@triadxyz/triad-protocol 4.0.7 → 4.0.9

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
@@ -8,7 +8,6 @@ import Poseidon from './poseidon';
8
8
  import Predictor from './predictor';
9
9
  import Trade from './trade';
10
10
  import Customer from './customer';
11
- import { PythSolanaReceiver } from '@pythnetwork/pyth-solana-receiver';
12
11
  export * from './types';
13
12
  export * from './types/predictor';
14
13
  export * from './types/stake';
@@ -29,7 +28,6 @@ export default class TriadProtocol {
29
28
  predictor: Predictor;
30
29
  trade: Trade;
31
30
  customer: Customer;
32
- pythSolanaReceiver: PythSolanaReceiver;
33
31
  constructor(connection: Connection, wallet: Wallet, rpcOptions: RpcOptions);
34
32
  /**
35
33
  * Get User Orders
@@ -174,5 +172,5 @@ export default class TriadProtocol {
174
172
  * @param args.customer - The customer of the market
175
173
  * @param args.poolId - The ID of the pool
176
174
  */
177
- createMarketPyth({ markets, customer, poolId }: CreateMarketPythArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
175
+ createMarketPyth({ marketId, resolveIn, customer, poolId, feedId }: CreateMarketPythArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
178
176
  }
package/dist/index.js CHANGED
@@ -59,7 +59,6 @@ class TriadProtocol {
59
59
  if (!this.rpcOptions.payer) {
60
60
  this.rpcOptions.payer = this.wallet.publicKey;
61
61
  }
62
- this.pythSolanaReceiver = new pyth_solana_receiver_1.PythSolanaReceiver({ connection, wallet });
63
62
  this.provider = new anchor_1.AnchorProvider(this.connection, this.wallet, {
64
63
  commitment: this.rpcOptions.commitment || 'confirmed'
65
64
  });
@@ -285,19 +284,23 @@ class TriadProtocol {
285
284
  throw new Error('Pool question must be less than 80 characters');
286
285
  }
287
286
  const ixs = [];
288
- const feedPDA = this.pythSolanaReceiver.getPriceFeedAccountAddress(0, feedId);
287
+ let feedPDA = null;
288
+ if (isPyth) {
289
+ feedPDA = (0, pyth_solana_receiver_1.getPriceFeedAccountForProgram)(0, feedId);
290
+ }
289
291
  const poolPDA = (0, pda_1.getPoolPDA)(this.program.programId, poolId);
290
292
  ixs.push(yield this.program.methods
291
293
  .createPool({
292
294
  poolId: new bn_js_1.default(poolId),
293
295
  question: (0, helpers_1.encodeString)(question, 80),
294
296
  isFast,
295
- isPyth,
296
- feed: feedPDA
297
+ isPyth
297
298
  })
298
299
  .accounts({
299
300
  signer: this.program.provider.publicKey,
300
- customer
301
+ priceUpdate: feedPDA,
302
+ customer,
303
+ feed: (0, helpers_1.getFeedIdFromHex)(feedId)
301
304
  })
302
305
  .instruction());
303
306
  for (const market of markets) {
@@ -481,31 +484,31 @@ class TriadProtocol {
481
484
  * @param args.customer - The customer of the market
482
485
  * @param args.poolId - The ID of the pool
483
486
  */
484
- createMarketPyth({ markets, customer, poolId }) {
487
+ createMarketPyth({ marketId, resolveIn, customer, poolId, feedId }) {
485
488
  return __awaiter(this, void 0, void 0, function* () {
486
489
  const ixs = [];
487
490
  let poolPDA = (0, pda_1.getPoolPDA)(this.program.programId, poolId);
488
- for (const market of markets) {
489
- ixs.push(yield this.program.methods
490
- .createMarketPyth({
491
- marketId: new bn_js_1.default(market.marketId),
492
- resolveIn: new bn_js_1.default(market.resolveIn)
493
- })
494
- .accounts({
495
- signer: this.program.provider.publicKey,
496
- tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
497
- pool: poolPDA,
498
- customer
499
- })
500
- .instruction());
501
- ixs.push(yield this.program.methods
502
- .createOrderBook(new bn_js_1.default(market.marketId))
503
- .accounts({
504
- signer: this.program.provider.publicKey,
505
- market: (0, pda_1.getMarketPDA)(this.program.programId, market.marketId)
506
- })
507
- .instruction());
508
- }
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());
509
512
  return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
510
513
  });
511
514
  }
@@ -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"
@@ -2982,12 +2986,6 @@
2982
2986
  {
2983
2987
  "name": "is_pyth",
2984
2988
  "type": "bool"
2985
- },
2986
- {
2987
- "name": "feed",
2988
- "type": {
2989
- "option": "pubkey"
2990
- }
2991
2989
  }
2992
2990
  ]
2993
2991
  }
@@ -3286,6 +3284,10 @@
3286
3284
  {
3287
3285
  "name": "resolved_ts",
3288
3286
  "type": "i64"
3287
+ },
3288
+ {
3289
+ "name": "pyth_price",
3290
+ "type": "u64"
3289
3291
  }
3290
3292
  ]
3291
3293
  }
@@ -3449,10 +3451,14 @@
3449
3451
  "name": "pre_market_end_ts",
3450
3452
  "type": "i64"
3451
3453
  },
