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

Refactor QuarkBuilder and Bridge routing fix #93

Merged
merged 22 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion src/builder/EIP712Helper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {IQuarkWallet} from "quark-core/src/interfaces/IQuarkWallet.sol";
import {QuarkWalletMetadata} from "quark-core/src/QuarkWallet.sol";

import {Actions} from "src/builder/actions/Actions.sol";
import {Errors} from "./Errors.sol";
import {Errors} from "src/builder/Errors.sol";

library EIP712Helper {
/* ===== Constants ===== */
Expand Down
39 changes: 24 additions & 15 deletions src/builder/QuarkBuilderBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,19 @@ contract QuarkBuilderBase {
error MissingWrapperCounterpart();
error InvalidRepayActionContext();

/**
* @dev Intent for an action to be executed by the Quark Wallet
* @param actor The address of the actor who is initiating the action
* @param amountOuts The amounts of assets to be transferred out from actor's account
* @param assetSymbolOuts The symbols of the assets to be transferred out from actor's account
* @param amountIns The amounts of assets to be transferred in to actor's account
* @param assetSymbolIns The symbols of the assets to be transferred in to actor's account
* @param blockTimestamp The block timestamp at which the action is initiated
* @param chainId The chain ID on which the action is initiated
* @param useQuotecall Whether to use Quotecall for the action
* @param bridgeEnabled Whether to enable bridging for the action
* @param autoWrapperEnabled Whether to enable auto wrapping/unwrapping for the action
*/
struct ActionIntent {
address actor;
uint256[] amountOuts;
Expand Down Expand Up @@ -87,8 +100,8 @@ contract QuarkBuilderBase {
List.DynamicArray memory actions = List.newList();
List.DynamicArray memory quarkOperations = List.newList();

// Flag to check if the assetSymbolOut(used/supplied/transferred out) is the same as the payment token
bool paymentTokenInAssetSymbolOut = false;
// Flag to check if the assetSymbolOut (used/supplied/transferred out) is the same as the payment token
bool paymentTokenIsPartOfAssetSymbolOuts = false;

for (uint256 i = 0; i < actionIntent.assetSymbolOuts.length; ++i) {
assertFundsAvailable(
Expand All @@ -100,7 +113,7 @@ contract QuarkBuilderBase {
);
// Check if the assetSymbolOut is the same as the payment token
if (Strings.stringEqIgnoreCase(actionIntent.assetSymbolOuts[i], payment.currency)) {
paymentTokenInAssetSymbolOut = true;
paymentTokenIsPartOfAssetSymbolOuts = true;
}

if (
Expand Down Expand Up @@ -154,9 +167,11 @@ contract QuarkBuilderBase {
}
}

if (payment.isToken && !paymentTokenInAssetSymbolOut) {
// If payment is token, and is not part of assetSymbolOuts, since if it's part of assetSymbolOuts, it's already handled in above codes
cwang25 marked this conversation as resolved.
Show resolved Hide resolved
if (payment.isToken && !paymentTokenIsPartOfAssetSymbolOuts) {
uint256 maxCostOnDstChain = PaymentInfo.findMaxCost(payment, actionIntent.chainId);

// Account for the assets will be gained through the actions, and reduce the maxCostOnDstChain if can
cwang25 marked this conversation as resolved.
Show resolved Hide resolved
for (uint256 k = 0; k < actionIntent.assetSymbolIns.length; ++k) {
cwang25 marked this conversation as resolved.
Show resolved Hide resolved
if (Strings.stringEqIgnoreCase(actionIntent.assetSymbolIns[k], payment.currency)) {
maxCostOnDstChain = Math.subtractFlooredAtZero(maxCostOnDstChain, actionIntent.amountIns[k]);
Expand Down Expand Up @@ -186,17 +201,11 @@ contract QuarkBuilderBase {
List.addAction(actions, bridgeActions[i]);
}
} else {
if (
needsBridgedFunds(
payment.currency, maxCostOnDstChain, actionIntent.chainId, chainAccountsList, payment
)
) {
revert FundsUnavailable(
payment.currency,
maxCostOnDstChain,
getBalanceOnChain(payment.currency, actionIntent.chainId, chainAccountsList, payment)
);
}
revert FundsUnavailable(
payment.currency,
maxCostOnDstChain,
getBalanceOnChain(payment.currency, actionIntent.chainId, chainAccountsList, payment)
);
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/builder/actions/CometActionsBuilder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ contract CometActionsBuilder is QuarkBuilderBase {
);

QuarkBuilderBase.ActionIntent memory actionIntent;
// Note:scope to avoid stack too deep errors
// Note: Scope to avoid stack too deep errors
{
uint256[] memory amountOuts = new uint256[](1);
amountOuts[0] = repayAmount;
Expand Down Expand Up @@ -144,7 +144,7 @@ contract CometActionsBuilder is QuarkBuilderBase {
);

QuarkBuilderBase.ActionIntent memory actionIntent;
// Note:scope to avoid stack too deep errors
// Note: Scope to avoid stack too deep errors
{
uint256[] memory amountIns = new uint256[](1);
amountIns[0] = borrowIntent.amount;
Expand Down Expand Up @@ -225,7 +225,7 @@ contract CometActionsBuilder is QuarkBuilderBase {

IQuarkWallet.QuarkOperation[] memory quarkOperationsArray;
Actions.Action[] memory actionsArray;
// Note:scope to avoid stack too deep errors
// Note: Scope to avoid stack too deep errors
{
uint256[] memory amountOuts = new uint256[](1);
amountOuts[0] = cometSupplyIntent.amount;
Expand Down Expand Up @@ -310,7 +310,7 @@ contract CometActionsBuilder is QuarkBuilderBase {
);
IQuarkWallet.QuarkOperation[] memory quarkOperationsArray;
Actions.Action[] memory actionsArray;
// Note:scope to avoid stack too deep errors
// Note: Scope to avoid stack too deep errors
{
uint256[] memory amountIns = new uint256[](1);
amountIns[0] = actualWithdrawAmount;
Expand Down
6 changes: 3 additions & 3 deletions src/builder/actions/MorphoActionsBuilder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ contract MorphoActionsBuilder is QuarkBuilderBase {
);

QuarkBuilderBase.ActionIntent memory actionIntent;
// Note:scope to avoid stack too deep errors
// Note: Scope to avoid stack too deep errors
{
uint256[] memory amountOuts = new uint256[](1);
amountOuts[0] = borrowIntent.collateralAmount;
Expand Down Expand Up @@ -141,7 +141,7 @@ contract MorphoActionsBuilder is QuarkBuilderBase {

IQuarkWallet.QuarkOperation[] memory quarkOperationsArray;
Actions.Action[] memory actionsArray;
// Note:scope to avoid stack too deep errors
// Note: Scope to avoid stack too deep errors
{
uint256[] memory amountOuts = new uint256[](1);
amountOuts[0] = repayAmount;
Expand Down Expand Up @@ -227,7 +227,7 @@ contract MorphoActionsBuilder is QuarkBuilderBase {
);

ActionIntent memory actionIntent;
// Note:scope to avoid stack too deep errors
// Note: Scope to avoid stack too deep errors
{
string[] memory assetSymbolIns = new string[](claimIntent.rewards.length);
for (uint256 i = 0; i < claimIntent.rewards.length; ++i) {
Expand Down
4 changes: 2 additions & 2 deletions src/builder/actions/MorphoVaultActionsBuilder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ contract MorphoVaultActionsBuilder is QuarkBuilderBase {

IQuarkWallet.QuarkOperation[] memory quarkOperationsArray;
Actions.Action[] memory actionsArray;
// Note:scope to avoid stack too deep errors
// Note: Scope to avoid stack too deep errors
{
uint256[] memory amountOuts = new uint256[](1);
amountOuts[0] = supplyIntent.amount;
Expand Down Expand Up @@ -148,7 +148,7 @@ contract MorphoVaultActionsBuilder is QuarkBuilderBase {
);

ActionIntent memory actionIntent;
// Note:scope to avoid stack too deep errors
// Note: Scope to avoid stack too deep errors
{
uint256[] memory amountIns = new uint256[](1);
amountIns[0] = actualWithdrawAmount;
Expand Down
4 changes: 2 additions & 2 deletions src/builder/actions/SwapActionsBuilder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ contract SwapActionsBuilder is QuarkBuilderBase {
);

ActionIntent memory actionIntent;
// Note:scope to avoid stack too deep errors
// Note: Scope to avoid stack too deep errors
{
uint256[] memory amountOuts = new uint256[](1);
amountOuts[0] = swapIntent.sellAmount;
Expand Down Expand Up @@ -183,7 +183,7 @@ contract SwapActionsBuilder is QuarkBuilderBase {
);

ActionIntent memory actionIntent;
// Note:scope to avoid stack too deep errors
// Note: Scope to avoid stack too deep errors
{
uint256[] memory amountOuts = new uint256[](1);
amountOuts[0] = swapIntent.sellAmount;
Expand Down
2 changes: 1 addition & 1 deletion src/builder/actions/TransferActionsBuilder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ contract TransferActionsBuilder is QuarkBuilderBase {
);

ActionIntent memory actionIntent;
// Note:scope to avoid stack too deep errors
// Note: Scope to avoid stack too deep errors
{
uint256[] memory amountOuts = new uint256[](1);
amountOuts[0] = transferIntent.amount;
Expand Down
10 changes: 5 additions & 5 deletions test/builder/lib/QuarkBuilderTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -95,27 +95,27 @@ contract QuarkBuilderTest {
function chainAccountsList_(uint256 amount) internal pure returns (Accounts.ChainAccounts[] memory) {
Accounts.ChainAccounts[] memory chainAccountsList = new Accounts.ChainAccounts[](3);

Accounts.QuarkSecret[] memory quarkSecrets = new Accounts.QuarkSecret[](4);
Accounts.QuarkSecret[] memory quarkSecrets = new Accounts.QuarkSecret[](3);
quarkSecrets[0] = quarkSecret_(address(0xa11ce), ALICE_DEFAULT_SECRET);
quarkSecrets[1] = quarkSecret_(address(0xb0b), BOB_DEFAULT_SECRET);
quarkSecrets[2] = quarkSecret_(address(0xc0b), COB_DEFAULT_SECRET);

address[] memory accounts = new address[](4);
address[] memory accounts = new address[](3);
accounts[0] = address(0xa11ce);
accounts[1] = address(0xb0b);
accounts[2] = address(0xc0b);

uint256[] memory amounts_chain_1 = new uint256[](4);
uint256[] memory amounts_chain_1 = new uint256[](3);
amounts_chain_1[0] = uint256(amount / 2);
amounts_chain_1[1] = uint256(0);
amounts_chain_1[2] = uint256(0);

uint256[] memory amounts_chain_8453 = new uint256[](4);
uint256[] memory amounts_chain_8453 = new uint256[](3);
amounts_chain_8453[0] = uint256(0);
amounts_chain_8453[1] = uint256(amount / 2);
amounts_chain_8453[2] = uint256(0);

uint256[] memory amounts_chain_7777 = new uint256[](4);
uint256[] memory amounts_chain_7777 = new uint256[](3);
amounts_chain_7777[0] = uint256(0);
amounts_chain_7777[1] = uint256(0);
amounts_chain_7777[2] = uint256(0);
Expand Down
Loading