Links

How to Interact with Market Contracts?

How to use with Etherscan?

The Market Protocol was initially deployed on Polygon, Fantom and Avalanche. This example will focus primarily on the contracts deployed on Polygon and it can be easily replicated on other chains.
So before we begin, let’s discuss the steps involved:
  • Finding your Pool contract with a Pool ID
  • Finding your account collateral and debt balance
  • Finding the Pool Token, in which your collateral/debt exists
    1. 1.
      Repaying your Debt
    2. 2.
      Withdrawing back Collateral

Finding the Pool with Pool ID

Adding the MarketPoolDirectory ABI

  1. 1.
    Sign-up on Polygonscan and then head over to: https://polygonscan.com/mycustomabi
  1. 2.
    Click on the Add button and it should open up the following dialog box
  1. 3.
    Enter the following values in the dialog box:
    • Name: MarketPoolDirectory
    • Address: 0xA2a1cb88D86A939A37770FE5E9530E8700DEe56b (Can be found here)
      1. 1.
        Polygon: 0xA2a1cb88D86A939A37770FE5E9530E8700DEe56b
      2. 2.
        Fantom: 0x0E7d754A8d1a82220432148C10715497a0569BD7
      3. 3.
        Avalanche: 0x1c4D63bDA492d69f2D6b02Fb622fb6c49cc401d2
    • Custom ABI:
[
{
"inputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"name": "pools",
"outputs": [
{
"internalType": "string",
"name": "name",
"type": "string"
},
{
"internalType": "address",
"name": "creator",
"type": "address"
},
{
"internalType": "address",
"name": "comptroller",
"type": "address"
},
{
"internalType": "uint256",
"name": "blockPosted",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "timestampPosted",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function",
"constant": true
}
]
It should look like this:

Interacting with the Contract

  1. 1.
    Go to PolygonScan
  2. 2.
    Search for the following address: 0xA2a1cb88D86A939A37770FE5E9530E8700DEe56b (Can be found here)
    1. 1.
      Polygon: 0xA2a1cb88D86A939A37770FE5E9530E8700DEe56b
    2. 2.
      Fantom: 0x0E7d754A8d1a82220432148C10715497a0569BD7
    3. 3.
      Avalanche: 0x1c4D63bDA492d69f2D6b02Fb622fb6c49cc401d2
  3. 3.
    You should see Read Custom and Write Custom tabs in the Contract section
  4. 4.
    Click on the Read Custom tab and choose the pools option
  5. 5.
    Enter the Pool ID in input box and press Query
  6. 6.
    You should get the following result:

Finding your account collateral and debt balance

Opening the Comptroller Contract

  1. 1.
    Go to PolygonScan
  2. 2.
    Search for the Comptroller Address mentioned in the previous step
  3. 3.
    You should see Read as Proxy and Write as Proxy tabs in the Contract section
    • If you don't see Read as Proxy, you will see the following:
    • Go to More Options and choose Is this a Proxy? and follow the steps
  4. 4.
    Click on the Read as Proxy tab
  5. 5.
    Scroll down until you find, getAccountLiquidity and click on it
    • Enter your account address there and it will have the following result:
    • A non-zero liquidity value indicates the account has available account liquidity. A non-zero shortfall value indicates the account is currently below his/her collateral requirement and is subject to liquidation. At most one of liquidity or shortfall shall be non-zero.
  6. 6.
    Scroll down a bit further until you find, getAssetsIn and click on it
    • Enter your account address there and it will have the following results:
Each of these addresses above are the CToken Contract addresses representing the assets you have interacted with in this specific pool.

Checking Individual Balances and Debts using CTokens

  1. 1.
    Go to PolygonScan
  2. 2.
    Search for the CToken Addresses (token addresses from getAssetsIn) mentioned in the above step
  3. 3.
    You should see Read as Proxy and Write as Proxy tabs in the Contract section
  4. 4.
    Click on the Read as Proxy tab
  5. 5.
    Scroll down until you find, borrowBalanceStored and click on it
    • Enter the following address and it will have the following result:
    • A non-zero amount represents your debt in the underlying token.
  6. 6.
    Again scroll down at the same CToken Addresses to find balanceOf
    • Enter your address and it will have the following result
    • A non-zero amount represents your Collateral balance in the underlying token.
  7. 7.
    Check this for each Token you have interacted to make a list of your debt and collateral positions along with their exchange rates. To find the exchange rate,
    • Go to Read as Proxy, and use exchangeRateStored function
  8. 8.
    Instead of this above, you may also use getAccountSnapshot
  1. 9.
    To get how many tokens you have in the pool,
  • For Collateral Balance, multiple the CToken Balance by the Exchange Rate and then divide it by 1ex where x is (18+number of decimals in the underlying token).
  • For Borrow Balance, divide the CToken Borrow Balance by 1ex where x is the number of decimals in the underlying token.

Repaying your Debt & Withdrawing back Collateral

If you have no borrow balance in any of the assets, you can directly withdraw(step 6 below). However if you have debt balance in any of the assets, you should first repay your debt to withdraw your collateral.
  1. 1.
    To Repay, open the CToken Contract Address in the block explorer of the token in which you had a non-zero borrow balance.
  2. 2.
    Before proceeding, you should ensure that your wallet has the required token and amount in your wallet . For help in the calculating the amount required to repay, please refer step 9 above.
    • To find out which token you need in your wallet, you can go to Read as Proxy in the CToken Contract and use underlying function.
  3. 3.
    Go to Write as Proxy, and
    • Connect your wallet by clicking on Connect to Web3
  4. 4.
    To repay, you need to approve the contract to use the tokens
    • Go the underlying token’s contract address on block explorer
    • Scroll and find approve
    • in spender field, enter the contract address of the CToken you are currently viewing
    • In amount field, enter the Borrow Balance from getAccountSnapshot or borrowBalanceStored
    • Click on Write and approve the transaction on your wallet
  5. 5.
    After connecting your wallet, find repayBorrow
    • Enter the Borrow Balance from getAccountSnapshot or borrowBalanceStored.
    • Click on Write and approve transaction on your wallet.
  6. 6.
    Repeat these steps above for every token you had a non-zero balance in.
  7. 7.
    To withdraw, go to the CToken Contract in the block explorer of the token you had a non-zero Collateral balance.
  8. 8.
    Go to Write as Proxy, and
    • Connect your wallet by clicking on Connect to Web3
  9. 9.
    After connecting your wallet, find redeem function
    • Enter the Collateral Balance you got from getAccountSnapshot or balanceOf
    • Click on Write and approve the transaction on your wallet.
  10. 10.
    Repeat steps 6-8 for every asset you had a non-zero Collateral balance.
  11. 11.
    Now you have paid back and withdrawn all the assets in the pool.