@logswap/sdk 0.5.65 → 0.5.67

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.
@@ -1741,26 +1741,6 @@ export declare const fPoolManagerAbi: readonly [{
1741
1741
  readonly type: "uint256";
1742
1742
  }];
1743
1743
  readonly stateMutability: "view";
1744
- }, {
1745
- readonly type: "function";
1746
- readonly inputs: readonly [];
1747
- readonly name: "FEE_MAX";
1748
- readonly outputs: readonly [{
1749
- readonly name: "";
1750
- readonly internalType: "uint256";
1751
- readonly type: "uint256";
1752
- }];
1753
- readonly stateMutability: "view";
1754
- }, {
1755
- readonly type: "function";
1756
- readonly inputs: readonly [];
1757
- readonly name: "FEE_MIN";
1758
- readonly outputs: readonly [{
1759
- readonly name: "";
1760
- readonly internalType: "uint256";
1761
- readonly type: "uint256";
1762
- }];
1763
- readonly stateMutability: "view";
1764
1744
  }, {
1765
1745
  readonly type: "function";
1766
1746
  readonly inputs: readonly [];
@@ -2162,63 +2142,6 @@ export declare const fPoolManagerAbi: readonly [{
2162
2142
  readonly name: "harvest";
2163
2143
  readonly outputs: readonly [];
2164
2144
  readonly stateMutability: "nonpayable";
2165
- }, {
2166
- readonly type: "function";
2167
- readonly inputs: readonly [{
2168
- readonly name: "poolId";
2169
- readonly internalType: "bytes32";
2170
- readonly type: "bytes32";
2171
- }];
2172
- readonly name: "harvestable";
2173
- readonly outputs: readonly [{
2174
- readonly name: "";
2175
- readonly internalType: "uint256";
2176
- readonly type: "uint256";
2177
- }];
2178
- readonly stateMutability: "view";
2179
- }, {
2180
- readonly type: "function";
2181
- readonly inputs: readonly [{
2182
- readonly name: "key";
2183
- readonly internalType: "struct FPoolKey";
2184
- readonly type: "tuple";
2185
- readonly components: readonly [{
2186
- readonly name: "quote";
2187
- readonly internalType: "address";
2188
- readonly type: "address";
2189
- }, {
2190
- readonly name: "bases";
2191
- readonly internalType: "address[]";
2192
- readonly type: "address[]";
2193
- }, {
2194
- readonly name: "weights";
2195
- readonly internalType: "uint256[]";
2196
- readonly type: "uint256[]";
2197
- }, {
2198
- readonly name: "phi";
2199
- readonly internalType: "uint256";
2200
- readonly type: "uint256";
2201
- }, {
2202
- readonly name: "policy";
2203
- readonly internalType: "address";
2204
- readonly type: "address";
2205
- }, {
2206
- readonly name: "creator";
2207
- readonly internalType: "address";
2208
- readonly type: "address";
2209
- }, {
2210
- readonly name: "salt";
2211
- readonly internalType: "bytes32";
2212
- readonly type: "bytes32";
2213
- }];
2214
- }];
2215
- readonly name: "idOf";
2216
- readonly outputs: readonly [{
2217
- readonly name: "";
2218
- readonly internalType: "bytes32";
2219
- readonly type: "bytes32";
2220
- }];
2221
- readonly stateMutability: "pure";
2222
2145
  }, {
2223
2146
  readonly type: "function";
2224
2147
  readonly inputs: readonly [{
@@ -2500,24 +2423,6 @@ export declare const fPoolManagerAbi: readonly [{
2500
2423
  readonly type: "address";
2501
2424
  }];
2502
2425
  readonly stateMutability: "view";
2503
- }, {
2504
- readonly type: "function";
2505
- readonly inputs: readonly [{
2506
- readonly name: "poolId";
2507
- readonly internalType: "bytes32";
2508
- readonly type: "bytes32";
2509
- }, {
2510
- readonly name: "j";
2511
- readonly internalType: "uint256";
2512
- readonly type: "uint256";
2513
- }];
2514
- readonly name: "reserveOf";
2515
- readonly outputs: readonly [{
2516
- readonly name: "";
2517
- readonly internalType: "uint256";
2518
- readonly type: "uint256";
2519
- }];
2520
- readonly stateMutability: "view";
2521
2426
  }, {
2522
2427
  readonly type: "function";
2523
2428
  readonly inputs: readonly [{
@@ -6681,6 +6586,10 @@ export declare const padPolicyAbi: readonly [{
6681
6586
  readonly name: "burn";
6682
6587
  readonly internalType: "uint256";
6683
6588
  readonly type: "uint256";
6589
+ }, {
6590
+ readonly name: "carried";
6591
+ readonly internalType: "address";
6592
+ readonly type: "address";
6684
6593
  }];
6685
6594
  }];
6686
6595
  readonly stateMutability: "nonpayable";
@@ -6746,20 +6655,6 @@ export declare const padPolicyAbi: readonly [{
6746
6655
  readonly type: "bool";
6747
6656
  }];
6748
6657
  readonly stateMutability: "view";
6749
- }, {
6750
- readonly type: "function";
6751
- readonly inputs: readonly [{
6752
- readonly name: "";
6753
- readonly internalType: "bytes32";
6754
- readonly type: "bytes32";
6755
- }];
6756
- readonly name: "rung";
6757
- readonly outputs: readonly [{
6758
- readonly name: "";
6759
- readonly internalType: "uint256";
6760
- readonly type: "uint256";
6761
- }];
6762
- readonly stateMutability: "view";
6763
6658
  }, {
6764
6659
  readonly type: "function";
6765
6660
  readonly inputs: readonly [{
@@ -6978,26 +6873,6 @@ export declare const padPolicyAbi: readonly [{
6978
6873
  readonly indexed: false;
6979
6874
  }];
6980
6875
  readonly name: "QuoteListed";
6981
- }, {
6982
- readonly type: "event";
6983
- readonly anonymous: false;
6984
- readonly inputs: readonly [{
6985
- readonly name: "poolId";
6986
- readonly internalType: "bytes32";
6987
- readonly type: "bytes32";
6988
- readonly indexed: true;
6989
- }, {
6990
- readonly name: "from";
6991
- readonly internalType: "address";
6992
- readonly type: "address";
6993
- readonly indexed: true;
6994
- }, {
6995
- readonly name: "rung";
6996
- readonly internalType: "uint256";
6997
- readonly type: "uint256";
6998
- readonly indexed: false;
6999
- }];
7000
- readonly name: "RungCarried";
7001
6876
  }, {
7002
6877
  readonly type: "event";
7003
6878
  readonly anonymous: false;
@@ -7449,6 +7324,10 @@ export declare const polPolicyAbi: readonly [{
7449
7324
  readonly name: "burn";
7450
7325
  readonly internalType: "uint256";
7451
7326
  readonly type: "uint256";
7327
+ }, {
7328
+ readonly name: "carried";
7329
+ readonly internalType: "address";
7330
+ readonly type: "address";
7452
7331
  }];
7453
7332
  }];
7454
7333
  readonly stateMutability: "nonpayable";
@@ -8581,6 +8460,10 @@ export declare const privatePolicyAbi: readonly [{
8581
8460
  readonly name: "burn";
8582
8461
  readonly internalType: "uint256";
8583
8462
  readonly type: "uint256";
8463
+ }, {
8464
+ readonly name: "carried";
8465
+ readonly internalType: "address";
8466
+ readonly type: "address";
8584
8467
  }];
8585
8468
  }];
8586
8469
  readonly stateMutability: "nonpayable";
@@ -9385,6 +9268,10 @@ export declare const publicPolicyAbi: readonly [{
9385
9268
  readonly name: "burn";
9386
9269
  readonly internalType: "uint256";
9387
9270
  readonly type: "uint256";
9271
+ }, {
9272
+ readonly name: "carried";
9273
+ readonly internalType: "address";
9274
+ readonly type: "address";
9388
9275
  }];
9389
9276
  }];
9390
9277
  readonly stateMutability: "nonpayable";
package/dist/generated.js CHANGED
@@ -1097,20 +1097,6 @@ export const fPoolManagerAbi = [
1097
1097
  outputs: [{ name: '', internalType: 'uint256', type: 'uint256' }],
1098
1098
  stateMutability: 'view',
1099
1099
  },
1100
- {
1101
- type: 'function',
1102
- inputs: [],
1103
- name: 'FEE_MAX',
1104
- outputs: [{ name: '', internalType: 'uint256', type: 'uint256' }],
1105
- stateMutability: 'view',
1106
- },
1107
- {
1108
- type: 'function',
1109
- inputs: [],
1110
- name: 'FEE_MIN',
1111
- outputs: [{ name: '', internalType: 'uint256', type: 'uint256' }],
1112
- stateMutability: 'view',
1113
- },
1114
1100
  {
1115
1101
  type: 'function',
1116
1102
  inputs: [],
@@ -1327,35 +1313,6 @@ export const fPoolManagerAbi = [
1327
1313
  outputs: [],
1328
1314
  stateMutability: 'nonpayable',
1329
1315
  },
1330
- {
1331
- type: 'function',
1332
- inputs: [{ name: 'poolId', internalType: 'bytes32', type: 'bytes32' }],
1333
- name: 'harvestable',
1334
- outputs: [{ name: '', internalType: 'uint256', type: 'uint256' }],
1335
- stateMutability: 'view',
1336
- },
1337
- {
1338
- type: 'function',
1339
- inputs: [
1340
- {
1341
- name: 'key',
1342
- internalType: 'struct FPoolKey',
1343
- type: 'tuple',
1344
- components: [
1345
- { name: 'quote', internalType: 'address', type: 'address' },
1346
- { name: 'bases', internalType: 'address[]', type: 'address[]' },
1347
- { name: 'weights', internalType: 'uint256[]', type: 'uint256[]' },
1348
- { name: 'phi', internalType: 'uint256', type: 'uint256' },
1349
- { name: 'policy', internalType: 'address', type: 'address' },
1350
- { name: 'creator', internalType: 'address', type: 'address' },
1351
- { name: 'salt', internalType: 'bytes32', type: 'bytes32' },
1352
- ],
1353
- },
1354
- ],
1355
- name: 'idOf',
1356
- outputs: [{ name: '', internalType: 'bytes32', type: 'bytes32' }],
1357
- stateMutability: 'pure',
1358
- },
1359
1316
  {
1360
1317
  type: 'function',
1361
1318
  inputs: [
@@ -1513,16 +1470,6 @@ export const fPoolManagerAbi = [
1513
1470
  ],
1514
1471
  stateMutability: 'view',
1515
1472
  },
1516
- {
1517
- type: 'function',
1518
- inputs: [
1519
- { name: 'poolId', internalType: 'bytes32', type: 'bytes32' },
1520
- { name: 'j', internalType: 'uint256', type: 'uint256' },
1521
- ],
1522
- name: 'reserveOf',
1523
- outputs: [{ name: '', internalType: 'uint256', type: 'uint256' }],
1524
- stateMutability: 'view',
1525
- },
1526
1473
  {
1527
1474
  type: 'function',
1528
1475
  inputs: [{ name: 'poolId', internalType: 'bytes32', type: 'bytes32' }],
@@ -3940,6 +3887,7 @@ export const padPolicyAbi = [
3940
3887
  { name: 'toPayee', internalType: 'uint256', type: 'uint256' },
3941
3888
  { name: 'protocolCut', internalType: 'uint256', type: 'uint256' },
3942
3889
  { name: 'burn', internalType: 'uint256', type: 'uint256' },
3890
+ { name: 'carried', internalType: 'address', type: 'address' },
3943
3891
  ],
3944
3892
  },
3945
3893
  ],
@@ -3983,13 +3931,6 @@ export const padPolicyAbi = [
3983
3931
  outputs: [{ name: '', internalType: 'bool', type: 'bool' }],
3984
3932
  stateMutability: 'view',
3985
3933
  },
3986
- {
3987
- type: 'function',
3988
- inputs: [{ name: '', internalType: 'bytes32', type: 'bytes32' }],
3989
- name: 'rung',
3990
- outputs: [{ name: '', internalType: 'uint256', type: 'uint256' }],
3991
- stateMutability: 'view',
3992
- },
3993
3934
  {
3994
3935
  type: 'function',
3995
3936
  inputs: [{ name: '_harvestCut', internalType: 'uint256', type: 'uint256' }],
@@ -4167,26 +4108,6 @@ export const padPolicyAbi = [
4167
4108
  ],
4168
4109
  name: 'QuoteListed',
4169
4110
  },
4170
- {
4171
- type: 'event',
4172
- anonymous: false,
4173
- inputs: [
4174
- {
4175
- name: 'poolId',
4176
- internalType: 'bytes32',
4177
- type: 'bytes32',
4178
- indexed: true,
4179
- },
4180
- { name: 'from', internalType: 'address', type: 'address', indexed: true },
4181
- {
4182
- name: 'rung',
4183
- internalType: 'uint256',
4184
- type: 'uint256',
4185
- indexed: false,
4186
- },
4187
- ],
4188
- name: 'RungCarried',
4189
- },
4190
4111
  {
4191
4112
  type: 'event',
4192
4113
  anonymous: false,
@@ -4457,6 +4378,7 @@ export const polPolicyAbi = [
4457
4378
  { name: 'toPayee', internalType: 'uint256', type: 'uint256' },
4458
4379
  { name: 'protocolCut', internalType: 'uint256', type: 'uint256' },
4459
4380
  { name: 'burn', internalType: 'uint256', type: 'uint256' },
4381
+ { name: 'carried', internalType: 'address', type: 'address' },
4460
4382
  ],
4461
4383
  },
4462
4384
  ],
@@ -5223,6 +5145,7 @@ export const privatePolicyAbi = [
5223
5145
  { name: 'toPayee', internalType: 'uint256', type: 'uint256' },
5224
5146
  { name: 'protocolCut', internalType: 'uint256', type: 'uint256' },
5225
5147
  { name: 'burn', internalType: 'uint256', type: 'uint256' },
5148
+ { name: 'carried', internalType: 'address', type: 'address' },
5226
5149
  ],
5227
5150
  },
