@triadxyz/triad-protocol 1.3.1-beta → 1.3.3-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 +34 -30
- package/dist/index.js +75 -29
- package/dist/local-test.js +209 -14
- package/dist/stake.d.ts +4 -23
- package/dist/stake.js +1 -24
- package/dist/trade.d.ts +17 -1
- package/dist/trade.js +35 -0
- package/dist/types/idl_triad_protocol.json +573 -376
- package/dist/types/index.d.ts +40 -0
- package/dist/types/triad_protocol.d.ts +754 -557
- package/dist/utils/constants.d.ts +2 -0
- package/dist/utils/constants.js +3 -1
- package/dist/utils/pda/index.d.ts +1 -0
- package/dist/utils/pda/index.js +5 -1
- package/dist/utils/sendTransactionWithOptions.d.ts +3 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import { Connection, PublicKey } from '@solana/web3.js';
|
|
1
|
+
import { AnchorProvider, Program, Wallet } from '@coral-xyz/anchor';
|
|
2
|
+
import { Connection, Keypair, PublicKey } from '@solana/web3.js';
|
|
4
3
|
import { TriadProtocol } from './types/triad_protocol';
|
|
5
4
|
import Trade from './trade';
|
|
6
5
|
import Stake from './stake';
|
|
7
|
-
import { CreateUserArgs, MintTicketArgs, RpcOptions } from './types';
|
|
6
|
+
import { CreateUserArgs, MintTicketArgs, PrizeType, RpcOptions } from './types';
|
|
8
7
|
export default class TriadProtocolClient {
|
|
9
8
|
program: Program<TriadProtocol>;
|
|
10
9
|
provider: AnchorProvider;
|
|
@@ -44,39 +43,44 @@ export default class TriadProtocolClient {
|
|
|
44
43
|
* @param options - RPC options
|
|
45
44
|
*
|
|
46
45
|
*/
|
|
47
|
-
createUser({ wallet, name, referral }: CreateUserArgs, options?: RpcOptions): Promise<
|
|
46
|
+
createUser({ wallet, name, referral }: CreateUserArgs, options?: RpcOptions): Promise<string>;
|
|
48
47
|
/**
|
|
49
|
-
*
|
|
50
|
-
* @param
|
|
48
|
+
* Create Collection
|
|
49
|
+
* @param args - Collection args
|
|
50
|
+
* @param options - RPC options
|
|
51
51
|
*
|
|
52
52
|
*/
|
|
53
|
-
getUserPositionsWithAmount(wallet: PublicKey): Promise<{
|
|
54
|
-
ts: BN;
|
|
55
|
-
bump: number;
|
|
56
|
-
totalDeposited: BN;
|
|
57
|
-
totalWithdrawn: BN;
|
|
58
|
-
lpShare: BN;
|
|
59
|
-
totalPositions: number;
|
|
60
|
-
ticker: PublicKey;
|
|
61
|
-
authority: PublicKey;
|
|
62
|
-
positions: {
|
|
63
|
-
amount: BN;
|
|
64
|
-
entryPrice: BN;
|
|
65
|
-
ts: BN;
|
|
66
|
-
isLong: boolean;
|
|
67
|
-
isOpen: boolean;
|
|
68
|
-
pnl: BN;
|
|
69
|
-
}[];
|
|
70
|
-
}[]>;
|
|
71
|
-
withdrawV1({ wallet, ticker, positionIndex }: {
|
|
72
|
-
wallet: PublicKey;
|
|
73
|
-
ticker: PublicKey;
|
|
74
|
-
positionIndex: number;
|
|
75
|
-
}, options?: RpcOptions): Promise<any>;
|
|
76
53
|
createCollection(args: {
|
|
77
54
|
collectionName: string;
|
|
78
55
|
collectionSymbol: string;
|
|
79
56
|
supply: number;
|
|
80
57
|
}, options?: RpcOptions): Promise<string>;
|
|
81
58
|
mintTicket({ discount, isBoosted, rarity, verifier, nftMint }: MintTicketArgs, options?: RpcOptions): Promise<string>;
|
|
59
|
+
/**
|
|
60
|
+
* Add Spin Prize
|
|
61
|
+
* @param args - Spin prize args
|
|
62
|
+
* @param options - RPC options
|
|
63
|
+
*
|
|
64
|
+
*/
|
|
65
|
+
addSpinPrize(args: {
|
|
66
|
+
rangeMin: number;
|
|
67
|
+
rangeMax: number;
|
|
68
|
+
prizeType: PrizeType;
|
|
69
|
+
availableQuantity: number;
|
|
70
|
+
}, options?: RpcOptions): Promise<string>;
|
|
71
|
+
/**
|
|
72
|
+
* Claim Spin Token
|
|
73
|
+
* @param amount - Amount of tokens to claim
|
|
74
|
+
* @param verifier - Verifier keypair
|
|
75
|
+
* @param options - RPC options
|
|
76
|
+
*
|
|
77
|
+
*/
|
|
78
|
+
claimSpinToken(amount: number, verifier: Keypair, options?: RpcOptions): Promise<string>;
|
|
79
|
+
/**
|
|
80
|
+
* Spin Wheel
|
|
81
|
+
* @param isSol - Whether to pay with SOL or token
|
|
82
|
+
* @param verifier - Verifier keypair
|
|
83
|
+
* @param options - RPC options
|
|
84
|
+
*/
|
|
85
|
+
spinWheel(isSol: boolean, options?: RpcOptions): Promise<any>;
|
|
82
86
|
}
|
package/dist/index.js
CHANGED
|
@@ -17,7 +17,6 @@ const web3_js_1 = require("@solana/web3.js");
|
|
|
17
17
|
const idl_triad_protocol_json_1 = __importDefault(require("./types/idl_triad_protocol.json"));
|
|
18
18
|
const trade_1 = __importDefault(require("./trade"));
|
|
19
19
|
const helpers_1 = require("./utils/helpers");
|
|
20
|
-
const spl_token_1 = require("@solana/spl-token");
|
|
21
20
|
const pda_1 = require("./utils/pda");
|
|
22
21
|
const stake_1 = __importDefault(require("./stake"));
|
|
23
22
|
const sendTransactionWithOptions_1 = __importDefault(require("./utils/sendTransactionWithOptions"));
|
|
@@ -123,36 +122,11 @@ class TriadProtocolClient {
|
|
|
123
122
|
});
|
|
124
123
|
}
|
|
125
124
|
/**
|
|
126
|
-
*
|
|
127
|
-
* @param
|
|
125
|
+
* Create Collection
|
|
126
|
+
* @param args - Collection args
|
|
127
|
+
* @param options - RPC options
|
|
128
128
|
*
|
|
129
129
|
*/
|
|
130
|
-
getUserPositionsWithAmount(wallet) {
|
|
131
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
132
|
-
const userPositions = [];
|
|
133
|
-
const userPositionPDA = (0, pda_1.getUserPositionPDA)(this.program.programId, wallet, new web3_js_1.PublicKey('EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v'));
|
|
134
|
-
userPositions.push(userPositionPDA);
|
|
135
|
-
const userPositionsWithAmount = yield this.program.account.userPosition.fetchMultiple(userPositions);
|
|
136
|
-
return userPositionsWithAmount.filter((item) => item &&
|
|
137
|
-
parseFloat(item.totalDeposited.toString()) >
|
|
138
|
-
parseFloat(item.totalWithdrawn.toString()));
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
withdrawV1({ wallet, ticker, positionIndex }, options) {
|
|
142
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
143
|
-
const vaultPDA = (0, pda_1.getVaultAddressSync)(this.program.programId, ticker);
|
|
144
|
-
const userPositionPDA = (0, pda_1.getUserPositionPDA)(this.program.programId, wallet, ticker);
|
|
145
|
-
const VaultTokenAccountPDA = (0, pda_1.getTokenVaultAddressSync)(this.program.programId, vaultPDA);
|
|
146
|
-
const userTokenAccount = yield (0, spl_token_1.getAssociatedTokenAddress)(new web3_js_1.PublicKey('EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v'), this.provider.wallet.publicKey);
|
|
147
|
-
return (0, sendTransactionWithOptions_1.default)(this.program.methods.withdrawV1(positionIndex).accounts({
|
|
148
|
-
signer: wallet,
|
|
149
|
-
userPosition: userPositionPDA,
|
|
150
|
-
userTokenAccount,
|
|
151
|
-
vault: vaultPDA,
|
|
152
|
-
vaultTokenAccount: VaultTokenAccountPDA
|
|
153
|
-
}), options);
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
130
|
createCollection(args, options) {
|
|
157
131
|
return __awaiter(this, void 0, void 0, function* () {
|
|
158
132
|
const keyPair = web3_js_1.Keypair.generate();
|
|
@@ -203,5 +177,77 @@ class TriadProtocolClient {
|
|
|
203
177
|
return (0, sendVersionedTransaction_1.default)(this.provider, ixs, options, asset, [], (0, convertSecretKeyToKeypair_1.convertSecretKeyToKeypair)(verifier));
|
|
204
178
|
});
|
|
205
179
|
}
|
|
180
|
+
/**
|
|
181
|
+
* Add Spin Prize
|
|
182
|
+
* @param args - Spin prize args
|
|
183
|
+
* @param options - RPC options
|
|
184
|
+
*
|
|
185
|
+
*/
|
|
186
|
+
addSpinPrize(args, options) {
|
|
187
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
188
|
+
const method = this.program.methods
|
|
189
|
+
.addSpinPrize({
|
|
190
|
+
name: 'christmas',
|
|
191
|
+
rangeMin: new anchor_1.BN(args.rangeMin),
|
|
192
|
+
rangeMax: new anchor_1.BN(args.rangeMax),
|
|
193
|
+
prizeType: args.prizeType,
|
|
194
|
+
availableQuantity: new anchor_1.BN(args.availableQuantity)
|
|
195
|
+
})
|
|
196
|
+
.accounts({
|
|
197
|
+
signer: this.provider.wallet.publicKey
|
|
198
|
+
});
|
|
199
|
+
return (0, sendTransactionWithOptions_1.default)(method, options);
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Claim Spin Token
|
|
204
|
+
* @param amount - Amount of tokens to claim
|
|
205
|
+
* @param verifier - Verifier keypair
|
|
206
|
+
* @param options - RPC options
|
|
207
|
+
*
|
|
208
|
+
*/
|
|
209
|
+
claimSpinToken(amount, verifier, options) {
|
|
210
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
211
|
+
const spinPDA = (0, pda_1.getSpinPDA)(this.program.programId, constants_1.SPIN_NAME);
|
|
212
|
+
const ix = yield this.program.methods
|
|
213
|
+
.claimSpinToken(new anchor_1.BN(amount))
|
|
214
|
+
.accounts({
|
|
215
|
+
signer: this.provider.wallet.publicKey,
|
|
216
|
+
verifier: verifier.publicKey,
|
|
217
|
+
spin: spinPDA,
|
|
218
|
+
mint: constants_1.TCMAS_MINT
|
|
219
|
+
})
|
|
220
|
+
.instruction();
|
|
221
|
+
return (0, sendVersionedTransaction_1.default)(this.provider, [ix], options, undefined, [], verifier);
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Spin Wheel
|
|
226
|
+
* @param isSol - Whether to pay with SOL or token
|
|
227
|
+
* @param verifier - Verifier keypair
|
|
228
|
+
* @param options - RPC options
|
|
229
|
+
*/
|
|
230
|
+
spinWheel(isSol, options) {
|
|
231
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
232
|
+
const spinPDA = (0, pda_1.getSpinPDA)(this.program.programId, constants_1.SPIN_NAME);
|
|
233
|
+
const method = this.program.methods.spinWheel(isSol).accounts({
|
|
234
|
+
signer: this.provider.wallet.publicKey,
|
|
235
|
+
spin: spinPDA,
|
|
236
|
+
mint: new web3_js_1.PublicKey('9LGNCsQsoeJK2jBMKNiX8UGJv5NPyBHhouTcQLLqWTt9')
|
|
237
|
+
});
|
|
238
|
+
const tx = yield (0, sendTransactionWithOptions_1.default)(method, options);
|
|
239
|
+
const txLogs = yield this.provider.connection.getTransaction(tx, {
|
|
240
|
+
commitment: 'confirmed',
|
|
241
|
+
maxSupportedTransactionVersion: 0
|
|
242
|
+
});
|
|
243
|
+
const eventLog = txLogs.meta.logMessages.find((log) => log.includes('RouletteSpinResult'));
|
|
244
|
+
if (!eventLog) {
|
|
245
|
+
throw new Error('Spin result not found in transaction logs');
|
|
246
|
+
}
|
|
247
|
+
const prizeType = JSON.parse(eventLog.split('RouletteSpinResult')[1]).data
|
|
248
|
+
.prize;
|
|
249
|
+
return prizeType;
|
|
250
|
+
});
|
|
251
|
+
}
|
|
206
252
|
}
|
|
207
253
|
exports.default = TriadProtocolClient;
|
package/dist/local-test.js
CHANGED
|
@@ -16,20 +16,21 @@ const fs_1 = __importDefault(require("fs"));
|
|
|
16
16
|
const _1 = __importDefault(require("./"));
|
|
17
17
|
const anchor_1 = require("@coral-xyz/anchor");
|
|
18
18
|
const web3_js_1 = require("@solana/web3.js");
|
|
19
|
+
const trade_1 = require("./types/trade");
|
|
19
20
|
const spl_token_1 = require("@solana/spl-token");
|
|
20
21
|
const constants_1 = require("./utils/constants");
|
|
21
|
-
const file = fs_1.default.readFileSync('/Users/dannpl/.config/solana/
|
|
22
|
+
const file = fs_1.default.readFileSync('/Users/dannpl/.config/solana/id.json');
|
|
22
23
|
const rpc_file = fs_1.default.readFileSync('/Users/dannpl/.config/solana/rpc.txt');
|
|
23
24
|
const keypair = web3_js_1.Keypair.fromSecretKey(new Uint8Array(JSON.parse(file.toString())));
|
|
24
|
-
const connection = new web3_js_1.Connection(
|
|
25
|
+
const connection = new web3_js_1.Connection('https://mainnet.helius-rpc.com/?api-key=05843ded-2085-4567-aff3-85af84ea71d2');
|
|
25
26
|
const wallet = new anchor_1.Wallet(keypair);
|
|
26
27
|
const triadProtocol = new _1.default(connection, wallet);
|
|
27
28
|
const markets = [
|
|
28
29
|
{
|
|
29
|
-
marketId:
|
|
30
|
-
question: 'Will $
|
|
31
|
-
startTime:
|
|
32
|
-
endTime:
|
|
30
|
+
marketId: 38,
|
|
31
|
+
question: 'Will $PENGU be above 0.10$ on December 18?',
|
|
32
|
+
startTime: 1734379200,
|
|
33
|
+
endTime: 1734440400
|
|
33
34
|
}
|
|
34
35
|
];
|
|
35
36
|
const ordersHypeAndFloopBot = [
|
|
@@ -44,7 +45,7 @@ const ordersHypeAndFloopBot = [
|
|
|
44
45
|
const updateStakeVault = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
45
46
|
const response = yield triadProtocol.stake.updateStakeVault({
|
|
46
47
|
wallet: wallet.publicKey,
|
|
47
|
-
amount: new anchor_1.BN(
|
|
48
|
+
amount: new anchor_1.BN(1000 * Math.pow(10, 6)),
|
|
48
49
|
isLocked: false
|
|
49
50
|
});
|
|
50
51
|
console.log(response);
|
|
@@ -53,9 +54,55 @@ const getStakeVault = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
53
54
|
const response = yield triadProtocol.stake.getStakeVaults();
|
|
54
55
|
console.log(response);
|
|
55
56
|
});
|
|
56
|
-
const
|
|
57
|
-
const
|
|
58
|
-
|
|
57
|
+
const getStakes = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
58
|
+
const stakes = yield triadProtocol.stake.getStakes();
|
|
59
|
+
fs_1.default.writeFileSync('stakes.json', JSON.stringify(stakes, null, 2));
|
|
60
|
+
const stakesJson = JSON.parse(fs_1.default.readFileSync('stakes.json', 'utf8'));
|
|
61
|
+
let amountLocked = 0;
|
|
62
|
+
let amountUnlocked = 0;
|
|
63
|
+
let uniqueStakersLocked = new Set();
|
|
64
|
+
let uniqueStakersUnlocked = new Set();
|
|
65
|
+
let usersUnlocked = [];
|
|
66
|
+
let usersLocked = [];
|
|
67
|
+
for (const stake of stakesJson) {
|
|
68
|
+
if (stake.withdrawTs === 0) {
|
|
69
|
+
amountLocked += stake.amount / Math.pow(10, 6);
|
|
70
|
+
uniqueStakersLocked.add(stake.authority);
|
|
71
|
+
if (!usersLocked.find((user) => user.address === stake.authority)) {
|
|
72
|
+
usersLocked.push({
|
|
73
|
+
address: stake.authority,
|
|
74
|
+
amount: stake.amount / Math.pow(10, 6)
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
usersLocked.find((user) => user.address === stake.authority).amount +=
|
|
79
|
+
stake.amount / Math.pow(10, 6);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
amountUnlocked += stake.amount / Math.pow(10, 6);
|
|
84
|
+
uniqueStakersUnlocked.add(stake.authority);
|
|
85
|
+
if (!usersUnlocked.find((user) => user.address === stake.authority)) {
|
|
86
|
+
usersUnlocked.push({
|
|
87
|
+
address: stake.authority,
|
|
88
|
+
amount: stake.amount / Math.pow(10, 6)
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
usersUnlocked.find((user) => user.address === stake.authority).amount +=
|
|
93
|
+
stake.amount / Math.pow(10, 6);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
const orders = usersLocked.sort((a, b) => b.amount - a.amount);
|
|
98
|
+
const ordersUnlocked = usersUnlocked.sort((a, b) => b.amount - a.amount);
|
|
99
|
+
console.log('Amount locked:', amountLocked);
|
|
100
|
+
console.log('Amount unlocked:', amountUnlocked);
|
|
101
|
+
console.log('Unique stakers:', uniqueStakersLocked.size);
|
|
102
|
+
console.log('Unique stakers unlocked:', uniqueStakersUnlocked.size);
|
|
103
|
+
console.log(JSON.stringify(orders, null, 2));
|
|
104
|
+
console.log('--------------------------------');
|
|
105
|
+
console.log(JSON.stringify(ordersUnlocked, null, 2));
|
|
59
106
|
});
|
|
60
107
|
const getAllMarkets = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
61
108
|
const markets = yield triadProtocol.trade.getAllMarkets();
|
|
@@ -105,6 +152,10 @@ const getLiquidityToRecovery = () => __awaiter(void 0, void 0, void 0, function*
|
|
|
105
152
|
const liquidityToRecovery = {};
|
|
106
153
|
for (const market of allMarkets) {
|
|
107
154
|
let currentMarket = liquidityToRecovery[market.marketId];
|
|
155
|
+
if (market.marketId === '31') {
|
|
156
|
+
console.log(market);
|
|
157
|
+
market.winningDirection = trade_1.WinningDirection.HYPE;
|
|
158
|
+
}
|
|
108
159
|
if (market.winningDirection.toLowerCase() === 'none') {
|
|
109
160
|
continue;
|
|
110
161
|
}
|
|
@@ -134,7 +185,7 @@ const getLiquidityToRecovery = () => __awaiter(void 0, void 0, void 0, function*
|
|
|
134
185
|
let liquidity_coeficient = 1;
|
|
135
186
|
if ('flop' in currentMarket.direction) {
|
|
136
187
|
let shares = parseFloat(market.flopShares.toString()) / Math.pow(10, 6);
|
|
137
|
-
currentMarket.sharesToPay = shares
|
|
188
|
+
currentMarket.sharesToPay = shares;
|
|
138
189
|
currentMarket.liquidityToPay =
|
|
139
190
|
parseFloat(market.hypeLiquidity.toString()) / Math.pow(10, 6);
|
|
140
191
|
currentMarket.liquidityToPay =
|
|
@@ -142,7 +193,7 @@ const getLiquidityToRecovery = () => __awaiter(void 0, void 0, void 0, function*
|
|
|
142
193
|
}
|
|
143
194
|
else {
|
|
144
195
|
let shares = parseFloat(market.hypeShares.toString()) / Math.pow(10, 6);
|
|
145
|
-
currentMarket.sharesToPay = shares
|
|
196
|
+
currentMarket.sharesToPay = shares;
|
|
146
197
|
currentMarket.liquidityToPay =
|
|
147
198
|
parseFloat(market.flopLiquidity.toString()) / Math.pow(10, 6);
|
|
148
199
|
currentMarket.liquidityToPay =
|
|
@@ -205,7 +256,7 @@ const closeOrders = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
205
256
|
}
|
|
206
257
|
});
|
|
207
258
|
const resolveMarket = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
208
|
-
const marketsToResolve = [{ marketId:
|
|
259
|
+
const marketsToResolve = [{ marketId: 38, winningDirection: { flop: {} } }];
|
|
209
260
|
for (const market of marketsToResolve) {
|
|
210
261
|
const response = yield triadProtocol.trade.resolveMarket({
|
|
211
262
|
marketId: market.marketId,
|
|
@@ -216,7 +267,6 @@ const resolveMarket = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
216
267
|
console.log(response);
|
|
217
268
|
}
|
|
218
269
|
});
|
|
219
|
-
resolveMarket();
|
|
220
270
|
const addLiquidity = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
221
271
|
const response = yield triadProtocol.trade.addLiquidity({
|
|
222
272
|
marketId: 5,
|
|
@@ -258,3 +308,148 @@ const getReferral = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
258
308
|
const response = yield triadProtocol.getUser(new web3_js_1.PublicKey('in6cFcFF2eawkdtrGvV4mM33dRhBymJcf1Fk8mrqGJt'));
|
|
259
309
|
console.log(response);
|
|
260
310
|
});
|
|
311
|
+
const resolveWithLiquidity = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
312
|
+
const response = yield triadProtocol.trade.resolveMarketWithLiquidity({
|
|
313
|
+
marketId: 37,
|
|
314
|
+
winningDirection: { flop: {} },
|
|
315
|
+
marketToAddLiquidity: { hype: {} },
|
|
316
|
+
amount: 1000
|
|
317
|
+
});
|
|
318
|
+
console.log(response);
|
|
319
|
+
});
|
|
320
|
+
const mintToken = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
321
|
+
const filekey = fs_1.default.readFileSync('./tCMraBSGHeMcQS76hNnBhnfbMzrtnnT3nbt3vAnSCE2.json');
|
|
322
|
+
const token = web3_js_1.Keypair.fromSecretKey(new Uint8Array(JSON.parse(filekey.toString())));
|
|
323
|
+
try {
|
|
324
|
+
const decimals = 6; // Common decimal places for tokens
|
|
325
|
+
const amount = 1000000 * Math.pow(10, decimals); // 1,000,000 tokens with decimals
|
|
326
|
+
// Calculate space needed for mint account including metadata pointer
|
|
327
|
+
// const mintLen = getMintLen([ExtensionType.MetadataPointer])
|
|
328
|
+
// const mintTransaction = new Transaction().add(
|
|
329
|
+
// // Create mint account
|
|
330
|
+
// SystemProgram.createAccount({
|
|
331
|
+
// fromPubkey: wallet.publicKey,
|
|
332
|
+
// newAccountPubkey: token.publicKey,
|
|
333
|
+
// space: mintLen,
|
|
334
|
+
// lamports: 6786240,
|
|
335
|
+
// programId: TOKEN_2022_PROGRAM_ID
|
|
336
|
+
// }),
|
|
337
|
+
// createInitializeMetadataPointerInstruction(
|
|
338
|
+
// token.publicKey,
|
|
339
|
+
// wallet.publicKey,
|
|
340
|
+
// token.publicKey,
|
|
341
|
+
// TOKEN_2022_PROGRAM_ID
|
|
342
|
+
// ),
|
|
343
|
+
// createInitializeMintInstruction(
|
|
344
|
+
// token.publicKey,
|
|
345
|
+
// decimals,
|
|
346
|
+
// wallet.publicKey,
|
|
347
|
+
// null,
|
|
348
|
+
// TOKEN_2022_PROGRAM_ID
|
|
349
|
+
// ),
|
|
350
|
+
// createInitializeInstruction({
|
|
351
|
+
// programId: TOKEN_2022_PROGRAM_ID,
|
|
352
|
+
// metadata: token.publicKey,
|
|
353
|
+
// updateAuthority: wallet.publicKey,
|
|
354
|
+
// mint: token.publicKey,
|
|
355
|
+
// mintAuthority: wallet.publicKey,
|
|
356
|
+
// name: 'Triad Christmas',
|
|
357
|
+
// symbol: 'tCMAS',
|
|
358
|
+
// uri: 'https://shdw-drive.genesysgo.net/DRRe9dZkP199W6GLrySn2xj2ayfr8gin8iaBt1YVMN9M/tCMAS.json'
|
|
359
|
+
// })
|
|
360
|
+
// )
|
|
361
|
+
// const transactionSignature = await sendAndConfirmTransaction(
|
|
362
|
+
// connection,
|
|
363
|
+
// mintTransaction,
|
|
364
|
+
// [keypair, token], // Signers,
|
|
365
|
+
// { skipPreflight: false }
|
|
366
|
+
// )
|
|
367
|
+
// console.log(
|
|
368
|
+
// '\nCreate Mint Account:',
|
|
369
|
+
// `https://solana.fm/tx/${transactionSignature}?cluster=devnet-solana`
|
|
370
|
+
// )
|
|
371
|
+
// const associatedTokenAccount = await getOrCreateAssociatedTokenAccount(
|
|
372
|
+
// connection,
|
|
373
|
+
// keypair,
|
|
374
|
+
// token.publicKey,
|
|
375
|
+
// wallet.publicKey,
|
|
376
|
+
// true,
|
|
377
|
+
// undefined,
|
|
378
|
+
// undefined,
|
|
379
|
+
// TOKEN_2022_PROGRAM_ID
|
|
380
|
+
// )
|
|
381
|
+
// const mintToResponse = await mintTo(
|
|
382
|
+
// connection,
|
|
383
|
+
// keypair,
|
|
384
|
+
// token.publicKey,
|
|
385
|
+
// associatedTokenAccount.address,
|
|
386
|
+
// wallet.publicKey,
|
|
387
|
+
// amount,
|
|
388
|
+
// [keypair, token],
|
|
389
|
+
// undefined,
|
|
390
|
+
// TOKEN_2022_PROGRAM_ID
|
|
391
|
+
// )
|
|
392
|
+
// console.log('Token created:', token.publicKey.toString())
|
|
393
|
+
// console.log('Associated Token Account:', associatedTokenAccount.toString())
|
|
394
|
+
// console.log('Mint tx:', mintToResponse)
|
|
395
|
+
}
|
|
396
|
+
catch (e) {
|
|
397
|
+
console.log(e);
|
|
398
|
+
}
|
|
399
|
+
});
|
|
400
|
+
const removeMintAuthority = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
401
|
+
const filekey = fs_1.default.readFileSync('./tCMraBSGHeMcQS76hNnBhnfbMzrtnnT3nbt3vAnSCE2.json');
|
|
402
|
+
const token = web3_js_1.Keypair.fromSecretKey(new Uint8Array(JSON.parse(filekey.toString())));
|
|
403
|
+
try {
|
|
404
|
+
const response = yield (0, spl_token_1.setAuthority)(connection, keypair, token.publicKey, wallet.publicKey, spl_token_1.AuthorityType.MetadataPointer, null, [], undefined, spl_token_1.TOKEN_2022_PROGRAM_ID);
|
|
405
|
+
console.log('Mint authority removed:', response);
|
|
406
|
+
}
|
|
407
|
+
catch (error) {
|
|
408
|
+
console.error('Error removing mint authority:', error);
|
|
409
|
+
}
|
|
410
|
+
});
|
|
411
|
+
const getMinteds = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
412
|
+
const response = yield triadProtocol.program.account.collection.all();
|
|
413
|
+
console.log(response);
|
|
414
|
+
});
|
|
415
|
+
// let prize_ranges = [
|
|
416
|
+
// (1, 14, PrizeType::Undead), // 0.0014%
|
|
417
|
+
// (15, 114, PrizeType::Ticket), // 0.01%
|
|
418
|
+
// (115, 614, PrizeType::Honeyland), // 0.05%
|
|
419
|
+
// (615, 1614, PrizeType::Trd100), // 0.1%
|
|
420
|
+
// (1615, 6614, PrizeType::Trd50), // 0.5%
|
|
421
|
+
// (6615, 16614, PrizeType::Flip), // 1%
|
|
422
|
+
// (16615, 26614, PrizeType::Pengu), // 1%
|
|
423
|
+
// (26615, 66614, PrizeType::Ore), // 4%
|
|
424
|
+
// (66615, 166614, PrizeType::Lucksea), // 10%
|
|
425
|
+
// (166615, 286614, PrizeType::Trd5), // 12%
|
|
426
|
+
// (286615, 499999, PrizeType::Trident2000), // 21.3385%
|
|
427
|
+
// (500000, 1000000, PrizeType::Trident500), // 50%
|
|
428
|
+
// ];
|
|
429
|
+
const addSpinPrize = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
430
|
+
const response = yield triadProtocol.addSpinPrize({
|
|
431
|
+
rangeMin: 66615,
|
|
432
|
+
rangeMax: 166614,
|
|
433
|
+
prizeType: { lucksea: {} },
|
|
434
|
+
availableQuantity: 2000
|
|
435
|
+
});
|
|
436
|
+
console.log(response);
|
|
437
|
+
});
|
|
438
|
+
const getSpinPrize = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
439
|
+
let response = yield triadProtocol.program.account.spin.fetch(new web3_js_1.PublicKey('EQ6ZJbdT2V8ZYcHRpJx6wBkGWmM1e3mimtPKshTVuw8h'));
|
|
440
|
+
const prizes = response.prizes.map((prize) => ({
|
|
441
|
+
rangeMin: prize.rangeMin.toNumber(),
|
|
442
|
+
rangeMax: prize.rangeMax.toNumber(),
|
|
443
|
+
prizeType: prize.prizeType,
|
|
444
|
+
availableQuantity: prize.availableQuantity.toNumber()
|
|
445
|
+
}));
|
|
446
|
+
console.log(prizes);
|
|
447
|
+
});
|
|
448
|
+
const spinWheel = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
449
|
+
const response = yield triadProtocol.spinWheel(false, {
|
|
450
|
+
skipPreflight: true,
|
|
451
|
+
microLamports: 5000
|
|
452
|
+
});
|
|
453
|
+
console.log(response);
|
|
454
|
+
});
|
|
455
|
+
spinWheel();
|
package/dist/stake.d.ts
CHANGED
|
@@ -30,11 +30,7 @@ export default class Stake {
|
|
|
30
30
|
* @param collections - NFT collections
|
|
31
31
|
* @param tensor rank
|
|
32
32
|
*/
|
|
33
|
-
getStakeByWallet(wallet: PublicKey, collections: number
|
|
34
|
-
onchainId: string;
|
|
35
|
-
name: string;
|
|
36
|
-
rarityRankHrtt: number;
|
|
37
|
-
}[]): Promise<StakeResponse[]>;
|
|
33
|
+
getStakeByWallet(wallet: PublicKey, collections: number): Promise<StakeResponse[]>;
|
|
38
34
|
/**
|
|
39
35
|
* Stake Token
|
|
40
36
|
* @param name - Index
|
|
@@ -42,7 +38,7 @@ export default class Stake {
|
|
|
42
38
|
* @param amount - Amount to stake
|
|
43
39
|
*
|
|
44
40
|
*/
|
|
45
|
-
stakeToken({ name, wallet, amount }: StakeTokenArgs, options?: RpcOptions): Promise<
|
|
41
|
+
stakeToken({ name, wallet, amount }: StakeTokenArgs, options?: RpcOptions): Promise<string>;
|
|
46
42
|
/**
|
|
47
43
|
* Update Stake Vault
|
|
48
44
|
* @param wallet - User wallet
|
|
@@ -50,7 +46,7 @@ export default class Stake {
|
|
|
50
46
|
* @param isLocked - is locked stake vault (optional)
|
|
51
47
|
*
|
|
52
48
|
*/
|
|
53
|
-
updateStakeVault({ wallet, amount, isLocked }: UpdateStakeVaultArgs, options?: RpcOptions): Promise<
|
|
49
|
+
updateStakeVault({ wallet, amount, isLocked }: UpdateStakeVaultArgs, options?: RpcOptions): Promise<string>;
|
|
54
50
|
/**
|
|
55
51
|
* Request Withdraw
|
|
56
52
|
* @param wallet - User wallet
|
|
@@ -65,7 +61,7 @@ export default class Stake {
|
|
|
65
61
|
* @param mint - NFT mint
|
|
66
62
|
*
|
|
67
63
|
*/
|
|
68
|
-
withdrawStake({ wallet, name, mint }: WithdrawArgs, options?: RpcOptions): Promise<
|
|
64
|
+
withdrawStake({ wallet, name, mint }: WithdrawArgs, options?: RpcOptions): Promise<string>;
|
|
69
65
|
/**
|
|
70
66
|
* Claim All Stake Rewards
|
|
71
67
|
* @param wallet - User wallet
|
|
@@ -84,19 +80,4 @@ export default class Stake {
|
|
|
84
80
|
verifier: string;
|
|
85
81
|
isToken?: boolean;
|
|
86
82
|
}, options?: RpcOptions): Promise<string>;
|
|
87
|
-
/**
|
|
88
|
-
* Withdraw NFT
|
|
89
|
-
* @param wallet - User wallet
|
|
90
|
-
* @param name - Stake name
|
|
91
|
-
* @param mint - NFT mint
|
|
92
|
-
*
|
|
93
|
-
*/
|
|
94
|
-
withdrawNft({ wallet, name, nftMint, tokenMint, rank, collections }: {
|
|
95
|
-
wallet: PublicKey;
|
|
96
|
-
name: string;
|
|
97
|
-
nftMint: PublicKey;
|
|
98
|
-
tokenMint: PublicKey;
|
|
99
|
-
rank: number;
|
|
100
|
-
collections: number;
|
|
101
|
-
}, options?: RpcOptions): Promise<any>;
|
|
102
83
|
}
|
package/dist/stake.js
CHANGED
|
@@ -92,12 +92,11 @@ class Stake {
|
|
|
92
92
|
* @param collections - NFT collections
|
|
93
93
|
* @param tensor rank
|
|
94
94
|
*/
|
|
95
|
-
getStakeByWallet(wallet, collections
|
|
95
|
+
getStakeByWallet(wallet, collections) {
|
|
96
96
|
return __awaiter(this, void 0, void 0, function* () {
|
|
97
97
|
const response = yield this.getUserStakes(wallet);
|
|
98
98
|
const data = [];
|
|
99
99
|
for (const stake of response) {
|
|
100
|
-
yield new Promise((resolve) => setTimeout(resolve, 5000));
|
|
101
100
|
let available = 0;
|
|
102
101
|
try {
|
|
103
102
|
available = yield this.getStakeRewards({
|
|
@@ -254,27 +253,5 @@ class Stake {
|
|
|
254
253
|
return (0, sendVersionedTransaction_1.default)(this.provider, ixs, options, (0, convertSecretKeyToKeypair_1.convertSecretKeyToKeypair)(verifier));
|
|
255
254
|
});
|
|
256
255
|
}
|
|
257
|
-
/**
|
|
258
|
-
* Withdraw NFT
|
|
259
|
-
* @param wallet - User wallet
|
|
260
|
-
* @param name - Stake name
|
|
261
|
-
* @param mint - NFT mint
|
|
262
|
-
*
|
|
263
|
-
*/
|
|
264
|
-
withdrawNft({ wallet, name, nftMint, tokenMint, rank, collections }, options) {
|
|
265
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
266
|
-
const stakeVaultPDA = (0, stake_1.getStakeVaultPDA)(this.program.programId, this.stakeVaultName);
|
|
267
|
-
const userPDA = (0, pda_1.getUserPDA)(this.program.programId, wallet);
|
|
268
|
-
const stakePDA = (0, stake_1.getStakePDA)(this.program.programId, wallet, name);
|
|
269
|
-
return (0, sendTransactionWithOptions_1.default)(this.program.methods.withdrawNft(rank, collections).accounts({
|
|
270
|
-
signer: this.provider.wallet.publicKey,
|
|
271
|
-
stake: stakePDA,
|
|
272
|
-
stakeVault: stakeVaultPDA,
|
|
273
|
-
tokenMint: tokenMint,
|
|
274
|
-
nftMint: nftMint,
|
|
275
|
-
user: userPDA
|
|
276
|
-
}), options);
|
|
277
|
-
});
|
|
278
|
-
}
|
|
279
256
|
}
|
|
280
257
|
exports.default = Stake;
|
package/dist/trade.d.ts
CHANGED
|
@@ -110,7 +110,7 @@ export default class Trade {
|
|
|
110
110
|
* @param options - RPC options
|
|
111
111
|
*
|
|
112
112
|
*/
|
|
113
|
-
initializeMarket({ marketId, startTime, endTime, question }: InitializeMarketArgs, options?: RpcOptions): Promise<
|
|
113
|
+
initializeMarket({ marketId, startTime, endTime, question }: InitializeMarketArgs, options?: RpcOptions): Promise<string>;
|
|
114
114
|
/**
|
|
115
115
|
* Open Order
|
|
116
116
|
* @param marketId - The ID of the market
|
|
@@ -153,6 +153,22 @@ export default class Trade {
|
|
|
153
153
|
none: {};
|
|
154
154
|
};
|
|
155
155
|
}, options?: RpcOptions): Promise<string>;
|
|
156
|
+
/**
|
|
157
|
+
* Resolve Market With Liquidity
|
|
158
|
+
* @param marketId - The ID of the market
|
|
159
|
+
* @param winningDirection - The winning direction of the market
|
|
160
|
+
* @param marketToAddLiquidity - The market to add liquidity
|
|
161
|
+
* @param amount - The amount of the order
|
|
162
|
+
*
|
|
163
|
+
* @param options - RPC options
|
|
164
|
+
*
|
|
165
|
+
*/
|
|
166
|
+
resolveMarketWithLiquidity({ marketId, winningDirection, marketToAddLiquidity, amount }: {
|
|
167
|
+
marketId: number;
|
|
168
|
+
winningDirection: OrderDirection;
|
|
169
|
+
marketToAddLiquidity: OrderDirection;
|
|
170
|
+
amount: number;
|
|
171
|
+
}, options?: RpcOptions): Promise<string>;
|
|
156
172
|
/**
|
|
157
173
|
* Settle an order
|
|
158
174
|
* @param marketId - The ID of the market
|
package/dist/trade.js
CHANGED
|
@@ -203,6 +203,41 @@ class Trade {
|
|
|
203
203
|
return (0, sendTransactionWithOptions_1.default)(method, options);
|
|
204
204
|
});
|
|
205
205
|
}
|
|
206
|
+
/**
|
|
207
|
+
* Resolve Market With Liquidity
|
|
208
|
+
* @param marketId - The ID of the market
|
|
209
|
+
* @param winningDirection - The winning direction of the market
|
|
210
|
+
* @param marketToAddLiquidity - The market to add liquidity
|
|
211
|
+
* @param amount - The amount of the order
|
|
212
|
+
*
|
|
213
|
+
* @param options - RPC options
|
|
214
|
+
*
|
|
215
|
+
*/
|
|
216
|
+
resolveMarketWithLiquidity({ marketId, winningDirection, marketToAddLiquidity, amount }, options) {
|
|
217
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
218
|
+
const marketPDA = (0, trade_1.getMarketPDA)(this.program.programId, marketId);
|
|
219
|
+
const ixs = [];
|
|
220
|
+
ixs.push(yield this.program.methods
|
|
221
|
+
.resolveMarket(winningDirection)
|
|
222
|
+
.accounts({
|
|
223
|
+
signer: this.provider.publicKey,
|
|
224
|
+
market: marketPDA
|
|
225
|
+
})
|
|
226
|
+
.instruction());
|
|
227
|
+
ixs.push(yield this.program.methods
|
|
228
|
+
.addLiquidity({
|
|
229
|
+
amount: new bn_js_1.default(amount * Math.pow(10, constants_1.TRD_DECIMALS)),
|
|
230
|
+
direction: marketToAddLiquidity
|
|
231
|
+
})
|
|
232
|
+
.accounts({
|
|
233
|
+
signer: this.provider.publicKey,
|
|
234
|
+
market: marketPDA,
|
|
235
|
+
mint: this.mint
|
|
236
|
+
})
|
|
237
|
+
.instruction());
|
|
238
|
+
return (0, sendVersionedTransaction_1.default)(this.provider, ixs, options);
|
|
239
|
+
});
|
|
240
|
+
}
|
|
206
241
|
/**
|
|
207
242
|
* Settle an order
|
|
208
243
|
* @param marketId - The ID of the market
|