x
375
parameter (or (nat %accept_trade)
(or (nat %cancel_trade)
(pair %propose_trade
(list %tokens (pair (address %fa2) (pair (nat %id) (nat %amount))))
(pair
(list %for_tokens (pair (address %fa2)
(pair (nat %id) (nat %amount))))
(option %with_user address)))));
storage (pair (nat %counter)
(pair (big_map %metadata string bytes)
(big_map %trades nat
(pair (bool %executed)
(pair (bool %cancelled)
(pair (address %user1)
(pair (option %user2 address)
(pair
(list %tokens1 (pair
(address %fa2)
(pair
(nat %id)
(nat %amount))))
(list %tokens2 (pair
(address %fa2)
(pair
(nat %id)
(nat %amount))))))))))));
code { UNPAIR ;
IF_LEFT
{ SWAP ;
DUP ;
DUG 2 ;
GET 4 ;
SWAP ;
DUP ;
DUG 2 ;
MEM ;
IF {} { PUSH string "The provided trade id doesn't exist" ; FAILWITH } ;
SWAP ;
DUP ;
DUG 2 ;
GET 4 ;
SWAP ;
DUP ;
DUG 2 ;
GET ;
IF_NONE { PUSH int 66 ; FAILWITH } {} ;
CAR ;
IF { PUSH string "The trade was executed" ; FAILWITH } {} ;
SWAP ;
DUP ;
DUG 2 ;
GET 4 ;
SWAP ;
DUP ;
DUG 2 ;
GET ;
IF_NONE { PUSH int 70 ; FAILWITH } {} ;
GET 3 ;
IF { PUSH string "The trade was cancelled" ; FAILWITH } {} ;
PUSH mutez 0 ;
AMOUNT ;
COMPARE ;
EQ ;
IF
{}
{ PUSH string "The operation does not need tez transfers" ; FAILWITH } ;
SWAP ;
DUP ;
DUG 2 ;
GET 4 ;
SWAP ;
DUP ;
DUG 2 ;
GET ;
IF_NONE { PUSH int 130 ; FAILWITH } {} ;
GET 7 ;
IF_NONE
{ SWAP ;
DUP ;
GET 4 ;
DUP ;
DUP 4 ;
DUP ;
DUG 2 ;
GET ;
IF_NONE { PUSH int 137 ; FAILWITH } {} ;
SENDER ;
SOME ;
UPDATE 7 ;
SOME ;
SWAP ;
UPDATE ;
UPDATE 4 ;
SWAP }
{ DROP ;
SWAP ;
DUP ;
DUG 2 ;
GET 4 ;
SWAP ;
DUP ;
DUG 2 ;
GET ;
IF_NONE { PUSH int 130 ; FAILWITH } {} ;
GET 7 ;
IF_NONE { PUSH int 133 ; FAILWITH } {} ;
SENDER ;
COMPARE ;
EQ ;
IF {} { PUSH string "Only user2 can accept the trade" ; FAILWITH } } ;
SWAP ;
DUP ;
GET 4 ;
DUP ;
DUP 4 ;
DUP ;
DUG 2 ;
GET ;
IF_NONE { PUSH int 140 ; FAILWITH } {} ;
PUSH bool True ;
UPDATE 1 ;
SOME ;
SWAP ;
UPDATE ;
UPDATE 4 ;
SWAP ;
NIL operation ;
DUP 3 ;
GET 4 ;
DUP 3 ;
GET ;
IF_NONE { PUSH int 130 ; FAILWITH } {} ;
GET 10 ;
ITER { DUP ;
DUG 2 ;
CAR ;
CONTRACT %transfer (list (pair address
(list (pair address (pair nat nat))))) ;
IF_NONE { PUSH int 199 ; FAILWITH } {} ;
PUSH mutez 0 ;
NIL (pair address (list (pair address (pair nat nat)))) ;
NIL (pair address (pair nat nat)) ;
DIG 5 ;
DUP ;
GET 4 ;
SWAP ;
GET 3 ;
DUP 9 ;
GET 4 ;
DUP 9 ;
GET ;
IF_NONE { PUSH int 130 ; FAILWITH } {} ;
GET 5 ;
PAIR 3 ;
CONS ;
SENDER ;
PAIR ;
CONS ;
TRANSFER_TOKENS ;
CONS } ;
DUP 3 ;
GET 4 ;
DIG 2 ;
GET ;
IF_NONE { PUSH int 130 ; FAILWITH } {} ;
GET 9 ;
ITER { DUP ;
DUG 2 ;
CAR ;
CONTRACT %transfer (list (pair address
(list (pair address (pair nat nat))))) ;
IF_NONE { PUSH int 199 ; FAILWITH } {} ;
PUSH mutez 0 ;
NIL (pair address (list (pair address (pair nat nat)))) ;
NIL (pair address (pair nat nat)) ;
DIG 5 ;
DUP ;
GET 4 ;
SWAP ;
GET 3 ;
SENDER ;
PAIR 3 ;
CONS ;
SELF_ADDRESS ;
PAIR ;
CONS ;
TRANSFER_TOKENS ;
CONS } }
{ IF_LEFT
{ SWAP ;
DUP ;
DUG 2 ;
GET 4 ;
SWAP ;
DUP ;
DUG 2 ;
MEM ;
IF {} { PUSH string "The provided trade id doesn't exist" ; FAILWITH } ;
SWAP ;
DUP ;
DUG 2 ;
GET 4 ;
SWAP ;
DUP ;
DUG 2 ;
GET ;
IF_NONE { PUSH int 66 ; FAILWITH } {} ;
CAR ;
IF { PUSH string "The trade was executed" ; FAILWITH } {} ;
SWAP ;
DUP ;
DUG 2 ;
GET 4 ;
SWAP ;
DUP ;
DUG 2 ;
GET ;
IF_NONE { PUSH int 70 ; FAILWITH } {} ;
GET 3 ;
IF { PUSH string "The trade was cancelled" ; FAILWITH } {} ;
PUSH mutez 0 ;
AMOUNT ;
COMPARE ;
EQ ;
IF
{}
{ PUSH string "The operation does not need tez transfers" ; FAILWITH } ;
SWAP ;
DUP ;
DUG 2 ;
GET 4 ;
SWAP ;
DUP ;
DUG 2 ;
GET ;
IF_NONE { PUSH int 169 ; FAILWITH } {} ;
GET 5 ;
SENDER ;
COMPARE ;
EQ ;
IF {} { PUSH string "Only user1 can cancel the trade" ; FAILWITH } ;
SWAP ;
DUP ;
GET 4 ;
DUP ;
DUP 4 ;
DUP ;
DUG 2 ;
GET ;
IF_NONE { PUSH int 174 ; FAILWITH } {} ;
PUSH bool True ;
UPDATE 3 ;
SOME ;
SWAP ;
UPDATE ;
UPDATE 4 ;
SWAP ;
NIL operation ;
DUP 3 ;
GET 4 ;
DIG 2 ;
GET ;
IF_NONE { PUSH int 169 ; FAILWITH } {} ;
GET 9 ;
ITER { DUP ;
DUG 2 ;
CAR ;
CONTRACT %transfer (list (pair address
(list (pair address (pair nat nat))))) ;
IF_NONE { PUSH int 199 ; FAILWITH } {} ;
PUSH mutez 0 ;
NIL (pair address (list (pair address (pair nat nat)))) ;
NIL (pair address (pair nat nat)) ;
DIG 5 ;
DUP ;
GET 4 ;
SWAP ;
GET 3 ;
SENDER ;
PAIR 3 ;
CONS ;
SELF_ADDRESS ;
PAIR ;
CONS ;
TRANSFER_TOKENS ;
CONS } }
{ PUSH mutez 0 ;
AMOUNT ;
COMPARE ;
EQ ;
IF
{}
{ PUSH string "The operation does not need tez transfers" ; FAILWITH } ;
DUP ;
CAR ;
ITER { GET 4 ;
PUSH nat 0 ;
SWAP ;
COMPARE ;
GE ;
IF
{}
{ PUSH string "At least one token edition needs to be traded" ;
FAILWITH } } ;
DUP ;
GET 3 ;
ITER { GET 4 ;
PUSH nat 0 ;
SWAP ;
COMPARE ;
GE ;
IF
{}
{ PUSH string "At least one token edition needs to be traded" ;
FAILWITH } } ;
DUP ;
CAR ;
NIL operation ;
SWAP ;
ITER { DUP ;
DUG 2 ;
CAR ;
CONTRACT %transfer (list (pair address
(list (pair address (pair nat nat))))) ;
IF_NONE { PUSH int 199 ; FAILWITH } {} ;
PUSH mutez 0 ;
NIL (pair address (list (pair address (pair nat nat)))) ;
NIL (pair address (pair nat nat)) ;
DIG 5 ;
DUP ;
GET 4 ;
SWAP ;
GET 3 ;
SELF_ADDRESS ;
PAIR 3 ;
CONS ;
SENDER ;
PAIR ;
CONS ;
TRANSFER_TOKENS ;
CONS } ;
DUP 3 ;
DUP ;
GET 4 ;
DIG 3 ;
DUP ;
GET 3 ;
SWAP ;
DUP ;
CAR ;
SWAP ;
DUP ;
DUG 6 ;
GET 4 ;
SENDER ;
PUSH bool False ;
DUP ;
PAIR 6 ;
DIG 4 ;
DROP ;
SOME ;
DIG 4 ;
CAR ;
UPDATE ;
UPDATE 4 ;
DUP ;
CAR ;
PUSH nat 1 ;
ADD ;
UPDATE 1 ;
SWAP } } ;
NIL operation ;
SWAP ;
ITER { CONS } ;
PAIR }