Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ src = 'src'
out = 'out'
libs = ['lib']
verbosity = 3
solc-version = '0.8.21'
solc-version = '0.8.19'
via_ir = true
optimizer = true
optimizer_runs = 100000000
Expand Down
2 changes: 1 addition & 1 deletion script/DeployCometWrapper.s.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.21;
pragma solidity 0.8.19;

import "forge-std/Script.sol";
import "forge-std/console.sol";
Expand Down
2 changes: 1 addition & 1 deletion src/CometHelpers.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.21;
pragma solidity 0.8.19;

import {CometMath} from "./vendor/CometMath.sol";

Expand Down
239 changes: 69 additions & 170 deletions src/CometWrapper.sol

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/test/EIP1271Signer.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.21;
pragma solidity 0.8.19;

contract EIP1271Signer {
bytes4 internal constant EIP1271_MAGIC_VALUE = 0x1626ba7e;
Expand Down
49 changes: 49 additions & 0 deletions src/vendor/CometConfiguration.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.19;

/**
* @title Compound's Comet Configuration Interface
* @author Compound
*/
contract CometConfiguration {
struct ExtConfiguration {
bytes32 name32;
bytes32 symbol32;
}

struct Configuration {
address governor;
address pauseGuardian;
address baseToken;
address baseTokenPriceFeed;
address extensionDelegate;

uint64 supplyKink;
uint64 supplyPerYearInterestRateSlopeLow;
uint64 supplyPerYearInterestRateSlopeHigh;
uint64 supplyPerYearInterestRateBase;
uint64 borrowKink;
uint64 borrowPerYearInterestRateSlopeLow;
uint64 borrowPerYearInterestRateSlopeHigh;
uint64 borrowPerYearInterestRateBase;
uint64 storeFrontPriceFactor;
uint64 trackingIndexScale;
uint64 baseTrackingSupplySpeed;
uint64 baseTrackingBorrowSpeed;
uint104 baseMinForRewards;
uint104 baseBorrowMin;
uint104 targetReserves;

AssetConfig[] assetConfigs;
}

struct AssetConfig {
address asset;
address priceFeed;
uint8 decimals;
uint64 borrowCollateralFactor;
uint64 liquidateCollateralFactor;
uint64 liquidationFactor;
uint128 supplyCap;
}
}
127 changes: 127 additions & 0 deletions src/vendor/CometCore.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.19;

import "./CometConfiguration.sol";
import "./CometStorage.sol";
import "./CometMath.sol";

abstract contract CometCore is CometConfiguration, CometStorage, CometMath {
struct AssetInfo {
uint8 offset;
address asset;
address priceFeed;
uint64 scale;
uint64 borrowCollateralFactor;
uint64 liquidateCollateralFactor;
uint64 liquidationFactor;
uint128 supplyCap;
}

/** Internal constants **/

/// @dev The max number of assets this contract is hardcoded to support
/// Do not change this variable without updating all the fields throughout the contract,
// including the size of UserBasic.assetsIn and corresponding integer conversions.
uint8 internal constant MAX_ASSETS = 15;

/// @dev The max number of decimals base token can have
/// Note this cannot just be increased arbitrarily.
uint8 internal constant MAX_BASE_DECIMALS = 18;

/// @dev The max value for a collateral factor (1)
uint64 internal constant MAX_COLLATERAL_FACTOR = FACTOR_SCALE;

/// @dev Offsets for specific actions in the pause flag bit array
uint8 internal constant PAUSE_SUPPLY_OFFSET = 0;
uint8 internal constant PAUSE_TRANSFER_OFFSET = 1;
uint8 internal constant PAUSE_WITHDRAW_OFFSET = 2;
uint8 internal constant PAUSE_ABSORB_OFFSET = 3;
uint8 internal constant PAUSE_BUY_OFFSET = 4;

/// @dev The decimals required for a price feed
uint8 internal constant PRICE_FEED_DECIMALS = 8;

/// @dev 365 days * 24 hours * 60 minutes * 60 seconds
uint64 internal constant SECONDS_PER_YEAR = 31_536_000;

/// @dev The scale for base tracking accrual
uint64 internal constant BASE_ACCRUAL_SCALE = 1e6;

/// @dev The scale for base index (depends on time/rate scales, not base token)
uint64 internal constant BASE_INDEX_SCALE = 1e15;

/// @dev The scale for prices (in USD)
uint64 internal constant PRICE_SCALE = uint64(10 ** PRICE_FEED_DECIMALS);

/// @dev The scale for factors
uint64 internal constant FACTOR_SCALE = 1e18;

/// @dev The storage slot for reentrancy guard flags
bytes32 internal constant REENTRANCY_GUARD_FLAG_SLOT = bytes32(keccak256("comet.reentrancy.guard"));

/// @dev The reentrancy guard statuses
uint256 internal constant REENTRANCY_GUARD_NOT_ENTERED = 0;
uint256 internal constant REENTRANCY_GUARD_ENTERED = 1;

/**
* @notice Determine if the manager has permission to act on behalf of the owner
* @param owner The owner account
* @param manager The manager account
* @return Whether or not the manager has permission
*/
function hasPermission(address owner, address manager) public view returns (bool) {
return owner == manager || isAllowed[owner][manager];
}

/**
* @dev The positive present supply balance if positive or the negative borrow balance if negative
*/
function presentValue(int104 principalValue_) internal view returns (int256) {
if (principalValue_ >= 0) {
return signed256(presentValueSupply(baseSupplyIndex, uint104(principalValue_)));
} else {
return -signed256(presentValueBorrow(baseBorrowIndex, uint104(-principalValue_)));
}
}

/**
* @dev The principal amount projected forward by the supply index
*/
function presentValueSupply(uint64 baseSupplyIndex_, uint104 principalValue_) internal pure returns (uint256) {
return uint256(principalValue_) * baseSupplyIndex_ / BASE_INDEX_SCALE;
}

/**
* @dev The principal amount projected forward by the borrow index
*/
function presentValueBorrow(uint64 baseBorrowIndex_, uint104 principalValue_) internal pure returns (uint256) {
return uint256(principalValue_) * baseBorrowIndex_ / BASE_INDEX_SCALE;
}

/**
* @dev The positive principal if positive or the negative principal if negative
*/
function principalValue(int256 presentValue_) internal view returns (int104) {
if (presentValue_ >= 0) {
return signed104(principalValueSupply(baseSupplyIndex, uint256(presentValue_)));
} else {
return -signed104(principalValueBorrow(baseBorrowIndex, uint256(-presentValue_)));
}
}

/**
* @dev The present value projected backward by the supply index (rounded down)
* Note: This will overflow (revert) at 2^104/1e18=~20 trillion principal for assets with 18 decimals.
*/
function principalValueSupply(uint64 baseSupplyIndex_, uint256 presentValue_) internal pure returns (uint104) {
return safe104((presentValue_ * BASE_INDEX_SCALE) / baseSupplyIndex_);
}

/**
* @dev The present value projected backward by the borrow index (rounded up)
* Note: This will overflow (revert) at 2^104/1e18=~20 trillion principal for assets with 18 decimals.
*/
function principalValueBorrow(uint64 baseBorrowIndex_, uint256 presentValue_) internal pure returns (uint104) {
return safe104((presentValue_ * BASE_INDEX_SCALE + baseBorrowIndex_ - 1) / baseBorrowIndex_);
}
}
106 changes: 41 additions & 65 deletions src/vendor/CometExtInterface.sol
Original file line number Diff line number Diff line change
@@ -1,92 +1,68 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.21;
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.19;

struct TotalsBasic {
uint64 baseSupplyIndex;
uint64 baseBorrowIndex;
uint64 trackingSupplyIndex;
uint64 trackingBorrowIndex;
uint104 totalSupplyBase;
uint104 totalBorrowBase;
uint40 lastAccrualTime;
uint8 pauseFlags;
}
import "./CometCore.sol";

/**
* @title Compound's Comet Ext Interface
* @notice An efficient monolithic money market protocol
* @author Compound
*/
abstract contract CometExtInterface {
abstract contract CometExtInterface is CometCore {
error BadAmount();
error BadNonce();
error BadSignatory();
error InvalidValueS();
error InvalidValueV();
error SignatureExpired();

function allow(address manager, bool isAllowed) external virtual;
function allow(address manager, bool isAllowed) virtual external;
function allowBySig(address owner, address manager, bool isAllowed, uint256 nonce, uint256 expiry, uint8 v, bytes32 r, bytes32 s) virtual external;

function allowBySig(
address owner,
address manager,
bool isAllowed,
uint256 nonce,
uint256 expiry,
uint8 v,
bytes32 r,
bytes32 s
) external virtual;
function collateralBalanceOf(address account, address asset) virtual external view returns (uint128);
function baseTrackingAccrued(address account) virtual external view returns (uint64);

function collateralBalanceOf(address account, address asset) external view virtual returns (uint128);
function baseAccrualScale() virtual external view returns (uint64);
function baseIndexScale() virtual external view returns (uint64);
function factorScale() virtual external view returns (uint64);
function priceScale() virtual external view returns (uint64);

function baseTrackingAccrued(address account) external view virtual returns (uint64);
function maxAssets() virtual external view returns (uint8);

function baseAccrualScale() external view virtual returns (uint64);
function totalsBasic() virtual external view returns (TotalsBasic memory);

function baseIndexScale() external view virtual returns (uint64);

function factorScale() external view virtual returns (uint64);

function priceScale() external view virtual returns (uint64);

function maxAssets() external view virtual returns (uint8);

function totalsBasic() external view virtual returns (TotalsBasic memory);

function version() external view virtual returns (string memory);
function version() virtual external view returns (string memory);

/**
* ===== ERC20 interfaces =====
* Does not include the following functions/events, which are defined in `CometMainInterface` instead:
* - function decimals() virtual external view returns (uint8)
* - function totalSupply() virtual external view returns (uint256)
* - function transfer(address dst, uint amount) virtual external returns (bool)
* - function transferFrom(address src, address dst, uint amount) virtual external returns (bool)
* - function balanceOf(address owner) virtual external view returns (uint256)
* - event Transfer(address indexed from, address indexed to, uint256 amount)
*/
function name() external view virtual returns (string memory);

function symbol() external view virtual returns (string memory);
* ===== ERC20 interfaces =====
* Does not include the following functions/events, which are defined in `CometMainInterface` instead:
* - function decimals() virtual external view returns (uint8)
* - function totalSupply() virtual external view returns (uint256)
* - function transfer(address dst, uint amount) virtual external returns (bool)
* - function transferFrom(address src, address dst, uint amount) virtual external returns (bool)
* - function balanceOf(address owner) virtual external view returns (uint256)
* - event Transfer(address indexed from, address indexed to, uint256 amount)
*/
function name() virtual external view returns (string memory);
function symbol() virtual external view returns (string memory);

/**
* @notice Approve `spender` to transfer up to `amount` from `src`
* @dev This will overwrite the approval amount for `spender`
* and is subject to issues noted [here](https://eips.ethereum.org/EIPS/eip-20#approve)
* @param spender The address of the account which may transfer tokens
* @param amount The number of tokens that are approved (-1 means infinite)
* @return Whether or not the approval succeeded
*/
function approve(address spender, uint256 amount) external virtual returns (bool);
* @notice Approve `spender` to transfer up to `amount` from `src`
* @dev This will overwrite the approval amount for `spender`
* and is subject to issues noted [here](https://eips.ethereum.org/EIPS/eip-20#approve)
* @param spender The address of the account which may transfer tokens
* @param amount The number of tokens that are approved (-1 means infinite)
* @return Whether or not the approval succeeded
*/
function approve(address spender, uint256 amount) virtual external returns (bool);

/**
* @notice Get the current allowance from `owner` for `spender`
* @param owner The address of the account which owns the tokens to be spent
* @param spender The address of the account which may transfer tokens
* @return The number of tokens allowed to be spent (-1 means infinite)
*/
function allowance(address owner, address spender) external view virtual returns (uint256);
* @notice Get the current allowance from `owner` for `spender`
* @param owner The address of the account which owns the tokens to be spent
* @param spender The address of the account which may transfer tokens
* @return The number of tokens allowed to be spent (-1 means infinite)
*/
function allowance(address owner, address spender) virtual external view returns (uint256);

event Approval(address indexed owner, address indexed spender, uint256 amount);
}
}
23 changes: 3 additions & 20 deletions src/vendor/CometInterface.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.21;
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.19;

import "./CometMainInterface.sol";
import "./CometExtInterface.sol";
Expand All @@ -9,21 +9,4 @@ import "./CometExtInterface.sol";
* @notice An efficient monolithic money market protocol
* @author Compound
*/
abstract contract CometInterface is CometMainInterface, CometExtInterface {
struct UserBasic {
int104 principal;
uint64 baseTrackingIndex;
uint64 baseTrackingAccrued;
uint16 assetsIn;
uint8 _reserved;
}

function userBasic(address account) external view virtual returns (UserBasic memory);

struct TotalsCollateral {
uint128 totalSupplyAsset;
uint128 _reserved;
}

function totalsCollateral(address) external virtual returns (TotalsCollateral memory);
}
abstract contract CometInterface is CometMainInterface, CometExtInterface {}
Loading