@triadxyz/triad-protocol 0.0.2-beta → 0.0.4-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
@@ -114,10 +114,9 @@ export default class Stake {
114
114
  * @param wallet - User wallet
115
115
  * @param mint - NFT mint
116
116
  * @param week - Week rewards
117
- * @param amount - Reward amount
118
117
  * @param stakeVault - Name of the stake vault
119
118
  * @param nftName - Name of the nft
120
119
  *
121
120
  */
122
- claimStakeRewards({ wallet, mint, week, stakeVault, nftName }: ClaimStakeRewardsArgs, options?: RpcOptions): Promise<string>;
121
+ claimStakeRewards({ wallet, mint, week, stakeVault, nftName }: ClaimStakeRewardsArgs, options?: RpcOptions): Promise<any>;
123
122
  }
package/dist/stake.js CHANGED
@@ -275,6 +275,8 @@ class Stake {
275
275
  const StakeVault = (0, helpers_1.getStakeVaultAddressSync)(this.program.programId, stakeVault);
276
276
  const FromAta = (0, helpers_1.getATASync)(StakeVault, mint);
277
277
  const ToAta = (0, helpers_1.getATASync)(wallet, mint);
278
+ const Stake = (0, helpers_1.getStakeAddressSync)(this.program.programId, nftName);
279
+ const NFTRewards = (0, helpers_1.getNFTRewardsAddressSync)(this.program.programId, Stake);
278
280
  const method = this.program.methods
279
281
  .withdrawNft({
280
282
  nftName,
@@ -284,6 +286,7 @@ class Stake {
284
286
  signer: wallet,
285
287
  fromAta: FromAta,
286
288
  toAta: ToAta,
289
+ nftRewards: NFTRewards,
287
290
  admin: new web3_js_1.PublicKey('82ppCojm3yrEKgdpH8B5AmBJTU1r1uAWXFWhxvPs9UCR'),
288
291
  mint: mint
289
292
  });
@@ -368,7 +371,8 @@ class Stake {
368
371
  }).compileToV0Message();
369
372
  const tx = new web3_js_1.VersionedTransaction(messageV0);
370
373
  return this.provider.sendAndConfirm(tx, [], {
371
- skipPreflight: options === null || options === void 0 ? void 0 : options.skipPreflight
374
+ skipPreflight: options === null || options === void 0 ? void 0 : options.skipPreflight,
375
+ commitment: 'confirmed'
372
376
  });
373
377
  });
374
378
  }
