Skip to content

Commit f20e84b

Browse files
committed
New Contract
1 parent d71eacb commit f20e84b

File tree

7 files changed

+124
-146
lines changed

7 files changed

+124
-146
lines changed

assets/css/style.css

+2
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ footer p a, footer h5 a {color: #c7ac97; font-weight: bold;}
193193
.SideFarmMaxBTN {font-size: 10px; background-color: #000000; color: #ffffff; font-weight: bold; padding: 2px 4px;}
194194
.WOOOOOOOOOOOOW {font-size:16px !important; color: #128b03 !important;}
195195
.WOOOOOOOOOOOOW b {font-size: 21px;}
196+
.NOOOOOOOOOOOOO {font-size:16px !important; color: #a5012d !important;}
197+
.NOOOOOOOOOOOOO b {font-size: 21px;}
196198
.BOHBOH {margin: 10px auto; display: inline-block;}
197199
.StableCoinTitleALWAYS .StableCoinTitleIntern {display: inline-block !important;padding: 5%; border-radius: 23px;}
198200
.StableCoinTitleALWAYS {width: 90%; margin: 0 auto;}

assets/scripts/script.js

+27-8
Original file line numberDiff line numberDiff line change
@@ -246,24 +246,27 @@ window.consumeAddressBarParam = function consumeAddressBarParam(paramName) {
246246
return param;
247247
};
248248

249-
window.getSendingOptions = function getSendingOptions(transaction) {
249+
window.getSendingOptions = function getSendingOptions(transaction, value) {
250250
return new Promise(async function(ok, ko) {
251251
if (transaction) {
252252
var address = await window.getAddress();
253253
return window.bypassEstimation ? ok({
254254
from: address,
255-
gas: window.gasLimit || '7900000'
255+
gas: window.gasLimit || '7900000',
256+
value
256257
}) : transaction.estimateGas({
257258
from: address,
258-
gasPrice: window.web3.utils.toWei("13", "gwei")
259+
gasPrice: window.web3.utils.toWei("13", "gwei"),
260+
value
259261
},
260262
function(error, gas) {
261263
if (error) {
262264
return ko(error.message || error);
263265
}
264266
return ok({
265267
from: address,
266-
gas: gas || window.gasLimit || '7900000'
268+
gas: gas || window.gasLimit || '7900000',
269+
value
267270
});
268271
});
269272
}
@@ -463,7 +466,19 @@ window.toDecimals = function toDecimals(n, d) {
463466
var decimals = (typeof d).toLowerCase() === 'string' ? parseInt(d) : d;
464467
var symbol = window.toEthereumSymbol(decimals);
465468
if (symbol) {
466-
return window.web3.utils.toWei((typeof n).toLowerCase() === 'string' ? n : window.numberToString(n), symbol);
469+
var input = (typeof n).toLowerCase() === 'string' ? n : window.numberToString(n);
470+
var output = undefined;
471+
while(!output) {
472+
try {
473+
output = window.web3.utils.toWei(input, symbol);
474+
} catch(e) {
475+
if((e.message || e).indexOf('places') === -1) {
476+
throw e;
477+
}
478+
input = input.substring(0, input.length - 1);
479+
}
480+
}
481+
return output;
467482
}
468483
var number = (typeof n).toLowerCase() === 'string' ? parseInt(n) : n;
469484
if (!number || this.isNaN(number)) {
@@ -1250,6 +1265,9 @@ window.loadTokenInfos = async function loadTokenInfos(addresses, abi, noLogo) {
12501265
decimals: address === window.wethAddress ? '18' : await window.blockchainCall(token.methods.decimals),
12511266
logo: noLogo ? undefined : await window.loadLogo(address === window.wethAddress ? window.voidEthereumAddress : address)
12521267
});
1268+
if(!window.tokenInfosCache[address].logo && noLogo !== true) {
1269+
window.tokenInfosCache[address].logo = await window.loadLogo(address === window.wethAddress ? window.voidEthereumAddress : address);
1270+
}
12531271
}
12541272
return single ? tokens[0] : tokens;
12551273
};
@@ -1344,10 +1362,11 @@ window.loadUniswapPairs = async function loadUniswapPairs(token, indexes) {
13441362
var pairToken = await window.loadTokenInfos(pairTokenAddress, window.context.UniswapV2PairAbi, true);
13451363
var token0 = window.web3.utils.toChecksumAddress(await window.blockchainCall(pairToken.token.methods.token0));
13461364
var token1 = window.web3.utils.toChecksumAddress(await window.blockchainCall(pairToken.token.methods.token1));
1347-
pairToken.token0 = token0 === address ? token : await window.loadTokenInfos(token0, undefined, true);
1348-
pairToken.token1 = token1 === address ? token : await window.loadTokenInfos(token1, undefined, true);
1365+
pairToken.token0 = token0 === address ? token : await window.loadTokenInfos(token0, undefined, indexes ? true : false);
1366+
pairToken.token1 = token1 === address ? token : await window.loadTokenInfos(token1, undefined, indexes ? true : false);
13491367
pairToken.key = `${token0}_${token1}-${token1}_${token0}`;
1350-
uniswapPairs.push(indexes[pairToken.key] = pairToken);
1368+
indexes && (indexes[pairToken.key] = pairToken);
1369+
uniswapPairs.push(pairToken);
13511370
}
13521371
}
13531372
return uniswapPairs;

contracts/stableCoin/farming/IUnifiedStableFarming.sol

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ interface IUnifiedStableFarming {
1414
uint256 amount0,
1515
uint256 amount1,
1616
address tokenAddress,
17-
uint256 tokenValue) external;
17+
uint256 tokenValue) external payable;
1818

1919
//Earn dumping uSD - Means mint uSD then swap uSD for the chosen Uniswap Pool tokens
2020
function earnByDump(
@@ -59,8 +59,10 @@ interface IUniswapV2Pair {
5959
}
6060

6161
interface IUniswapV2Router {
62+
function WETH() external pure returns (address);
6263
function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts);
6364
function swapExactTokensForTokens(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts);
65+
function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) external payable returns (uint[] memory amounts);
6466
}
6567

6668
interface IERC20 {

contracts/stableCoin/farming/UnifiedStableFarming.sol

+34-72
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,17 @@ contract UnifiedStableFarming is IUnifiedStableFarming {
88
address
99
private constant UNISWAP_V2_ROUTER = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D;
1010

11+
address private WETH_ADDRESS;
12+
1113
uint256[] private _percentage;
1214

1315
constructor(uint256[] memory percentage) {
16+
WETH_ADDRESS = IUniswapV2Router(UNISWAP_V2_ROUTER).WETH();
1417
assert(percentage.length == 2);
1518
_percentage = percentage;
1619
}
1720

18-
function percentage() public override view returns(uint256[] memory) {
21+
function percentage() public override view returns (uint256[] memory) {
1922
return _percentage;
2023
}
2124

@@ -28,20 +31,21 @@ contract UnifiedStableFarming is IUnifiedStableFarming {
2831
uint256 amount1,
2932
address tokenAddress,
3033
uint256 tokenValue
31-
) public override {
32-
require(
33-
_isValidPairToken(stableCoinAddress, tokenAddress),
34-
"Choosen token address is not in a valid pair"
35-
);
36-
_transferToMeAndCheckAllowance(
37-
tokenAddress,
38-
tokenValue,
39-
UNISWAP_V2_ROUTER
40-
);
34+
) public override payable {
35+
if(tokenAddress != WETH_ADDRESS) {
36+
_transferToMeAndCheckAllowance(
37+
tokenAddress,
38+
tokenValue,
39+
UNISWAP_V2_ROUTER
40+
);
41+
}
42+
uint256 realTokenValue = tokenAddress == WETH_ADDRESS
43+
? msg.value
44+
: tokenValue;
4145
uint256 stableCoinAmount = _swap(
4246
tokenAddress,
4347
stableCoinAddress,
44-
tokenValue,
48+
realTokenValue,
4549
address(this)
4650
);
4751
(uint256 return0, uint256 return1) = IStableCoin(stableCoinAddress)
@@ -50,45 +54,7 @@ contract UnifiedStableFarming is IUnifiedStableFarming {
5054
stableCoinAddress,
5155
pairIndex
5256
);
53-
require(
54-
_isPumpOK(
55-
stableCoinAddress,
56-
tokenAddress,
57-
tokenValue,
58-
token0,
59-
return0,
60-
token1,
61-
return1,
62-
stableCoinAmount
63-
),
64-
"Values are not coherent"
65-
);
66-
_flushToSender(token0, token1, stableCoinAddress);
67-
}
68-
69-
function _isPumpOK(
70-
address stableCoinAddress,
71-
address tokenAddress,
72-
uint256 tokenValue,
73-
address token0,
74-
uint256 return0,
75-
address token1,
76-
uint256 return1,
77-
uint256 stableCoinAmount
78-
) private view returns (bool) {
79-
IStableCoin stableCoin = IStableCoin(stableCoinAddress);
80-
uint256 cumulative = stableCoin.fromTokenToStable(
81-
tokenAddress,
82-
tokenValue
83-
);
84-
cumulative += stableCoin.fromTokenToStable(token0, return0);
85-
cumulative += stableCoin.fromTokenToStable(token1, return1);
86-
uint256 percentage = (cumulative * _percentage[0]) / _percentage[1];
87-
uint256 cumulativePlus = cumulative + percentage;
88-
uint256 cumulativeMinus = cumulative - percentage;
89-
return
90-
stableCoinAmount >= cumulativeMinus &&
91-
stableCoinAmount <= cumulativePlus;
57+
_flushToSender(token0, token1, stableCoinAddress, tokenAddress);
9258
}
9359

9460
//Earn dumping uSD - Means mint uSD then swap uSD for the chosen Uniswap Pool tokens
@@ -131,7 +97,7 @@ contract UnifiedStableFarming is IUnifiedStableFarming {
13197
msg.sender
13298
);
13399
}
134-
_flushToSender(token0, token1, stableCoinAddress);
100+
_flushToSender(token0, token1, stableCoinAddress, address(0));
135101
}
136102

137103
function _transferTokens(
@@ -199,17 +165,23 @@ contract UnifiedStableFarming is IUnifiedStableFarming {
199165
function _flushToSender(
200166
address token0,
201167
address token1,
202-
address token2
168+
address token2,
169+
address token3
203170
) private {
204171
_flushToSender(token0);
205172
_flushToSender(token1);
206173
_flushToSender(token2);
174+
_flushToSender(token3);
207175
}
208176

209177
function _flushToSender(address tokenAddress) private {
210178
if (tokenAddress == address(0)) {
211179
return;
212180
}
181+
if(tokenAddress == WETH_ADDRESS) {
182+
payable(msg.sender).transfer(address(this).balance);
183+
return;
184+
}
213185
IERC20 token = IERC20(tokenAddress);
214186
uint256 balanceOf = token.balanceOf(address(this));
215187
if (balanceOf > 0) {
@@ -230,6 +202,15 @@ contract UnifiedStableFarming is IUnifiedStableFarming {
230202
address[] memory path = new address[](2);
231203
path[0] = tokenIn;
232204
path[1] = tokenOut;
205+
if (path[0] == WETH_ADDRESS) {
206+
return
207+
uniswapV2Router.swapExactETHForTokens{value: amountIn}(
208+
uniswapV2Router.getAmountsOut(amountIn, path)[1],
209+
path,
210+
receiver,
211+
block.timestamp + 1000
212+
)[1];
213+
}
233214
return
234215
uniswapV2Router.swapExactTokensForTokens(
235216
amountIn,
@@ -239,23 +220,4 @@ contract UnifiedStableFarming is IUnifiedStableFarming {
239220
block.timestamp + 1000
240221
)[1];
241222
}
242-
243-
function _isValidPairToken(address stableCoinAddress, address tokenAddress)
244-
private
245-
view
246-
returns (bool)
247-
{
248-
address[] memory allowedPairs = IStableCoin(stableCoinAddress)
249-
.allowedPairs();
250-
for (uint256 i = 0; i < allowedPairs.length; i++) {
251-
IUniswapV2Pair pair = IUniswapV2Pair(allowedPairs[i]);
252-
if (pair.token0() == tokenAddress) {
253-
return true;
254-
}
255-
if (pair.token1() == tokenAddress) {
256-
return true;
257-
}
258-
}
259-
return false;
260-
}
261223
}

data/context.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"stableCoinAddress" : "0x44086035439E676c02D411880FcCb9837CE37c57",
2626
"oldStableCoinAddressRopsten" : "0xba6d34a9c638270a5393772b0b45b528e12eb9a4",
2727
"oldStableCoinAddress" : "0x84841e552A021224de716b7Be89747bb2D62D642",
28-
"farmingContractAddress" : "0x9a54a7d214157035Da0C02B00F4312d126e719DE",
28+
"farmingContractAddress" : "0xBce9f63920f34c32872048810C216a18aC53d40d",
2929
"farmingShowRulePump" : 1,
3030
"farmingShowRuleDump" : 1,
3131
"infuraNode" : "https://mainnet.infura.io/v3/5e302428cc5e41a188dc717dc6f34a5b",

0 commit comments

Comments
 (0)