-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathStakingIncentives.js
620 lines (505 loc) · 28.6 KB
/
StakingIncentives.js
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
/*global describe, beforeEach, it, context*/
const { ethers } = require("hardhat");
const { expect } = require("chai");
const helpers = require("@nomicfoundation/hardhat-network-helpers");
describe("StakingIncentives", async () => {
const initialMint = "1" + "0".repeat(26);
const AddressZero = ethers.constants.AddressZero;
const HashZero = ethers.constants.HashZero;
const defaultHash = "0x" + "5".repeat(64);
const oneYear = 365 * 24 * 3600;
const oneMonth = 86400 * 30;
const chainId = 31337;
const gnosisChainId = 100;
const mockChainId = 200;
const maxWeight = 10000;
let numClaimedEpochs = 1;
const bridgePayload = "0x";
const epochLen = oneMonth;
const maxNumClaimingEpochs = 10;
const maxNumStakingTargets = 100;
const defaultMinStakingWeight = 100;
const defaultMaxStakingIncentive = ethers.utils.parseEther("1");
let numInstances = 3;
const retainer = "0x" + "0".repeat(24) + "5".repeat(40);
const livenessRatio = "1" + "0".repeat(16); // 0.01 transaction per second (TPS)
let serviceParams = {
metadataHash: defaultHash,
maxNumServices: 3,
rewardsPerSecond: "1" + "0".repeat(18),
minStakingDeposit: 10,
minNumStakingPeriods: 3,
maxNumInactivityPeriods: 3,
livenessPeriod: 10, // Ten seconds
timeForEmissions: 100000000,
numAgentInstances: 1,
agentIds: [],
threshold: 0,
configHash: HashZero,
proxyHash: HashZero,
serviceRegistry: AddressZero,
activityChecker: AddressZero
};
// Double (fload) delta
const dDelta = 1. / 10**10;
// Big number delta
const bnDelta = 10**7;
let signers;
let deployer;
let olas;
let ve;
let vw;
let stakingActivityChecker;
let stakingFactory;
let stakingTokenImplementation;
let stakingInstances = new Array(numInstances);
let stakingInstanceAddresses = new Array(numInstances);
let stakingInstanceAddresses32 = new Array(numInstances);
let tokenomics;
let treasury;
let dispenser;
let ethereumDepositProcessor;
let bridgeRelayer;
let gnosisDepositProcessorL1;
let gnosisTargetDispenserL2;
let mockDepositProcessorL1;
function compare(a, b) {
if (a.toString() < b.toString()){
return -1;
}
if (a.toString() > b.toString()){
return 1;
}
return 0;
}
function convertAddressToBytes32(account) {
return ("0x" + "0".repeat(24) + account.slice(2)).toLowerCase();
}
function convertBytes32ToAddress(account) {
return "0x" + account.slice(26);
}
// These should not be in beforeEach.
beforeEach(async () => {
signers = await ethers.getSigners();
deployer = signers[0];
// Governance contracts
const OLAS = await ethers.getContractFactory("OLAS");
olas = await OLAS.deploy();
await olas.deployed();
const VEOLAS = await ethers.getContractFactory("veOLAS");
ve = await VEOLAS.deploy(olas.address, "Voting Escrow OLAS", "veOLAS");
await ve.deployed();
const VoteWeighting = await ethers.getContractFactory("VoteWeighting");
vw = await VoteWeighting.deploy(ve.address);
await vw.deployed();
// Registries contracts
const StakingActivityChecker = await ethers.getContractFactory("StakingActivityChecker");
stakingActivityChecker = await StakingActivityChecker.deploy(livenessRatio);
await stakingActivityChecker.deployed();
serviceParams.activityChecker = stakingActivityChecker.address;
const StakingFactory = await ethers.getContractFactory("StakingFactory");
stakingFactory = await StakingFactory.deploy(AddressZero);
await stakingFactory.deployed();
// For the purpose of this testing, it does not matter which bytecode is specified in the staking contract
// Also, service registry is not important, as the staking capability itself is out of this scope
const bytecode = await ethers.provider.getCode(stakingFactory.address);
const bytecodeHash = ethers.utils.keccak256(bytecode);
serviceParams.proxyHash = bytecodeHash;
serviceParams.serviceRegistry = stakingFactory.address;
const StakingToken = await ethers.getContractFactory("StakingToken");
stakingTokenImplementation = await StakingToken.deploy();
await stakingTokenImplementation.deployed();
// Create a first staking proxy instance
// Note serviceRegistryTokenUtility is also irrelevant for this testing (substituting with deployer)
const initPayload = stakingTokenImplementation.interface.encodeFunctionData("initialize",
[serviceParams, deployer.address, olas.address]);
// Create staking proxy instances
for (let i = 0; i < numInstances; i++) {
const tx = await stakingFactory.createStakingInstance(stakingTokenImplementation.address, initPayload);
const res = await tx.wait();
const stakingTokenAddress = "0x" + res.logs[0].topics[2].slice(26);
const stakingInstance = await ethers.getContractAt("StakingToken", stakingTokenAddress);
stakingInstances[i] = stakingInstance;
stakingInstanceAddresses[i] = stakingTokenAddress;
stakingInstanceAddresses32[i] = convertAddressToBytes32(stakingTokenAddress);
}
// Tokenomics contracts
const Dispenser = await ethers.getContractFactory("Dispenser");
dispenser = await Dispenser.deploy(olas.address, deployer.address, deployer.address, vw.address,
retainer, maxNumClaimingEpochs, maxNumStakingTargets, defaultMinStakingWeight, defaultMaxStakingIncentive);
await dispenser.deployed();
// Set Dispenser in Vote Weighting
vw.changeDispenser(dispenser.address);
const Treasury = await ethers.getContractFactory("Treasury");
treasury = await Treasury.deploy(olas.address, deployer.address, deployer.address, dispenser.address);
await treasury.deployed();
// Update for the correct treasury contract
await dispenser.changeManagers(AddressZero, treasury.address, AddressZero);
const tokenomicsFactory = await ethers.getContractFactory("Tokenomics");
// Deploy master tokenomics contract
const tokenomicsMaster = await tokenomicsFactory.deploy();
await tokenomicsMaster.deployed();
const proxyData = tokenomicsMaster.interface.encodeFunctionData("initializeTokenomics",
[olas.address, treasury.address, deployer.address, dispenser.address, deployer.address, epochLen,
deployer.address, deployer.address, deployer.address, AddressZero]);
// Deploy tokenomics proxy based on the needed tokenomics initialization
const TokenomicsProxy = await ethers.getContractFactory("TokenomicsProxy");
const tokenomicsProxy = await TokenomicsProxy.deploy(tokenomicsMaster.address, proxyData);
await tokenomicsProxy.deployed();
// Get the tokenomics proxy contract
tokenomics = await ethers.getContractAt("Tokenomics", tokenomicsProxy.address);
// Change the tokenomics and treasury addresses in the dispenser to correct ones
await dispenser.changeManagers(tokenomics.address, treasury.address, vw.address);
// Update tokenomics address in treasury
await treasury.changeManagers(tokenomics.address, AddressZero, AddressZero);
// Mint the initial balance
await olas.mint(deployer.address, initialMint);
// Give treasury the minter role
await olas.changeMinter(treasury.address);
// Default Deposit Processor
const EthereumDepositProcessor = await ethers.getContractFactory("EthereumDepositProcessor");
ethereumDepositProcessor = await EthereumDepositProcessor.deploy(olas.address, dispenser.address,
stakingFactory.address, deployer.address);
await ethereumDepositProcessor.deployed();
const BridgeRelayer = await ethers.getContractFactory("BridgeRelayer");
bridgeRelayer = await BridgeRelayer.deploy(olas.address);
await bridgeRelayer.deployed();
const GnosisDepositProcessorL1 = await ethers.getContractFactory("GnosisDepositProcessorL1");
gnosisDepositProcessorL1 = await GnosisDepositProcessorL1.deploy(olas.address, dispenser.address,
bridgeRelayer.address, bridgeRelayer.address, gnosisChainId);
await gnosisDepositProcessorL1.deployed();
const GnosisTargetDispenserL2 = await ethers.getContractFactory("GnosisTargetDispenserL2");
gnosisTargetDispenserL2 = await GnosisTargetDispenserL2.deploy(olas.address,
stakingFactory.address, bridgeRelayer.address, gnosisDepositProcessorL1.address, chainId);
await gnosisTargetDispenserL2.deployed();
// Set the gnosisTargetDispenserL2 address in gnosisDepositProcessorL1
await gnosisDepositProcessorL1.setL2TargetDispenser(gnosisTargetDispenserL2.address);
const MockDepositProcessorL1 = await ethers.getContractFactory("MockDepositProcessorL1");
mockDepositProcessorL1 = await MockDepositProcessorL1.deploy(olas.address, dispenser.address);
await mockDepositProcessorL1.deployed();
// Whitelist deposit processors
await dispenser.setDepositProcessorChainIds(
[ethereumDepositProcessor.address, gnosisDepositProcessorL1.address, mockDepositProcessorL1.address],
[chainId, gnosisChainId, mockChainId]);
});
context("Staking incentives", async function () {
it("Claim staking incentives with total veOLAS power bigger than inflation", async () => {
// Take a snapshot of the current state of the blockchain
const snapshot = await helpers.takeSnapshot();
// Set staking fraction to 100%
await tokenomics.changeIncentiveFractions(0, 0, 0, 0, 0, 100);
// Changing staking parameters (max staking amount, min weight (in 10_000 form, so 100 is 1%))
await tokenomics.changeStakingParams(ethers.utils.parseEther("300000"), 100);
// Checkpoint to apply changes
await helpers.time.increase(epochLen);
await tokenomics.checkpoint();
// Unpause the dispenser
await dispenser.setPauseState(0);
// Lock veOLAS
await olas.approve(ve.address, initialMint);
await ve.createLock(ethers.utils.parseEther("100000"), oneYear * 4);
// Transfer OLAS to another account
await olas.transfer(signers[1].address, ethers.utils.parseEther("200000"));
await olas.connect(signers[1]).approve(ve.address, initialMint);
await ve.connect(signers[1]).createLock(ethers.utils.parseEther("200000"), oneYear * 4);
// Add staking instances as nominees
for (let i = 0; i < numInstances; i++) {
await vw.addNomineeEVM(stakingInstances[i].address, chainId);
}
const chainIds = new Array(numInstances).fill(chainId);
// Vote for the nominees by the deployer
const weights = [maxWeight / 2, maxWeight / 2, 0];
await vw.voteForNomineeWeightsBatch(stakingInstanceAddresses32, chainIds, weights);
// Vote for the nominees by another wallet
const weights2 = [Math.floor(maxWeight / 3), Math.floor(maxWeight / 3), Math.floor(maxWeight / 3) + 1];
await vw.connect(signers[1]).voteForNomineeWeightsBatch(stakingInstanceAddresses32, chainIds, weights2);
// Checkpoint to apply changes
await helpers.time.increase(epochLen);
await tokenomics.checkpoint();
// Get the staking inflation for the previous epoch
const lastPoint = await tokenomics.epochCounter() - 1;
// Get the staking point of the last epoch
const sp = await tokenomics.mapEpochStakingPoints(lastPoint);
// Calculate total staking incentive and return amounts
let totalStakingIncentive = ethers.BigNumber.from(0);
let totalReturnAmount = ethers.BigNumber.from(0);
for (let i = 0; i < numInstances; i++) {
const res = await dispenser.callStatic.calculateStakingIncentives(numClaimedEpochs, chainId,
stakingInstanceAddresses32[i], 18);
totalStakingIncentive = totalStakingIncentive.add(res.totalStakingIncentive);
totalReturnAmount = totalReturnAmount.add(res.totalReturnAmount);
}
// Get the difference: staking inflation - (staking incentive + staking return)
let diff = sp.stakingIncentive.sub(totalStakingIncentive.add(totalReturnAmount));
expect(diff).to.lt(bnDelta);
// Sort staking addresses
stakingInstanceAddresses32.sort(compare);
// Claim staking incentives
await dispenser.claimStakingIncentivesBatch(numClaimedEpochs, [chainId], [stakingInstanceAddresses32],
[bridgePayload], [0]);
// Check that the target contract got OLAS
let sumBalance = ethers.BigNumber.from(0);
let sumWeights = ethers.BigNumber.from(0);
let balances = new Array(numInstances).fill(0);
let totalWeights = new Array(numInstances).fill(0);
for (let i = 0; i < numInstances; i++) {
const weightBN = ethers.BigNumber.from(weights[i]);
const weightBN2 = ethers.BigNumber.from(weights2[i]);
const maxWeightBN = ethers.BigNumber.from(maxWeight);
totalWeights[i] = ((await ve.getVotes(deployer.address)).mul(weightBN).
add((await ve.getVotes(signers[1].address)).mul(weightBN2))).div(maxWeightBN);
sumWeights = sumWeights.add(totalWeights[i]);
balances[i] = await olas.balanceOf(stakingInstances[i].address);
sumBalance = sumBalance.add(balances[i]);
expect(balances[i]).to.gt(0);
}
// The overall veOLAS power must be bigger than the inflation
expect(sumWeights).to.gt(sp.stakingIncentive);
// Since the veOLAS power is bigger than staking inflation, all the staking inflation must be used
diff = sp.stakingIncentive.sub(sumBalance);
expect(diff).to.lt(bnDelta);
// Restore to the state of the snapshot
await snapshot.restore();
});
it("Claim staking incentives with total veOLAS power smaller than inflation", async () => {
// Take a snapshot of the current state of the blockchain
const snapshot = await helpers.takeSnapshot();
// Set staking fraction to 100%
await tokenomics.changeIncentiveFractions(0, 0, 0, 0, 0, 100);
// Changing staking parameters (max staking amount, min weight (in 10_000 form, so 100 is 1%))
// The limit is much smaller than the staking inflation
await tokenomics.changeStakingParams(ethers.utils.parseEther("3"), 100);
// Checkpoint to apply changes
await helpers.time.increase(epochLen);
await tokenomics.checkpoint();
// Unpause the dispenser
await dispenser.setPauseState(0);
// Lock veOLAS
await olas.approve(ve.address, initialMint);
await ve.createLock(ethers.utils.parseEther("1"), oneYear);
// Transfer OLAS to another account
await olas.transfer(signers[1].address, ethers.utils.parseEther("2"));
await olas.connect(signers[1]).approve(ve.address, initialMint);
await ve.connect(signers[1]).createLock(ethers.utils.parseEther("2"), oneYear);
// Add staking instances as nominees
for (let i = 0; i < numInstances; i++) {
await vw.addNomineeEVM(stakingInstances[i].address, chainId);
}
const chainIds = new Array(numInstances).fill(chainId);
// Vote for the nominees by the deployer
const weights = [maxWeight / 2, maxWeight / 2, 0];
await vw.voteForNomineeWeightsBatch(stakingInstanceAddresses32, chainIds, weights);
// Vote for the nominees by another wallet
const weights2 = [Math.floor(maxWeight / 3), Math.floor(maxWeight / 3), Math.floor(maxWeight / 3) + 1];
await vw.connect(signers[1]).voteForNomineeWeightsBatch(stakingInstanceAddresses32, chainIds, weights2);
// Checkpoint to apply changes
await helpers.time.increase(epochLen);
await tokenomics.checkpoint();
// Get the staking inflation for the previous epoch
const lastPoint = await tokenomics.epochCounter() - 1;
// Get the staking point of the last epoch
const sp = await tokenomics.mapEpochStakingPoints(lastPoint);
// Calculate total staking incentive and return amounts
let totalStakingIncentive = ethers.BigNumber.from(0);
let totalReturnAmount = ethers.BigNumber.from(0);
for (let i = 0; i < numInstances; i++) {
const res = await dispenser.callStatic.calculateStakingIncentives(numClaimedEpochs, chainId,
stakingInstanceAddresses32[i], 18);
totalStakingIncentive = totalStakingIncentive.add(res.totalStakingIncentive);
totalReturnAmount = totalReturnAmount.add(res.totalReturnAmount);
}
// Get the difference: staking inflation - (staking incentive + staking return)
const diff = sp.stakingIncentive.sub(totalStakingIncentive.add(totalReturnAmount));
expect(diff).to.lt(bnDelta);
// Sort staking addresses
stakingInstanceAddresses32.sort(compare);
// Claim staking incentives
await dispenser.claimStakingIncentivesBatch(numClaimedEpochs, [chainId], [stakingInstanceAddresses32],
[bridgePayload], [0]);
// Check that the target contract got OLAS
let balances = new Array(numInstances).fill(0);
let totalWeights = new Array(numInstances).fill(0);
let ratios = new Array(numInstances).fill(0);
let ratioSum = 0;
for (let i = 0; i < numInstances; i++) {
const weightBN = ethers.BigNumber.from(weights[i]);
const weightBN2 = ethers.BigNumber.from(weights2[i]);
const maxWeightBN = ethers.BigNumber.from(maxWeight);
totalWeights[i] = ((await ve.getVotes(deployer.address)).mul(weightBN).
add((await ve.getVotes(signers[1].address)).mul(weightBN2))).div(maxWeightBN);
balances[i] = await olas.balanceOf(stakingInstances[i].address);
expect(balances[i]).to.gt(0);
ratios[i] = Number(totalWeights[i]) / Number(balances[i]);
ratioSum += ratios[i];
}
// The weight / balance ratio must be approximately the same for all the elements
const ratioAverage = ratioSum / numInstances;
for (let i = 0; i < numInstances; i++) {
const diff = Math.abs(ratios[i] - ratioAverage);
expect(diff).to.lt(dDelta);
}
// Restore to the state of the snapshot
await snapshot.restore();
});
});
context("Limits", async function () {
it("Number of epochs to claim with a single staking contracts", async () => {
// Take a snapshot of the current state of the blockchain
const snapshot = await helpers.takeSnapshot();
numClaimedEpochs = 10;
// Set staking fraction to 100%
await tokenomics.changeIncentiveFractions(0, 0, 0, 0, 0, 100);
// Changing staking parameters (max staking amount, min weight (in 10_000 form, so 100 is 1%))
await tokenomics.changeStakingParams(ethers.utils.parseEther("10"), 100);
// Checkpoint to apply changes
await helpers.time.increase(epochLen);
await tokenomics.checkpoint();
// Unpause the dispenser
await dispenser.setPauseState(0);
// Lock veOLAS
await olas.approve(ve.address, initialMint);
await ve.createLock(ethers.utils.parseEther("10"), oneYear * 4);
// Add a staking instances as a nominee
await vw.addNomineeEVM(stakingInstances[0].address, mockChainId);
// Vote for the nominee by the deployer
await vw.voteForNomineeWeightsBatch([stakingInstanceAddresses32[0]], [mockChainId], [maxWeight]);
// Checkpoint for the number of claimed epochs
for (let i = 0; i < numClaimedEpochs; i++) {
await helpers.time.increase(epochLen);
await tokenomics.checkpoint();
}
// Claim staking incentives
await dispenser.claimStakingIncentivesBatch(numClaimedEpochs, [mockChainId], [[stakingInstanceAddresses32[0]]],
[bridgePayload], [0]);
// Restore to the state of the snapshot
await snapshot.restore();
});
it("Number of epochs to claim with 100 staking contracts", async () => {
// Take a snapshot of the current state of the blockchain
const snapshot = await helpers.takeSnapshot();
numClaimedEpochs = 10;
// Set staking fraction to 100%
await tokenomics.changeIncentiveFractions(0, 0, 0, 0, 0, 100);
// Changing staking parameters (max staking amount, min weight (in 10_000 form, so 100 is 1%))
await tokenomics.changeStakingParams(ethers.utils.parseEther("10"), 100);
// Checkpoint to apply changes
await helpers.time.increase(epochLen);
await tokenomics.checkpoint();
// Unpause the dispenser
await dispenser.setPauseState(0);
// Lock veOLAS
await olas.approve(ve.address, initialMint);
await ve.createLock(ethers.utils.parseEther("10"), oneYear * 4);
// Add staking instances as nominees
for (let i = 0; i < numInstances; i++) {
await vw.addNomineeEVM(stakingInstances[i].address, mockChainId);
}
const chainIds = new Array(numInstances).fill(mockChainId);
// Vote for the nominees by the deployer
const weights = [Math.floor(maxWeight / 3), Math.floor(maxWeight / 3), Math.floor(maxWeight / 3) + 1];
await vw.voteForNomineeWeightsBatch(stakingInstanceAddresses32, chainIds, weights);
// Checkpoint for the number of claimed epochs
for (let i = 0; i < numClaimedEpochs; i++) {
await helpers.time.increase(epochLen);
await tokenomics.checkpoint();
}
// Sort staking addresses
stakingInstanceAddresses32.sort(compare);
// Claim staking incentives
await dispenser.claimStakingIncentivesBatch(numClaimedEpochs, [mockChainId], [stakingInstanceAddresses32],
[bridgePayload], [0]);
// Restore to the state of the snapshot
await snapshot.restore();
});
it("Number of epochs to claim with max limiting values", async () => {
// Take a snapshot of the current state of the blockchain
const snapshot = await helpers.takeSnapshot();
numClaimedEpochs = 1;
numInstances = 100;
stakingInstances = new Array(numInstances);
stakingInstanceAddresses = new Array(numInstances);
stakingInstanceAddresses32 = new Array(numInstances);
// Get the standard service staking payload
const initPayload = stakingTokenImplementation.interface.encodeFunctionData("initialize",
[serviceParams, deployer.address, olas.address]);
// Create staking proxy instances
for (let i = 0; i < numInstances; i++) {
const stakingTokenAddress = await stakingFactory.getProxyAddress(stakingTokenImplementation.address);
await stakingFactory.createStakingInstance(stakingTokenImplementation.address, initPayload);
const stakingInstance = await ethers.getContractAt("StakingToken", stakingTokenAddress);
stakingInstances[i] = stakingInstance;
stakingInstanceAddresses[i] = stakingTokenAddress;
stakingInstanceAddresses32[i] = convertAddressToBytes32(stakingTokenAddress);
}
// Set staking fraction to 100%
await tokenomics.changeIncentiveFractions(0, 0, 0, 0, 0, 100);
// Changing staking parameters (max staking amount, min weight (in 10_000 form, so 100 is 1%))
await tokenomics.changeStakingParams(ethers.utils.parseEther("10"), 100);
// Checkpoint to apply changes
await helpers.time.increase(epochLen);
await tokenomics.checkpoint();
// Unpause the dispenser
await dispenser.setPauseState(0);
// Lock veOLAS
await olas.approve(ve.address, initialMint);
await ve.createLock(ethers.utils.parseEther("10"), oneYear * 4);
// Add staking instances as nominees
for (let i = 0; i < numInstances; i++) {
await vw.addNomineeEVM(stakingInstances[i].address, mockChainId);
}
const chainIds = new Array(numInstances).fill(mockChainId);
// Vote for the nominees by the deployer
const weights = new Array(numInstances).fill(Math.floor(maxWeight / numInstances));
await vw.voteForNomineeWeightsBatch(stakingInstanceAddresses32, chainIds, weights);
// Sort staking addresses
stakingInstanceAddresses32.sort(compare);
// Checkpoint for the number of claimed epochs
for (let i = 0; i < numClaimedEpochs; i++) {
await helpers.time.increase(epochLen);
await tokenomics.checkpoint();
}
// Claim staking incentives
await dispenser.claimStakingIncentivesBatch(numClaimedEpochs, [mockChainId], [stakingInstanceAddresses32],
[bridgePayload], [0]);
// Restore to the state of the snapshot
await snapshot.restore();
});
it("Limiting values on L2 side", async () => {
// Take a snapshot of the current state of the blockchain
const snapshot = await helpers.takeSnapshot();
numInstances = 50;
stakingInstances = new Array(numInstances);
stakingInstanceAddresses = new Array(numInstances);
stakingInstanceAddresses32 = new Array(numInstances);
// Get the standard service staking payload
const initPayload = stakingTokenImplementation.interface.encodeFunctionData("initialize",
[serviceParams, deployer.address, olas.address]);
// Create staking proxy instances
for (let i = 0; i < numInstances; i++) {
const tx = await stakingFactory.createStakingInstance(stakingTokenImplementation.address, initPayload);
const res = await tx.wait();
const stakingTokenAddress = "0x" + res.logs[0].topics[2].slice(26);
stakingInstanceAddresses[i] = stakingTokenAddress;
}
// Mock the processing of staking contracts
const MockStakingDispenser = await ethers.getContractFactory("MockStakingDispenser");
dispenser = await MockStakingDispenser.deploy(olas.address);
await dispenser.deployed();
// Update dispenser address in treasury and tokenomics
await treasury.changeManagers(AddressZero, AddressZero, dispenser.address);
await tokenomics.changeManagers(AddressZero, AddressZero, dispenser.address);
await olas.changeMinter(dispenser.address);
const EthereumDepositProcessor = await ethers.getContractFactory("EthereumDepositProcessor");
ethereumDepositProcessor = await EthereumDepositProcessor.deploy(olas.address, dispenser.address,
stakingFactory.address, deployer.address);
await ethereumDepositProcessor.deployed();
const amount = 1000;
const stakingIncentives = new Array(numInstances).fill(amount);
// Claim staking incentives
await dispenser.sendMessageBatch(ethereumDepositProcessor.address, stakingInstanceAddresses,
stakingIncentives, bridgePayload, amount * numInstances);
// Restore to the state of the snapshot
await snapshot.restore();
});
});
});