@triadxyz/triad-protocol 1.2.2-beta → 1.2.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 +0 -10
- package/dist/index.js +2 -11
- package/dist/local-test.js +23 -90
- package/dist/stake.d.ts +1 -8
- package/dist/stake.js +0 -25
- package/dist/trade.d.ts +7 -3
- package/dist/trade.js +43 -6
- package/dist/types/idl_triad_protocol.json +24 -364
- package/dist/types/triad_protocol.d.ts +24 -422
- package/dist/utils/constants.d.ts +1 -0
- package/dist/utils/constants.js +2 -1
- package/dist/utils/jup-swap.d.ts +15 -0
- package/dist/utils/jup-swap.js +66 -0
- package/dist/utils/swap.js +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -23,16 +23,6 @@ export default class TriadProtocolClient {
|
|
|
23
23
|
*
|
|
24
24
|
*/
|
|
25
25
|
getUsers(): Promise<import("./types").User[]>;
|
|
26
|
-
getTickers(): Promise<import("@coral-xyz/anchor").ProgramAccount<{
|
|
27
|
-
initTs: import("bn.js");
|
|
28
|
-
updatedTs: import("bn.js");
|
|
29
|
-
bump: number;
|
|
30
|
-
authority: PublicKey;
|
|
31
|
-
name: string;
|
|
32
|
-
protocolProgramId: PublicKey;
|
|
33
|
-
price: import("bn.js");
|
|
34
|
-
vault: PublicKey;
|
|
35
|
-
}>[]>;
|
|
36
26
|
/**
|
|
37
27
|
* Check if user exists
|
|
38
28
|
* @param username - User name
|
package/dist/index.js
CHANGED
|
@@ -55,11 +55,6 @@ class TriadProtocolClient {
|
|
|
55
55
|
.sort((a, b) => b.referred - a.referred);
|
|
56
56
|
});
|
|
57
57
|
}
|
|
58
|
-
getTickers() {
|
|
59
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
-
return yield this.program.account.ticker.all();
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
58
|
/**
|
|
64
59
|
* Check if user exists
|
|
65
60
|
* @param username - User name
|
|
@@ -131,12 +126,9 @@ class TriadProtocolClient {
|
|
|
131
126
|
*/
|
|
132
127
|
getUserPositionsWithAmount(wallet) {
|
|
133
128
|
return __awaiter(this, void 0, void 0, function* () {
|
|
134
|
-
const tickers = yield this.program.account.ticker.all();
|
|
135
129
|
const userPositions = [];
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
userPositions.push(userPositionPDA);
|
|
139
|
-
}
|
|
130
|
+
const userPositionPDA = (0, pda_1.getUserPositionPDA)(this.program.programId, wallet, new web3_js_1.PublicKey('EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v'));
|
|
131
|
+
userPositions.push(userPositionPDA);
|
|
140
132
|
const userPositionsWithAmount = yield this.program.account.userPosition.fetchMultiple(userPositions);
|
|
141
133
|
return userPositionsWithAmount.filter((item) => item &&
|
|
142
134
|
parseFloat(item.totalDeposited.toString()) >
|
|
@@ -154,7 +146,6 @@ class TriadProtocolClient {
|
|
|
154
146
|
userPosition: userPositionPDA,
|
|
155
147
|
userTokenAccount,
|
|
156
148
|
vault: vaultPDA,
|
|
157
|
-
ticker,
|
|
158
149
|
vaultTokenAccount: VaultTokenAccountPDA
|
|
159
150
|
}), options);
|
|
160
151
|
});
|
package/dist/local-test.js
CHANGED
|
@@ -21,79 +21,11 @@ const spl_token_1 = require("@solana/spl-token");
|
|
|
21
21
|
const file = fs_1.default.readFileSync('/Users/dannpl/.config/solana/id.json');
|
|
22
22
|
const rpc_file = fs_1.default.readFileSync('/Users/dannpl/.config/solana/rpc.txt');
|
|
23
23
|
const keypair = web3_js_1.Keypair.fromSecretKey(new Uint8Array(JSON.parse(file.toString())));
|
|
24
|
-
const connection = new web3_js_1.Connection('https://mainnet.
|
|
24
|
+
const connection = new web3_js_1.Connection('https://triad-solanam-a5ee.mainnet.rpcpool.com/34797434-86a9-4a15-abb1-6b5f6cb7a8ff');
|
|
25
25
|
const wallet = new anchor_1.Wallet(keypair);
|
|
26
26
|
const triadProtocol = new _1.default(connection, wallet);
|
|
27
27
|
const mint = new web3_js_1.PublicKey('X41iRJUPkKaEvhqWdxqrS5P7M5d8A9oathki5sT47KR');
|
|
28
|
-
const markets = [
|
|
29
|
-
// { name: 'Triad', marketId: 0 },
|
|
30
|
-
// { name: 'PYTH', marketId: 1 }
|
|
31
|
-
// { name: 'DRIFT', marketId: 2 }
|
|
32
|
-
// { name: 'SYMMETRY', marketId: 3 }
|
|
33
|
-
// { name: 'ORE', marketId: 4 }
|
|
34
|
-
// { name: 'COLETA', marketId: 5 }
|
|
35
|
-
// { name: 'UNDEADS', marketId: 6 },
|
|
36
|
-
// { name: 'SOL x ETH', marketId: 7 }
|
|
37
|
-
// { name: 'SOL vs ETH', marketId: 8 }
|
|
38
|
-
{ name: 'SOL vs ETH 2', marketId: 9 }
|
|
39
|
-
// { name: 'PYTH x LINK', marketId: 8 },
|
|
40
|
-
// { name: 'SOL PRICE', marketId: 9 }
|
|
41
|
-
];
|
|
42
|
-
const questions = [
|
|
43
|
-
{
|
|
44
|
-
name: 'Pyth',
|
|
45
|
-
marketId: 1,
|
|
46
|
-
question: 'test 2',
|
|
47
|
-
startTime: 1719513866,
|
|
48
|
-
endTime: 1730394000
|
|
49
|
-
}
|
|
50
|
-
// },
|
|
51
|
-
// {
|
|
52
|
-
// name: 'Pyth',
|
|
53
|
-
// marketId: 1,
|
|
54
|
-
// question: "$PYTH's market cap exceed $1.5B by the end of October?",
|
|
55
|
-
// startTime: 1728415578,
|
|
56
|
-
// endTime: 1730394000
|
|
57
|
-
// },
|
|
58
|
-
// {
|
|
59
|
-
// name: 'Drift',
|
|
60
|
-
// marketId: 2,
|
|
61
|
-
// question:
|
|
62
|
-
// 'Drift surpass $33M in volume on prediction markets by the end of October?',
|
|
63
|
-
// startTime: 1728415578,
|
|
64
|
-
// endTime: 1730394000
|
|
65
|
-
// },
|
|
66
|
-
// {
|
|
67
|
-
// name: 'Symmetry',
|
|
68
|
-
// marketId: 3,
|
|
69
|
-
// question: "Symmetry's TVL exceed $5.5M by the end of October?",
|
|
70
|
-
// startTime: 1728415578,
|
|
71
|
-
// endTime: 1730394000
|
|
72
|
-
// },
|
|
73
|
-
// {
|
|
74
|
-
// name: 'Ore',
|
|
75
|
-
// marketId: 4,
|
|
76
|
-
// question: 'ORE surpass 20k on-chain miners by the end of October?',
|
|
77
|
-
// startTime: 1728415578,
|
|
78
|
-
// endTime: 1730394000
|
|
79
|
-
// },
|
|
80
|
-
// {
|
|
81
|
-
// name: 'Coleta',
|
|
82
|
-
// marketId: 5,
|
|
83
|
-
// question:
|
|
84
|
-
// 'COLETA PFP reach 500 SOL in total volume by the end of October (based on Tensor)?',
|
|
85
|
-
// startTime: 1728415578,
|
|
86
|
-
// endTime: 1730394000
|
|
87
|
-
// },
|
|
88
|
-
// {
|
|
89
|
-
// name: 'Undeads',
|
|
90
|
-
// marketId: 6,
|
|
91
|
-
// question:
|
|
92
|
-
// 'The Undeads reach more than 1,600 holders by the end of October?',
|
|
93
|
-
// startTime: 1728415578,
|
|
94
|
-
// endTime: 1730394000
|
|
95
|
-
// }
|
|
96
|
-
];
|
|
28
|
+
const markets = [];
|
|
97
29
|
const ordersHypeAndFloopBot = [
|
|
98
30
|
{
|
|
99
31
|
marketId: 7,
|
|
@@ -106,7 +38,7 @@ const ordersHypeAndFloopBot = [
|
|
|
106
38
|
const updateStakeVault = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
107
39
|
const response = yield triadProtocol.stake.updateStakeVault({
|
|
108
40
|
wallet: wallet.publicKey,
|
|
109
|
-
amount: new anchor_1.BN(
|
|
41
|
+
amount: new anchor_1.BN(10000 * Math.pow(10, 6)),
|
|
110
42
|
isLocked: false
|
|
111
43
|
});
|
|
112
44
|
console.log(response);
|
|
@@ -140,22 +72,22 @@ const getAllMarkets = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
140
72
|
console.log(markets);
|
|
141
73
|
});
|
|
142
74
|
const getMarket = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
143
|
-
const market = yield triadProtocol.trade.getMarketById(
|
|
75
|
+
const market = yield triadProtocol.trade.getMarketById(12);
|
|
144
76
|
console.log(market);
|
|
145
77
|
});
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
78
|
+
const initializeAllMarkets = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
79
|
+
for (const market of markets) {
|
|
80
|
+
try {
|
|
81
|
+
const response = yield triadProtocol.trade.initializeMarket(market, {
|
|
82
|
+
microLamports: 5000
|
|
83
|
+
});
|
|
84
|
+
console.log(`Initialized market ${market.name}:`, response);
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
console.error(`Error initializing market ${market.name}:`, error);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
});
|
|
159
91
|
const getOrders = (walletAddress) => __awaiter(void 0, void 0, void 0, function* () {
|
|
160
92
|
const response = (yield triadProtocol.program.account.userTrade.all()).find((userTrade) => userTrade.account.authority.toBase58() === walletAddress.toBase58());
|
|
161
93
|
let orders = [];
|
|
@@ -312,7 +244,6 @@ const getLiquidityToRecovery = () => __awaiter(void 0, void 0, void 0, function*
|
|
|
312
244
|
}
|
|
313
245
|
console.log(liquidityToRecovery);
|
|
314
246
|
});
|
|
315
|
-
getLiquidityToRecovery();
|
|
316
247
|
const openOrder = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
317
248
|
yield getMarket();
|
|
318
249
|
for (const order of ordersHypeAndFloopBot) {
|
|
@@ -395,14 +326,15 @@ const addLiquidity = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
395
326
|
const collectFees = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
396
327
|
console.log('Collecting fees');
|
|
397
328
|
const allMarkets = yield triadProtocol.trade.getAllMarkets();
|
|
329
|
+
let currentFees = {};
|
|
398
330
|
for (const market of allMarkets) {
|
|
399
|
-
if (Number(market.marketId) === 0 || Number(market.marketId) === 7) {
|
|
400
|
-
continue;
|
|
401
|
-
}
|
|
402
331
|
console.log(`Collecting fees for market ${market.marketId}`);
|
|
403
332
|
try {
|
|
404
333
|
const response = yield triadProtocol.trade.collectFee({
|
|
405
|
-
marketId: Number(market.marketId)
|
|
334
|
+
marketId: Number(market.marketId),
|
|
335
|
+
vault: new web3_js_1.PublicKey('6fcSf6qfwPNR9AUUNC1UWYZDy5cQ4TzTb2aaipN2zFdq')
|
|
336
|
+
}, {
|
|
337
|
+
microLamports: 70000
|
|
406
338
|
});
|
|
407
339
|
console.log(response);
|
|
408
340
|
}
|
|
@@ -410,4 +342,5 @@ const collectFees = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
410
342
|
console.log(e);
|
|
411
343
|
}
|
|
412
344
|
}
|
|
345
|
+
fs_1.default.writeFileSync(`fees-collected.json`, JSON.stringify(currentFees, null, 2));
|
|
413
346
|
});
|
package/dist/stake.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { AnchorProvider, Program } from '@coral-xyz/anchor';
|
|
|
2
2
|
import { PublicKey } from '@solana/web3.js';
|
|
3
3
|
import { TriadProtocol } from './types/triad_protocol';
|
|
4
4
|
import { RpcOptions } from './types';
|
|
5
|
-
import { UpdateStakeVaultArgs,
|
|
5
|
+
import { UpdateStakeVaultArgs, RequestWithdrawArgs, WithdrawArgs, Stake as StakeResponse, ClaimStakeRewardsArgs, StakeTokenArgs, UpdateBoostArgs } from './types/stake';
|
|
6
6
|
export default class Stake {
|
|
7
7
|
program: Program<TriadProtocol>;
|
|
8
8
|
provider: AnchorProvider;
|
|
@@ -35,13 +35,6 @@ export default class Stake {
|
|
|
35
35
|
name: string;
|
|
36
36
|
rarityRankHrtt: number;
|
|
37
37
|
}[]): Promise<StakeResponse[]>;
|
|
38
|
-
/**
|
|
39
|
-
* Stake NFT
|
|
40
|
-
* @param mint - NFT mint
|
|
41
|
-
* @param items - NFT items
|
|
42
|
-
*
|
|
43
|
-
*/
|
|
44
|
-
stakeNft({ wallet, items }: StakeNftArgs, options?: RpcOptions): Promise<string>;
|
|
45
38
|
/**
|
|
46
39
|
* Stake Token
|
|
47
40
|
* @param name - Index
|
package/dist/stake.js
CHANGED
|
@@ -114,31 +114,6 @@ class Stake {
|
|
|
114
114
|
return data;
|
|
115
115
|
});
|
|
116
116
|
}
|
|
117
|
-
/**
|
|
118
|
-
* Stake NFT
|
|
119
|
-
* @param mint - NFT mint
|
|
120
|
-
* @param items - NFT items
|
|
121
|
-
*
|
|
122
|
-
*/
|
|
123
|
-
stakeNft({ wallet, items }, options) {
|
|
124
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
125
|
-
let ixs = [];
|
|
126
|
-
for (let i = 0; i < items.length; i++) {
|
|
127
|
-
let item = items[i];
|
|
128
|
-
ixs.push(yield this.program.methods
|
|
129
|
-
.stakeNft({
|
|
130
|
-
name: item.name,
|
|
131
|
-
stakeVault: this.stakeVaultName
|
|
132
|
-
})
|
|
133
|
-
.accounts({
|
|
134
|
-
signer: wallet,
|
|
135
|
-
mint: item.mint
|
|
136
|
-
})
|
|
137
|
-
.instruction());
|
|
138
|
-
}
|
|
139
|
-
return (0, sendVersionedTransaction_1.default)(this.provider, ixs, options);
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
117
|
/**
|
|
143
118
|
* Stake Token
|
|
144
119
|
* @param name - Index
|
package/dist/trade.d.ts
CHANGED
|
@@ -122,7 +122,7 @@ export default class Trade {
|
|
|
122
122
|
* @param options - RPC options
|
|
123
123
|
*
|
|
124
124
|
*/
|
|
125
|
-
openOrder({ marketId, amount, direction, token
|
|
125
|
+
openOrder({ marketId, amount, direction, token }: OpenOrderArgs, options?: RpcOptions): Promise<string>;
|
|
126
126
|
/**
|
|
127
127
|
* Close Order
|
|
128
128
|
* @param marketId - The ID of the market
|
|
@@ -186,7 +186,11 @@ export default class Trade {
|
|
|
186
186
|
* @param options - RPC options
|
|
187
187
|
*
|
|
188
188
|
*/
|
|
189
|
-
collectFee({ marketId }: {
|
|
189
|
+
collectFee({ marketId, vault }: {
|
|
190
190
|
marketId: number;
|
|
191
|
-
|
|
191
|
+
vault: PublicKey;
|
|
192
|
+
}, options?: RpcOptions): Promise<{
|
|
193
|
+
feeToSwap: number;
|
|
194
|
+
lamport: number;
|
|
195
|
+
}>;
|
|
192
196
|
}
|
package/dist/trade.js
CHANGED
|
@@ -12,6 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
15
16
|
const bn_js_1 = __importDefault(require("bn.js"));
|
|
16
17
|
const constants_1 = require("./utils/constants");
|
|
17
18
|
const helpers_1 = require("./utils/helpers");
|
|
@@ -20,6 +21,7 @@ const pda_1 = require("./utils/pda");
|
|
|
20
21
|
const sendVersionedTransaction_1 = __importDefault(require("./utils/sendVersionedTransaction"));
|
|
21
22
|
const sendTransactionWithOptions_1 = __importDefault(require("./utils/sendTransactionWithOptions"));
|
|
22
23
|
const swap_1 = require("./utils/swap");
|
|
24
|
+
const jup_swap_1 = require("./utils/jup-swap");
|
|
23
25
|
class Trade {
|
|
24
26
|
constructor(program, provider) {
|
|
25
27
|
this.mint = constants_1.TRD_MINT;
|
|
@@ -109,7 +111,7 @@ class Trade {
|
|
|
109
111
|
* @param options - RPC options
|
|
110
112
|
*
|
|
111
113
|
*/
|
|
112
|
-
openOrder({ marketId, amount, direction, token
|
|
114
|
+
openOrder({ marketId, amount, direction, token }, options) {
|
|
113
115
|
return __awaiter(this, void 0, void 0, function* () {
|
|
114
116
|
const marketPDA = (0, trade_1.getMarketPDA)(this.program.programId, marketId);
|
|
115
117
|
const userTradePDA = (0, trade_1.getUserTradePDA)(this.program.programId, this.provider.publicKey);
|
|
@@ -147,8 +149,7 @@ class Trade {
|
|
|
147
149
|
ixs.push(yield this.program.methods
|
|
148
150
|
.openOrder({
|
|
149
151
|
amount: new bn_js_1.default(amountInTRD),
|
|
150
|
-
direction: direction
|
|
151
|
-
comment: (0, helpers_1.encodeString)(comment, 64)
|
|
152
|
+
direction: direction
|
|
152
153
|
})
|
|
153
154
|
.accounts({
|
|
154
155
|
signer: this.provider.publicKey,
|
|
@@ -251,14 +252,50 @@ class Trade {
|
|
|
251
252
|
* @param options - RPC options
|
|
252
253
|
*
|
|
253
254
|
*/
|
|
254
|
-
collectFee({ marketId }, options) {
|
|
255
|
+
collectFee({ marketId, vault }, options) {
|
|
255
256
|
return __awaiter(this, void 0, void 0, function* () {
|
|
256
257
|
const marketPDA = (0, trade_1.getMarketPDA)(this.program.programId, marketId);
|
|
257
|
-
|
|
258
|
+
const ixs = [];
|
|
259
|
+
ixs.push(yield this.program.methods
|
|
260
|
+
.collectFee()
|
|
261
|
+
.accounts({
|
|
258
262
|
signer: this.provider.publicKey,
|
|
259
263
|
market: marketPDA,
|
|
260
264
|
mint: this.mint
|
|
261
|
-
})
|
|
265
|
+
})
|
|
266
|
+
.instruction());
|
|
267
|
+
const market = yield this.getMarketById(marketId);
|
|
268
|
+
const marketFee = parseFloat(market.marketFeeAvailable) -
|
|
269
|
+
parseFloat(market.marketFeeClaimed);
|
|
270
|
+
const nftFee = parseFloat(market.nftHoldersFeeAvailable) -
|
|
271
|
+
parseFloat(market.nftHoldersFeeClaimed);
|
|
272
|
+
const totalFee = marketFee + nftFee;
|
|
273
|
+
if (totalFee / Math.pow(10, constants_1.TRD_DECIMALS) < 100) {
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
const { setupInstructions, swapIxs, addressLookupTableAccounts, cleanupInstruction, otherAmountThreshold } = yield (0, jup_swap_1.jupSwap)({
|
|
277
|
+
connection: this.provider.connection,
|
|
278
|
+
wallet: this.provider.publicKey.toBase58(),
|
|
279
|
+
inToken: constants_1.TRD_MINT.toBase58(),
|
|
280
|
+
outToken: constants_1.SOL_MINT.toBase58(),
|
|
281
|
+
amount: parseInt(totalFee.toFixed())
|
|
282
|
+
});
|
|
283
|
+
ixs.push(...setupInstructions);
|
|
284
|
+
ixs.push(web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({
|
|
285
|
+
units: 500000
|
|
286
|
+
}));
|
|
287
|
+
ixs.push(...swapIxs);
|
|
288
|
+
ixs.push(cleanupInstruction);
|
|
289
|
+
ixs.push(web3_js_1.SystemProgram.transfer({
|
|
290
|
+
fromPubkey: this.provider.publicKey,
|
|
291
|
+
toPubkey: vault,
|
|
292
|
+
lamports: otherAmountThreshold
|
|
293
|
+
}));
|
|
294
|
+
yield (0, sendVersionedTransaction_1.default)(this.provider, ixs, options, undefined, addressLookupTableAccounts);
|
|
295
|
+
return {
|
|
296
|
+
feeToSwap: totalFee,
|
|
297
|
+
lamport: otherAmountThreshold
|
|
298
|
+
};
|
|
262
299
|
});
|
|
263
300
|
}
|
|
264
301
|
}
|