// Set up Hardhat project. // Download the source code from etherscan: https://etherscan.io/address/0x35ffd6e268610e764ff6944d07760d0efe5e40e5#code // and compile // kTokens: /* kETH: 0x179212cb86D0eE6A4dfb2AbB1CF6A09feE0A9525 kwETH: 0x834CAcd6425fA6c7126b028B3d1E4cda53EB7257 kDAI: 0x8EE17Fa30D63ebD66e02205B1DF2f30D60a5CA30 kBTC: 0x77565202D78a6EDA565c7DC737FF1d8E64fd672a kUSDC: 0x3045312Fb54f00f43d6607999e387Db58FFb4cF4 */ // Export the private key from Metamask, etc, and put it in your hardhat config: module.exports = { defaultNetwork: "mainnet", networks: { mainnet: { url: "https://eth-mainnet.alchemyapi.io/v2/my_api_key", chainId: 1, accounts: [ "0xmy_private_key", ], }, }, solidity: { compilers: [{ version: "0.5.12" }], }, }; // here's the task: task("rook", "Withdraw ktokens", async (args, hre) => { const account = (await hre.ethers.getSigners())[0]; console.log("From:", account.address); // whichever token you use goes here const kUsdc = await hre.ethers.getContractAt( "IKToken", "0xac826952bc30504359a099c3a486d44e97415c77" ); const bal = await kUsdc.balanceOf(account.address); console.log("Balance", hre.ethers.utils.formatUnits(bal, 6), "kUSDC"); console.log("Underlying:", await kUsdc.underlying()); const liqPool = await hre.ethers.getContractAt( "LiquidityPoolV2", "0x35fFd6E268610E764fF6944d07760D0EFe5E40E5" ); // withdraw(address payable _to, IKToken _kToken, uint256 _kTokenAmount) const tx = await liqPool.withdraw(account.address, kUsdc.address, bal); console.log(tx); const mined = await tx.wait(); console.log(mined); });