Skip to content

Commit fb501fd

Browse files
✨ Improve compatibility when using the client SDK with React (#10)
1 parent 7511324 commit fb501fd

File tree

9 files changed

+17775
-1523
lines changed

9 files changed

+17775
-1523
lines changed

client/sdk/package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@magicblock-labs/soar-sdk",
3-
"version": "0.1.22",
3+
"version": "0.1.23",
44
"description": "Sdk bindings for the SOAR smart contract.",
55
"repository": {
66
"type": "git",
@@ -27,28 +27,29 @@
2727
"dependencies": {
2828
"@coral-xyz/anchor": "^0.27.0",
2929
"@metaplex-foundation/beet-solana": "^0.4.0",
30-
"@metaplex-foundation/js": "^0.19.3",
30+
"@metaplex-foundation/js": "^0.20.1",
3131
"@metaplex-foundation/mpl-token-metadata": "^2.13.0",
3232
"@solana/spl-token": "^0.3.8",
3333
"@solana/web3.js": "^1.73.2",
3434
"bn.js": "^5.2.1",
35-
"bs58": "^5.0.0",
36-
"tsx": "^3.12.3",
3735
"typescript": "*"
3836
},
3937
"devDependencies": {
4038
"@types/bn.js": "^5.1.2",
4139
"@types/chai": "^4.3.0",
4240
"@typescript-eslint/eslint-plugin": "^5.50.0",
4341
"@typescript-eslint/parser": "^5.50.0",
42+
"bs58": "^5.0.0",
4443
"chai": "^4.3.4",
4544
"eslint": "^8.33.0",
4645
"eslint-config-prettier": "^8.6.0",
4746
"eslint-plugin-import": "^2.25.3",
4847
"eslint-plugin-n": "^16.5.0",
4948
"eslint-plugin-react": "^7.32.2",
5049
"prettier": "^2.6.2",
50+
"tsx": "^3.12.3",
5151
"typedoc": "^0.25.1",
52-
"typedoc-plugin-markdown": "^3.16.0"
52+
"typedoc-plugin-markdown": "^3.16.0",
53+
"typescript": "*"
5354
}
5455
}

client/sdk/src/instructions/accountsBuilder.ts

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,23 @@ export class AccountsBuilder {
2323
}
2424

2525
initializeGameAccounts = async (
26-
game: PublicKey
26+
game: PublicKey,
27+
creator?: PublicKey
2728
): Promise<{
2829
creator: PublicKey;
2930
game: PublicKey;
3031
systemProgram: PublicKey;
3132
}> => {
3233
return {
33-
creator: this.provider.publicKey,
34+
creator: creator != null ? creator : this.provider.publicKey,
3435
game,
3536
systemProgram: SystemProgram.programId,
3637
};
3738
};
3839

3940
initializePlayerAccounts = async (
40-
user: PublicKey
41+
user: PublicKey,
42+
payer?: PublicKey
4143
): Promise<{
4244
playerAccount: PublicKey;
4345
user: PublicKey;
@@ -47,14 +49,15 @@ export class AccountsBuilder {
4749
return {
4850
playerAccount: this.utils.derivePlayerAddress(user)[0],
4951
user,
50-
payer: this.provider.publicKey,
52+
payer: payer != null ? payer : this.provider.publicKey,
5153
systemProgram: SystemProgram.programId,
5254
};
5355
};
5456

5557
initiateMergeAccounts = async (
5658
user: PublicKey,
57-
mergeAccount: PublicKey
59+
mergeAccount: PublicKey,
60+
payer?: PublicKey
5861
): Promise<{
5962
user: PublicKey;
6063
payer: PublicKey;
@@ -64,7 +67,7 @@ export class AccountsBuilder {
6467
}> => {
6568
return {
6669
user,
67-
payer: this.provider.publicKey,
70+
payer: payer != null ? payer : this.provider.publicKey,
6871
playerAccount: this.utils.derivePlayerAddress(user)[0],
6972
mergeAccount,
7073
systemProgram: SystemProgram.programId,
@@ -74,7 +77,8 @@ export class AccountsBuilder {
7477
addAchievementAccounts = async (
7578
game: PublicKey,
7679
authority: PublicKey,
77-
nextAchievement?: PublicKey
80+
nextAchievement?: PublicKey,
81+
payer?: PublicKey
7882
): Promise<{
7983
newAchievement: PublicKey;
8084
game: PublicKey;
@@ -92,7 +96,7 @@ export class AccountsBuilder {
9296
return {
9397
newAchievement,
9498
game,
95-
payer: this.provider.publicKey,
99+
payer: payer != null ? payer : this.provider.publicKey,
96100
authority,
97101
systemProgram: SystemProgram.programId,
98102
};
@@ -102,7 +106,8 @@ export class AccountsBuilder {
102106
game: PublicKey,
103107
authority: PublicKey,
104108
nextLeaderboard?: PublicKey,
105-
nullTopEntries?: boolean
109+
nullTopEntries?: boolean,
110+
payer?: PublicKey
106111
): Promise<{
107112
authority: PublicKey;
108113
game: PublicKey;
@@ -130,7 +135,7 @@ export class AccountsBuilder {
130135
return {
131136
authority,
132137
game,
133-
payer: this.provider.publicKey,
138+
payer: payer != null ? payer : this.provider.publicKey,
134139
leaderboard: newLeaderBoard,
135140
topEntries,
136141
systemProgram: SystemProgram.programId,
@@ -144,7 +149,8 @@ export class AccountsBuilder {
144149
sourceTokenAccount: PublicKey,
145150
tokenAccountOwner: PublicKey,
146151
mint: PublicKey,
147-
game?: PublicKey
152+
game?: PublicKey,
153+
payer?: PublicKey
148154
): Promise<{
149155
authority: PublicKey;
150156
payer: PublicKey;
@@ -162,7 +168,7 @@ export class AccountsBuilder {
162168

163169
return {
164170
authority,
165-
payer: this.provider.publicKey,
171+
payer: payer != null ? payer : this.provider.publicKey,
166172
game: gameAddress,
167173
achievement,
168174
newReward,
@@ -180,7 +186,8 @@ export class AccountsBuilder {
180186
achievement: PublicKey,
181187
collectionMint?: PublicKey,
182188
collectionUpdateAuthority?: PublicKey,
183-
game?: PublicKey
189+
game?: PublicKey,
190+
payer?: PublicKey
184191
): Promise<{
185192
authority: PublicKey;
186193
payer: PublicKey;
@@ -210,7 +217,7 @@ export class AccountsBuilder {
210217

211218
return {
212219
authority,
213-
payer: this.provider.publicKey,
220+
payer: payer != null ? payer : this.provider.publicKey,
214221
game: gameAddress,
215222
achievement,
216223
newReward,
@@ -314,7 +321,8 @@ export class AccountsBuilder {
314321
mint: PublicKey,
315322
user: PublicKey,
316323
reward?: PublicKey,
317-
game?: PublicKey
324+
game?: PublicKey,
325+
payer?: PublicKey
318326
): Promise<{
319327
user: PublicKey;
320328
authority: PublicKey;
@@ -375,7 +383,7 @@ export class AccountsBuilder {
375383
achievement,
376384
reward: rewardAddress,
377385
playerAchievement,
378-
payer: this.provider.publicKey,
386+
payer: payer != null ? payer : this.provider.publicKey,
379387
claim,
380388
newMint: mint,
381389
newMetadata: metadata,
@@ -392,7 +400,8 @@ export class AccountsBuilder {
392400
registerPlayerEntryAccounts = async (
393401
user: PublicKey,
394402
leaderboard: PublicKey,
395-
game?: PublicKey
403+
game?: PublicKey,
404+
payer?: PublicKey
396405
): Promise<{
397406
user: PublicKey;
398407
payer: PublicKey;
@@ -412,7 +421,7 @@ export class AccountsBuilder {
412421

413422
return {
414423
user,
415-
payer: this.provider.publicKey,
424+
payer: payer != null ? payer : this.provider.publicKey,
416425
playerAccount,
417426
newList,
418427
game: gameAddress,
@@ -425,7 +434,8 @@ export class AccountsBuilder {
425434
user: PublicKey,
426435
authority: PublicKey,
427436
leaderboard: PublicKey,
428-
game?: PublicKey
437+
game?: PublicKey,
438+
payer?: PublicKey
429439
): Promise<{
430440
payer: PublicKey;
431441
playerAccount: PublicKey;
@@ -448,7 +458,7 @@ export class AccountsBuilder {
448458
const topEntries = leaderboardAccount.topEntries;
449459

450460
return {
451-
payer: this.provider.publicKey,
461+
payer: payer != null ? payer : this.provider.publicKey,
452462
playerAccount,
453463
authority,
454464
game: gameAddress,
@@ -483,7 +493,8 @@ export class AccountsBuilder {
483493
authority: PublicKey,
484494
achievement: PublicKey,
485495
leaderboard: PublicKey,
486-
game?: PublicKey
496+
game?: PublicKey,
497+
payer?: PublicKey
487498
): Promise<{
488499
payer: PublicKey;
489500
playerAccount: PublicKey;
@@ -507,7 +518,7 @@ export class AccountsBuilder {
507518
)[0];
508519

509520
return {
510-
payer: this.provider.publicKey,
521+
payer: payer != null ? payer : this.provider.publicKey,
511522
playerAccount,
512523
playerScores: playerEntryList,
513524
game: gameAddress,
@@ -519,15 +530,16 @@ export class AccountsBuilder {
519530

520531
updateGameAccounts = async (
521532
game: PublicKey,
522-
authority: PublicKey
533+
authority: PublicKey,
534+
payer?: PublicKey
523535
): Promise<{
524536
payer: PublicKey;
525537
game: PublicKey;
526538
authority: PublicKey;
527539
systemProgram: PublicKey;
528540
}> => {
529541
return {
530-
payer: this.provider.publicKey,
542+
payer: payer != null ? payer : this.provider.publicKey,
531543
game,
532544
authority,
533545
systemProgram: SystemProgram.programId,
@@ -573,7 +585,8 @@ export class AccountsBuilder {
573585
achievement: PublicKey,
574586
mint: PublicKey,
575587
reward?: PublicKey,
576-
game?: PublicKey
588+
game?: PublicKey,
589+
payer?: PublicKey
577590
): Promise<{
578591
payer: PublicKey;
579592
user: PublicKey;
@@ -637,7 +650,7 @@ export class AccountsBuilder {
637650
this.utils.deriveEditionAddress(collectionMint)[0];
638651

639652
return {
640-
payer: this.provider.publicKey,
653+
payer: payer != null ? payer : this.provider.publicKey,
641654
user,
642655
playerAccount,
643656
achievement,

0 commit comments

Comments
 (0)