@myx-trade/sdk 0.1.192 → 0.1.194
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 +197 -136
- package/dist/index.d.ts +197 -136
- package/dist/index.js +354 -466
- package/dist/index.mjs +353 -448
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -58,48 +58,31 @@ __export(index_exports, {
|
|
|
58
58
|
TradeFlowTypeEnum: () => TradeFlowTypeEnum,
|
|
59
59
|
TriggerType: () => TriggerType2,
|
|
60
60
|
TriggerTypeEnum: () => TriggerTypeEnum,
|
|
61
|
-
addFavorite: () => addFavorite,
|
|
62
61
|
approve: () => approve,
|
|
63
62
|
base: () => base_exports,
|
|
64
63
|
bigintAmountSlipperCalculator: () => bigintAmountSlipperCalculator,
|
|
65
64
|
bigintTradingGasPriceWithRatio: () => bigintTradingGasPriceWithRatio,
|
|
66
65
|
bigintTradingGasToRatioCalculator: () => bigintTradingGasToRatioCalculator,
|
|
67
|
-
fetchForwarderGetApi: () => fetchForwarderGetApi,
|
|
68
66
|
formatUnits: () => import_ethers22.formatUnits,
|
|
69
|
-
forwarderTxApi: () => forwarderTxApi,
|
|
70
|
-
getAllTickers: () => getAllTickers,
|
|
71
67
|
getAllowanceApproved: () => getAllowanceApproved,
|
|
72
68
|
getBalanceOf: () => getBalanceOf,
|
|
73
69
|
getBaseDetail: () => getBaseDetail,
|
|
74
70
|
getBaseUrlByEnv: () => getBaseUrlByEnv,
|
|
75
|
-
getFavoritesList: () => getFavoritesList,
|
|
76
71
|
getForwardUrlByEnv: () => getForwardUrlByEnv,
|
|
77
|
-
getHistoryOrders: () => getHistoryOrders,
|
|
78
|
-
getKlineData: () => getKlineData,
|
|
79
|
-
getKlineLatestBar: () => getKlineLatestBar,
|
|
80
72
|
getMarketDetail: () => getMarketDetail,
|
|
81
73
|
getMarketList: () => getMarketList,
|
|
82
74
|
getOraclePrice: () => getOraclePrice,
|
|
83
|
-
getOrders: () => getOrders,
|
|
84
75
|
getPoolDetail: () => getPoolDetail,
|
|
85
|
-
getPoolLevelConfig: () => getPoolLevelConfig,
|
|
86
76
|
getPoolList: () => getPoolList,
|
|
87
77
|
getPoolOpenOrders: () => getPoolOpenOrders,
|
|
88
|
-
getPoolSymbolAll: () => getPoolSymbolAll,
|
|
89
|
-
getPositionHistory: () => getPositionHistory,
|
|
90
|
-
getPositions: () => getPositions,
|
|
91
78
|
getPriceData: () => getPriceData,
|
|
92
79
|
getPricesData: () => getPricesData,
|
|
93
80
|
getTickerData: () => getTickerData,
|
|
94
81
|
getTokenInfo: () => getTokenInfo,
|
|
95
|
-
getTradeFlow: () => getTradeFlow,
|
|
96
82
|
market: () => market_exports,
|
|
97
83
|
parseUnits: () => import_ethers22.parseUnits,
|
|
98
84
|
pool: () => pool_exports,
|
|
99
|
-
quote: () => quote_exports
|
|
100
|
-
removeFavorite: () => removeFavorite,
|
|
101
|
-
searchMarket: () => searchMarket,
|
|
102
|
-
searchMarketAuth: () => searchMarketAuth
|
|
85
|
+
quote: () => quote_exports
|
|
103
86
|
});
|
|
104
87
|
module.exports = __toCommonJS(index_exports);
|
|
105
88
|
|
|
@@ -1824,7 +1807,7 @@ var RotationProvider = class extends import_providers.BaseProvider {
|
|
|
1824
1807
|
// package.json
|
|
1825
1808
|
var package_default = {
|
|
1826
1809
|
name: "@myx-trade/sdk",
|
|
1827
|
-
version: "0.1.
|
|
1810
|
+
version: "0.1.194",
|
|
1828
1811
|
private: false,
|
|
1829
1812
|
publishConfig: {
|
|
1830
1813
|
access: "public"
|
|
@@ -1940,28 +1923,6 @@ var http = {
|
|
|
1940
1923
|
}
|
|
1941
1924
|
};
|
|
1942
1925
|
|
|
1943
|
-
// src/api/utils.ts
|
|
1944
|
-
function encodeQueryParam(key, value) {
|
|
1945
|
-
const encodedKey = encodeURIComponent(key);
|
|
1946
|
-
return `${encodedKey}=${encodeURIComponent(typeof value === "number" ? value : `${value}`)}`;
|
|
1947
|
-
}
|
|
1948
|
-
function addQueryParam(query, key) {
|
|
1949
|
-
return encodeQueryParam(key, query[key]);
|
|
1950
|
-
}
|
|
1951
|
-
function addArrayQueryParam(query, key) {
|
|
1952
|
-
const value = query[key];
|
|
1953
|
-
return value.map((v) => encodeQueryParam(key, v)).join("&");
|
|
1954
|
-
}
|
|
1955
|
-
function toQueryString(rawQuery) {
|
|
1956
|
-
const query = rawQuery || {};
|
|
1957
|
-
const keys = Object.keys(query).filter((key) => "undefined" !== typeof query[key]);
|
|
1958
|
-
return keys.map((key) => Array.isArray(query[key]) ? addArrayQueryParam(query, key) : addQueryParam(query, key)).join("&");
|
|
1959
|
-
}
|
|
1960
|
-
function addQueryParams(rawQuery) {
|
|
1961
|
-
const queryString = toQueryString(rawQuery);
|
|
1962
|
-
return queryString ? `?${queryString}` : "";
|
|
1963
|
-
}
|
|
1964
|
-
|
|
1965
1926
|
// src/api/type.ts
|
|
1966
1927
|
var ErrorCode = /* @__PURE__ */ ((ErrorCode3) => {
|
|
1967
1928
|
ErrorCode3[ErrorCode3["SUCCESS"] = 9200] = "SUCCESS";
|
|
@@ -1984,10 +1945,10 @@ var MarketPoolState = /* @__PURE__ */ ((MarketPoolState3) => {
|
|
|
1984
1945
|
MarketPoolState3[MarketPoolState3["Bench"] = 4] = "Bench";
|
|
1985
1946
|
return MarketPoolState3;
|
|
1986
1947
|
})(MarketPoolState || {});
|
|
1987
|
-
var OracleType = /* @__PURE__ */ ((
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
return
|
|
1948
|
+
var OracleType = /* @__PURE__ */ ((OracleType6) => {
|
|
1949
|
+
OracleType6[OracleType6["Chainlink"] = 1] = "Chainlink";
|
|
1950
|
+
OracleType6[OracleType6["Pyth"] = 2] = "Pyth";
|
|
1951
|
+
return OracleType6;
|
|
1991
1952
|
})(OracleType || {});
|
|
1992
1953
|
var HttpKlineIntervalEnum = /* @__PURE__ */ ((HttpKlineIntervalEnum2) => {
|
|
1993
1954
|
HttpKlineIntervalEnum2[HttpKlineIntervalEnum2["Minute1"] = 1] = "Minute1";
|
|
@@ -2086,23 +2047,6 @@ var ExecTypeEnum = /* @__PURE__ */ ((ExecTypeEnum2) => {
|
|
|
2086
2047
|
ExecTypeEnum2[ExecTypeEnum2["MarketClose"] = 9] = "MarketClose";
|
|
2087
2048
|
return ExecTypeEnum2;
|
|
2088
2049
|
})(ExecTypeEnum || {});
|
|
2089
|
-
var getHistoryOrders = async ({
|
|
2090
|
-
accessToken,
|
|
2091
|
-
address,
|
|
2092
|
-
...params
|
|
2093
|
-
}, envParams) => {
|
|
2094
|
-
const isProd = envParams?.isProd ?? true;
|
|
2095
|
-
return http.get(
|
|
2096
|
-
`${getBaseUrlByEnv(isProd)}/openapi/gateway/scan/order/closed`,
|
|
2097
|
-
params,
|
|
2098
|
-
{
|
|
2099
|
-
headers: {
|
|
2100
|
-
myx_openapi_account: address,
|
|
2101
|
-
myx_openapi_access_token: accessToken
|
|
2102
|
-
}
|
|
2103
|
-
}
|
|
2104
|
-
);
|
|
2105
|
-
};
|
|
2106
2050
|
var CloseTypeEnum = /* @__PURE__ */ ((CloseTypeEnum2) => {
|
|
2107
2051
|
CloseTypeEnum2[CloseTypeEnum2["Open"] = 0] = "Open";
|
|
2108
2052
|
CloseTypeEnum2[CloseTypeEnum2["PartialClose"] = 1] = "PartialClose";
|
|
@@ -2116,59 +2060,14 @@ var CloseTypeEnum = /* @__PURE__ */ ((CloseTypeEnum2) => {
|
|
|
2116
2060
|
CloseTypeEnum2[CloseTypeEnum2["Increase"] = 9] = "Increase";
|
|
2117
2061
|
return CloseTypeEnum2;
|
|
2118
2062
|
})(CloseTypeEnum || {});
|
|
2119
|
-
var getPositionHistory = async ({
|
|
2120
|
-
accessToken,
|
|
2121
|
-
address,
|
|
2122
|
-
...params
|
|
2123
|
-
}, envParams) => {
|
|
2124
|
-
const isProd = envParams?.isProd ?? true;
|
|
2125
|
-
return http.get(
|
|
2126
|
-
`${getBaseUrlByEnv(isProd)}/openapi/gateway/scan/position/closed`,
|
|
2127
|
-
params,
|
|
2128
|
-
{
|
|
2129
|
-
headers: {
|
|
2130
|
-
myx_openapi_account: address,
|
|
2131
|
-
myx_openapi_access_token: accessToken
|
|
2132
|
-
}
|
|
2133
|
-
}
|
|
2134
|
-
);
|
|
2135
|
-
};
|
|
2136
2063
|
var TradeFlowAccountTypeEnum = /* @__PURE__ */ ((TradeFlowAccountTypeEnum2) => {
|
|
2137
2064
|
TradeFlowAccountTypeEnum2[TradeFlowAccountTypeEnum2["MarginAccount"] = 1] = "MarginAccount";
|
|
2138
2065
|
TradeFlowAccountTypeEnum2[TradeFlowAccountTypeEnum2["WalletAccount"] = 2] = "WalletAccount";
|
|
2139
2066
|
TradeFlowAccountTypeEnum2[TradeFlowAccountTypeEnum2["ReferralReward"] = 3] = "ReferralReward";
|
|
2140
2067
|
return TradeFlowAccountTypeEnum2;
|
|
2141
2068
|
})(TradeFlowAccountTypeEnum || {});
|
|
2142
|
-
var getTradeFlow = async ({
|
|
2143
|
-
accessToken,
|
|
2144
|
-
address,
|
|
2145
|
-
...params
|
|
2146
|
-
}, envParams) => {
|
|
2147
|
-
const isProd = envParams?.isProd ?? true;
|
|
2148
|
-
return http.get(
|
|
2149
|
-
`${getBaseUrlByEnv(isProd)}/openapi/gateway/scan/trade/flow`,
|
|
2150
|
-
params,
|
|
2151
|
-
{
|
|
2152
|
-
headers: {
|
|
2153
|
-
myx_openapi_access_token: accessToken,
|
|
2154
|
-
myx_openapi_account: address
|
|
2155
|
-
}
|
|
2156
|
-
}
|
|
2157
|
-
);
|
|
2158
|
-
};
|
|
2159
2069
|
|
|
2160
2070
|
// src/api/seamless/index.ts
|
|
2161
|
-
var forwarderTxApi = async (params, chainId, isProd = true) => {
|
|
2162
|
-
return http.post(
|
|
2163
|
-
`${getForwardUrlByEnv(isProd)}/forwarder/tx-v2`,
|
|
2164
|
-
params,
|
|
2165
|
-
{
|
|
2166
|
-
headers: {
|
|
2167
|
-
"myx-chain-id": chainId.toString()
|
|
2168
|
-
}
|
|
2169
|
-
}
|
|
2170
|
-
);
|
|
2171
|
-
};
|
|
2172
2071
|
var ForwarderGetStatus = /* @__PURE__ */ ((ForwarderGetStatus2) => {
|
|
2173
2072
|
ForwarderGetStatus2[ForwarderGetStatus2["EXECUTING"] = 1] = "EXECUTING";
|
|
2174
2073
|
ForwarderGetStatus2[ForwarderGetStatus2["BROADCAST_FAILED"] = 2] = "BROADCAST_FAILED";
|
|
@@ -2176,40 +2075,26 @@ var ForwarderGetStatus = /* @__PURE__ */ ((ForwarderGetStatus2) => {
|
|
|
2176
2075
|
ForwarderGetStatus2[ForwarderGetStatus2["EXECUTED"] = 9] = "EXECUTED";
|
|
2177
2076
|
return ForwarderGetStatus2;
|
|
2178
2077
|
})(ForwarderGetStatus || {});
|
|
2179
|
-
var fetchForwarderGetApi = async (params, isProd = true) => {
|
|
2180
|
-
const rs = await http.get(
|
|
2181
|
-
`${getForwardUrlByEnv(isProd)}/forwarder/get${addQueryParams(params)}`
|
|
2182
|
-
);
|
|
2183
|
-
return rs;
|
|
2184
|
-
};
|
|
2185
2078
|
|
|
2186
2079
|
// src/api/pool/index.ts
|
|
2187
|
-
var getPoolList = async ({
|
|
2188
|
-
isProd = true
|
|
2189
|
-
}) => {
|
|
2080
|
+
var getPoolList = async () => {
|
|
2190
2081
|
return http.get(
|
|
2191
|
-
`${getBaseUrlByEnv(
|
|
2192
|
-
);
|
|
2193
|
-
};
|
|
2194
|
-
var getPoolSymbolAll = async ({
|
|
2195
|
-
isProd = true
|
|
2196
|
-
}) => {
|
|
2197
|
-
return http.get(
|
|
2198
|
-
`${getBaseUrlByEnv(isProd)}/openapi/gateway/scan/pools`
|
|
2082
|
+
`${getBaseUrlByEnv()}/openapi/gateway/scan/market/list`
|
|
2199
2083
|
);
|
|
2200
2084
|
};
|
|
2201
2085
|
|
|
2202
2086
|
// src/api/index.ts
|
|
2203
2087
|
var getBaseUrlByEnv = (isProd) => {
|
|
2204
|
-
|
|
2088
|
+
const _isProd = !!isProd || !web3_default.getConfigManager()?.getConfig()?.isTestnet;
|
|
2089
|
+
return _isProd ? "https://api.myx.finance" : "https://api-test.myx.cash";
|
|
2205
2090
|
};
|
|
2206
2091
|
var getForwardUrlByEnv = (isProd) => {
|
|
2207
|
-
return isProd
|
|
2092
|
+
return `${getBaseUrlByEnv(isProd)}/v2/agent`;
|
|
2208
2093
|
};
|
|
2209
|
-
var getOraclePrice = async (chainId, poolIds = []
|
|
2094
|
+
var getOraclePrice = async (chainId, poolIds = []) => {
|
|
2210
2095
|
if (!!poolIds.length) {
|
|
2211
2096
|
return http.get(
|
|
2212
|
-
`${getBaseUrlByEnv(
|
|
2097
|
+
`${getBaseUrlByEnv()}/openapi/gateway/quote/price/oracles`,
|
|
2213
2098
|
{
|
|
2214
2099
|
chainId,
|
|
2215
2100
|
poolIds: poolIds.join(",")
|
|
@@ -2218,43 +2103,14 @@ var getOraclePrice = async (chainId, poolIds = [], isProd = true) => {
|
|
|
2218
2103
|
}
|
|
2219
2104
|
return Promise.reject(new Error("Invalid pool id"));
|
|
2220
2105
|
};
|
|
2221
|
-
var
|
|
2222
|
-
poolId,
|
|
2223
|
-
chainId,
|
|
2224
|
-
isProd = true
|
|
2225
|
-
}) => {
|
|
2226
|
-
return http.get(
|
|
2227
|
-
`${getBaseUrlByEnv(
|
|
2228
|
-
isProd
|
|
2229
|
-
)}/openapi/gateway/risk/market_pool/level_config${addQueryParams({
|
|
2230
|
-
poolId,
|
|
2231
|
-
chainId
|
|
2232
|
-
})}`
|
|
2233
|
-
);
|
|
2234
|
-
};
|
|
2235
|
-
var getPoolDetail = async (chainId, poolId, isProd = true) => {
|
|
2236
|
-
return await http.get(
|
|
2237
|
-
`${getBaseUrlByEnv(
|
|
2238
|
-
isProd
|
|
2239
|
-
)}/openapi/gateway/scan/market/info?chainId=${chainId}&poolId=${poolId}`
|
|
2240
|
-
);
|
|
2241
|
-
};
|
|
2242
|
-
var getPositions = async (accessToken, address, isProd = true) => {
|
|
2106
|
+
var getPoolDetail = async (chainId, poolId, isProd) => {
|
|
2243
2107
|
return await http.get(
|
|
2244
|
-
`${getBaseUrlByEnv(isProd)}/openapi/gateway/scan/
|
|
2245
|
-
void 0,
|
|
2246
|
-
// params
|
|
2247
|
-
{
|
|
2248
|
-
headers: {
|
|
2249
|
-
myx_openapi_access_token: accessToken,
|
|
2250
|
-
myx_openapi_account: address
|
|
2251
|
-
}
|
|
2252
|
-
}
|
|
2108
|
+
`${getBaseUrlByEnv(isProd)}/openapi/gateway/scan/market/info?chainId=${chainId}&poolId=${poolId}`
|
|
2253
2109
|
);
|
|
2254
2110
|
};
|
|
2255
|
-
var
|
|
2111
|
+
var getPoolOpenOrders = async (accessToken, address, chainId) => {
|
|
2256
2112
|
return await http.get(
|
|
2257
|
-
`${getBaseUrlByEnv(
|
|
2113
|
+
`${getBaseUrlByEnv()}/openapi/gateway/scan/market/pool-order/open?chainId=${chainId}`,
|
|
2258
2114
|
void 0,
|
|
2259
2115
|
{
|
|
2260
2116
|
headers: {
|
|
@@ -2264,40 +2120,6 @@ var getOrders = async (accessToken, address, isProd = true) => {
|
|
|
2264
2120
|
}
|
|
2265
2121
|
);
|
|
2266
2122
|
};
|
|
2267
|
-
var getPoolOpenOrders = async (accessToken, address, chainId, isProd = true) => {
|
|
2268
|
-
return await http.get(
|
|
2269
|
-
`${getBaseUrlByEnv(
|
|
2270
|
-
isProd
|
|
2271
|
-
)}/openapi/gateway/scan/market/pool-order/open?chainId=${chainId}`,
|
|
2272
|
-
void 0,
|
|
2273
|
-
{
|
|
2274
|
-
headers: {
|
|
2275
|
-
myx_openapi_access_token: accessToken,
|
|
2276
|
-
myx_openapi_account: address
|
|
2277
|
-
}
|
|
2278
|
-
}
|
|
2279
|
-
);
|
|
2280
|
-
};
|
|
2281
|
-
var getKlineData = ({ chainId, poolId, endTime, limit, interval }, envParams) => {
|
|
2282
|
-
const isProd = envParams?.isProd ?? true;
|
|
2283
|
-
return http.get(
|
|
2284
|
-
`${getBaseUrlByEnv(isProd)}/openapi/gateway/quote/candles`,
|
|
2285
|
-
{
|
|
2286
|
-
chainId,
|
|
2287
|
-
poolId,
|
|
2288
|
-
endTime,
|
|
2289
|
-
limit,
|
|
2290
|
-
interval
|
|
2291
|
-
}
|
|
2292
|
-
);
|
|
2293
|
-
};
|
|
2294
|
-
var getKlineLatestBar = async (params, envParams) => {
|
|
2295
|
-
const isProd = envParams?.isProd ?? true;
|
|
2296
|
-
return http.get(
|
|
2297
|
-
`${getBaseUrlByEnv(isProd)}/openapi/gateway/quote/candle/latest`,
|
|
2298
|
-
params
|
|
2299
|
-
);
|
|
2300
|
-
};
|
|
2301
2123
|
var getTickerData = async ({ chainId, poolIds }, envParams) => {
|
|
2302
2124
|
const isProd = envParams?.isProd ?? true;
|
|
2303
2125
|
return http.get(
|
|
@@ -2308,93 +2130,21 @@ var getTickerData = async ({ chainId, poolIds }, envParams) => {
|
|
|
2308
2130
|
}
|
|
2309
2131
|
);
|
|
2310
2132
|
};
|
|
2311
|
-
var
|
|
2312
|
-
const isProd = envParams?.isProd ?? true;
|
|
2313
|
-
return http.get(
|
|
2314
|
-
`${getBaseUrlByEnv(isProd)}/v2/mx-gateway/quote/candle/all_tickers`
|
|
2315
|
-
);
|
|
2316
|
-
};
|
|
2317
|
-
var searchMarketAuth = async ({ accessToken, address, ...params }, envParams) => {
|
|
2318
|
-
const isProd = envParams?.isProd ?? true;
|
|
2319
|
-
return http.get(
|
|
2320
|
-
`${getBaseUrlByEnv(isProd)}/openapi/gateway/scan/market/ac-search`,
|
|
2321
|
-
params,
|
|
2322
|
-
{
|
|
2323
|
-
headers: {
|
|
2324
|
-
myx_openapi_access_token: accessToken,
|
|
2325
|
-
myx_openapi_account: address
|
|
2326
|
-
}
|
|
2327
|
-
}
|
|
2328
|
-
);
|
|
2329
|
-
};
|
|
2330
|
-
var searchMarket = async ({ ...params }, envParams) => {
|
|
2331
|
-
const isProd = envParams?.isProd ?? true;
|
|
2332
|
-
return http.get(
|
|
2333
|
-
`${getBaseUrlByEnv(isProd)}/openapi/gateway/scan/market/search`,
|
|
2334
|
-
params
|
|
2335
|
-
);
|
|
2336
|
-
};
|
|
2337
|
-
var addFavorite = async ({ accessToken, address, ...params }, envParams) => {
|
|
2338
|
-
const isProd = envParams?.isProd ?? true;
|
|
2339
|
-
return http.get(
|
|
2340
|
-
`${getBaseUrlByEnv(isProd)}/openapi/gateway/scan/market/add-favorites`,
|
|
2341
|
-
params,
|
|
2342
|
-
{
|
|
2343
|
-
headers: {
|
|
2344
|
-
myx_openapi_access_token: accessToken,
|
|
2345
|
-
myx_openapi_account: address
|
|
2346
|
-
}
|
|
2347
|
-
}
|
|
2348
|
-
);
|
|
2349
|
-
};
|
|
2350
|
-
var removeFavorite = async ({
|
|
2351
|
-
accessToken,
|
|
2352
|
-
address,
|
|
2353
|
-
...params
|
|
2354
|
-
}, envParams) => {
|
|
2355
|
-
const isProd = envParams?.isProd ?? true;
|
|
2356
|
-
return http.get(
|
|
2357
|
-
`${getBaseUrlByEnv(isProd)}/openapi/gateway/scan/market/cancel-favorites`,
|
|
2358
|
-
params,
|
|
2359
|
-
{
|
|
2360
|
-
headers: {
|
|
2361
|
-
myx_openapi_access_token: accessToken,
|
|
2362
|
-
myx_openapi_account: address
|
|
2363
|
-
}
|
|
2364
|
-
}
|
|
2365
|
-
);
|
|
2366
|
-
};
|
|
2367
|
-
var getFavoritesList = async ({ accessToken, address, ...params }, envParams) => {
|
|
2368
|
-
const isProd = envParams?.isProd ?? true;
|
|
2133
|
+
var getBaseDetail = async ({ ...params }) => {
|
|
2369
2134
|
return http.get(
|
|
2370
|
-
`${getBaseUrlByEnv(
|
|
2371
|
-
params,
|
|
2372
|
-
{
|
|
2373
|
-
headers: {
|
|
2374
|
-
myx_openapi_access_token: accessToken,
|
|
2375
|
-
myx_openapi_account: address
|
|
2376
|
-
}
|
|
2377
|
-
}
|
|
2378
|
-
);
|
|
2379
|
-
};
|
|
2380
|
-
var getBaseDetail = async ({ ...params }, envParams) => {
|
|
2381
|
-
const isProd = envParams?.isProd ?? true;
|
|
2382
|
-
return http.get(
|
|
2383
|
-
`${getBaseUrlByEnv(isProd)}/openapi/gateway/scan/market/base-details`,
|
|
2135
|
+
`${getBaseUrlByEnv()}/openapi/gateway/scan/market/base-details`,
|
|
2384
2136
|
params
|
|
2385
2137
|
);
|
|
2386
2138
|
};
|
|
2387
|
-
var getMarketDetail = async ({ ...params }
|
|
2388
|
-
const isProd = envParams?.isProd ?? true;
|
|
2139
|
+
var getMarketDetail = async ({ ...params }) => {
|
|
2389
2140
|
return http.get(
|
|
2390
|
-
`${getBaseUrlByEnv(
|
|
2141
|
+
`${getBaseUrlByEnv()}/openapi/gateway/scan/market/detail`,
|
|
2391
2142
|
params
|
|
2392
2143
|
);
|
|
2393
2144
|
};
|
|
2394
|
-
var getMarketList = async (
|
|
2395
|
-
const isProd = envParams?.isProd ?? true;
|
|
2145
|
+
var getMarketList = async () => {
|
|
2396
2146
|
return http.get(
|
|
2397
|
-
`${getBaseUrlByEnv(
|
|
2147
|
+
`${getBaseUrlByEnv()}/openapi/gateway/scan/market`
|
|
2398
2148
|
);
|
|
2399
2149
|
};
|
|
2400
2150
|
|
|
@@ -2451,9 +2201,7 @@ var MxSDK = class _MxSDK {
|
|
|
2451
2201
|
}
|
|
2452
2202
|
async getMarkets() {
|
|
2453
2203
|
try {
|
|
2454
|
-
const result = await getMarketList(
|
|
2455
|
-
isProd: !this.configManager?.getConfig()?.isTestnet
|
|
2456
|
-
});
|
|
2204
|
+
const result = await getMarketList();
|
|
2457
2205
|
this.Markets = result?.data || [];
|
|
2458
2206
|
} catch (error) {
|
|
2459
2207
|
throw error;
|
|
@@ -2466,6 +2214,7 @@ if (typeof window !== "undefined") {
|
|
|
2466
2214
|
} else if (typeof globalThis !== "undefined") {
|
|
2467
2215
|
globalThis.MxSDK = sdk;
|
|
2468
2216
|
}
|
|
2217
|
+
var web3_default = sdk;
|
|
2469
2218
|
var getWalletProvider = async (chainId) => {
|
|
2470
2219
|
try {
|
|
2471
2220
|
const walletClient = sdk.getConfigManager()?.getConfig()?.walletClient;
|
|
@@ -12169,9 +11918,9 @@ var getPricesData = async (chainId, poolIds) => {
|
|
|
12169
11918
|
const result = await parsePriceData(chainId, rs.data);
|
|
12170
11919
|
return result;
|
|
12171
11920
|
};
|
|
12172
|
-
var getPriceData = async (chainId, poolId
|
|
11921
|
+
var getPriceData = async (chainId, poolId) => {
|
|
12173
11922
|
if (!poolId) return;
|
|
12174
|
-
const rs = await getOraclePrice(chainId, [poolId]
|
|
11923
|
+
const rs = await getOraclePrice(chainId, [poolId]);
|
|
12175
11924
|
const data = rs?.data?.[0];
|
|
12176
11925
|
if (!data) {
|
|
12177
11926
|
throw new Error(`Unable to get price for ${poolId} in the deposit`);
|
|
@@ -12428,7 +12177,7 @@ var deposit = async (params) => {
|
|
|
12428
12177
|
let value = 0n;
|
|
12429
12178
|
let amountOut;
|
|
12430
12179
|
if (isNeedPrice) {
|
|
12431
|
-
const priceData = await getPriceData(chainId, poolId
|
|
12180
|
+
const priceData = await getPriceData(chainId, poolId);
|
|
12432
12181
|
if (!priceData) return;
|
|
12433
12182
|
const referencePrice = (0, import_ethers10.parseUnits)(priceData.price, COMMON_PRICE_DECIMALS);
|
|
12434
12183
|
price.push({
|
|
@@ -12498,7 +12247,7 @@ var withdraw = async (params) => {
|
|
|
12498
12247
|
let value = 0n;
|
|
12499
12248
|
let amountOut;
|
|
12500
12249
|
if (isNeedPrice) {
|
|
12501
|
-
const priceData = await getPriceData(chainId, poolId
|
|
12250
|
+
const priceData = await getPriceData(chainId, poolId);
|
|
12502
12251
|
if (!priceData) return;
|
|
12503
12252
|
const referencePrice = (0, import_ethers11.parseUnits)(priceData.price, COMMON_PRICE_DECIMALS);
|
|
12504
12253
|
price.push({
|
|
@@ -12570,7 +12319,7 @@ var getLpPrice = async (chainId, poolId) => {
|
|
|
12570
12319
|
try {
|
|
12571
12320
|
const contract = await getBasePoolContract(chainId);
|
|
12572
12321
|
let price = 0n;
|
|
12573
|
-
const res = await getPriceData(chainId, poolId
|
|
12322
|
+
const res = await getPriceData(chainId, poolId);
|
|
12574
12323
|
if (res?.price) {
|
|
12575
12324
|
price = (0, import_ethers13.parseUnits)(res.price, COMMON_PRICE_DECIMALS);
|
|
12576
12325
|
}
|
|
@@ -12662,7 +12411,7 @@ var deposit2 = async (params) => {
|
|
|
12662
12411
|
let value = 0n;
|
|
12663
12412
|
let amountOut;
|
|
12664
12413
|
if (isNeedPrice) {
|
|
12665
|
-
const priceData = await getPriceData(chainId, poolId
|
|
12414
|
+
const priceData = await getPriceData(chainId, poolId);
|
|
12666
12415
|
if (!priceData) return;
|
|
12667
12416
|
const referencePrice = (0, import_ethers14.parseUnits)(priceData.price, COMMON_PRICE_DECIMALS);
|
|
12668
12417
|
price.push({
|
|
@@ -12732,7 +12481,7 @@ var withdraw2 = async (params) => {
|
|
|
12732
12481
|
let value = 0n;
|
|
12733
12482
|
let amountOut;
|
|
12734
12483
|
if (isNeedPrice) {
|
|
12735
|
-
const priceData = await getPriceData(chainId, poolId
|
|
12484
|
+
const priceData = await getPriceData(chainId, poolId);
|
|
12736
12485
|
if (!priceData) return;
|
|
12737
12486
|
const referencePrice = (0, import_ethers15.parseUnits)(priceData.price, COMMON_PRICE_DECIMALS);
|
|
12738
12487
|
price.push({
|
|
@@ -12934,7 +12683,7 @@ var getLpPrice2 = async (chainId, poolId) => {
|
|
|
12934
12683
|
try {
|
|
12935
12684
|
const contract = await getQuotePoolContract(chainId);
|
|
12936
12685
|
let price = 0n;
|
|
12937
|
-
const res = await getPriceData(chainId, poolId
|
|
12686
|
+
const res = await getPriceData(chainId, poolId);
|
|
12938
12687
|
if (res?.price) {
|
|
12939
12688
|
price = (0, import_ethers19.parseUnits)(res.price, COMMON_PRICE_DECIMALS);
|
|
12940
12689
|
}
|
|
@@ -14218,18 +13967,19 @@ var ConfigManager = class {
|
|
|
14218
13967
|
|
|
14219
13968
|
// src/manager/markets/index.ts
|
|
14220
13969
|
var Markets = class {
|
|
14221
|
-
constructor(configManager, utils) {
|
|
13970
|
+
constructor(configManager, utils, api) {
|
|
14222
13971
|
this.configManager = configManager;
|
|
14223
13972
|
this.utils = utils;
|
|
13973
|
+
this.api = api;
|
|
14224
13974
|
}
|
|
14225
13975
|
getMarkets() {
|
|
14226
13976
|
return Promise.resolve([]);
|
|
14227
13977
|
}
|
|
14228
|
-
async getPoolLevelConfig(poolId) {
|
|
13978
|
+
async getPoolLevelConfig(poolId, chainId) {
|
|
14229
13979
|
const config = this.configManager.getConfig();
|
|
14230
|
-
return (await getPoolLevelConfig({
|
|
13980
|
+
return (await this.api.getPoolLevelConfig({
|
|
14231
13981
|
poolId,
|
|
14232
|
-
chainId
|
|
13982
|
+
chainId
|
|
14233
13983
|
})).data;
|
|
14234
13984
|
}
|
|
14235
13985
|
/**
|
|
@@ -14240,13 +13990,10 @@ var Markets = class {
|
|
|
14240
13990
|
...params
|
|
14241
13991
|
}) {
|
|
14242
13992
|
const config = this.configManager.getConfig();
|
|
14243
|
-
return (await getKlineData(
|
|
13993
|
+
return (await this.api.getKlineData(
|
|
14244
13994
|
{
|
|
14245
13995
|
...params,
|
|
14246
13996
|
interval: this.utils.transferKlineResolutionToInterval(interval)
|
|
14247
|
-
},
|
|
14248
|
-
{
|
|
14249
|
-
isProd: !config?.isTestnet
|
|
14250
13997
|
}
|
|
14251
13998
|
)).data;
|
|
14252
13999
|
}
|
|
@@ -14255,13 +14002,10 @@ var Markets = class {
|
|
|
14255
14002
|
...params
|
|
14256
14003
|
}) {
|
|
14257
14004
|
const config = this.configManager.getConfig();
|
|
14258
|
-
return (await getKlineLatestBar(
|
|
14005
|
+
return (await this.api.getKlineLatestBar(
|
|
14259
14006
|
{
|
|
14260
14007
|
...params,
|
|
14261
14008
|
interval: this.utils.transferKlineResolutionToInterval(interval)
|
|
14262
|
-
},
|
|
14263
|
-
{
|
|
14264
|
-
isProd: !config?.isTestnet
|
|
14265
14009
|
}
|
|
14266
14010
|
)).data;
|
|
14267
14011
|
}
|
|
@@ -14272,10 +14016,7 @@ var Markets = class {
|
|
|
14272
14016
|
* ticker start
|
|
14273
14017
|
*/
|
|
14274
14018
|
async getTickerList(params) {
|
|
14275
|
-
|
|
14276
|
-
return (await getTickerData(params, {
|
|
14277
|
-
isProd: !config?.isTestnet
|
|
14278
|
-
})).data;
|
|
14019
|
+
return (await this.api.getTickerData(params)).data;
|
|
14279
14020
|
}
|
|
14280
14021
|
/**
|
|
14281
14022
|
* ticker end
|
|
@@ -14286,7 +14027,6 @@ var Markets = class {
|
|
|
14286
14027
|
*
|
|
14287
14028
|
*/
|
|
14288
14029
|
async searchMarketAuth(params, address) {
|
|
14289
|
-
const config = this.configManager.getConfig();
|
|
14290
14030
|
const accessToken = await this.configManager.getAccessToken();
|
|
14291
14031
|
if (!accessToken) {
|
|
14292
14032
|
throw new MyxSDKError(
|
|
@@ -14294,14 +14034,11 @@ var Markets = class {
|
|
|
14294
14034
|
"Invalid access token"
|
|
14295
14035
|
);
|
|
14296
14036
|
}
|
|
14297
|
-
return (await searchMarketAuth(
|
|
14037
|
+
return (await this.api.searchMarketAuth(
|
|
14298
14038
|
{
|
|
14299
14039
|
address,
|
|
14300
14040
|
...params,
|
|
14301
14041
|
accessToken
|
|
14302
|
-
},
|
|
14303
|
-
{
|
|
14304
|
-
isProd: !config?.isTestnet
|
|
14305
14042
|
}
|
|
14306
14043
|
)).data;
|
|
14307
14044
|
}
|
|
@@ -14309,10 +14046,7 @@ var Markets = class {
|
|
|
14309
14046
|
* search by unauthenticated users
|
|
14310
14047
|
*/
|
|
14311
14048
|
async searchMarket(params) {
|
|
14312
|
-
|
|
14313
|
-
return (await searchMarket(params, {
|
|
14314
|
-
isProd: !config?.isTestnet
|
|
14315
|
-
})).data;
|
|
14049
|
+
return (await this.api.searchMarket(params)).data;
|
|
14316
14050
|
}
|
|
14317
14051
|
/**
|
|
14318
14052
|
* get favorites list
|
|
@@ -14327,14 +14061,11 @@ var Markets = class {
|
|
|
14327
14061
|
"Invalid access token"
|
|
14328
14062
|
);
|
|
14329
14063
|
}
|
|
14330
|
-
return (await getFavoritesList(
|
|
14064
|
+
return (await this.api.getFavoritesList(
|
|
14331
14065
|
{
|
|
14332
14066
|
...params,
|
|
14333
14067
|
address,
|
|
14334
14068
|
accessToken
|
|
14335
|
-
},
|
|
14336
|
-
{
|
|
14337
|
-
isProd: !config?.isTestnet
|
|
14338
14069
|
}
|
|
14339
14070
|
)).data;
|
|
14340
14071
|
}
|
|
@@ -14350,19 +14081,15 @@ var Markets = class {
|
|
|
14350
14081
|
"Invalid access token"
|
|
14351
14082
|
);
|
|
14352
14083
|
}
|
|
14353
|
-
return (await addFavorite(
|
|
14084
|
+
return (await this.api.addFavorite(
|
|
14354
14085
|
{
|
|
14355
14086
|
...params,
|
|
14356
14087
|
address,
|
|
14357
14088
|
accessToken
|
|
14358
|
-
},
|
|
14359
|
-
{
|
|
14360
|
-
isProd: !config?.isTestnet
|
|
14361
14089
|
}
|
|
14362
14090
|
)).data;
|
|
14363
14091
|
}
|
|
14364
14092
|
async removeFavorite(params, address) {
|
|
14365
|
-
const config = this.configManager.getConfig();
|
|
14366
14093
|
const accessToken = await this.configManager.getAccessToken();
|
|
14367
14094
|
if (!accessToken) {
|
|
14368
14095
|
throw new MyxSDKError(
|
|
@@ -14370,14 +14097,11 @@ var Markets = class {
|
|
|
14370
14097
|
"Invalid access token"
|
|
14371
14098
|
);
|
|
14372
14099
|
}
|
|
14373
|
-
return (await removeFavorite(
|
|
14100
|
+
return (await this.api.removeFavorite(
|
|
14374
14101
|
{
|
|
14375
14102
|
...params,
|
|
14376
14103
|
address,
|
|
14377
14104
|
accessToken
|
|
14378
|
-
},
|
|
14379
|
-
{
|
|
14380
|
-
isProd: !config?.isTestnet
|
|
14381
14105
|
}
|
|
14382
14106
|
)).data;
|
|
14383
14107
|
}
|
|
@@ -14385,28 +14109,19 @@ var Markets = class {
|
|
|
14385
14109
|
* base detail
|
|
14386
14110
|
*/
|
|
14387
14111
|
async getBaseDetail(params) {
|
|
14388
|
-
|
|
14389
|
-
return (await getBaseDetail(params, {
|
|
14390
|
-
isProd: !config?.isTestnet
|
|
14391
|
-
})).data;
|
|
14112
|
+
return (await this.api.getBaseDetail(params)).data;
|
|
14392
14113
|
}
|
|
14393
14114
|
/**
|
|
14394
14115
|
* get market detail
|
|
14395
14116
|
*/
|
|
14396
14117
|
async getMarketDetail(params) {
|
|
14397
|
-
|
|
14398
|
-
return (await getMarketDetail(params, {
|
|
14399
|
-
isProd: !config?.isTestnet
|
|
14400
|
-
})).data;
|
|
14118
|
+
return (await this.api.getMarketDetail(params)).data;
|
|
14401
14119
|
}
|
|
14402
14120
|
/**
|
|
14403
14121
|
* get pool symbol all
|
|
14404
14122
|
*/
|
|
14405
14123
|
async getPoolSymbolAll() {
|
|
14406
|
-
|
|
14407
|
-
return (await getPoolSymbolAll({
|
|
14408
|
-
isProd: !config?.isTestnet
|
|
14409
|
-
})).data;
|
|
14124
|
+
return (await this.api.getPoolSymbolAll()).data;
|
|
14410
14125
|
}
|
|
14411
14126
|
};
|
|
14412
14127
|
|
|
@@ -14414,15 +14129,15 @@ var Markets = class {
|
|
|
14414
14129
|
var import_ethers23 = require("ethers");
|
|
14415
14130
|
var import_dayjs = __toESM(require("dayjs"));
|
|
14416
14131
|
var Position = class {
|
|
14417
|
-
constructor(configManager, logger, utils, seamless, account) {
|
|
14132
|
+
constructor(configManager, logger, utils, seamless, account, api) {
|
|
14418
14133
|
this.configManager = configManager;
|
|
14419
14134
|
this.logger = logger;
|
|
14420
14135
|
this.utils = utils;
|
|
14421
14136
|
this.seamless = seamless;
|
|
14422
14137
|
this.account = account;
|
|
14138
|
+
this.api = api;
|
|
14423
14139
|
}
|
|
14424
14140
|
async listPositions(address) {
|
|
14425
|
-
const isProd = !this.configManager.getConfig().isTestnet;
|
|
14426
14141
|
const accessToken = await this.configManager.getAccessToken();
|
|
14427
14142
|
if (!accessToken) {
|
|
14428
14143
|
return {
|
|
@@ -14431,7 +14146,7 @@ var Position = class {
|
|
|
14431
14146
|
};
|
|
14432
14147
|
}
|
|
14433
14148
|
try {
|
|
14434
|
-
const res = await getPositions(accessToken, address
|
|
14149
|
+
const res = await this.api.getPositions(accessToken, address);
|
|
14435
14150
|
return {
|
|
14436
14151
|
code: 0,
|
|
14437
14152
|
data: res.data
|
|
@@ -14445,7 +14160,6 @@ var Position = class {
|
|
|
14445
14160
|
}
|
|
14446
14161
|
}
|
|
14447
14162
|
async getPositionHistory(params, address) {
|
|
14448
|
-
const config = this.configManager.getConfig();
|
|
14449
14163
|
const accessToken = await this.configManager.getAccessToken();
|
|
14450
14164
|
if (!accessToken) {
|
|
14451
14165
|
throw new MyxSDKError(
|
|
@@ -14453,11 +14167,8 @@ var Position = class {
|
|
|
14453
14167
|
"Invalid access token"
|
|
14454
14168
|
);
|
|
14455
14169
|
}
|
|
14456
|
-
const res = await getPositionHistory(
|
|
14457
|
-
{ accessToken, ...params, address }
|
|
14458
|
-
{
|
|
14459
|
-
isProd: !config?.isTestnet
|
|
14460
|
-
}
|
|
14170
|
+
const res = await this.api.getPositionHistory(
|
|
14171
|
+
{ accessToken, ...params, address }
|
|
14461
14172
|
);
|
|
14462
14173
|
return {
|
|
14463
14174
|
code: 0,
|
|
@@ -14680,12 +14391,13 @@ var OrderStatus = {
|
|
|
14680
14391
|
var import_ethers24 = require("ethers");
|
|
14681
14392
|
var import_dayjs2 = __toESM(require("dayjs"));
|
|
14682
14393
|
var Order = class {
|
|
14683
|
-
constructor(configManager, logger, utils, seamless, account) {
|
|
14394
|
+
constructor(configManager, logger, utils, seamless, account, api) {
|
|
14684
14395
|
this.configManager = configManager;
|
|
14685
14396
|
this.logger = logger;
|
|
14686
14397
|
this.utils = utils;
|
|
14687
14398
|
this.seamless = seamless;
|
|
14688
14399
|
this.account = account;
|
|
14400
|
+
this.api = api;
|
|
14689
14401
|
}
|
|
14690
14402
|
async createIncreaseOrder(params, tradingFee) {
|
|
14691
14403
|
try {
|
|
@@ -14845,10 +14557,9 @@ var Order = class {
|
|
|
14845
14557
|
);
|
|
14846
14558
|
}
|
|
14847
14559
|
const receipt = await transaction.wait();
|
|
14848
|
-
const orderId = this.utils.getOrderIdFromTransaction(receipt);
|
|
14849
14560
|
const result = {
|
|
14850
14561
|
success: true,
|
|
14851
|
-
orderId,
|
|
14562
|
+
// orderId,
|
|
14852
14563
|
transactionHash: transaction.hash,
|
|
14853
14564
|
blockNumber: receipt?.blockNumber,
|
|
14854
14565
|
gasUsed: receipt?.gasUsed?.toString(),
|
|
@@ -14857,10 +14568,6 @@ var Order = class {
|
|
|
14857
14568
|
timestamp: Date.now(),
|
|
14858
14569
|
receipt
|
|
14859
14570
|
};
|
|
14860
|
-
if (!orderId) {
|
|
14861
|
-
this.logger.warn("Warning: OrderId not found in transaction logs");
|
|
14862
|
-
result.success = false;
|
|
14863
|
-
}
|
|
14864
14571
|
return {
|
|
14865
14572
|
code: 0,
|
|
14866
14573
|
message: "create increase order success",
|
|
@@ -14985,16 +14692,11 @@ var Order = class {
|
|
|
14985
14692
|
const transaction = await brokerContract.placeOrdersWithPosition(depositData, positionIds, dataMap, {
|
|
14986
14693
|
gasLimit: gasLimit * 120n / 100n
|
|
14987
14694
|
});
|
|
14988
|
-
this.logger.info("Transaction sent:", transaction.hash);
|
|
14989
|
-
this.logger.info("Waiting for confirmation...");
|
|
14990
14695
|
const receipt = await transaction.wait();
|
|
14991
|
-
this.logger.info("Transaction confirmed in block:", receipt?.blockNumber);
|
|
14992
|
-
this.logger.info("closeAllPositions receipt--->", receipt);
|
|
14993
|
-
const orderId = this.utils.getOrderIdFromTransaction(receipt);
|
|
14994
14696
|
return {
|
|
14995
14697
|
code: 0,
|
|
14996
14698
|
message: "close all positions success",
|
|
14997
|
-
data: orderId,
|
|
14699
|
+
// data: orderId,
|
|
14998
14700
|
transactionHash: transaction.hash,
|
|
14999
14701
|
blockNumber: receipt?.blockNumber,
|
|
15000
14702
|
gasUsed: receipt?.gasUsed?.toString(),
|
|
@@ -15139,10 +14841,9 @@ var Order = class {
|
|
|
15139
14841
|
);
|
|
15140
14842
|
}
|
|
15141
14843
|
const receipt = await transaction.wait();
|
|
15142
|
-
const orderId = this.utils.getOrderIdFromTransaction(receipt);
|
|
15143
14844
|
const result = {
|
|
15144
14845
|
success: true,
|
|
15145
|
-
orderId,
|
|
14846
|
+
// orderId,
|
|
15146
14847
|
transactionHash: transaction.hash,
|
|
15147
14848
|
blockNumber: receipt?.blockNumber,
|
|
15148
14849
|
gasUsed: receipt?.gasUsed?.toString(),
|
|
@@ -15151,10 +14852,6 @@ var Order = class {
|
|
|
15151
14852
|
timestamp: Date.now(),
|
|
15152
14853
|
receipt
|
|
15153
14854
|
};
|
|
15154
|
-
if (!orderId) {
|
|
15155
|
-
this.logger.warn("Warning: OrderId not found in transaction logs");
|
|
15156
|
-
result.success = false;
|
|
15157
|
-
}
|
|
15158
14855
|
return {
|
|
15159
14856
|
code: 0,
|
|
15160
14857
|
message: "create decrease order success",
|
|
@@ -15310,18 +15007,10 @@ var Order = class {
|
|
|
15310
15007
|
gasLimit: gasLimit * 120n / 100n
|
|
15311
15008
|
});
|
|
15312
15009
|
}
|
|
15313
|
-
this.logger.info("Transaction sent:", transaction2.hash);
|
|
15314
|
-
this.logger.info("Waiting for confirmation...");
|
|
15315
15010
|
const receipt2 = await transaction2.wait();
|
|
15316
|
-
this.logger.info(
|
|
15317
|
-
"Transaction confirmed in block:",
|
|
15318
|
-
receipt2?.blockNumber
|
|
15319
|
-
);
|
|
15320
|
-
this.logger.info("createDecreaseOrder receipt--->", receipt2);
|
|
15321
|
-
const orderId2 = this.utils.getOrderIdFromTransaction(receipt2);
|
|
15322
15011
|
const result2 = {
|
|
15323
15012
|
success: true,
|
|
15324
|
-
orderId
|
|
15013
|
+
// orderId,
|
|
15325
15014
|
transactionHash: transaction2.hash,
|
|
15326
15015
|
blockNumber: receipt2?.blockNumber,
|
|
15327
15016
|
gasUsed: receipt2?.gasUsed?.toString(),
|
|
@@ -15330,10 +15019,6 @@ var Order = class {
|
|
|
15330
15019
|
timestamp: Date.now(),
|
|
15331
15020
|
receipt: receipt2
|
|
15332
15021
|
};
|
|
15333
|
-
if (!orderId2) {
|
|
15334
|
-
this.logger.warn("Warning: OrderId not found in transaction logs");
|
|
15335
|
-
result2.success = false;
|
|
15336
|
-
}
|
|
15337
15022
|
return {
|
|
15338
15023
|
code: 0,
|
|
15339
15024
|
message: "create decrease order success",
|
|
@@ -15449,18 +15134,10 @@ var Order = class {
|
|
|
15449
15134
|
gasLimit: gasLimit * 120n / 100n
|
|
15450
15135
|
});
|
|
15451
15136
|
}
|
|
15452
|
-
this.logger.info("Transaction sent:", transaction.hash);
|
|
15453
|
-
this.logger.info("Waiting for confirmation...");
|
|
15454
15137
|
const receipt = await transaction.wait();
|
|
15455
|
-
this.logger.info(
|
|
15456
|
-
"Transaction confirmed in block:",
|
|
15457
|
-
receipt?.blockNumber
|
|
15458
|
-
);
|
|
15459
|
-
this.logger.info("createDecreaseOrder receipt--->", receipt);
|
|
15460
|
-
const orderId = this.utils.getOrderIdFromTransaction(receipt);
|
|
15461
15138
|
const result = {
|
|
15462
15139
|
success: true,
|
|
15463
|
-
orderId,
|
|
15140
|
+
// orderId,
|
|
15464
15141
|
transactionHash: transaction.hash,
|
|
15465
15142
|
blockNumber: receipt?.blockNumber,
|
|
15466
15143
|
gasUsed: receipt?.gasUsed?.toString(),
|
|
@@ -15469,10 +15146,6 @@ var Order = class {
|
|
|
15469
15146
|
timestamp: Date.now(),
|
|
15470
15147
|
receipt
|
|
15471
15148
|
};
|
|
15472
|
-
if (!orderId) {
|
|
15473
|
-
this.logger.warn("Warning: OrderId not found in transaction logs");
|
|
15474
|
-
result.success = false;
|
|
15475
|
-
}
|
|
15476
15149
|
return {
|
|
15477
15150
|
code: 0,
|
|
15478
15151
|
message: "create decrease order success",
|
|
@@ -15662,7 +15335,6 @@ var Order = class {
|
|
|
15662
15335
|
}
|
|
15663
15336
|
}
|
|
15664
15337
|
async getOrders(address) {
|
|
15665
|
-
const isProd = !this.configManager.getConfig().isTestnet;
|
|
15666
15338
|
const accessToken = await this.configManager.getAccessToken();
|
|
15667
15339
|
if (!accessToken) {
|
|
15668
15340
|
return {
|
|
@@ -15671,7 +15343,7 @@ var Order = class {
|
|
|
15671
15343
|
};
|
|
15672
15344
|
}
|
|
15673
15345
|
try {
|
|
15674
|
-
const res = await getOrders(accessToken, address
|
|
15346
|
+
const res = await this.api.getOrders(accessToken, address);
|
|
15675
15347
|
return {
|
|
15676
15348
|
code: 0,
|
|
15677
15349
|
data: res.data
|
|
@@ -15693,9 +15365,7 @@ var Order = class {
|
|
|
15693
15365
|
"Invalid access token"
|
|
15694
15366
|
);
|
|
15695
15367
|
}
|
|
15696
|
-
const res = await getHistoryOrders({ accessToken, ...params, address }
|
|
15697
|
-
isProd: !config?.isTestnet
|
|
15698
|
-
});
|
|
15368
|
+
const res = await this.api.getHistoryOrders({ accessToken, ...params, address });
|
|
15699
15369
|
return {
|
|
15700
15370
|
code: 0,
|
|
15701
15371
|
data: res.data
|
|
@@ -20351,7 +20021,6 @@ var Utils = class {
|
|
|
20351
20021
|
const eventTopic = import_ethers25.ethers.id(
|
|
20352
20022
|
"OrderPlaced(address,address,bytes32,uint256,uint256,uint8,uint8,uint8,uint8,uint256,uint256,uint256,uint8,bool,uint16,address,uint256,uint16)"
|
|
20353
20023
|
);
|
|
20354
|
-
this.logger.info("Looking for OrderPlaced events with topic:", eventTopic);
|
|
20355
20024
|
for (let i = 0; i < receipt.logs.length; i++) {
|
|
20356
20025
|
const log = receipt.logs[i];
|
|
20357
20026
|
this.logger.info(`Log ${i}:`, {
|
|
@@ -20360,18 +20029,15 @@ var Utils = class {
|
|
|
20360
20029
|
data: log.data
|
|
20361
20030
|
});
|
|
20362
20031
|
if (log.topics && log.topics.length > 0 && log.topics[0] === eventTopic) {
|
|
20363
|
-
this.logger.info(`Found OrderPlaced event in log ${i}`);
|
|
20364
20032
|
try {
|
|
20365
20033
|
const parsedLog = emiterInterface.parseLog({
|
|
20366
20034
|
topics: log.topics,
|
|
20367
20035
|
data: log.data
|
|
20368
20036
|
});
|
|
20369
20037
|
if (parsedLog && parsedLog.name === "OrderPlaced") {
|
|
20370
|
-
this.logger.info("Parsed OrderPlaced event:", parsedLog.args);
|
|
20371
20038
|
const orderId = parsedLog.args[4];
|
|
20372
20039
|
if (orderId !== void 0 && orderId !== null) {
|
|
20373
20040
|
const orderIdString = orderId.toString();
|
|
20374
|
-
this.logger.info(`Found orderId: ${orderIdString}`);
|
|
20375
20041
|
return orderIdString;
|
|
20376
20042
|
}
|
|
20377
20043
|
}
|
|
@@ -20381,7 +20047,6 @@ var Utils = class {
|
|
|
20381
20047
|
}
|
|
20382
20048
|
}
|
|
20383
20049
|
}
|
|
20384
|
-
this.logger.warn("OrderPlaced event not found in transaction logs");
|
|
20385
20050
|
return null;
|
|
20386
20051
|
}
|
|
20387
20052
|
async getApproveQuoteAmount(chainId, quoteAddress, spenderAddress) {
|
|
@@ -20513,7 +20178,6 @@ var Utils = class {
|
|
|
20513
20178
|
const networkFee = await orderManagerContract.getExecutionFee(
|
|
20514
20179
|
quoteAddress
|
|
20515
20180
|
);
|
|
20516
|
-
console.log("networkFee-->", networkFee.toString());
|
|
20517
20181
|
return networkFee.toString();
|
|
20518
20182
|
} catch (error) {
|
|
20519
20183
|
this.logger.error("Error getting network fee:", error);
|
|
@@ -20522,8 +20186,7 @@ var Utils = class {
|
|
|
20522
20186
|
}
|
|
20523
20187
|
async getOraclePrice(poolId, chainId) {
|
|
20524
20188
|
try {
|
|
20525
|
-
const
|
|
20526
|
-
const priceData = await getPriceData(chainId, poolId, isProd);
|
|
20189
|
+
const priceData = await getPriceData(chainId, poolId);
|
|
20527
20190
|
if (!priceData) throw new Error("Failed to get price data");
|
|
20528
20191
|
return priceData;
|
|
20529
20192
|
} catch (error) {
|
|
@@ -21409,38 +21072,10 @@ var Account = class {
|
|
|
21409
21072
|
data: balance
|
|
21410
21073
|
};
|
|
21411
21074
|
}
|
|
21412
|
-
/**
|
|
21413
|
-
* get tradable amount
|
|
21414
|
-
*/
|
|
21415
|
-
async getTradableAmount({ poolId, chainId, address }) {
|
|
21416
|
-
const contractAddress = getContractAddressByChainId(chainId);
|
|
21417
|
-
const provider = await getJSONProvider(chainId);
|
|
21418
|
-
const accountContract = new import_ethers26.ethers.Contract(
|
|
21419
|
-
contractAddress.Account,
|
|
21420
|
-
Account_default,
|
|
21421
|
-
provider
|
|
21422
|
-
);
|
|
21423
|
-
try {
|
|
21424
|
-
const assets = await accountContract.getTradableAmount(address, poolId);
|
|
21425
|
-
const data = {
|
|
21426
|
-
profitIsReleased: assets[0],
|
|
21427
|
-
freeAmount: assets[1],
|
|
21428
|
-
tradeableProfit: assets[2]
|
|
21429
|
-
};
|
|
21430
|
-
return {
|
|
21431
|
-
code: 0,
|
|
21432
|
-
data
|
|
21433
|
-
};
|
|
21434
|
-
} catch (error) {
|
|
21435
|
-
return {
|
|
21436
|
-
code: -1
|
|
21437
|
-
};
|
|
21438
|
-
}
|
|
21439
|
-
}
|
|
21440
21075
|
async getAvailableMarginBalance({ poolId, chainId, address }) {
|
|
21441
21076
|
try {
|
|
21442
21077
|
const isProd = !this.configManager.getConfig().isTestnet;
|
|
21443
|
-
const poolListRes = await getPoolList(
|
|
21078
|
+
const poolListRes = await this.client.api.getPoolList();
|
|
21444
21079
|
if (poolListRes.code !== 9200) {
|
|
21445
21080
|
throw new MyxSDKError(
|
|
21446
21081
|
"REQUEST_FAILED" /* RequestFailed */,
|
|
@@ -21481,7 +21116,6 @@ var Account = class {
|
|
|
21481
21116
|
const availableAccountMarginBalance = accountMargin - usedMargin;
|
|
21482
21117
|
return availableAccountMarginBalance;
|
|
21483
21118
|
} catch (error) {
|
|
21484
|
-
this.logger.info("getAvailableMarginBalance error-->", error);
|
|
21485
21119
|
throw new MyxSDKError(
|
|
21486
21120
|
"REQUEST_FAILED" /* RequestFailed */,
|
|
21487
21121
|
"Failed to get getAvailableMarginBalance"
|
|
@@ -21489,7 +21123,6 @@ var Account = class {
|
|
|
21489
21123
|
}
|
|
21490
21124
|
}
|
|
21491
21125
|
async getTradeFlow(params, address) {
|
|
21492
|
-
const config = this.configManager.getConfig();
|
|
21493
21126
|
const accessToken = await this.configManager.getAccessToken();
|
|
21494
21127
|
if (!accessToken) {
|
|
21495
21128
|
throw new MyxSDKError(
|
|
@@ -21497,9 +21130,7 @@ var Account = class {
|
|
|
21497
21130
|
"Invalid access token"
|
|
21498
21131
|
);
|
|
21499
21132
|
}
|
|
21500
|
-
const res = await getTradeFlow({ accessToken, ...params, address }
|
|
21501
|
-
isProd: !config?.isTestnet
|
|
21502
|
-
});
|
|
21133
|
+
const res = await this.client.api.getTradeFlow({ accessToken, ...params, address });
|
|
21503
21134
|
return {
|
|
21504
21135
|
code: 0,
|
|
21505
21136
|
data: res.data
|
|
@@ -21533,9 +21164,7 @@ var Account = class {
|
|
|
21533
21164
|
data: functionHash,
|
|
21534
21165
|
nonce: nonce.toString()
|
|
21535
21166
|
};
|
|
21536
|
-
this.logger.info("withdraw forward tx params --->", forwardTxParams);
|
|
21537
21167
|
const rs2 = await this.client.seamless.forwarderTx(forwardTxParams, chainId, seamlessWallet);
|
|
21538
|
-
console.log("rs-->", rs2);
|
|
21539
21168
|
return {
|
|
21540
21169
|
code: 0,
|
|
21541
21170
|
message: "withdraw success",
|
|
@@ -21609,7 +21238,6 @@ var Account = class {
|
|
|
21609
21238
|
};
|
|
21610
21239
|
this.logger.info("deposit forward tx params --->", forwardTxParams);
|
|
21611
21240
|
const rs2 = await this.client.seamless.forwarderTx(forwardTxParams, chainId, seamlessWallet);
|
|
21612
|
-
console.log("rs-->", rs2);
|
|
21613
21241
|
return {
|
|
21614
21242
|
code: 0,
|
|
21615
21243
|
message: "deposit success",
|
|
@@ -21668,6 +21296,282 @@ var Account = class {
|
|
|
21668
21296
|
}
|
|
21669
21297
|
};
|
|
21670
21298
|
|
|
21299
|
+
// src/api/utils.ts
|
|
21300
|
+
function encodeQueryParam(key, value) {
|
|
21301
|
+
const encodedKey = encodeURIComponent(key);
|
|
21302
|
+
return `${encodedKey}=${encodeURIComponent(typeof value === "number" ? value : `${value}`)}`;
|
|
21303
|
+
}
|
|
21304
|
+
function addQueryParam(query, key) {
|
|
21305
|
+
return encodeQueryParam(key, query[key]);
|
|
21306
|
+
}
|
|
21307
|
+
function addArrayQueryParam(query, key) {
|
|
21308
|
+
const value = query[key];
|
|
21309
|
+
return value.map((v) => encodeQueryParam(key, v)).join("&");
|
|
21310
|
+
}
|
|
21311
|
+
function toQueryString(rawQuery) {
|
|
21312
|
+
const query = rawQuery || {};
|
|
21313
|
+
const keys = Object.keys(query).filter((key) => "undefined" !== typeof query[key]);
|
|
21314
|
+
return keys.map((key) => Array.isArray(query[key]) ? addArrayQueryParam(query, key) : addQueryParam(query, key)).join("&");
|
|
21315
|
+
}
|
|
21316
|
+
function addQueryParams(rawQuery) {
|
|
21317
|
+
const queryString = toQueryString(rawQuery);
|
|
21318
|
+
return queryString ? `?${queryString}` : "";
|
|
21319
|
+
}
|
|
21320
|
+
|
|
21321
|
+
// src/manager/api/index.ts
|
|
21322
|
+
var Api = class {
|
|
21323
|
+
constructor(configManager, logger) {
|
|
21324
|
+
this.configManager = configManager;
|
|
21325
|
+
this.logger = logger;
|
|
21326
|
+
}
|
|
21327
|
+
getHost() {
|
|
21328
|
+
const isProd = !this.configManager.getConfig().isTestnet;
|
|
21329
|
+
return isProd ? "https://api.myx.finance" : "https://api-test.myx.cash";
|
|
21330
|
+
}
|
|
21331
|
+
async getTradeFlow({
|
|
21332
|
+
accessToken,
|
|
21333
|
+
address,
|
|
21334
|
+
...params
|
|
21335
|
+
}) {
|
|
21336
|
+
return http.get(
|
|
21337
|
+
`${this.getHost()}/openapi/gateway/scan/trade/flow`,
|
|
21338
|
+
params,
|
|
21339
|
+
{
|
|
21340
|
+
headers: {
|
|
21341
|
+
myx_openapi_access_token: accessToken,
|
|
21342
|
+
myx_openapi_account: address
|
|
21343
|
+
}
|
|
21344
|
+
}
|
|
21345
|
+
);
|
|
21346
|
+
}
|
|
21347
|
+
async getPoolSymbolAll() {
|
|
21348
|
+
return http.get(
|
|
21349
|
+
`${this.getHost()}/openapi/gateway/scan/pools`
|
|
21350
|
+
);
|
|
21351
|
+
}
|
|
21352
|
+
async fetchForwarderGetApi(params) {
|
|
21353
|
+
const rs = await http.get(
|
|
21354
|
+
`${this.getHost()}/v2/agent/forwarder/get${addQueryParams(params)}`
|
|
21355
|
+
);
|
|
21356
|
+
return rs;
|
|
21357
|
+
}
|
|
21358
|
+
async getPoolList() {
|
|
21359
|
+
return http.get(
|
|
21360
|
+
`${this.getHost()}/openapi/gateway/scan/market/list`
|
|
21361
|
+
);
|
|
21362
|
+
}
|
|
21363
|
+
async forwarderTxApi(params, chainId) {
|
|
21364
|
+
return http.post(
|
|
21365
|
+
`${this.getHost()}/v2/agent/forwarder/tx-v2`,
|
|
21366
|
+
params,
|
|
21367
|
+
{
|
|
21368
|
+
headers: {
|
|
21369
|
+
"myx-chain-id": chainId.toString()
|
|
21370
|
+
}
|
|
21371
|
+
}
|
|
21372
|
+
);
|
|
21373
|
+
}
|
|
21374
|
+
async getOraclePrice(chainId, poolIds = []) {
|
|
21375
|
+
if (!!poolIds.length) {
|
|
21376
|
+
return http.get(
|
|
21377
|
+
`${this.getHost()}/openapi/gateway/quote/price/oracles`,
|
|
21378
|
+
{
|
|
21379
|
+
chainId,
|
|
21380
|
+
poolIds: poolIds.join(",")
|
|
21381
|
+
}
|
|
21382
|
+
);
|
|
21383
|
+
}
|
|
21384
|
+
throw new Error("Invalid pool id");
|
|
21385
|
+
}
|
|
21386
|
+
async getPoolDetail(chainId, poolId) {
|
|
21387
|
+
return await http.get(
|
|
21388
|
+
`${this.getHost()}/openapi/gateway/scan/market/info?chainId=${chainId}&poolId=${poolId}`
|
|
21389
|
+
);
|
|
21390
|
+
}
|
|
21391
|
+
async getPoolLevelConfig({
|
|
21392
|
+
poolId,
|
|
21393
|
+
chainId
|
|
21394
|
+
}) {
|
|
21395
|
+
return http.get(
|
|
21396
|
+
`${this.getHost()}/openapi/gateway/risk/market_pool/level_config${addQueryParams({
|
|
21397
|
+
poolId,
|
|
21398
|
+
chainId
|
|
21399
|
+
})}`
|
|
21400
|
+
);
|
|
21401
|
+
}
|
|
21402
|
+
async getPositions(accessToken, address) {
|
|
21403
|
+
return await http.get(
|
|
21404
|
+
`${this.getHost()}/openapi/gateway/scan/position/open`,
|
|
21405
|
+
void 0,
|
|
21406
|
+
{
|
|
21407
|
+
headers: {
|
|
21408
|
+
myx_openapi_access_token: accessToken,
|
|
21409
|
+
myx_openapi_account: address
|
|
21410
|
+
}
|
|
21411
|
+
}
|
|
21412
|
+
);
|
|
21413
|
+
}
|
|
21414
|
+
async getOrders(accessToken, address) {
|
|
21415
|
+
return await http.get(
|
|
21416
|
+
`${this.getHost()}/openapi/gateway/scan/order/open`,
|
|
21417
|
+
void 0,
|
|
21418
|
+
{
|
|
21419
|
+
headers: {
|
|
21420
|
+
myx_openapi_access_token: accessToken,
|
|
21421
|
+
myx_openapi_account: address
|
|
21422
|
+
}
|
|
21423
|
+
}
|
|
21424
|
+
);
|
|
21425
|
+
}
|
|
21426
|
+
async getPoolOpenOrders(accessToken, address, chainId) {
|
|
21427
|
+
return await http.get(
|
|
21428
|
+
`${this.getHost()}/openapi/gateway/scan/market/pool-order/open?chainId=${chainId}`,
|
|
21429
|
+
void 0,
|
|
21430
|
+
{
|
|
21431
|
+
headers: {
|
|
21432
|
+
myx_openapi_access_token: accessToken,
|
|
21433
|
+
myx_openapi_account: address
|
|
21434
|
+
}
|
|
21435
|
+
}
|
|
21436
|
+
);
|
|
21437
|
+
}
|
|
21438
|
+
async getKlineData({ chainId, poolId, endTime, limit, interval }) {
|
|
21439
|
+
return http.get(
|
|
21440
|
+
`${this.getHost()}/openapi/gateway/quote/candles`,
|
|
21441
|
+
{
|
|
21442
|
+
chainId,
|
|
21443
|
+
poolId,
|
|
21444
|
+
endTime,
|
|
21445
|
+
limit,
|
|
21446
|
+
interval
|
|
21447
|
+
}
|
|
21448
|
+
);
|
|
21449
|
+
}
|
|
21450
|
+
async getKlineLatestBar(params) {
|
|
21451
|
+
return http.get(
|
|
21452
|
+
`${this.getHost()}/openapi/gateway/quote/candle/latest`,
|
|
21453
|
+
params
|
|
21454
|
+
);
|
|
21455
|
+
}
|
|
21456
|
+
async getTickerData({ chainId, poolIds }) {
|
|
21457
|
+
return http.get(
|
|
21458
|
+
`${this.getHost()}/openapi/gateway/quote/candle/tickers`,
|
|
21459
|
+
{
|
|
21460
|
+
chainId,
|
|
21461
|
+
poolIds: poolIds.join(",")
|
|
21462
|
+
}
|
|
21463
|
+
);
|
|
21464
|
+
}
|
|
21465
|
+
async getAllTickers() {
|
|
21466
|
+
return http.get(
|
|
21467
|
+
`${this.getHost()}/v2/mx-gateway/quote/candle/all_tickers`
|
|
21468
|
+
);
|
|
21469
|
+
}
|
|
21470
|
+
async searchMarketAuth({ accessToken, address, ...params }) {
|
|
21471
|
+
return http.get(
|
|
21472
|
+
`${this.getHost()}/openapi/gateway/scan/market/ac-search`,
|
|
21473
|
+
params,
|
|
21474
|
+
{
|
|
21475
|
+
headers: {
|
|
21476
|
+
myx_openapi_access_token: accessToken,
|
|
21477
|
+
myx_openapi_account: address
|
|
21478
|
+
}
|
|
21479
|
+
}
|
|
21480
|
+
);
|
|
21481
|
+
}
|
|
21482
|
+
async searchMarket({ ...params }) {
|
|
21483
|
+
return http.get(
|
|
21484
|
+
`${this.getHost()}/openapi/gateway/scan/market/search`,
|
|
21485
|
+
params
|
|
21486
|
+
);
|
|
21487
|
+
}
|
|
21488
|
+
async addFavorite({ accessToken, address, ...params }) {
|
|
21489
|
+
return http.get(
|
|
21490
|
+
`${this.getHost()}/openapi/gateway/scan/market/add-favorites`,
|
|
21491
|
+
params,
|
|
21492
|
+
{
|
|
21493
|
+
headers: {
|
|
21494
|
+
myx_openapi_access_token: accessToken,
|
|
21495
|
+
myx_openapi_account: address
|
|
21496
|
+
}
|
|
21497
|
+
}
|
|
21498
|
+
);
|
|
21499
|
+
}
|
|
21500
|
+
async removeFavorite({ accessToken, address, ...params }) {
|
|
21501
|
+
return http.get(
|
|
21502
|
+
`${this.getHost()}/openapi/gateway/scan/market/cancel-favorites`,
|
|
21503
|
+
params,
|
|
21504
|
+
{
|
|
21505
|
+
headers: {
|
|
21506
|
+
myx_openapi_access_token: accessToken,
|
|
21507
|
+
myx_openapi_account: address
|
|
21508
|
+
}
|
|
21509
|
+
}
|
|
21510
|
+
);
|
|
21511
|
+
}
|
|
21512
|
+
async getFavoritesList({ accessToken, address, ...params }) {
|
|
21513
|
+
return http.get(
|
|
21514
|
+
`${this.getHost()}/openapi/gateway/scan/market/favorites`,
|
|
21515
|
+
params,
|
|
21516
|
+
{
|
|
21517
|
+
headers: {
|
|
21518
|
+
myx_openapi_access_token: accessToken,
|
|
21519
|
+
myx_openapi_account: address
|
|
21520
|
+
}
|
|
21521
|
+
}
|
|
21522
|
+
);
|
|
21523
|
+
}
|
|
21524
|
+
async getBaseDetail({ ...params }) {
|
|
21525
|
+
return http.get(
|
|
21526
|
+
`${this.getHost()}/openapi/gateway/scan/market/base-details`,
|
|
21527
|
+
params
|
|
21528
|
+
);
|
|
21529
|
+
}
|
|
21530
|
+
async getMarketDetail({ ...params }) {
|
|
21531
|
+
return http.get(
|
|
21532
|
+
`${this.getHost()}/openapi/gateway/scan/market/detail`,
|
|
21533
|
+
params
|
|
21534
|
+
);
|
|
21535
|
+
}
|
|
21536
|
+
async getHistoryOrders({
|
|
21537
|
+
accessToken,
|
|
21538
|
+
address,
|
|
21539
|
+
...params
|
|
21540
|
+
}) {
|
|
21541
|
+
return http.get(
|
|
21542
|
+
`${this.getHost()}/openapi/gateway/scan/order/closed`,
|
|
21543
|
+
params,
|
|
21544
|
+
{
|
|
21545
|
+
headers: {
|
|
21546
|
+
myx_openapi_account: address,
|
|
21547
|
+
myx_openapi_access_token: accessToken
|
|
21548
|
+
}
|
|
21549
|
+
}
|
|
21550
|
+
);
|
|
21551
|
+
}
|
|
21552
|
+
async getPositionHistory({
|
|
21553
|
+
accessToken,
|
|
21554
|
+
address,
|
|
21555
|
+
...params
|
|
21556
|
+
}) {
|
|
21557
|
+
return http.get(
|
|
21558
|
+
`${this.getHost()}/openapi/gateway/scan/position/closed`,
|
|
21559
|
+
params,
|
|
21560
|
+
{
|
|
21561
|
+
headers: {
|
|
21562
|
+
myx_openapi_account: address,
|
|
21563
|
+
myx_openapi_access_token: accessToken
|
|
21564
|
+
}
|
|
21565
|
+
}
|
|
21566
|
+
);
|
|
21567
|
+
}
|
|
21568
|
+
async getMarketList() {
|
|
21569
|
+
return http.get(
|
|
21570
|
+
`${this.getHost()}/openapi/gateway/scan/market`
|
|
21571
|
+
);
|
|
21572
|
+
}
|
|
21573
|
+
};
|
|
21574
|
+
|
|
21671
21575
|
// src/manager/seamless/index.ts
|
|
21672
21576
|
var import_crypto_js = __toESM(require("crypto-js"));
|
|
21673
21577
|
var import_ethers27 = require("ethers");
|
|
@@ -21843,11 +21747,12 @@ async function signPermit(provider, contract, owner, spender, value, nonce, dead
|
|
|
21843
21747
|
return { v, r, s };
|
|
21844
21748
|
}
|
|
21845
21749
|
var Seamless = class {
|
|
21846
|
-
constructor(configManager, logger, utils, account) {
|
|
21750
|
+
constructor(configManager, logger, utils, account, api) {
|
|
21847
21751
|
this.configManager = configManager;
|
|
21848
21752
|
this.logger = logger;
|
|
21849
21753
|
this.utils = utils;
|
|
21850
21754
|
this.account = account;
|
|
21755
|
+
this.api = api;
|
|
21851
21756
|
}
|
|
21852
21757
|
async onCheckRelayer(account, relayer, chainId) {
|
|
21853
21758
|
const forwarderContract = await getForwarderContract(chainId);
|
|
@@ -21927,7 +21832,6 @@ var Seamless = class {
|
|
|
21927
21832
|
data,
|
|
21928
21833
|
nonce
|
|
21929
21834
|
}, chainId, provider) {
|
|
21930
|
-
const isProd = !this.configManager.getConfig().isTestnet;
|
|
21931
21835
|
const forwarderContract = await getForwarderContract(chainId);
|
|
21932
21836
|
const forwarderJsonRpcContractDomain = await forwarderContract.eip712Domain();
|
|
21933
21837
|
const domain = {
|
|
@@ -21946,7 +21850,7 @@ var Seamless = class {
|
|
|
21946
21850
|
deadline,
|
|
21947
21851
|
data
|
|
21948
21852
|
});
|
|
21949
|
-
const txRs = await forwarderTxApi({ from, to, value, gas, nonce, data, deadline, signature }, chainId
|
|
21853
|
+
const txRs = await this.api.forwarderTxApi({ from, to, value, gas, nonce, data, deadline, signature }, chainId);
|
|
21950
21854
|
return txRs;
|
|
21951
21855
|
}
|
|
21952
21856
|
async authorizeSeamlessAccount({ approve: approve2, seamlessAddress, chainId }) {
|
|
@@ -21996,7 +21900,7 @@ var Seamless = class {
|
|
|
21996
21900
|
if (!txRs.data?.txHash) {
|
|
21997
21901
|
const retryOptions = { n: 10, minWait: 250, maxWait: 1e3 };
|
|
21998
21902
|
const { promise } = retry(async () => {
|
|
21999
|
-
const getRs = await fetchForwarderGetApi({
|
|
21903
|
+
const getRs = await this.api.fetchForwarderGetApi({
|
|
22000
21904
|
requestId: txRs.data?.requestId
|
|
22001
21905
|
});
|
|
22002
21906
|
if (getRs.data?.status === 9 /* EXECUTED */) {
|
|
@@ -22174,15 +22078,16 @@ var MyxClient = class {
|
|
|
22174
22078
|
this.logger = new Logger({
|
|
22175
22079
|
logLevel: options.logLevel
|
|
22176
22080
|
});
|
|
22081
|
+
const lp = MxSDK.getInstance();
|
|
22082
|
+
lp.setConfigManager(this.configManager);
|
|
22177
22083
|
this.utils = new Utils(this.configManager, this.logger);
|
|
22084
|
+
this.api = new Api(this.configManager, this.logger);
|
|
22178
22085
|
this.account = new Account(this.configManager, this.logger, this.utils, this);
|
|
22179
|
-
this.seamless = new Seamless(this.configManager, this.logger, this.utils, this.account);
|
|
22180
|
-
this.markets = new Markets(this.configManager, this.utils);
|
|
22181
|
-
this.position = new Position(this.configManager, this.logger, this.utils, this.seamless, this.account);
|
|
22182
|
-
this.order = new Order(this.configManager, this.logger, this.utils, this.seamless, this.account);
|
|
22086
|
+
this.seamless = new Seamless(this.configManager, this.logger, this.utils, this.account, this.api);
|
|
22087
|
+
this.markets = new Markets(this.configManager, this.utils, this.api);
|
|
22088
|
+
this.position = new Position(this.configManager, this.logger, this.utils, this.seamless, this.account, this.api);
|
|
22089
|
+
this.order = new Order(this.configManager, this.logger, this.utils, this.seamless, this.account, this.api);
|
|
22183
22090
|
this.subscription = new SubScription(this.configManager, this.logger);
|
|
22184
|
-
const lp = MxSDK.getInstance();
|
|
22185
|
-
lp.setConfigManager(this.configManager);
|
|
22186
22091
|
}
|
|
22187
22092
|
/**
|
|
22188
22093
|
* auth the client
|
|
@@ -22237,48 +22142,31 @@ var MyxClient = class {
|
|
|
22237
22142
|
TradeFlowTypeEnum,
|
|
22238
22143
|
TriggerType,
|
|
22239
22144
|
TriggerTypeEnum,
|
|
22240
|
-
addFavorite,
|
|
22241
22145
|
approve,
|
|
22242
22146
|
base,
|
|
22243
22147
|
bigintAmountSlipperCalculator,
|
|
22244
22148
|
bigintTradingGasPriceWithRatio,
|
|
22245
22149
|
bigintTradingGasToRatioCalculator,
|
|
22246
|
-
fetchForwarderGetApi,
|
|
22247
22150
|
formatUnits,
|
|
22248
|
-
forwarderTxApi,
|
|
22249
|
-
getAllTickers,
|
|
22250
22151
|
getAllowanceApproved,
|
|
22251
22152
|
getBalanceOf,
|
|
22252
22153
|
getBaseDetail,
|
|
22253
22154
|
getBaseUrlByEnv,
|
|
22254
|
-
getFavoritesList,
|
|
22255
22155
|
getForwardUrlByEnv,
|
|
22256
|
-
getHistoryOrders,
|
|
22257
|
-
getKlineData,
|
|
22258
|
-
getKlineLatestBar,
|
|
22259
22156
|
getMarketDetail,
|
|
22260
22157
|
getMarketList,
|
|
22261
22158
|
getOraclePrice,
|
|
22262
|
-
getOrders,
|
|
22263
22159
|
getPoolDetail,
|
|
22264
|
-
getPoolLevelConfig,
|
|
22265
22160
|
getPoolList,
|
|
22266
22161
|
getPoolOpenOrders,
|
|
22267
|
-
getPoolSymbolAll,
|
|
22268
|
-
getPositionHistory,
|
|
22269
|
-
getPositions,
|
|
22270
22162
|
getPriceData,
|
|
22271
22163
|
getPricesData,
|
|
22272
22164
|
getTickerData,
|
|
22273
22165
|
getTokenInfo,
|
|
22274
|
-
getTradeFlow,
|
|
22275
22166
|
market,
|
|
22276
22167
|
parseUnits,
|
|
22277
22168
|
pool,
|
|
22278
|
-
quote
|
|
22279
|
-
removeFavorite,
|
|
22280
|
-
searchMarket,
|
|
22281
|
-
searchMarketAuth
|
|
22169
|
+
quote
|
|
22282
22170
|
});
|
|
22283
22171
|
/**
|
|
22284
22172
|
* MyxLogger
|