Skip to content

Commit cb857cc

Browse files
⚡ Add a configurable option to determine whether to allow multiple scores per player or not. (#9)
* 📝 Add Issues and PR template * ✨ Add scores deduplication * ✨ Add configurable option to allow multiple scores per player Add configurable option wether to allow or not multiple scores per player * ♻️ Remove package lock * ♻️ Reset yarn lock * ♻️ Code Refactoring * 🔖 Program v0.1.1 * 📝 Revert to localnet * ✨ Add option to change order asc/desc of existing leaderboard
1 parent a73f6cf commit cb857cc

20 files changed

+846
-163
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/sdk/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@magicblock-labs/soar-sdk",
3-
"version": "0.1.21",
3+
"version": "0.1.22",
44
"description": "Sdk bindings for the SOAR smart contract.",
55
"repository": {
66
"type": "git",
@@ -45,6 +45,7 @@
4545
"eslint": "^8.33.0",
4646
"eslint-config-prettier": "^8.6.0",
4747
"eslint-plugin-import": "^2.25.3",
48+
"eslint-plugin-n": "^16.5.0",
4849
"eslint-plugin-react": "^7.32.2",
4950
"prettier": "^2.6.2",
5051
"typedoc": "^0.25.1",

client/sdk/src/idl/soar.ts

Lines changed: 96 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export type Soar = {
2-
version: "0.1.0";
2+
version: "0.1.1";
33
name: "soar";
44
constants: [
55
{
@@ -233,7 +233,8 @@ export type Soar = {
233233
{
234234
name: "updateLeaderboard";
235235
docs: [
236-
"Update's a leaderboard's description and nft metadata information."
236+
"Update's a leaderboard's description, nft metadata information, min/max score, or whether",
237+
"or not multiple scores are allowed for a single player."
237238
];
238239
accounts: [
239240
{
@@ -250,6 +251,12 @@ export type Soar = {
250251
name: "leaderboard";
251252
isMut: true;
252253
isSigner: false;
254+
},
255+
{
256+
name: "topEntries";
257+
isMut: true;
258+
isSigner: false;
259+
isOptional: true;
253260
}
254261
];
255262
args: [
@@ -264,6 +271,30 @@ export type Soar = {
264271
type: {
265272
option: "publicKey";
266273
};
274+
},
275+
{
276+
name: "newMinScore";
277+
type: {
278+
option: "u64";
279+
};
280+
},
281+
{
282+
name: "newMaxScore";
283+
type: {
284+
option: "u64";
285+
};
286+
},
287+
{
288+
name: "newIsAscending";
289+
type: {
290+
option: "bool";
291+
};
292+
},
293+
{
294+
name: "newAllowMultipleScores";
295+
type: {
296+
option: "bool";
297+
};
267298
}
268299
];
269300
},
@@ -1111,6 +1142,13 @@ export type Soar = {
11111142
type: {
11121143
option: "publicKey";
11131144
};
1145+
},
1146+
{
1147+
name: "allowMultipleScores";
1148+
docs: [
1149+
"Whether or not multiple scores are allowed for a single player."
1150+
];
1151+
type: "bool";
11141152
}
11151153
];
11161154
};
@@ -1467,11 +1505,18 @@ export type Soar = {
14671505
type: "u8";
14681506
},
14691507
{
1470-
name: "scoresOrder";
1508+
name: "isAscending";
14711509
docs: [
14721510
"Order by which scores are stored. `true` for ascending, `false` for descending."
14731511
];
14741512
type: "bool";
1513+
},
1514+
{
1515+
name: "allowMultipleScores";
1516+
docs: [
1517+
"Whether or not multiple scores are kept in the leaderboard for a single player."
1518+
];
1519+
type: "bool";
14751520
}
14761521
];
14771522
};
@@ -1708,7 +1753,7 @@ export type Soar = {
17081753
};
17091754

17101755
export const IDL: Soar = {
1711-
version: "0.1.0",
1756+
version: "0.1.1",
17121757
name: "soar",
17131758
constants: [
17141759
{
@@ -1942,7 +1987,8 @@ export const IDL: Soar = {
19421987
{
19431988
name: "updateLeaderboard",
19441989
docs: [
1945-
"Update's a leaderboard's description and nft metadata information.",
1990+
"Update's a leaderboard's description, nft metadata information, min/max score, or whether",
1991+
"or not multiple scores are allowed for a single player.",
19461992
],
19471993
accounts: [
19481994
{
@@ -1960,6 +2006,12 @@ export const IDL: Soar = {
19602006
isMut: true,
19612007
isSigner: false,
19622008
},
2009+
{
2010+
name: "topEntries",
2011+
isMut: true,
2012+
isSigner: false,
2013+
isOptional: true,
2014+
},
19632015
],
19642016
args: [
19652017
{
@@ -1974,6 +2026,30 @@ export const IDL: Soar = {
19742026
option: "publicKey",
19752027
},
19762028
},
2029+
{
2030+
name: "newMinScore",
2031+
type: {
2032+
option: "u64",
2033+
},
2034+
},
2035+
{
2036+
name: "newMaxScore",
2037+
type: {
2038+
option: "u64",
2039+
},
2040+
},
2041+
{
2042+
name: "newIsAscending",
2043+
type: {
2044+
option: "bool",
2045+
},
2046+
},
2047+
{
2048+
name: "newAllowMultipleScores",
2049+
type: {
2050+
option: "bool",
2051+
},
2052+
},
19772053
],
19782054
},
19792055
{
@@ -2821,6 +2897,13 @@ export const IDL: Soar = {
28212897
option: "publicKey",
28222898
},
28232899
},
2900+
{
2901+
name: "allowMultipleScores",
2902+
docs: [
2903+
"Whether or not multiple scores are allowed for a single player.",
2904+
],
2905+
type: "bool",
2906+
},
28242907
],
28252908
},
28262909
},
@@ -3176,12 +3259,19 @@ export const IDL: Soar = {
31763259
type: "u8",
31773260
},
31783261
{
3179-
name: "scoresOrder",
3262+
name: "isAscending",
31803263
docs: [
31813264
"Order by which scores are stored. `true` for ascending, `false` for descending.",
31823265
],
31833266
type: "bool",
31843267
},
3268+
{
3269+
name: "allowMultipleScores",
3270+
docs: [
3271+
"Whether or not multiple scores are kept in the leaderboard for a single player.",
3272+
],
3273+
type: "bool",
3274+
},
31853275
],
31863276
},
31873277
},

client/sdk/src/instructions/accountsBuilder.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,11 +537,13 @@ export class AccountsBuilder {
537537
updateLeaderboardAccounts = async (
538538
authority: PublicKey,
539539
leaderboard: PublicKey,
540-
game?: PublicKey
540+
game?: PublicKey,
541+
topEntries?: PublicKey
541542
): Promise<{
542543
authority: PublicKey;
543544
game: PublicKey;
544545
leaderboard: PublicKey;
546+
topEntries: PublicKey | null;
545547
}> => {
546548
const gameAddress =
547549
game ?? (await this.program.account.leaderBoard.fetch(leaderboard)).game;
@@ -550,6 +552,7 @@ export class AccountsBuilder {
550552
authority,
551553
game: gameAddress,
552554
leaderboard,
555+
topEntries: topEntries ?? null,
553556
};
554557
};
555558

client/sdk/src/instructions/ixBuilder.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,8 @@ export class InstructionBuilder {
263263
args: UpdateLeaderboardArgs,
264264
authority: PublicKey,
265265
leaderboard: PublicKey,
266-
game?: PublicKey
266+
game?: PublicKey,
267+
topEntries?: PublicKey
267268
): Promise<
268269
[
269270
InstructionBuilder,
@@ -275,7 +276,8 @@ export class InstructionBuilder {
275276
const accounts = await this.accounts.updateLeaderboardAccounts(
276277
authority,
277278
leaderboard,
278-
game
279+
game,
280+
topEntries
279281
);
280282
const instruction = await updateLeaderBoardInstruction(
281283
this.program,

client/sdk/src/instructions/rawInstructions.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,11 +321,19 @@ export const updateLeaderBoardInstruction = async (
321321
authority: PublicKey;
322322
game: PublicKey;
323323
leaderboard: PublicKey;
324+
topEntries: PublicKey | null;
324325
},
325326
pre?: TransactionInstruction[]
326327
): Promise<TransactionInstruction> => {
327328
return program.methods
328-
.updateLeaderboard(args.newDescription, args.newNftMeta)
329+
.updateLeaderboard(
330+
args.newDescription,
331+
args.newNftMeta,
332+
args.newMinScore,
333+
args.newMaxScore,
334+
args.newIsAscending,
335+
args.newAllowMultipleScores
336+
)
329337
.accounts(accounts)
330338
.preInstructions(pre ?? [])
331339
.instruction();

client/sdk/src/soar.game.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ export class GameClient {
117117
scoresOrder: boolean,
118118
decimals?: number,
119119
minScore?: BN,
120-
maxScore?: BN
120+
maxScore?: BN,
121+
allowMultipleScores?: boolean
121122
): Promise<InstructionResult.AddLeaderBoard> {
122123
return this.program.addNewGameLeaderBoard(
123124
this.address,
@@ -128,7 +129,8 @@ export class GameClient {
128129
scoresOrder,
129130
decimals,
130131
minScore,
131-
maxScore
132+
maxScore,
133+
allowMultipleScores
132134
);
133135
}
134136

client/sdk/src/soar.program.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,8 @@ export class SoarProgram {
237237
scoresOrder: boolean,
238238
decimals?: number,
239239
minScore?: BN,
240-
maxScore?: BN
240+
maxScore?: BN,
241+
allowMultipleScores?: boolean
241242
): Promise<InstructionResult.AddLeaderBoard> {
242243
this.builder.clean();
243244

@@ -246,10 +247,11 @@ export class SoarProgram {
246247
description,
247248
nftMeta,
248249
scoresToRetain,
249-
scoresOrder,
250+
isAscending: scoresOrder,
250251
decimals: decimals ?? null,
251252
minScore: minScore ?? null,
252253
maxScore: maxScore ?? null,
254+
allowMultipleScores: allowMultipleScores ?? false,
253255
},
254256
gameAddress,
255257
authority
@@ -267,7 +269,12 @@ export class SoarProgram {
267269
authority: PublicKey,
268270
leaderboard: PublicKey,
269271
newDescription?: string,
270-
newNftMeta?: PublicKey
272+
newNftMeta?: PublicKey,
273+
newMinScore?: BN,
274+
newMaxScore?: BN,
275+
newIsAscending?: boolean,
276+
newAllowMultipleScores?: boolean,
277+
topEntries?: PublicKey
271278
): Promise<InstructionResult.UpdateLeaderboard> {
272279
this.builder.clean();
273280
if (newDescription === undefined && newNftMeta === undefined) {
@@ -280,9 +287,15 @@ export class SoarProgram {
280287
{
281288
newDescription: newDescription ?? null,
282289
newNftMeta: newNftMeta ?? null,
290+
newMinScore: newMinScore ?? null,
291+
newMaxScore: newMaxScore ?? null,
292+
newIsAscending: newIsAscending ?? null,
293+
newAllowMultipleScores: newAllowMultipleScores ?? null,
283294
},
284295
authority,
285-
leaderboard
296+
leaderboard,
297+
undefined,
298+
topEntries ?? undefined
286299
);
287300

288301
return { transaction: step[0].build() };

client/sdk/src/state/leaderboard.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export class LeaderBoardAccount {
1414
public readonly decimals: number,
1515
public readonly minScore: BN,
1616
public readonly maxScore: BN,
17+
public readonly allowMultipleScores: boolean,
1718
public readonly topEntries: PublicKey | null
1819
) {}
1920

@@ -31,6 +32,7 @@ export class LeaderBoardAccount {
3132
account.decimals,
3233
account.minScore,
3334
account.maxScore,
35+
account.allowMultipleScores,
3436
account.topEntries
3537
);
3638
}
@@ -45,6 +47,7 @@ export class LeaderBoardAccount {
4547
decimals: number;
4648
minScore: string;
4749
maxScore: string;
50+
allowMultipleScores: boolean;
4851
topEntries: string | null;
4952
} {
5053
return {
@@ -56,6 +59,7 @@ export class LeaderBoardAccount {
5659
decimals: this.decimals,
5760
minScore: this.minScore.toString(),
5861
maxScore: this.maxScore.toString(),
62+
allowMultipleScores: this.allowMultipleScores,
5963
topEntries: this.topEntries ? this.topEntries.toBase58() : null,
6064
};
6165
}

0 commit comments

Comments
 (0)