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

it compiles #5

Closed
wants to merge 15 commits into from
1 change: 1 addition & 0 deletions .gas-snapshot
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
ApproveAndSwapTest:testSwap() (gas: 285500)
ApproveAndSwapTest:testSwapFailsIfWeExpectedTooMuch() (gas: 364666)
ApproveAndSwapTest:testSwapFailsWithNoApproval() (gas: 122231)
CCTPBridge:testBridgeToBase() (gas: 146874)
CometClaimRewardsTest:testClaimComp() (gas: 131265)
CometRepayAndWithdrawMultipleAssetsTest:testInvalidInput() (gas: 68171)
CometRepayAndWithdrawMultipleAssetsTest:testRepayAndWithdrawMultipleAssets() (gas: 153860)
Expand Down
3 changes: 2 additions & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ evm_version = "paris"

libs = [ "./lib" ]

[profile.ir]
via_ir = true
optimizer = true
optimizer_runs = 100000000

bytecode_hash = "none"
cbor_metadata = false
cbor_metadata = false
18 changes: 18 additions & 0 deletions src/BridgeScripts.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity 0.8.23;

import {IERC20} from "openzeppelin/token/ERC20/IERC20.sol";
import {ITokenMessenger} from "./interfaces/ITokenMessenger.sol";

contract CCTPBridgeActions {
function bridgeUSDC(
address tokenMessenger,
uint256 amount,
uint32 destinationDomain,
bytes32 mintRecipient,
address burnToken
) external {
IERC20(burnToken).approve(tokenMessenger, amount);
ITokenMessenger(tokenMessenger).depositForBurn(amount, destinationDomain, mintRecipient, burnToken);
}
}
69 changes: 69 additions & 0 deletions src/builder/BridgeRoutes.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity ^0.8.23;

import "./Strings.sol";

library BridgeRoutes {
enum BridgeType {
NONE,
CCTP
}

struct Bridge {
// Note: Cannot name these `address` nor `type` because those are both reserved keywords
address bridgeAddress;
BridgeType bridgeType;
}

function hasBridge(uint256 srcChainId, uint256 dstChainId, string memory assetSymbol) internal pure returns (bool) {
if (getBridge(srcChainId, dstChainId, assetSymbol).bridgeType == BridgeType.NONE) {
return false;
} else {
return true;
}
}

function getBridge(uint256 srcChainId, uint256 dstChainId, string memory assetSymbol) internal pure returns (Bridge memory) {
if (srcChainId == 1) {
return getBridgeForMainnet(dstChainId, assetSymbol);
} else if (srcChainId == 8453) {
return getBridgeForBase(dstChainId, assetSymbol);
} else {
return Bridge({
bridgeAddress: address(0),
bridgeType: BridgeType.NONE
});
// revert BridgeNotFound(1, dstChainid, assetSymbol);
}
}

function getBridgeForMainnet(uint256 /*dstChainId*/, string memory assetSymbol) internal pure returns (Bridge memory) {
if (Strings.stringEqIgnoreCase(assetSymbol, "USDC")) {
return Bridge({
bridgeAddress: 0xBd3fa81B58Ba92a82136038B25aDec7066af3155,
bridgeType: BridgeType.CCTP
});
} else {
return Bridge({
bridgeAddress: address(0),
bridgeType: BridgeType.NONE
});
// revert BridgeNotFound(1, dstChainid, assetSymbol);
}
}

function getBridgeForBase(uint256 /*dstChainId*/, string memory assetSymbol) internal pure returns (Bridge memory) {
if (Strings.stringEqIgnoreCase(assetSymbol, "USDC")) {
return Bridge({
bridgeAddress: 0x1682Ae6375C4E4A97e4B583BC394c861A46D8962,
bridgeType: BridgeType.CCTP
});
} else {
return Bridge({
bridgeAddress: address(0),
bridgeType: BridgeType.NONE
});
// revert BridgeNotFound(1, dstChainid, assetSymbol);
}
}
}
Loading
Loading