Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
EXCHANGE_TOKEN_STANDARD=FA12
LIGO_VERSION=0.9.0
LIGO_VERSION=0.24.0
8 changes: 0 additions & 8 deletions contracts/main/BakerRegistry.ligo

This file was deleted.

29 changes: 29 additions & 0 deletions contracts/main/Dex.ligo
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include "../partials/IDex.ligo"
#include "../partials/Utils.ligo"
#include "../partials/MethodFA2.ligo"
#include "../partials/MethodDex.ligo"
#include "../partials/Dex.ligo"

(* Dex - Contract for exchanges between FA12 and FA2 tokens *)
function main(
const p : full_action_type;
const s : full_storage_type)
: full_return_type is
case p of
Use(params) -> call_dex(params, s)
| Transfer(params) -> call_token(ITransfer(params), 0n, s)
| Balance_of(params) -> call_token(IBalance_of(params), 2n, s)
| Update_operators(params) -> call_token(IUpdate_operators(params), 1n, s)
| Get_reserves(params) -> get_reserves(params, s)
| Close -> ((nil:list(operation)), close(s))
| SetDexFunction(params) ->
((nil:list(operation)),
if params.index > dex_func_count
then (failwith("Dex/wrong-index") : full_storage_type)
else set_dex_function(params.index, params.func, s))
| SetTokenFunction(params) ->
((nil:list(operation)),
if params.index > token_func_count
then (failwith("Dex/wrong-index") : full_storage_type)
else set_token_function(params.index, params.func, s))
end
16 changes: 0 additions & 16 deletions contracts/main/DexFA12.ligo

This file was deleted.

445 changes: 0 additions & 445 deletions contracts/main/DexFA12.tz

This file was deleted.

15 changes: 0 additions & 15 deletions contracts/main/DexFA2.ligo

This file was deleted.

382 changes: 0 additions & 382 deletions contracts/main/DexFA2.tz

This file was deleted.

3 changes: 0 additions & 3 deletions contracts/main/FactoryFA12.ligo

This file was deleted.

4 changes: 0 additions & 4 deletions contracts/main/FactoryFA2.ligo

This file was deleted.

44 changes: 29 additions & 15 deletions contracts/main/MetadataStorage.ligo
Original file line number Diff line number Diff line change
@@ -1,30 +1,44 @@
#include "../partials/IMetadataStorage.ligo"

(* Add or remove the admin permissions for address; only called by one of the current owners *)
function update_owner (const params : update_owner_type; const s : storage) : return is
(* Add or remove the admin permissions for address;
only called by one of the current owners *)
function update_owner(
const params : set_owner_type;
var s : storage_type)
: return_type is
block {
if s.owners contains Tezos.sender then
skip
if s.owners contains Tezos.sender
then skip
else failwith("MetadataStorage/permision-denied");
if params.add then
s.owners := Set.add (params.owner, s.owners)
else
s.owners := Set.remove (params.owner, s.owners);

if params.add
then s.owners := Set.add (params.owner, s.owners)
else s.owners := Set.remove (params.owner, s.owners);
} with ((nil : list (operation)), s)

(* Update the metadata for the token; only called by one of the current owners *)
function update_metadata (const new_metadata : metadata_type; const s : storage) : return is
(* Update the metadata for the token;
only called by one of the current owners *)
function update_metadata(
const new_metadata : metadata_type;
var s : storage_type)
: return_type is
block {
if s.owners contains Tezos.sender then
skip
if s.owners contains Tezos.sender
then skip
else failwith("MetadataStorage/permision-denied");
s.metadata := new_metadata;
} with ((nil : list (operation)), s)

(* MetadataStorage - Contract to store and upgrade the shares token metadata *)
function main (const p : storage_action; const s : storage) : return is
function main(
const p : action_type;
var s : storage_type)
: return_type is
case p of
| Update_owners(params) -> update_owner(params, s)
Update_owners(params) -> update_owner(params, s)
| Update_storage(new_metadata) -> update_metadata(new_metadata, s)
| Get_metadata(receiver) -> (list [transaction(s.metadata, 0tz, receiver)], s)
| Get_metadata(receiver) -> (list [
transaction(s.metadata, 0tz, receiver)
],
s)
end
20 changes: 0 additions & 20 deletions contracts/main/TTDex.ligo

This file was deleted.

2 changes: 0 additions & 2 deletions contracts/main/TestFactoryFA12.ligo

This file was deleted.

2 changes: 0 additions & 2 deletions contracts/main/TestFactoryFA2.ligo

This file was deleted.

32 changes: 16 additions & 16 deletions contracts/main/TokenFA12.ligo
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "../partials/IToken.ligo"

