Contract con_nft_marketplace_2


Contract Code


  
1 # THIS IS COMPATIBLE WITH EVERY LST003 COLLECTION, YOU CAN SELL DIFFERENT COLLECTIONS NOT JUST NAMESPACE
2
3 I = importlib
4 allowed_currency = Variable()
5 operator = Variable()
6 market = Hash(default_value=0) # Stores NFTs up for sale
7 treasury = Variable()
8
9 forced_collection_interface = [I.Func('transfer', args=('name', 'amount', 'to')), I.Func(
10 'approve', args=('amount', 'name', 'to')), I.Func('transfer_from', args=(
11 'name', 'amount', 'to', 'main_account'))]
12
13 @construct
14 def seed():
15 allowed_currency.set("con_reflecttau_v2")
16 operator.set("ff61544ea94eaaeb5df08ed863c4a938e9129aba6ceee5f31b6681bdede11b89")
17 treasury.set("con_reflecttau_v2_treasury")
18
19 @export
20 def sell_nft(name_of_nft: str, collection_contract: str, amount: int, currency_price: 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 @export
30 def refund_nft(name_of_nft: str, collection_contract: str):
31 market_entry = market[ctx.caller, collection_contract, name_of_nft]
32 collection = I.import_module(collection_contract)
33 collection.transfer(name=name_of_nft, amount=market_entry["amount"], to=ctx.caller)
34 market[ctx.caller, collection_contract, name_of_nft] = {"amount":0, "price":market_entry["price"]}
35
36
37 @export
38 def buy_nft(name: str, collection_contract: str, seller: str, amount:int):
39 assert amount > 0, 'Cannot buy negative NFT amount'
40 assert market[seller, collection_contract, name]["amount"] >= amount, 'Not enough for sale'
41 collection = I.import_module(collection_contract)
42 currency = I.import_module(allowed_currency.get())
43 assert I.enforce_interface(collection, forced_collection_interface
44 ), 'Invalid collection interface!'
45 fee = ((market[seller, collection_contract, name]["price"] * amount)/100*1)
46 currency.transfer_from(amout=(market[seller, collection_contract, name]["price"] * amount) - fee, to=seller, main_account=ctx.caller)
47 currency.transfer_from(amout=fee, to=treasury.get(), main_account=ctx.caller)
48
49 old_market_entry = market[seller, collection_contract, name]
50 market[seller, collection_contract, name] = {"amount": old_market_entry["amount"] - amount, "price": old_market_entry["price"]}
51
52 collection.transfer(name=name, amount=amount, to=ctx.caller)
53
54
55 @export
56 def change_allowed_currency(contract: str):
57 assert ctx.caller == operator.get(), "Only the operator can do this"
58 allowed_currency.set(contract)
59
60 @export
61 def change_treasury(address: str):
62 assert ctx.caller == operator.get(), "Only the operator can do this"
63 treasury.set(address)
64
65 @export
66 def change_operator(address: str):
67 assert ctx.caller == operator.get(), "Only the operator can do this"
68 operator.set(address)

Byte Code

e3000000000000000000000000080000004000000073fc00000065005a0165026400640164028d025a0365026400640364028d025a04650564046400640564068d035a0665026400640764028d025a0765016a0864086424640c8d0265016a08640d6425640c8d0265016a08640e6426640c8d0267035a096410641184005a0a650b64008301650c650c650d650e64129c0464136414840483015a0f650b64008301650c650c64159c0264166417840483015a10650b64008301650c650c650c650d64189c046419641a840483015a11650b64008301650c641b9c01641c641d840483015a12650b64008301650c641e9c01641f6420840483015a13650b64008301650c641e9c0164216422840483015a14642353002927da15636f6e5f6e66745f6d61726b6574706c6163655f32da10616c6c6f7765645f63757272656e63792902da08636f6e7472616374da046e616d65da086f70657261746f72e900000000da066d61726b65742903da0d64656661756c745f76616c756572030000007204000000da087472656173757279da087472616e736665727204000000da06616d6f756e74da02746f2901da0461726773da07617070726f7665da0d7472616e736665725f66726f6dda0c6d61696e5f6163636f756e74630000000000000000000000000200000043000000732200000074006a0164018301010074026a0164028301010074036a016403830101006400530029044eda11636f6e5f7265666c6563747461755f7632da4066663631353434656139346561616562356466303865643836336334613933386539313239616261366365656535663331623636383162646564653131623839da1a636f6e5f7265666c6563747461755f76325f74726561737572792904da125f5f616c6c6f7765645f63757272656e6379da03736574da0a5f5f6f70657261746f72da0a5f5f7472656173757279a90072180000007218000000da00da045f5f5f5f0d000000730800000000010a0104010601721a0000002904da0b6e616d655f6f665f6e6674da13636f6c6c656374696f6e5f636f6e7472616374720b000000da0e63757272656e63795f7072696365630400000000000000050000000600000043000000736e0000007c0264016b04731074006402830182017c0364016b047320740064038301820174016a027c0183017d0474016a037c0474048302733e74006404830182017c046a057c007c0274066a0774066a0864058d0401007c027c0364069c02740974066a087c017c0066033c006400530029074e72060000007a1f43616e6e6f742073656c6c206e65676174697665204e465420616d6f756e747a2243616e6e6f742073656c6c20666f72206e656761746976652062616c616e636573217a1d496e76616c696420636f6c6c656374696f6e20696e746572666163652129047204000000720b000000720c00000072100000002902720b000000da057072696365290ada0e417373657274696f6e4572726f72da0149da0d696d706f72745f6d6f64756c65da11656e666f7263655f696e74657266616365da1b666f726365645f636f6c6c656374696f6e5f696e74657266616365720f000000da03637478da0474686973da0663616c6c6572da085f5f6d61726b65742905721b000000721c000000720b000000721d000000da0a636f6c6c656374696f6e721800000072180000007219000000da0873656c6c5f6e66741400000073100000000003100110010a010e0106010c010a0272290000002902721b000000721c000000630200000000000000040000000500000043000000734e000000740074016a027c017c00660319007d0274036a047c0183017d037c036a057c007c026401190074016a0264028d03010064037c026404190064059c02740074016a027c017c0066033c006400530029064e720b00000029037204000000720b000000720c0000007206000000721e0000002902720b000000721e000000290672270000007224000000722600000072200000007221000000720a0000002904721b000000721c000000da0c6d61726b65745f656e7472797228000000721800000072180000007219000000da0a726566756e645f6e667422000000730c000000000210010a010c010a010201722b00000029047204000000721c000000da0673656c6c6572720b00000063040000000000000008000000050000004300000073fa0000007c0364016b047310740064028301820174017c027c017c0066031900640319007c036b05732e740064048301820174026a037c0183017d0474026a0374046a05830083017d0574026a067c0474078302735a740064058301820174017c027c017c0066031900640619007c03140064071b00640814007d067c056a0874017c027c017c0066031900640619007c0314007c0618007c0274096a0a64098d0301007c056a087c06740b6a05830074096a0a64098d03010074017c027c017c00660319007d077c07640319007c0318007c0764061900640a9c0274017c027c017c0066033c007c046a0c7c007c0374096a0a640b8d03010064005300290c4e72060000007a1e43616e6e6f7420627579206e65676174697665204e465420616d6f756e74720b0000007a134e6f7420656e6f75676820666f722073616c657a1d496e76616c696420636f6c6c656374696f6e20696e7465726661636521721e000000e964000000e9010000002903da05616d6f7574720c00000072100000002902720b000000721e00000029037204000000720b000000720c000000290d721f0000007227000000722000000072210000007214000000da0367657472220000007223000000720f000000722400000072260000007217000000720a00000029087204000000721c000000722c000000720b0000007228000000da0863757272656e6379da03666565da106f6c645f6d61726b65745f656e747279721800000072180000007219000000da076275795f6e66742c000000731c0000000002100110010e010a010e010e0106021e011001180116020e022002723400000029017203000000630100000000000000010000000200000043000000732400000074006a0174026a0383006b027316740464018301820174056a067c00830101006400530029024e7a1d4f6e6c7920746865206f70657261746f722063616e20646f207468697329077224000000722600000072160000007230000000721f0000007214000000721500000029017203000000721800000072180000007219000000da176368616e67655f616c6c6f7765645f63757272656e63794200000073040000000002160172350000002901da0761646472657373630100000000000000010000000200000043000000732400000074006a0174026a0383006b027316740464018301820174056a067c00830101006400530029024e7a1d4f6e6c7920746865206f70657261746f722063616e20646f207468697329077224000000722600000072160000007230000000721f0000007217000000721500000029017236000000721800000072180000007219000000da0f6368616e67655f7472656173757279480000007304000000000216017237000000630100000000000000010000000200000043000000732400000074006a0174026a0383006b027316740464018301820174026a057c00830101006400530029024e7a1d4f6e6c7920746865206f70657261746f722063616e20646f207468697329067224000000722600000072160000007230000000721f000000721500000029017236000000721800000072180000007219000000da0f6368616e67655f6f70657261746f724e00000073040000000002160172380000004e29037204000000720b000000720c0000002903720b0000007204000000720c00000029047204000000720b000000720c00000072100000002915da09696d706f72746c69627220000000da085661726961626c6572140000007216000000da044861736872270000007217000000da0446756e637223000000721a000000da085f5f6578706f7274da03737472da03696e74da05666c6f61747229000000722b00000072340000007235000000723700000072380000007218000000721800000072180000007219000000da083c6d6f64756c653e01000000732e0000000401040108010c01060108010c01060116010c03080706010601100c060112090601161506011005060110050601