mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
update test script
This commit is contained in:
parent
72ba571ce3
commit
52ecac01a3
|
@ -4,7 +4,6 @@ pragma solidity ^0.7.0;
|
||||||
import {DSMath} from "../../../common/math.sol";
|
import {DSMath} from "../../../common/math.sol";
|
||||||
import {Basic} from "../../../common/basic.sol";
|
import {Basic} from "../../../common/basic.sol";
|
||||||
import {TokenInterface} from "../../../common/interfaces.sol";
|
import {TokenInterface} from "../../../common/interfaces.sol";
|
||||||
import {AugustusSwapperInterface} from "./interface.sol";
|
|
||||||
|
|
||||||
abstract contract Helpers is DSMath, Basic {
|
abstract contract Helpers is DSMath, Basic {
|
||||||
struct SwapData {
|
struct SwapData {
|
||||||
|
@ -35,7 +34,6 @@ abstract contract Helpers is DSMath, Basic {
|
||||||
);
|
);
|
||||||
|
|
||||||
uint256 initalBal = getTokenBal(buyToken);
|
uint256 initalBal = getTokenBal(buyToken);
|
||||||
|
|
||||||
(bool success, ) = kyberswap.call{value: wethAmt}(swapData.callData);
|
(bool success, ) = kyberswap.call{value: wethAmt}(swapData.callData);
|
||||||
if (!success) revert("kyberswap-failed");
|
if (!success) revert("kyberswap-failed");
|
||||||
|
|
||||||
|
@ -57,11 +55,8 @@ abstract contract Helpers is DSMath, Basic {
|
||||||
if (address(_sellAddr) == ethAddr) {
|
if (address(_sellAddr) == ethAddr) {
|
||||||
ethAmt = swapData._sellAmt;
|
ethAmt = swapData._sellAmt;
|
||||||
} else {
|
} else {
|
||||||
address tokenProxy = AugustusSwapperInterface(kyberswap)
|
approve(TokenInterface(_sellAddr), kyberswap, swapData._sellAmt);
|
||||||
.getTokenTransferProxy();
|
|
||||||
approve(TokenInterface(_sellAddr), tokenProxy, swapData._sellAmt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
swapData._buyAmt = _swapHelper(swapData, ethAmt);
|
swapData._buyAmt = _swapHelper(swapData, ethAmt);
|
||||||
|
|
||||||
setUint(setId, swapData._buyAmt);
|
setUint(setId, swapData._buyAmt);
|
||||||
|
|
|
@ -41,7 +41,6 @@ abstract contract KyberResolver is Helpers {
|
||||||
_sellAmt: sellAmt,
|
_sellAmt: sellAmt,
|
||||||
_buyAmt: 0
|
_buyAmt: 0
|
||||||
});
|
});
|
||||||
|
|
||||||
swapData = _swap(swapData, setId);
|
swapData = _swap(swapData, setId);
|
||||||
|
|
||||||
_eventName = "LogSwap(address,address,uint256,uint256,uint256)";
|
_eventName = "LogSwap(address,address,uint256,uint256,uint256)";
|
||||||
|
|
|
@ -88,31 +88,25 @@ describe("Kyberswap", function() {
|
||||||
.times(new BigNumber(10).pow(sellTokenDecimals))
|
.times(new BigNumber(10).pow(sellTokenDecimals))
|
||||||
.toFixed(0);
|
.toFixed(0);
|
||||||
const fromAddress = dsaWallet0.address;
|
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 = {
|
let params = {
|
||||||
base: sellTokenAddress,
|
tokenIn: sellTokenAddress,
|
||||||
quote: buyTokenAddress,
|
tokenOut: buyTokenAddress,
|
||||||
amount: srcAmount,
|
amountIn: srcAmount,
|
||||||
type: "sell",
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const buyTokenAmount = await axios
|
const routeSummary = await axios
|
||||||
.get(url, { params: params })
|
.get(url, { params: params })
|
||||||
.then((data) => data.data);
|
.then((data) => data.data.routeSummary);
|
||||||
console.log("--------buy amount--------",buyTokenAmount)
|
|
||||||
let minAmount = new BigNumber(buyTokenAmount)
|
|
||||||
.times(1 - slippage / 100)
|
|
||||||
.toFixed(0);
|
|
||||||
|
|
||||||
let txConfig = {
|
let txConfig = {
|
||||||
user_address: fromAddress,
|
routeSummary: routeSummary,
|
||||||
src_id: sellTokenAddress,
|
sender: fromAddress,
|
||||||
dst_id: buyTokenAddress,
|
recipient: fromAddress,
|
||||||
src_qty: srcAmount,
|
|
||||||
min_dst_qty: minAmount,
|
|
||||||
gas_price: 'high'
|
|
||||||
};
|
};
|
||||||
let url2 = "https://api.kyber.network/trade_data";
|
let url2 = "https://aggregator-api.kyberswap.com/ethereum/api/v1/route/build";
|
||||||
const calldata = await axios
|
const calldata = await axios
|
||||||
.post(url2, txConfig)
|
.post(url2, txConfig)
|
||||||
.then((data) => data.data.data);
|
.then((data) => data.data.data);
|
||||||
|
@ -134,13 +128,13 @@ describe("Kyberswap", function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
let unitAmt = caculateUnitAmt(
|
let unitAmt = caculateUnitAmt(
|
||||||
buyTokenAmount,
|
routeSummary.amountOut,
|
||||||
srcAmount,
|
srcAmount,
|
||||||
buyTokenDecimals,
|
buyTokenDecimals,
|
||||||
sellTokenDecimals,
|
sellTokenDecimals,
|
||||||
1
|
1
|
||||||
);
|
);
|
||||||
|
console.log('----------------unitAmt-------------', unitAmt.toString())
|
||||||
return [
|
return [
|
||||||
buyTokenAddress,
|
buyTokenAddress,
|
||||||
sellTokenAddress,
|
sellTokenAddress,
|
||||||
|
@ -162,7 +156,6 @@ describe("Kyberswap", function() {
|
||||||
.connect(wallet0)
|
.connect(wallet0)
|
||||||
.cast(...encodeSpells(spells), wallet1.address);
|
.cast(...encodeSpells(spells), wallet1.address);
|
||||||
const receipt = await tx.wait();
|
const receipt = await tx.wait();
|
||||||
|
|
||||||
expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.lte(
|
expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.lte(
|
||||||
ethers.utils.parseEther("8")
|
ethers.utils.parseEther("8")
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user