def revoke(self, amount):
        sp.set_type(amount, sp.TNat)

        # Only callable by the governor
        sp.verify(sp.sender == self.data.governorAddress, "NOT_GOVERNOR")

        handle = sp.contract(
            sp.TRecord(from_=sp.TAddress, to_=sp.TAddress,
                       value=sp.TNat).layout(
                           ("from_ as from", ("to_ as to", "value"))),
            self.data.rewardTokenAddress, "transfer").open_some()
        arg = sp.record(from_=sp.self_address,
                        to_=self.data.revokeAddress,
                        value=amount)
        sp.transfer(arg, sp.mutez(0), handle)
Esempio n. 2
0
 def is_operator(self, params):
     sp.set_type(params, self.operator_param.is_operator_request_type())
     if self.config.support_operator:
         res = self.operator_set.is_member(self.data.operators,
                                           params.operator.owner,
                                           params.operator.operator)
         returned = sp.record(
             operator = params.operator,
             is_operator = res)
         sp.transfer(returned, sp.mutez(0), params.callback)
     else:
         returned = sp.record(
             operator = params.operator,
             is_operator = False)
         sp.transfer(returned, sp.mutez(0), params.callback)
Esempio n. 3
0
    def configureAuction(self, params):
        sp.verify(sp.sender == self.data.owner)
        sp.verify(~self.data.started)
        sp.verify(~self.data.ended)

        self.data.current_price = params.opening_price
        self.data.reserve_price = params.reserve_price
        self.data.start_time = params.start_time
        self.data.round_time = params.round_time

        # configureInstance
        c = sp.contract(sp.TNat,
                        self.data.master_auction_contract,
                        entry_point="configureInstance").open_some()
        sp.transfer(self.data.asset_id, sp.mutez(0), c)
Esempio n. 4
0
 def mint_hDAO(self, params):
     
     c = sp.contract(
         sp.TList(
         sp.TRecord(
         to_=sp.TAddress,
         amount=sp.TNat
         )), 
         self.data.hdao, 
         entry_point = "hDAO_batch").open_some()
         
     sp.transfer(
         params, 
         sp.mutez(0), 
         c)
Esempio n. 5
0
 def redeem(self, _hashedSecret, _secret):
     self.checkState(_hashedSecret, State.Initiated)
     self.isRedeemable(_hashedSecret, _secret)
     c = sp.contract(sp.TRecord(from_=sp.TAddress,
                                to_=sp.TAddress,
                                value=sp.TNat).layout(
                                    ("from_ as from", ("to_ as to",
                                                       "value"))),
                     self.data.fa12,
                     entry_point="transfer").open_some()
     transferData = sp.record(
         from_=sp.self_address,
         to_=self.data.swaps[_hashedSecret].participant,
         value=self.data.swaps[_hashedSecret].value)
     sp.transfer(transferData, sp.mutez(0), c)
     del self.data.swaps[_hashedSecret]
