@triadxyz/poseidons-protocol 0.2.6 → 0.2.9
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/types/idl_poseidons_protocol.json +8 -4
- package/dist/types/index.d.ts +1 -0
- package/dist/types/poseidons_protocol.d.ts +8 -4
- package/dist/utils/helpers.d.ts +2 -0
- package/dist/utils/helpers.js +33 -2
- package/dist/utils/pda.js +1 -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
|
}
|
|
@@ -318,7 +318,7 @@
|
|
|
318
318
|
"seeds": [
|
|
319
319
|
{
|
|
320
320
|
"kind": "const",
|
|
321
|
-
"value": [119, 104, 101,
|
|
321
|
+
"value": [119, 104, 101, 101, 108]
|
|
322
322
|
},
|
|
323
323
|
{
|
|
324
324
|
"kind": "arg",
|
|
@@ -715,7 +715,7 @@
|
|
|
715
715
|
"seeds": [
|
|
716
716
|
{
|
|
717
717
|
"kind": "const",
|
|
718
|
-
"value": [119, 104, 101,
|
|
718
|
+
"value": [119, 104, 101, 101, 108]
|
|
719
719
|
},
|
|
720
720
|
{
|
|
721
721
|
"kind": "arg",
|
|
@@ -879,7 +879,7 @@
|
|
|
879
879
|
"seeds": [
|
|
880
880
|
{
|
|
881
881
|
"kind": "const",
|
|
882
|
-
"value": [119, 104, 101,
|
|
882
|
+
"value": [119, 104, 101, 101, 108]
|
|
883
883
|
},
|
|
884
884
|
{
|
|
885
885
|
"kind": "arg",
|
|
@@ -1866,10 +1866,14 @@
|
|
|
1866
1866
|
]
|
|
1867
1867
|
}
|
|
1868
1868
|
},
|
|
1869
|
+
{
|
|
1870
|
+
"name": "is_active",
|
|
1871
|
+
"type": "bool"
|
|
1872
|
+
},
|
|
1869
1873
|
{
|
|
1870
1874
|
"name": "padding",
|
|
1871
1875
|
"type": {
|
|
1872
|
-
"array": ["u8",
|
|
1876
|
+
"array": ["u8", 31]
|
|
1873
1877
|
}
|
|
1874
1878
|
}
|
|
1875
1879
|
]
|
package/dist/types/index.d.ts
CHANGED
|
@@ -423,7 +423,7 @@ export type PoseidonsProtocol = {
|
|
|
423
423
|
seeds: [
|
|
424
424
|
{
|
|
425
425
|
kind: 'const';
|
|
426
|
-
value: [119, 104, 101,
|
|
426
|
+
value: [119, 104, 101, 101, 108];
|
|
427
427
|
},
|
|
428
428
|
{
|
|
429
429
|
kind: 'arg';
|
|
@@ -948,7 +948,7 @@ export type PoseidonsProtocol = {
|
|
|
948
948
|
seeds: [
|
|
949
949
|
{
|
|
950
950
|
kind: 'const';
|
|
951
|
-
value: [119, 104, 101,
|
|
951
|
+
value: [119, 104, 101, 101, 108];
|
|
952
952
|
},
|
|
953
953
|
{
|
|
954
954
|
kind: 'arg';
|
|
@@ -1170,7 +1170,7 @@ export type PoseidonsProtocol = {
|
|
|
1170
1170
|
seeds: [
|
|
1171
1171
|
{
|
|
1172
1172
|
kind: 'const';
|
|
1173
|
-
value: [119, 104, 101,
|
|
1173
|
+
value: [119, 104, 101, 101, 108];
|
|
1174
1174
|
},
|
|
1175
1175
|
{
|
|
1176
1176
|
kind: 'arg';
|
|
@@ -2157,10 +2157,14 @@ export type PoseidonsProtocol = {
|
|
|
2157
2157
|
];
|
|
2158
2158
|
};
|
|
2159
2159
|
},
|
|
2160
|
+
{
|
|
2161
|
+
name: 'isActive';
|
|
2162
|
+
type: 'bool';
|
|
2163
|
+
},
|
|
2160
2164
|
{
|
|
2161
2165
|
name: 'padding';
|
|
2162
2166
|
type: {
|
|
2163
|
-
array: ['u8',
|
|
2167
|
+
array: ['u8', 31];
|
|
2164
2168
|
};
|
|
2165
2169
|
}
|
|
2166
2170
|
];
|
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(),
|
|
@@ -67,14 +77,35 @@ const formatWheel = (account, address) => {
|
|
|
67
77
|
id: account.id,
|
|
68
78
|
name: account.name,
|
|
69
79
|
count: account.count.toNumber(),
|
|
80
|
+
isActive: account.isActive,
|
|
70
81
|
prizes: account.prizes.map((prize) => ({
|
|
71
82
|
id: prize.id,
|
|
72
83
|
name: prize.name,
|
|
73
84
|
available: prize.available.toNumber(),
|
|
74
85
|
rangeMin: prize.rangeMin.toNumber(),
|
|
75
86
|
rangeMax: prize.rangeMax.toNumber(),
|
|
76
|
-
unit: prize.unit.toNumber()
|
|
87
|
+
unit: prize.unit.toNumber() / Math.pow(10, 6)
|
|
77
88
|
}))
|
|
78
89
|
};
|
|
79
90
|
};
|
|
80
91
|
exports.formatWheel = formatWheel;
|
|
92
|
+
const getPrize = (program, transaction) => __awaiter(void 0, void 0, void 0, function* () {
|
|
93
|
+
var _a, _b;
|
|
94
|
+
const prize = [];
|
|
95
|
+
const tx = yield program.provider.connection.getParsedTransaction(transaction);
|
|
96
|
+
if ((_a = tx === null || tx === void 0 ? void 0 : tx.meta) === null || _a === void 0 ? void 0 : _a.logMessages) {
|
|
97
|
+
const eventParser = new anchor_1.EventParser(program.programId, new anchor_1.BorshCoder(program.idl));
|
|
98
|
+
const events = eventParser.parseLogs((_b = tx === null || tx === void 0 ? void 0 : tx.meta) === null || _b === void 0 ? void 0 : _b.logMessages);
|
|
99
|
+
for (let event of events) {
|
|
100
|
+
switch (event.name) {
|
|
101
|
+
case 'SpinWheelEvent':
|
|
102
|
+
prize.push(event.data.prizeId);
|
|
103
|
+
break;
|
|
104
|
+
default:
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return prize;
|
|
110
|
+
});
|
|
111
|
+
exports.getPrize = getPrize;
|
package/dist/utils/pda.js
CHANGED
|
@@ -26,6 +26,6 @@ const getChestPDA = (id) => {
|
|
|
26
26
|
};
|
|
27
27
|
exports.getChestPDA = getChestPDA;
|
|
28
28
|
const getWheelPDA = (id) => {
|
|
29
|
-
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('wheel'), new anchor_1.BN(id).toArrayLike(Buffer, 'le',
|
|
29
|
+
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('wheel'), new anchor_1.BN(id).toArrayLike(Buffer, 'le', 1)], constants_1.POSEIDON_VAULT_PROGRAM_ID)[0];
|
|
30
30
|
};
|
|
31
31
|
exports.getWheelPDA = getWheelPDA;
|