diff --git a/contracts/vortex/CarbonVortex.sol b/contracts/vortex/CarbonVortex.sol index 2f70902..01ace37 100644 --- a/contracts/vortex/CarbonVortex.sol +++ b/contracts/vortex/CarbonVortex.sol @@ -39,7 +39,6 @@ contract CarbonVortex is ICarbonVortex, Upgradeable, ReentrancyGuardUpgradeable, // addresses for token withdrawal ICarbonController private immutable _carbonController; - IVault private immutable _oldVortex; IVault private immutable _vault; // address for token collection - collects all swapped target/final target tokens @@ -96,14 +95,12 @@ contract CarbonVortex is ICarbonVortex, Upgradeable, ReentrancyGuardUpgradeable, constructor( ICarbonController carbonController, IVault vault, - IVault oldVortex, address payable transferAddress, Token targetTokenInit, Token finalTargetTokenInit ) validAddress(transferAddress) validAddress(Token.unwrap(targetTokenInit)) { _carbonController = carbonController; _vault = vault; - _oldVortex = oldVortex; _transferAddress = transferAddress; @@ -178,7 +175,7 @@ contract CarbonVortex is ICarbonVortex, Upgradeable, ReentrancyGuardUpgradeable, * @inheritdoc Upgradeable */ function version() public pure override(IVersioned, Upgradeable) returns (uint16) { - return 2; + return 3; } /** @@ -357,9 +354,6 @@ contract CarbonVortex is ICarbonVortex, Upgradeable, ReentrancyGuardUpgradeable, if (address(_vault) != address(0)) { totalFees += token.balanceOf(address(_vault)); } - if (address(_oldVortex) != address(0)) { - totalFees += token.balanceOf(address(_oldVortex)); - } return totalFees + token.balanceOf(address(this)); } @@ -379,9 +373,8 @@ contract CarbonVortex is ICarbonVortex, Upgradeable, ReentrancyGuardUpgradeable, // cache address checks to save gas bool carbonControllerIsNotZero = address(_carbonController) != address(0); bool vaultIsNotZero = address(_vault) != address(0); - bool oldVortexIsNotZero = address(_oldVortex) != address(0); - // withdraw fees from carbon, vault and old vortex + // withdraw fees from carbon vault for (uint256 i = 0; i < len; i = uncheckedInc(i)) { Token token = tokens[i]; // withdraw token fees @@ -396,13 +389,6 @@ contract CarbonVortex is ICarbonVortex, Upgradeable, ReentrancyGuardUpgradeable, _vault.withdrawFunds(token, payable(address(this)), vaultBalance); totalFeeAmount += vaultBalance; } - if (oldVortexIsNotZero) { - // get old vortex token balance - uint256 oldVortexBalance = token.balanceOf(address(_oldVortex)); - // withdraw old vortex token balance - _oldVortex.withdrawFunds(token, payable(address(this)), oldVortexBalance); - totalFeeAmount += oldVortexBalance; - } feeAmounts[i] = totalFeeAmount; // get reward amount for token diff --git a/data/named-accounts.ts b/data/named-accounts.ts index 1ff31eb..5cc6e2b 100644 --- a/data/named-accounts.ts +++ b/data/named-accounts.ts @@ -155,9 +155,6 @@ const BancorNamedAccounts = { vault: { ...getAddress(mainnet, ZERO_ADDRESS), ...getAddress(base, '0xD2b2D272c30d9a0ff3DbaFe848DA7e2f194f697F') - }, - oldVortex: { - ...getAddress(mainnet, '0xba7d1581Db6248DC9177466a328BF457703c8f84') } }; diff --git a/deploy/scripts/mainnet/0017-CarbonVortex-upgrade.ts b/deploy/scripts/mainnet/0017-CarbonVortex-upgrade.ts new file mode 100644 index 0000000..68820cc --- /dev/null +++ b/deploy/scripts/mainnet/0017-CarbonVortex-upgrade.ts @@ -0,0 +1,24 @@ +import { DeployFunction } from 'hardhat-deploy/types'; +import { HardhatRuntimeEnvironment } from 'hardhat/types'; +import { DeployedContracts, upgradeProxy, InstanceName, setDeploymentMetadata } from '../../../utils/Deploy'; +import { NATIVE_TOKEN_ADDRESS } from '../../../utils/Constants'; + +/** + * upgrade carbon vortex 2.0 to v3: + * remove the old vortex dependency + */ +const func: DeployFunction = async ({ getNamedAccounts }: HardhatRuntimeEnvironment) => { + const { deployer, bnt, vault } = await getNamedAccounts(); + const carbonController = await DeployedContracts.CarbonController.deployed(); + + await upgradeProxy({ + name: InstanceName.CarbonVortex, + from: deployer, + args: [carbonController.address, vault, bnt, NATIVE_TOKEN_ADDRESS, bnt], + checkVersion: false + }); + + return true; +}; + +export default setDeploymentMetadata(__filename, func); diff --git a/deploy/tests/mainnet/0017-carbon-vortex-upgrade.ts b/deploy/tests/mainnet/0017-carbon-vortex-upgrade.ts new file mode 100644 index 0000000..8868b5e --- /dev/null +++ b/deploy/tests/mainnet/0017-carbon-vortex-upgrade.ts @@ -0,0 +1,33 @@ +import { CarbonVortex, ProxyAdmin } from '../../../components/Contracts'; +import { DeployedContracts, describeDeployment } from '../../../utils/Deploy'; +import { expect } from 'chai'; +import { ethers } from 'hardhat'; + +describeDeployment(__filename, () => { + let proxyAdmin: ProxyAdmin; + let carbonVortex: CarbonVortex; + + beforeEach(async () => { + proxyAdmin = await DeployedContracts.ProxyAdmin.deployed(); + carbonVortex = await DeployedContracts.CarbonVortex.deployed(); + }); + + it('should deploy and configure the carbon vortex contract', async () => { + expect(await proxyAdmin.getProxyAdmin(carbonVortex.address)).to.equal(proxyAdmin.address); + expect(await carbonVortex.version()).to.equal(3); + }); + + it('carbon vortex implementation should be initialized', async () => { + const implementationAddress = await proxyAdmin.getProxyImplementation(carbonVortex.address); + const carbonControllerImpl: CarbonVortex = await ethers.getContractAt('CarbonVortex', implementationAddress); + // hardcoding gas limit to avoid gas estimation attempts (which get rejected instead of reverted) + const tx = await carbonControllerImpl.initialize({ gasLimit: 6000000 }); + await expect(tx.wait()).to.be.reverted; + }); + + it('cannot call postUpgrade on carbon vortex', async () => { + // hardcoding gas limit to avoid gas estimation attempts (which get rejected instead of reverted) + const tx = await carbonVortex.postUpgrade(true, '0x', { gasLimit: 6000000 }); + await expect(tx.wait()).to.be.reverted; + }); +}); diff --git a/deploy/tests/mainnet/carbon.ts b/deploy/tests/mainnet/carbon.ts index c96f409..4b2560c 100644 --- a/deploy/tests/mainnet/carbon.ts +++ b/deploy/tests/mainnet/carbon.ts @@ -47,7 +47,6 @@ import { ethers, getNamedAccounts } from 'hardhat'; let carbonVortex: CarbonVortex; let daoMultisig: SignerWithAddress; - let oldVortex: string; shouldHaveGap('CarbonController'); shouldHaveGap('Pairs', '_lastPairId'); @@ -58,7 +57,6 @@ import { ethers, getNamedAccounts } from 'hardhat'; before(async () => { ({ daoMultisig } = await getNamedSigners()); - ({ oldVortex } = await getNamedAccounts()); }); beforeEach(async () => { @@ -77,10 +75,7 @@ import { ethers, getNamedAccounts } from 'hardhat'; await expectRoleMembers(carbonVortex, Roles.Upgradeable.ROLE_ADMIN, [daoMultisig.address]); // expect carbon vortex to have fee manager role in Carbon - await expectRoleMembers(carbonController, Roles.CarbonController.ROLE_FEES_MANAGER, [ - oldVortex, - carbonVortex.address - ]); + await expectRoleMembers(carbonController, Roles.CarbonController.ROLE_FEES_MANAGER, [carbonVortex.address]); // expect carbonController to have minter role in voucher await expectRoleMembers(voucher, Roles.Voucher.ROLE_MINTER, [carbonController.address]); diff --git a/test/forge/CarbonVortex.t.sol b/test/forge/CarbonVortex.t.sol index 3f5808f..c5a94ab 100644 --- a/test/forge/CarbonVortex.t.sol +++ b/test/forge/CarbonVortex.t.sol @@ -21,7 +21,6 @@ contract CarbonVortexTest is TestFixture { using Address for address payable; address private vault; - address private oldVortex; address payable private transferAddress; Token private targetToken; @@ -149,8 +148,6 @@ contract CarbonVortexTest is TestFixture { setupCarbonController(); // Deploy Vault vault = deployVault(); - // Deploy Old Vortex - oldVortex = deployVault(); // set up target token targetToken = NATIVE_TOKEN; // set up final target token @@ -158,7 +155,7 @@ contract CarbonVortexTest is TestFixture { // set up transfer address transferAddress = payable(user2); // Deploy Carbon Vortex - deployCarbonVortex(address(carbonController), vault, oldVortex, transferAddress, targetToken, finalTargetToken); + deployCarbonVortex(address(carbonController), vault, transferAddress, targetToken, finalTargetToken); // Transfer tokens to Carbon Controller transferTokensToCarbonController(); // Deploy test case parser @@ -171,24 +168,17 @@ contract CarbonVortexTest is TestFixture { function testShouldRevertWhenDeployingWithInvalidTransferAddress() public { vm.expectRevert(InvalidAddress.selector); - new CarbonVortex(carbonController, IVault(vault), IVault(oldVortex), payable(address(0)), NATIVE_TOKEN, bnt); + new CarbonVortex(carbonController, IVault(vault), payable(address(0)), NATIVE_TOKEN, bnt); } function testShouldRevertWhenDeployingWithInvalidTargetToken() public { vm.expectRevert(InvalidAddress.selector); - new CarbonVortex( - carbonController, - IVault(vault), - IVault(oldVortex), - transferAddress, - Token.wrap(address(0)), - bnt - ); + new CarbonVortex(carbonController, IVault(vault), transferAddress, Token.wrap(address(0)), bnt); } function testShouldBeInitialized() public view { uint16 version = carbonVortex.version(); - assertEq(version, 2); + assertEq(version, 3); } function testShouldntBeAbleToReinitialize() public { @@ -236,12 +226,8 @@ contract CarbonVortexTest is TestFixture { assertEq(balanceAfter - balanceBefore, expectedUserRewards[0]); } - /// @dev test should distribute rewards to caller on execute from vault and old vortex - function testShouldDistributeRewardsToCallerOnExecuteFromVaultAndOldVortex( - uint256 i, - uint256 feesAccumulatedVault, - uint256 feesAccumulatedOldVortex - ) public { + /// @dev test should distribute rewards to caller on execute from vault + function testShouldDistributeRewardsToCallerOnExecuteFromVault(uint256 i, uint256 feesAccumulatedVault) public { vm.startPrank(admin); // token index @@ -252,20 +238,15 @@ contract CarbonVortexTest is TestFixture { Token token = tokens[i]; feesAccumulatedVault = bound(feesAccumulatedVault, 0, MAX_WITHDRAW_AMOUNT); - feesAccumulatedOldVortex = bound(feesAccumulatedOldVortex, 0, MAX_WITHDRAW_AMOUNT); - // transfer tokens to vault and old vortex + // transfer tokens to vault if (token == NATIVE_TOKEN) { vm.deal(address(vault), feesAccumulatedVault); - vm.deal(address(oldVortex), feesAccumulatedOldVortex); } else { token.safeTransfer(address(vault), feesAccumulatedVault); - token.safeTransfer(address(oldVortex), feesAccumulatedOldVortex); } - // check combined token balance of both vault and old vortex + // check token balance of the vault uint256 balanceOfVault = token.balanceOf(address(vault)); - uint256 balanceOfOldVortex = token.balanceOf(address(oldVortex)); - uint256 combinedBalance = balanceOfVault + balanceOfOldVortex; vm.stopPrank(); @@ -278,7 +259,7 @@ contract CarbonVortexTest is TestFixture { Token[] memory tokensArr = new Token[](1); tokensArr[0] = token; // calculate expected rewards - uint256 expectedUserRewards = (combinedBalance * rewards) / PPM_RESOLUTION; + uint256 expectedUserRewards = (balanceOfVault * rewards) / PPM_RESOLUTION; carbonVortex.execute(tokensArr); uint256 balanceAfter = token.balanceOf(user1); @@ -328,42 +309,27 @@ contract CarbonVortexTest is TestFixture { assertEq(balancesAfter[2] - balancesBefore[2], expectedRewards); } - function testShouldDistributeRewardsToCallerOnExecuteFromOldVortexAndVaultForMultipleTokens( - uint256 feesAccumulatedVault, - uint256 feesAccumulatedOldVortex + function testShouldDistributeRewardsToCallerOnExecuteFromVaultForMultipleTokens( + uint256 feesAccumulatedVault ) public { vm.startPrank(admin); feesAccumulatedVault = bound(feesAccumulatedVault, 0, MAX_WITHDRAW_AMOUNT); - feesAccumulatedOldVortex = bound(feesAccumulatedOldVortex, 0, MAX_WITHDRAW_AMOUNT); Token[] memory tokens = new Token[](3); tokens[0] = token1; tokens[1] = token2; tokens[2] = targetToken; - // transfer tokens to vault and old vortex + // transfer tokens to vault tokens[0].safeTransfer(address(vault), feesAccumulatedVault); - tokens[0].safeTransfer(address(oldVortex), feesAccumulatedOldVortex); tokens[1].safeTransfer(address(vault), feesAccumulatedVault); - tokens[1].safeTransfer(address(oldVortex), feesAccumulatedOldVortex); vm.deal(address(vault), feesAccumulatedVault); - vm.deal(address(oldVortex), feesAccumulatedVault); uint256[3] memory balancesOfVault = [ tokens[0].balanceOf(address(vault)), tokens[1].balanceOf(address(vault)), tokens[2].balanceOf(address(vault)) ]; - uint256[3] memory balancesOfOldVortex = [ - tokens[0].balanceOf(address(oldVortex)), - tokens[1].balanceOf(address(oldVortex)), - tokens[2].balanceOf(address(oldVortex)) - ]; - uint256[3] memory combinedBalances = [ - balancesOfVault[0] + balancesOfOldVortex[0], - balancesOfVault[1] + balancesOfOldVortex[1], - balancesOfVault[2] + balancesOfOldVortex[2] - ]; vm.stopPrank(); @@ -380,7 +346,7 @@ contract CarbonVortexTest is TestFixture { // calculate expected rewards uint256[] memory expectedUserRewards = new uint256[](3); for (uint256 i = 0; i < 3; ++i) { - expectedUserRewards[i] = (combinedBalances[i] * rewards) / PPM_RESOLUTION; + expectedUserRewards[i] = (balancesOfVault[i] * rewards) / PPM_RESOLUTION; } // execute @@ -442,7 +408,7 @@ contract CarbonVortexTest is TestFixture { } } - /// @dev test should withdraw fees from CarbonController, Vault and OldVortex on calling execute + /// @dev test should withdraw fees from CarbonController and Vault on calling execute function testShouldWithdrawFeesOnExecute() public { vm.startPrank(admin); uint256[] memory tokenAmounts = new uint256[](4); @@ -459,7 +425,6 @@ contract CarbonVortexTest is TestFixture { for (uint256 i = 0; i < 4; ++i) { carbonController.testSetAccumulatedFees(tokens[i], tokenAmounts[i]); tokens[i].safeTransfer(address(vault), tokenAmounts[i]); - tokens[i].safeTransfer(address(oldVortex), tokenAmounts[i]); vm.expectEmit(); // carbon controller fees event @@ -467,9 +432,6 @@ contract CarbonVortexTest is TestFixture { vm.expectEmit(); // vault fees event emit FundsWithdrawn(tokens[i], address(carbonVortex), address(carbonVortex), tokenAmounts[i]); - vm.expectEmit(); - // old vortex fees event - emit FundsWithdrawn(tokens[i], address(carbonVortex), address(carbonVortex), tokenAmounts[i]); carbonVortex.execute(tokens); } vm.stopPrank(); @@ -478,7 +440,7 @@ contract CarbonVortexTest is TestFixture { /// @dev test that vortex can be deployed with carbon controller set to 0x0 address and it will be skipped on execute function testExecuteShouldSkipCarbonControllerDeployedWithZeroAddress() public { // deploy new vortex with carbon controller set to 0x0 - deployCarbonVortex(address(0), vault, oldVortex, transferAddress, targetToken, finalTargetToken); + deployCarbonVortex(address(0), vault, transferAddress, targetToken, finalTargetToken); vm.startPrank(admin); // test with the target token @@ -488,8 +450,6 @@ contract CarbonVortexTest is TestFixture { // send fees to vault token.safeTransfer(address(vault), accumulatedFees); - // send tokens to old vortex - token.safeTransfer(address(oldVortex), accumulatedFees); vm.stopPrank(); @@ -499,67 +459,16 @@ contract CarbonVortexTest is TestFixture { Token[] memory tokens = new Token[](1); tokens[0] = token; // call execute for the target token - // expect two withdraw emits from vault and old vortex - for (uint256 i = 0; i < 2; ++i) { - vm.expectEmit(); - emit FundsWithdrawn(token, address(carbonVortex), address(carbonVortex), accumulatedFees); - } + // expect one withdraw emit from vault + vm.expectEmit(); + emit FundsWithdrawn(token, address(carbonVortex), address(carbonVortex), accumulatedFees); carbonVortex.execute(tokens); } /// @dev test that vortex can be deployed with vault set to 0x0 address and it will be skipped on execute function testExecuteShouldSkipVaultWithZeroAddress() public { // deploy vortex with a vault with 0x0 address - deployCarbonVortex( - address(carbonController), - address(0), - oldVortex, - transferAddress, - targetToken, - finalTargetToken - ); - - vm.startPrank(admin); - - // test with the target token - Token token = targetToken; - - uint256 accumulatedFees = 100 ether; - - // send fees to old vortex - token.safeTransfer(address(oldVortex), accumulatedFees); - - // accumulate fees in carbon controller - carbonController.testSetAccumulatedFees(token, accumulatedFees); - - vm.stopPrank(); - - vm.startPrank(user1); - - // create token array - Token[] memory tokens = new Token[](1); - tokens[0] = token; - // call execute for the target token - // expect two withdraw emits from carbon controller and old vortex - vm.expectEmit(); - emit FeesWithdrawn(token, address(carbonVortex), accumulatedFees, address(carbonVortex)); - vm.expectEmit(); - emit FundsWithdrawn(token, address(carbonVortex), address(carbonVortex), accumulatedFees); - // execute - carbonVortex.execute(tokens); - } - - /// @dev test that vortex can be deployed with old vortex set to 0x0 address and it will be skipped on execute - function testExecuteShouldSkipOldVortexWithZeroAddress() public { - // deploy vortex with a old vortex with 0x0 address - deployCarbonVortex( - address(carbonController), - vault, - address(0), - transferAddress, - targetToken, - finalTargetToken - ); + deployCarbonVortex(address(carbonController), address(0), transferAddress, targetToken, finalTargetToken); vm.startPrank(admin); @@ -568,9 +477,6 @@ contract CarbonVortexTest is TestFixture { uint256 accumulatedFees = 100 ether; - // send fees to vault - token.safeTransfer(address(vault), accumulatedFees); - // accumulate fees in carbon controller carbonController.testSetAccumulatedFees(token, accumulatedFees); @@ -582,11 +488,9 @@ contract CarbonVortexTest is TestFixture { Token[] memory tokens = new Token[](1); tokens[0] = token; // call execute for the target token - // expect two withdraw emits from carbon controller and old vortex + // expect two withdraw emits from carbon controller vm.expectEmit(); emit FeesWithdrawn(token, address(carbonVortex), accumulatedFees, address(carbonVortex)); - vm.expectEmit(); - emit FundsWithdrawn(token, address(carbonVortex), address(carbonVortex), accumulatedFees); // execute carbonVortex.execute(tokens); } @@ -597,8 +501,8 @@ contract CarbonVortexTest is TestFixture { /// @dev test should properly transfer out fees from the vaults and send fees to the vortex /// @param idx: token index - /// @param feesAccumulated: fees accumulated in the carbon controller, vault and old vortex - function testShouldProperlyTransferAmountsOnExecuteForToken(uint256 idx, uint256[3] memory feesAccumulated) public { + /// @param feesAccumulated: fees accumulated in the carbon controller and vault + function testShouldProperlyTransferAmountsOnExecuteForToken(uint256 idx, uint256[2] memory feesAccumulated) public { vm.startPrank(admin); // token index @@ -609,30 +513,27 @@ contract CarbonVortexTest is TestFixture { Token token = tokens[idx]; // set fee amounts - for (uint256 i = 0; i < 3; ++i) { + for (uint256 i = 0; i < 2; ++i) { feesAccumulated[i] = bound(feesAccumulated[i], 0, MAX_WITHDRAW_AMOUNT); } // set token fees in the carbon controller carbonController.testSetAccumulatedFees(token, feesAccumulated[0]); - // transfer tokens to vault and old vortex + // transfer tokens to vault if (token == NATIVE_TOKEN) { vm.deal(address(vault), feesAccumulated[1]); - vm.deal(address(oldVortex), feesAccumulated[2]); } else { token.safeTransfer(address(vault), feesAccumulated[1]); - token.safeTransfer(address(oldVortex), feesAccumulated[2]); } vm.stopPrank(); vm.startPrank(user1); - uint256[4] memory balancesBefore = [ + uint256[3] memory balancesBefore = [ token.balanceOf(address(carbonController)), token.balanceOf(address(vault)), - token.balanceOf(address(oldVortex)), token.balanceOf(address(carbonVortex)) ]; @@ -640,33 +541,32 @@ contract CarbonVortexTest is TestFixture { tokensArr[0] = token; carbonVortex.execute(tokensArr); - uint256[4] memory balancesAfter = [ + uint256[3] memory balancesAfter = [ token.balanceOf(address(carbonController)), token.balanceOf(address(vault)), - token.balanceOf(address(oldVortex)), token.balanceOf(address(carbonVortex)) ]; - // assert full carbon controller, vault and old vortex fees are withdrawn - for (uint256 i = 0; i < 3; ++i) { + // assert full carbon controller and vault fees are withdrawn + for (uint256 i = 0; i < 2; ++i) { assertEq(balancesBefore[i] - balancesAfter[i], feesAccumulated[i]); } // assert full fees are transferred to the vortex - uint256 totalFeesAccumulated = feesAccumulated[0] + feesAccumulated[1] + feesAccumulated[2]; + uint256 totalFeesAccumulated = feesAccumulated[0] + feesAccumulated[1]; uint256 expectedRewards = (totalFeesAccumulated * carbonVortex.rewardsPPM()) / PPM_RESOLUTION; - assertEq(balancesAfter[3] - balancesBefore[3], totalFeesAccumulated - expectedRewards); + assertEq(balancesAfter[2] - balancesBefore[2], totalFeesAccumulated - expectedRewards); } /// @dev test should properly transfer out fees from the vaults and send fees to the vortex for multiple tokens - function testShouldProperlyTransferAmountsOnExecuteForMultipleTokens(uint256[3] memory feesAccumulated) public { + function testShouldProperlyTransferAmountsOnExecuteForMultipleTokens(uint256[2] memory feesAccumulated) public { vm.startPrank(admin); // test with these 3 tokens Token[3] memory tokens = [token1, token2, targetToken]; // set fee amounts - for (uint256 i = 0; i < 3; ++i) { + for (uint256 i = 0; i < 2; ++i) { feesAccumulated[i] = bound(feesAccumulated[i], 0, MAX_WITHDRAW_AMOUNT); } @@ -675,35 +575,30 @@ contract CarbonVortexTest is TestFixture { carbonController.testSetAccumulatedFees(tokens[i], feesAccumulated[0]); } - // transfer tokens to vault and old vortex + // transfer tokens to vault vm.deal(address(vault), feesAccumulated[1]); - vm.deal(address(oldVortex), feesAccumulated[2]); for (uint256 i = 0; i < 2; ++i) { tokens[i].safeTransfer(address(vault), feesAccumulated[1]); - tokens[i].safeTransfer(address(oldVortex), feesAccumulated[2]); } vm.stopPrank(); vm.startPrank(user1); - uint256[4][3] memory balancesBefore = [ + uint256[3][3] memory balancesBefore = [ [ tokens[0].balanceOf(address(carbonController)), tokens[0].balanceOf(address(vault)), - tokens[0].balanceOf(address(oldVortex)), tokens[0].balanceOf(address(carbonVortex)) ], [ tokens[1].balanceOf(address(carbonController)), tokens[1].balanceOf(address(vault)), - tokens[1].balanceOf(address(oldVortex)), tokens[1].balanceOf(address(carbonVortex)) ], [ tokens[2].balanceOf(address(carbonController)), tokens[2].balanceOf(address(vault)), - tokens[2].balanceOf(address(oldVortex)), tokens[2].balanceOf(address(carbonVortex)) ] ]; @@ -715,53 +610,43 @@ contract CarbonVortexTest is TestFixture { carbonVortex.execute(tokensArr); - uint256[4][3] memory balancesAfter = [ + uint256[3][3] memory balancesAfter = [ [ tokens[0].balanceOf(address(carbonController)), tokens[0].balanceOf(address(vault)), - tokens[0].balanceOf(address(oldVortex)), tokens[0].balanceOf(address(carbonVortex)) ], [ tokens[1].balanceOf(address(carbonController)), tokens[1].balanceOf(address(vault)), - tokens[1].balanceOf(address(oldVortex)), tokens[1].balanceOf(address(carbonVortex)) ], [ tokens[2].balanceOf(address(carbonController)), tokens[2].balanceOf(address(vault)), - tokens[2].balanceOf(address(oldVortex)), tokens[2].balanceOf(address(carbonVortex)) ] ]; - // assert full carbon controller, vault and old vortex fees are withdrawn + // assert full carbon controller and vault fees are withdrawn for (uint256 i = 0; i < 3; ++i) { - for (uint256 j = 0; j < 3; ++j) { + for (uint256 j = 0; j < 2; ++j) { assertEq(balancesBefore[i][j] - balancesAfter[i][j], feesAccumulated[j]); } } // assert full fees are transferred to the vortex - uint256 totalFeesAccumulated = feesAccumulated[0] + feesAccumulated[1] + feesAccumulated[2]; + uint256 totalFeesAccumulated = feesAccumulated[0] + feesAccumulated[1]; uint256 expectedRewards = (totalFeesAccumulated * carbonVortex.rewardsPPM()) / PPM_RESOLUTION; for (uint256 i = 0; i < 3; ++i) { - assertEq(balancesAfter[i][3] - balancesBefore[i][3], totalFeesAccumulated - expectedRewards); + assertEq(balancesAfter[i][2] - balancesBefore[i][2], totalFeesAccumulated - expectedRewards); } } /// @dev test execute shouldnt emit a trade reset event for the target token if the final target token is zero function testShouldTransferTokensDirectlyToTheTransferAddressOnExecuteIfFinalTargetTokenIsZero() public { // Deploy new Carbon Vortex with the final target token set to the zero address - deployCarbonVortex( - address(carbonController), - vault, - oldVortex, - transferAddress, - targetToken, - Token.wrap(address(0)) - ); + deployCarbonVortex(address(carbonController), vault, transferAddress, targetToken, Token.wrap(address(0))); vm.startPrank(admin); @@ -797,14 +682,7 @@ contract CarbonVortexTest is TestFixture { /// @dev test execute should increment total collected on execute for the target token if the final target token is zero function testShouldIncrementTotalCollectedOnExecuteIfFinalTargetTokenAddressIsZero() public { // Deploy new Carbon Vortex with the final target token set to the zero address - deployCarbonVortex( - address(carbonController), - vault, - oldVortex, - transferAddress, - targetToken, - Token.wrap(address(0)) - ); + deployCarbonVortex(address(carbonController), vault, transferAddress, targetToken, Token.wrap(address(0))); vm.startPrank(admin); @@ -1131,14 +1009,7 @@ contract CarbonVortexTest is TestFixture { /// @dev test execute shouldnt emit a trade reset event for the target token if the final target token is zero function testFailShouldntEmitTradeResetForTheTargetTokenIfTheFinalTargetTokenIsZero() public { // Deploy new Carbon Vortex with the final target token set to the zero address - deployCarbonVortex( - address(carbonController), - vault, - oldVortex, - transferAddress, - targetToken, - Token.wrap(address(0)) - ); + deployCarbonVortex(address(carbonController), vault, transferAddress, targetToken, Token.wrap(address(0))); vm.startPrank(admin); @@ -1535,14 +1406,7 @@ contract CarbonVortexTest is TestFixture { public { // Deploy new Carbon Vortex with the final target token set to the zero address - deployCarbonVortex( - address(carbonController), - vault, - oldVortex, - transferAddress, - targetToken, - Token.wrap(address(0)) - ); + deployCarbonVortex(address(carbonController), vault, transferAddress, targetToken, Token.wrap(address(0))); vm.prank(admin); // set fees @@ -1581,7 +1445,7 @@ contract CarbonVortexTest is TestFixture { finalTargetToken = NATIVE_TOKEN; Token token = token1; // Deploy new Carbon Vortex with the target token set to a token different than native token - deployCarbonVortex(address(carbonController), vault, oldVortex, transferAddress, targetToken, finalTargetToken); + deployCarbonVortex(address(carbonController), vault, transferAddress, targetToken, finalTargetToken); vm.prank(admin); // set fees uint256 accumulatedFees = 100 ether; @@ -1640,7 +1504,7 @@ contract CarbonVortexTest is TestFixture { targetToken = bnt; finalTargetToken = NATIVE_TOKEN; // Deploy new Carbon Vortex with the final target token set to the native token - deployCarbonVortex(address(carbonController), vault, oldVortex, transferAddress, targetToken, finalTargetToken); + deployCarbonVortex(address(carbonController), vault, transferAddress, targetToken, finalTargetToken); vm.prank(admin); // set fees uint256 accumulatedFees = 100 ether; @@ -1673,7 +1537,7 @@ contract CarbonVortexTest is TestFixture { targetToken = bnt; finalTargetToken = NATIVE_TOKEN; // Deploy new Carbon Vortex with the final target token set to the native token - deployCarbonVortex(address(carbonController), vault, oldVortex, transferAddress, targetToken, finalTargetToken); + deployCarbonVortex(address(carbonController), vault, transferAddress, targetToken, finalTargetToken); vm.prank(admin); // set fees uint256 accumulatedFees = 100 ether; @@ -1717,7 +1581,7 @@ contract CarbonVortexTest is TestFixture { targetToken = bnt; finalTargetToken = NATIVE_TOKEN; // Deploy new Carbon Vortex with the final target token set to the native token - deployCarbonVortex(address(carbonController), vault, oldVortex, transferAddress, targetToken, finalTargetToken); + deployCarbonVortex(address(carbonController), vault, transferAddress, targetToken, finalTargetToken); vm.prank(admin); // set fees uint256 accumulatedFees = 100 ether; @@ -2237,7 +2101,7 @@ contract CarbonVortexTest is TestFixture { // set fees uint256 accumulatedFees = 100 ether; carbonController.testSetAccumulatedFees(token1, accumulatedFees); - // transfer fees to vault and old vortex + // transfer fees to vortex and vault token1.safeTransfer(address(carbonVortex), accumulatedFees); token1.safeTransfer(address(vault), accumulatedFees); @@ -2253,11 +2117,11 @@ contract CarbonVortexTest is TestFixture { /// @dev test that there isn't an incorrect reading of the 0x0 address balance function testShouldReturnTotalFeesAvailableCorrectlyIfCarbonControllerIsTheZeroAddress() public { // deploy new vortex with carbon controller set to 0x0 - deployCarbonVortex(address(0), vault, oldVortex, transferAddress, targetToken, finalTargetToken); + deployCarbonVortex(address(0), vault, transferAddress, targetToken, finalTargetToken); vm.startPrank(admin); // set fees uint256 accumulatedFees = 100 ether; - // transfer fees to vault and old vortex + // transfer fees to vortex and vault token1.safeTransfer(address(carbonVortex), accumulatedFees); token1.safeTransfer(address(vault), accumulatedFees); @@ -2273,21 +2137,14 @@ contract CarbonVortexTest is TestFixture { /// @dev test that there isn't an incorrect reading of the 0x0 address balance function testShouldReturnTotalFeesAvailableCorrectlyIfTheVaultIsTheZeroAddress() public { // deploy new vortex with the vault set to 0x0 - deployCarbonVortex( - address(carbonController), - address(0), - oldVortex, - transferAddress, - targetToken, - finalTargetToken - ); + deployCarbonVortex(address(carbonController), address(0), transferAddress, targetToken, finalTargetToken); vm.startPrank(admin); // set fees uint256 accumulatedFees = 100 ether; // increment fees in the carbon controller carbonController.testSetAccumulatedFees(token1, accumulatedFees); - // transfer fees to vault and old vortex - token1.safeTransfer(address(oldVortex), accumulatedFees); + // transfer fees to vortex + token1.safeTransfer(address(carbonVortex), accumulatedFees); vm.startPrank(user1); @@ -2298,24 +2155,15 @@ contract CarbonVortexTest is TestFixture { assertEq(totalFees, accumulatedFees * 2); } - /// @dev test that there isn't an incorrect reading of the 0x0 address balance - function testShouldReturnTotalFeesAvailableCorrectlyIfTheOldVortexIsTheZeroAddress() public { - // deploy new vortex with the vault set to 0x0 - deployCarbonVortex( - address(carbonController), - address(vault), - address(0), - transferAddress, - targetToken, - finalTargetToken - ); + /// @dev test that there isn't an incorrect reading of the fees + function testShouldReturnTotalFeesAvailableCorrectly() public { + // deploy new vortex + deployCarbonVortex(address(carbonController), address(vault), transferAddress, targetToken, finalTargetToken); vm.startPrank(admin); // set fees uint256 accumulatedFees = 100 ether; // increment fees in the carbon controller carbonController.testSetAccumulatedFees(token1, accumulatedFees); - // transfer fees to vault and old vortex - token1.safeTransfer(address(oldVortex), accumulatedFees); token1.safeTransfer(address(vault), accumulatedFees); vm.startPrank(user1); diff --git a/test/forge/TestFixture.t.sol b/test/forge/TestFixture.t.sol index 31e81c0..f946a89 100644 --- a/test/forge/TestFixture.t.sol +++ b/test/forge/TestFixture.t.sol @@ -123,7 +123,6 @@ contract TestFixture is Test { function deployCarbonVortex( address _carbonController, address _vault, - address _oldVortex, address _fundReceiver, Token _targetToken, Token _finalTargetToken @@ -135,7 +134,6 @@ contract TestFixture is Test { carbonVortex = new CarbonVortex( ICarbonController(_carbonController), IVault(_vault), - IVault(_oldVortex), payable(_fundReceiver), _targetToken, _finalTargetToken @@ -161,14 +159,6 @@ contract TestFixture is Test { TestVault(payable(_vault)).grantRole(TestVault(payable(_vault)).roleAssetManager(), address(carbonVortex)); } - // grant asset manager role on old vortex to carbon vortex - if (_oldVortex != address(0)) { - TestVault(payable(_oldVortex)).grantRole( - TestVault(payable(_oldVortex)).roleAssetManager(), - address(carbonVortex) - ); - } - vm.stopPrank(); }