tx · 9wWnRUe4hJ9Q2Q4HuC4Kg7efGpPsfjQuZYk6S6ES2RZ3

3N1TdY92brvvrQyVdkpHNK2aRbAsx9dYUKc:  -0.01000000 Waves

2022.05.23 09:43 [2063987] smart account 3N1TdY92brvvrQyVdkpHNK2aRbAsx9dYUKc > SELF 0.00000000 Waves

{ "type": 13, "id": "9wWnRUe4hJ9Q2Q4HuC4Kg7efGpPsfjQuZYk6S6ES2RZ3", "fee": 1000000, "feeAssetId": null, "timestamp": 1653288221828, "version": 2, "chainId": 84, "sender": "3N1TdY92brvvrQyVdkpHNK2aRbAsx9dYUKc", "senderPublicKey": "3N3TSucEwKCeSJy32W5m6LB2taq7FG7aQ7XxiXvJGdCk", "proofs": [ "4XFyskgVQAJAWtiAp91BUw2uBLppgMn2M9eQsQrnJVJZFZorWQpAg45mcei59Qepecs3qMLCp3YY4V7BnuJfrMok" ], "script": "base64:AAIFAAAAAAAAACwIAhIGCgQCAgICEggKBgICAQICAhIHCgUCAgECAhIDCgECEgMKAQISAwoBAgAAABUAAAAAEGtleUxvY2tSZWNpcGllbnQCAAAAA19scgAAAAANa2V5TG9ja0Ftb3VudAIAAAADX2xhAAAAABJrZXlMb2NrRGVzdGluYXRpb24CAAAAA19sZAAAAAASa2V5TG9ja0Fzc2V0U291cmNlAgAAAARfbGFzAAAAAAprZXlWZXJzaW9uAgAAAAJfdgAAAAAJa2V5QnJpZGdlAgAAAAJfYgAAAAAJa2V5T3JhY2xlAgAAAAJfbwAAAAAIa2V5QWRtaW4CAAAAAl9hAAAAAAlrZXlVbmxvY2sCAAAAAl91AAAAAA9lcnJVbmF1dGhvcml6ZWQCAAAADHVuYXV0aG9yaXplZAAAAAAQZXJyVW5pbml0aWFsaXplZAIAAAANdW5pbml0aWFsaXplZAAAAAATZXJySW52YWxpZFNpZ25hdHVyZQIAAAARaW52YWxpZCBzaWduYXR1cmUAAAAAEWVyckFscmVhZHlDbGFpbWVkAgAAAAdjbGFpbWVkAAAAABBlcnJBbHJlY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nZQUAAAAJbmV3QnJpZGdlBQAAAANuaWwJAAACAAAAAQIAAAAkU3RyaWN0IHZhbHVlIGlzIG5vdCBlcXVhbCB0byBpdHNlbGYuAAAAAJlbLbE=", "height": 2063987, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 2xBXLq3BhTVoBWxSLd7zx4FvsjeQumZ4kgJFyTa5824w Next: none Diff:
OldNewDifferences
11 {-# STDLIB_VERSION 5 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
4-let keyAssetAddress = "_aa"
4+let keyLockRecipient = "_lr"
55
6-let keyAssetType = "_at"
6+let keyLockAmount = "_la"
77
8-let keyAssetPrecision = "_ap"
8+let keyLockDestination = "_ld"
99
10-let keyAssetMinFee = "_amf"
10+let keyLockAssetSource = "_las"
1111
12-let keyAssetIsActive = "_aia"
12+let keyVersion = "_v"
1313
14-let keyBaseFeeRateBP = "_bfr"
14+let keyBridge = "_b"
1515
16-let keyValidator = "_v"
16+let keyOracle = "_o"
1717
18-let keyFeeCollector = "_fc"
18+let keyAdmin = "_a"
1919
20-let keyUnlockSigner = "_us"
21-
22-let keyIsActive = "_ia"
23-
24-let keyManager = "_m"
25-
26-let BRIDGE_MANAGER = "BRIDGE_MANAGER"
27-
28-let ASSET_MANAGER = "ASSET_MANAGER"
29-
30-let STOP_MANAGER = "STOP_MANAGER"
31-
32-let baseAssetSourceAndAddress = base58'fRpRFUxiLXbzAaAT3sfi1oTFa8n4X8b9FUaQHyT5MkdXYpGZV'
33-
34-let baseAssetId = base58'6scFjhFGDfpmYySMKQ9vDbZuH8aMRWsUQJAHXzm1FsJo'
35-
36-let chainWaves = base58'3EMsPJ'
37-
38-let BP = 10000
39-
40-let systemPrecision = 9
20+let keyUnlock = "_u"
4121
4222 let errUnauthorized = "unauthorized"
4323
4424 let errUninitialized = "uninitialized"
4525
46-let errInitialized = "initialized"
26+let errInvalidSignature = "invalid signature"
4727
48-let errAlreadyExists = "exists"
28+let errAlreadyClaimed = "claimed"
4929
50-let errNotExists = "not exists"
30+let errAlreadyLocked = "locked"
5131
52-let errInvalidValues = "invalid values"
32+let errInvalidLockId = "invalid lockId"
5333
54-let errNotOnePayment = "not one payment"
34+let chainWaves = "V0FWRQ=="
5535
56-let errAssetNotFound = "asset not found"
57-
58-let errNotEnoughBalance = "not enough balance"
59-
60-let errBigPowValue = "pow value too big"
61-
62-let errBridgeDisabled = "bridge is disabled"
63-
64-let errAssetDisabled = "asset is disabled"
65-
66-let errWrongDestinationChain = "wrong destination chain"
67-
68-let typeBase = 0
69-
70-let typeNative = 1
71-
72-let typeWrapped = 2
73-
74-func assertCallerIsManager (i,managerType) = match getBinary((managerType + keyManager)) {
36+func assertCaller (i,key) = match getBinary(key) {
7537 case authority: ByteVector =>
7638 if ((authority != i.caller.bytes))
7739 then throw(errUnauthorized)
8143 }
8244
8345
84-func assertBridgeIsActive () = if (!(valueOrElse(getBoolean(keyIsActive), false)))
85- then throw(errBridgeDisabled)
86- else unit
46+func assertCallerIsBridge (i) = assertCaller(i, keyBridge)
8747
8848
89-func assertAssetIsActive (assetIdStr) = match getBoolean((assetIdStr + keyAssetIsActive)) {
90- case isActive: Boolean =>
91- if (isActive)
92- then unit
93- else throw(errAssetDisabled)
49+func assertCallerIsAdmin (i) = assertCaller(i, keyAdmin)
50+
51+
52+func assertValidLockId (lockId) = {
53+ let version = valueOrErrorMessage(getBinary(keyVersion), errUninitialized)
54+ if (if ((size(lockId) != 16))
55+ then true
56+ else (take(lockId, 1) != version))
57+ then throw(errInvalidLockId)
58+ else unit
59+ }
60+
61+
62+func assertLockNotExists (lockRecipientKey) = match getBinary(lockRecipientKey) {
63+ case t: ByteVector =>
64+ throw(errAlreadyLocked)
9465 case _ =>
95- throw(errAssetNotFound)
66+ unit
9667 }
9768
9869
99-func getFee (amount,assetIdStr) = {
100- let baseFeeRateBP = valueOrErrorMessage(getInteger(keyBaseFeeRateBP), errUninitialized)
101- let minFee = valueOrErrorMessage(getInteger((assetIdStr + keyAssetMinFee)), errAssetNotFound)
102- let fee = ((amount * baseFeeRateBP) / BP)
103- if ((minFee > fee))
104- then minFee
105- else fee
106- }
107-
108-
109-func pow10 (value,power) = {
110- let absPow = if ((0 > power))
111- then -(power)
112- else power
113- let powerValue = if ((absPow == 0))
114- then 1
115- else if ((absPow == 1))
116- then 10
117- else if ((absPow == 2))
118- then 100
119- else if ((absPow == 3))
120- then 1000
121- else if ((absPow == 4))
122- then 10000
123- else if ((absPow == 5))
124- then 100000
125- else if ((absPow == 6))
126- then 1000000
127- else if ((absPow == 7))
128- then 10000000
129- else if ((absPow == 8))
130- then 100000000
131- else if ((absPow == 9))
132- then 1000000000
133- else throw(errBigPowValue)
134- if ((0 > power))
135- then (value / powerValue)
136- else (value * powerValue)
137- }
138-
139-
140-func toSystemPrecision (amount,precision) = pow10(amount, (systemPrecision - precision))
141-
142-
143-func fromSystemPrecision (amount,precision) = pow10(amount, (precision - systemPrecision))
144-
145-
14670 @Callable(i)
147-func init (admin,validatorAddress,feeCollector,unlockSigner,baseFeeRateBP) = if (isDefined(getBinary((BRIDGE_MANAGER + keyManager))))
148- then throw(errInitialized)
149- else [BinaryEntry((BRIDGE_MANAGER + keyManager), admin), BinaryEntry(keyValidator, validatorAddress), BinaryEntry(keyFeeCollector, feeCollector), BinaryEntry(keyUnlockSigner, unlockSigner), IntegerEntry(keyBaseFeeRateBP, baseFeeRateBP), BooleanEntry(keyIsActive, true)]
71+func init (admin,version,bridge,oracle) = if (isDefined(getBinary(keyAdmin)))
72+ then throw(errUnauthorized)
73+ else [BinaryEntry(keyVersion, version), BinaryEntry(keyBridge, bridge), BinaryEntry(keyOracle, oracle), BinaryEntry(keyAdmin, admin)]
15074
15175
15276
15377 @Callable(i)
154-func addAsset (assetSourceAndAddress,assetId,minFee) = {
155- let callerCheck = assertCallerIsManager(i, ASSET_MANAGER)
156- if ((callerCheck == callerCheck))
78+func createUnlock (lockId,recipient,amount,lockSource,tokenSourceAndAddress,signature) = {
79+ let checkLockId = assertValidLockId(lockId)
80+ if ((checkLockId == checkLockId))
15781 then {
158- let $t041684568 = if ((assetId == baseAssetId))
159- then if ((assetSourceAndAddress != baseAssetSourceAndAddress))
160- then throw(errInvalidValues)
161- else $Tuple2(typeBase, 8)
162- else {
163- let asset = valueOrErrorMessage(assetInfo(assetId), errAssetNotFound)
164- let type = if ((asset.issuer == this))
165- then typeWrapped
166- else typeNative
167- $Tuple2(type, asset.decimals)
168- }
169- let type = $t041684568._1
170- let precision = $t041684568._2
171- let assetIdStr = toBase64String(assetId)
172- let keySourceAddress = (toBase64String(assetSourceAndAddress) + keyAssetAddress)
173- let keyNativeAddress = (assetIdStr + keyAssetAddress)
174- if (if (isDefined(getBinary(keySourceAddress)))
175- then true
176- else isDefined(getBinary(keyNativeAddress)))
177- then throw(errAlreadyExists)
178- else [BinaryEntry(keySourceAddress, assetId), BinaryEntry(keyNativeAddress, assetSourceAndAddress), IntegerEntry((assetIdStr + keyAssetType), type), IntegerEntry((assetIdStr + keyAssetPrecision), precision), IntegerEntry((assetIdStr + keyAssetMinFee), minFee), BooleanEntry((assetIdStr + keyAssetIsActive), true)]
179- }
180- else throw("Strict value is not equal to itself.")
181- }
182-
183-
184-
185-@Callable(i)
186-func issue (name,description,precision) = {
187- let callerCheck = assertCallerIsManager(i, ASSET_MANAGER)
188- if ((callerCheck == callerCheck))
189- then [Issue(name, description, 0, precision, true)]
190- else throw("Strict value is not equal to itself.")
191- }
192-
193-
194-
195-@Callable(i)
196-func removeAsset (assetSourceAndAddress,newAuthority) = {
197- let callerCheck = assertCallerIsManager(i, ASSET_MANAGER)
198- if ((callerCheck == callerCheck))
199- then {
200- let keySourceAddress = (toBase64String(assetSourceAndAddress) + keyAssetAddress)
201- let assetId = valueOrErrorMessage(getBinary(keySourceAddress), errNotExists)
202- let assetIdStr = toBase64String(assetId)
203- let type = valueOrErrorMessage(getInteger((assetIdStr + keyAssetType)), errNotExists)
204- let actions = if ((type == typeBase))
82+ let checkCaller = assertCallerIsBridge(i)
83+ if ((checkCaller == checkCaller))
20584 then {
206- let balance = wavesBalance(this)
207- if ((balance.available > 0))
208- then [ScriptTransfer(Address(newAuthority), balance.available, unit)]
209- else nil
210- }
211- else if ((type == typeNative))
212- then {
213- let balance = assetBalance(this, assetId)
214- if ((balance > 0))
215- then [ScriptTransfer(Address(newAuthority), balance, assetId)]
216- else nil
217- }
218- else if ((type == typeWrapped))
219- then nil
220- else throw(errInvalidValues)
221- (actions ++ [DeleteEntry(keySourceAddress), DeleteEntry((assetIdStr + keyAssetAddress)), DeleteEntry((assetIdStr + keyAssetType)), DeleteEntry((assetIdStr + keyAssetPrecision)), DeleteEntry((assetIdStr + keyAssetMinFee)), DeleteEntry((assetIdStr + keyAssetIsActive))])
222- }
223- else throw("Strict value is not equal to itself.")
224- }
225-
226-
227-
228-@Callable(i)
229-func lock (lockId,recipient,destination) = {
230- let birdgeCheck = assertBridgeIsActive()
231- if ((birdgeCheck == birdgeCheck))
232- then if ((destination == chainWaves))
233- then throw(errWrongDestinationChain)
234- else if ((size(i.payments) != 1))
235- then throw(errNotOnePayment)
236- else {
237- let assetId = valueOrElse(i.payments[0].assetId, baseAssetId)
238- let assetIdStr = toBase64String(assetId)
239- let assetCheck = assertAssetIsActive(assetIdStr)
240- if ((assetCheck == assetCheck))
241- then {
242- let amount = i.payments[0].amount
243- let validatorAddress = valueOrErrorMessage(getBinary(keyValidator), errUninitialized)
244- let fee = getFee(amount, assetIdStr)
245- let amountWithoutFee = (amount - fee)
246- if ((0 >= amountWithoutFee))
247- then throw(errNotEnoughBalance)
248- else {
249- let assetSourceAndAddress = valueOrErrorMessage(getBinary((assetIdStr + keyAssetAddress)), errAssetNotFound)
250- let type = valueOrErrorMessage(getInteger((assetIdStr + keyAssetType)), errAssetNotFound)
251- let precision = valueOrErrorMessage(getInteger((assetIdStr + keyAssetPrecision)), errAssetNotFound)
252- let feeCollector = valueOrErrorMessage(getBinary(keyFeeCollector), errUninitialized)
253- let createLock = invoke(Address(validatorAddress), "createLock", [lockId, recipient, toSystemPrecision(amountWithoutFee, precision), destination, assetSourceAndAddress], nil)
254- if ((createLock == createLock))
255- then if ((type == typeBase))
256- then [ScriptTransfer(Address(feeCollector), fee, unit)]
257- else if ((type == typeNative))
258- then [ScriptTransfer(Address(feeCollector), fee, assetId)]
259- else if ((type == typeWrapped))
260- then [Burn(assetId, amountWithoutFee), ScriptTransfer(Address(feeCollector), fee, assetId)]
261- else throw(errInvalidValues)
262- else throw("Strict value is not equal to itself.")
263- }
264- }
265- else throw("Strict value is not equal to itself.")
266- }
267- else throw("Strict value is not equal to itself.")
268- }
269-
270-
271-
272-@Callable(i)
273-func unlock (lockId,recipient,amount,lockSource,assetSourceAndAddress,signature) = {
274- let birdgeCheck = assertBridgeIsActive()
275- if ((birdgeCheck == birdgeCheck))
276- then {
277- let assetId = valueOrErrorMessage(getBinary((toBase64String(assetSourceAndAddress) + keyAssetAddress)), errAssetNotFound)
278- let assetIdStr = toBase64String(assetId)
279- let type = valueOrErrorMessage(getInteger((assetIdStr + keyAssetType)), errAssetNotFound)
280- let precision = valueOrErrorMessage(getInteger((assetIdStr + keyAssetPrecision)), errAssetNotFound)
281- let validatorAddress = valueOrErrorMessage(getBinary(keyValidator), errUninitialized)
282- let unlockSigner = valueOrErrorMessage(getBinary(keyUnlockSigner), errUninitialized)
283- let feeCollector = valueOrErrorMessage(getBinary(keyFeeCollector), errUninitialized)
284- let createUnlock = invoke(Address(validatorAddress), "createUnlock", [lockId, recipient, amount, lockSource, assetSourceAndAddress, signature], nil)
285- if ((createUnlock == createUnlock))
286- then {
287- let isValid = match createUnlock {
288- case v: Boolean =>
289- v
290- case _ =>
291- false
292- }
293- if (!(isValid))
294- then throw(errInvalidValues)
85+ let lockIdStr = toBase64String(lockId)
86+ let lockSourceStr = toBase64String(lockSource)
87+ let unlockKey = (((lockSourceStr + "_") + lockIdStr) + keyUnlock)
88+ if (isDefined(getBoolean(unlockKey)))
89+ then throw(errAlreadyClaimed)
29590 else {
296- let fee = if ((unlockSigner == i.caller.bytes))
297- then valueOrErrorMessage(getInteger((assetIdStr + keyAssetMinFee)), errAssetNotFound)
298- else 0
299- let amountToSend = fromSystemPrecision(amount, precision)
300- let amountToSendWithoutFee = (amountToSend - fee)
301- if ((0 >= amountToSendWithoutFee))
302- then throw(errNotEnoughBalance)
303- else if ((type == typeBase))
304- then ([ScriptTransfer(Address(recipient), amountToSendWithoutFee, unit)] ++ (if ((fee > 0))
305- then [ScriptTransfer(Address(feeCollector), fee, unit)]
306- else nil))
307- else if ((type == typeNative))
308- then ([ScriptTransfer(Address(recipient), amountToSendWithoutFee, assetId)] ++ (if ((fee > 0))
309- then [ScriptTransfer(Address(feeCollector), fee, assetId)]
310- else nil))
311- else if ((type == typeWrapped))
312- then ([Reissue(assetId, amountToSend, true), ScriptTransfer(Address(recipient), amountToSendWithoutFee, assetId)] ++ (if ((fee > 0))
313- then [ScriptTransfer(Address(feeCollector), fee, assetId)]
314- else nil))
315- else throw(errInvalidValues)
91+ let message = makeString([lockIdStr, toBase64String(recipient), toString(amount), lockSourceStr, toBase64String(tokenSourceAndAddress), chainWaves], "_")
92+ let hash = keccak256(toBytes(message))
93+ let recoveredKey = ecrecover(hash, signature)
94+ if ((recoveredKey != getBinaryValue(keyOracle)))
95+ then throw(errInvalidSignature)
96+ else $Tuple2([BooleanEntry(unlockKey, true)], true)
31697 }
31798 }
31899 else throw("Strict value is not equal to itself.")
323104
324105
325106 @Callable(i)
326-func setManager (managerType,manager) = {
327- let callerCheck = assertCallerIsManager(i, BRIDGE_MANAGER)
328- if ((callerCheck == callerCheck))
329- then [BinaryEntry((managerType + keyManager), manager)]
330- else throw("Strict value is not equal to itself.")
331- }
332-
333-
334-
335-@Callable(i)
336-func setFeeCollector (feeCollector) = {
337- let callerCheck = assertCallerIsManager(i, BRIDGE_MANAGER)
338- if ((callerCheck == callerCheck))
339- then [BinaryEntry(keyFeeCollector, feeCollector)]
340- else throw("Strict value is not equal to itself.")
341- }
342-
343-
344-
345-@Callable(i)
346-func setValidator (validator) = {
347- let callerCheck = assertCallerIsManager(i, BRIDGE_MANAGER)
348- if ((callerCheck == callerCheck))
349- then [BinaryEntry(keyValidator, validator)]
350- else throw("Strict value is not equal to itself.")
351- }
352-
353-
354-
355-@Callable(i)
356-func startBridge () = {
357- let callerCheck = assertCallerIsManager(i, BRIDGE_MANAGER)
358- if ((callerCheck == callerCheck))
359- then [BooleanEntry(keyIsActive, true)]
360- else throw("Strict value is not equal to itself.")
361- }
362-
363-
364-
365-@Callable(i)
366-func stopBridge () = {
367- let callerCheck = assertCallerIsManager(i, STOP_MANAGER)
368- if ((callerCheck == callerCheck))
369- then [BooleanEntry(keyIsActive, false)]
370- else throw("Strict value is not equal to itself.")
371- }
372-
373-
374-
375-@Callable(i)
376-func setMinFee (assetId,minFee) = {
377- let callerCheck = assertCallerIsManager(i, ASSET_MANAGER)
378- if ((callerCheck == callerCheck))
107+func createLock (lockId,recipient,amount,lockDestination,assetSourceAndAddress) = {
108+ let lockIdStr = toBase64String(lockId)
109+ let lockRecipientKey = (lockIdStr + keyLockRecipient)
110+ let checkCaller = assertCallerIsBridge(i)
111+ if ((checkCaller == checkCaller))
379112 then {
380- let assetIdStr = toBase64String(assetId)
381-[IntegerEntry((assetIdStr + keyAssetMinFee), minFee)]
113+ let checkLockId = assertValidLockId(lockId)
114+ if ((checkLockId == checkLockId))
115+ then {
116+ let checkLock = assertLockNotExists(lockRecipientKey)
117+ if ((checkLock == checkLock))
118+ then [BinaryEntry((lockIdStr + keyLockRecipient), recipient), IntegerEntry((lockIdStr + keyLockAmount), amount), BinaryEntry((lockIdStr + keyLockDestination), lockDestination), BinaryEntry((lockIdStr + keyLockAssetSource), assetSourceAndAddress)]
119+ else throw("Strict value is not equal to itself.")
120+ }
121+ else throw("Strict value is not equal to itself.")
382122 }
383123 else throw("Strict value is not equal to itself.")
384124 }
386126
387127
388128 @Callable(i)
389-func setBaseFeeRate (baseFeeRateBP) = {
390- let callerCheck = assertCallerIsManager(i, ASSET_MANAGER)
391- if ((callerCheck == callerCheck))
392- then [IntegerEntry(keyBaseFeeRateBP, baseFeeRateBP)]
129+func setAdmin (newAdmin) = {
130+ let checkCaller = assertCallerIsAdmin(i)
131+ if ((checkCaller == checkCaller))
132+ then [BinaryEntry(keyAdmin, newAdmin)]
393133 else throw("Strict value is not equal to itself.")
394134 }
395135
396136
397137
398138 @Callable(i)
399-func setAssetState (assetId,state) = {
400- let callerCheck = assertCallerIsManager(i, ASSET_MANAGER)
401- if ((callerCheck == callerCheck))
402- then {
403- let assetIdStr = toBase64String(assetId)
404-[BooleanEntry((assetIdStr + keyAssetIsActive), state)]
405- }
139+func setOracle (newOracle) = {
140+ let checkCaller = assertCallerIsAdmin(i)
141+ if ((checkCaller == checkCaller))
142+ then [BinaryEntry(keyOracle, newOracle)]
143+ else throw("Strict value is not equal to itself.")
144+ }
145+
146+
147+
148+@Callable(i)
149+func setBridge (newBridge) = {
150+ let checkCaller = assertCallerIsAdmin(i)
151+ if ((checkCaller == checkCaller))
152+ then [BinaryEntry(keyBridge, newBridge)]
406153 else throw("Strict value is not equal to itself.")
407154 }
408155
Full:
OldNewDifferences
11 {-# STDLIB_VERSION 5 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
4-let keyAssetAddress = "_aa"
4+let keyLockRecipient = "_lr"
55
6-let keyAssetType = "_at"
6+let keyLockAmount = "_la"
77
8-let keyAssetPrecision = "_ap"
8+let keyLockDestination = "_ld"
99
10-let keyAssetMinFee = "_amf"
10+let keyLockAssetSource = "_las"
1111
12-let keyAssetIsActive = "_aia"
12+let keyVersion = "_v"
1313
14-let keyBaseFeeRateBP = "_bfr"
14+let keyBridge = "_b"
1515
16-let keyValidator = "_v"
16+let keyOracle = "_o"
1717
18-let keyFeeCollector = "_fc"
18+let keyAdmin = "_a"
1919
20-let keyUnlockSigner = "_us"
21-
22-let keyIsActive = "_ia"
23-
24-let keyManager = "_m"
25-
26-let BRIDGE_MANAGER = "BRIDGE_MANAGER"
27-
28-let ASSET_MANAGER = "ASSET_MANAGER"
29-
30-let STOP_MANAGER = "STOP_MANAGER"
31-
32-let baseAssetSourceAndAddress = base58'fRpRFUxiLXbzAaAT3sfi1oTFa8n4X8b9FUaQHyT5MkdXYpGZV'
33-
34-let baseAssetId = base58'6scFjhFGDfpmYySMKQ9vDbZuH8aMRWsUQJAHXzm1FsJo'
35-
36-let chainWaves = base58'3EMsPJ'
37-
38-let BP = 10000
39-
40-let systemPrecision = 9
20+let keyUnlock = "_u"
4121
4222 let errUnauthorized = "unauthorized"
4323
4424 let errUninitialized = "uninitialized"
4525
46-let errInitialized = "initialized"
26+let errInvalidSignature = "invalid signature"
4727
48-let errAlreadyExists = "exists"
28+let errAlreadyClaimed = "claimed"
4929
50-let errNotExists = "not exists"
30+let errAlreadyLocked = "locked"
5131
52-let errInvalidValues = "invalid values"
32+let errInvalidLockId = "invalid lockId"
5333
54-let errNotOnePayment = "not one payment"
34+let chainWaves = "V0FWRQ=="
5535
56-let errAssetNotFound = "asset not found"
57-
58-let errNotEnoughBalance = "not enough balance"
59-
60-let errBigPowValue = "pow value too big"
61-
62-let errBridgeDisabled = "bridge is disabled"
63-
64-let errAssetDisabled = "asset is disabled"
65-
66-let errWrongDestinationChain = "wrong destination chain"
67-
68-let typeBase = 0
69-
70-let typeNative = 1
71-
72-let typeWrapped = 2
73-
74-func assertCallerIsManager (i,managerType) = match getBinary((managerType + keyManager)) {
36+func assertCaller (i,key) = match getBinary(key) {
7537 case authority: ByteVector =>
7638 if ((authority != i.caller.bytes))
7739 then throw(errUnauthorized)
7840 else unit
7941 case _ =>
8042 throw(errUninitialized)
8143 }
8244
8345
84-func assertBridgeIsActive () = if (!(valueOrElse(getBoolean(keyIsActive), false)))
85- then throw(errBridgeDisabled)
86- else unit
46+func assertCallerIsBridge (i) = assertCaller(i, keyBridge)
8747
8848
89-func assertAssetIsActive (assetIdStr) = match getBoolean((assetIdStr + keyAssetIsActive)) {
90- case isActive: Boolean =>
91- if (isActive)
92- then unit
93- else throw(errAssetDisabled)
49+func assertCallerIsAdmin (i) = assertCaller(i, keyAdmin)
50+
51+
52+func assertValidLockId (lockId) = {
53+ let version = valueOrErrorMessage(getBinary(keyVersion), errUninitialized)
54+ if (if ((size(lockId) != 16))
55+ then true
56+ else (take(lockId, 1) != version))
57+ then throw(errInvalidLockId)
58+ else unit
59+ }
60+
61+
62+func assertLockNotExists (lockRecipientKey) = match getBinary(lockRecipientKey) {
63+ case t: ByteVector =>
64+ throw(errAlreadyLocked)
9465 case _ =>
95- throw(errAssetNotFound)
66+ unit
9667 }
9768
9869
99-func getFee (amount,assetIdStr) = {
100- let baseFeeRateBP = valueOrErrorMessage(getInteger(keyBaseFeeRateBP), errUninitialized)
101- let minFee = valueOrErrorMessage(getInteger((assetIdStr + keyAssetMinFee)), errAssetNotFound)
102- let fee = ((amount * baseFeeRateBP) / BP)
103- if ((minFee > fee))
104- then minFee
105- else fee
106- }
107-
108-
109-func pow10 (value,power) = {
110- let absPow = if ((0 > power))
111- then -(power)
112- else power
113- let powerValue = if ((absPow == 0))
114- then 1
115- else if ((absPow == 1))
116- then 10
117- else if ((absPow == 2))
118- then 100
119- else if ((absPow == 3))
120- then 1000
121- else if ((absPow == 4))
122- then 10000
123- else if ((absPow == 5))
124- then 100000
125- else if ((absPow == 6))
126- then 1000000
127- else if ((absPow == 7))
128- then 10000000
129- else if ((absPow == 8))
130- then 100000000
131- else if ((absPow == 9))
132- then 1000000000
133- else throw(errBigPowValue)
134- if ((0 > power))
135- then (value / powerValue)
136- else (value * powerValue)
137- }
138-
139-
140-func toSystemPrecision (amount,precision) = pow10(amount, (systemPrecision - precision))
141-
142-
143-func fromSystemPrecision (amount,precision) = pow10(amount, (precision - systemPrecision))
144-
145-
14670 @Callable(i)
147-func init (admin,validatorAddress,feeCollector,unlockSigner,baseFeeRateBP) = if (isDefined(getBinary((BRIDGE_MANAGER + keyManager))))
148- then throw(errInitialized)
149- else [BinaryEntry((BRIDGE_MANAGER + keyManager), admin), BinaryEntry(keyValidator, validatorAddress), BinaryEntry(keyFeeCollector, feeCollector), BinaryEntry(keyUnlockSigner, unlockSigner), IntegerEntry(keyBaseFeeRateBP, baseFeeRateBP), BooleanEntry(keyIsActive, true)]
71+func init (admin,version,bridge,oracle) = if (isDefined(getBinary(keyAdmin)))
72+ then throw(errUnauthorized)
73+ else [BinaryEntry(keyVersion, version), BinaryEntry(keyBridge, bridge), BinaryEntry(keyOracle, oracle), BinaryEntry(keyAdmin, admin)]
15074
15175
15276
15377 @Callable(i)
154-func addAsset (assetSourceAndAddress,assetId,minFee) = {
155- let callerCheck = assertCallerIsManager(i, ASSET_MANAGER)
156- if ((callerCheck == callerCheck))
78+func createUnlock (lockId,recipient,amount,lockSource,tokenSourceAndAddress,signature) = {
79+ let checkLockId = assertValidLockId(lockId)
80+ if ((checkLockId == checkLockId))
15781 then {
158- let $t041684568 = if ((assetId == baseAssetId))
159- then if ((assetSourceAndAddress != baseAssetSourceAndAddress))
160- then throw(errInvalidValues)
161- else $Tuple2(typeBase, 8)
162- else {
163- let asset = valueOrErrorMessage(assetInfo(assetId), errAssetNotFound)
164- let type = if ((asset.issuer == this))
165- then typeWrapped
166- else typeNative
167- $Tuple2(type, asset.decimals)
168- }
169- let type = $t041684568._1
170- let precision = $t041684568._2
171- let assetIdStr = toBase64String(assetId)
172- let keySourceAddress = (toBase64String(assetSourceAndAddress) + keyAssetAddress)
173- let keyNativeAddress = (assetIdStr + keyAssetAddress)
174- if (if (isDefined(getBinary(keySourceAddress)))
175- then true
176- else isDefined(getBinary(keyNativeAddress)))
177- then throw(errAlreadyExists)
178- else [BinaryEntry(keySourceAddress, assetId), BinaryEntry(keyNativeAddress, assetSourceAndAddress), IntegerEntry((assetIdStr + keyAssetType), type), IntegerEntry((assetIdStr + keyAssetPrecision), precision), IntegerEntry((assetIdStr + keyAssetMinFee), minFee), BooleanEntry((assetIdStr + keyAssetIsActive), true)]
179- }
180- else throw("Strict value is not equal to itself.")
181- }
182-
183-
184-
185-@Callable(i)
186-func issue (name,description,precision) = {
187- let callerCheck = assertCallerIsManager(i, ASSET_MANAGER)
188- if ((callerCheck == callerCheck))
189- then [Issue(name, description, 0, precision, true)]
190- else throw("Strict value is not equal to itself.")
191- }
192-
193-
194-
195-@Callable(i)
196-func removeAsset (assetSourceAndAddress,newAuthority) = {
197- let callerCheck = assertCallerIsManager(i, ASSET_MANAGER)
198- if ((callerCheck == callerCheck))
199- then {
200- let keySourceAddress = (toBase64String(assetSourceAndAddress) + keyAssetAddress)
201- let assetId = valueOrErrorMessage(getBinary(keySourceAddress), errNotExists)
202- let assetIdStr = toBase64String(assetId)
203- let type = valueOrErrorMessage(getInteger((assetIdStr + keyAssetType)), errNotExists)
204- let actions = if ((type == typeBase))
82+ let checkCaller = assertCallerIsBridge(i)
83+ if ((checkCaller == checkCaller))
20584 then {
206- let balance = wavesBalance(this)
207- if ((balance.available > 0))
208- then [ScriptTransfer(Address(newAuthority), balance.available, unit)]
209- else nil
210- }
211- else if ((type == typeNative))
212- then {
213- let balance = assetBalance(this, assetId)
214- if ((balance > 0))
215- then [ScriptTransfer(Address(newAuthority), balance, assetId)]
216- else nil
217- }
218- else if ((type == typeWrapped))
219- then nil
220- else throw(errInvalidValues)
221- (actions ++ [DeleteEntry(keySourceAddress), DeleteEntry((assetIdStr + keyAssetAddress)), DeleteEntry((assetIdStr + keyAssetType)), DeleteEntry((assetIdStr + keyAssetPrecision)), DeleteEntry((assetIdStr + keyAssetMinFee)), DeleteEntry((assetIdStr + keyAssetIsActive))])
222- }
223- else throw("Strict value is not equal to itself.")
224- }
225-
226-
227-
228-@Callable(i)
229-func lock (lockId,recipient,destination) = {
230- let birdgeCheck = assertBridgeIsActive()
231- if ((birdgeCheck == birdgeCheck))
232- then if ((destination == chainWaves))
233- then throw(errWrongDestinationChain)
234- else if ((size(i.payments) != 1))
235- then throw(errNotOnePayment)
236- else {
237- let assetId = valueOrElse(i.payments[0].assetId, baseAssetId)
238- let assetIdStr = toBase64String(assetId)
239- let assetCheck = assertAssetIsActive(assetIdStr)
240- if ((assetCheck == assetCheck))
241- then {
242- let amount = i.payments[0].amount
243- let validatorAddress = valueOrErrorMessage(getBinary(keyValidator), errUninitialized)
244- let fee = getFee(amount, assetIdStr)
245- let amountWithoutFee = (amount - fee)
246- if ((0 >= amountWithoutFee))
247- then throw(errNotEnoughBalance)
248- else {
249- let assetSourceAndAddress = valueOrErrorMessage(getBinary((assetIdStr + keyAssetAddress)), errAssetNotFound)
250- let type = valueOrErrorMessage(getInteger((assetIdStr + keyAssetType)), errAssetNotFound)
251- let precision = valueOrErrorMessage(getInteger((assetIdStr + keyAssetPrecision)), errAssetNotFound)
252- let feeCollector = valueOrErrorMessage(getBinary(keyFeeCollector), errUninitialized)
253- let createLock = invoke(Address(validatorAddress), "createLock", [lockId, recipient, toSystemPrecision(amountWithoutFee, precision), destination, assetSourceAndAddress], nil)
254- if ((createLock == createLock))
255- then if ((type == typeBase))
256- then [ScriptTransfer(Address(feeCollector), fee, unit)]
257- else if ((type == typeNative))
258- then [ScriptTransfer(Address(feeCollector), fee, assetId)]
259- else if ((type == typeWrapped))
260- then [Burn(assetId, amountWithoutFee), ScriptTransfer(Address(feeCollector), fee, assetId)]
261- else throw(errInvalidValues)
262- else throw("Strict value is not equal to itself.")
263- }
264- }
265- else throw("Strict value is not equal to itself.")
266- }
267- else throw("Strict value is not equal to itself.")
268- }
269-
270-
271-
272-@Callable(i)
273-func unlock (lockId,recipient,amount,lockSource,assetSourceAndAddress,signature) = {
274- let birdgeCheck = assertBridgeIsActive()
275- if ((birdgeCheck == birdgeCheck))
276- then {
277- let assetId = valueOrErrorMessage(getBinary((toBase64String(assetSourceAndAddress) + keyAssetAddress)), errAssetNotFound)
278- let assetIdStr = toBase64String(assetId)
279- let type = valueOrErrorMessage(getInteger((assetIdStr + keyAssetType)), errAssetNotFound)
280- let precision = valueOrErrorMessage(getInteger((assetIdStr + keyAssetPrecision)), errAssetNotFound)
281- let validatorAddress = valueOrErrorMessage(getBinary(keyValidator), errUninitialized)
282- let unlockSigner = valueOrErrorMessage(getBinary(keyUnlockSigner), errUninitialized)
283- let feeCollector = valueOrErrorMessage(getBinary(keyFeeCollector), errUninitialized)
284- let createUnlock = invoke(Address(validatorAddress), "createUnlock", [lockId, recipient, amount, lockSource, assetSourceAndAddress, signature], nil)
285- if ((createUnlock == createUnlock))
286- then {
287- let isValid = match createUnlock {
288- case v: Boolean =>
289- v
290- case _ =>
291- false
292- }
293- if (!(isValid))
294- then throw(errInvalidValues)
85+ let lockIdStr = toBase64String(lockId)
86+ let lockSourceStr = toBase64String(lockSource)
87+ let unlockKey = (((lockSourceStr + "_") + lockIdStr) + keyUnlock)
88+ if (isDefined(getBoolean(unlockKey)))
89+ then throw(errAlreadyClaimed)
29590 else {
296- let fee = if ((unlockSigner == i.caller.bytes))
297- then valueOrErrorMessage(getInteger((assetIdStr + keyAssetMinFee)), errAssetNotFound)
298- else 0
299- let amountToSend = fromSystemPrecision(amount, precision)
300- let amountToSendWithoutFee = (amountToSend - fee)
301- if ((0 >= amountToSendWithoutFee))
302- then throw(errNotEnoughBalance)
303- else if ((type == typeBase))
304- then ([ScriptTransfer(Address(recipient), amountToSendWithoutFee, unit)] ++ (if ((fee > 0))
305- then [ScriptTransfer(Address(feeCollector), fee, unit)]
306- else nil))
307- else if ((type == typeNative))
308- then ([ScriptTransfer(Address(recipient), amountToSendWithoutFee, assetId)] ++ (if ((fee > 0))
309- then [ScriptTransfer(Address(feeCollector), fee, assetId)]
310- else nil))
311- else if ((type == typeWrapped))
312- then ([Reissue(assetId, amountToSend, true), ScriptTransfer(Address(recipient), amountToSendWithoutFee, assetId)] ++ (if ((fee > 0))
313- then [ScriptTransfer(Address(feeCollector), fee, assetId)]
314- else nil))
315- else throw(errInvalidValues)
91+ let message = makeString([lockIdStr, toBase64String(recipient), toString(amount), lockSourceStr, toBase64String(tokenSourceAndAddress), chainWaves], "_")
92+ let hash = keccak256(toBytes(message))
93+ let recoveredKey = ecrecover(hash, signature)
94+ if ((recoveredKey != getBinaryValue(keyOracle)))
95+ then throw(errInvalidSignature)
96+ else $Tuple2([BooleanEntry(unlockKey, true)], true)
31697 }
31798 }
31899 else throw("Strict value is not equal to itself.")
319100 }
320101 else throw("Strict value is not equal to itself.")
321102 }
322103
323104
324105
325106 @Callable(i)
326-func setManager (managerType,manager) = {
327- let callerCheck = assertCallerIsManager(i, BRIDGE_MANAGER)
328- if ((callerCheck == callerCheck))
329- then [BinaryEntry((managerType + keyManager), manager)]
330- else throw("Strict value is not equal to itself.")
331- }
332-
333-
334-
335-@Callable(i)
336-func setFeeCollector (feeCollector) = {
337- let callerCheck = assertCallerIsManager(i, BRIDGE_MANAGER)
338- if ((callerCheck == callerCheck))
339- then [BinaryEntry(keyFeeCollector, feeCollector)]
340- else throw("Strict value is not equal to itself.")
341- }
342-
343-
344-
345-@Callable(i)
346-func setValidator (validator) = {
347- let callerCheck = assertCallerIsManager(i, BRIDGE_MANAGER)
348- if ((callerCheck == callerCheck))
349- then [BinaryEntry(keyValidator, validator)]
350- else throw("Strict value is not equal to itself.")
351- }
352-
353-
354-
355-@Callable(i)
356-func startBridge () = {
357- let callerCheck = assertCallerIsManager(i, BRIDGE_MANAGER)
358- if ((callerCheck == callerCheck))
359- then [BooleanEntry(keyIsActive, true)]
360- else throw("Strict value is not equal to itself.")
361- }
362-
363-
364-
365-@Callable(i)
366-func stopBridge () = {
367- let callerCheck = assertCallerIsManager(i, STOP_MANAGER)
368- if ((callerCheck == callerCheck))
369- then [BooleanEntry(keyIsActive, false)]
370- else throw("Strict value is not equal to itself.")
371- }
372-
373-
374-
375-@Callable(i)
376-func setMinFee (assetId,minFee) = {
377- let callerCheck = assertCallerIsManager(i, ASSET_MANAGER)
378- if ((callerCheck == callerCheck))
107+func createLock (lockId,recipient,amount,lockDestination,assetSourceAndAddress) = {
108+ let lockIdStr = toBase64String(lockId)
109+ let lockRecipientKey = (lockIdStr + keyLockRecipient)
110+ let checkCaller = assertCallerIsBridge(i)
111+ if ((checkCaller == checkCaller))
379112 then {
380- let assetIdStr = toBase64String(assetId)
381-[IntegerEntry((assetIdStr + keyAssetMinFee), minFee)]
113+ let checkLockId = assertValidLockId(lockId)
114+ if ((checkLockId == checkLockId))
115+ then {
116+ let checkLock = assertLockNotExists(lockRecipientKey)
117+ if ((checkLock == checkLock))
118+ then [BinaryEntry((lockIdStr + keyLockRecipient), recipient), IntegerEntry((lockIdStr + keyLockAmount), amount), BinaryEntry((lockIdStr + keyLockDestination), lockDestination), BinaryEntry((lockIdStr + keyLockAssetSource), assetSourceAndAddress)]
119+ else throw("Strict value is not equal to itself.")
120+ }
121+ else throw("Strict value is not equal to itself.")
382122 }
383123 else throw("Strict value is not equal to itself.")
384124 }
385125
386126
387127
388128 @Callable(i)
389-func setBaseFeeRate (baseFeeRateBP) = {
390- let callerCheck = assertCallerIsManager(i, ASSET_MANAGER)
391- if ((callerCheck == callerCheck))
392- then [IntegerEntry(keyBaseFeeRateBP, baseFeeRateBP)]
129+func setAdmin (newAdmin) = {
130+ let checkCaller = assertCallerIsAdmin(i)
131+ if ((checkCaller == checkCaller))
132+ then [BinaryEntry(keyAdmin, newAdmin)]
393133 else throw("Strict value is not equal to itself.")
394134 }
395135
396136
397137
398138 @Callable(i)
399-func setAssetState (assetId,state) = {
400- let callerCheck = assertCallerIsManager(i, ASSET_MANAGER)
401- if ((callerCheck == callerCheck))
402- then {
403- let assetIdStr = toBase64String(assetId)
404-[BooleanEntry((assetIdStr + keyAssetIsActive), state)]
405- }
139+func setOracle (newOracle) = {
140+ let checkCaller = assertCallerIsAdmin(i)
141+ if ((checkCaller == checkCaller))
142+ then [BinaryEntry(keyOracle, newOracle)]
143+ else throw("Strict value is not equal to itself.")
144+ }
145+
146+
147+
148+@Callable(i)
149+func setBridge (newBridge) = {
150+ let checkCaller = assertCallerIsAdmin(i)
151+ if ((checkCaller == checkCaller))
152+ then [BinaryEntry(keyBridge, newBridge)]
406153 else throw("Strict value is not equal to itself.")
407154 }
408155
409156

github/deemru/w8io/169f3d6 
46.22 ms