@myx-trade/sdk 0.1.192 → 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 +349 -416
- package/dist/index.mjs +348 -398
- 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
|
|
|
@@ -2358,9 +2125,7 @@ var MxSDK = class _MxSDK {
|
|
|
2358
2125
|
}
|
|
2359
2126
|
async getMarkets() {
|
|
2360
2127
|
try {
|
|
2361
|
-
const result = await getMarketList(
|
|
2362
|
-
isProd: !this.configManager?.getConfig()?.isTestnet
|
|
2363
|
-
});
|
|
2128
|
+
const result = await getMarketList();
|
|
2364
2129
|
this.Markets = result?.data || [];
|
|
2365
2130
|
} catch (error) {
|
|
2366
2131
|
throw error;
|
|
@@ -2373,6 +2138,7 @@ if (typeof window !== "undefined") {
|
|
|
2373
2138
|
} else if (typeof globalThis !== "undefined") {
|
|
2374
2139
|
globalThis.MxSDK = sdk;
|
|
2375
2140
|
}
|
|
2141
|
+
var web3_default = sdk;
|
|
2376
2142
|
var getWalletProvider = async (chainId) => {
|
|
2377
2143
|
try {
|
|
2378
2144
|
const walletClient = sdk.getConfigManager()?.getConfig()?.walletClient;
|
|
@@ -12076,9 +11842,9 @@ var getPricesData = async (chainId, poolIds) => {
|
|
|
12076
11842
|
const result = await parsePriceData(chainId, rs.data);
|
|
12077
11843
|
return result;
|
|
12078
11844
|
};
|
|
12079
|
-
var getPriceData = async (chainId, poolId
|
|
11845
|
+
var getPriceData = async (chainId, poolId) => {
|
|
12080
11846
|
if (!poolId) return;
|
|
12081
|
-
const rs = await getOraclePrice(chainId, [poolId]
|
|
11847
|
+
const rs = await getOraclePrice(chainId, [poolId]);
|
|
12082
11848
|
const data = rs?.data?.[0];
|
|
12083
11849
|
if (!data) {
|
|
12084
11850
|
throw new Error(`Unable to get price for ${poolId} in the deposit`);
|
|
@@ -12335,7 +12101,7 @@ var deposit = async (params) => {
|
|
|
12335
12101
|
let value = 0n;
|
|
12336
12102
|
let amountOut;
|
|
12337
12103
|
if (isNeedPrice) {
|
|
12338
|
-
const priceData = await getPriceData(chainId, poolId
|
|
12104
|
+
const priceData = await getPriceData(chainId, poolId);
|
|
12339
12105
|
if (!priceData) return;
|
|
12340
12106
|
const referencePrice = parseUnits7(priceData.price, COMMON_PRICE_DECIMALS);
|
|
12341
12107
|
price.push({
|
|
@@ -12405,7 +12171,7 @@ var withdraw = async (params) => {
|
|
|
12405
12171
|
let value = 0n;
|
|
12406
12172
|
let amountOut;
|
|
12407
12173
|
if (isNeedPrice) {
|
|
12408
|
-
const priceData = await getPriceData(chainId, poolId
|
|
12174
|
+
const priceData = await getPriceData(chainId, poolId);
|
|
12409
12175
|
if (!priceData) return;
|
|
12410
12176
|
const referencePrice = parseUnits8(priceData.price, COMMON_PRICE_DECIMALS);
|
|
12411
12177
|
price.push({
|
|
@@ -12477,7 +12243,7 @@ var getLpPrice = async (chainId, poolId) => {
|
|
|
12477
12243
|
try {
|
|
12478
12244
|
const contract = await getBasePoolContract(chainId);
|
|
12479
12245
|
let price = 0n;
|
|
12480
|
-
const res = await getPriceData(chainId, poolId
|
|
12246
|
+
const res = await getPriceData(chainId, poolId);
|
|
12481
12247
|
if (res?.price) {
|
|
12482
12248
|
price = parseUnits10(res.price, COMMON_PRICE_DECIMALS);
|
|
12483
12249
|
}
|
|
@@ -12569,7 +12335,7 @@ var deposit2 = async (params) => {
|
|
|
12569
12335
|
let value = 0n;
|
|
12570
12336
|
let amountOut;
|
|
12571
12337
|
if (isNeedPrice) {
|
|
12572
|
-
const priceData = await getPriceData(chainId, poolId
|
|
12338
|
+
const priceData = await getPriceData(chainId, poolId);
|
|
12573
12339
|
if (!priceData) return;
|
|
12574
12340
|
const referencePrice = parseUnits11(priceData.price, COMMON_PRICE_DECIMALS);
|
|
12575
12341
|
price.push({
|
|
@@ -12639,7 +12405,7 @@ var withdraw2 = async (params) => {
|
|
|
12639
12405
|
let value = 0n;
|
|
12640
12406
|
let amountOut;
|
|
12641
12407
|
if (isNeedPrice) {
|
|
12642
|
-
const priceData = await getPriceData(chainId, poolId
|
|
12408
|
+
const priceData = await getPriceData(chainId, poolId);
|
|
12643
12409
|
if (!priceData) return;
|
|
12644
12410
|
const referencePrice = parseUnits12(priceData.price, COMMON_PRICE_DECIMALS);
|
|
12645
12411
|
price.push({
|
|
@@ -12841,7 +12607,7 @@ var getLpPrice2 = async (chainId, poolId) => {
|
|
|
12841
12607
|
try {
|
|
12842
12608
|
const contract = await getQuotePoolContract(chainId);
|
|
12843
12609
|
let price = 0n;
|
|
12844
|
-
const res = await getPriceData(chainId, poolId
|
|
12610
|
+
const res = await getPriceData(chainId, poolId);
|
|
12845
12611
|
if (res?.price) {
|
|
12846
12612
|
price = parseUnits16(res.price, COMMON_PRICE_DECIMALS);
|
|
12847
12613
|
}
|
|
@@ -14125,18 +13891,19 @@ var ConfigManager = class {
|
|
|
14125
13891
|
|
|
14126
13892
|
// src/manager/markets/index.ts
|
|
14127
13893
|
var Markets = class {
|
|
14128
|
-
constructor(configManager, utils) {
|
|
13894
|
+
constructor(configManager, utils, api) {
|
|
14129
13895
|
this.configManager = configManager;
|
|
14130
13896
|
this.utils = utils;
|
|
13897
|
+
this.api = api;
|
|
14131
13898
|
}
|
|
14132
13899
|
getMarkets() {
|
|
14133
13900
|
return Promise.resolve([]);
|
|
14134
13901
|
}
|
|
14135
|
-
async getPoolLevelConfig(poolId) {
|
|
13902
|
+
async getPoolLevelConfig(poolId, chainId) {
|
|
14136
13903
|
const config = this.configManager.getConfig();
|
|
14137
|
-
return (await getPoolLevelConfig({
|
|
13904
|
+
return (await this.api.getPoolLevelConfig({
|
|
14138
13905
|
poolId,
|
|
14139
|
-
chainId
|
|
13906
|
+
chainId
|
|
14140
13907
|
})).data;
|
|
14141
13908
|
}
|
|
14142
13909
|
/**
|
|
@@ -14147,13 +13914,10 @@ var Markets = class {
|
|
|
14147
13914
|
...params
|
|
14148
13915
|
}) {
|
|
14149
13916
|
const config = this.configManager.getConfig();
|
|
14150
|
-
return (await getKlineData(
|
|
13917
|
+
return (await this.api.getKlineData(
|
|
14151
13918
|
{
|
|
14152
13919
|
...params,
|
|
14153
13920
|
interval: this.utils.transferKlineResolutionToInterval(interval)
|
|
14154
|
-
},
|
|
14155
|
-
{
|
|
14156
|
-
isProd: !config?.isTestnet
|
|
14157
13921
|
}
|
|
14158
13922
|
)).data;
|
|
14159
13923
|
}
|
|
@@ -14162,13 +13926,10 @@ var Markets = class {
|
|
|
14162
13926
|
...params
|
|
14163
13927
|
}) {
|
|
14164
13928
|
const config = this.configManager.getConfig();
|
|
14165
|
-
return (await getKlineLatestBar(
|
|
13929
|
+
return (await this.api.getKlineLatestBar(
|
|
14166
13930
|
{
|
|
14167
13931
|
...params,
|
|
14168
13932
|
interval: this.utils.transferKlineResolutionToInterval(interval)
|
|
14169
|
-
},
|
|
14170
|
-
{
|
|
14171
|
-
isProd: !config?.isTestnet
|
|
14172
13933
|
}
|
|
14173
13934
|
)).data;
|
|
14174
13935
|
}
|
|
@@ -14179,10 +13940,7 @@ var Markets = class {
|
|
|
14179
13940
|
* ticker start
|
|
14180
13941
|
*/
|
|
14181
13942
|
async getTickerList(params) {
|
|
14182
|
-
|
|
14183
|
-
return (await getTickerData(params, {
|
|
14184
|
-
isProd: !config?.isTestnet
|
|
14185
|
-
})).data;
|
|
13943
|
+
return (await this.api.getTickerData(params)).data;
|
|
14186
13944
|
}
|
|
14187
13945
|
/**
|
|
14188
13946
|
* ticker end
|
|
@@ -14193,7 +13951,6 @@ var Markets = class {
|
|
|
14193
13951
|
*
|
|
14194
13952
|
*/
|
|
14195
13953
|
async searchMarketAuth(params, address) {
|
|
14196
|
-
const config = this.configManager.getConfig();
|
|
14197
13954
|
const accessToken = await this.configManager.getAccessToken();
|
|
14198
13955
|
if (!accessToken) {
|
|
14199
13956
|
throw new MyxSDKError(
|
|
@@ -14201,14 +13958,11 @@ var Markets = class {
|
|
|
14201
13958
|
"Invalid access token"
|
|
14202
13959
|
);
|
|
14203
13960
|
}
|
|
14204
|
-
return (await searchMarketAuth(
|
|
13961
|
+
return (await this.api.searchMarketAuth(
|
|
14205
13962
|
{
|
|
14206
13963
|
address,
|
|
14207
13964
|
...params,
|
|
14208
13965
|
accessToken
|
|
14209
|
-
},
|
|
14210
|
-
{
|
|
14211
|
-
isProd: !config?.isTestnet
|
|
14212
13966
|
}
|
|
14213
13967
|
)).data;
|
|
14214
13968
|
}
|
|
@@ -14216,10 +13970,7 @@ var Markets = class {
|
|
|
14216
13970
|
* search by unauthenticated users
|
|
14217
13971
|
*/
|
|
14218
13972
|
async searchMarket(params) {
|
|
14219
|
-
|
|
14220
|
-
return (await searchMarket(params, {
|
|
14221
|
-
isProd: !config?.isTestnet
|
|
14222
|
-
})).data;
|
|
13973
|
+
return (await this.api.searchMarket(params)).data;
|
|
14223
13974
|
}
|
|
14224
13975
|
/**
|
|
14225
13976
|
* get favorites list
|
|
@@ -14234,14 +13985,11 @@ var Markets = class {
|
|
|
14234
13985
|
"Invalid access token"
|
|
14235
13986
|
);
|
|
14236
13987
|
}
|
|
14237
|
-
return (await getFavoritesList(
|
|
13988
|
+
return (await this.api.getFavoritesList(
|
|
14238
13989
|
{
|
|
14239
13990
|
...params,
|
|
14240
13991
|
address,
|
|
14241
13992
|
accessToken
|
|
14242
|
-
},
|
|
14243
|
-
{
|
|
14244
|
-
isProd: !config?.isTestnet
|
|
14245
13993
|
}
|
|
14246
13994
|
)).data;
|
|
14247
13995
|
}
|
|
@@ -14257,19 +14005,15 @@ var Markets = class {
|
|
|
14257
14005
|
"Invalid access token"
|
|
14258
14006
|
);
|
|
14259
14007
|
}
|
|
14260
|
-
return (await addFavorite(
|
|
14008
|
+
return (await this.api.addFavorite(
|
|
14261
14009
|
{
|
|
14262
14010
|
...params,
|
|
14263
14011
|
address,
|
|
14264
14012
|
accessToken
|
|
14265
|
-
},
|
|
14266
|
-
{
|
|
14267
|
-
isProd: !config?.isTestnet
|
|
14268
14013
|
}
|
|
14269
14014
|
)).data;
|
|
14270
14015
|
}
|
|
14271
14016
|
async removeFavorite(params, address) {
|
|
14272
|
-
const config = this.configManager.getConfig();
|
|
14273
14017
|
const accessToken = await this.configManager.getAccessToken();
|
|
14274
14018
|
if (!accessToken) {
|
|
14275
14019
|
throw new MyxSDKError(
|
|
@@ -14277,14 +14021,11 @@ var Markets = class {
|
|
|
14277
14021
|
"Invalid access token"
|
|
14278
14022
|
);
|
|
14279
14023
|
}
|
|
14280
|
-
return (await removeFavorite(
|
|
14024
|
+
return (await this.api.removeFavorite(
|
|
14281
14025
|
{
|
|
14282
14026
|
...params,
|
|
14283
14027
|
address,
|
|
14284
14028
|
accessToken
|
|
14285
|
-
},
|
|
14286
|
-
{
|
|
14287
|
-
isProd: !config?.isTestnet
|
|
14288
14029
|
}
|
|
14289
14030
|
)).data;
|
|
14290
14031
|
}
|
|
@@ -14292,28 +14033,19 @@ var Markets = class {
|
|
|
14292
14033
|
* base detail
|
|
14293
14034
|
*/
|
|
14294
14035
|
async getBaseDetail(params) {
|
|
14295
|
-
|
|
14296
|
-
return (await getBaseDetail(params, {
|
|
14297
|
-
isProd: !config?.isTestnet
|
|
14298
|
-
})).data;
|
|
14036
|
+
return (await this.api.getBaseDetail(params)).data;
|
|
14299
14037
|
}
|
|
14300
14038
|
/**
|
|
14301
14039
|
* get market detail
|
|
14302
14040
|
*/
|
|
14303
14041
|
async getMarketDetail(params) {
|
|
14304
|
-
|
|
14305
|
-
return (await getMarketDetail(params, {
|
|
14306
|
-
isProd: !config?.isTestnet
|
|
14307
|
-
})).data;
|
|
14042
|
+
return (await this.api.getMarketDetail(params)).data;
|
|
14308
14043
|
}
|
|
14309
14044
|
/**
|
|
14310
14045
|
* get pool symbol all
|
|
14311
14046
|
*/
|
|
14312
14047
|
async getPoolSymbolAll() {
|
|
14313
|
-
|
|
14314
|
-
return (await getPoolSymbolAll({
|
|
14315
|
-
isProd: !config?.isTestnet
|
|
14316
|
-
})).data;
|
|
14048
|
+
return (await this.api.getPoolSymbolAll()).data;
|
|
14317
14049
|
}
|
|
14318
14050
|
};
|
|
14319
14051
|
|
|
@@ -14321,15 +14053,15 @@ var Markets = class {
|
|
|
14321
14053
|
import { ethers as ethers5 } from "ethers";
|
|
14322
14054
|
import dayjs from "dayjs";
|
|
14323
14055
|
var Position = class {
|
|
14324
|
-
constructor(configManager, logger, utils, seamless, account) {
|
|
14056
|
+
constructor(configManager, logger, utils, seamless, account, api) {
|
|
14325
14057
|
this.configManager = configManager;
|
|
14326
14058
|
this.logger = logger;
|
|
14327
14059
|
this.utils = utils;
|
|
14328
14060
|
this.seamless = seamless;
|
|
14329
14061
|
this.account = account;
|
|
14062
|
+
this.api = api;
|
|
14330
14063
|
}
|
|
14331
14064
|
async listPositions(address) {
|
|
14332
|
-
const isProd = !this.configManager.getConfig().isTestnet;
|
|
14333
14065
|
const accessToken = await this.configManager.getAccessToken();
|
|
14334
14066
|
if (!accessToken) {
|
|
14335
14067
|
return {
|
|
@@ -14338,7 +14070,7 @@ var Position = class {
|
|
|
14338
14070
|
};
|
|
14339
14071
|
}
|
|
14340
14072
|
try {
|
|
14341
|
-
const res = await getPositions(accessToken, address
|
|
14073
|
+
const res = await this.api.getPositions(accessToken, address);
|
|
14342
14074
|
return {
|
|
14343
14075
|
code: 0,
|
|
14344
14076
|
data: res.data
|
|
@@ -14352,7 +14084,6 @@ var Position = class {
|
|
|
14352
14084
|
}
|
|
14353
14085
|
}
|
|
14354
14086
|
async getPositionHistory(params, address) {
|
|
14355
|
-
const config = this.configManager.getConfig();
|
|
14356
14087
|
const accessToken = await this.configManager.getAccessToken();
|
|
14357
14088
|
if (!accessToken) {
|
|
14358
14089
|
throw new MyxSDKError(
|
|
@@ -14360,11 +14091,8 @@ var Position = class {
|
|
|
14360
14091
|
"Invalid access token"
|
|
14361
14092
|
);
|
|
14362
14093
|
}
|
|
14363
|
-
const res = await getPositionHistory(
|
|
14364
|
-
{ accessToken, ...params, address }
|
|
14365
|
-
{
|
|
14366
|
-
isProd: !config?.isTestnet
|
|
14367
|
-
}
|
|
14094
|
+
const res = await this.api.getPositionHistory(
|
|
14095
|
+
{ accessToken, ...params, address }
|
|
14368
14096
|
);
|
|
14369
14097
|
return {
|
|
14370
14098
|
code: 0,
|
|
@@ -14587,12 +14315,13 @@ var OrderStatus = {
|
|
|
14587
14315
|
import { ethers as ethers6 } from "ethers";
|
|
14588
14316
|
import dayjs2 from "dayjs";
|
|
14589
14317
|
var Order = class {
|
|
14590
|
-
constructor(configManager, logger, utils, seamless, account) {
|
|
14318
|
+
constructor(configManager, logger, utils, seamless, account, api) {
|
|
14591
14319
|
this.configManager = configManager;
|
|
14592
14320
|
this.logger = logger;
|
|
14593
14321
|
this.utils = utils;
|
|
14594
14322
|
this.seamless = seamless;
|
|
14595
14323
|
this.account = account;
|
|
14324
|
+
this.api = api;
|
|
14596
14325
|
}
|
|
14597
14326
|
async createIncreaseOrder(params, tradingFee) {
|
|
14598
14327
|
try {
|
|
@@ -15569,7 +15298,6 @@ var Order = class {
|
|
|
15569
15298
|
}
|
|
15570
15299
|
}
|
|
15571
15300
|
async getOrders(address) {
|
|
15572
|
-
const isProd = !this.configManager.getConfig().isTestnet;
|
|
15573
15301
|
const accessToken = await this.configManager.getAccessToken();
|
|
15574
15302
|
if (!accessToken) {
|
|
15575
15303
|
return {
|
|
@@ -15578,7 +15306,7 @@ var Order = class {
|
|
|
15578
15306
|
};
|
|
15579
15307
|
}
|
|
15580
15308
|
try {
|
|
15581
|
-
const res = await getOrders(accessToken, address
|
|
15309
|
+
const res = await this.api.getOrders(accessToken, address);
|
|
15582
15310
|
return {
|
|
15583
15311
|
code: 0,
|
|
15584
15312
|
data: res.data
|
|
@@ -15600,9 +15328,7 @@ var Order = class {
|
|
|
15600
15328
|
"Invalid access token"
|
|
15601
15329
|
);
|
|
15602
15330
|
}
|
|
15603
|
-
const res = await getHistoryOrders({ accessToken, ...params, address }
|
|
15604
|
-
isProd: !config?.isTestnet
|
|
15605
|
-
});
|
|
15331
|
+
const res = await this.api.getHistoryOrders({ accessToken, ...params, address });
|
|
15606
15332
|
return {
|
|
15607
15333
|
code: 0,
|
|
15608
15334
|
data: res.data
|
|
@@ -20429,8 +20155,7 @@ var Utils = class {
|
|
|
20429
20155
|
}
|
|
20430
20156
|
async getOraclePrice(poolId, chainId) {
|
|
20431
20157
|
try {
|
|
20432
|
-
const
|
|
20433
|
-
const priceData = await getPriceData(chainId, poolId, isProd);
|
|
20158
|
+
const priceData = await getPriceData(chainId, poolId);
|
|
20434
20159
|
if (!priceData) throw new Error("Failed to get price data");
|
|
20435
20160
|
return priceData;
|
|
20436
20161
|
} catch (error) {
|
|
@@ -21316,38 +21041,10 @@ var Account = class {
|
|
|
21316
21041
|
data: balance
|
|
21317
21042
|
};
|
|
21318
21043
|
}
|
|
21319
|
-
/**
|
|
21320
|
-
* get tradable amount
|
|
21321
|
-
*/
|
|
21322
|
-
async getTradableAmount({ poolId, chainId, address }) {
|
|
21323
|
-
const contractAddress = getContractAddressByChainId(chainId);
|
|
21324
|
-
const provider = await getJSONProvider(chainId);
|
|
21325
|
-
const accountContract = new ethers8.Contract(
|
|
21326
|
-
contractAddress.Account,
|
|
21327
|
-
Account_default,
|
|
21328
|
-
provider
|
|
21329
|
-
);
|
|
21330
|
-
try {
|
|
21331
|
-
const assets = await accountContract.getTradableAmount(address, poolId);
|
|
21332
|
-
const data = {
|
|
21333
|
-
profitIsReleased: assets[0],
|
|
21334
|
-
freeAmount: assets[1],
|
|
21335
|
-
tradeableProfit: assets[2]
|
|
21336
|
-
};
|
|
21337
|
-
return {
|
|
21338
|
-
code: 0,
|
|
21339
|
-
data
|
|
21340
|
-
};
|
|
21341
|
-
} catch (error) {
|
|
21342
|
-
return {
|
|
21343
|
-
code: -1
|
|
21344
|
-
};
|
|
21345
|
-
}
|
|
21346
|
-
}
|
|
21347
21044
|
async getAvailableMarginBalance({ poolId, chainId, address }) {
|
|
21348
21045
|
try {
|
|
21349
21046
|
const isProd = !this.configManager.getConfig().isTestnet;
|
|
21350
|
-
const poolListRes = await getPoolList(
|
|
21047
|
+
const poolListRes = await this.client.api.getPoolList();
|
|
21351
21048
|
if (poolListRes.code !== 9200) {
|
|
21352
21049
|
throw new MyxSDKError(
|
|
21353
21050
|
"REQUEST_FAILED" /* RequestFailed */,
|
|
@@ -21388,7 +21085,6 @@ var Account = class {
|
|
|
21388
21085
|
const availableAccountMarginBalance = accountMargin - usedMargin;
|
|
21389
21086
|
return availableAccountMarginBalance;
|
|
21390
21087
|
} catch (error) {
|
|
21391
|
-
this.logger.info("getAvailableMarginBalance error-->", error);
|
|
21392
21088
|
throw new MyxSDKError(
|
|
21393
21089
|
"REQUEST_FAILED" /* RequestFailed */,
|
|
21394
21090
|
"Failed to get getAvailableMarginBalance"
|
|
@@ -21396,7 +21092,6 @@ var Account = class {
|
|
|
21396
21092
|
}
|
|
21397
21093
|
}
|
|
21398
21094
|
async getTradeFlow(params, address) {
|
|
21399
|
-
const config = this.configManager.getConfig();
|
|
21400
21095
|
const accessToken = await this.configManager.getAccessToken();
|
|
21401
21096
|
if (!accessToken) {
|
|
21402
21097
|
throw new MyxSDKError(
|
|
@@ -21404,9 +21099,7 @@ var Account = class {
|
|
|
21404
21099
|
"Invalid access token"
|
|
21405
21100
|
);
|
|
21406
21101
|
}
|
|
21407
|
-
const res = await getTradeFlow({ accessToken, ...params, address }
|
|
21408
|
-
isProd: !config?.isTestnet
|
|
21409
|
-
});
|
|
21102
|
+
const res = await this.client.api.getTradeFlow({ accessToken, ...params, address });
|
|
21410
21103
|
return {
|
|
21411
21104
|
code: 0,
|
|
21412
21105
|
data: res.data
|
|
@@ -21440,9 +21133,7 @@ var Account = class {
|
|
|
21440
21133
|
data: functionHash,
|
|
21441
21134
|
nonce: nonce.toString()
|
|
21442
21135
|
};
|
|
21443
|
-
this.logger.info("withdraw forward tx params --->", forwardTxParams);
|
|
21444
21136
|
const rs2 = await this.client.seamless.forwarderTx(forwardTxParams, chainId, seamlessWallet);
|
|
21445
|
-
console.log("rs-->", rs2);
|
|
21446
21137
|
return {
|
|
21447
21138
|
code: 0,
|
|
21448
21139
|
message: "withdraw success",
|
|
@@ -21516,7 +21207,6 @@ var Account = class {
|
|
|
21516
21207
|
};
|
|
21517
21208
|
this.logger.info("deposit forward tx params --->", forwardTxParams);
|
|
21518
21209
|
const rs2 = await this.client.seamless.forwarderTx(forwardTxParams, chainId, seamlessWallet);
|
|
21519
|
-
console.log("rs-->", rs2);
|
|
21520
21210
|
return {
|
|
21521
21211
|
code: 0,
|
|
21522
21212
|
message: "deposit success",
|
|
@@ -21575,6 +21265,282 @@ var Account = class {
|
|
|
21575
21265
|
}
|
|
21576
21266
|
};
|
|
21577
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
|
+
|
|
21578
21544
|
// src/manager/seamless/index.ts
|
|
21579
21545
|
import CryptoJS from "crypto-js";
|
|
21580
21546
|
import { toUtf8Bytes, keccak256, hexlify, ethers as ethers9, isHexString, getBytes, ZeroAddress as ZeroAddress2 } from "ethers";
|
|
@@ -21750,11 +21716,12 @@ async function signPermit(provider, contract, owner, spender, value, nonce, dead
|
|
|
21750
21716
|
return { v, r, s };
|
|
21751
21717
|
}
|
|
21752
21718
|
var Seamless = class {
|
|
21753
|
-
constructor(configManager, logger, utils, account) {
|
|
21719
|
+
constructor(configManager, logger, utils, account, api) {
|
|
21754
21720
|
this.configManager = configManager;
|
|
21755
21721
|
this.logger = logger;
|
|
21756
21722
|
this.utils = utils;
|
|
21757
21723
|
this.account = account;
|
|
21724
|
+
this.api = api;
|
|
21758
21725
|
}
|
|
21759
21726
|
async onCheckRelayer(account, relayer, chainId) {
|
|
21760
21727
|
const forwarderContract = await getForwarderContract(chainId);
|
|
@@ -21834,7 +21801,6 @@ var Seamless = class {
|
|
|
21834
21801
|
data,
|
|
21835
21802
|
nonce
|
|
21836
21803
|
}, chainId, provider) {
|
|
21837
|
-
const isProd = !this.configManager.getConfig().isTestnet;
|
|
21838
21804
|
const forwarderContract = await getForwarderContract(chainId);
|
|
21839
21805
|
const forwarderJsonRpcContractDomain = await forwarderContract.eip712Domain();
|
|
21840
21806
|
const domain = {
|
|
@@ -21853,7 +21819,7 @@ var Seamless = class {
|
|
|
21853
21819
|
deadline,
|
|
21854
21820
|
data
|
|
21855
21821
|
});
|
|
21856
|
-
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);
|
|
21857
21823
|
return txRs;
|
|
21858
21824
|
}
|
|
21859
21825
|
async authorizeSeamlessAccount({ approve: approve2, seamlessAddress, chainId }) {
|
|
@@ -21903,7 +21869,7 @@ var Seamless = class {
|
|
|
21903
21869
|
if (!txRs.data?.txHash) {
|
|
21904
21870
|
const retryOptions = { n: 10, minWait: 250, maxWait: 1e3 };
|
|
21905
21871
|
const { promise } = retry(async () => {
|
|
21906
|
-
const getRs = await fetchForwarderGetApi({
|
|
21872
|
+
const getRs = await this.api.fetchForwarderGetApi({
|
|
21907
21873
|
requestId: txRs.data?.requestId
|
|
21908
21874
|
});
|
|
21909
21875
|
if (getRs.data?.status === 9 /* EXECUTED */) {
|
|
@@ -22081,15 +22047,16 @@ var MyxClient = class {
|
|
|
22081
22047
|
this.logger = new Logger({
|
|
22082
22048
|
logLevel: options.logLevel
|
|
22083
22049
|
});
|
|
22050
|
+
const lp = MxSDK.getInstance();
|
|
22051
|
+
lp.setConfigManager(this.configManager);
|
|
22084
22052
|
this.utils = new Utils(this.configManager, this.logger);
|
|
22053
|
+
this.api = new Api(this.configManager, this.logger);
|
|
22085
22054
|
this.account = new Account(this.configManager, this.logger, this.utils, this);
|
|
22086
|
-
this.seamless = new Seamless(this.configManager, this.logger, this.utils, this.account);
|
|
22087
|
-
this.markets = new Markets(this.configManager, this.utils);
|
|
22088
|
-
this.position = new Position(this.configManager, this.logger, this.utils, this.seamless, this.account);
|
|
22089
|
-
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);
|
|
22090
22059
|
this.subscription = new SubScription(this.configManager, this.logger);
|
|
22091
|
-
const lp = MxSDK.getInstance();
|
|
22092
|
-
lp.setConfigManager(this.configManager);
|
|
22093
22060
|
}
|
|
22094
22061
|
/**
|
|
22095
22062
|
* auth the client
|
|
@@ -22143,48 +22110,31 @@ export {
|
|
|
22143
22110
|
TradeFlowTypeEnum,
|
|
22144
22111
|
TriggerType2 as TriggerType,
|
|
22145
22112
|
TriggerTypeEnum,
|
|
22146
|
-
addFavorite,
|
|
22147
22113
|
approve,
|
|
22148
22114
|
base_exports as base,
|
|
22149
22115
|
bigintAmountSlipperCalculator,
|
|
22150
22116
|
bigintTradingGasPriceWithRatio,
|
|
22151
22117
|
bigintTradingGasToRatioCalculator,
|
|
22152
|
-
fetchForwarderGetApi,
|
|
22153
22118
|
formatUnits2 as formatUnits,
|
|
22154
|
-
forwarderTxApi,
|
|
22155
|
-
getAllTickers,
|
|
22156
22119
|
getAllowanceApproved,
|
|
22157
22120
|
getBalanceOf,
|
|
22158
22121
|
getBaseDetail,
|
|
22159
22122
|
getBaseUrlByEnv,
|
|
22160
|
-
getFavoritesList,
|
|
22161
22123
|
getForwardUrlByEnv,
|
|
22162
|
-
getHistoryOrders,
|
|
22163
|
-
getKlineData,
|
|
22164
|
-
getKlineLatestBar,
|
|
22165
22124
|
getMarketDetail,
|
|
22166
22125
|
getMarketList,
|
|
22167
22126
|
getOraclePrice,
|
|
22168
|
-
getOrders,
|
|
22169
22127
|
getPoolDetail,
|
|
22170
|
-
getPoolLevelConfig,
|
|
22171
22128
|
getPoolList,
|
|
22172
22129
|
getPoolOpenOrders,
|
|
22173
|
-
getPoolSymbolAll,
|
|
22174
|
-
getPositionHistory,
|
|
22175
|
-
getPositions,
|
|
22176
22130
|
getPriceData,
|
|
22177
22131
|
getPricesData,
|
|
22178
22132
|
getTickerData,
|
|
22179
22133
|
getTokenInfo,
|
|
22180
|
-
getTradeFlow,
|
|
22181
22134
|
market_exports as market,
|
|
22182
22135
|
parseUnits17 as parseUnits,
|
|
22183
22136
|
pool_exports as pool,
|
|
22184
|
-
quote_exports as quote
|
|
22185
|
-
removeFavorite,
|
|
22186
|
-
searchMarket,
|
|
22187
|
-
searchMarketAuth
|
|
22137
|
+
quote_exports as quote
|
|
22188
22138
|
};
|
|
22189
22139
|
/**
|
|
22190
22140
|
* MyxLogger
|