def accept_bid_for_bot(self, params):
     # Make sure that sp.sender has admin access otherwise don't proceed forward
     # Make sure that contract isn't paused
     
     sp.set_type(params.token_id, sp.TNat)
     sp.set_type(params.nft_amount, sp.TNat)
     
     # Make sure that the NFT token id is already present in the ledger
     sp.verify(self.token_id_set.contains(self.data.all_tokens, params.token_id), "TOKEN ID NOT FOUND")
     
     # NFT transfer amount should be 1
     sp.verify(params.nft_amount == 1, "NFT AMOUNT OF 1 REQUIRED")
     
     # Make sure that the caller is the owner of NFT token id else throw error 
     user = self.ledger_key.make(sp.sender, params.token_id)
     sp.verify(self.data.ledger.contains(user) == True, "NOT OWNER OF NFT TOKEN ID")
     
     # Make sure their is aleast one bid for NFT token id
     sp.verify(sp.len(self.data.bid[params.token_id]) > 0, "NO BIDDER YET")
     
 
     highest_bidder = sp.local("highest_bidder", sp.record(
             has_bid = False,
             bidder = sp.address("tz1iLVzBpCNTGz6tCBK2KHaQ8o44mmhLTBio"),
             bid_value = sp.mutez(0)
         ))
 
     # transfer the highest bidder value to the seller account    
     sp.for bidder in self.data.bid[params.token_id]:
         # store highest bidder 
         sp.if bidder.bid_value > highest_bidder.value.bid_value:
             highest_bidder.value = bidder
Exemple #2
0
 def cvrDrop(self, params):
     sp.verify(sp.sender == self.data.administrator)
     self.checkLimit(params.amount * sp.to_int(sp.len(params.addresses)))
     sp.for address in params.addresses:
         self.addAddressIfNecessary(address)
         self.data.balances[address].balance += params.amount
         self.data.circulatingSupply += params.amount
Exemple #3
0
 def closeAuction(self, param):
     sp.if ( sp.len(self.data.bids) > 0 ) :
         lenCtr = sp.local("lenctr", sp.len(self.data.ctrs))
         self.data.ctrs[lenCtr.value] = 0
         i = sp.local('i', 0)
         jc = sp.local('jc', 0)
         price_i = sp.local("price_i", 0)
         oneNat = sp.as_nat(1)
         sp.while ( (i.value < lenCtr.value) & (i.value < sp.len(self.data.bids)) ):
             price_i.value =  0
             jc.value =  i.value + oneNat
             sp.while ( jc.value < (lenCtr.value  + 1) ):
                 price_i.value = price_i.value + (self.data.bids[jc.value] * (self.data.ctrs[sp.as_nat(sp.to_int(jc.value) - 1)] - self.data.ctrs[jc.value]))
                 jc.value += 1
             self.data.prices[i.value] = price_i.value
             i.value += 1
         del self.data.ctrs[lenCtr.value]
Exemple #4
0
 def completeBetFromOro(self,params):
     sp.verify(sp.sender==self.data.oracleAddress, message="complete bet can be invoked by oro only")
     data = self.data.tempCompleteBetData[params.uuid]
     sp.verify(data.betId + data.betType < params.cycleNumber, message="Bet not yet mature")
     sp.verify(self.data.betSize.contains(data.betType),message="Invalid bet type")
     #  calculate winner
     betPool = self.data.betData[data.betType][data.betId]
     winnerIndex = (betPool.seed + abs(sp.now-sp.timestamp(0))) % sp.len(betPool.senderList) 
     # calculating winner amount 
     self.data.earnedAmount = self.data.betSize[data.betType] * sp.len(betPool.senderList) * self.data.yields[data.betType] / 10000
     #disburse Amounts
     i = sp.local('i',0)
     
     amount = self.data.earnedAmount * 10 / 100 
     self.data.adminBalance += sp.mutez(amount)
     sp.for x in betPool.senderList:
         sp.if i.value==winnerIndex:
             amount = self.data.earnedAmount * 90 / 100 + self.data.betSize[data.betType]
             sp.send(x,sp.mutez(amount))
Exemple #5
0
 def resolveAuction(self, params):
     sp.verify(self.data.started)
     sp.verify(self.data.first_revealed)
     sp.verify(~self.data.ended)
     sp.verify(self.data.sealed_bids.contains(sp.sender))
     sp.verify((self.data.revealed_count == sp.len(self.data.sealed_bids)) | (sp.now > self.data.start_time.add_seconds(2 * self.data.round_time)))
     
     sp.for bidder in self.data.sealed_bids.keys():
         sp.if (~(bidder == self.data.highest_bidder)):
             # refund participation fee to bidder
             sp.send(bidder, sp.mutez(self.data.deposit))
    def ContractWriter(self,params):

        sp.set_type(params, sp.TRecord(amount = sp.TNat))

        sp.verify(params.amount >= 1000000000)
        sp.verify(params.amount % 1000000000 == 0 )

        sp.verify(sp.len(self.data.poolSet.elements()) <= self.data.PoolSize)

        sp.if self.data.poolSet.contains(sp.sender):

            self.data.LiquidityProvider[sp.sender].amount += params.amount 
