@triadxyz/poseidons-protocol 0.2.5 → 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 +7 -1
- 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
|
@@ -57,5 +57,8 @@ export default class Wheel {
|
|
|
57
57
|
user: PublicKey;
|
|
58
58
|
id: number;
|
|
59
59
|
spins: number;
|
|
60
|
-
}): Promise<string | import("@solana/web3.js").VersionedTransaction
|
|
60
|
+
}): Promise<string | import("@solana/web3.js").VersionedTransaction | {
|
|
61
|
+
transaction: string;
|
|
62
|
+
prize: number[];
|
|
63
|
+
}>;
|
|
61
64
|
}
|
package/dist/game/wheel.js
CHANGED
|
@@ -103,6 +103,7 @@ 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
108
|
const userPDA = (0, pda_1.getUserPDA)(user);
|
|
108
109
|
const instructions = [];
|
|
@@ -115,7 +116,12 @@ class Wheel {
|
|
|
115
116
|
})
|
|
116
117
|
.instruction());
|
|
117
118
|
}
|
|
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) };
|
|
119
125
|
});
|
|
120
126
|
}
|
|
121
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;
|