@triadxyz/poseidons-protocol 0.2.6 → 0.2.8

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.
@@ -57,5 +57,8 @@ export default class Wheel {
57
57
  user: PublicKey;
58
58
  id: number;
59
59
  spins: number;
60
- }): Promise<void>;
60
+ }): Promise<string | import("@solana/web3.js").VersionedTransaction | {
61
+ transaction: string;
62
+ prize: number[];
63
+ }>;
61
64
  }
@@ -103,23 +103,25 @@ class Wheel {
103
103
  * @returns The transaction signature or versioned transaction
104
104
  */
105
105
  spinWheel({ user, id, spins }) {
106
+ var _a, _b;
106
107
  return __awaiter(this, void 0, void 0, function* () {
107
- const dumpPrizes = Promise.all([3, 4, 5, 6, 7]);
108
- yield dumpPrizes;
109
- // const userPDA = getUserPDA(user)
110
- // const instructions: TransactionInstruction[] = []
111
- // for (let i = 0; i < spins; i++) {
112
- // instructions.push(
113
- // await this.program.methods
114
- // .spinWheel(id)
115
- // .accounts({
116
- // signer: this.program.provider.publicKey,
117
- // user: userPDA
118
- // })
119
- // .instruction()
120
- // )
121
- // }
122
- // return sendVersionedTransaction(this.program, instructions, this.rpcOptions)
108
+ const userPDA = (0, pda_1.getUserPDA)(user);
109
+ const instructions = [];
110
+ for (let i = 0; i < spins; i++) {
111
+ instructions.push(yield this.program.methods
112
+ .spinWheel(id)
113
+ .accounts({
114
+ signer: this.program.provider.publicKey,
115
+ user: userPDA
116
+ })
117
+ .instruction());
118
+ }
119
+ if (this.program.provider.publicKey.toBase58() !==
120
+ ((_b = (_a = this.rpcOptions) === null || _a === void 0 ? void 0 : _a.payer) === null || _b === void 0 ? void 0 : _b.toBase58())) {
121
+ return (0, sendVersionedTransaction_1.default)(this.program, instructions, this.rpcOptions);
122
+ }
123
+ const transaction = (yield (0, sendVersionedTransaction_1.default)(this.program, instructions, this.rpcOptions));
124
+ return { transaction, prize: yield (0, helpers_1.getPrize)(this.program, transaction) };
123
125
  });
124
126
  }
125
127
  }
@@ -1,5 +1,6 @@
1
1
  import { IdlAccounts } from '@coral-xyz/anchor';
2
2
  import { PublicKey } from '@solana/web3.js';
3
+ import { Program } from '@coral-xyz/anchor';
3
4
  import { PoseidonsProtocol } from '../types/poseidons_protocol';
4
5
  import { PoseidonVault, Poseidon, Chest, User, Wheel } from '../types';
5
6
  export declare const formatPoseidonVault: (account: IdlAccounts<PoseidonsProtocol>['poseidonVault'], address: PublicKey) => PoseidonVault;
@@ -7,3 +8,4 @@ export declare const formatPoseidon: (account: IdlAccounts<PoseidonsProtocol>['p
7
8
  export declare const formatUser: (account: IdlAccounts<PoseidonsProtocol>['user'], address: PublicKey) => User;
8
9
  export declare const formatChest: (account: IdlAccounts<PoseidonsProtocol>['chest'], address: PublicKey) => Chest;
9
10
  export declare const formatWheel: (account: IdlAccounts<PoseidonsProtocol>['wheel'], address: PublicKey) => Wheel;
11
+ export declare const getPrize: (program: Program<PoseidonsProtocol>, transaction: string) => Promise<number[]>;
@@ -1,6 +1,16 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.formatWheel = exports.formatChest = exports.formatUser = exports.formatPoseidon = exports.formatPoseidonVault = void 0;
12
+ exports.getPrize = exports.formatWheel = exports.formatChest = exports.formatUser = exports.formatPoseidon = exports.formatPoseidonVault = void 0;
13
+ const anchor_1 = require("@coral-xyz/anchor");
4
14
  const formatPoseidonVault = (account, address) => {
5
15
  return {
6
16
  address: address.toString(),
@@ -78,3 +88,23 @@ const formatWheel = (account, address) => {
78
88
  };
79
89
  };
80
90
  exports.formatWheel = formatWheel;
91
+ const getPrize = (program, transaction) => __awaiter(void 0, void 0, void 0, function* () {
92
+ var _a, _b;
93
+ const prize = [];
94
+ const tx = yield program.provider.connection.getParsedTransaction(transaction);
95
+ if ((_a = tx === null || tx === void 0 ? void 0 : tx.meta) === null || _a === void 0 ? void 0 : _a.logMessages) {
96
+ const eventParser = new anchor_1.EventParser(program.programId, new anchor_1.BorshCoder(program.idl));
97
+ const events = eventParser.parseLogs((_b = tx === null || tx === void 0 ? void 0 : tx.meta) === null || _b === void 0 ? void 0 : _b.logMessages);
98
+ for (let event of events) {
99
+ switch (event.name) {
100
+ case 'SpinWheelEvent':
101
+ prize.push(event.data.prizeId);
102
+ break;
103
+ default:
104
+ break;
105
+ }
106
+ }
107
+ }
108
+ return prize;
109
+ });
110
+ exports.getPrize = getPrize;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@triadxyz/poseidons-protocol",
3
- "version": "0.2.6",
3
+ "version": "0.2.8",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",