Skip to content

Commit cc88d50

Browse files
ChesterSim0xbigz
authored andcommitted
refactor(sdk): add update delegate ix method, ovrride authority for settle multiple pnl (#1822)
1 parent b0662f8 commit cc88d50

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

sdk/src/driftClient.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1587,6 +1587,26 @@ export class DriftClient {
15871587
return txSig;
15881588
}
15891589

1590+
public async getUpdateUserDelegateIx(
1591+
delegate: PublicKey,
1592+
overrides: {
1593+
subAccountId?: number,
1594+
userAccountPublicKey?: PublicKey,
1595+
authority?: PublicKey,
1596+
}
1597+
): Promise<TransactionInstruction> {
1598+
const subAccountId = overrides.subAccountId ?? this.activeSubAccountId;
1599+
const userAccountPublicKey = overrides.userAccountPublicKey ?? await this.getUserAccountPublicKey();
1600+
const authority = overrides.authority ?? this.wallet.publicKey;
1601+
1602+
return await this.program.instruction.updateUserDelegate(subAccountId, delegate, {
1603+
accounts: {
1604+
user: userAccountPublicKey,
1605+
authority,
1606+
},
1607+
});
1608+
}
1609+
15901610
public async updateUserDelegate(
15911611
delegate: PublicKey,
15921612
subAccountId = 0
@@ -7406,7 +7426,10 @@ export class DriftClient {
74067426
settleeUserAccountPublicKey: PublicKey,
74077427
settleeUserAccount: UserAccount,
74087428
marketIndexes: number[],
7409-
mode: SettlePnlMode
7429+
mode: SettlePnlMode,
7430+
overrides?: {
7431+
authority?: PublicKey;
7432+
}
74107433
): Promise<TransactionInstruction> {
74117434
const remainingAccounts = this.getRemainingAccounts({
74127435
userAccounts: [settleeUserAccount],
@@ -7420,7 +7443,7 @@ export class DriftClient {
74207443
{
74217444
accounts: {
74227445
state: await this.getStatePublicKey(),
7423-
authority: this.wallet.publicKey,
7446+
authority: overrides?.authority ?? this.wallet.publicKey,
74247447
user: settleeUserAccountPublicKey,
74257448
spotMarketVault: this.getQuoteSpotMarketAccount().vault,
74267449
},

sdk/src/tx/txHandler.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ export class TxHandler {
133133
this.preSignedCb = props.opts?.preSignedCb;
134134
}
135135

136+
public getWallet() {
137+
return this.wallet;
138+
}
139+
136140
private addHashAndExpiryToLookup(
137141
hashAndExpiry: BlockhashWithExpiryBlockHeight
138142
) {

0 commit comments

Comments
 (0)