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

Standard Bridger #176

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
45 changes: 45 additions & 0 deletions src/legend-scripts/src/LegendScript.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import {QuarkScript} from "quark-core/src/QuarkScript.sol";
import {IComet} from "legend-scripts/src/interfaces/IComet.sol";
import {ICometRewards} from "legend-scripts/src/interfaces/ICometRewards.sol";

import {ITokenMessenger} from "legend-scripts/src/interfaces/ITokenMessenger.sol";
import {IStandardBridge} from "legend-scripts/src/interfaces/IStandardBridge.sol";

library TerminalErrors {
error InvalidInput();
error TransferFailed(bytes data);
Expand Down Expand Up @@ -333,3 +336,45 @@ contract ApproveAndSwap {
IERC20(sellToken).forceApprove(to, 0);
}
}

contract StandardBridger {
IStandardBridge immutable bridge;

constructor(IStandardBridge bridge_) {
bridge = bridge_;
}

/**
* @notice Bridge token over standard bridge.
*/
function bridgeToken(
address localToken,
address remoteToken,
address to,
uint256 amount,
uint32 minGasLimit,
bytes calldata extraData) external {
IERC20(localToken).approve(address(bridge), amount);
bridge.bridgeERC20To(localToken, remoteToken, to, amount, minGasLimit, extraData);
}
}

contract CCTPBridger {
ITokenMessenger immutable bridge;

constructor(ITokenMessenger bridge_) {
bridge = bridge_;
}

/**
* @notice Bridge token over standard bridge.
*/
function bridgeToken(
uint256 amount,
uint32 destinationDomain,
bytes32 mintRecipient,
address burnToken) external {
IERC20(burnToken).approve(address(bridge), amount);
bridge.depositForBurn(amount, destinationDomain, mintRecipient, burnToken);
}
}
13 changes: 13 additions & 0 deletions src/legend-scripts/src/interfaces/IStandardBridge.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity 0.8.23;

interface IStandardBridge {
function bridgeERC20To(
address _localToken,
address _remoteToken,
address _to,
uint256 _amount,
uint32 _minGasLimit,
bytes calldata _extraData
) external;
}
11 changes: 11 additions & 0 deletions src/legend-scripts/src/interfaces/ITokenMessenger.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity 0.8.23;

interface ITokenMessenger {
function depositForBurn(
uint256 amount,
uint32 destinationDomain,
bytes32 mintRecipient,
address burnToken
) external returns (uint64 _nonce);
}
Loading