@myx-trade/sdk 0.1.34 → 0.1.36

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
@@ -1467,14 +1467,14 @@ function isSupportedChainFn(chainId2) {
1467
1467
  // src/config/address/ARB_TEST_SEPOLIA.ts
1468
1468
  var import_ethers = require("ethers");
1469
1469
  var ARB_TEST_SEPOLIA = {
1470
- USDC: "",
1471
- POOL_MANAGER: "0x29fA92d5f47051E49Ab9001A3cbd8091c34c5638",
1472
- Account: "0x900F3003c59b9c55A09CEB7b3134A53E511531C3",
1470
+ USDC: "0x7E248Ec1721639413A280d9E82e2862Cae2E6E28",
1471
+ POOL_MANAGER: "0xA4A1dfbe40cB725A79D34bd529f0C1b54AB46954",
1472
+ Account: "0x6136899e8c77C452bc46AcD786aA2C09fD31f947",
1473
1473
  POOL_VIEW: "",
1474
1474
  HYPER_VAULT: import_ethers.ZeroAddress,
1475
1475
  FEE_COLLECTOR: "",
1476
- POSITION_MANAGER: "0x520435fA110549aE7eA1894839575a62cbF5A8D5",
1477
- ORDER_MANAGER: "0x4eDe4E20162551F293B9D6f33E8567314fb5612f",
1476
+ POSITION_MANAGER: "0x002F28be205E9A1e279d2eeF1f5e472CeA1d910C",
1477
+ ORDER_MANAGER: "0x3A3C7c4588Fb2aE46A4108994a47712E03F96B23",
1478
1478
  TRUSTED_FORWARDER: "",
1479
1479
  FRONT_FACET: "",
1480
1480
  // router address
@@ -1483,21 +1483,19 @@ var ARB_TEST_SEPOLIA = {
1483
1483
  FAUCET: "",
1484
1484
  UI_POOL_DATA_PROVIDER: "",
1485
1485
  UI_POSITION_DATA_PROVIDER: "",
1486
- PYTH: "0x4374e5a8b9C22271E9EB878A2AA31DE97DF15DAF",
1486
+ PYTH: "0x361360Def495BfB4F0BE59AB11878D042c458155",
1487
1487
  // !!! 非Pyth Adapter
1488
1488
  MYX: import_ethers.ZeroAddress,
1489
1489
  ERC20: "0x7E248Ec1721639413A280d9E82e2862Cae2E6E28",
1490
- LIQUIDITY_ROUTER: "0x3533595E0546CCA3CEa58bD23f2733BbCE057F44",
1491
- BASE_POOL: "0x4b86814b748D2ae323a8449b98C5add6D07901F3",
1492
- QUOTE_POOL: "0x22342d91b372ED991aB5A93bdC31706E4971Cec2",
1493
- BROKER: "0x461A33C5E75c292A45f8c961ab816060a94AfbA0",
1494
- // MYXBroker
1495
- ORACLE: "0x38aC036082810F43f83c2bca0Ab2518703d74738",
1490
+ LIQUIDITY_ROUTER: "0xd185C3f675d991735FCF6885Ff6BADE02A21313d",
1491
+ BASE_POOL: "0x2c6AdaE4A01836487842b7369c1db3F441871E83",
1492
+ QUOTE_POOL: "0xe1Ff495206635570A8Eaf9517125Ce66a2d09d32",
1493
+ ORACLE: "0x574001F6cB520b15d5a6db9F7B7a0ebf1A8E25c0",
1496
1494
  // MYXOracle
1497
- EIP7702Delegation: "0xDec0Eb393c362e459B124F4A27E21BCD10D45B41",
1498
- MARKET_MANAGER: "0x26645ba85E6294f4AE4605C56967B0A16BcB9cBb",
1499
- DATA_PROVIDER: "0xc4472860fA175d0E8b5a73620778799469232763",
1500
- ORACLE_RESERVE: "0x513AE26EdD58E1fD209c68Ed790585fFb08Fd740"
1495
+ EIP7702Delegation: "0x4e1B9aDf5Aa4a893f578c8502E6E28841b2403f3",
1496
+ MARKET_MANAGER: "0x12AD75316A92a66b92c79080c555594314e7aFB3",
1497
+ DATA_PROVIDER: "0x726A4978eDcb974B9889BC6f5Ee2Ec06D703038E",
1498
+ ORACLE_RESERVE: "0xC46b81c38091933f4811EC16E93553f9801EB863"
1501
1499
  };
1502
1500
 
1503
1501
  // src/config/address.ts
@@ -1827,7 +1825,7 @@ var RotationProvider = class extends import_providers.BaseProvider {
1827
1825
  // package.json
1828
1826
  var package_default = {
1829
1827
  name: "@myx-trade/sdk",
1830
- version: "0.1.34",
1828
+ version: "0.1.36",
1831
1829
  private: false,
1832
1830
  publishConfig: {
1833
1831
  access: "public"
@@ -1861,7 +1859,8 @@ var package_default = {
1861
1859
  "publish:patch": "node scripts/publish.js patch",
1862
1860
  "publish:minor": "node scripts/publish.js minor",
1863
1861
  "publish:major": "node scripts/publish.js major",
1864
- "publish:no-bump": "npm run build && npm publish --access public"
1862
+ "publish:no-bump": "npm run build && npm publish --access public",
1863
+ "type-check": "echo 'Skipping type-check for @myx-trade/sdk'"
1865
1864
  },
1866
1865
  keywords: [
1867
1866
  "trading",
@@ -5682,11 +5681,15 @@ var Broker_default = [
5682
5681
  },
5683
5682
  {
5684
5683
  type: "function",
5685
- name: "placeOrder",
5684
+ name: "placeOrderWithPosition",
5686
5685
  constant: false,
5687
5686
  stateMutability: "payable",
5688
5687
  payable: true,
5689
5688
  inputs: [
5689
+ {
5690
+ type: "bytes32",
5691
+ name: "positionId"
5692
+ },
5690
5693
  {
5691
5694
  type: "tuple",
5692
5695
  name: "orderParams",
@@ -5700,8 +5703,100 @@ var Broker_default = [
5700
5703
  name: "poolId"
5701
5704
  },
5702
5705
  {
5703
- type: "uint64",
5704
- name: "userPositionSalt"
5706
+ type: "uint8",
5707
+ name: "orderType"
5708
+ },
5709
+ {
5710
+ type: "uint8",
5711
+ name: "triggerType"
5712
+ },
5713
+ {
5714
+ type: "uint8",
5715
+ name: "operation"
5716
+ },
5717
+ {
5718
+ type: "uint8",
5719
+ name: "direction"
5720
+ },
5721
+ {
5722
+ type: "uint256",
5723
+ name: "collateralAmount"
5724
+ },
5725
+ {
5726
+ type: "uint256",
5727
+ name: "size"
5728
+ },
5729
+ {
5730
+ type: "uint256",
5731
+ name: "price"
5732
+ },
5733
+ {
5734
+ type: "uint8",
5735
+ name: "timeInForce"
5736
+ },
5737
+ {
5738
+ type: "bool",
5739
+ name: "postOnly"
5740
+ },
5741
+ {
5742
+ type: "uint16",
5743
+ name: "slippagePct"
5744
+ },
5745
+ {
5746
+ type: "address",
5747
+ name: "executionFeeToken"
5748
+ },
5749
+ {
5750
+ type: "uint16",
5751
+ name: "leverage"
5752
+ },
5753
+ {
5754
+ type: "uint256",
5755
+ name: "tpSize"
5756
+ },
5757
+ {
5758
+ type: "uint256",
5759
+ name: "tpPrice"
5760
+ },
5761
+ {
5762
+ type: "uint256",
5763
+ name: "slSize"
5764
+ },
5765
+ {
5766
+ type: "uint256",
5767
+ name: "slPrice"
5768
+ },
5769
+ {
5770
+ type: "bool",
5771
+ name: "useAccountBalance"
5772
+ }
5773
+ ]
5774
+ }
5775
+ ],
5776
+ outputs: []
5777
+ },
5778
+ {
5779
+ type: "function",
5780
+ name: "placeOrderWithSalt",
5781
+ constant: false,
5782
+ stateMutability: "payable",
5783
+ payable: true,
5784
+ inputs: [
5785
+ {
5786
+ type: "uint64",
5787
+ name: "userPositionSalt"
5788
+ },
5789
+ {
5790
+ type: "tuple",
5791
+ name: "orderParams",
5792
+ components: [
5793
+ {
5794
+ type: "address",
5795
+ name: "user"
5796
+ },
5797
+ {
5798
+ type: "bytes32",
5799
+ name: "poolId"
5705
5800
  },
5706
5801
  {
5707
5802
  type: "uint8",
@@ -5778,11 +5873,15 @@ var Broker_default = [
5778
5873
  },
5779
5874
  {
5780
5875
  type: "function",
5781
- name: "placeOrders",
5876
+ name: "placeOrdersWithPosition",
5782
5877
  constant: false,
5783
5878
  stateMutability: "payable",
5784
5879
  payable: true,
5785
5880
  inputs: [
5881
+ {
5882
+ type: "bytes32[]",
5883
+ name: "positionIds"
5884
+ },
5786
5885
  {
5787
5886
  type: "tuple[]",
5788
5887
  name: "orderParams",
@@ -5796,8 +5895,100 @@ var Broker_default = [
5796
5895
  name: "poolId"
5797
5896
  },
5798
5897
  {
5799
- type: "uint64",
5800
- name: "userPositionSalt"
5898
+ type: "uint8",
5899
+ name: "orderType"
5900
+ },
5901
+ {
5902
+ type: "uint8",
5903
+ name: "triggerType"
5904
+ },
5905
+ {
5906
+ type: "uint8",
5907
+ name: "operation"
5908
+ },
5909
+ {
5910
+ type: "uint8",
5911
+ name: "direction"
5912
+ },
5913
+ {
5914
+ type: "uint256",
5915
+ name: "collateralAmount"
5916
+ },
5917
+ {
5918
+ type: "uint256",
5919
+ name: "size"
5920
+ },
5921
+ {
5922
+ type: "uint256",
5923
+ name: "price"
5924
+ },
5925
+ {
5926
+ type: "uint8",
5927
+ name: "timeInForce"
5928
+ },
5929
+ {
5930
+ type: "bool",
5931
+ name: "postOnly"
5932
+ },
5933
+ {
5934
+ type: "uint16",
5935
+ name: "slippagePct"
5936
+ },
5937
+ {
5938
+ type: "address",
5939
+ name: "executionFeeToken"
5940
+ },
5941
+ {
5942
+ type: "uint16",
5943
+ name: "leverage"
5944
+ },
5945
+ {
5946
+ type: "uint256",
5947
+ name: "tpSize"
5948
+ },
5949
+ {
5950
+ type: "uint256",
5951
+ name: "tpPrice"
5952
+ },
5953
+ {
5954
+ type: "uint256",
5955
+ name: "slSize"
5956
+ },
5957
+ {
5958
+ type: "uint256",
5959
+ name: "slPrice"
5960
+ },
5961
+ {
5962
+ type: "bool",
5963
+ name: "useAccountBalance"
5964
+ }
5965
+ ]
5966
+ }
5967
+ ],
5968
+ outputs: []
5969
+ },
5970
+ {
5971
+ type: "function",
5972
+ name: "placeOrdersWithSalt",
5973
+ constant: false,
5974
+ stateMutability: "payable",
5975
+ payable: true,
5976
+ inputs: [
5977
+ {
5978
+ type: "uint64[]",
5979
+ name: "userPositionSalts"
5980
+ },
5981
+ {
5982
+ type: "tuple[]",
5983
+ name: "orderParams",
5984
+ components: [
5985
+ {
5986
+ type: "address",
5987
+ name: "user"
5988
+ },
5989
+ {
5990
+ type: "bytes32",
5991
+ name: "poolId"
5801
5992
  },
5802
5993
  {
5803
5994
  type: "uint8",
@@ -12078,6 +12269,13 @@ var SubScription = class {
12078
12269
  var ConfigManager = class {
12079
12270
  // accessToken 过期时间
12080
12271
  constructor(config) {
12272
+ /**
12273
+ * 获取有效的 accessToken,自动处理获取和刷新
12274
+ * @param forceRefresh 是否强制刷新
12275
+ * @returns Promise<string | null> 有效的 accessToken 或 null
12276
+ */
12277
+ this._getAccessTokenQueue = [];
12278
+ this._isGettingAccessToken = false;
12081
12279
  const mergedConfig = {
12082
12280
  isTestnet: false,
12083
12281
  ...config
@@ -12118,13 +12316,36 @@ var ConfigManager = class {
12118
12316
  );
12119
12317
  }
12120
12318
  }
12121
- /**
12122
- * 获取有效的 accessToken,自动处理获取和刷新
12123
- * @param forceRefresh 是否强制刷新
12124
- * @returns Promise<string | null> 有效的 accessToken 或 null
12125
- */
12126
12319
  async getAccessToken(forceRefresh = false) {
12320
+ return new Promise((resolve, reject) => {
12321
+ this._getAccessTokenQueue.push({
12322
+ resolve,
12323
+ reject,
12324
+ forceRefresh
12325
+ });
12326
+ this._processAccessTokenQueue();
12327
+ });
12328
+ }
12329
+ _processAccessTokenQueue() {
12330
+ if (this._isGettingAccessToken) {
12331
+ return;
12332
+ }
12333
+ this._isGettingAccessToken = true;
12334
+ const item = this._getAccessTokenQueue.shift();
12335
+ if (item) {
12336
+ this._getAccessToken(item.forceRefresh).then(item.resolve).catch(item.reject).finally(() => {
12337
+ this._isGettingAccessToken = false;
12338
+ if (this._getAccessTokenQueue.length > 0) {
12339
+ this._processAccessTokenQueue();
12340
+ }
12341
+ });
12342
+ } else {
12343
+ this._isGettingAccessToken = false;
12344
+ }
12345
+ }
12346
+ async _getAccessToken(forceRefresh = false) {
12127
12347
  if (!forceRefresh && this.isAccessTokenValid()) {
12348
+ this._isGettingAccessToken = false;
12128
12349
  return this.accessToken;
12129
12350
  }
12130
12351
  if (!this.config.getAccessToken) {
@@ -12180,7 +12401,7 @@ var ConfigManager = class {
12180
12401
  * @returns boolean token 是否有效
12181
12402
  */
12182
12403
  isAccessTokenValid() {
12183
- if (!this.accessToken || !this.accessTokenExpiry) {
12404
+ if (!this.accessToken || !this.accessTokenExpiry || !this.config.getAccessToken || !this.config.signer) {
12184
12405
  return false;
12185
12406
  }
12186
12407
  return Date.now() < this.accessTokenExpiry;
@@ -12575,7 +12796,7 @@ var Position = class {
12575
12796
  }
12576
12797
  }
12577
12798
  const brokerContract = getContract(
12578
- contractAddress.BROKER,
12799
+ config.brokerAddress,
12579
12800
  Broker_default,
12580
12801
  config.signer
12581
12802
  );
@@ -12671,12 +12892,22 @@ var OrderStatus = {
12671
12892
 
12672
12893
  // src/manager/order/index.ts
12673
12894
  var import_ethers25 = require("ethers");
12895
+ var import_viem = require("viem");
12674
12896
  var Order = class {
12675
12897
  constructor(configManager, logger, utils) {
12676
12898
  this.configManager = configManager;
12677
12899
  this.logger = logger;
12678
12900
  this.utils = utils;
12679
12901
  }
12902
+ async createPositionId(poolId, user, direction, salt) {
12903
+ const encoded = (0, import_viem.encodeAbiParameters)((0, import_viem.parseAbiParameters)("bytes32 poolId, address user, uint8 direction, uint64 salt"), [
12904
+ poolId,
12905
+ user,
12906
+ direction,
12907
+ salt
12908
+ ]);
12909
+ return (0, import_ethers25.keccak256)(encoded);
12910
+ }
12680
12911
  async createIncreaseOrder(params) {
12681
12912
  try {
12682
12913
  const config = this.configManager.getConfig();
@@ -12703,32 +12934,9 @@ var Order = class {
12703
12934
  throw new Error(approvalResult.message);
12704
12935
  }
12705
12936
  }
12706
- console.log("createIncreaseOrder params--->", {
12707
- user: params.address,
12708
- poolId: params.poolId,
12709
- userPositionSalt: params.userPositionSalt,
12710
- orderType: params.orderType,
12711
- triggerType: params.triggerType,
12712
- operation: OperationType.INCREASE,
12713
- direction: params.direction,
12714
- collateralAmount: collateralWithNetworkFee,
12715
- size: params.size,
12716
- price: params.price,
12717
- timeInForce: TIME_IN_FORCE,
12718
- postOnly: params.postOnly,
12719
- slippagePct: params.slippagePct,
12720
- executionFeeToken: params.executionFeeToken,
12721
- leverage: params.leverage,
12722
- tpSize: params.tpSize ? params.tpSize : 0,
12723
- tpPrice: params.tpPrice ? params.tpPrice : 0,
12724
- slSize: params.slSize ? params.slSize : 0,
12725
- slPrice: params.slPrice ? params.slPrice : 0,
12726
- useAccountBalance: false
12727
- });
12728
- const gasLimit = await brokerContract.placeOrder.estimateGas({
12937
+ const data = {
12729
12938
  user: params.address,
12730
12939
  poolId: params.poolId,
12731
- userPositionSalt: params.userPositionSalt,
12732
12940
  orderType: params.orderType,
12733
12941
  triggerType: params.triggerType,
12734
12942
  operation: OperationType.INCREASE,
@@ -12746,12 +12954,14 @@ var Order = class {
12746
12954
  slSize: params.slSize ? params.slSize : 0,
12747
12955
  slPrice: params.slPrice ? params.slPrice : 0,
12748
12956
  useAccountBalance: false
12749
- });
12750
- const transaction = await brokerContract.placeOrder(
12751
- {
12957
+ };
12958
+ let transaction;
12959
+ if (!params.positionId) {
12960
+ const positionId = await this.createPositionId(params.poolId, params.address, params.direction, BigInt(1));
12961
+ this.logger.info("createIncreaseOrder salt position params--->", { ...data, positionId });
12962
+ const gasLimit = await brokerContract.placeOrderWithSalt.estimateGas(positionId.toString(), {
12752
12963
  user: params.address,
12753
12964
  poolId: params.poolId,
12754
- userPositionSalt: params.userPositionSalt,
12755
12965
  orderType: params.orderType,
12756
12966
  triggerType: params.triggerType,
12757
12967
  operation: OperationType.INCREASE,
@@ -12769,11 +12979,85 @@ var Order = class {
12769
12979
  slSize: params.slSize ? params.slSize : 0,
12770
12980
  slPrice: params.slPrice ? params.slPrice : 0,
12771
12981
  useAccountBalance: false
12772
- },
12773
- {
12774
- gasLimit: gasLimit * 120n / 100n
12775
- }
12776
- );
12982
+ });
12983
+ transaction = await brokerContract.placeOrderWithSalt(
12984
+ positionId.toString(),
12985
+ {
12986
+ user: params.address,
12987
+ poolId: params.poolId,
12988
+ orderType: params.orderType,
12989
+ triggerType: params.triggerType,
12990
+ operation: OperationType.INCREASE,
12991
+ direction: params.direction,
12992
+ collateralAmount: collateralWithNetworkFee,
12993
+ size: params.size,
12994
+ price: params.price,
12995
+ timeInForce: TIME_IN_FORCE,
12996
+ postOnly: params.postOnly,
12997
+ slippagePct: params.slippagePct,
12998
+ executionFeeToken: params.executionFeeToken,
12999
+ leverage: params.leverage,
13000
+ tpSize: params.tpSize ? params.tpSize : 0,
13001
+ tpPrice: params.tpPrice ? params.tpPrice : 0,
13002
+ slSize: params.slSize ? params.slSize : 0,
13003
+ slPrice: params.slPrice ? params.slPrice : 0,
13004
+ useAccountBalance: false
13005
+ },
13006
+ {
13007
+ gasLimit: gasLimit * 120n / 100n
13008
+ }
13009
+ );
13010
+ } else {
13011
+ this.logger.info("createIncreaseOrder nft position params--->", { ...data, positionId: params.positionId });
13012
+ const gasLimit = await brokerContract.placeOrderWithPosition.estimateGas(params.positionId.toString(), {
13013
+ user: params.address,
13014
+ poolId: params.poolId,
13015
+ orderType: params.orderType,
13016
+ triggerType: params.triggerType,
13017
+ operation: OperationType.INCREASE,
13018
+ direction: params.direction,
13019
+ collateralAmount: collateralWithNetworkFee,
13020
+ size: params.size,
13021
+ price: params.price,
13022
+ timeInForce: TIME_IN_FORCE,
13023
+ postOnly: params.postOnly,
13024
+ slippagePct: params.slippagePct,
13025
+ executionFeeToken: params.executionFeeToken,
13026
+ leverage: params.leverage,
13027
+ tpSize: params.tpSize ? params.tpSize : 0,
13028
+ tpPrice: params.tpPrice ? params.tpPrice : 0,
13029
+ slSize: params.slSize ? params.slSize : 0,
13030
+ slPrice: params.slPrice ? params.slPrice : 0,
13031
+ useAccountBalance: false
13032
+ });
13033
+ transaction = await brokerContract.placeOrderWithPosition(
13034
+ params.positionId.toString(),
13035
+ {
13036
+ user: params.address,
13037
+ poolId: params.poolId,
13038
+ orderType: params.orderType,
13039
+ triggerType: params.triggerType,
13040
+ operation: OperationType.INCREASE,
13041
+ direction: params.direction,
13042
+ collateralAmount: collateralWithNetworkFee,
13043
+ size: params.size,
13044
+ price: params.price,
13045
+ timeInForce: TIME_IN_FORCE,
13046
+ postOnly: params.postOnly,
13047
+ slippagePct: params.slippagePct,
13048
+ executionFeeToken: params.executionFeeToken,
13049
+ leverage: params.leverage,
13050
+ tpSize: params.tpSize ? params.tpSize : 0,
13051
+ tpPrice: params.tpPrice ? params.tpPrice : 0,
13052
+ slSize: params.slSize ? params.slSize : 0,
13053
+ slPrice: params.slPrice ? params.slPrice : 0,
13054
+ useAccountBalance: false
13055
+ },
13056
+ {
13057
+ gasLimit: gasLimit * 120n / 100n
13058
+ }
13059
+ );
13060
+ }
12777
13061
  const receipt = await transaction.wait();
12778
13062
  this.logger.info("createIncreaseOrder receipt--->", receipt);
12779
13063
  const orderId = this.utils.getOrderIdFromTransaction(receipt);
@@ -12823,7 +13107,7 @@ var Order = class {
12823
13107
  console.log("createDecreaseOrder params--->", {
12824
13108
  user: params.address,
12825
13109
  poolId: params.poolId,
12826
- userPositionSalt: params.userPositionSalt,
13110
+ positionId: params.positionId,
12827
13111
  orderType: params.orderType,
12828
13112
  triggerType: params.triggerType,
12829
13113
  operation: OperationType.DECREASE,
@@ -12837,10 +13121,9 @@ var Order = class {
12837
13121
  executionFeeToken: params.executionFeeToken,
12838
13122
  leverage: params.leverage
12839
13123
  });
12840
- const gasLimit = await brokerContract.placeOrder.estimateGas({
13124
+ const data = {
12841
13125
  user: params.address,
12842
13126
  poolId: params.poolId,
12843
- userPositionSalt: params.userPositionSalt,
12844
13127
  orderType: params.orderType,
12845
13128
  triggerType: params.triggerType,
12846
13129
  operation: OperationType.DECREASE,
@@ -12858,12 +13141,14 @@ var Order = class {
12858
13141
  slSize: 0,
12859
13142
  slPrice: 0,
12860
13143
  useAccountBalance: false
12861
- });
12862
- const transaction = await brokerContract.placeOrder(
12863
- {
13144
+ };
13145
+ let transaction;
13146
+ if (!params.positionId) {
13147
+ const positionId = await this.createPositionId(params.poolId, params.address, params.direction, BigInt(1));
13148
+ this.logger.info("createDecreaseOrder salt position params--->", { ...data, positionId });
13149
+ const gasLimit = await brokerContract.placeOrderWithPosition.estimateGas(positionId.toString(), {
12864
13150
  user: params.address,
12865
13151
  poolId: params.poolId,
12866
- userPositionSalt: params.userPositionSalt,
12867
13152
  orderType: params.orderType,
12868
13153
  triggerType: params.triggerType,
12869
13154
  operation: OperationType.DECREASE,
@@ -12872,7 +13157,7 @@ var Order = class {
12872
13157
  size: params.size,
12873
13158
  price: params.price,
12874
13159
  timeInForce: TIME_IN_FORCE,
12875
- postOnly: false,
13160
+ postOnly: params.postOnly,
12876
13161
  slippagePct: params.slippagePct,
12877
13162
  executionFeeToken: params.executionFeeToken,
12878
13163
  leverage: params.leverage,
@@ -12881,11 +13166,85 @@ var Order = class {
12881
13166
  slSize: 0,
12882
13167
  slPrice: 0,
12883
13168
  useAccountBalance: false
12884
- },
12885
- {
12886
- gasLimit: gasLimit * 130n / 100n
12887
- }
12888
- );
13169
+ });
13170
+ transaction = await brokerContract.placeOrderWithPosition(
13171
+ params.positionId.toString(),
13172
+ {
13173
+ user: params.address,
13174
+ poolId: params.poolId,
13175
+ orderType: params.orderType,
13176
+ triggerType: params.triggerType,
13177
+ operation: OperationType.DECREASE,
13178
+ direction: params.direction,
13179
+ collateralAmount: collateralWithNetworkFee,
13180
+ size: params.size,
13181
+ price: params.price,
13182
+ timeInForce: TIME_IN_FORCE,
13183
+ postOnly: false,
13184
+ slippagePct: params.slippagePct,
13185
+ executionFeeToken: params.executionFeeToken,
13186
+ leverage: params.leverage,
13187
+ tpSize: 0,
13188
+ tpPrice: 0,
13189
+ slSize: 0,
13190
+ slPrice: 0,
13191
+ useAccountBalance: false
13192
+ },
13193
+ {
13194
+ gasLimit: gasLimit * 130n / 100n
13195
+ }
13196
+ );
13197
+ } else {
13198
+ this.logger.info("createDecreaseOrder nft position params--->", { ...data, positionId: params.positionId });
13199
+ const gasLimit = await brokerContract.placeOrderWithPosition.estimateGas(params.positionId.toString(), {
13200
+ user: params.address,
13201
+ poolId: params.poolId,
13202
+ orderType: params.orderType,
13203
+ triggerType: params.triggerType,
13204
+ operation: OperationType.DECREASE,
13205
+ direction: params.direction,
13206
+ collateralAmount: collateralWithNetworkFee,
13207
+ size: params.size,
13208
+ price: params.price,
13209
+ timeInForce: TIME_IN_FORCE,
13210
+ postOnly: params.postOnly,
13211
+ slippagePct: params.slippagePct,
13212
+ executionFeeToken: params.executionFeeToken,
13213
+ leverage: params.leverage,
13214
+ tpSize: 0,
13215
+ tpPrice: 0,
13216
+ slSize: 0,
13217
+ slPrice: 0,
13218
+ useAccountBalance: false
13219
+ });
13220
+ transaction = await brokerContract.placeOrderWithPosition(
13221
+ params.positionId.toString(),
13222
+ {
13223
+ user: params.address,
13224
+ poolId: params.poolId,
13225
+ orderType: params.orderType,
13226
+ triggerType: params.triggerType,
13227
+ operation: OperationType.DECREASE,
13228
+ direction: params.direction,
13229
+ collateralAmount: collateralWithNetworkFee,
13230
+ size: params.size,
13231
+ price: params.price,
13232
+ timeInForce: TIME_IN_FORCE,
13233
+ postOnly: false,
13234
+ slippagePct: params.slippagePct,
13235
+ executionFeeToken: params.executionFeeToken,
13236
+ leverage: params.leverage,
13237
+ tpSize: 0,
13238
+ tpPrice: 0,
13239
+ slSize: 0,
13240
+ slPrice: 0,
13241
+ useAccountBalance: false
13242
+ },
13243
+ {
13244
+ gasLimit: gasLimit * 130n / 100n
13245
+ }
13246
+ );
13247
+ }
12889
13248
  this.logger.info("Transaction sent:", transaction.hash);
12890
13249
  this.logger.info("Waiting for confirmation...");
12891
13250
  const receipt = await transaction.wait();
@@ -12938,7 +13297,6 @@ var Order = class {
12938
13297
  {
12939
13298
  user: params.address,
12940
13299
  poolId: params.poolId,
12941
- userPositionSalt: params.userPositionSalt,
12942
13300
  orderType: OrderType.STOP,
12943
13301
  triggerType: params.tpTriggerType,
12944
13302
  operation: OperationType.DECREASE,
@@ -12960,7 +13318,6 @@ var Order = class {
12960
13318
  {
12961
13319
  user: params.address,
12962
13320
  poolId: params.poolId,
12963
- userPositionSalt: params.userPositionSalt,
12964
13321
  orderType: OrderType.STOP,
12965
13322
  triggerType: params.slTriggerType,
12966
13323
  operation: OperationType.DECREASE,
@@ -12980,11 +13337,21 @@ var Order = class {
12980
13337
  useAccountBalance: false
12981
13338
  }
12982
13339
  ];
12983
- console.log("createPositionTpSlOrder data--->", data2);
12984
- const gasLimit2 = await brokerContract.placeOrders.estimateGas(data2);
12985
- const transaction2 = await brokerContract.placeOrders(data2, {
12986
- gasLimit: gasLimit2 * 120n / 100n
12987
- });
13340
+ let transaction2;
13341
+ if (!params.positionId) {
13342
+ this.logger.info("createPositionTpSlOrder salt position data--->", data2);
13343
+ const positionId = await this.createPositionId(params.poolId, params.address, params.direction, BigInt(1));
13344
+ const gasLimit = await brokerContract.placeOrdersWithSalt.estimateGas([positionId.toString(), positionId.toString()], data2);
13345
+ transaction2 = await brokerContract.placeOrdersWithSalt([positionId.toString(), positionId.toString()], data2, {
13346
+ gasLimit: gasLimit * 120n / 100n
13347
+ });
13348
+ } else {
13349
+ this.logger.info("createPositionTpSlOrder nft position data--->", data2);
13350
+ const gasLimit = await brokerContract.placeOrdersWithPosition.estimateGas([params.positionId.toString(), params.positionId.toString()], data2);
13351
+ transaction2 = await brokerContract.placeOrdersWithPosition([params.positionId.toString(), params.positionId.toString()], data2, {
13352
+ gasLimit: gasLimit * 120n / 100n
13353
+ });
13354
+ }
12988
13355
  this.logger.info("Transaction sent:", transaction2.hash);
12989
13356
  this.logger.info("Waiting for confirmation...");
12990
13357
  const receipt2 = await transaction2.wait();
@@ -13018,7 +13385,6 @@ var Order = class {
13018
13385
  const data = {
13019
13386
  user: params.address,
13020
13387
  poolId: params.poolId,
13021
- userPositionSalt: params.userPositionSalt,
13022
13388
  orderType: OrderType.STOP,
13023
13389
  triggerType: params.tpSize !== "0" ? params.tpTriggerType : params.slTriggerType,
13024
13390
  operation: OperationType.DECREASE,
@@ -13037,11 +13403,21 @@ var Order = class {
13037
13403
  slPrice: "0",
13038
13404
  useAccountBalance: false
13039
13405
  };
13040
- console.log("createPositionTpSlOrder data--->", data);
13041
- const gasLimit = await brokerContract.placeOrder.estimateGas(data);
13042
- const transaction = await brokerContract.placeOrder(data, {
13043
- gasLimit: gasLimit * 120n / 100n
13044
- });
13406
+ let transaction;
13407
+ if (!params.positionId) {
13408
+ this.logger.info("createPositionTpOrSlOrder salt position data--->", data);
13409
+ const positionId = await this.createPositionId(params.poolId, params.address, params.direction, BigInt(1));
13410
+ const gasLimit = await brokerContract.placeOrderWithPosition.estimateGas(params.positionId.toString(), data);
13411
+ transaction = await brokerContract.placeOrderWithPosition(positionId.toString(), data, {
13412
+ gasLimit: gasLimit * 120n / 100n
13413
+ });
13414
+ } else {
13415
+ this.logger.info("createPositionTpOrSlOrder nft position data--->", data);
13416
+ const gasLimit = await brokerContract.placeOrderWithPosition.estimateGas(params.positionId.toString(), data);
13417
+ transaction = await brokerContract.placeOrderWithPosition(params.positionId.toString(), data, {
13418
+ gasLimit: gasLimit * 120n / 100n
13419
+ });
13420
+ }
13045
13421
  this.logger.info("Transaction sent:", transaction.hash);
13046
13422
  this.logger.info("Waiting for confirmation...");
13047
13423
  const receipt = await transaction.wait();
@@ -13138,7 +13514,6 @@ var Order = class {
13138
13514
  if (!config.signer) {
13139
13515
  throw new MyxSDKError("INVALID_SIGNER" /* InvalidSigner */, "Invalid signer");
13140
13516
  }
13141
- console.log("updateOrderTpSl params", params);
13142
13517
  const brokerContract = await getBrokerSingerContract(
13143
13518
  config.chainId
13144
13519
  );
@@ -13157,18 +13532,17 @@ var Order = class {
13157
13532
  paymentType: 0
13158
13533
  }
13159
13534
  };
13160
- console.log(data);
13535
+ this.logger.info("updateOrderTpSl params", data);
13161
13536
  try {
13162
13537
  const gasLimit = await brokerContract.updateOrder.estimateGas(data);
13163
- console.log("gaslimit->", gasLimit);
13164
13538
  const request = await brokerContract.updateOrder(data, {
13165
13539
  gasLimit: gasLimit * 120n / 100n
13166
13540
  });
13167
13541
  const receipt = await request?.wait();
13168
- console.log("updateOrderTpSl receipt", receipt);
13542
+ this.logger.info("updateOrderTpSl receipt", receipt);
13169
13543
  return receipt;
13170
13544
  } catch (error) {
13171
- console.error("Error updating order:", error);
13545
+ this.logger.error("Error updating order:", error);
13172
13546
  return {
13173
13547
  code: -1,
13174
13548
  message: "Failed to update order"
@@ -17020,9 +17394,7 @@ var Utils = class {
17020
17394
  }
17021
17395
  async getUserTradingFeeRate(assetClass) {
17022
17396
  const config = this.configManager.getConfig();
17023
- const brokerAddress = getContractAddressByChainId(
17024
- config.chainId
17025
- ).BROKER;
17397
+ const brokerAddress = config.brokerAddress;
17026
17398
  const brokerContract = new import_ethers26.ethers.Contract(
17027
17399
  brokerAddress,
17028
17400
  Broker_default,