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

Add a mapping to tracked locked ZRC20s into Cosmos coins #2991

Open
lumtis opened this issue Oct 11, 2024 · 3 comments
Open

Add a mapping to tracked locked ZRC20s into Cosmos coins #2991

lumtis opened this issue Oct 11, 2024 · 3 comments

Comments

@lumtis
Copy link
Member

lumtis commented Oct 11, 2024

Context: #2979 (review)

Add a mapping ZRC20Address -> locked tokens (converted in Cosmos coins) in the store

And add invariant ModuleBalance>LockedTokens

This will be useful for testing when using the simulations testing, doing many operation on the staking we verify there is no unwanted emissions of tokens happening

@kingpinXD
Copy link
Contributor

@lumtis I am not very sure about the invariant mentioned , The ModuleBalance would not be greater that the Locked tokens as we transfer the tokens from the Module to the cosmos address of the user after minting .

@kingpinXD
Copy link
Contributor

Lock ZRC20

  • When locking we do the following checks

    • AlreadyLocked : It is the current balance of ZRC20 tokens for the locker account , i.e the bank precompile
    • AmountToDeposit : It is the amount of ZRC20 tokens that the user wants to lock
      We verify that the sum of AlreadyLocked + AmountToDeposit is less than or equal to the total supply of the ZRC20 token.
      Where the total supply is fetched from the the smart contract directly
  • An equvalent amount of AmountToDeposit tokens are then locked in the bank precompile account [Transferred from user to bank precompile]

  • Once conformed we can Mint the equivalentAmount of cosmos native tokens to the user account

  • The total amount minted should always be less than or equal to the amount of ZRC20 tokens locked in the bank precompile account.

Unlock ZRC20

  • Check that the caller has enough balance
  • Bank Precompile has enough locked ZRC20 to release the tokens
  • Send cosmos native tokens from user to fungible module, burn the transferred tokens.
  • Send ZRC20 tokens from bank precompile to a user account

Task: Add an invariant to make sure the balance between locked and minted tokens is always maintained
NOTE:

  • Burn and Mint automatically adjust supply of cosmos native tokens
  • Currently there is only one locker for ZRC20 tokens. The bank precompile .

For all ZRC20 tokens

  • Total supply of cosmos native tokens <= Total ZRC20 tokens locked in the bank precompile account

    • Fetch Total supply of cosmos native tokens using bankkeeper.GetSupply(zrc20). Where
      zrc20=ZRC20ToCosmosDenom(zrc20address)
    • Fetch Total ZRC20 tokens locked in the bank precompile account
      lockedAmount, err := k.ZRC20BalanceOf(ctx, zrc20Address, "bankPrecompileAddress")

    Wanted to verify if this is in line with what you were thinking as well ?

@kingpinXD
Copy link
Contributor

kingpinXD commented Dec 17, 2024

  • When locking, a mint is always called which would adjust the Supply of cosmos native tokens

  • When unlocking a burn is always called which would adjust the Supply of cosmos native tokens

  • The check would fail under the conditions

    • We lock tokens and we dont mint
    • We unlock tokens and we dont burn

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

No branches or pull requests

2 participants