Skip to content

Commit

Permalink
fix kyber proxy: use minRate (#26)
Browse files Browse the repository at this point in the history
* fix kyber proxy minRate

* minor

* new kyber contract
  • Loading branch information
Jarvis authored Aug 12, 2021
1 parent 475157d commit 4958681
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 7 deletions.
4 changes: 2 additions & 2 deletions contracts.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@
}
},
"eth_mainnet": {
"smartWalletImplementation": "0x051DC16b2ECB366984d1074dCC07c342a9463999",
"smartWalletImplementation": "0x95ceC39Aa053C62d1A49D88B60620a489C241F53",
"smartWalletProxy": "0x70270C228c5B4279d1578799926873aa72446CcD",
"fetchTokenBalances": "0xA526388721De4cB8206ff4D0b1A1948696b5d073",
"fetchAaveDataWrapper": "0x0C816D6C4C37294186CBCA0E514Fc56F0c34d059",
"swapContracts": {
"uniSwap": "0x2FA1e7dF142665320cA916AFDA9DFD9A97C9b986",
"uniSwapV3": "0x0cf9205d8868fF4d5d0a4d7F0a3719A6F0681B18",
"kyberProxy": "0x60fc810EA972809d729FCE0043B82a58766596ee",
"kyberProxy": "0xfF0A25c7E0621358b8f84771D275810e47D35b6f",
"kyberDmm": "0xf351Dd5EC89e5ac6c9125262853c74E714C1d56a"
},
"lendingContracts": {
Expand Down
1 change: 0 additions & 1 deletion contracts/swap/ISwap.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ interface ISwap {

struct SwapParams {
uint256 srcAmount;
// min return for uni, min conversionrate for kyber, etc.
uint256 minDestAmount;
address[] tradePath;
address recipient;
Expand Down
12 changes: 11 additions & 1 deletion contracts/swap/KyberProxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,27 @@ contract KyberProxy is BaseSwap {
uint256 callValue = params.tradePath[0] == address(ETH_TOKEN_ADDRESS)
? params.srcAmount
: 0;

// Convert minDestAmount to minConversionRate
uint256 minConversionRate = calcRateFromQty(
params.srcAmount,
params.minDestAmount,
getDecimals(IERC20Ext(params.tradePath[0])),
getDecimals(IERC20Ext(params.tradePath[1]))
);

kyberProxy.tradeWithHintAndFee{value: callValue}(
IERC20Ext(params.tradePath[0]),
params.srcAmount,
IERC20Ext(params.tradePath[1]),
payable(params.recipient),
MAX_AMOUNT,
params.minDestAmount,
minConversionRate,
params.feeReceiver,
params.feeBps,
params.extraArgs
);

destAmount = getBalance(IERC20Ext(params.tradePath[1]), params.recipient).sub(
destBalanceBefore
);
Expand Down
4 changes: 2 additions & 2 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,15 @@ if (PRIVATE_KEY && INFURA_API_KEY) {
chainId: 3,
accounts: [PRIVATE_KEY],
timeout: 20000,
gasPrice: 20 * 1e9,
gasPrice: 80 * 1e9,
};

config.networks!.eth_mainnet = {
url: `https://mainnet.infura.io/v3/${INFURA_API_KEY}`,
chainId: 1,
accounts: [PRIVATE_KEY],
timeout: 20000,
gasPrice: 24 * 1e9,
gasPrice: 42 * 1e9,
};
}

Expand Down
1 change: 1 addition & 0 deletions scripts/config_eth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const EthConfig: Record<string, IConfig> = {
{symbol: 'dai', address: '0x6b175474e89094c44da98b954eedeac495271d0f'},
{symbol: 'usdc', address: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48'},
{symbol: 'usdt', address: '0xdac17f958d2ee523a2206206994597c13d831ec7'},
// {symbol: 'knc', address: '0xdefa4e8a7bcba345f687a2f1456f5edd9ce97202'},
],

wNative: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
Expand Down
2 changes: 1 addition & 1 deletion test/swap.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ describe('swap test', async () => {
continue;
}

// console.log(`swapping from ${token.address} -> ${targetToken}`);
console.log(`swapping from ${token.address} -> ${targetToken}`);

// Approve first
await token.approve(setup.proxyInstance.address, tokenAmount);
Expand Down

0 comments on commit 4958681

Please sign in to comment.