From bf64c97511d9e01fbf3c20ced2aecd6b9e7fbfa5 Mon Sep 17 00:00:00 2001 From: dd Date: Sun, 7 Feb 2021 17:25:08 -0500 Subject: [PATCH] updated devnet.env --- devnet.env | 2 +- src/index.ts | 119 ++++++++++++++++++++++++++------------------------- 2 files changed, 61 insertions(+), 60 deletions(-) diff --git a/devnet.env b/devnet.env index b47c987..c39564c 100644 --- a/devnet.env +++ b/devnet.env @@ -1,6 +1,6 @@ CLUSTER=devnet DEX_PROGRAM_ID=9MVDeYQnJmN2Dt7H44Z8cob4bET2ysdNu2uFJcatDJno KEYPAIR=~/.config/solana/id.json -BTCUSD=D9CBrNncuERiTzQwUVkxCevrM6irHJybeU2NQXtgXRbq +BTCUSD=6pZpjgfwKJhQ93ZYNjbJFtWEaB8kZjErsiGAEXn9WNjn BTC_WALLET=HLoPtihB8oETm1kkTpx17FEnXm7afQdS4hojTNvbg3Rg USDC_WALLET=GBBtcVE7WA8qdrHyhWTZkYDaz71EVHsg7wVaca9iq9xs diff --git a/src/index.ts b/src/index.ts index 76f6b49..1f77ead 100644 --- a/src/index.ts +++ b/src/index.ts @@ -11,65 +11,66 @@ 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("58hhPAgRgk1BHM1UkvYnJfxpMcoyi3DSoKnkwxuFe47") -// 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)) -// } +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() { // const cluster = "devnet"