@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.mjs
CHANGED
|
@@ -1731,7 +1731,7 @@ var RotationProvider = class extends BaseProvider {
|
|
|
1731
1731
|
// package.json
|
|
1732
1732
|
var package_default = {
|
|
1733
1733
|
name: "@myx-trade/sdk",
|
|
1734
|
-
version: "0.1.
|
|
1734
|
+
version: "0.1.193",
|
|
1735
1735
|
private: false,
|
|
1736
1736
|
publishConfig: {
|
|
1737
1737
|
access: "public"
|
|
@@ -1847,28 +1847,6 @@ var http = {
|
|
|
1847
1847
|
}
|
|
1848
1848
|
};
|
|
1849
1849
|
|
|
1850
|
-
// src/api/utils.ts
|
|
1851
|
-
function encodeQueryParam(key, value) {
|
|
1852
|
-
const encodedKey = encodeURIComponent(key);
|
|
1853
|
-
return `${encodedKey}=${encodeURIComponent(typeof value === "number" ? value : `${value}`)}`;
|
|
1854
|
-
}
|
|
1855
|
-
function addQueryParam(query, key) {
|
|
1856
|
-
return encodeQueryParam(key, query[key]);
|
|
1857
|
-
}
|
|
1858
|
-
function addArrayQueryParam(query, key) {
|
|
1859
|
-
const value = query[key];
|
|
1860
|
-
return value.map((v) => encodeQueryParam(key, v)).join("&");
|
|
1861
|
-
}
|
|
1862
|
-
function toQueryString(rawQuery) {
|
|
1863
|
-
const query = rawQuery || {};
|
|
1864
|
-
const keys = Object.keys(query).filter((key) => "undefined" !== typeof query[key]);
|
|
1865
|
-
return keys.map((key) => Array.isArray(query[key]) ? addArrayQueryParam(query, key) : addQueryParam(query, key)).join("&");
|
|
1866
|
-
}
|
|
1867
|
-
function addQueryParams(rawQuery) {
|
|
1868
|
-
const queryString = toQueryString(rawQuery);
|
|
1869
|
-
return queryString ? `?${queryString}` : "";
|
|
1870
|
-
}
|
|
1871
|
-
|
|
1872
1850
|
// src/api/type.ts
|
|
1873
1851
|
var ErrorCode = /* @__PURE__ */ ((ErrorCode3) => {
|
|
1874
1852
|
ErrorCode3[ErrorCode3["SUCCESS"] = 9200] = "SUCCESS";
|
|
@@ -1891,10 +1869,10 @@ var MarketPoolState = /* @__PURE__ */ ((MarketPoolState3) => {
|
|
|
1891
1869
|
MarketPoolState3[MarketPoolState3["Bench"] = 4] = "Bench";
|
|
1892
1870
|
return MarketPoolState3;
|
|
1893
1871
|
})(MarketPoolState || {});
|
|
1894
|
-
var OracleType = /* @__PURE__ */ ((
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
return
|
|
1872
|
+
var OracleType = /* @__PURE__ */ ((OracleType6) => {
|
|
1873
|
+
OracleType6[OracleType6["Chainlink"] = 1] = "Chainlink";
|
|
1874
|
+
OracleType6[OracleType6["Pyth"] = 2] = "Pyth";
|
|
1875
|
+
return OracleType6;
|
|
1898
1876
|
})(OracleType || {});
|
|
1899
1877
|
var HttpKlineIntervalEnum = /* @__PURE__ */ ((HttpKlineIntervalEnum2) => {
|
|
1900
1878
|
HttpKlineIntervalEnum2[HttpKlineIntervalEnum2["Minute1"] = 1] = "Minute1";
|
|
@@ -1993,23 +1971,6 @@ var ExecTypeEnum = /* @__PURE__ */ ((ExecTypeEnum2) => {
|
|
|
1993
1971
|
ExecTypeEnum2[ExecTypeEnum2["MarketClose"] = 9] = "MarketClose";
|
|
1994
1972
|
return ExecTypeEnum2;
|
|
1995
1973
|
})(ExecTypeEnum || {});
|
|
1996
|
-
var getHistoryOrders = async ({
|
|
1997
|
-
accessToken,
|
|
1998
|
-
address,
|
|
1999
|
-
...params
|
|
2000
|
-
}, envParams) => {
|
|
2001
|
-
const isProd = envParams?.isProd ?? true;
|
|
2002
|
-
return http.get(
|
|
2003
|
-
`${getBaseUrlByEnv(isProd)}/openapi/gateway/scan/order/closed`,
|
|
2004
|
-
params,
|
|
2005
|
-
{
|
|
2006
|
-
headers: {
|
|
2007
|
-
myx_openapi_account: address,
|
|
2008
|
-
myx_openapi_access_token: accessToken
|
|
2009
|
-
}
|
|
2010
|
-
}
|
|
2011
|
-
);
|
|
2012
|
-
};
|
|
2013
1974
|
var CloseTypeEnum = /* @__PURE__ */ ((CloseTypeEnum2) => {
|
|
2014
1975
|
CloseTypeEnum2[CloseTypeEnum2["Open"] = 0] = "Open";
|
|
2015
1976
|
CloseTypeEnum2[CloseTypeEnum2["PartialClose"] = 1] = "PartialClose";
|
|
@@ -2023,59 +1984,14 @@ var CloseTypeEnum = /* @__PURE__ */ ((CloseTypeEnum2) => {
|
|
|
2023
1984
|
CloseTypeEnum2[CloseTypeEnum2["Increase"] = 9] = "Increase";
|
|
2024
1985
|
return CloseTypeEnum2;
|
|
2025
1986
|
})(CloseTypeEnum || {});
|
|
2026
|
-
var getPositionHistory = async ({
|
|
2027
|
-
accessToken,
|
|
2028
|
-
address,
|
|
2029
|
-
...params
|
|
2030
|
-
}, envParams) => {
|
|
2031
|
-
const isProd = envParams?.isProd ?? true;
|
|
2032
|
-
return http.get(
|
|
2033
|
-
`${getBaseUrlByEnv(isProd)}/openapi/gateway/scan/position/closed`,
|
|
2034
|
-
params,
|
|
2035
|
-
{
|
|
2036
|
-
headers: {
|
|
2037
|
-
myx_openapi_account: address,
|
|
2038
|
-
myx_openapi_access_token: accessToken
|
|
2039
|
-
}
|
|
2040
|
-
}
|
|
2041
|
-
);
|
|
2042
|
-
};
|
|
2043
1987
|
var TradeFlowAccountTypeEnum = /* @__PURE__ */ ((TradeFlowAccountTypeEnum2) => {
|
|
2044
1988
|
TradeFlowAccountTypeEnum2[TradeFlowAccountTypeEnum2["MarginAccount"] = 1] = "MarginAccount";
|
|
2045
1989
|
TradeFlowAccountTypeEnum2[TradeFlowAccountTypeEnum2["WalletAccount"] = 2] = "WalletAccount";
|
|
2046
1990
|
TradeFlowAccountTypeEnum2[TradeFlowAccountTypeEnum2["ReferralReward"] = 3] = "ReferralReward";
|
|
2047
1991
|
return TradeFlowAccountTypeEnum2;
|
|
2048
1992
|
})(TradeFlowAccountTypeEnum || {});
|
|
2049
|
-
var getTradeFlow = async ({
|
|
2050
|
-
accessToken,
|
|
2051
|
-
address,
|
|
2052
|
-
...params
|
|
2053
|
-
}, envParams) => {
|
|
2054
|
-
const isProd = envParams?.isProd ?? true;
|
|
2055
|
-
return http.get(
|
|
2056
|
-
`${getBaseUrlByEnv(isProd)}/openapi/gateway/scan/trade/flow`,
|
|
2057
|
-
params,
|
|
2058
|
-
{
|
|
2059
|
-
headers: {
|
|
2060
|
-
myx_openapi_access_token: accessToken,
|
|
2061
|
-
myx_openapi_account: address
|
|
2062
|
-
}
|
|
2063
|
-
}
|
|
2064
|
-
);
|
|
2065
|
-
};
|
|
2066
1993
|
|
|
2067
1994
|
// src/api/seamless/index.ts
|
|
2068
|
-
var forwarderTxApi = async (params, chainId, isProd = true) => {
|
|
2069
|
-
return http.post(
|
|
2070
|
-
`${getForwardUrlByEnv(isProd)}/forwarder/tx-v2`,
|
|
2071
|
-
params,
|
|
2072
|
-
{
|
|
2073
|
-
headers: {
|
|
2074
|
-
"myx-chain-id": chainId.toString()
|
|
2075
|
-
}
|
|
2076
|
-
}
|
|
2077
|
-
);
|
|
2078
|
-
};
|
|
2079
1995
|
var ForwarderGetStatus = /* @__PURE__ */ ((ForwarderGetStatus2) => {
|
|
2080
1996
|
ForwarderGetStatus2[ForwarderGetStatus2["EXECUTING"] = 1] = "EXECUTING";
|
|
2081
1997
|
ForwarderGetStatus2[ForwarderGetStatus2["BROADCAST_FAILED"] = 2] = "BROADCAST_FAILED";
|
|
@@ -2083,40 +1999,26 @@ var ForwarderGetStatus = /* @__PURE__ */ ((ForwarderGetStatus2) => {
|
|
|
2083
1999
|
ForwarderGetStatus2[ForwarderGetStatus2["EXECUTED"] = 9] = "EXECUTED";
|
|
2084
2000
|
return ForwarderGetStatus2;
|
|
2085
2001
|
})(ForwarderGetStatus || {});
|
|
2086
|
-
var fetchForwarderGetApi = async (params, isProd = true) => {
|
|
2087
|
-
const rs = await http.get(
|
|
2088
|
-
`${getForwardUrlByEnv(isProd)}/forwarder/get${addQueryParams(params)}`
|
|
2089
|
-
);
|
|
2090
|
-
return rs;
|
|
2091
|
-
};
|
|
2092
2002
|
|
|
2093
2003
|
// src/api/pool/index.ts
|
|
2094
|
-
var getPoolList = async ({
|
|
2095
|
-
isProd = true
|
|
2096
|
-
}) => {
|
|
2004
|
+
var getPoolList = async () => {
|
|
2097
2005
|
return http.get(
|
|
2098
|
-
`${getBaseUrlByEnv(
|
|
2099
|
-
);
|
|
2100
|
-
};
|
|
2101
|
-
var getPoolSymbolAll = async ({
|
|
2102
|
-
isProd = true
|
|
2103
|
-
}) => {
|
|
2104
|
-
return http.get(
|
|
2105
|
-
`${getBaseUrlByEnv(isProd)}/openapi/gateway/scan/pools`
|
|
2006
|
+
`${getBaseUrlByEnv()}/openapi/gateway/scan/market/list`
|
|
2106
2007
|
);
|
|
2107
2008
|
};
|
|
2108
2009
|
|
|
2109
2010
|
// src/api/index.ts
|
|
2110
2011
|
var getBaseUrlByEnv = (isProd) => {
|
|
2111
|
-
|
|
2012
|
+
const _isProd = !!isProd || !web3_default.getConfigManager()?.getConfig()?.isTestnet;
|
|
2013
|
+
return _isProd ? "https://api.myx.finance" : "https://api-test.myx.cash";
|
|
2112
2014
|
};
|
|
2113
2015
|
var getForwardUrlByEnv = (isProd) => {
|
|
2114
|
-
return isProd
|
|
2016
|
+
return `${getBaseUrlByEnv(isProd)}/v2/agent`;
|
|
2115
2017
|
};
|
|
2116
|
-
var getOraclePrice = async (chainId, poolIds = []
|
|
2018
|
+
var getOraclePrice = async (chainId, poolIds = []) => {
|
|
2117
2019
|
if (!!poolIds.length) {
|
|
2118
2020
|
return http.get(
|
|
2119
|
-
`${getBaseUrlByEnv(
|
|
2021
|
+
`${getBaseUrlByEnv()}/openapi/gateway/quote/price/oracles`,
|
|
2120
2022
|
{
|
|
2121
2023
|
chainId,
|
|
2122
2024
|
poolIds: poolIds.join(",")
|
|
@@ -2125,32 +2027,15 @@ var getOraclePrice = async (chainId, poolIds = [], isProd = true) => {
|
|
|
2125
2027
|
}
|
|
2126
2028
|
return Promise.reject(new Error("Invalid pool id"));
|
|
2127
2029
|
};
|
|
2128
|
-
var
|
|
2129
|
-
poolId,
|
|
2130
|
-
chainId,
|
|
2131
|
-
isProd = true
|
|
2132
|
-
}) => {
|
|
2133
|
-
return http.get(
|
|
2134
|
-
`${getBaseUrlByEnv(
|
|
2135
|
-
isProd
|
|
2136
|
-
)}/openapi/gateway/risk/market_pool/level_config${addQueryParams({
|
|
2137
|
-
poolId,
|
|
2138
|
-
chainId
|
|
2139
|
-
})}`
|
|
2140
|
-
);
|
|
2141
|
-
};
|
|
2142
|
-
var getPoolDetail = async (chainId, poolId, isProd = true) => {
|
|
2030
|
+
var getPoolDetail = async (chainId, poolId, isProd) => {
|
|
2143
2031
|
return await http.get(
|
|
2144
|
-
`${getBaseUrlByEnv(
|
|
2145
|
-
isProd
|
|
2146
|
-
)}/openapi/gateway/scan/market/info?chainId=${chainId}&poolId=${poolId}`
|
|
2032
|
+
`${getBaseUrlByEnv(isProd)}/openapi/gateway/scan/market/info?chainId=${chainId}&poolId=${poolId}`
|
|
2147
2033
|
);
|
|
2148
2034
|
};
|
|
2149
|
-
var
|
|
2035
|
+
var getPoolOpenOrders = async (accessToken, address, chainId) => {
|
|
2150
2036
|
return await http.get(
|
|
2151
|
-
`${getBaseUrlByEnv(
|
|
2037
|
+
`${getBaseUrlByEnv()}/openapi/gateway/scan/market/pool-order/open?chainId=${chainId}`,
|
|
2152
2038
|
void 0,
|
|
2153
|
-
// params
|
|
2154
2039
|
{
|
|
2155
2040
|
headers: {
|
|
2156
2041
|
myx_openapi_access_token: accessToken,
|
|
@@ -2159,52 +2044,6 @@ var getPositions = async (accessToken, address, isProd = true) => {
|
|
|
2159
2044
|
}
|
|
2160
2045
|
);
|
|
2161
2046
|
};
|
|
2162
|
-
var getOrders = async (accessToken, address, isProd = true) => {
|
|
2163
|
-
return await http.get(
|
|
2164
|
-
`${getBaseUrlByEnv(isProd)}/openapi/gateway/scan/order/open`,
|
|
2165
|
-
void 0,
|
|
2166
|
-
{
|
|
2167
|
-
headers: {
|
|
2168
|
-
myx_openapi_access_token: accessToken,
|
|
2169
|
-
myx_openapi_account: address
|
|
2170
|
-
}
|
|
2171
|
-
}
|
|
2172
|
-
);
|
|
2173
|
-
};
|
|
2174
|
-
var getPoolOpenOrders = async (accessToken, address, chainId, isProd = true) => {
|
|
2175
|
-
return await http.get(
|
|
2176
|
-
`${getBaseUrlByEnv(
|
|
2177
|
-
isProd
|
|
2178
|
-
)}/openapi/gateway/scan/market/pool-order/open?chainId=${chainId}`,
|
|
2179
|
-
void 0,
|
|
2180
|
-
{
|
|
2181
|
-
headers: {
|
|
2182
|
-
myx_openapi_access_token: accessToken,
|
|
2183
|
-
myx_openapi_account: address
|
|
2184
|
-
}
|
|
2185
|
-
}
|
|
2186
|
-
);
|
|
2187
|
-
};
|
|
2188
|
-
var getKlineData = ({ chainId, poolId, endTime, limit, interval }, envParams) => {
|
|
2189
|
-
const isProd = envParams?.isProd ?? true;
|
|
2190
|
-
return http.get(
|
|
2191
|
-
`${getBaseUrlByEnv(isProd)}/openapi/gateway/quote/candles`,
|
|
2192
|
-
{
|
|
2193
|
-
chainId,
|
|
2194
|
-
poolId,
|
|
2195
|
-
endTime,
|
|
2196
|
-
limit,
|
|
2197
|
-
interval
|
|
2198
|
-
}
|
|
2199
|
-
);
|
|
2200
|
-
};
|
|
2201
|
-
var getKlineLatestBar = async (params, envParams) => {
|
|
2202
|
-
const isProd = envParams?.isProd ?? true;
|
|
2203
|
-
return http.get(
|
|
2204
|
-
`${getBaseUrlByEnv(isProd)}/openapi/gateway/quote/candle/latest`,
|
|
2205
|
-
params
|
|
2206
|
-
);
|
|
2207
|
-
};
|
|
2208
2047
|
var getTickerData = async ({ chainId, poolIds }, envParams) => {
|
|
2209
2048
|
const isProd = envParams?.isProd ?? true;
|
|
2210
2049
|
return http.get(
|
|
@@ -2215,93 +2054,21 @@ var getTickerData = async ({ chainId, poolIds }, envParams) => {
|
|
|
2215
2054
|
}
|
|
2216
2055
|
);
|
|
2217
2056
|
};
|
|
2218
|
-
var
|
|
2219
|
-
const isProd = envParams?.isProd ?? true;
|
|
2220
|
-
return http.get(
|
|
2221
|
-
`${getBaseUrlByEnv(isProd)}/v2/mx-gateway/quote/candle/all_tickers`
|
|
2222
|
-
);
|
|
2223
|
-
};
|
|
2224
|
-
var searchMarketAuth = async ({ accessToken, address, ...params }, envParams) => {
|
|
2225
|
-
const isProd = envParams?.isProd ?? true;
|
|
2226
|
-
return http.get(
|
|
2227
|
-
`${getBaseUrlByEnv(isProd)}/openapi/gateway/scan/market/ac-search`,
|
|
2228
|
-
params,
|
|
2229
|
-
{
|
|
2230
|
-
headers: {
|
|
2231
|
-
myx_openapi_access_token: accessToken,
|
|
2232
|
-
myx_openapi_account: address
|
|
2233
|
-
}
|
|
2234
|
-
}
|
|
2235
|
-
);
|
|
2236
|
-
};
|
|
2237
|
-
var searchMarket = async ({ ...params }, envParams) => {
|
|
2238
|
-
const isProd = envParams?.isProd ?? true;
|
|
2239
|
-
return http.get(
|
|
2240
|
-
`${getBaseUrlByEnv(isProd)}/openapi/gateway/scan/market/search`,
|
|
2241
|
-
params
|
|
2242
|
-
);
|
|
2243
|
-
};
|
|
2244
|
-
var addFavorite = async ({ accessToken, address, ...params }, envParams) => {
|
|
2245
|
-
const isProd = envParams?.isProd ?? true;
|
|
2246
|
-
return http.get(
|
|
2247
|
-
`${getBaseUrlByEnv(isProd)}/openapi/gateway/scan/market/add-favorites`,
|
|
2248
|
-
params,
|
|
2249
|
-
{
|
|
2250
|
-
headers: {
|
|
2251
|
-
myx_openapi_access_token: accessToken,
|
|
2252
|
-
myx_openapi_account: address
|
|
2253
|
-
}
|
|
2254
|
-
}
|
|
2255
|
-
);
|
|
2256
|
-
};
|
|
2257
|
-
var removeFavorite = async ({
|
|
2258
|
-
accessToken,
|
|
2259
|
-
address,
|
|
2260
|
-
...params
|
|
2261
|
-
}, envParams) => {
|
|
2262
|
-
const isProd = envParams?.isProd ?? true;
|
|
2263
|
-
return http.get(
|
|
2264
|
-
`${getBaseUrlByEnv(isProd)}/openapi/gateway/scan/market/cancel-favorites`,
|
|
2265
|
-
params,
|
|
2266
|
-
{
|
|
2267
|
-
headers: {
|
|
2268
|
-
myx_openapi_access_token: accessToken,
|
|
2269
|
-
myx_openapi_account: address
|
|
2270
|
-
}
|
|
2271
|
-
}
|
|
2272
|
-
);
|
|
2273
|
-
};
|
|
2274
|
-
var getFavoritesList = async ({ accessToken, address, ...params }, envParams) => {
|
|
2275
|
-
const isProd = envParams?.isProd ?? true;
|
|
2057
|
+
var getBaseDetail = async ({ ...params }) => {
|
|
2276
2058
|
return http.get(
|
|
2277
|
-
`${getBaseUrlByEnv(
|
|
2278
|
-
params,
|
|
2279
|
-
{
|
|
2280
|
-
headers: {
|
|
2281
|
-
myx_openapi_access_token: accessToken,
|
|
2282
|
-
myx_openapi_account: address
|
|
2283
|
-
}
|
|
2284
|
-
}
|
|
2285
|
-
);
|
|
2286
|
-
};
|
|
2287
|
-
var getBaseDetail = async ({ ...params }, envParams) => {
|
|
2288
|
-
const isProd = envParams?.isProd ?? true;
|
|
2289
|
-
return http.get(
|
|
2290
|
-
`${getBaseUrlByEnv(isProd)}/openapi/gateway/scan/market/base-details`,
|
|
2059
|
+
`${getBaseUrlByEnv()}/openapi/gateway/scan/market/base-details`,
|
|
2291
2060
|
params
|
|
2292
2061
|
);
|
|
2293
2062
|
};
|
|
2294
|
-
var getMarketDetail = async ({ ...params }
|
|
2295
|
-
const isProd = envParams?.isProd ?? true;
|
|
2063
|
+
var getMarketDetail = async ({ ...params }) => {
|
|
2296
2064
|
return http.get(
|
|
2297
|
-
`${getBaseUrlByEnv(
|
|
2065
|
+
`${getBaseUrlByEnv()}/openapi/gateway/scan/market/detail`,
|
|
2298
2066
|
params
|
|
2299
2067
|
);
|
|
2300
2068
|
};
|
|
2301
|
-
var getMarketList = async (
|
|
2302
|
-
const isProd = envParams?.isProd ?? true;
|
|
2069
|
+
var getMarketList = async () => {
|
|
2303
2070
|
return http.get(
|
|
2304
|
-
`${getBaseUrlByEnv(
|
|
2071
|
+
`${getBaseUrlByEnv()}/openapi/gateway/scan/market`
|
|
2305
2072
|
);
|
|
2306
2073
|
};
|
|
2307
2074
|
|
|
@@ -2371,6 +2138,7 @@ if (typeof window !== "undefined") {
|
|
|
2371
2138
|
} else if (typeof globalThis !== "undefined") {
|
|
2372
2139
|
globalThis.MxSDK = sdk;
|
|
2373
2140
|
}
|
|
2141
|
+
var web3_default = sdk;
|
|
2374
2142
|
var getWalletProvider = async (chainId) => {
|
|
2375
2143
|
try {
|
|
2376
2144
|
const walletClient = sdk.getConfigManager()?.getConfig()?.walletClient;
|
|
@@ -12074,9 +11842,9 @@ var getPricesData = async (chainId, poolIds) => {
|
|
|
12074
11842
|
const result = await parsePriceData(chainId, rs.data);
|
|
12075
11843
|
return result;
|
|
12076
11844
|
};
|
|
12077
|
-
var getPriceData = async (chainId, poolId
|
|
11845
|
+
var getPriceData = async (chainId, poolId) => {
|
|
12078
11846
|
if (!poolId) return;
|
|
12079
|
-
const rs = await getOraclePrice(chainId, [poolId]
|
|
11847
|
+
const rs = await getOraclePrice(chainId, [poolId]);
|
|
12080
11848
|
const data = rs?.data?.[0];
|
|
12081
11849
|
if (!data) {
|
|
12082
11850
|
throw new Error(`Unable to get price for ${poolId} in the deposit`);
|
|
@@ -12333,7 +12101,7 @@ var deposit = async (params) => {
|
|
|
12333
12101
|
let value = 0n;
|
|
12334
12102
|
let amountOut;
|
|
12335
12103
|
if (isNeedPrice) {
|
|
12336
|
-
const priceData = await getPriceData(chainId, poolId
|
|
12104
|
+
const priceData = await getPriceData(chainId, poolId);
|
|
12337
12105
|
if (!priceData) return;
|
|
12338
12106
|
const referencePrice = parseUnits7(priceData.price, COMMON_PRICE_DECIMALS);
|
|
12339
12107
|
price.push({
|
|
@@ -12403,7 +12171,7 @@ var withdraw = async (params) => {
|
|
|
12403
12171
|
let value = 0n;
|
|
12404
12172
|
let amountOut;
|
|
12405
12173
|
if (isNeedPrice) {
|
|
12406
|
-
const priceData = await getPriceData(chainId, poolId
|
|
12174
|
+
const priceData = await getPriceData(chainId, poolId);
|
|
12407
12175
|
if (!priceData) return;
|
|
12408
12176
|
const referencePrice = parseUnits8(priceData.price, COMMON_PRICE_DECIMALS);
|
|
12409
12177
|
price.push({
|
|
@@ -12475,7 +12243,7 @@ var getLpPrice = async (chainId, poolId) => {
|
|
|
12475
12243
|
try {
|
|
12476
12244
|
const contract = await getBasePoolContract(chainId);
|
|
12477
12245
|
let price = 0n;
|
|
12478
|
-
const res = await getPriceData(chainId, poolId
|
|
12246
|
+
const res = await getPriceData(chainId, poolId);
|
|
12479
12247
|
if (res?.price) {
|
|
12480
12248
|
price = parseUnits10(res.price, COMMON_PRICE_DECIMALS);
|
|
12481
12249
|
}
|
|
@@ -12567,7 +12335,7 @@ var deposit2 = async (params) => {
|
|
|
12567
12335
|
let value = 0n;
|
|
12568
12336
|
let amountOut;
|
|
12569
12337
|
if (isNeedPrice) {
|
|
12570
|
-
const priceData = await getPriceData(chainId, poolId
|
|
12338
|
+
const priceData = await getPriceData(chainId, poolId);
|
|
12571
12339
|
if (!priceData) return;
|
|
12572
12340
|
const referencePrice = parseUnits11(priceData.price, COMMON_PRICE_DECIMALS);
|
|
12573
12341
|
price.push({
|
|
@@ -12637,7 +12405,7 @@ var withdraw2 = async (params) => {
|
|
|
12637
12405
|
let value = 0n;
|
|
12638
12406
|
let amountOut;
|
|
12639
12407
|
if (isNeedPrice) {
|
|
12640
|
-
const priceData = await getPriceData(chainId, poolId
|
|
12408
|
+
const priceData = await getPriceData(chainId, poolId);
|
|
12641
12409
|
if (!priceData) return;
|
|
12642
12410
|
const referencePrice = parseUnits12(priceData.price, COMMON_PRICE_DECIMALS);
|
|
12643
12411
|
price.push({
|
|
@@ -12839,7 +12607,7 @@ var getLpPrice2 = async (chainId, poolId) => {
|
|
|
12839
12607
|
try {
|
|
12840
12608
|
const contract = await getQuotePoolContract(chainId);
|
|
12841
12609
|
let price = 0n;
|
|
12842
|
-
const res = await getPriceData(chainId, poolId
|
|
12610
|
+
const res = await getPriceData(chainId, poolId);
|
|
12843
12611
|
if (res?.price) {
|
|
12844
12612
|
price = parseUnits16(res.price, COMMON_PRICE_DECIMALS);
|
|
12845
12613
|
}
|
|
@@ -14123,18 +13891,19 @@ var ConfigManager = class {
|
|
|
14123
13891
|
|
|
14124
13892
|
// src/manager/markets/index.ts
|
|
14125
13893
|
var Markets = class {
|
|
14126
|
-
constructor(configManager, utils) {
|
|
13894
|
+
constructor(configManager, utils, api) {
|
|
14127
13895
|
this.configManager = configManager;
|
|
14128
13896
|
this.utils = utils;
|
|
13897
|
+
this.api = api;
|
|
14129
13898
|
}
|
|
14130
13899
|
getMarkets() {
|
|
14131
13900
|
return Promise.resolve([]);
|
|
14132
13901
|
}
|
|
14133
|
-
async getPoolLevelConfig(poolId) {
|
|
13902
|
+
async getPoolLevelConfig(poolId, chainId) {
|
|
14134
13903
|
const config = this.configManager.getConfig();
|
|
14135
|
-
return (await getPoolLevelConfig({
|
|
13904
|
+
return (await this.api.getPoolLevelConfig({
|
|
14136
13905
|
poolId,
|
|
14137
|
-
chainId
|
|
13906
|
+
chainId
|
|
14138
13907
|
})).data;
|
|
14139
13908
|
}
|
|
14140
13909
|
/**
|
|
@@ -14145,13 +13914,10 @@ var Markets = class {
|
|
|
14145
13914
|
...params
|
|
14146
13915
|
}) {
|
|
14147
13916
|
const config = this.configManager.getConfig();
|
|
14148
|
-
return (await getKlineData(
|
|
13917
|
+
return (await this.api.getKlineData(
|
|
14149
13918
|
{
|
|
14150
13919
|
...params,
|
|
14151
13920
|
interval: this.utils.transferKlineResolutionToInterval(interval)
|
|
14152
|
-
},
|
|
14153
|
-
{
|
|
14154
|
-
isProd: !config?.isTestnet
|
|
14155
13921
|
}
|
|
14156
13922
|
)).data;
|
|
14157
13923
|
}
|
|
@@ -14160,13 +13926,10 @@ var Markets = class {
|
|
|
14160
13926
|
...params
|
|
14161
13927
|
}) {
|
|
14162
13928
|
const config = this.configManager.getConfig();
|
|
14163
|
-
return (await getKlineLatestBar(
|
|
13929
|
+
return (await this.api.getKlineLatestBar(
|
|
14164
13930
|
{
|
|
14165
13931
|
...params,
|
|
14166
13932
|
interval: this.utils.transferKlineResolutionToInterval(interval)
|
|
14167
|
-
},
|
|
14168
|
-
{
|
|
14169
|
-
isProd: !config?.isTestnet
|
|
14170
13933
|
}
|
|
14171
13934
|
)).data;
|
|
14172
13935
|
}
|
|
@@ -14177,10 +13940,7 @@ var Markets = class {
|
|
|
14177
13940
|
* ticker start
|
|
14178
13941
|
*/
|
|
14179
13942
|
async getTickerList(params) {
|
|
14180
|
-
|
|
14181
|
-
return (await getTickerData(params, {
|
|
14182
|
-
isProd: !config?.isTestnet
|
|
14183
|
-
})).data;
|
|
13943
|
+
return (await this.api.getTickerData(params)).data;
|
|
14184
13944
|
}
|
|
14185
13945
|
/**
|
|
14186
13946
|
* ticker end
|
|
@@ -14191,7 +13951,6 @@ var Markets = class {
|
|
|
14191
13951
|
*
|
|
14192
13952
|
*/
|
|
14193
13953
|
async searchMarketAuth(params, address) {
|
|
14194
|
-
const config = this.configManager.getConfig();
|
|
14195
13954
|
const accessToken = await this.configManager.getAccessToken();
|
|
14196
13955
|
if (!accessToken) {
|
|
14197
13956
|
throw new MyxSDKError(
|
|
@@ -14199,14 +13958,11 @@ var Markets = class {
|
|
|
14199
13958
|
"Invalid access token"
|
|
14200
13959
|
);
|
|
14201
13960
|
}
|
|
14202
|
-
return (await searchMarketAuth(
|
|
13961
|
+
return (await this.api.searchMarketAuth(
|
|
14203
13962
|
{
|
|
14204
13963
|
address,
|
|
14205
13964
|
...params,
|
|
14206
13965
|
accessToken
|
|
14207
|
-
},
|
|
14208
|
-
{
|
|
14209
|
-
isProd: !config?.isTestnet
|
|
14210
13966
|
}
|
|
14211
13967
|
)).data;
|
|
14212
13968
|
}
|
|
@@ -14214,10 +13970,7 @@ var Markets = class {
|
|
|
14214
13970
|
* search by unauthenticated users
|
|
14215
13971
|
*/
|
|
14216
13972
|
async searchMarket(params) {
|
|
14217
|
-
|
|
14218
|
-
return (await searchMarket(params, {
|
|
14219
|
-
isProd: !config?.isTestnet
|
|
14220
|
-
})).data;
|
|
13973
|
+
return (await this.api.searchMarket(params)).data;
|
|
14221
13974
|
}
|
|
14222
13975
|
/**
|
|
14223
13976
|
* get favorites list
|
|
@@ -14232,14 +13985,11 @@ var Markets = class {
|
|
|
14232
13985
|
"Invalid access token"
|
|
14233
13986
|
);
|
|
14234
13987
|
}
|
|
14235
|
-
return (await getFavoritesList(
|
|
13988
|
+
return (await this.api.getFavoritesList(
|
|
14236
13989
|
{
|
|
14237
13990
|
...params,
|
|
14238
13991
|
address,
|
|
14239
13992
|
accessToken
|
|
14240
|
-
},
|
|
14241
|
-
{
|
|
14242
|
-
isProd: !config?.isTestnet
|
|
14243
13993
|
}
|
|
14244
13994
|
)).data;
|
|
14245
13995
|
}
|
|
@@ -14255,19 +14005,15 @@ var Markets = class {
|
|
|
14255
14005
|
"Invalid access token"
|
|
14256
14006
|
);
|
|
14257
14007
|
}
|
|
14258
|
-
return (await addFavorite(
|
|
14008
|
+
return (await this.api.addFavorite(
|
|
14259
14009
|
{
|
|
14260
14010
|
...params,
|
|
14261
14011
|
address,
|
|
14262
14012
|
accessToken
|
|
14263
|
-
},
|
|
14264
|
-
{
|
|
14265
|
-
isProd: !config?.isTestnet
|
|
14266
14013
|
}
|
|
14267
14014
|
)).data;
|
|
14268
14015
|
}
|
|
14269
14016
|
async removeFavorite(params, address) {
|
|
14270
|
-
const config = this.configManager.getConfig();
|
|
14271
14017
|
const accessToken = await this.configManager.getAccessToken();
|
|
14272
14018
|
if (!accessToken) {
|
|
14273
14019
|
throw new MyxSDKError(
|
|
@@ -14275,14 +14021,11 @@ var Markets = class {
|
|
|
14275
14021
|
"Invalid access token"
|
|
14276
14022
|
);
|
|
14277
14023
|
}
|
|
14278
|
-
return (await removeFavorite(
|
|
14024
|
+
return (await this.api.removeFavorite(
|
|
14279
14025
|
{
|
|
14280
14026
|
...params,
|
|
14281
14027
|
address,
|
|
14282
14028
|
accessToken
|
|
14283
|
-
},
|
|
14284
|
-
{
|
|
14285
|
-
isProd: !config?.isTestnet
|
|
14286
14029
|
}
|
|
14287
14030
|
)).data;
|
|
14288
14031
|
}
|
|
@@ -14290,28 +14033,19 @@ var Markets = class {
|
|
|
14290
14033
|
* base detail
|
|
14291
14034
|
*/
|
|
14292
14035
|
async getBaseDetail(params) {
|
|
14293
|
-
|
|
14294
|
-
return (await getBaseDetail(params, {
|
|
14295
|
-
isProd: !config?.isTestnet
|
|
14296
|
-
})).data;
|
|
14036
|
+
return (await this.api.getBaseDetail(params)).data;
|
|
14297
14037
|
}
|
|
14298
14038
|
/**
|
|
14299
14039
|
* get market detail
|
|
14300
14040
|
*/
|
|
14301
14041
|
async getMarketDetail(params) {
|
|
14302
|
-
|
|
14303
|
-
return (await getMarketDetail(params, {
|
|
14304
|
-
isProd: !config?.isTestnet
|
|
14305
|
-
})).data;
|
|
14042
|
+
return (await this.api.getMarketDetail(params)).data;
|
|
14306
14043
|
}
|
|
14307
14044
|
/**
|
|
14308
14045
|
* get pool symbol all
|
|
14309
14046
|
*/
|
|
14310
14047
|
async getPoolSymbolAll() {
|
|
14311
|
-
|
|
14312
|
-
return (await getPoolSymbolAll({
|
|
14313
|
-
isProd: !config?.isTestnet
|
|
14314
|
-
})).data;
|
|
14048
|
+
return (await this.api.getPoolSymbolAll()).data;
|
|
14315
14049
|
}
|
|
14316
14050
|
};
|
|
14317
14051
|
|
|
@@ -14319,15 +14053,15 @@ var Markets = class {
|
|
|
14319
14053
|
import { ethers as ethers5 } from "ethers";
|
|
14320
14054
|
import dayjs from "dayjs";
|
|
14321
14055
|
var Position = class {
|
|
14322
|
-
constructor(configManager, logger, utils, seamless, account) {
|
|
14056
|
+
constructor(configManager, logger, utils, seamless, account, api) {
|
|
14323
14057
|
this.configManager = configManager;
|
|
14324
14058
|
this.logger = logger;
|
|
14325
14059
|
this.utils = utils;
|
|
14326
14060
|
this.seamless = seamless;
|
|
14327
14061
|
this.account = account;
|
|
14062
|
+
this.api = api;
|
|
14328
14063
|
}
|
|
14329
14064
|
async listPositions(address) {
|
|
14330
|
-
const isProd = !this.configManager.getConfig().isTestnet;
|
|
14331
14065
|
const accessToken = await this.configManager.getAccessToken();
|
|
14332
14066
|
if (!accessToken) {
|
|
14333
14067
|
return {
|
|
@@ -14336,7 +14070,7 @@ var Position = class {
|
|
|
14336
14070
|
};
|
|
14337
14071
|
}
|
|
14338
14072
|
try {
|
|
14339
|
-
const res = await getPositions(accessToken, address
|
|
14073
|
+
const res = await this.api.getPositions(accessToken, address);
|
|
14340
14074
|
return {
|
|
14341
14075
|
code: 0,
|
|
14342
14076
|
data: res.data
|
|
@@ -14350,7 +14084,6 @@ var Position = class {
|
|
|
14350
14084
|
}
|
|
14351
14085
|
}
|
|
14352
14086
|
async getPositionHistory(params, address) {
|
|
14353
|
-
const config = this.configManager.getConfig();
|
|
14354
14087
|
const accessToken = await this.configManager.getAccessToken();
|
|
14355
14088
|
if (!accessToken) {
|
|
14356
14089
|
throw new MyxSDKError(
|
|
@@ -14358,11 +14091,8 @@ var Position = class {
|
|
|
14358
14091
|
"Invalid access token"
|
|
14359
14092
|
);
|
|
14360
14093
|
}
|
|
14361
|
-
const res = await getPositionHistory(
|
|
14362
|
-
{ accessToken, ...params, address }
|
|
14363
|
-
{
|
|
14364
|
-
isProd: !config?.isTestnet
|
|
14365
|
-
}
|
|
14094
|
+
const res = await this.api.getPositionHistory(
|
|
14095
|
+
{ accessToken, ...params, address }
|
|
14366
14096
|
);
|
|
14367
14097
|
return {
|
|
14368
14098
|
code: 0,
|
|
@@ -14585,12 +14315,13 @@ var OrderStatus = {
|
|
|
14585
14315
|
import { ethers as ethers6 } from "ethers";
|
|
14586
14316
|
import dayjs2 from "dayjs";
|
|
14587
14317
|
var Order = class {
|
|
14588
|
-
constructor(configManager, logger, utils, seamless, account) {
|
|
14318
|
+
constructor(configManager, logger, utils, seamless, account, api) {
|
|
14589
14319
|
this.configManager = configManager;
|
|
14590
14320
|
this.logger = logger;
|
|
14591
14321
|
this.utils = utils;
|
|
14592
14322
|
this.seamless = seamless;
|
|
14593
14323
|
this.account = account;
|
|
14324
|
+
this.api = api;
|
|
14594
14325
|
}
|
|
14595
14326
|
async createIncreaseOrder(params, tradingFee) {
|
|
14596
14327
|
try {
|
|
@@ -15567,7 +15298,6 @@ var Order = class {
|
|
|
15567
15298
|
}
|
|
15568
15299
|
}
|
|
15569
15300
|
async getOrders(address) {
|
|
15570
|
-
const isProd = !this.configManager.getConfig().isTestnet;
|
|
15571
15301
|
const accessToken = await this.configManager.getAccessToken();
|
|
15572
15302
|
if (!accessToken) {
|
|
15573
15303
|
return {
|
|
@@ -15576,7 +15306,7 @@ var Order = class {
|
|
|
15576
15306
|
};
|
|
15577
15307
|
}
|
|
15578
15308
|
try {
|
|
15579
|
-
const res = await getOrders(accessToken, address
|
|
15309
|
+
const res = await this.api.getOrders(accessToken, address);
|
|
15580
15310
|
return {
|
|
15581
15311
|
code: 0,
|
|
15582
15312
|
data: res.data
|
|
@@ -15598,9 +15328,7 @@ var Order = class {
|
|
|
15598
15328
|
"Invalid access token"
|
|
15599
15329
|
);
|
|
15600
15330
|
}
|
|
15601
|
-
const res = await getHistoryOrders({ accessToken, ...params, address }
|
|
15602
|
-
isProd: !config?.isTestnet
|
|
15603
|
-
});
|
|
15331
|
+
const res = await this.api.getHistoryOrders({ accessToken, ...params, address });
|
|
15604
15332
|
return {
|
|
15605
15333
|
code: 0,
|
|
15606
15334
|
data: res.data
|
|
@@ -20427,8 +20155,7 @@ var Utils = class {
|
|
|
20427
20155
|
}
|
|
20428
20156
|
async getOraclePrice(poolId, chainId) {
|
|
20429
20157
|
try {
|
|
20430
|
-
const
|
|
20431
|
-
const priceData = await getPriceData(chainId, poolId, isProd);
|
|
20158
|
+
const priceData = await getPriceData(chainId, poolId);
|
|
20432
20159
|
if (!priceData) throw new Error("Failed to get price data");
|
|
20433
20160
|
return priceData;
|
|
20434
20161
|
} catch (error) {
|
|
@@ -21314,38 +21041,10 @@ var Account = class {
|
|
|
21314
21041
|
data: balance
|
|
21315
21042
|
};
|
|
21316
21043
|
}
|
|
21317
|
-
/**
|
|
21318
|
-
* get tradable amount
|
|
21319
|
-
*/
|
|
21320
|
-
async getTradableAmount({ poolId, chainId, address }) {
|
|
21321
|
-
const contractAddress = getContractAddressByChainId(chainId);
|
|
21322
|
-
const provider = await getJSONProvider(chainId);
|
|
21323
|
-
const accountContract = new ethers8.Contract(
|
|
21324
|
-
contractAddress.Account,
|
|
21325
|
-
Account_default,
|
|
21326
|
-
provider
|
|
21327
|
-
);
|
|
21328
|
-
try {
|
|
21329
|
-
const assets = await accountContract.getTradableAmount(address, poolId);
|
|
21330
|
-
const data = {
|
|
21331
|
-
profitIsReleased: assets[0],
|
|
21332
|
-
freeAmount: assets[1],
|
|
21333
|
-
tradeableProfit: assets[2]
|
|
21334
|
-
};
|
|
21335
|
-
return {
|
|
21336
|
-
code: 0,
|
|
21337
|
-
data
|
|
21338
|
-
};
|
|
21339
|
-
} catch (error) {
|
|
21340
|
-
return {
|
|
21341
|
-
code: -1
|
|
21342
|
-
};
|
|
21343
|
-
}
|
|
21344
|
-
}
|
|
21345
21044
|
async getAvailableMarginBalance({ poolId, chainId, address }) {
|
|
21346
21045
|
try {
|
|
21347
21046
|
const isProd = !this.configManager.getConfig().isTestnet;
|
|
21348
|
-
const poolListRes = await getPoolList(
|
|
21047
|
+
const poolListRes = await this.client.api.getPoolList();
|
|
21349
21048
|
if (poolListRes.code !== 9200) {
|
|
21350
21049
|
throw new MyxSDKError(
|
|
21351
21050
|
"REQUEST_FAILED" /* RequestFailed */,
|
|
@@ -21386,7 +21085,6 @@ var Account = class {
|
|
|
21386
21085
|
const availableAccountMarginBalance = accountMargin - usedMargin;
|
|
21387
21086
|
return availableAccountMarginBalance;
|
|
21388
21087
|
} catch (error) {
|
|
21389
|
-
this.logger.info("getAvailableMarginBalance error-->", error);
|
|
21390
21088
|
throw new MyxSDKError(
|
|
21391
21089
|
"REQUEST_FAILED" /* RequestFailed */,
|
|
21392
21090
|
"Failed to get getAvailableMarginBalance"
|
|
@@ -21394,7 +21092,6 @@ var Account = class {
|
|
|
21394
21092
|
}
|
|
21395
21093
|
}
|
|
21396
21094
|
async getTradeFlow(params, address) {
|
|
21397
|
-
const config = this.configManager.getConfig();
|
|
21398
21095
|
const accessToken = await this.configManager.getAccessToken();
|
|
21399
21096
|
if (!accessToken) {
|
|
21400
21097
|
throw new MyxSDKError(
|
|
@@ -21402,9 +21099,7 @@ var Account = class {
|
|
|
21402
21099
|
"Invalid access token"
|
|
21403
21100
|
);
|
|
21404
21101
|
}
|
|
21405
|
-
const res = await getTradeFlow({ accessToken, ...params, address }
|
|
21406
|
-
isProd: !config?.isTestnet
|
|
21407
|
-
});
|
|
21102
|
+
const res = await this.client.api.getTradeFlow({ accessToken, ...params, address });
|
|
21408
21103
|
return {
|
|
21409
21104
|
code: 0,
|
|
21410
21105
|
data: res.data
|
|
@@ -21438,9 +21133,7 @@ var Account = class {
|
|
|
21438
21133
|
data: functionHash,
|
|
21439
21134
|
nonce: nonce.toString()
|
|
21440
21135
|
};
|
|
21441
|
-
this.logger.info("withdraw forward tx params --->", forwardTxParams);
|
|
21442
21136
|
const rs2 = await this.client.seamless.forwarderTx(forwardTxParams, chainId, seamlessWallet);
|
|
21443
|
-
console.log("rs-->", rs2);
|
|
21444
21137
|
return {
|
|
21445
21138
|
code: 0,
|
|
21446
21139
|
message: "withdraw success",
|
|
@@ -21514,7 +21207,6 @@ var Account = class {
|
|
|
21514
21207
|
};
|
|
21515
21208
|
this.logger.info("deposit forward tx params --->", forwardTxParams);
|
|
21516
21209
|
const rs2 = await this.client.seamless.forwarderTx(forwardTxParams, chainId, seamlessWallet);
|
|
21517
|
-
console.log("rs-->", rs2);
|
|
21518
21210
|
return {
|
|
21519
21211
|
code: 0,
|
|
21520
21212
|
message: "deposit success",
|
|
@@ -21573,6 +21265,282 @@ var Account = class {
|
|
|
21573
21265
|
}
|
|
21574
21266
|
};
|
|
21575
21267
|
|
|
21268
|
+
// src/api/utils.ts
|
|
21269
|
+
function encodeQueryParam(key, value) {
|
|
21270
|
+
const encodedKey = encodeURIComponent(key);
|
|
21271
|
+
return `${encodedKey}=${encodeURIComponent(typeof value === "number" ? value : `${value}`)}`;
|
|
21272
|
+
}
|
|
21273
|
+
function addQueryParam(query, key) {
|
|
21274
|
+
return encodeQueryParam(key, query[key]);
|
|
21275
|
+
}
|
|
21276
|
+
function addArrayQueryParam(query, key) {
|
|
21277
|
+
const value = query[key];
|
|
21278
|
+
return value.map((v) => encodeQueryParam(key, v)).join("&");
|
|
21279
|
+
}
|
|
21280
|
+
function toQueryString(rawQuery) {
|
|
21281
|
+
const query = rawQuery || {};
|
|
21282
|
+
const keys = Object.keys(query).filter((key) => "undefined" !== typeof query[key]);
|
|
21283
|
+
return keys.map((key) => Array.isArray(query[key]) ? addArrayQueryParam(query, key) : addQueryParam(query, key)).join("&");
|
|
21284
|
+
}
|
|
21285
|
+
function addQueryParams(rawQuery) {
|
|
21286
|
+
const queryString = toQueryString(rawQuery);
|
|
21287
|
+
return queryString ? `?${queryString}` : "";
|
|
21288
|
+
}
|
|
21289
|
+
|
|
21290
|
+
// src/manager/api/index.ts
|
|
21291
|
+
var Api = class {
|
|
21292
|
+
constructor(configManager, logger) {
|
|
21293
|
+
this.configManager = configManager;
|
|
21294
|
+
this.logger = logger;
|
|
21295
|
+
}
|
|
21296
|
+
getHost() {
|
|
21297
|
+
const isProd = !this.configManager.getConfig().isTestnet;
|
|
21298
|
+
return isProd ? "https://api.myx.finance" : "https://api-test.myx.cash";
|
|
21299
|
+
}
|
|
21300
|
+
async getTradeFlow({
|
|
21301
|
+
accessToken,
|
|
21302
|
+
address,
|
|
21303
|
+
...params
|
|
21304
|
+
}) {
|
|
21305
|
+
return http.get(
|
|
21306
|
+
`${this.getHost()}/openapi/gateway/scan/trade/flow`,
|
|
21307
|
+
params,
|
|
21308
|
+
{
|
|
21309
|
+
headers: {
|
|
21310
|
+
myx_openapi_access_token: accessToken,
|
|
21311
|
+
myx_openapi_account: address
|
|
21312
|
+
}
|
|
21313
|
+
}
|
|
21314
|
+
);
|
|
21315
|
+
}
|
|
21316
|
+
async getPoolSymbolAll() {
|
|
21317
|
+
return http.get(
|
|
21318
|
+
`${this.getHost()}/openapi/gateway/scan/pools`
|
|
21319
|
+
);
|
|
21320
|
+
}
|
|
21321
|
+
async fetchForwarderGetApi(params) {
|
|
21322
|
+
const rs = await http.get(
|
|
21323
|
+
`${this.getHost()}/forwarder/get${addQueryParams(params)}`
|
|
21324
|
+
);
|
|
21325
|
+
return rs;
|
|
21326
|
+
}
|
|
21327
|
+
async getPoolList() {
|
|
21328
|
+
return http.get(
|
|
21329
|
+
`${this.getHost()}/openapi/gateway/scan/market/list`
|
|
21330
|
+
);
|
|
21331
|
+
}
|
|
21332
|
+
async forwarderTxApi(params, chainId) {
|
|
21333
|
+
return http.post(
|
|
21334
|
+
`${this.getHost()}/forwarder/tx-v2`,
|
|
21335
|
+
params,
|
|
21336
|
+
{
|
|
21337
|
+
headers: {
|
|
21338
|
+
"myx-chain-id": chainId.toString()
|
|
21339
|
+
}
|
|
21340
|
+
}
|
|
21341
|
+
);
|
|
21342
|
+
}
|
|
21343
|
+
async getOraclePrice(chainId, poolIds = []) {
|
|
21344
|
+
if (!!poolIds.length) {
|
|
21345
|
+
return http.get(
|
|
21346
|
+
`${this.getHost()}/openapi/gateway/quote/price/oracles`,
|
|
21347
|
+
{
|
|
21348
|
+
chainId,
|
|
21349
|
+
poolIds: poolIds.join(",")
|
|
21350
|
+
}
|
|
21351
|
+
);
|
|
21352
|
+
}
|
|
21353
|
+
throw new Error("Invalid pool id");
|
|
21354
|
+
}
|
|
21355
|
+
async getPoolDetail(chainId, poolId) {
|
|
21356
|
+
return await http.get(
|
|
21357
|
+
`${this.getHost()}/openapi/gateway/scan/market/info?chainId=${chainId}&poolId=${poolId}`
|
|
21358
|
+
);
|
|
21359
|
+
}
|
|
21360
|
+
async getPoolLevelConfig({
|
|
21361
|
+
poolId,
|
|
21362
|
+
chainId
|
|
21363
|
+
}) {
|
|
21364
|
+
return http.get(
|
|
21365
|
+
`${this.getHost()}/openapi/gateway/risk/market_pool/level_config${addQueryParams({
|
|
21366
|
+
poolId,
|
|
21367
|
+
chainId
|
|
21368
|
+
})}`
|
|
21369
|
+
);
|
|
21370
|
+
}
|
|
21371
|
+
async getPositions(accessToken, address) {
|
|
21372
|
+
return await http.get(
|
|
21373
|
+
`${this.getHost()}/openapi/gateway/scan/position/open`,
|
|
21374
|
+
void 0,
|
|
21375
|
+
{
|
|
21376
|
+
headers: {
|
|
21377
|
+
myx_openapi_access_token: accessToken,
|
|
21378
|
+
myx_openapi_account: address
|
|
21379
|
+
}
|
|
21380
|
+
}
|
|
21381
|
+
);
|
|
21382
|
+
}
|
|
21383
|
+
async getOrders(accessToken, address) {
|
|
21384
|
+
return await http.get(
|
|
21385
|
+
`${this.getHost()}/openapi/gateway/scan/order/open`,
|
|
21386
|
+
void 0,
|
|
21387
|
+
{
|
|
21388
|
+
headers: {
|
|
21389
|
+
myx_openapi_access_token: accessToken,
|
|
21390
|
+
myx_openapi_account: address
|
|
21391
|
+
}
|
|
21392
|
+
}
|
|
21393
|
+
);
|
|
21394
|
+
}
|
|
21395
|
+
async getPoolOpenOrders(accessToken, address, chainId) {
|
|
21396
|
+
return await http.get(
|
|
21397
|
+
`${this.getHost()}/openapi/gateway/scan/market/pool-order/open?chainId=${chainId}`,
|
|
21398
|
+
void 0,
|
|
21399
|
+
{
|
|
21400
|
+
headers: {
|
|
21401
|
+
myx_openapi_access_token: accessToken,
|
|
21402
|
+
myx_openapi_account: address
|
|
21403
|
+
}
|
|
21404
|
+
}
|
|
21405
|
+
);
|
|
21406
|
+
}
|
|
21407
|
+
async getKlineData({ chainId, poolId, endTime, limit, interval }) {
|
|
21408
|
+
return http.get(
|
|
21409
|
+
`${this.getHost()}/openapi/gateway/quote/candles`,
|
|
21410
|
+
{
|
|
21411
|
+
chainId,
|
|
21412
|
+
poolId,
|
|
21413
|
+
endTime,
|
|
21414
|
+
limit,
|
|
21415
|
+
interval
|
|
21416
|
+
}
|
|
21417
|
+
);
|
|
21418
|
+
}
|
|
21419
|
+
async getKlineLatestBar(params) {
|
|
21420
|
+
return http.get(
|
|
21421
|
+
`${this.getHost()}/openapi/gateway/quote/candle/latest`,
|
|
21422
|
+
params
|
|
21423
|
+
);
|
|
21424
|
+
}
|
|
21425
|
+
async getTickerData({ chainId, poolIds }) {
|
|
21426
|
+
return http.get(
|
|
21427
|
+
`${this.getHost()}/openapi/gateway/quote/candle/tickers`,
|
|
21428
|
+
{
|
|
21429
|
+
chainId,
|
|
21430
|
+
poolIds: poolIds.join(",")
|
|
21431
|
+
}
|
|
21432
|
+
);
|
|
21433
|
+
}
|
|
21434
|
+
async getAllTickers() {
|
|
21435
|
+
return http.get(
|
|
21436
|
+
`${this.getHost()}/v2/mx-gateway/quote/candle/all_tickers`
|
|
21437
|
+
);
|
|
21438
|
+
}
|
|
21439
|
+
async searchMarketAuth({ accessToken, address, ...params }) {
|
|
21440
|
+
return http.get(
|
|
21441
|
+
`${this.getHost()}/openapi/gateway/scan/market/ac-search`,
|
|
21442
|
+
params,
|
|
21443
|
+
{
|
|
21444
|
+
headers: {
|
|
21445
|
+
myx_openapi_access_token: accessToken,
|
|
21446
|
+
myx_openapi_account: address
|
|
21447
|
+
}
|
|
21448
|
+
}
|
|
21449
|
+
);
|
|
21450
|
+
}
|
|
21451
|
+
async searchMarket({ ...params }) {
|
|
21452
|
+
return http.get(
|
|
21453
|
+
`${this.getHost()}/openapi/gateway/scan/market/search`,
|
|
21454
|
+
params
|
|
21455
|
+
);
|
|
21456
|
+
}
|
|
21457
|
+
async addFavorite({ accessToken, address, ...params }) {
|
|
21458
|
+
return http.get(
|
|
21459
|
+
`${this.getHost()}/openapi/gateway/scan/market/add-favorites`,
|
|
21460
|
+
params,
|
|
21461
|
+
{
|
|
21462
|
+
headers: {
|
|
21463
|
+
myx_openapi_access_token: accessToken,
|
|
21464
|
+
myx_openapi_account: address
|
|
21465
|
+
}
|
|
21466
|
+
}
|
|
21467
|
+
);
|
|
21468
|
+
}
|
|
21469
|
+
async removeFavorite({ accessToken, address, ...params }) {
|
|
21470
|
+
return http.get(
|
|
21471
|
+
`${this.getHost()}/openapi/gateway/scan/market/cancel-favorites`,
|
|
21472
|
+
params,
|
|
21473
|
+
{
|
|
21474
|
+
headers: {
|
|
21475
|
+
myx_openapi_access_token: accessToken,
|
|
21476
|
+
myx_openapi_account: address
|
|
21477
|
+
}
|
|
21478
|
+
}
|
|
21479
|
+
);
|
|
21480
|
+
}
|
|
21481
|
+
async getFavoritesList({ accessToken, address, ...params }) {
|
|
21482
|
+
return http.get(
|
|
21483
|
+
`${this.getHost()}/openapi/gateway/scan/market/favorites`,
|
|
21484
|
+
params,
|
|
21485
|
+
{
|
|
21486
|
+
headers: {
|
|
21487
|
+
myx_openapi_access_token: accessToken,
|
|
21488
|
+
myx_openapi_account: address
|
|
21489
|
+
}
|
|
21490
|
+
}
|
|
21491
|
+
);
|
|
21492
|
+
}
|
|
21493
|
+
async getBaseDetail({ ...params }) {
|
|
21494
|
+
return http.get(
|
|
21495
|
+
`${this.getHost()}/openapi/gateway/scan/market/base-details`,
|
|
21496
|
+
params
|
|
21497
|
+
);
|
|
21498
|
+
}
|
|
21499
|
+
async getMarketDetail({ ...params }) {
|
|
21500
|
+
return http.get(
|
|
21501
|
+
`${this.getHost()}/openapi/gateway/scan/market/detail`,
|
|
21502
|
+
params
|
|
21503
|
+
);
|
|
21504
|
+
}
|
|
21505
|
+
async getHistoryOrders({
|
|
21506
|
+
accessToken,
|
|
21507
|
+
address,
|
|
21508
|
+
...params
|
|
21509
|
+
}) {
|
|
21510
|
+
return http.get(
|
|
21511
|
+
`${this.getHost()}/openapi/gateway/scan/order/closed`,
|
|
21512
|
+
params,
|
|
21513
|
+
{
|
|
21514
|
+
headers: {
|
|
21515
|
+
myx_openapi_account: address,
|
|
21516
|
+
myx_openapi_access_token: accessToken
|
|
21517
|
+
}
|
|
21518
|
+
}
|
|
21519
|
+
);
|
|
21520
|
+
}
|
|
21521
|
+
async getPositionHistory({
|
|
21522
|
+
accessToken,
|
|
21523
|
+
address,
|
|
21524
|
+
...params
|
|
21525
|
+
}) {
|
|
21526
|
+
return http.get(
|
|
21527
|
+
`${this.getHost()}/openapi/gateway/scan/position/closed`,
|
|
21528
|
+
params,
|
|
21529
|
+
{
|
|
21530
|
+
headers: {
|
|
21531
|
+
myx_openapi_account: address,
|
|
21532
|
+
myx_openapi_access_token: accessToken
|
|
21533
|
+
}
|
|
21534
|
+
}
|
|
21535
|
+
);
|
|
21536
|
+
}
|
|
21537
|
+
async getMarketList() {
|
|
21538
|
+
return http.get(
|
|
21539
|
+
`${this.getHost()}/openapi/gateway/scan/market`
|
|
21540
|
+
);
|
|
21541
|
+
}
|
|
21542
|
+
};
|
|
21543
|
+
|
|
21576
21544
|
// src/manager/seamless/index.ts
|
|
21577
21545
|
import CryptoJS from "crypto-js";
|
|
21578
21546
|
import { toUtf8Bytes, keccak256, hexlify, ethers as ethers9, isHexString, getBytes, ZeroAddress as ZeroAddress2 } from "ethers";
|
|
@@ -21748,11 +21716,12 @@ async function signPermit(provider, contract, owner, spender, value, nonce, dead
|
|
|
21748
21716
|
return { v, r, s };
|
|
21749
21717
|
}
|
|
21750
21718
|
var Seamless = class {
|
|
21751
|
-
constructor(configManager, logger, utils, account) {
|
|
21719
|
+
constructor(configManager, logger, utils, account, api) {
|
|
21752
21720
|
this.configManager = configManager;
|
|
21753
21721
|
this.logger = logger;
|
|
21754
21722
|
this.utils = utils;
|
|
21755
21723
|
this.account = account;
|
|
21724
|
+
this.api = api;
|
|
21756
21725
|
}
|
|
21757
21726
|
async onCheckRelayer(account, relayer, chainId) {
|
|
21758
21727
|
const forwarderContract = await getForwarderContract(chainId);
|
|
@@ -21832,7 +21801,6 @@ var Seamless = class {
|
|
|
21832
21801
|
data,
|
|
21833
21802
|
nonce
|
|
21834
21803
|
}, chainId, provider) {
|
|
21835
|
-
const isProd = !this.configManager.getConfig().isTestnet;
|
|
21836
21804
|
const forwarderContract = await getForwarderContract(chainId);
|
|
21837
21805
|
const forwarderJsonRpcContractDomain = await forwarderContract.eip712Domain();
|
|
21838
21806
|
const domain = {
|
|
@@ -21851,7 +21819,7 @@ var Seamless = class {
|
|
|
21851
21819
|
deadline,
|
|
21852
21820
|
data
|
|
21853
21821
|
});
|
|
21854
|
-
const txRs = await forwarderTxApi({ from, to, value, gas, nonce, data, deadline, signature }, chainId
|
|
21822
|
+
const txRs = await this.api.forwarderTxApi({ from, to, value, gas, nonce, data, deadline, signature }, chainId);
|
|
21855
21823
|
return txRs;
|
|
21856
21824
|
}
|
|
21857
21825
|
async authorizeSeamlessAccount({ approve: approve2, seamlessAddress, chainId }) {
|
|
@@ -21901,7 +21869,7 @@ var Seamless = class {
|
|
|
21901
21869
|
if (!txRs.data?.txHash) {
|
|
21902
21870
|
const retryOptions = { n: 10, minWait: 250, maxWait: 1e3 };
|
|
21903
21871
|
const { promise } = retry(async () => {
|
|
21904
|
-
const getRs = await fetchForwarderGetApi({
|
|
21872
|
+
const getRs = await this.api.fetchForwarderGetApi({
|
|
21905
21873
|
requestId: txRs.data?.requestId
|
|
21906
21874
|
});
|
|
21907
21875
|
if (getRs.data?.status === 9 /* EXECUTED */) {
|
|
@@ -22079,15 +22047,16 @@ var MyxClient = class {
|
|
|
22079
22047
|
this.logger = new Logger({
|
|
22080
22048
|
logLevel: options.logLevel
|
|
22081
22049
|
});
|
|
22050
|
+
const lp = MxSDK.getInstance();
|
|
22051
|
+
lp.setConfigManager(this.configManager);
|
|
22082
22052
|
this.utils = new Utils(this.configManager, this.logger);
|
|
22053
|
+
this.api = new Api(this.configManager, this.logger);
|
|
22083
22054
|
this.account = new Account(this.configManager, this.logger, this.utils, this);
|
|
22084
|
-
this.seamless = new Seamless(this.configManager, this.logger, this.utils, this.account);
|
|
22085
|
-
this.markets = new Markets(this.configManager, this.utils);
|
|
22086
|
-
this.position = new Position(this.configManager, this.logger, this.utils, this.seamless, this.account);
|
|
22087
|
-
this.order = new Order(this.configManager, this.logger, this.utils, this.seamless, this.account);
|
|
22055
|
+
this.seamless = new Seamless(this.configManager, this.logger, this.utils, this.account, this.api);
|
|
22056
|
+
this.markets = new Markets(this.configManager, this.utils, this.api);
|
|
22057
|
+
this.position = new Position(this.configManager, this.logger, this.utils, this.seamless, this.account, this.api);
|
|
22058
|
+
this.order = new Order(this.configManager, this.logger, this.utils, this.seamless, this.account, this.api);
|
|
22088
22059
|
this.subscription = new SubScription(this.configManager, this.logger);
|
|
22089
|
-
const lp = MxSDK.getInstance();
|
|
22090
|
-
lp.setConfigManager(this.configManager);
|
|
22091
22060
|
}
|
|
22092
22061
|
/**
|
|
22093
22062
|
* auth the client
|
|
@@ -22141,48 +22110,31 @@ export {
|
|
|
22141
22110
|
TradeFlowTypeEnum,
|
|
22142
22111
|
TriggerType2 as TriggerType,
|
|
22143
22112
|
TriggerTypeEnum,
|
|
22144
|
-
addFavorite,
|
|
22145
22113
|
approve,
|
|
22146
22114
|
base_exports as base,
|
|
22147
22115
|
bigintAmountSlipperCalculator,
|
|
22148
22116
|
bigintTradingGasPriceWithRatio,
|
|
22149
22117
|
bigintTradingGasToRatioCalculator,
|
|
22150
|
-
fetchForwarderGetApi,
|
|
22151
22118
|
formatUnits2 as formatUnits,
|
|
22152
|
-
forwarderTxApi,
|
|
22153
|
-
getAllTickers,
|
|
22154
22119
|
getAllowanceApproved,
|
|
22155
22120
|
getBalanceOf,
|
|
22156
22121
|
getBaseDetail,
|
|
22157
22122
|
getBaseUrlByEnv,
|
|
22158
|
-
getFavoritesList,
|
|
22159
22123
|
getForwardUrlByEnv,
|
|
22160
|
-
getHistoryOrders,
|
|
22161
|
-
getKlineData,
|
|
22162
|
-
getKlineLatestBar,
|
|
22163
22124
|
getMarketDetail,
|
|
22164
22125
|
getMarketList,
|
|
22165
22126
|
getOraclePrice,
|
|
22166
|
-
getOrders,
|
|
22167
22127
|
getPoolDetail,
|
|
22168
|
-
getPoolLevelConfig,
|
|
22169
22128
|
getPoolList,
|
|
22170
22129
|
getPoolOpenOrders,
|
|
22171
|
-
getPoolSymbolAll,
|
|
22172
|
-
getPositionHistory,
|
|
22173
|
-
getPositions,
|
|
22174
22130
|
getPriceData,
|
|
22175
22131
|
getPricesData,
|
|
22176
22132
|
getTickerData,
|
|
22177
22133
|
getTokenInfo,
|
|
22178
|
-
getTradeFlow,
|
|
22179
22134
|
market_exports as market,
|
|
22180
22135
|
parseUnits17 as parseUnits,
|
|
22181
22136
|
pool_exports as pool,
|
|
22182
|
-
quote_exports as quote
|
|
22183
|
-
removeFavorite,
|
|
22184
|
-
searchMarket,
|
|
22185
|
-
searchMarketAuth
|
|
22137
|
+
quote_exports as quote
|
|
22186
22138
|
};
|
|
22187
22139
|
/**
|
|
22188
22140
|
* MyxLogger
|