@usdu-core/usdu-core 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/.claude/settings.local.json +12 -0
  2. package/.env.example +6 -0
  3. package/.prettierrc.json +7 -0
  4. package/LICENSE +674 -0
  5. package/README.md +244 -0
  6. package/contracts/curve/CurveAdapterV1.sol +310 -0
  7. package/contracts/curve/CurveAdapterV1_1.sol +198 -0
  8. package/contracts/curve/helpers/ICurveStableSwapNG.json +566 -0
  9. package/contracts/curve/helpers/ICurveStableSwapNG.sol +177 -0
  10. package/contracts/deploy/VaultDeployer.sol +110 -0
  11. package/contracts/morpho/MorphoAdapterV1.sol +255 -0
  12. package/contracts/morpho/MorphoAdapterV1_1.sol +137 -0
  13. package/contracts/morpho/MorphoAdapterV1_2.sol +126 -0
  14. package/contracts/morpho/helpers/AggregatorV3Interface.sol +24 -0
  15. package/contracts/morpho/helpers/ChainlinkDataFeedLib.sol +36 -0
  16. package/contracts/morpho/helpers/ConstantsLib.sol +20 -0
  17. package/contracts/morpho/helpers/ErrorsLib.sol +17 -0
  18. package/contracts/morpho/helpers/IERC4626.sol +6 -0
  19. package/contracts/morpho/helpers/IMetaMorphoV1_1.sol +229 -0
  20. package/contracts/morpho/helpers/IMetaMorphoV1_1Factory.sol +32 -0
  21. package/contracts/morpho/helpers/IMorpho.sol +361 -0
  22. package/contracts/morpho/helpers/IMorphoCallbacks.sol +52 -0
  23. package/contracts/morpho/helpers/IMorphoChainlinkOracleV2.sol +39 -0
  24. package/contracts/morpho/helpers/IMorphoChainlinkOracleV2Factory.sol +56 -0
  25. package/contracts/morpho/helpers/IOracle.sol +15 -0
  26. package/contracts/morpho/helpers/MarketParamsLib.sol +21 -0
  27. package/contracts/morpho/helpers/MathLib.sol +45 -0
  28. package/contracts/morpho/helpers/Morpho.sol.bak +517 -0
  29. package/contracts/morpho/helpers/MorphoChainlinkOracleV2.sol +157 -0
  30. package/contracts/morpho/helpers/PendingLib.sol +47 -0
  31. package/contracts/morpho/helpers/SharesMathLib.sol +45 -0
  32. package/contracts/morpho/helpers/VaultLib.sol +18 -0
  33. package/contracts/reward/RewardDistributionV1.sol +110 -0
  34. package/contracts/reward/RewardRouterV0.sol +63 -0
  35. package/contracts/reward/Rewards.example.json +72 -0
  36. package/contracts/stablecoin/IStablecoin.sol +211 -0
  37. package/contracts/stablecoin/IStablecoinMetadata.sol +27 -0
  38. package/contracts/stablecoin/IStablecoinModifier.sol +52 -0
  39. package/contracts/stablecoin/Stablecoin.sol +376 -0
  40. package/contracts/stablecoin/libraries/ConstantsLib.sol +13 -0
  41. package/contracts/stablecoin/libraries/ErrorsLib.sol +45 -0
  42. package/contracts/stablecoin/libraries/EventsLib.sol +74 -0
  43. package/contracts/stablecoin/libraries/PendingLib.sol +38 -0
  44. package/contracts/vault/VaultAdapterRecoverV1.sol +29 -0
  45. package/contracts/vault/VaultAdapterV1.sol +126 -0
  46. package/dist/index.d.mts +16154 -0
  47. package/dist/index.d.ts +16154 -0
  48. package/dist/index.js +21134 -0
  49. package/dist/index.mjs +21061 -0
  50. package/docs/CoreVault: Integration of new Markets.md +197 -0
  51. package/docs/CoreVault: SupplyQueue.md +11 -0
  52. package/docs/Markets USDC Vault.md +35 -0
  53. package/docs/Markets USDU Vault.md +89 -0
  54. package/docs/Markets WETH Vault.md +35 -0
  55. package/docs/Overview.drawio +117 -0
  56. package/exports/abis/curve/CurveAdapterV1.ts +599 -0
  57. package/exports/abis/curve/CurveAdapterV1_1.ts +609 -0
  58. package/exports/abis/curve/CurveAdapterV1_2.ts +721 -0
  59. package/exports/abis/curve/helper/ICurveStableSwapNG.ts +1589 -0
  60. package/exports/abis/morpho/MorphoAdapterV1.ts +516 -0
  61. package/exports/abis/morpho/MorphoAdapterV1_1.ts +489 -0
  62. package/exports/abis/morpho/MorphoAdapterV1_2.ts +459 -0
  63. package/exports/abis/morpho/helper/AggregatorV3Interface.ts +113 -0
  64. package/exports/abis/morpho/helper/IMetaMorphoV1_1.ts +1483 -0
  65. package/exports/abis/morpho/helper/IMetaMorphoV1_1Base.ts +607 -0
  66. package/exports/abis/morpho/helper/IMetaMorphoV1_1StaticTyping.ts +696 -0
  67. package/exports/abis/morpho/helper/IMorpho.ts +1024 -0
  68. package/exports/abis/morpho/helper/IMorphoBase.ts +886 -0
  69. package/exports/abis/morpho/helper/IMorphoChainlinkOracleV2.ts +132 -0
  70. package/exports/abis/morpho/helper/IMorphoChainlinkOracleV2Factory.ts +109 -0
  71. package/exports/abis/morpho/helper/IMorphoFlashLoanCallback.ts +20 -0
  72. package/exports/abis/morpho/helper/IMorphoLiquidateCallback.ts +20 -0
  73. package/exports/abis/morpho/helper/IMorphoRepayCallback.ts +20 -0
  74. package/exports/abis/morpho/helper/IMorphoStaticTyping.ts +1003 -0
  75. package/exports/abis/morpho/helper/IMorphoSupplyCallback.ts +20 -0
  76. package/exports/abis/morpho/helper/IMorphoSupplyCollateralCallback.ts +20 -0
  77. package/exports/abis/morpho/helper/IMulticall.ts +21 -0
  78. package/exports/abis/morpho/helper/IOracle.ts +15 -0
  79. package/exports/abis/morpho/helper/IOwnable.ts +55 -0
  80. package/exports/abis/morpho/helper/MorphoChainlinkOracleV2.ts +188 -0
  81. package/exports/abis/openzeppelin/ERC20.ts +310 -0
  82. package/exports/abis/openzeppelin/ERC20Permit.ts +520 -0
  83. package/exports/abis/openzeppelin/IERC20.ts +185 -0
  84. package/exports/abis/openzeppelin/IERC20Metadata.ts +224 -0
  85. package/exports/abis/openzeppelin/IERC20Permit.ts +77 -0
  86. package/exports/abis/openzeppelin/IERC4626.ts +614 -0
  87. package/exports/abis/reward/RewardDistributionV1.ts +246 -0
  88. package/exports/abis/stablecoin/ErrorsLib.ts +114 -0
  89. package/exports/abis/stablecoin/EventsLib.ts +372 -0
  90. package/exports/abis/stablecoin/IStablecoin.ts +642 -0
  91. package/exports/abis/stablecoin/IStablecoinMetadata.ts +856 -0
  92. package/exports/abis/stablecoin/IStablecoinModifier.ts +15 -0
  93. package/exports/abis/stablecoin/Stablecoin.ts +1922 -0
  94. package/exports/abis/termmax/ITermMaxVault.ts +2335 -0
  95. package/exports/abis/vault/VaultAdapterRecoverV1.ts +490 -0
  96. package/exports/abis/vault/VaultAdapterV1.ts +459 -0
  97. package/exports/address.config.ts +113 -0
  98. package/exports/address.types.ts +130 -0
  99. package/exports/index.ts +61 -0
  100. package/hardhat.config.ts +231 -0
  101. package/helper/store.args.ts +17 -0
  102. package/helper/wallet.info.ts +3 -0
  103. package/helper/wallet.ts +41 -0
  104. package/install-macos.sh +46 -0
  105. package/package.json +73 -0
  106. package/tsconfig.json +15 -0
  107. package/tsup.config.ts +10 -0
