@myx-trade/sdk 0.1.51 → 0.1.53
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 +58 -57
- package/dist/index.d.ts +58 -57
- package/dist/index.js +47 -101
- package/dist/index.mjs +47 -101
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1422,11 +1422,68 @@ interface UpdateOrderParams {
|
|
|
1422
1422
|
price: string;
|
|
1423
1423
|
}
|
|
1424
1424
|
|
|
1425
|
-
declare class
|
|
1425
|
+
declare class Account {
|
|
1426
1426
|
private configManager;
|
|
1427
1427
|
private logger;
|
|
1428
1428
|
private utils;
|
|
1429
1429
|
constructor(configManager: ConfigManager, logger: Logger, utils: Utils);
|
|
1430
|
+
getWalletQuoteTokenBalance(): Promise<{
|
|
1431
|
+
code: number;
|
|
1432
|
+
data: any;
|
|
1433
|
+
}>;
|
|
1434
|
+
/**
|
|
1435
|
+
* get tradable amount
|
|
1436
|
+
*/
|
|
1437
|
+
getTradableAmount({ poolId }: {
|
|
1438
|
+
poolId: string;
|
|
1439
|
+
}): Promise<{
|
|
1440
|
+
code: number;
|
|
1441
|
+
data: {
|
|
1442
|
+
profitIsReleased: any;
|
|
1443
|
+
freeAmount: any;
|
|
1444
|
+
tradeableProfit: any;
|
|
1445
|
+
};
|
|
1446
|
+
} | {
|
|
1447
|
+
code: number;
|
|
1448
|
+
data?: undefined;
|
|
1449
|
+
}>;
|
|
1450
|
+
getTradeFlow(params: GetHistoryOrdersParams): Promise<{
|
|
1451
|
+
code: number;
|
|
1452
|
+
data: TradeFlowItem[];
|
|
1453
|
+
}>;
|
|
1454
|
+
withdraw({ poolId, amount }: {
|
|
1455
|
+
poolId: string;
|
|
1456
|
+
amount: string;
|
|
1457
|
+
}): Promise<{
|
|
1458
|
+
code: number;
|
|
1459
|
+
data: any;
|
|
1460
|
+
message?: undefined;
|
|
1461
|
+
} | {
|
|
1462
|
+
code: number;
|
|
1463
|
+
message: string;
|
|
1464
|
+
data?: undefined;
|
|
1465
|
+
}>;
|
|
1466
|
+
deposit({ poolId, amount, tokenAddress }: {
|
|
1467
|
+
poolId: string;
|
|
1468
|
+
amount: string;
|
|
1469
|
+
tokenAddress: string;
|
|
1470
|
+
}): Promise<{
|
|
1471
|
+
code: number;
|
|
1472
|
+
data: any;
|
|
1473
|
+
message?: undefined;
|
|
1474
|
+
} | {
|
|
1475
|
+
code: number;
|
|
1476
|
+
message: string;
|
|
1477
|
+
data?: undefined;
|
|
1478
|
+
}>;
|
|
1479
|
+
}
|
|
1480
|
+
|
|
1481
|
+
declare class Order {
|
|
1482
|
+
private configManager;
|
|
1483
|
+
private logger;
|
|
1484
|
+
private utils;
|
|
1485
|
+
private account;
|
|
1486
|
+
constructor(configManager: ConfigManager, logger: Logger, utils: Utils, account: Account);
|
|
1430
1487
|
createPositionId(poolId: string, user: Address$2, direction: Direction, salt: bigint): Promise<string>;
|
|
1431
1488
|
createIncreaseOrder(params: PlaceOrderParams): Promise<{
|
|
1432
1489
|
code: number;
|
|
@@ -1517,62 +1574,6 @@ declare class Order {
|
|
|
1517
1574
|
}>;
|
|
1518
1575
|
}
|
|
1519
1576
|
|
|
1520
|
-
declare class Account {
|
|
1521
|
-
private configManager;
|
|
1522
|
-
private logger;
|
|
1523
|
-
private utils;
|
|
1524
|
-
constructor(configManager: ConfigManager, logger: Logger, utils: Utils);
|
|
1525
|
-
getWalletQuoteTokenBalance(): Promise<{
|
|
1526
|
-
code: number;
|
|
1527
|
-
data: any;
|
|
1528
|
-
}>;
|
|
1529
|
-
/**
|
|
1530
|
-
* get tradable amount
|
|
1531
|
-
*/
|
|
1532
|
-
getTradableAmount({ poolId }: {
|
|
1533
|
-
poolId: string;
|
|
1534
|
-
}): Promise<{
|
|
1535
|
-
code: number;
|
|
1536
|
-
data: {
|
|
1537
|
-
profitIsReleased: any;
|
|
1538
|
-
freeAmount: any;
|
|
1539
|
-
tradeableProfit: any;
|
|
1540
|
-
};
|
|
1541
|
-
} | {
|
|
1542
|
-
code: number;
|
|
1543
|
-
data?: undefined;
|
|
1544
|
-
}>;
|
|
1545
|
-
getTradeFlow(params: GetHistoryOrdersParams): Promise<{
|
|
1546
|
-
code: number;
|
|
1547
|
-
data: TradeFlowItem[];
|
|
1548
|
-
}>;
|
|
1549
|
-
withdraw({ poolId, amount }: {
|
|
1550
|
-
poolId: string;
|
|
1551
|
-
amount: string;
|
|
1552
|
-
}): Promise<{
|
|
1553
|
-
code: number;
|
|
1554
|
-
data: any;
|
|
1555
|
-
message?: undefined;
|
|
1556
|
-
} | {
|
|
1557
|
-
code: number;
|
|
1558
|
-
message: string;
|
|
1559
|
-
data?: undefined;
|
|
1560
|
-
}>;
|
|
1561
|
-
deposit({ poolId, amount, tokenAddress }: {
|
|
1562
|
-
poolId: string;
|
|
1563
|
-
amount: string;
|
|
1564
|
-
tokenAddress: string;
|
|
1565
|
-
}): Promise<{
|
|
1566
|
-
code: number;
|
|
1567
|
-
data: any;
|
|
1568
|
-
message?: undefined;
|
|
1569
|
-
} | {
|
|
1570
|
-
code: number;
|
|
1571
|
-
message: string;
|
|
1572
|
-
data?: undefined;
|
|
1573
|
-
}>;
|
|
1574
|
-
}
|
|
1575
|
-
|
|
1576
1577
|
declare class MyxClient {
|
|
1577
1578
|
/**
|
|
1578
1579
|
* private properties
|
package/dist/index.d.ts
CHANGED
|
@@ -1422,11 +1422,68 @@ interface UpdateOrderParams {
|
|
|
1422
1422
|
price: string;
|
|
1423
1423
|
}
|
|
1424
1424
|
|
|
1425
|
-
declare class
|
|
1425
|
+
declare class Account {
|
|
1426
1426
|
private configManager;
|
|
1427
1427
|
private logger;
|
|
1428
1428
|
private utils;
|
|
1429
1429
|
constructor(configManager: ConfigManager, logger: Logger, utils: Utils);
|
|
1430
|
+
getWalletQuoteTokenBalance(): Promise<{
|
|
1431
|
+
code: number;
|
|
1432
|
+
data: any;
|
|
1433
|
+
}>;
|
|
1434
|
+
/**
|
|
1435
|
+
* get tradable amount
|
|
1436
|
+
*/
|
|
1437
|
+
getTradableAmount({ poolId }: {
|
|
1438
|
+
poolId: string;
|
|
1439
|
+
}): Promise<{
|
|
1440
|
+
code: number;
|
|
1441
|
+
data: {
|
|
1442
|
+
profitIsReleased: any;
|
|
1443
|
+
freeAmount: any;
|
|
1444
|
+
tradeableProfit: any;
|
|
1445
|
+
};
|
|
1446
|
+
} | {
|
|
1447
|
+
code: number;
|
|
1448
|
+
data?: undefined;
|
|
1449
|
+
}>;
|
|
1450
|
+
getTradeFlow(params: GetHistoryOrdersParams): Promise<{
|
|
1451
|
+
code: number;
|
|
1452
|
+
data: TradeFlowItem[];
|
|
1453
|
+
}>;
|
|
1454
|
+
withdraw({ poolId, amount }: {
|
|
1455
|
+
poolId: string;
|
|
1456
|
+
amount: string;
|
|
1457
|
+
}): Promise<{
|
|
1458
|
+
code: number;
|
|
1459
|
+
data: any;
|
|
1460
|
+
message?: undefined;
|
|
1461
|
+
} | {
|
|
1462
|
+
code: number;
|
|
1463
|
+
message: string;
|
|
1464
|
+
data?: undefined;
|
|
1465
|
+
}>;
|
|
1466
|
+
deposit({ poolId, amount, tokenAddress }: {
|
|
1467
|
+
poolId: string;
|
|
1468
|
+
amount: string;
|
|
1469
|
+
tokenAddress: string;
|
|
1470
|
+
}): Promise<{
|
|
1471
|
+
code: number;
|
|
1472
|
+
data: any;
|
|
1473
|
+
message?: undefined;
|
|
1474
|
+
} | {
|
|
1475
|
+
code: number;
|
|
1476
|
+
message: string;
|
|
1477
|
+
data?: undefined;
|
|
1478
|
+
}>;
|
|
1479
|
+
}
|
|
1480
|
+
|
|
1481
|
+
declare class Order {
|
|
1482
|
+
private configManager;
|
|
1483
|
+
private logger;
|
|
1484
|
+
private utils;
|
|
1485
|
+
private account;
|
|
1486
|
+
constructor(configManager: ConfigManager, logger: Logger, utils: Utils, account: Account);
|
|
1430
1487
|
createPositionId(poolId: string, user: Address$2, direction: Direction, salt: bigint): Promise<string>;
|
|
1431
1488
|
createIncreaseOrder(params: PlaceOrderParams): Promise<{
|
|
1432
1489
|
code: number;
|
|
@@ -1517,62 +1574,6 @@ declare class Order {
|
|
|
1517
1574
|
}>;
|
|
1518
1575
|
}
|
|
1519
1576
|
|
|
1520
|
-
declare class Account {
|
|
1521
|
-
private configManager;
|
|
1522
|
-
private logger;
|
|
1523
|
-
private utils;
|
|
1524
|
-
constructor(configManager: ConfigManager, logger: Logger, utils: Utils);
|
|
1525
|
-
getWalletQuoteTokenBalance(): Promise<{
|
|
1526
|
-
code: number;
|
|
1527
|
-
data: any;
|
|
1528
|
-
}>;
|
|
1529
|
-
/**
|
|
1530
|
-
* get tradable amount
|
|
1531
|
-
*/
|
|
1532
|
-
getTradableAmount({ poolId }: {
|
|
1533
|
-
poolId: string;
|
|
1534
|
-
}): Promise<{
|
|
1535
|
-
code: number;
|
|
1536
|
-
data: {
|
|
1537
|
-
profitIsReleased: any;
|
|
1538
|
-
freeAmount: any;
|
|
1539
|
-
tradeableProfit: any;
|
|
1540
|
-
};
|
|
1541
|
-
} | {
|
|
1542
|
-
code: number;
|
|
1543
|
-
data?: undefined;
|
|
1544
|
-
}>;
|
|
1545
|
-
getTradeFlow(params: GetHistoryOrdersParams): Promise<{
|
|
1546
|
-
code: number;
|
|
1547
|
-
data: TradeFlowItem[];
|
|
1548
|
-
}>;
|
|
1549
|
-
withdraw({ poolId, amount }: {
|
|
1550
|
-
poolId: string;
|
|
1551
|
-
amount: string;
|
|
1552
|
-
}): Promise<{
|
|
1553
|
-
code: number;
|
|
1554
|
-
data: any;
|
|
1555
|
-
message?: undefined;
|
|
1556
|
-
} | {
|
|
1557
|
-
code: number;
|
|
1558
|
-
message: string;
|
|
1559
|
-
data?: undefined;
|
|
1560
|
-
}>;
|
|
1561
|
-
deposit({ poolId, amount, tokenAddress }: {
|
|
1562
|
-
poolId: string;
|
|
1563
|
-
amount: string;
|
|
1564
|
-
tokenAddress: string;
|
|
1565
|
-
}): Promise<{
|
|
1566
|
-
code: number;
|
|
1567
|
-
data: any;
|
|
1568
|
-
message?: undefined;
|
|
1569
|
-
} | {
|
|
1570
|
-
code: number;
|
|
1571
|
-
message: string;
|
|
1572
|
-
data?: undefined;
|
|
1573
|
-
}>;
|
|
1574
|
-
}
|
|
1575
|
-
|
|
1576
1577
|
declare class MyxClient {
|
|
1577
1578
|
/**
|
|
1578
1579
|
* private properties
|
package/dist/index.js
CHANGED
|
@@ -1836,7 +1836,7 @@ var RotationProvider = class extends import_providers.BaseProvider {
|
|
|
1836
1836
|
// package.json
|
|
1837
1837
|
var package_default = {
|
|
1838
1838
|
name: "@myx-trade/sdk",
|
|
1839
|
-
version: "0.1.
|
|
1839
|
+
version: "0.1.53",
|
|
1840
1840
|
private: false,
|
|
1841
1841
|
publishConfig: {
|
|
1842
1842
|
access: "public"
|
|
@@ -13023,10 +13023,11 @@ var OrderStatus = {
|
|
|
13023
13023
|
var import_ethers24 = require("ethers");
|
|
13024
13024
|
var import_viem = require("viem");
|
|
13025
13025
|
var Order = class {
|
|
13026
|
-
constructor(configManager, logger, utils) {
|
|
13026
|
+
constructor(configManager, logger, utils, account) {
|
|
13027
13027
|
this.configManager = configManager;
|
|
13028
13028
|
this.logger = logger;
|
|
13029
13029
|
this.utils = utils;
|
|
13030
|
+
this.account = account;
|
|
13030
13031
|
}
|
|
13031
13032
|
async createPositionId(poolId, user, direction, salt) {
|
|
13032
13033
|
const encoded = (0, import_viem.encodeAbiParameters)((0, import_viem.parseAbiParameters)("bytes32 poolId, address user, uint8 direction, uint64 salt"), [
|
|
@@ -13063,6 +13064,26 @@ var Order = class {
|
|
|
13063
13064
|
throw new Error(approvalResult.message);
|
|
13064
13065
|
}
|
|
13065
13066
|
}
|
|
13067
|
+
const marginAccountBalanceRes = await this.account.getTradableAmount({ poolId: params.poolId });
|
|
13068
|
+
const walletBalanceRes = await this.account.getWalletQuoteTokenBalance();
|
|
13069
|
+
console.log("marginAccountBalance--->", marginAccountBalanceRes);
|
|
13070
|
+
console.log("createIncreaseOrder walletBalance--->", walletBalanceRes);
|
|
13071
|
+
const marginAccountBalance = marginAccountBalanceRes?.data;
|
|
13072
|
+
const walletBalance = walletBalanceRes?.data;
|
|
13073
|
+
if (marginAccountBalanceRes.code !== 0 || walletBalanceRes.code !== 0) {
|
|
13074
|
+
return {
|
|
13075
|
+
code: -1,
|
|
13076
|
+
message: "Failed to get tradable amount or wallet balance"
|
|
13077
|
+
};
|
|
13078
|
+
}
|
|
13079
|
+
let useAccountBalance = false;
|
|
13080
|
+
const totalBalance = BigInt(marginAccountBalance?.freeAmount.toString() ?? 0) + BigInt(marginAccountBalance?.tradeableProfit.toString() ?? 0);
|
|
13081
|
+
let transferAmount = 0n;
|
|
13082
|
+
if (totalBalance > 0) {
|
|
13083
|
+
useAccountBalance = true;
|
|
13084
|
+
transferAmount = collateralWithNetworkFee - totalBalance;
|
|
13085
|
+
}
|
|
13086
|
+
console.log("transferAmount-->", transferAmount);
|
|
13066
13087
|
const data = {
|
|
13067
13088
|
user: params.address,
|
|
13068
13089
|
poolId: params.poolId,
|
|
@@ -13070,125 +13091,50 @@ var Order = class {
|
|
|
13070
13091
|
triggerType: params.triggerType,
|
|
13071
13092
|
operation: OperationType.INCREASE,
|
|
13072
13093
|
direction: params.direction,
|
|
13073
|
-
collateralAmount: collateralWithNetworkFee,
|
|
13094
|
+
collateralAmount: collateralWithNetworkFee.toString(),
|
|
13074
13095
|
size: params.size,
|
|
13075
13096
|
price: params.price,
|
|
13076
13097
|
timeInForce: TIME_IN_FORCE,
|
|
13077
|
-
postOnly: params.postOnly,
|
|
13078
|
-
slippagePct: params.slippagePct,
|
|
13098
|
+
postOnly: params.postOnly ?? false,
|
|
13099
|
+
slippagePct: params.slippagePct ?? "0",
|
|
13079
13100
|
executionFeeToken: params.executionFeeToken,
|
|
13080
|
-
leverage: params.leverage,
|
|
13081
|
-
tpSize: params.tpSize
|
|
13082
|
-
tpPrice: params.tpPrice
|
|
13083
|
-
slSize: params.slSize
|
|
13084
|
-
slPrice: params.slPrice
|
|
13085
|
-
useAccountBalance
|
|
13101
|
+
leverage: params.leverage ?? 0,
|
|
13102
|
+
tpSize: params.tpSize ?? "0",
|
|
13103
|
+
tpPrice: params.tpPrice ?? "0",
|
|
13104
|
+
slSize: params.slSize ?? "0",
|
|
13105
|
+
slPrice: params.slPrice ?? "0",
|
|
13106
|
+
useAccountBalance
|
|
13086
13107
|
};
|
|
13087
|
-
this.logger.info("positionId", params.positionId);
|
|
13088
13108
|
let transaction;
|
|
13089
13109
|
if (!params.positionId) {
|
|
13090
|
-
const
|
|
13091
|
-
this.logger.info("createIncreaseOrder salt position params--->", { ...data,
|
|
13092
|
-
const gasLimit = await brokerContract.placeOrderWithSalt.estimateGas(
|
|
13093
|
-
user: params.address,
|
|
13094
|
-
poolId: params.poolId,
|
|
13095
|
-
orderType: params.orderType,
|
|
13096
|
-
triggerType: params.triggerType,
|
|
13097
|
-
operation: OperationType.INCREASE,
|
|
13098
|
-
direction: params.direction,
|
|
13099
|
-
collateralAmount: collateralWithNetworkFee,
|
|
13100
|
-
size: params.size,
|
|
13101
|
-
price: params.price,
|
|
13102
|
-
timeInForce: TIME_IN_FORCE,
|
|
13103
|
-
postOnly: params.postOnly,
|
|
13104
|
-
slippagePct: params.slippagePct,
|
|
13105
|
-
executionFeeToken: params.executionFeeToken,
|
|
13106
|
-
leverage: params.leverage,
|
|
13107
|
-
tpSize: params.tpSize ? params.tpSize : 0,
|
|
13108
|
-
tpPrice: params.tpPrice ? params.tpPrice : 0,
|
|
13109
|
-
slSize: params.slSize ? params.slSize : 0,
|
|
13110
|
-
slPrice: params.slPrice ? params.slPrice : 0,
|
|
13111
|
-
useAccountBalance: false
|
|
13112
|
-
});
|
|
13110
|
+
const positionSalt = "1";
|
|
13111
|
+
this.logger.info("createIncreaseOrder salt position params--->", { ...data, positionSalt });
|
|
13112
|
+
const gasLimit = await brokerContract.placeOrderWithSalt.estimateGas(positionSalt, data);
|
|
13113
13113
|
transaction = await brokerContract.placeOrderWithSalt(
|
|
13114
|
-
|
|
13115
|
-
|
|
13116
|
-
user: params.address,
|
|
13117
|
-
poolId: params.poolId,
|
|
13118
|
-
orderType: params.orderType,
|
|
13119
|
-
triggerType: params.triggerType,
|
|
13120
|
-
operation: OperationType.INCREASE,
|
|
13121
|
-
direction: params.direction,
|
|
13122
|
-
collateralAmount: collateralWithNetworkFee,
|
|
13123
|
-
size: params.size,
|
|
13124
|
-
price: params.price,
|
|
13125
|
-
timeInForce: TIME_IN_FORCE,
|
|
13126
|
-
postOnly: params.postOnly,
|
|
13127
|
-
slippagePct: params.slippagePct,
|
|
13128
|
-
executionFeeToken: params.executionFeeToken,
|
|
13129
|
-
leverage: params.leverage,
|
|
13130
|
-
tpSize: params.tpSize ? params.tpSize : 0,
|
|
13131
|
-
tpPrice: params.tpPrice ? params.tpPrice : 0,
|
|
13132
|
-
slSize: params.slSize ? params.slSize : 0,
|
|
13133
|
-
slPrice: params.slPrice ? params.slPrice : 0,
|
|
13134
|
-
useAccountBalance: false
|
|
13135
|
-
},
|
|
13114
|
+
positionSalt,
|
|
13115
|
+
data,
|
|
13136
13116
|
{
|
|
13137
13117
|
gasLimit: gasLimit * 120n / 100n
|
|
13138
13118
|
}
|
|
13139
13119
|
);
|
|
13140
13120
|
} else {
|
|
13141
13121
|
this.logger.info("createIncreaseOrder nft position params--->", { ...data, positionId: params.positionId });
|
|
13142
|
-
const gasLimit = await brokerContract.placeOrderWithPosition.estimateGas(
|
|
13143
|
-
|
|
13144
|
-
|
|
13145
|
-
|
|
13146
|
-
triggerType: params.triggerType,
|
|
13147
|
-
operation: OperationType.INCREASE,
|
|
13148
|
-
direction: params.direction,
|
|
13149
|
-
collateralAmount: collateralWithNetworkFee,
|
|
13150
|
-
size: params.size,
|
|
13151
|
-
price: params.price,
|
|
13152
|
-
timeInForce: TIME_IN_FORCE,
|
|
13153
|
-
postOnly: params.postOnly,
|
|
13154
|
-
slippagePct: params.slippagePct,
|
|
13155
|
-
executionFeeToken: params.executionFeeToken,
|
|
13156
|
-
leverage: params.leverage,
|
|
13157
|
-
tpSize: params.tpSize ? params.tpSize : 0,
|
|
13158
|
-
tpPrice: params.tpPrice ? params.tpPrice : 0,
|
|
13159
|
-
slSize: params.slSize ? params.slSize : 0,
|
|
13160
|
-
slPrice: params.slPrice ? params.slPrice : 0,
|
|
13161
|
-
useAccountBalance: false
|
|
13162
|
-
});
|
|
13122
|
+
const gasLimit = await brokerContract.placeOrderWithPosition.estimateGas(
|
|
13123
|
+
params.positionId.toString(),
|
|
13124
|
+
data
|
|
13125
|
+
);
|
|
13163
13126
|
transaction = await brokerContract.placeOrderWithPosition(
|
|
13164
13127
|
params.positionId.toString(),
|
|
13165
|
-
|
|
13166
|
-
user: params.address,
|
|
13167
|
-
poolId: params.poolId,
|
|
13168
|
-
orderType: params.orderType,
|
|
13169
|
-
triggerType: params.triggerType,
|
|
13170
|
-
operation: OperationType.INCREASE,
|
|
13171
|
-
direction: params.direction,
|
|
13172
|
-
collateralAmount: collateralWithNetworkFee,
|
|
13173
|
-
size: params.size,
|
|
13174
|
-
price: params.price,
|
|
13175
|
-
timeInForce: TIME_IN_FORCE,
|
|
13176
|
-
postOnly: params.postOnly,
|
|
13177
|
-
slippagePct: params.slippagePct,
|
|
13178
|
-
executionFeeToken: params.executionFeeToken,
|
|
13179
|
-
leverage: params.leverage,
|
|
13180
|
-
tpSize: params.tpSize ? params.tpSize : 0,
|
|
13181
|
-
tpPrice: params.tpPrice ? params.tpPrice : 0,
|
|
13182
|
-
slSize: params.slSize ? params.slSize : 0,
|
|
13183
|
-
slPrice: params.slPrice ? params.slPrice : 0,
|
|
13184
|
-
useAccountBalance: false
|
|
13185
|
-
},
|
|
13128
|
+
data,
|
|
13186
13129
|
{
|
|
13187
13130
|
gasLimit: gasLimit * 120n / 100n
|
|
13188
13131
|
}
|
|
13189
13132
|
);
|
|
13190
13133
|
}
|
|
13134
|
+
this.logger.info("Transaction sent:", transaction.hash);
|
|
13135
|
+
this.logger.info("Waiting for confirmation...");
|
|
13191
13136
|
const receipt = await transaction.wait();
|
|
13137
|
+
this.logger.info("Transaction confirmed in block:", receipt?.blockNumber);
|
|
13192
13138
|
this.logger.info("createIncreaseOrder receipt--->", receipt);
|
|
13193
13139
|
const orderId = this.utils.getOrderIdFromTransaction(receipt);
|
|
13194
13140
|
const result = {
|
|
@@ -19113,10 +19059,10 @@ var MyxClient = class {
|
|
|
19113
19059
|
logLevel: options.logLevel
|
|
19114
19060
|
});
|
|
19115
19061
|
this.utils = new Utils(this.configManager, this.logger);
|
|
19062
|
+
this.account = new Account(this.configManager, this.logger, this.utils);
|
|
19116
19063
|
this.markets = new Markets(this.configManager, this.utils);
|
|
19117
19064
|
this.position = new Position(this.configManager, this.logger, this.utils);
|
|
19118
|
-
this.order = new Order(this.configManager, this.logger, this.utils);
|
|
19119
|
-
this.account = new Account(this.configManager, this.logger, this.utils);
|
|
19065
|
+
this.order = new Order(this.configManager, this.logger, this.utils, this.account);
|
|
19120
19066
|
this.subscription = new SubScription(this.configManager, this.logger);
|
|
19121
19067
|
const lp = MxSDK.getInstance();
|
|
19122
19068
|
lp.setConfigManager(this.configManager);
|
package/dist/index.mjs
CHANGED
|
@@ -1751,7 +1751,7 @@ var RotationProvider = class extends BaseProvider {
|
|
|
1751
1751
|
// package.json
|
|
1752
1752
|
var package_default = {
|
|
1753
1753
|
name: "@myx-trade/sdk",
|
|
1754
|
-
version: "0.1.
|
|
1754
|
+
version: "0.1.53",
|
|
1755
1755
|
private: false,
|
|
1756
1756
|
publishConfig: {
|
|
1757
1757
|
access: "public"
|
|
@@ -12938,10 +12938,11 @@ var OrderStatus = {
|
|
|
12938
12938
|
import { ethers as ethers6, keccak256 } from "ethers";
|
|
12939
12939
|
import { encodeAbiParameters, parseAbiParameters } from "viem";
|
|
12940
12940
|
var Order = class {
|
|
12941
|
-
constructor(configManager, logger, utils) {
|
|
12941
|
+
constructor(configManager, logger, utils, account) {
|
|
12942
12942
|
this.configManager = configManager;
|
|
12943
12943
|
this.logger = logger;
|
|
12944
12944
|
this.utils = utils;
|
|
12945
|
+
this.account = account;
|
|
12945
12946
|
}
|
|
12946
12947
|
async createPositionId(poolId, user, direction, salt) {
|
|
12947
12948
|
const encoded = encodeAbiParameters(parseAbiParameters("bytes32 poolId, address user, uint8 direction, uint64 salt"), [
|
|
@@ -12978,6 +12979,26 @@ var Order = class {
|
|
|
12978
12979
|
throw new Error(approvalResult.message);
|
|
12979
12980
|
}
|
|
12980
12981
|
}
|
|
12982
|
+
const marginAccountBalanceRes = await this.account.getTradableAmount({ poolId: params.poolId });
|
|
12983
|
+
const walletBalanceRes = await this.account.getWalletQuoteTokenBalance();
|
|
12984
|
+
console.log("marginAccountBalance--->", marginAccountBalanceRes);
|
|
12985
|
+
console.log("createIncreaseOrder walletBalance--->", walletBalanceRes);
|
|
12986
|
+
const marginAccountBalance = marginAccountBalanceRes?.data;
|
|
12987
|
+
const walletBalance = walletBalanceRes?.data;
|
|
12988
|
+
if (marginAccountBalanceRes.code !== 0 || walletBalanceRes.code !== 0) {
|
|
12989
|
+
return {
|
|
12990
|
+
code: -1,
|
|
12991
|
+
message: "Failed to get tradable amount or wallet balance"
|
|
12992
|
+
};
|
|
12993
|
+
}
|
|
12994
|
+
let useAccountBalance = false;
|
|
12995
|
+
const totalBalance = BigInt(marginAccountBalance?.freeAmount.toString() ?? 0) + BigInt(marginAccountBalance?.tradeableProfit.toString() ?? 0);
|
|
12996
|
+
let transferAmount = 0n;
|
|
12997
|
+
if (totalBalance > 0) {
|
|
12998
|
+
useAccountBalance = true;
|
|
12999
|
+
transferAmount = collateralWithNetworkFee - totalBalance;
|
|
13000
|
+
}
|
|
13001
|
+
console.log("transferAmount-->", transferAmount);
|
|
12981
13002
|
const data = {
|
|
12982
13003
|
user: params.address,
|
|
12983
13004
|
poolId: params.poolId,
|
|
@@ -12985,125 +13006,50 @@ var Order = class {
|
|
|
12985
13006
|
triggerType: params.triggerType,
|
|
12986
13007
|
operation: OperationType.INCREASE,
|
|
12987
13008
|
direction: params.direction,
|
|
12988
|
-
collateralAmount: collateralWithNetworkFee,
|
|
13009
|
+
collateralAmount: collateralWithNetworkFee.toString(),
|
|
12989
13010
|
size: params.size,
|
|
12990
13011
|
price: params.price,
|
|
12991
13012
|
timeInForce: TIME_IN_FORCE,
|
|
12992
|
-
postOnly: params.postOnly,
|
|
12993
|
-
slippagePct: params.slippagePct,
|
|
13013
|
+
postOnly: params.postOnly ?? false,
|
|
13014
|
+
slippagePct: params.slippagePct ?? "0",
|
|
12994
13015
|
executionFeeToken: params.executionFeeToken,
|
|
12995
|
-
leverage: params.leverage,
|
|
12996
|
-
tpSize: params.tpSize
|
|
12997
|
-
tpPrice: params.tpPrice
|
|
12998
|
-
slSize: params.slSize
|
|
12999
|
-
slPrice: params.slPrice
|
|
13000
|
-
useAccountBalance
|
|
13016
|
+
leverage: params.leverage ?? 0,
|
|
13017
|
+
tpSize: params.tpSize ?? "0",
|
|
13018
|
+
tpPrice: params.tpPrice ?? "0",
|
|
13019
|
+
slSize: params.slSize ?? "0",
|
|
13020
|
+
slPrice: params.slPrice ?? "0",
|
|
13021
|
+
useAccountBalance
|
|
13001
13022
|
};
|
|
13002
|
-
this.logger.info("positionId", params.positionId);
|
|
13003
13023
|
let transaction;
|
|
13004
13024
|
if (!params.positionId) {
|
|
13005
|
-
const
|
|
13006
|
-
this.logger.info("createIncreaseOrder salt position params--->", { ...data,
|
|
13007
|
-
const gasLimit = await brokerContract.placeOrderWithSalt.estimateGas(
|
|
13008
|
-
user: params.address,
|
|
13009
|
-
poolId: params.poolId,
|
|
13010
|
-
orderType: params.orderType,
|
|
13011
|
-
triggerType: params.triggerType,
|
|
13012
|
-
operation: OperationType.INCREASE,
|
|
13013
|
-
direction: params.direction,
|
|
13014
|
-
collateralAmount: collateralWithNetworkFee,
|
|
13015
|
-
size: params.size,
|
|
13016
|
-
price: params.price,
|
|
13017
|
-
timeInForce: TIME_IN_FORCE,
|
|
13018
|
-
postOnly: params.postOnly,
|
|
13019
|
-
slippagePct: params.slippagePct,
|
|
13020
|
-
executionFeeToken: params.executionFeeToken,
|
|
13021
|
-
leverage: params.leverage,
|
|
13022
|
-
tpSize: params.tpSize ? params.tpSize : 0,
|
|
13023
|
-
tpPrice: params.tpPrice ? params.tpPrice : 0,
|
|
13024
|
-
slSize: params.slSize ? params.slSize : 0,
|
|
13025
|
-
slPrice: params.slPrice ? params.slPrice : 0,
|
|
13026
|
-
useAccountBalance: false
|
|
13027
|
-
});
|
|
13025
|
+
const positionSalt = "1";
|
|
13026
|
+
this.logger.info("createIncreaseOrder salt position params--->", { ...data, positionSalt });
|
|
13027
|
+
const gasLimit = await brokerContract.placeOrderWithSalt.estimateGas(positionSalt, data);
|
|
13028
13028
|
transaction = await brokerContract.placeOrderWithSalt(
|
|
13029
|
-
|
|
13030
|
-
|
|
13031
|
-
user: params.address,
|
|
13032
|
-
poolId: params.poolId,
|
|
13033
|
-
orderType: params.orderType,
|
|
13034
|
-
triggerType: params.triggerType,
|
|
13035
|
-
operation: OperationType.INCREASE,
|
|
13036
|
-
direction: params.direction,
|
|
13037
|
-
collateralAmount: collateralWithNetworkFee,
|
|
13038
|
-
size: params.size,
|
|
13039
|
-
price: params.price,
|
|
13040
|
-
timeInForce: TIME_IN_FORCE,
|
|
13041
|
-
postOnly: params.postOnly,
|
|
13042
|
-
slippagePct: params.slippagePct,
|
|
13043
|
-
executionFeeToken: params.executionFeeToken,
|
|
13044
|
-
leverage: params.leverage,
|
|
13045
|
-
tpSize: params.tpSize ? params.tpSize : 0,
|
|
13046
|
-
tpPrice: params.tpPrice ? params.tpPrice : 0,
|
|
13047
|
-
slSize: params.slSize ? params.slSize : 0,
|
|
13048
|
-
slPrice: params.slPrice ? params.slPrice : 0,
|
|
13049
|
-
useAccountBalance: false
|
|
13050
|
-
},
|
|
13029
|
+
positionSalt,
|
|
13030
|
+
data,
|
|
13051
13031
|
{
|
|
13052
13032
|
gasLimit: gasLimit * 120n / 100n
|
|
13053
13033
|
}
|
|
13054
13034
|
);
|
|
13055
13035
|
} else {
|
|
13056
13036
|
this.logger.info("createIncreaseOrder nft position params--->", { ...data, positionId: params.positionId });
|
|
13057
|
-
const gasLimit = await brokerContract.placeOrderWithPosition.estimateGas(
|
|
13058
|
-
|
|
13059
|
-
|
|
13060
|
-
|
|
13061
|
-
triggerType: params.triggerType,
|
|
13062
|
-
operation: OperationType.INCREASE,
|
|
13063
|
-
direction: params.direction,
|
|
13064
|
-
collateralAmount: collateralWithNetworkFee,
|
|
13065
|
-
size: params.size,
|
|
13066
|
-
price: params.price,
|
|
13067
|
-
timeInForce: TIME_IN_FORCE,
|
|
13068
|
-
postOnly: params.postOnly,
|
|
13069
|
-
slippagePct: params.slippagePct,
|
|
13070
|
-
executionFeeToken: params.executionFeeToken,
|
|
13071
|
-
leverage: params.leverage,
|
|
13072
|
-
tpSize: params.tpSize ? params.tpSize : 0,
|
|
13073
|
-
tpPrice: params.tpPrice ? params.tpPrice : 0,
|
|
13074
|
-
slSize: params.slSize ? params.slSize : 0,
|
|
13075
|
-
slPrice: params.slPrice ? params.slPrice : 0,
|
|
13076
|
-
useAccountBalance: false
|
|
13077
|
-
});
|
|
13037
|
+
const gasLimit = await brokerContract.placeOrderWithPosition.estimateGas(
|
|
13038
|
+
params.positionId.toString(),
|
|
13039
|
+
data
|
|
13040
|
+
);
|
|
13078
13041
|
transaction = await brokerContract.placeOrderWithPosition(
|
|
13079
13042
|
params.positionId.toString(),
|
|
13080
|
-
|
|
13081
|
-
user: params.address,
|
|
13082
|
-
poolId: params.poolId,
|
|
13083
|
-
orderType: params.orderType,
|
|
13084
|
-
triggerType: params.triggerType,
|
|
13085
|
-
operation: OperationType.INCREASE,
|
|
13086
|
-
direction: params.direction,
|
|
13087
|
-
collateralAmount: collateralWithNetworkFee,
|
|
13088
|
-
size: params.size,
|
|
13089
|
-
price: params.price,
|
|
13090
|
-
timeInForce: TIME_IN_FORCE,
|
|
13091
|
-
postOnly: params.postOnly,
|
|
13092
|
-
slippagePct: params.slippagePct,
|
|
13093
|
-
executionFeeToken: params.executionFeeToken,
|
|
13094
|
-
leverage: params.leverage,
|
|
13095
|
-
tpSize: params.tpSize ? params.tpSize : 0,
|
|
13096
|
-
tpPrice: params.tpPrice ? params.tpPrice : 0,
|
|
13097
|
-
slSize: params.slSize ? params.slSize : 0,
|
|
13098
|
-
slPrice: params.slPrice ? params.slPrice : 0,
|
|
13099
|
-
useAccountBalance: false
|
|
13100
|
-
},
|
|
13043
|
+
data,
|
|
13101
13044
|
{
|
|
13102
13045
|
gasLimit: gasLimit * 120n / 100n
|
|
13103
13046
|
}
|
|
13104
13047
|
);
|
|
13105
13048
|
}
|
|
13049
|
+
this.logger.info("Transaction sent:", transaction.hash);
|
|
13050
|
+
this.logger.info("Waiting for confirmation...");
|
|
13106
13051
|
const receipt = await transaction.wait();
|
|
13052
|
+
this.logger.info("Transaction confirmed in block:", receipt?.blockNumber);
|
|
13107
13053
|
this.logger.info("createIncreaseOrder receipt--->", receipt);
|
|
13108
13054
|
const orderId = this.utils.getOrderIdFromTransaction(receipt);
|
|
13109
13055
|
const result = {
|
|
@@ -19028,10 +18974,10 @@ var MyxClient = class {
|
|
|
19028
18974
|
logLevel: options.logLevel
|
|
19029
18975
|
});
|
|
19030
18976
|
this.utils = new Utils(this.configManager, this.logger);
|
|
18977
|
+
this.account = new Account(this.configManager, this.logger, this.utils);
|
|
19031
18978
|
this.markets = new Markets(this.configManager, this.utils);
|
|
19032
18979
|
this.position = new Position(this.configManager, this.logger, this.utils);
|
|
19033
|
-
this.order = new Order(this.configManager, this.logger, this.utils);
|
|
19034
|
-
this.account = new Account(this.configManager, this.logger, this.utils);
|
|
18980
|
+
this.order = new Order(this.configManager, this.logger, this.utils, this.account);
|
|
19035
18981
|
this.subscription = new SubScription(this.configManager, this.logger);
|
|
19036
18982
|
const lp = MxSDK.getInstance();
|
|
19037
18983
|
lp.setConfigManager(this.configManager);
|