test deposit error code

This commit is contained in:
Tyler Shipe 2021-03-29 18:14:32 -04:00
parent 8d846fe974
commit cc73a0c2bc
1 changed files with 131 additions and 64 deletions

View File

@ -1,74 +1,141 @@
import fs from 'fs';
import { homedir } from 'os';
import { MangoClient, MangoGroup } from './client';
import IDS from './ids.json';
import { Connection, PublicKey, Account } from '@solana/web3.js';
import { nativeToUi } from './utils';
import { NUM_MARKETS, NUM_TOKENS } from './layout';
export { MangoClient, MangoGroup, MarginAccount, tokenToDecimals } from './client';
export { MangoIndexLayout, MarginAccountLayout, MangoGroupLayout } from './layout';
export {
MangoClient,
MangoGroup,
MarginAccount,
tokenToDecimals,
} from './client';
export {
MangoIndexLayout,
MarginAccountLayout,
MangoGroupLayout,
} from './layout';
export * from './layout';
export * from './utils'
export * from './utils';
export { IDS }
export { IDS };
//
// async function tests() {
// const cluster = "mainnet-beta";
// const cluster = 'devnet';
// const client = new MangoClient();
// const clusterIds = IDS[cluster]
//
// const connection = new Connection(IDS.cluster_urls[cluster], 'singleGossip')
// const mangoGroupPk = new PublicKey(clusterIds.mango_groups['BTC_ETH_USDT'].mango_group_pk);
// const clusterIds = IDS[cluster];
// const connection = new Connection(IDS.cluster_urls[cluster], 'singleGossip');
// const mangoGroupPk = new PublicKey(
// clusterIds.mango_groups['BTC_ETH_USDT'].mango_group_pk,
// );
// const mangoProgramId = new PublicKey(clusterIds.mango_program_id);
//
// const keyPairPath = process.env.KEYPAIR || homedir() + '/.config/solana/id.json'
// const payer = new Account(JSON.parse(fs.readFileSync(keyPairPath, 'utf-8')))
//
//
// async function testSolink() {
//
// const oraclePk = new PublicKey(IDS[cluster].oracles['ETH/USDT'])
// const agg = await Aggregator.loadWithConnection(oraclePk, connection)
//
// // const agg = await Aggregator.loadWithConnection(oraclePk, connection)
// console.log(agg.answer.median.toNumber(), agg.answer.updatedAt.toNumber(), agg.round.id.toNumber())
//
// }
//
// async function testDepositSrm() {
// const srmVaultPk = new PublicKey(clusterIds['mango_groups']['BTC_ETH_USDT']['srm_vault_pk'])
// const mangoGroup = await client.getMangoGroup(connection, mangoGroupPk, srmVaultPk)
// const srmAccountPk = new PublicKey("6utvndL8EEjpwK5QVtguErncQEPVbkuyABmXu6FeygeV")
// const mangoSrmAccountPk = await client.depositSrm(connection, mangoProgramId, mangoGroup, payer, srmAccountPk, 100)
// console.log(mangoSrmAccountPk.toBase58())
// await sleep(2000)
// const mangoSrmAccount = await client.getMangoSrmAccount(connection, mangoSrmAccountPk)
// const txid = await client.withdrawSrm(connection, mangoProgramId, mangoGroup, mangoSrmAccount, payer, srmAccountPk, 50)
// console.log('success', txid)
// }
//
// async function getMarginAccountDetails() {
// const mangoGroup = await client.getMangoGroup(connection, mangoGroupPk);
// const marginAccountPk = new PublicKey("Et4ieruYqyBAzfTpGqbFgYpddFXdFaGDtLDqFqs665Ui")
// const marginAccount = await client.getMarginAccount(connection, marginAccountPk, mangoGroup.dexProgramId)
// const prices = await mangoGroup.getPrices(connection)
//
// console.log(marginAccount.toPrettyString(mangoGroup, prices))
//
// for (let i = 0; i < NUM_TOKENS; i++) {
// console.log(i, marginAccount.getUiDeposit(mangoGroup, i), marginAccount.getUiBorrow(mangoGroup, i))
// }
// for (let i = 0; i < NUM_MARKETS; i++) {
// let openOrdersAccount = marginAccount.openOrdersAccounts[i]
// if (openOrdersAccount === undefined) {
// continue
// }
//
// console.log(i, nativeToUi(openOrdersAccount.quoteTokenTotal.toNumber(), mangoGroup.mintDecimals[NUM_MARKETS]),
// nativeToUi(openOrdersAccount.baseTokenTotal.toNumber(), mangoGroup.mintDecimals[i]))
// }
//
// }
// await getMarginAccountDetails()
// // await testSolink()
// // testDepositSrm()
// const keyPairPath =
// process.env.KEYPAIR || homedir() + '/.config/solana/id.json';
// const payer = new Account(JSON.parse(fs.readFileSync(keyPairPath, 'utf-8')));
// async function testSolink() {
// const oraclePk = new PublicKey(IDS[cluster].oracles['ETH/USDT'])
// const agg = await Aggregator.loadWithConnection(oraclePk, connection)
// // const agg = await Aggregator.loadWithConnection(oraclePk, connection)
// console.log(agg.answer.median.toNumber(), agg.answer.updatedAt.toNumber(), agg.round.id.toNumber())
// }
//
// tests()
// async function testDepositSrm() {
// const srmVaultPk = new PublicKey(clusterIds['mango_groups']['BTC_ETH_USDT']['srm_vault_pk'])
// const mangoGroup = await client.getMangoGroup(connection, mangoGroupPk, srmVaultPk)
// const srmAccountPk = new PublicKey("6utvndL8EEjpwK5QVtguErncQEPVbkuyABmXu6FeygeV")
// const mangoSrmAccountPk = await client.depositSrm(connection, mangoProgramId, mangoGroup, payer, srmAccountPk, 100)
// console.log(mangoSrmAccountPk.toBase58())
// await sleep(2000)
// const mangoSrmAccount = await client.getMangoSrmAccount(connection, mangoSrmAccountPk)
// const txid = await client.withdrawSrm(connection, mangoProgramId, mangoGroup, mangoSrmAccount, payer, srmAccountPk, 50)
// console.log('success', txid)
// }
// async function getMarginAccountDetails() {
// const mangoGroup = await client.getMangoGroup(connection, mangoGroupPk);
// const marginAccountPk = new PublicKey(
// '5pmKq6D67vdUam6KMoMNa1euaqDCScqCehtcTyhC4Koh',
// );
// console.log('ma:', mangoGroup.dexProgramId.toString());
// const marginAccount = await client.getMarginAccount(
// connection,
// marginAccountPk,
// mangoGroup.dexProgramId,
// );
// const prices = await mangoGroup.getPrices(connection);
// console.log(marginAccount.toPrettyString(mangoGroup, prices));
// for (let i = 0; i < NUM_TOKENS; i++) {
// console.log(
// i,
// marginAccount.getUiDeposit(mangoGroup, i),
// marginAccount.getUiBorrow(mangoGroup, i),
// );
// }
// for (let i = 0; i < NUM_MARKETS; i++) {
// let openOrdersAccount = marginAccount.openOrdersAccounts[i];
// if (openOrdersAccount === undefined) {
// continue;
// }
// console.log(
// i,
// nativeToUi(
// openOrdersAccount.quoteTokenTotal.toNumber(),
// mangoGroup.mintDecimals[NUM_MARKETS],
// ),
// nativeToUi(
// openOrdersAccount.baseTokenTotal.toNumber(),
// mangoGroup.mintDecimals[i],
// ),
// );
// }
// }
// async function testDeposit() {
// const mangoGroup = await client.getMangoGroup(connection, mangoGroupPk);
// const marginAccountPk = new PublicKey(
// '5pmKq6D67vdUam6KMoMNa1euaqDCScqCehtcTyhC4Koh',
// );
// const marginAccount = await client.getMarginAccount(
// connection,
// marginAccountPk,
// mangoGroup.dexProgramId,
// );
// console.log('starting deposit');
// try {
// await client.deposit(
// connection,
// mangoProgramId,
// mangoGroup,
// marginAccount,
// payer,
// new PublicKey('7KBVenLz5WNH4PA5MdGkJNpDDyNKnBQTwnz1UqJv9GUm'),
// new PublicKey('FNYRWcdcJn1YjWstQ7SGmSizgmERECfoknwk2cf1sQMe'),
// 1000,
// );
// } catch (e) {
// console.log('deposit error:', e);
// }
// console.log('deposit complete');
// }
// await testDeposit();
// await getMarginAccountDetails();
// await testSolink()
// testDepositSrm()
// }
// tests();