Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect emission amounts in ScaledBalanceTokenBase.sol _mintScaled() #686

Closed
scottincrypto opened this issue Jul 2, 2022 · 2 comments
Closed

Comments

@scottincrypto
Copy link

scottincrypto commented Jul 2, 2022

I suspect that the amounts contained in the Transfer and Mint events emitted in the _mintScaled() function in ScaledBalanceTokenBase.sol are incorrect. This doesn't appear to be fixed in PR 682 (similar issue).

The issue appears in the MintToTreasury() transaction on avax mainnet at block 15154957. Details using eth-brownie on just the aAvaWAVAX portion of this transaction:

network.connect('avax-main')
pool = Contract.from_explorer('0x794a61358d6845594f94dc1db02a252b5b4814ad')
awavax = Contract.from_explorer('0x6d80113e533a2C0fe82EaBD35f1875DcEA89Ea97')
wavax = Contract.from_explorer('0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7')
treasury = Contract.from_explorer('0x5ba7fd868c40c16f7aDfAe6CF87121E13FC2F7a0')

mint_tx = network.chain.get_transaction('0xde2b36439ea0b64acaad3bfbcd05cd256a0021977fdb137e0e20c39be5e5f17a')
print(f'Transfer event: {mint_tx.events[27][0]}')
print(f'Mint event: {mint_tx.events[28][0]}')
print(f'MintedToTreasury event: {mint_tx.events[29][0]}')

Output:

Transfer event: OrderedDict([('from', '0x0000000000000000000000000000000000000000'), ('to', '0x5ba7fd868c40c16f7aDfAe6CF87121E13FC2F7a0'), ('value', 4193524073182740554855)])
Mint event: OrderedDict([('caller', '0x794a61358D6845594F94dc1DB02A252b5b4814aD'), ('onBehalfOf', '0x5ba7fd868c40c16f7aDfAe6CF87121E13FC2F7a0'), ('value', 4193524073182740554855), ('balanceIncrease', 767685077247459322517), ('index', 1003583121665315728830145171)])
MintedToTreasury event: OrderedDict([('reserve', '0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7'), ('amountMinted', 3425838995935281232338)])
balance_before = awavax.balanceOf('0x5ba7fd868c40c16f7aDfAe6CF87121E13FC2F7a0', block_identifier = 15154956)
balance_after = awavax.balanceOf('0x5ba7fd868c40c16f7aDfAe6CF87121E13FC2F7a0', block_identifier = 15154957)
print(f'Treasury aAvaWAVAX balanceOf() at block 15154956 is {balance_before}')
print(f'Treasury aAvaWAVAX balanceOf() at block 15154957 is {balance_after}')
print(f'delta is {balance_after - balance_before}')

Output:

Treasury aAvaWAVAX balanceOf() at block 15154956 is 767685076087066672333
Treasury aAvaWAVAX balanceOf() at block 15154957 is 4193524073182740554855
delta is 3425838997095673882522

Note that the Mint and Transfer events value is the same as the final balanceOf(), instead of the amount the balance was incremented by. The MintedToTreasury event appears to contain the correct value.

I suspect the issue lies with line 86 in ScaledBalanceTokenBase.sol

Appreciate any further understanding if I haven't interpreted this correctly.

@miguelmtzinf
Copy link
Contributor

Hey @scottincrypto, It's nice to see people digging into the event details!
The code is correct and working as expected. Let me explain:

  • MintedToTreasury event emits the amount of new aTokens minted on behalf of the treasury.
  • Transfer and Mint events emit the amount of aTokens the receiver gets (minted + accrued interests).

So,

  • MintedToTreasury is emitting 3425838995935281232338 because is the amount new aTokens minted to the treasury.
  • Transfer is emitting 4193524073182740554855 because is the total amount of aTokens that the treasury is getting.
  • Mint is emitting 4193524073182740554855 as value (total amount the treasury is getting) and 767685077247459322517 as balanceIncrease (accrual amount of interests).
value - balanceIncrease = mintedAmount == valueOfMintedTreasury
4193524073182740554855 - 767685077247459322517 = 3425838995935281232338 == 3425838995935281232338

Hope it's clear.

@scottincrypto
Copy link
Author

Thanks, that's clear now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants