@gmx-io/sdk 1.5.0-alpha-7 → 1.5.0-alpha-9
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/build/cjs/src/clients/v1/testUtil.js +1 -1
- package/build/cjs/src/clients/v2/index.js +42 -9
- package/build/cjs/src/codegen/prebuilt/hashedKinkModelMarketRatesKeys.json +34 -0
- package/build/cjs/src/codegen/prebuilt/hashedMarketConfigKeys.json +230 -0
- package/build/cjs/src/codegen/prebuilt/hashedMarketValuesKeys.json +62 -0
- package/build/cjs/src/configs/__tests__/tokens.spec.js +1 -0
- package/build/cjs/src/configs/api.js +4 -3
- package/build/cjs/src/configs/batch.js +13 -0
- package/build/cjs/src/configs/chainIds.js +2 -1
- package/build/cjs/src/configs/chains.js +48 -2
- package/build/cjs/src/configs/contracts.js +67 -0
- package/build/cjs/src/configs/express.js +3 -6
- package/build/cjs/src/configs/fees.js +9 -0
- package/build/cjs/src/configs/gasLimits.js +7 -0
- package/build/cjs/src/configs/markets.js +30 -0
- package/build/cjs/src/configs/oracleKeeper.js +2 -0
- package/build/cjs/src/configs/tokens.js +89 -1
- package/build/cjs/src/utils/__tests__/orderTransactions/decreaseOrders.spec.js +2 -0
- package/build/cjs/src/utils/__tests__/orderTransactions/increaseOrders.spec.js +2 -0
- package/build/cjs/src/utils/__tests__/orderTransactions/swapOrders.spec.js +1 -0
- package/build/cjs/src/utils/__tests__/uiFeeReceiver.spec.js +24 -0
- package/build/cjs/src/utils/apy/api.js +11 -0
- package/build/cjs/src/utils/apy/types.js +2 -0
- package/build/cjs/src/utils/errors/parseError.js +3 -0
- package/build/cjs/src/utils/fees/executionFee.js +11 -3
- package/build/cjs/src/utils/markets/api.js +16 -1
- package/build/cjs/src/utils/numbers/utils.js +4 -0
- package/build/cjs/src/utils/orderTransactions/utils.js +2 -2
- package/build/cjs/src/utils/pairs/api.js +7 -0
- package/build/cjs/src/utils/pairs/types.js +2 -0
- package/build/cjs/src/utils/performance/api.js +21 -0
- package/build/cjs/src/utils/performance/types.js +2 -0
- package/build/cjs/src/utils/rates/api.js +13 -0
- package/build/cjs/src/utils/rates/types.js +2 -0
- package/build/cjs/src/utils/staking/api.js +11 -0
- package/build/cjs/src/utils/staking/types.js +2 -0
- package/build/cjs/src/utils/swap/swapValues.js +3 -3
- package/build/cjs/src/utils/tokens/api.js +7 -0
- package/build/cjs/src/utils/trade/decrease.js +131 -6
- package/build/cjs/src/utils/trade/increase.js +2 -6
- package/build/cjs/src/utils/twap/uiFeeReceiver.js +29 -13
- package/build/esm/src/clients/v1/testUtil.js +1 -1
- package/build/esm/src/clients/v2/index.js +34 -1
- package/build/esm/src/codegen/prebuilt/hashedKinkModelMarketRatesKeys.json +34 -0
- package/build/esm/src/codegen/prebuilt/hashedMarketConfigKeys.json +230 -0
- package/build/esm/src/codegen/prebuilt/hashedMarketValuesKeys.json +62 -0
- package/build/esm/src/configs/__tests__/tokens.spec.js +2 -1
- package/build/esm/src/configs/api.js +5 -4
- package/build/esm/src/configs/batch.js +14 -1
- package/build/esm/src/configs/chainIds.js +1 -0
- package/build/esm/src/configs/chains.js +48 -3
- package/build/esm/src/configs/contracts.js +68 -1
- package/build/esm/src/configs/express.js +4 -7
- package/build/esm/src/configs/fees.js +6 -0
- package/build/esm/src/configs/gasLimits.js +8 -1
- package/build/esm/src/configs/markets.js +31 -1
- package/build/esm/src/configs/oracleKeeper.js +3 -1
- package/build/esm/src/configs/tokens.js +90 -2
- package/build/esm/src/utils/__tests__/orderTransactions/decreaseOrders.spec.js +2 -0
- package/build/esm/src/utils/__tests__/orderTransactions/increaseOrders.spec.js +2 -0
- package/build/esm/src/utils/__tests__/orderTransactions/swapOrders.spec.js +1 -0
- package/build/esm/src/utils/__tests__/uiFeeReceiver.spec.js +25 -1
- package/build/esm/src/utils/apy/api.js +7 -0
- package/build/esm/src/utils/apy/types.js +1 -0
- package/build/esm/src/utils/errors/parseError.js +3 -0
- package/build/esm/src/utils/fees/executionFee.js +8 -2
- package/build/esm/src/utils/markets/api.js +13 -0
- package/build/esm/src/utils/numbers/utils.js +4 -0
- package/build/esm/src/utils/orderTransactions/utils.js +2 -2
- package/build/esm/src/utils/pairs/api.js +3 -0
- package/build/esm/src/utils/pairs/types.js +1 -0
- package/build/esm/src/utils/performance/api.js +16 -0
- package/build/esm/src/utils/performance/types.js +1 -0
- package/build/esm/src/utils/rates/api.js +9 -0
- package/build/esm/src/utils/rates/types.js +1 -0
- package/build/esm/src/utils/staking/api.js +7 -0
- package/build/esm/src/utils/staking/types.js +1 -0
- package/build/esm/src/utils/swap/swapValues.js +3 -3
- package/build/esm/src/utils/tokens/api.js +3 -0
- package/build/esm/src/utils/trade/decrease.js +127 -7
- package/build/esm/src/utils/trade/increase.js +3 -7
- package/build/esm/src/utils/twap/uiFeeReceiver.js +27 -12
- package/build/types/src/clients/v1/index.d.ts +1 -1
- package/build/types/src/clients/v1/modules/base.d.ts +1 -1
- package/build/types/src/clients/v1/multicall.d.ts +1 -1
- package/build/types/src/clients/v2/index.d.ts +26 -1
- package/build/types/src/codegen/prebuilt/index.d.ts +326 -0
- package/build/types/src/configs/chainIds.d.ts +1 -0
- package/build/types/src/configs/chains.d.ts +26 -6
- package/build/types/src/configs/contracts.d.ts +64 -0
- package/build/types/src/configs/express.d.ts +0 -4
- package/build/types/src/configs/fees.d.ts +4 -0
- package/build/types/src/utils/apy/api.d.ts +5 -0
- package/build/types/src/utils/apy/types.d.ts +13 -0
- package/build/types/src/utils/errors/parseError.d.ts +3 -0
- package/build/types/src/utils/fees/executionFee.d.ts +2 -0
- package/build/types/src/utils/markets/api.d.ts +10 -1
- package/build/types/src/utils/numbers/utils.d.ts +1 -0
- package/build/types/src/utils/orderTransactions/utils.d.ts +2 -1
- package/build/types/src/utils/pairs/api.d.ts +5 -0
- package/build/types/src/utils/pairs/types.d.ts +20 -0
- package/build/types/src/utils/performance/api.d.ts +8 -0
- package/build/types/src/utils/performance/types.d.ts +19 -0
- package/build/types/src/utils/rates/api.d.ts +5 -0
- package/build/types/src/utils/rates/types.d.ts +19 -0
- package/build/types/src/utils/staking/api.d.ts +7 -0
- package/build/types/src/utils/staking/types.d.ts +14 -0
- package/build/types/src/utils/swap/swapValues.d.ts +2 -0
- package/build/types/src/utils/tokens/api.d.ts +5 -0
- package/build/types/src/utils/trade/decrease.d.ts +41 -2
- package/build/types/src/utils/trade/types.d.ts +8 -0
- package/build/types/src/utils/twap/uiFeeReceiver.d.ts +9 -6
- package/package.json +1 -1
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Avoid adding client-side code here, as it can break the build process.
|
|
4
4
|
*/
|
|
5
5
|
import { zeroAddress } from "viem";
|
|
6
|
-
import { ARBITRUM, ARBITRUM_SEPOLIA, AVALANCHE, AVALANCHE_FUJI, BOTANIX } from "./chains";
|
|
6
|
+
import { ARBITRUM, ARBITRUM_SEPOLIA, AVALANCHE, AVALANCHE_FUJI, BOTANIX, MEGAETH } from "./chains";
|
|
7
7
|
import { convertTokenAddress, getToken, getTokenBySymbol } from "./tokens";
|
|
8
8
|
export const SWAP_GRAPH_MAX_MARKETS_PER_TOKEN = 5;
|
|
9
9
|
/*
|
|
@@ -1246,6 +1246,36 @@ export const MARKETS = {
|
|
|
1246
1246
|
shortTokenAddress: "0x0D2437F93Fed6EA64Ef01cCde385FB1263910C56",
|
|
1247
1247
|
},
|
|
1248
1248
|
},
|
|
1249
|
+
[MEGAETH]: {
|
|
1250
|
+
// BTC/USD [USDM-USDM]
|
|
1251
|
+
"0x31EdCc52bE2Fa55Ba68f50409F9e6b7d9EbF3D59": {
|
|
1252
|
+
marketTokenAddress: "0x31EdCc52bE2Fa55Ba68f50409F9e6b7d9EbF3D59",
|
|
1253
|
+
indexTokenAddress: "0xc258141Ad80cafF9ab82a04bEb1c10F4B5bCb8F4",
|
|
1254
|
+
longTokenAddress: "0xFAfDdbb3FC7688494971a79cc65DCa3EF82079E7",
|
|
1255
|
+
shortTokenAddress: "0xFAfDdbb3FC7688494971a79cc65DCa3EF82079E7",
|
|
1256
|
+
},
|
|
1257
|
+
// ETH/USD [USDM-USDM]
|
|
1258
|
+
"0x9b1B72720f6D277F3b1e607a0c5fab1B300248b1": {
|
|
1259
|
+
marketTokenAddress: "0x9b1B72720f6D277F3b1e607a0c5fab1B300248b1",
|
|
1260
|
+
indexTokenAddress: "0x4200000000000000000000000000000000000006",
|
|
1261
|
+
longTokenAddress: "0xFAfDdbb3FC7688494971a79cc65DCa3EF82079E7",
|
|
1262
|
+
shortTokenAddress: "0xFAfDdbb3FC7688494971a79cc65DCa3EF82079E7",
|
|
1263
|
+
},
|
|
1264
|
+
// SOL/USD [USDM-USDM]
|
|
1265
|
+
"0xe8E716F1cddfFD0698B86919D41A8228d701fEe9": {
|
|
1266
|
+
marketTokenAddress: "0xe8E716F1cddfFD0698B86919D41A8228d701fEe9",
|
|
1267
|
+
indexTokenAddress: "0x30998706b1e5C95e9d3645D2e9E0EB1466819962",
|
|
1268
|
+
longTokenAddress: "0xFAfDdbb3FC7688494971a79cc65DCa3EF82079E7",
|
|
1269
|
+
shortTokenAddress: "0xFAfDdbb3FC7688494971a79cc65DCa3EF82079E7",
|
|
1270
|
+
},
|
|
1271
|
+
// SWAP-ONLY [ETH-USDM]
|
|
1272
|
+
"0xc5c9B5E23810565763De41144741477eeCB25e2e": {
|
|
1273
|
+
marketTokenAddress: "0xc5c9B5E23810565763De41144741477eeCB25e2e",
|
|
1274
|
+
indexTokenAddress: "0x0000000000000000000000000000000000000000",
|
|
1275
|
+
longTokenAddress: "0x4200000000000000000000000000000000000006",
|
|
1276
|
+
shortTokenAddress: "0xFAfDdbb3FC7688494971a79cc65DCa3EF82079E7",
|
|
1277
|
+
},
|
|
1278
|
+
},
|
|
1249
1279
|
};
|
|
1250
1280
|
export function getMarketsByChainId(chainId) {
|
|
1251
1281
|
if (!MARKETS[chainId]) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ARBITRUM, ARBITRUM_SEPOLIA, AVALANCHE, AVALANCHE_FUJI, BOTANIX } from "./chains";
|
|
1
|
+
import { ARBITRUM, ARBITRUM_SEPOLIA, AVALANCHE, AVALANCHE_FUJI, BOTANIX, MEGAETH } from "./chains";
|
|
2
2
|
export const ORACLE_FALLBACK_TRACKER_CONFIG = {
|
|
3
3
|
trackInterval: 10 * 1000, // 10 secs
|
|
4
4
|
checkTimeout: 10 * 1000, // 10 secs
|
|
@@ -17,6 +17,7 @@ const ORACLE_KEEPER_URLS = {
|
|
|
17
17
|
[AVALANCHE]: "https://avalanche-api.gmxinfra.io",
|
|
18
18
|
[AVALANCHE_FUJI]: "https://synthetics-api-avax-fuji-upovm.ondigitalocean.app",
|
|
19
19
|
[BOTANIX]: "https://botanix-api.gmxinfra.io",
|
|
20
|
+
[MEGAETH]: "https://megaeth-api.gmxinfra.io",
|
|
20
21
|
[ARBITRUM_SEPOLIA]: "https://dolphin-app-a2dup.ondigitalocean.app",
|
|
21
22
|
};
|
|
22
23
|
const ORACLE_KEEPER_FALLBACK_URLS = {
|
|
@@ -24,6 +25,7 @@ const ORACLE_KEEPER_FALLBACK_URLS = {
|
|
|
24
25
|
[AVALANCHE]: ["https://avalanche-api-fallback.gmxinfra.io", "https://avalanche-api-fallback.gmxinfra2.io"],
|
|
25
26
|
[AVALANCHE_FUJI]: ["https://synthetics-api-avax-fuji.gmxinfra.io"],
|
|
26
27
|
[BOTANIX]: ["https://botanix-api-fallback.gmxinfra.io", "https://botanix-api-fallback.gmxinfra2.io"],
|
|
28
|
+
[MEGAETH]: ["https://megaeth-api-fallback.gmxinfra.io"],
|
|
27
29
|
[ARBITRUM_SEPOLIA]: ["https://dolphin-app-a2dup.ondigitalocean.app"],
|
|
28
30
|
};
|
|
29
31
|
export function getOracleKeeperUrl(chainId) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { zeroAddress } from "viem";
|
|
2
|
-
import { ARBITRUM, ARBITRUM_SEPOLIA, AVALANCHE, AVALANCHE_FUJI, BOTANIX } from "./chains";
|
|
2
|
+
import { ARBITRUM, ARBITRUM_SEPOLIA, AVALANCHE, AVALANCHE_FUJI, BOTANIX, MEGAETH } from "./chains";
|
|
3
3
|
import { getContract } from "./contracts";
|
|
4
4
|
export const NATIVE_TOKEN_ADDRESS = zeroAddress;
|
|
5
5
|
export const GM_STUB_ADDRESS = "<GM-ADDRESS>";
|
|
@@ -1961,6 +1961,94 @@ export const TOKENS = {
|
|
|
1961
1961
|
isPlatformToken: true,
|
|
1962
1962
|
},
|
|
1963
1963
|
],
|
|
1964
|
+
[MEGAETH]: [
|
|
1965
|
+
{
|
|
1966
|
+
name: "Ethereum",
|
|
1967
|
+
symbol: "ETH",
|
|
1968
|
+
address: NATIVE_TOKEN_ADDRESS,
|
|
1969
|
+
decimals: 18,
|
|
1970
|
+
isNative: true,
|
|
1971
|
+
isShortable: true,
|
|
1972
|
+
categories: ["layer1"],
|
|
1973
|
+
imageUrl: "https://assets.coingecko.com/coins/images/279/small/ethereum.png?1595348880",
|
|
1974
|
+
},
|
|
1975
|
+
{
|
|
1976
|
+
name: "Wrapped Ethereum",
|
|
1977
|
+
symbol: "WETH",
|
|
1978
|
+
address: "0x4200000000000000000000000000000000000006",
|
|
1979
|
+
decimals: 18,
|
|
1980
|
+
isWrapped: true,
|
|
1981
|
+
baseSymbol: "ETH",
|
|
1982
|
+
imageUrl: "https://assets.coingecko.com/coins/images/2518/thumb/weth.png?1628852295",
|
|
1983
|
+
},
|
|
1984
|
+
{
|
|
1985
|
+
name: "Bitcoin",
|
|
1986
|
+
symbol: "BTC",
|
|
1987
|
+
address: "0xc258141Ad80cafF9ab82a04bEb1c10F4B5bCb8F4",
|
|
1988
|
+
isSynthetic: true,
|
|
1989
|
+
decimals: 8,
|
|
1990
|
+
categories: ["layer1"],
|
|
1991
|
+
imageUrl: "https://assets.coingecko.com/coins/images/7598/thumb/wrapped_bitcoin_wbtc.png?1548822744",
|
|
1992
|
+
},
|
|
1993
|
+
{
|
|
1994
|
+
name: "Solana",
|
|
1995
|
+
symbol: "SOL",
|
|
1996
|
+
address: "0x30998706b1e5C95e9d3645D2e9E0EB1466819962",
|
|
1997
|
+
isSynthetic: true,
|
|
1998
|
+
priceDecimals: 3,
|
|
1999
|
+
decimals: 9,
|
|
2000
|
+
categories: ["layer1"],
|
|
2001
|
+
imageUrl: "https://assets.coingecko.com/coins/images/4128/small/solana.png?1640133422",
|
|
2002
|
+
},
|
|
2003
|
+
{
|
|
2004
|
+
name: "USDM",
|
|
2005
|
+
symbol: "USDM",
|
|
2006
|
+
address: "0xFAfDdbb3FC7688494971a79cc65DCa3EF82079E7",
|
|
2007
|
+
decimals: 18,
|
|
2008
|
+
isStable: true,
|
|
2009
|
+
imageUrl: "https://assets.coingecko.com/coins/images/69955/standard/USDm.png?1760170136",
|
|
2010
|
+
},
|
|
2011
|
+
{
|
|
2012
|
+
name: "GMX",
|
|
2013
|
+
symbol: "GMX",
|
|
2014
|
+
address: GMX_STUB_ADDRESS,
|
|
2015
|
+
decimals: 18,
|
|
2016
|
+
imageUrl: "https://assets.coingecko.com/coins/images/18323/small/arbit.png?1631532468",
|
|
2017
|
+
isPlatformToken: true,
|
|
2018
|
+
},
|
|
2019
|
+
{
|
|
2020
|
+
name: "Escrowed GMX",
|
|
2021
|
+
symbol: "ESGMX",
|
|
2022
|
+
address: ESGMX_STUB_ADDRESS,
|
|
2023
|
+
decimals: 18,
|
|
2024
|
+
isPlatformToken: true,
|
|
2025
|
+
},
|
|
2026
|
+
{
|
|
2027
|
+
name: "GMX LP",
|
|
2028
|
+
symbol: "GLP",
|
|
2029
|
+
address: GLP_STUB_ADDRESS,
|
|
2030
|
+
decimals: 18,
|
|
2031
|
+
imageUrl: "https://github.com/gmx-io/gmx-assets/blob/main/GMX-Assets/PNG/GLP_LOGO%20ONLY.png?raw=true",
|
|
2032
|
+
isPlatformToken: true,
|
|
2033
|
+
},
|
|
2034
|
+
/** Placeholder tokens */
|
|
2035
|
+
{
|
|
2036
|
+
name: "GMX Market tokens",
|
|
2037
|
+
symbol: "GM",
|
|
2038
|
+
address: GM_STUB_ADDRESS,
|
|
2039
|
+
decimals: 18,
|
|
2040
|
+
imageUrl: "https://raw.githubusercontent.com/gmx-io/gmx-assets/main/GMX-Assets/PNG/GM_LOGO.png",
|
|
2041
|
+
isPlatformToken: true,
|
|
2042
|
+
},
|
|
2043
|
+
{
|
|
2044
|
+
name: "GLV Market tokens",
|
|
2045
|
+
symbol: "GLV",
|
|
2046
|
+
address: GLV_STUB_ADDRESS,
|
|
2047
|
+
decimals: 18,
|
|
2048
|
+
imageUrl: "https://raw.githubusercontent.com/gmx-io/gmx-assets/main/GMX-Assets/PNG/GLV_LOGO.png",
|
|
2049
|
+
isPlatformToken: true,
|
|
2050
|
+
},
|
|
2051
|
+
],
|
|
1964
2052
|
};
|
|
1965
2053
|
export const TOKEN_COLOR_MAP = {
|
|
1966
2054
|
ETH: "#6062a6",
|
|
@@ -2004,7 +2092,7 @@ export const SYNTHETIC_TOKENS = {};
|
|
|
2004
2092
|
export const TOKENS_BY_SYMBOL_MAP = {};
|
|
2005
2093
|
export const WRAPPED_TOKENS_MAP = {};
|
|
2006
2094
|
export const NATIVE_TOKENS_MAP = {};
|
|
2007
|
-
const CHAIN_IDS = [ARBITRUM, AVALANCHE, AVALANCHE_FUJI, BOTANIX, ARBITRUM_SEPOLIA];
|
|
2095
|
+
const CHAIN_IDS = [ARBITRUM, AVALANCHE, AVALANCHE_FUJI, BOTANIX, ARBITRUM_SEPOLIA, MEGAETH];
|
|
2008
2096
|
for (let j = 0; j < CHAIN_IDS.length; j++) {
|
|
2009
2097
|
const chainId = CHAIN_IDS[j];
|
|
2010
2098
|
TOKENS_MAP[chainId] = {};
|
|
@@ -374,6 +374,7 @@ describe("Decrease Order Payloads", () => {
|
|
|
374
374
|
twapId: "8000",
|
|
375
375
|
numberOfParts: twapParams.numberOfParts,
|
|
376
376
|
isExpress: false,
|
|
377
|
+
isJit: false,
|
|
377
378
|
});
|
|
378
379
|
return {
|
|
379
380
|
orderPayload: {
|
|
@@ -468,6 +469,7 @@ describe("Decrease Order Payloads", () => {
|
|
|
468
469
|
const decoded = decodeTwapUiFeeReceiver(uiFeeReceiver);
|
|
469
470
|
expect(decoded).toEqual({
|
|
470
471
|
isExpress: false,
|
|
472
|
+
isJit: false,
|
|
471
473
|
twapId: "8000",
|
|
472
474
|
numberOfParts: twapParams.numberOfParts,
|
|
473
475
|
});
|
|
@@ -542,6 +542,7 @@ describe("Increase Order Payloads", () => {
|
|
|
542
542
|
const decoded = decodeTwapUiFeeReceiver(uiFeeReceiver);
|
|
543
543
|
expect(decoded).toEqual({
|
|
544
544
|
isExpress: false,
|
|
545
|
+
isJit: false,
|
|
545
546
|
twapId: "8000",
|
|
546
547
|
numberOfParts: twapParams.numberOfParts,
|
|
547
548
|
});
|
|
@@ -638,6 +639,7 @@ describe("Increase Order Payloads", () => {
|
|
|
638
639
|
const decoded = decodeTwapUiFeeReceiver(uiFeeReceiver);
|
|
639
640
|
expect(decoded).toEqual({
|
|
640
641
|
isExpress: false,
|
|
642
|
+
isJit: false,
|
|
641
643
|
twapId: "8000",
|
|
642
644
|
numberOfParts: twapParams.numberOfParts,
|
|
643
645
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isAddress } from "viem";
|
|
2
2
|
import { describe, it, expect } from "vitest";
|
|
3
|
-
import { createTwapUiFeeReceiver, decodeTwapUiFeeReceiver, setUiFeeReceiverIsExpress } from "../twap/uiFeeReceiver";
|
|
3
|
+
import { createTwapUiFeeReceiver, decodeTwapUiFeeReceiver, setUiFeeReceiverIsExpress, setUiFeeReceiverIsJit, } from "../twap/uiFeeReceiver";
|
|
4
4
|
describe("uiFeeReceiver", () => {
|
|
5
5
|
describe("decodeTwapUiFeeReceiver", () => {
|
|
6
6
|
it("should return undefined if the address is not a valid address", () => {
|
|
@@ -14,6 +14,15 @@ describe("uiFeeReceiver", () => {
|
|
|
14
14
|
it("should correctly decode isExpress", () => {
|
|
15
15
|
expect(decodeTwapUiFeeReceiver("0xff0000000000000000000000000000010a123401")).toEqual({
|
|
16
16
|
isExpress: true,
|
|
17
|
+
isJit: false,
|
|
18
|
+
twapId: "1234",
|
|
19
|
+
numberOfParts: 10,
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
it("should correctly decode isJit", () => {
|
|
23
|
+
expect(decodeTwapUiFeeReceiver("0xff0000000000000000000000000001000a123401")).toEqual({
|
|
24
|
+
isExpress: false,
|
|
25
|
+
isJit: true,
|
|
17
26
|
twapId: "1234",
|
|
18
27
|
numberOfParts: 10,
|
|
19
28
|
});
|
|
@@ -21,11 +30,13 @@ describe("uiFeeReceiver", () => {
|
|
|
21
30
|
it("should return the twapId and numberOfParts if the uiFeeReceiver is valid twap", () => {
|
|
22
31
|
expect(decodeTwapUiFeeReceiver("0xff0000000000000000000000000000000a123401")).toEqual({
|
|
23
32
|
isExpress: false,
|
|
33
|
+
isJit: false,
|
|
24
34
|
twapId: "1234",
|
|
25
35
|
numberOfParts: 10,
|
|
26
36
|
});
|
|
27
37
|
expect(decodeTwapUiFeeReceiver("0xff000000000000000000000000000000153a4f01")).toEqual({
|
|
28
38
|
isExpress: false,
|
|
39
|
+
isJit: false,
|
|
29
40
|
twapId: "3a4f",
|
|
30
41
|
numberOfParts: 21,
|
|
31
42
|
});
|
|
@@ -60,3 +71,16 @@ describe("setUiFeeReceiverIsExpress", () => {
|
|
|
60
71
|
expect(setUiFeeReceiverIsExpress("0xff0000000000000000000000000000000a123401", false)).toEqual("0xff0000000000000000000000000000000a123401");
|
|
61
72
|
});
|
|
62
73
|
});
|
|
74
|
+
describe("setUiFeeReceiverIsJit", () => {
|
|
75
|
+
it("should correctly set isJit for simple uiFeeReceiver", () => {
|
|
76
|
+
expect(setUiFeeReceiverIsJit("0xff00000000000000000000000000000000000001", true)).toEqual("0xff00000000000000000000000000010000000001");
|
|
77
|
+
expect(setUiFeeReceiverIsJit("0xff00000000000000000000000000010000000001", false)).toEqual("0xff00000000000000000000000000000000000001");
|
|
78
|
+
});
|
|
79
|
+
it("should preserve isExpress when setting isJit", () => {
|
|
80
|
+
expect(setUiFeeReceiverIsJit("0xff0000000000000000000000000000010a123401", true)).toEqual("0xff0000000000000000000000000001010a123401");
|
|
81
|
+
});
|
|
82
|
+
it("should correctly set isJit for twap uiFeeReceiver", () => {
|
|
83
|
+
expect(setUiFeeReceiverIsJit("0xff0000000000000000000000000000000a123401", true)).toEqual("0xff0000000000000000000000000001000a123401");
|
|
84
|
+
expect(setUiFeeReceiverIsJit("0xff0000000000000000000000000001000a123401", false)).toEqual("0xff0000000000000000000000000000000a123401");
|
|
85
|
+
});
|
|
86
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -31,6 +31,7 @@ export function extendError(error, params) {
|
|
|
31
31
|
error.errorSource = params.errorSource;
|
|
32
32
|
error.isAdditionalValidationPassed = params.isAdditionalValidationPassed;
|
|
33
33
|
error.additionalValidationType = params.additionalValidationType;
|
|
34
|
+
error.simulationMethod = params.simulationMethod;
|
|
34
35
|
error.data = params.data;
|
|
35
36
|
return error;
|
|
36
37
|
}
|
|
@@ -44,6 +45,7 @@ export function parseError(error, errorDepth = 0) {
|
|
|
44
45
|
const errorContext = typeof error === "string" ? undefined : error?.errorContext;
|
|
45
46
|
const isAdditionalValidationPassed = typeof error === "string" ? undefined : error?.isAdditionalValidationPassed;
|
|
46
47
|
const additionalValidationType = typeof error === "string" ? undefined : error?.additionalValidationType;
|
|
48
|
+
const simulationMethod = typeof error === "string" ? undefined : error?.simulationMethod;
|
|
47
49
|
const data = typeof error === "string" ? undefined : error?.data;
|
|
48
50
|
let errorMessage = "Unknown error";
|
|
49
51
|
let errorStack = undefined;
|
|
@@ -153,6 +155,7 @@ export function parseError(error, errorDepth = 0) {
|
|
|
153
155
|
parentError,
|
|
154
156
|
isAdditionalValidationPassed,
|
|
155
157
|
additionalValidationType,
|
|
158
|
+
simulationMethod,
|
|
156
159
|
errorDepth,
|
|
157
160
|
};
|
|
158
161
|
}
|
|
@@ -5,6 +5,12 @@ import { bigMath } from "../bigmath";
|
|
|
5
5
|
import { applyFactor, expandDecimals } from "../numbers";
|
|
6
6
|
import { DecreasePositionSwapType } from "../orders/types";
|
|
7
7
|
import { convertBetweenTokens, convertToTokenAmount, convertToUsd, getTokenData } from "../tokens";
|
|
8
|
+
export function getIsExecutionFeeHigh(chainId, feeUsd) {
|
|
9
|
+
return feeUsd > expandDecimals(getHighExecutionFee(chainId), USD_DECIMALS);
|
|
10
|
+
}
|
|
11
|
+
export function getIsExecutionFeeVeryHigh(chainId, feeUsd) {
|
|
12
|
+
return feeUsd > expandDecimals(getExcessiveExecutionFee(chainId), USD_DECIMALS);
|
|
13
|
+
}
|
|
8
14
|
export function getExecutionFee(chainId, gasLimits,
|
|
9
15
|
// TODO optimize we only need the native token data
|
|
10
16
|
tokensData, estimatedGasLimit, gasPrice, oraclePriceCount, numberOfParts) {
|
|
@@ -26,8 +32,8 @@ tokensData, estimatedGasLimit, gasPrice, oraclePriceCount, numberOfParts) {
|
|
|
26
32
|
}
|
|
27
33
|
const feeTokenAmount = feeTokenAmountPerExecution * BigInt(numberOfParts ?? 1);
|
|
28
34
|
const feeUsd = convertToUsd(feeTokenAmount, nativeToken.decimals, nativeToken.prices.minPrice);
|
|
29
|
-
const isFeeHigh =
|
|
30
|
-
const isFeeVeryHigh =
|
|
35
|
+
const isFeeHigh = getIsExecutionFeeHigh(chainId, feeUsd);
|
|
36
|
+
const isFeeVeryHigh = getIsExecutionFeeVeryHigh(chainId, feeUsd);
|
|
31
37
|
return {
|
|
32
38
|
feeUsd,
|
|
33
39
|
feeTokenAmount,
|
|
@@ -7,3 +7,16 @@ export async function fetchApiTokensData(ctx) {
|
|
|
7
7
|
const tInfos = await ctx.api.fetchJson("/tokens/info");
|
|
8
8
|
return tInfos.map((tInfo) => deserializeBigIntsInObject(tInfo, { handleInts: true }));
|
|
9
9
|
}
|
|
10
|
+
export async function fetchApiMarkets(ctx) {
|
|
11
|
+
const markets = await ctx.api.fetchJson("/markets");
|
|
12
|
+
return markets.map((m) => deserializeBigIntsInObject(m, { handleInts: true }));
|
|
13
|
+
}
|
|
14
|
+
export async function fetchApiMarketsTickers(ctx, params) {
|
|
15
|
+
const tickers = await ctx.api.fetchJson("/markets/tickers", {
|
|
16
|
+
query: {
|
|
17
|
+
addresses: params?.addresses,
|
|
18
|
+
symbols: params?.symbols,
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
return tickers.map((t) => deserializeBigIntsInObject(t, { handleInts: true }));
|
|
22
|
+
}
|
|
@@ -122,6 +122,10 @@ export function formatUsd(usd, opts = {}) {
|
|
|
122
122
|
if (opts.visualMultiplier) {
|
|
123
123
|
usd *= BigInt(opts.visualMultiplier);
|
|
124
124
|
}
|
|
125
|
+
if (opts.roundMode === "floor" && displayDecimals < USD_DECIMALS) {
|
|
126
|
+
const factor = expandDecimals(1, USD_DECIMALS - displayDecimals);
|
|
127
|
+
usd = usd >= 0n ? (usd / factor) * factor : ((usd - factor + 1n) / factor) * factor;
|
|
128
|
+
}
|
|
125
129
|
const defaultMinThreshold = displayDecimals > 1 ? "0." + "0".repeat(displayDecimals - 1) + "1" : undefined;
|
|
126
130
|
const exceedingInfo = getLimitedDisplay(usd, USD_DECIMALS, {
|
|
127
131
|
maxThreshold: opts.maxThreshold,
|
|
@@ -271,8 +271,8 @@ export function buildUpdateOrderPayload(p) {
|
|
|
271
271
|
},
|
|
272
272
|
};
|
|
273
273
|
}
|
|
274
|
-
export function getBatchTotalExecutionFee({ batchParams, tokensData, chainId, }) {
|
|
275
|
-
if (getIsEmptyBatch(batchParams)) {
|
|
274
|
+
export function getBatchTotalExecutionFee({ batchParams, tokensData, chainId, allowEmptyBatch = false, }) {
|
|
275
|
+
if (getIsEmptyBatch(batchParams) && !allowEmptyBatch) {
|
|
276
276
|
return undefined;
|
|
277
277
|
}
|
|
278
278
|
let feeTokenAmount = 0n;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export async function fetchApiPerformanceAnnualized(ctx, params) {
|
|
2
|
+
return ctx.api.fetchJson("/performance/annualized", {
|
|
3
|
+
query: {
|
|
4
|
+
period: params?.period,
|
|
5
|
+
address: params?.address,
|
|
6
|
+
},
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
export async function fetchApiPerformanceSnapshots(ctx, params) {
|
|
10
|
+
return ctx.api.fetchJson("/performance/snapshots", {
|
|
11
|
+
query: {
|
|
12
|
+
period: params?.period,
|
|
13
|
+
address: params?.address,
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { deserializeBigIntsInObject } from "../numbers";
|
|
2
|
+
export async function fetchApiStakingPower(ctx, params) {
|
|
3
|
+
const data = await ctx.api.fetchJson("/staking/power", {
|
|
4
|
+
query: { address: params.address },
|
|
5
|
+
});
|
|
6
|
+
return deserializeBigIntsInObject(data, { handleInts: true });
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -76,7 +76,7 @@ export function getSwapAmountsByFromValue(p) {
|
|
|
76
76
|
};
|
|
77
77
|
}
|
|
78
78
|
export function getSwapAmountsByToValue(p) {
|
|
79
|
-
const { tokenIn, tokenOut, amountOut, triggerRatio, isLimit, uiFeeFactor, swapOptimizationOrder, allowedSwapSlippageBps, marketsInfoData, chainId, externalSwapQuoteParams, allowSameTokenSwap, } = p;
|
|
79
|
+
const { tokenIn, tokenOut, amountOut, triggerRatio, isLimit, uiFeeFactor, swapOptimizationOrder, allowedSwapSlippageBps, marketsInfoData, chainId, externalSwapQuoteParams, allowSameTokenSwap, swapPricingType = SwapPricingType.Swap, } = p;
|
|
80
80
|
if (!externalSwapQuoteParams) {
|
|
81
81
|
return getSwapAmountsByToValueDefault(p);
|
|
82
82
|
}
|
|
@@ -88,7 +88,7 @@ export function getSwapAmountsByToValue(p) {
|
|
|
88
88
|
chainId,
|
|
89
89
|
externalSwapQuoteParams,
|
|
90
90
|
swapOptimizationOrder,
|
|
91
|
-
swapPricingType
|
|
91
|
+
swapPricingType,
|
|
92
92
|
allowSameTokenSwap,
|
|
93
93
|
});
|
|
94
94
|
const swapStrategy = buildSwapStrategy({
|
|
@@ -99,7 +99,7 @@ export function getSwapAmountsByToValue(p) {
|
|
|
99
99
|
chainId,
|
|
100
100
|
swapOptimizationOrder,
|
|
101
101
|
externalSwapQuoteParams,
|
|
102
|
-
swapPricingType
|
|
102
|
+
swapPricingType,
|
|
103
103
|
allowSameTokenSwap,
|
|
104
104
|
});
|
|
105
105
|
const uiFeeUsd = applyFactor(swapStrategy.usdIn, uiFeeFactor);
|