@triadxyz/triad-protocol 1.3.5-beta → 1.3.7-beta
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/index.d.ts +1 -15
- package/dist/index.js +9 -37
- package/dist/local-test.js +3 -6
- package/dist/stake.d.ts +1 -1
- package/dist/stake.js +3 -18
- package/dist/types/idl_triad_protocol.json +0 -86
- package/dist/types/triad_protocol.d.ts +0 -86
- package/dist/utils/helpers.d.ts +1 -0
- package/dist/utils/helpers.js +24 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -82,19 +82,5 @@ export default class TriadProtocolClient {
|
|
|
82
82
|
* @param verifier - Verifier keypair
|
|
83
83
|
* @param options - RPC options
|
|
84
84
|
*/
|
|
85
|
-
spinWheel(isSol: boolean, options?: RpcOptions): Promise<
|
|
86
|
-
/**
|
|
87
|
-
* Mint Poseidon
|
|
88
|
-
* @param number - Poseidon number
|
|
89
|
-
* @param attributes - Poseidon attributes
|
|
90
|
-
* @param options - RPC options
|
|
91
|
-
*
|
|
92
|
-
*/
|
|
93
|
-
mintPoseidon(items: {
|
|
94
|
-
number: number;
|
|
95
|
-
attributes: {
|
|
96
|
-
key: string;
|
|
97
|
-
value: string;
|
|
98
|
-
}[];
|
|
99
|
-
}[], options?: RpcOptions): Promise<string>;
|
|
85
|
+
spinWheel(isSol: boolean, options?: RpcOptions): Promise<number>;
|
|
100
86
|
}
|
package/dist/index.js
CHANGED
|
@@ -14,6 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
const anchor_1 = require("@coral-xyz/anchor");
|
|
16
16
|
const web3_js_1 = require("@solana/web3.js");
|
|
17
|
+
const base64_js_1 = require("base64-js");
|
|
17
18
|
const idl_triad_protocol_json_1 = __importDefault(require("./types/idl_triad_protocol.json"));
|
|
18
19
|
const trade_1 = __importDefault(require("./trade"));
|
|
19
20
|
const helpers_1 = require("./utils/helpers");
|
|
@@ -228,6 +229,7 @@ class TriadProtocolClient {
|
|
|
228
229
|
* @param options - RPC options
|
|
229
230
|
*/
|
|
230
231
|
spinWheel(isSol, options) {
|
|
232
|
+
var _a, _b, _c;
|
|
231
233
|
return __awaiter(this, void 0, void 0, function* () {
|
|
232
234
|
const spinPDA = (0, pda_1.getSpinPDA)(this.program.programId, constants_1.SPIN_NAME);
|
|
233
235
|
const method = this.program.methods.spinWheel(isSol).accounts({
|
|
@@ -236,46 +238,16 @@ class TriadProtocolClient {
|
|
|
236
238
|
mint: constants_1.TCMAS_MINT
|
|
237
239
|
});
|
|
238
240
|
const tx = yield (0, sendTransactionWithOptions_1.default)(method, options);
|
|
239
|
-
const
|
|
241
|
+
const txResult = (yield this.provider.connection.getTransaction(tx, {
|
|
240
242
|
commitment: 'confirmed',
|
|
241
243
|
maxSupportedTransactionVersion: 0
|
|
242
|
-
});
|
|
243
|
-
const
|
|
244
|
-
if (!
|
|
245
|
-
throw new Error('
|
|
246
|
-
}
|
|
247
|
-
const prizeType = JSON.parse(eventLog.split('RouletteSpinResult')[1]).data
|
|
248
|
-
.prize;
|
|
249
|
-
return prizeType;
|
|
250
|
-
});
|
|
251
|
-
}
|
|
252
|
-
/**
|
|
253
|
-
* Mint Poseidon
|
|
254
|
-
* @param number - Poseidon number
|
|
255
|
-
* @param attributes - Poseidon attributes
|
|
256
|
-
* @param options - RPC options
|
|
257
|
-
*
|
|
258
|
-
*/
|
|
259
|
-
mintPoseidon(items, options) {
|
|
260
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
261
|
-
const assets = [];
|
|
262
|
-
const ixs = [];
|
|
263
|
-
for (const item of items) {
|
|
264
|
-
const asset = web3_js_1.Keypair.generate();
|
|
265
|
-
assets.push(asset);
|
|
266
|
-
ixs.push(yield this.program.methods
|
|
267
|
-
.mintPoseidon({
|
|
268
|
-
collectionSymbol: constants_1.POSEIDON_COLLECTION_SYMBOL,
|
|
269
|
-
number: new anchor_1.BN(item.number)
|
|
270
|
-
})
|
|
271
|
-
.accounts({
|
|
272
|
-
signer: this.provider.wallet.publicKey,
|
|
273
|
-
asset: asset.publicKey,
|
|
274
|
-
coreCollection: constants_1.POSEIDON_CORE_COLLECTION
|
|
275
|
-
})
|
|
276
|
-
.instruction());
|
|
244
|
+
}));
|
|
245
|
+
const returnData = (_b = (_a = txResult.meta) === null || _a === void 0 ? void 0 : _a.returnData) === null || _b === void 0 ? void 0 : _b.data;
|
|
246
|
+
if (!returnData) {
|
|
247
|
+
throw new Error('No return data found in transaction');
|
|
277
248
|
}
|
|
278
|
-
|
|
249
|
+
let value = (_c = txResult.meta) === null || _c === void 0 ? void 0 : _c.returnData.data[0];
|
|
250
|
+
return new anchor_1.BN((0, base64_js_1.toByteArray)(value), 'le').toNumber();
|
|
279
251
|
});
|
|
280
252
|
}
|
|
281
253
|
}
|
package/dist/local-test.js
CHANGED
|
@@ -446,11 +446,8 @@ const getSpinPrize = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
446
446
|
console.log(prizes);
|
|
447
447
|
});
|
|
448
448
|
const spinWheel = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
449
|
-
const response = yield triadProtocol.spinWheel(false, {
|
|
450
|
-
|
|
451
|
-
});
|
|
452
|
-
spinWheel();
|
|
453
|
-
const mintPoseidon = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
454
|
-
const response = yield triadProtocol.mintPoseidon([]);
|
|
449
|
+
const response = yield triadProtocol.spinWheel(false, {
|
|
450
|
+
skipPreflight: false
|
|
451
|
+
});
|
|
455
452
|
console.log(response);
|
|
456
453
|
});
|
package/dist/stake.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export default class Stake {
|
|
|
15
15
|
/**
|
|
16
16
|
* Get Stake Rewards
|
|
17
17
|
*/
|
|
18
|
-
getStakeRewards({ wallet, nftName, collections
|
|
18
|
+
getStakeRewards({ wallet, nftName, collections }: ClaimStakeRewardsArgs): Promise<number>;
|
|
19
19
|
/**
|
|
20
20
|
* Get all Stakes
|
|
21
21
|
*/
|
package/dist/stake.js
CHANGED
|
@@ -17,7 +17,6 @@ const helpers_1 = require("./utils/helpers");
|
|
|
17
17
|
const stake_1 = require("./utils/pda/stake");
|
|
18
18
|
const pda_1 = require("./utils/pda");
|
|
19
19
|
const constants_1 = require("./utils/constants");
|
|
20
|
-
const base64_js_1 = require("base64-js");
|
|
21
20
|
const getRarityRank_1 = __importDefault(require("./utils/getRarityRank"));
|
|
22
21
|
const sendVersionedTransaction_1 = __importDefault(require("./utils/sendVersionedTransaction"));
|
|
23
22
|
const sendTransactionWithOptions_1 = __importDefault(require("./utils/sendTransactionWithOptions"));
|
|
@@ -40,25 +39,11 @@ class Stake {
|
|
|
40
39
|
/**
|
|
41
40
|
* Get Stake Rewards
|
|
42
41
|
*/
|
|
43
|
-
getStakeRewards({ wallet, nftName, collections
|
|
42
|
+
getStakeRewards({ wallet, nftName, collections }) {
|
|
44
43
|
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
-
const stakeVaultPDA = (0, stake_1.getStakeVaultPDA)(this.program.programId, this.stakeVaultName);
|
|
46
44
|
const stakePDA = (0, stake_1.getStakePDA)(this.program.programId, wallet, nftName);
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
collections,
|
|
50
|
-
rank
|
|
51
|
-
})
|
|
52
|
-
.accounts({
|
|
53
|
-
signer: wallet,
|
|
54
|
-
mint: constants_1.TRD_MINT,
|
|
55
|
-
stake: stakePDA,
|
|
56
|
-
stakeVault: stakeVaultPDA,
|
|
57
|
-
verifier: constants_1.VERIFIER
|
|
58
|
-
})
|
|
59
|
-
.simulate();
|
|
60
|
-
let value = method.raw[method.raw.length - 2].split(' ')[3];
|
|
61
|
-
return new anchor_1.BN((0, base64_js_1.toByteArray)(value), 'le').toNumber() / Math.pow(10, constants_1.TRD_DECIMALS);
|
|
45
|
+
const stake = yield this.program.account.stakeV2.fetch(stakePDA);
|
|
46
|
+
return (0, helpers_1.calculateStakeRewards)((0, helpers_1.formatStake)(stake), collections);
|
|
62
47
|
});
|
|
63
48
|
}
|
|
64
49
|
/**
|
|
@@ -755,76 +755,6 @@
|
|
|
755
755
|
}
|
|
756
756
|
]
|
|
757
757
|
},
|
|
758
|
-
{
|
|
759
|
-
"name": "mint_poseidon",
|
|
760
|
-
"discriminator": [102, 210, 5, 220, 154, 54, 98, 23],
|
|
761
|
-
"accounts": [
|
|
762
|
-
{
|
|
763
|
-
"name": "signer",
|
|
764
|
-
"writable": true,
|
|
765
|
-
"signer": true
|
|
766
|
-
},
|
|
767
|
-
{
|
|
768
|
-
"name": "nft",
|
|
769
|
-
"writable": true,
|
|
770
|
-
"pda": {
|
|
771
|
-
"seeds": [
|
|
772
|
-
{
|
|
773
|
-
"kind": "const",
|
|
774
|
-
"value": [112, 111, 115, 101, 105, 100, 111, 110]
|
|
775
|
-
},
|
|
776
|
-
{
|
|
777
|
-
"kind": "arg",
|
|
778
|
-
"path": "args.number"
|
|
779
|
-
}
|
|
780
|
-
]
|
|
781
|
-
}
|
|
782
|
-
},
|
|
783
|
-
{
|
|
784
|
-
"name": "asset",
|
|
785
|
-
"writable": true,
|
|
786
|
-
"signer": true
|
|
787
|
-
},
|
|
788
|
-
{
|
|
789
|
-
"name": "collection",
|
|
790
|
-
"writable": true,
|
|
791
|
-
"pda": {
|
|
792
|
-
"seeds": [
|
|
793
|
-
{
|
|
794
|
-
"kind": "const",
|
|
795
|
-
"value": [99, 111, 108, 108, 101, 99, 116, 105, 111, 110]
|
|
796
|
-
},
|
|
797
|
-
{
|
|
798
|
-
"kind": "arg",
|
|
799
|
-
"path": "args.collection_symbol"
|
|
800
|
-
}
|
|
801
|
-
]
|
|
802
|
-
}
|
|
803
|
-
},
|
|
804
|
-
{
|
|
805
|
-
"name": "core_collection",
|
|
806
|
-
"writable": true
|
|
807
|
-
},
|
|
808
|
-
{
|
|
809
|
-
"name": "metaplex_program",
|
|
810
|
-
"address": "CoREENxT6tW1HoK8ypY1SxRMZTcVPm7R94rH4PZNhX7d"
|
|
811
|
-
},
|
|
812
|
-
{
|
|
813
|
-
"name": "system_program",
|
|
814
|
-
"address": "11111111111111111111111111111111"
|
|
815
|
-
}
|
|
816
|
-
],
|
|
817
|
-
"args": [
|
|
818
|
-
{
|
|
819
|
-
"name": "args",
|
|
820
|
-
"type": {
|
|
821
|
-
"defined": {
|
|
822
|
-
"name": "MintPoseidonArgs"
|
|
823
|
-
}
|
|
824
|
-
}
|
|
825
|
-
}
|
|
826
|
-
]
|
|
827
|
-
},
|
|
828
758
|
{
|
|
829
759
|
"name": "mint_ticket",
|
|
830
760
|
"discriminator": [159, 167, 223, 60, 138, 6, 23, 29],
|
|
@@ -2522,22 +2452,6 @@
|
|
|
2522
2452
|
]
|
|
2523
2453
|
}
|
|
2524
2454
|
},
|
|
2525
|
-
{
|
|
2526
|
-
"name": "MintPoseidonArgs",
|
|
2527
|
-
"type": {
|
|
2528
|
-
"kind": "struct",
|
|
2529
|
-
"fields": [
|
|
2530
|
-
{
|
|
2531
|
-
"name": "collection_symbol",
|
|
2532
|
-
"type": "string"
|
|
2533
|
-
},
|
|
2534
|
-
{
|
|
2535
|
-
"name": "number",
|
|
2536
|
-
"type": "u64"
|
|
2537
|
-
}
|
|
2538
|
-
]
|
|
2539
|
-
}
|
|
2540
|
-
},
|
|
2541
2455
|
{
|
|
2542
2456
|
"name": "MintTicketArgs",
|
|
2543
2457
|
"type": {
|
|
@@ -1080,76 +1080,6 @@ export type TriadProtocol = {
|
|
|
1080
1080
|
}
|
|
1081
1081
|
];
|
|
1082
1082
|
},
|
|
1083
|
-
{
|
|
1084
|
-
name: 'mintPoseidon';
|
|
1085
|
-
discriminator: [102, 210, 5, 220, 154, 54, 98, 23];
|
|
1086
|
-
accounts: [
|
|
1087
|
-
{
|
|
1088
|
-
name: 'signer';
|
|
1089
|
-
writable: true;
|
|
1090
|
-
signer: true;
|
|
1091
|
-
},
|
|
1092
|
-
{
|
|
1093
|
-
name: 'nft';
|
|
1094
|
-
writable: true;
|
|
1095
|
-
pda: {
|
|
1096
|
-
seeds: [
|
|
1097
|
-
{
|
|
1098
|
-
kind: 'const';
|
|
1099
|
-
value: [112, 111, 115, 101, 105, 100, 111, 110];
|
|
1100
|
-
},
|
|
1101
|
-
{
|
|
1102
|
-
kind: 'arg';
|
|
1103
|
-
path: 'args.number';
|
|
1104
|
-
}
|
|
1105
|
-
];
|
|
1106
|
-
};
|
|
1107
|
-
},
|
|
1108
|
-
{
|
|
1109
|
-
name: 'asset';
|
|
1110
|
-
writable: true;
|
|
1111
|
-
signer: true;
|
|
1112
|
-
},
|
|
1113
|
-
{
|
|
1114
|
-
name: 'collection';
|
|
1115
|
-
writable: true;
|
|
1116
|
-
pda: {
|
|
1117
|
-
seeds: [
|
|
1118
|
-
{
|
|
1119
|
-
kind: 'const';
|
|
1120
|
-
value: [99, 111, 108, 108, 101, 99, 116, 105, 111, 110];
|
|
1121
|
-
},
|
|
1122
|
-
{
|
|
1123
|
-
kind: 'arg';
|
|
1124
|
-
path: 'args.collection_symbol';
|
|
1125
|
-
}
|
|
1126
|
-
];
|
|
1127
|
-
};
|
|
1128
|
-
},
|
|
1129
|
-
{
|
|
1130
|
-
name: 'coreCollection';
|
|
1131
|
-
writable: true;
|
|
1132
|
-
},
|
|
1133
|
-
{
|
|
1134
|
-
name: 'metaplexProgram';
|
|
1135
|
-
address: 'CoREENxT6tW1HoK8ypY1SxRMZTcVPm7R94rH4PZNhX7d';
|
|
1136
|
-
},
|
|
1137
|
-
{
|
|
1138
|
-
name: 'systemProgram';
|
|
1139
|
-
address: '11111111111111111111111111111111';
|
|
1140
|
-
}
|
|
1141
|
-
];
|
|
1142
|
-
args: [
|
|
1143
|
-
{
|
|
1144
|
-
name: 'args';
|
|
1145
|
-
type: {
|
|
1146
|
-
defined: {
|
|
1147
|
-
name: 'mintPoseidonArgs';
|
|
1148
|
-
};
|
|
1149
|
-
};
|
|
1150
|
-
}
|
|
1151
|
-
];
|
|
1152
|
-
},
|
|
1153
1083
|
{
|
|
1154
1084
|
name: 'mintTicket';
|
|
1155
1085
|
discriminator: [159, 167, 223, 60, 138, 6, 23, 29];
|
|
@@ -3278,22 +3208,6 @@ export type TriadProtocol = {
|
|
|
3278
3208
|
];
|
|
3279
3209
|
};
|
|
3280
3210
|
},
|
|
3281
|
-
{
|
|
3282
|
-
name: 'mintPoseidonArgs';
|
|
3283
|
-
type: {
|
|
3284
|
-
kind: 'struct';
|
|
3285
|
-
fields: [
|
|
3286
|
-
{
|
|
3287
|
-
name: 'collectionSymbol';
|
|
3288
|
-
type: 'string';
|
|
3289
|
-
},
|
|
3290
|
-
{
|
|
3291
|
-
name: 'number';
|
|
3292
|
-
type: 'u64';
|
|
3293
|
-
}
|
|
3294
|
-
];
|
|
3295
|
-
};
|
|
3296
|
-
},
|
|
3297
3211
|
{
|
|
3298
3212
|
name: 'mintTicketArgs';
|
|
3299
3213
|
type: {
|
package/dist/utils/helpers.d.ts
CHANGED
|
@@ -9,3 +9,4 @@ export declare const formatStake: (stake: any) => Stake;
|
|
|
9
9
|
export declare const formatUser: (user: any) => User;
|
|
10
10
|
export declare const formatMarket: (account: any, address: PublicKey) => Market;
|
|
11
11
|
export declare const accountToMarketV1: (account: any, address: PublicKey) => Market;
|
|
12
|
+
export declare const calculateStakeRewards: (stake: Stake, collections: number) => number;
|
package/dist/utils/helpers.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.accountToMarketV1 = exports.formatMarket = exports.formatUser = exports.formatStake = exports.formatStakeVault = exports.decodeString = exports.encodeString = void 0;
|
|
3
|
+
exports.calculateStakeRewards = exports.accountToMarketV1 = exports.formatMarket = exports.formatUser = exports.formatStake = exports.formatStakeVault = exports.decodeString = exports.encodeString = void 0;
|
|
4
4
|
const trade_1 = require("../types/trade");
|
|
5
|
+
const constants_1 = require("./constants");
|
|
5
6
|
const encodeString = (value, alloc = 32) => {
|
|
6
7
|
const buffer = Buffer.alloc(alloc, 32);
|
|
7
8
|
buffer.write(value);
|
|
@@ -125,3 +126,25 @@ const accountToMarketV1 = (account, address) => {
|
|
|
125
126
|
};
|
|
126
127
|
};
|
|
127
128
|
exports.accountToMarketV1 = accountToMarketV1;
|
|
129
|
+
const calculateStakeRewards = (stake, collections) => {
|
|
130
|
+
if (stake.withdrawTs !== 0)
|
|
131
|
+
return 0;
|
|
132
|
+
if (collections > 3)
|
|
133
|
+
return 0;
|
|
134
|
+
const collectionsMultiplier = collections * 150;
|
|
135
|
+
const maxRank = 1633;
|
|
136
|
+
const rank = 963;
|
|
137
|
+
const rankWeight = (maxRank - rank + 1) / maxRank;
|
|
138
|
+
const userStakedAmount = stake.mint === constants_1.TRD_MINT.toBase58()
|
|
139
|
+
? stake.amount
|
|
140
|
+
: stake.amount * 10000 * Math.pow(10, constants_1.TRD_DECIMALS);
|
|
141
|
+
const formattedAmount = userStakedAmount / Math.pow(10, constants_1.TRD_DECIMALS) + collectionsMultiplier;
|
|
142
|
+
const adjustedAmount = formattedAmount * rankWeight;
|
|
143
|
+
const lastClaim = stake.claimedTs === 0 ? stake.initTs : stake.claimedTs;
|
|
144
|
+
const currentTime = Math.floor(Date.now() / 1000);
|
|
145
|
+
const secondsStaked = currentTime - lastClaim;
|
|
146
|
+
const userBaseRewards = ((adjustedAmount / 10000) * secondsStaked) / 86400;
|
|
147
|
+
const rewards = userBaseRewards * Math.pow(10, constants_1.TRD_DECIMALS);
|
|
148
|
+
return (rewards + stake.available) / Math.pow(10, constants_1.TRD_DECIMALS);
|
|
149
|
+
};
|
|
150
|
+
exports.calculateStakeRewards = calculateStakeRewards;
|