@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.mjs
CHANGED
|
@@ -1368,37 +1368,25 @@ var ChainId = /* @__PURE__ */ ((ChainId3) => {
|
|
|
1368
1368
|
ChainId3[ChainId3["BSC_MAINNET"] = 56] = "BSC_MAINNET";
|
|
1369
1369
|
return ChainId3;
|
|
1370
1370
|
})(ChainId || {});
|
|
1371
|
-
var SupportedChainIds = [421614 /* ARB_TESTNET */];
|
|
1372
|
-
function isSupportedChainFn(
|
|
1373
|
-
return !!
|
|
1371
|
+
var SupportedChainIds = [421614 /* ARB_TESTNET */, 59141 /* LINEA_SEPOLIA */];
|
|
1372
|
+
function isSupportedChainFn(chainId) {
|
|
1373
|
+
return !!chainId && SupportedChainIds.includes(chainId);
|
|
1374
1374
|
}
|
|
1375
1375
|
|
|
1376
1376
|
// src/config/address/ARB_TEST_SEPOLIA.ts
|
|
1377
|
-
import { ZeroAddress } from "ethers";
|
|
1378
1377
|
var ARB_TEST_SEPOLIA = {
|
|
1379
|
-
USDC: "0x7E248Ec1721639413A280d9E82e2862Cae2E6E28",
|
|
1380
1378
|
POOL_MANAGER: "0xA4A1dfbe40cB725A79D34bd529f0C1b54AB46954",
|
|
1381
1379
|
Account: "0x6136899e8c77C452bc46AcD786aA2C09fD31f947",
|
|
1382
|
-
POOL_VIEW: "",
|
|
1383
|
-
HYPER_VAULT: ZeroAddress,
|
|
1384
|
-
FEE_COLLECTOR: "",
|
|
1385
1380
|
POSITION_MANAGER: "0x002F28be205E9A1e279d2eeF1f5e472CeA1d910C",
|
|
1386
|
-
ORDER_MANAGER: "
|
|
1387
|
-
|
|
1388
|
-
FRONT_FACET: "",
|
|
1389
|
-
// router address
|
|
1390
|
-
DELEGATE_FACET: "",
|
|
1391
|
-
// Seamless router address
|
|
1392
|
-
FAUCET: "",
|
|
1393
|
-
UI_POOL_DATA_PROVIDER: "",
|
|
1394
|
-
UI_POSITION_DATA_PROVIDER: "",
|
|
1395
|
-
PYTH: "0x361360Def495BfB4F0BE59AB11878D042c458155",
|
|
1381
|
+
ORDER_MANAGER: "0x4eDe4E20162551F293B9D6f33E8567314fb5612f",
|
|
1382
|
+
PYTH: "0x4374e5a8b9C22271E9EB878A2AA31DE97DF15DAF",
|
|
1396
1383
|
// !!! 非Pyth Adapter
|
|
1397
|
-
MYX: ZeroAddress,
|
|
1398
1384
|
ERC20: "0x7E248Ec1721639413A280d9E82e2862Cae2E6E28",
|
|
1399
1385
|
LIQUIDITY_ROUTER: "0xd185C3f675d991735FCF6885Ff6BADE02A21313d",
|
|
1400
1386
|
BASE_POOL: "0x2c6AdaE4A01836487842b7369c1db3F441871E83",
|
|
1401
1387
|
QUOTE_POOL: "0xe1Ff495206635570A8Eaf9517125Ce66a2d09d32",
|
|
1388
|
+
BROKER: "0xB3DaeFF433c005e214D6cd73C35cD4bBCe7f94fD",
|
|
1389
|
+
// MYXBroker
|
|
1402
1390
|
ORACLE: "0x574001F6cB520b15d5a6db9F7B7a0ebf1A8E25c0",
|
|
1403
1391
|
// MYXOracle
|
|
1404
1392
|
EIP7702Delegation: "0x4e1B9aDf5Aa4a893f578c8502E6E28841b2403f3",
|
|
@@ -1418,7 +1406,7 @@ import {
|
|
|
1418
1406
|
Contract,
|
|
1419
1407
|
ethers,
|
|
1420
1408
|
JsonRpcProvider,
|
|
1421
|
-
ZeroAddress
|
|
1409
|
+
ZeroAddress
|
|
1422
1410
|
} from "ethers";
|
|
1423
1411
|
|
|
1424
1412
|
// src/address.ts
|
|
@@ -1629,10 +1617,10 @@ var CHAIN_INFO = {
|
|
|
1629
1617
|
[42161 /* ARB_MAINNET */]: ARB_MAINNET_default.chainInfo,
|
|
1630
1618
|
[56 /* BSC_MAINNET */]: BSC_MAINNET_default.chainInfo
|
|
1631
1619
|
};
|
|
1632
|
-
function getChainInfo(
|
|
1633
|
-
const chainInfo = CHAIN_INFO[
|
|
1620
|
+
function getChainInfo(chainId) {
|
|
1621
|
+
const chainInfo = CHAIN_INFO[chainId];
|
|
1634
1622
|
if (!chainInfo) {
|
|
1635
|
-
throw new Error(`Could not find information with chain id ${
|
|
1623
|
+
throw new Error(`Could not find information with chain id ${chainId}`);
|
|
1636
1624
|
}
|
|
1637
1625
|
return chainInfo;
|
|
1638
1626
|
}
|
|
@@ -1668,15 +1656,15 @@ function checkNetworks(networks) {
|
|
|
1668
1656
|
return result;
|
|
1669
1657
|
}
|
|
1670
1658
|
var RotationProvider = class extends BaseProvider {
|
|
1671
|
-
constructor(urls,
|
|
1672
|
-
super(
|
|
1659
|
+
constructor(urls, chainId, config) {
|
|
1660
|
+
super(chainId);
|
|
1673
1661
|
this.currentProviderIndex = 0;
|
|
1674
1662
|
this.firstRotationTimestamp = 0;
|
|
1675
1663
|
// number of full loops through provider array before throwing an error
|
|
1676
1664
|
this.maxRetries = 0;
|
|
1677
1665
|
this.retries = 0;
|
|
1678
1666
|
this.lastError = "";
|
|
1679
|
-
this.providers = urls.map((url) => new StaticJsonRpcProvider(url,
|
|
1667
|
+
this.providers = urls.map((url) => new StaticJsonRpcProvider(url, chainId));
|
|
1680
1668
|
this.maxRetries = config?.maxRetries || MAX_RETRIES;
|
|
1681
1669
|
this.fallForwardDelay = config?.fallFowardDelay || DEFAULT_FALL_FORWARD_DELAY;
|
|
1682
1670
|
}
|
|
@@ -1740,7 +1728,7 @@ var RotationProvider = class extends BaseProvider {
|
|
|
1740
1728
|
// package.json
|
|
1741
1729
|
var package_default = {
|
|
1742
1730
|
name: "@myx-trade/sdk",
|
|
1743
|
-
version: "0.1.
|
|
1731
|
+
version: "0.1.38",
|
|
1744
1732
|
private: false,
|
|
1745
1733
|
publishConfig: {
|
|
1746
1734
|
access: "public"
|
|
@@ -1813,15 +1801,407 @@ var package_default = {
|
|
|
1813
1801
|
}
|
|
1814
1802
|
};
|
|
1815
1803
|
|
|
1804
|
+
// src/api/request.ts
|
|
1805
|
+
import wretch from "wretch";
|
|
1806
|
+
var client = wretch();
|
|
1807
|
+
var buildQueryOptions = (url, params) => {
|
|
1808
|
+
if (params) {
|
|
1809
|
+
params = JSON.parse(JSON.stringify(params));
|
|
1810
|
+
if (url.includes("?")) {
|
|
1811
|
+
return url + "&" + new URLSearchParams(params).toString();
|
|
1812
|
+
}
|
|
1813
|
+
return url + "?" + new URLSearchParams(params).toString();
|
|
1814
|
+
}
|
|
1815
|
+
return url;
|
|
1816
|
+
};
|
|
1817
|
+
var http = {
|
|
1818
|
+
/**
|
|
1819
|
+
* Get request
|
|
1820
|
+
*/
|
|
1821
|
+
get: (url, params, options = {}) => {
|
|
1822
|
+
const requestUrl = buildQueryOptions(url, params);
|
|
1823
|
+
return client.url(requestUrl).options(options).get().json();
|
|
1824
|
+
},
|
|
1825
|
+
/**
|
|
1826
|
+
* Post request
|
|
1827
|
+
*/
|
|
1828
|
+
post: (url, data, options = {}) => {
|
|
1829
|
+
return client.url(url).options(options).post(data).json();
|
|
1830
|
+
},
|
|
1831
|
+
/**
|
|
1832
|
+
* Put request
|
|
1833
|
+
*/
|
|
1834
|
+
put: (url, data, options = {}) => {
|
|
1835
|
+
return client.url(url).options(options).put(data).json();
|
|
1836
|
+
},
|
|
1837
|
+
/**
|
|
1838
|
+
* Delete request
|
|
1839
|
+
*/
|
|
1840
|
+
delete: (url, options = {}) => {
|
|
1841
|
+
return client.url(url).options(options).delete().json();
|
|
1842
|
+
}
|
|
1843
|
+
};
|
|
1844
|
+
|
|
1845
|
+
// src/api/utils.ts
|
|
1846
|
+
function encodeQueryParam(key, value) {
|
|
1847
|
+
const encodedKey = encodeURIComponent(key);
|
|
1848
|
+
return `${encodedKey}=${encodeURIComponent(typeof value === "number" ? value : `${value}`)}`;
|
|
1849
|
+
}
|
|
1850
|
+
function addQueryParam(query, key) {
|
|
1851
|
+
return encodeQueryParam(key, query[key]);
|
|
1852
|
+
}
|
|
1853
|
+
function addArrayQueryParam(query, key) {
|
|
1854
|
+
const value = query[key];
|
|
1855
|
+
return value.map((v) => encodeQueryParam(key, v)).join("&");
|
|
1856
|
+
}
|
|
1857
|
+
function toQueryString(rawQuery) {
|
|
1858
|
+
const query = rawQuery || {};
|
|
1859
|
+
const keys = Object.keys(query).filter((key) => "undefined" !== typeof query[key]);
|
|
1860
|
+
return keys.map((key) => Array.isArray(query[key]) ? addArrayQueryParam(query, key) : addQueryParam(query, key)).join("&");
|
|
1861
|
+
}
|
|
1862
|
+
function addQueryParams(rawQuery) {
|
|
1863
|
+
const queryString = toQueryString(rawQuery);
|
|
1864
|
+
return queryString ? `?${queryString}` : "";
|
|
1865
|
+
}
|
|
1866
|
+
|
|
1867
|
+
// src/api/type.ts
|
|
1868
|
+
var ErrorCode = /* @__PURE__ */ ((ErrorCode3) => {
|
|
1869
|
+
ErrorCode3[ErrorCode3["SUCCESS"] = 9200] = "SUCCESS";
|
|
1870
|
+
ErrorCode3[ErrorCode3["SUCCESS_ORIGIN"] = 0] = "SUCCESS_ORIGIN";
|
|
1871
|
+
ErrorCode3[ErrorCode3["IDENTITY_VERIFICATION_FAILED"] = 9401] = "IDENTITY_VERIFICATION_FAILED";
|
|
1872
|
+
ErrorCode3[ErrorCode3["PERMISSION_DENIED"] = 9403] = "PERMISSION_DENIED";
|
|
1873
|
+
ErrorCode3[ErrorCode3["NOT_EXIST"] = 9404] = "NOT_EXIST";
|
|
1874
|
+
ErrorCode3[ErrorCode3["REQUEST_LIMIT"] = 9429] = "REQUEST_LIMIT";
|
|
1875
|
+
ErrorCode3[ErrorCode3["SERVICE_ERROR"] = 9500] = "SERVICE_ERROR";
|
|
1876
|
+
ErrorCode3[ErrorCode3["MISS_REQUESTED_PARAMETER"] = 9900] = "MISS_REQUESTED_PARAMETER";
|
|
1877
|
+
ErrorCode3[ErrorCode3["INVALID_PARAMETER"] = 9901] = "INVALID_PARAMETER";
|
|
1878
|
+
ErrorCode3["NETWORK_ERROR"] = "ERR_NETWORK";
|
|
1879
|
+
return ErrorCode3;
|
|
1880
|
+
})(ErrorCode || {});
|
|
1881
|
+
var MarketPoolState = /* @__PURE__ */ ((MarketPoolState3) => {
|
|
1882
|
+
MarketPoolState3[MarketPoolState3["Cook"] = 0] = "Cook";
|
|
1883
|
+
MarketPoolState3[MarketPoolState3["Primed"] = 1] = "Primed";
|
|
1884
|
+
MarketPoolState3[MarketPoolState3["Trench"] = 2] = "Trench";
|
|
1885
|
+
MarketPoolState3[MarketPoolState3["PreBench"] = 3] = "PreBench";
|
|
1886
|
+
MarketPoolState3[MarketPoolState3["Bench"] = 4] = "Bench";
|
|
1887
|
+
return MarketPoolState3;
|
|
1888
|
+
})(MarketPoolState || {});
|
|
1889
|
+
var OracleType = /* @__PURE__ */ ((OracleType7) => {
|
|
1890
|
+
OracleType7[OracleType7["Chainlink"] = 1] = "Chainlink";
|
|
1891
|
+
OracleType7[OracleType7["Pyth"] = 2] = "Pyth";
|
|
1892
|
+
return OracleType7;
|
|
1893
|
+
})(OracleType || {});
|
|
1894
|
+
var HttpKlineIntervalEnum = /* @__PURE__ */ ((HttpKlineIntervalEnum2) => {
|
|
1895
|
+
HttpKlineIntervalEnum2[HttpKlineIntervalEnum2["Minute1"] = 1] = "Minute1";
|
|
1896
|
+
HttpKlineIntervalEnum2[HttpKlineIntervalEnum2["Minute5"] = 5] = "Minute5";
|
|
1897
|
+
HttpKlineIntervalEnum2[HttpKlineIntervalEnum2["Minute15"] = 15] = "Minute15";
|
|
1898
|
+
HttpKlineIntervalEnum2[HttpKlineIntervalEnum2["Minute30"] = 30] = "Minute30";
|
|
1899
|
+
HttpKlineIntervalEnum2[HttpKlineIntervalEnum2["Hour1"] = 60] = "Hour1";
|
|
1900
|
+
HttpKlineIntervalEnum2[HttpKlineIntervalEnum2["Hour4"] = 240] = "Hour4";
|
|
1901
|
+
HttpKlineIntervalEnum2[HttpKlineIntervalEnum2["Day1"] = 1440] = "Day1";
|
|
1902
|
+
HttpKlineIntervalEnum2[HttpKlineIntervalEnum2["Week1"] = 10080] = "Week1";
|
|
1903
|
+
HttpKlineIntervalEnum2[HttpKlineIntervalEnum2["Month1"] = 40320] = "Month1";
|
|
1904
|
+
return HttpKlineIntervalEnum2;
|
|
1905
|
+
})(HttpKlineIntervalEnum || {});
|
|
1906
|
+
var MarketType = /* @__PURE__ */ ((MarketType2) => {
|
|
1907
|
+
MarketType2[MarketType2["Contract"] = 1] = "Contract";
|
|
1908
|
+
MarketType2[MarketType2["Cook"] = 2] = "Cook";
|
|
1909
|
+
MarketType2[MarketType2["Earn"] = 3] = "Earn";
|
|
1910
|
+
return MarketType2;
|
|
1911
|
+
})(MarketType || {});
|
|
1912
|
+
var SearchTypeEnum = /* @__PURE__ */ ((SearchTypeEnum2) => {
|
|
1913
|
+
SearchTypeEnum2[SearchTypeEnum2["All"] = 0] = "All";
|
|
1914
|
+
SearchTypeEnum2[SearchTypeEnum2["Contract"] = 1 /* Contract */] = "Contract";
|
|
1915
|
+
SearchTypeEnum2[SearchTypeEnum2["Cook"] = 2 /* Cook */] = "Cook";
|
|
1916
|
+
SearchTypeEnum2[SearchTypeEnum2["Earn"] = 3 /* Earn */] = "Earn";
|
|
1917
|
+
return SearchTypeEnum2;
|
|
1918
|
+
})(SearchTypeEnum || {});
|
|
1919
|
+
var MarketCapType = /* @__PURE__ */ ((MarketCapType2) => {
|
|
1920
|
+
MarketCapType2[MarketCapType2["BlueChips"] = 1] = "BlueChips";
|
|
1921
|
+
MarketCapType2[MarketCapType2["Alpha"] = 2] = "Alpha";
|
|
1922
|
+
return MarketCapType2;
|
|
1923
|
+
})(MarketCapType || {});
|
|
1924
|
+
var SearchSecondTypeEnum = /* @__PURE__ */ ((SearchSecondTypeEnum2) => {
|
|
1925
|
+
SearchSecondTypeEnum2[SearchSecondTypeEnum2["BlueChips"] = 1 /* BlueChips */] = "BlueChips";
|
|
1926
|
+
SearchSecondTypeEnum2[SearchSecondTypeEnum2["Alpha"] = 2 /* Alpha */] = "Alpha";
|
|
1927
|
+
SearchSecondTypeEnum2[SearchSecondTypeEnum2["Favorite"] = 3] = "Favorite";
|
|
1928
|
+
return SearchSecondTypeEnum2;
|
|
1929
|
+
})(SearchSecondTypeEnum || {});
|
|
1930
|
+
|
|
1931
|
+
// src/api/account/index.ts
|
|
1932
|
+
var OrderTypeEnum = /* @__PURE__ */ ((OrderTypeEnum2) => {
|
|
1933
|
+
OrderTypeEnum2[OrderTypeEnum2["Market"] = 0] = "Market";
|
|
1934
|
+
OrderTypeEnum2[OrderTypeEnum2["Limit"] = 1] = "Limit";
|
|
1935
|
+
OrderTypeEnum2[OrderTypeEnum2["Stop"] = 2] = "Stop";
|
|
1936
|
+
OrderTypeEnum2[OrderTypeEnum2["Conditional"] = 3] = "Conditional";
|
|
1937
|
+
return OrderTypeEnum2;
|
|
1938
|
+
})(OrderTypeEnum || {});
|
|
1939
|
+
var OperationEnum = /* @__PURE__ */ ((OperationEnum2) => {
|
|
1940
|
+
OperationEnum2[OperationEnum2["Increase"] = 0] = "Increase";
|
|
1941
|
+
OperationEnum2[OperationEnum2["Decrease"] = 1] = "Decrease";
|
|
1942
|
+
return OperationEnum2;
|
|
1943
|
+
})(OperationEnum || {});
|
|
1944
|
+
var TriggerTypeEnum = /* @__PURE__ */ ((TriggerTypeEnum2) => {
|
|
1945
|
+
TriggerTypeEnum2[TriggerTypeEnum2["Unknown"] = 0] = "Unknown";
|
|
1946
|
+
TriggerTypeEnum2[TriggerTypeEnum2["GTE"] = 1] = "GTE";
|
|
1947
|
+
TriggerTypeEnum2[TriggerTypeEnum2["LTE"] = 2] = "LTE";
|
|
1948
|
+
return TriggerTypeEnum2;
|
|
1949
|
+
})(TriggerTypeEnum || {});
|
|
1950
|
+
var DirectionEnum = /* @__PURE__ */ ((DirectionEnum2) => {
|
|
1951
|
+
DirectionEnum2[DirectionEnum2["Long"] = 0] = "Long";
|
|
1952
|
+
DirectionEnum2[DirectionEnum2["Short"] = 1] = "Short";
|
|
1953
|
+
return DirectionEnum2;
|
|
1954
|
+
})(DirectionEnum || {});
|
|
1955
|
+
var OrderStatusEnum = /* @__PURE__ */ ((OrderStatusEnum2) => {
|
|
1956
|
+
OrderStatusEnum2[OrderStatusEnum2["Cancelled"] = 1] = "Cancelled";
|
|
1957
|
+
OrderStatusEnum2[OrderStatusEnum2["Expired"] = 2] = "Expired";
|
|
1958
|
+
OrderStatusEnum2[OrderStatusEnum2["Successful"] = 9] = "Successful";
|
|
1959
|
+
return OrderStatusEnum2;
|
|
1960
|
+
})(OrderStatusEnum || {});
|
|
1961
|
+
var ExecTypeEnum = /* @__PURE__ */ ((ExecTypeEnum2) => {
|
|
1962
|
+
ExecTypeEnum2[ExecTypeEnum2["UserEntrust"] = 0] = "UserEntrust";
|
|
1963
|
+
ExecTypeEnum2[ExecTypeEnum2["Liquidation"] = 1] = "Liquidation";
|
|
1964
|
+
ExecTypeEnum2[ExecTypeEnum2["Adl"] = 2] = "Adl";
|
|
1965
|
+
ExecTypeEnum2[ExecTypeEnum2["AdlTrigger"] = 3] = "AdlTrigger";
|
|
1966
|
+
return ExecTypeEnum2;
|
|
1967
|
+
})(ExecTypeEnum || {});
|
|
1968
|
+
var getHistoryOrders = async ({
|
|
1969
|
+
accessToken,
|
|
1970
|
+
...params
|
|
1971
|
+
}) => {
|
|
1972
|
+
return http.get(
|
|
1973
|
+
`${baseUrl}/openapi/gateway/scan/order/closed`,
|
|
1974
|
+
params,
|
|
1975
|
+
{
|
|
1976
|
+
headers: {
|
|
1977
|
+
myx_openapi_access_token: accessToken
|
|
1978
|
+
}
|
|
1979
|
+
}
|
|
1980
|
+
);
|
|
1981
|
+
};
|
|
1982
|
+
var CloseTypeEnum = /* @__PURE__ */ ((CloseTypeEnum2) => {
|
|
1983
|
+
CloseTypeEnum2[CloseTypeEnum2["Open"] = 0] = "Open";
|
|
1984
|
+
CloseTypeEnum2[CloseTypeEnum2["PartialClose"] = 1] = "PartialClose";
|
|
1985
|
+
CloseTypeEnum2[CloseTypeEnum2["FullClose"] = 2] = "FullClose";
|
|
1986
|
+
CloseTypeEnum2[CloseTypeEnum2["Liquidation"] = 3] = "Liquidation";
|
|
1987
|
+
CloseTypeEnum2[CloseTypeEnum2["EarlyClose"] = 4] = "EarlyClose";
|
|
1988
|
+
CloseTypeEnum2[CloseTypeEnum2["MarketClose"] = 5] = "MarketClose";
|
|
1989
|
+
CloseTypeEnum2[CloseTypeEnum2["ADL"] = 6] = "ADL";
|
|
1990
|
+
CloseTypeEnum2[CloseTypeEnum2["TP"] = 7] = "TP";
|
|
1991
|
+
CloseTypeEnum2[CloseTypeEnum2["SL"] = 8] = "SL";
|
|
1992
|
+
CloseTypeEnum2[CloseTypeEnum2["Increase"] = 9] = "Increase";
|
|
1993
|
+
return CloseTypeEnum2;
|
|
1994
|
+
})(CloseTypeEnum || {});
|
|
1995
|
+
var getPositionHistory = async ({
|
|
1996
|
+
accessToken,
|
|
1997
|
+
...params
|
|
1998
|
+
}) => {
|
|
1999
|
+
return http.get(
|
|
2000
|
+
`${baseUrl}/openapi/gateway/scan/position/closed`,
|
|
2001
|
+
params,
|
|
2002
|
+
{
|
|
2003
|
+
headers: {
|
|
2004
|
+
myx_openapi_access_token: accessToken
|
|
2005
|
+
}
|
|
2006
|
+
}
|
|
2007
|
+
);
|
|
2008
|
+
};
|
|
2009
|
+
var getTradeFlow = async ({
|
|
2010
|
+
accessToken,
|
|
2011
|
+
...params
|
|
2012
|
+
}) => {
|
|
2013
|
+
return http.get(
|
|
2014
|
+
`${baseUrl}/openapi/gateway/scan/trade/flow`,
|
|
2015
|
+
params,
|
|
2016
|
+
{
|
|
2017
|
+
headers: {
|
|
2018
|
+
myx_openapi_access_token: accessToken
|
|
2019
|
+
}
|
|
2020
|
+
}
|
|
2021
|
+
);
|
|
2022
|
+
};
|
|
2023
|
+
|
|
2024
|
+
// src/api/index.ts
|
|
2025
|
+
var baseUrl = "https://api-test.myx.cash";
|
|
2026
|
+
var getOraclePrice = async (chainId, poolIds = []) => {
|
|
2027
|
+
if (!!poolIds.length) {
|
|
2028
|
+
return http.get(`${baseUrl}/openapi/gateway/quote/price/oracles`, {
|
|
2029
|
+
chainId,
|
|
2030
|
+
poolIds: poolIds.join(",")
|
|
2031
|
+
});
|
|
2032
|
+
}
|
|
2033
|
+
return Promise.reject(new Error("Invalid pool id"));
|
|
2034
|
+
};
|
|
2035
|
+
var getPoolLevelConfig = async ({
|
|
2036
|
+
poolId,
|
|
2037
|
+
chainId
|
|
2038
|
+
}) => {
|
|
2039
|
+
return http.get(
|
|
2040
|
+
`${baseUrl}/openapi/gateway/risk/market_pool/level_config${addQueryParams({
|
|
2041
|
+
poolId,
|
|
2042
|
+
chainId
|
|
2043
|
+
})}`
|
|
2044
|
+
);
|
|
2045
|
+
};
|
|
2046
|
+
var getPoolDetail = async (chainId, poolId) => {
|
|
2047
|
+
return await http.get(
|
|
2048
|
+
`${baseUrl}/openapi/gateway/scan/market/info?chainId=${chainId}&poolId=${poolId}`
|
|
2049
|
+
);
|
|
2050
|
+
};
|
|
2051
|
+
var getPositions = async (accessToken, chainId) => {
|
|
2052
|
+
return await http.get(
|
|
2053
|
+
`${baseUrl}/openapi/gateway/scan/position/open?chainId=${chainId}`,
|
|
2054
|
+
void 0,
|
|
2055
|
+
// params
|
|
2056
|
+
{
|
|
2057
|
+
headers: {
|
|
2058
|
+
myx_openapi_access_token: accessToken
|
|
2059
|
+
}
|
|
2060
|
+
}
|
|
2061
|
+
);
|
|
2062
|
+
};
|
|
2063
|
+
var getOrders = async (accessToken, chainId) => {
|
|
2064
|
+
return await http.get(
|
|
2065
|
+
`${baseUrl}/openapi/gateway/scan/order/open?chainId=${chainId}`,
|
|
2066
|
+
void 0,
|
|
2067
|
+
{ headers: { myx_openapi_access_token: accessToken } }
|
|
2068
|
+
);
|
|
2069
|
+
};
|
|
2070
|
+
var getPoolOpenOrders = async (accessToken, chainId) => {
|
|
2071
|
+
return await http.get(
|
|
2072
|
+
`${baseUrl}/openapi/gateway/scan/market/pool-order/open?chainId=${chainId}`,
|
|
2073
|
+
void 0,
|
|
2074
|
+
{ headers: { myx_openapi_access_token: accessToken } }
|
|
2075
|
+
);
|
|
2076
|
+
};
|
|
2077
|
+
var getKlineData = ({
|
|
2078
|
+
chainId,
|
|
2079
|
+
poolId,
|
|
2080
|
+
endTime,
|
|
2081
|
+
limit,
|
|
2082
|
+
interval
|
|
2083
|
+
}) => {
|
|
2084
|
+
return http.get(
|
|
2085
|
+
`${baseUrl}/openapi/gateway/quote/candles`,
|
|
2086
|
+
{
|
|
2087
|
+
chainId,
|
|
2088
|
+
poolId,
|
|
2089
|
+
endTime,
|
|
2090
|
+
limit,
|
|
2091
|
+
interval
|
|
2092
|
+
}
|
|
2093
|
+
);
|
|
2094
|
+
};
|
|
2095
|
+
var getKlineLatestBar = async (params) => {
|
|
2096
|
+
return http.get(
|
|
2097
|
+
`${baseUrl}/openapi/gateway/quote/candle/latest`,
|
|
2098
|
+
params
|
|
2099
|
+
);
|
|
2100
|
+
};
|
|
2101
|
+
var getTickerData = async ({
|
|
2102
|
+
chainId,
|
|
2103
|
+
poolIds
|
|
2104
|
+
}) => {
|
|
2105
|
+
return http.get(
|
|
2106
|
+
`${baseUrl}/openapi/gateway/quote/candle/tickers`,
|
|
2107
|
+
{
|
|
2108
|
+
chainId,
|
|
2109
|
+
poolIds: poolIds.join(",")
|
|
2110
|
+
}
|
|
2111
|
+
);
|
|
2112
|
+
};
|
|
2113
|
+
var getAllTickers = async () => {
|
|
2114
|
+
return http.get(
|
|
2115
|
+
`${baseUrl}/v2/mx-gateway/quote/candle/all_tickers`
|
|
2116
|
+
);
|
|
2117
|
+
};
|
|
2118
|
+
var searchMarketAuth = async ({
|
|
2119
|
+
accessToken,
|
|
2120
|
+
...params
|
|
2121
|
+
}) => {
|
|
2122
|
+
return http.get(
|
|
2123
|
+
`${baseUrl}/openapi/gateway/scan/market/ac-search`,
|
|
2124
|
+
params,
|
|
2125
|
+
{
|
|
2126
|
+
headers: {
|
|
2127
|
+
myx_openapi_access_token: accessToken
|
|
2128
|
+
}
|
|
2129
|
+
}
|
|
2130
|
+
);
|
|
2131
|
+
};
|
|
2132
|
+
var searchMarket = async ({ ...params }) => {
|
|
2133
|
+
return http.get(
|
|
2134
|
+
`${baseUrl}/openapi/gateway/scan/market/search`,
|
|
2135
|
+
params
|
|
2136
|
+
);
|
|
2137
|
+
};
|
|
2138
|
+
var addFavorite = async ({
|
|
2139
|
+
accessToken,
|
|
2140
|
+
...params
|
|
2141
|
+
}) => {
|
|
2142
|
+
return http.get(
|
|
2143
|
+
`${baseUrl}/openapi/gateway/scan/market/add-favorites`,
|
|
2144
|
+
params,
|
|
2145
|
+
{
|
|
2146
|
+
headers: {
|
|
2147
|
+
myx_openapi_access_token: accessToken
|
|
2148
|
+
}
|
|
2149
|
+
}
|
|
2150
|
+
);
|
|
2151
|
+
};
|
|
2152
|
+
var removeFavorite = async ({
|
|
2153
|
+
accessToken,
|
|
2154
|
+
...params
|
|
2155
|
+
}) => {
|
|
2156
|
+
return http.get(
|
|
2157
|
+
`${baseUrl}/openapi/gateway/scan/market/cancel-favorites`,
|
|
2158
|
+
params,
|
|
2159
|
+
{
|
|
2160
|
+
headers: {
|
|
2161
|
+
myx_openapi_access_token: accessToken
|
|
2162
|
+
}
|
|
2163
|
+
}
|
|
2164
|
+
);
|
|
2165
|
+
};
|
|
2166
|
+
var getFavoritesList = async ({
|
|
2167
|
+
accessToken,
|
|
2168
|
+
...params
|
|
2169
|
+
}) => {
|
|
2170
|
+
return http.get(
|
|
2171
|
+
`${baseUrl}/openapi/gateway/scan/market/favorites`,
|
|
2172
|
+
params,
|
|
2173
|
+
{
|
|
2174
|
+
headers: {
|
|
2175
|
+
myx_openapi_access_token: accessToken
|
|
2176
|
+
}
|
|
2177
|
+
}
|
|
2178
|
+
);
|
|
2179
|
+
};
|
|
2180
|
+
var getBaseDetail = async (params) => {
|
|
2181
|
+
return http.get(
|
|
2182
|
+
`${baseUrl}/openapi/gateway/scan/market/base-details`,
|
|
2183
|
+
params
|
|
2184
|
+
);
|
|
2185
|
+
};
|
|
2186
|
+
var getMarketDetail = async (params) => {
|
|
2187
|
+
return http.get(
|
|
2188
|
+
`${baseUrl}/openapi/gateway/scan/market/detail`,
|
|
2189
|
+
params
|
|
2190
|
+
);
|
|
2191
|
+
};
|
|
2192
|
+
var getMarketList = async () => {
|
|
2193
|
+
return http.get(`${baseUrl}/openapi/gateway/scan/market`);
|
|
2194
|
+
};
|
|
2195
|
+
|
|
1816
2196
|
// src/web3/index.ts
|
|
1817
2197
|
function getContract(address, ABI, provider) {
|
|
1818
|
-
if (Address.from(address).isEqualTo(
|
|
2198
|
+
if (Address.from(address).isEqualTo(ZeroAddress)) {
|
|
1819
2199
|
throw new Error(`Invalid 'address' parameter '${address}'.`);
|
|
1820
2200
|
}
|
|
1821
2201
|
return new Contract(address, ABI, provider);
|
|
1822
2202
|
}
|
|
1823
|
-
var getJSONProvider = (
|
|
1824
|
-
const chainConfig = getChainInfo(
|
|
2203
|
+
var getJSONProvider = (chainId) => {
|
|
2204
|
+
const chainConfig = getChainInfo(chainId);
|
|
1825
2205
|
const chainProviders = [];
|
|
1826
2206
|
if (chainConfig.privateJsonRPCUrl) {
|
|
1827
2207
|
chainProviders.push(chainConfig.privateJsonRPCUrl);
|
|
@@ -1830,20 +2210,21 @@ var getJSONProvider = (chainId2) => {
|
|
|
1830
2210
|
chainConfig.publicJsonRPCUrl.map((rpc) => chainProviders.push(rpc));
|
|
1831
2211
|
}
|
|
1832
2212
|
if (chainProviders.length === 0) {
|
|
1833
|
-
throw new Error(`${
|
|
2213
|
+
throw new Error(`${chainId} has no jsonRPCUrl configured`);
|
|
1834
2214
|
}
|
|
1835
2215
|
if (chainProviders.length === 1) {
|
|
1836
|
-
return new JsonRpcProvider(chainProviders[0],
|
|
2216
|
+
return new JsonRpcProvider(chainProviders[0], chainId, {
|
|
1837
2217
|
staticNetwork: true
|
|
1838
2218
|
});
|
|
1839
2219
|
} else {
|
|
1840
|
-
return new RotationProvider(chainProviders,
|
|
2220
|
+
return new RotationProvider(chainProviders, chainId);
|
|
1841
2221
|
}
|
|
1842
2222
|
};
|
|
1843
2223
|
var MxSDK = class _MxSDK {
|
|
1844
2224
|
constructor() {
|
|
1845
2225
|
this.version = package_default.version;
|
|
1846
2226
|
console.log(this.version);
|
|
2227
|
+
this.getMarkets().then();
|
|
1847
2228
|
}
|
|
1848
2229
|
setConfigManager(configManager) {
|
|
1849
2230
|
this.configManager = configManager;
|
|
@@ -1863,6 +2244,14 @@ var MxSDK = class _MxSDK {
|
|
|
1863
2244
|
}
|
|
1864
2245
|
return this._instance;
|
|
1865
2246
|
}
|
|
2247
|
+
async getMarkets() {
|
|
2248
|
+
try {
|
|
2249
|
+
const result = await getMarketList();
|
|
2250
|
+
this.Markets = result?.data || [];
|
|
2251
|
+
} catch (error) {
|
|
2252
|
+
throw error;
|
|
2253
|
+
}
|
|
2254
|
+
}
|
|
1866
2255
|
};
|
|
1867
2256
|
var sdk = MxSDK.getInstance();
|
|
1868
2257
|
if (typeof window !== "undefined") {
|
|
@@ -1870,7 +2259,7 @@ if (typeof window !== "undefined") {
|
|
|
1870
2259
|
} else if (typeof globalThis !== "undefined") {
|
|
1871
2260
|
globalThis.MxSDK = sdk;
|
|
1872
2261
|
}
|
|
1873
|
-
var getWalletProvider = async (
|
|
2262
|
+
var getWalletProvider = async (chainId) => {
|
|
1874
2263
|
try {
|
|
1875
2264
|
const walletClient = sdk.getConfigManager()?.getConfig()?.walletClient;
|
|
1876
2265
|
const provider = new BrowserProvider(walletClient?.transport);
|
|
@@ -1883,8 +2272,8 @@ var getWalletProvider = async (chainId2) => {
|
|
|
1883
2272
|
return ethers.getDefaultProvider("mainnet");
|
|
1884
2273
|
}
|
|
1885
2274
|
};
|
|
1886
|
-
var getSignerProvider = async (
|
|
1887
|
-
const provider = await getWalletProvider(
|
|
2275
|
+
var getSignerProvider = async (chainId) => {
|
|
2276
|
+
const provider = await getWalletProvider(chainId);
|
|
1888
2277
|
return provider?.getSigner?.();
|
|
1889
2278
|
};
|
|
1890
2279
|
|
|
@@ -8984,6 +9373,30 @@ var DataProvider_default = [
|
|
|
8984
9373
|
}
|
|
8985
9374
|
]
|
|
8986
9375
|
},
|
|
9376
|
+
{
|
|
9377
|
+
type: "error",
|
|
9378
|
+
name: "PositionNotHealthy",
|
|
9379
|
+
inputs: [
|
|
9380
|
+
{
|
|
9381
|
+
type: "bytes32",
|
|
9382
|
+
name: "positionId"
|
|
9383
|
+
},
|
|
9384
|
+
{
|
|
9385
|
+
type: "uint256",
|
|
9386
|
+
name: "marginRatio"
|
|
9387
|
+
}
|
|
9388
|
+
]
|
|
9389
|
+
},
|
|
9390
|
+
{
|
|
9391
|
+
type: "error",
|
|
9392
|
+
name: "SafeCastOverflowedUintToInt",
|
|
9393
|
+
inputs: [
|
|
9394
|
+
{
|
|
9395
|
+
type: "uint256",
|
|
9396
|
+
name: "value"
|
|
9397
|
+
}
|
|
9398
|
+
]
|
|
9399
|
+
},
|
|
8987
9400
|
{
|
|
8988
9401
|
type: "function",
|
|
8989
9402
|
name: "ADDRESS_MANAGER",
|
|
@@ -8997,6 +9410,36 @@ var DataProvider_default = [
|
|
|
8997
9410
|
}
|
|
8998
9411
|
]
|
|
8999
9412
|
},
|
|
9413
|
+
{
|
|
9414
|
+
type: "function",
|
|
9415
|
+
name: "getAvailableLiquiditySize",
|
|
9416
|
+
constant: true,
|
|
9417
|
+
stateMutability: "view",
|
|
9418
|
+
payable: false,
|
|
9419
|
+
inputs: [
|
|
9420
|
+
{
|
|
9421
|
+
type: "bytes32",
|
|
9422
|
+
name: "poolId"
|
|
9423
|
+
},
|
|
9424
|
+
{
|
|
9425
|
+
type: "uint8",
|
|
9426
|
+
name: "operation"
|
|
9427
|
+
},
|
|
9428
|
+
{
|
|
9429
|
+
type: "uint8",
|
|
9430
|
+
name: "direction"
|
|
9431
|
+
},
|
|
9432
|
+
{
|
|
9433
|
+
type: "uint256",
|
|
9434
|
+
name: "executePrice"
|
|
9435
|
+
}
|
|
9436
|
+
],
|
|
9437
|
+
outputs: [
|
|
9438
|
+
{
|
|
9439
|
+
type: "uint256"
|
|
9440
|
+
}
|
|
9441
|
+
]
|
|
9442
|
+
},
|
|
9000
9443
|
{
|
|
9001
9444
|
type: "function",
|
|
9002
9445
|
name: "getBrokerFeeTiers",
|
|
@@ -9027,11 +9470,11 @@ var DataProvider_default = [
|
|
|
9027
9470
|
name: "tier"
|
|
9028
9471
|
},
|
|
9029
9472
|
{
|
|
9030
|
-
type: "
|
|
9473
|
+
type: "uint32",
|
|
9031
9474
|
name: "takerFeeRate"
|
|
9032
9475
|
},
|
|
9033
9476
|
{
|
|
9034
|
-
type: "
|
|
9477
|
+
type: "int32",
|
|
9035
9478
|
name: "makerFeeRate"
|
|
9036
9479
|
}
|
|
9037
9480
|
]
|
|
@@ -9045,11 +9488,11 @@ var DataProvider_default = [
|
|
|
9045
9488
|
name: "assetClass"
|
|
9046
9489
|
},
|
|
9047
9490
|
{
|
|
9048
|
-
type: "
|
|
9491
|
+
type: "uint32",
|
|
9049
9492
|
name: "makerFeeRate"
|
|
9050
9493
|
},
|
|
9051
9494
|
{
|
|
9052
|
-
type: "
|
|
9495
|
+
type: "uint32",
|
|
9053
9496
|
name: "takerFeeRate"
|
|
9054
9497
|
}
|
|
9055
9498
|
]
|
|
@@ -9063,11 +9506,11 @@ var DataProvider_default = [
|
|
|
9063
9506
|
name: "tier"
|
|
9064
9507
|
},
|
|
9065
9508
|
{
|
|
9066
|
-
type: "
|
|
9509
|
+
type: "uint32",
|
|
9067
9510
|
name: "takerFeeRate"
|
|
9068
9511
|
},
|
|
9069
9512
|
{
|
|
9070
|
-
type: "
|
|
9513
|
+
type: "int32",
|
|
9071
9514
|
name: "makerFeeRate"
|
|
9072
9515
|
}
|
|
9073
9516
|
]
|
|
@@ -9094,26 +9537,52 @@ var DataProvider_default = [
|
|
|
9094
9537
|
],
|
|
9095
9538
|
outputs: [
|
|
9096
9539
|
{
|
|
9097
|
-
type: "tuple[]",
|
|
9098
|
-
name: "exchangeables",
|
|
9099
|
-
components: [
|
|
9100
|
-
{
|
|
9101
|
-
type: "uint256",
|
|
9102
|
-
name: "maxBaseIn"
|
|
9103
|
-
},
|
|
9104
|
-
{
|
|
9105
|
-
type: "uint256",
|
|
9106
|
-
name: "maxQuoteIn"
|
|
9107
|
-
},
|
|
9108
|
-
{
|
|
9109
|
-
type: "uint256",
|
|
9110
|
-
name: "maxBaseOut"
|
|
9111
|
-
},
|
|
9112
|
-
{
|
|
9113
|
-
type: "uint256",
|
|
9114
|
-
name: "maxQuoteOut"
|
|
9115
|
-
}
|
|
9116
|
-
]
|
|
9540
|
+
type: "tuple[]",
|
|
9541
|
+
name: "exchangeables",
|
|
9542
|
+
components: [
|
|
9543
|
+
{
|
|
9544
|
+
type: "uint256",
|
|
9545
|
+
name: "maxBaseIn"
|
|
9546
|
+
},
|
|
9547
|
+
{
|
|
9548
|
+
type: "uint256",
|
|
9549
|
+
name: "maxQuoteIn"
|
|
9550
|
+
},
|
|
9551
|
+
{
|
|
9552
|
+
type: "uint256",
|
|
9553
|
+
name: "maxBaseOut"
|
|
9554
|
+
},
|
|
9555
|
+
{
|
|
9556
|
+
type: "uint256",
|
|
9557
|
+
name: "maxQuoteOut"
|
|
9558
|
+
}
|
|
9559
|
+
]
|
|
9560
|
+
}
|
|
9561
|
+
]
|
|
9562
|
+
},
|
|
9563
|
+
{
|
|
9564
|
+
type: "function",
|
|
9565
|
+
name: "getLiquidationPrice",
|
|
9566
|
+
constant: true,
|
|
9567
|
+
stateMutability: "view",
|
|
9568
|
+
payable: false,
|
|
9569
|
+
inputs: [
|
|
9570
|
+
{
|
|
9571
|
+
type: "bytes32",
|
|
9572
|
+
name: "positionId"
|
|
9573
|
+
},
|
|
9574
|
+
{
|
|
9575
|
+
type: "uint256",
|
|
9576
|
+
name: "marketPrice"
|
|
9577
|
+
},
|
|
9578
|
+
{
|
|
9579
|
+
type: "address",
|
|
9580
|
+
name: "broker"
|
|
9581
|
+
}
|
|
9582
|
+
],
|
|
9583
|
+
outputs: [
|
|
9584
|
+
{
|
|
9585
|
+
type: "uint256"
|
|
9117
9586
|
}
|
|
9118
9587
|
]
|
|
9119
9588
|
},
|
|
@@ -9412,74 +9881,178 @@ var DataProvider_default = [
|
|
|
9412
9881
|
]
|
|
9413
9882
|
}
|
|
9414
9883
|
]
|
|
9884
|
+
},
|
|
9885
|
+
{
|
|
9886
|
+
type: "function",
|
|
9887
|
+
name: "getPositionFees",
|
|
9888
|
+
constant: true,
|
|
9889
|
+
stateMutability: "view",
|
|
9890
|
+
payable: false,
|
|
9891
|
+
inputs: [
|
|
9892
|
+
{
|
|
9893
|
+
type: "bytes32",
|
|
9894
|
+
name: "positionId"
|
|
9895
|
+
},
|
|
9896
|
+
{
|
|
9897
|
+
type: "address",
|
|
9898
|
+
name: "broker"
|
|
9899
|
+
},
|
|
9900
|
+
{
|
|
9901
|
+
type: "uint256",
|
|
9902
|
+
name: "price"
|
|
9903
|
+
}
|
|
9904
|
+
],
|
|
9905
|
+
outputs: [
|
|
9906
|
+
{
|
|
9907
|
+
type: "int256",
|
|
9908
|
+
name: "netCollateral"
|
|
9909
|
+
},
|
|
9910
|
+
{
|
|
9911
|
+
type: "uint256",
|
|
9912
|
+
name: "collateralAmount"
|
|
9913
|
+
},
|
|
9914
|
+
{
|
|
9915
|
+
type: "uint256",
|
|
9916
|
+
name: "tradingFee"
|
|
9917
|
+
},
|
|
9918
|
+
{
|
|
9919
|
+
type: "int256",
|
|
9920
|
+
name: "fundingFee"
|
|
9921
|
+
}
|
|
9922
|
+
]
|
|
9923
|
+
},
|
|
9924
|
+
{
|
|
9925
|
+
type: "function",
|
|
9926
|
+
name: "getUserPositionInfos",
|
|
9927
|
+
constant: true,
|
|
9928
|
+
stateMutability: "view",
|
|
9929
|
+
payable: false,
|
|
9930
|
+
inputs: [
|
|
9931
|
+
{
|
|
9932
|
+
type: "address",
|
|
9933
|
+
name: "user"
|
|
9934
|
+
},
|
|
9935
|
+
{
|
|
9936
|
+
type: "bytes32[]",
|
|
9937
|
+
name: "poolIds"
|
|
9938
|
+
}
|
|
9939
|
+
],
|
|
9940
|
+
outputs: [
|
|
9941
|
+
{
|
|
9942
|
+
type: "tuple[]",
|
|
9943
|
+
name: "positions",
|
|
9944
|
+
components: [
|
|
9945
|
+
{
|
|
9946
|
+
type: "bytes32",
|
|
9947
|
+
name: "positionId"
|
|
9948
|
+
},
|
|
9949
|
+
{
|
|
9950
|
+
type: "bytes32",
|
|
9951
|
+
name: "poolId"
|
|
9952
|
+
},
|
|
9953
|
+
{
|
|
9954
|
+
type: "uint256",
|
|
9955
|
+
name: "size"
|
|
9956
|
+
},
|
|
9957
|
+
{
|
|
9958
|
+
type: "uint256",
|
|
9959
|
+
name: "entryPrice"
|
|
9960
|
+
},
|
|
9961
|
+
{
|
|
9962
|
+
type: "int256",
|
|
9963
|
+
name: "fundingRateIndex"
|
|
9964
|
+
},
|
|
9965
|
+
{
|
|
9966
|
+
type: "uint256",
|
|
9967
|
+
name: "earlyClosePrice"
|
|
9968
|
+
},
|
|
9969
|
+
{
|
|
9970
|
+
type: "uint8",
|
|
9971
|
+
name: "direction"
|
|
9972
|
+
},
|
|
9973
|
+
{
|
|
9974
|
+
type: "uint8",
|
|
9975
|
+
name: "riskTier"
|
|
9976
|
+
},
|
|
9977
|
+
{
|
|
9978
|
+
type: "uint64",
|
|
9979
|
+
name: "lastUpdateTime"
|
|
9980
|
+
},
|
|
9981
|
+
{
|
|
9982
|
+
type: "uint256",
|
|
9983
|
+
name: "collateralAmount"
|
|
9984
|
+
}
|
|
9985
|
+
]
|
|
9986
|
+
}
|
|
9987
|
+
]
|
|
9415
9988
|
}
|
|
9416
9989
|
];
|
|
9417
9990
|
|
|
9418
9991
|
// src/web3/providers.ts
|
|
9419
|
-
var getTokenContract = async (
|
|
9420
|
-
const provider = getJSONProvider(
|
|
9992
|
+
var getTokenContract = async (chainId, tokenAddress) => {
|
|
9993
|
+
const provider = getJSONProvider(chainId);
|
|
9421
9994
|
return getContract(tokenAddress, IERC20Metadata_default, provider);
|
|
9422
9995
|
};
|
|
9423
|
-
var getERC20Contract = async (
|
|
9424
|
-
const provider = await getSignerProvider(
|
|
9996
|
+
var getERC20Contract = async (chainId, tokenAddress) => {
|
|
9997
|
+
const provider = await getSignerProvider(chainId);
|
|
9425
9998
|
return getContract(tokenAddress, IERC20Metadata_default, provider);
|
|
9426
9999
|
};
|
|
9427
|
-
var getAccount = async (
|
|
9428
|
-
const provider = await getSignerProvider(
|
|
10000
|
+
var getAccount = async (chainId) => {
|
|
10001
|
+
const provider = await getSignerProvider(chainId);
|
|
9429
10002
|
const account = await provider?.getAddress();
|
|
9430
10003
|
return account ?? void 0;
|
|
9431
10004
|
};
|
|
9432
|
-
var getLiquidityRouterContract = async (
|
|
9433
|
-
const addresses = address_default[
|
|
10005
|
+
var getLiquidityRouterContract = async (chainId) => {
|
|
10006
|
+
const addresses = address_default[chainId];
|
|
9434
10007
|
const address = addresses.LIQUIDITY_ROUTER;
|
|
9435
|
-
const provider = await getSignerProvider(
|
|
10008
|
+
const provider = await getSignerProvider(chainId);
|
|
9436
10009
|
return getContract(address, LiquidityRouter_default, provider);
|
|
9437
10010
|
};
|
|
9438
|
-
var getPoolManagerContract = async (
|
|
9439
|
-
const addresses = address_default[
|
|
10011
|
+
var getPoolManagerContract = async (chainId, type = 1 /* Signer */) => {
|
|
10012
|
+
const addresses = address_default[chainId];
|
|
9440
10013
|
const address = addresses.POOL_MANAGER;
|
|
9441
|
-
const provider = type === 0 /* JSON */ ? getJSONProvider(
|
|
10014
|
+
const provider = type === 0 /* JSON */ ? getJSONProvider(chainId) : await getSignerProvider(chainId);
|
|
9442
10015
|
return getContract(address, PoolManager_default, provider);
|
|
9443
10016
|
};
|
|
9444
|
-
var getQuotePoolContract = async (
|
|
9445
|
-
const addresses = address_default[
|
|
10017
|
+
var getQuotePoolContract = async (chainId, type = 0 /* JSON */) => {
|
|
10018
|
+
const addresses = address_default[chainId];
|
|
9446
10019
|
const address = addresses.QUOTE_POOL;
|
|
9447
|
-
const provider = type === 0 /* JSON */ ? getJSONProvider(
|
|
10020
|
+
const provider = type === 0 /* JSON */ ? getJSONProvider(chainId) : await getSignerProvider(chainId);
|
|
9448
10021
|
return getContract(address, QuotePool_default, provider);
|
|
9449
10022
|
};
|
|
9450
|
-
var getBasePoolContract = async (
|
|
9451
|
-
const addresses = address_default[
|
|
10023
|
+
var getBasePoolContract = async (chainId, type = 0 /* JSON */) => {
|
|
10024
|
+
const addresses = address_default[chainId];
|
|
9452
10025
|
const address = addresses.BASE_POOL;
|
|
9453
|
-
const provider = type === 0 /* JSON */ ? getJSONProvider(
|
|
10026
|
+
const provider = type === 0 /* JSON */ ? getJSONProvider(chainId) : await getSignerProvider(chainId);
|
|
9454
10027
|
return getContract(address, BasePool_default, provider);
|
|
9455
10028
|
};
|
|
9456
|
-
var getBrokerSingerContract = async (
|
|
9457
|
-
const addresses = address_default[
|
|
10029
|
+
var getBrokerSingerContract = async (chainId) => {
|
|
10030
|
+
const addresses = address_default[chainId];
|
|
9458
10031
|
const address = addresses.BROKER;
|
|
9459
|
-
const provider = await getSignerProvider(
|
|
10032
|
+
const provider = await getSignerProvider(chainId);
|
|
9460
10033
|
return getContract(address, Broker_default, provider);
|
|
9461
10034
|
};
|
|
9462
|
-
var getPythContract = async (
|
|
9463
|
-
const addresses = address_default[
|
|
10035
|
+
var getPythContract = async (chainId, type = 0 /* JSON */) => {
|
|
10036
|
+
const addresses = address_default[chainId];
|
|
9464
10037
|
const address = addresses.PYTH;
|
|
9465
|
-
const provider = type === 0 /* JSON */ ? getJSONProvider(
|
|
10038
|
+
const provider = type === 0 /* JSON */ ? getJSONProvider(chainId) : await getSignerProvider(chainId);
|
|
9466
10039
|
return getContract(address, IPyth_default, provider);
|
|
9467
10040
|
};
|
|
9468
|
-
var getPoolTokenContract = async (
|
|
10041
|
+
var getPoolTokenContract = async (chainId, lpTokenAddress, type = 0 /* JSON */) => {
|
|
9469
10042
|
const address = lpTokenAddress;
|
|
9470
|
-
const provider = type === 0 /* JSON */ ? getJSONProvider(
|
|
10043
|
+
const provider = type === 0 /* JSON */ ? getJSONProvider(chainId) : await getSignerProvider(chainId);
|
|
9471
10044
|
return getContract(address, PoolToken_default, provider);
|
|
9472
10045
|
};
|
|
9473
|
-
var getMarketManageContract = async (
|
|
9474
|
-
const addresses = address_default[
|
|
10046
|
+
var getMarketManageContract = async (chainId, type = 0 /* JSON */) => {
|
|
10047
|
+
const addresses = address_default[chainId];
|
|
9475
10048
|
const address = addresses.MARKET_MANAGER;
|
|
9476
|
-
const provider = type === 0 /* JSON */ ? getJSONProvider(
|
|
10049
|
+
const provider = type === 0 /* JSON */ ? getJSONProvider(chainId) : await getSignerProvider(chainId);
|
|
9477
10050
|
return getContract(address, MarketManager_default, provider);
|
|
9478
10051
|
};
|
|
9479
|
-
var getDataProviderContract = async (
|
|
9480
|
-
const addresses = address_default[
|
|
10052
|
+
var getDataProviderContract = async (chainId, type = 0 /* JSON */) => {
|
|
10053
|
+
const addresses = address_default[chainId];
|
|
9481
10054
|
const address = addresses.DATA_PROVIDER;
|
|
9482
|
-
const provider = type === 0 /* JSON */ ? getJSONProvider(
|
|
10055
|
+
const provider = type === 0 /* JSON */ ? getJSONProvider(chainId) : await getSignerProvider(chainId);
|
|
9483
10056
|
return getContract(address, DataProvider_default, provider);
|
|
9484
10057
|
};
|
|
9485
10058
|
|
|
@@ -9677,576 +10250,187 @@ var Errors = {
|
|
|
9677
10250
|
[2 /* Invalid_TOKEN_ADDRESS */]: `Invalid Token Address`,
|
|
9678
10251
|
[4001 /* USER_REJECTED_REQUEST */]: `User Rejected`,
|
|
9679
10252
|
[3 /* Insufficient_Balance */]: `Insufficient Balance`,
|
|
9680
|
-
[4 /* Insufficient_Amount_Of_Approved */]: `Insufficient Amount Of Approved`,
|
|
9681
|
-
[4002 /* Invalid_Base */]: `Invalid Base Token Address`,
|
|
9682
|
-
[4003 /* Invalid_slippage */]: `Invalid Slippage`,
|
|
9683
|
-
[4004 /* Invalid_Amount */]: `Invalid Amount`,
|
|
9684
|
-
[4005 /* Invalid_Pool_State */]: `Invalid Pool State`,
|
|
9685
|
-
[4006 /* Invalid_Params */]: `Invalid Params`
|
|
9686
|
-
};
|
|
9687
|
-
function didUserReject(error) {
|
|
9688
|
-
return error?.code === 4001 /* USER_REJECTED_REQUEST */;
|
|
9689
|
-
}
|
|
9690
|
-
async function getErrorTextFormError(error) {
|
|
9691
|
-
if (didUserReject(error)) {
|
|
9692
|
-
return {
|
|
9693
|
-
error: Errors[4001 /* USER_REJECTED_REQUEST */]
|
|
9694
|
-
};
|
|
9695
|
-
}
|
|
9696
|
-
const decodeErrorResult = await errorDecoder.decode(error);
|
|
9697
|
-
console.log(decodeErrorResult);
|
|
9698
|
-
if (decodeErrorResult.type === ErrorType.UserRejectError || decodeErrorResult.name === "ACTION_REJECTED") {
|
|
9699
|
-
return {
|
|
9700
|
-
error: Errors[4001 /* USER_REJECTED_REQUEST */]
|
|
9701
|
-
};
|
|
9702
|
-
}
|
|
9703
|
-
if (decodeErrorResult.type === ErrorType.CustomError) {
|
|
9704
|
-
const errorKey = Object.keys(customErrorMapping).find((k) => k.toLowerCase() === decodeErrorResult.selector.toLowerCase());
|
|
9705
|
-
if (errorKey) {
|
|
9706
|
-
return {
|
|
9707
|
-
error: customErrorMapping[errorKey]
|
|
9708
|
-
};
|
|
9709
|
-
}
|
|
9710
|
-
return {
|
|
9711
|
-
error: error?.reason || decodeErrorResult.reason || error.message || error?.code
|
|
9712
|
-
};
|
|
9713
|
-
}
|
|
9714
|
-
console.error(error);
|
|
9715
|
-
return {
|
|
9716
|
-
error: decodeErrorResult.reason
|
|
9717
|
-
};
|
|
9718
|
-
}
|
|
9719
|
-
|
|
9720
|
-
// src/common/balanceOf.ts
|
|
9721
|
-
import { ethers as ethers2 } from "ethers";
|
|
9722
|
-
var getBalanceOf = async (chainId2, account, tokenAddress) => {
|
|
9723
|
-
try {
|
|
9724
|
-
const provider = getJSONProvider(chainId2);
|
|
9725
|
-
const contractInterface = new ethers2.Interface(IERC20Metadata_default);
|
|
9726
|
-
const data = contractInterface.encodeFunctionData("balanceOf", [account]);
|
|
9727
|
-
const callData = {
|
|
9728
|
-
to: tokenAddress,
|
|
9729
|
-
data
|
|
9730
|
-
};
|
|
9731
|
-
const result = await provider.call(callData);
|
|
9732
|
-
const balance = BigInt(result);
|
|
9733
|
-
return balance;
|
|
9734
|
-
} catch (e) {
|
|
9735
|
-
console.error(e);
|
|
9736
|
-
throw e;
|
|
9737
|
-
}
|
|
9738
|
-
};
|
|
9739
|
-
|
|
9740
|
-
// src/common/checkParams.ts
|
|
9741
|
-
import { MaxUint256, parseUnits as parseUnits2 } from "ethers";
|
|
9742
|
-
|
|
9743
|
-
// src/common/allowance.ts
|
|
9744
|
-
import { ethers as ethers3 } from "ethers";
|
|
9745
|
-
var getAllowanceApproved = async (chainId2, account, tokenAddress, approveAddress, approveAmount) => {
|
|
9746
|
-
try {
|
|
9747
|
-
const provider = getJSONProvider(chainId2);
|
|
9748
|
-
const contractInterface = new ethers3.Interface(IERC20Metadata_default);
|
|
9749
|
-
const data = contractInterface.encodeFunctionData("allowance", [account, approveAddress]);
|
|
9750
|
-
const callData = {
|
|
9751
|
-
to: tokenAddress,
|
|
9752
|
-
data
|
|
9753
|
-
};
|
|
9754
|
-
const result = await provider.call(callData);
|
|
9755
|
-
const allowance = BigInt(result);
|
|
9756
|
-
if (allowance >= approveAmount) {
|
|
9757
|
-
return true;
|
|
9758
|
-
}
|
|
9759
|
-
return false;
|
|
9760
|
-
} catch (e) {
|
|
9761
|
-
throw e;
|
|
9762
|
-
}
|
|
9763
|
-
};
|
|
9764
|
-
|
|
9765
|
-
// src/common/approve.ts
|
|
9766
|
-
var approve = async (chainId2, account, tokenAddress, approveAddress, amount) => {
|
|
9767
|
-
try {
|
|
9768
|
-
const TokenContract = await getERC20Contract(chainId2, tokenAddress);
|
|
9769
|
-
const response = await TokenContract.approve(approveAddress, amount);
|
|
9770
|
-
const receipt = await response?.wait();
|
|
9771
|
-
const isApproved = await getAllowanceApproved(chainId2, account, tokenAddress, approveAddress, amount);
|
|
9772
|
-
if (!isApproved) {
|
|
9773
|
-
throw new Error(Errors[4 /* Insufficient_Amount_Of_Approved */]);
|
|
9774
|
-
}
|
|
9775
|
-
} catch (e) {
|
|
9776
|
-
throw e;
|
|
9777
|
-
}
|
|
9778
|
-
};
|
|
9779
|
-
|
|
9780
|
-
// src/common/checkParams.ts
|
|
9781
|
-
var checkParams = async (params) => {
|
|
9782
|
-
if ("chainId" in params) {
|
|
9783
|
-
const valid = isSupportedChainFn(params.chainId);
|
|
9784
|
-
if (!valid) {
|
|
9785
|
-
throw new Error(Errors[1 /* Invalid_Chain_ID */]);
|
|
9786
|
-
}
|
|
9787
|
-
}
|
|
9788
|
-
if ("slippage" in params) {
|
|
9789
|
-
if (!(Number(params?.slippage) <= 1 && Number(params?.slippage) > 0)) {
|
|
9790
|
-
throw new Error(Errors[4003 /* Invalid_slippage */]);
|
|
9791
|
-
}
|
|
9792
|
-
}
|
|
9793
|
-
if ("amount" in params) {
|
|
9794
|
-
if (Number(params.amount) === Number.NaN || Number(params.amount) < 0) {
|
|
9795
|
-
throw new Error(Errors[4004 /* Invalid_Amount */]);
|
|
9796
|
-
}
|
|
9797
|
-
}
|
|
9798
|
-
const { tokenAddress, contractAddress, chainId: chainId2, amount, decimals, account } = params;
|
|
9799
|
-
if (amount && chainId2 && decimals && account) {
|
|
9800
|
-
const amountIn = parseUnits2(amount.toString(), decimals);
|
|
9801
|
-
if (tokenAddress) {
|
|
9802
|
-
const balance = await getBalanceOf(chainId2, account, tokenAddress);
|
|
9803
|
-
if (!balance || balance < amountIn) {
|
|
9804
|
-
throw new Error(Errors[3 /* Insufficient_Balance */]);
|
|
9805
|
-
}
|
|
9806
|
-
}
|
|
9807
|
-
if (contractAddress && tokenAddress) {
|
|
9808
|
-
const isApproved = await getAllowanceApproved(chainId2, account, tokenAddress, contractAddress, amountIn);
|
|
9809
|
-
if (!isApproved) {
|
|
9810
|
-
await approve(chainId2, account, tokenAddress, contractAddress, MaxUint256);
|
|
9811
|
-
}
|
|
9812
|
-
}
|
|
9813
|
-
}
|
|
9814
|
-
};
|
|
9815
|
-
|
|
9816
|
-
// src/common/tradingGas.ts
|
|
9817
|
-
import { parseUnits as parseUnits3 } from "ethers";
|
|
9818
|
-
|
|
9819
|
-
// src/config/decimals.ts
|
|
9820
|
-
var COMMON_CONFIG_DECIMALS = 8;
|
|
9821
|
-
var COMMON_PRICE_DECIMALS = 30;
|
|
9822
|
-
var COMMON_LP_AMOUNT_DECIMALS = 18;
|
|
9823
|
-
|
|
9824
|
-
// src/common/tradingGas.ts
|
|
9825
|
-
var bigintTradingGasToRatioCalculator = (gas, ratio) => {
|
|
9826
|
-
return gas * parseUnits3(ratio.toString(), COMMON_CONFIG_DECIMALS) / BigInt(10 ** COMMON_CONFIG_DECIMALS);
|
|
10253
|
+
[4 /* Insufficient_Amount_Of_Approved */]: `Insufficient Amount Of Approved`,
|
|
10254
|
+
[4002 /* Invalid_Base */]: `Invalid Base Token Address`,
|
|
10255
|
+
[4003 /* Invalid_slippage */]: `Invalid Slippage`,
|
|
10256
|
+
[4004 /* Invalid_Amount */]: `Invalid Amount`,
|
|
10257
|
+
[4005 /* Invalid_Pool_State */]: `Invalid Pool State`,
|
|
10258
|
+
[4006 /* Invalid_Params */]: `Invalid Params`
|
|
9827
10259
|
};
|
|
9828
|
-
|
|
9829
|
-
|
|
9830
|
-
|
|
9831
|
-
|
|
9832
|
-
|
|
9833
|
-
if (!gasPrice) {
|
|
9834
|
-
throw new Error("Network Error");
|
|
9835
|
-
}
|
|
9836
|
-
const gasPriceWithRatio = bigintTradingGasToRatioCalculator(gasPrice, chainInfo.gasPriceRatio);
|
|
10260
|
+
function didUserReject(error) {
|
|
10261
|
+
return error?.code === 4001 /* USER_REJECTED_REQUEST */;
|
|
10262
|
+
}
|
|
10263
|
+
async function getErrorTextFormError(error) {
|
|
10264
|
+
if (didUserReject(error)) {
|
|
9837
10265
|
return {
|
|
9838
|
-
|
|
10266
|
+
error: Errors[4001 /* USER_REJECTED_REQUEST */]
|
|
9839
10267
|
};
|
|
9840
|
-
} catch (e) {
|
|
9841
|
-
throw e;
|
|
9842
10268
|
}
|
|
9843
|
-
|
|
9844
|
-
|
|
9845
|
-
|
|
9846
|
-
|
|
9847
|
-
|
|
9848
|
-
|
|
9849
|
-
// src/lp/base/claim.ts
|
|
9850
|
-
import { parseUnits as parseUnits4 } from "ethers";
|
|
9851
|
-
|
|
9852
|
-
// src/api/request.ts
|
|
9853
|
-
import wretch from "wretch";
|
|
9854
|
-
var client = wretch();
|
|
9855
|
-
var buildQueryOptions = (url, params) => {
|
|
9856
|
-
if (params) {
|
|
9857
|
-
params = JSON.parse(JSON.stringify(params));
|
|
9858
|
-
if (url.includes("?")) {
|
|
9859
|
-
return url + "&" + new URLSearchParams(params).toString();
|
|
9860
|
-
}
|
|
9861
|
-
return url + "?" + new URLSearchParams(params).toString();
|
|
10269
|
+
const decodeErrorResult = await errorDecoder.decode(error);
|
|
10270
|
+
console.log(decodeErrorResult);
|
|
10271
|
+
if (decodeErrorResult.type === ErrorType.UserRejectError || decodeErrorResult.name === "ACTION_REJECTED") {
|
|
10272
|
+
return {
|
|
10273
|
+
error: Errors[4001 /* USER_REJECTED_REQUEST */]
|
|
10274
|
+
};
|
|
9862
10275
|
}
|
|
9863
|
-
|
|
9864
|
-
|
|
9865
|
-
|
|
9866
|
-
|
|
9867
|
-
|
|
9868
|
-
|
|
9869
|
-
|
|
9870
|
-
|
|
9871
|
-
|
|
9872
|
-
|
|
9873
|
-
/**
|
|
9874
|
-
* Post request
|
|
9875
|
-
*/
|
|
9876
|
-
post: (url, data, options = {}) => {
|
|
9877
|
-
return client.url(url).options(options).post(data).json();
|
|
9878
|
-
},
|
|
9879
|
-
/**
|
|
9880
|
-
* Put request
|
|
9881
|
-
*/
|
|
9882
|
-
put: (url, data, options = {}) => {
|
|
9883
|
-
return client.url(url).options(options).put(data).json();
|
|
9884
|
-
},
|
|
9885
|
-
/**
|
|
9886
|
-
* Delete request
|
|
9887
|
-
*/
|
|
9888
|
-
delete: (url, options = {}) => {
|
|
9889
|
-
return client.url(url).options(options).delete().json();
|
|
10276
|
+
if (decodeErrorResult.type === ErrorType.CustomError) {
|
|
10277
|
+
const errorKey = Object.keys(customErrorMapping).find((k) => k.toLowerCase() === decodeErrorResult.selector.toLowerCase());
|
|
10278
|
+
if (errorKey) {
|
|
10279
|
+
return {
|
|
10280
|
+
error: customErrorMapping[errorKey]
|
|
10281
|
+
};
|
|
10282
|
+
}
|
|
10283
|
+
return {
|
|
10284
|
+
error: error?.reason || decodeErrorResult.reason || error.message || error?.code
|
|
10285
|
+
};
|
|
9890
10286
|
}
|
|
9891
|
-
|
|
9892
|
-
|
|
9893
|
-
|
|
9894
|
-
|
|
9895
|
-
const encodedKey = encodeURIComponent(key);
|
|
9896
|
-
return `${encodedKey}=${encodeURIComponent(typeof value === "number" ? value : `${value}`)}`;
|
|
9897
|
-
}
|
|
9898
|
-
function addQueryParam(query, key) {
|
|
9899
|
-
return encodeQueryParam(key, query[key]);
|
|
9900
|
-
}
|
|
9901
|
-
function addArrayQueryParam(query, key) {
|
|
9902
|
-
const value = query[key];
|
|
9903
|
-
return value.map((v) => encodeQueryParam(key, v)).join("&");
|
|
9904
|
-
}
|
|
9905
|
-
function toQueryString(rawQuery) {
|
|
9906
|
-
const query = rawQuery || {};
|
|
9907
|
-
const keys = Object.keys(query).filter((key) => "undefined" !== typeof query[key]);
|
|
9908
|
-
return keys.map((key) => Array.isArray(query[key]) ? addArrayQueryParam(query, key) : addQueryParam(query, key)).join("&");
|
|
9909
|
-
}
|
|
9910
|
-
function addQueryParams(rawQuery) {
|
|
9911
|
-
const queryString = toQueryString(rawQuery);
|
|
9912
|
-
return queryString ? `?${queryString}` : "";
|
|
10287
|
+
console.error(error);
|
|
10288
|
+
return {
|
|
10289
|
+
error: decodeErrorResult.reason
|
|
10290
|
+
};
|
|
9913
10291
|
}
|
|
9914
10292
|
|
|
9915
|
-
// src/
|
|
9916
|
-
|
|
9917
|
-
|
|
9918
|
-
|
|
9919
|
-
|
|
9920
|
-
|
|
9921
|
-
|
|
9922
|
-
|
|
9923
|
-
|
|
9924
|
-
|
|
9925
|
-
|
|
9926
|
-
|
|
9927
|
-
|
|
9928
|
-
|
|
9929
|
-
|
|
9930
|
-
|
|
9931
|
-
|
|
9932
|
-
|
|
9933
|
-
MarketPoolState3[MarketPoolState3["PreBench"] = 3] = "PreBench";
|
|
9934
|
-
MarketPoolState3[MarketPoolState3["Bench"] = 4] = "Bench";
|
|
9935
|
-
return MarketPoolState3;
|
|
9936
|
-
})(MarketPoolState || {});
|
|
9937
|
-
var OracleType = /* @__PURE__ */ ((OracleType7) => {
|
|
9938
|
-
OracleType7[OracleType7["Chainlink"] = 1] = "Chainlink";
|
|
9939
|
-
OracleType7[OracleType7["Pyth"] = 2] = "Pyth";
|
|
9940
|
-
return OracleType7;
|
|
9941
|
-
})(OracleType || {});
|
|
9942
|
-
var HttpKlineIntervalEnum = /* @__PURE__ */ ((HttpKlineIntervalEnum2) => {
|
|
9943
|
-
HttpKlineIntervalEnum2[HttpKlineIntervalEnum2["Minute1"] = 1] = "Minute1";
|
|
9944
|
-
HttpKlineIntervalEnum2[HttpKlineIntervalEnum2["Minute5"] = 5] = "Minute5";
|
|
9945
|
-
HttpKlineIntervalEnum2[HttpKlineIntervalEnum2["Minute15"] = 15] = "Minute15";
|
|
9946
|
-
HttpKlineIntervalEnum2[HttpKlineIntervalEnum2["Minute30"] = 30] = "Minute30";
|
|
9947
|
-
HttpKlineIntervalEnum2[HttpKlineIntervalEnum2["Hour1"] = 60] = "Hour1";
|
|
9948
|
-
HttpKlineIntervalEnum2[HttpKlineIntervalEnum2["Hour4"] = 240] = "Hour4";
|
|
9949
|
-
HttpKlineIntervalEnum2[HttpKlineIntervalEnum2["Day1"] = 1440] = "Day1";
|
|
9950
|
-
HttpKlineIntervalEnum2[HttpKlineIntervalEnum2["Week1"] = 10080] = "Week1";
|
|
9951
|
-
HttpKlineIntervalEnum2[HttpKlineIntervalEnum2["Month1"] = 40320] = "Month1";
|
|
9952
|
-
return HttpKlineIntervalEnum2;
|
|
9953
|
-
})(HttpKlineIntervalEnum || {});
|
|
9954
|
-
var MarketType = /* @__PURE__ */ ((MarketType2) => {
|
|
9955
|
-
MarketType2[MarketType2["Contract"] = 1] = "Contract";
|
|
9956
|
-
MarketType2[MarketType2["Cook"] = 2] = "Cook";
|
|
9957
|
-
MarketType2[MarketType2["Earn"] = 3] = "Earn";
|
|
9958
|
-
return MarketType2;
|
|
9959
|
-
})(MarketType || {});
|
|
9960
|
-
var SearchTypeEnum = /* @__PURE__ */ ((SearchTypeEnum2) => {
|
|
9961
|
-
SearchTypeEnum2[SearchTypeEnum2["All"] = 0] = "All";
|
|
9962
|
-
SearchTypeEnum2[SearchTypeEnum2["Contract"] = 1 /* Contract */] = "Contract";
|
|
9963
|
-
SearchTypeEnum2[SearchTypeEnum2["Cook"] = 2 /* Cook */] = "Cook";
|
|
9964
|
-
SearchTypeEnum2[SearchTypeEnum2["Earn"] = 3 /* Earn */] = "Earn";
|
|
9965
|
-
return SearchTypeEnum2;
|
|
9966
|
-
})(SearchTypeEnum || {});
|
|
9967
|
-
var MarketCapType = /* @__PURE__ */ ((MarketCapType2) => {
|
|
9968
|
-
MarketCapType2[MarketCapType2["BlueChips"] = 1] = "BlueChips";
|
|
9969
|
-
MarketCapType2[MarketCapType2["Alpha"] = 2] = "Alpha";
|
|
9970
|
-
return MarketCapType2;
|
|
9971
|
-
})(MarketCapType || {});
|
|
9972
|
-
var SearchSecondTypeEnum = /* @__PURE__ */ ((SearchSecondTypeEnum2) => {
|
|
9973
|
-
SearchSecondTypeEnum2[SearchSecondTypeEnum2["BlueChips"] = 1 /* BlueChips */] = "BlueChips";
|
|
9974
|
-
SearchSecondTypeEnum2[SearchSecondTypeEnum2["Alpha"] = 2 /* Alpha */] = "Alpha";
|
|
9975
|
-
SearchSecondTypeEnum2[SearchSecondTypeEnum2["Favorite"] = 3] = "Favorite";
|
|
9976
|
-
return SearchSecondTypeEnum2;
|
|
9977
|
-
})(SearchSecondTypeEnum || {});
|
|
9978
|
-
|
|
9979
|
-
// src/api/account/index.ts
|
|
9980
|
-
var OrderTypeEnum = /* @__PURE__ */ ((OrderTypeEnum2) => {
|
|
9981
|
-
OrderTypeEnum2[OrderTypeEnum2["Market"] = 0] = "Market";
|
|
9982
|
-
OrderTypeEnum2[OrderTypeEnum2["Limit"] = 1] = "Limit";
|
|
9983
|
-
OrderTypeEnum2[OrderTypeEnum2["Stop"] = 2] = "Stop";
|
|
9984
|
-
OrderTypeEnum2[OrderTypeEnum2["Conditional"] = 3] = "Conditional";
|
|
9985
|
-
return OrderTypeEnum2;
|
|
9986
|
-
})(OrderTypeEnum || {});
|
|
9987
|
-
var OperationEnum = /* @__PURE__ */ ((OperationEnum2) => {
|
|
9988
|
-
OperationEnum2[OperationEnum2["Increase"] = 0] = "Increase";
|
|
9989
|
-
OperationEnum2[OperationEnum2["Decrease"] = 1] = "Decrease";
|
|
9990
|
-
return OperationEnum2;
|
|
9991
|
-
})(OperationEnum || {});
|
|
9992
|
-
var TriggerTypeEnum = /* @__PURE__ */ ((TriggerTypeEnum2) => {
|
|
9993
|
-
TriggerTypeEnum2[TriggerTypeEnum2["Unknown"] = 0] = "Unknown";
|
|
9994
|
-
TriggerTypeEnum2[TriggerTypeEnum2["GTE"] = 1] = "GTE";
|
|
9995
|
-
TriggerTypeEnum2[TriggerTypeEnum2["LTE"] = 2] = "LTE";
|
|
9996
|
-
return TriggerTypeEnum2;
|
|
9997
|
-
})(TriggerTypeEnum || {});
|
|
9998
|
-
var DirectionEnum = /* @__PURE__ */ ((DirectionEnum2) => {
|
|
9999
|
-
DirectionEnum2[DirectionEnum2["Long"] = 0] = "Long";
|
|
10000
|
-
DirectionEnum2[DirectionEnum2["Short"] = 1] = "Short";
|
|
10001
|
-
return DirectionEnum2;
|
|
10002
|
-
})(DirectionEnum || {});
|
|
10003
|
-
var OrderStatusEnum = /* @__PURE__ */ ((OrderStatusEnum2) => {
|
|
10004
|
-
OrderStatusEnum2[OrderStatusEnum2["Cancelled"] = 1] = "Cancelled";
|
|
10005
|
-
OrderStatusEnum2[OrderStatusEnum2["Expired"] = 2] = "Expired";
|
|
10006
|
-
OrderStatusEnum2[OrderStatusEnum2["Successful"] = 9] = "Successful";
|
|
10007
|
-
return OrderStatusEnum2;
|
|
10008
|
-
})(OrderStatusEnum || {});
|
|
10009
|
-
var ExecTypeEnum = /* @__PURE__ */ ((ExecTypeEnum2) => {
|
|
10010
|
-
ExecTypeEnum2[ExecTypeEnum2["UserEntrust"] = 0] = "UserEntrust";
|
|
10011
|
-
ExecTypeEnum2[ExecTypeEnum2["Liquidation"] = 1] = "Liquidation";
|
|
10012
|
-
ExecTypeEnum2[ExecTypeEnum2["Adl"] = 2] = "Adl";
|
|
10013
|
-
ExecTypeEnum2[ExecTypeEnum2["AdlTrigger"] = 3] = "AdlTrigger";
|
|
10014
|
-
return ExecTypeEnum2;
|
|
10015
|
-
})(ExecTypeEnum || {});
|
|
10016
|
-
var getHistoryOrders = async ({
|
|
10017
|
-
accessToken,
|
|
10018
|
-
...params
|
|
10019
|
-
}) => {
|
|
10020
|
-
return http.get(
|
|
10021
|
-
`${baseUrl}/openapi/gateway/scan/order/closed`,
|
|
10022
|
-
params,
|
|
10023
|
-
{
|
|
10024
|
-
headers: {
|
|
10025
|
-
myx_openapi_access_token: accessToken
|
|
10026
|
-
}
|
|
10027
|
-
}
|
|
10028
|
-
);
|
|
10029
|
-
};
|
|
10030
|
-
var CloseTypeEnum = /* @__PURE__ */ ((CloseTypeEnum2) => {
|
|
10031
|
-
CloseTypeEnum2[CloseTypeEnum2["Open"] = 0] = "Open";
|
|
10032
|
-
CloseTypeEnum2[CloseTypeEnum2["PartialClose"] = 1] = "PartialClose";
|
|
10033
|
-
CloseTypeEnum2[CloseTypeEnum2["FullClose"] = 2] = "FullClose";
|
|
10034
|
-
CloseTypeEnum2[CloseTypeEnum2["Liquidation"] = 3] = "Liquidation";
|
|
10035
|
-
CloseTypeEnum2[CloseTypeEnum2["EarlyClose"] = 4] = "EarlyClose";
|
|
10036
|
-
CloseTypeEnum2[CloseTypeEnum2["MarketClose"] = 5] = "MarketClose";
|
|
10037
|
-
CloseTypeEnum2[CloseTypeEnum2["ADL"] = 6] = "ADL";
|
|
10038
|
-
CloseTypeEnum2[CloseTypeEnum2["TP"] = 7] = "TP";
|
|
10039
|
-
CloseTypeEnum2[CloseTypeEnum2["SL"] = 8] = "SL";
|
|
10040
|
-
CloseTypeEnum2[CloseTypeEnum2["Increase"] = 9] = "Increase";
|
|
10041
|
-
return CloseTypeEnum2;
|
|
10042
|
-
})(CloseTypeEnum || {});
|
|
10043
|
-
var getPositionHistory = async ({
|
|
10044
|
-
accessToken,
|
|
10045
|
-
...params
|
|
10046
|
-
}) => {
|
|
10047
|
-
return http.get(
|
|
10048
|
-
`${baseUrl}/openapi/gateway/scan/position/closed`,
|
|
10049
|
-
params,
|
|
10050
|
-
{
|
|
10051
|
-
headers: {
|
|
10052
|
-
myx_openapi_access_token: accessToken
|
|
10053
|
-
}
|
|
10054
|
-
}
|
|
10055
|
-
);
|
|
10293
|
+
// src/common/balanceOf.ts
|
|
10294
|
+
import { ethers as ethers2 } from "ethers";
|
|
10295
|
+
var getBalanceOf = async (chainId, account, tokenAddress) => {
|
|
10296
|
+
try {
|
|
10297
|
+
const provider = getJSONProvider(chainId);
|
|
10298
|
+
const contractInterface = new ethers2.Interface(IERC20Metadata_default);
|
|
10299
|
+
const data = contractInterface.encodeFunctionData("balanceOf", [account]);
|
|
10300
|
+
const callData = {
|
|
10301
|
+
to: tokenAddress,
|
|
10302
|
+
data
|
|
10303
|
+
};
|
|
10304
|
+
const result = await provider.call(callData);
|
|
10305
|
+
const balance = BigInt(result);
|
|
10306
|
+
return balance;
|
|
10307
|
+
} catch (e) {
|
|
10308
|
+
console.error(e);
|
|
10309
|
+
throw e;
|
|
10310
|
+
}
|
|
10056
10311
|
};
|
|
10057
|
-
|
|
10058
|
-
|
|
10059
|
-
|
|
10060
|
-
|
|
10061
|
-
|
|
10062
|
-
|
|
10063
|
-
|
|
10064
|
-
|
|
10065
|
-
|
|
10066
|
-
|
|
10067
|
-
|
|
10312
|
+
|
|
10313
|
+
// src/common/checkParams.ts
|
|
10314
|
+
import { MaxUint256, parseUnits as parseUnits2 } from "ethers";
|
|
10315
|
+
|
|
10316
|
+
// src/common/allowance.ts
|
|
10317
|
+
import { ethers as ethers3 } from "ethers";
|
|
10318
|
+
var getAllowanceApproved = async (chainId, account, tokenAddress, approveAddress, approveAmount) => {
|
|
10319
|
+
try {
|
|
10320
|
+
const provider = getJSONProvider(chainId);
|
|
10321
|
+
const contractInterface = new ethers3.Interface(IERC20Metadata_default);
|
|
10322
|
+
const data = contractInterface.encodeFunctionData("allowance", [account, approveAddress]);
|
|
10323
|
+
const callData = {
|
|
10324
|
+
to: tokenAddress,
|
|
10325
|
+
data
|
|
10326
|
+
};
|
|
10327
|
+
const result = await provider.call(callData);
|
|
10328
|
+
const allowance = BigInt(result);
|
|
10329
|
+
if (allowance >= approveAmount) {
|
|
10330
|
+
return true;
|
|
10068
10331
|
}
|
|
10069
|
-
|
|
10332
|
+
return false;
|
|
10333
|
+
} catch (e) {
|
|
10334
|
+
throw e;
|
|
10335
|
+
}
|
|
10070
10336
|
};
|
|
10071
10337
|
|
|
10072
|
-
// src/
|
|
10073
|
-
var
|
|
10074
|
-
|
|
10075
|
-
|
|
10076
|
-
|
|
10077
|
-
|
|
10078
|
-
|
|
10079
|
-
|
|
10338
|
+
// src/common/approve.ts
|
|
10339
|
+
var approve = async (chainId, account, tokenAddress, approveAddress, amount) => {
|
|
10340
|
+
try {
|
|
10341
|
+
const TokenContract = await getERC20Contract(chainId, tokenAddress);
|
|
10342
|
+
const response = await TokenContract.approve(approveAddress, amount);
|
|
10343
|
+
const receipt = await response?.wait();
|
|
10344
|
+
const isApproved = await getAllowanceApproved(chainId, account, tokenAddress, approveAddress, amount);
|
|
10345
|
+
if (!isApproved) {
|
|
10346
|
+
throw new Error(Errors[4 /* Insufficient_Amount_Of_Approved */]);
|
|
10347
|
+
}
|
|
10348
|
+
} catch (e) {
|
|
10349
|
+
throw e;
|
|
10080
10350
|
}
|
|
10081
|
-
return Promise.reject(new Error("Invalid pool id"));
|
|
10082
|
-
};
|
|
10083
|
-
var getPoolLevelConfig = async ({
|
|
10084
|
-
poolId,
|
|
10085
|
-
chainId: chainId2
|
|
10086
|
-
}) => {
|
|
10087
|
-
return http.get(
|
|
10088
|
-
`${baseUrl}/openapi/gateway/risk/market_pool/level_config${addQueryParams({
|
|
10089
|
-
poolId,
|
|
10090
|
-
chainId: chainId2
|
|
10091
|
-
})}`
|
|
10092
|
-
);
|
|
10093
|
-
};
|
|
10094
|
-
var getPoolDetail = async (chainId2, poolId) => {
|
|
10095
|
-
return await http.get(
|
|
10096
|
-
`${baseUrl}/openapi/gateway/scan/market/detail?chainId=${chainId2}&poolId=${poolId}`
|
|
10097
|
-
);
|
|
10098
10351
|
};
|
|
10099
|
-
|
|
10100
|
-
|
|
10101
|
-
|
|
10102
|
-
|
|
10103
|
-
|
|
10104
|
-
{
|
|
10105
|
-
|
|
10106
|
-
myx_openapi_access_token: accessToken
|
|
10107
|
-
}
|
|
10352
|
+
|
|
10353
|
+
// src/common/checkParams.ts
|
|
10354
|
+
var checkParams = async (params) => {
|
|
10355
|
+
if ("chainId" in params) {
|
|
10356
|
+
const valid = isSupportedChainFn(params.chainId);
|
|
10357
|
+
if (!valid) {
|
|
10358
|
+
throw new Error(Errors[1 /* Invalid_Chain_ID */]);
|
|
10108
10359
|
}
|
|
10109
|
-
|
|
10110
|
-
|
|
10111
|
-
|
|
10112
|
-
|
|
10113
|
-
`${baseUrl}/openapi/gateway/scan/order/open?chainId=${chainId2}`,
|
|
10114
|
-
void 0,
|
|
10115
|
-
{ headers: { myx_openapi_access_token: accessToken } }
|
|
10116
|
-
);
|
|
10117
|
-
};
|
|
10118
|
-
var getPoolOpenOrders = async (accessToken, chainId2) => {
|
|
10119
|
-
return await http.get(
|
|
10120
|
-
`${baseUrl}/openapi/gateway/scan/market/pool-order/open?chainId=${chainId2}`,
|
|
10121
|
-
void 0,
|
|
10122
|
-
{ headers: { myx_openapi_access_token: accessToken } }
|
|
10123
|
-
);
|
|
10124
|
-
};
|
|
10125
|
-
var getKlineData = ({
|
|
10126
|
-
chainId: chainId2,
|
|
10127
|
-
poolId,
|
|
10128
|
-
endTime,
|
|
10129
|
-
limit,
|
|
10130
|
-
interval
|
|
10131
|
-
}) => {
|
|
10132
|
-
return http.get(
|
|
10133
|
-
`${baseUrl}/openapi/gateway/quote/candles`,
|
|
10134
|
-
{
|
|
10135
|
-
chainId: chainId2,
|
|
10136
|
-
poolId,
|
|
10137
|
-
endTime,
|
|
10138
|
-
limit,
|
|
10139
|
-
interval
|
|
10360
|
+
}
|
|
10361
|
+
if ("slippage" in params) {
|
|
10362
|
+
if (!(Number(params?.slippage) <= 1 && Number(params?.slippage) > 0)) {
|
|
10363
|
+
throw new Error(Errors[4003 /* Invalid_slippage */]);
|
|
10140
10364
|
}
|
|
10141
|
-
|
|
10142
|
-
|
|
10143
|
-
|
|
10144
|
-
|
|
10145
|
-
`${baseUrl}/openapi/gateway/quote/candle/latest`,
|
|
10146
|
-
params
|
|
10147
|
-
);
|
|
10148
|
-
};
|
|
10149
|
-
var getTickerData = async ({
|
|
10150
|
-
chainId: chainId2,
|
|
10151
|
-
poolIds
|
|
10152
|
-
}) => {
|
|
10153
|
-
return http.get(
|
|
10154
|
-
`${baseUrl}/openapi/gateway/quote/candle/tickers`,
|
|
10155
|
-
{
|
|
10156
|
-
chainId: chainId2,
|
|
10157
|
-
poolIds: poolIds.join(",")
|
|
10365
|
+
}
|
|
10366
|
+
if ("amount" in params) {
|
|
10367
|
+
if (Number(params.amount) === Number.NaN || Number(params.amount) < 0) {
|
|
10368
|
+
throw new Error(Errors[4004 /* Invalid_Amount */]);
|
|
10158
10369
|
}
|
|
10159
|
-
|
|
10160
|
-
};
|
|
10161
|
-
|
|
10162
|
-
|
|
10163
|
-
|
|
10164
|
-
|
|
10165
|
-
|
|
10166
|
-
|
|
10167
|
-
accessToken,
|
|
10168
|
-
...params
|
|
10169
|
-
}) => {
|
|
10170
|
-
return http.get(
|
|
10171
|
-
`${baseUrl}/openapi/gateway/scan/market/ac-search`,
|
|
10172
|
-
params,
|
|
10173
|
-
{
|
|
10174
|
-
headers: {
|
|
10175
|
-
myx_openapi_access_token: accessToken
|
|
10370
|
+
}
|
|
10371
|
+
const { tokenAddress, contractAddress, chainId, amount, decimals, account } = params;
|
|
10372
|
+
if (amount && chainId && decimals && account) {
|
|
10373
|
+
const amountIn = parseUnits2(amount.toString(), decimals);
|
|
10374
|
+
if (tokenAddress) {
|
|
10375
|
+
const balance = await getBalanceOf(chainId, account, tokenAddress);
|
|
10376
|
+
if (!balance || balance < amountIn) {
|
|
10377
|
+
throw new Error(Errors[3 /* Insufficient_Balance */]);
|
|
10176
10378
|
}
|
|
10177
10379
|
}
|
|
10178
|
-
|
|
10179
|
-
|
|
10180
|
-
|
|
10181
|
-
|
|
10182
|
-
`${baseUrl}/openapi/gateway/scan/market/search`,
|
|
10183
|
-
params
|
|
10184
|
-
);
|
|
10185
|
-
};
|
|
10186
|
-
var addFavorite = async ({
|
|
10187
|
-
accessToken,
|
|
10188
|
-
...params
|
|
10189
|
-
}) => {
|
|
10190
|
-
return http.get(
|
|
10191
|
-
`${baseUrl}/openapi/gateway/scan/market/add-favorites`,
|
|
10192
|
-
params,
|
|
10193
|
-
{
|
|
10194
|
-
headers: {
|
|
10195
|
-
myx_openapi_access_token: accessToken
|
|
10380
|
+
if (contractAddress && tokenAddress) {
|
|
10381
|
+
const isApproved = await getAllowanceApproved(chainId, account, tokenAddress, contractAddress, amountIn);
|
|
10382
|
+
if (!isApproved) {
|
|
10383
|
+
await approve(chainId, account, tokenAddress, contractAddress, MaxUint256);
|
|
10196
10384
|
}
|
|
10197
10385
|
}
|
|
10198
|
-
|
|
10386
|
+
}
|
|
10199
10387
|
};
|
|
10200
|
-
|
|
10201
|
-
|
|
10202
|
-
|
|
10203
|
-
|
|
10204
|
-
|
|
10205
|
-
|
|
10206
|
-
|
|
10207
|
-
|
|
10208
|
-
|
|
10209
|
-
|
|
10210
|
-
|
|
10211
|
-
|
|
10212
|
-
);
|
|
10388
|
+
|
|
10389
|
+
// src/common/tradingGas.ts
|
|
10390
|
+
import { parseUnits as parseUnits3 } from "ethers";
|
|
10391
|
+
|
|
10392
|
+
// src/config/decimals.ts
|
|
10393
|
+
var COMMON_CONFIG_DECIMALS = 8;
|
|
10394
|
+
var COMMON_PRICE_DECIMALS = 30;
|
|
10395
|
+
var COMMON_LP_AMOUNT_DECIMALS = 18;
|
|
10396
|
+
|
|
10397
|
+
// src/common/tradingGas.ts
|
|
10398
|
+
var bigintTradingGasToRatioCalculator = (gas, ratio) => {
|
|
10399
|
+
return gas * parseUnits3(ratio.toString(), COMMON_CONFIG_DECIMALS) / BigInt(10 ** COMMON_CONFIG_DECIMALS);
|
|
10213
10400
|
};
|
|
10214
|
-
var
|
|
10215
|
-
|
|
10216
|
-
|
|
10217
|
-
|
|
10218
|
-
|
|
10219
|
-
|
|
10220
|
-
|
|
10221
|
-
{
|
|
10222
|
-
headers: {
|
|
10223
|
-
myx_openapi_access_token: accessToken
|
|
10224
|
-
}
|
|
10401
|
+
var bigintTradingGasPriceWithRatio = async (chainId) => {
|
|
10402
|
+
try {
|
|
10403
|
+
const chainInfo = CHAIN_INFO[chainId];
|
|
10404
|
+
const provider = getJSONProvider(chainId);
|
|
10405
|
+
const { gasPrice } = await provider.getFeeData();
|
|
10406
|
+
if (!gasPrice) {
|
|
10407
|
+
throw new Error("Network Error");
|
|
10225
10408
|
}
|
|
10226
|
-
|
|
10227
|
-
|
|
10228
|
-
|
|
10229
|
-
|
|
10230
|
-
|
|
10231
|
-
|
|
10232
|
-
|
|
10409
|
+
const gasPriceWithRatio = bigintTradingGasToRatioCalculator(gasPrice, chainInfo.gasPriceRatio);
|
|
10410
|
+
return {
|
|
10411
|
+
gasPrice: gasPriceWithRatio
|
|
10412
|
+
};
|
|
10413
|
+
} catch (e) {
|
|
10414
|
+
throw e;
|
|
10415
|
+
}
|
|
10233
10416
|
};
|
|
10234
|
-
var
|
|
10235
|
-
|
|
10236
|
-
|
|
10237
|
-
params
|
|
10238
|
-
);
|
|
10417
|
+
var bigintAmountSlipperCalculator = (amount, slipper = 0.01) => {
|
|
10418
|
+
const radio = parseUnits3("1", COMMON_CONFIG_DECIMALS) - parseUnits3(slipper.toString(), COMMON_CONFIG_DECIMALS);
|
|
10419
|
+
return amount * radio / BigInt(10 ** COMMON_CONFIG_DECIMALS);
|
|
10239
10420
|
};
|
|
10240
10421
|
|
|
10422
|
+
// src/lp/base/claim.ts
|
|
10423
|
+
import { parseUnits as parseUnits4 } from "ethers";
|
|
10424
|
+
|
|
10241
10425
|
// src/common/price.ts
|
|
10242
10426
|
import { isNil } from "lodash-es";
|
|
10243
|
-
var parsePriceData = async (
|
|
10427
|
+
var parsePriceData = async (chainId, data) => {
|
|
10244
10428
|
const result = await Promise.all(
|
|
10245
10429
|
data.map(async (item) => {
|
|
10246
10430
|
const { publishTime, vaa, oracleType, nativeFee, price, poolId } = item;
|
|
10247
10431
|
let value = !isNil(nativeFee) ? BigInt(nativeFee) : 1n;
|
|
10248
10432
|
if (oracleType === 2 /* Pyth */) {
|
|
10249
|
-
const PythContract = await getPythContract(
|
|
10433
|
+
const PythContract = await getPythContract(chainId);
|
|
10250
10434
|
const v = await PythContract.getUpdateFee([vaa]);
|
|
10251
10435
|
value = v;
|
|
10252
10436
|
}
|
|
@@ -10262,34 +10446,34 @@ var parsePriceData = async (chainId2, data) => {
|
|
|
10262
10446
|
);
|
|
10263
10447
|
return result;
|
|
10264
10448
|
};
|
|
10265
|
-
var getPricesData = async (
|
|
10449
|
+
var getPricesData = async (chainId, poolIds) => {
|
|
10266
10450
|
if (!poolIds || !poolIds.length) return;
|
|
10267
|
-
const rs = await getOraclePrice(
|
|
10268
|
-
const result = await parsePriceData(
|
|
10451
|
+
const rs = await getOraclePrice(chainId, poolIds);
|
|
10452
|
+
const result = await parsePriceData(chainId, rs.data);
|
|
10269
10453
|
return result;
|
|
10270
10454
|
};
|
|
10271
|
-
var getPriceData = async (
|
|
10455
|
+
var getPriceData = async (chainId, poolId) => {
|
|
10272
10456
|
if (!poolId) return;
|
|
10273
|
-
const rs = await getOraclePrice(
|
|
10457
|
+
const rs = await getOraclePrice(chainId, [poolId]);
|
|
10274
10458
|
const data = rs?.data?.[0];
|
|
10275
10459
|
if (!data) {
|
|
10276
10460
|
throw new Error(`Unable to get price for ${poolId} in the deposit`);
|
|
10277
10461
|
}
|
|
10278
|
-
const result = await parsePriceData(
|
|
10462
|
+
const result = await parsePriceData(chainId, [data]);
|
|
10279
10463
|
return result?.[0];
|
|
10280
10464
|
};
|
|
10281
10465
|
|
|
10282
10466
|
// src/lp/base/claim.ts
|
|
10283
10467
|
var claimBasePoolRebate = async (params) => {
|
|
10284
10468
|
try {
|
|
10285
|
-
const { chainId
|
|
10286
|
-
const chainInfo = CHAIN_INFO[
|
|
10287
|
-
const account = await getAccount(
|
|
10469
|
+
const { chainId, poolId } = params;
|
|
10470
|
+
const chainInfo = CHAIN_INFO[chainId];
|
|
10471
|
+
const account = await getAccount(chainId);
|
|
10288
10472
|
await checkParams({
|
|
10289
10473
|
account,
|
|
10290
|
-
chainId
|
|
10474
|
+
chainId
|
|
10291
10475
|
});
|
|
10292
|
-
const priceResponse = await getPricesData(
|
|
10476
|
+
const priceResponse = await getPricesData(chainId, [poolId]);
|
|
10293
10477
|
if (!priceResponse) return;
|
|
10294
10478
|
const values = priceResponse.map((item) => {
|
|
10295
10479
|
return item.value;
|
|
@@ -10309,12 +10493,12 @@ var claimBasePoolRebate = async (params) => {
|
|
|
10309
10493
|
poolId,
|
|
10310
10494
|
recipient: account
|
|
10311
10495
|
};
|
|
10312
|
-
const contract = await getLiquidityRouterContract(
|
|
10496
|
+
const contract = await getLiquidityRouterContract(chainId);
|
|
10313
10497
|
const _gasLimit = await contract["claimBasePoolRebate((bytes32,uint8,uint256,bytes,uint64)[],bytes32,address)"].estimateGas(prices, poolId, account, {
|
|
10314
10498
|
value: values[0]
|
|
10315
10499
|
});
|
|
10316
10500
|
const gasLimit = bigintTradingGasToRatioCalculator(_gasLimit, chainInfo.gasLimitRatio);
|
|
10317
|
-
const { gasPrice } = await bigintTradingGasPriceWithRatio(
|
|
10501
|
+
const { gasPrice } = await bigintTradingGasPriceWithRatio(chainId);
|
|
10318
10502
|
const response = await contract["claimBasePoolRebate((bytes32,uint8,uint256,bytes,uint64)[],bytes32,address)"](prices, poolId, account, {
|
|
10319
10503
|
gasLimit,
|
|
10320
10504
|
gasPrice,
|
|
@@ -10328,15 +10512,15 @@ var claimBasePoolRebate = async (params) => {
|
|
|
10328
10512
|
};
|
|
10329
10513
|
var claimBasePoolRebates = async (params) => {
|
|
10330
10514
|
try {
|
|
10331
|
-
const { chainId
|
|
10515
|
+
const { chainId, poolIds } = params;
|
|
10332
10516
|
if (poolIds.length === 0) return;
|
|
10333
|
-
const chainInfo = CHAIN_INFO[
|
|
10334
|
-
const account = await getAccount(
|
|
10517
|
+
const chainInfo = CHAIN_INFO[chainId];
|
|
10518
|
+
const account = await getAccount(chainId);
|
|
10335
10519
|
await checkParams({
|
|
10336
10520
|
account,
|
|
10337
|
-
chainId
|
|
10521
|
+
chainId
|
|
10338
10522
|
});
|
|
10339
|
-
const priceData = await getPricesData(
|
|
10523
|
+
const priceData = await getPricesData(chainId, poolIds);
|
|
10340
10524
|
if (!priceData) return;
|
|
10341
10525
|
const prices = priceData.map((item) => {
|
|
10342
10526
|
return {
|
|
@@ -10355,12 +10539,12 @@ var claimBasePoolRebates = async (params) => {
|
|
|
10355
10539
|
value,
|
|
10356
10540
|
recipient: account
|
|
10357
10541
|
};
|
|
10358
|
-
const contract = await getLiquidityRouterContract(
|
|
10542
|
+
const contract = await getLiquidityRouterContract(chainId);
|
|
10359
10543
|
const _gasLimit = await contract["claimBasePoolRebates((bytes32,uint8,uint256,bytes,uint64)[],bytes32[],address)"].estimateGas(prices, poolIds, account, {
|
|
10360
10544
|
value
|
|
10361
10545
|
});
|
|
10362
10546
|
const gasLimit = bigintTradingGasToRatioCalculator(_gasLimit, chainInfo.gasLimitRatio);
|
|
10363
|
-
const { gasPrice } = await bigintTradingGasPriceWithRatio(
|
|
10547
|
+
const { gasPrice } = await bigintTradingGasPriceWithRatio(chainId);
|
|
10364
10548
|
const response = await contract["claimBasePoolRebates((bytes32,uint8,uint256,bytes,uint64)[],bytes32[],address)"](prices, poolIds, account, {
|
|
10365
10549
|
gasLimit,
|
|
10366
10550
|
gasPrice,
|
|
@@ -10378,33 +10562,13 @@ import { parseUnits as parseUnits7 } from "ethers";
|
|
|
10378
10562
|
|
|
10379
10563
|
// src/lp/base/preview.ts
|
|
10380
10564
|
import { parseUnits as parseUnits5 } from "ethers";
|
|
10381
|
-
|
|
10382
|
-
// src/config/market/ARB_TEST_SEPOLIA.ts
|
|
10383
|
-
var ARB_TEST_SEPOLIA2 = {
|
|
10384
|
-
marketId: "0x1ddd0797c40b61b1437e0c455a78470e7c0659ed497d94222425736210f9d08c",
|
|
10385
|
-
quoteToken: "0x7E248Ec1721639413A280d9E82e2862Cae2E6E28",
|
|
10386
|
-
oracleFeeUsd: 400000000n,
|
|
10387
|
-
oracleRefundFeeUsd: 300000000n,
|
|
10388
|
-
baseReserveRatio: 100,
|
|
10389
|
-
quoteReserveRatio: 100,
|
|
10390
|
-
poolPrimeThreshold: 20000n,
|
|
10391
|
-
decimals: 6,
|
|
10392
|
-
lpDecimals: COMMON_LP_AMOUNT_DECIMALS
|
|
10393
|
-
};
|
|
10394
|
-
|
|
10395
|
-
// src/config/market/index.ts
|
|
10396
|
-
var Market = {
|
|
10397
|
-
[421614 /* ARB_TESTNET */]: ARB_TEST_SEPOLIA2
|
|
10398
|
-
};
|
|
10399
|
-
|
|
10400
|
-
// src/lp/base/preview.ts
|
|
10401
|
-
var previewLpAmountOut = async ({ chainId: chainId2, amountIn, poolId, price = 0n }) => {
|
|
10565
|
+
var previewLpAmountOut = async ({ chainId, amountIn, poolId, price = 0n }) => {
|
|
10402
10566
|
try {
|
|
10403
|
-
const chainInfo = CHAIN_INFO[
|
|
10404
|
-
const basePoolContract = await getBasePoolContract(
|
|
10567
|
+
const chainInfo = CHAIN_INFO[chainId];
|
|
10568
|
+
const basePoolContract = await getBasePoolContract(chainId);
|
|
10405
10569
|
const _gasLimit = await basePoolContract.previewLpAmountOut.estimateGas(poolId, amountIn, price);
|
|
10406
10570
|
const gasLimit = bigintTradingGasToRatioCalculator(_gasLimit, chainInfo.gasLimitRatio);
|
|
10407
|
-
const { gasPrice } = await bigintTradingGasPriceWithRatio(
|
|
10571
|
+
const { gasPrice } = await bigintTradingGasPriceWithRatio(chainId);
|
|
10408
10572
|
const request = await basePoolContract.previewLpAmountOut(poolId, amountIn, price, {
|
|
10409
10573
|
gasLimit,
|
|
10410
10574
|
gasPrice
|
|
@@ -10415,13 +10579,13 @@ var previewLpAmountOut = async ({ chainId: chainId2, amountIn, poolId, price = 0
|
|
|
10415
10579
|
throw typeof error === "string" ? error : await getErrorTextFormError(error);
|
|
10416
10580
|
}
|
|
10417
10581
|
};
|
|
10418
|
-
var previewBaseAmountOut = async ({ chainId
|
|
10582
|
+
var previewBaseAmountOut = async ({ chainId, amountIn, poolId, price = 0n }) => {
|
|
10419
10583
|
try {
|
|
10420
|
-
const chainInfo = CHAIN_INFO[
|
|
10421
|
-
const basePoolContract = await getBasePoolContract(
|
|
10584
|
+
const chainInfo = CHAIN_INFO[chainId];
|
|
10585
|
+
const basePoolContract = await getBasePoolContract(chainId);
|
|
10422
10586
|
const _gasLimit = await basePoolContract.previewBaseAmountOut.estimateGas(poolId, amountIn, price);
|
|
10423
10587
|
const gasLimit = bigintTradingGasToRatioCalculator(_gasLimit, chainInfo.gasLimitRatio);
|
|
10424
|
-
const { gasPrice } = await bigintTradingGasPriceWithRatio(
|
|
10588
|
+
const { gasPrice } = await bigintTradingGasPriceWithRatio(chainId);
|
|
10425
10589
|
const request = await basePoolContract.previewBaseAmountOut(poolId, amountIn, price, {
|
|
10426
10590
|
gasLimit,
|
|
10427
10591
|
gasPrice
|
|
@@ -10432,32 +10596,32 @@ var previewBaseAmountOut = async ({ chainId: chainId2, amountIn, poolId, price =
|
|
|
10432
10596
|
throw typeof error === "string" ? error : await getErrorTextFormError(error);
|
|
10433
10597
|
}
|
|
10434
10598
|
};
|
|
10435
|
-
var previewUserWithdrawData = async ({ chainId
|
|
10599
|
+
var previewUserWithdrawData = async ({ chainId, account, poolId, amount = 0 }) => {
|
|
10436
10600
|
try {
|
|
10437
|
-
if (!
|
|
10601
|
+
if (!chainId || !account || !poolId) return;
|
|
10438
10602
|
if (!amount) {
|
|
10439
10603
|
return {
|
|
10440
10604
|
baseAmountOut: 0n,
|
|
10441
10605
|
rebateAmount: 0n
|
|
10442
10606
|
};
|
|
10443
10607
|
}
|
|
10444
|
-
const chainInfo = CHAIN_INFO[
|
|
10445
|
-
const decimals =
|
|
10608
|
+
const chainInfo = CHAIN_INFO[chainId];
|
|
10609
|
+
const decimals = COMMON_LP_AMOUNT_DECIMALS;
|
|
10446
10610
|
await checkParams({
|
|
10447
10611
|
// tokenAddress: lpAddress,
|
|
10448
10612
|
decimals,
|
|
10449
10613
|
account,
|
|
10450
|
-
chainId
|
|
10614
|
+
chainId,
|
|
10451
10615
|
amount: Number(amount)
|
|
10452
10616
|
});
|
|
10453
10617
|
const amountIn = parseUnits5(amount.toString(), decimals);
|
|
10454
|
-
const priceResponse = await getOraclePrice(
|
|
10618
|
+
const priceResponse = await getOraclePrice(chainId, [poolId]);
|
|
10455
10619
|
const _price = priceResponse.data?.[0]?.price || "0";
|
|
10456
10620
|
const price = parseUnits5(_price, COMMON_PRICE_DECIMALS);
|
|
10457
|
-
const basePoolContract = await getBasePoolContract(
|
|
10621
|
+
const basePoolContract = await getBasePoolContract(chainId);
|
|
10458
10622
|
const _gasLimit = await basePoolContract.previewUserWithdrawData.estimateGas(poolId, amountIn, account, price);
|
|
10459
10623
|
const gasLimit = bigintTradingGasToRatioCalculator(_gasLimit, chainInfo.gasLimitRatio);
|
|
10460
|
-
const { gasPrice } = await bigintTradingGasPriceWithRatio(
|
|
10624
|
+
const { gasPrice } = await bigintTradingGasPriceWithRatio(chainId);
|
|
10461
10625
|
const request = await basePoolContract.previewUserWithdrawData(poolId, amountIn, account, price, {
|
|
10462
10626
|
gasLimit,
|
|
10463
10627
|
gasPrice
|
|
@@ -10474,10 +10638,10 @@ var previewUserWithdrawData = async ({ chainId: chainId2, account, poolId, amoun
|
|
|
10474
10638
|
};
|
|
10475
10639
|
|
|
10476
10640
|
// src/lp/getPoolInfo.ts
|
|
10477
|
-
var getPoolInfo = async (
|
|
10641
|
+
var getPoolInfo = async (chainId, poolId) => {
|
|
10478
10642
|
try {
|
|
10479
|
-
if (!
|
|
10480
|
-
const response = await getPoolDetail(
|
|
10643
|
+
if (!chainId || !poolId) return;
|
|
10644
|
+
const response = await getPoolDetail(chainId, poolId);
|
|
10481
10645
|
const pool = response.data;
|
|
10482
10646
|
return pool;
|
|
10483
10647
|
} catch (error) {
|
|
@@ -10520,25 +10684,25 @@ var getTpSlParams = (slippage = 0.01, tpsl = [], decimals = COMMON_LP_AMOUNT_DEC
|
|
|
10520
10684
|
// src/lp/base/deposit.ts
|
|
10521
10685
|
var deposit = async (params) => {
|
|
10522
10686
|
try {
|
|
10523
|
-
const { poolId, chainId
|
|
10687
|
+
const { poolId, chainId, amount, slippage = 0.01, tpsl = [] } = params;
|
|
10524
10688
|
await checkParams(params);
|
|
10525
|
-
const pool = await getPoolInfo(
|
|
10689
|
+
const pool = await getPoolInfo(chainId, poolId);
|
|
10526
10690
|
if (!pool) {
|
|
10527
10691
|
throw new Error(Errors[4006 /* Invalid_Params */]);
|
|
10528
10692
|
}
|
|
10529
10693
|
const decimals = pool?.baseDecimals;
|
|
10530
10694
|
const quoteDecimals = pool?.quoteDecimals;
|
|
10531
10695
|
const tokenAddress = pool?.baseToken;
|
|
10532
|
-
const chainInfo = CHAIN_INFO[
|
|
10533
|
-
const account = await getAccount(
|
|
10534
|
-
const addresses = address_default[
|
|
10696
|
+
const chainInfo = CHAIN_INFO[chainId];
|
|
10697
|
+
const account = await getAccount(chainId);
|
|
10698
|
+
const addresses = address_default[chainId];
|
|
10535
10699
|
const contractAddress = addresses.BASE_POOL;
|
|
10536
10700
|
await checkParams({
|
|
10537
10701
|
tokenAddress,
|
|
10538
10702
|
contractAddress,
|
|
10539
10703
|
decimals,
|
|
10540
10704
|
account,
|
|
10541
|
-
chainId
|
|
10705
|
+
chainId,
|
|
10542
10706
|
amount
|
|
10543
10707
|
});
|
|
10544
10708
|
const isNeedPrice = !(Number(pool?.state) === 0 /* Cook */ || Number(pool?.state) === 1 /* Primed */);
|
|
@@ -10547,7 +10711,7 @@ var deposit = async (params) => {
|
|
|
10547
10711
|
let value = 0n;
|
|
10548
10712
|
let amountOut;
|
|
10549
10713
|
if (isNeedPrice) {
|
|
10550
|
-
const priceData = await getPriceData(
|
|
10714
|
+
const priceData = await getPriceData(chainId, poolId);
|
|
10551
10715
|
if (!priceData) return;
|
|
10552
10716
|
const referencePrice = parseUnits7(priceData.price, COMMON_PRICE_DECIMALS);
|
|
10553
10717
|
price.push({
|
|
@@ -10557,10 +10721,10 @@ var deposit = async (params) => {
|
|
|
10557
10721
|
publishTime: priceData.publishTime,
|
|
10558
10722
|
oracleType: priceData.oracleType
|
|
10559
10723
|
});
|
|
10560
|
-
amountOut = await previewLpAmountOut({ chainId
|
|
10724
|
+
amountOut = await previewLpAmountOut({ chainId, poolId, amountIn, price: referencePrice });
|
|
10561
10725
|
value = priceData.value;
|
|
10562
10726
|
} else {
|
|
10563
|
-
amountOut = await previewLpAmountOut({ chainId
|
|
10727
|
+
amountOut = await previewLpAmountOut({ chainId, poolId, amountIn });
|
|
10564
10728
|
}
|
|
10565
10729
|
const _tpsl = tpsl.map((item) => {
|
|
10566
10730
|
return {
|
|
@@ -10578,10 +10742,10 @@ var deposit = async (params) => {
|
|
|
10578
10742
|
recipient: account,
|
|
10579
10743
|
tpslParams
|
|
10580
10744
|
};
|
|
10581
|
-
const contract = await getLiquidityRouterContract(
|
|
10745
|
+
const contract = await getLiquidityRouterContract(chainId);
|
|
10582
10746
|
const _gasLimit = await contract["depositBase((bytes32,uint8,uint256,bytes,uint64)[],(bytes32,uint256,uint256,address,(uint256,uint256,uint8,uint256)[]))"].estimateGas(price, data, { value });
|
|
10583
10747
|
const gasLimit = bigintTradingGasToRatioCalculator(_gasLimit, chainInfo.gasLimitRatio);
|
|
10584
|
-
const { gasPrice } = await bigintTradingGasPriceWithRatio(
|
|
10748
|
+
const { gasPrice } = await bigintTradingGasPriceWithRatio(chainId);
|
|
10585
10749
|
const result = await contract["depositBase((bytes32,uint8,uint256,bytes,uint64)[],(bytes32,uint256,uint256,address,(uint256,uint256,uint8,uint256)[]))"](price, data, {
|
|
10586
10750
|
gasLimit,
|
|
10587
10751
|
gasPrice,
|
|
@@ -10598,17 +10762,17 @@ var deposit = async (params) => {
|
|
|
10598
10762
|
import { parseUnits as parseUnits8 } from "ethers";
|
|
10599
10763
|
var withdraw = async (params) => {
|
|
10600
10764
|
try {
|
|
10601
|
-
const { chainId
|
|
10602
|
-
const pool = await getPoolInfo(
|
|
10765
|
+
const { chainId, poolId, amount, slippage = 0.01 } = params;
|
|
10766
|
+
const pool = await getPoolInfo(chainId, poolId);
|
|
10603
10767
|
const lpAddress = pool?.quotePoolToken;
|
|
10604
|
-
const chainInfo = CHAIN_INFO[
|
|
10605
|
-
const account = await getAccount(
|
|
10606
|
-
const decimals =
|
|
10768
|
+
const chainInfo = CHAIN_INFO[chainId];
|
|
10769
|
+
const account = await getAccount(chainId);
|
|
10770
|
+
const decimals = COMMON_LP_AMOUNT_DECIMALS;
|
|
10607
10771
|
await checkParams({
|
|
10608
10772
|
tokenAddress: lpAddress,
|
|
10609
10773
|
decimals,
|
|
10610
10774
|
account,
|
|
10611
|
-
chainId
|
|
10775
|
+
chainId,
|
|
10612
10776
|
amount
|
|
10613
10777
|
});
|
|
10614
10778
|
const amountIn = parseUnits8(amount.toString(), decimals);
|
|
@@ -10617,7 +10781,7 @@ var withdraw = async (params) => {
|
|
|
10617
10781
|
let value = 0n;
|
|
10618
10782
|
let amountOut;
|
|
10619
10783
|
if (isNeedPrice) {
|
|
10620
|
-
const priceData = await getPriceData(
|
|
10784
|
+
const priceData = await getPriceData(chainId, poolId);
|
|
10621
10785
|
if (!priceData) return;
|
|
10622
10786
|
const referencePrice = parseUnits8(priceData.price, COMMON_PRICE_DECIMALS);
|
|
10623
10787
|
price.push({
|
|
@@ -10627,10 +10791,10 @@ var withdraw = async (params) => {
|
|
|
10627
10791
|
publishTime: priceData.publishTime,
|
|
10628
10792
|
oracleType: priceData.oracleType
|
|
10629
10793
|
});
|
|
10630
|
-
amountOut = await previewBaseAmountOut({ chainId
|
|
10794
|
+
amountOut = await previewBaseAmountOut({ chainId, poolId, amountIn, price: referencePrice });
|
|
10631
10795
|
value = priceData.value;
|
|
10632
10796
|
} else {
|
|
10633
|
-
amountOut = await previewBaseAmountOut({ chainId
|
|
10797
|
+
amountOut = await previewBaseAmountOut({ chainId, poolId, amountIn });
|
|
10634
10798
|
}
|
|
10635
10799
|
const data = {
|
|
10636
10800
|
poolId,
|
|
@@ -10638,10 +10802,10 @@ var withdraw = async (params) => {
|
|
|
10638
10802
|
minAmountOut: bigintAmountSlipperCalculator(amountOut, slippage),
|
|
10639
10803
|
recipient: account
|
|
10640
10804
|
};
|
|
10641
|
-
const contract = await getLiquidityRouterContract(
|
|
10805
|
+
const contract = await getLiquidityRouterContract(chainId);
|
|
10642
10806
|
const _gasLimit = await contract["withdrawBase((bytes32,uint8,uint256,bytes,uint64)[],(bytes32,uint256,uint256,address))"].estimateGas(price, data, { value });
|
|
10643
10807
|
const gasLimit = bigintTradingGasToRatioCalculator(_gasLimit, chainInfo.gasLimitRatio);
|
|
10644
|
-
const { gasPrice } = await bigintTradingGasPriceWithRatio(
|
|
10808
|
+
const { gasPrice } = await bigintTradingGasPriceWithRatio(chainId);
|
|
10645
10809
|
const response = await contract["withdrawBase((bytes32,uint8,uint256,bytes,uint64)[],(bytes32,uint256,uint256,address))"](price, data, {
|
|
10646
10810
|
gasLimit,
|
|
10647
10811
|
gasPrice,
|
|
@@ -10659,17 +10823,17 @@ var withdraw = async (params) => {
|
|
|
10659
10823
|
import { parseUnits as parseUnits9 } from "ethers";
|
|
10660
10824
|
var getRewards = async (params) => {
|
|
10661
10825
|
try {
|
|
10662
|
-
const { chainId
|
|
10663
|
-
if (!
|
|
10664
|
-
const chainInfo = CHAIN_INFO[
|
|
10826
|
+
const { chainId, account, poolId } = params;
|
|
10827
|
+
if (!chainId || !account || !poolId) return;
|
|
10828
|
+
const chainInfo = CHAIN_INFO[chainId];
|
|
10665
10829
|
const lpAmountIn = 0n;
|
|
10666
|
-
const priceResponse = await getOraclePrice(
|
|
10830
|
+
const priceResponse = await getOraclePrice(chainId, [poolId]);
|
|
10667
10831
|
const _price = priceResponse.data?.[0]?.price || "0";
|
|
10668
10832
|
const price = parseUnits9(_price, COMMON_PRICE_DECIMALS);
|
|
10669
|
-
const basePoolContract = await getBasePoolContract(
|
|
10833
|
+
const basePoolContract = await getBasePoolContract(chainId);
|
|
10670
10834
|
const _gasLimit = await basePoolContract.pendingUserRebates.estimateGas(poolId, account, price);
|
|
10671
10835
|
const gasLimit = bigintTradingGasToRatioCalculator(_gasLimit, chainInfo.gasLimitRatio);
|
|
10672
|
-
const { gasPrice } = await bigintTradingGasPriceWithRatio(
|
|
10836
|
+
const { gasPrice } = await bigintTradingGasPriceWithRatio(chainId);
|
|
10673
10837
|
const request = await basePoolContract.pendingUserRebates(poolId, account, price, {
|
|
10674
10838
|
gasLimit,
|
|
10675
10839
|
gasPrice
|
|
@@ -10683,14 +10847,14 @@ var getRewards = async (params) => {
|
|
|
10683
10847
|
|
|
10684
10848
|
// src/lp/base/price.ts
|
|
10685
10849
|
import { parseUnits as parseUnits10 } from "ethers";
|
|
10686
|
-
var getLpPrice = async (
|
|
10850
|
+
var getLpPrice = async (chainId, poolId) => {
|
|
10687
10851
|
if (!poolId) return;
|
|
10688
10852
|
try {
|
|
10689
|
-
const pool = await getPoolInfo(
|
|
10690
|
-
const contract = await getBasePoolContract(
|
|
10853
|
+
const pool = await getPoolInfo(chainId, poolId);
|
|
10854
|
+
const contract = await getBasePoolContract(chainId);
|
|
10691
10855
|
let price = 0n;
|
|
10692
10856
|
if (!(Number(pool?.state) === 0 /* Cook */ || Number(pool?.state) === 1 /* Primed */)) {
|
|
10693
|
-
const res = await getPriceData(
|
|
10857
|
+
const res = await getPriceData(chainId, poolId);
|
|
10694
10858
|
if (res?.price) {
|
|
10695
10859
|
price = parseUnits10(res.price, COMMON_PRICE_DECIMALS);
|
|
10696
10860
|
}
|
|
@@ -10719,13 +10883,13 @@ __export(quote_exports, {
|
|
|
10719
10883
|
import { parseUnits as parseUnits11 } from "ethers";
|
|
10720
10884
|
|
|
10721
10885
|
// src/lp/quote/preview.ts
|
|
10722
|
-
var previewLpAmountOut2 = async ({ chainId
|
|
10886
|
+
var previewLpAmountOut2 = async ({ chainId, amountIn, poolId, price = 0n }) => {
|
|
10723
10887
|
try {
|
|
10724
|
-
const chainInfo = CHAIN_INFO[
|
|
10725
|
-
const quotePoolContract = await getQuotePoolContract(
|
|
10888
|
+
const chainInfo = CHAIN_INFO[chainId];
|
|
10889
|
+
const quotePoolContract = await getQuotePoolContract(chainId);
|
|
10726
10890
|
const _gasLimit = await quotePoolContract.previewLpAmountOut.estimateGas(poolId, amountIn, price);
|
|
10727
10891
|
const gasLimit = bigintTradingGasToRatioCalculator(_gasLimit, chainInfo.gasLimitRatio);
|
|
10728
|
-
const { gasPrice } = await bigintTradingGasPriceWithRatio(
|
|
10892
|
+
const { gasPrice } = await bigintTradingGasPriceWithRatio(chainId);
|
|
10729
10893
|
const request = await quotePoolContract.previewLpAmountOut(poolId, amountIn, price, {
|
|
10730
10894
|
gasLimit,
|
|
10731
10895
|
gasPrice
|
|
@@ -10736,13 +10900,13 @@ var previewLpAmountOut2 = async ({ chainId: chainId2, amountIn, poolId, price =
|
|
|
10736
10900
|
throw typeof error === "string" ? error : await getErrorTextFormError(error);
|
|
10737
10901
|
}
|
|
10738
10902
|
};
|
|
10739
|
-
var previewQuoteAmountOut = async ({ chainId
|
|
10903
|
+
var previewQuoteAmountOut = async ({ chainId, amountIn, poolId, price = 0n }) => {
|
|
10740
10904
|
try {
|
|
10741
|
-
const chainInfo = CHAIN_INFO[
|
|
10742
|
-
const quotePoolContract = await getQuotePoolContract(
|
|
10905
|
+
const chainInfo = CHAIN_INFO[chainId];
|
|
10906
|
+
const quotePoolContract = await getQuotePoolContract(chainId);
|
|
10743
10907
|
const _gasLimit = await quotePoolContract.previewQuoteAmountOut.estimateGas(poolId, amountIn, price);
|
|
10744
10908
|
const gasLimit = bigintTradingGasToRatioCalculator(_gasLimit, chainInfo.gasLimitRatio);
|
|
10745
|
-
const { gasPrice } = await bigintTradingGasPriceWithRatio(
|
|
10909
|
+
const { gasPrice } = await bigintTradingGasPriceWithRatio(chainId);
|
|
10746
10910
|
const request = await quotePoolContract.previewQuoteAmountOut(poolId, amountIn, price, {
|
|
10747
10911
|
gasLimit,
|
|
10748
10912
|
gasPrice
|
|
@@ -10757,15 +10921,15 @@ var previewQuoteAmountOut = async ({ chainId: chainId2, amountIn, poolId, price
|
|
|
10757
10921
|
// src/lp/quote/deposit.ts
|
|
10758
10922
|
var deposit2 = async (params) => {
|
|
10759
10923
|
try {
|
|
10760
|
-
const { poolId, chainId
|
|
10924
|
+
const { poolId, chainId, amount, slippage = 0.01, tpsl = [] } = params;
|
|
10761
10925
|
await checkParams(params);
|
|
10762
|
-
const pool = await getPoolInfo(
|
|
10926
|
+
const pool = await getPoolInfo(chainId, poolId);
|
|
10763
10927
|
if (!pool) {
|
|
10764
10928
|
throw new Error(Errors[4006 /* Invalid_Params */]);
|
|
10765
10929
|
}
|
|
10766
|
-
const chainInfo = CHAIN_INFO[
|
|
10767
|
-
const account = await getAccount(
|
|
10768
|
-
const addresses = address_default[
|
|
10930
|
+
const chainInfo = CHAIN_INFO[chainId];
|
|
10931
|
+
const account = await getAccount(chainId);
|
|
10932
|
+
const addresses = address_default[chainId];
|
|
10769
10933
|
const contractAddress = addresses.QUOTE_POOL;
|
|
10770
10934
|
const tokenAddress = pool.quoteToken;
|
|
10771
10935
|
const decimals = pool?.quoteDecimals;
|
|
@@ -10774,7 +10938,7 @@ var deposit2 = async (params) => {
|
|
|
10774
10938
|
contractAddress,
|
|
10775
10939
|
decimals,
|
|
10776
10940
|
account,
|
|
10777
|
-
chainId
|
|
10941
|
+
chainId,
|
|
10778
10942
|
amount
|
|
10779
10943
|
});
|
|
10780
10944
|
const amountIn = parseUnits11(amount.toString(), decimals);
|
|
@@ -10783,7 +10947,7 @@ var deposit2 = async (params) => {
|
|
|
10783
10947
|
let value = 0n;
|
|
10784
10948
|
let amountOut;
|
|
10785
10949
|
if (isNeedPrice) {
|
|
10786
|
-
const priceData = await getPriceData(
|
|
10950
|
+
const priceData = await getPriceData(chainId, poolId);
|
|
10787
10951
|
if (!priceData) return;
|
|
10788
10952
|
const referencePrice = parseUnits11(priceData.price, COMMON_PRICE_DECIMALS);
|
|
10789
10953
|
price.push({
|
|
@@ -10793,10 +10957,10 @@ var deposit2 = async (params) => {
|
|
|
10793
10957
|
publishTime: priceData.publishTime,
|
|
10794
10958
|
oracleType: priceData.oracleType
|
|
10795
10959
|
});
|
|
10796
|
-
amountOut = await previewLpAmountOut2({ chainId
|
|
10960
|
+
amountOut = await previewLpAmountOut2({ chainId, poolId, amountIn, price: referencePrice });
|
|
10797
10961
|
value = priceData.value;
|
|
10798
10962
|
} else {
|
|
10799
|
-
amountOut = await previewLpAmountOut2({ chainId
|
|
10963
|
+
amountOut = await previewLpAmountOut2({ chainId, poolId, amountIn });
|
|
10800
10964
|
}
|
|
10801
10965
|
const _tpsl = tpsl.map((item) => {
|
|
10802
10966
|
return {
|
|
@@ -10814,10 +10978,10 @@ var deposit2 = async (params) => {
|
|
|
10814
10978
|
recipient: account,
|
|
10815
10979
|
tpslParams
|
|
10816
10980
|
};
|
|
10817
|
-
const contract = await getLiquidityRouterContract(
|
|
10981
|
+
const contract = await getLiquidityRouterContract(chainId);
|
|
10818
10982
|
const _gasLimit = await contract["depositQuote((bytes32,uint8,uint256,bytes,uint64)[],(bytes32,uint256,uint256,address,(uint256,uint256,uint8,uint256)[]))"].estimateGas(price, data, { value });
|
|
10819
10983
|
const gasLimit = bigintTradingGasToRatioCalculator(_gasLimit, chainInfo.gasLimitRatio);
|
|
10820
|
-
const { gasPrice } = await bigintTradingGasPriceWithRatio(
|
|
10984
|
+
const { gasPrice } = await bigintTradingGasPriceWithRatio(chainId);
|
|
10821
10985
|
const result = await contract["depositQuote((bytes32,uint8,uint256,bytes,uint64)[],(bytes32,uint256,uint256,address,(uint256,uint256,uint8,uint256)[]))"](price, data, {
|
|
10822
10986
|
gasLimit,
|
|
10823
10987
|
gasPrice,
|
|
@@ -10834,17 +10998,17 @@ var deposit2 = async (params) => {
|
|
|
10834
10998
|
import { parseUnits as parseUnits12 } from "ethers";
|
|
10835
10999
|
var withdraw2 = async (params) => {
|
|
10836
11000
|
try {
|
|
10837
|
-
const { chainId
|
|
10838
|
-
const pool = await getPoolInfo(
|
|
11001
|
+
const { chainId, poolId, amount, slippage = 0.01 } = params;
|
|
11002
|
+
const pool = await getPoolInfo(chainId, poolId);
|
|
10839
11003
|
const lpAddress = pool?.quotePoolToken;
|
|
10840
|
-
const chainInfo = CHAIN_INFO[
|
|
10841
|
-
const account = await getAccount(
|
|
10842
|
-
const decimals =
|
|
11004
|
+
const chainInfo = CHAIN_INFO[chainId];
|
|
11005
|
+
const account = await getAccount(chainId);
|
|
11006
|
+
const decimals = COMMON_LP_AMOUNT_DECIMALS;
|
|
10843
11007
|
await checkParams({
|
|
10844
11008
|
tokenAddress: lpAddress,
|
|
10845
11009
|
decimals,
|
|
10846
11010
|
account,
|
|
10847
|
-
chainId
|
|
11011
|
+
chainId,
|
|
10848
11012
|
amount
|
|
10849
11013
|
});
|
|
10850
11014
|
const amountIn = parseUnits12(amount.toString(), decimals);
|
|
@@ -10853,7 +11017,7 @@ var withdraw2 = async (params) => {
|
|
|
10853
11017
|
let value = 0n;
|
|
10854
11018
|
let amountOut;
|
|
10855
11019
|
if (isNeedPrice) {
|
|
10856
|
-
const priceData = await getPriceData(
|
|
11020
|
+
const priceData = await getPriceData(chainId, poolId);
|
|
10857
11021
|
if (!priceData) return;
|
|
10858
11022
|
const referencePrice = parseUnits12(priceData.price, COMMON_PRICE_DECIMALS);
|
|
10859
11023
|
price.push({
|
|
@@ -10863,10 +11027,10 @@ var withdraw2 = async (params) => {
|
|
|
10863
11027
|
publishTime: priceData.publishTime,
|
|
10864
11028
|
oracleType: priceData.oracleType
|
|
10865
11029
|
});
|
|
10866
|
-
amountOut = await previewQuoteAmountOut({ chainId
|
|
11030
|
+
amountOut = await previewQuoteAmountOut({ chainId, poolId, amountIn, price: referencePrice });
|
|
10867
11031
|
value = priceData.value;
|
|
10868
11032
|
} else {
|
|
10869
|
-
amountOut = await previewQuoteAmountOut({ chainId
|
|
11033
|
+
amountOut = await previewQuoteAmountOut({ chainId, poolId, amountIn });
|
|
10870
11034
|
}
|
|
10871
11035
|
const data = {
|
|
10872
11036
|
poolId,
|
|
@@ -10875,10 +11039,10 @@ var withdraw2 = async (params) => {
|
|
|
10875
11039
|
// todo 调合约获取
|
|
10876
11040
|
recipient: account
|
|
10877
11041
|
};
|
|
10878
|
-
const contract = await getLiquidityRouterContract(
|
|
11042
|
+
const contract = await getLiquidityRouterContract(chainId);
|
|
10879
11043
|
const _gasLimit = await contract["withdrawQuote((bytes32,uint8,uint256,bytes,uint64)[],(bytes32,uint256,uint256,address))"].estimateGas(price, data, { value });
|
|
10880
11044
|
const gasLimit = bigintTradingGasToRatioCalculator(_gasLimit, chainInfo.gasLimitRatio);
|
|
10881
|
-
const { gasPrice } = await bigintTradingGasPriceWithRatio(
|
|
11045
|
+
const { gasPrice } = await bigintTradingGasPriceWithRatio(chainId);
|
|
10882
11046
|
const request = await contract["withdrawQuote((bytes32,uint8,uint256,bytes,uint64)[],(bytes32,uint256,uint256,address))"]([], data, {
|
|
10883
11047
|
gasLimit,
|
|
10884
11048
|
gasPrice,
|
|
@@ -10894,28 +11058,28 @@ var withdraw2 = async (params) => {
|
|
|
10894
11058
|
|
|
10895
11059
|
// src/lp/quote/transfer.ts
|
|
10896
11060
|
import { parseUnits as parseUnits13 } from "ethers";
|
|
10897
|
-
var transfer = async (
|
|
11061
|
+
var transfer = async (chainId, fromPoolId, toPoolId, amount) => {
|
|
10898
11062
|
try {
|
|
10899
|
-
const fromPool = await getPoolInfo(
|
|
10900
|
-
const toPool = await getPoolInfo(
|
|
11063
|
+
const fromPool = await getPoolInfo(chainId, fromPoolId);
|
|
11064
|
+
const toPool = await getPoolInfo(chainId, toPoolId);
|
|
10901
11065
|
if (!toPool || !fromPool) return null;
|
|
10902
11066
|
if ([3 /* PreBench */, 4 /* Bench */].includes(toPool.state)) {
|
|
10903
11067
|
throw new Error(Errors[4005 /* Invalid_Pool_State */]);
|
|
10904
11068
|
}
|
|
10905
|
-
const account = await getAccount(
|
|
10906
|
-
const chainInfo = CHAIN_INFO[
|
|
10907
|
-
const decimals =
|
|
10908
|
-
await checkParams({ chainId
|
|
11069
|
+
const account = await getAccount(chainId);
|
|
11070
|
+
const chainInfo = CHAIN_INFO[chainId];
|
|
11071
|
+
const decimals = COMMON_LP_AMOUNT_DECIMALS;
|
|
11072
|
+
await checkParams({ chainId, amount, account, decimals, tokenAddress: fromPool.quotePoolToken });
|
|
10909
11073
|
const data = {
|
|
10910
11074
|
fromPoolId,
|
|
10911
11075
|
toPoolId,
|
|
10912
11076
|
minLpOut: 0n,
|
|
10913
11077
|
amount: parseUnits13(amount.toString(), decimals)
|
|
10914
11078
|
};
|
|
10915
|
-
const contract = await getLiquidityRouterContract(
|
|
11079
|
+
const contract = await getLiquidityRouterContract(chainId);
|
|
10916
11080
|
const _gasLimit = await contract.migrateLiquidity.estimateGas(data);
|
|
10917
11081
|
const gasLimit = bigintTradingGasToRatioCalculator(_gasLimit, chainInfo.gasLimitRatio);
|
|
10918
|
-
const { gasPrice } = await bigintTradingGasPriceWithRatio(
|
|
11082
|
+
const { gasPrice } = await bigintTradingGasPriceWithRatio(chainId);
|
|
10919
11083
|
const result = await contract.migrateLiquidity(data, {
|
|
10920
11084
|
gasLimit,
|
|
10921
11085
|
gasPrice
|
|
@@ -10930,16 +11094,16 @@ var transfer = async (chainId2, fromPoolId, toPoolId, amount) => {
|
|
|
10930
11094
|
import { parseUnits as parseUnits14 } from "ethers";
|
|
10931
11095
|
var getRewards2 = async (params) => {
|
|
10932
11096
|
try {
|
|
10933
|
-
const { chainId
|
|
10934
|
-
if (!
|
|
10935
|
-
const chainInfo = CHAIN_INFO[
|
|
10936
|
-
const priceResponse = await getOraclePrice(
|
|
11097
|
+
const { chainId, account, poolId } = params;
|
|
11098
|
+
if (!chainId || !account || !poolId) return;
|
|
11099
|
+
const chainInfo = CHAIN_INFO[chainId];
|
|
11100
|
+
const priceResponse = await getOraclePrice(chainId, [poolId]);
|
|
10937
11101
|
const _price = priceResponse.data?.[0]?.price || "0";
|
|
10938
11102
|
const price = parseUnits14(_price, COMMON_PRICE_DECIMALS);
|
|
10939
|
-
const contract = await getQuotePoolContract(
|
|
11103
|
+
const contract = await getQuotePoolContract(chainId);
|
|
10940
11104
|
const _gasLimit = await contract.pendingUserRebates.estimateGas(poolId, account, price);
|
|
10941
11105
|
const gasLimit = bigintTradingGasToRatioCalculator(_gasLimit, chainInfo.gasLimitRatio);
|
|
10942
|
-
const { gasPrice } = await bigintTradingGasPriceWithRatio(
|
|
11106
|
+
const { gasPrice } = await bigintTradingGasPriceWithRatio(chainId);
|
|
10943
11107
|
const request = await contract.pendingUserRebates(poolId, account, price, {
|
|
10944
11108
|
gasLimit,
|
|
10945
11109
|
gasPrice
|
|
@@ -10955,15 +11119,15 @@ var getRewards2 = async (params) => {
|
|
|
10955
11119
|
import { parseUnits as parseUnits15 } from "ethers";
|
|
10956
11120
|
var claimQuotePoolRebate = async (params) => {
|
|
10957
11121
|
try {
|
|
10958
|
-
const { chainId
|
|
10959
|
-
const chainInfo = CHAIN_INFO[
|
|
10960
|
-
const account = await getAccount(
|
|
11122
|
+
const { chainId, poolId } = params;
|
|
11123
|
+
const chainInfo = CHAIN_INFO[chainId];
|
|
11124
|
+
const account = await getAccount(chainId);
|
|
10961
11125
|
const decimals = COMMON_LP_AMOUNT_DECIMALS;
|
|
10962
11126
|
await checkParams({
|
|
10963
11127
|
account,
|
|
10964
|
-
chainId
|
|
11128
|
+
chainId
|
|
10965
11129
|
});
|
|
10966
|
-
const priceResponse = await getPricesData(
|
|
11130
|
+
const priceResponse = await getPricesData(chainId, [poolId]);
|
|
10967
11131
|
if (!priceResponse) return;
|
|
10968
11132
|
const values = priceResponse.map((item) => {
|
|
10969
11133
|
return item.value;
|
|
@@ -10983,12 +11147,12 @@ var claimQuotePoolRebate = async (params) => {
|
|
|
10983
11147
|
poolId,
|
|
10984
11148
|
recipient: account
|
|
10985
11149
|
};
|
|
10986
|
-
const contract = await getLiquidityRouterContract(
|
|
11150
|
+
const contract = await getLiquidityRouterContract(chainId);
|
|
10987
11151
|
const _gasLimit = await contract["claimQuotePoolRebate((bytes32,uint8,uint256,bytes,uint64)[],bytes32,address)"].estimateGas(prices, poolId, account, {
|
|
10988
11152
|
value: values[0]
|
|
10989
11153
|
});
|
|
10990
11154
|
const gasLimit = bigintTradingGasToRatioCalculator(_gasLimit, chainInfo.gasLimitRatio);
|
|
10991
|
-
const { gasPrice } = await bigintTradingGasPriceWithRatio(
|
|
11155
|
+
const { gasPrice } = await bigintTradingGasPriceWithRatio(chainId);
|
|
10992
11156
|
const response = await contract["claimQuotePoolRebate((bytes32,uint8,uint256,bytes,uint64)[],bytes32,address)"](prices, poolId, account, {
|
|
10993
11157
|
gasLimit,
|
|
10994
11158
|
gasPrice,
|
|
@@ -11002,16 +11166,16 @@ var claimQuotePoolRebate = async (params) => {
|
|
|
11002
11166
|
};
|
|
11003
11167
|
var claimQuotePoolRebates = async (params) => {
|
|
11004
11168
|
try {
|
|
11005
|
-
const { chainId
|
|
11169
|
+
const { chainId, poolIds } = params;
|
|
11006
11170
|
if (poolIds.length === 0) return;
|
|
11007
|
-
const chainInfo = CHAIN_INFO[
|
|
11008
|
-
const account = await getAccount(
|
|
11171
|
+
const chainInfo = CHAIN_INFO[chainId];
|
|
11172
|
+
const account = await getAccount(chainId);
|
|
11009
11173
|
const decimals = COMMON_LP_AMOUNT_DECIMALS;
|
|
11010
11174
|
await checkParams({
|
|
11011
11175
|
account,
|
|
11012
|
-
chainId
|
|
11176
|
+
chainId
|
|
11013
11177
|
});
|
|
11014
|
-
const priceResponse = await getPricesData(
|
|
11178
|
+
const priceResponse = await getPricesData(chainId, poolIds);
|
|
11015
11179
|
if (!priceResponse) return;
|
|
11016
11180
|
const prices = priceResponse.map((item) => {
|
|
11017
11181
|
return {
|
|
@@ -11030,12 +11194,12 @@ var claimQuotePoolRebates = async (params) => {
|
|
|
11030
11194
|
poolIds,
|
|
11031
11195
|
recipient: account
|
|
11032
11196
|
};
|
|
11033
|
-
const contract = await getLiquidityRouterContract(
|
|
11197
|
+
const contract = await getLiquidityRouterContract(chainId);
|
|
11034
11198
|
const _gasLimit = await contract["claimQuotePoolRebates((bytes32,uint8,uint256,bytes,uint64)[],bytes32[],address)"].estimateGas(prices, poolIds, account, {
|
|
11035
11199
|
value
|
|
11036
11200
|
});
|
|
11037
11201
|
const gasLimit = bigintTradingGasToRatioCalculator(_gasLimit, chainInfo.gasLimitRatio);
|
|
11038
|
-
const { gasPrice } = await bigintTradingGasPriceWithRatio(
|
|
11202
|
+
const { gasPrice } = await bigintTradingGasPriceWithRatio(chainId);
|
|
11039
11203
|
const response = await contract["claimQuotePoolRebates((bytes32,uint8,uint256,bytes,uint64)[],bytes32[],address)"](prices, poolIds, account, {
|
|
11040
11204
|
gasLimit,
|
|
11041
11205
|
gasPrice,
|
|
@@ -11050,14 +11214,14 @@ var claimQuotePoolRebates = async (params) => {
|
|
|
11050
11214
|
|
|
11051
11215
|
// src/lp/quote/price.ts
|
|
11052
11216
|
import { parseUnits as parseUnits16 } from "ethers";
|
|
11053
|
-
var getLpPrice2 = async (
|
|
11217
|
+
var getLpPrice2 = async (chainId, poolId) => {
|
|
11054
11218
|
if (!poolId) return;
|
|
11055
11219
|
try {
|
|
11056
|
-
const pool = await getPoolInfo(
|
|
11057
|
-
const contract = await getQuotePoolContract(
|
|
11220
|
+
const pool = await getPoolInfo(chainId, poolId);
|
|
11221
|
+
const contract = await getQuotePoolContract(chainId);
|
|
11058
11222
|
let price = 0n;
|
|
11059
11223
|
if (!(Number(pool?.state) === 0 /* Cook */ || Number(pool?.state) === 1 /* Primed */)) {
|
|
11060
|
-
const res = await getPriceData(
|
|
11224
|
+
const res = await getPriceData(chainId, poolId);
|
|
11061
11225
|
if (res?.price) {
|
|
11062
11226
|
price = parseUnits16(res.price, COMMON_PRICE_DECIMALS);
|
|
11063
11227
|
}
|
|
@@ -11088,34 +11252,30 @@ __export(pool_exports, {
|
|
|
11088
11252
|
});
|
|
11089
11253
|
|
|
11090
11254
|
// src/lp/pool/get.ts
|
|
11091
|
-
var getMarketInfo = (chainId2) => {
|
|
11092
|
-
const marketId2 = Market[chainId2].marketId;
|
|
11093
|
-
return marketId2;
|
|
11094
|
-
};
|
|
11095
11255
|
var getMarketPoolId = async ({
|
|
11096
|
-
chainId
|
|
11097
|
-
baseToken
|
|
11256
|
+
chainId,
|
|
11257
|
+
baseToken,
|
|
11258
|
+
marketId
|
|
11098
11259
|
}) => {
|
|
11099
11260
|
try {
|
|
11100
|
-
const marketId2 = getMarketInfo(chainId2);
|
|
11101
11261
|
if (!baseToken) {
|
|
11102
11262
|
throw new Error(Errors[2 /* Invalid_TOKEN_ADDRESS */]);
|
|
11103
11263
|
}
|
|
11104
|
-
const chainInfo = CHAIN_INFO[
|
|
11105
|
-
const addresses = address_default[
|
|
11264
|
+
const chainInfo = CHAIN_INFO[chainId];
|
|
11265
|
+
const addresses = address_default[chainId];
|
|
11106
11266
|
const address = addresses.POOL_MANAGER;
|
|
11107
|
-
const contract = await getPoolManagerContract(
|
|
11108
|
-
const data = [
|
|
11109
|
-
const request = await contract.getMarketPool(
|
|
11267
|
+
const contract = await getPoolManagerContract(chainId, 0 /* JSON */);
|
|
11268
|
+
const data = [marketId, baseToken];
|
|
11269
|
+
const request = await contract.getMarketPool(marketId, baseToken);
|
|
11110
11270
|
return request.poolId === "0x0000000000000000000000000000000000000000000000000000000000000000" || !request.poolId ? void 0 : request.poolId;
|
|
11111
11271
|
} catch (error) {
|
|
11112
11272
|
console.error(error);
|
|
11113
11273
|
throw typeof error === "string" ? error : await getErrorTextFormError(error);
|
|
11114
11274
|
}
|
|
11115
11275
|
};
|
|
11116
|
-
var getMarketPools = async (
|
|
11276
|
+
var getMarketPools = async (chainId) => {
|
|
11117
11277
|
try {
|
|
11118
|
-
const contract = await getPoolManagerContract(
|
|
11278
|
+
const contract = await getPoolManagerContract(chainId);
|
|
11119
11279
|
const request = await contract.getPools();
|
|
11120
11280
|
console.log(request);
|
|
11121
11281
|
return request || [];
|
|
@@ -11124,9 +11284,9 @@ var getMarketPools = async (chainId2) => {
|
|
|
11124
11284
|
throw typeof error === "string" ? error : await getErrorTextFormError(error);
|
|
11125
11285
|
}
|
|
11126
11286
|
};
|
|
11127
|
-
var getPoolInfo2 = async (
|
|
11287
|
+
var getPoolInfo2 = async (chainId, poolId, marketPrice = 0n) => {
|
|
11128
11288
|
try {
|
|
11129
|
-
const contract = await getDataProviderContract(
|
|
11289
|
+
const contract = await getDataProviderContract(chainId);
|
|
11130
11290
|
const request = await contract.getPoolInfo(poolId, marketPrice);
|
|
11131
11291
|
const info = {
|
|
11132
11292
|
quotePool: {
|
|
@@ -11168,20 +11328,18 @@ var getPoolInfo2 = async (chainId2, poolId, marketPrice = 0n) => {
|
|
|
11168
11328
|
};
|
|
11169
11329
|
|
|
11170
11330
|
// src/lp/pool/create.ts
|
|
11171
|
-
var
|
|
11172
|
-
var marketId = Market[chainId].marketId;
|
|
11173
|
-
var createPool = async ({ chainId: chainId2, baseToken }) => {
|
|
11331
|
+
var createPool = async ({ chainId, baseToken, marketId }) => {
|
|
11174
11332
|
try {
|
|
11175
11333
|
if (!baseToken) {
|
|
11176
11334
|
throw new Error(Errors[2 /* Invalid_TOKEN_ADDRESS */]);
|
|
11177
11335
|
}
|
|
11178
|
-
const chainInfo = CHAIN_INFO[
|
|
11179
|
-
const contract = await getPoolManagerContract(
|
|
11336
|
+
const chainInfo = CHAIN_INFO[chainId];
|
|
11337
|
+
const contract = await getPoolManagerContract(chainId);
|
|
11180
11338
|
const data = { marketId, baseToken };
|
|
11181
11339
|
const _gasLimit = await contract.deployPool.estimateGas(data);
|
|
11182
11340
|
const gasLimit = bigintTradingGasToRatioCalculator(_gasLimit, chainInfo.gasLimitRatio);
|
|
11183
11341
|
console.log("gasLimit", _gasLimit, gasLimit);
|
|
11184
|
-
const { gasPrice } = await bigintTradingGasPriceWithRatio(
|
|
11342
|
+
const { gasPrice } = await bigintTradingGasPriceWithRatio(chainId);
|
|
11185
11343
|
console.log("gasPrice", gasPrice);
|
|
11186
11344
|
const request = await contract.deployPool(data, {
|
|
11187
11345
|
gasLimit,
|
|
@@ -11189,7 +11347,7 @@ var createPool = async ({ chainId: chainId2, baseToken }) => {
|
|
|
11189
11347
|
});
|
|
11190
11348
|
const receipt = await request?.wait();
|
|
11191
11349
|
if (receipt?.hash) {
|
|
11192
|
-
const poolId = await getMarketPoolId({ chainId
|
|
11350
|
+
const poolId = await getMarketPoolId({ chainId, baseToken, marketId });
|
|
11193
11351
|
return poolId;
|
|
11194
11352
|
}
|
|
11195
11353
|
} catch (error) {
|
|
@@ -11199,9 +11357,9 @@ var createPool = async ({ chainId: chainId2, baseToken }) => {
|
|
|
11199
11357
|
};
|
|
11200
11358
|
|
|
11201
11359
|
// src/lp/pool/getUserGenesisShare.ts
|
|
11202
|
-
var getUserGenesisShare = async (
|
|
11360
|
+
var getUserGenesisShare = async (chainId, tokenAddress, account) => {
|
|
11203
11361
|
try {
|
|
11204
|
-
const contract = await getPoolTokenContract(
|
|
11362
|
+
const contract = await getPoolTokenContract(chainId, tokenAddress);
|
|
11205
11363
|
const request = await contract.userGenesisShare(account);
|
|
11206
11364
|
return request;
|
|
11207
11365
|
} catch (error) {
|
|
@@ -11213,17 +11371,17 @@ var getUserGenesisShare = async (chainId2, tokenAddress, account) => {
|
|
|
11213
11371
|
// src/lp/pool/addTpSl.ts
|
|
11214
11372
|
var addTpSl = async (params) => {
|
|
11215
11373
|
try {
|
|
11216
|
-
const { chainId
|
|
11374
|
+
const { chainId, poolId, poolType, slippage = 0.01, tpsl = [] } = params;
|
|
11217
11375
|
await checkParams(params);
|
|
11218
|
-
const pool = await getPoolInfo(
|
|
11376
|
+
const pool = await getPoolInfo(chainId, poolId);
|
|
11219
11377
|
if (!pool) {
|
|
11220
11378
|
throw new Error(Errors[4006 /* Invalid_Params */]);
|
|
11221
11379
|
}
|
|
11222
|
-
const decimals =
|
|
11380
|
+
const decimals = COMMON_LP_AMOUNT_DECIMALS;
|
|
11223
11381
|
const quoteDecimals = pool.quoteDecimals;
|
|
11224
11382
|
const tpslParams = getTpSlParams(slippage, tpsl, decimals, quoteDecimals);
|
|
11225
|
-
const chainInfo = CHAIN_INFO[
|
|
11226
|
-
const contract = await getLiquidityRouterContract(
|
|
11383
|
+
const chainInfo = CHAIN_INFO[chainId];
|
|
11384
|
+
const contract = await getLiquidityRouterContract(chainId);
|
|
11227
11385
|
const data = {
|
|
11228
11386
|
poolId,
|
|
11229
11387
|
poolType: BigInt(poolType),
|
|
@@ -11231,7 +11389,7 @@ var addTpSl = async (params) => {
|
|
|
11231
11389
|
};
|
|
11232
11390
|
const _gasLimit = await contract.addTpsl.estimateGas(data);
|
|
11233
11391
|
const gasLimit = bigintTradingGasToRatioCalculator(_gasLimit, chainInfo.gasLimitRatio);
|
|
11234
|
-
const { gasPrice } = await bigintTradingGasPriceWithRatio(
|
|
11392
|
+
const { gasPrice } = await bigintTradingGasPriceWithRatio(chainId);
|
|
11235
11393
|
const request = await contract.addTpsl(data, {
|
|
11236
11394
|
gasLimit,
|
|
11237
11395
|
gasPrice
|
|
@@ -11247,13 +11405,13 @@ var addTpSl = async (params) => {
|
|
|
11247
11405
|
// src/lp/pool/cancel.ts
|
|
11248
11406
|
var cancelTpSl = async (params) => {
|
|
11249
11407
|
try {
|
|
11250
|
-
const { chainId
|
|
11408
|
+
const { chainId, orderId } = params;
|
|
11251
11409
|
await checkParams(params);
|
|
11252
|
-
const chainInfo = CHAIN_INFO[
|
|
11253
|
-
const contract = await getLiquidityRouterContract(
|
|
11410
|
+
const chainInfo = CHAIN_INFO[chainId];
|
|
11411
|
+
const contract = await getLiquidityRouterContract(chainId);
|
|
11254
11412
|
const _gasLimit = await contract.cancelTpsl.estimateGas(orderId);
|
|
11255
11413
|
const gasLimit = bigintTradingGasToRatioCalculator(_gasLimit, chainInfo.gasLimitRatio);
|
|
11256
|
-
const { gasPrice } = await bigintTradingGasPriceWithRatio(
|
|
11414
|
+
const { gasPrice } = await bigintTradingGasPriceWithRatio(chainId);
|
|
11257
11415
|
const request = await contract.cancelTpsl(orderId, {
|
|
11258
11416
|
gasLimit,
|
|
11259
11417
|
gasPrice
|
|
@@ -11276,9 +11434,9 @@ async function checkImageExists(url) {
|
|
|
11276
11434
|
return false;
|
|
11277
11435
|
}
|
|
11278
11436
|
}
|
|
11279
|
-
var getTokenInfo = async (
|
|
11437
|
+
var getTokenInfo = async (chainId, tokenAddress, account) => {
|
|
11280
11438
|
try {
|
|
11281
|
-
const token = await getTokenContract(
|
|
11439
|
+
const token = await getTokenContract(chainId, tokenAddress);
|
|
11282
11440
|
const _name = await token.name();
|
|
11283
11441
|
console.log(_name);
|
|
11284
11442
|
const [name, symbol, decimals, totalSupply] = await Promise.all([
|
|
@@ -11288,7 +11446,7 @@ var getTokenInfo = async (chainId2, tokenAddress, account) => {
|
|
|
11288
11446
|
token.totalSupply()
|
|
11289
11447
|
]);
|
|
11290
11448
|
const normalized = ethers4.getAddress(tokenAddress);
|
|
11291
|
-
const iconUrl = `https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/${
|
|
11449
|
+
const iconUrl = `https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/${chainId}/assets/${normalized}/logo.png`;
|
|
11292
11450
|
const fallbackIcon = "";
|
|
11293
11451
|
const icon = await checkImageExists(iconUrl) ? iconUrl : fallbackIcon;
|
|
11294
11452
|
let balance;
|
|
@@ -11319,12 +11477,12 @@ __export(market_exports, {
|
|
|
11319
11477
|
});
|
|
11320
11478
|
|
|
11321
11479
|
// src/lp/market/getMarket.ts
|
|
11322
|
-
var getMarket = async (
|
|
11480
|
+
var getMarket = async (chainId, marketId) => {
|
|
11323
11481
|
try {
|
|
11324
|
-
await checkParams({ chainId
|
|
11325
|
-
if (!
|
|
11326
|
-
const contract = await getMarketManageContract(
|
|
11327
|
-
const request = await contract.getMarket(
|
|
11482
|
+
await checkParams({ chainId });
|
|
11483
|
+
if (!marketId) return;
|
|
11484
|
+
const contract = await getMarketManageContract(chainId);
|
|
11485
|
+
const request = await contract.getMarket(marketId);
|
|
11328
11486
|
return request;
|
|
11329
11487
|
} catch (error) {
|
|
11330
11488
|
console.error(error);
|
|
@@ -11333,12 +11491,12 @@ var getMarket = async (chainId2, marketId2) => {
|
|
|
11333
11491
|
};
|
|
11334
11492
|
|
|
11335
11493
|
// src/lp/market/getOracleFee.ts
|
|
11336
|
-
var getOracleFee = async (
|
|
11494
|
+
var getOracleFee = async (chainId, marketId) => {
|
|
11337
11495
|
try {
|
|
11338
|
-
await checkParams({ chainId
|
|
11339
|
-
if (!
|
|
11340
|
-
const contract = await getMarketManageContract(
|
|
11341
|
-
const request = await contract.getOracleFee(
|
|
11496
|
+
await checkParams({ chainId });
|
|
11497
|
+
if (!marketId) return;
|
|
11498
|
+
const contract = await getMarketManageContract(chainId);
|
|
11499
|
+
const request = await contract.getOracleFee(marketId);
|
|
11342
11500
|
return request;
|
|
11343
11501
|
} catch (error) {
|
|
11344
11502
|
console.error(error);
|
|
@@ -11348,32 +11506,31 @@ var getOracleFee = async (chainId2, marketId2) => {
|
|
|
11348
11506
|
|
|
11349
11507
|
// src/lp/pool/reprime.ts
|
|
11350
11508
|
import { formatUnits } from "ethers";
|
|
11351
|
-
var reprime = async (
|
|
11509
|
+
var reprime = async (chainId, poolId, marketId) => {
|
|
11352
11510
|
try {
|
|
11353
|
-
await checkParams({ chainId
|
|
11354
|
-
const pool = await getPoolInfo(
|
|
11511
|
+
await checkParams({ chainId });
|
|
11512
|
+
const pool = await getPoolInfo(chainId, poolId);
|
|
11355
11513
|
if (!pool) {
|
|
11356
11514
|
throw new Error(Errors[4006 /* Invalid_Params */]);
|
|
11357
11515
|
}
|
|
11358
|
-
const
|
|
11359
|
-
const
|
|
11360
|
-
const _amount = await getOracleFee(chainId2, marketId2);
|
|
11516
|
+
const account = await getAccount(chainId);
|
|
11517
|
+
const _amount = await getOracleFee(chainId, marketId);
|
|
11361
11518
|
if (!_amount) {
|
|
11362
11519
|
throw new Error("Invalid Market");
|
|
11363
11520
|
}
|
|
11364
11521
|
await checkParams({
|
|
11365
11522
|
tokenAddress: pool.quoteToken,
|
|
11366
|
-
contractAddress: address_default[
|
|
11523
|
+
contractAddress: address_default[chainId].ORACLE_RESERVE,
|
|
11367
11524
|
decimals: pool.quoteDecimals,
|
|
11368
11525
|
account,
|
|
11369
|
-
chainId
|
|
11526
|
+
chainId,
|
|
11370
11527
|
amount: Number(formatUnits(_amount, pool.quoteDecimals))
|
|
11371
11528
|
});
|
|
11372
|
-
const chainInfo = CHAIN_INFO[
|
|
11373
|
-
const contract = await getPoolManagerContract(
|
|
11529
|
+
const chainInfo = CHAIN_INFO[chainId];
|
|
11530
|
+
const contract = await getPoolManagerContract(chainId);
|
|
11374
11531
|
const _gasLimit = await contract.reprimePool.estimateGas({ poolId });
|
|
11375
11532
|
const gasLimit = bigintTradingGasToRatioCalculator(_gasLimit, chainInfo.gasLimitRatio);
|
|
11376
|
-
const { gasPrice } = await bigintTradingGasPriceWithRatio(
|
|
11533
|
+
const { gasPrice } = await bigintTradingGasPriceWithRatio(chainId);
|
|
11377
11534
|
const request = await contract.reprimePool({ poolId });
|
|
11378
11535
|
const receipt = await request?.wait();
|
|
11379
11536
|
return receipt;
|
|
@@ -11384,7 +11541,7 @@ var reprime = async (chainId2, poolId) => {
|
|
|
11384
11541
|
};
|
|
11385
11542
|
|
|
11386
11543
|
// src/lp/pool/orders.ts
|
|
11387
|
-
var getOpenOrders = async (
|
|
11544
|
+
var getOpenOrders = async (chainId) => {
|
|
11388
11545
|
try {
|
|
11389
11546
|
const accessToken = await MxSDK.getInstance().getConfigManager()?.getAccessToken();
|
|
11390
11547
|
if (!accessToken) {
|
|
@@ -11392,7 +11549,7 @@ var getOpenOrders = async (chainId2) => {
|
|
|
11392
11549
|
"Failed to obtain accessToken"
|
|
11393
11550
|
);
|
|
11394
11551
|
}
|
|
11395
|
-
const response = await getPoolOpenOrders(accessToken,
|
|
11552
|
+
const response = await getPoolOpenOrders(accessToken, chainId);
|
|
11396
11553
|
return response.data || [];
|
|
11397
11554
|
} catch (error) {
|
|
11398
11555
|
console.error(error);
|
|
@@ -12216,18 +12373,18 @@ var ConfigManager = class {
|
|
|
12216
12373
|
this.validateConfig(this.config);
|
|
12217
12374
|
}
|
|
12218
12375
|
validateConfig(config) {
|
|
12219
|
-
const { isTestnet, chainId
|
|
12376
|
+
const { isTestnet, chainId } = config;
|
|
12220
12377
|
if (isTestnet) {
|
|
12221
|
-
if (!TESTNET_CHAIN_IDS.includes(
|
|
12378
|
+
if (!TESTNET_CHAIN_IDS.includes(chainId))
|
|
12222
12379
|
throw new MyxSDKError(
|
|
12223
12380
|
"INVALID_CHAIN_ID" /* InvalidChainId */,
|
|
12224
|
-
`chainId ${
|
|
12381
|
+
`chainId ${chainId} is not in the range of TESTNET_CHAIN_IDS`
|
|
12225
12382
|
);
|
|
12226
12383
|
} else {
|
|
12227
|
-
if (!MAINNET_CHAIN_IDS.includes(
|
|
12384
|
+
if (!MAINNET_CHAIN_IDS.includes(chainId))
|
|
12228
12385
|
throw new MyxSDKError(
|
|
12229
12386
|
"INVALID_CHAIN_ID" /* InvalidChainId */,
|
|
12230
|
-
`chainId ${
|
|
12387
|
+
`chainId ${chainId} is not in the range of MAINNET_CHAIN_IDS`
|
|
12231
12388
|
);
|
|
12232
12389
|
}
|
|
12233
12390
|
}
|
|
@@ -12474,11 +12631,35 @@ var Markets = class {
|
|
|
12474
12631
|
}
|
|
12475
12632
|
};
|
|
12476
12633
|
|
|
12634
|
+
// src/config/address/LINEA_SEPOLIA.ts
|
|
12635
|
+
var LINEA_SEPOLIA = {
|
|
12636
|
+
POOL_MANAGER: "0x7507Ec88C6fcd0c6ebE421988b5ACc052422be2b",
|
|
12637
|
+
Account: "0x05C39d54Ac84f5225218D4E03Ee6aE2999a47a03",
|
|
12638
|
+
POSITION_MANAGER: "0xD7090F7CD1D65e83feB74dCF1c2fcBA4854a934b",
|
|
12639
|
+
ORDER_MANAGER: "0x50602673C3506AFF2e7Df82dB6E93B6B134331Ae",
|
|
12640
|
+
PYTH: "0xA2aa501b19aff244D90cc15a4Cf739D2725B5729",
|
|
12641
|
+
// !!! 非Pyth Adapter
|
|
12642
|
+
ERC20: "0x635eC74A4A39A27177310F0d605515D9df4bDe43",
|
|
12643
|
+
LIQUIDITY_ROUTER: "0x7fa9B7C0D95E19f180A2bf359d980c0bD3aC2503",
|
|
12644
|
+
BASE_POOL: "0x6d3A2AB082388C35319007a2D635Cf7A8B8aF0E1",
|
|
12645
|
+
QUOTE_POOL: "0x5A6fdFD381B76eD163b60300E619F7EB6049e7bD",
|
|
12646
|
+
BROKER: "0x0C6358400a8d86d8377640B1B783b8326b7D0fdc",
|
|
12647
|
+
// MYXBroker
|
|
12648
|
+
ORACLE: "0xfbA4a141bb3BbD0EB34b24152caa3d2940629545",
|
|
12649
|
+
// MYXOracle
|
|
12650
|
+
EIP7702Delegation: "0xa55149B66A7fC4a4eF05c8da981E46Fe27695E6c",
|
|
12651
|
+
MARKET_MANAGER: "0x96Dd73d94c7359e92a45Ff75bC90909E66332990",
|
|
12652
|
+
DATA_PROVIDER: "0xF10B5736EA756488139135BF14aE5A542de435a9",
|
|
12653
|
+
ORACLE_RESERVE: "0xb9433C0e23f38E8Ad48B9A6e562F0a543e06a9F4"
|
|
12654
|
+
};
|
|
12655
|
+
|
|
12477
12656
|
// src/config/address/index.ts
|
|
12478
|
-
var getContractAddressByChainId = (
|
|
12479
|
-
switch (
|
|
12657
|
+
var getContractAddressByChainId = (chainId) => {
|
|
12658
|
+
switch (chainId) {
|
|
12480
12659
|
case 421614 /* ARB_TESTNET */:
|
|
12481
12660
|
return ARB_TEST_SEPOLIA;
|
|
12661
|
+
case 59141 /* LINEA_SEPOLIA */:
|
|
12662
|
+
return LINEA_SEPOLIA;
|
|
12482
12663
|
default:
|
|
12483
12664
|
return {};
|
|
12484
12665
|
}
|
|
@@ -18763,10 +18944,9 @@ export {
|
|
|
18763
18944
|
CloseTypeEnum,
|
|
18764
18945
|
Direction,
|
|
18765
18946
|
DirectionEnum,
|
|
18766
|
-
|
|
18947
|
+
ErrorCode,
|
|
18767
18948
|
ExecTypeEnum,
|
|
18768
18949
|
HttpKlineIntervalEnum,
|
|
18769
|
-
Market,
|
|
18770
18950
|
MarketCapType,
|
|
18771
18951
|
MarketPoolState,
|
|
18772
18952
|
MarketType,
|
|
@@ -18800,6 +18980,7 @@ export {
|
|
|
18800
18980
|
getKlineData,
|
|
18801
18981
|
getKlineLatestBar,
|
|
18802
18982
|
getMarketDetail,
|
|
18983
|
+
getMarketList,
|
|
18803
18984
|
getOraclePrice,
|
|
18804
18985
|
getOrders,
|
|
18805
18986
|
getPoolDetail,
|