Add rebalancing warp route extensions

rebalance-collateral
Yorke Rhodes 1 month ago
parent 0301055abc
commit a13839109c
No known key found for this signature in database
GPG Key ID: 9EEACF1DA75C5627
  1. 37
      solidity/contracts/token/extensions/HypERC20RebalancingCollateral.sol
  2. 29
      solidity/contracts/token/extensions/HypNativeRebalancing.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
);
}
}

@ -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);
}
}
Loading…
Cancel
Save