|
| 1 | +import { VeBalHelper } from '@custom-types/contracts'; |
| 2 | +import { NamedAddresses, NamedContracts } from '@custom-types/types'; |
| 3 | +import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'; |
| 4 | +import { ProposalsConfig } from '@protocol/proposalsConfig'; |
| 5 | +import { getAddresses, getImpersonatedSigner, time } from '@test/helpers'; |
| 6 | +import { TestEndtoEndCoordinator } from '@test/integration/setup'; |
| 7 | +import chai, { expect } from 'chai'; |
| 8 | +import CBN from 'chai-bn'; |
| 9 | +import { solidity } from 'ethereum-waffle'; |
| 10 | +import { Contract, Signer } from 'ethers'; |
| 11 | +import { ethers } from 'hardhat'; |
| 12 | +import { forceEth } from '../setup/utils'; |
| 13 | + |
| 14 | +before(async () => { |
| 15 | + chai.use(CBN(ethers.BigNumber)); |
| 16 | + chai.use(solidity); |
| 17 | +}); |
| 18 | + |
| 19 | +describe('e2e-veBalHelper-boost-management', function () { |
| 20 | + const impersonatedSigners: { [key: string]: Signer } = {}; |
| 21 | + let contracts: NamedContracts; |
| 22 | + let contractAddresses: NamedAddresses; |
| 23 | + let deployAddress: string; |
| 24 | + let e2eCoord: TestEndtoEndCoordinator; |
| 25 | + let doLogging: boolean; |
| 26 | + let vebalOtcHelper: Contract; |
| 27 | + let otcBuyerAddress: string; |
| 28 | + let otcBuyerSigner: SignerWithAddress; |
| 29 | + |
| 30 | + beforeEach(async function () { |
| 31 | + deployAddress = (await ethers.getSigners())[0].address; |
| 32 | + if (!deployAddress) throw new Error(`No deploy address!`); |
| 33 | + const addresses = await getAddresses(); |
| 34 | + // add any addresses you want to impersonate here |
| 35 | + const impersonatedAddresses = [addresses.userAddress, addresses.pcvControllerAddress, addresses.governorAddress]; |
| 36 | + |
| 37 | + doLogging = Boolean(process.env.LOGGING); |
| 38 | + |
| 39 | + const config = { |
| 40 | + logging: doLogging, |
| 41 | + deployAddress: deployAddress, |
| 42 | + version: 1 |
| 43 | + }; |
| 44 | + |
| 45 | + e2eCoord = new TestEndtoEndCoordinator(config, ProposalsConfig); |
| 46 | + |
| 47 | + doLogging && console.log(`Loading environment...`); |
| 48 | + ({ contracts, contractAddresses } = await e2eCoord.loadEnvironment()); |
| 49 | + |
| 50 | + ({ vebalOtcHelper } = contracts); |
| 51 | + doLogging && console.log(`Environment loaded.`); |
| 52 | + vebalOtcHelper = vebalOtcHelper as VeBalHelper; |
| 53 | + |
| 54 | + for (const address of impersonatedAddresses) { |
| 55 | + impersonatedSigners[address] = await getImpersonatedSigner(address); |
| 56 | + } |
| 57 | + |
| 58 | + otcBuyerAddress = contractAddresses.aaveCompaniesMultisig; |
| 59 | + await forceEth(otcBuyerAddress); |
| 60 | + otcBuyerSigner = await getImpersonatedSigner(otcBuyerAddress); |
| 61 | + }); |
| 62 | + |
| 63 | + it('should be able to create_boost() to boost delegation to another address', async () => { |
| 64 | + await vebalOtcHelper.connect(otcBuyerSigner).create_boost( |
| 65 | + contractAddresses.veBalDelegatorPCVDeposit, // address _delegator |
| 66 | + contractAddresses.eswak, // address _receiver |
| 67 | + '10000', // int256 _percentage |
| 68 | + '1669852800', // uint256 _cancel_time = December 1 2022 |
| 69 | + '1672272000', // uint256 _expire_time = December 29 2022 |
| 70 | + '0' // uint256 _id |
| 71 | + ); |
| 72 | + const expectedMinBoost = '70000000000000000000000'; // should be 77.5k with 18 decimals as of 14/09/2022 |
| 73 | + expect( |
| 74 | + await contracts.balancerVotingEscrowDelegation.delegated_boost(contracts.veBalDelegatorPCVDeposit.address) |
| 75 | + ).to.be.at.least(expectedMinBoost); |
| 76 | + expect(await contracts.balancerVotingEscrowDelegation.received_boost(contractAddresses.eswak)).to.be.at.least( |
| 77 | + expectedMinBoost |
| 78 | + ); |
| 79 | + |
| 80 | + // token id is uint256(delegatorAddress << 96 + boostId), and boostId = 0 |
| 81 | + const tokenId = '0xc4eac760c2c631ee0b064e39888b89158ff808b2000000000000000000000000'; |
| 82 | + expect(await contracts.balancerVotingEscrowDelegation.token_boost(tokenId)).to.be.at.least(expectedMinBoost); |
| 83 | + expect(await contracts.balancerVotingEscrowDelegation.token_expiry(tokenId)).to.equal('1672272000'); |
| 84 | + expect(await contracts.balancerVotingEscrowDelegation.token_cancel_time(tokenId)).to.equal('1669852800'); |
| 85 | + }); |
| 86 | + |
| 87 | + it('should be able to extend_boost', async () => { |
| 88 | + await vebalOtcHelper.connect(otcBuyerSigner).create_boost( |
| 89 | + contractAddresses.veBalDelegatorPCVDeposit, // address _delegator |
| 90 | + contractAddresses.eswak, // address _receiver |
| 91 | + '10000', // int256 _percentage |
| 92 | + '1669852800', // uint256 _cancel_time = December 1 2022 |
| 93 | + '1672272000', // uint256 _expire_time = December 29 2022 |
| 94 | + '0' // uint256 _id |
| 95 | + ); |
| 96 | + const tokenId = '0xc4eac760c2c631ee0b064e39888b89158ff808b2000000000000000000000000'; |
| 97 | + |
| 98 | + await time.increase(86400 * 8); |
| 99 | + const boostedExpireTime = '1674998582'; // uint256 _expire_time = Jan 29 2023 |
| 100 | + // - boostedExpireTime gets rounded down to nearest week |
| 101 | + const boostedCancelTime = '1672694348'; // uint256 _cancel_time = Jan 2 2023 |
| 102 | + |
| 103 | + // Extend the boost |
| 104 | + await vebalOtcHelper.connect(otcBuyerSigner).extend_boost( |
| 105 | + tokenId, |
| 106 | + '10000', // int256 _percentage |
| 107 | + boostedExpireTime, |
| 108 | + boostedCancelTime |
| 109 | + ); |
| 110 | + |
| 111 | + const recordedBoostedExpireTime = await contracts.balancerVotingEscrowDelegation.token_expiry(tokenId); |
| 112 | + |
| 113 | + // Expected boosted expire time rounded down to nearest week |
| 114 | + const WEEK = 86400 * 7; |
| 115 | + const expectedBoostedExpire = Math.floor(Number(boostedExpireTime) / WEEK) * WEEK; |
| 116 | + expect(recordedBoostedExpireTime).to.equal(expectedBoostedExpire); |
| 117 | + expect(await contracts.balancerVotingEscrowDelegation.token_cancel_time(tokenId)).to.equal(boostedCancelTime); |
| 118 | + }); |
| 119 | + |
| 120 | + it('should be able to cancel_boost', async () => { |
| 121 | + await vebalOtcHelper.connect(otcBuyerSigner).create_boost( |
| 122 | + contractAddresses.veBalDelegatorPCVDeposit, // address _delegator |
| 123 | + contractAddresses.eswak, // address _receiver |
| 124 | + '10000', // int256 _percentage |
| 125 | + '1665432310', // uint256 _cancel_time = October 10 2022 |
| 126 | + '1676495110', // uint256 _expire_time = February 15 2023 |
| 127 | + '0' // uint256 _id |
| 128 | + ); |
| 129 | + const tokenId = '0xc4eac760c2c631ee0b064e39888b89158ff808b2000000000000000000000000'; |
| 130 | + expect(await contracts.balancerVotingEscrowDelegation.token_boost(tokenId)).to.be.at.least('1'); // non-zero check |
| 131 | + |
| 132 | + // Cancel boost - fast forward past cancel time |
| 133 | + await time.increase(86400 * 30); |
| 134 | + await vebalOtcHelper.connect(otcBuyerSigner).cancel_boost(tokenId); |
| 135 | + |
| 136 | + const balancerTokenBoost = await contracts.balancerVotingEscrowDelegation.token_boost(tokenId); |
| 137 | + expect(balancerTokenBoost).to.equal(0); |
| 138 | + }); |
| 139 | + |
| 140 | + it('should be able to burn a token', async () => { |
| 141 | + await vebalOtcHelper.connect(otcBuyerSigner).create_boost( |
| 142 | + contractAddresses.veBalDelegatorPCVDeposit, // address _delegator |
| 143 | + contractAddresses.veBalDelegatorPCVDeposit, // address _receiver (becomes owner, only owner can burn) |
| 144 | + '10000', // int256 _percentage |
| 145 | + '1669852800', // uint256 _cancel_time = December 1 2022 |
| 146 | + '1672272000', // uint256 _expire_time = December 29 2022 |
| 147 | + '0' // uint256 _id |
| 148 | + ); |
| 149 | + const tokenId = '0xc4eac760c2c631ee0b064e39888b89158ff808b2000000000000000000000000'; |
| 150 | + // Burn token |
| 151 | + await vebalOtcHelper.connect(otcBuyerSigner).burn(tokenId); |
| 152 | + }); |
| 153 | +}); |
0 commit comments