Contract con_test_collection_add_1


Contract Code


  
1 I = importlib
2
3 collection_name = Variable()
4 collection_owner = Variable()
5 collection_nfts = Hash(default_value=0)
6 collection_balances = Hash(default_value=0)
7 collection_balances_approvals = Hash(default_value=0)
8
9 @construct
10 def seed():
11 collection_name.set("testset")
12 collection_owner.set(ctx.caller)
13
14 @export
15 def mint_nft(name: str, description: str, ipfs_image_url: str, metadata: dict, amount: int):
16 assert name != "", "Name cannot be empty"
17 assert collection_nfts[name] == 0, "Name already exists"
18 assert amount > 0, "You cannot transfer negative amounts"
19 assert collection_owner.get() == ctx.caller, "Only the collection owner can mint NFTs"
20
21 collection_nfts[name] = {"description": description, "ipfs_image_url": ipfs_image_url, "metadata": metadata, "amount": amount}
22 collection_balances[ctx.caller, name] = amount
23
24 @export
25 def transfer(name: str, amount:int, to: str):
26 assert amount > 0, "You cannot transfer negative amounts"
27 assert name != "", "Please specify the name of the NFT you want to transfer"
28 assert collection_balances[ctx.caller, name] >= amount, "You dont have enough NFTs to send"
29
30 collection_balances[ctx.caller, name] -= amount
31 collection_balances[to, name] += amount # Adds amount to receiver
32
33 @export
34 def approve(amount: int, name: str, to: str):
35 assert amount > 0, "Cannot approve negative amounts"
36
37 collection_balances_approvals[ctx.caller, to, name] += amount
38
39 @export
40 def transfer_from(name:str, amount:int, to: str, main_account: str):
41 assert amount > 0, "Cannot send negative balances!"
42
43 assert collection_balances_approvals[main_account, to, name] >= amount, "Not enough NFTs approved to send! You have {} and are trying to spend {}".format(collection_balances_approvals[main_account, to, name], amount)
44 assert collection_balances[main_account, name] >= amount, "Not enough NFTs to send!"
45
46 collection_balances_approvals[main_account, to, name] -= amount
47 collection_balances[main_account, name] -= amount
48
49 collection_balances[to, name] += amount
50
51 @export
52 def setup_redeem(name: str, redeem_type: str, redeem_contract: str, redeem_amount: float):
53 assert collection_owner.get() == ctx.caller, "You are not the collection creator"
54 assert collection_nfts[name] != 0, f"NFT {name} doesnt exist"
55 assert redeem_type.lower() in ["lp", "token"], "Only redeem types lp and token supported"
56
57 nft_data = collection_nfts[name]
58
59 assert "redeem_type" not in nft_data, "NFT is already redeemable!"
60
61 nft_data["redeem_type"] = redeem_type.lower()
62 nft_data["redeem_contract"] = redeem_contract
63 nft_data["redeem_amount"] = redeem_amount
64
65 collection_nfts[name] = nft_data
66
67 # Transfer token
68 if redeem_type.lower() == "token":
69 I.import_module(redeem_contract).transfer_from(
70 amount=redeem_amount,
71 to=ctx.this,
72 main_account=ctx.caller)
73
74 # Transfer LP
75 elif redeem_type.lower() == "lp":
76 I.import_module("con_rocketswap_official_v1_1").transfer_liquidity_from(
77 contract=redeem_contract,
78 amount=redeem_amount,
79 to=ctx.this,
80 main_account=ctx.caller)
81
82 @export
83 def redeem(name: str):
84 assert collection_nfts[name] != 0, f"NFT {name} doesnt exist"
85
86 nft_data = collection_nfts[name]
87
88 assert "redeem_type" in nft_data, "NFT is not redeemable!"
89
90 # Get redeem amount for one NFT
91 redeem_amount = nft_data["redeem_amount"]
92 nft_amount = nft_data["amount"]
93 amount = redeem_amount / nft_amount
94
95 # Transfer redeemable amount
96 if nft_data["redeem_type"].lower() == "token":
97 I.import_module(nft_data["redeem_contract"]).transfer(amount=amount, to=ctx.caller)
98 elif nft_data["redeem_type"].lower() == "lp":
99 I.import_module("con_rocketswap_official_v1_1").transfer_liquidity(contract=nft_data["redeem_contract"], amount=amount, to=ctx.caller)
100
101 # Burn NFT
102 approve(name=name, amount=1, to=ctx.this)
103 transfer_from(name=name, amount=1, to=ctx.this, main_account=ctx.caller)

