@triadxyz/triad-protocol 4.0.6 → 4.0.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.
@@ -1,3 +1,4 @@
1
+ /// <reference types="jito-ts/node_modules/@solana/web3.js" />
1
2
  import { PublicKey } from '@solana/web3.js';
2
3
  import { Program } from '@coral-xyz/anchor';
3
4
  import { TriadProtocol } from './types/triad_protocol';
@@ -27,6 +28,7 @@ export default class Customer {
27
28
  * @param args.name - The name of the customer
28
29
  * @param args.authority - The authority of the customer
29
30
  * @param args.feeRecipient - The fee recipient of the customer
31
+ * @param args.feeBps - The fee in basis points of the customer
30
32
  */
31
- createCustomer({ id, name, authority, feeRecipient }: CreateCustomerArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
33
+ createCustomer({ id, name, authority, feeRecipient, feeBps }: CreateCustomerArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
32
34
  }
package/dist/customer.js CHANGED
@@ -63,12 +63,13 @@ class Customer {
63
63
  * @param args.name - The name of the customer
64
64
  * @param args.authority - The authority of the customer
65
65
  * @param args.feeRecipient - The fee recipient of the customer
66
+ * @param args.feeBps - The fee in basis points of the customer
66
67
  */
67
- createCustomer({ id, name, authority, feeRecipient }) {
68
+ createCustomer({ id, name, authority, feeRecipient, feeBps }) {
68
69
  return __awaiter(this, void 0, void 0, function* () {
69
70
  const ixs = [
70
71
  yield this.program.methods
71
- .createCustomer({ id, name, authority, feeRecipient })
72
+ .createCustomer({ id, name, authority, feeRecipient, feeBps })
72
73
  .accounts({
73
74
  signer: this.program.provider.publicKey
74
75
  })
package/dist/index.d.ts CHANGED
@@ -1,7 +1,8 @@
1
+ /// <reference types="jito-ts/node_modules/@solana/web3.js" />
1
2
  import { Connection, PublicKey } from '@solana/web3.js';
2
3
  import { AnchorProvider, Program, Wallet } from '@coral-xyz/anchor';
3
4
  import { TriadProtocol as TriadProtocolIDL } from './types/triad_protocol';
4
- import { RpcOptions, CreateMarketArgs, CreatePoolArgs, UpdateMarketWinningDirectionArgs, UpdateMarketPayoutArgs, UpdateMarketQuestionArgs, UpdateMarketEndArgs } from './types';
5
+ import { RpcOptions, CreateMarketArgs, CreatePoolArgs, UpdateMarketWinningDirectionArgs, UpdateMarketPayoutArgs, UpdateMarketQuestionArgs, UpdateMarketEndArgs, CreateMarketPythArgs } from './types';
5
6
  import Stake from './stake';
6
7
  import Poseidon from './poseidon';
7
8
  import Predictor from './predictor';
@@ -102,6 +103,14 @@ export default class TriadProtocol {
102
103
  * @param poolId - The ID of the pool
103
104
  * @param question - The question of the pool
104
105
  * @param markets - The markets of the pool
106
+ * @param customer - The customer of the pool
107
+ * @param startTime - The start time of the pool
108
+ * @param endTime - The end time of the pool
109
+ * @param feeBps - The fee in basis points of the pool
110
+ * @param payoutFee - The payout fee of the pool
111
+ * @param isFast - Whether the pool is fast
112
+ * @param isPyth - Whether the pool is pyth
113
+ * @param feedId - The feed ID of the pool
105
114
  */
106
115
  createPool({ poolId, question, markets, customer, startTime, endTime, feeBps, payoutFee, isFast, isPyth, feedId }: CreatePoolArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
107
116
  /**
@@ -155,4 +164,13 @@ export default class TriadProtocol {
155
164
  * @param question - Question
156
165
  */
157
166
  updatePoolQuestion(poolId: number, question: string): Promise<string | import("@solana/web3.js").VersionedTransaction>;
167
+ /**
168
+ * Create Market Pyth
169
+ * @param args.markets - Array of markets to create
170
+ * @param args.markets.marketId - Market ID
171
+ * @param args.markets.resolveIn - Time to add for resolver the market in seconds
172
+ * @param args.customer - The customer of the market
173
+ * @param args.poolId - The ID of the pool
174
+ */
175
+ createMarketPyth({ marketId, resolveIn, customer, poolId, feedId }: CreateMarketPythArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
158
176
  }
package/dist/index.js CHANGED
@@ -41,6 +41,7 @@ const poseidon_1 = __importDefault(require("./poseidon"));
41
41
  const predictor_1 = __importDefault(require("./predictor"));
42
42
  const trade_1 = __importDefault(require("./trade"));
43
43
  const customer_1 = __importDefault(require("./customer"));
44
+ const pyth_solana_receiver_1 = require("@pythnetwork/pyth-solana-receiver");
44
45
  __exportStar(require("./types"), exports);
45
46
  __exportStar(require("./types/predictor"), exports);
46
47
  __exportStar(require("./types/stake"), exports);
@@ -268,6 +269,14 @@ class TriadProtocol {
268
269
  * @param poolId - The ID of the pool
269
270
  * @param question - The question of the pool
270
271
  * @param markets - The markets of the pool
272
+ * @param customer - The customer of the pool
273
+ * @param startTime - The start time of the pool
274
+ * @param endTime - The end time of the pool
275
+ * @param feeBps - The fee in basis points of the pool
276
+ * @param payoutFee - The payout fee of the pool
277
+ * @param isFast - Whether the pool is fast
278
+ * @param isPyth - Whether the pool is pyth
279
+ * @param feedId - The feed ID of the pool
271
280
  */
272
281
  createPool({ poolId, question, markets, customer, startTime, endTime, feeBps, payoutFee, isFast, isPyth, feedId }) {
273
282
  return __awaiter(this, void 0, void 0, function* () {
@@ -275,18 +284,23 @@ class TriadProtocol {
275
284
  throw new Error('Pool question must be less than 80 characters');
276
285
  }
277
286
  const ixs = [];
287
+ let feedPDA = null;
288
+ if (isPyth) {
289
+ feedPDA = (0, pyth_solana_receiver_1.getPriceFeedAccountForProgram)(0, feedId);
290
+ }
278
291
  const poolPDA = (0, pda_1.getPoolPDA)(this.program.programId, poolId);
279
292
  ixs.push(yield this.program.methods
280
293
  .createPool({
281
294
  poolId: new bn_js_1.default(poolId),
282
295
  question: (0, helpers_1.encodeString)(question, 80),
283
296
  isFast,
284
- isPyth,
285
- feedId
297
+ isPyth
286
298
  })
287
299
  .accounts({
288
300
  signer: this.program.provider.publicKey,
289
- customer
301
+ priceUpdate: feedPDA,
302
+ customer,
303
+ feed: (0, helpers_1.getFeedIdFromHex)(feedId)
290
304
  })
291
305
  .instruction());
292
306
  for (const market of markets) {
@@ -462,5 +476,41 @@ class TriadProtocol {
462
476
  return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
463
477
  });
464
478
  }
479
+ /**
480
+ * Create Market Pyth
481
+ * @param args.markets - Array of markets to create
482
+ * @param args.markets.marketId - Market ID
483
+ * @param args.markets.resolveIn - Time to add for resolver the market in seconds
484
+ * @param args.customer - The customer of the market
485
+ * @param args.poolId - The ID of the pool
486
+ */
487
+ createMarketPyth({ marketId, resolveIn, customer, poolId, feedId }) {
488
+ return __awaiter(this, void 0, void 0, function* () {
489
+ const ixs = [];
490
+ let poolPDA = (0, pda_1.getPoolPDA)(this.program.programId, poolId);
491
+ const feedPDA = (0, pyth_solana_receiver_1.getPriceFeedAccountForProgram)(0, feedId);
492
+ ixs.push(yield this.program.methods
493
+ .createMarketPyth({
494
+ marketId: new bn_js_1.default(marketId),
495
+ resolveIn: new bn_js_1.default(resolveIn)
496
+ })
497
+ .accounts({
498
+ signer: this.program.provider.publicKey,
499
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
500
+ pool: poolPDA,
501
+ customer,
502
+ priceUpdate: feedPDA
503
+ })
504
+ .instruction());
505
+ ixs.push(yield this.program.methods
506
+ .createOrderBook(new bn_js_1.default(marketId))
507
+ .accounts({
508
+ signer: this.program.provider.publicKey,
509
+ market: (0, pda_1.getMarketPDA)(this.program.programId, marketId)
510
+ })
511
+ .instruction());
512
+ return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
513
+ });
514
+ }
465
515
  }
466
516
  exports.default = TriadProtocol;
@@ -1,3 +1,4 @@
1
+ /// <reference types="jito-ts/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';
@@ -1,3 +1,4 @@
1
+ /// <reference types="jito-ts/node_modules/@solana/web3.js" />
1
2
  import { PublicKey } from '@solana/web3.js';
2
3
  import { Program } from '@coral-xyz/anchor';
3
4
  import { TriadProtocol } from './types/triad_protocol';
package/dist/stake.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ /// <reference types="jito-ts/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';
package/dist/trade.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ /// <reference types="jito-ts/node_modules/@solana/web3.js" />
1
2
  import { PublicKey } from '@solana/web3.js';
2
3
  import { Program } from '@coral-xyz/anchor';
3
4
  import { TriadProtocol } from './types/triad_protocol';
@@ -13,4 +13,5 @@ export type CreateCustomerArgs = {
13
13
  name: string;
14
14
  authority: PublicKey;
15
15
  feeRecipient: PublicKey;
16
+ feeBps: number;
16
17
  };
@@ -889,6 +889,10 @@
889
889
  "writable": true,
890
890
  "optional": true
891
891
  },
892
+ {
893
+ "name": "feed",
894
+ "writable": true
895
+ },
892
896
  {
893
897
  "name": "system_program",
894
898
  "address": "11111111111111111111111111111111"
@@ -2894,6 +2898,10 @@
2894
2898
  {
2895
2899
  "name": "fee_recipient",
2896
2900
  "type": "pubkey"
2901
+ },
2902
+ {
2903
+ "name": "fee_bps",
2904
+ "type": "u16"
2897
2905
  }
2898
2906
  ]
2899
2907
  }
@@ -2978,12 +2986,6 @@
2978
2986
  {
2979
2987
  "name": "is_pyth",
2980
2988
  "type": "bool"
2981
- },
2982
- {
2983
- "name": "feed_id",
2984
- "type": {
2985
- "option": "pubkey"
2986
- }
2987
2989
  }
2988
2990
  ]
2989
2991
  }
@@ -3282,6 +3284,10 @@
3282
3284
  {
3283
3285
  "name": "resolved_ts",
3284
3286
  "type": "i64"
3287
+ },
3288
+ {
3289
+ "name": "pyth_price",
3290
+ "type": "u64"
3285
3291
  }
3286
3292
  ]
3287
3293
  }
@@ -3445,10 +3451,14 @@
3445
3451
  "name": "pre_market_end_ts",
3446
3452
  "type": "i64"
3447
3453
  },
3454
+ {
3455
+ "name": "pyth_price",
3456
+ "type": "u64"
3457
+ },
3448
3458
  {
3449
3459
  "name": "padding",
3450
3460
  "type": {
3451
- "array": ["u8", 24]
3461
+ "array": ["u8", 16]
3452
3462
  }
3453
3463
  }
3454
3464
  ]
@@ -3729,10 +3739,8 @@
3729
3739
  "type": "bool"
3730
3740
  },
3731
3741
  {
3732
- "name": "feed_id",
3733
- "type": {
3734
- "array": ["u8", 32]
3735
- }
3742
+ "name": "feed",
3743
+ "type": "pubkey"
3736
3744
  },
3737
3745
  {
3738
3746
  "name": "padding",
@@ -3761,6 +3769,14 @@
3761
3769
  {
3762
3770
  "name": "authority",
3763
3771
  "type": "pubkey"
3772
+ },
3773
+ {
3774
+ "name": "is_fast",
3775
+ "type": "bool"
3776
+ },
3777
+ {
3778
+ "name": "is_pyth",
3779
+ "type": "bool"
3764
3780
  }
3765
3781
  ]
3766
3782
  }
@@ -11,6 +11,8 @@ export type Pool = {
11
11
  id: number;
12
12
  question: string;
13
13
  authority: string;
14
+ isFast: boolean;
15
+ isPyth: boolean;
14
16
  };
15
17
  export type Market = {
16
18
  address: string;
@@ -43,6 +45,7 @@ export type Market = {
43
45
  customer: string;
44
46
  poolId: number;
45
47
  feeRecipient: string;
48
+ pythPrice: string;
46
49
  };
47
50
  export type Order = {
48
51
  address: string;
@@ -150,6 +153,13 @@ export type CreateMarketArgs = {
150
153
  customer: PublicKey;
151
154
  poolId?: number;
152
155
  };
156
+ export type CreateMarketPythArgs = {
157
+ marketId: number;
158
+ resolveIn: number;
159
+ customer: PublicKey;
160
+ poolId: number;
161
+ feedId: string;
162
+ };
153
163
  export type CreatePoolArgs = {
154
164
  poolId: number;
155
165
  question?: string;
@@ -164,7 +174,7 @@ export type CreatePoolArgs = {
164
174
  }[];
165
175
  isFast?: boolean;
166
176
  isPyth?: boolean;
167
- feedId?: PublicKey;
177
+ feedId?: string;
168
178
  };
169
179
  export type UpdateMarketWinningDirectionArgs = {
170
180
  marketId: number;
@@ -1238,6 +1238,10 @@ export type TriadProtocol = {
1238
1238
  writable: true;
1239
1239
  optional: true;
1240
1240
  },
1241
+ {
1242
+ name: 'feed';
1243
+ writable: true;
1244
+ },
1241
1245
  {
1242
1246
  name: 'systemProgram';
1243
1247
  address: '11111111111111111111111111111111';
@@ -3811,6 +3815,10 @@ export type TriadProtocol = {
3811
3815
  {
3812
3816
  name: 'feeRecipient';
3813
3817
  type: 'pubkey';
3818
+ },
3819
+ {
3820
+ name: 'feeBps';
3821
+ type: 'u16';
3814
3822
  }
3815
3823
  ];
3816
3824
  };
@@ -3895,12 +3903,6 @@ export type TriadProtocol = {
3895
3903
  {
3896
3904
  name: 'isPyth';
3897
3905
  type: 'bool';
3898
- },
3899
- {
3900
- name: 'feedId';
3901
- type: {
3902
- option: 'pubkey';
3903
- };
3904
3906
  }
3905
3907
  ];
3906
3908
  };
@@ -4199,6 +4201,10 @@ export type TriadProtocol = {
4199
4201
  {
4200
4202
  name: 'resolvedTs';
4201
4203
  type: 'i64';
4204
+ },
4205
+ {
4206
+ name: 'pythPrice';
4207
+ type: 'u64';
4202
4208
  }
4203
4209
  ];
4204
4210
  };
@@ -4362,10 +4368,14 @@ export type TriadProtocol = {
4362
4368
  name: 'preMarketEndTs';
4363
4369
  type: 'i64';
4364
4370
  },
4371
+ {
4372
+ name: 'pythPrice';
4373
+ type: 'u64';
4374
+ },
4365
4375
  {
4366
4376
  name: 'padding';
4367
4377
  type: {
4368
- array: ['u8', 24];
4378
+ array: ['u8', 16];
4369
4379
  };
4370
4380
  }
4371
4381
  ];
@@ -4646,10 +4656,8 @@ export type TriadProtocol = {
4646
4656
  type: 'bool';
4647
4657
  },
4648
4658
  {
4649
- name: 'feedId';
4650
- type: {
4651
- array: ['u8', 32];
4652
- };
4659
+ name: 'feed';
4660
+ type: 'pubkey';
4653
4661
  },
4654
4662
  {
4655
4663
  name: 'padding';
@@ -4678,6 +4686,14 @@ export type TriadProtocol = {
4678
4686
  {
4679
4687
  name: 'authority';
4680
4688
  type: 'pubkey';
4689
+ },
4690
+ {
4691
+ name: 'isFast';
4692
+ type: 'bool';
4693
+ },
4694
+ {
4695
+ name: 'isPyth';
4696
+ type: 'bool';
4681
4697
  }
4682
4698
  ];
4683
4699
  };
@@ -7,3 +7,8 @@ export declare const POSEIDON_CORE_COLLECTION: PublicKey;
7
7
  export declare const POSEIDON_COLLECTION_SYMBOL = "$PSN";
8
8
  export declare const BASE_DECIMALS = 6;
9
9
  export declare const BOOK_ORDER_NULL = 61;
10
+ export declare const PRICE_FEED: {
11
+ BTC: string;
12
+ SOL: string;
13
+ ETH: string;
14
+ };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BOOK_ORDER_NULL = exports.BASE_DECIMALS = exports.POSEIDON_COLLECTION_SYMBOL = exports.POSEIDON_CORE_COLLECTION = exports.TRIAD_ADMIN = exports.UNIT_MINT = exports.TRD_MINT = exports.USDC_MINT = void 0;
3
+ exports.PRICE_FEED = exports.BOOK_ORDER_NULL = exports.BASE_DECIMALS = exports.POSEIDON_COLLECTION_SYMBOL = exports.POSEIDON_CORE_COLLECTION = exports.TRIAD_ADMIN = exports.UNIT_MINT = exports.TRD_MINT = exports.USDC_MINT = void 0;
4
4
  const web3_js_1 = require("@solana/web3.js");
5
5
  exports.USDC_MINT = new web3_js_1.PublicKey('EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v');
6
6
  exports.TRD_MINT = new web3_js_1.PublicKey('t3DohmswhKk94PPbPYwA6ZKACyY3y5kbcqeQerAJjmV');
@@ -10,3 +10,8 @@ exports.POSEIDON_CORE_COLLECTION = new web3_js_1.PublicKey('69CLccefLRmvDSAJP7Er
10
10
  exports.POSEIDON_COLLECTION_SYMBOL = '$PSN';
11
11
  exports.BASE_DECIMALS = 6;
12
12
  exports.BOOK_ORDER_NULL = 61;
13
+ exports.PRICE_FEED = {
14
+ BTC: '0xe62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43',
15
+ SOL: '0xef0d8b6fda2ceba41da15d4095d1da392a0d2f8ed0c6c7bc0f4cfac8c280b56d',
16
+ ETH: '0xff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace'
17
+ };
@@ -27,3 +27,4 @@ export declare const getOrderDirectionEncoded: (orderDirection: OrderDirection)
27
27
  export declare const getOppositeOrderDirection: (orderDirection: OrderDirection) => OrderDirection;
28
28
  export declare const getOppositeOrderDirectionEncoded: (orderDirection: OrderDirectionEncoded) => OrderDirectionEncoded;
29
29
  export declare const formatPredictor: (account: IdlAccounts<TriadProtocol>['predictor'], publicKey: PublicKey, balance: BN) => Predictor;
30
+ export declare const getFeedIdFromHex: (input?: string) => PublicKey | null;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.formatPredictor = exports.getOppositeOrderDirectionEncoded = exports.getOppositeOrderDirection = exports.getOrderDirectionEncoded = exports.getOrderStatus = exports.getOrderSide = exports.getOrderType = exports.getOrderSideFromNumber = exports.getOrderDirectionFromNumber = exports.getOrderDirection = exports.getTokenProgram = exports.calculateStakeRewards = exports.formatCustomer = exports.formatBookOrder = exports.formatOrder = exports.formatMarket = exports.formatPool = exports.formatUnstake = exports.formatStake = exports.formatStakeVault = exports.decodeString = exports.encodeString = void 0;
3
+ exports.getFeedIdFromHex = exports.formatPredictor = exports.getOppositeOrderDirectionEncoded = exports.getOppositeOrderDirection = exports.getOrderDirectionEncoded = exports.getOrderStatus = exports.getOrderSide = exports.getOrderType = exports.getOrderSideFromNumber = exports.getOrderDirectionFromNumber = exports.getOrderDirection = exports.getTokenProgram = exports.calculateStakeRewards = exports.formatCustomer = exports.formatBookOrder = exports.formatOrder = exports.formatMarket = exports.formatPool = exports.formatUnstake = exports.formatStake = exports.formatStakeVault = exports.decodeString = exports.encodeString = void 0;
4
4
  const web3_js_1 = require("@solana/web3.js");
5
5
  const spl_token_1 = require("@solana/spl-token");
6
6
  const types_1 = require("../types");
@@ -63,7 +63,9 @@ const formatPool = (account, address) => {
63
63
  address: address.toString(),
64
64
  id: account.id.toNumber(),
65
65
  question: Buffer.from(account.question).toString().replace(/\0+$/, ''),
66
- authority: account.authority.toString()
66
+ authority: account.authority.toString(),
67
+ isFast: account.isFast,
68
+ isPyth: account.isPyth
67
69
  };
68
70
  };
69
71
  exports.formatPool = formatPool;
@@ -100,7 +102,8 @@ const formatMarket = (account, address) => {
100
102
  payoutFee: account.payoutFee,
101
103
  customer: account.customerId === 0 ? 'Triad' : account.customerId.toString(),
102
104
  poolId: account.poolId.toNumber(),
103
- feeRecipient: account.feeRecipient.toString()
105
+ feeRecipient: account.feeRecipient.toString(),
106
+ pythPrice: account.pythPrice.toString()
104
107
  };
105
108
  };
106
109
  exports.formatMarket = formatMarket;
@@ -255,3 +258,17 @@ const formatPredictor = (account, publicKey, balance) => {
255
258
  };
256
259
  };
257
260
  exports.formatPredictor = formatPredictor;
261
+ const getFeedIdFromHex = (input) => {
262
+ let feedId = new Uint8Array(32);
263
+ if (!input) {
264
+ return null;
265
+ }
266
+ if (input.length === 66) {
267
+ feedId = Uint8Array.from(Buffer.from(input.slice(2), 'hex'));
268
+ }
269
+ if (input.length === 64) {
270
+ feedId = Uint8Array.from(Buffer.from(input, 'hex'));
271
+ }
272
+ return new web3_js_1.PublicKey(feedId);
273
+ };
274
+ exports.getFeedIdFromHex = getFeedIdFromHex;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@triadxyz/triad-protocol",
3
- "version": "4.0.6",
3
+ "version": "4.0.8",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -33,6 +33,7 @@
33
33
  "license": "ISC",
34
34
  "dependencies": {
35
35
  "@coral-xyz/anchor": "0.31.1",
36
+ "@pythnetwork/pyth-solana-receiver": "0.14.0",
36
37
  "@solana/spl-token": "0.4.14",
37
38
  "@solana/web3.js": "1.98.4",
38
39
  "axios": "1.13.6",