Example #1
0
 def transfer(self, params):
     sp.set_type(params, sp.TRecord(from_=sp.TAddress, to_=sp.TAddress,
                                    value=sp.TNat)).layout(("from_ as from", ("to_ as to", "value")))
     sender = sp.local("sender", sp.sender)
     sp.if (self.transfer_presigned(params)):
         # Setting sender.value to from_ so call to transfer_helper will be authorized
         sender.value = params.from_
Example #2
0
 def validateMovePiece(self, myPieces, params):
     sp.for myPiece in myPieces:
         sp.if (myPiece.y == params.start_y) & (myPiece.x == params.start_x) & (~myPiece.isKing):
             diffX = params.target_x - params.start_x
             sp.if sp.sender == self.data.player1:
                 diffY = params.target_y - params.start_y
                 self.validateXYCords(diffX, diffY)
Example #3
0
 def transfer(self, params):
     sp.verify( ~self.data.paused )
     sp.set_type(params, self.batch_transfer.get_type())
     sp.for transfer in params:
        current_from = transfer.from_
        if self.config.support_operator:
            sp.verify(
                (sp.sender == self.data.administrator) |
                (current_from == sp.sender) |
                self.operator_set.is_member(self.data.operators,
                                            current_from,
                                            sp.sender),
                message = self.error_message.not_operator())
        else:
            sp.verify(
                (sp.sender == self.data.administrator) |
                (current_from == sp.sender),
                message = self.error_message.not_owner())
        sp.for tx in transfer.txs:
             #sp.verify(tx.amount > 0, message = "TRANSFER_OF_ZERO")
             if self.config.single_asset:
                 sp.verify(tx.token_id == 0, "single-asset: token-id <> 0")
             sp.verify(self.data.tokens.contains(tx.token_id),
                       message = self.error_message.token_undefined())
             # If amount is 0 we do nothing now:
             sp.if (tx.amount > 0):
                 from_user = self.ledger_key.make(current_from, tx.token_id)
                 sp.verify(
                     (self.data.ledger[from_user].balance >= tx.amount),
                     message = self.error_message.insufficient_balance())
                 to_user = self.ledger_key.make(tx.to_, tx.token_id)
                 self.data.ledger[from_user].balance = sp.as_nat(
                     self.data.ledger[from_user].balance - tx.amount)
                 sp.if self.data.ledger.contains(to_user):
                     self.data.ledger[to_user].balance += tx.amount
Example #4
0
 def transferFrom(self, params):
   sp.verify(self.data.tokensMinted.contains(params.token_id))
   sp.verify(params.f == self.data.tokenIdToOwner[params.token_id])
   sp.verify(sp.sender == self.data.tokenApprovals[params.token_id])
   self.data.tokenHolderToID[params.f].remove(params.token_id)
   sp.if (~ (self.data.ownerToBalance.contains(params.t))):
     self.data.tokenHolderToID[params.t] = sp.set([])
Example #5
0
 def cancelAuction(self):
     sp.verify(sp.sender == self.data.owner)
     sp.if (self.data.isOpen) :
         self.data.isOpen = False
         self.data.bids = ({})
         self.data.agents = ({})
         self.data.ctrs = ({})
 def Cancellation_Guest(self):
     sp.verify(self.data.guest == sp.sender)
     sp.verify(self.data.active == True)
     sp.verify(self.data.in_house == False)
     sp.if (self.data.host == sp.test_account("VOID").address): 
         sp.send(self.data.guest, self.data.g_deposit)
         sp.send(self.data.guest, self.data.rent)
Example #7
0
 def updateMovePiece(self, myPieces, params, kingPlace):
     sp.for myPiece in myPieces:
         sp.if (myPiece.y == params.start_y) & (myPiece.x == params.start_x):
             myPiece.x = params.target_x
             myPiece.y = params.target_y
             sp.if myPiece.y == kingPlace:
                 myPiece.isKing = True
Example #8
0
 def eatPiece(self, myPiece, opPiece, params, kingPlace):
     sp.if (myPiece.y == params.start_y) & (myPiece.x == params.start_x):
         opPiece.alive = False
         myPiece.x = params.target_x
         myPiece.y = params.target_y
         self.data.status.eaten = True
         sp.if myPiece.y == kingPlace:
             myPiece.isKing = True
Example #9
0
 def feedStrike(self,params):
     sp.if (self.data.keysset.contains(sp.sender)):
         self.data.StrikePrice[80] = params.one
         self.data.StrikePrice[90] = params.two
         self.data.StrikePrice[100] = params.three
         self.data.StrikePrice[110] = params.four
         self.data.StrikePrice[120] = params.five
         self.data.xtzPrice = params.three
