Example #1
0
    def default(self, params):
        sp.verify(sp.amount == LEADERSHIP_PAYMENT_AMOUNT)
        sp.verify(self.data.leadership_start_timestamp.add_seconds(sp.to_int(self.data.countdown_milliseconds/1000)) > sp.now)
        self.data.leader = sp.sender
        self.data.leadership_start_timestamp = sp.now
        
        balance_weight_tenthtez = sp.fst(sp.ediv(sp.balance-INITIAL_BALANCE,sp.mutez(1)).open_some())/sp.nat(100000) # mutez becomes tenth of a tez

        countdown_drop_milliseconds = (COUNTDOWN_DROP_FACTOR+balance_weight_tenthtez)/balance_weight_tenthtez
        sp.if self.data.countdown_milliseconds - countdown_drop_milliseconds > sp.to_int(MINIMAL_COUNT_DOWN_MILLISECONDS):
            self.data.countdown_milliseconds = sp.as_nat(self.data.countdown_milliseconds - countdown_drop_milliseconds)
Example #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
 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 #4
0
 def getDataMint(self,params):
 
     data = sp.record(price=sp.to_int(self.data.xtzPrice),address=params.address,amount=params.amount)
     
     contract = sp.contract(sp.TRecord( price = sp.TInt,address = sp.TAddress, amount = sp.TInt),sp.sender,entry_point = "OrOMint").open_some()
     
     sp.if sp.amount == sp.mutez(10):
         sp.transfer(data,sp.mutez(0),contract)
Example #5
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)
Example #6
0
 def sellShort(self, params):
     sp.set_type(params, sp.TRecord(quantity = sp.TNat, price_buy = sp.TNat, price_sell = sp.TNat))
     sp.verify(~self.data.result.is_some())
     sp.verify(self.data.sharesShort[sp.sender][params.price_buy] >= sp.to_int(params.quantity))
     sp.verify(params.price_sell <= 1000000)
     
     matchPrice = 1000000 - params.price_sell
     confirmed = sp.local('confirmed', False)
     index = sp.local('index', -1)
     sp.for i in self.data.sellLongOrders.keys():
         order = self.data.orders[i]
         sp.if ~confirmed.value & (order.price == sp.as_nat(matchPrice)) & (order.quantity == params.quantity) & ~(order.creator == sp.sender):
                 confirmed.value = True
                 index.value = i
Example #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)
Example #8
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
    def OraclePurchaseSecurity(self,params):
        
        sp.set_type(params, sp.TRecord(price = sp.TNat, duration = sp.TNat, order = sp.TNat, owner = sp.TAddress, spender = sp.TAddress ))

        sp.verify(sp.sender == self.data.oracle)
        sp.verify(~self.data.Securities.contains(params.owner))

        Deadline = sp.now.add_days(sp.to_int(params.duration))

        self.data.Securities[params.owner] = sp.record(strikePrice = params.price, pool = sp.map(),
        adminpayment = sp.nat(0), options = params.order, expiry = Deadline
        )

        TotalAmount = sp.local('TotalAmount',params.price*params.order*abs(10000000))
        CollateralValue = sp.local('CollateralValue',sp.nat(0))

        self.data.InterestRate[1] = sp.nat(1)
        self.data.InterestRate[7] = sp.nat(2)
        self.data.InterestRate[14] = sp.nat(4)
        

        PremiumTotal = sp.local('PremiumTotal',params.price*params.order*self.data.InterestRate[params.duration]*abs(100000))
        PremiumLiquidity = sp.local('PremiumLiquidity',sp.nat(0))

        del self.data.InterestRate[1]
        del self.data.InterestRate[7]
        del self.data.InterestRate[14]

        self.data.adminAccount += params.price*params.order*100000
    
        sp.verify(self.data.totalSupply >= TotalAmount.value)

        sp.for i in self.data.poolSet.elements():

            self.data.Securities[params.owner].pool[i] = (self.data.LiquidityProvider[i].amount*TotalAmount.value)/(self.data.totalSupply)
            
            self.data.LiquidityProvider[i].locked += (self.data.LiquidityProvider[i].amount*TotalAmount.value)/(self.data.totalSupply)

            CollateralValue.value += (self.data.LiquidityProvider[i].amount*TotalAmount.value)/(self.data.totalSupply)

            self.data.LiquidityProvider[i].premium += (self.data.LiquidityProvider[i].amount*PremiumTotal.value)/(self.data.totalSupply)
            PremiumLiquidity.value += (self.data.LiquidityProvider[i].amount*PremiumTotal.value)/(self.data.totalSupply)

            self.data.LiquidityProvider[i].amount = abs(self.data.LiquidityProvider[i].amount - (self.data.LiquidityProvider[i].amount*TotalAmount.value)/(self.data.totalSupply) )
