def __init__( self, config, metadata, administrators, validators=sp.set([], t=sp.TAddress), controllers=sp.set([], t=sp.TAddress), burners=sp.set([], t=sp.TAddress), minters=sp.set([], t=sp.TAddress) ): FA12_core.__init__( self, config, paused=False, operable=True, issuable=True, controllable=True, metadata=metadata, roles=make_roles( administrators=administrators, validators=validators, controllers=controllers, burners=burners, minters=burners, ) )
def __init__(self,admin,endCycle,endWithdraw,token): self.init(contractBuyer= sp.big_map(),contractSellar = sp.big_map(), administrator = admin,buyerSet = sp.set(),poolSet=sp.set(), xtzPrice=400,validation=sp.record(cycleEnd=sp.timestamp(endCycle),withdrawTime=sp.timestamp(endWithdraw),totalSupply=sp.nat(0)), tokenContract=token,adminAccount=0,model = sp.map() )
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(params.expire)) sp.verify(self.data.validation.cycleEnd > sp.now.add_days(params.expire))
def make_roles(administrators=sp.set([], t=sp.TAddress), validators=sp.set([], t=sp.TAddress), controllers=sp.set([], t=sp.TAddress)): return sp.map( { ADMIN_ROLE: make_role(ADMIN_ROLE, administrators), ALLOWLIST_ADMIN_ROLE: make_role(ADMIN_ROLE, controllers), BLOCKLIST_ADMIN_ROLE: make_role(ADMIN_ROLE) }, tkey=sp.TNat, tvalue=sp.TRecord( role_admin=sp.TNat, members=sp.TSet(t=sp.TAddress) ) )
def test(): scenario = sp.test_scenario() scenario.h1("ExchangeRateOracle Tests") admin = sp.test_account("Admin") scenario.show(admin) operatorA = sp.test_account("operatorA") scenario.show(operatorA) operatorB = sp.test_account("operatorB") scenario.show(operatorB) caller = sp.test_account("caller") scenario.show(caller) oracle = ExchangeRateOracle(admin.address) scenario.register(oracle) consumer = ExchangeRateConsumer(oracle.address) scenario.register(consumer) scenario += oracle.updateOperatorList(operators = sp.set([operatorA.address, operatorB.address])).run(sender = admin) scenario += oracle.registerFeed(currencyPair = "USDEUR", cost = sp.mutez(1000)).run(sender = admin) scenario += oracle.updateFeed(currencyPair = "USDEUR", value = sp.nat(92), precision = sp.nat(2), timestamp = sp.timestamp(0), source = "Trusted Source").run(sender = operatorA) scenario += consumer.sendQuery(currencyPair = "USDEUR").run(sender = caller, amount = sp.mutez(1000)) scenario.verify(consumer.data.value == 92) scenario.verify(consumer.data.currencyPair == "USDEUR")
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([])
def __init__(self, admin): self.init( feed = sp.map( tkey = sp.TString, tvalue = sp.TRecord( value = sp.TNat, precision = sp.TNat, timestamp = sp.TTimestamp, source = sp.TString )), feedQueryCost = sp.map(tkey = sp.TString, tvalue = sp.TMutez), admin = admin, operators = sp.set(), registeredPairs = sp.set() )
def test(): scenario = sp.test_scenario() scenario.h1('Land Register') manager = sp.test_account('Manager') r1 = sp.test_account('Registrar 1') r2 = sp.test_account('Registrar 2') r3 = sp.test_account('Registrar 3') c = LandRegister(manager=manager.address, registrars=sp.set([r1.address, r2.address, r3.address]) ) scenario += c scenario.h2("Add Registrar") r4 = sp.test_account('Registrar 4') scenario += c.add_registrar(registrar=r4.address).run(sender=manager) scenario.h2("Add Registrar with Wrong Manager") wrong = sp.test_account('Wrong Manager') r5 = sp.test_account('Registrar 5') scenario += c.add_registrar(registrar=r5.address).run(sender=wrong, valid=False) scenario.h2("Remove Registrar") scenario += c.remove_registrar(registrar=r1.address).run(sender=manager) scenario.h2("Remove Registrar with Wrong Manager") scenario += c.remove_registrar(registrar=r2.address).run(sender=wrong, valid=False) scenario.h2("Add Land") land_owner = sp.test_account('Land Owner') land = { 'A': (1,2), 'B': (3,2), 'C': (4,3), 'D': (5,4) } code = "ABCD" scenario += c.add_land(owner=land_owner.address, land=land, code=code).run(sender=r3) scenario.h2("Add Land with Wrong Registrar") scenario += c.add_land(owner=land_owner.address, land=land, code=code).run(sender=wrong, valid=False)
def __init__(self, reward, token, tokenAddress=None): self.token = token if tokenAddress is None: tokenAddress = self.token.address self.init(distributed=0, reward=reward, token=tokenAddress, receivers=sp.set([]))
def AddVault(self,params): sp.set_type(params, sp.TRecord(address = sp.TAddress, owner = sp.TAddress)) sp.verify(self.data.validator.contains(sp.sender)) sp.if ~ self.data.Indexer.contains(params.owner): self.data.Indexer[params.owner] = sp.set()
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)
def transderDataToken(self, f, t, token_id): self.data.tokenHolderToID[f].remove(token_id) with sp.if_(~self.data.ownerToBalance.contains(t)): self.data.tokenHolderToID[t] = sp.set() self.data.tokenHolderToID[t].add(token_id) self.data.tokenIdToOwner[token_id] = t self.data.ownerToBalance[f] -= 1 with sp.if_(~self.data.ownerToBalance.contains(t)): self.data.ownerToBalance[t] = 0 self.data.ownerToBalance[t] += 1
def mintCertificate(self,params): sp.verify(~self.data.tokensMinted.contains(params.token_id)) self.data.tokensMinted.add(params.token_id) sp.if ~self.data.ownerToBalance.contains(params.address): self.data.tokenHolderToID[params.address] = sp.set()
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)
def __init__(self, _name, _symbol, _admin): self.init( name = _name, symbol = _symbol, admin = _admin, tokensMinted = sp.set( t= sp.TString), tokenHolderToID = sp.big_map(tkey = sp.TAddress, tvalue = sp.TSet(sp.TString)), ownerToBalance = sp.big_map(tkey = sp.TAddress, tvalue = sp.TInt), tokenIdToOwner = sp.big_map(tkey = sp.TString, tvalue = sp.TAddress), tokenApprovals = sp.big_map(tkey = sp.TString, tvalue = sp.TAddress), )
def mintDataToken(self,params): sp.verify(sp.sender == self.data.admin) sp.verify(~self.data.tokensMinted.contains(params.token_id)) self.data.tokensMinted.add(params.token_id) with sp.if_(~self.data.ownerToBalance.contains(params.address)): self.data.tokenHolderToID[params.address] = sp.set() self.data.tokenHolderToID[params.address].add(params.token_id) self.data.tokenIdToOwner[params.token_id] = params.address with sp.if_(~self.data.ownerToBalance.contains(params.address)): self.data.ownerToBalance[params.address] = 0 self.data.ownerToBalance[params.address] += 1
def __init__(self,admin,token,oracle): self.init( Securities= sp.big_map(),LiquidityProvider = sp.big_map(), poolSet=sp.set(), totalSupply=sp.nat(0), adminAccount=sp.nat(0), PoolSize = sp.nat(10), InterestRate=sp.map(), administrator = admin, token=token, oracle=oracle)
def test(): scenario = sp.test_scenario() scenario.h1("Chainlink Oracles") scenario.table_of_contents() scenario.h2("Accounts") admin = sp.test_account("Administrator") bob = sp.address("tz1WdHqcAo7gjtFDPMgD6yN8pk1sq67MJRjH") oracle1 = sp.test_account("Oracle1") client1_admin = sp.test_account("Client1 admin") client2_admin = sp.test_account("Client2 admin") scenario.show([admin, oracle1, client1_admin, client2_admin]) scenario.h2("Link Token") link_token = Link_token(FA2.FA2_config(single_asset = True), admin.address) scenario += link_token scenario += link_token.mint(address = admin.address, amount = 200, symbol = 'tzLINK', token_id = 0).run(sender = admin) scenario.h2("Token Faucet") faucet = TokenFaucet(admin.address, link_token, link_token.address, 10) scenario += faucet scenario.h2("Oracle") oracle = Oracle(oracle1.address, link_token) scenario += oracle scenario.h2("Client1") client1 = Client(link_token.address, oracle.address, sp.bytes("0x0001"), client1_admin.address) scenario += client1 scenario.h2("Client2") client2 = Client(link_token.address, oracle.address, sp.bytes("0x0001"), client2_admin.address) scenario += client2 scenario.h2("Tokens") scenario += link_token.transfer([sp.record(from_ = admin.address, txs = [sp.record(to_ = faucet.address, token_id = 0, amount = 100)])]).run(sender = admin) scenario += link_token.transfer([sp.record(from_ = admin.address, txs = [sp.record(to_ = oracle1.address, token_id = 0, amount = 1)])]).run(sender = admin) scenario += faucet.request_tokens(sp.set([client1.address, client2.address])) #scenario += link_token.transfer([sp.record(from_ = client1_admin.address, txs = [sp.record(to_ = client1.address, token_id = 0, amount = 10)])]).run(sender = client1_admin) scenario.h2("Client1 sends a request that gets fulfilled") scenario.h3("A request") scenario += client1.request_fortune(payment = 1, timeout = 10).run(sender = bob)
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)
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") )
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 __init__(self, config, admin): self.config = config self.error_message = Error_message(self.config) self.operator_set = Operator_set(self.config) self.operator_param = Operator_param(self.config) self.token_id_set = Token_id_set(self.config) self.ledger_key = Ledger_key(self.config) self.token_meta_data = Token_meta_data(self.config) self.permissions_descriptor_ = Permissions_descriptor(self.config) self.batch_transfer = Batch_transfer(self.config) self.player_meta_data = Player_meta_data(self.config) self.player_id_set = Player_id_set(self.config) if self.config.add_mutez_transfer: self.transfer_mutez = sp.entry_point(mutez_transfer) if self.config.add_permissions_descriptor: def permissions_descriptor(self, params): sp.set_type(params, sp.TContract( self.permissions_descriptor_.get_type())) v = self.permissions_descriptor_.make() sp.transfer(v, sp.mutez(0), params) self.permissions_descriptor = sp.entry_point( permissions_descriptor) if config.lazy_entry_points: self.add_flag("lazy_entry_points") if config.lazy_entry_points_multiple: self.add_flag("lazy_entry_points_multiple") self.exception_optimization_level = "DefaultLine" self.init( paused=False, ledger=self.config.my_map(tvalue=Ledger_value.get_type()), tokens=self.config.my_map(tvalue=self.token_meta_data.get_type()), operators=self.operator_set.make(), administrator=admin, all_tokens=self.token_id_set.empty(), players=self.config.my_map( tkey=sp.TNat, tvalue=self.player_meta_data.get_type()), tokens_on_sale=sp.big_map(tkey=sp.TNat, tvalue=sp.TRecord( owner=sp.TAddress, price=sp.TMutez)), selected_tokens=sp.map( tkey=sp.TAddress, tvalue=sp.TRecord(tokens=sp.TSet(sp.TNat))), matches=sp.map(tkey=sp.TNat, tvalue=sp.TRecord( teamA=sp.TString, teamB=sp.TString, active=sp.TBool, finished=sp.TBool, date=sp.TString, compete=sp.TBool)), playerPoints=sp.map(tkey=sp.TNat, tvalue=sp.TRecord( points=sp.TNat, rank=sp.TNat)), keysset=sp.set([admin]), )
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)
def test(): scenario = sp.test_scenario() scenario.h1("Simple ST12 Contract") # sp.test_account generates ED25519 key-pairs deterministically: admin = sp.test_account("Administrable") alice = sp.test_account("Alice") bob = sp.test_account("Robert") # Let's display the accounts: scenario.h2("Accounts") scenario.show([admin, alice, bob]) g = GeneralTransferManager(sp.set([admin.address])) scenario += g t = TestToken(gtm=g.address, controller=admin.address) scenario += t scenario.h2("Not Controller Transfer") scenario.h3("Allowlisted from_ and to_") scenario += g.addToAllowlist(sp.record(address=alice.address)).run(sender=admin.address) scenario += g.addToAllowlist(sp.record(address=bob.address)).run(sender=admin.address) scenario += t.transfer(sp.record(to_=alice.address, from_=bob.address)).run(sender=bob.address) scenario.h3("Controller can move tokens") scenario += t.transfer(sp.record(to_=alice.address, from_=bob.address)).run(sender=admin.address) scenario.h3("Blocklisted to_") scenario += g.addToBlocklist(sp.record(address=alice.address)).run(sender=admin.address) scenario += t.transfer(sp.record(to_=alice.address, from_=bob.address)).run(sender=bob.address, valid=False) scenario.h3("Controller can't move tokens to a blocked address") scenario += t.transfer(sp.record(to_=alice.address, from_=bob.address)).run(sender=admin.address, valid=False) scenario.h3("Blocklisted from_") scenario += t.transfer(sp.record(to_=bob.address, from_=alice.address)).run(sender=alice.address, valid=False) scenario.h3("Controller can move tokens out of a blocked address") scenario += t.transfer(sp.record(to_=bob.address, from_=alice.address)).run(sender=admin.address) scenario.h3("Blocklisted to_") scenario += g.addToBlocklist(sp.record(address=bob.address)).run(sender=admin.address) scenario += t.transfer(sp.record(to_=alice.address, from_=bob.address)).run(sender=bob.address, valid=False) scenario.h3("Controller should not move tokens to a blocked address") scenario += t.transfer(sp.record(to_=alice.address, from_=bob.address)).run(sender=admin.address, valid=False)
class LandRegister(sp.Contract): def __init__(self, manager, registrars): self.init( manager=manager, registrars=registrars, lands=sp.big_map(tkey=sp.TString, tvalue=sp.TRecord( A=sp.TPair(sp.TInt, sp.TInt), B=sp.TPair(sp.TInt, sp.TInt), C=sp.TPair(sp.TInt, sp.TInt), D=sp.TPair(sp.TInt, sp.TInt) )), land_owners=sp.map(tkey=sp.TAddress, tvalue=sp.TSet(sp.TString)) ) @sp.entry_point def add_registrar(self, params): sp.verify_equal(sp.sender, self.data.manager, message="Unauthorized Action. You are not manager.") self.data.registrars.add(params.registrar) @sp.entry_point def remove_registrar(self, params): sp.verify_equal(sp.sender, self.data.manager, message="Unauthorized Action. You are not manager.") self.data.registrars.remove(params.registrar) @sp.entry_point def add_land(self, params): sp.verify(self.data.registrars.contains(sp.sender), message = "You must be a registrar") self.data.lands[params.code] = sp.record(A=params.land['A'], B=params.land['B'], C=params.land['C'], D=params.land['D']) sp.if self.data.land_owners.contains(params.owner): self.data.land_owners[params.owner].add(params.code) sp.else: self.data.land_owners[params.owner] = sp.set([params.code])
def empty(self): if self.config.assume_consecutive_token_ids: # The "set" is its cardinal. return sp.nat(0) else: return sp.set(t=token_id_type)
def make(token): return sp.record(tokens=sp.set([token]))
def __init__(self, admin): FA12_core.__init__(self, paused = False, administrator = admin,validator = sp.set([admin]), Indexer = sp.big_map())
def __init__(self, admin): self.init(playerPoints=sp.map(tkey=sp.TNat, tvalue=sp.TRecord( points=sp.TNat, rank=sp.TNat)), keysset=sp.set([admin]), owner=admin)
def __init__(self,admin): self.init( owner=admin, keysset = sp.set([admin]), cycleNumber = 268 )