0

我喜欢计算 MATIC 在多边形区块链中借入或借出 Aave 资产的 APR。在文档中,多边形上不存在区块链级别的以太坊链功能。因为我不知道我需要从区块链中获得什么样的值来计算它。我尝试了 subgraphQL 方法。他们在这里描述:https ://docs.aave.com/developers/guides/apy-and-apr 。

但这仅适用于 DAI、WETH 和 MATIC。对于 WBTC oder USD T/C 等其他资产,它不起作用。

const answerFromSubgraphQL = [{
        "aEmissionPerSecond": "198333333333333000",
        "decimals": 18,
        "liquidityRate": "15906236277975353622140835",
        "name": "Wrapped Matic",
        "price": {
          "priceInEth": "411073414880100"
        },
        "sEmissionPerSecond": "0",
        "stableBorrowRate": "129448086968825704426507509",
        "totalATokenSupply": "166844926949324822599352584",
        "totalCurrentVariableDebt": "59650318078851499620827801",
        "underlyingAsset": "0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270",
        "vEmissionPerSecond": "22037037037037000",
        "variableBorrowRate": "55613660878177993098555256"
      },
      {
        "aEmissionPerSecond": "37187500000000000",
        "decimals": 8,
        "liquidityRate": "208828554790132442407086",
        "name": "(PoS) Wrapped BTC",
        "price": {
          "priceInEth": "15448709270521012000"
        },
        "sEmissionPerSecond": "0",
        "stableBorrowRate": "37085137389250194911588145",
        "totalATokenSupply": "1052630140493",
        "totalCurrentVariableDebt": "48477374813",
        "underlyingAsset": "0x1bfd67037b42cf73acf2047067bd4f2c47d9bfd6",
        "vEmissionPerSecond": "4131944444444440",
        "variableBorrowRate": "5668109911400155929270517"
      }];
      
      const secondsPerYear = 525600 * 60;
      const maticLendApr = 100 * (answerFromSubgraphQL[0].aEmissionPerSecond * secondsPerYear * answerFromSubgraphQL[0].price.priceInEth * answerFromSubgraphQL[0].decimals)/(answerFromSubgraphQL[0].totalATokenSupply * answerFromSubgraphQL[0].price.priceInEth * answerFromSubgraphQL[0].decimals)
      console.log(`MATIC: value from https://app.aave.com/markets: 3,75% calculated: ${maticLendApr}`);
      
            const wbtcLendApr = 100 * (answerFromSubgraphQL[1].aEmissionPerSecond * secondsPerYear * answerFromSubgraphQL[0].price.priceInEth * answerFromSubgraphQL[1].decimals)/(answerFromSubgraphQL[1].totalATokenSupply * answerFromSubgraphQL[1].price.priceInEth * answerFromSubgraphQL[0].decimals)
      console.log(`WBTC: value from https://app.aave.com/markets: 0,02% calculated: ${wbtcLendApr}`);

4

0 回答 0