@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.mjs CHANGED
@@ -1376,14 +1376,14 @@ function isSupportedChainFn(chainId2) {
1376
1376
  // src/config/address/ARB_TEST_SEPOLIA.ts
1377
1377
  import { ZeroAddress } from "ethers";
1378
1378
  var ARB_TEST_SEPOLIA = {
1379
- USDC: "",
1380
- POOL_MANAGER: "0x29fA92d5f47051E49Ab9001A3cbd8091c34c5638",
1381
- Account: "0x900F3003c59b9c55A09CEB7b3134A53E511531C3",
1379
+ USDC: "0x7E248Ec1721639413A280d9E82e2862Cae2E6E28",
1380
+ POOL_MANAGER: "0xA4A1dfbe40cB725A79D34bd529f0C1b54AB46954",
1381
+ Account: "0x6136899e8c77C452bc46AcD786aA2C09fD31f947",
1382
1382
  POOL_VIEW: "",
1383
1383
  HYPER_VAULT: ZeroAddress,
1384
1384
  FEE_COLLECTOR: "",
1385
- POSITION_MANAGER: "0x520435fA110549aE7eA1894839575a62cbF5A8D5",
1386
- ORDER_MANAGER: "0x4eDe4E20162551F293B9D6f33E8567314fb5612f",
1385
+ POSITION_MANAGER: "0x002F28be205E9A1e279d2eeF1f5e472CeA1d910C",
1386
+ ORDER_MANAGER: "0x3A3C7c4588Fb2aE46A4108994a47712E03F96B23",
1387
1387
  TRUSTED_FORWARDER: "",
1388
1388
  FRONT_FACET: "",
1389
1389
  // router address
@@ -1392,21 +1392,19 @@ var ARB_TEST_SEPOLIA = {
1392
1392
  FAUCET: "",
1393
1393
  UI_POOL_DATA_PROVIDER: "",
1394
1394
  UI_POSITION_DATA_PROVIDER: "",
1395
- PYTH: "0x4374e5a8b9C22271E9EB878A2AA31DE97DF15DAF",
1395
+ PYTH: "0x361360Def495BfB4F0BE59AB11878D042c458155",
1396
1396
  // !!! 非Pyth Adapter
1397
1397
  MYX: ZeroAddress,
1398
1398
  ERC20: "0x7E248Ec1721639413A280d9E82e2862Cae2E6E28",
1399
- LIQUIDITY_ROUTER: "0x3533595E0546CCA3CEa58bD23f2733BbCE057F44",
1400
- BASE_POOL: "0x4b86814b748D2ae323a8449b98C5add6D07901F3",
1401
- QUOTE_POOL: "0x22342d91b372ED991aB5A93bdC31706E4971Cec2",
1402
- BROKER: "0x461A33C5E75c292A45f8c961ab816060a94AfbA0",
1403
- // MYXBroker
1404
- ORACLE: "0x38aC036082810F43f83c2bca0Ab2518703d74738",
1399
+ LIQUIDITY_ROUTER: "0xd185C3f675d991735FCF6885Ff6BADE02A21313d",
1400
+ BASE_POOL: "0x2c6AdaE4A01836487842b7369c1db3F441871E83",
1401
+ QUOTE_POOL: "0xe1Ff495206635570A8Eaf9517125Ce66a2d09d32",
1402
+ ORACLE: "0x574001F6cB520b15d5a6db9F7B7a0ebf1A8E25c0",
1405
1403
  // MYXOracle
1406
- EIP7702Delegation: "0xDec0Eb393c362e459B124F4A27E21BCD10D45B41",
1407
- MARKET_MANAGER: "0x26645ba85E6294f4AE4605C56967B0A16BcB9cBb",
1408
- DATA_PROVIDER: "0xc4472860fA175d0E8b5a73620778799469232763",
1409
- ORACLE_RESERVE: "0x513AE26EdD58E1fD209c68Ed790585fFb08Fd740"
1404
+ EIP7702Delegation: "0x4e1B9aDf5Aa4a893f578c8502E6E28841b2403f3",
1405
+ MARKET_MANAGER: "0x12AD75316A92a66b92c79080c555594314e7aFB3",
1406
+ DATA_PROVIDER: "0x726A4978eDcb974B9889BC6f5Ee2Ec06D703038E",
1407
+ ORACLE_RESERVE: "0xC46b81c38091933f4811EC16E93553f9801EB863"
1410
1408
  };
1411
1409
 
1412
1410
  // src/config/address.ts
@@ -1742,7 +1740,7 @@ var RotationProvider = class extends BaseProvider {
1742
1740
  // package.json
1743
1741
  var package_default = {
1744
1742
  name: "@myx-trade/sdk",
1745
- version: "0.1.34",
1743
+ version: "0.1.36",
1746
1744
  private: false,
1747
1745
  publishConfig: {
1748
1746
  access: "public"
@@ -1776,7 +1774,8 @@ var package_default = {
1776
1774
  "publish:patch": "node scripts/publish.js patch",
1777
1775
  "publish:minor": "node scripts/publish.js minor",
1778
1776
  "publish:major": "node scripts/publish.js major",
1779
- "publish:no-bump": "npm run build && npm publish --access public"
1777
+ "publish:no-bump": "npm run build && npm publish --access public",
1778
+ "type-check": "echo 'Skipping type-check for @myx-trade/sdk'"
1780
1779
  },
1781
1780
  keywords: [
1782
1781
  "trading",
@@ -5597,11 +5596,15 @@ var Broker_default = [
5597
5596
  },
5598
5597
  {
5599
5598
  type: "function",
5600
- name: "placeOrder",
5599
+ name: "placeOrderWithPosition",
5601
5600
  constant: false,
5602
5601
  stateMutability: "payable",
5603
5602
  payable: true,
5604
5603
  inputs: [
5604
+ {
5605
+ type: "bytes32",
5606
+ name: "positionId"
5607
+ },
5605
5608
  {
5606
5609
  type: "tuple",
5607
5610
  name: "orderParams",
@@ -5615,8 +5618,100 @@ var Broker_default = [
5615
5618
  name: "poolId"
5616
5619
  },
5617
5620
  {
5618
- type: "uint64",
5619
- name: "userPositionSalt"
5621
+ type: "uint8",
5622
+ name: "orderType"
5623
+ },
5624
+ {
5625
+ type: "uint8",
5626
+ name: "triggerType"
5627
+ },
5628
+ {
5629
+ type: "uint8",
5630
+ name: "operation"
5631
+ },
5632
+ {
5633
+ type: "uint8",
5634
+ name: "direction"
5635
+ },
5636
+ {
5637
+ type: "uint256",
5638
+ name: "collateralAmount"
5639
+ },
5640
+ {
5641
+ type: "uint256",
5642
+ name: "size"
5643
+ },
5644
+ {
5645
+ type: "uint256",
5646
+ name: "price"
5647
+ },
5648
+ {
5649
+ type: "uint8",
5650
+ name: "timeInForce"
5651
+ },
5652
+ {
5653
+ type: "bool",
5654
+ name: "postOnly"
5655
+ },
5656
+ {
5657
+ type: "uint16",
5658
+ name: "slippagePct"
5659
+ },
5660
+ {
5661
+ type: "address",
5662
+ name: "executionFeeToken"
5663
+ },
5664
+ {
5665
+ type: "uint16",
5666
+ name: "leverage"
5667
+ },
5668
+ {
5669
+ type: "uint256",
5670
+ name: "tpSize"
5671
+ },
5672
+ {
5673
+ type: "uint256",
5674
+ name: "tpPrice"
5675
+ },
5676
+ {
5677
+ type: "uint256",
5678
+ name: "slSize"
5679
+ },
5680
+ {
5681
+ type: "uint256",
5682
+ name: "slPrice"
5683
+ },
5684
+ {
5685
+ type: "bool",
5686
+ name: "useAccountBalance"
5687
+ }
5688
+ ]
5689
+ }
5690
+ ],
5691
+ outputs: []
5692
+ },
5693
+ {
5694
+ type: "function",
5695
+ name: "placeOrderWithSalt",
5696
+ constant: false,
5697
+ stateMutability: "payable",
5698
+ payable: true,
5699
+ inputs: [
5700
+ {
5701
+ type: "uint64",
5702
+ name: "userPositionSalt"
5703
+ },
5704
+ {
5705
+ type: "tuple",
5706
+ name: "orderParams",
5707
+ components: [
5708
+ {
5709
+ type: "address",
5710
+ name: "user"
5711
+ },
5712
+ {
5713
+ type: "bytes32",
5714
+ name: "poolId"
5620
5715
  },
5621
5716
  {
5622
5717
  type: "uint8",
@@ -5693,11 +5788,15 @@ var Broker_default = [
5693
5788
  },
5694
5789
  {
5695
5790
  type: "function",
5696
- name: "placeOrders",
5791
+ name: "placeOrdersWithPosition",
5697
5792
  constant: false,
5698
5793
  stateMutability: "payable",
5699
5794
  payable: true,
5700
5795
  inputs: [
5796
+ {
5797
+ type: "bytes32[]",
5798
+ name: "positionIds"
5799
+ },
5701
5800
  {
5702
5801
  type: "tuple[]",
5703
5802
  name: "orderParams",
@@ -5711,8 +5810,100 @@ var Broker_default = [
5711
5810
  name: "poolId"
5712
5811
  },
5713
5812
  {
5714
- type: "uint64",
5715
- name: "userPositionSalt"
5813
+ type: "uint8",
5814
+ name: "orderType"
5815
+ },
5816
+ {
5817
+ type: "uint8",
5818
+ name: "triggerType"
5819
+ },
5820
+ {
5821
+ type: "uint8",
5822
+ name: "operation"
5823
+ },
5824
+ {
5825
+ type: "uint8",
5826
+ name: "direction"
5827
+ },
5828
+ {
5829
+ type: "uint256",
5830
+ name: "collateralAmount"
5831
+ },
5832
+ {
5833
+ type: "uint256",
5834
+ name: "size"
5835
+ },
5836
+ {
5837
+ type: "uint256",
5838
+ name: "price"
5839
+ },
5840
+ {
5841
+ type: "uint8",
5842
+ name: "timeInForce"
5843
+ },
5844
+ {
5845
+ type: "bool",
5846
+ name: "postOnly"
5847
+ },
5848
+ {
5849
+ type: "uint16",
5850
+ name: "slippagePct"
5851
+ },
5852
+ {
5853
+ type: "address",
5854
+ name: "executionFeeToken"
5855
+ },
5856
+ {
5857
+ type: "uint16",
5858
+ name: "leverage"
5859
+ },
5860
+ {
5861
+ type: "uint256",
5862
+ name: "tpSize"
5863
+ },
5864
+ {
5865
+ type: "uint256",
5866
+ name: "tpPrice"
5867
+ },
5868
+ {
5869
+ type: "uint256",
5870
+ name: "slSize"
5871
+ },
5872
+ {
5873
+ type: "uint256",
5874
+ name: "slPrice"
5875
+ },
5876
+ {
5877
+ type: "bool",
5878
+ name: "useAccountBalance"
5879
+ }
5880
+ ]
5881
+ }
5882
+ ],
5883
+ outputs: []
5884
+ },
5885
+ {
5886
+ type: "function",
5887
+ name: "placeOrdersWithSalt",
5888
+ constant: false,
5889
+ stateMutability: "payable",
5890
+ payable: true,
5891
+ inputs: [
5892
+ {
5893
+ type: "uint64[]",
5894
+ name: "userPositionSalts"
5895
+ },
5896
+ {
5897
+ type: "tuple[]",
5898
+ name: "orderParams",
5899
+ components: [
5900
+ {
5901
+ type: "address",
5902
+ name: "user"
5903
+ },
5904
+ {
5905
+ type: "bytes32",
5906
+ name: "poolId"
5716
5907
  },
5717
5908
  {
5718
5909
  type: "uint8",
@@ -11993,6 +12184,13 @@ var SubScription = class {
11993
12184
  var ConfigManager = class {
11994
12185
  // accessToken 过期时间
11995
12186
  constructor(config) {
12187
+ /**
12188
+ * 获取有效的 accessToken,自动处理获取和刷新
12189
+ * @param forceRefresh 是否强制刷新
12190
+ * @returns Promise<string | null> 有效的 accessToken 或 null
12191
+ */
12192
+ this._getAccessTokenQueue = [];
12193
+ this._isGettingAccessToken = false;
11996
12194
  const mergedConfig = {
11997
12195
  isTestnet: false,
11998
12196
  ...config
@@ -12033,13 +12231,36 @@ var ConfigManager = class {
12033
12231
  );
12034
12232
  }
12035
12233
  }
12036
- /**
12037
- * 获取有效的 accessToken,自动处理获取和刷新
12038
- * @param forceRefresh 是否强制刷新
12039
- * @returns Promise<string | null> 有效的 accessToken 或 null
12040
- */
12041
12234
  async getAccessToken(forceRefresh = false) {
12235
+ return new Promise((resolve, reject) => {
12236
+ this._getAccessTokenQueue.push({
12237
+ resolve,
12238
+ reject,
12239
+ forceRefresh
12240
+ });
12241
+ this._processAccessTokenQueue();
12242
+ });
12243
+ }
12244
+ _processAccessTokenQueue() {
12245
+ if (this._isGettingAccessToken) {
12246
+ return;
12247
+ }
12248
+ this._isGettingAccessToken = true;
12249
+ const item = this._getAccessTokenQueue.shift();
12250
+ if (item) {
12251
+ this._getAccessToken(item.forceRefresh).then(item.resolve).catch(item.reject).finally(() => {
12252
+ this._isGettingAccessToken = false;
12253
+ if (this._getAccessTokenQueue.length > 0) {
12254
+ this._processAccessTokenQueue();
12255
+ }
12256
+ });
12257
+ } else {
12258
+ this._isGettingAccessToken = false;
12259
+ }
12260
+ }
12261
+ async _getAccessToken(forceRefresh = false) {
12042
12262
  if (!forceRefresh && this.isAccessTokenValid()) {
12263
+ this._isGettingAccessToken = false;
12043
12264
  return this.accessToken;
12044
12265
  }
12045
12266
  if (!this.config.getAccessToken) {
@@ -12095,7 +12316,7 @@ var ConfigManager = class {
12095
12316
  * @returns boolean token 是否有效
12096
12317
  */
12097
12318
  isAccessTokenValid() {
12098
- if (!this.accessToken || !this.accessTokenExpiry) {
12319
+ if (!this.accessToken || !this.accessTokenExpiry || !this.config.getAccessToken || !this.config.signer) {
12099
12320
  return false;
12100
12321
  }
12101
12322
  return Date.now() < this.accessTokenExpiry;
@@ -12490,7 +12711,7 @@ var Position = class {
12490
12711
  }
12491
12712
  }
12492
12713
  const brokerContract = getContract(
12493
- contractAddress.BROKER,
12714
+ config.brokerAddress,
12494
12715
  Broker_default,
12495
12716
  config.signer
12496
12717
  );
@@ -12585,13 +12806,23 @@ var OrderStatus = {
12585
12806
  };
12586
12807
 
12587
12808
  // src/manager/order/index.ts
12588
- import { ethers as ethers6 } from "ethers";
12809
+ import { ethers as ethers6, keccak256 } from "ethers";
12810
+ import { encodeAbiParameters, parseAbiParameters } from "viem";
12589
12811
  var Order = class {
12590
12812
  constructor(configManager, logger, utils) {
12591
12813
  this.configManager = configManager;
12592
12814
  this.logger = logger;
12593
12815
  this.utils = utils;
12594
12816
  }
12817
+ async createPositionId(poolId, user, direction, salt) {
12818
+ const encoded = encodeAbiParameters(parseAbiParameters("bytes32 poolId, address user, uint8 direction, uint64 salt"), [
12819
+ poolId,
12820
+ user,
12821
+ direction,
12822
+ salt
12823
+ ]);
12824
+ return keccak256(encoded);
12825
+ }
12595
12826
  async createIncreaseOrder(params) {
12596
12827
  try {
12597
12828
  const config = this.configManager.getConfig();
@@ -12618,32 +12849,9 @@ var Order = class {
12618
12849
  throw new Error(approvalResult.message);
12619
12850
  }
12620
12851
  }
12621
- console.log("createIncreaseOrder params--->", {
12622
- user: params.address,
12623
- poolId: params.poolId,
12624
- userPositionSalt: params.userPositionSalt,
12625
- orderType: params.orderType,
12626
- triggerType: params.triggerType,
12627
- operation: OperationType.INCREASE,
12628
- direction: params.direction,
12629
- collateralAmount: collateralWithNetworkFee,
12630
- size: params.size,
12631
- price: params.price,
12632
- timeInForce: TIME_IN_FORCE,
12633
- postOnly: params.postOnly,
12634
- slippagePct: params.slippagePct,
12635
- executionFeeToken: params.executionFeeToken,
12636
- leverage: params.leverage,
12637
- tpSize: params.tpSize ? params.tpSize : 0,
12638
- tpPrice: params.tpPrice ? params.tpPrice : 0,
12639
- slSize: params.slSize ? params.slSize : 0,
12640
- slPrice: params.slPrice ? params.slPrice : 0,
12641
- useAccountBalance: false
12642
- });
12643
- const gasLimit = await brokerContract.placeOrder.estimateGas({
12852
+ const data = {
12644
12853
  user: params.address,
12645
12854
  poolId: params.poolId,
12646
- userPositionSalt: params.userPositionSalt,
12647
12855
  orderType: params.orderType,
12648
12856
  triggerType: params.triggerType,
12649
12857
  operation: OperationType.INCREASE,
@@ -12661,12 +12869,14 @@ var Order = class {
12661
12869
  slSize: params.slSize ? params.slSize : 0,
12662
12870
  slPrice: params.slPrice ? params.slPrice : 0,
12663
12871
  useAccountBalance: false
12664
- });
12665
- const transaction = await brokerContract.placeOrder(
12666
- {
12872
+ };
12873
+ let transaction;
12874
+ if (!params.positionId) {
12875
+ const positionId = await this.createPositionId(params.poolId, params.address, params.direction, BigInt(1));
12876
+ this.logger.info("createIncreaseOrder salt position params--->", { ...data, positionId });
12877
+ const gasLimit = await brokerContract.placeOrderWithSalt.estimateGas(positionId.toString(), {
12667
12878
  user: params.address,
12668
12879
  poolId: params.poolId,
12669
- userPositionSalt: params.userPositionSalt,
12670
12880
  orderType: params.orderType,
12671
12881
  triggerType: params.triggerType,
12672
12882
  operation: OperationType.INCREASE,
@@ -12684,11 +12894,85 @@ var Order = class {
12684
12894
  slSize: params.slSize ? params.slSize : 0,
12685
12895
  slPrice: params.slPrice ? params.slPrice : 0,
12686
12896
  useAccountBalance: false
12687
- },
12688
- {
12689
- gasLimit: gasLimit * 120n / 100n
12690
- }
12691
- );
12897
+ });
12898
+ transaction = await brokerContract.placeOrderWithSalt(
12899
+ positionId.toString(),
12900
+ {
12901
+ user: params.address,
12902
+ poolId: params.poolId,
12903
+ orderType: params.orderType,
12904
+ triggerType: params.triggerType,
12905
+ operation: OperationType.INCREASE,
12906
+ direction: params.direction,
12907
+ collateralAmount: collateralWithNetworkFee,
12908
+ size: params.size,
12909
+ price: params.price,
12910
+ timeInForce: TIME_IN_FORCE,
12911
+ postOnly: params.postOnly,
12912
+ slippagePct: params.slippagePct,
12913
+ executionFeeToken: params.executionFeeToken,
12914
+ leverage: params.leverage,
12915
+ tpSize: params.tpSize ? params.tpSize : 0,
12916
+ tpPrice: params.tpPrice ? params.tpPrice : 0,
12917
+ slSize: params.slSize ? params.slSize : 0,
12918
+ slPrice: params.slPrice ? params.slPrice : 0,
12919
+ useAccountBalance: false
12920
+ },
12921
+ {
12922
+ gasLimit: gasLimit * 120n / 100n
12923
+ }
12924
+ );
12925
+ } else {
12926
+ this.logger.info("createIncreaseOrder nft position params--->", { ...data, positionId: params.positionId });
12927
+ const gasLimit = await brokerContract.placeOrderWithPosition.estimateGas(params.positionId.toString(), {
12928
+ user: params.address,
12929
+ poolId: params.poolId,
12930
+ orderType: params.orderType,
12931
+ triggerType: params.triggerType,
12932
+ operation: OperationType.INCREASE,
12933
+ direction: params.direction,
12934
+ collateralAmount: collateralWithNetworkFee,
12935
+ size: params.size,
12936
+ price: params.price,
12937
+ timeInForce: TIME_IN_FORCE,
12938
+ postOnly: params.postOnly,
12939
+ slippagePct: params.slippagePct,
12940
+ executionFeeToken: params.executionFeeToken,
12941
+ leverage: params.leverage,
12942
+ tpSize: params.tpSize ? params.tpSize : 0,
12943
+ tpPrice: params.tpPrice ? params.tpPrice : 0,
12944
+ slSize: params.slSize ? params.slSize : 0,
12945
+ slPrice: params.slPrice ? params.slPrice : 0,
12946
+ useAccountBalance: false
12947
+ });
12948
+ transaction = await brokerContract.placeOrderWithPosition(
12949
+ params.positionId.toString(),
12950
+ {
12951
+ user: params.address,
12952
+ poolId: params.poolId,
12953
+ orderType: params.orderType,
12954
+ triggerType: params.triggerType,
12955
+ operation: OperationType.INCREASE,
12956
+ direction: params.direction,
12957
+ collateralAmount: collateralWithNetworkFee,
12958
+ size: params.size,
12959
+ price: params.price,
12960
+ timeInForce: TIME_IN_FORCE,
12961
+ postOnly: params.postOnly,
12962
+ slippagePct: params.slippagePct,
12963
+ executionFeeToken: params.executionFeeToken,
12964
+ leverage: params.leverage,
12965
+ tpSize: params.tpSize ? params.tpSize : 0,
12966
+ tpPrice: params.tpPrice ? params.tpPrice : 0,
12967
+ slSize: params.slSize ? params.slSize : 0,
12968
+ slPrice: params.slPrice ? params.slPrice : 0,
12969
+ useAccountBalance: false
12970
+ },
12971
+ {
12972
+ gasLimit: gasLimit * 120n / 100n
12973
+ }
12974
+ );
12975
+ }
12692
12976
  const receipt = await transaction.wait();
12693
12977
  this.logger.info("createIncreaseOrder receipt--->", receipt);
12694
12978
  const orderId = this.utils.getOrderIdFromTransaction(receipt);
@@ -12738,7 +13022,7 @@ var Order = class {
12738
13022
  console.log("createDecreaseOrder params--->", {
12739
13023
  user: params.address,
12740
13024
  poolId: params.poolId,
12741
- userPositionSalt: params.userPositionSalt,
13025
+ positionId: params.positionId,
12742
13026
  orderType: params.orderType,
12743
13027
  triggerType: params.triggerType,
12744
13028
  operation: OperationType.DECREASE,
@@ -12752,10 +13036,9 @@ var Order = class {
12752
13036
  executionFeeToken: params.executionFeeToken,
12753
13037
  leverage: params.leverage
12754
13038
  });
12755
- const gasLimit = await brokerContract.placeOrder.estimateGas({
13039
+ const data = {
12756
13040
  user: params.address,
12757
13041
  poolId: params.poolId,
12758
- userPositionSalt: params.userPositionSalt,
12759
13042
  orderType: params.orderType,
12760
13043
  triggerType: params.triggerType,
12761
13044
  operation: OperationType.DECREASE,
@@ -12773,12 +13056,14 @@ var Order = class {
12773
13056
  slSize: 0,
12774
13057
  slPrice: 0,
12775
13058
  useAccountBalance: false
12776
- });
12777
- const transaction = await brokerContract.placeOrder(
12778
- {
13059
+ };
13060
+ let transaction;
13061
+ if (!params.positionId) {
13062
+ const positionId = await this.createPositionId(params.poolId, params.address, params.direction, BigInt(1));
13063
+ this.logger.info("createDecreaseOrder salt position params--->", { ...data, positionId });
13064
+ const gasLimit = await brokerContract.placeOrderWithPosition.estimateGas(positionId.toString(), {
12779
13065
  user: params.address,
12780
13066
  poolId: params.poolId,
12781
- userPositionSalt: params.userPositionSalt,
12782
13067
  orderType: params.orderType,
12783
13068
  triggerType: params.triggerType,
12784
13069
  operation: OperationType.DECREASE,
@@ -12787,7 +13072,7 @@ var Order = class {
12787
13072
  size: params.size,
12788
13073
  price: params.price,
12789
13074
  timeInForce: TIME_IN_FORCE,
12790
- postOnly: false,
13075
+ postOnly: params.postOnly,
12791
13076
  slippagePct: params.slippagePct,
12792
13077
  executionFeeToken: params.executionFeeToken,
12793
13078
  leverage: params.leverage,
@@ -12796,11 +13081,85 @@ var Order = class {
12796
13081
  slSize: 0,
12797
13082
  slPrice: 0,
12798
13083
  useAccountBalance: false
12799
- },
12800
- {
12801
- gasLimit: gasLimit * 130n / 100n
12802
- }
12803
- );
13084
+ });
13085
+ transaction = await brokerContract.placeOrderWithPosition(
13086
+ params.positionId.toString(),
13087
+ {
13088
+ user: params.address,
13089
+ poolId: params.poolId,
13090
+ orderType: params.orderType,
13091
+ triggerType: params.triggerType,
13092
+ operation: OperationType.DECREASE,
13093
+ direction: params.direction,
13094
+ collateralAmount: collateralWithNetworkFee,
13095
+ size: params.size,
13096
+ price: params.price,
13097
+ timeInForce: TIME_IN_FORCE,
13098
+ postOnly: false,
13099
+ slippagePct: params.slippagePct,
13100
+ executionFeeToken: params.executionFeeToken,
13101
+ leverage: params.leverage,
13102
+ tpSize: 0,
13103
+ tpPrice: 0,
13104
+ slSize: 0,
13105
+ slPrice: 0,
13106
+ useAccountBalance: false
13107
+ },
13108
+ {
13109
+ gasLimit: gasLimit * 130n / 100n
13110
+ }
13111
+ );
13112
+ } else {
13113
+ this.logger.info("createDecreaseOrder nft position params--->", { ...data, positionId: params.positionId });
13114
+ const gasLimit = await brokerContract.placeOrderWithPosition.estimateGas(params.positionId.toString(), {
13115
+ user: params.address,
13116
+ poolId: params.poolId,
13117
+ orderType: params.orderType,
13118
+ triggerType: params.triggerType,
13119
+ operation: OperationType.DECREASE,
13120
+ direction: params.direction,
13121
+ collateralAmount: collateralWithNetworkFee,
13122
+ size: params.size,
13123
+ price: params.price,
13124
+ timeInForce: TIME_IN_FORCE,
13125
+ postOnly: params.postOnly,
13126
+ slippagePct: params.slippagePct,
13127
+ executionFeeToken: params.executionFeeToken,
13128
+ leverage: params.leverage,
13129
+ tpSize: 0,
13130
+ tpPrice: 0,
13131
+ slSize: 0,
13132
+ slPrice: 0,
13133
+ useAccountBalance: false
13134
+ });
13135
+ transaction = await brokerContract.placeOrderWithPosition(
13136
+ params.positionId.toString(),
13137
+ {
13138
+ user: params.address,
13139
+ poolId: params.poolId,
13140
+ orderType: params.orderType,
13141
+ triggerType: params.triggerType,
13142
+ operation: OperationType.DECREASE,
13143
+ direction: params.direction,
13144
+ collateralAmount: collateralWithNetworkFee,
13145
+ size: params.size,
13146
+ price: params.price,
13147
+ timeInForce: TIME_IN_FORCE,
13148
+ postOnly: false,
13149
+ slippagePct: params.slippagePct,
13150
+ executionFeeToken: params.executionFeeToken,
13151
+ leverage: params.leverage,
13152
+ tpSize: 0,
13153
+ tpPrice: 0,
13154
+ slSize: 0,
13155
+ slPrice: 0,
13156
+ useAccountBalance: false
13157
+ },
13158
+ {
13159
+ gasLimit: gasLimit * 130n / 100n
13160
+ }
13161
+ );
13162
+ }
12804
13163
  this.logger.info("Transaction sent:", transaction.hash);
12805
13164
  this.logger.info("Waiting for confirmation...");
12806
13165
  const receipt = await transaction.wait();
@@ -12853,7 +13212,6 @@ var Order = class {
12853
13212
  {
12854
13213
  user: params.address,
12855
13214
  poolId: params.poolId,
12856
- userPositionSalt: params.userPositionSalt,
12857
13215
  orderType: OrderType.STOP,
12858
13216
  triggerType: params.tpTriggerType,
12859
13217
  operation: OperationType.DECREASE,
@@ -12875,7 +13233,6 @@ var Order = class {
12875
13233
  {
12876
13234
  user: params.address,
12877
13235
  poolId: params.poolId,
12878
- userPositionSalt: params.userPositionSalt,
12879
13236
  orderType: OrderType.STOP,
12880
13237
  triggerType: params.slTriggerType,
12881
13238
  operation: OperationType.DECREASE,
@@ -12895,11 +13252,21 @@ var Order = class {
12895
13252
  useAccountBalance: false
12896
13253
  }
12897
13254
  ];
12898
- console.log("createPositionTpSlOrder data--->", data2);
12899
- const gasLimit2 = await brokerContract.placeOrders.estimateGas(data2);
12900
- const transaction2 = await brokerContract.placeOrders(data2, {
12901
- gasLimit: gasLimit2 * 120n / 100n
12902
- });
13255
+ let transaction2;
13256
+ if (!params.positionId) {
13257
+ this.logger.info("createPositionTpSlOrder salt position data--->", data2);
13258
+ const positionId = await this.createPositionId(params.poolId, params.address, params.direction, BigInt(1));
13259
+ const gasLimit = await brokerContract.placeOrdersWithSalt.estimateGas([positionId.toString(), positionId.toString()], data2);
13260
+ transaction2 = await brokerContract.placeOrdersWithSalt([positionId.toString(), positionId.toString()], data2, {
13261
+ gasLimit: gasLimit * 120n / 100n
13262
+ });
13263
+ } else {
13264
+ this.logger.info("createPositionTpSlOrder nft position data--->", data2);
13265
+ const gasLimit = await brokerContract.placeOrdersWithPosition.estimateGas([params.positionId.toString(), params.positionId.toString()], data2);
13266
+ transaction2 = await brokerContract.placeOrdersWithPosition([params.positionId.toString(), params.positionId.toString()], data2, {
13267
+ gasLimit: gasLimit * 120n / 100n
13268
+ });
13269
+ }
12903
13270
  this.logger.info("Transaction sent:", transaction2.hash);
12904
13271
  this.logger.info("Waiting for confirmation...");
12905
13272
  const receipt2 = await transaction2.wait();
@@ -12933,7 +13300,6 @@ var Order = class {
12933
13300
  const data = {
12934
13301
  user: params.address,
12935
13302
  poolId: params.poolId,
12936
- userPositionSalt: params.userPositionSalt,
12937
13303
  orderType: OrderType.STOP,
12938
13304
  triggerType: params.tpSize !== "0" ? params.tpTriggerType : params.slTriggerType,
12939
13305
  operation: OperationType.DECREASE,
@@ -12952,11 +13318,21 @@ var Order = class {
12952
13318
  slPrice: "0",
12953
13319
  useAccountBalance: false
12954
13320
  };
12955
- console.log("createPositionTpSlOrder data--->", data);
12956
- const gasLimit = await brokerContract.placeOrder.estimateGas(data);
12957
- const transaction = await brokerContract.placeOrder(data, {
12958
- gasLimit: gasLimit * 120n / 100n
12959
- });
13321
+ let transaction;
13322
+ if (!params.positionId) {
13323
+ this.logger.info("createPositionTpOrSlOrder salt position data--->", data);
13324
+ const positionId = await this.createPositionId(params.poolId, params.address, params.direction, BigInt(1));
13325
+ const gasLimit = await brokerContract.placeOrderWithPosition.estimateGas(params.positionId.toString(), data);
13326
+ transaction = await brokerContract.placeOrderWithPosition(positionId.toString(), data, {
13327
+ gasLimit: gasLimit * 120n / 100n
13328
+ });
13329
+ } else {
13330
+ this.logger.info("createPositionTpOrSlOrder nft position data--->", data);
13331
+ const gasLimit = await brokerContract.placeOrderWithPosition.estimateGas(params.positionId.toString(), data);
13332
+ transaction = await brokerContract.placeOrderWithPosition(params.positionId.toString(), data, {
13333
+ gasLimit: gasLimit * 120n / 100n
13334
+ });
13335
+ }
12960
13336
  this.logger.info("Transaction sent:", transaction.hash);
12961
13337
  this.logger.info("Waiting for confirmation...");
12962
13338
  const receipt = await transaction.wait();
@@ -13053,7 +13429,6 @@ var Order = class {
13053
13429
  if (!config.signer) {
13054
13430
  throw new MyxSDKError("INVALID_SIGNER" /* InvalidSigner */, "Invalid signer");
13055
13431
  }
13056
- console.log("updateOrderTpSl params", params);
13057
13432
  const brokerContract = await getBrokerSingerContract(
13058
13433
  config.chainId
13059
13434
  );
@@ -13072,18 +13447,17 @@ var Order = class {
13072
13447
  paymentType: 0
13073
13448
  }
13074
13449
  };
13075
- console.log(data);
13450
+ this.logger.info("updateOrderTpSl params", data);
13076
13451
  try {
13077
13452
  const gasLimit = await brokerContract.updateOrder.estimateGas(data);
13078
- console.log("gaslimit->", gasLimit);
13079
13453
  const request = await brokerContract.updateOrder(data, {
13080
13454
  gasLimit: gasLimit * 120n / 100n
13081
13455
  });
13082
13456
  const receipt = await request?.wait();
13083
- console.log("updateOrderTpSl receipt", receipt);
13457
+ this.logger.info("updateOrderTpSl receipt", receipt);
13084
13458
  return receipt;
13085
13459
  } catch (error) {
13086
- console.error("Error updating order:", error);
13460
+ this.logger.error("Error updating order:", error);
13087
13461
  return {
13088
13462
  code: -1,
13089
13463
  message: "Failed to update order"
@@ -16935,9 +17309,7 @@ var Utils = class {
16935
17309
  }
16936
17310
  async getUserTradingFeeRate(assetClass) {
16937
17311
  const config = this.configManager.getConfig();
16938
- const brokerAddress = getContractAddressByChainId(
16939
- config.chainId
16940
- ).BROKER;
17312
+ const brokerAddress = config.brokerAddress;
16941
17313
  const brokerContract = new ethers7.Contract(
16942
17314
  brokerAddress,
16943
17315
  Broker_default,