Contract con_nft_marketplace_v3


Contract Code


  
1 #royalties update
2 I = importlib
3 allowed_currency = Variable()
4 operator = Variable()
5 market = Hash(default_value=0) # Stores NFTs up for sale
6 treasury = Variable()
7 royalty_receivers = Hash(default_value=False)
8 forced_collection_interface = [I.Func('transfer', args=('name', 'amount', 'to')), I.Func(
9 'approve', args=('amount', 'name', 'to')), I.Func('transfer_from', args=(
10 'name', 'amount', 'to', 'main_account'))]
11
12 @construct
13 def seed():
14 allowed_currency.set("con_reflecttau_v2")
15 operator.set("ff61544ea94eaaeb5df08ed863c4a938e9129aba6ceee5f31b6681bdede11b89")
16 treasury.set("con_reflecttau_v2_treasury")
17
18
19 @export
20 def sell_nft(name_of_nft: str, collection_contract: str, amount: int, currency_price: float, royalty_percentage: float):
21 assert amount > 0, 'Cannot sell negative NFT amount'
22 assert currency_price > 0, 'Cannot sell for negative balances!'
23 collection = I.import_module(collection_contract)
24 assert I.enforce_interface(collection, forced_collection_interface
25 ), 'Invalid collection interface!'
26 collection.transfer_from(name=name_of_nft, amount=amount, to=ctx.this, main_account=ctx.caller)
27 market[ctx.caller, collection_contract, name_of_nft] = {"amount": amount, "price": currency_price}
28
29 if royalty_receivers[collection_contract, name_of_nft] == False:
30 if(royalty_percentage == None):
31 royalty_percentage = 0.0
32 assert royalty_percentage <= 50, "Over 50% royalty is not allowed"
33 royalty_receivers[collection_contract, name_of_nft] = {"receiver": ctx.caller, "royalty_percentage": royalty_percentage}
34
35 @export
36 def refund_nft(name_of_nft: str, collection_contract: str):
37 market_entry = market[ctx.caller, collection_contract, name_of_nft]
38 collection = I.import_module(collection_contract)
39 collection.transfer(name=name_of_nft, amount=market_entry["amount"], to=ctx.caller)
40 market[ctx.caller, collection_contract, name_of_nft] = {"amount":0, "price":market_entry["price"]}
41
42
43 @export
44 def buy_nft(name: str, collection_contract: str, seller: str, amount:int):
45 assert amount > 0, 'Cannot buy negative NFT amount'
46 assert market[seller, collection_contract, name]["amount"] >= amount, 'Not enough for sale'
47 collection = I.import_module(collection_contract)
48 currency = I.import_module(allowed_currency.get())
49 assert I.enforce_interface(collection, forced_collection_interface
50 ), 'Invalid collection interface!'
51 fee = ((market[seller, collection_contract, name]["price"] * amount)/100*2)
52 royalty = ((market[seller, collection_contract, name]["price"] * amount)/100*royalty_receivers[collection_contract, name]["royalty_percentage"])
53
54 currency.transfer_from(amount=(market[seller, collection_contract, name]["price"] * amount) - fee - royalty, to=seller, main_account=ctx.caller)
55 currency.transfer_from(amount=fee, to=treasury.get(), main_account=ctx.caller)
56 currency.transfer_from(amount=royalty, to=royalty_receivers[collection_contract, name]["receiver"], main_account=ctx.caller)
57
58 old_market_entry = market[seller, collection_contract, name]
59 market[seller, collection_contract, name] = {"amount": old_market_entry["amount"] - amount, "price": old_market_entry["price"]}
60 collection.transfer(name=name, amount=amount, to=ctx.caller)
61
62
63 @export
64 def change_allowed_currency(contract: str):
65 assert ctx.caller == operator.get(), "Only the operator can do this"
66 allowed_currency.set(contract)
67
68
69 @export
70 def change_treasury(address: str):
71 assert ctx.caller == operator.get(), "Only the operator can do this"
72 treasury.set(address)
73
74
75 @export
76 def change_operator(address: str):
77 assert ctx.caller == operator.get(), "Only the operator can do this"
78 operator.set(address)
79

