From 354fd93a75602a9ab486605779d77b03090be45f Mon Sep 17 00:00:00 2001 From: Chris Heaney Date: Fri, 13 Oct 2023 09:05:12 -0400 Subject: [PATCH] add sdk method --- ts/sdk/src/jitProxyClient.ts | 55 ++++++++++++++++++++++++++ ts/sdk/src/types/jit_proxy.ts | 72 +++++++++++++++++++++++++++++++++++ 2 files changed, 127 insertions(+) diff --git a/ts/sdk/src/jitProxyClient.ts b/ts/sdk/src/jitProxyClient.ts index 4b771259..f70ccad8 100644 --- a/ts/sdk/src/jitProxyClient.ts +++ b/ts/sdk/src/jitProxyClient.ts @@ -2,6 +2,7 @@ import { BN, DriftClient, isVariant, + MakerInfo, MarketType, PostOnlyParams, QUOTE_SPOT_MARKET_INDEX, @@ -180,4 +181,58 @@ export class JitProxyClient { .remainingAccounts(remainingAccounts) .instruction(); } + + public async arbPerp( + params: { + makerInfos: MakerInfo[]; + marketIndex: number; + }, + txParams?: TxParams + ): Promise { + const ix = await this.getArbPerpIx(params); + const tx = await this.driftClient.buildTransaction([ix], txParams); + return await this.driftClient.sendTransaction(tx); + } + + public async getArbPerpIx({ + makerInfos, + marketIndex, + }: { + makerInfos: MakerInfo[]; + marketIndex: number; + }): Promise { + const userAccounts = [this.driftClient.getUserAccount()]; + for (const makerInfo of makerInfos) { + userAccounts.push(makerInfo.makerUserAccount); + } + + const remainingAccounts = this.driftClient.getRemainingAccounts({ + userAccounts, + writablePerpMarketIndexes: [marketIndex], + }); + + for (const makerInfo of makerInfos) { + remainingAccounts.push({ + pubkey: makerInfo.maker, + isWritable: true, + isSigner: false, + }); + remainingAccounts.push({ + pubkey: makerInfo.makerStats, + isWritable: true, + isSigner: false, + }); + } + + return this.program.methods + .arbPerp(marketIndex) + .accounts({ + state: await this.driftClient.getStatePublicKey(), + user: await this.driftClient.getUserAccountPublicKey(), + userStats: this.driftClient.getUserStatsAccountPublicKey(), + driftProgram: this.driftClient.program.programId, + }) + .remainingAccounts(remainingAccounts) + .instruction(); + } } diff --git a/ts/sdk/src/types/jit_proxy.ts b/ts/sdk/src/types/jit_proxy.ts index 0d9cb6f3..d5e8a331 100644 --- a/ts/sdk/src/types/jit_proxy.ts +++ b/ts/sdk/src/types/jit_proxy.ts @@ -69,6 +69,42 @@ export type JitProxy = { }; } ]; + }, + { + name: 'arbPerp'; + accounts: [ + { + name: 'state'; + isMut: false; + isSigner: false; + }, + { + name: 'user'; + isMut: true; + isSigner: false; + }, + { + name: 'userStats'; + isMut: true; + isSigner: false; + }, + { + name: 'authority'; + isMut: false; + isSigner: true; + }, + { + name: 'driftProgram'; + isMut: false; + isSigner: false; + } + ]; + args: [ + { + name: 'marketIndex'; + type: 'u16'; + } + ]; } ]; types: [ @@ -302,6 +338,42 @@ export const IDL: JitProxy = { }, ], }, + { + name: 'arbPerp', + accounts: [ + { + name: 'state', + isMut: false, + isSigner: false, + }, + { + name: 'user', + isMut: true, + isSigner: false, + }, + { + name: 'userStats', + isMut: true, + isSigner: false, + }, + { + name: 'authority', + isMut: false, + isSigner: true, + }, + { + name: 'driftProgram', + isMut: false, + isSigner: false, + }, + ], + args: [ + { + name: 'marketIndex', + type: 'u16', + }, + ], + }, ], types: [ {