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 · 4 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
@thehowl
Copy link
Member

thehowl commented Feb 18, 2025

Hey. In order to verify if this is a bug or not, we need a minimal example of code that creates problem; and not as a screenshot, but as text - text is copyable, screenshots are not.

I suspect this may be just some form of syntax error; I suggest you to inspect your code with gno tool lint first, which runs the type checker and should be able to provide you with better error messages.

@matijamarjanovic
Copy link
Contributor Author

matijamarjanovic commented Feb 19, 2025

Okay, so I was told by Leon to try and recreate it and after spending too much time, I stopped because he mock was too close to the original code in the PR. This is why I have chosen this approach - screenshots are easier to read because of the text coloring; here is the zipped dir of my namespace you can use locally (see attachement matijamarjanovic.zip - only thing you have to do is replace testAddr value to your address in matijamarjanovic/test) or alternatively you can see feat/gnoxchange on https://github.com/matijamarjanovic/gno if it's easier.

This is token approval script you can use to give approval to tokens from the test so you can create a pool to try and withdraw from it:

package main

import(
	"std"
	"gno.land/r/matijamarjanovic/tokenhub"
)

func main(){
	a:=tokenhub.GetToken("gno.land/r/matijamarjanovic/test.token-a")
	b:=tokenhub.GetToken("gno.land/r/matijamarjanovic/test.token-b")
	c:=tokenhub.GetToken("gno.land/r/matijamarjanovic/test.token-c")
	nft:=tokenhub.GetNFT("gno.land/r/matijamarjanovic/test.nft-a.NFTA_2")

	atel:=a.CallerTeller()
	btel:=b.CallerTeller()
	ctel:=c.CallerTeller()
	

	atel.Approve(std.DerivePkgAddr("gno.land/r/matijamarjanovic/gnoxchange"), 10000000000)
	btel.Approve(std.DerivePkgAddr("gno.land/r/matijamarjanovic/gnoxchange"), 10000000000)
	ctel.Approve(std.DerivePkgAddr("gno.land/r/matijamarjanovic/gnoxchange"), 10000000000)
	nft.SetApprovalForAll(std.DerivePkgAddr("gno.land/r/matijamarjanovic/gnoxchange"), true)
}

I suggest you to inspect your code with gno tool lint first, which runs the type checker and should be able to provide you with better error messages.

As I have mentioned in the original description:

I have also run the gno tool lint and everything seems to be in order.

I'm sorry if I couldn't be of more help, if it is needed I will continue my efforts in recreating the issue in a simple manner.

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

2 participants