@triadxyz/triad-protocol 2.9.3-beta → 2.9.5-beta

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
@@ -69,6 +69,12 @@ export default class TriadProtocolClient {
69
69
  *
70
70
  */
71
71
  getCustomerByWallet(wallet: PublicKey): Promise<import("./types").Customer>;
72
+ /**
73
+ * Get Customer By ID
74
+ * @param customerId - The ID of the customer
75
+ *
76
+ */
77
+ getCustomerById(customerId: number): Promise<import("./types").Customer>;
72
78
  /**
73
79
  * Get Refer By Wallet Address
74
80
  * @param wallet - The wallet address of the refer
package/dist/index.js CHANGED
@@ -166,6 +166,18 @@ class TriadProtocolClient {
166
166
  return (0, helpers_1.formatCustomer)(customer.account, customer.publicKey);
167
167
  });
168
168
  }
169
+ /**
170
+ * Get Customer By ID
171
+ * @param customerId - The ID of the customer
172
+ *
173
+ */
174
+ getCustomerById(customerId) {
175
+ return __awaiter(this, void 0, void 0, function* () {
176
+ const customerPDA = (0, pda_1.getCustomerPDA)(this.program.programId, customerId);
177
+ const customer = yield this.program.account.customer.fetch(customerPDA);
178
+ return (0, helpers_1.formatCustomer)(customer, customerPDA);
179
+ });
180
+ }
169
181
  /**
170
182
  * Get Refer By Wallet Address
171
183
  * @param wallet - The wallet address of the refer
@@ -900,6 +912,8 @@ class TriadProtocolClient {
900
912
  const usdcAmount = sharesToBuy
901
913
  .mul(adjustedPrice)
902
914
  .div(new bn_js_1.default(Math.pow(10, this.decimals)));
915
+ if (usdcAmount.lte(new bn_js_1.default(0)))
916
+ continue;
903
917
  totalUSDCNeeded = totalUSDCNeeded.add(usdcAmount);
904
918
  tempRemainingUSDC = tempRemainingUSDC.sub(usdcAmount);
905
919
  }
@@ -938,15 +952,17 @@ class TriadProtocolClient {
938
952
  .div(new bn_js_1.default(1000000));
939
953
  adjustedPrice = orderPrice.add(fee);
940
954
  }
941
- const maxSharesForPrice = remainingUSDC
955
+ const maxSharesForPrice = (0, helpers_1.roundUp)(remainingUSDC)
942
956
  .mul(new bn_js_1.default(Math.pow(10, this.decimals)))
943
957
  .div(adjustedPrice);
944
- const sharesToBuy = bn_js_1.default.min(maxSharesForPrice, availableShares);
958
+ const sharesToBuy = bn_js_1.default.min((0, helpers_1.roundUp)(maxSharesForPrice), availableShares);
945
959
  if (sharesToBuy.lte(new bn_js_1.default(0)))
946
960
  continue;
947
961
  const usdcAmount = sharesToBuy
948
962
  .mul(adjustedPrice)
949
963
  .div(new bn_js_1.default(Math.pow(10, this.decimals)));
964
+ if (usdcAmount.lte(new bn_js_1.default(0)))
965
+ continue;
950
966
  ixs.push(yield this.program.methods
951
967
  .marketBidOrder({
952
968
  amount: new bn_js_1.default(usdcAmount),
@@ -3,6 +3,7 @@ import { IdlAccounts } from '@coral-xyz/anchor';
3
3
  import { Stake, StakeVault, Unstake } from './../types/stake';
4
4
  import { Market, Order, OrderDirection, OrderSide, OrderStatus, OrderType, UserTrade, Pool, BookOrder, Refer, Customer } from '../types';
5
5
  import { TriadProtocol } from '../types/triad_protocol';
6
+ import { BN } from '@coral-xyz/anchor';
6
7
  export declare const encodeString: (value: string, alloc?: number) => number[];
7
8
  export declare const decodeString: (bytes: number[]) => string;
8
9
  export declare const formatStakeVault: (stakeVault: IdlAccounts<TriadProtocol>['stakeVault']) => StakeVault;
@@ -47,3 +48,4 @@ export declare const getOrderStatus: (status: {
47
48
  }) => OrderStatus;
48
49
  export declare const formatRefer: (account: IdlAccounts<TriadProtocol>['refer']) => Refer;
49
50
  export declare const formatCustomer: (account: IdlAccounts<TriadProtocol>['customer'], publicKey: PublicKey) => Customer;
51
+ export declare const roundUp: (value: BN) => BN;
@@ -1,10 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.formatCustomer = exports.formatRefer = exports.getOrderStatus = exports.getOrderSide = exports.getOrderType = exports.getOrderSideFromNumber = exports.getOrderDirectionFromNumber = exports.getOrderDirection = exports.getTokenProgram = exports.calculateStakeRewards = exports.formatBookOrder = exports.formatOrder = exports.formatUserTrade = exports.formatMarket = exports.formatPool = exports.formatUnstake = exports.formatStake = exports.formatStakeVault = exports.decodeString = exports.encodeString = void 0;
3
+ exports.roundUp = exports.formatCustomer = exports.formatRefer = exports.getOrderStatus = exports.getOrderSide = exports.getOrderType = exports.getOrderSideFromNumber = exports.getOrderDirectionFromNumber = exports.getOrderDirection = exports.getTokenProgram = exports.calculateStakeRewards = exports.formatBookOrder = exports.formatOrder = exports.formatUserTrade = 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");
7
7
  const constants_1 = require("./constants");
8
+ const anchor_1 = require("@coral-xyz/anchor");
8
9
  const encodeString = (value, alloc = 32) => {
9
10
  const buffer = Buffer.alloc(alloc, 32);
10
11
  buffer.write(value);
@@ -248,3 +249,9 @@ const formatCustomer = (account, publicKey) => {
248
249
  };
249
250
  };
250
251
  exports.formatCustomer = formatCustomer;
252
+ const roundUp = (value) => {
253
+ let decimal = value.toNumber() / 1000000;
254
+ let rounded = Math.round(decimal * 100) / 100;
255
+ return new anchor_1.BN(rounded * 1000000);
256
+ };
257
+ exports.roundUp = roundUp;
@@ -20,7 +20,7 @@ const getOrderBookPDA = (programId, marketId) => {
20
20
  };
21
21
  exports.getOrderBookPDA = getOrderBookPDA;
22
22
  const getCustomerPDA = (programId, customerId) => {
23
- return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('customer'), new bn_js_1.default(customerId).toArrayLike(Buffer, 'le', 8)], programId)[0];
23
+ return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('customer'), new bn_js_1.default(customerId).toArrayLike(Buffer, 'le', 2)], programId)[0];
24
24
  };
25
25
  exports.getCustomerPDA = getCustomerPDA;
26
26
  const getUserTradePDA = (programId, wallet) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@triadxyz/triad-protocol",
3
- "version": "2.9.3-beta",
3
+ "version": "2.9.5-beta",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",