Last active
April 9, 2024 18:04
-
-
Save BlockmanCodes/d0057d623269f0d4390b3526469bf381 to your computer and use it in GitHub Desktop.
Kyber (classic): swap eth to usdt
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
const ethers = require('ethers'); | |
const dmmRouterAbi = require("../abis/dmmRouter.json") | |
const erc20Abi = require("../abis/erc20.json") | |
const wethAbi = require("../abis/weth.json") | |
WETH_ADDRESS= '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2' | |
USDT_ADDRESS= '0xdAC17F958D2ee523a2206206994597C13D831ec7' | |
DMM_ROUTER_ADDRESS='0x1c87257F5e8609940Bc751a07BB085Bb7f8cDBE6' | |
const provider = new ethers.providers.JsonRpcProvider('http://127.0.0.1:8545/') | |
const wallet = new ethers.Wallet('0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80') | |
const signer = wallet.connect(provider) | |
const dmmRouter = new ethers.Contract(DMM_ROUTER_ADDRESS, dmmRouterAbi, provider) | |
const usdt = new ethers.Contract(USDT_ADDRESS, erc20Abi, provider) | |
const weth = new ethers.Contract(WETH_ADDRESS, wethAbi, provider) | |
const logBalances = async () => { | |
const ethBalance = await provider.getBalance(signer.address) | |
const usdtBalance = await usdt.balanceOf(signer.address) | |
const wethBalance = await weth.balanceOf(signer.address) | |
console.log('--------------------') | |
console.log('ETH Balance:', ethers.utils.formatUnits(ethBalance, 18)) | |
console.log('WETH Balance:', ethers.utils.formatUnits(wethBalance, 18)) | |
console.log('USDT Balance:', ethers.utils.formatUnits(usdtBalance, 6)) | |
console.log('--------------------') | |
} | |
const POOL_ADDRESSES = [ | |
'0xf8467EF9de03E83B5a778Ac858EA5c2d1FC47188', | |
'0xcE9874C42DcE7fffbE5E48B026Ff1182733266Cb', | |
'0xCD9fD9Cf78CAD37b3a913681A6c3fD2Ce0606827' | |
] | |
const main = async () => { | |
logBalances() | |
const amountIn = ethers.utils.parseUnits('1', 18) | |
// const tx1 = await weth.connect(signer).approve(DMM_ROUTER_ADDRESS, amountIn) | |
// tx1.wait() | |
const tx2 = await dmmRouter.connect(signer).swapExactETHForTokens( | |
0, | |
[POOL_ADDRESSES[0]], | |
[WETH_ADDRESS, USDT_ADDRESS], | |
signer.address, | |
Math.floor(Date.now() / 1000) + (60 * 10), | |
{ | |
value: amountIn | |
} | |
) | |
tx2.wait() | |
logBalances() | |
} | |
main() | |
/* | |
node scripts/01_classicSwap.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
/** @type import('hardhat/config').HardhatUserConfig */ | |
module.exports = { | |
solidity: "0.8.18", | |
networks: { | |
hardhat: { | |
forking: { | |
url: "https://mainnet.infura.io/v3/abc" | |
} | |
} | |
} | |
}; |
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
{ | |
"name": "classic-swap", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"keywords": [], | |
"author": "", | |
"license": "ISC", | |
"dependencies": { | |
"ethers": "^5.7.2", | |
"hardhat": "^2.14.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment