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

bug?(gnovm): interface conversion error when trying to burn grc20 #3685

Open
matijamarjanovic opened this issue Feb 4, 2025 · 2 comments
Open

Comments

@matijamarjanovic
Copy link
Contributor

matijamarjanovic commented Feb 4, 2025

Please note that I might be mistaken as I lack deeper understanding of gnovm

I'm in the process of making a simple dex, which mints LP tokens to liquidity providers. When lp is to withdraw his assets the LP tokens should be burned, i do this in this func:

Image

This results in this error:
0 /mnt/c/Users/matij/Projects/gno/tm2/pkg/errors/errors.go:28 - deliver transaction failed: log:recovered: interface conversion: gnolang.Stmt is *gnolang.AssignStmt, not *gnolang.bodyStmt

The prints I added in token.gno indicate that the error happens in line 214:

Image

I have made sure that the amount of minted LPs is much higher than the amount I try to burn (I've tried burning both a little % as well as 100% of minted LPs). I have also double checked all the types (all are uint64). I have also run the gno tool lint and everything seems to be in order. Also calling this function works as inteded:

Image

which is what confuses me the most. Regardless, I hope to stand corrected (and find a solution to the error that I am getting).

@matijamarjanovic
Copy link
Contributor Author

Update:
I have tried using the debugger but the script I have written (see below) seems to have withdrawing lp work just right - I haven't found anything unexpected using debugger. The problem occurs when I try to do this using gnokey on gnodev.

package main

import (
	"std"
	"gno.land/p/demo/grc/grc20"
	"gno.land/r/demo/tokenhub"
	"gno.land/r/matijamarjanovic/gnoxchange"
)

func main() {
	tokenA, tokenALedger := grc20.NewToken("Test Token A", "TTA", 6)
	tokenB, tokenBLedger := grc20.NewToken("Test Token B", "TTB", 6)
	
	tokenhub.RegisterToken(tokenA.Getter(), "TTA")
	tokenhub.RegisterToken(tokenB.Getter(), "TTB")

  	provider := std.Address(std.CurrentRealm().Addr())
   
   	initialAmount := uint64(1000_000000)
  	tokenALedger.Mint(provider, initialAmount)
   	tokenBLedger.Mint(provider, initialAmount)

   	poolAmount := uint64(100_000000)

	tokenALedger.Approve(std.CurrentRealm().Addr(), std.DerivePkgAddr("gno.land/r/matijamarjanovic/gnoxchange"), poolAmount)
	tokenBLedger.Approve(std.CurrentRealm().Addr(), std.DerivePkgAddr("gno.land/r/matijamarjanovic/gnoxchange"), poolAmount)
	
	poolKey, err := gnoxchange.CreatePool(".TTA", ".TTB", poolAmount, poolAmount)
	if err != nil {
		panic(err)
	}

	withdrawAmount := uint64(50_000000)
	amountA, amountB, err := gnoxchange.WithdrawLiquidity(poolKey, withdrawAmount)
	if err != nil {
		panic(err)
	}

	println("Pool created with key:", poolKey)
	println("Withdrawn amounts - A:", amountA, "B:", amountB)
	println(tokenhub.GetUserTokenBalances(string(std.CurrentRealm().Addr())))
}

@matijamarjanovic
Copy link
Contributor Author

Update:

I have found out that this error is not only for the Burn, but also for the Mint func in token.gno from grc20. I'm starting to think this is related to the fact that I am storing the ledger in the Pool struct in the tree, which is why I have decied to recreate this. Code I've written works perfectly fine:

Image

@matijamarjanovic matijamarjanovic changed the title bug(?): interface conversion error when trying to burn grc20 bug?(gnovm): interface conversion error when trying to burn grc20 Feb 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Triage
Development

No branches or pull requests

1 participant