@nradko/metric-omm-sdk-v1 0.4.1 → 0.4.3

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.
Files changed (77) hide show
  1. package/README.md +96 -12
  2. package/dist/abis/MetricOmmSimpleRouter.d.ts +44 -0
  3. package/dist/abis/MetricOmmSimpleRouter.d.ts.map +1 -1
  4. package/dist/abis/MetricOmmSimpleRouter.js +58 -0
  5. package/dist/abis/MetricOmmSimpleRouter.js.map +1 -1
  6. package/dist/abis/MetricOmmSwapQuoter.d.ts +26 -2
  7. package/dist/abis/MetricOmmSwapQuoter.d.ts.map +1 -1
  8. package/dist/abis/MetricOmmSwapQuoter.js +34 -2
  9. package/dist/abis/MetricOmmSwapQuoter.js.map +1 -1
  10. package/dist/abis/index.d.ts +0 -1
  11. package/dist/abis/index.d.ts.map +1 -1
  12. package/dist/abis/index.js +0 -1
  13. package/dist/abis/index.js.map +1 -1
  14. package/dist/addresses.d.ts +0 -2
  15. package/dist/addresses.d.ts.map +1 -1
  16. package/dist/addresses.js +8 -9
  17. package/dist/addresses.js.map +1 -1
  18. package/dist/dataProvider/index.d.ts +1 -1
  19. package/dist/dataProvider/index.d.ts.map +1 -1
  20. package/dist/dataProvider/index.js +1 -1
  21. package/dist/dataProvider/index.js.map +1 -1
  22. package/dist/dataProvider/read.d.ts +1 -3
  23. package/dist/dataProvider/read.d.ts.map +1 -1
  24. package/dist/dataProvider/read.js +1 -3
  25. package/dist/dataProvider/read.js.map +1 -1
  26. package/dist/index.d.ts +3 -3
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.js +3 -3
  29. package/dist/index.js.map +1 -1
  30. package/dist/pool/liquidity.d.ts +83 -7
  31. package/dist/pool/liquidity.d.ts.map +1 -1
  32. package/dist/pool/liquidity.js +63 -3
  33. package/dist/pool/liquidity.js.map +1 -1
  34. package/dist/router/fromRoute.d.ts +93 -0
  35. package/dist/router/fromRoute.d.ts.map +1 -0
  36. package/dist/router/fromRoute.js +187 -0
  37. package/dist/router/fromRoute.js.map +1 -0
  38. package/dist/router/index.d.ts +8 -1
  39. package/dist/router/index.d.ts.map +1 -1
  40. package/dist/router/index.js +8 -1
  41. package/dist/router/index.js.map +1 -1
  42. package/dist/router/nativeSwap.d.ts +47 -0
  43. package/dist/router/nativeSwap.d.ts.map +1 -0
  44. package/dist/router/nativeSwap.js +89 -0
  45. package/dist/router/nativeSwap.js.map +1 -0
  46. package/dist/router/swap.d.ts +82 -1
  47. package/dist/router/swap.d.ts.map +1 -1
  48. package/dist/router/swap.js +51 -1
  49. package/dist/router/swap.js.map +1 -1
  50. package/dist/router/swapPath.d.ts +46 -1
  51. package/dist/router/swapPath.d.ts.map +1 -1
  52. package/dist/router/swapPath.js +34 -0
  53. package/dist/router/swapPath.js.map +1 -1
  54. package/dist/router/utils.d.ts +9 -0
  55. package/dist/router/utils.d.ts.map +1 -0
  56. package/dist/router/utils.js +27 -0
  57. package/dist/router/utils.js.map +1 -0
  58. package/package.json +2 -2
  59. package/src/abis/MetricOmmSimpleRouter.ts +58 -0
  60. package/src/abis/MetricOmmSwapQuoter.ts +34 -2
  61. package/src/abis/index.ts +0 -1
  62. package/src/addresses.ts +8 -11
  63. package/src/dataProvider/index.ts +0 -1
  64. package/src/dataProvider/read.ts +1 -4
  65. package/src/index.ts +22 -2
  66. package/src/pool/liquidity.ts +83 -7
  67. package/src/router/fromRoute.ts +318 -0
  68. package/src/router/index.ts +36 -1
  69. package/src/router/nativeSwap.ts +123 -0
  70. package/src/router/swap.ts +82 -1
  71. package/src/router/swapPath.ts +47 -1
  72. package/src/router/utils.ts +31 -0
  73. package/dist/abis/MetricOmmPoolStateView.d.ts +0 -238
  74. package/dist/abis/MetricOmmPoolStateView.d.ts.map +0 -1
  75. package/dist/abis/MetricOmmPoolStateView.js +0 -315
  76. package/dist/abis/MetricOmmPoolStateView.js.map +0 -1
  77. package/src/abis/MetricOmmPoolStateView.ts +0 -314
