BuyBackAndBurn
Collects a share of the bridge fees (currently 15%) which it uses to buy back tokens and burn them
Initiates a bridge transaction for the swapToken (=burnToken, if contract in SWAP_ONLY mode)
For networks in which the desired burnToken is not available
added in v1.2
function bridgeSwapToken(uint256 _targetChainId) external whenNotPaused {
if (_targetChainId == 56 || _targetChainId == 137) revert InvalidParameter();
// create bridge deposit
bridgeERC20.depositERC20(burnToken, burnToken.balanceOf(address(this)), address(this), _targetChainId);
}
Name | Type | Description |
---|---|---|
_targetChainId | uint256 | the ID of the network to which the collected funds should be bridged to |
Swaps all collected fees in the given token into burn tokens using an external DEX and then burns them
function buyBackAndBurnERC20(address collectedToken) external whenNotPaused nonReentrant {
// trigger deposit of uncollected fees from bridgeERC20
bridgeERC20.forwardCollectedFees(IERC20(collectedToken), true, false, false);
// check how much of the given token is ready for burn
uint256 availableBalance = IERC20(collectedToken).balanceOf(address(this));
// register approval for router to spend collectedToken
IERC20(collectedToken).safeIncreaseAllowance(address(router), availableBalance);
// swap collected tokens to burn tokens using external DEX
router.tradeERC20(IERC20(collectedToken), burnToken, availableBalance);
// burn all available burn tokens (swapped and directly collected))
uint256 balanceBurnToken = burnToken.balanceOf(address(this));
ERC20Burnable(address(burnToken)).burn(balanceBurnToken);
// collected tokens successfully swapped and burned => emit event
emit BoughtBackAndBurned(collectedToken, availableBalance, address(burnToken), balanceBurnToken);
}
Name | Type | Description |
---|---|---|
collectedToken | address | contract address of the collected ERC20 tokens that should be swapped and burned (must be an IERC20 contract) |
Transfers ERC20 tokens from caller to this smart contract and updates collectedTokenForBurn counter
function depositERC20(IERC20 token, uint256 amount) external override whenNotPaused {
// transfer the specified amount of given ERC20 tokens from sender to this contract
token.safeTransferFrom(_msgSender(), address(this), amount);
// transfer complete - emit event
emit TokensAdded(address(token), amount, IERC20(token).balanceOf(address(this)));
}
Name | Type | Description |
---|---|---|
token | IERC20 | contract address of the token to be deposited (must be an IERC20 contract) |
amount | uint256 | the amount of tokens to be deposited |
Swaps entire balance of the given token into swapToken (=burnToken, if contract in SWAP_ONLY mode) which can then be bridged to another network, swapped to actual burnToken and then burned.
For networks in which the desired burnToken is not available.
(added in v1.2)
function swapERC20ToSwapToken(address collectedToken) external payable whenNotPaused {
// trigger deposit of uncollected fees from bridgeERC20
bridgeERC20.forwardCollectedFees(IERC20(collectedToken), true, false, false);
// check how much of the given token is ready to be swapped
uint256 amount = IERC20(collectedToken).balanceOf(address(this));
// register approval for router to spend collectedToken
IERC20(collectedToken).safeIncreaseAllowance(address(router), amount);
// swap collected tokens to collect token using external DEX
router.tradeERC20(IERC20(collectedToken), burnToken, amount);
}
Name | Type | Description |
---|---|---|
collectedToken | address | contract address of the collected ERC20 tokens that should be swapped and burned (must be an IERC20 contract) |
Last modified 1yr ago