Info: current mainnet eth block number: 11210219
I'm wondering where the interest come from, so I made some investigations for dUSDx:
The contract address for dUSDx is 0x109917f7c3b6174096f9e1744e41ac073b3e1f72 etherscan, and it has two handlers:
The code for calculating exchange ratio, namely how many USDx can 1 dUSDx exchange, is getCurrentExchangeRate, which is implemented by summing up the handlers' getRealBalance(_token) and then divided by totalSupply
|
function getCurrentExchangeRateByHandler( |
|
address[] memory _handlers, |
|
address _token |
|
) internal returns (uint256) { |
|
uint256 _totalToken = 0; |
|
|
|
// Get the total underlying token amount from handlers |
|
for (uint256 i = 0; i < _handlers.length; i++) |
|
_totalToken = _totalToken.add( |
|
IHandler(_handlers[i]).getRealBalance(_token) |
|
); |
|
|
|
// Reset exchange rate to 1 when there is no dToken left |
|
uint256 _exchangeRate = (totalSupply == 0) |
|
? BASE |
|
: rdiv(_totalToken, totalSupply); |
|
|
|
require(_exchangeRate > 0, "Exchange rate should not be 0!"); |
|
|
|
return _exchangeRate; |
|
} |
By calling getBaseData for different blocks (using MetaMask API), I find that getCurrentExchangeRate update for each block:
def getbasedata(id, blockid):
data = '{"id":%d,"jsonrpc":"2.0","method":"eth_call","params":[{"data":"0x148a95ea","to":"0x109917f7c3b6174096f9e1744e41ac073b3e1f72"},"%s"]}'%(id, blockid)
response = sess.post('https://mainnet.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161', headers=headers, data=data)
res = response.json()
#print(res)
data = base64.b16decode(res["result"][2:].upper())
i = 1
rate = int.from_bytes(data[i*32:i*32+32],"big")
return rate
>>> getbasedata(1,hex(11210217))
1008824037259265003
>>> getbasedata(1,hex(11210218))
1008824072639567928
>>> getbasedata(1,hex(11210219))
1008824108020446490
The InternalHandler's getRealBalance can be easily called via etherscan dapp getRealBalance 0xeb269732ab75a6fd61ea60b06fe994cd32a83549

And this output seems stable 83373969497199741501815, not change for hours. So this is not the source of interest.
However, I cannot find way to call USRHandler's getRealBalance, and the implementation code is not available on Etherscan.
So, my question is:
- What is USR Token?
- Where can I find the implementation of USR Token, i.e. the code for contract 0xd4eef282f58ecaf12118e96ed4c06f60f88009c6
- Where does the interest come from, and why this is updating for every block? I guess the calculation involves block number?
Thanks for your answering~
I'm wondering where the interest come from, so I made some investigations for dUSDx:
The contract address for dUSDx is
0x109917f7c3b6174096f9e1744e41ac073b3e1f72etherscan, and it has two handlers:0x885dd179c76ee5949b9053f1958ba3a91e4cf592, proxy for 0x3c573234e1a9e47e0cac56db543e1ca153eb7f8b0x8916a9b0064feab04b3bf3729adbb0be119ed12d, proxy for 0xbde39e19dc806620d5377cd14827d42bbe42c8f9, whose underlying USR address is0xef004c5cdfaab19299b3ed66f14ec010fe5f20d0, proxy for 0xd4eef282f58ecaf12118e96ed4c06f60f88009c6, which NEED decompileThe code for calculating exchange ratio, namely how many USDx can 1 dUSDx exchange, is
getCurrentExchangeRate, which is implemented by summing up the handlers'getRealBalance(_token)and then divided bytotalSupplydToken/contracts/DToken.sol
Lines 357 to 377 in 563d7d0
By calling
getBaseDatafor different blocks (using MetaMask API), I find that getCurrentExchangeRate update for each block:The InternalHandler's getRealBalance can be easily called via etherscan dapp getRealBalance

0xeb269732ab75a6fd61ea60b06fe994cd32a83549And this output seems stable
83373969497199741501815, not change for hours. So this is not the source of interest.However, I cannot find way to call USRHandler's getRealBalance, and the implementation code is not available on Etherscan.
So, my question is:
Thanks for your answering~