@logswap/sdk 0.5.102 → 0.5.104

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 (64) hide show
  1. package/README.md +14 -418
  2. package/dist/actions.d.ts +0 -39
  3. package/dist/actions.js +0 -39
  4. package/dist/admin.d.ts +0 -106
  5. package/dist/admin.js +1 -96
  6. package/dist/chains.d.ts +0 -49
  7. package/dist/chains.js +0 -30
  8. package/dist/claims.d.ts +0 -32
  9. package/dist/claims.js +0 -30
  10. package/dist/client.d.ts +0 -116
  11. package/dist/client.js +1 -231
  12. package/dist/fees.d.ts +1 -45
  13. package/dist/fees.js +0 -44
  14. package/dist/fpool.d.ts +4 -612
  15. package/dist/fpool.js +14 -490
  16. package/dist/generated.js +0 -30
  17. package/dist/history.d.ts +0 -61
  18. package/dist/history.js +5 -74
  19. package/dist/ids.d.ts +0 -30
  20. package/dist/ids.js +0 -31
  21. package/dist/index.d.ts +0 -7
  22. package/dist/index.js +0 -7
  23. package/dist/indexer.d.ts +0 -68
  24. package/dist/indexer.js +1 -77
  25. package/dist/keys.d.ts +0 -50
  26. package/dist/keys.js +0 -35
  27. package/dist/liquidity.d.ts +0 -128
  28. package/dist/liquidity.js +1 -107
  29. package/dist/onboard.d.ts +0 -52
  30. package/dist/onboard.js +1 -59
  31. package/dist/pools.d.ts +3 -157
  32. package/dist/pools.js +1 -164
  33. package/dist/positions.d.ts +0 -102
  34. package/dist/positions.js +1 -90
  35. package/dist/quote.d.ts +0 -14
  36. package/dist/quote.js +0 -14
  37. package/dist/swap.d.ts +0 -31
  38. package/dist/swap.js +5 -37
  39. package/dist/tokencache.d.ts +0 -48
  40. package/dist/tokencache.js +1 -73
  41. package/dist/write.d.ts +1 -87
  42. package/dist/write.js +1 -87
  43. package/package.json +3 -8
  44. package/src/actions.ts +0 -208
  45. package/src/admin.ts +0 -350
  46. package/src/chains.ts +0 -278
  47. package/src/claims.ts +0 -111
  48. package/src/client.ts +0 -436
  49. package/src/fees.ts +0 -138
  50. package/src/fpool.ts +0 -2049
  51. package/src/generated.ts +0 -4345
  52. package/src/history.ts +0 -383
  53. package/src/ids.ts +0 -78
  54. package/src/index.ts +0 -26
  55. package/src/indexer.ts +0 -264
  56. package/src/keys.ts +0 -138
  57. package/src/liquidity.ts +0 -456
  58. package/src/onboard.ts +0 -253
  59. package/src/pools.ts +0 -465
  60. package/src/positions.ts +0 -297
  61. package/src/quote.ts +0 -36
  62. package/src/swap.ts +0 -181
  63. package/src/tokencache.ts +0 -178
  64. package/src/write.ts +0 -236
package/dist/quote.js CHANGED
@@ -1,18 +1,4 @@
1
- /**
2
- * quote.ts — reading a revert-quoter's answer.
3
- *
4
- * Both managers' quoters are the router's (`Router.quoteSwap`, F: decision 049, C: decision 092): the real swap runs
5
- * in the manager's lock and the contract reverts with `QuoteResult(uint256)`. The value is therefore decoded out of the
6
- * revert, not returned. There is no second pricing path to drift from the first.
7
- */
8
1
  import { toFunctionSelector } from "viem";
9
- /**
10
- * `QuoteResult(uint256)` — selector then one word. viem nests the revert data several layers deep
11
- * depending on the transport, so walk for it rather than guessing the shape.
12
- *
13
- * The selector is DERIVED, not written down. A hardcoded one is wrong silently: the decode simply
14
- * never matches and every quote rethrows as if the swap had failed.
15
- */
16
2
  export function findQuoteResult(err) {
17
3
  const SELECTOR = toFunctionSelector("QuoteResult(uint256)");
18
4
  const seen = new Set();
package/dist/swap.d.ts CHANGED
@@ -1,41 +1,23 @@
1
- /**
2
- * swap.ts — trading.
3
- *
4
- * All four shapes go through the router, which is where slippage and deadline live. The manager's
5
- * merged `swap(key, baseSide, amount, limit)` uses a NEGATIVE amount for exact-out; that convention
6
- * is deliberately not exposed here — callers say `swapExactOut`.
7
- */
8
1
  import { type Address, type Hash } from "viem";
9
2
  import { type LogswapClient } from "./client.js";
10
3
  import { type PoolKey } from "./keys.js";
11
4
  import { type WriteOptions } from "./write.js";
12
- /**
13
- * Quote an exact-in swap. Exact, not approximate — the router runs the real swap and reverts with the result, so
14
- * what it returns is what execution returns, bit for bit (including the dynamic fee, even across a block boundary
15
- * with the variance fold pending).
16
- */
17
5
  export declare function quoteExactIn(c: LogswapClient, key: PoolKey, baseIn: boolean, amountIn: bigint, taker?: Address): Promise<bigint>;
18
- /** Quote an exact-out swap: how much input it will cost. Exact, same mechanism as above. */
19
6
  export declare function quoteExactOut(c: LogswapClient, key: PoolKey, baseOut: boolean, amountOut: bigint, taker?: Address): Promise<bigint>;
20
7
  export interface SwapExactInArgs extends WriteOptions {
21
8
  key: PoolKey;
22
- /** true = base in, quote out (price falls). false = quote in, base out (price rises). */
23
9
  baseIn: boolean;
24
10
  amountIn: bigint;
25
- /** Reverts below this. Derive from a quote with `withSlippage(q, bps, "output")`. */
26
11
  minOut: bigint;
27
12
  }
28
13
  export declare function swapExactIn(c: LogswapClient, a: SwapExactInArgs): Promise<Hash>;
29
14
  export interface SwapExactOutArgs extends WriteOptions {
30
15
  key: PoolKey;
31
- /** true = base out (price rises). false = quote out (price falls). */
32
16
  baseOut: boolean;
33
17
  amountOut: bigint;
34
- /** Reverts above this. Derive from a quote with `withSlippage(q, bps, "input")`. */
35
18
  maxIn: bigint;
36
19
  }
37
20
  export declare function swapExactOut(c: LogswapClient, a: SwapExactOutArgs): Promise<Hash>;
38
- /** One leg of a route. `baseIn` is that hop's direction through its own market. */
39
21
  export interface Hop {
40
22
  key: PoolKey;
41
23
  baseIn: boolean;
@@ -45,22 +27,9 @@ export interface SwapPathArgs extends WriteOptions {
45
27
  amountIn: bigint;
46
28
  minOut: bigint;
47
29
  }
48
- /**
49
- * Multi-hop, all inside ONE lock.
50
- *
51
- * The singleton dividend: deltas accrue per TOKEN across the whole route, so an intermediate asset
52
- * is never actually moved — a three-market route transfers only the tokens at the endpoints. The
53
- * path is not validated on-chain, and it does not need to be: a mis-chained hop leaves a dangling
54
- * delta and the lock refuses to close.
55
- */
56
30
  export declare function swapExactInPath(c: LogswapClient, a: SwapPathArgs): Promise<Hash>;
57
- /**
58
- * Which token a hop takes in and pays out — the check a UI should run before building a route, so
59
- * a mis-chained path fails in the form rather than at the lock.
60
- */
61
31
  export declare function hopTokens(h: Hop): {
62
32
  tokenIn: Address;
63
33
  tokenOut: Address;
64
34
  };
65
- /** True when every hop's output feeds the next hop's input. */
66
35
  export declare function isPathChained(hops: readonly Hop[]): boolean;
package/dist/swap.js CHANGED
@@ -1,22 +1,9 @@
1
- /**
2
- * swap.ts — trading.
3
- *
4
- * All four shapes go through the router, which is where slippage and deadline live. The manager's
5
- * merged `swap(key, baseSide, amount, limit)` uses a NEGATIVE amount for exact-out; that convention
6
- * is deliberately not exposed here — callers say `swapExactOut`.
7
- */
8
1
  import { zeroAddress } from "viem";
9
2
  import { routerCAbi } from "./generated.js";
10
3
  import { routerC } from "./client.js";
11
4
  import { poolId as keyId } from "./keys.js";
12
5
  import { findQuoteResult } from "./quote.js";
13
6
  import { resolveDeadline, resolveRecipient, sendRouterWrite, sendRouterWriteWithPermits } from "./write.js";
14
- /**
15
- * The C quoter (C 14, decision 092): `Router.quoteSwap` runs the real swap in the manager's lock for `taker` and reverts
16
- * with `QuoteResult`, so the answer is decoded out of the revert. `baseSide` says whether the SPECIFIED token is the base.
17
- * The taker matters only on a gated market (the router must then be the taker's ERC-6909 operator, as for the swap):
18
- * the connected account, or the zero address.
19
- */
20
7
  async function quoteSwapC(c, key, exactIn, baseSide, amount, taker) {
21
8
  try {
22
9
  await c.public.simulateContract({
@@ -30,19 +17,13 @@ async function quoteSwapC(c, key, exactIn, baseSide, amount, taker) {
30
17
  const hit = findQuoteResult(err);
31
18
  if (hit !== null)
32
19
  return hit;
33
- throw err; // a real revert — no liquidity, a gate, a bad amount — belongs to the caller
20
+ throw err;
34
21
  }
35
22
  throw new Error("logswap: quoteSwap returned without reverting, which it must never do");
36
23
  }
37
- /**
38
- * Quote an exact-in swap. Exact, not approximate — the router runs the real swap and reverts with the result, so
39
- * what it returns is what execution returns, bit for bit (including the dynamic fee, even across a block boundary
40
- * with the variance fold pending).
41
- */
42
24
  export async function quoteExactIn(c, key, baseIn, amountIn, taker) {
43
25
  return quoteSwapC(c, key, true, baseIn, amountIn, taker);
44
26
  }
45
- /** Quote an exact-out swap: how much input it will cost. Exact, same mechanism as above. */
46
27
  export async function quoteExactOut(c, key, baseOut, amountOut, taker) {
47
28
  return quoteSwapC(c, key, false, baseOut, amountOut, taker);
48
29
  }
@@ -53,8 +34,8 @@ export async function swapExactIn(c, a) {
53
34
  functionName: "swapExactIn",
54
35
  args: [
55
36
  keyId(a.key),
56
- a.baseIn ? a.key.base : a.key.quote, // tokenIn: the router checks the tokens the caller names against the pool's
57
- a.baseIn ? a.key.quote : a.key.base, // tokenOut
37
+ a.baseIn ? a.key.base : a.key.quote,
38
+ a.baseIn ? a.key.quote : a.key.base,
58
39
  a.baseIn,
59
40
  a.amountIn,
60
41
  a.minOut,
@@ -70,8 +51,8 @@ export async function swapExactOut(c, a) {
70
51
  functionName: "swapExactOut",
71
52
  args: [
72
53
  keyId(a.key),
73
- a.baseOut ? a.key.quote : a.key.base, // tokenIn
74
- a.baseOut ? a.key.base : a.key.quote, // tokenOut
54
+ a.baseOut ? a.key.quote : a.key.base,
55
+ a.baseOut ? a.key.base : a.key.quote,
75
56
  a.baseOut,
76
57
  a.amountOut,
77
58
  a.maxIn,
@@ -80,14 +61,6 @@ export async function swapExactOut(c, a) {
80
61
  ],
81
62
  }, [a.baseOut ? a.key.quote : a.key.base]);
82
63
  }
83
- /**
84
- * Multi-hop, all inside ONE lock.
85
- *
86
- * The singleton dividend: deltas accrue per TOKEN across the whole route, so an intermediate asset
87
- * is never actually moved — a three-market route transfers only the tokens at the endpoints. The
88
- * path is not validated on-chain, and it does not need to be: a mis-chained hop leaves a dangling
89
- * delta and the lock refuses to close.
90
- */
91
64
  export async function swapExactInPath(c, a) {
92
65
  if (a.hops.length === 0)
93
66
  throw new Error("logswap: empty path");
@@ -106,16 +79,11 @@ export async function swapExactInPath(c, a) {
106
79
  ],
107
80
  });
108
81
  }
109
- /**
110
- * Which token a hop takes in and pays out — the check a UI should run before building a route, so
111
- * a mis-chained path fails in the form rather than at the lock.
112
- */
113
82
  export function hopTokens(h) {
114
83
  return h.baseIn
115
84
  ? { tokenIn: h.key.base, tokenOut: h.key.quote }
116
85
  : { tokenIn: h.key.quote, tokenOut: h.key.base };
117
86
  }
118
- /** True when every hop's output feeds the next hop's input. */
119
87
  export function isPathChained(hops) {
120
88
  for (let i = 1; i < hops.length; i++) {
121
89
  const prev = hopTokens(hops[i - 1]);
@@ -1,68 +1,20 @@
1
- /**
2
- * tokencache.ts — remember token metadata so it is read once, not once per screen.
3
- *
4
- * `marketTokens` costs four reads per market and every screen calls it. On two markets that is
5
- * free; on fifty it is a hundred round trips on every navigation, over a tunnel.
6
- *
7
- * **A cache over a value that becomes a transaction amount is a way to be wrong, so three rules
8
- * hold here and are enforced by tests:**
9
- *
10
- * 1. **Only successes are stored.** The previous fix made a failed `decimals()` read throw rather
11
- * than assume 18; caching a failure would reintroduce that bug with a longer half-life.
12
- * 2. **The key includes the chain id.** The same address is a different token on a different
13
- * chain — a mock USDC at 18 decimals on a devnet, the real one at 6 on mainnet. Keying on
14
- * address alone is the classic version of this bug and it survives a page reload.
15
- * 3. **A fallback symbol is never stored.** `symbol` degrades to `0x5FbD…` on failure, which is
16
- * fine as a label but must not be persisted — one blip would name the token that forever.
17
- *
18
- * 4. **A resettable chain never reaches the persistent store.** Rule 3's premise is that decimals
19
- * are immutable *for the life of a token*, and the key's premise is that an address names one
20
- * token forever. Both hold on a public chain. Neither holds on a local one: restart anvil and
21
- * the very same deterministic addresses come back holding DIFFERENT contracts. That is not
22
- * hypothetical — a `logswap.token.31337:0x5fbd…` entry saying USDC has 18 decimals outlived the
23
- * deploy that wrote it and made every quote-denominated number in the app read as zero, with
24
- * nothing anywhere reporting a fault. Those chains get the memory store, so a page reload is
25
- * enough to correct them.
26
- *
27
- * Decimals are immutable for the life of a token: ERC-20 exposes no way to change them, and a token
28
- * that did would break every integration, not just this one. That is what makes an unbounded TTL
29
- * correct rather than merely convenient — on a chain whose addresses are permanent.
30
- */
31
1
  import type { Address } from "viem";
32
2
  export interface CachedToken {
33
3
  symbol: string;
34
4
  decimals: number;
35
5
  }
36
- /** Somewhere to keep entries. Sync and tiny on purpose — `localStorage` fits, and so does a Map. */
37
6
  export interface TokenStore {
38
7
  get(key: string): string | null;
39
8
  set(key: string, value: string): void;
40
- /** Drop everything this store owns. Optional: a store that cannot enumerate may omit it. */
41
9
  clear?(): void;
42
10
  }
43
- /** The default: per-process, no persistence. Works in node, workers and a browser alike. */
44
11
  export declare const memoryStore: TokenStore;
45
- /**
46
- * `localStorage`, when there is one. Returns the memory store otherwise, so a caller never has to
47
- * branch on the environment — and a browser in private mode degrades instead of throwing.
48
- */
49
12
  export declare function browserStore(prefix?: string): TokenStore;
50
- /** Swap the backing store. Call once at startup; `browserStore()` is the usual argument. */
51
13
  export declare function setTokenStore(s: TokenStore): void;
52
14
  export declare const RESETTABLE_CHAINS: ReadonlySet<number>;
53
- /** Mark a development chain the registry does not list as resettable. There is no removal. */
54
15
  export declare function addResettableChain(chainId: number): void;
55
- /** True when a `(chainId, address)` pair cannot be trusted to name one contract forever. */
56
16
  export declare function isResettableChain(chainId: number): boolean;
57
17
  export declare function readCachedToken(chainId: number, address: Address): CachedToken | null;
58
18
  export declare function writeCachedToken(chainId: number, address: Address, t: CachedToken): void;
59
- /**
60
- * Forget everything, including reads still in flight.
61
- *
62
- * For tests, and for a devnet that redeployed its mocks to the same addresses — the one case where
63
- * a token at a known address legitimately changes its decimals, because it is a different contract
64
- * wearing the same address.
65
- */
66
19
  export declare function clearTokenCache(): void;
67
- /** Internal: lets `pools.ts` drop its in-flight map when the cache is cleared. */
68
20
  export declare function registerCacheClear(f: () => void): void;
@@ -1,50 +1,15 @@
1
- /**
2
- * tokencache.ts — remember token metadata so it is read once, not once per screen.
3
- *
4
- * `marketTokens` costs four reads per market and every screen calls it. On two markets that is
5
- * free; on fifty it is a hundred round trips on every navigation, over a tunnel.
6
- *
7
- * **A cache over a value that becomes a transaction amount is a way to be wrong, so three rules
8
- * hold here and are enforced by tests:**
9
- *
10
- * 1. **Only successes are stored.** The previous fix made a failed `decimals()` read throw rather
11
- * than assume 18; caching a failure would reintroduce that bug with a longer half-life.
12
- * 2. **The key includes the chain id.** The same address is a different token on a different
13
- * chain — a mock USDC at 18 decimals on a devnet, the real one at 6 on mainnet. Keying on
14
- * address alone is the classic version of this bug and it survives a page reload.
15
- * 3. **A fallback symbol is never stored.** `symbol` degrades to `0x5FbD…` on failure, which is
16
- * fine as a label but must not be persisted — one blip would name the token that forever.
17
- *
18
- * 4. **A resettable chain never reaches the persistent store.** Rule 3's premise is that decimals
19
- * are immutable *for the life of a token*, and the key's premise is that an address names one
20
- * token forever. Both hold on a public chain. Neither holds on a local one: restart anvil and
21
- * the very same deterministic addresses come back holding DIFFERENT contracts. That is not
22
- * hypothetical — a `logswap.token.31337:0x5fbd…` entry saying USDC has 18 decimals outlived the
23
- * deploy that wrote it and made every quote-denominated number in the app read as zero, with
24
- * nothing anywhere reporting a fault. Those chains get the memory store, so a page reload is
25
- * enough to correct them.
26
- *
27
- * Decimals are immutable for the life of a token: ERC-20 exposes no way to change them, and a token
28
- * that did would break every integration, not just this one. That is what makes an unbounded TTL
29
- * correct rather than merely convenient — on a chain whose addresses are permanent.
30
- */
31
1
  import { LOGSWAP_CHAINS } from "./chains.js";
32
2
  const memory = new Map();
33
- /** The default: per-process, no persistence. Works in node, workers and a browser alike. */
34
3
  export const memoryStore = {
35
4
  get: (k) => memory.get(k) ?? null,
36
5
  set: (k, v) => void memory.set(k, v),
37
6
  clear: () => memory.clear(),
38
7
  };
39
- /**
40
- * `localStorage`, when there is one. Returns the memory store otherwise, so a caller never has to
41
- * branch on the environment — and a browser in private mode degrades instead of throwing.
42
- */
43
8
  export function browserStore(prefix = "logswap.token.") {
44
9
  try {
45
10
  if (typeof localStorage === "undefined")
46
11
  return memoryStore;
47
- localStorage.getItem(`${prefix}probe`); // Safari private mode throws on access, not on use
12
+ localStorage.getItem(`${prefix}probe`);
48
13
  return {
49
14
  get: (k) => {
50
15
  try {
@@ -59,10 +24,8 @@ export function browserStore(prefix = "logswap.token.") {
59
24
  localStorage.setItem(prefix + k, v);
60
25
  }
61
26
  catch {
62
- /* quota or private mode — the cache is an optimisation, never a requirement */
63
27
  }
64
28
  },
65
- // Only this prefix, never the whole of localStorage: the app's own keys live there too.
66
29
  clear: () => {
67
30
  try {
68
31
  for (const k of Object.keys(localStorage))
@@ -70,7 +33,6 @@ export function browserStore(prefix = "logswap.token.") {
70
33
  localStorage.removeItem(k);
71
34
  }
72
35
  catch {
73
- /* nothing to do — see set */
74
36
  }
75
37
  },
76
38
  };
@@ -80,39 +42,18 @@ export function browserStore(prefix = "logswap.token.") {
80
42
  }
81
43
  }
82
44
  let store = memoryStore;
83
- /** Swap the backing store. Call once at startup; `browserStore()` is the usual argument. */
84
45
  export function setTokenStore(s) {
85
46
  store = s;
86
47
  }
87
- /** Address casing varies by source, so normalise — otherwise the same token gets two entries. */
88
48
  const keyOf = (chainId, address) => `${chainId}:${address.toLowerCase()}`;
89
- /**
90
- * Chains whose addresses are not permanent identities: a development node can be wiped and
91
- * redeployed, and because deployment addresses are derived from a deterministic nonce sequence the
92
- * SAME address comes back holding a different contract. Every chain the registry flags `devnet`
93
- * (31337 anvil's and hardhat's default, 31339 the logswap devnet), plus 1337 (ganache's and
94
- * hardhat's legacy id) and 31338 (the unimod devnet), persisted with `--state` and documented as
95
- * resettable by deleting that file.
96
- *
97
- * Add to this set rather than removing from it ({@link addResettableChain}): a chain wrongly listed
98
- * here costs some RPC round trips, while one wrongly absent silently serves a stale scale, which is
99
- * the bug this exists for.
100
- */
101
49
  const resettable = new Set([1337, 31338, ...Object.values(LOGSWAP_CHAINS).filter((ch) => ch.devnet).map((ch) => ch.chainId)]);
102
50
  export const RESETTABLE_CHAINS = resettable;
103
- /** Mark a development chain the registry does not list as resettable. There is no removal. */
104
51
  export function addResettableChain(chainId) {
105
52
  resettable.add(chainId);
106
53
  }
107
- /** True when a `(chainId, address)` pair cannot be trusted to name one contract forever. */
108
54
  export function isResettableChain(chainId) {
109
55
  return RESETTABLE_CHAINS.has(chainId);
110
56
  }
111
- /**
112
- * The store an entry for this chain may use. A resettable chain gets memory — good enough to stop
113
- * one navigation re-reading the same token fifty times, and gone on reload, which is exactly the
114
- * lifetime over which its addresses can be trusted.
115
- */
116
57
  const storeFor = (chainId) => (isResettableChain(chainId) ? memoryStore : store);
117
58
  export function readCachedToken(chainId, address) {
118
59
  const raw = storeFor(chainId).get(keyOf(chainId, address));
@@ -120,8 +61,6 @@ export function readCachedToken(chainId, address) {
120
61
  return null;
121
62
  try {
122
63
  const v = JSON.parse(raw);
123
- // Validate on the way OUT as well as in: the store is shared with other tabs and other builds,
124
- // and a corrupt entry must be ignored rather than trusted.
125
64
  if (typeof v?.decimals !== "number" || !Number.isInteger(v.decimals) || v.decimals < 0 || v.decimals > 36) {
126
65
  return null;
127
66
  }
@@ -136,23 +75,12 @@ export function readCachedToken(chainId, address) {
136
75
  export function writeCachedToken(chainId, address, t) {
137
76
  storeFor(chainId).set(keyOf(chainId, address), JSON.stringify({ symbol: t.symbol, decimals: t.decimals }));
138
77
  }
139
- /**
140
- * Forget everything, including reads still in flight.
141
- *
142
- * For tests, and for a devnet that redeployed its mocks to the same addresses — the one case where
143
- * a token at a known address legitimately changes its decimals, because it is a different contract
144
- * wearing the same address.
145
- */
146
78
  export function clearTokenCache() {
147
79
  memory.clear();
148
- // The persistent store too. It did not used to be, which made this function useless against the
149
- // one situation its own doc names: the entry that survives a redeploy lives in `localStorage`,
150
- // so clearing only memory left it in place and the next read served it straight back.
151
80
  store.clear?.();
152
81
  onClear.forEach((f) => f());
153
82
  }
154
83
  const onClear = new Set();
155
- /** Internal: lets `pools.ts` drop its in-flight map when the cache is cleared. */
156
84
  export function registerCacheClear(f) {
157
85
  onClear.add(f);
158
86
  }
package/dist/write.d.ts CHANGED
@@ -1,63 +1,18 @@
1
- /**
2
- * write.ts — shared plumbing for every mutating call.
3
- *
4
- * Two conventions every write helper inherits, so no caller has to remember them:
5
- *
6
- * **Deadlines are mandatory on-chain and defaulted here.** Every mutating router entry carries
7
- * `checkDeadline`. Passing `type(uint256).max` disables it, which is what most SDKs do implicitly
8
- * and is a real hazard for a user whose transaction sits in the mempool through a price move. The
9
- * default is a bounded window; pass `deadline: NEVER` only deliberately.
10
- *
11
- * **Slippage is expressed as a bound, never as a percentage of a stale quote.** Helpers take the
12
- * raw `minOut`/`maxIn` the contract wants. `withSlippage()` derives one from a quote when that is
13
- * what you have — but the bound is what ships.
14
- */
15
1
  import type { Address, Hash, Hex } from "viem";
16
2
  import { type LogswapClient, type Side } from "./client.js";
17
- /** Disables the deadline check. Deliberate opt-out, never a default. */
18
3
  export declare const NEVER: bigint;
19
- /** Default deadline window: 20 minutes, the same order as every major DEX front end. */
20
4
  export declare const DEFAULT_DEADLINE_SECONDS: bigint;
21
5
  export interface WriteOptions {
22
- /** Absolute unix seconds. Defaults to now + {@link DEFAULT_DEADLINE_SECONDS}. */
23
6
  deadline?: bigint;
24
- /** Who receives the output. Defaults to the wallet account. */
25
7
  recipient?: Address;
26
8
  }
27
9
  export declare function resolveDeadline(o: WriteOptions | undefined, now?: number): bigint;
28
- /**
29
- * The wallet's account, as the ACCOUNT OBJECT rather than its address.
30
- *
31
- * This distinction decides how the transaction is signed, and getting it wrong fails in only half
32
- * the cases — which is how it survived a long time here. viem treats a bare `0x…` address as a
33
- * *JSON-RPC account* and calls `eth_sendTransaction`, asking the NODE to sign. That is right for an
34
- * injected wallet and wrong for a local account, which must sign in-process and send
35
- * `eth_sendRawTransaction`.
36
- *
37
- * A dev node holds the keys for its own accounts, so passing an address appears to work right up
38
- * until someone uses a key the node does not have — a bot, a script, CI, or a real user's wallet.
39
- * Passing the object lets viem pick the correct path for both kinds.
40
- */
41
- /**
42
- * The wallet's account OBJECT for a write the caller named by address — see {@link requireWallet}
43
- * for why the object and never the address. The F helpers take `account: Address` in their
44
- * arguments; passed straight to viem it became a JSON-RPC account and the NODE was asked to sign,
45
- * which works only on a dev node holding the key (every agent on the devnet did exactly that).
46
- * A named account that is not the wallet's is refused: nothing else could sign for it.
47
- */
48
10
  export declare function signerFor(c: LogswapClient, address: Address): NonNullable<LogswapClient["wallet"]>["account"];
49
11
  export declare function requireWallet(c: LogswapClient): {
50
12
  account: NonNullable<LogswapClient["wallet"]>["account"];
51
13
  address: Address;
52
14
  };
53
15
  export declare function resolveRecipient(c: LogswapClient, o?: WriteOptions): Address;
54
- /**
55
- * Turn a quoted amount into a slippage bound.
56
- *
57
- * `bps` is basis points of tolerance. Direction matters: an output bound floors, an input bound
58
- * ceilings. Getting that backwards produces a bound that can never bind, which is worse than no
59
- * bound at all because it looks protective.
60
- */
61
16
  export declare function withSlippage(quoted: bigint, bps: number, side: "output" | "input"): bigint;
62
17
  type AbiError = {
63
18
  type: "error";
@@ -66,53 +21,18 @@ type AbiError = {
66
21
  type: string;
67
22
  }[];
68
23
  };
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), the pad policy's
72
- * (a launch's `NoThreshold`, `PadExists`, `OutOfRange`; a graduation's `NotGraduated`) and Permit2's.
73
- * Without them viem can name only the router's errors, and anything raised in the manager comes
74
- * back as a bare selector.
75
- */
76
24
  export declare const routerRevertErrors: readonly AbiError[];
77
- /** `abi` plus every error in {@link routerRevertErrors} it does not already declare. */
78
25
  export declare function withRevertErrors(abi: readonly unknown[]): readonly unknown[];
79
- /**
80
- * The decoded revert of a contract call, e.g. `SlippageIn()` or `AllowanceExpired(1700000000)`,
81
- * found however deep viem nested it; the raw selector when the error is not in the ABI; undefined
82
- * when the failure was not a revert. viem's `message` puts the name on its second line, so a UI
83
- * that shows only the first line ("The contract function … reverted.") loses it.
84
- */
85
26
  export declare function revertName(e: unknown): string | undefined;
86
- /**
87
- * Send a router write with a gas buffer over an explicit estimate.
88
- *
89
- * A swap's gas is path-dependent: how many ticks it crosses depends on the price when it LANDS, not
90
- * when it was estimated, and the variance kernel does more work when a block boundary has passed
91
- * since the last touch. An exact `eth_estimateGas` can therefore OutOfGas one block later. Every
92
- * write goes through here.
93
- */
94
- export declare function sendRouterWrite(c: LogswapClient,
95
- /** `side` picks the router (decision 096: one per manager, each its own Permit2 spender). */
96
- args: {
27
+ export declare function sendRouterWrite(c: LogswapClient, args: {
97
28
  side: Side;
98
29
  abi: readonly unknown[];
99
30
  functionName: string;
100
31
  args: readonly unknown[];
101
32
  bufferPct?: bigint;
102
33
  }): Promise<Hash>;
103
- /**
104
- * Whether an error is the user saying no in their wallet (EIP-1193 code 4001, viem's
105
- * `UserRejectedRequestError`), however deep viem nested it.
106
- */
107
34
  export declare function isUserRejection(e: unknown): boolean;
108
- /**
109
- * The permit signatures are an optimisation: when they cannot be produced (a wallet without
110
- * `signTypedData`, a read that failed) the write goes out plain and relies on a standing
111
- * allowance. A REJECTED signature is not that — it was swallowed too, and the user who had just
112
- * said no was shown a transaction prompt, which then reverted with a Permit2 error that hid why.
113
- */
114
35
  export declare function fallBackUnlessRejected(e: unknown): Hex[];
115
- /** Simulate a router write and return its decoded result, without sending. */
116
36
  export declare function simulateRouterWrite<T>(c: LogswapClient, args: {
117
37
  side: Side;
118
38
  abi: readonly unknown[];
@@ -120,12 +40,6 @@ export declare function simulateRouterWrite<T>(c: LogswapClient, args: {
120
40
  args: readonly unknown[];
121
41
  account?: Address;
122
42
  }): Promise<T>;
123
- /**
124
- * A router write that carries its own Permit2 permissions: missing allowances for `pullTokens`
125
- * are SIGNED (no gas, no extra transaction) and submitted as `applyPermit2` calls in one
126
- * multicall with the action. The 3-transaction mint becomes 1. Falls through to a plain write
127
- * when nothing is missing or Permit2 is not wired.
128
- */
129
43
  export declare function sendRouterWriteWithPermits(c: LogswapClient, args: {
130
44
  side: Side;
131
45
  abi: readonly unknown[];