Byte Code

e3000000000000000000000000070000004000000073f200000065005a0165026400640164028d025a0365026400640364028d025a04650564046400640564068d035a06650564046400640764068d035a07650564046400640864068d035a086409640a84005a09650a64008301650b650b650b650c650d640b9c05640c640d840483015a0e650a64008301650b650d650b640e9c03640f6410840483015a0f650a64008301650d650b650b64119c0364126413840483015a10650a64008301650b650d650b650b64149c0464156416840483015a11650a64008301650b650b650b651264179c0464186419840483015a13650a64008301650b641a9c01641b641c840483015a14641d5300291eda19636f6e5f746573745f636f6c6c656374696f6e5f6164645f31da0f636f6c6c656374696f6e5f6e616d652902da08636f6e7472616374da046e616d65da10636f6c6c656374696f6e5f6f776e6572e900000000da0f636f6c6c656374696f6e5f6e6674732903da0d64656661756c745f76616c756572030000007204000000da13636f6c6c656374696f6e5f62616c616e636573da1d636f6c6c656374696f6e5f62616c616e6365735f617070726f76616c73630000000000000000000000000200000043000000731a00000074006a0164018301010074026a0174036a04830101006400530029024eda07746573747365742905da115f5f636f6c6c656374696f6e5f6e616d65da03736574da125f5f636f6c6c656374696f6e5f6f776e6572da03637478da0663616c6c6572a90072110000007211000000da00da045f5f5f5f0e000000730400000000010a01721300000029057204000000da0b6465736372697074696f6eda0e697066735f696d6167655f75726cda086d65746164617461da06616d6f756e74630500000000000000050000000500000043000000736e0000007c0064016b037310740064028301820174017c00190064036b02732474006404830182017c0464036b047334740064058301820174026a03830074046a056b02734a74006406830182017c017c027c037c0464079c0474017c003c007c04740674046a057c0066023c006400530029084e72120000007a144e616d652063616e6e6f7420626520656d70747972060000007a134e616d6520616c7265616479206578697374737a24596f752063616e6e6f74207472616e73666572206e6567617469766520616d6f756e74737a274f6e6c792074686520636f6c6c656374696f6e206f776e65722063616e206d696e74204e465473290472140000007215000000721600000072170000002907da0e417373657274696f6e4572726f72da115f5f636f6c6c656374696f6e5f6e667473720e000000da03676574720f0000007210000000da155f5f636f6c6c656374696f6e5f62616c616e636573290572040000007214000000721500000072160000007217000000721100000072110000007212000000da086d696e745f6e667413000000731000000000031001140110010601100102011001721c000000290372040000007217000000da02746f63030000000000000003000000040000004300000073680000007c0164016b04731074006402830182017c0064036b0373207400640483018201740174026a037c00660219007c016b05733a7400640583018201740174026a037c006602050019007c01380003003c0074017c027c006602050019007c01370003003c006400530029064e72060000007a24596f752063616e6e6f74207472616e73666572206e6567617469766520616d6f756e747372120000007a37506c65617365207370656369667920746865206e616d65206f6620746865204e465420796f752077616e7420746f207472616e736665727a21596f7520646f6e74206861766520656e6f756768204e46547320746f2073656e6429047218000000721b000000720f0000007210000000290372040000007217000000721d000000721100000072110000007212000000da087472616e7366657220000000730c0000000002100110010c010e011601721e000000290372170000007204000000721d000000630300000000000000030000000400000043000000732c0000007c0064016b0473107400640283018201740174026a037c027c016603050019007c00370003003c006400530029034e72060000007a1f43616e6e6f7420617070726f7665206e6567617469766520616d6f756e747329047218000000da1f5f5f636f6c6c656374696f6e5f62616c616e6365735f617070726f76616c73720f0000007210000000290372170000007204000000721d000000721100000072110000007212000000da07617070726f76652a0000007304000000000210017220000000290472040000007217000000721d000000da0c6d61696e5f6163636f756e7463040000000000000004000000060000004300000073960000007c0164016b047310740064028301820174017c037c027c00660319007c016b05733c740064036a0274017c037c027c00660319007c0183028301820174037c037c00660219007c016b057354740064048301820174017c037c027c006603050019007c01380003003c0074037c037c006602050019007c01380003003c0074037c027c006602050019007c01370003003c006400530029054e72060000007a1e43616e6e6f742073656e64206e656761746976652062616c616e636573217a484e6f7420656e6f756768204e46547320617070726f76656420746f2073656e642120596f752068617665207b7d20616e642061726520747279696e6720746f207370656e64207b7d7a184e6f7420656e6f756768204e46547320746f2073656e642129047218000000721f000000da06666f726d6174721b000000290472040000007217000000721d0000007221000000721100000072110000007212000000da0d7472616e736665725f66726f6d300000007312000000000210010c010c0114010a010e0116011401722300000029047204000000da0b72656465656d5f74797065da0f72656465656d5f636f6e7472616374da0d72656465656d5f616d6f756e7463040000000000000005000000060000004300000073d600000074006a01830074026a036b027316740464018301820174057c00190064026b037332740464037c009b0064049d03830182017c016a068300640f6b067346740464078301820174057c0019007d0464087c046b07735e74046409830182017c016a0683007c0464083c007c027c04640a3c007c037c04640b3c007c0474057c003c007c016a06830064066b0272aa74076a087c0283016a097c0374026a0a74026a03640c8d0301006e287c016a06830064056b0272d274076a08640d83016a0b7c027c0374026a0a74026a03640e8d0401006400530029104e7a22596f7520617265206e6f742074686520636f6c6c656374696f6e2063726561746f7272060000007a044e4654207a0d20646f65736e74206578697374da026c70da05746f6b656e7a284f6e6c792072656465656d207479706573206c7020616e6420746f6b656e20737570706f7274656472240000007a1a4e465420697320616c72656164792072656465656d61626c65217225000000722600000029037217000000721d0000007221000000da1c636f6e5f726f636b6574737761705f6f6666696369616c5f76315f31290472030000007217000000721d0000007221000000290272270000007228000000290c720e000000721a000000720f000000721000000072180000007219000000da056c6f776572da0149da0d696d706f72745f6d6f64756c657223000000da0474686973da177472616e736665725f6c69717569646974795f66726f6d29057204000000722400000072250000007226000000da086e66745f64617461721100000072110000007212000000da0c73657475705f72656465656d3d00000073240000000003060110011c010e010601080110010c010801080108010c010c0110010c010a01020172300000002901720400000063010000000000000005000000060000004300000073cc00000074007c00190064016b03731c740164027c009b0064039d038301820174007c0019007d0164047c016b06733474016405830182017c01640619007d027c01640719007d037c027c031b007d047c01640419006a02830064086b02727874036a047c016409190083016a057c0474066a07640a8d0201006e2c7c01640419006a028300640b6b0272a474036a04640c83016a087c01640919007c0474066a07640d8d03010074097c00640e74066a0a640f8d030100740b7c00640e74066a0a74066a0764108d0401006400530029114e72060000007a044e4654207a0d20646f65736e7420657869737472240000007a164e4654206973206e6f742072656465656d61626c6521722600000072170000007228000000722500000029027217000000721d00000072270000007229000000290372030000007217000000721d000000e901000000290372040000007217000000721d000000290472040000007217000000721d0000007221000000290c72190000007218000000722a000000722b000000722c000000721e000000720f0000007210000000da127472616e736665725f6c69717569646974797220000000722d000000722300000029057204000000722f0000007226000000da0a6e66745f616d6f756e747217000000721100000072110000007212000000da0672656465656d54000000731c00000000021c0108011001080108010801100110010c0110010a011201100172340000004e2915da09696d706f72746c6962722b000000da085661726961626c65720c000000720e000000da04486173687219000000721b000000721f0000007213000000da085f5f6578706f7274da03737472da0464696374da03696e74721c000000721e00000072200000007223000000da05666c6f6174723000000072340000007211000000721100000072110000007212000000da083c6d6f64756c653e0100000073320000000401040108010401080104010a0104010a0104010a03080506010601120b06011409060114050601160c0601060110150601