tx · 7zMtizKKWVwmCzdhAoDQDZMLsQtpDkNqCJtBVHZKNYe2

3N88HLHyQgayARc6MXuoJgYJM6Hp9q8AD4X:  -0.01000000 Waves

2021.06.25 11:48 [1585676] smart account 3N88HLHyQgayARc6MXuoJgYJM6Hp9q8AD4X > SELF 0.00000000 Waves

{ "type": 13, "id": "7zMtizKKWVwmCzdhAoDQDZMLsQtpDkNqCJtBVHZKNYe2", "fee": 1000000, "feeAssetId": null, "timestamp": 1624610866721, "version": 2, "chainId": 84, "sender": "3N88HLHyQgayARc6MXuoJgYJM6Hp9q8AD4X", "senderPublicKey": "7d8ot6oQCGQZb8ATJ6U8KciEiWMyGupkrdYRjcoRfNzs", "proofs": [ "46AcCxf9EL63EpqSXSZLS8RZ3CbNsHN82P7VychUK17ckZvs9ZK5CtYSe8DqnWf3Ww2kEWFQUm7RUPdcMxAcfAdW" ], "script": "base64:AAIEAAAAAAAAACAIAhIECgIBCBIECgIBCBIECgIBCBIECgIBCBIECgIBCAAAAAQBAAAACmdldEFzc2V0SUQAAAABAAAABWFzc2V0BAAAAAdhc3NldElEAwkAAAAAAAACBQAAAAVhc3NldAIAAAAAAgAAAAADCQAAAAAAAAIFAAAABWFzc2V0AgAAAARVU0ROAgAAACwzS0ZYQkdHTENqQTVaMkR1VzREcTlmRERySGpKSlAxWkVrYW9halN6dUtzQwkAAAIAAAABAgAAABFVbnN1cHBvcnRlZCBhc3NldAUAAAAHYXNzZXRJRAEAAAAQZ2V0RGVwb3NpdEFtb3VudAAAAAIAAAAJcHVibGljS2V5AAAABWFzc2V0BAAAAAl1c2VkQXNzZXQDCQAAAAAAAAIFAAAABWFzc2V0AgAAAAACAAAABVdBVkVTBQAAAAVhc3NldAQAAAAHYmFsYW5jZQQAAAAHJG1hdGNoMAkABBoAAAACBQAAAAR0aGlzCQABLAAAAAIJAAEsAAAAAgkAASwAAAACAgAAAAhkZXBvc2l0XwUAAAAJcHVibGljS2V5AgAAAAFfBQAAAAl1c2VkQXNzZXQD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hbGxlclB1YmxpY0tleQQAAAAKY3VycmVudERlcAkBAAAAEGdldERlcG9zaXRBbW91bnQAAAACBQAAAAlwdWJsaWNLZXkFAAAACXVzZWRBc3NldAMJAABmAAAAAgAAAAAAAAAAAAUAAAAGYW1vdW50CQAAAgAAAAECAAAAHkNhbid0IHdpdGhkcmF3IG5lZ2F0aXZlIGFtb3VudAMDCQAAZgAAAAIFAAAACmN1cnJlbnREZXAAAAAAAAAAAAAJAABnAAAAAgUAAAAKY3VycmVudERlcAUAAAAGYW1vdW50BwkABEwAAAACCQEAAAAMSW50ZWdlckVudHJ5AAAAAgkAASwAAAACCQABLAAAAAIJAAEsAAAAAgIAAAAIZGVwb3NpdF8FAAAACXB1YmxpY0tleQIAAAABXwUAAAAJdXNlZEFzc2V0CQAAZQAAAAIFAAAACmN1cnJlbnREZXAFAAAABmFtb3VudAkABEwAAAACCQEAAAAOU2NyaXB0VHJhbnNmZXIAAAADBQAAABR0cmFuc2FjdGlvblB1YmxpY0tleQUAAAAGYW1vdW50CAUAAAABaQAAAApmZWVBc3NldElkBQAAAANuaWwJAAACAAAAAQIAAAATTm90aGluZyB0byB3aXRoZHJhdwAAAAEAAAACdHgBAAAABnZlcmlmeQAAAAAEAAAAByRtYXRjaDAFAAAAAnR4AwkAAAEAAAACBQAAAAckbWF0Y2gwAgAAAA9EYXRhVHJhbnNhY3Rpb24GAwkAAAEAAAACBQAAAAckbWF0Y2gwAgAAABRTZXRTY3JpcHRUcmFuc2FjdGlvbgYG8isTqA==", "height": 1585676, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: ABqEYGbmUNvS8kZB9cxC4dRR1m4c4VbPf5NV9hpRvzBU Next: none Diff:
OldNewDifferences
11 {-# STDLIB_VERSION 4 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
4+func getAssetID (asset) = {
5+ let assetID = if ((asset == ""))
6+ then ""
7+ else if ((asset == "USDN"))
8+ then "3KFXBGGLCjA5Z2DuW4Dq9fDDrHjJJP1ZEkaoajSzuKsC"
9+ else throw("Unsupported asset")
10+ assetID
11+ }
12+
13+
414 func getDepositAmount (publicKey,asset) = {
5- let balance = match getInteger(this, ((("deposit_" + publicKey) + "_") + asset)) {
15+ let usedAsset = if ((asset == ""))
16+ then "WAVES"
17+ else asset
18+ let balance = match getInteger(this, ((("deposit_" + publicKey) + "_") + usedAsset)) {
619 case a: Int =>
720 a
821 case _ =>
1326
1427
1528 func getBorrowAmount (publicKey,asset) = {
16- let balance = match getInteger(this, ((("borrow_" + publicKey) + "_") + asset)) {
29+ let usedAsset = if ((asset == ""))
30+ then "WAVES"
31+ else asset
32+ let balance = match getInteger(this, ((("borrow_" + publicKey) + "_") + usedAsset)) {
1733 case a: Int =>
1834 a
1935 case _ =>
2339 }
2440
2541
26-func getCollateral (publicKey,asset) = if ((asset == ""))
27- then {
28- let collateral = match getInteger(this, ((("collateral_" + publicKey) + "_Waves") + asset)) {
29- case a: Int =>
30- a
31- case _ =>
32- 0
33- }
34- collateral
35- }
36- else {
37- let collateral = match getInteger(this, ((("collateral_" + publicKey) + "_") + asset)) {
38- case a: Int =>
39- a
40- case _ =>
41- 0
42- }
43- collateral
44- }
42+func getCollateral (publicKey,asset) = {
43+ let usedAsset = if ((asset == ""))
44+ then "WAVES"
45+ else asset
46+ let collateral = match getInteger(this, ((("collateral_" + publicKey) + "_") + usedAsset)) {
47+ case a: Int =>
48+ a
49+ case _ =>
50+ 0
51+ }
52+ collateral
53+ }
4554
4655
4756 @Callable(i)
4857 func deposit (amount,asset) = {
4958 let publicKey = toBase58String(i.callerPublicKey)
50- let test = if ((asset == ""))
59+ let usedAsset = if ((asset == ""))
5160 then "WAVES"
5261 else asset
53- let depositAmount = getDepositAmount(publicKey, test)
62+ let depositAmount = getDepositAmount(publicKey, usedAsset)
5463 let newDepositAmount = (depositAmount + amount)
55-[IntegerEntry(((("deposit_" + publicKey) + "_") + test), newDepositAmount)]
64+[IntegerEntry(((("deposit_" + publicKey) + "_") + usedAsset), newDepositAmount)]
5665 }
5766
5867
5968
6069 @Callable(i)
6170 func depositCollateral (amount,asset) = {
71+ let usedAsset = if ((asset == ""))
72+ then "WAVES"
73+ else asset
6274 let publicKey = toBase58String(i.callerPublicKey)
63- let collateralAmount = getCollateral(publicKey, asset)
75+ let collateralAmount = getCollateral(publicKey, usedAsset)
6476 let newCollateralAmount = (collateralAmount + amount)
65-[IntegerEntry(((("collateral_" + publicKey) + "_") + asset), newCollateralAmount)]
77+ if ((0 >= amount))
78+ then throw("Ammount must be bigger than 0")
79+ else [IntegerEntry(((("collateral_" + publicKey) + "_") + usedAsset), newCollateralAmount)]
6680 }
6781
6882
6983
7084 @Callable(i)
7185 func borrow (amount,asset) = {
86+ let usedAsset = if ((asset == ""))
87+ then "WAVES"
88+ else asset
7289 let publicKey = toBase58String(i.callerPublicKey)
73- let borrowAmount = getBorrowAmount(publicKey, asset)
74- let collateral = getCollateral(publicKey, asset)
90+ let transactionPublicKey = addressFromPublicKey(i.callerPublicKey)
91+ let borrowAmount = getBorrowAmount(publicKey, usedAsset)
92+ let collateral = getCollateral(publicKey, usedAsset)
7593 let maxBorrowAmount = ((collateral * 70) / 100)
7694 let newBorrowAmount = (borrowAmount + amount)
95+ let usedAssetID = getAssetID(asset)
7796 if ((collateral >= maxBorrowAmount))
78- then [IntegerEntry(((("borrow_" + publicKey) + "_") + asset), newBorrowAmount)]
97+ then [IntegerEntry(((("borrow_" + publicKey) + "_") + usedAsset), newBorrowAmount), ScriptTransfer(Address(toBytes(toBase58String(i.callerPublicKey))), amount, toBytes(usedAssetID))]
7998 else throw("Not enough collateral")
8099 }
81100
83102
84103 @Callable(i)
85104 func repay (amount,asset) = {
105+ let usedAsset = if ((asset == ""))
106+ then "WAVES"
107+ else asset
86108 let publicKey = toBase58String(i.callerPublicKey)
87- let currentBorr = getBorrowAmount(publicKey, asset)
109+ let currentBorr = getBorrowAmount(publicKey, usedAsset)
88110 if ((currentBorr > 0))
89- then [IntegerEntry(((("borrow_" + publicKey) + "_") + asset), (currentBorr - amount))]
90- else throw("Nothing to repay")
111+ then [IntegerEntry(((("borrow_" + publicKey) + "_") + usedAsset), (currentBorr - amount))]
112+ else [IntegerEntry(((("collateral_" + publicKey) + "_") + usedAsset), amount), throw("Nothing to repay, your Ammount has been deposit as Collateral")]
91113 }
92114
93115
94116
95117 @Callable(i)
96118 func withdraw (amount,asset) = {
119+ let usedAsset = if ((asset == ""))
120+ then "WAVES"
121+ else asset
97122 let publicKey = toBase58String(i.callerPublicKey)
98- let currentDep = getDepositAmount(publicKey, asset)
99- if ((currentDep > 0))
100- then [IntegerEntry(((("deposit_" + publicKey) + "_") + asset), (currentDep - amount))]
101- else throw("Nothing to withdraw")
123+ let transactionPublicKey = addressFromPublicKey(i.callerPublicKey)
124+ let currentDep = getDepositAmount(publicKey, usedAsset)
125+ if ((0 > amount))
126+ then throw("Can't withdraw negative amount")
127+ else if (if ((currentDep > 0))
128+ then (currentDep >= amount)
129+ else false)
130+ then [IntegerEntry(((("deposit_" + publicKey) + "_") + usedAsset), (currentDep - amount)), ScriptTransfer(transactionPublicKey, amount, i.feeAssetId)]
131+ else throw("Nothing to withdraw")
102132 }
103133
104134
Full:
OldNewDifferences
11 {-# STDLIB_VERSION 4 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
4+func getAssetID (asset) = {
5+ let assetID = if ((asset == ""))
6+ then ""
7+ else if ((asset == "USDN"))
8+ then "3KFXBGGLCjA5Z2DuW4Dq9fDDrHjJJP1ZEkaoajSzuKsC"
9+ else throw("Unsupported asset")
10+ assetID
11+ }
12+
13+
414 func getDepositAmount (publicKey,asset) = {
5- let balance = match getInteger(this, ((("deposit_" + publicKey) + "_") + asset)) {
15+ let usedAsset = if ((asset == ""))
16+ then "WAVES"
17+ else asset
18+ let balance = match getInteger(this, ((("deposit_" + publicKey) + "_") + usedAsset)) {
619 case a: Int =>
720 a
821 case _ =>
922 0
1023 }
1124 balance
1225 }
1326
1427
1528 func getBorrowAmount (publicKey,asset) = {
16- let balance = match getInteger(this, ((("borrow_" + publicKey) + "_") + asset)) {
29+ let usedAsset = if ((asset == ""))
30+ then "WAVES"
31+ else asset
32+ let balance = match getInteger(this, ((("borrow_" + publicKey) + "_") + usedAsset)) {
1733 case a: Int =>
1834 a
1935 case _ =>
2036 0
2137 }
2238 balance
2339 }
2440
2541
26-func getCollateral (publicKey,asset) = if ((asset == ""))
27- then {
28- let collateral = match getInteger(this, ((("collateral_" + publicKey) + "_Waves") + asset)) {
29- case a: Int =>
30- a
31- case _ =>
32- 0
33- }
34- collateral
35- }
36- else {
37- let collateral = match getInteger(this, ((("collateral_" + publicKey) + "_") + asset)) {
38- case a: Int =>
39- a
40- case _ =>
41- 0
42- }
43- collateral
44- }
42+func getCollateral (publicKey,asset) = {
43+ let usedAsset = if ((asset == ""))
44+ then "WAVES"
45+ else asset
46+ let collateral = match getInteger(this, ((("collateral_" + publicKey) + "_") + usedAsset)) {
47+ case a: Int =>
48+ a
49+ case _ =>
50+ 0
51+ }
52+ collateral
53+ }
4554
4655
4756 @Callable(i)
4857 func deposit (amount,asset) = {
4958 let publicKey = toBase58String(i.callerPublicKey)
50- let test = if ((asset == ""))
59+ let usedAsset = if ((asset == ""))
5160 then "WAVES"
5261 else asset
53- let depositAmount = getDepositAmount(publicKey, test)
62+ let depositAmount = getDepositAmount(publicKey, usedAsset)
5463 let newDepositAmount = (depositAmount + amount)
55-[IntegerEntry(((("deposit_" + publicKey) + "_") + test), newDepositAmount)]
64+[IntegerEntry(((("deposit_" + publicKey) + "_") + usedAsset), newDepositAmount)]
5665 }
5766
5867
5968
6069 @Callable(i)
6170 func depositCollateral (amount,asset) = {
71+ let usedAsset = if ((asset == ""))
72+ then "WAVES"
73+ else asset
6274 let publicKey = toBase58String(i.callerPublicKey)
63- let collateralAmount = getCollateral(publicKey, asset)
75+ let collateralAmount = getCollateral(publicKey, usedAsset)
6476 let newCollateralAmount = (collateralAmount + amount)
65-[IntegerEntry(((("collateral_" + publicKey) + "_") + asset), newCollateralAmount)]
77+ if ((0 >= amount))
78+ then throw("Ammount must be bigger than 0")
79+ else [IntegerEntry(((("collateral_" + publicKey) + "_") + usedAsset), newCollateralAmount)]
6680 }
6781
6882
6983
7084 @Callable(i)
7185 func borrow (amount,asset) = {
86+ let usedAsset = if ((asset == ""))
87+ then "WAVES"
88+ else asset
7289 let publicKey = toBase58String(i.callerPublicKey)
73- let borrowAmount = getBorrowAmount(publicKey, asset)
74- let collateral = getCollateral(publicKey, asset)
90+ let transactionPublicKey = addressFromPublicKey(i.callerPublicKey)
91+ let borrowAmount = getBorrowAmount(publicKey, usedAsset)
92+ let collateral = getCollateral(publicKey, usedAsset)
7593 let maxBorrowAmount = ((collateral * 70) / 100)
7694 let newBorrowAmount = (borrowAmount + amount)
95+ let usedAssetID = getAssetID(asset)
7796 if ((collateral >= maxBorrowAmount))
78- then [IntegerEntry(((("borrow_" + publicKey) + "_") + asset), newBorrowAmount)]
97+ then [IntegerEntry(((("borrow_" + publicKey) + "_") + usedAsset), newBorrowAmount), ScriptTransfer(Address(toBytes(toBase58String(i.callerPublicKey))), amount, toBytes(usedAssetID))]
7998 else throw("Not enough collateral")
8099 }
81100
82101
83102
84103 @Callable(i)
85104 func repay (amount,asset) = {
105+ let usedAsset = if ((asset == ""))
106+ then "WAVES"
107+ else asset
86108 let publicKey = toBase58String(i.callerPublicKey)
87- let currentBorr = getBorrowAmount(publicKey, asset)
109+ let currentBorr = getBorrowAmount(publicKey, usedAsset)
88110 if ((currentBorr > 0))
89- then [IntegerEntry(((("borrow_" + publicKey) + "_") + asset), (currentBorr - amount))]
90- else throw("Nothing to repay")
111+ then [IntegerEntry(((("borrow_" + publicKey) + "_") + usedAsset), (currentBorr - amount))]
112+ else [IntegerEntry(((("collateral_" + publicKey) + "_") + usedAsset), amount), throw("Nothing to repay, your Ammount has been deposit as Collateral")]
91113 }
92114
93115
94116
95117 @Callable(i)
96118 func withdraw (amount,asset) = {
119+ let usedAsset = if ((asset == ""))
120+ then "WAVES"
121+ else asset
97122 let publicKey = toBase58String(i.callerPublicKey)
98- let currentDep = getDepositAmount(publicKey, asset)
99- if ((currentDep > 0))
100- then [IntegerEntry(((("deposit_" + publicKey) + "_") + asset), (currentDep - amount))]
101- else throw("Nothing to withdraw")
123+ let transactionPublicKey = addressFromPublicKey(i.callerPublicKey)
124+ let currentDep = getDepositAmount(publicKey, usedAsset)
125+ if ((0 > amount))
126+ then throw("Can't withdraw negative amount")
127+ else if (if ((currentDep > 0))
128+ then (currentDep >= amount)
129+ else false)
130+ then [IntegerEntry(((("deposit_" + publicKey) + "_") + usedAsset), (currentDep - amount)), ScriptTransfer(transactionPublicKey, amount, i.feeAssetId)]
131+ else throw("Nothing to withdraw")
102132 }
103133
104134
105135 @Verifier(tx)
106136 func verify () = match tx {
107137 case _: DataTransaction =>
108138 true
109139 case _: SetScriptTransaction =>
110140 true
111141 case _ =>
112142 true
113143 }
114144

github/deemru/w8io/169f3d6 
61.29 ms