Esempio n. 6
0
    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 round_end_time = start_time + round_time
        sp.verify(
            sp.now < self.data.start_time.add_seconds(self.data.round_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)
Esempio n. 7
0
    def PurchaseSecurity(self,params):
        sp.set_type(params, sp.TRecord(order = sp.TNat , duration = sp.TNat, securityDelegator = sp.TAddress))

        duration = sp.set([1,7,14])        

        sp.verify(sp.sender == self.data.owner)
        sp.verify(duration.contains(params.duration))

        self.data.Insurance =  sp.now.add_days(sp.to_int(params.duration))
        self.data.securityDelegator = params.securityDelegator
        
        c = sp.contract(sp.TRecord(xtz = sp.TNat, token = sp.TNat, order = sp.TNat , duration = sp.TNat , spender = sp.TAddress), self.data.oracle, entry_point = "SecuritiesPurchase").open_some()

        mydata = sp.record(xtz = self.data.xtz, token = self.data.token, order = params.order , duration = params.duration, spender = self.data.owner)

        sp.transfer(mydata, sp.mutez(0), c)
    def SecuritiesPurchase(self,params):

        sp.set_type(params, sp.TRecord(xtz = sp.TNat, token = sp.TNat, order = sp.TNat , duration = sp.TNat , spender = sp.TAddress))

        duration = sp.set([1,7,14])

        sp.verify(params.xtz * self.data.USDPrice * 1000 >= params.token * 150)

        sp.verify(params.order * self.data.USDPrice*1000000000 >= params.token * 150 )

        sp.verify(duration.contains(params.duration))

        c = sp.contract(sp.TRecord(price = sp.TNat, duration = sp.TNat, order = sp.TNat, owner = sp.TAddress, spender = sp.TAddress ), self.data.securities, entry_point = "OraclePurchaseSecurity").open_some()

        mydata = sp.record(price = self.data.USDPrice,duration = params.duration , order = params.order,  owner = sp.sender , spender = params.spender)

        sp.transfer(mydata, sp.mutez(0), c)
Esempio n. 9
0
    def redeem(self):
        sp.verify(~self.data.receivers.contains(sp.sender))

        token = sp.contract(self.token.batch_transfer.get_type(),
                            self.data.token,
                            entry_point="transfer").open_some()
        sp.transfer([
            sp.record(from_=sp.self_address,
                      txs=[
                          sp.record(to_=sp.sender,
                                    token_id=0,
                                    amount=self.data.reward)
                      ])
        ], sp.tez(0), token)

        self.data.distributed += self.data.reward
        self.data.receivers.add(sp.sender)
class CheckSig(sp.Contract):
    @sp.entry_point
    def run(self, params):
        sp.set_type(params.x, sp.TNat)
        sp.if params.x > 9:
            sp.transfer(True, sp.mutez(0), params.k)
        sp.else:
            sp.transfer(False, sp.mutez(0), params.k)
Esempio n. 11
0
    def processDataRequest(self, params):
        sp.verify(self.data.registeredPairs.contains(params.currencyPair), message = "Unregistered currency pair")
        sp.verify(sp.amount > self.data.feedQueryCost[params.currencyPair], message = "Incorrect query fee")
        sp.verify(self.data.feed.contains(params.currencyPair), message = "Data not available")

        record = self.data.feed[params.currencyPair]

        sp.transfer(
            sp.record(
                currencyPair = params.currencyPair,
                value = record.value,
                precision = record.precision,
                timestamp = record.timestamp,
                source = record.source
                ),
            sp.tez(0),
            params.callback)
 def mint(self, token_id, royalty, metadata):
     sp.set_type(token_id, sp.TNat)
     sp.set_type(royalty, sp.TOption(Royalty.get_type()))
     sp.set_type(metadata, sp.TBytes)
     
     sp.verify(sp.sender == self.data.minter, message = FA2ErrorMessage.ONLY_MINTER_CAN_MINT)
     sp.verify(~self.data.total_supply.contains(token_id), message = FA2ErrorMessage.TOKEN_ALREADY_EXISTS)
     
     minter_ledger_key = LedgerKey.make(self.data.minter, token_id)
     self.data.total_supply[token_id] = 1
     self.data.ledger[minter_ledger_key] = 1
     self.data.token_metadata[token_id] = sp.record(token_id = token_id, token_info = {"" : metadata})
     
     sp.if royalty.is_some():
         self.data.token_royalties[token_id] = sp.unit
         register_token = sp.contract(sp.TRecord(token_id=sp.TNat, royalty=Royalty.get_type()), self.data.initial_auction_house_address, entry_point = "register_token").open_some()
         sp.transfer(sp.record(token_id = token_id, royalty = royalty.open_some()), sp.tez(0), register_token)
Esempio n. 13
0
    def OpenLoan(self,params):
        sp.set_type(params, sp.TRecord(amount = sp.TNat, loan = sp.TNat))

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

        sp.verify(sp.mutez(params.amount) == sp.amount)
        
        sp.verify(self.data.Closed)

        self.data.xtz += params.amount 
        self.data.token += params.loan 

        self.data.Closed = False
        c = sp.contract(sp.TRecord(loan = sp.TNat), self.data.oracle, entry_point = "MintToken").open_some()

        mydata = sp.record(loan = params.loan)

        sp.transfer(mydata, sp.mutez(0), c)
Esempio n. 14
0
    def ExitContractWriter(self,params):
        
        sp.verify(self.data.poolSet.contains(sp.sender))
        
        self.data.poolSet.remove(sp.sender)

        # Reduce Total Supply
        self.data.totalSupply = abs(self.data.totalSupply-self.data.LiquidityProvider[sp.sender].amount)

        c = sp.contract(sp.TRecord(from_ = sp.TAddress, to_ = sp.TAddress , value = sp.TNat), self.data.token, entry_point = "transfer").open_some()

        mydata = sp.record(from_ = sp.self_address,to_ = sp.sender, value = self.data.LiquidityProvider[sp.sender].premium + self.data.LiquidityProvider[sp.sender].amount)

        sp.transfer(mydata, sp.mutez(0), c)


        self.data.LiquidityProvider[sp.sender].premium = 0 
        self.data.LiquidityProvider[sp.sender].amount = 0 
Esempio n. 15
0
    def GetputSeller(self,params):
        
        price = sp.set([80,90,100,110,120])
        duration = sp.set([7,14,21])

        sp.verify(params.Options>0)
        sp.verify(price.contains(params.Ratio))
        sp.verify(duration.contains(params.expire))

        data = sp.record(Options=params.Options,Ratio=params.Ratio,StrikePrice=self.data.StrikePrice[params.Ratio],
        address=params.address,expire=params.expire,xtzPrice=self.data.xtzPrice)

        contract = sp.contract(sp.TRecord(Options=sp.TNat,Ratio=sp.TInt,StrikePrice=sp.TNat,address = sp.TAddress,
        expire = sp.TInt,xtzPrice=sp.TNat),sp.sender,entry_point = "OrOputBuyer").open_some()

        
        sp.if sp.amount == sp.mutez(10):
            sp.transfer(data,sp.mutez(0),contract)
Esempio n. 16
0
def assert_token_admin(token, account):
    c = sp.contract(
        t = sp.TRecord(
            account=sp.TAddress,
            role=sp.TNat
        ), 
        address = token, 
        entry_point = "assertRole"
    ).open_some()
    
    sp.transfer(
        sp.record(
            role=TOKEN_ADMIN_ROLE,
            account=account
        ),
        sp.mutez(0),
        c
    )
Esempio n. 17
0
    def get(self, requestPair):
        sp.set_type(requestPair, sp.TPair(sp.TString, sp.TContract(sp.TPair(sp.TString, sp.TPair(sp.TTimestamp, sp.TNat)))))

        # Destructure the arguments.
        requestedAsset = sp.compute(sp.fst(requestPair))
        callback = sp.compute(sp.snd(requestPair))

        # Verify this normalizer has data for the requested asset.
        sp.verify(
            self.data.assetMap.contains(requestedAsset),
            message="bad request"
        )

        # Callback with the requested data.
        assetData = self.data.assetMap[requestedAsset]
        normalizedPrice = assetData.computedPrice
        lastUpdateTime = assetData.lastUpdateTime
        callbackParam = (requestedAsset, (lastUpdateTime, normalizedPrice))
        sp.transfer(callbackParam, sp.mutez(0), callback)
    def getAddressInfoFromRegistry(self, params):
        # type of response
        tkResponse = sp.TRecord(
            name = sp.TString,
            info = sp.TRecord(
                name = sp.TString, 
                owner = sp.TAddress,
                resolver = sp.TAddress, 
                registeredAt = sp.TTimestamp,
                registrationPeriod = sp.TInt,
                modified = sp.TBool))
        # callback handle for the receiver entrypoint
        kResponse = sp.contract(tkResponse, sp.to_address(sp.self), entry_point = "recvAddressInfo").open_some()
        
        # type of request
        tkRequest = sp.TRecord(addr = sp.TAddress, k = sp.TContract(tkResponse))
        kRequest = sp.contract(tkRequest, self.data.registry, entry_point = "sendAddressInfo").open_some()

        sp.transfer(sp.record(addr = params.addr, k = kResponse), sp.mutez(0), kRequest)
Esempio n. 19
0
    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)
