Q&A for Michelson and Liquidity instructions

catsigma
2 min readMar 9, 2018

--

(outdated, waiting for the formal release of zeronet)

Since Michelson and Liquidity are basically isomorphic, I’ll answer the questions with both of them to show the correspondence. This topic will be continuously updated.

Notice that Michelson is represented as M whilst Liquidity is represented as L and type symbols are represented as 'symbol .

Who is calling me?

M(Michelson): SOURCE 'a 'b
Effect: A contract with type ('a 'b) pushed to the top of the stack
L(Liquidity): (Source : ('a,'b) contract)
Effect: return a contract with type ('a, 'b)

'a is the type of the caller’s parameter and 'b is the type of its return.

How to transfer 5 XTZs to other accounts?

M: 
keep your stack like this
[
UNIT;
"5" : tez;
"TZ1rM3KL4aERKYgZiPf1tvZZqKggvfh9Cs9Q" : contract unit unit;
storage : storage
]
and then TRANSFER_TOKENS
Effect: the stack will be changed to [UNIT; storage]
L:
let account = (TZ1rM3KL4aERKYgZiPf1tvZZqKggvfh9Cs9Q: (unit, unit) contract) in
let (result, storage) = Contract.call account 5tz storage () in
Effect: you can only access `result` and `storage` from now

How to do fraction calculations?

Let’s say you want to do 2 / 3 * 7 = 4.666666.

M:
PUSH nat 3 ;
PUSH nat 1000000 ;
PUSH nat 7 ;
PUSH nat 2 ;
MUL ;
MUL ;
EDIV ;
IF_NONE
{
FAIL ;
}
{
DUP ;
DIP
{
DROP ;
};
CAR;
};
Effect: 4666666 at the top of stack
L:
let result =
match 2p * 7p * 1000000p / 3p with
| None -> Current.fail ()
| Some x -> x.(0)
in
Effect: result is 4666666p

Tezos cannot handle fractions directly, so we need to multiply a large number to remove the decimal point. Later you can recover the decimal point to make it display correctly.

…to be continued

Donation BTC: 1L7oCqy7GHx7EiQc9SPFputCWftfaoT3kB

--

--