@morpho-org/morpho-sdk 1.1.0 → 1.2.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/LICENSE +2 -2
- package/README.md +31 -33
- package/lib/cjs/actions/index.d.ts +4 -0
- package/lib/{actions → cjs/actions}/index.js +4 -4
- package/lib/cjs/actions/marketV1/borrow.d.ts +69 -0
- package/lib/cjs/actions/marketV1/borrow.js +97 -0
- package/lib/cjs/actions/marketV1/buildReallocationActions.d.ts +28 -0
- package/lib/cjs/actions/marketV1/buildReallocationActions.js +47 -0
- package/lib/cjs/actions/marketV1/index.d.ts +6 -0
- package/lib/{actions → cjs/actions}/marketV1/index.js +6 -6
- package/lib/cjs/actions/marketV1/repay.d.ts +89 -0
- package/lib/cjs/actions/marketV1/repay.js +134 -0
- package/lib/cjs/actions/marketV1/repayWithdrawCollateral.d.ts +103 -0
- package/lib/cjs/actions/marketV1/repayWithdrawCollateral.js +155 -0
- package/lib/cjs/actions/marketV1/supplyCollateral.d.ts +59 -0
- package/lib/cjs/actions/marketV1/supplyCollateral.js +116 -0
- package/lib/cjs/actions/marketV1/supplyCollateralBorrow.d.ts +91 -0
- package/lib/cjs/actions/marketV1/supplyCollateralBorrow.js +163 -0
- package/lib/cjs/actions/marketV1/withdrawCollateral.d.ts +49 -0
- package/lib/cjs/actions/marketV1/withdrawCollateral.js +72 -0
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +36 -0
- package/lib/{actions → cjs/actions}/requirements/encode/encodeErc20Approval.js +25 -0
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +52 -0
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +108 -0
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2.d.ts +44 -0
- package/lib/{actions → cjs/actions}/requirements/encode/encodeErc20Permit2.js +36 -4
- package/lib/cjs/actions/requirements/encode/index.d.ts +3 -0
- package/lib/{actions → cjs/actions}/requirements/encode/index.js +3 -3
- package/lib/cjs/actions/requirements/getMorphoAuthorizationRequirement.d.ts +37 -0
- package/lib/cjs/actions/requirements/getMorphoAuthorizationRequirement.js +71 -0
- package/lib/cjs/actions/requirements/getRequirements.d.ts +74 -0
- package/lib/cjs/actions/requirements/getRequirements.js +112 -0
- package/lib/cjs/actions/requirements/getRequirementsAction.d.ts +33 -0
- package/lib/{actions → cjs/actions}/requirements/getRequirementsAction.js +20 -4
- package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +43 -0
- package/lib/cjs/actions/requirements/getRequirementsApproval.js +63 -0
- package/lib/cjs/actions/requirements/getRequirementsPermit.d.ts +45 -0
- package/lib/cjs/actions/requirements/getRequirementsPermit.js +57 -0
- package/lib/cjs/actions/requirements/getRequirementsPermit2.d.ts +63 -0
- package/lib/cjs/actions/requirements/getRequirementsPermit2.js +85 -0
- package/lib/cjs/actions/requirements/index.d.ts +6 -0
- package/lib/{actions → cjs/actions}/requirements/index.js +6 -6
- package/lib/cjs/actions/vaultV1/deposit.d.ts +72 -0
- package/lib/cjs/actions/vaultV1/deposit.js +146 -0
- package/lib/cjs/actions/vaultV1/index.d.ts +4 -0
- package/lib/{actions → cjs/actions}/vaultV1/index.js +4 -4
- package/lib/cjs/actions/vaultV1/migrateToV2.d.ts +84 -0
- package/lib/cjs/actions/vaultV1/migrateToV2.js +143 -0
- package/lib/cjs/actions/vaultV1/redeem.d.ts +39 -0
- package/lib/cjs/actions/vaultV1/redeem.js +57 -0
- package/lib/cjs/actions/vaultV1/withdraw.d.ts +39 -0
- package/lib/cjs/actions/vaultV1/withdraw.js +57 -0
- package/lib/cjs/actions/vaultV2/deposit.d.ts +72 -0
- package/lib/cjs/actions/vaultV2/deposit.js +146 -0
- package/lib/cjs/actions/vaultV2/forceRedeem.d.ts +63 -0
- package/lib/cjs/actions/vaultV2/forceRedeem.js +99 -0
- package/lib/cjs/actions/vaultV2/forceWithdraw.d.ts +58 -0
- package/lib/cjs/actions/vaultV2/forceWithdraw.js +94 -0
- package/lib/cjs/actions/vaultV2/index.d.ts +5 -0
- package/lib/{actions → cjs/actions}/vaultV2/index.js +5 -5
- package/lib/cjs/actions/vaultV2/redeem.d.ts +40 -0
- package/lib/cjs/actions/vaultV2/redeem.js +58 -0
- package/lib/cjs/actions/vaultV2/withdraw.d.ts +40 -0
- package/lib/cjs/actions/vaultV2/withdraw.js +58 -0
- package/lib/cjs/client/index.d.ts +2 -0
- package/lib/{client → cjs/client}/index.js +2 -2
- package/lib/cjs/client/morphoClient.d.ts +113 -0
- package/lib/cjs/client/morphoClient.js +123 -0
- package/lib/cjs/client/morphoViemExtension.d.ts +45 -0
- package/lib/cjs/client/morphoViemExtension.js +46 -0
- package/lib/cjs/entities/index.d.ts +3 -0
- package/lib/{entities → cjs/entities}/index.js +3 -3
- package/lib/cjs/entities/marketV1/index.d.ts +1 -0
- package/lib/{entities/vaultV1 → cjs/entities/marketV1}/index.js +1 -1
- package/lib/{entities → cjs/entities}/marketV1/marketV1.d.ts +9 -6
- package/lib/{entities → cjs/entities}/marketV1/marketV1.js +89 -87
- package/lib/cjs/entities/vaultV1/index.d.ts +1 -0
- package/lib/{entities/marketV1 → cjs/entities/vaultV1}/index.js +1 -1
- package/lib/{entities → cjs/entities}/vaultV1/vaultV1.d.ts +4 -8
- package/lib/{entities → cjs/entities}/vaultV1/vaultV1.js +39 -35
- package/lib/cjs/entities/vaultV2/index.d.ts +1 -0
- package/lib/{entities → cjs/entities}/vaultV2/index.js +1 -1
- package/lib/{entities → cjs/entities}/vaultV2/vaultV2.d.ts +2 -2
- package/lib/{entities → cjs/entities}/vaultV2/vaultV2.js +25 -24
- package/lib/{helpers → cjs/helpers}/computeReallocations.d.ts +1 -1
- package/lib/{helpers → cjs/helpers}/computeReallocations.js +2 -2
- package/lib/{helpers → cjs/helpers}/encodeDeallocation.d.ts +1 -1
- package/lib/{helpers → cjs/helpers}/encodeDeallocation.js +2 -2
- package/lib/{helpers → cjs/helpers}/index.d.ts +4 -4
- package/lib/{helpers → cjs/helpers}/index.js +19 -19
- package/lib/{helpers → cjs/helpers}/metadata.d.ts +1 -1
- package/lib/{helpers → cjs/helpers}/slippage.js +7 -7
- package/lib/{helpers → cjs/helpers}/validate.d.ts +1 -1
- package/lib/{helpers → cjs/helpers}/validate.js +33 -33
- package/lib/cjs/index.d.ts +5 -0
- package/lib/cjs/index.js +21 -0
- package/lib/cjs/package.json +1 -0
- package/lib/{types → cjs/types}/action.d.ts +1 -1
- package/lib/{types → cjs/types}/client.d.ts +6 -2
- package/lib/{types → cjs/types}/error.d.ts +46 -0
- package/lib/{types → cjs/types}/error.js +46 -0
- package/lib/cjs/types/index.d.ts +7 -0
- package/lib/cjs/types/index.js +23 -0
- package/lib/esm/actions/index.d.ts +4 -0
- package/lib/esm/actions/index.js +4 -0
- package/lib/esm/actions/marketV1/borrow.d.ts +69 -0
- package/lib/esm/actions/marketV1/borrow.js +93 -0
- package/lib/esm/actions/marketV1/buildReallocationActions.d.ts +28 -0
- package/lib/esm/actions/marketV1/buildReallocationActions.js +43 -0
- package/lib/esm/actions/marketV1/index.d.ts +6 -0
- package/lib/esm/actions/marketV1/index.js +6 -0
- package/lib/esm/actions/marketV1/repay.d.ts +89 -0
- package/lib/esm/actions/marketV1/repay.js +130 -0
- package/lib/esm/actions/marketV1/repayWithdrawCollateral.d.ts +103 -0
- package/lib/esm/actions/marketV1/repayWithdrawCollateral.js +151 -0
- package/lib/esm/actions/marketV1/supplyCollateral.d.ts +59 -0
- package/lib/esm/actions/marketV1/supplyCollateral.js +112 -0
- package/lib/esm/actions/marketV1/supplyCollateralBorrow.d.ts +91 -0
- package/lib/esm/actions/marketV1/supplyCollateralBorrow.js +159 -0
- package/lib/esm/actions/marketV1/withdrawCollateral.d.ts +49 -0
- package/lib/esm/actions/marketV1/withdrawCollateral.js +68 -0
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +36 -0
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +46 -0
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +52 -0
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +104 -0
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2.d.ts +44 -0
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2.js +98 -0
- package/lib/esm/actions/requirements/encode/index.d.ts +3 -0
- package/lib/esm/actions/requirements/encode/index.js +3 -0
- package/lib/esm/actions/requirements/getMorphoAuthorizationRequirement.d.ts +37 -0
- package/lib/esm/actions/requirements/getMorphoAuthorizationRequirement.js +67 -0
- package/lib/esm/actions/requirements/getRequirements.d.ts +74 -0
- package/lib/esm/actions/requirements/getRequirements.js +108 -0
- package/lib/esm/actions/requirements/getRequirementsAction.d.ts +33 -0
- package/lib/esm/actions/requirements/getRequirementsAction.js +76 -0
- package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +43 -0
- package/lib/esm/actions/requirements/getRequirementsApproval.js +59 -0
- package/lib/esm/actions/requirements/getRequirementsPermit.d.ts +45 -0
- package/lib/esm/actions/requirements/getRequirementsPermit.js +53 -0
- package/lib/esm/actions/requirements/getRequirementsPermit2.d.ts +63 -0
- package/lib/esm/actions/requirements/getRequirementsPermit2.js +81 -0
- package/lib/esm/actions/requirements/index.d.ts +6 -0
- package/lib/esm/actions/requirements/index.js +6 -0
- package/lib/esm/actions/vaultV1/deposit.d.ts +72 -0
- package/lib/esm/actions/vaultV1/deposit.js +142 -0
- package/lib/esm/actions/vaultV1/index.d.ts +4 -0
- package/lib/esm/actions/vaultV1/index.js +4 -0
- package/lib/esm/actions/vaultV1/migrateToV2.d.ts +84 -0
- package/lib/esm/actions/vaultV1/migrateToV2.js +139 -0
- package/lib/esm/actions/vaultV1/redeem.d.ts +39 -0
- package/lib/esm/actions/vaultV1/redeem.js +53 -0
- package/lib/esm/actions/vaultV1/withdraw.d.ts +39 -0
- package/lib/esm/actions/vaultV1/withdraw.js +53 -0
- package/lib/esm/actions/vaultV2/deposit.d.ts +72 -0
- package/lib/esm/actions/vaultV2/deposit.js +142 -0
- package/lib/esm/actions/vaultV2/forceRedeem.d.ts +63 -0
- package/lib/esm/actions/vaultV2/forceRedeem.js +95 -0
- package/lib/esm/actions/vaultV2/forceWithdraw.d.ts +58 -0
- package/lib/esm/actions/vaultV2/forceWithdraw.js +90 -0
- package/lib/esm/actions/vaultV2/index.d.ts +5 -0
- package/lib/esm/actions/vaultV2/index.js +5 -0
- package/lib/esm/actions/vaultV2/redeem.d.ts +40 -0
- package/lib/esm/actions/vaultV2/redeem.js +54 -0
- package/lib/esm/actions/vaultV2/withdraw.d.ts +40 -0
- package/lib/esm/actions/vaultV2/withdraw.js +54 -0
- package/lib/esm/client/index.d.ts +2 -0
- package/lib/esm/client/index.js +2 -0
- package/lib/esm/client/morphoClient.d.ts +113 -0
- package/lib/esm/client/morphoClient.js +119 -0
- package/lib/esm/client/morphoViemExtension.d.ts +45 -0
- package/lib/esm/client/morphoViemExtension.js +43 -0
- package/lib/esm/entities/index.d.ts +3 -0
- package/lib/esm/entities/index.js +3 -0
- package/lib/esm/entities/marketV1/index.d.ts +1 -0
- package/lib/esm/entities/marketV1/index.js +1 -0
- package/lib/esm/entities/marketV1/marketV1.d.ts +293 -0
- package/lib/esm/entities/marketV1/marketV1.js +529 -0
- package/lib/esm/entities/vaultV1/index.d.ts +1 -0
- package/lib/esm/entities/vaultV1/index.js +1 -0
- package/lib/esm/entities/vaultV1/vaultV1.d.ts +129 -0
- package/lib/esm/entities/vaultV1/vaultV1.js +186 -0
- package/lib/esm/entities/vaultV2/index.d.ts +1 -0
- package/lib/esm/entities/vaultV2/index.js +1 -0
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +180 -0
- package/lib/esm/entities/vaultV2/vaultV2.js +164 -0
- package/lib/esm/helpers/computeReallocations.d.ts +23 -0
- package/lib/esm/helpers/computeReallocations.js +94 -0
- package/lib/esm/helpers/constant.d.ts +6 -0
- package/lib/esm/helpers/constant.js +7 -0
- package/lib/esm/helpers/encodeDeallocation.d.ts +10 -0
- package/lib/esm/helpers/encodeDeallocation.js +34 -0
- package/lib/esm/helpers/index.d.ts +4 -0
- package/lib/esm/helpers/index.js +4 -0
- package/lib/esm/helpers/metadata.d.ts +33 -0
- package/lib/esm/helpers/metadata.js +46 -0
- package/lib/esm/helpers/slippage.d.ts +46 -0
- package/lib/esm/helpers/slippage.js +69 -0
- package/lib/esm/helpers/validate.d.ts +156 -0
- package/lib/esm/helpers/validate.js +273 -0
- package/lib/esm/index.d.ts +5 -0
- package/lib/esm/index.js +5 -0
- package/lib/esm/package.json +1 -0
- package/lib/esm/types/action.d.ts +216 -0
- package/lib/esm/types/action.js +21 -0
- package/lib/esm/types/client.d.ts +19 -0
- package/lib/esm/types/client.js +1 -0
- package/lib/esm/types/data.d.ts +2 -0
- package/lib/esm/types/data.js +1 -0
- package/lib/esm/types/deallocation.d.ts +15 -0
- package/lib/esm/types/deallocation.js +1 -0
- package/lib/esm/types/entity.d.ts +5 -0
- package/lib/esm/types/entity.js +1 -0
- package/lib/esm/types/error.d.ts +205 -0
- package/lib/esm/types/error.js +276 -0
- package/lib/esm/types/index.d.ts +7 -0
- package/lib/esm/types/index.js +7 -0
- package/lib/esm/types/metadata.d.ts +4 -0
- package/lib/esm/types/metadata.js +1 -0
- package/lib/esm/types/sharedLiquidity.d.ts +41 -0
- package/lib/esm/types/sharedLiquidity.js +1 -0
- package/package.json +33 -56
- package/src/index.ts +5 -0
- package/lib/actions/index.d.ts +0 -4
- package/lib/actions/marketV1/borrow.d.ts +0 -34
- package/lib/actions/marketV1/borrow.js +0 -62
- package/lib/actions/marketV1/buildReallocationActions.d.ts +0 -17
- package/lib/actions/marketV1/buildReallocationActions.js +0 -36
- package/lib/actions/marketV1/index.d.ts +0 -6
- package/lib/actions/marketV1/repay.d.ts +0 -44
- package/lib/actions/marketV1/repay.js +0 -93
- package/lib/actions/marketV1/repayWithdrawCollateral.d.ts +0 -51
- package/lib/actions/marketV1/repayWithdrawCollateral.js +0 -108
- package/lib/actions/marketV1/supplyCollateral.d.ts +0 -28
- package/lib/actions/marketV1/supplyCollateral.js +0 -85
- package/lib/actions/marketV1/supplyCollateralBorrow.d.ts +0 -37
- package/lib/actions/marketV1/supplyCollateralBorrow.js +0 -109
- package/lib/actions/marketV1/withdrawCollateral.d.ts +0 -28
- package/lib/actions/marketV1/withdrawCollateral.js +0 -51
- package/lib/actions/requirements/encode/encodeErc20Approval.d.ts +0 -10
- package/lib/actions/requirements/encode/encodeErc20Permit.d.ts +0 -13
- package/lib/actions/requirements/encode/encodeErc20Permit.js +0 -70
- package/lib/actions/requirements/encode/encodeErc20Permit2.d.ts +0 -11
- package/lib/actions/requirements/encode/index.d.ts +0 -3
- package/lib/actions/requirements/getMorphoAuthorizationRequirement.d.ts +0 -21
- package/lib/actions/requirements/getMorphoAuthorizationRequirement.js +0 -55
- package/lib/actions/requirements/getRequirements.d.ts +0 -42
- package/lib/actions/requirements/getRequirements.js +0 -80
- package/lib/actions/requirements/getRequirementsAction.d.ts +0 -17
- package/lib/actions/requirements/getRequirementsApproval.d.ts +0 -31
- package/lib/actions/requirements/getRequirementsApproval.js +0 -51
- package/lib/actions/requirements/getRequirementsPermit.d.ts +0 -28
- package/lib/actions/requirements/getRequirementsPermit.js +0 -40
- package/lib/actions/requirements/getRequirementsPermit2.d.ts +0 -37
- package/lib/actions/requirements/getRequirementsPermit2.js +0 -59
- package/lib/actions/requirements/index.d.ts +0 -6
- package/lib/actions/vaultV1/deposit.d.ts +0 -41
- package/lib/actions/vaultV1/deposit.js +0 -116
- package/lib/actions/vaultV1/index.d.ts +0 -4
- package/lib/actions/vaultV1/migrateToV2.d.ts +0 -50
- package/lib/actions/vaultV1/migrateToV2.js +0 -108
- package/lib/actions/vaultV1/redeem.d.ts +0 -29
- package/lib/actions/vaultV1/redeem.js +0 -48
- package/lib/actions/vaultV1/withdraw.d.ts +0 -29
- package/lib/actions/vaultV1/withdraw.js +0 -48
- package/lib/actions/vaultV2/deposit.d.ts +0 -41
- package/lib/actions/vaultV2/deposit.js +0 -116
- package/lib/actions/vaultV2/forceRedeem.d.ts +0 -48
- package/lib/actions/vaultV2/forceRedeem.js +0 -85
- package/lib/actions/vaultV2/forceWithdraw.d.ts +0 -40
- package/lib/actions/vaultV2/forceWithdraw.js +0 -77
- package/lib/actions/vaultV2/index.d.ts +0 -5
- package/lib/actions/vaultV2/redeem.d.ts +0 -32
- package/lib/actions/vaultV2/redeem.js +0 -51
- package/lib/actions/vaultV2/withdraw.d.ts +0 -32
- package/lib/actions/vaultV2/withdraw.js +0 -51
- package/lib/client/index.d.ts +0 -2
- package/lib/client/morphoClient.d.ts +0 -25
- package/lib/client/morphoClient.js +0 -28
- package/lib/client/morphoViemExtension.d.ts +0 -39
- package/lib/client/morphoViemExtension.js +0 -40
- package/lib/entities/index.d.ts +0 -3
- package/lib/entities/marketV1/index.d.ts +0 -1
- package/lib/entities/vaultV1/index.d.ts +0 -1
- package/lib/entities/vaultV2/index.d.ts +0 -1
- package/lib/index.d.ts +0 -5
- package/lib/index.js +0 -21
- package/lib/types/index.d.ts +0 -7
- package/lib/types/index.js +0 -23
- /package/lib/{helpers → cjs/helpers}/constant.d.ts +0 -0
- /package/lib/{helpers → cjs/helpers}/constant.js +0 -0
- /package/lib/{helpers → cjs/helpers}/metadata.js +0 -0
- /package/lib/{helpers → cjs/helpers}/slippage.d.ts +0 -0
- /package/lib/{types → cjs/types}/action.js +0 -0
- /package/lib/{types → cjs/types}/client.js +0 -0
- /package/lib/{types → cjs/types}/data.d.ts +0 -0
- /package/lib/{types → cjs/types}/data.js +0 -0
- /package/lib/{types → cjs/types}/deallocation.d.ts +0 -0
- /package/lib/{types → cjs/types}/deallocation.js +0 -0
- /package/lib/{types → cjs/types}/entity.d.ts +0 -0
- /package/lib/{types → cjs/types}/entity.js +0 -0
- /package/lib/{types → cjs/types}/metadata.d.ts +0 -0
- /package/lib/{types → cjs/types}/metadata.js +0 -0
- /package/lib/{types → cjs/types}/sharedLiquidity.d.ts +0 -0
- /package/lib/{types → cjs/types}/sharedLiquidity.js +0 -0
|
@@ -4,14 +4,15 @@ exports.MorphoVaultV1 = void 0;
|
|
|
4
4
|
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
5
5
|
const blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
|
|
6
6
|
const viem_1 = require("viem");
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
7
|
+
const index_js_1 = require("../../actions/index.js");
|
|
8
|
+
const constant_js_1 = require("../../helpers/constant.js");
|
|
9
|
+
const index_js_2 = require("../../helpers/index.js");
|
|
10
|
+
const index_js_3 = require("../../types/index.js");
|
|
11
11
|
class MorphoVaultV1 {
|
|
12
12
|
client;
|
|
13
13
|
vault;
|
|
14
14
|
chainId;
|
|
15
|
+
// biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
|
|
15
16
|
constructor(client, vault, chainId) {
|
|
16
17
|
this.client = client;
|
|
17
18
|
this.vault = vault;
|
|
@@ -20,7 +21,7 @@ class MorphoVaultV1 {
|
|
|
20
21
|
async getData(parameters) {
|
|
21
22
|
if (this.client.viemClient.chain?.id &&
|
|
22
23
|
this.client.viemClient.chain?.id !== this.chainId) {
|
|
23
|
-
throw new
|
|
24
|
+
throw new index_js_3.ChainIdMismatchError(this.client.viemClient.chain?.id, this.chainId);
|
|
24
25
|
}
|
|
25
26
|
return (0, blue_sdk_viem_1.fetchAccrualVault)(this.vault, this.client.viemClient, {
|
|
26
27
|
...parameters,
|
|
@@ -30,43 +31,43 @@ class MorphoVaultV1 {
|
|
|
30
31
|
}
|
|
31
32
|
deposit({ amount = 0n, userAddress, accrualVault, slippageTolerance = blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE, nativeAmount, }) {
|
|
32
33
|
if (this.client.viemClient.chain?.id !== this.chainId) {
|
|
33
|
-
throw new
|
|
34
|
+
throw new index_js_3.ChainIdMismatchError(this.client.viemClient.chain?.id, this.chainId);
|
|
34
35
|
}
|
|
35
36
|
if (!(0, viem_1.isAddressEqual)(accrualVault.address, this.vault)) {
|
|
36
|
-
throw new
|
|
37
|
+
throw new index_js_3.VaultAddressMismatchError(this.vault, accrualVault.address);
|
|
37
38
|
}
|
|
38
39
|
if (amount < 0n) {
|
|
39
|
-
throw new
|
|
40
|
+
throw new index_js_3.NonPositiveAssetAmountError(this.vault);
|
|
40
41
|
}
|
|
41
42
|
if (nativeAmount && nativeAmount < 0n) {
|
|
42
|
-
throw new
|
|
43
|
+
throw new index_js_3.NegativeNativeAmountError(nativeAmount);
|
|
43
44
|
}
|
|
44
45
|
let wNative;
|
|
45
46
|
if (nativeAmount) {
|
|
46
47
|
({ wNative } = (0, blue_sdk_1.getChainAddresses)(this.chainId));
|
|
47
48
|
if (!wNative) {
|
|
48
|
-
throw new
|
|
49
|
+
throw new index_js_3.ChainWNativeMissingError(this.chainId);
|
|
49
50
|
}
|
|
50
51
|
}
|
|
51
52
|
if (slippageTolerance < 0n) {
|
|
52
|
-
throw new
|
|
53
|
+
throw new index_js_3.NegativeSlippageToleranceError(slippageTolerance);
|
|
53
54
|
}
|
|
54
|
-
if (slippageTolerance >
|
|
55
|
-
throw new
|
|
55
|
+
if (slippageTolerance > constant_js_1.MAX_SLIPPAGE_TOLERANCE) {
|
|
56
|
+
throw new index_js_3.ExcessiveSlippageToleranceError(slippageTolerance);
|
|
56
57
|
}
|
|
57
58
|
if (nativeAmount && wNative) {
|
|
58
59
|
if (!(0, viem_1.isAddressEqual)(accrualVault.asset, wNative)) {
|
|
59
|
-
throw new
|
|
60
|
+
throw new index_js_3.NativeAmountOnNonWNativeVaultError(accrualVault.asset, wNative);
|
|
60
61
|
}
|
|
61
62
|
}
|
|
62
63
|
const totalAssets = amount + (nativeAmount ?? 0n);
|
|
63
64
|
const shares = accrualVault.toShares(totalAssets);
|
|
64
65
|
if (shares <= 0n) {
|
|
65
|
-
throw new
|
|
66
|
+
throw new index_js_3.NonPositiveSharesAmountError(this.vault);
|
|
66
67
|
}
|
|
67
|
-
const maxSharePrice = blue_sdk_1.MathLib.min(blue_sdk_1.MathLib.mulDivUp(totalAssets, blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD + slippageTolerance), shares),
|
|
68
|
+
const maxSharePrice = blue_sdk_1.MathLib.min(blue_sdk_1.MathLib.mulDivUp(totalAssets, blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD + slippageTolerance), shares), constant_js_1.MAX_ABSOLUTE_SHARE_PRICE);
|
|
68
69
|
return {
|
|
69
|
-
getRequirements: async (params) => await (0,
|
|
70
|
+
getRequirements: async (params) => await (0, index_js_1.getRequirements)(this.client.viemClient, {
|
|
70
71
|
address: accrualVault.asset,
|
|
71
72
|
chainId: this.chainId,
|
|
72
73
|
supportSignature: this.client.options.supportSignature,
|
|
@@ -77,7 +78,7 @@ class MorphoVaultV1 {
|
|
|
77
78
|
from: userAddress,
|
|
78
79
|
},
|
|
79
80
|
}),
|
|
80
|
-
buildTx: (requirementSignature) => (0,
|
|
81
|
+
buildTx: (requirementSignature) => (0, index_js_1.vaultV1Deposit)({
|
|
81
82
|
vault: {
|
|
82
83
|
chainId: this.chainId,
|
|
83
84
|
address: this.vault,
|
|
@@ -96,10 +97,10 @@ class MorphoVaultV1 {
|
|
|
96
97
|
}
|
|
97
98
|
withdraw({ amount, userAddress }) {
|
|
98
99
|
if (this.client.viemClient.chain?.id !== this.chainId) {
|
|
99
|
-
throw new
|
|
100
|
+
throw new index_js_3.ChainIdMismatchError(this.client.viemClient.chain?.id, this.chainId);
|
|
100
101
|
}
|
|
101
102
|
return {
|
|
102
|
-
buildTx: () => (0,
|
|
103
|
+
buildTx: () => (0, index_js_1.vaultV1Withdraw)({
|
|
103
104
|
vault: { address: this.vault },
|
|
104
105
|
args: {
|
|
105
106
|
amount,
|
|
@@ -112,10 +113,10 @@ class MorphoVaultV1 {
|
|
|
112
113
|
}
|
|
113
114
|
redeem({ shares, userAddress }) {
|
|
114
115
|
if (this.client.viemClient.chain?.id !== this.chainId) {
|
|
115
|
-
throw new
|
|
116
|
+
throw new index_js_3.ChainIdMismatchError(this.client.viemClient.chain?.id, this.chainId);
|
|
116
117
|
}
|
|
117
118
|
return {
|
|
118
|
-
buildTx: () => (0,
|
|
119
|
+
buildTx: () => (0, index_js_1.vaultV1Redeem)({
|
|
119
120
|
vault: { address: this.vault },
|
|
120
121
|
args: {
|
|
121
122
|
shares,
|
|
@@ -127,22 +128,22 @@ class MorphoVaultV1 {
|
|
|
127
128
|
};
|
|
128
129
|
}
|
|
129
130
|
migrateToV2({ userAddress, sourceVault, targetVault, shares, slippageTolerance = blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE, }) {
|
|
130
|
-
(0,
|
|
131
|
-
(0,
|
|
131
|
+
(0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
|
|
132
|
+
(0, index_js_2.validateUserAddress)(this.client.viemClient.account?.address, userAddress);
|
|
132
133
|
if (!(0, viem_1.isAddressEqual)(sourceVault.address, this.vault)) {
|
|
133
|
-
throw new
|
|
134
|
+
throw new index_js_3.VaultAddressMismatchError(this.vault, sourceVault.address);
|
|
134
135
|
}
|
|
135
136
|
if (!(0, viem_1.isAddressEqual)(sourceVault.asset, targetVault.asset)) {
|
|
136
|
-
throw new
|
|
137
|
+
throw new index_js_3.VaultAssetMismatchError(sourceVault.asset, targetVault.asset);
|
|
137
138
|
}
|
|
138
139
|
if (shares <= 0n) {
|
|
139
|
-
throw new
|
|
140
|
+
throw new index_js_3.NonPositiveSharesAmountError(this.vault);
|
|
140
141
|
}
|
|
141
142
|
if (slippageTolerance < 0n) {
|
|
142
|
-
throw new
|
|
143
|
+
throw new index_js_3.NegativeSlippageToleranceError(slippageTolerance);
|
|
143
144
|
}
|
|
144
|
-
if (slippageTolerance >
|
|
145
|
-
throw new
|
|
145
|
+
if (slippageTolerance > constant_js_1.MAX_SLIPPAGE_TOLERANCE) {
|
|
146
|
+
throw new index_js_3.ExcessiveSlippageToleranceError(slippageTolerance);
|
|
146
147
|
}
|
|
147
148
|
// Compute minSharePriceVaultV1 for V1 redeem (slippage downward)
|
|
148
149
|
const v1RefAssets = sourceVault.toAssets(shares);
|
|
@@ -150,28 +151,31 @@ class MorphoVaultV1 {
|
|
|
150
151
|
// Compute maxSharePriceVaultV2 for V2 deposit (slippage upward)
|
|
151
152
|
const v2RefShares = targetVault.toShares(v1RefAssets);
|
|
152
153
|
if (v2RefShares <= 0n) {
|
|
153
|
-
throw new
|
|
154
|
+
throw new index_js_3.NonPositiveSharesAmountError(targetVault.address);
|
|
154
155
|
}
|
|
155
|
-
const maxSharePriceVaultV2 = blue_sdk_1.MathLib.min(blue_sdk_1.MathLib.mulDivUp(v1RefAssets, blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD + slippageTolerance), v2RefShares),
|
|
156
|
+
const maxSharePriceVaultV2 = blue_sdk_1.MathLib.min(blue_sdk_1.MathLib.mulDivUp(v1RefAssets, blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD + slippageTolerance), v2RefShares), constant_js_1.MAX_ABSOLUTE_SHARE_PRICE);
|
|
156
157
|
return {
|
|
157
|
-
getRequirements: async (
|
|
158
|
+
getRequirements: async () => await (0, index_js_1.getRequirements)(this.client.viemClient, {
|
|
158
159
|
address: this.vault,
|
|
159
160
|
chainId: this.chainId,
|
|
160
161
|
supportSignature: this.client.options.supportSignature,
|
|
161
162
|
supportDeployless: this.client.options.supportDeployless,
|
|
162
|
-
|
|
163
|
+
// V1 shares always implement EIP-2612.
|
|
164
|
+
useSimplePermit: true,
|
|
163
165
|
args: {
|
|
164
166
|
amount: shares,
|
|
165
167
|
from: userAddress,
|
|
166
168
|
},
|
|
167
169
|
}),
|
|
168
|
-
buildTx: (requirementSignature) => (0,
|
|
170
|
+
buildTx: (requirementSignature) => (0, index_js_1.vaultV1MigrateToV2)({
|
|
169
171
|
vault: {
|
|
170
172
|
chainId: this.chainId,
|
|
171
173
|
address: this.vault,
|
|
174
|
+
asset: sourceVault.asset,
|
|
172
175
|
},
|
|
173
176
|
args: {
|
|
174
177
|
targetVault: targetVault.address,
|
|
178
|
+
targetAsset: targetVault.asset,
|
|
175
179
|
shares,
|
|
176
180
|
minSharePriceVaultV1,
|
|
177
181
|
maxSharePriceVaultV2,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./vaultV2.js";
|
|
@@ -14,4 +14,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./vaultV2"), exports);
|
|
17
|
+
__exportStar(require("./vaultV2.js"), exports);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
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
|
-
import
|
|
5
|
-
import type
|
|
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";
|
|
6
6
|
export interface VaultV2Actions {
|
|
7
7
|
/**
|
|
8
8
|
* Fetches the latest vault data.
|
|
@@ -4,13 +4,14 @@ exports.MorphoVaultV2 = void 0;
|
|
|
4
4
|
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
5
5
|
const blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
|
|
6
6
|
const viem_1 = require("viem");
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
7
|
+
const index_js_1 = require("../../actions/index.js");
|
|
8
|
+
const constant_js_1 = require("../../helpers/constant.js");
|
|
9
|
+
const index_js_2 = require("../../types/index.js");
|
|
10
10
|
class MorphoVaultV2 {
|
|
11
11
|
client;
|
|
12
12
|
vault;
|
|
13
13
|
chainId;
|
|
14
|
+
// biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
|
|
14
15
|
constructor(client, vault, chainId) {
|
|
15
16
|
this.client = client;
|
|
16
17
|
this.vault = vault;
|
|
@@ -19,7 +20,7 @@ class MorphoVaultV2 {
|
|
|
19
20
|
async getData(parameters) {
|
|
20
21
|
if (this.client.viemClient.chain?.id &&
|
|
21
22
|
this.client.viemClient.chain?.id !== this.chainId) {
|
|
22
|
-
throw new
|
|
23
|
+
throw new index_js_2.ChainIdMismatchError(this.client.viemClient.chain?.id, this.chainId);
|
|
23
24
|
}
|
|
24
25
|
return (0, blue_sdk_viem_1.fetchAccrualVaultV2)(this.vault, this.client.viemClient, {
|
|
25
26
|
...parameters,
|
|
@@ -29,43 +30,43 @@ class MorphoVaultV2 {
|
|
|
29
30
|
}
|
|
30
31
|
deposit({ amount = 0n, userAddress, accrualVault, slippageTolerance = blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE, nativeAmount, }) {
|
|
31
32
|
if (this.client.viemClient.chain?.id !== this.chainId) {
|
|
32
|
-
throw new
|
|
33
|
+
throw new index_js_2.ChainIdMismatchError(this.client.viemClient.chain?.id, this.chainId);
|
|
33
34
|
}
|
|
34
35
|
if (!(0, viem_1.isAddressEqual)(accrualVault.address, this.vault)) {
|
|
35
|
-
throw new
|
|
36
|
+
throw new index_js_2.VaultAddressMismatchError(this.vault, accrualVault.address);
|
|
36
37
|
}
|
|
37
38
|
if (amount < 0n) {
|
|
38
|
-
throw new
|
|
39
|
+
throw new index_js_2.NonPositiveAssetAmountError(this.vault);
|
|
39
40
|
}
|
|
40
41
|
if (nativeAmount && nativeAmount < 0n) {
|
|
41
|
-
throw new
|
|
42
|
+
throw new index_js_2.NegativeNativeAmountError(nativeAmount);
|
|
42
43
|
}
|
|
43
44
|
let wNative;
|
|
44
45
|
if (nativeAmount) {
|
|
45
46
|
({ wNative } = (0, blue_sdk_1.getChainAddresses)(this.chainId));
|
|
46
47
|
if (!wNative) {
|
|
47
|
-
throw new
|
|
48
|
+
throw new index_js_2.ChainWNativeMissingError(this.chainId);
|
|
48
49
|
}
|
|
49
50
|
}
|
|
50
51
|
if (slippageTolerance < 0n) {
|
|
51
|
-
throw new
|
|
52
|
+
throw new index_js_2.NegativeSlippageToleranceError(slippageTolerance);
|
|
52
53
|
}
|
|
53
|
-
if (slippageTolerance >
|
|
54
|
-
throw new
|
|
54
|
+
if (slippageTolerance > constant_js_1.MAX_SLIPPAGE_TOLERANCE) {
|
|
55
|
+
throw new index_js_2.ExcessiveSlippageToleranceError(slippageTolerance);
|
|
55
56
|
}
|
|
56
57
|
if (nativeAmount && wNative) {
|
|
57
58
|
if (!(0, viem_1.isAddressEqual)(accrualVault.asset, wNative)) {
|
|
58
|
-
throw new
|
|
59
|
+
throw new index_js_2.NativeAmountOnNonWNativeVaultError(accrualVault.asset, wNative);
|
|
59
60
|
}
|
|
60
61
|
}
|
|
61
62
|
const totalAssets = amount + (nativeAmount ?? 0n);
|
|
62
63
|
const shares = accrualVault.toShares(totalAssets);
|
|
63
64
|
if (shares <= 0n) {
|
|
64
|
-
throw new
|
|
65
|
+
throw new index_js_2.NonPositiveSharesAmountError(this.vault);
|
|
65
66
|
}
|
|
66
67
|
const maxSharePrice = blue_sdk_1.MathLib.min(blue_sdk_1.MathLib.mulDivUp(totalAssets, blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD + slippageTolerance), shares), blue_sdk_1.MathLib.RAY * 100n);
|
|
67
68
|
return {
|
|
68
|
-
getRequirements: async (params) => await (0,
|
|
69
|
+
getRequirements: async (params) => await (0, index_js_1.getRequirements)(this.client.viemClient, {
|
|
69
70
|
address: accrualVault.asset,
|
|
70
71
|
chainId: this.chainId,
|
|
71
72
|
supportSignature: this.client.options.supportSignature,
|
|
@@ -76,7 +77,7 @@ class MorphoVaultV2 {
|
|
|
76
77
|
from: userAddress,
|
|
77
78
|
},
|
|
78
79
|
}),
|
|
79
|
-
buildTx: (requirementSignature) => (0,
|
|
80
|
+
buildTx: (requirementSignature) => (0, index_js_1.vaultV2Deposit)({
|
|
80
81
|
vault: {
|
|
81
82
|
chainId: this.chainId,
|
|
82
83
|
address: this.vault,
|
|
@@ -95,10 +96,10 @@ class MorphoVaultV2 {
|
|
|
95
96
|
}
|
|
96
97
|
withdraw({ amount, userAddress }) {
|
|
97
98
|
if (this.client.viemClient.chain?.id !== this.chainId) {
|
|
98
|
-
throw new
|
|
99
|
+
throw new index_js_2.ChainIdMismatchError(this.client.viemClient.chain?.id, this.chainId);
|
|
99
100
|
}
|
|
100
101
|
return {
|
|
101
|
-
buildTx: () => (0,
|
|
102
|
+
buildTx: () => (0, index_js_1.vaultV2Withdraw)({
|
|
102
103
|
vault: { address: this.vault },
|
|
103
104
|
args: {
|
|
104
105
|
amount,
|
|
@@ -111,10 +112,10 @@ class MorphoVaultV2 {
|
|
|
111
112
|
}
|
|
112
113
|
redeem({ shares, userAddress }) {
|
|
113
114
|
if (this.client.viemClient.chain?.id !== this.chainId) {
|
|
114
|
-
throw new
|
|
115
|
+
throw new index_js_2.ChainIdMismatchError(this.client.viemClient.chain?.id, this.chainId);
|
|
115
116
|
}
|
|
116
117
|
return {
|
|
117
|
-
buildTx: () => (0,
|
|
118
|
+
buildTx: () => (0, index_js_1.vaultV2Redeem)({
|
|
118
119
|
vault: { address: this.vault },
|
|
119
120
|
args: {
|
|
120
121
|
shares,
|
|
@@ -127,10 +128,10 @@ class MorphoVaultV2 {
|
|
|
127
128
|
}
|
|
128
129
|
forceWithdraw({ deallocations, withdraw, userAddress, }) {
|
|
129
130
|
if (this.client.viemClient.chain?.id !== this.chainId) {
|
|
130
|
-
throw new
|
|
131
|
+
throw new index_js_2.ChainIdMismatchError(this.client.viemClient.chain?.id, this.chainId);
|
|
131
132
|
}
|
|
132
133
|
return {
|
|
133
|
-
buildTx: () => (0,
|
|
134
|
+
buildTx: () => (0, index_js_1.vaultV2ForceWithdraw)({
|
|
134
135
|
vault: { address: this.vault },
|
|
135
136
|
args: {
|
|
136
137
|
deallocations,
|
|
@@ -146,10 +147,10 @@ class MorphoVaultV2 {
|
|
|
146
147
|
}
|
|
147
148
|
forceRedeem({ deallocations, redeem, userAddress, }) {
|
|
148
149
|
if (this.client.viemClient.chain?.id !== this.chainId) {
|
|
149
|
-
throw new
|
|
150
|
+
throw new index_js_2.ChainIdMismatchError(this.client.viemClient.chain?.id, this.chainId);
|
|
150
151
|
}
|
|
151
152
|
return {
|
|
152
|
-
buildTx: () => (0,
|
|
153
|
+
buildTx: () => (0, index_js_1.vaultV2ForceRedeem)({
|
|
153
154
|
vault: { address: this.vault },
|
|
154
155
|
args: {
|
|
155
156
|
deallocations,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type MarketId } from "@morpho-org/blue-sdk";
|
|
2
2
|
import type { SimulationState } from "@morpho-org/simulation-sdk";
|
|
3
|
-
import { type ReallocationComputeOptions, type VaultReallocation } from "../types";
|
|
3
|
+
import { type ReallocationComputeOptions, type VaultReallocation } from "../types/index.js";
|
|
4
4
|
/**
|
|
5
5
|
* Computes vault reallocations for a borrow operation on a target market.
|
|
6
6
|
*
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.computeReallocations = void 0;
|
|
4
4
|
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
5
5
|
const bundler_sdk_viem_1 = require("@morpho-org/bundler-sdk-viem");
|
|
6
|
-
const
|
|
6
|
+
const index_js_1 = require("../types/index.js");
|
|
7
7
|
/**
|
|
8
8
|
* Computes vault reallocations for a borrow operation on a target market.
|
|
9
9
|
*
|
|
@@ -82,7 +82,7 @@ const computeReallocations = ({ reallocationData: data, marketId, borrowAmount,
|
|
|
82
82
|
fee: (() => {
|
|
83
83
|
const config = data.getVault(vault).publicAllocatorConfig;
|
|
84
84
|
if (config == null) {
|
|
85
|
-
throw new
|
|
85
|
+
throw new index_js_1.MissingPublicAllocatorConfigError(vault);
|
|
86
86
|
}
|
|
87
87
|
return config.fee;
|
|
88
88
|
})(),
|
|
@@ -4,7 +4,7 @@ exports.encodeForceDeallocateCall = encodeForceDeallocateCall;
|
|
|
4
4
|
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
5
5
|
const blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
|
|
6
6
|
const viem_1 = require("viem");
|
|
7
|
-
const
|
|
7
|
+
const index_js_1 = require("../types/index.js");
|
|
8
8
|
/**
|
|
9
9
|
* Encodes the adapter-specific `data` bytes for a `forceDeallocate` call.
|
|
10
10
|
*
|
|
@@ -26,7 +26,7 @@ function encodeDeallocateData(deallocation) {
|
|
|
26
26
|
*/
|
|
27
27
|
function encodeForceDeallocateCall(deallocation, onBehalf) {
|
|
28
28
|
if (deallocation.amount <= 0n) {
|
|
29
|
-
throw new
|
|
29
|
+
throw new index_js_1.NonPositiveAssetAmountError(deallocation.adapter);
|
|
30
30
|
}
|
|
31
31
|
const data = encodeDeallocateData(deallocation);
|
|
32
32
|
return (0, viem_1.encodeFunctionData)({
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { computeReallocations } from "./computeReallocations";
|
|
2
|
-
export { addTransactionMetadata } from "./metadata";
|
|
3
|
-
export { computeMaxRepaySharePrice, computeMinBorrowSharePrice, } from "./slippage";
|
|
4
|
-
export { validateAccrualPosition, validateChainId, validateNativeCollateral, validatePositionHealth, validatePositionHealthAfterWithdraw, validateReallocations, validateRepayAmount, validateRepayParams, validateRepayShares, validateSlippageTolerance, validateUserAddress, } from "./validate";
|
|
1
|
+
export { computeReallocations } from "./computeReallocations.js";
|
|
2
|
+
export { addTransactionMetadata } from "./metadata.js";
|
|
3
|
+
export { computeMaxRepaySharePrice, computeMinBorrowSharePrice, } from "./slippage.js";
|
|
4
|
+
export { validateAccrualPosition, validateChainId, validateNativeCollateral, validatePositionHealth, validatePositionHealthAfterWithdraw, validateReallocations, validateRepayAmount, validateRepayParams, validateRepayShares, validateSlippageTolerance, validateUserAddress, } from "./validate.js";
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.validateUserAddress = exports.validateSlippageTolerance = exports.validateRepayShares = exports.validateRepayParams = exports.validateRepayAmount = exports.validateReallocations = exports.validatePositionHealthAfterWithdraw = exports.validatePositionHealth = exports.validateNativeCollateral = exports.validateChainId = exports.validateAccrualPosition = exports.computeMinBorrowSharePrice = exports.computeMaxRepaySharePrice = exports.addTransactionMetadata = exports.computeReallocations = void 0;
|
|
4
|
-
var
|
|
5
|
-
Object.defineProperty(exports, "computeReallocations", { enumerable: true, get: function () { return
|
|
6
|
-
var
|
|
7
|
-
Object.defineProperty(exports, "addTransactionMetadata", { enumerable: true, get: function () { return
|
|
8
|
-
var
|
|
9
|
-
Object.defineProperty(exports, "computeMaxRepaySharePrice", { enumerable: true, get: function () { return
|
|
10
|
-
Object.defineProperty(exports, "computeMinBorrowSharePrice", { enumerable: true, get: function () { return
|
|
11
|
-
var
|
|
12
|
-
Object.defineProperty(exports, "validateAccrualPosition", { enumerable: true, get: function () { return
|
|
13
|
-
Object.defineProperty(exports, "validateChainId", { enumerable: true, get: function () { return
|
|
14
|
-
Object.defineProperty(exports, "validateNativeCollateral", { enumerable: true, get: function () { return
|
|
15
|
-
Object.defineProperty(exports, "validatePositionHealth", { enumerable: true, get: function () { return
|
|
16
|
-
Object.defineProperty(exports, "validatePositionHealthAfterWithdraw", { enumerable: true, get: function () { return
|
|
17
|
-
Object.defineProperty(exports, "validateReallocations", { enumerable: true, get: function () { return
|
|
18
|
-
Object.defineProperty(exports, "validateRepayAmount", { enumerable: true, get: function () { return
|
|
19
|
-
Object.defineProperty(exports, "validateRepayParams", { enumerable: true, get: function () { return
|
|
20
|
-
Object.defineProperty(exports, "validateRepayShares", { enumerable: true, get: function () { return
|
|
21
|
-
Object.defineProperty(exports, "validateSlippageTolerance", { enumerable: true, get: function () { return
|
|
22
|
-
Object.defineProperty(exports, "validateUserAddress", { enumerable: true, get: function () { return
|
|
4
|
+
var computeReallocations_js_1 = require("./computeReallocations.js");
|
|
5
|
+
Object.defineProperty(exports, "computeReallocations", { enumerable: true, get: function () { return computeReallocations_js_1.computeReallocations; } });
|
|
6
|
+
var metadata_js_1 = require("./metadata.js");
|
|
7
|
+
Object.defineProperty(exports, "addTransactionMetadata", { enumerable: true, get: function () { return metadata_js_1.addTransactionMetadata; } });
|
|
8
|
+
var slippage_js_1 = require("./slippage.js");
|
|
9
|
+
Object.defineProperty(exports, "computeMaxRepaySharePrice", { enumerable: true, get: function () { return slippage_js_1.computeMaxRepaySharePrice; } });
|
|
10
|
+
Object.defineProperty(exports, "computeMinBorrowSharePrice", { enumerable: true, get: function () { return slippage_js_1.computeMinBorrowSharePrice; } });
|
|
11
|
+
var validate_js_1 = require("./validate.js");
|
|
12
|
+
Object.defineProperty(exports, "validateAccrualPosition", { enumerable: true, get: function () { return validate_js_1.validateAccrualPosition; } });
|
|
13
|
+
Object.defineProperty(exports, "validateChainId", { enumerable: true, get: function () { return validate_js_1.validateChainId; } });
|
|
14
|
+
Object.defineProperty(exports, "validateNativeCollateral", { enumerable: true, get: function () { return validate_js_1.validateNativeCollateral; } });
|
|
15
|
+
Object.defineProperty(exports, "validatePositionHealth", { enumerable: true, get: function () { return validate_js_1.validatePositionHealth; } });
|
|
16
|
+
Object.defineProperty(exports, "validatePositionHealthAfterWithdraw", { enumerable: true, get: function () { return validate_js_1.validatePositionHealthAfterWithdraw; } });
|
|
17
|
+
Object.defineProperty(exports, "validateReallocations", { enumerable: true, get: function () { return validate_js_1.validateReallocations; } });
|
|
18
|
+
Object.defineProperty(exports, "validateRepayAmount", { enumerable: true, get: function () { return validate_js_1.validateRepayAmount; } });
|
|
19
|
+
Object.defineProperty(exports, "validateRepayParams", { enumerable: true, get: function () { return validate_js_1.validateRepayParams; } });
|
|
20
|
+
Object.defineProperty(exports, "validateRepayShares", { enumerable: true, get: function () { return validate_js_1.validateRepayShares; } });
|
|
21
|
+
Object.defineProperty(exports, "validateSlippageTolerance", { enumerable: true, get: function () { return validate_js_1.validateSlippageTolerance; } });
|
|
22
|
+
Object.defineProperty(exports, "validateUserAddress", { enumerable: true, get: function () { return validate_js_1.validateUserAddress; } });
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Address, type Hex } from "viem";
|
|
2
|
-
import type { Metadata } from "../types";
|
|
2
|
+
import type { Metadata } from "../types/index.js";
|
|
3
3
|
/**
|
|
4
4
|
* Adds metadata to a transaction object by concatenating additional
|
|
5
5
|
* hex-encoded data to the transaction's `data` field. The additional
|
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.computeMinBorrowSharePrice = computeMinBorrowSharePrice;
|
|
4
4
|
exports.computeMaxRepaySharePrice = computeMaxRepaySharePrice;
|
|
5
5
|
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
6
|
-
const
|
|
7
|
-
const
|
|
6
|
+
const index_js_1 = require("../types/index.js");
|
|
7
|
+
const constant_js_1 = require("./constant.js");
|
|
8
8
|
/**
|
|
9
9
|
* Computes the minimum borrow share price (in RAY, 1e27) for slippage protection.
|
|
10
10
|
*
|
|
@@ -22,11 +22,11 @@ const constant_1 = require("./constant");
|
|
|
22
22
|
function computeMinBorrowSharePrice(params) {
|
|
23
23
|
const { borrowAmount, market, slippageTolerance } = params;
|
|
24
24
|
if (slippageTolerance >= blue_sdk_1.MathLib.WAD) {
|
|
25
|
-
throw new
|
|
25
|
+
throw new index_js_1.ExcessiveSlippageToleranceError(slippageTolerance);
|
|
26
26
|
}
|
|
27
27
|
const expectedShares = market.toBorrowShares(borrowAmount, "Up");
|
|
28
28
|
if (expectedShares === 0n) {
|
|
29
|
-
throw new
|
|
29
|
+
throw new index_js_1.ShareDivideByZeroError(market.params.id);
|
|
30
30
|
}
|
|
31
31
|
return blue_sdk_1.MathLib.mulDivDown(borrowAmount, blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD - slippageTolerance), expectedShares);
|
|
32
32
|
}
|
|
@@ -53,7 +53,7 @@ function computeMinBorrowSharePrice(params) {
|
|
|
53
53
|
function computeMaxRepaySharePrice(params) {
|
|
54
54
|
const { repayAssets, repayShares, market, slippageTolerance } = params;
|
|
55
55
|
if (slippageTolerance >= blue_sdk_1.MathLib.WAD) {
|
|
56
|
-
throw new
|
|
56
|
+
throw new index_js_1.ExcessiveSlippageToleranceError(slippageTolerance);
|
|
57
57
|
}
|
|
58
58
|
let assets;
|
|
59
59
|
let shares;
|
|
@@ -66,8 +66,8 @@ function computeMaxRepaySharePrice(params) {
|
|
|
66
66
|
shares = market.toBorrowShares(repayAssets, "Down");
|
|
67
67
|
}
|
|
68
68
|
if (shares === 0n) {
|
|
69
|
-
throw new
|
|
69
|
+
throw new index_js_1.ShareDivideByZeroError(market.params.id);
|
|
70
70
|
}
|
|
71
71
|
const maxSharePrice = blue_sdk_1.MathLib.mulDivUp(assets, blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD + slippageTolerance), shares);
|
|
72
|
-
return blue_sdk_1.MathLib.min(maxSharePrice,
|
|
72
|
+
return blue_sdk_1.MathLib.min(maxSharePrice, constant_js_1.MAX_ABSOLUTE_SHARE_PRICE);
|
|
73
73
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type AccrualPosition, type MarketId } from "@morpho-org/blue-sdk";
|
|
2
2
|
import { type Address } from "viem";
|
|
3
|
-
import { type VaultReallocation } from "../types";
|
|
3
|
+
import { type VaultReallocation } from "../types/index.js";
|
|
4
4
|
/**
|
|
5
5
|
* Validates that the client has a connected account AND that it matches
|
|
6
6
|
* the provided user address.
|