tx · 8TZ8LTcVYxQZQ3MyX4qqSysCv14oYSa2XAFmJJJpRM47

3GpJhSPmFdaB1N3nbmGGnqUeC7jSK4iMbG1:  -0.05000000 Gic

2025.06.25 22:50 [6635] smart account 3GpJhSPmFdaB1N3nbmGGnqUeC7jSK4iMbG1 > SELF 0.00000000 Gic

{ "type": 13, "id": "8TZ8LTcVYxQZQ3MyX4qqSysCv14oYSa2XAFmJJJpRM47", "fee": 5000000, "feeAssetId": null, "timestamp": 1750881069128, "version": 2, "chainId": 71, "sender": "3GpJhSPmFdaB1N3nbmGGnqUeC7jSK4iMbG1", "senderPublicKey": "3QpT3yez6M99264RVoDPZZ3oZ7JSPeYduUQDJqdhG82y", "proofs": [ "4aqkevSUYrH8mDXzEDtDfQEvL17ZtpML8gEDyK8vnnoboUBRWMfgZWFw89ab3WCR6mWhsTzVVLCjv9Gs2rGG53aT" ], "script": "base64:AAIFAAAAAAAAABwIAhIDCgEIEgMKAQESBAoCCAgSAwoBARIDCgEIAAAABgAAAAAMYWRtaW5BZGRyZXNzAgAAAA1hZG1pbl9hZGRyZXNzAAAAAANmZWUCAAAAA2ZlZQEAAAAPZ2V0QWRtaW5BZGRyZXNzAAAAAAQAAAAHJG1hdGNoMAkABCIAAAABBQAAAAxhZG1pbkFkZHJlc3MDCQAAAQAAAAIFAAAAByRtYXRjaDACAAAABlN0cmluZwQAAAABdAUAAAAHJG1hdGNoMAUAAAABdAkAAlgAAAABCAUAAAAEdGhpcwAAAAVieXRlcwEAAAAQZ2V0QXNzZXREZWNpbWFscwAAAAEAAAAHYXNzZXRJZAMJAAAAAAAAAgUAAAAHYXNzZXRJZAIAAAADR0lDAAAAAAAAAAAIBAAAAAckbWF0Y2gwCQAD7AAAAAEJAAJZAAAAAQUAAAAHYXNzZXRJZAMJAAABAAAAAgUAAAAHJG1hdGNoMAIAAAAFQXNzZXQEAAAAAWEFAAAAByRtYXRjaDAIBQAAAAFhAAAACGRlY2ltYWxzAAAAAAAAAAAIAQAAABBnZ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gAAAAhpc19zYWxlXwUAAAAKcG10QXNzZXRJZAcJAARMAAAAAgkBAAAAC1N0cmluZ0VudHJ5AAAAAgkAASwAAAACAgAAAAZzYWxlcl8FAAAACnBtdEFzc2V0SWQJAAJYAAAAAQgIBQAAAAFpAAAABmNhbGxlcgAAAAVieXRlcwkABEwAAAACCQEAAAAMSW50ZWdlckVudHJ5AAAAAgkAASwAAAACAgAAAAhoaXN0b3J5XwUAAAAKcG10QXNzZXRJZAUAAAAHbnVtYmVySAkABEwAAAACCQEAAAALU3RyaW5nRW50cnkAAAACCQABLAAAAAIJAAEsAAAAAgIAAAAIaGlzdG9yeV8FAAAACnBtdEFzc2V0SWQJAAGkAAAAAQUAAAAHbnVtYmVySAIAAAADYnV5BQAAAANuaWwAAAABAAAAAnR4AQAAAAZ2ZXJpZnkAAAAACQAB9AAAAAMIBQAAAAJ0eAAAAAlib2R5Qnl0ZXMJAAGRAAAAAggFAAAAAnR4AAAABnByb29mcwAAAAAAAAAAAAgFAAAAAnR4AAAAD3NlbmRlclB1YmxpY0tleawiAYQ=", "height": 6635, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: DnFcsTBvMYcqykihzMRQZb4PaU5CW2tS1E3YLQ7nG9dG Next: none Diff:
OldNewDifferences
11 {-# STDLIB_VERSION 5 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
4-let main = "main_asset"
5-
64 let adminAddress = "admin_address"
75
8-let lp = "lp_asset_"
6+let fee = "fee"
97
10-let pool = "pool__"
11-
12-let farm = "farm__"
13-
14-let staked = "staked_"
15-
16-let rewardClaimed = "reward_claimed_"
17-
18-let depositHeight = "deposit_height_"
19-
20-let farmHeight = "farm_height_"
21-
22-let totalLocked = "total_locked_"
23-
24-let swapFee = "swap_fee"
25-
26-let farmRewardPool = "farm_reward_pool_"
27-
28-let farmApr = "farm_apr_"
29-
30-let farmLockBlocks = "farm_lock_blocks_"
31-
32-let farmTotalStaked = "farm_total_staked_"
33-
34-let blacklistedTokens = "blacklisted_"
35-
36-let totalUsersFarm = "total_users_farm_"
37-
38-let D8 = 100000000
39-
40-let contractAddress = Address(this.bytes)
41-
42-let ac = "activate"
43-
44-let poolAc = "activate_pools"
45-
46-let swapAc = "activate_swap"
47-
48-let liquidityAc = "activate_liquidity"
49-
50-let farmAc = "activate_farms"
51-
52-func kp (asset1,asset2) = (((pool + asset1) + "_") + asset2)
53-
54-
55-func fk (asset1,asset2) = (((farm + asset1) + "_") + asset2)
56-
57-
58-func sk (asset1,asset2,address) = (((staked + kp(asset1, asset2)) + "_") + address)
59-
60-
61-func rk (asset1,asset2,address) = (((rewardClaimed + kp(asset1, asset2)) + "_") + address)
62-
63-
64-func dh (asset1,asset2,address) = (((depositHeight + kp(asset1, asset2)) + "_") + address)
65-
66-
67-func fh (asset1,asset2,address) = (((farmHeight + kp(asset1, asset2)) + "_") + address)
68-
69-
70-func isValidAsset (assetId) = if ((assetId == "GIC"))
71- then true
72- else match assetInfo(fromBase58String(assetId)) {
73- case a: Asset =>
74- true
75- case _ =>
76- false
77- }
78-
79-
80-func isBlacklisted (assetId) = valueOrElse(getBoolean(this, (blacklistedTokens + assetId)), false)
8+func getAdminAddress () = match getString(adminAddress) {
9+ case t: String =>
10+ t
11+ case _ =>
12+ toBase58String(this.bytes)
13+}
8114
8215
8316 func getAssetDecimals (assetId) = if ((assetId == "GIC"))
9023 }
9124
9225
93-func getAddressIfValid (address) = toString(valueOrErrorMessage(addressFromString(address), (("Can't parse " + address) + " as address")))
26+func getAssetquantity (assetId) = if ((assetId == "GIC"))
27+ then 1000000000
28+ else match assetInfo(fromBase58String(assetId)) {
29+ case a: Asset =>
30+ a.quantity
31+ case _ =>
32+ 1000000000
33+ }
9434
9535
96-func validPoolK (key) = match getInteger(this, key) {
97- case t: Int =>
98- t
99- case _ =>
100- 0
101-}
102-
103-
104-func poolAA (key,asset) = match getInteger(this, ((key + "_") + asset)) {
105- case t: Int =>
106- t
107- case _ =>
108- 0
109-}
110-
111-
112-func userLiquidity (address,key,asset) = match getInteger(this, ((((key + "_") + address) + "_") + asset)) {
113- case t: Int =>
114- t
115- case _ =>
116- 0
117-}
118-
119-
120-func getAdminAddress () = if ((valueOrElse(getStringValue(adminAddress), "") == ""))
121- then throw("Constructor has not been initialized yet!")
122- else getStringValue(adminAddress)
123-
124-
125-@Callable(i)
126-func constructor (MainAssetId,AdminAddress,SwapFeeBps,acceptGic) = if ((i.caller != this))
127- then throw("Only the contract itself can invoke this function")
128- else if (!(isValidAsset(MainAssetId)))
129- then throw("Invalid MainAssetId")
130- else if ((AdminAddress == ""))
131- then throw("Invalid AdminAddress")
132- else if (if ((0 > SwapFeeBps))
133- then true
134- else (SwapFeeBps > 1000))
135- then throw("SwapFeeBps must be between 0 and 1000")
136- else [StringEntry(main, MainAssetId), StringEntry(adminAddress, AdminAddress), IntegerEntry(swapFee, SwapFeeBps), BooleanEntry(ac, true), BooleanEntry(poolAc, false), BooleanEntry(swapAc, false), BooleanEntry(liquidityAc, false), BooleanEntry(farmAc, false), BooleanEntry("accept_gic", acceptGic)]
137-
36+func getIsReissuable (assetId) = if ((assetId == "GIC"))
37+ then true
38+ else match assetInfo(fromBase58String(assetId)) {
39+ case a: Asset =>
40+ a.reissuable
41+ case _ =>
42+ true
43+ }
13844
13945
14046 @Callable(i)
14854
14955
15056 @Callable(i)
151-func activate (v) = {
152- let admin = getAdminAddress()
153- if ((toBase58String(i.caller.bytes) != admin))
154- then throw("Only the Admin itself can invoke this function")
155- else [BooleanEntry(ac, v)]
156- }
157-
158-
159-
160-@Callable(i)
161-func maintenance (pools,swap,stake,farms) = {
162- let admin = getAdminAddress()
163- if ((toBase58String(i.caller.bytes) != admin))
164- then throw("Only the Admin itself can invoke this function")
165- else [BooleanEntry(poolAc, pools), BooleanEntry(swapAc, swap), BooleanEntry(liquidityAc, stake), BooleanEntry(farmAc, farms)]
166- }
167-
168-
169-
170-@Callable(i)
171-func setSwapFee (feeBps) = {
57+func setNFTFee (feeBps) = {
17258 let admin = getAdminAddress()
17359 if ((toBase58String(i.caller.bytes) != admin))
17460 then throw("Only the Admin itself can invoke this function")
17662 then true
17763 else (feeBps > 1000))
17864 then throw("Fee must be between 0 and 1000 basis points")
179- else [IntegerEntry(swapFee, feeBps)]
65+ else [IntegerEntry(fee, feeBps)]
18066 }
18167
18268
18369
18470 @Callable(i)
185-func blacklistToken (assetId,blacklist) = {
186- let admin = getAdminAddress()
187- if ((toBase58String(i.caller.bytes) != admin))
188- then throw("Only the Admin itself can invoke this function")
189- else if (if (!(isValidAsset(assetId)))
190- then (assetId != "GIC")
191- else false)
192- then throw("Invalid assetId")
193- else [BooleanEntry((blacklistedTokens + assetId), blacklist)]
194- }
71+func createNFT (name,ipfs) = if ((100000000 > i.fee))
72+ then throw("Error: NFT fee amount to be paid is less than 1 GIC")
73+ else if ((ipfs == ""))
74+ then throw("Error: Put a valid IPFS string.")
75+ else if ((name == ""))
76+ then throw("Error: Put a valid NFT name string.")
77+ else {
78+ let nftCreate = Issue(name, ipfs, 1, 0, false)
79+ let idNft = calculateAssetId(nftCreate)
80+[nftCreate, ScriptTransfer(i.caller, 1, idNft)]
81+ }
19582
19683
19784
19885 @Callable(i)
199-func createFarm (asset1,asset2,apr,lockBlocks,rewardAmount) = {
200- let admin = getAdminAddress()
201- if ((toBase58String(i.caller.bytes) != admin))
202- then throw("Only the Admin itself can invoke this function")
203- else if (!(isValidAsset(asset1)))
204- then throw("Invalid asset1")
205- else if (!(isValidAsset(asset2)))
206- then throw("Invalid asset2")
207- else if ((asset1 == asset2))
208- then throw("Asset1 cannot be equal to Asset2")
209- else if ((0 >= apr))
210- then throw("APR must be positive")
211- else if ((0 >= lockBlocks))
212- then throw("Lock blocks must be positive")
213- else if ((0 >= rewardAmount))
214- then throw("Reward amount must be positive")
215- else {
216- let poolKey = kp(asset1, asset2)
217- if ((validPoolK(poolKey) == 0))
218- then throw("Pool does not exist")
219- else {
220- let farmKey = fk(asset1, asset2)
221-[IntegerEntry(farmKey, 1), IntegerEntry((farmApr + poolKey), apr), IntegerEntry((farmLockBlocks + poolKey), lockBlocks), IntegerEntry((farmRewardPool + poolKey), rewardAmount), IntegerEntry((farmTotalStaked + poolKey), 0), IntegerEntry((totalUsersFarm + poolKey), 0)]
222- }
223- }
224- }
86+func sellNFT (ValueToSell) = if ((100 > ValueToSell))
87+ then throw("Error: set a minimum value (0.00000100) to sell your NFT")
88+ else {
89+ let nft = i.payments[0]
90+ let pmtAssetId = match nft.assetId {
91+ case a: ByteVector =>
92+ toBase58String(a)
93+ case _ =>
94+ "GIC"
95+ }
96+ let isRessuable = getIsReissuable(pmtAssetId)
97+ let totalQuantity = getAssetquantity(pmtAssetId)
98+ let totalDecimals = getAssetDecimals(pmtAssetId)
99+ let OldNumberH = valueOrElse(getIntegerValue(this, ("history_" + pmtAssetId)), 0)
100+ let numberH = (OldNumberH + 1)
101+ let OldNumberHUser = valueOrElse(getIntegerValue(this, ("history_" + pmtAssetId)), 0)
102+ let numberHUser = (OldNumberH + 1)
103+ if ((pmtAssetId == "GIC"))
104+ then throw("Error: Invalid NFT.")
105+ else if (if (if (!(isRessuable))
106+ then (totalQuantity == 1)
107+ else false)
108+ then (totalDecimals == 0)
109+ else false)
110+ then [BooleanEntry(("is_sale_" + pmtAssetId), true), IntegerEntry(("price_sale_" + pmtAssetId), ValueToSell), StringEntry(("coin_accepted_" + pmtAssetId), "GIC"), StringEntry(("saler_" + pmtAssetId), toBase58String(i.caller.bytes)), IntegerEntry(("history_" + toBase58String(i.caller.bytes)), numberHUser), StringEntry(((("history_" + toBase58String(i.caller.bytes)) + "_") + toString(numberHUser)), pmtAssetId), IntegerEntry(("history_" + pmtAssetId), numberH), StringEntry((("history_" + pmtAssetId) + toString(numberH)), "sell")]
111+ else throw("Error: this is an asset, not an NFT.")
112+ }
225113
226114
227115
228116 @Callable(i)
229-func fundFarm (asset1,asset2) = {
230- let admin = getAdminAddress()
231- if ((toBase58String(i.caller.bytes) != admin))
232- then throw("Only the Admin itself can invoke this function")
233- else {
234- let pmt = i.payments[0]
235- let pmtAssetId = match pmt.assetId {
236- case a: ByteVector =>
237- toBase58String(a)
238- case _ =>
239- "GIC"
240- }
241- if ((toBase58String(i.caller.bytes) != admin))
242- then throw("Only the Admin itself can invoke this function")
243- else if ((pmtAssetId != "GIC"))
244- then throw("Rewards must be in GIC")
245- else {
246- let poolKey = kp(asset1, asset2)
247- let farmKey = fk(asset1, asset2)
248- if ((valueOrElse(getInteger(this, farmKey), 0) == 0))
249- then throw("Farm does not exist")
250- else {
251- let currentRewardPool = valueOrElse(getInteger(this, (farmRewardPool + poolKey)), 0)
252- let newRewardPool = (currentRewardPool + pmt.amount)
253-[IntegerEntry((farmRewardPool + poolKey), newRewardPool)]
254- }
255- }
256- }
257- }
258-
259-
260-
261-@Callable(i)
262-func changeData (key,data) = {
263- let admin = getAdminAddress()
264- if ((toBase58String(i.caller.bytes) != admin))
265- then throw("Only the Admin itself can invoke this function")
266- else [IntegerEntry(key, data)]
267- }
268-
269-
270-
271-@Callable(i)
272-func createPool (asset1,asset2,nameLp) = {
273- let poolKey = kp(asset1, asset2)
274- let admin = getAdminAddress()
275- if ((toBase58String(i.caller.bytes) != admin))
276- then throw("Only the Admin itself can invoke this function")
277- else if (!(isValidAsset(asset1)))
278- then throw("Invalid asset1")
279- else if (!(isValidAsset(asset2)))
280- then throw("Invalid asset2")
281- else if ((asset1 == asset2))
282- then throw("Asset1 cannot be equal to Asset2")
283- else if (if (isBlacklisted(asset1))
284- then true
285- else isBlacklisted(asset2))
286- then throw("One or both assets are blacklisted")
287- else if ((validPoolK(poolKey) != 0))
288- then throw("Pool already exists")
289- else {
290- let assetLpCreate = Issue(nameLp, ((("LP asset for pool " + asset1) + "_") + asset2), 1, 8, true)
291- let idAssetLp = calculateAssetId(assetLpCreate)
292-[assetLpCreate, StringEntry((lp + poolKey), toBase58String(idAssetLp)), IntegerEntry(poolKey, 1)]
293- }
294- }
295-
296-
297-
298-@Callable(i)
299-func addLiquidity (asset1,asset2) = {
300- let power = getBooleanValue(this, ac)
301- let liquidityPower = getBooleanValue(this, liquidityAc)
302- let acGic = getBooleanValue(this, "accept_gic")
303- let poolKey = kp(asset1, asset2)
304- let pmt1 = i.payments[0]
305- let pmt2 = i.payments[1]
306- let asset1Id = match pmt1.assetId {
117+func buyNFT (nftId) = {
118+ let pay = i.payments[0]
119+ let pmtAssetId = match pay.assetId {
307120 case a: ByteVector =>
308121 toBase58String(a)
309122 case _ =>
310123 "GIC"
311124 }
312- let asset2Id = match pmt2.assetId {
313- case a: ByteVector =>
314- toBase58String(a)
315- case _ =>
316- "GIC"
317- }
318- let decimals1 = getAssetDecimals(asset1Id)
319- let decimals2 = getAssetDecimals(asset2Id)
320- if (!(power))
321- then throw("dApp is currently under maintenance")
322- else if (liquidityPower)
323- then throw("Liquidity is currently under maintenance")
324- else if (if ((asset1Id != asset1))
325- then true
326- else (asset2Id != asset2))
327- then throw("Payment assets do not match specified assets")
328- else if ((asset1 == asset2))
329- then throw("Asset1 cannot be equal to Asset2")
330- else if (!(isValidAsset(asset1)))
331- then throw("Invalid asset1")
332- else if (!(isValidAsset(asset2)))
333- then throw("Invalid asset2")
334- else if (if (isBlacklisted(asset1))
335- then true
336- else isBlacklisted(asset2))
337- then throw("One or both assets are blacklisted")
338- else if (if (if ((asset1 == "GIC"))
339- then true
340- else (asset2 == "GIC"))
341- then !(acGic)
342- else false)
343- then throw("GIC not allowed")
344- else if ((validPoolK(poolKey) == 0))
345- then throw("Pool does not exist. Create it first")
346- else {
347- let poolAmount1 = poolAA(poolKey, asset1)
348- let poolAmount2 = poolAA(poolKey, asset2)
349- let amount1 = pmt1.amount
350- let amount2 = pmt2.amount
351- let lpAmount = if (if ((poolAmount1 == 0))
352- then true
353- else (poolAmount2 == 0))
354- then toBigInt(amount1)
355- else ((toBigInt(amount1) * toBigInt(poolAmount2)) / toBigInt(poolAmount1))
356- let currentKey = toBase58String(i.caller.bytes)
357- let currentAmountAsset1 = userLiquidity(currentKey, poolKey, asset1)
358- let currentAmountAsset2 = userLiquidity(currentKey, poolKey, asset2)
359- let newAmountAsset1 = (toBigInt(currentAmountAsset1) + toBigInt(amount1))
360- let newAmountAsset2 = (toBigInt(currentAmountAsset2) + toBigInt(amount2))
361- let newPoolAmount1 = (toBigInt(poolAmount1) + toBigInt(amount1))
362- let newPoolAmount2 = (toBigInt(poolAmount2) + toBigInt(amount2))
363- let lpAssetId = getStringValue(this, (lp + poolKey))
364- let oldAssetLpTotal = valueOrElse(getIntegerValue(poolKey), 0)
365- let lpAsset = if ((lpAssetId == ""))
366- then throw("Pool does not have a liquidity pair, contact admin")
367- else fromBase58String(lpAssetId)
368-[IntegerEntry(((((poolKey + "_") + currentKey) + "_") + asset1), toInt(newAmountAsset1)), IntegerEntry(((((poolKey + "_") + currentKey) + "_") + asset2), toInt(newAmountAsset2)), IntegerEntry(((poolKey + "_") + asset1), toInt(newPoolAmount1)), IntegerEntry(((poolKey + "_") + asset2), toInt(newPoolAmount2)), IntegerEntry((((depositHeight + poolKey) + "_") + currentKey), height), IntegerEntry(poolKey, (oldAssetLpTotal + toInt(lpAmount))), Reissue(lpAsset, toInt(lpAmount), true), ScriptTransfer(i.caller, toInt(lpAmount), lpAsset)]
369- }
370- }
371-
372-
373-
374-@Callable(i)
375-func removeLiquidity (asset1,asset2,lpAmount) = {
376- let power = getBooleanValue(this, ac)
377- let liquidityPower = getBooleanValue(this, liquidityAc)
378- let poolKey = kp(asset1, asset2)
379- let lpAssetId = getStringValue(this, (lp + poolKey))
380- let lpAsset = fromBase58String(lpAssetId)
381- let pmt = i.payments[0]
382- let pmtAssetId = match pmt.assetId {
383- case a: ByteVector =>
384- toBase58String(a)
385- case _ =>
386- "GIC"
387- }
388- let decimals1 = getAssetDecimals(asset1)
389- let decimals2 = getAssetDecimals(asset2)
390- if (!(power))
391- then throw("dApp is currently under maintenance")
392- else if (liquidityPower)
393- then throw("Liquidity is currently under maintenance")
394- else if ((lpAssetId == ""))
395- then throw("Invalid LP asset")
396- else if ((pmtAssetId != lpAssetId))
397- then throw("Invalid LP token")
398- else if ((validPoolK(poolKey) == 0))
399- then throw("Pool does not exist")
400- else if ((0 >= lpAmount))
401- then throw("LP amount must be positive")
402- else {
403- let poolAmount1 = poolAA(poolKey, asset1)
404- let poolAmount2 = poolAA(poolKey, asset2)
405- let totalLpSupply = match assetInfo(fromBase58String(lpAssetId)) {
406- case a: Asset =>
407- a.quantity
408- case _ =>
409- 0
410- }
411- let amount1 = ((lpAmount * poolAmount1) / totalLpSupply)
412- let amount2 = ((lpAmount * poolAmount2) / totalLpSupply)
413- let currentKey = toBase58String(i.caller.bytes)
414- let currentAmountAsset1 = userLiquidity(currentKey, poolKey, asset1)
415- let currentAmountAsset2 = userLiquidity(currentKey, poolKey, asset2)
416- let newAmountAsset1 = (currentAmountAsset1 - amount1)
417- let newAmountAsset2 = (currentAmountAsset2 - amount2)
418- if (if ((0 > newAmountAsset1))
419- then true
420- else (0 > newAmountAsset2))
421- then throw("Insufficient liquidity balance")
422- else {
423- let newPoolAmount1 = (poolAmount1 - amount1)
424- let newPoolAmount2 = (poolAmount2 - amount2)
425- let asset1Bytes = if ((asset1 == "GIC"))
426- then unit
427- else fromBase58String(asset1)
428- let asset2Bytes = if ((asset2 == "GIC"))
429- then unit
430- else fromBase58String(asset2)
431- let oldAssetLpTotal = getIntegerValue(poolKey)
432-[IntegerEntry(((((poolKey + "_") + currentKey) + "_") + asset1), newAmountAsset1), IntegerEntry(((((poolKey + "_") + currentKey) + "_") + asset2), newAmountAsset2), IntegerEntry(((poolKey + "_") + asset1), newPoolAmount1), IntegerEntry(((poolKey + "_") + asset2), newPoolAmount2), IntegerEntry(poolKey, (oldAssetLpTotal - lpAmount)), Burn(lpAsset, lpAmount), ScriptTransfer(i.caller, amount1, asset1Bytes), ScriptTransfer(i.caller, amount2, asset2Bytes)]
433- }
434- }
435- }
436-
437-
438-
439-@Callable(i)
440-func swap (assetIn,assetOut,maxSlippage) = {
441- let power = getBooleanValue(this, ac)
442- let swapActivate = getBooleanValue(this, swapAc)
443- let acGic = getBooleanValue(this, "accept_gic")
444- let poolKey = kp(assetIn, assetOut)
445- let reversePoolKey = kp(assetOut, assetIn)
446- let key = if ((validPoolK(poolKey) != 0))
447- then poolKey
448- else if ((validPoolK(reversePoolKey) != 0))
449- then reversePoolKey
450- else ""
451- let pmt = i.payments[0]
452- let pmtAssetId = match pmt.assetId {
453- case a: ByteVector =>
454- toBase58String(a)
455- case _ =>
456- "GIC"
457- }
458- let decimalsIn = getAssetDecimals(assetIn)
459- let decimalsOut = getAssetDecimals(assetOut)
460- let feeBps = toBigInt(getIntegerValue(this, swapFee))
461- let adminAddr = addressFromStringValue(getStringValue(this, adminAddress))
462- if (!(power))
463- then throw("dApp is currently under maintenance")
464- else if (swapActivate)
465- then throw("Swap is currently under maintenance")
466- else if ((pmtAssetId != assetIn))
467- then throw("Payment asset does not match assetIn")
468- else if (!(isValidAsset(assetIn)))
469- then throw("Invalid assetIn")
470- else if (!(isValidAsset(assetOut)))
471- then throw("Invalid assetOut")
472- else if (if (isBlacklisted(assetIn))
473- then true
474- else isBlacklisted(assetOut))
475- then throw("One or both assets are blacklisted")
476- else if ((assetIn == assetOut))
477- then throw("assetIn cannot be equal to assetOut")
478- else if (if (if ((assetIn == "GIC"))
479- then true
480- else (assetOut == "GIC"))
481- then !(acGic)
482- else false)
483- then throw("GIC not allowed")
484- else if ((key == ""))
485- then throw("Pool does not exist")
486- else {
487- let isReverse = (key == reversePoolKey)
488- let poolAsset1 = if (isReverse)
489- then assetOut
490- else assetIn
491- let poolAsset2 = if (isReverse)
492- then assetIn
493- else assetOut
494- let poolAmount1 = toBigInt(poolAA(key, poolAsset1))
495- let poolAmount2 = toBigInt(poolAA(key, poolAsset2))
496- let amountInAdjusted = toBigInt(pmt.amount)
497- let amountOut = if (isReverse)
498- then ((amountInAdjusted * poolAmount1) / poolAmount2)
499- else ((amountInAdjusted * poolAmount2) / poolAmount1)
500- let fee = ((amountOut * feeBps) / toBigInt(10000))
501- let amountOutAfterFee = (amountOut - fee)
502- let feeToSend = ((amountInAdjusted * feeBps) / toBigInt(10000))
503- let minAmountOut = ((amountOutAfterFee * toBigInt((10000 - maxSlippage))) / toBigInt(10000))
504- if ((minAmountOut > amountOutAfterFee))
505- then throw("Slippage exceeded")
506- else {
507- let newPoolAmount1 = if (isReverse)
508- then (poolAmount1 - amountOut)
509- else (poolAmount1 + amountInAdjusted)
510- let newPoolAmount2 = if (isReverse)
511- then (poolAmount2 + amountInAdjusted)
512- else (poolAmount2 - amountOut)
513- let assettoReceive = if ((assetOut == "GIC"))
514- then unit
515- else fromBase58String(assetOut)
516- let assetOutBytes = if ((assetIn == "GIC"))
517- then unit
518- else fromBase58String(assetIn)
519-[IntegerEntry(((key + "_") + poolAsset1), toInt(newPoolAmount1)), IntegerEntry(((key + "_") + poolAsset2), toInt(newPoolAmount2)), BooleanEntry("isReverse", isReverse), ScriptTransfer(i.caller, toInt(amountOutAfterFee), assettoReceive), ScriptTransfer(adminAddr, toInt(feeToSend), assetOutBytes)]
520- }
521- }
522- }
523-
524-
525-
526-@Callable(i)
527-func farmsAddLP (asset1,asset2) = {
528- let power = getBooleanValue(this, ac)
529- let farmPower = getBooleanValue(this, farmAc)
530- let poolKey = kp(asset1, asset2)
531- let farmKey = fk(asset1, asset2)
532- let pmt = i.payments[0]
533- let lpAssetId = getStringValue(this, (lp + poolKey))
534- let pmtAssetId = match pmt.assetId {
535- case a: ByteVector =>
536- toBase58String(a)
537- case _ =>
538- "GIC"
539- }
540- if (!(power))
541- then throw("dApp is currently under maintenance")
542- else if (farmPower)
543- then throw("Farms are currently under maintenance")
544- else if ((pmtAssetId != lpAssetId))
545- then throw("Invalid LP token")
546- else if ((validPoolK(poolKey) == 0))
547- then throw("Pool does not exist")
548- else if ((valueOrElse(getInteger(this, farmKey), 0) == 0))
549- then throw("Farm does not exist")
550- else {
551- let currentKey = toBase58String(i.caller.bytes)
552- let stakedKey = sk(asset1, asset2, currentKey)
553- let currentStaked = valueOrElse(getInteger(this, stakedKey), 0)
554- let newStaked = (currentStaked + pmt.amount)
555- let totalStakedKey = (farmTotalStaked + poolKey)
556- let previousTotalStaked = valueOrElse(getInteger(this, totalStakedKey), 0)
557- let newTotalStaked = (previousTotalStaked + pmt.amount)
558- let totalUsers = valueOrElse(getInteger(this, (totalUsersFarm + poolKey)), 0)
559- let newTotalUsers = if ((currentStaked == 0))
560- then (totalUsers + 1)
561- else totalUsers
562-[IntegerEntry(stakedKey, newStaked), IntegerEntry(totalStakedKey, newTotalStaked), IntegerEntry((totalUsersFarm + poolKey), newTotalUsers), IntegerEntry(fh(asset1, asset2, currentKey), height)]
563- }
564- }
565-
566-
567-
568-@Callable(i)
569-func farmsClaimLP (asset1,asset2) = {
570- let power = getBooleanValue(this, ac)
571- let farmPower = getBooleanValue(this, farmAc)
572- let poolKey = kp(asset1, asset2)
573- let farmKey = fk(asset1, asset2)
574- let currentKey = toBase58String(i.caller.bytes)
575- let stakedKey = sk(asset1, asset2, currentKey)
576- let heightKey = fh(asset1, asset2, currentKey)
577- let rewardKey = rk(asset1, asset2, currentKey)
578- if (!(power))
579- then throw("dApp is currently under maintenance")
580- else if (farmPower)
581- then throw("Farms are currently under maintenance")
582- else if ((validPoolK(poolKey) == 0))
583- then throw("Pool does not exist")
584- else if ((valueOrElse(getInteger(this, farmKey), 0) == 0))
585- then throw("Farm does not exist")
586- else {
587- let currentStaked = valueOrElse(getInteger(this, stakedKey), 0)
588- if ((0 >= currentStaked))
589- then throw("No staked LP tokens")
590- else {
591- let rewardPool = valueOrElse(getInteger(this, (farmRewardPool + poolKey)), 0)
592- let totalUsers = valueOrElse(getInteger(this, (totalUsersFarm + poolKey)), 1)
593- let lockBlocks = getIntegerValue(this, (farmLockBlocks + poolKey))
594- let apr = getIntegerValue(this, (farmApr + poolKey))
595- let lastClaimHeight = valueOrElse(getInteger(this, heightKey), height)
596- let blocksSinceLastClaim = (height - lastClaimHeight)
597- if ((1 > blocksSinceLastClaim))
598- then throw("Must wait at least 1 block since last claim")
599- else {
600- let rewardPerBlock = ((rewardPool * apr) / ((10000 * lockBlocks) * totalUsers))
601- let reward = (((rewardPerBlock * blocksSinceLastClaim) * currentStaked) / D8)
602- if ((reward > rewardPool))
603- then throw("Insufficient reward pool")
604- else {
605- let newRewardPool = (rewardPool - reward)
606-[IntegerEntry(rewardKey, 0), IntegerEntry((farmRewardPool + poolKey), newRewardPool), IntegerEntry(heightKey, height), ScriptTransfer(i.caller, reward, unit)]
607- }
608- }
609- }
610- }
611- }
612-
613-
614-
615-@Callable(i)
616-func farmsRemoveLP (asset1,asset2,amount) = {
617- let power = getBooleanValue(this, ac)
618- let farmPower = getBooleanValue(this, farmAc)
619- let poolKey = kp(asset1, asset2)
620- let farmKey = fk(asset1, asset2)
621- let lpAssetId = getStringValue(this, (lp + poolKey))
622- let lpAsset = if ((lpAssetId == ""))
623- then unit
624- else fromBase58String(lpAssetId)
625- let currentKey = toBase58String(i.caller.bytes)
626- let stakedKey = sk(asset1, asset2, currentKey)
627- let heightKey = fh(asset1, asset2, currentKey)
628- let rewardKey = rk(asset1, asset2, currentKey)
629- if (!(power))
630- then throw("dApp is currently under maintenance")
631- else if (farmPower)
632- then throw("Farms are currently under maintenance")
633- else if ((validPoolK(poolKey) == 0))
634- then throw("Pool does not exist")
635- else if ((valueOrElse(getInteger(this, farmKey), 0) == 0))
636- then throw("Farm does not exist")
637- else {
638- let currentStaked = valueOrElse(getInteger(this, stakedKey), 0)
639- if ((0 >= amount))
640- then throw("Amount must be positive")
641- else if ((amount > currentStaked))
642- then throw("Insufficient staked LP tokens")
643- else {
644- let rewardPool = valueOrElse(getInteger(this, (farmRewardPool + poolKey)), 0)
645- let totalUsers = valueOrElse(getInteger(this, (totalUsersFarm + poolKey)), 1)
646- let lockBlocks = getIntegerValue(this, (farmLockBlocks + poolKey))
647- let apr = getIntegerValue(this, (farmApr + poolKey))
648- let lastClaimHeight = valueOrElse(getInteger(this, heightKey), height)
649- let blocksSinceLastClaim = (height - lastClaimHeight)
650- let rewardPerBlock = ((rewardPool * apr) / ((10000 * lockBlocks) * totalUsers))
651- let reward = if ((blocksSinceLastClaim >= 1))
652- then (((rewardPerBlock * blocksSinceLastClaim) * currentStaked) / D8)
653- else 0
654- let newRewardPool = (rewardPool - reward)
655- let newStaked = (currentStaked - amount)
656- let totalStakedKey = (farmTotalStaked + poolKey)
657- let previousTotalStaked = valueOrElse(getInteger(this, totalStakedKey), 0)
658- let newTotalStaked = (previousTotalStaked - amount)
659- let newTotalUsers = if ((newStaked == 0))
660- then (totalUsers - 1)
661- else totalUsers
662-[IntegerEntry(stakedKey, newStaked), IntegerEntry(totalStakedKey, newTotalStaked), IntegerEntry((totalUsersFarm + poolKey), newTotalUsers), IntegerEntry(rewardKey, 0), IntegerEntry((farmRewardPool + poolKey), newRewardPool), IntegerEntry(heightKey, height), ScriptTransfer(i.caller, amount, lpAsset), ScriptTransfer(i.caller, reward, unit)]
663- }
664- }
125+ let feeBps = toBigInt(getIntegerValue(this, fee))
126+ let isSale = valueOrElse(getBooleanValue(("is_sale_" + nftId)), false)
127+ let valueSale = valueOrElse(getIntegerValue(("price_sale_" + nftId)), 0)
128+ let feeToSend = ((toBigInt(pay.amount) * feeBps) / toBigInt(10000))
129+ let adminAddr = getAdminAddress()
130+ let OldNumberH = valueOrElse(getIntegerValue(this, ("history_" + pmtAssetId)), 0)
131+ let numberH = (OldNumberH + 1)
132+ let OldNumberHUser = valueOrElse(getIntegerValue(this, ("history_" + pmtAssetId)), 0)
133+ let numberHUser = (OldNumberH + 1)
134+ let toSendToSaler = (toBigInt(pay.amount) - feeToSend)
135+ if ((pmtAssetId != "GIC"))
136+ then throw("Error: Invalid Asset to buy.")
137+ else if (!(isSale))
138+ then throw("This NFT is no longer for sale.")
139+ else if ((valueSale != pay.amount))
140+ then throw("Insufficient value to make the purchase.")
141+ else [ScriptTransfer(i.caller, 1, fromBase58String(nftId)), ScriptTransfer(addressFromStringValue(getStringValue(this, ("saler_" + pmtAssetId))), toInt(toSendToSaler), unit), ScriptTransfer(addressFromStringValue(adminAddr), toInt(feeToSend), unit), BooleanEntry(("is_sale_" + pmtAssetId), false), StringEntry(("saler_" + pmtAssetId), toBase58String(i.caller.bytes)), IntegerEntry(("history_" + pmtAssetId), numberH), StringEntry((("history_" + pmtAssetId) + toString(numberH)), "buy")]
665142 }
666143
667144
668145 @Verifier(tx)
669-func verify () = match tx {
670- case _ =>
671- sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey)
672-}
146+func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey)
673147
Full:
OldNewDifferences
11 {-# STDLIB_VERSION 5 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
4-let main = "main_asset"
5-
64 let adminAddress = "admin_address"
75
8-let lp = "lp_asset_"
6+let fee = "fee"
97
10-let pool = "pool__"
11-
12-let farm = "farm__"
13-
14-let staked = "staked_"
15-
16-let rewardClaimed = "reward_claimed_"
17-
18-let depositHeight = "deposit_height_"
19-
20-let farmHeight = "farm_height_"
21-
22-let totalLocked = "total_locked_"
23-
24-let swapFee = "swap_fee"
25-
26-let farmRewardPool = "farm_reward_pool_"
27-
28-let farmApr = "farm_apr_"
29-
30-let farmLockBlocks = "farm_lock_blocks_"
31-
32-let farmTotalStaked = "farm_total_staked_"
33-
34-let blacklistedTokens = "blacklisted_"
35-
36-let totalUsersFarm = "total_users_farm_"
37-
38-let D8 = 100000000
39-
40-let contractAddress = Address(this.bytes)
41-
42-let ac = "activate"
43-
44-let poolAc = "activate_pools"
45-
46-let swapAc = "activate_swap"
47-
48-let liquidityAc = "activate_liquidity"
49-
50-let farmAc = "activate_farms"
51-
52-func kp (asset1,asset2) = (((pool + asset1) + "_") + asset2)
53-
54-
55-func fk (asset1,asset2) = (((farm + asset1) + "_") + asset2)
56-
57-
58-func sk (asset1,asset2,address) = (((staked + kp(asset1, asset2)) + "_") + address)
59-
60-
61-func rk (asset1,asset2,address) = (((rewardClaimed + kp(asset1, asset2)) + "_") + address)
62-
63-
64-func dh (asset1,asset2,address) = (((depositHeight + kp(asset1, asset2)) + "_") + address)
65-
66-
67-func fh (asset1,asset2,address) = (((farmHeight + kp(asset1, asset2)) + "_") + address)
68-
69-
70-func isValidAsset (assetId) = if ((assetId == "GIC"))
71- then true
72- else match assetInfo(fromBase58String(assetId)) {
73- case a: Asset =>
74- true
75- case _ =>
76- false
77- }
78-
79-
80-func isBlacklisted (assetId) = valueOrElse(getBoolean(this, (blacklistedTokens + assetId)), false)
8+func getAdminAddress () = match getString(adminAddress) {
9+ case t: String =>
10+ t
11+ case _ =>
12+ toBase58String(this.bytes)
13+}
8114
8215
8316 func getAssetDecimals (assetId) = if ((assetId == "GIC"))
8417 then 8
8518 else match assetInfo(fromBase58String(assetId)) {
8619 case a: Asset =>
8720 a.decimals
8821 case _ =>
8922 8
9023 }
9124
9225
93-func getAddressIfValid (address) = toString(valueOrErrorMessage(addressFromString(address), (("Can't parse " + address) + " as address")))
26+func getAssetquantity (assetId) = if ((assetId == "GIC"))
27+ then 1000000000
28+ else match assetInfo(fromBase58String(assetId)) {
29+ case a: Asset =>
30+ a.quantity
31+ case _ =>
32+ 1000000000
33+ }
9434
9535
96-func validPoolK (key) = match getInteger(this, key) {
97- case t: Int =>
98- t
99- case _ =>
100- 0
101-}
102-
103-
104-func poolAA (key,asset) = match getInteger(this, ((key + "_") + asset)) {
105- case t: Int =>
106- t
107- case _ =>
108- 0
109-}
110-
111-
112-func userLiquidity (address,key,asset) = match getInteger(this, ((((key + "_") + address) + "_") + asset)) {
113- case t: Int =>
114- t
115- case _ =>
116- 0
117-}
118-
119-
120-func getAdminAddress () = if ((valueOrElse(getStringValue(adminAddress), "") == ""))
121- then throw("Constructor has not been initialized yet!")
122- else getStringValue(adminAddress)
123-
124-
125-@Callable(i)
126-func constructor (MainAssetId,AdminAddress,SwapFeeBps,acceptGic) = if ((i.caller != this))
127- then throw("Only the contract itself can invoke this function")
128- else if (!(isValidAsset(MainAssetId)))
129- then throw("Invalid MainAssetId")
130- else if ((AdminAddress == ""))
131- then throw("Invalid AdminAddress")
132- else if (if ((0 > SwapFeeBps))
133- then true
134- else (SwapFeeBps > 1000))
135- then throw("SwapFeeBps must be between 0 and 1000")
136- else [StringEntry(main, MainAssetId), StringEntry(adminAddress, AdminAddress), IntegerEntry(swapFee, SwapFeeBps), BooleanEntry(ac, true), BooleanEntry(poolAc, false), BooleanEntry(swapAc, false), BooleanEntry(liquidityAc, false), BooleanEntry(farmAc, false), BooleanEntry("accept_gic", acceptGic)]
137-
36+func getIsReissuable (assetId) = if ((assetId == "GIC"))
37+ then true
38+ else match assetInfo(fromBase58String(assetId)) {
39+ case a: Asset =>
40+ a.reissuable
41+ case _ =>
42+ true
43+ }
13844
13945
14046 @Callable(i)
14147 func changeAdmin (address) = {
14248 let admin = getAdminAddress()
14349 if ((toBase58String(i.caller.bytes) != admin))
14450 then throw("Only the Admin itself can invoke this function.")
14551 else [StringEntry(adminAddress, address)]
14652 }
14753
14854
14955
15056 @Callable(i)
151-func activate (v) = {
152- let admin = getAdminAddress()
153- if ((toBase58String(i.caller.bytes) != admin))
154- then throw("Only the Admin itself can invoke this function")
155- else [BooleanEntry(ac, v)]
156- }
157-
158-
159-
160-@Callable(i)
161-func maintenance (pools,swap,stake,farms) = {
162- let admin = getAdminAddress()
163- if ((toBase58String(i.caller.bytes) != admin))
164- then throw("Only the Admin itself can invoke this function")
165- else [BooleanEntry(poolAc, pools), BooleanEntry(swapAc, swap), BooleanEntry(liquidityAc, stake), BooleanEntry(farmAc, farms)]
166- }
167-
168-
169-
170-@Callable(i)
171-func setSwapFee (feeBps) = {
57+func setNFTFee (feeBps) = {
17258 let admin = getAdminAddress()
17359 if ((toBase58String(i.caller.bytes) != admin))
17460 then throw("Only the Admin itself can invoke this function")
17561 else if (if ((0 > feeBps))
17662 then true
17763 else (feeBps > 1000))
17864 then throw("Fee must be between 0 and 1000 basis points")
179- else [IntegerEntry(swapFee, feeBps)]
65+ else [IntegerEntry(fee, feeBps)]
18066 }
18167
18268
18369
18470 @Callable(i)
185-func blacklistToken (assetId,blacklist) = {
186- let admin = getAdminAddress()
187- if ((toBase58String(i.caller.bytes) != admin))
188- then throw("Only the Admin itself can invoke this function")
189- else if (if (!(isValidAsset(assetId)))
190- then (assetId != "GIC")
191- else false)
192- then throw("Invalid assetId")
193- else [BooleanEntry((blacklistedTokens + assetId), blacklist)]
194- }
71+func createNFT (name,ipfs) = if ((100000000 > i.fee))
72+ then throw("Error: NFT fee amount to be paid is less than 1 GIC")
73+ else if ((ipfs == ""))
74+ then throw("Error: Put a valid IPFS string.")
75+ else if ((name == ""))
76+ then throw("Error: Put a valid NFT name string.")
77+ else {
78+ let nftCreate = Issue(name, ipfs, 1, 0, false)
79+ let idNft = calculateAssetId(nftCreate)
80+[nftCreate, ScriptTransfer(i.caller, 1, idNft)]
81+ }
19582
19683
19784
19885 @Callable(i)
199-func createFarm (asset1,asset2,apr,lockBlocks,rewardAmount) = {
200- let admin = getAdminAddress()
201- if ((toBase58String(i.caller.bytes) != admin))
202- then throw("Only the Admin itself can invoke this function")
203- else if (!(isValidAsset(asset1)))
204- then throw("Invalid asset1")
205- else if (!(isValidAsset(asset2)))
206- then throw("Invalid asset2")
207- else if ((asset1 == asset2))
208- then throw("Asset1 cannot be equal to Asset2")
209- else if ((0 >= apr))
210- then throw("APR must be positive")
211- else if ((0 >= lockBlocks))
212- then throw("Lock blocks must be positive")
213- else if ((0 >= rewardAmount))
214- then throw("Reward amount must be positive")
215- else {
216- let poolKey = kp(asset1, asset2)
217- if ((validPoolK(poolKey) == 0))
218- then throw("Pool does not exist")
219- else {
220- let farmKey = fk(asset1, asset2)
221-[IntegerEntry(farmKey, 1), IntegerEntry((farmApr + poolKey), apr), IntegerEntry((farmLockBlocks + poolKey), lockBlocks), IntegerEntry((farmRewardPool + poolKey), rewardAmount), IntegerEntry((farmTotalStaked + poolKey), 0), IntegerEntry((totalUsersFarm + poolKey), 0)]
222- }
223- }
224- }
86+func sellNFT (ValueToSell) = if ((100 > ValueToSell))
87+ then throw("Error: set a minimum value (0.00000100) to sell your NFT")
88+ else {
89+ let nft = i.payments[0]
90+ let pmtAssetId = match nft.assetId {
91+ case a: ByteVector =>
92+ toBase58String(a)
93+ case _ =>
94+ "GIC"
95+ }
96+ let isRessuable = getIsReissuable(pmtAssetId)
97+ let totalQuantity = getAssetquantity(pmtAssetId)
98+ let totalDecimals = getAssetDecimals(pmtAssetId)
99+ let OldNumberH = valueOrElse(getIntegerValue(this, ("history_" + pmtAssetId)), 0)
100+ let numberH = (OldNumberH + 1)
101+ let OldNumberHUser = valueOrElse(getIntegerValue(this, ("history_" + pmtAssetId)), 0)
102+ let numberHUser = (OldNumberH + 1)
103+ if ((pmtAssetId == "GIC"))
104+ then throw("Error: Invalid NFT.")
105+ else if (if (if (!(isRessuable))
106+ then (totalQuantity == 1)
107+ else false)
108+ then (totalDecimals == 0)
109+ else false)
110+ then [BooleanEntry(("is_sale_" + pmtAssetId), true), IntegerEntry(("price_sale_" + pmtAssetId), ValueToSell), StringEntry(("coin_accepted_" + pmtAssetId), "GIC"), StringEntry(("saler_" + pmtAssetId), toBase58String(i.caller.bytes)), IntegerEntry(("history_" + toBase58String(i.caller.bytes)), numberHUser), StringEntry(((("history_" + toBase58String(i.caller.bytes)) + "_") + toString(numberHUser)), pmtAssetId), IntegerEntry(("history_" + pmtAssetId), numberH), StringEntry((("history_" + pmtAssetId) + toString(numberH)), "sell")]
111+ else throw("Error: this is an asset, not an NFT.")
112+ }
225113
226114
227115
228116 @Callable(i)
229-func fundFarm (asset1,asset2) = {
230- let admin = getAdminAddress()
231- if ((toBase58String(i.caller.bytes) != admin))
232- then throw("Only the Admin itself can invoke this function")
233- else {
234- let pmt = i.payments[0]
235- let pmtAssetId = match pmt.assetId {
236- case a: ByteVector =>
237- toBase58String(a)
238- case _ =>
239- "GIC"
240- }
241- if ((toBase58String(i.caller.bytes) != admin))
242- then throw("Only the Admin itself can invoke this function")
243- else if ((pmtAssetId != "GIC"))
244- then throw("Rewards must be in GIC")
245- else {
246- let poolKey = kp(asset1, asset2)
247- let farmKey = fk(asset1, asset2)
248- if ((valueOrElse(getInteger(this, farmKey), 0) == 0))
249- then throw("Farm does not exist")
250- else {
251- let currentRewardPool = valueOrElse(getInteger(this, (farmRewardPool + poolKey)), 0)
252- let newRewardPool = (currentRewardPool + pmt.amount)
253-[IntegerEntry((farmRewardPool + poolKey), newRewardPool)]
254- }
255- }
256- }
257- }
258-
259-
260-
261-@Callable(i)
262-func changeData (key,data) = {
263- let admin = getAdminAddress()
264- if ((toBase58String(i.caller.bytes) != admin))
265- then throw("Only the Admin itself can invoke this function")
266- else [IntegerEntry(key, data)]
267- }
268-
269-
270-
271-@Callable(i)
272-func createPool (asset1,asset2,nameLp) = {
273- let poolKey = kp(asset1, asset2)
274- let admin = getAdminAddress()
275- if ((toBase58String(i.caller.bytes) != admin))
276- then throw("Only the Admin itself can invoke this function")
277- else if (!(isValidAsset(asset1)))
278- then throw("Invalid asset1")
279- else if (!(isValidAsset(asset2)))
280- then throw("Invalid asset2")
281- else if ((asset1 == asset2))
282- then throw("Asset1 cannot be equal to Asset2")
283- else if (if (isBlacklisted(asset1))
284- then true
285- else isBlacklisted(asset2))
286- then throw("One or both assets are blacklisted")
287- else if ((validPoolK(poolKey) != 0))
288- then throw("Pool already exists")
289- else {
290- let assetLpCreate = Issue(nameLp, ((("LP asset for pool " + asset1) + "_") + asset2), 1, 8, true)
291- let idAssetLp = calculateAssetId(assetLpCreate)
292-[assetLpCreate, StringEntry((lp + poolKey), toBase58String(idAssetLp)), IntegerEntry(poolKey, 1)]
293- }
294- }
295-
296-
297-
298-@Callable(i)
299-func addLiquidity (asset1,asset2) = {
300- let power = getBooleanValue(this, ac)
301- let liquidityPower = getBooleanValue(this, liquidityAc)
302- let acGic = getBooleanValue(this, "accept_gic")
303- let poolKey = kp(asset1, asset2)
304- let pmt1 = i.payments[0]
305- let pmt2 = i.payments[1]
306- let asset1Id = match pmt1.assetId {
117+func buyNFT (nftId) = {
118+ let pay = i.payments[0]
119+ let pmtAssetId = match pay.assetId {
307120 case a: ByteVector =>
308121 toBase58String(a)
309122 case _ =>
310123 "GIC"
311124 }
312- let asset2Id = match pmt2.assetId {
313- case a: ByteVector =>
314- toBase58String(a)
315- case _ =>
316- "GIC"
317- }
318- let decimals1 = getAssetDecimals(asset1Id)
319- let decimals2 = getAssetDecimals(asset2Id)
320- if (!(power))
321- then throw("dApp is currently under maintenance")
322- else if (liquidityPower)
323- then throw("Liquidity is currently under maintenance")
324- else if (if ((asset1Id != asset1))
325- then true
326- else (asset2Id != asset2))
327- then throw("Payment assets do not match specified assets")
328- else if ((asset1 == asset2))
329- then throw("Asset1 cannot be equal to Asset2")
330- else if (!(isValidAsset(asset1)))
331- then throw("Invalid asset1")
332- else if (!(isValidAsset(asset2)))
333- then throw("Invalid asset2")
334- else if (if (isBlacklisted(asset1))
335- then true
336- else isBlacklisted(asset2))
337- then throw("One or both assets are blacklisted")
338- else if (if (if ((asset1 == "GIC"))
339- then true
340- else (asset2 == "GIC"))
341- then !(acGic)
342- else false)
343- then throw("GIC not allowed")
344- else if ((validPoolK(poolKey) == 0))
345- then throw("Pool does not exist. Create it first")
346- else {
347- let poolAmount1 = poolAA(poolKey, asset1)
348- let poolAmount2 = poolAA(poolKey, asset2)
349- let amount1 = pmt1.amount
350- let amount2 = pmt2.amount
351- let lpAmount = if (if ((poolAmount1 == 0))
352- then true
353- else (poolAmount2 == 0))
354- then toBigInt(amount1)
355- else ((toBigInt(amount1) * toBigInt(poolAmount2)) / toBigInt(poolAmount1))
356- let currentKey = toBase58String(i.caller.bytes)
357- let currentAmountAsset1 = userLiquidity(currentKey, poolKey, asset1)
358- let currentAmountAsset2 = userLiquidity(currentKey, poolKey, asset2)
359- let newAmountAsset1 = (toBigInt(currentAmountAsset1) + toBigInt(amount1))
360- let newAmountAsset2 = (toBigInt(currentAmountAsset2) + toBigInt(amount2))
361- let newPoolAmount1 = (toBigInt(poolAmount1) + toBigInt(amount1))
362- let newPoolAmount2 = (toBigInt(poolAmount2) + toBigInt(amount2))
363- let lpAssetId = getStringValue(this, (lp + poolKey))
364- let oldAssetLpTotal = valueOrElse(getIntegerValue(poolKey), 0)
365- let lpAsset = if ((lpAssetId == ""))
366- then throw("Pool does not have a liquidity pair, contact admin")
367- else fromBase58String(lpAssetId)
368-[IntegerEntry(((((poolKey + "_") + currentKey) + "_") + asset1), toInt(newAmountAsset1)), IntegerEntry(((((poolKey + "_") + currentKey) + "_") + asset2), toInt(newAmountAsset2)), IntegerEntry(((poolKey + "_") + asset1), toInt(newPoolAmount1)), IntegerEntry(((poolKey + "_") + asset2), toInt(newPoolAmount2)), IntegerEntry((((depositHeight + poolKey) + "_") + currentKey), height), IntegerEntry(poolKey, (oldAssetLpTotal + toInt(lpAmount))), Reissue(lpAsset, toInt(lpAmount), true), ScriptTransfer(i.caller, toInt(lpAmount), lpAsset)]
369- }
370- }
371-
372-
373-
374-@Callable(i)
375-func removeLiquidity (asset1,asset2,lpAmount) = {
376- let power = getBooleanValue(this, ac)
377- let liquidityPower = getBooleanValue(this, liquidityAc)
378- let poolKey = kp(asset1, asset2)
379- let lpAssetId = getStringValue(this, (lp + poolKey))
380- let lpAsset = fromBase58String(lpAssetId)
381- let pmt = i.payments[0]
382- let pmtAssetId = match pmt.assetId {
383- case a: ByteVector =>
384- toBase58String(a)
385- case _ =>
386- "GIC"
387- }
388- let decimals1 = getAssetDecimals(asset1)
389- let decimals2 = getAssetDecimals(asset2)
390- if (!(power))
391- then throw("dApp is currently under maintenance")
392- else if (liquidityPower)
393- then throw("Liquidity is currently under maintenance")
394- else if ((lpAssetId == ""))
395- then throw("Invalid LP asset")
396- else if ((pmtAssetId != lpAssetId))
397- then throw("Invalid LP token")
398- else if ((validPoolK(poolKey) == 0))
399- then throw("Pool does not exist")
400- else if ((0 >= lpAmount))
401- then throw("LP amount must be positive")
402- else {
403- let poolAmount1 = poolAA(poolKey, asset1)
404- let poolAmount2 = poolAA(poolKey, asset2)
405- let totalLpSupply = match assetInfo(fromBase58String(lpAssetId)) {
406- case a: Asset =>
407- a.quantity
408- case _ =>
409- 0
410- }
411- let amount1 = ((lpAmount * poolAmount1) / totalLpSupply)
412- let amount2 = ((lpAmount * poolAmount2) / totalLpSupply)
413- let currentKey = toBase58String(i.caller.bytes)
414- let currentAmountAsset1 = userLiquidity(currentKey, poolKey, asset1)
415- let currentAmountAsset2 = userLiquidity(currentKey, poolKey, asset2)
416- let newAmountAsset1 = (currentAmountAsset1 - amount1)
417- let newAmountAsset2 = (currentAmountAsset2 - amount2)
418- if (if ((0 > newAmountAsset1))
419- then true
420- else (0 > newAmountAsset2))
421- then throw("Insufficient liquidity balance")
422- else {
423- let newPoolAmount1 = (poolAmount1 - amount1)
424- let newPoolAmount2 = (poolAmount2 - amount2)
425- let asset1Bytes = if ((asset1 == "GIC"))
426- then unit
427- else fromBase58String(asset1)
428- let asset2Bytes = if ((asset2 == "GIC"))
429- then unit
430- else fromBase58String(asset2)
431- let oldAssetLpTotal = getIntegerValue(poolKey)
432-[IntegerEntry(((((poolKey + "_") + currentKey) + "_") + asset1), newAmountAsset1), IntegerEntry(((((poolKey + "_") + currentKey) + "_") + asset2), newAmountAsset2), IntegerEntry(((poolKey + "_") + asset1), newPoolAmount1), IntegerEntry(((poolKey + "_") + asset2), newPoolAmount2), IntegerEntry(poolKey, (oldAssetLpTotal - lpAmount)), Burn(lpAsset, lpAmount), ScriptTransfer(i.caller, amount1, asset1Bytes), ScriptTransfer(i.caller, amount2, asset2Bytes)]
433- }
434- }
435- }
436-
437-
438-
439-@Callable(i)
440-func swap (assetIn,assetOut,maxSlippage) = {
441- let power = getBooleanValue(this, ac)
442- let swapActivate = getBooleanValue(this, swapAc)
443- let acGic = getBooleanValue(this, "accept_gic")
444- let poolKey = kp(assetIn, assetOut)
445- let reversePoolKey = kp(assetOut, assetIn)
446- let key = if ((validPoolK(poolKey) != 0))
447- then poolKey
448- else if ((validPoolK(reversePoolKey) != 0))
449- then reversePoolKey
450- else ""
451- let pmt = i.payments[0]
452- let pmtAssetId = match pmt.assetId {
453- case a: ByteVector =>
454- toBase58String(a)
455- case _ =>
456- "GIC"
457- }
458- let decimalsIn = getAssetDecimals(assetIn)
459- let decimalsOut = getAssetDecimals(assetOut)
460- let feeBps = toBigInt(getIntegerValue(this, swapFee))
461- let adminAddr = addressFromStringValue(getStringValue(this, adminAddress))
462- if (!(power))
463- then throw("dApp is currently under maintenance")
464- else if (swapActivate)
465- then throw("Swap is currently under maintenance")
466- else if ((pmtAssetId != assetIn))
467- then throw("Payment asset does not match assetIn")
468- else if (!(isValidAsset(assetIn)))
469- then throw("Invalid assetIn")
470- else if (!(isValidAsset(assetOut)))
471- then throw("Invalid assetOut")
472- else if (if (isBlacklisted(assetIn))
473- then true
474- else isBlacklisted(assetOut))
475- then throw("One or both assets are blacklisted")
476- else if ((assetIn == assetOut))
477- then throw("assetIn cannot be equal to assetOut")
478- else if (if (if ((assetIn == "GIC"))
479- then true
480- else (assetOut == "GIC"))
481- then !(acGic)
482- else false)
483- then throw("GIC not allowed")
484- else if ((key == ""))
485- then throw("Pool does not exist")
486- else {
487- let isReverse = (key == reversePoolKey)
488- let poolAsset1 = if (isReverse)
489- then assetOut
490- else assetIn
491- let poolAsset2 = if (isReverse)
492- then assetIn
493- else assetOut
494- let poolAmount1 = toBigInt(poolAA(key, poolAsset1))
495- let poolAmount2 = toBigInt(poolAA(key, poolAsset2))
496- let amountInAdjusted = toBigInt(pmt.amount)
497- let amountOut = if (isReverse)
498- then ((amountInAdjusted * poolAmount1) / poolAmount2)
499- else ((amountInAdjusted * poolAmount2) / poolAmount1)
500- let fee = ((amountOut * feeBps) / toBigInt(10000))
501- let amountOutAfterFee = (amountOut - fee)
502- let feeToSend = ((amountInAdjusted * feeBps) / toBigInt(10000))
503- let minAmountOut = ((amountOutAfterFee * toBigInt((10000 - maxSlippage))) / toBigInt(10000))
504- if ((minAmountOut > amountOutAfterFee))
505- then throw("Slippage exceeded")
506- else {
507- let newPoolAmount1 = if (isReverse)
508- then (poolAmount1 - amountOut)
509- else (poolAmount1 + amountInAdjusted)
510- let newPoolAmount2 = if (isReverse)
511- then (poolAmount2 + amountInAdjusted)
512- else (poolAmount2 - amountOut)
513- let assettoReceive = if ((assetOut == "GIC"))
514- then unit
515- else fromBase58String(assetOut)
516- let assetOutBytes = if ((assetIn == "GIC"))
517- then unit
518- else fromBase58String(assetIn)
519-[IntegerEntry(((key + "_") + poolAsset1), toInt(newPoolAmount1)), IntegerEntry(((key + "_") + poolAsset2), toInt(newPoolAmount2)), BooleanEntry("isReverse", isReverse), ScriptTransfer(i.caller, toInt(amountOutAfterFee), assettoReceive), ScriptTransfer(adminAddr, toInt(feeToSend), assetOutBytes)]
520- }
521- }
522- }
523-
524-
525-
526-@Callable(i)
527-func farmsAddLP (asset1,asset2) = {
528- let power = getBooleanValue(this, ac)
529- let farmPower = getBooleanValue(this, farmAc)
530- let poolKey = kp(asset1, asset2)
531- let farmKey = fk(asset1, asset2)
532- let pmt = i.payments[0]
533- let lpAssetId = getStringValue(this, (lp + poolKey))
534- let pmtAssetId = match pmt.assetId {
535- case a: ByteVector =>
536- toBase58String(a)
537- case _ =>
538- "GIC"
539- }
540- if (!(power))
541- then throw("dApp is currently under maintenance")
542- else if (farmPower)
543- then throw("Farms are currently under maintenance")
544- else if ((pmtAssetId != lpAssetId))
545- then throw("Invalid LP token")
546- else if ((validPoolK(poolKey) == 0))
547- then throw("Pool does not exist")
548- else if ((valueOrElse(getInteger(this, farmKey), 0) == 0))
549- then throw("Farm does not exist")
550- else {
551- let currentKey = toBase58String(i.caller.bytes)
552- let stakedKey = sk(asset1, asset2, currentKey)
553- let currentStaked = valueOrElse(getInteger(this, stakedKey), 0)
554- let newStaked = (currentStaked + pmt.amount)
555- let totalStakedKey = (farmTotalStaked + poolKey)
556- let previousTotalStaked = valueOrElse(getInteger(this, totalStakedKey), 0)
557- let newTotalStaked = (previousTotalStaked + pmt.amount)
558- let totalUsers = valueOrElse(getInteger(this, (totalUsersFarm + poolKey)), 0)
559- let newTotalUsers = if ((currentStaked == 0))
560- then (totalUsers + 1)
561- else totalUsers
562-[IntegerEntry(stakedKey, newStaked), IntegerEntry(totalStakedKey, newTotalStaked), IntegerEntry((totalUsersFarm + poolKey), newTotalUsers), IntegerEntry(fh(asset1, asset2, currentKey), height)]
563- }
564- }
565-
566-
567-
568-@Callable(i)
569-func farmsClaimLP (asset1,asset2) = {
570- let power = getBooleanValue(this, ac)
571- let farmPower = getBooleanValue(this, farmAc)
572- let poolKey = kp(asset1, asset2)
573- let farmKey = fk(asset1, asset2)
574- let currentKey = toBase58String(i.caller.bytes)
575- let stakedKey = sk(asset1, asset2, currentKey)
576- let heightKey = fh(asset1, asset2, currentKey)
577- let rewardKey = rk(asset1, asset2, currentKey)
578- if (!(power))
579- then throw("dApp is currently under maintenance")
580- else if (farmPower)
581- then throw("Farms are currently under maintenance")
582- else if ((validPoolK(poolKey) == 0))
583- then throw("Pool does not exist")
584- else if ((valueOrElse(getInteger(this, farmKey), 0) == 0))
585- then throw("Farm does not exist")
586- else {
587- let currentStaked = valueOrElse(getInteger(this, stakedKey), 0)
588- if ((0 >= currentStaked))
589- then throw("No staked LP tokens")
590- else {
591- let rewardPool = valueOrElse(getInteger(this, (farmRewardPool + poolKey)), 0)
592- let totalUsers = valueOrElse(getInteger(this, (totalUsersFarm + poolKey)), 1)
593- let lockBlocks = getIntegerValue(this, (farmLockBlocks + poolKey))
594- let apr = getIntegerValue(this, (farmApr + poolKey))
595- let lastClaimHeight = valueOrElse(getInteger(this, heightKey), height)
596- let blocksSinceLastClaim = (height - lastClaimHeight)
597- if ((1 > blocksSinceLastClaim))
598- then throw("Must wait at least 1 block since last claim")
599- else {
600- let rewardPerBlock = ((rewardPool * apr) / ((10000 * lockBlocks) * totalUsers))
601- let reward = (((rewardPerBlock * blocksSinceLastClaim) * currentStaked) / D8)
602- if ((reward > rewardPool))
603- then throw("Insufficient reward pool")
604- else {
605- let newRewardPool = (rewardPool - reward)
606-[IntegerEntry(rewardKey, 0), IntegerEntry((farmRewardPool + poolKey), newRewardPool), IntegerEntry(heightKey, height), ScriptTransfer(i.caller, reward, unit)]
607- }
608- }
609- }
610- }
611- }
612-
613-
614-
615-@Callable(i)
616-func farmsRemoveLP (asset1,asset2,amount) = {
617- let power = getBooleanValue(this, ac)
618- let farmPower = getBooleanValue(this, farmAc)
619- let poolKey = kp(asset1, asset2)
620- let farmKey = fk(asset1, asset2)
621- let lpAssetId = getStringValue(this, (lp + poolKey))
622- let lpAsset = if ((lpAssetId == ""))
623- then unit
624- else fromBase58String(lpAssetId)
625- let currentKey = toBase58String(i.caller.bytes)
626- let stakedKey = sk(asset1, asset2, currentKey)
627- let heightKey = fh(asset1, asset2, currentKey)
628- let rewardKey = rk(asset1, asset2, currentKey)
629- if (!(power))
630- then throw("dApp is currently under maintenance")
631- else if (farmPower)
632- then throw("Farms are currently under maintenance")
633- else if ((validPoolK(poolKey) == 0))
634- then throw("Pool does not exist")
635- else if ((valueOrElse(getInteger(this, farmKey), 0) == 0))
636- then throw("Farm does not exist")
637- else {
638- let currentStaked = valueOrElse(getInteger(this, stakedKey), 0)
639- if ((0 >= amount))
640- then throw("Amount must be positive")
641- else if ((amount > currentStaked))
642- then throw("Insufficient staked LP tokens")
643- else {
644- let rewardPool = valueOrElse(getInteger(this, (farmRewardPool + poolKey)), 0)
645- let totalUsers = valueOrElse(getInteger(this, (totalUsersFarm + poolKey)), 1)
646- let lockBlocks = getIntegerValue(this, (farmLockBlocks + poolKey))
647- let apr = getIntegerValue(this, (farmApr + poolKey))
648- let lastClaimHeight = valueOrElse(getInteger(this, heightKey), height)
649- let blocksSinceLastClaim = (height - lastClaimHeight)
650- let rewardPerBlock = ((rewardPool * apr) / ((10000 * lockBlocks) * totalUsers))
651- let reward = if ((blocksSinceLastClaim >= 1))
652- then (((rewardPerBlock * blocksSinceLastClaim) * currentStaked) / D8)
653- else 0
654- let newRewardPool = (rewardPool - reward)
655- let newStaked = (currentStaked - amount)
656- let totalStakedKey = (farmTotalStaked + poolKey)
657- let previousTotalStaked = valueOrElse(getInteger(this, totalStakedKey), 0)
658- let newTotalStaked = (previousTotalStaked - amount)
659- let newTotalUsers = if ((newStaked == 0))
660- then (totalUsers - 1)
661- else totalUsers
662-[IntegerEntry(stakedKey, newStaked), IntegerEntry(totalStakedKey, newTotalStaked), IntegerEntry((totalUsersFarm + poolKey), newTotalUsers), IntegerEntry(rewardKey, 0), IntegerEntry((farmRewardPool + poolKey), newRewardPool), IntegerEntry(heightKey, height), ScriptTransfer(i.caller, amount, lpAsset), ScriptTransfer(i.caller, reward, unit)]
663- }
664- }
125+ let feeBps = toBigInt(getIntegerValue(this, fee))
126+ let isSale = valueOrElse(getBooleanValue(("is_sale_" + nftId)), false)
127+ let valueSale = valueOrElse(getIntegerValue(("price_sale_" + nftId)), 0)
128+ let feeToSend = ((toBigInt(pay.amount) * feeBps) / toBigInt(10000))
129+ let adminAddr = getAdminAddress()
130+ let OldNumberH = valueOrElse(getIntegerValue(this, ("history_" + pmtAssetId)), 0)
131+ let numberH = (OldNumberH + 1)
132+ let OldNumberHUser = valueOrElse(getIntegerValue(this, ("history_" + pmtAssetId)), 0)
133+ let numberHUser = (OldNumberH + 1)
134+ let toSendToSaler = (toBigInt(pay.amount) - feeToSend)
135+ if ((pmtAssetId != "GIC"))
136+ then throw("Error: Invalid Asset to buy.")
137+ else if (!(isSale))
138+ then throw("This NFT is no longer for sale.")
139+ else if ((valueSale != pay.amount))
140+ then throw("Insufficient value to make the purchase.")
141+ else [ScriptTransfer(i.caller, 1, fromBase58String(nftId)), ScriptTransfer(addressFromStringValue(getStringValue(this, ("saler_" + pmtAssetId))), toInt(toSendToSaler), unit), ScriptTransfer(addressFromStringValue(adminAddr), toInt(feeToSend), unit), BooleanEntry(("is_sale_" + pmtAssetId), false), StringEntry(("saler_" + pmtAssetId), toBase58String(i.caller.bytes)), IntegerEntry(("history_" + pmtAssetId), numberH), StringEntry((("history_" + pmtAssetId) + toString(numberH)), "buy")]
665142 }
666143
667144
668145 @Verifier(tx)
669-func verify () = match tx {
670- case _ =>
671- sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey)
672-}
146+func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey)
673147

github/gicsportsofficial/g8-explorer
73.19 ms