tx · 7F3oKDBJhPxdGDuBUd7oxcez4FMhv9kRn53FCmBGSJro 3NBG2Nuz2cjtG8wWcKLBGZ1bBpveU56gp77: -0.04000000 Waves 2021.09.05 03:14 [1689005] smart account 3NBG2Nuz2cjtG8wWcKLBGZ1bBpveU56gp77 > SELF 0.00000000 Waves
{ "type": 13, "id": "7F3oKDBJhPxdGDuBUd7oxcez4FMhv9kRn53FCmBGSJro", "fee": 4000000, "feeAssetId": null, "timestamp": 1630800898883, "version": 2, "chainId": 84, "sender": "3NBG2Nuz2cjtG8wWcKLBGZ1bBpveU56gp77", "senderPublicKey": "B565vUqaobfDQJcgjUnNdsSqnqWfRsAQDBb1JeciPWtP", "proofs": [ "3gPyTW21kzjF4ub8DTGt7aEgkduuAdDHYiGnHcGCDeZXvSRbrtiuwkpeWVduErvFS78wJ66diWWmGroPKQf6t9jQ" ], "script": "base64:AAIFAAAAAAAAACkIAhIFCgMICAESBAoCCBgSAwoBCBIDCgEIEgQKAggEEgMKAQgSAwoBCAAAAAwAAAAABmNvbmZpZwkBAAAAC3ZhbHVlT3JFbHNlAAAAAgkBAAAAEUBleHRyTmF0aXZlKDEwNTMpAAAAAgUAAAAEdGhpcwIAAAAGY29uZmlnAgAAAAAAAAAABWFkbWluCQEAAAALdmFsdWVPckVsc2UAAAACCQEAAAARQGV4dHJOYXRpdmUoMTA1MykAAAACCQEAAAARQGV4dHJOYXRpdmUoMTA2MikAAAABBQAAAAZjb25maWcCAAAABWFkbWluAgAAAAAAAAAABXBvb2xzCQEAAAALdmFsdWVPckVsc2UAAAACCQEAAAARQGV4dHJOYXRpdmUoMTA1MykAAAACBQAAAAR0aGlzAgAAAAVwb29scwIAAAAAAQAAAAdpc0FkbWluAAAAAQAAAA1jYWxsZXJBZGRyZXNzAwkAAAAAAAACBQAAAA1jYWxsZXJBZGRyZXNzCQEAAAARQGV4dHJOYXRpdmUoMTA2MikAAAABBQAAAAVhZG1pbgYHAQAAAAljaGVja1Bvb2wAAAABAAAAB3B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0ZXMEAAAAA21zZwkAA/wAAAAECQEAAAARQGV4dHJOYXRpdmUoMTA2MikAAAABBQAAAAtwb29sQWRkcmVzcwIAAAAQbG9ja0FzQ29sbGF0ZXJhbAkABEwAAAACBQAAAAR1c2VyBQAAAANuaWwIBQAAAAFpAAAACHBheW1lbnRzAwkAAAAAAAACBQAAAANtc2cFAAAAA21zZwQAAAAHJG1hdGNoMAUAAAADbXNnAwkAAAEAAAACBQAAAAckbWF0Y2gwAgAAAAZTdHJpbmcEAAAAAXQFAAAAByRtYXRjaDAFAAAAA25pbAkAAAIAAAABAgAAABhJbmNvcnJlY3QgaW52b2tlIHJlc3VsdCEJAAACAAAAAQIAAAAkU3RyaWN0IHZhbHVlIGlzIG5vdCBlcXVhbCB0byBpdHNlbGYuCQAAAgAAAAECAAAAFE5vIHBheW1lbnQgYXR0YWNoZWQhCQAAAgAAAAECAAAAF0Fzc2V0SWRzIGRvZXMgbm90IG1hdGNoCQAAAgAAAAECAAAAF1Bvb2wgYWRkcmVzcyBub3QgZm91bmQhAAAAAPFxhck=", "height": 1689005, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: AXmDmZ8d96sAcx7UsXAbM1BdTXeAZhNeR2UFfTz2dmZw Next: 57ua4u22SQs3cUXMUhy785myJZiou6kKvwHSKr7FQKxb Diff:
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 5 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | - | let | |
4 | + | let config = valueOrElse(getStringValue(this, "config"), "") | |
5 | 5 | ||
6 | - | let | |
6 | + | let admin = valueOrElse(getStringValue(addressFromStringValue(config), "admin"), "") | |
7 | 7 | ||
8 | - | let | |
8 | + | let pools = valueOrElse(getStringValue(this, "pools"), "") | |
9 | 9 | ||
10 | - | let config = valueOrElse(getString(this, "configAddress"), "") | |
11 | - | ||
12 | - | let admin = valueOrElse(getString(addressFromStringValue(config), "admin"), "") | |
13 | - | ||
14 | - | let wavetroller = valueOrElse(getString(addressFromStringValue(config), "wavetroller"), "") | |
15 | - | ||
16 | - | let oracle = valueOrElse(getString(addressFromStringValue(config), "oracle"), "") | |
17 | - | ||
18 | - | let assetIdSub = valueOrErrorMessage(getString(this, "assetId"), "No assetId could be found in data storage!") | |
19 | - | ||
20 | - | let assetDecimals = valueOrErrorMessage(getInteger(addressFromStringValue(config), (assetIdSub + "_Decimals")), (("No key " + (assetIdSub + "_Decimals")) + " was found")) | |
21 | - | ||
22 | - | let multiplier = valueOrErrorMessage(getInteger(addressFromStringValue(config), (assetIdSub + "_Multiplier")), (("No key " + (assetIdSub + "_Multiplier")) + " was found")) | |
23 | - | ||
24 | - | let kink = valueOrErrorMessage(getInteger(addressFromStringValue(config), (assetIdSub + "_Kink")), (("No key " + (assetIdSub + "_Kink")) + " was found")) | |
25 | - | ||
26 | - | let jumpMultiplier = valueOrErrorMessage(getInteger(addressFromStringValue(config), (assetIdSub + "_JumpMultiplier")), (("No key " + (assetIdSub + "_JumpMultiplier")) + " was found")) | |
27 | - | ||
28 | - | let baseRate = valueOrErrorMessage(getInteger(addressFromStringValue(config), (assetIdSub + "_BaseRate")), (("No key " + (assetIdSub + "_BaseRate")) + " was found")) | |
29 | - | ||
30 | - | let baseExchangeRate = valueOrErrorMessage(getInteger(this, "baseExchangeRate"), "No key baseExchangeRate was found") | |
31 | - | ||
32 | - | let collateralFactor = valueOrErrorMessage(getInteger(addressFromStringValue(config), (assetIdSub + "_CollateralFactor")), (("No key " + (assetIdSub + "_CollateralFactor")) + " was found")) | |
33 | - | ||
34 | - | let liquidationThreshold = valueOrErrorMessage(getInteger(addressFromStringValue(config), (assetIdSub + "_Threshold")), (("No key " + (assetIdSub + "_Threshold")) + " was found")) | |
35 | - | ||
36 | - | let reserveFactor = valueOrErrorMessage(getInteger(addressFromStringValue(config), (assetIdSub + "_ReserveFactor")), (("No key " + (assetIdSub + "_ReserveFactor")) + " was found")) | |
37 | - | ||
38 | - | let totalBorrow = valueOrElse(getInteger(this, "totalBorrow"), 0) | |
39 | - | ||
40 | - | let totalSupply = valueOrElse(getInteger(this, "totalSupply"), 0) | |
41 | - | ||
42 | - | let totalReserve = valueOrElse(getInteger(this, "totalReserve"), 0) | |
43 | - | ||
44 | - | let dTokenSupply = valueOrErrorMessage(getInteger(this, "dTokenSupply"), "No key dTokenSupply was found") | |
45 | - | ||
46 | - | let dTokenDecimals = valueOrErrorMessage(getInteger(this, "dTokenDecimals"), "No key dTokenDecimals was found") | |
47 | - | ||
48 | - | let dTokenId = valueOrErrorMessage(getString(this, "dTokenId"), "No key dTokenId was found") | |
49 | - | ||
50 | - | let dTokenName = valueOrErrorMessage(getString(this, "dTokenName"), "No key dTokenName was found") | |
51 | - | ||
52 | - | let storedHeight = valueOrElse(getInteger(this, "storedHeight"), height) | |
53 | - | ||
54 | - | let storedIndex = valueOrElse(getInteger(this, "storedIndex"), 10000000000000000) | |
55 | - | ||
56 | - | func isAdminAddress (address) = if ((addressFromStringValue(admin) == address)) | |
10 | + | func isAdmin (callerAddress) = if ((callerAddress == addressFromStringValue(admin))) | |
57 | 11 | then true | |
58 | 12 | else false | |
59 | 13 | ||
60 | 14 | ||
61 | - | func isWavetroller (address) = if ((addressFromStringValue(wavetroller) == address)) | |
62 | - | then true | |
63 | - | else false | |
64 | - | ||
65 | - | ||
66 | - | func isAcceptableAssetId (assetId) = if ((assetId == assetIdSub)) | |
15 | + | func checkPool (poolAdd) = if (contains(pools, poolAdd)) | |
67 | 16 | then true | |
68 | 17 | else false | |
69 | 18 | ||
74 | 23 | func writeInteger (key,integerValue) = IntegerEntry(key, integerValue) | |
75 | 24 | ||
76 | 25 | ||
77 | - | func userlockedBalance (userAddress) = valueOrElse(getInteger(this, (userAddress + "_locked")), 0) | |
78 | - | ||
79 | - | ||
80 | - | let utilization = if ((totalSupply > 0)) | |
81 | - | then fraction(totalBorrow, baseFactor, totalSupply) | |
82 | - | else 0 | |
83 | - | ||
84 | - | let apr = { | |
85 | - | let minValue = [utilization, kink] | |
86 | - | let minValueItem = min(minValue) | |
87 | - | let maxValue = [0, (utilization - kink)] | |
88 | - | let maxValueItem = max(maxValue) | |
89 | - | ((fraction(multiplier, minValueItem, baseFactor) + fraction(jumpMultiplier, maxValueItem, baseFactor)) + baseRate) | |
90 | - | } | |
91 | - | ||
92 | - | let apy = fraction(fraction(apr, utilization, baseFactor), (baseFactor - reserveFactor), baseFactor) | |
93 | - | ||
94 | - | let borrowRatePerBlock = fraction(apr, baseIndex, (blocksPerYear * baseFactor)) | |
95 | - | ||
96 | - | let deltaBlocks = (height - storedHeight) | |
97 | - | ||
98 | - | let currentIndex = fraction(storedIndex, (baseIndex + (borrowRatePerBlock * deltaBlocks)), baseIndex, CEILING) | |
99 | - | ||
100 | - | let currentTotalBorrow = fraction(totalBorrow, currentIndex, storedIndex) | |
101 | - | ||
102 | - | let collectedInterest = fraction(totalBorrow, (borrowRatePerBlock * deltaBlocks), baseIndex) | |
103 | - | ||
104 | - | let currentTotalSupply = (totalSupply + fraction((baseFactor - reserveFactor), collectedInterest, baseFactor)) | |
105 | - | ||
106 | - | let currentReserve = (totalReserve + fraction(reserveFactor, collectedInterest, baseFactor)) | |
107 | - | ||
108 | - | let exchangeRate = if ((dTokenSupply > 0)) | |
109 | - | then { | |
110 | - | let exponent = ((18 - dTokenDecimals) + assetDecimals) | |
111 | - | let mantissa = pow(10, 0, exponent, 0, 0, CEILING) | |
112 | - | fraction(currentTotalSupply, mantissa, dTokenSupply) | |
113 | - | } | |
114 | - | else baseExchangeRate | |
115 | - | ||
116 | - | func calcDTokenAmount (assetAmount) = { | |
117 | - | let exponent = ((18 - dTokenDecimals) + assetDecimals) | |
118 | - | let mantissa = pow(10, 0, exponent, 0, 0, CEILING) | |
119 | - | fraction(assetAmount, mantissa, exchangeRate) | |
26 | + | func checkPoolLiquidity (poolAddress,amount) = { | |
27 | + | let totalSupply = getIntegerValue(addressFromStringValue(poolAddress), "totalSupply") | |
28 | + | let totalBorrow = getIntegerValue(addressFromStringValue(poolAddress), "totalBorrow") | |
29 | + | let availableLiquidity = (totalSupply - totalBorrow) | |
30 | + | if ((availableLiquidity >= amount)) | |
31 | + | then true | |
32 | + | else false | |
120 | 33 | } | |
121 | 34 | ||
122 | 35 | ||
123 | - | func calcAssetAmount (dTokenAmount) = { | |
124 | - | let exponent = ((18 - dTokenDecimals) + assetDecimals) | |
125 | - | let mantissa = pow(10, 0, exponent, 0, 0, CEILING) | |
126 | - | fraction(dTokenAmount, exchangeRate, mantissa) | |
36 | + | func getHealthParameter (user,poolAddress,newDebtAmount,newDebtId,collateralAmount,collateralId) = { | |
37 | + | let result = invoke(addressFromStringValue(poolAddress), "getUserHealthParameter", [user, collateralAmount, collateralId, newDebtAmount, newDebtId], nil) | |
38 | + | match result { | |
39 | + | case t: (Int, Int) => | |
40 | + | t | |
41 | + | case _ => | |
42 | + | $Tuple2(0, 0) | |
43 | + | } | |
127 | 44 | } | |
128 | 45 | ||
129 | 46 | ||
130 | - | func getCurrentUserBorrow (user) = { | |
131 | - | let storedBorrow = valueOrElse(getIntegerValue(this, (user + "_borrow")), 0) | |
132 | - | let storedBorrowIndex = valueOrElse(getIntegerValue(this, (user + "_index")), 0) | |
133 | - | if ((storedBorrowIndex > 0)) | |
134 | - | then fraction(storedBorrow, currentIndex, storedBorrowIndex) | |
135 | - | else 0 | |
47 | + | func calcHealthFactor (borrowCapacity,borrowCapacityUsed) = fraction((borrowCapacity - borrowCapacityUsed), 1000, borrowCapacity) | |
48 | + | ||
49 | + | ||
50 | + | func calcBorrowCBorrowCU (user,newDebtAmount,newDebtId,collateralAmount,collateralId) = { | |
51 | + | let poolList = split(pools, ";") | |
52 | + | let listSize = size(poolList) | |
53 | + | func foldPools (accum,next) = { | |
54 | + | let healthParams = getHealthParameter(user, next, newDebtAmount, newDebtId, collateralAmount, collateralId) | |
55 | + | match healthParams { | |
56 | + | case t: (Int, Int) => | |
57 | + | $Tuple2((accum._1 + healthParams._1), (accum._2 + healthParams._1)) | |
58 | + | case e => | |
59 | + | throw("Test") | |
60 | + | } | |
61 | + | } | |
62 | + | ||
63 | + | let $list22852319 = poolList | |
64 | + | let $size22852319 = size($list22852319) | |
65 | + | let $acc022852319 = $Tuple2(0, 0) | |
66 | + | if (($size22852319 == 0)) | |
67 | + | then $acc022852319 | |
68 | + | else { | |
69 | + | let $acc122852319 = foldPools($acc022852319, $list22852319[0]) | |
70 | + | if (($size22852319 == 1)) | |
71 | + | then $acc122852319 | |
72 | + | else { | |
73 | + | let $acc222852319 = foldPools($acc122852319, $list22852319[1]) | |
74 | + | if (($size22852319 == 2)) | |
75 | + | then $acc222852319 | |
76 | + | else { | |
77 | + | let $acc322852319 = foldPools($acc222852319, $list22852319[2]) | |
78 | + | throw("List size exceed 2") | |
79 | + | } | |
80 | + | } | |
81 | + | } | |
82 | + | } | |
83 | + | ||
84 | + | ||
85 | + | func checkUserHealth (user,newDebtAmount,newDebtId,collateralAmount,collateralId) = { | |
86 | + | let bcBcu = calcBorrowCBorrowCU(user, newDebtAmount, newDebtId, collateralAmount, collateralId) | |
87 | + | let userHealth = calcHealthFactor(bcBcu._1, bcBcu._2) | |
88 | + | if ((userHealth >= 0)) | |
89 | + | then true | |
90 | + | else false | |
136 | 91 | } | |
137 | 92 | ||
138 | 93 | ||
139 | 94 | @Callable(i) | |
140 | - | func | |
95 | + | func borrowFrom (poolAddress,assetId,amount) = if (checkPool(poolAddress)) | |
141 | 96 | then { | |
142 | - | let userLocked = valueOrElse(getIntegerValue(this, (user + "_locked")), 0) | |
143 | - | let userDTokenCollateral = if ((dTokenId == collateralId)) | |
144 | - | then (userLocked - collateralAmount) | |
145 | - | else userLocked | |
146 | - | let currentUserBorrow = if ((newDebtId == assetIdSub)) | |
147 | - | then (getCurrentUserBorrow(user) + newDebtAmount) | |
148 | - | else getCurrentUserBorrow(user) | |
149 | - | let userCollateral = calcAssetAmount(userDTokenCollateral) | |
150 | - | let assetPrice = invoke(addressFromStringValue(oracle), "getPrice", [assetIdSub], nil) | |
151 | - | match assetPrice { | |
152 | - | case t: Int => | |
153 | - | let collateralValue = fraction(collateralFactor, userCollateral, baseFactor) | |
154 | - | let mantissa = pow(10, 0, assetDecimals, 0, 0, CEILING) | |
155 | - | let bCSummand = fraction(collateralValue, t, mantissa) | |
156 | - | let borrowInUSD = fraction(currentUserBorrow, t, mantissa) | |
157 | - | let bCUSummand = fraction(borrowInUSD, baseFactor, liquidationThreshold) | |
158 | - | $Tuple2(nil, $Tuple2(bCSummand, bCUSummand)) | |
159 | - | case _ => | |
160 | - | throw("Incorrect pricing") | |
97 | + | let poolAsset = getStringValue(addressFromStringValue(poolAddress), "assetId") | |
98 | + | if ((poolAsset == assetId)) | |
99 | + | then if (checkPoolLiquidity(poolAddress, amount)) | |
100 | + | then { | |
101 | + | let user = toBase58String(i.caller.bytes) | |
102 | + | if (checkUserHealth(user, amount, assetId, 0, "")) | |
103 | + | then nil | |
104 | + | else throw("Borrow exceeds user health!") | |
105 | + | } | |
106 | + | else throw("Pool liquidity is not sufficient!") | |
107 | + | else throw("AssetIds does not match") | |
161 | 108 | } | |
162 | - | } | |
163 | - | else throw("Address does not match with wavetroller address!") | |
109 | + | else throw("Pool address not found!") | |
164 | 110 | ||
165 | 111 | ||
166 | 112 | ||
167 | 113 | @Callable(i) | |
168 | - | func deposit (user,isCollateral) = if (isWavetroller(i.caller)) | |
169 | - | then { | |
170 | - | let userTokenAmount = calcDTokenAmount(i.payments[0].amount) | |
171 | - | let currentDTokenSupply = (dTokenSupply + userTokenAmount) | |
172 | - | if (isCollateral) | |
173 | - | then { | |
174 | - | let lockedUserBalance = (userlockedBalance(user) + userTokenAmount) | |
175 | - | $Tuple2([writeInteger((user + "_locked"), lockedUserBalance), writeInteger("dTokenSupply", currentDTokenSupply), writeInteger("totalBorrow", currentTotalBorrow), writeInteger("totalSupply", (currentTotalSupply + i.payments[0].amount)), writeInteger("totalReserve", currentReserve), writeInteger("storedIndex", currentIndex), writeInteger("storedHeight", height), Reissue(fromBase58String(dTokenId), userTokenAmount, true)], ((toString(i.payments[0].amount) + dTokenName) + "were successfully locked")) | |
176 | - | } | |
177 | - | else $Tuple2([writeInteger("dTokenSupply", currentDTokenSupply), writeInteger("totalBorrow", currentTotalBorrow), writeInteger("totalSupply", (currentTotalSupply + i.payments[0].amount)), writeInteger("totalReserve", currentReserve), writeInteger("storedIndex", currentIndex), writeInteger("storedHeight", height), Reissue(fromBase58String(dTokenId), userTokenAmount, true), ScriptTransfer(i.caller, userTokenAmount, fromBase58String(dTokenId))], userTokenAmount) | |
178 | - | } | |
179 | - | else throw("Address does not match with wavetroller address!") | |
114 | + | func setup (configAddress,pools) = if (if (!(isDefined(getString(this, "config")))) | |
115 | + | then !(isDefined(getString(this, "pools"))) | |
116 | + | else false) | |
117 | + | then [writeString("config", configAddress), writeString("pools", makeString(pools, ";"))] | |
118 | + | else throw("Admin and config address already definied!") | |
180 | 119 | ||
181 | 120 | ||
182 | 121 | ||
183 | 122 | @Callable(i) | |
184 | - | func | |
123 | + | func addPool (poolAddress) = if (isAdmin(i.caller)) | |
185 | 124 | then { | |
186 | - | let | |
187 | - | | |
188 | - | | |
189 | - | | |
190 | - | ||
191 | - | | |
192 | - | else throw("Pool | |
125 | + | let poolList = split(pools, ";") | |
126 | + | if ((containsElement(poolList, poolAddress) == false)) | |
127 | + | then { | |
128 | + | let newPools = (poolList :+ poolAddress) | |
129 | + | [writeString("pools", makeString(newPools, ";"))] | |
130 | + | } | |
131 | + | else throw("Pool already exists!") | |
193 | 132 | } | |
194 | - | else throw("Address does not match with | |
133 | + | else throw("Address does not match with admin address!") | |
195 | 134 | ||
196 | 135 | ||
197 | 136 | ||
198 | 137 | @Callable(i) | |
199 | - | func lockAsCollateral (user) = if (isWavetroller(i.caller)) | |
200 | - | then { | |
201 | - | let newLockedBalance = (userlockedBalance(user) + i.payments[0].amount) | |
202 | - | $Tuple2([writeInteger((user + "_locked"), newLockedBalance), writeInteger("totalBorrow", currentTotalBorrow), writeInteger("totalSupply", currentTotalSupply), writeInteger("totalReserve", currentReserve), writeInteger("storedIndex", currentIndex), writeInteger("storedHeight", height)], ((toString(i.payments[0].amount) + dTokenName) + "were successfully locked")) | |
203 | - | } | |
204 | - | else throw("Address does not match with wavetroller address!") | |
138 | + | func updateConfig (configAddress) = if (isAdmin(i.caller)) | |
139 | + | then [writeString("config", configAddress)] | |
140 | + | else throw("Address does not match with admin address!") | |
205 | 141 | ||
206 | 142 | ||
207 | 143 | ||
208 | 144 | @Callable(i) | |
209 | - | func borrow (user,amount) = if (isWavetroller(i.caller)) | |
210 | - | then { | |
211 | - | let currentUserBorrow = getCurrentUserBorrow(user) | |
212 | - | $Tuple2([writeInteger((user + "_borrow"), (currentUserBorrow + amount)), writeInteger((user + "_index"), currentIndex), writeInteger("totalBorrow", (currentTotalBorrow + amount)), writeInteger("totalSupply", currentTotalSupply), writeInteger("totalReserve", currentReserve), writeInteger("storedIndex", currentIndex), writeInteger("storedHeight", height), if ((assetIdSub == "WAVES")) | |
213 | - | then ScriptTransfer(i.caller, amount, unit) | |
214 | - | else ScriptTransfer(i.caller, amount, fromBase58String(assetIdSub))], amount) | |
215 | - | } | |
216 | - | else throw("Address does not match with wavetroller address!") | |
145 | + | func depositAt (poolAddress,isCollateral) = if (checkPool(poolAddress)) | |
146 | + | then if ((size(i.payments) > 0)) | |
147 | + | then { | |
148 | + | let user = toBase58String(i.caller.bytes) | |
149 | + | let tokenAmount = invoke(addressFromStringValue(poolAddress), "deposit", [user, isCollateral], i.payments) | |
150 | + | if ((tokenAmount == tokenAmount)) | |
151 | + | then { | |
152 | + | let tokenId = getStringValue(addressFromStringValue(poolAddress), "dTokenId") | |
153 | + | match tokenAmount { | |
154 | + | case t: Int => | |
155 | + | [ScriptTransfer(i.caller, t, fromBase58String(tokenId))] | |
156 | + | case t: String => | |
157 | + | nil | |
158 | + | case _ => | |
159 | + | throw("Incorrect invoke result!") | |
160 | + | } | |
161 | + | } | |
162 | + | else throw("Strict value is not equal to itself.") | |
163 | + | } | |
164 | + | else throw("No payment attached!") | |
165 | + | else throw("Pool address not found!") | |
217 | 166 | ||
218 | 167 | ||
219 | 168 | ||
220 | 169 | @Callable(i) | |
221 | - | func | |
170 | + | func withdrawFrom (poolAddress) = if (checkPool(poolAddress)) | |
222 | 171 | then { | |
223 | - | let asset = Issue(tokenName, tokenDescription, 0, 8, true) | |
224 | - | let tokenId = calculateAssetId(asset) | |
225 | - | [asset, writeString("assetId", aId), writeString("configAddress", configAdd), IntegerEntry("totalBorrow", 0), IntegerEntry("totalSupply", 0), IntegerEntry("totalReserve", 0), IntegerEntry("storedIndex", baseIndex), IntegerEntry("storedHeight", height), IntegerEntry("baseExchangeRate", baseExchangeRate), writeString("dTokenName", tokenName), writeString("dTokenId", toBase58String(tokenId)), IntegerEntry("dTokenDecimals", 8), IntegerEntry("dTokenSupply", 0)] | |
172 | + | let dTokenId = getStringValue(addressFromStringValue(poolAddress), "dTokenId") | |
173 | + | if ((fromBase58String(dTokenId) == i.payments[0].assetId)) | |
174 | + | then if ((size(i.payments) > 0)) | |
175 | + | then { | |
176 | + | let user = toBase58String(i.caller.bytes) | |
177 | + | let tokenAmount = invoke(addressFromStringValue(poolAddress), "withdraw", [user], i.payments) | |
178 | + | if ((tokenAmount == tokenAmount)) | |
179 | + | then { | |
180 | + | let tokenId = getStringValue(addressFromStringValue(poolAddress), "assetId") | |
181 | + | match tokenAmount { | |
182 | + | case t: Int => | |
183 | + | if ((tokenId == "WAVES")) | |
184 | + | then [ScriptTransfer(i.caller, t, unit)] | |
185 | + | else [ScriptTransfer(i.caller, t, fromBase58String(tokenId))] | |
186 | + | case t: String => | |
187 | + | nil | |
188 | + | case _ => | |
189 | + | throw("Incorrect invoke result!") | |
190 | + | } | |
191 | + | } | |
192 | + | else throw("Strict value is not equal to itself.") | |
193 | + | } | |
194 | + | else throw("No payment attached!") | |
195 | + | else throw("AssetIds does not match") | |
226 | 196 | } | |
227 | - | else throw("Pool | |
197 | + | else throw("Pool address not found!") | |
228 | 198 | ||
229 | 199 | ||
230 | 200 | ||
231 | 201 | @Callable(i) | |
232 | - | func writeEntry (name,data) = [writeString(name, data)] | |
202 | + | func lockAsCollateralAt (poolAddress) = if (checkPool(poolAddress)) | |
203 | + | then { | |
204 | + | let dTokenId = getStringValue(addressFromStringValue(poolAddress), "dTokenId") | |
205 | + | if ((fromBase58String(dTokenId) == i.payments[0].assetId)) | |
206 | + | then if ((size(i.payments) > 0)) | |
207 | + | then { | |
208 | + | let user = toBase58String(i.caller.bytes) | |
209 | + | let msg = invoke(addressFromStringValue(poolAddress), "lockAsCollateral", [user], i.payments) | |
210 | + | if ((msg == msg)) | |
211 | + | then match msg { | |
212 | + | case t: String => | |
213 | + | nil | |
214 | + | case _ => | |
215 | + | throw("Incorrect invoke result!") | |
216 | + | } | |
217 | + | else throw("Strict value is not equal to itself.") | |
218 | + | } | |
219 | + | else throw("No payment attached!") | |
220 | + | else throw("AssetIds does not match") | |
221 | + | } | |
222 | + | else throw("Pool address not found!") | |
233 | 223 | ||
234 | - | ||
235 | - | @Verifier(tx) | |
236 | - | func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) | |
237 | 224 |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 5 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | - | let | |
4 | + | let config = valueOrElse(getStringValue(this, "config"), "") | |
5 | 5 | ||
6 | - | let | |
6 | + | let admin = valueOrElse(getStringValue(addressFromStringValue(config), "admin"), "") | |
7 | 7 | ||
8 | - | let | |
8 | + | let pools = valueOrElse(getStringValue(this, "pools"), "") | |
9 | 9 | ||
10 | - | let config = valueOrElse(getString(this, "configAddress"), "") | |
11 | - | ||
12 | - | let admin = valueOrElse(getString(addressFromStringValue(config), "admin"), "") | |
13 | - | ||
14 | - | let wavetroller = valueOrElse(getString(addressFromStringValue(config), "wavetroller"), "") | |
15 | - | ||
16 | - | let oracle = valueOrElse(getString(addressFromStringValue(config), "oracle"), "") | |
17 | - | ||
18 | - | let assetIdSub = valueOrErrorMessage(getString(this, "assetId"), "No assetId could be found in data storage!") | |
19 | - | ||
20 | - | let assetDecimals = valueOrErrorMessage(getInteger(addressFromStringValue(config), (assetIdSub + "_Decimals")), (("No key " + (assetIdSub + "_Decimals")) + " was found")) | |
21 | - | ||
22 | - | let multiplier = valueOrErrorMessage(getInteger(addressFromStringValue(config), (assetIdSub + "_Multiplier")), (("No key " + (assetIdSub + "_Multiplier")) + " was found")) | |
23 | - | ||
24 | - | let kink = valueOrErrorMessage(getInteger(addressFromStringValue(config), (assetIdSub + "_Kink")), (("No key " + (assetIdSub + "_Kink")) + " was found")) | |
25 | - | ||
26 | - | let jumpMultiplier = valueOrErrorMessage(getInteger(addressFromStringValue(config), (assetIdSub + "_JumpMultiplier")), (("No key " + (assetIdSub + "_JumpMultiplier")) + " was found")) | |
27 | - | ||
28 | - | let baseRate = valueOrErrorMessage(getInteger(addressFromStringValue(config), (assetIdSub + "_BaseRate")), (("No key " + (assetIdSub + "_BaseRate")) + " was found")) | |
29 | - | ||
30 | - | let baseExchangeRate = valueOrErrorMessage(getInteger(this, "baseExchangeRate"), "No key baseExchangeRate was found") | |
31 | - | ||
32 | - | let collateralFactor = valueOrErrorMessage(getInteger(addressFromStringValue(config), (assetIdSub + "_CollateralFactor")), (("No key " + (assetIdSub + "_CollateralFactor")) + " was found")) | |
33 | - | ||
34 | - | let liquidationThreshold = valueOrErrorMessage(getInteger(addressFromStringValue(config), (assetIdSub + "_Threshold")), (("No key " + (assetIdSub + "_Threshold")) + " was found")) | |
35 | - | ||
36 | - | let reserveFactor = valueOrErrorMessage(getInteger(addressFromStringValue(config), (assetIdSub + "_ReserveFactor")), (("No key " + (assetIdSub + "_ReserveFactor")) + " was found")) | |
37 | - | ||
38 | - | let totalBorrow = valueOrElse(getInteger(this, "totalBorrow"), 0) | |
39 | - | ||
40 | - | let totalSupply = valueOrElse(getInteger(this, "totalSupply"), 0) | |
41 | - | ||
42 | - | let totalReserve = valueOrElse(getInteger(this, "totalReserve"), 0) | |
43 | - | ||
44 | - | let dTokenSupply = valueOrErrorMessage(getInteger(this, "dTokenSupply"), "No key dTokenSupply was found") | |
45 | - | ||
46 | - | let dTokenDecimals = valueOrErrorMessage(getInteger(this, "dTokenDecimals"), "No key dTokenDecimals was found") | |
47 | - | ||
48 | - | let dTokenId = valueOrErrorMessage(getString(this, "dTokenId"), "No key dTokenId was found") | |
49 | - | ||
50 | - | let dTokenName = valueOrErrorMessage(getString(this, "dTokenName"), "No key dTokenName was found") | |
51 | - | ||
52 | - | let storedHeight = valueOrElse(getInteger(this, "storedHeight"), height) | |
53 | - | ||
54 | - | let storedIndex = valueOrElse(getInteger(this, "storedIndex"), 10000000000000000) | |
55 | - | ||
56 | - | func isAdminAddress (address) = if ((addressFromStringValue(admin) == address)) | |
10 | + | func isAdmin (callerAddress) = if ((callerAddress == addressFromStringValue(admin))) | |
57 | 11 | then true | |
58 | 12 | else false | |
59 | 13 | ||
60 | 14 | ||
61 | - | func isWavetroller (address) = if ((addressFromStringValue(wavetroller) == address)) | |
62 | - | then true | |
63 | - | else false | |
64 | - | ||
65 | - | ||
66 | - | func isAcceptableAssetId (assetId) = if ((assetId == assetIdSub)) | |
15 | + | func checkPool (poolAdd) = if (contains(pools, poolAdd)) | |
67 | 16 | then true | |
68 | 17 | else false | |
69 | 18 | ||
70 | 19 | ||
71 | 20 | func writeString (key,stringValue) = StringEntry(key, stringValue) | |
72 | 21 | ||
73 | 22 | ||
74 | 23 | func writeInteger (key,integerValue) = IntegerEntry(key, integerValue) | |
75 | 24 | ||
76 | 25 | ||
77 | - | func userlockedBalance (userAddress) = valueOrElse(getInteger(this, (userAddress + "_locked")), 0) | |
78 | - | ||
79 | - | ||
80 | - | let utilization = if ((totalSupply > 0)) | |
81 | - | then fraction(totalBorrow, baseFactor, totalSupply) | |
82 | - | else 0 | |
83 | - | ||
84 | - | let apr = { | |
85 | - | let minValue = [utilization, kink] | |
86 | - | let minValueItem = min(minValue) | |
87 | - | let maxValue = [0, (utilization - kink)] | |
88 | - | let maxValueItem = max(maxValue) | |
89 | - | ((fraction(multiplier, minValueItem, baseFactor) + fraction(jumpMultiplier, maxValueItem, baseFactor)) + baseRate) | |
90 | - | } | |
91 | - | ||
92 | - | let apy = fraction(fraction(apr, utilization, baseFactor), (baseFactor - reserveFactor), baseFactor) | |
93 | - | ||
94 | - | let borrowRatePerBlock = fraction(apr, baseIndex, (blocksPerYear * baseFactor)) | |
95 | - | ||
96 | - | let deltaBlocks = (height - storedHeight) | |
97 | - | ||
98 | - | let currentIndex = fraction(storedIndex, (baseIndex + (borrowRatePerBlock * deltaBlocks)), baseIndex, CEILING) | |
99 | - | ||
100 | - | let currentTotalBorrow = fraction(totalBorrow, currentIndex, storedIndex) | |
101 | - | ||
102 | - | let collectedInterest = fraction(totalBorrow, (borrowRatePerBlock * deltaBlocks), baseIndex) | |
103 | - | ||
104 | - | let currentTotalSupply = (totalSupply + fraction((baseFactor - reserveFactor), collectedInterest, baseFactor)) | |
105 | - | ||
106 | - | let currentReserve = (totalReserve + fraction(reserveFactor, collectedInterest, baseFactor)) | |
107 | - | ||
108 | - | let exchangeRate = if ((dTokenSupply > 0)) | |
109 | - | then { | |
110 | - | let exponent = ((18 - dTokenDecimals) + assetDecimals) | |
111 | - | let mantissa = pow(10, 0, exponent, 0, 0, CEILING) | |
112 | - | fraction(currentTotalSupply, mantissa, dTokenSupply) | |
113 | - | } | |
114 | - | else baseExchangeRate | |
115 | - | ||
116 | - | func calcDTokenAmount (assetAmount) = { | |
117 | - | let exponent = ((18 - dTokenDecimals) + assetDecimals) | |
118 | - | let mantissa = pow(10, 0, exponent, 0, 0, CEILING) | |
119 | - | fraction(assetAmount, mantissa, exchangeRate) | |
26 | + | func checkPoolLiquidity (poolAddress,amount) = { | |
27 | + | let totalSupply = getIntegerValue(addressFromStringValue(poolAddress), "totalSupply") | |
28 | + | let totalBorrow = getIntegerValue(addressFromStringValue(poolAddress), "totalBorrow") | |
29 | + | let availableLiquidity = (totalSupply - totalBorrow) | |
30 | + | if ((availableLiquidity >= amount)) | |
31 | + | then true | |
32 | + | else false | |
120 | 33 | } | |
121 | 34 | ||
122 | 35 | ||
123 | - | func calcAssetAmount (dTokenAmount) = { | |
124 | - | let exponent = ((18 - dTokenDecimals) + assetDecimals) | |
125 | - | let mantissa = pow(10, 0, exponent, 0, 0, CEILING) | |
126 | - | fraction(dTokenAmount, exchangeRate, mantissa) | |
36 | + | func getHealthParameter (user,poolAddress,newDebtAmount,newDebtId,collateralAmount,collateralId) = { | |
37 | + | let result = invoke(addressFromStringValue(poolAddress), "getUserHealthParameter", [user, collateralAmount, collateralId, newDebtAmount, newDebtId], nil) | |
38 | + | match result { | |
39 | + | case t: (Int, Int) => | |
40 | + | t | |
41 | + | case _ => | |
42 | + | $Tuple2(0, 0) | |
43 | + | } | |
127 | 44 | } | |
128 | 45 | ||
129 | 46 | ||
130 | - | func getCurrentUserBorrow (user) = { | |
131 | - | let storedBorrow = valueOrElse(getIntegerValue(this, (user + "_borrow")), 0) | |
132 | - | let storedBorrowIndex = valueOrElse(getIntegerValue(this, (user + "_index")), 0) | |
133 | - | if ((storedBorrowIndex > 0)) | |
134 | - | then fraction(storedBorrow, currentIndex, storedBorrowIndex) | |
135 | - | else 0 | |
47 | + | func calcHealthFactor (borrowCapacity,borrowCapacityUsed) = fraction((borrowCapacity - borrowCapacityUsed), 1000, borrowCapacity) | |
48 | + | ||
49 | + | ||
50 | + | func calcBorrowCBorrowCU (user,newDebtAmount,newDebtId,collateralAmount,collateralId) = { | |
51 | + | let poolList = split(pools, ";") | |
52 | + | let listSize = size(poolList) | |
53 | + | func foldPools (accum,next) = { | |
54 | + | let healthParams = getHealthParameter(user, next, newDebtAmount, newDebtId, collateralAmount, collateralId) | |
55 | + | match healthParams { | |
56 | + | case t: (Int, Int) => | |
57 | + | $Tuple2((accum._1 + healthParams._1), (accum._2 + healthParams._1)) | |
58 | + | case e => | |
59 | + | throw("Test") | |
60 | + | } | |
61 | + | } | |
62 | + | ||
63 | + | let $list22852319 = poolList | |
64 | + | let $size22852319 = size($list22852319) | |
65 | + | let $acc022852319 = $Tuple2(0, 0) | |
66 | + | if (($size22852319 == 0)) | |
67 | + | then $acc022852319 | |
68 | + | else { | |
69 | + | let $acc122852319 = foldPools($acc022852319, $list22852319[0]) | |
70 | + | if (($size22852319 == 1)) | |
71 | + | then $acc122852319 | |
72 | + | else { | |
73 | + | let $acc222852319 = foldPools($acc122852319, $list22852319[1]) | |
74 | + | if (($size22852319 == 2)) | |
75 | + | then $acc222852319 | |
76 | + | else { | |
77 | + | let $acc322852319 = foldPools($acc222852319, $list22852319[2]) | |
78 | + | throw("List size exceed 2") | |
79 | + | } | |
80 | + | } | |
81 | + | } | |
82 | + | } | |
83 | + | ||
84 | + | ||
85 | + | func checkUserHealth (user,newDebtAmount,newDebtId,collateralAmount,collateralId) = { | |
86 | + | let bcBcu = calcBorrowCBorrowCU(user, newDebtAmount, newDebtId, collateralAmount, collateralId) | |
87 | + | let userHealth = calcHealthFactor(bcBcu._1, bcBcu._2) | |
88 | + | if ((userHealth >= 0)) | |
89 | + | then true | |
90 | + | else false | |
136 | 91 | } | |
137 | 92 | ||
138 | 93 | ||
139 | 94 | @Callable(i) | |
140 | - | func | |
95 | + | func borrowFrom (poolAddress,assetId,amount) = if (checkPool(poolAddress)) | |
141 | 96 | then { | |
142 | - | let userLocked = valueOrElse(getIntegerValue(this, (user + "_locked")), 0) | |
143 | - | let userDTokenCollateral = if ((dTokenId == collateralId)) | |
144 | - | then (userLocked - collateralAmount) | |
145 | - | else userLocked | |
146 | - | let currentUserBorrow = if ((newDebtId == assetIdSub)) | |
147 | - | then (getCurrentUserBorrow(user) + newDebtAmount) | |
148 | - | else getCurrentUserBorrow(user) | |
149 | - | let userCollateral = calcAssetAmount(userDTokenCollateral) | |
150 | - | let assetPrice = invoke(addressFromStringValue(oracle), "getPrice", [assetIdSub], nil) | |
151 | - | match assetPrice { | |
152 | - | case t: Int => | |
153 | - | let collateralValue = fraction(collateralFactor, userCollateral, baseFactor) | |
154 | - | let mantissa = pow(10, 0, assetDecimals, 0, 0, CEILING) | |
155 | - | let bCSummand = fraction(collateralValue, t, mantissa) | |
156 | - | let borrowInUSD = fraction(currentUserBorrow, t, mantissa) | |
157 | - | let bCUSummand = fraction(borrowInUSD, baseFactor, liquidationThreshold) | |
158 | - | $Tuple2(nil, $Tuple2(bCSummand, bCUSummand)) | |
159 | - | case _ => | |
160 | - | throw("Incorrect pricing") | |
97 | + | let poolAsset = getStringValue(addressFromStringValue(poolAddress), "assetId") | |
98 | + | if ((poolAsset == assetId)) | |
99 | + | then if (checkPoolLiquidity(poolAddress, amount)) | |
100 | + | then { | |
101 | + | let user = toBase58String(i.caller.bytes) | |
102 | + | if (checkUserHealth(user, amount, assetId, 0, "")) | |
103 | + | then nil | |
104 | + | else throw("Borrow exceeds user health!") | |
105 | + | } | |
106 | + | else throw("Pool liquidity is not sufficient!") | |
107 | + | else throw("AssetIds does not match") | |
161 | 108 | } | |
162 | - | } | |
163 | - | else throw("Address does not match with wavetroller address!") | |
109 | + | else throw("Pool address not found!") | |
164 | 110 | ||
165 | 111 | ||
166 | 112 | ||
167 | 113 | @Callable(i) | |
168 | - | func deposit (user,isCollateral) = if (isWavetroller(i.caller)) | |
169 | - | then { | |
170 | - | let userTokenAmount = calcDTokenAmount(i.payments[0].amount) | |
171 | - | let currentDTokenSupply = (dTokenSupply + userTokenAmount) | |
172 | - | if (isCollateral) | |
173 | - | then { | |
174 | - | let lockedUserBalance = (userlockedBalance(user) + userTokenAmount) | |
175 | - | $Tuple2([writeInteger((user + "_locked"), lockedUserBalance), writeInteger("dTokenSupply", currentDTokenSupply), writeInteger("totalBorrow", currentTotalBorrow), writeInteger("totalSupply", (currentTotalSupply + i.payments[0].amount)), writeInteger("totalReserve", currentReserve), writeInteger("storedIndex", currentIndex), writeInteger("storedHeight", height), Reissue(fromBase58String(dTokenId), userTokenAmount, true)], ((toString(i.payments[0].amount) + dTokenName) + "were successfully locked")) | |
176 | - | } | |
177 | - | else $Tuple2([writeInteger("dTokenSupply", currentDTokenSupply), writeInteger("totalBorrow", currentTotalBorrow), writeInteger("totalSupply", (currentTotalSupply + i.payments[0].amount)), writeInteger("totalReserve", currentReserve), writeInteger("storedIndex", currentIndex), writeInteger("storedHeight", height), Reissue(fromBase58String(dTokenId), userTokenAmount, true), ScriptTransfer(i.caller, userTokenAmount, fromBase58String(dTokenId))], userTokenAmount) | |
178 | - | } | |
179 | - | else throw("Address does not match with wavetroller address!") | |
114 | + | func setup (configAddress,pools) = if (if (!(isDefined(getString(this, "config")))) | |
115 | + | then !(isDefined(getString(this, "pools"))) | |
116 | + | else false) | |
117 | + | then [writeString("config", configAddress), writeString("pools", makeString(pools, ";"))] | |
118 | + | else throw("Admin and config address already definied!") | |
180 | 119 | ||
181 | 120 | ||
182 | 121 | ||
183 | 122 | @Callable(i) | |
184 | - | func | |
123 | + | func addPool (poolAddress) = if (isAdmin(i.caller)) | |
185 | 124 | then { | |
186 | - | let | |
187 | - | | |
188 | - | | |
189 | - | | |
190 | - | ||
191 | - | | |
192 | - | else throw("Pool | |
125 | + | let poolList = split(pools, ";") | |
126 | + | if ((containsElement(poolList, poolAddress) == false)) | |
127 | + | then { | |
128 | + | let newPools = (poolList :+ poolAddress) | |
129 | + | [writeString("pools", makeString(newPools, ";"))] | |
130 | + | } | |
131 | + | else throw("Pool already exists!") | |
193 | 132 | } | |
194 | - | else throw("Address does not match with | |
133 | + | else throw("Address does not match with admin address!") | |
195 | 134 | ||
196 | 135 | ||
197 | 136 | ||
198 | 137 | @Callable(i) | |
199 | - | func lockAsCollateral (user) = if (isWavetroller(i.caller)) | |
200 | - | then { | |
201 | - | let newLockedBalance = (userlockedBalance(user) + i.payments[0].amount) | |
202 | - | $Tuple2([writeInteger((user + "_locked"), newLockedBalance), writeInteger("totalBorrow", currentTotalBorrow), writeInteger("totalSupply", currentTotalSupply), writeInteger("totalReserve", currentReserve), writeInteger("storedIndex", currentIndex), writeInteger("storedHeight", height)], ((toString(i.payments[0].amount) + dTokenName) + "were successfully locked")) | |
203 | - | } | |
204 | - | else throw("Address does not match with wavetroller address!") | |
138 | + | func updateConfig (configAddress) = if (isAdmin(i.caller)) | |
139 | + | then [writeString("config", configAddress)] | |
140 | + | else throw("Address does not match with admin address!") | |
205 | 141 | ||
206 | 142 | ||
207 | 143 | ||
208 | 144 | @Callable(i) | |
209 | - | func borrow (user,amount) = if (isWavetroller(i.caller)) | |
210 | - | then { | |
211 | - | let currentUserBorrow = getCurrentUserBorrow(user) | |
212 | - | $Tuple2([writeInteger((user + "_borrow"), (currentUserBorrow + amount)), writeInteger((user + "_index"), currentIndex), writeInteger("totalBorrow", (currentTotalBorrow + amount)), writeInteger("totalSupply", currentTotalSupply), writeInteger("totalReserve", currentReserve), writeInteger("storedIndex", currentIndex), writeInteger("storedHeight", height), if ((assetIdSub == "WAVES")) | |
213 | - | then ScriptTransfer(i.caller, amount, unit) | |
214 | - | else ScriptTransfer(i.caller, amount, fromBase58String(assetIdSub))], amount) | |
215 | - | } | |
216 | - | else throw("Address does not match with wavetroller address!") | |
145 | + | func depositAt (poolAddress,isCollateral) = if (checkPool(poolAddress)) | |
146 | + | then if ((size(i.payments) > 0)) | |
147 | + | then { | |
148 | + | let user = toBase58String(i.caller.bytes) | |
149 | + | let tokenAmount = invoke(addressFromStringValue(poolAddress), "deposit", [user, isCollateral], i.payments) | |
150 | + | if ((tokenAmount == tokenAmount)) | |
151 | + | then { | |
152 | + | let tokenId = getStringValue(addressFromStringValue(poolAddress), "dTokenId") | |
153 | + | match tokenAmount { | |
154 | + | case t: Int => | |
155 | + | [ScriptTransfer(i.caller, t, fromBase58String(tokenId))] | |
156 | + | case t: String => | |
157 | + | nil | |
158 | + | case _ => | |
159 | + | throw("Incorrect invoke result!") | |
160 | + | } | |
161 | + | } | |
162 | + | else throw("Strict value is not equal to itself.") | |
163 | + | } | |
164 | + | else throw("No payment attached!") | |
165 | + | else throw("Pool address not found!") | |
217 | 166 | ||
218 | 167 | ||
219 | 168 | ||
220 | 169 | @Callable(i) | |
221 | - | func | |
170 | + | func withdrawFrom (poolAddress) = if (checkPool(poolAddress)) | |
222 | 171 | then { | |
223 | - | let asset = Issue(tokenName, tokenDescription, 0, 8, true) | |
224 | - | let tokenId = calculateAssetId(asset) | |
225 | - | [asset, writeString("assetId", aId), writeString("configAddress", configAdd), IntegerEntry("totalBorrow", 0), IntegerEntry("totalSupply", 0), IntegerEntry("totalReserve", 0), IntegerEntry("storedIndex", baseIndex), IntegerEntry("storedHeight", height), IntegerEntry("baseExchangeRate", baseExchangeRate), writeString("dTokenName", tokenName), writeString("dTokenId", toBase58String(tokenId)), IntegerEntry("dTokenDecimals", 8), IntegerEntry("dTokenSupply", 0)] | |
172 | + | let dTokenId = getStringValue(addressFromStringValue(poolAddress), "dTokenId") | |
173 | + | if ((fromBase58String(dTokenId) == i.payments[0].assetId)) | |
174 | + | then if ((size(i.payments) > 0)) | |
175 | + | then { | |
176 | + | let user = toBase58String(i.caller.bytes) | |
177 | + | let tokenAmount = invoke(addressFromStringValue(poolAddress), "withdraw", [user], i.payments) | |
178 | + | if ((tokenAmount == tokenAmount)) | |
179 | + | then { | |
180 | + | let tokenId = getStringValue(addressFromStringValue(poolAddress), "assetId") | |
181 | + | match tokenAmount { | |
182 | + | case t: Int => | |
183 | + | if ((tokenId == "WAVES")) | |
184 | + | then [ScriptTransfer(i.caller, t, unit)] | |
185 | + | else [ScriptTransfer(i.caller, t, fromBase58String(tokenId))] | |
186 | + | case t: String => | |
187 | + | nil | |
188 | + | case _ => | |
189 | + | throw("Incorrect invoke result!") | |
190 | + | } | |
191 | + | } | |
192 | + | else throw("Strict value is not equal to itself.") | |
193 | + | } | |
194 | + | else throw("No payment attached!") | |
195 | + | else throw("AssetIds does not match") | |
226 | 196 | } | |
227 | - | else throw("Pool | |
197 | + | else throw("Pool address not found!") | |
228 | 198 | ||
229 | 199 | ||
230 | 200 | ||
231 | 201 | @Callable(i) | |
232 | - | func writeEntry (name,data) = [writeString(name, data)] | |
202 | + | func lockAsCollateralAt (poolAddress) = if (checkPool(poolAddress)) | |
203 | + | then { | |
204 | + | let dTokenId = getStringValue(addressFromStringValue(poolAddress), "dTokenId") | |
205 | + | if ((fromBase58String(dTokenId) == i.payments[0].assetId)) | |
206 | + | then if ((size(i.payments) > 0)) | |
207 | + | then { | |
208 | + | let user = toBase58String(i.caller.bytes) | |
209 | + | let msg = invoke(addressFromStringValue(poolAddress), "lockAsCollateral", [user], i.payments) | |
210 | + | if ((msg == msg)) | |
211 | + | then match msg { | |
212 | + | case t: String => | |
213 | + | nil | |
214 | + | case _ => | |
215 | + | throw("Incorrect invoke result!") | |
216 | + | } | |
217 | + | else throw("Strict value is not equal to itself.") | |
218 | + | } | |
219 | + | else throw("No payment attached!") | |
220 | + | else throw("AssetIds does not match") | |
221 | + | } | |
222 | + | else throw("Pool address not found!") | |
233 | 223 | ||
234 | - | ||
235 | - | @Verifier(tx) | |
236 | - | func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) | |
237 | 224 |
github/deemru/w8io/169f3d6 44.36 ms ◑![]()