tx · HnJ2tEckyXM14p72xHyUs35Tamy5xDzsDruqozRxjR6F

3N85YW6NZ9pLYvSdt1ASMQTGxvncnU1vUNx:  -0.01000000 Waves

2022.12.02 16:13 [2342772] smart account 3N85YW6NZ9pLYvSdt1ASMQTGxvncnU1vUNx > SELF 0.00000000 Waves

{ "type": 13, "id": "HnJ2tEckyXM14p72xHyUs35Tamy5xDzsDruqozRxjR6F", "fee": 1000000, "feeAssetId": null, "timestamp": 1669986843675, "version": 2, "chainId": 84, "sender": "3N85YW6NZ9pLYvSdt1ASMQTGxvncnU1vUNx", "senderPublicKey": "EKZmHJ5bK3qKKgRdq8rAamt9qrDbVMLARzRqXoQW258v", "proofs": [ "5SW82Nm6ma5G28EyYqj7nZkd31uNLVPCNhn8vLMqTa4uwQUJvUQZgkD4Q5kLHXtZ9dWnzeQK98d9FSt7sRvg9SQ1" ], "script": "base64:AAIFAAAAAAAAAAgIAhIECgIIAQAAAAcAAAAACXNlcGFyYXRvcgIAAAABXwEAAAAOam9pblBhaXJTdHJ1Y3QAAAAEAAAABnRva2VuMAAAAAZ0b2tlbjEAAAAIcmVzZXJ2ZTAAAAAIcmVzZXJ2ZTEJAAS5AAAAAgkABEwAAAACBQAAAAZ0b2tlbjAJAARMAAAAAgUAAAAGdG9rZW4xCQAETAAAAAIJAAGkAAAAAQUAAAAIcmVzZXJ2ZTAJAARMAAAAAgkAAaQAAAABBQAAAAhyZXNlcnZlMQUAAAADbmlsBQAAAAlzZXBhcmF0b3IBAAAADnNldFBhaXJEZXRhaWxzAAAABQAAAAlscFRva2VuSWQAAAAGdG9rZW4wAAAABnRva2VuMQAAAAhyZXNlcnZlMAAAAAhyZXNlcnZlMQkBAAAAC1N0cmluZ0VudHJ5AAAAAgUAAAAJbHBUb2tlbklkCQEAAAAOam9pblBhaXJTdHJ1Y3QAAAAEBQAAAAZ0b2tlbjAFAAAABnRva2VuMQUAAAAIcmVzZXJ2ZTAFAAAACHJlc2VydmUxAQAAAA1jYWxjQW1vdW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EAAAACWFtb3VudE91dAkBAAAADWNhbGNBbW91bnRPdXQAAAADBQAAAAhhbW91bnRJbgUAAAAMcGFpclJlc2VydmUwBQAAAAxwYWlyUmVzZXJ2ZTEDCQAAZgAAAAIFAAAADGFtb3VudE91dE1pbgUAAAAJYW1vdW50T3V0CQAAAgAAAAECAAAAGkluc3VmZmljaWVudCBvdXRwdXQgYW1vdW50CQAETAAAAAIJAQAAAA5TY3JpcHRUcmFuc2ZlcgAAAAMIBQAAAAFpAAAABmNhbGxlcgUAAAAJYW1vdW50T3V0CQACWQAAAAEFAAAACnBhaXJUb2tlbjEJAARMAAAAAgkBAAAADnNldFBhaXJEZXRhaWxzAAAABQUAAAAHbHBUb2tlbgUAAAAHdG9rZW5JbgUAAAAIdG9rZW5PdXQJAABkAAAAAgUAAAAMcGFpclJlc2VydmUwBQAAAAhhbW91bnRJbgkAAGUAAAACBQAAAAxwYWlyUmVzZXJ2ZTEFAAAACWFtb3VudE91dAUAAAADbmlsAAAAAOaRgMs=", "height": 2342772, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: B9n1bFVD8QLMneBb5X78y9U89T1ZGsV6UbgiKpnFJAoC Next: G8ThLkwZBdn2Msaejm82aH2rv7uGkT9F4SLFoUq8hsbf Full:
OldNewDifferences
11 {-# STDLIB_VERSION 5 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
4-let usdN = base58''
4+let separator = "_"
55
6-let staker = Address(base58'')
6+func joinPairStruct (token0,token1,reserve0,reserve1) = makeString([token0, token1, toString(reserve0), toString(reserve1)], separator)
77
8-let leasePool = Address(base58'')
98
10-let shareToken = base58''
9+func setPairDetails (lpTokenId,token0,token1,reserve0,reserve1) = StringEntry(lpTokenId, joinPairStruct(token0, token1, reserve0, reserve1))
1110
12-let loanFeePercent = 5
1311
14-let assetA = base58''
12+func calcAmountOut (amountIn,reserveIn,reserveOut) = {
13+ let amountInWithFee = (amountIn * 970)
14+ let numerator = (amountInWithFee * reserveOut)
15+ let denominator = ((reserveIn * 1000) + amountInWithFee)
16+ fraction(1, numerator, denominator, HALFEVEN)
17+ }
1518
16-let assetB = base58''
1719
18-let exchangerABAddress = Address(base58'')
20+func getPairKey (token0,token1) = {
21+ let token0BV = toInt(fromBase58String(token0))
22+ let token1BV = toInt(fromBase58String(token1))
23+ if ((token1BV > token0BV))
24+ then makeString([token0, token1], separator)
25+ else makeString([token1, token0], separator)
26+ }
1927
20-let exchangerBAAddress = Address(base58'')
2128
22-let loanerAddress = Address(base58'')
29+func getPairTokenId (token0,token1) = valueOrErrorMessage(getString(this, getPairKey(token0, token1)), "Pair doesn`t exist")
2330
24-let aToBRate = 5
2531
26-let exchangeRate = 5
27-
28-let exchangeRateDiffPercent = 20
29-
30-@Callable(i)
31-func addLiquidity () = if (if ((i.payments[0].assetId != unit))
32- then true
33- else (i.payments[1].assetId != usdN))
34- then throw("unexpected assets")
35- else {
36- let r = invoke(staker, "stake", nil, [i.payments[1]])
37- if ((r == r))
38- then {
39- let stakingAmount = match r {
40- case a: Int =>
41- a
42- case _ =>
43- throw("unexpected result type from the staker")
44- }
45- let stakingAmountKey = ("STAKING_AMOUNT_" + toString(i.caller))
46- let leaseAmountKey = ("LEASE_AMOUNT_" + toString(i.caller))
47- let idKey = ("ID_" + toString(i.caller))
48- let leasedAmount = valueOrElse(getInteger(this, leaseAmountKey), 0)
49- let leaseId = getString(this, idKey)
50- let newLease = Lease(leasePool, (leasedAmount + i.payments[0].amount))
51- let newLeaseId = calculateLeaseId(newLease)
52- let cancel = match leaseId {
53- case id: String =>
54-[LeaseCancel(fromBase58String(id))]
55- case _ =>
56-[StringEntry(idKey, toBase58String(newLeaseId))]
57- }
58- (cancel ++ [newLease, ScriptTransfer(i.caller, 1, shareToken), IntegerEntry(leaseAmountKey, (leasedAmount + i.payments[0].amount)), IntegerEntry(stakingAmountKey, stakingAmount)])
59- }
60- else throw("Strict value is not equal to itself.")
61- }
62-
32+func getPairDetails (lpTokenId) = {
33+ let details = split(valueOrElse(getString(this, lpTokenId), "assetId0_assetId1_0_0"), separator)
34+ $Tuple4(details[0], details[1], parseIntValue(details[2]), parseIntValue(details[3]))
35+ }
6336
6437
6538 @Callable(i)
66-func trade (beneficiary) = {
67- let loanAmount = if ((i.payments[0].assetId == assetA))
68- then i.payments[0].amount
69- else throw("unexpected payment asset")
70- let startBalanceB = assetBalance(this, assetB)
71- if ((startBalanceB == startBalanceB))
72- then {
73- let r1 = invoke(exchangerABAddress, "exchangeAB", nil, [AttachedPayment(assetA, loanAmount)])
74- if ((r1 == r1))
75- then {
76- let diffB = (assetBalance(this, assetB) - startBalanceB)
77- if ((diffB == diffB))
78- then {
79- let r2 = invoke(exchangerBAAddress, "exchangeBA", nil, [AttachedPayment(assetB, diffB)])
80- if ((r2 == r2))
81- then {
82- let debt = fraction(loanAmount, (100 + loanFeePercent), 100)
83- let profit = (assetBalance(this, assetA) - debt)
84-[ScriptTransfer(Address(beneficiary), profit, assetA), ScriptTransfer(loanerAddress, debt, assetA)]
85- }
86- else throw("Strict value is not equal to itself.")
87- }
88- else throw("Strict value is not equal to itself.")
89- }
90- else throw("Strict value is not equal to itself.")
91- }
92- else throw("Strict value is not equal to itself.")
39+func swap (tokenOut,amountOutMin) = {
40+ let $t014441548 = $Tuple2(toBase58String(value(i.payments[0].assetId)), value(i.payments[0].amount))
41+ let tokenIn = $t014441548._1
42+ let amountIn = $t014441548._2
43+ let lpToken = getPairTokenId(tokenIn, tokenOut)
44+ let $t016011683 = getPairDetails(lpToken)
45+ let pairToken0 = $t016011683._1
46+ let pairToken1 = $t016011683._2
47+ let pairReserve0 = $t016011683._3
48+ let pairReserve1 = $t016011683._4
49+ let amountOut = calcAmountOut(amountIn, pairReserve0, pairReserve1)
50+ if ((amountOutMin > amountOut))
51+ then throw("Insufficient output amount")
52+ else [ScriptTransfer(i.caller, amountOut, fromBase58String(pairToken1)), setPairDetails(lpToken, tokenIn, tokenOut, (pairReserve0 + amountIn), (pairReserve1 - amountOut))]
9353 }
94-
95-
96-
97-@Callable(i)
98-func exchangeAB () = if ((i.payments[0].assetId == assetA))
99- then [ScriptTransfer(i.caller, (i.payments[0].amount * aToBRate), assetB)]
100- else throw("unexpected token")
101-
102-
103-
104-@Callable(i)
105-func exchangeBA () = if ((i.payments[0].assetId == assetB))
106- then [ScriptTransfer(i.caller, (i.payments[0].amount / aToBRate), assetA)]
107- else throw("unexpected token")
108-
109-
110-
111-@Callable(i)
112-func exchangeWavesUsdN () = if ((i.payments[0].assetId != unit))
113- then throw("unexpected asset")
114- else {
115- let r = invoke(staker, "cancelStake", [(i.payments[0].amount * exchangeRate)], nil)
116- if ((r == r))
117- then [ScriptTransfer(i.caller, (i.payments[0].amount * exchangeRate), usdN)]
118- else throw("Strict value is not equal to itself.")
119- }
120-
121-
122-
123-@Callable(i)
124-func stake () = if ((i.payments[0].assetId != usdN))
125- then throw("unexpected asset")
126- else {
127- let currentLiquidity = valueOrElse(getInteger(this, toString(i.originCaller)), 0)
128-[IntegerEntry(toString(i.originCaller), (currentLiquidity + i.payments[0].amount))]
129- }
130-
131-
132-
133-@Callable(i)
134-func cancelStake (amount) = if ((getIntegerValue(this, toString(i.caller)) >= amount))
135- then [ScriptTransfer(i.caller, amount, usdN)]
136- else throw("too big amount")
13754
13855

github/deemru/w8io/169f3d6 
42.04 ms