@lifi/compose-spec 0.5.1 → 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/README.md CHANGED
@@ -13,7 +13,8 @@ npm install @lifi/compose-spec
13
13
  ## What's included
14
14
 
15
15
  - **Flow schema types** — `Flow`, `Call`, `Continuation`, `Ref`, `BindValue`, and related types that define the structure of a Compose flow document
16
- - **Resource types** — `Resource`, `Availability`, `OutputAmount`, `SimulatedAmounts`, plus helpers like `erc20Token`, `foldResource`, `resourceKey`
16
+ - **Resource types** — `Resource`, `Availability`, plus helpers like `erc20Token`, `foldResource`, `resourceKey`
17
+ - **Output types** — `Outputs`, `Output`, `ConsumedOutput`, `TerminalOutput`, `Amount`, `Estimate`, `Minimum`, `Delivery`, `EstimateBasis`, `MinimumBasis` — the per-port `outputs` record on a compile result
17
18
  - **Manifest types** — `ComposeManifest`, `ManifestOperation`, `ManifestGuard`, `ManifestMaterialiser`, `ManifestPrecondition`
18
19
  - **Port types** — `ResourcePort`, `HandlePort`, `OpInputPort`, `OpOutputPort`, and type guards
19
20
  - **Ref utilities** — `ref` to build bind refs (`ref.input('amount')`, `ref.context.sender`, `ref('nodeId.port')`), plus `parseRef`, `foldRef`, `refKey` for working with flow references
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,
@@ -145,7 +152,8 @@ __export(index_exports, {
145
152
  resourceKey: () => resourceKey,
146
153
  resourceOutput: () => resourceOutput,
147
154
  resourceToken: () => resourceToken,
148
- resourcesEqual: () => resourcesEqual
155
+ resourcesEqual: () => resourcesEqual,
156
+ settledOutcome: () => settledOutcome
149
157
  });
150
158
  module.exports = __toCommonJS(index_exports);
151
159
 
