Skip to content

Commit

Permalink
TokenBridge: Add ability to withdraw fees to manager's account
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelKim20 committed Aug 12, 2022
1 parent 91b3964 commit e34c650
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions contracts/bridge/TokenBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -431,4 +431,9 @@ contract TokenBridge is ManagerAccessControl {
{
return tokens[_tokenId].liquidBalance[_provider];
}

/// @notice Withdraw transaction fees to the manager's account
function withdrawTxFee() public onlyManager {
payable(msg.sender).transfer(address(this).balance);
}
}
19 changes: 19 additions & 0 deletions test/bridge/TokenBridgeSwap.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,25 @@ describe("Test Swap of TokenBridge", () => {
.openWithdraw(token_id_ethnet, box_id, swap_amount.value, user_eth.address, user_biz.address, lock)
);
});

it("Management the transaction fees", async () => {
const bridge_balance_before_withdraw = await provider.getBalance(bridge_ethnet.address);
assert.strictEqual(bridge_balance_before_withdraw.toString(), txFee.toString());

const manager_balance_before_withdraw = await provider.getBalance(manager.address);
const tx = await bridge_ethnet.connect(manager_signer).withdrawTxFee();
const res = await tx.wait();
const txFeeUsed = res.gasUsed.mul(res.effectiveGasPrice);
const manager_balance_after_withdraw = await provider.getBalance(manager.address);

const bridge_balance_after_withdraw = await provider.getBalance(bridge_ethnet.address);
assert.strictEqual(bridge_balance_after_withdraw.toString(), "0");

assert.strictEqual(
manager_balance_after_withdraw.sub(manager_balance_before_withdraw).add(txFeeUsed).toString(),
txFee.toString()
);
});
});

context("BizNet: User -> Contract, EthNet : Contract -> User", async () => {
Expand Down

0 comments on commit e34c650

Please sign in to comment.