OriginProtocol / origin-dollar

OUSD and OETH are stablecoins that passively accrue yield while you are holding it
https://originprotocol.com
MIT License
116 stars 80 forks source link

Empty balance #1073

Closed micahalcorn closed 2 years ago

micahalcorn commented 2 years ago

A user reported that the balance is not showing properly while the pending yield and lifetime earnings are.

case

I was able to reproduce the issue and saw some errors in the console.

Screen Shot 2022-08-26 at 4 44 40 PM
0xcodercrane commented 2 years ago

Where does this error happen?

Above error happens at balances.service.js because the provider returns error.

      if (balanceResponseData.error === null) {
        balanceData[contractData.name] =
          balanceResponseData.tokenBalance === '0x'
            ? '0'
            : ethers.utils.formatUnits(
                balanceResponseData.tokenBalance,
                contractData.decimals
              )
      } else {
        console.error(
          `Can not load balance for ${contractData.name} reason: ${balanceResponseData.error}`
        )
      }

Why does this error happen?

    const data = {
      jsonrpc: '2.0',
      method: '_**alchemy_getTokenBalances**_',
      params: [
        account,
        allContractData.map((contractData) => contractData.address),
      ],
      id: jsonCallId.toString(),
    }
    jsonCallId++

    const response = await fetch(**_process.env.ETHEREUM_RPC_PROVIDER_**, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
      },
      referrerPolicy: 'no-referrer',
      body: JSON.stringify(data),
    })

    if (!response.ok) {
      throw new Error(
        `Could not fetch balances from Alchemy http status: ${response.status}`
      )
    }

How to improve balance service?

This service seems to be just limited to alchemy provider, but there are other kinds of rpc providers like infura. moralis, quicknode, etc. So I think that would be more powerful to allow any kinds of rpc providers to get balances. Another suggestion is to use multicall which uses 1 number of rpc calls to get a bunch of token balances.

I will appreciate it if my debug/suggestion might help a little bit to fix this issue.

tomhirst commented 2 years ago

Thanks for your research @0xcodercrane, that was helpful.

I managed to replicate this issue locally and fix it with https://github.com/OriginProtocol/origin-dollar/pull/1075

0xcodercrane commented 2 years ago

I am glad if it was helpful