@triadxyz/triad-protocol 1.6.8-beta-dev → 1.6.8-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 +28 -0
- package/dist/index.js +61 -1
- package/dist/stake.d.ts +9 -1
- package/dist/stake.js +10 -4
- package/dist/trade.d.ts +37 -79
- package/dist/trade.js +102 -260
- package/dist/types/idl_triad_protocol.json +274 -521
- package/dist/types/trade.d.ts +25 -76
- package/dist/types/trade.js +1 -25
- package/dist/types/triad_protocol.d.ts +305 -610
- package/dist/utils/constants.d.ts +0 -1
- package/dist/utils/constants.js +1 -2
- package/dist/utils/helpers.d.ts +3 -32
- package/dist/utils/helpers.js +18 -73
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -39,4 +39,32 @@ export default class TriadProtocolClient {
|
|
|
39
39
|
* @param options - RPC options
|
|
40
40
|
*/
|
|
41
41
|
collectRoyalty(collection: string, options?: RpcOptions): Promise<string>;
|
|
42
|
+
/**
|
|
43
|
+
* Add Default Poseidon
|
|
44
|
+
* @param users - Users
|
|
45
|
+
*
|
|
46
|
+
* @param options - RPC options
|
|
47
|
+
*/
|
|
48
|
+
addDefaultPoseidon(users: PublicKey[], options?: RpcOptions): Promise<string>;
|
|
49
|
+
/**
|
|
50
|
+
* Add Trader Poseidon
|
|
51
|
+
* @param user - User
|
|
52
|
+
* @param poseidonAsset - Poseidon Asset
|
|
53
|
+
*
|
|
54
|
+
* @param options - RPC options
|
|
55
|
+
*/
|
|
56
|
+
addTraderPoseidon({ user, poseidonAsset }: {
|
|
57
|
+
user: PublicKey;
|
|
58
|
+
poseidonAsset: PublicKey;
|
|
59
|
+
}, options?: RpcOptions): Promise<string>;
|
|
60
|
+
/**
|
|
61
|
+
* Remove Trader Poseidon
|
|
62
|
+
* @param user - User
|
|
63
|
+
*
|
|
64
|
+
* @param options - RPC options
|
|
65
|
+
*/
|
|
66
|
+
removeTraderPoseidon({ user, poseidonAsset }: {
|
|
67
|
+
user: PublicKey;
|
|
68
|
+
poseidonAsset: PublicKey;
|
|
69
|
+
}, options?: RpcOptions): Promise<string>;
|
|
42
70
|
}
|
package/dist/index.js
CHANGED
|
@@ -20,10 +20,11 @@ const stake_1 = __importDefault(require("./stake"));
|
|
|
20
20
|
const sendVersionedTransaction_1 = __importDefault(require("./utils/sendVersionedTransaction"));
|
|
21
21
|
const constants_1 = require("./utils/constants");
|
|
22
22
|
const sendTransactionWithOptions_1 = __importDefault(require("./utils/sendTransactionWithOptions"));
|
|
23
|
+
const trade_2 = require("./utils/pda/trade");
|
|
23
24
|
class TriadProtocolClient {
|
|
24
25
|
constructor(connection, wallet) {
|
|
25
26
|
this.provider = new anchor_1.AnchorProvider(connection, wallet, {
|
|
26
|
-
commitment: '
|
|
27
|
+
commitment: 'processed'
|
|
27
28
|
});
|
|
28
29
|
this.program = new anchor_1.Program(idl_triad_protocol_json_1.default, this.provider);
|
|
29
30
|
this.trade = new trade_1.default(this.program, this.provider);
|
|
@@ -99,5 +100,64 @@ class TriadProtocolClient {
|
|
|
99
100
|
}), options);
|
|
100
101
|
});
|
|
101
102
|
}
|
|
103
|
+
/**
|
|
104
|
+
* Add Default Poseidon
|
|
105
|
+
* @param users - Users
|
|
106
|
+
*
|
|
107
|
+
* @param options - RPC options
|
|
108
|
+
*/
|
|
109
|
+
addDefaultPoseidon(users, options) {
|
|
110
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
111
|
+
const ixs = [];
|
|
112
|
+
for (const user of users) {
|
|
113
|
+
const UserTradePDA = (0, trade_2.getUserTradePDA)(this.program.programId, user);
|
|
114
|
+
ixs.push(yield this.program.methods
|
|
115
|
+
.addDefaultPoseidon()
|
|
116
|
+
.accounts({
|
|
117
|
+
signer: this.provider.wallet.publicKey,
|
|
118
|
+
userTrade: UserTradePDA
|
|
119
|
+
})
|
|
120
|
+
.instruction());
|
|
121
|
+
}
|
|
122
|
+
return (0, sendVersionedTransaction_1.default)(this.provider, ixs, options);
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Add Trader Poseidon
|
|
127
|
+
* @param user - User
|
|
128
|
+
* @param poseidonAsset - Poseidon Asset
|
|
129
|
+
*
|
|
130
|
+
* @param options - RPC options
|
|
131
|
+
*/
|
|
132
|
+
addTraderPoseidon({ user, poseidonAsset }, options) {
|
|
133
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
134
|
+
const UserTradePDA = (0, trade_2.getUserTradePDA)(this.program.programId, user);
|
|
135
|
+
const PoseidonCollectionPDA = (0, pda_1.getCollectionPDA)(this.program.programId, constants_1.POSEIDON_COLLECTION_SYMBOL);
|
|
136
|
+
return (0, sendTransactionWithOptions_1.default)(this.program.methods.addTraderPoseidon().accounts({
|
|
137
|
+
poseidonAsset,
|
|
138
|
+
userTrade: UserTradePDA,
|
|
139
|
+
corePoseidonCollection: constants_1.POSEIDON_CORE_COLLECTION,
|
|
140
|
+
poseidonCollection: PoseidonCollectionPDA
|
|
141
|
+
}), options);
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Remove Trader Poseidon
|
|
146
|
+
* @param user - User
|
|
147
|
+
*
|
|
148
|
+
* @param options - RPC options
|
|
149
|
+
*/
|
|
150
|
+
removeTraderPoseidon({ user, poseidonAsset }, options) {
|
|
151
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
152
|
+
const UserTradePDA = (0, trade_2.getUserTradePDA)(this.program.programId, user);
|
|
153
|
+
const PoseidonCollectionPDA = (0, pda_1.getCollectionPDA)(this.program.programId, constants_1.POSEIDON_COLLECTION_SYMBOL);
|
|
154
|
+
return (0, sendTransactionWithOptions_1.default)(this.program.methods.removeTraderPoseidon().accounts({
|
|
155
|
+
userTrade: UserTradePDA,
|
|
156
|
+
poseidonAsset,
|
|
157
|
+
corePoseidonCollection: constants_1.POSEIDON_CORE_COLLECTION,
|
|
158
|
+
poseidonCollection: PoseidonCollectionPDA
|
|
159
|
+
}), options);
|
|
160
|
+
});
|
|
161
|
+
}
|
|
102
162
|
}
|
|
103
163
|
exports.default = TriadProtocolClient;
|
package/dist/stake.d.ts
CHANGED
|
@@ -72,12 +72,20 @@ export default class Stake {
|
|
|
72
72
|
* Claim Stake Rewards
|
|
73
73
|
* @param args.wallet - User wallet
|
|
74
74
|
* @param args.collections - NFT collections
|
|
75
|
+
* @param args.ranks - Tensor ranks
|
|
75
76
|
* @param args.verifier - Verifier
|
|
76
77
|
*
|
|
77
78
|
* @param options - RPC options
|
|
78
79
|
*
|
|
79
80
|
*/
|
|
80
|
-
claimStakeRewards({ wallet }: {
|
|
81
|
+
claimStakeRewards({ wallet, collections, ranks, verifier }: {
|
|
81
82
|
wallet: PublicKey;
|
|
83
|
+
collections: number;
|
|
84
|
+
ranks: {
|
|
85
|
+
onchainId: string;
|
|
86
|
+
name: string;
|
|
87
|
+
rarityRankHrtt: number;
|
|
88
|
+
}[];
|
|
89
|
+
verifier: string;
|
|
82
90
|
}, options?: RpcOptions): Promise<string>;
|
|
83
91
|
}
|
package/dist/stake.js
CHANGED
|
@@ -18,6 +18,7 @@ const stake_1 = require("./utils/pda/stake");
|
|
|
18
18
|
const constants_1 = require("./utils/constants");
|
|
19
19
|
const sendVersionedTransaction_1 = __importDefault(require("./utils/sendVersionedTransaction"));
|
|
20
20
|
const sendTransactionWithOptions_1 = __importDefault(require("./utils/sendTransactionWithOptions"));
|
|
21
|
+
const convertSecretKeyToKeypair_1 = require("./utils/convertSecretKeyToKeypair");
|
|
21
22
|
class Stake {
|
|
22
23
|
constructor(program, provider) {
|
|
23
24
|
this.program = program;
|
|
@@ -174,12 +175,13 @@ class Stake {
|
|
|
174
175
|
* Claim Stake Rewards
|
|
175
176
|
* @param args.wallet - User wallet
|
|
176
177
|
* @param args.collections - NFT collections
|
|
178
|
+
* @param args.ranks - Tensor ranks
|
|
177
179
|
* @param args.verifier - Verifier
|
|
178
180
|
*
|
|
179
181
|
* @param options - RPC options
|
|
180
182
|
*
|
|
181
183
|
*/
|
|
182
|
-
claimStakeRewards({ wallet }, options) {
|
|
184
|
+
claimStakeRewards({ wallet, collections, ranks, verifier }, options) {
|
|
183
185
|
return __awaiter(this, void 0, void 0, function* () {
|
|
184
186
|
const stakes = (yield this.getUserStakes(wallet)).sort((a, b) => a.claimedTs - b.claimedTs);
|
|
185
187
|
const ixs = [];
|
|
@@ -197,16 +199,20 @@ class Stake {
|
|
|
197
199
|
const stakeVaultPDA = (0, stake_1.getStakeVaultPDA)(this.program.programId, constants_1.STAKE_VAULT_NAME);
|
|
198
200
|
const stakePDA = (0, stake_1.getStakePDA)(this.program.programId, wallet, stake.name);
|
|
199
201
|
ixs.push(yield this.program.methods
|
|
200
|
-
.claimStakeRewards(
|
|
202
|
+
.claimStakeRewards({
|
|
203
|
+
collections,
|
|
204
|
+
rank: 963
|
|
205
|
+
})
|
|
201
206
|
.accounts({
|
|
202
207
|
signer: wallet,
|
|
203
208
|
mint: constants_1.TRD_MINT,
|
|
204
209
|
stake: stakePDA,
|
|
205
|
-
stakeVault: stakeVaultPDA
|
|
210
|
+
stakeVault: stakeVaultPDA,
|
|
211
|
+
verifier: constants_1.VERIFIER
|
|
206
212
|
})
|
|
207
213
|
.instruction());
|
|
208
214
|
}
|
|
209
|
-
return (0, sendVersionedTransaction_1.default)(this.provider, ixs, options);
|
|
215
|
+
return (0, sendVersionedTransaction_1.default)(this.provider, ixs, options, (0, convertSecretKeyToKeypair_1.convertSecretKeyToKeypair)(verifier));
|
|
210
216
|
});
|
|
211
217
|
}
|
|
212
218
|
}
|
package/dist/trade.d.ts
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import { AnchorProvider, Program } from '@coral-xyz/anchor';
|
|
2
2
|
import { TriadProtocol } from './types/triad_protocol';
|
|
3
3
|
import { PublicKey } from '@solana/web3.js';
|
|
4
|
-
import { InitializeMarketArgs,
|
|
4
|
+
import { InitializeMarketArgs, OpenOrderArgs, UserTrade } from './types/trade';
|
|
5
5
|
import { RpcOptions } from './types';
|
|
6
6
|
import BN from 'bn.js';
|
|
7
7
|
export default class Trade {
|
|
8
8
|
private program;
|
|
9
9
|
private provider;
|
|
10
|
-
mint: PublicKey;
|
|
11
|
-
decimals: number;
|
|
12
10
|
constructor(program: Program<TriadProtocol>, provider: AnchorProvider);
|
|
13
11
|
/**
|
|
14
12
|
* Get All Markets
|
|
@@ -27,21 +25,6 @@ export default class Trade {
|
|
|
27
25
|
*
|
|
28
26
|
*/
|
|
29
27
|
getUserOrders(user: PublicKey): Promise<import("./types/trade").Order[]>;
|
|
30
|
-
/**
|
|
31
|
-
* Get Orders By Market ID
|
|
32
|
-
* @param marketId - The ID of the market
|
|
33
|
-
*
|
|
34
|
-
*/
|
|
35
|
-
getLimitOrdersByMarketId(marketId: number): Promise<{
|
|
36
|
-
hype: {
|
|
37
|
-
bid: any[];
|
|
38
|
-
ask: any[];
|
|
39
|
-
};
|
|
40
|
-
flop: {
|
|
41
|
-
bid: any[];
|
|
42
|
-
ask: any[];
|
|
43
|
-
};
|
|
44
|
-
}>;
|
|
45
28
|
/**
|
|
46
29
|
* Get Market By ID
|
|
47
30
|
* @param marketId - The ID of the market
|
|
@@ -69,14 +52,13 @@ export default class Trade {
|
|
|
69
52
|
orders: {
|
|
70
53
|
ts: BN;
|
|
71
54
|
orderId: BN;
|
|
72
|
-
|
|
55
|
+
questionId: BN;
|
|
73
56
|
marketId: BN;
|
|
74
57
|
status: ({
|
|
75
58
|
open?: never;
|
|
76
59
|
closed?: never;
|
|
77
60
|
claimed?: never;
|
|
78
61
|
liquidated?: never;
|
|
79
|
-
waiting?: never;
|
|
80
62
|
} & {
|
|
81
63
|
init: Record<string, never>;
|
|
82
64
|
}) | ({
|
|
@@ -84,7 +66,6 @@ export default class Trade {
|
|
|
84
66
|
closed?: never;
|
|
85
67
|
claimed?: never;
|
|
86
68
|
liquidated?: never;
|
|
87
|
-
waiting?: never;
|
|
88
69
|
} & {
|
|
89
70
|
open: Record<string, never>;
|
|
90
71
|
}) | ({
|
|
@@ -92,7 +73,6 @@ export default class Trade {
|
|
|
92
73
|
open?: never;
|
|
93
74
|
claimed?: never;
|
|
94
75
|
liquidated?: never;
|
|
95
|
-
waiting?: never;
|
|
96
76
|
} & {
|
|
97
77
|
closed: Record<string, never>;
|
|
98
78
|
}) | ({
|
|
@@ -100,7 +80,6 @@ export default class Trade {
|
|
|
100
80
|
open?: never;
|
|
101
81
|
closed?: never;
|
|
102
82
|
liquidated?: never;
|
|
103
|
-
waiting?: never;
|
|
104
83
|
} & {
|
|
105
84
|
claimed: Record<string, never>;
|
|
106
85
|
}) | ({
|
|
@@ -108,21 +87,12 @@ export default class Trade {
|
|
|
108
87
|
open?: never;
|
|
109
88
|
closed?: never;
|
|
110
89
|
claimed?: never;
|
|
111
|
-
waiting?: never;
|
|
112
90
|
} & {
|
|
113
91
|
liquidated: Record<string, never>;
|
|
114
|
-
}) | ({
|
|
115
|
-
init?: never;
|
|
116
|
-
open?: never;
|
|
117
|
-
closed?: never;
|
|
118
|
-
claimed?: never;
|
|
119
|
-
liquidated?: never;
|
|
120
|
-
} & {
|
|
121
|
-
waiting: Record<string, never>;
|
|
122
92
|
});
|
|
123
93
|
price: BN;
|
|
124
|
-
|
|
125
|
-
|
|
94
|
+
totalAmount: BN;
|
|
95
|
+
totalShares: BN;
|
|
126
96
|
orderType: ({
|
|
127
97
|
limit?: never;
|
|
128
98
|
} & {
|
|
@@ -132,7 +102,7 @@ export default class Trade {
|
|
|
132
102
|
} & {
|
|
133
103
|
limit: Record<string, never>;
|
|
134
104
|
});
|
|
135
|
-
|
|
105
|
+
direction: ({
|
|
136
106
|
flop?: never;
|
|
137
107
|
} & {
|
|
138
108
|
hype: Record<string, never>;
|
|
@@ -142,16 +112,6 @@ export default class Trade {
|
|
|
142
112
|
flop: Record<string, never>;
|
|
143
113
|
});
|
|
144
114
|
userNonce: number;
|
|
145
|
-
orderSide: ({
|
|
146
|
-
ask?: never;
|
|
147
|
-
} & {
|
|
148
|
-
bid: Record<string, never>;
|
|
149
|
-
}) | ({
|
|
150
|
-
bid?: never;
|
|
151
|
-
} & {
|
|
152
|
-
ask: Record<string, never>;
|
|
153
|
-
});
|
|
154
|
-
linkedOrderId: BN;
|
|
155
115
|
padding: number[];
|
|
156
116
|
}[];
|
|
157
117
|
nonce: number;
|
|
@@ -160,7 +120,7 @@ export default class Trade {
|
|
|
160
120
|
padding: number[];
|
|
161
121
|
}>;
|
|
162
122
|
/**
|
|
163
|
-
*
|
|
123
|
+
* Initialize Market
|
|
164
124
|
* @param args.marketId - new markert id - length + 1
|
|
165
125
|
* @param args.startTime - start time
|
|
166
126
|
* @param args.endTime - end time
|
|
@@ -169,7 +129,7 @@ export default class Trade {
|
|
|
169
129
|
* @param options - RPC options
|
|
170
130
|
*
|
|
171
131
|
*/
|
|
172
|
-
|
|
132
|
+
initializeMarket({ marketId, startTime, endTime, question }: InitializeMarketArgs, options?: RpcOptions): Promise<string>;
|
|
173
133
|
/**
|
|
174
134
|
* Get User Trade Nonce With Slots
|
|
175
135
|
* @param userTrades - User Trades
|
|
@@ -177,20 +137,18 @@ export default class Trade {
|
|
|
177
137
|
*/
|
|
178
138
|
getUserTradeNonceWithSlots(userTrades: UserTrade[]): Promise<PublicKey>;
|
|
179
139
|
/**
|
|
180
|
-
*
|
|
140
|
+
* Open Order
|
|
181
141
|
* @param args.marketId - The ID of the Market
|
|
182
142
|
* @param args.amount - The amount of the Order
|
|
183
143
|
* @param args.direction - The direction of the Order
|
|
184
|
-
* @param args.
|
|
185
|
-
* @param args.mint - The mint of the Order
|
|
186
|
-
* @param args.price - The price of the Order
|
|
144
|
+
* @param args.token - The token to use for the Order
|
|
187
145
|
*
|
|
188
146
|
* @param options - RPC options
|
|
189
147
|
*
|
|
190
148
|
*/
|
|
191
|
-
|
|
149
|
+
openOrder({ marketId, amount, direction, token }: OpenOrderArgs, options?: RpcOptions): Promise<string>;
|
|
192
150
|
/**
|
|
193
|
-
*
|
|
151
|
+
* Close Order
|
|
194
152
|
* @param args.marketId - The ID of the Market
|
|
195
153
|
* @param args.orderId - The ID of the Order
|
|
196
154
|
* @param args.userNonce - The nonce of the user
|
|
@@ -198,11 +156,31 @@ export default class Trade {
|
|
|
198
156
|
* @param options - RPC options
|
|
199
157
|
*
|
|
200
158
|
*/
|
|
201
|
-
|
|
159
|
+
closeOrder({ marketId, orderId, userNonce }: {
|
|
202
160
|
marketId: number;
|
|
203
161
|
orderId: number;
|
|
204
162
|
userNonce: number;
|
|
205
163
|
}, options?: RpcOptions): Promise<string>;
|
|
164
|
+
/**
|
|
165
|
+
* Resolve Market
|
|
166
|
+
* @param args.marketId - The ID of the Market
|
|
167
|
+
* @param args.winningDirection - The Winning Direction of the Market
|
|
168
|
+
*
|
|
169
|
+
* @param options - RPC options
|
|
170
|
+
*
|
|
171
|
+
*/
|
|
172
|
+
resolveMarket({ marketId, winningDirection }: {
|
|
173
|
+
marketId: number;
|
|
174
|
+
winningDirection: {
|
|
175
|
+
hype: {};
|
|
176
|
+
} | {
|
|
177
|
+
flop: {};
|
|
178
|
+
} | {
|
|
179
|
+
none: {};
|
|
180
|
+
} | {
|
|
181
|
+
draw: {};
|
|
182
|
+
};
|
|
183
|
+
}, options?: RpcOptions): Promise<string>;
|
|
206
184
|
/**
|
|
207
185
|
* Collect Remaining Liquidity
|
|
208
186
|
* @param marketId - The ID of the market
|
|
@@ -245,44 +223,24 @@ export default class Trade {
|
|
|
245
223
|
* Update Market
|
|
246
224
|
* @param marketId - The ID of the market
|
|
247
225
|
* @param marketEnd - The end time of the market
|
|
248
|
-
* @param winningDirection - The winning direction of the market
|
|
249
|
-
*
|
|
250
|
-
* @param options - RPC options
|
|
251
|
-
*
|
|
252
|
-
*/
|
|
253
|
-
updateMarket({ marketId, marketEnd, winningDirection }: UpdateMarketArgs, options?: RpcOptions): Promise<string>;
|
|
254
|
-
/**
|
|
255
|
-
* Create Customer
|
|
256
|
-
* @param args.id - The ID of the customer
|
|
257
|
-
* @param args.name - The name of the customer
|
|
258
|
-
* @param args.authority - The authority of the customer
|
|
259
|
-
* @param args.shadowStorage - The shadow storage of the customer
|
|
260
226
|
*
|
|
261
227
|
* @param options - RPC options
|
|
262
228
|
*
|
|
263
229
|
*/
|
|
264
|
-
|
|
230
|
+
updateMarket(marketId: number, marketEnd: number, options?: RpcOptions): Promise<string>;
|
|
265
231
|
/**
|
|
266
|
-
*
|
|
267
|
-
* @param args.marketId - The ID of the Market
|
|
268
|
-
* @param args.amount - The amount of the Order
|
|
269
|
-
* @param args.direction - The direction of the Order
|
|
270
|
-
*
|
|
271
|
-
* @param options - RPC options
|
|
272
|
-
*
|
|
273
|
-
*/
|
|
274
|
-
openOrder({ marketId, amount, direction }: OpenOrderArgs, options?: RpcOptions): Promise<string>;
|
|
275
|
-
/**
|
|
276
|
-
* Close Order
|
|
232
|
+
* Force Cancel Order
|
|
277
233
|
* @param args.marketId - The ID of the Market
|
|
234
|
+
* @param args.user - The user to force cancel the order for
|
|
278
235
|
* @param args.orderId - The ID of the Order
|
|
279
236
|
* @param args.userNonce - The nonce of the user
|
|
280
237
|
*
|
|
281
238
|
* @param options - RPC options
|
|
282
239
|
*
|
|
283
240
|
*/
|
|
284
|
-
|
|
241
|
+
forceCancelOrder({ marketId, user, orderId, userNonce }: {
|
|
285
242
|
marketId: number;
|
|
243
|
+
user: PublicKey;
|
|
286
244
|
orderId: number;
|
|
287
245
|
userNonce: number;
|
|
288
246
|
}, options?: RpcOptions): Promise<string>;
|