@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
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
export const PriceProviderUiAbi = [
|
|
2
|
+
{
|
|
3
|
+
type: "constructor",
|
|
4
|
+
inputs: [
|
|
5
|
+
{ name: "_factory", type: "address", internalType: "address" },
|
|
6
|
+
{ name: "_oracle", type: "address", internalType: "address" },
|
|
7
|
+
{ name: "_offchainFeedId", type: "bytes32", internalType: "bytes32" },
|
|
8
|
+
{ name: "_cexStep", type: "int256", internalType: "int256" },
|
|
9
|
+
{ name: "_maxTimeDelta", type: "uint256", internalType: "uint256" },
|
|
10
|
+
{ name: "_maxClDeviation", type: "uint16", internalType: "uint16" },
|
|
11
|
+
{ name: "_baseTokenOverride", type: "address", internalType: "address" },
|
|
12
|
+
{ name: "_quoteTokenOverride", type: "address", internalType: "address" },
|
|
13
|
+
],
|
|
14
|
+
stateMutability: "nonpayable",
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
type: "function",
|
|
18
|
+
name: "BPS_BASE",
|
|
19
|
+
inputs: [],
|
|
20
|
+
outputs: [{ name: "", type: "int256", internalType: "int256" }],
|
|
21
|
+
stateMutability: "view",
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
type: "function",
|
|
25
|
+
name: "BPS_BASE_U",
|
|
26
|
+
inputs: [],
|
|
27
|
+
outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
|
|
28
|
+
stateMutability: "view",
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
type: "function",
|
|
32
|
+
name: "MAGIC_COOLDOWN",
|
|
33
|
+
inputs: [],
|
|
34
|
+
outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
|
|
35
|
+
stateMutability: "view",
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
type: "function",
|
|
39
|
+
name: "MAGIC_MAX",
|
|
40
|
+
inputs: [],
|
|
41
|
+
outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
|
|
42
|
+
stateMutability: "view",
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
type: "function",
|
|
46
|
+
name: "MAX_TIME_DELTA",
|
|
47
|
+
inputs: [],
|
|
48
|
+
outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
|
|
49
|
+
stateMutability: "view",
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
type: "function",
|
|
53
|
+
name: "baseToken",
|
|
54
|
+
inputs: [],
|
|
55
|
+
outputs: [{ name: "", type: "address", internalType: "address" }],
|
|
56
|
+
stateMutability: "view",
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
type: "function",
|
|
60
|
+
name: "cexStep",
|
|
61
|
+
inputs: [],
|
|
62
|
+
outputs: [{ name: "", type: "int256", internalType: "int256" }],
|
|
63
|
+
stateMutability: "view",
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
type: "function",
|
|
67
|
+
name: "factory",
|
|
68
|
+
inputs: [],
|
|
69
|
+
outputs: [{ name: "", type: "address", internalType: "address" }],
|
|
70
|
+
stateMutability: "view",
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
type: "function",
|
|
74
|
+
name: "getAskPrice",
|
|
75
|
+
inputs: [],
|
|
76
|
+
outputs: [{ name: "askPrice", type: "uint256", internalType: "uint256" }],
|
|
77
|
+
stateMutability: "view",
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
type: "function",
|
|
81
|
+
name: "getAskPriceUi",
|
|
82
|
+
inputs: [],
|
|
83
|
+
outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
|
|
84
|
+
stateMutability: "view",
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
type: "function",
|
|
88
|
+
name: "getBidAndAskPrice",
|
|
89
|
+
inputs: [],
|
|
90
|
+
outputs: [
|
|
91
|
+
{ name: "bid", type: "uint128", internalType: "uint128" },
|
|
92
|
+
{ name: "ask", type: "uint128", internalType: "uint128" },
|
|
93
|
+
],
|
|
94
|
+
stateMutability: "view",
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
type: "function",
|
|
98
|
+
name: "getBidAndAskPriceUi",
|
|
99
|
+
inputs: [],
|
|
100
|
+
outputs: [
|
|
101
|
+
{ name: "bid", type: "uint128", internalType: "uint128" },
|
|
102
|
+
{ name: "ask", type: "uint128", internalType: "uint128" },
|
|
103
|
+
],
|
|
104
|
+
stateMutability: "view",
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
type: "function",
|
|
108
|
+
name: "getBidPrice",
|
|
109
|
+
inputs: [],
|
|
110
|
+
outputs: [{ name: "bidPrice", type: "uint256", internalType: "uint256" }],
|
|
111
|
+
stateMutability: "view",
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
type: "function",
|
|
115
|
+
name: "getBidPriceUi",
|
|
116
|
+
inputs: [],
|
|
117
|
+
outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
|
|
118
|
+
stateMutability: "view",
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
type: "function",
|
|
122
|
+
name: "getTokens",
|
|
123
|
+
inputs: [],
|
|
124
|
+
outputs: [
|
|
125
|
+
{ name: "", type: "address", internalType: "address" },
|
|
126
|
+
{ name: "", type: "address", internalType: "address" },
|
|
127
|
+
],
|
|
128
|
+
stateMutability: "view",
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
type: "function",
|
|
132
|
+
name: "lastMagicUpdate",
|
|
133
|
+
inputs: [],
|
|
134
|
+
outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
|
|
135
|
+
stateMutability: "view",
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
type: "function",
|
|
139
|
+
name: "magicNumber",
|
|
140
|
+
inputs: [],
|
|
141
|
+
outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
|
|
142
|
+
stateMutability: "view",
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
type: "function",
|
|
146
|
+
name: "maxClDeviation",
|
|
147
|
+
inputs: [],
|
|
148
|
+
outputs: [{ name: "", type: "uint16", internalType: "uint16" }],
|
|
149
|
+
stateMutability: "view",
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
type: "function",
|
|
153
|
+
name: "offchainFeedId",
|
|
154
|
+
inputs: [],
|
|
155
|
+
outputs: [{ name: "", type: "bytes32", internalType: "bytes32" }],
|
|
156
|
+
stateMutability: "view",
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
type: "function",
|
|
160
|
+
name: "offchainOracle",
|
|
161
|
+
inputs: [],
|
|
162
|
+
outputs: [{ name: "", type: "address", internalType: "contract IOffchainOracle" }],
|
|
163
|
+
stateMutability: "view",
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
type: "function",
|
|
167
|
+
name: "quoteToken",
|
|
168
|
+
inputs: [],
|
|
169
|
+
outputs: [{ name: "", type: "address", internalType: "address" }],
|
|
170
|
+
stateMutability: "view",
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
type: "function",
|
|
174
|
+
name: "removeClOracle",
|
|
175
|
+
inputs: [{ name: "token", type: "address", internalType: "address" }],
|
|
176
|
+
outputs: [],
|
|
177
|
+
stateMutability: "nonpayable",
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
type: "function",
|
|
181
|
+
name: "setCexStep",
|
|
182
|
+
inputs: [{ name: "_cexStep", type: "int256", internalType: "int256" }],
|
|
183
|
+
outputs: [],
|
|
184
|
+
stateMutability: "nonpayable",
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
type: "function",
|
|
188
|
+
name: "setClOracle",
|
|
189
|
+
inputs: [
|
|
190
|
+
{ name: "token", type: "address", internalType: "address" },
|
|
191
|
+
{ name: "oracle", type: "address", internalType: "address" },
|
|
192
|
+
{ name: "heartbeat", type: "uint32", internalType: "uint32" },
|
|
193
|
+
],
|
|
194
|
+
outputs: [],
|
|
195
|
+
stateMutability: "nonpayable",
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
type: "function",
|
|
199
|
+
name: "setMagicNumber",
|
|
200
|
+
inputs: [{ name: "newMagic", type: "uint256", internalType: "uint256" }],
|
|
201
|
+
outputs: [],
|
|
202
|
+
stateMutability: "nonpayable",
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
type: "function",
|
|
206
|
+
name: "setMaxClDeviation",
|
|
207
|
+
inputs: [{ name: "newMaxDeviation", type: "uint16", internalType: "uint16" }],
|
|
208
|
+
outputs: [],
|
|
209
|
+
stateMutability: "nonpayable",
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
type: "event",
|
|
213
|
+
name: "CexStepUpdated",
|
|
214
|
+
inputs: [
|
|
215
|
+
{
|
|
216
|
+
name: "newCexStep",
|
|
217
|
+
type: "int256",
|
|
218
|
+
indexed: true,
|
|
219
|
+
internalType: "int256",
|
|
220
|
+
},
|
|
221
|
+
],
|
|
222
|
+
anonymous: false,
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
type: "event",
|
|
226
|
+
name: "ClOracleRemoved",
|
|
227
|
+
inputs: [
|
|
228
|
+
{
|
|
229
|
+
name: "token",
|
|
230
|
+
type: "address",
|
|
231
|
+
indexed: true,
|
|
232
|
+
internalType: "address",
|
|
233
|
+
},
|
|
234
|
+
],
|
|
235
|
+
anonymous: false,
|
|
236
|
+
},
|
|
237
|
+
{
|
|
238
|
+
type: "event",
|
|
239
|
+
name: "ClOracleSet",
|
|
240
|
+
inputs: [
|
|
241
|
+
{
|
|
242
|
+
name: "token",
|
|
243
|
+
type: "address",
|
|
244
|
+
indexed: true,
|
|
245
|
+
internalType: "address",
|
|
246
|
+
},
|
|
247
|
+
{
|
|
248
|
+
name: "oracle",
|
|
249
|
+
type: "address",
|
|
250
|
+
indexed: true,
|
|
251
|
+
internalType: "address",
|
|
252
|
+
},
|
|
253
|
+
{
|
|
254
|
+
name: "heartbeat",
|
|
255
|
+
type: "uint32",
|
|
256
|
+
indexed: false,
|
|
257
|
+
internalType: "uint32",
|
|
258
|
+
},
|
|
259
|
+
],
|
|
260
|
+
anonymous: false,
|
|
261
|
+
},
|
|
262
|
+
{
|
|
263
|
+
type: "event",
|
|
264
|
+
name: "ClOracleStateSet",
|
|
265
|
+
inputs: [
|
|
266
|
+
{
|
|
267
|
+
name: "token",
|
|
268
|
+
type: "address",
|
|
269
|
+
indexed: true,
|
|
270
|
+
internalType: "address",
|
|
271
|
+
},
|
|
272
|
+
{
|
|
273
|
+
name: "oracle",
|
|
274
|
+
type: "address",
|
|
275
|
+
indexed: true,
|
|
276
|
+
internalType: "address",
|
|
277
|
+
},
|
|
278
|
+
],
|
|
279
|
+
anonymous: false,
|
|
280
|
+
},
|
|
281
|
+
{
|
|
282
|
+
type: "event",
|
|
283
|
+
name: "MagicNumberSet",
|
|
284
|
+
inputs: [
|
|
285
|
+
{
|
|
286
|
+
name: "newMagic",
|
|
287
|
+
type: "uint256",
|
|
288
|
+
indexed: true,
|
|
289
|
+
internalType: "uint256",
|
|
290
|
+
},
|
|
291
|
+
],
|
|
292
|
+
anonymous: false,
|
|
293
|
+
},
|
|
294
|
+
{
|
|
295
|
+
type: "event",
|
|
296
|
+
name: "MaxClDeviationUpdated",
|
|
297
|
+
inputs: [
|
|
298
|
+
{
|
|
299
|
+
name: "newMaxClDeviation",
|
|
300
|
+
type: "uint16",
|
|
301
|
+
indexed: true,
|
|
302
|
+
internalType: "uint16",
|
|
303
|
+
},
|
|
304
|
+
],
|
|
305
|
+
anonymous: false,
|
|
306
|
+
},
|
|
307
|
+
{ type: "error", name: "BadCreationRequest", inputs: [] },
|
|
308
|
+
{ type: "error", name: "CexStepOutOfBounds", inputs: [] },
|
|
309
|
+
{ type: "error", name: "ClOracleNotFound", inputs: [] },
|
|
310
|
+
{ type: "error", name: "CooldownNotElapsed", inputs: [] },
|
|
311
|
+
{ type: "error", name: "FeedStalled", inputs: [] },
|
|
312
|
+
{ type: "error", name: "MagicNumberOutOfBounds", inputs: [] },
|
|
313
|
+
{ type: "error", name: "MaxClDeviationOutOfBounds", inputs: [] },
|
|
314
|
+
{ type: "error", name: "MaxTimeDeltaOutOfBounds", inputs: [] },
|
|
315
|
+
{ type: "error", name: "OnlyFactory", inputs: [] },
|
|
316
|
+
{ type: "error", name: "Pow10ExponentTooLarge", inputs: [] },
|
|
317
|
+
] as const;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MetricAMM Contract ABIs (v1)
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export { MetricOmmPoolAbi } from "./MetricOmmPool.js";
|
|
6
|
+
export { MetricOmmPoolStateViewAbi } from "./MetricOmmPoolStateView.js";
|
|
7
|
+
export { MetricOmmPoolSwapperAbi } from "./MetricOmmPoolSwapper.js";
|
|
8
|
+
export { MetricOmmPoolLiquidityAdderAbi } from "./MetricOmmPoolLiquidityAdder.js";
|
|
9
|
+
export { MetricOmmPoolFactoryAbi } from "./MetricOmmPoolFactory.js";
|
|
10
|
+
export { PriceProviderAbi } from "./PriceProvider.js";
|
|
11
|
+
export { PriceProviderUiAbi } from "./PriceProviderUi.js";
|
package/src/addresses.ts
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MetricAMM SDK — v1 deployed addresses.
|
|
3
|
+
*
|
|
4
|
+
* Only Ethereum mainnet is configured (no other chain deployments for this release).
|
|
5
|
+
* State view (`test/MetricOmmPoolStateView.sol` in core) is not part of the periphery bundle;
|
|
6
|
+
* set `stateView` on the returned object when you deploy it, or pass its address into read helpers directly.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import type { Address } from "viem";
|
|
10
|
+
|
|
11
|
+
// ============ Chain IDs ============
|
|
12
|
+
|
|
13
|
+
export const ChainId = {
|
|
14
|
+
ETHEREUM: 1,
|
|
15
|
+
BASE: 8453,
|
|
16
|
+
ARBITRUM: 42161,
|
|
17
|
+
AVALANCHE: 43114,
|
|
18
|
+
BNB: 56,
|
|
19
|
+
POLYGON: 137,
|
|
20
|
+
MEGAETH: 4326,
|
|
21
|
+
HYPEREVM: 999,
|
|
22
|
+
MONAD: 143,
|
|
23
|
+
} as const;
|
|
24
|
+
|
|
25
|
+
export type ChainId = (typeof ChainId)[keyof typeof ChainId];
|
|
26
|
+
|
|
27
|
+
/** Chains that have entries in `ADDRESSES` for this SDK release. */
|
|
28
|
+
export type DeployedChainId = typeof ChainId.ETHEREUM;
|
|
29
|
+
|
|
30
|
+
// ============ Contract Address Types ============
|
|
31
|
+
|
|
32
|
+
export interface ChainAddresses {
|
|
33
|
+
/** MetricOmmPoolFactory */
|
|
34
|
+
factory: Address;
|
|
35
|
+
/** MetricOmmPoolDeployer */
|
|
36
|
+
poolDeployer: Address;
|
|
37
|
+
/** MetricOmmPoolLiquidityAdder */
|
|
38
|
+
liquidityAdder: Address;
|
|
39
|
+
/** MetricOmmPoolSwapDataProvider */
|
|
40
|
+
swapDataProvider: Address;
|
|
41
|
+
/** DepositAllowlist */
|
|
42
|
+
depositAllowlist: Address;
|
|
43
|
+
/** SwapAllowlist */
|
|
44
|
+
swapAllowlist: Address;
|
|
45
|
+
/** MetricOmmPoolSwapper */
|
|
46
|
+
swapper: Address;
|
|
47
|
+
/** Wrapped native (WETH on Ethereum) */
|
|
48
|
+
wrappedNative: Address;
|
|
49
|
+
/**
|
|
50
|
+
* Optional `MetricOmmPoolStateView` used by batch read helpers.
|
|
51
|
+
* Not included in the v1 Ethereum deploy manifest; wire when you deploy the state view.
|
|
52
|
+
*/
|
|
53
|
+
stateView?: Address;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// ============ Deployed addresses ============
|
|
57
|
+
|
|
58
|
+
export const ADDRESSES: Record<DeployedChainId, ChainAddresses> = {
|
|
59
|
+
[ChainId.ETHEREUM]: {
|
|
60
|
+
factory: "0x93e314a9a65a15f3c3bc039bb4261dbbbc343fba",
|
|
61
|
+
poolDeployer: "0xe56e89c4faeec39364b5a2cbde13c572a876afb6",
|
|
62
|
+
liquidityAdder: "0x1f2a03dc43947c6bdebb2e6136222997e49fa3e9",
|
|
63
|
+
swapDataProvider: "0x404bdb6d2b9ed34a5637211a8d52177c38c39d02",
|
|
64
|
+
depositAllowlist: "0xea700fcd860533474e1ff920b76914113ae56681",
|
|
65
|
+
swapAllowlist: "0x5269d78af4a288e1649be6bf169a51bb94b6eb78",
|
|
66
|
+
swapper: "0x85e4ff47427f1a62ed19a3abf97b80c333da266c",
|
|
67
|
+
wrappedNative: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
|
68
|
+
},
|
|
69
|
+
} as const;
|
|
70
|
+
|
|
71
|
+
// ============ Helper Functions ============
|
|
72
|
+
|
|
73
|
+
export function getAddresses(chainId: number): ChainAddresses | undefined {
|
|
74
|
+
if (chainId !== ChainId.ETHEREUM) return undefined;
|
|
75
|
+
return ADDRESSES[ChainId.ETHEREUM];
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function getAddressesOrThrow(chainId: number): ChainAddresses {
|
|
79
|
+
const addresses = getAddresses(chainId);
|
|
80
|
+
if (!addresses) {
|
|
81
|
+
throw new Error(
|
|
82
|
+
`Chain ${chainId} has no v1 deployment in this SDK (only Ethereum mainnet is configured)`,
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
return addresses;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function isChainSupported(chainId: number): chainId is DeployedChainId {
|
|
89
|
+
return chainId === ChainId.ETHEREUM;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function getSupportedChainIds(): DeployedChainId[] {
|
|
93
|
+
return [ChainId.ETHEREUM];
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function isChainDeployed(chainId: number): boolean {
|
|
97
|
+
const addresses = getAddresses(chainId);
|
|
98
|
+
if (!addresses) return false;
|
|
99
|
+
return addresses.factory !== "0x0000000000000000000000000000000000000000";
|
|
100
|
+
}
|
package/src/constants.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MetricAMM SDK Constants (v1)
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { Abi } from "viem";
|
|
6
|
+
import { MetricOmmPoolAbi } from "./abis/MetricOmmPool.js";
|
|
7
|
+
import { MetricOmmPoolStateViewAbi } from "./abis/MetricOmmPoolStateView.js";
|
|
8
|
+
import { MetricOmmPoolSwapperAbi } from "./abis/MetricOmmPoolSwapper.js";
|
|
9
|
+
import { MetricOmmPoolLiquidityAdderAbi } from "./abis/MetricOmmPoolLiquidityAdder.js";
|
|
10
|
+
import { MetricOmmPoolFactoryAbi } from "./abis/MetricOmmPoolFactory.js";
|
|
11
|
+
|
|
12
|
+
// ============ Numeric Constants ============
|
|
13
|
+
|
|
14
|
+
/** Q64 format multiplier (2^64) */
|
|
15
|
+
export const Q64 = 2n ** 64n;
|
|
16
|
+
|
|
17
|
+
/** Max uint128 value for no price limit */
|
|
18
|
+
export const MAX_UINT128 = 2n ** 128n - 1n;
|
|
19
|
+
|
|
20
|
+
/** Max int128 value for no slippage limit */
|
|
21
|
+
export const MAX_INT128 = 2n ** 127n - 1n;
|
|
22
|
+
|
|
23
|
+
/** Max position in bin */
|
|
24
|
+
export const MAX_UINT104 = 2n ** 104n - 1n;
|
|
25
|
+
|
|
26
|
+
/** Max int104 value */
|
|
27
|
+
export const MAX_INT104 = 2n ** 103n - 1n;
|
|
28
|
+
|
|
29
|
+
// ============ Internal ABI References ============
|
|
30
|
+
|
|
31
|
+
export const POOL_ABI = MetricOmmPoolAbi as Abi;
|
|
32
|
+
export const STATE_VIEW_ABI = MetricOmmPoolStateViewAbi as Abi;
|
|
33
|
+
export const SWAPPER_ABI = MetricOmmPoolSwapperAbi as Abi;
|
|
34
|
+
export const LIQUIDITY_ADDER_ABI = MetricOmmPoolLiquidityAdderAbi as Abi;
|
|
35
|
+
export const POOL_FACTORY_ABI = MetricOmmPoolFactoryAbi as Abi;
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MetricAMM SDK - Factory Fee Collection
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
erc20Abi,
|
|
7
|
+
zeroAddress,
|
|
8
|
+
type Address,
|
|
9
|
+
type Hex,
|
|
10
|
+
type PublicClient,
|
|
11
|
+
type TransactionReceipt,
|
|
12
|
+
type WalletClient,
|
|
13
|
+
} from "viem";
|
|
14
|
+
import { POOL_FACTORY_ABI } from "../constants.js";
|
|
15
|
+
|
|
16
|
+
export interface FactoryAssetBalance {
|
|
17
|
+
asset: Address;
|
|
18
|
+
amount: bigint;
|
|
19
|
+
isNative: boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface CollectFactoryFeesParams {
|
|
23
|
+
publicClient: PublicClient;
|
|
24
|
+
walletClient: WalletClient;
|
|
25
|
+
factoryAddress: Address;
|
|
26
|
+
target: Address;
|
|
27
|
+
assets: Address[];
|
|
28
|
+
account: Address;
|
|
29
|
+
awaitReceipts?: boolean;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface CollectedFactoryFeeTx {
|
|
33
|
+
asset: Address;
|
|
34
|
+
amount: bigint;
|
|
35
|
+
isNative: boolean;
|
|
36
|
+
hash: Hex;
|
|
37
|
+
receipt?: TransactionReceipt;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface CollectFactoryFeesResult {
|
|
41
|
+
balances: FactoryAssetBalance[];
|
|
42
|
+
collected: CollectedFactoryFeeTx[];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Read balances for the provided asset list on the factory.
|
|
47
|
+
* For ERC20 assets this uses multicall(balanceOf(factory)).
|
|
48
|
+
* For native ETH (zero address), this uses getBalance(factory).
|
|
49
|
+
*/
|
|
50
|
+
export async function getFactoryAssetBalances(
|
|
51
|
+
publicClient: PublicClient,
|
|
52
|
+
factoryAddress: Address,
|
|
53
|
+
assets: Address[],
|
|
54
|
+
): Promise<FactoryAssetBalance[]> {
|
|
55
|
+
const uniqueAssets = dedupeAssets(assets);
|
|
56
|
+
const nativeAsset = zeroAddress.toLowerCase();
|
|
57
|
+
|
|
58
|
+
const erc20Assets = uniqueAssets.filter((asset) => asset.toLowerCase() !== nativeAsset);
|
|
59
|
+
|
|
60
|
+
const erc20Balances = new Map<string, bigint>();
|
|
61
|
+
|
|
62
|
+
if (erc20Assets.length > 0) {
|
|
63
|
+
const results = await publicClient.multicall({
|
|
64
|
+
contracts: erc20Assets.map((asset) => ({
|
|
65
|
+
address: asset,
|
|
66
|
+
abi: erc20Abi,
|
|
67
|
+
functionName: "balanceOf",
|
|
68
|
+
args: [factoryAddress],
|
|
69
|
+
})),
|
|
70
|
+
allowFailure: true,
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
const failedAssets: Address[] = [];
|
|
74
|
+
|
|
75
|
+
results.forEach((result, index) => {
|
|
76
|
+
const asset = erc20Assets[index];
|
|
77
|
+
if (result.status === "success") {
|
|
78
|
+
erc20Balances.set(asset.toLowerCase(), result.result as bigint);
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
failedAssets.push(asset);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
if (failedAssets.length > 0) {
|
|
85
|
+
throw new Error(`Failed to read ERC20 balances for: ${failedAssets.join(", ")}`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const nativeIncluded = uniqueAssets.some((asset) => asset.toLowerCase() === nativeAsset);
|
|
90
|
+
|
|
91
|
+
const nativeBalance = nativeIncluded
|
|
92
|
+
? await publicClient.getBalance({ address: factoryAddress })
|
|
93
|
+
: undefined;
|
|
94
|
+
|
|
95
|
+
return uniqueAssets.map((asset) => {
|
|
96
|
+
const isNative = asset.toLowerCase() === nativeAsset;
|
|
97
|
+
|
|
98
|
+
return {
|
|
99
|
+
asset,
|
|
100
|
+
isNative,
|
|
101
|
+
amount: isNative ? (nativeBalance ?? 0n) : (erc20Balances.get(asset.toLowerCase()) ?? 0n),
|
|
102
|
+
};
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Collect all non-zero balances for the provided assets from the factory,
|
|
108
|
+
* sending each asset in a separate transaction.
|
|
109
|
+
*/
|
|
110
|
+
export async function collectFactoryFees(
|
|
111
|
+
params: CollectFactoryFeesParams,
|
|
112
|
+
): Promise<CollectFactoryFeesResult> {
|
|
113
|
+
const {
|
|
114
|
+
publicClient,
|
|
115
|
+
walletClient,
|
|
116
|
+
factoryAddress,
|
|
117
|
+
target,
|
|
118
|
+
assets,
|
|
119
|
+
account,
|
|
120
|
+
awaitReceipts = true,
|
|
121
|
+
} = params;
|
|
122
|
+
|
|
123
|
+
const balances = await getFactoryAssetBalances(publicClient, factoryAddress, assets);
|
|
124
|
+
|
|
125
|
+
const toCollect = balances.filter((item) => item.amount > 0n);
|
|
126
|
+
const collected: CollectedFactoryFeeTx[] = [];
|
|
127
|
+
|
|
128
|
+
for (const item of toCollect) {
|
|
129
|
+
if (item.isNative) {
|
|
130
|
+
const { request } = await publicClient.simulateContract({
|
|
131
|
+
address: factoryAddress,
|
|
132
|
+
abi: POOL_FACTORY_ABI,
|
|
133
|
+
functionName: "collectETH",
|
|
134
|
+
args: [target, item.amount],
|
|
135
|
+
account,
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
const hash = await walletClient.writeContract(request);
|
|
139
|
+
const tx: CollectedFactoryFeeTx = {
|
|
140
|
+
asset: item.asset,
|
|
141
|
+
amount: item.amount,
|
|
142
|
+
isNative: true,
|
|
143
|
+
hash,
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
if (awaitReceipts) {
|
|
147
|
+
tx.receipt = await publicClient.waitForTransactionReceipt({ hash });
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
collected.push(tx);
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const { request } = await publicClient.simulateContract({
|
|
155
|
+
address: factoryAddress,
|
|
156
|
+
abi: POOL_FACTORY_ABI,
|
|
157
|
+
functionName: "collectTokens",
|
|
158
|
+
args: [item.asset, target, item.amount],
|
|
159
|
+
account,
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
const hash = await walletClient.writeContract(request);
|
|
163
|
+
const tx: CollectedFactoryFeeTx = {
|
|
164
|
+
asset: item.asset,
|
|
165
|
+
amount: item.amount,
|
|
166
|
+
isNative: false,
|
|
167
|
+
hash,
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
if (awaitReceipts) {
|
|
171
|
+
tx.receipt = await publicClient.waitForTransactionReceipt({ hash });
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
collected.push(tx);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
return {
|
|
178
|
+
balances,
|
|
179
|
+
collected,
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function dedupeAssets(assets: Address[]): Address[] {
|
|
184
|
+
const deduped: Address[] = [];
|
|
185
|
+
const seen = new Set<string>();
|
|
186
|
+
|
|
187
|
+
for (const asset of assets) {
|
|
188
|
+
const key = asset.toLowerCase();
|
|
189
|
+
if (seen.has(key)) {
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
seen.add(key);
|
|
193
|
+
deduped.push(asset);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
return deduped;
|
|
197
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MetricAMM SDK - Factory Functions
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export {
|
|
6
|
+
getFactoryAssetBalances,
|
|
7
|
+
collectFactoryFees,
|
|
8
|
+
type FactoryAssetBalance,
|
|
9
|
+
type CollectFactoryFeesParams,
|
|
10
|
+
type CollectedFactoryFeeTx,
|
|
11
|
+
type CollectFactoryFeesResult,
|
|
12
|
+
} from "./collectFees.js";
|