@myx-trade/sdk 0.1.191 → 0.1.193
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 +196 -132
- package/dist/index.d.ts +196 -132
- package/dist/index.js +348 -413
- package/dist/index.mjs +347 -395
- 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.193",
|
|
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,32 +2103,15 @@ 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) => {
|
|
2106
|
+
var getPoolDetail = async (chainId, poolId, isProd) => {
|
|
2236
2107
|
return await http.get(
|
|
2237
|
-
`${getBaseUrlByEnv(
|
|
2238
|
-
isProd
|
|
2239
|
-
)}/openapi/gateway/scan/market/info?chainId=${chainId}&poolId=${poolId}`
|
|
2108
|
+
`${getBaseUrlByEnv(isProd)}/openapi/gateway/scan/market/info?chainId=${chainId}&poolId=${poolId}`
|
|
2240
2109
|
);
|
|
2241
2110
|
};
|
|
2242
|
-
var
|
|
2111
|
+
var getPoolOpenOrders = async (accessToken, address, chainId) => {
|
|
2243
2112
|
return await http.get(
|
|
2244
|
-
`${getBaseUrlByEnv(
|
|
2113
|
+
`${getBaseUrlByEnv()}/openapi/gateway/scan/market/pool-order/open?chainId=${chainId}`,
|
|
2245
2114
|
void 0,
|
|
2246
|
-
// params
|
|
2247
2115
|
{
|
|
2248
2116
|
headers: {
|
|
2249
2117
|
myx_openapi_access_token: accessToken,
|
|
@@ -2252,52 +2120,6 @@ var getPositions = async (accessToken, address, isProd = true) => {
|
|
|
2252
2120
|
}
|
|
2253
2121
|
);
|
|
2254
2122
|
};
|
|
2255
|
-
var getOrders = async (accessToken, address, isProd = true) => {
|
|
2256
|
-
return await http.get(
|
|
2257
|
-
`${getBaseUrlByEnv(isProd)}/openapi/gateway/scan/order/open`,
|
|
2258
|
-
void 0,
|
|
2259
|
-
{
|
|
2260
|
-
headers: {
|
|
2261
|
-
myx_openapi_access_token: accessToken,
|
|
2262
|
-
myx_openapi_account: address
|
|
2263
|
-
}
|
|
2264
|
-
}
|
|
2265
|
-
);
|
|
2266
|
-
};
|
|
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
|
|
|
@@ -2464,6 +2214,7 @@ if (typeof window !== "undefined") {
|
|
|
2464
2214
|
} else if (typeof globalThis !== "undefined") {
|
|
2465
2215
|
globalThis.MxSDK = sdk;
|
|
2466
2216
|
}
|
|
2217
|
+
var web3_default = sdk;
|
|
2467
2218
|
var getWalletProvider = async (chainId) => {
|
|
2468
2219
|
try {
|
|
2469
2220
|
const walletClient = sdk.getConfigManager()?.getConfig()?.walletClient;
|
|
@@ -12167,9 +11918,9 @@ var getPricesData = async (chainId, poolIds) => {
|
|
|
12167
11918
|
const result = await parsePriceData(chainId, rs.data);
|
|
12168
11919
|
return result;
|
|
12169
11920
|
};
|
|
12170
|
-
var getPriceData = async (chainId, poolId
|
|
11921
|
+
var getPriceData = async (chainId, poolId) => {
|
|
12171
11922
|
if (!poolId) return;
|
|
12172
|
-
const rs = await getOraclePrice(chainId, [poolId]
|
|
11923
|
+
const rs = await getOraclePrice(chainId, [poolId]);
|
|
12173
11924
|
const data = rs?.data?.[0];
|
|
12174
11925
|
if (!data) {
|
|
12175
11926
|
throw new Error(`Unable to get price for ${poolId} in the deposit`);
|
|
@@ -12426,7 +12177,7 @@ var deposit = async (params) => {
|
|
|
12426
12177
|
let value = 0n;
|
|
12427
12178
|
let amountOut;
|
|
12428
12179
|
if (isNeedPrice) {
|
|
12429
|
-
const priceData = await getPriceData(chainId, poolId
|
|
12180
|
+
const priceData = await getPriceData(chainId, poolId);
|
|
12430
12181
|
if (!priceData) return;
|
|
12431
12182
|
const referencePrice = (0, import_ethers10.parseUnits)(priceData.price, COMMON_PRICE_DECIMALS);
|
|
12432
12183
|
price.push({
|
|
@@ -12496,7 +12247,7 @@ var withdraw = async (params) => {
|
|
|
12496
12247
|
let value = 0n;
|
|
12497
12248
|
let amountOut;
|
|
12498
12249
|
if (isNeedPrice) {
|
|
12499
|
-
const priceData = await getPriceData(chainId, poolId
|
|
12250
|
+
const priceData = await getPriceData(chainId, poolId);
|
|
12500
12251
|
if (!priceData) return;
|
|
12501
12252
|
const referencePrice = (0, import_ethers11.parseUnits)(priceData.price, COMMON_PRICE_DECIMALS);
|
|
12502
12253
|
price.push({
|
|
@@ -12568,7 +12319,7 @@ var getLpPrice = async (chainId, poolId) => {
|
|
|
12568
12319
|
try {
|
|
12569
12320
|
const contract = await getBasePoolContract(chainId);
|
|
12570
12321
|
let price = 0n;
|
|
12571
|
-
const res = await getPriceData(chainId, poolId
|
|
12322
|
+
const res = await getPriceData(chainId, poolId);
|
|
12572
12323
|
if (res?.price) {
|
|
12573
12324
|
price = (0, import_ethers13.parseUnits)(res.price, COMMON_PRICE_DECIMALS);
|
|
12574
12325
|
}
|
|
@@ -12660,7 +12411,7 @@ var deposit2 = async (params) => {
|
|
|
12660
12411
|
let value = 0n;
|
|
12661
12412
|
let amountOut;
|
|
12662
12413
|
if (isNeedPrice) {
|
|
12663
|
-
const priceData = await getPriceData(chainId, poolId
|
|
12414
|
+
const priceData = await getPriceData(chainId, poolId);
|
|
12664
12415
|
if (!priceData) return;
|
|
12665
12416
|
const referencePrice = (0, import_ethers14.parseUnits)(priceData.price, COMMON_PRICE_DECIMALS);
|
|
12666
12417
|
price.push({
|
|
@@ -12730,7 +12481,7 @@ var withdraw2 = async (params) => {
|
|
|
12730
12481
|
let value = 0n;
|
|
12731
12482
|
let amountOut;
|
|
12732
12483
|
if (isNeedPrice) {
|
|
12733
|
-
const priceData = await getPriceData(chainId, poolId
|
|
12484
|
+
const priceData = await getPriceData(chainId, poolId);
|
|
12734
12485
|
if (!priceData) return;
|
|
12735
12486
|
const referencePrice = (0, import_ethers15.parseUnits)(priceData.price, COMMON_PRICE_DECIMALS);
|
|
12736
12487
|
price.push({
|
|
@@ -12932,7 +12683,7 @@ var getLpPrice2 = async (chainId, poolId) => {
|
|
|
12932
12683
|
try {
|
|
12933
12684
|
const contract = await getQuotePoolContract(chainId);
|
|
12934
12685
|
let price = 0n;
|
|
12935
|
-
const res = await getPriceData(chainId, poolId
|
|
12686
|
+
const res = await getPriceData(chainId, poolId);
|
|
12936
12687
|
if (res?.price) {
|
|
12937
12688
|
price = (0, import_ethers19.parseUnits)(res.price, COMMON_PRICE_DECIMALS);
|
|
12938
12689
|
}
|
|
@@ -14216,18 +13967,19 @@ var ConfigManager = class {
|
|
|
14216
13967
|
|
|
14217
13968
|
// src/manager/markets/index.ts
|
|
14218
13969
|
var Markets = class {
|
|
14219
|
-
constructor(configManager, utils) {
|
|
13970
|
+
constructor(configManager, utils, api) {
|
|
14220
13971
|
this.configManager = configManager;
|
|
14221
13972
|
this.utils = utils;
|
|
13973
|
+
this.api = api;
|
|
14222
13974
|
}
|
|
14223
13975
|
getMarkets() {
|
|
14224
13976
|
return Promise.resolve([]);
|
|
14225
13977
|
}
|
|
14226
|
-
async getPoolLevelConfig(poolId) {
|
|
13978
|
+
async getPoolLevelConfig(poolId, chainId) {
|
|
14227
13979
|
const config = this.configManager.getConfig();
|
|
14228
|
-
return (await getPoolLevelConfig({
|
|
13980
|
+
return (await this.api.getPoolLevelConfig({
|
|
14229
13981
|
poolId,
|
|
14230
|
-
chainId
|
|
13982
|
+
chainId
|
|
14231
13983
|
})).data;
|
|
14232
13984
|
}
|
|
14233
13985
|
/**
|
|
@@ -14238,13 +13990,10 @@ var Markets = class {
|
|
|
14238
13990
|
...params
|
|
14239
13991
|
}) {
|
|
14240
13992
|
const config = this.configManager.getConfig();
|
|
14241
|
-
return (await getKlineData(
|
|
13993
|
+
return (await this.api.getKlineData(
|
|
14242
13994
|
{
|
|
14243
13995
|
...params,
|
|
14244
13996
|
interval: this.utils.transferKlineResolutionToInterval(interval)
|
|
14245
|
-
},
|
|
14246
|
-
{
|
|
14247
|
-
isProd: !config?.isTestnet
|
|
14248
13997
|
}
|
|
14249
13998
|
)).data;
|
|
14250
13999
|
}
|
|
@@ -14253,13 +14002,10 @@ var Markets = class {
|
|
|
14253
14002
|
...params
|
|
14254
14003
|
}) {
|
|
14255
14004
|
const config = this.configManager.getConfig();
|
|
14256
|
-
return (await getKlineLatestBar(
|
|
14005
|
+
return (await this.api.getKlineLatestBar(
|
|
14257
14006
|
{
|
|
14258
14007
|
...params,
|
|
14259
14008
|
interval: this.utils.transferKlineResolutionToInterval(interval)
|
|
14260
|
-
},
|
|
14261
|
-
{
|
|
14262
|
-
isProd: !config?.isTestnet
|
|
14263
14009
|
}
|
|
14264
14010
|
)).data;
|
|
14265
14011
|
}
|
|
@@ -14270,10 +14016,7 @@ var Markets = class {
|
|
|
14270
14016
|
* ticker start
|
|
14271
14017
|
*/
|
|
14272
14018
|
async getTickerList(params) {
|
|
14273
|
-
|
|
14274
|
-
return (await getTickerData(params, {
|
|
14275
|
-
isProd: !config?.isTestnet
|
|
14276
|
-
})).data;
|
|
14019
|
+
return (await this.api.getTickerData(params)).data;
|
|
14277
14020
|
}
|
|
14278
14021
|
/**
|
|
14279
14022
|
* ticker end
|
|
@@ -14284,7 +14027,6 @@ var Markets = class {
|
|
|
14284
14027
|
*
|
|
14285
14028
|
*/
|
|
14286
14029
|
async searchMarketAuth(params, address) {
|
|
14287
|
-
const config = this.configManager.getConfig();
|
|
14288
14030
|
const accessToken = await this.configManager.getAccessToken();
|
|
14289
14031
|
if (!accessToken) {
|
|
14290
14032
|
throw new MyxSDKError(
|
|
@@ -14292,14 +14034,11 @@ var Markets = class {
|
|
|
14292
14034
|
"Invalid access token"
|
|
14293
14035
|
);
|
|
14294
14036
|
}
|
|
14295
|
-
return (await searchMarketAuth(
|
|
14037
|
+
return (await this.api.searchMarketAuth(
|
|
14296
14038
|
{
|
|
14297
14039
|
address,
|
|
14298
14040
|
...params,
|
|
14299
14041
|
accessToken
|
|
14300
|
-
},
|
|
14301
|
-
{
|
|
14302
|
-
isProd: !config?.isTestnet
|
|
14303
14042
|
}
|
|
14304
14043
|
)).data;
|
|
14305
14044
|
}
|
|
@@ -14307,10 +14046,7 @@ var Markets = class {
|
|
|
14307
14046
|
* search by unauthenticated users
|
|
14308
14047
|
*/
|
|
14309
14048
|
async searchMarket(params) {
|
|
14310
|
-
|
|
14311
|
-
return (await searchMarket(params, {
|
|
14312
|
-
isProd: !config?.isTestnet
|
|
14313
|
-
})).data;
|
|
14049
|
+
return (await this.api.searchMarket(params)).data;
|
|
14314
14050
|
}
|
|
14315
14051
|
/**
|
|
14316
14052
|
* get favorites list
|
|
@@ -14325,14 +14061,11 @@ var Markets = class {
|
|
|
14325
14061
|
"Invalid access token"
|
|
14326
14062
|
);
|
|
14327
14063
|
}
|
|
14328
|
-
return (await getFavoritesList(
|
|
14064
|
+
return (await this.api.getFavoritesList(
|
|
14329
14065
|
{
|
|
14330
14066
|
...params,
|
|
14331
14067
|
address,
|
|
14332
14068
|
accessToken
|
|
14333
|
-
},
|
|
14334
|
-
{
|
|
14335
|
-
isProd: !config?.isTestnet
|
|
14336
14069
|
}
|
|
14337
14070
|
)).data;
|
|
14338
14071
|
}
|
|
@@ -14348,19 +14081,15 @@ var Markets = class {
|
|
|
14348
14081
|
"Invalid access token"
|
|
14349
14082
|
);
|
|
14350
14083
|
}
|
|
14351
|
-
return (await addFavorite(
|
|
14084
|
+
return (await this.api.addFavorite(
|
|
14352
14085
|
{
|
|
14353
14086
|
...params,
|
|
14354
14087
|
address,
|
|
14355
14088
|
accessToken
|
|
14356
|
-
},
|
|
14357
|
-
{
|
|
14358
|
-
isProd: !config?.isTestnet
|
|
14359
14089
|
}
|
|
14360
14090
|
)).data;
|
|
14361
14091
|
}
|
|
14362
14092
|
async removeFavorite(params, address) {
|
|
14363
|
-
const config = this.configManager.getConfig();
|
|
14364
14093
|
const accessToken = await this.configManager.getAccessToken();
|
|
14365
14094
|
if (!accessToken) {
|
|
14366
14095
|
throw new MyxSDKError(
|
|
@@ -14368,14 +14097,11 @@ var Markets = class {
|
|
|
14368
14097
|
"Invalid access token"
|
|
14369
14098
|
);
|
|
14370
14099
|
}
|
|
14371
|
-
return (await removeFavorite(
|
|
14100
|
+
return (await this.api.removeFavorite(
|
|
14372
14101
|
{
|
|
14373
14102
|
...params,
|
|
14374
14103
|
address,
|
|
14375
14104
|
accessToken
|
|
14376
|
-
},
|
|
14377
|
-
{
|
|
14378
|
-
isProd: !config?.isTestnet
|
|
14379
14105
|
}
|
|
14380
14106
|
)).data;
|
|
14381
14107
|
}
|
|
@@ -14383,28 +14109,19 @@ var Markets = class {
|
|
|
14383
14109
|
* base detail
|
|
14384
14110
|
*/
|
|
14385
14111
|
async getBaseDetail(params) {
|
|
14386
|
-
|
|
14387
|
-
return (await getBaseDetail(params, {
|
|
14388
|
-
isProd: !config?.isTestnet
|
|
14389
|
-
})).data;
|
|
14112
|
+
return (await this.api.getBaseDetail(params)).data;
|
|
14390
14113
|
}
|
|
14391
14114
|
/**
|
|
14392
14115
|
* get market detail
|
|
14393
14116
|
*/
|
|
14394
14117
|
async getMarketDetail(params) {
|
|
14395
|
-
|
|
14396
|
-
return (await getMarketDetail(params, {
|
|
14397
|
-
isProd: !config?.isTestnet
|
|
14398
|
-
})).data;
|
|
14118
|
+
return (await this.api.getMarketDetail(params)).data;
|
|
14399
14119
|
}
|
|
14400
14120
|
/**
|
|
14401
14121
|
* get pool symbol all
|
|
14402
14122
|
*/
|
|
14403
14123
|
async getPoolSymbolAll() {
|
|
14404
|
-
|
|
14405
|
-
return (await getPoolSymbolAll({
|
|
14406
|
-
isProd: !config?.isTestnet
|
|
14407
|
-
})).data;
|
|
14124
|
+
return (await this.api.getPoolSymbolAll()).data;
|
|
14408
14125
|
}
|
|
14409
14126
|
};
|
|
14410
14127
|
|
|
@@ -14412,15 +14129,15 @@ var Markets = class {
|
|
|
14412
14129
|
var import_ethers23 = require("ethers");
|
|
14413
14130
|
var import_dayjs = __toESM(require("dayjs"));
|
|
14414
14131
|
var Position = class {
|
|
14415
|
-
constructor(configManager, logger, utils, seamless, account) {
|
|
14132
|
+
constructor(configManager, logger, utils, seamless, account, api) {
|
|
14416
14133
|
this.configManager = configManager;
|
|
14417
14134
|
this.logger = logger;
|
|
14418
14135
|
this.utils = utils;
|
|
14419
14136
|
this.seamless = seamless;
|
|
14420
14137
|
this.account = account;
|
|
14138
|
+
this.api = api;
|
|
14421
14139
|
}
|
|
14422
14140
|
async listPositions(address) {
|
|
14423
|
-
const isProd = !this.configManager.getConfig().isTestnet;
|
|
14424
14141
|
const accessToken = await this.configManager.getAccessToken();
|
|
14425
14142
|
if (!accessToken) {
|
|
14426
14143
|
return {
|
|
@@ -14429,7 +14146,7 @@ var Position = class {
|
|
|
14429
14146
|
};
|
|
14430
14147
|
}
|
|
14431
14148
|
try {
|
|
14432
|
-
const res = await getPositions(accessToken, address
|
|
14149
|
+
const res = await this.api.getPositions(accessToken, address);
|
|
14433
14150
|
return {
|
|
14434
14151
|
code: 0,
|
|
14435
14152
|
data: res.data
|
|
@@ -14443,7 +14160,6 @@ var Position = class {
|
|
|
14443
14160
|
}
|
|
14444
14161
|
}
|
|
14445
14162
|
async getPositionHistory(params, address) {
|
|
14446
|
-
const config = this.configManager.getConfig();
|
|
14447
14163
|
const accessToken = await this.configManager.getAccessToken();
|
|
14448
14164
|
if (!accessToken) {
|
|
14449
14165
|
throw new MyxSDKError(
|
|
@@ -14451,11 +14167,8 @@ var Position = class {
|
|
|
14451
14167
|
"Invalid access token"
|
|
14452
14168
|
);
|
|
14453
14169
|
}
|
|
14454
|
-
const res = await getPositionHistory(
|
|
14455
|
-
{ accessToken, ...params, address }
|
|
14456
|
-
{
|
|
14457
|
-
isProd: !config?.isTestnet
|
|
14458
|
-
}
|
|
14170
|
+
const res = await this.api.getPositionHistory(
|
|
14171
|
+
{ accessToken, ...params, address }
|
|
14459
14172
|
);
|
|
14460
14173
|
return {
|
|
14461
14174
|
code: 0,
|
|
@@ -14678,12 +14391,13 @@ var OrderStatus = {
|
|
|
14678
14391
|
var import_ethers24 = require("ethers");
|
|
14679
14392
|
var import_dayjs2 = __toESM(require("dayjs"));
|
|
14680
14393
|
var Order = class {
|
|
14681
|
-
constructor(configManager, logger, utils, seamless, account) {
|
|
14394
|
+
constructor(configManager, logger, utils, seamless, account, api) {
|
|
14682
14395
|
this.configManager = configManager;
|
|
14683
14396
|
this.logger = logger;
|
|
14684
14397
|
this.utils = utils;
|
|
14685
14398
|
this.seamless = seamless;
|
|
14686
14399
|
this.account = account;
|
|
14400
|
+
this.api = api;
|
|
14687
14401
|
}
|
|
14688
14402
|
async createIncreaseOrder(params, tradingFee) {
|
|
14689
14403
|
try {
|
|
@@ -15660,7 +15374,6 @@ var Order = class {
|
|
|
15660
15374
|
}
|
|
15661
15375
|
}
|
|
15662
15376
|
async getOrders(address) {
|
|
15663
|
-
const isProd = !this.configManager.getConfig().isTestnet;
|
|
15664
15377
|
const accessToken = await this.configManager.getAccessToken();
|
|
15665
15378
|
if (!accessToken) {
|
|
15666
15379
|
return {
|
|
@@ -15669,7 +15382,7 @@ var Order = class {
|
|
|
15669
15382
|
};
|
|
15670
15383
|
}
|
|
15671
15384
|
try {
|
|
15672
|
-
const res = await getOrders(accessToken, address
|
|
15385
|
+
const res = await this.api.getOrders(accessToken, address);
|
|
15673
15386
|
return {
|
|
15674
15387
|
code: 0,
|
|
15675
15388
|
data: res.data
|
|
@@ -15691,9 +15404,7 @@ var Order = class {
|
|
|
15691
15404
|
"Invalid access token"
|
|
15692
15405
|
);
|
|
15693
15406
|
}
|
|
15694
|
-
const res = await getHistoryOrders({ accessToken, ...params, address }
|
|
15695
|
-
isProd: !config?.isTestnet
|
|
15696
|
-
});
|
|
15407
|
+
const res = await this.api.getHistoryOrders({ accessToken, ...params, address });
|
|
15697
15408
|
return {
|
|
15698
15409
|
code: 0,
|
|
15699
15410
|
data: res.data
|
|
@@ -20520,8 +20231,7 @@ var Utils = class {
|
|
|
20520
20231
|
}
|
|
20521
20232
|
async getOraclePrice(poolId, chainId) {
|
|
20522
20233
|
try {
|
|
20523
|
-
const
|
|
20524
|
-
const priceData = await getPriceData(chainId, poolId, isProd);
|
|
20234
|
+
const priceData = await getPriceData(chainId, poolId);
|
|
20525
20235
|
if (!priceData) throw new Error("Failed to get price data");
|
|
20526
20236
|
return priceData;
|
|
20527
20237
|
} catch (error) {
|
|
@@ -21407,38 +21117,10 @@ var Account = class {
|
|
|
21407
21117
|
data: balance
|
|
21408
21118
|
};
|
|
21409
21119
|
}
|
|
21410
|
-
/**
|
|
21411
|
-
* get tradable amount
|
|
21412
|
-
*/
|
|
21413
|
-
async getTradableAmount({ poolId, chainId, address }) {
|
|
21414
|
-
const contractAddress = getContractAddressByChainId(chainId);
|
|
21415
|
-
const provider = await getJSONProvider(chainId);
|
|
21416
|
-
const accountContract = new import_ethers26.ethers.Contract(
|
|
21417
|
-
contractAddress.Account,
|
|
21418
|
-
Account_default,
|
|
21419
|
-
provider
|
|
21420
|
-
);
|
|
21421
|
-
try {
|
|
21422
|
-
const assets = await accountContract.getTradableAmount(address, poolId);
|
|
21423
|
-
const data = {
|
|
21424
|
-
profitIsReleased: assets[0],
|
|
21425
|
-
freeAmount: assets[1],
|
|
21426
|
-
tradeableProfit: assets[2]
|
|
21427
|
-
};
|
|
21428
|
-
return {
|
|
21429
|
-
code: 0,
|
|
21430
|
-
data
|
|
21431
|
-
};
|
|
21432
|
-
} catch (error) {
|
|
21433
|
-
return {
|
|
21434
|
-
code: -1
|
|
21435
|
-
};
|
|
21436
|
-
}
|
|
21437
|
-
}
|
|
21438
21120
|
async getAvailableMarginBalance({ poolId, chainId, address }) {
|
|
21439
21121
|
try {
|
|
21440
21122
|
const isProd = !this.configManager.getConfig().isTestnet;
|
|
21441
|
-
const poolListRes = await getPoolList(
|
|
21123
|
+
const poolListRes = await this.client.api.getPoolList();
|
|
21442
21124
|
if (poolListRes.code !== 9200) {
|
|
21443
21125
|
throw new MyxSDKError(
|
|
21444
21126
|
"REQUEST_FAILED" /* RequestFailed */,
|
|
@@ -21479,7 +21161,6 @@ var Account = class {
|
|
|
21479
21161
|
const availableAccountMarginBalance = accountMargin - usedMargin;
|
|
21480
21162
|
return availableAccountMarginBalance;
|
|
21481
21163
|
} catch (error) {
|
|
21482
|
-
this.logger.info("getAvailableMarginBalance error-->", error);
|
|
21483
21164
|
throw new MyxSDKError(
|
|
21484
21165
|
"REQUEST_FAILED" /* RequestFailed */,
|
|
21485
21166
|
"Failed to get getAvailableMarginBalance"
|
|
@@ -21487,7 +21168,6 @@ var Account = class {
|
|
|
21487
21168
|
}
|
|
21488
21169
|
}
|
|
21489
21170
|
async getTradeFlow(params, address) {
|
|
21490
|
-
const config = this.configManager.getConfig();
|
|
21491
21171
|
const accessToken = await this.configManager.getAccessToken();
|
|
21492
21172
|
if (!accessToken) {
|
|
21493
21173
|
throw new MyxSDKError(
|
|
@@ -21495,9 +21175,7 @@ var Account = class {
|
|
|
21495
21175
|
"Invalid access token"
|
|
21496
21176
|
);
|
|
21497
21177
|
}
|
|
21498
|
-
const res = await getTradeFlow({ accessToken, ...params, address }
|
|
21499
|
-
isProd: !config?.isTestnet
|
|
21500
|
-
});
|
|
21178
|
+
const res = await this.client.api.getTradeFlow({ accessToken, ...params, address });
|
|
21501
21179
|
return {
|
|
21502
21180
|
code: 0,
|
|
21503
21181
|
data: res.data
|
|
@@ -21531,9 +21209,7 @@ var Account = class {
|
|
|
21531
21209
|
data: functionHash,
|
|
21532
21210
|
nonce: nonce.toString()
|
|
21533
21211
|
};
|
|
21534
|
-
this.logger.info("withdraw forward tx params --->", forwardTxParams);
|
|
21535
21212
|
const rs2 = await this.client.seamless.forwarderTx(forwardTxParams, chainId, seamlessWallet);
|
|
21536
|
-
console.log("rs-->", rs2);
|
|
21537
21213
|
return {
|
|
21538
21214
|
code: 0,
|
|
21539
21215
|
message: "withdraw success",
|
|
@@ -21607,7 +21283,6 @@ var Account = class {
|
|
|
21607
21283
|
};
|
|
21608
21284
|
this.logger.info("deposit forward tx params --->", forwardTxParams);
|
|
21609
21285
|
const rs2 = await this.client.seamless.forwarderTx(forwardTxParams, chainId, seamlessWallet);
|
|
21610
|
-
console.log("rs-->", rs2);
|
|
21611
21286
|
return {
|
|
21612
21287
|
code: 0,
|
|
21613
21288
|
message: "deposit success",
|
|
@@ -21666,6 +21341,282 @@ var Account = class {
|
|
|
21666
21341
|
}
|
|
21667
21342
|
};
|
|
21668
21343
|
|
|
21344
|
+
// src/api/utils.ts
|
|
21345
|
+
function encodeQueryParam(key, value) {
|
|
21346
|
+
const encodedKey = encodeURIComponent(key);
|
|
21347
|
+
return `${encodedKey}=${encodeURIComponent(typeof value === "number" ? value : `${value}`)}`;
|
|
21348
|
+
}
|
|
21349
|
+
function addQueryParam(query, key) {
|
|
21350
|
+
return encodeQueryParam(key, query[key]);
|
|
21351
|
+
}
|
|
21352
|
+
function addArrayQueryParam(query, key) {
|
|
21353
|
+
const value = query[key];
|
|
21354
|
+
return value.map((v) => encodeQueryParam(key, v)).join("&");
|
|
21355
|
+
}
|
|
21356
|
+
function toQueryString(rawQuery) {
|
|
21357
|
+
const query = rawQuery || {};
|
|
21358
|
+
const keys = Object.keys(query).filter((key) => "undefined" !== typeof query[key]);
|
|
21359
|
+
return keys.map((key) => Array.isArray(query[key]) ? addArrayQueryParam(query, key) : addQueryParam(query, key)).join("&");
|
|
21360
|
+
}
|
|
21361
|
+
function addQueryParams(rawQuery) {
|
|
21362
|
+
const queryString = toQueryString(rawQuery);
|
|
21363
|
+
return queryString ? `?${queryString}` : "";
|
|
21364
|
+
}
|
|
21365
|
+
|
|
21366
|
+
// src/manager/api/index.ts
|
|
21367
|
+
var Api = class {
|
|
21368
|
+
constructor(configManager, logger) {
|
|
21369
|
+
this.configManager = configManager;
|
|
21370
|
+
this.logger = logger;
|
|
21371
|
+
}
|
|
21372
|
+
getHost() {
|
|
21373
|
+
const isProd = !this.configManager.getConfig().isTestnet;
|
|
21374
|
+
return isProd ? "https://api.myx.finance" : "https://api-test.myx.cash";
|
|
21375
|
+
}
|
|
21376
|
+
async getTradeFlow({
|
|
21377
|
+
accessToken,
|
|
21378
|
+
address,
|
|
21379
|
+
...params
|
|
21380
|
+
}) {
|
|
21381
|
+
return http.get(
|
|
21382
|
+
`${this.getHost()}/openapi/gateway/scan/trade/flow`,
|
|
21383
|
+
params,
|
|
21384
|
+
{
|
|
21385
|
+
headers: {
|
|
21386
|
+
myx_openapi_access_token: accessToken,
|
|
21387
|
+
myx_openapi_account: address
|
|
21388
|
+
}
|
|
21389
|
+
}
|
|
21390
|
+
);
|
|
21391
|
+
}
|
|
21392
|
+
async getPoolSymbolAll() {
|
|
21393
|
+
return http.get(
|
|
21394
|
+
`${this.getHost()}/openapi/gateway/scan/pools`
|
|
21395
|
+
);
|
|
21396
|
+
}
|
|
21397
|
+
async fetchForwarderGetApi(params) {
|
|
21398
|
+
const rs = await http.get(
|
|
21399
|
+
`${this.getHost()}/forwarder/get${addQueryParams(params)}`
|
|
21400
|
+
);
|
|
21401
|
+
return rs;
|
|
21402
|
+
}
|
|
21403
|
+
async getPoolList() {
|
|
21404
|
+
return http.get(
|
|
21405
|
+
`${this.getHost()}/openapi/gateway/scan/market/list`
|
|
21406
|
+
);
|
|
21407
|
+
}
|
|
21408
|
+
async forwarderTxApi(params, chainId) {
|
|
21409
|
+
return http.post(
|
|
21410
|
+
`${this.getHost()}/forwarder/tx-v2`,
|
|
21411
|
+
params,
|
|
21412
|
+
{
|
|
21413
|
+
headers: {
|
|
21414
|
+
"myx-chain-id": chainId.toString()
|
|
21415
|
+
}
|
|
21416
|
+
}
|
|
21417
|
+
);
|
|
21418
|
+
}
|
|
21419
|
+
async getOraclePrice(chainId, poolIds = []) {
|
|
21420
|
+
if (!!poolIds.length) {
|
|
21421
|
+
return http.get(
|
|
21422
|
+
`${this.getHost()}/openapi/gateway/quote/price/oracles`,
|
|
21423
|
+
{
|
|
21424
|
+
chainId,
|
|
21425
|
+
poolIds: poolIds.join(",")
|
|
21426
|
+
}
|
|
21427
|
+
);
|
|
21428
|
+
}
|
|
21429
|
+
throw new Error("Invalid pool id");
|
|
21430
|
+
}
|
|
21431
|
+
async getPoolDetail(chainId, poolId) {
|
|
21432
|
+
return await http.get(
|
|
21433
|
+
`${this.getHost()}/openapi/gateway/scan/market/info?chainId=${chainId}&poolId=${poolId}`
|
|
21434
|
+
);
|
|
21435
|
+
}
|
|
21436
|
+
async getPoolLevelConfig({
|
|
21437
|
+
poolId,
|
|
21438
|
+
chainId
|
|
21439
|
+
}) {
|
|
21440
|
+
return http.get(
|
|
21441
|
+
`${this.getHost()}/openapi/gateway/risk/market_pool/level_config${addQueryParams({
|
|
21442
|
+
poolId,
|
|
21443
|
+
chainId
|
|
21444
|
+
})}`
|
|
21445
|
+
);
|
|
21446
|
+
}
|
|
21447
|
+
async getPositions(accessToken, address) {
|
|
21448
|
+
return await http.get(
|
|
21449
|
+
`${this.getHost()}/openapi/gateway/scan/position/open`,
|
|
21450
|
+
void 0,
|
|
21451
|
+
{
|
|
21452
|
+
headers: {
|
|
21453
|
+
myx_openapi_access_token: accessToken,
|
|
21454
|
+
myx_openapi_account: address
|
|
21455
|
+
}
|
|
21456
|
+
}
|
|
21457
|
+
);
|
|
21458
|
+
}
|
|
21459
|
+
async getOrders(accessToken, address) {
|
|
21460
|
+
return await http.get(
|
|
21461
|
+
`${this.getHost()}/openapi/gateway/scan/order/open`,
|
|
21462
|
+
void 0,
|
|
21463
|
+
{
|
|
21464
|
+
headers: {
|
|
21465
|
+
myx_openapi_access_token: accessToken,
|
|
21466
|
+
myx_openapi_account: address
|
|
21467
|
+
}
|
|
21468
|
+
}
|
|
21469
|
+
);
|
|
21470
|
+
}
|
|
21471
|
+
async getPoolOpenOrders(accessToken, address, chainId) {
|
|
21472
|
+
return await http.get(
|
|
21473
|
+
`${this.getHost()}/openapi/gateway/scan/market/pool-order/open?chainId=${chainId}`,
|
|
21474
|
+
void 0,
|
|
21475
|
+
{
|
|
21476
|
+
headers: {
|
|
21477
|
+
myx_openapi_access_token: accessToken,
|
|
21478
|
+
myx_openapi_account: address
|
|
21479
|
+
}
|
|
21480
|
+
}
|
|
21481
|
+
);
|
|
21482
|
+
}
|
|
21483
|
+
async getKlineData({ chainId, poolId, endTime, limit, interval }) {
|
|
21484
|
+
return http.get(
|
|
21485
|
+
`${this.getHost()}/openapi/gateway/quote/candles`,
|
|
21486
|
+
{
|
|
21487
|
+
chainId,
|
|
21488
|
+
poolId,
|
|
21489
|
+
endTime,
|
|
21490
|
+
limit,
|
|
21491
|
+
interval
|
|
21492
|
+
}
|
|
21493
|
+
);
|
|
21494
|
+
}
|
|
21495
|
+
async getKlineLatestBar(params) {
|
|
21496
|
+
return http.get(
|
|
21497
|
+
`${this.getHost()}/openapi/gateway/quote/candle/latest`,
|
|
21498
|
+
params
|
|
21499
|
+
);
|
|
21500
|
+
}
|
|
21501
|
+
async getTickerData({ chainId, poolIds }) {
|
|
21502
|
+
return http.get(
|
|
21503
|
+
`${this.getHost()}/openapi/gateway/quote/candle/tickers`,
|
|
21504
|
+
{
|
|
21505
|
+
chainId,
|
|
21506
|
+
poolIds: poolIds.join(",")
|
|
21507
|
+
}
|
|
21508
|
+
);
|
|
21509
|
+
}
|
|
21510
|
+
async getAllTickers() {
|
|
21511
|
+
return http.get(
|
|
21512
|
+
`${this.getHost()}/v2/mx-gateway/quote/candle/all_tickers`
|
|
21513
|
+
);
|
|
21514
|
+
}
|
|
21515
|
+
async searchMarketAuth({ accessToken, address, ...params }) {
|
|
21516
|
+
return http.get(
|
|
21517
|
+
`${this.getHost()}/openapi/gateway/scan/market/ac-search`,
|
|
21518
|
+
params,
|
|
21519
|
+
{
|
|
21520
|
+
headers: {
|
|
21521
|
+
myx_openapi_access_token: accessToken,
|
|
21522
|
+
myx_openapi_account: address
|
|
21523
|
+
}
|
|
21524
|
+
}
|
|
21525
|
+
);
|
|
21526
|
+
}
|
|
21527
|
+
async searchMarket({ ...params }) {
|
|
21528
|
+
return http.get(
|
|
21529
|
+
`${this.getHost()}/openapi/gateway/scan/market/search`,
|
|
21530
|
+
params
|
|
21531
|
+
);
|
|
21532
|
+
}
|
|
21533
|
+
async addFavorite({ accessToken, address, ...params }) {
|
|
21534
|
+
return http.get(
|
|
21535
|
+
`${this.getHost()}/openapi/gateway/scan/market/add-favorites`,
|
|
21536
|
+
params,
|
|
21537
|
+
{
|
|
21538
|
+
headers: {
|
|
21539
|
+
myx_openapi_access_token: accessToken,
|
|
21540
|
+
myx_openapi_account: address
|
|
21541
|
+
}
|
|
21542
|
+
}
|
|
21543
|
+
);
|
|
21544
|
+
}
|
|
21545
|
+
async removeFavorite({ accessToken, address, ...params }) {
|
|
21546
|
+
return http.get(
|
|
21547
|
+
`${this.getHost()}/openapi/gateway/scan/market/cancel-favorites`,
|
|
21548
|
+
params,
|
|
21549
|
+
{
|
|
21550
|
+
headers: {
|
|
21551
|
+
myx_openapi_access_token: accessToken,
|
|
21552
|
+
myx_openapi_account: address
|
|
21553
|
+
}
|
|
21554
|
+
}
|
|
21555
|
+
);
|
|
21556
|
+
}
|
|
21557
|
+
async getFavoritesList({ accessToken, address, ...params }) {
|
|
21558
|
+
return http.get(
|
|
21559
|
+
`${this.getHost()}/openapi/gateway/scan/market/favorites`,
|
|
21560
|
+
params,
|
|
21561
|
+
{
|
|
21562
|
+
headers: {
|
|
21563
|
+
myx_openapi_access_token: accessToken,
|
|
21564
|
+
myx_openapi_account: address
|
|
21565
|
+
}
|
|
21566
|
+
}
|
|
21567
|
+
);
|
|
21568
|
+
}
|
|
21569
|
+
async getBaseDetail({ ...params }) {
|
|
21570
|
+
return http.get(
|
|
21571
|
+
`${this.getHost()}/openapi/gateway/scan/market/base-details`,
|
|
21572
|
+
params
|
|
21573
|
+
);
|
|
21574
|
+
}
|
|
21575
|
+
async getMarketDetail({ ...params }) {
|
|
21576
|
+
return http.get(
|
|
21577
|
+
`${this.getHost()}/openapi/gateway/scan/market/detail`,
|
|
21578
|
+
params
|
|
21579
|
+
);
|
|
21580
|
+
}
|
|
21581
|
+
async getHistoryOrders({
|
|
21582
|
+
accessToken,
|
|
21583
|
+
address,
|
|
21584
|
+
...params
|
|
21585
|
+
}) {
|
|
21586
|
+
return http.get(
|
|
21587
|
+
`${this.getHost()}/openapi/gateway/scan/order/closed`,
|
|
21588
|
+
params,
|
|
21589
|
+
{
|
|
21590
|
+
headers: {
|
|
21591
|
+
myx_openapi_account: address,
|
|
21592
|
+
myx_openapi_access_token: accessToken
|
|
21593
|
+
}
|
|
21594
|
+
}
|
|
21595
|
+
);
|
|
21596
|
+
}
|
|
21597
|
+
async getPositionHistory({
|
|
21598
|
+
accessToken,
|
|
21599
|
+
address,
|
|
21600
|
+
...params
|
|
21601
|
+
}) {
|
|
21602
|
+
return http.get(
|
|
21603
|
+
`${this.getHost()}/openapi/gateway/scan/position/closed`,
|
|
21604
|
+
params,
|
|
21605
|
+
{
|
|
21606
|
+
headers: {
|
|
21607
|
+
myx_openapi_account: address,
|
|
21608
|
+
myx_openapi_access_token: accessToken
|
|
21609
|
+
}
|
|
21610
|
+
}
|
|
21611
|
+
);
|
|
21612
|
+
}
|
|
21613
|
+
async getMarketList() {
|
|
21614
|
+
return http.get(
|
|
21615
|
+
`${this.getHost()}/openapi/gateway/scan/market`
|
|
21616
|
+
);
|
|
21617
|
+
}
|
|
21618
|
+
};
|
|
21619
|
+
|
|
21669
21620
|
// src/manager/seamless/index.ts
|
|
21670
21621
|
var import_crypto_js = __toESM(require("crypto-js"));
|
|
21671
21622
|
var import_ethers27 = require("ethers");
|
|
@@ -21841,11 +21792,12 @@ async function signPermit(provider, contract, owner, spender, value, nonce, dead
|
|
|
21841
21792
|
return { v, r, s };
|
|
21842
21793
|
}
|
|
21843
21794
|
var Seamless = class {
|
|
21844
|
-
constructor(configManager, logger, utils, account) {
|
|
21795
|
+
constructor(configManager, logger, utils, account, api) {
|
|
21845
21796
|
this.configManager = configManager;
|
|
21846
21797
|
this.logger = logger;
|
|
21847
21798
|
this.utils = utils;
|
|
21848
21799
|
this.account = account;
|
|
21800
|
+
this.api = api;
|
|
21849
21801
|
}
|
|
21850
21802
|
async onCheckRelayer(account, relayer, chainId) {
|
|
21851
21803
|
const forwarderContract = await getForwarderContract(chainId);
|
|
@@ -21925,7 +21877,6 @@ var Seamless = class {
|
|
|
21925
21877
|
data,
|
|
21926
21878
|
nonce
|
|
21927
21879
|
}, chainId, provider) {
|
|
21928
|
-
const isProd = !this.configManager.getConfig().isTestnet;
|
|
21929
21880
|
const forwarderContract = await getForwarderContract(chainId);
|
|
21930
21881
|
const forwarderJsonRpcContractDomain = await forwarderContract.eip712Domain();
|
|
21931
21882
|
const domain = {
|
|
@@ -21944,7 +21895,7 @@ var Seamless = class {
|
|
|
21944
21895
|
deadline,
|
|
21945
21896
|
data
|
|
21946
21897
|
});
|
|
21947
|
-
const txRs = await forwarderTxApi({ from, to, value, gas, nonce, data, deadline, signature }, chainId
|
|
21898
|
+
const txRs = await this.api.forwarderTxApi({ from, to, value, gas, nonce, data, deadline, signature }, chainId);
|
|
21948
21899
|
return txRs;
|
|
21949
21900
|
}
|
|
21950
21901
|
async authorizeSeamlessAccount({ approve: approve2, seamlessAddress, chainId }) {
|
|
@@ -21994,7 +21945,7 @@ var Seamless = class {
|
|
|
21994
21945
|
if (!txRs.data?.txHash) {
|
|
21995
21946
|
const retryOptions = { n: 10, minWait: 250, maxWait: 1e3 };
|
|
21996
21947
|
const { promise } = retry(async () => {
|
|
21997
|
-
const getRs = await fetchForwarderGetApi({
|
|
21948
|
+
const getRs = await this.api.fetchForwarderGetApi({
|
|
21998
21949
|
requestId: txRs.data?.requestId
|
|
21999
21950
|
});
|
|
22000
21951
|
if (getRs.data?.status === 9 /* EXECUTED */) {
|
|
@@ -22172,15 +22123,16 @@ var MyxClient = class {
|
|
|
22172
22123
|
this.logger = new Logger({
|
|
22173
22124
|
logLevel: options.logLevel
|
|
22174
22125
|
});
|
|
22126
|
+
const lp = MxSDK.getInstance();
|
|
22127
|
+
lp.setConfigManager(this.configManager);
|
|
22175
22128
|
this.utils = new Utils(this.configManager, this.logger);
|
|
22129
|
+
this.api = new Api(this.configManager, this.logger);
|
|
22176
22130
|
this.account = new Account(this.configManager, this.logger, this.utils, this);
|
|
22177
|
-
this.seamless = new Seamless(this.configManager, this.logger, this.utils, this.account);
|
|
22178
|
-
this.markets = new Markets(this.configManager, this.utils);
|
|
22179
|
-
this.position = new Position(this.configManager, this.logger, this.utils, this.seamless, this.account);
|
|
22180
|
-
this.order = new Order(this.configManager, this.logger, this.utils, this.seamless, this.account);
|
|
22131
|
+
this.seamless = new Seamless(this.configManager, this.logger, this.utils, this.account, this.api);
|
|
22132
|
+
this.markets = new Markets(this.configManager, this.utils, this.api);
|
|
22133
|
+
this.position = new Position(this.configManager, this.logger, this.utils, this.seamless, this.account, this.api);
|
|
22134
|
+
this.order = new Order(this.configManager, this.logger, this.utils, this.seamless, this.account, this.api);
|
|
22181
22135
|
this.subscription = new SubScription(this.configManager, this.logger);
|
|
22182
|
-
const lp = MxSDK.getInstance();
|
|
22183
|
-
lp.setConfigManager(this.configManager);
|
|
22184
22136
|
}
|
|
22185
22137
|
/**
|
|
22186
22138
|
* auth the client
|
|
@@ -22235,48 +22187,31 @@ var MyxClient = class {
|
|
|
22235
22187
|
TradeFlowTypeEnum,
|
|
22236
22188
|
TriggerType,
|
|
22237
22189
|
TriggerTypeEnum,
|
|
22238
|
-
addFavorite,
|
|
22239
22190
|
approve,
|
|
22240
22191
|
base,
|
|
22241
22192
|
bigintAmountSlipperCalculator,
|
|
22242
22193
|
bigintTradingGasPriceWithRatio,
|
|
22243
22194
|
bigintTradingGasToRatioCalculator,
|
|
22244
|
-
fetchForwarderGetApi,
|
|
22245
22195
|
formatUnits,
|
|
22246
|
-
forwarderTxApi,
|
|
22247
|
-
getAllTickers,
|
|
22248
22196
|
getAllowanceApproved,
|
|
22249
22197
|
getBalanceOf,
|
|
22250
22198
|
getBaseDetail,
|
|
22251
22199
|
getBaseUrlByEnv,
|
|
22252
|
-
getFavoritesList,
|
|
22253
22200
|
getForwardUrlByEnv,
|
|
22254
|
-
getHistoryOrders,
|
|
22255
|
-
getKlineData,
|
|
22256
|
-
getKlineLatestBar,
|
|
22257
22201
|
getMarketDetail,
|
|
22258
22202
|
getMarketList,
|
|
22259
22203
|
getOraclePrice,
|
|
22260
|
-
getOrders,
|
|
22261
22204
|
getPoolDetail,
|
|
22262
|
-
getPoolLevelConfig,
|
|
22263
22205
|
getPoolList,
|
|
22264
22206
|
getPoolOpenOrders,
|
|
22265
|
-
getPoolSymbolAll,
|
|
22266
|
-
getPositionHistory,
|
|
22267
|
-
getPositions,
|
|
22268
22207
|
getPriceData,
|
|
22269
22208
|
getPricesData,
|
|
22270
22209
|
getTickerData,
|
|
22271
22210
|
getTokenInfo,
|
|
22272
|
-
getTradeFlow,
|
|
22273
22211
|
market,
|
|
22274
22212
|
parseUnits,
|
|
22275
22213
|
pool,
|
|
22276
|
-
quote
|
|
22277
|
-
removeFavorite,
|
|
22278
|
-
searchMarket,
|
|
22279
|
-
searchMarketAuth
|
|
22214
|
+
quote
|
|
22280
22215
|
});
|
|
22281
22216
|
/**
|
|
22282
22217
|
* MyxLogger
|