Skip to content

Commit

Permalink
Bridge via Hinting
Browse files Browse the repository at this point in the history
This patch simply reverses the order s.t. we bridge via Across if possible, then CCTP otherwise. Technically this means we'll never bridge via CCTP, but we'll probably adjust our overall system to allow user-hinting, etc, to retain CCTP support.

Also, we move first-class support for console logs. Note: (a) we'll need to implement console logs in Eth.swift, and (b) we should just update `forge-std` and then use `import {console} from "forge-std/console.sol";` but upgrading forge-std causes stack too deep issues.
  • Loading branch information
hayesgm committed Nov 15, 2024
1 parent 30bb173 commit 861e453
Show file tree
Hide file tree
Showing 8 changed files with 1,623 additions and 26 deletions.
7 changes: 5 additions & 2 deletions src/builder/QuarkBuilderBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ contract QuarkBuilderBase {
bool useQuotecall;
bool bridgeEnabled;
bool autoWrapperEnabled;
bool preferAcross;
}

/**
Expand Down Expand Up @@ -135,7 +136,8 @@ contract QuarkBuilderBase {
dstChainId: actionIntent.chainId,
recipient: actionIntent.actor,
blockTimestamp: actionIntent.blockTimestamp,
useQuotecall: actionIntent.useQuotecall
useQuotecall: actionIntent.useQuotecall,
preferAcross: actionIntent.preferAcross
}),
chainAccountsList,
payment
Expand Down Expand Up @@ -193,7 +195,8 @@ contract QuarkBuilderBase {
dstChainId: actionIntent.chainId,
recipient: actionIntent.actor,
blockTimestamp: actionIntent.blockTimestamp,
useQuotecall: actionIntent.useQuotecall
useQuotecall: actionIntent.useQuotecall,
preferAcross: actionIntent.preferAcross
}),
chainAccountsList,
payment
Expand Down
45 changes: 33 additions & 12 deletions src/builder/actions/Actions.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity ^0.8.27;

import {console} from "../console.sol";

import {Accounts} from "src/builder/Accounts.sol";
import {Across, BridgeRoutes, CCTP} from "src/builder/BridgeRoutes.sol";
import {CodeJarHelper} from "src/builder/CodeJarHelper.sol";
Expand Down Expand Up @@ -248,6 +250,7 @@ library Actions {
address recipient;
uint256 blockTimestamp;
bool useQuotecall;
bool preferAcross;
}

// Note: To avoid stack too deep errors
Expand Down Expand Up @@ -585,7 +588,8 @@ library Actions {
blockTimestamp: bridgeInfo.blockTimestamp
}),
payment,
bridgeInfo.useQuotecall
bridgeInfo.useQuotecall,
bridgeInfo.preferAcross
);

List.addAction(actions, action);
Expand All @@ -605,25 +609,40 @@ library Actions {
return (List.toQuarkOperationArray(quarkOperations), List.toActionArray(actions));
}

function bridgeAsset(BridgeAsset memory bridge, PaymentInfo.Payment memory payment, bool useQuotecall)
internal
pure
returns (IQuarkWallet.QuarkOperation memory, Action memory)
{
if (CCTP.canBridge(bridge.srcChainId, bridge.destinationChainId, bridge.assetSymbol)) {
return bridgeUSDC(bridge, payment, useQuotecall);
} else if (Across.canBridge(bridge.srcChainId, bridge.destinationChainId, bridge.assetSymbol)) {
return bridgeAcross(bridge, payment, useQuotecall);
function bridgeAsset(
BridgeAsset memory bridge,
PaymentInfo.Payment memory payment,
bool useQuotecall,
bool preferAcross
) internal pure returns (IQuarkWallet.QuarkOperation memory, Action memory) {
bool acrossCanBridge = Across.canBridge(bridge.srcChainId, bridge.destinationChainId, bridge.assetSymbol);
bool cctpCanBridge = CCTP.canBridge(bridge.srcChainId, bridge.destinationChainId, bridge.assetSymbol);

// Choose order of actions based on user bridge preference.
if (preferAcross) {
if (acrossCanBridge) {
return bridgeAcross(bridge, payment, useQuotecall);
} else if (cctpCanBridge) {
return bridgeCCTP(bridge, payment, useQuotecall);
}
} else {
revert BridgingUnsupportedForAsset();
if (cctpCanBridge) {
return bridgeCCTP(bridge, payment, useQuotecall);
} else if (acrossCanBridge) {
return bridgeAcross(bridge, payment, useQuotecall);
}
}

revert BridgingUnsupportedForAsset();
}

function bridgeUSDC(BridgeAsset memory bridge, PaymentInfo.Payment memory payment, bool useQuotecall)
function bridgeCCTP(BridgeAsset memory bridge, PaymentInfo.Payment memory payment, bool useQuotecall)
internal
pure
returns (IQuarkWallet.QuarkOperation memory, Action memory)
{
console.log("Bridging via CCTP", bridge.assetSymbol);

if (!Strings.stringEqIgnoreCase(bridge.assetSymbol, "USDC")) {
revert InvalidAssetForBridge();
}
Expand Down Expand Up @@ -688,6 +707,8 @@ library Actions {
pure
returns (IQuarkWallet.QuarkOperation memory, Action memory)
{
console.log("Bridging via Across", bridge.assetSymbol);

Accounts.ChainAccounts memory srcChainAccounts =
Accounts.findChainAccounts(bridge.srcChainId, bridge.chainAccountsList);

Expand Down
12 changes: 8 additions & 4 deletions src/builder/actions/CometActionsBuilder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ contract CometActionsBuilder is QuarkBuilderBase {
chainId: repayIntent.chainId,
useQuotecall: useQuotecall,
bridgeEnabled: true,
autoWrapperEnabled: true
autoWrapperEnabled: true,
preferAcross: true
});
}

Expand Down Expand Up @@ -160,7 +161,8 @@ contract CometActionsBuilder is QuarkBuilderBase {
chainId: borrowIntent.chainId,
useQuotecall: useQuotecall,
bridgeEnabled: true,
autoWrapperEnabled: true
autoWrapperEnabled: true,
preferAcross: true
});
}

Expand Down Expand Up @@ -245,7 +247,8 @@ contract CometActionsBuilder is QuarkBuilderBase {
chainId: cometSupplyIntent.chainId,
useQuotecall: isMaxSupply,
bridgeEnabled: true,
autoWrapperEnabled: true
autoWrapperEnabled: true,
preferAcross: true
}),
chainAccountsList: chainAccountsList,
payment: payment,
Expand Down Expand Up @@ -330,7 +333,8 @@ contract CometActionsBuilder is QuarkBuilderBase {
chainId: cometWithdrawIntent.chainId,
useQuotecall: useQuotecall,
bridgeEnabled: true,
autoWrapperEnabled: true
autoWrapperEnabled: true,
preferAcross: true
}),
chainAccountsList: chainAccountsList,
payment: payment,
Expand Down
9 changes: 6 additions & 3 deletions src/builder/actions/MorphoActionsBuilder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ contract MorphoActionsBuilder is QuarkBuilderBase {
chainId: borrowIntent.chainId,
useQuotecall: useQuotecall,
bridgeEnabled: true,
autoWrapperEnabled: true
autoWrapperEnabled: true,
preferAcross: true
});
}

Expand Down Expand Up @@ -163,7 +164,8 @@ contract MorphoActionsBuilder is QuarkBuilderBase {
chainId: repayIntent.chainId,
useQuotecall: useQuotecall,
bridgeEnabled: true,
autoWrapperEnabled: true
autoWrapperEnabled: true,
preferAcross: true
}),
chainAccountsList: chainAccountsList,
payment: payment,
Expand Down Expand Up @@ -246,7 +248,8 @@ contract MorphoActionsBuilder is QuarkBuilderBase {
chainId: claimIntent.chainId,
useQuotecall: useQuotecall,
bridgeEnabled: true,
autoWrapperEnabled: true
autoWrapperEnabled: true,
preferAcross: true
});
}

Expand Down
6 changes: 4 additions & 2 deletions src/builder/actions/MorphoVaultActionsBuilder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ contract MorphoVaultActionsBuilder is QuarkBuilderBase {
chainId: supplyIntent.chainId,
useQuotecall: useQuotecall,
bridgeEnabled: true,
autoWrapperEnabled: true
autoWrapperEnabled: true,
preferAcross: true
}),
chainAccountsList: chainAccountsList,
payment: payment,
Expand Down Expand Up @@ -166,7 +167,8 @@ contract MorphoVaultActionsBuilder is QuarkBuilderBase {
chainId: withdrawIntent.chainId,
useQuotecall: useQuotecall,
bridgeEnabled: true,
autoWrapperEnabled: true
autoWrapperEnabled: true,
preferAcross: true
});
}

Expand Down
6 changes: 4 additions & 2 deletions src/builder/actions/SwapActionsBuilder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ contract SwapActionsBuilder is QuarkBuilderBase {
chainId: swapIntent.chainId,
useQuotecall: isMaxSwap,
bridgeEnabled: true,
autoWrapperEnabled: true
autoWrapperEnabled: true,
preferAcross: true
});
}

Expand Down Expand Up @@ -205,7 +206,8 @@ contract SwapActionsBuilder is QuarkBuilderBase {
chainId: swapIntent.chainId,
useQuotecall: false,
bridgeEnabled: false,
autoWrapperEnabled: false
autoWrapperEnabled: false,
preferAcross: true
});
}

Expand Down
3 changes: 2 additions & 1 deletion src/builder/actions/TransferActionsBuilder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ contract TransferActionsBuilder is QuarkBuilderBase {
chainId: transferIntent.chainId,
useQuotecall: useQuotecall,
bridgeEnabled: true,
autoWrapperEnabled: true
autoWrapperEnabled: true,
preferAcross: true
});
}

Expand Down
Loading

0 comments on commit 861e453

Please sign in to comment.