Aavegotchi Docs
Official WebsiteDapp
  • Welcome to Aavegotchi
    • Introduction
  • Own. Trade. Earn.
    • What is True Ownership?
    • Tokens
      • GHST Token
      • Gotchus Alchemica
      • GLTR Token
    • Game Items
      • Aavegotchis
      • Portals
      • Wearables
      • The Forge
      • Gotchiverse
    • Trading
      • Aavegotchi Baazaar
      • Auction House
    • Earning in Aavegotchi
      • Rarity Farming
      • Staking
      • Playing Games
  • Gaming
    • Aavegotchi Gaming Console
    • Live Games
    • Assets
      • Badges
      • Experience Points
      • Skins
      • [REDACTED]
  • Geist
    • Overview
    • FAQ
  • Governance
    • About AavegotchiDAO
    • Creating a Proposal
    • Voting on Proposals
  • developers
    • Aavegotchi Contracts
      • Reading from Aavegotchi Contracts
        • Fetching Onchain SVGs
      • Writing to Aavegotchi Contracts
      • Extending Aavegotchi Contracts
        • Upgrading
        • Security
        • Deployment
        • Governance
      • About EIP-2535 Diamonds
        • Facets
      • maTokens
      • Concepts
      • Deployed Contracts
        • Aavegotchi Diamond
        • Forge Diamond
        • Wearable Diamond
        • Gotchiverse Realm Diamond
        • Installation Diamond
        • Tile Diamond
    • Subgraphs
      • General
      • Core Matic Subgraph
      • SVG Subgraphs
      • Gotchiverse Subgraph
      • FAKE Gotchi Subgraph
Powered by GitBook
On this page
  • Conversion between aTokens and maTokens
  • Getting aToken and maToken contract addresses

Was this helpful?

  1. developers
  2. Aavegotchi Contracts

maTokens

Aave's aTokens on Matic Network

PreviousFacetsNextConcepts

Last updated 1 year ago

Was this helpful?

Information generally about how maTokens work is given in the article here: .

Conversion between aTokens and maTokens

The aToken bridging contract leverages the 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);
 }

Getting aToken and maToken contract addresses

Use the functions below to get aTokens and maToken addresses.

 /**
  * @dev Gets the maTokens contract address on Matic that is associate with
  * the aTokens contract on Ethereum.
  * @param _rootToken The aToken contract address on Ethereum
  * @return The maToken contract address on Matic.
  **/
function rootToChildToken(address _rootToken) external view returns (address)

 /**
  * @dev Gets the aTokens contract address on Ethereum that is associate with
  * the maTokens contract on Matic.
  * @param _childToken The maToken contract address on Matic
  * @return The aToken contract address on Ethereum.
  **/
function childToRootToken(address _childToken) external view returns (address)

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

The source code for the aToken bridge contract is here:

Don't use the ABI on Etherscan to call these functions. Instead use the ABI at this link:

The aToken addresses can be found on Etherscan or in .

Aave's Interest-Bearing aTokens on Matic Network
Aave protocol
https://github.com/aavegotchi/pos-portal/blob/master/contracts/root/RootChainManager/ATokenRootChainManager.sol
https://gist.github.com/mudgen/5da65e965e05ba08354f003aa86e6587
Aave documentation