@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.cjs
CHANGED
|
@@ -484,30 +484,38 @@ const resourceKey = (r) => foldResource(r, {
|
|
|
484
484
|
native: ({ chainId }) => `native:${chainId}`,
|
|
485
485
|
erc20: ({ token, chainId }) => `erc20:${token.toLowerCase()}:${chainId}`
|
|
486
486
|
});
|
|
487
|
+
const describeResource = (r) => foldResource(r, {
|
|
488
|
+
native: ({ chainId }) => `native coin on chain ${chainId}`,
|
|
489
|
+
erc20: ({ token, chainId }) => `${token} on chain ${chainId}`
|
|
490
|
+
});
|
|
487
491
|
const erc20Token = (r) => {
|
|
488
492
|
if (r.kind !== "erc20") throw new Error(`Expected erc20 resource, got ${r.kind}`);
|
|
489
493
|
return r.token;
|
|
490
494
|
};
|
|
491
495
|
//#endregion
|
|
492
496
|
//#region src/flashloan.ts
|
|
493
|
-
const PROVIDER_KIND = {
|
|
494
|
-
AAVE_V3: 0,
|
|
495
|
-
ERC3156: 1,
|
|
496
|
-
BALANCER_V2: 2,
|
|
497
|
-
MORPHO_BLUE: 3
|
|
498
|
-
};
|
|
499
497
|
const providerKindNames = [
|
|
500
498
|
"aave-v3",
|
|
501
|
-
"erc3156",
|
|
502
499
|
"balancer-v2",
|
|
503
500
|
"morpho-blue"
|
|
504
501
|
];
|
|
505
|
-
const
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
502
|
+
const FlashloanConfigSchema = effect.Schema.Struct({
|
|
503
|
+
providerKind: effect.Schema.Literal(...providerKindNames),
|
|
504
|
+
amount: IntegerString,
|
|
505
|
+
maxFee: effect.Schema.optional(IntegerString)
|
|
506
|
+
});
|
|
507
|
+
const FlashloanMaterialiserInputSchema = effect.Schema.Struct({
|
|
508
|
+
kind: effect.Schema.Literal("flashloan"),
|
|
509
|
+
...FlashloanConfigSchema.fields
|
|
510
|
+
});
|
|
511
|
+
const isFlashloanMaterialiserInput = effect.Schema.is(FlashloanMaterialiserInputSchema);
|
|
512
|
+
const FLASHLOAN_FEE_BPS = {
|
|
513
|
+
"aave-v3": 5n,
|
|
514
|
+
"balancer-v2": 0n,
|
|
515
|
+
"morpho-blue": 0n
|
|
510
516
|
};
|
|
517
|
+
const BPS_DENOMINATOR = 10000n;
|
|
518
|
+
const flashloanMaxFee = ({ providerKind, amount, maxFee }) => maxFee !== void 0 ? BigInt(maxFee) : (BigInt(amount) * FLASHLOAN_FEE_BPS[providerKind] + BPS_DENOMINATOR - 1n) / BPS_DENOMINATOR;
|
|
511
519
|
//#endregion
|
|
512
520
|
//#region src/constructors.ts
|
|
513
521
|
/** Returns `{ [key]: value }` when `value` is not nullish, else `{}`. */
|
|
@@ -1001,6 +1009,8 @@ exports.EVM_NATIVE_SENTINEL = EVM_NATIVE_SENTINEL;
|
|
|
1001
1009
|
exports.EpilogueForwardSchema = EpilogueForwardSchema;
|
|
1002
1010
|
exports.EpilogueSchema = EpilogueSchema;
|
|
1003
1011
|
exports.Erc20BalanceGteSpecSchema = Erc20BalanceGteSpecSchema;
|
|
1012
|
+
exports.FlashloanConfigSchema = FlashloanConfigSchema;
|
|
1013
|
+
exports.FlashloanMaterialiserInputSchema = FlashloanMaterialiserInputSchema;
|
|
1004
1014
|
exports.FlowInputSchema = FlowInputSchema;
|
|
1005
1015
|
exports.FlowSchema = FlowSchema;
|
|
1006
1016
|
exports.ForwardToSchema = ForwardToSchema;
|
|
@@ -1022,7 +1032,6 @@ exports.ManifestPreconditionZod = ManifestPreconditionZod;
|
|
|
1022
1032
|
exports.ManifestRoutingZod = ManifestRoutingZod;
|
|
1023
1033
|
exports.NativeBalanceGteSpecSchema = NativeBalanceGteSpecSchema;
|
|
1024
1034
|
exports.OutputPortZod = OutputPortZod;
|
|
1025
|
-
exports.PROVIDER_KIND = PROVIDER_KIND;
|
|
1026
1035
|
exports.Phase1ArtifactSchema = Phase1ArtifactSchema;
|
|
1027
1036
|
exports.RESERVED_REF_SCOPES = RESERVED_REF_SCOPES;
|
|
1028
1037
|
exports.RefSchema = RefSchema;
|
|
@@ -1046,6 +1055,7 @@ exports.canonicalAssertedPredicate = canonicalAssertedPredicate;
|
|
|
1046
1055
|
exports.canonicalNativeAddress = canonicalNativeAddress;
|
|
1047
1056
|
exports.checkCompatibility = checkCompatibility;
|
|
1048
1057
|
exports.copy = copy;
|
|
1058
|
+
exports.describeResource = describeResource;
|
|
1049
1059
|
exports.erc20 = erc20;
|
|
1050
1060
|
exports.erc20Allowance = erc20Allowance;
|
|
1051
1061
|
exports.erc20Balance = erc20Balance;
|
|
@@ -1053,6 +1063,7 @@ exports.erc20Resource = erc20Resource;
|
|
|
1053
1063
|
exports.erc20Token = erc20Token;
|
|
1054
1064
|
exports.expandOutputPorts = expandOutputPorts;
|
|
1055
1065
|
exports.familySize = familySize;
|
|
1066
|
+
exports.flashloanMaxFee = flashloanMaxFee;
|
|
1056
1067
|
exports.flowInputMode = flowInputMode;
|
|
1057
1068
|
exports.flowInputResource = flowInputResource;
|
|
1058
1069
|
exports.flowInputType = flowInputType;
|
|
@@ -1069,6 +1080,7 @@ exports.isContextKey = isContextKey;
|
|
|
1069
1080
|
exports.isERC20Resource = isERC20Resource;
|
|
1070
1081
|
exports.isErc20AllowancePrecondition = isErc20AllowancePrecondition;
|
|
1071
1082
|
exports.isErc20BalancePrecondition = isErc20BalancePrecondition;
|
|
1083
|
+
exports.isFlashloanMaterialiserInput = isFlashloanMaterialiserInput;
|
|
1072
1084
|
exports.isFutureResourceOutput = isFutureResourceOutput;
|
|
1073
1085
|
exports.isHandlePort = isHandlePort;
|
|
1074
1086
|
exports.isMaterialiserInput = isMaterialiserInput;
|
|
@@ -1092,7 +1104,6 @@ exports.normalizeResource = normalizeResource;
|
|
|
1092
1104
|
exports.opHandle = opHandle;
|
|
1093
1105
|
exports.parseRef = parseRef;
|
|
1094
1106
|
exports.parseVersion = parseVersion;
|
|
1095
|
-
exports.providerKindByName = providerKindByName;
|
|
1096
1107
|
exports.providerKindNames = providerKindNames;
|
|
1097
1108
|
exports.readResource = readResource;
|
|
1098
1109
|
exports.ref = ref;
|