5228
5151
  ],
@@ -5751,6 +5674,7 @@ export const publicPolicyAbi = [
5751
5674
  { name: 'toPayee', internalType: 'uint256', type: 'uint256' },
5752
5675
  { name: 'protocolCut', internalType: 'uint256', type: 'uint256' },
5753
5676
  { name: 'burn', internalType: 'uint256', type: 'uint256' },
5677
+ { name: 'carried', internalType: 'address', type: 'address' },
5754
5678
  ],
5755
5679
  },
5756
5680
  ],
package/dist/keys.d.ts CHANGED
@@ -11,6 +11,15 @@
11
11
  * if the two ever disagree, that test fails rather than the SDK silently addressing the wrong pool.
12
12
  */
13
13
  import { type Address, type Hex } from "viem";
14
+ /**
15
+ * The fee domain of the family, `FeeParams.FEE_MIN` / `FEE_MAX` (decisions 043): one bound for a
16
+ * C market's φ and an F pool's alike, WAD. 1 bp and 1%. The F manager no longer answers
17
+ * `FEE_MIN()` / `FEE_MAX()` (F version 21 cut the getters for bytecode); every F policy still
18
+ * checks φ against these at `onInitialize`, and the C side re-exposes them through the lens's
19
+ * `cParams()`. Constants here, so a create form bounds φ with no read.
20
+ */
21
+ export declare const FEE_MIN: bigint;
22
+ export declare const FEE_MAX: bigint;
14
23
  /**
15
24
  * The economic tuple that IS the market. Field order is load-bearing: it is the ABI encoding order,
16
25
  * so it must match `src/types/PoolKey.sol` exactly.
@@ -21,7 +30,7 @@ export interface PoolKey {
21
30
  /** Log-tick spacing, WAD. The LP-boundary ladder — position floors and caps. */
