BuyBackAndBurn
Collects a share of the bridge fees (currently 15%) which it uses to buy back tokens and burn them

Functions

bridgeSwapToken

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
1
function bridgeSwapToken(uint256 _targetChainId) external whenNotPaused {
2
if (_targetChainId == 56 || _targetChainId == 137) revert InvalidParameter();
3
// create bridge deposit
4
bridgeERC20.depositERC20(burnToken, burnToken.balanceOf(address(this)), address(this), _targetChainId);
5
}
Copied!

Parameters:

Name
Type
Description
_targetChainId
uint256
the ID of the network to which the collected funds should be bridged to

buyBackAndBurnERC20

Swaps all collected fees in the given token into burn tokens using an external DEX and then burns them
1
function buyBackAndBurnERC20(address collectedToken) external whenNotPaused nonReentrant {
2
// trigger deposit of uncollected fees from bridgeERC20
3
bridgeERC20.forwardCollectedFees(IERC20(collectedToken), true, false, false);
4
5
// check how much of the given token is ready for burn
6
uint256 availableBalance = IERC20(collectedToken).balanceOf(address(this));
7
8
// register approval for router to spend collectedToken
9
IERC20(collectedToken).safeIncreaseAllowance(address(router), availableBalance);
10
11
// swap collected tokens to burn tokens using external DEX
12
router.tradeERC20(IERC20(collectedToken), burnToken, availableBalance);
13
14
// burn all available burn tokens (swapped and directly collected))
15
uint256 balanceBurnToken = burnToken.balanceOf(address(this));
16
ERC20Burnable(address(burnToken)).burn(balanceBurnToken);
17
18
// collected tokens successfully swapped and burned => emit event
19
emit BoughtBackAndBurned(collectedToken, availableBalance, address(burnToken), balanceBurnToken);
20
}
21
Copied!

Parameters:

Name
Type
Description
collectedToken
address
contract address of the collected ERC20 tokens that should be swapped and burned (must be an IERC20 contract)

depositERC20

Transfers ERC20 tokens from caller to this smart contract and updates collectedTokenForBurn counter
1
function depositERC20(IERC20 token, uint256 amount) external override whenNotPaused {
2
// transfer the specified amount of given ERC20 tokens from sender to this contract
3
token.safeTransferFrom(_msgSender(), address(this), amount);
4
5
// transfer complete - emit event
6
emit TokensAdded(address(token), amount, IERC20(token).balanceOf(address(this)));
7
}
Copied!

Parameters:

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

swapERC20ToSwapToken

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)
1
function swapERC20ToSwapToken(address collectedToken) external payable whenNotPaused {
2
// trigger deposit of uncollected fees from bridgeERC20
3
bridgeERC20.forwardCollectedFees(IERC20(collectedToken), true, false, false);
4
5
// check how much of the given token is ready to be swapped
6
uint256 amount = IERC20(collectedToken).balanceOf(address(this));
7
8
// register approval for router to spend collectedToken
9
IERC20(collectedToken).safeIncreaseAllowance(address(router), amount);
10
11
// swap collected tokens to collect token using external DEX
12
router.tradeERC20(IERC20(collectedToken), burnToken, amount);
13
}
Copied!

Parameters:

Name
Type
Description
collectedToken
address
contract address of the collected ERC20 tokens that should be swapped and burned (must be an IERC20 contract)