@lifi/compose-spec 0.6.0 → 0.6.1
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 +84 -22
- package/dist/index.d.cts +125 -33
- package/dist/index.d.ts +125 -33
- package/dist/index.js +80 -25
- package/package.json +1 -1
- package/src/chainCapabilities.ts +187 -38
- package/src/continuation.ts +55 -36
- package/src/descriptor.ts +13 -17
- package/src/index.ts +12 -1
- package/src/preconditions.ts +4 -0
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;
|
|
@@ -2111,15 +2111,26 @@ declare const refKey: (ref: Ref) => string;
|
|
|
2111
2111
|
* Per-chain native-asset semantics.
|
|
2112
2112
|
*
|
|
2113
2113
|
* 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
|
-
*
|
|
2114
|
+
* `evm-native` policy). A small number express their "native" coin as an
|
|
2115
|
+
* ERC-20 token: on `as-erc20` chains (Tempo) no `msg.value` coin exists at
|
|
2116
|
+
* all, while on `native-mirrored-erc20` chains (Arc) a real `msg.value` coin
|
|
2117
|
+
* exists but is canonically routed through an ERC-20 facade that mirrors the
|
|
2118
|
+
* native balance (`balanceOf == native wei / nativeScale`, with no balance
|
|
2119
|
+
* storage of its own). Code that needs to lower or simulate a `Resource` of
|
|
2120
|
+
* kind `"native"` should consult `getChainCapabilities(chainId)` rather than
|
|
2121
|
+
* hardcoding chain IDs.
|
|
2118
2122
|
*
|
|
2119
2123
|
* 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`).
|
|
2124
|
+
* resources into ERC-20 resources on both ERC-20-canonical kinds at
|
|
2125
|
+
* schema-decode time (see `normalizeResource` below and the `ResourceSchema`
|
|
2126
|
+
* transform in `flowSchema.ts`).
|
|
2127
|
+
*
|
|
2128
|
+
* The two ERC-20-canonical kinds behave identically at the resource level —
|
|
2129
|
+
* `hasErc20CanonicalNative` is the predicate for that shared behaviour. They
|
|
2130
|
+
* diverge only at the simulation layer: `as-erc20` balances live in ordinary
|
|
2131
|
+
* token storage, while `native-mirrored-erc20` balances have no storage slot
|
|
2132
|
+
* and are satisfied by a native balance override scaled by `nativeScale`
|
|
2133
|
+
* (see compose-core's `rewritePreconditions`).
|
|
2123
2134
|
*
|
|
2124
2135
|
* This union is the extension point for future native-asset policies. A chain
|
|
2125
2136
|
* with no canonical native asset would get a `reject-native` arm, under which a
|
|
@@ -2133,6 +2144,12 @@ type ChainCapabilities = {
|
|
|
2133
2144
|
readonly kind: 'as-erc20';
|
|
2134
2145
|
readonly chainId: number;
|
|
2135
2146
|
readonly nativeErc20: NativeErc20;
|
|
2147
|
+
} | {
|
|
2148
|
+
readonly kind: 'native-mirrored-erc20';
|
|
2149
|
+
readonly chainId: number;
|
|
2150
|
+
readonly nativeErc20: NativeErc20;
|
|
2151
|
+
/** Native wei per 1 unit of the facade ERC-20 (1e12 on Arc: 18-dec native, 6-dec USDC). */
|
|
2152
|
+
readonly nativeScale: bigint;
|
|
2136
2153
|
};
|
|
2137
2154
|
interface NativeErc20 {
|
|
2138
2155
|
readonly token: `0x${string}`;
|
|
@@ -2151,21 +2168,93 @@ interface NativeErc20 {
|
|
|
2151
2168
|
declare const EVM_NATIVE_SENTINEL: `0x${string}`;
|
|
2152
2169
|
declare const TEMPO_CHAIN_ID = 4217;
|
|
2153
2170
|
declare const TEMPO_NATIVE_ERC20: NativeErc20;
|
|
2171
|
+
declare const ARC_CHAIN_ID = 5042;
|
|
2172
|
+
/**
|
|
2173
|
+
* Arc's native gas coin is USDC (18-decimal wei at the EVM level). The USDC
|
|
2174
|
+
* ERC-20 at this address is a view over native balances: `balanceOf` returns
|
|
2175
|
+
* `native wei / 1e12` and has no balance storage slot; allowances live in
|
|
2176
|
+
* regular storage. The composer interacts with USDC exclusively through this
|
|
2177
|
+
* facade, never via `msg.value`.
|
|
2178
|
+
*/
|
|
2179
|
+
declare const ARC_NATIVE_ERC20: NativeErc20;
|
|
2180
|
+
declare const ARC_NATIVE_SCALE: bigint;
|
|
2154
2181
|
declare const getChainCapabilities: (chainId: number) => ChainCapabilities;
|
|
2182
|
+
/**
|
|
2183
|
+
* Structural fold over the `ChainCapabilities` union — the capabilities
|
|
2184
|
+
* counterpart of `foldResource`/`foldRef`. Dispatches on `kind` and hands each
|
|
2185
|
+
* case its narrowed fields, so consumers that must branch on the native-asset
|
|
2186
|
+
* policy (e.g. compose-core's `rewritePreconditions`) do so through one
|
|
2187
|
+
* combinator whose exhaustiveness the compiler enforces: adding a new arm to
|
|
2188
|
+
* the union above turns every `foldChainCapabilities` call into a type error
|
|
2189
|
+
* until it handles the new case.
|
|
2190
|
+
*/
|
|
2191
|
+
declare const foldChainCapabilities: <R>(caps: ChainCapabilities, cases: {
|
|
2192
|
+
readonly evmNative: (chainId: number) => R;
|
|
2193
|
+
readonly asErc20: (nativeErc20: NativeErc20, chainId: number) => R;
|
|
2194
|
+
readonly nativeMirroredErc20: (nativeErc20: NativeErc20, nativeScale: bigint, chainId: number) => R;
|
|
2195
|
+
}) => R;
|
|
2196
|
+
/**
|
|
2197
|
+
* What a wire-level native-balance check (`nativeBalanceGte`) must become on
|
|
2198
|
+
* a chain, decided once here from the native-asset policy:
|
|
2199
|
+
*
|
|
2200
|
+
* - `keep` — `evm-native`: the native read is the right read.
|
|
2201
|
+
* - `rewrite` — `as-erc20` (Tempo): no `msg.value` coin exists, so the check
|
|
2202
|
+
* becomes an `erc20BalanceGte` of `token`, the stand-in ERC-20. Amounts were
|
|
2203
|
+
* always facade-denominated, so `minAmount` carries over verbatim.
|
|
2204
|
+
* - `reject` — `native-mirrored-erc20` (Arc): a native read returns real
|
|
2205
|
+
* 18-decimal wei, `nativeScale`× the facade's units, so no interpretation of
|
|
2206
|
+
* `minAmount` is safe — reusing it on a facade read is 1e12 too strict for a
|
|
2207
|
+
* wei-denominated check, keeping the native read lets a facade-denominated
|
|
2208
|
+
* check pass 1e12 too easily. The check must be authored as
|
|
2209
|
+
* `erc20BalanceGte` of the facade; `reason` says so.
|
|
2210
|
+
*
|
|
2211
|
+
* Consumers (the `CheckSchema` / `AssertedPredicateSchema` decodes and
|
|
2212
|
+
* compose-core's derive backstop) are adapters over this result, so the unit
|
|
2213
|
+
* rule lives in one place and the fold's exhaustiveness reaches every site.
|
|
2214
|
+
*/
|
|
2215
|
+
type NativeCheckPolicy = {
|
|
2216
|
+
readonly kind: 'keep';
|
|
2217
|
+
} | {
|
|
2218
|
+
readonly kind: 'rewrite';
|
|
2219
|
+
readonly token: `0x${string}`;
|
|
2220
|
+
} | {
|
|
2221
|
+
readonly kind: 'reject';
|
|
2222
|
+
readonly reason: string;
|
|
2223
|
+
};
|
|
2224
|
+
declare const nativeCheckPolicy: (chainId: number) => NativeCheckPolicy;
|
|
2225
|
+
/**
|
|
2226
|
+
* Exact-kind check for `as-erc20` (currently Tempo only) — the rare case that
|
|
2227
|
+
* genuinely means "no `msg.value` coin exists on this chain". Most consumers
|
|
2228
|
+
* want `hasErc20CanonicalNative` instead, which also covers
|
|
2229
|
+
* `native-mirrored-erc20` chains (Arc), where the composer's ERC-20-only
|
|
2230
|
+
* policy applies even though `msg.value` works. Code that must treat the two
|
|
2231
|
+
* ERC-20-native kinds differently goes through `foldChainCapabilities` or
|
|
2232
|
+
* `nativeCheckPolicy`, never a second exact-kind predicate.
|
|
2233
|
+
*/
|
|
2155
2234
|
declare const isAsErc20Chain: (chainId: number) => boolean;
|
|
2235
|
+
/**
|
|
2236
|
+
* Whether the chain's canonical native asset is an ERC-20 — true for both
|
|
2237
|
+
* `as-erc20` chains (Tempo: no `msg.value` coin exists) and
|
|
2238
|
+
* `native-mirrored-erc20` chains (Arc: `msg.value` exists but is never used).
|
|
2239
|
+
* This is the predicate for the shared resource-level behaviour: native
|
|
2240
|
+
* resources are rewritten to the ERC-20, native routing edges are dropped, and
|
|
2241
|
+
* a surviving native resource is a compile error.
|
|
2242
|
+
*/
|
|
2243
|
+
declare const hasErc20CanonicalNative: (chainId: number) => boolean;
|
|
2156
2244
|
/**
|
|
2157
2245
|
* The address that represents the chain's native asset.
|
|
2158
2246
|
*
|
|
2159
|
-
* On EVM-native chains this is the zero-address sentinel `0x0…0`. On
|
|
2160
|
-
*
|
|
2247
|
+
* On EVM-native chains this is the zero-address sentinel `0x0…0`. On chains
|
|
2248
|
+
* whose canonical native asset is an ERC-20 it is the chain's stand-in token
|
|
2249
|
+
* (PathUSD on Tempo, the USDC facade on Arc).
|
|
2161
2250
|
*/
|
|
2162
2251
|
declare const canonicalNativeAddress: (chainId: number) => `0x${string}`;
|
|
2163
2252
|
/**
|
|
2164
2253
|
* Whether `address` represents the native asset of `chainId`.
|
|
2165
2254
|
*
|
|
2166
2255
|
* On EVM-native chains, this is the case-insensitive zero-address check. On
|
|
2167
|
-
*
|
|
2168
|
-
* chain's stand-in ERC-20 address matches.
|
|
2256
|
+
* chains whose canonical native asset is an ERC-20, the literal zero address
|
|
2257
|
+
* returns `false` — only the chain's stand-in ERC-20 address matches.
|
|
2169
2258
|
*/
|
|
2170
2259
|
declare const isNativeAddressForChain: (chainId: number, address: string) => boolean;
|
|
2171
2260
|
/**
|
|
@@ -2175,28 +2264,30 @@ declare const isNativeAddressForChain: (chainId: number, address: string) => boo
|
|
|
2175
2264
|
* This is the single predicate that gates `msg.value` semantics — choosing a
|
|
2176
2265
|
* `NativeBalance` over an `Erc20Balance` simulation requirement, and skipping
|
|
2177
2266
|
* 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
|
-
* `
|
|
2267
|
+
* for every address on a chain whose canonical native asset is an ERC-20
|
|
2268
|
+
* (including the zero sentinel): on `as-erc20` chains the "native" coin is a
|
|
2269
|
+
* real ERC-20 moved via `transferFrom`, never `msg.value`, and on
|
|
2270
|
+
* `native-mirrored-erc20` chains `msg.value` works but the composer's policy
|
|
2271
|
+
* is to move the coin exclusively through the ERC-20 facade. Use this rather
|
|
2272
|
+
* than re-deriving the check at call sites, and rather than
|
|
2273
|
+
* `isNativeAddressForChain`, which returns `true` for the stand-in ERC-20
|
|
2274
|
+
* (PathUSD on Tempo) and would wrongly route it to `msg.value`.
|
|
2185
2275
|
*/
|
|
2186
2276
|
declare const isMsgValueNative: (chainId: number, address: string) => boolean;
|
|
2187
2277
|
/**
|
|
2188
2278
|
* Rewrite a single `Resource` according to its chain's capabilities.
|
|
2189
2279
|
*
|
|
2190
2280
|
* 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
|
|
2281
|
+
* unchanged. On chains whose canonical native asset is an ERC-20 (`as-erc20`
|
|
2282
|
+
* Tempo, `native-mirrored-erc20` Arc), a resource of kind `"native"` is
|
|
2283
|
+
* rewritten into the equivalent ERC-20 resource pointing at the chain's
|
|
2284
|
+
* stand-in token (PathUSD on Tempo, the USDC facade on Arc).
|
|
2194
2285
|
*
|
|
2195
2286
|
* This is the rewrite primitive behind the `ResourceSchema` decode transform
|
|
2196
2287
|
* (see `flowSchema.ts`), which is THE chokepoint: it runs every time a
|
|
2197
2288
|
* `Resource` is parsed — flow inputs via `FlowSchema`, op configs via
|
|
2198
2289
|
* `decodeConfig` — so every downstream pass (`normalizeFlow`, `resolve`,
|
|
2199
|
-
* `lower`, `simulate`) sees only ERC-20 resources on
|
|
2290
|
+
* `lower`, `simulate`) sees only ERC-20 resources on those chains.
|
|
2200
2291
|
*
|
|
2201
2292
|
* The function preserves referential identity when nothing changes (returns the
|
|
2202
2293
|
* input `r` unchanged on evm-native chains and for ERC-20 resources) and is
|
|
@@ -2206,8 +2297,8 @@ declare const normalizeResource: (r: Resource) => Resource;
|
|
|
2206
2297
|
/**
|
|
2207
2298
|
* Address-level counterpart of `normalizeResource` for wire fields that carry a
|
|
2208
2299
|
* native asset as a bare token string (a continuation outcome's `token`). On
|
|
2209
|
-
*
|
|
2210
|
-
* ERC-20; every other address passes through.
|
|
2300
|
+
* chains whose canonical native asset is an ERC-20, the native sentinel is
|
|
2301
|
+
* rewritten to the chain's stand-in ERC-20; every other address passes through.
|
|
2211
2302
|
*/
|
|
2212
2303
|
declare const normalizeNativeTokenAddress: (token: string, chainId: number) => string;
|
|
2213
2304
|
|
|
@@ -2376,6 +2467,7 @@ type Erc20AllowancePrecondition = {
|
|
|
2376
2467
|
declare const erc20Balance: (config: Omit<Erc20BalancePrecondition, "type">) => Erc20BalancePrecondition;
|
|
2377
2468
|
declare const nativeBalance: (config: Omit<NativeBalancePrecondition, "type">) => NativeBalancePrecondition;
|
|
2378
2469
|
declare const erc20Allowance: (config: Omit<Erc20AllowancePrecondition, "type">) => Erc20AllowancePrecondition;
|
|
2470
|
+
declare const isErc20BalancePrecondition: (p: Precondition) => p is Erc20BalancePrecondition;
|
|
2379
2471
|
declare const isErc20AllowancePrecondition: (p: Precondition) => p is Erc20AllowancePrecondition;
|
|
2380
2472
|
declare const isNativeBalancePrecondition: (p: Precondition) => p is NativeBalancePrecondition;
|
|
2381
2473
|
|
|
@@ -2604,4 +2696,4 @@ declare const foldMaterialiserMetadata: <R>(meta: MaterialiserMetadata, cases: {
|
|
|
2604
2696
|
readonly runtime: () => R;
|
|
2605
2697
|
}) => R;
|
|
2606
2698
|
|
|
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 };
|
|
2699
|
+
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
|
|
|
@@ -781,6 +829,9 @@ var ContinuationPlanZod = z.object({
|
|
|
781
829
|
correlationId: z.string().optional()
|
|
782
830
|
});
|
|
783
831
|
export {
|
|
832
|
+
ARC_CHAIN_ID,
|
|
833
|
+
ARC_NATIVE_ERC20,
|
|
834
|
+
ARC_NATIVE_SCALE,
|
|
784
835
|
AppliedGuardSchema,
|
|
785
836
|
AssertedErc20BalanceGteSpecSchema,
|
|
786
837
|
AssertedNativeBalanceGteSpecSchema,
|
|
@@ -854,16 +905,19 @@ export {
|
|
|
854
905
|
flowInputMode,
|
|
855
906
|
flowInputResource,
|
|
856
907
|
flowInputType,
|
|
908
|
+
foldChainCapabilities,
|
|
857
909
|
foldMaterialiserMetadata,
|
|
858
910
|
foldRef,
|
|
859
911
|
foldResource,
|
|
860
912
|
getChainCapabilities,
|
|
861
913
|
handle,
|
|
914
|
+
hasErc20CanonicalNative,
|
|
862
915
|
isAsErc20Chain,
|
|
863
916
|
isContextKey,
|
|
864
917
|
isEQCheck,
|
|
865
918
|
isERC20Resource,
|
|
866
919
|
isErc20AllowancePrecondition,
|
|
920
|
+
isErc20BalancePrecondition,
|
|
867
921
|
isFutureResourceOutput,
|
|
868
922
|
isGTECheck,
|
|
869
923
|
isHandlePort,
|
|
@@ -881,6 +935,7 @@ export {
|
|
|
881
935
|
linear,
|
|
882
936
|
native,
|
|
883
937
|
nativeBalance,
|
|
938
|
+
nativeCheckPolicy,
|
|
884
939
|
nativeResource,
|
|
885
940
|
normalizeNativeTokenAddress,
|
|
886
941
|
normalizeResource,
|