@lifi/compose-spec 0.11.3 → 0.13.0
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 +63 -98
- package/dist/index.d.cts +132 -436
- package/dist/index.d.ts +132 -436
- package/dist/index.js +64 -94
- package/package.json +1 -1
- package/src/chainCapabilities.ts +13 -0
- package/src/compile.ts +0 -23
- package/src/continuation.ts +100 -89
- package/src/descriptor.ts +20 -72
- package/src/flow.ts +0 -2
- package/src/flowSchema.ts +0 -12
- package/src/hexPatterns.ts +0 -5
- package/src/index.ts +3 -7
- package/src/materialiserMetadata.ts +6 -3
- package/src/route.ts +7 -13
- package/src/simulate.ts +30 -2
- package/src/zodSchemas.ts +41 -71
package/dist/index.cjs
CHANGED
|
@@ -61,16 +61,26 @@ const ARC_NATIVE_ERC20 = {
|
|
|
61
61
|
decimals: 6
|
|
62
62
|
};
|
|
63
63
|
const ARC_NATIVE_SCALE = 10n ** BigInt(18 - ARC_NATIVE_ERC20.decimals);
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
64
|
+
const ARC_TESTNET_CHAIN_ID = 5042002;
|
|
65
|
+
const REGISTRY = /* @__PURE__ */ new Map([
|
|
66
|
+
[TEMPO_CHAIN_ID, {
|
|
67
|
+
kind: "as-erc20",
|
|
68
|
+
chainId: TEMPO_CHAIN_ID,
|
|
69
|
+
nativeErc20: TEMPO_NATIVE_ERC20
|
|
70
|
+
}],
|
|
71
|
+
[ARC_CHAIN_ID, {
|
|
72
|
+
kind: "native-mirrored-erc20",
|
|
73
|
+
chainId: ARC_CHAIN_ID,
|
|
74
|
+
nativeErc20: ARC_NATIVE_ERC20,
|
|
75
|
+
nativeScale: ARC_NATIVE_SCALE
|
|
76
|
+
}],
|
|
77
|
+
[ARC_TESTNET_CHAIN_ID, {
|
|
78
|
+
kind: "native-mirrored-erc20",
|
|
79
|
+
chainId: ARC_TESTNET_CHAIN_ID,
|
|
80
|
+
nativeErc20: ARC_NATIVE_ERC20,
|
|
81
|
+
nativeScale: ARC_NATIVE_SCALE
|
|
82
|
+
}]
|
|
83
|
+
]);
|
|
74
84
|
const getChainCapabilities = (chainId) => REGISTRY.get(chainId) ?? {
|
|
75
85
|
kind: "evm-native",
|
|
76
86
|
chainId
|
|
@@ -204,7 +214,6 @@ const normalizeNativeTokenAddress = (token, chainId) => hasErc20CanonicalNative(
|
|
|
204
214
|
//#region src/hexPatterns.ts
|
|
205
215
|
const BYTES32_LOWER_HEX = /^0x[0-9a-f]{64}$/;
|
|
206
216
|
const EVM_ADDRESS_HEX = /^0x[0-9a-fA-F]{40}$/;
|
|
207
|
-
const HEX_BYTES = /^0x(?:[0-9a-fA-F]{2})*$/;
|
|
208
217
|
const DECIMAL_UINT = /^[0-9]+$/;
|
|
209
218
|
const MAX_UINT256 = 2n ** 256n - 1n;
|
|
210
219
|
const MAX_DATE_MS = 864e13;
|
|
@@ -213,7 +222,6 @@ const MAX_DATE_MS = 864e13;
|
|
|
213
222
|
const SolTypeSchema = effect.Schema.Literal("uint8", "uint16", "uint32", "uint64", "uint128", "uint256", "int128", "int256", "address", "bool", "bytes", "bytes4", "bytes32", "string");
|
|
214
223
|
const ChainIdSchema = effect.Schema.Number.pipe(effect.Schema.int(), effect.Schema.positive());
|
|
215
224
|
const EVMAddressString = effect.Schema.String.pipe(effect.Schema.pattern(EVM_ADDRESS_HEX, { message: () => "expected a 0x-prefixed 20-byte EVM address" })).annotations({ description: "EVM address: 0x followed by 40 hex characters" });
|
|
216
|
-
const HexBytesString = effect.Schema.String.pipe(effect.Schema.pattern(HEX_BYTES, { message: () => "expected 0x-prefixed hex of whole bytes" })).annotations({ description: "Hex bytes: 0x followed by an even number of hex characters" });
|
|
217
225
|
const EpochMsSchema = effect.Schema.Number.pipe(effect.Schema.int(), effect.Schema.between(-864e13, MAX_DATE_MS));
|
|
218
226
|
const IntegerString = effect.Schema.String.pipe(effect.Schema.filter((value) => {
|
|
219
227
|
if (!DECIMAL_UINT.test(value)) return "amount must be a decimal integer string";
|
|
@@ -325,13 +333,13 @@ const normalizingOutcome = (raw) => effect.Schema.transform(raw, effect.Schema.t
|
|
|
325
333
|
const ContinuationOutcomeSchema = normalizingOutcome(effect.Schema.Struct(outcomeFields(effect.Schema.optional(IntegerString))));
|
|
326
334
|
const CommittedOutcomeSchema = normalizingOutcome(effect.Schema.Struct(outcomeFields(IntegerString)));
|
|
327
335
|
const ContinuationIntentSchema = effect.Schema.Struct({
|
|
328
|
-
outcomes: effect.Schema.
|
|
336
|
+
outcomes: effect.Schema.Array(ContinuationOutcomeSchema),
|
|
329
337
|
continuationFlow: effect.Schema.optional(FlowSchema),
|
|
330
338
|
validity: effect.Schema.Struct({ expiresAtMs: EpochMsSchema }),
|
|
331
|
-
perpetual: effect.Schema.optional(effect.Schema.Boolean),
|
|
332
339
|
provider: effect.Schema.optional(effect.Schema.String),
|
|
333
340
|
funding: effect.Schema.optional(effect.Schema.Literal("inline", "external")),
|
|
334
|
-
refund: effect.Schema.optional(EVMAddressString.pipe(effect.Schema.filter((address) => !isZeroAddress(address), { message: () => "refund must not be the zero address" })))
|
|
341
|
+
refund: effect.Schema.optional(EVMAddressString.pipe(effect.Schema.filter((address) => !isZeroAddress(address), { message: () => "refund must not be the zero address" }))),
|
|
342
|
+
exact: effect.Schema.optional(effect.Schema.Boolean)
|
|
335
343
|
});
|
|
336
344
|
const HexStringSchema = effect.Schema.String.pipe(effect.Schema.startsWith("0x"));
|
|
337
345
|
const Phase1EscrowSchema = effect.Schema.Struct({
|
|
@@ -345,6 +353,16 @@ const Phase1EscrowSchema = effect.Schema.Struct({
|
|
|
345
353
|
refund: HexStringSchema,
|
|
346
354
|
expiresAtMs: effect.Schema.Number.pipe(effect.Schema.int(), effect.Schema.positive())
|
|
347
355
|
});
|
|
356
|
+
const Phase1BindingSchema = effect.Schema.Struct({
|
|
357
|
+
executionTarget: HexStringSchema,
|
|
358
|
+
payload: HexStringSchema,
|
|
359
|
+
payloadHash: HexStringSchema,
|
|
360
|
+
calldata: HexStringSchema,
|
|
361
|
+
approvals: effect.Schema.Array(effect.Schema.Struct({
|
|
362
|
+
token: HexStringSchema,
|
|
363
|
+
spender: HexStringSchema
|
|
364
|
+
}))
|
|
365
|
+
});
|
|
348
366
|
const Phase1ArtifactSchema = effect.Schema.Union(effect.Schema.Struct({
|
|
349
367
|
kind: effect.Schema.Literal("transaction"),
|
|
350
368
|
funding: effect.Schema.Literal("inline", "external", "delivered"),
|
|
@@ -354,7 +372,8 @@ const Phase1ArtifactSchema = effect.Schema.Union(effect.Schema.Struct({
|
|
|
354
372
|
value: effect.Schema.String,
|
|
355
373
|
chainId: effect.Schema.Number
|
|
356
374
|
})),
|
|
357
|
-
escrow: effect.Schema.optional(Phase1EscrowSchema)
|
|
375
|
+
escrow: effect.Schema.optional(Phase1EscrowSchema),
|
|
376
|
+
binding: effect.Schema.optional(Phase1BindingSchema)
|
|
358
377
|
}), effect.Schema.Struct({
|
|
359
378
|
kind: effect.Schema.Literal("signables"),
|
|
360
379
|
typedData: effect.Schema.Array(effect.Schema.Unknown)
|
|
@@ -364,22 +383,23 @@ const Erc20BalanceGteSpecSchema = effect.Schema.Struct({
|
|
|
364
383
|
kind: effect.Schema.Literal("erc20BalanceGte"),
|
|
365
384
|
chainId: ChainIdSchema,
|
|
366
385
|
token: EVMAddressString,
|
|
367
|
-
owner:
|
|
386
|
+
owner: AssertionOwnerSchema,
|
|
368
387
|
minAmount: IntegerString
|
|
369
388
|
});
|
|
370
389
|
const NativeBalanceGteSpecSchema = effect.Schema.Struct({
|
|
371
390
|
kind: effect.Schema.Literal("nativeBalanceGte"),
|
|
372
391
|
chainId: ChainIdSchema,
|
|
373
|
-
owner:
|
|
392
|
+
owner: AssertionOwnerSchema,
|
|
374
393
|
minAmount: IntegerString
|
|
375
394
|
});
|
|
376
395
|
const CallCheckSpecSchema = effect.Schema.Struct({
|
|
377
396
|
kind: effect.Schema.Literal("call"),
|
|
378
397
|
chainId: ChainIdSchema,
|
|
379
398
|
to: EVMAddressString,
|
|
380
|
-
|
|
399
|
+
signature: effect.Schema.String,
|
|
400
|
+
args: effect.Schema.Array(effect.Schema.String),
|
|
381
401
|
comparator: effect.Schema.Literal("gte", "eq", "lte"),
|
|
382
|
-
|
|
402
|
+
threshold: IntegerString
|
|
383
403
|
});
|
|
384
404
|
const asErc20BalanceGteCheck = (check, token) => ({
|
|
385
405
|
kind: "erc20BalanceGte",
|
|
@@ -396,39 +416,12 @@ const decodeNativeBalanceGte = (check, ast) => {
|
|
|
396
416
|
case "reject": return effect.ParseResult.fail(new effect.ParseResult.Type(ast, check, policy.reason));
|
|
397
417
|
}
|
|
398
418
|
};
|
|
399
|
-
const
|
|
400
|
-
kind: effect.Schema.Literal("erc20BalanceDeltaGte"),
|
|
401
|
-
chainId: ChainIdSchema,
|
|
402
|
-
token: EVMAddressString,
|
|
403
|
-
owner: AssertionOwnerSchema,
|
|
404
|
-
minDelta: IntegerString
|
|
405
|
-
});
|
|
406
|
-
const NativeBalanceDeltaGteSpecSchema = effect.Schema.Struct({
|
|
407
|
-
kind: effect.Schema.Literal("nativeBalanceDeltaGte"),
|
|
408
|
-
chainId: ChainIdSchema,
|
|
409
|
-
owner: AssertionOwnerSchema,
|
|
410
|
-
minDelta: IntegerString
|
|
411
|
-
});
|
|
412
|
-
const AssertionSpecSchema = effect.Schema.Union(Erc20BalanceGteSpecSchema, NativeBalanceGteSpecSchema, CallCheckSpecSchema, Erc20BalanceDeltaGteSpecSchema, NativeBalanceDeltaGteSpecSchema);
|
|
419
|
+
const AssertionSpecSchema = effect.Schema.Union(Erc20BalanceGteSpecSchema, NativeBalanceGteSpecSchema, CallCheckSpecSchema);
|
|
413
420
|
const settledOutcome = (intent) => intent.outcomes[0];
|
|
414
421
|
//#endregion
|
|
415
422
|
//#region src/descriptor.ts
|
|
416
423
|
const Bytes32HexSchema = effect.Schema.String.pipe(effect.Schema.pattern(BYTES32_LOWER_HEX));
|
|
417
|
-
const
|
|
418
|
-
kind: effect.Schema.Literal("erc20BalanceGte"),
|
|
419
|
-
chainId: ChainIdSchema,
|
|
420
|
-
token: EVMAddressString,
|
|
421
|
-
owner: AssertionOwnerSchema,
|
|
422
|
-
minAmount: IntegerString
|
|
423
|
-
});
|
|
424
|
-
const AssertedNativeBalanceGteSpecSchema = effect.Schema.Struct({
|
|
425
|
-
kind: effect.Schema.Literal("nativeBalanceGte"),
|
|
426
|
-
chainId: ChainIdSchema,
|
|
427
|
-
owner: AssertionOwnerSchema,
|
|
428
|
-
minAmount: IntegerString
|
|
429
|
-
});
|
|
430
|
-
const RawAssertedPredicateSchema = effect.Schema.Union(AssertedErc20BalanceGteSpecSchema, AssertedNativeBalanceGteSpecSchema, CallCheckSpecSchema, Erc20BalanceDeltaGteSpecSchema, NativeBalanceDeltaGteSpecSchema);
|
|
431
|
-
const AssertedPredicateSchema = effect.Schema.transformOrFail(RawAssertedPredicateSchema, effect.Schema.typeSchema(RawAssertedPredicateSchema), {
|
|
424
|
+
const AssertedPredicateSchema = effect.Schema.transformOrFail(AssertionSpecSchema, effect.Schema.typeSchema(AssertionSpecSchema), {
|
|
432
425
|
strict: true,
|
|
433
426
|
decode: (pred, _options, ast) => pred.kind === "nativeBalanceGte" ? decodeNativeBalanceGte(pred, ast) : effect.ParseResult.succeed(pred),
|
|
434
427
|
encode: (pred) => effect.ParseResult.succeed(pred)
|
|
@@ -772,13 +765,12 @@ const foldMaterialiserMetadata = (meta, cases) => {
|
|
|
772
765
|
if (meta.kind === "exact") return cases.exact(meta.amount);
|
|
773
766
|
if (meta.kind === "exact-native") return cases.exactNative(meta.amount);
|
|
774
767
|
if (meta.kind === "capped") return cases.capped(meta.amount, meta.min);
|
|
775
|
-
return cases.runtime();
|
|
768
|
+
return cases.runtime(meta.min);
|
|
776
769
|
};
|
|
777
770
|
//#endregion
|
|
778
771
|
//#region src/zodSchemas.ts
|
|
779
772
|
const chainIdZod = zod.default.number().int().positive();
|
|
780
773
|
const evmAddressZod = zod.default.string().regex(EVM_ADDRESS_HEX);
|
|
781
|
-
const hexBytesZod = zod.default.string().regex(HEX_BYTES);
|
|
782
774
|
const uintStringZod = zod.default.string().refine((value) => DECIMAL_UINT.test(value) && BigInt(value) <= MAX_UINT256, { message: "expected a uint256 decimal integer string" });
|
|
783
775
|
const SolTypeZod = zod.default.enum([
|
|
784
776
|
"uint8",
|
|
@@ -932,85 +924,60 @@ const SettlementEscrowZod = zod.default.object({
|
|
|
932
924
|
refund: hexStringZod,
|
|
933
925
|
expiresAtMs: zod.default.number().int().positive()
|
|
934
926
|
});
|
|
927
|
+
const SettlementBindingZod = zod.default.object({
|
|
928
|
+
executionTarget: hexStringZod,
|
|
929
|
+
payload: hexStringZod,
|
|
930
|
+
payloadHash: hexStringZod,
|
|
931
|
+
calldata: hexStringZod,
|
|
932
|
+
approvals: zod.default.array(zod.default.object({
|
|
933
|
+
token: hexStringZod,
|
|
934
|
+
spender: hexStringZod
|
|
935
|
+
})).readonly()
|
|
936
|
+
});
|
|
935
937
|
const assertionOwnerZod = zod.default.union([evmAddressZod, zod.default.enum(["escrow", "delivery"])]);
|
|
936
938
|
const AssertionSpecZod = zod.default.discriminatedUnion("kind", [
|
|
937
939
|
zod.default.object({
|
|
938
940
|
kind: zod.default.literal("erc20BalanceGte"),
|
|
939
941
|
chainId: chainIdZod,
|
|
940
942
|
token: evmAddressZod,
|
|
941
|
-
owner:
|
|
943
|
+
owner: assertionOwnerZod,
|
|
942
944
|
minAmount: uintStringZod
|
|
943
945
|
}),
|
|
944
946
|
zod.default.object({
|
|
945
947
|
kind: zod.default.literal("nativeBalanceGte"),
|
|
946
948
|
chainId: chainIdZod,
|
|
947
|
-
owner:
|
|
949
|
+
owner: assertionOwnerZod,
|
|
948
950
|
minAmount: uintStringZod
|
|
949
951
|
}),
|
|
950
952
|
zod.default.object({
|
|
951
953
|
kind: zod.default.literal("call"),
|
|
952
954
|
chainId: chainIdZod,
|
|
953
955
|
to: evmAddressZod,
|
|
954
|
-
|
|
956
|
+
signature: zod.default.string(),
|
|
957
|
+
args: zod.default.array(zod.default.string()).readonly(),
|
|
955
958
|
comparator: zod.default.enum([
|
|
956
959
|
"gte",
|
|
957
960
|
"eq",
|
|
958
961
|
"lte"
|
|
959
962
|
]),
|
|
960
|
-
|
|
961
|
-
}),
|
|
962
|
-
zod.default.object({
|
|
963
|
-
kind: zod.default.literal("erc20BalanceDeltaGte"),
|
|
964
|
-
chainId: zod.default.number().int().positive(),
|
|
965
|
-
token: evmAddressZod,
|
|
966
|
-
owner: assertionOwnerZod,
|
|
967
|
-
minDelta: uintStringZod
|
|
968
|
-
}),
|
|
969
|
-
zod.default.object({
|
|
970
|
-
kind: zod.default.literal("nativeBalanceDeltaGte"),
|
|
971
|
-
chainId: zod.default.number().int().positive(),
|
|
972
|
-
owner: assertionOwnerZod,
|
|
973
|
-
minDelta: uintStringZod
|
|
963
|
+
threshold: uintStringZod
|
|
974
964
|
})
|
|
975
965
|
]);
|
|
976
|
-
const assertionSpecOptionByKind = (kind) => {
|
|
977
|
-
const option = AssertionSpecZod.options.find((o) => o.shape.kind.value === kind);
|
|
978
|
-
if (option === void 0) throw new Error(`AssertionSpecZod has no member with kind "${kind}"`);
|
|
979
|
-
return option;
|
|
980
|
-
};
|
|
981
|
-
const AssertedPredicateZod = zod.default.discriminatedUnion("kind", [
|
|
982
|
-
zod.default.object({
|
|
983
|
-
kind: zod.default.literal("erc20BalanceGte"),
|
|
984
|
-
chainId: zod.default.number().int().positive(),
|
|
985
|
-
token: evmAddressZod,
|
|
986
|
-
owner: assertionOwnerZod,
|
|
987
|
-
minAmount: uintStringZod
|
|
988
|
-
}),
|
|
989
|
-
zod.default.object({
|
|
990
|
-
kind: zod.default.literal("nativeBalanceGte"),
|
|
991
|
-
chainId: zod.default.number().int().positive(),
|
|
992
|
-
owner: assertionOwnerZod,
|
|
993
|
-
minAmount: uintStringZod
|
|
994
|
-
}),
|
|
995
|
-
assertionSpecOptionByKind("call"),
|
|
996
|
-
assertionSpecOptionByKind("erc20BalanceDeltaGte"),
|
|
997
|
-
assertionSpecOptionByKind("nativeBalanceDeltaGte")
|
|
998
|
-
]);
|
|
999
966
|
const VerificationDescriptorZod = zod.default.object({
|
|
1000
967
|
validationProgramHash: zod.default.string().regex(BYTES32_LOWER_HEX),
|
|
1001
968
|
paramsHash: zod.default.string().regex(BYTES32_LOWER_HEX),
|
|
1002
|
-
assertedPredicate: zod.default.array(
|
|
969
|
+
assertedPredicate: zod.default.array(AssertionSpecZod).readonly()
|
|
970
|
+
});
|
|
971
|
+
const SettlementZod = zod.default.object({
|
|
972
|
+
escrow: SettlementEscrowZod.optional(),
|
|
973
|
+
binding: SettlementBindingZod.optional()
|
|
1003
974
|
});
|
|
1004
|
-
const SettlementZod = zod.default.object({ escrow: SettlementEscrowZod.optional() });
|
|
1005
975
|
//#endregion
|
|
1006
976
|
exports.ARC_CHAIN_ID = ARC_CHAIN_ID;
|
|
1007
977
|
exports.ARC_NATIVE_ERC20 = ARC_NATIVE_ERC20;
|
|
1008
978
|
exports.ARC_NATIVE_SCALE = ARC_NATIVE_SCALE;
|
|
1009
979
|
exports.AppliedGuardSchema = AppliedGuardSchema;
|
|
1010
|
-
exports.AssertedErc20BalanceGteSpecSchema = AssertedErc20BalanceGteSpecSchema;
|
|
1011
|
-
exports.AssertedNativeBalanceGteSpecSchema = AssertedNativeBalanceGteSpecSchema;
|
|
1012
980
|
exports.AssertedPredicateSchema = AssertedPredicateSchema;
|
|
1013
|
-
exports.AssertedPredicateZod = AssertedPredicateZod;
|
|
1014
981
|
exports.AssertionOwnerSchema = AssertionOwnerSchema;
|
|
1015
982
|
exports.AssertionSpecSchema = AssertionSpecSchema;
|
|
1016
983
|
exports.AssertionSpecZod = AssertionSpecZod;
|
|
@@ -1029,7 +996,6 @@ exports.EVMAddressString = EVMAddressString;
|
|
|
1029
996
|
exports.EVM_NATIVE_SENTINEL = EVM_NATIVE_SENTINEL;
|
|
1030
997
|
exports.EpilogueForwardSchema = EpilogueForwardSchema;
|
|
1031
998
|
exports.EpilogueSchema = EpilogueSchema;
|
|
1032
|
-
exports.Erc20BalanceDeltaGteSpecSchema = Erc20BalanceDeltaGteSpecSchema;
|
|
1033
999
|
exports.Erc20BalanceGteSpecSchema = Erc20BalanceGteSpecSchema;
|
|
1034
1000
|
exports.FlowInputSchema = FlowInputSchema;
|
|
1035
1001
|
exports.FlowSchema = FlowSchema;
|
|
@@ -1050,7 +1016,6 @@ exports.ManifestMaterialiserZod = ManifestMaterialiserZod;
|
|
|
1050
1016
|
exports.ManifestOperationZod = ManifestOperationZod;
|
|
1051
1017
|
exports.ManifestPreconditionZod = ManifestPreconditionZod;
|
|
1052
1018
|
exports.ManifestRoutingZod = ManifestRoutingZod;
|
|
1053
|
-
exports.NativeBalanceDeltaGteSpecSchema = NativeBalanceDeltaGteSpecSchema;
|
|
1054
1019
|
exports.NativeBalanceGteSpecSchema = NativeBalanceGteSpecSchema;
|
|
1055
1020
|
exports.OutputPortZod = OutputPortZod;
|
|
1056
1021
|
exports.PROVIDER_KIND = PROVIDER_KIND;
|