@triadxyz/triad-protocol 0.1.0-alpha.7 → 0.1.0-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 +4 -48
- package/dist/index.js +26 -67
- package/dist/stake.d.ts +122 -0
- package/dist/stake.js +444 -0
- package/dist/test.d.ts +1 -0
- package/dist/test.js +107 -0
- package/dist/ticker.d.ts +10 -0
- package/dist/ticker.js +32 -6
- package/dist/types/idl_triad_protocol.json +1738 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/index.js +2 -0
- package/dist/types/stake.d.ts +118 -0
- package/dist/types/stake.js +20 -0
- package/dist/types/triad_protocol.d.ts +1496 -309
- package/dist/types/triad_protocol.js +0 -603
- package/dist/utils/constants.d.ts +31 -0
- package/dist/utils/constants.js +14 -1
- package/dist/utils/helpers.d.ts +18 -1
- package/dist/utils/helpers.js +81 -5
- package/dist/utils/priorityFee.d.ts +1 -0
- package/dist/utils/priorityFee.js +36 -0
- package/dist/utils/stake-season-1/rarity.json +11036 -0
- package/dist/utils/stake-season-1/users-collections-week-1.json +3290 -0
- package/dist/vault.d.ts +10 -10
- package/dist/vault.js +49 -34
- package/package.json +9 -8
package/dist/stake.js
ADDED
|
@@ -0,0 +1,444 @@
|
|
|
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
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
13
|
+
const helpers_1 = require("./utils/helpers");
|
|
14
|
+
const constants_1 = require("./utils/constants");
|
|
15
|
+
class Stake {
|
|
16
|
+
constructor(program, provider) {
|
|
17
|
+
this.provider = provider;
|
|
18
|
+
this.program = program;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Get all Stake Vaults
|
|
22
|
+
*/
|
|
23
|
+
getStakeVaults() {
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
const response = yield this.program.account.stakeVault.all();
|
|
26
|
+
return response.map((stakeVault) => (0, helpers_1.formatStakeVault)(stakeVault.account));
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Get Stake Vault by name
|
|
31
|
+
* @param stakeVault - Stake Vault name
|
|
32
|
+
*/
|
|
33
|
+
getStakeVaultByName(stakeVault) {
|
|
34
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
const StakeVault = (0, helpers_1.getStakeVaultAddressSync)(this.program.programId, stakeVault);
|
|
36
|
+
return (0, helpers_1.formatStakeVault)(yield this.program.account.stakeVault.fetch(StakeVault));
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Get all stakes by vault
|
|
41
|
+
* @param stakeVault - Stake Vault name
|
|
42
|
+
*
|
|
43
|
+
*/
|
|
44
|
+
getStakes(stakeVault) {
|
|
45
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
const response = yield this.program.account.stake.all();
|
|
47
|
+
const StakeVault = (0, helpers_1.getStakeVaultAddressSync)(this.program.programId, stakeVault);
|
|
48
|
+
return response
|
|
49
|
+
.filter((item) => item.account.stakeVault.toBase58() === StakeVault.toBase58())
|
|
50
|
+
.map((stake) => (0, helpers_1.formatStake)(stake.account));
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Get Stake by wallet
|
|
55
|
+
* @param wallet - User wallet
|
|
56
|
+
* @param stakeVault - Stake Vault name
|
|
57
|
+
*
|
|
58
|
+
*/
|
|
59
|
+
getStakeByWallet(wallet, stakeVault) {
|
|
60
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
61
|
+
const response = yield this.getStakes(stakeVault);
|
|
62
|
+
const stakeVaultByName = yield this.getStakeVaultByName(stakeVault);
|
|
63
|
+
const myStakes = response.filter((item) => item.authority === wallet.toBase58());
|
|
64
|
+
for (const stake of myStakes) {
|
|
65
|
+
try {
|
|
66
|
+
const stakeRewards = yield this.program.account.nftRewards.fetch(new web3_js_1.PublicKey(stake.stakeRewards));
|
|
67
|
+
let start = stakeVaultByName.week * 7;
|
|
68
|
+
let end = stakeVaultByName.week == 4 ? 30 : start + 7;
|
|
69
|
+
stake.apr = stakeRewards.apr;
|
|
70
|
+
stake.dailyRewards = stakeRewards.dailyRewards.map((reward) => reward.toNumber() / Math.pow(10, constants_1.TTRIAD_DECIMALS));
|
|
71
|
+
stake.weeklyRewardsPaid = stakeRewards.weeklyRewardsPaid;
|
|
72
|
+
let rewards = stake.dailyRewards
|
|
73
|
+
.slice(start, end)
|
|
74
|
+
.reduce((a, b) => a + b, 0);
|
|
75
|
+
let allRewards = stake.dailyRewards.reduce((a, b) => a + b);
|
|
76
|
+
stake.rewardsToClaim = 0;
|
|
77
|
+
let index = 0;
|
|
78
|
+
let week = 0;
|
|
79
|
+
let limit = 7;
|
|
80
|
+
for (const item of stake.dailyRewards) {
|
|
81
|
+
if (!stake.weeklyRewardsPaid[week]) {
|
|
82
|
+
stake.rewardsToClaim += item;
|
|
83
|
+
}
|
|
84
|
+
if (index === limit) {
|
|
85
|
+
limit += 6;
|
|
86
|
+
week += 1;
|
|
87
|
+
}
|
|
88
|
+
index++;
|
|
89
|
+
}
|
|
90
|
+
stake.weeklyRewards = rewards;
|
|
91
|
+
stake.allRewards = allRewards;
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
console.log(error);
|
|
95
|
+
stake.apr = 0;
|
|
96
|
+
stake.dailyRewards = [];
|
|
97
|
+
stake.weeklyRewardsPaid = [];
|
|
98
|
+
stake.weeklyRewards = 0;
|
|
99
|
+
stake.rewardsToClaim = 0;
|
|
100
|
+
stake.allRewards = 0;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return myStakes;
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Get Stake Vault Rewards details
|
|
108
|
+
* @param stakeVault - Stake Vault name
|
|
109
|
+
*/
|
|
110
|
+
getStakeVaultRewards(stakeVault) {
|
|
111
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
112
|
+
const StakeVault = (0, helpers_1.getStakeVaultAddressSync)(this.program.programId, stakeVault);
|
|
113
|
+
const response = yield this.program.account.stakeVault.fetch(StakeVault);
|
|
114
|
+
const amount = response.amount.toNumber() / Math.pow(10, constants_1.TTRIAD_DECIMALS);
|
|
115
|
+
const period = (response.endTs.toNumber() - response.initTs.toNumber()) / (60 * 60 * 24);
|
|
116
|
+
const netAmount = amount - (amount * constants_1.TTRIAD_FEE) / 100;
|
|
117
|
+
const data = {
|
|
118
|
+
amount: netAmount,
|
|
119
|
+
perDay: netAmount / period,
|
|
120
|
+
perWeek: (netAmount / period) * 7,
|
|
121
|
+
perMonth: (netAmount / period) * 30,
|
|
122
|
+
period,
|
|
123
|
+
days: []
|
|
124
|
+
};
|
|
125
|
+
for (let ts = response.initTs.toNumber(); ts <= response.endTs.toNumber(); ts += 60 * 60 * 24) {
|
|
126
|
+
data.days.push(ts);
|
|
127
|
+
}
|
|
128
|
+
return data;
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Get Stakes by day
|
|
133
|
+
* @param stakeVault - Stake Vault name
|
|
134
|
+
* @param day - Day timestamp
|
|
135
|
+
*/
|
|
136
|
+
getStakesByDay(stakeVault, day) {
|
|
137
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
138
|
+
const stakes = yield this.getStakes(stakeVault);
|
|
139
|
+
const rewards = [];
|
|
140
|
+
stakes.forEach((stake) => {
|
|
141
|
+
const date = stake.initTs * 1000;
|
|
142
|
+
const stakeDay = day * 1000;
|
|
143
|
+
const currentDate = new Date().getTime();
|
|
144
|
+
if (date <= stakeDay && stakeDay <= currentDate) {
|
|
145
|
+
rewards.push(stake);
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
return rewards;
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Stake NFT
|
|
153
|
+
* @param name - NFT name
|
|
154
|
+
* @param wallet - User wallet
|
|
155
|
+
* @param mint - NFT mint
|
|
156
|
+
* @param collections - NFT collections
|
|
157
|
+
* @param rarity - NFT rarity
|
|
158
|
+
*
|
|
159
|
+
*/
|
|
160
|
+
stakeNft({ name, wallet, mint, collections, rarity, stakeVault }, options) {
|
|
161
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
162
|
+
const StakeVault = (0, helpers_1.getStakeVaultAddressSync)(this.program.programId, stakeVault);
|
|
163
|
+
const FromAta = (0, helpers_1.getATASync)(wallet, mint);
|
|
164
|
+
const ToAta = (0, helpers_1.getATASync)(StakeVault, mint);
|
|
165
|
+
let items = [];
|
|
166
|
+
Object.keys(collections).forEach((key) => {
|
|
167
|
+
if (collections[key]) {
|
|
168
|
+
items.push({ [key]: {} });
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
const method = this.program.methods
|
|
172
|
+
.stakeNft({
|
|
173
|
+
name,
|
|
174
|
+
collections: items,
|
|
175
|
+
rarity,
|
|
176
|
+
stakeVault
|
|
177
|
+
})
|
|
178
|
+
.accounts({
|
|
179
|
+
signer: wallet,
|
|
180
|
+
toAta: ToAta,
|
|
181
|
+
fromAta: FromAta,
|
|
182
|
+
mint: mint
|
|
183
|
+
});
|
|
184
|
+
if (options === null || options === void 0 ? void 0 : options.microLamports) {
|
|
185
|
+
method.postInstructions([
|
|
186
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({
|
|
187
|
+
microLamports: options.microLamports
|
|
188
|
+
})
|
|
189
|
+
]);
|
|
190
|
+
}
|
|
191
|
+
return method.rpc({ skipPreflight: options === null || options === void 0 ? void 0 : options.skipPreflight });
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Initialize Stake Vault
|
|
196
|
+
* @param name - The ticker's name
|
|
197
|
+
* @param slots - Amount available to users joining the vault
|
|
198
|
+
* @param collection - The Collection name
|
|
199
|
+
*
|
|
200
|
+
*/
|
|
201
|
+
initializeStakeVault({ name, slots, collection, amount }, options) {
|
|
202
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
203
|
+
const method = this.program.methods
|
|
204
|
+
.initializeStakeVault({
|
|
205
|
+
name,
|
|
206
|
+
slots,
|
|
207
|
+
collection,
|
|
208
|
+
amount
|
|
209
|
+
})
|
|
210
|
+
.accounts({
|
|
211
|
+
signer: this.provider.wallet.publicKey
|
|
212
|
+
});
|
|
213
|
+
if (options === null || options === void 0 ? void 0 : options.microLamports) {
|
|
214
|
+
method.postInstructions([
|
|
215
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({
|
|
216
|
+
microLamports: options.microLamports
|
|
217
|
+
})
|
|
218
|
+
]);
|
|
219
|
+
}
|
|
220
|
+
return method.rpc({ skipPreflight: options === null || options === void 0 ? void 0 : options.skipPreflight });
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Deposit Stake Rewards
|
|
225
|
+
* @param wallet - User wallet
|
|
226
|
+
* @param mint - NFT mint
|
|
227
|
+
* @param amount - Reward amount
|
|
228
|
+
*
|
|
229
|
+
*/
|
|
230
|
+
depositStakeRewards({ wallet, mint, amount, stakeVault }, options) {
|
|
231
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
232
|
+
const StakeVault = (0, helpers_1.getStakeVaultAddressSync)(this.program.programId, stakeVault);
|
|
233
|
+
const ToAta = (0, helpers_1.getATASync)(StakeVault, mint);
|
|
234
|
+
const FromAta = (0, helpers_1.getATASync)(wallet, mint);
|
|
235
|
+
const method = this.program.methods
|
|
236
|
+
.depositStakeRewards({
|
|
237
|
+
amount,
|
|
238
|
+
stakeVault
|
|
239
|
+
})
|
|
240
|
+
.accounts({
|
|
241
|
+
signer: wallet,
|
|
242
|
+
fromAta: FromAta,
|
|
243
|
+
toAta: ToAta,
|
|
244
|
+
mint: mint
|
|
245
|
+
});
|
|
246
|
+
if (options === null || options === void 0 ? void 0 : options.microLamports) {
|
|
247
|
+
method.postInstructions([
|
|
248
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({
|
|
249
|
+
microLamports: options.microLamports
|
|
250
|
+
})
|
|
251
|
+
]);
|
|
252
|
+
}
|
|
253
|
+
return method.rpc({ skipPreflight: options === null || options === void 0 ? void 0 : options.skipPreflight });
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Request Withdraw
|
|
258
|
+
* @param wallet - User wallet
|
|
259
|
+
* @param nftName - NFT name
|
|
260
|
+
* @param stakeVault - Name of the stake vault
|
|
261
|
+
*
|
|
262
|
+
*/
|
|
263
|
+
requestWithdraw({ wallet, nftName, mint, stakeVault }, options) {
|
|
264
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
265
|
+
const stakeVaultPDA = (0, helpers_1.getStakeVaultAddressSync)(this.program.programId, stakeVault);
|
|
266
|
+
const stakePDA = (0, helpers_1.getStakeAddressSync)(this.program.programId, nftName);
|
|
267
|
+
const method = this.program.methods.requestWithdrawStake().accounts({
|
|
268
|
+
signer: wallet,
|
|
269
|
+
mint: mint,
|
|
270
|
+
stake: stakePDA,
|
|
271
|
+
stakeVault: stakeVaultPDA
|
|
272
|
+
});
|
|
273
|
+
if (options === null || options === void 0 ? void 0 : options.microLamports) {
|
|
274
|
+
method.postInstructions([
|
|
275
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({
|
|
276
|
+
microLamports: options.microLamports
|
|
277
|
+
})
|
|
278
|
+
]);
|
|
279
|
+
}
|
|
280
|
+
return method.rpc({ skipPreflight: options === null || options === void 0 ? void 0 : options.skipPreflight });
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Withdraw Stake
|
|
285
|
+
* @param wallet - User wallet
|
|
286
|
+
* @param nftName - Stake name
|
|
287
|
+
* @param mint - NFT mint
|
|
288
|
+
* @param stakeVault - Name of the stake vault
|
|
289
|
+
*
|
|
290
|
+
*/
|
|
291
|
+
withdrawStake({ wallet, nftName, mint, stakeVault }, options) {
|
|
292
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
293
|
+
const stakeVaultPDA = (0, helpers_1.getStakeVaultAddressSync)(this.program.programId, stakeVault);
|
|
294
|
+
const FromAta = (0, helpers_1.getATASync)(stakeVaultPDA, mint);
|
|
295
|
+
const ToAta = (0, helpers_1.getATASync)(wallet, mint);
|
|
296
|
+
const stakePDA = (0, helpers_1.getStakeAddressSync)(this.program.programId, nftName);
|
|
297
|
+
const NFTRewards = (0, helpers_1.getNFTRewardsAddressSync)(this.program.programId, stakePDA);
|
|
298
|
+
const method = this.program.methods.withdrawStake().accounts({
|
|
299
|
+
signer: wallet,
|
|
300
|
+
fromAta: FromAta,
|
|
301
|
+
nftRewards: NFTRewards,
|
|
302
|
+
stake: stakePDA,
|
|
303
|
+
toAta: ToAta,
|
|
304
|
+
stakeVault: stakeVaultPDA,
|
|
305
|
+
admin: new web3_js_1.PublicKey('82ppCojm3yrEKgdpH8B5AmBJTU1r1uAWXFWhxvPs9UCR'),
|
|
306
|
+
mint: mint
|
|
307
|
+
});
|
|
308
|
+
if (options === null || options === void 0 ? void 0 : options.microLamports) {
|
|
309
|
+
method.postInstructions([
|
|
310
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({
|
|
311
|
+
microLamports: options.microLamports
|
|
312
|
+
})
|
|
313
|
+
]);
|
|
314
|
+
}
|
|
315
|
+
return method.rpc({ skipPreflight: options === null || options === void 0 ? void 0 : options.skipPreflight });
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Update Stake Vault Status
|
|
320
|
+
* @param wallet - User wallet
|
|
321
|
+
* @param stakeVault - Name of the stake vault
|
|
322
|
+
* @param isLocked - Status of the stake vault
|
|
323
|
+
* @param week - Current week rewards (Starts from 0)
|
|
324
|
+
*
|
|
325
|
+
*/
|
|
326
|
+
updateStakeVaultStatus({ wallet, isLocked, week, stakeVault }, options) {
|
|
327
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
328
|
+
const StakeVault = (0, helpers_1.getStakeVaultAddressSync)(this.program.programId, stakeVault);
|
|
329
|
+
const method = this.program.methods
|
|
330
|
+
.updateStakeVaultStatus({
|
|
331
|
+
isLocked,
|
|
332
|
+
week
|
|
333
|
+
})
|
|
334
|
+
.accounts({
|
|
335
|
+
signer: wallet,
|
|
336
|
+
stakeVault: StakeVault
|
|
337
|
+
});
|
|
338
|
+
if (options === null || options === void 0 ? void 0 : options.microLamports) {
|
|
339
|
+
method.postInstructions([
|
|
340
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({
|
|
341
|
+
microLamports: options.microLamports
|
|
342
|
+
})
|
|
343
|
+
]);
|
|
344
|
+
}
|
|
345
|
+
return method.rpc({ skipPreflight: options === null || options === void 0 ? void 0 : options.skipPreflight });
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* Update Stake Rewards
|
|
350
|
+
* @param wallet - User wallet
|
|
351
|
+
* @param nft_name - Name of the nft
|
|
352
|
+
* @param apr - APR based in the current day
|
|
353
|
+
* @param day - Day for update rewards (Starts from 0)
|
|
354
|
+
* @param rewards - Rewards for the day
|
|
355
|
+
*
|
|
356
|
+
*/
|
|
357
|
+
updateStakeRewards({ wallet, day, items }, options) {
|
|
358
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
359
|
+
const ixs = [
|
|
360
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({
|
|
361
|
+
microLamports: options.microLamports
|
|
362
|
+
}),
|
|
363
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({
|
|
364
|
+
units: 600000
|
|
365
|
+
})
|
|
366
|
+
];
|
|
367
|
+
for (const item of items) {
|
|
368
|
+
const Stake = (0, helpers_1.getStakeAddressSync)(this.program.programId, item.nftName);
|
|
369
|
+
ixs.push(yield this.program.methods
|
|
370
|
+
.updateStakeRewards({
|
|
371
|
+
rewards: item.rewards,
|
|
372
|
+
apr: item.apr,
|
|
373
|
+
day
|
|
374
|
+
})
|
|
375
|
+
.accounts({
|
|
376
|
+
signer: wallet,
|
|
377
|
+
stake: Stake
|
|
378
|
+
})
|
|
379
|
+
.instruction());
|
|
380
|
+
}
|
|
381
|
+
const { blockhash } = yield this.provider.connection.getLatestBlockhash();
|
|
382
|
+
const messageV0 = new web3_js_1.TransactionMessage({
|
|
383
|
+
instructions: ixs,
|
|
384
|
+
recentBlockhash: blockhash,
|
|
385
|
+
payerKey: wallet
|
|
386
|
+
}).compileToV0Message();
|
|
387
|
+
const tx = new web3_js_1.VersionedTransaction(messageV0);
|
|
388
|
+
return this.provider.sendAndConfirm(tx, [], {
|
|
389
|
+
skipPreflight: options === null || options === void 0 ? void 0 : options.skipPreflight,
|
|
390
|
+
commitment: 'confirmed'
|
|
391
|
+
});
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* Claim Stake Rewards
|
|
396
|
+
* @param wallet - User wallet
|
|
397
|
+
* @param mint - NFT mint
|
|
398
|
+
* @param week - Week rewards
|
|
399
|
+
* @param stakeVault - Name of the stake vault
|
|
400
|
+
* @param nftName - Name of the nft
|
|
401
|
+
*
|
|
402
|
+
*/
|
|
403
|
+
claimStakeRewards({ wallet, mint, week, stakeVault, nftName }, options) {
|
|
404
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
405
|
+
const StakeVault = (0, helpers_1.getStakeVaultAddressSync)(this.program.programId, stakeVault);
|
|
406
|
+
const Stake = (0, helpers_1.getStakeAddressSync)(this.program.programId, nftName);
|
|
407
|
+
const NFTRewards = (0, helpers_1.getNFTRewardsAddressSync)(this.program.programId, Stake);
|
|
408
|
+
const FromAta = (0, helpers_1.getATASync)(StakeVault, mint);
|
|
409
|
+
let ixs = [];
|
|
410
|
+
for (let w of week) {
|
|
411
|
+
ixs.push(yield this.program.methods
|
|
412
|
+
.claimStakeRewards({
|
|
413
|
+
week: w
|
|
414
|
+
})
|
|
415
|
+
.accounts({
|
|
416
|
+
signer: wallet,
|
|
417
|
+
fromAta: FromAta,
|
|
418
|
+
mint: mint,
|
|
419
|
+
nftRewards: NFTRewards,
|
|
420
|
+
stake: Stake,
|
|
421
|
+
stakeVault: StakeVault
|
|
422
|
+
})
|
|
423
|
+
.instruction());
|
|
424
|
+
}
|
|
425
|
+
if (options === null || options === void 0 ? void 0 : options.microLamports) {
|
|
426
|
+
ixs.push(web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({
|
|
427
|
+
microLamports: options.microLamports
|
|
428
|
+
}));
|
|
429
|
+
}
|
|
430
|
+
const { blockhash } = yield this.provider.connection.getLatestBlockhash();
|
|
431
|
+
const messageV0 = new web3_js_1.TransactionMessage({
|
|
432
|
+
payerKey: wallet,
|
|
433
|
+
recentBlockhash: blockhash,
|
|
434
|
+
instructions: ixs
|
|
435
|
+
}).compileToV0Message();
|
|
436
|
+
const tx = new web3_js_1.VersionedTransaction(messageV0);
|
|
437
|
+
return this.provider.sendAndConfirm(tx, [], {
|
|
438
|
+
skipPreflight: options === null || options === void 0 ? void 0 : options.skipPreflight,
|
|
439
|
+
commitment: 'confirmed'
|
|
440
|
+
});
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
exports.default = Stake;
|
package/dist/test.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/test.js
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
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
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const fs_1 = __importDefault(require("fs"));
|
|
16
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
17
|
+
const index_1 = __importDefault(require("./index"));
|
|
18
|
+
const anchor_1 = require("@coral-xyz/anchor");
|
|
19
|
+
const constants_1 = require("./utils/constants");
|
|
20
|
+
const file = fs_1.default.readFileSync('/Users/dannpl/.config/solana/id.json');
|
|
21
|
+
const rpc_file = fs_1.default.readFileSync('/Users/dannpl/.config/solana/rpc.txt');
|
|
22
|
+
const keypair = web3_js_1.Keypair.fromSecretKey(new Uint8Array(JSON.parse(file.toString())));
|
|
23
|
+
const connection = new web3_js_1.Connection(rpc_file.toString(), 'confirmed');
|
|
24
|
+
const wallet = new anchor_1.Wallet(keypair);
|
|
25
|
+
const triadProtocol = new index_1.default(connection, wallet);
|
|
26
|
+
const requestWithdraw = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
27
|
+
const response = yield triadProtocol.stake.requestWithdraw({
|
|
28
|
+
wallet: wallet.publicKey,
|
|
29
|
+
nftName: 'Triad 0',
|
|
30
|
+
mint: new web3_js_1.PublicKey('FXRhaGeYue7bMCwcksNw4hJRY7jZ1YMwgmCu1Y8fyUNd'),
|
|
31
|
+
stakeVault: 'Rev 1'
|
|
32
|
+
}, {
|
|
33
|
+
microLamports: 10000,
|
|
34
|
+
skipPreflight: true
|
|
35
|
+
});
|
|
36
|
+
console.log(response);
|
|
37
|
+
});
|
|
38
|
+
const updateStakeVaultStatus = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
39
|
+
const response = yield triadProtocol.stake.updateStakeVaultStatus({
|
|
40
|
+
wallet: wallet.publicKey,
|
|
41
|
+
isLocked: true,
|
|
42
|
+
week: 4,
|
|
43
|
+
stakeVault: constants_1.STAKE_SEASON
|
|
44
|
+
}, {
|
|
45
|
+
skipPreflight: true,
|
|
46
|
+
microLamports: 10000
|
|
47
|
+
});
|
|
48
|
+
console.log(response);
|
|
49
|
+
});
|
|
50
|
+
const withdraw = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
51
|
+
const response = yield triadProtocol.stake.withdrawStake({
|
|
52
|
+
wallet: wallet.publicKey,
|
|
53
|
+
nftName: 'Triad 2807',
|
|
54
|
+
mint: new web3_js_1.PublicKey('A4fu2s6bCbKAveVgACkxpMgtJUHqoRJsTyzRp1Jp8nuE'),
|
|
55
|
+
stakeVault: constants_1.STAKE_SEASON
|
|
56
|
+
}, {
|
|
57
|
+
microLamports: 10000,
|
|
58
|
+
skipPreflight: true
|
|
59
|
+
});
|
|
60
|
+
console.log(response);
|
|
61
|
+
});
|
|
62
|
+
const getStake = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
63
|
+
const response = yield triadProtocol.stake.getStakeByWallet(new web3_js_1.PublicKey('E48CKgbZVpDzerQ7DdommgqNobRHLqHy8RUVi8HXkSHE'), constants_1.STAKE_SEASON);
|
|
64
|
+
const stakeVaults = yield triadProtocol.stake.getStakeVaults();
|
|
65
|
+
console.log(response);
|
|
66
|
+
console.log(stakeVaults);
|
|
67
|
+
});
|
|
68
|
+
const claimStakeRewardsV1 = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
69
|
+
const response = yield triadProtocol.stake.claimStakeRewards({
|
|
70
|
+
wallet: wallet.publicKey,
|
|
71
|
+
mint: new web3_js_1.PublicKey('t3DohmswhKk94PPbPYwA6ZKACyY3y5kbcqeQerAJjmV'),
|
|
72
|
+
week: [4],
|
|
73
|
+
stakeVault: constants_1.STAKE_SEASON,
|
|
74
|
+
nftName: 'Triad 2807'
|
|
75
|
+
}, {
|
|
76
|
+
skipPreflight: true,
|
|
77
|
+
microLamports: 10000
|
|
78
|
+
});
|
|
79
|
+
console.log(response);
|
|
80
|
+
});
|
|
81
|
+
const getStakers = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
82
|
+
const response = yield triadProtocol.stake.getStakes(constants_1.STAKE_SEASON);
|
|
83
|
+
console.log(JSON.stringify(response, null, 2));
|
|
84
|
+
const users = response
|
|
85
|
+
.filter((item, index, self) => index === self.findIndex((t) => t.authority === item.authority))
|
|
86
|
+
.map((user) => user.authority);
|
|
87
|
+
fs_1.default.writeFileSync('./src/utils/stake-season-1/users.json', JSON.stringify(users, null, 2));
|
|
88
|
+
});
|
|
89
|
+
const stake = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
90
|
+
const response = yield triadProtocol.stake.stakeNft({
|
|
91
|
+
name: 'Triad 0',
|
|
92
|
+
wallet: wallet.publicKey,
|
|
93
|
+
stakeVault: 'Rev 1',
|
|
94
|
+
rarity: { mythic: {} },
|
|
95
|
+
collections: {
|
|
96
|
+
coleta: false,
|
|
97
|
+
undead: false,
|
|
98
|
+
alligators: false,
|
|
99
|
+
pyth: false
|
|
100
|
+
},
|
|
101
|
+
mint: new web3_js_1.PublicKey('FXRhaGeYue7bMCwcksNw4hJRY7jZ1YMwgmCu1Y8fyUNd')
|
|
102
|
+
}, {
|
|
103
|
+
skipPreflight: true,
|
|
104
|
+
microLamports: 20000
|
|
105
|
+
});
|
|
106
|
+
console.log(response);
|
|
107
|
+
});
|
package/dist/ticker.d.ts
CHANGED
|
@@ -31,4 +31,14 @@ export default class Ticker {
|
|
|
31
31
|
protocolProgramId: PublicKey;
|
|
32
32
|
tokenMint: PublicKey;
|
|
33
33
|
}): Promise<string>;
|
|
34
|
+
/**
|
|
35
|
+
* Update a ticker's price
|
|
36
|
+
* @param name - The ticker's name
|
|
37
|
+
* @param price - The ticker's price
|
|
38
|
+
*
|
|
39
|
+
*/
|
|
40
|
+
updateTickerPrice({ name, price }: {
|
|
41
|
+
name: string;
|
|
42
|
+
price: string;
|
|
43
|
+
}): Promise<string>;
|
|
34
44
|
}
|
package/dist/ticker.js
CHANGED
|
@@ -9,7 +9,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
12
13
|
const helpers_1 = require("./utils/helpers");
|
|
14
|
+
const bn_js_1 = require("bn.js");
|
|
13
15
|
class Ticker {
|
|
14
16
|
constructor(program, provider) {
|
|
15
17
|
this.provider = provider;
|
|
@@ -32,20 +34,44 @@ class Ticker {
|
|
|
32
34
|
*/
|
|
33
35
|
createTicker({ name, protocolProgramId, tokenMint }) {
|
|
34
36
|
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
-
const TickerPDA = (0, helpers_1.getTickerAddressSync)(this.program.programId, name);
|
|
36
|
-
const VaultPDA = (0, helpers_1.getVaultAddressSync)(this.program.programId, TickerPDA);
|
|
37
|
-
const TokenAccountPDA = (0, helpers_1.getTokenVaultAddressSync)(this.program.programId, VaultPDA);
|
|
38
37
|
return this.program.methods
|
|
39
38
|
.createTicker({ name, protocolProgramId })
|
|
40
39
|
.accounts({
|
|
41
40
|
signer: this.provider.wallet.publicKey,
|
|
42
|
-
ticker: TickerPDA,
|
|
43
|
-
vault: VaultPDA,
|
|
44
|
-
tokenAccount: TokenAccountPDA,
|
|
45
41
|
payerTokenMint: tokenMint
|
|
46
42
|
})
|
|
47
43
|
.rpc();
|
|
48
44
|
});
|
|
49
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* Update a ticker's price
|
|
48
|
+
* @param name - The ticker's name
|
|
49
|
+
* @param price - The ticker's price
|
|
50
|
+
*
|
|
51
|
+
*/
|
|
52
|
+
updateTickerPrice({ name, price }) {
|
|
53
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
const TickerPDA = (0, helpers_1.getTickerAddressSync)(this.program.programId, name);
|
|
55
|
+
const instructions = [
|
|
56
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({
|
|
57
|
+
microLamports: 12000
|
|
58
|
+
})
|
|
59
|
+
];
|
|
60
|
+
instructions.push(yield this.program.methods
|
|
61
|
+
.updateTickerPrice({ price: new bn_js_1.BN(price) })
|
|
62
|
+
.accounts({
|
|
63
|
+
signer: this.provider.wallet.publicKey,
|
|
64
|
+
ticker: TickerPDA
|
|
65
|
+
})
|
|
66
|
+
.instruction());
|
|
67
|
+
const { blockhash } = yield this.provider.connection.getLatestBlockhash();
|
|
68
|
+
const message = new web3_js_1.TransactionMessage({
|
|
69
|
+
payerKey: this.provider.wallet.publicKey,
|
|
70
|
+
recentBlockhash: blockhash,
|
|
71
|
+
instructions
|
|
72
|
+
}).compileToV0Message();
|
|
73
|
+
return this.provider.sendAndConfirm(new web3_js_1.VersionedTransaction(message));
|
|
74
|
+
});
|
|
75
|
+
}
|
|
50
76
|
}
|
|
51
77
|
exports.default = Ticker;
|