@triadxyz/triad-protocol 4.1.7 → 4.1.8

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 CHANGED
@@ -119,7 +119,7 @@ export default class TriadProtocol {
119
119
  * @param args.poolId - The ID of the Pool
120
120
  * @param args.withPayout - Whether to allow the market to payout
121
121
  */
122
- updateMarketWinningDirection({ marketId, winningDirection, poolId, withPayout }: UpdateMarketWinningDirectionArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
122
+ updateMarketWinningDirection({ markets }: UpdateMarketWinningDirectionArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
123
123
  /**
124
124
  * Update Market Payout
125
125
  * @param args.marketId - The ID of the market
@@ -159,6 +159,17 @@ export default class TriadProtocol {
159
159
  id: number;
160
160
  authority: PublicKey;
161
161
  }[]): Promise<string | import("@solana/web3.js").VersionedTransaction>;
162
+ /**
163
+ * Close IDLE Market
164
+ * @param markets.id - Market ID
165
+ * @param markets.authority - Market authority
166
+ * @param markets.mint - Market mint
167
+ */
168
+ closeIdleMarket(markets: {
169
+ id: number;
170
+ authority: PublicKey;
171
+ mint: PublicKey;
172
+ }[]): Promise<string | import("@solana/web3.js").VersionedTransaction>;
162
173
  /**
163
174
  * Update Pool Question
164
175
  * @param poolId - Pool ID
@@ -173,7 +184,7 @@ export default class TriadProtocol {
173
184
  * @param args.customer - The customer of the market
174
185
  * @param args.poolId - The ID of the pool
175
186
  */
176
- createMarketPyth({ marketId, resolveIn, customer, poolId, feedId, direction }: CreateMarketPythArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
187
+ createMarketPyth({ markets }: CreateMarketPythArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
177
188
  /**
178
189
  * Burn Triad
179
190
  * @param amount - Amount to burn
package/dist/index.js CHANGED
@@ -198,8 +198,17 @@ class TriadProtocol {
198
198
  */
199
199
  nextMarketId() {
200
200
  return __awaiter(this, void 0, void 0, function* () {
201
- const markets = yield this.program.account.marketV2.all();
202
- return markets.length + 10;
201
+ let validId = null;
202
+ while (!validId) {
203
+ const marketId = Math.floor(Math.random() * 1000000000000000);
204
+ try {
205
+ yield this.program.account.marketV2.fetch((0, pda_1.getMarketPDA)(this.program.programId, marketId));
206
+ }
207
+ catch (_a) {
208
+ validId = marketId;
209
+ }
210
+ }
211
+ return validId;
203
212
  });
204
213
  }
205
214
  /**
@@ -342,26 +351,29 @@ class TriadProtocol {
342
351
  * @param args.poolId - The ID of the Pool
343
352
  * @param args.withPayout - Whether to allow the market to payout
344
353
  */
345
- updateMarketWinningDirection({ marketId, winningDirection, poolId, withPayout = false }) {
354
+ updateMarketWinningDirection({ markets }) {
346
355
  return __awaiter(this, void 0, void 0, function* () {
347
- const ixs = [
348
- yield this.program.methods
349
- .updateMarketWinningDirection(winningDirection)
350
- .accounts({
351
- signer: this.program.provider.publicKey,
352
- market: (0, pda_1.getMarketPDA)(this.program.programId, marketId),
353
- pool: poolId ? (0, pda_1.getPoolPDA)(this.program.programId, poolId) : null
354
- })
355
- .instruction()
356
- ];
357
- if (withPayout) {
356
+ const ixs = [];
357
+ for (const market of markets) {
358
358
  ixs.push(yield this.program.methods
359
- .updateMarketPayout(true)
359
+ .updateMarketWinningDirection(market.winningDirection)
360
360
  .accounts({
361
361
  signer: this.program.provider.publicKey,
362
- market: (0, pda_1.getMarketPDA)(this.program.programId, marketId)
362
+ market: (0, pda_1.getMarketPDA)(this.program.programId, market.marketId),
363
+ pool: market.poolId
364
+ ? (0, pda_1.getPoolPDA)(this.program.programId, market.poolId)
365
+ : null
363
366
  })
364
367
  .instruction());
368
+ if (market.withPayout) {
369
+ ixs.push(yield this.program.methods
370
+ .updateMarketPayout(true)
371
+ .accounts({
372
+ signer: this.program.provider.publicKey,
373
+ market: (0, pda_1.getMarketPDA)(this.program.programId, market.marketId)
374
+ })
375
+ .instruction());
376
+ }
365
377
  }
366
378
  return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
367
379
  });
@@ -468,6 +480,28 @@ class TriadProtocol {
468
480
  return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
469
481
  });
470
482
  }
483
+ /**
484
+ * Close IDLE Market
485
+ * @param markets.id - Market ID
486
+ * @param markets.authority - Market authority
487
+ * @param markets.mint - Market mint
488
+ */
489
+ closeIdleMarket(markets) {
490
+ return __awaiter(this, void 0, void 0, function* () {
491
+ const ixs = [];
492
+ for (const market of markets) {
493
+ ixs.push(yield this.program.methods
494
+ .closeIdleMarket(new bn_js_1.default(market.id))
495
+ .accounts({
496
+ signer: this.program.provider.publicKey,
497
+ mint: market.mint,
498
+ tokenProgram: (0, helpers_1.getTokenProgram)(market.mint)
499
+ })
500
+ .instruction());
501
+ }
502
+ return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
503
+ });
504
+ }
471
505
  /**
472
506
  * Update Pool Question
473
507
  * @param poolId - Pool ID
@@ -495,32 +529,34 @@ class TriadProtocol {
495
529
  * @param args.customer - The customer of the market
496
530
  * @param args.poolId - The ID of the pool
497
531
  */
498
- createMarketPyth({ marketId, resolveIn, customer, poolId, feedId, direction }) {
532
+ createMarketPyth({ markets }) {
499
533
  return __awaiter(this, void 0, void 0, function* () {
500
534
  const ixs = [];
501
- let poolPDA = (0, pda_1.getPoolPDA)(this.program.programId, poolId);
502
- const feedPDA = (0, helpers_2.getPriceFeedAccountForProgram)(feedId);
503
- ixs.push(yield this.program.methods
504
- .createMarketPyth({
505
- marketId: new bn_js_1.default(marketId),
506
- resolveIn: new bn_js_1.default(resolveIn),
507
- direction
508
- })
509
- .accounts({
510
- signer: this.program.provider.publicKey,
511
- tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
512
- pool: poolPDA,
513
- customer,
514
- priceUpdate: feedPDA
515
- })
516
- .instruction());
517
- ixs.push(yield this.program.methods
518
- .createOrderBook(new bn_js_1.default(marketId))
519
- .accounts({
520
- signer: this.program.provider.publicKey,
521
- market: (0, pda_1.getMarketPDA)(this.program.programId, marketId)
522
- })
523
- .instruction());
535
+ for (const market of markets) {
536
+ let poolPDA = (0, pda_1.getPoolPDA)(this.program.programId, market.poolId);
537
+ const feedPDA = (0, helpers_2.getPriceFeedAccountForProgram)(market.feedId);
538
+ ixs.push(yield this.program.methods
539
+ .createMarketPyth({
540
+ marketId: new bn_js_1.default(market.marketId),
541
+ resolveIn: new bn_js_1.default(market.resolveIn),
542
+ direction: market.direction
543
+ })
544
+ .accounts({
545
+ signer: this.program.provider.publicKey,
546
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
547
+ pool: poolPDA,
548
+ customer: market.customer,
549
+ priceUpdate: feedPDA
550
+ })
551
+ .instruction());
552
+ ixs.push(yield this.program.methods
553
+ .createOrderBook(new bn_js_1.default(market.marketId))
554
+ .accounts({
555
+ signer: this.program.provider.publicKey,
556
+ market: (0, pda_1.getMarketPDA)(this.program.programId, market.marketId)
557
+ })
558
+ .instruction());
559
+ }
524
560
  return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
525
561
  });
526
562
  }
@@ -474,6 +474,129 @@
474
474
  ],
475
475
  "args": []
476
476
  },
477
+ {
478
+ "name": "close_idle_market",
479
+ "discriminator": [249, 217, 214, 137, 20, 38, 112, 154],
480
+ "accounts": [
481
+ {
482
+ "name": "signer",
483
+ "writable": true,
484
+ "signer": true
485
+ },
486
+ {
487
+ "name": "squads",
488
+ "writable": true,
489
+ "address": "Hk1r2NUL4LbUhx1agg1w44tyZiNr72mbeLsg6suF5MA4"
490
+ },
491
+ {
492
+ "name": "market",
493
+ "writable": true,
494
+ "pda": {
495
+ "seeds": [
496
+ {
497
+ "kind": "const",
498
+ "value": [109, 97, 114, 107, 101, 116]
499
+ },
500
+ {
501
+ "kind": "arg",
502
+ "path": "market_id"
503
+ }
504
+ ]
505
+ }
506
+ },
507
+ {
508
+ "name": "mint"
509
+ },
510
+ {
511
+ "name": "market_to_ata",
512
+ "writable": true,
513
+ "pda": {
514
+ "seeds": [
515
+ {
516
+ "kind": "account",
517
+ "path": "market"
518
+ },
519
+ {
520
+ "kind": "account",
521
+ "path": "token_program"
522
+ },
523
+ {
524
+ "kind": "account",
525
+ "path": "mint"
526
+ }
527
+ ],
528
+ "program": {
529
+ "kind": "const",
530
+ "value": [
531
+ 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142,
532
+ 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216,
533
+ 219, 233, 248, 89
534
+ ]
535
+ }
536
+ }
537
+ },
538
+ {
539
+ "name": "squads_ata",
540
+ "writable": true,
541
+ "pda": {
542
+ "seeds": [
543
+ {
544
+ "kind": "account",
545
+ "path": "squads"
546
+ },
547
+ {
548
+ "kind": "account",
549
+ "path": "token_program"
550
+ },
551
+ {
552
+ "kind": "account",
553
+ "path": "mint"
554
+ }
555
+ ],
556
+ "program": {
557
+ "kind": "const",
558
+ "value": [
559
+ 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142,
560
+ 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216,
561
+ 219, 233, 248, 89
562
+ ]
563
+ }
564
+ }
565
+ },
566
+ {
567
+ "name": "order_book",
568
+ "pda": {
569
+ "seeds": [
570
+ {
571
+ "kind": "const",
572
+ "value": [111, 114, 100, 101, 114, 95, 98, 111, 111, 107]
573
+ },
574
+ {
575
+ "kind": "arg",
576
+ "path": "market_id"
577
+ }
578
+ ]
579
+ }
580
+ },
581
+ {
582
+ "name": "token_program"
583
+ },
584
+ {
585
+ "name": "associated_token_program",
586
+ "address": "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
587
+ },
588
+ {
589
+ "name": "system_program",
590
+ "address": "11111111111111111111111111111111"
591
+ }
592
+ ],
593
+ "args": [
594
+ {
595
+ "name": "market_id",
596
+ "type": "u64"
597
+ }
598
+ ]
599
+ },
477
600
  {
478
601
  "name": "close_order_book",
479
602
  "discriminator": [219, 134, 73, 219, 180, 7, 94, 206],
@@ -2591,6 +2714,16 @@
2591
2714
  "code": 6027,
2592
2715
  "name": "InvalidQuestion",
2593
2716
  "msg": "Invalid Question"
2717
+ },
2718
+ {
2719
+ "code": 6028,
2720
+ "name": "MarketNotIdle",
2721
+ "msg": "Market Not Idle"
2722
+ },
2723
+ {
2724
+ "code": 6029,
2725
+ "name": "OrderBookStillExists",
2726
+ "msg": "Order Book still exists"
2594
2727
  }
2595
2728
  ],
2596
2729
  "types": [
@@ -156,12 +156,14 @@ export type CreateMarketArgs = {
156
156
  poolId?: number;
157
157
  };
158
158
  export type CreateMarketPythArgs = {
159
- marketId: number;
160
- resolveIn: number;
161
- customer: PublicKey;
162
- poolId: number;
163
- feedId: string;
164
- direction: 'Above' | 'Below';
159
+ markets: {
160
+ marketId: number;
161
+ resolveIn: number;
162
+ customer: PublicKey;
163
+ poolId: number;
164
+ feedId: string;
165
+ direction: 'Above' | 'Below';
166
+ }[];
165
167
  };
166
168
  export type CreatePoolArgs = {
167
169
  poolId: number;
@@ -180,10 +182,12 @@ export type CreatePoolArgs = {
180
182
  feedId?: string;
181
183
  };
182
184
  export type UpdateMarketWinningDirectionArgs = {
183
- marketId: number;
184
- winningDirection: WinningDirectionEncoded;
185
- poolId?: number;
186
- withPayout?: boolean;
185
+ markets: {
186
+ marketId: number;
187
+ winningDirection: WinningDirectionEncoded;
188
+ poolId?: number;
189
+ withPayout?: boolean;
190
+ }[];
187
191
  };
188
192
  export type UpdateMarketPayoutArgs = {
189
193
  marketId: number;
@@ -707,6 +707,187 @@ export type TriadProtocol = {
707
707
  ];
708
708
  args: [];
709
709
  },
710
+ {
711
+ name: 'closeIdleMarket';
712
+ discriminator: [249, 217, 214, 137, 20, 38, 112, 154];
713
+ accounts: [
714
+ {
715
+ name: 'signer';
716
+ writable: true;
717
+ signer: true;
718
+ },
719
+ {
720
+ name: 'squads';
721
+ writable: true;
722
+ address: 'Hk1r2NUL4LbUhx1agg1w44tyZiNr72mbeLsg6suF5MA4';
723
+ },
724
+ {
725
+ name: 'market';
726
+ writable: true;
727
+ pda: {
728
+ seeds: [
729
+ {
730
+ kind: 'const';
731
+ value: [109, 97, 114, 107, 101, 116];
732
+ },
733
+ {
734
+ kind: 'arg';
735
+ path: 'marketId';
736
+ }
737
+ ];
738
+ };
739
+ },
740
+ {
741
+ name: 'mint';
742
+ },
743
+ {
744
+ name: 'marketToAta';
745
+ writable: true;
746
+ pda: {
747
+ seeds: [
748
+ {
749
+ kind: 'account';
750
+ path: 'market';
751
+ },
752
+ {
753
+ kind: 'account';
754
+ path: 'tokenProgram';
755
+ },
756
+ {
757
+ kind: 'account';
758
+ path: 'mint';
759
+ }
760
+ ];
761
+ program: {
762
+ kind: 'const';
763
+ value: [
764
+ 140,
765
+ 151,
766
+ 37,
767
+ 143,
768
+ 78,
769
+ 36,
770
+ 137,
771
+ 241,
772
+ 187,
773
+ 61,
774
+ 16,
775
+ 41,
776
+ 20,
777
+ 142,
778
+ 13,
779
+ 131,
780
+ 11,
781
+ 90,
782
+ 19,
783
+ 153,
784
+ 218,
785
+ 255,
786
+ 16,
787
+ 132,
788
+ 4,
789
+ 142,
790
+ 123,
791
+ 216,
792
+ 219,
793
+ 233,
794
+ 248,
795
+ 89
796
+ ];
797
+ };
798
+ };
799
+ },
800
+ {
801
+ name: 'squadsAta';
802
+ writable: true;
803
+ pda: {
804
+ seeds: [
805
+ {
806
+ kind: 'account';
807
+ path: 'squads';
808
+ },
809
+ {
810
+ kind: 'account';
811
+ path: 'tokenProgram';
812
+ },
813
+ {
814
+ kind: 'account';
815
+ path: 'mint';
816
+ }
817
+ ];
818
+ program: {
819
+ kind: 'const';
820
+ value: [
821
+ 140,
822
+ 151,
823
+ 37,
824
+ 143,
825
+ 78,
826
+ 36,
827
+ 137,
828
+ 241,
829
+ 187,
830
+ 61,
831
+ 16,
832
+ 41,
833
+ 20,
834
+ 142,
835
+ 13,
836
+ 131,
837
+ 11,
838
+ 90,
839
+ 19,
840
+ 153,
841
+ 218,
842
+ 255,
843
+ 16,
844
+ 132,
845
+ 4,
846
+ 142,
847
+ 123,
848
+ 216,
849
+ 219,
850
+ 233,
851
+ 248,
852
+ 89
853
+ ];
854
+ };
855
+ };
856
+ },
857
+ {
858
+ name: 'orderBook';
859
+ pda: {
860
+ seeds: [
861
+ {
862
+ kind: 'const';
863
+ value: [111, 114, 100, 101, 114, 95, 98, 111, 111, 107];
864
+ },
865
+ {
866
+ kind: 'arg';
867
+ path: 'marketId';
868
+ }
869
+ ];
870
+ };
871
+ },
872
+ {
873
+ name: 'tokenProgram';
874
+ },
875
+ {
876
+ name: 'associatedTokenProgram';
877
+ address: 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL';
878
+ },
879
+ {
880
+ name: 'systemProgram';
881
+ address: '11111111111111111111111111111111';
882
+ }
883
+ ];
884
+ args: [
885
+ {
886
+ name: 'marketId';
887
+ type: 'u64';
888
+ }
889
+ ];
890
+ },
710
891
  {
711
892
  name: 'closeOrderBook';
712
893
  discriminator: [219, 134, 73, 219, 180, 7, 94, 206];
@@ -3537,6 +3718,16 @@ export type TriadProtocol = {
3537
3718
  code: 6027;
3538
3719
  name: 'invalidQuestion';
3539
3720
  msg: 'Invalid Question';
3721
+ },
3722
+ {
3723
+ code: 6028;
3724
+ name: 'marketNotIdle';
3725
+ msg: 'Market Not Idle';
3726
+ },
3727
+ {
3728
+ code: 6029;
3729
+ name: 'orderBookStillExists';
3730
+ msg: 'Order Book still exists';
3540
3731
  }
3541
3732
  ];
3542
3733
  types: [
@@ -10,7 +10,7 @@ function calculateDynamicFeeBps(price, feeBps) {
10
10
  if (internalPrice < 900000) {
11
11
  return feeBps;
12
12
  }
13
- return Math.floor(((990000 - internalPrice) * 1900) / price);
13
+ return Math.max(Math.floor(((990000 - internalPrice) * 1900) / internalPrice), 90);
14
14
  }
15
15
  exports.calculateDynamicFeeBps = calculateDynamicFeeBps;
16
16
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@triadxyz/triad-protocol",
3
- "version": "4.1.7",
3
+ "version": "4.1.8",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",