Skip to content

Commit

Permalink
Merge pull request #489 from bancorprotocol/burn-network-fees
Browse files Browse the repository at this point in the history
burn network fees
  • Loading branch information
yudilevi authored Oct 26, 2023
2 parents e14a077 + 094af71 commit 8d9b5c5
Show file tree
Hide file tree
Showing 7 changed files with 189 additions and 78 deletions.
79 changes: 49 additions & 30 deletions contracts/network/BancorNetwork.sol
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,6 @@ contract BancorNetwork is IBancorNetwork, Upgradeable, ReentrancyGuardUpgradeabl
// the emergency manager role is required to pause/unpause the network
bytes32 private constant ROLE_EMERGENCY_STOPPER = keccak256("ROLE_EMERGENCY_STOPPER");

// the network fee manager role is required to pull the accumulated pending network fees
bytes32 private constant ROLE_NETWORK_FEE_MANAGER = keccak256("ROLE_NETWORK_FEE_MANAGER");

// the address of the BNT token
IERC20 private immutable _bnt;

Expand Down Expand Up @@ -149,15 +146,18 @@ contract BancorNetwork is IBancorNetwork, Upgradeable, ReentrancyGuardUpgradeabl
// a mapping between pools and their respective pool collections
mapping(Token => IPoolCollection) private _collectionByPool;

// the pending network fee amount to be burned by the vortex
// the pending network fee amount to be burned
uint256 internal _pendingNetworkFeeAmount;

bool private _depositingEnabled = true;

uint32 private _polRewardsPPM;

// min network fee amount that can be burned
uint256 private _minNetworkFeeBurn;

// upgrade forward-compatibility storage gap
uint256[MAX_GAP - 11] private __gap;
uint256[MAX_GAP - 12] private __gap;

/**
* @dev triggered when a new pool collection is added
Expand Down Expand Up @@ -217,9 +217,9 @@ contract BancorNetwork is IBancorNetwork, Upgradeable, ReentrancyGuardUpgradeabl
event FlashLoanCompleted(Token indexed token, address indexed borrower, uint256 amount, uint256 feeAmount);

/**
* @dev triggered when network fees are withdrawn
* @dev triggered when network fees are burned
*/
event NetworkFeesWithdrawn(address indexed caller, address indexed recipient, uint256 amount);
event NetworkFeesBurned(address indexed caller, uint256 amount);

/**
* @dev triggered when pool surplus tokens are withdrawn
Expand All @@ -231,6 +231,11 @@ contract BancorNetwork is IBancorNetwork, Upgradeable, ReentrancyGuardUpgradeabl
*/
event POLRewardsPPMUpdated(uint32 oldRewardsPPM, uint32 newRewardsPPM);

/**
* @dev triggered when the min network fee burn is updated
*/
event MinNetworkFeeBurnUpdated(uint256 oldMinNetworkFeeBurn, uint256 newMinNetworkFeeBurn);

/**
* @dev a "virtual" constructor that is only used to set immutable state variables
*/
Expand Down Expand Up @@ -315,11 +320,11 @@ contract BancorNetwork is IBancorNetwork, Upgradeable, ReentrancyGuardUpgradeabl
// set up administrative roles
_setRoleAdmin(ROLE_MIGRATION_MANAGER, ROLE_ADMIN);
_setRoleAdmin(ROLE_EMERGENCY_STOPPER, ROLE_ADMIN);
_setRoleAdmin(ROLE_NETWORK_FEE_MANAGER, ROLE_ADMIN);

_depositingEnabled = true;

_setPOLRewardsPPM(2000);
_setMinNetworkFeeBurn(1_000_000e18);
}

// solhint-enable func-name-mixedcase
Expand All @@ -342,7 +347,7 @@ contract BancorNetwork is IBancorNetwork, Upgradeable, ReentrancyGuardUpgradeabl
* @inheritdoc Upgradeable
*/
function version() public pure override(IVersioned, Upgradeable) returns (uint16) {
return 9;
return 10;
}

/**
Expand All @@ -360,14 +365,7 @@ contract BancorNetwork is IBancorNetwork, Upgradeable, ReentrancyGuardUpgradeabl
}

/**
* @dev returns the network fee manager role
*/
function roleNetworkFeeManager() external pure returns (bytes32) {
return ROLE_NETWORK_FEE_MANAGER;
}

