Skip to content

Commit

Permalink
Deploy v1.2 (#148)
Browse files Browse the repository at this point in the history
* Update coverage [skip ci]

* Deploy cbBTC/USDC

---------

Co-authored-by: Size <[email protected]>
  • Loading branch information
aviggiano and sizecash authored Oct 4, 2024
1 parent 31ecbe4 commit 007a7f8
Show file tree
Hide file tree
Showing 18 changed files with 5,980 additions and 493 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ node_modules
# Crytic
crytic-export
echidna
medusa
710 changes: 710 additions & 0 deletions broadcast/Deploy.s.sol/8453/run-1728063082.json

Large diffs are not rendered by default.

710 changes: 710 additions & 0 deletions broadcast/Deploy.s.sol/8453/run-1728063109.json

Large diffs are not rendered by default.

710 changes: 710 additions & 0 deletions broadcast/Deploy.s.sol/8453/run-1728063215.json

Large diffs are not rendered by default.

710 changes: 710 additions & 0 deletions broadcast/Deploy.s.sol/8453/run-1728063509.json

Large diffs are not rendered by default.

710 changes: 710 additions & 0 deletions broadcast/Deploy.s.sol/8453/run-1728063592.json

Large diffs are not rendered by default.

1,192 changes: 1,192 additions & 0 deletions broadcast/Deploy.s.sol/8453/run-1728064206.json

Large diffs are not rendered by default.

1,450 changes: 966 additions & 484 deletions broadcast/Deploy.s.sol/8453/run-latest.json

Large diffs are not rendered by default.

28 changes: 28 additions & 0 deletions deployments/base-production-cbbtc-usdc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"chainId": "8453",
"commit": "f9f953a",
"deployments": {
"PriceFeed": "0x634160Ce49Fe29FC086E0B12230bD571c3A4858b",
"Size-implementation": "0x94Afc4AfA15A4d3973fb02fc989de25D52aADD78",
"Size-proxy": "0xB21Bbe052F5cE9ae681c59725f0A313765Fd016c"
},
"networkConfiguration": "base-production-cbbtc-usdc",
"parameters": {
"borrowATokenCap": "1000000000000",
"crLiquidation": "1300000000000000000",
"crOpening": "1500000000000000000",
"feeRecipient": "0x12328ea44ab6d7b18aa9cc030714763734b625db",
"fragmentationFee": "1000000",
"minimumCreditBorrowAToken": "10000000",
"owner": "0x462b545e8bbb6f9e5860928748bfe9ecc712c3a7",
"sequencerUptimeFeed": "0xbcf85224fc0756b9fa45aa7892530b47e10b6433",
"underlyingBorrowToken": "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913",
"underlyingBorrowTokenAggregator": "0x7e860098f58bbfc8648a4311b374b1d669a2bc6b",
"underlyingBorrowTokenHeartbeat": "95040",
"underlyingCollateralToken": "0xcbb7c0000ab88b473b1f5afd9ef808440eed33bf",
"underlyingCollateralTokenAggregator": "0x07da0e54543a844a80abe69c8a12f22b3aa59f9d",
"underlyingCollateralTokenHeartbeat": "95040",
"variablePool": "0xa238dd80c259a72e81d7e4664a9801593f98d1c5",
"weth": "0x4200000000000000000000000000000000000006"
}
}
File renamed without changes.
File renamed without changes.
82 changes: 82 additions & 0 deletions medusa-differential.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{
"fuzzing": {
"workers": 10,
"workerResetLimit": 50,
"timeout": 0,
"testLimit": 0,
"callSequenceLength": 100,
"corpusDirectory": "medusa",
"coverageEnabled": true,
"targetContracts": [
"CryticNonTransferrableScaledTokenDifferentialCryticTester"
],
"targetContractsBalances": [],
"constructorArgs": {},
"deployerAddress": "0x30000",
"senderAddresses": [
"0x10000",
"0x20000",
"0x30000"
],
"blockNumberDelayMax": 60480,
"blockTimestampDelayMax": 604800,
"blockGasLimit": 125000000,
"transactionGasLimit": 12500000,
"testing": {
"stopOnFailedTest": true,
"stopOnFailedContractMatching": true,
"stopOnNoTests": true,
"testAllContracts": false,
"traceAll": false,
"assertionTesting": {
"enabled": true,
"testViewMethods": false,
"panicCodeConfig": {
"failOnCompilerInsertedPanic": false,
"failOnAssertion": true,
"failOnArithmeticUnderflow": false,
"failOnDivideByZero": false,
"failOnEnumTypeConversionOutOfBounds": false,
"failOnIncorrectStorageAccess": false,
"failOnPopEmptyArray": false,
"failOnOutOfBoundsArrayAccess": false,
"failOnAllocateTooMuchMemory": false,
"failOnCallUninitializedVariable": false
}
},
"propertyTesting": {
"enabled": true,
"testPrefixes": [
"property_"
]
},
"optimizationTesting": {
"enabled": true,
"testPrefixes": [
"optimize_"
]
}
},
"chainConfig": {
"codeSizeCheckDisabled": true,
"cheatCodes": {
"cheatCodesEnabled": true,
"enableFFI": false
}
}
},
"compilation": {
"platform": "crytic-compile",
"platformConfig": {
"target": ".",
"solcVersion": "",
"exportDirectory": "",
"args": ["--compile-libraries=(Errors,0x10),(UpdateConfig,0x11),(Deposit,0x12),(Withdraw,0x13),(Initialize,0x14),(Events,0x15),(Multicall,0x16),(DepositTokenLibrary,0x17),(OfferLibrary,0x18),(CapsLibrary,0x19),(LoanLibrary,0x1a),(RiskLibrary,0x1b),(LiquidateWithReplacement,0x1c),(Claim,0x1d),(Compensate,0x1e),(SellCreditLimit,0x1f),(BuyCreditMarket,0x20),(Liquidate,0x21),(Repay,0x22),(SellCreditMarket,0x23),(SelfLiquidate,0x24),(BuyCreditLimit,0x25),(SetUserConfiguration,0x26),(YieldCurveLibrary,0x27),(AccountingLibrary,0x28),(Math,0x29),(YieldCurveHelper,0x2a)","--foundry-compile-all"]
}
},
"logging": {
"level": "info",
"logDirectory": "",
"noColor": false
}
}
6 changes: 3 additions & 3 deletions script/Networks.sol
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ abstract contract Networks {
minimumCreditBorrowAToken: 10e6,
borrowATokenCap: 1_000_000e6
});
} else if (Strings.equal(chain, "base-sepolia")) {
} else if (Strings.equal(chain, "base-sepolia-weth-usdc")) {
return NetworkConfiguration({
weth: 0x4200000000000000000000000000000000000006,
underlyingCollateralToken: 0x4200000000000000000000000000000000000006,
Expand Down Expand Up @@ -109,7 +109,7 @@ abstract contract Networks {
minimumCreditBorrowAToken: 10e6,
borrowATokenCap: 1_000_000e6
});
} else if (Strings.equal(chain, "base-production-eth-usdc")) {
} else if (Strings.equal(chain, "base-production-weth-usdc")) {
return NetworkConfiguration({
weth: 0x4200000000000000000000000000000000000006,
underlyingCollateralToken: 0x4200000000000000000000000000000000000006,
Expand Down Expand Up @@ -143,7 +143,7 @@ abstract contract Networks {
minimumCreditBorrowAToken: 10e6,
borrowATokenCap: 1_000_000e6
});
} else if (Strings.equal(chain, "base-production-wsteth-eth")) {
} else if (Strings.equal(chain, "base-production-wsteth-weth")) {
return NetworkConfiguration({
weth: 0x4200000000000000000000000000000000000006,
underlyingCollateralToken: 0xc1CBa3fCea344f92D9239c08C0568f6F2F0ee452,
Expand Down
17 changes: 16 additions & 1 deletion src/token/NonTransferrableScaledToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ contract NonTransferrableScaledToken is Ownable, IERC20Metadata, IERC20Errors {
/// @dev Emits a TransferUnscaled event representing the actual unscaled amount
/// Re-implements `_mint` logic from solmate's ERC20.sol
function mintScaled(address to, uint256 scaledAmount) external onlyOwner {
if (to == address(0)) {
revert ERC20InvalidReceiver(address(0));
}

_totalSupply += scaledAmount;

// Cannot overflow because the sum of all user
Expand All @@ -80,6 +84,10 @@ contract NonTransferrableScaledToken is Ownable, IERC20Metadata, IERC20Errors {
/// @dev Emits a TransferUnscaled event representing the actual unscaled amount
/// Re-implements `_burn` logic from solmate's ERC20.sol
function burnScaled(address from, uint256 scaledAmount) external onlyOwner {
if (from == address(0)) {
revert ERC20InvalidSender(address(0));
}

uint256 unscaledAmount = _unscale(scaledAmount);
if (_balanceOf[from] < scaledAmount) {
revert ERC20InsufficientBalance(from, balanceOf(from), unscaledAmount);
Expand All @@ -106,6 +114,13 @@ contract NonTransferrableScaledToken is Ownable, IERC20Metadata, IERC20Errors {
/// Scales the amount by the current liquidity index before transferring scaled tokens
/// @return True if the transfer was successful
function transferFrom(address from, address to, uint256 value) public virtual onlyOwner returns (bool) {
if (from == address(0)) {
revert ERC20InvalidSender(address(0));
}
if (to == address(0)) {
revert ERC20InvalidReceiver(address(0));
}

uint256 scaledAmount = Math.mulDivDown(value, WadRayMath.RAY, liquidityIndex());

if (_balanceOf[from] < scaledAmount) {
Expand Down Expand Up @@ -148,7 +163,7 @@ contract NonTransferrableScaledToken is Ownable, IERC20Metadata, IERC20Errors {
/// @param scaledAmount The scaled amount to unscale
/// @return The unscaled amount
/// @dev The unscaled amount is the scaled amount divided by the current liquidity index
function _unscale(uint256 scaledAmount) internal view returns (uint256) {
function _unscale(uint256 scaledAmount) private view returns (uint256) {
return Math.mulDivDown(scaledAmount, liquidityIndex(), WadRayMath.RAY);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.23;

import {IPool} from "@aave/interfaces/IPool.sol";

import {WadRayMath} from "@aave/protocol/libraries/math/WadRayMath.sol";
import {CryticAsserts} from "@chimera/CryticAsserts.sol";
import {vm} from "@chimera/Hevm.sol";
import {IERC20Metadata} from "@openzeppelin/contracts/interfaces/IERC20Metadata.sol";
import {NonTransferrableScaledToken} from "@src/token/NonTransferrableScaledToken.sol";
import {NonTransferrableScaledTokenV1} from "@test/local/token/differential/NonTransferrableScaledTokenV1.sol";
import {INonTransferrableScaledTokenCall} from
"@test/local/token/differential/interfaces/INonTransferrableScaledTokenCall.sol";
import {INonTransferrableScaledTokenStaticcall} from
"@test/local/token/differential/interfaces/INonTransferrableScaledTokenStaticcall.sol";
import {SimplePool} from "@test/local/token/differential/mocks/SimplePool.sol";
import {USDC} from "@test/mocks/USDC.sol";

// echidna . --contract CryticNonTransferrableScaledTokenDifferentialCryticTester --config echidna.yaml
// medusa fuzz
contract CryticNonTransferrableScaledTokenDifferentialCryticTester is CryticAsserts {
string private constant ERROR = "ERROR";

NonTransferrableScaledTokenV1 private v1;
NonTransferrableScaledToken private v2;
USDC private underlying;
IPool private pool;

constructor() {
underlying = new USDC(address(this));
pool = IPool(address(new SimplePool(WadRayMath.RAY)));
v1 = new NonTransferrableScaledTokenV1(
pool,
IERC20Metadata(underlying),
msg.sender,
string.concat(underlying.name(), " Test"),
string.concat(underlying.symbol(), " TEST"),
underlying.decimals()
);
v2 = new NonTransferrableScaledToken(
pool,
IERC20Metadata(underlying),
msg.sender,
string.concat(underlying.name(), " Test"),
string.concat(underlying.symbol(), " TEST"),
underlying.decimals()
);
}

// Helper function for regular calls
function callFunction(address target1, address target2, bytes memory data) internal {
vm.prank(msg.sender);
(bool success1, bytes memory result1) = target1.call(data);

vm.prank(msg.sender);
(bool success2, bytes memory result2) = target2.call(data);

t(success1 == success2, ERROR);
if (success1) {
t(keccak256(result1) == keccak256(result2), ERROR);
}
}

function staticCallFunction(address target1, address target2, bytes memory data) internal {
vm.prank(msg.sender);
(bool success1, bytes memory result1) = target1.staticcall(data);

vm.prank(msg.sender);
(bool success2, bytes memory result2) = target2.staticcall(data);

t(success1 == success2, ERROR);
if (success1) {
t(keccak256(result1) == keccak256(result2), ERROR);
}
}

function mintScaled(address to, uint256 scaledAmount) external {
callFunction(
address(v1), address(v2), abi.encodeCall(INonTransferrableScaledTokenCall.mintScaled, (to, scaledAmount))
);
}

function burnScaled(address from, uint256 scaledAmount) external {
callFunction(
address(v1), address(v2), abi.encodeCall(INonTransferrableScaledTokenCall.burnScaled, (from, scaledAmount))
);
}

function transferFrom(address from, address to, uint256 value) external {
callFunction(
address(v1), address(v2), abi.encodeCall(INonTransferrableScaledTokenCall.transferFrom, (from, to, value))
);
}

function transfer(address to, uint256 value) external {
callFunction(address(v1), address(v2), abi.encodeCall(INonTransferrableScaledTokenCall.transfer, (to, value)));
}

function approve(address spender, uint256 value) external {
callFunction(
address(v1), address(v2), abi.encodeCall(INonTransferrableScaledTokenCall.approve, (spender, value))
);
}

function allowance(address owner, address spender) external {
staticCallFunction(
address(v1), address(v2), abi.encodeCall(INonTransferrableScaledTokenStaticcall.allowance, (owner, spender))
);
}

function scaledBalanceOf(address account) external {
staticCallFunction(
address(v1), address(v2), abi.encodeCall(INonTransferrableScaledTokenStaticcall.scaledBalanceOf, (account))
);
}

function balanceOf(address account) external {
staticCallFunction(
address(v1), address(v2), abi.encodeCall(INonTransferrableScaledTokenStaticcall.balanceOf, (account))
);
}

function scaledTotalSupply() external {
staticCallFunction(
address(v1), address(v2), abi.encodeCall(INonTransferrableScaledTokenStaticcall.scaledTotalSupply, ())
);
}

function totalSupply() external {
staticCallFunction(
address(v1), address(v2), abi.encodeCall(INonTransferrableScaledTokenStaticcall.totalSupply, ())
);
}

function liquidityIndex() external {
staticCallFunction(
address(v1), address(v2), abi.encodeCall(INonTransferrableScaledTokenStaticcall.liquidityIndex, ())
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import {SymTest} from "halmos-cheatcodes/SymTest.sol";
import {IERC20Metadata} from "@openzeppelin/contracts/interfaces/IERC20Metadata.sol";
import {NonTransferrableScaledToken} from "@src/token/NonTransferrableScaledToken.sol";
import {NonTransferrableScaledTokenV1} from "@test/local/token/differential/NonTransferrableScaledTokenV1.sol";
import {USDC} from "@test/mocks/USDC.sol";

import {SimplePool} from "@test/local/token/differential/mocks/SimplePool.sol";
import {USDC} from "@test/mocks/USDC.sol";

import {Test} from "forge-std/Test.sol";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,5 @@ interface INonTransferrableScaledTokenCall {

function transfer(address to, uint256 value) external;

function allowance(address, address spender) external returns (uint256);

function approve(address, uint256) external returns (bool);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,5 @@ interface INonTransferrableScaledTokenV1Call {

function transfer(address to, uint256 value) external;

function allowance(address, address spender) external returns (uint256);

function approve(address, uint256) external returns (bool);
}

0 comments on commit 007a7f8

Please sign in to comment.