@triadxyz/triad-protocol 4.1.8 → 4.1.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.
@@ -29,5 +29,5 @@ export default class Customer {
29
29
  * @param args.feeRecipient - The fee recipient of the customer
30
30
  * @param args.feeBps - The fee in basis points of the customer
31
31
  */
32
- createCustomer({ id, name, authority, feeRecipient, feeBps }: CreateCustomerArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
32
+ createCustomer({ id, name, authority, feeRecipient, feeBps, marketFeeBps, payoutFeeBps }: CreateCustomerArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
33
33
  }
package/dist/customer.js CHANGED
@@ -14,7 +14,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const helpers_1 = require("./utils/helpers");
16
16
  const sendVersionedTransaction_1 = __importDefault(require("./utils/sendVersionedTransaction"));
17
- const pda_1 = require("./utils/pda");
18
17
  class Customer {
19
18
  constructor(program, rpcOptions) {
20
19
  this.program = program;
@@ -52,9 +51,7 @@ class Customer {
52
51
  */
53
52
  getCustomerById(customerId) {
54
53
  return __awaiter(this, void 0, void 0, function* () {
55
- const customerPDA = (0, pda_1.getCustomerPDA)(this.program.programId, customerId);
56
- const customer = yield this.program.account.customer.fetch(customerPDA, this.rpcOptions.commitment);
57
- return (0, helpers_1.formatCustomer)(customer, customerPDA);
54
+ return (0, helpers_1.getCustomerById)(this.program, customerId);
58
55
  });
59
56
  }
60
57
  /**
@@ -65,11 +62,19 @@ class Customer {
65
62
  * @param args.feeRecipient - The fee recipient of the customer
66
63
  * @param args.feeBps - The fee in basis points of the customer
67
64
  */
68
- createCustomer({ id, name, authority, feeRecipient, feeBps }) {
65
+ createCustomer({ id, name, authority, feeRecipient, feeBps, marketFeeBps, payoutFeeBps }) {
69
66
  return __awaiter(this, void 0, void 0, function* () {
70
67
  const ixs = [
71
68
  yield this.program.methods
72
- .createCustomer({ id, name, authority, feeRecipient, feeBps })
69
+ .createCustomer({
70
+ id,
71
+ name,
72
+ authority,
73
+ feeRecipient,
74
+ feeBps,
75
+ marketFeeBps,
76
+ payoutFeeBps
77
+ })
73
78
  .accounts({
74
79
  signer: this.program.provider.publicKey
75
80
  })
package/dist/trade.d.ts CHANGED
@@ -64,7 +64,7 @@ export default class Trade {
64
64
  * @param args.amount - The amount of the Order
65
65
  * @param args.orderDirection - The direction of the Order
66
66
  */
67
- marketBidOrder({ marketId, amount, orderDirection }: MarketBidOrderArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
67
+ marketBidOrder({ marketId, amount, customerId, orderDirection }: MarketBidOrderArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
68
68
  /**
69
69
  * Market Ask Order
70
70
  * @param args.marketId - The ID of the Market
@@ -72,7 +72,7 @@ export default class Trade {
72
72
  * @param args.bookOrderBidId - The ID of the Bid Order
73
73
  * @param args.orderDirection - The direction of the Order
74
74
  */
75
- marketAskOrder({ marketId, shares, orderDirection }: MarketAskOrderArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
75
+ marketAskOrder({ marketId, shares, orderDirection, customerId }: MarketAskOrderArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
76
76
  /**
77
77
  * Payout Order
78
78
  * @param args.marketId - The ID of the Market
package/dist/trade.js CHANGED
@@ -196,11 +196,12 @@ class Trade {
196
196
  * @param args.amount - The amount of the Order
197
197
  * @param args.orderDirection - The direction of the Order
198
198
  */
199
- marketBidOrder({ marketId, amount, orderDirection }) {
199
+ marketBidOrder({ marketId, amount, customerId, orderDirection }) {
200
200
  return __awaiter(this, void 0, void 0, function* () {
201
201
  const marketPDA = (0, pda_1.getMarketPDA)(this.program.programId, marketId);
202
202
  const ixs = [];
203
203
  const addressLookupTableAccounts = [];
204
+ const customer = yield (0, helpers_1.getCustomerById)(this.program, customerId);
204
205
  const orderBook = yield this.getOrderBook(marketId);
205
206
  let remainingUSDC = new bn_js_1.default(amount * Math.pow(10, constants_1.BASE_DECIMALS));
206
207
  const orders = Object.keys(orderDirection)[0] === 'hype'
@@ -215,7 +216,7 @@ class Trade {
215
216
  }
216
217
  const orderPrice = new bn_js_1.default(order.price);
217
218
  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, 500);
219
+ const effectivePriceDecimal = (0, feeCalculator_1.applyBuyFee)(orderPrice.toNumber() / 1000000, 500, customer.marketFeeBps);
219
220
  const adjustedPrice = new bn_js_1.default(Math.floor(effectivePriceDecimal * 1000000));
220
221
  const maxSharesForPrice = remainingUSDC
221
222
  .mul(new bn_js_1.default(Math.pow(10, constants_1.BASE_DECIMALS)))
@@ -244,7 +245,8 @@ class Trade {
244
245
  orderBook: (0, pda_1.getOrderBookPDA)(this.program.programId, marketId),
245
246
  bookOrderAskAuthority: new web3_js_1.PublicKey(order.authority),
246
247
  order: (0, pda_1.getOrderPDA)(this.program.programId, this.program.provider.publicKey, marketId, (0, helpers_1.getOrderDirection)(orderDirection)),
247
- oppositeOrder: (0, pda_1.getOrderPDA)(this.program.programId, new web3_js_1.PublicKey(order.authority), marketId, (0, helpers_1.getOrderDirection)(oppositeOrderDirection))
248
+ oppositeOrder: (0, pda_1.getOrderPDA)(this.program.programId, new web3_js_1.PublicKey(order.authority), marketId, (0, helpers_1.getOrderDirection)(oppositeOrderDirection)),
249
+ customer: (0, pda_1.getCustomerPDA)(this.program.programId, customerId)
248
250
  })
249
251
  .instruction());
250
252
  remainingUSDC = remainingUSDC.sub(usdcAmount);
@@ -262,11 +264,12 @@ class Trade {
262
264
  * @param args.bookOrderBidId - The ID of the Bid Order
263
265
  * @param args.orderDirection - The direction of the Order
264
266
  */
265
- marketAskOrder({ marketId, shares, orderDirection }) {
267
+ marketAskOrder({ marketId, shares, orderDirection, customerId }) {
266
268
  return __awaiter(this, void 0, void 0, function* () {
267
269
  const marketPDA = (0, pda_1.getMarketPDA)(this.program.programId, marketId);
268
270
  const ixs = [];
269
271
  const addressLookupTableAccounts = [];
272
+ const customer = yield (0, helpers_1.getCustomerById)(this.program, customerId);
270
273
  const orderBook = yield this.getOrderBook(marketId);
271
274
  const bidOrders = Object.keys(orderDirection)[0] === 'hype'
272
275
  ? orderBook.hype.bid
@@ -287,7 +290,7 @@ class Trade {
287
290
  continue;
288
291
  remainingShares = remainingShares.sub(sharesToSell);
289
292
  const orderPrice = new bn_js_1.default(order.price);
290
- const effectivePriceDecimal = (0, feeCalculator_1.applySellFee)(orderPrice.toNumber() / 1000000, 500);
293
+ const effectivePriceDecimal = (0, feeCalculator_1.applySellFee)(orderPrice.toNumber() / 1000000, 500, customer.marketFeeBps);
291
294
  const adjustedPrice = new bn_js_1.default(Math.floor(effectivePriceDecimal * 1000000));
292
295
  amountOfUSDC = amountOfUSDC.add(sharesToSell.mul(adjustedPrice).div(new bn_js_1.default(Math.pow(10, constants_1.BASE_DECIMALS))));
293
296
  ixs.push(yield this.program.methods
@@ -304,7 +307,8 @@ class Trade {
304
307
  orderBook: (0, pda_1.getOrderBookPDA)(this.program.programId, marketId),
305
308
  marketAta: (0, pda_1.getTokenATA)(marketPDA, constants_1.USDC_MINT, spl_token_1.TOKEN_PROGRAM_ID),
306
309
  bidOrder: (0, pda_1.getOrderPDA)(this.program.programId, new web3_js_1.PublicKey(order.authority), marketId, (0, helpers_1.getOrderDirection)(orderDirection)),
307
- askOrder: (0, pda_1.getOrderPDA)(this.program.programId, this.program.provider.publicKey, marketId, (0, helpers_1.getOrderDirection)(orderDirection))
310
+ askOrder: (0, pda_1.getOrderPDA)(this.program.programId, this.program.provider.publicKey, marketId, (0, helpers_1.getOrderDirection)(orderDirection)),
311
+ customer: customer.address
308
312
  })
309
313
  .instruction());
310
314
  }
@@ -7,6 +7,8 @@ export type Customer = {
7
7
  feeBps: number;
8
8
  isVerified: boolean;
9
9
  address: string;
10
+ marketFeeBps: number;
11
+ payoutFeeBps: number;
10
12
  };
11
13
  export type CreateCustomerArgs = {
12
14
  id: number;
@@ -14,4 +16,6 @@ export type CreateCustomerArgs = {
14
16
  authority: PublicKey;
15
17
  feeRecipient: PublicKey;
16
18
  feeBps: number;
19
+ marketFeeBps: number;
20
+ payoutFeeBps: number;
17
21
  };
@@ -1317,6 +1317,10 @@
1317
1317
  "name": "order_book",
1318
1318
  "writable": true
1319
1319
  },
1320
+ {
1321
+ "name": "customer",
1322
+ "writable": true
1323
+ },
1320
1324
  {
1321
1325
  "name": "ask_order",
1322
1326
  "writable": true
@@ -1412,6 +1416,10 @@
1412
1416
  "name": "order_book",
1413
1417
  "writable": true
1414
1418
  },
1419
+ {
1420
+ "name": "customer",
1421
+ "writable": true
1422
+ },
1415
1423
  {
1416
1424
  "name": "order",
1417
1425
  "writable": true
@@ -2137,6 +2145,48 @@
2137
2145
  ],
2138
2146
  "args": []
2139
2147
  },
2148
+ {
2149
+ "name": "update_customer",
2150
+ "discriminator": [158, 118, 103, 177, 241, 229, 169, 124],
2151
+ "accounts": [
2152
+ {
2153
+ "name": "signer",
2154
+ "writable": true,
2155
+ "signer": true
2156
+ },
2157
+ {
2158
+ "name": "customer",
2159
+ "writable": true,
2160
+ "pda": {
2161
+ "seeds": [
2162
+ {
2163
+ "kind": "const",
2164
+ "value": [99, 117, 115, 116, 111, 109, 101, 114]
2165
+ },
2166
+ {
2167
+ "kind": "account",
2168
+ "path": "customer.id",
2169
+ "account": "Customer"
2170
+ }
2171
+ ]
2172
+ }
2173
+ },
2174
+ {
2175
+ "name": "system_program",
2176
+ "address": "11111111111111111111111111111111"
2177
+ }
2178
+ ],
2179
+ "args": [
2180
+ {
2181
+ "name": "args",
2182
+ "type": {
2183
+ "defined": {
2184
+ "name": "UpdateCustomerArgs"
2185
+ }
2186
+ }
2187
+ }
2188
+ ]
2189
+ },
2140
2190
  {
2141
2191
  "name": "update_market_end",
2142
2192
  "discriminator": [10, 188, 22, 219, 206, 83, 67, 31],
@@ -3131,6 +3181,14 @@
3131
3181
  {
3132
3182
  "name": "fee_bps",
3133
3183
  "type": "u16"
3184
+ },
3185
+ {
3186
+ "name": "market_fee_bps",
3187
+ "type": "u16"
3188
+ },
3189
+ {
3190
+ "name": "payout_fee_bps",
3191
+ "type": "u16"
3134
3192
  }
3135
3193
  ]
3136
3194
  }
@@ -3272,10 +3330,18 @@
3272
3330
  "name": "is_verified",
3273
3331
  "type": "bool"
3274
3332
  },
3333
+ {
3334
+ "name": "market_fee_bps",
3335
+ "type": "u16"
3336
+ },
3337
+ {
3338
+ "name": "payout_fee_bps",
3339
+ "type": "u16"
3340
+ },
3275
3341
  {
3276
3342
  "name": "padding",
3277
3343
  "type": {
3278
- "array": ["u8", 29]
3344
+ "array": ["u8", 25]
3279
3345
  }
3280
3346
  }
3281
3347
  ]
@@ -4450,6 +4516,26 @@
4450
4516
  ]
4451
4517
  }
4452
4518
  },
4519
+ {
4520
+ "name": "UpdateCustomerArgs",
4521
+ "type": {
4522
+ "kind": "struct",
4523
+ "fields": [
4524
+ {
4525
+ "name": "market_fee_bps",
4526
+ "type": {
4527
+ "option": "u16"
4528
+ }
4529
+ },
4530
+ {
4531
+ "name": "payout_fee_bps",
4532
+ "type": {
4533
+ "option": "u16"
4534
+ }
4535
+ }
4536
+ ]
4537
+ }
4538
+ },
4453
4539
  {
4454
4540
  "name": "VerificationLevel",
4455
4541
  "docs": [
@@ -35,10 +35,12 @@ export type CancelAskOrderArgs = {
35
35
  export type MarketBidOrderArgs = {
36
36
  marketId: number;
37
37
  amount: number;
38
+ customerId: number;
38
39
  orderDirection: OrderDirectionEncoded;
39
40
  };
40
41
  export type MarketAskOrderArgs = {
41
42
  marketId: number;
42
43
  shares: number;
44
+ customerId: number;
43
45
  orderDirection: OrderDirectionEncoded;
44
46
  };
@@ -1851,6 +1851,10 @@ export type TriadProtocol = {
1851
1851
  name: 'orderBook';
1852
1852
  writable: true;
1853
1853
  },
1854
+ {
1855
+ name: 'customer';
1856
+ writable: true;
1857
+ },
1854
1858
  {
1855
1859
  name: 'askOrder';
1856
1860
  writable: true;
@@ -1975,6 +1979,10 @@ export type TriadProtocol = {
1975
1979
  name: 'orderBook';
1976
1980
  writable: true;
1977
1981
  },
1982
+ {
1983
+ name: 'customer';
1984
+ writable: true;
1985
+ },
1978
1986
  {
1979
1987
  name: 'order';
1980
1988
  writable: true;
@@ -3043,6 +3051,48 @@ export type TriadProtocol = {
3043
3051
  ];
3044
3052
  args: [];
3045
3053
  },
3054
+ {
3055
+ name: 'updateCustomer';
3056
+ discriminator: [158, 118, 103, 177, 241, 229, 169, 124];
3057
+ accounts: [
3058
+ {
3059
+ name: 'signer';
3060
+ writable: true;
3061
+ signer: true;
3062
+ },
3063
+ {
3064
+ name: 'customer';
3065
+ writable: true;
3066
+ pda: {
3067
+ seeds: [
3068
+ {
3069
+ kind: 'const';
3070
+ value: [99, 117, 115, 116, 111, 109, 101, 114];
3071
+ },
3072
+ {
3073
+ kind: 'account';
3074
+ path: 'customer.id';
3075
+ account: 'customer';
3076
+ }
3077
+ ];
3078
+ };
3079
+ },
3080
+ {
3081
+ name: 'systemProgram';
3082
+ address: '11111111111111111111111111111111';
3083
+ }
3084
+ ];
3085
+ args: [
3086
+ {
3087
+ name: 'args';
3088
+ type: {
3089
+ defined: {
3090
+ name: 'updateCustomerArgs';
3091
+ };
3092
+ };
3093
+ }
3094
+ ];
3095
+ },
3046
3096
  {
3047
3097
  name: 'updateMarketEnd';
3048
3098
  discriminator: [10, 188, 22, 219, 206, 83, 67, 31];
@@ -4135,6 +4185,14 @@ export type TriadProtocol = {
4135
4185
  {
4136
4186
  name: 'feeBps';
4137
4187
  type: 'u16';
4188
+ },
4189
+ {
4190
+ name: 'marketFeeBps';
4191
+ type: 'u16';
4192
+ },
4193
+ {
4194
+ name: 'payoutFeeBps';
4195
+ type: 'u16';
4138
4196
  }
4139
4197
  ];
4140
4198
  };
@@ -4276,10 +4334,18 @@ export type TriadProtocol = {
4276
4334
  name: 'isVerified';
4277
4335
  type: 'bool';
4278
4336
  },
4337
+ {
4338
+ name: 'marketFeeBps';
4339
+ type: 'u16';
4340
+ },
4341
+ {
4342
+ name: 'payoutFeeBps';
4343
+ type: 'u16';
4344
+ },
4279
4345
  {
4280
4346
  name: 'padding';
4281
4347
  type: {
4282
- array: ['u8', 29];
4348
+ array: ['u8', 25];
4283
4349
  };
4284
4350
  }
4285
4351
  ];
@@ -5454,6 +5520,26 @@ export type TriadProtocol = {
5454
5520
  ];
5455
5521
  };
5456
5522
  },
5523
+ {
5524
+ name: 'updateCustomerArgs';
5525
+ type: {
5526
+ kind: 'struct';
5527
+ fields: [
5528
+ {
5529
+ name: 'marketFeeBps';
5530
+ type: {
5531
+ option: 'u16';
5532
+ };
5533
+ },
5534
+ {
5535
+ name: 'payoutFeeBps';
5536
+ type: {
5537
+ option: 'u16';
5538
+ };
5539
+ }
5540
+ ];
5541
+ };
5542
+ },
5457
5543
  {
5458
5544
  name: 'verificationLevel';
5459
5545
  docs: [
@@ -2,32 +2,42 @@
2
2
  * Calculate dynamic fee based on price
3
3
  * Returns fee in basis points (bps)
4
4
  */
5
- export declare function calculateDynamicFeeBps(price: number, feeBps: number): number;
5
+ export declare function calculateDynamicFeeBps(price: number, feeBps: number, customerMarketFeeBps: number): number;
6
+ /**
7
+ * Calculate tiered fixed fee based on entry amount (USDC)
8
+ */
9
+ export declare function calculateFixedFee(amount: number): number;
6
10
  /**
7
11
  * Apply dynamic fee to price for buy orders (adds fee)
8
12
  */
9
- export declare function applyBuyFee(price: number, feeBps: number): number;
13
+ export declare function applyBuyFee(price: number, feeBps: number, customerMarketFeeBps: number): number;
10
14
  /**
11
15
  * Apply dynamic fee to price for sell orders (subtracts fee)
12
16
  */
13
- export declare function applySellFee(price: number, feeBps: number): number;
17
+ export declare function applySellFee(price: number, feeBps: number, customerMarketFeeBps: number): number;
14
18
  /**
15
19
  * Simulate a buy order with given amount and price
16
20
  */
17
- export declare function simulateBuyOrder(amount: number, price: number, feeBps: number): {
21
+ export declare function simulateBuyOrder(amount: number, price: number, feeBps: number, customerMarketFeeBps: number): {
18
22
  entryPrice: number;
19
23
  effectivePrice: number;
20
24
  sharesReceived: number;
21
25
  feeAmount: number;
22
26
  feePercentage: number;
27
+ fixedFee: number;
28
+ volumeFee: number;
29
+ realEntryPrice: number;
23
30
  };
24
31
  /**
25
32
  * Simulate a sell order with given shares and price
26
33
  */
27
- export declare function simulateSellOrder(shares: number, price: number, feeBps: number): {
34
+ export declare function simulateSellOrder(shares: number, price: number, feeBps: number, customerMarketFeeBps: number): {
28
35
  entryPrice: number;
29
36
  effectivePrice: number;
30
37
  sharesReceived: number;
31
38
  feeAmount: number;
32
39
  feePercentage: number;
40
+ fixedFee: number;
41
+ volumeFee: number;
42
+ realEntryPrice: number;
33
43
  };
@@ -1,23 +1,45 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.simulateSellOrder = exports.simulateBuyOrder = exports.applySellFee = exports.applyBuyFee = exports.calculateDynamicFeeBps = void 0;
3
+ exports.simulateSellOrder = exports.simulateBuyOrder = exports.applySellFee = exports.applyBuyFee = exports.calculateFixedFee = exports.calculateDynamicFeeBps = void 0;
4
4
  /**
5
5
  * Calculate dynamic fee based on price
6
6
  * Returns fee in basis points (bps)
7
7
  */
8
- function calculateDynamicFeeBps(price, feeBps) {
8
+ function calculateDynamicFeeBps(price, feeBps, customerMarketFeeBps) {
9
9
  const internalPrice = price * Math.pow(10, 6);
10
10
  if (internalPrice < 900000) {
11
- return feeBps;
11
+ return feeBps + customerMarketFeeBps;
12
12
  }
13
13
  return Math.max(Math.floor(((990000 - internalPrice) * 1900) / internalPrice), 90);
14
14
  }
15
15
  exports.calculateDynamicFeeBps = calculateDynamicFeeBps;
16
+ /**
17
+ * Calculate tiered fixed fee based on entry amount (USDC)
18
+ */
19
+ function calculateFixedFee(amount) {
20
+ const internalAmount = Math.floor(amount * 1000000);
21
+ if (internalAmount >= 100000000) {
22
+ return 2.5;
23
+ }
24
+ else if (internalAmount >= 50000000) {
25
+ return 1.5;
26
+ }
27
+ else if (internalAmount >= 20000000) {
28
+ return 0.75;
29
+ }
30
+ else if (internalAmount >= 5000000) {
31
+ return 0.3;
32
+ }
33
+ else {
34
+ return 0.15;
35
+ }
36
+ }
37
+ exports.calculateFixedFee = calculateFixedFee;
16
38
  /**
17
39
  * Apply dynamic fee to price for buy orders (adds fee)
18
40
  */
19
- function applyBuyFee(price, feeBps) {
20
- const dynamicFeeBps = calculateDynamicFeeBps(price, feeBps);
41
+ function applyBuyFee(price, feeBps, customerMarketFeeBps) {
42
+ const dynamicFeeBps = calculateDynamicFeeBps(price, feeBps, customerMarketFeeBps);
21
43
  const internalPrice = Math.floor(price * 1000000);
22
44
  const effectiveInternalPrice = Math.floor((internalPrice * (10000 + dynamicFeeBps)) / 10000);
23
45
  const clampedPrice = Math.min(effectiveInternalPrice, 999999);
@@ -27,8 +49,8 @@ exports.applyBuyFee = applyBuyFee;
27
49
  /**
28
50
  * Apply dynamic fee to price for sell orders (subtracts fee)
29
51
  */
30
- function applySellFee(price, feeBps) {
31
- const dynamicFeeBps = calculateDynamicFeeBps(price, feeBps);
52
+ function applySellFee(price, feeBps, customerMarketFeeBps) {
53
+ const dynamicFeeBps = calculateDynamicFeeBps(price, feeBps, customerMarketFeeBps);
32
54
  const internalPrice = Math.floor(price * 1000000);
33
55
  const effectiveInternalPrice = Math.floor((internalPrice * (10000 - dynamicFeeBps)) / 10000);
34
56
  const clampedPrice = Math.max(effectiveInternalPrice, 1);
@@ -38,36 +60,44 @@ exports.applySellFee = applySellFee;
38
60
  /**
39
61
  * Simulate a buy order with given amount and price
40
62
  */
41
- function simulateBuyOrder(amount, price, feeBps) {
42
- const effectivePrice = applyBuyFee(price, feeBps);
43
- const sharesReceived = amount / effectivePrice;
63
+ function simulateBuyOrder(amount, price, feeBps, customerMarketFeeBps) {
64
+ const fixedFee = calculateFixedFee(amount);
65
+ const amountAfterFixedFee = amount - fixedFee;
66
+ const effectivePrice = applyBuyFee(price, feeBps, customerMarketFeeBps);
67
+ const sharesReceived = amountAfterFixedFee / effectivePrice;
44
68
  const valueAtOriginalPrice = sharesReceived * price;
45
69
  const feeAmount = amount - valueAtOriginalPrice;
46
- const feePercentage = (feeAmount / amount) * 100;
47
70
  return {
48
71
  entryPrice: price,
49
72
  effectivePrice,
50
73
  sharesReceived,
51
74
  feeAmount,
52
- feePercentage
75
+ feePercentage: (feeAmount / amount) * 100,
76
+ fixedFee,
77
+ volumeFee: feeAmount - fixedFee,
78
+ realEntryPrice: amount / sharesReceived
53
79
  };
54
80
  }
55
81
  exports.simulateBuyOrder = simulateBuyOrder;
56
82
  /**
57
83
  * Simulate a sell order with given shares and price
58
84
  */
59
- function simulateSellOrder(shares, price, feeBps) {
60
- const effectivePrice = applySellFee(price, feeBps);
61
- const amountReceived = shares * effectivePrice;
85
+ function simulateSellOrder(shares, price, feeBps, customerMarketFeeBps) {
86
+ const effectivePrice = applySellFee(price, feeBps, customerMarketFeeBps);
87
+ const amountToReceiveBeforeFixed = shares * effectivePrice;
62
88
  const valueAtOriginalPrice = shares * price;
89
+ const fixedFee = calculateFixedFee(valueAtOriginalPrice);
90
+ const amountReceived = amountToReceiveBeforeFixed - fixedFee;
63
91
  const feeAmount = valueAtOriginalPrice - amountReceived;
64
- const feePercentage = (feeAmount / valueAtOriginalPrice) * 100;
65
92
  return {
66
93
  entryPrice: price,
67
94
  effectivePrice,
68
95
  sharesReceived: shares,
69
96
  feeAmount,
70
- feePercentage
97
+ feePercentage: (feeAmount / valueAtOriginalPrice) * 100,
98
+ fixedFee,
99
+ volumeFee: feeAmount - fixedFee,
100
+ realEntryPrice: amountReceived / shares
71
101
  };
72
102
  }
73
103
  exports.simulateSellOrder = simulateSellOrder;
@@ -1,5 +1,5 @@
1
1
  import { PublicKey } from '@solana/web3.js';
2
- import { BN, IdlAccounts } from '@coral-xyz/anchor';
2
+ import { BN, IdlAccounts, Program } 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';
@@ -29,3 +29,4 @@ export declare const getOppositeOrderDirectionEncoded: (orderDirection: OrderDir
29
29
  export declare const formatPredictor: (account: IdlAccounts<TriadProtocol>['predictor'], publicKey: PublicKey, balance: BN) => Predictor;
30
30
  export declare const getPriceFeedAccountForProgram: (priceFeedId: string) => PublicKey;
31
31
  export declare const getFeedIdFromHex: (input?: string) => PublicKey | null;
32
+ export declare const getCustomerById: (program: Program<TriadProtocol>, customerId: number) => Promise<Customer>;
@@ -1,9 +1,19 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getFeedIdFromHex = exports.getPriceFeedAccountForProgram = 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;
12
+ exports.getCustomerById = exports.getFeedIdFromHex = exports.getPriceFeedAccountForProgram = 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
13
  const web3_js_1 = require("@solana/web3.js");
5
14
  const spl_token_1 = require("@solana/spl-token");
6
15
  const types_1 = require("../types");
16
+ const pda_1 = require("./pda");
7
17
  const constants_1 = require("./constants");
8
18
  const encodeString = (value, alloc = 32) => {
9
19
  const buffer = Buffer.alloc(alloc, 32);
@@ -145,6 +155,8 @@ const formatCustomer = (account, publicKey) => {
145
155
  name: account.name,
146
156
  feeRecipient: account.feeRecipient.toString(),
147
157
  feeBps: account.feeBps,
158
+ marketFeeBps: account.marketFeeBps,
159
+ payoutFeeBps: account.payoutFeeBps,
148
160
  isVerified: account.isVerified,
149
161
  address: publicKey.toString()
150
162
  };
@@ -289,3 +301,9 @@ const getFeedIdFromHex = (input) => {
289
301
  return new web3_js_1.PublicKey(feedId);
290
302
  };
291
303
  exports.getFeedIdFromHex = getFeedIdFromHex;
304
+ const getCustomerById = (program, customerId) => __awaiter(void 0, void 0, void 0, function* () {
305
+ const customerPDA = (0, pda_1.getCustomerPDA)(program.programId, customerId);
306
+ const customer = yield program.account.customer.fetch(customerPDA, program.provider.connection.commitment);
307
+ return (0, exports.formatCustomer)(customer, customerPDA);
308
+ });
309
+ exports.getCustomerById = getCustomerById;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@triadxyz/triad-protocol",
3
- "version": "4.1.8",
3
+ "version": "4.1.9",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",