tx · HjFAsPEx8miJGpwHGm8oeru6Szzvk5yT5u4TifqfCTqK 3MrASWFH3k8Tkfq2eoMDH6vZWy2dywFQNen: -0.03700000 Waves 2022.12.12 16:42 [2357198] smart account 3MrASWFH3k8Tkfq2eoMDH6vZWy2dywFQNen > SELF 0.00000000 Waves
{ "type": 13, "id": "HjFAsPEx8miJGpwHGm8oeru6Szzvk5yT5u4TifqfCTqK", "fee": 3700000, "feeAssetId": null, "timestamp": 1670852608328, "version": 2, "chainId": 84, "sender": "3MrASWFH3k8Tkfq2eoMDH6vZWy2dywFQNen", "senderPublicKey": "9JqU7LHuYERXD76iWBYPkx8qsJ5kNWc8UjTncwigr2BS", "proofs": [ "3ZW1JNMNRQg9trbPWXTQsh4ruJk9PPoHwWJAxSW9933ocZxxtCPKZTAmH2T8F6iN2Afz6wDmPAHAoQx1mewp9E3F" ], "script": "base64:BgIiCAISBAoCCAgSAwoBCBIFCgMIAQgSBQoDCAEIEgUKAwgIAR8AEmtfYXNzZXRfY29sbGF0ZXJhbAISa19hc3NldF9jb2xsYXRlcmFsACBrX3RyYWRlcl9tYXJrZXRfYXNzZXRfY29sbGF0ZXJhbAIga190cmFkZXJfbWFya2V0X2Fzc2V0X2NvbGxhdGVyYWwAEWtfd2hpdGVsaXN0X2Fzc2V0AhFrX3doaXRlbGlzdF9hc3NldAANa19pbml0aWFsaXplZAINa19pbml0aWFsaXplZAAUa19jb29yZGluYXRvckFkZHJlc3MCFGtfY29vcmRpbmF0b3JBZGRyZXNzABJrX2dvdmVybmFuY2VfYXNzZXQCC2tfZ292X2Fzc2V0AA1rX3F1b3RlX2Fzc2V0Ag1rX3F1b3RlX2Fzc2V0ABJrX2FkbWluX3B1YmxpY19rZXkCEmtfYWRtaW5fcHVibGljX2tleQARa19tYW5hZ2VyX2FkZHJlc3MCEWtfbWFuYWdlcl9hZGRyZXNzAAVrX2FtbQIFa19hbW0AEmtfZXhjaGFuZ2VfYWRkcmVzcwISa19leGNoYW5nZV9hZGRyZX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bGYuCQACAQIkU3RyaWN0IHZhbHVlIGlzIG5vdCBlcXVhbCB0byBpdHNlbGYuCQACAQIkU3RyaWN0IHZhbHVlIGlzIG5vdCBlcXVhbCB0byBpdHNlbGYuAQJ0eAEGdmVyaWZ5AAkA9AMDCAUCdHgJYm9keUJ5dGVzCQCRAwIIBQJ0eAZwcm9vZnMAAAkBDmFkbWluUHVibGljS2V5AP7eLfY=", "height": 2357198, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: HJNSTA4LU1KkwcJ1w4NDXyHRXeF3apNJWUKFMUAyw25e Next: none Diff:
Old | New | Differences | |
---|---|---|---|
21 | 21 | ||
22 | 22 | let k_amm = "k_amm" | |
23 | 23 | ||
24 | - | let k_ | |
24 | + | let k_exchange_address = "k_exchange_address" | |
25 | 25 | ||
26 | - | let k_ | |
26 | + | let k_vault_address = "k_vault_address" | |
27 | 27 | ||
28 | 28 | func toCompositeKey (_key,_address) = ((_key + "_") + _address) | |
29 | 29 | ||
49 | 49 | func isWhitelistAsset (_assetId) = valueOrElse(getBoolean(this, toCompositeKey(k_whitelist_asset, _assetId)), false) | |
50 | 50 | ||
51 | 51 | ||
52 | - | func | |
52 | + | func vaultAddress () = valueOrErrorMessage(addressFromString(getStringValue(coordinator(), k_vault_address)), "Vault not set") | |
53 | 53 | ||
54 | 54 | ||
55 | 55 | func swapAddress () = valueOrErrorMessage(addressFromString(valueOrErrorMessage(getString(coordinator(), k_exchange_address), "No swap address")), "Invalid swap address") | |
116 | 116 | else !(isWhitelistAsset(assetId))) | |
117 | 117 | then throw("Invalid borrow parameters") | |
118 | 118 | else { | |
119 | - | let withdrawInsurance = invoke( | |
119 | + | let withdrawInsurance = invoke(vaultAddress(), "addLockedV", [amount], nil) | |
120 | 120 | if ((withdrawInsurance == withdrawInsurance)) | |
121 | - | then [ | |
121 | + | then [IntegerEntry(getBorrowedByTraderInMarketKey(amm, assetId, _trader), (getBorrowedByTraderInMarket(amm, assetId, _trader) + amount))] | |
122 | 122 | else throw("Strict value is not equal to itself.") | |
123 | 123 | } | |
124 | 124 | } | |
126 | 126 | ||
127 | 127 | ||
128 | 128 | @Callable(i) | |
129 | - | func repay (_trader,_assetId) = { | |
130 | - | let amount = i.payments[0].amount | |
129 | + | func repay (_trader,_amount,_assetId) = { | |
131 | 130 | let amm = toString(i.caller) | |
132 | 131 | if (if (!(isWhitelist(amm))) | |
133 | 132 | then true | |
134 | 133 | else !(isWhitelistAsset(_assetId))) | |
135 | 134 | then throw("Invalid repay parameters") | |
136 | 135 | else { | |
137 | - | let withdrawInsurance = invoke( | |
136 | + | let withdrawInsurance = invoke(vaultAddress(), "withdrawLockedV", [_amount], nil) | |
138 | 137 | if ((withdrawInsurance == withdrawInsurance)) | |
139 | 138 | then { | |
140 | - | let newDebt = (getBorrowedByTraderInMarket(amm, _assetId, _trader) - amount) | |
141 | - | ([ScriptTransfer(i.caller, amount, fromBase58String(_assetId))] ++ (if ((newDebt > 0)) | |
139 | + | let newDebt = (getBorrowedByTraderInMarket(amm, _assetId, _trader) - _amount) | |
140 | + | ([ScriptTransfer(i.caller, _amount, fromBase58String(_assetId))] ++ (if ((newDebt > 0)) | |
142 | 141 | then [IntegerEntry(getBorrowedByTraderInMarketKey(amm, _assetId, _trader), newDebt)] | |
143 | 142 | else [DeleteEntry(getBorrowedByTraderInMarketKey(amm, _assetId, _trader))])) | |
144 | 143 | } | |
149 | 148 | ||
150 | 149 | ||
151 | 150 | @Callable(i) | |
152 | - | func realizePartiallyAndClose (_trader,_assetId) = { | |
153 | - | let amount = if ((size(i.payments) > 0)) | |
154 | - | then i.payments[0].amount | |
155 | - | else 0 | |
151 | + | func realizePartiallyAndClose (_trader,_amount,_assetId) = { | |
156 | 152 | let amm = toString(i.caller) | |
157 | 153 | let debt = getBorrowedByTraderInMarket(amm, _assetId, _trader) | |
158 | - | let toSell = (debt - amount) | |
154 | + | let toSell = (debt - _amount) | |
159 | 155 | let sanityCheck = if ((0 >= toSell)) | |
160 | 156 | then throw("Use repay instead") | |
161 | 157 | else nil | |
177 | 173 | let soldForAmount = (amountAfter - amountBefore) | |
178 | 174 | if ((soldForAmount == soldForAmount)) | |
179 | 175 | then { | |
180 | - | let | |
181 | - | if (( | |
176 | + | let depositSoldCollateral = invoke(vaultAddress(), "addLocked", [true], [AttachedPayment(quoteAsset(), soldForAmount)]) | |
177 | + | if ((depositSoldCollateral == depositSoldCollateral)) | |
182 | 178 | then { | |
183 | - | let toGetBack = (debt - toSell) | |
184 | - | if ((toGetBack > 0)) | |
185 | - | then [ScriptTransfer(i.caller, (debt - toSell), fromBase58String(_assetId))] | |
186 | - | else (nil ++ [DeleteEntry(getBorrowedByTraderInMarketKey(amm, _assetId, _trader))]) | |
179 | + | let withdrawLockedV = invoke(vaultAddress(), "withdrawLockedV", [debt], nil) | |
180 | + | if ((withdrawLockedV == withdrawLockedV)) | |
181 | + | then { | |
182 | + | let toGetBack = (debt - toSell) | |
183 | + | if ((toGetBack > 0)) | |
184 | + | then [ScriptTransfer(i.caller, (debt - toSell), fromBase58String(_assetId))] | |
185 | + | else (nil ++ [DeleteEntry(getBorrowedByTraderInMarketKey(amm, _assetId, _trader))]) | |
186 | + | } | |
187 | + | else throw("Strict value is not equal to itself.") | |
187 | 188 | } | |
188 | 189 | else throw("Strict value is not equal to itself.") | |
189 | 190 | } | |
207 | 208 | let sanityCheck = if (if ((0 >= _toSell)) | |
208 | 209 | then true | |
209 | 210 | else (_toSell > debt)) | |
210 | - | then throw("Invalid | |
211 | + | then throw("Invalid realizePartially parameters") | |
211 | 212 | else nil | |
212 | 213 | if ((sanityCheck == sanityCheck)) | |
213 | 214 | then if (if (!(isWhitelist(amm))) | |
227 | 228 | let soldForAmount = (amountAfter - amountBefore) | |
228 | 229 | if ((soldForAmount == soldForAmount)) | |
229 | 230 | then { | |
230 | - | let withdrawInsurance = invoke(insuranceAddress(), "deposit", nil, [AttachedPayment(quoteAsset(), soldForAmount)]) | |
231 | - | if ((withdrawInsurance == withdrawInsurance)) | |
232 | - | then [IntegerEntry(getBorrowedByTraderInMarketKey(amm, _assetId, _trader), (getBorrowedByTraderInMarket(amm, _assetId, _trader) - _toSell))] | |
231 | + | let addLocked = invoke(vaultAddress(), "addLocked", [true], [AttachedPayment(quoteAsset(), soldForAmount)]) | |
232 | + | if ((addLocked == addLocked)) | |
233 | + | then { | |
234 | + | let withdrawLockedV = invoke(vaultAddress(), "withdrawLockedV", [soldForAmount], nil) | |
235 | + | if ((withdrawLockedV == withdrawLockedV)) | |
236 | + | then [IntegerEntry(getBorrowedByTraderInMarketKey(amm, _assetId, _trader), (getBorrowedByTraderInMarket(amm, _assetId, _trader) - _toSell))] | |
237 | + | else throw("Strict value is not equal to itself.") | |
238 | + | } | |
233 | 239 | else throw("Strict value is not equal to itself.") | |
234 | 240 | } | |
235 | 241 | else throw("Strict value is not equal to itself.") |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 6 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let k_asset_collateral = "k_asset_collateral" | |
5 | 5 | ||
6 | 6 | let k_trader_market_asset_collateral = "k_trader_market_asset_collateral" | |
7 | 7 | ||
8 | 8 | let k_whitelist_asset = "k_whitelist_asset" | |
9 | 9 | ||
10 | 10 | let k_initialized = "k_initialized" | |
11 | 11 | ||
12 | 12 | let k_coordinatorAddress = "k_coordinatorAddress" | |
13 | 13 | ||
14 | 14 | let k_governance_asset = "k_gov_asset" | |
15 | 15 | ||
16 | 16 | let k_quote_asset = "k_quote_asset" | |
17 | 17 | ||
18 | 18 | let k_admin_public_key = "k_admin_public_key" | |
19 | 19 | ||
20 | 20 | let k_manager_address = "k_manager_address" | |
21 | 21 | ||
22 | 22 | let k_amm = "k_amm" | |
23 | 23 | ||
24 | - | let k_ | |
24 | + | let k_exchange_address = "k_exchange_address" | |
25 | 25 | ||
26 | - | let k_ | |
26 | + | let k_vault_address = "k_vault_address" | |
27 | 27 | ||
28 | 28 | func toCompositeKey (_key,_address) = ((_key + "_") + _address) | |
29 | 29 | ||
30 | 30 | ||
31 | 31 | func coordinator () = valueOrErrorMessage(addressFromString(getStringValue(this, k_coordinatorAddress)), "Coordinator not set") | |
32 | 32 | ||
33 | 33 | ||
34 | 34 | func adminPublicKey () = fromBase58String(getStringValue(coordinator(), k_admin_public_key)) | |
35 | 35 | ||
36 | 36 | ||
37 | 37 | func governanceAsset () = fromBase58String(getStringValue(coordinator(), k_governance_asset)) | |
38 | 38 | ||
39 | 39 | ||
40 | 40 | func quoteAsset () = fromBase58String(getStringValue(coordinator(), k_quote_asset)) | |
41 | 41 | ||
42 | 42 | ||
43 | 43 | func managerAddress () = valueOrErrorMessage(addressFromString(getStringValue(coordinator(), k_manager_address)), "Manager not set") | |
44 | 44 | ||
45 | 45 | ||
46 | 46 | func isWhitelist (_address) = valueOrElse(getBoolean(coordinator(), toCompositeKey(k_amm, _address)), false) | |
47 | 47 | ||
48 | 48 | ||
49 | 49 | func isWhitelistAsset (_assetId) = valueOrElse(getBoolean(this, toCompositeKey(k_whitelist_asset, _assetId)), false) | |
50 | 50 | ||
51 | 51 | ||
52 | - | func | |
52 | + | func vaultAddress () = valueOrErrorMessage(addressFromString(getStringValue(coordinator(), k_vault_address)), "Vault not set") | |
53 | 53 | ||
54 | 54 | ||
55 | 55 | func swapAddress () = valueOrErrorMessage(addressFromString(valueOrErrorMessage(getString(coordinator(), k_exchange_address), "No swap address")), "Invalid swap address") | |
56 | 56 | ||
57 | 57 | ||
58 | 58 | let DECIMAL_UNIT = (1 * (((((((10 * 10) * 10) * 10) * 10) * 10) * 10) * 10)) | |
59 | 59 | ||
60 | 60 | let DURATION = ((60 * 60) * 24) | |
61 | 61 | ||
62 | 62 | let NO_ADDRESS = "" | |
63 | 63 | ||
64 | 64 | let NO_STAKER = 0 | |
65 | 65 | ||
66 | 66 | func usdnFromDecimals (_amount) = (_amount / 100) | |
67 | 67 | ||
68 | 68 | ||
69 | 69 | func usdnToDecimals (_amount) = (_amount * 100) | |
70 | 70 | ||
71 | 71 | ||
72 | 72 | func initialized () = valueOrElse(getBoolean(this, k_initialized), false) | |
73 | 73 | ||
74 | 74 | ||
75 | 75 | func getBorrowedByTraderInMarketKey (_amm,_assetId,_trader) = ((((((k_trader_market_asset_collateral + "_") + _amm) + "_") + _assetId) + "_") + _trader) | |
76 | 76 | ||
77 | 77 | ||
78 | 78 | func getBorrowedByTraderInMarket (_amm,_assetId,_trader) = { | |
79 | 79 | let key = getBorrowedByTraderInMarketKey(_amm, _assetId, _trader) | |
80 | 80 | valueOrElse(getInteger(this, key), 0) | |
81 | 81 | } | |
82 | 82 | ||
83 | 83 | ||
84 | 84 | @Callable(i) | |
85 | 85 | func initialize (_coordinator,_whitelist) = if (initialized()) | |
86 | 86 | then throw("Already initialized") | |
87 | 87 | else { | |
88 | 88 | let initialAssetIds = split(_whitelist, ",") | |
89 | 89 | func doWhitelist (_acc,_assetId) = (_acc :+ BooleanEntry(toCompositeKey(k_whitelist_asset, _assetId), true)) | |
90 | 90 | ||
91 | 91 | ({ | |
92 | 92 | let $l = initialAssetIds | |
93 | 93 | let $s = size($l) | |
94 | 94 | let $acc0 = nil | |
95 | 95 | func $f0_1 ($a,$i) = if (($i >= $s)) | |
96 | 96 | then $a | |
97 | 97 | else doWhitelist($a, $l[$i]) | |
98 | 98 | ||
99 | 99 | func $f0_2 ($a,$i) = if (($i >= $s)) | |
100 | 100 | then $a | |
101 | 101 | else throw("List size exceeds 20") | |
102 | 102 | ||
103 | 103 | $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10), 11), 12), 13), 14), 15), 16), 17), 18), 19), 20) | |
104 | 104 | } ++ [StringEntry(k_coordinatorAddress, _coordinator), BooleanEntry(k_initialized, true)]) | |
105 | 105 | } | |
106 | 106 | ||
107 | 107 | ||
108 | 108 | ||
109 | 109 | @Callable(i) | |
110 | 110 | func borrow (_trader) = { | |
111 | 111 | let amount = i.payments[0].amount | |
112 | 112 | let assetId = toBase58String(valueOrErrorMessage(i.payments[0].assetId, "Invalid asset id")) | |
113 | 113 | let amm = toString(i.caller) | |
114 | 114 | if (if (!(isWhitelist(amm))) | |
115 | 115 | then true | |
116 | 116 | else !(isWhitelistAsset(assetId))) | |
117 | 117 | then throw("Invalid borrow parameters") | |
118 | 118 | else { | |
119 | - | let withdrawInsurance = invoke( | |
119 | + | let withdrawInsurance = invoke(vaultAddress(), "addLockedV", [amount], nil) | |
120 | 120 | if ((withdrawInsurance == withdrawInsurance)) | |
121 | - | then [ | |
121 | + | then [IntegerEntry(getBorrowedByTraderInMarketKey(amm, assetId, _trader), (getBorrowedByTraderInMarket(amm, assetId, _trader) + amount))] | |
122 | 122 | else throw("Strict value is not equal to itself.") | |
123 | 123 | } | |
124 | 124 | } | |
125 | 125 | ||
126 | 126 | ||
127 | 127 | ||
128 | 128 | @Callable(i) | |
129 | - | func repay (_trader,_assetId) = { | |
130 | - | let amount = i.payments[0].amount | |
129 | + | func repay (_trader,_amount,_assetId) = { | |
131 | 130 | let amm = toString(i.caller) | |
132 | 131 | if (if (!(isWhitelist(amm))) | |
133 | 132 | then true | |
134 | 133 | else !(isWhitelistAsset(_assetId))) | |
135 | 134 | then throw("Invalid repay parameters") | |
136 | 135 | else { | |
137 | - | let withdrawInsurance = invoke( | |
136 | + | let withdrawInsurance = invoke(vaultAddress(), "withdrawLockedV", [_amount], nil) | |
138 | 137 | if ((withdrawInsurance == withdrawInsurance)) | |
139 | 138 | then { | |
140 | - | let newDebt = (getBorrowedByTraderInMarket(amm, _assetId, _trader) - amount) | |
141 | - | ([ScriptTransfer(i.caller, amount, fromBase58String(_assetId))] ++ (if ((newDebt > 0)) | |
139 | + | let newDebt = (getBorrowedByTraderInMarket(amm, _assetId, _trader) - _amount) | |
140 | + | ([ScriptTransfer(i.caller, _amount, fromBase58String(_assetId))] ++ (if ((newDebt > 0)) | |
142 | 141 | then [IntegerEntry(getBorrowedByTraderInMarketKey(amm, _assetId, _trader), newDebt)] | |
143 | 142 | else [DeleteEntry(getBorrowedByTraderInMarketKey(amm, _assetId, _trader))])) | |
144 | 143 | } | |
145 | 144 | else throw("Strict value is not equal to itself.") | |
146 | 145 | } | |
147 | 146 | } | |
148 | 147 | ||
149 | 148 | ||
150 | 149 | ||
151 | 150 | @Callable(i) | |
152 | - | func realizePartiallyAndClose (_trader,_assetId) = { | |
153 | - | let amount = if ((size(i.payments) > 0)) | |
154 | - | then i.payments[0].amount | |
155 | - | else 0 | |
151 | + | func realizePartiallyAndClose (_trader,_amount,_assetId) = { | |
156 | 152 | let amm = toString(i.caller) | |
157 | 153 | let debt = getBorrowedByTraderInMarket(amm, _assetId, _trader) | |
158 | - | let toSell = (debt - amount) | |
154 | + | let toSell = (debt - _amount) | |
159 | 155 | let sanityCheck = if ((0 >= toSell)) | |
160 | 156 | then throw("Use repay instead") | |
161 | 157 | else nil | |
162 | 158 | if ((sanityCheck == sanityCheck)) | |
163 | 159 | then if (if (!(isWhitelist(amm))) | |
164 | 160 | then true | |
165 | 161 | else !(isWhitelistAsset(_assetId))) | |
166 | 162 | then throw("Invalid realizePartiallyAndClose parameters") | |
167 | 163 | else { | |
168 | 164 | let amountBefore = assetBalance(this, quoteAsset()) | |
169 | 165 | if ((amountBefore == amountBefore)) | |
170 | 166 | then { | |
171 | 167 | let doSwap = invoke(swapAddress(), "swap", [toBase58String(quoteAsset()), 0], [AttachedPayment(fromBase58String(_assetId), toSell)]) | |
172 | 168 | if ((doSwap == doSwap)) | |
173 | 169 | then { | |
174 | 170 | let amountAfter = assetBalance(this, quoteAsset()) | |
175 | 171 | if ((amountAfter == amountAfter)) | |
176 | 172 | then { | |
177 | 173 | let soldForAmount = (amountAfter - amountBefore) | |
178 | 174 | if ((soldForAmount == soldForAmount)) | |
179 | 175 | then { | |
180 | - | let | |
181 | - | if (( | |
176 | + | let depositSoldCollateral = invoke(vaultAddress(), "addLocked", [true], [AttachedPayment(quoteAsset(), soldForAmount)]) | |
177 | + | if ((depositSoldCollateral == depositSoldCollateral)) | |
182 | 178 | then { | |
183 | - | let toGetBack = (debt - toSell) | |
184 | - | if ((toGetBack > 0)) | |
185 | - | then [ScriptTransfer(i.caller, (debt - toSell), fromBase58String(_assetId))] | |
186 | - | else (nil ++ [DeleteEntry(getBorrowedByTraderInMarketKey(amm, _assetId, _trader))]) | |
179 | + | let withdrawLockedV = invoke(vaultAddress(), "withdrawLockedV", [debt], nil) | |
180 | + | if ((withdrawLockedV == withdrawLockedV)) | |
181 | + | then { | |
182 | + | let toGetBack = (debt - toSell) | |
183 | + | if ((toGetBack > 0)) | |
184 | + | then [ScriptTransfer(i.caller, (debt - toSell), fromBase58String(_assetId))] | |
185 | + | else (nil ++ [DeleteEntry(getBorrowedByTraderInMarketKey(amm, _assetId, _trader))]) | |
186 | + | } | |
187 | + | else throw("Strict value is not equal to itself.") | |
187 | 188 | } | |
188 | 189 | else throw("Strict value is not equal to itself.") | |
189 | 190 | } | |
190 | 191 | else throw("Strict value is not equal to itself.") | |
191 | 192 | } | |
192 | 193 | else throw("Strict value is not equal to itself.") | |
193 | 194 | } | |
194 | 195 | else throw("Strict value is not equal to itself.") | |
195 | 196 | } | |
196 | 197 | else throw("Strict value is not equal to itself.") | |
197 | 198 | } | |
198 | 199 | else throw("Strict value is not equal to itself.") | |
199 | 200 | } | |
200 | 201 | ||
201 | 202 | ||
202 | 203 | ||
203 | 204 | @Callable(i) | |
204 | 205 | func realizePartially (_trader,_assetId,_toSell) = { | |
205 | 206 | let amm = toString(i.caller) | |
206 | 207 | let debt = getBorrowedByTraderInMarket(amm, _assetId, _trader) | |
207 | 208 | let sanityCheck = if (if ((0 >= _toSell)) | |
208 | 209 | then true | |
209 | 210 | else (_toSell > debt)) | |
210 | - | then throw("Invalid | |
211 | + | then throw("Invalid realizePartially parameters") | |
211 | 212 | else nil | |
212 | 213 | if ((sanityCheck == sanityCheck)) | |
213 | 214 | then if (if (!(isWhitelist(amm))) | |
214 | 215 | then true | |
215 | 216 | else !(isWhitelistAsset(_assetId))) | |
216 | 217 | then throw("Invalid realizePartiallyAndClose parameters") | |
217 | 218 | else { | |
218 | 219 | let amountBefore = assetBalance(this, quoteAsset()) | |
219 | 220 | if ((amountBefore == amountBefore)) | |
220 | 221 | then { | |
221 | 222 | let doSwap = invoke(swapAddress(), "swap", [toBase58String(quoteAsset()), 0], [AttachedPayment(fromBase58String(_assetId), _toSell)]) | |
222 | 223 | if ((doSwap == doSwap)) | |
223 | 224 | then { | |
224 | 225 | let amountAfter = assetBalance(this, quoteAsset()) | |
225 | 226 | if ((amountAfter == amountAfter)) | |
226 | 227 | then { | |
227 | 228 | let soldForAmount = (amountAfter - amountBefore) | |
228 | 229 | if ((soldForAmount == soldForAmount)) | |
229 | 230 | then { | |
230 | - | let withdrawInsurance = invoke(insuranceAddress(), "deposit", nil, [AttachedPayment(quoteAsset(), soldForAmount)]) | |
231 | - | if ((withdrawInsurance == withdrawInsurance)) | |
232 | - | then [IntegerEntry(getBorrowedByTraderInMarketKey(amm, _assetId, _trader), (getBorrowedByTraderInMarket(amm, _assetId, _trader) - _toSell))] | |
231 | + | let addLocked = invoke(vaultAddress(), "addLocked", [true], [AttachedPayment(quoteAsset(), soldForAmount)]) | |
232 | + | if ((addLocked == addLocked)) | |
233 | + | then { | |
234 | + | let withdrawLockedV = invoke(vaultAddress(), "withdrawLockedV", [soldForAmount], nil) | |
235 | + | if ((withdrawLockedV == withdrawLockedV)) | |
236 | + | then [IntegerEntry(getBorrowedByTraderInMarketKey(amm, _assetId, _trader), (getBorrowedByTraderInMarket(amm, _assetId, _trader) - _toSell))] | |
237 | + | else throw("Strict value is not equal to itself.") | |
238 | + | } | |
233 | 239 | else throw("Strict value is not equal to itself.") | |
234 | 240 | } | |
235 | 241 | else throw("Strict value is not equal to itself.") | |
236 | 242 | } | |
237 | 243 | else throw("Strict value is not equal to itself.") | |
238 | 244 | } | |
239 | 245 | else throw("Strict value is not equal to itself.") | |
240 | 246 | } | |
241 | 247 | else throw("Strict value is not equal to itself.") | |
242 | 248 | } | |
243 | 249 | else throw("Strict value is not equal to itself.") | |
244 | 250 | } | |
245 | 251 | ||
246 | 252 | ||
247 | 253 | @Verifier(tx) | |
248 | 254 | func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], adminPublicKey()) | |
249 | 255 |
github/deemru/w8io/169f3d6 42.08 ms ◑