|
| 1 | +import hre from 'hardhat'; |
| 2 | +import { expect } from 'chai'; |
| 3 | +import { Contract } from 'ethers'; |
| 4 | +import { bn, fp } from '@helpers/numbers'; |
| 5 | +import { describeForkTest, getForkedNetwork, Task, TaskMode, impersonate, getSigner } from '@src'; |
| 6 | +import { actionId } from '@helpers/models/misc/actions'; |
| 7 | +import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'; |
| 8 | + |
| 9 | +describeForkTest('V3-ProtocolFeeHelper', 'mainnet', 22348940, function () { |
| 10 | + const TASK_NAME = '20250430-v3-protocol-fee-helper'; |
| 11 | + const CONTRACT_NAME = 'ProtocolFeeHelper'; |
| 12 | + |
| 13 | + const GOV_MULTISIG = '0x10A19e7eE7d7F8a52822f6817de8ea18204F2e4f'; |
| 14 | + |
| 15 | + const SWAP_FEE_PERCENTAGE = fp(0.0243); |
| 16 | + const YIELD_FEE_PERCENTAGE = fp(0.0115); |
| 17 | + |
| 18 | + let task: Task; |
| 19 | + let feeHelper: Contract; |
| 20 | + let feeController: Contract; |
| 21 | + let authorizer: Contract; |
| 22 | + let pool: Contract; |
| 23 | + |
| 24 | + let admin: SignerWithAddress; |
| 25 | + let feeSetter: SignerWithAddress; |
| 26 | + |
| 27 | + before('run task', async () => { |
| 28 | + task = new Task(TASK_NAME, TaskMode.TEST, getForkedNetwork(hre)); |
| 29 | + await task.run({ force: true }); |
| 30 | + feeHelper = await task.deployedInstance(CONTRACT_NAME); |
| 31 | + }); |
| 32 | + |
| 33 | + before('load tasks and setup accounts', async () => { |
| 34 | + const feeControllerTask = new Task( |
| 35 | + '20250214-v3-protocol-fee-controller-v2', |
| 36 | + TaskMode.READ_ONLY, |
| 37 | + getForkedNetwork(hre) |
| 38 | + ); |
| 39 | + feeController = await feeControllerTask.deployedInstance('ProtocolFeeController'); |
| 40 | + |
| 41 | + const authorizerTask = new Task('20210418-authorizer', TaskMode.READ_ONLY, getForkedNetwork(hre)); |
| 42 | + authorizer = await authorizerTask.deployedInstance('Authorizer'); |
| 43 | + |
| 44 | + const poolTask = new Task('20241205-v3-weighted-pool', TaskMode.READ_ONLY, getForkedNetwork(hre)); |
| 45 | + pool = await poolTask.instanceAt('WeightedPool', poolTask.output().MockWeightedPool); |
| 46 | + |
| 47 | + admin = await getSigner(0); |
| 48 | + feeSetter = await getSigner(1); |
| 49 | + }); |
| 50 | + |
| 51 | + before('grant permissions', async () => { |
| 52 | + const govMultisig = await impersonate(GOV_MULTISIG, fp(100)); |
| 53 | + |
| 54 | + // Grant the helper permission to set protocol fees. |
| 55 | + await authorizer |
| 56 | + .connect(govMultisig) |
| 57 | + .grantRole(await actionId(feeController, 'setProtocolSwapFeePercentage'), feeHelper.address); |
| 58 | + await authorizer |
| 59 | + .connect(govMultisig) |
| 60 | + .grantRole(await actionId(feeController, 'setProtocolYieldFeePercentage'), feeHelper.address); |
| 61 | + |
| 62 | + // Grant permission to call add and set fees on the helper. |
| 63 | + await authorizer.connect(govMultisig).grantRole(await actionId(feeHelper, 'addPools'), admin.address); |
| 64 | + await authorizer |
| 65 | + .connect(govMultisig) |
| 66 | + .grantRole(await actionId(feeHelper, 'setProtocolSwapFeePercentage'), feeSetter.address); |
| 67 | + await authorizer |
| 68 | + .connect(govMultisig) |
| 69 | + .grantRole(await actionId(feeHelper, 'setProtocolYieldFeePercentage'), feeSetter.address); |
| 70 | + }); |
| 71 | + |
| 72 | + it('can add pools', async () => { |
| 73 | + await feeHelper.connect(admin).addPools([pool.address]); |
| 74 | + |
| 75 | + expect(await feeHelper.getPoolCount()).to.eq(1); |
| 76 | + }); |
| 77 | + |
| 78 | + it('can set fees on pools', async () => { |
| 79 | + await feeHelper.connect(feeSetter).setProtocolSwapFeePercentage(pool.address, SWAP_FEE_PERCENTAGE); |
| 80 | + await feeHelper.connect(feeSetter).setProtocolYieldFeePercentage(pool.address, YIELD_FEE_PERCENTAGE); |
| 81 | + |
| 82 | + // Fees should now be set. |
| 83 | + const [protocolSwapFeePercentage] = await feeController.getPoolProtocolSwapFeeInfo(pool.address); |
| 84 | + const [protocolYieldFeePercentage] = await feeController.getPoolProtocolYieldFeeInfo(pool.address); |
| 85 | + |
| 86 | + expect(bn(protocolSwapFeePercentage)).to.eq(SWAP_FEE_PERCENTAGE); |
| 87 | + expect(bn(protocolYieldFeePercentage)).to.eq(YIELD_FEE_PERCENTAGE); |
| 88 | + }); |
| 89 | +}); |
0 commit comments