tx · AquSqmK3DiQhCFkTgTWgvLWUBeQMzZqje9cQXYq226vs 3MsgzbtRg8NEkbTcHBywtwTdCe9BRxMQo5T: -0.00800000 Waves 2024.09.24 08:54 [3297271] smart account 3MsgzbtRg8NEkbTcHBywtwTdCe9BRxMQo5T > SELF 0.00000000 Waves
{ "type": 13, "id": "AquSqmK3DiQhCFkTgTWgvLWUBeQMzZqje9cQXYq226vs", "fee": 800000, "feeAssetId": null, "timestamp": 1727157307994, "version": 1, "sender": "3MsgzbtRg8NEkbTcHBywtwTdCe9BRxMQo5T", "senderPublicKey": "iTiQR3Kvxn7i8PFgEbZn36n5iFLxFwkTA6M3wi846Vx", "proofs": [ "4mQaXVZc22rCaCMkZAdiRW3836kFQ2f6cBmkyrbBPqVxabmgLAQDCmgEPKRgH2QFzKGjQN57tFtqHGwKWGFnRb8Z" ], "script": "base64:BwJLCAISAwoBCBIECgIICBIECgIIARIECgIIBBIECgIIAhIDCgEIEgUKAwIBBBIECgICARIFCgMCAQISBQoDAhIREgQKAgIBEgQKAggYEAAJc2VwYXJhdG9yAgJfXwALd2F2ZXNTdHJpbmcCBVdBVkVTABBjb250cmFjdEZpbGVuYW1lAhRtZW1lX2ltX2ZhY3RvcnkucmlkZQAJa1NodXRkb3duAgwlc19fc2h1dGRvd24ACHNodXRkb3duCQELdmFsdWVPckVsc2UCCQCgCAEFCWtTaHV0ZG93bgcBB3dyYXBFcnIBAXMJAKwCAgkArAICBRBjb250cmFjdEZpbGVuYW1lAgI6IAUBcwEIdGhyb3dFcnIBAXMJAAIBCQEHd3JhcEVycgEFAXMBD3ZhbGlkYXRlQWRkcmVzcwEHYWRkcmVzcwkBCWlzRGVmaW5lZAEJAKYIAQUHYWRkcmVzcwASa0NhbGN1bGF0b3JBZGRyZXNzAhNjYWxjdWxhdG9yX19hZGRyZXNzABdjYWxjdWxhdG9yQWRkcmVzc09wdGlvbgQHJG1hdGNoMAkAnQgCBQR0aGlzBRJrQ2FsY3VsYXRvckFkZHJlc3MDCQABAgUHJG1hdGNoMAIGU3RyaW5nBAFzBQckbWF0Y2gwCQCmCAEFAXMDCQABAgUHJG1hdGNoMAIEVW5pdAUEdW5pdAkAAgECC01hdGNoIGVycm9yABFjYWxjdWxhdG9yQWRkcmVzcwkBE3ZhbHVlT3JFcnJvck1lc3NhZ2UCBRdjYWxjdWxhdG9yQWRkcmVzc09wdGlvbgkBB3dyYXBFcnIBAhppbnZhbGlkIGNhbGN1bGF0b3IgYWRkcmVzcwELbXVzdEFkZHJlc3MCAWkHYWRkcmVzcwMJAAACCAUBaQZjYWxsZXIFB2FkZHJlc3MGCQEIdGhyb3dFcnIBAhFwZXJtaXNzaW9uIGRlbmllZAEIbXVzdFRoaXMBAWkJAQttdXN0QWRkcmVzcwIFAWkFBHRoaXMBDm11c3RDYWxjdWxhdG9yAQFpCQELbXVzdEFkZHJlc3MCBQFpBRFjYWxjdWxhdG9yQWRkcmVzcwEMcGFyc2VBc3NldElkAQVpbnB1dAMJAAACBQVpbnB1dAULd2F2ZXNTdHJpbmcFBHVuaXQJANkEAQUFaW5wdXQBD2Fzc2V0SWRUb1N0cmluZwEFaW5wdXQDCQAAAgUFaW5wdXQFBHVuaXQFC3dhdmVzU3RyaW5nCQDYBAEJAQV2YWx1ZQEFBWlucHV0DAFpAQRpbml0ARRjYWxjdWxhdG9yQWRkcmVzc1N0cgQLY2hlY2tDYWxsZXIJAQhtdXN0VGhpcwEFAWkDCQAAAgULY2hlY2tDYWxsZXIFC2NoZWNrQ2FsbGVyCQCUCgIJAMwIAgkBC1N0cmluZ0VudHJ5AgUSa0NhbGN1bGF0b3JBZGRyZXNzBRRjYWxjdWxhdG9yQWRkcmVzc1N0cgUDbmlsBQR1bml0CQACAQIkU3RyaWN0IHZhbHVlIGlzIG5vdCBlcXVhbCB0byBpdHNlbGYuAWkBC3N0cmluZ0VudHJ5AgNrZXkDdmFsAwMJAQEhAQUIc2h1dGRvd24JAQ5tdXN0Q2FsY3VsYXRvcgEFAWkHCQCUCgIJAMwIAgkBC1N0cmluZ0VudHJ5AgUDa2V5BQN2YWwFA25pbAUDa2V5CQEIdGhyb3dFcnIBAgtub3QgYWxsb3dlZAFpAQxpbnRlZ2VyRW50cnkCA2tleQN2YWwDAwkBASEBBQhzaHV0ZG93bgkBDm11c3RDYWxjdWxhdG9yAQUBaQcJAJQKAgkAzAgCCQEMSW50ZWdlckVudHJ5AgUDa2V5BQN2YWwFA25pbAUDa2V5CQEIdGhyb3dFcnIBAgtub3QgYWxsb3dlZAFpAQxib29sZWFuRW50cnkCA2tleQN2YWwDAwkBASEBBQhzaHV0ZG93bgkBDm11c3RDYWxjdWxhdG9yAQUBaQcJAJQKAgkAzAgCCQEMQm9vbGVhbkVudHJ5AgUDa2V5BQN2YWwFA25pbAUDa2V5CQEIdGhyb3dFcnIBAgtub3QgYWxsb3dlZAFpAQtiaW5hcnlFbnRyeQIDa2V5A3ZhbAMDCQEBIQEFCHNodXRkb3duCQEObXVzdENhbGN1bGF0b3IBBQFpBwkAlAoCCQDMCAIJAQtCaW5hcnlFbnRyeQIFA2tleQUDdmFsBQNuaWwFA2tleQkBCHRocm93RXJyAQILbm90IGFsbG93ZWQBaQELZGVsZXRlRW50cnkBA2tleQMDCQEBIQEFCHNodXRkb3duCQEObXVzdENhbGN1bGF0b3IBBQFpBwkAlAoCCQDMCAIJAQtEZWxldGVFbnRyeQEFA2tleQUDbmlsBQNrZXkJAQh0aHJvd0VycgECC25vdCBhbGxvd2VkAWkBB3JlaXNzdWUDB2Fzc2V0SWQGYW1vdW50CnJlaXNzdWFibGUDAwkBASEBBQhzaHV0ZG93bgkBDm11c3RDYWxjdWxhdG9yAQUBaQcJAJQKAgkAzAgCCQEHUmVpc3N1ZQMFB2Fzc2V0SWQFBmFtb3VudAUKcmVpc3N1YWJsZQUDbmlsBQZhbW91bnQJAQh0aHJvd0VycgECC25vdCBhbGxvd2VkAWkBBGJ1cm4CB2Fzc2V0SWQGYW1vdW50AwMJAQEhAQUIc2h1dGRvd24JAQ5tdXN0Q2FsY3VsYXRvcgEFAWkHCQCUCgIJAMwIAgkBBEJ1cm4CBQdhc3NldElkBQZhbW91bnQFA25pbAUGYW1vdW50CQEIdGhyb3dFcnIBAgtub3QgYWxsb3dlZAFpAQ10cmFuc2ZlckFzc2V0Aw5yZWNpcGllbnRCeXRlcwZhbW91bnQHYXNzZXRJZAMDCQEBIQEFCHNodXRkb3duCQEObXVzdENhbGN1bGF0b3IBBQFpBwkAlAoCCQDMCAIJAQ5TY3JpcHRUcmFuc2ZlcgMJAQdBZGRyZXNzAQUOcmVjaXBpZW50Qnl0ZXMFBmFtb3VudAUHYXNzZXRJZAUDbmlsBQZhbW91bnQJAQh0aHJvd0VycgECC25vdCBhbGxvd2VkAWkBDnRyYW5zZmVyQXNzZXRzAw5yZWNpcGllbnRCeXRlcwphc3NldHNMaXN0C2Ftb3VudHNMaXN0AwMJAQEhAQUIc2h1dGRvd24JAQ5tdXN0Q2FsY3VsYXRvcgEFAWkHCgEOYWRkTmV3VHJhbnNmZXICA2FjYwtuZXh0QXNzZXRJZAQLJHQwMzEwNDMxMjgFA2FjYwQJdHJhbnNmZXJzCAULJHQwMzEwNDMxMjgCXzEEAWoIBQskdDAzMTA0MzEyOAJfMgQLbmV3VHJhbnNmZXIJAQ5TY3JpcHRUcmFuc2ZlcgMJAQdBZGRyZXNzAQUOcmVjaXBpZW50Qnl0ZXMJAJEDAgULYW1vdW50c0xpc3QFAWoJAJEDAgUKYXNzZXRzTGlzdAUBagQQdXBkYXRlZFRyYW5zZmVycwkAzQgCBQl0cmFuc2ZlcnMFC25ld1RyYW5zZmVyCQCUCgIFEHVwZGF0ZWRUcmFuc2ZlcnMJAGQCBQFqAAEECyR0MDMzNTQzNDM1CgACJGwFCmFzc2V0c0xpc3QKAAIkcwkAkAMBBQIkbAoABSRhY2MwCQCUCgIFA25pbAAACgEFJGYwXzECAiRhAiRpAwkAZwIFAiRpBQIkcwUCJGEJAQ5hZGROZXdUcmFuc2ZlcgIFAiRhCQCRAwIFAiRsBQIkaQoBBSRmMF8yAgIkYQIkaQMJAGcCBQIkaQUCJHMFAiRhCQACAQIUTGlzdCBzaXplIGV4Y2VlZHMgMTAJAQUkZjBfMgIJAQUkZjBfMQIJAQUkZjBfMQIJAQUkZjBfMQIJAQUkZjBfMQIJAQUkZjBfMQIJAQUkZjBfMQIJAQUkZjBfMQIJAQUkZjBfMQIJAQUkZjBfMQIJAQUkZjBfMQIFBSRhY2MwAAAAAQACAAMABAAFAAYABwAIAAkACgQPYXNzZXRzVHJhbnNmZXJzCAULJHQwMzM1NDM0MzUCXzEECl9sYXN0SW5kZXgIBQskdDAzMzU0MzQzNQJfMgkAlAoCBQ9hc3NldHNUcmFuc2ZlcnMFBHVuaXQJAQh0aHJvd0VycgECC25vdCBhbGxvd2VkAWkBDXRyYW5zZmVyV2F2ZXMCDnJlY2lwaWVudEJ5dGVzBmFtb3VudAMDCQEBIQEFCHNodXRkb3duCQEObXVzdENhbGN1bGF0b3IBBQFpBwkAlAoCCQDMCAIJAQ5TY3JpcHRUcmFuc2ZlcgMJAQdBZGRyZXNzAQUOcmVjaXBpZW50Qnl0ZXMFBmFtb3VudAUEdW5pdAUDbmlsBQZhbW91bnQJAQh0aHJvd0VycgECC25vdCBhbGxvd2VkAWkBBGNhbGwCCGZ1bmN0aW9uBGFyZ3MEDWNsZWFuUGF5bWVudHMDCQAAAggFAWkPY2FsbGVyUHVibGljS2V5ASAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUDbmlsCAUBaQhwYXltZW50cwQGcmVzdWx0CQD9BwQFEWNhbGN1bGF0b3JBZGRyZXNzBQhmdW5jdGlvbgkAzAgCCAUBaQ9jYWxsZXJQdWJsaWNLZXkJAMwIAgUEYXJncwUDbmlsBQ1jbGVhblBheW1lbnRzCQCUCgIFA25pbAUGcmVzdWx0AGelHiA=", "chainId": 84, "height": 3297271, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: A9MF7eiEdrTN3nNz9cpyQ4YeR38xeFQS5osguQwMyJpY Next: 4j9ZJFaRvwQuJWwK5ZPG66uCAgdExnk5aNDgitknDCWq Diff:
Old | New | Differences | |
---|---|---|---|
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let separator = "__" | |
5 | 5 | ||
6 | - | let chainId = take(drop(this.bytes, 1), 1) | |
7 | - | ||
8 | - | let chainIdW = base58'2W' | |
9 | - | ||
10 | - | let contractFilename = "futures_calculator.ride" | |
11 | - | ||
12 | - | let mult8 = 100000000 | |
13 | - | ||
14 | - | let mult18BigInt = toBigInt(1000000000000000000) | |
15 | - | ||
16 | - | let wavesDecimals = 8 | |
17 | - | ||
18 | - | let usdtDecimals = 6 | |
19 | - | ||
20 | 6 | let wavesString = "WAVES" | |
21 | 7 | ||
22 | - | let queueItemSize = 32 | |
23 | - | ||
24 | - | let big0 = toBigInt(0) | |
25 | - | ||
26 | - | let INDEX_LIST = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19] | |
27 | - | ||
28 | - | let kMultisig = "%s__multisig" | |
29 | - | ||
30 | - | func kStatus (dapp,txId) = makeString(["%s__status", dapp, txId], separator) | |
31 | - | ||
8 | + | let contractFilename = "meme_im_factory.ride" | |
32 | 9 | ||
33 | 10 | let kShutdown = "%s__shutdown" | |
34 | 11 | ||
35 | - | let kPublicKeys = "%s__publicKeys" | |
36 | - | ||
37 | - | let kMatcherPublicKey = "%s__matcherPublicKey" | |
38 | - | ||
39 | - | func toX18 (origVal,origScaleMult) = fraction(toBigInt(origVal), mult18BigInt, toBigInt(origScaleMult)) | |
40 | - | ||
41 | - | ||
42 | - | func fromX18 (val,resultScaleMult) = toInt(fraction(val, toBigInt(resultScaleMult), mult18BigInt)) | |
43 | - | ||
44 | - | ||
45 | - | func validateAddress (address) = isDefined(addressFromString(address)) | |
46 | - | ||
12 | + | let shutdown = valueOrElse(getBoolean(kShutdown), false) | |
47 | 13 | ||
48 | 14 | func wrapErr (s) = ((contractFilename + ": ") + s) | |
49 | 15 | ||
51 | 17 | func throwErr (s) = throw(wrapErr(s)) | |
52 | 18 | ||
53 | 19 | ||
54 | - | func ensurePositive (v,s) = if ((v >= 0)) | |
55 | - | then v | |
56 | - | else throwErr((s + " value should be positive")) | |
20 | + | func validateAddress (address) = isDefined(addressFromString(address)) | |
21 | + | ||
22 | + | ||
23 | + | let kCalculatorAddress = "calculator__address" | |
24 | + | ||
25 | + | let calculatorAddressOption = match getString(this, kCalculatorAddress) { | |
26 | + | case s: String => | |
27 | + | addressFromString(s) | |
28 | + | case _: Unit => | |
29 | + | unit | |
30 | + | case _ => | |
31 | + | throw("Match error") | |
32 | + | } | |
33 | + | ||
34 | + | let calculatorAddress = valueOrErrorMessage(calculatorAddressOption, wrapErr("invalid calculator address")) | |
35 | + | ||
36 | + | func mustAddress (i,address) = if ((i.caller == address)) | |
37 | + | then true | |
38 | + | else throwErr("permission denied") | |
39 | + | ||
40 | + | ||
41 | + | func mustThis (i) = mustAddress(i, this) | |
42 | + | ||
43 | + | ||
44 | + | func mustCalculator (i) = mustAddress(i, calculatorAddress) | |
57 | 45 | ||
58 | 46 | ||
59 | 47 | func parseAssetId (input) = if ((input == wavesString)) | |
66 | 54 | else toBase58String(value(input)) | |
67 | 55 | ||
68 | 56 | ||
69 | - | func getAssetInfoOrFail (assetId) = valueOrErrorMessage(assetInfo(assetId), wrapErr("invalid asset info")) | |
70 | - | ||
71 | - | ||
72 | - | func getAssetDecimalsOrFail (assetId) = match assetId { | |
73 | - | case _: Unit => | |
74 | - | wavesDecimals | |
75 | - | case assetId: ByteVector => | |
76 | - | getAssetInfoOrFail(assetId).decimals | |
77 | - | case _ => | |
78 | - | throw("Match error") | |
79 | - | } | |
80 | - | ||
81 | - | ||
82 | - | func getAssetBalance (assetId,address) = match assetId { | |
83 | - | case _: Unit => | |
84 | - | wavesBalance(address).available | |
85 | - | case assetId: ByteVector => | |
86 | - | assetBalance(address, assetId) | |
87 | - | case _ => | |
88 | - | throw("Match error") | |
89 | - | } | |
90 | - | ||
91 | - | ||
92 | - | func pow10 (n) = pow(10, 0, n, 0, 0, DOWN) | |
93 | - | ||
94 | - | ||
95 | - | func pow10Decimals (assetId) = pow10(getAssetDecimalsOrFail(assetId)) | |
96 | - | ||
97 | - | ||
98 | - | let kFactoryAddress = "%s__factoryAddress" | |
99 | - | ||
100 | - | let factoryAddressOption = match getString(this, kFactoryAddress) { | |
101 | - | case s: String => | |
102 | - | addressFromString(s) | |
103 | - | case _: Unit => | |
104 | - | unit | |
105 | - | case _ => | |
106 | - | throw("Match error") | |
107 | - | } | |
108 | - | ||
109 | - | let factoryAddress = valueOrErrorMessage(factoryAddressOption, wrapErr("invalid factory address")) | |
110 | - | ||
111 | - | let kUsdtAssetId = "%s__usdtAssetId" | |
112 | - | ||
113 | - | let usdtAssetIdOption = match getString(factoryAddress, kUsdtAssetId) { | |
114 | - | case s: String => | |
115 | - | parseAssetId(s) | |
116 | - | case _: Unit => | |
117 | - | unit | |
118 | - | case _ => | |
119 | - | throw("Match error") | |
120 | - | } | |
121 | - | ||
122 | - | let usdtAssetId = valueOrErrorMessage(usdtAssetIdOption, wrapErr("invalid usdt asset id")) | |
123 | - | ||
124 | - | let kPricesAddress = "%s__calculatorAddress" | |
125 | - | ||
126 | - | let shutdown = valueOrElse(getBoolean(factoryAddress, kShutdown), false) | |
127 | - | ||
128 | - | func mustAddress (caller,address) = if ((caller == address)) | |
129 | - | then true | |
130 | - | else throwErr("permission denied") | |
131 | - | ||
132 | - | ||
133 | - | func mustThis (caller) = mustAddress(caller, this) | |
134 | - | ||
135 | - | ||
136 | - | func mustFactory (caller) = mustAddress(caller, factoryAddress) | |
137 | - | ||
138 | - | ||
139 | - | func mustAdmin (callerPublicKey) = { | |
140 | - | let multisigAddressString = getString(factoryAddress, kMultisig) | |
141 | - | let isAdmin = match multisigAddressString { | |
142 | - | case addressString: String => | |
143 | - | let multisig = addressFromStringValue(addressString) | |
144 | - | let publicKeysList = split(getStringValue(multisig, kPublicKeys), separator) | |
145 | - | containsElement(publicKeysList, toBase58String(callerPublicKey)) | |
146 | - | case _ => | |
147 | - | (addressFromPublicKey(callerPublicKey) == factoryAddress) | |
148 | - | } | |
149 | - | if (isAdmin) | |
150 | - | then true | |
151 | - | else throwErr("not allowed") | |
152 | - | } | |
153 | - | ||
154 | - | ||
155 | - | let kAccountScript = "%s__accountScript" | |
156 | - | ||
157 | - | func accountScript () = valueOrErrorMessage(getBinary(factoryAddress, kAccountScript), wrapErr("account script is not set")) | |
158 | - | ||
159 | - | ||
160 | - | let kRewardAmount = "%s__rewardAmount" | |
161 | - | ||
162 | - | func rewardAmount () = valueOrErrorMessage(getInteger(factoryAddress, kRewardAmount), wrapErr("reward amount is not set")) | |
163 | - | ||
164 | - | ||
165 | - | let kAccountsLimit = "%s__accountsLimit" | |
166 | - | ||
167 | - | let accountsLimitDefault = 20 | |
168 | - | ||
169 | - | func accountsLimit () = valueOrElse(getInteger(factoryAddress, kAccountsLimit), accountsLimitDefault) | |
170 | - | ||
171 | - | ||
172 | - | func kDeposited (accountAddress) = makeString(["%s%s", "deposited", toString(accountAddress)], separator) | |
173 | - | ||
174 | - | ||
175 | - | func depositedOption (accountAddress) = getInteger(factoryAddress, kDeposited(accountAddress)) | |
176 | - | ||
177 | - | ||
178 | - | func kCredit (accountAddress,assetId) = makeString(["%s%s%s", "credit", toString(accountAddress), assetIdToString(assetId)], separator) | |
179 | - | ||
180 | - | ||
181 | - | func creditOption (accountAddress,assetId) = getInteger(factoryAddress, kCredit(accountAddress, assetId)) | |
182 | - | ||
183 | - | ||
184 | - | func kLeverage (accountAddress) = makeString(["%s%s", "leverage", toString(accountAddress)], separator) | |
185 | - | ||
186 | - | ||
187 | - | func kRequestLeverage (requestId) = makeString(["%s%s", "requestLeverage", toBase58String(requestId)], separator) | |
188 | - | ||
189 | - | ||
190 | - | func kSyntheticAssetId (baseAssetId) = makeString(["%s%s", "syntheticAssetId", assetIdToString(baseAssetId)], separator) | |
191 | - | ||
192 | - | ||
193 | - | func kBaseAssetId (syntheticAssetId) = makeString(["%s%s", "baseAssetId", assetIdToString(syntheticAssetId)], separator) | |
194 | - | ||
195 | - | ||
196 | - | let REQUEST_STATUS_EMPTY = 0 | |
197 | - | ||
198 | - | let REQUEST_STATUS_READY = 1 | |
199 | - | ||
200 | - | func kRequestStatus (requestId) = makeString(["%s%s", toBase58String(requestId), "status"], separator) | |
201 | - | ||
202 | - | ||
203 | - | func kAccountCreatorPublicKey (accountAddress) = makeString(["%s%s", toString(accountAddress), "creatorPublicKey"], separator) | |
204 | - | ||
205 | - | ||
206 | - | func kRequestOwnerPublicKey (requestId) = makeString(["%s%s", toBase58String(requestId), "ownerPublicKey"], separator) | |
207 | - | ||
208 | - | ||
209 | - | func kRequestAmountAssetId (requestId) = makeString(["%s%s", toBase58String(requestId), "amountAssetId"], separator) | |
210 | - | ||
211 | - | ||
212 | - | func kRequestPriceAssetId (requestId) = makeString(["%s%s", toBase58String(requestId), "priceAssetId"], separator) | |
213 | - | ||
214 | - | ||
215 | - | func kRequestIdToAccountPublicKey (requestId) = makeString(["%s%s", toBase58String(requestId), "requestIdToAccountPublicKey"], separator) | |
216 | - | ||
217 | - | ||
218 | - | func kAccountAddressToRequestId (accountAddress) = makeString(["%s%s", toString(accountAddress), "accountAddressToRequestId"], separator) | |
219 | - | ||
220 | - | ||
221 | - | func kRequestsQueue () = makeString(["%s", "requestsQueue"], separator) | |
222 | - | ||
223 | - | ||
224 | - | func requestsQueue () = valueOrElse(getBinary(factoryAddress, kRequestsQueue()), base58'') | |
225 | - | ||
226 | - | ||
227 | - | func kRequestsByOwner (ownerAddress) = makeString(["%s%s", "requests", toString(ownerAddress)], separator) | |
228 | - | ||
229 | - | ||
230 | - | func requestsByOwner (ownerAddress) = valueOrElse(getBinary(factoryAddress, kRequestsByOwner(ownerAddress)), base58'') | |
231 | - | ||
232 | - | ||
233 | - | func kPairAllowed (amountAssetId,priceAssetId) = makeString(["%s%s%s", assetIdToString(amountAssetId), assetIdToString(priceAssetId), "pairAllowed"], separator) | |
234 | - | ||
235 | - | ||
236 | - | func pairAllowed (amountAssetId,priceAssetId) = valueOrElse(getBoolean(factoryAddress, kPairAllowed(amountAssetId, priceAssetId)), false) | |
237 | - | ||
238 | - | ||
239 | - | func kPrice (assetId) = makeString(["%s", assetIdToString(assetId)], separator) | |
240 | - | ||
241 | - | ||
242 | - | func kPairPricesListKey (amountAssetId,priceAssetId) = makeString(["%s%s%s", assetIdToString(amountAssetId), assetIdToString(priceAssetId), "pairSettingPrices"], separator) | |
243 | - | ||
244 | - | ||
245 | - | func getPairPricesList (amountAssetId,priceAssetId) = match getString(factoryAddress, kPairPricesListKey(amountAssetId, priceAssetId)) { | |
246 | - | case s: String => | |
247 | - | split(s, separator) | |
248 | - | case _ => | |
249 | - | nil | |
250 | - | } | |
251 | - | ||
252 | - | ||
253 | - | func kPairSettingsKey (amountAssetId,priceAssetId,priceString) = makeString(["%s%s%d%s", assetIdToString(amountAssetId), assetIdToString(priceAssetId), priceString, "settings"], separator) | |
254 | - | ||
255 | - | ||
256 | - | func getCurrentPrice (assetId) = { | |
257 | - | let matcherPublicKey = fromBase58String(valueOrErrorMessage(getString(factoryAddress, kMatcherPublicKey), wrapErr("invalid matcher public key"))) | |
258 | - | let matcherAddress = addressFromPublicKey(matcherPublicKey) | |
259 | - | let price = valueOrErrorMessage(getInteger(matcherAddress, kPrice(assetId)), wrapErr(("invalid price, assetId = " + assetIdToString(assetId)))) | |
260 | - | price | |
261 | - | } | |
262 | - | ||
263 | - | ||
264 | - | func calcTotalCredit (creditA,creditB,currentPrice) = (fraction(creditA, currentPrice, mult18BigInt) + creditB) | |
265 | - | ||
266 | - | ||
267 | - | func calcTotalBalance (balanceA,balanceB,currentPrice) = (fraction(balanceA, currentPrice, mult18BigInt) + balanceB) | |
268 | - | ||
269 | - | ||
270 | - | func calcPnl (totalBalance,totalCredit) = (totalBalance - totalCredit) | |
271 | - | ||
272 | - | ||
273 | - | func calcCreditAvailable (deposit,leverage,totalCredit) = (fraction(deposit, leverage, mult18BigInt) - totalCredit) | |
274 | - | ||
275 | - | ||
276 | - | func calcRealInCredit (credit,balance) = if ((credit > big0)) | |
277 | - | then (credit - balance) | |
278 | - | else big0 | |
279 | - | ||
280 | - | ||
281 | - | func calcFree (credit,balance) = if ((credit > big0)) | |
282 | - | then (balance - credit) | |
283 | - | else big0 | |
284 | - | ||
285 | - | ||
286 | - | func calcShortPrice (free,realInCredit) = if ((realInCredit > big0)) | |
287 | - | then max([big0, fraction(free, mult18BigInt, realInCredit)]) | |
288 | - | else big0 | |
289 | - | ||
290 | - | ||
291 | - | func calcLongPrice (free,realInCredit) = if ((realInCredit > big0)) | |
292 | - | then max([big0, fraction(realInCredit, mult18BigInt, free)]) | |
293 | - | else big0 | |
294 | - | ||
295 | - | ||
296 | - | func calcStartMargin (realInCreditA,realInCreditB,currentPrice,settingsMargin) = fraction((fraction(realInCreditA, currentPrice, mult18BigInt) + realInCreditB), settingsMargin, mult18BigInt) | |
297 | - | ||
298 | - | ||
299 | - | func calcMarginSupply (settingsMarginSupply,settingsMargin,startMargin) = fraction(settingsMarginSupply, startMargin, settingsMargin) | |
300 | - | ||
301 | - | ||
302 | - | func calcLiquidationPrice (deposit,marginSupply,realInCreditA,realInCreditB,shortPrice,longPrice) = { | |
303 | - | let liquidationPriceA = if ((realInCreditA > big0)) | |
304 | - | then (((deposit - marginSupply) / realInCreditA) + shortPrice) | |
305 | - | else big0 | |
306 | - | let liquidationPriceB = if ((realInCreditB > big0)) | |
307 | - | then (longPrice - ((deposit - marginSupply) / (realInCreditA / longPrice))) | |
308 | - | else big0 | |
309 | - | (liquidationPriceA + liquidationPriceB) | |
310 | - | } | |
311 | - | ||
312 | - | ||
313 | - | func getRequestId (accountAddress) = { | |
314 | - | let requestId = fromBase58String(valueOrErrorMessage(getString(factoryAddress, kAccountAddressToRequestId(accountAddress)), wrapErr("invalid account address: request id is undefined"))) | |
315 | - | requestId | |
316 | - | } | |
317 | - | ||
318 | - | ||
319 | - | func getAccountAssets (accountAddress) = { | |
320 | - | let requestId = getRequestId(accountAddress) | |
321 | - | let amountAssetId = parseAssetId(valueOrErrorMessage(getString(factoryAddress, kRequestAmountAssetId(requestId)), wrapErr("invalid amount asset id"))) | |
322 | - | let priceAssetId = parseAssetId(valueOrErrorMessage(getString(factoryAddress, kRequestPriceAssetId(requestId)), wrapErr("invalid amount price id"))) | |
323 | - | $Tuple2(amountAssetId, priceAssetId) | |
324 | - | } | |
325 | - | ||
326 | - | ||
327 | - | func getAccountOwnerPublicKey (accountAddress) = { | |
328 | - | let requestId = getRequestId(accountAddress) | |
329 | - | let requestOwnerPublicKey = valueOrErrorMessage(getBinary(factoryAddress, kRequestOwnerPublicKey(requestId)), wrapErr("invalid amount asset id")) | |
330 | - | requestOwnerPublicKey | |
331 | - | } | |
332 | - | ||
333 | - | ||
334 | - | func getAccountInfoInternal (accountAddress) = { | |
335 | - | let $t01125511323 = getAccountAssets(accountAddress) | |
336 | - | let amountAssetId = $t01125511323._1 | |
337 | - | let priceAssetId = $t01125511323._2 | |
338 | - | let leverage = valueOrErrorMessage(getInteger(factoryAddress, kLeverage(accountAddress)), wrapErr("leverage should be defined")) | |
339 | - | let requestId = getRequestId(accountAddress) | |
340 | - | let accountPublicKey = valueOrErrorMessage(getBinary(factoryAddress, kRequestIdToAccountPublicKey(requestId)), "kRequestIdToAccountPublicKey not found") | |
341 | - | let deposited = valueOrElse(depositedOption(accountAddress), 0) | |
342 | - | let currentPrice = toX18(getCurrentPrice(amountAssetId), pow10Decimals(priceAssetId)) | |
343 | - | let creditA = valueOrElse(getInteger(factoryAddress, kCredit(accountAddress, amountAssetId)), 0) | |
344 | - | let creditB = valueOrElse(getInteger(factoryAddress, kCredit(accountAddress, priceAssetId)), 0) | |
345 | - | let status = valueOrErrorMessage(getInteger(factoryAddress, kRequestStatus(requestId)), ("status not found. RequestId = " + toBase58String(requestId))) | |
346 | - | let synthAmountAssetId = getString(factoryAddress, kSyntheticAssetId(amountAssetId)) | |
347 | - | let synthAmountAssetBalance = match synthAmountAssetId { | |
348 | - | case s: String => | |
349 | - | getAssetBalance(parseAssetId(s), accountAddress) | |
350 | - | case _ => | |
351 | - | 0 | |
352 | - | } | |
353 | - | let synthPriceAssetId = getString(factoryAddress, kSyntheticAssetId(priceAssetId)) | |
354 | - | let synthPriceAssetBalance = match synthPriceAssetId { | |
355 | - | case s: String => | |
356 | - | getAssetBalance(parseAssetId(s), accountAddress) | |
357 | - | case _ => | |
358 | - | 0 | |
359 | - | } | |
360 | - | $Tuple12(assetIdToString(amountAssetId), assetIdToString(priceAssetId), toString(accountAddress), toBase58String(accountPublicKey), leverage, toBase58String(requestId), deposited, creditA, creditB, synthAmountAssetBalance, synthPriceAssetBalance, status) | |
361 | - | } | |
362 | - | ||
363 | - | ||
364 | - | func depositINTERNAL (callerPublicKey,args,i) = { | |
365 | - | let payment = i.payments[0] | |
366 | - | let accountAddress = valueOrErrorMessage(addressFromString(args[0]), wrapErr("invalid account address")) | |
367 | - | let ckecks = [if (!(shutdown)) | |
368 | - | then true | |
369 | - | else throwErr("not allowed"), mustFactory(i.caller), if ((size(i.payments) == 1)) | |
370 | - | then true | |
371 | - | else throwErr("1 payment is required"), if ((payment.assetId == usdtAssetId)) | |
372 | - | then true | |
373 | - | else throwErr("invalid asset"), if ((getInteger(factoryAddress, kRequestStatus(getRequestId(accountAddress))) == REQUEST_STATUS_READY)) | |
374 | - | then true | |
375 | - | else throwErr("account is not ready")] | |
376 | - | if ((ckecks == ckecks)) | |
377 | - | then { | |
378 | - | let actions = [ScriptTransfer(accountAddress, payment.amount, payment.assetId)] | |
379 | - | let factoryActions = [invoke(factoryAddress, "integerEntry", [kDeposited(accountAddress), (valueOrElse(depositedOption(accountAddress), 0) + payment.amount)], nil)] | |
380 | - | $Tuple2(actions, factoryActions) | |
381 | - | } | |
382 | - | else throw("Strict value is not equal to itself.") | |
383 | - | } | |
384 | - | ||
385 | - | ||
386 | - | func borrowINTERNAL (callerPublicKey,args,i) = { | |
387 | - | let accountAddress = valueOrErrorMessage(addressFromString(args[0]), wrapErr("invalid account address")) | |
388 | - | let assetIdRequested = parseAssetId(args[1]) | |
389 | - | let amountRequested = ensurePositive(valueOrErrorMessage(parseInt(args[2]), wrapErr("invalid requested amount")), "requested amount") | |
390 | - | let accountOwnerPublicKey = getAccountOwnerPublicKey(accountAddress) | |
391 | - | let userAddress = addressFromPublicKey(callerPublicKey) | |
392 | - | let ckecks = [if (!(shutdown)) | |
393 | - | then true | |
394 | - | else throwErr("not allowed"), mustFactory(i.caller), if ((callerPublicKey == accountOwnerPublicKey)) | |
395 | - | then true | |
396 | - | else throwErr("can be called by account owner only")] | |
397 | - | if ((ckecks == ckecks)) | |
398 | - | then { | |
399 | - | let amountAssetId = getAccountAssets(accountAddress)._1 | |
400 | - | let deposited = toX18(valueOrElse(depositedOption(accountAddress), 0), pow10Decimals(usdtAssetId)) | |
401 | - | let currentPrice = toX18(getCurrentPrice(amountAssetId), pow10Decimals(usdtAssetId)) | |
402 | - | let creditA = toX18(valueOrElse(getInteger(factoryAddress, kCredit(accountAddress, amountAssetId)), 0), pow10Decimals(amountAssetId)) | |
403 | - | let creditB = toX18(valueOrElse(getInteger(factoryAddress, kCredit(accountAddress, usdtAssetId)), 0), pow10Decimals(usdtAssetId)) | |
404 | - | let totalCredit = calcTotalCredit(creditA, creditB, currentPrice) | |
405 | - | let leverage = toX18(valueOrErrorMessage(getInteger(factoryAddress, kLeverage(accountAddress)), wrapErr("leverage should be defined")), 1) | |
406 | - | let creditAvailableUsdt = calcCreditAvailable(deposited, leverage, totalCredit) | |
407 | - | let creditAvailable = if ((assetIdRequested == amountAssetId)) | |
408 | - | then fromX18(fraction(creditAvailableUsdt, mult18BigInt, currentPrice), pow10Decimals(amountAssetId)) | |
409 | - | else if ((assetIdRequested == usdtAssetId)) | |
410 | - | then fromX18(creditAvailableUsdt, pow10Decimals(usdtAssetId)) | |
411 | - | else throwErr("invalid requested asset id") | |
412 | - | let syntheticAssetId = parseAssetId(valueOrErrorMessage(getString(factoryAddress, kSyntheticAssetId(assetIdRequested)), wrapErr("synthetic asset for requested asset is undefined"))) | |
413 | - | let amountToSend = if ((creditAvailable >= amountRequested)) | |
414 | - | then amountRequested | |
415 | - | else throwErr(("credit available = " + toString(creditAvailable))) | |
416 | - | let factoryActions = [invoke(factoryAddress, "integerEntry", [kCredit(accountAddress, assetIdRequested), (valueOrElse(creditOption(accountAddress, assetIdRequested), 0) + amountToSend)], nil), invoke(factoryAddress, "transferAsset", [accountAddress.bytes, amountToSend, syntheticAssetId], nil)] | |
417 | - | $Tuple2(nil, [factoryActions, creditAvailable]) | |
418 | - | } | |
419 | - | else throw("Strict value is not equal to itself.") | |
420 | - | } | |
421 | - | ||
422 | - | ||
423 | 57 | @Callable(i) | |
424 | - | func init ( | |
425 | - | let checkCaller = mustThis(i | |
58 | + | func init (calculatorAddressStr) = { | |
59 | + | let checkCaller = mustThis(i) | |
426 | 60 | if ((checkCaller == checkCaller)) | |
427 | - | then $Tuple2([StringEntry( | |
61 | + | then $Tuple2([StringEntry(kCalculatorAddress, calculatorAddressStr)], unit) | |
428 | 62 | else throw("Strict value is not equal to itself.") | |
429 | 63 | } | |
430 | 64 | ||
431 | 65 | ||
432 | 66 | ||
433 | 67 | @Callable(i) | |
434 | - | func requestAccount (callerPublicKey,args) = { | |
435 | - | let ckecks = [if (!(shutdown)) | |
436 | - | then true | |
437 | - | else throwErr("not allowed"), mustFactory(i.caller)] | |
438 | - | if ((ckecks == ckecks)) | |
439 | - | then { | |
440 | - | let amountAssetIdStr = args[0] | |
441 | - | let priceAssetIdStr = args[1] | |
442 | - | let leverage = valueOrErrorMessage(parseInt(args[2]), wrapErr("invalid leverage")) | |
443 | - | let userAddress = addressFromPublicKey(callerPublicKey) | |
444 | - | let requestId = sha256(i.transactionId) | |
445 | - | let amountAssetId = parseAssetId(amountAssetIdStr) | |
446 | - | let priceAssetId = parseAssetId(priceAssetIdStr) | |
447 | - | let userRequestsNumber = (size(kRequestsByOwner(userAddress)) / queueItemSize) | |
448 | - | let checks = [if ((size(i.payments) == 1)) | |
449 | - | then true | |
450 | - | else throwErr("1 payment is required"), if ((i.payments[0].assetId == unit)) | |
451 | - | then true | |
452 | - | else throwErr("invalid asset"), if ((i.payments[0].amount == rewardAmount())) | |
453 | - | then true | |
454 | - | else throwErr("invalid amount"), if (pairAllowed(amountAssetId, priceAssetId)) | |
455 | - | then true | |
456 | - | else throwErr("pair is not allowed"), if ((leverage == 2)) | |
457 | - | then true | |
458 | - | else throwErr("leverage is not allowed"), if ((getInteger(factoryAddress, kRequestStatus(requestId)) == unit)) | |
459 | - | then true | |
460 | - | else throwErr("account is already exists"), if ((accountsLimit() > userRequestsNumber)) | |
461 | - | then true | |
462 | - | else throwErr(("accounts limit is " + toString(accountsLimit())))] | |
463 | - | if ((checks == checks)) | |
464 | - | then { | |
465 | - | let actions = [ScriptTransfer(factoryAddress, rewardAmount(), unit)] | |
466 | - | $Tuple2(actions, [invoke(factoryAddress, "integerEntry", [kRequestStatus(requestId), REQUEST_STATUS_EMPTY], nil), invoke(factoryAddress, "binaryEntry", [kRequestsQueue(), (requestsQueue() + requestId)], nil), invoke(factoryAddress, "binaryEntry", [kRequestsByOwner(userAddress), (requestsByOwner(userAddress) + requestId)], nil), invoke(factoryAddress, "binaryEntry", [kRequestOwnerPublicKey(requestId), callerPublicKey], nil), invoke(factoryAddress, "stringEntry", [kRequestAmountAssetId(requestId), amountAssetIdStr], nil), invoke(factoryAddress, "stringEntry", [kRequestPriceAssetId(requestId), priceAssetIdStr], nil), invoke(factoryAddress, "integerEntry", [kRequestLeverage(requestId), leverage], nil)]) | |
467 | - | } | |
468 | - | else throw("Strict value is not equal to itself.") | |
469 | - | } | |
470 | - | else throw("Strict value is not equal to itself.") | |
471 | - | } | |
68 | + | func stringEntry (key,val) = if (if (!(shutdown)) | |
69 | + | then mustCalculator(i) | |
70 | + | else false) | |
71 | + | then $Tuple2([StringEntry(key, val)], key) | |
72 | + | else throwErr("not allowed") | |
472 | 73 | ||
473 | 74 | ||
474 | 75 | ||
475 | 76 | @Callable(i) | |
476 | - | func editAccount (callerPublicKey,args) = { | |
477 | - | let accountAddress = valueOrErrorMessage(addressFromString(args[0]), wrapErr("invalid account address")) | |
478 | - | let amountAssetIdStr = args[1] | |
479 | - | let priceAssetIdStr = args[2] | |
480 | - | let leverage = valueOrErrorMessage(parseInt(args[3]), wrapErr("invalid leverage")) | |
481 | - | let requestId = getRequestId(accountAddress) | |
482 | - | let ownerPublicKey = getAccountOwnerPublicKey(accountAddress) | |
483 | - | let amountAssetId = parseAssetId(amountAssetIdStr) | |
484 | - | let priceAssetId = parseAssetId(priceAssetIdStr) | |
485 | - | let checks = [if (!(shutdown)) | |
486 | - | then true | |
487 | - | else throwErr("not allowed"), mustFactory(i.caller), if ((callerPublicKey == ownerPublicKey)) | |
488 | - | then true | |
489 | - | else throwErr("caller is not an account owner"), if (pairAllowed(amountAssetId, priceAssetId)) | |
490 | - | then true | |
491 | - | else throwErr("pair is not allowed"), if ((leverage == 2)) | |
492 | - | then true | |
493 | - | else throwErr("leverage is not allowed"), if ((getInteger(factoryAddress, kRequestStatus(requestId)) == REQUEST_STATUS_READY)) | |
494 | - | then true | |
495 | - | else throwErr("account is not ready")] | |
496 | - | if ((checks == checks)) | |
497 | - | then $Tuple2(nil, [invoke(factoryAddress, "stringEntry", [kRequestAmountAssetId(requestId), amountAssetIdStr], nil), invoke(factoryAddress, "stringEntry", [kRequestPriceAssetId(requestId), priceAssetIdStr], nil), invoke(factoryAddress, "integerEntry", [kRequestLeverage(requestId), leverage], nil)]) | |
498 | - | else throw("Strict value is not equal to itself.") | |
499 | - | } | |
77 | + | func integerEntry (key,val) = if (if (!(shutdown)) | |
78 | + | then mustCalculator(i) | |
79 | + | else false) | |
80 | + | then $Tuple2([IntegerEntry(key, val)], key) | |
81 | + | else throwErr("not allowed") | |
500 | 82 | ||
501 | 83 | ||
502 | 84 | ||
503 | 85 | @Callable(i) | |
504 | - | func addAccount (callerPublicKey,args) = { | |
505 | - | let ckecks = [if (!(shutdown)) | |
506 | - | then true | |
507 | - | else throwErr("not allowed"), mustFactory(i.caller)] | |
508 | - | if ((ckecks == ckecks)) | |
509 | - | then { | |
510 | - | let creatorPublicKey = fromBase58String(args[0]) | |
511 | - | let accountPublicKey = callerPublicKey | |
512 | - | let accountAddress = addressFromPublicKey(callerPublicKey) | |
513 | - | let creatorAddress = addressFromPublicKey(creatorPublicKey) | |
514 | - | let checks = [if ((getBinary(factoryAddress, kAccountCreatorPublicKey(accountAddress)) == unit)) | |
515 | - | then true | |
516 | - | else throwErr("account is already exists"), if ( match scriptHash(accountAddress) { | |
517 | - | case b: ByteVector => | |
518 | - | (b == blake2b256_32Kb(accountScript())) | |
519 | - | case _ => | |
520 | - | false | |
521 | - | }) | |
522 | - | then true | |
523 | - | else throwErr("invalid script")] | |
524 | - | if ((checks == checks)) | |
525 | - | then { | |
526 | - | let $t02126422409 = if ((size(requestsQueue()) == 0)) | |
527 | - | then $Tuple2(throwErr("requests queue is empty"), nil) | |
528 | - | else { | |
529 | - | let requestId = take(requestsQueue(), queueItemSize) | |
530 | - | let leverage = valueOrErrorMessage(getInteger(factoryAddress, kRequestLeverage(requestId)), wrapErr("request's leverage is undefined")) | |
531 | - | $Tuple2(nil, [invoke(factoryAddress, "integerEntry", [kRequestStatus(requestId), REQUEST_STATUS_READY], nil), invoke(factoryAddress, "binaryEntry", [kRequestIdToAccountPublicKey(requestId), accountPublicKey], nil), invoke(factoryAddress, "binaryEntry", [kRequestsQueue(), drop(requestsQueue(), queueItemSize)], nil), invoke(factoryAddress, "stringEntry", [kAccountAddressToRequestId(accountAddress), toBase58String(requestId)], nil), invoke(factoryAddress, "transferWaves", [creatorAddress.bytes, rewardAmount()], nil), invoke(factoryAddress, "integerEntry", [kLeverage(accountAddress), leverage], nil)]) | |
532 | - | } | |
533 | - | let actions = $t02126422409._1 | |
534 | - | let factoryActions = $t02126422409._2 | |
535 | - | $Tuple2(actions, (factoryActions ++ [invoke(factoryAddress, "binaryEntry", [kAccountCreatorPublicKey(accountAddress), creatorPublicKey], nil)])) | |
536 | - | } | |
537 | - | else throw("Strict value is not equal to itself.") | |
538 | - | } | |
539 | - | else throw("Strict value is not equal to itself.") | |
540 | - | } | |
86 | + | func booleanEntry (key,val) = if (if (!(shutdown)) | |
87 | + | then mustCalculator(i) | |
88 | + | else false) | |
89 | + | then $Tuple2([BooleanEntry(key, val)], key) | |
90 | + | else throwErr("not allowed") | |
541 | 91 | ||
542 | 92 | ||
543 | 93 | ||
544 | 94 | @Callable(i) | |
545 | - | func withdraw (callerPublicKey,args) = { | |
546 | - | let checks = [if (!(shutdown)) | |
547 | - | then true | |
548 | - | else throwErr("not allowed"), mustFactory(i.caller)] | |
549 | - | if ((checks == checks)) | |
550 | - | then { | |
551 | - | let userAddress = addressFromPublicKey(callerPublicKey) | |
552 | - | let accountAddress = valueOrErrorMessage(addressFromString(args[0]), wrapErr("invalid account address")) | |
553 | - | let amount = valueOrErrorMessage(parseInt(args[1]), wrapErr("invalid amount")) | |
554 | - | let assetId = parseAssetId(args[2]) | |
555 | - | let invocations = [invoke(accountAddress, "transferAsset", [userAddress.bytes, amount, assetId], nil)] | |
556 | - | $Tuple2(nil, invocations) | |
557 | - | } | |
558 | - | else throw("Strict value is not equal to itself.") | |
559 | - | } | |
95 | + | func binaryEntry (key,val) = if (if (!(shutdown)) | |
96 | + | then mustCalculator(i) | |
97 | + | else false) | |
98 | + | then $Tuple2([BinaryEntry(key, val)], key) | |
99 | + | else throwErr("not allowed") | |
560 | 100 | ||
561 | 101 | ||
562 | 102 | ||
563 | 103 | @Callable(i) | |
564 | - | func deposit (callerPublicKey,args) = { | |
565 | - | let $t02343023503 = depositINTERNAL(callerPublicKey, args, i) | |
566 | - | let actions = $t02343023503._1 | |
567 | - | let factoryActions = $t02343023503._2 | |
568 | - | $Tuple2(actions, factoryActions) | |
569 | - | } | |
104 | + | func deleteEntry (key) = if (if (!(shutdown)) | |
105 | + | then mustCalculator(i) | |
106 | + | else false) | |
107 | + | then $Tuple2([DeleteEntry(key)], key) | |
108 | + | else throwErr("not allowed") | |
570 | 109 | ||
571 | 110 | ||
572 | 111 | ||
573 | 112 | @Callable(i) | |
574 | - | func borrow (callerPublicKey,args) = { | |
575 | - | let $t02365823730 = borrowINTERNAL(callerPublicKey, args, i) | |
576 | - | let actions = $t02365823730._1 | |
577 | - | let factoryActions = $t02365823730._2 | |
578 | - | $Tuple2(actions, factoryActions) | |
579 | - | } | |
113 | + | func reissue (assetId,amount,reissuable) = if (if (!(shutdown)) | |
114 | + | then mustCalculator(i) | |
115 | + | else false) | |
116 | + | then $Tuple2([Reissue(assetId, amount, reissuable)], amount) | |
117 | + | else throwErr("not allowed") | |
580 | 118 | ||
581 | 119 | ||
582 | 120 | ||
583 | 121 | @Callable(i) | |
584 | - | func depositAndBorrow (callerPublicKey,args) = { | |
585 | - | let accountAddress = args[0] | |
586 | - | let $t02392624025 = depositINTERNAL(callerPublicKey, [accountAddress], i) | |
587 | - | let depositActions = $t02392624025._1 | |
588 | - | let depositFactoryActions = $t02392624025._2 | |
589 | - | let $t02402824112 = borrowINTERNAL(callerPublicKey, args, i) | |
590 | - | let borrowActions = $t02402824112._1 | |
591 | - | let borrowFactoryActions = $t02402824112._2 | |
592 | - | $Tuple2((depositActions ++ borrowActions), (depositFactoryActions ++ borrowFactoryActions)) | |
593 | - | } | |
122 | + | func burn (assetId,amount) = if (if (!(shutdown)) | |
123 | + | then mustCalculator(i) | |
124 | + | else false) | |
125 | + | then $Tuple2([Burn(assetId, amount)], amount) | |
126 | + | else throwErr("not allowed") | |
594 | 127 | ||
595 | 128 | ||
596 | 129 | ||
597 | 130 | @Callable(i) | |
598 | - | func repay (callerPublicKey,args) = { | |
599 | - | let ckecks = [if (!(shutdown)) | |
600 | - | then true | |
601 | - | else throwErr("not allowed"), mustFactory(i.caller)] | |
602 | - | if ((ckecks == ckecks)) | |
603 | - | then $Tuple2(nil, unit) | |
604 | - | else throw("Strict value is not equal to itself.") | |
605 | - | } | |
131 | + | func transferAsset (recipientBytes,amount,assetId) = if (if (!(shutdown)) | |
132 | + | then mustCalculator(i) | |
133 | + | else false) | |
134 | + | then $Tuple2([ScriptTransfer(Address(recipientBytes), amount, assetId)], amount) | |
135 | + | else throwErr("not allowed") | |
606 | 136 | ||
607 | 137 | ||
608 | 138 | ||
609 | 139 | @Callable(i) | |
610 | - | func setPairAllowance (callerPublicKey,args) = { | |
611 | - | let ckecks = [if (!(shutdown)) | |
612 | - | then true | |
613 | - | else throwErr("not allowed"), mustFactory(i.caller), mustAdmin(callerPublicKey)] | |
614 | - | if ((ckecks == ckecks)) | |
615 | - | then { | |
616 | - | let amountAssetIdStr = args[0] | |
617 | - | let priceAssetIdStr = args[1] | |
618 | - | let allowStr = args[2] | |
619 | - | let amountAssetId = parseAssetId(amountAssetIdStr) | |
620 | - | let priceAssetId = parseAssetId(priceAssetIdStr) | |
621 | - | let allow = (allowStr == "true") | |
622 | - | let invocations = [invoke(factoryAddress, "booleanEntry", [kPairAllowed(amountAssetId, priceAssetId), allow], nil)] | |
623 | - | $Tuple2(nil, invocations) | |
140 | + | func transferAssets (recipientBytes,assetsList,amountsList) = if (if (!(shutdown)) | |
141 | + | then mustCalculator(i) | |
142 | + | else false) | |
143 | + | then { | |
144 | + | func addNewTransfer (acc,nextAssetId) = { | |
145 | + | let $t031043128 = acc | |
146 | + | let transfers = $t031043128._1 | |
147 | + | let j = $t031043128._2 | |
148 | + | let newTransfer = ScriptTransfer(Address(recipientBytes), amountsList[j], assetsList[j]) | |
149 | + | let updatedTransfers = (transfers :+ newTransfer) | |
150 | + | $Tuple2(updatedTransfers, (j + 1)) | |
624 | 151 | } | |
625 | - | else throw("Strict value is not equal to itself.") | |
626 | - | } | |
152 | + | ||
153 | + | let $t033543435 = { | |
154 | + | let $l = assetsList | |
155 | + | let $s = size($l) | |
156 | + | let $acc0 = $Tuple2(nil, 0) | |
157 | + | func $f0_1 ($a,$i) = if (($i >= $s)) | |
158 | + | then $a | |
159 | + | else addNewTransfer($a, $l[$i]) | |
160 | + | ||
161 | + | func $f0_2 ($a,$i) = if (($i >= $s)) | |
162 | + | then $a | |
163 | + | else throw("List size exceeds 10") | |
164 | + | ||
165 | + | $f0_2($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) | |
166 | + | } | |
167 | + | let assetsTransfers = $t033543435._1 | |
168 | + | let _lastIndex = $t033543435._2 | |
169 | + | $Tuple2(assetsTransfers, unit) | |
170 | + | } | |
171 | + | else throwErr("not allowed") | |
627 | 172 | ||
628 | 173 | ||
629 | 174 | ||
630 | 175 | @Callable(i) | |
631 | - | func addSyntheticAsset (callerPublicKey,args) = { | |
632 | - | let baseAssetId = parseAssetId(args[0]) | |
633 | - | let syntheticAssetId = parseAssetId(args[1]) | |
634 | - | let ckecks = [if (!(shutdown)) | |
635 | - | then true | |
636 | - | else throwErr("not allowed"), mustFactory(i.caller), mustAdmin(callerPublicKey), if ((getString(factoryAddress, kSyntheticAssetId(baseAssetId)) == unit)) | |
637 | - | then true | |
638 | - | else throwErr("invalid base asset"), if ((getString(factoryAddress, kBaseAssetId(syntheticAssetId)) == unit)) | |
639 | - | then true | |
640 | - | else throwErr("invalid synthetic asset")] | |
641 | - | if ((ckecks == ckecks)) | |
642 | - | then { | |
643 | - | let invocations = [invoke(factoryAddress, "stringEntry", [kSyntheticAssetId(baseAssetId), assetIdToString(syntheticAssetId)], nil), invoke(factoryAddress, "stringEntry", [kBaseAssetId(syntheticAssetId), assetIdToString(baseAssetId)], nil)] | |
644 | - | $Tuple2(nil, invocations) | |
645 | - | } | |
646 | - | else throw("Strict value is not equal to itself.") | |
647 | - | } | |
176 | + | func transferWaves (recipientBytes,amount) = if (if (!(shutdown)) | |
177 | + | then mustCalculator(i) | |
178 | + | else false) | |
179 | + | then $Tuple2([ScriptTransfer(Address(recipientBytes), amount, unit)], amount) | |
180 | + | else throwErr("not allowed") | |
648 | 181 | ||
649 | 182 | ||
650 | 183 | ||
651 | 184 | @Callable(i) | |
652 | - | func doShutdown (callerPublicKey,args) = { | |
653 | - | let checks = [mustFactory(i.caller), mustAdmin(callerPublicKey)] | |
654 | - | if ((checks == checks)) | |
655 | - | then { | |
656 | - | let invocations = [invoke(factoryAddress, "booleanEntry", [kShutdown, true], nil)] | |
657 | - | $Tuple2(nil, invocations) | |
658 | - | } | |
659 | - | else throw("Strict value is not equal to itself.") | |
185 | + | func call (function,args) = { | |
186 | + | let cleanPayments = if ((i.callerPublicKey == base58'11111111111111111111111111111111')) | |
187 | + | then nil | |
188 | + | else i.payments | |
189 | + | let result = reentrantInvoke(calculatorAddress, function, [i.callerPublicKey, args], cleanPayments) | |
190 | + | $Tuple2(nil, result) | |
660 | 191 | } | |
661 | 192 | ||
662 | - | ||
663 | - | ||
664 | - | @Callable(i) | |
665 | - | func getAccountInfoREADONLY (callerPublicKey,args) = { | |
666 | - | let checks = [mustFactory(i.caller)] | |
667 | - | if ((checks == checks)) | |
668 | - | then { | |
669 | - | let accountAddress = valueOrErrorMessage(addressFromString(args[0]), wrapErr("invalid account address")) | |
670 | - | let data = getAccountInfoInternal(accountAddress) | |
671 | - | $Tuple2(nil, data) | |
672 | - | } | |
673 | - | else throw("Strict value is not equal to itself.") | |
674 | - | } | |
675 | - | ||
676 | - | ||
677 | - | ||
678 | - | @Callable(i) | |
679 | - | func getUserInfoREADONLY (callerPublicKey,args) = { | |
680 | - | let checks = [mustFactory(i.caller)] | |
681 | - | if ((checks == checks)) | |
682 | - | then { | |
683 | - | let userAddress = valueOrErrorMessage(addressFromString(args[0]), wrapErr("invalid user address")) | |
684 | - | let userRequests = valueOrElse(getBinary(factoryAddress, kRequestsByOwner(userAddress)), base58'') | |
685 | - | let userRequestsNumber = (size(userRequests) / queueItemSize) | |
686 | - | func getAccountsData (acc,count) = { | |
687 | - | let $t02704527087 = acc | |
688 | - | let accDataList = $t02704527087._1 | |
689 | - | let rawBytes = $t02704527087._2 | |
690 | - | let maxSize = $t02704527087._3 | |
691 | - | if ((maxSize > count)) | |
692 | - | then { | |
693 | - | let requestId = take(rawBytes, queueItemSize) | |
694 | - | let newRawBytes = drop(rawBytes, queueItemSize) | |
695 | - | let accountPublicKey = valueOrErrorMessage(getBinary(factoryAddress, kRequestIdToAccountPublicKey(requestId)), "kRequestIdToAccountPublicKey not found") | |
696 | - | let accountAddress = addressFromPublicKey(accountPublicKey) | |
697 | - | let data = getAccountInfoInternal(accountAddress) | |
698 | - | $Tuple3((accDataList :+ data), newRawBytes, maxSize) | |
699 | - | } | |
700 | - | else acc | |
701 | - | } | |
702 | - | ||
703 | - | let $t02759127696 = { | |
704 | - | let $l = INDEX_LIST | |
705 | - | let $s = size($l) | |
706 | - | let $acc0 = $Tuple3(nil, userRequests, userRequestsNumber) | |
707 | - | func $f0_1 ($a,$i) = if (($i >= $s)) | |
708 | - | then $a | |
709 | - | else getAccountsData($a, $l[$i]) | |
710 | - | ||
711 | - | func $f0_2 ($a,$i) = if (($i >= $s)) | |
712 | - | then $a | |
713 | - | else throw("List size exceeds 20") | |
714 | - | ||
715 | - | $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) | |
716 | - | } | |
717 | - | let accDataList = $t02759127696._1 | |
718 | - | let _a = $t02759127696._2 | |
719 | - | let _b = $t02759127696._3 | |
720 | - | $Tuple2(nil, accDataList) | |
721 | - | } | |
722 | - | else throw("Strict value is not equal to itself.") | |
723 | - | } | |
724 | - | ||
725 | - | ||
726 | - | ||
727 | - | @Callable(i) | |
728 | - | func getPairSettingsInfoREADONLY (callerPublicKey,args) = { | |
729 | - | let amountAsset = parseAssetId(args[0]) | |
730 | - | let priceAsset = parseAssetId(args[1]) | |
731 | - | let pricesList = getPairPricesList(amountAsset, priceAsset) | |
732 | - | func getPairSettings (acc,pricesString) = { | |
733 | - | let settingsKey = kPairSettingsKey(amountAsset, priceAsset, pricesString) | |
734 | - | let settingsStringValue = getStringValue(factoryAddress, settingsKey) | |
735 | - | let sList = split(settingsStringValue, separator) | |
736 | - | let price = parseInt(pricesString) | |
737 | - | let maxLeverage = parseInt(sList[1]) | |
738 | - | let initialMargin = parseInt(sList[2]) | |
739 | - | let maintenanceMargin = parseInt(sList[3]) | |
740 | - | (acc :+ $Tuple4(price, maxLeverage, initialMargin, maintenanceMargin)) | |
741 | - | } | |
742 | - | ||
743 | - | let data = { | |
744 | - | let $l = pricesList | |
745 | - | let $s = size($l) | |
746 | - | let $acc0 = nil | |
747 | - | func $f0_1 ($a,$i) = if (($i >= $s)) | |
748 | - | then $a | |
749 | - | else getPairSettings($a, $l[$i]) | |
750 | - | ||
751 | - | func $f0_2 ($a,$i) = if (($i >= $s)) | |
752 | - | then $a | |
753 | - | else throw("List size exceeds 20") | |
754 | - | ||
755 | - | $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) | |
756 | - | } | |
757 | - | $Tuple2(nil, data) | |
758 | - | } | |
759 | - | ||
760 | - | ||
761 | - | ||
762 | - | @Callable(i) | |
763 | - | func editPairSettings (callerPublicKey,args) = { | |
764 | - | let checks = [mustFactory(i.caller), mustAdmin(callerPublicKey)] | |
765 | - | if ((checks == checks)) | |
766 | - | then { | |
767 | - | let amountAsset = parseAssetId(args[0]) | |
768 | - | let priceAsset = parseAssetId(args[1]) | |
769 | - | let price = args[2] | |
770 | - | let maxLeverage = args[3] | |
771 | - | let initialMargin = args[4] | |
772 | - | let maintenanceMargin = args[5] | |
773 | - | let pairPricesListKey = kPairPricesListKey(amountAsset, priceAsset) | |
774 | - | let settingsKey = kPairSettingsKey(amountAsset, priceAsset, price) | |
775 | - | let pricesList = getPairPricesList(amountAsset, priceAsset) | |
776 | - | let newList = match indexOf(pricesList, price) { | |
777 | - | case ind: Int => | |
778 | - | pricesList | |
779 | - | case _ => | |
780 | - | (pricesList :+ price) | |
781 | - | } | |
782 | - | let check2 = [valueOrErrorMessage(parseInt(price), wrapErr("price value is not an Int")), valueOrErrorMessage(maxLeverage, wrapErr("maxLeverage value is not an Int")), valueOrErrorMessage(initialMargin, wrapErr("initialMargin value is not an Int")), valueOrErrorMessage(maintenanceMargin, wrapErr("maintenanceMargin value is not an Int")), if ((20 >= size(newList))) | |
783 | - | then true | |
784 | - | else throwErr("exceeded max prices list size (20)")] | |
785 | - | if ((check2 == check2)) | |
786 | - | then { | |
787 | - | let pairSettingValue = makeString(["%s%s%s", maxLeverage, initialMargin, maintenanceMargin], separator) | |
788 | - | let invocations = [invoke(factoryAddress, "stringEntry", [kPairPricesListKey(amountAsset, priceAsset), makeString(newList, separator)], nil), invoke(factoryAddress, "stringEntry", [kPairSettingsKey(amountAsset, priceAsset, price), pairSettingValue], nil)] | |
789 | - | $Tuple2(nil, invocations) | |
790 | - | } | |
791 | - | else throw("Strict value is not equal to itself.") | |
792 | - | } | |
793 | - | else throw("Strict value is not equal to itself.") | |
794 | - | } | |
795 | - | ||
796 | - | ||
797 | - | ||
798 | - | @Callable(i) | |
799 | - | func deletePairSettings (callerPublicKey,args) = { | |
800 | - | let checks = [mustFactory(i.caller), mustAdmin(callerPublicKey)] | |
801 | - | if ((checks == checks)) | |
802 | - | then { | |
803 | - | let amountAsset = parseAssetId(args[0]) | |
804 | - | let priceAsset = parseAssetId(args[1]) | |
805 | - | let price = args[2] | |
806 | - | let settingsKey = kPairSettingsKey(amountAsset, priceAsset, price) | |
807 | - | let pairPricesListKey = kPairPricesListKey(amountAsset, priceAsset) | |
808 | - | let pricesList = getPairPricesList(amountAsset, priceAsset) | |
809 | - | let newList = match indexOf(pricesList, price) { | |
810 | - | case ind: Int => | |
811 | - | removeByIndex(pricesList, ind) | |
812 | - | case _ => | |
813 | - | pricesList | |
814 | - | } | |
815 | - | let invocations = [invoke(factoryAddress, "deleteEntry", [settingsKey], nil), if ((size(newList) == 0)) | |
816 | - | then invoke(factoryAddress, "deleteEntry", [kPairPricesListKey(amountAsset, priceAsset)], nil) | |
817 | - | else invoke(factoryAddress, "stringEntry", [kPairPricesListKey(amountAsset, priceAsset), makeString(newList, separator)], nil)] | |
818 | - | $Tuple2(nil, invocations) | |
819 | - | } | |
820 | - | else throw("Strict value is not equal to itself.") | |
821 | - | } | |
822 | - | ||
823 | - | ||
824 | - | @Verifier(tx) | |
825 | - | func verify () = if (if (isDefined(factoryAddressOption)) | |
826 | - | then isDefined(getString(factoryAddress, kMultisig)) | |
827 | - | else false) | |
828 | - | then match getString(factoryAddress, kMultisig) { | |
829 | - | case multisig: String => | |
830 | - | let statusKey = kStatus(toString(this), toBase58String(tx.id)) | |
831 | - | let status = valueOrElse(getBoolean(addressFromStringValue(multisig), statusKey), false) | |
832 | - | status | |
833 | - | case _ => | |
834 | - | false | |
835 | - | } | |
836 | - | else sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) | |
837 | 193 |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 7 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let separator = "__" | |
5 | 5 | ||
6 | - | let chainId = take(drop(this.bytes, 1), 1) | |
7 | - | ||
8 | - | let chainIdW = base58'2W' | |
9 | - | ||
10 | - | let contractFilename = "futures_calculator.ride" | |
11 | - | ||
12 | - | let mult8 = 100000000 | |
13 | - | ||
14 | - | let mult18BigInt = toBigInt(1000000000000000000) | |
15 | - | ||
16 | - | let wavesDecimals = 8 | |
17 | - | ||
18 | - | let usdtDecimals = 6 | |
19 | - | ||
20 | 6 | let wavesString = "WAVES" | |
21 | 7 | ||
22 | - | let queueItemSize = 32 | |
23 | - | ||
24 | - | let big0 = toBigInt(0) | |
25 | - | ||
26 | - | let INDEX_LIST = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19] | |
27 | - | ||
28 | - | let kMultisig = "%s__multisig" | |
29 | - | ||
30 | - | func kStatus (dapp,txId) = makeString(["%s__status", dapp, txId], separator) | |
31 | - | ||
8 | + | let contractFilename = "meme_im_factory.ride" | |
32 | 9 | ||
33 | 10 | let kShutdown = "%s__shutdown" | |
34 | 11 | ||
35 | - | let kPublicKeys = "%s__publicKeys" | |
36 | - | ||
37 | - | let kMatcherPublicKey = "%s__matcherPublicKey" | |
38 | - | ||
39 | - | func toX18 (origVal,origScaleMult) = fraction(toBigInt(origVal), mult18BigInt, toBigInt(origScaleMult)) | |
40 | - | ||
41 | - | ||
42 | - | func fromX18 (val,resultScaleMult) = toInt(fraction(val, toBigInt(resultScaleMult), mult18BigInt)) | |
43 | - | ||
44 | - | ||
45 | - | func validateAddress (address) = isDefined(addressFromString(address)) | |
46 | - | ||
12 | + | let shutdown = valueOrElse(getBoolean(kShutdown), false) | |
47 | 13 | ||
48 | 14 | func wrapErr (s) = ((contractFilename + ": ") + s) | |
49 | 15 | ||
50 | 16 | ||
51 | 17 | func throwErr (s) = throw(wrapErr(s)) | |
52 | 18 | ||
53 | 19 | ||
54 | - | func ensurePositive (v,s) = if ((v >= 0)) | |
55 | - | then v | |
56 | - | else throwErr((s + " value should be positive")) | |
20 | + | func validateAddress (address) = isDefined(addressFromString(address)) | |
21 | + | ||
22 | + | ||
23 | + | let kCalculatorAddress = "calculator__address" | |
24 | + | ||
25 | + | let calculatorAddressOption = match getString(this, kCalculatorAddress) { | |
26 | + | case s: String => | |
27 | + | addressFromString(s) | |
28 | + | case _: Unit => | |
29 | + | unit | |
30 | + | case _ => | |
31 | + | throw("Match error") | |
32 | + | } | |
33 | + | ||
34 | + | let calculatorAddress = valueOrErrorMessage(calculatorAddressOption, wrapErr("invalid calculator address")) | |
35 | + | ||
36 | + | func mustAddress (i,address) = if ((i.caller == address)) | |
37 | + | then true | |
38 | + | else throwErr("permission denied") | |
39 | + | ||
40 | + | ||
41 | + | func mustThis (i) = mustAddress(i, this) | |
42 | + | ||
43 | + | ||
44 | + | func mustCalculator (i) = mustAddress(i, calculatorAddress) | |
57 | 45 | ||
58 | 46 | ||
59 | 47 | func parseAssetId (input) = if ((input == wavesString)) | |
60 | 48 | then unit | |
61 | 49 | else fromBase58String(input) | |
62 | 50 | ||
63 | 51 | ||
64 | 52 | func assetIdToString (input) = if ((input == unit)) | |
65 | 53 | then wavesString | |
66 | 54 | else toBase58String(value(input)) | |
67 | 55 | ||
68 | 56 | ||
69 | - | func getAssetInfoOrFail (assetId) = valueOrErrorMessage(assetInfo(assetId), wrapErr("invalid asset info")) | |
70 | - | ||
71 | - | ||
72 | - | func getAssetDecimalsOrFail (assetId) = match assetId { | |
73 | - | case _: Unit => | |
74 | - | wavesDecimals | |
75 | - | case assetId: ByteVector => | |
76 | - | getAssetInfoOrFail(assetId).decimals | |
77 | - | case _ => | |
78 | - | throw("Match error") | |
79 | - | } | |
80 | - | ||
81 | - | ||
82 | - | func getAssetBalance (assetId,address) = match assetId { | |
83 | - | case _: Unit => | |
84 | - | wavesBalance(address).available | |
85 | - | case assetId: ByteVector => | |
86 | - | assetBalance(address, assetId) | |
87 | - | case _ => | |
88 | - | throw("Match error") | |
89 | - | } | |
90 | - | ||
91 | - | ||
92 | - | func pow10 (n) = pow(10, 0, n, 0, 0, DOWN) | |
93 | - | ||
94 | - | ||
95 | - | func pow10Decimals (assetId) = pow10(getAssetDecimalsOrFail(assetId)) | |
96 | - | ||
97 | - | ||
98 | - | let kFactoryAddress = "%s__factoryAddress" | |
99 | - | ||
100 | - | let factoryAddressOption = match getString(this, kFactoryAddress) { | |
101 | - | case s: String => | |
102 | - | addressFromString(s) | |
103 | - | case _: Unit => | |
104 | - | unit | |
105 | - | case _ => | |
106 | - | throw("Match error") | |
107 | - | } | |
108 | - | ||
109 | - | let factoryAddress = valueOrErrorMessage(factoryAddressOption, wrapErr("invalid factory address")) | |
110 | - | ||
111 | - | let kUsdtAssetId = "%s__usdtAssetId" | |
112 | - | ||
113 | - | let usdtAssetIdOption = match getString(factoryAddress, kUsdtAssetId) { | |
114 | - | case s: String => | |
115 | - | parseAssetId(s) | |
116 | - | case _: Unit => | |
117 | - | unit | |
118 | - | case _ => | |
119 | - | throw("Match error") | |
120 | - | } | |
121 | - | ||
122 | - | let usdtAssetId = valueOrErrorMessage(usdtAssetIdOption, wrapErr("invalid usdt asset id")) | |
123 | - | ||
124 | - | let kPricesAddress = "%s__calculatorAddress" | |
125 | - | ||
126 | - | let shutdown = valueOrElse(getBoolean(factoryAddress, kShutdown), false) | |
127 | - | ||
128 | - | func mustAddress (caller,address) = if ((caller == address)) | |
129 | - | then true | |
130 | - | else throwErr("permission denied") | |
131 | - | ||
132 | - | ||
133 | - | func mustThis (caller) = mustAddress(caller, this) | |
134 | - | ||
135 | - | ||
136 | - | func mustFactory (caller) = mustAddress(caller, factoryAddress) | |
137 | - | ||
138 | - | ||
139 | - | func mustAdmin (callerPublicKey) = { | |
140 | - | let multisigAddressString = getString(factoryAddress, kMultisig) | |
141 | - | let isAdmin = match multisigAddressString { | |
142 | - | case addressString: String => | |
143 | - | let multisig = addressFromStringValue(addressString) | |
144 | - | let publicKeysList = split(getStringValue(multisig, kPublicKeys), separator) | |
145 | - | containsElement(publicKeysList, toBase58String(callerPublicKey)) | |
146 | - | case _ => | |
147 | - | (addressFromPublicKey(callerPublicKey) == factoryAddress) | |
148 | - | } | |
149 | - | if (isAdmin) | |
150 | - | then true | |
151 | - | else throwErr("not allowed") | |
152 | - | } | |
153 | - | ||
154 | - | ||
155 | - | let kAccountScript = "%s__accountScript" | |
156 | - | ||
157 | - | func accountScript () = valueOrErrorMessage(getBinary(factoryAddress, kAccountScript), wrapErr("account script is not set")) | |
158 | - | ||
159 | - | ||
160 | - | let kRewardAmount = "%s__rewardAmount" | |
161 | - | ||
162 | - | func rewardAmount () = valueOrErrorMessage(getInteger(factoryAddress, kRewardAmount), wrapErr("reward amount is not set")) | |
163 | - | ||
164 | - | ||
165 | - | let kAccountsLimit = "%s__accountsLimit" | |
166 | - | ||
167 | - | let accountsLimitDefault = 20 | |
168 | - | ||
169 | - | func accountsLimit () = valueOrElse(getInteger(factoryAddress, kAccountsLimit), accountsLimitDefault) | |
170 | - | ||
171 | - | ||
172 | - | func kDeposited (accountAddress) = makeString(["%s%s", "deposited", toString(accountAddress)], separator) | |
173 | - | ||
174 | - | ||
175 | - | func depositedOption (accountAddress) = getInteger(factoryAddress, kDeposited(accountAddress)) | |
176 | - | ||
177 | - | ||
178 | - | func kCredit (accountAddress,assetId) = makeString(["%s%s%s", "credit", toString(accountAddress), assetIdToString(assetId)], separator) | |
179 | - | ||
180 | - | ||
181 | - | func creditOption (accountAddress,assetId) = getInteger(factoryAddress, kCredit(accountAddress, assetId)) | |
182 | - | ||
183 | - | ||
184 | - | func kLeverage (accountAddress) = makeString(["%s%s", "leverage", toString(accountAddress)], separator) | |
185 | - | ||
186 | - | ||
187 | - | func kRequestLeverage (requestId) = makeString(["%s%s", "requestLeverage", toBase58String(requestId)], separator) | |
188 | - | ||
189 | - | ||
190 | - | func kSyntheticAssetId (baseAssetId) = makeString(["%s%s", "syntheticAssetId", assetIdToString(baseAssetId)], separator) | |
191 | - | ||
192 | - | ||
193 | - | func kBaseAssetId (syntheticAssetId) = makeString(["%s%s", "baseAssetId", assetIdToString(syntheticAssetId)], separator) | |
194 | - | ||
195 | - | ||
196 | - | let REQUEST_STATUS_EMPTY = 0 | |
197 | - | ||
198 | - | let REQUEST_STATUS_READY = 1 | |
199 | - | ||
200 | - | func kRequestStatus (requestId) = makeString(["%s%s", toBase58String(requestId), "status"], separator) | |
201 | - | ||
202 | - | ||
203 | - | func kAccountCreatorPublicKey (accountAddress) = makeString(["%s%s", toString(accountAddress), "creatorPublicKey"], separator) | |
204 | - | ||
205 | - | ||
206 | - | func kRequestOwnerPublicKey (requestId) = makeString(["%s%s", toBase58String(requestId), "ownerPublicKey"], separator) | |
207 | - | ||
208 | - | ||
209 | - | func kRequestAmountAssetId (requestId) = makeString(["%s%s", toBase58String(requestId), "amountAssetId"], separator) | |
210 | - | ||
211 | - | ||
212 | - | func kRequestPriceAssetId (requestId) = makeString(["%s%s", toBase58String(requestId), "priceAssetId"], separator) | |
213 | - | ||
214 | - | ||
215 | - | func kRequestIdToAccountPublicKey (requestId) = makeString(["%s%s", toBase58String(requestId), "requestIdToAccountPublicKey"], separator) | |
216 | - | ||
217 | - | ||
218 | - | func kAccountAddressToRequestId (accountAddress) = makeString(["%s%s", toString(accountAddress), "accountAddressToRequestId"], separator) | |
219 | - | ||
220 | - | ||
221 | - | func kRequestsQueue () = makeString(["%s", "requestsQueue"], separator) | |
222 | - | ||
223 | - | ||
224 | - | func requestsQueue () = valueOrElse(getBinary(factoryAddress, kRequestsQueue()), base58'') | |
225 | - | ||
226 | - | ||
227 | - | func kRequestsByOwner (ownerAddress) = makeString(["%s%s", "requests", toString(ownerAddress)], separator) | |
228 | - | ||
229 | - | ||
230 | - | func requestsByOwner (ownerAddress) = valueOrElse(getBinary(factoryAddress, kRequestsByOwner(ownerAddress)), base58'') | |
231 | - | ||
232 | - | ||
233 | - | func kPairAllowed (amountAssetId,priceAssetId) = makeString(["%s%s%s", assetIdToString(amountAssetId), assetIdToString(priceAssetId), "pairAllowed"], separator) | |
234 | - | ||
235 | - | ||
236 | - | func pairAllowed (amountAssetId,priceAssetId) = valueOrElse(getBoolean(factoryAddress, kPairAllowed(amountAssetId, priceAssetId)), false) | |
237 | - | ||
238 | - | ||
239 | - | func kPrice (assetId) = makeString(["%s", assetIdToString(assetId)], separator) | |
240 | - | ||
241 | - | ||
242 | - | func kPairPricesListKey (amountAssetId,priceAssetId) = makeString(["%s%s%s", assetIdToString(amountAssetId), assetIdToString(priceAssetId), "pairSettingPrices"], separator) | |
243 | - | ||
244 | - | ||
245 | - | func getPairPricesList (amountAssetId,priceAssetId) = match getString(factoryAddress, kPairPricesListKey(amountAssetId, priceAssetId)) { | |
246 | - | case s: String => | |
247 | - | split(s, separator) | |
248 | - | case _ => | |
249 | - | nil | |
250 | - | } | |
251 | - | ||
252 | - | ||
253 | - | func kPairSettingsKey (amountAssetId,priceAssetId,priceString) = makeString(["%s%s%d%s", assetIdToString(amountAssetId), assetIdToString(priceAssetId), priceString, "settings"], separator) | |
254 | - | ||
255 | - | ||
256 | - | func getCurrentPrice (assetId) = { | |
257 | - | let matcherPublicKey = fromBase58String(valueOrErrorMessage(getString(factoryAddress, kMatcherPublicKey), wrapErr("invalid matcher public key"))) | |
258 | - | let matcherAddress = addressFromPublicKey(matcherPublicKey) | |
259 | - | let price = valueOrErrorMessage(getInteger(matcherAddress, kPrice(assetId)), wrapErr(("invalid price, assetId = " + assetIdToString(assetId)))) | |
260 | - | price | |
261 | - | } | |
262 | - | ||
263 | - | ||
264 | - | func calcTotalCredit (creditA,creditB,currentPrice) = (fraction(creditA, currentPrice, mult18BigInt) + creditB) | |
265 | - | ||
266 | - | ||
267 | - | func calcTotalBalance (balanceA,balanceB,currentPrice) = (fraction(balanceA, currentPrice, mult18BigInt) + balanceB) | |
268 | - | ||
269 | - | ||
270 | - | func calcPnl (totalBalance,totalCredit) = (totalBalance - totalCredit) | |
271 | - | ||
272 | - | ||
273 | - | func calcCreditAvailable (deposit,leverage,totalCredit) = (fraction(deposit, leverage, mult18BigInt) - totalCredit) | |
274 | - | ||
275 | - | ||
276 | - | func calcRealInCredit (credit,balance) = if ((credit > big0)) | |
277 | - | then (credit - balance) | |
278 | - | else big0 | |
279 | - | ||
280 | - | ||
281 | - | func calcFree (credit,balance) = if ((credit > big0)) | |
282 | - | then (balance - credit) | |
283 | - | else big0 | |
284 | - | ||
285 | - | ||
286 | - | func calcShortPrice (free,realInCredit) = if ((realInCredit > big0)) | |
287 | - | then max([big0, fraction(free, mult18BigInt, realInCredit)]) | |
288 | - | else big0 | |
289 | - | ||
290 | - | ||
291 | - | func calcLongPrice (free,realInCredit) = if ((realInCredit > big0)) | |
292 | - | then max([big0, fraction(realInCredit, mult18BigInt, free)]) | |
293 | - | else big0 | |
294 | - | ||
295 | - | ||
296 | - | func calcStartMargin (realInCreditA,realInCreditB,currentPrice,settingsMargin) = fraction((fraction(realInCreditA, currentPrice, mult18BigInt) + realInCreditB), settingsMargin, mult18BigInt) | |
297 | - | ||
298 | - | ||
299 | - | func calcMarginSupply (settingsMarginSupply,settingsMargin,startMargin) = fraction(settingsMarginSupply, startMargin, settingsMargin) | |
300 | - | ||
301 | - | ||
302 | - | func calcLiquidationPrice (deposit,marginSupply,realInCreditA,realInCreditB,shortPrice,longPrice) = { | |
303 | - | let liquidationPriceA = if ((realInCreditA > big0)) | |
304 | - | then (((deposit - marginSupply) / realInCreditA) + shortPrice) | |
305 | - | else big0 | |
306 | - | let liquidationPriceB = if ((realInCreditB > big0)) | |
307 | - | then (longPrice - ((deposit - marginSupply) / (realInCreditA / longPrice))) | |
308 | - | else big0 | |
309 | - | (liquidationPriceA + liquidationPriceB) | |
310 | - | } | |
311 | - | ||
312 | - | ||
313 | - | func getRequestId (accountAddress) = { | |
314 | - | let requestId = fromBase58String(valueOrErrorMessage(getString(factoryAddress, kAccountAddressToRequestId(accountAddress)), wrapErr("invalid account address: request id is undefined"))) | |
315 | - | requestId | |
316 | - | } | |
317 | - | ||
318 | - | ||
319 | - | func getAccountAssets (accountAddress) = { | |
320 | - | let requestId = getRequestId(accountAddress) | |
321 | - | let amountAssetId = parseAssetId(valueOrErrorMessage(getString(factoryAddress, kRequestAmountAssetId(requestId)), wrapErr("invalid amount asset id"))) | |
322 | - | let priceAssetId = parseAssetId(valueOrErrorMessage(getString(factoryAddress, kRequestPriceAssetId(requestId)), wrapErr("invalid amount price id"))) | |
323 | - | $Tuple2(amountAssetId, priceAssetId) | |
324 | - | } | |
325 | - | ||
326 | - | ||
327 | - | func getAccountOwnerPublicKey (accountAddress) = { | |
328 | - | let requestId = getRequestId(accountAddress) | |
329 | - | let requestOwnerPublicKey = valueOrErrorMessage(getBinary(factoryAddress, kRequestOwnerPublicKey(requestId)), wrapErr("invalid amount asset id")) | |
330 | - | requestOwnerPublicKey | |
331 | - | } | |
332 | - | ||
333 | - | ||
334 | - | func getAccountInfoInternal (accountAddress) = { | |
335 | - | let $t01125511323 = getAccountAssets(accountAddress) | |
336 | - | let amountAssetId = $t01125511323._1 | |
337 | - | let priceAssetId = $t01125511323._2 | |
338 | - | let leverage = valueOrErrorMessage(getInteger(factoryAddress, kLeverage(accountAddress)), wrapErr("leverage should be defined")) | |
339 | - | let requestId = getRequestId(accountAddress) | |
340 | - | let accountPublicKey = valueOrErrorMessage(getBinary(factoryAddress, kRequestIdToAccountPublicKey(requestId)), "kRequestIdToAccountPublicKey not found") | |
341 | - | let deposited = valueOrElse(depositedOption(accountAddress), 0) | |
342 | - | let currentPrice = toX18(getCurrentPrice(amountAssetId), pow10Decimals(priceAssetId)) | |
343 | - | let creditA = valueOrElse(getInteger(factoryAddress, kCredit(accountAddress, amountAssetId)), 0) | |
344 | - | let creditB = valueOrElse(getInteger(factoryAddress, kCredit(accountAddress, priceAssetId)), 0) | |
345 | - | let status = valueOrErrorMessage(getInteger(factoryAddress, kRequestStatus(requestId)), ("status not found. RequestId = " + toBase58String(requestId))) | |
346 | - | let synthAmountAssetId = getString(factoryAddress, kSyntheticAssetId(amountAssetId)) | |
347 | - | let synthAmountAssetBalance = match synthAmountAssetId { | |
348 | - | case s: String => | |
349 | - | getAssetBalance(parseAssetId(s), accountAddress) | |
350 | - | case _ => | |
351 | - | 0 | |
352 | - | } | |
353 | - | let synthPriceAssetId = getString(factoryAddress, kSyntheticAssetId(priceAssetId)) | |
354 | - | let synthPriceAssetBalance = match synthPriceAssetId { | |
355 | - | case s: String => | |
356 | - | getAssetBalance(parseAssetId(s), accountAddress) | |
357 | - | case _ => | |
358 | - | 0 | |
359 | - | } | |
360 | - | $Tuple12(assetIdToString(amountAssetId), assetIdToString(priceAssetId), toString(accountAddress), toBase58String(accountPublicKey), leverage, toBase58String(requestId), deposited, creditA, creditB, synthAmountAssetBalance, synthPriceAssetBalance, status) | |
361 | - | } | |
362 | - | ||
363 | - | ||
364 | - | func depositINTERNAL (callerPublicKey,args,i) = { | |
365 | - | let payment = i.payments[0] | |
366 | - | let accountAddress = valueOrErrorMessage(addressFromString(args[0]), wrapErr("invalid account address")) | |
367 | - | let ckecks = [if (!(shutdown)) | |
368 | - | then true | |
369 | - | else throwErr("not allowed"), mustFactory(i.caller), if ((size(i.payments) == 1)) | |
370 | - | then true | |
371 | - | else throwErr("1 payment is required"), if ((payment.assetId == usdtAssetId)) | |
372 | - | then true | |
373 | - | else throwErr("invalid asset"), if ((getInteger(factoryAddress, kRequestStatus(getRequestId(accountAddress))) == REQUEST_STATUS_READY)) | |
374 | - | then true | |
375 | - | else throwErr("account is not ready")] | |
376 | - | if ((ckecks == ckecks)) | |
377 | - | then { | |
378 | - | let actions = [ScriptTransfer(accountAddress, payment.amount, payment.assetId)] | |
379 | - | let factoryActions = [invoke(factoryAddress, "integerEntry", [kDeposited(accountAddress), (valueOrElse(depositedOption(accountAddress), 0) + payment.amount)], nil)] | |
380 | - | $Tuple2(actions, factoryActions) | |
381 | - | } | |
382 | - | else throw("Strict value is not equal to itself.") | |
383 | - | } | |
384 | - | ||
385 | - | ||
386 | - | func borrowINTERNAL (callerPublicKey,args,i) = { | |
387 | - | let accountAddress = valueOrErrorMessage(addressFromString(args[0]), wrapErr("invalid account address")) | |
388 | - | let assetIdRequested = parseAssetId(args[1]) | |
389 | - | let amountRequested = ensurePositive(valueOrErrorMessage(parseInt(args[2]), wrapErr("invalid requested amount")), "requested amount") | |
390 | - | let accountOwnerPublicKey = getAccountOwnerPublicKey(accountAddress) | |
391 | - | let userAddress = addressFromPublicKey(callerPublicKey) | |
392 | - | let ckecks = [if (!(shutdown)) | |
393 | - | then true | |
394 | - | else throwErr("not allowed"), mustFactory(i.caller), if ((callerPublicKey == accountOwnerPublicKey)) | |
395 | - | then true | |
396 | - | else throwErr("can be called by account owner only")] | |
397 | - | if ((ckecks == ckecks)) | |
398 | - | then { | |
399 | - | let amountAssetId = getAccountAssets(accountAddress)._1 | |
400 | - | let deposited = toX18(valueOrElse(depositedOption(accountAddress), 0), pow10Decimals(usdtAssetId)) | |
401 | - | let currentPrice = toX18(getCurrentPrice(amountAssetId), pow10Decimals(usdtAssetId)) | |
402 | - | let creditA = toX18(valueOrElse(getInteger(factoryAddress, kCredit(accountAddress, amountAssetId)), 0), pow10Decimals(amountAssetId)) | |
403 | - | let creditB = toX18(valueOrElse(getInteger(factoryAddress, kCredit(accountAddress, usdtAssetId)), 0), pow10Decimals(usdtAssetId)) | |
404 | - | let totalCredit = calcTotalCredit(creditA, creditB, currentPrice) | |
405 | - | let leverage = toX18(valueOrErrorMessage(getInteger(factoryAddress, kLeverage(accountAddress)), wrapErr("leverage should be defined")), 1) | |
406 | - | let creditAvailableUsdt = calcCreditAvailable(deposited, leverage, totalCredit) | |
407 | - | let creditAvailable = if ((assetIdRequested == amountAssetId)) | |
408 | - | then fromX18(fraction(creditAvailableUsdt, mult18BigInt, currentPrice), pow10Decimals(amountAssetId)) | |
409 | - | else if ((assetIdRequested == usdtAssetId)) | |
410 | - | then fromX18(creditAvailableUsdt, pow10Decimals(usdtAssetId)) | |
411 | - | else throwErr("invalid requested asset id") | |
412 | - | let syntheticAssetId = parseAssetId(valueOrErrorMessage(getString(factoryAddress, kSyntheticAssetId(assetIdRequested)), wrapErr("synthetic asset for requested asset is undefined"))) | |
413 | - | let amountToSend = if ((creditAvailable >= amountRequested)) | |
414 | - | then amountRequested | |
415 | - | else throwErr(("credit available = " + toString(creditAvailable))) | |
416 | - | let factoryActions = [invoke(factoryAddress, "integerEntry", [kCredit(accountAddress, assetIdRequested), (valueOrElse(creditOption(accountAddress, assetIdRequested), 0) + amountToSend)], nil), invoke(factoryAddress, "transferAsset", [accountAddress.bytes, amountToSend, syntheticAssetId], nil)] | |
417 | - | $Tuple2(nil, [factoryActions, creditAvailable]) | |
418 | - | } | |
419 | - | else throw("Strict value is not equal to itself.") | |
420 | - | } | |
421 | - | ||
422 | - | ||
423 | 57 | @Callable(i) | |
424 | - | func init ( | |
425 | - | let checkCaller = mustThis(i | |
58 | + | func init (calculatorAddressStr) = { | |
59 | + | let checkCaller = mustThis(i) | |
426 | 60 | if ((checkCaller == checkCaller)) | |
427 | - | then $Tuple2([StringEntry( | |
61 | + | then $Tuple2([StringEntry(kCalculatorAddress, calculatorAddressStr)], unit) | |
428 | 62 | else throw("Strict value is not equal to itself.") | |
429 | 63 | } | |
430 | 64 | ||
431 | 65 | ||
432 | 66 | ||
433 | 67 | @Callable(i) | |
434 | - | func requestAccount (callerPublicKey,args) = { | |
435 | - | let ckecks = [if (!(shutdown)) | |
436 | - | then true | |
437 | - | else throwErr("not allowed"), mustFactory(i.caller)] | |
438 | - | if ((ckecks == ckecks)) | |
439 | - | then { | |
440 | - | let amountAssetIdStr = args[0] | |
441 | - | let priceAssetIdStr = args[1] | |
442 | - | let leverage = valueOrErrorMessage(parseInt(args[2]), wrapErr("invalid leverage")) | |
443 | - | let userAddress = addressFromPublicKey(callerPublicKey) | |
444 | - | let requestId = sha256(i.transactionId) | |
445 | - | let amountAssetId = parseAssetId(amountAssetIdStr) | |
446 | - | let priceAssetId = parseAssetId(priceAssetIdStr) | |
447 | - | let userRequestsNumber = (size(kRequestsByOwner(userAddress)) / queueItemSize) | |
448 | - | let checks = [if ((size(i.payments) == 1)) | |
449 | - | then true | |
450 | - | else throwErr("1 payment is required"), if ((i.payments[0].assetId == unit)) | |
451 | - | then true | |
452 | - | else throwErr("invalid asset"), if ((i.payments[0].amount == rewardAmount())) | |
453 | - | then true | |
454 | - | else throwErr("invalid amount"), if (pairAllowed(amountAssetId, priceAssetId)) | |
455 | - | then true | |
456 | - | else throwErr("pair is not allowed"), if ((leverage == 2)) | |
457 | - | then true | |
458 | - | else throwErr("leverage is not allowed"), if ((getInteger(factoryAddress, kRequestStatus(requestId)) == unit)) | |
459 | - | then true | |
460 | - | else throwErr("account is already exists"), if ((accountsLimit() > userRequestsNumber)) | |
461 | - | then true | |
462 | - | else throwErr(("accounts limit is " + toString(accountsLimit())))] | |
463 | - | if ((checks == checks)) | |
464 | - | then { | |
465 | - | let actions = [ScriptTransfer(factoryAddress, rewardAmount(), unit)] | |
466 | - | $Tuple2(actions, [invoke(factoryAddress, "integerEntry", [kRequestStatus(requestId), REQUEST_STATUS_EMPTY], nil), invoke(factoryAddress, "binaryEntry", [kRequestsQueue(), (requestsQueue() + requestId)], nil), invoke(factoryAddress, "binaryEntry", [kRequestsByOwner(userAddress), (requestsByOwner(userAddress) + requestId)], nil), invoke(factoryAddress, "binaryEntry", [kRequestOwnerPublicKey(requestId), callerPublicKey], nil), invoke(factoryAddress, "stringEntry", [kRequestAmountAssetId(requestId), amountAssetIdStr], nil), invoke(factoryAddress, "stringEntry", [kRequestPriceAssetId(requestId), priceAssetIdStr], nil), invoke(factoryAddress, "integerEntry", [kRequestLeverage(requestId), leverage], nil)]) | |
467 | - | } | |
468 | - | else throw("Strict value is not equal to itself.") | |
469 | - | } | |
470 | - | else throw("Strict value is not equal to itself.") | |
471 | - | } | |
68 | + | func stringEntry (key,val) = if (if (!(shutdown)) | |
69 | + | then mustCalculator(i) | |
70 | + | else false) | |
71 | + | then $Tuple2([StringEntry(key, val)], key) | |
72 | + | else throwErr("not allowed") | |
472 | 73 | ||
473 | 74 | ||
474 | 75 | ||
475 | 76 | @Callable(i) | |
476 | - | func editAccount (callerPublicKey,args) = { | |
477 | - | let accountAddress = valueOrErrorMessage(addressFromString(args[0]), wrapErr("invalid account address")) | |
478 | - | let amountAssetIdStr = args[1] | |
479 | - | let priceAssetIdStr = args[2] | |
480 | - | let leverage = valueOrErrorMessage(parseInt(args[3]), wrapErr("invalid leverage")) | |
481 | - | let requestId = getRequestId(accountAddress) | |
482 | - | let ownerPublicKey = getAccountOwnerPublicKey(accountAddress) | |
483 | - | let amountAssetId = parseAssetId(amountAssetIdStr) | |
484 | - | let priceAssetId = parseAssetId(priceAssetIdStr) | |
485 | - | let checks = [if (!(shutdown)) | |
486 | - | then true | |
487 | - | else throwErr("not allowed"), mustFactory(i.caller), if ((callerPublicKey == ownerPublicKey)) | |
488 | - | then true | |
489 | - | else throwErr("caller is not an account owner"), if (pairAllowed(amountAssetId, priceAssetId)) | |
490 | - | then true | |
491 | - | else throwErr("pair is not allowed"), if ((leverage == 2)) | |
492 | - | then true | |
493 | - | else throwErr("leverage is not allowed"), if ((getInteger(factoryAddress, kRequestStatus(requestId)) == REQUEST_STATUS_READY)) | |
494 | - | then true | |
495 | - | else throwErr("account is not ready")] | |
496 | - | if ((checks == checks)) | |
497 | - | then $Tuple2(nil, [invoke(factoryAddress, "stringEntry", [kRequestAmountAssetId(requestId), amountAssetIdStr], nil), invoke(factoryAddress, "stringEntry", [kRequestPriceAssetId(requestId), priceAssetIdStr], nil), invoke(factoryAddress, "integerEntry", [kRequestLeverage(requestId), leverage], nil)]) | |
498 | - | else throw("Strict value is not equal to itself.") | |
499 | - | } | |
77 | + | func integerEntry (key,val) = if (if (!(shutdown)) | |
78 | + | then mustCalculator(i) | |
79 | + | else false) | |
80 | + | then $Tuple2([IntegerEntry(key, val)], key) | |
81 | + | else throwErr("not allowed") | |
500 | 82 | ||
501 | 83 | ||
502 | 84 | ||
503 | 85 | @Callable(i) | |
504 | - | func addAccount (callerPublicKey,args) = { | |
505 | - | let ckecks = [if (!(shutdown)) | |
506 | - | then true | |
507 | - | else throwErr("not allowed"), mustFactory(i.caller)] | |
508 | - | if ((ckecks == ckecks)) | |
509 | - | then { | |
510 | - | let creatorPublicKey = fromBase58String(args[0]) | |
511 | - | let accountPublicKey = callerPublicKey | |
512 | - | let accountAddress = addressFromPublicKey(callerPublicKey) | |
513 | - | let creatorAddress = addressFromPublicKey(creatorPublicKey) | |
514 | - | let checks = [if ((getBinary(factoryAddress, kAccountCreatorPublicKey(accountAddress)) == unit)) | |
515 | - | then true | |
516 | - | else throwErr("account is already exists"), if ( match scriptHash(accountAddress) { | |
517 | - | case b: ByteVector => | |
518 | - | (b == blake2b256_32Kb(accountScript())) | |
519 | - | case _ => | |
520 | - | false | |
521 | - | }) | |
522 | - | then true | |
523 | - | else throwErr("invalid script")] | |
524 | - | if ((checks == checks)) | |
525 | - | then { | |
526 | - | let $t02126422409 = if ((size(requestsQueue()) == 0)) | |
527 | - | then $Tuple2(throwErr("requests queue is empty"), nil) | |
528 | - | else { | |
529 | - | let requestId = take(requestsQueue(), queueItemSize) | |
530 | - | let leverage = valueOrErrorMessage(getInteger(factoryAddress, kRequestLeverage(requestId)), wrapErr("request's leverage is undefined")) | |
531 | - | $Tuple2(nil, [invoke(factoryAddress, "integerEntry", [kRequestStatus(requestId), REQUEST_STATUS_READY], nil), invoke(factoryAddress, "binaryEntry", [kRequestIdToAccountPublicKey(requestId), accountPublicKey], nil), invoke(factoryAddress, "binaryEntry", [kRequestsQueue(), drop(requestsQueue(), queueItemSize)], nil), invoke(factoryAddress, "stringEntry", [kAccountAddressToRequestId(accountAddress), toBase58String(requestId)], nil), invoke(factoryAddress, "transferWaves", [creatorAddress.bytes, rewardAmount()], nil), invoke(factoryAddress, "integerEntry", [kLeverage(accountAddress), leverage], nil)]) | |
532 | - | } | |
533 | - | let actions = $t02126422409._1 | |
534 | - | let factoryActions = $t02126422409._2 | |
535 | - | $Tuple2(actions, (factoryActions ++ [invoke(factoryAddress, "binaryEntry", [kAccountCreatorPublicKey(accountAddress), creatorPublicKey], nil)])) | |
536 | - | } | |
537 | - | else throw("Strict value is not equal to itself.") | |
538 | - | } | |
539 | - | else throw("Strict value is not equal to itself.") | |
540 | - | } | |
86 | + | func booleanEntry (key,val) = if (if (!(shutdown)) | |
87 | + | then mustCalculator(i) | |
88 | + | else false) | |
89 | + | then $Tuple2([BooleanEntry(key, val)], key) | |
90 | + | else throwErr("not allowed") | |
541 | 91 | ||
542 | 92 | ||
543 | 93 | ||
544 | 94 | @Callable(i) | |
545 | - | func withdraw (callerPublicKey,args) = { | |
546 | - | let checks = [if (!(shutdown)) | |
547 | - | then true | |
548 | - | else throwErr("not allowed"), mustFactory(i.caller)] | |
549 | - | if ((checks == checks)) | |
550 | - | then { | |
551 | - | let userAddress = addressFromPublicKey(callerPublicKey) | |
552 | - | let accountAddress = valueOrErrorMessage(addressFromString(args[0]), wrapErr("invalid account address")) | |
553 | - | let amount = valueOrErrorMessage(parseInt(args[1]), wrapErr("invalid amount")) | |
554 | - | let assetId = parseAssetId(args[2]) | |
555 | - | let invocations = [invoke(accountAddress, "transferAsset", [userAddress.bytes, amount, assetId], nil)] | |
556 | - | $Tuple2(nil, invocations) | |
557 | - | } | |
558 | - | else throw("Strict value is not equal to itself.") | |
559 | - | } | |
95 | + | func binaryEntry (key,val) = if (if (!(shutdown)) | |
96 | + | then mustCalculator(i) | |
97 | + | else false) | |
98 | + | then $Tuple2([BinaryEntry(key, val)], key) | |
99 | + | else throwErr("not allowed") | |
560 | 100 | ||
561 | 101 | ||
562 | 102 | ||
563 | 103 | @Callable(i) | |
564 | - | func deposit (callerPublicKey,args) = { | |
565 | - | let $t02343023503 = depositINTERNAL(callerPublicKey, args, i) | |
566 | - | let actions = $t02343023503._1 | |
567 | - | let factoryActions = $t02343023503._2 | |
568 | - | $Tuple2(actions, factoryActions) | |
569 | - | } | |
104 | + | func deleteEntry (key) = if (if (!(shutdown)) | |
105 | + | then mustCalculator(i) | |
106 | + | else false) | |
107 | + | then $Tuple2([DeleteEntry(key)], key) | |
108 | + | else throwErr("not allowed") | |
570 | 109 | ||
571 | 110 | ||
572 | 111 | ||
573 | 112 | @Callable(i) | |
574 | - | func borrow (callerPublicKey,args) = { | |
575 | - | let $t02365823730 = borrowINTERNAL(callerPublicKey, args, i) | |
576 | - | let actions = $t02365823730._1 | |
577 | - | let factoryActions = $t02365823730._2 | |
578 | - | $Tuple2(actions, factoryActions) | |
579 | - | } | |
113 | + | func reissue (assetId,amount,reissuable) = if (if (!(shutdown)) | |
114 | + | then mustCalculator(i) | |
115 | + | else false) | |
116 | + | then $Tuple2([Reissue(assetId, amount, reissuable)], amount) | |
117 | + | else throwErr("not allowed") | |
580 | 118 | ||
581 | 119 | ||
582 | 120 | ||
583 | 121 | @Callable(i) | |
584 | - | func depositAndBorrow (callerPublicKey,args) = { | |
585 | - | let accountAddress = args[0] | |
586 | - | let $t02392624025 = depositINTERNAL(callerPublicKey, [accountAddress], i) | |
587 | - | let depositActions = $t02392624025._1 | |
588 | - | let depositFactoryActions = $t02392624025._2 | |
589 | - | let $t02402824112 = borrowINTERNAL(callerPublicKey, args, i) | |
590 | - | let borrowActions = $t02402824112._1 | |
591 | - | let borrowFactoryActions = $t02402824112._2 | |
592 | - | $Tuple2((depositActions ++ borrowActions), (depositFactoryActions ++ borrowFactoryActions)) | |
593 | - | } | |
122 | + | func burn (assetId,amount) = if (if (!(shutdown)) | |
123 | + | then mustCalculator(i) | |
124 | + | else false) | |
125 | + | then $Tuple2([Burn(assetId, amount)], amount) | |
126 | + | else throwErr("not allowed") | |
594 | 127 | ||
595 | 128 | ||
596 | 129 | ||
597 | 130 | @Callable(i) | |
598 | - | func repay (callerPublicKey,args) = { | |
599 | - | let ckecks = [if (!(shutdown)) | |
600 | - | then true | |
601 | - | else throwErr("not allowed"), mustFactory(i.caller)] | |
602 | - | if ((ckecks == ckecks)) | |
603 | - | then $Tuple2(nil, unit) | |
604 | - | else throw("Strict value is not equal to itself.") | |
605 | - | } | |
131 | + | func transferAsset (recipientBytes,amount,assetId) = if (if (!(shutdown)) | |
132 | + | then mustCalculator(i) | |
133 | + | else false) | |
134 | + | then $Tuple2([ScriptTransfer(Address(recipientBytes), amount, assetId)], amount) | |
135 | + | else throwErr("not allowed") | |
606 | 136 | ||
607 | 137 | ||
608 | 138 | ||
609 | 139 | @Callable(i) | |
610 | - | func setPairAllowance (callerPublicKey,args) = { | |
611 | - | let ckecks = [if (!(shutdown)) | |
612 | - | then true | |
613 | - | else throwErr("not allowed"), mustFactory(i.caller), mustAdmin(callerPublicKey)] | |
614 | - | if ((ckecks == ckecks)) | |
615 | - | then { | |
616 | - | let amountAssetIdStr = args[0] | |
617 | - | let priceAssetIdStr = args[1] | |
618 | - | let allowStr = args[2] | |
619 | - | let amountAssetId = parseAssetId(amountAssetIdStr) | |
620 | - | let priceAssetId = parseAssetId(priceAssetIdStr) | |
621 | - | let allow = (allowStr == "true") | |
622 | - | let invocations = [invoke(factoryAddress, "booleanEntry", [kPairAllowed(amountAssetId, priceAssetId), allow], nil)] | |
623 | - | $Tuple2(nil, invocations) | |
140 | + | func transferAssets (recipientBytes,assetsList,amountsList) = if (if (!(shutdown)) | |
141 | + | then mustCalculator(i) | |
142 | + | else false) | |
143 | + | then { | |
144 | + | func addNewTransfer (acc,nextAssetId) = { | |
145 | + | let $t031043128 = acc | |
146 | + | let transfers = $t031043128._1 | |
147 | + | let j = $t031043128._2 | |
148 | + | let newTransfer = ScriptTransfer(Address(recipientBytes), amountsList[j], assetsList[j]) | |
149 | + | let updatedTransfers = (transfers :+ newTransfer) | |
150 | + | $Tuple2(updatedTransfers, (j + 1)) | |
624 | 151 | } | |
625 | - | else throw("Strict value is not equal to itself.") | |
626 | - | } | |
152 | + | ||
153 | + | let $t033543435 = { | |
154 | + | let $l = assetsList | |
155 | + | let $s = size($l) | |
156 | + | let $acc0 = $Tuple2(nil, 0) | |
157 | + | func $f0_1 ($a,$i) = if (($i >= $s)) | |
158 | + | then $a | |
159 | + | else addNewTransfer($a, $l[$i]) | |
160 | + | ||
161 | + | func $f0_2 ($a,$i) = if (($i >= $s)) | |
162 | + | then $a | |
163 | + | else throw("List size exceeds 10") | |
164 | + | ||
165 | + | $f0_2($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) | |
166 | + | } | |
167 | + | let assetsTransfers = $t033543435._1 | |
168 | + | let _lastIndex = $t033543435._2 | |
169 | + | $Tuple2(assetsTransfers, unit) | |
170 | + | } | |
171 | + | else throwErr("not allowed") | |
627 | 172 | ||
628 | 173 | ||
629 | 174 | ||
630 | 175 | @Callable(i) | |
631 | - | func addSyntheticAsset (callerPublicKey,args) = { | |
632 | - | let baseAssetId = parseAssetId(args[0]) | |
633 | - | let syntheticAssetId = parseAssetId(args[1]) | |
634 | - | let ckecks = [if (!(shutdown)) | |
635 | - | then true | |
636 | - | else throwErr("not allowed"), mustFactory(i.caller), mustAdmin(callerPublicKey), if ((getString(factoryAddress, kSyntheticAssetId(baseAssetId)) == unit)) | |
637 | - | then true | |
638 | - | else throwErr("invalid base asset"), if ((getString(factoryAddress, kBaseAssetId(syntheticAssetId)) == unit)) | |
639 | - | then true | |
640 | - | else throwErr("invalid synthetic asset")] | |
641 | - | if ((ckecks == ckecks)) | |
642 | - | then { | |
643 | - | let invocations = [invoke(factoryAddress, "stringEntry", [kSyntheticAssetId(baseAssetId), assetIdToString(syntheticAssetId)], nil), invoke(factoryAddress, "stringEntry", [kBaseAssetId(syntheticAssetId), assetIdToString(baseAssetId)], nil)] | |
644 | - | $Tuple2(nil, invocations) | |
645 | - | } | |
646 | - | else throw("Strict value is not equal to itself.") | |
647 | - | } | |
176 | + | func transferWaves (recipientBytes,amount) = if (if (!(shutdown)) | |
177 | + | then mustCalculator(i) | |
178 | + | else false) | |
179 | + | then $Tuple2([ScriptTransfer(Address(recipientBytes), amount, unit)], amount) | |
180 | + | else throwErr("not allowed") | |
648 | 181 | ||
649 | 182 | ||
650 | 183 | ||
651 | 184 | @Callable(i) | |
652 | - | func doShutdown (callerPublicKey,args) = { | |
653 | - | let checks = [mustFactory(i.caller), mustAdmin(callerPublicKey)] | |
654 | - | if ((checks == checks)) | |
655 | - | then { | |
656 | - | let invocations = [invoke(factoryAddress, "booleanEntry", [kShutdown, true], nil)] | |
657 | - | $Tuple2(nil, invocations) | |
658 | - | } | |
659 | - | else throw("Strict value is not equal to itself.") | |
185 | + | func call (function,args) = { | |
186 | + | let cleanPayments = if ((i.callerPublicKey == base58'11111111111111111111111111111111')) | |
187 | + | then nil | |
188 | + | else i.payments | |
189 | + | let result = reentrantInvoke(calculatorAddress, function, [i.callerPublicKey, args], cleanPayments) | |
190 | + | $Tuple2(nil, result) | |
660 | 191 | } | |
661 | 192 | ||
662 | - | ||
663 | - | ||
664 | - | @Callable(i) | |
665 | - | func getAccountInfoREADONLY (callerPublicKey,args) = { | |
666 | - | let checks = [mustFactory(i.caller)] | |
667 | - | if ((checks == checks)) | |
668 | - | then { | |
669 | - | let accountAddress = valueOrErrorMessage(addressFromString(args[0]), wrapErr("invalid account address")) | |
670 | - | let data = getAccountInfoInternal(accountAddress) | |
671 | - | $Tuple2(nil, data) | |
672 | - | } | |
673 | - | else throw("Strict value is not equal to itself.") | |
674 | - | } | |
675 | - | ||
676 | - | ||
677 | - | ||
678 | - | @Callable(i) | |
679 | - | func getUserInfoREADONLY (callerPublicKey,args) = { | |
680 | - | let checks = [mustFactory(i.caller)] | |
681 | - | if ((checks == checks)) | |
682 | - | then { | |
683 | - | let userAddress = valueOrErrorMessage(addressFromString(args[0]), wrapErr("invalid user address")) | |
684 | - | let userRequests = valueOrElse(getBinary(factoryAddress, kRequestsByOwner(userAddress)), base58'') | |
685 | - | let userRequestsNumber = (size(userRequests) / queueItemSize) | |
686 | - | func getAccountsData (acc,count) = { | |
687 | - | let $t02704527087 = acc | |
688 | - | let accDataList = $t02704527087._1 | |
689 | - | let rawBytes = $t02704527087._2 | |
690 | - | let maxSize = $t02704527087._3 | |
691 | - | if ((maxSize > count)) | |
692 | - | then { | |
693 | - | let requestId = take(rawBytes, queueItemSize) | |
694 | - | let newRawBytes = drop(rawBytes, queueItemSize) | |
695 | - | let accountPublicKey = valueOrErrorMessage(getBinary(factoryAddress, kRequestIdToAccountPublicKey(requestId)), "kRequestIdToAccountPublicKey not found") | |
696 | - | let accountAddress = addressFromPublicKey(accountPublicKey) | |
697 | - | let data = getAccountInfoInternal(accountAddress) | |
698 | - | $Tuple3((accDataList :+ data), newRawBytes, maxSize) | |
699 | - | } | |
700 | - | else acc | |
701 | - | } | |
702 | - | ||
703 | - | let $t02759127696 = { | |
704 | - | let $l = INDEX_LIST | |
705 | - | let $s = size($l) | |
706 | - | let $acc0 = $Tuple3(nil, userRequests, userRequestsNumber) | |
707 | - | func $f0_1 ($a,$i) = if (($i >= $s)) | |
708 | - | then $a | |
709 | - | else getAccountsData($a, $l[$i]) | |
710 | - | ||
711 | - | func $f0_2 ($a,$i) = if (($i >= $s)) | |
712 | - | then $a | |
713 | - | else throw("List size exceeds 20") | |
714 | - | ||
715 | - | $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) | |
716 | - | } | |
717 | - | let accDataList = $t02759127696._1 | |
718 | - | let _a = $t02759127696._2 | |
719 | - | let _b = $t02759127696._3 | |
720 | - | $Tuple2(nil, accDataList) | |
721 | - | } | |
722 | - | else throw("Strict value is not equal to itself.") | |
723 | - | } | |
724 | - | ||
725 | - | ||
726 | - | ||
727 | - | @Callable(i) | |
728 | - | func getPairSettingsInfoREADONLY (callerPublicKey,args) = { | |
729 | - | let amountAsset = parseAssetId(args[0]) | |
730 | - | let priceAsset = parseAssetId(args[1]) | |
731 | - | let pricesList = getPairPricesList(amountAsset, priceAsset) | |
732 | - | func getPairSettings (acc,pricesString) = { | |
733 | - | let settingsKey = kPairSettingsKey(amountAsset, priceAsset, pricesString) | |
734 | - | let settingsStringValue = getStringValue(factoryAddress, settingsKey) | |
735 | - | let sList = split(settingsStringValue, separator) | |
736 | - | let price = parseInt(pricesString) | |
737 | - | let maxLeverage = parseInt(sList[1]) | |
738 | - | let initialMargin = parseInt(sList[2]) | |
739 | - | let maintenanceMargin = parseInt(sList[3]) | |
740 | - | (acc :+ $Tuple4(price, maxLeverage, initialMargin, maintenanceMargin)) | |
741 | - | } | |
742 | - | ||
743 | - | let data = { | |
744 | - | let $l = pricesList | |
745 | - | let $s = size($l) | |
746 | - | let $acc0 = nil | |
747 | - | func $f0_1 ($a,$i) = if (($i >= $s)) | |
748 | - | then $a | |
749 | - | else getPairSettings($a, $l[$i]) | |
750 | - | ||
751 | - | func $f0_2 ($a,$i) = if (($i >= $s)) | |
752 | - | then $a | |
753 | - | else throw("List size exceeds 20") | |
754 | - | ||
755 | - | $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) | |
756 | - | } | |
757 | - | $Tuple2(nil, data) | |
758 | - | } | |
759 | - | ||
760 | - | ||
761 | - | ||
762 | - | @Callable(i) | |
763 | - | func editPairSettings (callerPublicKey,args) = { | |
764 | - | let checks = [mustFactory(i.caller), mustAdmin(callerPublicKey)] | |
765 | - | if ((checks == checks)) | |
766 | - | then { | |
767 | - | let amountAsset = parseAssetId(args[0]) | |
768 | - | let priceAsset = parseAssetId(args[1]) | |
769 | - | let price = args[2] | |
770 | - | let maxLeverage = args[3] | |
771 | - | let initialMargin = args[4] | |
772 | - | let maintenanceMargin = args[5] | |
773 | - | let pairPricesListKey = kPairPricesListKey(amountAsset, priceAsset) | |
774 | - | let settingsKey = kPairSettingsKey(amountAsset, priceAsset, price) | |
775 | - | let pricesList = getPairPricesList(amountAsset, priceAsset) | |
776 | - | let newList = match indexOf(pricesList, price) { | |
777 | - | case ind: Int => | |
778 | - | pricesList | |
779 | - | case _ => | |
780 | - | (pricesList :+ price) | |
781 | - | } | |
782 | - | let check2 = [valueOrErrorMessage(parseInt(price), wrapErr("price value is not an Int")), valueOrErrorMessage(maxLeverage, wrapErr("maxLeverage value is not an Int")), valueOrErrorMessage(initialMargin, wrapErr("initialMargin value is not an Int")), valueOrErrorMessage(maintenanceMargin, wrapErr("maintenanceMargin value is not an Int")), if ((20 >= size(newList))) | |
783 | - | then true | |
784 | - | else throwErr("exceeded max prices list size (20)")] | |
785 | - | if ((check2 == check2)) | |
786 | - | then { | |
787 | - | let pairSettingValue = makeString(["%s%s%s", maxLeverage, initialMargin, maintenanceMargin], separator) | |
788 | - | let invocations = [invoke(factoryAddress, "stringEntry", [kPairPricesListKey(amountAsset, priceAsset), makeString(newList, separator)], nil), invoke(factoryAddress, "stringEntry", [kPairSettingsKey(amountAsset, priceAsset, price), pairSettingValue], nil)] | |
789 | - | $Tuple2(nil, invocations) | |
790 | - | } | |
791 | - | else throw("Strict value is not equal to itself.") | |
792 | - | } | |
793 | - | else throw("Strict value is not equal to itself.") | |
794 | - | } | |
795 | - | ||
796 | - | ||
797 | - | ||
798 | - | @Callable(i) | |
799 | - | func deletePairSettings (callerPublicKey,args) = { | |
800 | - | let checks = [mustFactory(i.caller), mustAdmin(callerPublicKey)] | |
801 | - | if ((checks == checks)) | |
802 | - | then { | |
803 | - | let amountAsset = parseAssetId(args[0]) | |
804 | - | let priceAsset = parseAssetId(args[1]) | |
805 | - | let price = args[2] | |
806 | - | let settingsKey = kPairSettingsKey(amountAsset, priceAsset, price) | |
807 | - | let pairPricesListKey = kPairPricesListKey(amountAsset, priceAsset) | |
808 | - | let pricesList = getPairPricesList(amountAsset, priceAsset) | |
809 | - | let newList = match indexOf(pricesList, price) { | |
810 | - | case ind: Int => | |
811 | - | removeByIndex(pricesList, ind) | |
812 | - | case _ => | |
813 | - | pricesList | |
814 | - | } | |
815 | - | let invocations = [invoke(factoryAddress, "deleteEntry", [settingsKey], nil), if ((size(newList) == 0)) | |
816 | - | then invoke(factoryAddress, "deleteEntry", [kPairPricesListKey(amountAsset, priceAsset)], nil) | |
817 | - | else invoke(factoryAddress, "stringEntry", [kPairPricesListKey(amountAsset, priceAsset), makeString(newList, separator)], nil)] | |
818 | - | $Tuple2(nil, invocations) | |
819 | - | } | |
820 | - | else throw("Strict value is not equal to itself.") | |
821 | - | } | |
822 | - | ||
823 | - | ||
824 | - | @Verifier(tx) | |
825 | - | func verify () = if (if (isDefined(factoryAddressOption)) | |
826 | - | then isDefined(getString(factoryAddress, kMultisig)) | |
827 | - | else false) | |
828 | - | then match getString(factoryAddress, kMultisig) { | |
829 | - | case multisig: String => | |
830 | - | let statusKey = kStatus(toString(this), toBase58String(tx.id)) | |
831 | - | let status = valueOrElse(getBoolean(addressFromStringValue(multisig), statusKey), false) | |
832 | - | status | |
833 | - | case _ => | |
834 | - | false | |
835 | - | } | |
836 | - | else sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) | |
837 | 193 |
github/deemru/w8io/169f3d6 74.46 ms ◑