Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rebalancing warp route extensions #4680

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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);

Check warning on line 18 in solidity/contracts/token/extensions/HypERC20RebalancingCollateral.sol

View check run for this annotation

Codecov / codecov/patch

solidity/contracts/token/extensions/HypERC20RebalancingCollateral.sol#L18

Added line #L18 was not covered by tests
require(
rebalancer.wrappedToken() == wrappedToken,
"Rebalancer collateral must match wrapped token"
);
}

function transferCollateral(
uint32 destination,
uint256 amount
) external payable onlyOwner {
bytes32 router = _mustHaveRemoteRouter(destination);

Check warning on line 29 in solidity/contracts/token/extensions/HypERC20RebalancingCollateral.sol

View check run for this annotation

Codecov / codecov/patch

solidity/contracts/token/extensions/HypERC20RebalancingCollateral.sol#L29

Added line #L29 was not covered by tests
require(wrappedToken.approve(address(rebalancer), amount));
rebalancer.transferRemote{value: msg.value}(

Check warning on line 31 in solidity/contracts/token/extensions/HypERC20RebalancingCollateral.sol

View check run for this annotation

Codecov / codecov/patch

solidity/contracts/token/extensions/HypERC20RebalancingCollateral.sol#L31

Added line #L31 was not covered by tests
destination,
router,
amount
);
}
}
29 changes: 29 additions & 0 deletions solidity/contracts/token/extensions/HypNativeRebalancing.sol
Original file line number Diff line number Diff line change
@@ -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);

Check warning on line 17 in solidity/contracts/token/extensions/HypNativeRebalancing.sol

View check run for this annotation

Codecov / codecov/patch

solidity/contracts/token/extensions/HypNativeRebalancing.sol#L17

Added line #L17 was not covered by tests
}

function transferCollateral(
uint32 destination,
uint256 amount
) external payable onlyOwner {
bytes32 router = _mustHaveRemoteRouter(destination);
uint256 payment = msg.value + amount;

Check warning on line 25 in solidity/contracts/token/extensions/HypNativeRebalancing.sol

View check run for this annotation

Codecov / codecov/patch

solidity/contracts/token/extensions/HypNativeRebalancing.sol#L24-L25

Added lines #L24 - L25 were not covered by tests
require(address(this).balance >= payment, "Insufficient balance");
rebalancer.transferRemote{value: payment}(destination, router, amount);

Check warning on line 27 in solidity/contracts/token/extensions/HypNativeRebalancing.sol

View check run for this annotation

Codecov / codecov/patch

solidity/contracts/token/extensions/HypNativeRebalancing.sol#L27

Added line #L27 was not covered by tests
}
}
Loading