def ChangePoolSize(self,params):

        sp.verify(sp.sender == self.data.administrator)

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

        self.data.PoolSize = params.size
 def getDataFromOro(self,params):
     sp.set_type(params.entryAddress,sp.TAddress)
     errcd = sp.record(uuid=params.uuid,cycleNumber=0)
     contract = sp.contract(sp.TRecord(uuid = sp.TNat, cycleNumber = sp.TNat),params.entryAddress).open_some()
     
     sp.if sp.amount == sp.mutez(5000):
         sp.transfer(sp.record(uuid=params.uuid,cycleNumber=self.data.cycleNumber),sp.mutez(0),contract)
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:
             from_user = self.ledger_key.make(current_from, tx.token_id)
             sp.verify(
                 self.data.ledger[from_user].tokens.contains(tx.token_id),
                 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)
             self.data.ledger[from_user].tokens.remove(tx.token_id)
             sp.if self.data.ledger.contains(to_user):
                 self.data.ledger[to_user].tokens.add(tx.token_id)
Example #4
0
 def permit(self, params):
     sp.set_type(
         params,
         sp.TList(sp.TPair(sp.TKey, sp.TPair(sp.TSignature, sp.TBytes))))
     sp.verify(~self.data.paused)
     with sp.for_('permit', params) as permit:
         params_hash = sp.snd(sp.snd(permit))
         unsigned = sp.pack(
             sp.pair(sp.pair(sp.chain_id, sp.self_address),
                     sp.pair(self.data.counter, params_hash)))
         pk_address = sp.to_address(
             sp.implicit_account(sp.hash_key(sp.fst(permit))))
         permit_key = sp.pair(pk_address, params_hash)
         permit_exists = self.data.permits.contains(permit_key)
         effective_expiry = self.getEffectiveExpiry(
             sp.pair(pk_address, params_hash))
         permit_submission_timestamp = self.data.permits[permit_key]
         sp.verify(
             ~(permit_exists &
               (sp.as_nat(sp.now - permit_submission_timestamp) <
                effective_expiry)), sp.pair("DUP_PERMIT", params_hash))
         sp.verify(
             sp.check_signature(sp.fst(permit), sp.fst(sp.snd(permit)),
                                unsigned), sp.pair("MISSIGNED", unsigned))
         self.data.permits[sp.pair(pk_address, params_hash)] = sp.now
         self.data.counter = self.data.counter + 1
Example #5
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)
     with sp.if_((self.transfer_presigned(params))):
         # Setting sender.value to from_ so call to transfer_helper will be authorized
         sender.value = params.from_
     sp.verify((sender.value == self.data.administrator) | (
         ~self.data.paused & (
             (params.from_ == sender.value) | (self.data.balances[
                 params.from_].approvals[sender.value] >= params.value))))
     self.addAddressIfNecessary(params.to_)
     sp.verify(self.data.balances[params.from_].balance >= params.value)
     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
     with sp.if_(((params.from_ != sender.value) &
                  (self.data.administrator != sender.value))):
         self.data.balances[params.from_].approvals[
             sender.value] = sp.as_nat(
                 self.data.balances[params.from_].approvals[sender.value] -
                 params.value)
 def remove_execution_request(self, removal_request):
     sp.set_type(removal_request, RemovalRequest.get_type())
     signing_payload = RemovalRequest.get_signing_payload(sp.chain_id, sp.self_address, removal_request.timelock_id)
     valid_signatures_counter = sp.local('valid_signatures_counter', sp.nat(0))
     sp.for operator_public_key in self.data.operator_public_keys:
         sp.if sp.check_signature(operator_public_key, removal_request.signatures[sp.hash_key(operator_public_key)], sp.pack(signing_payload)):
             valid_signatures_counter.value += 1
