@nradko/metric-omm-sdk-v1 0.0.16
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/README.md +111 -0
- package/dist/abis/MetricOmmPool.d.ts +784 -0
- package/dist/abis/MetricOmmPool.d.ts.map +1 -0
- package/dist/abis/MetricOmmPool.js +1008 -0
- package/dist/abis/MetricOmmPool.js.map +1 -0
- package/dist/abis/MetricOmmPoolFactory.d.ts +1365 -0
- package/dist/abis/MetricOmmPoolFactory.d.ts.map +1 -0
- package/dist/abis/MetricOmmPoolFactory.js +1754 -0
- package/dist/abis/MetricOmmPoolFactory.js.map +1 -0
- package/dist/abis/MetricOmmPoolLiquidityAdder.d.ts +308 -0
- package/dist/abis/MetricOmmPoolLiquidityAdder.d.ts.map +1 -0
- package/dist/abis/MetricOmmPoolLiquidityAdder.js +401 -0
- package/dist/abis/MetricOmmPoolLiquidityAdder.js.map +1 -0
- package/dist/abis/MetricOmmPoolStateView.d.ts +538 -0
- package/dist/abis/MetricOmmPoolStateView.d.ts.map +1 -0
- package/dist/abis/MetricOmmPoolStateView.js +717 -0
- package/dist/abis/MetricOmmPoolStateView.js.map +1 -0
- package/dist/abis/MetricOmmPoolSwapper.d.ts +557 -0
- package/dist/abis/MetricOmmPoolSwapper.d.ts.map +1 -0
- package/dist/abis/MetricOmmPoolSwapper.js +723 -0
- package/dist/abis/MetricOmmPoolSwapper.js.map +1 -0
- package/dist/abis/Multicall3.d.ts +333 -0
- package/dist/abis/Multicall3.d.ts.map +1 -0
- package/dist/abis/Multicall3.js +441 -0
- package/dist/abis/Multicall3.js.map +1 -0
- package/dist/abis/PriceProvider.d.ts +142 -0
- package/dist/abis/PriceProvider.d.ts.map +1 -0
- package/dist/abis/PriceProvider.js +184 -0
- package/dist/abis/PriceProvider.js.map +1 -0
- package/dist/abis/PriceProviderUi.d.ts +433 -0
- package/dist/abis/PriceProviderUi.d.ts.map +1 -0
- package/dist/abis/PriceProviderUi.js +318 -0
- package/dist/abis/PriceProviderUi.js.map +1 -0
- package/dist/abis/index.d.ts +11 -0
- package/dist/abis/index.d.ts.map +1 -0
- package/dist/abis/index.js +11 -0
- package/dist/abis/index.js.map +1 -0
- package/dist/addresses.d.ts +52 -0
- package/dist/addresses.d.ts.map +1 -0
- package/dist/addresses.js +58 -0
- package/dist/addresses.js.map +1 -0
- package/dist/constants.d.ts +20 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +26 -0
- package/dist/constants.js.map +1 -0
- package/dist/factory/collectFees.d.ts +41 -0
- package/dist/factory/collectFees.d.ts.map +1 -0
- package/dist/factory/collectFees.js +120 -0
- package/dist/factory/collectFees.js.map +1 -0
- package/dist/factory/index.d.ts +5 -0
- package/dist/factory/index.d.ts.map +1 -0
- package/dist/factory/index.js +5 -0
- package/dist/factory/index.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -0
- package/dist/pool/create.d.ts +80 -0
- package/dist/pool/create.d.ts.map +1 -0
- package/dist/pool/create.js +80 -0
- package/dist/pool/create.js.map +1 -0
- package/dist/pool/index.d.ts +7 -0
- package/dist/pool/index.d.ts.map +1 -0
- package/dist/pool/index.js +10 -0
- package/dist/pool/index.js.map +1 -0
- package/dist/pool/liquidity.d.ts +165 -0
- package/dist/pool/liquidity.d.ts.map +1 -0
- package/dist/pool/liquidity.js +508 -0
- package/dist/pool/liquidity.js.map +1 -0
- package/dist/pool/read.d.ts +22 -0
- package/dist/pool/read.d.ts.map +1 -0
- package/dist/pool/read.js +88 -0
- package/dist/pool/read.js.map +1 -0
- package/dist/router/index.d.ts +5 -0
- package/dist/router/index.d.ts.map +1 -0
- package/dist/router/index.js +5 -0
- package/dist/router/index.js.map +1 -0
- package/dist/router/swap.d.ts +117 -0
- package/dist/router/swap.d.ts.map +1 -0
- package/dist/router/swap.js +298 -0
- package/dist/router/swap.js.map +1 -0
- package/dist/stateView/index.d.ts +5 -0
- package/dist/stateView/index.d.ts.map +1 -0
- package/dist/stateView/index.js +5 -0
- package/dist/stateView/index.js.map +1 -0
- package/dist/stateView/read.d.ts +80 -0
- package/dist/stateView/read.d.ts.map +1 -0
- package/dist/stateView/read.js +249 -0
- package/dist/stateView/read.js.map +1 -0
- package/dist/types.d.ts +134 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +6 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/binData.d.ts +65 -0
- package/dist/utils/binData.d.ts.map +1 -0
- package/dist/utils/binData.js +109 -0
- package/dist/utils/binData.js.map +1 -0
- package/dist/utils/index.d.ts +7 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +10 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/liquidityMath.d.ts +10 -0
- package/dist/utils/liquidityMath.d.ts.map +1 -0
- package/dist/utils/liquidityMath.js +31 -0
- package/dist/utils/liquidityMath.js.map +1 -0
- package/dist/utils/price.d.ts +13 -0
- package/dist/utils/price.d.ts.map +1 -0
- package/dist/utils/price.js +21 -0
- package/dist/utils/price.js.map +1 -0
- package/package.json +74 -0
- package/src/abis/MetricOmmPool.ts +1007 -0
- package/src/abis/MetricOmmPoolFactory.ts +1753 -0
- package/src/abis/MetricOmmPoolLiquidityAdder.ts +400 -0
- package/src/abis/MetricOmmPoolStateView.ts +716 -0
- package/src/abis/MetricOmmPoolSwapper.ts +722 -0
- package/src/abis/Multicall3.ts +440 -0
- package/src/abis/PriceProvider.ts +183 -0
- package/src/abis/PriceProviderUi.ts +317 -0
- package/src/abis/index.ts +11 -0
- package/src/addresses.ts +100 -0
- package/src/constants.ts +35 -0
- package/src/factory/collectFees.ts +197 -0
- package/src/factory/index.ts +12 -0
- package/src/index.ts +157 -0
- package/src/pool/create.ts +158 -0
- package/src/pool/index.ts +47 -0
- package/src/pool/liquidity.ts +839 -0
- package/src/pool/read.ts +131 -0
- package/src/router/index.ts +27 -0
- package/src/router/swap.ts +507 -0
- package/src/stateView/index.ts +18 -0
- package/src/stateView/read.ts +355 -0
- package/src/types.ts +162 -0
- package/src/utils/binData.ts +127 -0
- package/src/utils/index.ts +26 -0
- package/src/utils/liquidityMath.ts +47 -0
- package/src/utils/price.ts +23 -0
package/src/index.ts
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MetricAMM SDK (v1 contracts: Swapper, LiquidityAdder, add/removeLiquidity).
|
|
3
|
+
*
|
|
4
|
+
* @packageDocumentation
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
// ============ Types ============
|
|
8
|
+
export type {
|
|
9
|
+
LiquidityDelta,
|
|
10
|
+
PoolLiquidityDelta,
|
|
11
|
+
BinData,
|
|
12
|
+
PoolImmutables,
|
|
13
|
+
PoolState,
|
|
14
|
+
BinState,
|
|
15
|
+
BinStateExternal,
|
|
16
|
+
BinStatesExternal,
|
|
17
|
+
BinStatesScaled,
|
|
18
|
+
Slot0,
|
|
19
|
+
Slot1,
|
|
20
|
+
FeeConfig,
|
|
21
|
+
PositionBinSharesResult,
|
|
22
|
+
CalculateUniformLiquidityParams,
|
|
23
|
+
LiquidityBinValueInput as AnyLiquidityBinInput,
|
|
24
|
+
CalculateAnyLiquidityParams,
|
|
25
|
+
PreparedLiquidityDistribution,
|
|
26
|
+
CalculatedLiquidityDistribution,
|
|
27
|
+
} from "./types.js";
|
|
28
|
+
|
|
29
|
+
// ============ Constants ============
|
|
30
|
+
export { Q64, MAX_UINT128, MAX_INT128, MAX_UINT104, MAX_INT104 } from "./constants.js";
|
|
31
|
+
|
|
32
|
+
// ============ Addresses ============
|
|
33
|
+
export {
|
|
34
|
+
ChainId,
|
|
35
|
+
ADDRESSES,
|
|
36
|
+
getAddresses,
|
|
37
|
+
getAddressesOrThrow,
|
|
38
|
+
isChainSupported,
|
|
39
|
+
getSupportedChainIds,
|
|
40
|
+
isChainDeployed,
|
|
41
|
+
type ChainAddresses,
|
|
42
|
+
type DeployedChainId,
|
|
43
|
+
} from "./addresses.js";
|
|
44
|
+
|
|
45
|
+
// ============ ABIs ============
|
|
46
|
+
export {
|
|
47
|
+
MetricOmmPoolAbi,
|
|
48
|
+
MetricOmmPoolStateViewAbi,
|
|
49
|
+
MetricOmmPoolSwapperAbi,
|
|
50
|
+
MetricOmmPoolLiquidityAdderAbi,
|
|
51
|
+
MetricOmmPoolFactoryAbi,
|
|
52
|
+
} from "./abis/index.js";
|
|
53
|
+
|
|
54
|
+
// ============ Utils ============
|
|
55
|
+
export {
|
|
56
|
+
packBinData,
|
|
57
|
+
packBins5,
|
|
58
|
+
packBinDataArray,
|
|
59
|
+
unpackBinData,
|
|
60
|
+
createBins,
|
|
61
|
+
createUniformBins,
|
|
62
|
+
priceToQ64,
|
|
63
|
+
q64ToPrice,
|
|
64
|
+
} from "./utils/index.js";
|
|
65
|
+
|
|
66
|
+
// ============ Pool Functions ============
|
|
67
|
+
export {
|
|
68
|
+
createPool,
|
|
69
|
+
prepareFactoryCreatePoolParams,
|
|
70
|
+
encodeCreatePoolCalldata,
|
|
71
|
+
preparePoolBinData,
|
|
72
|
+
type CreatePoolFactoryParams,
|
|
73
|
+
type CreatePoolParams,
|
|
74
|
+
getPoolImmutables,
|
|
75
|
+
getPoolState,
|
|
76
|
+
getBinState,
|
|
77
|
+
getPositionBinShares,
|
|
78
|
+
} from "./pool/index.js";
|
|
79
|
+
|
|
80
|
+
// ============ StateView Functions ============
|
|
81
|
+
export {
|
|
82
|
+
getSlot0,
|
|
83
|
+
getSlot1,
|
|
84
|
+
getBinStateExternal,
|
|
85
|
+
getBinStatesExternal,
|
|
86
|
+
getBinStatesScaled,
|
|
87
|
+
getBinTotalShares,
|
|
88
|
+
getPositionBinSharesFromStateView,
|
|
89
|
+
toPositionBinKey,
|
|
90
|
+
getPositionBinSharesRange,
|
|
91
|
+
getFeeConfig,
|
|
92
|
+
getPriceProvider,
|
|
93
|
+
getLastTradeTimestamp,
|
|
94
|
+
} from "./stateView/index.js";
|
|
95
|
+
|
|
96
|
+
// ============ Liquidity Functions ============
|
|
97
|
+
export {
|
|
98
|
+
buildModifyLiquidityArgsForAddition,
|
|
99
|
+
buildModifyLiquidityArgsForUniformAddition,
|
|
100
|
+
buildModifyLiquidityArgsForUniformAdditionWithTotalTokenAmount,
|
|
101
|
+
buildModifyLiquidityArgsForPercentageRemoval,
|
|
102
|
+
buildModifyLiquidityArgsForRemoval,
|
|
103
|
+
buildAddLiquidityExactSharesParamsFromBinTargets,
|
|
104
|
+
buildRemoveLiquidityPoolDelta,
|
|
105
|
+
additionPlanToPoolLiquidityDelta,
|
|
106
|
+
removalPlanToPoolLiquidityDelta,
|
|
107
|
+
scaleWeightedPoolDeltasToFitCaps,
|
|
108
|
+
encodeAddLiquidityExactSharesSelfCalldata,
|
|
109
|
+
encodeAddLiquidityExactSharesWithOwnerCalldata,
|
|
110
|
+
encodeAddLiquidityWeightedSelfCalldata,
|
|
111
|
+
encodeAddLiquidityWeightedWithOwnerCalldata,
|
|
112
|
+
encodeRemoveLiquidityCalldata,
|
|
113
|
+
getPositionShares,
|
|
114
|
+
getPositionSharesForBins,
|
|
115
|
+
NO_SLIPPAGE_LIMIT,
|
|
116
|
+
type ModifyLiquidityArgs,
|
|
117
|
+
type BuildModifyLiquidityArgsBase,
|
|
118
|
+
type BuildModifyLiquidityArgsForAdditionParams,
|
|
119
|
+
type BuildModifyLiquidityArgsForUniformAdditionParams,
|
|
120
|
+
type BuildModifyLiquidityArgsForUniformAdditionWithTotalTokenAmountParams,
|
|
121
|
+
type BuildModifyLiquidityArgsForPercentageRemovalParams,
|
|
122
|
+
type BuildModifyLiquidityArgsForRemovalParams,
|
|
123
|
+
type RemoveLiquidityParams,
|
|
124
|
+
type BinRemovalSpec,
|
|
125
|
+
} from "./pool/liquidity.js";
|
|
126
|
+
|
|
127
|
+
// ============ Swapper Functions ============
|
|
128
|
+
export {
|
|
129
|
+
buildArgsForSwapExactInput,
|
|
130
|
+
buildArgsAndExpectedAmountsForSwapExactInput,
|
|
131
|
+
quoteExpectedAmountsForSwapExactInput,
|
|
132
|
+
buildArgsForSwapExactOutput,
|
|
133
|
+
buildArgsAndExpectedAmountsForSwapExactOutput,
|
|
134
|
+
quoteExpectedAmountsForSwapExactOutput,
|
|
135
|
+
prepareSwapExactInputCalldata,
|
|
136
|
+
prepareSwapExactOutputCalldata,
|
|
137
|
+
prepareSwapExactInputNativeForTokensCalldata,
|
|
138
|
+
type PreparedSwapTransaction,
|
|
139
|
+
type BuildSwapExactInputParams,
|
|
140
|
+
type QuoteExpectedAmountsForSwapExactInputParams,
|
|
141
|
+
type BuildSwapExactOutputParams,
|
|
142
|
+
type QuoteExpectedAmountsForSwapExactOutputParams,
|
|
143
|
+
type SwapExactInputParams,
|
|
144
|
+
type SwapExactOutputParams,
|
|
145
|
+
type SwapExactInputArgs,
|
|
146
|
+
type SwapExactOutputArgs,
|
|
147
|
+
} from "./router/index.js";
|
|
148
|
+
|
|
149
|
+
// ============ Factory Functions ============
|
|
150
|
+
export {
|
|
151
|
+
getFactoryAssetBalances,
|
|
152
|
+
collectFactoryFees,
|
|
153
|
+
type FactoryAssetBalance,
|
|
154
|
+
type CollectFactoryFeesParams,
|
|
155
|
+
type CollectedFactoryFeeTx,
|
|
156
|
+
type CollectFactoryFeesResult,
|
|
157
|
+
} from "./factory/index.js";
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MetricAMM SDK - Pool creation (v1 factory `PoolParameters`).
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { Address, PublicClient, WalletClient, Hex } from "viem";
|
|
6
|
+
import { encodeFunctionData, zeroAddress } from "viem";
|
|
7
|
+
import { POOL_FACTORY_ABI } from "../constants.js";
|
|
8
|
+
import { createUniformBins } from "../utils/binData.js";
|
|
9
|
+
|
|
10
|
+
// ============ Types ============
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Parameters for creating a new pool via the v1 factory.
|
|
14
|
+
*/
|
|
15
|
+
export interface CreatePoolFactoryParams {
|
|
16
|
+
token0: Address;
|
|
17
|
+
token1: Address;
|
|
18
|
+
priceProvider: Address;
|
|
19
|
+
admin: Address;
|
|
20
|
+
/** Defaults to zero address (no allowlist). */
|
|
21
|
+
depositAllowlistProvider?: Address;
|
|
22
|
+
/** Defaults to zero address (no allowlist). */
|
|
23
|
+
swapAllowlistProvider?: Address;
|
|
24
|
+
/** Defaults to 0. */
|
|
25
|
+
priceProviderTimelock?: bigint;
|
|
26
|
+
nonNegativeBins: bigint[];
|
|
27
|
+
negativeBins: bigint[];
|
|
28
|
+
initialScaledToken0PerShareE18: bigint;
|
|
29
|
+
initialScaledToken1PerShareE18: bigint;
|
|
30
|
+
minimalMintableLiquidity: bigint;
|
|
31
|
+
reportSwapToPriceProvider: boolean;
|
|
32
|
+
/** Admin spread fee in E6 units (same convention as on-chain pool fees). */
|
|
33
|
+
adminSpreadFeeE6: number;
|
|
34
|
+
/** Admin notional fee in E8 units. */
|
|
35
|
+
adminNotionalFeeE8: number;
|
|
36
|
+
adminFeeDestination: Address;
|
|
37
|
+
/** Distance from oracle price to bin anchor, in pool E6 units (same scaling as v0 helper). */
|
|
38
|
+
curBinDistFromProvidedPricePercent: number;
|
|
39
|
+
salt?: Hex;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* @deprecated Use CreatePoolFactoryParams instead
|
|
44
|
+
*/
|
|
45
|
+
export interface CreatePoolParams {
|
|
46
|
+
token0: Address;
|
|
47
|
+
token1: Address;
|
|
48
|
+
priceProvider: Address;
|
|
49
|
+
numBins: number;
|
|
50
|
+
binLengthE6: number;
|
|
51
|
+
baseFeeE6: number;
|
|
52
|
+
protocolFeeE6: number;
|
|
53
|
+
maxDriftE8: bigint;
|
|
54
|
+
maxDriftDecayPerSecondE8: bigint;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function prepareFactoryCreatePoolParams(params: CreatePoolFactoryParams) {
|
|
58
|
+
const curBinDistFromProvidedPriceE6 = Math.round(
|
|
59
|
+
params.curBinDistFromProvidedPricePercent * 10_000,
|
|
60
|
+
);
|
|
61
|
+
if (curBinDistFromProvidedPriceE6 < -(2 ** 23) || curBinDistFromProvidedPriceE6 > 2 ** 23 - 1) {
|
|
62
|
+
throw new Error("curBinDistFromProvidedPricePercent maps to int24 out of range");
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const salt =
|
|
66
|
+
params.salt ??
|
|
67
|
+
(`0x${[...Array(64)].map(() => Math.floor(Math.random() * 16).toString(16)).join("")}` as Hex);
|
|
68
|
+
|
|
69
|
+
return {
|
|
70
|
+
token0: params.token0,
|
|
71
|
+
token1: params.token1,
|
|
72
|
+
priceProvider: params.priceProvider,
|
|
73
|
+
depositAllowlistProvider: params.depositAllowlistProvider ?? zeroAddress,
|
|
74
|
+
swapAllowlistProvider: params.swapAllowlistProvider ?? zeroAddress,
|
|
75
|
+
priceProviderTimelock: params.priceProviderTimelock ?? 0n,
|
|
76
|
+
admin: params.admin,
|
|
77
|
+
initialAmount0PerShareE18: params.initialScaledToken0PerShareE18,
|
|
78
|
+
initialAmount1PerShareE18: params.initialScaledToken1PerShareE18,
|
|
79
|
+
minimalMintableLiquidity: params.minimalMintableLiquidity,
|
|
80
|
+
reportSwapToPriceProvider: params.reportSwapToPriceProvider,
|
|
81
|
+
adminSpreadFeeE6: params.adminSpreadFeeE6,
|
|
82
|
+
adminNotionalFeeE8: params.adminNotionalFeeE8,
|
|
83
|
+
adminFeeDestination: params.adminFeeDestination,
|
|
84
|
+
curBinDistFromProvidedPriceE6: curBinDistFromProvidedPriceE6,
|
|
85
|
+
nonNegativeBinDataArray: params.nonNegativeBins,
|
|
86
|
+
negativeBinDataArray: params.negativeBins,
|
|
87
|
+
salt,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export async function createPool(
|
|
92
|
+
publicClient: PublicClient,
|
|
93
|
+
walletClient: WalletClient,
|
|
94
|
+
factoryAddress: Address,
|
|
95
|
+
params: CreatePoolFactoryParams,
|
|
96
|
+
account: Address,
|
|
97
|
+
): Promise<{ hash: Hex; poolAddress?: Address }> {
|
|
98
|
+
const factoryParams = prepareFactoryCreatePoolParams(params);
|
|
99
|
+
const args = buildCreatePoolArgs(factoryParams);
|
|
100
|
+
|
|
101
|
+
const { request, result } = await publicClient.simulateContract({
|
|
102
|
+
address: factoryAddress,
|
|
103
|
+
abi: POOL_FACTORY_ABI,
|
|
104
|
+
functionName: "createPool",
|
|
105
|
+
args,
|
|
106
|
+
account,
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
const hash = await walletClient.writeContract(request);
|
|
110
|
+
|
|
111
|
+
return {
|
|
112
|
+
hash,
|
|
113
|
+
poolAddress: result as Address,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export function encodeCreatePoolCalldata(params: CreatePoolFactoryParams): Hex {
|
|
118
|
+
const factoryParams = prepareFactoryCreatePoolParams(params);
|
|
119
|
+
const args = buildCreatePoolArgs(factoryParams);
|
|
120
|
+
|
|
121
|
+
return encodeFunctionData({
|
|
122
|
+
abi: POOL_FACTORY_ABI,
|
|
123
|
+
functionName: "createPool",
|
|
124
|
+
args,
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function buildCreatePoolArgs(factoryParams: unknown): unknown[] {
|
|
129
|
+
const createPoolAbi = (POOL_FACTORY_ABI as readonly any[]).find(
|
|
130
|
+
(item) => item?.type === "function" && item?.name === "createPool",
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
const inputCount = createPoolAbi?.inputs?.length ?? 1;
|
|
134
|
+
|
|
135
|
+
if (inputCount === 1) {
|
|
136
|
+
return [factoryParams];
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
throw new Error("Unsupported createPool ABI shape");
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* @deprecated Use prepareFactoryCreatePoolParams instead
|
|
144
|
+
*/
|
|
145
|
+
export function preparePoolBinData(params: CreatePoolParams): {
|
|
146
|
+
positiveBinData: bigint[];
|
|
147
|
+
negativeBinData: bigint[];
|
|
148
|
+
} {
|
|
149
|
+
const halfBins = Math.floor(params.numBins / 2);
|
|
150
|
+
|
|
151
|
+
const positiveBinData = createUniformBins(halfBins, params.binLengthE6);
|
|
152
|
+
const negativeBinData = createUniformBins(halfBins, params.binLengthE6);
|
|
153
|
+
|
|
154
|
+
return {
|
|
155
|
+
positiveBinData,
|
|
156
|
+
negativeBinData,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MetricAMM SDK - Pool Functions
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
// Pool creation
|
|
6
|
+
export {
|
|
7
|
+
createPool,
|
|
8
|
+
prepareFactoryCreatePoolParams,
|
|
9
|
+
encodeCreatePoolCalldata,
|
|
10
|
+
preparePoolBinData,
|
|
11
|
+
type CreatePoolFactoryParams,
|
|
12
|
+
type CreatePoolParams,
|
|
13
|
+
} from "./create.js";
|
|
14
|
+
|
|
15
|
+
// Pool read functions
|
|
16
|
+
export { getPoolImmutables, getPoolState, getBinState, getPositionBinShares } from "./read.js";
|
|
17
|
+
|
|
18
|
+
// Liquidity calculations and position operations
|
|
19
|
+
export {
|
|
20
|
+
buildModifyLiquidityArgsForAddition,
|
|
21
|
+
buildModifyLiquidityArgsForUniformAddition,
|
|
22
|
+
buildModifyLiquidityArgsForUniformAdditionWithTotalTokenAmount,
|
|
23
|
+
buildModifyLiquidityArgsForPercentageRemoval,
|
|
24
|
+
buildModifyLiquidityArgsForRemoval,
|
|
25
|
+
buildAddLiquidityExactSharesParamsFromBinTargets,
|
|
26
|
+
buildRemoveLiquidityPoolDelta,
|
|
27
|
+
additionPlanToPoolLiquidityDelta,
|
|
28
|
+
removalPlanToPoolLiquidityDelta,
|
|
29
|
+
scaleWeightedPoolDeltasToFitCaps,
|
|
30
|
+
encodeAddLiquidityExactSharesSelfCalldata,
|
|
31
|
+
encodeAddLiquidityExactSharesWithOwnerCalldata,
|
|
32
|
+
encodeAddLiquidityWeightedSelfCalldata,
|
|
33
|
+
encodeAddLiquidityWeightedWithOwnerCalldata,
|
|
34
|
+
encodeRemoveLiquidityCalldata,
|
|
35
|
+
getPositionShares,
|
|
36
|
+
getPositionSharesForBins,
|
|
37
|
+
NO_SLIPPAGE_LIMIT,
|
|
38
|
+
type ModifyLiquidityArgs,
|
|
39
|
+
type BuildModifyLiquidityArgsBase,
|
|
40
|
+
type BuildModifyLiquidityArgsForAdditionParams,
|
|
41
|
+
type BuildModifyLiquidityArgsForUniformAdditionParams,
|
|
42
|
+
type BuildModifyLiquidityArgsForUniformAdditionWithTotalTokenAmountParams,
|
|
43
|
+
type BuildModifyLiquidityArgsForPercentageRemovalParams,
|
|
44
|
+
type BuildModifyLiquidityArgsForRemovalParams,
|
|
45
|
+
type RemoveLiquidityParams,
|
|
46
|
+
type BinRemovalSpec,
|
|
47
|
+
} from "./liquidity.js";
|