From 8d2de503ff1b628ce4fab42025f271bc8a713c2c Mon Sep 17 00:00:00 2001 From: andy Date: Wed, 29 Jan 2025 08:47:40 -0500 Subject: [PATCH 1/5] clean --- .../contracts/MarketLiquidityRewards.sol | 482 ------------- .../contracts/contracts/MetaForwarder.sol | 10 - packages/contracts/contracts/TellerV2.sol | 2 +- .../contracts/contracts/TellerV2Context.sol | 4 +- packages/contracts/deploy/teller_v2/deploy.ts | 4 +- .../contracts/tests/GetMetaDataURI_Test.sol | 2 +- ...enderCommitmentForwarder_Combined_Test.txt | 2 +- ...itmentForwarder_OracleLimited_Override.sol | 2 +- ...tmentForwarder_OracleLimited_Unit_Test.sol | 2 +- .../LenderCommitmentForwarder_Override.sol | 2 +- .../LenderCommitmentForwarder_Unit_Test.sol | 2 +- .../tests/LenderManager_Combined_Test.sol | 2 +- .../contracts/tests/LenderManager_Test.sol | 2 +- .../tests/MarketForwarder_Combined_Test.sol | 2 +- .../contracts/tests/MarketForwarder_Test.sol | 2 +- .../MarketLiquidityRewards_Combined_Test.sol | 515 -------------- .../tests/MarketLiquidityRewards_Override.sol | 162 ----- .../tests/MarketLiquidityRewards_Test.sol | 669 ------------------ .../contracts/tests/MarketRegistry_Test.sol | 2 +- packages/contracts/tests/NextDueDate_test.sol | 2 +- packages/contracts/tests/PMT_Test.sol | 2 +- .../LenderCommitmentGroup_Factory_Test.sol | 2 +- .../UniswapPricingLibrary_Test.sol | 2 +- .../tests/TellerV2/TellerV2_Override.sol | 2 +- .../tests/TellerV2/TellerV2_Test.sol | 8 +- .../TellerV2Context_Override.sol | 2 +- .../integration/IntegrationTestHelpers.sol | 4 +- 27 files changed, 28 insertions(+), 1866 deletions(-) delete mode 100644 packages/contracts/contracts/MarketLiquidityRewards.sol delete mode 100644 packages/contracts/contracts/MetaForwarder.sol delete mode 100644 packages/contracts/tests/MarketLiquidityRewards_Combined_Test.sol delete mode 100644 packages/contracts/tests/MarketLiquidityRewards_Override.sol delete mode 100644 packages/contracts/tests/MarketLiquidityRewards_Test.sol diff --git a/packages/contracts/contracts/MarketLiquidityRewards.sol b/packages/contracts/contracts/MarketLiquidityRewards.sol deleted file mode 100644 index ad1792429..000000000 --- a/packages/contracts/contracts/MarketLiquidityRewards.sol +++ /dev/null @@ -1,482 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.0; - -import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; - -import "./interfaces/IMarketLiquidityRewards.sol"; - -import "./interfaces/IMarketRegistry.sol"; -import "./interfaces/ICollateralManager.sol"; -import "./interfaces/ITellerV2.sol"; - -import { BidState } from "./TellerV2Storage.sol"; - -// Libraries -import { MathUpgradeable } from "@openzeppelin/contracts-upgradeable/utils/math/MathUpgradeable.sol"; - -import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/IERC20MetadataUpgradeable.sol"; - -/* -- Allocate and claim rewards for loans based on bidId - -- Anyone can allocate rewards and an allocation has specific parameters that can be set to incentivise certain types of loans - -*/ - -contract MarketLiquidityRewards is IMarketLiquidityRewards, Initializable { - address immutable tellerV2; - address immutable marketRegistry; - address immutable collateralManager; - - uint256 allocationCount; - - //allocationId => rewardAllocation - mapping(uint256 => RewardAllocation) public allocatedRewards; - - //bidId => allocationId => rewardWasClaimed - mapping(uint256 => mapping(uint256 => bool)) public rewardClaimedForBid; - - modifier onlyMarketOwner(uint256 _marketId) { - require( - msg.sender == - IMarketRegistry(marketRegistry).getMarketOwner(_marketId), - "Only market owner can call this function." - ); - _; - } - - event CreatedAllocation( - uint256 allocationId, - address allocator, - uint256 marketId - ); - - event UpdatedAllocation(uint256 allocationId); - - event IncreasedAllocation(uint256 allocationId, uint256 amount); - - event DecreasedAllocation(uint256 allocationId, uint256 amount); - - event DeletedAllocation(uint256 allocationId); - - event ClaimedRewards( - uint256 allocationId, - uint256 bidId, - address recipient, - uint256 amount - ); - - constructor( - address _tellerV2, - address _marketRegistry, - address _collateralManager - ) { - tellerV2 = _tellerV2; - marketRegistry = _marketRegistry; - collateralManager = _collateralManager; - } - - function initialize() external initializer {} - - /** - * @notice Creates a new token allocation and transfers the token amount into escrow in this contract - * @param _allocation - The RewardAllocation struct data to create - * @return allocationId_ - */ - function allocateRewards(RewardAllocation calldata _allocation) - public - virtual - returns (uint256 allocationId_) - { - allocationId_ = allocationCount++; - - require( - _allocation.allocator == msg.sender, - "Invalid allocator address" - ); - - require( - _allocation.requiredPrincipalTokenAddress != address(0), - "Invalid required principal token address" - ); - - IERC20Upgradeable(_allocation.rewardTokenAddress).transferFrom( - msg.sender, - address(this), - _allocation.rewardTokenAmount - ); - - allocatedRewards[allocationId_] = _allocation; - - emit CreatedAllocation( - allocationId_, - _allocation.allocator, - _allocation.marketId - ); - } - - /** - * @notice Allows the allocator to update properties of an allocation - * @param _allocationId - The id for the allocation - * @param _minimumCollateralPerPrincipalAmount - The required collateralization ratio - * @param _rewardPerLoanPrincipalAmount - The reward to give per principal amount - * @param _bidStartTimeMin - The block timestamp that loans must have been accepted after to claim rewards - * @param _bidStartTimeMax - The block timestamp that loans must have been accepted before to claim rewards - */ - function updateAllocation( - uint256 _allocationId, - uint256 _minimumCollateralPerPrincipalAmount, - uint256 _rewardPerLoanPrincipalAmount, - uint32 _bidStartTimeMin, - uint32 _bidStartTimeMax - ) public virtual { - RewardAllocation storage allocation = allocatedRewards[_allocationId]; - - require( - msg.sender == allocation.allocator, - "Only the allocator can update allocation rewards." - ); - - allocation - .minimumCollateralPerPrincipalAmount = _minimumCollateralPerPrincipalAmount; - allocation.rewardPerLoanPrincipalAmount = _rewardPerLoanPrincipalAmount; - allocation.bidStartTimeMin = _bidStartTimeMin; - allocation.bidStartTimeMax = _bidStartTimeMax; - - emit UpdatedAllocation(_allocationId); - } - - /** - * @notice Allows anyone to add tokens to an allocation - * @param _allocationId - The id for the allocation - * @param _tokenAmount - The amount of tokens to add - */ - function increaseAllocationAmount( - uint256 _allocationId, - uint256 _tokenAmount - ) public virtual { - IERC20Upgradeable(allocatedRewards[_allocationId].rewardTokenAddress) - .transferFrom(msg.sender, address(this), _tokenAmount); - allocatedRewards[_allocationId].rewardTokenAmount += _tokenAmount; - - emit IncreasedAllocation(_allocationId, _tokenAmount); - } - - /** - * @notice Allows the allocator to withdraw some or all of the funds within an allocation - * @param _allocationId - The id for the allocation - * @param _tokenAmount - The amount of tokens to withdraw - */ - function deallocateRewards(uint256 _allocationId, uint256 _tokenAmount) - public - virtual - { - require( - msg.sender == allocatedRewards[_allocationId].allocator, - "Only the allocator can deallocate rewards." - ); - - //enforce that the token amount withdraw must be LEQ to the reward amount for this allocation - if (_tokenAmount > allocatedRewards[_allocationId].rewardTokenAmount) { - _tokenAmount = allocatedRewards[_allocationId].rewardTokenAmount; - } - - //subtract amount reward before transfer - _decrementAllocatedAmount(_allocationId, _tokenAmount); - - IERC20Upgradeable(allocatedRewards[_allocationId].rewardTokenAddress) - .transfer(msg.sender, _tokenAmount); - - //if the allocated rewards are drained completely, delete the storage slot for it - if (allocatedRewards[_allocationId].rewardTokenAmount == 0) { - delete allocatedRewards[_allocationId]; - - emit DeletedAllocation(_allocationId); - } else { - emit DecreasedAllocation(_allocationId, _tokenAmount); - } - } - - struct LoanSummary { - address borrower; - address lender; - uint256 marketId; - address principalTokenAddress; - uint256 principalAmount; - uint32 acceptedTimestamp; - uint32 lastRepaidTimestamp; - BidState bidState; - } - - function _getLoanSummary(uint256 _bidId) - internal - returns (LoanSummary memory _summary) - { - ( - _summary.borrower, - _summary.lender, - _summary.marketId, - _summary.principalTokenAddress, - _summary.principalAmount, - _summary.acceptedTimestamp, - _summary.lastRepaidTimestamp, - _summary.bidState - ) = ITellerV2(tellerV2).getLoanSummary(_bidId); - } - - /** - * @notice Allows a borrower or lender to withdraw the allocated ERC20 reward for their loan - * @param _allocationId - The id for the reward allocation - * @param _bidId - The id for the loan. Each loan only grants one reward per allocation. - */ - function claimRewards(uint256 _allocationId, uint256 _bidId) - external - virtual - { - RewardAllocation storage allocatedReward = allocatedRewards[ - _allocationId - ]; - - //set a flag that this reward was claimed for this bid to defend against re-entrancy - require( - !rewardClaimedForBid[_bidId][_allocationId], - "reward already claimed" - ); - rewardClaimedForBid[_bidId][_allocationId] = true; - - //make this a struct ? - LoanSummary memory loanSummary = _getLoanSummary(_bidId); //ITellerV2(tellerV2).getLoanSummary(_bidId); - - address collateralTokenAddress = allocatedReward - .requiredCollateralTokenAddress; - - //require that the loan was started in the correct timeframe - _verifyLoanStartTime( - loanSummary.acceptedTimestamp, - allocatedReward.bidStartTimeMin, - allocatedReward.bidStartTimeMax - ); - - //if a collateral token address is set on the allocation, verify that the bid has enough collateral ratio - if (collateralTokenAddress != address(0)) { - uint256 collateralAmount = ICollateralManager(collateralManager) - .getCollateralAmount(_bidId, collateralTokenAddress); - - //require collateral amount - _verifyCollateralAmount( - collateralTokenAddress, - collateralAmount, - loanSummary.principalTokenAddress, - loanSummary.principalAmount, - allocatedReward.minimumCollateralPerPrincipalAmount - ); - } - - require( - loanSummary.principalTokenAddress == - allocatedReward.requiredPrincipalTokenAddress, - "Principal token address mismatch for allocation" - ); - - require( - loanSummary.marketId == allocatedRewards[_allocationId].marketId, - "MarketId mismatch for allocation" - ); - - uint256 principalTokenDecimals = IERC20MetadataUpgradeable( - loanSummary.principalTokenAddress - ).decimals(); - - address rewardRecipient = _verifyAndReturnRewardRecipient( - allocatedReward.allocationStrategy, - loanSummary.bidState, - loanSummary.borrower, - loanSummary.lender - ); - - uint32 loanDuration = loanSummary.lastRepaidTimestamp - - loanSummary.acceptedTimestamp; - - uint256 amountToReward = _calculateRewardAmount( - loanSummary.principalAmount, - loanDuration, - principalTokenDecimals, - allocatedReward.rewardPerLoanPrincipalAmount - ); - - if (amountToReward > allocatedReward.rewardTokenAmount) { - amountToReward = allocatedReward.rewardTokenAmount; - } - - require(amountToReward > 0, "Nothing to claim."); - - _decrementAllocatedAmount(_allocationId, amountToReward); - - //transfer tokens reward to the msgsender - IERC20Upgradeable(allocatedRewards[_allocationId].rewardTokenAddress) - .transfer(rewardRecipient, amountToReward); - - emit ClaimedRewards( - _allocationId, - _bidId, - rewardRecipient, - amountToReward - ); - } - - /** - * @notice Verifies that the bid state is appropriate for claiming rewards based on the allocation strategy and then returns the address of the reward recipient(borrower or lender) - * @param _strategy - The strategy for the reward allocation. - * @param _bidState - The bid state of the loan. - * @param _borrower - The borrower of the loan. - * @param _lender - The lender of the loan. - * @return rewardRecipient_ The address that will receive the rewards. Either the borrower or lender. - */ - function _verifyAndReturnRewardRecipient( - AllocationStrategy _strategy, - BidState _bidState, - address _borrower, - address _lender - ) internal virtual returns (address rewardRecipient_) { - if (_strategy == AllocationStrategy.BORROWER) { - require(_bidState == BidState.PAID, "Invalid bid state for loan."); - - rewardRecipient_ = _borrower; - } else if (_strategy == AllocationStrategy.LENDER) { - //Loan must have been accepted in the past - require( - _bidState >= BidState.ACCEPTED, - "Invalid bid state for loan." - ); - - rewardRecipient_ = _lender; - } else { - revert("Unknown allocation strategy"); - } - } - - /** - * @notice Decrements the amount allocated to keep track of tokens in escrow - * @param _allocationId - The id for the allocation to decrement - * @param _amount - The amount of ERC20 to decrement - */ - function _decrementAllocatedAmount(uint256 _allocationId, uint256 _amount) - internal - { - allocatedRewards[_allocationId].rewardTokenAmount -= _amount; - } - - /** - * @notice Calculates the reward to claim for the allocation - * @param _loanPrincipal - The amount of principal for the loan for which to reward - * @param _loanDuration - The duration of the loan in seconds - * @param _principalTokenDecimals - The number of decimals of the principal token - * @param _rewardPerLoanPrincipalAmount - The amount of reward per loan principal amount, expanded by the principal token decimals - * @return The amount of ERC20 to reward - */ - function _calculateRewardAmount( - uint256 _loanPrincipal, - uint256 _loanDuration, - uint256 _principalTokenDecimals, - uint256 _rewardPerLoanPrincipalAmount - ) internal view returns (uint256) { - uint256 rewardPerYear = MathUpgradeable.mulDiv( - _loanPrincipal, - _rewardPerLoanPrincipalAmount, //expanded by principal token decimals - 10**_principalTokenDecimals - ); - - return MathUpgradeable.mulDiv(rewardPerYear, _loanDuration, 365 days); - } - - /** - * @notice Verifies that the collateral ratio for the loan was sufficient based on _minimumCollateralPerPrincipalAmount of the allocation - * @param _collateralTokenAddress - The contract address for the collateral token - * @param _collateralAmount - The number of decimals of the collateral token - * @param _principalTokenAddress - The contract address for the principal token - * @param _principalAmount - The number of decimals of the principal token - * @param _minimumCollateralPerPrincipalAmount - The amount of collateral required per principal amount. Expanded by the principal token decimals and collateral token decimals. - */ - function _verifyCollateralAmount( - address _collateralTokenAddress, - uint256 _collateralAmount, - address _principalTokenAddress, - uint256 _principalAmount, - uint256 _minimumCollateralPerPrincipalAmount - ) internal virtual { - uint256 principalTokenDecimals = IERC20MetadataUpgradeable( - _principalTokenAddress - ).decimals(); - - uint256 collateralTokenDecimals = IERC20MetadataUpgradeable( - _collateralTokenAddress - ).decimals(); - - uint256 minCollateral = _requiredCollateralAmount( - _principalAmount, - principalTokenDecimals, - collateralTokenDecimals, - _minimumCollateralPerPrincipalAmount - ); - - require( - _collateralAmount >= minCollateral, - "Loan does not meet minimum collateralization ratio." - ); - } - - /** - * @notice Calculates the minimum amount of collateral the loan requires based on principal amount - * @param _principalAmount - The number of decimals of the principal token - * @param _principalTokenDecimals - The number of decimals of the principal token - * @param _collateralTokenDecimals - The number of decimals of the collateral token - * @param _minimumCollateralPerPrincipalAmount - The amount of collateral required per principal amount. Expanded by the principal token decimals and collateral token decimals. - */ - function _requiredCollateralAmount( - uint256 _principalAmount, - uint256 _principalTokenDecimals, - uint256 _collateralTokenDecimals, - uint256 _minimumCollateralPerPrincipalAmount - ) internal view virtual returns (uint256) { - return - MathUpgradeable.mulDiv( - _principalAmount, - _minimumCollateralPerPrincipalAmount, //expanded by principal token decimals and collateral token decimals - 10**(_principalTokenDecimals + _collateralTokenDecimals) - ); - } - - /** - * @notice Verifies that the loan start time is within the bounds set by the allocation requirements - * @param _loanStartTime - The timestamp when the loan was accepted - * @param _minStartTime - The minimum time required, after which the loan must have been accepted - * @param _maxStartTime - The maximum time required, before which the loan must have been accepted - */ - function _verifyLoanStartTime( - uint32 _loanStartTime, - uint32 _minStartTime, - uint32 _maxStartTime - ) internal virtual { - require( - _minStartTime == 0 || _loanStartTime > _minStartTime, - "Loan was accepted before the min start time." - ); - require( - _maxStartTime == 0 || _loanStartTime < _maxStartTime, - "Loan was accepted after the max start time." - ); - } - - /** - * @notice Returns the amount of reward tokens remaining in the allocation - * @param _allocationId - The id for the allocation - */ - function getRewardTokenAmount(uint256 _allocationId) - public - view - override - returns (uint256) - { - return allocatedRewards[_allocationId].rewardTokenAmount; - } -} diff --git a/packages/contracts/contracts/MetaForwarder.sol b/packages/contracts/contracts/MetaForwarder.sol deleted file mode 100644 index 5dae3f3a8..000000000 --- a/packages/contracts/contracts/MetaForwarder.sol +++ /dev/null @@ -1,10 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.9; - -import "@openzeppelin/contracts-upgradeable/metatx/MinimalForwarderUpgradeable.sol"; - -contract MetaForwarder is MinimalForwarderUpgradeable { - function initialize() external initializer { - __EIP712_init_unchained("TellerMetaForwarder", "0.0.1"); - } -} diff --git a/packages/contracts/contracts/TellerV2.sol b/packages/contracts/contracts/TellerV2.sol index a6c633cea..d1459d8c9 100644 --- a/packages/contracts/contracts/TellerV2.sol +++ b/packages/contracts/contracts/TellerV2.sol @@ -174,7 +174,7 @@ contract TellerV2 is /** Constructor **/ - constructor(address trustedForwarder) TellerV2Context(trustedForwarder) {} + constructor( ) TellerV2Context( ) {} /** External Functions **/ diff --git a/packages/contracts/contracts/TellerV2Context.sol b/packages/contracts/contracts/TellerV2Context.sol index 5ebb607d5..275a0f4d6 100644 --- a/packages/contracts/contracts/TellerV2Context.sol +++ b/packages/contracts/contracts/TellerV2Context.sol @@ -30,8 +30,8 @@ abstract contract TellerV2Context is address sender ); - constructor(address trustedForwarder) - ERC2771ContextUpgradeable(trustedForwarder) + constructor( ) + ERC2771ContextUpgradeable( address(0) ) //we use custom forwarders, not one specific {} /** diff --git a/packages/contracts/deploy/teller_v2/deploy.ts b/packages/contracts/deploy/teller_v2/deploy.ts index dba095e07..9cb2936d6 100644 --- a/packages/contracts/deploy/teller_v2/deploy.ts +++ b/packages/contracts/deploy/teller_v2/deploy.ts @@ -1,7 +1,7 @@ import { DeployFunction } from 'hardhat-deploy/dist/types' const deployFn: DeployFunction = async (hre) => { - const trustedForwarder = await hre.contracts.get('MetaForwarder') + const v2Calculations = await hre.deployments.get('V2Calculations') const tellerV2 = await hre.deployProxy('TellerV2', { @@ -10,7 +10,7 @@ const deployFn: DeployFunction = async (hre) => { 'state-variable-immutable', 'external-library-linking', ], - constructorArgs: [await trustedForwarder.getAddress()], + constructorArgs: [ ], initializer: false, libraries: { V2Calculations: v2Calculations.address, diff --git a/packages/contracts/tests/GetMetaDataURI_Test.sol b/packages/contracts/tests/GetMetaDataURI_Test.sol index 6f94b2a45..41c042f02 100644 --- a/packages/contracts/tests/GetMetaDataURI_Test.sol +++ b/packages/contracts/tests/GetMetaDataURI_Test.sol @@ -5,7 +5,7 @@ import "./Testable.sol"; import "../contracts/TellerV2.sol"; contract GetMetaDataURI_Test is Testable, TellerV2 { - constructor() TellerV2(address(0)) {} + constructor() TellerV2( ) {} function setUp() public { // Old depreciated _metadataURI on bid struct diff --git a/packages/contracts/tests/LenderCommitmentForwarder/LenderCommitmentForwarder_Combined_Test.txt b/packages/contracts/tests/LenderCommitmentForwarder/LenderCommitmentForwarder_Combined_Test.txt index be3e62172..b53c85a22 100644 --- a/packages/contracts/tests/LenderCommitmentForwarder/LenderCommitmentForwarder_Combined_Test.txt +++ b/packages/contracts/tests/LenderCommitmentForwarder/LenderCommitmentForwarder_Combined_Test.txt @@ -867,7 +867,7 @@ contract LenderCommitmentUser is User { //Move to a helper file ! contract LenderCommitmentForwarderTest_TellerV2Mock is TellerV2Context { - constructor() TellerV2Context(address(0)) {} + constructor() TellerV2Context( ) {} function __setMarketRegistry(address _marketRegistry) external { marketRegistry = IMarketRegistry(_marketRegistry); diff --git a/packages/contracts/tests/LenderCommitmentForwarder/LenderCommitmentForwarder_OracleLimited_Override.sol b/packages/contracts/tests/LenderCommitmentForwarder/LenderCommitmentForwarder_OracleLimited_Override.sol index 95a406bd0..68164abea 100644 --- a/packages/contracts/tests/LenderCommitmentForwarder/LenderCommitmentForwarder_OracleLimited_Override.sol +++ b/packages/contracts/tests/LenderCommitmentForwarder/LenderCommitmentForwarder_OracleLimited_Override.sol @@ -67,7 +67,7 @@ contract LenderCommitmentForwarder_U1_Override is LenderCommitmentForwarder_U1 { } contract LenderCommitmentForwarderTest_TellerV2Mock is TellerV2Context { - constructor() TellerV2Context(address(0)) {} + constructor() TellerV2Context( ) {} function getSenderForMarket(uint256 _marketId) external diff --git a/packages/contracts/tests/LenderCommitmentForwarder/LenderCommitmentForwarder_OracleLimited_Unit_Test.sol b/packages/contracts/tests/LenderCommitmentForwarder/LenderCommitmentForwarder_OracleLimited_Unit_Test.sol index a7f3927a9..545d382a7 100644 --- a/packages/contracts/tests/LenderCommitmentForwarder/LenderCommitmentForwarder_OracleLimited_Unit_Test.sol +++ b/packages/contracts/tests/LenderCommitmentForwarder/LenderCommitmentForwarder_OracleLimited_Unit_Test.sol @@ -2486,7 +2486,7 @@ contract LenderCommitmentUser is User { //Move to a helper file ! contract LenderCommitmentForwarderTest_TellerV2Mock is TellerV2Context { - constructor() TellerV2Context(address(0)) {} + constructor() TellerV2Context( ) {} function __setMarketRegistry(address _marketRegistry) external { marketRegistry = IMarketRegistry(_marketRegistry); diff --git a/packages/contracts/tests/LenderCommitmentForwarder/LenderCommitmentForwarder_Override.sol b/packages/contracts/tests/LenderCommitmentForwarder/LenderCommitmentForwarder_Override.sol index 76104a03f..4b74201ef 100644 --- a/packages/contracts/tests/LenderCommitmentForwarder/LenderCommitmentForwarder_Override.sol +++ b/packages/contracts/tests/LenderCommitmentForwarder/LenderCommitmentForwarder_Override.sol @@ -62,7 +62,7 @@ contract LenderCommitmentForwarder_Override is LenderCommitmentForwarder_G2 { } contract LenderCommitmentForwarderTest_TellerV2Mock is TellerV2Context { - constructor() TellerV2Context(address(0)) {} + constructor() TellerV2Context( ) {} function getSenderForMarket(uint256 _marketId) external diff --git a/packages/contracts/tests/LenderCommitmentForwarder/LenderCommitmentForwarder_Unit_Test.sol b/packages/contracts/tests/LenderCommitmentForwarder/LenderCommitmentForwarder_Unit_Test.sol index 0baec2f0c..c375a380d 100644 --- a/packages/contracts/tests/LenderCommitmentForwarder/LenderCommitmentForwarder_Unit_Test.sol +++ b/packages/contracts/tests/LenderCommitmentForwarder/LenderCommitmentForwarder_Unit_Test.sol @@ -1443,7 +1443,7 @@ contract LenderCommitmentUser is User { //Move to a helper file ! contract LenderCommitmentForwarderTest_TellerV2Mock is TellerV2Context { - constructor() TellerV2Context(address(0)) {} + constructor() TellerV2Context( ) {} function __setMarketRegistry(address _marketRegistry) external { marketRegistry = IMarketRegistry(_marketRegistry); diff --git a/packages/contracts/tests/LenderManager_Combined_Test.sol b/packages/contracts/tests/LenderManager_Combined_Test.sol index 7cee2f19a..5963ba33e 100644 --- a/packages/contracts/tests/LenderManager_Combined_Test.sol +++ b/packages/contracts/tests/LenderManager_Combined_Test.sol @@ -146,7 +146,7 @@ contract LenderManagerUser is User { //Move to a helper or change it contract LenderCommitmentTester is TellerV2Context { - constructor() TellerV2Context(address(0)) {} + constructor() TellerV2Context( ) {} function getSenderForMarket(uint256 _marketId) external diff --git a/packages/contracts/tests/LenderManager_Test.sol b/packages/contracts/tests/LenderManager_Test.sol index cd62c9ed6..2c1067add 100644 --- a/packages/contracts/tests/LenderManager_Test.sol +++ b/packages/contracts/tests/LenderManager_Test.sol @@ -216,7 +216,7 @@ contract LenderManagerUser is User { //Move to a helper or change it contract LenderCommitmentTester is TellerV2Context { - constructor() TellerV2Context(address(0)) {} + constructor() TellerV2Context( ) {} function getSenderForMarket(uint256 _marketId) external diff --git a/packages/contracts/tests/MarketForwarder_Combined_Test.sol b/packages/contracts/tests/MarketForwarder_Combined_Test.sol index 0aed78f3a..8c803e543 100644 --- a/packages/contracts/tests/MarketForwarder_Combined_Test.sol +++ b/packages/contracts/tests/MarketForwarder_Combined_Test.sol @@ -138,7 +138,7 @@ contract MarketForwarderUser is User { //Move to a helper //this is a tellerV2 mock contract MarketForwarderTester is TellerV2Context { - constructor() TellerV2Context(address(0)) {} + constructor() TellerV2Context( ) {} function __setMarketRegistry(address _marketRegistry) external { marketRegistry = IMarketRegistry(_marketRegistry); diff --git a/packages/contracts/tests/MarketForwarder_Test.sol b/packages/contracts/tests/MarketForwarder_Test.sol index 53bd9e336..9732f44a6 100644 --- a/packages/contracts/tests/MarketForwarder_Test.sol +++ b/packages/contracts/tests/MarketForwarder_Test.sol @@ -147,7 +147,7 @@ contract MarketForwarderUser is User { } contract MarketForwarderTellerV2Mock is TellerV2Context { - constructor() TellerV2Context(address(0)) {} + constructor() TellerV2Context( ) {} function setMarketRegistry(address _marketRegistry) external { marketRegistry = IMarketRegistry(_marketRegistry); diff --git a/packages/contracts/tests/MarketLiquidityRewards_Combined_Test.sol b/packages/contracts/tests/MarketLiquidityRewards_Combined_Test.sol deleted file mode 100644 index a50ec7e5a..000000000 --- a/packages/contracts/tests/MarketLiquidityRewards_Combined_Test.sol +++ /dev/null @@ -1,515 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.0; - -import "@openzeppelin/contracts/utils/Address.sol"; -import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; -import "../contracts/TellerV2MarketForwarder_G1.sol"; - -import "./tokens/TestERC20Token.sol"; -import "../contracts/TellerV2Context.sol"; - -import { Testable } from "./Testable.sol"; - -import { Collateral, CollateralType } from "../contracts/interfaces/escrow/ICollateralEscrowV1.sol"; - -import { User } from "./Test_Helpers.sol"; - -import "../contracts/mock/MarketRegistryMock.sol"; -import "../contracts/mock/CollateralManagerMock.sol"; - -import "../contracts/MarketLiquidityRewards.sol"; - -import "forge-std/console.sol"; - -contract MarketLiquidityRewards_Test is Testable, MarketLiquidityRewards { - MarketLiquidityUser private marketOwner; - MarketLiquidityUser private lender; - MarketLiquidityUser private borrower; - - uint256 immutable startTime = 1678122531; - - // address tokenAddress; - uint256 marketId; - uint256 maxAmount; - - address[] emptyArray; - address[] borrowersArray; - - uint32 maxLoanDuration; - uint16 minInterestRate; - uint32 expiration; - - TestERC20Token rewardToken; - uint8 constant rewardTokenDecimals = 18; - - TestERC20Token principalToken; - uint8 constant principalTokenDecimals = 18; - - TestERC20Token collateralToken; - uint8 constant collateralTokenDecimals = 6; - - bool verifyLoanStartTimeWasCalled; - - bool verifyRewardRecipientWasCalled; - bool verifyCollateralAmountWasCalled; - - constructor() - MarketLiquidityRewards( - address(new TellerV2Mock()), - address(new MarketRegistryMock()), - address(new CollateralManagerMock()) - ) - {} - - function setUp() public { - marketOwner = new MarketLiquidityUser(address(tellerV2), (this)); - borrower = new MarketLiquidityUser(address(tellerV2), (this)); - lender = new MarketLiquidityUser(address(tellerV2), (this)); - TellerV2Mock(tellerV2).__setMarketRegistry(address(marketRegistry)); - - MarketRegistryMock(marketRegistry).setMarketOwner(address(marketOwner)); - - //tokenAddress = address(0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174); - marketId = 2; - maxAmount = 100000000000000000000; - maxLoanDuration = 2480000; - minInterestRate = 3000; - expiration = uint32(block.timestamp) + uint32(64000); - - marketOwner.setTrustedMarketForwarder(marketId, address(this)); - lender.approveMarketForwarder(marketId, address(this)); - - borrowersArray = new address[](1); - borrowersArray[0] = address(borrower); - - rewardToken = new TestERC20Token( - "Test Wrapped ETH", - "TWETH", - 100000, - rewardTokenDecimals - ); - - principalToken = new TestERC20Token( - "Test Wrapped ETH", - "TWETH", - 100000, - principalTokenDecimals - ); - - collateralToken = new TestERC20Token( - "Test USDC", - "TUSDC", - 100000, - collateralTokenDecimals - ); - - IERC20Upgradeable(address(rewardToken)).transfer( - address(lender), - 10000 - ); - - vm.warp(startTime + 100); - //delete allocationCount; - - verifyLoanStartTimeWasCalled = false; - - verifyRewardRecipientWasCalled = false; - verifyCollateralAmountWasCalled = false; - } - - function _setAllocation(uint256 allocationId) internal { - uint256 rewardTokenAmount = 0; - - RewardAllocation memory _allocation = IMarketLiquidityRewards - .RewardAllocation({ - allocator: address(lender), - marketId: marketId, - rewardTokenAddress: address(rewardToken), - rewardTokenAmount: rewardTokenAmount, - requiredPrincipalTokenAddress: address(principalToken), - requiredCollateralTokenAddress: address(collateralToken), - minimumCollateralPerPrincipalAmount: 0, - rewardPerLoanPrincipalAmount: 1e18, - bidStartTimeMin: uint32(startTime), - bidStartTimeMax: uint32(startTime + 10000), - allocationStrategy: AllocationStrategy.BORROWER - }); - - allocatedRewards[allocationId] = _allocation; - } - - function test_allocateRewards() public { - uint256 rewardTokenAmount = 500; - - RewardAllocation memory _allocation = IMarketLiquidityRewards - .RewardAllocation({ - allocator: address(lender), - marketId: marketId, - rewardTokenAddress: address(rewardToken), - rewardTokenAmount: rewardTokenAmount, - requiredPrincipalTokenAddress: address(principalToken), - requiredCollateralTokenAddress: address(collateralToken), - minimumCollateralPerPrincipalAmount: 0, - rewardPerLoanPrincipalAmount: 0, - bidStartTimeMin: uint32(startTime), - bidStartTimeMax: uint32(startTime + 10000), - allocationStrategy: AllocationStrategy.BORROWER - }); - - lender._approveERC20Token( - address(rewardToken), - address(this), - rewardTokenAmount - ); - - uint256 allocationId = lender._allocateRewards(_allocation); - } - - function test_increaseAllocationAmount() public { - uint256 allocationId = 0; - uint256 amountToIncrease = 100; - - _setAllocation(allocationId); - - uint256 amountBefore = allocatedRewards[allocationId].rewardTokenAmount; - - lender._approveERC20Token( - address(rewardToken), - address(this), - amountToIncrease - ); - - lender._increaseAllocationAmount(allocationId, amountToIncrease); - - uint256 amountAfter = allocatedRewards[allocationId].rewardTokenAmount; - - assertEq( - amountAfter, - amountBefore + amountToIncrease, - "Allocation did not increase" - ); - } - - function test_deallocateRewards() public { - uint256 allocationId = 0; - - _setAllocation(allocationId); - - uint256 amountBefore = allocatedRewards[allocationId].rewardTokenAmount; - - lender._deallocateRewards(allocationId, amountBefore); - - uint256 amountAfter = allocatedRewards[allocationId].rewardTokenAmount; - - assertEq(amountAfter, 0, "Allocation was not deleted"); - } - - function test_claimRewards() public { - Bid memory mockBid; - - mockBid.borrower = address(borrower); - mockBid.lender = address(lender); - mockBid.marketplaceId = marketId; - mockBid.loanDetails.loanDuration = 80000; - mockBid.loanDetails.lendingToken = (principalToken); - mockBid.loanDetails.principal = 10000; - mockBid.loanDetails.acceptedTimestamp = uint32(block.timestamp); - mockBid.loanDetails.lastRepaidTimestamp = uint32( - block.timestamp + 5000 - ); - mockBid.state = BidState.PAID; - - TellerV2Mock(tellerV2).setMockBid(mockBid); - - uint256 allocationId = 0; - uint256 bidId = 0; - - _setAllocation(allocationId); - allocatedRewards[allocationId].rewardTokenAmount = 4000; - - borrower._claimRewards(allocationId, bidId); - - assertEq( - verifyLoanStartTimeWasCalled, - true, - "verifyLoanStartTime was not called" - ); - - assertEq( - verifyRewardRecipientWasCalled, - true, - "verifyRewardRecipient was not called" - ); - - assertEq( - verifyCollateralAmountWasCalled, - true, - "verifyCollateralAmount was not called" - ); - - //add some negative tests (unit) - //add comments to all of the methods - } - - function test_calculateRewardAmount_weth_principal() public { - uint256 loanPrincipal = 1e8; - uint256 principalTokenDecimals = 18; - uint32 loanDuration = 60 * 60 * 24 * 365; - - uint256 rewardPerLoanPrincipalAmount = 1e16; // expanded by token decimals so really 0.01 - - uint256 rewardAmount = super._calculateRewardAmount( - loanPrincipal, - loanDuration, - principalTokenDecimals, - rewardPerLoanPrincipalAmount - ); - - assertEq(rewardAmount, 1e6, "Invalid reward amount"); - } - - function test_calculateRewardAmount_usdc_principal() public { - uint256 loanPrincipal = 1e8; - uint256 principalTokenDecimals = 6; - uint32 loanDuration = 60 * 60 * 24 * 365; - - uint256 rewardPerLoanPrincipalAmount = 1e4; // expanded by token decimals so really 0.01 - - uint256 rewardAmount = super._calculateRewardAmount( - loanPrincipal, - loanDuration, - principalTokenDecimals, - rewardPerLoanPrincipalAmount - ); - - assertEq(rewardAmount, 1e6, "Invalid reward amount"); - } - - function test_requiredCollateralAmount() public { - uint256 collateralTokenDecimals = 6; - - uint256 loanPrincipal = 1e8; - uint256 principalTokenDecimals = 6; - - uint256 minimumCollateralPerPrincipal = 1e4 * 1e6; // expanded by token decimals so really 0.01 - - uint256 minCollateral = super._requiredCollateralAmount( - loanPrincipal, - principalTokenDecimals, - collateralTokenDecimals, - minimumCollateralPerPrincipal - ); - - assertEq(minCollateral, 1e6, "Invalid min collateral calculation"); - } - - function test_decrementAllocatedAmount() public { - uint256 allocationId = 0; - - _setAllocation(allocationId); - - uint256 amount = 100; - - allocatedRewards[allocationId].rewardTokenAmount += amount; - - super._decrementAllocatedAmount(allocationId, amount); - - assertEq( - allocatedRewards[allocationId].rewardTokenAmount, - 0, - "allocation amount not decremented" - ); - } - - /* function test_verifyCollateralAmount() public { - - vm.expectRevert(); - super._verifyCollateralAmount( - address(collateralToken), - 100, - address(principalToken), - 1000, - 5000 * 1e18 * 1e18 - ); - - - }*/ - - function test_verifyLoanStartTime_min() public { - vm.expectRevert(bytes("Loan was accepted before the min start time.")); - - super._verifyLoanStartTime(100, 200, 300); - } - - function test_verifyAndReturnRewardRecipient() public { - address recipient = super._verifyAndReturnRewardRecipient( - AllocationStrategy.BORROWER, - BidState.PAID, - address(borrower), - address(lender) - ); - - assertEq(recipient, address(borrower), "incorrect address returned"); - } - - function test_verifyAndReturnRewardRecipient_reverts() public { - vm.expectRevert(); - - address recipient = super._verifyAndReturnRewardRecipient( - AllocationStrategy.BORROWER, - BidState.PENDING, - address(borrower), - address(lender) - ); - } - - function test_verifyLoanStartTime_max() public { - vm.expectRevert(bytes("Loan was accepted after the max start time.")); - - super._verifyLoanStartTime(400, 200, 300); - } - - function allocateRewards( - MarketLiquidityRewards.RewardAllocation calldata _allocation - ) public override returns (uint256 allocationId_) { - super.allocateRewards(_allocation); - } - - function increaseAllocationAmount( - uint256 _allocationId, - uint256 _tokenAmount - ) public override { - super.increaseAllocationAmount(_allocationId, _tokenAmount); - } - - function deallocateRewards(uint256 _allocationId, uint256 _tokenAmount) - public - override - { - super.deallocateRewards(_allocationId, _tokenAmount); - } - - function _verifyAndReturnRewardRecipient( - AllocationStrategy strategy, - BidState bidState, - address borrower, - address lender - ) internal override returns (address rewardRecipient) { - verifyRewardRecipientWasCalled = true; - return address(borrower); - } - - function _verifyCollateralAmount( - address _collateralTokenAddress, - uint256 _collateralAmount, - address _principalTokenAddress, - uint256 _principalAmount, - uint256 _minimumCollateralPerPrincipalAmount - ) internal override { - verifyCollateralAmountWasCalled = true; - } - - function _verifyLoanStartTime( - uint32 loanStartTime, - uint32 minStartTime, - uint32 maxStartTime - ) internal override { - verifyLoanStartTimeWasCalled = true; - } -} - -contract MarketLiquidityUser is User { - MarketLiquidityRewards public immutable liquidityRewards; - - constructor(address _tellerV2, MarketLiquidityRewards _liquidityRewards) - User(_tellerV2) - { - liquidityRewards = _liquidityRewards; - } - - function _allocateRewards( - MarketLiquidityRewards.RewardAllocation calldata _allocation - ) public returns (uint256) { - return liquidityRewards.allocateRewards(_allocation); - } - - function _increaseAllocationAmount( - uint256 _allocationId, - uint256 _allocationAmount - ) public { - liquidityRewards.increaseAllocationAmount( - _allocationId, - _allocationAmount - ); - } - - function _deallocateRewards(uint256 _allocationId, uint256 _amount) public { - liquidityRewards.deallocateRewards(_allocationId, _amount); - } - - function _claimRewards(uint256 _allocationId, uint256 _bidId) public { - return liquidityRewards.claimRewards(_allocationId, _bidId); - } - - function _approveERC20Token(address tokenAddress, address guy, uint256 wad) - public - { - IERC20Upgradeable(tokenAddress).approve(guy, wad); - } -} - -contract TellerV2Mock is TellerV2Context { - Bid mockBid; - - constructor() TellerV2Context(address(0)) {} - - function __setMarketRegistry(address _marketRegistry) external { - marketRegistry = IMarketRegistry(_marketRegistry); - } - - function getSenderForMarket(uint256 _marketId) - external - view - returns (address) - { - return _msgSenderForMarket(_marketId); - } - - function getDataForMarket(uint256 _marketId) - external - view - returns (bytes calldata) - { - return _msgDataForMarket(_marketId); - } - - function setMockBid(Bid calldata bid) public { - mockBid = bid; - } - - function getLoanSummary(uint256 _bidId) - external - view - returns ( - address borrower, - address lender, - uint256 marketId, - address principalTokenAddress, - uint256 principalAmount, - uint32 acceptedTimestamp, - uint32 lastRepaidTimestamp, - BidState bidState - ) - { - Bid storage bid = mockBid; - - borrower = bid.borrower; - lender = bid.lender; - marketId = bid.marketplaceId; - principalTokenAddress = address(bid.loanDetails.lendingToken); - principalAmount = bid.loanDetails.principal; - acceptedTimestamp = bid.loanDetails.acceptedTimestamp; - lastRepaidTimestamp = bid.loanDetails.lastRepaidTimestamp; - bidState = bid.state; - } -} diff --git a/packages/contracts/tests/MarketLiquidityRewards_Override.sol b/packages/contracts/tests/MarketLiquidityRewards_Override.sol deleted file mode 100644 index 8dc459fe8..000000000 --- a/packages/contracts/tests/MarketLiquidityRewards_Override.sol +++ /dev/null @@ -1,162 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.0; - -import "@openzeppelin/contracts/utils/Address.sol"; -import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; -import "../contracts/TellerV2MarketForwarder_G1.sol"; - -import "../contracts/TellerV2Context.sol"; - -import { Testable } from "./Testable.sol"; - -import { Collateral, CollateralType } from "../contracts/interfaces/escrow/ICollateralEscrowV1.sol"; - -import { User } from "./Test_Helpers.sol"; - -import "../contracts/mock/MarketRegistryMock.sol"; -import "../contracts/mock/CollateralManagerMock.sol"; - -import "../contracts/MarketLiquidityRewards.sol"; - -contract MarketLiquidityRewards_Override is MarketLiquidityRewards { - uint256 immutable startTime = 1678122531; - - // address tokenAddress; - uint256 marketId; - uint256 maxAmount; - - address[] emptyArray; - address[] borrowersArray; - - uint32 maxLoanDuration; - uint16 minInterestRate; - uint32 expiration; - - bool public verifyLoanStartTimeWasCalled; - - bool public verifyRewardRecipientWasCalled; - bool public verifyCollateralAmountWasCalled; - - constructor( - address tellerV2, - address marketRegistry, - address collateralManager - ) MarketLiquidityRewards(tellerV2, marketRegistry, collateralManager) {} - - function setAllocation( - uint256 _allocationId, - RewardAllocation memory _allocation - ) public { - allocatedRewards[_allocationId] = _allocation; - } - - function setAllocatedAmount(uint256 _allocationId, uint256 _amount) public { - allocatedRewards[_allocationId].rewardTokenAmount = _amount; - } - - function calculateRewardAmount( - uint256 loanPrincipal, - uint32 loanDuration, - uint256 principalTokenDecimals, - uint256 rewardPerLoanPrincipalAmount - ) public view returns (uint256) { - return - super._calculateRewardAmount( - loanPrincipal, - loanDuration, - principalTokenDecimals, - rewardPerLoanPrincipalAmount - ); - } - - function requiredCollateralAmount( - uint256 loanPrincipal, - uint256 principalTokenDecimals, - uint256 collateralTokenDecimals, - uint256 minimumCollateralPerPrincipal - ) public view returns (uint256) { - return - super._requiredCollateralAmount( - loanPrincipal, - principalTokenDecimals, - collateralTokenDecimals, - minimumCollateralPerPrincipal - ); - } - - function decrementAllocatedAmount( - uint256 _allocationId, - uint256 _tokenAmount - ) public { - super._decrementAllocatedAmount(_allocationId, _tokenAmount); - } - - function verifyLoanStartTime(uint32 a, uint32 b, uint32 c) public { - super._verifyLoanStartTime(a, b, c); - } - - function verifyAndReturnRewardRecipient( - AllocationStrategy allocationStrategy, - BidState bidState, - address borrower, - address lender - ) public returns (address) { - return - super._verifyAndReturnRewardRecipient( - allocationStrategy, - bidState, - borrower, - lender - ); - } - - //overrides - - function allocateRewards( - MarketLiquidityRewards.RewardAllocation calldata _allocation - ) public override returns (uint256 allocationId_) { - super.allocateRewards(_allocation); - } - - function increaseAllocationAmount( - uint256 _allocationId, - uint256 _tokenAmount - ) public override { - super.increaseAllocationAmount(_allocationId, _tokenAmount); - } - - function deallocateRewards(uint256 _allocationId, uint256 _tokenAmount) - public - override - { - super.deallocateRewards(_allocationId, _tokenAmount); - } - - function _verifyAndReturnRewardRecipient( - AllocationStrategy strategy, - BidState bidState, - address borrower, - address lender - ) internal override returns (address rewardRecipient) { - verifyRewardRecipientWasCalled = true; - return address(borrower); - } - - function _verifyCollateralAmount( - address _collateralTokenAddress, - uint256 _collateralAmount, - address _principalTokenAddress, - uint256 _principalAmount, - uint256 _minimumCollateralPerPrincipalAmount - ) internal override { - verifyCollateralAmountWasCalled = true; - } - - function _verifyLoanStartTime( - uint32 loanStartTime, - uint32 minStartTime, - uint32 maxStartTime - ) internal override { - verifyLoanStartTimeWasCalled = true; - } -} diff --git a/packages/contracts/tests/MarketLiquidityRewards_Test.sol b/packages/contracts/tests/MarketLiquidityRewards_Test.sol deleted file mode 100644 index 177891f53..000000000 --- a/packages/contracts/tests/MarketLiquidityRewards_Test.sol +++ /dev/null @@ -1,669 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.0; - -import "@openzeppelin/contracts/utils/Address.sol"; -import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; -import "../contracts/TellerV2MarketForwarder_G1.sol"; - -import "./tokens/TestERC20Token.sol"; -import "../contracts/TellerV2Context.sol"; - -import { Testable } from "./Testable.sol"; - -import { Collateral, CollateralType } from "../contracts/interfaces/escrow/ICollateralEscrowV1.sol"; - -import { User } from "./Test_Helpers.sol"; -import { MarketLiquidityRewards_Override } from "./MarketLiquidityRewards_Override.sol"; - -import "../contracts/mock/MarketRegistryMock.sol"; -import "../contracts/mock/CollateralManagerMock.sol"; - -import "../contracts/MarketLiquidityRewards.sol"; - -contract MarketLiquidityRewards_Test is Testable { - MarketLiquidityUser private marketOwner; - MarketLiquidityUser private lender; - MarketLiquidityUser private borrower; - - uint256 immutable startTime = 1678122531; - - // address tokenAddress; - uint256 marketId; - uint256 maxAmount; - - address[] emptyArray; - address[] borrowersArray; - - uint32 maxLoanDuration; - uint16 minInterestRate; - uint32 expiration; - - TestERC20Token rewardToken; - uint8 constant rewardTokenDecimals = 18; - - TestERC20Token principalToken; - uint8 constant principalTokenDecimals = 18; - - TestERC20Token collateralToken; - uint8 constant collateralTokenDecimals = 6; - - MarketLiquidityRewards_Override marketLiquidityRewards; - - TellerV2Mock tellerV2Mock; - MarketRegistryMock marketRegistryMock; - CollateralManagerMock collateralManagerMock; - - constructor() - /* MarketLiquidityRewards( - address(new TellerV2Mock()), - address(new MarketRegistryMock(address(0))), - address(new CollateralManagerMock()) - )*/ - { - - } - - function setUp() public { - tellerV2Mock = new TellerV2Mock(); - - marketRegistryMock = new MarketRegistryMock(); - - collateralManagerMock = new CollateralManagerMock(); - - tellerV2Mock.setMarketRegistry(address(marketRegistryMock)); - - marketLiquidityRewards = new MarketLiquidityRewards_Override( - address(tellerV2Mock), - address(marketRegistryMock), - address(collateralManagerMock) - ); - - borrower = new MarketLiquidityUser( - address(tellerV2Mock), - address(marketLiquidityRewards) - ); - lender = new MarketLiquidityUser( - address(tellerV2Mock), - address(marketLiquidityRewards) - ); - - marketOwner = new MarketLiquidityUser( - address(tellerV2Mock), - address(marketLiquidityRewards) - ); - - marketRegistryMock.setMarketOwner(address(marketOwner)); - - //tokenAddress = address(0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174); - marketId = 2; - maxAmount = 100000000000000000000; - maxLoanDuration = 2480000; - minInterestRate = 3000; - expiration = uint32(block.timestamp) + uint32(64000); - - //failing - marketOwner.setTrustedMarketForwarder( - marketId, - address(marketLiquidityRewards) - ); - lender.approveMarketForwarder( - marketId, - address(marketLiquidityRewards) - ); - - borrowersArray = new address[](1); - borrowersArray[0] = address(borrower); - - rewardToken = new TestERC20Token( - "Test Wrapped ETH", - "TWETH", - 1e30, - rewardTokenDecimals - ); - - principalToken = new TestERC20Token( - "Test Wrapped ETH", - "TWETH", - 1e30, - principalTokenDecimals - ); - - collateralToken = new TestERC20Token( - "Test USDC", - "TUSDC", - 100000, - collateralTokenDecimals - ); - - IERC20Upgradeable(address(rewardToken)).transfer( - address(lender), - 10000 - ); - - IERC20Upgradeable(address(rewardToken)).transfer( - address(marketLiquidityRewards), - 1e12 - ); - - vm.warp(startTime + 100); - //delete allocationCount; - - /* verifyLoanStartTimeWasCalled = false; - - - verifyRewardRecipientWasCalled = false; - verifyCollateralAmountWasCalled = false;*/ - } - - /* -FNDA:0,MarketLiquidityRewards.initialize -FNDA:0,MarketLiquidityRewards.updateAllocation -FNDA:0,MarketLiquidityRewards._verifyCollateralAmount - - */ - - function _setAllocation(uint256 _allocationId, uint256 rewardTokenAmount) - internal - { - MarketLiquidityRewards.RewardAllocation - memory _allocation = IMarketLiquidityRewards.RewardAllocation({ - allocator: address(lender), - marketId: marketId, - rewardTokenAddress: address(rewardToken), - rewardTokenAmount: rewardTokenAmount, - requiredPrincipalTokenAddress: address(principalToken), - requiredCollateralTokenAddress: address(collateralToken), - minimumCollateralPerPrincipalAmount: 0, - rewardPerLoanPrincipalAmount: 1e18, - bidStartTimeMin: uint32(startTime), - bidStartTimeMax: uint32(startTime + 10000), - allocationStrategy: IMarketLiquidityRewards - .AllocationStrategy - .BORROWER - }); - - marketLiquidityRewards.setAllocation(_allocationId, _allocation); - } - - function test_allocateRewards() public { - uint256 rewardTokenAmount = 500; - - MarketLiquidityRewards.RewardAllocation - memory _allocation = IMarketLiquidityRewards.RewardAllocation({ - allocator: address(lender), - marketId: marketId, - rewardTokenAddress: address(rewardToken), - rewardTokenAmount: rewardTokenAmount, - requiredPrincipalTokenAddress: address(principalToken), - requiredCollateralTokenAddress: address(collateralToken), - minimumCollateralPerPrincipalAmount: 0, - rewardPerLoanPrincipalAmount: 0, - bidStartTimeMin: uint32(startTime), - bidStartTimeMax: uint32(startTime + 10000), - allocationStrategy: IMarketLiquidityRewards - .AllocationStrategy - .BORROWER - }); - - lender._approveERC20Token( - address(rewardToken), - address(marketLiquidityRewards), - rewardTokenAmount - ); - - uint256 allocationId = lender._allocateRewards(_allocation); - } - - function test_increaseAllocationAmount() public { - uint256 allocationId = 0; - uint256 amountToIncrease = 100; - - _setAllocation(allocationId, 0); - - uint256 amountBefore = marketLiquidityRewards.getRewardTokenAmount( - allocationId - ); - - lender._approveERC20Token( - address(rewardToken), - address(marketLiquidityRewards), - amountToIncrease - ); - - lender._increaseAllocationAmount(allocationId, amountToIncrease); - - uint256 amountAfter = marketLiquidityRewards.getRewardTokenAmount( - allocationId - ); - - assertEq( - amountAfter, - amountBefore + amountToIncrease, - "Allocation did not increase" - ); - } - - function test_deallocateRewards() public { - uint256 allocationId = 0; - - _setAllocation(allocationId, 0); - - uint256 amountBefore = marketLiquidityRewards.getRewardTokenAmount( - allocationId - ); - - lender._deallocateRewards(allocationId, amountBefore); - - uint256 amountAfter = marketLiquidityRewards.getRewardTokenAmount( - allocationId - ); - - assertEq(amountAfter, 0, "Allocation was not deleted"); - } - - function test_claimRewards() public { - Bid memory mockBid; - - mockBid.borrower = address(borrower); - mockBid.lender = address(lender); - mockBid.marketplaceId = marketId; - mockBid.loanDetails.loanDuration = 80000; - mockBid.loanDetails.lendingToken = (principalToken); - mockBid.loanDetails.principal = 10000; - mockBid.loanDetails.acceptedTimestamp = uint32(block.timestamp); - mockBid.loanDetails.lastRepaidTimestamp = uint32( - block.timestamp + 5000 - ); - mockBid.state = BidState.PAID; - - tellerV2Mock.setMockBid(mockBid); - - uint256 allocationId = 0; - uint256 bidId = 0; - - _setAllocation(allocationId, 4000); - - vm.prank(address(borrower)); - marketLiquidityRewards.claimRewards(allocationId, bidId); - - assertEq( - marketLiquidityRewards.verifyLoanStartTimeWasCalled(), - true, - "verifyLoanStartTime was not called" - ); - - assertEq( - marketLiquidityRewards.verifyRewardRecipientWasCalled(), - true, - "verifyRewardRecipient was not called" - ); - - assertEq( - marketLiquidityRewards.verifyCollateralAmountWasCalled(), - true, - "verifyCollateralAmount was not called" - ); - - //add some negative tests (unit) - //add comments to all of the methods - } - - function test_claimRewards_zero_principal() public { - Bid memory mockBid; - - mockBid.borrower = address(borrower); - mockBid.lender = address(lender); - mockBid.marketplaceId = marketId; - mockBid.loanDetails.lendingToken = (principalToken); - mockBid.loanDetails.principal = 0; - mockBid.loanDetails.acceptedTimestamp = uint32(block.timestamp); - mockBid.loanDetails.lastRepaidTimestamp = uint32( - block.timestamp + 5000 - ); - mockBid.state = BidState.PAID; - - tellerV2Mock.setMockBid(mockBid); - - uint256 allocationId = 0; - uint256 bidId = 0; - - _setAllocation(allocationId, 0); - - vm.prank(address(borrower)); - vm.expectRevert("Nothing to claim."); - marketLiquidityRewards.claimRewards(allocationId, bidId); - } - - function test_claimRewards_round_remainder() public { - Bid memory mockBid; - - mockBid.borrower = address(borrower); - mockBid.lender = address(lender); - mockBid.marketplaceId = marketId; - mockBid.loanDetails.lendingToken = (principalToken); - mockBid.loanDetails.principal = 10000000; - mockBid.loanDetails.acceptedTimestamp = uint32(block.timestamp); - mockBid.loanDetails.lastRepaidTimestamp = uint32( - block.timestamp + (365 days) - ); - mockBid.state = BidState.PAID; - - tellerV2Mock.setMockBid(mockBid); - - uint256 allocationId = 0; - uint256 bidId = 0; - - MarketLiquidityRewards.RewardAllocation - memory _allocation = IMarketLiquidityRewards.RewardAllocation({ - allocator: address(this), - marketId: marketId, - rewardTokenAddress: address(rewardToken), - rewardTokenAmount: 1000, - requiredPrincipalTokenAddress: address(principalToken), - requiredCollateralTokenAddress: address(collateralToken), - minimumCollateralPerPrincipalAmount: 0, - rewardPerLoanPrincipalAmount: 1000 * 1e18, - bidStartTimeMin: uint32(startTime), - bidStartTimeMax: uint32(startTime + 10000), - allocationStrategy: IMarketLiquidityRewards - .AllocationStrategy - .BORROWER - }); - - marketLiquidityRewards.setAllocation(allocationId, _allocation); - - //send 1000 tokens to the contract - IERC20Upgradeable(address(rewardToken)).transfer( - address(marketLiquidityRewards), - 1000 - ); - - vm.prank(address(borrower)); - marketLiquidityRewards.claimRewards(allocationId, bidId); - - assertEq( - marketLiquidityRewards.verifyLoanStartTimeWasCalled(), - true, - "verifyLoanStartTime was not called" - ); - - assertEq( - marketLiquidityRewards.verifyRewardRecipientWasCalled(), - true, - "verifyRewardRecipient was not called" - ); - - assertEq( - marketLiquidityRewards.verifyCollateralAmountWasCalled(), - true, - "verifyCollateralAmount was not called" - ); - - uint256 remainingTokenAmount = marketLiquidityRewards - .getRewardTokenAmount(allocationId); - - //verify that the reward status is updated to drained - assertEq(remainingTokenAmount, 0, "Reward was not completely drained"); - } - - function test_claimRewards_zero_time_elapsed() public { - Bid memory mockBid; - - mockBid.borrower = address(borrower); - mockBid.lender = address(lender); - mockBid.marketplaceId = marketId; - mockBid.loanDetails.lendingToken = (principalToken); - mockBid.loanDetails.principal = 10000000; - mockBid.loanDetails.acceptedTimestamp = uint32(block.timestamp); - mockBid.loanDetails.lastRepaidTimestamp = uint32(block.timestamp); - mockBid.state = BidState.PAID; - - tellerV2Mock.setMockBid(mockBid); - - uint256 allocationId = 0; - uint256 bidId = 0; - - MarketLiquidityRewards.RewardAllocation - memory _allocation = IMarketLiquidityRewards.RewardAllocation({ - allocator: address(this), - marketId: marketId, - rewardTokenAddress: address(rewardToken), - rewardTokenAmount: 1000, - requiredPrincipalTokenAddress: address(principalToken), - requiredCollateralTokenAddress: address(collateralToken), - minimumCollateralPerPrincipalAmount: 0, - rewardPerLoanPrincipalAmount: 1000 * 1e18, - bidStartTimeMin: uint32(startTime), - bidStartTimeMax: uint32(startTime + 10000), - allocationStrategy: IMarketLiquidityRewards - .AllocationStrategy - .BORROWER - }); - - marketLiquidityRewards.setAllocation(allocationId, _allocation); - - //send 1000 tokens to the contract - IERC20Upgradeable(address(rewardToken)).transfer( - address(marketLiquidityRewards), - 1000 - ); - - vm.prank(address(borrower)); - vm.expectRevert("Nothing to claim."); - marketLiquidityRewards.claimRewards(allocationId, bidId); - } - - function test_calculateRewardAmount_weth_principal() public { - uint256 loanPrincipal = 1e8; - uint256 principalTokenDecimals = 18; - uint32 loanDuration = 60 * 60 * 24 * 365; - - uint256 rewardPerLoanPrincipalAmount = 1e16; // expanded by token decimals so really 0.01 - - uint256 rewardAmount = marketLiquidityRewards.calculateRewardAmount( - loanPrincipal, - loanDuration, - principalTokenDecimals, - rewardPerLoanPrincipalAmount - ); - - assertEq(rewardAmount, 1e6, "Invalid reward amount"); - } - - function test_calculateRewardAmount_usdc_principal() public { - uint256 loanPrincipal = 1e8; - uint256 principalTokenDecimals = 6; - uint32 loanDuration = 60 * 60 * 24 * 365; - - uint256 rewardPerLoanPrincipalAmount = 1e4; // expanded by token decimals so really 0.01 - - uint256 rewardAmount = marketLiquidityRewards.calculateRewardAmount( - loanPrincipal, - loanDuration, - principalTokenDecimals, - rewardPerLoanPrincipalAmount - ); - - assertEq(rewardAmount, 1e6, "Invalid reward amount"); - } - - function test_requiredCollateralAmount() public { - uint256 collateralTokenDecimals = 6; - - uint256 loanPrincipal = 1e8; - uint256 principalTokenDecimals = 6; - - uint256 minimumCollateralPerPrincipal = 1e4 * 1e6; // expanded by token decimals so really 0.01 - - uint256 minCollateral = marketLiquidityRewards.requiredCollateralAmount( - loanPrincipal, - principalTokenDecimals, - collateralTokenDecimals, - minimumCollateralPerPrincipal - ); - - assertEq(minCollateral, 1e6, "Invalid min collateral calculation"); - } - - function test_decrementAllocatedAmount() public { - uint256 allocationId = 0; - - _setAllocation(allocationId, 0); - - uint256 amount = 100; - - marketLiquidityRewards.setAllocatedAmount(allocationId, amount); - - marketLiquidityRewards.decrementAllocatedAmount(allocationId, amount); - - assertEq( - marketLiquidityRewards.getRewardTokenAmount(allocationId), - 0, - "allocation amount not decremented" - ); - } - - /* function test_verifyCollateralAmount() public { - - vm.expectRevert(); - super._verifyCollateralAmount( - address(collateralToken), - 100, - address(principalToken), - 1000, - 5000 * 1e18 * 1e18 - ); - - - }*/ - - function test_verifyLoanStartTime_min() public { - vm.expectRevert(bytes("Loan was accepted before the min start time.")); - - marketLiquidityRewards.verifyLoanStartTime(100, 200, 300); - } - - function test_verifyAndReturnRewardRecipient() public { - address recipient = marketLiquidityRewards - .verifyAndReturnRewardRecipient( - IMarketLiquidityRewards.AllocationStrategy.BORROWER, - BidState.PAID, - address(borrower), - address(lender) - ); - - assertEq(recipient, address(borrower), "incorrect address returned"); - } - - function test_verifyAndReturnRewardRecipient_reverts() public { - vm.expectRevert(); - - address recipient = marketLiquidityRewards - .verifyAndReturnRewardRecipient( - IMarketLiquidityRewards.AllocationStrategy.BORROWER, - BidState.PENDING, - address(borrower), - address(lender) - ); - } - - function test_verifyLoanStartTime_max() public { - vm.expectRevert(bytes("Loan was accepted after the max start time.")); - - marketLiquidityRewards.verifyLoanStartTime(400, 200, 300); - } -} - -contract MarketLiquidityUser is User { - MarketLiquidityRewards public immutable liquidityRewards; - - constructor(address _tellerV2, address _liquidityRewards) User(_tellerV2) { - liquidityRewards = MarketLiquidityRewards(_liquidityRewards); - } - - function _allocateRewards( - MarketLiquidityRewards.RewardAllocation calldata _allocation - ) public returns (uint256) { - return liquidityRewards.allocateRewards(_allocation); - } - - function _increaseAllocationAmount( - uint256 _allocationId, - uint256 _allocationAmount - ) public { - liquidityRewards.increaseAllocationAmount( - _allocationId, - _allocationAmount - ); - } - - function _deallocateRewards(uint256 _allocationId, uint256 _amount) public { - liquidityRewards.deallocateRewards(_allocationId, _amount); - } - - function _claimRewards(uint256 _allocationId, uint256 _bidId) public { - return liquidityRewards.claimRewards(_allocationId, _bidId); - } - - function _approveERC20Token(address tokenAddress, address guy, uint256 wad) - public - { - IERC20Upgradeable(tokenAddress).approve(guy, wad); - } -} - -contract TellerV2Mock is TellerV2Context { - Bid mockBid; - - constructor() TellerV2Context(address(0)) {} - - function setMarketRegistry(address _marketRegistry) external { - marketRegistry = IMarketRegistry(_marketRegistry); - } - - function getSenderForMarket(uint256 _marketId) - external - view - returns (address) - { - return _msgSenderForMarket(_marketId); - } - - function getDataForMarket(uint256 _marketId) - external - view - returns (bytes calldata) - { - return _msgDataForMarket(_marketId); - } - - function setMockBid(Bid calldata bid) public { - mockBid = bid; - } - - function getLoanSummary(uint256 _bidId) - external - view - returns ( - address borrower, - address lender, - uint256 marketId, - address principalTokenAddress, - uint256 principalAmount, - uint32 acceptedTimestamp, - uint32 lastRepaidTimestamp, - BidState bidState - ) - { - Bid storage bid = mockBid; - - borrower = bid.borrower; - lender = bid.lender; - marketId = bid.marketplaceId; - principalTokenAddress = address(bid.loanDetails.lendingToken); - principalAmount = bid.loanDetails.principal; - acceptedTimestamp = bid.loanDetails.acceptedTimestamp; - lastRepaidTimestamp = bid.loanDetails.lastRepaidTimestamp; - bidState = bid.state; - } -} diff --git a/packages/contracts/tests/MarketRegistry_Test.sol b/packages/contracts/tests/MarketRegistry_Test.sol index 210540211..8a62cefc5 100644 --- a/packages/contracts/tests/MarketRegistry_Test.sol +++ b/packages/contracts/tests/MarketRegistry_Test.sol @@ -1094,7 +1094,7 @@ contract MarketRegistryUser is User { contract TellerV2Mock is TellerV2Context { Bid mockBid; - constructor() TellerV2Context(address(0)) {} + constructor() TellerV2Context( ) {} function setMarketRegistry(address _marketRegistry) external { marketRegistry = IMarketRegistry(_marketRegistry); diff --git a/packages/contracts/tests/NextDueDate_test.sol b/packages/contracts/tests/NextDueDate_test.sol index 5a89c0ee6..f17a402bf 100644 --- a/packages/contracts/tests/NextDueDate_test.sol +++ b/packages/contracts/tests/NextDueDate_test.sol @@ -8,7 +8,7 @@ import { BokkyPooBahsDateTimeLibrary as BPBDTL } from "../contracts/libraries/Da contract NextDueDate_Test is Testable, TellerV2 { Bid __bid; - constructor() TellerV2(address(0)) { + constructor() TellerV2() { __bid.loanDetails.principal = 10000e6; // 10k USDC __bid.loanDetails.loanDuration = 365 days * 2; // 2 years __bid.terms.paymentCycle = 30 days; // 1 month diff --git a/packages/contracts/tests/PMT_Test.sol b/packages/contracts/tests/PMT_Test.sol index cc77a4570..b0e7d0cbf 100644 --- a/packages/contracts/tests/PMT_Test.sol +++ b/packages/contracts/tests/PMT_Test.sol @@ -9,7 +9,7 @@ import "../contracts/TellerV2.sol"; contract PMT_Test is Testable, TellerV2 { Bid __bid; - constructor() TellerV2(address(0)) {} + constructor() TellerV2( ) {} function test_01_pmt() public { __bid.loanDetails.principal = 10000e6; // 10k USDC diff --git a/packages/contracts/tests/SmartCommitmentForwarder/LenderCommitmentGroup_Factory_Test.sol b/packages/contracts/tests/SmartCommitmentForwarder/LenderCommitmentGroup_Factory_Test.sol index 7e1ce3dc6..aaf07be5a 100644 --- a/packages/contracts/tests/SmartCommitmentForwarder/LenderCommitmentGroup_Factory_Test.sol +++ b/packages/contracts/tests/SmartCommitmentForwarder/LenderCommitmentGroup_Factory_Test.sol @@ -286,7 +286,7 @@ contract LenderCommitmentGroupFactory_Test is Testable { //Move to a helper file ! contract LenderCommitmentForwarderTest_TellerV2Mock is TellerV2Context { - constructor() TellerV2Context(address(0)) {} + constructor() TellerV2Context( ) {} function __setMarketRegistry(address _marketRegistry) external { marketRegistry = IMarketRegistry(_marketRegistry); diff --git a/packages/contracts/tests/SmartCommitmentForwarder/UniswapPricingLibrary_Test.sol b/packages/contracts/tests/SmartCommitmentForwarder/UniswapPricingLibrary_Test.sol index 75f3756bb..778365f57 100644 --- a/packages/contracts/tests/SmartCommitmentForwarder/UniswapPricingLibrary_Test.sol +++ b/packages/contracts/tests/SmartCommitmentForwarder/UniswapPricingLibrary_Test.sol @@ -498,7 +498,7 @@ function test_getUniswapPriceRatioForPoolRoutes_twoPools_differentPrices() publi contract LenderCommitmentForwarderTest_TellerV2Mock is TellerV2Context { - constructor() TellerV2Context(address(0)) {} + constructor() TellerV2Context( ) {} function __setMarketRegistry(address _marketRegistry) external { marketRegistry = IMarketRegistry(_marketRegistry); diff --git a/packages/contracts/tests/TellerV2/TellerV2_Override.sol b/packages/contracts/tests/TellerV2/TellerV2_Override.sol index 714000b54..396149562 100644 --- a/packages/contracts/tests/TellerV2/TellerV2_Override.sol +++ b/packages/contracts/tests/TellerV2/TellerV2_Override.sol @@ -14,7 +14,7 @@ contract TellerV2_Override is TellerV2 { bool public repayLoanWasCalled; address public mockMsgSenderForMarket; - constructor() TellerV2(address(0)) {} + constructor() TellerV2( ) {} function mock_setBid(uint256 bidId, Bid memory bid) public { diff --git a/packages/contracts/tests/TellerV2/TellerV2_Test.sol b/packages/contracts/tests/TellerV2/TellerV2_Test.sol index 4849effec..72920535a 100644 --- a/packages/contracts/tests/TellerV2/TellerV2_Test.sol +++ b/packages/contracts/tests/TellerV2/TellerV2_Test.sol @@ -27,7 +27,7 @@ import { Collateral } from "../../contracts/interfaces/escrow/ICollateralEscrowV import { PaymentType } from "../../contracts/libraries/V2Calculations.sol"; import { BidState, Payment } from "../../contracts/TellerV2Storage.sol"; -import "../../contracts/MetaForwarder.sol"; + import { LenderManager } from "../../contracts/LenderManager.sol"; import { EscrowVault } from "../../contracts/EscrowVault.sol"; import { ProtocolPausingManager } from "../../contracts/pausing/ProtocolPausingManager.sol"; @@ -59,7 +59,7 @@ contract TellerV2_Test is Testable { ); // Deploy protocol - tellerV2 = new TellerV2(address(0)); + tellerV2 = new TellerV2( ); // Deploy MarketRegistry & ReputationManager IMarketRegistry marketRegistry = IMarketRegistry(new MarketRegistry()); @@ -73,8 +73,8 @@ contract TellerV2_Test is Testable { collateralManager.initialize(address(escrowBeacon), address(tellerV2)); // Deploy Lender manager - MetaForwarder metaforwarder = new MetaForwarder(); - metaforwarder.initialize(); + // MetaForwarder metaforwarder = new MetaForwarder(); + // metaforwarder.initialize(); LenderManager lenderManager = new LenderManager((marketRegistry)); lenderManager.initialize(); lenderManager.transferOwnership(address(tellerV2)); diff --git a/packages/contracts/tests/TellerV2Context/TellerV2Context_Override.sol b/packages/contracts/tests/TellerV2Context/TellerV2Context_Override.sol index bc3084255..e77351f18 100644 --- a/packages/contracts/tests/TellerV2Context/TellerV2Context_Override.sol +++ b/packages/contracts/tests/TellerV2Context/TellerV2Context_Override.sol @@ -10,7 +10,7 @@ contract TellerV2Context_Override is TellerV2Context { using EnumerableSet for EnumerableSet.AddressSet; constructor(address _marketRegistry, address _lenderCommitmentForwarder) - TellerV2Context(address(0)) + TellerV2Context( ) { marketRegistry = IMarketRegistry(_marketRegistry); lenderCommitmentForwarder = _lenderCommitmentForwarder; diff --git a/packages/contracts/tests/integration/IntegrationTestHelpers.sol b/packages/contracts/tests/integration/IntegrationTestHelpers.sol index 8fa4e5892..5489c5c92 100644 --- a/packages/contracts/tests/integration/IntegrationTestHelpers.sol +++ b/packages/contracts/tests/integration/IntegrationTestHelpers.sol @@ -36,8 +36,8 @@ library IntegrationTestHelpers { } function deployIntegrationSuite() public returns (TellerV2 tellerV2_) { - address trustedForwarder = address(0); - TellerV2 tellerV2 = new TellerV2(trustedForwarder); + + TellerV2 tellerV2 = new TellerV2( ); uint16 _protocolFee = 100; address _marketRegistry = deployMarketRegistry(); From 85f18e53576f33cbfe26c66693db15419575c9de Mon Sep 17 00:00:00 2001 From: andy Date: Wed, 29 Jan 2025 08:52:25 -0500 Subject: [PATCH 2/5] remove rep manager --- packages/contracts/contracts/TLR.sol | 57 ------------------- packages/contracts/contracts/TellerV2.sol | 19 +++---- .../contracts/contracts/TellerV2Storage.sol | 2 +- .../contracts/deploy/teller_v2/initialize.ts | 4 +- .../tests/TellerV2/TellerV2_Override.sol | 4 +- .../tests/TellerV2/TellerV2_Test.sol | 10 +--- .../tests/TellerV2/TellerV2_bids.sol | 12 ++-- .../tests/TellerV2/TellerV2_initialize.sol | 51 +++++------------ .../integration/IntegrationTestHelpers.sol | 10 ++-- 9 files changed, 36 insertions(+), 133 deletions(-) delete mode 100644 packages/contracts/contracts/TLR.sol diff --git a/packages/contracts/contracts/TLR.sol b/packages/contracts/contracts/TLR.sol deleted file mode 100644 index 51817b4ba..000000000 --- a/packages/contracts/contracts/TLR.sol +++ /dev/null @@ -1,57 +0,0 @@ -pragma solidity >=0.8.0 <0.9.0; -// SPDX-License-Identifier: MIT - -import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Votes.sol"; -import "@openzeppelin/contracts/access/Ownable.sol"; - -contract TLR is ERC20Votes, Ownable { - uint224 private immutable MAX_SUPPLY; - - /** - * @dev Sets the value of the `cap`. This value is immutable, it can only be - * set once during construction. - */ - constructor(uint224 _supplyCap, address tokenOwner) - ERC20("Teller", "TLR") - ERC20Permit("Teller") - { - require(_supplyCap > 0, "ERC20Capped: cap is 0"); - MAX_SUPPLY = _supplyCap; - _transferOwnership(tokenOwner); - } - - /** - * @dev Max supply has been overridden to cap the token supply upon initialization of the contract - * @dev See OpenZeppelin's implementation of ERC20Votes _mint() function - */ - function _maxSupply() internal view override returns (uint224) { - return MAX_SUPPLY; - } - - /** @dev Creates `amount` tokens and assigns them to `account` - * - * Emits a {Transfer} event with `from` set to the zero address. - * - * Requirements: - * - * - `account` cannot be the zero address. - */ - function mint(address account, uint256 amount) external onlyOwner { - _mint(account, amount); - } - - /** - * @dev Destroys `amount` tokens from `account`, reducing the - * total supply. - * - * Emits a {Transfer} event with `to` set to the zero address. - * - * Requirements: - * - * - `account` cannot be the zero address. - * - `account` must have at least `amount` tokens. - */ - function burn(address account, uint256 amount) external onlyOwner { - _burn(account, amount); - } -} diff --git a/packages/contracts/contracts/TellerV2.sol b/packages/contracts/contracts/TellerV2.sol index d1459d8c9..ebdd56b63 100644 --- a/packages/contracts/contracts/TellerV2.sol +++ b/packages/contracts/contracts/TellerV2.sol @@ -182,7 +182,7 @@ contract TellerV2 is * @notice Initializes the proxy. * @param _protocolFee The fee collected by the protocol for loan processing. * @param _marketRegistry The address of the market registry contract for the protocol. - * @param _reputationManager The address of the reputation manager contract. + * @param _lenderCommitmentForwarder The address of the lender commitment forwarder contract. * @param _collateralManager The address of the collateral manager contracts. * @param _lenderManager The address of the lender manager contract for loans on the protocol. @@ -191,7 +191,7 @@ contract TellerV2 is function initialize( uint16 _protocolFee, address _marketRegistry, - address _reputationManager, + // address _reputationManager, address _lenderCommitmentForwarder, address _collateralManager, address _lenderManager, @@ -213,12 +213,7 @@ contract TellerV2 is "MR_ic" ); marketRegistry = IMarketRegistry(_marketRegistry); - - require( - _reputationManager.isContract(), - "RM_ic" - ); - reputationManager = IReputationManager(_reputationManager); + require( _collateralManager.isContract(), @@ -834,10 +829,10 @@ contract TellerV2 is Bid storage bid = bids[_bidId]; uint256 paymentAmount = _payment.principal + _payment.interest; - RepMark mark = reputationManager.updateAccountReputation( + /* RepMark mark = reputationManager.updateAccountReputation( bid.borrower, _bidId - ); + );*/ // Check if we are sending a payment or amount remaining if (paymentAmount >= _owedAmount) { @@ -873,9 +868,9 @@ contract TellerV2 is _sendOrEscrowFunds(_bidId, _payment); //send or escrow the funds // If the loan is paid in full and has a mark, we should update the current reputation - if (mark != RepMark.Good) { + /* if (mark != RepMark.Good) { reputationManager.updateAccountReputation(bid.borrower, _bidId); - } + } */ } diff --git a/packages/contracts/contracts/TellerV2Storage.sol b/packages/contracts/contracts/TellerV2Storage.sol index 371e567c6..9a1707933 100644 --- a/packages/contracts/contracts/TellerV2Storage.sol +++ b/packages/contracts/contracts/TellerV2Storage.sol @@ -107,7 +107,7 @@ abstract contract TellerV2Storage_G0 { EnumerableSet.AddressSet internal __lendingTokensSet; // DEPRECATED IMarketRegistry public marketRegistry; - IReputationManager public reputationManager; + IReputationManager private _reputationManager; // Mapping of borrowers to borrower requests. mapping(address => EnumerableSet.UintSet) internal _borrowerBidsActive; diff --git a/packages/contracts/deploy/teller_v2/initialize.ts b/packages/contracts/deploy/teller_v2/initialize.ts index 98bcc73e2..2704b00e1 100644 --- a/packages/contracts/deploy/teller_v2/initialize.ts +++ b/packages/contracts/deploy/teller_v2/initialize.ts @@ -10,7 +10,7 @@ const deployFn: DeployFunction = async (hre) => { const protocolFee = 5 // 0.05% const marketRegistry = await hre.contracts.get('MarketRegistry') - const reputationManager = await hre.contracts.get('ReputationManager') + //const reputationManager = await hre.contracts.get('ReputationManager') const lenderCommitmentForwarder = await hre.contracts.get( 'LenderCommitmentForwarder' ) @@ -22,7 +22,7 @@ const deployFn: DeployFunction = async (hre) => { const tx = await tellerV2.initialize( protocolFee, marketRegistry, - reputationManager, + lenderCommitmentForwarder, collateralManager, lenderManager, diff --git a/packages/contracts/tests/TellerV2/TellerV2_Override.sol b/packages/contracts/tests/TellerV2/TellerV2_Override.sol index 396149562..3a5359a16 100644 --- a/packages/contracts/tests/TellerV2/TellerV2_Override.sol +++ b/packages/contracts/tests/TellerV2/TellerV2_Override.sol @@ -47,9 +47,7 @@ contract TellerV2_Override is TellerV2 { collateralManager = ICollateralManager(_collateralManager); } - function setReputationManagerSuper(address _reputationManager) public { - reputationManager = IReputationManager(_reputationManager); - } + function mock_setBidState(uint256 bidId, BidState state) public { bids[bidId].state = state; diff --git a/packages/contracts/tests/TellerV2/TellerV2_Test.sol b/packages/contracts/tests/TellerV2/TellerV2_Test.sol index 72920535a..d3ccc3a8c 100644 --- a/packages/contracts/tests/TellerV2/TellerV2_Test.sol +++ b/packages/contracts/tests/TellerV2/TellerV2_Test.sol @@ -4,8 +4,7 @@ pragma solidity ^0.8.0; import { Testable } from "../Testable.sol"; import { TellerV2 } from "../../contracts/TellerV2.sol"; -import { MarketRegistry } from "../../contracts/MarketRegistry.sol"; -import { ReputationManager } from "../../contracts/ReputationManager.sol"; +import { MarketRegistry } from "../../contracts/MarketRegistry.sol"; import "../../contracts/interfaces/IMarketRegistry.sol"; import "../../contracts/interfaces/IReputationManager.sol"; @@ -63,10 +62,7 @@ contract TellerV2_Test is Testable { // Deploy MarketRegistry & ReputationManager IMarketRegistry marketRegistry = IMarketRegistry(new MarketRegistry()); - IReputationManager reputationManager = IReputationManager( - new ReputationManager() - ); - reputationManager.initialize(address(tellerV2)); + // Deploy Collateral manager collateralManager = new CollateralManager(); @@ -95,7 +91,7 @@ contract TellerV2_Test is Testable { tellerV2.initialize( 50, address(marketRegistry), - address(reputationManager), + address(lenderCommitmentForwarder), address(collateralManager), address(lenderManager), diff --git a/packages/contracts/tests/TellerV2/TellerV2_bids.sol b/packages/contracts/tests/TellerV2/TellerV2_bids.sol index 7bef80f8c..077eac821 100644 --- a/packages/contracts/tests/TellerV2/TellerV2_bids.sol +++ b/packages/contracts/tests/TellerV2/TellerV2_bids.sol @@ -7,8 +7,7 @@ import { TellerV2_Override } from "./TellerV2_Override.sol"; import { Bid, BidState, Collateral, Payment, LoanDetails, Terms, ActionNotAllowed } from "../../contracts/TellerV2.sol"; import { PaymentType, PaymentCycleType } from "../../contracts/libraries/V2Calculations.sol"; - -import { ReputationManagerMock } from "../../contracts/mock/ReputationManagerMock.sol"; + import { CollateralManagerMock } from "../../contracts/mock/CollateralManagerMock.sol"; import { LenderManagerMock } from "../../contracts/mock/LenderManagerMock.sol"; import { MarketRegistryMock } from "../../contracts/mock/MarketRegistryMock.sol"; @@ -40,8 +39,7 @@ contract TellerV2_bids_test is Testable { User feeRecipient; MarketRegistryMock marketRegistryMock; - - ReputationManagerMock reputationManagerMock; + CollateralManagerMock collateralManagerMock; LenderManagerMock lenderManagerMock; @@ -61,7 +59,7 @@ contract TellerV2_bids_test is Testable { tellerV2 = new TellerV2_Override(); marketRegistryMock = new MarketRegistryMock(); - reputationManagerMock = new ReputationManagerMock(); + collateralManagerMock = new CollateralManagerMock(); lenderManagerMock = new LenderManagerMock(); protocolPausingManager = new ProtocolPausingManager(); @@ -541,7 +539,7 @@ contract TellerV2_bids_test is Testable { //set address(this) as the account that will be paying off the loan tellerV2.setMockMsgSenderForMarket(address(this)); - tellerV2.setReputationManagerSuper(address(reputationManagerMock)); + tellerV2.mock_setBidState(bidId, BidState.ACCEPTED); vm.warp(2000); @@ -564,7 +562,7 @@ contract TellerV2_bids_test is Testable { //set address(this) as the account that will be paying off the loan tellerV2.setMockMsgSenderForMarket(address(this)); - tellerV2.setReputationManagerSuper(address(reputationManagerMock)); + tellerV2.mock_setBidState(bidId, BidState.LIQUIDATED); vm.warp(2000); diff --git a/packages/contracts/tests/TellerV2/TellerV2_initialize.sol b/packages/contracts/tests/TellerV2/TellerV2_initialize.sol index 6c8df615d..b09efa6f0 100644 --- a/packages/contracts/tests/TellerV2/TellerV2_initialize.sol +++ b/packages/contracts/tests/TellerV2/TellerV2_initialize.sol @@ -14,7 +14,7 @@ contract TellerV2_initialize is Testable { uint16 protocolFee = 5; Contract marketRegistry; - Contract reputationManager; + Contract lenderCommitmentForwarder; Contract collateralManager; Contract lenderManager; @@ -29,7 +29,7 @@ contract TellerV2_initialize is Testable { function test_initialize() public { marketRegistry = new Contract(); - reputationManager = new Contract(); + lenderCommitmentForwarder = new Contract(); collateralManager = new Contract(); lenderManager = new Contract(); @@ -39,7 +39,7 @@ contract TellerV2_initialize is Testable { tellerV2.initialize( protocolFee, address(marketRegistry), - address(reputationManager), + address(lenderCommitmentForwarder), address(collateralManager), address(lenderManager), @@ -54,7 +54,7 @@ contract TellerV2_initialize is Testable { function test_initialize_lender_commitment_forwarder_not_contract() public { marketRegistry = new Contract(); - reputationManager = new Contract(); + collateralManager = new Contract(); lenderManager = new Contract(); @@ -66,7 +66,7 @@ contract TellerV2_initialize is Testable { tellerV2.initialize( protocolFee, address(marketRegistry), - address(reputationManager), + address(lenderCommitmentForwarder), address(collateralManager), address(lenderManager), @@ -76,7 +76,7 @@ contract TellerV2_initialize is Testable { } function test_initialize_market_registry_not_contract() public { - reputationManager = new Contract(); + lenderCommitmentForwarder = new Contract(); collateralManager = new Contract(); @@ -89,7 +89,7 @@ contract TellerV2_initialize is Testable { tellerV2.initialize( protocolFee, address(marketRegistry), - address(reputationManager), + address(lenderCommitmentForwarder), address(collateralManager), address(lenderManager), @@ -98,34 +98,13 @@ contract TellerV2_initialize is Testable { ); } - function test_initialize_reputation_manager_not_contract() public { - marketRegistry = new Contract(); - - lenderCommitmentForwarder = new Contract(); - collateralManager = new Contract(); - lenderManager = new Contract(); - escrowVault = new Contract(); - protocolPausingManager = new Contract(); - - vm.expectRevert("RM_ic"); - - tellerV2.initialize( - protocolFee, - address(marketRegistry), - address(reputationManager), - address(lenderCommitmentForwarder), - address(collateralManager), - address(lenderManager), - address(escrowVault), - address(protocolPausingManager) - ); - } + function test_initialize_collateral_manager_not_contract() public { marketRegistry = new Contract(); lenderCommitmentForwarder = new Contract(); - reputationManager = new Contract(); + lenderManager = new Contract(); escrowVault = new Contract(); protocolPausingManager = new Contract(); @@ -135,7 +114,7 @@ contract TellerV2_initialize is Testable { tellerV2.initialize( protocolFee, address(marketRegistry), - address(reputationManager), + address(lenderCommitmentForwarder), address(collateralManager), address(lenderManager), @@ -148,7 +127,7 @@ contract TellerV2_initialize is Testable { marketRegistry = new Contract(); lenderCommitmentForwarder = new Contract(); - reputationManager = new Contract(); + collateralManager = new Contract(); escrowVault = new Contract(); protocolPausingManager = new Contract(); @@ -158,7 +137,7 @@ contract TellerV2_initialize is Testable { tellerV2.initialize( protocolFee, address(marketRegistry), - address(reputationManager), + address(lenderCommitmentForwarder), address(collateralManager), address(lenderManager), @@ -171,11 +150,7 @@ contract TellerV2_initialize is Testable { //how to mock self as the owner ? //tellerV2.setLenderManager(address(lenderManager)); } - - function test_setReputationManager_external() public { - //how to mock self as the owner ? - //tellerV2.setReputationManager(address(reputationManager)); - } + function test_setLenderManager_internal() public { lenderManager = new Contract(); diff --git a/packages/contracts/tests/integration/IntegrationTestHelpers.sol b/packages/contracts/tests/integration/IntegrationTestHelpers.sol index 5489c5c92..4807d2fba 100644 --- a/packages/contracts/tests/integration/IntegrationTestHelpers.sol +++ b/packages/contracts/tests/integration/IntegrationTestHelpers.sol @@ -18,8 +18,7 @@ import { LenderManager } from "../../contracts/LenderManager.sol"; import { LenderCommitmentForwarder_G3 } from "../../contracts/LenderCommitmentForwarder/LenderCommitmentForwarder_G3.sol"; import { CollateralManager } from "../../contracts/CollateralManager.sol"; import { CollateralEscrowV1 } from "../../contracts/escrow/CollateralEscrowV1.sol"; - -import { ReputationManager } from "../../contracts/ReputationManager.sol"; + import { IMarketRegistry } from "../../contracts/interfaces/IMarketRegistry.sol"; library IntegrationTestHelpers { @@ -41,7 +40,7 @@ library IntegrationTestHelpers { uint16 _protocolFee = 100; address _marketRegistry = deployMarketRegistry(); - ReputationManager _reputationManager = new ReputationManager(); + LenderCommitmentForwarder_G3 _lenderCommitmentForwarder = new LenderCommitmentForwarder_G3( address(tellerV2), @@ -64,12 +63,11 @@ library IntegrationTestHelpers { _protocolPausingManager.initialize(); //need to xfer ownership ..? _collateralManager.initialize(address(escrowBeacon), address(tellerV2)); _lenderManager.initialize(); - _reputationManager.initialize(address(tellerV2)); - + tellerV2.initialize( _protocolFee, address(_marketRegistry), - address(_reputationManager), + address(_lenderCommitmentForwarder), address(_collateralManager), address(_lenderManager), From 705c73aac6d42fec3385f0e78f34e661abcecc48 Mon Sep 17 00:00:00 2001 From: andy Date: Wed, 29 Jan 2025 08:57:57 -0500 Subject: [PATCH 3/5] remove rep mgr --- .../contracts/contracts/ReputationManager.sol | 140 ------------------ .../contracts/tests/TellerV2Autopay_Test.sol | 2 +- 2 files changed, 1 insertion(+), 141 deletions(-) delete mode 100644 packages/contracts/contracts/ReputationManager.sol diff --git a/packages/contracts/contracts/ReputationManager.sol b/packages/contracts/contracts/ReputationManager.sol deleted file mode 100644 index 58eff6062..000000000 --- a/packages/contracts/contracts/ReputationManager.sol +++ /dev/null @@ -1,140 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity >=0.8.0 <0.9.0; - -// Interfaces -import "./interfaces/IReputationManager.sol"; -import "./interfaces/ITellerV2.sol"; -import "@openzeppelin/contracts/proxy/utils/Initializable.sol"; - -// Libraries -import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol"; - -contract ReputationManager is IReputationManager, Initializable { - using EnumerableSet for EnumerableSet.UintSet; - - bytes32 public constant CONTROLLER = keccak256("CONTROLLER"); - - ITellerV2 public tellerV2; - mapping(address => EnumerableSet.UintSet) private _delinquencies; - mapping(address => EnumerableSet.UintSet) private _defaults; - mapping(address => EnumerableSet.UintSet) private _currentDelinquencies; - mapping(address => EnumerableSet.UintSet) private _currentDefaults; - - event MarkAdded( - address indexed account, - RepMark indexed repMark, - uint256 bidId - ); - event MarkRemoved( - address indexed account, - RepMark indexed repMark, - uint256 bidId - ); - - /** - * @notice Initializes the proxy. - */ - function initialize(address _tellerV2) external initializer { - tellerV2 = ITellerV2(_tellerV2); - } - - function getDelinquentLoanIds(address _account) - public - override - returns (uint256[] memory) - { - updateAccountReputation(_account); - return _delinquencies[_account].values(); - } - - function getDefaultedLoanIds(address _account) - public - override - returns (uint256[] memory) - { - updateAccountReputation(_account); - return _defaults[_account].values(); - } - - function getCurrentDelinquentLoanIds(address _account) - public - override - returns (uint256[] memory) - { - updateAccountReputation(_account); - return _currentDelinquencies[_account].values(); - } - - function getCurrentDefaultLoanIds(address _account) - public - override - returns (uint256[] memory) - { - updateAccountReputation(_account); - return _currentDefaults[_account].values(); - } - - function updateAccountReputation(address _account) public override { - uint256[] memory activeBidIds = tellerV2.getBorrowerActiveLoanIds( - _account - ); - for (uint256 i; i < activeBidIds.length; i++) { - _applyReputation(_account, activeBidIds[i]); - } - } - - function updateAccountReputation(address _account, uint256 _bidId) - public - override - returns (RepMark) - { - return _applyReputation(_account, _bidId); - } - - function _applyReputation(address _account, uint256 _bidId) - internal - returns (RepMark mark_) - { - mark_ = RepMark.Good; - - if (tellerV2.isLoanDefaulted(_bidId)) { - mark_ = RepMark.Default; - - // Remove delinquent status - _removeMark(_account, _bidId, RepMark.Delinquent); - } else if (tellerV2.isPaymentLate(_bidId)) { - mark_ = RepMark.Delinquent; - } - - // Mark status if not "Good" - if (mark_ != RepMark.Good) { - _addMark(_account, _bidId, mark_); - } - } - - function _addMark(address _account, uint256 _bidId, RepMark _mark) - internal - { - if (_mark == RepMark.Delinquent) { - _delinquencies[_account].add(_bidId); - _currentDelinquencies[_account].add(_bidId); - } else if (_mark == RepMark.Default) { - _defaults[_account].add(_bidId); - _currentDefaults[_account].add(_bidId); - } - - emit MarkAdded(_account, _mark, _bidId); - } - - function _removeMark(address _account, uint256 _bidId, RepMark _mark) - internal - { - if (_mark == RepMark.Delinquent) { - _currentDelinquencies[_account].remove(_bidId); - } else if (_mark == RepMark.Default) { - _currentDefaults[_account].remove(_bidId); - } - - emit MarkRemoved(_account, _mark, _bidId); - } -} diff --git a/packages/contracts/tests/TellerV2Autopay_Test.sol b/packages/contracts/tests/TellerV2Autopay_Test.sol index a6ca178aa..9b66a7dcb 100644 --- a/packages/contracts/tests/TellerV2Autopay_Test.sol +++ b/packages/contracts/tests/TellerV2Autopay_Test.sol @@ -5,7 +5,7 @@ import { Testable } from "./Testable.sol"; import { TellerV2Autopay } from "../contracts/TellerV2Autopay.sol"; import { MarketRegistry } from "../contracts/MarketRegistry.sol"; -import { ReputationManager } from "../contracts/ReputationManager.sol"; + import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; From 49439a8a47af898ab78f34766ca651120eb7dd5f Mon Sep 17 00:00:00 2001 From: andy Date: Wed, 29 Jan 2025 09:17:50 -0500 Subject: [PATCH 4/5] clean up market registry --- .../contracts/contracts/MarketRegistry.sol | 323 +++++------------- .../contracts/interfaces/IMarketRegistry.sol | 2 +- .../contracts/mock/MarketRegistryMock.sol | 2 +- packages/contracts/deploy/market_registry.ts | 6 +- .../tests/MarketRegistry_Override.sol | 35 +- .../contracts/tests/MarketRegistry_Test.sol | 34 +- .../integration/IntegrationTestHelpers.sol | 2 +- 7 files changed, 121 insertions(+), 283 deletions(-) diff --git a/packages/contracts/contracts/MarketRegistry.sol b/packages/contracts/contracts/MarketRegistry.sol index b8762f13d..74a915ae5 100644 --- a/packages/contracts/contracts/MarketRegistry.sol +++ b/packages/contracts/contracts/MarketRegistry.sol @@ -2,8 +2,8 @@ pragma solidity ^0.8.0; // Contracts -import "./EAS/TellerAS.sol"; -import "./EAS/TellerASResolver.sol"; +//import "./EAS/TellerAS.sol"; + //must continue to use this so storage slots are not broken import "@openzeppelin/contracts/proxy/utils/Initializable.sol"; @@ -19,8 +19,8 @@ import { PaymentType } from "./libraries/V2Calculations.sol"; contract MarketRegistry is IMarketRegistry, Initializable, - Context, - TellerASResolver + Context + { using EnumerableSet for EnumerableSet.AddressSet; @@ -49,19 +49,19 @@ contract MarketRegistry is PaymentCycleType paymentCycleType; } - bytes32 public lenderAttestationSchemaId; + bytes32 private _lenderAttestationSchemaId; //DEPRECATED mapping(uint256 => Marketplace) internal markets; mapping(bytes32 => uint256) internal __uriToId; //DEPRECATED uint256 public marketCount; bytes32 private _attestingSchemaId; - bytes32 public borrowerAttestationSchemaId; + bytes32 private _borrowerAttestationSchemaId; //DEPRECATED uint256 public version; mapping(uint256 => bool) private marketIsClosed; - TellerAS public tellerAS; + TellerAS private _tellerAS; //DEPRECATED /* Modifiers */ @@ -70,11 +70,11 @@ contract MarketRegistry is _; } - modifier withAttestingSchema(bytes32 schemaId) { + /* modifier withAttestingSchema(bytes32 schemaId) { _attestingSchemaId = schemaId; _; _attestingSchemaId = bytes32(0); - } + } */ /* Events */ @@ -104,17 +104,17 @@ contract MarketRegistry is /* External Functions */ - function initialize(TellerAS _tellerAS) external initializer { - tellerAS = _tellerAS; + function initialize( ) external initializer { + // tellerAS = _tellerAS; - lenderAttestationSchemaId = tellerAS.getASRegistry().register( + /* lenderAttestationSchemaId = tellerAS.getASRegistry().register( "(uint256 marketId, address lenderAddress)", - this + IASResolver( address(this) ) ); borrowerAttestationSchemaId = tellerAS.getASRegistry().register( "(uint256 marketId, address borrowerAddress)", - this - ); + IASResolver( address(this) ) + ); */ } /** @@ -294,28 +294,7 @@ contract MarketRegistry is _attestStakeholder(_marketId, _lenderAddress, _expirationTime, true); } - /** - * @notice Adds a lender to a market via delegated attestation. - * @dev See {_attestStakeholderViaDelegation}. - */ - function attestLender( - uint256 _marketId, - address _lenderAddress, - uint256 _expirationTime, - uint8 _v, - bytes32 _r, - bytes32 _s - ) external { - _attestStakeholderViaDelegation( - _marketId, - _lenderAddress, - _expirationTime, - true, - _v, - _r, - _s - ); - } + /** * @notice Removes a lender from an market. @@ -325,27 +304,7 @@ contract MarketRegistry is _revokeStakeholder(_marketId, _lenderAddress, true); } - /** - * @notice Removes a borrower from a market via delegated revocation. - * @dev See {_revokeStakeholderViaDelegation}. - */ - /* function revokeLender( - uint256 _marketId, - address _lenderAddress, - uint8 _v, - bytes32 _r, - bytes32 _s - ) external { - _revokeStakeholderViaDelegation( - _marketId, - _lenderAddress, - true, - _v, - _r, - _s - ); - } */ - + /** * @notice Allows a lender to voluntarily leave a market. * @param _marketId The market ID to leave. @@ -372,28 +331,7 @@ contract MarketRegistry is _attestStakeholder(_marketId, _borrowerAddress, _expirationTime, false); } - /** - * @notice Adds a borrower to a market via delegated attestation. - * @dev See {_attestStakeholderViaDelegation}. - */ - function attestBorrower( - uint256 _marketId, - address _borrowerAddress, - uint256 _expirationTime, - uint8 _v, - bytes32 _r, - bytes32 _s - ) external { - _attestStakeholderViaDelegation( - _marketId, - _borrowerAddress, - _expirationTime, - false, - _v, - _r, - _s - ); - } + /** * @notice Removes a borrower from an market. @@ -405,27 +343,7 @@ contract MarketRegistry is _revokeStakeholder(_marketId, _borrowerAddress, false); } - /** - * @notice Removes a borrower from a market via delegated revocation. - * @dev See {_revokeStakeholderViaDelegation}. - */ - /* function revokeBorrower( - uint256 _marketId, - address _borrowerAddress, - uint8 _v, - bytes32 _r, - bytes32 _s - ) external { - _revokeStakeholderViaDelegation( - _marketId, - _borrowerAddress, - false, - _v, - _r, - _s - ); - }*/ - + /** * @notice Allows a borrower to voluntarily leave a market. * @param _marketId The market ID to leave. @@ -456,7 +374,7 @@ contract MarketRegistry is bytes calldata data, uint256 /* expirationTime */, address attestor - ) external payable override returns (bool) { + ) external payable returns (bool) { bytes32 attestationSchemaId = keccak256( abi.encodePacked(schema, address(this)) ); @@ -992,38 +910,8 @@ contract MarketRegistry is setPaymentCycle(_marketId, _paymentCycleType, _paymentCycleDuration); } - /** - * @notice Gets addresses of all attested relevant stakeholders. - * @param _set The stored set of stakeholders to index from. - * @param _page Page index to start from. - * @param _perPage Number of items in a page to return. - * @return stakeholders_ Array of addresses that have been added to a market. - */ - function _getStakeholdersForMarket( - EnumerableSet.AddressSet storage _set, - uint256 _page, - uint256 _perPage - ) internal view returns (address[] memory stakeholders_) { - uint256 len = _set.length(); - - uint256 start = _page * _perPage; - if (start <= len) { - uint256 end = start + _perPage; - // Ensure we do not go out of bounds - if (end > len) { - end = len; - } - - stakeholders_ = new address[](end - start); - for (uint256 i = start; i < end; i++) { - stakeholders_[i] = _set.at(i); - } - } - } - - /* Internal Functions */ - /** + /** * @notice Adds a stakeholder (lender or borrower) to a market. * @param _marketId The market ID to add a borrower to. * @param _stakeholderAddress The address of the stakeholder to add to the market. @@ -1039,9 +927,9 @@ contract MarketRegistry is ) internal virtual - withAttestingSchema( + /* withAttestingSchema( _isLender ? lenderAttestationSchemaId : borrowerAttestationSchemaId - ) + ) */ { require( _msgSender() == _getMarketOwner(_marketId), @@ -1049,91 +937,42 @@ contract MarketRegistry is ); // Submit attestation for borrower to join a market - bytes32 uuid = tellerAS.attest( + /* bytes32 uuid = tellerAS.attest( _stakeholderAddress, _attestingSchemaId, // set by the modifier _expirationTime, 0, abi.encode(_marketId, _stakeholderAddress) - ); + ); */ _attestStakeholderVerification( _marketId, _stakeholderAddress, - uuid, + // uuid, _isLender ); } - /** - * @notice Adds a stakeholder (lender or borrower) to a market via delegated attestation. - * @dev The signature must match that of the market owner. - * @param _marketId The market ID to add a lender to. - * @param _stakeholderAddress The address of the lender to add to the market. - * @param _expirationTime The expiration time of the attestation. - * @param _isLender Boolean indicating if the stakeholder is a lender. Otherwise it is a borrower. - * @param _v Signature value - * @param _r Signature value - * @param _s Signature value - */ - function _attestStakeholderViaDelegation( - uint256 _marketId, - address _stakeholderAddress, - uint256 _expirationTime, - bool _isLender, - uint8 _v, - bytes32 _r, - bytes32 _s - ) - internal - virtual - withAttestingSchema( - _isLender ? lenderAttestationSchemaId : borrowerAttestationSchemaId - ) - { - // NOTE: block scope to prevent stack too deep! - bytes32 uuid; - { - bytes memory data = abi.encode(_marketId, _stakeholderAddress); - address attestor = _getMarketOwner(_marketId); - // Submit attestation for stakeholder to join a market (attestation must be signed by market owner) - uuid = tellerAS.attestByDelegation( - _stakeholderAddress, - _attestingSchemaId, // set by the modifier - _expirationTime, - 0, - data, - attestor, - _v, - _r, - _s - ); - } - _attestStakeholderVerification( - _marketId, - _stakeholderAddress, - uuid, - _isLender - ); - } + - /** + + /** * @notice Adds a stakeholder (borrower/lender) to a market. * @param _marketId The market ID to add a stakeholder to. * @param _stakeholderAddress The address of the stakeholder to add to the market. - * @param _uuid The UUID of the attestation created. + * @param _isLender Boolean indicating if the stakeholder is a lender. Otherwise it is a borrower. */ function _attestStakeholderVerification( uint256 _marketId, address _stakeholderAddress, - bytes32 _uuid, + // bytes32 _uuid, bool _isLender ) internal virtual { if (_isLender) { // Store the lender attestation ID for the market ID - markets[_marketId].lenderAttestationIds[ + /* markets[_marketId].lenderAttestationIds[ _stakeholderAddress - ] = _uuid; + ] = _uuid; */ // Add lender address to market set markets[_marketId].verifiedLendersForMarket.add( _stakeholderAddress @@ -1142,9 +981,9 @@ contract MarketRegistry is emit LenderAttestation(_marketId, _stakeholderAddress); } else { // Store the lender attestation ID for the market ID - markets[_marketId].borrowerAttestationIds[ + /* markets[_marketId].borrowerAttestationIds[ _stakeholderAddress - ] = _uuid; + ] = _uuid; */ // Add lender address to market set markets[_marketId].verifiedBorrowersForMarket.add( _stakeholderAddress @@ -1152,9 +991,10 @@ contract MarketRegistry is emit BorrowerAttestation(_marketId, _stakeholderAddress); } - } + } - /** + + /** * @notice Removes a stakeholder from an market. * @dev The caller must be the market owner. * @param _marketId The market ID to remove the borrower from. @@ -1171,7 +1011,7 @@ contract MarketRegistry is "Not the market owner" ); - bytes32 uuid = _revokeStakeholderVerification( + _revokeStakeholderVerification( _marketId, _stakeholderAddress, _isLender @@ -1180,41 +1020,15 @@ contract MarketRegistry is // tellerAS.revoke(uuid); } - - /* function _revokeStakeholderViaDelegation( - uint256 _marketId, - address _stakeholderAddress, - bool _isLender, - uint8 _v, - bytes32 _r, - bytes32 _s - ) internal { - bytes32 uuid = _revokeStakeholderVerification( - _marketId, - _stakeholderAddress, - _isLender - ); - // NOTE: Disabling the call to revoke the attestation on EAS contracts - // address attestor = markets[_marketId].owner; - // tellerAS.revokeByDelegation(uuid, attestor, _v, _r, _s); - } */ - /** - * @notice Removes a stakeholder (borrower/lender) from a market. - * @param _marketId The market ID to remove the lender from. - * @param _stakeholderAddress The address of the stakeholder to remove from the market. - * @param _isLender Boolean indicating if the stakeholder is a lender. Otherwise it is a borrower. - * @return uuid_ The ID of the previously verified attestation. - */ - function _revokeStakeholderVerification( + + function _revokeStakeholderVerification( uint256 _marketId, address _stakeholderAddress, bool _isLender - ) internal virtual returns (bytes32 uuid_) { + ) internal virtual { if (_isLender) { - uuid_ = markets[_marketId].lenderAttestationIds[ - _stakeholderAddress - ]; + // Remove lender address from market set markets[_marketId].verifiedLendersForMarket.remove( _stakeholderAddress @@ -1222,9 +1036,7 @@ contract MarketRegistry is emit LenderRevocation(_marketId, _stakeholderAddress); } else { - uuid_ = markets[_marketId].borrowerAttestationIds[ - _stakeholderAddress - ]; + // Remove borrower address from market set markets[_marketId].verifiedBorrowersForMarket.remove( _stakeholderAddress @@ -1234,6 +1046,43 @@ contract MarketRegistry is } } + + + /** + * @notice Gets addresses of all attested relevant stakeholders. + * @param _set The stored set of stakeholders to index from. + * @param _page Page index to start from. + * @param _perPage Number of items in a page to return. + * @return stakeholders_ Array of addresses that have been added to a market. + */ + function _getStakeholdersForMarket( + EnumerableSet.AddressSet storage _set, + uint256 _page, + uint256 _perPage + ) internal view returns (address[] memory stakeholders_) { + uint256 len = _set.length(); + + uint256 start = _page * _perPage; + if (start <= len) { + uint256 end = start + _perPage; + // Ensure we do not go out of bounds + if (end > len) { + end = len; + } + + stakeholders_ = new address[](end - start); + for (uint256 i = start; i < end; i++) { + stakeholders_[i] = _set.at(i); + } + } + } + + /* Internal Functions */ + + + + + /** * @notice Checks if a stakeholder has been attested and added to a market. * @param _stakeholderAddress Address of the stakeholder to check. @@ -1248,13 +1097,13 @@ contract MarketRegistry is ) internal view virtual returns (bool isVerified_, bytes32 uuid_) { if (_attestationRequired) { isVerified_ = - _verifiedStakeholderForMarket.contains(_stakeholderAddress) && - tellerAS.isAttestationActive( - _stakeholderAttestationIds[_stakeholderAddress] - ); - uuid_ = _stakeholderAttestationIds[_stakeholderAddress]; + _verifiedStakeholderForMarket.contains(_stakeholderAddress) ; + uuid_ = _stakeholderAttestationIds[_stakeholderAddress]; //deprecated } else { isVerified_ = true; } } + + + } diff --git a/packages/contracts/contracts/interfaces/IMarketRegistry.sol b/packages/contracts/contracts/interfaces/IMarketRegistry.sol index 4dd6cf698..cd557453b 100644 --- a/packages/contracts/contracts/interfaces/IMarketRegistry.sol +++ b/packages/contracts/contracts/interfaces/IMarketRegistry.sol @@ -5,7 +5,7 @@ import "../EAS/TellerAS.sol"; import { PaymentType, PaymentCycleType } from "../libraries/V2Calculations.sol"; interface IMarketRegistry { - function initialize(TellerAS tellerAs) external; + function initialize( ) external; function isVerifiedLender(uint256 _marketId, address _lender) external diff --git a/packages/contracts/contracts/mock/MarketRegistryMock.sol b/packages/contracts/contracts/mock/MarketRegistryMock.sol index 2496a0b96..4b5762f3d 100644 --- a/packages/contracts/contracts/mock/MarketRegistryMock.sol +++ b/packages/contracts/contracts/mock/MarketRegistryMock.sol @@ -17,7 +17,7 @@ contract MarketRegistryMock is IMarketRegistry { constructor() {} - function initialize(TellerAS _tellerAS) external {} + function initialize( ) external {} function isVerifiedLender(uint256 _marketId, address _lenderAddress) public diff --git a/packages/contracts/deploy/market_registry.ts b/packages/contracts/deploy/market_registry.ts index 8e024fe76..bd64f32f4 100644 --- a/packages/contracts/deploy/market_registry.ts +++ b/packages/contracts/deploy/market_registry.ts @@ -2,7 +2,7 @@ import { DeployFunction } from 'hardhat-deploy/dist/types' import { deploy } from 'helpers/deploy-helpers' const deployFn: DeployFunction = async (hre) => { - const registry = await deploy({ + /* const registry = await deploy({ contract: 'TellerASRegistry', skipIfAlreadyDeployed: true, hre, @@ -17,10 +17,10 @@ const deployFn: DeployFunction = async (hre) => { args: [await registry.getAddress(), await verifier.getAddress()], skipIfAlreadyDeployed: true, hre, - }) + }) */ const marketRegistry = await hre.deployProxy('MarketRegistry', { - initArgs: [await tellerAS.getAddress()], + initArgs: [ ], }) return true diff --git a/packages/contracts/tests/MarketRegistry_Override.sol b/packages/contracts/tests/MarketRegistry_Override.sol index 27360ffc1..77083264c 100644 --- a/packages/contracts/tests/MarketRegistry_Override.sol +++ b/packages/contracts/tests/MarketRegistry_Override.sol @@ -12,7 +12,7 @@ import "../contracts/TellerV2Storage.sol"; import "../contracts/interfaces/IMarketRegistry.sol"; -import "../contracts/EAS/TellerAS.sol"; +//import "../contracts/EAS/TellerAS.sol"; import "../contracts/mock/WethMock.sol"; import "../contracts/interfaces/IWETH.sol"; @@ -26,11 +26,11 @@ contract MarketRegistry_Override is MarketRegistry { address globalMarketOwner; address globalFeeRecipient; - bool public attestStakeholderWasCalled; + bool public attestStakeholderWasCalled; bool public attestStakeholderVerificationWasCalled; - bool public attestStakeholderViaDelegationWasCalled; + // bool public attestStakeholderViaDelegationWasCalled; bool public revokeStakeholderWasCalled; - bool public revokeStakeholderVerificationWasCalled; + bool public revokeStakeholderVerificationWasCalled; constructor() MarketRegistry() {} @@ -71,13 +71,13 @@ contract MarketRegistry_Override is MarketRegistry { function attestStakeholderVerification( uint256 _marketId, address _stakeholderAddress, - bytes32 _uuid, + // bytes32 _uuid, bool _isLender ) public { super._attestStakeholderVerification( _marketId, _stakeholderAddress, - _uuid, + // _uuid, _isLender ); } @@ -118,7 +118,7 @@ contract MarketRegistry_Override is MarketRegistry { return markets[_marketId].verifiedBorrowersForMarket.contains(guy); } - function getLenderAttestationId(uint256 _marketId, address guy) +/* function getLenderAttestationId(uint256 _marketId, address guy) public returns (bytes32) { @@ -130,8 +130,8 @@ contract MarketRegistry_Override is MarketRegistry { returns (bytes32) { return markets[_marketId].borrowerAttestationIds[guy]; - } - + } */ + /* @notice returns the actual value in the markets storage mapping, not globalMarketOwner the override */ @@ -183,23 +183,12 @@ contract MarketRegistry_Override is MarketRegistry { function _attestStakeholderVerification( uint256 _marketId, address _stakeholderAddress, - bytes32 _uuid, + bool _isLender ) internal override { attestStakeholderVerificationWasCalled = true; } - - function _attestStakeholderViaDelegation( - uint256 _marketId, - address _stakeholderAddress, - uint256 _expirationTime, - bool _isLender, - uint8 _v, - bytes32 _r, - bytes32 _s - ) internal override { - attestStakeholderViaDelegationWasCalled = true; - } + function _revokeStakeholder( uint256 _marketId, @@ -213,7 +202,7 @@ contract MarketRegistry_Override is MarketRegistry { uint256 _marketId, address _stakeholderAddress, bool _isLender - ) internal override returns (bytes32 uuid_) { + ) internal override { revokeStakeholderVerificationWasCalled = true; } diff --git a/packages/contracts/tests/MarketRegistry_Test.sol b/packages/contracts/tests/MarketRegistry_Test.sol index 8a62cefc5..e53140164 100644 --- a/packages/contracts/tests/MarketRegistry_Test.sol +++ b/packages/contracts/tests/MarketRegistry_Test.sol @@ -22,7 +22,7 @@ import { PaymentType, PaymentCycleType } from "../contracts/libraries/V2Calculat import { MarketRegistry_Override } from "./MarketRegistry_Override.sol"; -import { TellerASMock } from "../contracts/mock/TellerASMock.sol"; +// import { TellerASMock } from "../contracts/mock/TellerASMock.sol"; contract MarketRegistry_Test is Testable { MarketRegistryUser private marketOwner; @@ -36,7 +36,7 @@ contract MarketRegistry_Test is Testable { TellerV2Mock tellerV2; MarketRegistry_Override marketRegistry; - TellerASMock tellerASMock; + // TellerASMock tellerASMock; uint32 expirationTime = 5000; uint256 marketId = 2; @@ -53,9 +53,9 @@ contract MarketRegistry_Test is Testable { tellerV2 = new TellerV2Mock(); marketRegistry = new MarketRegistry_Override(); - tellerASMock = new TellerASMock(); + //tellerASMock = new TellerASMock(); - marketRegistry.initialize(tellerASMock); + marketRegistry.initialize( ); marketOwner = new MarketRegistryUser( address(tellerV2), @@ -302,7 +302,7 @@ FNDA:0,MarketRegistry._attestStakeholderViaDelegation marketRegistry.attestStakeholderVerification( marketId, address(lender), - uuid, + // uuid, isLender ); @@ -317,11 +317,11 @@ FNDA:0,MarketRegistry._attestStakeholderViaDelegation "Did not add lender to verified set" ); - assertEq( + /* assertEq( marketRegistry.getLenderAttestationId(marketId, address(lender)), uuid, "Did not set market attestation Id" - ); + ); */ } function test_attestStakeholderVerification_borrower() public { @@ -330,7 +330,7 @@ FNDA:0,MarketRegistry._attestStakeholderViaDelegation marketRegistry.attestStakeholderVerification( marketId, address(borrower), - uuid, + // uuid, isLender ); @@ -345,14 +345,14 @@ FNDA:0,MarketRegistry._attestStakeholderViaDelegation "Did not add lender to verified set" ); - assertEq( + /* assertEq( marketRegistry.getBorrowerAttestationId( marketId, address(borrower) ), uuid, "Did not set market attestation Id" - ); + ); */ } function test_attestLender() public { @@ -367,7 +367,7 @@ FNDA:0,MarketRegistry._attestStakeholderViaDelegation function test_attestLender_expired() public {} - function test_attestLenderDelegated() public { + /* function test_attestLenderDelegated() public { marketRegistry.attestLender( marketId, address(lender), @@ -382,7 +382,7 @@ FNDA:0,MarketRegistry._attestStakeholderViaDelegation true, "Attest stakeholder via delegation was not called" ); - } + } */ function test_attestBorrower() public { marketRegistry.attestBorrower( @@ -398,7 +398,7 @@ FNDA:0,MarketRegistry._attestStakeholderViaDelegation ); } - function test_attestBorrowerDelegated() public { + /* function test_attestBorrowerDelegated() public { marketRegistry.attestBorrower( marketId, address(lender), @@ -413,7 +413,7 @@ FNDA:0,MarketRegistry._attestStakeholderViaDelegation true, "Attest stakeholder via delegation was not called" ); - } + } */ function test_revokeLender() public { marketRegistry.revokeLender(marketId, address(lender)); @@ -946,7 +946,7 @@ FNDA:0,MarketRegistry._attestStakeholderViaDelegation marketRegistry.attestStakeholderVerification( marketId, address(lender), - uuid, + // uuid, true ); @@ -998,7 +998,7 @@ FNDA:0,MarketRegistry._attestStakeholderViaDelegation marketRegistry.attestStakeholderVerification( marketId, address(borrower), - uuid, + // uuid, isLender ); @@ -1028,7 +1028,7 @@ FNDA:0,MarketRegistry._attestStakeholderViaDelegation marketRegistry.attestStakeholderVerification( marketId, address(lender), - uuid, + // uuid, isLender ); diff --git a/packages/contracts/tests/integration/IntegrationTestHelpers.sol b/packages/contracts/tests/integration/IntegrationTestHelpers.sol index 4807d2fba..6dd46331d 100644 --- a/packages/contracts/tests/integration/IntegrationTestHelpers.sol +++ b/packages/contracts/tests/integration/IntegrationTestHelpers.sol @@ -29,7 +29,7 @@ library IntegrationTestHelpers { TellerAS tellerAS = new TellerAS((iasRegistry), (ieaseip712verifier)); MarketRegistry marketRegistry = new MarketRegistry(); - marketRegistry.initialize(tellerAS); + marketRegistry.initialize( ); return address(marketRegistry); } From b1fe1231896304294c705f2642d4813e713fc669 Mon Sep 17 00:00:00 2001 From: andy Date: Wed, 29 Jan 2025 09:24:26 -0500 Subject: [PATCH 5/5] removing teller as completely --- packages/contracts/contracts/EAS/TellerAS.sol | 514 ------------------ .../contracts/EAS/TellerASEIP712Verifier.sol | 128 ----- .../contracts/EAS/TellerASRegistry.sol | 81 --- .../contracts/EAS/TellerASResolver.sol | 21 - .../contracts/contracts/MarketRegistry.sol | 2 +- .../contracts/interfaces/IMarketRegistry.sol | 2 +- .../contracts/contracts/mock/TellerASMock.sol | 27 - .../contracts/tests/MarketRegistry_Test.sol | 2 +- .../tests/TellerV2/TellerV2_Test.sol | 2 +- .../contracts/tests/TellerV2Autopay_Test.sol | 2 +- .../integration/IntegrationTestHelpers.sol | 8 +- .../resolvers/TestASAttestationResolver.sol | 52 -- .../resolvers/TestASAttesterResolver.sol | 25 - .../tests/resolvers/TestASDataResolver.sol | 20 - .../TestASExpirationTimeResolver.sol | 25 - .../tests/resolvers/TestASPayingResolver.sol | 31 -- .../resolvers/TestASRecipientResolver.sol | 25 - .../tests/resolvers/TestASTokenResolver.sol | 33 -- .../tests/resolvers/TestASValueResolver.sol | 29 - 19 files changed, 10 insertions(+), 1019 deletions(-) delete mode 100644 packages/contracts/contracts/EAS/TellerAS.sol delete mode 100644 packages/contracts/contracts/EAS/TellerASEIP712Verifier.sol delete mode 100644 packages/contracts/contracts/EAS/TellerASRegistry.sol delete mode 100644 packages/contracts/contracts/EAS/TellerASResolver.sol delete mode 100644 packages/contracts/contracts/mock/TellerASMock.sol delete mode 100644 packages/contracts/tests/resolvers/TestASAttestationResolver.sol delete mode 100644 packages/contracts/tests/resolvers/TestASAttesterResolver.sol delete mode 100644 packages/contracts/tests/resolvers/TestASDataResolver.sol delete mode 100644 packages/contracts/tests/resolvers/TestASExpirationTimeResolver.sol delete mode 100644 packages/contracts/tests/resolvers/TestASPayingResolver.sol delete mode 100644 packages/contracts/tests/resolvers/TestASRecipientResolver.sol delete mode 100644 packages/contracts/tests/resolvers/TestASTokenResolver.sol delete mode 100644 packages/contracts/tests/resolvers/TestASValueResolver.sol diff --git a/packages/contracts/contracts/EAS/TellerAS.sol b/packages/contracts/contracts/EAS/TellerAS.sol deleted file mode 100644 index 759d2565a..000000000 --- a/packages/contracts/contracts/EAS/TellerAS.sol +++ /dev/null @@ -1,514 +0,0 @@ -pragma solidity >=0.8.0 <0.9.0; -// SPDX-License-Identifier: MIT - -import "../Types.sol"; -import "../interfaces/IEAS.sol"; -import "../interfaces/IASRegistry.sol"; - -/** - * @title TellerAS - Teller Attestation Service - based on EAS - Ethereum Attestation Service - */ -contract TellerAS is IEAS { - error AccessDenied(); - error AlreadyRevoked(); - error InvalidAttestation(); - error InvalidExpirationTime(); - error InvalidOffset(); - error InvalidRegistry(); - error InvalidSchema(); - error InvalidVerifier(); - error NotFound(); - error NotPayable(); - - string public constant VERSION = "0.8"; - - // A terminator used when concatenating and hashing multiple fields. - string private constant HASH_TERMINATOR = "@"; - - // The AS global registry. - IASRegistry private immutable _asRegistry; - - // The EIP712 verifier used to verify signed attestations. - IEASEIP712Verifier private immutable _eip712Verifier; - - // A mapping between attestations and their related attestations. - mapping(bytes32 => bytes32[]) private _relatedAttestations; - - // A mapping between an account and its received attestations. - mapping(address => mapping(bytes32 => bytes32[])) - private _receivedAttestations; - - // A mapping between an account and its sent attestations. - mapping(address => mapping(bytes32 => bytes32[])) private _sentAttestations; - - // A mapping between a schema and its attestations. - mapping(bytes32 => bytes32[]) private _schemaAttestations; - - // The global mapping between attestations and their UUIDs. - mapping(bytes32 => Attestation) private _db; - - // The global counter for the total number of attestations. - uint256 private _attestationsCount; - - bytes32 private _lastUUID; - - /** - * @dev Creates a new EAS instance. - * - * @param registry The address of the global AS registry. - * @param verifier The address of the EIP712 verifier. - */ - constructor(IASRegistry registry, IEASEIP712Verifier verifier) { - if (address(registry) == address(0x0)) { - revert InvalidRegistry(); - } - - if (address(verifier) == address(0x0)) { - revert InvalidVerifier(); - } - - _asRegistry = registry; - _eip712Verifier = verifier; - } - - /** - * @inheritdoc IEAS - */ - function getASRegistry() external view override returns (IASRegistry) { - return _asRegistry; - } - - /** - * @inheritdoc IEAS - */ - function getEIP712Verifier() - external - view - override - returns (IEASEIP712Verifier) - { - return _eip712Verifier; - } - - /** - * @inheritdoc IEAS - */ - function getAttestationsCount() external view override returns (uint256) { - return _attestationsCount; - } - - /** - * @inheritdoc IEAS - */ - function attest( - address recipient, - bytes32 schema, - uint256 expirationTime, - bytes32 refUUID, - bytes calldata data - ) public payable virtual override returns (bytes32) { - return - _attest( - recipient, - schema, - expirationTime, - refUUID, - data, - msg.sender - ); - } - - /** - * @inheritdoc IEAS - */ - function attestByDelegation( - address recipient, - bytes32 schema, - uint256 expirationTime, - bytes32 refUUID, - bytes calldata data, - address attester, - uint8 v, - bytes32 r, - bytes32 s - ) public payable virtual override returns (bytes32) { - _eip712Verifier.attest( - recipient, - schema, - expirationTime, - refUUID, - data, - attester, - v, - r, - s - ); - - return - _attest(recipient, schema, expirationTime, refUUID, data, attester); - } - - /** - * @inheritdoc IEAS - */ - function revoke(bytes32 uuid) public virtual override { - return _revoke(uuid, msg.sender); - } - - /** - * @inheritdoc IEAS - */ - function revokeByDelegation( - bytes32 uuid, - address attester, - uint8 v, - bytes32 r, - bytes32 s - ) public virtual override { - _eip712Verifier.revoke(uuid, attester, v, r, s); - - _revoke(uuid, attester); - } - - /** - * @inheritdoc IEAS - */ - function getAttestation(bytes32 uuid) - external - view - override - returns (Attestation memory) - { - return _db[uuid]; - } - - /** - * @inheritdoc IEAS - */ - function isAttestationValid(bytes32 uuid) - public - view - override - returns (bool) - { - return _db[uuid].uuid != 0; - } - - /** - * @inheritdoc IEAS - */ - function isAttestationActive(bytes32 uuid) - public - view - virtual - override - returns (bool) - { - return - isAttestationValid(uuid) && - _db[uuid].expirationTime >= block.timestamp && - _db[uuid].revocationTime == 0; - } - - /** - * @inheritdoc IEAS - */ - function getReceivedAttestationUUIDs( - address recipient, - bytes32 schema, - uint256 start, - uint256 length, - bool reverseOrder - ) external view override returns (bytes32[] memory) { - return - _sliceUUIDs( - _receivedAttestations[recipient][schema], - start, - length, - reverseOrder - ); - } - - /** - * @inheritdoc IEAS - */ - function getReceivedAttestationUUIDsCount(address recipient, bytes32 schema) - external - view - override - returns (uint256) - { - return _receivedAttestations[recipient][schema].length; - } - - /** - * @inheritdoc IEAS - */ - function getSentAttestationUUIDs( - address attester, - bytes32 schema, - uint256 start, - uint256 length, - bool reverseOrder - ) external view override returns (bytes32[] memory) { - return - _sliceUUIDs( - _sentAttestations[attester][schema], - start, - length, - reverseOrder - ); - } - - /** - * @inheritdoc IEAS - */ - function getSentAttestationUUIDsCount(address recipient, bytes32 schema) - external - view - override - returns (uint256) - { - return _sentAttestations[recipient][schema].length; - } - - /** - * @inheritdoc IEAS - */ - function getRelatedAttestationUUIDs( - bytes32 uuid, - uint256 start, - uint256 length, - bool reverseOrder - ) external view override returns (bytes32[] memory) { - return - _sliceUUIDs( - _relatedAttestations[uuid], - start, - length, - reverseOrder - ); - } - - /** - * @inheritdoc IEAS - */ - function getRelatedAttestationUUIDsCount(bytes32 uuid) - external - view - override - returns (uint256) - { - return _relatedAttestations[uuid].length; - } - - /** - * @inheritdoc IEAS - */ - function getSchemaAttestationUUIDs( - bytes32 schema, - uint256 start, - uint256 length, - bool reverseOrder - ) external view override returns (bytes32[] memory) { - return - _sliceUUIDs( - _schemaAttestations[schema], - start, - length, - reverseOrder - ); - } - - /** - * @inheritdoc IEAS - */ - function getSchemaAttestationUUIDsCount(bytes32 schema) - external - view - override - returns (uint256) - { - return _schemaAttestations[schema].length; - } - - /** - * @dev Attests to a specific AS. - * - * @param recipient The recipient of the attestation. - * @param schema The UUID of the AS. - * @param expirationTime The expiration time of the attestation. - * @param refUUID An optional related attestation's UUID. - * @param data Additional custom data. - * @param attester The attesting account. - * - * @return The UUID of the new attestation. - */ - function _attest( - address recipient, - bytes32 schema, - uint256 expirationTime, - bytes32 refUUID, - bytes calldata data, - address attester - ) private returns (bytes32) { - if (expirationTime <= block.timestamp) { - revert InvalidExpirationTime(); - } - - IASRegistry.ASRecord memory asRecord = _asRegistry.getAS(schema); - if (asRecord.uuid == EMPTY_UUID) { - revert InvalidSchema(); - } - - IASResolver resolver = asRecord.resolver; - if (address(resolver) != address(0x0)) { - if (msg.value != 0 && !resolver.isPayable()) { - revert NotPayable(); - } - - if ( - !resolver.resolve{ value: msg.value }( - recipient, - asRecord.schema, - data, - expirationTime, - attester - ) - ) { - revert InvalidAttestation(); - } - } - - Attestation memory attestation = Attestation({ - uuid: EMPTY_UUID, - schema: schema, - recipient: recipient, - attester: attester, - time: block.timestamp, - expirationTime: expirationTime, - revocationTime: 0, - refUUID: refUUID, - data: data - }); - - _lastUUID = _getUUID(attestation); - attestation.uuid = _lastUUID; - - _receivedAttestations[recipient][schema].push(_lastUUID); - _sentAttestations[attester][schema].push(_lastUUID); - _schemaAttestations[schema].push(_lastUUID); - - _db[_lastUUID] = attestation; - _attestationsCount++; - - if (refUUID != 0) { - if (!isAttestationValid(refUUID)) { - revert NotFound(); - } - - _relatedAttestations[refUUID].push(_lastUUID); - } - - emit Attested(recipient, attester, _lastUUID, schema); - - return _lastUUID; - } - - function getLastUUID() external view returns (bytes32) { - return _lastUUID; - } - - /** - * @dev Revokes an existing attestation to a specific AS. - * - * @param uuid The UUID of the attestation to revoke. - * @param attester The attesting account. - */ - function _revoke(bytes32 uuid, address attester) private { - Attestation storage attestation = _db[uuid]; - if (attestation.uuid == EMPTY_UUID) { - revert NotFound(); - } - - if (attestation.attester != attester) { - revert AccessDenied(); - } - - if (attestation.revocationTime != 0) { - revert AlreadyRevoked(); - } - - attestation.revocationTime = block.timestamp; - - emit Revoked(attestation.recipient, attester, uuid, attestation.schema); - } - - /** - * @dev Calculates a UUID for a given attestation. - * - * @param attestation The input attestation. - * - * @return Attestation UUID. - */ - function _getUUID(Attestation memory attestation) - private - view - returns (bytes32) - { - return - keccak256( - abi.encodePacked( - attestation.schema, - attestation.recipient, - attestation.attester, - attestation.time, - attestation.expirationTime, - attestation.data, - HASH_TERMINATOR, - _attestationsCount - ) - ); - } - - /** - * @dev Returns a slice in an array of attestation UUIDs. - * - * @param uuids The array of attestation UUIDs. - * @param start The offset to start from. - * @param length The number of total members to retrieve. - * @param reverseOrder Whether the offset starts from the end and the data is returned in reverse. - * - * @return An array of attestation UUIDs. - */ - function _sliceUUIDs( - bytes32[] memory uuids, - uint256 start, - uint256 length, - bool reverseOrder - ) private pure returns (bytes32[] memory) { - uint256 attestationsLength = uuids.length; - if (attestationsLength == 0) { - return new bytes32[](0); - } - - if (start >= attestationsLength) { - revert InvalidOffset(); - } - - uint256 len = length; - if (attestationsLength < start + length) { - len = attestationsLength - start; - } - - bytes32[] memory res = new bytes32[](len); - - for (uint256 i = 0; i < len; ++i) { - res[i] = uuids[ - reverseOrder ? attestationsLength - (start + i + 1) : start + i - ]; - } - - return res; - } -} diff --git a/packages/contracts/contracts/EAS/TellerASEIP712Verifier.sol b/packages/contracts/contracts/EAS/TellerASEIP712Verifier.sol deleted file mode 100644 index 18dd3e6eb..000000000 --- a/packages/contracts/contracts/EAS/TellerASEIP712Verifier.sol +++ /dev/null @@ -1,128 +0,0 @@ -pragma solidity >=0.8.0 <0.9.0; -// SPDX-License-Identifier: MIT - -import "../interfaces/IEASEIP712Verifier.sol"; - -/** - * @title EIP712 typed signatures verifier for EAS delegated attestations. - */ -contract TellerASEIP712Verifier is IEASEIP712Verifier { - error InvalidSignature(); - - string public constant VERSION = "0.8"; - - // EIP712 domain separator, making signatures from different domains incompatible. - bytes32 public immutable DOMAIN_SEPARATOR; // solhint-disable-line var-name-mixedcase - - // The hash of the data type used to relay calls to the attest function. It's the value of - // keccak256("Attest(address recipient,bytes32 schema,uint256 expirationTime,bytes32 refUUID,bytes data,uint256 nonce)"). - bytes32 public constant ATTEST_TYPEHASH = - 0x39c0608dd995a3a25bfecb0fffe6801a81bae611d94438af988caa522d9d1476; - - // The hash of the data type used to relay calls to the revoke function. It's the value of - // keccak256("Revoke(bytes32 uuid,uint256 nonce)"). - bytes32 public constant REVOKE_TYPEHASH = - 0xbae0931f3a99efd1b97c2f5b6b6e79d16418246b5055d64757e16de5ad11a8ab; - - // Replay protection nonces. - mapping(address => uint256) private _nonces; - - /** - * @dev Creates a new EIP712Verifier instance. - */ - constructor() { - uint256 chainId; - // solhint-disable-next-line no-inline-assembly - assembly { - chainId := chainid() - } - - DOMAIN_SEPARATOR = keccak256( - abi.encode( - keccak256( - "EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)" - ), - keccak256(bytes("EAS")), - keccak256(bytes(VERSION)), - chainId, - address(this) - ) - ); - } - - /** - * @inheritdoc IEASEIP712Verifier - */ - function getNonce(address account) - external - view - override - returns (uint256) - { - return _nonces[account]; - } - - /** - * @inheritdoc IEASEIP712Verifier - */ - function attest( - address recipient, - bytes32 schema, - uint256 expirationTime, - bytes32 refUUID, - bytes calldata data, - address attester, - uint8 v, - bytes32 r, - bytes32 s - ) external override { - bytes32 digest = keccak256( - abi.encodePacked( - "\x19\x01", - DOMAIN_SEPARATOR, - keccak256( - abi.encode( - ATTEST_TYPEHASH, - recipient, - schema, - expirationTime, - refUUID, - keccak256(data), - _nonces[attester]++ - ) - ) - ) - ); - - address recoveredAddress = ecrecover(digest, v, r, s); - if (recoveredAddress == address(0) || recoveredAddress != attester) { - revert InvalidSignature(); - } - } - - /** - * @inheritdoc IEASEIP712Verifier - */ - function revoke( - bytes32 uuid, - address attester, - uint8 v, - bytes32 r, - bytes32 s - ) external override { - bytes32 digest = keccak256( - abi.encodePacked( - "\x19\x01", - DOMAIN_SEPARATOR, - keccak256( - abi.encode(REVOKE_TYPEHASH, uuid, _nonces[attester]++) - ) - ) - ); - - address recoveredAddress = ecrecover(digest, v, r, s); - if (recoveredAddress == address(0) || recoveredAddress != attester) { - revert InvalidSignature(); - } - } -} diff --git a/packages/contracts/contracts/EAS/TellerASRegistry.sol b/packages/contracts/contracts/EAS/TellerASRegistry.sol deleted file mode 100644 index 2a7e2bf95..000000000 --- a/packages/contracts/contracts/EAS/TellerASRegistry.sol +++ /dev/null @@ -1,81 +0,0 @@ -pragma solidity >=0.8.0 <0.9.0; -// SPDX-License-Identifier: MIT - -import "../Types.sol"; -import "../interfaces/IASRegistry.sol"; -import "../interfaces/IASResolver.sol"; - -/** - * @title The global AS registry. - */ -contract TellerASRegistry is IASRegistry { - error AlreadyExists(); - - string public constant VERSION = "0.8"; - - // The global mapping between AS records and their IDs. - mapping(bytes32 => ASRecord) private _registry; - - // The global counter for the total number of attestations. - uint256 private _asCount; - - /** - * @inheritdoc IASRegistry - */ - function register(bytes calldata schema, IASResolver resolver) - external - override - returns (bytes32) - { - uint256 index = ++_asCount; - - ASRecord memory asRecord = ASRecord({ - uuid: EMPTY_UUID, - index: index, - schema: schema, - resolver: resolver - }); - - bytes32 uuid = _getUUID(asRecord); - if (_registry[uuid].uuid != EMPTY_UUID) { - revert AlreadyExists(); - } - - asRecord.uuid = uuid; - _registry[uuid] = asRecord; - - emit Registered(uuid, index, schema, resolver, msg.sender); - - return uuid; - } - - /** - * @inheritdoc IASRegistry - */ - function getAS(bytes32 uuid) - external - view - override - returns (ASRecord memory) - { - return _registry[uuid]; - } - - /** - * @inheritdoc IASRegistry - */ - function getASCount() external view override returns (uint256) { - return _asCount; - } - - /** - * @dev Calculates a UUID for a given AS. - * - * @param asRecord The input AS. - * - * @return AS UUID. - */ - function _getUUID(ASRecord memory asRecord) private pure returns (bytes32) { - return keccak256(abi.encodePacked(asRecord.schema, asRecord.resolver)); - } -} diff --git a/packages/contracts/contracts/EAS/TellerASResolver.sol b/packages/contracts/contracts/EAS/TellerASResolver.sol deleted file mode 100644 index 28b55fb25..000000000 --- a/packages/contracts/contracts/EAS/TellerASResolver.sol +++ /dev/null @@ -1,21 +0,0 @@ -pragma solidity >=0.8.0 <0.9.0; -// SPDX-License-Identifier: MIT - -import "../interfaces/IASResolver.sol"; - -/** - * @title A base resolver contract - */ -abstract contract TellerASResolver is IASResolver { - error NotPayable(); - - function isPayable() public pure virtual override returns (bool) { - return false; - } - - receive() external payable virtual { - if (!isPayable()) { - revert NotPayable(); - } - } -} diff --git a/packages/contracts/contracts/MarketRegistry.sol b/packages/contracts/contracts/MarketRegistry.sol index 74a915ae5..121c2751d 100644 --- a/packages/contracts/contracts/MarketRegistry.sol +++ b/packages/contracts/contracts/MarketRegistry.sol @@ -61,7 +61,7 @@ contract MarketRegistry is mapping(uint256 => bool) private marketIsClosed; - TellerAS private _tellerAS; //DEPRECATED + address private _tellerAS; //DEPRECATED /* Modifiers */ diff --git a/packages/contracts/contracts/interfaces/IMarketRegistry.sol b/packages/contracts/contracts/interfaces/IMarketRegistry.sol index cd557453b..07ba9d369 100644 --- a/packages/contracts/contracts/interfaces/IMarketRegistry.sol +++ b/packages/contracts/contracts/interfaces/IMarketRegistry.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; -import "../EAS/TellerAS.sol"; +//import "../EAS/TellerAS.sol"; import { PaymentType, PaymentCycleType } from "../libraries/V2Calculations.sol"; interface IMarketRegistry { diff --git a/packages/contracts/contracts/mock/TellerASMock.sol b/packages/contracts/contracts/mock/TellerASMock.sol deleted file mode 100644 index c0fbfbf89..000000000 --- a/packages/contracts/contracts/mock/TellerASMock.sol +++ /dev/null @@ -1,27 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.0; - -import "../EAS/TellerAS.sol"; -import "../EAS/TellerASEIP712Verifier.sol"; -import "../EAS/TellerASRegistry.sol"; - -import "../interfaces/IASRegistry.sol"; -import "../interfaces/IEASEIP712Verifier.sol"; - -contract TellerASMock is TellerAS { - constructor() - TellerAS( - IASRegistry(new TellerASRegistry()), - IEASEIP712Verifier(new TellerASEIP712Verifier()) - ) - {} - - function isAttestationActive(bytes32 uuid) - public - view - override - returns (bool) - { - return true; - } -} diff --git a/packages/contracts/tests/MarketRegistry_Test.sol b/packages/contracts/tests/MarketRegistry_Test.sol index e53140164..c3cb62be8 100644 --- a/packages/contracts/tests/MarketRegistry_Test.sol +++ b/packages/contracts/tests/MarketRegistry_Test.sol @@ -12,7 +12,7 @@ import "../contracts/TellerV2Storage.sol"; import "../contracts/interfaces/IMarketRegistry.sol"; -import "../contracts/EAS/TellerAS.sol"; +//import "../contracts/EAS/TellerAS.sol"; import "../contracts/mock/WethMock.sol"; import "../contracts/interfaces/IWETH.sol"; diff --git a/packages/contracts/tests/TellerV2/TellerV2_Test.sol b/packages/contracts/tests/TellerV2/TellerV2_Test.sol index d3ccc3a8c..62971a259 100644 --- a/packages/contracts/tests/TellerV2/TellerV2_Test.sol +++ b/packages/contracts/tests/TellerV2/TellerV2_Test.sol @@ -9,7 +9,7 @@ import { MarketRegistry } from "../../contracts/MarketRegistry.sol"; import "../../contracts/interfaces/IMarketRegistry.sol"; import "../../contracts/interfaces/IReputationManager.sol"; -import "../../contracts/EAS/TellerAS.sol"; +//import "../../contracts/EAS/TellerAS.sol"; import "../../contracts/mock/WethMock.sol"; import "../../contracts/interfaces/IWETH.sol"; diff --git a/packages/contracts/tests/TellerV2Autopay_Test.sol b/packages/contracts/tests/TellerV2Autopay_Test.sol index 9b66a7dcb..b8f55f165 100644 --- a/packages/contracts/tests/TellerV2Autopay_Test.sol +++ b/packages/contracts/tests/TellerV2Autopay_Test.sol @@ -14,7 +14,7 @@ import "../contracts/TellerV2Storage.sol"; import "../contracts/interfaces/IMarketRegistry.sol"; import "../contracts/interfaces/IReputationManager.sol"; -import "../contracts/EAS/TellerAS.sol"; +//import "../contracts/EAS/TellerAS.sol"; import "../contracts/mock/WethMock.sol"; diff --git a/packages/contracts/tests/integration/IntegrationTestHelpers.sol b/packages/contracts/tests/integration/IntegrationTestHelpers.sol index 6dd46331d..8b1c66f30 100644 --- a/packages/contracts/tests/integration/IntegrationTestHelpers.sol +++ b/packages/contracts/tests/integration/IntegrationTestHelpers.sol @@ -3,9 +3,11 @@ pragma solidity >=0.8.0 <0.9.0; import { TellerV2 } from "../../contracts/TellerV2.sol"; +/* import "../../contracts/EAS/TellerAS.sol"; import "../../contracts/EAS/TellerASEIP712Verifier.sol"; import "../../contracts/EAS/TellerASRegistry.sol"; +*/ import "@openzeppelin/contracts/proxy/beacon/UpgradeableBeacon.sol"; import "@openzeppelin/contracts/proxy/beacon/BeaconProxy.sol"; @@ -23,10 +25,10 @@ import { IMarketRegistry } from "../../contracts/interfaces/IMarketRegistry.sol" library IntegrationTestHelpers { function deployMarketRegistry() public returns (address) { - IASRegistry iasRegistry = new TellerASRegistry(); - IEASEIP712Verifier ieaseip712verifier = new TellerASEIP712Verifier(); + // IASRegistry iasRegistry = new TellerASRegistry(); + // IEASEIP712Verifier ieaseip712verifier = new TellerASEIP712Verifier(); - TellerAS tellerAS = new TellerAS((iasRegistry), (ieaseip712verifier)); + // TellerAS tellerAS = new TellerAS((iasRegistry), (ieaseip712verifier)); MarketRegistry marketRegistry = new MarketRegistry(); marketRegistry.initialize( ); diff --git a/packages/contracts/tests/resolvers/TestASAttestationResolver.sol b/packages/contracts/tests/resolvers/TestASAttestationResolver.sol deleted file mode 100644 index 10dce5df8..000000000 --- a/packages/contracts/tests/resolvers/TestASAttestationResolver.sol +++ /dev/null @@ -1,52 +0,0 @@ -pragma solidity >=0.8.0 <0.9.0; -// SPDX-License-Identifier: MIT - -import "../../contracts/EAS/TellerASResolver.sol"; -import "../../contracts/EAS/TellerAS.sol"; - -/** - * @title A sample AS resolver that checks whether an attestations attest to an existing attestation. - */ -contract TestASAttestationResolver is TellerASResolver { - error Overflow(); - error OutOfBounds(); - - TellerAS private immutable _eas; - - constructor(TellerAS eas) { - _eas = eas; - } - - function resolve( - address /* recipient */, - bytes calldata /* schema */, - bytes calldata data, - uint256 /* expirationTime */, - address /* msgSender */ - ) external payable virtual override returns (bool) { - return _eas.isAttestationValid(_toBytes32(data, 0)); - } - - function _toBytes32(bytes memory data, uint256 start) - private - pure - returns (bytes32) - { - if (start + 32 < start) { - revert Overflow(); - } - - if (data.length < start + 32) { - revert OutOfBounds(); - } - - bytes32 tempBytes32; - - // solhint-disable-next-line no-inline-assembly - assembly { - tempBytes32 := mload(add(add(data, 0x20), start)) - } - - return tempBytes32; - } -} diff --git a/packages/contracts/tests/resolvers/TestASAttesterResolver.sol b/packages/contracts/tests/resolvers/TestASAttesterResolver.sol deleted file mode 100644 index 040fd5096..000000000 --- a/packages/contracts/tests/resolvers/TestASAttesterResolver.sol +++ /dev/null @@ -1,25 +0,0 @@ -pragma solidity >=0.8.0 <0.9.0; -// SPDX-License-Identifier: MIT - -import "../../contracts/EAS/TellerASResolver.sol"; - -/** - * @title A sample AS resolver that checks whether the attestation is from a specific attester. - */ -contract TestASAttesterResolver is TellerASResolver { - address private immutable _targetAttester; - - constructor(address targetAttester) { - _targetAttester = targetAttester; - } - - function resolve( - address /* recipient */, - bytes calldata /* schema */, - bytes calldata /* data */, - uint256 /* expirationTime */, - address msgSender - ) external payable virtual override returns (bool) { - return msgSender == _targetAttester; - } -} diff --git a/packages/contracts/tests/resolvers/TestASDataResolver.sol b/packages/contracts/tests/resolvers/TestASDataResolver.sol deleted file mode 100644 index 288643d3c..000000000 --- a/packages/contracts/tests/resolvers/TestASDataResolver.sol +++ /dev/null @@ -1,20 +0,0 @@ -pragma solidity >=0.8.0 <0.9.0; -// SPDX-License-Identifier: MIT - -import "../../contracts/EAS/TellerASResolver.sol"; - -/** - * @title A sample AS resolver that checks whether an attestation data is either \x00 or \x01. - */ -contract TestASDataResolver is TellerASResolver { - function resolve( - address /* recipient */, - bytes calldata /* schema */, - bytes calldata data, - uint256 /* expirationTime */, - address /* msgSender */ - ) external payable virtual override returns (bool) { - // Verifies that the data is either 0 or 1. - return data.length == 1 && (data[0] == "\x00" || data[0] == "\x01"); - } -} diff --git a/packages/contracts/tests/resolvers/TestASExpirationTimeResolver.sol b/packages/contracts/tests/resolvers/TestASExpirationTimeResolver.sol deleted file mode 100644 index 209de1b4c..000000000 --- a/packages/contracts/tests/resolvers/TestASExpirationTimeResolver.sol +++ /dev/null @@ -1,25 +0,0 @@ -pragma solidity >=0.8.0 <0.9.0; -// SPDX-License-Identifier: MIT - -import "../../contracts/EAS/TellerASResolver.sol"; - -/** - * @title A sample AS resolver that checks whether the expiration time is later than a specific timestamp. - */ -contract TestASExpirationTimeResolver is TellerASResolver { - uint256 private immutable _validAfter; - - constructor(uint256 validAfter) { - _validAfter = validAfter; - } - - function resolve( - address /* recipient */, - bytes calldata /* schema */, - bytes calldata /* data */, - uint256 expirationTime, - address /* msgSender */ - ) external payable virtual override returns (bool) { - return expirationTime >= _validAfter; - } -} diff --git a/packages/contracts/tests/resolvers/TestASPayingResolver.sol b/packages/contracts/tests/resolvers/TestASPayingResolver.sol deleted file mode 100644 index 575b5602b..000000000 --- a/packages/contracts/tests/resolvers/TestASPayingResolver.sol +++ /dev/null @@ -1,31 +0,0 @@ -pragma solidity >=0.8.0 <0.9.0; -// SPDX-License-Identifier: MIT - -import "../../contracts/EAS/TellerASResolver.sol"; - -/** - * @title A sample AS resolver that pays attesters - */ -contract TestASPayingResolver is TellerASResolver { - uint256 private immutable _incentive; - - constructor(uint256 incentive) { - _incentive = incentive; - } - - function isPayable() public pure override returns (bool) { - return true; - } - - function resolve( - address recipient, - bytes calldata /* schema */, - bytes calldata /* data */, - uint256 /* expirationTime */, - address /* msgSender */ - ) external payable virtual override returns (bool) { - payable(recipient).transfer(_incentive); - - return true; - } -} diff --git a/packages/contracts/tests/resolvers/TestASRecipientResolver.sol b/packages/contracts/tests/resolvers/TestASRecipientResolver.sol deleted file mode 100644 index 60d6f144c..000000000 --- a/packages/contracts/tests/resolvers/TestASRecipientResolver.sol +++ /dev/null @@ -1,25 +0,0 @@ -pragma solidity >=0.8.0 <0.9.0; -// SPDX-License-Identifier: MIT - -import "../../contracts/EAS/TellerASResolver.sol"; - -/** - * @title A sample AS resolver that checks whether the attestation is to a specific recipient. - */ -contract TestASRecipientResolver is TellerASResolver { - address private immutable _targetRecipient; - - constructor(address targetRecipient) { - _targetRecipient = targetRecipient; - } - - function resolve( - address recipient, - bytes calldata /* schema */, - bytes calldata /* data */, - uint256 /* expirationTime */, - address /* msgSender */ - ) external payable virtual override returns (bool) { - return recipient == _targetRecipient; - } -} diff --git a/packages/contracts/tests/resolvers/TestASTokenResolver.sol b/packages/contracts/tests/resolvers/TestASTokenResolver.sol deleted file mode 100644 index 0fc2474c2..000000000 --- a/packages/contracts/tests/resolvers/TestASTokenResolver.sol +++ /dev/null @@ -1,33 +0,0 @@ -pragma solidity >=0.8.0 <0.9.0; -// SPDX-License-Identifier: MIT - -import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; -import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; -import "../../contracts/EAS/TellerASResolver.sol"; - -/** - * @title A sample AS resolver that checks whether a specific amount of tokens was approved to be included in an attestation. - */ -contract TestASTokenResolver is TellerASResolver { - using SafeERC20 for IERC20; - - IERC20 private immutable _targetToken; - uint256 private immutable _targetAmount; - - constructor(IERC20 targetToken, uint256 targetAmount) { - _targetToken = targetToken; - _targetAmount = targetAmount; - } - - function resolve( - address /* recipient */, - bytes calldata /* schema */, - bytes calldata /* data */, - uint256 /* expirationTime */, - address msgSender - ) external payable virtual override returns (bool) { - _targetToken.safeTransferFrom(msgSender, address(this), _targetAmount); - - return true; - } -} diff --git a/packages/contracts/tests/resolvers/TestASValueResolver.sol b/packages/contracts/tests/resolvers/TestASValueResolver.sol deleted file mode 100644 index 6bd865efd..000000000 --- a/packages/contracts/tests/resolvers/TestASValueResolver.sol +++ /dev/null @@ -1,29 +0,0 @@ -pragma solidity >=0.8.0 <0.9.0; -// SPDX-License-Identifier: MIT - -import "../../contracts/EAS/TellerASResolver.sol"; - -/** - * @title A sample AS resolver that checks whether a specific amount of ETH was sent with an attestation. - */ -contract TestASValueResolver is TellerASResolver { - uint256 private immutable _targetValue; - - constructor(uint256 targetValue) { - _targetValue = targetValue; - } - - function isPayable() public pure override returns (bool) { - return true; - } - - function resolve( - address /* recipient */, - bytes calldata /* schema */, - bytes calldata /* data */, - uint256 /* expirationTime */, - address /* msgSender */ - ) external payable virtual override returns (bool) { - return msg.value == _targetValue; - } -}