Mavryk
let get_balance: (_u: unit) => mav
Get the balance for the contract.
let get_now: (_u : unit) => timestamp
Returns the current time as a UNIX timestamp.
In LIGO, timestamps are type compatible in operations with integers. This lets you set for instance time constraints for your smart contracts like this:
Examples
24 hours from now
24 hours ago
Comparing Timestamps
You can also compare timestamps using the same comparison operators as for numbers
let get_amount: (_u : unit) => mav
Get the amount of mav provided by the sender to complete this transaction.
let get_sender: (_u : unit) => address
Get the address that initiated the current transaction.
let address: (contract: contract<'a>) => address
Get the address associated with a value of type contract
.
let get_self_address: (_u : unit) => address
Get the address of the currently running contract.
let self: (entrypoint: string) => contract<'a>
Typecast the currently running contract with an entrypoint annotation. If you are using entrypoints, use "%bar" for a constructor "Bar". If you are not using entrypoints: use "%default"
let implicit_account : (_: key_hash) => contract<unit>
Get the default contract associated with an on-chain key-pair. This contract does not execute code, instead it exists to receive tokens on behalf of a key's owner.
See also: http://protocol.mavryk.org/user/glossary.html#implicit-account
let get_source: (_u : unit) => address
Get the originator (address) of the current transaction. That is, if
a chain of transactions led to the current execution get the address
that began the chain. Not to be confused with Mavryk.get_sender
, which
gives the address of the contract or user which directly caused the
current transaction.
⚠️ There are a few caveats you should keep in mind before using
Mavryk.get_source
overMavryk.get_sender
:
Mavryk.get_source
will never be a contract, so if you want to allow contracts (multisigs etc) to operate your contract, you need to useMavryk.get_sender
- https://vessenes.com/tx-origin-and-ethereum-oh-my/ -- in general it is somewhat unsafe to assume that
Mavryk.get_source
understands everything that is going to happen in a transaction. IfMavryk.get_source
transfers to a malicious (or sufficiently attackable) contract, that contract might potentially transfer to yours, withoutMavryk.get_source
's consent. So if you are usingMavryk.get_source
for authentication, you risk being confused. A good historical example of this is bakers paying out delegation rewards. Naive bakers did (and probably still do) just use mavryk-client to transfer to whatever KT1 delegates they had, even if those KT1 were malicious scripts.
let failwith: (message: 'a) => unit
let get_chain_id: (_u : unit) => chain_id
Get the identifier of the chain to distinguish between main and test chains.
This is mainly intended to avoid replay attacks between the chains, and can currently
only be used together with Bytes.pack
and Bytes.unpack
.
let transaction: (action: 'param, amount: mumav, contract: contract<'param>) => operation
Transfer mav
to an account, or run code of another smart contract.
To indicate an account, use unit
as param
.
let create_contract = (contract: ('param, 'storage) => (list <operation>, 'storage), delegate: option<key_hash>, balance: mav, init: 'storage) => [operation, address]
Construct an operation that originates a contract from a function. The
optional argument of type key_hash
represents a delegate.
let set_delegate: (delegate: option<key_hash>) => operation
Modify the delegate of the current contract.
The operation fails when:
- the delegate is the same as current delegate
- the keyhash is not of a registered delegate
Use None
to withdraw the current delegate.
let get_contract_opt : (a: address) => option<contract<'param>>
Get a contract from an address.
When no contract is found or the contract doesn't match the type,
None
is returned.
let get_contract_with_error : (a: address,s: string) => contract<'param>
Get a contract from an address.
When no contract is found, fail with the provided string
let get_entrypoint_opt: (entrypoint: string, a: address) => option<contract<'param>>
Get a contract from an address and entrypoint.
Entrypoints are written in the form of: %entrypoint
.
When no contract is found or the contract doesn't match the type,
None
is returned.
let get_level : (_u : unit) => nat
Get the current block level.
let min_block_time: unit => nat;
Returns the current minimal time between blocks, the value is obtained from the protocol’s minimal_block_delay constant.
let pairing_check: list<[bls12_381_g1, bls12_381_g2]>) => bool
Verify that the product of pairings of the given list of points is equal to 1 in Fq12. Returns true if the list is empty.
Can be used to verify if two pairings P1 and P2 are equal by verifying P1 * P2^(-1) = 1
.
(extracted from Mavryk documentation)
let never: (never: never) => 'a
Eliminate a value of the type never
using the instruction NEVER
from Michelson.
let get_total_voting_power: (_u : unit) => nat
Return the total voting power of all contracts. The total voting power coincides with the sum of the rolls count of every contract in the voting listings. The voting listings is calculated at the beginning of every voting period.
let voting_power: (key_hash:key_hash) => nat
Return the voting power of a given contract. The voting power value is the full staking power of the delegate, currently expressed in mumav. Though, developers should not rely on Mavryk.voting_power
to query the staking power of a contract in mumav: the value returned by Mavryk.voting_power
is still of typenat and it should only be considered relative to
Mavryk.total_voting_power`.
Sapling
Delphi protocol introduced the following sapling types (state and transaction) with N being an int singleton
let sapling_empty_state: sapling_state<n>
Sapling empty state
let sapling_verify_update: sapling_transaction<'a> => sapling_state<'a> => option<[bytes, [int, sapling_state<'a>]]>
Verify sapling update
Linearity
If a contract storage type contains a ticket, you must destructure the parameter-storage pair within the body to preserve storage linearity (e.g. avoid DUP
-ing storage).
For the same reasons, if tickets are stored in a map
/big_map
you must use the new operator get_and_update
to update your bindings.
Timelock
let open_chest : (key: chest_key, chest: chest, time: nat) => option<bytes>
Open a timelocked chest given its key and the time.