@@ -377,7 +381,6 @@ class Stake {
377
381
  * @param wallet - User wallet
378
382
  * @param mint - NFT mint
379
383
  * @param week - Week rewards
380
- * @param amount - Reward amount
381
384
  * @param stakeVault - Name of the stake vault
382
385
  * @param nftName - Name of the nft
383
386
  *
@@ -389,19 +392,22 @@ class Stake {
389
392
  const NFTRewards = (0, helpers_1.getNFTRewardsAddressSync)(this.program.programId, Stake);
390
393
  const FromAta = (0, helpers_1.getATASync)(StakeVault, mint);
391
394
  const ToAta = (0, helpers_1.getATASync)(wallet, mint);
392
- const method = this.program.methods
393
- .claimStakeRewards({
394
- week
395
- })
396
- .accounts({
397
- signer: wallet,
398
- fromAta: FromAta,
399
- toAta: ToAta,
400
- mint: mint,
401
- nftRewards: NFTRewards,
402
- stake: Stake,
403
- stakeVault: StakeVault
404
- });
395
+ let method;
396
+ for (let w of week) {
397
+ method = this.program.methods
398
+ .claimStakeRewards({
399
+ week: w
400
+ })
401
+ .accounts({
402
+ signer: wallet,
403
+ fromAta: FromAta,
404
+ toAta: ToAta,
405
+ mint: mint,
406
+ nftRewards: NFTRewards,
407
+ stake: Stake,
408
+ stakeVault: StakeVault
409
+ });
410
+ }
405
411
  if (options === null || options === void 0 ? void 0 : options.microLamports) {
406
412
  method.postInstructions([
407
413
  web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({
package/dist/test.js CHANGED
@@ -28,7 +28,7 @@ const wallet = new anchor_1.Wallet(keypair);
28
28
  const triadProtocol = new index_1.default(connection, wallet);
29
29
  const populateStakeDay = () => __awaiter(void 0, void 0, void 0, function* () {
30
30
  const { perDay } = yield triadProtocol.stake.getStakeVaultRewards(constants_1.STAKE_SEASON_1);
31
- const day = 1719755851;
31
+ const day = 1720360651;
32
32
  const stakes = yield triadProtocol.stake.getStakesByDay(constants_1.STAKE_SEASON_1, day);
33
33
  const newItems = [];
34
34
  const itemsByAuthority = stakes.reduce((acc, item) => {
@@ -36,6 +36,9 @@ const populateStakeDay = () => __awaiter(void 0, void 0, void 0, function* () {
36
36
  if (!itemRarity) {
37
37
  return acc;
38
38
  }
39
+ if (item.withdrawTs !== 0 && item.withdrawTs < 1720441379) {
40
+ return acc;
41
+ }
39
42
  if (!acc[item.authority]) {
40
43
  acc[item.authority] = [];
41
44
  }
@@ -46,14 +49,19 @@ const populateStakeDay = () => __awaiter(void 0, void 0, void 0, function* () {
46
49
  const items = itemsByAuthority[authority];
47
50
  items.sort((a, b) => a.rarityRankHrtt - b.rarityRankHrtt);
48
51
  items.forEach((item, index) => {
49
- const collections = Object.values(users_collections_week_1_json_1.default.find((collection) => Object.keys(collection)[0] === item.authority))[0];
50
- let totalMultiplier = (0, helpers_1.calculateTotalMultiplier)(index === 0
51
- ? Object.keys(item.collections).map((x) => x.toUpperCase())
52
- : [], {
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()) : [], {
53
61
  max: 1839,
54
62
  currentPosition: item.rarityRankHrtt
55
63
  });
56
- newItems.push(Object.assign(Object.assign({}, item), { totalMultiplier, collections: index === 0 ? collections : {} }));
64
+ newItems.push(Object.assign(Object.assign({}, item), { totalMultiplier, collections: index === 0 ? collections[0] : {} }));
57
65
  });
58
66
  });
59
67
  const totalMultiplierSum = newItems.reduce((sum, user) => sum + user.totalMultiplier, 0);
@@ -84,8 +92,8 @@ const requestWithdraw = () => __awaiter(void 0, void 0, void 0, function* () {
84
92
  const updateStakeVaultStatus = () => __awaiter(void 0, void 0, void 0, function* () {
85
93
  const response = yield triadProtocol.stake.updateStakeVaultStatus({
86
94
  wallet: wallet.publicKey,
87
- isLocked: false,
88
- week: 0,
95
+ isLocked: true,
96
+ week: 1,
89
97
  stakeVault: constants_1.STAKE_SEASON_1
90
98
  }, {
91
99
  skipPreflight: true,
@@ -115,7 +123,7 @@ const claimStakeRewards = () => __awaiter(void 0, void 0, void 0, function* () {
115
123
  const response = yield triadProtocol.stake.claimStakeRewards({
116
124
  wallet: wallet.publicKey,
117
125
  mint: new web3_js_1.PublicKey(''),
118
- week: 0,
126
+ week: [],
119
127
  stakeVault: constants_1.STAKE_SEASON_1,
120
128
  nftName: ''
121
129
  }, {
@@ -126,6 +134,7 @@ const claimStakeRewards = () => __awaiter(void 0, void 0, void 0, function* () {
126
134
  });
127
135
  const getStakes = () => __awaiter(void 0, void 0, void 0, function* () {
128
136
  const response = yield triadProtocol.stake.getStakes(constants_1.STAKE_SEASON_1);
137
+ console.log(JSON.stringify(response, null, 2));
129
138
  const users = response
130
139
  .filter((item, index, self) => index === self.findIndex((t) => t.authority === item.authority))
131
140
  .map((user) => user.authority);
@@ -150,17 +159,48 @@ const stake = () => __awaiter(void 0, void 0, void 0, function* () {
150
159
  });
151
160
  console.log(response);
152
161
  });
153
- const getWeeklyRewards = () => __awaiter(void 0, void 0, void 0, function* () {
154
- let weekly_rewards = 0;
155
- const users = fs_1.default.readFileSync('./src/utils/stake-season-1/users.json', 'utf-8');
156
- const usersArray = JSON.parse(users);
157
- for (let i = 0; i < usersArray.length; i++) {
158
- const user = usersArray[i];
159
- const stakes = yield triadProtocol.stake.getStakeByWallet(new web3_js_1.PublicKey(user), constants_1.STAKE_SEASON_1);
160
- const rewards = stakes.reduce((acc, stake) => {
161
- return acc + stake.weeklyRewards;
162
- }, 0);
163
- weekly_rewards += rewards;
164
- console.log(weekly_rewards);
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`);
165
205
  }
166
206
  });
@@ -343,6 +343,31 @@
343
343
  }
344
344
  ]
345
345
  },
346
+ {
347
+ "name": "jupiter_swap",
348
+ "discriminator": [116, 207, 0, 196, 252, 120, 243, 18],
349
+ "accounts": [
350
+ {
351
+ "name": "user_account",
352
+ "writable": true,
353
+ "signer": true
354
+ },
355
+ {
356
+ "name": "jupiter_program",
357
+ "address": "JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4"
358
+ },
359
+ {
360
+ "name": "system_program",
361
+ "address": "11111111111111111111111111111111"
362
+ }
363
+ ],
364
+ "args": [
365
+ {
366
+ "name": "data",
367
+ "type": "bytes"
368
+ }
369
+ ]
370
+ },
346
371
  {
347
372
  "name": "open_position",
348
373
  "discriminator": [135, 128, 47, 77, 15, 152, 240, 49],
@@ -53,7 +53,7 @@ export type UpdateStakeVaultStatusArgs = {
53
53
  };
54
54
  export type ClaimStakeRewardsArgs = {
55
55
  wallet: PublicKey;
56
- week: number;
56
+ week: number[];
57
57
  mint: PublicKey;
58
58
  stakeVault: string;
59
59
  nftName: string;
@@ -378,6 +378,31 @@ export type TriadProtocol = {
378
378
  }
379
379
  ];
380
380
  },
381
+ {
382
+ name: 'jupiterSwap';
383
+ discriminator: [116, 207, 0, 196, 252, 120, 243, 18];
384
+ accounts: [
385
+ {
386
+ name: 'userAccount';
387
+ writable: true;
388
+ signer: true;
389
+ },
390
+ {
391
+ name: 'jupiterProgram';
392
+ address: 'JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4';
393
+ },
394
+ {
395
+ name: 'systemProgram';
396
+ address: '11111111111111111111111111111111';
397
+ }
398
+ ];
399
+ args: [
400
+ {
401
+ name: 'data';
402
+ type: 'bytes';
403
+ }
404
+ ];
405
+ },
381
406
  {
382
407
  name: 'openPosition';
383
408
  discriminator: [135, 128, 47, 77, 15, 152, 240, 49];