@myx-trade/sdk 0.1.107 → 0.1.108
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.d.mts +26 -2
- package/dist/index.d.ts +26 -2
- package/dist/index.js +290 -33
- package/dist/index.mjs +290 -33
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1318,11 +1318,12 @@ declare class Utils {
|
|
|
1318
1318
|
getOrderIdFromTransaction(receipt: any): string | null;
|
|
1319
1319
|
private getApproveQuoteAmount;
|
|
1320
1320
|
needsApproval(chainId: number, quoteAddress: string, requiredAmount: string, spenderAddress?: string): Promise<boolean>;
|
|
1321
|
-
approveAuthorization({ chainId, quoteAddress, amount, spenderAddress, }: {
|
|
1321
|
+
approveAuthorization({ chainId, quoteAddress, amount, spenderAddress, signer }: {
|
|
1322
1322
|
chainId: number;
|
|
1323
1323
|
quoteAddress: string;
|
|
1324
1324
|
amount?: string;
|
|
1325
1325
|
spenderAddress?: string;
|
|
1326
|
+
signer?: ethers$1.Signer;
|
|
1326
1327
|
}): Promise<{
|
|
1327
1328
|
code: number;
|
|
1328
1329
|
message: any;
|
|
@@ -1606,7 +1607,6 @@ declare class Seamless {
|
|
|
1606
1607
|
code: number;
|
|
1607
1608
|
data: {
|
|
1608
1609
|
open: boolean;
|
|
1609
|
-
config: MyxClientConfig;
|
|
1610
1610
|
};
|
|
1611
1611
|
}>;
|
|
1612
1612
|
createSeamless({ password, chainId }: {
|
|
@@ -1659,6 +1659,17 @@ declare class Order {
|
|
|
1659
1659
|
data?: undefined;
|
|
1660
1660
|
}>;
|
|
1661
1661
|
closeAllPositions(chainId: number, params: PlaceOrderParams[]): Promise<{
|
|
1662
|
+
code: number;
|
|
1663
|
+
message: string;
|
|
1664
|
+
data: ApiResponse<any>;
|
|
1665
|
+
transactionHash?: undefined;
|
|
1666
|
+
blockNumber?: undefined;
|
|
1667
|
+
gasUsed?: undefined;
|
|
1668
|
+
status?: undefined;
|
|
1669
|
+
confirmations?: undefined;
|
|
1670
|
+
timestamp?: undefined;
|
|
1671
|
+
receipt?: undefined;
|
|
1672
|
+
} | {
|
|
1662
1673
|
code: number;
|
|
1663
1674
|
message: string;
|
|
1664
1675
|
data: string | null;
|
|
@@ -1682,6 +1693,10 @@ declare class Order {
|
|
|
1682
1693
|
receipt?: undefined;
|
|
1683
1694
|
}>;
|
|
1684
1695
|
createDecreaseOrder(params: PlaceOrderParams): Promise<{
|
|
1696
|
+
code: number;
|
|
1697
|
+
message: string;
|
|
1698
|
+
data: ApiResponse<any>;
|
|
1699
|
+
} | {
|
|
1685
1700
|
code: number;
|
|
1686
1701
|
message: string;
|
|
1687
1702
|
data: {
|
|
@@ -1701,6 +1716,10 @@ declare class Order {
|
|
|
1701
1716
|
data?: undefined;
|
|
1702
1717
|
}>;
|
|
1703
1718
|
createPositionTpSlOrder(params: PositionTpSlOrderParams): Promise<{
|
|
1719
|
+
code: number;
|
|
1720
|
+
message: string;
|
|
1721
|
+
data: ApiResponse<any>;
|
|
1722
|
+
} | {
|
|
1704
1723
|
code: number;
|
|
1705
1724
|
message: string;
|
|
1706
1725
|
data: {
|
|
@@ -1720,8 +1739,13 @@ declare class Order {
|
|
|
1720
1739
|
data?: undefined;
|
|
1721
1740
|
}>;
|
|
1722
1741
|
cancelAllOrders(orderIds: string[], chainId: ChainId): Promise<{
|
|
1742
|
+
code: number;
|
|
1743
|
+
message: string;
|
|
1744
|
+
data: ApiResponse<any>;
|
|
1745
|
+
} | {
|
|
1723
1746
|
code: number;
|
|
1724
1747
|
message: any;
|
|
1748
|
+
data?: undefined;
|
|
1725
1749
|
}>;
|
|
1726
1750
|
cancelOrder(orderId: string, chainId: ChainId): Promise<{
|
|
1727
1751
|
code: number;
|
package/dist/index.d.ts
CHANGED
|
@@ -1318,11 +1318,12 @@ declare class Utils {
|
|
|
1318
1318
|
getOrderIdFromTransaction(receipt: any): string | null;
|
|
1319
1319
|
private getApproveQuoteAmount;
|
|
1320
1320
|
needsApproval(chainId: number, quoteAddress: string, requiredAmount: string, spenderAddress?: string): Promise<boolean>;
|
|
1321
|
-
approveAuthorization({ chainId, quoteAddress, amount, spenderAddress, }: {
|
|
1321
|
+
approveAuthorization({ chainId, quoteAddress, amount, spenderAddress, signer }: {
|
|
1322
1322
|
chainId: number;
|
|
1323
1323
|
quoteAddress: string;
|
|
1324
1324
|
amount?: string;
|
|
1325
1325
|
spenderAddress?: string;
|
|
1326
|
+
signer?: ethers$1.Signer;
|
|
1326
1327
|
}): Promise<{
|
|
1327
1328
|
code: number;
|
|
1328
1329
|
message: any;
|
|
@@ -1606,7 +1607,6 @@ declare class Seamless {
|
|
|
1606
1607
|
code: number;
|
|
1607
1608
|
data: {
|
|
1608
1609
|
open: boolean;
|
|
1609
|
-
config: MyxClientConfig;
|
|
1610
1610
|
};
|
|
1611
1611
|
}>;
|
|
1612
1612
|
createSeamless({ password, chainId }: {
|
|
@@ -1659,6 +1659,17 @@ declare class Order {
|
|
|
1659
1659
|
data?: undefined;
|
|
1660
1660
|
}>;
|
|
1661
1661
|
closeAllPositions(chainId: number, params: PlaceOrderParams[]): Promise<{
|
|
1662
|
+
code: number;
|
|
1663
|
+
message: string;
|
|
1664
|
+
data: ApiResponse<any>;
|
|
1665
|
+
transactionHash?: undefined;
|
|
1666
|
+
blockNumber?: undefined;
|
|
1667
|
+
gasUsed?: undefined;
|
|
1668
|
+
status?: undefined;
|
|
1669
|
+
confirmations?: undefined;
|
|
1670
|
+
timestamp?: undefined;
|
|
1671
|
+
receipt?: undefined;
|
|
1672
|
+
} | {
|
|
1662
1673
|
code: number;
|
|
1663
1674
|
message: string;
|
|
1664
1675
|
data: string | null;
|
|
@@ -1682,6 +1693,10 @@ declare class Order {
|
|
|
1682
1693
|
receipt?: undefined;
|
|
1683
1694
|
}>;
|
|
1684
1695
|
createDecreaseOrder(params: PlaceOrderParams): Promise<{
|
|
1696
|
+
code: number;
|
|
1697
|
+
message: string;
|
|
1698
|
+
data: ApiResponse<any>;
|
|
1699
|
+
} | {
|
|
1685
1700
|
code: number;
|
|
1686
1701
|
message: string;
|
|
1687
1702
|
data: {
|
|
@@ -1701,6 +1716,10 @@ declare class Order {
|
|
|
1701
1716
|
data?: undefined;
|
|
1702
1717
|
}>;
|
|
1703
1718
|
createPositionTpSlOrder(params: PositionTpSlOrderParams): Promise<{
|
|
1719
|
+
code: number;
|
|
1720
|
+
message: string;
|
|
1721
|
+
data: ApiResponse<any>;
|
|
1722
|
+
} | {
|
|
1704
1723
|
code: number;
|
|
1705
1724
|
message: string;
|
|
1706
1725
|
data: {
|
|
@@ -1720,8 +1739,13 @@ declare class Order {
|
|
|
1720
1739
|
data?: undefined;
|
|
1721
1740
|
}>;
|
|
1722
1741
|
cancelAllOrders(orderIds: string[], chainId: ChainId): Promise<{
|
|
1742
|
+
code: number;
|
|
1743
|
+
message: string;
|
|
1744
|
+
data: ApiResponse<any>;
|
|
1745
|
+
} | {
|
|
1723
1746
|
code: number;
|
|
1724
1747
|
message: any;
|
|
1748
|
+
data?: undefined;
|
|
1725
1749
|
}>;
|
|
1726
1750
|
cancelOrder(orderId: string, chainId: ChainId): Promise<{
|
|
1727
1751
|
code: number;
|
package/dist/index.js
CHANGED
|
@@ -1822,7 +1822,7 @@ var RotationProvider = class extends import_providers.BaseProvider {
|
|
|
1822
1822
|
// package.json
|
|
1823
1823
|
var package_default = {
|
|
1824
1824
|
name: "@myx-trade/sdk",
|
|
1825
|
-
version: "0.1.
|
|
1825
|
+
version: "0.1.108",
|
|
1826
1826
|
private: false,
|
|
1827
1827
|
publishConfig: {
|
|
1828
1828
|
access: "public"
|
|
@@ -14376,9 +14376,6 @@ var Order = class {
|
|
|
14376
14376
|
async createIncreaseOrder(params) {
|
|
14377
14377
|
try {
|
|
14378
14378
|
const config = this.configManager.getConfig();
|
|
14379
|
-
if (!config.signer) {
|
|
14380
|
-
throw new MyxSDKError("INVALID_SIGNER" /* InvalidSigner */, "Invalid signer");
|
|
14381
|
-
}
|
|
14382
14379
|
const networkFee = await this.utils.getNetworkFee(
|
|
14383
14380
|
params.executionFeeToken,
|
|
14384
14381
|
params.chainId
|
|
@@ -14437,13 +14434,20 @@ var Order = class {
|
|
|
14437
14434
|
slSize: params.slSize ?? "0",
|
|
14438
14435
|
slPrice: params.slPrice ?? "0"
|
|
14439
14436
|
};
|
|
14440
|
-
this.logger.info("createIncreaseOrder position params--->", data);
|
|
14441
14437
|
const authorized = this.configManager.getConfig().seamlessAccount?.authorized;
|
|
14442
14438
|
const seamlessWallet = this.configManager.getConfig().seamlessAccount?.wallet;
|
|
14443
|
-
this.logger.info("seamlessWallet-->", seamlessWallet);
|
|
14444
|
-
this.logger.info("authorized-->", authorized);
|
|
14445
|
-
this.logger.info("config.seamlessMode-->", config.seamlessMode);
|
|
14446
14439
|
if (config.seamlessMode && authorized && seamlessWallet) {
|
|
14440
|
+
if (needsApproval) {
|
|
14441
|
+
const approvalResult = await this.utils.approveAuthorization({
|
|
14442
|
+
chainId: params.chainId,
|
|
14443
|
+
quoteAddress: params.executionFeeToken,
|
|
14444
|
+
amount: import_ethers24.ethers.MaxUint256.toString(),
|
|
14445
|
+
signer: seamlessWallet
|
|
14446
|
+
});
|
|
14447
|
+
if (approvalResult.code !== 0) {
|
|
14448
|
+
throw new Error(approvalResult.message);
|
|
14449
|
+
}
|
|
14450
|
+
}
|
|
14447
14451
|
const isEnoughGas = await this.utils.checkSeamlessGas(params.address);
|
|
14448
14452
|
if (!isEnoughGas) {
|
|
14449
14453
|
throw new MyxSDKError("INSUFFICIENT_BALANCE" /* InsufficientBalance */, "Insufficient relay fee");
|
|
@@ -14464,7 +14468,6 @@ var Order = class {
|
|
|
14464
14468
|
{ ...depositData },
|
|
14465
14469
|
data
|
|
14466
14470
|
]);
|
|
14467
|
-
this.logger.info("createIncreaseOrder placeOrderWithSalt function hash --->", functionHash);
|
|
14468
14471
|
} else {
|
|
14469
14472
|
functionHash = brokerContract2.interface.encodeFunctionData("placeOrderWithPosition", [
|
|
14470
14473
|
params.positionId.toString(),
|
|
@@ -14491,6 +14494,19 @@ var Order = class {
|
|
|
14491
14494
|
data: rs
|
|
14492
14495
|
};
|
|
14493
14496
|
}
|
|
14497
|
+
if (!config.signer) {
|
|
14498
|
+
throw new MyxSDKError("INVALID_SIGNER" /* InvalidSigner */, "Invalid signer");
|
|
14499
|
+
}
|
|
14500
|
+
if (needsApproval) {
|
|
14501
|
+
const approvalResult = await this.utils.approveAuthorization({
|
|
14502
|
+
chainId: params.chainId,
|
|
14503
|
+
quoteAddress: params.executionFeeToken,
|
|
14504
|
+
amount: import_ethers24.ethers.MaxUint256.toString()
|
|
14505
|
+
});
|
|
14506
|
+
if (approvalResult.code !== 0) {
|
|
14507
|
+
throw new Error(approvalResult.message);
|
|
14508
|
+
}
|
|
14509
|
+
}
|
|
14494
14510
|
const brokerContract = await getBrokerSingerContract(
|
|
14495
14511
|
params.chainId,
|
|
14496
14512
|
this.configManager.getConfig().brokerAddress
|
|
@@ -14565,10 +14581,6 @@ var Order = class {
|
|
|
14565
14581
|
if (!config.signer) {
|
|
14566
14582
|
throw new MyxSDKError("INVALID_SIGNER" /* InvalidSigner */, "Invalid signer");
|
|
14567
14583
|
}
|
|
14568
|
-
const brokerContract = await getBrokerSingerContract(
|
|
14569
|
-
chainId,
|
|
14570
|
-
this.configManager.getConfig().brokerAddress
|
|
14571
|
-
);
|
|
14572
14584
|
const networkFee = await this.utils.getNetworkFee(
|
|
14573
14585
|
params[0].executionFeeToken,
|
|
14574
14586
|
chainId
|
|
@@ -14579,16 +14591,6 @@ var Order = class {
|
|
|
14579
14591
|
params[0].executionFeeToken,
|
|
14580
14592
|
depositAmount.toString()
|
|
14581
14593
|
);
|
|
14582
|
-
if (needsApproval) {
|
|
14583
|
-
const approvalResult = await this.utils.approveAuthorization({
|
|
14584
|
-
chainId,
|
|
14585
|
-
quoteAddress: params[0].executionFeeToken,
|
|
14586
|
-
amount: import_ethers24.ethers.MaxUint256.toString()
|
|
14587
|
-
});
|
|
14588
|
-
if (approvalResult.code !== 0) {
|
|
14589
|
-
throw new Error(approvalResult.message);
|
|
14590
|
-
}
|
|
14591
|
-
}
|
|
14592
14594
|
const depositData = {
|
|
14593
14595
|
token: params[0].executionFeeToken,
|
|
14594
14596
|
amount: depositAmount.toString()
|
|
@@ -14617,6 +14619,63 @@ var Order = class {
|
|
|
14617
14619
|
};
|
|
14618
14620
|
});
|
|
14619
14621
|
this.logger.info("closeAllPositions params--->", depositData, positionIds, dataMap);
|
|
14622
|
+
const authorized = this.configManager.getConfig().seamlessAccount?.authorized;
|
|
14623
|
+
const seamlessWallet = this.configManager.getConfig().seamlessAccount?.wallet;
|
|
14624
|
+
if (config.seamlessMode && authorized && seamlessWallet) {
|
|
14625
|
+
if (needsApproval) {
|
|
14626
|
+
const approvalResult = await this.utils.approveAuthorization({
|
|
14627
|
+
chainId,
|
|
14628
|
+
quoteAddress: params[0].executionFeeToken,
|
|
14629
|
+
amount: import_ethers24.ethers.MaxUint256.toString(),
|
|
14630
|
+
signer: seamlessWallet
|
|
14631
|
+
});
|
|
14632
|
+
if (approvalResult.code !== 0) {
|
|
14633
|
+
throw new Error(approvalResult.message);
|
|
14634
|
+
}
|
|
14635
|
+
}
|
|
14636
|
+
const isEnoughGas = await this.utils.checkSeamlessGas(params[0].address);
|
|
14637
|
+
if (!isEnoughGas) {
|
|
14638
|
+
throw new MyxSDKError("INSUFFICIENT_BALANCE" /* InsufficientBalance */, "Insufficient relay fee");
|
|
14639
|
+
}
|
|
14640
|
+
const forwarderContract = await getForwarderContract(chainId);
|
|
14641
|
+
const brokerContract2 = await getSeamlessBrokerContract(
|
|
14642
|
+
this.configManager.getConfig().brokerAddress,
|
|
14643
|
+
seamlessWallet
|
|
14644
|
+
);
|
|
14645
|
+
const functionHash = brokerContract2.interface.encodeFunctionData("placeOrdersWithPosition", [depositData, positionIds, dataMap]);
|
|
14646
|
+
const nonce = await forwarderContract.nonces(seamlessWallet.address);
|
|
14647
|
+
const forwardTxParams = {
|
|
14648
|
+
from: seamlessWallet.address ?? "",
|
|
14649
|
+
to: this.configManager.getConfig().brokerAddress,
|
|
14650
|
+
value: "0",
|
|
14651
|
+
gas: "350000",
|
|
14652
|
+
deadline: (0, import_dayjs.default)().add(60, "minute").unix(),
|
|
14653
|
+
data: functionHash,
|
|
14654
|
+
nonce: nonce.toString()
|
|
14655
|
+
};
|
|
14656
|
+
this.logger.info("cancel all positions forward tx params --->", forwardTxParams);
|
|
14657
|
+
const rs = await this.seamless.forwarderTx(forwardTxParams, seamlessWallet);
|
|
14658
|
+
console.log("rs-->", rs);
|
|
14659
|
+
return {
|
|
14660
|
+
code: 0,
|
|
14661
|
+
message: "cancel all positions success",
|
|
14662
|
+
data: rs
|
|
14663
|
+
};
|
|
14664
|
+
}
|
|
14665
|
+
const brokerContract = await getBrokerSingerContract(
|
|
14666
|
+
chainId,
|
|
14667
|
+
this.configManager.getConfig().brokerAddress
|
|
14668
|
+
);
|
|
14669
|
+
if (needsApproval) {
|
|
14670
|
+
const approvalResult = await this.utils.approveAuthorization({
|
|
14671
|
+
chainId,
|
|
14672
|
+
quoteAddress: params[0].executionFeeToken,
|
|
14673
|
+
amount: import_ethers24.ethers.MaxUint256.toString()
|
|
14674
|
+
});
|
|
14675
|
+
if (approvalResult.code !== 0) {
|
|
14676
|
+
throw new Error(approvalResult.message);
|
|
14677
|
+
}
|
|
14678
|
+
}
|
|
14620
14679
|
const gasLimit = await brokerContract.placeOrdersWithPosition.estimateGas(depositData, positionIds, dataMap);
|
|
14621
14680
|
const transaction = await brokerContract.placeOrdersWithPosition(depositData, positionIds, dataMap, {
|
|
14622
14681
|
gasLimit: gasLimit * 120n / 100n
|
|
@@ -14650,9 +14709,6 @@ var Order = class {
|
|
|
14650
14709
|
async createDecreaseOrder(params) {
|
|
14651
14710
|
try {
|
|
14652
14711
|
const config = this.configManager.getConfig();
|
|
14653
|
-
if (!config.signer) {
|
|
14654
|
-
throw new MyxSDKError("INVALID_SIGNER" /* InvalidSigner */, "Invalid signer");
|
|
14655
|
-
}
|
|
14656
14712
|
const brokerContract = await getBrokerSingerContract(
|
|
14657
14713
|
params.chainId,
|
|
14658
14714
|
this.configManager.getConfig().brokerAddress
|
|
@@ -14690,6 +14746,65 @@ var Order = class {
|
|
|
14690
14746
|
params.executionFeeToken,
|
|
14691
14747
|
networkFee.toString()
|
|
14692
14748
|
);
|
|
14749
|
+
const authorized = this.configManager.getConfig().seamlessAccount?.authorized;
|
|
14750
|
+
const seamlessWallet = this.configManager.getConfig().seamlessAccount?.wallet;
|
|
14751
|
+
if (config.seamlessMode && authorized && seamlessWallet) {
|
|
14752
|
+
if (needsApproval) {
|
|
14753
|
+
const approvalResult = await this.utils.approveAuthorization({
|
|
14754
|
+
chainId: params.chainId,
|
|
14755
|
+
quoteAddress: params.executionFeeToken,
|
|
14756
|
+
amount: import_ethers24.ethers.MaxUint256.toString(),
|
|
14757
|
+
signer: seamlessWallet
|
|
14758
|
+
});
|
|
14759
|
+
if (approvalResult.code !== 0) {
|
|
14760
|
+
throw new Error(approvalResult.message);
|
|
14761
|
+
}
|
|
14762
|
+
}
|
|
14763
|
+
const isEnoughGas = await this.utils.checkSeamlessGas(params.address);
|
|
14764
|
+
if (!isEnoughGas) {
|
|
14765
|
+
throw new MyxSDKError("INSUFFICIENT_BALANCE" /* InsufficientBalance */, "Insufficient relay fee");
|
|
14766
|
+
}
|
|
14767
|
+
const forwarderContract = await getForwarderContract(params.chainId);
|
|
14768
|
+
const brokerContract2 = await getSeamlessBrokerContract(
|
|
14769
|
+
this.configManager.getConfig().brokerAddress,
|
|
14770
|
+
seamlessWallet
|
|
14771
|
+
);
|
|
14772
|
+
let functionHash = "";
|
|
14773
|
+
if (!params.positionId) {
|
|
14774
|
+
functionHash = brokerContract2.interface.encodeFunctionData("placeOrderWithSalt", [
|
|
14775
|
+
"1",
|
|
14776
|
+
{ ...depositData },
|
|
14777
|
+
data
|
|
14778
|
+
]);
|
|
14779
|
+
} else {
|
|
14780
|
+
functionHash = brokerContract2.interface.encodeFunctionData("placeOrderWithPosition", [
|
|
14781
|
+
params.positionId.toString(),
|
|
14782
|
+
{ ...depositData },
|
|
14783
|
+
data
|
|
14784
|
+
]);
|
|
14785
|
+
}
|
|
14786
|
+
const nonce = await forwarderContract.nonces(seamlessWallet.address);
|
|
14787
|
+
const forwardTxParams = {
|
|
14788
|
+
from: seamlessWallet.address ?? "",
|
|
14789
|
+
to: this.configManager.getConfig().brokerAddress,
|
|
14790
|
+
value: "0",
|
|
14791
|
+
gas: "350000",
|
|
14792
|
+
deadline: (0, import_dayjs.default)().add(60, "minute").unix(),
|
|
14793
|
+
data: functionHash,
|
|
14794
|
+
nonce: nonce.toString()
|
|
14795
|
+
};
|
|
14796
|
+
this.logger.info("create decrease order forward tx params --->", forwardTxParams);
|
|
14797
|
+
const rs = await this.seamless.forwarderTx(forwardTxParams, seamlessWallet);
|
|
14798
|
+
console.log("rs-->", rs);
|
|
14799
|
+
return {
|
|
14800
|
+
code: 0,
|
|
14801
|
+
message: "create decrease order success",
|
|
14802
|
+
data: rs
|
|
14803
|
+
};
|
|
14804
|
+
}
|
|
14805
|
+
if (!config.signer) {
|
|
14806
|
+
throw new MyxSDKError("INVALID_SIGNER" /* InvalidSigner */, "Invalid signer");
|
|
14807
|
+
}
|
|
14693
14808
|
if (needsApproval) {
|
|
14694
14809
|
const approvalResult = await this.utils.approveAuthorization({
|
|
14695
14810
|
chainId: params.chainId,
|
|
@@ -14766,7 +14881,7 @@ var Order = class {
|
|
|
14766
14881
|
async createPositionTpSlOrder(params) {
|
|
14767
14882
|
try {
|
|
14768
14883
|
const config = this.configManager.getConfig();
|
|
14769
|
-
if (!config.signer) {
|
|
14884
|
+
if (!config.signer && !config.seamlessMode) {
|
|
14770
14885
|
throw new MyxSDKError("INVALID_SIGNER" /* InvalidSigner */, "Invalid signer");
|
|
14771
14886
|
}
|
|
14772
14887
|
const brokerContract = await getBrokerSingerContract(
|
|
@@ -14827,6 +14942,62 @@ var Order = class {
|
|
|
14827
14942
|
params.executionFeeToken,
|
|
14828
14943
|
depositAmount.toString()
|
|
14829
14944
|
);
|
|
14945
|
+
const authorized2 = this.configManager.getConfig().seamlessAccount?.authorized;
|
|
14946
|
+
const seamlessWallet2 = this.configManager.getConfig().seamlessAccount?.wallet;
|
|
14947
|
+
if (config.seamlessMode && authorized2 && seamlessWallet2) {
|
|
14948
|
+
if (needsApproval2) {
|
|
14949
|
+
const approvalResult = await this.utils.approveAuthorization({
|
|
14950
|
+
chainId: params.chainId,
|
|
14951
|
+
quoteAddress: params.executionFeeToken,
|
|
14952
|
+
amount: import_ethers24.ethers.MaxUint256.toString(),
|
|
14953
|
+
signer: seamlessWallet2
|
|
14954
|
+
});
|
|
14955
|
+
if (approvalResult.code !== 0) {
|
|
14956
|
+
throw new Error(approvalResult.message);
|
|
14957
|
+
}
|
|
14958
|
+
}
|
|
14959
|
+
const isEnoughGas = await this.utils.checkSeamlessGas(params.address);
|
|
14960
|
+
if (!isEnoughGas) {
|
|
14961
|
+
throw new MyxSDKError("INSUFFICIENT_BALANCE" /* InsufficientBalance */, "Insufficient relay fee");
|
|
14962
|
+
}
|
|
14963
|
+
const forwarderContract = await getForwarderContract(params.chainId);
|
|
14964
|
+
const brokerContract2 = await getSeamlessBrokerContract(
|
|
14965
|
+
this.configManager.getConfig().brokerAddress,
|
|
14966
|
+
seamlessWallet2
|
|
14967
|
+
);
|
|
14968
|
+
let functionHash = "";
|
|
14969
|
+
if (!params.positionId) {
|
|
14970
|
+
functionHash = brokerContract2.interface.encodeFunctionData("placeOrdersWithSalt", [
|
|
14971
|
+
{ token: params.executionFeeToken, amount: depositAmount.toString() },
|
|
14972
|
+
["1", "1"],
|
|
14973
|
+
data2
|
|
14974
|
+
]);
|
|
14975
|
+
} else {
|
|
14976
|
+
functionHash = brokerContract2.interface.encodeFunctionData("placeOrdersWithPosition", [
|
|
14977
|
+
{ token: params.executionFeeToken, amount: depositAmount.toString() },
|
|
14978
|
+
[params.positionId.toString(), params.positionId.toString()],
|
|
14979
|
+
data2
|
|
14980
|
+
]);
|
|
14981
|
+
}
|
|
14982
|
+
const nonce = await forwarderContract.nonces(seamlessWallet2.address);
|
|
14983
|
+
const forwardTxParams = {
|
|
14984
|
+
from: seamlessWallet2.address ?? "",
|
|
14985
|
+
to: this.configManager.getConfig().brokerAddress,
|
|
14986
|
+
value: "0",
|
|
14987
|
+
gas: "350000",
|
|
14988
|
+
deadline: (0, import_dayjs.default)().add(60, "minute").unix(),
|
|
14989
|
+
data: functionHash,
|
|
14990
|
+
nonce: nonce.toString()
|
|
14991
|
+
};
|
|
14992
|
+
this.logger.info("createPositionTpSlOrder forward tx params --->", forwardTxParams);
|
|
14993
|
+
const rs = await this.seamless.forwarderTx(forwardTxParams, seamlessWallet2);
|
|
14994
|
+
console.log("rs-->", rs);
|
|
14995
|
+
return {
|
|
14996
|
+
code: 0,
|
|
14997
|
+
message: "createPositionTpSlOrder success",
|
|
14998
|
+
data: rs
|
|
14999
|
+
};
|
|
15000
|
+
}
|
|
14830
15001
|
if (needsApproval2) {
|
|
14831
15002
|
const approvalResult = await this.utils.approveAuthorization({
|
|
14832
15003
|
chainId: params.chainId,
|
|
@@ -14910,6 +15081,62 @@ var Order = class {
|
|
|
14910
15081
|
params.executionFeeToken,
|
|
14911
15082
|
networkFee.toString()
|
|
14912
15083
|
);
|
|
15084
|
+
const authorized = this.configManager.getConfig().seamlessAccount?.authorized;
|
|
15085
|
+
const seamlessWallet = this.configManager.getConfig().seamlessAccount?.wallet;
|
|
15086
|
+
if (config.seamlessMode && authorized && seamlessWallet) {
|
|
15087
|
+
if (needsApproval) {
|
|
15088
|
+
const approvalResult = await this.utils.approveAuthorization({
|
|
15089
|
+
chainId: params.chainId,
|
|
15090
|
+
quoteAddress: params.executionFeeToken,
|
|
15091
|
+
amount: import_ethers24.ethers.MaxUint256.toString(),
|
|
15092
|
+
signer: seamlessWallet
|
|
15093
|
+
});
|
|
15094
|
+
if (approvalResult.code !== 0) {
|
|
15095
|
+
throw new Error(approvalResult.message);
|
|
15096
|
+
}
|
|
15097
|
+
}
|
|
15098
|
+
const isEnoughGas = await this.utils.checkSeamlessGas(params.address);
|
|
15099
|
+
if (!isEnoughGas) {
|
|
15100
|
+
throw new MyxSDKError("INSUFFICIENT_BALANCE" /* InsufficientBalance */, "Insufficient relay fee");
|
|
15101
|
+
}
|
|
15102
|
+
const forwarderContract = await getForwarderContract(params.chainId);
|
|
15103
|
+
const brokerContract2 = await getSeamlessBrokerContract(
|
|
15104
|
+
this.configManager.getConfig().brokerAddress,
|
|
15105
|
+
seamlessWallet
|
|
15106
|
+
);
|
|
15107
|
+
let functionHash = "";
|
|
15108
|
+
if (!params.positionId) {
|
|
15109
|
+
functionHash = brokerContract2.interface.encodeFunctionData("placeOrderWithSalt", [
|
|
15110
|
+
"1",
|
|
15111
|
+
depositData,
|
|
15112
|
+
data
|
|
15113
|
+
]);
|
|
15114
|
+
} else {
|
|
15115
|
+
functionHash = brokerContract2.interface.encodeFunctionData("placeOrderWithPosition", [
|
|
15116
|
+
params.positionId.toString(),
|
|
15117
|
+
depositData,
|
|
15118
|
+
data
|
|
15119
|
+
]);
|
|
15120
|
+
}
|
|
15121
|
+
const nonce = await forwarderContract.nonces(seamlessWallet.address);
|
|
15122
|
+
const forwardTxParams = {
|
|
15123
|
+
from: seamlessWallet.address ?? "",
|
|
15124
|
+
to: this.configManager.getConfig().brokerAddress,
|
|
15125
|
+
value: "0",
|
|
15126
|
+
gas: "350000",
|
|
15127
|
+
deadline: (0, import_dayjs.default)().add(60, "minute").unix(),
|
|
15128
|
+
data: functionHash,
|
|
15129
|
+
nonce: nonce.toString()
|
|
15130
|
+
};
|
|
15131
|
+
this.logger.info("createPositionTpSlOrder forward tx params --->", forwardTxParams);
|
|
15132
|
+
const rs = await this.seamless.forwarderTx(forwardTxParams, seamlessWallet);
|
|
15133
|
+
console.log("rs-->", rs);
|
|
15134
|
+
return {
|
|
15135
|
+
code: 0,
|
|
15136
|
+
message: "createPositionTpSlOrder success",
|
|
15137
|
+
data: rs
|
|
15138
|
+
};
|
|
15139
|
+
}
|
|
14913
15140
|
if (needsApproval) {
|
|
14914
15141
|
const approvalResult = await this.utils.approveAuthorization({
|
|
14915
15142
|
chainId: params.chainId,
|
|
@@ -14982,6 +15209,38 @@ var Order = class {
|
|
|
14982
15209
|
async cancelAllOrders(orderIds, chainId) {
|
|
14983
15210
|
try {
|
|
14984
15211
|
const config = this.configManager.getConfig();
|
|
15212
|
+
const authorized = this.configManager.getConfig().seamlessAccount?.authorized;
|
|
15213
|
+
const seamlessWallet = this.configManager.getConfig().seamlessAccount?.wallet;
|
|
15214
|
+
if (config.seamlessMode && authorized && seamlessWallet) {
|
|
15215
|
+
const isEnoughGas = await this.utils.checkSeamlessGas(config.seamlessAccount?.masterAddress);
|
|
15216
|
+
if (!isEnoughGas) {
|
|
15217
|
+
throw new MyxSDKError("INSUFFICIENT_BALANCE" /* InsufficientBalance */, "Insufficient relay fee");
|
|
15218
|
+
}
|
|
15219
|
+
const forwarderContract = await getForwarderContract(chainId);
|
|
15220
|
+
const brokerContract2 = await getSeamlessBrokerContract(
|
|
15221
|
+
this.configManager.getConfig().brokerAddress,
|
|
15222
|
+
seamlessWallet
|
|
15223
|
+
);
|
|
15224
|
+
let functionHash = brokerContract2.interface.encodeFunctionData("cancelOrders", [orderIds]);
|
|
15225
|
+
const nonce = await forwarderContract.nonces(seamlessWallet.address);
|
|
15226
|
+
const forwardTxParams = {
|
|
15227
|
+
from: seamlessWallet.address ?? "",
|
|
15228
|
+
to: this.configManager.getConfig().brokerAddress,
|
|
15229
|
+
value: "0",
|
|
15230
|
+
gas: "350000",
|
|
15231
|
+
deadline: (0, import_dayjs.default)().add(60, "minute").unix(),
|
|
15232
|
+
data: functionHash,
|
|
15233
|
+
nonce: nonce.toString()
|
|
15234
|
+
};
|
|
15235
|
+
this.logger.info("create decrease order forward tx params --->", forwardTxParams);
|
|
15236
|
+
const rs = await this.seamless.forwarderTx(forwardTxParams, seamlessWallet);
|
|
15237
|
+
console.log("rs-->", rs);
|
|
15238
|
+
return {
|
|
15239
|
+
code: 0,
|
|
15240
|
+
message: "create decrease order success",
|
|
15241
|
+
data: rs
|
|
15242
|
+
};
|
|
15243
|
+
}
|
|
14985
15244
|
if (!config.signer) {
|
|
14986
15245
|
throw new MyxSDKError("INVALID_SIGNER" /* InvalidSigner */, "Invalid signer");
|
|
14987
15246
|
}
|
|
@@ -19873,7 +20132,8 @@ var Utils = class {
|
|
|
19873
20132
|
chainId,
|
|
19874
20133
|
quoteAddress,
|
|
19875
20134
|
amount,
|
|
19876
|
-
spenderAddress
|
|
20135
|
+
spenderAddress,
|
|
20136
|
+
signer
|
|
19877
20137
|
}) {
|
|
19878
20138
|
try {
|
|
19879
20139
|
const erc20Abi = [
|
|
@@ -19883,7 +20143,7 @@ var Utils = class {
|
|
|
19883
20143
|
const usdcContract = new import_ethers25.ethers.Contract(
|
|
19884
20144
|
quoteAddress,
|
|
19885
20145
|
erc20Abi,
|
|
19886
|
-
config.signer
|
|
20146
|
+
signer ?? config.signer
|
|
19887
20147
|
);
|
|
19888
20148
|
const approveAmount = amount ?? import_ethers25.ethers.MaxUint256;
|
|
19889
20149
|
const spender = spenderAddress ?? getContractAddressByChainId(chainId).Account;
|
|
@@ -21363,14 +21623,11 @@ var Seamless = class {
|
|
|
21363
21623
|
};
|
|
21364
21624
|
}
|
|
21365
21625
|
async startSeamlessMode({ open }) {
|
|
21366
|
-
this.logger.info("startSeamlessMode-->", open);
|
|
21367
21626
|
const config = this.configManager.startSeamlessMode(open);
|
|
21368
|
-
this.logger.info("startSeamlessMode config-->", config);
|
|
21369
21627
|
return {
|
|
21370
21628
|
code: 0,
|
|
21371
21629
|
data: {
|
|
21372
|
-
open
|
|
21373
|
-
config
|
|
21630
|
+
open
|
|
21374
21631
|
}
|
|
21375
21632
|
};
|
|
21376
21633
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -1732,7 +1732,7 @@ var RotationProvider = class extends BaseProvider {
|
|
|
1732
1732
|
// package.json
|
|
1733
1733
|
var package_default = {
|
|
1734
1734
|
name: "@myx-trade/sdk",
|
|
1735
|
-
version: "0.1.
|
|
1735
|
+
version: "0.1.108",
|
|
1736
1736
|
private: false,
|
|
1737
1737
|
publishConfig: {
|
|
1738
1738
|
access: "public"
|
|
@@ -14286,9 +14286,6 @@ var Order = class {
|
|
|
14286
14286
|
async createIncreaseOrder(params) {
|
|
14287
14287
|
try {
|
|
14288
14288
|
const config = this.configManager.getConfig();
|
|
14289
|
-
if (!config.signer) {
|
|
14290
|
-
throw new MyxSDKError("INVALID_SIGNER" /* InvalidSigner */, "Invalid signer");
|
|
14291
|
-
}
|
|
14292
14289
|
const networkFee = await this.utils.getNetworkFee(
|
|
14293
14290
|
params.executionFeeToken,
|
|
14294
14291
|
params.chainId
|
|
@@ -14347,13 +14344,20 @@ var Order = class {
|
|
|
14347
14344
|
slSize: params.slSize ?? "0",
|
|
14348
14345
|
slPrice: params.slPrice ?? "0"
|
|
14349
14346
|
};
|
|
14350
|
-
this.logger.info("createIncreaseOrder position params--->", data);
|
|
14351
14347
|
const authorized = this.configManager.getConfig().seamlessAccount?.authorized;
|
|
14352
14348
|
const seamlessWallet = this.configManager.getConfig().seamlessAccount?.wallet;
|
|
14353
|
-
this.logger.info("seamlessWallet-->", seamlessWallet);
|
|
14354
|
-
this.logger.info("authorized-->", authorized);
|
|
14355
|
-
this.logger.info("config.seamlessMode-->", config.seamlessMode);
|
|
14356
14349
|
if (config.seamlessMode && authorized && seamlessWallet) {
|
|
14350
|
+
if (needsApproval) {
|
|
14351
|
+
const approvalResult = await this.utils.approveAuthorization({
|
|
14352
|
+
chainId: params.chainId,
|
|
14353
|
+
quoteAddress: params.executionFeeToken,
|
|
14354
|
+
amount: ethers6.MaxUint256.toString(),
|
|
14355
|
+
signer: seamlessWallet
|
|
14356
|
+
});
|
|
14357
|
+
if (approvalResult.code !== 0) {
|
|
14358
|
+
throw new Error(approvalResult.message);
|
|
14359
|
+
}
|
|
14360
|
+
}
|
|
14357
14361
|
const isEnoughGas = await this.utils.checkSeamlessGas(params.address);
|
|
14358
14362
|
if (!isEnoughGas) {
|
|
14359
14363
|
throw new MyxSDKError("INSUFFICIENT_BALANCE" /* InsufficientBalance */, "Insufficient relay fee");
|
|
@@ -14374,7 +14378,6 @@ var Order = class {
|
|
|
14374
14378
|
{ ...depositData },
|
|
14375
14379
|
data
|
|
14376
14380
|
]);
|
|
14377
|
-
this.logger.info("createIncreaseOrder placeOrderWithSalt function hash --->", functionHash);
|
|
14378
14381
|
} else {
|
|
14379
14382
|
functionHash = brokerContract2.interface.encodeFunctionData("placeOrderWithPosition", [
|
|
14380
14383
|
params.positionId.toString(),
|
|
@@ -14401,6 +14404,19 @@ var Order = class {
|
|
|
14401
14404
|
data: rs
|
|
14402
14405
|
};
|
|
14403
14406
|
}
|
|
14407
|
+
if (!config.signer) {
|
|
14408
|
+
throw new MyxSDKError("INVALID_SIGNER" /* InvalidSigner */, "Invalid signer");
|
|
14409
|
+
}
|
|
14410
|
+
if (needsApproval) {
|
|
14411
|
+
const approvalResult = await this.utils.approveAuthorization({
|
|
14412
|
+
chainId: params.chainId,
|
|
14413
|
+
quoteAddress: params.executionFeeToken,
|
|
14414
|
+
amount: ethers6.MaxUint256.toString()
|
|
14415
|
+
});
|
|
14416
|
+
if (approvalResult.code !== 0) {
|
|
14417
|
+
throw new Error(approvalResult.message);
|
|
14418
|
+
}
|
|
14419
|
+
}
|
|
14404
14420
|
const brokerContract = await getBrokerSingerContract(
|
|
14405
14421
|
params.chainId,
|
|
14406
14422
|
this.configManager.getConfig().brokerAddress
|
|
@@ -14475,10 +14491,6 @@ var Order = class {
|
|
|
14475
14491
|
if (!config.signer) {
|
|
14476
14492
|
throw new MyxSDKError("INVALID_SIGNER" /* InvalidSigner */, "Invalid signer");
|
|
14477
14493
|
}
|
|
14478
|
-
const brokerContract = await getBrokerSingerContract(
|
|
14479
|
-
chainId,
|
|
14480
|
-
this.configManager.getConfig().brokerAddress
|
|
14481
|
-
);
|
|
14482
14494
|
const networkFee = await this.utils.getNetworkFee(
|
|
14483
14495
|
params[0].executionFeeToken,
|
|
14484
14496
|
chainId
|
|
@@ -14489,16 +14501,6 @@ var Order = class {
|
|
|
14489
14501
|
params[0].executionFeeToken,
|
|
14490
14502
|
depositAmount.toString()
|
|
14491
14503
|
);
|
|
14492
|
-
if (needsApproval) {
|
|
14493
|
-
const approvalResult = await this.utils.approveAuthorization({
|
|
14494
|
-
chainId,
|
|
14495
|
-
quoteAddress: params[0].executionFeeToken,
|
|
14496
|
-
amount: ethers6.MaxUint256.toString()
|
|
14497
|
-
});
|
|
14498
|
-
if (approvalResult.code !== 0) {
|
|
14499
|
-
throw new Error(approvalResult.message);
|
|
14500
|
-
}
|
|
14501
|
-
}
|
|
14502
14504
|
const depositData = {
|
|
14503
14505
|
token: params[0].executionFeeToken,
|
|
14504
14506
|
amount: depositAmount.toString()
|
|
@@ -14527,6 +14529,63 @@ var Order = class {
|
|
|
14527
14529
|
};
|
|
14528
14530
|
});
|
|
14529
14531
|
this.logger.info("closeAllPositions params--->", depositData, positionIds, dataMap);
|
|
14532
|
+
const authorized = this.configManager.getConfig().seamlessAccount?.authorized;
|
|
14533
|
+
const seamlessWallet = this.configManager.getConfig().seamlessAccount?.wallet;
|
|
14534
|
+
if (config.seamlessMode && authorized && seamlessWallet) {
|
|
14535
|
+
if (needsApproval) {
|
|
14536
|
+
const approvalResult = await this.utils.approveAuthorization({
|
|
14537
|
+
chainId,
|
|
14538
|
+
quoteAddress: params[0].executionFeeToken,
|
|
14539
|
+
amount: ethers6.MaxUint256.toString(),
|
|
14540
|
+
signer: seamlessWallet
|
|
14541
|
+
});
|
|
14542
|
+
if (approvalResult.code !== 0) {
|
|
14543
|
+
throw new Error(approvalResult.message);
|
|
14544
|
+
}
|
|
14545
|
+
}
|
|
14546
|
+
const isEnoughGas = await this.utils.checkSeamlessGas(params[0].address);
|
|
14547
|
+
if (!isEnoughGas) {
|
|
14548
|
+
throw new MyxSDKError("INSUFFICIENT_BALANCE" /* InsufficientBalance */, "Insufficient relay fee");
|
|
14549
|
+
}
|
|
14550
|
+
const forwarderContract = await getForwarderContract(chainId);
|
|
14551
|
+
const brokerContract2 = await getSeamlessBrokerContract(
|
|
14552
|
+
this.configManager.getConfig().brokerAddress,
|
|
14553
|
+
seamlessWallet
|
|
14554
|
+
);
|
|
14555
|
+
const functionHash = brokerContract2.interface.encodeFunctionData("placeOrdersWithPosition", [depositData, positionIds, dataMap]);
|
|
14556
|
+
const nonce = await forwarderContract.nonces(seamlessWallet.address);
|
|
14557
|
+
const forwardTxParams = {
|
|
14558
|
+
from: seamlessWallet.address ?? "",
|
|
14559
|
+
to: this.configManager.getConfig().brokerAddress,
|
|
14560
|
+
value: "0",
|
|
14561
|
+
gas: "350000",
|
|
14562
|
+
deadline: dayjs().add(60, "minute").unix(),
|
|
14563
|
+
data: functionHash,
|
|
14564
|
+
nonce: nonce.toString()
|
|
14565
|
+
};
|
|
14566
|
+
this.logger.info("cancel all positions forward tx params --->", forwardTxParams);
|
|
14567
|
+
const rs = await this.seamless.forwarderTx(forwardTxParams, seamlessWallet);
|
|
14568
|
+
console.log("rs-->", rs);
|
|
14569
|
+
return {
|
|
14570
|
+
code: 0,
|
|
14571
|
+
message: "cancel all positions success",
|
|
14572
|
+
data: rs
|
|
14573
|
+
};
|
|
14574
|
+
}
|
|
14575
|
+
const brokerContract = await getBrokerSingerContract(
|
|
14576
|
+
chainId,
|
|
14577
|
+
this.configManager.getConfig().brokerAddress
|
|
14578
|
+
);
|
|
14579
|
+
if (needsApproval) {
|
|
14580
|
+
const approvalResult = await this.utils.approveAuthorization({
|
|
14581
|
+
chainId,
|
|
14582
|
+
quoteAddress: params[0].executionFeeToken,
|
|
14583
|
+
amount: ethers6.MaxUint256.toString()
|
|
14584
|
+
});
|
|
14585
|
+
if (approvalResult.code !== 0) {
|
|
14586
|
+
throw new Error(approvalResult.message);
|
|
14587
|
+
}
|
|
14588
|
+
}
|
|
14530
14589
|
const gasLimit = await brokerContract.placeOrdersWithPosition.estimateGas(depositData, positionIds, dataMap);
|
|
14531
14590
|
const transaction = await brokerContract.placeOrdersWithPosition(depositData, positionIds, dataMap, {
|
|
14532
14591
|
gasLimit: gasLimit * 120n / 100n
|
|
@@ -14560,9 +14619,6 @@ var Order = class {
|
|
|
14560
14619
|
async createDecreaseOrder(params) {
|
|
14561
14620
|
try {
|
|
14562
14621
|
const config = this.configManager.getConfig();
|
|
14563
|
-
if (!config.signer) {
|
|
14564
|
-
throw new MyxSDKError("INVALID_SIGNER" /* InvalidSigner */, "Invalid signer");
|
|
14565
|
-
}
|
|
14566
14622
|
const brokerContract = await getBrokerSingerContract(
|
|
14567
14623
|
params.chainId,
|
|
14568
14624
|
this.configManager.getConfig().brokerAddress
|
|
@@ -14600,6 +14656,65 @@ var Order = class {
|
|
|
14600
14656
|
params.executionFeeToken,
|
|
14601
14657
|
networkFee.toString()
|
|
14602
14658
|
);
|
|
14659
|
+
const authorized = this.configManager.getConfig().seamlessAccount?.authorized;
|
|
14660
|
+
const seamlessWallet = this.configManager.getConfig().seamlessAccount?.wallet;
|
|
14661
|
+
if (config.seamlessMode && authorized && seamlessWallet) {
|
|
14662
|
+
if (needsApproval) {
|
|
14663
|
+
const approvalResult = await this.utils.approveAuthorization({
|
|
14664
|
+
chainId: params.chainId,
|
|
14665
|
+
quoteAddress: params.executionFeeToken,
|
|
14666
|
+
amount: ethers6.MaxUint256.toString(),
|
|
14667
|
+
signer: seamlessWallet
|
|
14668
|
+
});
|
|
14669
|
+
if (approvalResult.code !== 0) {
|
|
14670
|
+
throw new Error(approvalResult.message);
|
|
14671
|
+
}
|
|
14672
|
+
}
|
|
14673
|
+
const isEnoughGas = await this.utils.checkSeamlessGas(params.address);
|
|
14674
|
+
if (!isEnoughGas) {
|
|
14675
|
+
throw new MyxSDKError("INSUFFICIENT_BALANCE" /* InsufficientBalance */, "Insufficient relay fee");
|
|
14676
|
+
}
|
|
14677
|
+
const forwarderContract = await getForwarderContract(params.chainId);
|
|
14678
|
+
const brokerContract2 = await getSeamlessBrokerContract(
|
|
14679
|
+
this.configManager.getConfig().brokerAddress,
|
|
14680
|
+
seamlessWallet
|
|
14681
|
+
);
|
|
14682
|
+
let functionHash = "";
|
|
14683
|
+
if (!params.positionId) {
|
|
14684
|
+
functionHash = brokerContract2.interface.encodeFunctionData("placeOrderWithSalt", [
|
|
14685
|
+
"1",
|
|
14686
|
+
{ ...depositData },
|
|
14687
|
+
data
|
|
14688
|
+
]);
|
|
14689
|
+
} else {
|
|
14690
|
+
functionHash = brokerContract2.interface.encodeFunctionData("placeOrderWithPosition", [
|
|
14691
|
+
params.positionId.toString(),
|
|
14692
|
+
{ ...depositData },
|
|
14693
|
+
data
|
|
14694
|
+
]);
|
|
14695
|
+
}
|
|
14696
|
+
const nonce = await forwarderContract.nonces(seamlessWallet.address);
|
|
14697
|
+
const forwardTxParams = {
|
|
14698
|
+
from: seamlessWallet.address ?? "",
|
|
14699
|
+
to: this.configManager.getConfig().brokerAddress,
|
|
14700
|
+
value: "0",
|
|
14701
|
+
gas: "350000",
|
|
14702
|
+
deadline: dayjs().add(60, "minute").unix(),
|
|
14703
|
+
data: functionHash,
|
|
14704
|
+
nonce: nonce.toString()
|
|
14705
|
+
};
|
|
14706
|
+
this.logger.info("create decrease order forward tx params --->", forwardTxParams);
|
|
14707
|
+
const rs = await this.seamless.forwarderTx(forwardTxParams, seamlessWallet);
|
|
14708
|
+
console.log("rs-->", rs);
|
|
14709
|
+
return {
|
|
14710
|
+
code: 0,
|
|
14711
|
+
message: "create decrease order success",
|
|
14712
|
+
data: rs
|
|
14713
|
+
};
|
|
14714
|
+
}
|
|
14715
|
+
if (!config.signer) {
|
|
14716
|
+
throw new MyxSDKError("INVALID_SIGNER" /* InvalidSigner */, "Invalid signer");
|
|
14717
|
+
}
|
|
14603
14718
|
if (needsApproval) {
|
|
14604
14719
|
const approvalResult = await this.utils.approveAuthorization({
|
|
14605
14720
|
chainId: params.chainId,
|
|
@@ -14676,7 +14791,7 @@ var Order = class {
|
|
|
14676
14791
|
async createPositionTpSlOrder(params) {
|
|
14677
14792
|
try {
|
|
14678
14793
|
const config = this.configManager.getConfig();
|
|
14679
|
-
if (!config.signer) {
|
|
14794
|
+
if (!config.signer && !config.seamlessMode) {
|
|
14680
14795
|
throw new MyxSDKError("INVALID_SIGNER" /* InvalidSigner */, "Invalid signer");
|
|
14681
14796
|
}
|
|
14682
14797
|
const brokerContract = await getBrokerSingerContract(
|
|
@@ -14737,6 +14852,62 @@ var Order = class {
|
|
|
14737
14852
|
params.executionFeeToken,
|
|
14738
14853
|
depositAmount.toString()
|
|
14739
14854
|
);
|
|
14855
|
+
const authorized2 = this.configManager.getConfig().seamlessAccount?.authorized;
|
|
14856
|
+
const seamlessWallet2 = this.configManager.getConfig().seamlessAccount?.wallet;
|
|
14857
|
+
if (config.seamlessMode && authorized2 && seamlessWallet2) {
|
|
14858
|
+
if (needsApproval2) {
|
|
14859
|
+
const approvalResult = await this.utils.approveAuthorization({
|
|
14860
|
+
chainId: params.chainId,
|
|
14861
|
+
quoteAddress: params.executionFeeToken,
|
|
14862
|
+
amount: ethers6.MaxUint256.toString(),
|
|
14863
|
+
signer: seamlessWallet2
|
|
14864
|
+
});
|
|
14865
|
+
if (approvalResult.code !== 0) {
|
|
14866
|
+
throw new Error(approvalResult.message);
|
|
14867
|
+
}
|
|
14868
|
+
}
|
|
14869
|
+
const isEnoughGas = await this.utils.checkSeamlessGas(params.address);
|
|
14870
|
+
if (!isEnoughGas) {
|
|
14871
|
+
throw new MyxSDKError("INSUFFICIENT_BALANCE" /* InsufficientBalance */, "Insufficient relay fee");
|
|
14872
|
+
}
|
|
14873
|
+
const forwarderContract = await getForwarderContract(params.chainId);
|
|
14874
|
+
const brokerContract2 = await getSeamlessBrokerContract(
|
|
14875
|
+
this.configManager.getConfig().brokerAddress,
|
|
14876
|
+
seamlessWallet2
|
|
14877
|
+
);
|
|
14878
|
+
let functionHash = "";
|
|
14879
|
+
if (!params.positionId) {
|
|
14880
|
+
functionHash = brokerContract2.interface.encodeFunctionData("placeOrdersWithSalt", [
|
|
14881
|
+
{ token: params.executionFeeToken, amount: depositAmount.toString() },
|
|
14882
|
+
["1", "1"],
|
|
14883
|
+
data2
|
|
14884
|
+
]);
|
|
14885
|
+
} else {
|
|
14886
|
+
functionHash = brokerContract2.interface.encodeFunctionData("placeOrdersWithPosition", [
|
|
14887
|
+
{ token: params.executionFeeToken, amount: depositAmount.toString() },
|
|
14888
|
+
[params.positionId.toString(), params.positionId.toString()],
|
|
14889
|
+
data2
|
|
14890
|
+
]);
|
|
14891
|
+
}
|
|
14892
|
+
const nonce = await forwarderContract.nonces(seamlessWallet2.address);
|
|
14893
|
+
const forwardTxParams = {
|
|
14894
|
+
from: seamlessWallet2.address ?? "",
|
|
14895
|
+
to: this.configManager.getConfig().brokerAddress,
|
|
14896
|
+
value: "0",
|
|
14897
|
+
gas: "350000",
|
|
14898
|
+
deadline: dayjs().add(60, "minute").unix(),
|
|
14899
|
+
data: functionHash,
|
|
14900
|
+
nonce: nonce.toString()
|
|
14901
|
+
};
|
|
14902
|
+
this.logger.info("createPositionTpSlOrder forward tx params --->", forwardTxParams);
|
|
14903
|
+
const rs = await this.seamless.forwarderTx(forwardTxParams, seamlessWallet2);
|
|
14904
|
+
console.log("rs-->", rs);
|
|
14905
|
+
return {
|
|
14906
|
+
code: 0,
|
|
14907
|
+
message: "createPositionTpSlOrder success",
|
|
14908
|
+
data: rs
|
|
14909
|
+
};
|
|
14910
|
+
}
|
|
14740
14911
|
if (needsApproval2) {
|
|
14741
14912
|
const approvalResult = await this.utils.approveAuthorization({
|
|
14742
14913
|
chainId: params.chainId,
|
|
@@ -14820,6 +14991,62 @@ var Order = class {
|
|
|
14820
14991
|
params.executionFeeToken,
|
|
14821
14992
|
networkFee.toString()
|
|
14822
14993
|
);
|
|
14994
|
+
const authorized = this.configManager.getConfig().seamlessAccount?.authorized;
|
|
14995
|
+
const seamlessWallet = this.configManager.getConfig().seamlessAccount?.wallet;
|
|
14996
|
+
if (config.seamlessMode && authorized && seamlessWallet) {
|
|
14997
|
+
if (needsApproval) {
|
|
14998
|
+
const approvalResult = await this.utils.approveAuthorization({
|
|
14999
|
+
chainId: params.chainId,
|
|
15000
|
+
quoteAddress: params.executionFeeToken,
|
|
15001
|
+
amount: ethers6.MaxUint256.toString(),
|
|
15002
|
+
signer: seamlessWallet
|
|
15003
|
+
});
|
|
15004
|
+
if (approvalResult.code !== 0) {
|
|
15005
|
+
throw new Error(approvalResult.message);
|
|
15006
|
+
}
|
|
15007
|
+
}
|
|
15008
|
+
const isEnoughGas = await this.utils.checkSeamlessGas(params.address);
|
|
15009
|
+
if (!isEnoughGas) {
|
|
15010
|
+
throw new MyxSDKError("INSUFFICIENT_BALANCE" /* InsufficientBalance */, "Insufficient relay fee");
|
|
15011
|
+
}
|
|
15012
|
+
const forwarderContract = await getForwarderContract(params.chainId);
|
|
15013
|
+
const brokerContract2 = await getSeamlessBrokerContract(
|
|
15014
|
+
this.configManager.getConfig().brokerAddress,
|
|
15015
|
+
seamlessWallet
|
|
15016
|
+
);
|
|
15017
|
+
let functionHash = "";
|
|
15018
|
+
if (!params.positionId) {
|
|
15019
|
+
functionHash = brokerContract2.interface.encodeFunctionData("placeOrderWithSalt", [
|
|
15020
|
+
"1",
|
|
15021
|
+
depositData,
|
|
15022
|
+
data
|
|
15023
|
+
]);
|
|
15024
|
+
} else {
|
|
15025
|
+
functionHash = brokerContract2.interface.encodeFunctionData("placeOrderWithPosition", [
|
|
15026
|
+
params.positionId.toString(),
|
|
15027
|
+
depositData,
|
|
15028
|
+
data
|
|
15029
|
+
]);
|
|
15030
|
+
}
|
|
15031
|
+
const nonce = await forwarderContract.nonces(seamlessWallet.address);
|
|
15032
|
+
const forwardTxParams = {
|
|
15033
|
+
from: seamlessWallet.address ?? "",
|
|
15034
|
+
to: this.configManager.getConfig().brokerAddress,
|
|
15035
|
+
value: "0",
|
|
15036
|
+
gas: "350000",
|
|
15037
|
+
deadline: dayjs().add(60, "minute").unix(),
|
|
15038
|
+
data: functionHash,
|
|
15039
|
+
nonce: nonce.toString()
|
|
15040
|
+
};
|
|
15041
|
+
this.logger.info("createPositionTpSlOrder forward tx params --->", forwardTxParams);
|
|
15042
|
+
const rs = await this.seamless.forwarderTx(forwardTxParams, seamlessWallet);
|
|
15043
|
+
console.log("rs-->", rs);
|
|
15044
|
+
return {
|
|
15045
|
+
code: 0,
|
|
15046
|
+
message: "createPositionTpSlOrder success",
|
|
15047
|
+
data: rs
|
|
15048
|
+
};
|
|
15049
|
+
}
|
|
14823
15050
|
if (needsApproval) {
|
|
14824
15051
|
const approvalResult = await this.utils.approveAuthorization({
|
|
14825
15052
|
chainId: params.chainId,
|
|
@@ -14892,6 +15119,38 @@ var Order = class {
|
|
|
14892
15119
|
async cancelAllOrders(orderIds, chainId) {
|
|
14893
15120
|
try {
|
|
14894
15121
|
const config = this.configManager.getConfig();
|
|
15122
|
+
const authorized = this.configManager.getConfig().seamlessAccount?.authorized;
|
|
15123
|
+
const seamlessWallet = this.configManager.getConfig().seamlessAccount?.wallet;
|
|
15124
|
+
if (config.seamlessMode && authorized && seamlessWallet) {
|
|
15125
|
+
const isEnoughGas = await this.utils.checkSeamlessGas(config.seamlessAccount?.masterAddress);
|
|
15126
|
+
if (!isEnoughGas) {
|
|
15127
|
+
throw new MyxSDKError("INSUFFICIENT_BALANCE" /* InsufficientBalance */, "Insufficient relay fee");
|
|
15128
|
+
}
|
|
15129
|
+
const forwarderContract = await getForwarderContract(chainId);
|
|
15130
|
+
const brokerContract2 = await getSeamlessBrokerContract(
|
|
15131
|
+
this.configManager.getConfig().brokerAddress,
|
|
15132
|
+
seamlessWallet
|
|
15133
|
+
);
|
|
15134
|
+
let functionHash = brokerContract2.interface.encodeFunctionData("cancelOrders", [orderIds]);
|
|
15135
|
+
const nonce = await forwarderContract.nonces(seamlessWallet.address);
|
|
15136
|
+
const forwardTxParams = {
|
|
15137
|
+
from: seamlessWallet.address ?? "",
|
|
15138
|
+
to: this.configManager.getConfig().brokerAddress,
|
|
15139
|
+
value: "0",
|
|
15140
|
+
gas: "350000",
|
|
15141
|
+
deadline: dayjs().add(60, "minute").unix(),
|
|
15142
|
+
data: functionHash,
|
|
15143
|
+
nonce: nonce.toString()
|
|
15144
|
+
};
|
|
15145
|
+
this.logger.info("create decrease order forward tx params --->", forwardTxParams);
|
|
15146
|
+
const rs = await this.seamless.forwarderTx(forwardTxParams, seamlessWallet);
|
|
15147
|
+
console.log("rs-->", rs);
|
|
15148
|
+
return {
|
|
15149
|
+
code: 0,
|
|
15150
|
+
message: "create decrease order success",
|
|
15151
|
+
data: rs
|
|
15152
|
+
};
|
|
15153
|
+
}
|
|
14895
15154
|
if (!config.signer) {
|
|
14896
15155
|
throw new MyxSDKError("INVALID_SIGNER" /* InvalidSigner */, "Invalid signer");
|
|
14897
15156
|
}
|
|
@@ -19783,7 +20042,8 @@ var Utils = class {
|
|
|
19783
20042
|
chainId,
|
|
19784
20043
|
quoteAddress,
|
|
19785
20044
|
amount,
|
|
19786
|
-
spenderAddress
|
|
20045
|
+
spenderAddress,
|
|
20046
|
+
signer
|
|
19787
20047
|
}) {
|
|
19788
20048
|
try {
|
|
19789
20049
|
const erc20Abi = [
|
|
@@ -19793,7 +20053,7 @@ var Utils = class {
|
|
|
19793
20053
|
const usdcContract = new ethers7.Contract(
|
|
19794
20054
|
quoteAddress,
|
|
19795
20055
|
erc20Abi,
|
|
19796
|
-
config.signer
|
|
20056
|
+
signer ?? config.signer
|
|
19797
20057
|
);
|
|
19798
20058
|
const approveAmount = amount ?? ethers7.MaxUint256;
|
|
19799
20059
|
const spender = spenderAddress ?? getContractAddressByChainId(chainId).Account;
|
|
@@ -21273,14 +21533,11 @@ var Seamless = class {
|
|
|
21273
21533
|
};
|
|
21274
21534
|
}
|
|
21275
21535
|
async startSeamlessMode({ open }) {
|
|
21276
|
-
this.logger.info("startSeamlessMode-->", open);
|
|
21277
21536
|
const config = this.configManager.startSeamlessMode(open);
|
|
21278
|
-
this.logger.info("startSeamlessMode config-->", config);
|
|
21279
21537
|
return {
|
|
21280
21538
|
code: 0,
|
|
21281
21539
|
data: {
|
|
21282
|
-
open
|
|
21283
|
-
config
|
|
21540
|
+
open
|
|
21284
21541
|
}
|
|
21285
21542
|
};
|
|
21286
21543
|
}
|