引子NAVI竞赛第8期来了!这次任务是闪电贷+合并+质押+提供+借用+还款let'smove!开始首先先配置好助记词环境npminstalldotenv创建.env文件用于存助记词MNEMONIC='你的助记词'在代
NAVI竞赛第8期 来了!
这次任务是 闪电贷 + 合并 + 质押 + 提供 + 借用 + 还款
let's move !
npm install dotenv
MNEMONIC = '你的助记词'
require('dotenv').config()
const mnemonic = process.env.MNEMONIC;
//1. FlashLoan 50% of 10 SUI
let to_flashloan_amount = (10*10**9) * 0.5;
console.log(to_flashloan_amount);
const to_flashloan_coin: CoinInfo = Sui;
const pool_to_flashloan: PoolConfig = pool[to_flashloan_coin.symbol as keyof Pool];
let [flvsuicoin,receipt] = await flashloan(txb,pool_to_flashloan,to_flashloan_amount);
const this_coin = await txb.moveCall({
target: '0x2::coin::from_balance',
arguments: [flvsuicoin],
typeArguments: [pool_to_flashloan.type],
});
//2. Merge the loaned SUI to your wallet Sui object to obtain 15 SUI + gas
let to_add_amount = 10*10**9 + 0.1*10**9;//10 sui + gas
const to_add = txb.splitCoins(txb.gas, [txb.pure(to_add_amount)]);//
await txb.mergeCoins(this_coin,[to_add]);
这里注意要拿出质押后的数量
//3 Stake 15 SUI to vSUI via the voloSui staking contract
let recvvSui = await txb.moveCall({
target : `0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::native_pool::stake_non_entry`,
arguments: [
txb.object('0x7fa2faa111b8c65bea48a23049bfd81ca8f971a262d981dcd9a17c3825cb5baf'),
txb.object('0x680cd26af32b2bde8d3361e804c53ec1d1cfe24c7f039eb7f549e8dfde389a60'),
txb.object("0x05"),
this_coin,
],
typeArguments:[]// type arguments
});
const r_coin: CoinInfo = vSui;
const pool_to_e: PoolConfig = pool[r_coin.symbol as keyof Pool];
const e_value = await txb.moveCall({
target: '0x2::coin::value',
arguments: [recvvSui],
typeArguments: [pool_to_e.type],
});
//4 Supply the vSUI from step 3 to NAVI
const to_supply_coin: CoinInfo = vSui;
const pool_to_supply: PoolConfig = pool[to_supply_coin.symbol as keyof Pool];
await txb.moveCall({
target: `${config.ProtocolPackage}::incentive_v2::entry_deposit`,
arguments: [
txb.object('0x06'),
txb.object(config.StorageId),
txb.object(pool_to_supply.poolId),
txb.pure(pool_to_supply.assetId),
recvvSui,
e_value,
txb.object(config.Incentive),
txb.object(config.IncentiveV2),
],
typeArguments: [pool_to_supply.type],
}) ;
这里注意要增加手续费用
//Borrow 5 SUI * (1 + 0.06% flashloan-fee)
let to_borrow_amount = (5*10**9) * (1 + 0.06);
const to_borrow_sui: CoinInfo = Sui;
const pool_to_borrow: PoolConfig = pool[to_borrow_sui.symbol as keyof Pool];
let [borrowed] = await borrowCoin(txb,pool_to_borrow,to_borrow_amount);
const repayBalance = txb.moveCall({
target: '0x2::coin::into_balance',
arguments: [borrowed],
typeArguments: [pool_to_flashloan.type],
});
let [e_balance] = await repayFlashLoan(txb,pool_to_flashloan,receipt,repayBalance);
//*
//Extra token after repay
const e_coin = await txb.moveCall({
target: '0x2::coin::from_balance',
arguments: [e_balance],
typeArguments: [pool_to_flashloan.type],
});
//Transfer left_money after repay to teh account
txb.transferObjects([e_coin], sender);
(未完待续)
Let's Move 中文社区
telegram: <https://t.me/move_cn>
QQ群: 79489587
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!