@triadxyz/triad-protocol 1.4.8-beta → 1.5.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/LICENSE +183 -183
- package/dist/index.d.ts +21 -296
- package/dist/index.js +51 -215
- package/dist/stake.d.ts +36 -25
- package/dist/stake.js +43 -39
- package/dist/trade.d.ts +41 -41
- package/dist/trade.js +55 -83
- package/dist/types/idl_triad_protocol.json +299 -1174
- package/dist/types/stake.d.ts +0 -1
- package/dist/types/trade.d.ts +1 -2
- package/dist/types/triad_protocol.d.ts +281 -1328
- package/dist/utils/helpers.d.ts +1 -1
- package/dist/utils/helpers.js +5 -5
- package/dist/utils/pda/index.d.ts +1 -0
- package/dist/utils/pda/index.js +5 -1
- package/package.json +1 -1
- package/dist/local-test.d.ts +0 -1
- package/dist/local-test.js +0 -538
- package/dist/utils/jup-swap.d.ts +0 -15
- package/dist/utils/jup-swap.js +0 -66
package/dist/utils/helpers.d.ts
CHANGED
|
@@ -9,4 +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,
|
|
12
|
+
export declare const calculateStakeRewards: (stake: Stake, multiplier: number) => number;
|
package/dist/utils/helpers.js
CHANGED
|
@@ -78,7 +78,7 @@ const formatMarket = (account, address) => {
|
|
|
78
78
|
openedOrders: account.openedOrders.toString(),
|
|
79
79
|
nextOrderId: account.nextOrderId.toString(),
|
|
80
80
|
feeBps: account.feeBps,
|
|
81
|
-
|
|
81
|
+
isAllowedToPayout: account.isAllowedToPayout,
|
|
82
82
|
marketStart: account.marketStart.toString(),
|
|
83
83
|
marketEnd: account.marketEnd.toString(),
|
|
84
84
|
question: Buffer.from(account.question).toString().replace(/\0+$/, ''),
|
|
@@ -111,7 +111,7 @@ const accountToMarketV1 = (account, address) => {
|
|
|
111
111
|
openedOrders: account.openOrdersCount.toString(),
|
|
112
112
|
nextOrderId: account.nextOrderId.toString(),
|
|
113
113
|
feeBps: account.feeBps,
|
|
114
|
-
|
|
114
|
+
isAllowedToPayout: account.isActive,
|
|
115
115
|
marketStart: account.currentQuestionStart.toString(),
|
|
116
116
|
marketEnd: account.currentQuestionEnd.toString(),
|
|
117
117
|
question: Buffer.from(account.currentQuestion)
|
|
@@ -126,12 +126,12 @@ const accountToMarketV1 = (account, address) => {
|
|
|
126
126
|
};
|
|
127
127
|
};
|
|
128
128
|
exports.accountToMarketV1 = accountToMarketV1;
|
|
129
|
-
const calculateStakeRewards = (stake,
|
|
129
|
+
const calculateStakeRewards = (stake, multiplier) => {
|
|
130
130
|
if (stake.withdrawTs !== 0)
|
|
131
131
|
return 0;
|
|
132
|
-
if (
|
|
132
|
+
if (multiplier > 3)
|
|
133
133
|
return 0;
|
|
134
|
-
const collectionsMultiplier =
|
|
134
|
+
const collectionsMultiplier = multiplier * 150;
|
|
135
135
|
const maxRank = 1633;
|
|
136
136
|
const rank = 963;
|
|
137
137
|
const rankWeight = (maxRank - rank + 1) / maxRank;
|
|
@@ -8,3 +8,4 @@ export declare const getTokenATA: (address: PublicKey, Mint: PublicKey) => Publi
|
|
|
8
8
|
export declare const getSpinPDA: (programId: PublicKey, name: string) => PublicKey;
|
|
9
9
|
export declare const getCollectionPDA: (programId: PublicKey, collectionSymbol: string) => PublicKey;
|
|
10
10
|
export declare const getNftPDA: (programId: PublicKey, number: number) => PublicKey;
|
|
11
|
+
export declare const getPoseidonPDA: (programId: PublicKey, number: number) => PublicKey;
|
package/dist/utils/pda/index.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getNftPDA = exports.getCollectionPDA = exports.getSpinPDA = exports.getTokenATA = exports.getTokenVaultAddressSync = exports.getUserPositionPDA = exports.getVaultAddressSync = exports.getTickerPDA = exports.getUserPDA = void 0;
|
|
6
|
+
exports.getPoseidonPDA = exports.getNftPDA = exports.getCollectionPDA = exports.getSpinPDA = exports.getTokenATA = exports.getTokenVaultAddressSync = exports.getUserPositionPDA = exports.getVaultAddressSync = exports.getTickerPDA = exports.getUserPDA = void 0;
|
|
7
7
|
const web3_js_1 = require("@solana/web3.js");
|
|
8
8
|
const bn_js_1 = __importDefault(require("bn.js"));
|
|
9
9
|
const spl_token_1 = require("@solana/spl-token");
|
|
@@ -43,3 +43,7 @@ const getNftPDA = (programId, number) => {
|
|
|
43
43
|
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('nft'), new bn_js_1.default(number).toArrayLike(Buffer, 'le', 8)], programId)[0];
|
|
44
44
|
};
|
|
45
45
|
exports.getNftPDA = getNftPDA;
|
|
46
|
+
const getPoseidonPDA = (programId, number) => {
|
|
47
|
+
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('poseidon'), new bn_js_1.default(number).toArrayLike(Buffer, 'le', 8)], programId)[0];
|
|
48
|
+
};
|
|
49
|
+
exports.getPoseidonPDA = getPoseidonPDA;
|
package/package.json
CHANGED
package/dist/local-test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/local-test.js
DELETED
|
@@ -1,538 +0,0 @@
|
|
|
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 _1 = __importDefault(require("./"));
|
|
17
|
-
const anchor_1 = require("@coral-xyz/anchor");
|
|
18
|
-
const web3_js_1 = require("@solana/web3.js");
|
|
19
|
-
const trade_1 = require("./types/trade");
|
|
20
|
-
const spl_token_1 = require("@solana/spl-token");
|
|
21
|
-
const constants_1 = require("./utils/constants");
|
|
22
|
-
const file = fs_1.default.readFileSync('/Users/dannpl/.config/solana/triad-man.json');
|
|
23
|
-
const rpc_file = fs_1.default.readFileSync('/Users/dannpl/.config/solana/rpc.txt');
|
|
24
|
-
const keypair = web3_js_1.Keypair.fromSecretKey(new Uint8Array(JSON.parse(file.toString())));
|
|
25
|
-
const connection = new web3_js_1.Connection(rpc_file.toString());
|
|
26
|
-
const wallet = new anchor_1.Wallet(keypair);
|
|
27
|
-
const triadProtocol = new _1.default(connection, wallet);
|
|
28
|
-
const markets = [
|
|
29
|
-
{
|
|
30
|
-
marketId: 38,
|
|
31
|
-
question: 'Will $PENGU be above 0.10$ on December 18?',
|
|
32
|
-
startTime: 1734379200,
|
|
33
|
-
endTime: 1734440400
|
|
34
|
-
}
|
|
35
|
-
];
|
|
36
|
-
const ordersHypeAndFloopBot = [
|
|
37
|
-
{
|
|
38
|
-
marketId: 7,
|
|
39
|
-
amount: 5000,
|
|
40
|
-
direction: {
|
|
41
|
-
flop: {}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
];
|
|
45
|
-
const updateStakeVault = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
46
|
-
const response = yield triadProtocol.stake.updateStakeVault({
|
|
47
|
-
wallet: wallet.publicKey,
|
|
48
|
-
amount: new anchor_1.BN(1000 * Math.pow(10, 6)),
|
|
49
|
-
isLocked: false
|
|
50
|
-
});
|
|
51
|
-
console.log(response);
|
|
52
|
-
});
|
|
53
|
-
const getStakeVault = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
54
|
-
const response = yield triadProtocol.stake.getStakeVaults();
|
|
55
|
-
console.log(response);
|
|
56
|
-
});
|
|
57
|
-
const getStakeByWallet = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
58
|
-
const response = yield triadProtocol.stake.getStakeByWallet(new web3_js_1.PublicKey('4k8qFA1i7fv6YGWJnoLZPSHj9nhLn3bokAdXWnuAteBV'), 1);
|
|
59
|
-
let sum = 0;
|
|
60
|
-
for (const stake of response) {
|
|
61
|
-
sum += stake.amount / Math.pow(10, 6);
|
|
62
|
-
}
|
|
63
|
-
console.log(sum);
|
|
64
|
-
});
|
|
65
|
-
const getAllStakes = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
66
|
-
const stakes = yield triadProtocol.stake.getStakes();
|
|
67
|
-
console.log(stakes.length);
|
|
68
|
-
});
|
|
69
|
-
const getStakes = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
70
|
-
const stakes = yield triadProtocol.stake.getStakes();
|
|
71
|
-
fs_1.default.writeFileSync('stakes.json', JSON.stringify(stakes, null, 2));
|
|
72
|
-
const stakesJson = JSON.parse(fs_1.default.readFileSync('stakes.json', 'utf8'));
|
|
73
|
-
let amountLocked = 0;
|
|
74
|
-
let amountUnlocked = 0;
|
|
75
|
-
let uniqueStakersLocked = new Set();
|
|
76
|
-
let uniqueStakersUnlocked = new Set();
|
|
77
|
-
let usersUnlocked = [];
|
|
78
|
-
let usersLocked = [];
|
|
79
|
-
for (const stake of stakesJson) {
|
|
80
|
-
if (stake.withdrawTs === 0) {
|
|
81
|
-
amountLocked += stake.amount / Math.pow(10, 6);
|
|
82
|
-
uniqueStakersLocked.add(stake.authority);
|
|
83
|
-
if (!usersLocked.find((user) => user.address === stake.authority)) {
|
|
84
|
-
usersLocked.push({
|
|
85
|
-
address: stake.authority,
|
|
86
|
-
amount: stake.amount / Math.pow(10, 6)
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
usersLocked.find((user) => user.address === stake.authority).amount +=
|
|
91
|
-
stake.amount / Math.pow(10, 6);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
amountUnlocked += stake.amount / Math.pow(10, 6);
|
|
96
|
-
uniqueStakersUnlocked.add(stake.authority);
|
|
97
|
-
if (!usersUnlocked.find((user) => user.address === stake.authority)) {
|
|
98
|
-
usersUnlocked.push({
|
|
99
|
-
address: stake.authority,
|
|
100
|
-
amount: stake.amount / Math.pow(10, 6)
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
usersUnlocked.find((user) => user.address === stake.authority).amount +=
|
|
105
|
-
stake.amount / Math.pow(10, 6);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
const orders = usersLocked.sort((a, b) => b.amount - a.amount);
|
|
110
|
-
const ordersUnlocked = usersUnlocked.sort((a, b) => b.amount - a.amount);
|
|
111
|
-
console.log('Amount locked:', amountLocked);
|
|
112
|
-
console.log('Amount unlocked:', amountUnlocked);
|
|
113
|
-
console.log('Unique stakers:', uniqueStakersLocked.size);
|
|
114
|
-
console.log('Unique stakers unlocked:', uniqueStakersUnlocked.size);
|
|
115
|
-
console.log(JSON.stringify(orders, null, 2));
|
|
116
|
-
console.log('--------------------------------');
|
|
117
|
-
console.log(JSON.stringify(ordersUnlocked, null, 2));
|
|
118
|
-
});
|
|
119
|
-
const getAllMarkets = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
120
|
-
const markets = yield triadProtocol.trade.getAllMarkets();
|
|
121
|
-
console.log(markets);
|
|
122
|
-
});
|
|
123
|
-
const getMarket = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
124
|
-
const market = yield triadProtocol.trade.getMarketById(9);
|
|
125
|
-
console.log(market);
|
|
126
|
-
});
|
|
127
|
-
const initializeAllMarkets = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
128
|
-
for (const market of markets) {
|
|
129
|
-
try {
|
|
130
|
-
const response = yield triadProtocol.trade.initializeMarket(market, {
|
|
131
|
-
microLamports: 5000
|
|
132
|
-
});
|
|
133
|
-
console.log(`Initialized market ${market.question}:`, response);
|
|
134
|
-
}
|
|
135
|
-
catch (error) {
|
|
136
|
-
console.error(`Error initializing market ${market.question}:`, error);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
});
|
|
140
|
-
const getOrders = (walletAddress) => __awaiter(void 0, void 0, void 0, function* () {
|
|
141
|
-
const response = (yield triadProtocol.program.account.userTrade.all()).find((userTrade) => userTrade.account.authority.toBase58() === walletAddress.toBase58());
|
|
142
|
-
let orders = [];
|
|
143
|
-
for (const order of response.account.orders) {
|
|
144
|
-
if (!order.status.open) {
|
|
145
|
-
continue;
|
|
146
|
-
}
|
|
147
|
-
orders.push({
|
|
148
|
-
marketId: order.marketId.toNumber(),
|
|
149
|
-
orderId: order.orderId.toNumber(),
|
|
150
|
-
totalShares: order.totalShares.toString(),
|
|
151
|
-
amount: order.totalAmount.toString(),
|
|
152
|
-
direction: order.direction,
|
|
153
|
-
questionId: order.questionId,
|
|
154
|
-
price: order.price.toString(),
|
|
155
|
-
status: order.status
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
console.log(orders);
|
|
159
|
-
return orders;
|
|
160
|
-
});
|
|
161
|
-
const getLiquidityToRecovery = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
162
|
-
const response = yield triadProtocol.program.account.userTrade.all();
|
|
163
|
-
const allMarkets = yield triadProtocol.trade.getAllMarkets();
|
|
164
|
-
const liquidityToRecovery = {};
|
|
165
|
-
for (const market of allMarkets) {
|
|
166
|
-
let currentMarket = liquidityToRecovery[market.marketId];
|
|
167
|
-
if (market.marketId === '31') {
|
|
168
|
-
console.log(market);
|
|
169
|
-
market.winningDirection = trade_1.WinningDirection.HYPE;
|
|
170
|
-
}
|
|
171
|
-
if (market.winningDirection.toLowerCase() === 'none') {
|
|
172
|
-
continue;
|
|
173
|
-
}
|
|
174
|
-
if (!currentMarket) {
|
|
175
|
-
currentMarket = {
|
|
176
|
-
address: market.address,
|
|
177
|
-
name: market.question,
|
|
178
|
-
liquidityToPay: 0,
|
|
179
|
-
sharesToPay: 0,
|
|
180
|
-
openOrders: 0,
|
|
181
|
-
amountInPDA: 0,
|
|
182
|
-
amountToPay: 0,
|
|
183
|
-
liquidityCoeficient: 0,
|
|
184
|
-
direction: market.winningDirection.toLowerCase() === 'flop'
|
|
185
|
-
? { flop: {} }
|
|
186
|
-
: { hype: {} },
|
|
187
|
-
totalLiquidity: 0
|
|
188
|
-
};
|
|
189
|
-
liquidityToRecovery[market.marketId] = currentMarket;
|
|
190
|
-
}
|
|
191
|
-
currentMarket.totalLiquidity +=
|
|
192
|
-
parseFloat(market.flopLiquidity.toString()) / Math.pow(10, 6);
|
|
193
|
-
currentMarket.totalLiquidity +=
|
|
194
|
-
parseFloat(market.hypeLiquidity.toString()) / Math.pow(10, 6);
|
|
195
|
-
const marketLiquidityAtStart = parseFloat(market.marketLiquidityAtStart.toString()) / Math.pow(10, 6);
|
|
196
|
-
currentMarket.totalLiquidity -= marketLiquidityAtStart;
|
|
197
|
-
let liquidity_coeficient = 1;
|
|
198
|
-
if ('flop' in currentMarket.direction) {
|
|
199
|
-
let shares = parseFloat(market.flopShares.toString()) / Math.pow(10, 6);
|
|
200
|
-
currentMarket.sharesToPay = shares;
|
|
201
|
-
currentMarket.liquidityToPay =
|
|
202
|
-
parseFloat(market.hypeLiquidity.toString()) / Math.pow(10, 6);
|
|
203
|
-
currentMarket.liquidityToPay =
|
|
204
|
-
currentMarket.liquidityToPay - marketLiquidityAtStart / 2;
|
|
205
|
-
}
|
|
206
|
-
else {
|
|
207
|
-
let shares = parseFloat(market.hypeShares.toString()) / Math.pow(10, 6);
|
|
208
|
-
currentMarket.sharesToPay = shares;
|
|
209
|
-
currentMarket.liquidityToPay =
|
|
210
|
-
parseFloat(market.flopLiquidity.toString()) / Math.pow(10, 6);
|
|
211
|
-
currentMarket.liquidityToPay =
|
|
212
|
-
currentMarket.liquidityToPay - marketLiquidityAtStart / 2;
|
|
213
|
-
}
|
|
214
|
-
if (currentMarket.sharesToPay > currentMarket.totalLiquidity) {
|
|
215
|
-
liquidity_coeficient =
|
|
216
|
-
currentMarket.totalLiquidity / currentMarket.sharesToPay;
|
|
217
|
-
}
|
|
218
|
-
currentMarket.liquidityCoeficient = liquidity_coeficient;
|
|
219
|
-
const token = yield (0, spl_token_1.getAssociatedTokenAddress)(constants_1.TRD_MINT, new web3_js_1.PublicKey(market.address), true, spl_token_1.TOKEN_2022_PROGRAM_ID);
|
|
220
|
-
const account = yield (0, spl_token_1.getAccount)(connection, token, 'finalized', spl_token_1.TOKEN_2022_PROGRAM_ID);
|
|
221
|
-
currentMarket.amountInPDA = Number(account.amount) / Math.pow(10, 6);
|
|
222
|
-
}
|
|
223
|
-
for (const userTrade of response) {
|
|
224
|
-
for (const order of userTrade.account.orders) {
|
|
225
|
-
const market = liquidityToRecovery[order.marketId.toNumber()];
|
|
226
|
-
if (!market) {
|
|
227
|
-
continue;
|
|
228
|
-
}
|
|
229
|
-
if (Object.keys(order.direction)[0] === Object.keys(market.direction)[0] &&
|
|
230
|
-
order.status.open) {
|
|
231
|
-
market.openOrders += 1;
|
|
232
|
-
const sharesRatio = parseFloat(order.totalShares.toString()) / market.sharesToPay;
|
|
233
|
-
const additionalPayout = Math.round(sharesRatio * market.liquidityToPay);
|
|
234
|
-
let payout = additionalPayout + parseFloat(order.totalAmount.toString());
|
|
235
|
-
if (payout > parseFloat(order.totalShares.toString())) {
|
|
236
|
-
payout = parseFloat(order.totalShares.toString());
|
|
237
|
-
}
|
|
238
|
-
payout = payout;
|
|
239
|
-
market.amountToPay += payout / Math.pow(10, 6);
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
console.log(JSON.stringify(liquidityToRecovery, null, 2));
|
|
244
|
-
let amountAllowToWithdraw = 0;
|
|
245
|
-
let amountToPay = 0;
|
|
246
|
-
let amountInPDA = 0;
|
|
247
|
-
for (const market of Object.values(liquidityToRecovery)) {
|
|
248
|
-
amountAllowToWithdraw += market.amountInPDA - market.amountToPay;
|
|
249
|
-
amountToPay += market.amountToPay;
|
|
250
|
-
amountInPDA += market.amountInPDA;
|
|
251
|
-
}
|
|
252
|
-
console.log('Amount allow to withdraw:', amountAllowToWithdraw);
|
|
253
|
-
console.log('Amount to pay:', amountToPay);
|
|
254
|
-
console.log('Amount in PDA:', amountInPDA);
|
|
255
|
-
});
|
|
256
|
-
const closeOrders = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
257
|
-
for (const order of yield getOrders(wallet.publicKey)) {
|
|
258
|
-
try {
|
|
259
|
-
const response = yield triadProtocol.trade.closeOrder({
|
|
260
|
-
marketId: order.marketId,
|
|
261
|
-
orderId: order.orderId
|
|
262
|
-
});
|
|
263
|
-
console.log(response);
|
|
264
|
-
}
|
|
265
|
-
catch (e) {
|
|
266
|
-
console.log(e);
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
});
|
|
270
|
-
const resolveMarket = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
271
|
-
const marketsToResolve = [{ marketId: 38, winningDirection: { flop: {} } }];
|
|
272
|
-
for (const market of marketsToResolve) {
|
|
273
|
-
const response = yield triadProtocol.trade.resolveMarket({
|
|
274
|
-
marketId: market.marketId,
|
|
275
|
-
winningDirection: market.winningDirection
|
|
276
|
-
}, {
|
|
277
|
-
microLamports: 5000
|
|
278
|
-
});
|
|
279
|
-
console.log(response);
|
|
280
|
-
}
|
|
281
|
-
});
|
|
282
|
-
const addLiquidity = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
283
|
-
const response = yield triadProtocol.trade.addLiquidity({
|
|
284
|
-
marketId: 5,
|
|
285
|
-
amount: 4729,
|
|
286
|
-
direction: {
|
|
287
|
-
hype: {}
|
|
288
|
-
}
|
|
289
|
-
});
|
|
290
|
-
console.log(response);
|
|
291
|
-
});
|
|
292
|
-
const collectFees = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
293
|
-
console.log('Collecting fees');
|
|
294
|
-
const allMarkets = yield triadProtocol.trade.getAllMarkets();
|
|
295
|
-
for (const market of allMarkets) {
|
|
296
|
-
console.log(`Collecting fees for market ${market.marketId}`);
|
|
297
|
-
try {
|
|
298
|
-
const response = yield triadProtocol.trade.collectFee({
|
|
299
|
-
marketId: Number(market.marketId),
|
|
300
|
-
vault: new web3_js_1.PublicKey('Hk1r2NUL4LbUhx1agg1w44tyZiNr72mbeLsg6suF5MA4')
|
|
301
|
-
}, {
|
|
302
|
-
microLamports: 32000
|
|
303
|
-
});
|
|
304
|
-
console.log(response);
|
|
305
|
-
}
|
|
306
|
-
catch (e) {
|
|
307
|
-
console.log(e);
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
});
|
|
311
|
-
const burnLP = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
312
|
-
const SOL_LP = new web3_js_1.PublicKey('8yXmXEQh8M1vyjKKhN6L12EZiXCY3cJS4xL45wwQExep');
|
|
313
|
-
const getTokenAccount = yield (0, spl_token_1.getAssociatedTokenAddress)(SOL_LP, wallet.publicKey, true);
|
|
314
|
-
console.log(getTokenAccount);
|
|
315
|
-
const amount = 191.360098123 * Math.pow(10, 9);
|
|
316
|
-
const response = yield (0, spl_token_1.burn)(connection, keypair, getTokenAccount, SOL_LP, wallet.publicKey, amount);
|
|
317
|
-
console.log(response);
|
|
318
|
-
});
|
|
319
|
-
const getReferral = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
320
|
-
const response = yield triadProtocol.getUser(new web3_js_1.PublicKey('in6cFcFF2eawkdtrGvV4mM33dRhBymJcf1Fk8mrqGJt'));
|
|
321
|
-
console.log(response);
|
|
322
|
-
});
|
|
323
|
-
const resolveWithLiquidity = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
324
|
-
const response = yield triadProtocol.trade.resolveMarketWithLiquidity({
|
|
325
|
-
marketId: 37,
|
|
326
|
-
winningDirection: { flop: {} },
|
|
327
|
-
marketToAddLiquidity: { hype: {} },
|
|
328
|
-
amount: 1000
|
|
329
|
-
});
|
|
330
|
-
console.log(response);
|
|
331
|
-
});
|
|
332
|
-
const mintToken = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
333
|
-
const filekey = fs_1.default.readFileSync('./tCMraBSGHeMcQS76hNnBhnfbMzrtnnT3nbt3vAnSCE2.json');
|
|
334
|
-
const token = web3_js_1.Keypair.fromSecretKey(new Uint8Array(JSON.parse(filekey.toString())));
|
|
335
|
-
try {
|
|
336
|
-
const decimals = 6; // Common decimal places for tokens
|
|
337
|
-
const amount = 1000000 * Math.pow(10, decimals); // 1,000,000 tokens with decimals
|
|
338
|
-
// Calculate space needed for mint account including metadata pointer
|
|
339
|
-
// const mintLen = getMintLen([ExtensionType.MetadataPointer])
|
|
340
|
-
// const mintTransaction = new Transaction().add(
|
|
341
|
-
// // Create mint account
|
|
342
|
-
// SystemProgram.createAccount({
|
|
343
|
-
// fromPubkey: wallet.publicKey,
|
|
344
|
-
// newAccountPubkey: token.publicKey,
|
|
345
|
-
// space: mintLen,
|
|
346
|
-
// lamports: 6786240,
|
|
347
|
-
// programId: TOKEN_2022_PROGRAM_ID
|
|
348
|
-
// }),
|
|
349
|
-
// createInitializeMetadataPointerInstruction(
|
|
350
|
-
// token.publicKey,
|
|
351
|
-
// wallet.publicKey,
|
|
352
|
-
// token.publicKey,
|
|
353
|
-
// TOKEN_2022_PROGRAM_ID
|
|
354
|
-
// ),
|
|
355
|
-
// createInitializeMintInstruction(
|
|
356
|
-
// token.publicKey,
|
|
357
|
-
// decimals,
|
|
358
|
-
// wallet.publicKey,
|
|
359
|
-
// null,
|
|
360
|
-
// TOKEN_2022_PROGRAM_ID
|
|
361
|
-
// ),
|
|
362
|
-
// createInitializeInstruction({
|
|
363
|
-
// programId: TOKEN_2022_PROGRAM_ID,
|
|
364
|
-
// metadata: token.publicKey,
|
|
365
|
-
// updateAuthority: wallet.publicKey,
|
|
366
|
-
// mint: token.publicKey,
|
|
367
|
-
// mintAuthority: wallet.publicKey,
|
|
368
|
-
// name: 'Triad Christmas',
|
|
369
|
-
// symbol: 'tCMAS',
|
|
370
|
-
// uri: 'https://shdw-drive.genesysgo.net/DRRe9dZkP199W6GLrySn2xj2ayfr8gin8iaBt1YVMN9M/tCMAS.json'
|
|
371
|
-
// })
|
|
372
|
-
// )
|
|
373
|
-
// const transactionSignature = await sendAndConfirmTransaction(
|
|
374
|
-
// connection,
|
|
375
|
-
// mintTransaction,
|
|
376
|
-
// [keypair, token], // Signers,
|
|
377
|
-
// { skipPreflight: false }
|
|
378
|
-
// )
|
|
379
|
-
// console.log(
|
|
380
|
-
// '\nCreate Mint Account:',
|
|
381
|
-
// `https://solana.fm/tx/${transactionSignature}?cluster=devnet-solana`
|
|
382
|
-
// )
|
|
383
|
-
// const associatedTokenAccount = await getOrCreateAssociatedTokenAccount(
|
|
384
|
-
// connection,
|
|
385
|
-
// keypair,
|
|
386
|
-
// token.publicKey,
|
|
387
|
-
// wallet.publicKey,
|
|
388
|
-
// true,
|
|
389
|
-
// undefined,
|
|
390
|
-
// undefined,
|
|
391
|
-
// TOKEN_2022_PROGRAM_ID
|
|
392
|
-
// )
|
|
393
|
-
// const mintToResponse = await mintTo(
|
|
394
|
-
// connection,
|
|
395
|
-
// keypair,
|
|
396
|
-
// token.publicKey,
|
|
397
|
-
// associatedTokenAccount.address,
|
|
398
|
-
// wallet.publicKey,
|
|
399
|
-
// amount,
|
|
400
|
-
// [keypair, token],
|
|
401
|
-
// undefined,
|
|
402
|
-
// TOKEN_2022_PROGRAM_ID
|
|
403
|
-
// )
|
|
404
|
-
// console.log('Token created:', token.publicKey.toString())
|
|
405
|
-
// console.log('Associated Token Account:', associatedTokenAccount.toString())
|
|
406
|
-
// console.log('Mint tx:', mintToResponse)
|
|
407
|
-
}
|
|
408
|
-
catch (e) {
|
|
409
|
-
console.log(e);
|
|
410
|
-
}
|
|
411
|
-
});
|
|
412
|
-
const removeMintAuthority = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
413
|
-
const filekey = fs_1.default.readFileSync('./tCMraBSGHeMcQS76hNnBhnfbMzrtnnT3nbt3vAnSCE2.json');
|
|
414
|
-
const token = web3_js_1.Keypair.fromSecretKey(new Uint8Array(JSON.parse(filekey.toString())));
|
|
415
|
-
try {
|
|
416
|
-
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);
|
|
417
|
-
console.log('Mint authority removed:', response);
|
|
418
|
-
}
|
|
419
|
-
catch (error) {
|
|
420
|
-
console.error('Error removing mint authority:', error);
|
|
421
|
-
}
|
|
422
|
-
});
|
|
423
|
-
const getMinteds = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
424
|
-
const response = yield triadProtocol.program.account.collection.all();
|
|
425
|
-
console.log(response);
|
|
426
|
-
});
|
|
427
|
-
// let prize_ranges = [
|
|
428
|
-
// (1, 9, PrizeType::Trd10000), // 0.0014%
|
|
429
|
-
// (10, 15, PrizeType::Undead), // 0.0014%
|
|
430
|
-
// (16, 116, PrizeType::Ticket), // 0.01%
|
|
431
|
-
// (117, 617, PrizeType::Honeyland), // 0.05%
|
|
432
|
-
// (618, 5618, PrizeType::Trd50), // 0.5%
|
|
433
|
-
// (5619, 15619, PrizeType::Flip), // 1%
|
|
434
|
-
// (15620, 25620, PrizeType::Pengu), // 1%
|
|
435
|
-
// (25621, 65621, PrizeType::Ore), // 4%
|
|
436
|
-
// (65622, 165622, PrizeType::Lucksea), // 10%
|
|
437
|
-
// (165623, 285623, PrizeType::Trd5), // 12%
|
|
438
|
-
// (285624, 499999, PrizeType::Trident2000), // 21.3385%
|
|
439
|
-
// (500000, 1000000, PrizeType::Trident500), // 50%
|
|
440
|
-
// ];
|
|
441
|
-
const addSpinPrize = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
442
|
-
const data = [
|
|
443
|
-
// {
|
|
444
|
-
// rangeMin: 1,
|
|
445
|
-
// rangeMax: 9,
|
|
446
|
-
// prizeType: { trd10000: {} },
|
|
447
|
-
// availableQuantity: 1
|
|
448
|
-
// },
|
|
449
|
-
// {
|
|
450
|
-
// rangeMin: 10,
|
|
451
|
-
// rangeMax: 15,
|
|
452
|
-
// prizeType: { undead: {} },
|
|
453
|
-
// availableQuantity: 1
|
|
454
|
-
// },
|
|
455
|
-
// {
|
|
456
|
-
// rangeMin: 16,
|
|
457
|
-
// rangeMax: 116,
|
|
458
|
-
// prizeType: { ticket: {} },
|
|
459
|
-
// availableQuantity: 2
|
|
460
|
-
// }
|
|
461
|
-
// {
|
|
462
|
-
// rangeMin: 117,
|
|
463
|
-
// rangeMax: 617,
|
|
464
|
-
// prizeType: { honeyland: {} },
|
|
465
|
-
// availableQuantity: 2
|
|
466
|
-
// }
|
|
467
|
-
// {
|
|
468
|
-
// rangeMin: 618,
|
|
469
|
-
// rangeMax: 5618,
|
|
470
|
-
// prizeType: { trd50: {} },
|
|
471
|
-
// availableQuantity: 50
|
|
472
|
-
// },
|
|
473
|
-
// {
|
|
474
|
-
// rangeMin: 5619,
|
|
475
|
-
// rangeMax: 15619,
|
|
476
|
-
// prizeType: { flip: {} },
|
|
477
|
-
// availableQuantity: 1
|
|
478
|
-
// },
|
|
479
|
-
{
|
|
480
|
-
rangeMin: 15620,
|
|
481
|
-
rangeMax: 25620,
|
|
482
|
-
prizeType: { pengu: {} },
|
|
483
|
-
availableQuantity: 3 + 7
|
|
484
|
-
},
|
|
485
|
-
{
|
|
486
|
-
rangeMin: 25621,
|
|
487
|
-
rangeMax: 65621,
|
|
488
|
-
prizeType: { ore: {} },
|
|
489
|
-
availableQuantity: 13
|
|
490
|
-
},
|
|
491
|
-
{
|
|
492
|
-
rangeMin: 65622,
|
|
493
|
-
rangeMax: 165622,
|
|
494
|
-
prizeType: { lucksea: {} },
|
|
495
|
-
availableQuantity: 18
|
|
496
|
-
}
|
|
497
|
-
// {
|
|
498
|
-
// rangeMin: 165623,
|
|
499
|
-
// rangeMax: 285623,
|
|
500
|
-
// prizeType: { trd5: {} },
|
|
501
|
-
// availableQuantity: 10000
|
|
502
|
-
// },
|
|
503
|
-
// {
|
|
504
|
-
// rangeMin: 285624,
|
|
505
|
-
// rangeMax: 499999,
|
|
506
|
-
// prizeType: { trident2000: {} },
|
|
507
|
-
// availableQuantity: 5000000
|
|
508
|
-
// },
|
|
509
|
-
// {
|
|
510
|
-
// rangeMin: 500000,
|
|
511
|
-
// rangeMax: 1000000,
|
|
512
|
-
// prizeType: { trident500: {} },
|
|
513
|
-
// availableQuantity: 5000000
|
|
514
|
-
// }
|
|
515
|
-
];
|
|
516
|
-
for (const item of data) {
|
|
517
|
-
const response = yield triadProtocol.addSpinPrize(item);
|
|
518
|
-
console.log(response);
|
|
519
|
-
}
|
|
520
|
-
});
|
|
521
|
-
const spinWheel = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
522
|
-
const response = yield triadProtocol.spinWheel({
|
|
523
|
-
isSol: false,
|
|
524
|
-
prizeType: { none: {} },
|
|
525
|
-
verifier: keypair
|
|
526
|
-
});
|
|
527
|
-
console.log(response);
|
|
528
|
-
});
|
|
529
|
-
const getSpinPrize = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
530
|
-
let response = yield triadProtocol.program.account.spin.fetch(new web3_js_1.PublicKey('EQ6ZJbdT2V8ZYcHRpJx6wBkGWmM1e3mimtPKshTVuw8h'));
|
|
531
|
-
const prizes = response.prizes.map((prize) => ({
|
|
532
|
-
rangeMin: prize.rangeMin.toNumber(),
|
|
533
|
-
rangeMax: prize.rangeMax.toNumber(),
|
|
534
|
-
prizeType: prize.prizeType,
|
|
535
|
-
availableQuantity: prize.availableQuantity.toNumber()
|
|
536
|
-
}));
|
|
537
|
-
console.log(prizes.filter((prize) => !prize.prizeType.none));
|
|
538
|
-
});
|
package/dist/utils/jup-swap.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { AddressLookupTableAccount, Connection, TransactionInstruction } from '@solana/web3.js';
|
|
2
|
-
export declare const jupSwap: ({ connection, wallet, inToken, outToken, amount }: {
|
|
3
|
-
connection: Connection;
|
|
4
|
-
wallet: string;
|
|
5
|
-
inToken: string;
|
|
6
|
-
outToken: string;
|
|
7
|
-
amount: number;
|
|
8
|
-
}) => Promise<{
|
|
9
|
-
swapIxs: TransactionInstruction[];
|
|
10
|
-
addressLookupTableAccounts: AddressLookupTableAccount[];
|
|
11
|
-
setupInstructions: any;
|
|
12
|
-
cleanupInstruction: TransactionInstruction;
|
|
13
|
-
otherAmountThreshold: any;
|
|
14
|
-
}>;
|
|
15
|
-
export declare const getAddressLookupTableAccounts: (connection: Connection, keys: string[]) => Promise<AddressLookupTableAccount[]>;
|