maTokens

Aave's aTokens on Matic Network

Information generally about how maTokens work is given in the article here: Aave's Interest-Bearing aTokens on Matic Networkarrow-up-right.

Conversion between aTokens and maTokens

The aToken bridging contract leverages the Aave protocolarrow-up-right to convert aToken values to maToken values and back. Exactly how this is done is given in the two functions below.

To convert an aToken value to a maToken value or vise versa call the following functions on Ethereum on the aToken bridge contract which is at this address: 0x0D29aDA4c818A9f089107201eaCc6300e56E0d5c

 /**
  * @dev Converts aToken value to maToken value
  * @param _aTokenAddress aToken contract address
  * @param _aTokenValue aToken value to convert
  * @return maTokenValue_ The converted maToken value
  **/
 function getMATokenValue(address _aTokenAddress, uint256 _aTokenValue) 
   public 
   view 
   returns 
   (uint256 maTokenValue_) 
 {
   ILendingPool pool = IAToken(_aTokenAddress).POOL();
   uint256 liquidityIndex = pool.getReserveNormalizedIncome(
     IAToken(_aTokenAddress).UNDERLYING_ASSET_ADDRESS()
   );
   maTokenValue_ = p27Div(_aTokenValue, liquidityIndex);
 }
 
 /**
  * @dev Converts maToken value to aToken value
  * @param _aTokenAddress aToken contract address
  * @param _maTokenValue maToken value to convert
  * @return aTokenValue_ The converted aToken value
  **/
 function getATokenValue(address _aTokenAddress, uint256 _maTokenValue) 
   public 
   view 
   returns (uint256 aTokenValue_) 
 {
  ILendingPool pool = IAToken(_aTokenAddress).POOL();
  uint256 liquidityIndex = pool.getReserveNormalizedIncome(
    IAToken(_aTokenAddress).UNDERLYING_ASSET_ADDRESS()
  );
  aTokenValue_ = p27Mul(_maTokenValue, liquidityIndex);
 }

The source code for the aToken bridge contract is here: https://github.com/aavegotchi/pos-portal/blob/master/contracts/root/RootChainManager/ATokenRootChainManager.solarrow-up-right

Don't use the ABI on Etherscan to call these functions. Instead use the ABI at this link: https://gist.github.com/mudgen/5da65e965e05ba08354f003aa86e6587arrow-up-right

Getting aToken and maToken contract addresses

Use the functions below to get aTokens and maToken addresses.

The aToken addresses can be found on Etherscan or in Aave documentationarrow-up-right.

The aToken bridge to Matic only works with version 2 aToken contracts.

Last updated

Was this helpful?