From 52ecac01a302c0f3a3e1c544d3c6a49eed2db849 Mon Sep 17 00:00:00 2001 From: q1q0 Date: Wed, 14 Jun 2023 08:29:41 -0400 Subject: [PATCH] update test script --- .../connectors/kyber/kyber_v3/helpers.sol | 7 +--- .../connectors/kyber/kyber_v3/main.sol | 1 - test/mainnet/kyberswap/kyberswap.test.ts | 35 ++++++++----------- 3 files changed, 15 insertions(+), 28 deletions(-) diff --git a/contracts/mainnet/connectors/kyber/kyber_v3/helpers.sol b/contracts/mainnet/connectors/kyber/kyber_v3/helpers.sol index a278476e..5b38d196 100644 --- a/contracts/mainnet/connectors/kyber/kyber_v3/helpers.sol +++ b/contracts/mainnet/connectors/kyber/kyber_v3/helpers.sol @@ -4,7 +4,6 @@ pragma solidity ^0.7.0; import {DSMath} from "../../../common/math.sol"; import {Basic} from "../../../common/basic.sol"; import {TokenInterface} from "../../../common/interfaces.sol"; -import {AugustusSwapperInterface} from "./interface.sol"; abstract contract Helpers is DSMath, Basic { struct SwapData { @@ -35,7 +34,6 @@ abstract contract Helpers is DSMath, Basic { ); uint256 initalBal = getTokenBal(buyToken); - (bool success, ) = kyberswap.call{value: wethAmt}(swapData.callData); if (!success) revert("kyberswap-failed"); @@ -57,11 +55,8 @@ abstract contract Helpers is DSMath, Basic { if (address(_sellAddr) == ethAddr) { ethAmt = swapData._sellAmt; } else { - address tokenProxy = AugustusSwapperInterface(kyberswap) - .getTokenTransferProxy(); - approve(TokenInterface(_sellAddr), tokenProxy, swapData._sellAmt); + approve(TokenInterface(_sellAddr), kyberswap, swapData._sellAmt); } - swapData._buyAmt = _swapHelper(swapData, ethAmt); setUint(setId, swapData._buyAmt); diff --git a/contracts/mainnet/connectors/kyber/kyber_v3/main.sol b/contracts/mainnet/connectors/kyber/kyber_v3/main.sol index 4b2b96dc..582176df 100644 --- a/contracts/mainnet/connectors/kyber/kyber_v3/main.sol +++ b/contracts/mainnet/connectors/kyber/kyber_v3/main.sol @@ -41,7 +41,6 @@ abstract contract KyberResolver is Helpers { _sellAmt: sellAmt, _buyAmt: 0 }); - swapData = _swap(swapData, setId); _eventName = "LogSwap(address,address,uint256,uint256,uint256)"; diff --git a/test/mainnet/kyberswap/kyberswap.test.ts b/test/mainnet/kyberswap/kyberswap.test.ts index 93831934..25be2b95 100644 --- a/test/mainnet/kyberswap/kyberswap.test.ts +++ b/test/mainnet/kyberswap/kyberswap.test.ts @@ -88,31 +88,25 @@ describe("Kyberswap", function() { .times(new BigNumber(10).pow(sellTokenDecimals)) .toFixed(0); const fromAddress = dsaWallet0.address; - let url = `https://api.kyber.network/quote_amount`; + let url = `https://aggregator-api.kyberswap.com/ethereum/api/v1/routes`; let params = { - base: sellTokenAddress, - quote: buyTokenAddress, - amount: srcAmount, - type: "sell", + tokenIn: sellTokenAddress, + tokenOut: buyTokenAddress, + amountIn: srcAmount, }; - const buyTokenAmount = await axios + const routeSummary = await axios .get(url, { params: params }) - .then((data) => data.data); - console.log("--------buy amount--------",buyTokenAmount) - let minAmount = new BigNumber(buyTokenAmount) - .times(1 - slippage / 100) - .toFixed(0); + .then((data) => data.data.routeSummary); + + let txConfig = { - user_address: fromAddress, - src_id: sellTokenAddress, - dst_id: buyTokenAddress, - src_qty: srcAmount, - min_dst_qty: minAmount, - gas_price: 'high' + routeSummary: routeSummary, + sender: fromAddress, + recipient: fromAddress, }; - let url2 = "https://api.kyber.network/trade_data"; + let url2 = "https://aggregator-api.kyberswap.com/ethereum/api/v1/route/build"; const calldata = await axios .post(url2, txConfig) .then((data) => data.data.data); @@ -134,13 +128,13 @@ describe("Kyberswap", function() { } let unitAmt = caculateUnitAmt( - buyTokenAmount, + routeSummary.amountOut, srcAmount, buyTokenDecimals, sellTokenDecimals, 1 ); - + console.log('----------------unitAmt-------------', unitAmt.toString()) return [ buyTokenAddress, sellTokenAddress, @@ -162,7 +156,6 @@ describe("Kyberswap", function() { .connect(wallet0) .cast(...encodeSpells(spells), wallet1.address); const receipt = await tx.wait(); - expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.lte( ethers.utils.parseEther("8") );