Exemple #7
0
    def putSeller(self,params):
        
        sp.verify(sp.now < self.data.validation.cycleEnd)
        sp.verify(params.amount >= 10000)
        sp.verify(params.amount %10000 == 0 )
        # Token Contract Call 
        sp.verify(sp.len(self.data.poolSet.elements()) <= 100)

        self.Lock(sp.sender,params.amount)

        sp.if self.data.poolSet.contains(sp.sender):

            self.data.contractSellar[sp.sender].amount += params.amount
 def selectTeam(self, params):
     # sp.verify(self.data.match_active.contains(params.match_id), message = "Match either does not exists or is inacitve.")
     sp.verify(sp.len(params.tokens) == 5,
               message="Only Five Tokens are Allowed.")
     sp.verify(~self.data.selected_tokens.contains(sp.sender), message = "You have already staked Cards for the match.")
     self.data.selected_tokens[sp.sender] = sp.record(tokens=sp.set())
     sp.for token_id in params.tokens:
         token_id = sp.set_type_expr(token_id, sp.TNat)
         sp.verify(self.data.ledger[sp.sender].tokens.contains(
             token_id), message="You can only select owned tokens.")
         sp.verify(~self.data.tokens_on_sale.contains(
             token_id), message="Cannot Play with a token on Sale. Unlist the token to continue.")
         self.data.tokens[token_id].inMatch = True
         self.data.selected_tokens[sp.sender].tokens.add(token_id)
Exemple #9
0
   def addStudent(self, params):
      # Assert the types of the relevant variables: SmartPy is strongly typed 
      sp.set_type(params.month, sp.TNat)
      sp.set_type(params.day, sp.TNat)
      sp.set_type(params.year, sp.TNat)
      sp.set_type(params.student, sp.TString)

      # Necessary logical verification steps before the contract can proceed
      sp.verify(params.month <= 12)
      sp.verify(params.day <= 31)
      sp.verify(sp.len(params.student) > 0) # non-empty student name

      date = self.date_to_int(params.month, params.day, params.year)
      self.checkDate(date)
      self.data.attendanceMap[date].push(params.student)
Exemple #10
0
    def test():
        c1 = HENDao([sp.address("tz1owner1"), sp.address("tz1owner2")])
        scenario = sp.test_scenario()
        scenario.h1("Test Propose Swap")
        scenario += c1
        user1 = sp.address("tz1owner1")
        user2 = sp.address("tz1owner2")

        scenario.h2("Users can call propose swap")
        c1.vote_lock(True).run(sender=user1)
        c1.vote_lock(True).run(sender=user2)
        c1.propose_swap(objkt_amount=sp.nat(1), objkt_id=sp.nat(123), xtz_per_objkt=sp.mutez(10000), creator=user2).run(sender=user1)
        c1.propose_swap(objkt_amount=sp.nat(1), objkt_id=sp.nat(456), xtz_per_objkt=sp.mutez(100), creator=user2).run(sender=user2)
        scenario.verify(c1.data.swap_proposals[0].passed == False)
        scenario.verify(c1.data.swap_proposals[1].passed == False)
        
        # Undo votes
        c1.vote_swap(0).run(sender=user1)
        scenario.verify(c1.data.swap_proposals[0].votes.contains(user1))
        c1.undo_vote_swap(0).run(sender=user1)
        scenario.verify(~c1.data.swap_proposals[0].votes.contains(user1))
        
        
        scenario.h2("All votes for a swap")
        # Vote to pass the proposals
        c1.vote_swap(0).run(sender=user1)
        c1.vote_swap(0).run(sender=user2)
        
        c1.vote_swap(1).run(sender=user1)
        c1.vote_swap(1).run(sender=user2)
        
        # Test double vote fails
        c1.vote_swap(0).run(sender=user2, valid=False)

        # Verify that num votes is valid
        scenario.verify(sp.len(c1.data.swap_proposals[0].votes) == 2)
        
        # Verify that proposal is passed
        scenario.verify(c1.data.swap_proposals[0].passed == True)
        scenario.verify(c1.data.swap_proposals[1].passed == True)
        
        # Can't undo after passed
        c1.undo_vote_swap(0).run(sender=user1, valid=False)
Exemple #11
0
 def __init__(self, initOwners):
     # Owners are locked at initialization in this iteration
     # Future iterations could have dynamic owners
     self.init(
         owners=sp.set(initOwners),
         numOwners=sp.len(initOwners),
         locked=False,
         closed=False,
         lock_votes=sp.set([], sp.TAddress),
         close_votes=sp.set([], sp.TAddress),
         total_contributed=sp.mutez(0),
         total_liquidated=sp.mutez(0),
         liquidated_ledger=sp.big_map({}, sp.TAddress, sp.TMutez),
         equity=sp.big_map({}, sp.TAddress, sp.TMutez),
         buy_proposals=sp.big_map({}, sp.TNat, sp.TRecord(votes=sp.TSet(sp.TAddress), passed=sp.TBool)),
         swap_proposals=sp.big_map({}),
         cancel_swap_proposals=sp.big_map({}, sp.TNat, sp.TRecord(votes=sp.TSet(sp.TAddress), passed=sp.TBool)),
         swap_proposal_id=0,
         # Used for collect/swap/cancel_swap
         hen_address = sp.address("KT1HbQepzV1nVGg8QVznG7z4RcHseD5kwqBn"),
         # Used for update_operators
         hen_nft_address = sp.address("KT1RJ6PbjHpwc3M5rw5s2Nbmefwbuwbdxton")
     )
