cleaned up index.ts

This commit is contained in:
dd 2021-02-07 17:26:42 -05:00
parent bf64c97511
commit 66558f28d7
1 changed files with 59 additions and 59 deletions

View File

@ -11,65 +11,65 @@ export { NUM_TOKENS } from './layout';
import IDS from "./ids.json";
export { IDS }
async function main() {
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_USDC.mango_group_pk);
const mangoProgramId = new PublicKey(clusterIds.mango_program_id);
const mangoGroup = await client.getMangoGroup(connection, mangoGroupPk);
const keyPairPath = '/home/dd/.config/solana/id.json'
const payer = new Account(JSON.parse(fs.readFileSync(keyPairPath, 'utf-8')))
// TODO auto fetch
const marginAccountPk = new PublicKey("DrKz21L9EqmykcEtiX3sY7ibHbVezgSY225upn3UA8Ju")
let marginAccount = await client.getMarginAccount(connection, marginAccountPk)
console.log(marginAccount.toPrettyString(mangoGroup))
const marketIndex = 0 // index for BTC/USDC
const spotMarket = await Market.load(
connection,
mangoGroup.spotMarkets[marketIndex],
{skipPreflight: true, commitment: 'singleGossip'},
mangoGroup.dexProgramId
)
// // margin short 0.1 BTC
// await client.placeOrder(
// connection,
// mangoProgramId,
// mangoGroup,
// marginAccount,
// spotMarket,
// payer,
// 'sell',
// 30000,
// 0.1
// )
//
// await spotMarket.matchOrders(connection, payer, 10)
//
await client.settleFunds(
connection,
mangoProgramId,
mangoGroup,
marginAccount,
payer,
spotMarket
)
//
// await client.settleBorrow(connection, mangoProgramId, mangoGroup, marginAccount, payer, mangoGroup.tokens[2], 5000)
// await client.settleBorrow(connection, mangoProgramId, mangoGroup, marginAccount, payer, mangoGroup.tokens[0], 1.0)
marginAccount = await client.getMarginAccount(connection, marginAccount.publicKey)
console.log(marginAccount.toPrettyString(mangoGroup))
}
main()
// async function main() {
// 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_USDC.mango_group_pk);
// const mangoProgramId = new PublicKey(clusterIds.mango_program_id);
//
// const mangoGroup = await client.getMangoGroup(connection, mangoGroupPk);
//
// const keyPairPath = '/home/dd/.config/solana/id.json'
// const payer = new Account(JSON.parse(fs.readFileSync(keyPairPath, 'utf-8')))
//
// // TODO auto fetch
// const marginAccountPk = new PublicKey("DrKz21L9EqmykcEtiX3sY7ibHbVezgSY225upn3UA8Ju")
// let marginAccount = await client.getMarginAccount(connection, marginAccountPk)
//
// console.log(marginAccount.toPrettyString(mangoGroup))
//
// const marketIndex = 0 // index for BTC/USDC
// const spotMarket = await Market.load(
// connection,
// mangoGroup.spotMarkets[marketIndex],
// {skipPreflight: true, commitment: 'singleGossip'},
// mangoGroup.dexProgramId
// )
//
// // // margin short 0.1 BTC
// // await client.placeOrder(
// // connection,
// // mangoProgramId,
// // mangoGroup,
// // marginAccount,
// // spotMarket,
// // payer,
// // 'sell',
// // 30000,
// // 0.1
// // )
// //
// // await spotMarket.matchOrders(connection, payer, 10)
// //
// await client.settleFunds(
// connection,
// mangoProgramId,
// mangoGroup,
// marginAccount,
// payer,
// spotMarket
// )
// //
// // await client.settleBorrow(connection, mangoProgramId, mangoGroup, marginAccount, payer, mangoGroup.tokens[2], 5000)
// // await client.settleBorrow(connection, mangoProgramId, mangoGroup, marginAccount, payer, mangoGroup.tokens[0], 1.0)
//
// marginAccount = await client.getMarginAccount(connection, marginAccount.publicKey)
// console.log(marginAccount.toPrettyString(mangoGroup))
// }
// main()
//
// async function testAll() {