Skip to content

Commit 861e453

Browse files
committed
Bridge via Hinting
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.
1 parent 30bb173 commit 861e453

File tree

8 files changed

+1623
-26
lines changed

8 files changed

+1623
-26
lines changed

src/builder/QuarkBuilderBase.sol

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ contract QuarkBuilderBase {
7474
bool useQuotecall;
7575
bool bridgeEnabled;
7676
bool autoWrapperEnabled;
77+
bool preferAcross;
7778
}
7879

7980
/**
@@ -135,7 +136,8 @@ contract QuarkBuilderBase {
135136
dstChainId: actionIntent.chainId,
136137
recipient: actionIntent.actor,
137138
blockTimestamp: actionIntent.blockTimestamp,
138-
useQuotecall: actionIntent.useQuotecall
139+
useQuotecall: actionIntent.useQuotecall,
140+
preferAcross: actionIntent.preferAcross
139141
}),
140142
chainAccountsList,
141143
payment
@@ -193,7 +195,8 @@ contract QuarkBuilderBase {
193195
dstChainId: actionIntent.chainId,
194196
recipient: actionIntent.actor,
195197
blockTimestamp: actionIntent.blockTimestamp,
196-
useQuotecall: actionIntent.useQuotecall
198+
useQuotecall: actionIntent.useQuotecall,
199+
preferAcross: actionIntent.preferAcross
197200
}),
198201
chainAccountsList,
199202
payment

src/builder/actions/Actions.sol

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// SPDX-License-Identifier: BSD-3-Clause
22
pragma solidity ^0.8.27;
33

4+
import {console} from "../console.sol";
5+
46
import {Accounts} from "src/builder/Accounts.sol";
57
import {Across, BridgeRoutes, CCTP} from "src/builder/BridgeRoutes.sol";
68
import {CodeJarHelper} from "src/builder/CodeJarHelper.sol";
@@ -248,6 +250,7 @@ library Actions {
248250
address recipient;
249251
uint256 blockTimestamp;
250252
bool useQuotecall;
253+
bool preferAcross;
251254
}
252255

253256
// Note: To avoid stack too deep errors
@@ -585,7 +588,8 @@ library Actions {
585588
blockTimestamp: bridgeInfo.blockTimestamp
586589
}),
587590
payment,
588-
bridgeInfo.useQuotecall
591+
bridgeInfo.useQuotecall,
592+
bridgeInfo.preferAcross
589593
);
590594

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

608-
function bridgeAsset(BridgeAsset memory bridge, PaymentInfo.Payment memory payment, bool useQuotecall)
609-
internal
610-
pure
611-
returns (IQuarkWallet.QuarkOperation memory, Action memory)
612-
{
613-
if (CCTP.canBridge(bridge.srcChainId, bridge.destinationChainId, bridge.assetSymbol)) {
614-
return bridgeUSDC(bridge, payment, useQuotecall);
615-
} else if (Across.canBridge(bridge.srcChainId, bridge.destinationChainId, bridge.assetSymbol)) {
616-
return bridgeAcross(bridge, payment, useQuotecall);
612+
function bridgeAsset(
613+
BridgeAsset memory bridge,
614+
PaymentInfo.Payment memory payment,
615+
bool useQuotecall,
616+
bool preferAcross
617+
) internal pure returns (IQuarkWallet.QuarkOperation memory, Action memory) {
618+
bool acrossCanBridge = Across.canBridge(bridge.srcChainId, bridge.destinationChainId, bridge.assetSymbol);
619+
bool cctpCanBridge = CCTP.canBridge(bridge.srcChainId, bridge.destinationChainId, bridge.assetSymbol);
620+
621+
// Choose order of actions based on user bridge preference.
622+
if (preferAcross) {
623+
if (acrossCanBridge) {
624+
return bridgeAcross(bridge, payment, useQuotecall);
625+
} else if (cctpCanBridge) {
626+
return bridgeCCTP(bridge, payment, useQuotecall);
627+
}
617628
} else {
618-
revert BridgingUnsupportedForAsset();
629+
if (cctpCanBridge) {
630+
return bridgeCCTP(bridge, payment, useQuotecall);
631+
} else if (acrossCanBridge) {
632+
return bridgeAcross(bridge, payment, useQuotecall);
633+
}
619634
}
635+
636+
revert BridgingUnsupportedForAsset();
620637
}
621638

622-
function bridgeUSDC(BridgeAsset memory bridge, PaymentInfo.Payment memory payment, bool useQuotecall)
639+
function bridgeCCTP(BridgeAsset memory bridge, PaymentInfo.Payment memory payment, bool useQuotecall)
623640
internal
624641
pure
625642
returns (IQuarkWallet.QuarkOperation memory, Action memory)
626643
{
644+
console.log("Bridging via CCTP", bridge.assetSymbol);
645+
627646
if (!Strings.stringEqIgnoreCase(bridge.assetSymbol, "USDC")) {
628647
revert InvalidAssetForBridge();
629648
}
@@ -688,6 +707,8 @@ library Actions {
688707
pure
689708
returns (IQuarkWallet.QuarkOperation memory, Action memory)
690709
{
710+
console.log("Bridging via Across", bridge.assetSymbol);
711+
691712
Accounts.ChainAccounts memory srcChainAccounts =
692713
Accounts.findChainAccounts(bridge.srcChainId, bridge.chainAccountsList);
693714

src/builder/actions/CometActionsBuilder.sol

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ contract CometActionsBuilder is QuarkBuilderBase {
8383
chainId: repayIntent.chainId,
8484
useQuotecall: useQuotecall,
8585
bridgeEnabled: true,
86-
autoWrapperEnabled: true
86+
autoWrapperEnabled: true,
87+
preferAcross: true
8788
});
8889
}
8990

@@ -160,7 +161,8 @@ contract CometActionsBuilder is QuarkBuilderBase {
160161
chainId: borrowIntent.chainId,
161162
useQuotecall: useQuotecall,
162163
bridgeEnabled: true,
163-
autoWrapperEnabled: true
164+
autoWrapperEnabled: true,
165+
preferAcross: true
164166
});
165167
}
166168

@@ -245,7 +247,8 @@ contract CometActionsBuilder is QuarkBuilderBase {
245247
chainId: cometSupplyIntent.chainId,
246248
useQuotecall: isMaxSupply,
247249
bridgeEnabled: true,
248-
autoWrapperEnabled: true
250+
autoWrapperEnabled: true,
251+
preferAcross: true
249252
}),
250253
chainAccountsList: chainAccountsList,
251254
payment: payment,
@@ -330,7 +333,8 @@ contract CometActionsBuilder is QuarkBuilderBase {
330333
chainId: cometWithdrawIntent.chainId,
331334
useQuotecall: useQuotecall,
332335
bridgeEnabled: true,
333-
autoWrapperEnabled: true
336+
autoWrapperEnabled: true,
337+
preferAcross: true
334338
}),
335339
chainAccountsList: chainAccountsList,
336340
payment: payment,

src/builder/actions/MorphoActionsBuilder.sol

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ contract MorphoActionsBuilder is QuarkBuilderBase {
7171
chainId: borrowIntent.chainId,
7272
useQuotecall: useQuotecall,
7373
bridgeEnabled: true,
74-
autoWrapperEnabled: true
74+
autoWrapperEnabled: true,
75+
preferAcross: true
7576
});
7677
}
7778

@@ -163,7 +164,8 @@ contract MorphoActionsBuilder is QuarkBuilderBase {
163164
chainId: repayIntent.chainId,
164165
useQuotecall: useQuotecall,
165166
bridgeEnabled: true,
166-
autoWrapperEnabled: true
167+
autoWrapperEnabled: true,
168+
preferAcross: true
167169
}),
168170
chainAccountsList: chainAccountsList,
169171
payment: payment,
@@ -246,7 +248,8 @@ contract MorphoActionsBuilder is QuarkBuilderBase {
246248
chainId: claimIntent.chainId,
247249
useQuotecall: useQuotecall,
248250
bridgeEnabled: true,
249-
autoWrapperEnabled: true
251+
autoWrapperEnabled: true,
252+
preferAcross: true
250253
});
251254
}
252255

src/builder/actions/MorphoVaultActionsBuilder.sol

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ contract MorphoVaultActionsBuilder is QuarkBuilderBase {
8080
chainId: supplyIntent.chainId,
8181
useQuotecall: useQuotecall,
8282
bridgeEnabled: true,
83-
autoWrapperEnabled: true
83+
autoWrapperEnabled: true,
84+
preferAcross: true
8485
}),
8586
chainAccountsList: chainAccountsList,
8687
payment: payment,
@@ -166,7 +167,8 @@ contract MorphoVaultActionsBuilder is QuarkBuilderBase {
166167
chainId: withdrawIntent.chainId,
167168
useQuotecall: useQuotecall,
168169
bridgeEnabled: true,
169-
autoWrapperEnabled: true
170+
autoWrapperEnabled: true,
171+
preferAcross: true
170172
});
171173
}
172174

src/builder/actions/SwapActionsBuilder.sol

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ contract SwapActionsBuilder is QuarkBuilderBase {
111111
chainId: swapIntent.chainId,
112112
useQuotecall: isMaxSwap,
113113
bridgeEnabled: true,
114-
autoWrapperEnabled: true
114+
autoWrapperEnabled: true,
115+
preferAcross: true
115116
});
116117
}
117118

@@ -205,7 +206,8 @@ contract SwapActionsBuilder is QuarkBuilderBase {
205206
chainId: swapIntent.chainId,
206207
useQuotecall: false,
207208
bridgeEnabled: false,
208-
autoWrapperEnabled: false
209+
autoWrapperEnabled: false,
210+
preferAcross: true
209211
});
210212
}
211213

src/builder/actions/TransferActionsBuilder.sol

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ contract TransferActionsBuilder is QuarkBuilderBase {
8181
chainId: transferIntent.chainId,
8282
useQuotecall: useQuotecall,
8383
bridgeEnabled: true,
84-
autoWrapperEnabled: true
84+
autoWrapperEnabled: true,
85+
preferAcross: true
8586
});
8687
}
8788

0 commit comments

Comments
 (0)