@triadxyz/poseidons-protocol 0.3.5 → 0.3.7
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/chest.js +6 -6
- package/dist/game/index.d.ts +3 -1
- package/dist/game/index.js +16 -8
- package/dist/game/wheel.d.ts +6 -10
- package/dist/game/wheel.js +11 -21
- package/dist/utils/helpers.d.ts +1 -0
- package/dist/utils/helpers.js +23 -17
- package/package.json +1 -1
package/dist/game/chest.js
CHANGED
|
@@ -52,7 +52,7 @@ class Chest {
|
|
|
52
52
|
*/
|
|
53
53
|
createChest({ id, price, amount }) {
|
|
54
54
|
return __awaiter(this, void 0, void 0, function* () {
|
|
55
|
-
const
|
|
55
|
+
const ixs = [
|
|
56
56
|
yield this.program.methods
|
|
57
57
|
.createChest({
|
|
58
58
|
id: new anchor_1.BN(id),
|
|
@@ -64,7 +64,7 @@ class Chest {
|
|
|
64
64
|
})
|
|
65
65
|
.instruction()
|
|
66
66
|
];
|
|
67
|
-
return (0, sendVersionedTransaction_1.default)(this.program,
|
|
67
|
+
return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
|
|
68
68
|
});
|
|
69
69
|
}
|
|
70
70
|
/**
|
|
@@ -76,7 +76,7 @@ class Chest {
|
|
|
76
76
|
*/
|
|
77
77
|
placeChestBid({ id, coins }) {
|
|
78
78
|
return __awaiter(this, void 0, void 0, function* () {
|
|
79
|
-
const
|
|
79
|
+
const ixs = [
|
|
80
80
|
yield this.program.methods
|
|
81
81
|
.placeChestBid({
|
|
82
82
|
id: new anchor_1.BN(id),
|
|
@@ -88,7 +88,7 @@ class Chest {
|
|
|
88
88
|
})
|
|
89
89
|
.instruction()
|
|
90
90
|
];
|
|
91
|
-
return (0, sendVersionedTransaction_1.default)(this.program,
|
|
91
|
+
return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
|
|
92
92
|
});
|
|
93
93
|
}
|
|
94
94
|
/**
|
|
@@ -100,7 +100,7 @@ class Chest {
|
|
|
100
100
|
*/
|
|
101
101
|
addChestWinners({ id, grandWinner, top10 }) {
|
|
102
102
|
return __awaiter(this, void 0, void 0, function* () {
|
|
103
|
-
const
|
|
103
|
+
const ixs = [
|
|
104
104
|
yield this.program.methods
|
|
105
105
|
.addChestWinners({
|
|
106
106
|
id: new anchor_1.BN(id),
|
|
@@ -118,7 +118,7 @@ class Chest {
|
|
|
118
118
|
})
|
|
119
119
|
.instruction()
|
|
120
120
|
];
|
|
121
|
-
return (0, sendVersionedTransaction_1.default)(this.program,
|
|
121
|
+
return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
|
|
122
122
|
});
|
|
123
123
|
}
|
|
124
124
|
}
|
package/dist/game/index.d.ts
CHANGED
|
@@ -17,8 +17,10 @@ export default class Game {
|
|
|
17
17
|
* @param spins - The number of spins to add
|
|
18
18
|
* @returns The transaction signature or versioned transaction
|
|
19
19
|
*/
|
|
20
|
-
addSpin({ user, spins }: {
|
|
20
|
+
addSpin({ user, spins, refer, newUser }: {
|
|
21
21
|
user: PublicKey;
|
|
22
22
|
spins: number;
|
|
23
|
+
refer: PublicKey;
|
|
24
|
+
newUser: boolean;
|
|
23
25
|
}): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
24
26
|
}
|
package/dist/game/index.js
CHANGED
|
@@ -30,19 +30,27 @@ class Game {
|
|
|
30
30
|
* @param spins - The number of spins to add
|
|
31
31
|
* @returns The transaction signature or versioned transaction
|
|
32
32
|
*/
|
|
33
|
-
addSpin({ user, spins }) {
|
|
33
|
+
addSpin({ user, spins, refer, newUser }) {
|
|
34
34
|
return __awaiter(this, void 0, void 0, function* () {
|
|
35
35
|
const userPDA = (0, pda_1.getUserPDA)(user);
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
const ixs = [];
|
|
37
|
+
if (newUser) {
|
|
38
|
+
ixs.push(yield this.program.methods
|
|
39
|
+
.createUser(refer)
|
|
39
40
|
.accounts({
|
|
40
41
|
signer: this.program.provider.publicKey,
|
|
41
|
-
|
|
42
|
+
payer: this.rpcOptions.payer
|
|
42
43
|
})
|
|
43
|
-
.instruction()
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
.instruction());
|
|
45
|
+
}
|
|
46
|
+
ixs.push(yield this.program.methods
|
|
47
|
+
.addSpin(new anchor_1.BN(spins))
|
|
48
|
+
.accounts({
|
|
49
|
+
signer: this.program.provider.publicKey,
|
|
50
|
+
user: userPDA
|
|
51
|
+
})
|
|
52
|
+
.instruction());
|
|
53
|
+
return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
|
|
46
54
|
});
|
|
47
55
|
}
|
|
48
56
|
}
|
package/dist/game/wheel.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import { PublicKey } from '@solana/web3.js';
|
|
1
|
+
import { PublicKey, VersionedTransaction } from '@solana/web3.js';
|
|
3
2
|
import { Program } from '@coral-xyz/anchor';
|
|
4
3
|
import { PoseidonsProtocol } from './../types/poseidons_protocol';
|
|
5
4
|
import { RpcOptions } from './../types';
|
|
@@ -9,7 +8,7 @@ export default class Wheel {
|
|
|
9
8
|
constructor(program: Program<PoseidonsProtocol>, rpcOptions: RpcOptions);
|
|
10
9
|
/**
|
|
11
10
|
* Get all wheels
|
|
12
|
-
* @returns The
|
|
11
|
+
* @returns The wheels
|
|
13
12
|
*/
|
|
14
13
|
getAllWheel(): Promise<import("./../types").Wheel[]>;
|
|
15
14
|
/**
|
|
@@ -36,7 +35,7 @@ export default class Wheel {
|
|
|
36
35
|
rangeMax: number;
|
|
37
36
|
unit: number;
|
|
38
37
|
}[];
|
|
39
|
-
}): Promise<string |
|
|
38
|
+
}): Promise<string | VersionedTransaction>;
|
|
40
39
|
/**
|
|
41
40
|
* Add a prize to a wheel
|
|
42
41
|
* @param id - The id of the chest
|
|
@@ -46,7 +45,7 @@ export default class Wheel {
|
|
|
46
45
|
addWheelPrize({ id, available }: {
|
|
47
46
|
id: number;
|
|
48
47
|
available: number;
|
|
49
|
-
}): Promise<string |
|
|
48
|
+
}): Promise<string | VersionedTransaction>;
|
|
50
49
|
/**
|
|
51
50
|
* Spin a wheel
|
|
52
51
|
* @param id - The id of the wheel
|
|
@@ -59,14 +58,11 @@ export default class Wheel {
|
|
|
59
58
|
spins: number;
|
|
60
59
|
refer: PublicKey;
|
|
61
60
|
newUser: boolean;
|
|
62
|
-
}): Promise<
|
|
63
|
-
transaction: string;
|
|
64
|
-
prize: number[];
|
|
65
|
-
}>;
|
|
61
|
+
}): Promise<string | VersionedTransaction>;
|
|
66
62
|
/**
|
|
67
63
|
* Close a wheel
|
|
68
64
|
* @param id - The id of the wheel
|
|
69
65
|
* @returns The transaction signature or versioned transaction
|
|
70
66
|
*/
|
|
71
|
-
closeWheel(id: number): Promise<string |
|
|
67
|
+
closeWheel(id: number): Promise<string | VersionedTransaction>;
|
|
72
68
|
}
|
package/dist/game/wheel.js
CHANGED
|
@@ -23,7 +23,7 @@ class Wheel {
|
|
|
23
23
|
}
|
|
24
24
|
/**
|
|
25
25
|
* Get all wheels
|
|
26
|
-
* @returns The
|
|
26
|
+
* @returns The wheels
|
|
27
27
|
*/
|
|
28
28
|
getAllWheel() {
|
|
29
29
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -52,7 +52,7 @@ class Wheel {
|
|
|
52
52
|
*/
|
|
53
53
|
createWheel({ id, name, prizes }) {
|
|
54
54
|
return __awaiter(this, void 0, void 0, function* () {
|
|
55
|
-
const
|
|
55
|
+
const ixs = [
|
|
56
56
|
yield this.program.methods
|
|
57
57
|
.createWheel({
|
|
58
58
|
id,
|
|
@@ -71,7 +71,7 @@ class Wheel {
|
|
|
71
71
|
})
|
|
72
72
|
.instruction()
|
|
73
73
|
];
|
|
74
|
-
return (0, sendVersionedTransaction_1.default)(this.program,
|
|
74
|
+
return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
|
|
75
75
|
});
|
|
76
76
|
}
|
|
77
77
|
/**
|
|
@@ -82,7 +82,7 @@ class Wheel {
|
|
|
82
82
|
*/
|
|
83
83
|
addWheelPrize({ id, available }) {
|
|
84
84
|
return __awaiter(this, void 0, void 0, function* () {
|
|
85
|
-
const
|
|
85
|
+
const ixs = [
|
|
86
86
|
yield this.program.methods
|
|
87
87
|
.addWheelPrize({
|
|
88
88
|
id,
|
|
@@ -93,7 +93,7 @@ class Wheel {
|
|
|
93
93
|
})
|
|
94
94
|
.instruction()
|
|
95
95
|
];
|
|
96
|
-
return (0, sendVersionedTransaction_1.default)(this.program,
|
|
96
|
+
return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
|
|
97
97
|
});
|
|
98
98
|
}
|
|
99
99
|
/**
|
|
@@ -106,9 +106,9 @@ class Wheel {
|
|
|
106
106
|
return __awaiter(this, void 0, void 0, function* () {
|
|
107
107
|
const userPDA = (0, pda_1.getUserPDA)(user);
|
|
108
108
|
const wheelPDA = (0, pda_1.getWheelPDA)(id);
|
|
109
|
-
const
|
|
109
|
+
const ixs = [];
|
|
110
110
|
if (newUser) {
|
|
111
|
-
|
|
111
|
+
ixs.push(yield this.program.methods
|
|
112
112
|
.createUser(refer)
|
|
113
113
|
.accounts({
|
|
114
114
|
signer: this.program.provider.publicKey,
|
|
@@ -117,7 +117,7 @@ class Wheel {
|
|
|
117
117
|
.instruction());
|
|
118
118
|
}
|
|
119
119
|
for (let i = 0; i < spins; i++) {
|
|
120
|
-
|
|
120
|
+
ixs.push(yield this.program.methods
|
|
121
121
|
.spinWheel()
|
|
122
122
|
.accounts({
|
|
123
123
|
signer: this.program.provider.publicKey,
|
|
@@ -126,17 +126,7 @@ class Wheel {
|
|
|
126
126
|
})
|
|
127
127
|
.instruction());
|
|
128
128
|
}
|
|
129
|
-
|
|
130
|
-
const { blockhash, lastValidBlockHeight } = yield this.program.provider.connection.getLatestBlockhash();
|
|
131
|
-
yield this.program.provider.connection.confirmTransaction({
|
|
132
|
-
signature: transaction,
|
|
133
|
-
blockhash,
|
|
134
|
-
lastValidBlockHeight
|
|
135
|
-
}, 'finalized');
|
|
136
|
-
return {
|
|
137
|
-
transaction,
|
|
138
|
-
prize: yield (0, helpers_1.getPrize)(this.program, transaction)
|
|
139
|
-
};
|
|
129
|
+
return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
|
|
140
130
|
});
|
|
141
131
|
}
|
|
142
132
|
/**
|
|
@@ -147,7 +137,7 @@ class Wheel {
|
|
|
147
137
|
closeWheel(id) {
|
|
148
138
|
return __awaiter(this, void 0, void 0, function* () {
|
|
149
139
|
const wheelPDA = (0, pda_1.getWheelPDA)(id);
|
|
150
|
-
const
|
|
140
|
+
const ixs = [
|
|
151
141
|
yield this.program.methods
|
|
152
142
|
.closeWheel()
|
|
153
143
|
.accounts({
|
|
@@ -156,7 +146,7 @@ class Wheel {
|
|
|
156
146
|
})
|
|
157
147
|
.instruction()
|
|
158
148
|
];
|
|
159
|
-
return (0, sendVersionedTransaction_1.default)(this.program,
|
|
149
|
+
return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
|
|
160
150
|
});
|
|
161
151
|
}
|
|
162
152
|
}
|
package/dist/utils/helpers.d.ts
CHANGED
|
@@ -8,4 +8,5 @@ export declare const formatPoseidon: (account: IdlAccounts<PoseidonsProtocol>['p
|
|
|
8
8
|
export declare const formatUser: (account: IdlAccounts<PoseidonsProtocol>['user'], address: PublicKey) => User;
|
|
9
9
|
export declare const formatChest: (account: IdlAccounts<PoseidonsProtocol>['chest'], address: PublicKey) => Chest;
|
|
10
10
|
export declare const formatWheel: (account: IdlAccounts<PoseidonsProtocol>['wheel'], address: PublicKey) => Wheel;
|
|
11
|
+
export declare const getPrizeFromLogs: (program: Program<PoseidonsProtocol>, logMessages: string[]) => number[];
|
|
11
12
|
export declare const getPrize: (program: Program<PoseidonsProtocol>, transaction: string) => Promise<number[]>;
|
package/dist/utils/helpers.js
CHANGED
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.getPrize = exports.formatWheel = exports.formatChest = exports.formatUser = exports.formatPoseidon = exports.formatPoseidonVault = void 0;
|
|
12
|
+
exports.getPrize = exports.getPrizeFromLogs = exports.formatWheel = exports.formatChest = exports.formatUser = exports.formatPoseidon = exports.formatPoseidonVault = void 0;
|
|
13
13
|
const anchor_1 = require("@coral-xyz/anchor");
|
|
14
14
|
const formatPoseidonVault = (account, address) => {
|
|
15
15
|
return {
|
|
@@ -89,25 +89,31 @@ const formatWheel = (account, address) => {
|
|
|
89
89
|
};
|
|
90
90
|
};
|
|
91
91
|
exports.formatWheel = formatWheel;
|
|
92
|
-
const
|
|
93
|
-
var _a, _b;
|
|
92
|
+
const getPrizeFromLogs = (program, logMessages) => {
|
|
94
93
|
const prize = [];
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
prize.push(event.data.prizeId);
|
|
105
|
-
break;
|
|
106
|
-
default:
|
|
107
|
-
break;
|
|
108
|
-
}
|
|
94
|
+
const eventParser = new anchor_1.EventParser(program.programId, new anchor_1.BorshCoder(program.idl));
|
|
95
|
+
const events = eventParser.parseLogs(logMessages);
|
|
96
|
+
for (let event of events) {
|
|
97
|
+
switch (event.name) {
|
|
98
|
+
case 'spinWheelEvent':
|
|
99
|
+
prize.push(event.data.prizeId);
|
|
100
|
+
break;
|
|
101
|
+
default:
|
|
102
|
+
break;
|
|
109
103
|
}
|
|
110
104
|
}
|
|
111
105
|
return prize;
|
|
106
|
+
};
|
|
107
|
+
exports.getPrizeFromLogs = getPrizeFromLogs;
|
|
108
|
+
const getPrize = (program, transaction) => __awaiter(void 0, void 0, void 0, function* () {
|
|
109
|
+
var _a;
|
|
110
|
+
const tx = yield program.provider.connection.getParsedTransaction(transaction, {
|
|
111
|
+
maxSupportedTransactionVersion: 0,
|
|
112
|
+
commitment: 'confirmed'
|
|
113
|
+
});
|
|
114
|
+
if (!((_a = tx === null || tx === void 0 ? void 0 : tx.meta) === null || _a === void 0 ? void 0 : _a.logMessages)) {
|
|
115
|
+
return [];
|
|
116
|
+
}
|
|
117
|
+
return (0, exports.getPrizeFromLogs)(program, tx.meta.logMessages);
|
|
112
118
|
});
|
|
113
119
|
exports.getPrize = getPrize;
|