-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test and deploy dackieswapV3 adapter on xlayer (#4)
Co-authored-by: lu.zhang <lu.zhang@okg.com>
- Loading branch information
1 parent
77fc3d6
commit 12d38e2
Showing
2 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
scripts/test_scripts/dex_router/onchaintest_dackieV3_adapter.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
const { ethers } = require("hardhat"); | ||
require("../../tools"); | ||
let { direction, FOREVER } = require("./utils") | ||
|
||
async function main() { | ||
const dexRouter = await ethers.getContractAt("DexRouter", "0x127a986cE31AA2ea8E1a6a0F0D5b7E5dbaD7b0bE"); | ||
const tokenApprove = await ethers.getContractAt("TokenApprove", "0x8b773D83bc66Be128c60e07E17C8901f7a64F000"); | ||
console.log("DexRouter: " + dexRouter.address); | ||
const gasPirce = await ethers.provider.getGasPrice(); | ||
console.log("gasPrice: " + gasPirce); | ||
const adapter = "0x329F0b78D7850Db32a35043c0DA9a63b3672617C" | ||
let poolAddress = "0xa5388037b5FEf0EfCdFC9e1d6d7bC6E7e61C7082"; | ||
toToken = await ethers.getContractAt( | ||
"MockERC20", | ||
"0xe538905cf8410324e03A5A23C1c177a474D59b2b"//WOKB | ||
) | ||
fromToken = await ethers.getContractAt( | ||
"MockERC20", | ||
"0x1e4a5963abfd975d8c9021ce480b42188849d41d"//USDT | ||
) | ||
let fromTokenAmount = ethers.utils.parseUnits("0.1", 6); | ||
let minReturnAmount = 0; | ||
let deadLine = FOREVER; | ||
let mixAdapter1 = [adapter]; | ||
let assertTo1 = [adapter]; | ||
let weight1 = Number(10000).toString(16).replace('0x', ''); | ||
let rawData1 = [ | ||
"0x" + | ||
direction(fromToken.address, toToken.address) + | ||
"0000000000000000000" + | ||
weight1 + | ||
poolAddress.replace("0x", "") | ||
]; | ||
const moreInfo = ethers.utils.defaultAbiCoder.encode( | ||
["uint160", "bytes"], | ||
[ | ||
0, | ||
ethers.utils.defaultAbiCoder.encode( | ||
["address", "address", "uint24"], | ||
[ | ||
fromToken.address, | ||
toToken.address, | ||
2500 | ||
] | ||
) | ||
] | ||
) | ||
let extraData1 = [moreInfo]; | ||
let router1 = [mixAdapter1, assertTo1, rawData1, extraData1, fromToken.address]; | ||
let layer1 = [router1]; | ||
let orderId = 0; | ||
let baseRequest = [ | ||
fromToken.address, | ||
toToken.address, | ||
fromTokenAmount, | ||
minReturnAmount, | ||
deadLine, | ||
] | ||
let pmmReq = [] | ||
await dexRouter.smartSwapByOrderId( | ||
orderId, | ||
baseRequest, | ||
[fromTokenAmount], | ||
[layer1], | ||
pmmReq | ||
); | ||
} | ||
|
||
main() | ||
.then(() => process.exit(0)) | ||
.catch(error => { | ||
console.error(error); | ||
process.exit(1); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
pragma solidity ^0.8.0; | ||
|
||
import "forge-std/test.sol"; | ||
import "forge-std/console2.sol"; | ||
import "@dex/adapter/PancakeswapV3Adapter.sol"; | ||
|
||
contract DackieSwapV3AdapterTest is Test { | ||
|
||
PancakeswapV3Adapter adapter; | ||
address WOKB = 0xe538905cf8410324e03A5A23C1c177a474D59b2b; | ||
address USDT = 0x1E4a5963aBFD975d8c9021ce480b42188849D41d; | ||
address USDTWETH = 0xa5388037b5FEf0EfCdFC9e1d6d7bC6E7e61C7082; | ||
|
||
function test_WOKBtoUSDC() public { | ||
vm.createSelectFork(vm.envString("XLAYER_RPC_URL")); | ||
adapter = PancakeswapV3Adapter(address(0x329F0b78D7850Db32a35043c0DA9a63b3672617C)); | ||
deal(USDT, address(this), 1 * 10 ** 6); | ||
IERC20(USDT).transfer(address(adapter), 1 * 10 ** 6); | ||
uint160 sqrtPriceLimitX96 = 0; | ||
bytes memory data = abi.encode(USDT, WOKB, uint24(2500)); | ||
bytes memory moreInfo = abi.encode(sqrtPriceLimitX96, data); | ||
adapter.sellBase(address(this), USDTWETH, moreInfo); | ||
console2.log("WOKB", IERC20(WOKB).balanceOf(address(this))); | ||
} | ||
} |