@triadxyz/triad-protocol 3.1.5-beta → 3.1.7-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/claim.d.ts CHANGED
@@ -1,7 +1,8 @@
1
+ /// <reference types="@coral-xyz/anchor/node_modules/@solana/web3.js" />
1
2
  import { Program } from '@coral-xyz/anchor';
2
3
  import { PublicKey } from '@solana/web3.js';
3
4
  import { TriadProtocol } from './types/triad_protocol';
4
- import { RpcOptions, CreateClaimVaultArgs, ClaimTokenArgs, UpdateClaimVaultMerkleRootArgs, UpdateClaimVaultIsActiveArgs } from './types';
5
+ import { RpcOptions, CreateClaimVaultArgs, ClaimTokenArgs, UpdateClaimVaultMerkleRootArgs, UpdateClaimVaultIsActiveArgs, UpdateClaimVaultAmountArgs } from './types';
5
6
  export default class Claim {
6
7
  private program;
7
8
  private rpcOptions;
@@ -23,25 +24,36 @@ export default class Claim {
23
24
  getClaimedUser(claimVault: PublicKey, user: PublicKey): Promise<import("./types").ClaimedUser>;
24
25
  /**
25
26
  * Claim Token
27
+ * @param claimData - Claim data
28
+ * @param claimVaultName - Vault name
29
+ * @param payer - Payer
30
+ * @param mint - Mint
26
31
  * @param amount - Amount to claim
27
- * @param merkleProof - Merkle proof
28
32
  */
29
- claimToken({ amount, merkleProof, mint, claimVault }: ClaimTokenArgs): Promise<string>;
33
+ claimToken({ mint, claimVaultName, claimData, amount, isFirstComeFirstServed }: ClaimTokenArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
30
34
  /**
31
35
  * Create Claim Vault
32
36
  * @param args - Create Claim Vault Args
33
37
  */
34
- createClaimVault({ totalAmount, totalUsers, name, isFirstComeFirstServed, endTs, merkleRoot, mint }: CreateClaimVaultArgs): Promise<string>;
38
+ createClaimVault({ totalAmount, totalUsers, name, isFirstComeFirstServed, endTs, claimData, mint }: CreateClaimVaultArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
35
39
  /**
36
40
  * Update Claim Vault Is Active
37
41
  * @param isActive - Is active
38
42
  * @param claimVault - Claim vault
39
43
  */
40
- updateClaimVaultIsActive({ isActive, claimVault }: UpdateClaimVaultIsActiveArgs): Promise<string>;
44
+ updateClaimVaultIsActive({ isActive, claimVaultName }: UpdateClaimVaultIsActiveArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
41
45
  /**
42
46
  * Update Claim Vault Merkle Root
43
47
  * @param merkleRoot - Merkle root
44
48
  * @param claimVault - Claim vault
45
49
  */
46
- updateClaimVaultMerkleRoot({ merkleRoot, claimVault }: UpdateClaimVaultMerkleRootArgs): Promise<string>;
50
+ updateClaimVaultMerkleRoot({ merkleRoot, claimVaultName }: UpdateClaimVaultMerkleRootArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
51
+ /**
52
+ * Update Claim Vault Amount
53
+ * @param amount - Amount to add
54
+ * @param newUsers - New users to add
55
+ * @param claimVaultName - Claim vault name
56
+ * @param mint - Mint
57
+ */
58
+ updateClaimVaultAmount({ amount, newUsers, claimVaultName, mint }: UpdateClaimVaultAmountArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
47
59
  }
package/dist/claim.js CHANGED
@@ -16,6 +16,7 @@ const anchor_1 = require("@coral-xyz/anchor");
16
16
  const helpers_1 = require("./utils/helpers");
17
17
  const sendVersionedTransaction_1 = __importDefault(require("./utils/sendVersionedTransaction"));
18
18
  const pda_1 = require("./utils/pda");
19
+ const merkle_1 = require("./utils/merkle");
19
20
  class Claim {
20
21
  constructor(program, rpcOptions) {
21
22
  this.program = program;
@@ -55,21 +56,32 @@ class Claim {
55
56
  }
56
57
  /**
57
58
  * Claim Token
59
+ * @param claimData - Claim data
60
+ * @param claimVaultName - Vault name
61
+ * @param payer - Payer
62
+ * @param mint - Mint
58
63
  * @param amount - Amount to claim
59
- * @param merkleProof - Merkle proof
60
64
  */
61
- claimToken({ amount, merkleProof, mint, claimVault }) {
65
+ claimToken({ mint, claimVaultName, claimData, amount, isFirstComeFirstServed }) {
66
+ var _a;
62
67
  return __awaiter(this, void 0, void 0, function* () {
68
+ let proof = [];
69
+ if (!isFirstComeFirstServed) {
70
+ const { proofs } = (0, merkle_1.generateMerkleTree)(claimData);
71
+ proof = (_a = proofs.find((p) => p.user.toBase58() === this.program.provider.publicKey.toBase58())) === null || _a === void 0 ? void 0 : _a.proof;
72
+ }
63
73
  const ixs = [
64
74
  yield this.program.methods
65
75
  .claimToken({
66
- amount: new anchor_1.BN(amount),
67
- merkleProof
76
+ amount: new anchor_1.BN(amount * Math.pow(10, 6)),
77
+ merkleProof: proof
68
78
  })
69
79
  .accounts({
70
80
  signer: this.program.provider.publicKey,
81
+ payer: this.rpcOptions.payer,
71
82
  mint,
72
- claimVault
83
+ claimVault: (0, pda_1.getClaimVaultPDA)(this.program.programId, claimVaultName),
84
+ tokenProgram: (0, helpers_1.getTokenProgram)(mint)
73
85
  })
74
86
  .instruction()
75
87
  ];
@@ -80,12 +92,13 @@ class Claim {
80
92
  * Create Claim Vault
81
93
  * @param args - Create Claim Vault Args
82
94
  */
83
- createClaimVault({ totalAmount, totalUsers, name, isFirstComeFirstServed, endTs, merkleRoot, mint }) {
95
+ createClaimVault({ totalAmount, totalUsers, name, isFirstComeFirstServed, endTs, claimData, mint }) {
84
96
  return __awaiter(this, void 0, void 0, function* () {
97
+ const { merkleRoot } = (0, merkle_1.generateMerkleTree)(claimData);
85
98
  const ixs = [
86
99
  yield this.program.methods
87
100
  .createClaimVault({
88
- totalAmount: new anchor_1.BN(totalAmount),
101
+ totalAmount: new anchor_1.BN(totalAmount * Math.pow(10, 6)),
89
102
  totalUsers: new anchor_1.BN(totalUsers),
90
103
  name,
91
104
  isFirstComeFirstServed,
@@ -94,7 +107,8 @@ class Claim {
94
107
  })
95
108
  .accounts({
96
109
  signer: this.program.provider.publicKey,
97
- mint
110
+ mint,
111
+ tokenProgram: (0, helpers_1.getTokenProgram)(mint)
98
112
  })
99
113
  .instruction()
100
114
  ];
@@ -106,14 +120,14 @@ class Claim {
106
120
  * @param isActive - Is active
107
121
  * @param claimVault - Claim vault
108
122
  */
109
- updateClaimVaultIsActive({ isActive, claimVault }) {
123
+ updateClaimVaultIsActive({ isActive, claimVaultName }) {
110
124
  return __awaiter(this, void 0, void 0, function* () {
111
125
  const ixs = [
112
126
  yield this.program.methods
113
127
  .updateClaimVaultIsActive(isActive)
114
128
  .accounts({
115
129
  signer: this.program.provider.publicKey,
116
- claimVault
130
+ claimVault: (0, pda_1.getClaimVaultPDA)(this.program.programId, claimVaultName)
117
131
  })
118
132
  .instruction()
119
133
  ];
@@ -125,14 +139,40 @@ class Claim {
125
139
  * @param merkleRoot - Merkle root
126
140
  * @param claimVault - Claim vault
127
141
  */
128
- updateClaimVaultMerkleRoot({ merkleRoot, claimVault }) {
142
+ updateClaimVaultMerkleRoot({ merkleRoot, claimVaultName }) {
129
143
  return __awaiter(this, void 0, void 0, function* () {
130
144
  const ixs = [
131
145
  yield this.program.methods
132
146
  .updateClaimVaultMerkleRoot(merkleRoot)
133
147
  .accounts({
134
148
  signer: this.program.provider.publicKey,
135
- claimVault
149
+ claimVault: (0, pda_1.getClaimVaultPDA)(this.program.programId, claimVaultName)
150
+ })
151
+ .instruction()
152
+ ];
153
+ return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
154
+ });
155
+ }
156
+ /**
157
+ * Update Claim Vault Amount
158
+ * @param amount - Amount to add
159
+ * @param newUsers - New users to add
160
+ * @param claimVaultName - Claim vault name
161
+ * @param mint - Mint
162
+ */
163
+ updateClaimVaultAmount({ amount, newUsers, claimVaultName, mint }) {
164
+ return __awaiter(this, void 0, void 0, function* () {
165
+ const ixs = [
166
+ yield this.program.methods
167
+ .updateClaimVaultAmount({
168
+ amount: new anchor_1.BN(amount * Math.pow(10, 6)),
169
+ newUsers: new anchor_1.BN(newUsers)
170
+ })
171
+ .accounts({
172
+ signer: this.program.provider.publicKey,
173
+ mint,
174
+ tokenProgram: (0, helpers_1.getTokenProgram)(mint),
175
+ claimVault: (0, pda_1.getClaimVaultPDA)(this.program.programId, claimVaultName)
136
176
  })
137
177
  .instruction()
138
178
  ];
package/dist/index.d.ts CHANGED
@@ -1,12 +1,16 @@
1
+ /// <reference types="@coral-xyz/anchor/node_modules/@solana/web3.js" />
1
2
  import { Connection, PublicKey, TransactionInstruction } from '@solana/web3.js';
2
3
  import { AnchorProvider, Program, Wallet } from '@coral-xyz/anchor';
3
4
  import BN from 'bn.js';
4
5
  import { TriadProtocol } from './types/triad_protocol';
5
- import { CreateMarketArgs, OpenOrderArgs, UserTrade, CreateCustomerArgs, MarketBidOrderArgs, CancelBidOrderArgs, CancelAskOrderArgs, PlaceBidOrderArgs, PlaceAskOrderArgs, CollectMarketFeeArgs, CreatePoolArgs, BookOrder, MarketAskOrderArgs, RpcOptions, OrderDirection } from './types';
6
+ import { OpenOrderArgs, UserTrade, CreateCustomerArgs, MarketBidOrderArgs, CancelBidOrderArgs, CancelAskOrderArgs, PlaceBidOrderArgs, PlaceAskOrderArgs, BookOrder, MarketAskOrderArgs, RpcOptions, OrderDirection, CloseOrderArgs } from './types';
6
7
  import Stake from './stake';
7
8
  import Poseidon from './poseidon';
9
+ import Claim from './claim';
10
+ import Market from './market';
8
11
  export * from './types';
9
12
  export * from './utils/helpers';
13
+ export * from './utils/merkle';
10
14
  export default class TriadProtocolClient {
11
15
  private connection;
12
16
  private wallet;
@@ -15,15 +19,9 @@ export default class TriadProtocolClient {
15
19
  provider: AnchorProvider;
16
20
  stake: Stake;
17
21
  poseidon: Poseidon;
22
+ claim: Claim;
23
+ market: Market;
18
24
  constructor(connection: Connection, wallet: Wallet, rpcOptions: RpcOptions);
19
- /**
20
- * Get All Pools
21
- */
22
- getAllPools(): Promise<import("./types").Pool[]>;
23
- /**
24
- * Get All Markets
25
- */
26
- getAllMarkets(): Promise<import("./types").Market[]>;
27
25
  /**
28
26
  * Get My User Trades from a user authority
29
27
  * @param wallet - User wallet PublicKey
@@ -44,21 +42,6 @@ export default class TriadProtocolClient {
44
42
  * Get User Book Orders
45
43
  */
46
44
  getUserBookOrders(wallet: PublicKey, marketId: number): Promise<BookOrder[]>;
47
- /**
48
- * Get Pool By ID
49
- * @param poolId - The ID of the pool
50
- */
51
- getPoolById(poolId: number): Promise<import("./types").Pool>;
52
- /**
53
- * Get Market By ID
54
- * @param marketId - The ID of the market
55
- */
56
- getMarketById(marketId: number): Promise<import("./types").Market>;
57
- /**
58
- * Get Market By Address
59
- * @param marketAddress - The address of the market
60
- */
61
- getMarketByAddress(marketAddress: PublicKey): Promise<import("./types").Market>;
62
45
  /**
63
46
  * Get Costumer By Wallet Address
64
47
  * @param wallet - The wallet address of the customer
@@ -69,18 +52,6 @@ export default class TriadProtocolClient {
69
52
  * @param customerId - The ID of the customer
70
53
  */
71
54
  getCustomerById(customerId: number): Promise<import("./types").Customer>;
72
- /**
73
- * Get Current Market ID
74
- */
75
- nextMarketId(): Promise<number>;
76
- /**
77
- * Get Next Customer ID
78
- */
79
- nextCustomerId(): Promise<number>;
80
- /**
81
- * Get Next Pool ID
82
- */
83
- nextPoolId(): Promise<number>;
84
55
  /**
85
56
  * Get User Trade PDA
86
57
  * @param wallet - User wallet PublicKey
@@ -92,7 +63,7 @@ export default class TriadProtocolClient {
92
63
  * @param wallet - User wallet PublicKey
93
64
  * @param userNonce - The nonce of the user
94
65
  */
95
- getUserTrade(wallet: PublicKey, userNonce?: number): Promise<{
66
+ getUserTradeByNonce(wallet: PublicKey, userNonce?: number): Promise<{
96
67
  bump: number;
97
68
  authority: PublicKey;
98
69
  padding1: number[];
@@ -194,26 +165,6 @@ export default class TriadProtocolClient {
194
165
  poseidon: number;
195
166
  padding: number[];
196
167
  }>;
197
- /**
198
- * Create Market
199
- * @param args.markets - Array of markets to create
200
- * @param args.markets.marketId - Market ID
201
- * @param args.markets.startTime - start time
202
- * @param args.markets.endTime - end time
203
- * @param args.markets.question - question (max 80 characters)
204
- * @param args.markets.liquidityAtStart - liquidity at start
205
- * @param args.markets.payoutFee - payout fee (to add affiliate system)
206
- * @param args.customer - The customer of the market
207
- * @param args.poolId - The ID of the pool
208
- */
209
- createMarket({ markets, customer, poolId }: CreateMarketArgs): Promise<string>;
210
- /**
211
- * Create Pool
212
- * @param poolId - The ID of the pool
213
- * @param question - The question of the pool
214
- * @param markets - The markets of the pool
215
- */
216
- createPool({ poolId, question, markets, customer, startTime, endTime, feeBps, payoutFee, isFast }: CreatePoolArgs): Promise<string>;
217
168
  /**
218
169
  * Open Order
219
170
  * @param args.marketId - The ID of the Market
@@ -222,37 +173,14 @@ export default class TriadProtocolClient {
222
173
  * @param args.mint - The mint of the Order
223
174
  * @param args.token - The token to use for the Order
224
175
  */
225
- openOrder({ marketId, amount, direction, mint, token }: OpenOrderArgs): Promise<string>;
176
+ openOrder({ marketId, amount, direction, mint, token }: OpenOrderArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
226
177
  /**
227
178
  * Close Order
228
179
  * @param args.marketId - The ID of the Market
229
180
  * @param args.orderId - The ID of the Order
230
181
  * @param args.userNonce - The nonce of the user
231
182
  */
232
- closeOrder({ marketId, orderId, userNonce }: {
233
- marketId: number;
234
- orderId: number;
235
- userNonce: number;
236
- }): Promise<string>;
237
- /**
238
- * Resolve Market
239
- * @param args.marketId - The ID of the Market
240
- * @param args.poolId - The ID of the Pool
241
- * @param args.winningDirection - The Winning Direction of the Market
242
- */
243
- updateMarketWinningDirection({ marketId, poolId, winningDirection }: {
244
- marketId: number;
245
- poolId?: number;
246
- winningDirection: {
247
- hype: {};
248
- } | {
249
- flop: {};
250
- } | {
251
- none: {};
252
- } | {
253
- draw: {};
254
- };
255
- }): Promise<string>;
183
+ closeOrder({ marketId, orderId, userNonce }: CloseOrderArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
256
184
  /**
257
185
  * Payout Order
258
186
  * @param args.marketId - The ID of the Market
@@ -265,41 +193,12 @@ export default class TriadProtocolClient {
265
193
  orderId: number;
266
194
  userNonce: number;
267
195
  mint: PublicKey;
268
- }[]): Promise<string>;
269
- /**
270
- * Update Market Payout
271
- * @param marketId - The ID of the market
272
- * @param poolId - The ID of the pool
273
- * @param allowPayout - Whether to allow the market to payout
274
- */
275
- updateMarketPayout({ marketId, poolId, allowPayout }: {
276
- marketId: number;
277
- poolId?: number;
278
- allowPayout: boolean;
279
- }): Promise<string>;
196
+ }[]): Promise<string | import("@solana/web3.js").VersionedTransaction>;
280
197
  /**
281
198
  * Create Sub User Trade
282
199
  * @param user - User PublicKey the main user
283
200
  */
284
- createSubUserTrade(user: PublicKey): Promise<string>;
285
- /**
286
- * Update Market End
287
- * @param marketId - The ID of the market
288
- * @param marketEnd - The end time of the market
289
- */
290
- updateMarketEnd({ marketId, marketEnd }: {
291
- marketId: number;
292
- marketEnd: number;
293
- }): Promise<string>;
294
- /**
295
- * Update Market Question
296
- * @param marketId - The ID of the market
297
- * @param question - The question of the market
298
- */
299
- updateMarketQuestion({ marketId, question }: {
300
- marketId: number;
301
- question: string;
302
- }): Promise<string>;
201
+ createSubUserTrade(user: PublicKey): Promise<string | import("@solana/web3.js").VersionedTransaction>;
303
202
  /**
304
203
  * Create Customer
305
204
  * @param args.id - The ID of the customer
@@ -307,12 +206,7 @@ export default class TriadProtocolClient {
307
206
  * @param args.authority - The authority of the customer
308
207
  * @param args.feeRecipient - The fee recipient of the customer
309
208
  */
310
- createCustomer({ id, name, authority, feeRecipient }: CreateCustomerArgs): Promise<string>;
311
- /**
312
- * Get User Trade Nonce With Slots
313
- * @param userTrades - User Trades
314
- */
315
- getUserTradeNonceWithSlots(userTrades: UserTrade[]): PublicKey;
209
+ createCustomer({ id, name, authority, feeRecipient }: CreateCustomerArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
316
210
  /**
317
211
  * Get User Trade Ixs
318
212
  */
@@ -344,7 +238,7 @@ export default class TriadProtocolClient {
344
238
  * @param args.mint - The mint of the Order
345
239
  * @param args.isTrdPayout - Whether to payout in TRD or not
346
240
  */
347
- placeBidOrder({ marketId, orders, isTrdPayout }: PlaceBidOrderArgs): Promise<string>;
241
+ placeBidOrder({ marketId, orders, isTrdPayout }: PlaceBidOrderArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
348
242
  /**
349
243
  * Place Ask Order
350
244
  * @param args.marketId - The ID of the Market
@@ -354,7 +248,7 @@ export default class TriadProtocolClient {
354
248
  * @param args.orders.bidOrderId - The ID of the Bid Order
355
249
  * @param args.orders.bidNonce - The nonce of the Bid Order
356
250
  */
357
- placeAskOrder({ marketId, orders }: PlaceAskOrderArgs): Promise<string>;
251
+ placeAskOrder({ marketId, orders }: PlaceAskOrderArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
358
252
  /**
359
253
  * Cancel Bid Order
360
254
  * @param args.marketId - The ID of the Market
@@ -362,7 +256,7 @@ export default class TriadProtocolClient {
362
256
  * @param args.orders.userNonce - The nonce of the user
363
257
  * @param args.orders.orderDirection - The direction of the Order
364
258
  */
365
- cancelBidOrder({ marketId, orders }: CancelBidOrderArgs): Promise<string>;
259
+ cancelBidOrder({ marketId, orders }: CancelBidOrderArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
366
260
  /**
367
261
  * Cancel Ask Order
368
262
  * @param args.marketId - The ID of the Market
@@ -370,16 +264,15 @@ export default class TriadProtocolClient {
370
264
  * @param args.orders.userNonce - The nonce of the user
371
265
  * @param args.orders.orderDirection - The direction of the Order
372
266
  */
373
- cancelAskOrder({ marketId, orders }: CancelAskOrderArgs): Promise<string>;
267
+ cancelAskOrder({ marketId, orders }: CancelAskOrderArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
374
268
  /**
375
269
  * Market Bid Order
376
270
  * @param args.marketId - The ID of the Market
377
271
  * @param args.amount - The amount of the Order
378
272
  * @param args.orderDirection - The direction of the Order
379
- * @param args.feeBps - The fee in basis points
380
273
  * @param args.isTrdPayout - Whether to payout in TRD or not
381
274
  */
382
- marketBidOrder({ marketId, amount, orderDirection, feeBps, isTrdPayout }: MarketBidOrderArgs): Promise<string>;
275
+ marketBidOrder({ marketId, amount, orderDirection, isTrdPayout }: MarketBidOrderArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
383
276
  /**
384
277
  * Market Ask Order
385
278
  * @param args.marketId - The ID of the Market
@@ -391,7 +284,7 @@ export default class TriadProtocolClient {
391
284
  * @param args.isTrdPayout - Whether to payout in TRD or not
392
285
  * @param args.feeBps - The fee in basis points
393
286
  */
394
- marketAskOrder({ marketId, orders, orderDirection, isTrdPayout, feeBps }: MarketAskOrderArgs): Promise<string>;
287
+ marketAskOrder({ marketId, orders, orderDirection, isTrdPayout, feeBps }: MarketAskOrderArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
395
288
  /**
396
289
  * Get Orders By Market ID
397
290
  * @param marketId - Market ID
@@ -410,30 +303,6 @@ export default class TriadProtocolClient {
410
303
  ask: BookOrder[];
411
304
  };
412
305
  }>;
413
- /**
414
- * Collect Market Fee
415
- * @param args.markets - The markets to collect the fee from
416
- * @param args.markets.marketAddress - The address of the market
417
- * @param args.markets.customerId - The ID of the customer
418
- * @param args.markets.customerFeeRecipient - The address of the customer fee recipient
419
- */
420
- collectMarketFee({ markets }: CollectMarketFeeArgs): Promise<string>;
421
- /**
422
- * Collect Market Order Fee
423
- * @param marketAddress - The address of the market
424
- */
425
- collectMarketOrderFee(marketAddress: PublicKey[]): Promise<string>;
426
- /**
427
- * Close Order Book
428
- * @param marketIds - Market IDs
429
- */
430
- closeOrderBook(marketIds: number[]): Promise<string>;
431
- /**
432
- * Update Pool Question
433
- * @param poolId - Pool ID
434
- * @param question - Question
435
- */
436
- updatePoolQuestion(poolId: number, question: string): Promise<string>;
437
306
  /**
438
307
  * Update Customer Fee
439
308
  * @param customerId - Customer ID
@@ -442,5 +311,5 @@ export default class TriadProtocolClient {
442
311
  updateCustomerFee({ customerId, feeBps }: {
443
312
  customerId: number;
444
313
  feeBps: number;
445
- }): Promise<string>;
314
+ }): Promise<string | import("@solana/web3.js").VersionedTransaction>;
446
315
  }