tx · 3XNuPqrLxCykM5YCU9L5mZmYiGrmPeEwC9g3UQwpDNG9

3N6LHjfGb6Fgcy7YsVcNxGyPTj49XbQAijq:  -0.01300000 Waves

2023.01.26 14:16 [2421866] smart account 3N6LHjfGb6Fgcy7YsVcNxGyPTj49XbQAijq > SELF 0.00000000 Waves

{ "type": 13, "id": "3XNuPqrLxCykM5YCU9L5mZmYiGrmPeEwC9g3UQwpDNG9", "fee": 1300000, "feeAssetId": null, "timestamp": 1674731782857, "version": 1, "sender": "3N6LHjfGb6Fgcy7YsVcNxGyPTj49XbQAijq", "senderPublicKey": "2u2wYYcVBQv43Cc71zkhHPPitkqgg6dqTZ3nUMvYJ1uq", "proofs": [ "AaUKfJfJ29FFiRGXHMWLBTTTM5hjijKp65RFD5fyzjNe789SSBnsuYSGHHhMjZLKnsqohXMzdC3yEWjYXc1UNzM" ], "script": "base64:BgIXCAISBQoDAQgIEgUKAwEICBIDCgEIEgAUAANTRVACAl9fAAhmZWVTY2FsZQkAtgIBAKCNBgEPZ2V0U3RyaW5nT3JGYWlsAQNrZXkJARN2YWx1ZU9yRXJyb3JNZXNzYWdlAgkAnQgCBQR0aGlzBQNrZXkJAKwCAgIVTm8gZGF0YSBmb3IgdGhpcy5rZXk9BQNrZXkADHBvb2xEaXNhYmxlZAkAAgECDVBvb2wgZGlzYWJsZWQADHBvb2xOb3RFeGlzdAkAAgECEVBvb2wgaXMgbm90IGV4aXN0AA5zbGlwcGFnZVRvb0JpZwkAAgECE1NsaXBwYWdlIGlzIHRvbyBiaWcBE2tleU1hbmFnZXJQdWJsaWNLZXkAAhQlc19fbWFuYWdlclB1YmxpY0tleQEaa2V5UGVuZGluZ01hbmFnZXJQdWJsaWNLZXkAAhslc19fcGVuZGluZ01hbmFnZXJQdWJsaWNLZXkBAmZjAAITJXNfX2ZhY3RvcnlDb250cmFjdAAPZmFjdG9yeUNvbnRyYWN0CQERQGV4dHJOYXRpdmUoMTA2MikBCQEPZ2V0U3RyaW5nT3JGYWl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prev: ZbukTgBHH3KsgfZPGV2kZBR3SKvD2zW5wgMHEbddpog Next: 4LDgK1DQT1SAcPwQ1cis7UAysoZz2dFoN5vPHTU98Nek Diff:
OldNewDifferences
2828 func feeLiquidityContractAddress () = makeString(["%s", "feeLiquidityContractAddress"], SEP)
2929
3030
31-func feeLiquidity () = makeString(["%d", "feeLiquidity"], SEP)
31+func feeLiquidity () = makeString(["%s", "feeLiquidity"], SEP)
3232
3333
34-func protocolFee () = makeString(["%d", "protocolFee"], SEP)
34+func protocolFee () = makeString(["%s", "protocolFee"], SEP)
3535
3636
3737 func asInt (val) = match val {
8080 else throw("permission denied")
8181
8282
83+func getAccBalance (assetId) = if ((assetId == "WAVES"))
84+ then wavesBalance(this).available
85+ else assetBalance(this, fromBase58String(assetId))
86+
87+
8388 @Callable(i)
84-func constructor (protocolFeeAmount,feeLiquidityAmount,feeLiquidityAddress,fc) = {
85- let check = mustManager(i)
89+func swapCalulateREADONLY (amountIn,assetIn,assetOut) = {
90+ let prFee = value(getInteger(protocolFee()))
91+ 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)
95+ let lpNonReverese = invoke(factoryContract, "getLpAssetFromPoolAssetsREADONLY", [assetIn, assetOut], nil)
96+ let lpReverse = invoke(factoryContract, "getLpAssetFromPoolAssetsREADONLY", [assetOut, assetIn], nil)
97+ let $t026383128 = if ((lpNonReverese != unit))
98+ then {
99+ let isReverse = false
100+ let pool = {
101+ let @ = invoke(factoryContract, "getPoolAddressFromLpAssetREADONLY", [lpNonReverese], nil)
102+ if ($isInstanceOf(@, "Address"))
103+ then @
104+ else throw(($getType(@) + " couldn't be cast to Address"))
105+ }
106+ $Tuple2(isReverse, pool)
107+ }
108+ else if ((lpReverse != unit))
109+ then {
110+ let isReverse = true
111+ let pool = invoke(factoryContract, "getPoolAddressFromLpAssetREADONLY", [lpReverse], nil)
112+ $Tuple2(isReverse, pool)
113+ }
114+ else poolNotExist
115+ let isReverse = $t026383128._1
116+ let pool = $t026383128._2
117+ let isPoolOneTokenOperationsDisabled = {
118+ let @ = invoke(factoryContract, "isPoolOneTokenOperationsDisabledREADONLY", [pool], nil)
119+ if ($isInstanceOf(@, "Boolean"))
120+ then @
121+ else throw(($getType(@) + " couldn't be cast to Boolean"))
122+ }
123+ let check = if (isPoolOneTokenOperationsDisabled)
124+ then true
125+ else poolDisabled
86126 if ((check == check))
87- then [StringEntry(feeLiquidityContractAddress(), feeLiquidityAddress), IntegerEntry(feeLiquidity(), feeLiquidityAmount), IntegerEntry(protocolFee(), protocolFeeAmount), StringEntry(fc(), fc)]
127+ then {
128+ let poolAdr = addressFromStringValue(valueOrElse(pool, ""))
129+ let res = {
130+ let @ = invoke(poolAdr, "calculateAmountOutForSwapREADONLY", [cleanAmountIn, isReverse], nil)
131+ if ($isInstanceOf(@, "Int"))
132+ then @
133+ else throw(($getType(@) + " couldn't be cast to Int"))
134+ }
135+ $Tuple2(nil, res)
136+ }
88137 else throw("Strict value is not equal to itself.")
89138 }
90139
93142 @Callable(i)
94143 func swap (amountOutMin,assetOut,addressTo) = {
95144 let pmt = value(i.payments[0])
96- let assetIn = value(pmt.assetId)
145+ let assetIn = if ((pmt.assetId == unit))
146+ then toBytes("WAVES")
147+ else value(pmt.assetId)
97148 let amountIn = value(pmt.amount)
98149 let prFee = value(getInteger(protocolFee()))
99150 let feeProtocolAmount = fraction(toBigInt(amountIn), toBigInt(prFee), feeScale)
107158 then {
108159 let lpNonReverese = invoke(factoryContract, "getLpAssetFromPoolAssetsREADONLY", [assetIn, assetOut], nil)
109160 let lpReverse = invoke(factoryContract, "getLpAssetFromPoolAssetsREADONLY", [assetOut, assetIn], nil)
110- let $t030893610 = if ((lpNonReverese != unit))
161+ let $t045485038 = if ((lpNonReverese != unit))
111162 then {
112163 let isReverse = false
113- let pool = invoke(factoryContract, "getPoolAddressFromLpAssetREADONLY", [lpNonReverese], nil)
164+ let pool = {
165+ let @ = invoke(factoryContract, "getPoolAddressFromLpAssetREADONLY", [lpNonReverese], nil)
166+ if ($isInstanceOf(@, "Address"))
167+ then @
168+ else throw(($getType(@) + " couldn't be cast to Address"))
169+ }
114170 $Tuple2(isReverse, pool)
115171 }
116172 else if ((lpReverse != unit))
119175 let pool = invoke(factoryContract, "getPoolAddressFromLpAssetREADONLY", [lpReverse], nil)
120176 $Tuple2(isReverse, pool)
121177 }
122- else {
123- let isReverse = true
124- let pool = ""
125- $Tuple2(isReverse, pool)
126- }
127- let isReverse = $t030893610._1
128- let pool = $t030893610._2
129- let checkExist = [if ((pool != ""))
178+ else poolNotExist
179+ let isReverse = $t045485038._1
180+ let pool = $t045485038._2
181+ let isPoolOneTokenOperationsDisabled = {
182+ let @ = invoke(factoryContract, "isPoolOneTokenOperationsDisabledREADONLY", [pool], nil)
183+ if ($isInstanceOf(@, "Boolean"))
184+ then @
185+ else throw(($getType(@) + " couldn't be cast to Boolean"))
186+ }
187+ let check = if (isPoolOneTokenOperationsDisabled)
130188 then true
131- else poolNotExist]
132- if ((checkExist == checkExist))
189+ else poolDisabled
190+ if ((check == check))
133191 then {
134- let isPoolOneTokenOperationsDisabled = {
135- let @ = invoke(factoryContract, "isPoolOneTokenOperationsDisabledREADONLY", [pool], nil)
192+ let poolAdr = addressFromStringValue(valueOrElse(pool, ""))
193+ let res = {
194+ let @ = invoke(poolAdr, "calculateAmountOutForSwapAndSendTokens", [cleanAmountIn, isReverse, amountOutMin, addressTo], [AttachedPayment(assetIn, toInt(amountInToPool))])
136195 if ($isInstanceOf(@, "Boolean"))
137196 then @
138197 else throw(($getType(@) + " couldn't be cast to Boolean"))
139198 }
140- let check = [if (isPoolOneTokenOperationsDisabled)
141- then true
142- else poolDisabled]
143- if ((check == check))
144- then {
145- let poolAdr = addressFromStringValue(valueOrElse(pool, ""))
146- let res = invoke(poolAdr, "calculateAmountOutForSwapAndSendTokens", [cleanAmountIn, isReverse, amountOutMin, addressTo], [AttachedPayment(assetIn, toInt(amountInToPool))])
147- $Tuple2(nil, true)
148- }
149- else throw("Strict value is not equal to itself.")
199+ $Tuple2(nil, res)
150200 }
151201 else throw("Strict value is not equal to itself.")
152202 }
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
2828 func feeLiquidityContractAddress () = makeString(["%s", "feeLiquidityContractAddress"], SEP)
2929
3030
31-func feeLiquidity () = makeString(["%d", "feeLiquidity"], SEP)
31+func feeLiquidity () = makeString(["%s", "feeLiquidity"], SEP)
3232
3333
34-func protocolFee () = makeString(["%d", "protocolFee"], SEP)
34+func protocolFee () = makeString(["%s", "protocolFee"], SEP)
3535
3636
3737 func asInt (val) = match val {
3838 case valInt: Int =>
3939 valInt
4040 case _ =>
4141 throw("fail to cast into Int")
4242 }
4343
4444
4545 func dataMappingPoolAssets (internalAmountAssetStr,internalPriceAssetStr) = makeString(["%d%d", toString(internalAmountAssetStr), toString(internalPriceAssetStr)], SEP)
4646
4747
4848 func managerPublicKeyOrUnit () = match getString(keyManagerPublicKey()) {
4949 case s: String =>
5050 fromBase58String(s)
5151 case _: Unit =>
5252 unit
5353 case _ =>
5454 throw("Match error")
5555 }
5656
5757
5858 func pendingManagerPublicKeyOrUnit () = match getString(keyPendingManagerPublicKey()) {
5959 case s: String =>
6060 fromBase58String(s)
6161 case _: Unit =>
6262 unit
6363 case _ =>
6464 throw("Match error")
6565 }
6666
6767
6868 func isManager (i) = match managerPublicKeyOrUnit() {
6969 case pk: ByteVector =>
7070 (i.callerPublicKey == pk)
7171 case _: Unit =>
7272 (i.caller == this)
7373 case _ =>
7474 throw("Match error")
7575 }
7676
7777
7878 func mustManager (i) = if (isManager(i))
7979 then true
8080 else throw("permission denied")
8181
8282
83+func getAccBalance (assetId) = if ((assetId == "WAVES"))
84+ then wavesBalance(this).available
85+ else assetBalance(this, fromBase58String(assetId))
86+
87+
8388 @Callable(i)
84-func constructor (protocolFeeAmount,feeLiquidityAmount,feeLiquidityAddress,fc) = {
85- let check = mustManager(i)
89+func swapCalulateREADONLY (amountIn,assetIn,assetOut) = {
90+ let prFee = value(getInteger(protocolFee()))
91+ 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)
95+ let lpNonReverese = invoke(factoryContract, "getLpAssetFromPoolAssetsREADONLY", [assetIn, assetOut], nil)
96+ let lpReverse = invoke(factoryContract, "getLpAssetFromPoolAssetsREADONLY", [assetOut, assetIn], nil)
97+ let $t026383128 = if ((lpNonReverese != unit))
98+ then {
99+ let isReverse = false
100+ let pool = {
101+ let @ = invoke(factoryContract, "getPoolAddressFromLpAssetREADONLY", [lpNonReverese], nil)
102+ if ($isInstanceOf(@, "Address"))
103+ then @
104+ else throw(($getType(@) + " couldn't be cast to Address"))
105+ }
106+ $Tuple2(isReverse, pool)
107+ }
108+ else if ((lpReverse != unit))
109+ then {
110+ let isReverse = true
111+ let pool = invoke(factoryContract, "getPoolAddressFromLpAssetREADONLY", [lpReverse], nil)
112+ $Tuple2(isReverse, pool)
113+ }
114+ else poolNotExist
115+ let isReverse = $t026383128._1
116+ let pool = $t026383128._2
117+ let isPoolOneTokenOperationsDisabled = {
118+ let @ = invoke(factoryContract, "isPoolOneTokenOperationsDisabledREADONLY", [pool], nil)
119+ if ($isInstanceOf(@, "Boolean"))
120+ then @
121+ else throw(($getType(@) + " couldn't be cast to Boolean"))
122+ }
123+ let check = if (isPoolOneTokenOperationsDisabled)
124+ then true
125+ else poolDisabled
86126 if ((check == check))
87- then [StringEntry(feeLiquidityContractAddress(), feeLiquidityAddress), IntegerEntry(feeLiquidity(), feeLiquidityAmount), IntegerEntry(protocolFee(), protocolFeeAmount), StringEntry(fc(), fc)]
127+ then {
128+ let poolAdr = addressFromStringValue(valueOrElse(pool, ""))
129+ let res = {
130+ let @ = invoke(poolAdr, "calculateAmountOutForSwapREADONLY", [cleanAmountIn, isReverse], nil)
131+ if ($isInstanceOf(@, "Int"))
132+ then @
133+ else throw(($getType(@) + " couldn't be cast to Int"))
134+ }
135+ $Tuple2(nil, res)
136+ }
88137 else throw("Strict value is not equal to itself.")
89138 }
90139
91140
92141
93142 @Callable(i)
94143 func swap (amountOutMin,assetOut,addressTo) = {
95144 let pmt = value(i.payments[0])
96- let assetIn = value(pmt.assetId)
145+ let assetIn = if ((pmt.assetId == unit))
146+ then toBytes("WAVES")
147+ else value(pmt.assetId)
97148 let amountIn = value(pmt.amount)
98149 let prFee = value(getInteger(protocolFee()))
99150 let feeProtocolAmount = fraction(toBigInt(amountIn), toBigInt(prFee), feeScale)
100151 let feeLiquidityAmount = fraction(toBigInt(amountIn), toBigInt(prFee), feeScale)
101152 let amountInToPool = (toBigInt(amountIn) - feeProtocolAmount)
102153 let cleanAmountIn = (amountInToPool - feeLiquidityAmount)
103154 let checks = [if ((size(i.payments) == 1))
104155 then true
105156 else throw("exactly 1 payment are expected")]
106157 if ((checks == checks))
107158 then {
108159 let lpNonReverese = invoke(factoryContract, "getLpAssetFromPoolAssetsREADONLY", [assetIn, assetOut], nil)
109160 let lpReverse = invoke(factoryContract, "getLpAssetFromPoolAssetsREADONLY", [assetOut, assetIn], nil)
110- let $t030893610 = if ((lpNonReverese != unit))
161+ let $t045485038 = if ((lpNonReverese != unit))
111162 then {
112163 let isReverse = false
113- let pool = invoke(factoryContract, "getPoolAddressFromLpAssetREADONLY", [lpNonReverese], nil)
164+ let pool = {
165+ let @ = invoke(factoryContract, "getPoolAddressFromLpAssetREADONLY", [lpNonReverese], nil)
166+ if ($isInstanceOf(@, "Address"))
167+ then @
168+ else throw(($getType(@) + " couldn't be cast to Address"))
169+ }
114170 $Tuple2(isReverse, pool)
115171 }
116172 else if ((lpReverse != unit))
117173 then {
118174 let isReverse = true
119175 let pool = invoke(factoryContract, "getPoolAddressFromLpAssetREADONLY", [lpReverse], nil)
120176 $Tuple2(isReverse, pool)
121177 }
122- else {
123- let isReverse = true
124- let pool = ""
125- $Tuple2(isReverse, pool)
126- }
127- let isReverse = $t030893610._1
128- let pool = $t030893610._2
129- let checkExist = [if ((pool != ""))
178+ else poolNotExist
179+ let isReverse = $t045485038._1
180+ let pool = $t045485038._2
181+ let isPoolOneTokenOperationsDisabled = {
182+ let @ = invoke(factoryContract, "isPoolOneTokenOperationsDisabledREADONLY", [pool], nil)
183+ if ($isInstanceOf(@, "Boolean"))
184+ then @
185+ else throw(($getType(@) + " couldn't be cast to Boolean"))
186+ }
187+ let check = if (isPoolOneTokenOperationsDisabled)
130188 then true
131- else poolNotExist]
132- if ((checkExist == checkExist))
189+ else poolDisabled
190+ if ((check == check))
133191 then {
134- let isPoolOneTokenOperationsDisabled = {
135- let @ = invoke(factoryContract, "isPoolOneTokenOperationsDisabledREADONLY", [pool], nil)
192+ let poolAdr = addressFromStringValue(valueOrElse(pool, ""))
193+ let res = {
194+ let @ = invoke(poolAdr, "calculateAmountOutForSwapAndSendTokens", [cleanAmountIn, isReverse, amountOutMin, addressTo], [AttachedPayment(assetIn, toInt(amountInToPool))])
136195 if ($isInstanceOf(@, "Boolean"))
137196 then @
138197 else throw(($getType(@) + " couldn't be cast to Boolean"))
139198 }
140- let check = [if (isPoolOneTokenOperationsDisabled)
141- then true
142- else poolDisabled]
143- if ((check == check))
144- then {
145- let poolAdr = addressFromStringValue(valueOrElse(pool, ""))
146- let res = invoke(poolAdr, "calculateAmountOutForSwapAndSendTokens", [cleanAmountIn, isReverse, amountOutMin, addressTo], [AttachedPayment(assetIn, toInt(amountInToPool))])
147- $Tuple2(nil, true)
148- }
149- else throw("Strict value is not equal to itself.")
199+ $Tuple2(nil, res)
150200 }
151201 else throw("Strict value is not equal to itself.")
152202 }
153203 else throw("Strict value is not equal to itself.")
154204 }
155205
156206
157207
158208 @Callable(i)
159209 func setManager (pendingManagerPublicKey) = {
160210 let checkCaller = mustManager(i)
161211 if ((checkCaller == checkCaller))
162212 then {
163213 let checkManagerPublicKey = fromBase58String(pendingManagerPublicKey)
164214 if ((checkManagerPublicKey == checkManagerPublicKey))
165215 then [StringEntry(keyPendingManagerPublicKey(), pendingManagerPublicKey)]
166216 else throw("Strict value is not equal to itself.")
167217 }
168218 else throw("Strict value is not equal to itself.")
169219 }
170220
171221
172222
173223 @Callable(i)
174224 func confirmManager () = {
175225 let pm = pendingManagerPublicKeyOrUnit()
176226 let hasPM = if (isDefined(pm))
177227 then true
178228 else throw("no pending manager")
179229 if ((hasPM == hasPM))
180230 then {
181231 let checkPM = if ((i.callerPublicKey == value(pm)))
182232 then true
183233 else throw("you are not pending manager")
184234 if ((checkPM == checkPM))
185235 then [StringEntry(keyManagerPublicKey(), toBase58String(value(pm))), DeleteEntry(keyPendingManagerPublicKey())]
186236 else throw("Strict value is not equal to itself.")
187237 }
188238 else throw("Strict value is not equal to itself.")
189239 }
190240
191241
192242 @Verifier(tx)
193243 func verify () = {
194244 let targetPublicKey = match managerPublicKeyOrUnit() {
195245 case pk: ByteVector =>
196246 pk
197247 case _: Unit =>
198248 tx.senderPublicKey
199249 case _ =>
200250 throw("Match error")
201251 }
202252 sigVerify(tx.bodyBytes, tx.proofs[0], targetPublicKey)
203253 }
204254

github/deemru/w8io/026f985 
77.23 ms