@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 CHANGED
@@ -30,6 +30,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
+ ARC_CHAIN_ID: () => ARC_CHAIN_ID,
34
+ ARC_NATIVE_ERC20: () => ARC_NATIVE_ERC20,
35
+ ARC_NATIVE_SCALE: () => ARC_NATIVE_SCALE,
33
36
  AppliedGuardSchema: () => AppliedGuardSchema,
34
37
  AssertedErc20BalanceGteSpecSchema: () => AssertedErc20BalanceGteSpecSchema,
35
38
  AssertedNativeBalanceGteSpecSchema: () => AssertedNativeBalanceGteSpecSchema,
@@ -103,16 +106,19 @@ __export(index_exports, {
103
106
  flowInputMode: () => flowInputMode,
104
107
  flowInputResource: () => flowInputResource,
105
108
  flowInputType: () => flowInputType,
109
+ foldChainCapabilities: () => foldChainCapabilities,
106
110
  foldMaterialiserMetadata: () => foldMaterialiserMetadata,
107
111
  foldRef: () => foldRef,
108
112
  foldResource: () => foldResource,
109
113
  getChainCapabilities: () => getChainCapabilities,
110
114
  handle: () => handle,
115
+ hasErc20CanonicalNative: () => hasErc20CanonicalNative,
111
116
  isAsErc20Chain: () => isAsErc20Chain,
112
117
  isContextKey: () => isContextKey,
113
118
  isEQCheck: () => isEQCheck,
114
119
  isERC20Resource: () => isERC20Resource,
115
120
  isErc20AllowancePrecondition: () => isErc20AllowancePrecondition,
121
+ isErc20BalancePrecondition: () => isErc20BalancePrecondition,
116
122
  isFutureResourceOutput: () => isFutureResourceOutput,
117
123
  isGTECheck: () => isGTECheck,
118
124
  isHandlePort: () => isHandlePort,
@@ -130,6 +136,7 @@ __export(index_exports, {
130
136
  linear: () => linear,
131
137
  native: () => native,
132
138
  nativeBalance: () => nativeBalance,
139
+ nativeCheckPolicy: () => nativeCheckPolicy,
133
140
  nativeResource: () => nativeResource,
134
141
  normalizeNativeTokenAddress: () => normalizeNativeTokenAddress,
135
142
  normalizeResource: () => normalizeResource,
@@ -165,6 +172,13 @@ var TEMPO_NATIVE_ERC20 = {
165
172
  symbol: "pathUSD",
166
173
  decimals: 6
167
174
  };
175
+ var ARC_CHAIN_ID = 5042;
176
+ var ARC_NATIVE_ERC20 = {
177
+ token: "0x3600000000000000000000000000000000000000",
178
+ symbol: "USDC",
179
+ decimals: 6
180
+ };
181
+ var ARC_NATIVE_SCALE = 10n ** BigInt(18 - ARC_NATIVE_ERC20.decimals);
168
182
  var REGISTRY = /* @__PURE__ */ new Map([
169
183
  [
170
184
  TEMPO_CHAIN_ID,
@@ -173,31 +187,60 @@ var REGISTRY = /* @__PURE__ */ new Map([
173
187
  chainId: TEMPO_CHAIN_ID,
174
188
  nativeErc20: TEMPO_NATIVE_ERC20
175
189
  }
190
+ ],
191
+ [
192
+ ARC_CHAIN_ID,
193
+ {
194
+ kind: "native-mirrored-erc20",
195
+ chainId: ARC_CHAIN_ID,
196
+ nativeErc20: ARC_NATIVE_ERC20,
197
+ nativeScale: ARC_NATIVE_SCALE
198
+ }
176
199
  ]
177
200
  ]);
178
201
  var getChainCapabilities = (chainId) => REGISTRY.get(chainId) ?? { kind: "evm-native", chainId };
179
- var isAsErc20Chain = (chainId) => getChainCapabilities(chainId).kind === "as-erc20";
180
- var canonicalNativeAddress = (chainId) => {
181
- const caps = getChainCapabilities(chainId);
182
- return caps.kind === "as-erc20" ? caps.nativeErc20.token : EVM_NATIVE_SENTINEL;
202
+ var foldChainCapabilities = (caps, cases) => {
203
+ switch (caps.kind) {
204
+ case "evm-native":
205
+ return cases.evmNative(caps.chainId);
206
+ case "as-erc20":
207
+ return cases.asErc20(caps.nativeErc20, caps.chainId);
208
+ case "native-mirrored-erc20":
209
+ return cases.nativeMirroredErc20(
210
+ caps.nativeErc20,
211
+ caps.nativeScale,
212
+ caps.chainId
213
+ );
214
+ }
183
215
  };
216
+ var nativeCheckPolicy = (chainId) => foldChainCapabilities(getChainCapabilities(chainId), {
217
+ evmNative: () => ({ kind: "keep" }),
218
+ asErc20: (nativeErc20) => ({ kind: "rewrite", token: nativeErc20.token }),
219
+ nativeMirroredErc20: (nativeErc20) => ({
220
+ kind: "reject",
221
+ 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}`
222
+ })
223
+ });
224
+ var isAsErc20Chain = (chainId) => getChainCapabilities(chainId).kind === "as-erc20";
225
+ var erc20CanonicalNative = (caps) => caps.kind === "as-erc20" || caps.kind === "native-mirrored-erc20" ? caps.nativeErc20 : void 0;
226
+ var hasErc20CanonicalNative = (chainId) => erc20CanonicalNative(getChainCapabilities(chainId)) !== void 0;
227
+ var canonicalNativeAddress = (chainId) => erc20CanonicalNative(getChainCapabilities(chainId))?.token ?? EVM_NATIVE_SENTINEL;
184
228
  var isNativeAddressForChain = (chainId, address) => {
185
- const caps = getChainCapabilities(chainId);
186
- const target = caps.kind === "as-erc20" ? caps.nativeErc20.token : EVM_NATIVE_SENTINEL;
229
+ const target = canonicalNativeAddress(chainId);
187
230
  return address.toLowerCase() === target.toLowerCase();
188
231
  };
189
- var isMsgValueNative = (chainId, address) => !isAsErc20Chain(chainId) && isNativeSentinel(address);
232
+ var isMsgValueNative = (chainId, address) => !hasErc20CanonicalNative(chainId) && isNativeSentinel(address);
190
233
  var normalizeResource = (r) => {
191
234
  if (r.kind !== "native") return r;
192
- const caps = getChainCapabilities(r.chainId);
193
- if (caps.kind !== "as-erc20") return r;
235
+ const erc202 = erc20CanonicalNative(getChainCapabilities(r.chainId));
236
+ if (erc202 === void 0) return r;
194
237
  return {
195
238
  kind: "erc20",
196
239
  chainId: r.chainId,
197
- token: caps.nativeErc20.token
240
+ token: erc202.token
198
241
  };
199
242
  };
200
- var normalizeNativeTokenAddress = (token, chainId) => isAsErc20Chain(chainId) && isNativeSentinel(token) ? canonicalNativeAddress(chainId) : token;
243
+ var normalizeNativeTokenAddress = (token, chainId) => hasErc20CanonicalNative(chainId) && isNativeSentinel(token) ? canonicalNativeAddress(chainId) : token;
201
244
 
202
245
  // src/flowSchema.ts
203
246
  var SolTypeSchema = import_effect.Schema.Literal(
@@ -363,25 +406,36 @@ var CallCheckSpecSchema = import_effect2.Schema.Struct({
363
406
  comparator: import_effect2.Schema.Literal("gte", "eq", "lte"),
364
407
  value: import_effect2.Schema.String
365
408
  });
366
- var asErc20BalanceGteCheck = (chainId, owner, minAmount) => ({
409
+ var asErc20BalanceGteCheck = (check, token) => ({
367
410
  kind: "erc20BalanceGte",
368
- chainId,
369
- token: canonicalNativeAddress(chainId),
370
- owner,
371
- minAmount
411
+ chainId: check.chainId,
412
+ token,
413
+ owner: check.owner,
414
+ minAmount: check.minAmount
372
415
  });
416
+ var decodeNativeBalanceGte = (check, ast) => {
417
+ const policy = nativeCheckPolicy(check.chainId);
418
+ switch (policy.kind) {
419
+ case "keep":
420
+ return import_effect2.ParseResult.succeed(check);
421
+ case "rewrite":
422
+ return import_effect2.ParseResult.succeed(asErc20BalanceGteCheck(check, policy.token));
423
+ case "reject":
424
+ return import_effect2.ParseResult.fail(new import_effect2.ParseResult.Type(ast, check, policy.reason));
425
+ }
426
+ };
373
427
  var RawCheckSchema = import_effect2.Schema.Union(
374
428
  Erc20BalanceGteSpecSchema,
375
429
  NativeBalanceGteSpecSchema,
376
430
  CallCheckSpecSchema
377
431
  );
378
- var CheckSchema = import_effect2.Schema.transform(
432
+ var CheckSchema = import_effect2.Schema.transformOrFail(
379
433
  RawCheckSchema,
380
434
  import_effect2.Schema.typeSchema(RawCheckSchema),
381
435
  {
382
436
  strict: true,
383
- decode: (check) => check.kind === "nativeBalanceGte" && isAsErc20Chain(check.chainId) ? asErc20BalanceGteCheck(check.chainId, check.owner, check.minAmount) : check,
384
- encode: (check) => check
437
+ decode: (check, _options, ast) => check.kind === "nativeBalanceGte" ? decodeNativeBalanceGte(check, ast) : import_effect2.ParseResult.succeed(check),
438
+ encode: (check) => import_effect2.ParseResult.succeed(check)
385
439
  }
386
440
  );
387
441
  var Erc20BalanceDeltaGteSpecSchema = import_effect2.Schema.Struct({
@@ -446,13 +500,13 @@ var RawAssertedPredicateSchema = import_effect3.Schema.Union(
446
500
  Erc20BalanceDeltaGteSpecSchema,
447
501
  NativeBalanceDeltaGteSpecSchema
448
502
  );
449
- var AssertedPredicateSchema = import_effect3.Schema.transform(
503
+ var AssertedPredicateSchema = import_effect3.Schema.transformOrFail(
450
504
  RawAssertedPredicateSchema,
451
505
  import_effect3.Schema.typeSchema(RawAssertedPredicateSchema),
452
506
  {
453
507
  strict: true,
454
- decode: (pred) => pred.kind === "nativeBalanceGte" && isAsErc20Chain(pred.chainId) ? asErc20BalanceGteCheck(pred.chainId, pred.owner, pred.minAmount) : pred,
455
- encode: (pred) => pred
508
+ decode: (pred, _options, ast) => pred.kind === "nativeBalanceGte" ? decodeNativeBalanceGte(pred, ast) : import_effect3.ParseResult.succeed(pred),
509
+ encode: (pred) => import_effect3.ParseResult.succeed(pred)
456
510
  }
457
511
  );
458
512
  var VerificationDescriptorSchema = import_effect3.Schema.Struct({
@@ -659,6 +713,7 @@ var refKey = (ref2) => foldRef(parseRef(ref2), {
659
713
  var erc20Balance = (config) => ({ type: "Erc20Balance", ...config });
660
714
  var nativeBalance = (config) => ({ type: "NativeBalance", ...config });
661
715
  var erc20Allowance = (config) => ({ type: "Erc20Allowance", ...config });
716
+ var isErc20BalancePrecondition = (p) => p.type === "Erc20Balance";
662
717
  var isErc20AllowancePrecondition = (p) => p.type === "Erc20Allowance";
663
718
  var isNativeBalancePrecondition = (p) => p.type === "NativeBalance";
664
719
 
@@ -696,6 +751,7 @@ var checkCompatibility = (client, server, minimum = {
696
751
  var foldMaterialiserMetadata = (meta, cases) => {
697
752
  if (meta.kind === "exact") return cases.exact(meta.amount);
698
753
  if (meta.kind === "exact-native") return cases.exactNative(meta.amount);
754
+ if (meta.kind === "capped") return cases.capped(meta.amount);
699
755
  return cases.runtime();
700
756
  };
701
757
 
@@ -934,6 +990,9 @@ var ContinuationPlanZod = import_zod.default.object({
934
990
  });
935
991
  // Annotate the CommonJS export names for ESM import in node:
936
992
  0 && (module.exports = {
993
+ ARC_CHAIN_ID,
994
+ ARC_NATIVE_ERC20,
995
+ ARC_NATIVE_SCALE,
937
996
  AppliedGuardSchema,
938
997
  AssertedErc20BalanceGteSpecSchema,
939
998
  AssertedNativeBalanceGteSpecSchema,
@@ -1007,16 +1066,19 @@ var ContinuationPlanZod = import_zod.default.object({
1007
1066
  flowInputMode,
1008
1067
  flowInputResource,
1009
1068
  flowInputType,
1069
+ foldChainCapabilities,
1010
1070
  foldMaterialiserMetadata,
1011
1071
  foldRef,
1012
1072
  foldResource,
1013
1073
  getChainCapabilities,
1014
1074
  handle,
1075
+ hasErc20CanonicalNative,
1015
1076
  isAsErc20Chain,
1016
1077
  isContextKey,
1017
1078
  isEQCheck,
1018
1079
  isERC20Resource,
1019
1080
  isErc20AllowancePrecondition,
1081
+ isErc20BalancePrecondition,
1020
1082
  isFutureResourceOutput,
1021
1083
  isGTECheck,
1022
1084
  isHandlePort,
@@ -1034,6 +1096,7 @@ var ContinuationPlanZod = import_zod.default.object({
1034
1096
  linear,
1035
1097
  native,
1036
1098
  nativeBalance,
1099
+ nativeCheckPolicy,
1037
1100
  nativeResource,
1038
1101
  normalizeNativeTokenAddress,
1039
1102
  normalizeResource,