@myx-trade/sdk 0.1.35 → 0.1.37
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 +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +217 -59
- package/dist/index.mjs +218 -60
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -2,7 +2,7 @@ import * as ethers from 'ethers';
|
|
|
2
2
|
import { ZeroAddress, AddressLike, Signer, ethers as ethers$1 } from 'ethers';
|
|
3
3
|
export { formatUnits, parseUnits } from 'ethers';
|
|
4
4
|
import { Options, Event } from 'reconnecting-websocket';
|
|
5
|
-
import { WalletClient } from 'viem';
|
|
5
|
+
import { WalletClient, Address as Address$3 } from 'viem';
|
|
6
6
|
|
|
7
7
|
type Address$2 = `0x${string}` | typeof ZeroAddress;
|
|
8
8
|
declare enum ChainId {
|
|
@@ -175,7 +175,7 @@ interface PlaceOrderParams {
|
|
|
175
175
|
chainId: number;
|
|
176
176
|
address: string;
|
|
177
177
|
poolId: string;
|
|
178
|
-
positionId:
|
|
178
|
+
positionId: string;
|
|
179
179
|
orderType: OrderType;
|
|
180
180
|
triggerType: TriggerType;
|
|
181
181
|
direction: Direction;
|
|
@@ -196,7 +196,7 @@ interface PositionTpSlOrderParams {
|
|
|
196
196
|
chainId: number;
|
|
197
197
|
address: string;
|
|
198
198
|
poolId: string;
|
|
199
|
-
positionId:
|
|
199
|
+
positionId: string;
|
|
200
200
|
executionFeeToken: string;
|
|
201
201
|
tpTriggerType: TriggerType;
|
|
202
202
|
slTriggerType: TriggerType;
|
|
@@ -1429,6 +1429,7 @@ declare class Order {
|
|
|
1429
1429
|
private logger;
|
|
1430
1430
|
private utils;
|
|
1431
1431
|
constructor(configManager: ConfigManager, logger: Logger, utils: Utils);
|
|
1432
|
+
createPositionId(poolId: string, user: Address$3, direction: Direction, salt: bigint): Promise<string>;
|
|
1432
1433
|
createIncreaseOrder(params: PlaceOrderParams): Promise<{
|
|
1433
1434
|
code: number;
|
|
1434
1435
|
message: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import * as ethers from 'ethers';
|
|
|
2
2
|
import { ZeroAddress, AddressLike, Signer, ethers as ethers$1 } from 'ethers';
|
|
3
3
|
export { formatUnits, parseUnits } from 'ethers';
|
|
4
4
|
import { Options, Event } from 'reconnecting-websocket';
|
|
5
|
-
import { WalletClient } from 'viem';
|
|
5
|
+
import { WalletClient, Address as Address$3 } from 'viem';
|
|
6
6
|
|
|
7
7
|
type Address$2 = `0x${string}` | typeof ZeroAddress;
|
|
8
8
|
declare enum ChainId {
|
|
@@ -175,7 +175,7 @@ interface PlaceOrderParams {
|
|
|
175
175
|
chainId: number;
|
|
176
176
|
address: string;
|
|
177
177
|
poolId: string;
|
|
178
|
-
positionId:
|
|
178
|
+
positionId: string;
|
|
179
179
|
orderType: OrderType;
|
|
180
180
|
triggerType: TriggerType;
|
|
181
181
|
direction: Direction;
|
|
@@ -196,7 +196,7 @@ interface PositionTpSlOrderParams {
|
|
|
196
196
|
chainId: number;
|
|
197
197
|
address: string;
|
|
198
198
|
poolId: string;
|
|
199
|
-
positionId:
|
|
199
|
+
positionId: string;
|
|
200
200
|
executionFeeToken: string;
|
|
201
201
|
tpTriggerType: TriggerType;
|
|
202
202
|
slTriggerType: TriggerType;
|
|
@@ -1429,6 +1429,7 @@ declare class Order {
|
|
|
1429
1429
|
private logger;
|
|
1430
1430
|
private utils;
|
|
1431
1431
|
constructor(configManager: ConfigManager, logger: Logger, utils: Utils);
|
|
1432
|
+
createPositionId(poolId: string, user: Address$3, direction: Direction, salt: bigint): Promise<string>;
|
|
1432
1433
|
createIncreaseOrder(params: PlaceOrderParams): Promise<{
|
|
1433
1434
|
code: number;
|
|
1434
1435
|
message: string;
|
package/dist/index.js
CHANGED
|
@@ -1825,7 +1825,7 @@ var RotationProvider = class extends import_providers.BaseProvider {
|
|
|
1825
1825
|
// package.json
|
|
1826
1826
|
var package_default = {
|
|
1827
1827
|
name: "@myx-trade/sdk",
|
|
1828
|
-
version: "0.1.
|
|
1828
|
+
version: "0.1.37",
|
|
1829
1829
|
private: false,
|
|
1830
1830
|
publishConfig: {
|
|
1831
1831
|
access: "public"
|
|
@@ -12892,12 +12892,22 @@ var OrderStatus = {
|
|
|
12892
12892
|
|
|
12893
12893
|
// src/manager/order/index.ts
|
|
12894
12894
|
var import_ethers25 = require("ethers");
|
|
12895
|
+
var import_viem = require("viem");
|
|
12895
12896
|
var Order = class {
|
|
12896
12897
|
constructor(configManager, logger, utils) {
|
|
12897
12898
|
this.configManager = configManager;
|
|
12898
12899
|
this.logger = logger;
|
|
12899
12900
|
this.utils = utils;
|
|
12900
12901
|
}
|
|
12902
|
+
async createPositionId(poolId, user, direction, salt) {
|
|
12903
|
+
const encoded = (0, import_viem.encodeAbiParameters)((0, import_viem.parseAbiParameters)("bytes32 poolId, address user, uint8 direction, uint64 salt"), [
|
|
12904
|
+
poolId,
|
|
12905
|
+
user,
|
|
12906
|
+
direction,
|
|
12907
|
+
salt
|
|
12908
|
+
]);
|
|
12909
|
+
return (0, import_ethers25.keccak256)(encoded);
|
|
12910
|
+
}
|
|
12901
12911
|
async createIncreaseOrder(params) {
|
|
12902
12912
|
try {
|
|
12903
12913
|
const config = this.configManager.getConfig();
|
|
@@ -12924,29 +12934,7 @@ var Order = class {
|
|
|
12924
12934
|
throw new Error(approvalResult.message);
|
|
12925
12935
|
}
|
|
12926
12936
|
}
|
|
12927
|
-
|
|
12928
|
-
user: params.address,
|
|
12929
|
-
poolId: params.poolId,
|
|
12930
|
-
positionId: params.positionId,
|
|
12931
|
-
orderType: params.orderType,
|
|
12932
|
-
triggerType: params.triggerType,
|
|
12933
|
-
operation: OperationType.INCREASE,
|
|
12934
|
-
direction: params.direction,
|
|
12935
|
-
collateralAmount: collateralWithNetworkFee,
|
|
12936
|
-
size: params.size,
|
|
12937
|
-
price: params.price,
|
|
12938
|
-
timeInForce: TIME_IN_FORCE,
|
|
12939
|
-
postOnly: params.postOnly,
|
|
12940
|
-
slippagePct: params.slippagePct,
|
|
12941
|
-
executionFeeToken: params.executionFeeToken,
|
|
12942
|
-
leverage: params.leverage,
|
|
12943
|
-
tpSize: params.tpSize ? params.tpSize : 0,
|
|
12944
|
-
tpPrice: params.tpPrice ? params.tpPrice : 0,
|
|
12945
|
-
slSize: params.slSize ? params.slSize : 0,
|
|
12946
|
-
slPrice: params.slPrice ? params.slPrice : 0,
|
|
12947
|
-
useAccountBalance: false
|
|
12948
|
-
});
|
|
12949
|
-
const gasLimit = await brokerContract.placeOrderWithPosition.estimateGas(params.positionId.toString(), {
|
|
12937
|
+
const data = {
|
|
12950
12938
|
user: params.address,
|
|
12951
12939
|
poolId: params.poolId,
|
|
12952
12940
|
orderType: params.orderType,
|
|
@@ -12966,10 +12954,12 @@ var Order = class {
|
|
|
12966
12954
|
slSize: params.slSize ? params.slSize : 0,
|
|
12967
12955
|
slPrice: params.slPrice ? params.slPrice : 0,
|
|
12968
12956
|
useAccountBalance: false
|
|
12969
|
-
}
|
|
12970
|
-
|
|
12971
|
-
|
|
12972
|
-
|
|
12957
|
+
};
|
|
12958
|
+
let transaction;
|
|
12959
|
+
if (!params.positionId) {
|
|
12960
|
+
const positionId = await this.createPositionId(params.poolId, params.address, params.direction, BigInt(1));
|
|
12961
|
+
this.logger.info("createIncreaseOrder salt position params--->", { ...data, positionId });
|
|
12962
|
+
const gasLimit = await brokerContract.placeOrderWithSalt.estimateGas(positionId.toString(), {
|
|
12973
12963
|
user: params.address,
|
|
12974
12964
|
poolId: params.poolId,
|
|
12975
12965
|
orderType: params.orderType,
|
|
@@ -12989,11 +12979,85 @@ var Order = class {
|
|
|
12989
12979
|
slSize: params.slSize ? params.slSize : 0,
|
|
12990
12980
|
slPrice: params.slPrice ? params.slPrice : 0,
|
|
12991
12981
|
useAccountBalance: false
|
|
12992
|
-
}
|
|
12993
|
-
|
|
12994
|
-
|
|
12995
|
-
|
|
12996
|
-
|
|
12982
|
+
});
|
|
12983
|
+
transaction = await brokerContract.placeOrderWithSalt(
|
|
12984
|
+
positionId.toString(),
|
|
12985
|
+
{
|
|
12986
|
+
user: params.address,
|
|
12987
|
+
poolId: params.poolId,
|
|
12988
|
+
orderType: params.orderType,
|
|
12989
|
+
triggerType: params.triggerType,
|
|
12990
|
+
operation: OperationType.INCREASE,
|
|
12991
|
+
direction: params.direction,
|
|
12992
|
+
collateralAmount: collateralWithNetworkFee,
|
|
12993
|
+
size: params.size,
|
|
12994
|
+
price: params.price,
|
|
12995
|
+
timeInForce: TIME_IN_FORCE,
|
|
12996
|
+
postOnly: params.postOnly,
|
|
12997
|
+
slippagePct: params.slippagePct,
|
|
12998
|
+
executionFeeToken: params.executionFeeToken,
|
|
12999
|
+
leverage: params.leverage,
|
|
13000
|
+
tpSize: params.tpSize ? params.tpSize : 0,
|
|
13001
|
+
tpPrice: params.tpPrice ? params.tpPrice : 0,
|
|
13002
|
+
slSize: params.slSize ? params.slSize : 0,
|
|
13003
|
+
slPrice: params.slPrice ? params.slPrice : 0,
|
|
13004
|
+
useAccountBalance: false
|
|
13005
|
+
},
|
|
13006
|
+
{
|
|
13007
|
+
gasLimit: gasLimit * 120n / 100n
|
|
13008
|
+
}
|
|
13009
|
+
);
|
|
13010
|
+
} else {
|
|
13011
|
+
this.logger.info("createIncreaseOrder nft position params--->", { ...data, positionId: params.positionId });
|
|
13012
|
+
const gasLimit = await brokerContract.placeOrderWithPosition.estimateGas(params.positionId.toString(), {
|
|
13013
|
+
user: params.address,
|
|
13014
|
+
poolId: params.poolId,
|
|
13015
|
+
orderType: params.orderType,
|
|
13016
|
+
triggerType: params.triggerType,
|
|
13017
|
+
operation: OperationType.INCREASE,
|
|
13018
|
+
direction: params.direction,
|
|
13019
|
+
collateralAmount: collateralWithNetworkFee,
|
|
13020
|
+
size: params.size,
|
|
13021
|
+
price: params.price,
|
|
13022
|
+
timeInForce: TIME_IN_FORCE,
|
|
13023
|
+
postOnly: params.postOnly,
|
|
13024
|
+
slippagePct: params.slippagePct,
|
|
13025
|
+
executionFeeToken: params.executionFeeToken,
|
|
13026
|
+
leverage: params.leverage,
|
|
13027
|
+
tpSize: params.tpSize ? params.tpSize : 0,
|
|
13028
|
+
tpPrice: params.tpPrice ? params.tpPrice : 0,
|
|
13029
|
+
slSize: params.slSize ? params.slSize : 0,
|
|
13030
|
+
slPrice: params.slPrice ? params.slPrice : 0,
|
|
13031
|
+
useAccountBalance: false
|
|
13032
|
+
});
|
|
13033
|
+
transaction = await brokerContract.placeOrderWithPosition(
|
|
13034
|
+
params.positionId.toString(),
|
|
13035
|
+
{
|
|
13036
|
+
user: params.address,
|
|
13037
|
+
poolId: params.poolId,
|
|
13038
|
+
orderType: params.orderType,
|
|
13039
|
+
triggerType: params.triggerType,
|
|
13040
|
+
operation: OperationType.INCREASE,
|
|
13041
|
+
direction: params.direction,
|
|
13042
|
+
collateralAmount: collateralWithNetworkFee,
|
|
13043
|
+
size: params.size,
|
|
13044
|
+
price: params.price,
|
|
13045
|
+
timeInForce: TIME_IN_FORCE,
|
|
13046
|
+
postOnly: params.postOnly,
|
|
13047
|
+
slippagePct: params.slippagePct,
|
|
13048
|
+
executionFeeToken: params.executionFeeToken,
|
|
13049
|
+
leverage: params.leverage,
|
|
13050
|
+
tpSize: params.tpSize ? params.tpSize : 0,
|
|
13051
|
+
tpPrice: params.tpPrice ? params.tpPrice : 0,
|
|
13052
|
+
slSize: params.slSize ? params.slSize : 0,
|
|
13053
|
+
slPrice: params.slPrice ? params.slPrice : 0,
|
|
13054
|
+
useAccountBalance: false
|
|
13055
|
+
},
|
|
13056
|
+
{
|
|
13057
|
+
gasLimit: gasLimit * 120n / 100n
|
|
13058
|
+
}
|
|
13059
|
+
);
|
|
13060
|
+
}
|
|
12997
13061
|
const receipt = await transaction.wait();
|
|
12998
13062
|
this.logger.info("createIncreaseOrder receipt--->", receipt);
|
|
12999
13063
|
const orderId = this.utils.getOrderIdFromTransaction(receipt);
|
|
@@ -13057,7 +13121,7 @@ var Order = class {
|
|
|
13057
13121
|
executionFeeToken: params.executionFeeToken,
|
|
13058
13122
|
leverage: params.leverage
|
|
13059
13123
|
});
|
|
13060
|
-
const
|
|
13124
|
+
const data = {
|
|
13061
13125
|
user: params.address,
|
|
13062
13126
|
poolId: params.poolId,
|
|
13063
13127
|
orderType: params.orderType,
|
|
@@ -13077,10 +13141,12 @@ var Order = class {
|
|
|
13077
13141
|
slSize: 0,
|
|
13078
13142
|
slPrice: 0,
|
|
13079
13143
|
useAccountBalance: false
|
|
13080
|
-
}
|
|
13081
|
-
|
|
13082
|
-
|
|
13083
|
-
|
|
13144
|
+
};
|
|
13145
|
+
let transaction;
|
|
13146
|
+
if (!params.positionId) {
|
|
13147
|
+
const positionId = await this.createPositionId(params.poolId, params.address, params.direction, BigInt(1));
|
|
13148
|
+
this.logger.info("createDecreaseOrder salt position params--->", { ...data, positionId });
|
|
13149
|
+
const gasLimit = await brokerContract.placeOrderWithPosition.estimateGas(positionId.toString(), {
|
|
13084
13150
|
user: params.address,
|
|
13085
13151
|
poolId: params.poolId,
|
|
13086
13152
|
orderType: params.orderType,
|
|
@@ -13091,7 +13157,7 @@ var Order = class {
|
|
|
13091
13157
|
size: params.size,
|
|
13092
13158
|
price: params.price,
|
|
13093
13159
|
timeInForce: TIME_IN_FORCE,
|
|
13094
|
-
postOnly:
|
|
13160
|
+
postOnly: params.postOnly,
|
|
13095
13161
|
slippagePct: params.slippagePct,
|
|
13096
13162
|
executionFeeToken: params.executionFeeToken,
|
|
13097
13163
|
leverage: params.leverage,
|
|
@@ -13100,11 +13166,85 @@ var Order = class {
|
|
|
13100
13166
|
slSize: 0,
|
|
13101
13167
|
slPrice: 0,
|
|
13102
13168
|
useAccountBalance: false
|
|
13103
|
-
}
|
|
13104
|
-
|
|
13105
|
-
|
|
13106
|
-
|
|
13107
|
-
|
|
13169
|
+
});
|
|
13170
|
+
transaction = await brokerContract.placeOrderWithPosition(
|
|
13171
|
+
params.positionId.toString(),
|
|
13172
|
+
{
|
|
13173
|
+
user: params.address,
|
|
13174
|
+
poolId: params.poolId,
|
|
13175
|
+
orderType: params.orderType,
|
|
13176
|
+
triggerType: params.triggerType,
|
|
13177
|
+
operation: OperationType.DECREASE,
|
|
13178
|
+
direction: params.direction,
|
|
13179
|
+
collateralAmount: collateralWithNetworkFee,
|
|
13180
|
+
size: params.size,
|
|
13181
|
+
price: params.price,
|
|
13182
|
+
timeInForce: TIME_IN_FORCE,
|
|
13183
|
+
postOnly: false,
|
|
13184
|
+
slippagePct: params.slippagePct,
|
|
13185
|
+
executionFeeToken: params.executionFeeToken,
|
|
13186
|
+
leverage: params.leverage,
|
|
13187
|
+
tpSize: 0,
|
|
13188
|
+
tpPrice: 0,
|
|
13189
|
+
slSize: 0,
|
|
13190
|
+
slPrice: 0,
|
|
13191
|
+
useAccountBalance: false
|
|
13192
|
+
},
|
|
13193
|
+
{
|
|
13194
|
+
gasLimit: gasLimit * 130n / 100n
|
|
13195
|
+
}
|
|
13196
|
+
);
|
|
13197
|
+
} else {
|
|
13198
|
+
this.logger.info("createDecreaseOrder nft position params--->", { ...data, positionId: params.positionId });
|
|
13199
|
+
const gasLimit = await brokerContract.placeOrderWithPosition.estimateGas(params.positionId.toString(), {
|
|
13200
|
+
user: params.address,
|
|
13201
|
+
poolId: params.poolId,
|
|
13202
|
+
orderType: params.orderType,
|
|
13203
|
+
triggerType: params.triggerType,
|
|
13204
|
+
operation: OperationType.DECREASE,
|
|
13205
|
+
direction: params.direction,
|
|
13206
|
+
collateralAmount: collateralWithNetworkFee,
|
|
13207
|
+
size: params.size,
|
|
13208
|
+
price: params.price,
|
|
13209
|
+
timeInForce: TIME_IN_FORCE,
|
|
13210
|
+
postOnly: params.postOnly,
|
|
13211
|
+
slippagePct: params.slippagePct,
|
|
13212
|
+
executionFeeToken: params.executionFeeToken,
|
|
13213
|
+
leverage: params.leverage,
|
|
13214
|
+
tpSize: 0,
|
|
13215
|
+
tpPrice: 0,
|
|
13216
|
+
slSize: 0,
|
|
13217
|
+
slPrice: 0,
|
|
13218
|
+
useAccountBalance: false
|
|
13219
|
+
});
|
|
13220
|
+
transaction = await brokerContract.placeOrderWithPosition(
|
|
13221
|
+
params.positionId.toString(),
|
|
13222
|
+
{
|
|
13223
|
+
user: params.address,
|
|
13224
|
+
poolId: params.poolId,
|
|
13225
|
+
orderType: params.orderType,
|
|
13226
|
+
triggerType: params.triggerType,
|
|
13227
|
+
operation: OperationType.DECREASE,
|
|
13228
|
+
direction: params.direction,
|
|
13229
|
+
collateralAmount: collateralWithNetworkFee,
|
|
13230
|
+
size: params.size,
|
|
13231
|
+
price: params.price,
|
|
13232
|
+
timeInForce: TIME_IN_FORCE,
|
|
13233
|
+
postOnly: false,
|
|
13234
|
+
slippagePct: params.slippagePct,
|
|
13235
|
+
executionFeeToken: params.executionFeeToken,
|
|
13236
|
+
leverage: params.leverage,
|
|
13237
|
+
tpSize: 0,
|
|
13238
|
+
tpPrice: 0,
|
|
13239
|
+
slSize: 0,
|
|
13240
|
+
slPrice: 0,
|
|
13241
|
+
useAccountBalance: false
|
|
13242
|
+
},
|
|
13243
|
+
{
|
|
13244
|
+
gasLimit: gasLimit * 130n / 100n
|
|
13245
|
+
}
|
|
13246
|
+
);
|
|
13247
|
+
}
|
|
13108
13248
|
this.logger.info("Transaction sent:", transaction.hash);
|
|
13109
13249
|
this.logger.info("Waiting for confirmation...");
|
|
13110
13250
|
const receipt = await transaction.wait();
|
|
@@ -13197,11 +13337,21 @@ var Order = class {
|
|
|
13197
13337
|
useAccountBalance: false
|
|
13198
13338
|
}
|
|
13199
13339
|
];
|
|
13200
|
-
|
|
13201
|
-
|
|
13202
|
-
|
|
13203
|
-
|
|
13204
|
-
|
|
13340
|
+
let transaction2;
|
|
13341
|
+
if (!params.positionId) {
|
|
13342
|
+
this.logger.info("createPositionTpSlOrder salt position data--->", data2);
|
|
13343
|
+
const positionId = await this.createPositionId(params.poolId, params.address, params.direction, BigInt(1));
|
|
13344
|
+
const gasLimit = await brokerContract.placeOrdersWithSalt.estimateGas([positionId.toString(), positionId.toString()], data2);
|
|
13345
|
+
transaction2 = await brokerContract.placeOrdersWithSalt([positionId.toString(), positionId.toString()], data2, {
|
|
13346
|
+
gasLimit: gasLimit * 120n / 100n
|
|
13347
|
+
});
|
|
13348
|
+
} else {
|
|
13349
|
+
this.logger.info("createPositionTpSlOrder nft position data--->", data2);
|
|
13350
|
+
const gasLimit = await brokerContract.placeOrdersWithPosition.estimateGas([params.positionId.toString(), params.positionId.toString()], data2);
|
|
13351
|
+
transaction2 = await brokerContract.placeOrdersWithPosition([params.positionId.toString(), params.positionId.toString()], data2, {
|
|
13352
|
+
gasLimit: gasLimit * 120n / 100n
|
|
13353
|
+
});
|
|
13354
|
+
}
|
|
13205
13355
|
this.logger.info("Transaction sent:", transaction2.hash);
|
|
13206
13356
|
this.logger.info("Waiting for confirmation...");
|
|
13207
13357
|
const receipt2 = await transaction2.wait();
|
|
@@ -13253,11 +13403,21 @@ var Order = class {
|
|
|
13253
13403
|
slPrice: "0",
|
|
13254
13404
|
useAccountBalance: false
|
|
13255
13405
|
};
|
|
13256
|
-
|
|
13257
|
-
|
|
13258
|
-
|
|
13259
|
-
|
|
13260
|
-
|
|
13406
|
+
let transaction;
|
|
13407
|
+
if (!params.positionId) {
|
|
13408
|
+
this.logger.info("createPositionTpOrSlOrder salt position data--->", data);
|
|
13409
|
+
const positionId = await this.createPositionId(params.poolId, params.address, params.direction, BigInt(1));
|
|
13410
|
+
const gasLimit = await brokerContract.placeOrderWithPosition.estimateGas(params.positionId.toString(), data);
|
|
13411
|
+
transaction = await brokerContract.placeOrderWithPosition(positionId.toString(), data, {
|
|
13412
|
+
gasLimit: gasLimit * 120n / 100n
|
|
13413
|
+
});
|
|
13414
|
+
} else {
|
|
13415
|
+
this.logger.info("createPositionTpOrSlOrder nft position data--->", data);
|
|
13416
|
+
const gasLimit = await brokerContract.placeOrderWithPosition.estimateGas(params.positionId.toString(), data);
|
|
13417
|
+
transaction = await brokerContract.placeOrderWithPosition(params.positionId.toString(), data, {
|
|
13418
|
+
gasLimit: gasLimit * 120n / 100n
|
|
13419
|
+
});
|
|
13420
|
+
}
|
|
13261
13421
|
this.logger.info("Transaction sent:", transaction.hash);
|
|
13262
13422
|
this.logger.info("Waiting for confirmation...");
|
|
13263
13423
|
const receipt = await transaction.wait();
|
|
@@ -13354,7 +13514,6 @@ var Order = class {
|
|
|
13354
13514
|
if (!config.signer) {
|
|
13355
13515
|
throw new MyxSDKError("INVALID_SIGNER" /* InvalidSigner */, "Invalid signer");
|
|
13356
13516
|
}
|
|
13357
|
-
console.log("updateOrderTpSl params", params);
|
|
13358
13517
|
const brokerContract = await getBrokerSingerContract(
|
|
13359
13518
|
config.chainId
|
|
13360
13519
|
);
|
|
@@ -13373,18 +13532,17 @@ var Order = class {
|
|
|
13373
13532
|
paymentType: 0
|
|
13374
13533
|
}
|
|
13375
13534
|
};
|
|
13376
|
-
|
|
13535
|
+
this.logger.info("updateOrderTpSl params", data);
|
|
13377
13536
|
try {
|
|
13378
13537
|
const gasLimit = await brokerContract.updateOrder.estimateGas(data);
|
|
13379
|
-
console.log("gaslimit->", gasLimit);
|
|
13380
13538
|
const request = await brokerContract.updateOrder(data, {
|
|
13381
13539
|
gasLimit: gasLimit * 120n / 100n
|
|
13382
13540
|
});
|
|
13383
13541
|
const receipt = await request?.wait();
|
|
13384
|
-
|
|
13542
|
+
this.logger.info("updateOrderTpSl receipt", receipt);
|
|
13385
13543
|
return receipt;
|
|
13386
13544
|
} catch (error) {
|
|
13387
|
-
|
|
13545
|
+
this.logger.error("Error updating order:", error);
|
|
13388
13546
|
return {
|
|
13389
13547
|
code: -1,
|
|
13390
13548
|
message: "Failed to update order"
|
package/dist/index.mjs
CHANGED
|
@@ -1740,7 +1740,7 @@ var RotationProvider = class extends BaseProvider {
|
|
|
1740
1740
|
// package.json
|
|
1741
1741
|
var package_default = {
|
|
1742
1742
|
name: "@myx-trade/sdk",
|
|
1743
|
-
version: "0.1.
|
|
1743
|
+
version: "0.1.37",
|
|
1744
1744
|
private: false,
|
|
1745
1745
|
publishConfig: {
|
|
1746
1746
|
access: "public"
|
|
@@ -12806,13 +12806,23 @@ var OrderStatus = {
|
|
|
12806
12806
|
};
|
|
12807
12807
|
|
|
12808
12808
|
// src/manager/order/index.ts
|
|
12809
|
-
import { ethers as ethers6 } from "ethers";
|
|
12809
|
+
import { ethers as ethers6, keccak256 } from "ethers";
|
|
12810
|
+
import { encodeAbiParameters, parseAbiParameters } from "viem";
|
|
12810
12811
|
var Order = class {
|
|
12811
12812
|
constructor(configManager, logger, utils) {
|
|
12812
12813
|
this.configManager = configManager;
|
|
12813
12814
|
this.logger = logger;
|
|
12814
12815
|
this.utils = utils;
|
|
12815
12816
|
}
|
|
12817
|
+
async createPositionId(poolId, user, direction, salt) {
|
|
12818
|
+
const encoded = encodeAbiParameters(parseAbiParameters("bytes32 poolId, address user, uint8 direction, uint64 salt"), [
|
|
12819
|
+
poolId,
|
|
12820
|
+
user,
|
|
12821
|
+
direction,
|
|
12822
|
+
salt
|
|
12823
|
+
]);
|
|
12824
|
+
return keccak256(encoded);
|
|
12825
|
+
}
|
|
12816
12826
|
async createIncreaseOrder(params) {
|
|
12817
12827
|
try {
|
|
12818
12828
|
const config = this.configManager.getConfig();
|
|
@@ -12839,29 +12849,7 @@ var Order = class {
|
|
|
12839
12849
|
throw new Error(approvalResult.message);
|
|
12840
12850
|
}
|
|
12841
12851
|
}
|
|
12842
|
-
|
|
12843
|
-
user: params.address,
|
|
12844
|
-
poolId: params.poolId,
|
|
12845
|
-
positionId: params.positionId,
|
|
12846
|
-
orderType: params.orderType,
|
|
12847
|
-
triggerType: params.triggerType,
|
|
12848
|
-
operation: OperationType.INCREASE,
|
|
12849
|
-
direction: params.direction,
|
|
12850
|
-
collateralAmount: collateralWithNetworkFee,
|
|
12851
|
-
size: params.size,
|
|
12852
|
-
price: params.price,
|
|
12853
|
-
timeInForce: TIME_IN_FORCE,
|
|
12854
|
-
postOnly: params.postOnly,
|
|
12855
|
-
slippagePct: params.slippagePct,
|
|
12856
|
-
executionFeeToken: params.executionFeeToken,
|
|
12857
|
-
leverage: params.leverage,
|
|
12858
|
-
tpSize: params.tpSize ? params.tpSize : 0,
|
|
12859
|
-
tpPrice: params.tpPrice ? params.tpPrice : 0,
|
|
12860
|
-
slSize: params.slSize ? params.slSize : 0,
|
|
12861
|
-
slPrice: params.slPrice ? params.slPrice : 0,
|
|
12862
|
-
useAccountBalance: false
|
|
12863
|
-
});
|
|
12864
|
-
const gasLimit = await brokerContract.placeOrderWithPosition.estimateGas(params.positionId.toString(), {
|
|
12852
|
+
const data = {
|
|
12865
12853
|
user: params.address,
|
|
12866
12854
|
poolId: params.poolId,
|
|
12867
12855
|
orderType: params.orderType,
|
|
@@ -12881,10 +12869,12 @@ var Order = class {
|
|
|
12881
12869
|
slSize: params.slSize ? params.slSize : 0,
|
|
12882
12870
|
slPrice: params.slPrice ? params.slPrice : 0,
|
|
12883
12871
|
useAccountBalance: false
|
|
12884
|
-
}
|
|
12885
|
-
|
|
12886
|
-
|
|
12887
|
-
|
|
12872
|
+
};
|
|
12873
|
+
let transaction;
|
|
12874
|
+
if (!params.positionId) {
|
|
12875
|
+
const positionId = await this.createPositionId(params.poolId, params.address, params.direction, BigInt(1));
|
|
12876
|
+
this.logger.info("createIncreaseOrder salt position params--->", { ...data, positionId });
|
|
12877
|
+
const gasLimit = await brokerContract.placeOrderWithSalt.estimateGas(positionId.toString(), {
|
|
12888
12878
|
user: params.address,
|
|
12889
12879
|
poolId: params.poolId,
|
|
12890
12880
|
orderType: params.orderType,
|
|
@@ -12904,11 +12894,85 @@ var Order = class {
|
|
|
12904
12894
|
slSize: params.slSize ? params.slSize : 0,
|
|
12905
12895
|
slPrice: params.slPrice ? params.slPrice : 0,
|
|
12906
12896
|
useAccountBalance: false
|
|
12907
|
-
}
|
|
12908
|
-
|
|
12909
|
-
|
|
12910
|
-
|
|
12911
|
-
|
|
12897
|
+
});
|
|
12898
|
+
transaction = await brokerContract.placeOrderWithSalt(
|
|
12899
|
+
positionId.toString(),
|
|
12900
|
+
{
|
|
12901
|
+
user: params.address,
|
|
12902
|
+
poolId: params.poolId,
|
|
12903
|
+
orderType: params.orderType,
|
|
12904
|
+
triggerType: params.triggerType,
|
|
12905
|
+
operation: OperationType.INCREASE,
|
|
12906
|
+
direction: params.direction,
|
|
12907
|
+
collateralAmount: collateralWithNetworkFee,
|
|
12908
|
+
size: params.size,
|
|
12909
|
+
price: params.price,
|
|
12910
|
+
timeInForce: TIME_IN_FORCE,
|
|
12911
|
+
postOnly: params.postOnly,
|
|
12912
|
+
slippagePct: params.slippagePct,
|
|
12913
|
+
executionFeeToken: params.executionFeeToken,
|
|
12914
|
+
leverage: params.leverage,
|
|
12915
|
+
tpSize: params.tpSize ? params.tpSize : 0,
|
|
12916
|
+
tpPrice: params.tpPrice ? params.tpPrice : 0,
|
|
12917
|
+
slSize: params.slSize ? params.slSize : 0,
|
|
12918
|
+
slPrice: params.slPrice ? params.slPrice : 0,
|
|
12919
|
+
useAccountBalance: false
|
|
12920
|
+
},
|
|
12921
|
+
{
|
|
12922
|
+
gasLimit: gasLimit * 120n / 100n
|
|
12923
|
+
}
|
|
12924
|
+
);
|
|
12925
|
+
} else {
|
|
12926
|
+
this.logger.info("createIncreaseOrder nft position params--->", { ...data, positionId: params.positionId });
|
|
12927
|
+
const gasLimit = await brokerContract.placeOrderWithPosition.estimateGas(params.positionId.toString(), {
|
|
12928
|
+
user: params.address,
|
|
12929
|
+
poolId: params.poolId,
|
|
12930
|
+
orderType: params.orderType,
|
|
12931
|
+
triggerType: params.triggerType,
|
|
12932
|
+
operation: OperationType.INCREASE,
|
|
12933
|
+
direction: params.direction,
|
|
12934
|
+
collateralAmount: collateralWithNetworkFee,
|
|
12935
|
+
size: params.size,
|
|
12936
|
+
price: params.price,
|
|
12937
|
+
timeInForce: TIME_IN_FORCE,
|
|
12938
|
+
postOnly: params.postOnly,
|
|
12939
|
+
slippagePct: params.slippagePct,
|
|
12940
|
+
executionFeeToken: params.executionFeeToken,
|
|
12941
|
+
leverage: params.leverage,
|
|
12942
|
+
tpSize: params.tpSize ? params.tpSize : 0,
|
|
12943
|
+
tpPrice: params.tpPrice ? params.tpPrice : 0,
|
|
12944
|
+
slSize: params.slSize ? params.slSize : 0,
|
|
12945
|
+
slPrice: params.slPrice ? params.slPrice : 0,
|
|
12946
|
+
useAccountBalance: false
|
|
12947
|
+
});
|
|
12948
|
+
transaction = await brokerContract.placeOrderWithPosition(
|
|
12949
|
+
params.positionId.toString(),
|
|
12950
|
+
{
|
|
12951
|
+
user: params.address,
|
|
12952
|
+
poolId: params.poolId,
|
|
12953
|
+
orderType: params.orderType,
|
|
12954
|
+
triggerType: params.triggerType,
|
|
12955
|
+
operation: OperationType.INCREASE,
|
|
12956
|
+
direction: params.direction,
|
|
12957
|
+
collateralAmount: collateralWithNetworkFee,
|
|
12958
|
+
size: params.size,
|
|
12959
|
+
price: params.price,
|
|
12960
|
+
timeInForce: TIME_IN_FORCE,
|
|
12961
|
+
postOnly: params.postOnly,
|
|
12962
|
+
slippagePct: params.slippagePct,
|
|
12963
|
+
executionFeeToken: params.executionFeeToken,
|
|
12964
|
+
leverage: params.leverage,
|
|
12965
|
+
tpSize: params.tpSize ? params.tpSize : 0,
|
|
12966
|
+
tpPrice: params.tpPrice ? params.tpPrice : 0,
|
|
12967
|
+
slSize: params.slSize ? params.slSize : 0,
|
|
12968
|
+
slPrice: params.slPrice ? params.slPrice : 0,
|
|
12969
|
+
useAccountBalance: false
|
|
12970
|
+
},
|
|
12971
|
+
{
|
|
12972
|
+
gasLimit: gasLimit * 120n / 100n
|
|
12973
|
+
}
|
|
12974
|
+
);
|
|
12975
|
+
}
|
|
12912
12976
|
const receipt = await transaction.wait();
|
|
12913
12977
|
this.logger.info("createIncreaseOrder receipt--->", receipt);
|
|
12914
12978
|
const orderId = this.utils.getOrderIdFromTransaction(receipt);
|
|
@@ -12972,7 +13036,7 @@ var Order = class {
|
|
|
12972
13036
|
executionFeeToken: params.executionFeeToken,
|
|
12973
13037
|
leverage: params.leverage
|
|
12974
13038
|
});
|
|
12975
|
-
const
|
|
13039
|
+
const data = {
|
|
12976
13040
|
user: params.address,
|
|
12977
13041
|
poolId: params.poolId,
|
|
12978
13042
|
orderType: params.orderType,
|
|
@@ -12992,10 +13056,12 @@ var Order = class {
|
|
|
12992
13056
|
slSize: 0,
|
|
12993
13057
|
slPrice: 0,
|
|
12994
13058
|
useAccountBalance: false
|
|
12995
|
-
}
|
|
12996
|
-
|
|
12997
|
-
|
|
12998
|
-
|
|
13059
|
+
};
|
|
13060
|
+
let transaction;
|
|
13061
|
+
if (!params.positionId) {
|
|
13062
|
+
const positionId = await this.createPositionId(params.poolId, params.address, params.direction, BigInt(1));
|
|
13063
|
+
this.logger.info("createDecreaseOrder salt position params--->", { ...data, positionId });
|
|
13064
|
+
const gasLimit = await brokerContract.placeOrderWithPosition.estimateGas(positionId.toString(), {
|
|
12999
13065
|
user: params.address,
|
|
13000
13066
|
poolId: params.poolId,
|
|
13001
13067
|
orderType: params.orderType,
|
|
@@ -13006,7 +13072,7 @@ var Order = class {
|
|
|
13006
13072
|
size: params.size,
|
|
13007
13073
|
price: params.price,
|
|
13008
13074
|
timeInForce: TIME_IN_FORCE,
|
|
13009
|
-
postOnly:
|
|
13075
|
+
postOnly: params.postOnly,
|
|
13010
13076
|
slippagePct: params.slippagePct,
|
|
13011
13077
|
executionFeeToken: params.executionFeeToken,
|
|
13012
13078
|
leverage: params.leverage,
|
|
@@ -13015,11 +13081,85 @@ var Order = class {
|
|
|
13015
13081
|
slSize: 0,
|
|
13016
13082
|
slPrice: 0,
|
|
13017
13083
|
useAccountBalance: false
|
|
13018
|
-
}
|
|
13019
|
-
|
|
13020
|
-
|
|
13021
|
-
|
|
13022
|
-
|
|
13084
|
+
});
|
|
13085
|
+
transaction = await brokerContract.placeOrderWithPosition(
|
|
13086
|
+
params.positionId.toString(),
|
|
13087
|
+
{
|
|
13088
|
+
user: params.address,
|
|
13089
|
+
poolId: params.poolId,
|
|
13090
|
+
orderType: params.orderType,
|
|
13091
|
+
triggerType: params.triggerType,
|
|
13092
|
+
operation: OperationType.DECREASE,
|
|
13093
|
+
direction: params.direction,
|
|
13094
|
+
collateralAmount: collateralWithNetworkFee,
|
|
13095
|
+
size: params.size,
|
|
13096
|
+
price: params.price,
|
|
13097
|
+
timeInForce: TIME_IN_FORCE,
|
|
13098
|
+
postOnly: false,
|
|
13099
|
+
slippagePct: params.slippagePct,
|
|
13100
|
+
executionFeeToken: params.executionFeeToken,
|
|
13101
|
+
leverage: params.leverage,
|
|
13102
|
+
tpSize: 0,
|
|
13103
|
+
tpPrice: 0,
|
|
13104
|
+
slSize: 0,
|
|
13105
|
+
slPrice: 0,
|
|
13106
|
+
useAccountBalance: false
|
|
13107
|
+
},
|
|
13108
|
+
{
|
|
13109
|
+
gasLimit: gasLimit * 130n / 100n
|
|
13110
|
+
}
|
|
13111
|
+
);
|
|
13112
|
+
} else {
|
|
13113
|
+
this.logger.info("createDecreaseOrder nft position params--->", { ...data, positionId: params.positionId });
|
|
13114
|
+
const gasLimit = await brokerContract.placeOrderWithPosition.estimateGas(params.positionId.toString(), {
|
|
13115
|
+
user: params.address,
|
|
13116
|
+
poolId: params.poolId,
|
|
13117
|
+
orderType: params.orderType,
|
|
13118
|
+
triggerType: params.triggerType,
|
|
13119
|
+
operation: OperationType.DECREASE,
|
|
13120
|
+
direction: params.direction,
|
|
13121
|
+
collateralAmount: collateralWithNetworkFee,
|
|
13122
|
+
size: params.size,
|
|
13123
|
+
price: params.price,
|
|
13124
|
+
timeInForce: TIME_IN_FORCE,
|
|
13125
|
+
postOnly: params.postOnly,
|
|
13126
|
+
slippagePct: params.slippagePct,
|
|
13127
|
+
executionFeeToken: params.executionFeeToken,
|
|
13128
|
+
leverage: params.leverage,
|
|
13129
|
+
tpSize: 0,
|
|
13130
|
+
tpPrice: 0,
|
|
13131
|
+
slSize: 0,
|
|
13132
|
+
slPrice: 0,
|
|
13133
|
+
useAccountBalance: false
|
|
13134
|
+
});
|
|
13135
|
+
transaction = await brokerContract.placeOrderWithPosition(
|
|
13136
|
+
params.positionId.toString(),
|
|
13137
|
+
{
|
|
13138
|
+
user: params.address,
|
|
13139
|
+
poolId: params.poolId,
|
|
13140
|
+
orderType: params.orderType,
|
|
13141
|
+
triggerType: params.triggerType,
|
|
13142
|
+
operation: OperationType.DECREASE,
|
|
13143
|
+
direction: params.direction,
|
|
13144
|
+
collateralAmount: collateralWithNetworkFee,
|
|
13145
|
+
size: params.size,
|
|
13146
|
+
price: params.price,
|
|
13147
|
+
timeInForce: TIME_IN_FORCE,
|
|
13148
|
+
postOnly: false,
|
|
13149
|
+
slippagePct: params.slippagePct,
|
|
13150
|
+
executionFeeToken: params.executionFeeToken,
|
|
13151
|
+
leverage: params.leverage,
|
|
13152
|
+
tpSize: 0,
|
|
13153
|
+
tpPrice: 0,
|
|
13154
|
+
slSize: 0,
|
|
13155
|
+
slPrice: 0,
|
|
13156
|
+
useAccountBalance: false
|
|
13157
|
+
},
|
|
13158
|
+
{
|
|
13159
|
+
gasLimit: gasLimit * 130n / 100n
|
|
13160
|
+
}
|
|
13161
|
+
);
|
|
13162
|
+
}
|
|
13023
13163
|
this.logger.info("Transaction sent:", transaction.hash);
|
|
13024
13164
|
this.logger.info("Waiting for confirmation...");
|
|
13025
13165
|
const receipt = await transaction.wait();
|
|
@@ -13112,11 +13252,21 @@ var Order = class {
|
|
|
13112
13252
|
useAccountBalance: false
|
|
13113
13253
|
}
|
|
13114
13254
|
];
|
|
13115
|
-
|
|
13116
|
-
|
|
13117
|
-
|
|
13118
|
-
|
|
13119
|
-
|
|
13255
|
+
let transaction2;
|
|
13256
|
+
if (!params.positionId) {
|
|
13257
|
+
this.logger.info("createPositionTpSlOrder salt position data--->", data2);
|
|
13258
|
+
const positionId = await this.createPositionId(params.poolId, params.address, params.direction, BigInt(1));
|
|
13259
|
+
const gasLimit = await brokerContract.placeOrdersWithSalt.estimateGas([positionId.toString(), positionId.toString()], data2);
|
|
13260
|
+
transaction2 = await brokerContract.placeOrdersWithSalt([positionId.toString(), positionId.toString()], data2, {
|
|
13261
|
+
gasLimit: gasLimit * 120n / 100n
|
|
13262
|
+
});
|
|
13263
|
+
} else {
|
|
13264
|
+
this.logger.info("createPositionTpSlOrder nft position data--->", data2);
|
|
13265
|
+
const gasLimit = await brokerContract.placeOrdersWithPosition.estimateGas([params.positionId.toString(), params.positionId.toString()], data2);
|
|
13266
|
+
transaction2 = await brokerContract.placeOrdersWithPosition([params.positionId.toString(), params.positionId.toString()], data2, {
|
|
13267
|
+
gasLimit: gasLimit * 120n / 100n
|
|
13268
|
+
});
|
|
13269
|
+
}
|
|
13120
13270
|
this.logger.info("Transaction sent:", transaction2.hash);
|
|
13121
13271
|
this.logger.info("Waiting for confirmation...");
|
|
13122
13272
|
const receipt2 = await transaction2.wait();
|
|
@@ -13168,11 +13318,21 @@ var Order = class {
|
|
|
13168
13318
|
slPrice: "0",
|
|
13169
13319
|
useAccountBalance: false
|
|
13170
13320
|
};
|
|
13171
|
-
|
|
13172
|
-
|
|
13173
|
-
|
|
13174
|
-
|
|
13175
|
-
|
|
13321
|
+
let transaction;
|
|
13322
|
+
if (!params.positionId) {
|
|
13323
|
+
this.logger.info("createPositionTpOrSlOrder salt position data--->", data);
|
|
13324
|
+
const positionId = await this.createPositionId(params.poolId, params.address, params.direction, BigInt(1));
|
|
13325
|
+
const gasLimit = await brokerContract.placeOrderWithPosition.estimateGas(params.positionId.toString(), data);
|
|
13326
|
+
transaction = await brokerContract.placeOrderWithPosition(positionId.toString(), data, {
|
|
13327
|
+
gasLimit: gasLimit * 120n / 100n
|
|
13328
|
+
});
|
|
13329
|
+
} else {
|
|
13330
|
+
this.logger.info("createPositionTpOrSlOrder nft position data--->", data);
|
|
13331
|
+
const gasLimit = await brokerContract.placeOrderWithPosition.estimateGas(params.positionId.toString(), data);
|
|
13332
|
+
transaction = await brokerContract.placeOrderWithPosition(params.positionId.toString(), data, {
|
|
13333
|
+
gasLimit: gasLimit * 120n / 100n
|
|
13334
|
+
});
|
|
13335
|
+
}
|
|
13176
13336
|
this.logger.info("Transaction sent:", transaction.hash);
|
|
13177
13337
|
this.logger.info("Waiting for confirmation...");
|
|
13178
13338
|
const receipt = await transaction.wait();
|
|
@@ -13269,7 +13429,6 @@ var Order = class {
|
|
|
13269
13429
|
if (!config.signer) {
|
|
13270
13430
|
throw new MyxSDKError("INVALID_SIGNER" /* InvalidSigner */, "Invalid signer");
|
|
13271
13431
|
}
|
|
13272
|
-
console.log("updateOrderTpSl params", params);
|
|
13273
13432
|
const brokerContract = await getBrokerSingerContract(
|
|
13274
13433
|
config.chainId
|
|
13275
13434
|
);
|
|
@@ -13288,18 +13447,17 @@ var Order = class {
|
|
|
13288
13447
|
paymentType: 0
|
|
13289
13448
|
}
|
|
13290
13449
|
};
|
|
13291
|
-
|
|
13450
|
+
this.logger.info("updateOrderTpSl params", data);
|
|
13292
13451
|
try {
|
|
13293
13452
|
const gasLimit = await brokerContract.updateOrder.estimateGas(data);
|
|
13294
|
-
console.log("gaslimit->", gasLimit);
|
|
13295
13453
|
const request = await brokerContract.updateOrder(data, {
|
|
13296
13454
|
gasLimit: gasLimit * 120n / 100n
|
|
13297
13455
|
});
|
|
13298
13456
|
const receipt = await request?.wait();
|
|
13299
|
-
|
|
13457
|
+
this.logger.info("updateOrderTpSl receipt", receipt);
|
|
13300
13458
|
return receipt;
|
|
13301
13459
|
} catch (error) {
|
|
13302
|
-
|
|
13460
|
+
this.logger.error("Error updating order:", error);
|
|
13303
13461
|
return {
|
|
13304
13462
|
code: -1,
|
|
13305
13463
|
message: "Failed to update order"
|