def createDutchAuctionInstance(self, asset_id): sp.verify(sp.sender == self.data.master_auction_contract) contract_address = sp.some( sp.create_contract(storage=sp.record( owner=sp.source, master_auction_contract=self.data.master_auction_contract, asset_id=asset_id, current_price=0, reserve_price=0, started=sp.bool(False), ended=sp.bool(False), start_time=sp.now, round_time=0), contract=self.dutch)) # registerInstance c = sp.contract(sp.TRecord(asset_id=sp.TNat, contract_address=sp.TAddress), self.data.master_auction_contract, entry_point="registerInstance").open_some() sp.transfer( sp.record(asset_id=asset_id, contract_address=contract_address.open_some()), sp.mutez(0), c)
def transfer_presigned(self, params): sp.set_type( params, sp.TRecord(from_=sp.TAddress, to_=sp.TAddress, value=sp.TNat)) params_hash = sp.blake2b(sp.pack(params)) #unsigned = sp.blake2b(mi.operator("SELF; ADDRESS; CHAIN_ID; PAIR; PAIR; PACK", [sp.TPair(sp.TNat, sp.TBytes)], [sp.TBytes])(sp.pair(self.data.counter, params_hash))) permit_key = sp.pair(params.from_, params_hash) effective_expiry = sp.local("effective_expiry", 0) with sp.if_(self.data.permits.contains(permit_key)): permit_submission_timestamp = self.data.permits[permit_key] with sp.if_( self.data.permit_expiries.contains(permit_key) & self.data.permit_expiries[permit_key].is_some()): effective_expiry.value = self.data.permit_expiries[ permit_key].open_some() with sp.else_(): with sp.if_( self.data.user_expiries.contains(params.from_) & self.data.user_expiries[params.from_].is_some()): effective_expiry.value = self.data.user_expiries[ params.from_].open_some() with sp.else_(): effective_expiry.value = self.data.default_expiry # Deleting permit regardless of whether or not its expired with sp.if_( sp.as_nat(sp.now - permit_submission_timestamp) >= effective_expiry.value): # Expired self.delete_permit(permit_key) sp.result(sp.bool(False)) with sp.else_(): self.delete_permit(permit_key) sp.result(sp.bool(True)) with sp.else_(): sp.result(sp.bool(False))
def interest(self, params): sp.verify(sp.amount >= self.data.tz_amount) sp.verify(sp.amount == sp.mutez(params)) sp.verify(self.data.immutable == sp.bool(False)) self.data.immutable = sp.bool(True) self.data.interested_party = sp.sender
def createSealedBidAuctionInstance(self, asset_id, asset_name): sp.verify(sp.sender == self.data.master_auction_contract) contract_address = sp.some(sp.create_contract( storage = sp.record(owner = sp.source, master_auction_contract = sp.to_address(sp.self), asset_id = asset_id, # deposit will get seized if participant tries to cheat deposit = 0, sealed_bids = sp.map(tkey = sp.TAddress, tvalue = sp.TBytes), # TODO: maintain revealed_participants list and only refund those # possibly split the money b/w highest bidder and owner # enforcing all participants to reveal their bids # Then there'll be no need to maintain revealed_count & first_revealed revealed_count = 0, highest_bid = sp.mutez(0), highest_bidder = sp.sender, started = sp.bool(False), first_revealed = sp.bool(False), ended = sp.bool(False), start_time = sp.now, round_time = 0), contract = self.sealed_bid)) # registerInstance c = sp.contract(sp.TRecord(asset_id = sp.TNat, contract_address = sp.TAddress), self.data.master_auction_contract, entry_point = "registerInstance").open_some() sp.transfer(sp.record(asset_id = asset_id, contract_address = contract_address.open_some()), sp.mutez(0), c)
def __init__(self, owner, asset_name, reserve_price, min_increase): self.init(owner = owner, asset_id = asset_id, current_bid = sp.mutez(reserve_price), min_increase = min_increase, highest_bidder = owner, is_active = sp.bool(True))
def __init__(self): self.init( origin = sp.address('tz1'), destiny = sp.address('tz2'), amount = sp.tez(0), immutability = sp.bool(False) )
def endAuction(self, asset_id, owner): self.data.ended = sp.bool(True) # destroyInstance c = sp.contract(sp.TRecord(asset_id=sp.TNat, owner=sp.TAddress), self.data.master_auction_contract, entry_point="destroyInstance").open_some() sp.transfer(sp.record(asset_id=asset_id, owner=owner), sp.mutez(0), c)
def __init__(self, admin, interested_party, fa12, tk_amount, tz_amount): self.init( admin = admin, fa12 = fa12, interested_party = interested_party, tz_amount = sp.mutez(tz_amount), tk_amount = sp.nat(tk_amount), immutable = sp.bool(False) )
def createDutchAuctionInstance(self, asset_id, asset_name): contract_address = sp.create_contract( storage = sp.record(owner = sp.sender, master_auction_contract = sp.to_address(sp.self), asset_id = asset_id, current_price = 0, reserve_price = 0, started = sp.bool(False), ended = sp.bool(False), start_time = sp.now, wait_time = 0), contract = self.dutch) self.data.instances_map[asset_id] = sp.record( asset_name = asset_name, auction_type = "dutch", owner = sp.sender, contract_address = contract_address, is_available = sp.bool(True))
def __init__(self, owner): self.init( owner = owner, isOpen = sp.bool(False), ctrs = sp.map(l = {}), bids = sp.map(l = {}), agents = sp.map(l = {}), prices = sp.map(l = {}), )
def createEnglishAuctionInstance(self, asset_id, asset_name): contract_address = sp.some(sp.create_contract( storage = sp.record(owner = sp.sender, master_auction_contract = sp.to_address(sp.self), asset_id = asset_id, current_bid = sp.mutez(0), min_increase = 0, highest_bidder = sp.sender, started = sp.bool(False), ended = sp.bool(False), start_time = sp.now, wait_time = 0), contract = self.english)) self.data.instances_map[asset_id] = sp.record( asset_name = asset_name, auction_type = "english", owner = sp.sender, contract_address = contract_address.open_some(), is_available = sp.bool(True))
def startAuction(self): sp.verify(sp.sender == self.data.owner, "User not Authorized") sp.verify(~self.data.in_progress, "Auction in progress") #Verify ticket/asset sent sp.verify(self.data.ticket.is_some(), "No ticket to auction") # verify now is at least start time of auction sp.verify(sp.now >= self.data.start_time, "Too early to start auction") self.data.in_progress = sp.bool(True) self.data.start_time = sp.now
def __init__(self, _admin, _swapFee, _commission): """ admin(address): address of admin account active(bool): shows whether the contract is active or not swapFee(nat): fee in bips that the change-makers take for a swap commission(nat): fee taken by the contract for facilitating the swaps in mutez userXTZDeposit(nat): amount of user xtz(mutez) currently locked in the contract swaps(map of TSwap): map of all the active swaps pairs(map of TPair): map of all the valid swap pairs supported """ self.init(admin=_admin, active=sp.bool(False), swapFee=sp.as_nat(_swapFee), commission=sp.as_nat(_commission), userXTZDeposit=sp.as_nat(0), swaps=sp.big_map(tkey=sp.TBytes, tvalue=TSwap),pairs=sp.big_map(tkey=sp.TString,tvalue=TPair))
def createEnglishAuctionInstance(self, asset_id): sp.verify((sp.sender == self.data.master_auction_contract), "only master auction contract can create instance") contract_address = sp.some(sp.create_contract( storage = sp.record(owner = sp.source, master_auction_contract = self.data.master_auction_contract, asset_id = asset_id, current_bid = sp.mutez(0), min_increase = 0, highest_bidder = self.data.master_auction_contract, started = sp.bool(False), first_bid_placed = sp.bool(False), ended = sp.bool(False), start_time = sp.now, round_time = 0), contract = self.english)) # registerInstance c = sp.contract(sp.TRecord(asset_id = sp.TNat, contract_address = sp.TAddress), self.data.master_auction_contract, entry_point = "registerInstance").open_some() sp.transfer(sp.record(asset_id = asset_id, contract_address = contract_address.open_some()), sp.mutez(0), c)
def bid(self, params): sp.verify(self.data.started) sp.verify(~self.data.ended) sp.verify(sp.amount - self.data.current_bid >= sp.mutez(self.data.min_increase)) sp.verify(~(self.data.highest_bidder == sp.sender)) # verify an externally owned account and not a contract account sp.verify(sp.sender == sp.source) # verify now is less than round_end_time = start_time + round_time sp.verify(sp.now < self.data.start_time.add_seconds(self.data.round_time)) sp.if ~self.data.first_bid_placed: self.data.first_bid_placed = sp.bool(True)
def cancelAuction(self): sp.verify(self.data.in_progress, "No Auction in progress") sp.verify(sp.sender == self.data.owner, "User not Authorized") self.data.current_price = 0 #Send back ticket to owner c = sp.contract(sp.TTicket(sp.TNat), self.data.owner, entry_point="receiveNft").open_some() sp.transfer(self.data.ticket.open_some(), sp.mutez(0), c) # endAuction self.data.ticket = sp.none self.data.in_progress = sp.bool(False)
def startAuction(self, params): sp.verify(sp.sender == self.data.owner) sp.verify(~self.data.started) sp.verify(~self.data.ended) # verify now is less than end_time = start_time + wait_time sp.verify(sp.now < self.data.start_time.add_seconds(self.data.wait_time)) self.data.started = sp.bool(True) self.data.start_time = sp.now # startedAuction c = sp.contract(sp.TNat, self.data.master_auction_contract, entry_point = "startedAuction").open_some() sp.transfer(self.data.asset_id, sp.mutez(0), c)
def cancelAuction(self, params): sp.verify(self.data.started) sp.verify(~self.data.ended) sp.verify(sp.sender == self.data.owner) #TODO # verify now more/less than end_time = start_time + wait_time sp.verify(sp.now > self.data.start_time.add_seconds(self.data.wait_time)) self.data.ended = sp.bool(True) self.data.current_price = 0 # endAuction self.endAuction(self.data.asset_id, self.data.owner)
def transfer_presigned(self, params): sp.set_type(params, sp.TRecord( from_=sp.TAddress, to_=sp.TAddress, value=sp.TNat)) params_hash = sp.blake2b(sp.pack(params)) permit_key = sp.pair(params.from_, params_hash) sp.if self.data.permit_data.permits.contains(permit_key): permit_submission_timestamp = self.data.permit_data.permits[permit_key] effective_expiry = self.getEffectiveExpiry(permit_key) # Deleting permit regardless of whether or not its expired sp.if sp.as_nat(sp.now - permit_submission_timestamp) >= effective_expiry: # Expired self.delete_permit(permit_key) sp.result(sp.bool(False))
def revealBid(self, params): sp.verify(self.data.started) sp.verify(~self.data.ended) # verify now is more than round end time = start_time + round_time but # less than start time + twice of round time sp.verify(sp.now > self.data.start_time.add_seconds(self.data.round_time)) sp.verify(sp.now < self.data.start_time.add_seconds(2 * self.data.round_time)) # bidder sends amt committed previusly minus amt locked as participation fee # if this doesn't match, possibly penalise the participant by seizing his deposit sp.verify(sp.mutez(params.value + self.data.deposit) == sp.amount) sp.verify(sp.sha256(sp.pack(params.value + self.data.deposit)) == self.data.sealed_bids[sp.sender]) sp.if ~self.data.first_revealed: self.data.first_revealed = sp.bool(True)
def acceptPrice(self, params): sp.verify(self.data.started) sp.verify(~self.data.ended) sp.verify(~(sp.sender == self.data.owner)) sp.verify(sp.amount == sp.mutez(self.data.current_price)) # verify now less than end_time = start_time + wait_time sp.verify(sp.now < self.data.start_time.add_seconds(self.data.wait_time)) sp.send(self.data.owner, sp.amount) self.data.ended = sp.bool(True) self.data.owner = sp.sender # endAuction self.endAuction(self.data.asset_id, self.data.owner)
def __init__(self, admin): self.add_flag("edo") self.init(owner=admin, current_price=0, reserve_price=0, in_progress=sp.bool(False), start_time=sp.timestamp(0), round_time=0, ticket=sp.none) self.init_type(t=sp.TRecord(owner=sp.TAddress, current_price=sp.TNat, reserve_price=sp.TNat, in_progress=sp.TBool, start_time=sp.TTimestamp, round_time=sp.TInt, ticket=sp.TOption(sp.TTicket(sp.TNat))))
def resolveAuction(self, params): sp.verify(self.data.started) sp.verify(~self.data.ended) sp.verify((sp.sender == self.data.highest_bidder) | (sp.sender == self.data.owner)) # verify now more than end_time = start_time + wait_time sp.verify(sp.now > self.data.start_time.add_seconds(self.data.wait_time)) # send current_bid to it's bidder (the current owner) sp.send(self.data.owner, self.data.current_bid) # Let current_bid remain as last price? # self.data.current_bid = sp.mutez(0) # TODO: Ensure cannot be restarted by owner self.data.ended = sp.bool(True) self.data.owner = self.data.highest_bidder # endAuction self.endAuction(self.data.asset_id, self.data.owner)
def buy(self, wallet_address): sp.set_type(wallet_address, sp.TAddress) sp.verify(self.data.in_progress) sp.verify(~(sp.sender == self.data.owner)) sp.verify(sp.amount == sp.mutez(self.data.current_price)) # verify now less than or equal to round_end_time = start_time + round_time sp.verify( sp.now <= self.data.start_time.add_seconds(self.data.round_time)) sp.send(self.data.owner, sp.amount) #Send ticket/asset to winner. They must have a "receive_ticket" entrypoint that accepts ticket of correct type c = sp.contract(sp.TTicket(sp.TNat), wallet_address, entry_point="receiveNft").open_some() sp.transfer(self.data.ticket.open_some(), sp.mutez(0), c) # endAuction self.data.ticket = sp.none self.data.in_progress = sp.bool(False)
def is_administrator(self, sender): return sp.bool(False)
def is_paused(self): return sp.bool(False)
def __init__(self, _admin, _fa12): self.init(admin=_admin, reward=sp.as_nat(15), fa12=_fa12, active=sp.bool(False), swaps=sp.big_map(tkey=sp.TBytes, tvalue=Swap))
def transfer_presigned(self, params): sp.set_type(params, sp.TRecord( from_=sp.TAddress, to_=sp.TAddress, value=sp.TNat)) params_hash = sp.blake2b(sp.pack(params)) permit_key = sp.pair(params.from_, params_hash) sp.if self.data.permit_data.permits.contains(permit_key): permit_submission_timestamp = self.data.permit_data.permits[permit_key] effective_expiry = self.getEffectiveExpiry(permit_key) # Deleting permit regardless of whether or not its expired sp.if sp.as_nat(sp.now - permit_submission_timestamp) >= effective_expiry: # Expired self.delete_permit(permit_key) sp.result(sp.bool(False)) sp.else: self.delete_permit(permit_key) sp.result(sp.bool(True)) sp.else: sp.result(sp.bool(False)) class Viewer(sp.Contract): def __init__(self, t): self.init(last = sp.none) self.init_type(sp.TRecord(last = sp.TOption(t))) @sp.entry_point def target(self, params): self.data.last = sp.some(params) if "templates" not in __name__: @sp.add_test(name = "FA12") def test():
def __init__(self, _admin): self.init(admin=_admin, active=sp.bool(False), swaps=sp.big_map(tkey=sp.TBytes, tvalue=Swap))
def contractIsActive(self): sp.verify(self.data.active == sp.bool(True))