tx · ETyneK55TP6tRJ7pzf7bK7MTgCeFG23YwdVFhHfrVjmD

3PDrYPF6izza2sXWffzTPF7e2Fcir2CMpki:  -0.02500000 Waves

2022.11.25 18:32 [3398267] smart account 3PDrYPF6izza2sXWffzTPF7e2Fcir2CMpki > SELF 0.00000000 Waves

{ "type": 13, "id": "ETyneK55TP6tRJ7pzf7bK7MTgCeFG23YwdVFhHfrVjmD", "fee": 2500000, "feeAssetId": null, "timestamp": 1669390376934, "version": 2, "chainId": 87, "sender": "3PDrYPF6izza2sXWffzTPF7e2Fcir2CMpki", "senderPublicKey": "BHGZUnraSaYR29gbS4KuRhjkKjKbD22KfX6vjJdcMQd3", "proofs": [ "3ecZasp22q4FD8UR3fHSfYT7BsTanQdJ6dcrYUj7ykyYaq1fog5SebFREL98Dui6J6HvNuYGHQUo9ppptqkEicM3" ], "script": "base64:AAIFAAAAAAAAAAQIAhIAAAAAAAAAAAEAAAABaQEAAAAEY2FsbAAAAAAJAAACAAAAAQIAAAAZcG9vbCBpcyB1bmRlciBtYWludGVuYW5jZQAAAAEAAAACdHgBAAAABnZlcmlmeQAAAAAJAAH0AAAAAwgFAAAAAnR4AAAACWJvZHlCeXRlcwkAAZEAAAACCAUAAAACdHgAAAAGcHJvb2ZzAAAAAAAAAAAACAUAAAACdHgAAAAPc2VuZGVyUHVibGljS2V5oG4yfg==", "height": 3398267, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: CFFzphchdp3AfYobfgrNXFSuJCTZH8UafsELys5D9cte Next: 2zWhSJENqobKB6LM49siDk7p854YqzbnXjFm4Wktzxe3 Full:
OldNewDifferences
11 {-# STDLIB_VERSION 5 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
4-let T = 10
5-
6-let assetIds = [unit, base58'C1iWsKGqLwjHUndiQ7iXpdmPum9PeCDFfyXBdJJosDRS', base58'Ehie5xYpeN8op1Cctc6aGUrqx8jq3jtf1DSjXDbfm7aT', base58'DSbbhLsSTeDg5Lsiufk2Aneh3DjVqJuPr2M9uU1gwy5p', base58'6nSpVyNH7yM69eg446wrQR94ipbbcmZMU1ENPwanC97g', base58'7LMV3s1J4dKpMQZqge5sKYoFkZRLojnnU49aerqos4yg', base58'9sQutD5HnRvjM1uui5cVC4w9xkMPAfYEV8ymug3Mon2Y', base58'HEB8Qaw9xrWpWs8tHsiATYGBWDBtP2S7kcPALrMu43AS', base58'34N9YcEETLWn93qYQ64EsP1x89tSruJU44RrEMSXXEPJ', base58'DG2xFkPdDwKUoBkzGAhQtLpSGzfXLiCYPEzeKH2Ad24p']
7-
8-let AssetsWeights = [20, 10, 5, 5, 5, 5, 5, 20, 10, 15]
9-
10-let AssetsWeightsDecimals = 2
11-
12-let PoolTokenDecimals = 8
13-
14-let Decimals = [8, 8, 8, 8, 6, 8, 8, 8, 6, 6]
15-
16-let Scales = [100000000, 100000000, 100000000, 100000000, 1000000, 100000000, 100000000, 100000000, 1000000, 1000000]
17-
18-let Fee = 200
19-
20-let Scale = 10000
21-
22-let Scale8 = 100000000
23-
24-let FeeScale = 10000
25-
26-let feeAggregator = Address(base58'3PES7MMthaKJx9WMXnNCY3cwTGG9nD9YT8f')
27-
28-func getAssetString (assetId) = match assetId {
29- case b: ByteVector =>
30- toBase58String(b)
31- case _ =>
32- "WAVES"
33-}
34-
35-
36-func getAssetBytes (assetIdStr) = if ((assetIdStr == "WAVES"))
37- then unit
38- else fromBase58String(assetIdStr)
39-
40-
41-let earnedAssets = assetIds
42-
43-func tryGetInteger (key) = match getInteger(this, key) {
44- case b: Int =>
45- b
46- case _ =>
47- 0
48-}
49-
50-
51-func tryGetBinary (key) = match getBinary(this, key) {
52- case b: ByteVector =>
53- b
54- case _ =>
55- base58''
56-}
57-
58-
59-func getCurrentTokenBalance (tokenType) = {
60- let tokenId = getAssetString(assetIds[tokenType])
61- tryGetInteger((("global_" + tokenId) + "_balance"))
62- }
63-
64-
65-func calculatePIssued (amount,tokenId) = {
66- let Psupply = tryGetInteger("global_poolToken_amount")
67- let Balance = tryGetInteger((("global_" + getAssetString(tokenId)) + "_balance"))
68- fraction(amount, Psupply, Balance, DOWN)
69- }
70-
71-
72-func getMinPIssued (payments) = {
73- func handler (accum,current) = {
74- let PIssued = calculatePIssued(current.amount, current.assetId)
75- if ((PIssued == 0))
76- then throw("one of the tokens amounts is too low")
77- else if (if ((accum == 0))
78- then true
79- else (accum > PIssued))
80- then PIssued
81- else accum
82- }
83-
84- let minPIssed = {
85- let $l = payments
86- let $s = size($l)
87- let $acc0 = 0
88- func $f0_1 ($a,$i) = if (($i >= $s))
89- then $a
90- else handler($a, $l[$i])
91-
92- func $f0_2 ($a,$i) = if (($i >= $s))
93- then $a
94- else throw("List size exceeds 10")
95-
96- $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10)
97- }
98- minPIssed
99- }
100-
101-
102-func calculateUsdnValue (assetId,amount,aBalance) = {
103- let usdnId = base58'DG2xFkPdDwKUoBkzGAhQtLpSGzfXLiCYPEzeKH2Ad24p'
104- let usdnWeight = AssetsWeights[value(indexOf(assetIds, usdnId))]
105- let assetWeight = AssetsWeights[value(indexOf(assetIds, assetId))]
106- let usdnBalance = tryGetInteger((("global_" + getAssetString(usdnId)) + "_balance"))
107- fraction(amount, (usdnBalance / usdnWeight), (aBalance / assetWeight))
108- }
109-
110-
111-func checkTokensValidity (payments) = {
112- func handler1 (accum,payment) = (accum ++ [payment.assetId])
113-
114- let ids = {
115- let $l = payments
116- let $s = size($l)
117- let $acc0 = nil
118- func $f0_1 ($a,$i) = if (($i >= $s))
119- then $a
120- else handler1($a, $l[$i])
121-
122- func $f0_2 ($a,$i) = if (($i >= $s))
123- then $a
124- else throw("List size exceeds 10")
125-
126- $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10)
127- }
128- if ((ids == ids))
129- then {
130- func handler2 (accum,assetId) = if ((indexOf(ids, assetId) != unit))
131- then (accum + 1)
132- else throw(("asset not attached: " + getAssetString(assetId)))
133-
134- let checks = {
135- let $l = assetIds
136- let $s = size($l)
137- let $acc0 = 0
138- func $f1_1 ($a,$i) = if (($i >= $s))
139- then $a
140- else handler2($a, $l[$i])
141-
142- func $f1_2 ($a,$i) = if (($i >= $s))
143- then $a
144- else throw("List size exceeds 10")
145-
146- $f1_2($f1_1($f1_1($f1_1($f1_1($f1_1($f1_1($f1_1($f1_1($f1_1($f1_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10)
147- }
148- if ((checks == checks))
149- then true
150- else throw("Strict value is not equal to itself.")
151- }
152- else throw("Strict value is not equal to itself.")
153- }
154-
155-
156-func handlePoolTokensAdd (PIssued,payments,userAddress,needChange) = {
157- func getTokenPaymentAmount (tokenId) = {
158- func handler (accum,payment) = if ((payment.assetId == tokenId))
159- then payment.amount
160- else accum
161-
162- let $l = payments
163- let $s = size($l)
164- let $acc0 = 0
165- func $f0_1 ($a,$i) = if (($i >= $s))
166- then $a
167- else handler($a, $l[$i])
168-
169- func $f0_2 ($a,$i) = if (($i >= $s))
170- then $a
171- else throw("List size exceeds 10")
172-
173- $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10)
174- }
175-
176- func handleTokenChange (accum,tokenId) = {
177- let Bk = tryGetInteger((("global_" + getAssetString(tokenId)) + "_balance"))
178- let PSupply = tryGetInteger("global_poolToken_amount")
179- let tokenDecimals = tryGetInteger((("static_" + getAssetString(tokenId)) + "_scale"))
180- let Dk = fraction((fraction((PSupply + PIssued), tokenDecimals, PSupply, CEILING) - tokenDecimals), Bk, tokenDecimals, CEILING)
181- let paymentAmount = getTokenPaymentAmount(tokenId)
182- let toReturn = ((if ((paymentAmount != 0))
183- then paymentAmount
184- else 0) - Dk)
185- let t = if (if (needChange)
186- then (toReturn > 0)
187- else false)
188- then [ScriptTransfer(userAddress, toReturn, tokenId)]
189- else nil
190- ((accum ++ t) ++ [IntegerEntry((("global_" + getAssetString(tokenId)) + "_balance"), (Bk + Dk))])
191- }
192-
193- let $l = assetIds
194- let $s = size($l)
195- let $acc0 = nil
196- func $f0_1 ($a,$i) = if (($i >= $s))
197- then $a
198- else handleTokenChange($a, $l[$i])
199-
200- func $f0_2 ($a,$i) = if (($i >= $s))
201- then $a
202- else throw("List size exceeds 10")
203-
204- $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10)
205- }
206-
207-
208-func handlePoolTokensRedeem (PRedeemed,userAddress) = {
209- func handleTokenRedeem (accum,tokenId) = {
210- let Bk = tryGetInteger((("global_" + getAssetString(tokenId)) + "_balance"))
211- let PSupply = tryGetInteger("global_poolToken_amount")
212- let tokenDecimals = tryGetInteger((("static_" + getAssetString(tokenId)) + "_scale"))
213- let amount = fraction((tokenDecimals - fraction((PSupply - PRedeemed), tokenDecimals, PSupply, DOWN)), Bk, tokenDecimals, DOWN)
214- (accum ++ [IntegerEntry((("global_" + getAssetString(tokenId)) + "_balance"), (Bk - amount))])
215- }
216-
217- func handleTokenRedeem2 (accum,tokenId) = {
218- let Bk = tryGetInteger((("global_" + getAssetString(tokenId)) + "_balance"))
219- let PSupply = tryGetInteger("global_poolToken_amount")
220- let tokenDecimals = tryGetInteger((("static_" + getAssetString(tokenId)) + "_scale"))
221- let amount = fraction((tokenDecimals - fraction((PSupply - PRedeemed), tokenDecimals, PSupply, DOWN)), Bk, tokenDecimals, DOWN)
222- (accum ++ [ScriptTransfer(userAddress, amount, tokenId)])
223- }
224-
225- ({
226- let $l = assetIds
227- let $s = size($l)
228- let $acc0 = nil
229- func $f0_1 ($a,$i) = if (($i >= $s))
230- then $a
231- else handleTokenRedeem($a, $l[$i])
232-
233- func $f0_2 ($a,$i) = if (($i >= $s))
234- then $a
235- else throw("List size exceeds 10")
236-
237- $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10)
238- } ++ {
239- let $l = assetIds
240- let $s = size($l)
241- let $acc0 = nil
242- func $f1_1 ($a,$i) = if (($i >= $s))
243- then $a
244- else handleTokenRedeem2($a, $l[$i])
245-
246- func $f1_2 ($a,$i) = if (($i >= $s))
247- then $a
248- else throw("List size exceeds 10")
249-
250- $f1_2($f1_1($f1_1($f1_1($f1_1($f1_1($f1_1($f1_1($f1_1($f1_1($f1_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10)
251- })
252- }
253-
254-
255-func calculateOutAmount (AmountIn,assetIn,assetOut,BalanceIn,BalanceOut) = {
256- let IndexIn = value(indexOf(assetIds, assetIn))
257- let IndexOut = value(indexOf(assetIds, assetOut))
258- if ((IndexIn == IndexOut))
259- then throw("wrong tokens pair")
260- else fraction(BalanceOut, ((Scale8 * Scale8) - toInt(pow(fraction(toBigInt(BalanceIn), toBigInt((Scale8 * Scale8)), toBigInt((BalanceIn + AmountIn)), HALFUP), 16, toBigInt(fraction(AssetsWeights[IndexIn], 10000, AssetsWeights[IndexOut])), 4, 16, CEILING))), (Scale8 * Scale8), DOWN)
261- }
262-
263-
264-func getTokenBalance (assetId) = match assetId {
265- case t: ByteVector =>
266- assetBalance(this, t)
267- case _ =>
268- wavesBalance(this).available
269-}
270-
271-
272-func calculateCurrentAssetInterest (assetId,assetIdStr,aBalance,tokenEarningsLastCheck) = {
273- let totalStaked = tryGetInteger("global_indexStaked")
274- let tokenBalanceLastCheck = tokenEarningsLastCheck
275- let currentBalanceDelta = (getTokenBalance(assetId) - aBalance)
276- let currentTokenEarnings = if ((currentBalanceDelta > tokenBalanceLastCheck))
277- then currentBalanceDelta
278- else tokenBalanceLastCheck
279- let newEarnings = (currentTokenEarnings - tokenBalanceLastCheck)
280- let newInterest = if ((totalStaked == 0))
281- then 0
282- else fraction(newEarnings, Scale8, totalStaked)
283- let lastCheckInterest = tryGetInteger((("global_lastCheck_" + assetIdStr) + "_interest"))
284- (lastCheckInterest + newInterest)
285- }
286-
287-
288-func claimResult (address) = {
289- let addressStr = toString(address)
290- let puzzleAmount = tryGetInteger((addressStr + "_indexStaked"))
291- func handler (accum,assetId) = {
292- let assetIdStr = getAssetString(assetId)
293- let aBalance = tryGetInteger((("global_" + getAssetString(assetId)) + "_balance"))
294- let tokenEarningsLastCheck = tryGetInteger((("global_lastCheck_" + assetIdStr) + "_earnings"))
295- let currentTokenInterest = calculateCurrentAssetInterest(assetId, assetIdStr, aBalance, tokenEarningsLastCheck)
296- let currentTokenEarnings = max([tokenEarningsLastCheck, (getTokenBalance(assetId) - aBalance)])
297- let rewardAmount = fraction(puzzleAmount, (currentTokenInterest - tryGetInteger((((addressStr + "_lastCheck_") + assetIdStr) + "_interest"))), Scale8)
298- let transfer = if ((rewardAmount == 0))
299- then nil
300- else [ScriptTransfer(address, rewardAmount, assetId)]
301- $Tuple2(((accum._1 ++ transfer) ++ [IntegerEntry((("global_lastCheck_" + assetIdStr) + "_earnings"), (currentTokenEarnings - rewardAmount)), IntegerEntry((("global_lastCheck_" + assetIdStr) + "_interest"), currentTokenInterest), IntegerEntry((((addressStr + "_lastCheck_") + assetIdStr) + "_interest"), currentTokenInterest)]), (accum._2 + calculateUsdnValue(assetId, rewardAmount, aBalance)))
302- }
303-
304- let accum = {
305- let $l = earnedAssets
306- let $s = size($l)
307- let $acc0 = $Tuple2(nil, 0)
308- func $f0_1 ($a,$i) = if (($i >= $s))
309- then $a
310- else handler($a, $l[$i])
311-
312- func $f0_2 ($a,$i) = if (($i >= $s))
313- then $a
314- else throw("List size exceeds 10")
315-
316- $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10)
317- }
318- (accum._1 ++ [IntegerEntry((addressStr + "_claimedRewardValue"), (tryGetInteger((addressStr + "_claimedRewardValue")) + accum._2)), IntegerEntry((addressStr + "_lastClaim"), lastBlock.timestamp)])
319- }
320-
321-
322-func indexStakeResult (addressStr,amount) = {
323- let li = claimResult(addressFromStringValue(addressStr))
324- (li ++ [IntegerEntry((addressStr + "_indexStaked"), (tryGetInteger((addressStr + "_indexStaked")) + amount)), IntegerEntry("global_indexStaked", (tryGetInteger("global_indexStaked") + amount))])
325- }
3264
3275
3286 @Callable(i)
329-func preInit () = {
330- func handler (accum,assetNum) = if ((assetNum >= T))
331- then accum
332- else (accum ++ [IntegerEntry((("static_" + getAssetString(assetIds[assetNum])) + "_scale"), Scales[assetNum]), IntegerEntry((("static_" + getAssetString(assetIds[assetNum])) + "_weight"), AssetsWeights[assetNum])])
333-
334- let $l = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
335- let $s = size($l)
336- let $acc0 = nil
337- func $f0_1 ($a,$i) = if (($i >= $s))
338- then $a
339- else handler($a, $l[$i])
340-
341- func $f0_2 ($a,$i) = if (($i >= $s))
342- then $a
343- else throw("List size exceeds 10")
344-
345- $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10)
346- }
7+func call () = throw("pool is under maintenance")
3478
3489
349-
350-@Callable(i)
351-func deInit () = if ((i.caller != this))
352- then throw("admin only")
353- else [IntegerEntry("global_wasInited", 0)]
354-
355-
356-
357-@Callable(i)
358-func init () = {
359- func prepareList () = {
360- func handler (accum,n) = (accum ++ [IntegerEntry((("global_" + getAssetString(n.assetId)) + "_balance"), n.amount)])
361-
362- let $l = i.payments
363- let $s = size($l)
364- let $acc0 = nil
365- func $f0_1 ($a,$i) = if (($i >= $s))
366- then $a
367- else handler($a, $l[$i])
368-
369- func $f0_2 ($a,$i) = if (($i >= $s))
370- then $a
371- else throw("List size exceeds 10")
372-
373- $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10)
374- }
375-
376- func calculatePoolTokensAmount (payments) = {
377- func handler (accum,pmt) = {
378- let assetId = pmt.assetId
379- func handler2 (accum,n) = if ((n == assetId))
380- then value(indexOf(assetIds, n))
381- else accum
382-
383- let Token = {
384- let $l = assetIds
385- let $s = size($l)
386- let $acc0 = 1
387- func $f0_1 ($a,$i) = if (($i >= $s))
388- then $a
389- else handler2($a, $l[$i])
390-
391- func $f0_2 ($a,$i) = if (($i >= $s))
392- then $a
393- else throw("List size exceeds 10")
394-
395- $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10)
396- }
397- (accum * pow(pmt.amount, Decimals[Token], AssetsWeights[Token], AssetsWeightsDecimals, 1, FLOOR))
398- }
399-
400- let $l = payments
401- let $s = size($l)
402- let $acc0 = 1
403- func $f0_1 ($a,$i) = if (($i >= $s))
404- then $a
405- else handler($a, $l[$i])
406-
407- func $f0_2 ($a,$i) = if (($i >= $s))
408- then $a
409- else throw("List size exceeds 10")
410-
411- $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10)
412- }
413-
414- if ((tryGetInteger("global_wasInited") > 0))
415- then throw("pool already inited")
416- else {
417- let initialPoolTokens = calculatePoolTokensAmount(i.payments)
418- let poolTokenIssue = Issue("Puzzle5", "Puzzle Swap Pool Token", initialPoolTokens, PoolTokenDecimals, true, unit, 0)
419- let poolTokenId = calculateAssetId(poolTokenIssue)
420- (prepareList() ++ [poolTokenIssue, IntegerEntry("global_poolToken_amount", initialPoolTokens), IntegerEntry("global_wasInited", 1), BinaryEntry("global_poolToken_id", poolTokenId), ScriptTransfer(i.caller, initialPoolTokens, poolTokenId)])
421- }
422- }
423-
424-
425-
426-@Callable(i)
427-func generateIndex (needChange) = if ((size(i.payments) != T))
428- then throw(("you need to attach all pool tokens. amount of pool tokens: " + toString(T)))
429- else if (!(checkTokensValidity(i.payments)))
430- then throw("wrong assets attached")
431- else {
432- let PIssued = getMinPIssued(i.payments)
433- let reissue = Reissue(getBinaryValue("global_poolToken_id"), PIssued, true)
434- let result = handlePoolTokensAdd(PIssued, i.payments, i.originCaller, needChange)
435- $Tuple2((result ++ [ScriptTransfer(i.caller, PIssued, tryGetBinary("global_poolToken_id")), reissue, IntegerEntry("global_poolToken_amount", (tryGetInteger("global_poolToken_amount") + PIssued))]), PIssued)
436- }
437-
438-
439-
440-@Callable(i)
441-func stakeIndex () = {
442- let addressStr = toString(i.originCaller)
443- let pmt = i.payments[0]
444- if ((value(pmt.assetId) != tryGetBinary("global_poolToken_id")))
445- then throw("wrong asset attached")
446- else indexStakeResult(addressStr, pmt.amount)
447- }
448-
449-
450-
451-@Callable(i)
452-func unstakeIndex (puzzleAmount) = {
453- let addressStr = toString(i.originCaller)
454- let puzzleAvailable = tryGetInteger((addressStr + "_indexStaked"))
455- if ((puzzleAmount > puzzleAvailable))
456- then throw("you don't have index tokens available")
457- else (claimResult(i.originCaller) ++ [IntegerEntry((addressStr + "_indexStaked"), (puzzleAvailable - puzzleAmount)), IntegerEntry("global_indexStaked", (tryGetInteger("global_indexStaked") - puzzleAmount)), ScriptTransfer(i.caller, puzzleAmount, getBinaryValue("global_poolToken_id"))])
458- }
459-
460-
461-
462-@Callable(i)
463-func claimIndexRewards () = claimResult(i.caller)
464-
465-
466-
467-@Callable(i)
468-func redeemIndex (sendToOrigin) = {
469- let pmt = i.payments[0]
470- if ((pmt.assetId != tryGetBinary("global_poolToken_id")))
471- then throw("please attach pool share token")
472- else {
473- let PRedeemed = pmt.amount
474- let result = handlePoolTokensRedeem(PRedeemed, if (sendToOrigin)
475- then i.originCaller
476- else i.caller)
477- (result ++ [Burn(tryGetBinary("global_poolToken_id"), PRedeemed), IntegerEntry("global_poolToken_amount", (tryGetInteger("global_poolToken_amount") - PRedeemed))])
478- }
479- }
480-
481-
482-
483-@Callable(i)
484-func swap (assetOut,minimum) = {
485- let pmt = value(i.payments[0])
486- let AmountIn = value(i.payments[0].amount)
487- let AssetIn = pmt.assetId
488- let AssetOut = getAssetBytes(assetOut)
489- let puzzleFee = (i.caller == i.originCaller)
490- let AssetInBalance = tryGetInteger((("global_" + getAssetString(AssetIn)) + "_balance"))
491- let AssetOutBalance = tryGetInteger((("global_" + assetOut) + "_balance"))
492- let AmountOut = calculateOutAmount(AmountIn, AssetIn, AssetOut, AssetInBalance, AssetOutBalance)
493- let feeAmount = fraction(AmountOut, Fee, FeeScale)
494- let protocolFeeAmount = fraction(feeAmount, 40, 100)
495- let cleanAmountOut = (AmountOut - feeAmount)
496- if ((minimum > cleanAmountOut))
497- then throw(("amount to recieve is lower than given one: " + toString(cleanAmountOut)))
498- else if ((0 > (AssetOutBalance - AmountOut)))
499- then throw("contract is out of reserves")
500- else {
501- let newBalanceIn = (AssetInBalance + AmountIn)
502- let newBalanceOut = (AssetOutBalance - AmountOut)
503- if (puzzleFee)
504- then {
505- let cashbackAmount = protocolFeeAmount
506- let usdnAssetId = base58'DG2xFkPdDwKUoBkzGAhQtLpSGzfXLiCYPEzeKH2Ad24p'
507- let usdnBalance = if ((AssetIn == usdnAssetId))
508- then newBalanceIn
509- else if ((AssetOut == usdnAssetId))
510- then newBalanceOut
511- else tryGetInteger((("global_" + getAssetString(usdnAssetId)) + "_balance"))
512- let usdnCashbackAmount = if ((AssetOut == usdnAssetId))
513- then cashbackAmount
514- else calculateOutAmount(cashbackAmount, AssetOut, usdnAssetId, newBalanceOut, usdnBalance)
515- let usdnBalanceChange = if ((AssetOut != usdnAssetId))
516- then [IntegerEntry((("global_" + toBase58String(usdnAssetId)) + "_balance"), (usdnBalance - usdnCashbackAmount))]
517- else nil
518- let stakingTopUp = reentrantInvoke(Address(base58'3PFTbywqxtFfukX3HyT881g4iW5K4QL3FAS'), "topUpReward", nil, [AttachedPayment(usdnAssetId, usdnCashbackAmount)])
519- if ((stakingTopUp == stakingTopUp))
520- then $Tuple2(([IntegerEntry((("global_" + assetOut) + "_balance"), (newBalanceOut + cashbackAmount)), IntegerEntry((("global_" + getAssetString(AssetIn)) + "_balance"), newBalanceIn), ScriptTransfer(i.caller, cleanAmountOut, AssetOut), IntegerEntry("global_volume", (tryGetInteger("global_volume") + calculateUsdnValue(AssetIn, AmountIn, AssetInBalance)))] ++ usdnBalanceChange), cleanAmountOut)
521- else throw("Strict value is not equal to itself.")
522- }
523- else $Tuple2([IntegerEntry((("global_" + assetOut) + "_balance"), newBalanceOut), IntegerEntry((("global_" + getAssetString(AssetIn)) + "_balance"), newBalanceIn), ScriptTransfer(i.caller, cleanAmountOut, AssetOut), IntegerEntry("global_volume", (tryGetInteger("global_volume") + calculateUsdnValue(AssetIn, AmountIn, AssetInBalance)))], cleanAmountOut)
524- }
525- }
526-
527-
528-
529-@Callable(i)
530-func swapWithReferral (assetOut,minimum,refKey) = {
531- let pmt = value(i.payments[0])
532- let AmountIn = value(i.payments[0].amount)
533- let AssetIn = pmt.assetId
534- let AssetOut = getAssetBytes(assetOut)
535- let referralAddress = Address(base58'3PQGxTse5eWufds6GA41UnbUNqLcCEnVJL3')
536- let puzzleFee = (i.caller == i.originCaller)
537- let AssetInBalance = tryGetInteger((("global_" + getAssetString(AssetIn)) + "_balance"))
538- let AssetOutBalance = tryGetInteger((("global_" + assetOut) + "_balance"))
539- let AmountOut = calculateOutAmount(AmountIn, AssetIn, AssetOut, AssetInBalance, AssetOutBalance)
540- let feeAmount = fraction(AmountOut, Fee, FeeScale)
541- let protocolFeeAmount = fraction(feeAmount, 40, 100)
542- let cleanAmountOut = (AmountOut - feeAmount)
543- if ((minimum > cleanAmountOut))
544- then throw(("amount to recieve is lower than given one: " + toString(cleanAmountOut)))
545- else if ((0 > (AssetOutBalance - AmountOut)))
546- then throw("contract is out of reserves")
547- else {
548- let newBalanceIn = (AssetInBalance + AmountIn)
549- let newBalanceOut = (AssetOutBalance - AmountOut)
550- if (puzzleFee)
551- then {
552- let cashbackAmount = protocolFeeAmount
553- let usdnAssetId = base58'DG2xFkPdDwKUoBkzGAhQtLpSGzfXLiCYPEzeKH2Ad24p'
554- let usdnBalance = if ((AssetIn == usdnAssetId))
555- then newBalanceIn
556- else if ((AssetOut == usdnAssetId))
557- then newBalanceOut
558- else tryGetInteger((("global_" + getAssetString(usdnAssetId)) + "_balance"))
559- let usdnCashbackAmount = if ((AssetOut == usdnAssetId))
560- then cashbackAmount
561- else calculateOutAmount(cashbackAmount, AssetOut, usdnAssetId, newBalanceOut, usdnBalance)
562- let usdnBalanceChange = if ((AssetOut != usdnAssetId))
563- then [IntegerEntry((("global_" + toBase58String(usdnAssetId)) + "_balance"), (usdnBalance - usdnCashbackAmount))]
564- else nil
565- let puzzlePool = Address(base58'3PFDgzu1UtswAkCMxqqQjbTeHaX4cMab8Kh')
566- let puzzleAssetId = base58'HEB8Qaw9xrWpWs8tHsiATYGBWDBtP2S7kcPALrMu43AS'
567- let puzzleCashbackAmount = match reentrantInvoke(puzzlePool, "swap", [toBase58String(puzzleAssetId), 0], [AttachedPayment(usdnAssetId, (usdnCashbackAmount / 4))]) {
568- case x: Int =>
569- x
570- case _ =>
571- 0
572- }
573- if ((puzzleCashbackAmount == puzzleCashbackAmount))
574- then {
575- let stakingTopUp = reentrantInvoke(Address(base58'3PFTbywqxtFfukX3HyT881g4iW5K4QL3FAS'), "topUpReward", nil, [AttachedPayment(usdnAssetId, (usdnCashbackAmount / 2))])
576- if ((stakingTopUp == stakingTopUp))
577- then $Tuple2(([IntegerEntry((("global_" + assetOut) + "_balance"), (newBalanceOut + cashbackAmount)), IntegerEntry((("global_" + getAssetString(AssetIn)) + "_balance"), newBalanceIn), ScriptTransfer(i.caller, cleanAmountOut, AssetOut), ScriptTransfer(i.caller, puzzleCashbackAmount, puzzleAssetId), ScriptTransfer(referralAddress, (usdnCashbackAmount / 4), usdnAssetId), IntegerEntry("global_volume", (tryGetInteger("global_volume") + calculateUsdnValue(AssetIn, AmountIn, AssetInBalance)))] ++ usdnBalanceChange), cleanAmountOut)
578- else throw("Strict value is not equal to itself.")
579- }
580- else throw("Strict value is not equal to itself.")
581- }
582- else $Tuple2([IntegerEntry((("global_" + assetOut) + "_balance"), newBalanceOut), IntegerEntry((("global_" + getAssetString(AssetIn)) + "_balance"), newBalanceIn), ScriptTransfer(i.caller, cleanAmountOut, AssetOut), IntegerEntry("global_volume", (tryGetInteger("global_volume") + calculateUsdnValue(AssetIn, AmountIn, AssetInBalance)))], cleanAmountOut)
583- }
584- }
585-
10+@Verifier(tx)
11+func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey)
58612

github/deemru/w8io/873ac7e 
159.07 ms