Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Improve compatibility when using the client SDK with React #10

Merged
merged 1 commit into from
Apr 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions client/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@magicblock-labs/soar-sdk",
"version": "0.1.22",
"version": "0.1.23",
"description": "Sdk bindings for the SOAR smart contract.",
"repository": {
"type": "git",
Expand All @@ -27,28 +27,29 @@
"dependencies": {
"@coral-xyz/anchor": "^0.27.0",
"@metaplex-foundation/beet-solana": "^0.4.0",
"@metaplex-foundation/js": "^0.19.3",
"@metaplex-foundation/js": "^0.20.1",
"@metaplex-foundation/mpl-token-metadata": "^2.13.0",
"@solana/spl-token": "^0.3.8",
"@solana/web3.js": "^1.73.2",
"bn.js": "^5.2.1",
"bs58": "^5.0.0",
"tsx": "^3.12.3",
"typescript": "*"
},
"devDependencies": {
"@types/bn.js": "^5.1.2",
"@types/chai": "^4.3.0",
"@typescript-eslint/eslint-plugin": "^5.50.0",
"@typescript-eslint/parser": "^5.50.0",
"bs58": "^5.0.0",
"chai": "^4.3.4",
"eslint": "^8.33.0",
"eslint-config-prettier": "^8.6.0",
"eslint-plugin-import": "^2.25.3",
"eslint-plugin-n": "^16.5.0",
"eslint-plugin-react": "^7.32.2",
"prettier": "^2.6.2",
"tsx": "^3.12.3",
"typedoc": "^0.25.1",
"typedoc-plugin-markdown": "^3.16.0"
"typedoc-plugin-markdown": "^3.16.0",
"typescript": "*"
}
}
65 changes: 39 additions & 26 deletions client/sdk/src/instructions/accountsBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,23 @@ export class AccountsBuilder {
}

initializeGameAccounts = async (
game: PublicKey
game: PublicKey,
creator?: PublicKey
): Promise<{
creator: PublicKey;
game: PublicKey;
systemProgram: PublicKey;
}> => {
return {
creator: this.provider.publicKey,
creator: creator != null ? creator : this.provider.publicKey,
game,
systemProgram: SystemProgram.programId,
};
};