Esempio n. 20
0
    def putBuyer(self,params):

        sp.verify(sp.now < self.data.validation.cycleEnd)
        sp.verify(~ self.data.contractBuyer.contains(sp.sender))
        
        price = sp.set([80,90,100,110,120])
        duration = sp.set([7,14,21])
        
        sp.verify(price.contains(params.StrikePrice))
        sp.verify(params.Options>0)
        sp.verify(duration.contains(sp.to_int(params.expire)))
        
        sp.verify(self.data.validation.cycleEnd > sp.now.add_days(sp.to_int(params.expire)))

        data = sp.record(Options=abs(params.Options),Ratio=sp.to_int(params.StrikePrice),address=sp.sender,expire=sp.to_int(params.expire))
        
        contract = sp.contract(sp.TRecord(Options = sp.TNat,address = sp.TAddress,Ratio = sp.TInt,expire=sp.TInt),self.data.Oracle,entry_point = "GetputSeller").open_some()
        #Oracle Call

        sp.transfer(data, sp.mutez(10), contract)
Esempio n. 21
0
 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)
Esempio n. 22
0
    def TokenToTez(self,
                   buyer: sp.TAddress,
                   recipient: sp.TAddress,
                   tokensIn: sp.TNat,
                   minTezOut: sp.TNat):
        this = self.data.address

        sp.verify(tokensIn > 0, message="Wrong tokensIn")
        sp.verify(minTezOut > 0, message="Wrong minTezOut")

        fee = tokensIn / self.data.feeRate  # TODO: ????
        newTokenPool = sp.local(
            "newTokenPool", self.data.tokenPool).value + tokensIn
        tempTokenPool = abs(newTokenPool - fee)
        newTezPool = sp.fst(sp.ediv(sp.local(
            "newTezPool", self.data.invariant).value, tempTokenPool).open_some())
        tezOut = abs(
            sp.local("tezOut", self.data.tokenPool).value - newTezPool)

        sp.verify(tezOut >= minTezOut, message="Wrong minTezOut")
        sp.verify(sp.mutez(tezOut) <= self.data.tezPool, message="Wrong tezPool")

        self.data.tezPool = newTezPool
        self.data.tokenPool = newTokenPool
        self.data.invariant = sp.mutez(newTezPool * newTokenPool)

        token_contract = sp.contract(
            sp.TRecord(account_from=sp.TAddress,
                       destination=sp.TAddress,
                       value=sp.TNat),
            address=self.data.tokenAddress,
            entry_point="Transfer"
        ).open_some()


        sp.transfer(sp.record(account_from=buyer,
                              destination=this,
                              value=tokensIn),
                    sp.mutez(0),
                    token_contract)
        sp.send(recipient, sp.mutez(tezOut),)
Esempio n. 23
0
    def buy_powerup(self, powerup):

        # modify data_type to also hold another variable called cryptobot_address.
        data_type = sp.TRecord(powerup=sp.TString, cryptobot_contract=sp.TContract(
            sp.TRecord(power=sp.TString, duration=sp.TNat)))

        market_contract = sp.contract(
            data_type, self.data.market_address).open_some()
        self.data.mutez_points -= sp.mutez(3000)

        # define self_contract -
        # 1. Accepts a record with two variables - power(string), duration(nat)
        # 2. Points to the Cryptobot( use sp.to_address() )
        # 3. Specifies receive_powerup entry point
        self_contract = sp.contract(sp.TRecord(power=sp.TString, duration=sp.TNat), sp.to_address(
            sp.self), "receive_powerup").open_some()

        # modify data_to_be_sent to also hold cryptobot_contract which is assigned self_contract
        data_to_be_sent = sp.record(
            powerup=powerup, cryptobot_contract=self_contract)
        sp.transfer(data_to_be_sent, sp.mutez(0), market_contract)
Esempio n. 24
0
    def sendQuery(self, params):
        rtype = sp.TRecord(
                currencyPair = sp.TString,
                value = sp.TNat,
                precision = sp.TNat,
                timestamp = sp.TTimestamp,
                source = sp.TString)
        ptype = sp.TRecord(
            currencyPair = sp.TString,
            callback = sp.TContract(rtype)
        )

        getHandle = sp.contract(ptype, self.data.oracle, entry_point = "processDataRequest").open_some()

        args = sp.record(
            currencyPair = params.currencyPair,
            callback = sp.contract(rtype,
                            sp.to_address(sp.self),
                            entry_point = "receiveData").open_some()
            )
        sp.transfer(args, sp.tez(1000), getHandle)
    def giveRewardAllowance(self, amount):
        sp.set_type(amount, sp.TNat)

        # Only callable by the governor
        sp.verify(sp.sender == self.data.governorAddress, "NOT_GOVERNOR")

        # Reset to zero, then reset to the given amount.
        approvalHandle = sp.contract(
            sp.TRecord(spender=sp.TAddress, value=sp.TNat).layout(
                ("spender", "value")), self.data.rewardTokenAddress,
            "approve").open_some()

        zeroApprovalArg = sp.record(spender=self.data.farmAddress,
                                    value=sp.nat(0))
        sp.transfer(zeroApprovalArg, sp.mutez(0), approvalHandle)

        newAmountApprovalArg = sp.record(
            spender=self.data.farmAddress,
            value=amount,
        )
        sp.transfer(newAmountApprovalArg, sp.mutez(0), approvalHandle)
 def transfer(self, params):
     # controller should be able to move tokens out of a blocked address
     c = sp.contract(
         t = sp.TRecord(
             from_=sp.TAddress,
             to_=sp.TAddress,
             operator=sp.TAddress
         ), 
         address = self.data.gtm, 
         entry_point = "assertTransfer"
     ).open_some()
                 
     sp.transfer(
         sp.record(
             from_=params.from_,
             to_=params.to_,
             operator=sp.sender
         ),
         sp.mutez(0),
         c
     )
