pushing actual reimburse.ts file used to reimburse
This commit is contained in:
parent
5e297dfa84
commit
7e0e989ba7
108
src/reimburse.ts
108
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 tokenIndex = 4
|
||||
const nativeQuantity = uiToNative(quantity, mangoGroup.mintDecimals[tokenIndex])
|
||||
const tokenAcc = tokenWallets[4].publicKey // 4 is index of usdc token acct
|
||||
const quantity = ma.amount * 1.2; // fill in quantity
|
||||
const nativeQuantity = uiToNative(
|
||||
quantity,
|
||||
mangoGroup.mintDecimals[tokenIndex],
|
||||
);
|
||||
|
||||
const keys = [
|
||||
{ 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: 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}})
|
||||
{ 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)
|
||||
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();
|
||||
|
|
Loading…
Reference in New Issue