@morpho-org/morpho-sdk 4.1.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 +12 -12
- package/lib/cjs/entities/reallocationData.js +19 -19
- 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 +12 -12
- package/lib/esm/entities/reallocationData.js +18 -18
- 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
|
@@ -2,10 +2,10 @@ import { DEFAULT_SLIPPAGE_TOLERANCE, getChainAddresses, MathLib, } from "@morpho
|
|
|
2
2
|
import { fetchAccrualVault } from "@morpho-org/blue-sdk-viem";
|
|
3
3
|
import { Time } from "@morpho-org/morpho-ts";
|
|
4
4
|
import { isAddressEqual } from "viem";
|
|
5
|
-
import {
|
|
5
|
+
import { getGeneralAdapterRequirements, vaultV1Deposit, vaultV1MigrateToV2, vaultV1Redeem, vaultV1Withdraw, } from "../../actions/index.js";
|
|
6
6
|
import { MAX_ABSOLUTE_SHARE_PRICE, MAX_SLIPPAGE_TOLERANCE, } from "../../helpers/constant.js";
|
|
7
7
|
import { validateChainId } from "../../helpers/index.js";
|
|
8
|
-
import { ChainIdMismatchError, ChainWNativeMissingError, ExcessiveSlippageToleranceError, NativeAmountOnNonWNativeVaultError, NegativeNativeAmountError, NegativeSlippageToleranceError, NonPositiveAssetAmountError, NonPositiveSharesAmountError, VaultAddressMismatchError, VaultAssetMismatchError, } from "../../types/index.js";
|
|
8
|
+
import { ChainIdMismatchError, ChainWNativeMissingError, ExcessiveSlippageToleranceError, NativeAmountOnNonWNativeVaultError, NegativeNativeAmountError, NegativeSlippageToleranceError, NonPositiveAssetAmountError, NonPositiveSharesAmountError, selectRequirementSignatures, VaultAddressMismatchError, VaultAssetMismatchError, } from "../../types/index.js";
|
|
9
9
|
export class MorphoVaultV1 {
|
|
10
10
|
client;
|
|
11
11
|
vault;
|
|
@@ -65,7 +65,7 @@ export class MorphoVaultV1 {
|
|
|
65
65
|
}
|
|
66
66
|
const maxSharePrice = MathLib.min(MathLib.mulDivUp(totalAssets, MathLib.wToRay(MathLib.WAD + slippageTolerance), shares), MAX_ABSOLUTE_SHARE_PRICE);
|
|
67
67
|
return {
|
|
68
|
-
getRequirements:
|
|
68
|
+
getRequirements: (params) => getGeneralAdapterRequirements(this.client.viemClient, {
|
|
69
69
|
address: vaultData.asset,
|
|
70
70
|
chainId: this.chainId,
|
|
71
71
|
supportSignature: this.client.options.supportSignature,
|
|
@@ -76,21 +76,26 @@ export class MorphoVaultV1 {
|
|
|
76
76
|
from: userAddress,
|
|
77
77
|
},
|
|
78
78
|
}),
|
|
79
|
-
buildTx: (
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
79
|
+
buildTx: (signatures) => {
|
|
80
|
+
const { permit } = selectRequirementSignatures(signatures, {
|
|
81
|
+
permit: true,
|
|
82
|
+
});
|
|
83
|
+
return vaultV1Deposit({
|
|
84
|
+
vault: {
|
|
85
|
+
chainId: this.chainId,
|
|
86
|
+
address: this.vault,
|
|
87
|
+
asset: vaultData.asset,
|
|
88
|
+
},
|
|
89
|
+
args: {
|
|
90
|
+
amount,
|
|
91
|
+
maxSharePrice,
|
|
92
|
+
recipient: userAddress,
|
|
93
|
+
requirementSignature: permit,
|
|
94
|
+
nativeAmount,
|
|
95
|
+
},
|
|
96
|
+
metadata: this.client.options.metadata,
|
|
97
|
+
});
|
|
98
|
+
},
|
|
94
99
|
};
|
|
95
100
|
}
|
|
96
101
|
withdraw({ amount, userAddress }) {
|
|
@@ -155,7 +160,7 @@ export class MorphoVaultV1 {
|
|
|
155
160
|
}
|
|
156
161
|
const maxSharePriceVaultV2 = MathLib.min(MathLib.mulDivUp(v1RefAssets, MathLib.wToRay(MathLib.WAD + slippageTolerance), v2RefShares), MAX_ABSOLUTE_SHARE_PRICE);
|
|
157
162
|
return {
|
|
158
|
-
getRequirements:
|
|
163
|
+
getRequirements: () => getGeneralAdapterRequirements(this.client.viemClient, {
|
|
159
164
|
address: this.vault,
|
|
160
165
|
chainId: this.chainId,
|
|
161
166
|
supportSignature: this.client.options.supportSignature,
|
|
@@ -167,23 +172,28 @@ export class MorphoVaultV1 {
|
|
|
167
172
|
from: userAddress,
|
|
168
173
|
},
|
|
169
174
|
}),
|
|
170
|
-
buildTx: (
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
175
|
+
buildTx: (signatures) => {
|
|
176
|
+
const { permit } = selectRequirementSignatures(signatures, {
|
|
177
|
+
permit: true,
|
|
178
|
+
});
|
|
179
|
+
return vaultV1MigrateToV2({
|
|
180
|
+
vault: {
|
|
181
|
+
chainId: this.chainId,
|
|
182
|
+
address: this.vault,
|
|
183
|
+
asset: sourceVault.asset,
|
|
184
|
+
},
|
|
185
|
+
args: {
|
|
186
|
+
targetVault: targetVault.address,
|
|
187
|
+
targetAsset: targetVault.asset,
|
|
188
|
+
shares,
|
|
189
|
+
minSharePriceVaultV1,
|
|
190
|
+
maxSharePriceVaultV2,
|
|
191
|
+
recipient: userAddress,
|
|
192
|
+
requirementSignature: permit,
|
|
193
|
+
},
|
|
194
|
+
metadata: this.client.options.metadata,
|
|
195
|
+
});
|
|
196
|
+
},
|
|
187
197
|
};
|
|
188
198
|
}
|
|
189
199
|
}
|
|
@@ -2,7 +2,7 @@ import { type AccrualVaultV2 } from "@morpho-org/blue-sdk";
|
|
|
2
2
|
import { fetchAccrualVaultV2 } from "@morpho-org/blue-sdk-viem";
|
|
3
3
|
import { type Address } from "viem";
|
|
4
4
|
import type { FetchParameters } from "../../types/data.js";
|
|
5
|
-
import { type Deallocation, type DepositAmountArgs, type ERC20ApprovalAction, type MorphoClientType, type Requirement, type RequirementSignature, type Transaction, type VaultV2DepositAction, type VaultV2ForceRedeemAction, type VaultV2ForceWithdrawAction, type VaultV2RedeemAction, type VaultV2WithdrawAction } from "../../types/index.js";
|
|
5
|
+
import { type Deallocation, type DepositAmountArgs, type ERC20ApprovalAction, type MorphoClientType, type PermitRequirementSignature, type Requirement, type RequirementSignature, type Transaction, type VaultV2DepositAction, type VaultV2ForceRedeemAction, type VaultV2ForceWithdrawAction, type VaultV2RedeemAction, type VaultV2WithdrawAction } from "../../types/index.js";
|
|
6
6
|
export interface VaultV2Actions {
|
|
7
7
|
/**
|
|
8
8
|
* Fetches the latest vault data.
|
|
@@ -29,17 +29,17 @@ export interface VaultV2Actions {
|
|
|
29
29
|
* @param {bigint} [params.nativeAmount] - Amount of native token to wrap into wNative. Vault asset must be wNative.
|
|
30
30
|
* @returns {Object} The result object.
|
|
31
31
|
* @returns {Readonly<Transaction<VaultV2DepositAction>>} returns.tx The prepared deposit transaction.
|
|
32
|
-
* @returns {Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Requirement)[]>} returns.getRequirements The function for retrieving all required approval transactions.
|
|
32
|
+
* @returns {Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Requirement<PermitRequirementSignature>)[]>} returns.getRequirements The function for retrieving all required approval transactions.
|
|
33
33
|
*/
|
|
34
34
|
deposit: (params: {
|
|
35
35
|
userAddress: Address;
|
|
36
36
|
vaultData: AccrualVaultV2;
|
|
37
37
|
slippageTolerance?: bigint;
|
|
38
38
|
} & DepositAmountArgs) => {
|
|
39
|
-
buildTx: (
|
|
39
|
+
buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<VaultV2DepositAction>>;
|
|
40
40
|
getRequirements: (params?: {
|
|
41
41
|
useSimplePermit?: boolean;
|
|
42
|
-
}) => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Requirement)[]>;
|
|
42
|
+
}) => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Requirement<PermitRequirementSignature>)[]>;
|
|
43
43
|
};
|
|
44
44
|
/**
|
|
45
45
|
* Prepares a withdraw transaction for the VaultV2 contract.
|
|
@@ -144,8 +144,8 @@ export declare class MorphoVaultV2 implements VaultV2Actions {
|
|
|
144
144
|
} & DepositAmountArgs): {
|
|
145
145
|
getRequirements: (params?: {
|
|
146
146
|
useSimplePermit?: boolean;
|
|
147
|
-
}) => Promise<(
|
|
148
|
-
buildTx: (
|
|
147
|
+
}) => Promise<(import("../../types/action.js").Bundler3TokenSignatureRequirement | Readonly<Transaction<ERC20ApprovalAction>>)[]>;
|
|
148
|
+
buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<VaultV2DepositAction>>;
|
|
149
149
|
};
|
|
150
150
|
withdraw({ amount, userAddress }: {
|
|
151
151
|
amount: bigint;
|
|
@@ -2,9 +2,9 @@ import { DEFAULT_SLIPPAGE_TOLERANCE, getChainAddresses, MathLib, } from "@morpho
|
|
|
2
2
|
import { fetchAccrualVaultV2 } from "@morpho-org/blue-sdk-viem";
|
|
3
3
|
import { Time } from "@morpho-org/morpho-ts";
|
|
4
4
|
import { isAddressEqual } from "viem";
|
|
5
|
-
import {
|
|
5
|
+
import { getGeneralAdapterRequirements, vaultV2Deposit, vaultV2ForceRedeem, vaultV2ForceWithdraw, vaultV2Redeem, vaultV2Withdraw, } from "../../actions/index.js";
|
|
6
6
|
import { MAX_SLIPPAGE_TOLERANCE } from "../../helpers/constant.js";
|
|
7
|
-
import { ChainIdMismatchError, ChainWNativeMissingError, ExcessiveSlippageToleranceError, NativeAmountOnNonWNativeVaultError, NegativeNativeAmountError, NegativeSlippageToleranceError, NonPositiveAssetAmountError, NonPositiveSharesAmountError, VaultAddressMismatchError, } from "../../types/index.js";
|
|
7
|
+
import { ChainIdMismatchError, ChainWNativeMissingError, ExcessiveSlippageToleranceError, NativeAmountOnNonWNativeVaultError, NegativeNativeAmountError, NegativeSlippageToleranceError, NonPositiveAssetAmountError, NonPositiveSharesAmountError, selectRequirementSignatures, VaultAddressMismatchError, } from "../../types/index.js";
|
|
8
8
|
export class MorphoVaultV2 {
|
|
9
9
|
client;
|
|
10
10
|
vault;
|
|
@@ -68,7 +68,7 @@ export class MorphoVaultV2 {
|
|
|
68
68
|
}
|
|
69
69
|
const maxSharePrice = MathLib.min(MathLib.mulDivUp(totalAssets, MathLib.wToRay(MathLib.WAD + slippageTolerance), shares), MathLib.RAY * 100n);
|
|
70
70
|
return {
|
|
71
|
-
getRequirements:
|
|
71
|
+
getRequirements: (params) => getGeneralAdapterRequirements(this.client.viemClient, {
|
|
72
72
|
address: vaultData.asset,
|
|
73
73
|
chainId: this.chainId,
|
|
74
74
|
supportSignature: this.client.options.supportSignature,
|
|
@@ -79,21 +79,26 @@ export class MorphoVaultV2 {
|
|
|
79
79
|
from: userAddress,
|
|
80
80
|
},
|
|
81
81
|
}),
|
|
82
|
-
buildTx: (
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
82
|
+
buildTx: (signatures) => {
|
|
83
|
+
const { permit } = selectRequirementSignatures(signatures, {
|
|
84
|
+
permit: true,
|
|
85
|
+
});
|
|
86
|
+
return vaultV2Deposit({
|
|
87
|
+
vault: {
|
|
88
|
+
chainId: this.chainId,
|
|
89
|
+
address: this.vault,
|
|
90
|
+
asset: vaultData.asset,
|
|
91
|
+
},
|
|
92
|
+
args: {
|
|
93
|
+
amount,
|
|
94
|
+
maxSharePrice,
|
|
95
|
+
recipient: userAddress,
|
|
96
|
+
requirementSignature: permit,
|
|
97
|
+
nativeAmount,
|
|
98
|
+
},
|
|
99
|
+
metadata: this.client.options.metadata,
|
|
100
|
+
});
|
|
101
|
+
},
|
|
97
102
|
};
|
|
98
103
|
}
|
|
99
104
|
withdraw({ amount, userAddress }) {
|
package/lib/esm/errors.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export
|
|
2
|
-
export {
|
|
1
|
+
export { BlueErrors, IncompleteChainRegistryError, InvalidMarketParamsError, UnknownAddressError, UnknownDataError, UnknownFactory, UnknownMarketParamsError, UnknownOfFactory, UnknownTokenError, UnknownTokenPriceError, UnknownVaultConfigError, UnsupportedChainIdError, UnsupportedPreLiquidationParamsError, UnsupportedVaultV2AdapterError, VaultV2Errors, } from "@morpho-org/blue-sdk";
|
|
2
|
+
export type { ErrorClass } from "@morpho-org/morpho-ts";
|
|
3
|
+
export { _try } from "@morpho-org/morpho-ts";
|
package/lib/esm/errors.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { BlueErrors, IncompleteChainRegistryError, InvalidMarketParamsError, UnknownAddressError, UnknownDataError, UnknownFactory, UnknownMarketParamsError, UnknownOfFactory, UnknownTokenError, UnknownTokenPriceError, UnknownVaultConfigError, UnsupportedChainIdError, UnsupportedPreLiquidationParamsError, UnsupportedVaultV2AdapterError, VaultV2Errors, } from "@morpho-org/blue-sdk";
|
|
2
|
+
export { _try } from "@morpho-org/morpho-ts";
|
|
@@ -2,13 +2,13 @@ import { type AccrualPosition, type MarketId } from "@morpho-org/blue-sdk";
|
|
|
2
2
|
import { type Address } from "viem";
|
|
3
3
|
import { type VaultReallocation } from "../types/index.js";
|
|
4
4
|
/** @internal */
|
|
5
|
-
export declare const compareMarketIds: (idA: MarketId, idB: MarketId) =>
|
|
5
|
+
export declare const compareMarketIds: (idA: MarketId, idB: MarketId) => 1 | 0 | -1;
|
|
6
6
|
/**
|
|
7
7
|
* Asserts that the client has a connected account AND that it matches
|
|
8
8
|
* the provided user address.
|
|
9
9
|
*
|
|
10
10
|
* Used internally by the signature requirements (`encodeErc20Permit`,
|
|
11
|
-
* `
|
|
11
|
+
* `encodeErc20Permit2Approve`) to enforce builder = signer at `sign()` time:
|
|
12
12
|
* the signing flow is the only path where an account/address mismatch
|
|
13
13
|
* is a real security concern (rather than just an integrator footgun).
|
|
14
14
|
*
|
|
@@ -18,7 +18,7 @@ export const compareMarketIds = (idA, idB) => {
|
|
|
18
18
|
* the provided user address.
|
|
19
19
|
*
|
|
20
20
|
* Used internally by the signature requirements (`encodeErc20Permit`,
|
|
21
|
-
* `
|
|
21
|
+
* `encodeErc20Permit2Approve`) to enforce builder = signer at `sign()` time:
|
|
22
22
|
* the signing flow is the only path where an account/address mismatch
|
|
23
23
|
* is a real security concern (rather than just an integrator footgun).
|
|
24
24
|
*
|
|
@@ -180,12 +180,13 @@ export type AssetsOrSharesArgs = {
|
|
|
180
180
|
};
|
|
181
181
|
/** @deprecated Use {@link AssetsOrSharesArgs}. Kept as an alias for back-compat. */
|
|
182
182
|
export type RepayAmountArgs = AssetsOrSharesArgs;
|
|
183
|
-
|
|
183
|
+
/** Metadata for a Blue authorization prerequisite transaction. */
|
|
184
|
+
export interface BlueAuthorizationAction extends BaseAction<"blueAuthorization", {
|
|
184
185
|
authorized: Address;
|
|
185
186
|
isAuthorized: boolean;
|
|
186
187
|
}> {
|
|
187
188
|
}
|
|
188
|
-
export type TransactionAction = ERC20ApprovalAction | VaultV2DepositAction | VaultV2WithdrawAction | VaultV2RedeemAction | VaultV2ForceWithdrawAction | VaultV2ForceRedeemAction | VaultV1DepositAction | VaultV1WithdrawAction | VaultV1RedeemAction | VaultV1MigrateToV2Action | BlueSupplyAction | BlueWithdrawAction | BlueSupplyCollateralAction | BlueBorrowAction | BlueSupplyCollateralBorrowAction | BlueRepayAction | BlueWithdrawCollateralAction | BlueRepayWithdrawCollateralAction | BlueRefinanceAction |
|
|
189
|
+
export type TransactionAction = ERC20ApprovalAction | VaultV2DepositAction | VaultV2WithdrawAction | VaultV2RedeemAction | VaultV2ForceWithdrawAction | VaultV2ForceRedeemAction | VaultV1DepositAction | VaultV1WithdrawAction | VaultV1RedeemAction | VaultV1MigrateToV2Action | BlueSupplyAction | BlueWithdrawAction | BlueSupplyCollateralAction | BlueBorrowAction | BlueSupplyCollateralBorrowAction | BlueRepayAction | BlueWithdrawCollateralAction | BlueRepayWithdrawCollateralAction | BlueRefinanceAction | BlueAuthorizationAction;
|
|
189
190
|
export interface Transaction<TAction extends BaseAction = TransactionAction> {
|
|
190
191
|
readonly to: Address;
|
|
191
192
|
readonly value: bigint;
|
|
@@ -223,9 +224,36 @@ export interface Permit2Args {
|
|
|
223
224
|
deadline: bigint;
|
|
224
225
|
expiration: bigint;
|
|
225
226
|
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
227
|
+
/**
|
|
228
|
+
* Signed Morpho Blue authorization payload produced when an integrator opts into offchain
|
|
229
|
+
* signatures (`supportSignature: true`). Consumed by the action layer to emit a
|
|
230
|
+
* `setAuthorizationWithSig` bundler call in place of a standalone `setAuthorization` transaction.
|
|
231
|
+
*/
|
|
232
|
+
export interface AuthorizationSignatureArgs {
|
|
233
|
+
/** Account granting the authorization (the position owner). */
|
|
234
|
+
owner: Address;
|
|
235
|
+
/** Account being authorized to operate on Morpho on the owner's behalf (GeneralAdapter1). */
|
|
236
|
+
authorized: Address;
|
|
237
|
+
/** Whether the authorization is granted (`true`) or revoked (`false`). */
|
|
238
|
+
isAuthorized: boolean;
|
|
239
|
+
/** Morpho authorization nonce consumed by the signature. */
|
|
240
|
+
nonce: bigint;
|
|
241
|
+
/** Signature deadline timestamp in seconds. */
|
|
242
|
+
deadline: bigint;
|
|
243
|
+
/** EIP-712 signature over the Morpho `Authorization` typed data. */
|
|
244
|
+
signature: Hex;
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* A signable approval / authorization requirement. `sign()` returns the matching
|
|
248
|
+
* {@link RequirementSignature}; `action` describes the requirement without signing.
|
|
249
|
+
*
|
|
250
|
+
* Generic over the signature it produces so permit encoders narrow to
|
|
251
|
+
* {@link PermitRequirementSignature} and the authorization encoder to
|
|
252
|
+
* {@link AuthorizationRequirementSignature}; the default keeps the broad union for mixed arrays.
|
|
253
|
+
*/
|
|
254
|
+
export interface Requirement<TSignature extends RequirementSignature = RequirementSignature> {
|
|
255
|
+
sign: (client: WalletClient, userAddress: Address) => Promise<TSignature>;
|
|
256
|
+
action: TSignature["action"];
|
|
229
257
|
}
|
|
230
258
|
export interface PermitAction extends BaseAction<"permit", {
|
|
231
259
|
spender: Address;
|
|
@@ -240,10 +268,86 @@ export interface Permit2Action extends BaseAction<"permit2", {
|
|
|
240
268
|
expiration: bigint;
|
|
241
269
|
}> {
|
|
242
270
|
}
|
|
243
|
-
|
|
271
|
+
/**
|
|
272
|
+
* Signable Morpho authorization requirement. Emitted by the entity layer when a bundled path
|
|
273
|
+
* needs GeneralAdapter1 authorized and the client opts into offchain signatures.
|
|
274
|
+
*/
|
|
275
|
+
export interface AuthorizationAction extends BaseAction<"authorization", {
|
|
276
|
+
authorized: Address;
|
|
277
|
+
isAuthorized: boolean;
|
|
278
|
+
deadline: bigint;
|
|
279
|
+
}> {
|
|
280
|
+
}
|
|
281
|
+
/** A signed ERC-2612 permit or Permit2 approval requirement. */
|
|
282
|
+
export interface PermitRequirementSignature {
|
|
244
283
|
args: PermitArgs | Permit2Args;
|
|
245
284
|
action: PermitAction | Permit2Action;
|
|
246
285
|
}
|
|
247
|
-
|
|
248
|
-
export
|
|
249
|
-
|
|
286
|
+
/** A signed Morpho authorization requirement (consumed via `setAuthorizationWithSig`). */
|
|
287
|
+
export interface AuthorizationRequirementSignature {
|
|
288
|
+
args: AuthorizationSignatureArgs;
|
|
289
|
+
action: AuthorizationAction;
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* The deep-frozen output of `Requirement.sign()`. Discriminated on `action.type`:
|
|
293
|
+
* `"permit"` / `"permit2"` carry token-approval args, `"authorization"` carries the signed
|
|
294
|
+
* Morpho authorization. Narrow with {@link isPermitSignature} / {@link isAuthorizationSignature}.
|
|
295
|
+
*/
|
|
296
|
+
export type RequirementSignature = PermitRequirementSignature | AuthorizationRequirementSignature;
|
|
297
|
+
/** Bundler3 token signature requirement. */
|
|
298
|
+
export type Bundler3TokenSignatureRequirement = Requirement<PermitRequirementSignature>;
|
|
299
|
+
export declare function isRequirementApproval(requirement: unknown): requirement is Transaction<ERC20ApprovalAction>;
|
|
300
|
+
/** Checks whether an action requirement is a Blue authorization transaction. */
|
|
301
|
+
export declare function isRequirementBlueAuthorization(requirement: unknown): requirement is Transaction<BlueAuthorizationAction>;
|
|
302
|
+
export declare function isRequirementSignature<T extends RequirementSignature = RequirementSignature>(requirement: Transaction<ERC20ApprovalAction> | Transaction<BlueAuthorizationAction> | Requirement<T> | undefined): requirement is Requirement<T>;
|
|
303
|
+
/**
|
|
304
|
+
* Narrows a {@link RequirementSignature} to a permit / Permit2 token-approval signature.
|
|
305
|
+
*
|
|
306
|
+
* @param signature - The signed requirement to test.
|
|
307
|
+
* @returns `true` when `signature.action.type` is `"permit"` or `"permit2"`.
|
|
308
|
+
*/
|
|
309
|
+
export declare function isPermitSignature(signature: RequirementSignature): signature is PermitRequirementSignature;
|
|
310
|
+
/**
|
|
311
|
+
* Narrows a {@link RequirementSignature} to a signed Morpho authorization.
|
|
312
|
+
*
|
|
313
|
+
* @param signature - The signed requirement to test.
|
|
314
|
+
* @returns `true` when `signature.action.type` is `"authorization"`.
|
|
315
|
+
*/
|
|
316
|
+
export declare function isAuthorizationSignature(signature: RequirementSignature): signature is AuthorizationRequirementSignature;
|
|
317
|
+
/** The typed permit / authorization slots a bundled path consumes, split from a `buildTx` array. */
|
|
318
|
+
export interface SelectedRequirementSignatures {
|
|
319
|
+
/** The single permit / Permit2 signature, when present. */
|
|
320
|
+
permit?: PermitRequirementSignature;
|
|
321
|
+
/** The single Morpho authorization signature, when present. */
|
|
322
|
+
authorization?: AuthorizationRequirementSignature;
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Splits a `buildTx` signature array into its typed permit / authorization slots, rejecting
|
|
326
|
+
* ambiguous or unexpected input so a path never silently consumes the wrong signature.
|
|
327
|
+
*
|
|
328
|
+
* A bundled path consumes at most one permit and one authorization signature. Passing several of
|
|
329
|
+
* the same kind, or a kind the path does not consume, is rejected with a typed error rather than
|
|
330
|
+
* silently dropping the extras — the latter could otherwise leave a required authorization or
|
|
331
|
+
* permit unsigned (and the bundle reverting on-chain) or apply the wrong signature.
|
|
332
|
+
*
|
|
333
|
+
* @param signatures - The signatures passed to `buildTx`.
|
|
334
|
+
* @param accepts - Which signature kinds this operation consumes.
|
|
335
|
+
* @param accepts.permit - Whether a permit / Permit2 signature is consumed.
|
|
336
|
+
* @param accepts.authorization - Whether a Morpho authorization signature is consumed.
|
|
337
|
+
* @returns The single permit and/or authorization signature, when present.
|
|
338
|
+
* @throws {AmbiguousRequirementSignaturesError} when more than one signature of an accepted kind is present.
|
|
339
|
+
* @throws {UnexpectedRequirementSignatureError} when a signature of a kind the operation does not consume is present.
|
|
340
|
+
* @example
|
|
341
|
+
* ```ts
|
|
342
|
+
* import { selectRequirementSignatures } from "@morpho-org/morpho-sdk";
|
|
343
|
+
*
|
|
344
|
+
* const { permit, authorization } = selectRequirementSignatures(signatures, {
|
|
345
|
+
* permit: true,
|
|
346
|
+
* authorization: true,
|
|
347
|
+
* });
|
|
348
|
+
* ```
|
|
349
|
+
*/
|
|
350
|
+
export declare function selectRequirementSignatures(signatures: readonly RequirementSignature[] | undefined, accepts: {
|
|
351
|
+
permit?: boolean;
|
|
352
|
+
authorization?: boolean;
|
|
353
|
+
}): SelectedRequirementSignatures;
|
package/lib/esm/types/action.js
CHANGED
|
@@ -1,21 +1,92 @@
|
|
|
1
|
+
import { AmbiguousRequirementSignaturesError, UnexpectedRequirementSignatureError, } from "./error.js";
|
|
1
2
|
export function isRequirementApproval(requirement) {
|
|
2
|
-
return (requirement
|
|
3
|
+
return (typeof requirement === "object" &&
|
|
4
|
+
requirement !== null &&
|
|
3
5
|
"to" in requirement &&
|
|
4
6
|
"value" in requirement &&
|
|
5
7
|
"data" in requirement &&
|
|
6
8
|
"action" in requirement &&
|
|
9
|
+
typeof requirement.action === "object" &&
|
|
10
|
+
requirement.action !== null &&
|
|
11
|
+
"type" in requirement.action &&
|
|
7
12
|
requirement.action.type === "erc20Approval");
|
|
8
13
|
}
|
|
9
|
-
|
|
10
|
-
|
|
14
|
+
/** Checks whether an action requirement is a Blue authorization transaction. */
|
|
15
|
+
export function isRequirementBlueAuthorization(requirement) {
|
|
16
|
+
return (typeof requirement === "object" &&
|
|
17
|
+
requirement !== null &&
|
|
11
18
|
"to" in requirement &&
|
|
12
19
|
"value" in requirement &&
|
|
13
20
|
"data" in requirement &&
|
|
14
21
|
"action" in requirement &&
|
|
15
|
-
requirement.action
|
|
22
|
+
typeof requirement.action === "object" &&
|
|
23
|
+
requirement.action !== null &&
|
|
24
|
+
"type" in requirement.action &&
|
|
25
|
+
requirement.action.type === "blueAuthorization");
|
|
16
26
|
}
|
|
17
27
|
export function isRequirementSignature(requirement) {
|
|
18
28
|
return (requirement !== undefined &&
|
|
29
|
+
typeof requirement === "object" &&
|
|
30
|
+
requirement !== null &&
|
|
19
31
|
"sign" in requirement &&
|
|
20
32
|
typeof requirement.sign === "function");
|
|
21
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* Narrows a {@link RequirementSignature} to a permit / Permit2 token-approval signature.
|
|
36
|
+
*
|
|
37
|
+
* @param signature - The signed requirement to test.
|
|
38
|
+
* @returns `true` when `signature.action.type` is `"permit"` or `"permit2"`.
|
|
39
|
+
*/
|
|
40
|
+
export function isPermitSignature(signature) {
|
|
41
|
+
return (signature.action.type === "permit" || signature.action.type === "permit2");
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Narrows a {@link RequirementSignature} to a signed Morpho authorization.
|
|
45
|
+
*
|
|
46
|
+
* @param signature - The signed requirement to test.
|
|
47
|
+
* @returns `true` when `signature.action.type` is `"authorization"`.
|
|
48
|
+
*/
|
|
49
|
+
export function isAuthorizationSignature(signature) {
|
|
50
|
+
return signature.action.type === "authorization";
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Splits a `buildTx` signature array into its typed permit / authorization slots, rejecting
|
|
54
|
+
* ambiguous or unexpected input so a path never silently consumes the wrong signature.
|
|
55
|
+
*
|
|
56
|
+
* A bundled path consumes at most one permit and one authorization signature. Passing several of
|
|
57
|
+
* the same kind, or a kind the path does not consume, is rejected with a typed error rather than
|
|
58
|
+
* silently dropping the extras — the latter could otherwise leave a required authorization or
|
|
59
|
+
* permit unsigned (and the bundle reverting on-chain) or apply the wrong signature.
|
|
60
|
+
*
|
|
61
|
+
* @param signatures - The signatures passed to `buildTx`.
|
|
62
|
+
* @param accepts - Which signature kinds this operation consumes.
|
|
63
|
+
* @param accepts.permit - Whether a permit / Permit2 signature is consumed.
|
|
64
|
+
* @param accepts.authorization - Whether a Morpho authorization signature is consumed.
|
|
65
|
+
* @returns The single permit and/or authorization signature, when present.
|
|
66
|
+
* @throws {AmbiguousRequirementSignaturesError} when more than one signature of an accepted kind is present.
|
|
67
|
+
* @throws {UnexpectedRequirementSignatureError} when a signature of a kind the operation does not consume is present.
|
|
68
|
+
* @example
|
|
69
|
+
* ```ts
|
|
70
|
+
* import { selectRequirementSignatures } from "@morpho-org/morpho-sdk";
|
|
71
|
+
*
|
|
72
|
+
* const { permit, authorization } = selectRequirementSignatures(signatures, {
|
|
73
|
+
* permit: true,
|
|
74
|
+
* authorization: true,
|
|
75
|
+
* });
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
export function selectRequirementSignatures(signatures, accepts) {
|
|
79
|
+
if (signatures == null)
|
|
80
|
+
return {};
|
|
81
|
+
const permits = signatures.filter(isPermitSignature);
|
|
82
|
+
const authorizations = signatures.filter(isAuthorizationSignature);
|
|
83
|
+
if (!accepts.permit && permits.length > 0)
|
|
84
|
+
throw new UnexpectedRequirementSignatureError("permit");
|
|
85
|
+
if (!accepts.authorization && authorizations.length > 0)
|
|
86
|
+
throw new UnexpectedRequirementSignatureError("authorization");
|
|
87
|
+
if (permits.length > 1)
|
|
88
|
+
throw new AmbiguousRequirementSignaturesError("permit", permits.length);
|
|
89
|
+
if (authorizations.length > 1)
|
|
90
|
+
throw new AmbiguousRequirementSignaturesError("authorization", authorizations.length);
|
|
91
|
+
return { permit: permits[0], authorization: authorizations[0] };
|
|
92
|
+
}
|
package/lib/esm/types/error.d.ts
CHANGED
|
@@ -43,6 +43,67 @@ export declare namespace BundlerErrors {
|
|
|
43
43
|
*/
|
|
44
44
|
constructor(type: string, chainId: number);
|
|
45
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* Thrown when a Morpho authorization signature names a forbidden `authorized` account
|
|
48
|
+
* (for example Bundler3 itself), which would grant operator rights to an unintended address.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* import { BundlerErrors } from "@morpho-org/morpho-sdk";
|
|
53
|
+
*
|
|
54
|
+
* if (error instanceof BundlerErrors.UnexpectedSignature) {
|
|
55
|
+
* // Re-sign the authorization targeting GeneralAdapter1.
|
|
56
|
+
* }
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
class UnexpectedSignature extends Error {
|
|
60
|
+
/**
|
|
61
|
+
* @param authorized - The forbidden `authorized` address carried by the signature.
|
|
62
|
+
*/
|
|
63
|
+
constructor(authorized: Address);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Thrown when `buildTx` receives more than one requirement signature of the same kind.
|
|
68
|
+
*
|
|
69
|
+
* A bundled path consumes at most one permit and one authorization signature; passing several of
|
|
70
|
+
* the same kind is ambiguous and would silently drop all but the first, so it is rejected instead.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```ts
|
|
74
|
+
* import { AmbiguousRequirementSignaturesError } from "@morpho-org/morpho-sdk";
|
|
75
|
+
*
|
|
76
|
+
* if (error instanceof AmbiguousRequirementSignaturesError) {
|
|
77
|
+
* // Pass a single permit (and at most one authorization) signature to buildTx.
|
|
78
|
+
* }
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
export declare class AmbiguousRequirementSignaturesError extends Error {
|
|
82
|
+
/**
|
|
83
|
+
* @param kind - The over-supplied signature kind (`"permit"` or `"authorization"`).
|
|
84
|
+
* @param count - How many signatures of that kind were received.
|
|
85
|
+
*/
|
|
86
|
+
constructor(kind: "permit" | "authorization", count: number);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Thrown when `buildTx` receives a requirement signature of a kind the operation does not consume
|
|
90
|
+
* (for example an authorization signature on a plain supply path). Surfacing it prevents a signed
|
|
91
|
+
* authorization or permit from being silently ignored.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```ts
|
|
95
|
+
* import { UnexpectedRequirementSignatureError } from "@morpho-org/morpho-sdk";
|
|
96
|
+
*
|
|
97
|
+
* if (error instanceof UnexpectedRequirementSignatureError) {
|
|
98
|
+
* // Remove the signature this operation does not use from the buildTx array.
|
|
99
|
+
* }
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
export declare class UnexpectedRequirementSignatureError extends Error {
|
|
103
|
+
/**
|
|
104
|
+
* @param kind - The unexpected signature kind (`"permit"` or `"authorization"`).
|
|
105
|
+
*/
|
|
106
|
+
constructor(kind: "permit" | "authorization");
|
|
46
107
|
}
|
|
47
108
|
/** Thrown when an asset amount is required to be positive but is zero or negative. */
|
|
48
109
|
export declare class NonPositiveAssetAmountError extends Error {
|
|
@@ -72,6 +133,18 @@ export declare class MissingClientPropertyError extends Error {
|
|
|
72
133
|
export declare class ApprovalAmountLessThanSpendAmountError extends Error {
|
|
73
134
|
constructor();
|
|
74
135
|
}
|
|
136
|
+
/** Thrown when a requirement encoder targets an unsupported spender. */
|
|
137
|
+
export declare class UnsupportedErc20ApprovalSpenderError extends Error {
|
|
138
|
+
constructor(params: {
|
|
139
|
+
readonly spender: Address;
|
|
140
|
+
readonly chainId: number;
|
|
141
|
+
readonly generalAdapter1: Address;
|
|
142
|
+
readonly permit2?: Address;
|
|
143
|
+
readonly midnight?: Address;
|
|
144
|
+
readonly midnightBundles?: Address;
|
|
145
|
+
readonly supportedSpenders?: readonly (Address | undefined)[];
|
|
146
|
+
});
|
|
147
|
+
}
|
|
75
148
|
/** Thrown when a slippage tolerance is negative. */
|
|
76
149
|
export declare class NegativeSlippageToleranceError extends Error {
|
|
77
150
|
constructor(slippageTolerance: bigint);
|