Skip to content

Instantly share code, notes, and snippets.

View mariano-aguero's full-sized avatar
:octocat:
Focusing

Mariano Aguero mariano-aguero

:octocat:
Focusing
View GitHub Profile
if amount =/= 0tz then failwith ("This contract do not accept token amount");
@mariano-aguero
mariano-aguero / roles.ligo
Last active May 14, 2020 12:34
Role mechanism
// Allowed roles, you can add a new annotation right here, for example 'Dev' or 'Moderator'
type role is Admin | User | NoRole
type action is
| MakeAdmin of (address)
| MakeUser of (address)
| RemoveRole of (address)
type store is record
users: big_map(address, role);
@mariano-aguero
mariano-aguero / owner.ligo
Last active May 11, 2020 18:57
Ownership mechanism
type action is AddOwner of (address)
// An unordered collections of owner accounts
type store is record
owners: set(address);
end
type return is list(operation) * store
// Function that checks if an account is an owner
@mariano-aguero
mariano-aguero / token.ligo
Created April 23, 2020 14:31
Change amount
// This is an implementation of the FA1.2 specification in PascaLIGO
type amountNat is nat;
type account is record
balance : amountNat;
allowances: map(address, amountNat);
end
type action is
function depositImp(var store: store): return is
block {
if amount = 0mutez
then failwith("No tez transferred!");
else skip;
// Setting the deposit to the sender
store := updateDeposit(amount, store);
// TODO: try to get the decimals property from the token contract
function tokenProxy (const action : tokenAction; const store : store): operation is
block {
const tokenContract: contract (tokenAction) =
case (Tezos.get_contract_opt (store.token.contractAddress) : option (contract (tokenAction))) of
Some (contractAction) -> contractAction
| None -> (failwith ("Contract not found.") : contract (tokenAction))
end;
const proxyOperation : operation = Tezos.transaction (action, 0mutez, tokenContract);
} with proxyOperation;
@mariano-aguero
mariano-aguero / fa12.ligo
Last active April 20, 2020 18:58
fa12.ligo
function transfer (const addressFrom : address; const addressTo : address; const value : nat; var store : store) : return is
block {
if addressFrom = addressTo then skip;
else block {
case isAllowed(addressFrom, addressTo, value, store) of
| False -> block {
failwith ("NotEnoughAllowance");
}
| True -> skip
end;
function approve (const addressSpender : address; const value : nat; var store : store) : return is
block {
// If sender is the spender approving is not necessary
if sender = addressSpender then skip;
else block {
const senderAccount: account = getAccount(sender, store.accounts);
var allowed: nat := getAllowance(addressSpender, senderAccount.allowances);
// Changing allowance value from non-zero value to a non-zero value is forbidden to prevent the corresponding attack vector.
if allowed =/= 0n then failwith("UnsafeAllowanceChange");
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
@mariano-aguero
mariano-aguero / FA12.ligo
Created April 20, 2020 17:45
FA12 store
type account is record
balance: nat;
allowances: map(address, nat);
end
type store is record
owners: set(address);
decimals: nat; // Added this property used in the erc20 ethereum specification
symbol: string; // Added this property used in the erc20 ethereum specification
name: string; // Added this property used in the erc20 ethereum specification