Esempio n. 27
0
 def mint(self, params):
     sp.set_type(params, sp.TRecord(address = sp.TAddress, value = sp.TNat))
     sp.verify(sp.sender == self.data.administrator)
     self.addAddressIfNecessary(params.address)
     self.data.balances[params.address].balance += params.value
     self.data.totalSupply += params.value
     sp.transfer(
         sp.record(
             address = params.address, 
             value = params.value
         ), 
         sp.tez(0), 
         sp.contract(
             sp.TRecord(
                 address = sp.TAddress, 
                 value = sp.TNat
             ),
            self.data.administrator, 
             "addTokens"
         ).open_some()
     )
Esempio n. 28
0
 def gaintoken(self,daoid):
     mem_address=sp.sender
     sp.verify(self.data.addDAOdata[daoid].disputestatus==1)
     sp.verify(self.data.addDAOdata[daoid].rewardstatus==1)
     sp.verify(self.data.addmemberdata[mem_address].DAO== daoid)
     sp.transfer(
             sp.record(
                 address= sp.sender,
                 value = self.data.addDAOdata[daoid].contri
             ), 
             sp.tez(0),
             sp.contract(
                 sp.TRecord(
                   address= sp.TAddress,
                   value = sp.TNat
                 ), 
                 self.data.projecttoken, 
                 "mint"
             ).open_some()
         )
     del self.data.addmemberdata[mem_address]
Esempio n. 29
0
 def curate(self, params):
     self.fa2_transfer(self.data.hdao, sp.sender, self.data.curate, 0, params.hDAO_amount)
     
     c = sp.contract(
         sp.TRecord(
             hDAO_amount = sp.TNat,
             objkt_id = sp.TNat,
             issuer = sp.TAddress
             ),
             self.data.curate,
             entry_point = 'curate'
         ).open_some()
     
     sp.transfer(
         sp.record(
             hDAO_amount = params.hDAO_amount,
             objkt_id = params.objkt_id,
             issuer = self.data.royalties[params.objkt_id].issuer
             ),
             sp.mutez(0),
             c
         )
Esempio n. 30
0
 def cancel_request(self, client_request_id):
     # We do not want to check active here (it would be bad for the client).
     # sp.sender needs to be validated; this process is done through the use of the reverse_request_key.
     reverse_request_key = sp.record(client=sp.sender,
                                     client_request_id=client_request_id)
     request_id = sp.local(
         'request_id',
         self.data.reverse_requests[reverse_request_key]).value
     request = sp.local('request', self.data.requests[request_id]).value
     sp.verify(request.timeout <= sp.now)
     token = sp.contract(self.token_contract.batch_transfer.get_type(),
                         self.data.token,
                         entry_point="transfer").open_some()
     sp.transfer([
         sp.record(from_=sp.to_address(sp.self),
                   txs=[
                       sp.record(to_=request.client,
                                 token_id=0,
                                 amount=request.amount)
                   ])
     ], sp.tez(0), token)
     del self.data.requests[request_id]