@triadxyz/poseidons-protocol 0.4.0 → 0.4.1

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.
@@ -37,9 +37,10 @@ export default class Chest {
37
37
  * @param refer - The refer of the user
38
38
  * @returns The transaction signature or versioned transaction
39
39
  */
40
- placeChestBid({ id, coins }: {
40
+ placeChestBid({ id, coins, refer }: {
41
41
  id: number;
42
42
  coins: number;
43
+ refer: PublicKey;
43
44
  }): Promise<string | import("@solana/web3.js").VersionedTransaction>;
44
45
  /**
45
46
  * Add chest winners
@@ -74,20 +74,32 @@ class Chest {
74
74
  * @param refer - The refer of the user
75
75
  * @returns The transaction signature or versioned transaction
76
76
  */
77
- placeChestBid({ id, coins }) {
77
+ placeChestBid({ id, coins, refer }) {
78
78
  return __awaiter(this, void 0, void 0, function* () {
79
- const ixs = [
80
- yield this.program.methods
81
- .placeChestBid({
82
- id: new anchor_1.BN(id),
83
- coins: new anchor_1.BN(coins)
84
- })
79
+ const ixs = [];
80
+ const userPDA = (0, pda_1.getUserPDA)(this.program.provider.publicKey);
81
+ try {
82
+ yield this.program.account.user.fetch(userPDA, this.rpcOptions.commitment);
83
+ }
84
+ catch (error) {
85
+ ixs.push(yield this.program.methods
86
+ .createUser(refer)
85
87
  .accounts({
86
88
  signer: this.program.provider.publicKey,
87
- user: (0, pda_1.getUserPDA)(this.program.provider.publicKey)
89
+ payer: this.rpcOptions.payer
88
90
  })
89
- .instruction()
90
- ];
91
+ .instruction());
92
+ }
93
+ ixs.push(yield this.program.methods
94
+ .placeChestBid({
95
+ id: new anchor_1.BN(id),
96
+ coins: new anchor_1.BN(coins)
97
+ })
98
+ .accounts({
99
+ signer: this.program.provider.publicKey,
100
+ user: (0, pda_1.getUserPDA)(this.program.provider.publicKey)
101
+ })
102
+ .instruction());
91
103
  return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
92
104
  });
93
105
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@triadxyz/poseidons-protocol",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",