Exemple #12
0
 def bid(self, params):
     l = sp.local('l', sp.len(self.data.bids))
     self.data.bids[l.value] = (params)
     self.data.agents[l.value] = sp.sender
Exemple #13
0
 def check_metadata_list(l):
     res = sp.local("toks", sp.string(""))
     sp.verify(sp.len(l) == 1)
     sp.for md in l:
         sp.verify((md.symbol == "FSCK") & (md.name == "Fishcake"))
Exemple #14
0
            self.data.locked &
            ~self.data.closed
        )

        sp.if self.data.buy_proposals.contains(swap_id):
            # If already passed, then fail
            sp.verify(~self.data.buy_proposals[swap_id].passed)
            
            self.data.buy_proposals[swap_id].votes.add(sp.sender)
        sp.else:
            votes = sp.set()
            votes.add(sp.sender)
            self.data.buy_proposals[swap_id] = sp.record(votes=votes, passed=False)

        # Everyone voted yes, execute the buy
        sp.if sp.len(self.data.buy_proposals[swap_id].votes) == sp.len(self.data.owners):
            self.hen_collect(swap_id, price)
            self.data.buy_proposals[swap_id].passed = True

    # Undo a vote for a swap
    @sp.entry_point
    def undo_vote_buy(self, swap_id):
        sp.set_type(swap_id, sp.TNat)
        
        sp.verify(
            self.data.owners.contains(sp.sender) &
            self.data.locked &
            ~self.data.closed &
            ~self.data.buy_proposals[swap_id].passed
        )
Exemple #15
0
 def sorting(self):
     sp.verify(sp.sender == self.data.owner)
     l = sp.local('l', sp.len(self.data.bids))
     j = sp.local('j', l.value - sp.nat(1))
     sp.for x in self.data.bids.items():
         self.insertSort( x.key )
Exemple #16
0
 def cardinal(self, metaset):
     if self.config.assume_consecutive_token_ids:
         return metaset
     else:
         return sp.len(metaset)
Exemple #17
0
     sp.if ~self.data.owners.contains(sp.sender):
         sp.failwith("not an owner")
     
     sp.if ~self.data.locked:
         sp.failwith("can't buy when unlocked")
     
     sp.if self.data.buyMap.contains(params.swap_id):
         self.data.buyMap[params.swap_id][sp.sender] = True
     sp.else:
         props = {}
         sp.set_type(props, sp.TMap(sp.TAddress, sp.TBool));
         props[sp.sender] = True
         self.data.buyMap[params.swap_id] = props
     
     # Everyone voted yes, execute the buy
     sp.if sp.len(self.data.buyMap[params.swap_id]) == sp.len(self.data.owners):
         self.buy_nft(params.swap_id)
 
 # Undo a vote for a swap
 @sp.entry_point
 def undo_vote_buy(self):
     pass
 
 # Propose selling an objkt at a certain price point
 @sp.entry_point
 def propose_sell(self):
     pass
 
 # Vote for a proposal to sell an objkt
 @sp.entry_point
 def vote_sell(self):
Exemple #18
0
    def Burn(self, params):
        value = params.value
        sp.verify(sp.sender == self.data.owner,
                  message="You must be the owner of the contract to burn tokens")
        owner_account = sp.record(balance=sp.nat(
            0), allowances=sp.map(tkey=sp.TAddress, tvalue=sp.TNat))
        sp.if self.data.ledger.contains(self.data.owner):
            owner_account = self.data.ledger[self.data.owner]
        sp.verify(value <= owner_account.balance,
                  message="Owner balance is too low")
        owner_account.balance = sp.as_nat(owner_account.balance - value)

        # subtract allowed amounts by value/len(allowances)
        sp.for key in owner_account.allowances.keys():
            owner_account.allowances[key] = sp.as_nat(
                owner_account.allowances[key] - value/sp.len(owner_account.allowances))

        self.data.ledger[self.data.owner] = owner_account
        self.data.totalSupply = sp.as_nat(self.data.totalSupply - value)

    @sp.entry_point
    def Approve(self, params):
        spender = params.spender
        value = params.value
        sp.if value > self.data.ledger[sp.sender].balance:
            value = self.data.ledger[sp.sender].balance
        sp.if sp.sender != spender:
            src = self.data.ledger[sp.sender]
            src.allowances[spender] = value
            self.data.ledger[sp.sender] = src