@myx-trade/sdk 0.1.112 → 0.1.113
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 +10 -5
- package/dist/index.d.ts +10 -5
- package/dist/index.js +84 -139
- package/dist/index.mjs +84 -139
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1435,10 +1435,6 @@ declare class Position {
|
|
|
1435
1435
|
code: number;
|
|
1436
1436
|
data: PositionHistoryItem[];
|
|
1437
1437
|
}>;
|
|
1438
|
-
/**
|
|
1439
|
-
* @desc temp skip eip7702
|
|
1440
|
-
* @todo adjustCollateral 调整保证金
|
|
1441
|
-
*/
|
|
1442
1438
|
adjustCollateral({ poolId, positionId, adjustAmount, quoteToken, poolOracleType, chainId }: {
|
|
1443
1439
|
poolId: string;
|
|
1444
1440
|
positionId: string;
|
|
@@ -1479,7 +1475,8 @@ declare class Account {
|
|
|
1479
1475
|
private configManager;
|
|
1480
1476
|
private logger;
|
|
1481
1477
|
private utils;
|
|
1482
|
-
|
|
1478
|
+
private client;
|
|
1479
|
+
constructor(configManager: ConfigManager, logger: Logger, utils: Utils, client: MyxClient);
|
|
1483
1480
|
getWalletQuoteTokenBalance(address?: string): Promise<{
|
|
1484
1481
|
code: number;
|
|
1485
1482
|
data: any;
|
|
@@ -1510,6 +1507,10 @@ declare class Account {
|
|
|
1510
1507
|
tokenAddress: string;
|
|
1511
1508
|
amount: string;
|
|
1512
1509
|
}): Promise<{
|
|
1510
|
+
code: number;
|
|
1511
|
+
message: string;
|
|
1512
|
+
data: ApiResponse<any>;
|
|
1513
|
+
} | {
|
|
1513
1514
|
code: number;
|
|
1514
1515
|
data: any;
|
|
1515
1516
|
message?: undefined;
|
|
@@ -1523,6 +1524,10 @@ declare class Account {
|
|
|
1523
1524
|
tokenAddress: string;
|
|
1524
1525
|
chainId: number;
|
|
1525
1526
|
}): Promise<{
|
|
1527
|
+
code: number;
|
|
1528
|
+
message: string;
|
|
1529
|
+
data: ApiResponse<any>;
|
|
1530
|
+
} | {
|
|
1526
1531
|
code: number;
|
|
1527
1532
|
data: any;
|
|
1528
1533
|
message?: undefined;
|
package/dist/index.d.ts
CHANGED
|
@@ -1435,10 +1435,6 @@ declare class Position {
|
|
|
1435
1435
|
code: number;
|
|
1436
1436
|
data: PositionHistoryItem[];
|
|
1437
1437
|
}>;
|
|
1438
|
-
/**
|
|
1439
|
-
* @desc temp skip eip7702
|
|
1440
|
-
* @todo adjustCollateral 调整保证金
|
|
1441
|
-
*/
|
|
1442
1438
|
adjustCollateral({ poolId, positionId, adjustAmount, quoteToken, poolOracleType, chainId }: {
|
|
1443
1439
|
poolId: string;
|
|
1444
1440
|
positionId: string;
|
|
@@ -1479,7 +1475,8 @@ declare class Account {
|
|
|
1479
1475
|
private configManager;
|
|
1480
1476
|
private logger;
|
|
1481
1477
|
private utils;
|
|
1482
|
-
|
|
1478
|
+
private client;
|
|
1479
|
+
constructor(configManager: ConfigManager, logger: Logger, utils: Utils, client: MyxClient);
|
|
1483
1480
|
getWalletQuoteTokenBalance(address?: string): Promise<{
|
|
1484
1481
|
code: number;
|
|
1485
1482
|
data: any;
|
|
@@ -1510,6 +1507,10 @@ declare class Account {
|
|
|
1510
1507
|
tokenAddress: string;
|
|
1511
1508
|
amount: string;
|
|
1512
1509
|
}): Promise<{
|
|
1510
|
+
code: number;
|
|
1511
|
+
message: string;
|
|
1512
|
+
data: ApiResponse<any>;
|
|
1513
|
+
} | {
|
|
1513
1514
|
code: number;
|
|
1514
1515
|
data: any;
|
|
1515
1516
|
message?: undefined;
|
|
@@ -1523,6 +1524,10 @@ declare class Account {
|
|
|
1523
1524
|
tokenAddress: string;
|
|
1524
1525
|
chainId: number;
|
|
1525
1526
|
}): Promise<{
|
|
1527
|
+
code: number;
|
|
1528
|
+
message: string;
|
|
1529
|
+
data: ApiResponse<any>;
|
|
1530
|
+
} | {
|
|
1526
1531
|
code: number;
|
|
1527
1532
|
data: any;
|
|
1528
1533
|
message?: undefined;
|
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.113",
|
|
1826
1826
|
private: false,
|
|
1827
1827
|
publishConfig: {
|
|
1828
1828
|
access: "public"
|
|
@@ -14078,127 +14078,6 @@ var Position = class {
|
|
|
14078
14078
|
data: res.data
|
|
14079
14079
|
};
|
|
14080
14080
|
}
|
|
14081
|
-
/**
|
|
14082
|
-
* @desc temp skip eip7702
|
|
14083
|
-
* @todo adjustCollateral 调整保证金
|
|
14084
|
-
*/
|
|
14085
|
-
// async adjustCollateral({ poolId, positionId, adjustAmount }: { poolId: string, positionId: string, adjustAmount: string }) {
|
|
14086
|
-
// const config: MyxClientConfig = this.configManager.getConfig();
|
|
14087
|
-
// console.log("adjustCollateral-->", { poolId, positionId, adjustAmount })
|
|
14088
|
-
// try {
|
|
14089
|
-
// const oraclePrice = await this.utils.getOraclePrice(poolId);
|
|
14090
|
-
// console.log("oraclePrice-->", oraclePrice);
|
|
14091
|
-
// const eip7702DelegationAddress = getContractAddressByChainId(
|
|
14092
|
-
// config.chainId
|
|
14093
|
-
// ).EIP7702Delegation;
|
|
14094
|
-
// const oracleAddress = getContractAddressByChainId(
|
|
14095
|
-
// config.chainId
|
|
14096
|
-
// ).ORACLE;
|
|
14097
|
-
// const brokerAddress = getContractAddressByChainId(
|
|
14098
|
-
// config.chainId
|
|
14099
|
-
// ).BROKER;
|
|
14100
|
-
// // 获取用户地址
|
|
14101
|
-
// const userAddress = await config.signer.getAddress();
|
|
14102
|
-
// const nonce = await config.signer.getNonce();
|
|
14103
|
-
// // 1️⃣ 构造签名消息
|
|
14104
|
-
// const message = {
|
|
14105
|
-
// chainId: config.chainId,
|
|
14106
|
-
// delegate: eip7702DelegationAddress,
|
|
14107
|
-
// nonce: nonce,
|
|
14108
|
-
// };
|
|
14109
|
-
// const signature = await config.signer.signMessage(JSON.stringify(message));
|
|
14110
|
-
// // 3️⃣ 构造 authorizationList
|
|
14111
|
-
// const sig = signature.slice(2);
|
|
14112
|
-
// const r = `0x${sig.slice(0, 64)}` as `0x${string}`;
|
|
14113
|
-
// const s = `0x${sig.slice(64, 128)}` as `0x${string}`;
|
|
14114
|
-
// const v = parseInt(sig.slice(128, 130), 16);
|
|
14115
|
-
// const authorizationList = [
|
|
14116
|
-
// {
|
|
14117
|
-
// chainId: config.chainId,
|
|
14118
|
-
// address: eip7702DelegationAddress as `0x${string}`,
|
|
14119
|
-
// nonce: Number(nonce),
|
|
14120
|
-
// r,
|
|
14121
|
-
// s,
|
|
14122
|
-
// yParity: v === 27 ? 0 : 1,
|
|
14123
|
-
// }
|
|
14124
|
-
// ];
|
|
14125
|
-
// const oracleContract = new ethers.Contract(
|
|
14126
|
-
// oracleAddress,
|
|
14127
|
-
// oracleAbi,
|
|
14128
|
-
// config.signer
|
|
14129
|
-
// );
|
|
14130
|
-
// const updatePricesGasLimit = await oracleContract.updatePrices.estimateGas([{
|
|
14131
|
-
// poolId: poolId,
|
|
14132
|
-
// referencePrice: ethers.parseUnits(oraclePrice?.price ?? '0', 30),
|
|
14133
|
-
// oracleUpdateData: oraclePrice?.vaa ?? '0',
|
|
14134
|
-
// publishTime: oraclePrice.publishTime,
|
|
14135
|
-
// }], {
|
|
14136
|
-
// value: oraclePrice.value ?? 1n,
|
|
14137
|
-
// });
|
|
14138
|
-
// // 构造更新价格的数据
|
|
14139
|
-
// const updateParams = {
|
|
14140
|
-
// poolId: poolId,
|
|
14141
|
-
// referencePrice: ethers.parseUnits(oraclePrice?.price ?? '0', 30),
|
|
14142
|
-
// oracleUpdateData: oraclePrice?.vaa ?? '0',
|
|
14143
|
-
// publishTime: oraclePrice.publishTime,
|
|
14144
|
-
// }
|
|
14145
|
-
// const updatePriceData = {
|
|
14146
|
-
// target: oracleAddress,
|
|
14147
|
-
// gas: updatePricesGasLimit,
|
|
14148
|
-
// data: encodeFunctionData({
|
|
14149
|
-
// abi: oracleAbi,
|
|
14150
|
-
// functionName: 'updatePrices',
|
|
14151
|
-
// args: [[updateParams]],
|
|
14152
|
-
// }),
|
|
14153
|
-
// value: oraclePrice.value ?? 1n,
|
|
14154
|
-
// }
|
|
14155
|
-
// // 构造调整保证金的数据
|
|
14156
|
-
// const adjustCollateralData = {
|
|
14157
|
-
// target: brokerAddress,
|
|
14158
|
-
// gas: 10000000n,
|
|
14159
|
-
// data: encodeFunctionData({
|
|
14160
|
-
// abi: brokerAbi,
|
|
14161
|
-
// functionName: 'adjustCollateral',
|
|
14162
|
-
// args: [positionId, adjustAmount],
|
|
14163
|
-
// }),
|
|
14164
|
-
// value: '0'
|
|
14165
|
-
// }
|
|
14166
|
-
// // 编码批量执行的数据
|
|
14167
|
-
// const batchExecuteData = encodeFunctionData({
|
|
14168
|
-
// abi: eip7702DelegationAbi,
|
|
14169
|
-
// functionName: 'updatePriceAndBatchExecute',
|
|
14170
|
-
// args: [[updatePriceData, adjustCollateralData]],
|
|
14171
|
-
// });
|
|
14172
|
-
// // 4️⃣ 发送交易
|
|
14173
|
-
// let hash: string;
|
|
14174
|
-
// if (config.walletClient) {
|
|
14175
|
-
// hash = await config.walletClient.sendTransaction({
|
|
14176
|
-
// account: userAddress as `0x${string}`,
|
|
14177
|
-
// to: userAddress as `0x${string}`,
|
|
14178
|
-
// data: batchExecuteData as `0x${string}`,
|
|
14179
|
-
// value: BigInt(oraclePrice?.value ?? 1n),
|
|
14180
|
-
// gas: 10000000n,
|
|
14181
|
-
// authorizationList,
|
|
14182
|
-
// type: 'eip7702',
|
|
14183
|
-
// } as any);
|
|
14184
|
-
// } else {
|
|
14185
|
-
// throw new Error('EIP-7702 交易目前只支持使用 walletClient,请在配置中提供 walletClient');
|
|
14186
|
-
// }
|
|
14187
|
-
// console.log("Transaction hash->", hash);
|
|
14188
|
-
// return {
|
|
14189
|
-
// code: 0,
|
|
14190
|
-
// data: { hash },
|
|
14191
|
-
// message: "调整保证金交易已提交"
|
|
14192
|
-
// };
|
|
14193
|
-
// } catch (error) {
|
|
14194
|
-
// console.log('error-->', error)
|
|
14195
|
-
// return {
|
|
14196
|
-
// code: -1,
|
|
14197
|
-
// // @ts-ignore
|
|
14198
|
-
// message: error?.message,
|
|
14199
|
-
// };
|
|
14200
|
-
// }
|
|
14201
|
-
// }
|
|
14202
14081
|
async adjustCollateral({
|
|
14203
14082
|
poolId,
|
|
14204
14083
|
positionId,
|
|
@@ -14408,8 +14287,6 @@ var Order = class {
|
|
|
14408
14287
|
if (totalBalance > 0) {
|
|
14409
14288
|
depositAmount = depositAmount - totalBalance;
|
|
14410
14289
|
}
|
|
14411
|
-
this.logger.info("params.collateralAmount->", params.collateralAmount);
|
|
14412
|
-
this.logger.info("depositAmount-->", depositAmount);
|
|
14413
14290
|
const depositData = {
|
|
14414
14291
|
token: params.executionFeeToken,
|
|
14415
14292
|
amount: depositAmount > BigInt(0) ? (depositAmount + BigInt(networkFee)).toString() : networkFee
|
|
@@ -21055,11 +20932,13 @@ var Account_default = [
|
|
|
21055
20932
|
];
|
|
21056
20933
|
|
|
21057
20934
|
// src/manager/account/index.ts
|
|
20935
|
+
var import_dayjs2 = __toESM(require("dayjs"));
|
|
21058
20936
|
var Account = class {
|
|
21059
|
-
constructor(configManager, logger, utils) {
|
|
20937
|
+
constructor(configManager, logger, utils, client2) {
|
|
21060
20938
|
this.configManager = configManager;
|
|
21061
20939
|
this.logger = logger;
|
|
21062
20940
|
this.utils = utils;
|
|
20941
|
+
this.client = client2;
|
|
21063
20942
|
}
|
|
21064
20943
|
async getWalletQuoteTokenBalance(address) {
|
|
21065
20944
|
const config = this.configManager.getConfig();
|
|
@@ -21135,12 +21014,45 @@ var Account = class {
|
|
|
21135
21014
|
async withdraw({ chainId, receiver, tokenAddress, amount }) {
|
|
21136
21015
|
const config = this.configManager.getConfig();
|
|
21137
21016
|
const contractAddress = getContractAddressByChainId(chainId);
|
|
21138
|
-
const accountContract = new import_ethers26.ethers.Contract(
|
|
21139
|
-
contractAddress.Account,
|
|
21140
|
-
Account_default,
|
|
21141
|
-
config.signer
|
|
21142
|
-
);
|
|
21143
21017
|
try {
|
|
21018
|
+
const authorized = this.configManager.getConfig().seamlessAccount?.authorized;
|
|
21019
|
+
const seamlessWallet = this.configManager.getConfig().seamlessAccount?.wallet;
|
|
21020
|
+
if (config.seamlessMode && authorized && seamlessWallet) {
|
|
21021
|
+
const isEnoughGas = await this.utils.checkSeamlessGas(receiver);
|
|
21022
|
+
if (!isEnoughGas) {
|
|
21023
|
+
throw new MyxSDKError("INSUFFICIENT_BALANCE" /* InsufficientBalance */, "Insufficient relay fee");
|
|
21024
|
+
}
|
|
21025
|
+
const forwarderContract = await getForwarderContract(chainId);
|
|
21026
|
+
const accountContract2 = new import_ethers26.ethers.Contract(
|
|
21027
|
+
contractAddress.Account,
|
|
21028
|
+
Account_default,
|
|
21029
|
+
seamlessWallet
|
|
21030
|
+
);
|
|
21031
|
+
const functionHash = accountContract2.interface.encodeFunctionData("withdraw", [receiver, tokenAddress, amount]);
|
|
21032
|
+
const nonce = await forwarderContract.nonces(seamlessWallet.address);
|
|
21033
|
+
const forwardTxParams = {
|
|
21034
|
+
from: seamlessWallet.address ?? "",
|
|
21035
|
+
to: this.configManager.getConfig().brokerAddress,
|
|
21036
|
+
value: "0",
|
|
21037
|
+
gas: "350000",
|
|
21038
|
+
deadline: (0, import_dayjs2.default)().add(60, "minute").unix(),
|
|
21039
|
+
data: functionHash,
|
|
21040
|
+
nonce: nonce.toString()
|
|
21041
|
+
};
|
|
21042
|
+
this.logger.info("withdraw forward tx params --->", forwardTxParams);
|
|
21043
|
+
const rs2 = await this.client.seamless.forwarderTx(forwardTxParams, seamlessWallet);
|
|
21044
|
+
console.log("rs-->", rs2);
|
|
21045
|
+
return {
|
|
21046
|
+
code: 0,
|
|
21047
|
+
message: "withdraw success",
|
|
21048
|
+
data: rs2
|
|
21049
|
+
};
|
|
21050
|
+
}
|
|
21051
|
+
const accountContract = new import_ethers26.ethers.Contract(
|
|
21052
|
+
contractAddress.Account,
|
|
21053
|
+
Account_default,
|
|
21054
|
+
config.signer
|
|
21055
|
+
);
|
|
21144
21056
|
const rs = await accountContract.withdraw(receiver, tokenAddress, amount);
|
|
21145
21057
|
const receipt = await rs?.wait(1);
|
|
21146
21058
|
return {
|
|
@@ -21157,12 +21069,7 @@ var Account = class {
|
|
|
21157
21069
|
async deposit({ amount, tokenAddress, chainId }) {
|
|
21158
21070
|
const config = this.configManager.getConfig();
|
|
21159
21071
|
const account = await config.signer?.getAddress() ?? "";
|
|
21160
|
-
const contractAddress = getContractAddressByChainId(
|
|
21161
|
-
const accountContract = new import_ethers26.ethers.Contract(
|
|
21162
|
-
contractAddress.Account,
|
|
21163
|
-
Account_default,
|
|
21164
|
-
config.signer
|
|
21165
|
-
);
|
|
21072
|
+
const contractAddress = getContractAddressByChainId(chainId);
|
|
21166
21073
|
try {
|
|
21167
21074
|
const needApproval = await this.utils.needsApproval(
|
|
21168
21075
|
chainId,
|
|
@@ -21170,6 +21077,39 @@ var Account = class {
|
|
|
21170
21077
|
amount,
|
|
21171
21078
|
contractAddress.Account
|
|
21172
21079
|
);
|
|
21080
|
+
const authorized = this.configManager.getConfig().seamlessAccount?.authorized;
|
|
21081
|
+
const seamlessWallet = this.configManager.getConfig().seamlessAccount?.wallet;
|
|
21082
|
+
if (config.seamlessMode && authorized && seamlessWallet) {
|
|
21083
|
+
const isEnoughGas = await this.utils.checkSeamlessGas(account);
|
|
21084
|
+
if (!isEnoughGas) {
|
|
21085
|
+
throw new MyxSDKError("INSUFFICIENT_BALANCE" /* InsufficientBalance */, "Insufficient relay fee");
|
|
21086
|
+
}
|
|
21087
|
+
const forwarderContract = await getForwarderContract(chainId);
|
|
21088
|
+
const accountContract2 = new import_ethers26.ethers.Contract(
|
|
21089
|
+
contractAddress.Account,
|
|
21090
|
+
Account_default,
|
|
21091
|
+
seamlessWallet
|
|
21092
|
+
);
|
|
21093
|
+
const functionHash = accountContract2.interface.encodeFunctionData("deposit", [account, tokenAddress, amount]);
|
|
21094
|
+
const nonce = await forwarderContract.nonces(seamlessWallet.address);
|
|
21095
|
+
const forwardTxParams = {
|
|
21096
|
+
from: seamlessWallet.address ?? "",
|
|
21097
|
+
to: this.configManager.getConfig().brokerAddress,
|
|
21098
|
+
value: "0",
|
|
21099
|
+
gas: "350000",
|
|
21100
|
+
deadline: (0, import_dayjs2.default)().add(60, "minute").unix(),
|
|
21101
|
+
data: functionHash,
|
|
21102
|
+
nonce: nonce.toString()
|
|
21103
|
+
};
|
|
21104
|
+
this.logger.info("deposit forward tx params --->", forwardTxParams);
|
|
21105
|
+
const rs2 = await this.client.seamless.forwarderTx(forwardTxParams, seamlessWallet);
|
|
21106
|
+
console.log("rs-->", rs2);
|
|
21107
|
+
return {
|
|
21108
|
+
code: 0,
|
|
21109
|
+
message: "deposit success",
|
|
21110
|
+
data: rs2
|
|
21111
|
+
};
|
|
21112
|
+
}
|
|
21173
21113
|
if (needApproval) {
|
|
21174
21114
|
const approvalResult = await this.utils.approveAuthorization({
|
|
21175
21115
|
chainId,
|
|
@@ -21181,6 +21121,11 @@ var Account = class {
|
|
|
21181
21121
|
throw new Error(approvalResult.message);
|
|
21182
21122
|
}
|
|
21183
21123
|
}
|
|
21124
|
+
const accountContract = new import_ethers26.ethers.Contract(
|
|
21125
|
+
contractAddress.Account,
|
|
21126
|
+
Account_default,
|
|
21127
|
+
config.signer
|
|
21128
|
+
);
|
|
21184
21129
|
const rs = await accountContract.deposit(account, tokenAddress, amount);
|
|
21185
21130
|
const receipt = await rs?.wait(1);
|
|
21186
21131
|
return {
|
|
@@ -21199,7 +21144,7 @@ var Account = class {
|
|
|
21199
21144
|
// src/manager/seamless/index.ts
|
|
21200
21145
|
var import_crypto_js = __toESM(require("crypto-js"));
|
|
21201
21146
|
var import_ethers27 = require("ethers");
|
|
21202
|
-
var
|
|
21147
|
+
var import_dayjs3 = __toESM(require("dayjs"));
|
|
21203
21148
|
|
|
21204
21149
|
// src/utils/index.ts
|
|
21205
21150
|
function getChainDomainConfig(chainId, address) {
|
|
@@ -21472,7 +21417,7 @@ var Seamless = class {
|
|
|
21472
21417
|
throw new MyxSDKError("INSUFFICIENT_BALANCE" /* InsufficientBalance */, "Insufficient balance");
|
|
21473
21418
|
}
|
|
21474
21419
|
}
|
|
21475
|
-
const deadline = (0,
|
|
21420
|
+
const deadline = (0, import_dayjs3.default)().add(60, "minute").unix();
|
|
21476
21421
|
let permitParams = [];
|
|
21477
21422
|
if (approve2) {
|
|
21478
21423
|
try {
|
|
@@ -21694,7 +21639,7 @@ var MyxClient = class {
|
|
|
21694
21639
|
logLevel: options.logLevel
|
|
21695
21640
|
});
|
|
21696
21641
|
this.utils = new Utils(this.configManager, this.logger);
|
|
21697
|
-
this.account = new Account(this.configManager, this.logger, this.utils);
|
|
21642
|
+
this.account = new Account(this.configManager, this.logger, this.utils, this);
|
|
21698
21643
|
this.seamless = new Seamless(this.configManager, this.logger, this.utils, this.account);
|
|
21699
21644
|
this.markets = new Markets(this.configManager, this.utils);
|
|
21700
21645
|
this.position = new Position(this.configManager, this.logger, this.utils);
|
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.113",
|
|
1736
1736
|
private: false,
|
|
1737
1737
|
publishConfig: {
|
|
1738
1738
|
access: "public"
|
|
@@ -13988,127 +13988,6 @@ var Position = class {
|
|
|
13988
13988
|
data: res.data
|
|
13989
13989
|
};
|
|
13990
13990
|
}
|
|
13991
|
-
/**
|
|
13992
|
-
* @desc temp skip eip7702
|
|
13993
|
-
* @todo adjustCollateral 调整保证金
|
|
13994
|
-
*/
|
|
13995
|
-
// async adjustCollateral({ poolId, positionId, adjustAmount }: { poolId: string, positionId: string, adjustAmount: string }) {
|
|
13996
|
-
// const config: MyxClientConfig = this.configManager.getConfig();
|
|
13997
|
-
// console.log("adjustCollateral-->", { poolId, positionId, adjustAmount })
|
|
13998
|
-
// try {
|
|
13999
|
-
// const oraclePrice = await this.utils.getOraclePrice(poolId);
|
|
14000
|
-
// console.log("oraclePrice-->", oraclePrice);
|
|
14001
|
-
// const eip7702DelegationAddress = getContractAddressByChainId(
|
|
14002
|
-
// config.chainId
|
|
14003
|
-
// ).EIP7702Delegation;
|
|
14004
|
-
// const oracleAddress = getContractAddressByChainId(
|
|
14005
|
-
// config.chainId
|
|
14006
|
-
// ).ORACLE;
|
|
14007
|
-
// const brokerAddress = getContractAddressByChainId(
|
|
14008
|
-
// config.chainId
|
|
14009
|
-
// ).BROKER;
|
|
14010
|
-
// // 获取用户地址
|
|
14011
|
-
// const userAddress = await config.signer.getAddress();
|
|
14012
|
-
// const nonce = await config.signer.getNonce();
|
|
14013
|
-
// // 1️⃣ 构造签名消息
|
|
14014
|
-
// const message = {
|
|
14015
|
-
// chainId: config.chainId,
|
|
14016
|
-
// delegate: eip7702DelegationAddress,
|
|
14017
|
-
// nonce: nonce,
|
|
14018
|
-
// };
|
|
14019
|
-
// const signature = await config.signer.signMessage(JSON.stringify(message));
|
|
14020
|
-
// // 3️⃣ 构造 authorizationList
|
|
14021
|
-
// const sig = signature.slice(2);
|
|
14022
|
-
// const r = `0x${sig.slice(0, 64)}` as `0x${string}`;
|
|
14023
|
-
// const s = `0x${sig.slice(64, 128)}` as `0x${string}`;
|
|
14024
|
-
// const v = parseInt(sig.slice(128, 130), 16);
|
|
14025
|
-
// const authorizationList = [
|
|
14026
|
-
// {
|
|
14027
|
-
// chainId: config.chainId,
|
|
14028
|
-
// address: eip7702DelegationAddress as `0x${string}`,
|
|
14029
|
-
// nonce: Number(nonce),
|
|
14030
|
-
// r,
|
|
14031
|
-
// s,
|
|
14032
|
-
// yParity: v === 27 ? 0 : 1,
|
|
14033
|
-
// }
|
|
14034
|
-
// ];
|
|
14035
|
-
// const oracleContract = new ethers.Contract(
|
|
14036
|
-
// oracleAddress,
|
|
14037
|
-
// oracleAbi,
|
|
14038
|
-
// config.signer
|
|
14039
|
-
// );
|
|
14040
|
-
// const updatePricesGasLimit = await oracleContract.updatePrices.estimateGas([{
|
|
14041
|
-
// poolId: poolId,
|
|
14042
|
-
// referencePrice: ethers.parseUnits(oraclePrice?.price ?? '0', 30),
|
|
14043
|
-
// oracleUpdateData: oraclePrice?.vaa ?? '0',
|
|
14044
|
-
// publishTime: oraclePrice.publishTime,
|
|
14045
|
-
// }], {
|
|
14046
|
-
// value: oraclePrice.value ?? 1n,
|
|
14047
|
-
// });
|
|
14048
|
-
// // 构造更新价格的数据
|
|
14049
|
-
// const updateParams = {
|
|
14050
|
-
// poolId: poolId,
|
|
14051
|
-
// referencePrice: ethers.parseUnits(oraclePrice?.price ?? '0', 30),
|
|
14052
|
-
// oracleUpdateData: oraclePrice?.vaa ?? '0',
|
|
14053
|
-
// publishTime: oraclePrice.publishTime,
|
|
14054
|
-
// }
|
|
14055
|
-
// const updatePriceData = {
|
|
14056
|
-
// target: oracleAddress,
|
|
14057
|
-
// gas: updatePricesGasLimit,
|
|
14058
|
-
// data: encodeFunctionData({
|
|
14059
|
-
// abi: oracleAbi,
|
|
14060
|
-
// functionName: 'updatePrices',
|
|
14061
|
-
// args: [[updateParams]],
|
|
14062
|
-
// }),
|
|
14063
|
-
// value: oraclePrice.value ?? 1n,
|
|
14064
|
-
// }
|
|
14065
|
-
// // 构造调整保证金的数据
|
|
14066
|
-
// const adjustCollateralData = {
|
|
14067
|
-
// target: brokerAddress,
|
|
14068
|
-
// gas: 10000000n,
|
|
14069
|
-
// data: encodeFunctionData({
|
|
14070
|
-
// abi: brokerAbi,
|
|
14071
|
-
// functionName: 'adjustCollateral',
|
|
14072
|
-
// args: [positionId, adjustAmount],
|
|
14073
|
-
// }),
|
|
14074
|
-
// value: '0'
|
|
14075
|
-
// }
|
|
14076
|
-
// // 编码批量执行的数据
|
|
14077
|
-
// const batchExecuteData = encodeFunctionData({
|
|
14078
|
-
// abi: eip7702DelegationAbi,
|
|
14079
|
-
// functionName: 'updatePriceAndBatchExecute',
|
|
14080
|
-
// args: [[updatePriceData, adjustCollateralData]],
|
|
14081
|
-
// });
|
|
14082
|
-
// // 4️⃣ 发送交易
|
|
14083
|
-
// let hash: string;
|
|
14084
|
-
// if (config.walletClient) {
|
|
14085
|
-
// hash = await config.walletClient.sendTransaction({
|
|
14086
|
-
// account: userAddress as `0x${string}`,
|
|
14087
|
-
// to: userAddress as `0x${string}`,
|
|
14088
|
-
// data: batchExecuteData as `0x${string}`,
|
|
14089
|
-
// value: BigInt(oraclePrice?.value ?? 1n),
|
|
14090
|
-
// gas: 10000000n,
|
|
14091
|
-
// authorizationList,
|
|
14092
|
-
// type: 'eip7702',
|
|
14093
|
-
// } as any);
|
|
14094
|
-
// } else {
|
|
14095
|
-
// throw new Error('EIP-7702 交易目前只支持使用 walletClient,请在配置中提供 walletClient');
|
|
14096
|
-
// }
|
|
14097
|
-
// console.log("Transaction hash->", hash);
|
|
14098
|
-
// return {
|
|
14099
|
-
// code: 0,
|
|
14100
|
-
// data: { hash },
|
|
14101
|
-
// message: "调整保证金交易已提交"
|
|
14102
|
-
// };
|
|
14103
|
-
// } catch (error) {
|
|
14104
|
-
// console.log('error-->', error)
|
|
14105
|
-
// return {
|
|
14106
|
-
// code: -1,
|
|
14107
|
-
// // @ts-ignore
|
|
14108
|
-
// message: error?.message,
|
|
14109
|
-
// };
|
|
14110
|
-
// }
|
|
14111
|
-
// }
|
|
14112
13991
|
async adjustCollateral({
|
|
14113
13992
|
poolId,
|
|
14114
13993
|
positionId,
|
|
@@ -14318,8 +14197,6 @@ var Order = class {
|
|
|
14318
14197
|
if (totalBalance > 0) {
|
|
14319
14198
|
depositAmount = depositAmount - totalBalance;
|
|
14320
14199
|
}
|
|
14321
|
-
this.logger.info("params.collateralAmount->", params.collateralAmount);
|
|
14322
|
-
this.logger.info("depositAmount-->", depositAmount);
|
|
14323
14200
|
const depositData = {
|
|
14324
14201
|
token: params.executionFeeToken,
|
|
14325
14202
|
amount: depositAmount > BigInt(0) ? (depositAmount + BigInt(networkFee)).toString() : networkFee
|
|
@@ -20965,11 +20842,13 @@ var Account_default = [
|
|
|
20965
20842
|
];
|
|
20966
20843
|
|
|
20967
20844
|
// src/manager/account/index.ts
|
|
20845
|
+
import dayjs2 from "dayjs";
|
|
20968
20846
|
var Account = class {
|
|
20969
|
-
constructor(configManager, logger, utils) {
|
|
20847
|
+
constructor(configManager, logger, utils, client2) {
|
|
20970
20848
|
this.configManager = configManager;
|
|
20971
20849
|
this.logger = logger;
|
|
20972
20850
|
this.utils = utils;
|
|
20851
|
+
this.client = client2;
|
|
20973
20852
|
}
|
|
20974
20853
|
async getWalletQuoteTokenBalance(address) {
|
|
20975
20854
|
const config = this.configManager.getConfig();
|
|
@@ -21045,12 +20924,45 @@ var Account = class {
|
|
|
21045
20924
|
async withdraw({ chainId, receiver, tokenAddress, amount }) {
|
|
21046
20925
|
const config = this.configManager.getConfig();
|
|
21047
20926
|
const contractAddress = getContractAddressByChainId(chainId);
|
|
21048
|
-
const accountContract = new ethers8.Contract(
|
|
21049
|
-
contractAddress.Account,
|
|
21050
|
-
Account_default,
|
|
21051
|
-
config.signer
|
|
21052
|
-
);
|
|
21053
20927
|
try {
|
|
20928
|
+
const authorized = this.configManager.getConfig().seamlessAccount?.authorized;
|
|
20929
|
+
const seamlessWallet = this.configManager.getConfig().seamlessAccount?.wallet;
|
|
20930
|
+
if (config.seamlessMode && authorized && seamlessWallet) {
|
|
20931
|
+
const isEnoughGas = await this.utils.checkSeamlessGas(receiver);
|
|
20932
|
+
if (!isEnoughGas) {
|
|
20933
|
+
throw new MyxSDKError("INSUFFICIENT_BALANCE" /* InsufficientBalance */, "Insufficient relay fee");
|
|
20934
|
+
}
|
|
20935
|
+
const forwarderContract = await getForwarderContract(chainId);
|
|
20936
|
+
const accountContract2 = new ethers8.Contract(
|
|
20937
|
+
contractAddress.Account,
|
|
20938
|
+
Account_default,
|
|
20939
|
+
seamlessWallet
|
|
20940
|
+
);
|
|
20941
|
+
const functionHash = accountContract2.interface.encodeFunctionData("withdraw", [receiver, tokenAddress, amount]);
|
|
20942
|
+
const nonce = await forwarderContract.nonces(seamlessWallet.address);
|
|
20943
|
+
const forwardTxParams = {
|
|
20944
|
+
from: seamlessWallet.address ?? "",
|
|
20945
|
+
to: this.configManager.getConfig().brokerAddress,
|
|
20946
|
+
value: "0",
|
|
20947
|
+
gas: "350000",
|
|
20948
|
+
deadline: dayjs2().add(60, "minute").unix(),
|
|
20949
|
+
data: functionHash,
|
|
20950
|
+
nonce: nonce.toString()
|
|
20951
|
+
};
|
|
20952
|
+
this.logger.info("withdraw forward tx params --->", forwardTxParams);
|
|
20953
|
+
const rs2 = await this.client.seamless.forwarderTx(forwardTxParams, seamlessWallet);
|
|
20954
|
+
console.log("rs-->", rs2);
|
|
20955
|
+
return {
|
|
20956
|
+
code: 0,
|
|
20957
|
+
message: "withdraw success",
|
|
20958
|
+
data: rs2
|
|
20959
|
+
};
|
|
20960
|
+
}
|
|
20961
|
+
const accountContract = new ethers8.Contract(
|
|
20962
|
+
contractAddress.Account,
|
|
20963
|
+
Account_default,
|
|
20964
|
+
config.signer
|
|
20965
|
+
);
|
|
21054
20966
|
const rs = await accountContract.withdraw(receiver, tokenAddress, amount);
|
|
21055
20967
|
const receipt = await rs?.wait(1);
|
|
21056
20968
|
return {
|
|
@@ -21067,12 +20979,7 @@ var Account = class {
|
|
|
21067
20979
|
async deposit({ amount, tokenAddress, chainId }) {
|
|
21068
20980
|
const config = this.configManager.getConfig();
|
|
21069
20981
|
const account = await config.signer?.getAddress() ?? "";
|
|
21070
|
-
const contractAddress = getContractAddressByChainId(
|
|
21071
|
-
const accountContract = new ethers8.Contract(
|
|
21072
|
-
contractAddress.Account,
|
|
21073
|
-
Account_default,
|
|
21074
|
-
config.signer
|
|
21075
|
-
);
|
|
20982
|
+
const contractAddress = getContractAddressByChainId(chainId);
|
|
21076
20983
|
try {
|
|
21077
20984
|
const needApproval = await this.utils.needsApproval(
|
|
21078
20985
|
chainId,
|
|
@@ -21080,6 +20987,39 @@ var Account = class {
|
|
|
21080
20987
|
amount,
|
|
21081
20988
|
contractAddress.Account
|
|
21082
20989
|
);
|
|
20990
|
+
const authorized = this.configManager.getConfig().seamlessAccount?.authorized;
|
|
20991
|
+
const seamlessWallet = this.configManager.getConfig().seamlessAccount?.wallet;
|
|
20992
|
+
if (config.seamlessMode && authorized && seamlessWallet) {
|
|
20993
|
+
const isEnoughGas = await this.utils.checkSeamlessGas(account);
|
|
20994
|
+
if (!isEnoughGas) {
|
|
20995
|
+
throw new MyxSDKError("INSUFFICIENT_BALANCE" /* InsufficientBalance */, "Insufficient relay fee");
|
|
20996
|
+
}
|
|
20997
|
+
const forwarderContract = await getForwarderContract(chainId);
|
|
20998
|
+
const accountContract2 = new ethers8.Contract(
|
|
20999
|
+
contractAddress.Account,
|
|
21000
|
+
Account_default,
|
|
21001
|
+
seamlessWallet
|
|
21002
|
+
);
|
|
21003
|
+
const functionHash = accountContract2.interface.encodeFunctionData("deposit", [account, tokenAddress, amount]);
|
|
21004
|
+
const nonce = await forwarderContract.nonces(seamlessWallet.address);
|
|
21005
|
+
const forwardTxParams = {
|
|
21006
|
+
from: seamlessWallet.address ?? "",
|
|
21007
|
+
to: this.configManager.getConfig().brokerAddress,
|
|
21008
|
+
value: "0",
|
|
21009
|
+
gas: "350000",
|
|
21010
|
+
deadline: dayjs2().add(60, "minute").unix(),
|
|
21011
|
+
data: functionHash,
|
|
21012
|
+
nonce: nonce.toString()
|
|
21013
|
+
};
|
|
21014
|
+
this.logger.info("deposit forward tx params --->", forwardTxParams);
|
|
21015
|
+
const rs2 = await this.client.seamless.forwarderTx(forwardTxParams, seamlessWallet);
|
|
21016
|
+
console.log("rs-->", rs2);
|
|
21017
|
+
return {
|
|
21018
|
+
code: 0,
|
|
21019
|
+
message: "deposit success",
|
|
21020
|
+
data: rs2
|
|
21021
|
+
};
|
|
21022
|
+
}
|
|
21083
21023
|
if (needApproval) {
|
|
21084
21024
|
const approvalResult = await this.utils.approveAuthorization({
|
|
21085
21025
|
chainId,
|
|
@@ -21091,6 +21031,11 @@ var Account = class {
|
|
|
21091
21031
|
throw new Error(approvalResult.message);
|
|
21092
21032
|
}
|
|
21093
21033
|
}
|
|
21034
|
+
const accountContract = new ethers8.Contract(
|
|
21035
|
+
contractAddress.Account,
|
|
21036
|
+
Account_default,
|
|
21037
|
+
config.signer
|
|
21038
|
+
);
|
|
21094
21039
|
const rs = await accountContract.deposit(account, tokenAddress, amount);
|
|
21095
21040
|
const receipt = await rs?.wait(1);
|
|
21096
21041
|
return {
|
|
@@ -21109,7 +21054,7 @@ var Account = class {
|
|
|
21109
21054
|
// src/manager/seamless/index.ts
|
|
21110
21055
|
import CryptoJS from "crypto-js";
|
|
21111
21056
|
import { toUtf8Bytes, keccak256, hexlify, ethers as ethers9, isHexString, getBytes, ZeroAddress as ZeroAddress2 } from "ethers";
|
|
21112
|
-
import
|
|
21057
|
+
import dayjs3 from "dayjs";
|
|
21113
21058
|
|
|
21114
21059
|
// src/utils/index.ts
|
|
21115
21060
|
function getChainDomainConfig(chainId, address) {
|
|
@@ -21382,7 +21327,7 @@ var Seamless = class {
|
|
|
21382
21327
|
throw new MyxSDKError("INSUFFICIENT_BALANCE" /* InsufficientBalance */, "Insufficient balance");
|
|
21383
21328
|
}
|
|
21384
21329
|
}
|
|
21385
|
-
const deadline =
|
|
21330
|
+
const deadline = dayjs3().add(60, "minute").unix();
|
|
21386
21331
|
let permitParams = [];
|
|
21387
21332
|
if (approve2) {
|
|
21388
21333
|
try {
|
|
@@ -21604,7 +21549,7 @@ var MyxClient = class {
|
|
|
21604
21549
|
logLevel: options.logLevel
|
|
21605
21550
|
});
|
|
21606
21551
|
this.utils = new Utils(this.configManager, this.logger);
|
|
21607
|
-
this.account = new Account(this.configManager, this.logger, this.utils);
|
|
21552
|
+
this.account = new Account(this.configManager, this.logger, this.utils, this);
|
|
21608
21553
|
this.seamless = new Seamless(this.configManager, this.logger, this.utils, this.account);
|
|
21609
21554
|
this.markets = new Markets(this.configManager, this.utils);
|
|
21610
21555
|
this.position = new Position(this.configManager, this.logger, this.utils);
|