/**
* @dev returns the pending network fee amount to be burned by the vortex
* @dev returns the pending network fee amount to be burned
*/
function pendingNetworkFeeAmount() external view returns (uint256) {
return _pendingNetworkFeeAmount;
Expand Down Expand Up @@ -820,26 +818,18 @@ contract BancorNetwork is IBancorNetwork, Upgradeable, ReentrancyGuardUpgradeabl
/**
* @inheritdoc IBancorNetwork
*/
function withdrawNetworkFees(
address recipient
)
external
whenNotPaused
onlyRoleMember(ROLE_NETWORK_FEE_MANAGER)
validAddress(recipient)
nonReentrant
returns (uint256)
{
function burnNetworkFees() external whenNotPaused nonReentrant returns (uint256) {
uint256 currentPendingNetworkFeeAmount = _pendingNetworkFeeAmount;
if (currentPendingNetworkFeeAmount == 0) {
if (currentPendingNetworkFeeAmount < _minNetworkFeeBurn) {
return 0;
}

_pendingNetworkFeeAmount = 0;

_masterVault.withdrawFunds(Token(address(_bnt)), payable(recipient), currentPendingNetworkFeeAmount);
// transferring bnt to the token's address burns the tokens
_masterVault.withdrawFunds(Token(address(_bnt)), payable(address(_bnt)), currentPendingNetworkFeeAmount);

emit NetworkFeesWithdrawn(msg.sender, recipient, currentPendingNetworkFeeAmount);
emit NetworkFeesBurned(msg.sender, currentPendingNetworkFeeAmount);

return currentPendingNetworkFeeAmount;
}
Expand Down Expand Up @@ -915,6 +905,35 @@ contract BancorNetwork is IBancorNetwork, Upgradeable, ReentrancyGuardUpgradeabl
emit POLRewardsPPMUpdated(oldRewardsPPM, newRewardsPPM);
}

/**
* @dev returns the min network fee burn
*/
function minNetworkFeeBurn() external view returns (uint256) {
return _minNetworkFeeBurn;
}

/**
* @dev set the min network fee burn
*/
function setMinNetworkFeeBurn(
uint256 newMinNetworkFeeBurn
) external onlyAdmin greaterThanZero(newMinNetworkFeeBurn) {
_setMinNetworkFeeBurn(newMinNetworkFeeBurn);
}

/**
* @dev set the min network fee burn
*/
function _setMinNetworkFeeBurn(uint256 newMinNetworkFeeBurn) private {
uint256 oldMinNetworkFeeBurn = _minNetworkFeeBurn;
if (oldMinNetworkFeeBurn == newMinNetworkFeeBurn) {
return;
}

_minNetworkFeeBurn = newMinNetworkFeeBurn;
emit MinNetworkFeeBurnUpdated(oldMinNetworkFeeBurn, newMinNetworkFeeBurn);
}

/**
* @dev generates context ID for a deposit request
*/
Expand Down
8 changes: 2 additions & 6 deletions contracts/network/interfaces/IBancorNetwork.sol
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,9 @@ interface IBancorNetwork is IUpgradeable {
) external payable;

/**
* @dev withdraws pending network fees, and returns the amount of fees withdrawn
*
* requirements:
*
* - the caller must have the ROLE_NETWORK_FEE_MANAGER privilege
* @dev burns pending network fees, and returns the amount of fees burned
*/
function withdrawNetworkFees(address recipient) external returns (uint256);
function burnNetworkFees() external returns (uint256);

/**
* @dev withdraws surplus tokens from a given pool to CarbonPOL contract,
Expand Down
44 changes: 44 additions & 0 deletions deploy/scripts/000064-upgrade-network-v10.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { DeployedContracts, execute, InstanceName, setDeploymentMetadata, upgradeProxy } from '../../utils/Deploy';
import { toWei } from '../../utils/Types';
import { DeployFunction } from 'hardhat-deploy/types';
import { HardhatRuntimeEnvironment } from 'hardhat/types';

const func: DeployFunction = async ({ getNamedAccounts }: HardhatRuntimeEnvironment) => {
const { deployer, bancorArbitrageAddress, carbonPOLAddress } = await getNamedAccounts();

// get the deployed contracts
const externalProtectionVault = await DeployedContracts.ExternalProtectionVault.deployed();
const masterVault = await DeployedContracts.MasterVault.deployed();
const networkSettings = await DeployedContracts.NetworkSettings.deployed();
const bntGovernance = await DeployedContracts.BNTGovernance.deployed();
const vbntGovernance = await DeployedContracts.VBNTGovernance.deployed();
const bnBNT = await DeployedContracts.bnBNT.deployed();

// upgrade the BancorNetwork contract
await upgradeProxy({
name: InstanceName.BancorNetwork,
args: [
bntGovernance.address,
vbntGovernance.address,
networkSettings.address,
masterVault.address,
externalProtectionVault.address,
bnBNT.address,
bancorArbitrageAddress,
carbonPOLAddress
],
from: deployer
});

// set the min network fee burn to 1M
await execute({
name: InstanceName.BancorNetwork,
methodName: 'setMinNetworkFeeBurn',
args: [toWei(1_000_000)],
from: deployer
});

return true;
};

export default setDeploymentMetadata(__filename, func);
18 changes: 18 additions & 0 deletions deploy/tests/000064-upgrade-network-v10.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { BancorNetwork } from '../../components/Contracts';
import { describeDeployment } from '../../test/helpers/Deploy';
import { DeployedContracts } from '../../utils/Deploy';
import { toWei } from '../../utils/Types';
import { expect } from 'chai';

describeDeployment(__filename, () => {
let network: BancorNetwork;

beforeEach(async () => {
network = await DeployedContracts.BancorNetwork.deployed();
});

it('should upgrade the network contract properly', async () => {
expect(await network.version()).to.equal(10);
expect(await network.minNetworkFeeBurn()).to.equal(toWei(1_000_000));
});
});
1 change: 0 additions & 1 deletion deploy/tests/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ import { getNamedAccounts } from 'hardhat';
await expectRoleMembers(network, Roles.Upgradeable.ROLE_ADMIN, [daoMultisig.address]);
await expectRoleMembers(network, Roles.BancorNetwork.ROLE_MIGRATION_MANAGER, [liquidityProtection.address]);
await expectRoleMembers(network, Roles.BancorNetwork.ROLE_EMERGENCY_STOPPER);
await expectRoleMembers(network, Roles.BancorNetwork.ROLE_NETWORK_FEE_MANAGER, [daoMultisig.address]);

await expectRoleMembers(standardRewards, Roles.Upgradeable.ROLE_ADMIN, [daoMultisig.address]);

Expand Down
Loading

0 comments on commit 8d9b5c5

Please sign in to comment.