(* Helper function to get account *)
function getAccount (const addr : address; const s : storage) : account is
function getAccount (const addr : address; const s : storage_type) : account is
case s.ledger[addr] of
None -> record [
balance = 0n;
Expand All @@ -11,22 +11,22 @@ function getAccount (const addr : address; const s : storage) : account is
end;

(* Helper function to get allowance for an account *)
function getAllowance (const ownerAccount : account; const spender : address; const s : storage) : amt is
function getAllowance (const ownerAccount : account; const spender : address) : amt is
case ownerAccount.allowances[spender] of
Some (amt) -> amt
| None -> 0n
end;

(* Transfer token to another account *)
function transfer (const from_ : address; const to_ : address; const value : amt; var s : storage) : return is
function transfer (const from_ : address; const to_ : address; const value : amt; var s : storage_type) : return_type is
block {
(* Sending to yourself? *)
if from_ = to_ then
failwith("InvalidSelfToSelfTransfer")
else skip;

(* Retrieve sender account from storage *)
const senderAccount : account = getAccount(from_, s);
(* Retrieve sender account from storage_type *)
var senderAccount : account := getAccount(from_, s);

(* Balance check *)
if senderAccount.balance < value then
Expand All @@ -35,7 +35,7 @@ function transfer (const from_ : address; const to_ : address; const value : amt

(* Check this address can spend the tokens *)
if from_ =/= Tezos.sender then block {
const spenderAllowance : amt = getAllowance(senderAccount, Tezos.sender, s);
const spenderAllowance : amt = getAllowance(senderAccount, Tezos.sender);

if spenderAllowance < value then
failwith("NotEnoughAllowance")
Expand All @@ -48,7 +48,7 @@ function transfer (const from_ : address; const to_ : address; const value : amt
(* Update sender balance *)
senderAccount.balance := abs(senderAccount.balance - value);

(* Update storage *)
(* Update storage_type *)
s.ledger[from_] := senderAccount;

(* Create or get destination account *)
Expand All @@ -57,13 +57,13 @@ function transfer (const from_ : address; const to_ : address; const value : amt
(* Update destination balance *)
destAccount.balance := destAccount.balance + value;

(* Update storage *)
(* Update storage_type *)
s.ledger[to_] := destAccount;

} with (noOperations, s)

(* Approve an amt to be spent by another address in the name of the sender *)
function approve (const spender : address; const value : amt; var s : storage) : return is
function approve (const spender : address; const value : amt; var s : storage_type) : return_type is
block {
if spender = Tezos.sender then
failwith("InvalidSelfToSelfApproval")
Expand All @@ -73,7 +73,7 @@ function approve (const spender : address; const value : amt; var s : storage) :
var senderAccount : account := getAccount(Tezos.sender, s);

(* Get current spender allowance *)
const spenderAllowance : amt = getAllowance(senderAccount, spender, s);
// const spenderAllowance : amt = getAllowance(senderAccount, spender, s);

(* Prevent a corresponding attack vector *)
// if spenderAllowance > 0n and value > 0n then
Expand All @@ -83,32 +83,32 @@ function approve (const spender : address; const value : amt; var s : storage) :
(* Set spender allowance *)
senderAccount.allowances[spender] := value;

(* Update storage *)
(* Update storage_type *)
s.ledger[Tezos.sender] := senderAccount;

} with (noOperations, s)

(* View function that forwards the balance of source to a contract *)
function getBalance (const owner : address; const contr : contract(amt); var s : storage) : return is
function getBalance (const owner : address; const contr : contract(amt); var s : storage_type) : return_type is
block {
const ownerAccount : account = getAccount(owner, s);
} with (list [transaction(ownerAccount.balance, 0tz, contr)], s)

(* View function that forwards the allowance amt of spender in the name of tokenOwner to a contract *)
function getAllowances (const owner : address; const spender : address; const contr : contract(amt); var s : storage) : return is
function getAllowances (const owner : address; const spender : address; const contr : contract(amt); var s : storage_type) : return_type is
block {
const ownerAccount : account = getAccount(owner, s);
const spenderAllowance : amt = getAllowance(ownerAccount, spender, s);
const spenderAllowance : amt = getAllowance(ownerAccount, spender);
} with (list [transaction(spenderAllowance, 0tz, contr)], s)

(* View function that forwards the totalSupply to a contract *)
function getTotalSupply (const contr : contract(amt); var s : storage) : return is
function getTotalSupply (const contr : contract(amt); var s : storage_type) : return_type is
block {
skip
} with (list [transaction(s.total_supply, 0tz, contr)], s)

(* TokenFA1.2 - Mock FA1.2 token for tests *)
function main (const action : tokenAction; var s : storage) : return is
function main (const action : tokenAction; var s : storage_type) : return_type is
block {
skip
} with case action of
Expand Down
Loading