@gmx-io/sdk 0.0.1-alpha-1
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/LICENSE +40 -0
- package/README.md +79 -0
- package/build/abis/CustomErrors.json +3254 -0
- package/build/abis/DataStore.json +1440 -0
- package/build/abis/ERC721.json +442 -0
- package/build/abis/EventEmitter.json +2065 -0
- package/build/abis/ExchangeRouter.json +1598 -0
- package/build/abis/GMT.json +522 -0
- package/build/abis/GlpManager.json +592 -0
- package/build/abis/GlvReader.json +1425 -0
- package/build/abis/GlvRouter.json +613 -0
- package/build/abis/GmxMigrator.json +657 -0
- package/build/abis/GovToken.json +1121 -0
- package/build/abis/MintableBaseToken.json +696 -0
- package/build/abis/Multicall.json +333 -0
- package/build/abis/OrderBook.json +1997 -0
- package/build/abis/OrderBookReader.json +111 -0
- package/build/abis/OrderExecutor.json +122 -0
- package/build/abis/PositionManager.json +1165 -0
- package/build/abis/PositionRouter.json +2030 -0
- package/build/abis/Reader.json +355 -0
- package/build/abis/ReaderV2.json +630 -0
- package/build/abis/ReferralStorage.json +507 -0
- package/build/abis/RewardReader.json +86 -0
- package/build/abis/RewardRouter.json +769 -0
- package/build/abis/RewardTracker.json +918 -0
- package/build/abis/Router-v2.json +605 -0
- package/build/abis/Router.json +605 -0
- package/build/abis/SubaccountRouter.json +648 -0
- package/build/abis/SyntheticsReader.json +4577 -0
- package/build/abis/SyntheticsRouter.json +77 -0
- package/build/abis/Timelock.json +1737 -0
- package/build/abis/Token.json +345 -0
- package/build/abis/Treasury.json +411 -0
- package/build/abis/UniPool.json +89 -0
- package/build/abis/UniswapV2.json +1 -0
- package/build/abis/Vault.json +3220 -0
- package/build/abis/VaultReader.json +87 -0
- package/build/abis/VaultV2.json +3019 -0
- package/build/abis/VaultV2b.json +3220 -0
- package/build/abis/Vester.json +1031 -0
- package/build/abis/WETH.json +320 -0
- package/build/abis/YieldFarm.json +599 -0
- package/build/abis/YieldToken.json +560 -0
- package/build/prebuilt/hashedMarketConfigKeys.json +3658 -0
- package/build/prebuilt/hashedMarketValuesKeys.json +1103 -0
- package/build/prebuilt/index.ts +28 -0
- package/build/src/abis/CustomErrors.json +3254 -0
- package/build/src/abis/DataStore.json +1440 -0
- package/build/src/abis/ERC721.json +442 -0
- package/build/src/abis/EventEmitter.json +2065 -0
- package/build/src/abis/ExchangeRouter.json +1598 -0
- package/build/src/abis/GMT.json +522 -0
- package/build/src/abis/GlpManager.json +591 -0
- package/build/src/abis/GlvReader.json +1424 -0
- package/build/src/abis/GlvRouter.json +612 -0
- package/build/src/abis/GmxMigrator.json +657 -0
- package/build/src/abis/GovToken.json +1121 -0
- package/build/src/abis/MintableBaseToken.json +696 -0
- package/build/src/abis/Multicall.json +333 -0
- package/build/src/abis/OrderBook.json +1997 -0
- package/build/src/abis/OrderBookReader.json +111 -0
- package/build/src/abis/OrderExecutor.json +122 -0
- package/build/src/abis/PositionManager.json +1165 -0
- package/build/src/abis/PositionRouter.json +2030 -0
- package/build/src/abis/Reader.json +355 -0
- package/build/src/abis/ReaderV2.json +630 -0
- package/build/src/abis/ReferralStorage.json +507 -0
- package/build/src/abis/RewardReader.json +86 -0
- package/build/src/abis/RewardRouter.json +769 -0
- package/build/src/abis/RewardTracker.json +918 -0
- package/build/src/abis/Router-v2.json +605 -0
- package/build/src/abis/Router.json +605 -0
- package/build/src/abis/SubaccountRouter.json +648 -0
- package/build/src/abis/SyntheticsReader.json +4577 -0
- package/build/src/abis/SyntheticsRouter.json +77 -0
- package/build/src/abis/Timelock.json +1737 -0
- package/build/src/abis/Token.json +345 -0
- package/build/src/abis/Treasury.json +411 -0
- package/build/src/abis/UniPool.json +89 -0
- package/build/src/abis/UniswapV2.json +1 -0
- package/build/src/abis/Vault.json +3220 -0
- package/build/src/abis/VaultReader.json +87 -0
- package/build/src/abis/VaultV2.json +3019 -0
- package/build/src/abis/VaultV2b.json +3220 -0
- package/build/src/abis/Vester.json +1031 -0
- package/build/src/abis/WETH.json +320 -0
- package/build/src/abis/YieldFarm.json +599 -0
- package/build/src/abis/YieldToken.json +560 -0
- package/build/src/configs/batch.d.ts +6 -0
- package/build/src/configs/batch.js +51 -0
- package/build/src/configs/chains.d.ts +37 -0
- package/build/src/configs/chains.js +90 -0
- package/build/src/configs/contracts.d.ts +2 -0
- package/build/src/configs/contracts.js +218 -0
- package/build/src/configs/dataStore.d.ts +149 -0
- package/build/src/configs/dataStore.js +276 -0
- package/build/src/configs/factors.d.ts +20 -0
- package/build/src/configs/factors.js +21 -0
- package/build/src/configs/markets.d.ts +8 -0
- package/build/src/configs/markets.js +528 -0
- package/build/src/configs/subgraph.d.ts +3 -0
- package/build/src/configs/subgraph.js +3 -0
- package/build/src/configs/tokens.d.ts +89 -0
- package/build/src/configs/tokens.js +1269 -0
- package/build/src/index.d.ts +44 -0
- package/build/src/index.js +245 -0
- package/build/src/modules/accounts/accounts.d.ts +5 -0
- package/build/src/modules/accounts/accounts.js +36 -0
- package/build/src/modules/accounts/accounts.spec.d.ts +1 -0
- package/build/src/modules/accounts/accounts.spec.js +7 -0
- package/build/src/modules/base.d.ts +9 -0
- package/build/src/modules/base.js +15 -0
- package/build/src/modules/markets/index.d.ts +26 -0
- package/build/src/modules/markets/index.js +339 -0
- package/build/src/modules/markets/markets.spec.d.ts +1 -0
- package/build/src/modules/markets/markets.spec.js +38 -0
- package/build/src/modules/markets/query-builders.d.ts +40 -0
- package/build/src/modules/markets/query-builders.js +379 -0
- package/build/src/modules/markets/types.d.ts +42 -0
- package/build/src/modules/markets/types.js +1 -0
- package/build/src/modules/oracle.d.ts +31 -0
- package/build/src/modules/oracle.js +53 -0
- package/build/src/modules/orders/orders.d.ts +60 -0
- package/build/src/modules/orders/orders.js +270 -0
- package/build/src/modules/orders/orders.spec.d.ts +1 -0
- package/build/src/modules/orders/orders.spec.js +16 -0
- package/build/src/modules/orders/transactions/cancelOrdersTxn.d.ts +6 -0
- package/build/src/modules/orders/transactions/cancelOrdersTxn.js +15 -0
- package/build/src/modules/orders/transactions/createDecreaseOrderTxn.d.ts +32 -0
- package/build/src/modules/orders/transactions/createDecreaseOrderTxn.js +98 -0
- package/build/src/modules/orders/transactions/createIncreaseOrderTxn.d.ts +77 -0
- package/build/src/modules/orders/transactions/createIncreaseOrderTxn.js +164 -0
- package/build/src/modules/orders/transactions/createSwapOrderTxn.d.ts +16 -0
- package/build/src/modules/orders/transactions/createSwapOrderTxn.js +97 -0
- package/build/src/modules/orders/transactions/createWrapOrUnwrapTxn.d.ts +6 -0
- package/build/src/modules/orders/transactions/createWrapOrUnwrapTxn.js +13 -0
- package/build/src/modules/orders/transactions/updateOrderTxn.d.ts +23 -0
- package/build/src/modules/orders/transactions/updateOrderTxn.js +44 -0
- package/build/src/modules/orders/utils.d.ts +248 -0
- package/build/src/modules/orders/utils.js +151 -0
- package/build/src/modules/positions/positions.d.ts +48 -0
- package/build/src/modules/positions/positions.js +563 -0
- package/build/src/modules/positions/positions.spec.d.ts +1 -0
- package/build/src/modules/positions/positions.spec.js +25 -0
- package/build/src/modules/tokens/tokens.d.ts +26 -0
- package/build/src/modules/tokens/tokens.js +132 -0
- package/build/src/modules/tokens/tokens.spec.d.ts +1 -0
- package/build/src/modules/tokens/tokens.spec.js +19 -0
- package/build/src/modules/trades/trades.d.ts +48 -0
- package/build/src/modules/trades/trades.js +390 -0
- package/build/src/modules/trades/trades.spec.d.ts +1 -0
- package/build/src/modules/trades/trades.spec.js +14 -0
- package/build/src/prebuilt/hashedMarketConfigKeys.json +3658 -0
- package/build/src/prebuilt/hashedMarketValuesKeys.json +1103 -0
- package/build/src/prebuilt/index.d.ts +14 -0
- package/build/src/prebuilt/index.js +9 -0
- package/build/src/types/amounts.d.ts +223 -0
- package/build/src/types/amounts.js +17 -0
- package/build/src/types/fees.d.ts +34 -0
- package/build/src/types/fees.js +1 -0
- package/build/src/types/markets.d.ts +143 -0
- package/build/src/types/markets.js +1 -0
- package/build/src/types/orders.d.ts +74 -0
- package/build/src/types/orders.js +33 -0
- package/build/src/types/positions.d.ts +53 -0
- package/build/src/types/positions.js +1 -0
- package/build/src/types/referrals.d.ts +124 -0
- package/build/src/types/referrals.js +9 -0
- package/build/src/types/sdk.d.ts +32 -0
- package/build/src/types/sdk.js +1 -0
- package/build/src/types/sidecarOrders.d.ts +54 -0
- package/build/src/types/sidecarOrders.js +1 -0
- package/build/src/types/syntheticsEvents.d.ts +88 -0
- package/build/src/types/syntheticsEvents.js +1 -0
- package/build/src/types/tokens.d.ts +89 -0
- package/build/src/types/tokens.js +1 -0
- package/build/src/types/trade.d.ts +223 -0
- package/build/src/types/trade.js +17 -0
- package/build/src/types/tradeHistory.d.ts +107 -0
- package/build/src/types/tradeHistory.js +8 -0
- package/build/src/utils/LruCache.d.ts +10 -0
- package/build/src/utils/LruCache.js +45 -0
- package/build/src/utils/bigmath.d.ts +7 -0
- package/build/src/utils/bigmath.js +23 -0
- package/build/src/utils/buildUrl.d.ts +1 -0
- package/build/src/utils/buildUrl.js +5 -0
- package/build/src/utils/callContract.d.ts +17 -0
- package/build/src/utils/callContract.js +133 -0
- package/build/src/utils/common.d.ts +2 -0
- package/build/src/utils/common.js +2 -0
- package/build/src/utils/fees/estimateOraclePriceCount.d.ts +6 -0
- package/build/src/utils/fees/estimateOraclePriceCount.js +19 -0
- package/build/src/utils/fees/executionFee.d.ts +59 -0
- package/build/src/utils/fees/executionFee.js +108 -0
- package/build/src/utils/fees/index.d.ts +29 -0
- package/build/src/utils/fees/index.js +89 -0
- package/build/src/utils/fees/priceImpact.d.ts +75 -0
- package/build/src/utils/fees/priceImpact.js +287 -0
- package/build/src/utils/graphqlFetcher.d.ts +1 -0
- package/build/src/utils/graphqlFetcher.js +18 -0
- package/build/src/utils/hash.d.ts +5 -0
- package/build/src/utils/hash.js +35 -0
- package/build/src/utils/marketKeysAndConfigs.d.ts +66 -0
- package/build/src/utils/marketKeysAndConfigs.js +257 -0
- package/build/src/utils/markets.d.ts +40 -0
- package/build/src/utils/markets.js +129 -0
- package/build/src/utils/multicall.d.ts +64 -0
- package/build/src/utils/multicall.js +116 -0
- package/build/src/utils/numbers.d.ts +9 -0
- package/build/src/utils/numbers.js +30 -0
- package/build/src/utils/objects.d.ts +18 -0
- package/build/src/utils/objects.js +30 -0
- package/build/src/utils/orders.d.ts +28 -0
- package/build/src/utils/orders.js +178 -0
- package/build/src/utils/positions.d.ts +60 -0
- package/build/src/utils/positions.js +133 -0
- package/build/src/utils/prices.d.ts +15 -0
- package/build/src/utils/prices.js +34 -0
- package/build/src/utils/referrals.d.ts +2 -0
- package/build/src/utils/referrals.js +27 -0
- package/build/src/utils/simulateExecuteOrder.d.ts +16 -0
- package/build/src/utils/simulateExecuteOrder.js +143 -0
- package/build/src/utils/slidingWindowFallbackSwitcher.d.ts +24 -0
- package/build/src/utils/slidingWindowFallbackSwitcher.js +40 -0
- package/build/src/utils/subgraph.d.ts +21 -0
- package/build/src/utils/subgraph.js +72 -0
- package/build/src/utils/swapStats.d.ts +35 -0
- package/build/src/utils/swapStats.js +197 -0
- package/build/src/utils/test.d.ts +2 -0
- package/build/src/utils/test.js +24 -0
- package/build/src/utils/tokens.d.ts +18 -0
- package/build/src/utils/tokens.js +64 -0
- package/build/src/utils/trade.d.ts +10 -0
- package/build/src/utils/trade.js +32 -0
- package/build/tsconfig.tsbuildinfo +1 -0
- package/package.json +96 -0
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { HIGH_PRICE_IMPACT_BPS } from "configs/factors";
|
|
2
|
+
import { bigMath } from "utils/bigmath";
|
|
3
|
+
import { applyFactor, getBasisPoints, PRECISION } from "utils/numbers";
|
|
4
|
+
export * from "./priceImpact";
|
|
5
|
+
export function getSwapFee(marketInfo, swapAmount, forPositiveImpact) {
|
|
6
|
+
const factor = forPositiveImpact
|
|
7
|
+
? marketInfo.swapFeeFactorForPositiveImpact
|
|
8
|
+
: marketInfo.swapFeeFactorForNegativeImpact;
|
|
9
|
+
return applyFactor(swapAmount, factor);
|
|
10
|
+
}
|
|
11
|
+
export function getPositionFee(marketInfo, sizeDeltaUsd, forPositiveImpact, referralInfo, uiFeeFactor) {
|
|
12
|
+
const factor = forPositiveImpact
|
|
13
|
+
? marketInfo.positionFeeFactorForPositiveImpact
|
|
14
|
+
: marketInfo.positionFeeFactorForNegativeImpact;
|
|
15
|
+
let positionFeeUsd = applyFactor(sizeDeltaUsd, factor);
|
|
16
|
+
const uiFeeUsd = applyFactor(sizeDeltaUsd, uiFeeFactor ?? 0n);
|
|
17
|
+
if (!referralInfo) {
|
|
18
|
+
return { positionFeeUsd, discountUsd: 0n, totalRebateUsd: 0n };
|
|
19
|
+
}
|
|
20
|
+
const totalRebateUsd = applyFactor(positionFeeUsd, referralInfo.totalRebateFactor);
|
|
21
|
+
const discountUsd = applyFactor(totalRebateUsd, referralInfo.discountFactor);
|
|
22
|
+
positionFeeUsd = positionFeeUsd - discountUsd;
|
|
23
|
+
return {
|
|
24
|
+
positionFeeUsd,
|
|
25
|
+
discountUsd,
|
|
26
|
+
totalRebateUsd,
|
|
27
|
+
uiFeeUsd,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export function getFundingFactorPerPeriod(marketInfo, isLong, periodInSeconds) {
|
|
31
|
+
const { fundingFactorPerSecond, longsPayShorts, longInterestUsd, shortInterestUsd } = marketInfo;
|
|
32
|
+
const isLargerSide = isLong ? longsPayShorts : !longsPayShorts;
|
|
33
|
+
let factorPerSecond;
|
|
34
|
+
if (isLargerSide) {
|
|
35
|
+
factorPerSecond = fundingFactorPerSecond * -1n;
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
const largerInterestUsd = longsPayShorts ? longInterestUsd : shortInterestUsd;
|
|
39
|
+
const smallerInterestUsd = longsPayShorts ? shortInterestUsd : longInterestUsd;
|
|
40
|
+
const ratio = smallerInterestUsd > 0 ? bigMath.mulDiv(largerInterestUsd, PRECISION, smallerInterestUsd) : 0n;
|
|
41
|
+
factorPerSecond = applyFactor(ratio, fundingFactorPerSecond);
|
|
42
|
+
}
|
|
43
|
+
return factorPerSecond * BigInt(periodInSeconds);
|
|
44
|
+
}
|
|
45
|
+
export function getFundingFeeRateUsd(marketInfo, isLong, sizeInUsd, periodInSeconds) {
|
|
46
|
+
const factor = getFundingFactorPerPeriod(marketInfo, isLong, periodInSeconds);
|
|
47
|
+
return applyFactor(sizeInUsd, factor);
|
|
48
|
+
}
|
|
49
|
+
export function getBorrowingFactorPerPeriod(marketInfo, isLong, periodInSeconds) {
|
|
50
|
+
const factorPerSecond = isLong
|
|
51
|
+
? marketInfo.borrowingFactorPerSecondForLongs
|
|
52
|
+
: marketInfo.borrowingFactorPerSecondForShorts;
|
|
53
|
+
return factorPerSecond * BigInt(periodInSeconds || 1);
|
|
54
|
+
}
|
|
55
|
+
export function getBorrowingFeeRateUsd(marketInfo, isLong, sizeInUsd, periodInSeconds) {
|
|
56
|
+
const factor = getBorrowingFactorPerPeriod(marketInfo, isLong, periodInSeconds);
|
|
57
|
+
return applyFactor(sizeInUsd, factor);
|
|
58
|
+
}
|
|
59
|
+
export function getIsHighPriceImpact(positionPriceImpact, swapPriceImpact) {
|
|
60
|
+
const totalPriceImpact = getTotalFeeItem([positionPriceImpact, swapPriceImpact]);
|
|
61
|
+
return totalPriceImpact.deltaUsd < 0 && bigMath.abs(totalPriceImpact.bps) >= HIGH_PRICE_IMPACT_BPS;
|
|
62
|
+
}
|
|
63
|
+
export function getFeeItem(feeDeltaUsd, basis, opts = {}) {
|
|
64
|
+
const { shouldRoundUp = false } = opts;
|
|
65
|
+
if (feeDeltaUsd === undefined)
|
|
66
|
+
return undefined;
|
|
67
|
+
return {
|
|
68
|
+
deltaUsd: feeDeltaUsd,
|
|
69
|
+
bps: basis !== undefined && basis > 0 ? getBasisPoints(feeDeltaUsd, basis, shouldRoundUp) : 0n,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
export function getTotalFeeItem(feeItems) {
|
|
73
|
+
const totalFeeItem = {
|
|
74
|
+
deltaUsd: 0n,
|
|
75
|
+
bps: 0n,
|
|
76
|
+
};
|
|
77
|
+
feeItems.filter(Boolean).forEach((feeItem) => {
|
|
78
|
+
totalFeeItem.deltaUsd = totalFeeItem.deltaUsd + feeItem.deltaUsd;
|
|
79
|
+
totalFeeItem.bps = totalFeeItem.bps + feeItem.bps;
|
|
80
|
+
});
|
|
81
|
+
return totalFeeItem;
|
|
82
|
+
}
|
|
83
|
+
export function getTotalSwapVolumeFromSwapStats(swapSteps) {
|
|
84
|
+
if (!swapSteps)
|
|
85
|
+
return 0n;
|
|
86
|
+
return swapSteps.reduce((acc, curr) => {
|
|
87
|
+
return acc + curr.usdIn;
|
|
88
|
+
}, 0n);
|
|
89
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { MarketInfo } from "types/markets";
|
|
2
|
+
import { TokenData } from "types/tokens";
|
|
3
|
+
export declare function getPriceImpactByAcceptablePrice(p: {
|
|
4
|
+
sizeDeltaUsd: bigint;
|
|
5
|
+
acceptablePrice: bigint;
|
|
6
|
+
indexPrice: bigint;
|
|
7
|
+
isLong: boolean;
|
|
8
|
+
isIncrease: boolean;
|
|
9
|
+
}): {
|
|
10
|
+
priceImpactDeltaUsd: bigint;
|
|
11
|
+
priceImpactDeltaAmount: bigint;
|
|
12
|
+
priceDelta: bigint;
|
|
13
|
+
acceptablePriceDeltaBps: bigint;
|
|
14
|
+
};
|
|
15
|
+
export declare function applySwapImpactWithCap(marketInfo: MarketInfo, token: TokenData, priceImpactDeltaUsd: bigint): {
|
|
16
|
+
impactDeltaAmount: bigint;
|
|
17
|
+
cappedDiffUsd: bigint;
|
|
18
|
+
};
|
|
19
|
+
export declare function getCappedPositionImpactUsd(marketInfo: MarketInfo, sizeDeltaUsd: bigint, isLong: boolean, opts?: {
|
|
20
|
+
fallbackToZero?: boolean;
|
|
21
|
+
}): bigint;
|
|
22
|
+
export declare function getPriceImpactForPosition(marketInfo: MarketInfo, sizeDeltaUsd: bigint, isLong: boolean, opts?: {
|
|
23
|
+
fallbackToZero?: boolean;
|
|
24
|
+
}): bigint;
|
|
25
|
+
export declare function getPriceImpactForSwap(marketInfo: MarketInfo, tokenA: TokenData, tokenB: TokenData, usdDeltaTokenA: bigint, usdDeltaTokenB: bigint, opts?: {
|
|
26
|
+
fallbackToZero?: boolean;
|
|
27
|
+
}): bigint;
|
|
28
|
+
export declare function getNextPoolAmountsParams(p: {
|
|
29
|
+
marketInfo: MarketInfo;
|
|
30
|
+
longToken: TokenData;
|
|
31
|
+
shortToken: TokenData;
|
|
32
|
+
longPoolAmount: bigint;
|
|
33
|
+
shortPoolAmount: bigint;
|
|
34
|
+
longDeltaUsd: bigint;
|
|
35
|
+
shortDeltaUsd: bigint;
|
|
36
|
+
}): {
|
|
37
|
+
longPoolUsd: bigint;
|
|
38
|
+
shortPoolUsd: bigint;
|
|
39
|
+
nextLongPoolUsd: bigint;
|
|
40
|
+
nextShortPoolUsd: bigint;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* @see https://github.com/gmx-io/gmx-synthetics/blob/updates/contracts/pricing/SwapPricingUtils.sol
|
|
44
|
+
*/
|
|
45
|
+
export declare function getPriceImpactUsd(p: {
|
|
46
|
+
currentLongUsd: bigint;
|
|
47
|
+
currentShortUsd: bigint;
|
|
48
|
+
nextLongUsd: bigint;
|
|
49
|
+
nextShortUsd: bigint;
|
|
50
|
+
factorPositive: bigint;
|
|
51
|
+
factorNegative: bigint;
|
|
52
|
+
exponentFactor: bigint;
|
|
53
|
+
fallbackToZero?: boolean;
|
|
54
|
+
}): bigint;
|
|
55
|
+
/**
|
|
56
|
+
* @see https://github.com/gmx-io/gmx-synthetics/blob/5fd9991ff2c37ae5f24f03bc9c132730b012ebf2/contracts/pricing/PricingUtils.sol
|
|
57
|
+
*/
|
|
58
|
+
export declare function calculateImpactForSameSideRebalance(p: {
|
|
59
|
+
currentDiff: bigint;
|
|
60
|
+
nextDiff: bigint;
|
|
61
|
+
hasPositiveImpact: boolean;
|
|
62
|
+
factor: bigint;
|
|
63
|
+
exponentFactor: bigint;
|
|
64
|
+
}): bigint;
|
|
65
|
+
/**
|
|
66
|
+
* @see https://github.com/gmx-io/gmx-synthetics/blob/5fd9991ff2c37ae5f24f03bc9c132730b012ebf2/contracts/pricing/PricingUtils.sol
|
|
67
|
+
*/
|
|
68
|
+
export declare function calculateImpactForCrossoverRebalance(p: {
|
|
69
|
+
currentDiff: bigint;
|
|
70
|
+
nextDiff: bigint;
|
|
71
|
+
factorPositive: bigint;
|
|
72
|
+
factorNegative: bigint;
|
|
73
|
+
exponentFactor: bigint;
|
|
74
|
+
}): bigint;
|
|
75
|
+
export declare function applyImpactFactor(diff: bigint, factor: bigint, exponent: bigint): bigint;
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
import { bigNumberify } from "modules/trades/trades";
|
|
2
|
+
import { bigMath } from "utils/bigmath";
|
|
3
|
+
import { getTokenPoolType } from "utils/markets";
|
|
4
|
+
import { applyFactor, expandDecimals, getBasisPoints, roundUpMagnitudeDivision } from "utils/numbers";
|
|
5
|
+
import { convertToTokenAmount, convertToUsd, getMidPrice } from "utils/tokens";
|
|
6
|
+
export function getPriceImpactByAcceptablePrice(p) {
|
|
7
|
+
const { sizeDeltaUsd, acceptablePrice, indexPrice: markPrice, isLong, isIncrease } = p;
|
|
8
|
+
const shouldFlipPriceDiff = isIncrease ? !isLong : isLong;
|
|
9
|
+
const priceDelta = (markPrice - acceptablePrice) * (shouldFlipPriceDiff ? -1n : 1n);
|
|
10
|
+
const acceptablePriceDeltaBps = markPrice === 0n ? 0n : getBasisPoints(priceDelta, markPrice);
|
|
11
|
+
const priceImpactDeltaUsd = acceptablePrice === 0n ? 0n : (sizeDeltaUsd * priceDelta) / acceptablePrice;
|
|
12
|
+
const priceImpactDeltaAmount = markPrice === 0n ? 0n : priceImpactDeltaUsd / markPrice;
|
|
13
|
+
return {
|
|
14
|
+
priceImpactDeltaUsd,
|
|
15
|
+
priceImpactDeltaAmount,
|
|
16
|
+
priceDelta,
|
|
17
|
+
acceptablePriceDeltaBps,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export function applySwapImpactWithCap(marketInfo, token, priceImpactDeltaUsd) {
|
|
21
|
+
const tokenPoolType = getTokenPoolType(marketInfo, token.address);
|
|
22
|
+
if (!tokenPoolType) {
|
|
23
|
+
throw new Error(`Token ${token.address} is not a collateral of the market ${marketInfo.marketTokenAddress}`);
|
|
24
|
+
}
|
|
25
|
+
const isLongCollateral = tokenPoolType === "long";
|
|
26
|
+
const price = priceImpactDeltaUsd > 0 ? token.prices.maxPrice : token.prices.minPrice;
|
|
27
|
+
let impactDeltaAmount;
|
|
28
|
+
let cappedDiffUsd = 0n;
|
|
29
|
+
if (priceImpactDeltaUsd > 0) {
|
|
30
|
+
// round positive impactAmount down, this will be deducted from the swap impact pool for the user
|
|
31
|
+
impactDeltaAmount = convertToTokenAmount(priceImpactDeltaUsd, token.decimals, price);
|
|
32
|
+
const maxImpactAmount = isLongCollateral
|
|
33
|
+
? marketInfo.swapImpactPoolAmountLong
|
|
34
|
+
: marketInfo.swapImpactPoolAmountShort;
|
|
35
|
+
if (impactDeltaAmount > maxImpactAmount) {
|
|
36
|
+
cappedDiffUsd = bigMath.mulDiv(impactDeltaAmount - maxImpactAmount, price, expandDecimals(1, token.decimals));
|
|
37
|
+
impactDeltaAmount = maxImpactAmount;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
// round negative impactAmount up, this will be deducted from the user
|
|
42
|
+
impactDeltaAmount = roundUpMagnitudeDivision(priceImpactDeltaUsd * expandDecimals(1, token.decimals), price);
|
|
43
|
+
}
|
|
44
|
+
return { impactDeltaAmount, cappedDiffUsd };
|
|
45
|
+
}
|
|
46
|
+
export function getCappedPositionImpactUsd(marketInfo, sizeDeltaUsd, isLong, opts = {}) {
|
|
47
|
+
const priceImpactDeltaUsd = getPriceImpactForPosition(marketInfo, sizeDeltaUsd, isLong, opts);
|
|
48
|
+
if (priceImpactDeltaUsd < 0) {
|
|
49
|
+
return priceImpactDeltaUsd;
|
|
50
|
+
}
|
|
51
|
+
const { indexToken } = marketInfo;
|
|
52
|
+
const impactPoolAmount = marketInfo?.positionImpactPoolAmount;
|
|
53
|
+
const maxPriceImpactUsdBasedOnImpactPool = convertToUsd(impactPoolAmount, indexToken.decimals, indexToken.prices.minPrice);
|
|
54
|
+
let cappedImpactUsd = priceImpactDeltaUsd;
|
|
55
|
+
if (cappedImpactUsd > maxPriceImpactUsdBasedOnImpactPool) {
|
|
56
|
+
cappedImpactUsd = maxPriceImpactUsdBasedOnImpactPool;
|
|
57
|
+
}
|
|
58
|
+
const maxPriceImpactFactor = marketInfo.maxPositionImpactFactorPositive;
|
|
59
|
+
const maxPriceImpactUsdBasedOnMaxPriceImpactFactor = applyFactor(bigMath.abs(sizeDeltaUsd), maxPriceImpactFactor);
|
|
60
|
+
if (cappedImpactUsd > maxPriceImpactUsdBasedOnMaxPriceImpactFactor) {
|
|
61
|
+
cappedImpactUsd = maxPriceImpactUsdBasedOnMaxPriceImpactFactor;
|
|
62
|
+
}
|
|
63
|
+
return cappedImpactUsd;
|
|
64
|
+
}
|
|
65
|
+
export function getPriceImpactForPosition(marketInfo, sizeDeltaUsd, isLong, opts = {}) {
|
|
66
|
+
const { longInterestUsd, shortInterestUsd } = marketInfo;
|
|
67
|
+
const { currentLongUsd, currentShortUsd, nextLongUsd, nextShortUsd } = getNextOpenInterestParams({
|
|
68
|
+
currentLongUsd: longInterestUsd,
|
|
69
|
+
currentShortUsd: shortInterestUsd,
|
|
70
|
+
usdDelta: sizeDeltaUsd,
|
|
71
|
+
isLong: isLong,
|
|
72
|
+
});
|
|
73
|
+
const priceImpactUsd = getPriceImpactUsd({
|
|
74
|
+
currentLongUsd,
|
|
75
|
+
currentShortUsd,
|
|
76
|
+
nextLongUsd,
|
|
77
|
+
nextShortUsd,
|
|
78
|
+
factorPositive: marketInfo.positionImpactFactorPositive,
|
|
79
|
+
factorNegative: marketInfo.positionImpactFactorNegative,
|
|
80
|
+
exponentFactor: marketInfo.positionImpactExponentFactor,
|
|
81
|
+
fallbackToZero: opts.fallbackToZero,
|
|
82
|
+
});
|
|
83
|
+
if (priceImpactUsd > 0) {
|
|
84
|
+
return priceImpactUsd;
|
|
85
|
+
}
|
|
86
|
+
if (bigMath.abs(marketInfo.virtualInventoryForPositions) <= 0) {
|
|
87
|
+
return priceImpactUsd;
|
|
88
|
+
}
|
|
89
|
+
const virtualInventoryParams = getNextOpenInterestForVirtualInventory({
|
|
90
|
+
virtualInventory: marketInfo.virtualInventoryForPositions,
|
|
91
|
+
usdDelta: sizeDeltaUsd,
|
|
92
|
+
isLong: isLong,
|
|
93
|
+
});
|
|
94
|
+
const priceImpactUsdForVirtualInventory = getPriceImpactUsd({
|
|
95
|
+
currentLongUsd: virtualInventoryParams.currentLongUsd,
|
|
96
|
+
currentShortUsd: virtualInventoryParams.currentShortUsd,
|
|
97
|
+
nextLongUsd: virtualInventoryParams.nextLongUsd,
|
|
98
|
+
nextShortUsd: virtualInventoryParams.nextShortUsd,
|
|
99
|
+
factorPositive: marketInfo.positionImpactFactorPositive,
|
|
100
|
+
factorNegative: marketInfo.positionImpactFactorNegative,
|
|
101
|
+
exponentFactor: marketInfo.positionImpactExponentFactor,
|
|
102
|
+
fallbackToZero: opts.fallbackToZero,
|
|
103
|
+
});
|
|
104
|
+
return priceImpactUsdForVirtualInventory < priceImpactUsd ? priceImpactUsdForVirtualInventory : priceImpactUsd;
|
|
105
|
+
}
|
|
106
|
+
export function getPriceImpactForSwap(marketInfo, tokenA, tokenB, usdDeltaTokenA, usdDeltaTokenB, opts = {}) {
|
|
107
|
+
const tokenAPoolType = getTokenPoolType(marketInfo, tokenA.address);
|
|
108
|
+
const tokenBPoolType = getTokenPoolType(marketInfo, tokenB.address);
|
|
109
|
+
if (tokenAPoolType === undefined ||
|
|
110
|
+
tokenBPoolType === undefined ||
|
|
111
|
+
(tokenAPoolType === tokenBPoolType && !marketInfo.isSameCollaterals)) {
|
|
112
|
+
throw new Error(`Invalid tokens to swap ${marketInfo.marketTokenAddress} ${tokenA.address} ${tokenB.address}`);
|
|
113
|
+
}
|
|
114
|
+
const [longToken, shortToken] = tokenAPoolType === "long" ? [tokenA, tokenB] : [tokenB, tokenA];
|
|
115
|
+
const [longDeltaUsd, shortDeltaUsd] = tokenAPoolType === "long" ? [usdDeltaTokenA, usdDeltaTokenB] : [usdDeltaTokenB, usdDeltaTokenA];
|
|
116
|
+
const { longPoolUsd, shortPoolUsd, nextLongPoolUsd, nextShortPoolUsd } = getNextPoolAmountsParams({
|
|
117
|
+
marketInfo,
|
|
118
|
+
longToken,
|
|
119
|
+
shortToken,
|
|
120
|
+
longPoolAmount: marketInfo.longPoolAmount,
|
|
121
|
+
shortPoolAmount: marketInfo.shortPoolAmount,
|
|
122
|
+
longDeltaUsd,
|
|
123
|
+
shortDeltaUsd,
|
|
124
|
+
});
|
|
125
|
+
const priceImpactUsd = getPriceImpactUsd({
|
|
126
|
+
currentLongUsd: longPoolUsd,
|
|
127
|
+
currentShortUsd: shortPoolUsd,
|
|
128
|
+
nextLongUsd: nextLongPoolUsd,
|
|
129
|
+
nextShortUsd: nextShortPoolUsd,
|
|
130
|
+
factorPositive: marketInfo.swapImpactFactorPositive,
|
|
131
|
+
factorNegative: marketInfo.swapImpactFactorNegative,
|
|
132
|
+
exponentFactor: marketInfo.swapImpactExponentFactor,
|
|
133
|
+
fallbackToZero: opts.fallbackToZero,
|
|
134
|
+
});
|
|
135
|
+
if (priceImpactUsd > 0) {
|
|
136
|
+
return priceImpactUsd;
|
|
137
|
+
}
|
|
138
|
+
const virtualInventoryLong = marketInfo.virtualPoolAmountForLongToken;
|
|
139
|
+
const virtualInventoryShort = marketInfo.virtualPoolAmountForShortToken;
|
|
140
|
+
if (virtualInventoryLong <= 0 || virtualInventoryShort <= 0) {
|
|
141
|
+
return priceImpactUsd;
|
|
142
|
+
}
|
|
143
|
+
const virtualInventoryParams = getNextPoolAmountsParams({
|
|
144
|
+
marketInfo,
|
|
145
|
+
longToken,
|
|
146
|
+
shortToken,
|
|
147
|
+
longPoolAmount: virtualInventoryLong,
|
|
148
|
+
shortPoolAmount: virtualInventoryShort,
|
|
149
|
+
longDeltaUsd,
|
|
150
|
+
shortDeltaUsd,
|
|
151
|
+
});
|
|
152
|
+
const priceImpactUsdForVirtualInventory = getPriceImpactUsd({
|
|
153
|
+
currentLongUsd: virtualInventoryParams.longPoolUsd,
|
|
154
|
+
currentShortUsd: virtualInventoryParams.shortPoolUsd,
|
|
155
|
+
nextLongUsd: virtualInventoryParams.nextLongPoolUsd,
|
|
156
|
+
nextShortUsd: virtualInventoryParams.nextShortPoolUsd,
|
|
157
|
+
factorPositive: marketInfo.swapImpactFactorPositive,
|
|
158
|
+
factorNegative: marketInfo.swapImpactFactorNegative,
|
|
159
|
+
exponentFactor: marketInfo.swapImpactExponentFactor,
|
|
160
|
+
fallbackToZero: opts.fallbackToZero,
|
|
161
|
+
});
|
|
162
|
+
return priceImpactUsdForVirtualInventory < priceImpactUsd ? priceImpactUsdForVirtualInventory : priceImpactUsd;
|
|
163
|
+
}
|
|
164
|
+
function getNextOpenInterestForVirtualInventory(p) {
|
|
165
|
+
const { virtualInventory, usdDelta, isLong } = p;
|
|
166
|
+
let currentLongUsd = 0n;
|
|
167
|
+
let currentShortUsd = 0n;
|
|
168
|
+
if (virtualInventory > 0) {
|
|
169
|
+
currentShortUsd = virtualInventory;
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
currentLongUsd = virtualInventory * -1n;
|
|
173
|
+
}
|
|
174
|
+
if (usdDelta < 0) {
|
|
175
|
+
const offset = bigMath.abs(usdDelta);
|
|
176
|
+
currentLongUsd = currentLongUsd + offset;
|
|
177
|
+
currentShortUsd = currentShortUsd + offset;
|
|
178
|
+
}
|
|
179
|
+
return getNextOpenInterestParams({
|
|
180
|
+
currentLongUsd,
|
|
181
|
+
currentShortUsd,
|
|
182
|
+
usdDelta,
|
|
183
|
+
isLong,
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
function getNextOpenInterestParams(p) {
|
|
187
|
+
const { currentLongUsd, currentShortUsd, usdDelta, isLong } = p;
|
|
188
|
+
let nextLongUsd = currentLongUsd;
|
|
189
|
+
let nextShortUsd = currentShortUsd;
|
|
190
|
+
if (isLong) {
|
|
191
|
+
nextLongUsd = (currentLongUsd ?? 0n) + (usdDelta ?? 0n);
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
nextShortUsd = (currentShortUsd ?? 0n) + (usdDelta ?? 0n);
|
|
195
|
+
}
|
|
196
|
+
return {
|
|
197
|
+
currentLongUsd,
|
|
198
|
+
currentShortUsd,
|
|
199
|
+
nextLongUsd,
|
|
200
|
+
nextShortUsd,
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
export function getNextPoolAmountsParams(p) {
|
|
204
|
+
const { marketInfo, longToken, shortToken, longPoolAmount, shortPoolAmount, longDeltaUsd, shortDeltaUsd } = p;
|
|
205
|
+
const longPrice = getMidPrice(longToken.prices);
|
|
206
|
+
const shortPrice = getMidPrice(shortToken.prices);
|
|
207
|
+
const longPoolUsd = convertToUsd(longPoolAmount, longToken.decimals, longPrice);
|
|
208
|
+
const shortPoolUsd = convertToUsd(shortPoolAmount, shortToken.decimals, shortPrice);
|
|
209
|
+
const longPoolUsdAdjustment = convertToUsd(marketInfo.longPoolAmountAdjustment, longToken.decimals, longPrice);
|
|
210
|
+
const shortPoolUsdAdjustment = convertToUsd(marketInfo.shortPoolAmountAdjustment, shortToken.decimals, shortPrice);
|
|
211
|
+
const nextLongPoolUsd = longPoolUsd + longDeltaUsd + longPoolUsdAdjustment;
|
|
212
|
+
const nextShortPoolUsd = shortPoolUsd + shortDeltaUsd + shortPoolUsdAdjustment;
|
|
213
|
+
return {
|
|
214
|
+
longPoolUsd,
|
|
215
|
+
shortPoolUsd,
|
|
216
|
+
nextLongPoolUsd,
|
|
217
|
+
nextShortPoolUsd,
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* @see https://github.com/gmx-io/gmx-synthetics/blob/updates/contracts/pricing/SwapPricingUtils.sol
|
|
222
|
+
*/
|
|
223
|
+
export function getPriceImpactUsd(p) {
|
|
224
|
+
const { nextLongUsd, nextShortUsd } = p;
|
|
225
|
+
if (nextLongUsd < 0 || nextShortUsd < 0) {
|
|
226
|
+
if (p.fallbackToZero) {
|
|
227
|
+
return 0n;
|
|
228
|
+
}
|
|
229
|
+
else {
|
|
230
|
+
throw new Error("Negative pool amount");
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
const currentDiff = bigMath.abs(p.currentLongUsd - p.currentShortUsd);
|
|
234
|
+
const nextDiff = bigMath.abs(nextLongUsd - nextShortUsd);
|
|
235
|
+
const isSameSideRebalance = p.currentLongUsd < p.currentShortUsd === nextLongUsd < nextShortUsd;
|
|
236
|
+
let impactUsd;
|
|
237
|
+
if (isSameSideRebalance) {
|
|
238
|
+
const hasPositiveImpact = nextDiff < currentDiff;
|
|
239
|
+
const factor = hasPositiveImpact ? p.factorPositive : p.factorNegative;
|
|
240
|
+
impactUsd = calculateImpactForSameSideRebalance({
|
|
241
|
+
currentDiff,
|
|
242
|
+
nextDiff,
|
|
243
|
+
hasPositiveImpact,
|
|
244
|
+
factor,
|
|
245
|
+
exponentFactor: p.exponentFactor,
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
else {
|
|
249
|
+
impactUsd = calculateImpactForCrossoverRebalance({
|
|
250
|
+
currentDiff,
|
|
251
|
+
nextDiff,
|
|
252
|
+
factorPositive: p.factorPositive,
|
|
253
|
+
factorNegative: p.factorNegative,
|
|
254
|
+
exponentFactor: p.exponentFactor,
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
return impactUsd;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* @see https://github.com/gmx-io/gmx-synthetics/blob/5fd9991ff2c37ae5f24f03bc9c132730b012ebf2/contracts/pricing/PricingUtils.sol
|
|
261
|
+
*/
|
|
262
|
+
export function calculateImpactForSameSideRebalance(p) {
|
|
263
|
+
const { currentDiff, nextDiff, hasPositiveImpact, factor, exponentFactor } = p;
|
|
264
|
+
const currentImpact = applyImpactFactor(currentDiff, factor, exponentFactor);
|
|
265
|
+
const nextImpact = applyImpactFactor(nextDiff, factor, exponentFactor);
|
|
266
|
+
const deltaDiff = bigMath.abs(currentImpact - nextImpact);
|
|
267
|
+
return hasPositiveImpact ? deltaDiff : -deltaDiff;
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* @see https://github.com/gmx-io/gmx-synthetics/blob/5fd9991ff2c37ae5f24f03bc9c132730b012ebf2/contracts/pricing/PricingUtils.sol
|
|
271
|
+
*/
|
|
272
|
+
export function calculateImpactForCrossoverRebalance(p) {
|
|
273
|
+
const { currentDiff, nextDiff, factorNegative, factorPositive, exponentFactor } = p;
|
|
274
|
+
const positiveImpact = applyImpactFactor(currentDiff, factorPositive, exponentFactor);
|
|
275
|
+
const negativeImpactUsd = applyImpactFactor(nextDiff, factorNegative, exponentFactor);
|
|
276
|
+
const deltaDiffUsd = bigMath.abs(positiveImpact - negativeImpactUsd);
|
|
277
|
+
return positiveImpact > negativeImpactUsd ? deltaDiffUsd : -deltaDiffUsd;
|
|
278
|
+
}
|
|
279
|
+
export function applyImpactFactor(diff, factor, exponent) {
|
|
280
|
+
// Convert diff and exponent to float js numbers
|
|
281
|
+
const _diff = Number(diff) / 10 ** 30;
|
|
282
|
+
const _exponent = Number(exponent) / 10 ** 30;
|
|
283
|
+
// Pow and convert back to BigInt with 30 decimals
|
|
284
|
+
let result = bigNumberify(BigInt(Math.round(_diff ** _exponent * 10 ** 30)));
|
|
285
|
+
result = (result * factor) / expandDecimals(1, 30);
|
|
286
|
+
return result;
|
|
287
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function graphqlFetcher<T>(endpoint: string, query: string, variables?: object): Promise<T | undefined>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import fetch from "cross-fetch";
|
|
2
|
+
export default async function graphqlFetcher(endpoint, query, variables) {
|
|
3
|
+
try {
|
|
4
|
+
const response = await fetch(endpoint, {
|
|
5
|
+
body: JSON.stringify({ query, variables }),
|
|
6
|
+
headers: { "Content-type": "application/json" },
|
|
7
|
+
method: "POST",
|
|
8
|
+
});
|
|
9
|
+
if (!response.ok) {
|
|
10
|
+
throw new Error(`HTTP error: ${response.status}`);
|
|
11
|
+
}
|
|
12
|
+
const { data } = await response.json();
|
|
13
|
+
return data;
|
|
14
|
+
}
|
|
15
|
+
catch (error) {
|
|
16
|
+
throw new Error(`Error fetching GraphQL query: ${error}`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare function hashData(dataTypes: any, dataValues: any): string;
|
|
2
|
+
export declare function hashString(string: string): string;
|
|
3
|
+
export declare function hashDataMap<R extends Record<string, [dataTypes: string[], dataValues: (string | number | bigint | boolean)[]] | undefined>>(map: R): {
|
|
4
|
+
[K in keyof R]: string;
|
|
5
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { encodeAbiParameters, keccak256 } from "viem";
|
|
2
|
+
import { LRUCache } from "./LruCache";
|
|
3
|
+
const dataCache = new LRUCache(10000);
|
|
4
|
+
export function hashData(dataTypes, dataValues) {
|
|
5
|
+
const key = JSON.stringify({ dataTypes, dataValues }, (_, val) => (typeof val === "bigint" ? String(val) : val));
|
|
6
|
+
if (dataCache.has(key)) {
|
|
7
|
+
return dataCache.get(key);
|
|
8
|
+
}
|
|
9
|
+
// Convert dataTypes from array of strings to array of objects with 'type' property
|
|
10
|
+
const abiParameters = dataTypes.map((type) => ({ type }));
|
|
11
|
+
const bytes = encodeAbiParameters(abiParameters, dataValues);
|
|
12
|
+
const hash = keccak256(bytes);
|
|
13
|
+
dataCache.set(key, hash);
|
|
14
|
+
return hash;
|
|
15
|
+
}
|
|
16
|
+
const stringCache = new LRUCache(10000);
|
|
17
|
+
export function hashString(string) {
|
|
18
|
+
if (stringCache.has(string)) {
|
|
19
|
+
return stringCache.get(string);
|
|
20
|
+
}
|
|
21
|
+
const hash = hashData(["string"], [string]);
|
|
22
|
+
stringCache.set(string, hash);
|
|
23
|
+
return hash;
|
|
24
|
+
}
|
|
25
|
+
export function hashDataMap(map) {
|
|
26
|
+
const result = {};
|
|
27
|
+
for (const key of Object.keys(map)) {
|
|
28
|
+
if (!map[key]) {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
const [dataTypes, dataValues] = map[key];
|
|
32
|
+
result[key] = hashData(dataTypes, dataValues);
|
|
33
|
+
}
|
|
34
|
+
return result;
|
|
35
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Market } from "types/markets";
|
|
2
|
+
export declare function hashMarketConfigKeys(market: Market): {
|
|
3
|
+
isDisabled: string;
|
|
4
|
+
maxLongPoolAmount: string;
|
|
5
|
+
maxShortPoolAmount: string;
|
|
6
|
+
maxLongPoolUsdForDeposit: string;
|
|
7
|
+
maxShortPoolUsdForDeposit: string;
|
|
8
|
+
longPoolAmountAdjustment: string;
|
|
9
|
+
shortPoolAmountAdjustment: string;
|
|
10
|
+
reserveFactorLong: string;
|
|
11
|
+
reserveFactorShort: string;
|
|
12
|
+
openInterestReserveFactorLong: string;
|
|
13
|
+
openInterestReserveFactorShort: string;
|
|
14
|
+
maxOpenInterestLong: string;
|
|
15
|
+
maxOpenInterestShort: string;
|
|
16
|
+
minPositionImpactPoolAmount: string;
|
|
17
|
+
positionImpactPoolDistributionRate: string;
|
|
18
|
+
borrowingFactorLong: string;
|
|
19
|
+
borrowingFactorShort: string;
|
|
20
|
+
borrowingExponentFactorLong: string;
|
|
21
|
+
borrowingExponentFactorShort: string;
|
|
22
|
+
fundingFactor: string;
|
|
23
|
+
fundingExponentFactor: string;
|
|
24
|
+
fundingIncreaseFactorPerSecond: string;
|
|
25
|
+
fundingDecreaseFactorPerSecond: string;
|
|
26
|
+
thresholdForStableFunding: string;
|
|
27
|
+
thresholdForDecreaseFunding: string;
|
|
28
|
+
minFundingFactorPerSecond: string;
|
|
29
|
+
maxFundingFactorPerSecond: string;
|
|
30
|
+
maxPnlFactorForTradersLong: string;
|
|
31
|
+
maxPnlFactorForTradersShort: string;
|
|
32
|
+
positionFeeFactorForPositiveImpact: string;
|
|
33
|
+
positionFeeFactorForNegativeImpact: string;
|
|
34
|
+
positionImpactFactorPositive: string;
|
|
35
|
+
positionImpactFactorNegative: string;
|
|
36
|
+
maxPositionImpactFactorPositive: string;
|
|
37
|
+
maxPositionImpactFactorNegative: string;
|
|
38
|
+
maxPositionImpactFactorForLiquidations: string;
|
|
39
|
+
minCollateralFactor: string;
|
|
40
|
+
minCollateralFactorForOpenInterestLong: string;
|
|
41
|
+
minCollateralFactorForOpenInterestShort: string;
|
|
42
|
+
positionImpactExponentFactor: string;
|
|
43
|
+
swapFeeFactorForPositiveImpact: string;
|
|
44
|
+
swapFeeFactorForNegativeImpact: string;
|
|
45
|
+
swapImpactFactorPositive: string;
|
|
46
|
+
swapImpactFactorNegative: string;
|
|
47
|
+
swapImpactExponentFactor: string;
|
|
48
|
+
virtualMarketId: string;
|
|
49
|
+
virtualLongTokenId: string;
|
|
50
|
+
virtualShortTokenId: string;
|
|
51
|
+
};
|
|
52
|
+
export declare function hashMarketValuesKeys(market: Market): {
|
|
53
|
+
longPoolAmount: string;
|
|
54
|
+
shortPoolAmount: string;
|
|
55
|
+
positionImpactPoolAmount: string;
|
|
56
|
+
swapImpactPoolAmountLong: string;
|
|
57
|
+
swapImpactPoolAmountShort: string;
|
|
58
|
+
longInterestUsingLongToken: string;
|
|
59
|
+
longInterestUsingShortToken: string;
|
|
60
|
+
shortInterestUsingLongToken: string;
|
|
61
|
+
shortInterestUsingShortToken: string;
|
|
62
|
+
longInterestInTokensUsingLongToken: string;
|
|
63
|
+
longInterestInTokensUsingShortToken: string;
|
|
64
|
+
shortInterestInTokensUsingLongToken: string;
|
|
65
|
+
shortInterestInTokensUsingShortToken: string;
|
|
66
|
+
};
|