Contract con_nft_marketplace_v2


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 royalty_receivers[collection_contract, name_of_nft] = {"receiver": ctx.caller, "royalty_percentage": royalty_percentage}
33
34 @export
35 def refund_nft(name_of_nft: str, collection_contract: str):
36 market_entry = market[ctx.caller, collection_contract, name_of_nft]
37 collection = I.import_module(collection_contract)
38 collection.transfer(name=name_of_nft, amount=market_entry["amount"], to=ctx.caller)
39 market[ctx.caller, collection_contract, name_of_nft] = {"amount":0, "price":market_entry["price"]}
40
41
42 @export
43 def buy_nft(name: str, collection_contract: str, seller: str, amount:int):
44 assert amount > 0, 'Cannot buy negative NFT amount'
45 assert market[seller, collection_contract, name]["amount"] >= amount, 'Not enough for sale'
46 collection = I.import_module(collection_contract)
47 currency = I.import_module(allowed_currency.get())
48 assert I.enforce_interface(collection, forced_collection_interface
49 ), 'Invalid collection interface!'
50 fee = ((market[seller, collection_contract, name]["price"] * amount)/100*2)
51 royalty = ((market[seller, collection_contract, name]["price"] * amount)/100*royalty_receivers[collection_contract, name]["royalty_percentage"])
52
53 currency.transfer_from(amount=(market[seller, collection_contract, name]["price"] * amount) - fee - royalty, to=seller, main_account=ctx.caller)
54 currency.transfer_from(amount=fee, to=treasury.get(), main_account=ctx.caller)
55 currency.transfer_from(amount=royalty, to=royalty_receivers[collection_contract, name]["receiver"], main_account=ctx.caller)
56
57 old_market_entry = market[seller, collection_contract, name]
58 market[seller, collection_contract, name] = {"amount": old_market_entry["amount"] - amount, "price": old_market_entry["price"]}
59 collection.transfer(name=name, amount=amount, to=ctx.caller)
60
61
62 @export
63 def change_allowed_currency(contract: str):
64 assert ctx.caller == operator.get(), "Only the operator can do this"
65 allowed_currency.set(contract)
66
67
68 @export
69 def change_treasury(address: str):
70 assert ctx.caller == operator.get(), "Only the operator can do this"
71 treasury.set(address)
72
73
74 @export
75 def change_operator(address: str):
76 assert ctx.caller == operator.get(), "Only the operator can do this"
77 operator.set(address)
78

Byte Code

