tx · ALnuBBV9sSqPtwwqrSwPmNEpknEHcjw3jb5QgSmSnuE8

3N6LHjfGb6Fgcy7YsVcNxGyPTj49XbQAijq:  -0.01300000 Waves

2023.02.13 14:32 [2447784] smart account 3N6LHjfGb6Fgcy7YsVcNxGyPTj49XbQAijq > SELF 0.00000000 Waves

{ "type": 13, "id": "ALnuBBV9sSqPtwwqrSwPmNEpknEHcjw3jb5QgSmSnuE8", "fee": 1300000, "feeAssetId": null, "timestamp": 1676287945708, "version": 2, "chainId": 84, "sender": "3N6LHjfGb6Fgcy7YsVcNxGyPTj49XbQAijq", "senderPublicKey": "2u2wYYcVBQv43Cc71zkhHPPitkqgg6dqTZ3nUMvYJ1uq", "proofs": [ "4o4akywfE3eRTQQsXZrkuYYXXthG8UXU8A3oPrQK2nWBtVc3Gm6UxFJqmyTVjE3pf4KMtC4NiwACCSsBmkGebyib" ], "script": "base64:BgIXCAISBQoDAQgIEgUKAwEICBIDCgEIEgAXAANTRVACAl9fAAhmZWVTY2FsZQkAtgIBAIDC1y8BD2dldFN0cmluZ09yRmFpbAEDa2V5CQETdmFsdWVPckVycm9yTWVzc2FnZQIJAJ0IAgUEdGhpcwUDa2V5CQCsAgICFU5vIGRhdGEgZm9yIHRoaXMua2V5PQUDa2V5AAxwb29sRGlzYWJsZWQJAAIBAg1Qb29sIGRpc2FibGVkAAxwb29sTm90RXhpc3QJAAIBAhFQb29sIGlzIG5vdCBleGlzdAAOc2xpcHBhZ2VUb29CaWcJAAIBAhNTbGlwcGFnZSBpcyB0b28gYmlnARNrZXlNYW5hZ2VyUHVibGljS2V5AAIUJXNfX21hbmFnZXJQdWJsaWNLZXkBGmtleVBlbmRpbmdNYW5hZ2VyUHVibGljS2V5AAIbJXNfX3BlbmRpbmdNYW5hZ2VyUHVibGljS2V5AQJmYwACEyVzX19mYWN0b3J5Q29udHJhY3QAD2ZhY3RvcnlDb250cmFjdAkBEUBleHRyTmF0aXZlKDEwNjIpAQkBD2dldFN0cmluZ09yRmFpb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RjaCBlcnJvcgkA9AMDCAUCdHgJYm9keUJ5dGVzCQCRAwIIBQJ0eAZwcm9vZnMAAAUPdGFyZ2V0UHVibGljS2V5TcrZYA==", "height": 2447784, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 3mrufDkoHKzzESv7NXcZSGk5zhWC6qoV8if8Etj8mGBi Next: C2AVK4JaqwYa5J7AQcJEqiSF6j1r6CQK6Rha1JZpu33v Diff:
OldNewDifferences
8989 else assetBalance(this, fromBase58String(assetId))
9090
9191
92+func getPoolAddressAndCheckPoolStatus (assetIn,assetOut) = {
93+ let lpNonReverse = {
94+ let @ = invoke(factoryContract, "getLpAssetFromPoolAssetsREADONLY", [assetIn, assetOut], nil)
95+ if ($isInstanceOf(@, "String"))
96+ then @
97+ else unit
98+ }
99+ let lpReverse = {
100+ let @ = invoke(factoryContract, "getLpAssetFromPoolAssetsREADONLY", [assetOut, assetIn], nil)
101+ if ($isInstanceOf(@, "String"))
102+ then @
103+ else unit
104+ }
105+ let $t025332992 = if ((lpNonReverse != unit))
106+ then {
107+ let pool = {
108+ let @ = invoke(factoryContract, "getPoolAddressFromLpAssetREADONLY", [value(lpNonReverse)], nil)
109+ if ($isInstanceOf(@, "String"))
110+ then @
111+ else throw(($getType(@) + " couldn't be cast to String"))
112+ }
113+ $Tuple2(false, pool)
114+ }
115+ else if ((lpReverse != unit))
116+ then {
117+ let pool = {
118+ let @ = invoke(factoryContract, "getPoolAddressFromLpAssetREADONLY", [value(lpReverse)], nil)
119+ if ($isInstanceOf(@, "String"))
120+ then @
121+ else throw(($getType(@) + " couldn't be cast to String"))
122+ }
123+ $Tuple2(true, pool)
124+ }
125+ else poolNotExist
126+ let isReverse = $t025332992._1
127+ let pool = $t025332992._2
128+ let poolStatus = {
129+ let @ = invoke(factoryContract, "getPoolStatusREADONLY", [pool], nil)
130+ if ($isInstanceOf(@, "Int"))
131+ then @
132+ else throw(($getType(@) + " couldn't be cast to Int"))
133+ }
134+ let check = if ((poolStatus == 1))
135+ then true
136+ else poolDisabled
137+ if ((check == check))
138+ then {
139+ let poolAdr = addressFromStringValue(valueOrElse(pool, ""))
140+ $Tuple2(poolAdr, isReverse)
141+ }
142+ else throw("Strict value is not equal to itself.")
143+ }
144+
145+
92146 @Callable(i)
93147 func swapCalculateREADONLY (amountIn,assetIn,assetOut) = {
94148 let prFee = value(getInteger(protocolFee()))
102156 then toBigInt(1)
103157 else feePoolAmountCalc
104158 let cleanAmountIn = ((toBigInt(amountIn) - feeProtocolAmount) - feePoolAmount)
105- let lpNonReverse = invoke(factoryContract, "getLpAssetFromPoolAssetsREADONLY", [assetIn, assetOut], nil)
106- let lpReverse = invoke(factoryContract, "getLpAssetFromPoolAssetsREADONLY", [assetOut, assetIn], nil)
107- let $t031223625 = if ((lpNonReverse != unit))
108- then {
109- let isReverse = false
110- let pool = {
111- let @ = invoke(factoryContract, "getPoolAddressFromLpAssetREADONLY", [lpNonReverse], nil)
112- if ($isInstanceOf(@, "String"))
113- then @
114- else throw(($getType(@) + " couldn't be cast to String"))
115- }
116- $Tuple2(isReverse, pool)
117- }
118- else if ((lpReverse != unit))
119- then {
120- let isReverse = true
121- let pool = {
122- let @ = invoke(factoryContract, "getPoolAddressFromLpAssetREADONLY", [lpReverse], nil)
123- if ($isInstanceOf(@, "String"))
124- then @
125- else throw(($getType(@) + " couldn't be cast to String"))
126- }
127- $Tuple2(isReverse, pool)
128- }
129- else poolNotExist
130- let isReverse = $t031223625._1
131- let pool = $t031223625._2
132- let poolStatus = {
133- let @ = invoke(factoryContract, "getPoolStatusREADONLY", [pool], nil)
159+ let $t039794057 = getPoolAddressAndCheckPoolStatus(assetIn, assetOut)
160+ let poolAdr = $t039794057._1
161+ let isReverse = $t039794057._2
162+ let res = {
163+ let @ = invoke(poolAdr, "calculateAmountOutForSwapREADONLY", [toInt(cleanAmountIn), isReverse], nil)
134164 if ($isInstanceOf(@, "Int"))
135165 then @
136166 else throw(($getType(@) + " couldn't be cast to Int"))
137167 }
138- let check = if ((poolStatus == 1))
139- then true
140- else poolDisabled
141- if ((check == check))
142- then {
143- let poolAdr = addressFromStringValue(valueOrElse(pool, ""))
144- let res = {
145- let @ = invoke(poolAdr, "calculateAmountOutForSwapREADONLY", [toInt(cleanAmountIn), isReverse], nil)
146- if ($isInstanceOf(@, "Int"))
147- then @
148- else throw(($getType(@) + " couldn't be cast to Int"))
149- }
150- $Tuple2(nil, res)
151- }
152- else throw("Strict value is not equal to itself.")
168+ $Tuple2(nil, res)
153169 }
154170
155171
177193 else throw("exactly 1 payment are expected")]
178194 if ((checks == checks))
179195 then {
180- let lpNonReverse = {
181- let @ = invoke(factoryContract, "getLpAssetFromPoolAssetsREADONLY", [assetIn, assetOut], nil)
182- if ($isInstanceOf(@, "String"))
183- then @
184- else unit
185- }
186- let lpReverse = {
187- let @ = invoke(factoryContract, "getLpAssetFromPoolAssetsREADONLY", [assetOut, assetIn], nil)
188- if ($isInstanceOf(@, "String"))
189- then @
190- else unit
191- }
192- let $t052305832 = if ((lpNonReverse != unit))
193- then {
194- let isReverse = false
195- let pool = {
196- let @ = invoke(factoryContract, "getPoolAddressFromLpAssetREADONLY", [value(lpNonReverse)], nil)
197- if ($isInstanceOf(@, "String"))
198- then @
199- else throw(($getType(@) + " couldn't be cast to String"))
200- }
201- $Tuple2(isReverse, pool)
202- }
203- else if ((lpReverse != unit))
204- then {
205- let isReverse = true
206- let pool = {
207- let @ = invoke(factoryContract, "getPoolAddressFromLpAssetREADONLY", [value(lpReverse)], nil)
208- if ($isInstanceOf(@, "String"))
209- then @
210- else throw(($getType(@) + " couldn't be cast to String"))
211- }
212- $Tuple2(isReverse, pool)
213- }
214- else throw(((("pool is not exist: assetIn=" + assetIn) + " assetOut=") + assetOut))
215- let isReverse = $t052305832._1
216- let pool = $t052305832._2
217- let poolStatus = {
218- let @ = invoke(factoryContract, "getPoolStatusREADONLY", [pool], nil)
196+ let $t051635241 = getPoolAddressAndCheckPoolStatus(assetIn, assetOut)
197+ let poolAdr = $t051635241._1
198+ let isReverse = $t051635241._2
199+ let assetInAttachedPayment = if ((assetIn == "WAVES"))
200+ then unit
201+ else fromBase58String(assetIn)
202+ let totalGetRaw = {
203+ let @ = invoke(poolAdr, "calculateAmountOutForSwapAndSendTokens", [toInt(cleanAmountIn), isReverse, amountOutMin, addressTo], [AttachedPayment(assetInAttachedPayment, toInt(cleanAmountIn))])
219204 if ($isInstanceOf(@, "Int"))
220205 then @
221206 else throw(($getType(@) + " couldn't be cast to Int"))
222207 }
223- let check = if ((poolStatus == 1))
224- then true
225- else poolDisabled
226- if ((check == check))
227- then {
228- let poolAdr = addressFromStringValue(pool)
229- let assetInAttachedPayment = if ((assetIn == "WAVES"))
230- then unit
231- else fromBase58String(assetIn)
232- let totalGetRaw = {
233- let @ = invoke(poolAdr, "calculateAmountOutForSwapAndSendTokens", [toInt(cleanAmountIn), isReverse, amountOutMin, addressTo], [AttachedPayment(assetInAttachedPayment, toInt(cleanAmountIn))])
234- if ($isInstanceOf(@, "Int"))
235- then @
236- else throw(($getType(@) + " couldn't be cast to Int"))
237- }
238- $Tuple2([ScriptTransfer(feeCollectorAddress, toInt(feeProtocolAmount), assetInAttachedPayment), ScriptTransfer(poolAdr, toInt(feePoolAmount), assetInAttachedPayment)], totalGetRaw)
239- }
240- else throw("Strict value is not equal to itself.")
208+ $Tuple2([ScriptTransfer(feeCollectorAddress, toInt(feeProtocolAmount), assetInAttachedPayment), ScriptTransfer(poolAdr, toInt(feePoolAmount), assetInAttachedPayment)], totalGetRaw)
241209 }
242210 else throw("Strict value is not equal to itself.")
243211 }
Full:
OldNewDifferences
11 {-# STDLIB_VERSION 6 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
44 let SEP = "__"
55
66 let feeScale = toBigInt(100000000)
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 protocolFee () = makeString(["%s", "protocolFee"], SEP)
2929
3030
3131 func poolFee () = makeString(["%s", "poolFee"], SEP)
3232
3333
3434 func getStringOrFailFromAddress (address,key) = valueOrErrorMessage(getString(address, key), makeString(["mandatory ", toString(address), ".", key, " is not defined"], ""))
3535
3636
3737 let keyFeeCollectorAddress = "%s__feeCollectorAddress"
3838
3939 let feeCollectorAddress = addressFromStringValue(getStringOrFailFromAddress(factoryContract, keyFeeCollectorAddress))
4040
4141 func asInt (val) = match val {
4242 case valInt: Int =>
4343 valInt
4444 case _ =>
4545 throw("fail to cast into Int")
4646 }
4747
4848
4949 func dataMappingPoolAssets (internalAmountAssetStr,internalPriceAssetStr) = makeString(["%d%d", toString(internalAmountAssetStr), toString(internalPriceAssetStr)], SEP)
5050
5151
5252 func managerPublicKeyOrUnit () = match getString(keyManagerPublicKey()) {
5353 case s: String =>
5454 fromBase58String(s)
5555 case _: Unit =>
5656 unit
5757 case _ =>
5858 throw("Match error")
5959 }
6060
6161
6262 func pendingManagerPublicKeyOrUnit () = match getString(keyPendingManagerPublicKey()) {
6363 case s: String =>
6464 fromBase58String(s)
6565 case _: Unit =>
6666 unit
6767 case _ =>
6868 throw("Match error")
6969 }
7070
7171
7272 func isManager (i) = match managerPublicKeyOrUnit() {
7373 case pk: ByteVector =>
7474 (i.callerPublicKey == pk)
7575 case _: Unit =>
7676 (i.caller == this)
7777 case _ =>
7878 throw("Match error")
7979 }
8080
8181
8282 func mustManager (i) = if (isManager(i))
8383 then true
8484 else throw("permission denied")
8585
8686
8787 func getAccBalance (assetId) = if ((assetId == "WAVES"))
8888 then wavesBalance(this).available
8989 else assetBalance(this, fromBase58String(assetId))
9090
9191
92+func getPoolAddressAndCheckPoolStatus (assetIn,assetOut) = {
93+ let lpNonReverse = {
94+ let @ = invoke(factoryContract, "getLpAssetFromPoolAssetsREADONLY", [assetIn, assetOut], nil)
95+ if ($isInstanceOf(@, "String"))
96+ then @
97+ else unit
98+ }
99+ let lpReverse = {
100+ let @ = invoke(factoryContract, "getLpAssetFromPoolAssetsREADONLY", [assetOut, assetIn], nil)
101+ if ($isInstanceOf(@, "String"))
102+ then @
103+ else unit
104+ }
105+ let $t025332992 = if ((lpNonReverse != unit))
106+ then {
107+ let pool = {
108+ let @ = invoke(factoryContract, "getPoolAddressFromLpAssetREADONLY", [value(lpNonReverse)], nil)
109+ if ($isInstanceOf(@, "String"))
110+ then @
111+ else throw(($getType(@) + " couldn't be cast to String"))
112+ }
113+ $Tuple2(false, pool)
114+ }
115+ else if ((lpReverse != unit))
116+ then {
117+ let pool = {
118+ let @ = invoke(factoryContract, "getPoolAddressFromLpAssetREADONLY", [value(lpReverse)], nil)
119+ if ($isInstanceOf(@, "String"))
120+ then @
121+ else throw(($getType(@) + " couldn't be cast to String"))
122+ }
123+ $Tuple2(true, pool)
124+ }
125+ else poolNotExist
126+ let isReverse = $t025332992._1
127+ let pool = $t025332992._2
128+ let poolStatus = {
129+ let @ = invoke(factoryContract, "getPoolStatusREADONLY", [pool], nil)
130+ if ($isInstanceOf(@, "Int"))
131+ then @
132+ else throw(($getType(@) + " couldn't be cast to Int"))
133+ }
134+ let check = if ((poolStatus == 1))
135+ then true
136+ else poolDisabled
137+ if ((check == check))
138+ then {
139+ let poolAdr = addressFromStringValue(valueOrElse(pool, ""))
140+ $Tuple2(poolAdr, isReverse)
141+ }
142+ else throw("Strict value is not equal to itself.")
143+ }
144+
145+
92146 @Callable(i)
93147 func swapCalculateREADONLY (amountIn,assetIn,assetOut) = {
94148 let prFee = value(getInteger(protocolFee()))
95149 let feeProtocolAmountCalc = fraction(toBigInt(amountIn), toBigInt(prFee), feeScale)
96150 let plFee = value(getInteger(poolFee()))
97151 let feePoolAmountCalc = fraction(toBigInt(amountIn), toBigInt(plFee), feeScale)
98152 let feeProtocolAmount = if ((toInt(feeProtocolAmountCalc) == 0))
99153 then toBigInt(1)
100154 else feeProtocolAmountCalc
101155 let feePoolAmount = if ((toInt(feePoolAmountCalc) == 0))
102156 then toBigInt(1)
103157 else feePoolAmountCalc
104158 let cleanAmountIn = ((toBigInt(amountIn) - feeProtocolAmount) - feePoolAmount)
105- let lpNonReverse = invoke(factoryContract, "getLpAssetFromPoolAssetsREADONLY", [assetIn, assetOut], nil)
106- let lpReverse = invoke(factoryContract, "getLpAssetFromPoolAssetsREADONLY", [assetOut, assetIn], nil)
107- let $t031223625 = if ((lpNonReverse != unit))
108- then {
109- let isReverse = false
110- let pool = {
111- let @ = invoke(factoryContract, "getPoolAddressFromLpAssetREADONLY", [lpNonReverse], nil)
112- if ($isInstanceOf(@, "String"))
113- then @
114- else throw(($getType(@) + " couldn't be cast to String"))
115- }
116- $Tuple2(isReverse, pool)
117- }
118- else if ((lpReverse != unit))
119- then {
120- let isReverse = true
121- let pool = {
122- let @ = invoke(factoryContract, "getPoolAddressFromLpAssetREADONLY", [lpReverse], nil)
123- if ($isInstanceOf(@, "String"))
124- then @
125- else throw(($getType(@) + " couldn't be cast to String"))
126- }
127- $Tuple2(isReverse, pool)
128- }
129- else poolNotExist
130- let isReverse = $t031223625._1
131- let pool = $t031223625._2
132- let poolStatus = {
133- let @ = invoke(factoryContract, "getPoolStatusREADONLY", [pool], nil)
159+ let $t039794057 = getPoolAddressAndCheckPoolStatus(assetIn, assetOut)
160+ let poolAdr = $t039794057._1
161+ let isReverse = $t039794057._2
162+ let res = {
163+ let @ = invoke(poolAdr, "calculateAmountOutForSwapREADONLY", [toInt(cleanAmountIn), isReverse], nil)
134164 if ($isInstanceOf(@, "Int"))
135165 then @
136166 else throw(($getType(@) + " couldn't be cast to Int"))
137167 }
138- let check = if ((poolStatus == 1))
139- then true
140- else poolDisabled
141- if ((check == check))
142- then {
143- let poolAdr = addressFromStringValue(valueOrElse(pool, ""))
144- let res = {
145- let @ = invoke(poolAdr, "calculateAmountOutForSwapREADONLY", [toInt(cleanAmountIn), isReverse], nil)
146- if ($isInstanceOf(@, "Int"))
147- then @
148- else throw(($getType(@) + " couldn't be cast to Int"))
149- }
150- $Tuple2(nil, res)
151- }
152- else throw("Strict value is not equal to itself.")
168+ $Tuple2(nil, res)
153169 }
154170
155171
156172
157173 @Callable(i)
158174 func swap (amountOutMin,assetOut,addressTo) = {
159175 let pmt = value(i.payments[0])
160176 let assetIn = if ((pmt.assetId == unit))
161177 then "WAVES"
162178 else toBase58String(value(pmt.assetId))
163179 let amountIn = value(pmt.amount)
164180 let prFee = value(getInteger(protocolFee()))
165181 let feeProtocolAmountCalc = fraction(toBigInt(amountIn), toBigInt(prFee), feeScale)
166182 let plFee = value(getInteger(poolFee()))
167183 let feePoolAmountCalc = fraction(toBigInt(amountIn), toBigInt(plFee), feeScale)
168184 let feeProtocolAmount = if ((toInt(feeProtocolAmountCalc) == 0))
169185 then toBigInt(1)
170186 else feeProtocolAmountCalc
171187 let feePoolAmount = if ((toInt(feePoolAmountCalc) == 0))
172188 then toBigInt(1)
173189 else feePoolAmountCalc
174190 let cleanAmountIn = ((toBigInt(amountIn) - feeProtocolAmount) - feePoolAmount)
175191 let checks = [if ((size(i.payments) == 1))
176192 then true
177193 else throw("exactly 1 payment are expected")]
178194 if ((checks == checks))
179195 then {
180- let lpNonReverse = {
181- let @ = invoke(factoryContract, "getLpAssetFromPoolAssetsREADONLY", [assetIn, assetOut], nil)
182- if ($isInstanceOf(@, "String"))
183- then @
184- else unit
185- }
186- let lpReverse = {
187- let @ = invoke(factoryContract, "getLpAssetFromPoolAssetsREADONLY", [assetOut, assetIn], nil)
188- if ($isInstanceOf(@, "String"))
189- then @
190- else unit
191- }
192- let $t052305832 = if ((lpNonReverse != unit))
193- then {
194- let isReverse = false
195- let pool = {
196- let @ = invoke(factoryContract, "getPoolAddressFromLpAssetREADONLY", [value(lpNonReverse)], nil)
197- if ($isInstanceOf(@, "String"))
198- then @
199- else throw(($getType(@) + " couldn't be cast to String"))
200- }
201- $Tuple2(isReverse, pool)
202- }
203- else if ((lpReverse != unit))
204- then {
205- let isReverse = true
206- let pool = {
207- let @ = invoke(factoryContract, "getPoolAddressFromLpAssetREADONLY", [value(lpReverse)], nil)
208- if ($isInstanceOf(@, "String"))
209- then @
210- else throw(($getType(@) + " couldn't be cast to String"))
211- }
212- $Tuple2(isReverse, pool)
213- }
214- else throw(((("pool is not exist: assetIn=" + assetIn) + " assetOut=") + assetOut))
215- let isReverse = $t052305832._1
216- let pool = $t052305832._2
217- let poolStatus = {
218- let @ = invoke(factoryContract, "getPoolStatusREADONLY", [pool], nil)
196+ let $t051635241 = getPoolAddressAndCheckPoolStatus(assetIn, assetOut)
197+ let poolAdr = $t051635241._1
198+ let isReverse = $t051635241._2
199+ let assetInAttachedPayment = if ((assetIn == "WAVES"))
200+ then unit
201+ else fromBase58String(assetIn)
202+ let totalGetRaw = {
203+ let @ = invoke(poolAdr, "calculateAmountOutForSwapAndSendTokens", [toInt(cleanAmountIn), isReverse, amountOutMin, addressTo], [AttachedPayment(assetInAttachedPayment, toInt(cleanAmountIn))])
219204 if ($isInstanceOf(@, "Int"))
220205 then @
221206 else throw(($getType(@) + " couldn't be cast to Int"))
222207 }
223- let check = if ((poolStatus == 1))
224- then true
225- else poolDisabled
226- if ((check == check))
227- then {
228- let poolAdr = addressFromStringValue(pool)
229- let assetInAttachedPayment = if ((assetIn == "WAVES"))
230- then unit
231- else fromBase58String(assetIn)
232- let totalGetRaw = {
233- let @ = invoke(poolAdr, "calculateAmountOutForSwapAndSendTokens", [toInt(cleanAmountIn), isReverse, amountOutMin, addressTo], [AttachedPayment(assetInAttachedPayment, toInt(cleanAmountIn))])
234- if ($isInstanceOf(@, "Int"))
235- then @
236- else throw(($getType(@) + " couldn't be cast to Int"))
237- }
238- $Tuple2([ScriptTransfer(feeCollectorAddress, toInt(feeProtocolAmount), assetInAttachedPayment), ScriptTransfer(poolAdr, toInt(feePoolAmount), assetInAttachedPayment)], totalGetRaw)
239- }
240- else throw("Strict value is not equal to itself.")
208+ $Tuple2([ScriptTransfer(feeCollectorAddress, toInt(feeProtocolAmount), assetInAttachedPayment), ScriptTransfer(poolAdr, toInt(feePoolAmount), assetInAttachedPayment)], totalGetRaw)
241209 }
242210 else throw("Strict value is not equal to itself.")
243211 }
244212
245213
246214
247215 @Callable(i)
248216 func setManager (pendingManagerPublicKey) = {
249217 let checkCaller = mustManager(i)
250218 if ((checkCaller == checkCaller))
251219 then {
252220 let checkManagerPublicKey = fromBase58String(pendingManagerPublicKey)
253221 if ((checkManagerPublicKey == checkManagerPublicKey))
254222 then [StringEntry(keyPendingManagerPublicKey(), pendingManagerPublicKey)]
255223 else throw("Strict value is not equal to itself.")
256224 }
257225 else throw("Strict value is not equal to itself.")
258226 }
259227
260228
261229
262230 @Callable(i)
263231 func confirmManager () = {
264232 let pm = pendingManagerPublicKeyOrUnit()
265233 let hasPM = if (isDefined(pm))
266234 then true
267235 else throw("no pending manager")
268236 if ((hasPM == hasPM))
269237 then {
270238 let checkPM = if ((i.callerPublicKey == value(pm)))
271239 then true
272240 else throw("you are not pending manager")
273241 if ((checkPM == checkPM))
274242 then [StringEntry(keyManagerPublicKey(), toBase58String(value(pm))), DeleteEntry(keyPendingManagerPublicKey())]
275243 else throw("Strict value is not equal to itself.")
276244 }
277245 else throw("Strict value is not equal to itself.")
278246 }
279247
280248
281249 @Verifier(tx)
282250 func verify () = {
283251 let targetPublicKey = match managerPublicKeyOrUnit() {
284252 case pk: ByteVector =>
285253 pk
286254 case _: Unit =>
287255 tx.senderPublicKey
288256 case _ =>
289257 throw("Match error")
290258 }
291259 sigVerify(tx.bodyBytes, tx.proofs[0], targetPublicKey)
292260 }
293261

github/deemru/w8io/026f985 
44.73 ms