initial integration of pei, no tests

This commit is contained in:
andyk 2020-09-15 16:53:20 +03:00
parent 227c0b4962
commit 43c8ef02db
10 changed files with 102 additions and 20 deletions

View File

@ -0,0 +1,11 @@
// SPDX-License-Identifier: agpl-3.0
pragma solidity 0.6.8;
pragma experimental ABIEncoderV2;
interface IAaveIncentivesController {
function handleAction(
address user,
uint256 userBalance,
uint256 totalSupply
) external;
}

View File

@ -9,8 +9,9 @@ contract MockAToken is AToken {
LendingPool _pool,
address _underlyingAssetAddress,
string memory _tokenName,
string memory _tokenSymbol
) public AToken(_pool, _underlyingAssetAddress, _tokenName, _tokenSymbol) {}
string memory _tokenSymbol,
address incentivesController
) public AToken(_pool, _underlyingAssetAddress, _tokenName, _tokenSymbol, incentivesController) {}
function getRevision() internal override pure returns (uint256) {
return 0x2;

View File

@ -9,8 +9,12 @@ contract MockStableDebtToken is StableDebtToken {
address _pool,
address _underlyingAssetAddress,
string memory _tokenName,
string memory _tokenSymbol
) public StableDebtToken(_pool, _underlyingAssetAddress, _tokenName, _tokenSymbol) {}
string memory _tokenSymbol,
address incentivesController
)
public
StableDebtToken(_pool, _underlyingAssetAddress, _tokenName, _tokenSymbol, incentivesController)
{}
function getRevision() internal override pure returns (uint256) {
return 0x2;

View File

@ -9,8 +9,18 @@ contract MockVariableDebtToken is VariableDebtToken {
address _pool,
address _underlyingAssetAddress,
string memory _tokenName,
string memory _tokenSymbol
) public VariableDebtToken(_pool, _underlyingAssetAddress, _tokenName, _tokenSymbol) {}
string memory _tokenSymbol,
address incentivesController
)
public
VariableDebtToken(
_pool,
_underlyingAssetAddress,
_tokenName,
_tokenSymbol,
incentivesController
)
{}
function getRevision() internal override pure returns (uint256) {
return 0x2;

View File

@ -45,8 +45,9 @@ contract AToken is VersionedInitializable, ERC20, IAToken {
LendingPool pool,
address underlyingAssetAddress,
string memory tokenName,
string memory tokenSymbol
) public ERC20(tokenName, tokenSymbol, 18) {
string memory tokenSymbol,
address incentivesController
) public ERC20(tokenName, tokenSymbol, 18, incentivesController) {
POOL = pool;
UNDERLYING_ASSET_ADDRESS = underlyingAssetAddress;
}
@ -161,6 +162,21 @@ contract AToken is VersionedInitializable, ERC20, IAToken {
return super.balanceOf(user);
}
/**
* @dev returns the principal balance of the user and principal total supply.
* @param user the address of the user
* @return the principal balance of the user
* @return the principal total supply
**/
function getScaledUserBalanceAndSupply(address user)
external
override
view
returns (uint256, uint256)
{
return (super.balanceOf(user), super.totalSupply());
}
/**
* @dev calculates the total supply of the specific aToken
* since the balance of every single user increases over time, the total supply

View File

@ -5,6 +5,7 @@ import {Context} from '../misc/Context.sol';
import {IERC20} from '../interfaces/IERC20.sol';
import {IERC20Detailed} from '../interfaces/IERC20Detailed.sol';
import {SafeMath} from '../libraries/math/SafeMath.sol';
import {IAaveIncentivesController} from '../interfaces/IAaveIncentivesController.sol';
/**
* @title ERC20
@ -14,6 +15,8 @@ import {SafeMath} from '../libraries/math/SafeMath.sol';
contract ERC20 is Context, IERC20, IERC20Detailed {
using SafeMath for uint256;
IAaveIncentivesController internal immutable _incentivesController;
mapping(address => uint256) private _balances;
mapping(address => mapping(address => uint256)) private _allowances;
uint256 private _totalSupply;
@ -24,11 +27,13 @@ contract ERC20 is Context, IERC20, IERC20Detailed {
constructor(
string memory name,
string memory symbol,
uint8 decimals
uint8 decimals,
address incentivesController
) public {
_name = name;
_symbol = symbol;
_decimals = decimals;
_incentivesController = IAaveIncentivesController(incentivesController);
}
/**
@ -167,8 +172,16 @@ contract ERC20 is Context, IERC20, IERC20Detailed {
_beforeTokenTransfer(sender, recipient, amount);
_balances[sender] = _balances[sender].sub(amount, 'ERC20: transfer amount exceeds balance');
uint256 oldSenderBalance = _balances[sender];
_balances[sender] = oldSenderBalance.sub(amount, 'ERC20: transfer amount exceeds balance');
uint256 oldRecipientBalance = _balances[recipient];
_balances[recipient] = _balances[recipient].add(amount);
if (address(_incentivesController) != address(0x0)) {
uint256 totalSupply = _totalSupply;
_incentivesController.handleAction(sender, totalSupply, oldSenderBalance);
_incentivesController.handleAction(recipient, totalSupply, oldRecipientBalance);
}
emit Transfer(sender, recipient, amount);
}
@ -177,8 +190,16 @@ contract ERC20 is Context, IERC20, IERC20Detailed {
_beforeTokenTransfer(address(0), account, amount);
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
uint256 oldTotalSupply = _totalSupply;
_totalSupply = oldTotalSupply.add(amount);
uint256 oldAccountBalance = _balances[account];
_balances[account] = oldAccountBalance.add(amount);
if (address(_incentivesController) != address(0x0)) {
_incentivesController.handleAction(account, oldTotalSupply, oldAccountBalance);
}
emit Transfer(address(0), account, amount);
}
@ -187,8 +208,16 @@ contract ERC20 is Context, IERC20, IERC20Detailed {
_beforeTokenTransfer(account, address(0), amount);
_balances[account] = _balances[account].sub(amount, 'ERC20: burn amount exceeds balance');
_totalSupply = _totalSupply.sub(amount);
uint256 oldTotalSupply = _totalSupply;
_totalSupply = oldTotalSupply.sub(amount);
uint256 oldAccountBalance = _balances[account];
_balances[account] = oldAccountBalance.sub(amount, 'ERC20: burn amount exceeds balance');
if (address(_incentivesController) != address(0x0)) {
_incentivesController.handleAction(account, oldTotalSupply, oldAccountBalance);
}
emit Transfer(account, address(0), amount);
}

View File

@ -26,8 +26,9 @@ contract StableDebtToken is IStableDebtToken, DebtTokenBase {
address pool,
address underlyingAsset,
string memory name,
string memory symbol
) public DebtTokenBase(pool, underlyingAsset, name, symbol) {}
string memory symbol,
address incentivesController
) public DebtTokenBase(pool, underlyingAsset, name, symbol, incentivesController) {}
/**
* @dev gets the revision of the stable debt token implementation

View File

@ -22,8 +22,9 @@ contract VariableDebtToken is DebtTokenBase, IVariableDebtToken {
address pool,
address underlyingAsset,
string memory name,
string memory symbol
) public DebtTokenBase(pool, underlyingAsset, name, symbol) {}
string memory symbol,
address incentivesController
) public DebtTokenBase(pool, underlyingAsset, name, symbol, incentivesController) {}
/**
* @dev gets the revision of the stable debt token implementation

View File

@ -38,8 +38,9 @@ abstract contract DebtTokenBase is ERC20, VersionedInitializable {
address pool,
address underlyingAssetAddress,
string memory name,
string memory symbol
) public ERC20(name, symbol, 18) {
string memory symbol,
address incentivesController
) public ERC20(name, symbol, 18, incentivesController) {
POOL = ILendingPool(pool);
UNDERLYING_ASSET = underlyingAssetAddress;
}

View File

@ -82,6 +82,14 @@ interface IAToken is IERC20 {
**/
function scaledBalanceOf(address user) external view returns (uint256);
/**
* @dev returns the principal balance of the user and principal total supply.
* @param user the address of the user
* @return the principal balance of the user
* @return the principal total supply
**/
function getScaledUserBalanceAndSupply(address user) external view returns (uint256, uint256);
/**
* @dev Used to validate transfers before actually executing them.
* @param user address of the user to check