@lifi/compose-spec 0.6.0 → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +85 -22
- package/dist/index.d.cts +184 -53
- package/dist/index.d.ts +184 -53
- package/dist/index.js +81 -25
- package/package.json +1 -1
- package/src/chainCapabilities.ts +202 -38
- package/src/compile.ts +4 -2
- package/src/continuation.ts +55 -36
- package/src/descriptor.ts +13 -17
- package/src/flow.ts +10 -0
- package/src/index.ts +12 -1
- package/src/materialiserMetadata.ts +6 -0
- package/src/preconditions.ts +4 -0
- package/src/route.ts +51 -20
package/dist/index.d.ts
CHANGED
|
@@ -337,7 +337,7 @@ declare const CallCheckSpecSchema: Schema.Struct<{
|
|
|
337
337
|
comparator: Schema.Literal<["gte", "eq", "lte"]>;
|
|
338
338
|
value: typeof Schema.String;
|
|
339
339
|
}>;
|
|
340
|
-
declare const CheckSchema: Schema.
|
|
340
|
+
declare const CheckSchema: Schema.transformOrFail<Schema.Union<[Schema.Struct<{
|
|
341
341
|
kind: Schema.Literal<["erc20BalanceGte"]>;
|
|
342
342
|
chainId: Schema.filter<Schema.filter<typeof Schema.Number>>;
|
|
343
343
|
token: Schema.filter<typeof Schema.String>;
|
|
@@ -391,7 +391,7 @@ declare const CheckSchema: Schema.transform<Schema.Union<[Schema.Struct<{
|
|
|
391
391
|
readonly to: string;
|
|
392
392
|
readonly calldata: string;
|
|
393
393
|
readonly comparator: "gte" | "eq" | "lte";
|
|
394
|
-
}, never
|
|
394
|
+
}, never>, never>;
|
|
395
395
|
declare const Erc20BalanceDeltaGteSpecSchema: Schema.Struct<{
|
|
396
396
|
kind: Schema.Literal<["erc20BalanceDeltaGte"]>;
|
|
397
397
|
chainId: Schema.filter<Schema.filter<typeof Schema.Number>>;
|
|
@@ -491,7 +491,7 @@ declare const ContinuationPlanSchema: Schema.Struct<{
|
|
|
491
491
|
}]>>>;
|
|
492
492
|
}>>;
|
|
493
493
|
}>;
|
|
494
|
-
check: Schema.
|
|
494
|
+
check: Schema.transformOrFail<Schema.Union<[Schema.Struct<{
|
|
495
495
|
kind: Schema.Literal<["erc20BalanceGte"]>;
|
|
496
496
|
chainId: Schema.filter<Schema.filter<typeof Schema.Number>>;
|
|
497
497
|
token: Schema.filter<typeof Schema.String>;
|
|
@@ -545,7 +545,7 @@ declare const ContinuationPlanSchema: Schema.Struct<{
|
|
|
545
545
|
readonly to: string;
|
|
546
546
|
readonly calldata: string;
|
|
547
547
|
readonly comparator: "gte" | "eq" | "lte";
|
|
548
|
-
}, never
|
|
548
|
+
}, never>, never>;
|
|
549
549
|
validity: Schema.Struct<{
|
|
550
550
|
expiresAtMs: typeof Schema.Number;
|
|
551
551
|
}>;
|
|
@@ -577,7 +577,7 @@ declare const AssertedNativeBalanceGteSpecSchema: Schema.Struct<{
|
|
|
577
577
|
owner: Schema.Union<[Schema.filter<typeof Schema.String>, Schema.Literal<["escrow", "delivery"]>]>;
|
|
578
578
|
minAmount: typeof Schema.String;
|
|
579
579
|
}>;
|
|
580
|
-
declare const AssertedPredicateSchema: Schema.
|
|
580
|
+
declare const AssertedPredicateSchema: Schema.transformOrFail<Schema.Union<[Schema.Struct<{
|
|
581
581
|
kind: Schema.Literal<["erc20BalanceGte"]>;
|
|
582
582
|
chainId: Schema.filter<Schema.filter<typeof Schema.Number>>;
|
|
583
583
|
token: Schema.filter<typeof Schema.String>;
|
|
@@ -664,11 +664,11 @@ declare const AssertedPredicateSchema: Schema.transform<Schema.Union<[Schema.Str
|
|
|
664
664
|
readonly chainId: number;
|
|
665
665
|
readonly minAmount: string;
|
|
666
666
|
readonly owner: string;
|
|
667
|
-
}, never
|
|
667
|
+
}, never>, never>;
|
|
668
668
|
declare const VerificationDescriptorSchema: Schema.Struct<{
|
|
669
669
|
validationProgramHash: Schema.filter<typeof Schema.String>;
|
|
670
670
|
paramsHash: Schema.filter<typeof Schema.String>;
|
|
671
|
-
assertedPredicate: Schema.Array$<Schema.
|
|
671
|
+
assertedPredicate: Schema.Array$<Schema.transformOrFail<Schema.Union<[Schema.Struct<{
|
|
672
672
|
kind: Schema.Literal<["erc20BalanceGte"]>;
|
|
673
673
|
chainId: Schema.filter<Schema.filter<typeof Schema.Number>>;
|
|
674
674
|
token: Schema.filter<typeof Schema.String>;
|
|
@@ -755,7 +755,7 @@ declare const VerificationDescriptorSchema: Schema.Struct<{
|
|
|
755
755
|
readonly chainId: number;
|
|
756
756
|
readonly minAmount: string;
|
|
757
757
|
readonly owner: string;
|
|
758
|
-
}, never
|
|
758
|
+
}, never>, never>>;
|
|
759
759
|
}>;
|
|
760
760
|
declare const canonicalAssertedPredicate: (specs: readonly AssertionSpec[]) => string;
|
|
761
761
|
type VerificationDescriptor = typeof VerificationDescriptorSchema.Type;
|
|
@@ -1958,10 +1958,14 @@ interface FailedPreparedOp {
|
|
|
1958
1958
|
readonly kind: GenericComposeErrorKind;
|
|
1959
1959
|
readonly message: string;
|
|
1960
1960
|
readonly path?: string;
|
|
1961
|
+
readonly port?: string;
|
|
1962
|
+
readonly fix?: string;
|
|
1961
1963
|
}
|
|
1962
1964
|
interface ComposeErrorBase {
|
|
1963
1965
|
readonly message: string;
|
|
1964
1966
|
readonly path?: string;
|
|
1967
|
+
readonly port?: string;
|
|
1968
|
+
readonly fix?: string;
|
|
1965
1969
|
}
|
|
1966
1970
|
interface PreparationComposeError extends ComposeErrorBase {
|
|
1967
1971
|
readonly kind: 'preparation_error';
|
|
@@ -2111,15 +2115,26 @@ declare const refKey: (ref: Ref) => string;
|
|
|
2111
2115
|
* Per-chain native-asset semantics.
|
|
2112
2116
|
*
|
|
2113
2117
|
* Most EVM chains have an ETH-style native gas coin sent via `msg.value` (the
|
|
2114
|
-
* `evm-native` policy). A small number
|
|
2115
|
-
*
|
|
2116
|
-
*
|
|
2117
|
-
*
|
|
2118
|
+
* `evm-native` policy). A small number express their "native" coin as an
|
|
2119
|
+
* ERC-20 token: on `as-erc20` chains (Tempo) no `msg.value` coin exists at
|
|
2120
|
+
* all, while on `native-mirrored-erc20` chains (Arc) a real `msg.value` coin
|
|
2121
|
+
* exists but is canonically routed through an ERC-20 facade that mirrors the
|
|
2122
|
+
* native balance (`balanceOf == native wei / nativeScale`, with no balance
|
|
2123
|
+
* storage of its own). Code that needs to lower or simulate a `Resource` of
|
|
2124
|
+
* kind `"native"` should consult `getChainCapabilities(chainId)` rather than
|
|
2125
|
+
* hardcoding chain IDs.
|
|
2118
2126
|
*
|
|
2119
2127
|
* The compose compiler uses this registry to transparently normalise native
|
|
2120
|
-
* resources into ERC-20 resources on
|
|
2121
|
-
* (see `normalizeResource` below and the `ResourceSchema`
|
|
2122
|
-
* `flowSchema.ts`).
|
|
2128
|
+
* resources into ERC-20 resources on both ERC-20-canonical kinds at
|
|
2129
|
+
* schema-decode time (see `normalizeResource` below and the `ResourceSchema`
|
|
2130
|
+
* transform in `flowSchema.ts`).
|
|
2131
|
+
*
|
|
2132
|
+
* The two ERC-20-canonical kinds behave identically at the resource level —
|
|
2133
|
+
* `hasErc20CanonicalNative` is the predicate for that shared behaviour. They
|
|
2134
|
+
* diverge only at the simulation layer: `as-erc20` balances live in ordinary
|
|
2135
|
+
* token storage, while `native-mirrored-erc20` balances have no storage slot
|
|
2136
|
+
* and are satisfied by a native balance override scaled by `nativeScale`
|
|
2137
|
+
* (see compose-core's `rewritePreconditions`).
|
|
2123
2138
|
*
|
|
2124
2139
|
* This union is the extension point for future native-asset policies. A chain
|
|
2125
2140
|
* with no canonical native asset would get a `reject-native` arm, under which a
|
|
@@ -2133,6 +2148,12 @@ type ChainCapabilities = {
|
|
|
2133
2148
|
readonly kind: 'as-erc20';
|
|
2134
2149
|
readonly chainId: number;
|
|
2135
2150
|
readonly nativeErc20: NativeErc20;
|
|
2151
|
+
} | {
|
|
2152
|
+
readonly kind: 'native-mirrored-erc20';
|
|
2153
|
+
readonly chainId: number;
|
|
2154
|
+
readonly nativeErc20: NativeErc20;
|
|
2155
|
+
/** Native wei per 1 unit of the facade ERC-20 (1e12 on Arc: 18-dec native, 6-dec USDC). */
|
|
2156
|
+
readonly nativeScale: bigint;
|
|
2136
2157
|
};
|
|
2137
2158
|
interface NativeErc20 {
|
|
2138
2159
|
readonly token: `0x${string}`;
|
|
@@ -2151,21 +2172,93 @@ interface NativeErc20 {
|
|
|
2151
2172
|
declare const EVM_NATIVE_SENTINEL: `0x${string}`;
|
|
2152
2173
|
declare const TEMPO_CHAIN_ID = 4217;
|
|
2153
2174
|
declare const TEMPO_NATIVE_ERC20: NativeErc20;
|
|
2175
|
+
declare const ARC_CHAIN_ID = 5042;
|
|
2176
|
+
/**
|
|
2177
|
+
* Arc's native gas coin is USDC (18-decimal wei at the EVM level). The USDC
|
|
2178
|
+
* ERC-20 at this address is a view over native balances: `balanceOf` returns
|
|
2179
|
+
* `native wei / 1e12` and has no balance storage slot; allowances live in
|
|
2180
|
+
* regular storage. The composer interacts with USDC exclusively through this
|
|
2181
|
+
* facade, never via `msg.value`.
|
|
2182
|
+
*/
|
|
2183
|
+
declare const ARC_NATIVE_ERC20: NativeErc20;
|
|
2184
|
+
declare const ARC_NATIVE_SCALE: bigint;
|
|
2154
2185
|
declare const getChainCapabilities: (chainId: number) => ChainCapabilities;
|
|
2186
|
+
/**
|
|
2187
|
+
* Structural fold over the `ChainCapabilities` union — the capabilities
|
|
2188
|
+
* counterpart of `foldResource`/`foldRef`. Dispatches on `kind` and hands each
|
|
2189
|
+
* case its narrowed fields, so consumers that must branch on the native-asset
|
|
2190
|
+
* policy (e.g. compose-core's `rewritePreconditions`) do so through one
|
|
2191
|
+
* combinator whose exhaustiveness the compiler enforces: adding a new arm to
|
|
2192
|
+
* the union above turns every `foldChainCapabilities` call into a type error
|
|
2193
|
+
* until it handles the new case.
|
|
2194
|
+
*/
|
|
2195
|
+
declare const foldChainCapabilities: <R>(caps: ChainCapabilities, cases: {
|
|
2196
|
+
readonly evmNative: (chainId: number) => R;
|
|
2197
|
+
readonly asErc20: (nativeErc20: NativeErc20, chainId: number) => R;
|
|
2198
|
+
readonly nativeMirroredErc20: (nativeErc20: NativeErc20, nativeScale: bigint, chainId: number) => R;
|
|
2199
|
+
}) => R;
|
|
2200
|
+
/**
|
|
2201
|
+
* What a wire-level native-balance check (`nativeBalanceGte`) must become on
|
|
2202
|
+
* a chain, decided once here from the native-asset policy:
|
|
2203
|
+
*
|
|
2204
|
+
* - `keep` — `evm-native`: the native read is the right read.
|
|
2205
|
+
* - `rewrite` — `as-erc20` (Tempo): no `msg.value` coin exists, so the check
|
|
2206
|
+
* becomes an `erc20BalanceGte` of `token`, the stand-in ERC-20. Amounts were
|
|
2207
|
+
* always facade-denominated, so `minAmount` carries over verbatim.
|
|
2208
|
+
* - `reject` — `native-mirrored-erc20` (Arc): a native read returns real
|
|
2209
|
+
* 18-decimal wei, `nativeScale`× the facade's units, so no interpretation of
|
|
2210
|
+
* `minAmount` is safe — reusing it on a facade read is 1e12 too strict for a
|
|
2211
|
+
* wei-denominated check, keeping the native read lets a facade-denominated
|
|
2212
|
+
* check pass 1e12 too easily. The check must be authored as
|
|
2213
|
+
* `erc20BalanceGte` of the facade; `reason` says so.
|
|
2214
|
+
*
|
|
2215
|
+
* Consumers (the `CheckSchema` / `AssertedPredicateSchema` decodes and
|
|
2216
|
+
* compose-core's derive backstop) are adapters over this result, so the unit
|
|
2217
|
+
* rule lives in one place and the fold's exhaustiveness reaches every site.
|
|
2218
|
+
*/
|
|
2219
|
+
type NativeCheckPolicy = {
|
|
2220
|
+
readonly kind: 'keep';
|
|
2221
|
+
} | {
|
|
2222
|
+
readonly kind: 'rewrite';
|
|
2223
|
+
readonly token: `0x${string}`;
|
|
2224
|
+
} | {
|
|
2225
|
+
readonly kind: 'reject';
|
|
2226
|
+
readonly reason: string;
|
|
2227
|
+
};
|
|
2228
|
+
declare const nativeCheckPolicy: (chainId: number) => NativeCheckPolicy;
|
|
2229
|
+
/**
|
|
2230
|
+
* Exact-kind check for `as-erc20` (currently Tempo only) — the rare case that
|
|
2231
|
+
* genuinely means "no `msg.value` coin exists on this chain". Most consumers
|
|
2232
|
+
* want `hasErc20CanonicalNative` instead, which also covers
|
|
2233
|
+
* `native-mirrored-erc20` chains (Arc), where the composer's ERC-20-only
|
|
2234
|
+
* policy applies even though `msg.value` works. Code that must treat the two
|
|
2235
|
+
* ERC-20-native kinds differently goes through `foldChainCapabilities` or
|
|
2236
|
+
* `nativeCheckPolicy`, never a second exact-kind predicate.
|
|
2237
|
+
*/
|
|
2155
2238
|
declare const isAsErc20Chain: (chainId: number) => boolean;
|
|
2239
|
+
/**
|
|
2240
|
+
* Whether the chain's canonical native asset is an ERC-20 — true for both
|
|
2241
|
+
* `as-erc20` chains (Tempo: no `msg.value` coin exists) and
|
|
2242
|
+
* `native-mirrored-erc20` chains (Arc: `msg.value` exists but is never used).
|
|
2243
|
+
* This is the predicate for the shared resource-level behaviour: native
|
|
2244
|
+
* resources are rewritten to the ERC-20, native routing edges are dropped, and
|
|
2245
|
+
* a surviving native resource is a compile error.
|
|
2246
|
+
*/
|
|
2247
|
+
declare const hasErc20CanonicalNative: (chainId: number) => boolean;
|
|
2156
2248
|
/**
|
|
2157
2249
|
* The address that represents the chain's native asset.
|
|
2158
2250
|
*
|
|
2159
|
-
* On EVM-native chains this is the zero-address sentinel `0x0…0`. On
|
|
2160
|
-
*
|
|
2251
|
+
* On EVM-native chains this is the zero-address sentinel `0x0…0`. On chains
|
|
2252
|
+
* whose canonical native asset is an ERC-20 it is the chain's stand-in token
|
|
2253
|
+
* (PathUSD on Tempo, the USDC facade on Arc).
|
|
2161
2254
|
*/
|
|
2162
2255
|
declare const canonicalNativeAddress: (chainId: number) => `0x${string}`;
|
|
2163
2256
|
/**
|
|
2164
2257
|
* Whether `address` represents the native asset of `chainId`.
|
|
2165
2258
|
*
|
|
2166
2259
|
* On EVM-native chains, this is the case-insensitive zero-address check. On
|
|
2167
|
-
*
|
|
2168
|
-
* chain's stand-in ERC-20 address matches.
|
|
2260
|
+
* chains whose canonical native asset is an ERC-20, the literal zero address
|
|
2261
|
+
* returns `false` — only the chain's stand-in ERC-20 address matches.
|
|
2169
2262
|
*/
|
|
2170
2263
|
declare const isNativeAddressForChain: (chainId: number, address: string) => boolean;
|
|
2171
2264
|
/**
|
|
@@ -2175,28 +2268,30 @@ declare const isNativeAddressForChain: (chainId: number, address: string) => boo
|
|
|
2175
2268
|
* This is the single predicate that gates `msg.value` semantics — choosing a
|
|
2176
2269
|
* `NativeBalance` over an `Erc20Balance` simulation requirement, and skipping
|
|
2177
2270
|
* the ERC-20 approval a native input would otherwise need. It returns `false`
|
|
2178
|
-
* for every address on
|
|
2179
|
-
*
|
|
2180
|
-
* never `msg.value
|
|
2181
|
-
*
|
|
2182
|
-
*
|
|
2183
|
-
*
|
|
2184
|
-
* `
|
|
2271
|
+
* for every address on a chain whose canonical native asset is an ERC-20
|
|
2272
|
+
* (including the zero sentinel): on `as-erc20` chains the "native" coin is a
|
|
2273
|
+
* real ERC-20 moved via `transferFrom`, never `msg.value`, and on
|
|
2274
|
+
* `native-mirrored-erc20` chains `msg.value` works but the composer's policy
|
|
2275
|
+
* is to move the coin exclusively through the ERC-20 facade. Use this rather
|
|
2276
|
+
* than re-deriving the check at call sites, and rather than
|
|
2277
|
+
* `isNativeAddressForChain`, which returns `true` for the stand-in ERC-20
|
|
2278
|
+
* (PathUSD on Tempo) and would wrongly route it to `msg.value`.
|
|
2185
2279
|
*/
|
|
2186
2280
|
declare const isMsgValueNative: (chainId: number, address: string) => boolean;
|
|
2187
2281
|
/**
|
|
2188
2282
|
* Rewrite a single `Resource` according to its chain's capabilities.
|
|
2189
2283
|
*
|
|
2190
2284
|
* On chains with the default `evm-native` policy, every resource is returned
|
|
2191
|
-
* unchanged. On
|
|
2192
|
-
* resource of kind `"native"` is
|
|
2193
|
-
* resource pointing at the chain's
|
|
2285
|
+
* unchanged. On chains whose canonical native asset is an ERC-20 (`as-erc20`
|
|
2286
|
+
* Tempo, `native-mirrored-erc20` Arc), a resource of kind `"native"` is
|
|
2287
|
+
* rewritten into the equivalent ERC-20 resource pointing at the chain's
|
|
2288
|
+
* stand-in token (PathUSD on Tempo, the USDC facade on Arc).
|
|
2194
2289
|
*
|
|
2195
2290
|
* This is the rewrite primitive behind the `ResourceSchema` decode transform
|
|
2196
2291
|
* (see `flowSchema.ts`), which is THE chokepoint: it runs every time a
|
|
2197
2292
|
* `Resource` is parsed — flow inputs via `FlowSchema`, op configs via
|
|
2198
2293
|
* `decodeConfig` — so every downstream pass (`normalizeFlow`, `resolve`,
|
|
2199
|
-
* `lower`, `simulate`) sees only ERC-20 resources on
|
|
2294
|
+
* `lower`, `simulate`) sees only ERC-20 resources on those chains.
|
|
2200
2295
|
*
|
|
2201
2296
|
* The function preserves referential identity when nothing changes (returns the
|
|
2202
2297
|
* input `r` unchanged on evm-native chains and for ERC-20 resources) and is
|
|
@@ -2206,8 +2301,8 @@ declare const normalizeResource: (r: Resource) => Resource;
|
|
|
2206
2301
|
/**
|
|
2207
2302
|
* Address-level counterpart of `normalizeResource` for wire fields that carry a
|
|
2208
2303
|
* native asset as a bare token string (a continuation outcome's `token`). On
|
|
2209
|
-
*
|
|
2210
|
-
* ERC-20; every other address passes through.
|
|
2304
|
+
* chains whose canonical native asset is an ERC-20, the native sentinel is
|
|
2305
|
+
* rewritten to the chain's stand-in ERC-20; every other address passes through.
|
|
2211
2306
|
*/
|
|
2212
2307
|
declare const normalizeNativeTokenAddress: (token: string, chainId: number) => string;
|
|
2213
2308
|
|
|
@@ -2217,18 +2312,21 @@ declare const normalizeNativeTokenAddress: (token: string, chainId: number) => s
|
|
|
2217
2312
|
* format is always a decimal string, which the SDK serialises for you.
|
|
2218
2313
|
*
|
|
2219
2314
|
* `/compose/route` trades authoring power for brevity. Instead of a full flow
|
|
2220
|
-
* document it takes a single from/to token pair; the server
|
|
2221
|
-
*
|
|
2222
|
-
* through the same compile pipeline as `POST /compose`.
|
|
2223
|
-
*
|
|
2224
|
-
* set
|
|
2225
|
-
*
|
|
2226
|
-
*
|
|
2227
|
-
*
|
|
2228
|
-
*
|
|
2229
|
-
*
|
|
2230
|
-
*
|
|
2231
|
-
* the
|
|
2315
|
+
* document it takes a single from/to token pair; the server plans a route for
|
|
2316
|
+
* that pair, builds the flow with a `directDeposit` input on the caller's
|
|
2317
|
+
* behalf, and runs it through the same compile pipeline as `POST /compose`.
|
|
2318
|
+
* The route is the shortest admissible chain of routing-catalog edges up to an
|
|
2319
|
+
* operator-set hop ceiling, and may begin with an aggregator swap when the
|
|
2320
|
+
* catalog alone cannot connect the pair. Terminal hops route through
|
|
2321
|
+
* `lifi.zap`, or `lifi.zapAsync` when the pair is reachable only
|
|
2322
|
+
* asynchronously and the request set `allowAsyncRoutes`. The route itself is
|
|
2323
|
+
* not disclosed: node ids are `hop0`, `hop1`, … with the terminal always
|
|
2324
|
+
* `zap`, so `outputs['zap.amountOut']` is the terminal output at every route
|
|
2325
|
+
* length and intermediate outputs carry `role: 'consumed'`. Its response body
|
|
2326
|
+
* is byte-identical to that of `POST /compose` — the enveloped
|
|
2327
|
+
* `ComposeCompileSuccessData` on HTTP 200 and `ComposeCompilePartialData` on
|
|
2328
|
+
* HTTP 206 — so this file declares only the request shape and reuses
|
|
2329
|
+
* `ComposeCompileResult` from `./compile.js` for the result.
|
|
2232
2330
|
*
|
|
2233
2331
|
* These are the single source of truth for the request shape, hand-authored
|
|
2234
2332
|
* here for the same reason as `./compile.ts` and `./simulate.ts` rather than
|
|
@@ -2267,6 +2365,15 @@ interface RouteAmountExact {
|
|
|
2267
2365
|
* arrives via `msg.value`, so there is no on-chain balance to sweep, and the
|
|
2268
2366
|
* server rejects the combination with a `validation_error`. Use
|
|
2269
2367
|
* {@link RouteAmountExact} for native inputs.
|
|
2368
|
+
*
|
|
2369
|
+
* On a route that begins with an aggregator swap the swap's input amount is
|
|
2370
|
+
* pinned to the quoted amount derived from `simAmount` (net of any input fee
|
|
2371
|
+
* when fee injection applies): a runtime balance below that pinned amount
|
|
2372
|
+
* reverts, and a balance above it leaves the remainder as `unspentIn`, which
|
|
2373
|
+
* may be most of the input and which `sweepTo` receives. Under `EXACT` the
|
|
2374
|
+
* deposit and the pinned quote are the same number, so the `unspentIn` output
|
|
2375
|
+
* is zero and omitted; any pre-existing dust of the sold token in the proxy is
|
|
2376
|
+
* moved to `sweepTo` by the whole-balance sweep independently of that output.
|
|
2270
2377
|
*/
|
|
2271
2378
|
interface RouteAmountAll {
|
|
2272
2379
|
readonly type: 'ALL';
|
|
@@ -2293,13 +2400,18 @@ interface ComposeRouteRequest {
|
|
|
2293
2400
|
/** Address that funds the route and, by default, owns its output. */
|
|
2294
2401
|
readonly signer: string;
|
|
2295
2402
|
/**
|
|
2296
|
-
* Slippage tolerance in basis points
|
|
2297
|
-
*
|
|
2403
|
+
* Slippage tolerance in basis points. Range 0–10000. Defaults to `100` (1%)
|
|
2404
|
+
* server-side when omitted. It is an end-to-end tolerance: the floor is the
|
|
2405
|
+
* simulated final output of the whole route, so a multi-hop route is not
|
|
2406
|
+
* bounded hop by hop. When the route begins with an aggregator swap the same
|
|
2407
|
+
* value is also the swap's own tolerance, which nests inside the end-to-end
|
|
2408
|
+
* floor rather than compounding with it.
|
|
2298
2409
|
*/
|
|
2299
2410
|
readonly slippageBps?: number;
|
|
2300
2411
|
/**
|
|
2301
2412
|
* Reject the route when its quoted price impact exceeds this many basis
|
|
2302
|
-
* points. Range 0–10000. Omitted ⇒
|
|
2413
|
+
* points. Range 0–10000. Omitted ⇒ the server's default of 500 bps applies;
|
|
2414
|
+
* `0` disables the check.
|
|
2303
2415
|
*/
|
|
2304
2416
|
readonly maxPriceImpactBps?: number;
|
|
2305
2417
|
/**
|
|
@@ -2311,11 +2423,20 @@ interface ComposeRouteRequest {
|
|
|
2311
2423
|
/** Opaque referrer tag forwarded to the underlying quote provider. */
|
|
2312
2424
|
readonly referrer?: string;
|
|
2313
2425
|
/**
|
|
2314
|
-
* Owner of the route
|
|
2315
|
-
*
|
|
2316
|
-
* `GET /compose/zap-packs`)
|
|
2317
|
-
*
|
|
2318
|
-
*
|
|
2426
|
+
* Owner of every asset the route leaves behind; defaults to `signer` on a
|
|
2427
|
+
* route with no aggregator swap. Routes whose protocol mints to a named
|
|
2428
|
+
* receiver (surfaced as `recipient: 'required'` by `GET /compose/zap-packs`)
|
|
2429
|
+
* and asynchronous routes bind this address at mint time rather than
|
|
2430
|
+
* transferring afterwards; otherwise the proxy's whole balance of each
|
|
2431
|
+
* asset the route leaves is transferred here.
|
|
2432
|
+
*
|
|
2433
|
+
* **Required when the route includes an aggregator swap.** Such a route can
|
|
2434
|
+
* leave an asset the caller did not plan for — the swap's unspent input —
|
|
2435
|
+
* and this address receives it alongside the terminal output, so it must be
|
|
2436
|
+
* named explicitly; omitting it fails with `validation_error`.
|
|
2437
|
+
*
|
|
2438
|
+
* Accepts an address or `{ $ref: 'context.sender' }` (which counts as
|
|
2439
|
+
* explicit); `{ $ref: 'context.executionAddress' }` is rejected.
|
|
2319
2440
|
*/
|
|
2320
2441
|
readonly sweepTo?: SweepTo;
|
|
2321
2442
|
/**
|
|
@@ -2342,6 +2463,11 @@ interface ComposeRouteRequest {
|
|
|
2342
2463
|
* opt-in. Defaults to `false` server-side, which leaves a pair reachable
|
|
2343
2464
|
* only asynchronously rejected with `no_route_error` and guarantees every
|
|
2344
2465
|
* terminal output is `delivery.when: 'now'`.
|
|
2466
|
+
*
|
|
2467
|
+
* It widens reach, it is not a preference: a synchronous route wins at any
|
|
2468
|
+
* length, so a pair with both a one-hop asynchronous edge and a longer
|
|
2469
|
+
* synchronous route is served synchronously. Opting in never costs you a
|
|
2470
|
+
* synchronous route.
|
|
2345
2471
|
*/
|
|
2346
2472
|
readonly allowAsyncRoutes?: boolean;
|
|
2347
2473
|
}
|
|
@@ -2376,6 +2502,7 @@ type Erc20AllowancePrecondition = {
|
|
|
2376
2502
|
declare const erc20Balance: (config: Omit<Erc20BalancePrecondition, "type">) => Erc20BalancePrecondition;
|
|
2377
2503
|
declare const nativeBalance: (config: Omit<NativeBalancePrecondition, "type">) => NativeBalancePrecondition;
|
|
2378
2504
|
declare const erc20Allowance: (config: Omit<Erc20AllowancePrecondition, "type">) => Erc20AllowancePrecondition;
|
|
2505
|
+
declare const isErc20BalancePrecondition: (p: Precondition) => p is Erc20BalancePrecondition;
|
|
2379
2506
|
declare const isErc20AllowancePrecondition: (p: Precondition) => p is Erc20AllowancePrecondition;
|
|
2380
2507
|
declare const isNativeBalancePrecondition: (p: Precondition) => p is NativeBalancePrecondition;
|
|
2381
2508
|
|
|
@@ -2591,6 +2718,9 @@ type MaterialiserMetadata = {
|
|
|
2591
2718
|
} | {
|
|
2592
2719
|
readonly kind: 'exact-native';
|
|
2593
2720
|
readonly amount: bigint;
|
|
2721
|
+
} | {
|
|
2722
|
+
readonly kind: 'capped';
|
|
2723
|
+
readonly amount: bigint;
|
|
2594
2724
|
} | {
|
|
2595
2725
|
readonly kind: 'runtime';
|
|
2596
2726
|
};
|
|
@@ -2601,7 +2731,8 @@ interface MaterialiserResolution {
|
|
|
2601
2731
|
declare const foldMaterialiserMetadata: <R>(meta: MaterialiserMetadata, cases: {
|
|
2602
2732
|
readonly exact: (amount: bigint) => R;
|
|
2603
2733
|
readonly exactNative: (amount: bigint) => R;
|
|
2734
|
+
readonly capped: (amount: bigint) => R;
|
|
2604
2735
|
readonly runtime: () => R;
|
|
2605
2736
|
}) => R;
|
|
2606
2737
|
|
|
2607
|
-
export { type Amount, type AppliedGuard, AppliedGuardSchema, type ApprovalEntry, AssertedErc20BalanceGteSpecSchema, AssertedNativeBalanceGteSpecSchema, type AssertedPredicate, AssertedPredicateSchema, type AssertedPredicateWire, AssertedPredicateZod, type AssertionOwner, AssertionOwnerSchema, type AssertionSpec, AssertionSpecSchema, type AssertionSpecWire, AssertionSpecZod, type Availability, type BindValue, BindValueSchema, Bytes32HexSchema, COMPOSER_SDK_VERSION_HEADER, COMPOSE_VERSION_HEADER, CONTINUATION_COMMITMENT_OP_ID, type Call, CallCheckSpecSchema, CallSchema, type ChainCapabilities, type Check, type CheckComparator, CheckSchema, CheckZod, type ComposeAction, type ComposeCompilePartialData, type ComposeCompileRequest, type ComposeCompileResult, type ComposeCompileSuccessData, type ComposeError, type ComposeErrorKind, type ComposeFee, type ComposeFill, type ComposeManifest, ComposeManifestZod, type ComposeRouteErrorKind, type ComposeRouteRequest, type ComposeRun, type ComposeTransactionRequest, type ComposeUserProgramSimulation, type ComposeVersion, type ConsumedOutput, type ContextKey, type ContinuationIntent, ContinuationIntentSchema, type ContinuationOutcome, ContinuationOutcomeSchema, type ContinuationPlan, ContinuationPlanSchema, type ContinuationPlanWire, ContinuationPlanZod, type Delivery, EVM_NATIVE_SENTINEL, type Erc20AllowancePrecondition, type Erc20AllowanceRequirement, Erc20BalanceDeltaGteSpecSchema, Erc20BalanceGteSpecSchema, type Erc20BalancePrecondition, type Erc20BalanceRequirement, type Estimate, type EstimateBasis, type FailedPreparedOp, type FlashloanMaterialiserInput, type Flow, type FlowInput, FlowInputSchema, FlowSchema, type GenericComposeError, type GenericComposeErrorKind, type GuardCompatibility, GuardCompatibilityZod, type GuardSelector, GuardSelectorZod, HANDLE_UNITS, type HandleInput, HandleInputSchema, type HandlePort, HandlePortZod, type HandleUnits, HandleUnitsZod, HexStringSchema, InputPortZod, type InputSpec, type LiteralBinding, LiteralBindingSchema, type ManifestGuard, ManifestGuardZod, type ManifestMaterialiser, ManifestMaterialiserZod, type ManifestOperation, ManifestOperationZod, type ManifestPrecondition, ManifestPreconditionZod, type MaterialiserConfigOf, type MaterialiserInput, type MaterialiserInputBase, type MaterialiserInputOf, type MaterialiserMetadata, type MaterialiserResolution, type Minimum, type MinimumBasis, NativeBalanceDeltaGteSpecSchema, NativeBalanceGteSpecSchema, type NativeBalancePrecondition, type NativeBalanceRequirement, type NativeErc20, type OpInputPort, type OpOutputPort, type Output, type OutputAmount, OutputPortZod, type Outputs, PROVIDER_KIND, type ParsedRef, type Phase1Artifact, Phase1ArtifactSchema, type Phase1ArtifactWire, Phase1ArtifactZod, type Port, type Precondition, type PreconditionBase, type PreconditionConfigOf, type PreconditionOf, type PreparationComposeError, type PriceImpact, type ProviderKindName, RESERVED_REF_SCOPES, type Ref, type RefBuilder, type RefPath, RefSchema, type RefScope, type Resource, type ResourceInput, ResourceInputSchema, type ResourceOutputPort, ResourceOutputPortZod, type ResourcePort, ResourcePortZod, ResourceSchema, type RouteAmount, type RouteAmountAll, type RouteAmountExact, SIMULATE_MAX_REQUIREMENTS, SIMULATE_MAX_TRACKED_BALANCES, STATIC_SOL_TYPES, type SimulateBalanceEntry, type SimulateOkResult, type SimulateRequest, type SimulateResult, type SimulateRevertDecodeResult, type SimulateRevertResult, type SimulateSetupErrorResult, type SimulationPolicy, type SimulationRevert, type SimulationRevertComposeError, type SlotFinderRequirement, type SolType, SolTypeSchema, type SpendEntry, type StaticSolType, StaticSolTypeZod, type SweepTo, TEMPO_CHAIN_ID, TEMPO_NATIVE_ERC20, type TerminalOutput, type TrackedBalance, type VerificationDescriptor, VerificationDescriptorSchema, type VerificationDescriptorWire, VerificationDescriptorZod, type VersionCompatibility, canonicalAssertedPredicate, canonicalNativeAddress, checkCompatibility, copy, erc20, erc20Allowance, erc20Balance, erc20Resource, erc20Token, flowInputMode, flowInputResource, flowInputType, foldMaterialiserMetadata, foldRef, foldResource, getChainCapabilities, handle, isAsErc20Chain, isContextKey, isEQCheck, isERC20Resource, isErc20AllowancePrecondition, isFutureResourceOutput, isGTECheck, isHandlePort, isLTECheck, isMaterialiserInput, isMsgValueNative, isNativeAddressForChain, isNativeBalancePrecondition, isNativeResource, isRef, isResourceInput, isResourceOutputPort, isResourcePort, isStaticSolType, linear, native, nativeBalance, nativeResource, normalizeNativeTokenAddress, normalizeResource, opHandle, parseRef, parseVersion, providerKindByName, providerKindNames, readResource, ref, refKey, resource, resourceKey, resourceOutput, resourceToken, resourcesEqual, settledOutcome };
|
|
2738
|
+
export { ARC_CHAIN_ID, ARC_NATIVE_ERC20, ARC_NATIVE_SCALE, type Amount, type AppliedGuard, AppliedGuardSchema, type ApprovalEntry, AssertedErc20BalanceGteSpecSchema, AssertedNativeBalanceGteSpecSchema, type AssertedPredicate, AssertedPredicateSchema, type AssertedPredicateWire, AssertedPredicateZod, type AssertionOwner, AssertionOwnerSchema, type AssertionSpec, AssertionSpecSchema, type AssertionSpecWire, AssertionSpecZod, type Availability, type BindValue, BindValueSchema, Bytes32HexSchema, COMPOSER_SDK_VERSION_HEADER, COMPOSE_VERSION_HEADER, CONTINUATION_COMMITMENT_OP_ID, type Call, CallCheckSpecSchema, CallSchema, type ChainCapabilities, type Check, type CheckComparator, CheckSchema, CheckZod, type ComposeAction, type ComposeCompilePartialData, type ComposeCompileRequest, type ComposeCompileResult, type ComposeCompileSuccessData, type ComposeError, type ComposeErrorKind, type ComposeFee, type ComposeFill, type ComposeManifest, ComposeManifestZod, type ComposeRouteErrorKind, type ComposeRouteRequest, type ComposeRun, type ComposeTransactionRequest, type ComposeUserProgramSimulation, type ComposeVersion, type ConsumedOutput, type ContextKey, type ContinuationIntent, ContinuationIntentSchema, type ContinuationOutcome, ContinuationOutcomeSchema, type ContinuationPlan, ContinuationPlanSchema, type ContinuationPlanWire, ContinuationPlanZod, type Delivery, EVM_NATIVE_SENTINEL, type Erc20AllowancePrecondition, type Erc20AllowanceRequirement, Erc20BalanceDeltaGteSpecSchema, Erc20BalanceGteSpecSchema, type Erc20BalancePrecondition, type Erc20BalanceRequirement, type Estimate, type EstimateBasis, type FailedPreparedOp, type FlashloanMaterialiserInput, type Flow, type FlowInput, FlowInputSchema, FlowSchema, type GenericComposeError, type GenericComposeErrorKind, type GuardCompatibility, GuardCompatibilityZod, type GuardSelector, GuardSelectorZod, HANDLE_UNITS, type HandleInput, HandleInputSchema, type HandlePort, HandlePortZod, type HandleUnits, HandleUnitsZod, HexStringSchema, InputPortZod, type InputSpec, type LiteralBinding, LiteralBindingSchema, type ManifestGuard, ManifestGuardZod, type ManifestMaterialiser, ManifestMaterialiserZod, type ManifestOperation, ManifestOperationZod, type ManifestPrecondition, ManifestPreconditionZod, type MaterialiserConfigOf, type MaterialiserInput, type MaterialiserInputBase, type MaterialiserInputOf, type MaterialiserMetadata, type MaterialiserResolution, type Minimum, type MinimumBasis, NativeBalanceDeltaGteSpecSchema, NativeBalanceGteSpecSchema, type NativeBalancePrecondition, type NativeBalanceRequirement, type NativeCheckPolicy, type NativeErc20, type OpInputPort, type OpOutputPort, type Output, type OutputAmount, OutputPortZod, type Outputs, PROVIDER_KIND, type ParsedRef, type Phase1Artifact, Phase1ArtifactSchema, type Phase1ArtifactWire, Phase1ArtifactZod, type Port, type Precondition, type PreconditionBase, type PreconditionConfigOf, type PreconditionOf, type PreparationComposeError, type PriceImpact, type ProviderKindName, RESERVED_REF_SCOPES, type Ref, type RefBuilder, type RefPath, RefSchema, type RefScope, type Resource, type ResourceInput, ResourceInputSchema, type ResourceOutputPort, ResourceOutputPortZod, type ResourcePort, ResourcePortZod, ResourceSchema, type RouteAmount, type RouteAmountAll, type RouteAmountExact, SIMULATE_MAX_REQUIREMENTS, SIMULATE_MAX_TRACKED_BALANCES, STATIC_SOL_TYPES, type SimulateBalanceEntry, type SimulateOkResult, type SimulateRequest, type SimulateResult, type SimulateRevertDecodeResult, type SimulateRevertResult, type SimulateSetupErrorResult, type SimulationPolicy, type SimulationRevert, type SimulationRevertComposeError, type SlotFinderRequirement, type SolType, SolTypeSchema, type SpendEntry, type StaticSolType, StaticSolTypeZod, type SweepTo, TEMPO_CHAIN_ID, TEMPO_NATIVE_ERC20, type TerminalOutput, type TrackedBalance, type VerificationDescriptor, VerificationDescriptorSchema, type VerificationDescriptorWire, VerificationDescriptorZod, type VersionCompatibility, canonicalAssertedPredicate, canonicalNativeAddress, checkCompatibility, copy, erc20, erc20Allowance, erc20Balance, erc20Resource, erc20Token, flowInputMode, flowInputResource, flowInputType, foldChainCapabilities, foldMaterialiserMetadata, foldRef, foldResource, getChainCapabilities, handle, hasErc20CanonicalNative, isAsErc20Chain, isContextKey, isEQCheck, isERC20Resource, isErc20AllowancePrecondition, isErc20BalancePrecondition, isFutureResourceOutput, isGTECheck, isHandlePort, isLTECheck, isMaterialiserInput, isMsgValueNative, isNativeAddressForChain, isNativeBalancePrecondition, isNativeResource, isRef, isResourceInput, isResourceOutputPort, isResourcePort, isStaticSolType, linear, native, nativeBalance, nativeCheckPolicy, nativeResource, normalizeNativeTokenAddress, normalizeResource, opHandle, parseRef, parseVersion, providerKindByName, providerKindNames, readResource, ref, refKey, resource, resourceKey, resourceOutput, resourceToken, resourcesEqual, settledOutcome };
|
package/dist/index.js
CHANGED
|
@@ -13,6 +13,13 @@ var TEMPO_NATIVE_ERC20 = {
|
|
|
13
13
|
symbol: "pathUSD",
|
|
14
14
|
decimals: 6
|
|
15
15
|
};
|
|
16
|
+
var ARC_CHAIN_ID = 5042;
|
|
17
|
+
var ARC_NATIVE_ERC20 = {
|
|
18
|
+
token: "0x3600000000000000000000000000000000000000",
|
|
19
|
+
symbol: "USDC",
|
|
20
|
+
decimals: 6
|
|
21
|
+
};
|
|
22
|
+
var ARC_NATIVE_SCALE = 10n ** BigInt(18 - ARC_NATIVE_ERC20.decimals);
|
|
16
23
|
var REGISTRY = /* @__PURE__ */ new Map([
|
|
17
24
|
[
|
|
18
25
|
TEMPO_CHAIN_ID,
|
|
@@ -21,31 +28,60 @@ var REGISTRY = /* @__PURE__ */ new Map([
|
|
|
21
28
|
chainId: TEMPO_CHAIN_ID,
|
|
22
29
|
nativeErc20: TEMPO_NATIVE_ERC20
|
|
23
30
|
}
|
|
31
|
+
],
|
|
32
|
+
[
|
|
33
|
+
ARC_CHAIN_ID,
|
|
34
|
+
{
|
|
35
|
+
kind: "native-mirrored-erc20",
|
|
36
|
+
chainId: ARC_CHAIN_ID,
|
|
37
|
+
nativeErc20: ARC_NATIVE_ERC20,
|
|
38
|
+
nativeScale: ARC_NATIVE_SCALE
|
|
39
|
+
}
|
|
24
40
|
]
|
|
25
41
|
]);
|
|
26
42
|
var getChainCapabilities = (chainId) => REGISTRY.get(chainId) ?? { kind: "evm-native", chainId };
|
|
27
|
-
var
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
43
|
+
var foldChainCapabilities = (caps, cases) => {
|
|
44
|
+
switch (caps.kind) {
|
|
45
|
+
case "evm-native":
|
|
46
|
+
return cases.evmNative(caps.chainId);
|
|
47
|
+
case "as-erc20":
|
|
48
|
+
return cases.asErc20(caps.nativeErc20, caps.chainId);
|
|
49
|
+
case "native-mirrored-erc20":
|
|
50
|
+
return cases.nativeMirroredErc20(
|
|
51
|
+
caps.nativeErc20,
|
|
52
|
+
caps.nativeScale,
|
|
53
|
+
caps.chainId
|
|
54
|
+
);
|
|
55
|
+
}
|
|
31
56
|
};
|
|
57
|
+
var nativeCheckPolicy = (chainId) => foldChainCapabilities(getChainCapabilities(chainId), {
|
|
58
|
+
evmNative: () => ({ kind: "keep" }),
|
|
59
|
+
asErc20: (nativeErc20) => ({ kind: "rewrite", token: nativeErc20.token }),
|
|
60
|
+
nativeMirroredErc20: (nativeErc20) => ({
|
|
61
|
+
kind: "reject",
|
|
62
|
+
reason: `nativeBalanceGte is not accepted on chain ${chainId}: its canonical native asset is an ERC-20 facade whose units differ from native wei \u2014 author the check as erc20BalanceGte of ${nativeErc20.token}`
|
|
63
|
+
})
|
|
64
|
+
});
|
|
65
|
+
var isAsErc20Chain = (chainId) => getChainCapabilities(chainId).kind === "as-erc20";
|
|
66
|
+
var erc20CanonicalNative = (caps) => caps.kind === "as-erc20" || caps.kind === "native-mirrored-erc20" ? caps.nativeErc20 : void 0;
|
|
67
|
+
var hasErc20CanonicalNative = (chainId) => erc20CanonicalNative(getChainCapabilities(chainId)) !== void 0;
|
|
68
|
+
var canonicalNativeAddress = (chainId) => erc20CanonicalNative(getChainCapabilities(chainId))?.token ?? EVM_NATIVE_SENTINEL;
|
|
32
69
|
var isNativeAddressForChain = (chainId, address) => {
|
|
33
|
-
const
|
|
34
|
-
const target = caps.kind === "as-erc20" ? caps.nativeErc20.token : EVM_NATIVE_SENTINEL;
|
|
70
|
+
const target = canonicalNativeAddress(chainId);
|
|
35
71
|
return address.toLowerCase() === target.toLowerCase();
|
|
36
72
|
};
|
|
37
|
-
var isMsgValueNative = (chainId, address) => !
|
|
73
|
+
var isMsgValueNative = (chainId, address) => !hasErc20CanonicalNative(chainId) && isNativeSentinel(address);
|
|
38
74
|
var normalizeResource = (r) => {
|
|
39
75
|
if (r.kind !== "native") return r;
|
|
40
|
-
const
|
|
41
|
-
if (
|
|
76
|
+
const erc202 = erc20CanonicalNative(getChainCapabilities(r.chainId));
|
|
77
|
+
if (erc202 === void 0) return r;
|
|
42
78
|
return {
|
|
43
79
|
kind: "erc20",
|
|
44
80
|
chainId: r.chainId,
|
|
45
|
-
token:
|
|
81
|
+
token: erc202.token
|
|
46
82
|
};
|
|
47
83
|
};
|
|
48
|
-
var normalizeNativeTokenAddress = (token, chainId) =>
|
|
84
|
+
var normalizeNativeTokenAddress = (token, chainId) => hasErc20CanonicalNative(chainId) && isNativeSentinel(token) ? canonicalNativeAddress(chainId) : token;
|
|
49
85
|
|
|
50
86
|
// src/flowSchema.ts
|
|
51
87
|
var SolTypeSchema = Schema.Literal(
|
|
@@ -135,7 +171,7 @@ var FlowSchema = Schema.Struct({
|
|
|
135
171
|
});
|
|
136
172
|
|
|
137
173
|
// src/continuation.ts
|
|
138
|
-
import { Schema as Schema2 } from "effect";
|
|
174
|
+
import { ParseResult, Schema as Schema2 } from "effect";
|
|
139
175
|
var CONTINUATION_COMMITMENT_OP_ID = "continuation.commitment";
|
|
140
176
|
var RawContinuationOutcomeSchema = Schema2.Struct({
|
|
141
177
|
token: Schema2.String,
|
|
@@ -211,25 +247,36 @@ var CallCheckSpecSchema = Schema2.Struct({
|
|
|
211
247
|
comparator: Schema2.Literal("gte", "eq", "lte"),
|
|
212
248
|
value: Schema2.String
|
|
213
249
|
});
|
|
214
|
-
var asErc20BalanceGteCheck = (
|
|
250
|
+
var asErc20BalanceGteCheck = (check, token) => ({
|
|
215
251
|
kind: "erc20BalanceGte",
|
|
216
|
-
chainId,
|
|
217
|
-
token
|
|
218
|
-
owner,
|
|
219
|
-
minAmount
|
|
220
|
-
});
|
|
252
|
+
chainId: check.chainId,
|
|
253
|
+
token,
|
|
254
|
+
owner: check.owner,
|
|
255
|
+
minAmount: check.minAmount
|
|
256
|
+
});
|
|
257
|
+
var decodeNativeBalanceGte = (check, ast) => {
|
|
258
|
+
const policy = nativeCheckPolicy(check.chainId);
|
|
259
|
+
switch (policy.kind) {
|
|
260
|
+
case "keep":
|
|
261
|
+
return ParseResult.succeed(check);
|
|
262
|
+
case "rewrite":
|
|
263
|
+
return ParseResult.succeed(asErc20BalanceGteCheck(check, policy.token));
|
|
264
|
+
case "reject":
|
|
265
|
+
return ParseResult.fail(new ParseResult.Type(ast, check, policy.reason));
|
|
266
|
+
}
|
|
267
|
+
};
|
|
221
268
|
var RawCheckSchema = Schema2.Union(
|
|
222
269
|
Erc20BalanceGteSpecSchema,
|
|
223
270
|
NativeBalanceGteSpecSchema,
|
|
224
271
|
CallCheckSpecSchema
|
|
225
272
|
);
|
|
226
|
-
var CheckSchema = Schema2.
|
|
273
|
+
var CheckSchema = Schema2.transformOrFail(
|
|
227
274
|
RawCheckSchema,
|
|
228
275
|
Schema2.typeSchema(RawCheckSchema),
|
|
229
276
|
{
|
|
230
277
|
strict: true,
|
|
231
|
-
decode: (check) => check.kind === "nativeBalanceGte"
|
|
232
|
-
encode: (check) => check
|
|
278
|
+
decode: (check, _options, ast) => check.kind === "nativeBalanceGte" ? decodeNativeBalanceGte(check, ast) : ParseResult.succeed(check),
|
|
279
|
+
encode: (check) => ParseResult.succeed(check)
|
|
233
280
|
}
|
|
234
281
|
);
|
|
235
282
|
var Erc20BalanceDeltaGteSpecSchema = Schema2.Struct({
|
|
@@ -265,7 +312,7 @@ var isLTECheck = (check) => check.kind === "call" && check.comparator === "lte";
|
|
|
265
312
|
var isEQCheck = (check) => check.kind === "call" && check.comparator === "eq";
|
|
266
313
|
|
|
267
314
|
// src/descriptor.ts
|
|
268
|
-
import { Schema as Schema3 } from "effect";
|
|
315
|
+
import { ParseResult as ParseResult2, Schema as Schema3 } from "effect";
|
|
269
316
|
|
|
270
317
|
// src/hexPatterns.ts
|
|
271
318
|
var BYTES32_LOWER_HEX = /^0x[0-9a-f]{64}$/;
|
|
@@ -294,13 +341,13 @@ var RawAssertedPredicateSchema = Schema3.Union(
|
|
|
294
341
|
Erc20BalanceDeltaGteSpecSchema,
|
|
295
342
|
NativeBalanceDeltaGteSpecSchema
|
|
296
343
|
);
|
|
297
|
-
var AssertedPredicateSchema = Schema3.
|
|
344
|
+
var AssertedPredicateSchema = Schema3.transformOrFail(
|
|
298
345
|
RawAssertedPredicateSchema,
|
|
299
346
|
Schema3.typeSchema(RawAssertedPredicateSchema),
|
|
300
347
|
{
|
|
301
348
|
strict: true,
|
|
302
|
-
decode: (pred) => pred.kind === "nativeBalanceGte"
|
|
303
|
-
encode: (pred) => pred
|
|
349
|
+
decode: (pred, _options, ast) => pred.kind === "nativeBalanceGte" ? decodeNativeBalanceGte(pred, ast) : ParseResult2.succeed(pred),
|
|
350
|
+
encode: (pred) => ParseResult2.succeed(pred)
|
|
304
351
|
}
|
|
305
352
|
);
|
|
306
353
|
var VerificationDescriptorSchema = Schema3.Struct({
|
|
@@ -507,6 +554,7 @@ var refKey = (ref2) => foldRef(parseRef(ref2), {
|
|
|
507
554
|
var erc20Balance = (config) => ({ type: "Erc20Balance", ...config });
|
|
508
555
|
var nativeBalance = (config) => ({ type: "NativeBalance", ...config });
|
|
509
556
|
var erc20Allowance = (config) => ({ type: "Erc20Allowance", ...config });
|
|
557
|
+
var isErc20BalancePrecondition = (p) => p.type === "Erc20Balance";
|
|
510
558
|
var isErc20AllowancePrecondition = (p) => p.type === "Erc20Allowance";
|
|
511
559
|
var isNativeBalancePrecondition = (p) => p.type === "NativeBalance";
|
|
512
560
|
|
|
@@ -544,6 +592,7 @@ var checkCompatibility = (client, server, minimum = {
|
|
|
544
592
|
var foldMaterialiserMetadata = (meta, cases) => {
|
|
545
593
|
if (meta.kind === "exact") return cases.exact(meta.amount);
|
|
546
594
|
if (meta.kind === "exact-native") return cases.exactNative(meta.amount);
|
|
595
|
+
if (meta.kind === "capped") return cases.capped(meta.amount);
|
|
547
596
|
return cases.runtime();
|
|
548
597
|
};
|
|
549
598
|
|
|
@@ -781,6 +830,9 @@ var ContinuationPlanZod = z.object({
|
|
|
781
830
|
correlationId: z.string().optional()
|
|
782
831
|
});
|
|
783
832
|
export {
|
|
833
|
+
ARC_CHAIN_ID,
|
|
834
|
+
ARC_NATIVE_ERC20,
|
|
835
|
+
ARC_NATIVE_SCALE,
|
|
784
836
|
AppliedGuardSchema,
|
|
785
837
|
AssertedErc20BalanceGteSpecSchema,
|
|
786
838
|
AssertedNativeBalanceGteSpecSchema,
|
|
@@ -854,16 +906,19 @@ export {
|
|
|
854
906
|
flowInputMode,
|
|
855
907
|
flowInputResource,
|
|
856
908
|
flowInputType,
|
|
909
|
+
foldChainCapabilities,
|
|
857
910
|
foldMaterialiserMetadata,
|
|
858
911
|
foldRef,
|
|
859
912
|
foldResource,
|
|
860
913
|
getChainCapabilities,
|
|
861
914
|
handle,
|
|
915
|
+
hasErc20CanonicalNative,
|
|
862
916
|
isAsErc20Chain,
|
|
863
917
|
isContextKey,
|
|
864
918
|
isEQCheck,
|
|
865
919
|
isERC20Resource,
|
|
866
920
|
isErc20AllowancePrecondition,
|
|
921
|
+
isErc20BalancePrecondition,
|
|
867
922
|
isFutureResourceOutput,
|
|
868
923
|
isGTECheck,
|
|
869
924
|
isHandlePort,
|
|
@@ -881,6 +936,7 @@ export {
|
|
|
881
936
|
linear,
|
|
882
937
|
native,
|
|
883
938
|
nativeBalance,
|
|
939
|
+
nativeCheckPolicy,
|
|
884
940
|
nativeResource,
|
|
885
941
|
normalizeNativeTokenAddress,
|
|
886
942
|
normalizeResource,
|