@triadxyz/poseidons-protocol 0.3.8 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -17,10 +17,11 @@ export default class Game {
17
17
  * @param spins - The number of spins to add
18
18
  * @returns The transaction signature or versioned transaction
19
19
  */
20
- addSpin({ user, spins, refer, newUser }: {
21
- user: PublicKey;
22
- spins: number;
20
+ addSpin({ users, refer }: {
21
+ users: {
22
+ user: PublicKey;
23
+ spins: number;
24
+ }[];
23
25
  refer: PublicKey;
24
- newUser: boolean;
25
26
  }): Promise<string | import("@solana/web3.js").VersionedTransaction>;
26
27
  }
@@ -30,26 +30,31 @@ class Game {
30
30
  * @param spins - The number of spins to add
31
31
  * @returns The transaction signature or versioned transaction
32
32
  */
33
- addSpin({ user, spins, refer, newUser }) {
33
+ addSpin({ users, refer }) {
34
34
  return __awaiter(this, void 0, void 0, function* () {
35
- const userPDA = (0, pda_1.getUserPDA)(user);
36
35
  const ixs = [];
37
- if (newUser) {
36
+ for (const user of users) {
37
+ const userPDA = (0, pda_1.getUserPDA)(user.user);
38
+ try {
39
+ yield this.program.account.user.fetch(userPDA, this.rpcOptions.commitment);
40
+ }
41
+ catch (error) {
42
+ ixs.push(yield this.program.methods
43
+ .createUser(refer)
44
+ .accounts({
45
+ signer: user.user,
46
+ payer: this.rpcOptions.payer
47
+ })
48
+ .instruction());
49
+ }
38
50
  ixs.push(yield this.program.methods
39
- .createUser(refer)
51
+ .addSpin(new anchor_1.BN(user.spins))
40
52
  .accounts({
41
53
  signer: this.program.provider.publicKey,
42
- payer: this.rpcOptions.payer
54
+ user: userPDA
43
55
  })
44
56
  .instruction());
45
57
  }
46
- ixs.push(yield this.program.methods
47
- .addSpin(new anchor_1.BN(spins))
48
- .accounts({
49
- signer: this.program.provider.publicKey,
50
- user: userPDA
51
- })
52
- .instruction());
53
58
  return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
54
59
  });
55
60
  }
@@ -1,4 +1,5 @@
1
- import { PublicKey, VersionedTransaction } from '@solana/web3.js';
1
+ /// <reference types="@coral-xyz/anchor/node_modules/@solana/web3.js" />
2
+ import { PublicKey } from '@solana/web3.js';
2
3
  import { Program } from '@coral-xyz/anchor';
3
4
  import { PoseidonsProtocol } from './../types/poseidons_protocol';
4
5
  import { RpcOptions } from './../types';
@@ -35,7 +36,7 @@ export default class Wheel {
35
36
  rangeMax: number;
36
37
  unit: number;
37
38
  }[];
38
- }): Promise<string | VersionedTransaction>;
39
+ }): Promise<string | import("@solana/web3.js").VersionedTransaction>;
39
40
  /**
40
41
  * Add a prize to a wheel
41
42
  * @param id - The id of the chest
@@ -45,7 +46,7 @@ export default class Wheel {
45
46
  addWheelPrize({ id, available }: {
46
47
  id: number;
47
48
  available: number;
48
- }): Promise<string | VersionedTransaction>;
49
+ }): Promise<string | import("@solana/web3.js").VersionedTransaction>;
49
50
  /**
50
51
  * Spin a wheel
51
52
  * @param id - The id of the wheel
@@ -58,12 +59,12 @@ export default class Wheel {
58
59
  spins: number;
59
60
  refer: PublicKey;
60
61
  newUser: boolean;
61
- }): Promise<string | VersionedTransaction>;
62
+ }): Promise<string | import("@solana/web3.js").VersionedTransaction>;
62
63
  /**
63
64
  * Close a wheel
64
65
  * @param id - The id of the wheel
65
66
  * @param isActive - The active status of the wheel
66
67
  * @returns The transaction signature or versioned transaction
67
68
  */
68
- closeWheel(id: number, isActive: boolean): Promise<string | VersionedTransaction>;
69
+ closeWheel(id: number, isActive: boolean): Promise<string | import("@solana/web3.js").VersionedTransaction>;
69
70
  }
@@ -89,7 +89,8 @@ class Wheel {
89
89
  available: new anchor_1.BN(available)
90
90
  })
91
91
  .accounts({
92
- signer: this.program.provider.publicKey
92
+ signer: this.program.provider.publicKey,
93
+ wheel: (0, pda_1.getWheelPDA)(0)
93
94
  })
94
95
  .instruction()
95
96
  ];
@@ -114,7 +115,7 @@ class Wheel {
114
115
  ixs.push(yield this.program.methods
115
116
  .createUser(refer)
116
117
  .accounts({
117
- signer: this.program.provider.publicKey,
118
+ signer: user,
118
119
  payer: this.rpcOptions.payer
119
120
  })
120
121
  .instruction());
@@ -313,19 +313,7 @@
313
313
  },
314
314
  {
315
315
  "name": "wheel",
316
- "writable": true,
317
- "pda": {
318
- "seeds": [
319
- {
320
- "kind": "const",
321
- "value": [119, 104, 101, 101, 108]
322
- },
323
- {
324
- "kind": "arg",
325
- "path": "args.id"
326
- }
327
- ]
328
- }
316
+ "writable": true
329
317
  },
330
318
  {
331
319
  "name": "system_program",
@@ -809,7 +797,7 @@
809
797
  },
810
798
  {
811
799
  "kind": "account",
812
- "path": "refer.authority",
800
+ "path": "user.refer",
813
801
  "account": "User"
814
802
  }
815
803
  ]
@@ -419,18 +419,6 @@ export type PoseidonsProtocol = {
419
419
  {
420
420
  name: 'wheel';
421
421
  writable: true;
422
- pda: {
423
- seeds: [
424
- {
425
- kind: 'const';
426
- value: [119, 104, 101, 101, 108];
427
- },
428
- {
429
- kind: 'arg';
430
- path: 'args.id';
431
- }
432
- ];
433
- };
434
422
  },
435
423
  {
436
424
  name: 'systemProgram';
@@ -1042,7 +1030,7 @@ export type PoseidonsProtocol = {
1042
1030
  },
1043
1031
  {
1044
1032
  kind: 'account';
1045
- path: 'refer.authority';
1033
+ path: 'user.refer';
1046
1034
  account: 'user';
1047
1035
  }
1048
1036
  ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@triadxyz/poseidons-protocol",
3
- "version": "0.3.8",
3
+ "version": "0.4.0",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",