update test script

This commit is contained in:
q1q0 2023-06-14 08:29:41 -04:00
parent 72ba571ce3
commit 52ecac01a3
3 changed files with 15 additions and 28 deletions

View File

@ -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);

View File

@ -41,7 +41,6 @@ abstract contract KyberResolver is Helpers {
_sellAmt: sellAmt,
_buyAmt: 0
});
swapData = _swap(swapData, setId);
_eventName = "LogSwap(address,address,uint256,uint256,uint256)";

View File

@ -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")
);