Byte Code

e30000000000000000000000000800000040000000730c01000065005a0165026400640164028d025a0365026400640364028d025a04650564046400640564068d035a0665026400640764028d025a07650564086400640964068d035a0865016a09640a6426640e8d0265016a09640f6427640e8d0265016a0964106428640e8d0267035a0a6412641384005a0b650c64008301650d650d650e650f650f64149c0564156416840483015a10650c64008301650d650d64179c0264186419840483015a11650c64008301650d650d650d650e641a9c04641b641c840483015a12650c64008301650d641d9c01641e641f840483015a13650c64008301650d64209c0164216422840483015a14650c64008301650d64209c0164236424840483015a15642553002929da16636f6e5f6e66745f6d61726b6574706c6163655f7633da10616c6c6f7765645f63757272656e63792902da08636f6e7472616374da046e616d65da086f70657261746f72e900000000da066d61726b65742903da0d64656661756c745f76616c756572030000007204000000da08747265617375727946da11726f79616c74795f726563656976657273da087472616e736665727204000000da06616d6f756e74da02746f2901da0461726773da07617070726f7665da0d7472616e736665725f66726f6dda0c6d61696e5f6163636f756e74630000000000000000000000000200000043000000732200000074006a0164018301010074026a0164028301010074036a016403830101006400530029044eda11636f6e5f7265666c6563747461755f7632da4066663631353434656139346561616562356466303865643836336334613933386539313239616261366365656535663331623636383162646564653131623839da1a636f6e5f7265666c6563747461755f76325f74726561737572792904da125f5f616c6c6f7765645f63757272656e6379da03736574da0a5f5f6f70657261746f72da0a5f5f7472656173757279a90072190000007219000000da00da045f5f5f5f0f000000730800000000010a0104010601721b0000002905da0b6e616d655f6f665f6e6674da13636f6c6c656374696f6e5f636f6e7472616374720c000000da0e63757272656e63795f7072696365da12726f79616c74795f70657263656e7461676563050000000000000006000000060000004300000073b20000007c0264016b04731074006402830182017c0364016b047320740064038301820174016a027c0183017d0574016a037c0574048302733e74006404830182017c056a057c007c0274066a0774066a0864058d0401007c027c0364069c02740974066a087c017c0066033c00740a7c017c006602190064076b0272ae7c0464006b02728a740b640883017d047c0464096b01739a7400640a8301820174066a087c04640b9c02740a7c017c0066023c0064005300290c4e72060000007a1f43616e6e6f742073656c6c206e65676174697665204e465420616d6f756e747a2243616e6e6f742073656c6c20666f72206e656761746976652062616c616e636573217a1d496e76616c696420636f6c6c656374696f6e20696e746572666163652129047204000000720c000000720d00000072110000002902720c000000da057072696365467a03302e30e9320000007a1f4f7665722035302520726f79616c7479206973206e6f7420616c6c6f7765642902da087265636569766572721f000000290cda0e417373657274696f6e4572726f72da0149da0d696d706f72745f6d6f64756c65da11656e666f7263655f696e74657266616365da1b666f726365645f636f6c6c656374696f6e5f696e746572666163657210000000da03637478da0474686973da0663616c6c6572da085f5f6d61726b6574da135f5f726f79616c74795f726563656976657273da07646563696d616c2906721c000000721d000000720c000000721e000000721f000000da0a636f6c6c656374696f6e72190000007219000000721a000000da0873656c6c5f6e667416000000731a0000000003100110010a010e0106010c010a0216011001080108011002722f0000002902721c000000721d000000630200000000000000040000000500000043000000734e000000740074016a027c017c00660319007d0274036a047c0183017d037c036a057c007c026401190074016a0264028d03010064037c026404190064059c02740074016a027c017c0066033c006400530029064e720c00000029037204000000720c000000720d000000720600000072200000002902720c00000072200000002906722b0000007228000000722a00000072240000007225000000720b0000002904721c000000721d000000da0c6d61726b65745f656e747279722e00000072190000007219000000721a000000da0a726566756e645f6e66742a000000730c000000000210010a010c010a010201723100000029047204000000721d000000da0673656c6c6572720c00000063040000000000000009000000050000004300000073460100007c0364016b047310740064028301820174017c027c017c0066031900640319007c036b05732e740064048301820174026a037c0183017d0474026a0374046a05830083017d0574026a067c0474078302735a740064058301820174017c027c017c0066031900640619007c03140064071b00640814007d0674017c027c017c0066031900640619007c03140064071b0074087c017c00660219006409190014007d077c056a0974017c027c017c0066031900640619007c0314007c0618007c0718007c02740a6a0b640a8d0301007c056a097c06740c6a058300740a6a0b640a8d0301007c056a097c0774087c017c0066021900640b1900740a6a0b640a8d03010074017c027c017c00660319007d087c08640319007c0318007c0864061900640c9c0274017c027c017c0066033c007c046a0d7c007c03740a6a0b640d8d03010064005300290e4e72060000007a1e43616e6e6f7420627579206e65676174697665204e465420616d6f756e74720c0000007a134e6f7420656e6f75676820666f722073616c657a1d496e76616c696420636f6c6c656374696f6e20696e74657266616365217220000000e964000000e902000000721f0000002903720c000000720d000000721100000072220000002902720c000000722000000029037204000000720c000000720d000000290e7223000000722b000000722400000072250000007215000000da0367657472260000007227000000722c00000072100000007228000000722a0000007218000000720b00000029097204000000721d0000007232000000720c000000722e000000da0863757272656e6379da03666565da07726f79616c7479da106f6c645f6d61726b65745f656e74727972190000007219000000721a000000da076275795f6e66743400000073280000000002100110010e010a010e010e0106021e022201080104011e010a010c010a01080116010e022002723a00000029017203000000630100000000000000010000000200000043000000732400000074006a0174026a0383006b027316740464018301820174056a067c00830101006400530029024e7a1d4f6e6c7920746865206f70657261746f722063616e20646f207468697329077228000000722a000000721700000072350000007223000000721500000072160000002901720300000072190000007219000000721a000000da176368616e67655f616c6c6f7765645f63757272656e637950000000730400000000021601723b0000002901da0761646472657373630100000000000000010000000200000043000000732400000074006a0174026a0383006b027316740464018301820174056a067c00830101006400530029024e7a1d4f6e6c7920746865206f70657261746f722063616e20646f207468697329077228000000722a000000721700000072350000007223000000721800000072160000002901723c00000072190000007219000000721a000000da0f6368616e67655f747265617375727956000000730400000000021601723d000000630100000000000000010000000200000043000000732400000074006a0174026a0383006b027316740464018301820174026a057c00830101006400530029024e7a1d4f6e6c7920746865206f70657261746f722063616e20646f207468697329067228000000722a00000072170000007235000000722300000072160000002901723c00000072190000007219000000721a000000da0f6368616e67655f6f70657261746f725c000000730400000000021601723e0000004e29037204000000720c000000720d0000002903720c0000007204000000720d00000029047204000000720c000000720d00000072110000002916da09696d706f72746c69627224000000da085661726961626c6572150000007217000000da0448617368722b0000007218000000722c000000da0446756e637227000000721b000000da085f5f6578706f7274da03737472da03696e74da05666c6f6174722f0000007231000000723a000000723b000000723d000000723e000000721900000072190000007219000000721a000000da083c6d6f64756c653e0100000073320000000401040108010c01060108010c0104010a01060116010c030807060106011212060112090601161b06011005060110050601