@nradko/metric-omm-sdk-v1 0.3.0 → 0.4.2
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 +98 -111
- package/dist/abis/MetricOmmPool.d.ts +14 -0
- package/dist/abis/MetricOmmPool.d.ts.map +1 -1
- package/dist/abis/MetricOmmPool.js +18 -0
- package/dist/abis/MetricOmmPool.js.map +1 -1
- package/dist/abis/MetricOmmPoolDataProvider.d.ts +0 -136
- package/dist/abis/MetricOmmPoolDataProvider.d.ts.map +1 -1
- package/dist/abis/MetricOmmPoolDataProvider.js +0 -177
- package/dist/abis/MetricOmmPoolDataProvider.js.map +1 -1
- package/dist/abis/MetricOmmPoolStateView.d.ts +238 -0
- package/dist/abis/MetricOmmPoolStateView.d.ts.map +1 -0
- package/dist/abis/MetricOmmPoolStateView.js +315 -0
- package/dist/abis/MetricOmmPoolStateView.js.map +1 -0
- package/dist/abis/MetricOmmSimpleRouter.d.ts +619 -0
- package/dist/abis/{MetricOmmPoolSwapper.d.ts.map → MetricOmmSimpleRouter.d.ts.map} +1 -1
- package/dist/abis/MetricOmmSimpleRouter.js +805 -0
- package/dist/abis/MetricOmmSimpleRouter.js.map +1 -0
- package/dist/abis/MetricOmmSwapQuoter.d.ts +576 -0
- package/dist/abis/{PriceProviderUi.d.ts.map → MetricOmmSwapQuoter.d.ts.map} +1 -1
- package/dist/abis/MetricOmmSwapQuoter.js +748 -0
- package/dist/abis/MetricOmmSwapQuoter.js.map +1 -0
- package/dist/abis/OracleProvider.d.ts +106 -0
- package/dist/abis/OracleProvider.d.ts.map +1 -0
- package/dist/abis/OracleProvider.js +62 -0
- package/dist/abis/OracleProvider.js.map +1 -0
- package/dist/abis/PriceProvider.d.ts +8 -2
- package/dist/abis/PriceProvider.d.ts.map +1 -1
- package/dist/abis/PriceProvider.js +9 -1
- package/dist/abis/PriceProvider.js.map +1 -1
- package/dist/abis/index.d.ts +4 -2
- package/dist/abis/index.d.ts.map +1 -1
- package/dist/abis/index.js +4 -2
- package/dist/abis/index.js.map +1 -1
- package/dist/addresses.d.ts +3 -3
- package/dist/addresses.d.ts.map +1 -1
- package/dist/addresses.js +10 -10
- package/dist/addresses.js.map +1 -1
- package/dist/constants.d.ts +4 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +7 -2
- package/dist/constants.js.map +1 -1
- package/dist/index.d.ts +5 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -4
- package/dist/index.js.map +1 -1
- package/dist/oracle/index.d.ts +5 -0
- package/dist/oracle/index.d.ts.map +1 -0
- package/dist/oracle/index.js +5 -0
- package/dist/oracle/index.js.map +1 -0
- package/dist/oracle/registry.d.ts +53 -0
- package/dist/oracle/registry.d.ts.map +1 -0
- package/dist/oracle/registry.js +70 -0
- package/dist/oracle/registry.js.map +1 -0
- package/dist/quoter/index.d.ts +6 -0
- package/dist/quoter/index.d.ts.map +1 -0
- package/dist/quoter/index.js +6 -0
- package/dist/quoter/index.js.map +1 -0
- package/dist/quoter/quote.d.ts +58 -0
- package/dist/quoter/quote.d.ts.map +1 -0
- package/dist/quoter/quote.js +74 -0
- package/dist/quoter/quote.js.map +1 -0
- package/dist/quoter/quotePath.d.ts +65 -0
- package/dist/quoter/quotePath.d.ts.map +1 -0
- package/dist/quoter/quotePath.js +108 -0
- package/dist/quoter/quotePath.js.map +1 -0
- package/dist/router/index.d.ts +2 -1
- package/dist/router/index.d.ts.map +1 -1
- package/dist/router/index.js +2 -1
- package/dist/router/index.js.map +1 -1
- package/dist/router/swap.d.ts +37 -92
- package/dist/router/swap.d.ts.map +1 -1
- package/dist/router/swap.js +96 -298
- package/dist/router/swap.js.map +1 -1
- package/dist/router/swapPath.d.ts +56 -0
- package/dist/router/swapPath.d.ts.map +1 -0
- package/dist/router/swapPath.js +98 -0
- package/dist/router/swapPath.js.map +1 -0
- package/dist/swap/path.d.ts +13 -0
- package/dist/swap/path.d.ts.map +1 -0
- package/dist/swap/path.js +74 -0
- package/dist/swap/path.js.map +1 -0
- package/package.json +4 -5
- package/src/abis/MetricOmmPool.ts +18 -0
- package/src/abis/MetricOmmPoolDataProvider.ts +0 -177
- package/src/abis/MetricOmmPoolStateView.ts +314 -0
- package/src/abis/MetricOmmSimpleRouter.ts +804 -0
- package/src/abis/MetricOmmSwapQuoter.ts +747 -0
- package/src/abis/OracleProvider.ts +61 -0
- package/src/abis/PriceProvider.ts +9 -1
- package/src/abis/index.ts +4 -2
- package/src/addresses.ts +13 -13
- package/src/constants.ts +7 -2
- package/src/index.ts +62 -23
- package/src/oracle/index.ts +14 -0
- package/src/oracle/registry.ts +146 -0
- package/src/quoter/index.ts +28 -0
- package/src/quoter/quote.ts +193 -0
- package/src/quoter/quotePath.ts +240 -0
- package/src/router/index.ts +24 -25
- package/src/router/swap.ts +142 -480
- package/src/router/swapPath.ts +181 -0
- package/src/swap/path.ts +107 -0
- package/dist/abis/MetricOmmPoolSwapper.d.ts +0 -917
- package/dist/abis/MetricOmmPoolSwapper.js +0 -1185
- package/dist/abis/MetricOmmPoolSwapper.js.map +0 -1
- package/dist/abis/PriceProviderUi.d.ts +0 -433
- package/dist/abis/PriceProviderUi.js +0 -318
- package/dist/abis/PriceProviderUi.js.map +0 -1
- package/src/abis/MetricOmmPoolSwapper.ts +0 -1184
- package/src/abis/PriceProviderUi.ts +0 -317
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MetricAMM SDK - MetricOmmSwapQuoter multihop quotes and shared helpers.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { Address, PublicClient, Hex } from "viem";
|
|
6
|
+
import { getAddressesOrThrow } from "../addresses.js";
|
|
7
|
+
import { MAX_UINT128, QUOTER_ABI } from "../constants.js";
|
|
8
|
+
import { EMPTY_EXTENSION_DATA } from "../extensions/types.js";
|
|
9
|
+
import { resolveSwapPath } from "../swap/path.js";
|
|
10
|
+
|
|
11
|
+
export type QuoteSwapResult = {
|
|
12
|
+
amountIn: bigint;
|
|
13
|
+
amountOut: bigint;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export interface QuoteLiveExactInParams {
|
|
17
|
+
publicClient: PublicClient;
|
|
18
|
+
tokenIn: Address;
|
|
19
|
+
tokenOut: Address;
|
|
20
|
+
pools: readonly Address[];
|
|
21
|
+
extensionDatas?: readonly Hex[];
|
|
22
|
+
recipient: Address;
|
|
23
|
+
amountIn: bigint;
|
|
24
|
+
quoterAddress?: Address;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface QuoteLiveExactOutParams {
|
|
28
|
+
publicClient: PublicClient;
|
|
29
|
+
tokenIn: Address;
|
|
30
|
+
tokenOut: Address;
|
|
31
|
+
pools: readonly Address[];
|
|
32
|
+
extensionDatas?: readonly Hex[];
|
|
33
|
+
recipient: Address;
|
|
34
|
+
amountOut: bigint;
|
|
35
|
+
quoterAddress?: Address;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface QuoteHypotheticalExactInputParams {
|
|
39
|
+
publicClient: PublicClient;
|
|
40
|
+
tokenIn: Address;
|
|
41
|
+
tokenOut: Address;
|
|
42
|
+
pools: readonly Address[];
|
|
43
|
+
extensionDatas?: readonly Hex[];
|
|
44
|
+
bidPricesX64: readonly bigint[];
|
|
45
|
+
askPricesX64: readonly bigint[];
|
|
46
|
+
recipient: Address;
|
|
47
|
+
amountIn: bigint;
|
|
48
|
+
quoterAddress?: Address;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface QuoteHypotheticalExactOutputParams {
|
|
52
|
+
publicClient: PublicClient;
|
|
53
|
+
tokenIn: Address;
|
|
54
|
+
tokenOut: Address;
|
|
55
|
+
pools: readonly Address[];
|
|
56
|
+
extensionDatas?: readonly Hex[];
|
|
57
|
+
bidPricesX64: readonly bigint[];
|
|
58
|
+
askPricesX64: readonly bigint[];
|
|
59
|
+
recipient: Address;
|
|
60
|
+
amountOut: bigint;
|
|
61
|
+
quoterAddress?: Address;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export async function resolveQuoterAddress(params: {
|
|
65
|
+
publicClient?: PublicClient;
|
|
66
|
+
quoterAddress?: Address;
|
|
67
|
+
}): Promise<Address> {
|
|
68
|
+
if (params.quoterAddress) return params.quoterAddress;
|
|
69
|
+
if (!params.publicClient) {
|
|
70
|
+
throw new Error("Either publicClient or quoterAddress must be provided");
|
|
71
|
+
}
|
|
72
|
+
const chainId = params.publicClient.chain?.id ?? (await params.publicClient.getChainId());
|
|
73
|
+
const addresses = getAddressesOrThrow(chainId);
|
|
74
|
+
if (addresses.quoter === "0x0000000000000000000000000000000000000000" || !addresses.quoter) {
|
|
75
|
+
throw new Error(
|
|
76
|
+
`Chain ${chainId} has no default quoter address. Pass a quoterAddress to override.`,
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
return addresses.quoter;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function defaultPriceLimitX64(zeroForOne: boolean): bigint {
|
|
83
|
+
return zeroForOne ? 0n : MAX_UINT128;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function withQuoteExtensionData(extensionData?: Hex): Hex {
|
|
87
|
+
return extensionData ?? EMPTY_EXTENSION_DATA;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function validateHypotheticalPrices(
|
|
91
|
+
pools: readonly Address[],
|
|
92
|
+
bidPricesX64: readonly bigint[],
|
|
93
|
+
askPricesX64: readonly bigint[],
|
|
94
|
+
): void {
|
|
95
|
+
if (bidPricesX64.length !== pools.length || askPricesX64.length !== pools.length) {
|
|
96
|
+
throw new Error("bidPricesX64 and askPricesX64 length must match pools length");
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export async function simulateQuote(
|
|
101
|
+
publicClient: PublicClient,
|
|
102
|
+
quoterAddress: Address,
|
|
103
|
+
recipient: Address,
|
|
104
|
+
functionName:
|
|
105
|
+
| "quoteLiveExactInSingle"
|
|
106
|
+
| "quoteLiveExactOutSingle"
|
|
107
|
+
| "quoteLiveExactIn"
|
|
108
|
+
| "quoteLiveExactOut"
|
|
109
|
+
| "quoteHypotheticalExactInputSingle"
|
|
110
|
+
| "quoteHypotheticalExactOutputSingle"
|
|
111
|
+
| "quoteHypotheticalExactInput"
|
|
112
|
+
| "quoteHypotheticalExactOutput",
|
|
113
|
+
args: readonly unknown[],
|
|
114
|
+
): Promise<QuoteSwapResult> {
|
|
115
|
+
const {
|
|
116
|
+
result: [amountIn, amountOut],
|
|
117
|
+
} = (await publicClient.simulateContract({
|
|
118
|
+
address: quoterAddress,
|
|
119
|
+
abi: QUOTER_ABI,
|
|
120
|
+
functionName,
|
|
121
|
+
args,
|
|
122
|
+
account: recipient,
|
|
123
|
+
})) as unknown as { result: [bigint, bigint] };
|
|
124
|
+
|
|
125
|
+
return { amountIn, amountOut };
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export async function quoteLiveExactIn(params: QuoteLiveExactInParams): Promise<QuoteSwapResult> {
|
|
129
|
+
const quoterAddress = await resolveQuoterAddress({
|
|
130
|
+
publicClient: params.publicClient,
|
|
131
|
+
quoterAddress: params.quoterAddress,
|
|
132
|
+
});
|
|
133
|
+
const { extensionDatas, zeroForOneBitMap } = await resolveSwapPath(
|
|
134
|
+
params.publicClient,
|
|
135
|
+
params.tokenIn,
|
|
136
|
+
params.tokenOut,
|
|
137
|
+
params.pools,
|
|
138
|
+
params.extensionDatas,
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
return simulateQuote(params.publicClient, quoterAddress, params.recipient, "quoteLiveExactIn", [
|
|
142
|
+
{
|
|
143
|
+
pools: [...params.pools],
|
|
144
|
+
extensionDatas,
|
|
145
|
+
zeroForOneBitMap,
|
|
146
|
+
amountIn: params.amountIn,
|
|
147
|
+
},
|
|
148
|
+
]);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export async function quoteLiveExactOut(params: QuoteLiveExactOutParams): Promise<QuoteSwapResult> {
|
|
152
|
+
const quoterAddress = await resolveQuoterAddress({
|
|
153
|
+
publicClient: params.publicClient,
|
|
154
|
+
quoterAddress: params.quoterAddress,
|
|
155
|
+
});
|
|
156
|
+
const { extensionDatas, zeroForOneBitMap } = await resolveSwapPath(
|
|
157
|
+
params.publicClient,
|
|
158
|
+
params.tokenIn,
|
|
159
|
+
params.tokenOut,
|
|
160
|
+
params.pools,
|
|
161
|
+
params.extensionDatas,
|
|
162
|
+
);
|
|
163
|
+
|
|
164
|
+
return simulateQuote(params.publicClient, quoterAddress, params.recipient, "quoteLiveExactOut", [
|
|
165
|
+
{
|
|
166
|
+
pools: [...params.pools],
|
|
167
|
+
extensionDatas,
|
|
168
|
+
zeroForOneBitMap,
|
|
169
|
+
amountOut: params.amountOut,
|
|
170
|
+
},
|
|
171
|
+
]);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export async function quoteHypotheticalExactInput(
|
|
175
|
+
params: QuoteHypotheticalExactInputParams,
|
|
176
|
+
): Promise<QuoteSwapResult> {
|
|
177
|
+
validateHypotheticalPrices(params.pools, params.bidPricesX64, params.askPricesX64);
|
|
178
|
+
const quoterAddress = await resolveQuoterAddress({
|
|
179
|
+
publicClient: params.publicClient,
|
|
180
|
+
quoterAddress: params.quoterAddress,
|
|
181
|
+
});
|
|
182
|
+
const { extensionDatas, zeroForOneBitMap } = await resolveSwapPath(
|
|
183
|
+
params.publicClient,
|
|
184
|
+
params.tokenIn,
|
|
185
|
+
params.tokenOut,
|
|
186
|
+
params.pools,
|
|
187
|
+
params.extensionDatas,
|
|
188
|
+
);
|
|
189
|
+
|
|
190
|
+
return simulateQuote(
|
|
191
|
+
params.publicClient,
|
|
192
|
+
quoterAddress,
|
|
193
|
+
params.recipient,
|
|
194
|
+
"quoteHypotheticalExactInput",
|
|
195
|
+
[
|
|
196
|
+
{
|
|
197
|
+
pools: [...params.pools],
|
|
198
|
+
extensionDatas,
|
|
199
|
+
zeroForOneBitMap,
|
|
200
|
+
amountIn: params.amountIn,
|
|
201
|
+
bidPricesX64: [...params.bidPricesX64],
|
|
202
|
+
askPricesX64: [...params.askPricesX64],
|
|
203
|
+
},
|
|
204
|
+
],
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export async function quoteHypotheticalExactOutput(
|
|
209
|
+
params: QuoteHypotheticalExactOutputParams,
|
|
210
|
+
): Promise<QuoteSwapResult> {
|
|
211
|
+
validateHypotheticalPrices(params.pools, params.bidPricesX64, params.askPricesX64);
|
|
212
|
+
const quoterAddress = await resolveQuoterAddress({
|
|
213
|
+
publicClient: params.publicClient,
|
|
214
|
+
quoterAddress: params.quoterAddress,
|
|
215
|
+
});
|
|
216
|
+
const { extensionDatas, zeroForOneBitMap } = await resolveSwapPath(
|
|
217
|
+
params.publicClient,
|
|
218
|
+
params.tokenIn,
|
|
219
|
+
params.tokenOut,
|
|
220
|
+
params.pools,
|
|
221
|
+
params.extensionDatas,
|
|
222
|
+
);
|
|
223
|
+
|
|
224
|
+
return simulateQuote(
|
|
225
|
+
params.publicClient,
|
|
226
|
+
quoterAddress,
|
|
227
|
+
params.recipient,
|
|
228
|
+
"quoteHypotheticalExactOutput",
|
|
229
|
+
[
|
|
230
|
+
{
|
|
231
|
+
pools: [...params.pools],
|
|
232
|
+
extensionDatas,
|
|
233
|
+
zeroForOneBitMap,
|
|
234
|
+
amountOut: params.amountOut,
|
|
235
|
+
bidPricesX64: [...params.bidPricesX64],
|
|
236
|
+
askPricesX64: [...params.askPricesX64],
|
|
237
|
+
},
|
|
238
|
+
],
|
|
239
|
+
);
|
|
240
|
+
}
|
package/src/router/index.ts
CHANGED
|
@@ -3,29 +3,28 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
export {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
type
|
|
27
|
-
type
|
|
28
|
-
type
|
|
29
|
-
type
|
|
30
|
-
type QuoteSwapResult,
|
|
6
|
+
buildExactInputParams,
|
|
7
|
+
buildExactOutputParams,
|
|
8
|
+
encodeExactInputCalldata,
|
|
9
|
+
encodeExactOutputCalldata,
|
|
10
|
+
encodeZeroForOneBitMap,
|
|
11
|
+
prepareExactInputCalldata,
|
|
12
|
+
prepareExactOutputCalldata,
|
|
13
|
+
type ExactInputParams,
|
|
14
|
+
type ExactOutputParams,
|
|
15
|
+
type BuildExactInputParams,
|
|
16
|
+
type BuildExactOutputParams,
|
|
17
|
+
} from "./swapPath.js";
|
|
18
|
+
|
|
19
|
+
export {
|
|
20
|
+
buildExactInputSingleParams,
|
|
21
|
+
buildExactOutputSingleParams,
|
|
22
|
+
encodeExactInputSingleCalldata,
|
|
23
|
+
encodeExactOutputSingleCalldata,
|
|
24
|
+
prepareExactInputSingleCalldata,
|
|
25
|
+
prepareExactOutputSingleCalldata,
|
|
26
|
+
type ExactInputSingleParams,
|
|
27
|
+
type ExactOutputSingleParams,
|
|
28
|
+
type BuildExactInputSingleParams,
|
|
29
|
+
type BuildExactOutputSingleParams,
|
|
31
30
|
} from "./swap.js";
|