@juicedollar/jusd 1.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.
Files changed (65) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +356 -0
  3. package/contracts/Equity.sol +457 -0
  4. package/contracts/JuiceDollar.sol +363 -0
  5. package/contracts/Leadrate.sol +79 -0
  6. package/contracts/MintingHubV2/MintingHub.sol +445 -0
  7. package/contracts/MintingHubV2/Position.sol +810 -0
  8. package/contracts/MintingHubV2/PositionFactory.sol +69 -0
  9. package/contracts/MintingHubV2/PositionRoller.sol +159 -0
  10. package/contracts/MintingHubV2/interface/IMintingHub.sol +26 -0
  11. package/contracts/MintingHubV2/interface/IPosition.sol +90 -0
  12. package/contracts/MintingHubV2/interface/IPositionFactory.sol +20 -0
  13. package/contracts/Savings.sol +141 -0
  14. package/contracts/SavingsVaultJUSD.sol +140 -0
  15. package/contracts/StablecoinBridge.sol +109 -0
  16. package/contracts/StartUSD.sol +16 -0
  17. package/contracts/gateway/CoinLendingGateway.sol +223 -0
  18. package/contracts/gateway/FrontendGateway.sol +224 -0
  19. package/contracts/gateway/MintingHubGateway.sol +87 -0
  20. package/contracts/gateway/SavingsGateway.sol +51 -0
  21. package/contracts/gateway/interface/ICoinLendingGateway.sol +73 -0
  22. package/contracts/gateway/interface/IFrontendGateway.sol +49 -0
  23. package/contracts/gateway/interface/IMintingHubGateway.sol +12 -0
  24. package/contracts/impl/ERC3009.sol +171 -0
  25. package/contracts/interface/IJuiceDollar.sol +54 -0
  26. package/contracts/interface/ILeadrate.sol +7 -0
  27. package/contracts/interface/IReserve.sol +9 -0
  28. package/contracts/interface/ISavingsJUSD.sol +49 -0
  29. package/contracts/test/FreakToken.sol +25 -0
  30. package/contracts/test/Math.sol +339 -0
  31. package/contracts/test/MockEquity.sol +15 -0
  32. package/contracts/test/PositionExpirationTest.sol +75 -0
  33. package/contracts/test/PositionRollingTest.sol +65 -0
  34. package/contracts/test/TestFlashLoan.sol +84 -0
  35. package/contracts/test/TestFlashLoanGateway.sol +49 -0
  36. package/contracts/test/TestMathUtil.sol +40 -0
  37. package/contracts/test/TestToken.sol +45 -0
  38. package/contracts/test/TestWcBTC.sol +35 -0
  39. package/contracts/utils/MathUtil.sol +61 -0
  40. package/dist/index.d.mts +8761 -0
  41. package/dist/index.d.ts +8761 -0
  42. package/dist/index.js +11119 -0
  43. package/dist/index.mjs +11073 -0
  44. package/exports/abis/MintingHubV2/PositionFactoryV2.ts +90 -0
  45. package/exports/abis/MintingHubV2/PositionRoller.ts +183 -0
  46. package/exports/abis/MintingHubV2/PositionV2.ts +999 -0
  47. package/exports/abis/core/CoinLendingGateway.ts +427 -0
  48. package/exports/abis/core/Equity.ts +1286 -0
  49. package/exports/abis/core/FrontendGateway.ts +906 -0
  50. package/exports/abis/core/JuiceDollar.ts +1366 -0
  51. package/exports/abis/core/MintingHubGateway.ts +865 -0
  52. package/exports/abis/core/SavingsGateway.ts +559 -0
  53. package/exports/abis/core/SavingsVaultJUSD.ts +920 -0
  54. package/exports/abis/utils/ERC20.ts +310 -0
  55. package/exports/abis/utils/ERC20PermitLight.ts +520 -0
  56. package/exports/abis/utils/Leadrate.ts +175 -0
  57. package/exports/abis/utils/MintingHubV2.ts +682 -0
  58. package/exports/abis/utils/Ownable.ts +76 -0
  59. package/exports/abis/utils/Savings.ts +453 -0
  60. package/exports/abis/utils/StablecoinBridge.ts +209 -0
  61. package/exports/abis/utils/StartUSD.ts +315 -0
  62. package/exports/abis/utils/UniswapV3Pool.ts +638 -0
  63. package/exports/address.config.ts +48 -0
  64. package/exports/index.ts +28 -0
  65. package/package.json +87 -0
@@ -0,0 +1,45 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.0;
3
+
4
+ import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
5
+ import {ERC20Burnable} from "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol";
6
+ import {EIP712} from "@openzeppelin/contracts/utils/cryptography/EIP712.sol";
7
+ import {ERC3009} from "../impl/ERC3009.sol";
8
+
9
+ contract TestToken is ERC20, EIP712, ERC3009, ERC20Burnable {
10
+ uint8 private _decimals;
11
+
12
+ constructor(string memory name_, string memory symbol_, uint8 decimals_) EIP712(name_, "1") ERC20(name_, symbol_) {
13
+ _decimals = decimals_;
14
+ _mint(msg.sender, 10_000_000 * 1e18);
15
+ }
16
+
17
+ function decimals() public view override returns (uint8) {
18
+ return _decimals;
19
+ }
20
+
21
+ function mint(address _account, uint256 _amount) external {
22
+ _mint(_account, _amount);
23
+ }
24
+
25
+ // Note: Doesn't revert on failure, instead returns false (same as USDC token).
26
+ // This behaviour is used in BasicTests.ts (SafeERC20 test).
27
+ function transferFrom(
28
+ address from,
29
+ address to,
30
+ uint256 amount
31
+ ) public override returns (bool) {
32
+ uint256 currentAllowance = allowance(from, msg.sender);
33
+ if (currentAllowance < amount) {
34
+ return false;
35
+ }
36
+
37
+ if (balanceOf(from) < amount) {
38
+ return false;
39
+ }
40
+
41
+ _approve(from, msg.sender, currentAllowance - amount); // Update allowance
42
+ _transfer(from, to, amount); // Perform the transfer
43
+ return true;
44
+ }
45
+ }
@@ -0,0 +1,35 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.24;
3
+
4
+ import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
5
+
6
+ /**
7
+ * @title TestWcBTC
8
+ * @notice Test WcBTC (Wrapped cBTC) implementation for testing CoinLendingGateway on Citrea
9
+ */
10
+ contract TestWcBTC is ERC20 {
11
+ error InsufficientBalance();
12
+ error CBTCTransferFailed();
13
+
14
+ event Deposit(address indexed dst, uint256 wad);
15
+ event Withdrawal(address indexed src, uint256 wad);
16
+
17
+ constructor() ERC20("Wrapped cBTC", "WcBTC") {}
18
+
19
+ receive() external payable {
20
+ deposit();
21
+ }
22
+
23
+ function deposit() public payable {
24
+ _mint(msg.sender, msg.value);
25
+ emit Deposit(msg.sender, msg.value);
26
+ }
27
+
28
+ function withdraw(uint256 wad) external {
29
+ if (balanceOf(msg.sender) < wad) revert InsufficientBalance();
30
+ _burn(msg.sender, wad);
31
+ (bool success, ) = msg.sender.call{value: wad}("");
32
+ if (!success) revert CBTCTransferFailed();
33
+ emit Withdrawal(msg.sender, wad);
34
+ }
35
+ }
@@ -0,0 +1,61 @@
1
+ // SPDX-License-Identifier: MIT
2
+
3
+ pragma solidity ^0.8.0;
4
+
5
+ /**
6
+ * @title Functions for share valuation
7
+ */
8
+ contract MathUtil {
9
+ uint256 internal constant ONE_DEC18 = 10 ** 18;
10
+
11
+ // Let's go for 12 digits of precision (18-6)
12
+ uint256 internal constant THRESH_DEC18 = 10 ** 6;
13
+
14
+ /**
15
+ * @notice Tenth root with Halley approximation
16
+ * Number 1e18 decimal
17
+ * @param _v number for which we calculate x**(1/10)
18
+ * @return returns _v**(1/10)
19
+ */
20
+ function _tenthRoot(uint256 _v) internal pure returns (uint256) {
21
+ // Good first guess for _v slightly above 1.0, which is often the case in the JUSD system
22
+ uint256 x = _v > ONE_DEC18 && _v < 10 ** 19 ? (_v - ONE_DEC18) / 10 + ONE_DEC18 : ONE_DEC18;
23
+ uint256 diff;
24
+ do {
25
+ uint256 powX10 = _power10(x);
26
+ uint256 xnew = _mulD18(x, _divD18(11 * _v + 9 * powX10, 9 * _v + 11 * powX10));
27
+ diff = xnew > x ? xnew - x : x - xnew;
28
+ x = xnew;
29
+ } while (diff > THRESH_DEC18);
30
+ return x;
31
+ }
32
+
33
+ function _mulD18(uint256 _a, uint256 _b) internal pure returns (uint256) {
34
+ return (_a * _b) / ONE_DEC18;
35
+ }
36
+
37
+ function _divD18(uint256 _a, uint256 _b) internal pure returns (uint256) {
38
+ return (_a * ONE_DEC18) / _b;
39
+ }
40
+
41
+ function _power10(uint256 _x) internal pure returns (uint256) {
42
+ uint256 x2 = _mulD18(_x, _x);
43
+ uint256 x4 = _mulD18(x2, x2);
44
+ uint256 x5 = _mulD18(x4, _x);
45
+ return _mulD18(x5, x5);
46
+ }
47
+
48
+ function _min(uint256 a, uint256 b) internal pure returns (uint256) {
49
+ return a < b ? a : b;
50
+ }
51
+
52
+ /**
53
+ * @notice Performs ceiling division for PPM calculations using formula: ceil(amount / (1 - ppm/1000000))
54
+ * @param amount The base amount to divide
55
+ * @param ppm Parts per million value (e.g., 200000 for 20%)
56
+ * @return The result of ceiling division
57
+ */
58
+ function _ceilDivPPM(uint256 amount, uint24 ppm) internal pure returns (uint256) {
59
+ return amount == 0 ? 0 : (amount * 1_000_000 - 1) / (1_000_000 - ppm) + 1;
60
+ }
61
+ }