@myx-trade/sdk 0.1.170 → 0.1.174
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 +41 -15
- package/dist/index.mjs +41 -15
- package/package.json +1 -1
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.
|
|
1824
|
+
version: "0.1.174",
|
|
1825
1825
|
private: false,
|
|
1826
1826
|
publishConfig: {
|
|
1827
1827
|
access: "public"
|
|
@@ -14400,18 +14400,23 @@ var Order = class {
|
|
|
14400
14400
|
params.executionFeeToken,
|
|
14401
14401
|
params.collateralAmount
|
|
14402
14402
|
);
|
|
14403
|
-
const availableAccountMarginBalance = await this.account.getAvailableMarginBalance({ poolId: params.poolId, chainId: params.chainId, address: params.address });
|
|
14404
14403
|
const totalCollateralAmount = BigInt(params.collateralAmount) + BigInt(tradingFee);
|
|
14405
|
-
const
|
|
14404
|
+
const availableAccountMarginBalance = await this.account.getAvailableMarginBalance({ poolId: params.poolId, chainId: params.chainId, address: params.address });
|
|
14405
|
+
this.logger.info("createIncreaseOrder availableAccountMarginBalance-->", availableAccountMarginBalance);
|
|
14406
|
+
const needAmount = totalCollateralAmount + totalNetWorkFee;
|
|
14407
|
+
this.logger.info("createIncreaseOrder needAmount-->", needAmount);
|
|
14406
14408
|
let depositAmount = BigInt(0);
|
|
14407
14409
|
const diff = needAmount - availableAccountMarginBalance;
|
|
14410
|
+
this.logger.info("createIncreaseOrder diff-->", diff);
|
|
14408
14411
|
if (diff > BigInt(0)) {
|
|
14409
14412
|
depositAmount = diff;
|
|
14410
14413
|
}
|
|
14414
|
+
this.logger.info("createIncreaseOrder depositAmount-->", depositAmount);
|
|
14411
14415
|
const depositData = {
|
|
14412
14416
|
token: params.executionFeeToken,
|
|
14413
14417
|
amount: depositAmount.toString()
|
|
14414
14418
|
};
|
|
14419
|
+
this.logger.info("createIncreaseOrder depositData-->", depositData);
|
|
14415
14420
|
const data = {
|
|
14416
14421
|
user: params.address,
|
|
14417
14422
|
poolId: params.poolId,
|
|
@@ -14538,11 +14543,7 @@ var Order = class {
|
|
|
14538
14543
|
}
|
|
14539
14544
|
);
|
|
14540
14545
|
}
|
|
14541
|
-
this.logger.info("Transaction sent:", transaction.hash);
|
|
14542
|
-
this.logger.info("Waiting for confirmation...");
|
|
14543
14546
|
const receipt = await transaction.wait();
|
|
14544
|
-
this.logger.info("Transaction confirmed in block:", receipt?.blockNumber);
|
|
14545
|
-
this.logger.info("createIncreaseOrder receipt--->", receipt);
|
|
14546
14547
|
const orderId = this.utils.getOrderIdFromTransaction(receipt);
|
|
14547
14548
|
const result = {
|
|
14548
14549
|
success: true,
|
|
@@ -14712,6 +14713,16 @@ var Order = class {
|
|
|
14712
14713
|
async createDecreaseOrder(params) {
|
|
14713
14714
|
try {
|
|
14714
14715
|
const config = this.configManager.getConfig();
|
|
14716
|
+
const networkFee = await this.utils.getNetworkFee(
|
|
14717
|
+
params.executionFeeToken,
|
|
14718
|
+
params.chainId
|
|
14719
|
+
);
|
|
14720
|
+
let depositAmount = BigInt(0);
|
|
14721
|
+
const availableAccountMarginBalance = await this.account.getAvailableMarginBalance({ poolId: params.poolId, chainId: params.chainId, address: params.address });
|
|
14722
|
+
const needAmount = BigInt(networkFee);
|
|
14723
|
+
if (availableAccountMarginBalance < needAmount) {
|
|
14724
|
+
depositAmount = needAmount - availableAccountMarginBalance;
|
|
14725
|
+
}
|
|
14715
14726
|
const data = {
|
|
14716
14727
|
user: params.address,
|
|
14717
14728
|
poolId: params.poolId,
|
|
@@ -14733,8 +14744,13 @@ var Order = class {
|
|
|
14733
14744
|
};
|
|
14734
14745
|
const depositData = {
|
|
14735
14746
|
token: params.executionFeeToken,
|
|
14736
|
-
amount:
|
|
14747
|
+
amount: depositAmount.toString()
|
|
14737
14748
|
};
|
|
14749
|
+
const needsApproval = await this.utils.needsApproval(
|
|
14750
|
+
params.chainId,
|
|
14751
|
+
params.executionFeeToken,
|
|
14752
|
+
depositAmount.toString()
|
|
14753
|
+
);
|
|
14738
14754
|
const authorized = this.configManager.getConfig().seamlessAccount?.authorized;
|
|
14739
14755
|
const seamlessWallet = this.configManager.getConfig().seamlessAccount?.wallet;
|
|
14740
14756
|
if (config.seamlessMode && authorized && seamlessWallet) {
|
|
@@ -14786,11 +14802,20 @@ var Order = class {
|
|
|
14786
14802
|
params.chainId,
|
|
14787
14803
|
this.configManager.getConfig().brokerAddress
|
|
14788
14804
|
);
|
|
14789
|
-
|
|
14805
|
+
if (needsApproval) {
|
|
14806
|
+
const approvalResult = await this.utils.approveAuthorization({
|
|
14807
|
+
chainId: params.chainId,
|
|
14808
|
+
quoteAddress: params.executionFeeToken,
|
|
14809
|
+
amount: import_ethers24.ethers.MaxUint256.toString()
|
|
14810
|
+
});
|
|
14811
|
+
if (approvalResult.code !== 0) {
|
|
14812
|
+
throw new Error(approvalResult.message);
|
|
14813
|
+
}
|
|
14814
|
+
}
|
|
14790
14815
|
let transaction;
|
|
14791
14816
|
if (!params.positionId) {
|
|
14792
14817
|
const positionId = 1;
|
|
14793
|
-
this.logger.info("createDecreaseOrder salt position params--->", [positionId, { data }]);
|
|
14818
|
+
this.logger.info("createDecreaseOrder salt position params--->", [positionId, depositData, { data }]);
|
|
14794
14819
|
const gasLimit = await brokerContract.placeOrderWithSalt.estimateGas(positionId.toString(), depositData, data);
|
|
14795
14820
|
transaction = await brokerContract.placeOrderWithSalt(
|
|
14796
14821
|
positionId.toString(),
|
|
@@ -14801,7 +14826,7 @@ var Order = class {
|
|
|
14801
14826
|
}
|
|
14802
14827
|
);
|
|
14803
14828
|
} else {
|
|
14804
|
-
this.logger.info("createDecreaseOrder nft position params--->", [params.positionId, { data }]);
|
|
14829
|
+
this.logger.info("createDecreaseOrder nft position params--->", [params.positionId, depositData, { data }]);
|
|
14805
14830
|
const gasLimit = await brokerContract.placeOrderWithPosition.estimateGas(params.positionId.toString(), depositData, data);
|
|
14806
14831
|
transaction = await brokerContract.placeOrderWithPosition(
|
|
14807
14832
|
params.positionId.toString(),
|
|
@@ -14812,11 +14837,7 @@ var Order = class {
|
|
|
14812
14837
|
}
|
|
14813
14838
|
);
|
|
14814
14839
|
}
|
|
14815
|
-
this.logger.info("Transaction sent:", transaction.hash);
|
|
14816
|
-
this.logger.info("Waiting for confirmation...");
|
|
14817
14840
|
const receipt = await transaction.wait();
|
|
14818
|
-
this.logger.info("Transaction confirmed in block:", receipt?.blockNumber);
|
|
14819
|
-
this.logger.info("createDecreaseOrder receipt--->", receipt);
|
|
14820
14841
|
const orderId = this.utils.getOrderIdFromTransaction(receipt);
|
|
14821
14842
|
const result = {
|
|
14822
14843
|
success: true,
|
|
@@ -21149,15 +21170,20 @@ var Account = class {
|
|
|
21149
21170
|
"Failed to get account info"
|
|
21150
21171
|
);
|
|
21151
21172
|
}
|
|
21173
|
+
this.logger.info("getAvailableMarginBalance used-->", used);
|
|
21152
21174
|
const marginAccountBalance = marginAccountBalanceRes.data;
|
|
21153
21175
|
const usedMargin = BigInt(used ?? "0");
|
|
21154
21176
|
const quoteProfit = BigInt(marginAccountBalance.quoteProfit ?? 0);
|
|
21177
|
+
this.logger.info("getAvailableMarginBalance quoteProfit-->", quoteProfit.toString);
|
|
21155
21178
|
const freeAmount = BigInt(marginAccountBalance?.freeMargin ?? 0);
|
|
21179
|
+
this.logger.info("getAvailableMarginBalance freeAmount-->", freeAmount.toString());
|
|
21156
21180
|
const accountMargin = freeAmount + quoteProfit;
|
|
21181
|
+
this.logger.info("getAvailableMarginBalance accountMargin-->", accountMargin.toString());
|
|
21157
21182
|
if (accountMargin < usedMargin) {
|
|
21158
21183
|
return BigInt(0);
|
|
21159
21184
|
}
|
|
21160
21185
|
const availableAccountMarginBalance = accountMargin - usedMargin;
|
|
21186
|
+
this.logger.info("getAvailableMarginBalance availableAccountMarginBalance-->", availableAccountMarginBalance.toString());
|
|
21161
21187
|
return availableAccountMarginBalance;
|
|
21162
21188
|
} catch (error) {
|
|
21163
21189
|
this.logger.info("getAvailableMarginBalance error-->", error);
|
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.
|
|
1734
|
+
version: "0.1.174",
|
|
1735
1735
|
private: false,
|
|
1736
1736
|
publishConfig: {
|
|
1737
1737
|
access: "public"
|
|
@@ -14310,18 +14310,23 @@ var Order = class {
|
|
|
14310
14310
|
params.executionFeeToken,
|
|
14311
14311
|
params.collateralAmount
|
|
14312
14312
|
);
|
|
14313
|
-
const availableAccountMarginBalance = await this.account.getAvailableMarginBalance({ poolId: params.poolId, chainId: params.chainId, address: params.address });
|
|
14314
14313
|
const totalCollateralAmount = BigInt(params.collateralAmount) + BigInt(tradingFee);
|
|
14315
|
-
const
|
|
14314
|
+
const availableAccountMarginBalance = await this.account.getAvailableMarginBalance({ poolId: params.poolId, chainId: params.chainId, address: params.address });
|
|
14315
|
+
this.logger.info("createIncreaseOrder availableAccountMarginBalance-->", availableAccountMarginBalance);
|
|
14316
|
+
const needAmount = totalCollateralAmount + totalNetWorkFee;
|
|
14317
|
+
this.logger.info("createIncreaseOrder needAmount-->", needAmount);
|
|
14316
14318
|
let depositAmount = BigInt(0);
|
|
14317
14319
|
const diff = needAmount - availableAccountMarginBalance;
|
|
14320
|
+
this.logger.info("createIncreaseOrder diff-->", diff);
|
|
14318
14321
|
if (diff > BigInt(0)) {
|
|
14319
14322
|
depositAmount = diff;
|
|
14320
14323
|
}
|
|
14324
|
+
this.logger.info("createIncreaseOrder depositAmount-->", depositAmount);
|
|
14321
14325
|
const depositData = {
|
|
14322
14326
|
token: params.executionFeeToken,
|
|
14323
14327
|
amount: depositAmount.toString()
|
|
14324
14328
|
};
|
|
14329
|
+
this.logger.info("createIncreaseOrder depositData-->", depositData);
|
|
14325
14330
|
const data = {
|
|
14326
14331
|
user: params.address,
|
|
14327
14332
|
poolId: params.poolId,
|
|
@@ -14448,11 +14453,7 @@ var Order = class {
|
|
|
14448
14453
|
}
|
|
14449
14454
|
);
|
|
14450
14455
|
}
|
|
14451
|
-
this.logger.info("Transaction sent:", transaction.hash);
|
|
14452
|
-
this.logger.info("Waiting for confirmation...");
|
|
14453
14456
|
const receipt = await transaction.wait();
|
|
14454
|
-
this.logger.info("Transaction confirmed in block:", receipt?.blockNumber);
|
|
14455
|
-
this.logger.info("createIncreaseOrder receipt--->", receipt);
|
|
14456
14457
|
const orderId = this.utils.getOrderIdFromTransaction(receipt);
|
|
14457
14458
|
const result = {
|
|
14458
14459
|
success: true,
|
|
@@ -14622,6 +14623,16 @@ var Order = class {
|
|
|
14622
14623
|
async createDecreaseOrder(params) {
|
|
14623
14624
|
try {
|
|
14624
14625
|
const config = this.configManager.getConfig();
|
|
14626
|
+
const networkFee = await this.utils.getNetworkFee(
|
|
14627
|
+
params.executionFeeToken,
|
|
14628
|
+
params.chainId
|
|
14629
|
+
);
|
|
14630
|
+
let depositAmount = BigInt(0);
|
|
14631
|
+
const availableAccountMarginBalance = await this.account.getAvailableMarginBalance({ poolId: params.poolId, chainId: params.chainId, address: params.address });
|
|
14632
|
+
const needAmount = BigInt(networkFee);
|
|
14633
|
+
if (availableAccountMarginBalance < needAmount) {
|
|
14634
|
+
depositAmount = needAmount - availableAccountMarginBalance;
|
|
14635
|
+
}
|
|
14625
14636
|
const data = {
|
|
14626
14637
|
user: params.address,
|
|
14627
14638
|
poolId: params.poolId,
|
|
@@ -14643,8 +14654,13 @@ var Order = class {
|
|
|
14643
14654
|
};
|
|
14644
14655
|
const depositData = {
|
|
14645
14656
|
token: params.executionFeeToken,
|
|
14646
|
-
amount:
|
|
14657
|
+
amount: depositAmount.toString()
|
|
14647
14658
|
};
|
|
14659
|
+
const needsApproval = await this.utils.needsApproval(
|
|
14660
|
+
params.chainId,
|
|
14661
|
+
params.executionFeeToken,
|
|
14662
|
+
depositAmount.toString()
|
|
14663
|
+
);
|
|
14648
14664
|
const authorized = this.configManager.getConfig().seamlessAccount?.authorized;
|
|
14649
14665
|
const seamlessWallet = this.configManager.getConfig().seamlessAccount?.wallet;
|
|
14650
14666
|
if (config.seamlessMode && authorized && seamlessWallet) {
|
|
@@ -14696,11 +14712,20 @@ var Order = class {
|
|
|
14696
14712
|
params.chainId,
|
|
14697
14713
|
this.configManager.getConfig().brokerAddress
|
|
14698
14714
|
);
|
|
14699
|
-
|
|
14715
|
+
if (needsApproval) {
|
|
14716
|
+
const approvalResult = await this.utils.approveAuthorization({
|
|
14717
|
+
chainId: params.chainId,
|
|
14718
|
+
quoteAddress: params.executionFeeToken,
|
|
14719
|
+
amount: ethers6.MaxUint256.toString()
|
|
14720
|
+
});
|
|
14721
|
+
if (approvalResult.code !== 0) {
|
|
14722
|
+
throw new Error(approvalResult.message);
|
|
14723
|
+
}
|
|
14724
|
+
}
|
|
14700
14725
|
let transaction;
|
|
14701
14726
|
if (!params.positionId) {
|
|
14702
14727
|
const positionId = 1;
|
|
14703
|
-
this.logger.info("createDecreaseOrder salt position params--->", [positionId, { data }]);
|
|
14728
|
+
this.logger.info("createDecreaseOrder salt position params--->", [positionId, depositData, { data }]);
|
|
14704
14729
|
const gasLimit = await brokerContract.placeOrderWithSalt.estimateGas(positionId.toString(), depositData, data);
|
|
14705
14730
|
transaction = await brokerContract.placeOrderWithSalt(
|
|
14706
14731
|
positionId.toString(),
|
|
@@ -14711,7 +14736,7 @@ var Order = class {
|
|
|
14711
14736
|
}
|
|
14712
14737
|
);
|
|
14713
14738
|
} else {
|
|
14714
|
-
this.logger.info("createDecreaseOrder nft position params--->", [params.positionId, { data }]);
|
|
14739
|
+
this.logger.info("createDecreaseOrder nft position params--->", [params.positionId, depositData, { data }]);
|
|
14715
14740
|
const gasLimit = await brokerContract.placeOrderWithPosition.estimateGas(params.positionId.toString(), depositData, data);
|
|
14716
14741
|
transaction = await brokerContract.placeOrderWithPosition(
|
|
14717
14742
|
params.positionId.toString(),
|
|
@@ -14722,11 +14747,7 @@ var Order = class {
|
|
|
14722
14747
|
}
|
|
14723
14748
|
);
|
|
14724
14749
|
}
|
|
14725
|
-
this.logger.info("Transaction sent:", transaction.hash);
|
|
14726
|
-
this.logger.info("Waiting for confirmation...");
|
|
14727
14750
|
const receipt = await transaction.wait();
|
|
14728
|
-
this.logger.info("Transaction confirmed in block:", receipt?.blockNumber);
|
|
14729
|
-
this.logger.info("createDecreaseOrder receipt--->", receipt);
|
|
14730
14751
|
const orderId = this.utils.getOrderIdFromTransaction(receipt);
|
|
14731
14752
|
const result = {
|
|
14732
14753
|
success: true,
|
|
@@ -21059,15 +21080,20 @@ var Account = class {
|
|
|
21059
21080
|
"Failed to get account info"
|
|
21060
21081
|
);
|
|
21061
21082
|
}
|
|
21083
|
+
this.logger.info("getAvailableMarginBalance used-->", used);
|
|
21062
21084
|
const marginAccountBalance = marginAccountBalanceRes.data;
|
|
21063
21085
|
const usedMargin = BigInt(used ?? "0");
|
|
21064
21086
|
const quoteProfit = BigInt(marginAccountBalance.quoteProfit ?? 0);
|
|
21087
|
+
this.logger.info("getAvailableMarginBalance quoteProfit-->", quoteProfit.toString);
|
|
21065
21088
|
const freeAmount = BigInt(marginAccountBalance?.freeMargin ?? 0);
|
|
21089
|
+
this.logger.info("getAvailableMarginBalance freeAmount-->", freeAmount.toString());
|
|
21066
21090
|
const accountMargin = freeAmount + quoteProfit;
|
|
21091
|
+
this.logger.info("getAvailableMarginBalance accountMargin-->", accountMargin.toString());
|
|
21067
21092
|
if (accountMargin < usedMargin) {
|
|
21068
21093
|
return BigInt(0);
|
|
21069
21094
|
}
|
|
21070
21095
|
const availableAccountMarginBalance = accountMargin - usedMargin;
|
|
21096
|
+
this.logger.info("getAvailableMarginBalance availableAccountMarginBalance-->", availableAccountMarginBalance.toString());
|
|
21071
21097
|
return availableAccountMarginBalance;
|
|
21072
21098
|
} catch (error) {
|
|
21073
21099
|
this.logger.info("getAvailableMarginBalance error-->", error);
|