tx · G7pT9pBJ4LG7FMkT6rUYr3ou9jvsUetXM27REm4w9iXW 3N3nfqFcxXfd3T18V9icDdh58MJ9wQ2k2xx: -0.00600000 Waves 2024.12.14 22:40 [3414697] smart account 3N3nfqFcxXfd3T18V9icDdh58MJ9wQ2k2xx > SELF 0.00000000 Waves
{ "type": 13, "id": "G7pT9pBJ4LG7FMkT6rUYr3ou9jvsUetXM27REm4w9iXW", "fee": 600000, "feeAssetId": null, "timestamp": 1734205235950, "version": 2, "chainId": 84, "sender": "3N3nfqFcxXfd3T18V9icDdh58MJ9wQ2k2xx", "senderPublicKey": "UGqkWsCpv7xRVXkQRXyLd6pWPDtYGXmPip7FxSd1pAu", "proofs": [ "4kS2ZpNCcK9U6phkwEFbPijhRm6PexhN1KTMU65HqVL6TAfemoGsjoW6HFzLPxgvb7HzdLvCRztYnJxWocZGUzKF" ], "script": "base64:BgIWCAISAwoBCBIDCgEBEgMKAQgSAwoBCBcAA1NFUAICX18ABWNoYWluCQDJAQIJAMoBAggFBHRoaXMFYnl0ZXMAAQABABZkZWZhdWx0UmVzdDJBZGRyZXNzU3RyBAckbWF0Y2gwBQVjaGFpbgMJAAACAQFXBQckbWF0Y2gwAiMzUEZ3WXRhOGJpRXozMXpwZUZlNURKSzh3RTV0clNwUVZGOAMJAAACAQFUBQckbWF0Y2gwAiMzTjdVdVlhcjYyNjRQNThGQmhWV0tQUUFoNFl1YTJoZ25ndgkAAgECDVVua25vd24gY2hhaW4BD2dldFN0cmluZ09yRmFpbAIHYWRkcmVzcwNrZXkJARN2YWx1ZU9yRXJyb3JNZXNzYWdlAgkAnQgCBQdhZGRyZXNzBQNrZXkJALkJAgkAzAgCAgptYW5kYXRvcnkgCQDMCAIJAKUIAQUHYWRkcmVzcwkAzAgCAgEuCQDMCAIFA2tleQkAzAgCAg8gaXMgbm90IGRlZmluZWQFA25pbAIAABBJZHhDZmdBY3JlczJEYXBwAAEADUlkeENmZ1dsZ0RhcHAAAgEKa2V5UmVzdENmZwACD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compacted Prev: 8gHkNkGLT1BJLFhdMqDk2sNaz4oEQ82wuM8K85ewycDE Next: C3sLkjhp4nMZh5gCsKeL1pVwqYh25fQmjPwYx8CnUqKM Diff:
Old | New | Differences | |
---|---|---|---|
88 | 88 | if ((prologResult == prologResult)) | |
89 | 89 | then if ((0 >= price)) | |
90 | 90 | then throw("Price should be positive") | |
91 | - | else if ((size(i.payments) != | |
92 | - | then throw("Exactly | |
91 | + | else if ((size(i.payments) != 1)) | |
92 | + | then throw("Exactly 1 payment required") | |
93 | 93 | else { | |
94 | 94 | let pmt = value(i.payments[0]) | |
95 | 95 | if ((pmt.amount != 1)) | |
96 | 96 | then throw("NFT token should be attached as 1st payment") | |
97 | 97 | else { | |
98 | - | let pmt1 = value(i.payments[1]) | |
99 | - | let wAssetId = valueOrErrorMessage(pmt1.assetId, "No WAVES payments allowed") | |
100 | - | if ((wAssetId != wlgAssetId)) | |
101 | - | then throw("Only WLGOLD payments are accepted as 2nd payment") | |
98 | + | let assetId = valueOrErrorMessage(pmt.assetId, "No WAVES payments allowed") | |
99 | + | let asset = value(assetInfo(assetId)) | |
100 | + | let assetIdStr = toBase58String(assetId) | |
101 | + | let addr = toString(i.caller) | |
102 | + | if ((asset.issuer != acres2Contract)) | |
103 | + | then throw("Only WavesLands NFT tokens are accepted") | |
102 | 104 | else { | |
103 | - | let change = (pmt1.amount - (price / 20)) | |
104 | - | if ((0 > change)) | |
105 | - | then throw("5% fee should be attached as 2nd payment") | |
106 | - | else { | |
107 | - | let changeActions = if ((change > 0)) | |
108 | - | then [ScriptTransfer(i.caller, change, wlgAssetId)] | |
109 | - | else nil | |
110 | - | let assetId = valueOrErrorMessage(pmt.assetId, "No WAVES payments allowed") | |
111 | - | let asset = value(assetInfo(assetId)) | |
112 | - | let assetIdStr = toBase58String(assetId) | |
113 | - | let addr = toString(i.caller) | |
114 | - | if ((asset.issuer != acres2Contract)) | |
115 | - | then throw("Only WavesLands NFT tokens are accepted") | |
116 | - | else { | |
117 | - | let nftsKey = keyAssetIdsBySeller(addr) | |
118 | - | let nftsStr = valueOrElse(getString(nftsKey), "") | |
119 | - | let nfts = if ((nftsStr != "")) | |
120 | - | then split_51C(value(nftsStr), "_") | |
121 | - | else nil | |
122 | - | $Tuple2(([IntegerEntry(keyPriceByAssetId(assetIdStr), price), StringEntry(keySellerByAssetId(assetIdStr), addr), StringEntry(nftsKey, makeString_11C((nfts :+ assetIdStr), "_"))] ++ changeActions), prologResult) | |
123 | - | } | |
124 | - | } | |
105 | + | let nftsKey = keyAssetIdsBySeller(addr) | |
106 | + | let nftsStr = valueOrElse(getString(nftsKey), "") | |
107 | + | let nfts = if ((nftsStr != "")) | |
108 | + | then split_51C(value(nftsStr), "_") | |
109 | + | else nil | |
110 | + | $Tuple2([IntegerEntry(keyPriceByAssetId(assetIdStr), price), StringEntry(keySellerByAssetId(assetIdStr), addr), StringEntry(nftsKey, makeString_11C((nfts :+ assetIdStr), "_"))], prologResult) | |
125 | 111 | } | |
126 | 112 | } | |
127 | 113 | } | |
149 | 135 | then StringEntry(nftsKey, makeString_11C(removeByIndex(nfts, value(idx)), "_")) | |
150 | 136 | else DeleteEntry(nftsKey) | |
151 | 137 | let price = valueOrErrorMessage(getInteger(keyPriceByAssetId(assetIdStr)), ("You don't have sell order for " + assetIdStr)) | |
152 | - | $Tuple2([listAction, DeleteEntry(keySellerByAssetId(assetIdStr)), DeleteEntry(keyPriceByAssetId(assetIdStr)), ScriptTransfer(i.caller, 1, fromBase58String(assetIdStr)) | |
138 | + | $Tuple2([listAction, DeleteEntry(keySellerByAssetId(assetIdStr)), DeleteEntry(keyPriceByAssetId(assetIdStr)), ScriptTransfer(i.caller, 1, fromBase58String(assetIdStr))], prologResult) | |
153 | 139 | } | |
154 | 140 | } | |
155 | 141 | else throw("Strict value is not equal to itself.") | |
194 | 180 | let fee = (price / 20) | |
195 | 181 | let forTeam = (fee / 2) | |
196 | 182 | let wlgRemain = asInt(invoke(wlgContract, "burnWlgold", [(fee - forTeam)], nil)) | |
197 | - | $Tuple2(([listAction, DeleteEntry(keySellerByAssetId(assetIdStr)), DeleteEntry(keyPriceByAssetId(assetIdStr)), ScriptTransfer(addressFromStringValue(seller), price, wlgAssetId), ScriptTransfer(addressFromStringValue(getStringValue(wlgContract, teamAddrKey)), forTeam, wlgAssetId), ScriptTransfer(i.caller, 1, fromBase58String(assetIdStr))] ++ changeActions), prologResult) | |
183 | + | $Tuple2(([listAction, DeleteEntry(keySellerByAssetId(assetIdStr)), DeleteEntry(keyPriceByAssetId(assetIdStr)), ScriptTransfer(addressFromStringValue(seller), (price - fee), wlgAssetId), ScriptTransfer(addressFromStringValue(getStringValue(wlgContract, teamAddrKey)), forTeam, wlgAssetId), ScriptTransfer(i.caller, 1, fromBase58String(assetIdStr))] ++ changeActions), prologResult) | |
198 | 184 | } | |
199 | 185 | } | |
200 | 186 | } |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 6 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let SEP = "__" | |
5 | 5 | ||
6 | 6 | let chain = take(drop(this.bytes, 1), 1) | |
7 | 7 | ||
8 | 8 | let defaultRest2AddressStr = match chain { | |
9 | 9 | case _ => | |
10 | 10 | if ((base58'2W' == $match0)) | |
11 | 11 | then "3PFwYta8biEz31zpeFe5DJK8wE5trSpQVF8" | |
12 | 12 | else if ((base58'2T' == $match0)) | |
13 | 13 | then "3N7UuYar6264P58FBhVWKPQAh4Yua2hgngv" | |
14 | 14 | else throw("Unknown chain") | |
15 | 15 | } | |
16 | 16 | ||
17 | 17 | func getStringOrFail (address,key) = valueOrErrorMessage(getString(address, key), makeString(["mandatory ", toString(address), ".", key, " is not defined"], "")) | |
18 | 18 | ||
19 | 19 | ||
20 | 20 | let IdxCfgAcres2Dapp = 1 | |
21 | 21 | ||
22 | 22 | let IdxCfgWlgDapp = 2 | |
23 | 23 | ||
24 | 24 | func keyRestCfg () = "%s__restConfig" | |
25 | 25 | ||
26 | 26 | ||
27 | 27 | func keyRest2Address () = "%s__rest2Addr" | |
28 | 28 | ||
29 | 29 | ||
30 | 30 | func readRestCfgOrFail (rest) = split_4C(getStringOrFail(rest, keyRestCfg()), SEP) | |
31 | 31 | ||
32 | 32 | ||
33 | 33 | func getContractAddressOrFail (rest2Cfg,idx) = valueOrErrorMessage(addressFromString(rest2Cfg[idx]), ("Rest cfg doesn't contain address at index " + toString(idx))) | |
34 | 34 | ||
35 | 35 | ||
36 | 36 | let rest2Contract = addressFromStringValue(valueOrElse(getString(this, keyRest2Address()), defaultRest2AddressStr)) | |
37 | 37 | ||
38 | 38 | let rest2Cfg = readRestCfgOrFail(rest2Contract) | |
39 | 39 | ||
40 | 40 | let acres2Contract = getContractAddressOrFail(rest2Cfg, IdxCfgAcres2Dapp) | |
41 | 41 | ||
42 | 42 | let wlgContract = getContractAddressOrFail(rest2Cfg, IdxCfgWlgDapp) | |
43 | 43 | ||
44 | 44 | let wlgAssetIdKey = "wlg_assetId" | |
45 | 45 | ||
46 | 46 | let wlgAssetId = valueOrErrorMessage(getBinary(wlgContract, wlgAssetIdKey), "WLGOLD is not issued yet") | |
47 | 47 | ||
48 | 48 | func keySellerByAssetId (assetId) = ("seller_" + assetId) | |
49 | 49 | ||
50 | 50 | ||
51 | 51 | func keyPriceByAssetId (assetId) = ("price_" + assetId) | |
52 | 52 | ||
53 | 53 | ||
54 | 54 | func keyAssetIdsBySeller (addr) = ("assetIds_" + addr) | |
55 | 55 | ||
56 | 56 | ||
57 | 57 | func asInt (v) = match v { | |
58 | 58 | case n: Int => | |
59 | 59 | n | |
60 | 60 | case _ => | |
61 | 61 | throw("fail to cast into Int") | |
62 | 62 | } | |
63 | 63 | ||
64 | 64 | ||
65 | 65 | func fixedPoint (val,decimals) = { | |
66 | 66 | let tenPow = pow(10, 0, decimals, 0, 0, DOWN) | |
67 | 67 | let lowPart = toString((val % tenPow)) | |
68 | 68 | let zeroes = drop(toString(tenPow), (1 + size(lowPart))) | |
69 | 69 | (((toString((val / tenPow)) + ".") + zeroes) + lowPart) | |
70 | 70 | } | |
71 | 71 | ||
72 | 72 | ||
73 | 73 | let teamAddrKey = "teamAddr" | |
74 | 74 | ||
75 | 75 | func prolog2 () = asInt(reentrantInvoke(acres2Contract, "saveLastTx", nil, nil)) | |
76 | 76 | ||
77 | 77 | ||
78 | 78 | @Callable(i) | |
79 | 79 | func constructorV1 (rest2Addr) = if ((i.caller != this)) | |
80 | 80 | then throw("Permission denied") | |
81 | 81 | else [StringEntry(keyRest2Address(), rest2Addr)] | |
82 | 82 | ||
83 | 83 | ||
84 | 84 | ||
85 | 85 | @Callable(i) | |
86 | 86 | func placeSellOrder (price) = { | |
87 | 87 | let prologResult = prolog2() | |
88 | 88 | if ((prologResult == prologResult)) | |
89 | 89 | then if ((0 >= price)) | |
90 | 90 | then throw("Price should be positive") | |
91 | - | else if ((size(i.payments) != | |
92 | - | then throw("Exactly | |
91 | + | else if ((size(i.payments) != 1)) | |
92 | + | then throw("Exactly 1 payment required") | |
93 | 93 | else { | |
94 | 94 | let pmt = value(i.payments[0]) | |
95 | 95 | if ((pmt.amount != 1)) | |
96 | 96 | then throw("NFT token should be attached as 1st payment") | |
97 | 97 | else { | |
98 | - | let pmt1 = value(i.payments[1]) | |
99 | - | let wAssetId = valueOrErrorMessage(pmt1.assetId, "No WAVES payments allowed") | |
100 | - | if ((wAssetId != wlgAssetId)) | |
101 | - | then throw("Only WLGOLD payments are accepted as 2nd payment") | |
98 | + | let assetId = valueOrErrorMessage(pmt.assetId, "No WAVES payments allowed") | |
99 | + | let asset = value(assetInfo(assetId)) | |
100 | + | let assetIdStr = toBase58String(assetId) | |
101 | + | let addr = toString(i.caller) | |
102 | + | if ((asset.issuer != acres2Contract)) | |
103 | + | then throw("Only WavesLands NFT tokens are accepted") | |
102 | 104 | else { | |
103 | - | let change = (pmt1.amount - (price / 20)) | |
104 | - | if ((0 > change)) | |
105 | - | then throw("5% fee should be attached as 2nd payment") | |
106 | - | else { | |
107 | - | let changeActions = if ((change > 0)) | |
108 | - | then [ScriptTransfer(i.caller, change, wlgAssetId)] | |
109 | - | else nil | |
110 | - | let assetId = valueOrErrorMessage(pmt.assetId, "No WAVES payments allowed") | |
111 | - | let asset = value(assetInfo(assetId)) | |
112 | - | let assetIdStr = toBase58String(assetId) | |
113 | - | let addr = toString(i.caller) | |
114 | - | if ((asset.issuer != acres2Contract)) | |
115 | - | then throw("Only WavesLands NFT tokens are accepted") | |
116 | - | else { | |
117 | - | let nftsKey = keyAssetIdsBySeller(addr) | |
118 | - | let nftsStr = valueOrElse(getString(nftsKey), "") | |
119 | - | let nfts = if ((nftsStr != "")) | |
120 | - | then split_51C(value(nftsStr), "_") | |
121 | - | else nil | |
122 | - | $Tuple2(([IntegerEntry(keyPriceByAssetId(assetIdStr), price), StringEntry(keySellerByAssetId(assetIdStr), addr), StringEntry(nftsKey, makeString_11C((nfts :+ assetIdStr), "_"))] ++ changeActions), prologResult) | |
123 | - | } | |
124 | - | } | |
105 | + | let nftsKey = keyAssetIdsBySeller(addr) | |
106 | + | let nftsStr = valueOrElse(getString(nftsKey), "") | |
107 | + | let nfts = if ((nftsStr != "")) | |
108 | + | then split_51C(value(nftsStr), "_") | |
109 | + | else nil | |
110 | + | $Tuple2([IntegerEntry(keyPriceByAssetId(assetIdStr), price), StringEntry(keySellerByAssetId(assetIdStr), addr), StringEntry(nftsKey, makeString_11C((nfts :+ assetIdStr), "_"))], prologResult) | |
125 | 111 | } | |
126 | 112 | } | |
127 | 113 | } | |
128 | 114 | else throw("Strict value is not equal to itself.") | |
129 | 115 | } | |
130 | 116 | ||
131 | 117 | ||
132 | 118 | ||
133 | 119 | @Callable(i) | |
134 | 120 | func cancelSellOrder (assetIdStr) = { | |
135 | 121 | let prologResult = prolog2() | |
136 | 122 | if ((prologResult == prologResult)) | |
137 | 123 | then { | |
138 | 124 | let addr = toString(i.caller) | |
139 | 125 | let nftsKey = keyAssetIdsBySeller(addr) | |
140 | 126 | let nftsStr = valueOrElse(getString(nftsKey), "") | |
141 | 127 | let nfts = if ((nftsStr != "")) | |
142 | 128 | then split_51C(value(nftsStr), "_") | |
143 | 129 | else nil | |
144 | 130 | let idx = indexOf(nfts, assetIdStr) | |
145 | 131 | if (!(isDefined(idx))) | |
146 | 132 | then throw(("Your don't have sell order for " + assetIdStr)) | |
147 | 133 | else { | |
148 | 134 | let listAction = if ((size(nfts) > 1)) | |
149 | 135 | then StringEntry(nftsKey, makeString_11C(removeByIndex(nfts, value(idx)), "_")) | |
150 | 136 | else DeleteEntry(nftsKey) | |
151 | 137 | let price = valueOrErrorMessage(getInteger(keyPriceByAssetId(assetIdStr)), ("You don't have sell order for " + assetIdStr)) | |
152 | - | $Tuple2([listAction, DeleteEntry(keySellerByAssetId(assetIdStr)), DeleteEntry(keyPriceByAssetId(assetIdStr)), ScriptTransfer(i.caller, 1, fromBase58String(assetIdStr)) | |
138 | + | $Tuple2([listAction, DeleteEntry(keySellerByAssetId(assetIdStr)), DeleteEntry(keyPriceByAssetId(assetIdStr)), ScriptTransfer(i.caller, 1, fromBase58String(assetIdStr))], prologResult) | |
153 | 139 | } | |
154 | 140 | } | |
155 | 141 | else throw("Strict value is not equal to itself.") | |
156 | 142 | } | |
157 | 143 | ||
158 | 144 | ||
159 | 145 | ||
160 | 146 | @Callable(i) | |
161 | 147 | func acceptSellOrder (assetIdStr) = { | |
162 | 148 | let prologResult = prolog2() | |
163 | 149 | if ((prologResult == prologResult)) | |
164 | 150 | then if ((size(i.payments) != 1)) | |
165 | 151 | then throw("exactly 1 payment must be attached") | |
166 | 152 | else { | |
167 | 153 | let pmt = i.payments[0] | |
168 | 154 | if (if (!(isDefined(pmt.assetId))) | |
169 | 155 | then true | |
170 | 156 | else (value(pmt.assetId) != wlgAssetId)) | |
171 | 157 | then throw("WLGOLD payments only!") | |
172 | 158 | else { | |
173 | 159 | let price = valueOrErrorMessage(getInteger(keyPriceByAssetId(assetIdStr)), (("NFT " + assetIdStr) + " is not selling")) | |
174 | 160 | let change = (pmt.amount - price) | |
175 | 161 | if ((0 > change)) | |
176 | 162 | then throw((("Payment attached doesn't cover sell price of " + fixedPoint(price, 8)) + " WLGOLD")) | |
177 | 163 | else { | |
178 | 164 | let changeActions = if ((change > 0)) | |
179 | 165 | then [ScriptTransfer(i.caller, change, wlgAssetId)] | |
180 | 166 | else nil | |
181 | 167 | let seller = valueOrErrorMessage(getString(keySellerByAssetId(assetIdStr)), (("NFT " + assetIdStr) + " is not selling")) | |
182 | 168 | let nftsKey = keyAssetIdsBySeller(seller) | |
183 | 169 | let nftsStr = valueOrElse(getString(nftsKey), "") | |
184 | 170 | let nfts = if ((nftsStr != "")) | |
185 | 171 | then split_51C(value(nftsStr), "_") | |
186 | 172 | else nil | |
187 | 173 | let idx = indexOf(nfts, assetIdStr) | |
188 | 174 | if (!(isDefined(idx))) | |
189 | 175 | then throw(("Seller don't have sell order for " + assetIdStr)) | |
190 | 176 | else { | |
191 | 177 | let listAction = if ((size(nfts) > 1)) | |
192 | 178 | then StringEntry(nftsKey, makeString_11C(removeByIndex(nfts, value(idx)), "_")) | |
193 | 179 | else DeleteEntry(nftsKey) | |
194 | 180 | let fee = (price / 20) | |
195 | 181 | let forTeam = (fee / 2) | |
196 | 182 | let wlgRemain = asInt(invoke(wlgContract, "burnWlgold", [(fee - forTeam)], nil)) | |
197 | - | $Tuple2(([listAction, DeleteEntry(keySellerByAssetId(assetIdStr)), DeleteEntry(keyPriceByAssetId(assetIdStr)), ScriptTransfer(addressFromStringValue(seller), price, wlgAssetId), ScriptTransfer(addressFromStringValue(getStringValue(wlgContract, teamAddrKey)), forTeam, wlgAssetId), ScriptTransfer(i.caller, 1, fromBase58String(assetIdStr))] ++ changeActions), prologResult) | |
183 | + | $Tuple2(([listAction, DeleteEntry(keySellerByAssetId(assetIdStr)), DeleteEntry(keyPriceByAssetId(assetIdStr)), ScriptTransfer(addressFromStringValue(seller), (price - fee), wlgAssetId), ScriptTransfer(addressFromStringValue(getStringValue(wlgContract, teamAddrKey)), forTeam, wlgAssetId), ScriptTransfer(i.caller, 1, fromBase58String(assetIdStr))] ++ changeActions), prologResult) | |
198 | 184 | } | |
199 | 185 | } | |
200 | 186 | } | |
201 | 187 | } | |
202 | 188 | else throw("Strict value is not equal to itself.") | |
203 | 189 | } | |
204 | 190 | ||
205 | 191 |
github/deemru/w8io/169f3d6 61.25 ms ◑