@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.
- package/dist/game/wheel.d.ts +4 -1
- package/dist/game/wheel.js +18 -16
- package/dist/utils/helpers.d.ts +2 -0
- package/dist/utils/helpers.js +31 -1
- package/package.json +1 -1
package/dist/game/wheel.d.ts
CHANGED
package/dist/game/wheel.js
CHANGED
|
@@ -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
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
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
|
}
|
package/dist/utils/helpers.d.ts
CHANGED
|
@@ -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[]>;
|
package/dist/utils/helpers.js
CHANGED
|
@@ -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;
|