1 | 1 | | {-# STDLIB_VERSION 6 #-} |
---|
2 | 2 | | {-# SCRIPT_TYPE ACCOUNT #-} |
---|
3 | 3 | | {-# CONTENT_TYPE DAPP #-} |
---|
4 | 4 | | let SEP = "__" |
---|
5 | 5 | | |
---|
6 | 6 | | func wrapErr (msg) = makeString(["emission.ride:", toString(this), msg], " ") |
---|
7 | 7 | | |
---|
8 | 8 | | |
---|
9 | 9 | | func throwErr (msg) = throw(wrapErr(msg)) |
---|
10 | 10 | | |
---|
11 | 11 | | |
---|
12 | 12 | | func getStringOrFail (address,key) = valueOrErrorMessage(getString(address, key), wrapErr((("mandatory this." + key) + " is not defined"))) |
---|
13 | 13 | | |
---|
14 | 14 | | |
---|
15 | 15 | | func keyFactoryAddress () = "%s%s__config__factoryAddress" |
---|
16 | 16 | | |
---|
17 | 17 | | |
---|
18 | 18 | | let keyVotingVerifiedContract = "%s%s__config__votingVerifiedContract" |
---|
19 | 19 | | |
---|
20 | 20 | | let keyVotingEmissionCandidateContract = "%s%s__config__votingEmissionCandidateContract" |
---|
21 | 21 | | |
---|
22 | 22 | | let keyUserPoolsContract = "%s%s__config__userPoolsContract" |
---|
23 | 23 | | |
---|
24 | 24 | | let keyVotingEmissionRateContract = "%s%s__config__votingEmissionRateContract" |
---|
25 | 25 | | |
---|
26 | 26 | | let votingVerifiedContract = addressFromStringValue(getStringOrFail(this, keyVotingVerifiedContract)) |
---|
27 | 27 | | |
---|
28 | 28 | | let votingEmissionCandidateContract = addressFromStringValue(getStringOrFail(this, keyVotingEmissionCandidateContract)) |
---|
29 | 29 | | |
---|
30 | 30 | | let userPoolsContract = addressFromStringValue(getStringOrFail(this, keyUserPoolsContract)) |
---|
31 | 31 | | |
---|
32 | 32 | | let votingEmissionRateContract = addressFromStringValue(getStringOrFail(this, keyVotingEmissionRateContract)) |
---|
33 | 33 | | |
---|
34 | 34 | | let IdxFactoryCfgStakingDapp = 1 |
---|
35 | 35 | | |
---|
36 | 36 | | let IdxFactoryCfgBoostingDapp = 2 |
---|
37 | 37 | | |
---|
38 | 38 | | let IdxFactoryCfgIdoDapp = 3 |
---|
39 | 39 | | |
---|
40 | 40 | | let IdxFactoryCfgTeamDapp = 4 |
---|
41 | 41 | | |
---|
42 | 42 | | let IdxFactoryCfgEmissionDapp = 5 |
---|
43 | 43 | | |
---|
44 | 44 | | let IdxFactoryCfgRestDapp = 6 |
---|
45 | 45 | | |
---|
46 | 46 | | let IdxFactoryCfgSlippageDapp = 7 |
---|
47 | 47 | | |
---|
48 | 48 | | let IdxFactoryCfgGwxRewardDapp = 10 |
---|
49 | 49 | | |
---|
50 | 50 | | func keyFactoryCfg () = "%s__factoryConfig" |
---|
51 | 51 | | |
---|
52 | 52 | | |
---|
53 | 53 | | func keyFactoryLp2AssetsMapping (lpAssetStr) = makeString(["%s%s%s", lpAssetStr, "mappings__lpAsset2PoolContract"], SEP) |
---|
54 | 54 | | |
---|
55 | 55 | | |
---|
56 | 56 | | func keyFactoryLpList () = "%s__lpTokensList" |
---|
57 | 57 | | |
---|
58 | 58 | | |
---|
59 | 59 | | func keyFactoryLpAssetToPoolContractAddress (lpAssetStr) = makeString(["%s%s%s", lpAssetStr, "mappings__lpAsset2PoolContract"], SEP) |
---|
60 | 60 | | |
---|
61 | 61 | | |
---|
62 | 62 | | func keyFactoryPoolWeight (contractAddress) = makeString(["%s%s", "poolWeight", contractAddress], SEP) |
---|
63 | 63 | | |
---|
64 | 64 | | |
---|
65 | 65 | | func readFactoryAddressOrFail () = addressFromStringValue(getStringOrFail(this, keyFactoryAddress())) |
---|
66 | 66 | | |
---|
67 | 67 | | |
---|
68 | 68 | | func readLpList () = split(valueOrElse(getString(readFactoryAddressOrFail(), keyFactoryLpList()), ""), SEP) |
---|
69 | 69 | | |
---|
70 | 70 | | |
---|
71 | 71 | | func readFactoryCfgOrFail (factory) = split(getStringOrFail(factory, keyFactoryCfg()), SEP) |
---|
72 | 72 | | |
---|
73 | 73 | | |
---|
74 | 74 | | func getBoostingAddressOrFail (factoryCfg) = addressFromStringValue(factoryCfg[IdxFactoryCfgBoostingDapp]) |
---|
75 | 75 | | |
---|
76 | 76 | | |
---|
77 | 77 | | func getEmissionAddressOrFail (factoryCfg) = addressFromStringValue(factoryCfg[IdxFactoryCfgEmissionDapp]) |
---|
78 | 78 | | |
---|
79 | 79 | | |
---|
80 | 80 | | func getStakingAddressOrFail (factoryCfg) = addressFromStringValue(factoryCfg[IdxFactoryCfgStakingDapp]) |
---|
81 | 81 | | |
---|
82 | 82 | | |
---|
83 | 83 | | func getGwxRewardAddressOrFail (factoryCfg) = addressFromStringValue(factoryCfg[IdxFactoryCfgGwxRewardDapp]) |
---|
84 | 84 | | |
---|
85 | 85 | | |
---|
86 | 86 | | func keyConfig () = "%s__config" |
---|
87 | 87 | | |
---|
88 | 88 | | |
---|
89 | 89 | | func keyRatePerBlockMaxCurrent () = "%s%s__ratePerBlockMax__current" |
---|
90 | 90 | | |
---|
91 | 91 | | |
---|
92 | 92 | | func keyRatePerBlockMaxStartFrom (timestamp,block) = makeString(["%s%s%d%d__ratePerBlockMax__start", toString(timestamp), toString(block)], SEP) |
---|
93 | 93 | | |
---|
94 | 94 | | |
---|
95 | 95 | | func keyRatePerBlockCurrent () = "%s%s__ratePerBlock__current" |
---|
96 | 99 | | |
---|
97 | 100 | | |
---|
98 | 101 | | func keyRatePerBlockStartFrom (timestamp,block) = makeString(["%s%s%d%d__ratePerBlock__start", toString(timestamp), toString(block)], SEP) |
---|
99 | 102 | | |
---|
100 | 103 | | |
---|
101 | 104 | | func keyEmissionStartBlock () = "%s%s__emission__startBlock" |
---|
102 | 105 | | |
---|
103 | 106 | | |
---|
104 | 107 | | func keyEmissionDurationInBlocks () = "%s%s__emission__duration" |
---|
105 | 108 | | |
---|
106 | 109 | | |
---|
107 | 110 | | func keyEmissionEndBlock () = "%s%s__emission__endBlock" |
---|
108 | 111 | | |
---|
109 | 112 | | |
---|
110 | 113 | | func keyBoostCoeff () = "%s__boostCoeff" |
---|
111 | 114 | | |
---|
112 | 115 | | |
---|
113 | 116 | | let boostCoeffDefault = 3 |
---|
114 | 117 | | |
---|
115 | 118 | | let boostCoeff = valueOrElse(getInteger(this, keyBoostCoeff()), boostCoeffDefault) |
---|
116 | 119 | | |
---|
117 | 120 | | func keyGwxHoldersRewardCurrent () = "%s%s__gwxHoldersReward__current" |
---|
118 | 121 | | |
---|
119 | 122 | | |
---|
120 | 123 | | func keyGwxHoldersRewardNext () = "%s%s__gwxHoldersReward__next" |
---|
121 | 124 | | |
---|
122 | 125 | | |
---|
123 | 126 | | func keyManagerPublicKey () = "%s__managerPublicKey" |
---|
124 | 127 | | |
---|
125 | 128 | | |
---|
126 | 129 | | func keyManagerVaultAddress () = "%s__managerVaultAddress" |
---|
127 | 130 | | |
---|
128 | 131 | | |
---|
129 | 132 | | func getManagerVaultAddressOrThis () = match getString(keyManagerVaultAddress()) { |
---|
130 | 133 | | case s: String => |
---|
131 | 134 | | addressFromStringValue(s) |
---|
132 | 135 | | case _ => |
---|
133 | 136 | | this |
---|
134 | 137 | | } |
---|
135 | 138 | | |
---|
136 | 139 | | |
---|
137 | 140 | | func managerPublicKeyOrUnit () = { |
---|
138 | 141 | | let managerVaultAddress = getManagerVaultAddressOrThis() |
---|
139 | 142 | | match getString(managerVaultAddress, keyManagerPublicKey()) { |
---|
140 | 143 | | case s: String => |
---|
141 | 144 | | fromBase58String(s) |
---|
142 | 145 | | case _: Unit => |
---|
143 | 146 | | unit |
---|
144 | 147 | | case _ => |
---|
145 | 148 | | throw("Match error") |
---|
146 | 149 | | } |
---|
147 | 150 | | } |
---|
148 | 151 | | |
---|
149 | 152 | | |
---|
150 | 153 | | func mustManager (i) = { |
---|
151 | 154 | | let pd = throwErr("Permission denied") |
---|
152 | 155 | | match managerPublicKeyOrUnit() { |
---|
153 | 156 | | case pk: ByteVector => |
---|
154 | 157 | | if ((i.callerPublicKey == pk)) |
---|
155 | 158 | | then true |
---|
156 | 159 | | else pd |
---|
157 | 160 | | case _: Unit => |
---|
158 | 161 | | if ((i.caller == this)) |
---|
159 | 162 | | then true |
---|
160 | 163 | | else pd |
---|
161 | 164 | | case _ => |
---|
162 | 165 | | throw("Match error") |
---|
163 | 166 | | } |
---|
164 | 167 | | } |
---|
165 | 168 | | |
---|
166 | 169 | | |
---|
167 | 170 | | @Callable(i) |
---|
168 | 171 | | func constructor (factoryAddress,ratePerBlockMax,ratePerBlock,emissionStartBlock,emissionDuration,emissionStartTimestamp,wxAssetIdStr) = { |
---|
169 | 172 | | let checkCaller = mustManager(i) |
---|
170 | 173 | | if ((checkCaller == checkCaller)) |
---|
171 | 174 | | then [IntegerEntry(keyRatePerBlockMaxStartFrom(emissionStartTimestamp, emissionStartBlock), ratePerBlockMax), IntegerEntry(keyRatePerBlockMaxCurrent(), ratePerBlockMax), IntegerEntry(keyRatePerBlockStartFrom(emissionStartTimestamp, emissionStartBlock), ratePerBlock), IntegerEntry(keyRatePerBlockCurrent(), ratePerBlock), IntegerEntry(keyEmissionStartBlock(), emissionStartBlock), IntegerEntry(keyEmissionDurationInBlocks(), emissionDuration), IntegerEntry(keyEmissionEndBlock(), (emissionStartBlock + emissionDuration)), StringEntry(keyFactoryAddress(), factoryAddress), StringEntry(keyConfig(), ("%s__" + wxAssetIdStr))] |
---|
172 | 175 | | else throw("Strict value is not equal to itself.") |
---|
173 | 176 | | } |
---|
174 | 177 | | |
---|
175 | 178 | | |
---|
176 | 179 | | |
---|
177 | 180 | | @Callable(i) |
---|
178 | 181 | | func constructorV2 (votingVerifiedContractPrm) = { |
---|
179 | 182 | | let checkCaller = mustManager(i) |
---|
180 | 183 | | if ((checkCaller == checkCaller)) |
---|
181 | 184 | | then $Tuple2([StringEntry(keyVotingVerifiedContract, votingVerifiedContractPrm)], unit) |
---|
182 | 185 | | else throw("Strict value is not equal to itself.") |
---|
183 | 186 | | } |
---|
184 | 187 | | |
---|
185 | 188 | | |
---|
186 | 189 | | |
---|
187 | 190 | | @Callable(i) |
---|
188 | 191 | | func emit (amount) = if ((0 >= amount)) |
---|
189 | 192 | | then $Tuple2(nil, nil) |
---|
190 | 193 | | else { |
---|
191 | 194 | | let factoryContract = readFactoryAddressOrFail() |
---|
192 | 195 | | let factoryCfg = readFactoryCfgOrFail(factoryContract) |
---|
193 | 196 | | let stakingContract = getStakingAddressOrFail(factoryCfg) |
---|
194 | 197 | | let gwxRewardsContract = getGwxRewardAddressOrFail(factoryCfg) |
---|
195 | 198 | | let caller = i.caller |
---|
196 | 199 | | if (if ((caller != stakingContract)) |
---|
197 | 200 | | then (caller != gwxRewardsContract) |
---|
198 | 201 | | else false) |
---|
199 | 202 | | then throwErr("permissions denied") |
---|
200 | 203 | | else { |
---|
201 | 204 | | let wxAssetIdStr = split(getStringOrFail(this, keyConfig()), SEP)[1] |
---|
202 | 205 | | let wxAssetId = fromBase58String(wxAssetIdStr) |
---|
203 | 206 | | $Tuple2([ScriptTransfer(caller, amount, wxAssetId)], [wxAssetId]) |
---|
204 | 207 | | } |
---|
205 | 208 | | } |
---|
206 | 209 | | |
---|
207 | 210 | | |
---|
208 | 211 | | |
---|
209 | 212 | | @Callable(i) |
---|
210 | 213 | | func burn () = { |
---|
211 | 214 | | let factoryContract = readFactoryAddressOrFail() |
---|
212 | 215 | | let factoryCfg = readFactoryCfgOrFail(factoryContract) |
---|
213 | 216 | | let boostingContract = getBoostingAddressOrFail(factoryCfg) |
---|
214 | 217 | | if ((size(i.payments) != 1)) |
---|
215 | 218 | | then throwErr("exact one payment is allowed") |
---|
216 | 219 | | else { |
---|
217 | 220 | | let pmt = i.payments[0] |
---|
218 | 221 | | let assetId = value(pmt.assetId) |
---|
219 | 222 | | let pmtAmount = pmt.amount |
---|
220 | 223 | | let wxAssetId = fromBase58String(split(getStringOrFail(this, keyConfig()), SEP)[1]) |
---|
221 | 224 | | if ((assetId != wxAssetId)) |
---|
222 | 225 | | then throwErr("invalid wxAssetId is passed") |
---|
223 | 226 | | else if (!(containsElement([boostingContract, votingVerifiedContract, votingEmissionCandidateContract, userPoolsContract], i.caller))) |
---|
224 | 227 | | then throwErr("permissions denied") |
---|
225 | 228 | | else [Burn(assetId, pmtAmount), StringEntry(("%s%s%s__history__burn__" + toBase58String(i.transactionId)), makeString(["%d%d%d", toString(height), toString(lastBlock.timestamp), toString(pmtAmount)], SEP))] |
---|
226 | 229 | | } |
---|
227 | 230 | | } |
---|
228 | 231 | | |
---|
229 | 232 | | |
---|
230 | 233 | | |
---|
231 | 234 | | @Callable(i) |
---|
232 | 235 | | func gwxHoldersRewardUpdate () = { |
---|
233 | 236 | | let factoryContract = readFactoryAddressOrFail() |
---|
234 | 237 | | let factoryCfg = readFactoryCfgOrFail(factoryContract) |
---|
235 | 238 | | let gwxRewardsContract = getGwxRewardAddressOrFail(factoryCfg) |
---|
236 | 239 | | let checkCaller = if ((i.caller == gwxRewardsContract)) |
---|
237 | 240 | | then true |
---|
238 | 241 | | else mustManager(i) |
---|
239 | 242 | | if ((checkCaller == checkCaller)) |
---|
240 | 243 | | then { |
---|
241 | 244 | | let gwxHolderRewardCurrent = valueOrElse(getInteger(keyGwxHoldersRewardCurrent()), 0) |
---|
242 | 245 | | let gwxHolderRewardNext = valueOrElse(getInteger(keyGwxHoldersRewardNext()), gwxHolderRewardCurrent) |
---|
243 | 246 | | let shouldBeUpdated = (gwxHolderRewardCurrent != gwxHolderRewardNext) |
---|
244 | 247 | | let actions = if (shouldBeUpdated) |
---|
245 | 248 | | then [IntegerEntry(keyGwxHoldersRewardCurrent(), gwxHolderRewardNext), DeleteEntry(keyGwxHoldersRewardNext())] |
---|
246 | 249 | | else nil |
---|
247 | 250 | | $Tuple2(actions, shouldBeUpdated) |
---|
248 | 251 | | } |
---|
249 | 252 | | else throw("Strict value is not equal to itself.") |
---|
250 | 253 | | } |
---|
251 | 254 | | |
---|
252 | 255 | | |
---|
253 | 256 | | |
---|
254 | 257 | | @Callable(i) |
---|
255 | 258 | | func getBoostCoeffREADONLY () = $Tuple2(nil, boostCoeff) |
---|
256 | 259 | | |
---|
257 | 260 | | |
---|
258 | 261 | | |
---|
259 | 262 | | @Callable(i) |
---|
260 | 263 | | func changeRatePerBlock (newRatePerBlock) = { |
---|
261 | 264 | | let check = if (if ((i.caller == votingEmissionRateContract)) |
---|
262 | 265 | | then true |
---|
263 | 266 | | else mustManager(i)) |
---|
264 | 267 | | then true |
---|
265 | 268 | | else throwErr("should be invoked by votingEmissionRateContract") |
---|
266 | 269 | | if ((check == check)) |
---|
267 | 270 | | then { |
---|
268 | 271 | | let factoryContract = readFactoryAddressOrFail() |
---|
269 | 272 | | let factoryCfg = readFactoryCfgOrFail(factoryContract) |
---|
270 | 273 | | let boostingContract = getBoostingAddressOrFail(factoryCfg) |
---|
271 | 274 | | let boostingInvoke = reentrantInvoke(boostingContract, "onBoostEmissionUpdate", nil, nil) |
---|
272 | 275 | | if ((boostingInvoke == boostingInvoke)) |
---|
273 | 276 | | then { |
---|
274 | 277 | | let blockTimestamp = match blockInfoByHeight(height) { |
---|
275 | 278 | | case bi: BlockInfo => |
---|
276 | 279 | | bi.timestamp |
---|
277 | 280 | | case _ => |
---|
278 | 281 | | throwErr("BlockInfo.timestamp error") |
---|
279 | 282 | | } |
---|
280 | 283 | | [IntegerEntry(keyRatePerBlockStartFrom(blockTimestamp, height), newRatePerBlock), IntegerEntry(keyRatePerBlockCurrent(), newRatePerBlock)] |
---|
281 | 284 | | } |
---|
282 | 285 | | else throw("Strict value is not equal to itself.") |
---|
283 | 286 | | } |
---|
284 | 287 | | else throw("Strict value is not equal to itself.") |
---|
285 | 288 | | } |
---|
286 | 289 | | |
---|
287 | 290 | | |
---|
288 | 291 | | @Verifier(tx) |
---|
289 | 292 | | func verify () = { |
---|
290 | 293 | | let targetPublicKey = match managerPublicKeyOrUnit() { |
---|
291 | 294 | | case pk: ByteVector => |
---|
292 | 295 | | pk |
---|
293 | 296 | | case _: Unit => |
---|
294 | 297 | | tx.senderPublicKey |
---|
295 | 298 | | case _ => |
---|
296 | 299 | | throw("Match error") |
---|
297 | 300 | | } |
---|
298 | 301 | | sigVerify(tx.bodyBytes, tx.proofs[0], targetPublicKey) |
---|
299 | 302 | | } |
---|
300 | 303 | | |
---|