@morpho-org/morpho-sdk 6.0.0-next.2 → 6.0.0-next.3
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/MIGRATION-v5-to-v6.md +83 -29
- package/README.md +9 -7
- package/lib/cjs/abis.d.ts +3 -2844
- package/lib/cjs/abis.js +1 -1951
- package/lib/cjs/actions/blue/borrow.d.ts +3 -2
- package/lib/cjs/actions/blue/borrow.js +3 -2
- package/lib/cjs/actions/blue/common.js +1 -9
- package/lib/cjs/actions/blue/refinance.d.ts +2 -2
- package/lib/cjs/actions/blue/refinance.js +2 -2
- package/lib/cjs/actions/blue/repay.d.ts +1 -1
- package/lib/cjs/actions/blue/repay.js +1 -1
- package/lib/cjs/actions/blue/repayWithdrawCollateral.d.ts +2 -2
- package/lib/cjs/actions/blue/repayWithdrawCollateral.js +2 -2
- package/lib/cjs/actions/blue/supply.d.ts +2 -2
- package/lib/cjs/actions/blue/supply.js +2 -2
- package/lib/cjs/actions/blue/supplyCollateral.d.ts +2 -2
- package/lib/cjs/actions/blue/supplyCollateral.js +2 -2
- package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +3 -2
- package/lib/cjs/actions/blue/supplyCollateralBorrow.js +3 -2
- package/lib/cjs/actions/blue/withdraw.d.ts +3 -3
- package/lib/cjs/actions/blue/withdraw.js +3 -3
- package/lib/cjs/actions/blue/withdrawCollateral.d.ts +2 -2
- package/lib/cjs/actions/blue/withdrawCollateral.js +2 -2
- package/lib/cjs/actions/bundles/common.d.ts +6 -2
- package/lib/cjs/actions/bundles/common.js +23 -5
- package/lib/cjs/actions/index.d.ts +0 -1
- package/lib/cjs/actions/index.js +0 -1
- package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +6 -8
- package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +11 -16
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +5 -6
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +4 -5
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +4 -4
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +4 -5
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +5 -5
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +6 -11
- package/lib/cjs/actions/requirements/encode/index.d.ts +0 -1
- package/lib/cjs/actions/requirements/encode/index.js +0 -1
- package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +5 -6
- package/lib/cjs/actions/requirements/getRequirementsApproval.js +5 -6
- package/lib/cjs/actions/requirements/index.d.ts +0 -1
- package/lib/cjs/actions/requirements/index.js +0 -1
- package/lib/cjs/actions/vaultV1/deposit.d.ts +1 -2
- package/lib/cjs/actions/vaultV1/deposit.js +1 -2
- package/lib/cjs/actions/vaultV1/inKindRedeem.d.ts +6 -5
- package/lib/cjs/actions/vaultV1/inKindRedeem.js +10 -7
- package/lib/cjs/actions/vaultV2/deposit.d.ts +1 -2
- package/lib/cjs/actions/vaultV2/deposit.js +1 -2
- package/lib/cjs/actions/vaultV2/forceWithdraw.d.ts +1 -1
- package/lib/cjs/actions/vaultV2/forceWithdraw.js +3 -3
- package/lib/cjs/actions/vaultV2/inKindRedeem.d.ts +6 -5
- package/lib/cjs/actions/vaultV2/inKindRedeem.js +10 -7
- package/lib/cjs/augment.d.ts +0 -1
- package/lib/cjs/augment.js +0 -1
- package/lib/cjs/blue/abis.d.ts +1 -5
- package/lib/cjs/blue/abis.js +1 -7
- package/lib/cjs/blue/entities.d.ts +2 -8
- package/lib/cjs/blue/entities.js +1 -3
- package/lib/cjs/blue/fetch.d.ts +1 -3
- package/lib/cjs/blue/fetch.js +1 -3
- package/lib/cjs/blue/types.d.ts +2 -4
- package/lib/cjs/blue/utils.d.ts +1 -3
- package/lib/cjs/blue/utils.js +1 -3
- package/lib/cjs/client/morphoViemExtension.d.ts +1 -1
- package/lib/cjs/client/morphoViemExtension.js +1 -1
- package/lib/cjs/constants.d.ts +3 -37
- package/lib/cjs/constants.js +1 -39
- package/lib/cjs/entities/blue/blue.d.ts +30 -265
- package/lib/cjs/entities/blue/blue.js +1 -205
- package/lib/cjs/entities/index.d.ts +3 -66
- package/lib/cjs/entities/index.js +1 -21
- package/lib/cjs/entities/vaultV1/vaultV1.d.ts +9 -2
- package/lib/cjs/entities/vaultV1/vaultV1.js +12 -7
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +22 -9
- package/lib/cjs/entities/vaultV2/vaultV2.js +28 -15
- package/lib/cjs/entities/vaultV2BlueReallocationData.js +4 -21
- package/lib/cjs/errors.d.ts +2 -46
- package/lib/cjs/errors.js +1 -46
- package/lib/cjs/fetch.d.ts +1 -17
- package/lib/cjs/fetch.js +1 -17
- package/lib/cjs/helpers/constant.d.ts +0 -2
- package/lib/cjs/helpers/constant.js +0 -2
- package/lib/cjs/helpers/index.d.ts +2 -3
- package/lib/cjs/helpers/index.js +1 -9
- package/lib/cjs/helpers/slippage.d.ts +1 -103
- package/lib/cjs/helpers/slippage.js +0 -150
- package/lib/cjs/helpers/utilization.d.ts +12 -10
- package/lib/cjs/helpers/utilization.js +27 -12
- package/lib/cjs/helpers/validate.d.ts +1 -24
- package/lib/cjs/helpers/validate.js +2 -49
- package/lib/cjs/helpers/validateRequirementSpender.d.ts +1 -1
- package/lib/cjs/helpers/validateRequirementSpender.js +1 -3
- package/lib/cjs/types/action.d.ts +17 -65
- package/lib/cjs/types/action.js +11 -4
- package/lib/cjs/types/error.d.ts +50 -381
- package/lib/cjs/types/error.js +64 -395
- package/lib/cjs/types/sharedLiquidity.d.ts +1 -117
- package/lib/cjs/types.d.ts +2 -18
- package/lib/cjs/utils.d.ts +6 -35
- package/lib/cjs/utils.js +2 -36
- package/lib/esm/abis.d.ts +3 -2844
- package/lib/esm/abis.js +3 -1950
- package/lib/esm/actions/blue/borrow.d.ts +3 -2
- package/lib/esm/actions/blue/borrow.js +3 -2
- package/lib/esm/actions/blue/common.js +1 -9
- package/lib/esm/actions/blue/refinance.d.ts +2 -2
- package/lib/esm/actions/blue/refinance.js +2 -2
- package/lib/esm/actions/blue/repay.d.ts +1 -1
- package/lib/esm/actions/blue/repay.js +1 -1
- package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +2 -2
- package/lib/esm/actions/blue/repayWithdrawCollateral.js +2 -2
- package/lib/esm/actions/blue/supply.d.ts +2 -2
- package/lib/esm/actions/blue/supply.js +2 -2
- package/lib/esm/actions/blue/supplyCollateral.d.ts +2 -2
- package/lib/esm/actions/blue/supplyCollateral.js +2 -2
- package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +3 -2
- package/lib/esm/actions/blue/supplyCollateralBorrow.js +3 -2
- package/lib/esm/actions/blue/withdraw.d.ts +3 -3
- package/lib/esm/actions/blue/withdraw.js +3 -3
- package/lib/esm/actions/blue/withdrawCollateral.d.ts +2 -2
- package/lib/esm/actions/blue/withdrawCollateral.js +2 -2
- package/lib/esm/actions/bundles/common.d.ts +6 -2
- package/lib/esm/actions/bundles/common.js +24 -6
- package/lib/esm/actions/index.d.ts +0 -1
- package/lib/esm/actions/index.js +0 -1
- package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +6 -8
- package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +12 -17
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +5 -6
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +4 -5
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +4 -4
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +4 -5
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +5 -5
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +6 -11
- package/lib/esm/actions/requirements/encode/index.d.ts +0 -1
- package/lib/esm/actions/requirements/encode/index.js +0 -1
- package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +5 -6
- package/lib/esm/actions/requirements/getRequirementsApproval.js +5 -6
- package/lib/esm/actions/requirements/index.d.ts +0 -1
- package/lib/esm/actions/requirements/index.js +0 -1
- package/lib/esm/actions/vaultV1/deposit.d.ts +1 -2
- package/lib/esm/actions/vaultV1/deposit.js +1 -2
- package/lib/esm/actions/vaultV1/inKindRedeem.d.ts +6 -5
- package/lib/esm/actions/vaultV1/inKindRedeem.js +10 -7
- package/lib/esm/actions/vaultV2/deposit.d.ts +1 -2
- package/lib/esm/actions/vaultV2/deposit.js +1 -2
- package/lib/esm/actions/vaultV2/forceWithdraw.d.ts +1 -1
- package/lib/esm/actions/vaultV2/forceWithdraw.js +3 -3
- package/lib/esm/actions/vaultV2/inKindRedeem.d.ts +6 -5
- package/lib/esm/actions/vaultV2/inKindRedeem.js +10 -7
- package/lib/esm/augment.d.ts +0 -1
- package/lib/esm/augment.js +0 -1
- package/lib/esm/blue/abis.d.ts +1 -5
- package/lib/esm/blue/abis.js +1 -5
- package/lib/esm/blue/entities.d.ts +2 -8
- package/lib/esm/blue/entities.js +1 -3
- package/lib/esm/blue/fetch.d.ts +1 -3
- package/lib/esm/blue/fetch.js +1 -3
- package/lib/esm/blue/types.d.ts +2 -4
- package/lib/esm/blue/utils.d.ts +1 -3
- package/lib/esm/blue/utils.js +1 -3
- package/lib/esm/client/morphoViemExtension.d.ts +1 -1
- package/lib/esm/client/morphoViemExtension.js +1 -1
- package/lib/esm/constants.d.ts +3 -37
- package/lib/esm/constants.js +3 -37
- package/lib/esm/entities/blue/blue.d.ts +30 -265
- package/lib/esm/entities/blue/blue.js +4 -208
- package/lib/esm/entities/index.d.ts +3 -66
- package/lib/esm/entities/index.js +1 -18
- package/lib/esm/entities/vaultV1/vaultV1.d.ts +9 -2
- package/lib/esm/entities/vaultV1/vaultV1.js +15 -10
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +22 -9
- package/lib/esm/entities/vaultV2/vaultV2.js +32 -19
- package/lib/esm/entities/vaultV2BlueReallocationData.js +2 -19
- package/lib/esm/errors.d.ts +2 -46
- package/lib/esm/errors.js +2 -46
- package/lib/esm/fetch.d.ts +1 -17
- package/lib/esm/fetch.js +1 -17
- package/lib/esm/helpers/constant.d.ts +0 -2
- package/lib/esm/helpers/constant.js +0 -2
- package/lib/esm/helpers/index.d.ts +2 -3
- package/lib/esm/helpers/index.js +2 -3
- package/lib/esm/helpers/slippage.d.ts +1 -103
- package/lib/esm/helpers/slippage.js +1 -147
- package/lib/esm/helpers/utilization.d.ts +12 -10
- package/lib/esm/helpers/utilization.js +26 -11
- package/lib/esm/helpers/validate.d.ts +1 -24
- package/lib/esm/helpers/validate.js +2 -48
- package/lib/esm/helpers/validateRequirementSpender.d.ts +1 -1
- package/lib/esm/helpers/validateRequirementSpender.js +1 -3
- package/lib/esm/types/action.d.ts +17 -65
- package/lib/esm/types/action.js +12 -5
- package/lib/esm/types/error.d.ts +50 -381
- package/lib/esm/types/error.js +58 -377
- package/lib/esm/types/sharedLiquidity.d.ts +1 -117
- package/lib/esm/types.d.ts +2 -18
- package/lib/esm/utils.d.ts +6 -35
- package/lib/esm/utils.js +5 -34
- package/package.json +5 -13
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2Approve.d.ts +0 -44
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2Approve.js +0 -88
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirements.d.ts +0 -88
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +0 -152
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +0 -40
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +0 -53
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.d.ts +0 -57
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.js +0 -74
- package/lib/cjs/actions/requirements/generalAdapter/index.d.ts +0 -3
- package/lib/cjs/actions/requirements/generalAdapter/index.js +0 -19
- package/lib/cjs/actions/signatures/getBlueAuthorizationAction.d.ts +0 -29
- package/lib/cjs/actions/signatures/getBlueAuthorizationAction.js +0 -48
- package/lib/cjs/actions/signatures/getTokenRequirementActions.d.ts +0 -58
- package/lib/cjs/actions/signatures/getTokenRequirementActions.js +0 -119
- package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +0 -50
- package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.js +0 -45
- package/lib/cjs/actions/signatures/index.d.ts +0 -3
- package/lib/cjs/actions/signatures/index.js +0 -19
- package/lib/cjs/augment/VaultMarketPublicAllocatorConfig.d.ts +0 -11
- package/lib/cjs/augment/VaultMarketPublicAllocatorConfig.js +0 -8
- package/lib/cjs/bundler/actions.d.ts +0 -797
- package/lib/cjs/bundler/actions.js +0 -1371
- package/lib/cjs/bundler/index.d.ts +0 -2
- package/lib/cjs/bundler/index.js +0 -18
- package/lib/cjs/bundler/types.d.ts +0 -235
- package/lib/cjs/bundler/types.js +0 -2
- package/lib/cjs/entities/vaultV1ReallocationData.d.ts +0 -332
- package/lib/cjs/entities/vaultV1ReallocationData.js +0 -557
- package/lib/cjs/helpers/computeVaultV1Reallocations.d.ts +0 -80
- package/lib/cjs/helpers/computeVaultV1Reallocations.js +0 -245
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2Approve.d.ts +0 -44
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2Approve.js +0 -84
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirements.d.ts +0 -88
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +0 -148
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +0 -40
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +0 -49
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.d.ts +0 -57
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.js +0 -70
- package/lib/esm/actions/requirements/generalAdapter/index.d.ts +0 -3
- package/lib/esm/actions/requirements/generalAdapter/index.js +0 -3
- package/lib/esm/actions/signatures/getBlueAuthorizationAction.d.ts +0 -29
- package/lib/esm/actions/signatures/getBlueAuthorizationAction.js +0 -44
- package/lib/esm/actions/signatures/getTokenRequirementActions.d.ts +0 -58
- package/lib/esm/actions/signatures/getTokenRequirementActions.js +0 -115
- package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +0 -50
- package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.js +0 -41
- package/lib/esm/actions/signatures/index.d.ts +0 -3
- package/lib/esm/actions/signatures/index.js +0 -3
- package/lib/esm/augment/VaultMarketPublicAllocatorConfig.d.ts +0 -11
- package/lib/esm/augment/VaultMarketPublicAllocatorConfig.js +0 -7
- package/lib/esm/bundler/actions.d.ts +0 -797
- package/lib/esm/bundler/actions.js +0 -1368
- package/lib/esm/bundler/index.d.ts +0 -2
- package/lib/esm/bundler/index.js +0 -2
- package/lib/esm/bundler/types.d.ts +0 -235
- package/lib/esm/bundler/types.js +0 -1
- package/lib/esm/entities/vaultV1ReallocationData.d.ts +0 -332
- package/lib/esm/entities/vaultV1ReallocationData.js +0 -559
- package/lib/esm/helpers/computeVaultV1Reallocations.d.ts +0 -80
- package/lib/esm/helpers/computeVaultV1Reallocations.js +0 -241
|
@@ -1,1371 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BundlerAction = void 0;
|
|
4
|
-
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
5
|
-
const blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
|
|
6
|
-
const viem_1 = require("viem");
|
|
7
|
-
const abis_js_1 = require("../abis.js");
|
|
8
|
-
const error_js_1 = require("../types/error.js");
|
|
9
|
-
const reenterAbiInputs = abis_js_1.bundler3Abi.find((item) => item.type === "function" && item.name === "reenter").inputs;
|
|
10
|
-
const encodeCallbackCalls = (callbackCalls) => {
|
|
11
|
-
const reenter = callbackCalls.length > 0;
|
|
12
|
-
const reenterData = reenter
|
|
13
|
-
? (0, viem_1.encodeAbiParameters)(reenterAbiInputs, [callbackCalls])
|
|
14
|
-
: "0x";
|
|
15
|
-
return {
|
|
16
|
-
callbackHash: reenter ? (0, viem_1.keccak256)(reenterData) : viem_1.zeroHash,
|
|
17
|
-
reenterData,
|
|
18
|
-
};
|
|
19
|
-
};
|
|
20
|
-
const addBundlerPrefund = (state, amount) => ({
|
|
21
|
-
value: state.value + amount,
|
|
22
|
-
availableBundlerValue: state.availableBundlerValue + amount,
|
|
23
|
-
});
|
|
24
|
-
/**
|
|
25
|
-
* Normalizes a raw ECDSA signature to its hex form. Integrators get a `Hex` from
|
|
26
|
-
* `signTypedData`/`signMessage` and a viem `Signature` object from the low-level
|
|
27
|
-
* `sign`; both are accepted so no manual conversion is required at the call site.
|
|
28
|
-
*/
|
|
29
|
-
const toSignatureHex = (signature) => typeof signature === "string" ? signature : (0, viem_1.serializeSignature)(signature);
|
|
30
|
-
const consumeCallValue = (state, call) => {
|
|
31
|
-
if (call.value > state.availableBundlerValue) {
|
|
32
|
-
return {
|
|
33
|
-
value: state.value + call.value - state.availableBundlerValue,
|
|
34
|
-
availableBundlerValue: 0n,
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
return {
|
|
38
|
-
value: state.value,
|
|
39
|
-
availableBundlerValue: state.availableBundlerValue - call.value,
|
|
40
|
-
};
|
|
41
|
-
};
|
|
42
|
-
/**
|
|
43
|
-
* Encodes the Bundler3 action subset used by `morpho-sdk` transaction builders.
|
|
44
|
-
*
|
|
45
|
-
* @remarks
|
|
46
|
-
* The namespace covers only the Bundler3 actions required by `morpho-sdk`.
|
|
47
|
-
* It does not expose operation population or broad simulation helpers.
|
|
48
|
-
*/
|
|
49
|
-
var BundlerAction;
|
|
50
|
-
(function (BundlerAction) {
|
|
51
|
-
/**
|
|
52
|
-
* Encodes a list of Bundler3 actions into a single Bundler3 multicall
|
|
53
|
-
* transaction request.
|
|
54
|
-
*
|
|
55
|
-
* @remarks
|
|
56
|
-
* This is a low-level encoding helper, not a safe bundle constructor. It
|
|
57
|
-
* does not validate that native-token pre-funding is fully consumed or that
|
|
58
|
-
* pre-funding actions are ordered before the value-carrying calls they fund.
|
|
59
|
-
*
|
|
60
|
-
* When custom actions include `nativeTransfer(externalOwner, bundler3,
|
|
61
|
-
* amount)`, no inner Bundler3 call is emitted for that transfer. Consumers
|
|
62
|
-
* must ensure those pre-funding actions precede their downstream consumers
|
|
63
|
-
* and leave no residual pre-funded native token; otherwise `tx.value` can be
|
|
64
|
-
* over-counted or native token can remain stranded on Bundler3. The
|
|
65
|
-
* high-level `morpho-sdk` action builders construct actions in that order,
|
|
66
|
-
* but this invariant is not checked at runtime by `encodeBundle`.
|
|
67
|
-
*
|
|
68
|
-
* @param chainId - Chain where the bundle will execute.
|
|
69
|
-
* @param actions - Ordered Bundler3 actions to encode.
|
|
70
|
-
* @returns Transaction target, calldata, and native value required by the
|
|
71
|
-
* bundle.
|
|
72
|
-
* @throws {BundlerErrors.MissingSignature} when a signature action is unsigned.
|
|
73
|
-
* @throws {BundlerErrors.UnexpectedAction} when an action is unavailable on the chain.
|
|
74
|
-
*
|
|
75
|
-
* @example
|
|
76
|
-
* ```ts
|
|
77
|
-
* import { getChainAddresses } from "@morpho-org/morpho-sdk/addresses";
|
|
78
|
-
* import { BundlerAction } from "@morpho-org/morpho-sdk/bundler";
|
|
79
|
-
*
|
|
80
|
-
* const { generalAdapter1 } = getChainAddresses(1).bundler3;
|
|
81
|
-
* const sender = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045";
|
|
82
|
-
*
|
|
83
|
-
* const tx = BundlerAction.encodeBundle(1, [
|
|
84
|
-
* {
|
|
85
|
-
* type: "nativeTransfer",
|
|
86
|
-
* args: [sender, generalAdapter1, 1_000000000000000000n],
|
|
87
|
-
* },
|
|
88
|
-
* ]);
|
|
89
|
-
* ```
|
|
90
|
-
*/
|
|
91
|
-
function encodeBundle(chainId, actions) {
|
|
92
|
-
const { bundler3: { bundler3 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
|
|
93
|
-
let valueState = {
|
|
94
|
-
value: 0n,
|
|
95
|
-
availableBundlerValue: 0n,
|
|
96
|
-
};
|
|
97
|
-
const encodedActions = [];
|
|
98
|
-
for (const action of actions) {
|
|
99
|
-
const encodedAction = encodeBundleAction({ chainId, action, valueState });
|
|
100
|
-
encodedActions.push(...encodedAction.calls);
|
|
101
|
-
valueState = encodedAction.valueState;
|
|
102
|
-
}
|
|
103
|
-
return {
|
|
104
|
-
to: bundler3,
|
|
105
|
-
value: valueState.value,
|
|
106
|
-
data: (0, viem_1.encodeFunctionData)({
|
|
107
|
-
abi: abis_js_1.bundler3Abi,
|
|
108
|
-
functionName: "multicall",
|
|
109
|
-
args: [encodedActions],
|
|
110
|
-
}),
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
BundlerAction.encodeBundle = encodeBundle;
|
|
114
|
-
/**
|
|
115
|
-
* Encodes a single supported Bundler3 action into one or more low-level
|
|
116
|
-
* Bundler3 calls.
|
|
117
|
-
*
|
|
118
|
-
* @param chainId - Chain where the action will execute.
|
|
119
|
-
* @param action - Bundler3 action to encode.
|
|
120
|
-
* @returns Encoded Bundler3 calls.
|
|
121
|
-
* @throws {BundlerErrors.MissingSignature} when a signature action is unsigned.
|
|
122
|
-
* @throws {BundlerErrors.UnexpectedAction} when the action is unavailable on the chain.
|
|
123
|
-
*
|
|
124
|
-
* @example
|
|
125
|
-
* ```ts
|
|
126
|
-
* import { BundlerAction } from "@morpho-org/morpho-sdk/bundler";
|
|
127
|
-
*
|
|
128
|
-
* const recipient = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045";
|
|
129
|
-
*
|
|
130
|
-
* const calls = BundlerAction.encode(1, {
|
|
131
|
-
* type: "wrapNative",
|
|
132
|
-
* args: [1_000000000000000000n, recipient],
|
|
133
|
-
* });
|
|
134
|
-
* ```
|
|
135
|
-
*/
|
|
136
|
-
function encode(chainId, action) {
|
|
137
|
-
const { type, args } = action;
|
|
138
|
-
switch (type) {
|
|
139
|
-
case "nativeTransfer": {
|
|
140
|
-
return BundlerAction.nativeTransfer(chainId, ...args);
|
|
141
|
-
}
|
|
142
|
-
case "erc20Transfer": {
|
|
143
|
-
return BundlerAction.erc20Transfer(...args);
|
|
144
|
-
}
|
|
145
|
-
case "erc20TransferFrom": {
|
|
146
|
-
return BundlerAction.erc20TransferFrom(chainId, ...args);
|
|
147
|
-
}
|
|
148
|
-
case "permit": {
|
|
149
|
-
const [sender, asset, amount, deadline, signature, skipRevert] = args;
|
|
150
|
-
if (signature == null)
|
|
151
|
-
throw new error_js_1.BundlerErrors.MissingSignature();
|
|
152
|
-
return BundlerAction.permit(chainId, sender, asset, amount, deadline, signature, skipRevert);
|
|
153
|
-
}
|
|
154
|
-
case "approve2": {
|
|
155
|
-
const [sender, permitSingle, signature, skipRevert] = args;
|
|
156
|
-
if (signature == null)
|
|
157
|
-
throw new error_js_1.BundlerErrors.MissingSignature();
|
|
158
|
-
return BundlerAction.approve2(chainId, sender, permitSingle, signature, skipRevert);
|
|
159
|
-
}
|
|
160
|
-
case "transferFrom2": {
|
|
161
|
-
return BundlerAction.transferFrom2(chainId, ...args);
|
|
162
|
-
}
|
|
163
|
-
case "erc4626Deposit": {
|
|
164
|
-
return BundlerAction.erc4626Deposit(chainId, ...args);
|
|
165
|
-
}
|
|
166
|
-
case "erc4626Redeem": {
|
|
167
|
-
return BundlerAction.erc4626Redeem(chainId, ...args);
|
|
168
|
-
}
|
|
169
|
-
case "morphoSetAuthorizationWithSig": {
|
|
170
|
-
const [authorization, signature, skipRevert] = args;
|
|
171
|
-
if (signature == null)
|
|
172
|
-
throw new error_js_1.BundlerErrors.MissingSignature();
|
|
173
|
-
return BundlerAction.morphoSetAuthorizationWithSig(chainId, authorization, signature, skipRevert);
|
|
174
|
-
}
|
|
175
|
-
case "morphoSupplyCollateral": {
|
|
176
|
-
const [market, amount, onBehalf, onMorphoSupplyCollateral, skipRevert] = args;
|
|
177
|
-
return BundlerAction.morphoSupplyCollateral(chainId, market, amount, onBehalf, onMorphoSupplyCollateral.flatMap(BundlerAction.encode.bind(null, chainId)), skipRevert);
|
|
178
|
-
}
|
|
179
|
-
case "morphoSupply": {
|
|
180
|
-
const [market, assets, shares, slippageAmount, onBehalf, onMorphoSupply, skipRevert,] = args;
|
|
181
|
-
return BundlerAction.morphoSupply(chainId, market, assets, shares, slippageAmount, onBehalf, onMorphoSupply.flatMap(BundlerAction.encode.bind(null, chainId)), skipRevert);
|
|
182
|
-
}
|
|
183
|
-
case "morphoBorrow": {
|
|
184
|
-
return BundlerAction.morphoBorrow(chainId, ...args);
|
|
185
|
-
}
|
|
186
|
-
case "morphoWithdraw": {
|
|
187
|
-
return BundlerAction.morphoWithdraw(chainId, ...args);
|
|
188
|
-
}
|
|
189
|
-
case "morphoRepay": {
|
|
190
|
-
const [market, assets, shares, maxSharePrice, onBehalf, onMorphoRepay, skipRevert,] = args;
|
|
191
|
-
return BundlerAction.morphoRepay(chainId, market, assets, shares, maxSharePrice, onBehalf, onMorphoRepay.flatMap(BundlerAction.encode.bind(null, chainId)), skipRevert);
|
|
192
|
-
}
|
|
193
|
-
case "morphoWithdrawCollateral": {
|
|
194
|
-
return BundlerAction.morphoWithdrawCollateral(chainId, ...args);
|
|
195
|
-
}
|
|
196
|
-
case "reallocateTo": {
|
|
197
|
-
return BundlerAction.publicAllocatorReallocateTo(chainId, ...args);
|
|
198
|
-
}
|
|
199
|
-
case "vaultV2BluePublicAllocatorReallocate": {
|
|
200
|
-
return BundlerAction.vaultV2BluePublicAllocatorReallocate(chainId, ...args);
|
|
201
|
-
}
|
|
202
|
-
case "vaultV2BluePublicAllocatorAllocateFromIdle": {
|
|
203
|
-
return BundlerAction.vaultV2BluePublicAllocatorAllocateFromIdle(chainId, ...args);
|
|
204
|
-
}
|
|
205
|
-
case "wrapNative": {
|
|
206
|
-
return BundlerAction.wrapNative(chainId, ...args);
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
BundlerAction.encode = encode;
|
|
211
|
-
function encodeBundleAction({ chainId, action, valueState, }) {
|
|
212
|
-
const { bundler3: { bundler3, generalAdapter1 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
|
|
213
|
-
let nextValueState = valueState;
|
|
214
|
-
if (action.type === "nativeTransfer") {
|
|
215
|
-
const [owner, recipient, amount] = action.args;
|
|
216
|
-
// A transfer into Bundler3 emits no inner call; it pre-funds later
|
|
217
|
-
// value-carrying calls in the same multicall or callback reentry.
|
|
218
|
-
if (!(0, viem_1.isAddressEqual)(owner, bundler3) &&
|
|
219
|
-
!(0, viem_1.isAddressEqual)(owner, generalAdapter1) &&
|
|
220
|
-
(0, viem_1.isAddressEqual)(recipient, bundler3)) {
|
|
221
|
-
nextValueState = addBundlerPrefund(nextValueState, amount);
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
const calls = BundlerAction.encode(chainId, action);
|
|
225
|
-
for (const call of calls) {
|
|
226
|
-
nextValueState = consumeCallValue(nextValueState, call);
|
|
227
|
-
}
|
|
228
|
-
if (action.type === "morphoSupplyCollateral") {
|
|
229
|
-
const [, , , onMorphoSupplyCollateral] = action.args;
|
|
230
|
-
for (const callbackAction of onMorphoSupplyCollateral) {
|
|
231
|
-
const encodedCallback = encodeBundleAction({
|
|
232
|
-
chainId,
|
|
233
|
-
action: callbackAction,
|
|
234
|
-
valueState: nextValueState,
|
|
235
|
-
});
|
|
236
|
-
nextValueState = encodedCallback.valueState;
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
if (action.type === "morphoSupply") {
|
|
240
|
-
const [, , , , , onMorphoSupply] = action.args;
|
|
241
|
-
for (const callbackAction of onMorphoSupply) {
|
|
242
|
-
const encodedCallback = encodeBundleAction({
|
|
243
|
-
chainId,
|
|
244
|
-
action: callbackAction,
|
|
245
|
-
valueState: nextValueState,
|
|
246
|
-
});
|
|
247
|
-
nextValueState = encodedCallback.valueState;
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
if (action.type === "morphoRepay") {
|
|
251
|
-
const [, , , , , onMorphoRepay] = action.args;
|
|
252
|
-
for (const callbackAction of onMorphoRepay) {
|
|
253
|
-
const encodedCallback = encodeBundleAction({
|
|
254
|
-
chainId,
|
|
255
|
-
action: callbackAction,
|
|
256
|
-
valueState: nextValueState,
|
|
257
|
-
});
|
|
258
|
-
nextValueState = encodedCallback.valueState;
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
return { calls, valueState: nextValueState };
|
|
262
|
-
}
|
|
263
|
-
/**
|
|
264
|
-
* Encodes a native-token transfer for Bundler3 execution.
|
|
265
|
-
*
|
|
266
|
-
* @remarks
|
|
267
|
-
* Transfers to Bundler3 are treated as bundle pre-funding and emit no inner
|
|
268
|
-
* call. Transfers whose `owner` is GeneralAdapter1 are encoded as
|
|
269
|
-
* `GeneralAdapter1.nativeTransfer(recipient, amount)` and always use
|
|
270
|
-
* `skipRevert: false`; the caller-supplied `skipRevert` argument applies
|
|
271
|
-
* only to direct native transfers from other owners.
|
|
272
|
-
*
|
|
273
|
-
* @param chainId - Chain where the action will execute.
|
|
274
|
-
* @param owner - Current native-token owner in the bundle.
|
|
275
|
-
* @param recipient - Native-token recipient.
|
|
276
|
-
* @param amount - Native-token amount in wei.
|
|
277
|
-
* @param skipRevert - Whether Bundler3 should tolerate a revert.
|
|
278
|
-
* @returns Encoded Bundler3 calls.
|
|
279
|
-
*
|
|
280
|
-
* @example
|
|
281
|
-
* ```ts
|
|
282
|
-
* import { BundlerAction } from "@morpho-org/morpho-sdk/bundler";
|
|
283
|
-
*
|
|
284
|
-
* const sender = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045";
|
|
285
|
-
* const recipient = "0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359";
|
|
286
|
-
*
|
|
287
|
-
* const calls = BundlerAction.nativeTransfer(
|
|
288
|
-
* 1,
|
|
289
|
-
* sender,
|
|
290
|
-
* recipient,
|
|
291
|
-
* 1_000000000000000000n,
|
|
292
|
-
* );
|
|
293
|
-
* ```
|
|
294
|
-
*/
|
|
295
|
-
// biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
|
|
296
|
-
function nativeTransfer(chainId, owner, recipient, amount, skipRevert = false) {
|
|
297
|
-
const { bundler3: { bundler3, generalAdapter1 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
|
|
298
|
-
if ((0, viem_1.isAddressEqual)(recipient, bundler3))
|
|
299
|
-
return [];
|
|
300
|
-
if ((0, viem_1.isAddressEqual)(owner, generalAdapter1)) {
|
|
301
|
-
return [
|
|
302
|
-
{
|
|
303
|
-
to: generalAdapter1,
|
|
304
|
-
data: (0, viem_1.encodeFunctionData)({
|
|
305
|
-
abi: abis_js_1.coreAdapterAbi,
|
|
306
|
-
functionName: "nativeTransfer",
|
|
307
|
-
args: [recipient, amount],
|
|
308
|
-
}),
|
|
309
|
-
value: 0n,
|
|
310
|
-
skipRevert: false,
|
|
311
|
-
callbackHash: viem_1.zeroHash,
|
|
312
|
-
},
|
|
313
|
-
];
|
|
314
|
-
}
|
|
315
|
-
return [
|
|
316
|
-
{
|
|
317
|
-
to: recipient,
|
|
318
|
-
data: "0x",
|
|
319
|
-
value: amount,
|
|
320
|
-
skipRevert,
|
|
321
|
-
callbackHash: viem_1.zeroHash,
|
|
322
|
-
},
|
|
323
|
-
];
|
|
324
|
-
}
|
|
325
|
-
BundlerAction.nativeTransfer = nativeTransfer;
|
|
326
|
-
/**
|
|
327
|
-
* Encodes an ERC20 transfer from the given adapter.
|
|
328
|
-
*
|
|
329
|
-
* @param asset - ERC20 token to transfer.
|
|
330
|
-
* @param recipient - Recipient of the transferred tokens.
|
|
331
|
-
* @param amount - Token amount to transfer.
|
|
332
|
-
* @param adapter - Adapter that currently holds the tokens.
|
|
333
|
-
* @param skipRevert - Whether Bundler3 should tolerate a revert.
|
|
334
|
-
* @returns Encoded Bundler3 calls.
|
|
335
|
-
*
|
|
336
|
-
* @example
|
|
337
|
-
* ```ts
|
|
338
|
-
* import { getChainAddresses } from "@morpho-org/morpho-sdk/addresses";
|
|
339
|
-
* import { BundlerAction } from "@morpho-org/morpho-sdk/bundler";
|
|
340
|
-
*
|
|
341
|
-
* const adapter = getChainAddresses(1).bundler3.generalAdapter1;
|
|
342
|
-
* const asset = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48";
|
|
343
|
-
* const recipient = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045";
|
|
344
|
-
*
|
|
345
|
-
* const calls = BundlerAction.erc20Transfer(
|
|
346
|
-
* asset,
|
|
347
|
-
* recipient,
|
|
348
|
-
* 100n,
|
|
349
|
-
* adapter,
|
|
350
|
-
* );
|
|
351
|
-
* ```
|
|
352
|
-
*/
|
|
353
|
-
// biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
|
|
354
|
-
function erc20Transfer(asset, recipient, amount, adapter, skipRevert = false) {
|
|
355
|
-
return [
|
|
356
|
-
{
|
|
357
|
-
to: adapter,
|
|
358
|
-
data: (0, viem_1.encodeFunctionData)({
|
|
359
|
-
abi: abis_js_1.coreAdapterAbi,
|
|
360
|
-
functionName: "erc20Transfer",
|
|
361
|
-
args: [asset, recipient, amount],
|
|
362
|
-
}),
|
|
363
|
-
value: 0n,
|
|
364
|
-
skipRevert,
|
|
365
|
-
callbackHash: viem_1.zeroHash,
|
|
366
|
-
},
|
|
367
|
-
];
|
|
368
|
-
}
|
|
369
|
-
BundlerAction.erc20Transfer = erc20Transfer;
|
|
370
|
-
/**
|
|
371
|
-
* Encodes a GeneralAdapter1 ERC20 `transferFrom`.
|
|
372
|
-
*
|
|
373
|
-
* @param chainId - Chain where the action will execute.
|
|
374
|
-
* @param asset - ERC20 token to transfer.
|
|
375
|
-
* @param amount - Token amount to transfer.
|
|
376
|
-
* @param recipient - Recipient of the transferred tokens.
|
|
377
|
-
* @param skipRevert - Whether Bundler3 should tolerate a revert.
|
|
378
|
-
* @returns Encoded Bundler3 calls.
|
|
379
|
-
*
|
|
380
|
-
* @example
|
|
381
|
-
* ```ts
|
|
382
|
-
* import { BundlerAction } from "@morpho-org/morpho-sdk/bundler";
|
|
383
|
-
*
|
|
384
|
-
* const asset = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48";
|
|
385
|
-
* const recipient = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045";
|
|
386
|
-
*
|
|
387
|
-
* const calls = BundlerAction.erc20TransferFrom(
|
|
388
|
-
* 1,
|
|
389
|
-
* asset,
|
|
390
|
-
* 100n,
|
|
391
|
-
* recipient,
|
|
392
|
-
* );
|
|
393
|
-
* ```
|
|
394
|
-
*/
|
|
395
|
-
// biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
|
|
396
|
-
function erc20TransferFrom(chainId, asset, amount, recipient, skipRevert = false) {
|
|
397
|
-
const { bundler3: { generalAdapter1 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
|
|
398
|
-
return [
|
|
399
|
-
{
|
|
400
|
-
to: generalAdapter1,
|
|
401
|
-
data: (0, viem_1.encodeFunctionData)({
|
|
402
|
-
abi: abis_js_1.generalAdapter1Abi,
|
|
403
|
-
functionName: "erc20TransferFrom",
|
|
404
|
-
args: [asset, recipient, amount],
|
|
405
|
-
}),
|
|
406
|
-
value: 0n,
|
|
407
|
-
skipRevert,
|
|
408
|
-
callbackHash: viem_1.zeroHash,
|
|
409
|
-
},
|
|
410
|
-
];
|
|
411
|
-
}
|
|
412
|
-
BundlerAction.erc20TransferFrom = erc20TransferFrom;
|
|
413
|
-
/**
|
|
414
|
-
* Encodes an ERC20 permit for GeneralAdapter1 spending.
|
|
415
|
-
*
|
|
416
|
-
* @param chainId - Chain where the action will execute.
|
|
417
|
-
* @param owner - Token owner signing the permit.
|
|
418
|
-
* @param asset - ERC20 token being permitted.
|
|
419
|
-
* @param amount - Allowance amount.
|
|
420
|
-
* @param deadline - Permit deadline timestamp.
|
|
421
|
-
* @param signature - Owner signature.
|
|
422
|
-
* @param skipRevert - Whether Bundler3 should tolerate a revert.
|
|
423
|
-
* @returns Encoded Bundler3 calls.
|
|
424
|
-
*
|
|
425
|
-
* @example
|
|
426
|
-
* ```ts
|
|
427
|
-
* import { BundlerAction } from "@morpho-org/morpho-sdk/bundler";
|
|
428
|
-
*
|
|
429
|
-
* const owner = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045";
|
|
430
|
-
* const asset = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48";
|
|
431
|
-
* const signature =
|
|
432
|
-
* "0x111111111111111111111111111111111111111111111111111111111111111122222222222222222222222222222222222222222222222222222222222222221b";
|
|
433
|
-
*
|
|
434
|
-
* const calls = BundlerAction.permit(
|
|
435
|
-
* 1,
|
|
436
|
-
* owner,
|
|
437
|
-
* asset,
|
|
438
|
-
* 100n,
|
|
439
|
-
* 1_900_000_000n,
|
|
440
|
-
* signature,
|
|
441
|
-
* );
|
|
442
|
-
* ```
|
|
443
|
-
*/
|
|
444
|
-
// biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
|
|
445
|
-
function permit(chainId, owner, asset, amount, deadline, signature, skipRevert = true) {
|
|
446
|
-
const { bundler3: { generalAdapter1 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
|
|
447
|
-
const { r, s, yParity } = (0, viem_1.parseSignature)(toSignatureHex(signature));
|
|
448
|
-
return [
|
|
449
|
-
{
|
|
450
|
-
to: asset,
|
|
451
|
-
data: (0, viem_1.encodeFunctionData)({
|
|
452
|
-
abi: blue_sdk_viem_1.erc2612Abi,
|
|
453
|
-
functionName: "permit",
|
|
454
|
-
args: [owner, generalAdapter1, amount, deadline, yParity + 27, r, s],
|
|
455
|
-
}),
|
|
456
|
-
value: 0n,
|
|
457
|
-
skipRevert,
|
|
458
|
-
callbackHash: viem_1.zeroHash,
|
|
459
|
-
},
|
|
460
|
-
];
|
|
461
|
-
}
|
|
462
|
-
BundlerAction.permit = permit;
|
|
463
|
-
/**
|
|
464
|
-
* Encodes a Permit2 approval for GeneralAdapter1 spending.
|
|
465
|
-
*
|
|
466
|
-
* @param chainId - Chain where the action will execute.
|
|
467
|
-
* @param owner - Token owner signing the Permit2 payload.
|
|
468
|
-
* @param permitSingle - Permit2 allowance payload.
|
|
469
|
-
* @param signature - Owner signature.
|
|
470
|
-
* @param skipRevert - Whether Bundler3 should tolerate a revert.
|
|
471
|
-
* @returns Encoded Bundler3 calls.
|
|
472
|
-
* @throws {BundlerErrors.UnexpectedAction} when Permit2 is unavailable on the chain.
|
|
473
|
-
*
|
|
474
|
-
* @example
|
|
475
|
-
* ```ts
|
|
476
|
-
* import { BundlerAction } from "@morpho-org/morpho-sdk/bundler";
|
|
477
|
-
*
|
|
478
|
-
* const owner = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045";
|
|
479
|
-
* const token = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48";
|
|
480
|
-
* const signature =
|
|
481
|
-
* "0x111111111111111111111111111111111111111111111111111111111111111122222222222222222222222222222222222222222222222222222222222222221b";
|
|
482
|
-
*
|
|
483
|
-
* const calls = BundlerAction.approve2(
|
|
484
|
-
* 1,
|
|
485
|
-
* owner,
|
|
486
|
-
* {
|
|
487
|
-
* details: {
|
|
488
|
-
* token,
|
|
489
|
-
* amount: 100n,
|
|
490
|
-
* expiration: 1_900_000_000,
|
|
491
|
-
* nonce: 0,
|
|
492
|
-
* },
|
|
493
|
-
* sigDeadline: 1_900_000_000n,
|
|
494
|
-
* },
|
|
495
|
-
* signature,
|
|
496
|
-
* );
|
|
497
|
-
* ```
|
|
498
|
-
*/
|
|
499
|
-
// biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
|
|
500
|
-
function approve2(chainId, owner, permitSingle, signature, skipRevert = true) {
|
|
501
|
-
const { permit2, bundler3: { generalAdapter1 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
|
|
502
|
-
if (permit2 == null) {
|
|
503
|
-
throw new error_js_1.BundlerErrors.UnexpectedAction("approve2", chainId);
|
|
504
|
-
}
|
|
505
|
-
return [
|
|
506
|
-
{
|
|
507
|
-
to: permit2,
|
|
508
|
-
data: (0, viem_1.encodeFunctionData)({
|
|
509
|
-
abi: blue_sdk_viem_1.permit2Abi,
|
|
510
|
-
functionName: "permit",
|
|
511
|
-
args: [
|
|
512
|
-
owner,
|
|
513
|
-
{
|
|
514
|
-
...permitSingle,
|
|
515
|
-
spender: generalAdapter1,
|
|
516
|
-
},
|
|
517
|
-
toSignatureHex(signature),
|
|
518
|
-
],
|
|
519
|
-
}),
|
|
520
|
-
value: 0n,
|
|
521
|
-
skipRevert,
|
|
522
|
-
callbackHash: viem_1.zeroHash,
|
|
523
|
-
},
|
|
524
|
-
];
|
|
525
|
-
}
|
|
526
|
-
BundlerAction.approve2 = approve2;
|
|
527
|
-
/**
|
|
528
|
-
* Encodes a GeneralAdapter1 Permit2 transfer.
|
|
529
|
-
*
|
|
530
|
-
* @param chainId - Chain where the action will execute.
|
|
531
|
-
* @param asset - ERC20 token to transfer through Permit2.
|
|
532
|
-
* @param amount - Token amount to transfer.
|
|
533
|
-
* @param recipient - Recipient of the transferred tokens.
|
|
534
|
-
* @param skipRevert - Whether Bundler3 should tolerate a revert.
|
|
535
|
-
* @returns Encoded Bundler3 calls.
|
|
536
|
-
*
|
|
537
|
-
* @example
|
|
538
|
-
* ```ts
|
|
539
|
-
* import { BundlerAction } from "@morpho-org/morpho-sdk/bundler";
|
|
540
|
-
*
|
|
541
|
-
* const asset = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48";
|
|
542
|
-
* const recipient = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045";
|
|
543
|
-
*
|
|
544
|
-
* const calls = BundlerAction.transferFrom2(
|
|
545
|
-
* 1,
|
|
546
|
-
* asset,
|
|
547
|
-
* 100n,
|
|
548
|
-
* recipient,
|
|
549
|
-
* );
|
|
550
|
-
* ```
|
|
551
|
-
*/
|
|
552
|
-
// biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
|
|
553
|
-
function transferFrom2(chainId, asset, amount, recipient, skipRevert = false) {
|
|
554
|
-
const { bundler3: { generalAdapter1 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
|
|
555
|
-
return [
|
|
556
|
-
{
|
|
557
|
-
to: generalAdapter1,
|
|
558
|
-
data: (0, viem_1.encodeFunctionData)({
|
|
559
|
-
abi: abis_js_1.generalAdapter1Abi,
|
|
560
|
-
functionName: "permit2TransferFrom",
|
|
561
|
-
args: [asset, recipient, amount],
|
|
562
|
-
}),
|
|
563
|
-
value: 0n,
|
|
564
|
-
skipRevert,
|
|
565
|
-
callbackHash: viem_1.zeroHash,
|
|
566
|
-
},
|
|
567
|
-
];
|
|
568
|
-
}
|
|
569
|
-
BundlerAction.transferFrom2 = transferFrom2;
|
|
570
|
-
/**
|
|
571
|
-
* Encodes a GeneralAdapter1 ERC4626 deposit.
|
|
572
|
-
*
|
|
573
|
-
* @param chainId - Chain where the action will execute.
|
|
574
|
-
* @param erc4626 - ERC4626 vault address.
|
|
575
|
-
* @param assets - Asset amount to deposit.
|
|
576
|
-
* @param maxSharePrice - Maximum accepted share price in RAY.
|
|
577
|
-
* @param receiver - Recipient of minted vault shares.
|
|
578
|
-
* @param skipRevert - Whether Bundler3 should tolerate a revert.
|
|
579
|
-
* @returns Encoded Bundler3 calls.
|
|
580
|
-
*
|
|
581
|
-
* @example
|
|
582
|
-
* ```ts
|
|
583
|
-
* import { BundlerAction } from "@morpho-org/morpho-sdk/bundler";
|
|
584
|
-
*
|
|
585
|
-
* const vault = "0x186514400e52270cef3D80e1c6F8d10A75d47344";
|
|
586
|
-
* const recipient = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045";
|
|
587
|
-
*
|
|
588
|
-
* const calls = BundlerAction.erc4626Deposit(
|
|
589
|
-
* 1,
|
|
590
|
-
* vault,
|
|
591
|
-
* 100n,
|
|
592
|
-
* 1_000000000000000000000000000n,
|
|
593
|
-
* recipient,
|
|
594
|
-
* );
|
|
595
|
-
* ```
|
|
596
|
-
*/
|
|
597
|
-
// biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
|
|
598
|
-
function erc4626Deposit(chainId, erc4626, assets, maxSharePrice, receiver, skipRevert = false) {
|
|
599
|
-
const { bundler3: { generalAdapter1 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
|
|
600
|
-
return [
|
|
601
|
-
{
|
|
602
|
-
to: generalAdapter1,
|
|
603
|
-
data: (0, viem_1.encodeFunctionData)({
|
|
604
|
-
abi: abis_js_1.generalAdapter1Abi,
|
|
605
|
-
functionName: "erc4626Deposit",
|
|
606
|
-
args: [erc4626, assets, maxSharePrice, receiver],
|
|
607
|
-
}),
|
|
608
|
-
value: 0n,
|
|
609
|
-
skipRevert,
|
|
610
|
-
callbackHash: viem_1.zeroHash,
|
|
611
|
-
},
|
|
612
|
-
];
|
|
613
|
-
}
|
|
614
|
-
BundlerAction.erc4626Deposit = erc4626Deposit;
|
|
615
|
-
/**
|
|
616
|
-
* Encodes a GeneralAdapter1 ERC4626 redeem.
|
|
617
|
-
*
|
|
618
|
-
* @param chainId - Chain where the action will execute.
|
|
619
|
-
* @param erc4626 - ERC4626 vault address.
|
|
620
|
-
* @param shares - Share amount to redeem.
|
|
621
|
-
* @param minSharePrice - Minimum accepted share price in RAY.
|
|
622
|
-
* @param receiver - Recipient of redeemed assets.
|
|
623
|
-
* @param owner - Owner of the shares being redeemed.
|
|
624
|
-
* @param skipRevert - Whether Bundler3 should tolerate a revert.
|
|
625
|
-
* @returns Encoded Bundler3 calls.
|
|
626
|
-
*
|
|
627
|
-
* @example
|
|
628
|
-
* ```ts
|
|
629
|
-
* import { BundlerAction } from "@morpho-org/morpho-sdk/bundler";
|
|
630
|
-
*
|
|
631
|
-
* const vault = "0x186514400e52270cef3D80e1c6F8d10A75d47344";
|
|
632
|
-
* const recipient = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045";
|
|
633
|
-
* const owner = recipient;
|
|
634
|
-
*
|
|
635
|
-
* const calls = BundlerAction.erc4626Redeem(
|
|
636
|
-
* 1,
|
|
637
|
-
* vault,
|
|
638
|
-
* 100n,
|
|
639
|
-
* 900000000000000000000000000n,
|
|
640
|
-
* recipient,
|
|
641
|
-
* owner,
|
|
642
|
-
* );
|
|
643
|
-
* ```
|
|
644
|
-
*/
|
|
645
|
-
// biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
|
|
646
|
-
function erc4626Redeem(chainId, erc4626, shares, minSharePrice, receiver, owner, skipRevert = false) {
|
|
647
|
-
const { bundler3: { generalAdapter1 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
|
|
648
|
-
return [
|
|
649
|
-
{
|
|
650
|
-
to: generalAdapter1,
|
|
651
|
-
data: (0, viem_1.encodeFunctionData)({
|
|
652
|
-
abi: abis_js_1.generalAdapter1Abi,
|
|
653
|
-
functionName: "erc4626Redeem",
|
|
654
|
-
args: [erc4626, shares, minSharePrice, receiver, owner],
|
|
655
|
-
}),
|
|
656
|
-
value: 0n,
|
|
657
|
-
skipRevert,
|
|
658
|
-
callbackHash: viem_1.zeroHash,
|
|
659
|
-
},
|
|
660
|
-
];
|
|
661
|
-
}
|
|
662
|
-
BundlerAction.erc4626Redeem = erc4626Redeem;
|
|
663
|
-
/**
|
|
664
|
-
* Encodes a Morpho Blue `setAuthorizationWithSig` call that submits a signed authorization.
|
|
665
|
-
*
|
|
666
|
-
* Lets a bundle grant `authorization.authorized` (GeneralAdapter1) operator rights on Morpho
|
|
667
|
-
* on behalf of `authorization.authorizer` without a separate `setAuthorization` transaction.
|
|
668
|
-
*
|
|
669
|
-
* @param chainId - Chain where the action will execute.
|
|
670
|
-
* @param authorization - The Morpho authorization payload covered by the signature.
|
|
671
|
-
* @param signature - The owner's EIP-712 signature over the authorization typed data, as a hex
|
|
672
|
-
* string or a viem `Signature` object.
|
|
673
|
-
* @param skipRevert - Whether Bundler3 should tolerate a revert. Defaults to `true`, matching
|
|
674
|
-
* the convention for already-authorized accounts (the call reverts harmlessly).
|
|
675
|
-
* @returns Encoded Bundler3 calls.
|
|
676
|
-
* @throws {BundlerErrors.UnexpectedSignature} when `authorization.authorized` is not the chain's
|
|
677
|
-
* `GeneralAdapter1` — the only operator this bundled path may grant rights to.
|
|
678
|
-
*
|
|
679
|
-
* @example
|
|
680
|
-
* ```ts
|
|
681
|
-
* import { getChainAddresses } from "@morpho-org/morpho-sdk/addresses";
|
|
682
|
-
* import { BundlerAction } from "@morpho-org/morpho-sdk/bundler";
|
|
683
|
-
*
|
|
684
|
-
* const { generalAdapter1 } = getChainAddresses(1).bundler3;
|
|
685
|
-
* const owner = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045";
|
|
686
|
-
* const signature =
|
|
687
|
-
* "0x111111111111111111111111111111111111111111111111111111111111111122222222222222222222222222222222222222222222222222222222222222221b";
|
|
688
|
-
*
|
|
689
|
-
* const calls = BundlerAction.morphoSetAuthorizationWithSig(
|
|
690
|
-
* 1,
|
|
691
|
-
* {
|
|
692
|
-
* authorizer: owner,
|
|
693
|
-
* authorized: generalAdapter1,
|
|
694
|
-
* isAuthorized: true,
|
|
695
|
-
* nonce: 0n,
|
|
696
|
-
* deadline: 1_900_000_000n,
|
|
697
|
-
* },
|
|
698
|
-
* signature,
|
|
699
|
-
* );
|
|
700
|
-
* ```
|
|
701
|
-
*/
|
|
702
|
-
// biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
|
|
703
|
-
function morphoSetAuthorizationWithSig(chainId, authorization, signature, skipRevert = true) {
|
|
704
|
-
const { morpho, bundler3: { generalAdapter1 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
|
|
705
|
-
const { r, s, yParity } = (0, viem_1.parseSignature)(toSignatureHex(signature));
|
|
706
|
-
if (!(0, viem_1.isAddressEqual)(authorization.authorized, generalAdapter1)) {
|
|
707
|
-
throw new error_js_1.BundlerErrors.UnexpectedSignature(authorization.authorized);
|
|
708
|
-
}
|
|
709
|
-
return [
|
|
710
|
-
{
|
|
711
|
-
to: morpho,
|
|
712
|
-
data: (0, viem_1.encodeFunctionData)({
|
|
713
|
-
abi: blue_sdk_viem_1.blueAbi,
|
|
714
|
-
functionName: "setAuthorizationWithSig",
|
|
715
|
-
args: [authorization, { v: yParity + 27, r, s }],
|
|
716
|
-
}),
|
|
717
|
-
value: 0n,
|
|
718
|
-
skipRevert,
|
|
719
|
-
callbackHash: viem_1.zeroHash,
|
|
720
|
-
},
|
|
721
|
-
];
|
|
722
|
-
}
|
|
723
|
-
BundlerAction.morphoSetAuthorizationWithSig = morphoSetAuthorizationWithSig;
|
|
724
|
-
/**
|
|
725
|
-
* Encodes a GeneralAdapter1 Morpho Blue supply-collateral call.
|
|
726
|
-
*
|
|
727
|
-
* @param chainId - Chain where the action will execute.
|
|
728
|
-
* @param market - Morpho Blue market parameters.
|
|
729
|
-
* @param assets - Collateral asset amount to supply.
|
|
730
|
-
* @param onBehalf - Account receiving the collateral position.
|
|
731
|
-
* @param callbackCalls - Calls executed in Morpho's callback.
|
|
732
|
-
* @param skipRevert - Whether Bundler3 should tolerate a revert.
|
|
733
|
-
* @returns Encoded Bundler3 calls.
|
|
734
|
-
*
|
|
735
|
-
* @example
|
|
736
|
-
* ```ts
|
|
737
|
-
* import { BundlerAction } from "@morpho-org/morpho-sdk/bundler";
|
|
738
|
-
*
|
|
739
|
-
* const loanToken = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48";
|
|
740
|
-
* const collateralToken = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2";
|
|
741
|
-
* const oracle = "0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419";
|
|
742
|
-
* const irm = "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC";
|
|
743
|
-
* const onBehalf = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045";
|
|
744
|
-
* const marketParams = {
|
|
745
|
-
* loanToken,
|
|
746
|
-
* collateralToken,
|
|
747
|
-
* oracle,
|
|
748
|
-
* irm,
|
|
749
|
-
* lltv: 860_000000000000000000n,
|
|
750
|
-
* };
|
|
751
|
-
*
|
|
752
|
-
* const calls = BundlerAction.morphoSupplyCollateral(
|
|
753
|
-
* 1,
|
|
754
|
-
* marketParams,
|
|
755
|
-
* 100n,
|
|
756
|
-
* onBehalf,
|
|
757
|
-
* [],
|
|
758
|
-
* );
|
|
759
|
-
* ```
|
|
760
|
-
*/
|
|
761
|
-
// biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
|
|
762
|
-
function morphoSupplyCollateral(chainId, market, assets, onBehalf, callbackCalls, skipRevert = false) {
|
|
763
|
-
const { bundler3: { generalAdapter1 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
|
|
764
|
-
const { callbackHash, reenterData } = encodeCallbackCalls(callbackCalls);
|
|
765
|
-
return [
|
|
766
|
-
{
|
|
767
|
-
to: generalAdapter1,
|
|
768
|
-
data: (0, viem_1.encodeFunctionData)({
|
|
769
|
-
abi: abis_js_1.generalAdapter1Abi,
|
|
770
|
-
functionName: "morphoSupplyCollateral",
|
|
771
|
-
args: [market, assets, onBehalf, reenterData],
|
|
772
|
-
}),
|
|
773
|
-
value: 0n,
|
|
774
|
-
skipRevert,
|
|
775
|
-
callbackHash,
|
|
776
|
-
},
|
|
777
|
-
];
|
|
778
|
-
}
|
|
779
|
-
BundlerAction.morphoSupplyCollateral = morphoSupplyCollateral;
|
|
780
|
-
/**
|
|
781
|
-
* Encodes a GeneralAdapter1 Morpho Blue supply call.
|
|
782
|
-
*
|
|
783
|
-
* @param chainId - Chain where the action will execute.
|
|
784
|
-
* @param market - Morpho Blue market parameters.
|
|
785
|
-
* @param assets - Supply asset amount.
|
|
786
|
-
* @param shares - Supply share amount.
|
|
787
|
-
* @param slippageAmount - Slippage guard amount (max share price in RAY for share-price slippage).
|
|
788
|
-
* @param onBehalf - Account receiving the supply position.
|
|
789
|
-
* @param callbackCalls - Calls executed in Morpho's callback.
|
|
790
|
-
* @param skipRevert - Whether Bundler3 should tolerate a revert.
|
|
791
|
-
* @returns Encoded Bundler3 calls.
|
|
792
|
-
*
|
|
793
|
-
* @example
|
|
794
|
-
* ```ts
|
|
795
|
-
* import { BundlerAction } from "@morpho-org/morpho-sdk/bundler";
|
|
796
|
-
*
|
|
797
|
-
* const loanToken = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48";
|
|
798
|
-
* const collateralToken = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2";
|
|
799
|
-
* const oracle = "0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419";
|
|
800
|
-
* const irm = "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC";
|
|
801
|
-
* const onBehalf = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045";
|
|
802
|
-
* const marketParams = {
|
|
803
|
-
* loanToken,
|
|
804
|
-
* collateralToken,
|
|
805
|
-
* oracle,
|
|
806
|
-
* irm,
|
|
807
|
-
* lltv: 860_000000000000000000n,
|
|
808
|
-
* };
|
|
809
|
-
*
|
|
810
|
-
* const calls = BundlerAction.morphoSupply(
|
|
811
|
-
* 1,
|
|
812
|
-
* marketParams,
|
|
813
|
-
* 100n,
|
|
814
|
-
* 0n,
|
|
815
|
-
* 1_010000000000000000000000000n,
|
|
816
|
-
* onBehalf,
|
|
817
|
-
* [],
|
|
818
|
-
* );
|
|
819
|
-
* ```
|
|
820
|
-
*/
|
|
821
|
-
// biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
|
|
822
|
-
function morphoSupply(chainId, market, assets, shares, slippageAmount, onBehalf, callbackCalls, skipRevert = false) {
|
|
823
|
-
const { bundler3: { generalAdapter1 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
|
|
824
|
-
const { callbackHash, reenterData } = encodeCallbackCalls(callbackCalls);
|
|
825
|
-
return [
|
|
826
|
-
{
|
|
827
|
-
to: generalAdapter1,
|
|
828
|
-
data: (0, viem_1.encodeFunctionData)({
|
|
829
|
-
abi: abis_js_1.generalAdapter1Abi,
|
|
830
|
-
functionName: "morphoSupply",
|
|
831
|
-
args: [market, assets, shares, slippageAmount, onBehalf, reenterData],
|
|
832
|
-
}),
|
|
833
|
-
value: 0n,
|
|
834
|
-
skipRevert,
|
|
835
|
-
callbackHash,
|
|
836
|
-
},
|
|
837
|
-
];
|
|
838
|
-
}
|
|
839
|
-
BundlerAction.morphoSupply = morphoSupply;
|
|
840
|
-
/**
|
|
841
|
-
* Encodes a GeneralAdapter1 Morpho Blue borrow call.
|
|
842
|
-
*
|
|
843
|
-
* @param chainId - Chain where the action will execute.
|
|
844
|
-
* @param market - Morpho Blue market parameters.
|
|
845
|
-
* @param assets - Borrow asset amount.
|
|
846
|
-
* @param shares - Borrow share amount.
|
|
847
|
-
* @param minSharePrice - Minimum amount of borrowed assets per borrow share minted, scaled by 1e27.
|
|
848
|
-
* @param receiver - Recipient of borrowed assets.
|
|
849
|
-
* @param skipRevert - Whether Bundler3 should tolerate a revert.
|
|
850
|
-
* @returns Encoded Bundler3 calls.
|
|
851
|
-
*
|
|
852
|
-
* @example
|
|
853
|
-
* ```ts
|
|
854
|
-
* import { BundlerAction } from "@morpho-org/morpho-sdk/bundler";
|
|
855
|
-
*
|
|
856
|
-
* const loanToken = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48";
|
|
857
|
-
* const collateralToken = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2";
|
|
858
|
-
* const oracle = "0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419";
|
|
859
|
-
* const irm = "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC";
|
|
860
|
-
* const receiver = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045";
|
|
861
|
-
* const marketParams = {
|
|
862
|
-
* loanToken,
|
|
863
|
-
* collateralToken,
|
|
864
|
-
* oracle,
|
|
865
|
-
* irm,
|
|
866
|
-
* lltv: 860_000000000000000000n,
|
|
867
|
-
* };
|
|
868
|
-
*
|
|
869
|
-
* const calls = BundlerAction.morphoBorrow(
|
|
870
|
-
* 1,
|
|
871
|
-
* marketParams,
|
|
872
|
-
* 100n,
|
|
873
|
-
* 0n,
|
|
874
|
-
* 1_000000000000000000000000000n,
|
|
875
|
-
* receiver,
|
|
876
|
-
* );
|
|
877
|
-
* ```
|
|
878
|
-
*/
|
|
879
|
-
// biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
|
|
880
|
-
function morphoBorrow(chainId, market, assets, shares, minSharePrice, receiver, skipRevert = false) {
|
|
881
|
-
const { bundler3: { generalAdapter1 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
|
|
882
|
-
return [
|
|
883
|
-
{
|
|
884
|
-
to: generalAdapter1,
|
|
885
|
-
data: (0, viem_1.encodeFunctionData)({
|
|
886
|
-
abi: abis_js_1.generalAdapter1Abi,
|
|
887
|
-
functionName: "morphoBorrow",
|
|
888
|
-
args: [market, assets, shares, minSharePrice, receiver],
|
|
889
|
-
}),
|
|
890
|
-
value: 0n,
|
|
891
|
-
skipRevert,
|
|
892
|
-
callbackHash: viem_1.zeroHash,
|
|
893
|
-
},
|
|
894
|
-
];
|
|
895
|
-
}
|
|
896
|
-
BundlerAction.morphoBorrow = morphoBorrow;
|
|
897
|
-
/**
|
|
898
|
-
* Encodes a GeneralAdapter1 Morpho Blue repay call.
|
|
899
|
-
*
|
|
900
|
-
* @param chainId - Chain where the action will execute.
|
|
901
|
-
* @param market - Morpho Blue market parameters.
|
|
902
|
-
* @param assets - Repay asset amount.
|
|
903
|
-
* @param shares - Repay share amount.
|
|
904
|
-
* @param maxSharePrice - Maximum amount of repaid assets per borrow share redeemed, scaled by 1e27.
|
|
905
|
-
* @param onBehalf - Account whose borrow is repaid.
|
|
906
|
-
* @param callbackCalls - Calls executed in Morpho's callback.
|
|
907
|
-
* @param skipRevert - Whether Bundler3 should tolerate a revert.
|
|
908
|
-
* @returns Encoded Bundler3 calls.
|
|
909
|
-
*
|
|
910
|
-
* @example
|
|
911
|
-
* ```ts
|
|
912
|
-
* import { BundlerAction } from "@morpho-org/morpho-sdk/bundler";
|
|
913
|
-
*
|
|
914
|
-
* const loanToken = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48";
|
|
915
|
-
* const collateralToken = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2";
|
|
916
|
-
* const oracle = "0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419";
|
|
917
|
-
* const irm = "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC";
|
|
918
|
-
* const onBehalf = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045";
|
|
919
|
-
* const marketParams = {
|
|
920
|
-
* loanToken,
|
|
921
|
-
* collateralToken,
|
|
922
|
-
* oracle,
|
|
923
|
-
* irm,
|
|
924
|
-
* lltv: 860_000000000000000000n,
|
|
925
|
-
* };
|
|
926
|
-
*
|
|
927
|
-
* const calls = BundlerAction.morphoRepay(
|
|
928
|
-
* 1,
|
|
929
|
-
* marketParams,
|
|
930
|
-
* 100n,
|
|
931
|
-
* 0n,
|
|
932
|
-
* 1_000000000000000000000000000n,
|
|
933
|
-
* onBehalf,
|
|
934
|
-
* [],
|
|
935
|
-
* );
|
|
936
|
-
* ```
|
|
937
|
-
*/
|
|
938
|
-
// biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
|
|
939
|
-
function morphoRepay(chainId, market, assets, shares, maxSharePrice, onBehalf, callbackCalls, skipRevert = false) {
|
|
940
|
-
const { bundler3: { generalAdapter1 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
|
|
941
|
-
const { callbackHash, reenterData } = encodeCallbackCalls(callbackCalls);
|
|
942
|
-
return [
|
|
943
|
-
{
|
|
944
|
-
to: generalAdapter1,
|
|
945
|
-
data: (0, viem_1.encodeFunctionData)({
|
|
946
|
-
abi: abis_js_1.generalAdapter1Abi,
|
|
947
|
-
functionName: "morphoRepay",
|
|
948
|
-
args: [market, assets, shares, maxSharePrice, onBehalf, reenterData],
|
|
949
|
-
}),
|
|
950
|
-
value: 0n,
|
|
951
|
-
skipRevert,
|
|
952
|
-
callbackHash,
|
|
953
|
-
},
|
|
954
|
-
];
|
|
955
|
-
}
|
|
956
|
-
BundlerAction.morphoRepay = morphoRepay;
|
|
957
|
-
/**
|
|
958
|
-
* Encodes a GeneralAdapter1 Morpho Blue withdraw call.
|
|
959
|
-
*
|
|
960
|
-
* @param chainId - Chain where the action will execute.
|
|
961
|
-
* @param market - Morpho Blue market parameters.
|
|
962
|
-
* @param assets - Withdraw asset amount.
|
|
963
|
-
* @param shares - Withdraw share amount.
|
|
964
|
-
* @param slippageAmount - Slippage guard amount (min share price in RAY for share-price slippage).
|
|
965
|
-
* @param receiver - Recipient of withdrawn assets.
|
|
966
|
-
* @param skipRevert - Whether Bundler3 should tolerate a revert.
|
|
967
|
-
* @returns Encoded Bundler3 calls.
|
|
968
|
-
*
|
|
969
|
-
* @example
|
|
970
|
-
* ```ts
|
|
971
|
-
* import { BundlerAction } from "@morpho-org/morpho-sdk/bundler";
|
|
972
|
-
*
|
|
973
|
-
* const loanToken = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48";
|
|
974
|
-
* const collateralToken = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2";
|
|
975
|
-
* const oracle = "0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419";
|
|
976
|
-
* const irm = "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC";
|
|
977
|
-
* const receiver = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045";
|
|
978
|
-
* const marketParams = {
|
|
979
|
-
* loanToken,
|
|
980
|
-
* collateralToken,
|
|
981
|
-
* oracle,
|
|
982
|
-
* irm,
|
|
983
|
-
* lltv: 860_000000000000000000n,
|
|
984
|
-
* };
|
|
985
|
-
*
|
|
986
|
-
* const calls = BundlerAction.morphoWithdraw(
|
|
987
|
-
* 1,
|
|
988
|
-
* marketParams,
|
|
989
|
-
* 100n,
|
|
990
|
-
* 0n,
|
|
991
|
-
* 990000000000000000000000000n,
|
|
992
|
-
* receiver,
|
|
993
|
-
* );
|
|
994
|
-
* ```
|
|
995
|
-
*/
|
|
996
|
-
// biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
|
|
997
|
-
function morphoWithdraw(chainId, market, assets, shares, slippageAmount, receiver, skipRevert = false) {
|
|
998
|
-
const { bundler3: { generalAdapter1 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
|
|
999
|
-
return [
|
|
1000
|
-
{
|
|
1001
|
-
to: generalAdapter1,
|
|
1002
|
-
data: (0, viem_1.encodeFunctionData)({
|
|
1003
|
-
abi: abis_js_1.generalAdapter1Abi,
|
|
1004
|
-
functionName: "morphoWithdraw",
|
|
1005
|
-
args: [market, assets, shares, slippageAmount, receiver],
|
|
1006
|
-
}),
|
|
1007
|
-
value: 0n,
|
|
1008
|
-
skipRevert,
|
|
1009
|
-
callbackHash: viem_1.zeroHash,
|
|
1010
|
-
},
|
|
1011
|
-
];
|
|
1012
|
-
}
|
|
1013
|
-
BundlerAction.morphoWithdraw = morphoWithdraw;
|
|
1014
|
-
/**
|
|
1015
|
-
* Encodes a GeneralAdapter1 Morpho Blue withdraw-collateral call.
|
|
1016
|
-
*
|
|
1017
|
-
* @param chainId - Chain where the action will execute.
|
|
1018
|
-
* @param market - Morpho Blue market parameters.
|
|
1019
|
-
* @param assets - Collateral asset amount to withdraw.
|
|
1020
|
-
* @param receiver - Recipient of withdrawn collateral.
|
|
1021
|
-
* @param skipRevert - Whether Bundler3 should tolerate a revert.
|
|
1022
|
-
* @returns Encoded Bundler3 calls.
|
|
1023
|
-
*
|
|
1024
|
-
* @example
|
|
1025
|
-
* ```ts
|
|
1026
|
-
* import { BundlerAction } from "@morpho-org/morpho-sdk/bundler";
|
|
1027
|
-
*
|
|
1028
|
-
* const loanToken = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48";
|
|
1029
|
-
* const collateralToken = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2";
|
|
1030
|
-
* const oracle = "0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419";
|
|
1031
|
-
* const irm = "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC";
|
|
1032
|
-
* const receiver = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045";
|
|
1033
|
-
* const marketParams = {
|
|
1034
|
-
* loanToken,
|
|
1035
|
-
* collateralToken,
|
|
1036
|
-
* oracle,
|
|
1037
|
-
* irm,
|
|
1038
|
-
* lltv: 860_000000000000000000n,
|
|
1039
|
-
* };
|
|
1040
|
-
*
|
|
1041
|
-
* const calls = BundlerAction.morphoWithdrawCollateral(
|
|
1042
|
-
* 1,
|
|
1043
|
-
* marketParams,
|
|
1044
|
-
* 100n,
|
|
1045
|
-
* receiver,
|
|
1046
|
-
* );
|
|
1047
|
-
* ```
|
|
1048
|
-
*/
|
|
1049
|
-
// biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
|
|
1050
|
-
function morphoWithdrawCollateral(chainId, market, assets, receiver, skipRevert = false) {
|
|
1051
|
-
const { bundler3: { generalAdapter1 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
|
|
1052
|
-
return [
|
|
1053
|
-
{
|
|
1054
|
-
to: generalAdapter1,
|
|
1055
|
-
data: (0, viem_1.encodeFunctionData)({
|
|
1056
|
-
abi: abis_js_1.generalAdapter1Abi,
|
|
1057
|
-
functionName: "morphoWithdrawCollateral",
|
|
1058
|
-
args: [market, assets, receiver],
|
|
1059
|
-
}),
|
|
1060
|
-
value: 0n,
|
|
1061
|
-
skipRevert,
|
|
1062
|
-
callbackHash: viem_1.zeroHash,
|
|
1063
|
-
},
|
|
1064
|
-
];
|
|
1065
|
-
}
|
|
1066
|
-
BundlerAction.morphoWithdrawCollateral = morphoWithdrawCollateral;
|
|
1067
|
-
/**
|
|
1068
|
-
* Encodes a PublicAllocator reallocation call.
|
|
1069
|
-
*
|
|
1070
|
-
* @param chainId - Chain where the action will execute.
|
|
1071
|
-
* @param vault - Vault to reallocate.
|
|
1072
|
-
* @param fee - Public allocator fee.
|
|
1073
|
-
* @param withdrawals - Market withdrawals performed before supply.
|
|
1074
|
-
* @param supplyMarketParams - Target supply market parameters.
|
|
1075
|
-
* @param skipRevert - Whether Bundler3 should tolerate a revert.
|
|
1076
|
-
* @returns Encoded Bundler3 calls.
|
|
1077
|
-
* @throws {BundlerErrors.UnexpectedAction} when the PublicAllocator is unavailable on the chain.
|
|
1078
|
-
* @deprecated Vault V1 PublicAllocator composition will be removed in the next major. Use
|
|
1079
|
-
* `vaultV2BluePublicAllocatorReallocate` or `vaultV2BluePublicAllocatorAllocateFromIdle`.
|
|
1080
|
-
*
|
|
1081
|
-
* @example
|
|
1082
|
-
* ```ts
|
|
1083
|
-
* import { BundlerAction } from "@morpho-org/morpho-sdk/bundler";
|
|
1084
|
-
*
|
|
1085
|
-
* const loanToken = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48";
|
|
1086
|
-
* const collateralToken = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2";
|
|
1087
|
-
* const oracle = "0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419";
|
|
1088
|
-
* const irm = "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC";
|
|
1089
|
-
* const vault = "0x186514400e52270cef3D80e1c6F8d10A75d47344";
|
|
1090
|
-
* const marketParams = {
|
|
1091
|
-
* loanToken,
|
|
1092
|
-
* collateralToken,
|
|
1093
|
-
* oracle,
|
|
1094
|
-
* irm,
|
|
1095
|
-
* lltv: 860_000000000000000000n,
|
|
1096
|
-
* };
|
|
1097
|
-
*
|
|
1098
|
-
* const calls = BundlerAction.publicAllocatorReallocateTo(
|
|
1099
|
-
* 1,
|
|
1100
|
-
* vault,
|
|
1101
|
-
* 0n,
|
|
1102
|
-
* [{ marketParams, amount: 100n }],
|
|
1103
|
-
* marketParams,
|
|
1104
|
-
* );
|
|
1105
|
-
* ```
|
|
1106
|
-
*/
|
|
1107
|
-
// biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
|
|
1108
|
-
function publicAllocatorReallocateTo(chainId, vault, fee, withdrawals, supplyMarketParams, skipRevert = false) {
|
|
1109
|
-
const { vaultV1PublicAllocator } = (0, blue_sdk_1.getChainAddresses)(chainId);
|
|
1110
|
-
if (vaultV1PublicAllocator == null) {
|
|
1111
|
-
throw new error_js_1.BundlerErrors.UnexpectedAction("reallocateTo", chainId);
|
|
1112
|
-
}
|
|
1113
|
-
return [
|
|
1114
|
-
{
|
|
1115
|
-
to: vaultV1PublicAllocator,
|
|
1116
|
-
data: (0, viem_1.encodeFunctionData)({
|
|
1117
|
-
abi: blue_sdk_viem_1.vaultV1PublicAllocatorAbi,
|
|
1118
|
-
functionName: "reallocateTo",
|
|
1119
|
-
args: [vault, withdrawals, supplyMarketParams],
|
|
1120
|
-
}),
|
|
1121
|
-
value: fee,
|
|
1122
|
-
skipRevert,
|
|
1123
|
-
callbackHash: viem_1.zeroHash,
|
|
1124
|
-
},
|
|
1125
|
-
];
|
|
1126
|
-
}
|
|
1127
|
-
BundlerAction.publicAllocatorReallocateTo = publicAllocatorReallocateTo;
|
|
1128
|
-
/**
|
|
1129
|
-
* Encodes a Vault V2 Blue Public Allocator market-to-market reallocation.
|
|
1130
|
-
*
|
|
1131
|
-
* @remarks Bundler3 must already hold the computed penalty assets. Explicit low-level
|
|
1132
|
-
* composition must add the corresponding GeneralAdapter1 transfer.
|
|
1133
|
-
*
|
|
1134
|
-
* @param chainId - Chain whose canonical Blue Public Allocator is called.
|
|
1135
|
-
* @param vault - Vault whose liquidity is reallocated.
|
|
1136
|
-
* @param deallocateAdapter - Vault V2 adapter supplying the source market.
|
|
1137
|
-
* @param deallocateMarket - Source Morpho Blue market parameters.
|
|
1138
|
-
* @param allocateAdapter - Vault V2 adapter supplying the target market.
|
|
1139
|
-
* @param allocateMarket - Target Morpho Blue market parameters.
|
|
1140
|
-
* @param assets - Assets to reallocate, bounded by `uint128` by the high-level action.
|
|
1141
|
-
* @param penalty - Vault-configured proportional penalty, scaled by WAD.
|
|
1142
|
-
* @param skipRevert - Whether Bundler3 should tolerate a revert.
|
|
1143
|
-
* @returns A zero reset and exact approval when needed, then the allocator call.
|
|
1144
|
-
* @throws {BundlerErrors.UnexpectedAction} when the chain has no Blue Public Allocator deployment.
|
|
1145
|
-
* @throws {BundlerErrors.SkippableAllocatorPenalty} when `skipRevert` is true and a token approval is required.
|
|
1146
|
-
* @example
|
|
1147
|
-
* ```ts
|
|
1148
|
-
* import { ChainId } from "@morpho-org/morpho-sdk/constants";
|
|
1149
|
-
* import type { BlueInputMarketParams } from "@morpho-org/morpho-sdk/types";
|
|
1150
|
-
* import {
|
|
1151
|
-
* BundlerAction,
|
|
1152
|
-
* type BundlerCall,
|
|
1153
|
-
* } from "@morpho-org/morpho-sdk/bundler";
|
|
1154
|
-
* import type { Address } from "viem";
|
|
1155
|
-
*
|
|
1156
|
-
* const keyrockUsdcVault =
|
|
1157
|
-
* "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145" satisfies Address;
|
|
1158
|
-
* const sourceAdapterFixture =
|
|
1159
|
-
* "0x70997970C51812dc3A010C7d01b50e0d17dc79C8" satisfies Address;
|
|
1160
|
-
* const targetAdapterFixture =
|
|
1161
|
-
* "0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC" satisfies Address;
|
|
1162
|
-
* const usdc = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48" satisfies Address;
|
|
1163
|
-
* const weth = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2" satisfies Address;
|
|
1164
|
-
* const wbtc = "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599" satisfies Address;
|
|
1165
|
-
* const ethUsdOracle = "0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419" satisfies Address;
|
|
1166
|
-
* const adaptiveCurveIrm = "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC" satisfies Address;
|
|
1167
|
-
* const sourceMarket = {
|
|
1168
|
-
* loanToken: usdc,
|
|
1169
|
-
* collateralToken: weth,
|
|
1170
|
-
* oracle: ethUsdOracle,
|
|
1171
|
-
* irm: adaptiveCurveIrm,
|
|
1172
|
-
* lltv: 860_000_000_000_000_000n,
|
|
1173
|
-
* } satisfies BlueInputMarketParams;
|
|
1174
|
-
* const targetMarket = {
|
|
1175
|
-
* ...sourceMarket,
|
|
1176
|
-
* collateralToken: wbtc,
|
|
1177
|
-
* } satisfies BlueInputMarketParams;
|
|
1178
|
-
*
|
|
1179
|
-
* const calls: BundlerCall[] = BundlerAction.vaultV2BluePublicAllocatorReallocate(
|
|
1180
|
-
* ChainId.EthMainnet,
|
|
1181
|
-
* keyrockUsdcVault,
|
|
1182
|
-
* sourceAdapterFixture,
|
|
1183
|
-
* sourceMarket,
|
|
1184
|
-
* targetAdapterFixture,
|
|
1185
|
-
* targetMarket,
|
|
1186
|
-
* 1_000_000n,
|
|
1187
|
-
* 1_000_000_000_000_000n,
|
|
1188
|
-
* );
|
|
1189
|
-
* // Bundler3 resets and approves 1_000 USDC units, then calls `reallocate` with zero native value.
|
|
1190
|
-
* ```
|
|
1191
|
-
*/
|
|
1192
|
-
// biome-ignore lint/complexity/useMaxParams: mirrors the protocol call
|
|
1193
|
-
function vaultV2BluePublicAllocatorReallocate(chainId, vault, deallocateAdapter, deallocateMarket, allocateAdapter, allocateMarket, assets, penalty, skipRevert = false) {
|
|
1194
|
-
const { vaultV2BluePublicAllocator: allocator } = (0, blue_sdk_1.getChainAddresses)(chainId);
|
|
1195
|
-
if (allocator == null) {
|
|
1196
|
-
throw new error_js_1.BundlerErrors.UnexpectedAction("vaultV2BluePublicAllocatorReallocate", chainId);
|
|
1197
|
-
}
|
|
1198
|
-
const calls = [];
|
|
1199
|
-
const penaltyAssets = blue_sdk_1.VaultV2BluePublicAllocatorConfigUtils.getPenaltyAssets({ penalty }, assets);
|
|
1200
|
-
if (skipRevert && penaltyAssets > 0n) {
|
|
1201
|
-
throw new error_js_1.BundlerErrors.SkippableAllocatorPenalty(penaltyAssets);
|
|
1202
|
-
}
|
|
1203
|
-
if (penaltyAssets > 0n) {
|
|
1204
|
-
for (const amount of [0n, penaltyAssets])
|
|
1205
|
-
calls.push({
|
|
1206
|
-
to: allocateMarket.loanToken,
|
|
1207
|
-
data: (0, viem_1.encodeFunctionData)({
|
|
1208
|
-
abi: viem_1.erc20Abi,
|
|
1209
|
-
functionName: "approve",
|
|
1210
|
-
args: [allocator, amount],
|
|
1211
|
-
}),
|
|
1212
|
-
value: 0n,
|
|
1213
|
-
skipRevert,
|
|
1214
|
-
callbackHash: viem_1.zeroHash,
|
|
1215
|
-
});
|
|
1216
|
-
}
|
|
1217
|
-
calls.push({
|
|
1218
|
-
to: allocator,
|
|
1219
|
-
data: (0, viem_1.encodeFunctionData)({
|
|
1220
|
-
abi: blue_sdk_viem_1.vaultV2BluePublicAllocatorAbi,
|
|
1221
|
-
functionName: "reallocate",
|
|
1222
|
-
args: [
|
|
1223
|
-
vault,
|
|
1224
|
-
deallocateAdapter,
|
|
1225
|
-
deallocateMarket,
|
|
1226
|
-
allocateAdapter,
|
|
1227
|
-
allocateMarket,
|
|
1228
|
-
assets,
|
|
1229
|
-
penalty,
|
|
1230
|
-
],
|
|
1231
|
-
}),
|
|
1232
|
-
value: 0n,
|
|
1233
|
-
skipRevert,
|
|
1234
|
-
callbackHash: viem_1.zeroHash,
|
|
1235
|
-
});
|
|
1236
|
-
return calls;
|
|
1237
|
-
}
|
|
1238
|
-
BundlerAction.vaultV2BluePublicAllocatorReallocate = vaultV2BluePublicAllocatorReallocate;
|
|
1239
|
-
/**
|
|
1240
|
-
* Encodes a Vault V2 Blue Public Allocator allocation from vault idle liquidity.
|
|
1241
|
-
*
|
|
1242
|
-
* @remarks Bundler3 must already hold the computed penalty assets. Explicit low-level
|
|
1243
|
-
* composition must add the corresponding GeneralAdapter1 transfer.
|
|
1244
|
-
*
|
|
1245
|
-
* @param chainId - Chain whose canonical Blue Public Allocator is called.
|
|
1246
|
-
* @param vault - Vault whose idle liquidity is allocated.
|
|
1247
|
-
* @param adapter - Vault V2 adapter supplying the target market.
|
|
1248
|
-
* @param market - Target Morpho Blue market parameters.
|
|
1249
|
-
* @param assets - Assets to allocate, bounded by `uint128` by the high-level action.
|
|
1250
|
-
* @param penalty - Vault-configured proportional penalty, scaled by WAD.
|
|
1251
|
-
* @param skipRevert - Whether Bundler3 should tolerate a revert.
|
|
1252
|
-
* @returns A zero reset and exact approval when needed, then the allocator call.
|
|
1253
|
-
* @throws {BundlerErrors.UnexpectedAction} when the chain has no Blue Public Allocator deployment.
|
|
1254
|
-
* @throws {BundlerErrors.SkippableAllocatorPenalty} when `skipRevert` is true and a token approval is required.
|
|
1255
|
-
* @example
|
|
1256
|
-
* ```ts
|
|
1257
|
-
* import { ChainId } from "@morpho-org/morpho-sdk/constants";
|
|
1258
|
-
* import type { BlueInputMarketParams } from "@morpho-org/morpho-sdk/types";
|
|
1259
|
-
* import {
|
|
1260
|
-
* BundlerAction,
|
|
1261
|
-
* type BundlerCall,
|
|
1262
|
-
* } from "@morpho-org/morpho-sdk/bundler";
|
|
1263
|
-
* import type { Address } from "viem";
|
|
1264
|
-
*
|
|
1265
|
-
* const keyrockUsdcVault =
|
|
1266
|
-
* "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145" satisfies Address;
|
|
1267
|
-
* const targetAdapterFixture =
|
|
1268
|
-
* "0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC" satisfies Address;
|
|
1269
|
-
* const usdc = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48" satisfies Address;
|
|
1270
|
-
* const weth = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2" satisfies Address;
|
|
1271
|
-
* const ethUsdOracle = "0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419" satisfies Address;
|
|
1272
|
-
* const adaptiveCurveIrm = "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC" satisfies Address;
|
|
1273
|
-
* const targetMarket = {
|
|
1274
|
-
* loanToken: usdc,
|
|
1275
|
-
* collateralToken: weth,
|
|
1276
|
-
* oracle: ethUsdOracle,
|
|
1277
|
-
* irm: adaptiveCurveIrm,
|
|
1278
|
-
* lltv: 860_000_000_000_000_000n,
|
|
1279
|
-
* } satisfies BlueInputMarketParams;
|
|
1280
|
-
*
|
|
1281
|
-
* const calls: BundlerCall[] = BundlerAction.vaultV2BluePublicAllocatorAllocateFromIdle(
|
|
1282
|
-
* ChainId.EthMainnet,
|
|
1283
|
-
* keyrockUsdcVault,
|
|
1284
|
-
* targetAdapterFixture,
|
|
1285
|
-
* targetMarket,
|
|
1286
|
-
* 1_000_000n,
|
|
1287
|
-
* 1_000_000_000_000_000n,
|
|
1288
|
-
* );
|
|
1289
|
-
* // Bundler3 resets and approves 1_000 USDC units, then calls `allocateFromIdle` with zero native value.
|
|
1290
|
-
* ```
|
|
1291
|
-
*/
|
|
1292
|
-
// biome-ignore lint/complexity/useMaxParams: mirrors the protocol call
|
|
1293
|
-
function vaultV2BluePublicAllocatorAllocateFromIdle(chainId, vault, adapter, market, assets, penalty, skipRevert = false) {
|
|
1294
|
-
const { vaultV2BluePublicAllocator: allocator } = (0, blue_sdk_1.getChainAddresses)(chainId);
|
|
1295
|
-
if (allocator == null) {
|
|
1296
|
-
throw new error_js_1.BundlerErrors.UnexpectedAction("vaultV2BluePublicAllocatorAllocateFromIdle", chainId);
|
|
1297
|
-
}
|
|
1298
|
-
const calls = [];
|
|
1299
|
-
const penaltyAssets = blue_sdk_1.VaultV2BluePublicAllocatorConfigUtils.getPenaltyAssets({ penalty }, assets);
|
|
1300
|
-
if (skipRevert && penaltyAssets > 0n) {
|
|
1301
|
-
throw new error_js_1.BundlerErrors.SkippableAllocatorPenalty(penaltyAssets);
|
|
1302
|
-
}
|
|
1303
|
-
if (penaltyAssets > 0n) {
|
|
1304
|
-
for (const amount of [0n, penaltyAssets])
|
|
1305
|
-
calls.push({
|
|
1306
|
-
to: market.loanToken,
|
|
1307
|
-
data: (0, viem_1.encodeFunctionData)({
|
|
1308
|
-
abi: viem_1.erc20Abi,
|
|
1309
|
-
functionName: "approve",
|
|
1310
|
-
args: [allocator, amount],
|
|
1311
|
-
}),
|
|
1312
|
-
value: 0n,
|
|
1313
|
-
skipRevert,
|
|
1314
|
-
callbackHash: viem_1.zeroHash,
|
|
1315
|
-
});
|
|
1316
|
-
}
|
|
1317
|
-
calls.push({
|
|
1318
|
-
to: allocator,
|
|
1319
|
-
data: (0, viem_1.encodeFunctionData)({
|
|
1320
|
-
abi: blue_sdk_viem_1.vaultV2BluePublicAllocatorAbi,
|
|
1321
|
-
functionName: "allocateFromIdle",
|
|
1322
|
-
args: [vault, adapter, market, assets, penalty],
|
|
1323
|
-
}),
|
|
1324
|
-
value: 0n,
|
|
1325
|
-
skipRevert,
|
|
1326
|
-
callbackHash: viem_1.zeroHash,
|
|
1327
|
-
});
|
|
1328
|
-
return calls;
|
|
1329
|
-
}
|
|
1330
|
-
BundlerAction.vaultV2BluePublicAllocatorAllocateFromIdle = vaultV2BluePublicAllocatorAllocateFromIdle;
|
|
1331
|
-
/**
|
|
1332
|
-
* Encodes a GeneralAdapter1 native-token wrap call.
|
|
1333
|
-
*
|
|
1334
|
-
* @param chainId - Chain where the action will execute.
|
|
1335
|
-
* @param amount - Native-token amount to wrap.
|
|
1336
|
-
* @param recipient - Recipient of wrapped native tokens.
|
|
1337
|
-
* @param skipRevert - Whether Bundler3 should tolerate a revert.
|
|
1338
|
-
* @returns Encoded Bundler3 calls.
|
|
1339
|
-
*
|
|
1340
|
-
* @example
|
|
1341
|
-
* ```ts
|
|
1342
|
-
* import { BundlerAction } from "@morpho-org/morpho-sdk/bundler";
|
|
1343
|
-
*
|
|
1344
|
-
* const recipient = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045";
|
|
1345
|
-
*
|
|
1346
|
-
* const calls = BundlerAction.wrapNative(
|
|
1347
|
-
* 1,
|
|
1348
|
-
* 1_000000000000000000n,
|
|
1349
|
-
* recipient,
|
|
1350
|
-
* );
|
|
1351
|
-
* ```
|
|
1352
|
-
*/
|
|
1353
|
-
// biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
|
|
1354
|
-
function wrapNative(chainId, amount, recipient, skipRevert = false) {
|
|
1355
|
-
const { bundler3: { generalAdapter1 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
|
|
1356
|
-
return [
|
|
1357
|
-
{
|
|
1358
|
-
to: generalAdapter1,
|
|
1359
|
-
data: (0, viem_1.encodeFunctionData)({
|
|
1360
|
-
abi: abis_js_1.generalAdapter1Abi,
|
|
1361
|
-
functionName: "wrapNative",
|
|
1362
|
-
args: [amount, recipient],
|
|
1363
|
-
}),
|
|
1364
|
-
value: 0n,
|
|
1365
|
-
skipRevert,
|
|
1366
|
-
callbackHash: viem_1.zeroHash,
|
|
1367
|
-
},
|
|
1368
|
-
];
|
|
1369
|
-
}
|
|
1370
|
-
BundlerAction.wrapNative = wrapNative;
|
|
1371
|
-
})(BundlerAction || (exports.BundlerAction = BundlerAction = {}));
|