TransWikia.com

Tezos.get_entrypoint_opt in Ligo issue

Tezos Asked by Anastasia Kondaurova on August 20, 2021

I am trying to replace get_contract with Tezos.get_entrypoint_opt
I need to transfer FA1.2 tokens in Dex: https://github.com/madfish-solutions/quipuswap-core/blob/master/contracts/Dex.ligo#L21-L28

      operations := transaction(
         Transfer(Tezos.sender, this, tokenAmount), 
         0mutez, 
         case (Tezos.get_entrypoint_opt("%transfer", s.tokenAddress) : option(contract(x))) of Some(contr) -> contr
         | None -> (failwith("01"):contract(x))
         end
         ) # operations;

But the entrypoint isn’t found during execution.
Deployed contract: https://better-call.dev/carthagenet/KT1PB7PCFS3F71FT8fbRmYsYX3ex8W7X5Vcw
I have used this approach before and it worked fine:

operations := transaction(Transfer(Tezos.sender, this, tokenAmount), 0mutez, (get_contract(s.tokenAddress): contract(tokenAction))) # operations;

Deployed contract: https://better-call.dev/carthagenet/KT1KSpx5NY7FkY9PFBGRbYbui36rEF6agVWr
Could someone advise something?

3 Answers

It depends on the "x"

let's say "x" is a variant (or (or (int %decrement) (unit %default)) (int %increment)) which represents entrypoints of the targeted contract.

  • get_contract({address}) returns a contract(x)
  • get_entrypoint_opt("%increment", {address}) returns a optional(contract(int))

Using get_entrypoint_opt function one must specify only the type of the parameter of the specified entrypoint (and not the parameter of the contract). Actually, it ensures that the contract at the given address possess an well-named entrypoint and with the expected type.

So I would say: replace the x by the right type. Find out what is expected by the entrypoint Transfer (i.e. Transfer of ...) ... I guess it must be (address * address * mutez) or in a record format .

I hope it helps

Answered by Frank Hillard on August 20, 2021

I think the entrypoint is well written ("%transfer") because if you look the generated Michelson code, the entrypoint annotations start with a low-case letter.

get_entrypoint_opt Ligo function is equivalent to CONTRACT %transfer {targeted_contract_entrypoints} in Michelson. And I reproduced this bug with a small michelson script like this one.

parameter address ;
storage bool;
code { CAR ;
       CONTRACT %increment (or (int %decrement) (int %increment)) ;
       IF_NONE { PUSH bool False } { DROP; PUSH bool True };
       NIL operation ;
       PAIR }

Notice that if you use get_contract_opt instead of get_entrypoint_opt then it generates an CONTRACT instruction without annotation.

CONTRACT  (or (int %decrement) (int %increment)) ;

and it works.

Answered by Frank Hillard on August 20, 2021

In LIGO entrypoint name corresponds to your router enum value types, not function names. So "Transfer" should start with uppercase letter.

In you case you should call it as follows: Tezos.get_entrypoint_opt("%Transfer", s.tokenAddress)

Answered by conscio on August 20, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP