From 16a41dfe38a54f8d8a90aa7488efd0b7928bfd05 Mon Sep 17 00:00:00 2001 From: microwavedcola1 Date: Wed, 22 Feb 2023 15:08:05 +0100 Subject: [PATCH 01/11] Fix extraction of amount for token account and mm Procfile Signed-off-by: microwavedcola1 --- Procfile | 2 +- ts/client/scripts/debug-scripts/debug-banks.ts | 14 +++++--------- ts/client/src/accounts/group.ts | 9 +++++++-- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/Procfile b/Procfile index b027e1d26..bdfc18d56 100644 --- a/Procfile +++ b/Procfile @@ -1 +1 @@ -mm: node dist/cjs/src/scripts/mm/market-maker.js \ No newline at end of file +mm: node dist/cjs/scripts/mm/market-maker.js \ No newline at end of file diff --git a/ts/client/scripts/debug-scripts/debug-banks.ts b/ts/client/scripts/debug-scripts/debug-banks.ts index 540d437a4..5e8cfabc8 100644 --- a/ts/client/scripts/debug-scripts/debug-banks.ts +++ b/ts/client/scripts/debug-scripts/debug-banks.ts @@ -1,5 +1,5 @@ import { AnchorProvider, Wallet } from '@coral-xyz/anchor'; -import { coder } from '@coral-xyz/anchor/dist/cjs/spl/token'; +import { getAccount } from '@solana/spl-token'; import { Cluster, Connection, Keypair } from '@solana/web3.js'; import * as dotenv from 'dotenv'; import fs from 'fs'; @@ -75,15 +75,11 @@ async function main(): Promise { for (const bank of await Array.from(banksMapUsingTokenIndex.values()).sort( (a, b) => a.tokenIndex - b.tokenIndex, )) { - const vault = I80F48.fromNumber( - coder() - .accounts.decode( - 'token', - (await client.program.provider.connection.getAccountInfo(bank.vault))! - .data, - ) - .amount.toNumber(), + const account = await getAccount( + client.program.provider.connection, + bank.vault, ); + const vault = I80F48.fromNumber(Number(account.amount)); const error = vault.sub( (bank as any).indexedDepositsByMangoAccounts diff --git a/ts/client/src/accounts/group.ts b/ts/client/src/accounts/group.ts index ae9cf6126..a29dc481b 100644 --- a/ts/client/src/accounts/group.ts +++ b/ts/client/src/accounts/group.ts @@ -1,6 +1,7 @@ import { BorshAccountsCoder } from '@coral-xyz/anchor'; import { Market, Orderbook } from '@project-serum/serum'; import { parsePriceData } from '@pythnetwork/client'; +import { TOKEN_PROGRAM_ID, unpackAccount } from '@solana/spl-token'; import { AccountInfo, AddressLookupTableAccount, @@ -414,8 +415,12 @@ export class Group { if (!vaultAi) { throw new Error(`Undefined vaultAi for ${vaultPks[i]}`!); } - const vaultAmount = coder.decode('token', vaultAi.data).amount; - return [vaultPks[i].toBase58(), vaultAmount]; + const vaultAmount = unpackAccount( + vaultPks[i], + vaultAi, + TOKEN_PROGRAM_ID, + ).amount; + return [vaultPks[i].toBase58(), new BN(Number(vaultAmount))]; }), ); } From 1a9f28f3fa89eb6c5906172e02a24366ada438aa Mon Sep 17 00:00:00 2001 From: tjs Date: Wed, 22 Feb 2023 12:18:26 -0500 Subject: [PATCH 02/11] include scripts in commonjs build --- tsconfig.cjs.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tsconfig.cjs.json b/tsconfig.cjs.json index b43dfbcaf..eada290e8 100644 --- a/tsconfig.cjs.json +++ b/tsconfig.cjs.json @@ -6,5 +6,6 @@ "declaration": true, "declarationMap": false, "sourceMap": false - } + }, + "include": ["ts/client/src", "ts/client/scripts"] } From 5c5638ab8d478632e41d847432e4cb170b7853ed Mon Sep 17 00:00:00 2001 From: tjs Date: Wed, 22 Feb 2023 15:18:02 -0500 Subject: [PATCH 03/11] deploy latest main to npm 0.5.22 --- package.json | 2 +- ts/client/scripts/token-spec.ts | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/package.json b/package.json index 85a9173c1..fbfa8a159 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@blockworks-foundation/mango-v4", - "version": "0.5.21", + "version": "0.5.22", "description": "Typescript Client for mango-v4 program.", "repository": "https://github.com/blockworks-foundation/mango-v4", "author": { diff --git a/ts/client/scripts/token-spec.ts b/ts/client/scripts/token-spec.ts index 29c3634cd..5f14526b9 100644 --- a/ts/client/scripts/token-spec.ts +++ b/ts/client/scripts/token-spec.ts @@ -68,7 +68,6 @@ async function main() { // get from jup api? // how does the oracle look like? - // how was the price volatility yday? } From f9bc74b48f4ea24f78c5a2ad09256eb8a0f086c8 Mon Sep 17 00:00:00 2001 From: tjs Date: Thu, 23 Feb 2023 13:00:22 -0500 Subject: [PATCH 04/11] fix return type on perp loadFills --- ts/client/src/accounts/perp.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ts/client/src/accounts/perp.ts b/ts/client/src/accounts/perp.ts index 4f02bb71b..a4588e4dd 100644 --- a/ts/client/src/accounts/perp.ts +++ b/ts/client/src/accounts/perp.ts @@ -312,7 +312,7 @@ export class PerpMarket { public async loadFills( client: MangoClient, lastSeqNum: BN = new BN(0), - ): Promise<(OutEvent | FillEvent | LiquidateEvent)[]> { + ): Promise { const eventQueue = await this.loadEventQueue(client); return eventQueue .eventsSince(lastSeqNum) From a77affa5becce183f151b99c28cf653e422db897 Mon Sep 17 00:00:00 2001 From: tjs Date: Thu, 23 Feb 2023 13:35:48 -0500 Subject: [PATCH 05/11] 0.5.23 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index fbfa8a159..47ca5face 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@blockworks-foundation/mango-v4", - "version": "0.5.22", + "version": "0.5.23", "description": "Typescript Client for mango-v4 program.", "repository": "https://github.com/blockworks-foundation/mango-v4", "author": { From 6c5c88b1e649ac409e7ff6e0efb35dedd0aeccab Mon Sep 17 00:00:00 2001 From: microwavedcola1 Date: Wed, 1 Mar 2023 12:12:01 +0100 Subject: [PATCH 06/11] fix access specifier Signed-off-by: microwavedcola1 --- ts/client/src/accounts/perp.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ts/client/src/accounts/perp.ts b/ts/client/src/accounts/perp.ts index a4588e4dd..8b9f6640d 100644 --- a/ts/client/src/accounts/perp.ts +++ b/ts/client/src/accounts/perp.ts @@ -8,10 +8,10 @@ import { I80F48, I80F48Dto, ZERO_I80F48 } from '../numbers/I80F48'; import { Modify } from '../types'; import { As, + QUOTE_DECIMALS, U64_MAX_BN, toNative, toUiDecimals, - QUOTE_DECIMALS, } from '../utils'; import { OracleConfig, @@ -198,7 +198,7 @@ export class PerpMarket { public reduceOnly: boolean, maintOverallAssetWeight: I80F48Dto, initOverallAssetWeight: I80F48Dto, - positivePnlLiquidationFee: I80F48Dto, + public positivePnlLiquidationFee: I80F48Dto, ) { this.name = utf8.decode(new Uint8Array(name)).split('\x00')[0]; this.oracleConfig = { From 925440b47e406a5c1b3615b209c18bfdb0a54310 Mon Sep 17 00:00:00 2001 From: microwavedcola1 Date: Wed, 1 Mar 2023 12:17:46 +0100 Subject: [PATCH 07/11] Fix type Signed-off-by: microwavedcola1 --- ts/client/src/accounts/perp.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ts/client/src/accounts/perp.ts b/ts/client/src/accounts/perp.ts index 8b9f6640d..7ca6a5baf 100644 --- a/ts/client/src/accounts/perp.ts +++ b/ts/client/src/accounts/perp.ts @@ -1026,8 +1026,8 @@ export interface FillEvent extends Event { takerOrderId: BN; takerClientOrderId: BN; takerFee: number; - price: BN; - quantity: BN; + price: number; + quantity: number; } export interface LiquidateEvent extends Event { From cd87b334005f1d70520fe8a874e3909584afdf4a Mon Sep 17 00:00:00 2001 From: microwavedcola1 Date: Wed, 1 Mar 2023 12:20:50 +0100 Subject: [PATCH 08/11] v0.5.24 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 47ca5face..1991a6fb2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@blockworks-foundation/mango-v4", - "version": "0.5.23", + "version": "0.5.24", "description": "Typescript Client for mango-v4 program.", "repository": "https://github.com/blockworks-foundation/mango-v4", "author": { From f192c19fb847249575c85a319fbe35cec111767d Mon Sep 17 00:00:00 2001 From: microwavedcola1 Date: Wed, 1 Mar 2023 12:28:59 +0100 Subject: [PATCH 09/11] Fix type Signed-off-by: microwavedcola1 --- ts/client/src/accounts/perp.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ts/client/src/accounts/perp.ts b/ts/client/src/accounts/perp.ts index 7ca6a5baf..3ddf74043 100644 --- a/ts/client/src/accounts/perp.ts +++ b/ts/client/src/accounts/perp.ts @@ -50,6 +50,7 @@ export class PerpMarket { public feesSettled: I80F48; public maintOverallAssetWeight: I80F48; public initOverallAssetWeight: I80F48; + public positivePnlLiquidationFee: I80F48; public _price: I80F48; public _uiPrice: number; @@ -198,7 +199,7 @@ export class PerpMarket { public reduceOnly: boolean, maintOverallAssetWeight: I80F48Dto, initOverallAssetWeight: I80F48Dto, - public positivePnlLiquidationFee: I80F48Dto, + positivePnlLiquidationFee: I80F48Dto, ) { this.name = utf8.decode(new Uint8Array(name)).split('\x00')[0]; this.oracleConfig = { @@ -220,6 +221,7 @@ export class PerpMarket { this.feesSettled = I80F48.from(feesSettled); this.maintOverallAssetWeight = I80F48.from(maintOverallAssetWeight); this.initOverallAssetWeight = I80F48.from(initOverallAssetWeight); + this.positivePnlLiquidationFee = I80F48.from(positivePnlLiquidationFee); this.priceLotsToUiConverter = new Big(10) .pow(baseDecimals - QUOTE_DECIMALS) From 8ec2a458a86d4e14320f684af39344f39013719d Mon Sep 17 00:00:00 2001 From: microwavedcola1 Date: Wed, 1 Mar 2023 12:41:49 +0100 Subject: [PATCH 10/11] v0.5.25 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1991a6fb2..f882b38d3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@blockworks-foundation/mango-v4", - "version": "0.5.24", + "version": "0.5.25", "description": "Typescript Client for mango-v4 program.", "repository": "https://github.com/blockworks-foundation/mango-v4", "author": { From 2d1f9bb20794b5f16b39a981b5efbd3bdea4a506 Mon Sep 17 00:00:00 2001 From: microwavedcola1 Date: Sat, 4 Mar 2023 12:50:28 +0100 Subject: [PATCH 11/11] add sol qouting to config Signed-off-by: microwavedcola1 --- ts/client/scripts/mm/params/default.json | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/ts/client/scripts/mm/params/default.json b/ts/client/scripts/mm/params/default.json index a681de704..87a4749c8 100644 --- a/ts/client/scripts/mm/params/default.json +++ b/ts/client/scripts/mm/params/default.json @@ -13,6 +13,17 @@ "spammerCharge": 2, "krakenCode": "XXBTZUSD" } + }, + "SOL": { + "perp": { + "sizePerc": 0.75, + "leanCoeff": 0.00025, + "bias": 0.0, + "requoteThresh": 0.0002, + "takeSpammers": true, + "spammerCharge": 2, + "krakenCode": "SOLUSD" + } } } }