@@ -1,6 +1,10 @@
1
1
  /**
2
- * MetricAMM SDK - SimpleRouter multihop swap helpers.
2
+ * SimpleRouter multihop swap helpers.
3
+ *
4
+ * Multihop swaps walk `pools` in order; intermediate tokens remain on the router between hops.
5
+ * For ERC-20 paths, approve the router for `tokenIn` once before sending the transaction.
3
6
  */
7
+
4
8
  import type { Address, Hex, PublicClient } from "viem";
5
9
  import { encodeFunctionData } from "viem";
6
10
  import { quoteLiveExactIn, quoteLiveExactOut } from "../quoter/quotePath.js";
@@ -10,10 +14,18 @@ import { ceilDiv, toSlippageBps } from "./swap.js";
10
14
 
11
15
  const BPS_BASE = 10_000n;
12
16
 
17
+ /**
18
+ * Arguments for `MetricOmmSimpleRouter.exactInput` (multihop exact input).
19
+ * `tokens` and `zeroForOneBitMap` are usually produced by {@link buildExactInputParams}.
20
+ */
13
21
  export type ExactInputParams = {
22
+ /** Path tokens, length `pools.length + 1`. */
14
23
  tokens: Address[];
24
+ /** One pool per hop, in swap order. */
15
25
  pools: Address[];
26
+ /** Extension calldata per hop; use `0x` when a pool has no extension. */
16
27
  extensionDatas: Hex[];
28
+ /** Bit `i` set when hop `i` is token0 → token1. */
17
29
  zeroForOneBitMap: bigint;
18
30
  amountIn: bigint;
19
31
  amountOutMinimum: bigint;
@@ -21,6 +33,7 @@ export type ExactInputParams = {
21
33
  deadline: bigint;
22
34
  };
23
35
 
36
+ /** Arguments for `MetricOmmSimpleRouter.exactOutput` (multihop exact output). */
24
37
  export type ExactOutputParams = {
25
38
  tokens: Address[];
26
39
  pools: Address[];
@@ -32,10 +45,12 @@ export type ExactOutputParams = {
32
45
  deadline: bigint;
33
46
  };
34
47
 
48
+ /** Inputs for {@link buildExactInputParams}. */
35
49
  export interface BuildExactInputParams {
36
50
  publicClient: PublicClient;
37
51
  tokenIn: Address;
38
52
  tokenOut: Address;
53
+ /** Ordered pool addresses connecting `tokenIn` → `tokenOut`. */
39
54
  pools: readonly Address[];
40
55
  extensionDatas?: readonly Hex[];
41
56
  recipient: Address;
@@ -43,8 +58,10 @@ export interface BuildExactInputParams {
43
58
  slippagePercent: number;
44
59
  deadline: bigint;
45
60
  quoterAddress?: Address;
61
+ wrappedNative?: Address;
46
62
  }
47
63
 
64
+ /** Inputs for {@link buildExactOutputParams}. */
48
65
  export interface BuildExactOutputParams {
49
66
  publicClient: PublicClient;
50
67
  tokenIn: Address;
@@ -56,6 +73,7 @@ export interface BuildExactOutputParams {
56
73
  slippagePercent: number;
57
74
  deadline: bigint;
58
75
  quoterAddress?: Address;
76
+ wrappedNative?: Address;
59
77
  }
60
78
 
61
79
  function toExactInputStruct(params: ExactInputParams) {
@@ -84,6 +102,29 @@ function toExactOutputStruct(params: ExactOutputParams) {
84
102
  };
85
103
  }
86
104
 
105
+ /**
106
+ * Build multihop exact-input params: resolves path, quotes output, applies slippage.
107
+ *
108
+ * @example
109
+ * ```ts
110
+ * const pathParams = await buildExactInputParams({
111
+ * publicClient,
112
+ * tokenIn: tokenA,
113
+ * tokenOut: tokenC,
114
+ * pools: [poolAB, poolBC],
115
+ * recipient: account,
116
+ * amountIn: parseUnits("1", 18),
117
+ * slippagePercent: 0.5,
118
+ * deadline,
119
+ * quoterAddress: addresses.quoter,
120
+ * });
121
+ * await walletClient.sendTransaction({
122
+ * to: addresses.simpleRouter,
123
+ * data: encodeExactInputCalldata(pathParams),
124
+ * account,
125
+ * });
126
+ * ```
127
+ */
87
128
  export async function buildExactInputParams(
88
129
  params: BuildExactInputParams,
89
130
  ): Promise<ExactInputParams> {
@@ -121,6 +162,7 @@ export async function buildExactInputParams(
121
162
  };
122
163
  }
123
164
 
165
+ /** Build multihop exact-output params with live quote and slippage on `amountInMaximum`. */
124
166
  export async function buildExactOutputParams(
125
167
  params: BuildExactOutputParams,
126
168
  ): Promise<ExactOutputParams> {
@@ -158,6 +200,7 @@ export async function buildExactOutputParams(
158
200
  };
159
201
  }
160
202
 
203
+ /** Encode `exactInput` multihop calldata. */
161
204
  export function encodeExactInputCalldata(params: ExactInputParams): Hex {
162
205
  return encodeFunctionData({
163
206
  abi: SIMPLE_ROUTER_ABI,
@@ -166,8 +209,10 @@ export function encodeExactInputCalldata(params: ExactInputParams): Hex {
166
209
  });
167
210
  }
168
211
 
212
+ /** Alias for {@link encodeExactInputCalldata}. */
169
213
  export const prepareExactInputCalldata = encodeExactInputCalldata;
170
214
 
215
+ /** Encode `exactOutput` multihop calldata. */
171
216
  export function encodeExactOutputCalldata(params: ExactOutputParams): Hex {
172
217
  return encodeFunctionData({
173
218
  abi: SIMPLE_ROUTER_ABI,
@@ -176,6 +221,7 @@ export function encodeExactOutputCalldata(params: ExactOutputParams): Hex {
176
221
  });
177
222
  }
178
223
 
224
+ /** Alias for {@link encodeExactOutputCalldata}. */
179
225
  export const prepareExactOutputCalldata = encodeExactOutputCalldata;
180
226
 
181
227
  export { encodeZeroForOneBitMap } from "../swap/path.js";
@@ -0,0 +1,31 @@
1
+ /** SimpleRouter multicall and PeripheryPayments calldata encoders. */
2
+
3
+ import type { Address, Hex } from "viem";
4
+ import { encodeFunctionData } from "viem";
5
+ import { SIMPLE_ROUTER_ABI } from "../constants.js";
6
+
7
+ /** `multicall(bytes[])`. */
8
+ export function encodeMulticallCalldata(calls: readonly Hex[]): Hex {
9
+ return encodeFunctionData({
10
+ abi: SIMPLE_ROUTER_ABI,
11
+ functionName: "multicall",
12
+ args: [calls],
13
+ });
14
+ }
15
+
16
+ /** `refundETH()` — unused native balance on the router back to caller. */
17
+ export function encodeRefundETHCalldata(): Hex {
18
+ return encodeFunctionData({
19
+ abi: SIMPLE_ROUTER_ABI,
20
+ functionName: "refundETH",
21
+ });
22
+ }
23
+
24
+ /** `unwrapWETH9(amountMinimum, recipient)`. */
25
+ export function encodeUnwrapWETH9Calldata(amountMinimum: bigint, recipient: Address): Hex {
26
+ return encodeFunctionData({
27
+ abi: SIMPLE_ROUTER_ABI,
28
+ functionName: "unwrapWETH9",
29
+ args: [amountMinimum, recipient],
30
+ });
31
+ }
@@ -1,238 +0,0 @@
1
- export declare const MetricOmmPoolStateViewAbi: readonly [{
2
- readonly inputs: readonly [{
3
- readonly internalType: "address";
4
- readonly name: "factory";
5
- readonly type: "address";
6
- }];
7
- readonly stateMutability: "nonpayable";
8
- readonly type: "constructor";
9
- }, {
10
- readonly inputs: readonly [{
11
- readonly internalType: "uint8";
12
- readonly name: "bits";
13
- readonly type: "uint8";
14
- }, {
15
- readonly internalType: "uint256";
16
- readonly name: "value";
17
- readonly type: "uint256";
18
- }];
19
- readonly name: "SafeCastOverflowedUintDowncast";
20
- readonly type: "error";
21
- }, {
22
- readonly inputs: readonly [{
23
- readonly internalType: "address";
24
- readonly name: "pool";
25
- readonly type: "address";
26
- }, {
27
- readonly internalType: "int8";
28
- readonly name: "binIdx";
29
- readonly type: "int8";
30
- }];
31
- readonly name: "binState";
32
- readonly outputs: readonly [{
33
- readonly internalType: "uint104";
34
- readonly name: "token0BalanceScaled";
35
- readonly type: "uint104";
36
- }, {
37
- readonly internalType: "uint104";
38
- readonly name: "token1BalanceScaled";
39
- readonly type: "uint104";
40
- }, {
41
- readonly internalType: "uint16";
42
- readonly name: "lengthE6";
43
- readonly type: "uint16";
44
- }, {
45
- readonly internalType: "uint16";
46
- readonly name: "addFeeBuyE6";
47
- readonly type: "uint16";
48
- }, {
49
- readonly internalType: "uint16";
50
- readonly name: "addFeeSellE6";
51
- readonly type: "uint16";
52
- }];
53
- readonly stateMutability: "view";
54
- readonly type: "function";
55
- }, {
56
- readonly inputs: readonly [{
57
- readonly internalType: "address";
58
- readonly name: "pool";
59
- readonly type: "address";
60
- }, {
61
- readonly internalType: "int8[]";
62
- readonly name: "binIdxs";
63
- readonly type: "int8[]";
64
- }];
65
- readonly name: "binStates";
66
- readonly outputs: readonly [{
67
- readonly internalType: "bytes32[]";
68
- readonly name: "";
69
- readonly type: "bytes32[]";
70
- }];
71
- readonly stateMutability: "view";
72
- readonly type: "function";
73
- }, {
74
- readonly inputs: readonly [{
75
- readonly internalType: "address";
76
- readonly name: "pool";
77
- readonly type: "address";
78
- }, {
79
- readonly internalType: "int8";
80
- readonly name: "binIdx";
81
- readonly type: "int8";
82
- }];
83
- readonly name: "binTotalShares";
84
- readonly outputs: readonly [{
85
- readonly internalType: "uint256";
86
- readonly name: "";
87
- readonly type: "uint256";
88
- }];
89
- readonly stateMutability: "view";
90
- readonly type: "function";
91
- }, {
92
- readonly inputs: readonly [{
93
- readonly internalType: "address";
94
- readonly name: "pool";
95
- readonly type: "address";
96
- }, {
97
- readonly internalType: "int8[]";
98
- readonly name: "binIdxs";
99
- readonly type: "int8[]";
100
- }];
101
- readonly name: "binTotalShares";
102
- readonly outputs: readonly [{
103
- readonly internalType: "bytes32[]";
104
- readonly name: "";
105
- readonly type: "bytes32[]";
106
- }];
107
- readonly stateMutability: "view";
108
- readonly type: "function";
109
- }, {
110
- readonly inputs: readonly [{
111
- readonly internalType: "address";
112
- readonly name: "pool";
113
- readonly type: "address";
114
- }, {
115
- readonly internalType: "bytes32";
116
- readonly name: "positionBinKey";
117
- readonly type: "bytes32";
118
- }];
119
- readonly name: "positionBinShares";
120
- readonly outputs: readonly [{
121
- readonly internalType: "uint104";
122
- readonly name: "";
123
- readonly type: "uint104";
124
- }];
125
- readonly stateMutability: "view";
126
- readonly type: "function";
127
- }, {
128
- readonly inputs: readonly [{
129
- readonly internalType: "address";
130
- readonly name: "pool";
131
- readonly type: "address";
132
- }, {
133
- readonly internalType: "address";
134
- readonly name: "owner";
135
- readonly type: "address";
136
- }, {
137
- readonly internalType: "uint80";
138
- readonly name: "salt";
139
- readonly type: "uint80";
140
- }, {
141
- readonly internalType: "int8";
142
- readonly name: "bin";
143
- readonly type: "int8";
144
- }];
145
- readonly name: "positionBinShares";
146
- readonly outputs: readonly [{
147
- readonly internalType: "uint104";
148
- readonly name: "";
149
- readonly type: "uint104";
150
- }];
151
- readonly stateMutability: "view";
152
- readonly type: "function";
153
- }, {
154
- readonly inputs: readonly [{
155
- readonly internalType: "address";
156
- readonly name: "pool";
157
- readonly type: "address";
158
- }];
159
- readonly name: "priceProvider";
160
- readonly outputs: readonly [{
161
- readonly internalType: "address";
162
- readonly name: "";
163
- readonly type: "address";
164
- }];
165
- readonly stateMutability: "view";
166
- readonly type: "function";
167
- }, {
168
- readonly inputs: readonly [{
169
- readonly internalType: "address";
170
- readonly name: "pool";
171
- readonly type: "address";
172
- }];
173
- readonly name: "slot0";
174
- readonly outputs: readonly [{
175
- readonly internalType: "uint8";
176
- readonly name: "_pauseLevel";
177
- readonly type: "uint8";
178
- }, {
179
- readonly internalType: "int8";
180
- readonly name: "_curBinIdx";
181
- readonly type: "int8";
182
- }, {
183
- readonly internalType: "uint104";
184
- readonly name: "_curPosInBin";
185
- readonly type: "uint104";
186
- }, {
187
- readonly internalType: "int24";
188
- readonly name: "_curBinDistFromProvidedPrice";
189
- readonly type: "int24";
190
- }, {
191
- readonly internalType: "uint24";
192
- readonly name: "_spreadFeeE6";
193
- readonly type: "uint24";
194
- }, {
195
- readonly internalType: "uint24";
196
- readonly name: "_notionalFeeE8";
197
- readonly type: "uint24";
198
- }];
199
- readonly stateMutability: "view";
200
- readonly type: "function";
201
- }, {
202
- readonly inputs: readonly [{
203
- readonly internalType: "address";
204
- readonly name: "pool";
205
- readonly type: "address";
206
- }];
207
- readonly name: "slot1";
208
- readonly outputs: readonly [{
209
- readonly internalType: "uint128";
210
- readonly name: "totalScaledToken0InBins";
211
- readonly type: "uint128";
212
- }, {
213
- readonly internalType: "uint128";
214
- readonly name: "totalScaledToken1InBins";
215
- readonly type: "uint128";
216
- }];
217
- readonly stateMutability: "view";
218
- readonly type: "function";
219
- }, {
220
- readonly inputs: readonly [{
221
- readonly internalType: "address";
222
- readonly name: "pool";
223
- readonly type: "address";
224
- }];
225
- readonly name: "slot2";
226
- readonly outputs: readonly [{
227
- readonly internalType: "uint128";
228
- readonly name: "notionalFeeToken0Scaled";
229
- readonly type: "uint128";
230
- }, {
231
- readonly internalType: "uint128";
232
- readonly name: "notionalFeeToken1Scaled";
233
- readonly type: "uint128";
234
- }];
235
- readonly stateMutability: "view";
236
- readonly type: "function";
237
- }];
238
- //# sourceMappingURL=MetricOmmPoolStateView.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"MetricOmmPoolStateView.d.ts","sourceRoot":"","sources":["../../src/abis/MetricOmmPoolStateView.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAyT5B,CAAC"}