From 4958681fe8025ef068803367bad520a56c08d6e3 Mon Sep 17 00:00:00 2001 From: Jarvis Date: Thu, 12 Aug 2021 16:32:05 +0700 Subject: [PATCH] fix kyber proxy: use minRate (#26) * fix kyber proxy minRate * minor * new kyber contract --- contracts.json | 4 ++-- contracts/swap/ISwap.sol | 1 - contracts/swap/KyberProxy.sol | 12 +++++++++++- hardhat.config.ts | 4 ++-- scripts/config_eth.ts | 1 + test/swap.test.ts | 2 +- 6 files changed, 17 insertions(+), 7 deletions(-) diff --git a/contracts.json b/contracts.json index 9705475..c636d5d 100644 --- a/contracts.json +++ b/contracts.json @@ -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": { diff --git a/contracts/swap/ISwap.sol b/contracts/swap/ISwap.sol index 6c4eb5e..fd72333 100644 --- a/contracts/swap/ISwap.sol +++ b/contracts/swap/ISwap.sol @@ -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; diff --git a/contracts/swap/KyberProxy.sol b/contracts/swap/KyberProxy.sol index 2541be8..a517d50 100644 --- a/contracts/swap/KyberProxy.sol +++ b/contracts/swap/KyberProxy.sol @@ -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 ); diff --git a/hardhat.config.ts b/hardhat.config.ts index 8e25f31..548987b 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -155,7 +155,7 @@ if (PRIVATE_KEY && INFURA_API_KEY) { chainId: 3, accounts: [PRIVATE_KEY], timeout: 20000, - gasPrice: 20 * 1e9, + gasPrice: 80 * 1e9, }; config.networks!.eth_mainnet = { @@ -163,7 +163,7 @@ if (PRIVATE_KEY && INFURA_API_KEY) { chainId: 1, accounts: [PRIVATE_KEY], timeout: 20000, - gasPrice: 24 * 1e9, + gasPrice: 42 * 1e9, }; } diff --git a/scripts/config_eth.ts b/scripts/config_eth.ts index 7c48a7b..8307454 100644 --- a/scripts/config_eth.ts +++ b/scripts/config_eth.ts @@ -8,6 +8,7 @@ export const EthConfig: Record = { {symbol: 'dai', address: '0x6b175474e89094c44da98b954eedeac495271d0f'}, {symbol: 'usdc', address: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48'}, {symbol: 'usdt', address: '0xdac17f958d2ee523a2206206994597c13d831ec7'}, + // {symbol: 'knc', address: '0xdefa4e8a7bcba345f687a2f1456f5edd9ce97202'}, ], wNative: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', diff --git a/test/swap.test.ts b/test/swap.test.ts index f590a2f..7df05ae 100644 --- a/test/swap.test.ts +++ b/test/swap.test.ts @@ -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);