22
31
  tickSpacing: bigint;
23
32
  /**
24
- * The swap fee, WAD, fixed for the life of the market: `FEE_MIN` (1 bp) ≤ φ ≤ `FEE_MAX` (25%),
33
+ * The swap fee, WAD, fixed for the life of the market: {@link FEE_MIN} (1 bp) ≤ φ ≤ {@link FEE_MAX} (1%),
25
34
  * or `0n`, which selects `DEFAULT_FEE` (2 bp) at read time. Four fields since C version 4
26
35
  *: `kappa` and `alpha` left with the variance kernel, and `phiMin` — a floor with
27
36
  * nothing above it — became `phi`. Every pool id changed with the shape.
package/dist/keys.js CHANGED
@@ -11,6 +11,15 @@
11
11
  * if the two ever disagree, that test fails rather than the SDK silently addressing the wrong pool.
12
12
  */
13
13
  import { encodeAbiParameters, keccak256 } from "viem";
14
+ /**
15
+ * The fee domain of the family, `FeeParams.FEE_MIN` / `FEE_MAX` (decisions 043): one bound for a
16
+ * C market's φ and an F pool's alike, WAD. 1 bp and 1%. The F manager no longer answers
17
+ * `FEE_MIN()` / `FEE_MAX()` (F version 21 cut the getters for bytecode); every F policy still
18
+ * checks φ against these at `onInitialize`, and the C side re-exposes them through the lens's
19
+ * `cParams()`. Constants here, so a create form bounds φ with no read.
20
+ */
21
+ export const FEE_MIN = 10n ** 14n;
22
+ export const FEE_MAX = 10n ** 16n;
14
23
  const POOL_KEY_ABI = [
15
24
  {
16
25
  type: "tuple",
package/dist/pools.d.ts CHANGED
@@ -53,6 +53,32 @@ export declare function priceOf(state: Pick<PoolState, "x">, scale?: number): nu
53
53
  * it is 1 and nothing changes.
54
54
  */
55
55
  export declare function priceScale(baseDecimals: number, quoteDecimals: number): number;
56
+ /** The C manager's log-price wall: |x| ≤ 46 on the WEI ratio (`MAX_ABS_FLOOR`). */
57
+ export declare const C_MAX_ABS_X = 46;
58
+ /** The least derived base reserve a C book keeps, in base wei (`MIN_RESERVE`, decisions 023). */
59
+ export declare const C_MIN_RESERVE: bigint;
60
+ /**
61
+ * The prices a C market can hold, in human units — quote per whole base token (decisions 054).
62
+ *
63
+ * - `listMin`, `listMax`: the wall, `10^(base − quote) · e^{∓46}`. A market cannot be initialized,
64
+ * and no floor or cap placed, outside it. An 18-dec token against 6-dec USDC cannot list under
65
+ * 1.05e-8; against an 18-dec quote the same token lists down to 1.05e-20.
66
+ * - `ceiling`: the highest price the book can trade to with `lActive` of active exposure (quote
67
+ * wei): the derived reserve `lActive / p` must stay at or above `C_MIN_RESERVE` base wei, so
68
+ * `ceiling = lActive · 10^(base − quote) / 1e6`, capped by `listMax`. In whole units that is
69
+ * `L · 10^(base − 6)`: the quote's decimals cancel and the base's set it — harmless on an
70
+ * 18-dec base, but a WBTC book of 1,000 USDC of depth stops at 100,000. Omit `lActive` for the
71
+ * wall alone.
72
+ *
73
+ * Floats, for display and warnings; the chain is the authority.
74
+ */
75
+ export declare function cPriceRange(baseDecimals: number, quoteDecimals: number, lActive?: bigint): {
76
+ listMin: number;
77
+ listMax: number;
78
+ ceiling: number;
79
+ };
80
+ /** Whether a C market can be initialized at `price` (human units) for this pair's decimals. */
81
+ export declare function cListable(price: number, baseDecimals: number, quoteDecimals: number): boolean;
56
82
  /**
57
83
  * The model-free LP edge, $F - \tfrac12\Sigma$ — the protocol's headline metric, in quote per unit
58
84
  * of exposure.
package/dist/pools.js CHANGED
@@ -55,6 +55,37 @@ export function priceOf(state, scale = 1) {
55
55
  export function priceScale(baseDecimals, quoteDecimals) {
56
56
  return 10 ** (baseDecimals - quoteDecimals);
57
57
  }
58
+ /** The C manager's log-price wall: |x| ≤ 46 on the WEI ratio (`MAX_ABS_FLOOR`). */
59
+ export const C_MAX_ABS_X = 46;
60
+ /** The least derived base reserve a C book keeps, in base wei (`MIN_RESERVE`, decisions 023). */
61
+ export const C_MIN_RESERVE = 10n ** 6n;
62
+ /**
63
+ * The prices a C market can hold, in human units — quote per whole base token (decisions 054).
64
+ *
65
+ * - `listMin`, `listMax`: the wall, `10^(base − quote) · e^{∓46}`. A market cannot be initialized,
66
+ * and no floor or cap placed, outside it. An 18-dec token against 6-dec USDC cannot list under
67
+ * 1.05e-8; against an 18-dec quote the same token lists down to 1.05e-20.
68
+ * - `ceiling`: the highest price the book can trade to with `lActive` of active exposure (quote
69
+ * wei): the derived reserve `lActive / p` must stay at or above `C_MIN_RESERVE` base wei, so
70
+ * `ceiling = lActive · 10^(base − quote) / 1e6`, capped by `listMax`. In whole units that is
71
+ * `L · 10^(base − 6)`: the quote's decimals cancel and the base's set it — harmless on an
72
+ * 18-dec base, but a WBTC book of 1,000 USDC of depth stops at 100,000. Omit `lActive` for the
73
+ * wall alone.
74
+ *
75
+ * Floats, for display and warnings; the chain is the authority.
76
+ */
77
+ export function cPriceRange(baseDecimals, quoteDecimals, lActive) {
78
+ const scale = priceScale(baseDecimals, quoteDecimals);
79
+ const listMin = Math.exp(-C_MAX_ABS_X) * scale;
80
+ const listMax = Math.exp(C_MAX_ABS_X) * scale;
81
+ const ceiling = lActive === undefined || lActive === 0n ? listMax : Math.min(listMax, (Number(lActive) / Number(C_MIN_RESERVE)) * scale);
82
+ return { listMin, listMax, ceiling };
83
+ }
84
+ /** Whether a C market can be initialized at `price` (human units) for this pair's decimals. */
85
+ export function cListable(price, baseDecimals, quoteDecimals) {
86
+ const { listMin, listMax } = cPriceRange(baseDecimals, quoteDecimals);
87
+ return price >= listMin && price <= listMax;
88
+ }
58
89
  /**
59
90
  * The model-free LP edge, $F - \tfrac12\Sigma$ — the protocol's headline metric, in quote per unit
60
91
  * of exposure.
package/dist/write.d.ts CHANGED
@@ -59,6 +59,29 @@ export declare function resolveRecipient(c: LogswapClient, o?: WriteOptions): Ad
59
59
  * bound at all because it looks protective.
60
60
  */
61
61
  export declare function withSlippage(quoted: bigint, bps: number, side: "output" | "input"): bigint;
62
+ type AbiError = {
63
+ type: "error";
64
+ name: string;
65
+ inputs: readonly {
66
+ type: string;
67
+ }[];
68
+ };
69
+ /**
70
+ * Every custom error a router call can revert with that the router's own ABI does not declare: the
71
+ * C and F managers' (a mint, a swap or a settlement bubbles them up unchanged) and Permit2's.
72
+ * Without them viem can name only the router's errors, and anything raised in the manager comes
73
+ * back as a bare selector.
74
+ */
75
+ export declare const routerRevertErrors: readonly AbiError[];
76
+ /** `abi` plus every error in {@link routerRevertErrors} it does not already declare. */
77
+ export declare function withRevertErrors(abi: readonly unknown[]): readonly unknown[];
78
+ /**
79
+ * The decoded revert of a contract call, e.g. `SlippageIn()` or `AllowanceExpired(1700000000)`,
80
+ * found however deep viem nested it; the raw selector when the error is not in the ABI; undefined
81
+ * when the failure was not a revert. viem's `message` puts the name on its second line, so a UI
82
+ * that shows only the first line ("The contract function … reverted.") loses it.
83
+ */
84
+ export declare function revertName(e: unknown): string | undefined;
62
85
  /**
63
86
  * Send a router write with a gas buffer over an explicit estimate.
64
87
  *
@@ -104,3 +127,4 @@ export declare function sendRouterWriteWithPermits(c: LogswapClient, args: {
104
127
  args: readonly unknown[];
105
128
  bufferPct?: bigint;
106
129
  }, pullTokens: Address[]): Promise<Hash>;
130
+ export {};
package/dist/write.js CHANGED
@@ -12,6 +12,7 @@
12
12
  * raw `minOut`/`maxIn` the contract wants. `withSlippage()` derives one from a quote when that is
13
13
  * what you have — but the bound is what ships.
14
14
  */
15
+ import { cPoolManagerAbi, fPoolManagerAbi } from "./generated.js";
15
16
  /** Disables the deadline check. Deliberate opt-out, never a default. */
16
17
  export const NEVER = (1n << 256n) - 1n;
17
18
  /** Default deadline window: 20 minutes, the same order as every major DEX front end. */
@@ -70,6 +71,59 @@ export function withSlippage(quoted, bps, side) {
70
71
  // an input bound rounds UP: flooring it would put a wei-exact quote at bps = 0 one wei short
71
72
  return side === "output" ? (quoted * (10000n - b)) / 10000n : (quoted * (10000n + b) + 9999n) / 10000n;
72
73
  }
74
+ /** Permit2's pull errors — Uniswap's and the devnet mock's — which a router write can revert with. */
75
+ const permit2Errors = [
76
+ { type: "error", name: "AllowanceExpired", inputs: [{ type: "uint256" }] },
77
+ { type: "error", name: "InsufficientAllowance", inputs: [{ type: "uint256" }] },
78
+ { type: "error", name: "AllowanceExpired", inputs: [] },
79
+ { type: "error", name: "NotAllowed", inputs: [] },
80
+ ];
81
+ const errorKey = (e) => `${e.name}(${e.inputs.map((i) => i.type).join(",")})`;
82
+ /**
83
+ * Every custom error a router call can revert with that the router's own ABI does not declare: the
84
+ * C and F managers' (a mint, a swap or a settlement bubbles them up unchanged) and Permit2's.
85
+ * Without them viem can name only the router's errors, and anything raised in the manager comes
86
+ * back as a bare selector.
87
+ */
88
+ export const routerRevertErrors = (() => {
89
+ const seen = new Set();
90
+ const out = [];
91
+ for (const x of [...cPoolManagerAbi, ...fPoolManagerAbi, ...permit2Errors]) {
92
+ if (x.type !== "error")
93
+ continue;
94
+ const e = x;
95
+ if (!seen.has(errorKey(e))) {
96
+ seen.add(errorKey(e));
97
+ out.push(e);
98
+ }
99
+ }
100
+ return out;
101
+ })();
102
+ /** `abi` plus every error in {@link routerRevertErrors} it does not already declare. */
103
+ export function withRevertErrors(abi) {
104
+ const have = new Set(abi.filter((x) => x.type === "error").map((x) => errorKey(x)));
105
+ return [...abi, ...routerRevertErrors.filter((e) => !have.has(errorKey(e)))];
106
+ }
107
+ /**
108
+ * The decoded revert of a contract call, e.g. `SlippageIn()` or `AllowanceExpired(1700000000)`,
109
+ * found however deep viem nested it; the raw selector when the error is not in the ABI; undefined
110
+ * when the failure was not a revert. viem's `message` puts the name on its second line, so a UI
111
+ * that shows only the first line ("The contract function … reverted.") loses it.
112
+ */
113
+ export function revertName(e) {
114
+ const seen = new Set();
115
+ for (let x = e; x && typeof x === "object" && !seen.has(x); x = x.cause) {
116
+ seen.add(x);
117
+ const o = x;
118
+ if (o.name !== "ContractFunctionRevertedError")
119
+ continue;
120
+ if (o.data?.errorName)
121
+ return `${o.data.errorName}(${(o.data.args ?? []).map(String).join(", ")})`;
122
+ if (o.signature)
123
+ return o.signature;
124
+ }
125
+ return undefined;
126
+ }
73
127
  /**
74
128
  * Send a router write with a gas buffer over an explicit estimate.
75
129
  *
@@ -82,7 +136,7 @@ export async function sendRouterWrite(c, args) {
82
136
  const { account } = requireWallet(c);
83
137
  const params = {
84
138
  address: c.addresses.router,
85
- abi: args.abi,
139
+ abi: withRevertErrors(args.abi),
86
140
  functionName: args.functionName,
87
141
  args: args.args,
88
142
  account,
@@ -122,7 +176,7 @@ export async function simulateRouterWrite(c, args) {
122
176
  const account = args.account ?? c.wallet?.account?.address;
123
177
  const { result } = await c.public.simulateContract({
124
178
  address: c.addresses.router,
125
- abi: args.abi,
179
+ abi: withRevertErrors(args.abi),
126
180
  functionName: args.functionName,
127
181
  args: args.args,
128
182
  account,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logswap/sdk",
3
- "version": "0.5.65",
3
+ "version": "0.5.67",
4
4
  "description": "TypeScript SDK for Logswap, the liquidity primitive introducing the logarithmic invariant — typed wrappers over the CPoolManager / FPoolManager / Router / Lens surface.",
5
5
  "license": "GPL-2.0-or-later",
6
6
  "type": "module",
package/src/admin.ts CHANGED
@@ -14,7 +14,7 @@
14
14
  import type { Address, Hash } from "viem";
15
15
  import type { LogswapClient } from "./client.js";
16
16
  import { cPoolManagerAbi, fPoolManagerAbi, padPolicyAbi, polPolicyAbi, policyRegistryAbi, publicPolicyAbi } from "./generated.js";
17
- import { bytes32ToText, fPolicyBaseAbi, fPoolKindOfPolicy, textToBytes32, type FPoolKind } from "./fpool.js";
17
+ import { bytes32ToText, fPolicyBaseAbi, fPoolKeyOfPool, fPoolKindOfPolicy, textToBytes32, type FPoolKey, type FPoolKind } from "./fpool.js";
18
18
 
19
19
  function wallet(c: LogswapClient) {
20
20
  if (!c.wallet) throw new Error("a wallet client is required");
@@ -138,13 +138,36 @@ export async function setPolicyApproved(c: LogswapClient, policy: Address, appro
138
138
  }
139
139
 
140
140
  /**
141
- * Move a pool to another approved policy of the same kind: the registry
142
- * owner's alone, orchestrated on the registry — `migrate(manager, poolId, to)`. The new policy
143
- * takes the authority and the name from the old; the operator and the lists void; no swap lands
144
- * in the block.
141
+ * Move a pool to another approved policy of the same kind: the registry owner's alone,
142
+ * orchestrated on the registry — `migrate(manager, key, to)` since F version 20 (it took the
143
+ * pool's id before). The registry checks the key against the manager (`NoPool`), checks the
144
+ * manager is its own (`WrongManager`), and compares the two policies' tags recorded at approval
145
+ * ({@link registryKindOf}). The new policy is brought the creator (the key's), the authority and
146
+ * the name (read off the old policy defensively, the key's creator standing in when it cannot
147
+ * answer); the operator and the lists void; no swap lands in the block.
148
+ *
149
+ * Pass the pool's `key` when in hand. Given only `poolId`, the key is rebuilt from the pool's
150
+ * `FInitialize` log ({@link fPoolKeyOfPool}) with `salt` (zero by default) and checked against
151
+ * the id — the log does not carry the salt, so a salted pool needs it named.
152
+ */
153
+ export async function fPoolMigrate(
154
+ c: LogswapClient,
155
+ a: { to: Address } & ({ key: FPoolKey } | { poolId: `0x${string}`; salt?: `0x${string}`; fromBlock?: bigint }),
156
+ ): Promise<Hash> {
157
+ const key = "key" in a ? a.key : await fPoolKeyOfPool(c, a.poolId, { salt: a.salt, fromBlock: a.fromBlock });
158
+ return registryWrite(c, "migrate", [c.addresses.fPoolManager as Address, key, a.to]);
159
+ }
160
+
161
+ /**
162
+ * The kind tag the registry recorded for `policy` at approval (`kindOf`, F version 20) — refreshed
163
+ * on re-approval and kept after a revoke; what `migrate` compares, never the policy's live
164
+ * answer. "" for a policy the registry never approved (or a deployment with no registry).
145
165
  */
146
- export async function fPoolMigrate(c: LogswapClient, a: { poolId: `0x${string}`; to: Address }): Promise<Hash> {
147
- return registryWrite(c, "migrate", [c.addresses.fPoolManager as Address, a.poolId, a.to]);
166
+ export async function registryKindOf(c: LogswapClient, policy: Address): Promise<FPoolKind | ""> {
167
+ const registry = await policyRegistryOf(c);
168
+ if (registry === ZERO) return "";
169
+ const word = (await c.public.readContract({ address: registry, abi: policyRegistryAbi, functionName: "kindOf", args: [policy] } as never)) as `0x${string}`;
170
+ return bytes32ToText(word) as FPoolKind | "";
148
171
  }
149
172
 
150
173
  // ─── the policies' numbers (the collector's; each bounded where it reaches the manager) ─────
@@ -154,7 +177,7 @@ export async function setHarvestCut(c: LogswapClient, policy: Address, rateWad:
154
177
  return write(c, policy, fPolicyBaseAbi, "setHarvestCut", [rateWad]);
155
178
  }
156
179
 
157
- /** `PadPolicy.setSchedule`: `T(0)`, the rung's growth, the creator's and the protocol's shares of the pot (≤ `POT_CUT_MAX`), the burn per rung (≤ `BURN_MAX`). */
180
+ /** `PadPolicy.setSchedule`: `T(0)`, the rung's growth, the creator's and the protocol's shares of the pot (≤ `POT_CUT_MAX`), the burn per rung (≤ `BURN_MAX`). The rung is the pool's generation since F version 21. */
158
181
  export async function padSetSchedule(
159
182
  c: LogswapClient,
160
183
  policy: Address,