@morpho-org/morpho-sdk 8.3.0 → 9.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/MIGRATION-v8-to-v9.md +54 -0
- package/README.md +13 -7
- package/lib/cjs/actions/bundles/common.d.ts +4 -7
- package/lib/cjs/actions/bundles/common.js +8 -14
- package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.d.ts +1 -5
- package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.js +1 -8
- package/lib/cjs/actions/midnight/authorization.d.ts +3 -1
- package/lib/cjs/actions/midnight/authorization.js +11 -1
- package/lib/cjs/actions/midnight/cancelAndMake.d.ts +2 -0
- package/lib/cjs/actions/midnight/cancelAndMake.js +10 -2
- package/lib/cjs/actions/midnight/redeem.d.ts +3 -1
- package/lib/cjs/actions/midnight/redeem.js +9 -3
- package/lib/cjs/actions/midnight/repayWithdrawCollateral.d.ts +1 -0
- package/lib/cjs/actions/midnight/repayWithdrawCollateral.js +7 -3
- package/lib/cjs/actions/midnight/supplyCollateral.d.ts +4 -1
- package/lib/cjs/actions/midnight/supplyCollateral.js +10 -3
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.d.ts +3 -1
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +9 -3
- package/lib/cjs/actions/midnight/takeBorrow.d.ts +3 -1
- package/lib/cjs/actions/midnight/takeBorrow.js +9 -3
- package/lib/cjs/actions/midnight/takeLend.d.ts +1 -0
- package/lib/cjs/actions/midnight/takeLend.js +7 -2
- package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.d.ts +1 -0
- package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.js +8 -2
- package/lib/cjs/actions/midnight/takeWithdraw.d.ts +3 -1
- package/lib/cjs/actions/midnight/takeWithdraw.js +10 -3
- package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +1 -5
- package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +5 -7
- package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +7 -11
- package/lib/cjs/actions/requirements/getRequirementsApproval.js +8 -15
- package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.d.ts +5 -10
- package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.js +11 -8
- package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.d.ts +2 -0
- package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +5 -0
- package/lib/cjs/actions/vaultV1/inKindRedeem.d.ts +1 -1
- package/lib/cjs/actions/vaultV1/inKindRedeem.js +1 -1
- package/lib/cjs/actions/vaultV1/withdraw.d.ts +4 -4
- package/lib/cjs/actions/vaultV1/withdraw.js +4 -4
- package/lib/cjs/actions/vaultV2/forceWithdraw.d.ts +1 -1
- package/lib/cjs/actions/vaultV2/forceWithdraw.js +1 -1
- package/lib/cjs/actions/vaultV2/inKindRedeem.d.ts +1 -1
- package/lib/cjs/actions/vaultV2/inKindRedeem.js +1 -1
- package/lib/cjs/actions/vaultV2/withdraw.d.ts +4 -4
- package/lib/cjs/actions/vaultV2/withdraw.js +4 -4
- package/lib/cjs/entities/blue/blue.d.ts +2 -12
- package/lib/cjs/entities/blue/blue.js +0 -4
- package/lib/cjs/entities/midnight/midnight.d.ts +56 -17
- package/lib/cjs/entities/midnight/midnight.js +131 -52
- package/lib/cjs/entities/midnight/types.d.ts +2 -9
- package/lib/cjs/entities/requirements/getBundlesTokenRequirements.d.ts +0 -4
- package/lib/cjs/entities/requirements/getBundlesTokenRequirements.js +0 -7
- package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.d.ts +5 -14
- package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.js +8 -20
- package/lib/cjs/entities/vaultV1/vaultV1.d.ts +40 -37
- package/lib/cjs/entities/vaultV1/vaultV1.js +5 -34
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +36 -34
- package/lib/cjs/entities/vaultV2/vaultV2.js +8 -34
- package/lib/cjs/helpers/encodeMidnightCalldata.d.ts +48 -0
- package/lib/cjs/helpers/encodeMidnightCalldata.js +74 -0
- package/lib/cjs/helpers/slippage.d.ts +9 -25
- package/lib/cjs/helpers/slippage.js +10 -27
- package/lib/cjs/helpers/validate.d.ts +1 -0
- package/lib/cjs/helpers/validate.js +5 -0
- package/lib/cjs/helpers/validateMidnightAccount.d.ts +34 -0
- package/lib/cjs/helpers/validateMidnightAccount.js +47 -0
- package/lib/cjs/helpers/validateMidnightAuthorizationTarget.d.ts +1 -0
- package/lib/cjs/helpers/validateMidnightAuthorizationTarget.js +4 -0
- package/lib/cjs/helpers/validateMidnightMarket.d.ts +2 -0
- package/lib/cjs/helpers/validateMidnightMarket.js +5 -0
- package/lib/cjs/helpers/validateMidnightPublication.d.ts +11 -0
- package/lib/cjs/helpers/validateMidnightPublication.js +12 -1
- package/lib/cjs/helpers/validateMidnightReceiver.d.ts +1 -0
- package/lib/cjs/helpers/validateMidnightReceiver.js +8 -0
- package/lib/cjs/helpers/validateTakeableOffers.d.ts +2 -1
- package/lib/cjs/helpers/validateTakeableOffers.js +4 -3
- package/lib/cjs/types/action.d.ts +3 -1
- package/lib/cjs/types/error.d.ts +56 -5
- package/lib/cjs/types/error.js +139 -10
- package/lib/esm/actions/bundles/common.d.ts +4 -7
- package/lib/esm/actions/bundles/common.js +8 -14
- package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.d.ts +1 -5
- package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.js +2 -9
- package/lib/esm/actions/midnight/authorization.d.ts +3 -1
- package/lib/esm/actions/midnight/authorization.js +12 -2
- package/lib/esm/actions/midnight/cancelAndMake.d.ts +2 -0
- package/lib/esm/actions/midnight/cancelAndMake.js +11 -3
- package/lib/esm/actions/midnight/redeem.d.ts +3 -1
- package/lib/esm/actions/midnight/redeem.js +10 -4
- package/lib/esm/actions/midnight/repayWithdrawCollateral.d.ts +1 -0
- package/lib/esm/actions/midnight/repayWithdrawCollateral.js +8 -4
- package/lib/esm/actions/midnight/supplyCollateral.d.ts +4 -1
- package/lib/esm/actions/midnight/supplyCollateral.js +11 -4
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.d.ts +3 -1
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +10 -4
- package/lib/esm/actions/midnight/takeBorrow.d.ts +3 -1
- package/lib/esm/actions/midnight/takeBorrow.js +10 -4
- package/lib/esm/actions/midnight/takeLend.d.ts +1 -0
- package/lib/esm/actions/midnight/takeLend.js +8 -3
- package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.d.ts +1 -0
- package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +9 -3
- package/lib/esm/actions/midnight/takeWithdraw.d.ts +3 -1
- package/lib/esm/actions/midnight/takeWithdraw.js +11 -4
- package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +1 -5
- package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +6 -8
- package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +7 -11
- package/lib/esm/actions/requirements/getRequirementsApproval.js +9 -16
- package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.d.ts +5 -10
- package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.js +12 -9
- package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.d.ts +2 -0
- package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +5 -0
- package/lib/esm/actions/vaultV1/inKindRedeem.d.ts +1 -1
- package/lib/esm/actions/vaultV1/inKindRedeem.js +1 -1
- package/lib/esm/actions/vaultV1/withdraw.d.ts +4 -4
- package/lib/esm/actions/vaultV1/withdraw.js +4 -4
- package/lib/esm/actions/vaultV2/forceWithdraw.d.ts +1 -1
- package/lib/esm/actions/vaultV2/forceWithdraw.js +1 -1
- package/lib/esm/actions/vaultV2/inKindRedeem.d.ts +1 -1
- package/lib/esm/actions/vaultV2/inKindRedeem.js +1 -1
- package/lib/esm/actions/vaultV2/withdraw.d.ts +4 -4
- package/lib/esm/actions/vaultV2/withdraw.js +4 -4
- package/lib/esm/entities/blue/blue.d.ts +2 -12
- package/lib/esm/entities/blue/blue.js +0 -4
- package/lib/esm/entities/midnight/midnight.d.ts +56 -17
- package/lib/esm/entities/midnight/midnight.js +132 -53
- package/lib/esm/entities/midnight/types.d.ts +2 -9
- package/lib/esm/entities/requirements/getBundlesTokenRequirements.d.ts +0 -4
- package/lib/esm/entities/requirements/getBundlesTokenRequirements.js +1 -8
- package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.d.ts +5 -14
- package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.js +9 -21
- package/lib/esm/entities/vaultV1/vaultV1.d.ts +40 -37
- package/lib/esm/entities/vaultV1/vaultV1.js +6 -35
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +36 -34
- package/lib/esm/entities/vaultV2/vaultV2.js +8 -34
- package/lib/esm/helpers/encodeMidnightCalldata.d.ts +48 -0
- package/lib/esm/helpers/encodeMidnightCalldata.js +69 -0
- package/lib/esm/helpers/slippage.d.ts +9 -25
- package/lib/esm/helpers/slippage.js +9 -25
- package/lib/esm/helpers/validate.d.ts +1 -0
- package/lib/esm/helpers/validate.js +5 -0
- package/lib/esm/helpers/validateMidnightAccount.d.ts +34 -0
- package/lib/esm/helpers/validateMidnightAccount.js +43 -0
- package/lib/esm/helpers/validateMidnightAuthorizationTarget.d.ts +1 -0
- package/lib/esm/helpers/validateMidnightAuthorizationTarget.js +4 -0
- package/lib/esm/helpers/validateMidnightMarket.d.ts +2 -0
- package/lib/esm/helpers/validateMidnightMarket.js +5 -0
- package/lib/esm/helpers/validateMidnightPublication.d.ts +11 -0
- package/lib/esm/helpers/validateMidnightPublication.js +10 -0
- package/lib/esm/helpers/validateMidnightReceiver.d.ts +1 -0
- package/lib/esm/helpers/validateMidnightReceiver.js +8 -0
- package/lib/esm/helpers/validateTakeableOffers.d.ts +2 -1
- package/lib/esm/helpers/validateTakeableOffers.js +4 -3
- package/lib/esm/types/action.d.ts +3 -1
- package/lib/esm/types/error.d.ts +56 -5
- package/lib/esm/types/error.js +134 -6
- package/package.json +4 -3
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# Migrating from morpho-sdk v8 to v9
|
|
2
|
+
|
|
3
|
+
Version 9 removes exact-amount approval controls. Classic ERC-20 approvals and vault-share
|
|
4
|
+
approvals or permits now use `maxUint256` when the existing allowance is below the required amount.
|
|
5
|
+
An allowance at or above the required amount satisfies the requirement; larger leftovers are
|
|
6
|
+
reused. `MAX_TOKEN_APPROVALS`, USDT-style zero-reset behavior, and spender allowlists remain.
|
|
7
|
+
|
|
8
|
+
## Removed and retyped inputs
|
|
9
|
+
|
|
10
|
+
Remove `approvalAmount` from these public inputs:
|
|
11
|
+
|
|
12
|
+
| Before | After |
|
|
13
|
+
| --- | --- |
|
|
14
|
+
| `BlueTokenRequirementsParams.approvalAmount` | Remove the property. |
|
|
15
|
+
| `GetBundlesTokenRequirementsParams.approvalAmount` | Remove the property; approvals no longer default to the pull amount. |
|
|
16
|
+
| `GetMidnightApprovalRequirementsParams.approvalAmount` | Remove the property. |
|
|
17
|
+
| `MidnightRequirementsParams.approvalAmount` | Use the retyped requirements params without the approval amount. |
|
|
18
|
+
| `RequirementOptions.approvalAmount` | Remove the property from WDK requirements options. |
|
|
19
|
+
| `EncodeVaultSharesPermitParams.amount` | Remove the property; vault-share permits authorize `maxUint256`. |
|
|
20
|
+
|
|
21
|
+
JavaScript callers that keep passing `approvalAmount` will not receive a warning: the extra
|
|
22
|
+
property is silently ignored and the SDK may return an unlimited approval when one is needed.
|
|
23
|
+
Remove the option rather than relying on the former exact-amount behavior.
|
|
24
|
+
|
|
25
|
+
`getRequirementsApproval` no longer accepts an `approvalAmount` argument. Call it with the token,
|
|
26
|
+
spender, spend amount, and current allowance; when the allowance is insufficient it returns an
|
|
27
|
+
approval for the maximum amount allowed by the token's cap. The USDT-style zero-reset requirement
|
|
28
|
+
and spender validation are unchanged.
|
|
29
|
+
|
|
30
|
+
`BundlesTokenRequirementsState`'s approval branch no longer includes an `approvalAmount` field.
|
|
31
|
+
Update serialized or constructed state to match the retyped branch.
|
|
32
|
+
|
|
33
|
+
## Removed error and share-allowance ceiling
|
|
34
|
+
|
|
35
|
+
`ApprovalAmountLessThanSpendAmountError` is removed from `morpho-sdk` and is no longer re-exported
|
|
36
|
+
by WDK. Remove catches and imports for this error.
|
|
37
|
+
|
|
38
|
+
Share authorization now requires only the SDK-derived minimum share allowance. A larger existing
|
|
39
|
+
allowance is reused instead of being reset to a ceiling, while an insufficient allowance is raised by an unlimited classic approval or vault-share permit.
|
|
40
|
+
|
|
41
|
+
## Permit and exit behavior
|
|
42
|
+
|
|
43
|
+
ERC-2612 token permits and Permit2 SignatureTransfer remain exact because the deployed bundles
|
|
44
|
+
pass the pull amount to `permit` or derive the signed transfer permission from that same amount.
|
|
45
|
+
Vault-share permits use `maxUint256`; their signature checks still require a signed value at least
|
|
46
|
+
as large as the needed share amount.
|
|
47
|
+
|
|
48
|
+
The former bounded VaultBundlesV1 share allowance capped how many shares an asset-mode exit could
|
|
49
|
+
burn, even though the bundle itself had no share-price or max-shares bound. V9 removes that cap.
|
|
50
|
+
Asset-mode `vaultBundlesV1Withdraw`, the asset-mode V1 `migrateToV2` source leg, and in-kind
|
|
51
|
+
redemption have no on-chain share-price or max-shares bound. With an unlimited share allowance, a
|
|
52
|
+
share-price drop before inclusion can burn more shares than quoted. Vault V2 `forceWithdraw` retains its
|
|
53
|
+
`minSharePriceE27` bound, shares-mode redemption burns its fixed share amount, and deposit or
|
|
54
|
+
migration-destination operations retain `maxSharePrice`.
|
package/README.md
CHANGED
|
@@ -24,6 +24,9 @@ General Vault V1 operations remain supported.
|
|
|
24
24
|
pnpm add @morpho-org/morpho-sdk
|
|
25
25
|
```
|
|
26
26
|
|
|
27
|
+
Upgrading from v8? Read the [v8 → v9 migration guide](./MIGRATION-v8-to-v9.md) for the approval
|
|
28
|
+
API removals and the new unlimited-approval behavior.
|
|
29
|
+
|
|
27
30
|
Upgrading from v6? Read the [v6 → v7 migration guide](./MIGRATION-v6-to-v7.md) before updating
|
|
28
31
|
Midnight maker integrations. Upgrading from v7? Read the
|
|
29
32
|
[v7 → v8 migration guide](./MIGRATION-v7-to-v8.md) before relying on fail-closed token metadata or
|
|
@@ -68,7 +71,7 @@ Robinhood Chain, Arc, and X Layer. Custom deployments can still be configured wi
|
|
|
68
71
|
|
|
69
72
|
Actions that pull tokens or touch a position return `{ buildTx, getRequirements }`. All Blue
|
|
70
73
|
writes use this lazy shape while still encoding one direct BlueBundlesV1 call. Vault deposits,
|
|
71
|
-
`withdraw`, and `redeem` use the same shape for token or
|
|
74
|
+
`withdraw`, and `redeem` use the same shape for token or vault-share authorization to
|
|
72
75
|
VaultBundlesV1. Vault `inKindRedeem` and `forceWithdraw` use it so callers can await
|
|
73
76
|
`getRequirements()` to check share authorization to VaultExitBundlesV1 — and, for `inKindRedeem`,
|
|
74
77
|
live Blue liquidity — before invoking `buildTx()`. Calling `buildTx()` directly skips those
|
|
@@ -85,8 +88,11 @@ BlueBundlesV1 call charges, where derivable; it is omitted in exact-shares mode
|
|
|
85
88
|
where the underlying amount is resolved at execution. On the repay actions it is set
|
|
86
89
|
only for an exact-assets repay (`repayAssets > 0n`), so it is also omitted when
|
|
87
90
|
`blueRepayWithdrawCollateral` has no repay leg).
|
|
88
|
-
`@morpho-org/evm-simulation`'s `toSimulationLimits` consumes this metadata
|
|
89
|
-
limits
|
|
91
|
+
`@morpho-org/evm-simulation`'s `toSimulationLimits` consumes this metadata
|
|
92
|
+
for quote-based limits. For operations covered by `OperationInputs`, prefer
|
|
93
|
+
independently chosen `inputs` in `simulate()` limits rather than bounds derived
|
|
94
|
+
from action metadata. Refinance, in-kind redeems, force exits and Midnight
|
|
95
|
+
operations still require quotes.
|
|
90
96
|
|
|
91
97
|
```typescript
|
|
92
98
|
const vaultData = await vault.getData();
|
|
@@ -153,9 +159,9 @@ const requirements = await getRequirements();
|
|
|
153
159
|
const tx = buildTx([permitSignature]);
|
|
154
160
|
```
|
|
155
161
|
|
|
156
|
-
Withdraw is a VaultBundlesV1 call that burns the caller's shares
|
|
157
|
-
|
|
158
|
-
|
|
162
|
+
Withdraw is a VaultBundlesV1 call that burns the caller's shares. Any existing allowance at or
|
|
163
|
+
above the required share amount is reused; otherwise, `getRequirements()` returns an unlimited
|
|
164
|
+
approval or permit:
|
|
159
165
|
|
|
160
166
|
```typescript
|
|
161
167
|
import { morphoViemExtension } from "@morpho-org/morpho-sdk";
|
|
@@ -197,7 +203,7 @@ async function withdrawUsdc(provider: EIP1193Provider, supportSignature = false)
|
|
|
197
203
|
if (receipt.status !== "success") throw new Error("The share approval reverted.");
|
|
198
204
|
}
|
|
199
205
|
}
|
|
200
|
-
// Approval is confirmed, or the
|
|
206
|
+
// Approval is confirmed, or the required allowance was already satisfied.
|
|
201
207
|
return walletClient.sendTransaction({ ...withdrawal.buildTx(), account: userAddress });
|
|
202
208
|
}
|
|
203
209
|
// await withdrawUsdc(provider) returns the withdrawal transaction hash.
|
|
@@ -17,7 +17,7 @@ export interface BundlesTokenPermit {
|
|
|
17
17
|
}
|
|
18
18
|
/** ABI-ready ERC-2612 share permit consumed by vault bundles. */
|
|
19
19
|
export interface BundleSharesPermit {
|
|
20
|
-
/**
|
|
20
|
+
/** Vault-share allowance authorized by the permit. */
|
|
21
21
|
readonly value: bigint;
|
|
22
22
|
/** Vault permit nonce signed by the owner. */
|
|
23
23
|
readonly nonce: bigint;
|
|
@@ -149,7 +149,7 @@ export declare const normalizeBundlesSignature: (serializedSignature: Hex, onInv
|
|
|
149
149
|
* @param params.deadline - Unix timestamp in seconds used by the empty-permit sentinel.
|
|
150
150
|
* @param params.owner - Optional expected signature owner.
|
|
151
151
|
* @param params.spender - Optional expected fixed bundles contract authorized to pull shares.
|
|
152
|
-
* @param params.amount - Optional
|
|
152
|
+
* @param params.amount - Optional minimum share allowance in the vault share token's smallest unit.
|
|
153
153
|
* @param params.requirementSignature - Optional signed ERC-2612 share requirement; omit for the empty-permit sentinel.
|
|
154
154
|
* @returns The signed share permit or the contract's empty-permit sentinel.
|
|
155
155
|
* @throws {NonPositiveInputError} when a bundle or permit deadline is not positive.
|
|
@@ -203,22 +203,19 @@ export declare const selectBundlesTokenRequirementSignature: (signatures: readon
|
|
|
203
203
|
* @internal
|
|
204
204
|
*
|
|
205
205
|
* @param signatures - Signatures passed to the operation's `buildTx` function.
|
|
206
|
-
* @param expected - Immutable spender, amount
|
|
206
|
+
* @param expected - Immutable spender, minimum amount, and deadline required by the operation.
|
|
207
207
|
* @param expected.spender - Fixed bundles contract the permit must authorize.
|
|
208
208
|
* @param expected.amount - Minimum share allowance the permit must cover.
|
|
209
|
-
* @param expected.maxAmount - Optional inclusive share allowance ceiling; defaults to
|
|
210
|
-
* `expected.amount`, which accepts only an exact match.
|
|
211
209
|
* @param expected.deadline - Deadline the permit must carry.
|
|
212
210
|
* @returns The matching ERC-2612 signature, or `undefined` when no signature is supplied.
|
|
213
211
|
* @throws {BundlesPermitMismatchError} when the signature is not ERC-2612, its spender or
|
|
214
212
|
* deadline differ from the operation's, its signed amount differs from its action's amount, or
|
|
215
|
-
* its amount is
|
|
213
|
+
* its amount is below `expected.amount`.
|
|
216
214
|
* The nonce is not checked here: it is onchain state the vault's `permit` verifies at execution.
|
|
217
215
|
*/
|
|
218
216
|
export declare const selectBundlesSharesPermitSignature: (signatures: readonly RequirementSignature[] | undefined, expected: {
|
|
219
217
|
readonly spender: Address;
|
|
220
218
|
readonly amount: bigint;
|
|
221
|
-
readonly maxAmount?: bigint;
|
|
222
219
|
readonly deadline: bigint;
|
|
223
220
|
}) => Erc2612RequirementSignature | undefined;
|
|
224
221
|
/** @internal Returns the exact referral fee deducted from a fixed gross asset amount. */
|
|
@@ -230,7 +230,7 @@ exports.normalizeBundlesSignature = normalizeBundlesSignature;
|
|
|
230
230
|
* @param params.deadline - Unix timestamp in seconds used by the empty-permit sentinel.
|
|
231
231
|
* @param params.owner - Optional expected signature owner.
|
|
232
232
|
* @param params.spender - Optional expected fixed bundles contract authorized to pull shares.
|
|
233
|
-
* @param params.amount - Optional
|
|
233
|
+
* @param params.amount - Optional minimum share allowance in the vault share token's smallest unit.
|
|
234
234
|
* @param params.requirementSignature - Optional signed ERC-2612 share requirement; omit for the empty-permit sentinel.
|
|
235
235
|
* @returns The signed share permit or the contract's empty-permit sentinel.
|
|
236
236
|
* @throws {NonPositiveInputError} when a bundle or permit deadline is not positive.
|
|
@@ -298,11 +298,11 @@ const getBundlesSharesPermit = (params) => {
|
|
|
298
298
|
});
|
|
299
299
|
}
|
|
300
300
|
if (params.amount != null &&
|
|
301
|
-
(requirementSignature.args.amount
|
|
302
|
-
requirementSignature.action.args.amount
|
|
301
|
+
(requirementSignature.args.amount < params.amount ||
|
|
302
|
+
requirementSignature.action.args.amount < params.amount)) {
|
|
303
303
|
throw new index_js_2.BundlesPermitMismatchError({
|
|
304
304
|
field: "amount",
|
|
305
|
-
expected:
|
|
305
|
+
expected: `at least ${params.amount}`,
|
|
306
306
|
actual: String(requirementSignature.args.amount),
|
|
307
307
|
});
|
|
308
308
|
}
|
|
@@ -417,16 +417,14 @@ exports.selectBundlesTokenRequirementSignature = selectBundlesTokenRequirementSi
|
|
|
417
417
|
* @internal
|
|
418
418
|
*
|
|
419
419
|
* @param signatures - Signatures passed to the operation's `buildTx` function.
|
|
420
|
-
* @param expected - Immutable spender, amount
|
|
420
|
+
* @param expected - Immutable spender, minimum amount, and deadline required by the operation.
|
|
421
421
|
* @param expected.spender - Fixed bundles contract the permit must authorize.
|
|
422
422
|
* @param expected.amount - Minimum share allowance the permit must cover.
|
|
423
|
-
* @param expected.maxAmount - Optional inclusive share allowance ceiling; defaults to
|
|
424
|
-
* `expected.amount`, which accepts only an exact match.
|
|
425
423
|
* @param expected.deadline - Deadline the permit must carry.
|
|
426
424
|
* @returns The matching ERC-2612 signature, or `undefined` when no signature is supplied.
|
|
427
425
|
* @throws {BundlesPermitMismatchError} when the signature is not ERC-2612, its spender or
|
|
428
426
|
* deadline differ from the operation's, its signed amount differs from its action's amount, or
|
|
429
|
-
* its amount is
|
|
427
|
+
* its amount is below `expected.amount`.
|
|
430
428
|
* The nonce is not checked here: it is onchain state the vault's `permit` verifies at execution.
|
|
431
429
|
*/
|
|
432
430
|
const selectBundlesSharesPermitSignature = (signatures, expected) => {
|
|
@@ -448,10 +446,6 @@ const selectBundlesSharesPermitSignature = (signatures, expected) => {
|
|
|
448
446
|
actual: action.args.spender,
|
|
449
447
|
});
|
|
450
448
|
}
|
|
451
|
-
const maxAmount = expected.maxAmount ?? expected.amount;
|
|
452
|
-
const expectedAmount = expected.maxAmount == null || expected.maxAmount === expected.amount
|
|
453
|
-
? String(expected.amount)
|
|
454
|
-
: `[${expected.amount}, ${expected.maxAmount}]`;
|
|
455
449
|
if (permit.args.amount !== action.args.amount) {
|
|
456
450
|
throw new index_js_2.BundlesPermitMismatchError({
|
|
457
451
|
field: "amount",
|
|
@@ -459,10 +453,10 @@ const selectBundlesSharesPermitSignature = (signatures, expected) => {
|
|
|
459
453
|
actual: String(permit.args.amount),
|
|
460
454
|
});
|
|
461
455
|
}
|
|
462
|
-
if (permit.args.amount < expected.amount
|
|
456
|
+
if (permit.args.amount < expected.amount) {
|
|
463
457
|
throw new index_js_2.BundlesPermitMismatchError({
|
|
464
458
|
field: "amount",
|
|
465
|
-
expected:
|
|
459
|
+
expected: `at least ${expected.amount}`,
|
|
466
460
|
actual: String(permit.args.amount),
|
|
467
461
|
});
|
|
468
462
|
}
|
|
@@ -5,8 +5,6 @@ export type BundlesTokenRequirementsState = {
|
|
|
5
5
|
readonly type: "approval";
|
|
6
6
|
/** Current allowance of the funding token for `spender`. */
|
|
7
7
|
readonly allowance: bigint;
|
|
8
|
-
/** Allowance to set when the current allowance cannot cover `amount`. */
|
|
9
|
-
readonly approvalAmount: bigint;
|
|
10
8
|
} | {
|
|
11
9
|
readonly type: "permit2SignatureTransfer";
|
|
12
10
|
readonly permit2Allowance: bigint;
|
|
@@ -36,7 +34,6 @@ export type BundlesTokenRequirementsState = {
|
|
|
36
34
|
* @param params.state - Prefetched state for either classic approval or Permit2 SignatureTransfer.
|
|
37
35
|
* @param params.state.type - `approval` for a direct allowance or `permit2SignatureTransfer` for a signed pull.
|
|
38
36
|
* @param params.state.allowance - In the approval branch, current token allowance from `owner` to `spender`.
|
|
39
|
-
* @param params.state.approvalAmount - In the approval branch, allowance to set if needed; must cover `amount`.
|
|
40
37
|
* @param params.state.permit2Allowance - In the SignatureTransfer branch, current token allowance from `owner` to canonical Permit2.
|
|
41
38
|
* @param params.state.permit2Nonce - In the SignatureTransfer branch, caller-selected unused uint256 unordered nonce.
|
|
42
39
|
* @param params.state.nonceBitmap - In the SignatureTransfer branch, owner's Permit2 bitmap word at `permit2Nonce >> 8n`.
|
|
@@ -48,7 +45,6 @@ export type BundlesTokenRequirementsState = {
|
|
|
48
45
|
* @throws {InputExceedsMaxError} when `amount`, the Permit2 nonce, or the SignatureTransfer
|
|
49
46
|
* `deadline` exceeds uint256.
|
|
50
47
|
* @throws {Permit2SignatureTransferNonceAlreadyUsedError} when the selected nonce bit is set.
|
|
51
|
-
* @throws {ApprovalAmountLessThanSpendAmountError} when a classic approval cannot cover the pull.
|
|
52
48
|
* @throws {UnknownAddressError} when the SignatureTransfer branch runs on a chain without canonical Permit2.
|
|
53
49
|
* @throws {NonPositiveInputError} when the SignatureTransfer `deadline` is not positive.
|
|
54
50
|
* @throws {ExpiredDeadlineError} when the SignatureTransfer `deadline` is positive but not in the future.
|
|
@@ -65,7 +61,7 @@ export type BundlesTokenRequirementsState = {
|
|
|
65
61
|
* chainId: 1,
|
|
66
62
|
* amount: 1_000_000n,
|
|
67
63
|
* deadline: 1_900_000_000n,
|
|
68
|
-
* state: { type: "approval", allowance: 1_000_000n
|
|
64
|
+
* state: { type: "approval", allowance: 1_000_000n },
|
|
69
65
|
* });
|
|
70
66
|
* // requirements is empty because the allowance already covers the amount.
|
|
71
67
|
* ```
|
|
@@ -31,7 +31,6 @@ const getRequirementsApproval_js_1 = require("../requirements/getRequirementsApp
|
|
|
31
31
|
* @param params.state - Prefetched state for either classic approval or Permit2 SignatureTransfer.
|
|
32
32
|
* @param params.state.type - `approval` for a direct allowance or `permit2SignatureTransfer` for a signed pull.
|
|
33
33
|
* @param params.state.allowance - In the approval branch, current token allowance from `owner` to `spender`.
|
|
34
|
-
* @param params.state.approvalAmount - In the approval branch, allowance to set if needed; must cover `amount`.
|
|
35
34
|
* @param params.state.permit2Allowance - In the SignatureTransfer branch, current token allowance from `owner` to canonical Permit2.
|
|
36
35
|
* @param params.state.permit2Nonce - In the SignatureTransfer branch, caller-selected unused uint256 unordered nonce.
|
|
37
36
|
* @param params.state.nonceBitmap - In the SignatureTransfer branch, owner's Permit2 bitmap word at `permit2Nonce >> 8n`.
|
|
@@ -43,7 +42,6 @@ const getRequirementsApproval_js_1 = require("../requirements/getRequirementsApp
|
|
|
43
42
|
* @throws {InputExceedsMaxError} when `amount`, the Permit2 nonce, or the SignatureTransfer
|
|
44
43
|
* `deadline` exceeds uint256.
|
|
45
44
|
* @throws {Permit2SignatureTransferNonceAlreadyUsedError} when the selected nonce bit is set.
|
|
46
|
-
* @throws {ApprovalAmountLessThanSpendAmountError} when a classic approval cannot cover the pull.
|
|
47
45
|
* @throws {UnknownAddressError} when the SignatureTransfer branch runs on a chain without canonical Permit2.
|
|
48
46
|
* @throws {NonPositiveInputError} when the SignatureTransfer `deadline` is not positive.
|
|
49
47
|
* @throws {ExpiredDeadlineError} when the SignatureTransfer `deadline` is positive but not in the future.
|
|
@@ -60,7 +58,7 @@ const getRequirementsApproval_js_1 = require("../requirements/getRequirementsApp
|
|
|
60
58
|
* chainId: 1,
|
|
61
59
|
* amount: 1_000_000n,
|
|
62
60
|
* deadline: 1_900_000_000n,
|
|
63
|
-
* state: { type: "approval", allowance: 1_000_000n
|
|
61
|
+
* state: { type: "approval", allowance: 1_000_000n },
|
|
64
62
|
* });
|
|
65
63
|
* // requirements is empty because the allowance already covers the amount.
|
|
66
64
|
* ```
|
|
@@ -76,9 +74,6 @@ const resolveBundlesTokenRequirements = (params) => {
|
|
|
76
74
|
if (params.amount === 0n)
|
|
77
75
|
return [];
|
|
78
76
|
if (params.state.type === "approval") {
|
|
79
|
-
if (params.state.approvalAmount < params.amount) {
|
|
80
|
-
throw new index_js_1.ApprovalAmountLessThanSpendAmountError();
|
|
81
|
-
}
|
|
82
77
|
return (0, getRequirementsApproval_js_1.getRequirementsApproval)({
|
|
83
78
|
address: params.token,
|
|
84
79
|
chainId: params.chainId,
|
|
@@ -86,7 +81,6 @@ const resolveBundlesTokenRequirements = (params) => {
|
|
|
86
81
|
// Compare against the bounded pull to avoid redundant approvals and USDT zero-resets.
|
|
87
82
|
spender: params.spender,
|
|
88
83
|
spendAmount: params.amount,
|
|
89
|
-
approvalAmount: params.state.approvalAmount,
|
|
90
84
|
},
|
|
91
85
|
allowances: params.state.allowance,
|
|
92
86
|
});
|
|
@@ -113,7 +107,6 @@ const resolveBundlesTokenRequirements = (params) => {
|
|
|
113
107
|
args: {
|
|
114
108
|
spender: permit2,
|
|
115
109
|
spendAmount: params.amount,
|
|
116
|
-
approvalAmount: viem_1.maxUint256,
|
|
117
110
|
},
|
|
118
111
|
allowances: params.state.permit2Allowance,
|
|
119
112
|
}),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Address } from "viem";
|
|
2
|
-
import type
|
|
2
|
+
import { type Metadata, type MidnightAuthorizationAction, type Transaction } from "../../types/index.js";
|
|
3
3
|
/** Parameters for encoding a direct Midnight `setIsAuthorized` call. */
|
|
4
4
|
export interface MidnightSetIsAuthorizedParams {
|
|
5
5
|
readonly chainId: number;
|
|
@@ -23,7 +23,9 @@ export interface MidnightSetIsAuthorizedParams {
|
|
|
23
23
|
* @param params.isAuthorized - Optional target state; defaults to `true`.
|
|
24
24
|
* @param params.metadata - Optional analytics metadata appended to calldata.
|
|
25
25
|
* @returns A deep-frozen `Transaction<MidnightAuthorizationAction>` targeting `Midnight`.
|
|
26
|
+
* @throws {MidnightZeroOnBehalfError} when `onBehalf` is the zero address.
|
|
26
27
|
* @throws {UnsupportedMidnightAuthorizationTargetError} when granting authorization to an unsupported operator.
|
|
28
|
+
* @throws {MidnightCalldataEncodingError} when an input cannot be ABI-encoded, such as a malformed `bytes32`, an out-of-range integer or a malformed address.
|
|
27
29
|
* @example
|
|
28
30
|
* ```ts
|
|
29
31
|
* import { midnightSetIsAuthorized } from "@morpho-org/morpho-sdk";
|
|
@@ -4,8 +4,11 @@ exports.midnightSetIsAuthorized = void 0;
|
|
|
4
4
|
const midnight_sdk_1 = require("@morpho-org/midnight-sdk");
|
|
5
5
|
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
6
6
|
const viem_1 = require("viem");
|
|
7
|
+
const encodeMidnightCalldata_js_1 = require("../../helpers/encodeMidnightCalldata.js");
|
|
7
8
|
const index_js_1 = require("../../helpers/index.js");
|
|
9
|
+
const validateMidnightAccount_js_1 = require("../../helpers/validateMidnightAccount.js");
|
|
8
10
|
const validateMidnightAuthorizationTarget_js_1 = require("../../helpers/validateMidnightAuthorizationTarget.js");
|
|
11
|
+
const index_js_2 = require("../../types/index.js");
|
|
9
12
|
/**
|
|
10
13
|
* Encodes `Midnight.setIsAuthorized`. Grants target MidnightBundlesV2;
|
|
11
14
|
* revocations accept any operator.
|
|
@@ -21,7 +24,9 @@ const validateMidnightAuthorizationTarget_js_1 = require("../../helpers/validate
|
|
|
21
24
|
* @param params.isAuthorized - Optional target state; defaults to `true`.
|
|
22
25
|
* @param params.metadata - Optional analytics metadata appended to calldata.
|
|
23
26
|
* @returns A deep-frozen `Transaction<MidnightAuthorizationAction>` targeting `Midnight`.
|
|
27
|
+
* @throws {MidnightZeroOnBehalfError} when `onBehalf` is the zero address.
|
|
24
28
|
* @throws {UnsupportedMidnightAuthorizationTargetError} when granting authorization to an unsupported operator.
|
|
29
|
+
* @throws {MidnightCalldataEncodingError} when an input cannot be ABI-encoded, such as a malformed `bytes32`, an out-of-range integer or a malformed address.
|
|
25
30
|
* @example
|
|
26
31
|
* ```ts
|
|
27
32
|
* import { midnightSetIsAuthorized } from "@morpho-org/morpho-sdk";
|
|
@@ -34,6 +39,11 @@ const validateMidnightAuthorizationTarget_js_1 = require("../../helpers/validate
|
|
|
34
39
|
* ```
|
|
35
40
|
*/
|
|
36
41
|
const midnightSetIsAuthorized = (params) => {
|
|
42
|
+
// Reject a malformed account before comparing it with the zero address.
|
|
43
|
+
(0, validateMidnightAccount_js_1.validateMidnightAddress)("onBehalf", params.onBehalf);
|
|
44
|
+
if ((0, viem_1.isAddressEqual)(params.onBehalf, viem_1.zeroAddress)) {
|
|
45
|
+
throw new index_js_2.MidnightZeroOnBehalfError("onBehalf");
|
|
46
|
+
}
|
|
37
47
|
const isAuthorized = params.isAuthorized ?? true;
|
|
38
48
|
if (isAuthorized) {
|
|
39
49
|
// Restrict grants to known protocol operators; revocations remain permissionless by target.
|
|
@@ -46,7 +56,7 @@ const midnightSetIsAuthorized = (params) => {
|
|
|
46
56
|
let tx = {
|
|
47
57
|
to: midnight,
|
|
48
58
|
value: 0n,
|
|
49
|
-
data: (0,
|
|
59
|
+
data: (0, encodeMidnightCalldata_js_1.encodeMidnightCalldata)({
|
|
50
60
|
abi: midnight_sdk_1.midnightAbi,
|
|
51
61
|
functionName: "setIsAuthorized",
|
|
52
62
|
args: [params.authorized, isAuthorized, params.onBehalf],
|
|
@@ -72,6 +72,8 @@ export type { MidnightCancelAndMakeParams, MidnightMakeBorrowCollateral, Midnigh
|
|
|
72
72
|
* @throws {UnknownCollateralIndexError} when a collateral index is not configured on the market.
|
|
73
73
|
* @throws {NonPositiveInputError} when a collateral supply amount is non-positive.
|
|
74
74
|
* @throws {NonPositiveInputError} when `blueSupply.assets` is non-positive.
|
|
75
|
+
* @throws {MidnightCalldataEncodingError} when another input cannot be ABI-encoded, such as an
|
|
76
|
+
* out-of-range integer or malformed address.
|
|
75
77
|
* @example
|
|
76
78
|
* ```ts
|
|
77
79
|
* import { getChainAddress } from "@morpho-org/morpho-ts";
|
|
@@ -4,8 +4,10 @@ exports.midnightCancelAndMake = void 0;
|
|
|
4
4
|
const midnight_sdk_1 = require("@morpho-org/midnight-sdk");
|
|
5
5
|
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
6
6
|
const viem_1 = require("viem");
|
|
7
|
+
const encodeMidnightCalldata_js_1 = require("../../helpers/encodeMidnightCalldata.js");
|
|
7
8
|
const index_js_1 = require("../../helpers/index.js");
|
|
8
9
|
const validate_js_1 = require("../../helpers/validate.js");
|
|
10
|
+
const validateMidnightAccount_js_1 = require("../../helpers/validateMidnightAccount.js");
|
|
9
11
|
const validateMidnightBounds_js_1 = require("../../helpers/validateMidnightBounds.js");
|
|
10
12
|
const validateMidnightMarket_js_1 = require("../../helpers/validateMidnightMarket.js");
|
|
11
13
|
const validateMidnightPublication_js_1 = require("../../helpers/validateMidnightPublication.js");
|
|
@@ -100,6 +102,8 @@ const emptyMidnightMarket = {
|
|
|
100
102
|
* @throws {UnknownCollateralIndexError} when a collateral index is not configured on the market.
|
|
101
103
|
* @throws {NonPositiveInputError} when a collateral supply amount is non-positive.
|
|
102
104
|
* @throws {NonPositiveInputError} when `blueSupply.assets` is non-positive.
|
|
105
|
+
* @throws {MidnightCalldataEncodingError} when another input cannot be ABI-encoded, such as an
|
|
106
|
+
* out-of-range integer or malformed address.
|
|
103
107
|
* @example
|
|
104
108
|
* ```ts
|
|
105
109
|
* import { getChainAddress } from "@morpho-org/morpho-ts";
|
|
@@ -165,6 +169,7 @@ const midnightCancelAndMake = (params) => {
|
|
|
165
169
|
}
|
|
166
170
|
const { priceRatifierV1, rateRatifierV1 } = (0, morpho_ts_1.getChainAddresses)(snapshot.chainId);
|
|
167
171
|
const supportedTargets = [priceRatifierV1, rateRatifierV1].filter((target) => target != null);
|
|
172
|
+
(0, validateMidnightAccount_js_1.validateMidnightAddress)("publication.ratifier", publication.ratifier);
|
|
168
173
|
if (!supportedTargets.some((target) => (0, viem_1.isAddressEqual)(publication.ratifier, target))) {
|
|
169
174
|
throw new index_js_2.UnsupportedMidnightAuthorizationTargetError({
|
|
170
175
|
authorized: publication.ratifier,
|
|
@@ -253,7 +258,7 @@ const midnightCancelAndMake = (params) => {
|
|
|
253
258
|
let tx = {
|
|
254
259
|
to: (0, morpho_ts_1.getChainAddress)(snapshot.chainId, "midnightBundlesV2"),
|
|
255
260
|
value: nativeFunding.value,
|
|
256
|
-
data: (0,
|
|
261
|
+
data: (0, encodeMidnightCalldata_js_1.encodeMidnightCalldata)({
|
|
257
262
|
abi: midnight_sdk_1.midnightBundlesV2Abi,
|
|
258
263
|
functionName: "midnightBundlesV2CancelAndMake",
|
|
259
264
|
args: [
|
|
@@ -289,13 +294,16 @@ const midnightCancelAndMake = (params) => {
|
|
|
289
294
|
args: {
|
|
290
295
|
market: publication?.collateral == null
|
|
291
296
|
? viem_1.zeroHash
|
|
292
|
-
:
|
|
297
|
+
: (0, encodeMidnightCalldata_js_1.encodeMidnightMarketId)(publication.collateral.market),
|
|
293
298
|
ratifier: publication?.ratifier ?? viem_1.zeroAddress,
|
|
294
299
|
root: publication?.root ?? viem_1.zeroHash,
|
|
295
300
|
groups: [...(publication?.groups ?? [])],
|
|
296
301
|
cancellations,
|
|
297
302
|
collateralSupplies: supplies,
|
|
298
303
|
...(blueSupply && { blueSupply }),
|
|
304
|
+
...(nativeFunding.value > 0n
|
|
305
|
+
? { nativeAmount: nativeFunding.value }
|
|
306
|
+
: {}),
|
|
299
307
|
deadline: snapshot.deadline,
|
|
300
308
|
},
|
|
301
309
|
},
|
|
@@ -23,7 +23,8 @@ export interface MidnightRedeemParams {
|
|
|
23
23
|
* @param params.chainId - Chain id used to resolve `Midnight`.
|
|
24
24
|
* @param params.market - Midnight market whose credit is redeemed.
|
|
25
25
|
* @param params.units - Credit units to withdraw.
|
|
26
|
-
* @param params.onBehalf - Account whose credit balance is reduced.
|
|
26
|
+
* @param params.onBehalf - Account whose credit balance is reduced. `onBehalf`, or an operator
|
|
27
|
+
* it authorized, must send the transaction; otherwise Midnight reverts `Unauthorized()`.
|
|
27
28
|
* @param params.receiver - Optional receiver for withdrawn loan assets; defaults to `onBehalf`.
|
|
28
29
|
* Midnight protocol and market token contracts are rejected.
|
|
29
30
|
* @param params.metadata - Optional analytics metadata appended to calldata.
|
|
@@ -33,6 +34,7 @@ export interface MidnightRedeemParams {
|
|
|
33
34
|
* @throws {MidnightZeroOnBehalfError} when `onBehalf` is the zero address.
|
|
34
35
|
* @throws {ChainIdMismatchError} when the market targets another chain.
|
|
35
36
|
* @throws {MidnightMarketAddressMismatchError} when the market targets another Midnight deployment.
|
|
37
|
+
* @throws {MidnightCalldataEncodingError} when an input cannot be ABI-encoded, such as a malformed `bytes32`, an out-of-range integer or a malformed address.
|
|
36
38
|
* @throws {MidnightZeroReceiverError} when `receiver` resolves to the zero address.
|
|
37
39
|
* @throws {MidnightContractReceiverError} when `receiver` is a Midnight protocol contract or a
|
|
38
40
|
* market token contract.
|
|
@@ -4,7 +4,9 @@ exports.midnightRedeem = void 0;
|
|
|
4
4
|
const midnight_sdk_1 = require("@morpho-org/midnight-sdk");
|
|
5
5
|
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
6
6
|
const viem_1 = require("viem");
|
|
7
|
+
const encodeMidnightCalldata_js_1 = require("../../helpers/encodeMidnightCalldata.js");
|
|
7
8
|
const index_js_1 = require("../../helpers/index.js");
|
|
9
|
+
const validateMidnightAccount_js_1 = require("../../helpers/validateMidnightAccount.js");
|
|
8
10
|
const validateMidnightBounds_js_1 = require("../../helpers/validateMidnightBounds.js");
|
|
9
11
|
const validateMidnightMarket_js_1 = require("../../helpers/validateMidnightMarket.js");
|
|
10
12
|
const validateMidnightReceiver_js_1 = require("../../helpers/validateMidnightReceiver.js");
|
|
@@ -22,7 +24,8 @@ const index_js_2 = require("../../types/index.js");
|
|
|
22
24
|
* @param params.chainId - Chain id used to resolve `Midnight`.
|
|
23
25
|
* @param params.market - Midnight market whose credit is redeemed.
|
|
24
26
|
* @param params.units - Credit units to withdraw.
|
|
25
|
-
* @param params.onBehalf - Account whose credit balance is reduced.
|
|
27
|
+
* @param params.onBehalf - Account whose credit balance is reduced. `onBehalf`, or an operator
|
|
28
|
+
* it authorized, must send the transaction; otherwise Midnight reverts `Unauthorized()`.
|
|
26
29
|
* @param params.receiver - Optional receiver for withdrawn loan assets; defaults to `onBehalf`.
|
|
27
30
|
* Midnight protocol and market token contracts are rejected.
|
|
28
31
|
* @param params.metadata - Optional analytics metadata appended to calldata.
|
|
@@ -32,6 +35,7 @@ const index_js_2 = require("../../types/index.js");
|
|
|
32
35
|
* @throws {MidnightZeroOnBehalfError} when `onBehalf` is the zero address.
|
|
33
36
|
* @throws {ChainIdMismatchError} when the market targets another chain.
|
|
34
37
|
* @throws {MidnightMarketAddressMismatchError} when the market targets another Midnight deployment.
|
|
38
|
+
* @throws {MidnightCalldataEncodingError} when an input cannot be ABI-encoded, such as a malformed `bytes32`, an out-of-range integer or a malformed address.
|
|
35
39
|
* @throws {MidnightZeroReceiverError} when `receiver` resolves to the zero address.
|
|
36
40
|
* @throws {MidnightContractReceiverError} when `receiver` is a Midnight protocol contract or a
|
|
37
41
|
* market token contract.
|
|
@@ -48,6 +52,8 @@ const index_js_2 = require("../../types/index.js");
|
|
|
48
52
|
* ```
|
|
49
53
|
*/
|
|
50
54
|
const midnightRedeem = (params) => {
|
|
55
|
+
// Reject a malformed account before comparing it with the zero address.
|
|
56
|
+
(0, validateMidnightAccount_js_1.validateMidnightAddress)("onBehalf", params.onBehalf);
|
|
51
57
|
if (params.units <= 0n) {
|
|
52
58
|
throw new index_js_2.NonPositiveInputError("units", params.units);
|
|
53
59
|
}
|
|
@@ -57,7 +63,7 @@ const midnightRedeem = (params) => {
|
|
|
57
63
|
}
|
|
58
64
|
// Reject markets from another chain deployment before encoding the call.
|
|
59
65
|
(0, validateMidnightMarket_js_1.validateMidnightMarket)({ market: params.market, chainId: params.chainId });
|
|
60
|
-
const marketId =
|
|
66
|
+
const marketId = (0, encodeMidnightCalldata_js_1.encodeMidnightMarketId)(params.market);
|
|
61
67
|
const midnight = (0, morpho_ts_1.getChainAddress)(params.chainId, "midnight");
|
|
62
68
|
const receiver = params.receiver ?? params.onBehalf;
|
|
63
69
|
// Rejects receivers that would strand the redeemed assets in a contract.
|
|
@@ -70,7 +76,7 @@ const midnightRedeem = (params) => {
|
|
|
70
76
|
let tx = {
|
|
71
77
|
to: midnight,
|
|
72
78
|
value: 0n,
|
|
73
|
-
data: (0,
|
|
79
|
+
data: (0, encodeMidnightCalldata_js_1.encodeMidnightCalldata)({
|
|
74
80
|
abi: midnight_sdk_1.midnightAbi,
|
|
75
81
|
functionName: "withdraw",
|
|
76
82
|
args: [
|
|
@@ -65,6 +65,7 @@ export interface MidnightRepayWithdrawCollateralParams {
|
|
|
65
65
|
* @throws {MidnightMarketAddressMismatchError} when the market targets another Midnight deployment.
|
|
66
66
|
* @throws {UnknownCollateralIndexError} when a withdrawal targets an unconfigured collateral index.
|
|
67
67
|
* @throws {MidnightZeroReceiverError} when collateral is withdrawn to the zero address.
|
|
68
|
+
* @throws {MidnightCalldataEncodingError} when an input cannot be ABI-encoded, such as a malformed `bytes32`, an out-of-range integer or a malformed address.
|
|
68
69
|
* @throws {MidnightContractReceiverError} when `collateralReceiver` is a Midnight protocol
|
|
69
70
|
* contract or a market token contract.
|
|
70
71
|
* @example
|
|
@@ -4,8 +4,10 @@ exports.midnightRepayWithdrawCollateral = void 0;
|
|
|
4
4
|
const midnight_sdk_1 = require("@morpho-org/midnight-sdk");
|
|
5
5
|
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
6
6
|
const viem_1 = require("viem");
|
|
7
|
+
const encodeMidnightCalldata_js_1 = require("../../helpers/encodeMidnightCalldata.js");
|
|
7
8
|
const index_js_1 = require("../../helpers/index.js");
|
|
8
9
|
const validate_js_1 = require("../../helpers/validate.js");
|
|
10
|
+
const validateMidnightAccount_js_1 = require("../../helpers/validateMidnightAccount.js");
|
|
9
11
|
const validateMidnightMarket_js_1 = require("../../helpers/validateMidnightMarket.js");
|
|
10
12
|
const validateMidnightReceiver_js_1 = require("../../helpers/validateMidnightReceiver.js");
|
|
11
13
|
const index_js_2 = require("../../types/index.js");
|
|
@@ -50,6 +52,7 @@ const index_js_2 = require("../../types/index.js");
|
|
|
50
52
|
* @throws {MidnightMarketAddressMismatchError} when the market targets another Midnight deployment.
|
|
51
53
|
* @throws {UnknownCollateralIndexError} when a withdrawal targets an unconfigured collateral index.
|
|
52
54
|
* @throws {MidnightZeroReceiverError} when collateral is withdrawn to the zero address.
|
|
55
|
+
* @throws {MidnightCalldataEncodingError} when an input cannot be ABI-encoded, such as a malformed `bytes32`, an out-of-range integer or a malformed address.
|
|
53
56
|
* @throws {MidnightContractReceiverError} when `collateralReceiver` is a Midnight protocol
|
|
54
57
|
* contract or a market token contract.
|
|
55
58
|
* @example
|
|
@@ -96,6 +99,7 @@ const midnightRepayWithdrawCollateral = (params) => {
|
|
|
96
99
|
// Throws UnknownCollateralIndexError when the index is not configured on the market.
|
|
97
100
|
midnight_sdk_1.MarketUtils.getCollateralByIndex(params.market, collateralIndex);
|
|
98
101
|
}
|
|
102
|
+
(0, validateMidnightAccount_js_1.validateMidnightAddress)("collateralReceiver", params.collateralReceiver);
|
|
99
103
|
if (params.collateralWithdrawals.length > 0) {
|
|
100
104
|
// Rejects receivers that would strand the withdrawn collateral in a contract.
|
|
101
105
|
(0, validateMidnightReceiver_js_1.validateMidnightReceiver)({
|
|
@@ -148,12 +152,12 @@ const midnightRepayWithdrawCollateral = (params) => {
|
|
|
148
152
|
to: (0, morpho_ts_1.getChainAddress)(params.chainId, "midnightBundlesV2"),
|
|
149
153
|
value: nativeFunding.value,
|
|
150
154
|
data: repay.type === "assets"
|
|
151
|
-
? (0,
|
|
155
|
+
? (0, encodeMidnightCalldata_js_1.encodeMidnightCalldata)({
|
|
152
156
|
abi: midnight_sdk_1.midnightBundlesV2Abi,
|
|
153
157
|
functionName: "midnightBundlesV2BuyWithAssetsTargetAndWithdrawCollateral",
|
|
154
158
|
args: [market, repay.assets, repay.assets, ...args],
|
|
155
159
|
})
|
|
156
|
-
: (0,
|
|
160
|
+
: (0, encodeMidnightCalldata_js_1.encodeMidnightCalldata)({
|
|
157
161
|
abi: midnight_sdk_1.midnightBundlesV2Abi,
|
|
158
162
|
functionName: "midnightBundlesV2BuyWithUnitsTargetAndWithdrawCollateral",
|
|
159
163
|
args: [market, viem_1.maxUint256, repay.maxBuyerAssets, ...args],
|
|
@@ -167,7 +171,7 @@ const midnightRepayWithdrawCollateral = (params) => {
|
|
|
167
171
|
action: {
|
|
168
172
|
type: "midnightRepayWithdrawCollateral",
|
|
169
173
|
args: {
|
|
170
|
-
market:
|
|
174
|
+
market: (0, encodeMidnightCalldata_js_1.encodeMidnightMarketId)(params.market),
|
|
171
175
|
repay: { ...repay },
|
|
172
176
|
collateralWithdrawals: params.collateralWithdrawals.map(({ collateralIndex, assets }) => ({ collateralIndex, assets })),
|
|
173
177
|
collateralReceiver: params.collateralReceiver,
|
|
@@ -22,7 +22,9 @@ export interface MidnightSupplyCollateralParams {
|
|
|
22
22
|
* @param params.market - Midnight market receiving collateral.
|
|
23
23
|
* @param params.collateralIndex - Optional collateral index; defaults to `0n`.
|
|
24
24
|
* @param params.assets - Collateral assets to supply.
|
|
25
|
-
* @param params.onBehalf - Account whose collateral balance increases.
|
|
25
|
+
* @param params.onBehalf - Account whose collateral balance increases. `onBehalf`, or an
|
|
26
|
+
* operator it authorized, must send the transaction; otherwise Midnight reverts
|
|
27
|
+
* `Unauthorized()`. The collateral is pulled from the sender.
|
|
26
28
|
* @param params.metadata - Optional analytics metadata appended to calldata.
|
|
27
29
|
* @returns A deep-frozen `Transaction<MidnightSupplyCollateralAction>` targeting `Midnight`.
|
|
28
30
|
* @throws {NonPositiveInputError} when `assets <= 0n`.
|
|
@@ -31,6 +33,7 @@ export interface MidnightSupplyCollateralParams {
|
|
|
31
33
|
* @throws {ChainIdMismatchError} when the market targets another chain.
|
|
32
34
|
* @throws {MidnightMarketAddressMismatchError} when the market targets another Midnight deployment.
|
|
33
35
|
* @throws {UnknownCollateralIndexError} when `collateralIndex` is not configured on the market.
|
|
36
|
+
* @throws {MidnightCalldataEncodingError} when an input cannot be ABI-encoded, such as a malformed `bytes32`, an out-of-range integer or a malformed address.
|
|
34
37
|
* @example
|
|
35
38
|
* ```ts
|
|
36
39
|
* import { midnightSupplyCollateral } from "@morpho-org/morpho-sdk";
|
|
@@ -4,7 +4,9 @@ exports.midnightSupplyCollateral = void 0;
|
|
|
4
4
|
const midnight_sdk_1 = require("@morpho-org/midnight-sdk");
|
|
5
5
|
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
6
6
|
const viem_1 = require("viem");
|
|
7
|
+
const encodeMidnightCalldata_js_1 = require("../../helpers/encodeMidnightCalldata.js");
|
|
7
8
|
const index_js_1 = require("../../helpers/index.js");
|
|
9
|
+
const validateMidnightAccount_js_1 = require("../../helpers/validateMidnightAccount.js");
|
|
8
10
|
const validateMidnightBounds_js_1 = require("../../helpers/validateMidnightBounds.js");
|
|
9
11
|
const validateMidnightMarket_js_1 = require("../../helpers/validateMidnightMarket.js");
|
|
10
12
|
const index_js_2 = require("../../types/index.js");
|
|
@@ -20,7 +22,9 @@ const index_js_2 = require("../../types/index.js");
|
|
|
20
22
|
* @param params.market - Midnight market receiving collateral.
|
|
21
23
|
* @param params.collateralIndex - Optional collateral index; defaults to `0n`.
|
|
22
24
|
* @param params.assets - Collateral assets to supply.
|
|
23
|
-
* @param params.onBehalf - Account whose collateral balance increases.
|
|
25
|
+
* @param params.onBehalf - Account whose collateral balance increases. `onBehalf`, or an
|
|
26
|
+
* operator it authorized, must send the transaction; otherwise Midnight reverts
|
|
27
|
+
* `Unauthorized()`. The collateral is pulled from the sender.
|
|
24
28
|
* @param params.metadata - Optional analytics metadata appended to calldata.
|
|
25
29
|
* @returns A deep-frozen `Transaction<MidnightSupplyCollateralAction>` targeting `Midnight`.
|
|
26
30
|
* @throws {NonPositiveInputError} when `assets <= 0n`.
|
|
@@ -29,6 +33,7 @@ const index_js_2 = require("../../types/index.js");
|
|
|
29
33
|
* @throws {ChainIdMismatchError} when the market targets another chain.
|
|
30
34
|
* @throws {MidnightMarketAddressMismatchError} when the market targets another Midnight deployment.
|
|
31
35
|
* @throws {UnknownCollateralIndexError} when `collateralIndex` is not configured on the market.
|
|
36
|
+
* @throws {MidnightCalldataEncodingError} when an input cannot be ABI-encoded, such as a malformed `bytes32`, an out-of-range integer or a malformed address.
|
|
32
37
|
* @example
|
|
33
38
|
* ```ts
|
|
34
39
|
* import { midnightSupplyCollateral } from "@morpho-org/morpho-sdk";
|
|
@@ -43,6 +48,8 @@ const index_js_2 = require("../../types/index.js");
|
|
|
43
48
|
* ```
|
|
44
49
|
*/
|
|
45
50
|
const midnightSupplyCollateral = (params) => {
|
|
51
|
+
// Reject a malformed account before comparing it with the zero address.
|
|
52
|
+
(0, validateMidnightAccount_js_1.validateMidnightAddress)("onBehalf", params.onBehalf);
|
|
46
53
|
if (params.assets <= 0n) {
|
|
47
54
|
throw new index_js_2.NonPositiveInputError("assets", params.assets);
|
|
48
55
|
}
|
|
@@ -52,7 +59,7 @@ const midnightSupplyCollateral = (params) => {
|
|
|
52
59
|
}
|
|
53
60
|
// Reject markets from another chain deployment before encoding the call.
|
|
54
61
|
(0, validateMidnightMarket_js_1.validateMidnightMarket)({ market: params.market, chainId: params.chainId });
|
|
55
|
-
const marketId =
|
|
62
|
+
const marketId = (0, encodeMidnightCalldata_js_1.encodeMidnightMarketId)(params.market);
|
|
56
63
|
const midnight = (0, morpho_ts_1.getChainAddress)(params.chainId, "midnight");
|
|
57
64
|
const collateralIndex = params.collateralIndex ?? 0n;
|
|
58
65
|
// Validate that the supplied collateral index is configured before encoding.
|
|
@@ -60,7 +67,7 @@ const midnightSupplyCollateral = (params) => {
|
|
|
60
67
|
let tx = {
|
|
61
68
|
to: midnight,
|
|
62
69
|
value: 0n,
|
|
63
|
-
data: (0,
|
|
70
|
+
data: (0, encodeMidnightCalldata_js_1.encodeMidnightCalldata)({
|
|
64
71
|
abi: midnight_sdk_1.midnightAbi,
|
|
65
72
|
functionName: "supplyCollateral",
|
|
66
73
|
args: [
|