e30000000000000000000000000800000040000000730c01000065005a0165026400640164028d025a0365026400640364028d025a04650564046400640564068d035a0665026400640764028d025a07650564086400640964068d035a0865016a09640a6426640e8d0265016a09640f6427640e8d0265016a0964106428640e8d0267035a0a6412641384005a0b650c64008301650d650d650e650f650f64149c0564156416840483015a10650c64008301650d650d64179c0264186419840483015a11650c64008301650d650d650d650e641a9c04641b641c840483015a12650c64008301650d641d9c01641e641f840483015a13650c64008301650d64209c0164216422840483015a14650c64008301650d64209c0164236424840483015a15642553002929da16636f6e5f6e66745f6d61726b6574706c6163655f7632da10616c6c6f7765645f63757272656e63792902da08636f6e7472616374da046e616d65da086f70657261746f72e900000000da066d61726b65742903da0d64656661756c745f76616c756572030000007204000000da08747265617375727946da11726f79616c74795f726563656976657273da087472616e736665727204000000da06616d6f756e74da02746f2901da0461726773da07617070726f7665da0d7472616e736665725f66726f6dda0c6d61696e5f6163636f756e74630000000000000000000000000200000043000000732200000074006a0164018301010074026a0164028301010074036a016403830101006400530029044eda11636f6e5f7265666c6563747461755f7632da4066663631353434656139346561616562356466303865643836336334613933386539313239616261366365656535663331623636383162646564653131623839da1a636f6e5f7265666c6563747461755f76325f74726561737572792904da125f5f616c6c6f7765645f63757272656e6379da03736574da0a5f5f6f70657261746f72da0a5f5f7472656173757279a90072190000007219000000da00da045f5f5f5f0f000000730800000000010a0104010601721b0000002905da0b6e616d655f6f665f6e6674da13636f6c6c656374696f6e5f636f6e7472616374720c000000da0e63757272656e63795f7072696365da12726f79616c74795f70657263656e7461676563050000000000000006000000060000004300000073a20000007c0264016b04731074006402830182017c0364016b047320740064038301820174016a027c0183017d0574016a037c0574048302733e74006404830182017c056a057c007c0274066a0774066a0864058d0401007c027c0364069c02740974066a087c017c0066033c00740a7c017c006602190064076b02729e7c0464006b02728a740b640883017d0474066a087c0464099c02740a7c017c0066023c0064005300290a4e72060000007a1f43616e6e6f742073656c6c206e65676174697665204e465420616d6f756e747a2243616e6e6f742073656c6c20666f72206e656761746976652062616c616e636573217a1d496e76616c696420636f6c6c656374696f6e20696e746572666163652129047204000000720c000000720d00000072110000002902720c000000da057072696365467a03302e302902da087265636569766572721f000000290cda0e417373657274696f6e4572726f72da0149da0d696d706f72745f6d6f64756c65da11656e666f7263655f696e74657266616365da1b666f726365645f636f6c6c656374696f6e5f696e746572666163657210000000da03637478da0474686973da0663616c6c6572da085f5f6d61726b6574da135f5f726f79616c74795f726563656976657273da07646563696d616c2906721c000000721d000000720c000000721e000000721f000000da0a636f6c6c656374696f6e72190000007219000000721a000000da0873656c6c5f6e66741600000073180000000003100110010a010e0106010c010a021601100108010802722e0000002902721c000000721d000000630200000000000000040000000500000043000000734e000000740074016a027c017c00660319007d0274036a047c0183017d037c036a057c007c026401190074016a0264028d03010064037c026404190064059c02740074016a027c017c0066033c006400530029064e720c00000029037204000000720c000000720d000000720600000072200000002902720c00000072200000002906722a0000007227000000722900000072230000007224000000720b0000002904721c000000721d000000da0c6d61726b65745f656e747279722d00000072190000007219000000721a000000da0a726566756e645f6e667429000000730c000000000210010a010c010a010201723000000029047204000000721d000000da0673656c6c6572720c00000063040000000000000009000000050000004300000073460100007c0364016b047310740064028301820174017c027c017c0066031900640319007c036b05732e740064048301820174026a037c0183017d0474026a0374046a05830083017d0574026a067c0474078302735a740064058301820174017c027c017c0066031900640619007c03140064071b00640814007d0674017c027c017c0066031900640619007c03140064071b0074087c017c00660219006409190014007d077c056a0974017c027c017c0066031900640619007c0314007c0618007c0718007c02740a6a0b640a8d0301007c056a097c06740c6a058300740a6a0b640a8d0301007c056a097c0774087c017c0066021900640b1900740a6a0b640a8d03010074017c027c017c00660319007d087c08640319007c0318007c0864061900640c9c0274017c027c017c0066033c007c046a0d7c007c03740a6a0b640d8d03010064005300290e4e72060000007a1e43616e6e6f7420627579206e65676174697665204e465420616d6f756e74720c0000007a134e6f7420656e6f75676820666f722073616c657a1d496e76616c696420636f6c6c656374696f6e20696e74657266616365217220000000e964000000e902000000721f0000002903720c000000720d000000721100000072210000002902720c000000722000000029037204000000720c000000720d000000290e7222000000722a000000722300000072240000007215000000da0367657472250000007226000000722b0000007210000000722700000072290000007218000000720b00000029097204000000721d0000007231000000720c000000722d000000da0863757272656e6379da03666565da07726f79616c7479da106f6c645f6d61726b65745f656e74727972190000007219000000721a000000da076275795f6e66743300000073280000000002100110010e010a010e010e0106021e022201080104011e010a010c010a01080116010e022002723900000029017203000000630100000000000000010000000200000043000000732400000074006a0174026a0383006b027316740464018301820174056a067c00830101006400530029024e7a1d4f6e6c7920746865206f70657261746f722063616e20646f2074686973290772270000007229000000721700000072340000007222000000721500000072160000002901720300000072190000007219000000721a000000da176368616e67655f616c6c6f7765645f63757272656e63794f000000730400000000021601723a0000002901da0761646472657373630100000000000000010000000200000043000000732400000074006a0174026a0383006b027316740464018301820174056a067c00830101006400530029024e7a1d4f6e6c7920746865206f70657261746f722063616e20646f2074686973290772270000007229000000721700000072340000007222000000721800000072160000002901723b00000072190000007219000000721a000000da0f6368616e67655f747265617375727955000000730400000000021601723c000000630100000000000000010000000200000043000000732400000074006a0174026a0383006b027316740464018301820174026a057c00830101006400530029024e7a1d4f6e6c7920746865206f70657261746f722063616e20646f207468697329067227000000722900000072170000007234000000722200000072160000002901723b00000072190000007219000000721a000000da0f6368616e67655f6f70657261746f725b000000730400000000021601723d0000004e29037204000000720c000000720d0000002903720c0000007204000000720d00000029047204000000720c000000720d00000072110000002916da09696d706f72746c69627223000000da085661726961626c6572150000007217000000da0448617368722a0000007218000000722b000000da0446756e637226000000721b000000da085f5f6578706f7274da03737472da03696e74da05666c6f6174722e00000072300000007239000000723a000000723c000000723d000000721900000072190000007219000000721a000000da083c6d6f64756c653e0100000073320000000401040108010c01060108010c0104010a01060116010c030807060106011211060112090601161b06011005060110050601