Skip to content

Commit 24ad046

Browse files
ChesterSimharsh4786
authored andcommitted
refactor(sdk): add fetch revenue share accounts, overrides for revenue share actions
1 parent 4e2cd95 commit 24ad046

File tree

2 files changed

+68
-8
lines changed

2 files changed

+68
-8
lines changed

sdk/src/accounts/fetch.ts

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import { Connection, PublicKey } from '@solana/web3.js';
2-
import { UserAccount, UserStatsAccount } from '../types';
32
import {
3+
RevenueShareAccount,
4+
RevenueShareEscrowAccount,
5+
UserAccount,
6+
UserStatsAccount,
7+
} from '../types';
8+
import {
9+
getRevenueShareAccountPublicKey,
10+
getRevenueShareEscrowAccountPublicKey,
411
getUserAccountPublicKey,
512
getUserStatsAccountPublicKey,
613
} from '../addresses/pda';
@@ -64,3 +71,45 @@ export async function fetchUserStatsAccount(
6471
) as UserStatsAccount)
6572
: undefined;
6673
}
74+
75+
export async function fetchRevenueShareAccount(
76+
connection: Connection,
77+
program: Program,
78+
authority: PublicKey
79+
): Promise<RevenueShareAccount | null> {
80+
const revenueShareAccountPublicKey = getRevenueShareAccountPublicKey(
81+
program.programId,
82+
authority
83+
);
84+
const accountInfo = await connection.getAccountInfo(
85+
revenueShareAccountPublicKey
86+
);
87+
if (!accountInfo) return null;
88+
return program.account.revenueShare.coder.accounts.decode(
89+
'RevenueShare',
90+
accountInfo.data
91+
) as RevenueShareAccount;
92+
}
93+
94+
export async function fetchRevenueShareEscrowAccount(
95+
connection: Connection,
96+
program: Program,
97+
authority: PublicKey
98+
): Promise<RevenueShareEscrowAccount | null> {
99+
const revenueShareEscrowPubKey = getRevenueShareEscrowAccountPublicKey(
100+
program.programId,
101+
authority
102+
);
103+
104+
const escrow = await connection.getAccountInfo(revenueShareEscrowPubKey);
105+
106+
if (!escrow) return null;
107+
108+
const escrowAccount =
109+
program.account.revenueShareEscrow.coder.accounts.decode(
110+
'RevenueShareEscrow',
111+
escrow.data
112+
) as RevenueShareEscrowAccount;
113+
114+
return escrowAccount;
115+
}

sdk/src/driftClient.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,7 +1255,10 @@ export class DriftClient {
12551255
}
12561256

12571257
public async getInitializeRevenueShareIx(
1258-
authority: PublicKey
1258+
authority: PublicKey,
1259+
overrides?: {
1260+
payer?: PublicKey;
1261+
}
12591262
): Promise<TransactionInstruction> {
12601263
const revenueShare = getRevenueShareAccountPublicKey(
12611264
this.program.programId,
@@ -1265,7 +1268,7 @@ export class DriftClient {
12651268
accounts: {
12661269
revenueShare,
12671270
authority,
1268-
payer: this.wallet.publicKey,
1271+
payer: overrides?.payer ?? this.wallet.publicKey,
12691272
rent: anchor.web3.SYSVAR_RENT_PUBKEY,
12701273
systemProgram: anchor.web3.SystemProgram.programId,
12711274
},
@@ -1288,7 +1291,10 @@ export class DriftClient {
12881291

12891292
public async getInitializeRevenueShareEscrowIx(
12901293
authority: PublicKey,
1291-
numOrders: number
1294+
numOrders: number,
1295+
overrides?: {
1296+
payer?: PublicKey;
1297+
}
12921298
): Promise<TransactionInstruction> {
12931299
const escrow = getRevenueShareEscrowAccountPublicKey(
12941300
this.program.programId,
@@ -1298,7 +1304,7 @@ export class DriftClient {
12981304
accounts: {
12991305
escrow,
13001306
authority,
1301-
payer: this.wallet.publicKey,
1307+
payer: overrides?.payer ?? this.wallet.publicKey,
13021308
userStats: getUserStatsAccountPublicKey(
13031309
this.program.programId,
13041310
authority
@@ -1411,9 +1417,14 @@ export class DriftClient {
14111417
public async getChangeApprovedBuilderIx(
14121418
builder: PublicKey,
14131419
maxFeeTenthBps: number,
1414-
add: boolean
1420+
add: boolean,
1421+
overrides?: {
1422+
authority?: PublicKey;
1423+
payer?: PublicKey;
1424+
}
14151425
): Promise<TransactionInstruction> {
1416-
const authority = this.wallet.publicKey;
1426+
const authority = overrides?.authority ?? this.wallet.publicKey;
1427+
const payer = overrides?.payer ?? this.wallet.publicKey;
14171428
const escrow = getRevenueShareEscrowAccountPublicKey(
14181429
this.program.programId,
14191430
authority
@@ -1426,7 +1437,7 @@ export class DriftClient {
14261437
accounts: {
14271438
escrow,
14281439
authority,
1429-
payer: this.wallet.publicKey,
1440+
payer,
14301441
systemProgram: anchor.web3.SystemProgram.programId,
14311442
},
14321443
}

0 commit comments

Comments
 (0)