From 7e0e989ba7db407b31fc7d5c38801c55ed940314 Mon Sep 17 00:00:00 2001 From: dd Date: Wed, 1 Sep 2021 11:03:41 -0400 Subject: [PATCH] pushing actual reimburse.ts file used to reimburse --- src/reimburse.ts | 120 +++++++++++++++++++++++++++++++---------------- 1 file changed, 80 insertions(+), 40 deletions(-) diff --git a/src/reimburse.ts b/src/reimburse.ts index 0b7cb39..fee8491 100644 --- a/src/reimburse.ts +++ b/src/reimburse.ts @@ -34,58 +34,98 @@ async function runReimburse() { // keypair const keyPairPath = - process.env.KEYPAIR || homedir() + '/.config/solana/id.json'; + process.env.KEYPAIR || homedir() + '/.config/solana/mm.json'; const payer = new Account(JSON.parse(fs.readFileSync(keyPairPath, 'utf-8'))); - let mangoGroup = await client.getMangoGroup(connection, mangoGroupPk); - - const tokenWallets = await Promise.all( - mangoGroup.tokens.map((mint) => - findLargestTokenAccountForOwner(connection, payer.publicKey, mint).then( - (response) => response, - ), - ), - ); + const tokenIndex = 4; + const tokenAcc = ( + await findLargestTokenAccountForOwner( + connection, + payer.publicKey, + mangoGroup.tokens[tokenIndex], + ) + ).publicKey; const marginAccounts = [ - { address: '4iZH4jgK1tdXQ3jwvQE7bsUDmxw1PnkhiBPdgEq5iRoS', amount: 1316.310144}, - { address: '4WoRSRkvJNenNVk7uB8st9PsjaPY8MZpHtK8NM7pRmzr', amount: 405.5065004}, - { address: '79k2VqrXFz8vSsuMWtCq2zJX2YGUL3gH5yS2A7gd2WNJ', amount: 534.7915884}, - { address: '7hudJyNLJKLH14httaFihK3zQ1auF3C1Rex2N79nja9u', amount: 1572.512634}, - { address: '7PAC5DfMxTYHLZicMrimsdL8XvgTp7gTM6ZbWzArQJXc', amount: 2180.24129}, - { address: 'CFcm6dtw6xaYkgoxZbRDa6WhLyHvirURT49HZAQGiLX2', amount: 3146.680519}, - { address: 'GVLZhyZma9tvKiXtKPTeRboju8kzj7MyoY1wPZ93eq79', amount: 928.1663967}, - { address: 'GvT7iqpnNe1zrXG5G1cNgKDyFYVx3E4Suqx1JmxXZW8m', amount: 2421.853979}, - { address: 'n3YxMeZvPnMqiNZuecWMdMm7tMszYS2Ve4TnN2bXYPi', amount: 2464.867504}, - { address: 'x3qpJRZFMHC4SRy2RGnbeahChNEUtd24uFidHMyrkjT', amount: 258.1840228} - ] + { + address: '4iZH4jgK1tdXQ3jwvQE7bsUDmxw1PnkhiBPdgEq5iRoS', + amount: 1316.310144, + }, + { + address: '4WoRSRkvJNenNVk7uB8st9PsjaPY8MZpHtK8NM7pRmzr', + amount: 405.5065004, + }, + { + address: '79k2VqrXFz8vSsuMWtCq2zJX2YGUL3gH5yS2A7gd2WNJ', + amount: 534.7915884, + }, + { + address: '7hudJyNLJKLH14httaFihK3zQ1auF3C1Rex2N79nja9u', + amount: 1572.512634, + }, + { + address: '7PAC5DfMxTYHLZicMrimsdL8XvgTp7gTM6ZbWzArQJXc', + amount: 2180.24129, + }, + { + address: 'CFcm6dtw6xaYkgoxZbRDa6WhLyHvirURT49HZAQGiLX2', + amount: 3146.680519, + }, + { + address: 'GVLZhyZma9tvKiXtKPTeRboju8kzj7MyoY1wPZ93eq79', + amount: 928.1663967, + }, + { + address: 'GvT7iqpnNe1zrXG5G1cNgKDyFYVx3E4Suqx1JmxXZW8m', + amount: 2421.853979, + }, + { + address: 'n3YxMeZvPnMqiNZuecWMdMm7tMszYS2Ve4TnN2bXYPi', + amount: 2464.867504, + }, + { + address: 'x3qpJRZFMHC4SRy2RGnbeahChNEUtd24uFidHMyrkjT', + amount: 258.1840228, + }, + ]; + let total = 0; for (const ma of marginAccounts) { - const marginAccount = new PublicKey(ma.address) + const marginAccount = new PublicKey(ma.address); + + const quantity = ma.amount * 1.2; // fill in quantity + const nativeQuantity = uiToNative( + quantity, + mangoGroup.mintDecimals[tokenIndex], + ); - const quantity = (ma.amount * 1.2) // fill in quantity - const tokenIndex = 4 - const nativeQuantity = uiToNative(quantity, mangoGroup.mintDecimals[tokenIndex]) - const tokenAcc = tokenWallets[4].publicKey // 4 is index of usdc token acct - const keys = [ - { isSigner: false, isWritable: true, pubkey: mangoGroup.publicKey}, - { isSigner: false, isWritable: true, pubkey: marginAccount }, + { isSigner: false, isWritable: true, pubkey: mangoGroup.publicKey }, + { isSigner: false, isWritable: true, pubkey: marginAccount }, { isSigner: true, isWritable: false, pubkey: payer.publicKey }, - { isSigner: false, isWritable: true, pubkey: tokenAcc }, - { isSigner: false, isWritable: true, pubkey: mangoGroup.vaults[tokenIndex] }, + { isSigner: false, isWritable: true, pubkey: tokenAcc }, + { + isSigner: false, + isWritable: true, + pubkey: mangoGroup.vaults[tokenIndex], + }, { isSigner: false, isWritable: false, pubkey: TOKEN_PROGRAM_ID }, - { isSigner: false, isWritable: false, pubkey: SYSVAR_CLOCK_PUBKEY } - ] - const data = encodeMangoInstruction({Deposit: {quantity: nativeQuantity}}) - - const instruction = new TransactionInstruction( { keys, data, programId }) - - const transaction = new Transaction() - transaction.add(instruction) - + { isSigner: false, isWritable: false, pubkey: SYSVAR_CLOCK_PUBKEY }, + ]; + const data = encodeMangoInstruction({ + Deposit: { quantity: nativeQuantity }, + }); + + const instruction = new TransactionInstruction({ keys, data, programId }); + + const transaction = new Transaction(); + transaction.add(instruction); + total += quantity; + console.log(ma.address.toString(), quantity); await client.sendTransaction(connection, transaction, payer, []); } + + console.log('total reimbursed', total); } runReimburse();