@lifi/compose-spec 0.15.1 → 0.16.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 +25 -14
- package/dist/index.d.cts +265 -253
- package/dist/index.d.ts +265 -253
- package/dist/index.js +21 -13
- package/package.json +11 -15
- package/src/flashloan.ts +61 -29
- package/src/index.ts +5 -2
- package/src/resource.ts +7 -0
package/dist/index.js
CHANGED
|
@@ -460,30 +460,38 @@ const resourceKey = (r) => foldResource(r, {
|
|
|
460
460
|
native: ({ chainId }) => `native:${chainId}`,
|
|
461
461
|
erc20: ({ token, chainId }) => `erc20:${token.toLowerCase()}:${chainId}`
|
|
462
462
|
});
|
|
463
|
+
const describeResource = (r) => foldResource(r, {
|
|
464
|
+
native: ({ chainId }) => `native coin on chain ${chainId}`,
|
|
465
|
+
erc20: ({ token, chainId }) => `${token} on chain ${chainId}`
|
|
466
|
+
});
|
|
463
467
|
const erc20Token = (r) => {
|
|
464
468
|
if (r.kind !== "erc20") throw new Error(`Expected erc20 resource, got ${r.kind}`);
|
|
465
469
|
return r.token;
|
|
466
470
|
};
|
|
467
471
|
//#endregion
|
|
468
472
|
//#region src/flashloan.ts
|
|
469
|
-
const PROVIDER_KIND = {
|
|
470
|
-
AAVE_V3: 0,
|
|
471
|
-
ERC3156: 1,
|
|
472
|
-
BALANCER_V2: 2,
|
|
473
|
-
MORPHO_BLUE: 3
|
|
474
|
-
};
|
|
475
473
|
const providerKindNames = [
|
|
476
474
|
"aave-v3",
|
|
477
|
-
"erc3156",
|
|
478
475
|
"balancer-v2",
|
|
479
476
|
"morpho-blue"
|
|
480
477
|
];
|
|
481
|
-
const
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
478
|
+
const FlashloanConfigSchema = Schema.Struct({
|
|
479
|
+
providerKind: Schema.Literal(...providerKindNames),
|
|
480
|
+
amount: IntegerString,
|
|
481
|
+
maxFee: Schema.optional(IntegerString)
|
|
482
|
+
});
|
|
483
|
+
const FlashloanMaterialiserInputSchema = Schema.Struct({
|
|
484
|
+
kind: Schema.Literal("flashloan"),
|
|
485
|
+
...FlashloanConfigSchema.fields
|
|
486
|
+
});
|
|
487
|
+
const isFlashloanMaterialiserInput = Schema.is(FlashloanMaterialiserInputSchema);
|
|
488
|
+
const FLASHLOAN_FEE_BPS = {
|
|
489
|
+
"aave-v3": 5n,
|
|
490
|
+
"balancer-v2": 0n,
|
|
491
|
+
"morpho-blue": 0n
|
|
486
492
|
};
|
|
493
|
+
const BPS_DENOMINATOR = 10000n;
|
|
494
|
+
const flashloanMaxFee = ({ providerKind, amount, maxFee }) => maxFee !== void 0 ? BigInt(maxFee) : (BigInt(amount) * FLASHLOAN_FEE_BPS[providerKind] + BPS_DENOMINATOR - 1n) / BPS_DENOMINATOR;
|
|
487
495
|
//#endregion
|
|
488
496
|
//#region src/constructors.ts
|
|
489
497
|
/** Returns `{ [key]: value }` when `value` is not nullish, else `{}`. */
|
|
@@ -953,4 +961,4 @@ const ShortfallZod = z.object({
|
|
|
953
961
|
available: z.string()
|
|
954
962
|
});
|
|
955
963
|
//#endregion
|
|
956
|
-
export { ARC_CHAIN_ID, ARC_NATIVE_ERC20, ARC_NATIVE_SCALE, AppliedGuardSchema, AssertedPredicateSchema, AssertionOwnerSchema, AssertionSpecSchema, AssertionSpecZod, BindValueSchema, Bytes32HexSchema, COMPOSER_SDK_VERSION_HEADER, COMPOSE_VERSION_HEADER, CONTINUATION_COMMITMENT_OP_ID, CallCheckSpecSchema, CallSchema, CommittedOutcomeSchema, ComposeManifestZod, ContinuationIntentSchema, ContinuationOutcomeSchema, EVMAddressString, EVM_NATIVE_SENTINEL, EpilogueForwardSchema, EpilogueSchema, Erc20BalanceGteSpecSchema, FlowInputSchema, FlowSchema, ForwardToSchema, GuardCompatibilityZod, GuardSelectorZod, HANDLE_UNITS, HandleInputSchema, HandlePortZod, HandleUnitsZod, HexStringSchema, InputPortZod, IntegerString, LineageSchema, LiteralBindingSchema, ManifestGuardZod, ManifestMaterialiserZod, ManifestOperationZod, ManifestPreconditionZod, ManifestRoutingZod, NativeBalanceGteSpecSchema, OutputPortZod,
|
|
964
|
+
export { ARC_CHAIN_ID, ARC_NATIVE_ERC20, ARC_NATIVE_SCALE, AppliedGuardSchema, AssertedPredicateSchema, AssertionOwnerSchema, AssertionSpecSchema, AssertionSpecZod, BindValueSchema, Bytes32HexSchema, COMPOSER_SDK_VERSION_HEADER, COMPOSE_VERSION_HEADER, CONTINUATION_COMMITMENT_OP_ID, CallCheckSpecSchema, CallSchema, CommittedOutcomeSchema, ComposeManifestZod, ContinuationIntentSchema, ContinuationOutcomeSchema, EVMAddressString, EVM_NATIVE_SENTINEL, EpilogueForwardSchema, EpilogueSchema, Erc20BalanceGteSpecSchema, FlashloanConfigSchema, FlashloanMaterialiserInputSchema, FlowInputSchema, FlowSchema, ForwardToSchema, GuardCompatibilityZod, GuardSelectorZod, HANDLE_UNITS, HandleInputSchema, HandlePortZod, HandleUnitsZod, HexStringSchema, InputPortZod, IntegerString, LineageSchema, LiteralBindingSchema, ManifestGuardZod, ManifestMaterialiserZod, ManifestOperationZod, ManifestPreconditionZod, ManifestRoutingZod, NativeBalanceGteSpecSchema, OutputPortZod, Phase1ArtifactSchema, RESERVED_REF_SCOPES, RefSchema, ResourceInputSchema, ResourceOutputPortZod, ResourcePortZod, ResourceSchema, SIMULATE_MAX_REQUIREMENTS, SIMULATE_MAX_TRACKED_BALANCES, STATIC_SOL_TYPES, SettlementZod, ShortfallZod, SolTypeSchema, StaticSolTypeZod, TEMPO_CHAIN_ID, TEMPO_NATIVE_ERC20, UuidSchema, VerificationDescriptorSchema, VerificationDescriptorZod, canonicalAssertedPredicate, canonicalNativeAddress, checkCompatibility, copy, describeResource, erc20, erc20Allowance, erc20Balance, erc20Resource, erc20Token, expandOutputPorts, familySize, flashloanMaxFee, flowInputMode, flowInputResource, flowInputType, foldChainCapabilities, foldMaterialiserMetadata, foldRef, foldResource, getChainCapabilities, handle, hasErc20CanonicalNative, instancePortName, isAsErc20Chain, isContextKey, isERC20Resource, isErc20AllowancePrecondition, isErc20BalancePrecondition, isFlashloanMaterialiserInput, isFutureResourceOutput, isHandlePort, isMaterialiserInput, isMsgValueNative, isNativeAddressForChain, isNativeBalancePrecondition, isNativeResource, isOutputFamily, isRef, isResourceInput, isResourceOutputPort, isResourcePort, isStaticSolType, linear, native, nativeBalance, nativeCheckPolicy, nativeResource, normalizeNativeTokenAddress, normalizeResource, opHandle, parseRef, parseVersion, providerKindNames, readResource, ref, refKey, resource, resourceKey, resourceOutput, resourceToken, resourcesEqual, settledOutcome };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lifi/compose-spec",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.0",
|
|
4
4
|
"description": "Public wire-format types and schemas for Compose flows",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -34,29 +34,25 @@
|
|
|
34
34
|
"clean": "rm -rf dist out",
|
|
35
35
|
"pack:local": "yarn build && mkdir -p out && yarn pack --out 'out/%s-%v.tgz'",
|
|
36
36
|
"test": "vitest run --config vitest.config.ts",
|
|
37
|
+
"test:affected": "vitest run --since-last-run --config vitest.config.ts",
|
|
37
38
|
"fix": "yarn fix:lint",
|
|
38
|
-
"fix:lint": "
|
|
39
|
-
"lint": "
|
|
40
|
-
"test:lint": "
|
|
39
|
+
"fix:lint": "oxlint src --fix",
|
|
40
|
+
"lint": "oxlint src",
|
|
41
|
+
"test:lint": "oxlint src"
|
|
41
42
|
},
|
|
42
43
|
"dependencies": {
|
|
43
44
|
"effect": "^3.21.0",
|
|
44
45
|
"zod": "^4.6.6"
|
|
45
46
|
},
|
|
46
47
|
"devDependencies": {
|
|
47
|
-
"@
|
|
48
|
-
"@lifi/eslint-plugin": "workspace:^",
|
|
48
|
+
"@lifi/oxlint-plugin": "workspace:^",
|
|
49
49
|
"@lifi/vitest-config": "workspace:^",
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"eslint": "^9.36.0",
|
|
53
|
-
"eslint-config-prettier": "^9.0.0",
|
|
54
|
-
"eslint-plugin-eslint-comments": "^3.2.0",
|
|
55
|
-
"eslint-plugin-import": "^2.22.0",
|
|
56
|
-
"eslint-plugin-require-extensions": "^0.1.3",
|
|
50
|
+
"oxlint": "^1.91.0",
|
|
51
|
+
"oxlint-tsgolint": "^7.0.2005",
|
|
57
52
|
"tsdown": "^0.23.0",
|
|
58
|
-
"typescript": "
|
|
59
|
-
"
|
|
53
|
+
"typescript": "~7.0.2",
|
|
54
|
+
"vite": "^8.2.4",
|
|
55
|
+
"vitest": "^5.1.0"
|
|
60
56
|
},
|
|
61
57
|
"files": [
|
|
62
58
|
"dist/**",
|
package/src/flashloan.ts
CHANGED
|
@@ -1,41 +1,73 @@
|
|
|
1
|
-
|
|
2
|
-
// `Yggdrasil-VirtualMachine/src/flashloan/FlashloanLeg.sol`. The numeric
|
|
3
|
-
// values are wire format; the Rust EVM backend consumes them in
|
|
4
|
-
// `executeWithFlashloan(adapter, legs, programBytes)`. Drift between this
|
|
5
|
-
// file and the Solidity source is a bug.
|
|
6
|
-
|
|
7
|
-
export const PROVIDER_KIND = {
|
|
8
|
-
AAVE_V3: 0,
|
|
9
|
-
ERC3156: 1,
|
|
10
|
-
BALANCER_V2: 2,
|
|
11
|
-
MORPHO_BLUE: 3,
|
|
12
|
-
} as const;
|
|
1
|
+
import { Schema } from 'effect';
|
|
13
2
|
|
|
3
|
+
import { IntegerString } from './flowSchema.js';
|
|
4
|
+
|
|
5
|
+
// The lenders a `flashloan` input can borrow from. Each name selects one
|
|
6
|
+
// lender adapter of the v1.3 flashloan runtime (one adapter contract per
|
|
7
|
+
// kind) and that lender's per-chain address.
|
|
14
8
|
export const providerKindNames = [
|
|
15
9
|
'aave-v3',
|
|
16
|
-
'erc3156',
|
|
17
10
|
'balancer-v2',
|
|
18
11
|
'morpho-blue',
|
|
19
12
|
] as const;
|
|
20
13
|
|
|
21
14
|
export type ProviderKindName = (typeof providerKindNames)[number];
|
|
22
15
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
16
|
+
// The one definition of a `flashloan` input's fields, in the wire form
|
|
17
|
+
// (decimal-integer strings). The materialiser's `configSchema`
|
|
18
|
+
// (compose-builtins), the input type and its guard all derive from it.
|
|
19
|
+
// - `amount`: what the leg borrows, in the token's smallest unit.
|
|
20
|
+
// - `maxFee`: the most the lender may charge for the leg; the runtime reverts
|
|
21
|
+
// `FlashloanFeeTooHigh` above it. Defaults to `flashloanMaxFee`'s rate.
|
|
22
|
+
export const FlashloanConfigSchema = Schema.Struct({
|
|
23
|
+
providerKind: Schema.Literal(...providerKindNames),
|
|
24
|
+
amount: IntegerString,
|
|
25
|
+
maxFee: Schema.optional(IntegerString),
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
// A `flashloan` input as authored: the config under the literal
|
|
29
|
+
// `kind: "flashloan"` that discriminates inside the `MaterialiserInput` union.
|
|
30
|
+
export const FlashloanMaterialiserInputSchema = Schema.Struct({
|
|
31
|
+
kind: Schema.Literal('flashloan'),
|
|
32
|
+
...FlashloanConfigSchema.fields,
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
export type FlashloanMaterialiserInput =
|
|
36
|
+
typeof FlashloanMaterialiserInputSchema.Type;
|
|
37
|
+
|
|
38
|
+
export const isFlashloanMaterialiserInput = Schema.is(
|
|
39
|
+
FlashloanMaterialiserInputSchema,
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
// Reference fee rates, in basis points of the borrowed amount, that size a
|
|
43
|
+
// leg's default `maxFee`. Aave v3: `FLASHLOAN_PREMIUM_TOTAL` is 5 bps on the
|
|
44
|
+
// markets in the registry.
|
|
45
|
+
const FLASHLOAN_FEE_BPS: Readonly<Record<ProviderKindName, bigint>> = {
|
|
46
|
+
'aave-v3': 5n,
|
|
47
|
+
'balancer-v2': 0n,
|
|
48
|
+
'morpho-blue': 0n,
|
|
28
49
|
};
|
|
29
50
|
|
|
30
|
-
//
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
//
|
|
34
|
-
//
|
|
35
|
-
//
|
|
36
|
-
//
|
|
37
|
-
|
|
38
|
-
|
|
51
|
+
// Local rather than imported: compose-spec may depend on no @lifi/* package.
|
|
52
|
+
const BPS_DENOMINATOR = 10_000n;
|
|
53
|
+
|
|
54
|
+
// The fee cap of one leg: the input's own `maxFee`, else the reference rate
|
|
55
|
+
// rounded up. Rounding up matters: Aave rounds its premium half-up
|
|
56
|
+
// (`percentMul`), so a rounded-down cap can sit one unit below the fee it
|
|
57
|
+
// charges and revert the flight. Amounts are wire strings or bigints, so an
|
|
58
|
+
// author who holds a bigint does not format it first.
|
|
59
|
+
export const flashloanMaxFee = ({
|
|
60
|
+
providerKind,
|
|
61
|
+
amount,
|
|
62
|
+
maxFee,
|
|
63
|
+
}: {
|
|
39
64
|
readonly providerKind: ProviderKindName;
|
|
40
|
-
readonly amount: string;
|
|
41
|
-
|
|
65
|
+
readonly amount: string | bigint;
|
|
66
|
+
readonly maxFee?: string | bigint;
|
|
67
|
+
}): bigint =>
|
|
68
|
+
maxFee !== undefined
|
|
69
|
+
? BigInt(maxFee)
|
|
70
|
+
: (BigInt(amount) * FLASHLOAN_FEE_BPS[providerKind] +
|
|
71
|
+
BPS_DENOMINATOR -
|
|
72
|
+
1n) /
|
|
73
|
+
BPS_DENOMINATOR;
|
package/src/index.ts
CHANGED
|
@@ -118,6 +118,7 @@ export type {
|
|
|
118
118
|
Resource,
|
|
119
119
|
} from './resource.js';
|
|
120
120
|
export {
|
|
121
|
+
describeResource,
|
|
121
122
|
erc20Resource,
|
|
122
123
|
erc20Token,
|
|
123
124
|
foldResource,
|
|
@@ -147,8 +148,10 @@ export type {
|
|
|
147
148
|
FlashloanMaterialiserInput,
|
|
148
149
|
} from './flashloan.js';
|
|
149
150
|
export {
|
|
150
|
-
|
|
151
|
-
|
|
151
|
+
FlashloanConfigSchema,
|
|
152
|
+
FlashloanMaterialiserInputSchema,
|
|
153
|
+
flashloanMaxFee,
|
|
154
|
+
isFlashloanMaterialiserInput,
|
|
152
155
|
providerKindNames,
|
|
153
156
|
} from './flashloan.js';
|
|
154
157
|
|
package/src/resource.ts
CHANGED
|
@@ -84,6 +84,13 @@ export const resourceKey = (r: Resource): string =>
|
|
|
84
84
|
erc20: ({ token, chainId }) => `erc20:${token.toLowerCase()}:${chainId}`,
|
|
85
85
|
});
|
|
86
86
|
|
|
87
|
+
// A resource as an error message names it.
|
|
88
|
+
export const describeResource = (r: Resource): string =>
|
|
89
|
+
foldResource(r, {
|
|
90
|
+
native: ({ chainId }) => `native coin on chain ${chainId}`,
|
|
91
|
+
erc20: ({ token, chainId }) => `${token} on chain ${chainId}`,
|
|
92
|
+
});
|
|
93
|
+
|
|
87
94
|
export const erc20Token = (r: Resource): string => {
|
|
88
95
|
if (r.kind !== 'erc20')
|
|
89
96
|
throw new Error(`Expected erc20 resource, got ${r.kind}`);
|