Skip to content

Commit

Permalink
Merge pull request #165 from bancorprotocol/remove-old-vortex-dependency
Browse files Browse the repository at this point in the history
Remove old vortex dependency
  • Loading branch information
yudilevi authored Sep 25, 2024
2 parents 81b1b35 + e792efa commit 74724a6
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 244 deletions.
18 changes: 2 additions & 16 deletions contracts/vortex/CarbonVortex.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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));
}

Expand All @@ -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
Expand All @@ -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
Expand Down
3 changes: 0 additions & 3 deletions data/named-accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,6 @@ const BancorNamedAccounts = {
vault: {
...getAddress(mainnet, ZERO_ADDRESS),
...getAddress(base, '0xD2b2D272c30d9a0ff3DbaFe848DA7e2f194f697F')
},
oldVortex: {
...getAddress(mainnet, '0xba7d1581Db6248DC9177466a328BF457703c8f84')
}
};

Expand Down
24 changes: 24 additions & 0 deletions deploy/scripts/mainnet/0017-CarbonVortex-upgrade.ts
Original file line number Diff line number Diff line change
@@ -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);
33 changes: 33 additions & 0 deletions deploy/tests/mainnet/0017-carbon-vortex-upgrade.ts
Original file line number Diff line number Diff line change
@@ -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;
});
});
7 changes: 1 addition & 6 deletions deploy/tests/mainnet/carbon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ import { ethers, getNamedAccounts } from 'hardhat';
let carbonVortex: CarbonVortex;

let daoMultisig: SignerWithAddress;
let oldVortex: string;

shouldHaveGap('CarbonController');
shouldHaveGap('Pairs', '_lastPairId');
Expand All @@ -58,7 +57,6 @@ import { ethers, getNamedAccounts } from 'hardhat';

before(async () => {
({ daoMultisig } = await getNamedSigners());
({ oldVortex } = await getNamedAccounts());
});

beforeEach(async () => {
Expand All @@ -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]);
Expand Down
Loading

0 comments on commit 74724a6

Please sign in to comment.