Example #7
0
 def transfer(self, params):
     sp.verify( ~self.data.paused )
     sp.set_type(params, sp.TList(Transfer.get_type()))
     sp.for transfer in params:
        Transfer.set_type_and_layout(transfer)
        from_user = Ledger_key.make(Transfer.get_from(transfer),
                                     Transfer.get_token_id(transfer))
        to_user = Ledger_key.make(Transfer.get_to(transfer),
                                   Transfer.get_token_id(transfer))
        if support_operator:
            sp.verify(
                (sp.sender == self.data.administrator) |
                (Transfer.get_from(transfer) == sp.sender) |
                self.data.ledger[from_user].operators.contains(sp.sender))
        else:
            sp.verify(
                (sp.sender == self.data.administrator) |
                (Transfer.get_from(transfer) == sp.sender))
        sp.verify(
            self.data.ledger[from_user].balance
            >= Transfer.get_amount(transfer))
        self.data.ledger[from_user].balance = sp.as_nat(
            self.data.ledger[from_user].balance - Transfer.get_amount(transfer))
        sp.if self.data.ledger.contains(to_user):
            self.data.ledger[to_user].balance += Transfer.get_amount(transfer)
Example #8
0
    def meta_transfer(self, params):
        sp.verify(sp.sender == self.data.administrator)
        sp.set_type(params, BatchMetaTransfer.get_type())

        sp.for meta_transfer in params:
            source_account_key_hash = sp.hash_key(
                meta_transfer.from_public_key)
            source_account = sp.to_address(
                sp.implicit_account(source_account_key_hash))

            sp.verify(self.data.nonces.get(
                source_account, 0)+1 == meta_transfer.nonce)

            packed_data = sp.pack(
                BatchMetaTransfer.get_signing_payload(meta_transfer))

            sp.verify(sp.check_signature(meta_transfer.from_public_key,
                                         meta_transfer.signature, packed_data), message=ErrorMessage.invalid_signature())

            self.data.nonces[source_account] = meta_transfer.nonce

            sp.for tx in meta_transfer.txs:
                from_user = LedgerKey.make(source_account, tx.token_id)
                to_user = LedgerKey.make(tx.to_, tx.token_id)
                sp.verify(tx.amount > 0,
                          message=ErrorMessage.transfer_of_zero())
                sp.verify(self.data.ledger[from_user] >= tx.amount,
                          message=ErrorMessage.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 #9
0
    def cleanup_nonce(self, params):
        # only admin can cleanup nonces
        sp.verify(sp.sender == self.data.administrator)
        sp.set_type(params, sp.TList(sp.TAddress))

        sp.for address in params:
            del self.data.nonces[address]
Example #10
0
 def _transfer(self, params):
     sp.set_type(params, 
         sp.TRecord(
             token_id = sp.TOption(sp.TNat),
             token_address = sp.TAddress,
             from_ = sp.TAddress, 
             to_ = sp.TAddress,
             amount = sp.TNat
         )
     )
     sp.if params.token_id.is_some():
         c = sp.contract(
             t = sp.TRecord(
                 token_id = sp.TNat,
                 from_ = sp.TAddress, 
                 to_ = sp.TAddress,
                 amount = sp.TNat
             ), 
             address = params.token_address,
             entry_point = "transfer"
         ).open_some()
             
         sp.transfer(
             sp.record(
                 token_id = params.token_id.open_some(),
                 from_ = params.from_,
                 to_ = params.to_,
                 amount = params.amount
             ), 
             sp.mutez(0),
             c
         )
 def set_redeem_addresses(self, redeem_addresses):
     """Allows to specify the burn adress for a  contract for a specific token, only a token administrator can do this"""
     sp.set_type(redeem_addresses, RedeemAddress.get_batch_type())
     sp.for redeem_address in redeem_addresses:
         administrator_ledger_key = LedgerKey.make(sp.sender, redeem_address.token_id)
         sp.verify(self.data.administrators.get(administrator_ledger_key, sp.nat(0))==AdministratorState.IS_ADMIN, message = AdministrableErrorMessage.NOT_ADMIN)
         self.data.token_context[redeem_address.token_id].redeem_address = redeem_address.address
Example #12
0
 def _mint(self, params):
     sp.set_type(params, 
         sp.TRecord(
             to_ = sp.TAddress,
             amount = sp.TNat,
             token_address = sp.TAddress,
             token_id = sp.TOption(sp.TNat),
             metadata=sp.TOption(sp.TMap(sp.TString, sp.TBytes))
         )
     )
     
     sp.if params.token_id.is_some():
         c = sp.contract(
             t = sp.TRecord(
                     address = sp.TAddress,
                     amount = sp.TNat,
                     token_id=sp.TNat,
                     metadata=sp.TMap(sp.TString, sp.TBytes)
                 ), 
                 address = params.token_address, 
                 entry_point = "mint"
             ).open_some()
                         
         sp.transfer(
             sp.record(
                 address = params.to_,
                 amount = params.amount,
                 token_id = params.token_id.open_some(),
                 metadata = params.metadata.open_some()
             ), 
             sp.mutez(0),
             c
         )
Example #13
0
    def vest(self, params):
        sp.set_type(
            params, 
            sp.TList(
                sp.TRecord(
                    schedule_name = sp.TString,
                    beneficiery = sp.TAddress,
                    start = sp.TTimestamp,
                    end = sp.TTimestamp,
                    cliff = sp.TTimestamp,
                    vesting_amount = sp.TNat,
                    token_address = sp.TAddress,
                    token_id = sp.TOption(sp.TNat),
                    metadata=sp.TOption(sp.TMap(sp.TString, sp.TBytes))
                )
            )
        )

        sp.for schedule in params:
            self._vest(schedule)
            self._mint(
                sp.record(
                    to_ = sp.self_address,
                    amount = schedule.vesting_amount,
                    token_id = schedule.token_id,
                    token_address = schedule.token_address,
                    metadata = schedule.metadata
                )
            )
 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
Example #15
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_
 def collect_royalties(self, to_):
     sp.set_type(to_, sp.TAddress)
     accumulated_royalties = self.data.accumulated_royalties[sp.sender]
     
     sp.send(to_, accumulated_royalties)
     
     del self.data.accumulated_royalties[sp.sender]
 def add_execution_request(self, execution_request):
     sp.set_type(execution_request, ExecutionRequest.get_type())
     signing_payload = ExecutionRequest.get_signing_payload(sp.chain_id, sp.self_address, self.data.nonce+sp.nat(1), execution_request.execution_payload)
     valid_signatures_counter = sp.local('valid_signatures_counter', sp.nat(0))
     sp.for operator_public_key in self.data.operator_public_keys:
         sp.if sp.check_signature(operator_public_key, execution_request.signatures[sp.hash_key(operator_public_key)], sp.pack(signing_payload)):
             valid_signatures_counter.value += 1
Example #18
0
 def update_operators(self, params):
     sp.set_type(
         params, 
         sp.TList(
             sp.TVariant(
                 add_operators = sp.TList(sp.TRecord(
                     owner = sp.TAddress,
                     operator = sp.TAddress
                 )),
                 remove_operators = sp.TList(sp.TRecord(
                     owner = sp.TAddress,
                     operator = sp.TAddress
                 ))
             )
         )
     )
     sp.if self.data.operable:
         sp.for update in params:
             with update.match_cases() as arg:
                 with arg.match("add_operators") as add_operators:
                     sp.for upd in add_operators:
                         sp.verify(
                             (upd.owner == sp.sender) |
                             (self.is_controller(sp.sender))
                         )
                         self.data.ledger[upd.owner].operators.add(upd.operator)
                 with arg.match("remove_operators") as remove_operators:
                     sp.for upd in remove_operators:
                         sp.verify(
                             (upd.owner == sp.sender) |
                             (self.is_controller(sp.sender))
                         )
                         self.data.ledger[upd.owner].operators.remove(upd.operator)
 def execute_timelocks(self, timelock_ids):
     sp.set_type(timelock_ids, sp.TList(sp.TNat))
     sp.for timelock_id in timelock_ids:
         timelocked_execution_request = self.data.timelocked_execution_requests[timelock_id]
         sp.verify(timelocked_execution_request.creation_timestamp.add_seconds(sp.to_int(self.data.timelock_seconds)) < sp.now)
         sp.add_operations(timelocked_execution_request.execution_request.execution_payload(sp.unit).rev())
         del self.data.timelocked_execution_requests[timelock_id]
Example #20
0
 def approve(self, params):
     sp.set_type(params, sp.TRecord(spender = sp.TAddress, value = sp.TNat).layout(("spender", "value")))
     self.addAddressIfNecessary(sp.sender)
     sp.verify(~self.is_paused(), FA12_Error.Paused)
     alreadyApproved = self.data.balances[sp.sender].approvals.get(params.spender, 0)
     sp.verify((alreadyApproved == 0) | (params.value == 0), FA12_Error.UnsafeAllowanceChange)
     self.data.balances[sp.sender].approvals[params.spender] = params.value
Example #21
0
 def updateLambda(unitParam):
     sp.set_type(unitParam, sp.TUnit)
     storeContractHandle = sp.contract(sp.TNat, box.address,
                                       'update').open_some()
     sp.result([
         sp.transfer_operation(newValue, sp.mutez(0), storeContractHandle)
     ])
    def assertTransfer(self, params):
        sp.set_type(
            params, 
            sp.TRecord(
                from_=sp.TAddress,
                to_=sp.TAddress,
                # we can assert the role of this operator
                operator=sp.TAddress
            )
        )

        sp.if ~self.data.allowlist.contains(params.from_) | self.data.blocklist.contains(params.from_):
            # controller should be able to move tokens out of a blocked address
            c = sp.contract(
                t = sp.TRecord(
                    role=sp.TNat,
                    account=sp.TAddress
                ), 
                address = sp.sender, 
                entry_point = "assertRole"
            ).open_some()
                        
            sp.transfer(
                sp.record(
                    role=TOKEN_CONTROLLER_ROLE,
                    account=params.operator
                ),
                sp.mutez(0),
                c
            )
Example #23
0
 def burn(self, params):
     sp.set_type(params, sp.TRecord(address=sp.TAddress, value=sp.TNat))
     sp.verify(sp.sender == self.data.administrator)
     sp.verify(self.data.balances[params.address].balance >= params.value)
     self.data.balances[params.address].balance = sp.as_nat(
         self.data.balances[params.address].balance - params.value)
     self.data.totalSupply = sp.as_nat(self.data.totalSupply - params.value)
    def breakGlass(self, newContracts):
        sp.set_type(
            newContracts,
            sp.TRecord(
                governorContract=sp.TAddress,
                tokenContract=sp.TAddress,
                ovenProxyContract=sp.TAddress,
                stabilityFundContract=sp.TAddress,
                developerFundContract=sp.TAddress,
            ).layout(("governorContract", ("tokenContract",
                                           ("ovenProxyContract",
                                            ("stabilityFundContract",
                                             "developerFundContract"))))))

        # Can only be called by the multisig.
        sp.verify(sp.sender == self.data.multisigAddress, "NOT_MSIG")
        targetParam = (newContracts.governorContract,
                       (newContracts.tokenContract,
                        (newContracts.ovenProxyContract,
                         (newContracts.stabilityFundContract,
                          newContracts.developerFundContract))))
        targetContractHandle = sp.contract(
            sp.TPair(
                sp.TAddress,
                sp.TPair(
                    sp.TAddress,
                    sp.TPair(sp.TAddress, sp.TPair(sp.TAddress,
                                                   sp.TAddress)))),
            self.data.targetAddress, 'updateContracts').open_some()
        sp.transfer(targetParam, sp.mutez(0), targetContractHandle)
Example #25
0
 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))
