@myx-trade/sdk 0.1.170 → 0.1.172

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
@@ -1821,7 +1821,7 @@ var RotationProvider = class extends import_providers.BaseProvider {
1821
1821
  // package.json
1822
1822
  var package_default = {
1823
1823
  name: "@myx-trade/sdk",
1824
- version: "0.1.170",
1824
+ version: "0.1.172",
1825
1825
  private: false,
1826
1826
  publishConfig: {
1827
1827
  access: "public"
@@ -14538,11 +14538,7 @@ var Order = class {
14538
14538
  }
14539
14539
  );
14540
14540
  }
14541
- this.logger.info("Transaction sent:", transaction.hash);
14542
- this.logger.info("Waiting for confirmation...");
14543
14541
  const receipt = await transaction.wait();
14544
- this.logger.info("Transaction confirmed in block:", receipt?.blockNumber);
14545
- this.logger.info("createIncreaseOrder receipt--->", receipt);
14546
14542
  const orderId = this.utils.getOrderIdFromTransaction(receipt);
14547
14543
  const result = {
14548
14544
  success: true,
@@ -14712,6 +14708,16 @@ var Order = class {
14712
14708
  async createDecreaseOrder(params) {
14713
14709
  try {
14714
14710
  const config = this.configManager.getConfig();
14711
+ const networkFee = await this.utils.getNetworkFee(
14712
+ params.executionFeeToken,
14713
+ params.chainId
14714
+ );
14715
+ let depositAmount = BigInt(0);
14716
+ const availableAccountMarginBalance = await this.account.getAvailableMarginBalance({ poolId: params.poolId, chainId: params.chainId, address: params.address });
14717
+ const needAmount = BigInt(networkFee);
14718
+ if (availableAccountMarginBalance < needAmount) {
14719
+ depositAmount = needAmount - availableAccountMarginBalance;
14720
+ }
14715
14721
  const data = {
14716
14722
  user: params.address,
14717
14723
  poolId: params.poolId,
@@ -14733,8 +14739,13 @@ var Order = class {
14733
14739
  };
14734
14740
  const depositData = {
14735
14741
  token: params.executionFeeToken,
14736
- amount: "0"
14742
+ amount: depositAmount.toString()
14737
14743
  };
14744
+ const needsApproval = await this.utils.needsApproval(
14745
+ params.chainId,
14746
+ params.executionFeeToken,
14747
+ depositAmount.toString()
14748
+ );
14738
14749
  const authorized = this.configManager.getConfig().seamlessAccount?.authorized;
14739
14750
  const seamlessWallet = this.configManager.getConfig().seamlessAccount?.wallet;
14740
14751
  if (config.seamlessMode && authorized && seamlessWallet) {
@@ -14786,11 +14797,20 @@ var Order = class {
14786
14797
  params.chainId,
14787
14798
  this.configManager.getConfig().brokerAddress
14788
14799
  );
14789
- console.log("data-->", data);
14800
+ if (needsApproval) {
14801
+ const approvalResult = await this.utils.approveAuthorization({
14802
+ chainId: params.chainId,
14803
+ quoteAddress: params.executionFeeToken,
14804
+ amount: import_ethers24.ethers.MaxUint256.toString()
14805
+ });
14806
+ if (approvalResult.code !== 0) {
14807
+ throw new Error(approvalResult.message);
14808
+ }
14809
+ }
14790
14810
  let transaction;
14791
14811
  if (!params.positionId) {
14792
14812
  const positionId = 1;
14793
- this.logger.info("createDecreaseOrder salt position params--->", [positionId, { data }]);
14813
+ this.logger.info("createDecreaseOrder salt position params--->", [positionId, depositData, { data }]);
14794
14814
  const gasLimit = await brokerContract.placeOrderWithSalt.estimateGas(positionId.toString(), depositData, data);
14795
14815
  transaction = await brokerContract.placeOrderWithSalt(
14796
14816
  positionId.toString(),
@@ -14801,7 +14821,7 @@ var Order = class {
14801
14821
  }
14802
14822
  );
14803
14823
  } else {
14804
- this.logger.info("createDecreaseOrder nft position params--->", [params.positionId, { data }]);
14824
+ this.logger.info("createDecreaseOrder nft position params--->", [params.positionId, depositData, { data }]);
14805
14825
  const gasLimit = await brokerContract.placeOrderWithPosition.estimateGas(params.positionId.toString(), depositData, data);
14806
14826
  transaction = await brokerContract.placeOrderWithPosition(
14807
14827
  params.positionId.toString(),
@@ -14812,11 +14832,7 @@ var Order = class {
14812
14832
  }
14813
14833
  );
14814
14834
  }
14815
- this.logger.info("Transaction sent:", transaction.hash);
14816
- this.logger.info("Waiting for confirmation...");
14817
14835
  const receipt = await transaction.wait();
14818
- this.logger.info("Transaction confirmed in block:", receipt?.blockNumber);
14819
- this.logger.info("createDecreaseOrder receipt--->", receipt);
14820
14836
  const orderId = this.utils.getOrderIdFromTransaction(receipt);
14821
14837
  const result = {
14822
14838
  success: true,
package/dist/index.mjs CHANGED
@@ -1731,7 +1731,7 @@ var RotationProvider = class extends BaseProvider {
1731
1731
  // package.json
1732
1732
  var package_default = {
1733
1733
  name: "@myx-trade/sdk",
1734
- version: "0.1.170",
1734
+ version: "0.1.172",
1735
1735
  private: false,
1736
1736
  publishConfig: {
1737
1737
  access: "public"
@@ -14448,11 +14448,7 @@ var Order = class {
14448
14448
  }
14449
14449
  );
14450
14450
  }
14451
- this.logger.info("Transaction sent:", transaction.hash);
14452
- this.logger.info("Waiting for confirmation...");
14453
14451
  const receipt = await transaction.wait();
14454
- this.logger.info("Transaction confirmed in block:", receipt?.blockNumber);
14455
- this.logger.info("createIncreaseOrder receipt--->", receipt);
14456
14452
  const orderId = this.utils.getOrderIdFromTransaction(receipt);
14457
14453
  const result = {
14458
14454
  success: true,
@@ -14622,6 +14618,16 @@ var Order = class {
14622
14618
  async createDecreaseOrder(params) {
14623
14619
  try {
14624
14620
  const config = this.configManager.getConfig();
14621
+ const networkFee = await this.utils.getNetworkFee(
14622
+ params.executionFeeToken,
14623
+ params.chainId
14624
+ );
14625
+ let depositAmount = BigInt(0);
14626
+ const availableAccountMarginBalance = await this.account.getAvailableMarginBalance({ poolId: params.poolId, chainId: params.chainId, address: params.address });
14627
+ const needAmount = BigInt(networkFee);
14628
+ if (availableAccountMarginBalance < needAmount) {
14629
+ depositAmount = needAmount - availableAccountMarginBalance;
14630
+ }
14625
14631
  const data = {
14626
14632
  user: params.address,
14627
14633
  poolId: params.poolId,
@@ -14643,8 +14649,13 @@ var Order = class {
14643
14649
  };
14644
14650
  const depositData = {
14645
14651
  token: params.executionFeeToken,
14646
- amount: "0"
14652
+ amount: depositAmount.toString()
14647
14653
  };
14654
+ const needsApproval = await this.utils.needsApproval(
14655
+ params.chainId,
14656
+ params.executionFeeToken,
14657
+ depositAmount.toString()
14658
+ );
14648
14659
  const authorized = this.configManager.getConfig().seamlessAccount?.authorized;
14649
14660
  const seamlessWallet = this.configManager.getConfig().seamlessAccount?.wallet;
14650
14661
  if (config.seamlessMode && authorized && seamlessWallet) {
@@ -14696,11 +14707,20 @@ var Order = class {
14696
14707
  params.chainId,
14697
14708
  this.configManager.getConfig().brokerAddress
14698
14709
  );
14699
- console.log("data-->", data);
14710
+ if (needsApproval) {
14711
+ const approvalResult = await this.utils.approveAuthorization({
14712
+ chainId: params.chainId,
14713
+ quoteAddress: params.executionFeeToken,
14714
+ amount: ethers6.MaxUint256.toString()
14715
+ });
14716
+ if (approvalResult.code !== 0) {
14717
+ throw new Error(approvalResult.message);
14718
+ }
14719
+ }
14700
14720
  let transaction;
14701
14721
  if (!params.positionId) {
14702
14722
  const positionId = 1;
14703
- this.logger.info("createDecreaseOrder salt position params--->", [positionId, { data }]);
14723
+ this.logger.info("createDecreaseOrder salt position params--->", [positionId, depositData, { data }]);
14704
14724
  const gasLimit = await brokerContract.placeOrderWithSalt.estimateGas(positionId.toString(), depositData, data);
14705
14725
  transaction = await brokerContract.placeOrderWithSalt(
14706
14726
  positionId.toString(),
@@ -14711,7 +14731,7 @@ var Order = class {
14711
14731
  }
14712
14732
  );
14713
14733
  } else {
14714
- this.logger.info("createDecreaseOrder nft position params--->", [params.positionId, { data }]);
14734
+ this.logger.info("createDecreaseOrder nft position params--->", [params.positionId, depositData, { data }]);
14715
14735
  const gasLimit = await brokerContract.placeOrderWithPosition.estimateGas(params.positionId.toString(), depositData, data);
14716
14736
  transaction = await brokerContract.placeOrderWithPosition(
14717
14737
  params.positionId.toString(),
@@ -14722,11 +14742,7 @@ var Order = class {
14722
14742
  }
14723
14743
  );
14724
14744
  }
14725
- this.logger.info("Transaction sent:", transaction.hash);
14726
- this.logger.info("Waiting for confirmation...");
14727
14745
  const receipt = await transaction.wait();
14728
- this.logger.info("Transaction confirmed in block:", receipt?.blockNumber);
14729
- this.logger.info("createDecreaseOrder receipt--->", receipt);
14730
14746
  const orderId = this.utils.getOrderIdFromTransaction(receipt);
14731
14747
  const result = {
14732
14748
  success: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@myx-trade/sdk",
3
- "version": "0.1.170",
3
+ "version": "0.1.172",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"