@triadxyz/triad-protocol 2.9.4-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.js CHANGED
@@ -912,6 +912,8 @@ class TriadProtocolClient {
912
912
  const usdcAmount = sharesToBuy
913
913
  .mul(adjustedPrice)
914
914
  .div(new bn_js_1.default(Math.pow(10, this.decimals)));
915
+ if (usdcAmount.lte(new bn_js_1.default(0)))
916
+ continue;
915
917
  totalUSDCNeeded = totalUSDCNeeded.add(usdcAmount);
916
918
  tempRemainingUSDC = tempRemainingUSDC.sub(usdcAmount);
917
919
  }
@@ -950,15 +952,17 @@ class TriadProtocolClient {
950
952
  .div(new bn_js_1.default(1000000));
951
953
  adjustedPrice = orderPrice.add(fee);
952
954
  }
953
- const maxSharesForPrice = remainingUSDC
955
+ const maxSharesForPrice = (0, helpers_1.roundUp)(remainingUSDC)
954
956
  .mul(new bn_js_1.default(Math.pow(10, this.decimals)))
955
957
  .div(adjustedPrice);
956
- const sharesToBuy = bn_js_1.default.min(maxSharesForPrice, availableShares);
958
+ const sharesToBuy = bn_js_1.default.min((0, helpers_1.roundUp)(maxSharesForPrice), availableShares);
957
959
  if (sharesToBuy.lte(new bn_js_1.default(0)))
958
960
  continue;
959
961
  const usdcAmount = sharesToBuy
960
962
  .mul(adjustedPrice)
961
963
  .div(new bn_js_1.default(Math.pow(10, this.decimals)));
964
+ if (usdcAmount.lte(new bn_js_1.default(0)))
965
+ continue;
962
966
  ixs.push(yield this.program.methods
963
967
  .marketBidOrder({
964
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@triadxyz/triad-protocol",
3
- "version": "2.9.4-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",