Example #10
0
 def dispatchRoyalties(self, params):
     sp.verify(sp.sender == self.data.administrator)
     rounded = sp.as_nat(10**10)
     muCVRtez = sp.as_nat(self.data.circulatingSupply)*rounded // params.amount + 1
     sp.for address in params.addresses:
         sp.if (self.data.balances.contains(address) & (sp.as_nat(self.data.balances[address].balance)*rounded > muCVRtez)):
             sendMuTez = sp.as_nat(self.data.balances[address].balance)*rounded // muCVRtez
             sp.send(address, sp.mutez(sendMuTez))
Example #11
0
 def openAuction(self, params):
     sp.verify(sp.sender == self.data.owner)
     sp.if (self.data.isOpen == False) :
         self.data.isOpen = True
         self.data.prices = ({})
         self.data.bids = ({})
         self.data.agents = ({})
         self.data.ctrs = params
Example #12
0
 def collect(self, params):
     sp.verify(params.objkt_amount > 0)
     self.fa2_transfer(self.data.ung, sp.sender, self.data.swaps[params.swap_id].issuer, 1, self.data.swaps[params.swap_id].ung_per_objkt * params.objkt_amount)
     self.fa2_transfer(self.data.objkt, sp.to_address(sp.self), sp.sender, self.data.swaps[params.swap_id].objkt_id, params.objkt_amount)
     self.data.swaps[params.swap_id].objkt_id = abs(self.data.swaps[params.swap_id].objkt_id - params.objkt_amount)
     
     sp.if (self.data.swaps[params.swap_id].objkt_amount == 0):
         del self.data.swaps[params.swap_id]
Example #13
0
 def transfer(self, params):
     self.validateTransfer(sp.sender, params.transferFrom, params.amount)
     self.addAddressIfNecessary(params.transferTo)
     
     # adjust token ledger
     self.data.balances[transferFrom].balance -= params.amount
     self.data.balances[transferTo].balance += params.amount
     sp.if (params.transferFrom != sp.sender) | (self.data.administrator != sp.sender):
         self.data.balances[params.transferFrom].approvals[sp.sender] -= params.amount
 def transfer(self, batch_transfers):
     sp.set_type(batch_transfers, BatchTransfer.get_type())
     sp.for transfer in batch_transfers:
        sp.for tx in transfer.txs:
             sp.if (tx.amount > sp.nat(0)):
                 from_user = LedgerKey.make(transfer.from_, tx.token_id)
                 to_user = LedgerKey.make(tx.to_, tx.token_id)
                 sp.if self.data.token_royalties.contains(tx.token_id):
                     sp.verify(sp.sender == self.data.initial_auction_house_address)
Example #15
0
 def deposit(self, params):
     sp.verify(sp.amount > sp.mutez(0), message = "Deposit too low")
     
     contractbal = sp.ediv(sp.balance, sp.tez(1))
     
     sp.if (contractbal.is_some() ):
         bal = sp.fst(contractbal.open_some())
         
         val = sp.split_tokens( sp.amount, self.data.totalTokens, bal)
         
         _natVal = sp.ediv(val, sp.tez(1))
         
     
         sp.if (_natVal.is_some() ):
             natVal = sp.fst(_natVal.open_some())
             
             self.data.withdrawBalances[params] = sp.to_int(natVal)
             self.data.totalTokens += natVal
Example #16
0
 def transfer(self, params):
     sp.verify((sp.sender == self.data.administrator) |
         (((params.fromAddr == sp.sender) |
              (self.data.balances[params.fromAddr].approvals[sp.sender] >= params.amount))))
     
     self.addAddressIfNecessary(params.toAddr)
     sp.verify(self.data.balances[params.fromAddr].balance >= params.amount)
     self.data.balances[params.fromAddr].balance -= params.amount
     self.data.balances[params.toAddr].balance += params.amount
     sp.if (params.fromAddr != sp.sender) & (self.data.administrator != sp.sender):
         self.data.balances[params.fromAddr].approvals[params.toAddr] -= params.amount
 def transfer(self, params):
     sp.verify((sp.sender == self.data.administrator) |
         (~self.data.paused &
             ((params.fro == sp.sender) |
              (self.data.balances[params.fro].approvals[sp.sender] >= params.value))))
     self.addAddressIfNecessary(params.to)
     sp.verify(self.data.balances[params.fro].balance >= params.value)
     self.data.balances[params.fro].balance = sp.as_nat(self.data.balances[params.fro].balance - params.value)
     self.data.balances[params.to].balance += params.value
     sp.if (params.fro != sp.sender) & (self.data.administrator != sp.sender):
         self.data.balances[params.fro].approvals[sp.sender] = sp.as_nat(self.data.balances[params.fro].approvals[sp.sender] - params.value)
