@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 {IERC4626} from '@openzeppelin/contracts/interfaces/IERC4626.sol';
8
+ import {SafeERC20} from '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol';
9
+
10
+ import {RewardDistributionV1, Stablecoin} from '../reward/RewardDistributionV1.sol';
11
+
12
+ /**
13
+ * @title VaultAdapterV1
14
+ * @author @samclassix <samclassix@proton.me>, @wrytlabs <wrytlabs@proton.me>
15
+ * @notice This contract serves as an adapter for interacting with vaults, facilitating the direct minting of liquidity into them.
16
+ */
17
+ contract VaultAdapterV1 is RewardDistributionV1 {
18
+ using Math for uint256;
19
+ using SafeERC20 for IERC20;
20
+ using SafeERC20 for IERC4626;
21
+ using SafeERC20 for Stablecoin;
22
+
23
+ IERC4626 public immutable vault;
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
+ IERC4626 _vault,
43
+ address[5] memory _receivers,
44
+ uint32[5] memory _weights
45
+ ) RewardDistributionV1(_stable, _receivers, _weights) {
46
+ vault = _vault;
47
+ }
48
+
49
+ // ---------------------------------------------------------------------------------------
50
+
51
+ function totalAssets() public view returns (uint256) {
52
+ return vault.convertToAssets(vault.balanceOf(address(this)));
53
+ }
54
+
55
+ // ---------------------------------------------------------------------------------------
56
+
57
+ function deposit(uint256 amount) external onlyCurator {
58
+ // mint stables
59
+ stable.mintModule(address(this), amount);
60
+ totalMinted += amount;
61
+
62
+ // approve stable for deposit into vault
63
+ stable.forceApprove(address(vault), amount);
64
+ uint256 sharesCore = vault.deposit(amount, address(this));
65
+
66
+ emit Deposit(amount, sharesCore, totalMinted);
67
+ }
68
+
69
+ // ---------------------------------------------------------------------------------------
70
+
71
+ function redeem(uint256 sharesCore) external onlyCurator {
72
+ // reconcile
73
+ _reconcile(totalAssets(), true);
74
+
75
+ // redeem vault shares for stables
76
+ vault.redeem(sharesCore, address(this), address(this));
77
+ uint256 amount = stable.balanceOf(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
+ }