Example #26
0
 def request_tokens(self, targets):
     sp.set_type(targets, sp.TSet(sp.TAddress))
     token = sp.contract(self.token_contract.batch_transfer.get_type(),
                         self.data.token,
                         entry_point = "transfer").open_some(message = "Incompatible token interface")
     targets = targets.elements().map(lambda target: sp.record(to_ = target, token_id = 0, amount = self.data.max_amount))
     sp.transfer([sp.record(from_ = sp.to_address(sp.self), txs = targets)], sp.tez(0), token)
Example #27
0
    def ValidatorOperation(self,params):
        sp.set_type(params, sp.TRecord(address = sp.TAddress, Operation = sp.TNat))

        sp.verify(sp.sender == self.data.administrator)

        sp.if params.Operation == sp.nat(1):
            self.data.validator.add(params.address) 
Example #28
0
 def update_operators(self, params):
     sp.set_type(params, sp.TList(
         sp.TVariant(
             add_operator = self.operator_param.get_type(),
             remove_operator = self.operator_param.get_type()
         )
     ))
     if self.config.support_operator:
         sp.for update in params:
             with update.match_cases() as arg:
                 with arg.match("add_operator") as upd:
                     sp.verify(
                         (upd.owner == sp.sender) | self.is_administrator(sp.sender),
                         message = self.error_message.not_admin_or_operator()
                     )
                     self.operator_set.add(self.data.operators,
                                           upd.owner,
                                           upd.operator,
                                           upd.token_id)
                 with arg.match("remove_operator") as upd:
                     sp.verify(
                         (upd.owner == sp.sender) | self.is_administrator(sp.sender),
                         message = self.error_message.not_admin_or_operator()
                     )
                     self.operator_set.remove(self.data.operators,
                                              upd.owner,
                                              upd.operator,
                                              upd.token_id)