initializePlayerAccounts = async (
user: PublicKey
user: PublicKey,
payer?: PublicKey
): Promise<{
playerAccount: PublicKey;
user: PublicKey;
Expand All @@ -47,14 +49,15 @@ export class AccountsBuilder {
return {
playerAccount: this.utils.derivePlayerAddress(user)[0],
user,
payer: this.provider.publicKey,
payer: payer != null ? payer : this.provider.publicKey,
systemProgram: SystemProgram.programId,
};
};

initiateMergeAccounts = async (
user: PublicKey,
mergeAccount: PublicKey
mergeAccount: PublicKey,
payer?: PublicKey
): Promise<{
user: PublicKey;
payer: PublicKey;
Expand All @@ -64,7 +67,7 @@ export class AccountsBuilder {
}> => {
return {
user,
payer: this.provider.publicKey,
payer: payer != null ? payer : this.provider.publicKey,
playerAccount: this.utils.derivePlayerAddress(user)[0],
mergeAccount,
systemProgram: SystemProgram.programId,
Expand All @@ -74,7 +77,8 @@ export class AccountsBuilder {
addAchievementAccounts = async (
game: PublicKey,
authority: PublicKey,
nextAchievement?: PublicKey
nextAchievement?: PublicKey,
payer?: PublicKey
): Promise<{
newAchievement: PublicKey;
game: PublicKey;
Expand All @@ -92,7 +96,7 @@ export class AccountsBuilder {
return {
newAchievement,
game,
payer: this.provider.publicKey,
payer: payer != null ? payer : this.provider.publicKey,
authority,
systemProgram: SystemProgram.programId,
};
Expand All @@ -102,7 +106,8 @@ export class AccountsBuilder {
game: PublicKey,
authority: PublicKey,
nextLeaderboard?: PublicKey,
nullTopEntries?: boolean
nullTopEntries?: boolean,
payer?: PublicKey
): Promise<{
authority: PublicKey;
game: PublicKey;
Expand Down Expand Up @@ -130,7 +135,7 @@ export class AccountsBuilder {
return {
authority,
game,
payer: this.provider.publicKey,
payer: payer != null ? payer : this.provider.publicKey,
leaderboard: newLeaderBoard,
topEntries,
systemProgram: SystemProgram.programId,
Expand All @@ -144,7 +149,8 @@ export class AccountsBuilder {
sourceTokenAccount: PublicKey,
tokenAccountOwner: PublicKey,
mint: PublicKey,
game?: PublicKey
game?: PublicKey,
payer?: PublicKey
): Promise<{
authority: PublicKey;
payer: PublicKey;
Expand All @@ -162,7 +168,7 @@ export class AccountsBuilder {

return {
authority,
payer: this.provider.publicKey,
payer: payer != null ? payer : this.provider.publicKey,
game: gameAddress,
achievement,
newReward,
Expand All @@ -180,7 +186,8 @@ export class AccountsBuilder {
achievement: PublicKey,
collectionMint?: PublicKey,
collectionUpdateAuthority?: PublicKey,
game?: PublicKey
game?: PublicKey,
payer?: PublicKey
): Promise<{
authority: PublicKey;
payer: PublicKey;
Expand Down Expand Up @@ -210,7 +217,7 @@ export class AccountsBuilder {

return {
authority,
payer: this.provider.publicKey,
payer: payer != null ? payer : this.provider.publicKey,
game: gameAddress,
achievement,
newReward,
Expand Down Expand Up @@ -314,7 +321,8 @@ export class AccountsBuilder {
mint: PublicKey,
user: PublicKey,
reward?: PublicKey,
game?: PublicKey
game?: PublicKey,
payer?: PublicKey
): Promise<{
user: PublicKey;
authority: PublicKey;
Expand Down Expand Up @@ -375,7 +383,7 @@ export class AccountsBuilder {
achievement,
reward: rewardAddress,
playerAchievement,
payer: this.provider.publicKey,
payer: payer != null ? payer : this.provider.publicKey,
claim,
newMint: mint,
newMetadata: metadata,
Expand All @@ -392,7 +400,8 @@ export class AccountsBuilder {
registerPlayerEntryAccounts = async (
user: PublicKey,
leaderboard: PublicKey,
game?: PublicKey
game?: PublicKey,
payer?: PublicKey
): Promise<{
user: PublicKey;
payer: PublicKey;
Expand All @@ -412,7 +421,7 @@ export class AccountsBuilder {

return {
user,
payer: this.provider.publicKey,
payer: payer != null ? payer : this.provider.publicKey,
playerAccount,
newList,
game: gameAddress,
Expand All @@ -425,7 +434,8 @@ export class AccountsBuilder {
user: PublicKey,
authority: PublicKey,
leaderboard: PublicKey,
game?: PublicKey
game?: PublicKey,
payer?: PublicKey
): Promise<{
payer: PublicKey;
playerAccount: PublicKey;
Expand All @@ -448,7 +458,7 @@ export class AccountsBuilder {
const topEntries = leaderboardAccount.topEntries;

return {
payer: this.provider.publicKey,
payer: payer != null ? payer : this.provider.publicKey,
playerAccount,
authority,
game: gameAddress,
Expand Down Expand Up @@ -483,7 +493,8 @@ export class AccountsBuilder {
authority: PublicKey,
achievement: PublicKey,
leaderboard: PublicKey,
game?: PublicKey
game?: PublicKey,
payer?: PublicKey
): Promise<{
payer: PublicKey;
playerAccount: PublicKey;
Expand All @@ -507,7 +518,7 @@ export class AccountsBuilder {
)[0];

return {
payer: this.provider.publicKey,
payer: payer != null ? payer : this.provider.publicKey,
playerAccount,
playerScores: playerEntryList,
game: gameAddress,
Expand All @@ -519,15 +530,16 @@ export class AccountsBuilder {

updateGameAccounts = async (
game: PublicKey,
authority: PublicKey
authority: PublicKey,
payer?: PublicKey
): Promise<{
payer: PublicKey;
game: PublicKey;
authority: PublicKey;
systemProgram: PublicKey;
}> => {
return {
payer: this.provider.publicKey,
payer: payer != null ? payer : this.provider.publicKey,
game,
authority,
systemProgram: SystemProgram.programId,
Expand Down Expand Up @@ -573,7 +585,8 @@ export class AccountsBuilder {
achievement: PublicKey,
mint: PublicKey,
reward?: PublicKey,
game?: PublicKey
game?: PublicKey,
payer?: PublicKey
): Promise<{
payer: PublicKey;
user: PublicKey;
Expand Down Expand Up @@ -637,7 +650,7 @@ export class AccountsBuilder {
this.utils.deriveEditionAddress(collectionMint)[0];

return {
payer: this.provider.publicKey,
payer: payer != null ? payer : this.provider.publicKey,
user,
playerAccount,
achievement,
Expand Down
Loading
Loading