@triadxyz/triad-protocol 0.0.6-beta → 0.0.8-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/stake.d.ts CHANGED
@@ -56,7 +56,7 @@ export default class Stake {
56
56
  * @param rarity - NFT rarity
57
57
  *
58
58
  */
59
- stake({ name, wallet, mint, collections, rarity, stakeVault }: StakeArgs, options?: RpcOptions): Promise<string>;
59
+ stakeNft({ name, wallet, mint, collections, rarity, stakeVault }: StakeArgs, options?: RpcOptions): Promise<string>;
60
60
  /**
61
61
  * Initialize Stake Vault
62
62
  * @param name - The ticker's name
@@ -82,14 +82,14 @@ export default class Stake {
82
82
  */
83
83
  requestWithdraw({ wallet, nftName, mint, stakeVault }: RequestWithdrawArgs, options?: RpcOptions): Promise<string>;
84
84
  /**
85
- * Withdraw NFT
85
+ * Withdraw Stake
86
86
  * @param wallet - User wallet
87
- * @param nftName - NFT name
87
+ * @param nftName - Stake name
88
88
  * @param mint - NFT mint
89
89
  * @param stakeVault - Name of the stake vault
90
90
  *
91
91
  */
92
- withdraw({ wallet, nftName, mint, stakeVault }: WithdrawArgs, options?: RpcOptions): Promise<string>;
92
+ withdrawStake({ wallet, nftName, mint, stakeVault }: WithdrawArgs, options?: RpcOptions): Promise<string>;
93
93
  /**
94
94
  * Update Stake Vault Status
95
95
  * @param wallet - User wallet
package/dist/stake.js CHANGED
@@ -74,21 +74,24 @@ class Stake {
74
74
  .reduce((a, b) => a + b, 0);
75
75
  let allRewards = stake.dailyRewards.reduce((a, b) => a + b);
76
76
  stake.rewardsToClaim = 0;
77
- stake.dailyRewards.forEach((item, index) => {
78
- let week = 0;
79
- let limit = 6;
77
+ let index = 0;
78
+ let week = 0;
79
+ let limit = 7;
80
+ for (const item of stake.dailyRewards) {
80
81
  if (!stake.weeklyRewardsPaid[week]) {
81
82
  stake.rewardsToClaim += item;
82
83
  }
83
84
  if (index === limit) {
84
85
  limit += 6;
85
- week + 1;
86
+ week += 1;
86
87
  }
87
- });
88
+ index++;
89
+ }
88
90
  stake.weeklyRewards = rewards;
89
91
  stake.allRewards = allRewards;
90
92
  }
91
93
  catch (error) {
94
+ console.log(error);
92
95
  stake.apr = 0;
93
96
  stake.dailyRewards = [];
94
97
  stake.weeklyRewardsPaid = [];
@@ -154,11 +157,9 @@ class Stake {
154
157
  * @param rarity - NFT rarity
155
158
  *
156
159
  */
157
- stake({ name, wallet, mint, collections, rarity, stakeVault }, options) {
160
+ stakeNft({ name, wallet, mint, collections, rarity, stakeVault }, options) {
158
161
  return __awaiter(this, void 0, void 0, function* () {
159
162
  const FromAta = (0, helpers_1.getATASync)(wallet, mint);
160
- const StakeVault = (0, helpers_1.getStakeVaultAddressSync)(this.program.programId, stakeVault);
161
- const ToAta = (0, helpers_1.getATASync)(StakeVault, mint);
162
163
  let items = [];
163
164
  Object.keys(collections).forEach((key) => {
164
165
  if (collections[key]) {
@@ -166,7 +167,7 @@ class Stake {
166
167
  }
167
168
  });
168
169
  const method = this.program.methods
169
- .stake({
170
+ .stakeNft({
170
171
  name,
171
172
  collections: items,
172
173
  rarity,
@@ -175,7 +176,6 @@ class Stake {
175
176
  .accounts({
176
177
  signer: wallet,
177
178
  fromAta: FromAta,
178
- toAta: ToAta,
179
179
  mint: mint
180
180
  });
181
181
  if (options === null || options === void 0 ? void 0 : options.microLamports) {
@@ -227,8 +227,6 @@ class Stake {
227
227
  depositStakeRewards({ wallet, mint, amount, stakeVault }, options) {
228
228
  return __awaiter(this, void 0, void 0, function* () {
229
229
  const FromAta = (0, helpers_1.getATASync)(wallet, mint);
230
- const StakeVault = (0, helpers_1.getStakeVaultAddressSync)(this.program.programId, stakeVault);
231
- const ToAta = (0, helpers_1.getATASync)(StakeVault, mint);
232
230
  const method = this.program.methods
233
231
  .depositStakeRewards({
234
232
  amount,
@@ -237,7 +235,6 @@ class Stake {
237
235
  .accounts({
238
236
  signer: wallet,
239
237
  fromAta: FromAta,
240
- toAta: ToAta,
241
238
  mint: mint
242
239
  });
243
240
  if (options === null || options === void 0 ? void 0 : options.microLamports) {
@@ -259,14 +256,13 @@ class Stake {
259
256
  */
260
257
  requestWithdraw({ wallet, nftName, mint, stakeVault }, options) {
261
258
  return __awaiter(this, void 0, void 0, function* () {
262
- const method = this.program.methods
263
- .requestWithdrawNft({
264
- nftName,
265
- stakeVault
266
- })
267
- .accounts({
259
+ const stakeVaultPDA = (0, helpers_1.getStakeVaultAddressSync)(this.program.programId, stakeVault);
260
+ const stakePDA = (0, helpers_1.getStakeAddressSync)(this.program.programId, nftName);
261
+ const method = this.program.methods.requestWithdrawStake().accounts({
268
262
  signer: wallet,
269
- mint: mint
263
+ mint: mint,
264
+ stake: stakePDA,
265
+ stakeVault: stakeVaultPDA
270
266
  });
271
267
  if (options === null || options === void 0 ? void 0 : options.microLamports) {
272
268
  method.postInstructions([
@@ -279,30 +275,25 @@ class Stake {
279
275
  });
280
276
  }
281
277
  /**
282
- * Withdraw NFT
278
+ * Withdraw Stake
283
279
  * @param wallet - User wallet
284
- * @param nftName - NFT name
280
+ * @param nftName - Stake name
285
281
  * @param mint - NFT mint
286
282
  * @param stakeVault - Name of the stake vault
287
283
  *
288
284
  */
289
- withdraw({ wallet, nftName, mint, stakeVault }, options) {
285
+ withdrawStake({ wallet, nftName, mint, stakeVault }, options) {
290
286
  return __awaiter(this, void 0, void 0, function* () {
291
- const StakeVault = (0, helpers_1.getStakeVaultAddressSync)(this.program.programId, stakeVault);
292
- const FromAta = (0, helpers_1.getATASync)(StakeVault, mint);
293
- const ToAta = (0, helpers_1.getATASync)(wallet, mint);
294
- const Stake = (0, helpers_1.getStakeAddressSync)(this.program.programId, nftName);
295
- const NFTRewards = (0, helpers_1.getNFTRewardsAddressSync)(this.program.programId, Stake);
296
- const method = this.program.methods
297
- .withdrawNft({
298
- nftName,
299
- stakeVault
300
- })
301
- .accounts({
287
+ const stakeVaultPDA = (0, helpers_1.getStakeVaultAddressSync)(this.program.programId, stakeVault);
288
+ const FromAta = (0, helpers_1.getATASync)(stakeVaultPDA, mint);
289
+ const stakePDA = (0, helpers_1.getStakeAddressSync)(this.program.programId, nftName);
290
+ const NFTRewards = (0, helpers_1.getNFTRewardsAddressSync)(this.program.programId, stakePDA);
291
+ const method = this.program.methods.withdrawStake().accounts({
302
292
  signer: wallet,
303
293
  fromAta: FromAta,
304
- toAta: ToAta,
305
294
  nftRewards: NFTRewards,
295
+ stake: stakePDA,
296
+ stakeVault: stakeVaultPDA,
306
297
  admin: new web3_js_1.PublicKey('82ppCojm3yrEKgdpH8B5AmBJTU1r1uAWXFWhxvPs9UCR'),
307
298
  mint: mint
308
299
  });
@@ -407,7 +398,6 @@ class Stake {
407
398
  const Stake = (0, helpers_1.getStakeAddressSync)(this.program.programId, nftName);
408
399
  const NFTRewards = (0, helpers_1.getNFTRewardsAddressSync)(this.program.programId, Stake);
409
400
  const FromAta = (0, helpers_1.getATASync)(StakeVault, mint);
410
- const ToAta = (0, helpers_1.getATASync)(wallet, mint);
411
401
  let ixs = [];
412
402
  for (let w of week) {
413
403
  ixs.push(yield this.program.methods
@@ -417,7 +407,6 @@ class Stake {
417
407
  .accounts({
418
408
  signer: wallet,
419
409
  fromAta: FromAta,
420
- toAta: ToAta,
421
410
  mint: mint,
422
411
  nftRewards: NFTRewards,
423
412
  stake: Stake,
package/dist/test.js CHANGED
@@ -17,66 +17,12 @@ const web3_js_1 = require("@solana/web3.js");
17
17
  const index_1 = __importDefault(require("./index"));
18
18
  const anchor_1 = require("@coral-xyz/anchor");
19
19
  const constants_1 = require("./utils/constants");
20
- const rarity_json_1 = __importDefault(require("./utils/stake-season-1/rarity.json"));
21
- const users_collections_week_1_json_1 = __importDefault(require("./utils/stake-season-1/users-collections-week-1.json"));
22
- const helpers_1 = require("./utils/helpers");
23
20
  const file = fs_1.default.readFileSync('/Users/dannpl/.config/solana/id.json');
24
21
  const rpc_file = fs_1.default.readFileSync('/Users/dannpl/.config/solana/rpc.txt');
25
22
  const keypair = web3_js_1.Keypair.fromSecretKey(new Uint8Array(JSON.parse(file.toString())));
26
23
  const connection = new web3_js_1.Connection(rpc_file.toString(), 'confirmed');
27
24
  const wallet = new anchor_1.Wallet(keypair);
28
25
  const triadProtocol = new index_1.default(connection, wallet);
29
- const populateStakeDay = () => __awaiter(void 0, void 0, void 0, function* () {
30
- const { perDay } = yield triadProtocol.stake.getStakeVaultRewards(constants_1.STAKE_SEASON_1);
31
- const day = 1720360651;
32
- const stakes = yield triadProtocol.stake.getStakesByDay(constants_1.STAKE_SEASON_1, day);
33
- const newItems = [];
34
- const itemsByAuthority = stakes.reduce((acc, item) => {
35
- const itemRarity = rarity_json_1.default.find((rarity) => rarity.onchainId === item.mint);
36
- if (!itemRarity) {
37
- return acc;
38
- }
39
- if (item.withdrawTs !== 0 && item.withdrawTs < 1720441379) {
40
- return acc;
41
- }
42
- if (!acc[item.authority]) {
43
- acc[item.authority] = [];
44
- }
45
- acc[item.authority].push(Object.assign(Object.assign({}, item), { rarity: itemRarity.rarity, rarityRankHrtt: itemRarity.rarityRankHrtt, collections: {} }));
46
- return acc;
47
- }, {});
48
- Object.keys(itemsByAuthority).forEach((authority) => {
49
- const items = itemsByAuthority[authority];
50
- items.sort((a, b) => a.rarityRankHrtt - b.rarityRankHrtt);
51
- items.forEach((item, index) => {
52
- var _a;
53
- const collections = (_a = users_collections_week_1_json_1.default[item.authority]) !== null && _a !== void 0 ? _a : {};
54
- const items = [];
55
- Object.keys(collections).forEach((collection) => {
56
- if (collections[collection]) {
57
- items.push(collection);
58
- }
59
- });
60
- let totalMultiplier = (0, helpers_1.calculateTotalMultiplier)(index === 0 ? items.map((item) => item.toUpperCase()) : [], {
61
- max: 1839,
62
- currentPosition: item.rarityRankHrtt
63
- });
64
- newItems.push(Object.assign(Object.assign({}, item), { totalMultiplier, collections: index === 0 ? collections[0] : {} }));
65
- });
66
- });
67
- const totalMultiplierSum = newItems.reduce((sum, user) => sum + user.totalMultiplier, 0);
68
- const rewards = newItems.map((item) => {
69
- const rewards = (item.totalMultiplier / totalMultiplierSum) * perDay;
70
- return Object.assign(Object.assign({}, item), { rewards, apr: (0, helpers_1.calculateAPR)({
71
- rewards,
72
- rate: 7,
73
- amount: 1,
74
- baseRewards: perDay
75
- }) });
76
- });
77
- const orderedRewards = rewards.sort((a, b) => b.rewards - a.rewards);
78
- fs_1.default.writeFileSync(`./src/utils/stake-season-1/stakes/2/${day}.json`, JSON.stringify(orderedRewards, null, 2));
79
- });
80
26
  const requestWithdraw = () => __awaiter(void 0, void 0, void 0, function* () {
81
27
  const response = yield triadProtocol.stake.requestWithdraw({
82
28
  wallet: wallet.publicKey,
@@ -93,8 +39,8 @@ const updateStakeVaultStatus = () => __awaiter(void 0, void 0, void 0, function*
93
39
  const response = yield triadProtocol.stake.updateStakeVaultStatus({
94
40
  wallet: wallet.publicKey,
95
41
  isLocked: true,
96
- week: 1,
97
- stakeVault: constants_1.STAKE_SEASON_1
42
+ week: 4,
43
+ stakeVault: constants_1.STAKE_SEASON
98
44
  }, {
99
45
  skipPreflight: true,
100
46
  microLamports: 10000
@@ -102,7 +48,7 @@ const updateStakeVaultStatus = () => __awaiter(void 0, void 0, void 0, function*
102
48
  console.log(response);
103
49
  });
104
50
  const withdraw = () => __awaiter(void 0, void 0, void 0, function* () {
105
- const response = yield triadProtocol.stake.withdraw({
51
+ const response = yield triadProtocol.stake.withdrawStake({
106
52
  wallet: wallet.publicKey,
107
53
  nftName: 'Triad 0',
108
54
  mint: new web3_js_1.PublicKey('FXRhaGeYue7bMCwcksNw4hJRY7jZ1YMwgmCu1Y8fyUNd'),
@@ -114,26 +60,27 @@ const withdraw = () => __awaiter(void 0, void 0, void 0, function* () {
114
60
  console.log(response);
115
61
  });
116
62
  const getStake = () => __awaiter(void 0, void 0, void 0, function* () {
117
- const response = yield triadProtocol.stake.getStakeByWallet(new web3_js_1.PublicKey('E48CKgbZVpDzerQ7DdommgqNobRHLqHy8RUVi8HXkSHE'), constants_1.STAKE_SEASON_1);
63
+ const response = yield triadProtocol.stake.getStakeByWallet(new web3_js_1.PublicKey('E48CKgbZVpDzerQ7DdommgqNobRHLqHy8RUVi8HXkSHE'), constants_1.STAKE_SEASON);
118
64
  const stakeVaults = yield triadProtocol.stake.getStakeVaults();
119
65
  console.log(response);
120
66
  console.log(stakeVaults);
121
67
  });
122
- const claimStakeRewards = () => __awaiter(void 0, void 0, void 0, function* () {
68
+ const claimStakeRewardsV1 = () => __awaiter(void 0, void 0, void 0, function* () {
123
69
  const response = yield triadProtocol.stake.claimStakeRewards({
124
70
  wallet: wallet.publicKey,
125
- mint: new web3_js_1.PublicKey(''),
126
- week: [],
127
- stakeVault: constants_1.STAKE_SEASON_1,
128
- nftName: ''
71
+ mint: new web3_js_1.PublicKey('t3DohmswhKk94PPbPYwA6ZKACyY3y5kbcqeQerAJjmV'),
72
+ week: [4],
73
+ stakeVault: constants_1.STAKE_SEASON,
74
+ nftName: 'Triad 2807'
129
75
  }, {
130
76
  skipPreflight: true,
131
77
  microLamports: 10000
132
78
  });
133
79
  console.log(response);
134
80
  });
135
- const getStakes = () => __awaiter(void 0, void 0, void 0, function* () {
136
- const response = yield triadProtocol.stake.getStakes(constants_1.STAKE_SEASON_1);
81
+ claimStakeRewardsV1();
82
+ const getStakers = () => __awaiter(void 0, void 0, void 0, function* () {
83
+ const response = yield triadProtocol.stake.getStakes(constants_1.STAKE_SEASON);
137
84
  console.log(JSON.stringify(response, null, 2));
138
85
  const users = response
139
86
  .filter((item, index, self) => index === self.findIndex((t) => t.authority === item.authority))
@@ -141,7 +88,7 @@ const getStakes = () => __awaiter(void 0, void 0, void 0, function* () {
141
88
  fs_1.default.writeFileSync('./src/utils/stake-season-1/users.json', JSON.stringify(users, null, 2));
142
89
  });
143
90
  const stake = () => __awaiter(void 0, void 0, void 0, function* () {
144
- const response = yield triadProtocol.stake.stake({
91
+ const response = yield triadProtocol.stake.stakeNft({
145
92
  name: 'Triad 0',
146
93
  wallet: wallet.publicKey,
147
94
  stakeVault: 'Rev 1',
@@ -159,51 +106,3 @@ const stake = () => __awaiter(void 0, void 0, void 0, function* () {
159
106
  });
160
107
  console.log(response);
161
108
  });
162
- const updateStakeRewards = () => __awaiter(void 0, void 0, void 0, function* () {
163
- const day = null;
164
- const ts = null;
165
- let file = fs_1.default.readFileSync(`./src/utils/stake-season-1/stakes/2/${ts}.json`);
166
- const data = JSON.parse(file.toString());
167
- const chunkLengths = 10;
168
- const chunks = [];
169
- for (let i = 0; i < data.length; i += chunkLengths) {
170
- chunks.push(data.slice(i, i + chunkLengths));
171
- }
172
- console.log(chunks.length);
173
- const failedChunks = [];
174
- for (let i = 0; i < chunks.length; i++) {
175
- const chunk = chunks[i];
176
- const items = [];
177
- console.log(`Processing chunk ${i + 1} of ${chunks.length}`);
178
- for (let j = 0; j < chunk.length; j++) {
179
- const item = chunk[j];
180
- items.push({
181
- rewards: new anchor_1.BN(item.rewards * Math.pow(10, constants_1.TTRIAD_DECIMALS)),
182
- apr: item.apr,
183
- nftName: item.name
184
- });
185
- }
186
- try {
187
- const rewards = yield triadProtocol.stake.updateStakeRewards({
188
- day,
189
- wallet: wallet.publicKey,
190
- items: items
191
- }, {
192
- skipPreflight: false,
193
- microLamports: 20000
194
- });
195
- console.log(rewards);
196
- }
197
- catch (error) {
198
- console.error(`Failed to update stake rewards for chunk ${i}:`, error);
199
- failedChunks.push(chunk);
200
- }
201
- }
202
- if (failedChunks.length > 0) {
203
- fs_1.default.writeFileSync(`./src/utils/stake-season-1/stakes/2/failedChunks_${ts}.json`, JSON.stringify(failedChunks, null, 2));
204
- console.log(`Failed chunks saved to ./src/utils/stake-season-1/stakes/2/failedChunks_${ts}.json`);
205
- }
206
- });
207
- triadProtocol.stake
208
- .getStakeByWallet(new web3_js_1.PublicKey('E48CKgbZVpDzerQ7DdommgqNobRHLqHy8RUVi8HXkSHE'), constants_1.STAKE_SEASON_1)
209
- .then(console.log);