Example #29
0
 def addProject(self,dao,adminaddress,cat):
     sp.set_type(adminaddress, sp.TAddress)
     adminaddress=adminaddress
     sp.if self.data.addDAOdata.contains(dao):
         self.data.project_id +=1
         keyindex=self.data.project_id
         self.data.addprojectdata[keyindex] = sp.record(proowner=adminaddress,DAO=dao,serialno=keyindex,vote=0,cat=cat)
    def OracleExerciseSecurity(self,params):
        
        sp.set_type(params, sp.TRecord(price = sp.TNat, owner = sp.TAddress))
        sp.verify(sp.sender == self.data.oracle)

        sp.verify(sp.now <= self.data.Securities[params.owner].expiry)

        sp.verify(self.data.Securities[params.owner].strikePrice > params.price)

        self.data.adminAccount += self.data.Securities[params.owner].adminpayment

        Amount = sp.local('Amount',abs(self.data.Securities[params.owner].strikePrice - params.price)*10000000)
        Amount.value = Amount.value*self.data.Securities[params.owner].options

        CalAmount = sp.local('CalAmount',sp.nat(0))

        PoolAmount = sp.local('PoolAmount',self.data.Securities[params.owner].strikePrice*self.data.Securities[params.owner].options*10000000)
        PoolAmount.value = abs(PoolAmount.value - self.data.Securities[params.owner].adminpayment)
        
        sp.for i in self.data.Securities[params.owner].pool.keys():
        
            CalAmount.value += (self.data.Securities[params.owner].pool[i]*Amount.value)/(PoolAmount.value)

            self.data.LiquidityProvider[i].locked = abs(self.data.LiquidityProvider[i].locked - self.data.Securities[params.owner].pool[i])

            self.data.Securities[params.owner].pool[i] = abs(self.data.Securities[params.owner].pool[i] - (self.data.Securities[params.owner].pool[i]*Amount.value)/(PoolAmount.value) )
            
            sp.if self.data.poolSet.contains(i):
                self.data.LiquidityProvider[i].amount += self.data.Securities[params.owner].pool[i]
                self.data.totalSupply += self.data.Securities[params.owner].pool[i]