@@ -0,0 +1,126 @@
1
+ // SPDX-License-Identifier: GPL-2.0-or-later
2
+ pragma solidity ^0.8.20;
3
+
4
+ import {Math} from '@openzeppelin/contracts/utils/math/Math.sol';
5
+
6
+ import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol';
7
+ import {SafeERC20} from '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol';
8
+
9
+ import {RewardDistributionV1, Stablecoin} from '../reward/RewardDistributionV1.sol';
10
+
11
+ import {IMetaMorphoV1_1} from './helpers/IMetaMorphoV1_1.sol';
12
+
13
+ /**
14
+ * @title MorphoAdapterV1_2
15
+ * @author @samclassix <samclassix@proton.me>, @wrytlabs <wrytlabs@proton.me>
16
+ * @notice This is an adapter for interacting with Morpho to mint liquidity straight into the market.
17
+ */
18
+ contract MorphoAdapterV1_2 is RewardDistributionV1 {
19
+ using Math for uint256;
20
+ using SafeERC20 for Stablecoin;
21
+ using SafeERC20 for IMetaMorphoV1_1;
22
+
23
+ IMetaMorphoV1_1 public immutable core;
24
+
25
+ uint256 public totalMinted;
26
+ uint256 public totalRevenue;
27
+
28
+ // ---------------------------------------------------------------------------------------
29
+
30
+ event Deposit(uint256 amount, uint256 sharesCore, uint256 totalMinted);
31
+ event Redeem(uint256 amount, uint256 sharesCore, uint256 totalMinted);
32
+ event Revenue(uint256 amount, uint256 totalRevenue, uint256 totalMinted);
33
+
34
+ // ---------------------------------------------------------------------------------------
35
+
36
+ error NothingToReconcile(uint256 assets, uint256 minted);
37
+
38
+ // ---------------------------------------------------------------------------------------
39
+
40
+ constructor(
41
+ Stablecoin _stable,
42
+ IMetaMorphoV1_1 _core,
43
+ address[5] memory _receivers,
44
+ uint32[5] memory _weights
45
+ ) RewardDistributionV1(_stable, _receivers, _weights) {
46
+ core = _core;
47
+ }
48
+
49
+ // ---------------------------------------------------------------------------------------
50
+
51
+ function totalAssets() public view returns (uint256) {
52
+ // this will use `_accruedFeeAndAssets`
53
+ return core.convertToAssets(core.balanceOf(address(this)));
54
+ }
55
+
56
+ // ---------------------------------------------------------------------------------------
57
+
58
+ function deposit(uint256 amount) external onlyCurator {
59
+ // mint stables
60
+ stable.mintModule(address(this), amount);
61
+ totalMinted += amount;
62
+
63
+ // approve stable for deposit into core vault
64
+ stable.forceApprove(address(core), amount);
65
+ uint256 sharesCore = core.deposit(amount, address(this));
66
+
67
+ emit Deposit(amount, sharesCore, totalMinted);
68
+ }
69
+
70
+ // ---------------------------------------------------------------------------------------
71
+
72
+ function redeem(uint256 sharesCore) external onlyCurator {
73
+ // reconcile, triggers `_accruedFeeAndAssets` in vault
74
+ _reconcile(totalAssets(), true);
75
+
76
+ // redeem core shares from core vault
77
+ uint256 amount = core.redeem(sharesCore, address(this), address(this));
78
+
79
+ // reduce minted amount
80
+ if (totalMinted >= amount) {
81
+ stable.burn(amount);
82
+ totalMinted -= amount;
83
+ } else {
84
+ // fallback, burn existing totalMinted if available
85
+ if (totalMinted > 0) {
86
+ stable.burn(totalMinted);
87
+ totalMinted = 0;
88
+ }
89
+
90
+ // fallback, distribute remaining balance
91
+ _distribute();
92
+ }
93
+
94
+ emit Redeem(amount, sharesCore, totalMinted);
95
+ }
96
+
97
+ // ---------------------------------------------------------------------------------------
98
+
99
+ function reconcile() external {
100
+ _reconcile(totalAssets(), false);
101
+ }
102
+
103
+ function _reconcile(uint256 assets, bool allowPassing) internal returns (uint256) {
104
+ if (assets > totalMinted) {
105
+ // calc revenue
106
+ uint256 mintToReconcile = assets - totalMinted;
107
+ totalRevenue += mintToReconcile;
108
+
109
+ // mint revenue to reconcile
110
+ stable.mintModule(address(this), mintToReconcile);
111
+ totalMinted += mintToReconcile;
112
+ emit Revenue(mintToReconcile, totalRevenue, totalMinted);
113
+
114
+ // distribute balance
115
+ _distribute();
116
+
117
+ return mintToReconcile;
118
+ } else {
119
+ if (allowPassing) {
120
+ return 0;
121
+ } else {
122
+ revert NothingToReconcile(assets, totalMinted);
123
+ }
124
+ }
125
+ }
126
+ }
@@ -0,0 +1,24 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity >=0.5.0;
3
+
4
+ /// @dev From
5
+ /// https://github.com/smartcontractkit/chainlink/blob/master/contracts/src/v0.8/shared/interfaces/AggregatorV3Interface.sol
6
+ interface AggregatorV3Interface {
7
+ function decimals() external view returns (uint8);
8
+
9
+ function description() external view returns (string memory);
10
+
11
+ function version() external view returns (uint256);
12
+
13
+ function getRoundData(
14
+ uint80 _roundId
15
+ )
16
+ external
17
+ view
18
+ returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound);
19
+
20
+ function latestRoundData()
21
+ external
22
+ view
23
+ returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound);
24
+ }
@@ -0,0 +1,36 @@
1
+ // SPDX-License-Identifier: GPL-2.0-or-later
2
+ pragma solidity ^0.8.0;
3
+
4
+ import {AggregatorV3Interface} from './AggregatorV3Interface.sol';
5
+
6
+ import {ErrorsLib} from './ErrorsLib.sol';
7
+
8
+ /// @title ChainlinkDataFeedLib
9
+ /// @author Morpho Labs
10
+ /// @custom:contact security@morpho.org
11
+ /// @notice Library exposing functions to interact with a Chainlink-compliant feed.
12
+ library ChainlinkDataFeedLib {
13
+ /// @dev Performs safety checks and returns the latest price of a `feed`.
14
+ /// @dev When `feed` is the address zero, returns 1.
15
+ /// @dev Notes on safety checks:
16
+ /// - L2s are not supported.
17
+ /// - Staleness is not checked because it's assumed that the Chainlink feed keeps its promises on this.
18
+ /// - The price is not checked to be in the min/max bounds because it's assumed that the Chainlink feed keeps its
19
+ /// promises on this.
20
+ function getPrice(AggregatorV3Interface feed) internal view returns (uint256) {
21
+ if (address(feed) == address(0)) return 1;
22
+
23
+ (, int256 answer, , , ) = feed.latestRoundData();
24
+ require(answer >= 0, ErrorsLib.NEGATIVE_ANSWER);
25
+
26
+ return uint256(answer);
27
+ }
28
+
29
+ /// @dev Returns the number of decimals of a `feed`.
30
+ /// @dev When `feed` is the address zero, returns 0.
31
+ function getDecimals(AggregatorV3Interface feed) internal view returns (uint256) {
32
+ if (address(feed) == address(0)) return 0;
33
+
34
+ return feed.decimals();
35
+ }
36
+ }
@@ -0,0 +1,20 @@
1
+ // SPDX-License-Identifier: GPL-2.0-or-later
2
+ pragma solidity ^0.8.0;
3
+
4
+ /// @title ConstantsLib
5
+ /// @author Morpho Labs
6
+ /// @custom:contact security@morpho.org
7
+ /// @notice Library exposing constants.
8
+ library ConstantsLib {
9
+ /// @dev The maximum delay of a timelock.
10
+ uint256 internal constant MAX_TIMELOCK = 2 weeks;
11
+
12
+ /// @dev The minimum delay of a timelock post initialization.
13
+ uint256 internal constant POST_INITIALIZATION_MIN_TIMELOCK = 1 days;
14
+
15
+ /// @dev The maximum number of markets in the supply/withdraw queue.
16
+ uint256 internal constant MAX_QUEUE_LENGTH = 30;
17
+
18
+ /// @dev The maximum fee the vault can have (50%).
19
+ uint256 internal constant MAX_FEE = 0.5e18;
20
+ }
@@ -0,0 +1,17 @@
1
+ // SPDX-License-Identifier: GPL-2.0-or-later
2
+ pragma solidity ^0.8.0;
3
+
4
+ /// @title ErrorsLib
5
+ /// @author Morpho Labs
6
+ /// @custom:contact security@morpho.org
7
+ /// @notice Library exposing error messages.
8
+ library ErrorsLib {
9
+ /// @notice Thrown when the answer returned by a Chainlink feed is negative.
10
+ string constant NEGATIVE_ANSWER = 'negative answer';
11
+
12
+ /// @notice Thrown when the vault conversion sample is 0.
13
+ string constant VAULT_CONVERSION_SAMPLE_IS_ZERO = 'vault conversion sample is zero';
14
+
15
+ /// @notice Thrown when the vault conversion sample is not 1 while vault = address(0).
16
+ string constant VAULT_CONVERSION_SAMPLE_IS_NOT_ONE = 'vault conversion sample is not one';
17
+ }
@@ -0,0 +1,6 @@
1
+ // SPDX-License-Identifier: GPL-2.0-or-later
2
+ pragma solidity >=0.5.0;
3
+
4
+ interface IERC4626 {
5
+ function convertToAssets(uint256) external view returns (uint256);
6
+ }
@@ -0,0 +1,229 @@
1
+ // SPDX-License-Identifier: GPL-2.0-or-later
2
+ pragma solidity >=0.5.0;
3
+
4
+ import {IMorpho, Id, MarketParams} from './IMorpho.sol';
5
+ import {IERC4626} from '@openzeppelin/contracts/interfaces/IERC4626.sol';
6
+ import {IERC20Permit} from '@openzeppelin/contracts/token/ERC20/extensions/IERC20Permit.sol';
7
+
8
+ import {MarketConfig, PendingUint192, PendingAddress} from './PendingLib.sol';
9
+
10
+ struct MarketAllocation {
11
+ /// @notice The market to allocate.
12
+ MarketParams marketParams;
13
+ /// @notice The amount of assets to allocate.
14
+ uint256 assets;
15
+ }
16
+
17
+ interface IMulticall {
18
+ function multicall(bytes[] calldata) external returns (bytes[] memory);
19
+ }
20
+
21
+ interface IOwnable {
22
+ function owner() external view returns (address);
23
+
24
+ function transferOwnership(address) external;
25
+
26
+ function renounceOwnership() external;
27
+
28
+ function acceptOwnership() external;
29
+
30
+ function pendingOwner() external view returns (address);
31
+ }
32
+
33
+ /// @dev This interface is used for factorizing IMetaMorphoV1_1StaticTyping and IMetaMorphoV1_1.
34
+ /// @dev Consider using the IMetaMorphoV1_1 interface instead of this one.
35
+ interface IMetaMorphoV1_1Base {
36
+ /// @notice The address of the Morpho contract.
37
+ function MORPHO() external view returns (IMorpho);
38
+
39
+ /// @notice OpenZeppelin decimals offset used by the ERC4626 implementation.
40
+ /// @dev Calculated to be max(0, 18 - underlyingDecimals).
41
+ /// @dev When equal to zero (<=> token decimals >= 18), the protection against the inflation front-running attack on
42
+ /// empty vault is low (see https://docs.openzeppelin.com/contracts/5.x/erc4626#inflation-attack). To protect
43
+ /// against this attack, vault deployers should make an initial deposit of a non-trivial amount in the vault or
44
+ /// depositors should check that the share price does not exceed a certain limit.
45
+ function DECIMALS_OFFSET() external view returns (uint8);
46
+
47
+ /// @notice The address of the curator.
48
+ function curator() external view returns (address);
49
+
50
+ /// @notice Stores whether an address is an allocator or not.
51
+ function isAllocator(address target) external view returns (bool);
52
+
53
+ /// @notice The current guardian. Can be set even without the timelock set.
54
+ function guardian() external view returns (address);
55
+
56
+ /// @notice The current fee.
57
+ function fee() external view returns (uint96);
58
+
59
+ /// @notice The fee recipient.
60
+ function feeRecipient() external view returns (address);
61
+
62
+ /// @notice The skim recipient.
63
+ function skimRecipient() external view returns (address);
64
+
65
+ /// @notice The current timelock.
66
+ function timelock() external view returns (uint256);
67
+
68
+ /// @dev Stores the order of markets on which liquidity is supplied upon deposit.
69
+ /// @dev Can contain any market. A market is skipped as soon as its supply cap is reached.
70
+ function supplyQueue(uint256) external view returns (Id);
71
+
72
+ /// @notice Returns the length of the supply queue.
73
+ function supplyQueueLength() external view returns (uint256);
74
+
75
+ /// @dev Stores the order of markets from which liquidity is withdrawn upon withdrawal.
76
+ /// @dev Always contain all non-zero cap markets as well as all markets on which the vault supplies liquidity,
77
+ /// without duplicate.
78
+ function withdrawQueue(uint256) external view returns (Id);
79
+
80
+ /// @notice Returns the length of the withdraw queue.
81
+ function withdrawQueueLength() external view returns (uint256);
82
+
83
+ /// @notice Stores the total assets managed by this vault when the fee was last accrued.
84
+ function lastTotalAssets() external view returns (uint256);
85
+
86
+ /// @notice Stores the missing assets due to realized bad debt or forced market removal.
87
+ /// @dev In order to cover those lost assets, it is advised to supply on behalf of address(1) on the vault
88
+ /// (canonical method).
89
+ function lostAssets() external view returns (uint256);
90
+
91
+ /// @notice Submits a `newTimelock`.
92
+ /// @dev Warning: Reverts if a timelock is already pending. Revoke the pending timelock to overwrite it.
93
+ /// @dev In case the new timelock is higher than the current one, the timelock is set immediately.
94
+ function submitTimelock(uint256 newTimelock) external;
95
+
96
+ /// @notice Accepts the pending timelock.
97
+ function acceptTimelock() external;
98
+
99
+ /// @notice Revokes the pending timelock.
100
+ /// @dev Does not revert if there is no pending timelock.
101
+ function revokePendingTimelock() external;
102
+
103
+ /// @notice Submits a `newSupplyCap` for the market defined by `marketParams`.
104
+ /// @dev Warning: Reverts if a cap is already pending. Revoke the pending cap to overwrite it.
105
+ /// @dev Warning: Reverts if a market removal is pending.
106
+ /// @dev In case the new cap is lower than the current one, the cap is set immediately.
107
+ function submitCap(MarketParams memory marketParams, uint256 newSupplyCap) external;
108
+
109
+ /// @notice Accepts the pending cap of the market defined by `marketParams`.
110
+ function acceptCap(MarketParams memory marketParams) external;
111
+
112
+ /// @notice Revokes the pending cap of the market defined by `id`.
113
+ /// @dev Does not revert if there is no pending cap.
114
+ function revokePendingCap(Id id) external;
115
+
116
+ /// @notice Submits a forced market removal from the vault, eventually losing all funds supplied to the market.
117
+ /// @notice This forced removal is expected to be used as an emergency process in case a market constantly reverts.
118
+ /// To softly remove a sane market, the curator role is expected to bundle a reallocation that empties the market
119
+ /// first (using `reallocate`), followed by the removal of the market (using `updateWithdrawQueue`).
120
+ /// @dev Warning: Reverts for non-zero cap or if there is a pending cap. Successfully submitting a zero cap will
121
+ /// prevent such reverts.
122
+ function submitMarketRemoval(MarketParams memory marketParams) external;
123
+
124
+ /// @notice Revokes the pending removal of the market defined by `id`.
125
+ /// @dev Does not revert if there is no pending market removal.
126
+ function revokePendingMarketRemoval(Id id) external;
127
+
128
+ /// @notice Sets the name of the vault.
129
+ function setName(string memory newName) external;
130
+
131
+ /// @notice Sets the symbol of the vault.
132
+ function setSymbol(string memory newSymbol) external;
133
+
134
+ /// @notice Submits a `newGuardian`.
135
+ /// @notice Warning: a malicious guardian could disrupt the vault's operation, and would have the power to revoke
136
+ /// any pending guardian.
137
+ /// @dev In case there is no guardian, the gardian is set immediately.
138
+ /// @dev Warning: Submitting a gardian will overwrite the current pending gardian.
139
+ function submitGuardian(address newGuardian) external;
140
+
141
+ /// @notice Accepts the pending guardian.
142
+ function acceptGuardian() external;
143
+
144
+ /// @notice Revokes the pending guardian.
145
+ function revokePendingGuardian() external;
146
+
147
+ /// @notice Skims the vault `token` balance to `skimRecipient`.
148
+ function skim(address) external;
149
+
150
+ /// @notice Sets `newAllocator` as an allocator or not (`newIsAllocator`).
151
+ function setIsAllocator(address newAllocator, bool newIsAllocator) external;
152
+
153
+ /// @notice Sets `curator` to `newCurator`.
154
+ function setCurator(address newCurator) external;
155
+
156
+ /// @notice Sets the `fee` to `newFee`.
157
+ function setFee(uint256 newFee) external;
158
+
159
+ /// @notice Sets `feeRecipient` to `newFeeRecipient`.
160
+ function setFeeRecipient(address newFeeRecipient) external;
161
+
162
+ /// @notice Sets `skimRecipient` to `newSkimRecipient`.
163
+ function setSkimRecipient(address newSkimRecipient) external;
164
+
165
+ /// @notice Sets `supplyQueue` to `newSupplyQueue`.
166
+ /// @param newSupplyQueue is an array of enabled markets, and can contain duplicate markets, but it would only
167
+ /// increase the cost of depositing to the vault.
168
+ function setSupplyQueue(Id[] calldata newSupplyQueue) external;
169
+
170
+ /// @notice Updates the withdraw queue. Some markets can be removed, but no market can be added.
171
+ /// @notice Removing a market requires the vault to have 0 supply on it, or to have previously submitted a removal
172
+ /// for this market (with the function `submitMarketRemoval`).
173
+ /// @notice Warning: Anyone can supply on behalf of the vault so the call to `updateWithdrawQueue` that expects a
174
+ /// market to be empty can be griefed by a front-run. To circumvent this, the allocator can simply bundle a
175
+ /// reallocation that withdraws max from this market with a call to `updateWithdrawQueue`.
176
+ /// @dev Warning: Removing a market with supply will decrease the fee accrued until one of the functions updating
177
+ /// `lastTotalAssets` is triggered (deposit/mint/withdraw/redeem/setFee/setFeeRecipient).
178
+ /// @dev Warning: `updateWithdrawQueue` is not idempotent. Submitting twice the same tx will change the queue twice.
179
+ /// @param indexes The indexes of each market in the previous withdraw queue, in the new withdraw queue's order.
180
+ function updateWithdrawQueue(uint256[] calldata indexes) external;
181
+
182
+ /// @notice Reallocates the vault's liquidity so as to reach a given allocation of assets on each given market.
183
+ /// @dev The behavior of the reallocation can be altered by state changes, including:
184
+ /// - Deposits on the vault that supplies to markets that are expected to be supplied to during reallocation.
185
+ /// - Withdrawals from the vault that withdraws from markets that are expected to be withdrawn from during
186
+ /// reallocation.
187
+ /// - Donations to the vault on markets that are expected to be supplied to during reallocation.
188
+ /// - Withdrawals from markets that are expected to be withdrawn from during reallocation.
189
+ /// @dev Sender is expected to pass `assets = type(uint256).max` with the last MarketAllocation of `allocations` to
190
+ /// supply all the remaining withdrawn liquidity, which would ensure that `totalWithdrawn` = `totalSupplied`.
191
+ /// @dev A supply in a reallocation step will make the reallocation revert if the amount is greater than the net
192
+ /// amount from previous steps (i.e. total withdrawn minus total supplied).
193
+ function reallocate(MarketAllocation[] calldata allocations) external;
194
+ }
195
+
196
+ /// @dev This interface is inherited by MetaMorphoV1_1 so that function signatures are checked by the compiler.
197
+ /// @dev Consider using the IMetaMorphoV1_1 interface instead of this one.
198
+ interface IMetaMorphoV1_1StaticTyping is IMetaMorphoV1_1Base {
199
+ /// @notice Returns the current configuration of each market.
200
+ function config(Id) external view returns (uint184 cap, bool enabled, uint64 removableAt);
201
+
202
+ /// @notice Returns the pending guardian.
203
+ function pendingGuardian() external view returns (address guardian, uint64 validAt);
204
+
205
+ /// @notice Returns the pending cap for each market.
206
+ function pendingCap(Id) external view returns (uint192 value, uint64 validAt);
207
+
208
+ /// @notice Returns the pending timelock.
209
+ function pendingTimelock() external view returns (uint192 value, uint64 validAt);
210
+ }
211
+
212
+ /// @title IMetaMorphoV1_1
213
+ /// @author Morpho Labs
214
+ /// @custom:contact security@morpho.org
215
+ /// @dev Use this interface for MetaMorphoV1_1 to have access to all the functions with the appropriate function
216
+ /// signatures.
217
+ interface IMetaMorphoV1_1 is IMetaMorphoV1_1Base, IERC4626, IERC20Permit, IOwnable, IMulticall {
218
+ /// @notice Returns the current configuration of each market.
219
+ function config(Id) external view returns (MarketConfig memory);
220
+
221
+ /// @notice Returns the pending guardian.
222
+ function pendingGuardian() external view returns (PendingAddress memory);
223
+
224
+ /// @notice Returns the pending cap for each market.
225
+ function pendingCap(Id) external view returns (PendingUint192 memory);
226
+
227
+ /// @notice Returns the pending timelock.
228
+ function pendingTimelock() external view returns (PendingUint192 memory);
229
+ }
@@ -0,0 +1,32 @@
1
+ // SPDX-License-Identifier: GPL-2.0-or-later
2
+ pragma solidity >=0.5.0;
3
+
4
+ import {IMetaMorphoV1_1} from './IMetaMorphoV1_1.sol';
5
+
6
+ /// @title IMetaMorphoV1_1Factory
7
+ /// @author Morpho Labs
8
+ /// @custom:contact security@morpho.org
9
+ /// @notice Interface of MetaMorphoV1_1's factory.
10
+ interface IMetaMorphoV1_1Factory {
11
+ /// @notice The address of the Morpho contract.
12
+ function MORPHO() external view returns (address);
13
+
14
+ /// @notice Whether a MetaMorphoV1_1 vault was created with the factory.
15
+ function isMetaMorpho(address target) external view returns (bool);
16
+
17
+ /// @notice Creates a new MetaMorphoV1_1 vault.
18
+ /// @param initialOwner The owner of the vault.
19
+ /// @param initialTimelock The initial timelock of the vault.
20
+ /// @param asset The address of the underlying asset.
21
+ /// @param name The name of the vault.
22
+ /// @param symbol The symbol of the vault.
23
+ /// @param salt The salt to use for the MetaMorphoV1_1 vault's CREATE2 address.
24
+ function createMetaMorpho(
25
+ address initialOwner,
26
+ uint256 initialTimelock,
27
+ address asset,
28
+ string memory name,
29
+ string memory symbol,
30
+ bytes32 salt
31
+ ) external returns (IMetaMorphoV1_1 metaMorpho);
32
+ }