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 #6

Merged
merged 20 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
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
97 changes: 62 additions & 35 deletions src/builder/BridgeRoutes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,61 +9,88 @@ library BridgeRoutes {
CCTP
}

error BridgeNotFound(uint256 srcChainId, uint256 dstChainId, string assetSymbol);

struct Bridge {
// Note: Cannot name these `address` nor `type` because those are both reserved keywords
address bridgeAddress;
uint256 chainId;
address outgoingAddress;
kevincheng96 marked this conversation as resolved.
Show resolved Hide resolved
BridgeType bridgeType;
}

function hasBridge(uint256 srcChainId, uint256 dstChainId, string memory assetSymbol) internal pure returns (bool) {
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);
// TODO: actually consider dstChainId before returning a bridge?
// TODO: resolve assetSymbol to address before trying to bridge?
// TODO: how do we represent the constant information about existing bridges? without mappings, etc.
function getBridge(uint256 srcChainId, uint256 /*dstChainId*/, string memory assetSymbol)
internal
pure
returns (Bridge memory bridge)
{
if (CCTP.canBridge(srcChainId, assetSymbol)) {
bridge = Bridge({
chainId: srcChainId,
outgoingAddress: CCTP.knownOutgoingAddress(srcChainId),
bridgeType: BridgeType.CCTP
});
}
}
}

// NOTE: this library would be generated by a network crawler script.
library CCTP {
// IDEA: input this into codegen, get out knownDomainId and knownOutgoingAddress functions?
struct Roots {
uint256 chainId;
uint256 domainId;
address outgoingAddress;
uint256 estimatedCost;
kevincheng96 marked this conversation as resolved.
Show resolved Hide resolved
}

error NoKnownBridge(uint256 chainId);
error MissingDomainId(uint256 chainId);

function knownDomainId(uint256 chainId) internal pure returns (uint32) {
if (chainId == 1) {
return 0;
} else if (chainId == 8453) {
return 6;
} else {
return Bridge({
bridgeAddress: address(0),
bridgeType: BridgeType.NONE
});
// revert BridgeNotFound(1, dstChainid, assetSymbol);
revert MissingDomainId(chainId);
}
}

function getBridgeForMainnet(uint256 /*dstChainId*/, string memory assetSymbol) internal pure returns (Bridge memory) {
if (Strings.stringEqIgnoreCase(assetSymbol, "USDC")) {
return Bridge({
bridgeAddress: 0xBd3fa81B58Ba92a82136038B25aDec7066af3155,
bridgeType: BridgeType.CCTP
});
function estimatedCost(uint256 chainId) internal pure returns (uint256) {
if (chainId == 1) {
return 1_000_000;
kevincheng96 marked this conversation as resolved.
Show resolved Hide resolved
} else {
return Bridge({
bridgeAddress: address(0),
bridgeType: BridgeType.NONE
});
// revert BridgeNotFound(1, dstChainid, assetSymbol);
// TODO: what's the default? Do we need to revert?
fluffywaffles marked this conversation as resolved.
Show resolved Hide resolved
return 0;
}
}

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

function canBridge(uint256 chainId, string memory assetSymbol) internal pure returns (bool) {
return Strings.stringEqIgnoreCase(assetSymbol, "USDC")
&& knownOutgoingAddress(chainId) != address(0);
}
}
Loading
Loading