Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Early Access #1

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions contracts/interfaces/IAAVEPool.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// SPDX-License-Identifier: agpl-3.0
pragma solidity ^0.8.0;

interface IAAVEPool {
struct ReserveData {
//stores the reserve configuration
ReserveConfigurationMap configuration;
//the liquidity index. Expressed in ray
uint128 liquidityIndex;
//the current supply rate. Expressed in ray
uint128 currentLiquidityRate;
//variable borrow index. Expressed in ray
uint128 variableBorrowIndex;
//the current variable borrow rate. Expressed in ray
uint128 currentVariableBorrowRate;
//the current stable borrow rate. Expressed in ray
uint128 currentStableBorrowRate;
//timestamp of last update
uint40 lastUpdateTimestamp;
//the id of the reserve. Represents the position in the list of the active reserves
uint16 id;
//aToken address
address aTokenAddress;
//stableDebtToken address
address stableDebtTokenAddress;
//variableDebtToken address
address variableDebtTokenAddress;
//address of the interest rate strategy
address interestRateStrategyAddress;
//the current treasury balance, scaled
uint128 accruedToTreasury;
//the outstanding unbacked aTokens minted through the bridging feature
uint128 unbacked;
//the outstanding debt borrowed against this asset in isolation mode
uint128 isolationModeTotalDebt;
}

struct ReserveConfigurationMap {
//bit 0-15: LTV
//bit 16-31: Liq. threshold
//bit 32-47: Liq. bonus
//bit 48-55: Decimals
//bit 56: reserve is active
//bit 57: reserve is frozen
//bit 58: borrowing is enabled
//bit 59: stable rate borrowing enabled
//bit 60: asset is paused
//bit 61: borrowing in isolation mode is enabled
//bit 62-63: reserved
//bit 64-79: reserve factor
//bit 80-115 borrow cap in whole tokens, borrowCap == 0 => no cap
//bit 116-151 supply cap in whole tokens, supplyCap == 0 => no cap
//bit 152-167 liquidation protocol fee
//bit 168-175 eMode category
//bit 176-211 unbacked mint cap in whole tokens, unbackedMintCap == 0 => minting disabled
//bit 212-251 debt ceiling for isolation mode with (ReserveConfiguration::DEBT_CEILING_DECIMALS) decimals
//bit 252-255 unused

uint256 data;
}

function getReserveData(
address asset
) external view returns (ReserveData memory);

function supply(
address asset,
uint256 amount,
address onBehalfOf,
uint16 referralCode
) external;

function withdraw(
address asset,
uint256 amount,
address to
) external returns (uint256);
}
10 changes: 4 additions & 6 deletions contracts/interfaces/IStrategy.sol
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
pragma solidity 0.8.19;
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity 0.8.20;

interface IStrategy {
function withdraw(uint256 amount_) external returns (uint256 loss_);

function withdrawAll() external;

function estimatedTotalAssets()
external
view
returns (uint256 totalAssets_);
function totalYieldAsset() external view returns (uint256 totalAssets_);

function invest() external;
function invest(uint256 amount_) external;
}
52 changes: 49 additions & 3 deletions contracts/superbridge/AaveStrategy.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,51 @@
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity 0.8.19;
pragma solidity 0.8.20;

// contract AaveStrategy {
// }
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/interfaces/IERC4626.sol";
import "../interfaces/IStrategy.sol";
import "../interfaces/IAAVEPool.sol";

contract AaveStrategy is Initializable {
using SafeERC20 for IERC20;

address public aavePool;
address public token;
address public vault;

error NotAllow();

modifier onlyVault() {
if (msg.sender != vault) revert NotAllow();
_;
}

function initialize(address _aavePool, address _vault) public initializer {
aavePool = _aavePool;
token = IERC4626(_vault).asset();
vault = _vault;
IERC20(token).safeIncreaseAllowance(aavePool, type(uint256).max);
}

function withdraw(uint256 amount_) external onlyVault returns (uint256 loss_) {
return IAAVEPool(aavePool).withdraw(token, amount_, vault);
}

function withdrawAll() onlyVault external {
uint256 totalAsset = totalYieldAsset();
IAAVEPool(aavePool).withdraw(token, totalAsset, vault);
}

function totalYieldAsset() public view returns (uint256 totalAssets_) {
address aToken = IAAVEPool(aavePool)
.getReserveData(token)
.aTokenAddress;
return IERC20(aToken).balanceOf(address(this));
}

function invest(uint256 amount_) external onlyVault {
IAAVEPool(aavePool).supply(token, amount_, address(this), 0);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pragma solidity 0.8.19;
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity 0.8.20;

import "solmate/tokens/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

// USDC's standard token
abstract contract IFiatTokenV2_1_Mintable is ERC20 {
Expand Down
3 changes: 2 additions & 1 deletion contracts/superbridge/Gauge.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pragma solidity 0.8.19;
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity 0.8.20;

abstract contract Gauge {
struct LimitParams {
Expand Down
5 changes: 3 additions & 2 deletions contracts/superbridge/IMintableERC20.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pragma solidity 0.8.19;
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity 0.8.20;

import "solmate/tokens/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

abstract contract IMintableERC20 is ERC20 {
function mint(address receiver_, uint256 amount_) external virtual;
Expand Down
30 changes: 30 additions & 0 deletions contracts/superbridge/ParallelProxy.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity 0.8.20;

import "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
import "@openzeppelin/contracts/proxy/ERC1967/ERC1967Utils.sol";

contract ParallelProxy is
TransparentUpgradeableProxy,
ITransparentUpgradeableProxy
{
constructor(
address implementation,
address admin_,
bytes memory _data
) TransparentUpgradeableProxy(implementation, admin_, _data) {}

error OnlyProxyAdmin();

function upgradeToAndCall(
address newImplementation,
bytes calldata data
) external payable {
if (msg.sender != _proxyAdmin()) {
revert OnlyProxyAdmin();
}
ERC1967Utils.upgradeToAndCall(newImplementation, data);
}

receive() external payable {}
}
Loading