@morpho-org/morpho-sdk 4.2.0 → 5.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -16
- package/lib/cjs/actions/blue/borrow.d.ts +12 -2
- package/lib/cjs/actions/blue/borrow.js +7 -1
- package/lib/cjs/actions/blue/buildAssetFundingActions.d.ts +47 -0
- package/lib/cjs/actions/blue/buildAssetFundingActions.js +63 -0
- package/lib/cjs/actions/blue/refinance.d.ts +13 -3
- package/lib/cjs/actions/blue/refinance.js +8 -2
- package/lib/cjs/actions/blue/repay.d.ts +44 -43
- package/lib/cjs/actions/blue/repay.js +70 -59
- package/lib/cjs/actions/blue/repayWithdrawCollateral.d.ts +50 -41
- package/lib/cjs/actions/blue/repayWithdrawCollateral.js +75 -54
- package/lib/cjs/actions/blue/resolveRepayFunding.d.ts +69 -0
- package/lib/cjs/actions/blue/resolveRepayFunding.js +82 -0
- package/lib/cjs/actions/blue/supply.d.ts +8 -8
- package/lib/cjs/actions/blue/supply.js +11 -35
- package/lib/cjs/actions/blue/supplyCollateral.d.ts +9 -9
- package/lib/cjs/actions/blue/supplyCollateral.js +12 -36
- package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +19 -7
- package/lib/cjs/actions/blue/supplyCollateralBorrow.js +17 -32
- package/lib/cjs/actions/blue/withdraw.d.ts +10 -2
- package/lib/cjs/actions/blue/withdraw.js +7 -1
- package/lib/cjs/actions/index.d.ts +1 -0
- package/lib/cjs/actions/index.js +1 -0
- package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +49 -0
- package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +111 -0
- package/lib/cjs/actions/requirements/blue/index.d.ts +1 -0
- package/lib/cjs/actions/requirements/blue/index.js +17 -0
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +55 -0
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +89 -0
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +6 -5
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +17 -5
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +9 -7
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +18 -4
- package/lib/cjs/actions/requirements/encode/{encodeErc20Permit2.d.ts → encodeErc20Permit2Approve.d.ts} +11 -13
- package/lib/cjs/actions/requirements/encode/{encodeErc20Permit2.js → encodeErc20Permit2Approve.js} +10 -14
- package/lib/cjs/actions/requirements/encode/index.d.ts +2 -1
- package/lib/cjs/actions/requirements/encode/index.js +2 -1
- package/lib/cjs/actions/requirements/{getRequirements.d.ts → generalAdapter/getGeneralAdapterRequirements.d.ts} +34 -20
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +151 -0
- package/lib/{esm/actions/requirements/getRequirementsPermit.d.ts → cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts} +6 -14
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +50 -0
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.d.ts +57 -0
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.js +74 -0
- package/lib/cjs/actions/requirements/generalAdapter/index.d.ts +3 -0
- package/lib/cjs/actions/requirements/generalAdapter/index.js +19 -0
- package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +3 -2
- package/lib/cjs/actions/requirements/getRequirementsApproval.js +3 -2
- package/lib/cjs/actions/requirements/index.d.ts +2 -5
- package/lib/cjs/actions/requirements/index.js +2 -5
- package/lib/cjs/actions/signatures/getBlueAuthorizationAction.d.ts +29 -0
- package/lib/cjs/actions/signatures/getBlueAuthorizationAction.js +48 -0
- package/lib/{esm/actions/requirements/getRequirementsAction.d.ts → cjs/actions/signatures/getTokenRequirementActions.d.ts} +17 -17
- package/lib/cjs/actions/{requirements/getRequirementsAction.js → signatures/getTokenRequirementActions.js} +26 -13
- package/lib/cjs/actions/signatures/index.d.ts +2 -0
- package/lib/cjs/actions/signatures/index.js +18 -0
- package/lib/cjs/actions/vaultV1/deposit.d.ts +6 -8
- package/lib/cjs/actions/vaultV1/deposit.js +11 -21
- package/lib/cjs/actions/vaultV1/migrateToV2.d.ts +6 -6
- package/lib/cjs/actions/vaultV1/migrateToV2.js +12 -20
- package/lib/cjs/actions/vaultV2/deposit.d.ts +6 -8
- package/lib/cjs/actions/vaultV2/deposit.js +11 -21
- package/lib/cjs/addresses.d.ts +2 -2
- package/lib/cjs/addresses.js +2 -1
- package/lib/cjs/bundler/actions.d.ts +44 -4
- package/lib/cjs/bundler/actions.js +75 -2
- package/lib/cjs/bundler/types.d.ts +6 -0
- package/lib/cjs/constants.d.ts +2 -2
- package/lib/cjs/constants.js +3 -3
- package/lib/cjs/entities/blue/blue.d.ts +58 -33
- package/lib/cjs/entities/blue/blue.js +309 -189
- package/lib/cjs/entities/reallocationData.d.ts +0 -44
- package/lib/cjs/entities/reallocationData.js +3 -50
- package/lib/cjs/entities/vaultV1/vaultV1.d.ts +9 -9
- package/lib/cjs/entities/vaultV1/vaultV1.js +44 -34
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +6 -6
- package/lib/cjs/entities/vaultV2/vaultV2.js +21 -16
- package/lib/cjs/errors.d.ts +3 -2
- package/lib/cjs/errors.js +5 -2
- package/lib/cjs/helpers/index.d.ts +1 -1
- package/lib/cjs/helpers/index.js +1 -2
- package/lib/cjs/helpers/validate.d.ts +2 -20
- package/lib/cjs/helpers/validate.js +2 -39
- package/lib/cjs/types/action.d.ts +164 -12
- package/lib/cjs/types/action.js +79 -5
- package/lib/cjs/types/error.d.ts +97 -2
- package/lib/cjs/types/error.js +113 -7
- package/lib/cjs/types.d.ts +2 -1
- package/lib/cjs/utils.d.ts +2 -2
- package/lib/cjs/utils.js +2 -4
- package/lib/esm/actions/blue/borrow.d.ts +12 -2
- package/lib/esm/actions/blue/borrow.js +7 -1
- package/lib/esm/actions/blue/buildAssetFundingActions.d.ts +47 -0
- package/lib/esm/actions/blue/buildAssetFundingActions.js +59 -0
- package/lib/esm/actions/blue/refinance.d.ts +13 -3
- package/lib/esm/actions/blue/refinance.js +8 -2
- package/lib/esm/actions/blue/repay.d.ts +44 -43
- package/lib/esm/actions/blue/repay.js +71 -60
- package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +50 -41
- package/lib/esm/actions/blue/repayWithdrawCollateral.js +76 -55
- package/lib/esm/actions/blue/resolveRepayFunding.d.ts +69 -0
- package/lib/esm/actions/blue/resolveRepayFunding.js +78 -0
- package/lib/esm/actions/blue/supply.d.ts +8 -8
- package/lib/esm/actions/blue/supply.js +12 -36
- package/lib/esm/actions/blue/supplyCollateral.d.ts +9 -9
- package/lib/esm/actions/blue/supplyCollateral.js +13 -37
- package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +19 -7
- package/lib/esm/actions/blue/supplyCollateralBorrow.js +18 -33
- package/lib/esm/actions/blue/withdraw.d.ts +10 -2
- package/lib/esm/actions/blue/withdraw.js +7 -1
- package/lib/esm/actions/index.d.ts +1 -0
- package/lib/esm/actions/index.js +1 -0
- package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +49 -0
- package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +107 -0
- package/lib/esm/actions/requirements/blue/index.d.ts +1 -0
- package/lib/esm/actions/requirements/blue/index.js +1 -0
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +55 -0
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +85 -0
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +6 -5
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +19 -7
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +9 -7
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +20 -6
- package/lib/esm/actions/requirements/encode/{encodeErc20Permit2.d.ts → encodeErc20Permit2Approve.d.ts} +11 -13
- package/lib/esm/actions/requirements/encode/{encodeErc20Permit2.js → encodeErc20Permit2Approve.js} +8 -12
- package/lib/esm/actions/requirements/encode/index.d.ts +2 -1
- package/lib/esm/actions/requirements/encode/index.js +2 -1
- package/lib/esm/actions/requirements/{getRequirements.d.ts → generalAdapter/getGeneralAdapterRequirements.d.ts} +34 -20
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +147 -0
- package/lib/{cjs/actions/requirements/getRequirementsPermit.d.ts → esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts} +6 -14
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +46 -0
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.d.ts +57 -0
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.js +70 -0
- package/lib/esm/actions/requirements/generalAdapter/index.d.ts +3 -0
- package/lib/esm/actions/requirements/generalAdapter/index.js +3 -0
- package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +3 -2
- package/lib/esm/actions/requirements/getRequirementsApproval.js +3 -2
- package/lib/esm/actions/requirements/index.d.ts +2 -5
- package/lib/esm/actions/requirements/index.js +2 -5
- package/lib/esm/actions/signatures/getBlueAuthorizationAction.d.ts +29 -0
- package/lib/esm/actions/signatures/getBlueAuthorizationAction.js +44 -0
- package/lib/{cjs/actions/requirements/getRequirementsAction.d.ts → esm/actions/signatures/getTokenRequirementActions.d.ts} +17 -17
- package/lib/esm/actions/{requirements/getRequirementsAction.js → signatures/getTokenRequirementActions.js} +24 -11
- package/lib/esm/actions/signatures/index.d.ts +2 -0
- package/lib/esm/actions/signatures/index.js +2 -0
- package/lib/esm/actions/vaultV1/deposit.d.ts +6 -8
- package/lib/esm/actions/vaultV1/deposit.js +11 -21
- package/lib/esm/actions/vaultV1/migrateToV2.d.ts +6 -6
- package/lib/esm/actions/vaultV1/migrateToV2.js +12 -20
- package/lib/esm/actions/vaultV2/deposit.d.ts +6 -8
- package/lib/esm/actions/vaultV2/deposit.js +11 -21
- package/lib/esm/addresses.d.ts +2 -2
- package/lib/esm/addresses.js +1 -1
- package/lib/esm/bundler/actions.d.ts +44 -4
- package/lib/esm/bundler/actions.js +77 -4
- package/lib/esm/bundler/types.d.ts +6 -0
- package/lib/esm/constants.d.ts +2 -2
- package/lib/esm/constants.js +2 -2
- package/lib/esm/entities/blue/blue.d.ts +58 -33
- package/lib/esm/entities/blue/blue.js +311 -191
- package/lib/esm/entities/reallocationData.d.ts +0 -44
- package/lib/esm/entities/reallocationData.js +2 -49
- package/lib/esm/entities/vaultV1/vaultV1.d.ts +9 -9
- package/lib/esm/entities/vaultV1/vaultV1.js +46 -36
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +6 -6
- package/lib/esm/entities/vaultV2/vaultV2.js +23 -18
- package/lib/esm/errors.d.ts +3 -2
- package/lib/esm/errors.js +2 -1
- package/lib/esm/helpers/index.d.ts +1 -1
- package/lib/esm/helpers/index.js +1 -1
- package/lib/esm/helpers/validate.d.ts +2 -20
- package/lib/esm/helpers/validate.js +2 -38
- package/lib/esm/types/action.d.ts +164 -12
- package/lib/esm/types/action.js +75 -4
- package/lib/esm/types/error.d.ts +97 -2
- package/lib/esm/types/error.js +107 -5
- package/lib/esm/types.d.ts +2 -1
- package/lib/esm/utils.d.ts +2 -2
- package/lib/esm/utils.js +2 -2
- package/package.json +22 -21
- package/lib/cjs/actions/requirements/getMorphoAuthorizationRequirement.d.ts +0 -37
- package/lib/cjs/actions/requirements/getMorphoAuthorizationRequirement.js +0 -71
- package/lib/cjs/actions/requirements/getRequirements.js +0 -112
- package/lib/cjs/actions/requirements/getRequirementsPermit.js +0 -57
- package/lib/cjs/actions/requirements/getRequirementsPermit2.d.ts +0 -63
- package/lib/cjs/actions/requirements/getRequirementsPermit2.js +0 -85
- package/lib/esm/actions/requirements/getMorphoAuthorizationRequirement.d.ts +0 -37
- package/lib/esm/actions/requirements/getMorphoAuthorizationRequirement.js +0 -67
- package/lib/esm/actions/requirements/getRequirements.js +0 -108
- package/lib/esm/actions/requirements/getRequirementsPermit.js +0 -53
- package/lib/esm/actions/requirements/getRequirementsPermit2.d.ts +0 -63
- package/lib/esm/actions/requirements/getRequirementsPermit2.js +0 -81
- package/src/index.ts +0 -4
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@morpho-org/morpho-sdk",
|
|
3
3
|
"description": "Abstraction layer for Morpho's complexity.",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "5.1.1",
|
|
5
5
|
"author": "Morpho Association <contact@morpho.org>",
|
|
6
6
|
"contributors": [
|
|
7
7
|
"Foulks-Plb <https://x.com/FoulkPlb>"
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
},
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"type": "module",
|
|
21
|
-
"main": "
|
|
21
|
+
"main": "./lib/cjs/index.js",
|
|
22
22
|
"exports": {
|
|
23
23
|
".": {
|
|
24
24
|
"types": "./lib/esm/index.d.ts",
|
|
@@ -89,40 +89,40 @@
|
|
|
89
89
|
"typesVersions": {
|
|
90
90
|
"*": {
|
|
91
91
|
"abis": [
|
|
92
|
-
"
|
|
92
|
+
"lib/esm/abis.d.ts"
|
|
93
93
|
],
|
|
94
94
|
"addresses": [
|
|
95
|
-
"
|
|
95
|
+
"lib/esm/addresses.d.ts"
|
|
96
96
|
],
|
|
97
97
|
"augment": [
|
|
98
|
-
"
|
|
98
|
+
"lib/esm/augment.d.ts"
|
|
99
99
|
],
|
|
100
100
|
"augment/*": [
|
|
101
|
-
"
|
|
101
|
+
"lib/esm/augment/*.d.ts"
|
|
102
102
|
],
|
|
103
103
|
"bundler": [
|
|
104
|
-
"
|
|
104
|
+
"lib/esm/bundler/index.d.ts"
|
|
105
105
|
],
|
|
106
106
|
"constants": [
|
|
107
|
-
"
|
|
107
|
+
"lib/esm/constants.d.ts"
|
|
108
108
|
],
|
|
109
109
|
"entities": [
|
|
110
|
-
"
|
|
110
|
+
"lib/esm/entities/index.d.ts"
|
|
111
111
|
],
|
|
112
112
|
"errors": [
|
|
113
|
-
"
|
|
113
|
+
"lib/esm/errors.d.ts"
|
|
114
114
|
],
|
|
115
115
|
"fetch": [
|
|
116
|
-
"
|
|
116
|
+
"lib/esm/fetch.d.ts"
|
|
117
117
|
],
|
|
118
118
|
"format": [
|
|
119
|
-
"
|
|
119
|
+
"lib/esm/format.d.ts"
|
|
120
120
|
],
|
|
121
121
|
"types": [
|
|
122
|
-
"
|
|
122
|
+
"lib/esm/types.d.ts"
|
|
123
123
|
],
|
|
124
124
|
"utils": [
|
|
125
|
-
"
|
|
125
|
+
"lib/esm/utils.d.ts"
|
|
126
126
|
]
|
|
127
127
|
}
|
|
128
128
|
},
|
|
@@ -137,9 +137,9 @@
|
|
|
137
137
|
],
|
|
138
138
|
"dependencies": {
|
|
139
139
|
"zod": "^4.4.3",
|
|
140
|
-
"@morpho-org/blue-sdk": "^6.
|
|
141
|
-
"@morpho-org/morpho-ts": "^2.
|
|
142
|
-
"@morpho-org/blue-sdk-viem": "^5.1.
|
|
140
|
+
"@morpho-org/blue-sdk": "^6.3.0",
|
|
141
|
+
"@morpho-org/morpho-ts": "^2.8.0",
|
|
142
|
+
"@morpho-org/blue-sdk-viem": "^5.1.2"
|
|
143
143
|
},
|
|
144
144
|
"peerDependencies": {
|
|
145
145
|
"viem": "^2.0.0"
|
|
@@ -148,11 +148,11 @@
|
|
|
148
148
|
"dotenv": "^17.4.2",
|
|
149
149
|
"fast-check": "^4.8.0",
|
|
150
150
|
"typescript": "^6.0.3",
|
|
151
|
-
"viem": "2.
|
|
152
|
-
"vitest": "^4.1.
|
|
151
|
+
"viem": "^2.54.2",
|
|
152
|
+
"vitest": "^4.1.9",
|
|
153
153
|
"@morpho-org/bundler-sdk-viem": "^5.0.3",
|
|
154
154
|
"@morpho-org/simulation-sdk": "^4.0.3",
|
|
155
|
-
"@morpho-org/test": "^2.8.
|
|
155
|
+
"@morpho-org/test": "^2.8.2"
|
|
156
156
|
},
|
|
157
157
|
"scripts": {
|
|
158
158
|
"prepublish": "$npm_execpath build",
|
|
@@ -160,5 +160,6 @@
|
|
|
160
160
|
"build:cjs": "tsc --build tsconfig.build.cjs.json && echo '{\"type\":\"commonjs\"}' > lib/cjs/package.json",
|
|
161
161
|
"build:esm": "tsc --build tsconfig.build.esm.json && echo '{\"type\":\"module\"}' > lib/esm/package.json",
|
|
162
162
|
"test": "vitest --root ../.. --project morpho-sdk"
|
|
163
|
-
}
|
|
163
|
+
},
|
|
164
|
+
"types": "./lib/esm/index.d.ts"
|
|
164
165
|
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import type { Client } from "viem";
|
|
2
|
-
import { type Address } from "viem";
|
|
3
|
-
import { type MorphoAuthorizationAction, type Transaction } from "../../types/index.js";
|
|
4
|
-
/**
|
|
5
|
-
* Resolves whether `GeneralAdapter1` needs Morpho authorization for the given user, and returns
|
|
6
|
-
* the `setAuthorization(generalAdapter1, true)` transaction when it does.
|
|
7
|
-
*
|
|
8
|
-
* Reads `Morpho.isAuthorized(userAddress, generalAdapter1)` on the target chain. Required before
|
|
9
|
-
* any bundled Blue path that operates on behalf of the user (`borrow`,
|
|
10
|
-
* `supplyCollateralBorrow`, `repayWithdrawCollateral`).
|
|
11
|
-
*
|
|
12
|
-
* @param params.viemClient - Connected viem `Client` whose `chain.id` matches `params.chainId`.
|
|
13
|
-
* @param params.chainId - Target chain id (used to resolve Morpho and `GeneralAdapter1`).
|
|
14
|
-
* @param params.userAddress - The user that must authorize `GeneralAdapter1`.
|
|
15
|
-
* @returns A deep-frozen `Transaction<MorphoAuthorizationAction>`, or `null` when authorization
|
|
16
|
-
* is already in place.
|
|
17
|
-
* @throws {ChainIdMismatchError} when `viemClient.chain?.id !== params.chainId`.
|
|
18
|
-
* @example
|
|
19
|
-
* ```ts
|
|
20
|
-
* import { createPublicClient, http } from "viem";
|
|
21
|
-
* import { mainnet } from "viem/chains";
|
|
22
|
-
* import { getMorphoAuthorizationRequirement } from "@morpho-org/morpho-sdk";
|
|
23
|
-
*
|
|
24
|
-
* const client = createPublicClient({ chain: mainnet, transport: http() });
|
|
25
|
-
* const tx = await getMorphoAuthorizationRequirement({
|
|
26
|
-
* viemClient: client,
|
|
27
|
-
* chainId: 1,
|
|
28
|
-
* userAddress: borrower,
|
|
29
|
-
* });
|
|
30
|
-
* // tx is null when already authorized, otherwise satisfies Readonly<Transaction<MorphoAuthorizationAction>>
|
|
31
|
-
* ```
|
|
32
|
-
*/
|
|
33
|
-
export declare const getMorphoAuthorizationRequirement: (params: {
|
|
34
|
-
viemClient: Client;
|
|
35
|
-
chainId: number;
|
|
36
|
-
userAddress: Address;
|
|
37
|
-
}) => Promise<Readonly<Transaction<MorphoAuthorizationAction>> | null>;
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getMorphoAuthorizationRequirement = 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 morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
7
|
-
const viem_1 = require("viem");
|
|
8
|
-
const index_js_1 = require("../../types/index.js");
|
|
9
|
-
/**
|
|
10
|
-
* Resolves whether `GeneralAdapter1` needs Morpho authorization for the given user, and returns
|
|
11
|
-
* the `setAuthorization(generalAdapter1, true)` transaction when it does.
|
|
12
|
-
*
|
|
13
|
-
* Reads `Morpho.isAuthorized(userAddress, generalAdapter1)` on the target chain. Required before
|
|
14
|
-
* any bundled Blue path that operates on behalf of the user (`borrow`,
|
|
15
|
-
* `supplyCollateralBorrow`, `repayWithdrawCollateral`).
|
|
16
|
-
*
|
|
17
|
-
* @param params.viemClient - Connected viem `Client` whose `chain.id` matches `params.chainId`.
|
|
18
|
-
* @param params.chainId - Target chain id (used to resolve Morpho and `GeneralAdapter1`).
|
|
19
|
-
* @param params.userAddress - The user that must authorize `GeneralAdapter1`.
|
|
20
|
-
* @returns A deep-frozen `Transaction<MorphoAuthorizationAction>`, or `null` when authorization
|
|
21
|
-
* is already in place.
|
|
22
|
-
* @throws {ChainIdMismatchError} when `viemClient.chain?.id !== params.chainId`.
|
|
23
|
-
* @example
|
|
24
|
-
* ```ts
|
|
25
|
-
* import { createPublicClient, http } from "viem";
|
|
26
|
-
* import { mainnet } from "viem/chains";
|
|
27
|
-
* import { getMorphoAuthorizationRequirement } from "@morpho-org/morpho-sdk";
|
|
28
|
-
*
|
|
29
|
-
* const client = createPublicClient({ chain: mainnet, transport: http() });
|
|
30
|
-
* const tx = await getMorphoAuthorizationRequirement({
|
|
31
|
-
* viemClient: client,
|
|
32
|
-
* chainId: 1,
|
|
33
|
-
* userAddress: borrower,
|
|
34
|
-
* });
|
|
35
|
-
* // tx is null when already authorized, otherwise satisfies Readonly<Transaction<MorphoAuthorizationAction>>
|
|
36
|
-
* ```
|
|
37
|
-
*/
|
|
38
|
-
const getMorphoAuthorizationRequirement = async (params) => {
|
|
39
|
-
const { viemClient, chainId, userAddress } = params;
|
|
40
|
-
if (viemClient.chain?.id !== chainId) {
|
|
41
|
-
throw new index_js_1.ChainIdMismatchError(viemClient.chain?.id, chainId);
|
|
42
|
-
}
|
|
43
|
-
const { morpho, bundler3: { generalAdapter1 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
|
|
44
|
-
const pc = viemClient.extend(viem_1.publicActions);
|
|
45
|
-
const isAuthorized = await pc.readContract({
|
|
46
|
-
address: morpho,
|
|
47
|
-
abi: blue_sdk_viem_1.blueAbi,
|
|
48
|
-
functionName: "isAuthorized",
|
|
49
|
-
args: [userAddress, generalAdapter1],
|
|
50
|
-
});
|
|
51
|
-
if (isAuthorized) {
|
|
52
|
-
return null;
|
|
53
|
-
}
|
|
54
|
-
return (0, morpho_ts_1.deepFreeze)({
|
|
55
|
-
to: morpho,
|
|
56
|
-
data: (0, viem_1.encodeFunctionData)({
|
|
57
|
-
abi: blue_sdk_viem_1.blueAbi,
|
|
58
|
-
functionName: "setAuthorization",
|
|
59
|
-
args: [generalAdapter1, true],
|
|
60
|
-
}),
|
|
61
|
-
value: 0n,
|
|
62
|
-
action: {
|
|
63
|
-
type: "morphoAuthorization",
|
|
64
|
-
args: {
|
|
65
|
-
authorized: generalAdapter1,
|
|
66
|
-
isAuthorized: true,
|
|
67
|
-
},
|
|
68
|
-
},
|
|
69
|
-
});
|
|
70
|
-
};
|
|
71
|
-
exports.getMorphoAuthorizationRequirement = getMorphoAuthorizationRequirement;
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getRequirements = 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 morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
7
|
-
const index_js_1 = require("../../types/index.js");
|
|
8
|
-
const getRequirementsApproval_js_1 = require("./getRequirementsApproval.js");
|
|
9
|
-
const getRequirementsPermit_js_1 = require("./getRequirementsPermit.js");
|
|
10
|
-
const getRequirementsPermit2_js_1 = require("./getRequirementsPermit2.js");
|
|
11
|
-
/**
|
|
12
|
-
* Resolves the approval requirements an integrator must satisfy before a Morpho bundle pulls
|
|
13
|
-
* tokens through `GeneralAdapter1`.
|
|
14
|
-
*
|
|
15
|
-
* Reads the user's current `holding` (allowances + nonces) from the chain, then picks one of
|
|
16
|
-
* three flows:
|
|
17
|
-
*
|
|
18
|
-
* 1. **`supportSignature: false`** — classic ERC-20 `approve` transaction (or no-op when the
|
|
19
|
-
* allowance is already large enough).
|
|
20
|
-
* 2. **`supportSignature: true` + EIP-2612 supported + `useSimplePermit`** — single permit
|
|
21
|
-
* signature against the token itself. DAI is excluded from this branch (its non-standard
|
|
22
|
-
* permit signature is incompatible) and falls through to Permit2 even with
|
|
23
|
-
* `useSimplePermit: true`.
|
|
24
|
-
* 3. **`supportSignature: true`, default** — Permit2 flow: classic approval to the Permit2
|
|
25
|
-
* contract (if needed), followed by a Permit2 signature against `GeneralAdapter1`.
|
|
26
|
-
*
|
|
27
|
-
* @param viemClient - Connected viem `Client` whose `chain.id` matches `params.chainId`.
|
|
28
|
-
* @param params - Requirement resolution parameters.
|
|
29
|
-
* @param params.address - ERC-20 token address.
|
|
30
|
-
* @param params.chainId - Chain id; must match `viemClient.chain.id`.
|
|
31
|
-
* @param params.args.amount - Required token amount. Returns `[]` when zero.
|
|
32
|
-
* @param params.args.from - Account that will grant the approval.
|
|
33
|
-
* @param params.supportSignature - Whether the integrator can collect a signature; controls
|
|
34
|
-
* permit / permit2 vs. classic approval.
|
|
35
|
-
* @param params.supportDeployless - Whether to fetch holdings via deployless multicall.
|
|
36
|
-
* @param params.useSimplePermit - When `supportSignature` is `true`, prefer EIP-2612 permit if
|
|
37
|
-
* the token supports it.
|
|
38
|
-
* @returns Promise resolving to an array of either deep-frozen approval transactions or
|
|
39
|
-
* `Requirement` objects (signature requirements with a `sign()` method). Empty when the
|
|
40
|
-
* existing allowance already covers `amount`.
|
|
41
|
-
* @throws {ChainIdMismatchError} when `viemClient.chain?.id !== params.chainId`. No other typed
|
|
42
|
-
* error is reachable through this entry point: the values passed into
|
|
43
|
-
* `getRequirementsApproval` always satisfy `approvalAmount >= spendAmount` (direct path uses
|
|
44
|
-
* `approvalAmount === spendAmount === amount`; Permit2 path uses `MAX_UINT_160`), so
|
|
45
|
-
* `ApprovalAmountLessThanSpendAmountError` cannot fire from here.
|
|
46
|
-
* @example
|
|
47
|
-
* ```ts
|
|
48
|
-
* import { createPublicClient, http } from "viem";
|
|
49
|
-
* import { mainnet } from "viem/chains";
|
|
50
|
-
* import { getRequirements } from "@morpho-org/morpho-sdk";
|
|
51
|
-
*
|
|
52
|
-
* const client = createPublicClient({ chain: mainnet, transport: http() });
|
|
53
|
-
* const requirements = await getRequirements(client, {
|
|
54
|
-
* address: USDC,
|
|
55
|
-
* chainId: 1,
|
|
56
|
-
* supportSignature: true,
|
|
57
|
-
* args: { amount: 1_000_000n, from: user },
|
|
58
|
-
* });
|
|
59
|
-
* // requirements satisfies (Readonly<Transaction<ERC20ApprovalAction>> | Requirement)[]
|
|
60
|
-
* ```
|
|
61
|
-
*/
|
|
62
|
-
const getRequirements = async (viemClient, params) => {
|
|
63
|
-
const { address, chainId, supportSignature, args: { amount, from }, } = params;
|
|
64
|
-
if (viemClient.chain?.id !== chainId) {
|
|
65
|
-
throw new index_js_1.ChainIdMismatchError(viemClient.chain?.id, chainId);
|
|
66
|
-
}
|
|
67
|
-
if (amount === 0n) {
|
|
68
|
-
return [];
|
|
69
|
-
}
|
|
70
|
-
const { permit2, dai, bundler3: { generalAdapter1 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
|
|
71
|
-
const { erc20Allowances, erc2612Nonce, permit2BundlerAllowance } = await (0, blue_sdk_viem_1.fetchHolding)(from, address, viemClient, {
|
|
72
|
-
deployless: params.supportDeployless,
|
|
73
|
-
});
|
|
74
|
-
if (supportSignature) {
|
|
75
|
-
const { useSimplePermit } = params;
|
|
76
|
-
const supportSimplePermit = (0, morpho_ts_1.isDefined)(erc2612Nonce) && address !== dai;
|
|
77
|
-
if (supportSimplePermit && useSimplePermit) {
|
|
78
|
-
return await (0, getRequirementsPermit_js_1.getRequirementsPermit)(viemClient, {
|
|
79
|
-
token: address,
|
|
80
|
-
chainId,
|
|
81
|
-
args: { amount },
|
|
82
|
-
allowancesGeneralAdapter: erc20Allowances["bundler3.generalAdapter1"],
|
|
83
|
-
nonce: erc2612Nonce,
|
|
84
|
-
supportDeployless: params.supportDeployless,
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
if (permit2) {
|
|
88
|
-
return (0, getRequirementsPermit2_js_1.getRequirementsPermit2)({
|
|
89
|
-
address,
|
|
90
|
-
chainId,
|
|
91
|
-
permit2,
|
|
92
|
-
args: { amount },
|
|
93
|
-
allowancesGeneralAdapter: erc20Allowances["bundler3.generalAdapter1"],
|
|
94
|
-
allowancesPermit2: erc20Allowances.permit2,
|
|
95
|
-
allowanceGeneralAdapterPermit2: permit2BundlerAllowance.amount,
|
|
96
|
-
allowanceGeneralAdapterExpiration: permit2BundlerAllowance.expiration,
|
|
97
|
-
nonce: permit2BundlerAllowance.nonce,
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
return (0, getRequirementsApproval_js_1.getRequirementsApproval)({
|
|
102
|
-
address,
|
|
103
|
-
chainId,
|
|
104
|
-
args: {
|
|
105
|
-
spendAmount: amount,
|
|
106
|
-
approvalAmount: amount,
|
|
107
|
-
spender: generalAdapter1,
|
|
108
|
-
},
|
|
109
|
-
allowances: erc20Allowances["bundler3.generalAdapter1"],
|
|
110
|
-
});
|
|
111
|
-
};
|
|
112
|
-
exports.getRequirements = getRequirements;
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getRequirementsPermit = void 0;
|
|
4
|
-
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
5
|
-
const index_js_1 = require("./encode/index.js");
|
|
6
|
-
/**
|
|
7
|
-
* Computes the EIP-2612 permit `Requirement` an integrator must sign so that `GeneralAdapter1`
|
|
8
|
-
* can pull `amount` of `token`.
|
|
9
|
-
*
|
|
10
|
-
* Returns an empty array when the existing allowance for `GeneralAdapter1` already covers
|
|
11
|
-
* `amount`.
|
|
12
|
-
*
|
|
13
|
-
* @param viemClient - Connected viem `Client` (used by the returned `Requirement.sign()`).
|
|
14
|
-
* @param params.token - ERC-20 token address (must support EIP-2612).
|
|
15
|
-
* @param params.chainId - The chain the bundle targets.
|
|
16
|
-
* @param params.args.amount - Required token amount.
|
|
17
|
-
* @param params.allowancesGeneralAdapter - The user's current allowance of `token` for
|
|
18
|
-
* `GeneralAdapter1`.
|
|
19
|
-
* @param params.nonce - The user's current EIP-2612 nonce on `token`.
|
|
20
|
-
* @param params.supportDeployless - Whether to fetch token metadata via deployless multicall.
|
|
21
|
-
* @returns A single-element array containing the `Requirement` to sign, or an empty array when
|
|
22
|
-
* the existing allowance already covers `amount`.
|
|
23
|
-
* @example
|
|
24
|
-
* ```ts
|
|
25
|
-
* import { createWalletClient, http } from "viem";
|
|
26
|
-
* import { mainnet } from "viem/chains";
|
|
27
|
-
* import { getRequirementsPermit } from "@morpho-org/morpho-sdk";
|
|
28
|
-
*
|
|
29
|
-
* const client = createWalletClient({ chain: mainnet, transport: http() });
|
|
30
|
-
* const reqs = await getRequirementsPermit(client, {
|
|
31
|
-
* token: USDC, // an ERC-2612-compatible token; DAI is excluded by getRequirements
|
|
32
|
-
* chainId: 1,
|
|
33
|
-
* args: { amount: 1_000_000n },
|
|
34
|
-
* allowancesGeneralAdapter: 0n,
|
|
35
|
-
* nonce: 0n,
|
|
36
|
-
* });
|
|
37
|
-
* // reqs satisfies Requirement[]
|
|
38
|
-
* ```
|
|
39
|
-
*/
|
|
40
|
-
const getRequirementsPermit = async (viemClient, params) => {
|
|
41
|
-
const { token, chainId, args: { amount }, allowancesGeneralAdapter, nonce, supportDeployless, } = params;
|
|
42
|
-
const { bundler3: { generalAdapter1 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
|
|
43
|
-
if (allowancesGeneralAdapter < amount) {
|
|
44
|
-
return [
|
|
45
|
-
await (0, index_js_1.encodeErc20Permit)(viemClient, {
|
|
46
|
-
token,
|
|
47
|
-
spender: generalAdapter1,
|
|
48
|
-
amount,
|
|
49
|
-
chainId,
|
|
50
|
-
nonce,
|
|
51
|
-
supportDeployless,
|
|
52
|
-
}),
|
|
53
|
-
];
|
|
54
|
-
}
|
|
55
|
-
return [];
|
|
56
|
-
};
|
|
57
|
-
exports.getRequirementsPermit = getRequirementsPermit;
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { type Address } from "@morpho-org/blue-sdk";
|
|
2
|
-
import type { ERC20ApprovalAction, Requirement, Transaction } from "../../types/index.js";
|
|
3
|
-
/**
|
|
4
|
-
* Computes the Permit2 prerequisites for `GeneralAdapter1` to pull `amount` of `address`.
|
|
5
|
-
*
|
|
6
|
-
* Returns an empty array when the direct adapter allowance already covers `amount`. Otherwise
|
|
7
|
-
* emits two ordered prerequisites:
|
|
8
|
-
*
|
|
9
|
-
* 1. A classic ERC-20 approval to the Permit2 contract (infinite, if not already in place).
|
|
10
|
-
* 2. A Permit2 `Requirement` signed against `GeneralAdapter1` (skipped when the existing
|
|
11
|
-
* Permit2-managed allowance covers `amount` and is not about to expire within four hours).
|
|
12
|
-
*
|
|
13
|
-
* @param params.address - ERC-20 token address.
|
|
14
|
-
* @param params.chainId - The chain the bundle targets.
|
|
15
|
-
* @param params.permit2 - The Permit2 contract address for the chain.
|
|
16
|
-
* @param params.args.amount - Required token amount.
|
|
17
|
-
* @param params.allowancesPermit2 - The user's current allowance of `address` for the Permit2
|
|
18
|
-
* contract.
|
|
19
|
-
* @param params.allowancesGeneralAdapter - The user's current direct allowance of `address` for
|
|
20
|
-
* `GeneralAdapter1` (separate from the Permit2-managed allowance).
|
|
21
|
-
* @param params.allowanceGeneralAdapterPermit2 - The Permit2-managed allowance for
|
|
22
|
-
* `GeneralAdapter1` to spend `address`.
|
|
23
|
-
* @param params.allowanceGeneralAdapterExpiration - Expiration timestamp of the Permit2-managed
|
|
24
|
-
* allowance.
|
|
25
|
-
* @param params.nonce - The user's current Permit2 nonce for `(address, GeneralAdapter1)`.
|
|
26
|
-
* @returns Ordered list of approval transactions and/or `Requirement` objects to satisfy before
|
|
27
|
-
* bundling.
|
|
28
|
-
* @throws {ApprovalAmountLessThanSpendAmountError} from the inner approval helper when its
|
|
29
|
-
* bookkeeping invariants break (should not happen with the values this function passes).
|
|
30
|
-
* @example
|
|
31
|
-
* ```ts
|
|
32
|
-
* import { getChainAddresses } from "@morpho-org/blue-sdk";
|
|
33
|
-
* import { getRequirementsPermit2 } from "@morpho-org/morpho-sdk";
|
|
34
|
-
*
|
|
35
|
-
* const { permit2 } = getChainAddresses(1);
|
|
36
|
-
* if (!permit2) throw new Error("Permit2 not configured for this chain");
|
|
37
|
-
* const requirements = getRequirementsPermit2({
|
|
38
|
-
* address: USDC,
|
|
39
|
-
* chainId: 1,
|
|
40
|
-
* permit2,
|
|
41
|
-
* args: { amount: 1_000_000n },
|
|
42
|
-
* allowancesPermit2: 0n,
|
|
43
|
-
* allowancesGeneralAdapter: 0n,
|
|
44
|
-
* allowanceGeneralAdapterPermit2: 0n,
|
|
45
|
-
* allowanceGeneralAdapterExpiration: 0n,
|
|
46
|
-
* nonce: 0n,
|
|
47
|
-
* });
|
|
48
|
-
* // requirements satisfies (Readonly<Transaction<ERC20ApprovalAction> | Requirement>)[]
|
|
49
|
-
* ```
|
|
50
|
-
*/
|
|
51
|
-
export declare const getRequirementsPermit2: (params: {
|
|
52
|
-
address: Address;
|
|
53
|
-
chainId: number;
|
|
54
|
-
permit2: Address;
|
|
55
|
-
args: {
|
|
56
|
-
amount: bigint;
|
|
57
|
-
};
|
|
58
|
-
allowancesPermit2: bigint;
|
|
59
|
-
allowancesGeneralAdapter: bigint;
|
|
60
|
-
allowanceGeneralAdapterPermit2: bigint;
|
|
61
|
-
allowanceGeneralAdapterExpiration: bigint;
|
|
62
|
-
nonce: bigint;
|
|
63
|
-
}) => Readonly<Transaction<ERC20ApprovalAction> | Requirement>[];
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getRequirementsPermit2 = void 0;
|
|
4
|
-
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
5
|
-
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
6
|
-
const encodeErc20Permit2_js_1 = require("./encode/encodeErc20Permit2.js");
|
|
7
|
-
const getRequirementsApproval_js_1 = require("./getRequirementsApproval.js");
|
|
8
|
-
/**
|
|
9
|
-
* Computes the Permit2 prerequisites for `GeneralAdapter1` to pull `amount` of `address`.
|
|
10
|
-
*
|
|
11
|
-
* Returns an empty array when the direct adapter allowance already covers `amount`. Otherwise
|
|
12
|
-
* emits two ordered prerequisites:
|
|
13
|
-
*
|
|
14
|
-
* 1. A classic ERC-20 approval to the Permit2 contract (infinite, if not already in place).
|
|
15
|
-
* 2. A Permit2 `Requirement` signed against `GeneralAdapter1` (skipped when the existing
|
|
16
|
-
* Permit2-managed allowance covers `amount` and is not about to expire within four hours).
|
|
17
|
-
*
|
|
18
|
-
* @param params.address - ERC-20 token address.
|
|
19
|
-
* @param params.chainId - The chain the bundle targets.
|
|
20
|
-
* @param params.permit2 - The Permit2 contract address for the chain.
|
|
21
|
-
* @param params.args.amount - Required token amount.
|
|
22
|
-
* @param params.allowancesPermit2 - The user's current allowance of `address` for the Permit2
|
|
23
|
-
* contract.
|
|
24
|
-
* @param params.allowancesGeneralAdapter - The user's current direct allowance of `address` for
|
|
25
|
-
* `GeneralAdapter1` (separate from the Permit2-managed allowance).
|
|
26
|
-
* @param params.allowanceGeneralAdapterPermit2 - The Permit2-managed allowance for
|
|
27
|
-
* `GeneralAdapter1` to spend `address`.
|
|
28
|
-
* @param params.allowanceGeneralAdapterExpiration - Expiration timestamp of the Permit2-managed
|
|
29
|
-
* allowance.
|
|
30
|
-
* @param params.nonce - The user's current Permit2 nonce for `(address, GeneralAdapter1)`.
|
|
31
|
-
* @returns Ordered list of approval transactions and/or `Requirement` objects to satisfy before
|
|
32
|
-
* bundling.
|
|
33
|
-
* @throws {ApprovalAmountLessThanSpendAmountError} from the inner approval helper when its
|
|
34
|
-
* bookkeeping invariants break (should not happen with the values this function passes).
|
|
35
|
-
* @example
|
|
36
|
-
* ```ts
|
|
37
|
-
* import { getChainAddresses } from "@morpho-org/blue-sdk";
|
|
38
|
-
* import { getRequirementsPermit2 } from "@morpho-org/morpho-sdk";
|
|
39
|
-
*
|
|
40
|
-
* const { permit2 } = getChainAddresses(1);
|
|
41
|
-
* if (!permit2) throw new Error("Permit2 not configured for this chain");
|
|
42
|
-
* const requirements = getRequirementsPermit2({
|
|
43
|
-
* address: USDC,
|
|
44
|
-
* chainId: 1,
|
|
45
|
-
* permit2,
|
|
46
|
-
* args: { amount: 1_000_000n },
|
|
47
|
-
* allowancesPermit2: 0n,
|
|
48
|
-
* allowancesGeneralAdapter: 0n,
|
|
49
|
-
* allowanceGeneralAdapterPermit2: 0n,
|
|
50
|
-
* allowanceGeneralAdapterExpiration: 0n,
|
|
51
|
-
* nonce: 0n,
|
|
52
|
-
* });
|
|
53
|
-
* // requirements satisfies (Readonly<Transaction<ERC20ApprovalAction> | Requirement>)[]
|
|
54
|
-
* ```
|
|
55
|
-
*/
|
|
56
|
-
const getRequirementsPermit2 = (params) => {
|
|
57
|
-
const { address, chainId, permit2, args: { amount }, allowancesPermit2, allowancesGeneralAdapter, allowanceGeneralAdapterPermit2, allowanceGeneralAdapterExpiration, nonce, } = params;
|
|
58
|
-
if (allowancesGeneralAdapter >= amount) {
|
|
59
|
-
return [];
|
|
60
|
-
}
|
|
61
|
-
const requirements = [];
|
|
62
|
-
const approvalRequirements = (0, getRequirementsApproval_js_1.getRequirementsApproval)({
|
|
63
|
-
address,
|
|
64
|
-
chainId,
|
|
65
|
-
args: {
|
|
66
|
-
approvalAmount: blue_sdk_1.MathLib.MAX_UINT_160, // Always approve infinite.
|
|
67
|
-
spendAmount: amount,
|
|
68
|
-
spender: permit2,
|
|
69
|
-
},
|
|
70
|
-
allowances: allowancesPermit2,
|
|
71
|
-
});
|
|
72
|
-
requirements.push(...approvalRequirements);
|
|
73
|
-
if (allowanceGeneralAdapterPermit2 < amount ||
|
|
74
|
-
allowanceGeneralAdapterExpiration < morpho_ts_1.Time.timestamp() + morpho_ts_1.Time.s.from.h(4n)) {
|
|
75
|
-
requirements.push((0, encodeErc20Permit2_js_1.encodeErc20Permit2)({
|
|
76
|
-
token: address,
|
|
77
|
-
amount,
|
|
78
|
-
chainId,
|
|
79
|
-
nonce,
|
|
80
|
-
expiration: blue_sdk_1.MathLib.MAX_UINT_48, // Always approve indefinitely.
|
|
81
|
-
}));
|
|
82
|
-
}
|
|
83
|
-
return requirements;
|
|
84
|
-
};
|
|
85
|
-
exports.getRequirementsPermit2 = getRequirementsPermit2;
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import type { Client } from "viem";
|
|
2
|
-
import { type Address } from "viem";
|
|
3
|
-
import { type MorphoAuthorizationAction, type Transaction } from "../../types/index.js";
|
|
4
|
-
/**
|
|
5
|
-
* Resolves whether `GeneralAdapter1` needs Morpho authorization for the given user, and returns
|
|
6
|
-
* the `setAuthorization(generalAdapter1, true)` transaction when it does.
|
|
7
|
-
*
|
|
8
|
-
* Reads `Morpho.isAuthorized(userAddress, generalAdapter1)` on the target chain. Required before
|
|
9
|
-
* any bundled Blue path that operates on behalf of the user (`borrow`,
|
|
10
|
-
* `supplyCollateralBorrow`, `repayWithdrawCollateral`).
|
|
11
|
-
*
|
|
12
|
-
* @param params.viemClient - Connected viem `Client` whose `chain.id` matches `params.chainId`.
|
|
13
|
-
* @param params.chainId - Target chain id (used to resolve Morpho and `GeneralAdapter1`).
|
|
14
|
-
* @param params.userAddress - The user that must authorize `GeneralAdapter1`.
|
|
15
|
-
* @returns A deep-frozen `Transaction<MorphoAuthorizationAction>`, or `null` when authorization
|
|
16
|
-
* is already in place.
|
|
17
|
-
* @throws {ChainIdMismatchError} when `viemClient.chain?.id !== params.chainId`.
|
|
18
|
-
* @example
|
|
19
|
-
* ```ts
|
|
20
|
-
* import { createPublicClient, http } from "viem";
|
|
21
|
-
* import { mainnet } from "viem/chains";
|
|
22
|
-
* import { getMorphoAuthorizationRequirement } from "@morpho-org/morpho-sdk";
|
|
23
|
-
*
|
|
24
|
-
* const client = createPublicClient({ chain: mainnet, transport: http() });
|
|
25
|
-
* const tx = await getMorphoAuthorizationRequirement({
|
|
26
|
-
* viemClient: client,
|
|
27
|
-
* chainId: 1,
|
|
28
|
-
* userAddress: borrower,
|
|
29
|
-
* });
|
|
30
|
-
* // tx is null when already authorized, otherwise satisfies Readonly<Transaction<MorphoAuthorizationAction>>
|
|
31
|
-
* ```
|
|
32
|
-
*/
|
|
33
|
-
export declare const getMorphoAuthorizationRequirement: (params: {
|
|
34
|
-
viemClient: Client;
|
|
35
|
-
chainId: number;
|
|
36
|
-
userAddress: Address;
|
|
37
|
-
}) => Promise<Readonly<Transaction<MorphoAuthorizationAction>> | null>;
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { getChainAddresses } from "@morpho-org/blue-sdk";
|
|
2
|
-
import { blueAbi } from "@morpho-org/blue-sdk-viem";
|
|
3
|
-
import { deepFreeze } from "@morpho-org/morpho-ts";
|
|
4
|
-
import { encodeFunctionData, publicActions } from "viem";
|
|
5
|
-
import { ChainIdMismatchError, } from "../../types/index.js";
|
|
6
|
-
/**
|
|
7
|
-
* Resolves whether `GeneralAdapter1` needs Morpho authorization for the given user, and returns
|
|
8
|
-
* the `setAuthorization(generalAdapter1, true)` transaction when it does.
|
|
9
|
-
*
|
|
10
|
-
* Reads `Morpho.isAuthorized(userAddress, generalAdapter1)` on the target chain. Required before
|
|
11
|
-
* any bundled Blue path that operates on behalf of the user (`borrow`,
|
|
12
|
-
* `supplyCollateralBorrow`, `repayWithdrawCollateral`).
|
|
13
|
-
*
|
|
14
|
-
* @param params.viemClient - Connected viem `Client` whose `chain.id` matches `params.chainId`.
|
|
15
|
-
* @param params.chainId - Target chain id (used to resolve Morpho and `GeneralAdapter1`).
|
|
16
|
-
* @param params.userAddress - The user that must authorize `GeneralAdapter1`.
|
|
17
|
-
* @returns A deep-frozen `Transaction<MorphoAuthorizationAction>`, or `null` when authorization
|
|
18
|
-
* is already in place.
|
|
19
|
-
* @throws {ChainIdMismatchError} when `viemClient.chain?.id !== params.chainId`.
|
|
20
|
-
* @example
|
|
21
|
-
* ```ts
|
|
22
|
-
* import { createPublicClient, http } from "viem";
|
|
23
|
-
* import { mainnet } from "viem/chains";
|
|
24
|
-
* import { getMorphoAuthorizationRequirement } from "@morpho-org/morpho-sdk";
|
|
25
|
-
*
|
|
26
|
-
* const client = createPublicClient({ chain: mainnet, transport: http() });
|
|
27
|
-
* const tx = await getMorphoAuthorizationRequirement({
|
|
28
|
-
* viemClient: client,
|
|
29
|
-
* chainId: 1,
|
|
30
|
-
* userAddress: borrower,
|
|
31
|
-
* });
|
|
32
|
-
* // tx is null when already authorized, otherwise satisfies Readonly<Transaction<MorphoAuthorizationAction>>
|
|
33
|
-
* ```
|
|
34
|
-
*/
|
|
35
|
-
export const getMorphoAuthorizationRequirement = async (params) => {
|
|
36
|
-
const { viemClient, chainId, userAddress } = params;
|
|
37
|
-
if (viemClient.chain?.id !== chainId) {
|
|
38
|
-
throw new ChainIdMismatchError(viemClient.chain?.id, chainId);
|
|
39
|
-
}
|
|
40
|
-
const { morpho, bundler3: { generalAdapter1 }, } = getChainAddresses(chainId);
|
|
41
|
-
const pc = viemClient.extend(publicActions);
|
|
42
|
-
const isAuthorized = await pc.readContract({
|
|
43
|
-
address: morpho,
|
|
44
|
-
abi: blueAbi,
|
|
45
|
-
functionName: "isAuthorized",
|
|
46
|
-
args: [userAddress, generalAdapter1],
|
|
47
|
-
});
|
|
48
|
-
if (isAuthorized) {
|
|
49
|
-
return null;
|
|
50
|
-
}
|
|
51
|
-
return deepFreeze({
|
|
52
|
-
to: morpho,
|
|
53
|
-
data: encodeFunctionData({
|
|
54
|
-
abi: blueAbi,
|
|
55
|
-
functionName: "setAuthorization",
|
|
56
|
-
args: [generalAdapter1, true],
|
|
57
|
-
}),
|
|
58
|
-
value: 0n,
|
|
59
|
-
action: {
|
|
60
|
-
type: "morphoAuthorization",
|
|
61
|
-
args: {
|
|
62
|
-
authorized: generalAdapter1,
|
|
63
|
-
isAuthorized: true,
|
|
64
|
-
},
|
|
65
|
-
},
|
|
66
|
-
});
|
|
67
|
-
};
|