Example #10
0
    def insertSort(self, param):
        self.data.isOpen = False
        jx = sp.local('jx', param)
        jint = sp.local('jint', sp.to_int(param))

        def swap(i):
            tempBid = sp.local("tempBid", self.data.bids[nat(i)])
            tempAgent = sp.local("tempAgent", self.data.agents[nat(i)])
            self.data.bids[nat(i)] = self.data.bids[nat(i - 1)]
            self.data.agents[nat(i)] = self.data.agents[nat(i - 1)]
            self.data.bids[nat(i - 1)] = tempBid.value
            self.data.agents[nat(i - 1)] = tempAgent.value

        def nat(x):
            return sp.as_nat(x)

        sp.while ((nat(jint.value) > 0) & (self.data.bids[nat(jint.value)] >= self.data.bids[nat(jint.value - 1)]) ) :
            swap(jint.value)
            jint.value -= 1
Example #11
0
 def getResponseFromHarbinger(self,response):
     sp.verify(self.data.admin.contains(sp.source) , "Un-authorized")
     
     sp.set_type(response , sp.TPair(sp.TString , sp.TPair(sp.TTimestamp , sp.TNat)))
     currentPrice=sp.local("currentPrice",sp.int(0))
     currentPrice = sp.to_int(sp.fst(sp.ediv(sp.snd(sp.snd(response)) , sp.nat(1000)).open_some()))
     
     currentCycle = sp.local("currentCycle" ,sp.int(0))
     currentCycle = sp.fst(sp.ediv(sp.level,self.data.blocksPerCycle).open_some())
     
     sp.verify(~self.data.cycleData.contains(currentCycle+self.data.stakingPeriod))
     
     
     
     rangeMap = sp.local("rangeMap" , sp.map(tkey = sp.TPair(sp.TInt, sp.TInt) , tvalue = sp.TMutez))
     
     iterator = sp.local("iterator" , sp.int(0))
     
     sp.while iterator.value<=self.data.rangeEnd:
         sp.if iterator.value+self.data.rangeStep<=self.data.rangeEnd:
             rangeMap.value[sp.pair(iterator.value,iterator.value+self.data.rangeStep)] =sp.mutez(0)
             rangeMap.value[(sp.int(-1)*(iterator.value+self.data.rangeStep),sp.int(-1)*iterator.value)] =sp.mutez(0)
Example #12
0
    def create_certificate(self, params):

        # 0) verify that lock period is not more than 2 years
        sp.verify(params.months < 25)

        # 1) get tez value
        mintAmount = sp.split_tokens(sp.amount, 100, 100)
        coins = sp.ediv(mintAmount, sp.mutez(1) )
        principal = sp.to_int( sp.fst(coins.open_some()) )


        # 2) get timestamp
        end_time = sp.now.add_days(params.months*30)


        # 3) calculate payout
        w = sp.local('w', 1)
        y = sp.local('y', 0)
        sp.while y.value < params.months:

            w.value = 10033*w.value
            y.value = y.value + 1
Example #13
0
 def toInt(self):
     sp.verify(
         sp.to_int(self.data.fr) ==
         35115637951021136697019058358166656987035571271296265805438287419849817743725,
         message="Failed to cast field element Fr to Int")
Example #14
0
 def getPeriod(self):
     y = sp.local('y', self.data.periods)
     sp.if sp.now > self.data.start.add_seconds(sp.to_int(self.data.duration)):
         y.value = self.data.periods
Example #15
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]
Example #16
0
 def withdraw(self, params):
     sp.verify(self.data.leader == sp.sender)
     sp.verify(self.data.leadership_start_timestamp.add_seconds(sp.to_int(self.data.countdown_milliseconds/1000)) < sp.now)
     sp.send(sp.sender, sp.balance)
