tx · 47dKp2G1rfvCbfPJBhXqCabjJy3e7ee4bbzhCEUSTdmF

3N6LHjfGb6Fgcy7YsVcNxGyPTj49XbQAijq:  -0.01300000 Waves

2023.02.08 11:04 [2440377] smart account 3N6LHjfGb6Fgcy7YsVcNxGyPTj49XbQAijq > SELF 0.00000000 Waves

{ "type": 13, "id": "47dKp2G1rfvCbfPJBhXqCabjJy3e7ee4bbzhCEUSTdmF", "fee": 1300000, "feeAssetId": null, "timestamp": 1675843434176, "version": 1, "sender": "3N6LHjfGb6Fgcy7YsVcNxGyPTj49XbQAijq", "senderPublicKey": "2u2wYYcVBQv43Cc71zkhHPPitkqgg6dqTZ3nUMvYJ1uq", "proofs": [ "5wtrQnyZ1YrqtiARjk1mDZ65Xztv72B3a5cDqenMfKzTRCTdddd2VvVY1CfRGArkZUc4pPfxS9DtPG2xT5MA86AU" ], "script": "base64:BgIXCAISBQoDAQgIEgUKAwEICBIDCgEIEgAUAANTRVACAl9fAAhmZWVTY2FsZQkAtgIBAKCNBgEPZ2V0U3RyaW5nT3JGYWlsAQNrZXkJARN2YWx1ZU9yRXJyb3JNZXNzYWdlAgkAnQgCBQR0aGlzBQNrZXkJAKwCAgIVTm8gZGF0YSBmb3IgdGhpcy5rZXk9BQNrZXkADHBvb2xEaXNhYmxlZAkAAgECDVBvb2wgZGlzYWJsZWQADHBvb2xOb3RFeGlzdAkAAgECEVBvb2wgaXMgbm90IGV4aXN0AA5zbGlwcGFnZVRvb0JpZwkAAgECE1NsaXBwYWdlIGlzIHRvbyBiaWcBE2tleU1hbmFnZXJQdWJsaWNLZXkAAhQlc19fbWFuYWdlclB1YmxpY0tleQEaa2V5UGVuZGluZ01hbmFnZXJQdWJsaWNLZXkAAhslc19fcGVuZGluZ01hbmFnZXJQdWJsaWNLZXkBAmZjAAITJXNfX2ZhY3RvcnlDb250cmFjdAAPZmFjdG9yeUNvbnRyYWN0CQERQGV4dHJOYXRpdmUoMTA2MikBCQEPZ2V0U3RyaW5nT3JGYWls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AJwbQkBHXBlbmRpbmdNYW5hZ2VyUHVibGljS2V5T3JVbml0AAQFaGFzUE0DCQEJaXNEZWZpbmVkAQUCcG0GCQACAQISbm8gcGVuZGluZyBtYW5hZ2VyAwkAAAIFBWhhc1BNBQVoYXNQTQQHY2hlY2tQTQMJAAACCAUBaQ9jYWxsZXJQdWJsaWNLZXkJAQV2YWx1ZQEFAnBtBgkAAgECG3lvdSBhcmUgbm90IHBlbmRpbmcgbWFuYWdlcgMJAAACBQdjaGVja1BNBQdjaGVja1BNCQDMCAIJAQtTdHJpbmdFbnRyeQIJARNrZXlNYW5hZ2VyUHVibGljS2V5AAkA2AQBCQEFdmFsdWUBBQJwbQkAzAgCCQELRGVsZXRlRW50cnkBCQEaa2V5UGVuZGluZ01hbmFnZXJQdWJsaWNLZXkABQNuaWwJAAIBAiRTdHJpY3QgdmFsdWUgaXMgbm90IGVxdWFsIHRvIGl0c2VsZi4JAAIBAiRTdHJpY3QgdmFsdWUgaXMgbm90IGVxdWFsIHRvIGl0c2VsZi4BAnR4AQZ2ZXJpZnkABA90YXJnZXRQdWJsaWNLZXkEByRtYXRjaDAJARZtYW5hZ2VyUHVibGljS2V5T3JVbml0AAMJAAECBQckbWF0Y2gwAgpCeXRlVmVjdG9yBAJwawUHJG1hdGNoMAUCcGsDCQABAgUHJG1hdGNoMAIEVW5pdAgFAnR4D3NlbmRlclB1YmxpY0tleQkAAgECC01hdGNoIGVycm9yCQD0AwMIBQJ0eAlib2R5Qnl0ZXMJAJEDAggFAnR4BnByb29mcwAABQ90YXJnZXRQdWJsaWNLZXkU+zT3", "chainId": 84, "height": 2440377, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 33MSPGrFxtMnbcVYSL7zRpjJWGNhAsy8VmSsK22dinba Next: 4t1pmk28DsRaH8KiUAm274kzrrNJSHucKZ3u7KPK3dWF Diff:
OldNewDifferences
2525
2626 let factoryContract = addressFromStringValue(getStringOrFail(fc()))
2727
28-func feeLiquidityContractAddress () = makeString(["%s", "feeLiquidityContractAddress"], SEP)
28+func feeProtocolContractAddress () = makeString(["%s", "feeProtocolContractAddress"], SEP)
2929
3030
31-func feeLiquidity () = makeString(["%s", "feeLiquidity"], SEP)
31+let feeContract = addressFromStringValue(getStringOrFail(feeProtocolContractAddress()))
3232
33-
34-func protocolFee () = makeString(["%d", "protocolFee"], SEP)
33+func protocolFee () = makeString(["%s", "protocolFee"], SEP)
3534
3635
3736 func asInt (val) = match val {
8988 func swapCalculateREADONLY (amountIn,assetIn,assetOut) = {
9089 let prFee = value(getInteger(protocolFee()))
9190 let feeProtocolAmount = fraction(toBigInt(amountIn), toBigInt(prFee), feeScale)
92- let feeLiquidityAmount = fraction(toBigInt(amountIn), toBigInt(prFee), feeScale)
93- let amountInToPool = (toBigInt(amountIn) - feeProtocolAmount)
94- let cleanAmountIn = (amountInToPool - feeLiquidityAmount)
91+ let cleanAmountIn = if ((toInt(feeProtocolAmount) == 0))
92+ then toBigInt(1)
93+ else (toBigInt(amountIn) - feeProtocolAmount)
9594 let lpNonReverese = invoke(factoryContract, "getLpAssetFromPoolAssetsREADONLY", [assetIn, assetOut], nil)
9695 let lpReverse = invoke(factoryContract, "getLpAssetFromPoolAssetsREADONLY", [assetOut, assetIn], nil)
97- let $t027103329 = if ((lpNonReverese != unit))
96+ let $t025613066 = if ((lpNonReverese != unit))
9897 then {
9998 let isReverse = false
10099 let pool = {
117116 $Tuple2(isReverse, pool)
118117 }
119118 else poolNotExist
120- let isReverse = $t027103329._1
121- let pool = $t027103329._2
119+ let isReverse = $t025613066._1
120+ let pool = $t025613066._2
122121 let poolStatus = {
123122 let @ = invoke(factoryContract, "getPoolStatusREADONLY", [pool], nil)
124123 if ($isInstanceOf(@, "Int"))
153152 let amountIn = value(pmt.amount)
154153 let prFee = value(getInteger(protocolFee()))
155154 let feeProtocolAmount = fraction(toBigInt(amountIn), toBigInt(prFee), feeScale)
156- let feeLiquidityAmount = fraction(toBigInt(amountIn), toBigInt(prFee), feeScale)
157- let amountInToPool = (toBigInt(amountIn) - feeProtocolAmount)
158- let cleanAmountIn = (amountInToPool - feeLiquidityAmount)
155+ let cleanAmountIn = (toBigInt(amountIn) - feeProtocolAmount)
159156 let checks = [if ((size(i.payments) == 1))
160157 then true
161158 else throw("exactly 1 payment are expected")]
163160 then {
164161 let lpNonReverese = invoke(factoryContract, "getLpAssetFromPoolAssetsREADONLY", [assetIn, assetOut], nil)
165162 let lpReverse = invoke(factoryContract, "getLpAssetFromPoolAssetsREADONLY", [assetOut, assetIn], nil)
166- let $t047995289 = if ((lpNonReverese != unit))
163+ let $t042474737 = if ((lpNonReverese != unit))
167164 then {
168165 let isReverse = false
169166 let pool = {
181178 $Tuple2(isReverse, pool)
182179 }
183180 else poolNotExist
184- let isReverse = $t047995289._1
185- let pool = $t047995289._2
181+ let isReverse = $t042474737._1
182+ let pool = $t042474737._2
186183 let isPoolOneTokenOperationsDisabled = {
187184 let @ = invoke(factoryContract, "isPoolOneTokenOperationsDisabledREADONLY", [pool], nil)
188185 if ($isInstanceOf(@, "Boolean"))
196193 then {
197194 let poolAdr = addressFromStringValue(valueOrElse(pool, ""))
198195 let res = {
199- let @ = invoke(poolAdr, "calculateAmountOutForSwapAndSendTokens", [toInt(cleanAmountIn), isReverse, amountOutMin, addressTo], [AttachedPayment(assetIn, toInt(amountInToPool))])
196+ let @ = invoke(poolAdr, "calculateAmountOutForSwapAndSendTokens", [toInt(cleanAmountIn), isReverse, amountOutMin, addressTo], [AttachedPayment(assetIn, toInt(cleanAmountIn))])
200197 if ($isInstanceOf(@, "Boolean"))
201198 then @
202199 else throw(($getType(@) + " couldn't be cast to Boolean"))
203200 }
204- $Tuple2(nil, res)
201+ $Tuple2([ScriptTransfer(feeContract, toInt(feeProtocolAmount), assetIn)], res)
205202 }
206203 else throw("Strict value is not equal to itself.")
207204 }
Full:
OldNewDifferences
11 {-# STDLIB_VERSION 6 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
44 let SEP = "__"
55
66 let feeScale = toBigInt(100000)
77
88 func getStringOrFail (key) = valueOrErrorMessage(getString(this, key), ("No data for this.key=" + key))
99
1010
1111 let poolDisabled = throw("Pool disabled")
1212
1313 let poolNotExist = throw("Pool is not exist")
1414
1515 let slippageTooBig = throw("Slippage is too big")
1616
1717 func keyManagerPublicKey () = "%s__managerPublicKey"
1818
1919
2020 func keyPendingManagerPublicKey () = "%s__pendingManagerPublicKey"
2121
2222
2323 func fc () = "%s__factoryContract"
2424
2525
2626 let factoryContract = addressFromStringValue(getStringOrFail(fc()))
2727
28-func feeLiquidityContractAddress () = makeString(["%s", "feeLiquidityContractAddress"], SEP)
28+func feeProtocolContractAddress () = makeString(["%s", "feeProtocolContractAddress"], SEP)
2929
3030
31-func feeLiquidity () = makeString(["%s", "feeLiquidity"], SEP)
31+let feeContract = addressFromStringValue(getStringOrFail(feeProtocolContractAddress()))
3232
33-
34-func protocolFee () = makeString(["%d", "protocolFee"], SEP)
33+func protocolFee () = makeString(["%s", "protocolFee"], SEP)
3534
3635
3736 func asInt (val) = match val {
3837 case valInt: Int =>
3938 valInt
4039 case _ =>
4140 throw("fail to cast into Int")
4241 }
4342
4443
4544 func dataMappingPoolAssets (internalAmountAssetStr,internalPriceAssetStr) = makeString(["%d%d", toString(internalAmountAssetStr), toString(internalPriceAssetStr)], SEP)
4645
4746
4847 func managerPublicKeyOrUnit () = match getString(keyManagerPublicKey()) {
4948 case s: String =>
5049 fromBase58String(s)
5150 case _: Unit =>
5251 unit
5352 case _ =>
5453 throw("Match error")
5554 }
5655
5756
5857 func pendingManagerPublicKeyOrUnit () = match getString(keyPendingManagerPublicKey()) {
5958 case s: String =>
6059 fromBase58String(s)
6160 case _: Unit =>
6261 unit
6362 case _ =>
6463 throw("Match error")
6564 }
6665
6766
6867 func isManager (i) = match managerPublicKeyOrUnit() {
6968 case pk: ByteVector =>
7069 (i.callerPublicKey == pk)
7170 case _: Unit =>
7271 (i.caller == this)
7372 case _ =>
7473 throw("Match error")
7574 }
7675
7776
7877 func mustManager (i) = if (isManager(i))
7978 then true
8079 else throw("permission denied")
8180
8281
8382 func getAccBalance (assetId) = if ((assetId == "WAVES"))
8483 then wavesBalance(this).available
8584 else assetBalance(this, fromBase58String(assetId))
8685
8786
8887 @Callable(i)
8988 func swapCalculateREADONLY (amountIn,assetIn,assetOut) = {
9089 let prFee = value(getInteger(protocolFee()))
9190 let feeProtocolAmount = fraction(toBigInt(amountIn), toBigInt(prFee), feeScale)
92- let feeLiquidityAmount = fraction(toBigInt(amountIn), toBigInt(prFee), feeScale)
93- let amountInToPool = (toBigInt(amountIn) - feeProtocolAmount)
94- let cleanAmountIn = (amountInToPool - feeLiquidityAmount)
91+ let cleanAmountIn = if ((toInt(feeProtocolAmount) == 0))
92+ then toBigInt(1)
93+ else (toBigInt(amountIn) - feeProtocolAmount)
9594 let lpNonReverese = invoke(factoryContract, "getLpAssetFromPoolAssetsREADONLY", [assetIn, assetOut], nil)
9695 let lpReverse = invoke(factoryContract, "getLpAssetFromPoolAssetsREADONLY", [assetOut, assetIn], nil)
97- let $t027103329 = if ((lpNonReverese != unit))
96+ let $t025613066 = if ((lpNonReverese != unit))
9897 then {
9998 let isReverse = false
10099 let pool = {
101100 let @ = invoke(factoryContract, "getPoolAddressFromLpAssetREADONLY", [lpNonReverese], nil)
102101 if ($isInstanceOf(@, "String"))
103102 then @
104103 else throw(($getType(@) + " couldn't be cast to String"))
105104 }
106105 $Tuple2(isReverse, pool)
107106 }
108107 else if ((lpReverse != unit))
109108 then {
110109 let isReverse = true
111110 let pool = {
112111 let @ = invoke(factoryContract, "getPoolAddressFromLpAssetREADONLY", [lpReverse], nil)
113112 if ($isInstanceOf(@, "String"))
114113 then @
115114 else throw(($getType(@) + " couldn't be cast to String"))
116115 }
117116 $Tuple2(isReverse, pool)
118117 }
119118 else poolNotExist
120- let isReverse = $t027103329._1
121- let pool = $t027103329._2
119+ let isReverse = $t025613066._1
120+ let pool = $t025613066._2
122121 let poolStatus = {
123122 let @ = invoke(factoryContract, "getPoolStatusREADONLY", [pool], nil)
124123 if ($isInstanceOf(@, "Int"))
125124 then @
126125 else throw(($getType(@) + " couldn't be cast to Int"))
127126 }
128127 let check = if ((poolStatus == 1))
129128 then true
130129 else poolDisabled
131130 if ((check == check))
132131 then {
133132 let poolAdr = addressFromStringValue(valueOrElse(pool, ""))
134133 let res = {
135134 let @ = invoke(poolAdr, "calculateAmountOutForSwapREADONLY", [toInt(cleanAmountIn), isReverse], nil)
136135 if ($isInstanceOf(@, "Int"))
137136 then @
138137 else throw(($getType(@) + " couldn't be cast to Int"))
139138 }
140139 $Tuple2(nil, res)
141140 }
142141 else throw("Strict value is not equal to itself.")
143142 }
144143
145144
146145
147146 @Callable(i)
148147 func swap (amountOutMin,assetOut,addressTo) = {
149148 let pmt = value(i.payments[0])
150149 let assetIn = if ((pmt.assetId == unit))
151150 then toBytes("WAVES")
152151 else value(pmt.assetId)
153152 let amountIn = value(pmt.amount)
154153 let prFee = value(getInteger(protocolFee()))
155154 let feeProtocolAmount = fraction(toBigInt(amountIn), toBigInt(prFee), feeScale)
156- let feeLiquidityAmount = fraction(toBigInt(amountIn), toBigInt(prFee), feeScale)
157- let amountInToPool = (toBigInt(amountIn) - feeProtocolAmount)
158- let cleanAmountIn = (amountInToPool - feeLiquidityAmount)
155+ let cleanAmountIn = (toBigInt(amountIn) - feeProtocolAmount)
159156 let checks = [if ((size(i.payments) == 1))
160157 then true
161158 else throw("exactly 1 payment are expected")]
162159 if ((checks == checks))
163160 then {
164161 let lpNonReverese = invoke(factoryContract, "getLpAssetFromPoolAssetsREADONLY", [assetIn, assetOut], nil)
165162 let lpReverse = invoke(factoryContract, "getLpAssetFromPoolAssetsREADONLY", [assetOut, assetIn], nil)
166- let $t047995289 = if ((lpNonReverese != unit))
163+ let $t042474737 = if ((lpNonReverese != unit))
167164 then {
168165 let isReverse = false
169166 let pool = {
170167 let @ = invoke(factoryContract, "getPoolAddressFromLpAssetREADONLY", [lpNonReverese], nil)
171168 if ($isInstanceOf(@, "Address"))
172169 then @
173170 else throw(($getType(@) + " couldn't be cast to Address"))
174171 }
175172 $Tuple2(isReverse, pool)
176173 }
177174 else if ((lpReverse != unit))
178175 then {
179176 let isReverse = true
180177 let pool = invoke(factoryContract, "getPoolAddressFromLpAssetREADONLY", [lpReverse], nil)
181178 $Tuple2(isReverse, pool)
182179 }
183180 else poolNotExist
184- let isReverse = $t047995289._1
185- let pool = $t047995289._2
181+ let isReverse = $t042474737._1
182+ let pool = $t042474737._2
186183 let isPoolOneTokenOperationsDisabled = {
187184 let @ = invoke(factoryContract, "isPoolOneTokenOperationsDisabledREADONLY", [pool], nil)
188185 if ($isInstanceOf(@, "Boolean"))
189186 then @
190187 else throw(($getType(@) + " couldn't be cast to Boolean"))
191188 }
192189 let check = if (isPoolOneTokenOperationsDisabled)
193190 then true
194191 else poolDisabled
195192 if ((check == check))
196193 then {
197194 let poolAdr = addressFromStringValue(valueOrElse(pool, ""))
198195 let res = {
199- let @ = invoke(poolAdr, "calculateAmountOutForSwapAndSendTokens", [toInt(cleanAmountIn), isReverse, amountOutMin, addressTo], [AttachedPayment(assetIn, toInt(amountInToPool))])
196+ let @ = invoke(poolAdr, "calculateAmountOutForSwapAndSendTokens", [toInt(cleanAmountIn), isReverse, amountOutMin, addressTo], [AttachedPayment(assetIn, toInt(cleanAmountIn))])
200197 if ($isInstanceOf(@, "Boolean"))
201198 then @
202199 else throw(($getType(@) + " couldn't be cast to Boolean"))
203200 }
204- $Tuple2(nil, res)
201+ $Tuple2([ScriptTransfer(feeContract, toInt(feeProtocolAmount), assetIn)], res)
205202 }
206203 else throw("Strict value is not equal to itself.")
207204 }
208205 else throw("Strict value is not equal to itself.")
209206 }
210207
211208
212209
213210 @Callable(i)
214211 func setManager (pendingManagerPublicKey) = {
215212 let checkCaller = mustManager(i)
216213 if ((checkCaller == checkCaller))
217214 then {
218215 let checkManagerPublicKey = fromBase58String(pendingManagerPublicKey)
219216 if ((checkManagerPublicKey == checkManagerPublicKey))
220217 then [StringEntry(keyPendingManagerPublicKey(), pendingManagerPublicKey)]
221218 else throw("Strict value is not equal to itself.")
222219 }
223220 else throw("Strict value is not equal to itself.")
224221 }
225222
226223
227224
228225 @Callable(i)
229226 func confirmManager () = {
230227 let pm = pendingManagerPublicKeyOrUnit()
231228 let hasPM = if (isDefined(pm))
232229 then true
233230 else throw("no pending manager")
234231 if ((hasPM == hasPM))
235232 then {
236233 let checkPM = if ((i.callerPublicKey == value(pm)))
237234 then true
238235 else throw("you are not pending manager")
239236 if ((checkPM == checkPM))
240237 then [StringEntry(keyManagerPublicKey(), toBase58String(value(pm))), DeleteEntry(keyPendingManagerPublicKey())]
241238 else throw("Strict value is not equal to itself.")
242239 }
243240 else throw("Strict value is not equal to itself.")
244241 }
245242
246243
247244 @Verifier(tx)
248245 func verify () = {
249246 let targetPublicKey = match managerPublicKeyOrUnit() {
250247 case pk: ByteVector =>
251248 pk
252249 case _: Unit =>
253250 tx.senderPublicKey
254251 case _ =>
255252 throw("Match error")
256253 }
257254 sigVerify(tx.bodyBytes, tx.proofs[0], targetPublicKey)
258255 }
259256

github/deemru/w8io/026f985 
95.88 ms