Example #18
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))
Example #19
0
 def internal_transfer(self, from_, to_, value):
      # Add both addresses if necessary
     self.addAddressIfNecessary(from_)                 
     self.addAddressIfNecessary(to_)
     # Verify is the balance is sufficient
     sp.verify(self.data.balances[from_].balance >=value, "Insufficient Balance")
     # Update the account from which the transfer is made
     self.data.balances[from_].balance = sp.as_nat(self.data.balances[from_].balance - value)
     # Update the account to which the transfer is made
     self.data.balances[to_].balance += value
     sp.if (from_ != sp.sender):
         self.data.balances[from_].approvals[sp.sender] = sp.as_nat(self.data.balances[from_].approvals[sp.sender] - value)
 def Contract_Call(self, params):
     
     sp.if (params.my_method == "Contract_Initialisation"):
         self.Contract_Initialisation(
             rent = params.rent, 
             g_deposit = params.g_deposit, 
             h_deposit = params.h_deposit, 
             host = params.host, 
             guest = params.guest,
             nuki = params.nuki,
             # contract_id = params.id,
             cp = params.cp)
Example #21
0
 def transfer(self, params):
     sp.set_type(params, sp.TRecord(from_ = sp.TAddress, to_ = sp.TAddress, value = sp.TNat).layout(("from_ as from", ("to_ as to", "value"))))
     sp.verify((sp.sender == self.data.administrator) |
         (~self.data.paused &
             ((params.from_ == sp.sender) |
              (self.data.ledger[params.from_].approvals[sp.sender] >= params.value))))
     self.addAddressIfNecessary(params.to_)
     sp.verify(self.data.ledger[params.from_].balance >= params.value)
     self.data.ledger[params.from_].balance = sp.as_nat(self.data.ledger[params.from_].balance - params.value)
     self.data.ledger[params.to_].balance += params.value
     sp.if (params.from_ != sp.sender) & (self.data.administrator != sp.sender):
         self.data.ledger[params.from_].approvals[sp.sender] = sp.as_nat(self.data.ledger[params.from_].approvals[sp.sender] - params.value)
Example #22
0
 def transfer(self, params):
     sp.set_type(params, sp.TRecord(from_ = sp.TAddress, to_ = sp.TAddress, value = sp.TNat).layout(("from_ as from", ("to_ as to", "value"))))
     sp.verify(self.is_administrator(sp.sender) |
         (~self.is_paused() &
             ((params.from_ == sp.sender) |
              (self.data.balances[params.from_].approvals[sp.sender] >= params.value))), FA12_Error.NotAllowed)
     self.addAddressIfNecessary(params.from_)
     self.addAddressIfNecessary(params.to_)
     sp.verify(self.data.balances[params.from_].balance >= params.value, FA12_Error.InsufficientBalance)
     self.data.balances[params.from_].balance = sp.as_nat(self.data.balances[params.from_].balance - params.value)
     self.data.balances[params.to_].balance += params.value
     sp.if (params.from_ != sp.sender) & (~self.is_administrator(sp.sender)):
         self.data.balances[params.from_].approvals[sp.sender] = sp.as_nat(self.data.balances[params.from_].approvals[sp.sender] - params.value)
Example #23
0
    def ExerciseSecurity(self,params):

        sp.verify(self.data.Insurance >= sp.now)

        sp.if (sp.sender == self.data.owner) | (sp.sender == self.data.securityDelegator) :
            
            self.data.Insurance = sp.now 

            c = sp.contract(sp.TRecord(owner = sp.TAddress), self.data.oracle, entry_point = "SecuritiesExercise").open_some()

            mydata = sp.record(owner = sp.self_address)

            sp.transfer(mydata, sp.mutez(0), c)