Example #17
0
        scaled_up_intrest = w.value

        u = sp.local('u', 1)
        v = sp.local('v', 0)
        sp.while v.value < params.months:

            u.value = 10000*u.value
            v.value = v.value + 1

        scale_factor = u.value

        scaled_stake = principal*(scaled_up_intrest - scale_factor)

        x = sp.as_nat(scaled_stake)/sp.as_nat(scale_factor)
        stake = sp.to_int(x)


        # 3) get highest token_index
        token_id = self.data.highestTokenIndex


        # 4) mint certificate
        sp.verify(~ self.token_id_set.contains(self.data.all_tokens,
                                               token_id),
                  "NFT-asset: cannot mint twice same token")

        user = self.ledger_key.make(sp.sender, token_id)
        self.token_id_set.add(self.data.all_tokens, token_id)

        sp.if self.data.ledger.contains(user):
Example #18
0
    def setManager(self, params):
        sp.verify(sp.sender == self.data.administrator)
        self.addAddressIfNecessary(params)
        self.data.saleManager = params

    @sp.entry_point
    def getManager(self, params):
        sp.transfer(self.data.saleManager, sp.tez(0), sp.contract(sp.TAddress, params.target).open_some())

    @sp.entry_point
    def sale(self, params):
        sp.verify(self.data.saleStatus)
        sp.if self.data.balances.contains(sp.sender):
            sp.verify(~ self.data.balances[sp.sender].lock)
        natMutez = sp.fst(sp.ediv(sp.amount, sp.mutez(1)).open_some())
        intMutez = sp.to_int(natMutez)
        self.mintSale(sp.sender, intMutez * self.data.ratio)

    @sp.entry_point
    def offchainSale(self, params):
        sp.verify(sp.sender == self.data.saleManager)
        sp.if self.data.balances.contains(params.address):
            sp.verify(~ self.data.balances[params.address].lock)
        self.mintSale(params.address, params.amount)

    def mintSale(self, address, nbMutoken):
        sp.verify(self.data.soldToken + nbMutoken <= self.data.saleLimit)
        self.addAddressIfNecessary(address)
        self.data.balances[address].balance += nbMutoken
        self.data.circulatingSupply += nbMutoken
        self.data.soldToken += nbMutoken
Example #19
0
 def __init__(self, value):
     self.init(storedValue=sp.to_int(value))
Example #20
0
    def withdraw(self):
        sp.verify(self.data.balances.contains(sp.sender))
        sp.send(sp.sender,sp.tez(1))

        self.data.balances[sp.sender].balance = sp.to_int(self.data.balances[sp.sender].balance % 10000)
Example #21
0
     sp.verify(params.price_sell <= 1000000)
     
     matchPrice = 1000000 - params.price_sell
     confirmed = sp.local('confirmed', False)
     index = sp.local('index', -1)
     sp.for i in self.data.sellLongOrders.keys():
         order = self.data.orders[i]
         sp.if ~confirmed.value & (order.price == sp.as_nat(matchPrice)) & (order.quantity == params.quantity) & ~(order.creator == sp.sender):
                 confirmed.value = True
                 index.value = i
     
     sp.if confirmed.value:
         order = self.data.orders[index.value]
         sp.send(order.creator, sp.mutez((order.price * order.quantity) // 10))
         sp.send(sp.sender, sp.mutez((params.price_sell * params.quantity) // 10))
         self.data.sharesLong[order.creator][order.price] -= sp.to_int(order.quantity)
         self.data.sharesShort[sp.sender][params.price_buy] -= sp.to_int(params.quantity)
         del self.data.orders[index.value]
         del self.data.sellLongOrders[index.value]
     sp.else:
         self.data.uuid += 1
         self.data.sellShortOrders[self.data.uuid] = True
         self.data.orders[self.data.uuid] = sp.record(position = Position.Short, creator = sp.sender, priceBuy = params.price_buy, price = params.price_sell, quantity = params.quantity)
 
 @sp.entry_point
 def sellLong(self, params):
     sp.set_type(params, sp.TRecord(quantity = sp.TNat, price_buy = sp.TNat, price_sell = sp.TNat))
     sp.verify(~self.data.result.is_some())
     sp.verify(self.data.sharesLong[sp.sender][params.price_buy] >= sp.to_int(params.quantity))
     sp.verify(params.price_sell <= 1000000)