3454
+ {
3455
+ "name": "pyth_price",
3456
+ "type": "u64"
3457
+ },
3452
3458
  {
3453
3459
  "name": "padding",
3454
3460
  "type": {
3455
- "array": ["u8", 24]
3461
+ "array": ["u8", 16]
3456
3462
  }
3457
3463
  }
3458
3464
  ]
@@ -3763,6 +3769,14 @@
3763
3769
  {
3764
3770
  "name": "authority",
3765
3771
  "type": "pubkey"
3772
+ },
3773
+ {
3774
+ "name": "is_fast",
3775
+ "type": "bool"
3776
+ },
3777
+ {
3778
+ "name": "is_pyth",
3779
+ "type": "bool"
3766
3780
  }
3767
3781
  ]
3768
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;
@@ -151,12 +154,11 @@ export type CreateMarketArgs = {
151
154
  poolId?: number;
152
155
  };
153
156
  export type CreateMarketPythArgs = {
154
- markets: {
155
- marketId: number;
156
- resolveIn: number;
157
- }[];
157
+ marketId: number;
158
+ resolveIn: number;
158
159
  customer: PublicKey;
159
160
  poolId: number;
161
+ feedId: string;
160
162
  };
161
163
  export type CreatePoolArgs = {
162
164
  poolId: number;
@@ -172,7 +174,7 @@ export type CreatePoolArgs = {
172
174
  }[];
173
175
  isFast?: boolean;
174
176
  isPyth?: boolean;
175
- feedId: string;
177
+ feedId?: string;
176
178
  };
177
179
  export type UpdateMarketWinningDirectionArgs = {
178
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';
@@ -3899,12 +3903,6 @@ export type TriadProtocol = {
3899
3903
  {
3900
3904
  name: 'isPyth';
3901
3905
  type: 'bool';
3902
- },
3903
- {
3904
- name: 'feed';
3905
- type: {
3906
- option: 'pubkey';
3907
- };
3908
3906
  }
3909
3907
  ];
3910
3908
  };
@@ -4203,6 +4201,10 @@ export type TriadProtocol = {
4203
4201
  {
4204
4202
  name: 'resolvedTs';
4205
4203
  type: 'i64';
4204
+ },
4205
+ {
4206
+ name: 'pythPrice';
4207
+ type: 'u64';
4206
4208
  }
4207
4209
  ];
4208
4210
  };
@@ -4366,10 +4368,14 @@ export type TriadProtocol = {
4366
4368
  name: 'preMarketEndTs';
4367
4369
  type: 'i64';
4368
4370
  },
4371
+ {
4372
+ name: 'pythPrice';
4373
+ type: 'u64';
4374
+ },
4369
4375
  {
4370
4376
  name: 'padding';
4371
4377
  type: {
4372
- array: ['u8', 24];
4378
+ array: ['u8', 16];
4373
4379
  };
4374
4380
  }
4375
4381
  ];
@@ -4680,6 +4686,14 @@ export type TriadProtocol = {
4680
4686
  {
4681
4687
  name: 'authority';
4682
4688
  type: 'pubkey';
4689
+ },
4690
+ {
4691
+ name: 'isFast';
4692
+ type: 'bool';
4693
+ },
4694
+ {
4695
+ name: 'isPyth';
4696
+ type: 'bool';
4683
4697
  }
4684
4698
  ];
4685
4699
  };
@@ -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.7",
3
+ "version": "4.0.9",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",