From a13839109c88ae99f65e76da2239c64eb0419a04 Mon Sep 17 00:00:00 2001 From: Yorke Rhodes Date: Mon, 14 Oct 2024 17:02:59 -0400 Subject: [PATCH] Add rebalancing warp route extensions --- .../HypERC20RebalancingCollateral.sol | 37 +++++++++++++++++++ .../token/extensions/HypNativeRebalancing.sol | 29 +++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 solidity/contracts/token/extensions/HypERC20RebalancingCollateral.sol create mode 100644 solidity/contracts/token/extensions/HypNativeRebalancing.sol diff --git a/solidity/contracts/token/extensions/HypERC20RebalancingCollateral.sol b/solidity/contracts/token/extensions/HypERC20RebalancingCollateral.sol new file mode 100644 index 0000000000..50d5b117e6 --- /dev/null +++ b/solidity/contracts/token/extensions/HypERC20RebalancingCollateral.sol @@ -0,0 +1,37 @@ +// SPDX-License-Identifier: Apache-2.0 +pragma solidity >=0.8.0; + +import {HypERC20Collateral} from "../HypERC20Collateral.sol"; + +/** + * @title Hyperlane Rebalancing Token Collateral + * @author Abacus Works + */ +contract HypERC20RebalancingCollateral is HypERC20Collateral { + HypERC20Collateral public immutable rebalancer; + + constructor( + address _erc20, + address _mailbox, + address _rebalancer + ) HypERC20Collateral(_erc20, _mailbox) { + rebalancer = HypERC20Collateral(_rebalancer); + require( + rebalancer.wrappedToken() == wrappedToken, + "Rebalancer collateral must match wrapped token" + ); + } + + function transferCollateral( + uint32 destination, + uint256 amount + ) external payable onlyOwner { + bytes32 router = _mustHaveRemoteRouter(destination); + require(wrappedToken.approve(address(rebalancer), amount)); + rebalancer.transferRemote{value: msg.value}( + destination, + router, + amount + ); + } +} diff --git a/solidity/contracts/token/extensions/HypNativeRebalancing.sol b/solidity/contracts/token/extensions/HypNativeRebalancing.sol new file mode 100644 index 0000000000..f91cc6c770 --- /dev/null +++ b/solidity/contracts/token/extensions/HypNativeRebalancing.sol @@ -0,0 +1,29 @@ +// SPDX-License-Identifier: Apache-2.0 +pragma solidity >=0.8.0; + +import {HypNative} from "../HypNative.sol"; + +/** + * @title Hyperlane Rebalancing Native Collateral + * @author Abacus Works + */ +contract HypERC20RebalancingCollateral is HypNative { + HypNative public immutable rebalancer; + + constructor( + address _mailbox, + address payable _rebalancer + ) HypNative(_mailbox) { + rebalancer = HypNative(_rebalancer); + } + + function transferCollateral( + uint32 destination, + uint256 amount + ) external payable onlyOwner { + bytes32 router = _mustHaveRemoteRouter(destination); + uint256 payment = msg.value + amount; + require(address(this).balance >= payment, "Insufficient balance"); + rebalancer.transferRemote{value: payment}(destination, router, amount); + } +}