@myx-trade/sdk 0.1.36 → 0.1.38
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 +26 -28
- package/dist/index.d.ts +26 -28
- package/dist/index.js +1097 -916
- package/dist/index.mjs +1035 -854
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -36,10 +36,9 @@ __export(index_exports, {
|
|
|
36
36
|
CloseTypeEnum: () => CloseTypeEnum,
|
|
37
37
|
Direction: () => Direction,
|
|
38
38
|
DirectionEnum: () => DirectionEnum,
|
|
39
|
-
ErrorCode: () =>
|
|
39
|
+
ErrorCode: () => ErrorCode,
|
|
40
40
|
ExecTypeEnum: () => ExecTypeEnum,
|
|
41
41
|
HttpKlineIntervalEnum: () => HttpKlineIntervalEnum,
|
|
42
|
-
Market: () => Market,
|
|
43
42
|
MarketCapType: () => MarketCapType,
|
|
44
43
|
MarketPoolState: () => MarketPoolState,
|
|
45
44
|
MarketType: () => MarketType,
|
|
@@ -63,7 +62,7 @@ __export(index_exports, {
|
|
|
63
62
|
bigintAmountSlipperCalculator: () => bigintAmountSlipperCalculator,
|
|
64
63
|
bigintTradingGasPriceWithRatio: () => bigintTradingGasPriceWithRatio,
|
|
65
64
|
bigintTradingGasToRatioCalculator: () => bigintTradingGasToRatioCalculator,
|
|
66
|
-
formatUnits: () =>
|
|
65
|
+
formatUnits: () => import_ethers22.formatUnits,
|
|
67
66
|
getAllTickers: () => getAllTickers,
|
|
68
67
|
getAllowanceApproved: () => getAllowanceApproved,
|
|
69
68
|
getBalanceOf: () => getBalanceOf,
|
|
@@ -73,6 +72,7 @@ __export(index_exports, {
|
|
|
73
72
|
getKlineData: () => getKlineData,
|
|
74
73
|
getKlineLatestBar: () => getKlineLatestBar,
|
|
75
74
|
getMarketDetail: () => getMarketDetail,
|
|
75
|
+
getMarketList: () => getMarketList,
|
|
76
76
|
getOraclePrice: () => getOraclePrice,
|
|
77
77
|
getOrders: () => getOrders,
|
|
78
78
|
getPoolDetail: () => getPoolDetail,
|
|
@@ -86,7 +86,7 @@ __export(index_exports, {
|
|
|
86
86
|
getTokenInfo: () => getTokenInfo,
|
|
87
87
|
getTradeFlow: () => getTradeFlow,
|
|
88
88
|
market: () => market_exports,
|
|
89
|
-
parseUnits: () =>
|
|
89
|
+
parseUnits: () => import_ethers22.parseUnits,
|
|
90
90
|
pool: () => pool_exports,
|
|
91
91
|
quote: () => quote_exports,
|
|
92
92
|
removeFavorite: () => removeFavorite,
|
|
@@ -1459,37 +1459,25 @@ var ChainId = /* @__PURE__ */ ((ChainId3) => {
|
|
|
1459
1459
|
ChainId3[ChainId3["BSC_MAINNET"] = 56] = "BSC_MAINNET";
|
|
1460
1460
|
return ChainId3;
|
|
1461
1461
|
})(ChainId || {});
|
|
1462
|
-
var SupportedChainIds = [421614 /* ARB_TESTNET */];
|
|
1463
|
-
function isSupportedChainFn(
|
|
1464
|
-
return !!
|
|
1462
|
+
var SupportedChainIds = [421614 /* ARB_TESTNET */, 59141 /* LINEA_SEPOLIA */];
|
|
1463
|
+
function isSupportedChainFn(chainId) {
|
|
1464
|
+
return !!chainId && SupportedChainIds.includes(chainId);
|
|
1465
1465
|
}
|
|
1466
1466
|
|
|
1467
1467
|
// src/config/address/ARB_TEST_SEPOLIA.ts
|
|
1468
|
-
var import_ethers = require("ethers");
|
|
1469
1468
|
var ARB_TEST_SEPOLIA = {
|
|
1470
|
-
USDC: "0x7E248Ec1721639413A280d9E82e2862Cae2E6E28",
|
|
1471
1469
|
POOL_MANAGER: "0xA4A1dfbe40cB725A79D34bd529f0C1b54AB46954",
|
|
1472
1470
|
Account: "0x6136899e8c77C452bc46AcD786aA2C09fD31f947",
|
|
1473
|
-
POOL_VIEW: "",
|
|
1474
|
-
HYPER_VAULT: import_ethers.ZeroAddress,
|
|
1475
|
-
FEE_COLLECTOR: "",
|
|
1476
1471
|
POSITION_MANAGER: "0x002F28be205E9A1e279d2eeF1f5e472CeA1d910C",
|
|
1477
|
-
ORDER_MANAGER: "
|
|
1478
|
-
|
|
1479
|
-
FRONT_FACET: "",
|
|
1480
|
-
// router address
|
|
1481
|
-
DELEGATE_FACET: "",
|
|
1482
|
-
// Seamless router address
|
|
1483
|
-
FAUCET: "",
|
|
1484
|
-
UI_POOL_DATA_PROVIDER: "",
|
|
1485
|
-
UI_POSITION_DATA_PROVIDER: "",
|
|
1486
|
-
PYTH: "0x361360Def495BfB4F0BE59AB11878D042c458155",
|
|
1472
|
+
ORDER_MANAGER: "0x4eDe4E20162551F293B9D6f33E8567314fb5612f",
|
|
1473
|
+
PYTH: "0x4374e5a8b9C22271E9EB878A2AA31DE97DF15DAF",
|
|
1487
1474
|
// !!! 非Pyth Adapter
|
|
1488
|
-
MYX: import_ethers.ZeroAddress,
|
|
1489
1475
|
ERC20: "0x7E248Ec1721639413A280d9E82e2862Cae2E6E28",
|
|
1490
1476
|
LIQUIDITY_ROUTER: "0xd185C3f675d991735FCF6885Ff6BADE02A21313d",
|
|
1491
1477
|
BASE_POOL: "0x2c6AdaE4A01836487842b7369c1db3F441871E83",
|
|
1492
1478
|
QUOTE_POOL: "0xe1Ff495206635570A8Eaf9517125Ce66a2d09d32",
|
|
1479
|
+
BROKER: "0xB3DaeFF433c005e214D6cd73C35cD4bBCe7f94fD",
|
|
1480
|
+
// MYXBroker
|
|
1493
1481
|
ORACLE: "0x574001F6cB520b15d5a6db9F7B7a0ebf1A8E25c0",
|
|
1494
1482
|
// MYXOracle
|
|
1495
1483
|
EIP7702Delegation: "0x4e1B9aDf5Aa4a893f578c8502E6E28841b2403f3",
|
|
@@ -1504,10 +1492,10 @@ var address_default = {
|
|
|
1504
1492
|
};
|
|
1505
1493
|
|
|
1506
1494
|
// src/web3/index.ts
|
|
1507
|
-
var
|
|
1495
|
+
var import_ethers2 = require("ethers");
|
|
1508
1496
|
|
|
1509
1497
|
// src/address.ts
|
|
1510
|
-
var
|
|
1498
|
+
var import_ethers = require("ethers");
|
|
1511
1499
|
var import_lodash_es = require("lodash-es");
|
|
1512
1500
|
var ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
1513
1501
|
var _Address = class _Address {
|
|
@@ -1515,7 +1503,7 @@ var _Address = class _Address {
|
|
|
1515
1503
|
if ((0, import_lodash_es.isUndefined)(addr) || Number(addr) === 0) {
|
|
1516
1504
|
addr = ZERO_ADDRESS.toString();
|
|
1517
1505
|
}
|
|
1518
|
-
this._addr = (0,
|
|
1506
|
+
this._addr = (0, import_ethers.getAddress)(addr);
|
|
1519
1507
|
}
|
|
1520
1508
|
toString() {
|
|
1521
1509
|
return this._addr.toString();
|
|
@@ -1714,10 +1702,10 @@ var CHAIN_INFO = {
|
|
|
1714
1702
|
[42161 /* ARB_MAINNET */]: ARB_MAINNET_default.chainInfo,
|
|
1715
1703
|
[56 /* BSC_MAINNET */]: BSC_MAINNET_default.chainInfo
|
|
1716
1704
|
};
|
|
1717
|
-
function getChainInfo(
|
|
1718
|
-
const chainInfo = CHAIN_INFO[
|
|
1705
|
+
function getChainInfo(chainId) {
|
|
1706
|
+
const chainInfo = CHAIN_INFO[chainId];
|
|
1719
1707
|
if (!chainInfo) {
|
|
1720
|
-
throw new Error(`Could not find information with chain id ${
|
|
1708
|
+
throw new Error(`Could not find information with chain id ${chainId}`);
|
|
1721
1709
|
}
|
|
1722
1710
|
return chainInfo;
|
|
1723
1711
|
}
|
|
@@ -1753,15 +1741,15 @@ function checkNetworks(networks) {
|
|
|
1753
1741
|
return result;
|
|
1754
1742
|
}
|
|
1755
1743
|
var RotationProvider = class extends import_providers.BaseProvider {
|
|
1756
|
-
constructor(urls,
|
|
1757
|
-
super(
|
|
1744
|
+
constructor(urls, chainId, config) {
|
|
1745
|
+
super(chainId);
|
|
1758
1746
|
this.currentProviderIndex = 0;
|
|
1759
1747
|
this.firstRotationTimestamp = 0;
|
|
1760
1748
|
// number of full loops through provider array before throwing an error
|
|
1761
1749
|
this.maxRetries = 0;
|
|
1762
1750
|
this.retries = 0;
|
|
1763
1751
|
this.lastError = "";
|
|
1764
|
-
this.providers = urls.map((url) => new import_providers.StaticJsonRpcProvider(url,
|
|
1752
|
+
this.providers = urls.map((url) => new import_providers.StaticJsonRpcProvider(url, chainId));
|
|
1765
1753
|
this.maxRetries = config?.maxRetries || MAX_RETRIES;
|
|
1766
1754
|
this.fallForwardDelay = config?.fallFowardDelay || DEFAULT_FALL_FORWARD_DELAY;
|
|
1767
1755
|
}
|
|
@@ -1825,7 +1813,7 @@ var RotationProvider = class extends import_providers.BaseProvider {
|
|
|
1825
1813
|
// package.json
|
|
1826
1814
|
var package_default = {
|
|
1827
1815
|
name: "@myx-trade/sdk",
|
|
1828
|
-
version: "0.1.
|
|
1816
|
+
version: "0.1.38",
|
|
1829
1817
|
private: false,
|
|
1830
1818
|
publishConfig: {
|
|
1831
1819
|
access: "public"
|
|
@@ -1898,82 +1886,483 @@ var package_default = {
|
|
|
1898
1886
|
}
|
|
1899
1887
|
};
|
|
1900
1888
|
|
|
1901
|
-
// src/
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
if (chainConfig.privateJsonRPCUrl) {
|
|
1912
|
-
chainProviders.push(chainConfig.privateJsonRPCUrl);
|
|
1913
|
-
}
|
|
1914
|
-
if (chainConfig.publicJsonRPCUrl.length > 0) {
|
|
1915
|
-
chainConfig.publicJsonRPCUrl.map((rpc) => chainProviders.push(rpc));
|
|
1916
|
-
}
|
|
1917
|
-
if (chainProviders.length === 0) {
|
|
1918
|
-
throw new Error(`${chainId2} has no jsonRPCUrl configured`);
|
|
1919
|
-
}
|
|
1920
|
-
if (chainProviders.length === 1) {
|
|
1921
|
-
return new import_ethers3.JsonRpcProvider(chainProviders[0], chainId2, {
|
|
1922
|
-
staticNetwork: true
|
|
1923
|
-
});
|
|
1924
|
-
} else {
|
|
1925
|
-
return new RotationProvider(chainProviders, chainId2);
|
|
1889
|
+
// src/api/request.ts
|
|
1890
|
+
var import_wretch = __toESM(require("wretch"));
|
|
1891
|
+
var client = (0, import_wretch.default)();
|
|
1892
|
+
var buildQueryOptions = (url, params) => {
|
|
1893
|
+
if (params) {
|
|
1894
|
+
params = JSON.parse(JSON.stringify(params));
|
|
1895
|
+
if (url.includes("?")) {
|
|
1896
|
+
return url + "&" + new URLSearchParams(params).toString();
|
|
1897
|
+
}
|
|
1898
|
+
return url + "?" + new URLSearchParams(params).toString();
|
|
1926
1899
|
}
|
|
1900
|
+
return url;
|
|
1927
1901
|
};
|
|
1928
|
-
var
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
}
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
}
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
}
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1902
|
+
var http = {
|
|
1903
|
+
/**
|
|
1904
|
+
* Get request
|
|
1905
|
+
*/
|
|
1906
|
+
get: (url, params, options = {}) => {
|
|
1907
|
+
const requestUrl = buildQueryOptions(url, params);
|
|
1908
|
+
return client.url(requestUrl).options(options).get().json();
|
|
1909
|
+
},
|
|
1910
|
+
/**
|
|
1911
|
+
* Post request
|
|
1912
|
+
*/
|
|
1913
|
+
post: (url, data, options = {}) => {
|
|
1914
|
+
return client.url(url).options(options).post(data).json();
|
|
1915
|
+
},
|
|
1916
|
+
/**
|
|
1917
|
+
* Put request
|
|
1918
|
+
*/
|
|
1919
|
+
put: (url, data, options = {}) => {
|
|
1920
|
+
return client.url(url).options(options).put(data).json();
|
|
1921
|
+
},
|
|
1922
|
+
/**
|
|
1923
|
+
* Delete request
|
|
1924
|
+
*/
|
|
1925
|
+
delete: (url, options = {}) => {
|
|
1926
|
+
return client.url(url).options(options).delete().json();
|
|
1950
1927
|
}
|
|
1951
1928
|
};
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1929
|
+
|
|
1930
|
+
// src/api/utils.ts
|
|
1931
|
+
function encodeQueryParam(key, value) {
|
|
1932
|
+
const encodedKey = encodeURIComponent(key);
|
|
1933
|
+
return `${encodedKey}=${encodeURIComponent(typeof value === "number" ? value : `${value}`)}`;
|
|
1957
1934
|
}
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1935
|
+
function addQueryParam(query, key) {
|
|
1936
|
+
return encodeQueryParam(key, query[key]);
|
|
1937
|
+
}
|
|
1938
|
+
function addArrayQueryParam(query, key) {
|
|
1939
|
+
const value = query[key];
|
|
1940
|
+
return value.map((v) => encodeQueryParam(key, v)).join("&");
|
|
1941
|
+
}
|
|
1942
|
+
function toQueryString(rawQuery) {
|
|
1943
|
+
const query = rawQuery || {};
|
|
1944
|
+
const keys = Object.keys(query).filter((key) => "undefined" !== typeof query[key]);
|
|
1945
|
+
return keys.map((key) => Array.isArray(query[key]) ? addArrayQueryParam(query, key) : addQueryParam(query, key)).join("&");
|
|
1946
|
+
}
|
|
1947
|
+
function addQueryParams(rawQuery) {
|
|
1948
|
+
const queryString = toQueryString(rawQuery);
|
|
1949
|
+
return queryString ? `?${queryString}` : "";
|
|
1950
|
+
}
|
|
1951
|
+
|
|
1952
|
+
// src/api/type.ts
|
|
1953
|
+
var ErrorCode = /* @__PURE__ */ ((ErrorCode3) => {
|
|
1954
|
+
ErrorCode3[ErrorCode3["SUCCESS"] = 9200] = "SUCCESS";
|
|
1955
|
+
ErrorCode3[ErrorCode3["SUCCESS_ORIGIN"] = 0] = "SUCCESS_ORIGIN";
|
|
1956
|
+
ErrorCode3[ErrorCode3["IDENTITY_VERIFICATION_FAILED"] = 9401] = "IDENTITY_VERIFICATION_FAILED";
|
|
1957
|
+
ErrorCode3[ErrorCode3["PERMISSION_DENIED"] = 9403] = "PERMISSION_DENIED";
|
|
1958
|
+
ErrorCode3[ErrorCode3["NOT_EXIST"] = 9404] = "NOT_EXIST";
|
|
1959
|
+
ErrorCode3[ErrorCode3["REQUEST_LIMIT"] = 9429] = "REQUEST_LIMIT";
|
|
1960
|
+
ErrorCode3[ErrorCode3["SERVICE_ERROR"] = 9500] = "SERVICE_ERROR";
|
|
1961
|
+
ErrorCode3[ErrorCode3["MISS_REQUESTED_PARAMETER"] = 9900] = "MISS_REQUESTED_PARAMETER";
|
|
1962
|
+
ErrorCode3[ErrorCode3["INVALID_PARAMETER"] = 9901] = "INVALID_PARAMETER";
|
|
1963
|
+
ErrorCode3["NETWORK_ERROR"] = "ERR_NETWORK";
|
|
1964
|
+
return ErrorCode3;
|
|
1965
|
+
})(ErrorCode || {});
|
|
1966
|
+
var MarketPoolState = /* @__PURE__ */ ((MarketPoolState3) => {
|
|
1967
|
+
MarketPoolState3[MarketPoolState3["Cook"] = 0] = "Cook";
|
|
1968
|
+
MarketPoolState3[MarketPoolState3["Primed"] = 1] = "Primed";
|
|
1969
|
+
MarketPoolState3[MarketPoolState3["Trench"] = 2] = "Trench";
|
|
1970
|
+
MarketPoolState3[MarketPoolState3["PreBench"] = 3] = "PreBench";
|
|
1971
|
+
MarketPoolState3[MarketPoolState3["Bench"] = 4] = "Bench";
|
|
1972
|
+
return MarketPoolState3;
|
|
1973
|
+
})(MarketPoolState || {});
|
|
1974
|
+
var OracleType = /* @__PURE__ */ ((OracleType7) => {
|
|
1975
|
+
OracleType7[OracleType7["Chainlink"] = 1] = "Chainlink";
|
|
1976
|
+
OracleType7[OracleType7["Pyth"] = 2] = "Pyth";
|
|
1977
|
+
return OracleType7;
|
|
1978
|
+
})(OracleType || {});
|
|
1979
|
+
var HttpKlineIntervalEnum = /* @__PURE__ */ ((HttpKlineIntervalEnum2) => {
|
|
1980
|
+
HttpKlineIntervalEnum2[HttpKlineIntervalEnum2["Minute1"] = 1] = "Minute1";
|
|
1981
|
+
HttpKlineIntervalEnum2[HttpKlineIntervalEnum2["Minute5"] = 5] = "Minute5";
|
|
1982
|
+
HttpKlineIntervalEnum2[HttpKlineIntervalEnum2["Minute15"] = 15] = "Minute15";
|
|
1983
|
+
HttpKlineIntervalEnum2[HttpKlineIntervalEnum2["Minute30"] = 30] = "Minute30";
|
|
1984
|
+
HttpKlineIntervalEnum2[HttpKlineIntervalEnum2["Hour1"] = 60] = "Hour1";
|
|
1985
|
+
HttpKlineIntervalEnum2[HttpKlineIntervalEnum2["Hour4"] = 240] = "Hour4";
|
|
1986
|
+
HttpKlineIntervalEnum2[HttpKlineIntervalEnum2["Day1"] = 1440] = "Day1";
|
|
1987
|
+
HttpKlineIntervalEnum2[HttpKlineIntervalEnum2["Week1"] = 10080] = "Week1";
|
|
1988
|
+
HttpKlineIntervalEnum2[HttpKlineIntervalEnum2["Month1"] = 40320] = "Month1";
|
|
1989
|
+
return HttpKlineIntervalEnum2;
|
|
1990
|
+
})(HttpKlineIntervalEnum || {});
|
|
1991
|
+
var MarketType = /* @__PURE__ */ ((MarketType2) => {
|
|
1992
|
+
MarketType2[MarketType2["Contract"] = 1] = "Contract";
|
|
1993
|
+
MarketType2[MarketType2["Cook"] = 2] = "Cook";
|
|
1994
|
+
MarketType2[MarketType2["Earn"] = 3] = "Earn";
|
|
1995
|
+
return MarketType2;
|
|
1996
|
+
})(MarketType || {});
|
|
1997
|
+
var SearchTypeEnum = /* @__PURE__ */ ((SearchTypeEnum2) => {
|
|
1998
|
+
SearchTypeEnum2[SearchTypeEnum2["All"] = 0] = "All";
|
|
1999
|
+
SearchTypeEnum2[SearchTypeEnum2["Contract"] = 1 /* Contract */] = "Contract";
|
|
2000
|
+
SearchTypeEnum2[SearchTypeEnum2["Cook"] = 2 /* Cook */] = "Cook";
|
|
2001
|
+
SearchTypeEnum2[SearchTypeEnum2["Earn"] = 3 /* Earn */] = "Earn";
|
|
2002
|
+
return SearchTypeEnum2;
|
|
2003
|
+
})(SearchTypeEnum || {});
|
|
2004
|
+
var MarketCapType = /* @__PURE__ */ ((MarketCapType2) => {
|
|
2005
|
+
MarketCapType2[MarketCapType2["BlueChips"] = 1] = "BlueChips";
|
|
2006
|
+
MarketCapType2[MarketCapType2["Alpha"] = 2] = "Alpha";
|
|
2007
|
+
return MarketCapType2;
|
|
2008
|
+
})(MarketCapType || {});
|
|
2009
|
+
var SearchSecondTypeEnum = /* @__PURE__ */ ((SearchSecondTypeEnum2) => {
|
|
2010
|
+
SearchSecondTypeEnum2[SearchSecondTypeEnum2["BlueChips"] = 1 /* BlueChips */] = "BlueChips";
|
|
2011
|
+
SearchSecondTypeEnum2[SearchSecondTypeEnum2["Alpha"] = 2 /* Alpha */] = "Alpha";
|
|
2012
|
+
SearchSecondTypeEnum2[SearchSecondTypeEnum2["Favorite"] = 3] = "Favorite";
|
|
2013
|
+
return SearchSecondTypeEnum2;
|
|
2014
|
+
})(SearchSecondTypeEnum || {});
|
|
2015
|
+
|
|
2016
|
+
// src/api/account/index.ts
|
|
2017
|
+
var OrderTypeEnum = /* @__PURE__ */ ((OrderTypeEnum2) => {
|
|
2018
|
+
OrderTypeEnum2[OrderTypeEnum2["Market"] = 0] = "Market";
|
|
2019
|
+
OrderTypeEnum2[OrderTypeEnum2["Limit"] = 1] = "Limit";
|
|
2020
|
+
OrderTypeEnum2[OrderTypeEnum2["Stop"] = 2] = "Stop";
|
|
2021
|
+
OrderTypeEnum2[OrderTypeEnum2["Conditional"] = 3] = "Conditional";
|
|
2022
|
+
return OrderTypeEnum2;
|
|
2023
|
+
})(OrderTypeEnum || {});
|
|
2024
|
+
var OperationEnum = /* @__PURE__ */ ((OperationEnum2) => {
|
|
2025
|
+
OperationEnum2[OperationEnum2["Increase"] = 0] = "Increase";
|
|
2026
|
+
OperationEnum2[OperationEnum2["Decrease"] = 1] = "Decrease";
|
|
2027
|
+
return OperationEnum2;
|
|
2028
|
+
})(OperationEnum || {});
|
|
2029
|
+
var TriggerTypeEnum = /* @__PURE__ */ ((TriggerTypeEnum2) => {
|
|
2030
|
+
TriggerTypeEnum2[TriggerTypeEnum2["Unknown"] = 0] = "Unknown";
|
|
2031
|
+
TriggerTypeEnum2[TriggerTypeEnum2["GTE"] = 1] = "GTE";
|
|
2032
|
+
TriggerTypeEnum2[TriggerTypeEnum2["LTE"] = 2] = "LTE";
|
|
2033
|
+
return TriggerTypeEnum2;
|
|
2034
|
+
})(TriggerTypeEnum || {});
|
|
2035
|
+
var DirectionEnum = /* @__PURE__ */ ((DirectionEnum2) => {
|
|
2036
|
+
DirectionEnum2[DirectionEnum2["Long"] = 0] = "Long";
|
|
2037
|
+
DirectionEnum2[DirectionEnum2["Short"] = 1] = "Short";
|
|
2038
|
+
return DirectionEnum2;
|
|
2039
|
+
})(DirectionEnum || {});
|
|
2040
|
+
var OrderStatusEnum = /* @__PURE__ */ ((OrderStatusEnum2) => {
|
|
2041
|
+
OrderStatusEnum2[OrderStatusEnum2["Cancelled"] = 1] = "Cancelled";
|
|
2042
|
+
OrderStatusEnum2[OrderStatusEnum2["Expired"] = 2] = "Expired";
|
|
2043
|
+
OrderStatusEnum2[OrderStatusEnum2["Successful"] = 9] = "Successful";
|
|
2044
|
+
return OrderStatusEnum2;
|
|
2045
|
+
})(OrderStatusEnum || {});
|
|
2046
|
+
var ExecTypeEnum = /* @__PURE__ */ ((ExecTypeEnum2) => {
|
|
2047
|
+
ExecTypeEnum2[ExecTypeEnum2["UserEntrust"] = 0] = "UserEntrust";
|
|
2048
|
+
ExecTypeEnum2[ExecTypeEnum2["Liquidation"] = 1] = "Liquidation";
|
|
2049
|
+
ExecTypeEnum2[ExecTypeEnum2["Adl"] = 2] = "Adl";
|
|
2050
|
+
ExecTypeEnum2[ExecTypeEnum2["AdlTrigger"] = 3] = "AdlTrigger";
|
|
2051
|
+
return ExecTypeEnum2;
|
|
2052
|
+
})(ExecTypeEnum || {});
|
|
2053
|
+
var getHistoryOrders = async ({
|
|
2054
|
+
accessToken,
|
|
2055
|
+
...params
|
|
2056
|
+
}) => {
|
|
2057
|
+
return http.get(
|
|
2058
|
+
`${baseUrl}/openapi/gateway/scan/order/closed`,
|
|
2059
|
+
params,
|
|
2060
|
+
{
|
|
2061
|
+
headers: {
|
|
2062
|
+
myx_openapi_access_token: accessToken
|
|
2063
|
+
}
|
|
1964
2064
|
}
|
|
1965
|
-
|
|
1966
|
-
} catch (error) {
|
|
1967
|
-
console.error("Error getting wallet provider:", error);
|
|
1968
|
-
return import_ethers3.ethers.getDefaultProvider("mainnet");
|
|
1969
|
-
}
|
|
2065
|
+
);
|
|
1970
2066
|
};
|
|
1971
|
-
var
|
|
1972
|
-
|
|
1973
|
-
|
|
2067
|
+
var CloseTypeEnum = /* @__PURE__ */ ((CloseTypeEnum2) => {
|
|
2068
|
+
CloseTypeEnum2[CloseTypeEnum2["Open"] = 0] = "Open";
|
|
2069
|
+
CloseTypeEnum2[CloseTypeEnum2["PartialClose"] = 1] = "PartialClose";
|
|
2070
|
+
CloseTypeEnum2[CloseTypeEnum2["FullClose"] = 2] = "FullClose";
|
|
2071
|
+
CloseTypeEnum2[CloseTypeEnum2["Liquidation"] = 3] = "Liquidation";
|
|
2072
|
+
CloseTypeEnum2[CloseTypeEnum2["EarlyClose"] = 4] = "EarlyClose";
|
|
2073
|
+
CloseTypeEnum2[CloseTypeEnum2["MarketClose"] = 5] = "MarketClose";
|
|
2074
|
+
CloseTypeEnum2[CloseTypeEnum2["ADL"] = 6] = "ADL";
|
|
2075
|
+
CloseTypeEnum2[CloseTypeEnum2["TP"] = 7] = "TP";
|
|
2076
|
+
CloseTypeEnum2[CloseTypeEnum2["SL"] = 8] = "SL";
|
|
2077
|
+
CloseTypeEnum2[CloseTypeEnum2["Increase"] = 9] = "Increase";
|
|
2078
|
+
return CloseTypeEnum2;
|
|
2079
|
+
})(CloseTypeEnum || {});
|
|
2080
|
+
var getPositionHistory = async ({
|
|
2081
|
+
accessToken,
|
|
2082
|
+
...params
|
|
2083
|
+
}) => {
|
|
2084
|
+
return http.get(
|
|
2085
|
+
`${baseUrl}/openapi/gateway/scan/position/closed`,
|
|
2086
|
+
params,
|
|
2087
|
+
{
|
|
2088
|
+
headers: {
|
|
2089
|
+
myx_openapi_access_token: accessToken
|
|
2090
|
+
}
|
|
2091
|
+
}
|
|
2092
|
+
);
|
|
1974
2093
|
};
|
|
1975
|
-
|
|
1976
|
-
|
|
2094
|
+
var getTradeFlow = async ({
|
|
2095
|
+
accessToken,
|
|
2096
|
+
...params
|
|
2097
|
+
}) => {
|
|
2098
|
+
return http.get(
|
|
2099
|
+
`${baseUrl}/openapi/gateway/scan/trade/flow`,
|
|
2100
|
+
params,
|
|
2101
|
+
{
|
|
2102
|
+
headers: {
|
|
2103
|
+
myx_openapi_access_token: accessToken
|
|
2104
|
+
}
|
|
2105
|
+
}
|
|
2106
|
+
);
|
|
2107
|
+
};
|
|
2108
|
+
|
|
2109
|
+
// src/api/index.ts
|
|
2110
|
+
var baseUrl = "https://api-test.myx.cash";
|
|
2111
|
+
var getOraclePrice = async (chainId, poolIds = []) => {
|
|
2112
|
+
if (!!poolIds.length) {
|
|
2113
|
+
return http.get(`${baseUrl}/openapi/gateway/quote/price/oracles`, {
|
|
2114
|
+
chainId,
|
|
2115
|
+
poolIds: poolIds.join(",")
|
|
2116
|
+
});
|
|
2117
|
+
}
|
|
2118
|
+
return Promise.reject(new Error("Invalid pool id"));
|
|
2119
|
+
};
|
|
2120
|
+
var getPoolLevelConfig = async ({
|
|
2121
|
+
poolId,
|
|
2122
|
+
chainId
|
|
2123
|
+
}) => {
|
|
2124
|
+
return http.get(
|
|
2125
|
+
`${baseUrl}/openapi/gateway/risk/market_pool/level_config${addQueryParams({
|
|
2126
|
+
poolId,
|
|
2127
|
+
chainId
|
|
2128
|
+
})}`
|
|
2129
|
+
);
|
|
2130
|
+
};
|
|
2131
|
+
var getPoolDetail = async (chainId, poolId) => {
|
|
2132
|
+
return await http.get(
|
|
2133
|
+
`${baseUrl}/openapi/gateway/scan/market/info?chainId=${chainId}&poolId=${poolId}`
|
|
2134
|
+
);
|
|
2135
|
+
};
|
|
2136
|
+
var getPositions = async (accessToken, chainId) => {
|
|
2137
|
+
return await http.get(
|
|
2138
|
+
`${baseUrl}/openapi/gateway/scan/position/open?chainId=${chainId}`,
|
|
2139
|
+
void 0,
|
|
2140
|
+
// params
|
|
2141
|
+
{
|
|
2142
|
+
headers: {
|
|
2143
|
+
myx_openapi_access_token: accessToken
|
|
2144
|
+
}
|
|
2145
|
+
}
|
|
2146
|
+
);
|
|
2147
|
+
};
|
|
2148
|
+
var getOrders = async (accessToken, chainId) => {
|
|
2149
|
+
return await http.get(
|
|
2150
|
+
`${baseUrl}/openapi/gateway/scan/order/open?chainId=${chainId}`,
|
|
2151
|
+
void 0,
|
|
2152
|
+
{ headers: { myx_openapi_access_token: accessToken } }
|
|
2153
|
+
);
|
|
2154
|
+
};
|
|
2155
|
+
var getPoolOpenOrders = async (accessToken, chainId) => {
|
|
2156
|
+
return await http.get(
|
|
2157
|
+
`${baseUrl}/openapi/gateway/scan/market/pool-order/open?chainId=${chainId}`,
|
|
2158
|
+
void 0,
|
|
2159
|
+
{ headers: { myx_openapi_access_token: accessToken } }
|
|
2160
|
+
);
|
|
2161
|
+
};
|
|
2162
|
+
var getKlineData = ({
|
|
2163
|
+
chainId,
|
|
2164
|
+
poolId,
|
|
2165
|
+
endTime,
|
|
2166
|
+
limit,
|
|
2167
|
+
interval
|
|
2168
|
+
}) => {
|
|
2169
|
+
return http.get(
|
|
2170
|
+
`${baseUrl}/openapi/gateway/quote/candles`,
|
|
2171
|
+
{
|
|
2172
|
+
chainId,
|
|
2173
|
+
poolId,
|
|
2174
|
+
endTime,
|
|
2175
|
+
limit,
|
|
2176
|
+
interval
|
|
2177
|
+
}
|
|
2178
|
+
);
|
|
2179
|
+
};
|
|
2180
|
+
var getKlineLatestBar = async (params) => {
|
|
2181
|
+
return http.get(
|
|
2182
|
+
`${baseUrl}/openapi/gateway/quote/candle/latest`,
|
|
2183
|
+
params
|
|
2184
|
+
);
|
|
2185
|
+
};
|
|
2186
|
+
var getTickerData = async ({
|
|
2187
|
+
chainId,
|
|
2188
|
+
poolIds
|
|
2189
|
+
}) => {
|
|
2190
|
+
return http.get(
|
|
2191
|
+
`${baseUrl}/openapi/gateway/quote/candle/tickers`,
|
|
2192
|
+
{
|
|
2193
|
+
chainId,
|
|
2194
|
+
poolIds: poolIds.join(",")
|
|
2195
|
+
}
|
|
2196
|
+
);
|
|
2197
|
+
};
|
|
2198
|
+
var getAllTickers = async () => {
|
|
2199
|
+
return http.get(
|
|
2200
|
+
`${baseUrl}/v2/mx-gateway/quote/candle/all_tickers`
|
|
2201
|
+
);
|
|
2202
|
+
};
|
|
2203
|
+
var searchMarketAuth = async ({
|
|
2204
|
+
accessToken,
|
|
2205
|
+
...params
|
|
2206
|
+
}) => {
|
|
2207
|
+
return http.get(
|
|
2208
|
+
`${baseUrl}/openapi/gateway/scan/market/ac-search`,
|
|
2209
|
+
params,
|
|
2210
|
+
{
|
|
2211
|
+
headers: {
|
|
2212
|
+
myx_openapi_access_token: accessToken
|
|
2213
|
+
}
|
|
2214
|
+
}
|
|
2215
|
+
);
|
|
2216
|
+
};
|
|
2217
|
+
var searchMarket = async ({ ...params }) => {
|
|
2218
|
+
return http.get(
|
|
2219
|
+
`${baseUrl}/openapi/gateway/scan/market/search`,
|
|
2220
|
+
params
|
|
2221
|
+
);
|
|
2222
|
+
};
|
|
2223
|
+
var addFavorite = async ({
|
|
2224
|
+
accessToken,
|
|
2225
|
+
...params
|
|
2226
|
+
}) => {
|
|
2227
|
+
return http.get(
|
|
2228
|
+
`${baseUrl}/openapi/gateway/scan/market/add-favorites`,
|
|
2229
|
+
params,
|
|
2230
|
+
{
|
|
2231
|
+
headers: {
|
|
2232
|
+
myx_openapi_access_token: accessToken
|
|
2233
|
+
}
|
|
2234
|
+
}
|
|
2235
|
+
);
|
|
2236
|
+
};
|
|
2237
|
+
var removeFavorite = async ({
|
|
2238
|
+
accessToken,
|
|
2239
|
+
...params
|
|
2240
|
+
}) => {
|
|
2241
|
+
return http.get(
|
|
2242
|
+
`${baseUrl}/openapi/gateway/scan/market/cancel-favorites`,
|
|
2243
|
+
params,
|
|
2244
|
+
{
|
|
2245
|
+
headers: {
|
|
2246
|
+
myx_openapi_access_token: accessToken
|
|
2247
|
+
}
|
|
2248
|
+
}
|
|
2249
|
+
);
|
|
2250
|
+
};
|
|
2251
|
+
var getFavoritesList = async ({
|
|
2252
|
+
accessToken,
|
|
2253
|
+
...params
|
|
2254
|
+
}) => {
|
|
2255
|
+
return http.get(
|
|
2256
|
+
`${baseUrl}/openapi/gateway/scan/market/favorites`,
|
|
2257
|
+
params,
|
|
2258
|
+
{
|
|
2259
|
+
headers: {
|
|
2260
|
+
myx_openapi_access_token: accessToken
|
|
2261
|
+
}
|
|
2262
|
+
}
|
|
2263
|
+
);
|
|
2264
|
+
};
|
|
2265
|
+
var getBaseDetail = async (params) => {
|
|
2266
|
+
return http.get(
|
|
2267
|
+
`${baseUrl}/openapi/gateway/scan/market/base-details`,
|
|
2268
|
+
params
|
|
2269
|
+
);
|
|
2270
|
+
};
|
|
2271
|
+
var getMarketDetail = async (params) => {
|
|
2272
|
+
return http.get(
|
|
2273
|
+
`${baseUrl}/openapi/gateway/scan/market/detail`,
|
|
2274
|
+
params
|
|
2275
|
+
);
|
|
2276
|
+
};
|
|
2277
|
+
var getMarketList = async () => {
|
|
2278
|
+
return http.get(`${baseUrl}/openapi/gateway/scan/market`);
|
|
2279
|
+
};
|
|
2280
|
+
|
|
2281
|
+
// src/web3/index.ts
|
|
2282
|
+
function getContract(address, ABI, provider) {
|
|
2283
|
+
if (Address.from(address).isEqualTo(import_ethers2.ZeroAddress)) {
|
|
2284
|
+
throw new Error(`Invalid 'address' parameter '${address}'.`);
|
|
2285
|
+
}
|
|
2286
|
+
return new import_ethers2.Contract(address, ABI, provider);
|
|
2287
|
+
}
|
|
2288
|
+
var getJSONProvider = (chainId) => {
|
|
2289
|
+
const chainConfig = getChainInfo(chainId);
|
|
2290
|
+
const chainProviders = [];
|
|
2291
|
+
if (chainConfig.privateJsonRPCUrl) {
|
|
2292
|
+
chainProviders.push(chainConfig.privateJsonRPCUrl);
|
|
2293
|
+
}
|
|
2294
|
+
if (chainConfig.publicJsonRPCUrl.length > 0) {
|
|
2295
|
+
chainConfig.publicJsonRPCUrl.map((rpc) => chainProviders.push(rpc));
|
|
2296
|
+
}
|
|
2297
|
+
if (chainProviders.length === 0) {
|
|
2298
|
+
throw new Error(`${chainId} has no jsonRPCUrl configured`);
|
|
2299
|
+
}
|
|
2300
|
+
if (chainProviders.length === 1) {
|
|
2301
|
+
return new import_ethers2.JsonRpcProvider(chainProviders[0], chainId, {
|
|
2302
|
+
staticNetwork: true
|
|
2303
|
+
});
|
|
2304
|
+
} else {
|
|
2305
|
+
return new RotationProvider(chainProviders, chainId);
|
|
2306
|
+
}
|
|
2307
|
+
};
|
|
2308
|
+
var MxSDK = class _MxSDK {
|
|
2309
|
+
constructor() {
|
|
2310
|
+
this.version = package_default.version;
|
|
2311
|
+
console.log(this.version);
|
|
2312
|
+
this.getMarkets().then();
|
|
2313
|
+
}
|
|
2314
|
+
setConfigManager(configManager) {
|
|
2315
|
+
this.configManager = configManager;
|
|
2316
|
+
}
|
|
2317
|
+
getConfigManager() {
|
|
2318
|
+
return this.configManager;
|
|
2319
|
+
}
|
|
2320
|
+
setProvider(provider) {
|
|
2321
|
+
this.provider = provider;
|
|
2322
|
+
}
|
|
2323
|
+
getProvider() {
|
|
2324
|
+
return this.provider;
|
|
2325
|
+
}
|
|
2326
|
+
static getInstance() {
|
|
2327
|
+
if (!this._instance) {
|
|
2328
|
+
this._instance = new _MxSDK();
|
|
2329
|
+
}
|
|
2330
|
+
return this._instance;
|
|
2331
|
+
}
|
|
2332
|
+
async getMarkets() {
|
|
2333
|
+
try {
|
|
2334
|
+
const result = await getMarketList();
|
|
2335
|
+
this.Markets = result?.data || [];
|
|
2336
|
+
} catch (error) {
|
|
2337
|
+
throw error;
|
|
2338
|
+
}
|
|
2339
|
+
}
|
|
2340
|
+
};
|
|
2341
|
+
var sdk = MxSDK.getInstance();
|
|
2342
|
+
if (typeof window !== "undefined") {
|
|
2343
|
+
window.MxSDK = sdk;
|
|
2344
|
+
} else if (typeof globalThis !== "undefined") {
|
|
2345
|
+
globalThis.MxSDK = sdk;
|
|
2346
|
+
}
|
|
2347
|
+
var getWalletProvider = async (chainId) => {
|
|
2348
|
+
try {
|
|
2349
|
+
const walletClient = sdk.getConfigManager()?.getConfig()?.walletClient;
|
|
2350
|
+
const provider = new import_ethers2.BrowserProvider(walletClient?.transport);
|
|
2351
|
+
if (!provider) {
|
|
2352
|
+
throw new Error("missing provider");
|
|
2353
|
+
}
|
|
2354
|
+
return provider;
|
|
2355
|
+
} catch (error) {
|
|
2356
|
+
console.error("Error getting wallet provider:", error);
|
|
2357
|
+
return import_ethers2.ethers.getDefaultProvider("mainnet");
|
|
2358
|
+
}
|
|
2359
|
+
};
|
|
2360
|
+
var getSignerProvider = async (chainId) => {
|
|
2361
|
+
const provider = await getWalletProvider(chainId);
|
|
2362
|
+
return provider?.getSigner?.();
|
|
2363
|
+
};
|
|
2364
|
+
|
|
2365
|
+
// src/abi/PoolManager.json
|
|
1977
2366
|
var PoolManager_default = [
|
|
1978
2367
|
{
|
|
1979
2368
|
type: "constructor",
|
|
@@ -9070,23 +9459,77 @@ var DataProvider_default = [
|
|
|
9070
9459
|
]
|
|
9071
9460
|
},
|
|
9072
9461
|
{
|
|
9073
|
-
type: "
|
|
9074
|
-
name: "
|
|
9075
|
-
|
|
9076
|
-
stateMutability: "view",
|
|
9077
|
-
payable: false,
|
|
9078
|
-
inputs: [],
|
|
9079
|
-
outputs: [
|
|
9462
|
+
type: "error",
|
|
9463
|
+
name: "PositionNotHealthy",
|
|
9464
|
+
inputs: [
|
|
9080
9465
|
{
|
|
9081
|
-
type: "
|
|
9466
|
+
type: "bytes32",
|
|
9467
|
+
name: "positionId"
|
|
9468
|
+
},
|
|
9469
|
+
{
|
|
9470
|
+
type: "uint256",
|
|
9471
|
+
name: "marginRatio"
|
|
9082
9472
|
}
|
|
9083
9473
|
]
|
|
9084
9474
|
},
|
|
9085
9475
|
{
|
|
9086
|
-
type: "
|
|
9087
|
-
name: "
|
|
9088
|
-
|
|
9089
|
-
|
|
9476
|
+
type: "error",
|
|
9477
|
+
name: "SafeCastOverflowedUintToInt",
|
|
9478
|
+
inputs: [
|
|
9479
|
+
{
|
|
9480
|
+
type: "uint256",
|
|
9481
|
+
name: "value"
|
|
9482
|
+
}
|
|
9483
|
+
]
|
|
9484
|
+
},
|
|
9485
|
+
{
|
|
9486
|
+
type: "function",
|
|
9487
|
+
name: "ADDRESS_MANAGER",
|
|
9488
|
+
constant: true,
|
|
9489
|
+
stateMutability: "view",
|
|
9490
|
+
payable: false,
|
|
9491
|
+
inputs: [],
|
|
9492
|
+
outputs: [
|
|
9493
|
+
{
|
|
9494
|
+
type: "address"
|
|
9495
|
+
}
|
|
9496
|
+
]
|
|
9497
|
+
},
|
|
9498
|
+
{
|
|
9499
|
+
type: "function",
|
|
9500
|
+
name: "getAvailableLiquiditySize",
|
|
9501
|
+
constant: true,
|
|
9502
|
+
stateMutability: "view",
|
|
9503
|
+
payable: false,
|
|
9504
|
+
inputs: [
|
|
9505
|
+
{
|
|
9506
|
+
type: "bytes32",
|
|
9507
|
+
name: "poolId"
|
|
9508
|
+
},
|
|
9509
|
+
{
|
|
9510
|
+
type: "uint8",
|
|
9511
|
+
name: "operation"
|
|
9512
|
+
},
|
|
9513
|
+
{
|
|
9514
|
+
type: "uint8",
|
|
9515
|
+
name: "direction"
|
|
9516
|
+
},
|
|
9517
|
+
{
|
|
9518
|
+
type: "uint256",
|
|
9519
|
+
name: "executePrice"
|
|
9520
|
+
}
|
|
9521
|
+
],
|
|
9522
|
+
outputs: [
|
|
9523
|
+
{
|
|
9524
|
+
type: "uint256"
|
|
9525
|
+
}
|
|
9526
|
+
]
|
|
9527
|
+
},
|
|
9528
|
+
{
|
|
9529
|
+
type: "function",
|
|
9530
|
+
name: "getBrokerFeeTiers",
|
|
9531
|
+
constant: true,
|
|
9532
|
+
stateMutability: "view",
|
|
9090
9533
|
payable: false,
|
|
9091
9534
|
inputs: [
|
|
9092
9535
|
{
|
|
@@ -9112,11 +9555,11 @@ var DataProvider_default = [
|
|
|
9112
9555
|
name: "tier"
|
|
9113
9556
|
},
|
|
9114
9557
|
{
|
|
9115
|
-
type: "
|
|
9558
|
+
type: "uint32",
|
|
9116
9559
|
name: "takerFeeRate"
|
|
9117
9560
|
},
|
|
9118
9561
|
{
|
|
9119
|
-
type: "
|
|
9562
|
+
type: "int32",
|
|
9120
9563
|
name: "makerFeeRate"
|
|
9121
9564
|
}
|
|
9122
9565
|
]
|
|
@@ -9130,11 +9573,11 @@ var DataProvider_default = [
|
|
|
9130
9573
|
name: "assetClass"
|
|
9131
9574
|
},
|
|
9132
9575
|
{
|
|
9133
|
-
type: "
|
|
9576
|
+
type: "uint32",
|
|
9134
9577
|
name: "makerFeeRate"
|
|
9135
9578
|
},
|
|
9136
9579
|
{
|
|
9137
|
-
type: "
|
|
9580
|
+
type: "uint32",
|
|
9138
9581
|
name: "takerFeeRate"
|
|
9139
9582
|
}
|
|
9140
9583
|
]
|
|
@@ -9148,11 +9591,11 @@ var DataProvider_default = [
|
|
|
9148
9591
|
name: "tier"
|
|
9149
9592
|
},
|
|
9150
9593
|
{
|
|
9151
|
-
type: "
|
|
9594
|
+
type: "uint32",
|
|
9152
9595
|
name: "takerFeeRate"
|
|
9153
9596
|
},
|
|
9154
9597
|
{
|
|
9155
|
-
type: "
|
|
9598
|
+
type: "int32",
|
|
9156
9599
|
name: "makerFeeRate"
|
|
9157
9600
|
}
|
|
9158
9601
|
]
|
|
@@ -9202,6 +9645,32 @@ var DataProvider_default = [
|
|
|
9202
9645
|
}
|
|
9203
9646
|
]
|
|
9204
9647
|
},
|
|
9648
|
+
{
|
|
9649
|
+
type: "function",
|
|
9650
|
+
name: "getLiquidationPrice",
|
|
9651
|
+
constant: true,
|
|
9652
|
+
stateMutability: "view",
|
|
9653
|
+
payable: false,
|
|
9654
|
+
inputs: [
|
|
9655
|
+
{
|
|
9656
|
+
type: "bytes32",
|
|
9657
|
+
name: "positionId"
|
|
9658
|
+
},
|
|
9659
|
+
{
|
|
9660
|
+
type: "uint256",
|
|
9661
|
+
name: "marketPrice"
|
|
9662
|
+
},
|
|
9663
|
+
{
|
|
9664
|
+
type: "address",
|
|
9665
|
+
name: "broker"
|
|
9666
|
+
}
|
|
9667
|
+
],
|
|
9668
|
+
outputs: [
|
|
9669
|
+
{
|
|
9670
|
+
type: "uint256"
|
|
9671
|
+
}
|
|
9672
|
+
]
|
|
9673
|
+
},
|
|
9205
9674
|
{
|
|
9206
9675
|
type: "function",
|
|
9207
9676
|
name: "getPoolInfo",
|
|
@@ -9497,74 +9966,178 @@ var DataProvider_default = [
|
|
|
9497
9966
|
]
|
|
9498
9967
|
}
|
|
9499
9968
|
]
|
|
9969
|
+
},
|
|
9970
|
+
{
|
|
9971
|
+
type: "function",
|
|
9972
|
+
name: "getPositionFees",
|
|
9973
|
+
constant: true,
|
|
9974
|
+
stateMutability: "view",
|
|
9975
|
+
payable: false,
|
|
9976
|
+
inputs: [
|
|
9977
|
+
{
|
|
9978
|
+
type: "bytes32",
|
|
9979
|
+
name: "positionId"
|
|
9980
|
+
},
|
|
9981
|
+
{
|
|
9982
|
+
type: "address",
|
|
9983
|
+
name: "broker"
|
|
9984
|
+
},
|
|
9985
|
+
{
|
|
9986
|
+
type: "uint256",
|
|
9987
|
+
name: "price"
|
|
9988
|
+
}
|
|
9989
|
+
],
|
|
9990
|
+
outputs: [
|
|
9991
|
+
{
|
|
9992
|
+
type: "int256",
|
|
9993
|
+
name: "netCollateral"
|
|
9994
|
+
},
|
|
9995
|
+
{
|
|
9996
|
+
type: "uint256",
|
|
9997
|
+
name: "collateralAmount"
|
|
9998
|
+
},
|
|
9999
|
+
{
|
|
10000
|
+
type: "uint256",
|
|
10001
|
+
name: "tradingFee"
|
|
10002
|
+
},
|
|
10003
|
+
{
|
|
10004
|
+
type: "int256",
|
|
10005
|
+
name: "fundingFee"
|
|
10006
|
+
}
|
|
10007
|
+
]
|
|
10008
|
+
},
|
|
10009
|
+
{
|
|
10010
|
+
type: "function",
|
|
10011
|
+
name: "getUserPositionInfos",
|
|
10012
|
+
constant: true,
|
|
10013
|
+
stateMutability: "view",
|
|
10014
|
+
payable: false,
|
|
10015
|
+
inputs: [
|
|
10016
|
+
{
|
|
10017
|
+
type: "address",
|
|
10018
|
+
name: "user"
|
|
10019
|
+
},
|
|
10020
|
+
{
|
|
10021
|
+
type: "bytes32[]",
|
|
10022
|
+
name: "poolIds"
|
|
10023
|
+
}
|
|
10024
|
+
],
|
|
10025
|
+
outputs: [
|
|
10026
|
+
{
|
|
10027
|
+
type: "tuple[]",
|
|
10028
|
+
name: "positions",
|
|
10029
|
+
components: [
|
|
10030
|
+
{
|
|
10031
|
+
type: "bytes32",
|
|
10032
|
+
name: "positionId"
|
|
10033
|
+
},
|
|
10034
|
+
{
|
|
10035
|
+
type: "bytes32",
|
|
10036
|
+
name: "poolId"
|
|
10037
|
+
},
|
|
10038
|
+
{
|
|
10039
|
+
type: "uint256",
|
|
10040
|
+
name: "size"
|
|
10041
|
+
},
|
|
10042
|
+
{
|
|
10043
|
+
type: "uint256",
|
|
10044
|
+
name: "entryPrice"
|
|
10045
|
+
},
|
|
10046
|
+
{
|
|
10047
|
+
type: "int256",
|
|
10048
|
+
name: "fundingRateIndex"
|
|
10049
|
+
},
|
|
10050
|
+
{
|
|
10051
|
+
type: "uint256",
|
|
10052
|
+
name: "earlyClosePrice"
|
|
10053
|
+
},
|
|
10054
|
+
{
|
|
10055
|
+
type: "uint8",
|
|
10056
|
+
name: "direction"
|
|
10057
|
+
},
|
|
10058
|
+
{
|
|
10059
|
+
type: "uint8",
|
|
10060
|
+
name: "riskTier"
|
|
10061
|
+
},
|
|
10062
|
+
{
|
|
10063
|
+
type: "uint64",
|
|
10064
|
+
name: "lastUpdateTime"
|
|
10065
|
+
},
|
|
10066
|
+
{
|
|
10067
|
+
type: "uint256",
|
|
10068
|
+
name: "collateralAmount"
|
|
10069
|
+
}
|
|
10070
|
+
]
|
|
10071
|
+
}
|
|
10072
|
+
]
|
|
9500
10073
|
}
|
|
9501
10074
|
];
|
|
9502
10075
|
|
|
9503
10076
|
// src/web3/providers.ts
|
|
9504
|
-
var getTokenContract = async (
|
|
9505
|
-
const provider = getJSONProvider(
|
|
10077
|
+
var getTokenContract = async (chainId, tokenAddress) => {
|
|
10078
|
+
const provider = getJSONProvider(chainId);
|
|
9506
10079
|
return getContract(tokenAddress, IERC20Metadata_default, provider);
|
|
9507
10080
|
};
|
|
9508
|
-
var getERC20Contract = async (
|
|
9509
|
-
const provider = await getSignerProvider(
|
|
10081
|
+
var getERC20Contract = async (chainId, tokenAddress) => {
|
|
10082
|
+
const provider = await getSignerProvider(chainId);
|
|
9510
10083
|
return getContract(tokenAddress, IERC20Metadata_default, provider);
|
|
9511
10084
|
};
|
|
9512
|
-
var getAccount = async (
|
|
9513
|
-
const provider = await getSignerProvider(
|
|
10085
|
+
var getAccount = async (chainId) => {
|
|
10086
|
+
const provider = await getSignerProvider(chainId);
|
|
9514
10087
|
const account = await provider?.getAddress();
|
|
9515
10088
|
return account ?? void 0;
|
|
9516
10089
|
};
|
|
9517
|
-
var getLiquidityRouterContract = async (
|
|
9518
|
-
const addresses = address_default[
|
|
10090
|
+
var getLiquidityRouterContract = async (chainId) => {
|
|
10091
|
+
const addresses = address_default[chainId];
|
|
9519
10092
|
const address = addresses.LIQUIDITY_ROUTER;
|
|
9520
|
-
const provider = await getSignerProvider(
|
|
10093
|
+
const provider = await getSignerProvider(chainId);
|
|
9521
10094
|
return getContract(address, LiquidityRouter_default, provider);
|
|
9522
10095
|
};
|
|
9523
|
-
var getPoolManagerContract = async (
|
|
9524
|
-
const addresses = address_default[
|
|
10096
|
+
var getPoolManagerContract = async (chainId, type = 1 /* Signer */) => {
|
|
10097
|
+
const addresses = address_default[chainId];
|
|
9525
10098
|
const address = addresses.POOL_MANAGER;
|
|
9526
|
-
const provider = type === 0 /* JSON */ ? getJSONProvider(
|
|
10099
|
+
const provider = type === 0 /* JSON */ ? getJSONProvider(chainId) : await getSignerProvider(chainId);
|
|
9527
10100
|
return getContract(address, PoolManager_default, provider);
|
|
9528
10101
|
};
|
|
9529
|
-
var getQuotePoolContract = async (
|
|
9530
|
-
const addresses = address_default[
|
|
10102
|
+
var getQuotePoolContract = async (chainId, type = 0 /* JSON */) => {
|
|
10103
|
+
const addresses = address_default[chainId];
|
|
9531
10104
|
const address = addresses.QUOTE_POOL;
|
|
9532
|
-
const provider = type === 0 /* JSON */ ? getJSONProvider(
|
|
10105
|
+
const provider = type === 0 /* JSON */ ? getJSONProvider(chainId) : await getSignerProvider(chainId);
|
|
9533
10106
|
return getContract(address, QuotePool_default, provider);
|
|
9534
10107
|
};
|
|
9535
|
-
var getBasePoolContract = async (
|
|
9536
|
-
const addresses = address_default[
|
|
10108
|
+
var getBasePoolContract = async (chainId, type = 0 /* JSON */) => {
|
|
10109
|
+
const addresses = address_default[chainId];
|
|
9537
10110
|
const address = addresses.BASE_POOL;
|
|
9538
|
-
const provider = type === 0 /* JSON */ ? getJSONProvider(
|
|
10111
|
+
const provider = type === 0 /* JSON */ ? getJSONProvider(chainId) : await getSignerProvider(chainId);
|
|
9539
10112
|
return getContract(address, BasePool_default, provider);
|
|
9540
10113
|
};
|
|
9541
|
-
var getBrokerSingerContract = async (
|
|
9542
|
-
const addresses = address_default[
|
|
10114
|
+
var getBrokerSingerContract = async (chainId) => {
|
|
10115
|
+
const addresses = address_default[chainId];
|
|
9543
10116
|
const address = addresses.BROKER;
|
|
9544
|
-
const provider = await getSignerProvider(
|
|
10117
|
+
const provider = await getSignerProvider(chainId);
|
|
9545
10118
|
return getContract(address, Broker_default, provider);
|
|
9546
10119
|
};
|
|
9547
|
-
var getPythContract = async (
|
|
9548
|
-
const addresses = address_default[
|
|
10120
|
+
var getPythContract = async (chainId, type = 0 /* JSON */) => {
|
|
10121
|
+
const addresses = address_default[chainId];
|
|
9549
10122
|
const address = addresses.PYTH;
|
|
9550
|
-
const provider = type === 0 /* JSON */ ? getJSONProvider(
|
|
10123
|
+
const provider = type === 0 /* JSON */ ? getJSONProvider(chainId) : await getSignerProvider(chainId);
|
|
9551
10124
|
return getContract(address, IPyth_default, provider);
|
|
9552
10125
|
};
|
|
9553
|
-
var getPoolTokenContract = async (
|
|
10126
|
+
var getPoolTokenContract = async (chainId, lpTokenAddress, type = 0 /* JSON */) => {
|
|
9554
10127
|
const address = lpTokenAddress;
|
|
9555
|
-
const provider = type === 0 /* JSON */ ? getJSONProvider(
|
|
10128
|
+
const provider = type === 0 /* JSON */ ? getJSONProvider(chainId) : await getSignerProvider(chainId);
|
|
9556
10129
|
return getContract(address, PoolToken_default, provider);
|
|
9557
10130
|
};
|
|
9558
|
-
var getMarketManageContract = async (
|
|
9559
|
-
const addresses = address_default[
|
|
10131
|
+
var getMarketManageContract = async (chainId, type = 0 /* JSON */) => {
|
|
10132
|
+
const addresses = address_default[chainId];
|
|
9560
10133
|
const address = addresses.MARKET_MANAGER;
|
|
9561
|
-
const provider = type === 0 /* JSON */ ? getJSONProvider(
|
|
10134
|
+
const provider = type === 0 /* JSON */ ? getJSONProvider(chainId) : await getSignerProvider(chainId);
|
|
9562
10135
|
return getContract(address, MarketManager_default, provider);
|
|
9563
10136
|
};
|
|
9564
|
-
var getDataProviderContract = async (
|
|
9565
|
-
const addresses = address_default[
|
|
10137
|
+
var getDataProviderContract = async (chainId, type = 0 /* JSON */) => {
|
|
10138
|
+
const addresses = address_default[chainId];
|
|
9566
10139
|
const address = addresses.DATA_PROVIDER;
|
|
9567
|
-
const provider = type === 0 /* JSON */ ? getJSONProvider(
|
|
10140
|
+
const provider = type === 0 /* JSON */ ? getJSONProvider(chainId) : await getSignerProvider(chainId);
|
|
9568
10141
|
return getContract(address, DataProvider_default, provider);
|
|
9569
10142
|
};
|
|
9570
10143
|
|
|
@@ -9803,11 +10376,11 @@ async function getErrorTextFormError(error) {
|
|
|
9803
10376
|
}
|
|
9804
10377
|
|
|
9805
10378
|
// src/common/balanceOf.ts
|
|
9806
|
-
var
|
|
9807
|
-
var getBalanceOf = async (
|
|
10379
|
+
var import_ethers3 = require("ethers");
|
|
10380
|
+
var getBalanceOf = async (chainId, account, tokenAddress) => {
|
|
9808
10381
|
try {
|
|
9809
|
-
const provider = getJSONProvider(
|
|
9810
|
-
const contractInterface = new
|
|
10382
|
+
const provider = getJSONProvider(chainId);
|
|
10383
|
+
const contractInterface = new import_ethers3.ethers.Interface(IERC20Metadata_default);
|
|
9811
10384
|
const data = contractInterface.encodeFunctionData("balanceOf", [account]);
|
|
9812
10385
|
const callData = {
|
|
9813
10386
|
to: tokenAddress,
|
|
@@ -9823,14 +10396,14 @@ var getBalanceOf = async (chainId2, account, tokenAddress) => {
|
|
|
9823
10396
|
};
|
|
9824
10397
|
|
|
9825
10398
|
// src/common/checkParams.ts
|
|
9826
|
-
var
|
|
10399
|
+
var import_ethers5 = require("ethers");
|
|
9827
10400
|
|
|
9828
10401
|
// src/common/allowance.ts
|
|
9829
|
-
var
|
|
9830
|
-
var getAllowanceApproved = async (
|
|
10402
|
+
var import_ethers4 = require("ethers");
|
|
10403
|
+
var getAllowanceApproved = async (chainId, account, tokenAddress, approveAddress, approveAmount) => {
|
|
9831
10404
|
try {
|
|
9832
|
-
const provider = getJSONProvider(
|
|
9833
|
-
const contractInterface = new
|
|
10405
|
+
const provider = getJSONProvider(chainId);
|
|
10406
|
+
const contractInterface = new import_ethers4.ethers.Interface(IERC20Metadata_default);
|
|
9834
10407
|
const data = contractInterface.encodeFunctionData("allowance", [account, approveAddress]);
|
|
9835
10408
|
const callData = {
|
|
9836
10409
|
to: tokenAddress,
|
|
@@ -9840,498 +10413,109 @@ var getAllowanceApproved = async (chainId2, account, tokenAddress, approveAddres
|
|
|
9840
10413
|
const allowance = BigInt(result);
|
|
9841
10414
|
if (allowance >= approveAmount) {
|
|
9842
10415
|
return true;
|
|
9843
|
-
}
|
|
9844
|
-
return false;
|
|
9845
|
-
} catch (e) {
|
|
9846
|
-
throw e;
|
|
9847
|
-
}
|
|
9848
|
-
};
|
|
9849
|
-
|
|
9850
|
-
// src/common/approve.ts
|
|
9851
|
-
var approve = async (chainId2, account, tokenAddress, approveAddress, amount) => {
|
|
9852
|
-
try {
|
|
9853
|
-
const TokenContract = await getERC20Contract(chainId2, tokenAddress);
|
|
9854
|
-
const response = await TokenContract.approve(approveAddress, amount);
|
|
9855
|
-
const receipt = await response?.wait();
|
|
9856
|
-
const isApproved = await getAllowanceApproved(chainId2, account, tokenAddress, approveAddress, amount);
|
|
9857
|
-
if (!isApproved) {
|
|
9858
|
-
throw new Error(Errors[4 /* Insufficient_Amount_Of_Approved */]);
|
|
9859
|
-
}
|
|
9860
|
-
} catch (e) {
|
|
9861
|
-
throw e;
|
|
9862
|
-
}
|
|
9863
|
-
};
|
|
9864
|
-
|
|
9865
|
-
// src/common/checkParams.ts
|
|
9866
|
-
var checkParams = async (params) => {
|
|
9867
|
-
if ("chainId" in params) {
|
|
9868
|
-
const valid = isSupportedChainFn(params.chainId);
|
|
9869
|
-
if (!valid) {
|
|
9870
|
-
throw new Error(Errors[1 /* Invalid_Chain_ID */]);
|
|
9871
|
-
}
|
|
9872
|
-
}
|
|
9873
|
-
if ("slippage" in params) {
|
|
9874
|
-
if (!(Number(params?.slippage) <= 1 && Number(params?.slippage) > 0)) {
|
|
9875
|
-
throw new Error(Errors[4003 /* Invalid_slippage */]);
|
|
9876
|
-
}
|
|
9877
|
-
}
|
|
9878
|
-
if ("amount" in params) {
|
|
9879
|
-
if (Number(params.amount) === Number.NaN || Number(params.amount) < 0) {
|
|
9880
|
-
throw new Error(Errors[4004 /* Invalid_Amount */]);
|
|
9881
|
-
}
|
|
9882
|
-
}
|
|
9883
|
-
const { tokenAddress, contractAddress, chainId: chainId2, amount, decimals, account } = params;
|
|
9884
|
-
if (amount && chainId2 && decimals && account) {
|
|
9885
|
-
const amountIn = (0, import_ethers6.parseUnits)(amount.toString(), decimals);
|
|
9886
|
-
if (tokenAddress) {
|
|
9887
|
-
const balance = await getBalanceOf(chainId2, account, tokenAddress);
|
|
9888
|
-
if (!balance || balance < amountIn) {
|
|
9889
|
-
throw new Error(Errors[3 /* Insufficient_Balance */]);
|
|
9890
|
-
}
|
|
9891
|
-
}
|
|
9892
|
-
if (contractAddress && tokenAddress) {
|
|
9893
|
-
const isApproved = await getAllowanceApproved(chainId2, account, tokenAddress, contractAddress, amountIn);
|
|
9894
|
-
if (!isApproved) {
|
|
9895
|
-
await approve(chainId2, account, tokenAddress, contractAddress, import_ethers6.MaxUint256);
|
|
9896
|
-
}
|
|
9897
|
-
}
|
|
9898
|
-
}
|
|
9899
|
-
};
|
|
9900
|
-
|
|
9901
|
-
// src/common/tradingGas.ts
|
|
9902
|
-
var import_ethers7 = require("ethers");
|
|
9903
|
-
|
|
9904
|
-
// src/config/decimals.ts
|
|
9905
|
-
var COMMON_CONFIG_DECIMALS = 8;
|
|
9906
|
-
var COMMON_PRICE_DECIMALS = 30;
|
|
9907
|
-
var COMMON_LP_AMOUNT_DECIMALS = 18;
|
|
9908
|
-
|
|
9909
|
-
// src/common/tradingGas.ts
|
|
9910
|
-
var bigintTradingGasToRatioCalculator = (gas, ratio) => {
|
|
9911
|
-
return gas * (0, import_ethers7.parseUnits)(ratio.toString(), COMMON_CONFIG_DECIMALS) / BigInt(10 ** COMMON_CONFIG_DECIMALS);
|
|
9912
|
-
};
|
|
9913
|
-
var bigintTradingGasPriceWithRatio = async (chainId2) => {
|
|
9914
|
-
try {
|
|
9915
|
-
const chainInfo = CHAIN_INFO[chainId2];
|
|
9916
|
-
const provider = getJSONProvider(chainId2);
|
|
9917
|
-
const { gasPrice } = await provider.getFeeData();
|
|
9918
|
-
if (!gasPrice) {
|
|
9919
|
-
throw new Error("Network Error");
|
|
9920
|
-
}
|
|
9921
|
-
const gasPriceWithRatio = bigintTradingGasToRatioCalculator(gasPrice, chainInfo.gasPriceRatio);
|
|
9922
|
-
return {
|
|
9923
|
-
gasPrice: gasPriceWithRatio
|
|
9924
|
-
};
|
|
9925
|
-
} catch (e) {
|
|
9926
|
-
throw e;
|
|
9927
|
-
}
|
|
9928
|
-
};
|
|
9929
|
-
var bigintAmountSlipperCalculator = (amount, slipper = 0.01) => {
|
|
9930
|
-
const radio = (0, import_ethers7.parseUnits)("1", COMMON_CONFIG_DECIMALS) - (0, import_ethers7.parseUnits)(slipper.toString(), COMMON_CONFIG_DECIMALS);
|
|
9931
|
-
return amount * radio / BigInt(10 ** COMMON_CONFIG_DECIMALS);
|
|
9932
|
-
};
|
|
9933
|
-
|
|
9934
|
-
// src/lp/base/claim.ts
|
|
9935
|
-
var import_ethers8 = require("ethers");
|
|
9936
|
-
|
|
9937
|
-
// src/api/request.ts
|
|
9938
|
-
var import_wretch = __toESM(require("wretch"));
|
|
9939
|
-
var client = (0, import_wretch.default)();
|
|
9940
|
-
var buildQueryOptions = (url, params) => {
|
|
9941
|
-
if (params) {
|
|
9942
|
-
params = JSON.parse(JSON.stringify(params));
|
|
9943
|
-
if (url.includes("?")) {
|
|
9944
|
-
return url + "&" + new URLSearchParams(params).toString();
|
|
9945
|
-
}
|
|
9946
|
-
return url + "?" + new URLSearchParams(params).toString();
|
|
9947
|
-
}
|
|
9948
|
-
return url;
|
|
9949
|
-
};
|
|
9950
|
-
var http = {
|
|
9951
|
-
/**
|
|
9952
|
-
* Get request
|
|
9953
|
-
*/
|
|
9954
|
-
get: (url, params, options = {}) => {
|
|
9955
|
-
const requestUrl = buildQueryOptions(url, params);
|
|
9956
|
-
return client.url(requestUrl).options(options).get().json();
|
|
9957
|
-
},
|
|
9958
|
-
/**
|
|
9959
|
-
* Post request
|
|
9960
|
-
*/
|
|
9961
|
-
post: (url, data, options = {}) => {
|
|
9962
|
-
return client.url(url).options(options).post(data).json();
|
|
9963
|
-
},
|
|
9964
|
-
/**
|
|
9965
|
-
* Put request
|
|
9966
|
-
*/
|
|
9967
|
-
put: (url, data, options = {}) => {
|
|
9968
|
-
return client.url(url).options(options).put(data).json();
|
|
9969
|
-
},
|
|
9970
|
-
/**
|
|
9971
|
-
* Delete request
|
|
9972
|
-
*/
|
|
9973
|
-
delete: (url, options = {}) => {
|
|
9974
|
-
return client.url(url).options(options).delete().json();
|
|
9975
|
-
}
|
|
9976
|
-
};
|
|
9977
|
-
|
|
9978
|
-
// src/api/utils.ts
|
|
9979
|
-
function encodeQueryParam(key, value) {
|
|
9980
|
-
const encodedKey = encodeURIComponent(key);
|
|
9981
|
-
return `${encodedKey}=${encodeURIComponent(typeof value === "number" ? value : `${value}`)}`;
|
|
9982
|
-
}
|
|
9983
|
-
function addQueryParam(query, key) {
|
|
9984
|
-
return encodeQueryParam(key, query[key]);
|
|
9985
|
-
}
|
|
9986
|
-
function addArrayQueryParam(query, key) {
|
|
9987
|
-
const value = query[key];
|
|
9988
|
-
return value.map((v) => encodeQueryParam(key, v)).join("&");
|
|
9989
|
-
}
|
|
9990
|
-
function toQueryString(rawQuery) {
|
|
9991
|
-
const query = rawQuery || {};
|
|
9992
|
-
const keys = Object.keys(query).filter((key) => "undefined" !== typeof query[key]);
|
|
9993
|
-
return keys.map((key) => Array.isArray(query[key]) ? addArrayQueryParam(query, key) : addQueryParam(query, key)).join("&");
|
|
9994
|
-
}
|
|
9995
|
-
function addQueryParams(rawQuery) {
|
|
9996
|
-
const queryString = toQueryString(rawQuery);
|
|
9997
|
-
return queryString ? `?${queryString}` : "";
|
|
9998
|
-
}
|
|
9999
|
-
|
|
10000
|
-
// src/api/type.ts
|
|
10001
|
-
var ErrorCode2 = /* @__PURE__ */ ((ErrorCode3) => {
|
|
10002
|
-
ErrorCode3[ErrorCode3["SUCCESS"] = 9200] = "SUCCESS";
|
|
10003
|
-
ErrorCode3[ErrorCode3["SUCCESS_ORIGIN"] = 0] = "SUCCESS_ORIGIN";
|
|
10004
|
-
ErrorCode3[ErrorCode3["IDENTITY_VERIFICATION_FAILED"] = 9401] = "IDENTITY_VERIFICATION_FAILED";
|
|
10005
|
-
ErrorCode3[ErrorCode3["PERMISSION_DENIED"] = 9403] = "PERMISSION_DENIED";
|
|
10006
|
-
ErrorCode3[ErrorCode3["NOT_EXIST"] = 9404] = "NOT_EXIST";
|
|
10007
|
-
ErrorCode3[ErrorCode3["REQUEST_LIMIT"] = 9429] = "REQUEST_LIMIT";
|
|
10008
|
-
ErrorCode3[ErrorCode3["SERVICE_ERROR"] = 9500] = "SERVICE_ERROR";
|
|
10009
|
-
ErrorCode3[ErrorCode3["MISS_REQUESTED_PARAMETER"] = 9900] = "MISS_REQUESTED_PARAMETER";
|
|
10010
|
-
ErrorCode3[ErrorCode3["INVALID_PARAMETER"] = 9901] = "INVALID_PARAMETER";
|
|
10011
|
-
ErrorCode3["NETWORK_ERROR"] = "ERR_NETWORK";
|
|
10012
|
-
return ErrorCode3;
|
|
10013
|
-
})(ErrorCode2 || {});
|
|
10014
|
-
var MarketPoolState = /* @__PURE__ */ ((MarketPoolState3) => {
|
|
10015
|
-
MarketPoolState3[MarketPoolState3["Cook"] = 0] = "Cook";
|
|
10016
|
-
MarketPoolState3[MarketPoolState3["Primed"] = 1] = "Primed";
|
|
10017
|
-
MarketPoolState3[MarketPoolState3["Trench"] = 2] = "Trench";
|
|
10018
|
-
MarketPoolState3[MarketPoolState3["PreBench"] = 3] = "PreBench";
|
|
10019
|
-
MarketPoolState3[MarketPoolState3["Bench"] = 4] = "Bench";
|
|
10020
|
-
return MarketPoolState3;
|
|
10021
|
-
})(MarketPoolState || {});
|
|
10022
|
-
var OracleType = /* @__PURE__ */ ((OracleType7) => {
|
|
10023
|
-
OracleType7[OracleType7["Chainlink"] = 1] = "Chainlink";
|
|
10024
|
-
OracleType7[OracleType7["Pyth"] = 2] = "Pyth";
|
|
10025
|
-
return OracleType7;
|
|
10026
|
-
})(OracleType || {});
|
|
10027
|
-
var HttpKlineIntervalEnum = /* @__PURE__ */ ((HttpKlineIntervalEnum2) => {
|
|
10028
|
-
HttpKlineIntervalEnum2[HttpKlineIntervalEnum2["Minute1"] = 1] = "Minute1";
|
|
10029
|
-
HttpKlineIntervalEnum2[HttpKlineIntervalEnum2["Minute5"] = 5] = "Minute5";
|
|
10030
|
-
HttpKlineIntervalEnum2[HttpKlineIntervalEnum2["Minute15"] = 15] = "Minute15";
|
|
10031
|
-
HttpKlineIntervalEnum2[HttpKlineIntervalEnum2["Minute30"] = 30] = "Minute30";
|
|
10032
|
-
HttpKlineIntervalEnum2[HttpKlineIntervalEnum2["Hour1"] = 60] = "Hour1";
|
|
10033
|
-
HttpKlineIntervalEnum2[HttpKlineIntervalEnum2["Hour4"] = 240] = "Hour4";
|
|
10034
|
-
HttpKlineIntervalEnum2[HttpKlineIntervalEnum2["Day1"] = 1440] = "Day1";
|
|
10035
|
-
HttpKlineIntervalEnum2[HttpKlineIntervalEnum2["Week1"] = 10080] = "Week1";
|
|
10036
|
-
HttpKlineIntervalEnum2[HttpKlineIntervalEnum2["Month1"] = 40320] = "Month1";
|
|
10037
|
-
return HttpKlineIntervalEnum2;
|
|
10038
|
-
})(HttpKlineIntervalEnum || {});
|
|
10039
|
-
var MarketType = /* @__PURE__ */ ((MarketType2) => {
|
|
10040
|
-
MarketType2[MarketType2["Contract"] = 1] = "Contract";
|
|
10041
|
-
MarketType2[MarketType2["Cook"] = 2] = "Cook";
|
|
10042
|
-
MarketType2[MarketType2["Earn"] = 3] = "Earn";
|
|
10043
|
-
return MarketType2;
|
|
10044
|
-
})(MarketType || {});
|
|
10045
|
-
var SearchTypeEnum = /* @__PURE__ */ ((SearchTypeEnum2) => {
|
|
10046
|
-
SearchTypeEnum2[SearchTypeEnum2["All"] = 0] = "All";
|
|
10047
|
-
SearchTypeEnum2[SearchTypeEnum2["Contract"] = 1 /* Contract */] = "Contract";
|
|
10048
|
-
SearchTypeEnum2[SearchTypeEnum2["Cook"] = 2 /* Cook */] = "Cook";
|
|
10049
|
-
SearchTypeEnum2[SearchTypeEnum2["Earn"] = 3 /* Earn */] = "Earn";
|
|
10050
|
-
return SearchTypeEnum2;
|
|
10051
|
-
})(SearchTypeEnum || {});
|
|
10052
|
-
var MarketCapType = /* @__PURE__ */ ((MarketCapType2) => {
|
|
10053
|
-
MarketCapType2[MarketCapType2["BlueChips"] = 1] = "BlueChips";
|
|
10054
|
-
MarketCapType2[MarketCapType2["Alpha"] = 2] = "Alpha";
|
|
10055
|
-
return MarketCapType2;
|
|
10056
|
-
})(MarketCapType || {});
|
|
10057
|
-
var SearchSecondTypeEnum = /* @__PURE__ */ ((SearchSecondTypeEnum2) => {
|
|
10058
|
-
SearchSecondTypeEnum2[SearchSecondTypeEnum2["BlueChips"] = 1 /* BlueChips */] = "BlueChips";
|
|
10059
|
-
SearchSecondTypeEnum2[SearchSecondTypeEnum2["Alpha"] = 2 /* Alpha */] = "Alpha";
|
|
10060
|
-
SearchSecondTypeEnum2[SearchSecondTypeEnum2["Favorite"] = 3] = "Favorite";
|
|
10061
|
-
return SearchSecondTypeEnum2;
|
|
10062
|
-
})(SearchSecondTypeEnum || {});
|
|
10063
|
-
|
|
10064
|
-
// src/api/account/index.ts
|
|
10065
|
-
var OrderTypeEnum = /* @__PURE__ */ ((OrderTypeEnum2) => {
|
|
10066
|
-
OrderTypeEnum2[OrderTypeEnum2["Market"] = 0] = "Market";
|
|
10067
|
-
OrderTypeEnum2[OrderTypeEnum2["Limit"] = 1] = "Limit";
|
|
10068
|
-
OrderTypeEnum2[OrderTypeEnum2["Stop"] = 2] = "Stop";
|
|
10069
|
-
OrderTypeEnum2[OrderTypeEnum2["Conditional"] = 3] = "Conditional";
|
|
10070
|
-
return OrderTypeEnum2;
|
|
10071
|
-
})(OrderTypeEnum || {});
|
|
10072
|
-
var OperationEnum = /* @__PURE__ */ ((OperationEnum2) => {
|
|
10073
|
-
OperationEnum2[OperationEnum2["Increase"] = 0] = "Increase";
|
|
10074
|
-
OperationEnum2[OperationEnum2["Decrease"] = 1] = "Decrease";
|
|
10075
|
-
return OperationEnum2;
|
|
10076
|
-
})(OperationEnum || {});
|
|
10077
|
-
var TriggerTypeEnum = /* @__PURE__ */ ((TriggerTypeEnum2) => {
|
|
10078
|
-
TriggerTypeEnum2[TriggerTypeEnum2["Unknown"] = 0] = "Unknown";
|
|
10079
|
-
TriggerTypeEnum2[TriggerTypeEnum2["GTE"] = 1] = "GTE";
|
|
10080
|
-
TriggerTypeEnum2[TriggerTypeEnum2["LTE"] = 2] = "LTE";
|
|
10081
|
-
return TriggerTypeEnum2;
|
|
10082
|
-
})(TriggerTypeEnum || {});
|
|
10083
|
-
var DirectionEnum = /* @__PURE__ */ ((DirectionEnum2) => {
|
|
10084
|
-
DirectionEnum2[DirectionEnum2["Long"] = 0] = "Long";
|
|
10085
|
-
DirectionEnum2[DirectionEnum2["Short"] = 1] = "Short";
|
|
10086
|
-
return DirectionEnum2;
|
|
10087
|
-
})(DirectionEnum || {});
|
|
10088
|
-
var OrderStatusEnum = /* @__PURE__ */ ((OrderStatusEnum2) => {
|
|
10089
|
-
OrderStatusEnum2[OrderStatusEnum2["Cancelled"] = 1] = "Cancelled";
|
|
10090
|
-
OrderStatusEnum2[OrderStatusEnum2["Expired"] = 2] = "Expired";
|
|
10091
|
-
OrderStatusEnum2[OrderStatusEnum2["Successful"] = 9] = "Successful";
|
|
10092
|
-
return OrderStatusEnum2;
|
|
10093
|
-
})(OrderStatusEnum || {});
|
|
10094
|
-
var ExecTypeEnum = /* @__PURE__ */ ((ExecTypeEnum2) => {
|
|
10095
|
-
ExecTypeEnum2[ExecTypeEnum2["UserEntrust"] = 0] = "UserEntrust";
|
|
10096
|
-
ExecTypeEnum2[ExecTypeEnum2["Liquidation"] = 1] = "Liquidation";
|
|
10097
|
-
ExecTypeEnum2[ExecTypeEnum2["Adl"] = 2] = "Adl";
|
|
10098
|
-
ExecTypeEnum2[ExecTypeEnum2["AdlTrigger"] = 3] = "AdlTrigger";
|
|
10099
|
-
return ExecTypeEnum2;
|
|
10100
|
-
})(ExecTypeEnum || {});
|
|
10101
|
-
var getHistoryOrders = async ({
|
|
10102
|
-
accessToken,
|
|
10103
|
-
...params
|
|
10104
|
-
}) => {
|
|
10105
|
-
return http.get(
|
|
10106
|
-
`${baseUrl}/openapi/gateway/scan/order/closed`,
|
|
10107
|
-
params,
|
|
10108
|
-
{
|
|
10109
|
-
headers: {
|
|
10110
|
-
myx_openapi_access_token: accessToken
|
|
10111
|
-
}
|
|
10112
|
-
}
|
|
10113
|
-
);
|
|
10114
|
-
};
|
|
10115
|
-
var CloseTypeEnum = /* @__PURE__ */ ((CloseTypeEnum2) => {
|
|
10116
|
-
CloseTypeEnum2[CloseTypeEnum2["Open"] = 0] = "Open";
|
|
10117
|
-
CloseTypeEnum2[CloseTypeEnum2["PartialClose"] = 1] = "PartialClose";
|
|
10118
|
-
CloseTypeEnum2[CloseTypeEnum2["FullClose"] = 2] = "FullClose";
|
|
10119
|
-
CloseTypeEnum2[CloseTypeEnum2["Liquidation"] = 3] = "Liquidation";
|
|
10120
|
-
CloseTypeEnum2[CloseTypeEnum2["EarlyClose"] = 4] = "EarlyClose";
|
|
10121
|
-
CloseTypeEnum2[CloseTypeEnum2["MarketClose"] = 5] = "MarketClose";
|
|
10122
|
-
CloseTypeEnum2[CloseTypeEnum2["ADL"] = 6] = "ADL";
|
|
10123
|
-
CloseTypeEnum2[CloseTypeEnum2["TP"] = 7] = "TP";
|
|
10124
|
-
CloseTypeEnum2[CloseTypeEnum2["SL"] = 8] = "SL";
|
|
10125
|
-
CloseTypeEnum2[CloseTypeEnum2["Increase"] = 9] = "Increase";
|
|
10126
|
-
return CloseTypeEnum2;
|
|
10127
|
-
})(CloseTypeEnum || {});
|
|
10128
|
-
var getPositionHistory = async ({
|
|
10129
|
-
accessToken,
|
|
10130
|
-
...params
|
|
10131
|
-
}) => {
|
|
10132
|
-
return http.get(
|
|
10133
|
-
`${baseUrl}/openapi/gateway/scan/position/closed`,
|
|
10134
|
-
params,
|
|
10135
|
-
{
|
|
10136
|
-
headers: {
|
|
10137
|
-
myx_openapi_access_token: accessToken
|
|
10138
|
-
}
|
|
10139
|
-
}
|
|
10140
|
-
);
|
|
10141
|
-
};
|
|
10142
|
-
var getTradeFlow = async ({
|
|
10143
|
-
accessToken,
|
|
10144
|
-
...params
|
|
10145
|
-
}) => {
|
|
10146
|
-
return http.get(
|
|
10147
|
-
`${baseUrl}/openapi/gateway/scan/trade/flow`,
|
|
10148
|
-
params,
|
|
10149
|
-
{
|
|
10150
|
-
headers: {
|
|
10151
|
-
myx_openapi_access_token: accessToken
|
|
10152
|
-
}
|
|
10153
|
-
}
|
|
10154
|
-
);
|
|
10155
|
-
};
|
|
10156
|
-
|
|
10157
|
-
// src/api/index.ts
|
|
10158
|
-
var baseUrl = "https://api-test.myx.cash";
|
|
10159
|
-
var getOraclePrice = async (chainId2, poolIds = []) => {
|
|
10160
|
-
if (!!poolIds.length) {
|
|
10161
|
-
return http.get(`${baseUrl}/openapi/gateway/quote/price/oracles`, {
|
|
10162
|
-
chainId: chainId2,
|
|
10163
|
-
poolIds: poolIds.join(",")
|
|
10164
|
-
});
|
|
10416
|
+
}
|
|
10417
|
+
return false;
|
|
10418
|
+
} catch (e) {
|
|
10419
|
+
throw e;
|
|
10165
10420
|
}
|
|
10166
|
-
return Promise.reject(new Error("Invalid pool id"));
|
|
10167
|
-
};
|
|
10168
|
-
var getPoolLevelConfig = async ({
|
|
10169
|
-
poolId,
|
|
10170
|
-
chainId: chainId2
|
|
10171
|
-
}) => {
|
|
10172
|
-
return http.get(
|
|
10173
|
-
`${baseUrl}/openapi/gateway/risk/market_pool/level_config${addQueryParams({
|
|
10174
|
-
poolId,
|
|
10175
|
-
chainId: chainId2
|
|
10176
|
-
})}`
|
|
10177
|
-
);
|
|
10178
|
-
};
|
|
10179
|
-
var getPoolDetail = async (chainId2, poolId) => {
|
|
10180
|
-
return await http.get(
|
|
10181
|
-
`${baseUrl}/openapi/gateway/scan/market/detail?chainId=${chainId2}&poolId=${poolId}`
|
|
10182
|
-
);
|
|
10183
10421
|
};
|
|
10184
|
-
|
|
10185
|
-
|
|
10186
|
-
|
|
10187
|
-
|
|
10188
|
-
|
|
10189
|
-
|
|
10190
|
-
|
|
10191
|
-
|
|
10192
|
-
|
|
10422
|
+
|
|
10423
|
+
// src/common/approve.ts
|
|
10424
|
+
var approve = async (chainId, account, tokenAddress, approveAddress, amount) => {
|
|
10425
|
+
try {
|
|
10426
|
+
const TokenContract = await getERC20Contract(chainId, tokenAddress);
|
|
10427
|
+
const response = await TokenContract.approve(approveAddress, amount);
|
|
10428
|
+
const receipt = await response?.wait();
|
|
10429
|
+
const isApproved = await getAllowanceApproved(chainId, account, tokenAddress, approveAddress, amount);
|
|
10430
|
+
if (!isApproved) {
|
|
10431
|
+
throw new Error(Errors[4 /* Insufficient_Amount_Of_Approved */]);
|
|
10193
10432
|
}
|
|
10194
|
-
)
|
|
10195
|
-
|
|
10196
|
-
|
|
10197
|
-
return await http.get(
|
|
10198
|
-
`${baseUrl}/openapi/gateway/scan/order/open?chainId=${chainId2}`,
|
|
10199
|
-
void 0,
|
|
10200
|
-
{ headers: { myx_openapi_access_token: accessToken } }
|
|
10201
|
-
);
|
|
10202
|
-
};
|
|
10203
|
-
var getPoolOpenOrders = async (accessToken, chainId2) => {
|
|
10204
|
-
return await http.get(
|
|
10205
|
-
`${baseUrl}/openapi/gateway/scan/market/pool-order/open?chainId=${chainId2}`,
|
|
10206
|
-
void 0,
|
|
10207
|
-
{ headers: { myx_openapi_access_token: accessToken } }
|
|
10208
|
-
);
|
|
10433
|
+
} catch (e) {
|
|
10434
|
+
throw e;
|
|
10435
|
+
}
|
|
10209
10436
|
};
|
|
10210
|
-
|
|
10211
|
-
|
|
10212
|
-
|
|
10213
|
-
|
|
10214
|
-
|
|
10215
|
-
|
|
10216
|
-
|
|
10217
|
-
return http.get(
|
|
10218
|
-
`${baseUrl}/openapi/gateway/quote/candles`,
|
|
10219
|
-
{
|
|
10220
|
-
chainId: chainId2,
|
|
10221
|
-
poolId,
|
|
10222
|
-
endTime,
|
|
10223
|
-
limit,
|
|
10224
|
-
interval
|
|
10437
|
+
|
|
10438
|
+
// src/common/checkParams.ts
|
|
10439
|
+
var checkParams = async (params) => {
|
|
10440
|
+
if ("chainId" in params) {
|
|
10441
|
+
const valid = isSupportedChainFn(params.chainId);
|
|
10442
|
+
if (!valid) {
|
|
10443
|
+
throw new Error(Errors[1 /* Invalid_Chain_ID */]);
|
|
10225
10444
|
}
|
|
10226
|
-
|
|
10227
|
-
|
|
10228
|
-
|
|
10229
|
-
|
|
10230
|
-
`${baseUrl}/openapi/gateway/quote/candle/latest`,
|
|
10231
|
-
params
|
|
10232
|
-
);
|
|
10233
|
-
};
|
|
10234
|
-
var getTickerData = async ({
|
|
10235
|
-
chainId: chainId2,
|
|
10236
|
-
poolIds
|
|
10237
|
-
}) => {
|
|
10238
|
-
return http.get(
|
|
10239
|
-
`${baseUrl}/openapi/gateway/quote/candle/tickers`,
|
|
10240
|
-
{
|
|
10241
|
-
chainId: chainId2,
|
|
10242
|
-
poolIds: poolIds.join(",")
|
|
10445
|
+
}
|
|
10446
|
+
if ("slippage" in params) {
|
|
10447
|
+
if (!(Number(params?.slippage) <= 1 && Number(params?.slippage) > 0)) {
|
|
10448
|
+
throw new Error(Errors[4003 /* Invalid_slippage */]);
|
|
10243
10449
|
}
|
|
10244
|
-
|
|
10245
|
-
|
|
10246
|
-
|
|
10247
|
-
|
|
10248
|
-
`${baseUrl}/v2/mx-gateway/quote/candle/all_tickers`
|
|
10249
|
-
);
|
|
10250
|
-
};
|
|
10251
|
-
var searchMarketAuth = async ({
|
|
10252
|
-
accessToken,
|
|
10253
|
-
...params
|
|
10254
|
-
}) => {
|
|
10255
|
-
return http.get(
|
|
10256
|
-
`${baseUrl}/openapi/gateway/scan/market/ac-search`,
|
|
10257
|
-
params,
|
|
10258
|
-
{
|
|
10259
|
-
headers: {
|
|
10260
|
-
myx_openapi_access_token: accessToken
|
|
10261
|
-
}
|
|
10450
|
+
}
|
|
10451
|
+
if ("amount" in params) {
|
|
10452
|
+
if (Number(params.amount) === Number.NaN || Number(params.amount) < 0) {
|
|
10453
|
+
throw new Error(Errors[4004 /* Invalid_Amount */]);
|
|
10262
10454
|
}
|
|
10263
|
-
|
|
10264
|
-
};
|
|
10265
|
-
|
|
10266
|
-
|
|
10267
|
-
|
|
10268
|
-
|
|
10269
|
-
|
|
10270
|
-
|
|
10271
|
-
var addFavorite = async ({
|
|
10272
|
-
accessToken,
|
|
10273
|
-
...params
|
|
10274
|
-
}) => {
|
|
10275
|
-
return http.get(
|
|
10276
|
-
`${baseUrl}/openapi/gateway/scan/market/add-favorites`,
|
|
10277
|
-
params,
|
|
10278
|
-
{
|
|
10279
|
-
headers: {
|
|
10280
|
-
myx_openapi_access_token: accessToken
|
|
10455
|
+
}
|
|
10456
|
+
const { tokenAddress, contractAddress, chainId, amount, decimals, account } = params;
|
|
10457
|
+
if (amount && chainId && decimals && account) {
|
|
10458
|
+
const amountIn = (0, import_ethers5.parseUnits)(amount.toString(), decimals);
|
|
10459
|
+
if (tokenAddress) {
|
|
10460
|
+
const balance = await getBalanceOf(chainId, account, tokenAddress);
|
|
10461
|
+
if (!balance || balance < amountIn) {
|
|
10462
|
+
throw new Error(Errors[3 /* Insufficient_Balance */]);
|
|
10281
10463
|
}
|
|
10282
10464
|
}
|
|
10283
|
-
|
|
10284
|
-
|
|
10285
|
-
|
|
10286
|
-
|
|
10287
|
-
...params
|
|
10288
|
-
}) => {
|
|
10289
|
-
return http.get(
|
|
10290
|
-
`${baseUrl}/openapi/gateway/scan/market/cancel-favorites`,
|
|
10291
|
-
params,
|
|
10292
|
-
{
|
|
10293
|
-
headers: {
|
|
10294
|
-
myx_openapi_access_token: accessToken
|
|
10465
|
+
if (contractAddress && tokenAddress) {
|
|
10466
|
+
const isApproved = await getAllowanceApproved(chainId, account, tokenAddress, contractAddress, amountIn);
|
|
10467
|
+
if (!isApproved) {
|
|
10468
|
+
await approve(chainId, account, tokenAddress, contractAddress, import_ethers5.MaxUint256);
|
|
10295
10469
|
}
|
|
10296
10470
|
}
|
|
10297
|
-
|
|
10471
|
+
}
|
|
10298
10472
|
};
|
|
10299
|
-
|
|
10300
|
-
|
|
10301
|
-
|
|
10302
|
-
|
|
10303
|
-
|
|
10304
|
-
|
|
10305
|
-
|
|
10306
|
-
|
|
10307
|
-
|
|
10308
|
-
|
|
10309
|
-
|
|
10310
|
-
|
|
10311
|
-
);
|
|
10473
|
+
|
|
10474
|
+
// src/common/tradingGas.ts
|
|
10475
|
+
var import_ethers6 = require("ethers");
|
|
10476
|
+
|
|
10477
|
+
// src/config/decimals.ts
|
|
10478
|
+
var COMMON_CONFIG_DECIMALS = 8;
|
|
10479
|
+
var COMMON_PRICE_DECIMALS = 30;
|
|
10480
|
+
var COMMON_LP_AMOUNT_DECIMALS = 18;
|
|
10481
|
+
|
|
10482
|
+
// src/common/tradingGas.ts
|
|
10483
|
+
var bigintTradingGasToRatioCalculator = (gas, ratio) => {
|
|
10484
|
+
return gas * (0, import_ethers6.parseUnits)(ratio.toString(), COMMON_CONFIG_DECIMALS) / BigInt(10 ** COMMON_CONFIG_DECIMALS);
|
|
10312
10485
|
};
|
|
10313
|
-
var
|
|
10314
|
-
|
|
10315
|
-
|
|
10316
|
-
|
|
10317
|
-
|
|
10486
|
+
var bigintTradingGasPriceWithRatio = async (chainId) => {
|
|
10487
|
+
try {
|
|
10488
|
+
const chainInfo = CHAIN_INFO[chainId];
|
|
10489
|
+
const provider = getJSONProvider(chainId);
|
|
10490
|
+
const { gasPrice } = await provider.getFeeData();
|
|
10491
|
+
if (!gasPrice) {
|
|
10492
|
+
throw new Error("Network Error");
|
|
10493
|
+
}
|
|
10494
|
+
const gasPriceWithRatio = bigintTradingGasToRatioCalculator(gasPrice, chainInfo.gasPriceRatio);
|
|
10495
|
+
return {
|
|
10496
|
+
gasPrice: gasPriceWithRatio
|
|
10497
|
+
};
|
|
10498
|
+
} catch (e) {
|
|
10499
|
+
throw e;
|
|
10500
|
+
}
|
|
10318
10501
|
};
|
|
10319
|
-
var
|
|
10320
|
-
|
|
10321
|
-
|
|
10322
|
-
params
|
|
10323
|
-
);
|
|
10502
|
+
var bigintAmountSlipperCalculator = (amount, slipper = 0.01) => {
|
|
10503
|
+
const radio = (0, import_ethers6.parseUnits)("1", COMMON_CONFIG_DECIMALS) - (0, import_ethers6.parseUnits)(slipper.toString(), COMMON_CONFIG_DECIMALS);
|
|
10504
|
+
return amount * radio / BigInt(10 ** COMMON_CONFIG_DECIMALS);
|
|
10324
10505
|
};
|
|
10325
10506
|
|
|
10507
|
+
// src/lp/base/claim.ts
|
|
10508
|
+
var import_ethers7 = require("ethers");
|
|
10509
|
+
|
|
10326
10510
|
// src/common/price.ts
|
|
10327
10511
|
var import_lodash_es2 = require("lodash-es");
|
|
10328
|
-
var parsePriceData = async (
|
|
10512
|
+
var parsePriceData = async (chainId, data) => {
|
|
10329
10513
|
const result = await Promise.all(
|
|
10330
10514
|
data.map(async (item) => {
|
|
10331
10515
|
const { publishTime, vaa, oracleType, nativeFee, price, poolId } = item;
|
|
10332
10516
|
let value = !(0, import_lodash_es2.isNil)(nativeFee) ? BigInt(nativeFee) : 1n;
|
|
10333
10517
|
if (oracleType === 2 /* Pyth */) {
|
|
10334
|
-
const PythContract = await getPythContract(
|
|
10518
|
+
const PythContract = await getPythContract(chainId);
|
|
10335
10519
|
const v = await PythContract.getUpdateFee([vaa]);
|
|
10336
10520
|
value = v;
|
|
10337
10521
|
}
|
|
@@ -10347,34 +10531,34 @@ var parsePriceData = async (chainId2, data) => {
|
|
|
10347
10531
|
);
|
|
10348
10532
|
return result;
|
|
10349
10533
|
};
|
|
10350
|
-
var getPricesData = async (
|
|
10534
|
+
var getPricesData = async (chainId, poolIds) => {
|
|
10351
10535
|
if (!poolIds || !poolIds.length) return;
|
|
10352
|
-
const rs = await getOraclePrice(
|
|
10353
|
-
const result = await parsePriceData(
|
|
10536
|
+
const rs = await getOraclePrice(chainId, poolIds);
|
|
10537
|
+
const result = await parsePriceData(chainId, rs.data);
|
|
10354
10538
|
return result;
|
|
10355
10539
|
};
|
|
10356
|
-
var getPriceData = async (
|
|
10540
|
+
var getPriceData = async (chainId, poolId) => {
|
|
10357
10541
|
if (!poolId) return;
|
|
10358
|
-
const rs = await getOraclePrice(
|
|
10542
|
+
const rs = await getOraclePrice(chainId, [poolId]);
|
|
10359
10543
|
const data = rs?.data?.[0];
|
|
10360
10544
|
if (!data) {
|
|
10361
10545
|
throw new Error(`Unable to get price for ${poolId} in the deposit`);
|
|
10362
10546
|
}
|
|
10363
|
-
const result = await parsePriceData(
|
|
10547
|
+
const result = await parsePriceData(chainId, [data]);
|
|
10364
10548
|
return result?.[0];
|
|
10365
10549
|
};
|
|
10366
10550
|
|
|
10367
10551
|
// src/lp/base/claim.ts
|
|
10368
10552
|
var claimBasePoolRebate = async (params) => {
|
|
10369
10553
|
try {
|
|
10370
|
-
const { chainId
|
|
10371
|
-
const chainInfo = CHAIN_INFO[
|
|
10372
|
-
const account = await getAccount(
|
|
10554
|
+
const { chainId, poolId } = params;
|
|
10555
|
+
const chainInfo = CHAIN_INFO[chainId];
|
|
10556
|
+
const account = await getAccount(chainId);
|
|
10373
10557
|
await checkParams({
|
|
10374
10558
|
account,
|
|
10375
|
-
chainId
|
|
10559
|
+
chainId
|
|
10376
10560
|
});
|
|
10377
|
-
const priceResponse = await getPricesData(
|
|
10561
|
+
const priceResponse = await getPricesData(chainId, [poolId]);
|
|
10378
10562
|
if (!priceResponse) return;
|
|
10379
10563
|
const values = priceResponse.map((item) => {
|
|
10380
10564
|
return item.value;
|
|
@@ -10382,7 +10566,7 @@ var claimBasePoolRebate = async (params) => {
|
|
|
10382
10566
|
const prices = priceResponse.map((item) => {
|
|
10383
10567
|
return {
|
|
10384
10568
|
poolId,
|
|
10385
|
-
referencePrice: (0,
|
|
10569
|
+
referencePrice: (0, import_ethers7.parseUnits)(item?.price ?? "0", COMMON_PRICE_DECIMALS),
|
|
10386
10570
|
oracleUpdateData: item?.vaa ?? "0",
|
|
10387
10571
|
publishTime: item.publishTime,
|
|
10388
10572
|
oracleType: item.oracleType
|
|
@@ -10394,12 +10578,12 @@ var claimBasePoolRebate = async (params) => {
|
|
|
10394
10578
|
poolId,
|
|
10395
10579
|
recipient: account
|
|
10396
10580
|
};
|
|
10397
|
-
const contract = await getLiquidityRouterContract(
|
|
10581
|
+
const contract = await getLiquidityRouterContract(chainId);
|
|
10398
10582
|
const _gasLimit = await contract["claimBasePoolRebate((bytes32,uint8,uint256,bytes,uint64)[],bytes32,address)"].estimateGas(prices, poolId, account, {
|
|
10399
10583
|
value: values[0]
|
|
10400
10584
|
});
|
|
10401
10585
|
const gasLimit = bigintTradingGasToRatioCalculator(_gasLimit, chainInfo.gasLimitRatio);
|
|
10402
|
-
const { gasPrice } = await bigintTradingGasPriceWithRatio(
|
|
10586
|
+
const { gasPrice } = await bigintTradingGasPriceWithRatio(chainId);
|
|
10403
10587
|
const response = await contract["claimBasePoolRebate((bytes32,uint8,uint256,bytes,uint64)[],bytes32,address)"](prices, poolId, account, {
|
|
10404
10588
|
gasLimit,
|
|
10405
10589
|
gasPrice,
|
|
@@ -10413,20 +10597,20 @@ var claimBasePoolRebate = async (params) => {
|
|
|
10413
10597
|
};
|
|
10414
10598
|
var claimBasePoolRebates = async (params) => {
|
|
10415
10599
|
try {
|
|
10416
|
-
const { chainId
|
|
10600
|
+
const { chainId, poolIds } = params;
|
|
10417
10601
|
if (poolIds.length === 0) return;
|
|
10418
|
-
const chainInfo = CHAIN_INFO[
|
|
10419
|
-
const account = await getAccount(
|
|
10602
|
+
const chainInfo = CHAIN_INFO[chainId];
|
|
10603
|
+
const account = await getAccount(chainId);
|
|
10420
10604
|
await checkParams({
|
|
10421
10605
|
account,
|
|
10422
|
-
chainId
|
|
10606
|
+
chainId
|
|
10423
10607
|
});
|
|
10424
|
-
const priceData = await getPricesData(
|
|
10608
|
+
const priceData = await getPricesData(chainId, poolIds);
|
|
10425
10609
|
if (!priceData) return;
|
|
10426
10610
|
const prices = priceData.map((item) => {
|
|
10427
10611
|
return {
|
|
10428
10612
|
poolId: item.poolId,
|
|
10429
|
-
referencePrice: (0,
|
|
10613
|
+
referencePrice: (0, import_ethers7.parseUnits)(item?.price ?? "0", COMMON_PRICE_DECIMALS),
|
|
10430
10614
|
oracleUpdateData: item?.vaa ?? "0",
|
|
10431
10615
|
publishTime: item.publishTime,
|
|
10432
10616
|
oracleType: item.oracleType
|
|
@@ -10440,12 +10624,12 @@ var claimBasePoolRebates = async (params) => {
|
|
|
10440
10624
|
value,
|
|
10441
10625
|
recipient: account
|
|
10442
10626
|
};
|
|
10443
|
-
const contract = await getLiquidityRouterContract(
|
|
10627
|
+
const contract = await getLiquidityRouterContract(chainId);
|
|
10444
10628
|
const _gasLimit = await contract["claimBasePoolRebates((bytes32,uint8,uint256,bytes,uint64)[],bytes32[],address)"].estimateGas(prices, poolIds, account, {
|
|
10445
10629
|
value
|
|
10446
10630
|
});
|
|
10447
10631
|
const gasLimit = bigintTradingGasToRatioCalculator(_gasLimit, chainInfo.gasLimitRatio);
|
|
10448
|
-
const { gasPrice } = await bigintTradingGasPriceWithRatio(
|
|
10632
|
+
const { gasPrice } = await bigintTradingGasPriceWithRatio(chainId);
|
|
10449
10633
|
const response = await contract["claimBasePoolRebates((bytes32,uint8,uint256,bytes,uint64)[],bytes32[],address)"](prices, poolIds, account, {
|
|
10450
10634
|
gasLimit,
|
|
10451
10635
|
gasPrice,
|
|
@@ -10459,37 +10643,17 @@ var claimBasePoolRebates = async (params) => {
|
|
|
10459
10643
|
};
|
|
10460
10644
|
|
|
10461
10645
|
// src/lp/base/deposit.ts
|
|
10462
|
-
var
|
|
10463
|
-
|
|
10464
|
-
// src/lp/base/preview.ts
|
|
10465
|
-
var import_ethers9 = require("ethers");
|
|
10466
|
-
|
|
10467
|
-
// src/config/market/ARB_TEST_SEPOLIA.ts
|
|
10468
|
-
var ARB_TEST_SEPOLIA2 = {
|
|
10469
|
-
marketId: "0x1ddd0797c40b61b1437e0c455a78470e7c0659ed497d94222425736210f9d08c",
|
|
10470
|
-
quoteToken: "0x7E248Ec1721639413A280d9E82e2862Cae2E6E28",
|
|
10471
|
-
oracleFeeUsd: 400000000n,
|
|
10472
|
-
oracleRefundFeeUsd: 300000000n,
|
|
10473
|
-
baseReserveRatio: 100,
|
|
10474
|
-
quoteReserveRatio: 100,
|
|
10475
|
-
poolPrimeThreshold: 20000n,
|
|
10476
|
-
decimals: 6,
|
|
10477
|
-
lpDecimals: COMMON_LP_AMOUNT_DECIMALS
|
|
10478
|
-
};
|
|
10479
|
-
|
|
10480
|
-
// src/config/market/index.ts
|
|
10481
|
-
var Market = {
|
|
10482
|
-
[421614 /* ARB_TESTNET */]: ARB_TEST_SEPOLIA2
|
|
10483
|
-
};
|
|
10646
|
+
var import_ethers10 = require("ethers");
|
|
10484
10647
|
|
|
10485
10648
|
// src/lp/base/preview.ts
|
|
10486
|
-
var
|
|
10649
|
+
var import_ethers8 = require("ethers");
|
|
10650
|
+
var previewLpAmountOut = async ({ chainId, amountIn, poolId, price = 0n }) => {
|
|
10487
10651
|
try {
|
|
10488
|
-
const chainInfo = CHAIN_INFO[
|
|
10489
|
-
const basePoolContract = await getBasePoolContract(
|
|
10652
|
+
const chainInfo = CHAIN_INFO[chainId];
|
|
10653
|
+
const basePoolContract = await getBasePoolContract(chainId);
|
|
10490
10654
|
const _gasLimit = await basePoolContract.previewLpAmountOut.estimateGas(poolId, amountIn, price);
|
|
10491
10655
|
const gasLimit = bigintTradingGasToRatioCalculator(_gasLimit, chainInfo.gasLimitRatio);
|
|
10492
|
-
const { gasPrice } = await bigintTradingGasPriceWithRatio(
|
|
10656
|
+
const { gasPrice } = await bigintTradingGasPriceWithRatio(chainId);
|
|
10493
10657
|
const request = await basePoolContract.previewLpAmountOut(poolId, amountIn, price, {
|
|
10494
10658
|
gasLimit,
|
|
10495
10659
|
gasPrice
|
|
@@ -10500,13 +10664,13 @@ var previewLpAmountOut = async ({ chainId: chainId2, amountIn, poolId, price = 0
|
|
|
10500
10664
|
throw typeof error === "string" ? error : await getErrorTextFormError(error);
|
|
10501
10665
|
}
|
|
10502
10666
|
};
|
|
10503
|
-
var previewBaseAmountOut = async ({ chainId
|
|
10667
|
+
var previewBaseAmountOut = async ({ chainId, amountIn, poolId, price = 0n }) => {
|
|
10504
10668
|
try {
|
|
10505
|
-
const chainInfo = CHAIN_INFO[
|
|
10506
|
-
const basePoolContract = await getBasePoolContract(
|
|
10669
|
+
const chainInfo = CHAIN_INFO[chainId];
|
|
10670
|
+
const basePoolContract = await getBasePoolContract(chainId);
|
|
10507
10671
|
const _gasLimit = await basePoolContract.previewBaseAmountOut.estimateGas(poolId, amountIn, price);
|
|
10508
10672
|
const gasLimit = bigintTradingGasToRatioCalculator(_gasLimit, chainInfo.gasLimitRatio);
|
|
10509
|
-
const { gasPrice } = await bigintTradingGasPriceWithRatio(
|
|
10673
|
+
const { gasPrice } = await bigintTradingGasPriceWithRatio(chainId);
|
|
10510
10674
|
const request = await basePoolContract.previewBaseAmountOut(poolId, amountIn, price, {
|
|
10511
10675
|
gasLimit,
|
|
10512
10676
|
gasPrice
|
|
@@ -10517,32 +10681,32 @@ var previewBaseAmountOut = async ({ chainId: chainId2, amountIn, poolId, price =
|
|
|
10517
10681
|
throw typeof error === "string" ? error : await getErrorTextFormError(error);
|
|
10518
10682
|
}
|
|
10519
10683
|
};
|
|
10520
|
-
var previewUserWithdrawData = async ({ chainId
|
|
10684
|
+
var previewUserWithdrawData = async ({ chainId, account, poolId, amount = 0 }) => {
|
|
10521
10685
|
try {
|
|
10522
|
-
if (!
|
|
10686
|
+
if (!chainId || !account || !poolId) return;
|
|
10523
10687
|
if (!amount) {
|
|
10524
10688
|
return {
|
|
10525
10689
|
baseAmountOut: 0n,
|
|
10526
10690
|
rebateAmount: 0n
|
|
10527
10691
|
};
|
|
10528
10692
|
}
|
|
10529
|
-
const chainInfo = CHAIN_INFO[
|
|
10530
|
-
const decimals =
|
|
10693
|
+
const chainInfo = CHAIN_INFO[chainId];
|
|
10694
|
+
const decimals = COMMON_LP_AMOUNT_DECIMALS;
|
|
10531
10695
|
await checkParams({
|
|
10532
10696
|
// tokenAddress: lpAddress,
|
|
10533
10697
|
decimals,
|
|
10534
10698
|
account,
|
|
10535
|
-
chainId
|
|
10699
|
+
chainId,
|
|
10536
10700
|
amount: Number(amount)
|
|
10537
10701
|
});
|
|
10538
|
-
const amountIn = (0,
|
|
10539
|
-
const priceResponse = await getOraclePrice(
|
|
10702
|
+
const amountIn = (0, import_ethers8.parseUnits)(amount.toString(), decimals);
|
|
10703
|
+
const priceResponse = await getOraclePrice(chainId, [poolId]);
|
|
10540
10704
|
const _price = priceResponse.data?.[0]?.price || "0";
|
|
10541
|
-
const price = (0,
|
|
10542
|
-
const basePoolContract = await getBasePoolContract(
|
|
10705
|
+
const price = (0, import_ethers8.parseUnits)(_price, COMMON_PRICE_DECIMALS);
|
|
10706
|
+
const basePoolContract = await getBasePoolContract(chainId);
|
|
10543
10707
|
const _gasLimit = await basePoolContract.previewUserWithdrawData.estimateGas(poolId, amountIn, account, price);
|
|
10544
10708
|
const gasLimit = bigintTradingGasToRatioCalculator(_gasLimit, chainInfo.gasLimitRatio);
|
|
10545
|
-
const { gasPrice } = await bigintTradingGasPriceWithRatio(
|
|
10709
|
+
const { gasPrice } = await bigintTradingGasPriceWithRatio(chainId);
|
|
10546
10710
|
const request = await basePoolContract.previewUserWithdrawData(poolId, amountIn, account, price, {
|
|
10547
10711
|
gasLimit,
|
|
10548
10712
|
gasPrice
|
|
@@ -10559,10 +10723,10 @@ var previewUserWithdrawData = async ({ chainId: chainId2, account, poolId, amoun
|
|
|
10559
10723
|
};
|
|
10560
10724
|
|
|
10561
10725
|
// src/lp/getPoolInfo.ts
|
|
10562
|
-
var getPoolInfo = async (
|
|
10726
|
+
var getPoolInfo = async (chainId, poolId) => {
|
|
10563
10727
|
try {
|
|
10564
|
-
if (!
|
|
10565
|
-
const response = await getPoolDetail(
|
|
10728
|
+
if (!chainId || !poolId) return;
|
|
10729
|
+
const response = await getPoolDetail(chainId, poolId);
|
|
10566
10730
|
const pool = response.data;
|
|
10567
10731
|
return pool;
|
|
10568
10732
|
} catch (error) {
|
|
@@ -10571,7 +10735,7 @@ var getPoolInfo = async (chainId2, poolId) => {
|
|
|
10571
10735
|
};
|
|
10572
10736
|
|
|
10573
10737
|
// src/common/getTpSlParams.ts
|
|
10574
|
-
var
|
|
10738
|
+
var import_ethers9 = require("ethers");
|
|
10575
10739
|
|
|
10576
10740
|
// src/utils/number.ts
|
|
10577
10741
|
function getDecimalPlaces(value) {
|
|
@@ -10587,10 +10751,10 @@ var getTpSlParams = (slippage = 0.01, tpsl = [], decimals = COMMON_LP_AMOUNT_DEC
|
|
|
10587
10751
|
throw new Error(Errors[4006 /* Invalid_Params */]);
|
|
10588
10752
|
}
|
|
10589
10753
|
const tpslParams = tpsl.map((item) => {
|
|
10590
|
-
const amount = (0,
|
|
10591
|
-
const triggerPrice = (0,
|
|
10754
|
+
const amount = (0, import_ethers9.parseUnits)(item.amount.toString(), decimals);
|
|
10755
|
+
const triggerPrice = (0, import_ethers9.parseUnits)(item.triggerPrice.toString(), COMMON_PRICE_DECIMALS);
|
|
10592
10756
|
const decimal = getDecimalPlaces(item.triggerPrice.toString());
|
|
10593
|
-
const price = (0,
|
|
10757
|
+
const price = (0, import_ethers9.parseUnits)(item.triggerPrice.toString(), decimal);
|
|
10594
10758
|
const minQuoteOut = bigintAmountSlipperCalculator(amount * price * BigInt(10 ** quoteDecimal) / BigInt(10 ** (decimal + decimals)), slippage);
|
|
10595
10759
|
return {
|
|
10596
10760
|
amount,
|
|
@@ -10605,36 +10769,36 @@ var getTpSlParams = (slippage = 0.01, tpsl = [], decimals = COMMON_LP_AMOUNT_DEC
|
|
|
10605
10769
|
// src/lp/base/deposit.ts
|
|
10606
10770
|
var deposit = async (params) => {
|
|
10607
10771
|
try {
|
|
10608
|
-
const { poolId, chainId
|
|
10772
|
+
const { poolId, chainId, amount, slippage = 0.01, tpsl = [] } = params;
|
|
10609
10773
|
await checkParams(params);
|
|
10610
|
-
const pool = await getPoolInfo(
|
|
10774
|
+
const pool = await getPoolInfo(chainId, poolId);
|
|
10611
10775
|
if (!pool) {
|
|
10612
10776
|
throw new Error(Errors[4006 /* Invalid_Params */]);
|
|
10613
10777
|
}
|
|
10614
10778
|
const decimals = pool?.baseDecimals;
|
|
10615
10779
|
const quoteDecimals = pool?.quoteDecimals;
|
|
10616
10780
|
const tokenAddress = pool?.baseToken;
|
|
10617
|
-
const chainInfo = CHAIN_INFO[
|
|
10618
|
-
const account = await getAccount(
|
|
10619
|
-
const addresses = address_default[
|
|
10781
|
+
const chainInfo = CHAIN_INFO[chainId];
|
|
10782
|
+
const account = await getAccount(chainId);
|
|
10783
|
+
const addresses = address_default[chainId];
|
|
10620
10784
|
const contractAddress = addresses.BASE_POOL;
|
|
10621
10785
|
await checkParams({
|
|
10622
10786
|
tokenAddress,
|
|
10623
10787
|
contractAddress,
|
|
10624
10788
|
decimals,
|
|
10625
10789
|
account,
|
|
10626
|
-
chainId
|
|
10790
|
+
chainId,
|
|
10627
10791
|
amount
|
|
10628
10792
|
});
|
|
10629
10793
|
const isNeedPrice = !(Number(pool?.state) === 0 /* Cook */ || Number(pool?.state) === 1 /* Primed */);
|
|
10630
10794
|
const price = [];
|
|
10631
|
-
const amountIn = (0,
|
|
10795
|
+
const amountIn = (0, import_ethers10.parseUnits)(amount.toString(), decimals);
|
|
10632
10796
|
let value = 0n;
|
|
10633
10797
|
let amountOut;
|
|
10634
10798
|
if (isNeedPrice) {
|
|
10635
|
-
const priceData = await getPriceData(
|
|
10799
|
+
const priceData = await getPriceData(chainId, poolId);
|
|
10636
10800
|
if (!priceData) return;
|
|
10637
|
-
const referencePrice = (0,
|
|
10801
|
+
const referencePrice = (0, import_ethers10.parseUnits)(priceData.price, COMMON_PRICE_DECIMALS);
|
|
10638
10802
|
price.push({
|
|
10639
10803
|
poolId,
|
|
10640
10804
|
referencePrice,
|
|
@@ -10642,10 +10806,10 @@ var deposit = async (params) => {
|
|
|
10642
10806
|
publishTime: priceData.publishTime,
|
|
10643
10807
|
oracleType: priceData.oracleType
|
|
10644
10808
|
});
|
|
10645
|
-
amountOut = await previewLpAmountOut({ chainId
|
|
10809
|
+
amountOut = await previewLpAmountOut({ chainId, poolId, amountIn, price: referencePrice });
|
|
10646
10810
|
value = priceData.value;
|
|
10647
10811
|
} else {
|
|
10648
|
-
amountOut = await previewLpAmountOut({ chainId
|
|
10812
|
+
amountOut = await previewLpAmountOut({ chainId, poolId, amountIn });
|
|
10649
10813
|
}
|
|
10650
10814
|
const _tpsl = tpsl.map((item) => {
|
|
10651
10815
|
return {
|
|
@@ -10663,10 +10827,10 @@ var deposit = async (params) => {
|
|
|
10663
10827
|
recipient: account,
|
|
10664
10828
|
tpslParams
|
|
10665
10829
|
};
|
|
10666
|
-
const contract = await getLiquidityRouterContract(
|
|
10830
|
+
const contract = await getLiquidityRouterContract(chainId);
|
|
10667
10831
|
const _gasLimit = await contract["depositBase((bytes32,uint8,uint256,bytes,uint64)[],(bytes32,uint256,uint256,address,(uint256,uint256,uint8,uint256)[]))"].estimateGas(price, data, { value });
|
|
10668
10832
|
const gasLimit = bigintTradingGasToRatioCalculator(_gasLimit, chainInfo.gasLimitRatio);
|
|
10669
|
-
const { gasPrice } = await bigintTradingGasPriceWithRatio(
|
|
10833
|
+
const { gasPrice } = await bigintTradingGasPriceWithRatio(chainId);
|
|
10670
10834
|
const result = await contract["depositBase((bytes32,uint8,uint256,bytes,uint64)[],(bytes32,uint256,uint256,address,(uint256,uint256,uint8,uint256)[]))"](price, data, {
|
|
10671
10835
|
gasLimit,
|
|
10672
10836
|
gasPrice,
|
|
@@ -10680,31 +10844,31 @@ var deposit = async (params) => {
|
|
|
10680
10844
|
};
|
|
10681
10845
|
|
|
10682
10846
|
// src/lp/base/withdraw.ts
|
|
10683
|
-
var
|
|
10847
|
+
var import_ethers11 = require("ethers");
|
|
10684
10848
|
var withdraw = async (params) => {
|
|
10685
10849
|
try {
|
|
10686
|
-
const { chainId
|
|
10687
|
-
const pool = await getPoolInfo(
|
|
10850
|
+
const { chainId, poolId, amount, slippage = 0.01 } = params;
|
|
10851
|
+
const pool = await getPoolInfo(chainId, poolId);
|
|
10688
10852
|
const lpAddress = pool?.quotePoolToken;
|
|
10689
|
-
const chainInfo = CHAIN_INFO[
|
|
10690
|
-
const account = await getAccount(
|
|
10691
|
-
const decimals =
|
|
10853
|
+
const chainInfo = CHAIN_INFO[chainId];
|
|
10854
|
+
const account = await getAccount(chainId);
|
|
10855
|
+
const decimals = COMMON_LP_AMOUNT_DECIMALS;
|
|
10692
10856
|
await checkParams({
|
|
10693
10857
|
tokenAddress: lpAddress,
|
|
10694
10858
|
decimals,
|
|
10695
10859
|
account,
|
|
10696
|
-
chainId
|
|
10860
|
+
chainId,
|
|
10697
10861
|
amount
|
|
10698
10862
|
});
|
|
10699
|
-
const amountIn = (0,
|
|
10863
|
+
const amountIn = (0, import_ethers11.parseUnits)(amount.toString(), decimals);
|
|
10700
10864
|
const isNeedPrice = !(Number(pool?.state) === 0 /* Cook */ || Number(pool?.state) === 1 /* Primed */);
|
|
10701
10865
|
const price = [];
|
|
10702
10866
|
let value = 0n;
|
|
10703
10867
|
let amountOut;
|
|
10704
10868
|
if (isNeedPrice) {
|
|
10705
|
-
const priceData = await getPriceData(
|
|
10869
|
+
const priceData = await getPriceData(chainId, poolId);
|
|
10706
10870
|
if (!priceData) return;
|
|
10707
|
-
const referencePrice = (0,
|
|
10871
|
+
const referencePrice = (0, import_ethers11.parseUnits)(priceData.price, COMMON_PRICE_DECIMALS);
|
|
10708
10872
|
price.push({
|
|
10709
10873
|
poolId,
|
|
10710
10874
|
referencePrice,
|
|
@@ -10712,10 +10876,10 @@ var withdraw = async (params) => {
|
|
|
10712
10876
|
publishTime: priceData.publishTime,
|
|
10713
10877
|
oracleType: priceData.oracleType
|
|
10714
10878
|
});
|
|
10715
|
-
amountOut = await previewBaseAmountOut({ chainId
|
|
10879
|
+
amountOut = await previewBaseAmountOut({ chainId, poolId, amountIn, price: referencePrice });
|
|
10716
10880
|
value = priceData.value;
|
|
10717
10881
|
} else {
|
|
10718
|
-
amountOut = await previewBaseAmountOut({ chainId
|
|
10882
|
+
amountOut = await previewBaseAmountOut({ chainId, poolId, amountIn });
|
|
10719
10883
|
}
|
|
10720
10884
|
const data = {
|
|
10721
10885
|
poolId,
|
|
@@ -10723,10 +10887,10 @@ var withdraw = async (params) => {
|
|
|
10723
10887
|
minAmountOut: bigintAmountSlipperCalculator(amountOut, slippage),
|
|
10724
10888
|
recipient: account
|
|
10725
10889
|
};
|
|
10726
|
-
const contract = await getLiquidityRouterContract(
|
|
10890
|
+
const contract = await getLiquidityRouterContract(chainId);
|
|
10727
10891
|
const _gasLimit = await contract["withdrawBase((bytes32,uint8,uint256,bytes,uint64)[],(bytes32,uint256,uint256,address))"].estimateGas(price, data, { value });
|
|
10728
10892
|
const gasLimit = bigintTradingGasToRatioCalculator(_gasLimit, chainInfo.gasLimitRatio);
|
|
10729
|
-
const { gasPrice } = await bigintTradingGasPriceWithRatio(
|
|
10893
|
+
const { gasPrice } = await bigintTradingGasPriceWithRatio(chainId);
|
|
10730
10894
|
const response = await contract["withdrawBase((bytes32,uint8,uint256,bytes,uint64)[],(bytes32,uint256,uint256,address))"](price, data, {
|
|
10731
10895
|
gasLimit,
|
|
10732
10896
|
gasPrice,
|
|
@@ -10741,20 +10905,20 @@ var withdraw = async (params) => {
|
|
|
10741
10905
|
};
|
|
10742
10906
|
|
|
10743
10907
|
// src/lp/base/rewards.ts
|
|
10744
|
-
var
|
|
10908
|
+
var import_ethers12 = require("ethers");
|
|
10745
10909
|
var getRewards = async (params) => {
|
|
10746
10910
|
try {
|
|
10747
|
-
const { chainId
|
|
10748
|
-
if (!
|
|
10749
|
-
const chainInfo = CHAIN_INFO[
|
|
10911
|
+
const { chainId, account, poolId } = params;
|
|
10912
|
+
if (!chainId || !account || !poolId) return;
|
|
10913
|
+
const chainInfo = CHAIN_INFO[chainId];
|
|
10750
10914
|
const lpAmountIn = 0n;
|
|
10751
|
-
const priceResponse = await getOraclePrice(
|
|
10915
|
+
const priceResponse = await getOraclePrice(chainId, [poolId]);
|
|
10752
10916
|
const _price = priceResponse.data?.[0]?.price || "0";
|
|
10753
|
-
const price = (0,
|
|
10754
|
-
const basePoolContract = await getBasePoolContract(
|
|
10917
|
+
const price = (0, import_ethers12.parseUnits)(_price, COMMON_PRICE_DECIMALS);
|
|
10918
|
+
const basePoolContract = await getBasePoolContract(chainId);
|
|
10755
10919
|
const _gasLimit = await basePoolContract.pendingUserRebates.estimateGas(poolId, account, price);
|
|
10756
10920
|
const gasLimit = bigintTradingGasToRatioCalculator(_gasLimit, chainInfo.gasLimitRatio);
|
|
10757
|
-
const { gasPrice } = await bigintTradingGasPriceWithRatio(
|
|
10921
|
+
const { gasPrice } = await bigintTradingGasPriceWithRatio(chainId);
|
|
10758
10922
|
const request = await basePoolContract.pendingUserRebates(poolId, account, price, {
|
|
10759
10923
|
gasLimit,
|
|
10760
10924
|
gasPrice
|
|
@@ -10767,17 +10931,17 @@ var getRewards = async (params) => {
|
|
|
10767
10931
|
};
|
|
10768
10932
|
|
|
10769
10933
|
// src/lp/base/price.ts
|
|
10770
|
-
var
|
|
10771
|
-
var getLpPrice = async (
|
|
10934
|
+
var import_ethers13 = require("ethers");
|
|
10935
|
+
var getLpPrice = async (chainId, poolId) => {
|
|
10772
10936
|
if (!poolId) return;
|
|
10773
10937
|
try {
|
|
10774
|
-
const pool = await getPoolInfo(
|
|
10775
|
-
const contract = await getBasePoolContract(
|
|
10938
|
+
const pool = await getPoolInfo(chainId, poolId);
|
|
10939
|
+
const contract = await getBasePoolContract(chainId);
|
|
10776
10940
|
let price = 0n;
|
|
10777
10941
|
if (!(Number(pool?.state) === 0 /* Cook */ || Number(pool?.state) === 1 /* Primed */)) {
|
|
10778
|
-
const res = await getPriceData(
|
|
10942
|
+
const res = await getPriceData(chainId, poolId);
|
|
10779
10943
|
if (res?.price) {
|
|
10780
|
-
price = (0,
|
|
10944
|
+
price = (0, import_ethers13.parseUnits)(res.price, COMMON_PRICE_DECIMALS);
|
|
10781
10945
|
}
|
|
10782
10946
|
}
|
|
10783
10947
|
const data = await contract.getPoolTokenPrice(poolId, price);
|
|
@@ -10801,16 +10965,16 @@ __export(quote_exports, {
|
|
|
10801
10965
|
});
|
|
10802
10966
|
|
|
10803
10967
|
// src/lp/quote/deposit.ts
|
|
10804
|
-
var
|
|
10968
|
+
var import_ethers14 = require("ethers");
|
|
10805
10969
|
|
|
10806
10970
|
// src/lp/quote/preview.ts
|
|
10807
|
-
var previewLpAmountOut2 = async ({ chainId
|
|
10971
|
+
var previewLpAmountOut2 = async ({ chainId, amountIn, poolId, price = 0n }) => {
|
|
10808
10972
|
try {
|
|
10809
|
-
const chainInfo = CHAIN_INFO[
|
|
10810
|
-
const quotePoolContract = await getQuotePoolContract(
|
|
10973
|
+
const chainInfo = CHAIN_INFO[chainId];
|
|
10974
|
+
const quotePoolContract = await getQuotePoolContract(chainId);
|
|
10811
10975
|
const _gasLimit = await quotePoolContract.previewLpAmountOut.estimateGas(poolId, amountIn, price);
|
|
10812
10976
|
const gasLimit = bigintTradingGasToRatioCalculator(_gasLimit, chainInfo.gasLimitRatio);
|
|
10813
|
-
const { gasPrice } = await bigintTradingGasPriceWithRatio(
|
|
10977
|
+
const { gasPrice } = await bigintTradingGasPriceWithRatio(chainId);
|
|
10814
10978
|
const request = await quotePoolContract.previewLpAmountOut(poolId, amountIn, price, {
|
|
10815
10979
|
gasLimit,
|
|
10816
10980
|
gasPrice
|
|
@@ -10821,13 +10985,13 @@ var previewLpAmountOut2 = async ({ chainId: chainId2, amountIn, poolId, price =
|
|
|
10821
10985
|
throw typeof error === "string" ? error : await getErrorTextFormError(error);
|
|
10822
10986
|
}
|
|
10823
10987
|
};
|
|
10824
|
-
var previewQuoteAmountOut = async ({ chainId
|
|
10988
|
+
var previewQuoteAmountOut = async ({ chainId, amountIn, poolId, price = 0n }) => {
|
|
10825
10989
|
try {
|
|
10826
|
-
const chainInfo = CHAIN_INFO[
|
|
10827
|
-
const quotePoolContract = await getQuotePoolContract(
|
|
10990
|
+
const chainInfo = CHAIN_INFO[chainId];
|
|
10991
|
+
const quotePoolContract = await getQuotePoolContract(chainId);
|
|
10828
10992
|
const _gasLimit = await quotePoolContract.previewQuoteAmountOut.estimateGas(poolId, amountIn, price);
|
|
10829
10993
|
const gasLimit = bigintTradingGasToRatioCalculator(_gasLimit, chainInfo.gasLimitRatio);
|
|
10830
|
-
const { gasPrice } = await bigintTradingGasPriceWithRatio(
|
|
10994
|
+
const { gasPrice } = await bigintTradingGasPriceWithRatio(chainId);
|
|
10831
10995
|
const request = await quotePoolContract.previewQuoteAmountOut(poolId, amountIn, price, {
|
|
10832
10996
|
gasLimit,
|
|
10833
10997
|
gasPrice
|
|
@@ -10842,15 +11006,15 @@ var previewQuoteAmountOut = async ({ chainId: chainId2, amountIn, poolId, price
|
|
|
10842
11006
|
// src/lp/quote/deposit.ts
|
|
10843
11007
|
var deposit2 = async (params) => {
|
|
10844
11008
|
try {
|
|
10845
|
-
const { poolId, chainId
|
|
11009
|
+
const { poolId, chainId, amount, slippage = 0.01, tpsl = [] } = params;
|
|
10846
11010
|
await checkParams(params);
|
|
10847
|
-
const pool = await getPoolInfo(
|
|
11011
|
+
const pool = await getPoolInfo(chainId, poolId);
|
|
10848
11012
|
if (!pool) {
|
|
10849
11013
|
throw new Error(Errors[4006 /* Invalid_Params */]);
|
|
10850
11014
|
}
|
|
10851
|
-
const chainInfo = CHAIN_INFO[
|
|
10852
|
-
const account = await getAccount(
|
|
10853
|
-
const addresses = address_default[
|
|
11015
|
+
const chainInfo = CHAIN_INFO[chainId];
|
|
11016
|
+
const account = await getAccount(chainId);
|
|
11017
|
+
const addresses = address_default[chainId];
|
|
10854
11018
|
const contractAddress = addresses.QUOTE_POOL;
|
|
10855
11019
|
const tokenAddress = pool.quoteToken;
|
|
10856
11020
|
const decimals = pool?.quoteDecimals;
|
|
@@ -10859,18 +11023,18 @@ var deposit2 = async (params) => {
|
|
|
10859
11023
|
contractAddress,
|
|
10860
11024
|
decimals,
|
|
10861
11025
|
account,
|
|
10862
|
-
chainId
|
|
11026
|
+
chainId,
|
|
10863
11027
|
amount
|
|
10864
11028
|
});
|
|
10865
|
-
const amountIn = (0,
|
|
11029
|
+
const amountIn = (0, import_ethers14.parseUnits)(amount.toString(), decimals);
|
|
10866
11030
|
const isNeedPrice = !(Number(pool?.state) === 0 /* Cook */ || Number(pool?.state) === 1 /* Primed */);
|
|
10867
11031
|
const price = [];
|
|
10868
11032
|
let value = 0n;
|
|
10869
11033
|
let amountOut;
|
|
10870
11034
|
if (isNeedPrice) {
|
|
10871
|
-
const priceData = await getPriceData(
|
|
11035
|
+
const priceData = await getPriceData(chainId, poolId);
|
|
10872
11036
|
if (!priceData) return;
|
|
10873
|
-
const referencePrice = (0,
|
|
11037
|
+
const referencePrice = (0, import_ethers14.parseUnits)(priceData.price, COMMON_PRICE_DECIMALS);
|
|
10874
11038
|
price.push({
|
|
10875
11039
|
poolId,
|
|
10876
11040
|
referencePrice,
|
|
@@ -10878,10 +11042,10 @@ var deposit2 = async (params) => {
|
|
|
10878
11042
|
publishTime: priceData.publishTime,
|
|
10879
11043
|
oracleType: priceData.oracleType
|
|
10880
11044
|
});
|
|
10881
|
-
amountOut = await previewLpAmountOut2({ chainId
|
|
11045
|
+
amountOut = await previewLpAmountOut2({ chainId, poolId, amountIn, price: referencePrice });
|
|
10882
11046
|
value = priceData.value;
|
|
10883
11047
|
} else {
|
|
10884
|
-
amountOut = await previewLpAmountOut2({ chainId
|
|
11048
|
+
amountOut = await previewLpAmountOut2({ chainId, poolId, amountIn });
|
|
10885
11049
|
}
|
|
10886
11050
|
const _tpsl = tpsl.map((item) => {
|
|
10887
11051
|
return {
|
|
@@ -10899,10 +11063,10 @@ var deposit2 = async (params) => {
|
|
|
10899
11063
|
recipient: account,
|
|
10900
11064
|
tpslParams
|
|
10901
11065
|
};
|
|
10902
|
-
const contract = await getLiquidityRouterContract(
|
|
11066
|
+
const contract = await getLiquidityRouterContract(chainId);
|
|
10903
11067
|
const _gasLimit = await contract["depositQuote((bytes32,uint8,uint256,bytes,uint64)[],(bytes32,uint256,uint256,address,(uint256,uint256,uint8,uint256)[]))"].estimateGas(price, data, { value });
|
|
10904
11068
|
const gasLimit = bigintTradingGasToRatioCalculator(_gasLimit, chainInfo.gasLimitRatio);
|
|
10905
|
-
const { gasPrice } = await bigintTradingGasPriceWithRatio(
|
|
11069
|
+
const { gasPrice } = await bigintTradingGasPriceWithRatio(chainId);
|
|
10906
11070
|
const result = await contract["depositQuote((bytes32,uint8,uint256,bytes,uint64)[],(bytes32,uint256,uint256,address,(uint256,uint256,uint8,uint256)[]))"](price, data, {
|
|
10907
11071
|
gasLimit,
|
|
10908
11072
|
gasPrice,
|
|
@@ -10916,31 +11080,31 @@ var deposit2 = async (params) => {
|
|
|
10916
11080
|
};
|
|
10917
11081
|
|
|
10918
11082
|
// src/lp/quote/withdraw.ts
|
|
10919
|
-
var
|
|
11083
|
+
var import_ethers15 = require("ethers");
|
|
10920
11084
|
var withdraw2 = async (params) => {
|
|
10921
11085
|
try {
|
|
10922
|
-
const { chainId
|
|
10923
|
-
const pool = await getPoolInfo(
|
|
11086
|
+
const { chainId, poolId, amount, slippage = 0.01 } = params;
|
|
11087
|
+
const pool = await getPoolInfo(chainId, poolId);
|
|
10924
11088
|
const lpAddress = pool?.quotePoolToken;
|
|
10925
|
-
const chainInfo = CHAIN_INFO[
|
|
10926
|
-
const account = await getAccount(
|
|
10927
|
-
const decimals =
|
|
11089
|
+
const chainInfo = CHAIN_INFO[chainId];
|
|
11090
|
+
const account = await getAccount(chainId);
|
|
11091
|
+
const decimals = COMMON_LP_AMOUNT_DECIMALS;
|
|
10928
11092
|
await checkParams({
|
|
10929
11093
|
tokenAddress: lpAddress,
|
|
10930
11094
|
decimals,
|
|
10931
11095
|
account,
|
|
10932
|
-
chainId
|
|
11096
|
+
chainId,
|
|
10933
11097
|
amount
|
|
10934
11098
|
});
|
|
10935
|
-
const amountIn = (0,
|
|
11099
|
+
const amountIn = (0, import_ethers15.parseUnits)(amount.toString(), decimals);
|
|
10936
11100
|
const isNeedPrice = !(Number(pool?.state) === 0 /* Cook */ || Number(pool?.state) === 1 /* Primed */);
|
|
10937
11101
|
const price = [];
|
|
10938
11102
|
let value = 0n;
|
|
10939
11103
|
let amountOut;
|
|
10940
11104
|
if (isNeedPrice) {
|
|
10941
|
-
const priceData = await getPriceData(
|
|
11105
|
+
const priceData = await getPriceData(chainId, poolId);
|
|
10942
11106
|
if (!priceData) return;
|
|
10943
|
-
const referencePrice = (0,
|
|
11107
|
+
const referencePrice = (0, import_ethers15.parseUnits)(priceData.price, COMMON_PRICE_DECIMALS);
|
|
10944
11108
|
price.push({
|
|
10945
11109
|
poolId,
|
|
10946
11110
|
referencePrice,
|
|
@@ -10948,10 +11112,10 @@ var withdraw2 = async (params) => {
|
|
|
10948
11112
|
publishTime: priceData.publishTime,
|
|
10949
11113
|
oracleType: priceData.oracleType
|
|
10950
11114
|
});
|
|
10951
|
-
amountOut = await previewQuoteAmountOut({ chainId
|
|
11115
|
+
amountOut = await previewQuoteAmountOut({ chainId, poolId, amountIn, price: referencePrice });
|
|
10952
11116
|
value = priceData.value;
|
|
10953
11117
|
} else {
|
|
10954
|
-
amountOut = await previewQuoteAmountOut({ chainId
|
|
11118
|
+
amountOut = await previewQuoteAmountOut({ chainId, poolId, amountIn });
|
|
10955
11119
|
}
|
|
10956
11120
|
const data = {
|
|
10957
11121
|
poolId,
|
|
@@ -10960,10 +11124,10 @@ var withdraw2 = async (params) => {
|
|
|
10960
11124
|
// todo 调合约获取
|
|
10961
11125
|
recipient: account
|
|
10962
11126
|
};
|
|
10963
|
-
const contract = await getLiquidityRouterContract(
|
|
11127
|
+
const contract = await getLiquidityRouterContract(chainId);
|
|
10964
11128
|
const _gasLimit = await contract["withdrawQuote((bytes32,uint8,uint256,bytes,uint64)[],(bytes32,uint256,uint256,address))"].estimateGas(price, data, { value });
|
|
10965
11129
|
const gasLimit = bigintTradingGasToRatioCalculator(_gasLimit, chainInfo.gasLimitRatio);
|
|
10966
|
-
const { gasPrice } = await bigintTradingGasPriceWithRatio(
|
|
11130
|
+
const { gasPrice } = await bigintTradingGasPriceWithRatio(chainId);
|
|
10967
11131
|
const request = await contract["withdrawQuote((bytes32,uint8,uint256,bytes,uint64)[],(bytes32,uint256,uint256,address))"]([], data, {
|
|
10968
11132
|
gasLimit,
|
|
10969
11133
|
gasPrice,
|
|
@@ -10978,29 +11142,29 @@ var withdraw2 = async (params) => {
|
|
|
10978
11142
|
};
|
|
10979
11143
|
|
|
10980
11144
|
// src/lp/quote/transfer.ts
|
|
10981
|
-
var
|
|
10982
|
-
var transfer = async (
|
|
11145
|
+
var import_ethers16 = require("ethers");
|
|
11146
|
+
var transfer = async (chainId, fromPoolId, toPoolId, amount) => {
|
|
10983
11147
|
try {
|
|
10984
|
-
const fromPool = await getPoolInfo(
|
|
10985
|
-
const toPool = await getPoolInfo(
|
|
11148
|
+
const fromPool = await getPoolInfo(chainId, fromPoolId);
|
|
11149
|
+
const toPool = await getPoolInfo(chainId, toPoolId);
|
|
10986
11150
|
if (!toPool || !fromPool) return null;
|
|
10987
11151
|
if ([3 /* PreBench */, 4 /* Bench */].includes(toPool.state)) {
|
|
10988
11152
|
throw new Error(Errors[4005 /* Invalid_Pool_State */]);
|
|
10989
11153
|
}
|
|
10990
|
-
const account = await getAccount(
|
|
10991
|
-
const chainInfo = CHAIN_INFO[
|
|
10992
|
-
const decimals =
|
|
10993
|
-
await checkParams({ chainId
|
|
11154
|
+
const account = await getAccount(chainId);
|
|
11155
|
+
const chainInfo = CHAIN_INFO[chainId];
|
|
11156
|
+
const decimals = COMMON_LP_AMOUNT_DECIMALS;
|
|
11157
|
+
await checkParams({ chainId, amount, account, decimals, tokenAddress: fromPool.quotePoolToken });
|
|
10994
11158
|
const data = {
|
|
10995
11159
|
fromPoolId,
|
|
10996
11160
|
toPoolId,
|
|
10997
11161
|
minLpOut: 0n,
|
|
10998
|
-
amount: (0,
|
|
11162
|
+
amount: (0, import_ethers16.parseUnits)(amount.toString(), decimals)
|
|
10999
11163
|
};
|
|
11000
|
-
const contract = await getLiquidityRouterContract(
|
|
11164
|
+
const contract = await getLiquidityRouterContract(chainId);
|
|
11001
11165
|
const _gasLimit = await contract.migrateLiquidity.estimateGas(data);
|
|
11002
11166
|
const gasLimit = bigintTradingGasToRatioCalculator(_gasLimit, chainInfo.gasLimitRatio);
|
|
11003
|
-
const { gasPrice } = await bigintTradingGasPriceWithRatio(
|
|
11167
|
+
const { gasPrice } = await bigintTradingGasPriceWithRatio(chainId);
|
|
11004
11168
|
const result = await contract.migrateLiquidity(data, {
|
|
11005
11169
|
gasLimit,
|
|
11006
11170
|
gasPrice
|
|
@@ -11012,19 +11176,19 @@ var transfer = async (chainId2, fromPoolId, toPoolId, amount) => {
|
|
|
11012
11176
|
};
|
|
11013
11177
|
|
|
11014
11178
|
// src/lp/quote/rewards.ts
|
|
11015
|
-
var
|
|
11179
|
+
var import_ethers17 = require("ethers");
|
|
11016
11180
|
var getRewards2 = async (params) => {
|
|
11017
11181
|
try {
|
|
11018
|
-
const { chainId
|
|
11019
|
-
if (!
|
|
11020
|
-
const chainInfo = CHAIN_INFO[
|
|
11021
|
-
const priceResponse = await getOraclePrice(
|
|
11182
|
+
const { chainId, account, poolId } = params;
|
|
11183
|
+
if (!chainId || !account || !poolId) return;
|
|
11184
|
+
const chainInfo = CHAIN_INFO[chainId];
|
|
11185
|
+
const priceResponse = await getOraclePrice(chainId, [poolId]);
|
|
11022
11186
|
const _price = priceResponse.data?.[0]?.price || "0";
|
|
11023
|
-
const price = (0,
|
|
11024
|
-
const contract = await getQuotePoolContract(
|
|
11187
|
+
const price = (0, import_ethers17.parseUnits)(_price, COMMON_PRICE_DECIMALS);
|
|
11188
|
+
const contract = await getQuotePoolContract(chainId);
|
|
11025
11189
|
const _gasLimit = await contract.pendingUserRebates.estimateGas(poolId, account, price);
|
|
11026
11190
|
const gasLimit = bigintTradingGasToRatioCalculator(_gasLimit, chainInfo.gasLimitRatio);
|
|
11027
|
-
const { gasPrice } = await bigintTradingGasPriceWithRatio(
|
|
11191
|
+
const { gasPrice } = await bigintTradingGasPriceWithRatio(chainId);
|
|
11028
11192
|
const request = await contract.pendingUserRebates(poolId, account, price, {
|
|
11029
11193
|
gasLimit,
|
|
11030
11194
|
gasPrice
|
|
@@ -11037,18 +11201,18 @@ var getRewards2 = async (params) => {
|
|
|
11037
11201
|
};
|
|
11038
11202
|
|
|
11039
11203
|
// src/lp/quote/claim.ts
|
|
11040
|
-
var
|
|
11204
|
+
var import_ethers18 = require("ethers");
|
|
11041
11205
|
var claimQuotePoolRebate = async (params) => {
|
|
11042
11206
|
try {
|
|
11043
|
-
const { chainId
|
|
11044
|
-
const chainInfo = CHAIN_INFO[
|
|
11045
|
-
const account = await getAccount(
|
|
11207
|
+
const { chainId, poolId } = params;
|
|
11208
|
+
const chainInfo = CHAIN_INFO[chainId];
|
|
11209
|
+
const account = await getAccount(chainId);
|
|
11046
11210
|
const decimals = COMMON_LP_AMOUNT_DECIMALS;
|
|
11047
11211
|
await checkParams({
|
|
11048
11212
|
account,
|
|
11049
|
-
chainId
|
|
11213
|
+
chainId
|
|
11050
11214
|
});
|
|
11051
|
-
const priceResponse = await getPricesData(
|
|
11215
|
+
const priceResponse = await getPricesData(chainId, [poolId]);
|
|
11052
11216
|
if (!priceResponse) return;
|
|
11053
11217
|
const values = priceResponse.map((item) => {
|
|
11054
11218
|
return item.value;
|
|
@@ -11056,7 +11220,7 @@ var claimQuotePoolRebate = async (params) => {
|
|
|
11056
11220
|
const prices = priceResponse.map((item) => {
|
|
11057
11221
|
return {
|
|
11058
11222
|
poolId: item.poolId,
|
|
11059
|
-
referencePrice: (0,
|
|
11223
|
+
referencePrice: (0, import_ethers18.parseUnits)(item?.price ?? "0", COMMON_PRICE_DECIMALS),
|
|
11060
11224
|
oracleUpdateData: item?.vaa ?? "0",
|
|
11061
11225
|
publishTime: item.publishTime,
|
|
11062
11226
|
oracleType: item.oracleType
|
|
@@ -11068,12 +11232,12 @@ var claimQuotePoolRebate = async (params) => {
|
|
|
11068
11232
|
poolId,
|
|
11069
11233
|
recipient: account
|
|
11070
11234
|
};
|
|
11071
|
-
const contract = await getLiquidityRouterContract(
|
|
11235
|
+
const contract = await getLiquidityRouterContract(chainId);
|
|
11072
11236
|
const _gasLimit = await contract["claimQuotePoolRebate((bytes32,uint8,uint256,bytes,uint64)[],bytes32,address)"].estimateGas(prices, poolId, account, {
|
|
11073
11237
|
value: values[0]
|
|
11074
11238
|
});
|
|
11075
11239
|
const gasLimit = bigintTradingGasToRatioCalculator(_gasLimit, chainInfo.gasLimitRatio);
|
|
11076
|
-
const { gasPrice } = await bigintTradingGasPriceWithRatio(
|
|
11240
|
+
const { gasPrice } = await bigintTradingGasPriceWithRatio(chainId);
|
|
11077
11241
|
const response = await contract["claimQuotePoolRebate((bytes32,uint8,uint256,bytes,uint64)[],bytes32,address)"](prices, poolId, account, {
|
|
11078
11242
|
gasLimit,
|
|
11079
11243
|
gasPrice,
|
|
@@ -11087,21 +11251,21 @@ var claimQuotePoolRebate = async (params) => {
|
|
|
11087
11251
|
};
|
|
11088
11252
|
var claimQuotePoolRebates = async (params) => {
|
|
11089
11253
|
try {
|
|
11090
|
-
const { chainId
|
|
11254
|
+
const { chainId, poolIds } = params;
|
|
11091
11255
|
if (poolIds.length === 0) return;
|
|
11092
|
-
const chainInfo = CHAIN_INFO[
|
|
11093
|
-
const account = await getAccount(
|
|
11256
|
+
const chainInfo = CHAIN_INFO[chainId];
|
|
11257
|
+
const account = await getAccount(chainId);
|
|
11094
11258
|
const decimals = COMMON_LP_AMOUNT_DECIMALS;
|
|
11095
11259
|
await checkParams({
|
|
11096
11260
|
account,
|
|
11097
|
-
chainId
|
|
11261
|
+
chainId
|
|
11098
11262
|
});
|
|
11099
|
-
const priceResponse = await getPricesData(
|
|
11263
|
+
const priceResponse = await getPricesData(chainId, poolIds);
|
|
11100
11264
|
if (!priceResponse) return;
|
|
11101
11265
|
const prices = priceResponse.map((item) => {
|
|
11102
11266
|
return {
|
|
11103
11267
|
poolId: item.poolId,
|
|
11104
|
-
referencePrice: (0,
|
|
11268
|
+
referencePrice: (0, import_ethers18.parseUnits)(item?.price ?? "0", COMMON_PRICE_DECIMALS),
|
|
11105
11269
|
oracleUpdateData: item?.vaa ?? "0",
|
|
11106
11270
|
publishTime: item.publishTime,
|
|
11107
11271
|
oracleType: item.oracleType
|
|
@@ -11115,12 +11279,12 @@ var claimQuotePoolRebates = async (params) => {
|
|
|
11115
11279
|
poolIds,
|
|
11116
11280
|
recipient: account
|
|
11117
11281
|
};
|
|
11118
|
-
const contract = await getLiquidityRouterContract(
|
|
11282
|
+
const contract = await getLiquidityRouterContract(chainId);
|
|
11119
11283
|
const _gasLimit = await contract["claimQuotePoolRebates((bytes32,uint8,uint256,bytes,uint64)[],bytes32[],address)"].estimateGas(prices, poolIds, account, {
|
|
11120
11284
|
value
|
|
11121
11285
|
});
|
|
11122
11286
|
const gasLimit = bigintTradingGasToRatioCalculator(_gasLimit, chainInfo.gasLimitRatio);
|
|
11123
|
-
const { gasPrice } = await bigintTradingGasPriceWithRatio(
|
|
11287
|
+
const { gasPrice } = await bigintTradingGasPriceWithRatio(chainId);
|
|
11124
11288
|
const response = await contract["claimQuotePoolRebates((bytes32,uint8,uint256,bytes,uint64)[],bytes32[],address)"](prices, poolIds, account, {
|
|
11125
11289
|
gasLimit,
|
|
11126
11290
|
gasPrice,
|
|
@@ -11134,17 +11298,17 @@ var claimQuotePoolRebates = async (params) => {
|
|
|
11134
11298
|
};
|
|
11135
11299
|
|
|
11136
11300
|
// src/lp/quote/price.ts
|
|
11137
|
-
var
|
|
11138
|
-
var getLpPrice2 = async (
|
|
11301
|
+
var import_ethers19 = require("ethers");
|
|
11302
|
+
var getLpPrice2 = async (chainId, poolId) => {
|
|
11139
11303
|
if (!poolId) return;
|
|
11140
11304
|
try {
|
|
11141
|
-
const pool = await getPoolInfo(
|
|
11142
|
-
const contract = await getQuotePoolContract(
|
|
11305
|
+
const pool = await getPoolInfo(chainId, poolId);
|
|
11306
|
+
const contract = await getQuotePoolContract(chainId);
|
|
11143
11307
|
let price = 0n;
|
|
11144
11308
|
if (!(Number(pool?.state) === 0 /* Cook */ || Number(pool?.state) === 1 /* Primed */)) {
|
|
11145
|
-
const res = await getPriceData(
|
|
11309
|
+
const res = await getPriceData(chainId, poolId);
|
|
11146
11310
|
if (res?.price) {
|
|
11147
|
-
price = (0,
|
|
11311
|
+
price = (0, import_ethers19.parseUnits)(res.price, COMMON_PRICE_DECIMALS);
|
|
11148
11312
|
}
|
|
11149
11313
|
}
|
|
11150
11314
|
const data = await contract.getPoolTokenPrice(poolId, price);
|
|
@@ -11173,34 +11337,30 @@ __export(pool_exports, {
|
|
|
11173
11337
|
});
|
|
11174
11338
|
|
|
11175
11339
|
// src/lp/pool/get.ts
|
|
11176
|
-
var getMarketInfo = (chainId2) => {
|
|
11177
|
-
const marketId2 = Market[chainId2].marketId;
|
|
11178
|
-
return marketId2;
|
|
11179
|
-
};
|
|
11180
11340
|
var getMarketPoolId = async ({
|
|
11181
|
-
chainId
|
|
11182
|
-
baseToken
|
|
11341
|
+
chainId,
|
|
11342
|
+
baseToken,
|
|
11343
|
+
marketId
|
|
11183
11344
|
}) => {
|
|
11184
11345
|
try {
|
|
11185
|
-
const marketId2 = getMarketInfo(chainId2);
|
|
11186
11346
|
if (!baseToken) {
|
|
11187
11347
|
throw new Error(Errors[2 /* Invalid_TOKEN_ADDRESS */]);
|
|
11188
11348
|
}
|
|
11189
|
-
const chainInfo = CHAIN_INFO[
|
|
11190
|
-
const addresses = address_default[
|
|
11349
|
+
const chainInfo = CHAIN_INFO[chainId];
|
|
11350
|
+
const addresses = address_default[chainId];
|
|
11191
11351
|
const address = addresses.POOL_MANAGER;
|
|
11192
|
-
const contract = await getPoolManagerContract(
|
|
11193
|
-
const data = [
|
|
11194
|
-
const request = await contract.getMarketPool(
|
|
11352
|
+
const contract = await getPoolManagerContract(chainId, 0 /* JSON */);
|
|
11353
|
+
const data = [marketId, baseToken];
|
|
11354
|
+
const request = await contract.getMarketPool(marketId, baseToken);
|
|
11195
11355
|
return request.poolId === "0x0000000000000000000000000000000000000000000000000000000000000000" || !request.poolId ? void 0 : request.poolId;
|
|
11196
11356
|
} catch (error) {
|
|
11197
11357
|
console.error(error);
|
|
11198
11358
|
throw typeof error === "string" ? error : await getErrorTextFormError(error);
|
|
11199
11359
|
}
|
|
11200
11360
|
};
|
|
11201
|
-
var getMarketPools = async (
|
|
11361
|
+
var getMarketPools = async (chainId) => {
|
|
11202
11362
|
try {
|
|
11203
|
-
const contract = await getPoolManagerContract(
|
|
11363
|
+
const contract = await getPoolManagerContract(chainId);
|
|
11204
11364
|
const request = await contract.getPools();
|
|
11205
11365
|
console.log(request);
|
|
11206
11366
|
return request || [];
|
|
@@ -11209,9 +11369,9 @@ var getMarketPools = async (chainId2) => {
|
|
|
11209
11369
|
throw typeof error === "string" ? error : await getErrorTextFormError(error);
|
|
11210
11370
|
}
|
|
11211
11371
|
};
|
|
11212
|
-
var getPoolInfo2 = async (
|
|
11372
|
+
var getPoolInfo2 = async (chainId, poolId, marketPrice = 0n) => {
|
|
11213
11373
|
try {
|
|
11214
|
-
const contract = await getDataProviderContract(
|
|
11374
|
+
const contract = await getDataProviderContract(chainId);
|
|
11215
11375
|
const request = await contract.getPoolInfo(poolId, marketPrice);
|
|
11216
11376
|
const info = {
|
|
11217
11377
|
quotePool: {
|
|
@@ -11253,20 +11413,18 @@ var getPoolInfo2 = async (chainId2, poolId, marketPrice = 0n) => {
|
|
|
11253
11413
|
};
|
|
11254
11414
|
|
|
11255
11415
|
// src/lp/pool/create.ts
|
|
11256
|
-
var
|
|
11257
|
-
var marketId = Market[chainId].marketId;
|
|
11258
|
-
var createPool = async ({ chainId: chainId2, baseToken }) => {
|
|
11416
|
+
var createPool = async ({ chainId, baseToken, marketId }) => {
|
|
11259
11417
|
try {
|
|
11260
11418
|
if (!baseToken) {
|
|
11261
11419
|
throw new Error(Errors[2 /* Invalid_TOKEN_ADDRESS */]);
|
|
11262
11420
|
}
|
|
11263
|
-
const chainInfo = CHAIN_INFO[
|
|
11264
|
-
const contract = await getPoolManagerContract(
|
|
11421
|
+
const chainInfo = CHAIN_INFO[chainId];
|
|
11422
|
+
const contract = await getPoolManagerContract(chainId);
|
|
11265
11423
|
const data = { marketId, baseToken };
|
|
11266
11424
|
const _gasLimit = await contract.deployPool.estimateGas(data);
|
|
11267
11425
|
const gasLimit = bigintTradingGasToRatioCalculator(_gasLimit, chainInfo.gasLimitRatio);
|
|
11268
11426
|
console.log("gasLimit", _gasLimit, gasLimit);
|
|
11269
|
-
const { gasPrice } = await bigintTradingGasPriceWithRatio(
|
|
11427
|
+
const { gasPrice } = await bigintTradingGasPriceWithRatio(chainId);
|
|
11270
11428
|
console.log("gasPrice", gasPrice);
|
|
11271
11429
|
const request = await contract.deployPool(data, {
|
|
11272
11430
|
gasLimit,
|
|
@@ -11274,7 +11432,7 @@ var createPool = async ({ chainId: chainId2, baseToken }) => {
|
|
|
11274
11432
|
});
|
|
11275
11433
|
const receipt = await request?.wait();
|
|
11276
11434
|
if (receipt?.hash) {
|
|
11277
|
-
const poolId = await getMarketPoolId({ chainId
|
|
11435
|
+
const poolId = await getMarketPoolId({ chainId, baseToken, marketId });
|
|
11278
11436
|
return poolId;
|
|
11279
11437
|
}
|
|
11280
11438
|
} catch (error) {
|
|
@@ -11284,9 +11442,9 @@ var createPool = async ({ chainId: chainId2, baseToken }) => {
|
|
|
11284
11442
|
};
|
|
11285
11443
|
|
|
11286
11444
|
// src/lp/pool/getUserGenesisShare.ts
|
|
11287
|
-
var getUserGenesisShare = async (
|
|
11445
|
+
var getUserGenesisShare = async (chainId, tokenAddress, account) => {
|
|
11288
11446
|
try {
|
|
11289
|
-
const contract = await getPoolTokenContract(
|
|
11447
|
+
const contract = await getPoolTokenContract(chainId, tokenAddress);
|
|
11290
11448
|
const request = await contract.userGenesisShare(account);
|
|
11291
11449
|
return request;
|
|
11292
11450
|
} catch (error) {
|
|
@@ -11298,17 +11456,17 @@ var getUserGenesisShare = async (chainId2, tokenAddress, account) => {
|
|
|
11298
11456
|
// src/lp/pool/addTpSl.ts
|
|
11299
11457
|
var addTpSl = async (params) => {
|
|
11300
11458
|
try {
|
|
11301
|
-
const { chainId
|
|
11459
|
+
const { chainId, poolId, poolType, slippage = 0.01, tpsl = [] } = params;
|
|
11302
11460
|
await checkParams(params);
|
|
11303
|
-
const pool = await getPoolInfo(
|
|
11461
|
+
const pool = await getPoolInfo(chainId, poolId);
|
|
11304
11462
|
if (!pool) {
|
|
11305
11463
|
throw new Error(Errors[4006 /* Invalid_Params */]);
|
|
11306
11464
|
}
|
|
11307
|
-
const decimals =
|
|
11465
|
+
const decimals = COMMON_LP_AMOUNT_DECIMALS;
|
|
11308
11466
|
const quoteDecimals = pool.quoteDecimals;
|
|
11309
11467
|
const tpslParams = getTpSlParams(slippage, tpsl, decimals, quoteDecimals);
|
|
11310
|
-
const chainInfo = CHAIN_INFO[
|
|
11311
|
-
const contract = await getLiquidityRouterContract(
|
|
11468
|
+
const chainInfo = CHAIN_INFO[chainId];
|
|
11469
|
+
const contract = await getLiquidityRouterContract(chainId);
|
|
11312
11470
|
const data = {
|
|
11313
11471
|
poolId,
|
|
11314
11472
|
poolType: BigInt(poolType),
|
|
@@ -11316,7 +11474,7 @@ var addTpSl = async (params) => {
|
|
|
11316
11474
|
};
|
|
11317
11475
|
const _gasLimit = await contract.addTpsl.estimateGas(data);
|
|
11318
11476
|
const gasLimit = bigintTradingGasToRatioCalculator(_gasLimit, chainInfo.gasLimitRatio);
|
|
11319
|
-
const { gasPrice } = await bigintTradingGasPriceWithRatio(
|
|
11477
|
+
const { gasPrice } = await bigintTradingGasPriceWithRatio(chainId);
|
|
11320
11478
|
const request = await contract.addTpsl(data, {
|
|
11321
11479
|
gasLimit,
|
|
11322
11480
|
gasPrice
|
|
@@ -11332,13 +11490,13 @@ var addTpSl = async (params) => {
|
|
|
11332
11490
|
// src/lp/pool/cancel.ts
|
|
11333
11491
|
var cancelTpSl = async (params) => {
|
|
11334
11492
|
try {
|
|
11335
|
-
const { chainId
|
|
11493
|
+
const { chainId, orderId } = params;
|
|
11336
11494
|
await checkParams(params);
|
|
11337
|
-
const chainInfo = CHAIN_INFO[
|
|
11338
|
-
const contract = await getLiquidityRouterContract(
|
|
11495
|
+
const chainInfo = CHAIN_INFO[chainId];
|
|
11496
|
+
const contract = await getLiquidityRouterContract(chainId);
|
|
11339
11497
|
const _gasLimit = await contract.cancelTpsl.estimateGas(orderId);
|
|
11340
11498
|
const gasLimit = bigintTradingGasToRatioCalculator(_gasLimit, chainInfo.gasLimitRatio);
|
|
11341
|
-
const { gasPrice } = await bigintTradingGasPriceWithRatio(
|
|
11499
|
+
const { gasPrice } = await bigintTradingGasPriceWithRatio(chainId);
|
|
11342
11500
|
const request = await contract.cancelTpsl(orderId, {
|
|
11343
11501
|
gasLimit,
|
|
11344
11502
|
gasPrice
|
|
@@ -11352,7 +11510,7 @@ var cancelTpSl = async (params) => {
|
|
|
11352
11510
|
};
|
|
11353
11511
|
|
|
11354
11512
|
// src/common/tokenInfo.ts
|
|
11355
|
-
var
|
|
11513
|
+
var import_ethers20 = require("ethers");
|
|
11356
11514
|
async function checkImageExists(url) {
|
|
11357
11515
|
try {
|
|
11358
11516
|
const res = await fetch(url, { method: "HEAD" });
|
|
@@ -11361,9 +11519,9 @@ async function checkImageExists(url) {
|
|
|
11361
11519
|
return false;
|
|
11362
11520
|
}
|
|
11363
11521
|
}
|
|
11364
|
-
var getTokenInfo = async (
|
|
11522
|
+
var getTokenInfo = async (chainId, tokenAddress, account) => {
|
|
11365
11523
|
try {
|
|
11366
|
-
const token = await getTokenContract(
|
|
11524
|
+
const token = await getTokenContract(chainId, tokenAddress);
|
|
11367
11525
|
const _name = await token.name();
|
|
11368
11526
|
console.log(_name);
|
|
11369
11527
|
const [name, symbol, decimals, totalSupply] = await Promise.all([
|
|
@@ -11372,14 +11530,14 @@ var getTokenInfo = async (chainId2, tokenAddress, account) => {
|
|
|
11372
11530
|
token.decimals(),
|
|
11373
11531
|
token.totalSupply()
|
|
11374
11532
|
]);
|
|
11375
|
-
const normalized =
|
|
11376
|
-
const iconUrl = `https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/${
|
|
11533
|
+
const normalized = import_ethers20.ethers.getAddress(tokenAddress);
|
|
11534
|
+
const iconUrl = `https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/${chainId}/assets/${normalized}/logo.png`;
|
|
11377
11535
|
const fallbackIcon = "";
|
|
11378
11536
|
const icon = await checkImageExists(iconUrl) ? iconUrl : fallbackIcon;
|
|
11379
11537
|
let balance;
|
|
11380
11538
|
if (account) {
|
|
11381
11539
|
const rawBalance = await token.balanceOf(account);
|
|
11382
|
-
balance = Number(
|
|
11540
|
+
balance = Number(import_ethers20.ethers.formatUnits(rawBalance, decimals));
|
|
11383
11541
|
}
|
|
11384
11542
|
return {
|
|
11385
11543
|
address: tokenAddress,
|
|
@@ -11387,7 +11545,7 @@ var getTokenInfo = async (chainId2, tokenAddress, account) => {
|
|
|
11387
11545
|
symbol,
|
|
11388
11546
|
decimals,
|
|
11389
11547
|
icon,
|
|
11390
|
-
totalSupply: Number(
|
|
11548
|
+
totalSupply: Number(import_ethers20.ethers.formatUnits(totalSupply, decimals)),
|
|
11391
11549
|
...account ? { balance } : {}
|
|
11392
11550
|
};
|
|
11393
11551
|
} catch (e) {
|
|
@@ -11404,12 +11562,12 @@ __export(market_exports, {
|
|
|
11404
11562
|
});
|
|
11405
11563
|
|
|
11406
11564
|
// src/lp/market/getMarket.ts
|
|
11407
|
-
var getMarket = async (
|
|
11565
|
+
var getMarket = async (chainId, marketId) => {
|
|
11408
11566
|
try {
|
|
11409
|
-
await checkParams({ chainId
|
|
11410
|
-
if (!
|
|
11411
|
-
const contract = await getMarketManageContract(
|
|
11412
|
-
const request = await contract.getMarket(
|
|
11567
|
+
await checkParams({ chainId });
|
|
11568
|
+
if (!marketId) return;
|
|
11569
|
+
const contract = await getMarketManageContract(chainId);
|
|
11570
|
+
const request = await contract.getMarket(marketId);
|
|
11413
11571
|
return request;
|
|
11414
11572
|
} catch (error) {
|
|
11415
11573
|
console.error(error);
|
|
@@ -11418,12 +11576,12 @@ var getMarket = async (chainId2, marketId2) => {
|
|
|
11418
11576
|
};
|
|
11419
11577
|
|
|
11420
11578
|
// src/lp/market/getOracleFee.ts
|
|
11421
|
-
var getOracleFee = async (
|
|
11579
|
+
var getOracleFee = async (chainId, marketId) => {
|
|
11422
11580
|
try {
|
|
11423
|
-
await checkParams({ chainId
|
|
11424
|
-
if (!
|
|
11425
|
-
const contract = await getMarketManageContract(
|
|
11426
|
-
const request = await contract.getOracleFee(
|
|
11581
|
+
await checkParams({ chainId });
|
|
11582
|
+
if (!marketId) return;
|
|
11583
|
+
const contract = await getMarketManageContract(chainId);
|
|
11584
|
+
const request = await contract.getOracleFee(marketId);
|
|
11427
11585
|
return request;
|
|
11428
11586
|
} catch (error) {
|
|
11429
11587
|
console.error(error);
|
|
@@ -11432,33 +11590,32 @@ var getOracleFee = async (chainId2, marketId2) => {
|
|
|
11432
11590
|
};
|
|
11433
11591
|
|
|
11434
11592
|
// src/lp/pool/reprime.ts
|
|
11435
|
-
var
|
|
11436
|
-
var reprime = async (
|
|
11593
|
+
var import_ethers21 = require("ethers");
|
|
11594
|
+
var reprime = async (chainId, poolId, marketId) => {
|
|
11437
11595
|
try {
|
|
11438
|
-
await checkParams({ chainId
|
|
11439
|
-
const pool = await getPoolInfo(
|
|
11596
|
+
await checkParams({ chainId });
|
|
11597
|
+
const pool = await getPoolInfo(chainId, poolId);
|
|
11440
11598
|
if (!pool) {
|
|
11441
11599
|
throw new Error(Errors[4006 /* Invalid_Params */]);
|
|
11442
11600
|
}
|
|
11443
|
-
const
|
|
11444
|
-
const
|
|
11445
|
-
const _amount = await getOracleFee(chainId2, marketId2);
|
|
11601
|
+
const account = await getAccount(chainId);
|
|
11602
|
+
const _amount = await getOracleFee(chainId, marketId);
|
|
11446
11603
|
if (!_amount) {
|
|
11447
11604
|
throw new Error("Invalid Market");
|
|
11448
11605
|
}
|
|
11449
11606
|
await checkParams({
|
|
11450
11607
|
tokenAddress: pool.quoteToken,
|
|
11451
|
-
contractAddress: address_default[
|
|
11608
|
+
contractAddress: address_default[chainId].ORACLE_RESERVE,
|
|
11452
11609
|
decimals: pool.quoteDecimals,
|
|
11453
11610
|
account,
|
|
11454
|
-
chainId
|
|
11455
|
-
amount: Number((0,
|
|
11611
|
+
chainId,
|
|
11612
|
+
amount: Number((0, import_ethers21.formatUnits)(_amount, pool.quoteDecimals))
|
|
11456
11613
|
});
|
|
11457
|
-
const chainInfo = CHAIN_INFO[
|
|
11458
|
-
const contract = await getPoolManagerContract(
|
|
11614
|
+
const chainInfo = CHAIN_INFO[chainId];
|
|
11615
|
+
const contract = await getPoolManagerContract(chainId);
|
|
11459
11616
|
const _gasLimit = await contract.reprimePool.estimateGas({ poolId });
|
|
11460
11617
|
const gasLimit = bigintTradingGasToRatioCalculator(_gasLimit, chainInfo.gasLimitRatio);
|
|
11461
|
-
const { gasPrice } = await bigintTradingGasPriceWithRatio(
|
|
11618
|
+
const { gasPrice } = await bigintTradingGasPriceWithRatio(chainId);
|
|
11462
11619
|
const request = await contract.reprimePool({ poolId });
|
|
11463
11620
|
const receipt = await request?.wait();
|
|
11464
11621
|
return receipt;
|
|
@@ -11469,7 +11626,7 @@ var reprime = async (chainId2, poolId) => {
|
|
|
11469
11626
|
};
|
|
11470
11627
|
|
|
11471
11628
|
// src/lp/pool/orders.ts
|
|
11472
|
-
var getOpenOrders = async (
|
|
11629
|
+
var getOpenOrders = async (chainId) => {
|
|
11473
11630
|
try {
|
|
11474
11631
|
const accessToken = await MxSDK.getInstance().getConfigManager()?.getAccessToken();
|
|
11475
11632
|
if (!accessToken) {
|
|
@@ -11477,7 +11634,7 @@ var getOpenOrders = async (chainId2) => {
|
|
|
11477
11634
|
"Failed to obtain accessToken"
|
|
11478
11635
|
);
|
|
11479
11636
|
}
|
|
11480
|
-
const response = await getPoolOpenOrders(accessToken,
|
|
11637
|
+
const response = await getPoolOpenOrders(accessToken, chainId);
|
|
11481
11638
|
return response.data || [];
|
|
11482
11639
|
} catch (error) {
|
|
11483
11640
|
console.error(error);
|
|
@@ -11498,7 +11655,7 @@ var TriggerType = /* @__PURE__ */ ((TriggerType3) => {
|
|
|
11498
11655
|
})(TriggerType || {});
|
|
11499
11656
|
|
|
11500
11657
|
// src/lp/index.ts
|
|
11501
|
-
var
|
|
11658
|
+
var import_ethers22 = require("ethers");
|
|
11502
11659
|
|
|
11503
11660
|
// src/manager/subscription/websocket/socket.ts
|
|
11504
11661
|
var import_mitt = __toESM(require("mitt"));
|
|
@@ -12301,18 +12458,18 @@ var ConfigManager = class {
|
|
|
12301
12458
|
this.validateConfig(this.config);
|
|
12302
12459
|
}
|
|
12303
12460
|
validateConfig(config) {
|
|
12304
|
-
const { isTestnet, chainId
|
|
12461
|
+
const { isTestnet, chainId } = config;
|
|
12305
12462
|
if (isTestnet) {
|
|
12306
|
-
if (!TESTNET_CHAIN_IDS.includes(
|
|
12463
|
+
if (!TESTNET_CHAIN_IDS.includes(chainId))
|
|
12307
12464
|
throw new MyxSDKError(
|
|
12308
12465
|
"INVALID_CHAIN_ID" /* InvalidChainId */,
|
|
12309
|
-
`chainId ${
|
|
12466
|
+
`chainId ${chainId} is not in the range of TESTNET_CHAIN_IDS`
|
|
12310
12467
|
);
|
|
12311
12468
|
} else {
|
|
12312
|
-
if (!MAINNET_CHAIN_IDS.includes(
|
|
12469
|
+
if (!MAINNET_CHAIN_IDS.includes(chainId))
|
|
12313
12470
|
throw new MyxSDKError(
|
|
12314
12471
|
"INVALID_CHAIN_ID" /* InvalidChainId */,
|
|
12315
|
-
`chainId ${
|
|
12472
|
+
`chainId ${chainId} is not in the range of MAINNET_CHAIN_IDS`
|
|
12316
12473
|
);
|
|
12317
12474
|
}
|
|
12318
12475
|
}
|
|
@@ -12559,18 +12716,42 @@ var Markets = class {
|
|
|
12559
12716
|
}
|
|
12560
12717
|
};
|
|
12561
12718
|
|
|
12719
|
+
// src/config/address/LINEA_SEPOLIA.ts
|
|
12720
|
+
var LINEA_SEPOLIA = {
|
|
12721
|
+
POOL_MANAGER: "0x7507Ec88C6fcd0c6ebE421988b5ACc052422be2b",
|
|
12722
|
+
Account: "0x05C39d54Ac84f5225218D4E03Ee6aE2999a47a03",
|
|
12723
|
+
POSITION_MANAGER: "0xD7090F7CD1D65e83feB74dCF1c2fcBA4854a934b",
|
|
12724
|
+
ORDER_MANAGER: "0x50602673C3506AFF2e7Df82dB6E93B6B134331Ae",
|
|
12725
|
+
PYTH: "0xA2aa501b19aff244D90cc15a4Cf739D2725B5729",
|
|
12726
|
+
// !!! 非Pyth Adapter
|
|
12727
|
+
ERC20: "0x635eC74A4A39A27177310F0d605515D9df4bDe43",
|
|
12728
|
+
LIQUIDITY_ROUTER: "0x7fa9B7C0D95E19f180A2bf359d980c0bD3aC2503",
|
|
12729
|
+
BASE_POOL: "0x6d3A2AB082388C35319007a2D635Cf7A8B8aF0E1",
|
|
12730
|
+
QUOTE_POOL: "0x5A6fdFD381B76eD163b60300E619F7EB6049e7bD",
|
|
12731
|
+
BROKER: "0x0C6358400a8d86d8377640B1B783b8326b7D0fdc",
|
|
12732
|
+
// MYXBroker
|
|
12733
|
+
ORACLE: "0xfbA4a141bb3BbD0EB34b24152caa3d2940629545",
|
|
12734
|
+
// MYXOracle
|
|
12735
|
+
EIP7702Delegation: "0xa55149B66A7fC4a4eF05c8da981E46Fe27695E6c",
|
|
12736
|
+
MARKET_MANAGER: "0x96Dd73d94c7359e92a45Ff75bC90909E66332990",
|
|
12737
|
+
DATA_PROVIDER: "0xF10B5736EA756488139135BF14aE5A542de435a9",
|
|
12738
|
+
ORACLE_RESERVE: "0xb9433C0e23f38E8Ad48B9A6e562F0a543e06a9F4"
|
|
12739
|
+
};
|
|
12740
|
+
|
|
12562
12741
|
// src/config/address/index.ts
|
|
12563
|
-
var getContractAddressByChainId = (
|
|
12564
|
-
switch (
|
|
12742
|
+
var getContractAddressByChainId = (chainId) => {
|
|
12743
|
+
switch (chainId) {
|
|
12565
12744
|
case 421614 /* ARB_TESTNET */:
|
|
12566
12745
|
return ARB_TEST_SEPOLIA;
|
|
12746
|
+
case 59141 /* LINEA_SEPOLIA */:
|
|
12747
|
+
return LINEA_SEPOLIA;
|
|
12567
12748
|
default:
|
|
12568
12749
|
return {};
|
|
12569
12750
|
}
|
|
12570
12751
|
};
|
|
12571
12752
|
|
|
12572
12753
|
// src/manager/position/index.ts
|
|
12573
|
-
var
|
|
12754
|
+
var import_ethers23 = require("ethers");
|
|
12574
12755
|
var Position = class {
|
|
12575
12756
|
constructor(configManager, logger, utils) {
|
|
12576
12757
|
this.configManager = configManager;
|
|
@@ -12759,7 +12940,7 @@ var Position = class {
|
|
|
12759
12940
|
}
|
|
12760
12941
|
const updateParams = {
|
|
12761
12942
|
poolId,
|
|
12762
|
-
referencePrice:
|
|
12943
|
+
referencePrice: import_ethers23.ethers.parseUnits(priceData?.price ?? "0", 30),
|
|
12763
12944
|
oracleUpdateData: priceData?.vaa ?? "0",
|
|
12764
12945
|
publishTime: priceData.publishTime,
|
|
12765
12946
|
oracleType: poolOracleType
|
|
@@ -12782,12 +12963,12 @@ var Position = class {
|
|
|
12782
12963
|
if (needsApproval) {
|
|
12783
12964
|
this.logger.debug("adjust collateral approve-->", {
|
|
12784
12965
|
quoteToken,
|
|
12785
|
-
amount:
|
|
12966
|
+
amount: import_ethers23.ethers.MaxUint256.toString(),
|
|
12786
12967
|
spenderAddress: contractAddress.POSITION_MANAGER
|
|
12787
12968
|
});
|
|
12788
12969
|
const approvalResult = await this.utils.approveAuthorization({
|
|
12789
12970
|
quoteAddress: quoteToken,
|
|
12790
|
-
amount:
|
|
12971
|
+
amount: import_ethers23.ethers.MaxUint256.toString(),
|
|
12791
12972
|
spenderAddress: contractAddress.POSITION_MANAGER
|
|
12792
12973
|
});
|
|
12793
12974
|
if (approvalResult.code !== 0) {
|
|
@@ -12891,7 +13072,7 @@ var OrderStatus = {
|
|
|
12891
13072
|
};
|
|
12892
13073
|
|
|
12893
13074
|
// src/manager/order/index.ts
|
|
12894
|
-
var
|
|
13075
|
+
var import_ethers24 = require("ethers");
|
|
12895
13076
|
var import_viem = require("viem");
|
|
12896
13077
|
var Order = class {
|
|
12897
13078
|
constructor(configManager, logger, utils) {
|
|
@@ -12906,7 +13087,7 @@ var Order = class {
|
|
|
12906
13087
|
direction,
|
|
12907
13088
|
salt
|
|
12908
13089
|
]);
|
|
12909
|
-
return (0,
|
|
13090
|
+
return (0, import_ethers24.keccak256)(encoded);
|
|
12910
13091
|
}
|
|
12911
13092
|
async createIncreaseOrder(params) {
|
|
12912
13093
|
try {
|
|
@@ -12928,7 +13109,7 @@ var Order = class {
|
|
|
12928
13109
|
if (needsApproval) {
|
|
12929
13110
|
const approvalResult = await this.utils.approveAuthorization({
|
|
12930
13111
|
quoteAddress: params.executionFeeToken,
|
|
12931
|
-
amount:
|
|
13112
|
+
amount: import_ethers24.ethers.MaxUint256.toString()
|
|
12932
13113
|
});
|
|
12933
13114
|
if (approvalResult.code !== 0) {
|
|
12934
13115
|
throw new Error(approvalResult.message);
|
|
@@ -13589,7 +13770,7 @@ var Order = class {
|
|
|
13589
13770
|
};
|
|
13590
13771
|
|
|
13591
13772
|
// src/manager/utils/index.ts
|
|
13592
|
-
var
|
|
13773
|
+
var import_ethers25 = require("ethers");
|
|
13593
13774
|
|
|
13594
13775
|
// src/abi/Emiter.json
|
|
13595
13776
|
var Emiter_default = [
|
|
@@ -17271,7 +17452,7 @@ var Utils = class {
|
|
|
17271
17452
|
if (!receipt || !receipt.logs) {
|
|
17272
17453
|
return null;
|
|
17273
17454
|
}
|
|
17274
|
-
const emiterInterface = new
|
|
17455
|
+
const emiterInterface = new import_ethers25.ethers.Interface(Emiter_default);
|
|
17275
17456
|
const orderPlacedEvent = Emiter_default.find(
|
|
17276
17457
|
(item) => item.type === "event" && item.name === "OrderPlaced"
|
|
17277
17458
|
);
|
|
@@ -17279,7 +17460,7 @@ var Utils = class {
|
|
|
17279
17460
|
this.logger.error("OrderPlaced event not found in Emiter ABI");
|
|
17280
17461
|
return null;
|
|
17281
17462
|
}
|
|
17282
|
-
const eventTopic =
|
|
17463
|
+
const eventTopic = import_ethers25.ethers.id(
|
|
17283
17464
|
"OrderPlaced(address,address,bytes32,uint256,uint256,uint8,uint8,uint8,uint8,uint256,uint256,uint256,uint8,bool,uint16,address,uint256,uint16)"
|
|
17284
17465
|
);
|
|
17285
17466
|
this.logger.info("Looking for OrderPlaced events with topic:", eventTopic);
|
|
@@ -17329,7 +17510,7 @@ var Utils = class {
|
|
|
17329
17510
|
}
|
|
17330
17511
|
const owner = await config.signer.getAddress();
|
|
17331
17512
|
const spender = spenderAddress ?? getContractAddressByChainId(config.chainId).ORDER_MANAGER;
|
|
17332
|
-
const tokenContract = new
|
|
17513
|
+
const tokenContract = new import_ethers25.ethers.Contract(
|
|
17333
17514
|
quoteAddress,
|
|
17334
17515
|
erc20Abi,
|
|
17335
17516
|
config.signer
|
|
@@ -17351,8 +17532,8 @@ var Utils = class {
|
|
|
17351
17532
|
spenderAddress
|
|
17352
17533
|
);
|
|
17353
17534
|
const currentAllowance = currentAllowanceRes.data;
|
|
17354
|
-
const allowanceBigInt =
|
|
17355
|
-
const requiredBigInt =
|
|
17535
|
+
const allowanceBigInt = import_ethers25.ethers.getBigInt(currentAllowance);
|
|
17536
|
+
const requiredBigInt = import_ethers25.ethers.getBigInt(requiredAmount);
|
|
17356
17537
|
const needsApproval = allowanceBigInt < requiredBigInt;
|
|
17357
17538
|
return needsApproval;
|
|
17358
17539
|
} catch (error) {
|
|
@@ -17370,12 +17551,12 @@ var Utils = class {
|
|
|
17370
17551
|
"function approve(address spender, uint256 amount) external returns (bool)"
|
|
17371
17552
|
];
|
|
17372
17553
|
const config = this.configManager.getConfig();
|
|
17373
|
-
const usdcContract = new
|
|
17554
|
+
const usdcContract = new import_ethers25.ethers.Contract(
|
|
17374
17555
|
quoteAddress,
|
|
17375
17556
|
erc20Abi,
|
|
17376
17557
|
config.signer
|
|
17377
17558
|
);
|
|
17378
|
-
const approveAmount = amount ??
|
|
17559
|
+
const approveAmount = amount ?? import_ethers25.ethers.MaxUint256;
|
|
17379
17560
|
const spender = spenderAddress ?? getContractAddressByChainId(config.chainId).ORDER_MANAGER;
|
|
17380
17561
|
const tx = await usdcContract.approve(spender, approveAmount);
|
|
17381
17562
|
await tx.wait();
|
|
@@ -17395,7 +17576,7 @@ var Utils = class {
|
|
|
17395
17576
|
async getUserTradingFeeRate(assetClass) {
|
|
17396
17577
|
const config = this.configManager.getConfig();
|
|
17397
17578
|
const brokerAddress = config.brokerAddress;
|
|
17398
|
-
const brokerContract = new
|
|
17579
|
+
const brokerContract = new import_ethers25.ethers.Contract(
|
|
17399
17580
|
brokerAddress,
|
|
17400
17581
|
Broker_default,
|
|
17401
17582
|
config.signer
|
|
@@ -17428,7 +17609,7 @@ var Utils = class {
|
|
|
17428
17609
|
const orderManagerAddress = getContractAddressByChainId(
|
|
17429
17610
|
config.chainId
|
|
17430
17611
|
).ORDER_MANAGER;
|
|
17431
|
-
const orderManagerContract = new
|
|
17612
|
+
const orderManagerContract = new import_ethers25.ethers.Contract(
|
|
17432
17613
|
orderManagerAddress,
|
|
17433
17614
|
OrderManager_default,
|
|
17434
17615
|
config.signer
|
|
@@ -17508,7 +17689,7 @@ var Utils = class {
|
|
|
17508
17689
|
};
|
|
17509
17690
|
|
|
17510
17691
|
// src/manager/account/index.ts
|
|
17511
|
-
var
|
|
17692
|
+
var import_ethers26 = require("ethers");
|
|
17512
17693
|
|
|
17513
17694
|
// src/abi/Account.json
|
|
17514
17695
|
var Account_default = [
|
|
@@ -18675,7 +18856,7 @@ var Account = class {
|
|
|
18675
18856
|
);
|
|
18676
18857
|
}
|
|
18677
18858
|
const contractAddress = getContractAddressByChainId(config.chainId);
|
|
18678
|
-
const erc20Contract = new
|
|
18859
|
+
const erc20Contract = new import_ethers26.ethers.Contract(
|
|
18679
18860
|
contractAddress.ERC20,
|
|
18680
18861
|
ERC20Token_default,
|
|
18681
18862
|
config.signer
|
|
@@ -18698,7 +18879,7 @@ var Account = class {
|
|
|
18698
18879
|
);
|
|
18699
18880
|
}
|
|
18700
18881
|
const contractAddress = getContractAddressByChainId(config.chainId);
|
|
18701
|
-
const accountContract = new
|
|
18882
|
+
const accountContract = new import_ethers26.ethers.Contract(
|
|
18702
18883
|
contractAddress.Account,
|
|
18703
18884
|
Account_default,
|
|
18704
18885
|
config.signer
|
|
@@ -18737,7 +18918,7 @@ var Account = class {
|
|
|
18737
18918
|
async withdraw({ poolId, amount }) {
|
|
18738
18919
|
const config = this.configManager.getConfig();
|
|
18739
18920
|
const contractAddress = getContractAddressByChainId(config.chainId);
|
|
18740
|
-
const accountContract = new
|
|
18921
|
+
const accountContract = new import_ethers26.ethers.Contract(
|
|
18741
18922
|
contractAddress.Account,
|
|
18742
18923
|
Account_default,
|
|
18743
18924
|
config.signer
|
|
@@ -18763,7 +18944,7 @@ var Account = class {
|
|
|
18763
18944
|
const account = await config.signer?.getAddress() ?? "";
|
|
18764
18945
|
console.log("deposit", account, poolId, amount);
|
|
18765
18946
|
const contractAddress = getContractAddressByChainId(config.chainId);
|
|
18766
|
-
const accountContract = new
|
|
18947
|
+
const accountContract = new import_ethers26.ethers.Contract(
|
|
18767
18948
|
contractAddress.Account,
|
|
18768
18949
|
Account_default,
|
|
18769
18950
|
config.signer
|
|
@@ -18777,7 +18958,7 @@ var Account = class {
|
|
|
18777
18958
|
if (needApproval) {
|
|
18778
18959
|
const approvalResult = await this.utils.approveAuthorization({
|
|
18779
18960
|
quoteAddress: tokenAddress,
|
|
18780
|
-
amount:
|
|
18961
|
+
amount: import_ethers26.ethers.MaxUint256.toString(),
|
|
18781
18962
|
spenderAddress: contractAddress.Account
|
|
18782
18963
|
});
|
|
18783
18964
|
if (approvalResult.code !== 0) {
|
|
@@ -18852,7 +19033,6 @@ var MyxClient = class {
|
|
|
18852
19033
|
ErrorCode,
|
|
18853
19034
|
ExecTypeEnum,
|
|
18854
19035
|
HttpKlineIntervalEnum,
|
|
18855
|
-
Market,
|
|
18856
19036
|
MarketCapType,
|
|
18857
19037
|
MarketPoolState,
|
|
18858
19038
|
MarketType,
|
|
@@ -18886,6 +19066,7 @@ var MyxClient = class {
|
|
|
18886
19066
|
getKlineData,
|
|
18887
19067
|
getKlineLatestBar,
|
|
18888
19068
|
getMarketDetail,
|
|
19069
|
+
getMarketList,
|
|
18889
19070
|
getOraclePrice,
|
|
18890
19071
|
getOrders,
|
|
18891
19072
|
getPoolDetail,
|