Skip to content

Instantly share code, notes, and snippets.

@mariano-aguero
Created April 20, 2020 18:31
Show Gist options
  • Save mariano-aguero/2e448c295997902832ee5ab023b33c34 to your computer and use it in GitHub Desktop.
Save mariano-aguero/2e448c295997902832ee5ab023b33c34 to your computer and use it in GitHub Desktop.
FA12.ligo
function mint (const value : nat ; var store : store) : return is
block {
// Fail if is not an owner
if not isOwner(sender, store) then failwith("You must be an owner of the contract to mint tokens");
else block {
var ownerAccount: account := record
balance = 0n;
allowances = (map end : map(address, nat));
end;
case store.accounts[sender] of
| None -> skip
| Some(n) -> ownerAccount := n
end;
// Update the owner balance and totalSupply
const newBalance :nat = ownerAccount.balance + value;
patch ownerAccount with record [balance = newBalance];
store.accounts[sender] := ownerAccount;
store.totalSupply := store.totalSupply + value;
}
} with (emptyOps, store)
function burn (const value : nat ; var store : store) : return is
block {
// Fail if is not an owner
if not isOwner(sender, store) then failwith("You must be an owner of the contract to burn tokens");
else block {
var ownerAccount: account := record
balance = 0n;
allowances = (map end : map(address, nat));
end;
case store.accounts[sender] of
| None -> skip
| Some(n) -> ownerAccount := n
end;
// Check that the owner can spend that much
if value > ownerAccount.balance
then failwith ("NotEnoughBalance");
else skip;
// Check totalSupply
if value > store.totalSupply
then failwith ("TotalSupply is too low");
else skip;
// Update balances and totalSupply
const newBalance :nat = abs(ownerAccount.balance - value);
patch ownerAccount with record [balance = newBalance];
store.accounts[sender] := ownerAccount;
store.totalSupply := abs(store.totalSupply - value);
}
} with (emptyOps, store)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment