@morpho-org/morpho-sdk 4.2.0 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -12
- package/lib/cjs/actions/blue/borrow.d.ts +12 -2
- package/lib/cjs/actions/blue/borrow.js +7 -1
- 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 +6 -5
- package/lib/cjs/actions/blue/repay.js +10 -18
- package/lib/cjs/actions/blue/repayWithdrawCollateral.d.ts +15 -6
- package/lib/cjs/actions/blue/repayWithdrawCollateral.js +16 -18
- package/lib/cjs/actions/blue/supply.d.ts +7 -7
- package/lib/cjs/actions/blue/supply.js +10 -20
- package/lib/cjs/actions/blue/supplyCollateral.d.ts +8 -8
- package/lib/cjs/actions/blue/supplyCollateral.js +11 -21
- package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +18 -6
- package/lib/cjs/actions/blue/supplyCollateralBorrow.js +17 -19
- 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 +171 -125
- 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/validate.d.ts +2 -2
- package/lib/cjs/helpers/validate.js +1 -1
- package/lib/cjs/types/action.d.ts +113 -9
- package/lib/cjs/types/action.js +79 -5
- package/lib/cjs/types/error.d.ts +73 -0
- package/lib/cjs/types/error.js +89 -4
- package/lib/cjs/types.d.ts +2 -1
- package/lib/cjs/utils.d.ts +1 -1
- package/lib/cjs/utils.js +2 -3
- package/lib/esm/actions/blue/borrow.d.ts +12 -2
- package/lib/esm/actions/blue/borrow.js +7 -1
- 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 +6 -5
- package/lib/esm/actions/blue/repay.js +10 -18
- package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +15 -6
- package/lib/esm/actions/blue/repayWithdrawCollateral.js +16 -18
- package/lib/esm/actions/blue/supply.d.ts +7 -7
- package/lib/esm/actions/blue/supply.js +10 -20
- package/lib/esm/actions/blue/supplyCollateral.d.ts +8 -8
- package/lib/esm/actions/blue/supplyCollateral.js +11 -21
- package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +18 -6
- package/lib/esm/actions/blue/supplyCollateralBorrow.js +17 -19
- 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 +173 -127
- 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/validate.d.ts +2 -2
- package/lib/esm/helpers/validate.js +1 -1
- package/lib/esm/types/action.d.ts +113 -9
- package/lib/esm/types/action.js +75 -4
- package/lib/esm/types/error.d.ts +73 -0
- package/lib/esm/types/error.js +84 -2
- package/lib/esm/types.d.ts +2 -1
- package/lib/esm/utils.d.ts +1 -1
- package/lib/esm/utils.js +1 -1
- package/package.json +6 -6
- 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/README.md
CHANGED
|
@@ -45,13 +45,13 @@ pnpm add @morpho-org/morpho-sdk
|
|
|
45
45
|
|
|
46
46
|
Every action that touches a user's tokens or positions returns two things:
|
|
47
47
|
|
|
48
|
-
- `buildTx(
|
|
48
|
+
- `buildTx(signatures?)` — builds the final viem `Transaction` object. Takes an optional array of collected `RequirementSignature`s (permit / Permit2 and/or Morpho authorization).
|
|
49
49
|
- `getRequirements()` — returns the list of on-chain pre-requisites that must be satisfied first.
|
|
50
50
|
|
|
51
51
|
Typical requirements:
|
|
52
52
|
|
|
53
53
|
- **ERC-20 approval** — the user must approve the bundler (or Morpho directly) to pull tokens. Returned as a standard `approve` transaction the consumer sends first.
|
|
54
|
-
- **Permit / Permit2 signature** — off-chain approvals that go into `buildTx`
|
|
54
|
+
- **Permit / Permit2 signature** — off-chain approvals that go into `buildTx` in the `signatures` array, avoiding the extra approval tx. Enabled via `morphoViemExtension({ supportSignature: true })`.
|
|
55
55
|
- **Morpho authorization** — `borrow`, `supplyCollateralBorrow`, and `repayWithdrawCollateral` require the user to authorize `GeneralAdapter1` on the Morpho contract once (`setAuthorization`). The SDK returns this as an extra transaction if it's missing.
|
|
56
56
|
|
|
57
57
|
Usage pattern:
|
|
@@ -66,12 +66,12 @@ const requirements = await getRequirements();
|
|
|
66
66
|
|
|
67
67
|
// Consumer satisfies each requirement (send tx / sign permit), collects the signature,
|
|
68
68
|
// then calls buildTx to get the final transaction:
|
|
69
|
-
const tx = buildTx(permitSignature);
|
|
69
|
+
const tx = buildTx([permitSignature]);
|
|
70
70
|
```
|
|
71
71
|
|
|
72
72
|
### Integration invariant — builder = signer
|
|
73
73
|
|
|
74
|
-
**`userAddress` MUST equal the account that ends up signing/executing the tx.** Critical for `repayWithdrawCollateral`, whose bundle mixes explicit `onBehalf` (repay) with implicit `msg.sender` (transfer-from + withdraw) — see [BUNDLER3.md](./BUNDLER3.md#other-pitfalls). Transaction builders do not validate this at build time, so callers MUST keep `userAddress` aligned with the signing account themselves. The signature requirements (`encodeErc20Permit` / `
|
|
74
|
+
**`userAddress` MUST equal the account that ends up signing/executing the tx.** Critical for `repayWithdrawCollateral`, whose bundle mixes explicit `onBehalf` (repay) with implicit `msg.sender` (transfer-from + withdraw) — see [BUNDLER3.md](./BUNDLER3.md#other-pitfalls). Transaction builders do not validate this at build time, so callers MUST keep `userAddress` aligned with the signing account themselves. The signature requirements (`encodeErc20Permit` / `encodeErc20Permit2Approve`) take a `WalletClient` and enforce the invariant at `sign()` time via `validateUserAddress`, rejecting any `sign(client, userAddress)` where `client.account.address !== userAddress` with `MissingClientPropertyError` / `AddressMismatchError`.
|
|
75
75
|
|
|
76
76
|
| Entity | Action | Route | Why |
|
|
77
77
|
| ------------ | ------------------------ | ------------------------- | --------------------------------------------------------------------------------------------------- |
|
|
@@ -114,7 +114,7 @@ const { buildTx, getRequirements } = await vault.deposit({
|
|
|
114
114
|
});
|
|
115
115
|
|
|
116
116
|
const requirements = await getRequirements();
|
|
117
|
-
const tx = buildTx(requirementSignature);
|
|
117
|
+
const tx = buildTx([requirementSignature]);
|
|
118
118
|
```
|
|
119
119
|
|
|
120
120
|
##### Deposit with native token wrapping
|
|
@@ -199,7 +199,7 @@ const { buildTx, getRequirements } = await vault.deposit({
|
|
|
199
199
|
});
|
|
200
200
|
|
|
201
201
|
const requirements = await getRequirements();
|
|
202
|
-
const tx = buildTx(requirementSignature);
|
|
202
|
+
const tx = buildTx([requirementSignature]);
|
|
203
203
|
```
|
|
204
204
|
|
|
205
205
|
#### Withdraw
|
|
@@ -240,7 +240,7 @@ const { buildTx, getRequirements } = sourceVault.migrateToV2({
|
|
|
240
240
|
});
|
|
241
241
|
|
|
242
242
|
const requirements = await getRequirements();
|
|
243
|
-
const tx = buildTx(requirementSignature);
|
|
243
|
+
const tx = buildTx([requirementSignature]);
|
|
244
244
|
```
|
|
245
245
|
|
|
246
246
|
### Blue
|
|
@@ -275,7 +275,7 @@ const { buildTx, getRequirements } = market.supply({
|
|
|
275
275
|
});
|
|
276
276
|
|
|
277
277
|
const requirements = await getRequirements();
|
|
278
|
-
const tx = buildTx(requirementSignature);
|
|
278
|
+
const tx = buildTx([requirementSignature]);
|
|
279
279
|
```
|
|
280
280
|
|
|
281
281
|
##### Supply with native token wrapping
|
|
@@ -301,7 +301,7 @@ const { buildTx, getRequirements } = market.supplyCollateral({
|
|
|
301
301
|
});
|
|
302
302
|
|
|
303
303
|
const requirements = await getRequirements();
|
|
304
|
-
const tx = buildTx(requirementSignature);
|
|
304
|
+
const tx = buildTx([requirementSignature]);
|
|
305
305
|
```
|
|
306
306
|
|
|
307
307
|
#### Borrow
|
|
@@ -332,7 +332,7 @@ const { buildTx, getRequirements } = market.supplyCollateralBorrow({
|
|
|
332
332
|
});
|
|
333
333
|
|
|
334
334
|
const requirements = await getRequirements();
|
|
335
|
-
const tx = buildTx(requirementSignature);
|
|
335
|
+
const tx = buildTx([requirementSignature]);
|
|
336
336
|
```
|
|
337
337
|
|
|
338
338
|
#### Repay
|
|
@@ -357,7 +357,7 @@ const { buildTx, getRequirements } = market.repay({
|
|
|
357
357
|
});
|
|
358
358
|
|
|
359
359
|
const requirements = await getRequirements();
|
|
360
|
-
const tx = buildTx(requirementSignature);
|
|
360
|
+
const tx = buildTx([requirementSignature]);
|
|
361
361
|
```
|
|
362
362
|
|
|
363
363
|
Repay does **not** require Morpho authorization (it only requires a loan token approval for `GeneralAdapter1`).
|
|
@@ -418,7 +418,7 @@ const { buildTx, getRequirements } = market.repayWithdrawCollateral({
|
|
|
418
418
|
});
|
|
419
419
|
|
|
420
420
|
const requirements = await getRequirements();
|
|
421
|
-
const tx = buildTx(requirementSignature);
|
|
421
|
+
const tx = buildTx([requirementSignature]);
|
|
422
422
|
```
|
|
423
423
|
|
|
424
424
|
Atomically bundles repay → withdraw collateral via bundler3. Bundle order is critical: repay runs first to reduce debt, then withdraw. Requires both a loan token approval (for repay) and a Morpho authorization (for withdraw). The SDK validates combined position health by simulating the repay before checking withdrawal safety.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { MarketParams } from "@morpho-org/blue-sdk";
|
|
2
2
|
import type { Address } from "viem";
|
|
3
|
-
import { type BlueBorrowAction, type Metadata, type Transaction, type VaultReallocation } from "../../types/index.js";
|
|
3
|
+
import { type AuthorizationRequirementSignature, type BlueBorrowAction, type Metadata, type Transaction, type VaultReallocation } from "../../types/index.js";
|
|
4
4
|
/** Parameters for {@link blueBorrow}. */
|
|
5
5
|
export interface BlueBorrowParams {
|
|
6
6
|
market: {
|
|
@@ -8,12 +8,20 @@ export interface BlueBorrowParams {
|
|
|
8
8
|
readonly marketParams: MarketParams;
|
|
9
9
|
};
|
|
10
10
|
args: {
|
|
11
|
+
/** Amount of loan asset to borrow. */
|
|
11
12
|
amount: bigint;
|
|
13
|
+
/** Address that receives the borrowed assets. */
|
|
12
14
|
receiver: Address;
|
|
13
15
|
/** Minimum borrow share price (in ray). Protects against share price manipulation. */
|
|
14
16
|
minSharePrice: bigint;
|
|
15
17
|
/** Vault reallocations to execute before borrowing (computed by entity). */
|
|
16
18
|
reallocations?: readonly VaultReallocation[];
|
|
19
|
+
/**
|
|
20
|
+
* Optional signed Morpho authorization. When provided, a `setAuthorizationWithSig` call is
|
|
21
|
+
* prepended to the bundle so GeneralAdapter1 is authorized in-bundle instead of via a
|
|
22
|
+
* standalone `setAuthorization` transaction.
|
|
23
|
+
*/
|
|
24
|
+
authorizationSignature?: AuthorizationRequirementSignature;
|
|
17
25
|
};
|
|
18
26
|
metadata?: Metadata;
|
|
19
27
|
}
|
|
@@ -35,6 +43,8 @@ export interface BlueBorrowParams {
|
|
|
35
43
|
* @param params.args.minSharePrice - Minimum borrow share price (in ray). Slippage protection.
|
|
36
44
|
* @param params.args.reallocations - Optional vault reallocations to execute before borrowing,
|
|
37
45
|
* computed by the entity layer.
|
|
46
|
+
* @param params.args.authorizationSignature - Optional signed Morpho authorization; when present,
|
|
47
|
+
* a `setAuthorizationWithSig` call is prepended to the bundle.
|
|
38
48
|
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
39
49
|
* @returns A deep-frozen `Transaction<BlueBorrowAction>` with `to`, `value`, `data`, and the
|
|
40
50
|
* typed `action` discriminator the simulation layer consumes.
|
|
@@ -66,4 +76,4 @@ export interface BlueBorrowParams {
|
|
|
66
76
|
* // tx satisfies Readonly<Transaction<BlueBorrowAction>>
|
|
67
77
|
* ```
|
|
68
78
|
*/
|
|
69
|
-
export declare const blueBorrow: ({ market: { chainId, marketParams }, args: { amount, receiver, minSharePrice, reallocations }, metadata, }: BlueBorrowParams) => Readonly<Transaction<BlueBorrowAction>>;
|
|
79
|
+
export declare const blueBorrow: ({ market: { chainId, marketParams }, args: { amount, receiver, minSharePrice, reallocations, authorizationSignature, }, metadata, }: BlueBorrowParams) => Readonly<Transaction<BlueBorrowAction>>;
|
|
@@ -5,6 +5,7 @@ const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
|
5
5
|
const index_js_1 = require("../../bundler/index.js");
|
|
6
6
|
const index_js_2 = require("../../helpers/index.js");
|
|
7
7
|
const index_js_3 = require("../../types/index.js");
|
|
8
|
+
const getBlueAuthorizationAction_js_1 = require("../signatures/getBlueAuthorizationAction.js");
|
|
8
9
|
const buildReallocationActions_js_1 = require("./buildReallocationActions.js");
|
|
9
10
|
/**
|
|
10
11
|
* Prepares a borrow transaction for a Morpho Blue market.
|
|
@@ -24,6 +25,8 @@ const buildReallocationActions_js_1 = require("./buildReallocationActions.js");
|
|
|
24
25
|
* @param params.args.minSharePrice - Minimum borrow share price (in ray). Slippage protection.
|
|
25
26
|
* @param params.args.reallocations - Optional vault reallocations to execute before borrowing,
|
|
26
27
|
* computed by the entity layer.
|
|
28
|
+
* @param params.args.authorizationSignature - Optional signed Morpho authorization; when present,
|
|
29
|
+
* a `setAuthorizationWithSig` call is prepended to the bundle.
|
|
27
30
|
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
28
31
|
* @returns A deep-frozen `Transaction<BlueBorrowAction>` with `to`, `value`, `data`, and the
|
|
29
32
|
* typed `action` discriminator the simulation layer consumes.
|
|
@@ -55,7 +58,7 @@ const buildReallocationActions_js_1 = require("./buildReallocationActions.js");
|
|
|
55
58
|
* // tx satisfies Readonly<Transaction<BlueBorrowAction>>
|
|
56
59
|
* ```
|
|
57
60
|
*/
|
|
58
|
-
const blueBorrow = ({ market: { chainId, marketParams }, args: { amount, receiver, minSharePrice, reallocations }, metadata, }) => {
|
|
61
|
+
const blueBorrow = ({ market: { chainId, marketParams }, args: { amount, receiver, minSharePrice, reallocations, authorizationSignature, }, metadata, }) => {
|
|
59
62
|
if (amount <= 0n) {
|
|
60
63
|
throw new index_js_3.NonPositiveBorrowAmountError(marketParams.id);
|
|
61
64
|
}
|
|
@@ -64,6 +67,9 @@ const blueBorrow = ({ market: { chainId, marketParams }, args: { amount, receive
|
|
|
64
67
|
}
|
|
65
68
|
const actions = [];
|
|
66
69
|
let reallocationFee = 0n;
|
|
70
|
+
if (authorizationSignature) {
|
|
71
|
+
actions.push((0, getBlueAuthorizationAction_js_1.getBlueAuthorizationAction)(chainId, authorizationSignature));
|
|
72
|
+
}
|
|
67
73
|
if (reallocations && reallocations.length > 0) {
|
|
68
74
|
const result = (0, buildReallocationActions_js_1.buildReallocationActions)(reallocations, marketParams);
|
|
69
75
|
actions.push(...result.actions);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type MarketParams } from "@morpho-org/blue-sdk";
|
|
2
2
|
import { type Address } from "viem";
|
|
3
|
-
import { type BlueRefinanceAction, type Metadata, type Transaction, type VaultReallocation } from "../../types/index.js";
|
|
3
|
+
import { type AuthorizationRequirementSignature, type BlueRefinanceAction, type Metadata, type Transaction, type VaultReallocation } from "../../types/index.js";
|
|
4
4
|
/** Parameters for {@link blueRefinance}. */
|
|
5
5
|
export interface BlueRefinanceParams {
|
|
6
6
|
source: {
|
|
@@ -11,7 +11,9 @@ export interface BlueRefinanceParams {
|
|
|
11
11
|
readonly marketParams: MarketParams;
|
|
12
12
|
};
|
|
13
13
|
args: {
|
|
14
|
+
/** Address whose position is refinanced from the source to the target market. */
|
|
14
15
|
user: Address;
|
|
16
|
+
/** Amount of collateral moved from the source market to the target market. */
|
|
15
17
|
collateralAmount: bigint;
|
|
16
18
|
/**
|
|
17
19
|
* Loan assets to borrow on the target. Assets mode: the exact borrow (exclusive with
|
|
@@ -27,6 +29,12 @@ export interface BlueRefinanceParams {
|
|
|
27
29
|
maxRepaySharePrice: bigint;
|
|
28
30
|
/** PublicAllocator reallocations into the target market, run before the bundle. Fees add to `tx.value`. */
|
|
29
31
|
targetReallocations?: readonly VaultReallocation[];
|
|
32
|
+
/**
|
|
33
|
+
* Optional signed Morpho authorization. When provided, a `setAuthorizationWithSig` call is
|
|
34
|
+
* prepended to the bundle so GeneralAdapter1 is authorized in-bundle instead of via a
|
|
35
|
+
* standalone `setAuthorization` transaction.
|
|
36
|
+
*/
|
|
37
|
+
authorizationSignature?: AuthorizationRequirementSignature;
|
|
30
38
|
};
|
|
31
39
|
metadata?: Metadata;
|
|
32
40
|
}
|
|
@@ -64,7 +72,7 @@ export interface BlueRefinanceParams {
|
|
|
64
72
|
* then an `erc20Transfer` skims any residual to the user if that repay is skipped.
|
|
65
73
|
* - **Collat-only** (both zero/omitted): only collateral is migrated; borrow/repay legs omitted.
|
|
66
74
|
*
|
|
67
|
-
* Prerequisite: GA1 must be authorized on
|
|
75
|
+
* Prerequisite: GA1 must be authorized on Blue — the entity's `getRequirements()` returns the
|
|
68
76
|
* `setAuthorization` transaction when needed.
|
|
69
77
|
*
|
|
70
78
|
* @param params.source.chainId - The chain both markets live on.
|
|
@@ -77,6 +85,8 @@ export interface BlueRefinanceParams {
|
|
|
77
85
|
* @param params.args.minBorrowSharePrice - Minimum borrow share price (ray) on the target.
|
|
78
86
|
* @param params.args.maxRepaySharePrice - Maximum repay share price (ray) on the source.
|
|
79
87
|
* @param params.args.targetReallocations - PublicAllocator reallocations into the target, run before the supply leg.
|
|
88
|
+
* @param params.args.authorizationSignature - Optional signed Morpho authorization; when present,
|
|
89
|
+
* a `setAuthorizationWithSig` call is prepended to the bundle.
|
|
80
90
|
* @param params.metadata - Optional analytics metadata appended to `tx.data`.
|
|
81
91
|
* @returns A deep-frozen `Transaction<BlueRefinanceAction>`.
|
|
82
92
|
* @remarks `borrowAssets` and `borrowShares` describe different markets (target borrow vs. source
|
|
@@ -114,4 +124,4 @@ export interface BlueRefinanceParams {
|
|
|
114
124
|
* // tx satisfies Readonly<Transaction<BlueRefinanceAction>>
|
|
115
125
|
* ```
|
|
116
126
|
*/
|
|
117
|
-
export declare const blueRefinance: ({ source: { chainId, marketParams: sourceParams }, target: { marketParams: targetParams }, args: { user, collateralAmount, borrowAssets, borrowShares, minBorrowSharePrice, maxRepaySharePrice, targetReallocations, }, metadata, }: BlueRefinanceParams) => Readonly<Transaction<BlueRefinanceAction>>;
|
|
127
|
+
export declare const blueRefinance: ({ source: { chainId, marketParams: sourceParams }, target: { marketParams: targetParams }, args: { user, collateralAmount, borrowAssets, borrowShares, minBorrowSharePrice, maxRepaySharePrice, targetReallocations, authorizationSignature, }, metadata, }: BlueRefinanceParams) => Readonly<Transaction<BlueRefinanceAction>>;
|
|
@@ -7,6 +7,7 @@ const viem_1 = require("viem");
|
|
|
7
7
|
const index_js_1 = require("../../bundler/index.js");
|
|
8
8
|
const index_js_2 = require("../../helpers/index.js");
|
|
9
9
|
const index_js_3 = require("../../types/index.js");
|
|
10
|
+
const getBlueAuthorizationAction_js_1 = require("../signatures/getBlueAuthorizationAction.js");
|
|
10
11
|
const buildReallocationActions_js_1 = require("./buildReallocationActions.js");
|
|
11
12
|
/**
|
|
12
13
|
* Prepares an atomic refinance migrating a Morpho Blue position to another market on the same
|
|
@@ -42,7 +43,7 @@ const buildReallocationActions_js_1 = require("./buildReallocationActions.js");
|
|
|
42
43
|
* then an `erc20Transfer` skims any residual to the user if that repay is skipped.
|
|
43
44
|
* - **Collat-only** (both zero/omitted): only collateral is migrated; borrow/repay legs omitted.
|
|
44
45
|
*
|
|
45
|
-
* Prerequisite: GA1 must be authorized on
|
|
46
|
+
* Prerequisite: GA1 must be authorized on Blue — the entity's `getRequirements()` returns the
|
|
46
47
|
* `setAuthorization` transaction when needed.
|
|
47
48
|
*
|
|
48
49
|
* @param params.source.chainId - The chain both markets live on.
|
|
@@ -55,6 +56,8 @@ const buildReallocationActions_js_1 = require("./buildReallocationActions.js");
|
|
|
55
56
|
* @param params.args.minBorrowSharePrice - Minimum borrow share price (ray) on the target.
|
|
56
57
|
* @param params.args.maxRepaySharePrice - Maximum repay share price (ray) on the source.
|
|
57
58
|
* @param params.args.targetReallocations - PublicAllocator reallocations into the target, run before the supply leg.
|
|
59
|
+
* @param params.args.authorizationSignature - Optional signed Morpho authorization; when present,
|
|
60
|
+
* a `setAuthorizationWithSig` call is prepended to the bundle.
|
|
58
61
|
* @param params.metadata - Optional analytics metadata appended to `tx.data`.
|
|
59
62
|
* @returns A deep-frozen `Transaction<BlueRefinanceAction>`.
|
|
60
63
|
* @remarks `borrowAssets` and `borrowShares` describe different markets (target borrow vs. source
|
|
@@ -92,7 +95,7 @@ const buildReallocationActions_js_1 = require("./buildReallocationActions.js");
|
|
|
92
95
|
* // tx satisfies Readonly<Transaction<BlueRefinanceAction>>
|
|
93
96
|
* ```
|
|
94
97
|
*/
|
|
95
|
-
const blueRefinance = ({ source: { chainId, marketParams: sourceParams }, target: { marketParams: targetParams }, args: { user, collateralAmount, borrowAssets = 0n, borrowShares = 0n, minBorrowSharePrice, maxRepaySharePrice, targetReallocations, }, metadata, }) => {
|
|
98
|
+
const blueRefinance = ({ source: { chainId, marketParams: sourceParams }, target: { marketParams: targetParams }, args: { user, collateralAmount, borrowAssets = 0n, borrowShares = 0n, minBorrowSharePrice, maxRepaySharePrice, targetReallocations, authorizationSignature, }, metadata, }) => {
|
|
96
99
|
if (collateralAmount <= 0n) {
|
|
97
100
|
throw new index_js_3.ZeroCollateralAmountError(sourceParams.id);
|
|
98
101
|
}
|
|
@@ -184,6 +187,9 @@ const blueRefinance = ({ source: { chainId, marketParams: sourceParams }, target
|
|
|
184
187
|
});
|
|
185
188
|
const actions = [];
|
|
186
189
|
let reallocationFee = 0n;
|
|
190
|
+
if (authorizationSignature) {
|
|
191
|
+
actions.push((0, getBlueAuthorizationAction_js_1.getBlueAuthorizationAction)(chainId, authorizationSignature));
|
|
192
|
+
}
|
|
187
193
|
if (targetReallocations && targetReallocations.length > 0) {
|
|
188
194
|
const result = (0, buildReallocationActions_js_1.buildReallocationActions)(targetReallocations, targetParams);
|
|
189
195
|
actions.push(...result.actions);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type MarketParams } from "@morpho-org/blue-sdk";
|
|
2
2
|
import { type Address } from "viem";
|
|
3
|
-
import type { BlueRepayAction, Metadata,
|
|
3
|
+
import type { BlueRepayAction, Metadata, PermitRequirementSignature, Transaction } from "../../types/index.js";
|
|
4
4
|
/** Parameters for {@link blueRepay}. */
|
|
5
5
|
export interface BlueRepayParams {
|
|
6
6
|
market: {
|
|
@@ -24,7 +24,8 @@ export interface BlueRepayParams {
|
|
|
24
24
|
receiver: Address;
|
|
25
25
|
/** Maximum repay share price (in ray). Protects against share price manipulation. */
|
|
26
26
|
maxSharePrice: bigint;
|
|
27
|
-
|
|
27
|
+
/** Optional pre-signed permit/permit2 approval for the loan-token transfer. */
|
|
28
|
+
requirementSignature?: PermitRequirementSignature;
|
|
28
29
|
};
|
|
29
30
|
metadata?: Metadata;
|
|
30
31
|
}
|
|
@@ -64,11 +65,11 @@ export interface BlueRepayParams {
|
|
|
64
65
|
* @throws {MutuallyExclusiveRepayAmountsError} when both `assets` and `shares` are non-zero.
|
|
65
66
|
* @throws {NonPositiveTransferAmountError} when `transferAmount <= 0n`.
|
|
66
67
|
* @throws {TransferAmountNotEqualToAssetsError} when in assets mode and `transferAmount !== assets`.
|
|
67
|
-
* @throws {DepositAssetMismatchError} from `
|
|
68
|
+
* @throws {DepositAssetMismatchError} from `getTokenRequirementActions` when `requirementSignature`
|
|
68
69
|
* is provided and the signed asset differs from `marketParams.loanToken`.
|
|
69
|
-
* @throws {DepositAmountMismatchError} from `
|
|
70
|
+
* @throws {DepositAmountMismatchError} from `getTokenRequirementActions` when `requirementSignature`
|
|
70
71
|
* is provided and the signed amount differs from `args.transferAmount`.
|
|
71
|
-
* @throws {Permit2ExpirationMissingError} from `
|
|
72
|
+
* @throws {Permit2ExpirationMissingError} from `getTokenRequirementActions` when a Permit2 requirement
|
|
72
73
|
* signature is missing its expiration.
|
|
73
74
|
* @example
|
|
74
75
|
* ```ts
|
|
@@ -6,7 +6,7 @@ const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
|
6
6
|
const viem_1 = require("viem");
|
|
7
7
|
const index_js_1 = require("../../bundler/index.js");
|
|
8
8
|
const index_js_2 = require("../../helpers/index.js");
|
|
9
|
-
const
|
|
9
|
+
const getTokenRequirementActions_js_1 = require("../signatures/getTokenRequirementActions.js");
|
|
10
10
|
/**
|
|
11
11
|
* Prepares a repay transaction for a Morpho Blue market.
|
|
12
12
|
*
|
|
@@ -43,11 +43,11 @@ const getRequirementsAction_js_1 = require("../requirements/getRequirementsActio
|
|
|
43
43
|
* @throws {MutuallyExclusiveRepayAmountsError} when both `assets` and `shares` are non-zero.
|
|
44
44
|
* @throws {NonPositiveTransferAmountError} when `transferAmount <= 0n`.
|
|
45
45
|
* @throws {TransferAmountNotEqualToAssetsError} when in assets mode and `transferAmount !== assets`.
|
|
46
|
-
* @throws {DepositAssetMismatchError} from `
|
|
46
|
+
* @throws {DepositAssetMismatchError} from `getTokenRequirementActions` when `requirementSignature`
|
|
47
47
|
* is provided and the signed asset differs from `marketParams.loanToken`.
|
|
48
|
-
* @throws {DepositAmountMismatchError} from `
|
|
48
|
+
* @throws {DepositAmountMismatchError} from `getTokenRequirementActions` when `requirementSignature`
|
|
49
49
|
* is provided and the signed amount differs from `args.transferAmount`.
|
|
50
|
-
* @throws {Permit2ExpirationMissingError} from `
|
|
50
|
+
* @throws {Permit2ExpirationMissingError} from `getTokenRequirementActions` when a Permit2 requirement
|
|
51
51
|
* signature is missing its expiration.
|
|
52
52
|
* @example
|
|
53
53
|
* ```ts
|
|
@@ -77,20 +77,12 @@ const blueRepay = ({ market: { chainId, marketParams }, args: { assets, shares,
|
|
|
77
77
|
});
|
|
78
78
|
const { bundler3: { generalAdapter1 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
|
|
79
79
|
const actions = [];
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}));
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
actions.push({
|
|
90
|
-
type: "erc20TransferFrom",
|
|
91
|
-
args: [marketParams.loanToken, transferAmount, generalAdapter1, false],
|
|
92
|
-
});
|
|
93
|
-
}
|
|
80
|
+
actions.push(...(0, getTokenRequirementActions_js_1.getTokenRequirementActions)({
|
|
81
|
+
asset: marketParams.loanToken,
|
|
82
|
+
amount: transferAmount,
|
|
83
|
+
recipient: generalAdapter1,
|
|
84
|
+
requirementSignature,
|
|
85
|
+
}));
|
|
94
86
|
actions.push({
|
|
95
87
|
type: "morphoRepay",
|
|
96
88
|
args: [marketParams, assets, shares, maxSharePrice, onBehalf, [], false],
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type MarketParams } from "@morpho-org/blue-sdk";
|
|
2
2
|
import { type Address } from "viem";
|
|
3
|
-
import { type BlueRepayWithdrawCollateralAction, type Metadata, type
|
|
3
|
+
import { type AuthorizationRequirementSignature, type BlueRepayWithdrawCollateralAction, type Metadata, type PermitRequirementSignature, type Transaction } from "../../types/index.js";
|
|
4
4
|
/** Parameters for {@link blueRepayWithdrawCollateral}. */
|
|
5
5
|
export interface BlueRepayWithdrawCollateralParams {
|
|
6
6
|
market: {
|
|
@@ -27,7 +27,14 @@ export interface BlueRepayWithdrawCollateralParams {
|
|
|
27
27
|
receiver: Address;
|
|
28
28
|
/** Maximum repay share price (in ray). Protects against share price manipulation. */
|
|
29
29
|
maxSharePrice: bigint;
|
|
30
|
-
|
|
30
|
+
/** Optional pre-signed permit/permit2 approval for the loan-token transfer. */
|
|
31
|
+
requirementSignature?: PermitRequirementSignature;
|
|
32
|
+
/**
|
|
33
|
+
* Optional signed Morpho authorization. When provided, a `setAuthorizationWithSig` call is
|
|
34
|
+
* prepended to the bundle so GeneralAdapter1 is authorized in-bundle instead of via a
|
|
35
|
+
* standalone `setAuthorization` transaction.
|
|
36
|
+
*/
|
|
37
|
+
authorizationSignature?: AuthorizationRequirementSignature;
|
|
31
38
|
};
|
|
32
39
|
metadata?: Metadata;
|
|
33
40
|
}
|
|
@@ -67,6 +74,8 @@ export interface BlueRepayWithdrawCollateralParams {
|
|
|
67
74
|
* protection.
|
|
68
75
|
* @param params.args.requirementSignature - Optional pre-signed permit/permit2 approval for the
|
|
69
76
|
* loan-token transfer.
|
|
77
|
+
* @param params.args.authorizationSignature - Optional signed Morpho authorization; when present,
|
|
78
|
+
* a `setAuthorizationWithSig` call is prepended to the bundle.
|
|
70
79
|
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
71
80
|
* @returns A deep-frozen `Transaction<BlueRepayWithdrawCollateralAction>` with `to`,
|
|
72
81
|
* `value`, `data`, and the typed `action` discriminator the simulation layer consumes.
|
|
@@ -77,11 +86,11 @@ export interface BlueRepayWithdrawCollateralParams {
|
|
|
77
86
|
* @throws {NonPositiveTransferAmountError} when `transferAmount <= 0n`.
|
|
78
87
|
* @throws {TransferAmountNotEqualToAssetsError} when in assets mode and `transferAmount !== assets`.
|
|
79
88
|
* @throws {NonPositiveWithdrawCollateralAmountError} when `withdrawAmount <= 0n`.
|
|
80
|
-
* @throws {DepositAssetMismatchError} from `
|
|
89
|
+
* @throws {DepositAssetMismatchError} from `getTokenRequirementActions` when `requirementSignature`
|
|
81
90
|
* is provided and the signed asset differs from `marketParams.loanToken`.
|
|
82
|
-
* @throws {DepositAmountMismatchError} from `
|
|
91
|
+
* @throws {DepositAmountMismatchError} from `getTokenRequirementActions` when `requirementSignature`
|
|
83
92
|
* is provided and the signed amount differs from `args.transferAmount`.
|
|
84
|
-
* @throws {Permit2ExpirationMissingError} from `
|
|
93
|
+
* @throws {Permit2ExpirationMissingError} from `getTokenRequirementActions` when a Permit2 requirement
|
|
85
94
|
* signature is missing its expiration.
|
|
86
95
|
* @example
|
|
87
96
|
* ```ts
|
|
@@ -102,4 +111,4 @@ export interface BlueRepayWithdrawCollateralParams {
|
|
|
102
111
|
* // tx satisfies Readonly<Transaction<BlueRepayWithdrawCollateralAction>>
|
|
103
112
|
* ```
|
|
104
113
|
*/
|
|
105
|
-
export declare const blueRepayWithdrawCollateral: ({ market: { chainId, marketParams }, args: { assets, shares, transferAmount, withdrawAmount, onBehalf, receiver, maxSharePrice, requirementSignature, }, metadata, }: BlueRepayWithdrawCollateralParams) => Readonly<Transaction<BlueRepayWithdrawCollateralAction>>;
|
|
114
|
+
export declare const blueRepayWithdrawCollateral: ({ market: { chainId, marketParams }, args: { assets, shares, transferAmount, withdrawAmount, onBehalf, receiver, maxSharePrice, requirementSignature, authorizationSignature, }, metadata, }: BlueRepayWithdrawCollateralParams) => Readonly<Transaction<BlueRepayWithdrawCollateralAction>>;
|
|
@@ -7,7 +7,8 @@ const viem_1 = require("viem");
|
|
|
7
7
|
const index_js_1 = require("../../bundler/index.js");
|
|
8
8
|
const index_js_2 = require("../../helpers/index.js");
|
|
9
9
|
const index_js_3 = require("../../types/index.js");
|
|
10
|
-
const
|
|
10
|
+
const getBlueAuthorizationAction_js_1 = require("../signatures/getBlueAuthorizationAction.js");
|
|
11
|
+
const getTokenRequirementActions_js_1 = require("../signatures/getTokenRequirementActions.js");
|
|
11
12
|
/**
|
|
12
13
|
* Prepares an atomic repay-and-withdraw-collateral transaction for a Morpho Blue market.
|
|
13
14
|
*
|
|
@@ -44,6 +45,8 @@ const getRequirementsAction_js_1 = require("../requirements/getRequirementsActio
|
|
|
44
45
|
* protection.
|
|
45
46
|
* @param params.args.requirementSignature - Optional pre-signed permit/permit2 approval for the
|
|
46
47
|
* loan-token transfer.
|
|
48
|
+
* @param params.args.authorizationSignature - Optional signed Morpho authorization; when present,
|
|
49
|
+
* a `setAuthorizationWithSig` call is prepended to the bundle.
|
|
47
50
|
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
48
51
|
* @returns A deep-frozen `Transaction<BlueRepayWithdrawCollateralAction>` with `to`,
|
|
49
52
|
* `value`, `data`, and the typed `action` discriminator the simulation layer consumes.
|
|
@@ -54,11 +57,11 @@ const getRequirementsAction_js_1 = require("../requirements/getRequirementsActio
|
|
|
54
57
|
* @throws {NonPositiveTransferAmountError} when `transferAmount <= 0n`.
|
|
55
58
|
* @throws {TransferAmountNotEqualToAssetsError} when in assets mode and `transferAmount !== assets`.
|
|
56
59
|
* @throws {NonPositiveWithdrawCollateralAmountError} when `withdrawAmount <= 0n`.
|
|
57
|
-
* @throws {DepositAssetMismatchError} from `
|
|
60
|
+
* @throws {DepositAssetMismatchError} from `getTokenRequirementActions` when `requirementSignature`
|
|
58
61
|
* is provided and the signed asset differs from `marketParams.loanToken`.
|
|
59
|
-
* @throws {DepositAmountMismatchError} from `
|
|
62
|
+
* @throws {DepositAmountMismatchError} from `getTokenRequirementActions` when `requirementSignature`
|
|
60
63
|
* is provided and the signed amount differs from `args.transferAmount`.
|
|
61
|
-
* @throws {Permit2ExpirationMissingError} from `
|
|
64
|
+
* @throws {Permit2ExpirationMissingError} from `getTokenRequirementActions` when a Permit2 requirement
|
|
62
65
|
* signature is missing its expiration.
|
|
63
66
|
* @example
|
|
64
67
|
* ```ts
|
|
@@ -79,7 +82,7 @@ const getRequirementsAction_js_1 = require("../requirements/getRequirementsActio
|
|
|
79
82
|
* // tx satisfies Readonly<Transaction<BlueRepayWithdrawCollateralAction>>
|
|
80
83
|
* ```
|
|
81
84
|
*/
|
|
82
|
-
const blueRepayWithdrawCollateral = ({ market: { chainId, marketParams }, args: { assets, shares, transferAmount, withdrawAmount, onBehalf, receiver, maxSharePrice, requirementSignature, }, metadata, }) => {
|
|
85
|
+
const blueRepayWithdrawCollateral = ({ market: { chainId, marketParams }, args: { assets, shares, transferAmount, withdrawAmount, onBehalf, receiver, maxSharePrice, requirementSignature, authorizationSignature, }, metadata, }) => {
|
|
83
86
|
(0, index_js_2.validateRepayParams)({
|
|
84
87
|
assets,
|
|
85
88
|
shares,
|
|
@@ -92,20 +95,15 @@ const blueRepayWithdrawCollateral = ({ market: { chainId, marketParams }, args:
|
|
|
92
95
|
}
|
|
93
96
|
const { bundler3: { generalAdapter1 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
|
|
94
97
|
const actions = [];
|
|
95
|
-
if (
|
|
96
|
-
actions.push(
|
|
97
|
-
asset: marketParams.loanToken,
|
|
98
|
-
amount: transferAmount,
|
|
99
|
-
recipient: generalAdapter1,
|
|
100
|
-
requirementSignature,
|
|
101
|
-
}));
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
actions.push({
|
|
105
|
-
type: "erc20TransferFrom",
|
|
106
|
-
args: [marketParams.loanToken, transferAmount, generalAdapter1, false],
|
|
107
|
-
});
|
|
98
|
+
if (authorizationSignature) {
|
|
99
|
+
actions.push((0, getBlueAuthorizationAction_js_1.getBlueAuthorizationAction)(chainId, authorizationSignature));
|
|
108
100
|
}
|
|
101
|
+
actions.push(...(0, getTokenRequirementActions_js_1.getTokenRequirementActions)({
|
|
102
|
+
asset: marketParams.loanToken,
|
|
103
|
+
amount: transferAmount,
|
|
104
|
+
recipient: generalAdapter1,
|
|
105
|
+
requirementSignature,
|
|
106
|
+
}));
|
|
109
107
|
// REPAY FIRST — reduces debt before withdrawing collateral
|
|
110
108
|
actions.push({
|
|
111
109
|
type: "morphoRepay",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type MarketParams } from "@morpho-org/blue-sdk";
|
|
2
2
|
import type { Address } from "viem";
|
|
3
|
-
import { type BlueSupplyAction, type DepositAmountArgs, type Metadata, type
|
|
3
|
+
import { type BlueSupplyAction, type DepositAmountArgs, type Metadata, type PermitRequirementSignature, type Transaction } from "../../types/index.js";
|
|
4
4
|
/** Parameters for {@link blueSupply}. */
|
|
5
5
|
export interface BlueSupplyParams {
|
|
6
6
|
market: {
|
|
@@ -8,10 +8,12 @@ export interface BlueSupplyParams {
|
|
|
8
8
|
readonly marketParams: MarketParams;
|
|
9
9
|
};
|
|
10
10
|
args: DepositAmountArgs & {
|
|
11
|
+
/** Address whose Morpho supply position is credited. */
|
|
11
12
|
onBehalf: Address;
|
|
12
13
|
/** Maximum supply share price (in ray). Slippage protection against inflation attacks. */
|
|
13
14
|
maxSharePrice: bigint;
|
|
14
|
-
|
|
15
|
+
/** Optional pre-signed permit/permit2 approval for the loan-token transfer. */
|
|
16
|
+
requirementSignature?: PermitRequirementSignature;
|
|
15
17
|
};
|
|
16
18
|
metadata?: Metadata;
|
|
17
19
|
}
|
|
@@ -34,9 +36,7 @@ export interface BlueSupplyParams {
|
|
|
34
36
|
* protection.
|
|
35
37
|
* @param params.args.nativeAmount - Optional amount of native token to wrap into wNative for the
|
|
36
38
|
* supply. Requires the loan token to be the chain's wNative.
|
|
37
|
-
* @param params.args.requirementSignature - Optional pre-signed permit/permit2 approval.
|
|
38
|
-
* absent, the bundle uses a plain `erc20TransferFrom` and assumes the user has already
|
|
39
|
-
* approved `GeneralAdapter1`.
|
|
39
|
+
* @param params.args.requirementSignature - Optional pre-signed permit/permit2 approval.
|
|
40
40
|
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
41
41
|
* @returns A deep-frozen `Transaction<BlueSupplyAction>` with `to`, `value`, `data`, and the
|
|
42
42
|
* typed `action` discriminator the simulation layer consumes.
|
|
@@ -47,9 +47,9 @@ export interface BlueSupplyParams {
|
|
|
47
47
|
* @throws {ChainWNativeMissingError} when `nativeAmount > 0n` but the chain has no configured wNative.
|
|
48
48
|
* @throws {NativeAmountOnNonWNativeAssetError} when `nativeAmount > 0n` but the loan token is not
|
|
49
49
|
* the chain's wNative.
|
|
50
|
-
* @throws {DepositAssetMismatchError} from `
|
|
50
|
+
* @throws {DepositAssetMismatchError} from `getTokenRequirementActions` when `requirementSignature`
|
|
51
51
|
* is provided and the signed asset differs from `marketParams.loanToken`.
|
|
52
|
-
* @throws {DepositAmountMismatchError} from `
|
|
52
|
+
* @throws {DepositAmountMismatchError} from `getTokenRequirementActions` when `requirementSignature`
|
|
53
53
|
* is provided and the signed amount differs from `args.amount`.
|
|
54
54
|
* @example
|
|
55
55
|
* ```ts
|
|
@@ -6,7 +6,7 @@ const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
|
6
6
|
const index_js_1 = require("../../bundler/index.js");
|
|
7
7
|
const index_js_2 = require("../../helpers/index.js");
|
|
8
8
|
const index_js_3 = require("../../types/index.js");
|
|
9
|
-
const
|
|
9
|
+
const getTokenRequirementActions_js_1 = require("../signatures/getTokenRequirementActions.js");
|
|
10
10
|
/**
|
|
11
11
|
* Prepares a loan-asset supply transaction for a Morpho Blue market.
|
|
12
12
|
*
|
|
@@ -26,9 +26,7 @@ const getRequirementsAction_js_1 = require("../requirements/getRequirementsActio
|
|
|
26
26
|
* protection.
|
|
27
27
|
* @param params.args.nativeAmount - Optional amount of native token to wrap into wNative for the
|
|
28
28
|
* supply. Requires the loan token to be the chain's wNative.
|
|
29
|
-
* @param params.args.requirementSignature - Optional pre-signed permit/permit2 approval.
|
|
30
|
-
* absent, the bundle uses a plain `erc20TransferFrom` and assumes the user has already
|
|
31
|
-
* approved `GeneralAdapter1`.
|
|
29
|
+
* @param params.args.requirementSignature - Optional pre-signed permit/permit2 approval.
|
|
32
30
|
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
33
31
|
* @returns A deep-frozen `Transaction<BlueSupplyAction>` with `to`, `value`, `data`, and the
|
|
34
32
|
* typed `action` discriminator the simulation layer consumes.
|
|
@@ -39,9 +37,9 @@ const getRequirementsAction_js_1 = require("../requirements/getRequirementsActio
|
|
|
39
37
|
* @throws {ChainWNativeMissingError} when `nativeAmount > 0n` but the chain has no configured wNative.
|
|
40
38
|
* @throws {NativeAmountOnNonWNativeAssetError} when `nativeAmount > 0n` but the loan token is not
|
|
41
39
|
* the chain's wNative.
|
|
42
|
-
* @throws {DepositAssetMismatchError} from `
|
|
40
|
+
* @throws {DepositAssetMismatchError} from `getTokenRequirementActions` when `requirementSignature`
|
|
43
41
|
* is provided and the signed asset differs from `marketParams.loanToken`.
|
|
44
|
-
* @throws {DepositAmountMismatchError} from `
|
|
42
|
+
* @throws {DepositAmountMismatchError} from `getTokenRequirementActions` when `requirementSignature`
|
|
45
43
|
* is provided and the signed amount differs from `args.amount`.
|
|
46
44
|
* @example
|
|
47
45
|
* ```ts
|
|
@@ -85,20 +83,12 @@ const blueSupply = ({ market: { chainId, marketParams }, args: { amount = 0n, on
|
|
|
85
83
|
});
|
|
86
84
|
}
|
|
87
85
|
if (amount > 0n) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}));
|
|
95
|
-
}
|
|
96
|
-
else {
|
|
97
|
-
actions.push({
|
|
98
|
-
type: "erc20TransferFrom",
|
|
99
|
-
args: [marketParams.loanToken, amount, generalAdapter1, false],
|
|
100
|
-
});
|
|
101
|
-
}
|
|
86
|
+
actions.push(...(0, getTokenRequirementActions_js_1.getTokenRequirementActions)({
|
|
87
|
+
asset: marketParams.loanToken,
|
|
88
|
+
amount,
|
|
89
|
+
recipient: generalAdapter1,
|
|
90
|
+
requirementSignature,
|
|
91
|
+
}));
|
|
102
92
|
}
|
|
103
93
|
actions.push({
|
|
104
94
|
type: "morphoSupply",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type MarketParams } from "@morpho-org/blue-sdk";
|
|
2
2
|
import type { Address } from "viem";
|
|
3
|
-
import { type BlueSupplyCollateralAction, type DepositAmountArgs, type Metadata, type
|
|
3
|
+
import { type BlueSupplyCollateralAction, type DepositAmountArgs, type Metadata, type PermitRequirementSignature, type Transaction } from "../../types/index.js";
|
|
4
4
|
/** Parameters for {@link blueSupplyCollateral}. */
|
|
5
5
|
export interface BlueSupplyCollateralParams {
|
|
6
6
|
market: {
|
|
@@ -8,8 +8,10 @@ export interface BlueSupplyCollateralParams {
|
|
|
8
8
|
readonly marketParams: MarketParams;
|
|
9
9
|
};
|
|
10
10
|
args: DepositAmountArgs & {
|
|
11
|
+
/** Address whose Morpho collateral position is credited. */
|
|
11
12
|
onBehalf: Address;
|
|
12
|
-
|
|
13
|
+
/** Optional pre-signed permit/permit2 approval for the collateral transfer. */
|
|
14
|
+
requirementSignature?: PermitRequirementSignature;
|
|
13
15
|
};
|
|
14
16
|
metadata?: Metadata;
|
|
15
17
|
}
|
|
@@ -27,9 +29,7 @@ export interface BlueSupplyCollateralParams {
|
|
|
27
29
|
* @param params.args.amount - Amount of ERC-20 collateral to supply. At least one of `amount` or
|
|
28
30
|
* `nativeAmount` must be positive. Defaults to `0n`.
|
|
29
31
|
* @param params.args.onBehalf - Address whose Morpho position is credited with the collateral.
|
|
30
|
-
* @param params.args.requirementSignature - Optional pre-signed permit/permit2 approval.
|
|
31
|
-
* absent, the bundle uses a plain `erc20TransferFrom` and assumes the user has already
|
|
32
|
-
* approved `GeneralAdapter1`.
|
|
32
|
+
* @param params.args.requirementSignature - Optional pre-signed permit/permit2 approval.
|
|
33
33
|
* @param params.args.nativeAmount - Optional amount of native token to wrap into wNative for the
|
|
34
34
|
* supply. Requires the collateral token to be the chain's wNative.
|
|
35
35
|
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
@@ -41,11 +41,11 @@ export interface BlueSupplyCollateralParams {
|
|
|
41
41
|
* @throws {ChainWNativeMissingError} when `nativeAmount > 0n` but the chain has no configured wNative.
|
|
42
42
|
* @throws {NativeAmountOnNonWNativeAssetError} when `nativeAmount > 0n` but the collateral
|
|
43
43
|
* token is not the chain's wNative.
|
|
44
|
-
* @throws {DepositAssetMismatchError} from `
|
|
44
|
+
* @throws {DepositAssetMismatchError} from `getTokenRequirementActions` when `requirementSignature`
|
|
45
45
|
* is provided and the signed asset differs from `marketParams.collateralToken`.
|
|
46
|
-
* @throws {DepositAmountMismatchError} from `
|
|
46
|
+
* @throws {DepositAmountMismatchError} from `getTokenRequirementActions` when `requirementSignature`
|
|
47
47
|
* is provided and the signed amount differs from `args.amount`.
|
|
48
|
-
* @throws {Permit2ExpirationMissingError} from `
|
|
48
|
+
* @throws {Permit2ExpirationMissingError} from `getTokenRequirementActions` when a Permit2 requirement
|
|
49
49
|
* signature is missing its expiration.
|
|
50
50
|
* @example
|
|
51
51
|
* ```ts
|