@@ -164,6 +172,13 @@ var TEMPO_NATIVE_ERC20 = {
164
172
  symbol: "pathUSD",
165
173
  decimals: 6
166
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);
167
182
  var REGISTRY = /* @__PURE__ */ new Map([
168
183
  [
169
184
  TEMPO_CHAIN_ID,
@@ -172,31 +187,60 @@ var REGISTRY = /* @__PURE__ */ new Map([
172
187
  chainId: TEMPO_CHAIN_ID,
173
188
  nativeErc20: TEMPO_NATIVE_ERC20
174
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
+ }
175
199
  ]
176
200
  ]);
177
201
  var getChainCapabilities = (chainId) => REGISTRY.get(chainId) ?? { kind: "evm-native", chainId };
178
- var isAsErc20Chain = (chainId) => getChainCapabilities(chainId).kind === "as-erc20";
179
- var canonicalNativeAddress = (chainId) => {
180
- const caps = getChainCapabilities(chainId);
181
- 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
+ }
182
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;
183
228
  var isNativeAddressForChain = (chainId, address) => {
184
- const caps = getChainCapabilities(chainId);
185
- const target = caps.kind === "as-erc20" ? caps.nativeErc20.token : EVM_NATIVE_SENTINEL;
229
+ const target = canonicalNativeAddress(chainId);
186
230
  return address.toLowerCase() === target.toLowerCase();
187
231
  };
188
- var isMsgValueNative = (chainId, address) => !isAsErc20Chain(chainId) && isNativeSentinel(address);
232
+ var isMsgValueNative = (chainId, address) => !hasErc20CanonicalNative(chainId) && isNativeSentinel(address);
189
233
  var normalizeResource = (r) => {
190
234
  if (r.kind !== "native") return r;
191
- const caps = getChainCapabilities(r.chainId);
192
- if (caps.kind !== "as-erc20") return r;
235
+ const erc202 = erc20CanonicalNative(getChainCapabilities(r.chainId));
236
+ if (erc202 === void 0) return r;
193
237
  return {
194
238
  kind: "erc20",
195
239
  chainId: r.chainId,
196
- token: caps.nativeErc20.token
240
+ token: erc202.token
197
241
  };
198
242
  };
199
- var normalizeNativeTokenAddress = (token, chainId) => isAsErc20Chain(chainId) && isNativeSentinel(token) ? canonicalNativeAddress(chainId) : token;
243
+ var normalizeNativeTokenAddress = (token, chainId) => hasErc20CanonicalNative(chainId) && isNativeSentinel(token) ? canonicalNativeAddress(chainId) : token;
200
244
 
201
245
  // src/flowSchema.ts
202
246
  var SolTypeSchema = import_effect.Schema.Literal(
@@ -362,25 +406,36 @@ var CallCheckSpecSchema = import_effect2.Schema.Struct({
362
406
  comparator: import_effect2.Schema.Literal("gte", "eq", "lte"),
363
407
  value: import_effect2.Schema.String
364
408
  });
365
- var asErc20BalanceGteCheck = (chainId, owner, minAmount) => ({
409
+ var asErc20BalanceGteCheck = (check, token) => ({
366
410
  kind: "erc20BalanceGte",
367
- chainId,
368
- token: canonicalNativeAddress(chainId),
369
- owner,
370
- minAmount
411
+ chainId: check.chainId,
412
+ token,
413
+ owner: check.owner,
414
+ minAmount: check.minAmount
371
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
+ };
372
427
  var RawCheckSchema = import_effect2.Schema.Union(
373
428
  Erc20BalanceGteSpecSchema,
374
429
  NativeBalanceGteSpecSchema,
375
430
  CallCheckSpecSchema
376
431
  );
377
- var CheckSchema = import_effect2.Schema.transform(
432
+ var CheckSchema = import_effect2.Schema.transformOrFail(
378
433
  RawCheckSchema,
379
434
  import_effect2.Schema.typeSchema(RawCheckSchema),
380
435
  {
381
436
  strict: true,
382
- decode: (check) => check.kind === "nativeBalanceGte" && isAsErc20Chain(check.chainId) ? asErc20BalanceGteCheck(check.chainId, check.owner, check.minAmount) : check,
383
- 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)
384
439
  }
385
440
  );
386
441
  var Erc20BalanceDeltaGteSpecSchema = import_effect2.Schema.Struct({
@@ -410,6 +465,7 @@ var ContinuationPlanSchema = import_effect2.Schema.Struct({
410
465
  validity: import_effect2.Schema.Struct({ expiresAtMs: import_effect2.Schema.Number }),
411
466
  correlationId: import_effect2.Schema.optional(import_effect2.Schema.String)
412
467
  });
468
+ var settledOutcome = (intent) => intent.outcomes[0];
413
469
  var isGTECheck = (check) => check.kind === "call" && check.comparator === "gte";
414
470
  var isLTECheck = (check) => check.kind === "call" && check.comparator === "lte";
415
471
  var isEQCheck = (check) => check.kind === "call" && check.comparator === "eq";
@@ -444,13 +500,13 @@ var RawAssertedPredicateSchema = import_effect3.Schema.Union(
444
500
  Erc20BalanceDeltaGteSpecSchema,
445
501
  NativeBalanceDeltaGteSpecSchema
446
502
  );
447
- var AssertedPredicateSchema = import_effect3.Schema.transform(
503
+ var AssertedPredicateSchema = import_effect3.Schema.transformOrFail(
448
504
  RawAssertedPredicateSchema,
449
505
  import_effect3.Schema.typeSchema(RawAssertedPredicateSchema),
450
506
  {
451
507
  strict: true,
452
- decode: (pred) => pred.kind === "nativeBalanceGte" && isAsErc20Chain(pred.chainId) ? asErc20BalanceGteCheck(pred.chainId, pred.owner, pred.minAmount) : pred,
453
- 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)
454
510
  }
455
511
  );
456
512
  var VerificationDescriptorSchema = import_effect3.Schema.Struct({
@@ -657,6 +713,7 @@ var refKey = (ref2) => foldRef(parseRef(ref2), {
657
713
  var erc20Balance = (config) => ({ type: "Erc20Balance", ...config });
658
714
  var nativeBalance = (config) => ({ type: "NativeBalance", ...config });
659
715
  var erc20Allowance = (config) => ({ type: "Erc20Allowance", ...config });
716
+ var isErc20BalancePrecondition = (p) => p.type === "Erc20Balance";
660
717
  var isErc20AllowancePrecondition = (p) => p.type === "Erc20Allowance";
661
718
  var isNativeBalancePrecondition = (p) => p.type === "NativeBalance";
662
719
 
@@ -680,12 +737,13 @@ var parseVersion = (version) => {
680
737
  return { major, minor, patch };
681
738
  };
682
739
  var compareVersions = (a, b) => a.major !== b.major ? a.major - b.major : a.minor !== b.minor ? a.minor - b.minor : a.patch - b.patch;
683
- var checkCompatibility = (client, server) => {
684
- const order = compareVersions(client, server);
685
- if (order > 0) return "server_outdated";
686
- if (client.major !== server.major || client.minor !== server.minor) {
687
- return "sdk_outdated";
688
- }
740
+ var checkCompatibility = (client, server, minimum = {
741
+ major: server.major,
742
+ minor: server.minor,
743
+ patch: 0
744
+ }) => {
745
+ if (compareVersions(client, server) > 0) return "server_outdated";
746
+ if (compareVersions(client, minimum) < 0) return "sdk_outdated";
689
747
  return "compatible";
690
748
  };
691
749
 
@@ -931,6 +989,9 @@ var ContinuationPlanZod = import_zod.default.object({
931
989
  });
932
990
  // Annotate the CommonJS export names for ESM import in node:
933
991
  0 && (module.exports = {
992
+ ARC_CHAIN_ID,
993
+ ARC_NATIVE_ERC20,
994
+ ARC_NATIVE_SCALE,
934
995
  AppliedGuardSchema,
935
996
  AssertedErc20BalanceGteSpecSchema,
936
997
  AssertedNativeBalanceGteSpecSchema,
@@ -1004,16 +1065,19 @@ var ContinuationPlanZod = import_zod.default.object({
1004
1065
  flowInputMode,
1005
1066
  flowInputResource,
1006
1067
  flowInputType,
1068
+ foldChainCapabilities,
1007
1069
  foldMaterialiserMetadata,
1008
1070
  foldRef,
1009
1071
  foldResource,
1010
1072
  getChainCapabilities,
1011
1073
  handle,
1074
+ hasErc20CanonicalNative,
1012
1075
  isAsErc20Chain,
1013
1076
  isContextKey,
1014
1077
  isEQCheck,
1015
1078
  isERC20Resource,
1016
1079
  isErc20AllowancePrecondition,
1080
+ isErc20BalancePrecondition,
1017
1081
  isFutureResourceOutput,
1018
1082
  isGTECheck,
1019
1083
  isHandlePort,
@@ -1031,6 +1095,7 @@ var ContinuationPlanZod = import_zod.default.object({
1031
1095
  linear,
1032
1096
  native,
1033
1097
  nativeBalance,
1098
+ nativeCheckPolicy,
1034
1099
  nativeResource,
1035
1100
  normalizeNativeTokenAddress,
1036
1101
  normalizeResource,
@@ -1046,5 +1111,6 @@ var ContinuationPlanZod = import_zod.default.object({
1046
1111
  resourceKey,
1047
1112
  resourceOutput,
1048
1113
  resourceToken,
1049
- resourcesEqual
1114
+ resourcesEqual,
1115
+ settledOutcome
1050
1116
  });