Skip to content

Commit

Permalink
add sdk method
Browse files Browse the repository at this point in the history
  • Loading branch information
crispheaney committed Oct 13, 2023
1 parent a0295ff commit 354fd93
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 0 deletions.
55 changes: 55 additions & 0 deletions ts/sdk/src/jitProxyClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
BN,
DriftClient,
isVariant,
MakerInfo,
MarketType,
PostOnlyParams,
QUOTE_SPOT_MARKET_INDEX,
Expand Down Expand Up @@ -180,4 +181,58 @@ export class JitProxyClient {
.remainingAccounts(remainingAccounts)
.instruction();
}

public async arbPerp(
params: {
makerInfos: MakerInfo[];
marketIndex: number;
},
txParams?: TxParams
): Promise<TxSigAndSlot> {
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<TransactionInstruction> {
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();
}
}
72 changes: 72 additions & 0 deletions ts/sdk/src/types/jit_proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down Expand Up @@ -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: [
{
Expand Down

0 comments on commit 354fd93

Please sign in to comment.