Getting 10% of tez

asked 2017-05-13 15:56:58 -0500

Hi, I'm writing a smart contract in Michelson, and I can't figure out how to get 10% of a tez amount. According to the language.pdf doc on Michelson, there are only these operators on tez: ADD, SUB, MUL, and COMPARE.

• ADD: :: tez : tez : 'S -> tez : 'S
• SUB: :: tez : tez : 'S -> tez : 'S
• MUL :: tez : u?int{8|16|32|64} : 'S -> tez : 'S
• COMPARE: :: tez : tez : 'S -> int64 : 'S

So it looks like I want to use MUL on a stack that looks like [ tez : 0.10], but 0.10 isn't an int, so I can't use that.

If I try to do MUL [tez : tez] where the second tez is "0.10", I get "operator MUL is undefined between tez and tez"

I saw that DIV existed as well, but if I do DIV [tez: tez], I get "operator DIV is undefined between tez and tez"

If I do DIV [tez: uint32] I get "operator DIV is undefined between tez and uint32"

It looks like the only thing I can do is:

PUSH uint32 10; PUSH uint32 1; DIV;

But that seems pretty convoluted, and I'm pretty sure that the result of int division should only be an int.

Any help would be appreciated, thanks!

edit retag close delete

1 Answer

Sort by » oldest newest most voted

answered 2017-05-13 23:11:39 -0500

Yes, it's totally missing, thank you for noticing! We're redoing the integers to use libgmp everywhere; tere will be only three int types: int, nat, and tez. But before we do we should still fix this.

If you're feeling adventurous and want to send us a patch, take a look at Mul_tez in the code

https://github.com/tezos/te...

You can add Div_tez is a couple lines by replicating this pattern.

more

Comments

Cool! I'll look into sending a patch. Thanks for the response!

( 2017-05-13 23:28:01 -0500 )edit

Your answer

Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

Add answer

[hide preview]

Stats

Asked: 2017-05-13 15:56:58 -0500

Seen: 11,940 times

Last updated: May 13 '17