Skip to content
This repository has been archived by the owner on Aug 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #40 from ionicprotocol/feat/register-sfs-contracts
Browse files Browse the repository at this point in the history
Register SFS contracts
  • Loading branch information
rhlsthrm authored Feb 1, 2024
2 parents 19e6940 + e5a1fc6 commit d8155c4
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 16 deletions.
11 changes: 10 additions & 1 deletion contracts/compound/CTokenFirstExtension.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ pragma solidity >=0.8.0;
import { DiamondExtension } from "../ionic/DiamondExtension.sol";
import { IFlashLoanReceiver } from "../ionic/IFlashLoanReceiver.sol";
import { CErc20FirstExtensionBase, CTokenFirstExtensionInterface, ICErc20 } from "./CTokenInterfaces.sol";
import { SFSRegister } from "./ComptrollerInterface.sol";
import { TokenErrorReporter } from "./ErrorReporter.sol";
import { Exponential } from "./Exponential.sol";
import { InterestRateModel } from "./InterestRateModel.sol";
import { IFeeDistributor } from "./IFeeDistributor.sol";
import { Multicall } from "../utils/Multicall.sol";

import { IERC20, SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

contract CTokenFirstExtension is
Expand All @@ -27,7 +29,7 @@ contract CTokenFirstExtension is
}

function _getExtensionFunctions() external pure virtual override returns (bytes4[] memory) {
uint8 fnsCount = 23;
uint8 fnsCount = 24;
bytes4[] memory functionSelectors = new bytes4[](fnsCount);
functionSelectors[--fnsCount] = this.transfer.selector;
functionSelectors[--fnsCount] = this.transferFrom.selector;
Expand All @@ -52,6 +54,7 @@ contract CTokenFirstExtension is
functionSelectors[--fnsCount] = this.flash.selector;
functionSelectors[--fnsCount] = this.getAccountSnapshot.selector;
functionSelectors[--fnsCount] = this.borrowBalanceCurrent.selector;
functionSelectors[--fnsCount] = this.registerInSFS.selector;

require(fnsCount == 0, "use the correct array length");
return functionSelectors;
Expand Down Expand Up @@ -703,4 +706,10 @@ contract CTokenFirstExtension is
{
return Multicall.multicall(data);
}

function registerInSFS() external returns (uint256) {
require(hasAdminRights(), "!admin");
SFSRegister sfsContract = SFSRegister(0x8680CEaBcb9b56913c519c069Add6Bc3494B7020);
return sfsContract.register(0x8Fba84867Ba458E7c6E2c024D2DE3d0b5C3ea1C2);
}
}
2 changes: 2 additions & 0 deletions contracts/compound/CTokenInterfaces.sol
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,8 @@ interface CTokenFirstExtensionInterface {
function supplyRatePerBlockAfterWithdraw(uint256 withdrawAmount) external view returns (uint256);

function borrowRatePerBlockAfterBorrow(uint256 borrowAmount) external view returns (uint256);

function registerInSFS() external returns (uint256);
}

interface CTokenSecondExtensionInterface {
Expand Down
11 changes: 9 additions & 2 deletions contracts/compound/ComptrollerFirstExtension.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity >=0.8.0;
import { DiamondExtension } from "../ionic/DiamondExtension.sol";
import { ComptrollerErrorReporter } from "../compound/ErrorReporter.sol";
import { ICErc20 } from "./CTokenInterfaces.sol";
import { ComptrollerExtensionInterface, ComptrollerBase } from "./ComptrollerInterface.sol";
import { ComptrollerExtensionInterface, ComptrollerBase, SFSRegister } from "./ComptrollerInterface.sol";

import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";

Expand Down Expand Up @@ -38,7 +38,7 @@ contract ComptrollerFirstExtension is
event MarketUnlisted(ICErc20 cToken);

function _getExtensionFunctions() external pure virtual override returns (bytes4[] memory) {
uint8 fnsCount = 30;
uint8 fnsCount = 31;
bytes4[] memory functionSelectors = new bytes4[](fnsCount);
functionSelectors[--fnsCount] = this.addNonAccruingFlywheel.selector;
functionSelectors[--fnsCount] = this._setMarketSupplyCaps.selector;
Expand Down Expand Up @@ -70,6 +70,7 @@ contract ComptrollerFirstExtension is
functionSelectors[--fnsCount] = this.getWhitelistedSuppliersSupply.selector;
functionSelectors[--fnsCount] = this.getWhitelistedBorrowersBorrows.selector;
functionSelectors[--fnsCount] = this.getAssetAsCollateralValueCap.selector;
functionSelectors[--fnsCount] = this.registerInSFS.selector;
require(fnsCount == 0, "use the correct array length");
return functionSelectors;
}
Expand Down Expand Up @@ -503,4 +504,10 @@ contract ComptrollerFirstExtension is

return false;
}

function registerInSFS() external returns (uint256) {
require(hasAdminRights(), "!admin");
SFSRegister sfsContract = SFSRegister(0x8680CEaBcb9b56913c519c069Add6Bc3494B7020);
return sfsContract.register(0x8Fba84867Ba458E7c6E2c024D2DE3d0b5C3ea1C2);
}
}
6 changes: 6 additions & 0 deletions contracts/compound/ComptrollerInterface.sol
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ interface ComptrollerStorageInterface {
function rewardsDistributors(uint256) external view returns (address);
}

interface SFSRegister {
function register(address _recipient) external returns (uint256 tokenId);
}

interface ComptrollerExtensionInterface {
function getWhitelistedSuppliersSupply(address cToken) external view returns (uint256 supplied);

Expand Down Expand Up @@ -298,6 +302,8 @@ interface ComptrollerExtensionInterface {
bool redeeming,
address account
) external view returns (uint256);

function registerInSFS() external returns (uint256);
}

interface UnitrollerInterface {
Expand Down
7 changes: 2 additions & 5 deletions contracts/test/DevTesting.t.sol
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.0;

import { ERC20 } from "solmate/tokens/ERC20.sol";

import "./config/BaseTest.t.sol";
import { IonicComptroller } from "../compound/ComptrollerInterface.sol";
import { ICErc20 } from "../compound/CTokenInterfaces.sol";
import { ERC20 } from "solmate/tokens/ERC20.sol";

import "../external/uniswap/quoter/interfaces/IUniswapV3Quoter.sol";
import { ISwapRouter } from "../external/uniswap/ISwapRouter.sol";
import "../external/uniswap/IUniswapV3FlashCallback.sol";

import { MasterPriceOracle } from "../oracles/MasterPriceOracle.sol";

contract DevTesting is BaseTest {
Expand Down
9 changes: 1 addition & 8 deletions contracts/test/liquidators/UniswapV3LiquidatorTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ contract UniswapV3LiquidatorTest is UpgradesBaseTest {
authRegistry = AuthoritiesRegistry(ap.getAddress("AuthoritiesRegistry"));
liquidatorsRegistry = ILiquidatorsRegistry(ap.getAddress("LiquidatorsRegistry"));

// liquidator = IonicUniV3Liquidator(ap.getAddress("IonicUniV3Liquidator"));
liquidator = new IonicUniV3Liquidator();
liquidator.initialize(ap.getAddress("wtoken"), address(quoter));
}
Expand Down Expand Up @@ -100,14 +101,6 @@ contract UniswapV3LiquidatorTest is UpgradesBaseTest {
_upgradePoolWithExtension(Unitroller(payable(poolAddress)));
upgradeRegistry();

{
PoolRolesAuthority auth = authRegistry.poolsAuthorities(poolAddress);
vm.startPrank(auth.owner());
auth.openPoolSupplierCapabilities(pool);
auth.openPoolBorrowerCapabilities(pool);
vm.stopPrank();
}

ICErc20[] memory markets = pool.getAllMarkets();

ICErc20 usdcMarket = markets[usdcMarketIndex];
Expand Down

0 comments on commit d8155c4

Please sign in to comment.