Contract con_stubucks


Contract Code


  
1 random.seed()
2
3 # LST001
4 balances = Hash(default_value=0)
5
6 # LST002
7 metadata = Hash()
8 pot = Variable()
9
10 @construct
11 def seed(supply=10_000):
12 # LST001 - MINT SUPPLY to wallet that submits the contract
13 balances[ctx.caller] = supply
14
15 # LST002
16 metadata['token_name'] = "Stubucks"
17 metadata['token_symbol'] = "SBUX"
18 metadata['operator'] = ctx.caller
19
20 pot.set(0)
21
22 # LST002
23 @export
24 def change_metadata(key: str, value: Any):
25 assert ctx.caller == metadata['operator'], 'Only operator can set metadata!'
26 metadata[key] = value
27
28 def calc_skim(amount: float):
29 skim = amount * 0.02
30 p = pot.get()
31 pot.set(p + skim)
32
33 return skim
34
35 def draw_lotto():
36 draw = random.randint(0, 99)
37 if draw == 0 or draw == 1:
38 # win!
39 return True
40 # lose
41 return False
42
43 # LST001
44 @export
45 def transfer(amount: float, to: str):
46 assert amount > 0, 'Cannot send negative balances!'
47 assert balances[ctx.caller] >= amount, 'Not enough coins to send!'
48
49 # Take 1% from the transfer and put it into the pot
50 skim = calc_skim(amount)
51
52 balances[ctx.caller] -= amount
53 balances[to] += (amount - skim)
54
55 draw = draw_lotto()
56 if draw:
57 balances[to] += pot.get()
58 pot.set(0)
59
60 # LST001
61 @export
62 def approve(amount: float, to: str):
63 assert amount > 0, 'Cannot send negative balances!'
64 balances[ctx.caller, to] += amount
65
66 # LST001
67 @export
68 def transfer_from(amount: float, to: str, main_account: str):
69 assert amount > 0, 'Cannot send negative balances!'
70 assert balances[
71 main_account, ctx.caller] >= amount, 'Not enough coins approved to send! You have {} and are trying to spend {}' \
72 .format(balances[main_account, ctx.caller], amount)
73 assert balances[main_account] >= amount, 'Not enough coins to send!'
74
75 skim = calc_skim(amount)
76
77 balances[main_account, ctx.caller] -= amount
78 balances[main_account] -= amount
79
80 balances[to] += (amount - skim)
81
82 draw = draw_lotto()
83 if draw:
84 balances[to] += pot.get()
85 pot.set(0)

Byte Code

'e3000000000000000000000000050000004000000073b400000065006a0183000100650264006401640264038d035a0365026401640464058d025a0465056401640664058d025a06641b6408640984015a076508640183016509650a640a9c02640b640c840483015a0b650c640d9c01640e640f84045a0d6410641184005a0e650864018301650c650964129c0264136414840483015a0f650864018301650c650964129c0264156416840483015a10650864018301650c6509650964179c0364186419840483015a11641a5300291ce900000000da0c636f6e5f7374756275636b73da0862616c616e6365732903da0d64656661756c745f76616c7565da08636f6e7472616374da046e616d65da086d65746164617461290272050000007206000000da03706f74e91027000063010000000000000001000000030000004300000073320000007c00740074016a023c006401740364023c006403740364043c0074016a02740364053c0074046a056406830101006400530029074eda085374756275636b73da0a746f6b656e5f6e616d65da0453425558da0c746f6b656e5f73796d626f6cda086f70657261746f7272010000002906da0a5f5f62616c616e636573da03637478da0663616c6c6572da0a5f5f6d65746164617461da055f5f706f74da037365742901da06737570706c79a9007216000000da00da045f5f5f5f07000000730a00000000010a01080108010a0172180000002902da036b6579da0576616c7565630200000000000000020000000300000043000000732200000074006a017402640119006b02731674036402830182017c0174027c003c006400530029034e720e0000007a1f4f6e6c79206f70657261746f722063616e20736574206d65746164617461212904721000000072110000007212000000da0e417373657274696f6e4572726f7229027219000000721a000000721600000072160000007217000000da0f6368616e67655f6d657461646174610f0000007306000000000210010601721c0000002901da06616d6f756e7463010000000000000003000000030000004300000073260000007c0074006401830114007d0174016a0283007d0274016a037c027c011700830101007c01530029024e7a04302e30322904da07646563696d616c7213000000da0367657472140000002903721d000000da04736b696dda0170721600000072160000007217000000da0b5f5f63616c635f736b696d16000000730800000000010c0108010e017222000000630000000000000000010000000300000043000000732400000074006a016401640283027d007c0064016b02731c7c0064036b027220640453006405530029064e7201000000e963000000e90100000054462902da0672616e646f6dda0772616e64696e742901da0464726177721600000072160000007217000000da0c5f5f647261775f6c6f74746f1d000000730800000000010c011001040172280000002902721d000000da02746f63020000000000000004000000050000004300000073800000007c0064016b0473107400640283018201740174026a0319007c006b057326740064038301820174047c0083017d02740174026a03050019007c00380003003c0074017c01050019007c007c021800370003003c00740583007d037c03727c74017c010500190074066a078300370003003c0074066a086401830101006400530029044e72010000007a1e43616e6e6f742073656e64206e656761746976652062616c616e636573217a194e6f7420656e6f75676820636f696e7320746f2073656e64212909721b000000720f00000072100000007211000000722200000072280000007213000000721f00000072140000002904721d000000722900000072200000007227000000721600000072160000007217000000da087472616e73666572240000007312000000000210011601080112011401060104011401722a000000630200000000000000020000000400000043000000732a0000007c0064016b0473107400640283018201740174026a037c016602050019007c00370003003c006400530029034e72010000007a1e43616e6e6f742073656e64206e656761746976652062616c616e636573212904721b000000720f000000721000000072110000002902721d0000007229000000721600000072160000007217000000da07617070726f766531000000730400000000021001722b0000002903721d0000007229000000da0c6d61696e5f6163636f756e7463030000000000000005000000050000004300000073be0000007c0064016b047310740064028301820174017c0274026a03660219007c006b05733c740064036a0474017c0274026a03660219007c0083028301820174017c0219007c006b057350740064048301820174057c0083017d0374017c0274026a036602050019007c00380003003c0074017c02050019007c00380003003c0074017c01050019007c007c031800370003003c00740683007d047c0472ba74017c010500190074076a088300370003003c0074076a096401830101006400530029054e72010000007a1e43616e6e6f742073656e64206e656761746976652062616c616e636573217a494e6f7420656e6f75676820636f696e7320617070726f76656420746f2073656e642120596f752068617665207b7d20616e642061726520747279696e6720746f207370656e64207b7d7a194e6f7420656e6f75676820636f696e7320746f2073656e6421290a721b000000720f00000072100000007211000000da06666f726d6174722200000072280000007213000000721f00000072140000002905721d0000007229000000722c00000072200000007227000000721600000072160000007217000000da0d7472616e736665725f66726f6d37000000731a000000000210010c010c01140114010801160110011401060104011401722e0000004e2901720900000029127225000000da0473656564da0448617368720f0000007212000000da085661726961626c6572130000007218000000da085f5f6578706f7274da03737472da03416e79721c000000da05666c6f617472220000007228000000722a000000722b000000722e0000007216000000721600000072160000007217000000da083c6d6f64756c653e01000000731c00000008010e010c010c030a08060112060e0708070601120c060112050601