Example #24
0
    def deposit(self, params):
        sp.verify(sp.amount > sp.mutez(0), message = "Deposit too low")
        sp.verify(sp.sender != self.data.issuer, message = "Invalid address")
        period = self.getPeriod()

        tokenBalance = sp.local('tokenBalance', 0)
        requiredCollateral = sp.local('requiredCollateral', sp.tez(0))
        expectedReturn = sp.ediv(sp.amount, self.data.schedule[period])
        coins = sp.ediv(sp.amount, sp.tez(1))
        sp.if (expectedReturn.is_some()) & (coins.is_some()):
            tokenBalance.value = sp.fst(expectedReturn.open_some())
            wholeCoins = sp.fst(coins.open_some())
            sp.verify(tokenBalance.value > wholeCoins, message = "Deposit too low")
            requiredCollateral.value = sp.tez(sp.as_nat(tokenBalance.value - wholeCoins))
    def updateRegistrationPeriod(self, params):
       self.validateUpdate(sp.sender, params.name)

       currentDuration = self.data.nameRegistry[params.name].registrationPeriod
       self.validateDuration(currentDuration + params.duration)
       cost = sp.local('cost', sp.mutez(0))
       cost.value = self.getCost(sp.amount, params.duration)

       self.data.nameRegistry[params.name].registrationPeriod = params.duration
       self.data.nameRegistry[params.name].modified = True

       # refund change
       sp.if (cost.value < (sp.amount - self.data.price)): 
           # if change is "significant"
           sp.send(sp.sender, sp.amount - cost.value)
 def realiseBet(self,params):
     # params = { bet, number, seed}
     sp.verify(sp.amount == sp.mutez(500000), message= 'Wrong amount sent')
     sp.verify(params.number > 0, message='Wrong bet number')
     sp.verify( params.number < 100,message='Wrong bet number')
     sp.verify(params.bet < self.data.bet, message='Invalid BET ID')
     sp.verify( params.bet > 0,message='Invalid BET ID')
     seed2 = params.seed % 100
     firstBetData = self.data.idToBet[params.bet]
     seed1 = firstBetData.seed % 100
     finalSeed = ( seed1 + seed2 ) % 100
     num1Diff = abs(finalSeed - firstBetData.number)
     num2Diff = abs(finalSeed - params.number)
     sp.if (num1Diff < num2Diff) :
         sp.send(firstBetData.creator,sp.tez(1))
Example #27
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]
    def transfer(self, transfers):
        """Sligthly adapted FA2 transfer method which includes pause functionality"""
        sp.set_type(transfers, Transfer.get_batch_type())
        sp.for transfer in  transfers:
           sp.for tx in transfer.txs:
                token_context = self.data.token_context[tx.token_id]
                sp.verify((transfer.from_ == sp.sender), message = FA2ErrorMessage.NOT_OWNER)
                sp.verify(self.data.token_metadata.contains(tx.token_id), message = FA2ErrorMessage.TOKEN_UNDEFINED)
                sp.verify(~token_context.is_paused, message = TZWFA2ErrorMessage.TOKEN_PAUSED)
                sp.if (tx.amount > sp.nat(0)):
                    from_user = LedgerKey.make(transfer.from_, tx.token_id)
                    to_user = LedgerKey.make(tx.to_, tx.token_id)
                    sp.verify((self.data.ledger[from_user] >= tx.amount), message = FA2ErrorMessage.INSUFFICIENT_BALANCE)
                    self.data.ledger[from_user] = sp.as_nat(self.data.ledger[from_user] - tx.amount)
                    self.data.ledger[to_user] = self.data.ledger.get(to_user, 0) + tx.amount

                    sp.if self.data.ledger[from_user] == 0:
                        del self.data.ledger[from_user]
Example #29
0
    def transfer(self, batch_transfers):
        sp.set_type(batch_transfers, BatchTransfer.get_type())
        sp.for transfer in batch_transfers:
           sp.for tx in transfer.txs:
                sp.if (tx.amount > sp.nat(0)):
                    from_user = LedgerKey.make(transfer.from_, tx.token_id)
                    to_user = LedgerKey.make(tx.to_, tx.token_id)

                    sp.verify((self.data.ledger.get(from_user,sp.nat(0)) >= tx.amount), message = FA2ErrorMessage.INSUFFICIENT_BALANCE)

                    operator_user = AllowanceKey.make(transfer.from_, sp.sender, tx.token_id)

                    sp.verify(((sp.sender == transfer.from_) | self.data.allowances.get(operator_user, False)), message=FA2ErrorMessage.NOT_OWNER)
                    self.data.ledger[from_user] = sp.as_nat(self.data.ledger[from_user] - tx.amount)
                    self.data.ledger[to_user] = self.data.ledger.get(to_user, 0) + tx.amount

                    sp.if sp.sender != transfer.from_:
                        del self.data.allowances[operator_user]
Example #30
0
    def dip_pool(self, address, amount, crypto, rate):
        # adds a swap request to the swap pool
        # it allocates available tezos from the open pool

        self.assert_crypto([crypto])

        y = sp.local('y', sp.map())
        s = sp.local('s', amount)

        # TODO: How to break out of this loop
        sp.for k in self.data.open_pool.keys():

            sp.if self.data.open_pool[k].cryptos.contains(crypto):
                # compte how much kTH pool request can provide (x)
                x = sp.local('x', self.data.open_pool[k].amount)
                sp.for j in self.data.open_pool[k].dips.keys():
                    sp.if (self.data.swap_pool[j].timelock > sp.now) | self.data.swap_pool[j].swapped:
                        x.value = x.value - self.data.open_pool[k].dips[j].amount