@triadxyz/triad-protocol 4.0.2 → 4.0.3

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,25 +1,32 @@
1
1
  /// <reference types="@coral-xyz/anchor/node_modules/@solana/web3.js" />
2
+ import { PublicKey } from '@solana/web3.js';
2
3
  import { Program } from '@coral-xyz/anchor';
3
4
  import { TriadProtocol } from './types/triad_protocol';
4
5
  import { RpcOptions } from './types';
5
- import { DepositArgs, WithdrawArgs } from './types/predictor';
6
+ import { DepositArgs, WithdrawArgs, Predictor as PredictorType } from './types/predictor';
6
7
  export default class Predictor {
7
8
  private program;
8
9
  private rpcOptions;
9
10
  constructor(program: Program<TriadProtocol>, rpcOptions: RpcOptions);
11
+ /**
12
+ * Get predictor
13
+ * @param authority - Authority public key
14
+ * @param customerId - Customer ID (optional) defaults to 7 from Triadmarkets
15
+ */
16
+ getPredictor(authority: PublicKey, customerId?: number): Promise<PredictorType>;
10
17
  /**
11
18
  * Deposit
12
19
  * @param args.authority - Authority of the deposit
13
20
  * @param args.amount - Amount to deposit
14
21
  * @param args.refer - Referral public key (optional) defaults to Triadmarkets public key
15
- * @param args.customer - Customer ID (optional) defaults to 7 from Triadmarkets
22
+ * @param args.customerId - Customer ID (optional) defaults to 7 from Triadmarkets
16
23
  */
17
- deposit({ authority, amount, refer, customer }: DepositArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
24
+ deposit({ authority, amount, refer, customerId }: DepositArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
18
25
  /**
19
26
  * Withdraw
20
27
  * @param args.authority - Authority of the withdraw
21
28
  * @param args.amount - Amount to deposit
22
- * @param args.customer - Customer ID (optional) defaults to 7 from Triadmarkets
29
+ * @param args.customerId - Customer ID (optional) defaults to 7 from Triadmarkets
23
30
  */
24
- withdraw({ authority, amount, customer }: WithdrawArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
31
+ withdraw({ authority, amount, customerId }: WithdrawArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
25
32
  }
package/dist/predictor.js CHANGED
@@ -17,29 +17,54 @@ const bn_js_1 = __importDefault(require("bn.js"));
17
17
  const constants_1 = require("./utils/constants");
18
18
  const pda_1 = require("./utils/pda");
19
19
  const sendVersionedTransaction_1 = __importDefault(require("./utils/sendVersionedTransaction"));
20
+ const helpers_1 = require("./utils/helpers");
20
21
  class Predictor {
21
22
  constructor(program, rpcOptions) {
22
23
  this.program = program;
23
24
  this.rpcOptions = rpcOptions;
24
25
  }
26
+ /**
27
+ * Get predictor
28
+ * @param authority - Authority public key
29
+ * @param customerId - Customer ID (optional) defaults to 7 from Triadmarkets
30
+ */
31
+ getPredictor(authority, customerId = 7) {
32
+ return __awaiter(this, void 0, void 0, function* () {
33
+ const predictorPDA = (0, pda_1.getPredictorPDA)(this.program.programId, authority, customerId);
34
+ try {
35
+ const predictor = yield this.program.account.predictor.fetch(predictorPDA);
36
+ const balance = yield this.program.provider.connection.getTokenAccountBalance((0, pda_1.getTokenATA)(authority, constants_1.UNIT_MINT, this.program.programId));
37
+ return (0, helpers_1.formatPredictor)(predictor, predictorPDA, new bn_js_1.default(balance.value.amount));
38
+ }
39
+ catch (e) {
40
+ return {
41
+ address: predictorPDA.toBase58(),
42
+ authority: authority.toBase58(),
43
+ balance: 0,
44
+ customerId,
45
+ refer: '11111111111111111111111111111111'
46
+ };
47
+ }
48
+ });
49
+ }
25
50
  /**
26
51
  * Deposit
27
52
  * @param args.authority - Authority of the deposit
28
53
  * @param args.amount - Amount to deposit
29
54
  * @param args.refer - Referral public key (optional) defaults to Triadmarkets public key
30
- * @param args.customer - Customer ID (optional) defaults to 7 from Triadmarkets
55
+ * @param args.customerId - Customer ID (optional) defaults to 7 from Triadmarkets
31
56
  */
32
- deposit({ authority, amount, refer = new web3_js_1.PublicKey('DqL77dzdTruyY9qssbU1aQNeDDywxL587k9FquxVv6iX'), customer = 7 }) {
57
+ deposit({ authority, amount, refer = new web3_js_1.PublicKey('DqL77dzdTruyY9qssbU1aQNeDDywxL587k9FquxVv6iX'), customerId = 7 }) {
33
58
  return __awaiter(this, void 0, void 0, function* () {
34
59
  const ixs = [];
35
- const predictorPDA = (0, pda_1.getPredictorPDA)(this.program.programId, authority, customer);
60
+ const predictorPDA = (0, pda_1.getPredictorPDA)(this.program.programId, authority, customerId);
36
61
  try {
37
62
  yield this.program.account.predictor.fetch(predictorPDA);
38
63
  }
39
64
  catch (e) {
40
65
  ixs.push(yield this.program.methods
41
66
  .createPredictor({
42
- customer,
67
+ customerId,
43
68
  refer
44
69
  })
45
70
  .accounts({
@@ -63,12 +88,12 @@ class Predictor {
63
88
  * Withdraw
64
89
  * @param args.authority - Authority of the withdraw
65
90
  * @param args.amount - Amount to deposit
66
- * @param args.customer - Customer ID (optional) defaults to 7 from Triadmarkets
91
+ * @param args.customerId - Customer ID (optional) defaults to 7 from Triadmarkets
67
92
  */
68
- withdraw({ authority, amount, customer = 7 }) {
93
+ withdraw({ authority, amount, customerId = 7 }) {
69
94
  return __awaiter(this, void 0, void 0, function* () {
70
95
  const ixs = [];
71
- const predictorPDA = (0, pda_1.getPredictorPDA)(this.program.programId, authority, customer);
96
+ const predictorPDA = (0, pda_1.getPredictorPDA)(this.program.programId, authority, customerId);
72
97
  ixs.push(yield this.program.methods
73
98
  .withdraw(new bn_js_1.default(amount * Math.pow(10, constants_1.BASE_DECIMALS)))
74
99
  .accounts({
package/dist/trade.js CHANGED
@@ -215,7 +215,7 @@ class Trade {
215
215
  }
216
216
  const orderPrice = new bn_js_1.default(order.price);
217
217
  const availableShares = new bn_js_1.default(order.totalShares).sub(new bn_js_1.default(order.filledShares));
218
- const effectivePriceDecimal = (0, feeCalculator_1.applyBuyFee)(orderPrice.toNumber() / 1000000, 700);
218
+ const effectivePriceDecimal = (0, feeCalculator_1.applyBuyFee)(orderPrice.toNumber() / 1000000, 500);
219
219
  const adjustedPrice = new bn_js_1.default(Math.floor(effectivePriceDecimal * 1000000));
220
220
  const maxSharesForPrice = remainingUSDC
221
221
  .mul(new bn_js_1.default(Math.pow(10, constants_1.BASE_DECIMALS)))
@@ -287,7 +287,7 @@ class Trade {
287
287
  continue;
288
288
  remainingShares = remainingShares.sub(sharesToSell);
289
289
  const orderPrice = new bn_js_1.default(order.price);
290
- const effectivePriceDecimal = (0, feeCalculator_1.applySellFee)(orderPrice.toNumber() / 1000000, 700);
290
+ const effectivePriceDecimal = (0, feeCalculator_1.applySellFee)(orderPrice.toNumber() / 1000000, 500);
291
291
  const adjustedPrice = new bn_js_1.default(Math.floor(effectivePriceDecimal * 1000000));
292
292
  amountOfUSDC = amountOfUSDC.add(sharesToSell.mul(adjustedPrice).div(new bn_js_1.default(Math.pow(10, constants_1.BASE_DECIMALS))));
293
293
  ixs.push(yield this.program.methods
@@ -847,7 +847,7 @@
847
847
  },
848
848
  {
849
849
  "kind": "arg",
850
- "path": "args.customer"
850
+ "path": "args.customer_id"
851
851
  }
852
852
  ]
853
853
  }
@@ -3106,7 +3106,7 @@
3106
3106
  "type": "pubkey"
3107
3107
  },
3108
3108
  {
3109
- "name": "customer",
3109
+ "name": "customer_id",
3110
3110
  "type": "u16"
3111
3111
  }
3112
3112
  ]
@@ -3886,7 +3886,7 @@
3886
3886
  "type": "pubkey"
3887
3887
  },
3888
3888
  {
3889
- "name": "customer",
3889
+ "name": "customer_id",
3890
3890
  "type": "u16"
3891
3891
  },
3892
3892
  {
@@ -1,13 +1,20 @@
1
1
  /// <reference types="@coral-xyz/anchor/node_modules/@solana/web3.js" />
2
2
  import { PublicKey } from '@solana/web3.js';
3
+ export type Predictor = {
4
+ address: string;
5
+ authority: string;
6
+ refer: string;
7
+ customerId: number;
8
+ balance: number;
9
+ };
3
10
  export type DepositArgs = {
4
11
  authority: PublicKey;
5
12
  amount: number;
6
13
  refer?: PublicKey;
7
- customer?: number;
14
+ customerId?: number;
8
15
  };
9
16
  export type WithdrawArgs = {
10
17
  authority: PublicKey;
11
18
  amount: number;
12
- customer?: number;
19
+ customerId?: number;
13
20
  };
@@ -1167,7 +1167,7 @@ export type TriadProtocol = {
1167
1167
  },
1168
1168
  {
1169
1169
  kind: 'arg';
1170
- path: 'args.customer';
1170
+ path: 'args.customer_id';
1171
1171
  }
1172
1172
  ];
1173
1173
  };
@@ -3994,7 +3994,7 @@ export type TriadProtocol = {
3994
3994
  type: 'pubkey';
3995
3995
  },
3996
3996
  {
3997
- name: 'customer';
3997
+ name: 'customerId';
3998
3998
  type: 'u16';
3999
3999
  }
4000
4000
  ];
@@ -4774,7 +4774,7 @@ export type TriadProtocol = {
4774
4774
  type: 'pubkey';
4775
4775
  },
4776
4776
  {
4777
- name: 'customer';
4777
+ name: 'customerId';
4778
4778
  type: 'u16';
4779
4779
  },
4780
4780
  {
@@ -2,6 +2,7 @@
2
2
  import { PublicKey } from '@solana/web3.js';
3
3
  export declare const USDC_MINT: PublicKey;
4
4
  export declare const TRD_MINT: PublicKey;
5
+ export declare const UNIT_MINT: PublicKey;
5
6
  export declare const TRIAD_ADMIN: PublicKey;
6
7
  export declare const TICKET_CORE_COLLECTION: PublicKey;
7
8
  export declare const POSEIDON_CORE_COLLECTION: PublicKey;
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BOOK_ORDER_NULL = exports.BASE_DECIMALS = exports.TICKET_COLLECTION_SYMBOL = exports.POSEIDON_COLLECTION_SYMBOL = exports.POSEIDON_CORE_COLLECTION = exports.TICKET_CORE_COLLECTION = exports.TRIAD_ADMIN = exports.TRD_MINT = exports.USDC_MINT = void 0;
3
+ exports.BOOK_ORDER_NULL = exports.BASE_DECIMALS = exports.TICKET_COLLECTION_SYMBOL = exports.POSEIDON_COLLECTION_SYMBOL = exports.POSEIDON_CORE_COLLECTION = exports.TICKET_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');
7
+ exports.UNIT_MINT = new web3_js_1.PublicKey('75wzVU6j9U6oZVJjQYLtiN7Z5Ah97it1UyWZN29HgE4m');
7
8
  exports.TRIAD_ADMIN = new web3_js_1.PublicKey('82ppCojm3yrEKgdpH8B5AmBJTU1r1uAWXFWhxvPs9UCR');
8
9
  exports.TICKET_CORE_COLLECTION = new web3_js_1.PublicKey('BaqopH1VXYUCT6VsojbTibVcd3k5jpGGT6296HFb6fVa');
9
10
  exports.POSEIDON_CORE_COLLECTION = new web3_js_1.PublicKey('69CLccefLRmvDSAJP7Er632dvn878qkpdcnvq5ZUspSm');
@@ -7,7 +7,7 @@ exports.simulateSellOrder = exports.simulateBuyOrder = exports.applySellFee = ex
7
7
  */
8
8
  function calculateDynamicFeeBps(price, feeBps) {
9
9
  const internalPrice = price * Math.pow(10, 6);
10
- if (internalPrice <= 900000) {
10
+ if (internalPrice < 900000) {
11
11
  return feeBps;
12
12
  }
13
13
  return Math.floor(((990000 - internalPrice) * 1900) / price);
@@ -1,9 +1,10 @@
1
1
  import { PublicKey } from '@solana/web3.js';
2
- import { IdlAccounts } from '@coral-xyz/anchor';
2
+ import { BN, IdlAccounts } from '@coral-xyz/anchor';
3
3
  import { Market, Order, OrderDirection, OrderSide, OrderStatus, OrderType, OrderDirectionEncoded, OrderTypeEncoded, OrderSideEncoded, OrderStatusEncoded, Pool, BookOrder } from '../types';
4
4
  import { Stake, StakeVault, Unstake } from '../types/stake';
5
5
  import { Customer } from '../types/customer';
6
6
  import { TriadProtocol } from '../types/triad_protocol';
7
+ import { Predictor } from '../types/predictor';
7
8
  export declare const encodeString: (value: string, alloc?: number) => number[];
8
9
  export declare const decodeString: (bytes: number[]) => string;
9
10
  export declare const formatStakeVault: (stakeVault: IdlAccounts<TriadProtocol>['stakeVault']) => StakeVault;
@@ -25,3 +26,4 @@ export declare const getOrderStatus: (status: OrderStatusEncoded) => OrderStatus
25
26
  export declare const getOrderDirectionEncoded: (orderDirection: OrderDirection) => OrderDirectionEncoded;
26
27
  export declare const getOppositeOrderDirection: (orderDirection: OrderDirection) => OrderDirection;
27
28
  export declare const getOppositeOrderDirectionEncoded: (orderDirection: OrderDirectionEncoded) => OrderDirectionEncoded;
29
+ export declare const formatPredictor: (account: IdlAccounts<TriadProtocol>['predictor'], publicKey: PublicKey, balance: BN) => Predictor;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- 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.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");
@@ -245,3 +245,13 @@ const getOppositeOrderDirectionEncoded = (orderDirection) => {
245
245
  return { hype: {} };
246
246
  };
247
247
  exports.getOppositeOrderDirectionEncoded = getOppositeOrderDirectionEncoded;
248
+ const formatPredictor = (account, publicKey, balance) => {
249
+ return {
250
+ address: publicKey.toBase58(),
251
+ authority: publicKey.toString(),
252
+ refer: account.refer.toString(),
253
+ customerId: account.customerId,
254
+ balance: balance.toNumber() / 1e6
255
+ };
256
+ };
257
+ exports.formatPredictor = formatPredictor;
@@ -13,5 +13,5 @@ export declare const getPoseidonPDA: (programId: PublicKey, number: number) => P
13
13
  export declare const getClaimVaultPDA: (programId: PublicKey, name: string) => PublicKey;
14
14
  export declare const getClaimedUserPDA: (programId: PublicKey, claimVault: PublicKey, user: PublicKey) => PublicKey;
15
15
  export declare const getOrderPDA: (programId: PublicKey, authority: PublicKey, marketId: number, orderDirection: OrderDirection) => PublicKey;
16
- export declare const getPredictorPDA: (programId: PublicKey, authority: PublicKey, customer: number) => PublicKey;
16
+ export declare const getPredictorPDA: (programId: PublicKey, authority: PublicKey, customerId: number) => PublicKey;
17
17
  export declare const getCentralPDA: (programId: PublicKey) => PublicKey;
package/dist/utils/pda.js CHANGED
@@ -64,11 +64,11 @@ const getOrderPDA = (programId, authority, marketId, orderDirection) => {
64
64
  ], programId)[0];
65
65
  };
66
66
  exports.getOrderPDA = getOrderPDA;
67
- const getPredictorPDA = (programId, authority, customer) => {
67
+ const getPredictorPDA = (programId, authority, customerId) => {
68
68
  return web3_js_1.PublicKey.findProgramAddressSync([
69
69
  Buffer.from('predictor'),
70
70
  authority.toBuffer(),
71
- new bn_js_1.default(customer).toArrayLike(Buffer, 'le', 2)
71
+ new bn_js_1.default(customerId).toArrayLike(Buffer, 'le', 2)
72
72
  ], programId)[0];
73
73
  };
74
74
  exports.getPredictorPDA = getPredictorPDA;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@triadxyz/triad-protocol",
3
- "version": "4.0.2",
3
+ "version": "4.0.3",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",