1 | | - | {-# STDLIB_VERSION 5 #-} |
---|
2 | | - | {-# SCRIPT_TYPE ACCOUNT #-} |
---|
3 | | - | {-# CONTENT_TYPE DAPP #-} |
---|
4 | | - | let depositFee = 1000 |
---|
5 | | - | |
---|
6 | | - | let controllerFee = 10000 |
---|
7 | | - | |
---|
8 | | - | let platformFee = 10000 |
---|
9 | | - | |
---|
10 | | - | let adminPubKey1 = base58'68Po1k24uP6goKr7RDmXPg4QkMiKuyTMEirao14rif8s' |
---|
11 | | - | |
---|
12 | | - | let adminPubKey2 = base58'68Po1k24uP6goKr7RDmXPg4QkMiKuyTMEirao14rif8s' |
---|
13 | | - | |
---|
14 | | - | let adminPubKey3 = base58'ALsqwPqiUP3bVbM7grozc1Y5oHVBAGKqACRJ5J8RXceC' |
---|
15 | | - | |
---|
16 | | - | @Callable(i) |
---|
17 | | - | func addPools (pools,liquidityTokens,serviceTokens,liquidityTokenDecimals) = if (containsElement([adminPubKey1, adminPubKey2, adminPubKey3], i.callerPublicKey)) |
---|
18 | | - | then { |
---|
19 | | - | func generatePoolKeys (accumulated,pool) = IntegerEntry((pool + "_asset_balance"), 0) :: accumulated |
---|
20 | | - | |
---|
21 | | - | func generatePoolLiquidityTokenKeys (accumulated,pool) = { |
---|
22 | | - | let poolIndex = value(indexOf(pools, pool)) |
---|
23 | | - | let liquidityToken = liquidityTokens[poolIndex] |
---|
24 | | - | StringEntry((pool + "_liquidity_token"), liquidityToken) :: accumulated |
---|
25 | | - | } |
---|
26 | | - | |
---|
27 | | - | func generatePoolServiceTokenKeys (accumulated,pool) = { |
---|
28 | | - | let poolIndex = value(indexOf(pools, pool)) |
---|
29 | | - | let liquidityToken = serviceTokens[poolIndex] |
---|
30 | | - | StringEntry((pool + "_service_token"), liquidityToken) :: accumulated |
---|
31 | | - | } |
---|
32 | | - | |
---|
33 | | - | func generatePoolLiquidityTokenDecimalKeys (accumulated,pool) = { |
---|
34 | | - | let poolIndex = value(indexOf(pools, pool)) |
---|
35 | | - | let liquidityToken = liquidityTokenDecimals[poolIndex] |
---|
36 | | - | IntegerEntry((pool + "_service_token"), liquidityToken) :: accumulated |
---|
37 | | - | } |
---|
38 | | - | |
---|
39 | | - | func generatePoolActiveKeys (accumulated,pool) = BooleanEntry((pool + "_active"), true) :: accumulated |
---|
40 | | - | |
---|
41 | | - | let poolBalanceKeys = { |
---|
42 | | - | let $l = pools |
---|
43 | | - | let $s = size($l) |
---|
44 | | - | let $acc0 = nil |
---|
45 | | - | func 1 ($a,$i) = if (($i >= $s)) |
---|
46 | | - | then $a |
---|
47 | | - | else generatePoolKeys($a, $l[$i]) |
---|
48 | | - | |
---|
49 | | - | func 2 ($a,$i) = if (($i >= $s)) |
---|
50 | | - | then $a |
---|
51 | | - | else throw("List size exceeds 20") |
---|
52 | | - | |
---|
53 | | - | 2(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10), 11), 12), 13), 14), 15), 16), 17), 18), 19), 20) |
---|
54 | | - | } |
---|
55 | | - | let poolLiquidityTokenKeys = { |
---|
56 | | - | let $l = pools |
---|
57 | | - | let $s = size($l) |
---|
58 | | - | let $acc0 = nil |
---|
59 | | - | func 1 ($a,$i) = if (($i >= $s)) |
---|
60 | | - | then $a |
---|
61 | | - | else generatePoolLiquidityTokenKeys($a, $l[$i]) |
---|
62 | | - | |
---|
63 | | - | func 2 ($a,$i) = if (($i >= $s)) |
---|
64 | | - | then $a |
---|
65 | | - | else throw("List size exceeds 20") |
---|
66 | | - | |
---|
67 | | - | 2(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10), 11), 12), 13), 14), 15), 16), 17), 18), 19), 20) |
---|
68 | | - | } |
---|
69 | | - | let poolServiceTokenKeys = { |
---|
70 | | - | let $l = pools |
---|
71 | | - | let $s = size($l) |
---|
72 | | - | let $acc0 = nil |
---|
73 | | - | func 1 ($a,$i) = if (($i >= $s)) |
---|
74 | | - | then $a |
---|
75 | | - | else generatePoolServiceTokenKeys($a, $l[$i]) |
---|
76 | | - | |
---|
77 | | - | func 2 ($a,$i) = if (($i >= $s)) |
---|
78 | | - | then $a |
---|
79 | | - | else throw("List size exceeds 20") |
---|
80 | | - | |
---|
81 | | - | 2(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10), 11), 12), 13), 14), 15), 16), 17), 18), 19), 20) |
---|
82 | | - | } |
---|
83 | | - | let poolLiquidityTokenDecimalKeys = { |
---|
84 | | - | let $l = pools |
---|
85 | | - | let $s = size($l) |
---|
86 | | - | let $acc0 = nil |
---|
87 | | - | func 1 ($a,$i) = if (($i >= $s)) |
---|
88 | | - | then $a |
---|
89 | | - | else generatePoolLiquidityTokenDecimalKeys($a, $l[$i]) |
---|
90 | | - | |
---|
91 | | - | func 2 ($a,$i) = if (($i >= $s)) |
---|
92 | | - | then $a |
---|
93 | | - | else throw("List size exceeds 20") |
---|
94 | | - | |
---|
95 | | - | 2(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10), 11), 12), 13), 14), 15), 16), 17), 18), 19), 20) |
---|
96 | | - | } |
---|
97 | | - | let poolActiveKeys = { |
---|
98 | | - | let $l = pools |
---|
99 | | - | let $s = size($l) |
---|
100 | | - | let $acc0 = nil |
---|
101 | | - | func 1 ($a,$i) = if (($i >= $s)) |
---|
102 | | - | then $a |
---|
103 | | - | else generatePoolActiveKeys($a, $l[$i]) |
---|
104 | | - | |
---|
105 | | - | func 2 ($a,$i) = if (($i >= $s)) |
---|
106 | | - | then $a |
---|
107 | | - | else throw("List size exceeds 20") |
---|
108 | | - | |
---|
109 | | - | 2(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10), 11), 12), 13), 14), 15), 16), 17), 18), 19), 20) |
---|
110 | | - | } |
---|
111 | | - | ((((poolBalanceKeys ++ poolLiquidityTokenKeys) ++ poolServiceTokenKeys) ++ poolLiquidityTokenDecimalKeys) ++ poolActiveKeys) |
---|
112 | | - | } |
---|
113 | | - | else throw("Only admin can call this function") |
---|
114 | | - | |
---|
115 | | - | |
---|
116 | | - | |
---|
117 | | - | @Callable(i) |
---|
118 | | - | func deleteDepositLockRecords (records) = if (containsElement([adminPubKey1, adminPubKey2, adminPubKey3], i.callerPublicKey)) |
---|
119 | | - | then { |
---|
120 | | - | func generateDeletingKeys (accumulated,record) = DeleteEntry((record + "_locked")) :: accumulated |
---|
121 | | - | |
---|
122 | | - | let deleteKeys = { |
---|
123 | | - | let $l = records |
---|
124 | | - | let $s = size($l) |
---|
125 | | - | let $acc0 = nil |
---|
126 | | - | func 1 ($a,$i) = if (($i >= $s)) |
---|
127 | | - | then $a |
---|
128 | | - | else generateDeletingKeys($a, $l[$i]) |
---|
129 | | - | |
---|
130 | | - | func 2 ($a,$i) = if (($i >= $s)) |
---|
131 | | - | then $a |
---|
132 | | - | else throw("List size exceeds 100") |
---|
133 | | - | |
---|
134 | | - | 2(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1(1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10), 11), 12), 13), 14), 15), 16), 17), 18), 19), 20), 21), 22), 23), 24), 25), 26), 27), 28), 29), 30), 31), 32), 33), 34), 35), 36), 37), 38), 39), 40), 41), 42), 43), 44), 45), 46), 47), 48), 49), 50), 51), 52), 53), 54), 55), 56), 57), 58), 59), 60), 61), 62), 63), 64), 65), 66), 67), 68), 69), 70), 71), 72), 73), 74), 75), 76), 77), 78), 79), 80), 81), 82), 83), 84), 85), 86), 87), 88), 89), 90), 91), 92), 93), 94), 95), 96), 97), 98), 99), 100) |
---|
135 | | - | } |
---|
136 | | - | deleteKeys |
---|
137 | | - | } |
---|
138 | | - | else throw("Only admin can call this function") |
---|
139 | | - | |
---|
140 | | - | |
---|
141 | | - | |
---|
142 | | - | @Callable(i) |
---|
143 | | - | func issueToken (name,description,quantity,decimals) = if (containsElement([adminPubKey1, adminPubKey2, adminPubKey3], i.callerPublicKey)) |
---|
144 | | - | then [Issue(name, description, quantity, decimals, true, unit, 0)] |
---|
145 | | - | else throw("Only admin can call this function") |
---|
146 | | - | |
---|
147 | | - | |
---|
148 | | - | |
---|
149 | | - | @Callable(a8) |
---|
150 | | - | func call () = { |
---|
151 | | - | let pmtAmountA = 10 |
---|
152 | | - | let pmtAmountB = 1 |
---|
153 | | - | let pmtDecimalsA = 8 |
---|
154 | | - | let pmtDecimalsB = 6 |
---|
155 | | - | let shareDecimals = ((pmtDecimalsA + pmtDecimalsB) / 2) |
---|
156 | | - | let a9 = pow(pmtAmountA, pmtDecimalsA, 5, 1, pmtDecimalsA, DOWN) |
---|
157 | | - | let a10 = pow(pmtAmountB, pmtDecimalsB, 5, 1, pmtDecimalsB, DOWN) |
---|
158 | | - | let third = pow(10, 0, shareDecimals, 0, 0, DOWN) |
---|
159 | | - | let fouth = fraction(a9, a10, third) |
---|
160 | | - | [IntegerEntry("fisrt", a9), IntegerEntry("second", a10), IntegerEntry("third", third), IntegerEntry("fouth", fouth)] |
---|
161 | | - | } |
---|
162 | | - | |
---|
163 | | - | |
---|
164 | | - | |
---|
165 | | - | @Callable(i) |
---|
166 | | - | func deposit (pool) = if ((size(i.payments) != 1)) |
---|
167 | | - | then throw("One attached payment expected") |
---|
168 | | - | else { |
---|
169 | | - | let amount = i.payments[0].amount |
---|
170 | | - | let assetId = i.payments[0].assetId |
---|
171 | | - | let assetIdString = match assetId { |
---|
172 | | - | case id: ByteVector => |
---|
173 | | - | toBase58String(id) |
---|
174 | | - | case _ => |
---|
175 | | - | throw("Match error") |
---|
176 | | - | } |
---|
177 | | - | if ((0 >= amount)) |
---|
178 | | - | then throw(("Deposit amount must be positive. Actual: " + toString(amount))) |
---|
179 | | - | else { |
---|
180 | | - | let poolAmountKey = (pool + "_asset_balance") |
---|
181 | | - | let userAddress = toString(i.caller) |
---|
182 | | - | let userPoolAmountKey = (((pool + "_") + userAddress) + "_asset_balance") |
---|
183 | | - | let dAppAssetAddress = match getString((pool + "_service_token")) { |
---|
184 | | - | case string: String => |
---|
185 | | - | string |
---|
186 | | - | case nothing => |
---|
187 | | - | throw("You try to deposit on unsupported pool") |
---|
188 | | - | } |
---|
189 | | - | let liquidutyAssetAddress = match getString((pool + "_liquidity_token")) { |
---|
190 | | - | case string: String => |
---|
191 | | - | string |
---|
192 | | - | case nothing => |
---|
193 | | - | throw("You try to deposit on unsupported pool") |
---|
194 | | - | } |
---|
195 | | - | let liquidityTokenDecimal = match assetInfo(fromBase58String(liquidutyAssetAddress)) { |
---|
196 | | - | case asset: Asset => |
---|
197 | | - | asset.decimals |
---|
198 | | - | case _ => |
---|
199 | | - | throw("Can't find asset") |
---|
200 | | - | } |
---|
201 | | - | if ((liquidutyAssetAddress != assetIdString)) |
---|
202 | | - | then throw("You attached wrong liquidity token from Swop.fi") |
---|
203 | | - | else { |
---|
204 | | - | let poolAmount = getIntegerValue(this, poolAmountKey) |
---|
205 | | - | let userAmount = match getInteger(userPoolAmountKey) { |
---|
206 | | - | case int: Int => |
---|
207 | | - | int |
---|
208 | | - | case nothing => |
---|
209 | | - | 0 |
---|
210 | | - | } |
---|
211 | | - | let newPoolAmount = (poolAmount + amount) |
---|
212 | | - | let userAmountWithoutFee = ((amount - fraction(amount, 1, depositFee, HALFUP)) - fraction(amount, 1, controllerFee, HALFUP)) |
---|
213 | | - | let newUserPoolAmount = (userAmount + userAmountWithoutFee) |
---|
214 | | - | let lockTokensKey = (((((pool + "_") + userAddress) + "_") + toBase58String(i.transactionId)) + "_locked") |
---|
215 | | - | [Reissue(fromBase58String(dAppAssetAddress), userAmountWithoutFee, true), ScriptTransfer(i.caller, userAmountWithoutFee, fromBase58String(dAppAssetAddress)), IntegerEntry(lockTokensKey, userAmountWithoutFee), IntegerEntry(poolAmountKey, newPoolAmount), IntegerEntry(userPoolAmountKey, newUserPoolAmount)] |
---|
216 | | - | } |
---|
217 | | - | } |
---|
218 | | - | } |
---|
219 | | - | |
---|
220 | | - | |
---|
221 | | - | |
---|
222 | | - | @Callable(i) |
---|
223 | | - | func withdraw (pool,amount) = if ((0 >= amount)) |
---|
224 | | - | then throw(("Deposit amount must be positive. Actual: " + toString(amount))) |
---|
225 | | - | else { |
---|
226 | | - | let poolAmountKey = (pool + "_asset_balance") |
---|
227 | | - | let userAddress = toString(i.caller) |
---|
228 | | - | let userPoolAmountKey = (((pool + "_") + userAddress) + "_asset_balance") |
---|
229 | | - | let dAppAssetAddress = match getString((pool + "_service_token")) { |
---|
230 | | - | case string: String => |
---|
231 | | - | string |
---|
232 | | - | case nothing => |
---|
233 | | - | throw("You try to withdraw from unsupported pool") |
---|
234 | | - | } |
---|
235 | | - | let liquidutyAssetAddress = match getString((pool + "_liquidity_token")) { |
---|
236 | | - | case string: String => |
---|
237 | | - | string |
---|
238 | | - | case nothing => |
---|
239 | | - | throw("You try to withdraw from unsupported pool") |
---|
240 | | - | } |
---|
241 | | - | let poolAmount = getIntegerValue(this, poolAmountKey) |
---|
242 | | - | let userAmount = match getInteger(userPoolAmountKey) { |
---|
243 | | - | case int: Int => |
---|
244 | | - | int |
---|
245 | | - | case nothing => |
---|
246 | | - | 0 |
---|
247 | | - | } |
---|
248 | | - | let amountWithoutFee = ((amount - fraction(amount, 1, platformFee, HALFUP)) - fraction(amount, 1, controllerFee, HALFUP)) |
---|
249 | | - | let newPoolAmount = (poolAmount - amountWithoutFee) |
---|
250 | | - | if ((userAmount >= amount)) |
---|
251 | | - | then { |
---|
252 | | - | let newUserPoolAmount = (userAmount - amount) |
---|
253 | | - | [Burn(fromBase58String(dAppAssetAddress), amountWithoutFee), ScriptTransfer(i.caller, amountWithoutFee, fromBase58String(liquidutyAssetAddress)), IntegerEntry(poolAmountKey, newPoolAmount), IntegerEntry(userPoolAmountKey, newUserPoolAmount)] |
---|
254 | | - | } |
---|
255 | | - | else throw("You have not such balance for withdraw") |
---|
256 | | - | } |
---|
257 | | - | |
---|
258 | | - | |
---|
| 1 | + | # no script |
---|