@lifi/compose-spec 0.11.3 → 0.12.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 +42 -87
- package/dist/index.d.cts +171 -501
- package/dist/index.d.ts +171 -501
- package/dist/index.js +43 -83
- package/package.json +1 -1
- package/src/compile.ts +0 -23
- package/src/continuation.ts +87 -81
- 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 +2 -7
- package/src/materialiserMetadata.ts +6 -3
- package/src/route.ts +7 -13
- package/src/zodSchemas.ts +41 -71
package/dist/index.cjs
CHANGED
|
@@ -204,7 +204,6 @@ const normalizeNativeTokenAddress = (token, chainId) => hasErc20CanonicalNative(
|
|
|
204
204
|
//#region src/hexPatterns.ts
|
|
205
205
|
const BYTES32_LOWER_HEX = /^0x[0-9a-f]{64}$/;
|
|
206
206
|
const EVM_ADDRESS_HEX = /^0x[0-9a-fA-F]{40}$/;
|
|
207
|
-
const HEX_BYTES = /^0x(?:[0-9a-fA-F]{2})*$/;
|
|
208
207
|
const DECIMAL_UINT = /^[0-9]+$/;
|
|
209
208
|
const MAX_UINT256 = 2n ** 256n - 1n;
|
|
210
209
|
const MAX_DATE_MS = 864e13;
|
|
@@ -213,7 +212,6 @@ const MAX_DATE_MS = 864e13;
|
|
|
213
212
|
const SolTypeSchema = effect.Schema.Literal("uint8", "uint16", "uint32", "uint64", "uint128", "uint256", "int128", "int256", "address", "bool", "bytes", "bytes4", "bytes32", "string");
|
|
214
213
|
const ChainIdSchema = effect.Schema.Number.pipe(effect.Schema.int(), effect.Schema.positive());
|
|
215
214
|
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
215
|
const EpochMsSchema = effect.Schema.Number.pipe(effect.Schema.int(), effect.Schema.between(-864e13, MAX_DATE_MS));
|
|
218
216
|
const IntegerString = effect.Schema.String.pipe(effect.Schema.filter((value) => {
|
|
219
217
|
if (!DECIMAL_UINT.test(value)) return "amount must be a decimal integer string";
|
|
@@ -328,10 +326,10 @@ const ContinuationIntentSchema = effect.Schema.Struct({
|
|
|
328
326
|
outcomes: effect.Schema.NonEmptyArray(ContinuationOutcomeSchema),
|
|
329
327
|
continuationFlow: effect.Schema.optional(FlowSchema),
|
|
330
328
|
validity: effect.Schema.Struct({ expiresAtMs: EpochMsSchema }),
|
|
331
|
-
perpetual: effect.Schema.optional(effect.Schema.Boolean),
|
|
332
329
|
provider: effect.Schema.optional(effect.Schema.String),
|
|
333
330
|
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" })))
|
|
331
|
+
refund: effect.Schema.optional(EVMAddressString.pipe(effect.Schema.filter((address) => !isZeroAddress(address), { message: () => "refund must not be the zero address" }))),
|
|
332
|
+
exact: effect.Schema.optional(effect.Schema.Boolean)
|
|
335
333
|
});
|
|
336
334
|
const HexStringSchema = effect.Schema.String.pipe(effect.Schema.startsWith("0x"));
|
|
337
335
|
const Phase1EscrowSchema = effect.Schema.Struct({
|
|
@@ -345,6 +343,16 @@ const Phase1EscrowSchema = effect.Schema.Struct({
|
|
|
345
343
|
refund: HexStringSchema,
|
|
346
344
|
expiresAtMs: effect.Schema.Number.pipe(effect.Schema.int(), effect.Schema.positive())
|
|
347
345
|
});
|
|
346
|
+
const Phase1BindingSchema = effect.Schema.Struct({
|
|
347
|
+
executionTarget: HexStringSchema,
|
|
348
|
+
payload: HexStringSchema,
|
|
349
|
+
payloadHash: HexStringSchema,
|
|
350
|
+
calldata: HexStringSchema,
|
|
351
|
+
approvals: effect.Schema.Array(effect.Schema.Struct({
|
|
352
|
+
token: HexStringSchema,
|
|
353
|
+
spender: HexStringSchema
|
|
354
|
+
}))
|
|
355
|
+
});
|
|
348
356
|
const Phase1ArtifactSchema = effect.Schema.Union(effect.Schema.Struct({
|
|
349
357
|
kind: effect.Schema.Literal("transaction"),
|
|
350
358
|
funding: effect.Schema.Literal("inline", "external", "delivered"),
|
|
@@ -354,7 +362,8 @@ const Phase1ArtifactSchema = effect.Schema.Union(effect.Schema.Struct({
|
|
|
354
362
|
value: effect.Schema.String,
|
|
355
363
|
chainId: effect.Schema.Number
|
|
356
364
|
})),
|
|
357
|
-
escrow: effect.Schema.optional(Phase1EscrowSchema)
|
|
365
|
+
escrow: effect.Schema.optional(Phase1EscrowSchema),
|
|
366
|
+
binding: effect.Schema.optional(Phase1BindingSchema)
|
|
358
367
|
}), effect.Schema.Struct({
|
|
359
368
|
kind: effect.Schema.Literal("signables"),
|
|
360
369
|
typedData: effect.Schema.Array(effect.Schema.Unknown)
|
|
@@ -364,22 +373,23 @@ const Erc20BalanceGteSpecSchema = effect.Schema.Struct({
|
|
|
364
373
|
kind: effect.Schema.Literal("erc20BalanceGte"),
|
|
365
374
|
chainId: ChainIdSchema,
|
|
366
375
|
token: EVMAddressString,
|
|
367
|
-
owner:
|
|
376
|
+
owner: AssertionOwnerSchema,
|
|
368
377
|
minAmount: IntegerString
|
|
369
378
|
});
|
|
370
379
|
const NativeBalanceGteSpecSchema = effect.Schema.Struct({
|
|
371
380
|
kind: effect.Schema.Literal("nativeBalanceGte"),
|
|
372
381
|
chainId: ChainIdSchema,
|
|
373
|
-
owner:
|
|
382
|
+
owner: AssertionOwnerSchema,
|
|
374
383
|
minAmount: IntegerString
|
|
375
384
|
});
|
|
376
385
|
const CallCheckSpecSchema = effect.Schema.Struct({
|
|
377
386
|
kind: effect.Schema.Literal("call"),
|
|
378
387
|
chainId: ChainIdSchema,
|
|
379
388
|
to: EVMAddressString,
|
|
380
|
-
|
|
389
|
+
signature: effect.Schema.String,
|
|
390
|
+
args: effect.Schema.Array(effect.Schema.String),
|
|
381
391
|
comparator: effect.Schema.Literal("gte", "eq", "lte"),
|
|
382
|
-
|
|
392
|
+
threshold: IntegerString
|
|
383
393
|
});
|
|
384
394
|
const asErc20BalanceGteCheck = (check, token) => ({
|
|
385
395
|
kind: "erc20BalanceGte",
|
|
@@ -396,39 +406,12 @@ const decodeNativeBalanceGte = (check, ast) => {
|
|
|
396
406
|
case "reject": return effect.ParseResult.fail(new effect.ParseResult.Type(ast, check, policy.reason));
|
|
397
407
|
}
|
|
398
408
|
};
|
|
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);
|
|
409
|
+
const AssertionSpecSchema = effect.Schema.Union(Erc20BalanceGteSpecSchema, NativeBalanceGteSpecSchema, CallCheckSpecSchema);
|
|
413
410
|
const settledOutcome = (intent) => intent.outcomes[0];
|
|
414
411
|
//#endregion
|
|
415
412
|
//#region src/descriptor.ts
|
|
416
413
|
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), {
|
|
414
|
+
const AssertedPredicateSchema = effect.Schema.transformOrFail(AssertionSpecSchema, effect.Schema.typeSchema(AssertionSpecSchema), {
|
|
432
415
|
strict: true,
|
|
433
416
|
decode: (pred, _options, ast) => pred.kind === "nativeBalanceGte" ? decodeNativeBalanceGte(pred, ast) : effect.ParseResult.succeed(pred),
|
|
434
417
|
encode: (pred) => effect.ParseResult.succeed(pred)
|
|
@@ -772,13 +755,12 @@ const foldMaterialiserMetadata = (meta, cases) => {
|
|
|
772
755
|
if (meta.kind === "exact") return cases.exact(meta.amount);
|
|
773
756
|
if (meta.kind === "exact-native") return cases.exactNative(meta.amount);
|
|
774
757
|
if (meta.kind === "capped") return cases.capped(meta.amount, meta.min);
|
|
775
|
-
return cases.runtime();
|
|
758
|
+
return cases.runtime(meta.min);
|
|
776
759
|
};
|
|
777
760
|
//#endregion
|
|
778
761
|
//#region src/zodSchemas.ts
|
|
779
762
|
const chainIdZod = zod.default.number().int().positive();
|
|
780
763
|
const evmAddressZod = zod.default.string().regex(EVM_ADDRESS_HEX);
|
|
781
|
-
const hexBytesZod = zod.default.string().regex(HEX_BYTES);
|
|
782
764
|
const uintStringZod = zod.default.string().refine((value) => DECIMAL_UINT.test(value) && BigInt(value) <= MAX_UINT256, { message: "expected a uint256 decimal integer string" });
|
|
783
765
|
const SolTypeZod = zod.default.enum([
|
|
784
766
|
"uint8",
|
|
@@ -932,85 +914,60 @@ const SettlementEscrowZod = zod.default.object({
|
|
|
932
914
|
refund: hexStringZod,
|
|
933
915
|
expiresAtMs: zod.default.number().int().positive()
|
|
934
916
|
});
|
|
917
|
+
const SettlementBindingZod = zod.default.object({
|
|
918
|
+
executionTarget: hexStringZod,
|
|
919
|
+
payload: hexStringZod,
|
|
920
|
+
payloadHash: hexStringZod,
|
|
921
|
+
calldata: hexStringZod,
|
|
922
|
+
approvals: zod.default.array(zod.default.object({
|
|
923
|
+
token: hexStringZod,
|
|
924
|
+
spender: hexStringZod
|
|
925
|
+
})).readonly()
|
|
926
|
+
});
|
|
935
927
|
const assertionOwnerZod = zod.default.union([evmAddressZod, zod.default.enum(["escrow", "delivery"])]);
|
|
936
928
|
const AssertionSpecZod = zod.default.discriminatedUnion("kind", [
|
|
937
929
|
zod.default.object({
|
|
938
930
|
kind: zod.default.literal("erc20BalanceGte"),
|
|
939
931
|
chainId: chainIdZod,
|
|
940
932
|
token: evmAddressZod,
|
|
941
|
-
owner:
|
|
933
|
+
owner: assertionOwnerZod,
|
|
942
934
|
minAmount: uintStringZod
|
|
943
935
|
}),
|
|
944
936
|
zod.default.object({
|
|
945
937
|
kind: zod.default.literal("nativeBalanceGte"),
|
|
946
938
|
chainId: chainIdZod,
|
|
947
|
-
owner:
|
|
939
|
+
owner: assertionOwnerZod,
|
|
948
940
|
minAmount: uintStringZod
|
|
949
941
|
}),
|
|
950
942
|
zod.default.object({
|
|
951
943
|
kind: zod.default.literal("call"),
|
|
952
944
|
chainId: chainIdZod,
|
|
953
945
|
to: evmAddressZod,
|
|
954
|
-
|
|
946
|
+
signature: zod.default.string(),
|
|
947
|
+
args: zod.default.array(zod.default.string()).readonly(),
|
|
955
948
|
comparator: zod.default.enum([
|
|
956
949
|
"gte",
|
|
957
950
|
"eq",
|
|
958
951
|
"lte"
|
|
959
952
|
]),
|
|
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
|
|
953
|
+
threshold: uintStringZod
|
|
974
954
|
})
|
|
975
955
|
]);
|
|
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
956
|
const VerificationDescriptorZod = zod.default.object({
|
|
1000
957
|
validationProgramHash: zod.default.string().regex(BYTES32_LOWER_HEX),
|
|
1001
958
|
paramsHash: zod.default.string().regex(BYTES32_LOWER_HEX),
|
|
1002
|
-
assertedPredicate: zod.default.array(
|
|
959
|
+
assertedPredicate: zod.default.array(AssertionSpecZod).readonly()
|
|
960
|
+
});
|
|
961
|
+
const SettlementZod = zod.default.object({
|
|
962
|
+
escrow: SettlementEscrowZod.optional(),
|
|
963
|
+
binding: SettlementBindingZod.optional()
|
|
1003
964
|
});
|
|
1004
|
-
const SettlementZod = zod.default.object({ escrow: SettlementEscrowZod.optional() });
|
|
1005
965
|
//#endregion
|
|
1006
966
|
exports.ARC_CHAIN_ID = ARC_CHAIN_ID;
|
|
1007
967
|
exports.ARC_NATIVE_ERC20 = ARC_NATIVE_ERC20;
|
|
1008
968
|
exports.ARC_NATIVE_SCALE = ARC_NATIVE_SCALE;
|
|
1009
969
|
exports.AppliedGuardSchema = AppliedGuardSchema;
|
|
1010
|
-
exports.AssertedErc20BalanceGteSpecSchema = AssertedErc20BalanceGteSpecSchema;
|
|
1011
|
-
exports.AssertedNativeBalanceGteSpecSchema = AssertedNativeBalanceGteSpecSchema;
|
|
1012
970
|
exports.AssertedPredicateSchema = AssertedPredicateSchema;
|
|
1013
|
-
exports.AssertedPredicateZod = AssertedPredicateZod;
|
|
1014
971
|
exports.AssertionOwnerSchema = AssertionOwnerSchema;
|
|
1015
972
|
exports.AssertionSpecSchema = AssertionSpecSchema;
|
|
1016
973
|
exports.AssertionSpecZod = AssertionSpecZod;
|
|
@@ -1029,7 +986,6 @@ exports.EVMAddressString = EVMAddressString;
|
|
|
1029
986
|
exports.EVM_NATIVE_SENTINEL = EVM_NATIVE_SENTINEL;
|
|
1030
987
|
exports.EpilogueForwardSchema = EpilogueForwardSchema;
|
|
1031
988
|
exports.EpilogueSchema = EpilogueSchema;
|
|
1032
|
-
exports.Erc20BalanceDeltaGteSpecSchema = Erc20BalanceDeltaGteSpecSchema;
|
|
1033
989
|
exports.Erc20BalanceGteSpecSchema = Erc20BalanceGteSpecSchema;
|
|
1034
990
|
exports.FlowInputSchema = FlowInputSchema;
|
|
1035
991
|
exports.FlowSchema = FlowSchema;
|
|
@@ -1050,7 +1006,6 @@ exports.ManifestMaterialiserZod = ManifestMaterialiserZod;
|
|
|
1050
1006
|
exports.ManifestOperationZod = ManifestOperationZod;
|
|
1051
1007
|
exports.ManifestPreconditionZod = ManifestPreconditionZod;
|
|
1052
1008
|
exports.ManifestRoutingZod = ManifestRoutingZod;
|
|
1053
|
-
exports.NativeBalanceDeltaGteSpecSchema = NativeBalanceDeltaGteSpecSchema;
|
|
1054
1009
|
exports.NativeBalanceGteSpecSchema = NativeBalanceGteSpecSchema;
|
|
1055
1010
|
exports.OutputPortZod = OutputPortZod;
|
|
1056
1011
|
exports.PROVIDER_KIND = PROVIDER_KIND;
|