Skip to content

Commit

Permalink
separate action context and action type for vault
Browse files Browse the repository at this point in the history
  • Loading branch information
cwang25 committed Sep 3, 2024
1 parent 2ab022c commit 31b32f7
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 30 deletions.
24 changes: 20 additions & 4 deletions src/builder/Actions.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ library Actions {
string constant ACTION_TYPE_REPAY = "REPAY";
string constant ACTION_TYPE_MORPHO_REPAY = "MORPHO_REPAY";
string constant ACTION_TYPE_SUPPLY = "SUPPLY";
string constant ACTION_TYPE_MORPHO_VAULT_SUPPLY = "MORPHO_VAULT_SUPPLY";
string constant ACTION_TYPE_SWAP = "SWAP";
string constant ACTION_TYPE_TRANSFER = "TRANSFER";
string constant ACTION_TYPE_WITHDRAW = "WITHDRAW";
string constant ACTION_TYPE_MORPHO_VAULT_WITHDRAW = "MORPHO_VAULT_WITHDRAW";
string constant ACTION_TYPE_WITHDRAW_AND_BORROW = "WITHDRAW_AND_BORROW";
string constant ACTION_TYPE_WRAP = "WRAP";
string constant ACTION_TYPE_UNWRAP = "UNWRAP";
Expand Down Expand Up @@ -272,6 +274,14 @@ library Actions {
string assetSymbol;
uint256 chainId;
address comet;
uint256 price;
address token;
}

struct MorphoVaultSupplyActionContext {
uint256 amount;
string assetSymbol;
uint256 chainId;
address morphoVault;
uint256 price;
address token;
Expand Down Expand Up @@ -308,6 +318,14 @@ library Actions {
string assetSymbol;
uint256 chainId;
address comet;
uint256 price;
address token;
}

struct MorphoVaultWithdrawActionContext {
uint256 amount;
string assetSymbol;
uint256 chainId;
address morphoVault;
uint256 price;
address token;
Expand Down Expand Up @@ -770,7 +788,6 @@ library Actions {
amount: cometSupply.amount,
chainId: cometSupply.chainId,
comet: cometSupply.comet,
morphoVault: address(0),
price: assetPositions.usdPrice,
token: assetPositions.asset,
assetSymbol: assetPositions.symbol
Expand Down Expand Up @@ -830,7 +847,6 @@ library Actions {
assetSymbol: cometWithdraw.assetSymbol,
chainId: cometWithdraw.chainId,
comet: cometWithdraw.comet,
morphoVault: address(0),
price: assetPositions.usdPrice,
token: assetPositions.asset
});
Expand Down Expand Up @@ -1092,7 +1108,7 @@ library Actions {
Action memory action = Actions.Action({
chainId: vaultSupply.chainId,
quarkAccount: vaultSupply.sender,
actionType: ACTION_TYPE_SUPPLY,
actionType: ACTION_TYPE_MORPHO_VAULT_SUPPLY,
actionContext: abi.encode(vaultSupplyActionContext),
paymentMethod: PaymentInfo.paymentMethodForPayment(payment, useQuotecall),
// Null address for OFFCHAIN payment.
Expand Down Expand Up @@ -1149,7 +1165,7 @@ library Actions {
Action memory action = Actions.Action({
chainId: vaultWithdraw.chainId,
quarkAccount: vaultWithdraw.withdrawer,
actionType: ACTION_TYPE_WITHDRAW,
actionType: ACTION_TYPE_MORPHO_VAULT_WITHDRAW,
actionContext: abi.encode(vaultWithdrawActionContext),
paymentMethod: PaymentInfo.paymentMethodForPayment(payment, false),
// Null address for OFFCHAIN payment.
Expand Down
11 changes: 11 additions & 0 deletions src/builder/QuarkBuilder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1824,6 +1824,13 @@ contract QuarkBuilder {
if (Strings.stringEqIgnoreCase(cometSupplyActionContext.assetSymbol, paymentTokenSymbol)) {
paymentTokenCost += cometSupplyActionContext.amount;
}
} else if (Strings.stringEqIgnoreCase(nonBridgeAction.actionType, Actions.ACTION_TYPE_MORPHO_VAULT_SUPPLY))
{
Actions.MorphoVaultSupplyContext memory morphoVaultSupplyActionContext =
abi.decode(nonBridgeAction.actionContext, (Actions.MorphoVaultSupplyContext));
if (Strings.stringEqIgnoreCase(morphoVaultSupplyActionContext.assetSymbol, paymentTokenSymbol)) {
paymentTokenCost += morphoVaultSupplyActionContext.amount;
}
} else if (Strings.stringEqIgnoreCase(nonBridgeAction.actionType, Actions.ACTION_TYPE_SWAP)) {
Actions.SwapActionContext memory swapActionContext =
abi.decode(nonBridgeAction.actionContext, (Actions.SwapActionContext));
Expand All @@ -1848,6 +1855,10 @@ contract QuarkBuilder {
}
} else if (Strings.stringEqIgnoreCase(nonBridgeAction.actionType, Actions.ACTION_TYPE_WITHDRAW)) {
continue;
} else if (
Strings.stringEqIgnoreCase(nonBridgeAction.actionType, Actions.ACTION_TYPE_MORPHO_VAULT_WITHDRAW)
) {
continue;
} else {
revert InvalidActionType();
}
Expand Down
8 changes: 0 additions & 8 deletions test/builder/QuarkBuilderCometSupply.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ contract QuarkBuilderCometSupplyTest is Test, QuarkBuilderTest {
assetSymbol: "USDC",
chainId: 1,
comet: COMET,
morphoVault: address(0),
price: USDC_PRICE,
token: USDC_1
})
Expand Down Expand Up @@ -219,7 +218,6 @@ contract QuarkBuilderCometSupplyTest is Test, QuarkBuilderTest {
assetSymbol: "USDC",
chainId: 1,
comet: COMET,
morphoVault: address(0),
price: USDC_PRICE,
token: USDC_1
})
Expand Down Expand Up @@ -316,7 +314,6 @@ contract QuarkBuilderCometSupplyTest is Test, QuarkBuilderTest {
assetSymbol: "WETH",
chainId: 1,
comet: COMET_ETH,
morphoVault: address(0),
price: WETH_PRICE,
token: WETH_1
})
Expand Down Expand Up @@ -382,7 +379,6 @@ contract QuarkBuilderCometSupplyTest is Test, QuarkBuilderTest {
assetSymbol: "USDC",
chainId: 1,
comet: COMET,
morphoVault: address(0),
price: USDC_PRICE,
token: USDC_1
})
Expand Down Expand Up @@ -518,7 +514,6 @@ contract QuarkBuilderCometSupplyTest is Test, QuarkBuilderTest {
assetSymbol: "USDC",
chainId: 8453,
comet: COMET,
morphoVault: address(0),
price: USDC_PRICE,
token: USDC_8453
})
Expand Down Expand Up @@ -654,7 +649,6 @@ contract QuarkBuilderCometSupplyTest is Test, QuarkBuilderTest {
assetSymbol: "USDC",
chainId: 8453,
comet: COMET,
morphoVault: address(0),
price: USDC_PRICE,
token: USDC_8453
})
Expand Down Expand Up @@ -776,7 +770,6 @@ contract QuarkBuilderCometSupplyTest is Test, QuarkBuilderTest {
assetSymbol: "USDC",
chainId: 8453,
comet: COMET,
morphoVault: address(0),
price: USDC_PRICE,
token: USDC_8453
})
Expand Down Expand Up @@ -898,7 +891,6 @@ contract QuarkBuilderCometSupplyTest is Test, QuarkBuilderTest {
assetSymbol: "USDC",
chainId: 8453,
comet: COMET,
morphoVault: address(0),
price: USDC_PRICE,
token: USDC_8453
})
Expand Down
5 changes: 0 additions & 5 deletions test/builder/QuarkBuilderCometWithdraw.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ contract QuarkBuilderCometWithdrawTest is Test, QuarkBuilderTest {
assetSymbol: "LINK",
chainId: 1,
comet: cometUsdc_(1),
morphoVault: address(0),
price: LINK_PRICE,
token: link_(1)
})
Expand Down Expand Up @@ -153,7 +152,6 @@ contract QuarkBuilderCometWithdrawTest is Test, QuarkBuilderTest {
assetSymbol: "LINK",
chainId: 1,
comet: cometUsdc_(1),
morphoVault: address(0),
price: LINK_PRICE,
token: link_(1)
})
Expand Down Expand Up @@ -219,7 +217,6 @@ contract QuarkBuilderCometWithdrawTest is Test, QuarkBuilderTest {
assetSymbol: "USDC",
chainId: 1,
comet: cometUsdc_(1),
morphoVault: address(0),
price: USDC_PRICE,
token: usdc_(1)
})
Expand Down Expand Up @@ -370,7 +367,6 @@ contract QuarkBuilderCometWithdrawTest is Test, QuarkBuilderTest {
assetSymbol: "LINK",
chainId: 8453,
comet: cometUsdc_(8453),
morphoVault: address(0),
price: LINK_PRICE,
token: link_(8453)
})
Expand Down Expand Up @@ -460,7 +456,6 @@ contract QuarkBuilderCometWithdrawTest is Test, QuarkBuilderTest {
assetSymbol: "USDC",
chainId: 1,
comet: cometUsdc_(1),
morphoVault: address(0),
price: USDC_PRICE,
token: usdc_(1)
})
Expand Down
16 changes: 8 additions & 8 deletions test/builder/QuarkBuilderMorphoVaultSupply.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ contract QuarkBuilderMorphoVaultTest is Test, QuarkBuilderTest {
assertEq(result.actions.length, 1, "one action");
assertEq(result.actions[0].chainId, 1, "operation is on chainid 1");
assertEq(result.actions[0].quarkAccount, address(0xa11ce), "0xa11ce sends the funds");
assertEq(result.actions[0].actionType, "SUPPLY", "action type is 'SUPPLY'");
assertEq(result.actions[0].actionType, "MORPHO_VAULT_SUPPLY", "action type is 'MORPHO_VAULT_SUPPLY'");
assertEq(result.actions[0].paymentMethod, "OFFCHAIN", "payment method is 'OFFCHAIN'");
assertEq(result.actions[0].paymentToken, address(0), "payment token is null");
assertEq(result.actions[0].paymentMaxCost, 0, "payment has no max cost, since 'OFFCHAIN'");
Expand Down Expand Up @@ -245,7 +245,7 @@ contract QuarkBuilderMorphoVaultTest is Test, QuarkBuilderTest {
assertEq(result.actions.length, 1, "one action");
assertEq(result.actions[0].chainId, 1, "operation is on chainid 1");
assertEq(result.actions[0].quarkAccount, address(0xa11ce), "0xa11ce sends the funds");
assertEq(result.actions[0].actionType, "SUPPLY", "action type is 'SUPPLY'");
assertEq(result.actions[0].actionType, "MORPHO_VAULT_SUPPLY", "action type is 'MORPHO_VAULT_SUPPLY'");
assertEq(result.actions[0].paymentMethod, "OFFCHAIN", "payment method is 'OFFCHAIN'");
assertEq(result.actions[0].paymentToken, address(0), "payment token is null");
assertEq(result.actions[0].paymentMaxCost, 0, "payment has no max cost, since 'OFFCHAIN'");
Expand Down Expand Up @@ -341,7 +341,7 @@ contract QuarkBuilderMorphoVaultTest is Test, QuarkBuilderTest {
assertEq(result.actions.length, 1, "one action");
assertEq(result.actions[0].chainId, 1, "operation is on chainid 1");
assertEq(result.actions[0].quarkAccount, address(0xa11ce), "0xa11ce sends the funds");
assertEq(result.actions[0].actionType, "SUPPLY", "action type is 'SUPPLY'");
assertEq(result.actions[0].actionType, "MORPHO_VAULT_SUPPLY", "action type is 'MORPHO_VAULT_SUPPLY'");
assertEq(result.actions[0].paymentMethod, "OFFCHAIN", "payment method is 'OFFCHAIN'");
assertEq(result.actions[0].paymentToken, address(0), "payment token is null");
assertEq(result.actions[0].paymentMaxCost, 0, "payment has no max cost, since 'OFFCHAIN'");
Expand Down Expand Up @@ -408,7 +408,7 @@ contract QuarkBuilderMorphoVaultTest is Test, QuarkBuilderTest {
assertEq(result.actions.length, 1, "one action");
assertEq(result.actions[0].chainId, 1, "operation is on chainid 1");
assertEq(result.actions[0].quarkAccount, address(0xa11ce), "0xa11ce sends the funds");
assertEq(result.actions[0].actionType, "SUPPLY", "action type is 'SUPPLY'");
assertEq(result.actions[0].actionType, "MORPHO_VAULT_SUPPLY", "action type is 'MORPHO_VAULT_SUPPLY'");
assertEq(result.actions[0].paymentMethod, "PAY_CALL", "payment method is 'PAY_CALL'");
assertEq(result.actions[0].paymentToken, USDC_1, "payment token is USDC");
assertEq(result.actions[0].paymentMaxCost, 0.1e6, "payment max is set to .1e6 in this test case");
Expand Down Expand Up @@ -545,7 +545,7 @@ contract QuarkBuilderMorphoVaultTest is Test, QuarkBuilderTest {
// second action
assertEq(result.actions[1].chainId, 8453, "second action is on chainid 8453");
assertEq(result.actions[1].quarkAccount, address(0xa11ce), "0xa11ce sends the funds");
assertEq(result.actions[1].actionType, "SUPPLY", "action type is 'SUPPLY'");
assertEq(result.actions[1].actionType, "MORPHO_VAULT_SUPPLY", "action type is 'MORPHO_VAULT_SUPPLY'");
assertEq(result.actions[1].paymentMethod, "OFFCHAIN", "payment method is 'OFFCHAIN'");
assertEq(result.actions[1].paymentToken, address(0), "payment token is null");
assertEq(result.actions[1].paymentMaxCost, 0, "payment has no max cost, since 'OFFCHAIN'");
Expand Down Expand Up @@ -682,7 +682,7 @@ contract QuarkBuilderMorphoVaultTest is Test, QuarkBuilderTest {
// second action
assertEq(result.actions[1].chainId, 8453, "second action is on chainid 8453");
assertEq(result.actions[1].quarkAccount, address(0xa11ce), "0xa11ce sends the funds");
assertEq(result.actions[1].actionType, "SUPPLY", "action type is 'SUPPLY'");
assertEq(result.actions[1].actionType, "MORPHO_VAULT_SUPPLY", "action type is 'MORPHO_VAULT_SUPPLY'");
assertEq(result.actions[1].paymentMethod, "OFFCHAIN", "payment method is 'OFFCHAIN'");
assertEq(result.actions[1].paymentToken, address(0), "payment token is null");
assertEq(result.actions[1].paymentMaxCost, 0, "payment has no max cost, since 'OFFCHAIN'");
Expand Down Expand Up @@ -805,7 +805,7 @@ contract QuarkBuilderMorphoVaultTest is Test, QuarkBuilderTest {
// second action
assertEq(result.actions[1].chainId, 8453, "operation is on chainid 8453");
assertEq(result.actions[1].quarkAccount, address(0xa11ce), "0xa11ce sends the funds");
assertEq(result.actions[1].actionType, "SUPPLY", "action type is 'SUPPLY'");
assertEq(result.actions[1].actionType, "MORPHO_VAULT_SUPPLY", "action type is 'MORPHO_VAULT_SUPPLY'");
assertEq(result.actions[1].paymentMethod, "QUOTE_CALL", "payment method is 'QUOTE_CALL'");
assertEq(result.actions[1].paymentToken, USDC_8453, "payment token is USDC on Base");
assertEq(result.actions[1].paymentMaxCost, 0.1e6, "payment should have max cost of 0.1e6");
Expand Down Expand Up @@ -928,7 +928,7 @@ contract QuarkBuilderMorphoVaultTest is Test, QuarkBuilderTest {
// second action
assertEq(result.actions[1].chainId, 8453, "operation is on chainid 8453");
assertEq(result.actions[1].quarkAccount, address(0xa11ce), "0xa11ce sends the funds");
assertEq(result.actions[1].actionType, "SUPPLY", "action type is 'SUPPLY'");
assertEq(result.actions[1].actionType, "MORPHO_VAULT_SUPPLY", "action type is 'MORPHO_VAULT_SUPPLY'");
assertEq(result.actions[1].paymentMethod, "PAY_CALL", "payment method is 'PAY_CALL'");
assertEq(result.actions[1].paymentToken, USDC_8453, "payment token is USDC on Base");
assertEq(result.actions[1].paymentMaxCost, 0.1e6, "payment should have max cost of 0.1e6");
Expand Down
10 changes: 5 additions & 5 deletions test/builder/QuarkBuilderMorphoVaultWithdraw.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ contract QuarkBuilderMorphoVaultWithdrawTest is Test, QuarkBuilderTest {
assertEq(result.actions.length, 1, "one action");
assertEq(result.actions[0].chainId, 1, "operation is on chainId 1");
assertEq(result.actions[0].quarkAccount, address(0xa11ce), "0xa11ce sends the funds");
assertEq(result.actions[0].actionType, "WITHDRAW", "action type is 'WITHDRAW'");
assertEq(result.actions[0].actionType, "MORPHO_VAULT_WITHDRAW", "action type is 'MORPHO_VAULT_WITHDRAW'");
assertEq(result.actions[0].paymentMethod, "OFFCHAIN", "payment method is 'OFFCHAIN'");
assertEq(result.actions[0].paymentToken, address(0), "payment token is null");
assertEq(result.actions[0].paymentMaxCost, 0, "payment has no max cost, since 'OFFCHAIN'");
Expand Down Expand Up @@ -141,7 +141,7 @@ contract QuarkBuilderMorphoVaultWithdrawTest is Test, QuarkBuilderTest {
assertEq(result.actions.length, 1, "one action");
assertEq(result.actions[0].chainId, 1, "operation is on chainid 1");
assertEq(result.actions[0].quarkAccount, address(0xa11ce), "0xa11ce sends the funds");
assertEq(result.actions[0].actionType, "WITHDRAW", "action type is 'WITHDRAW'");
assertEq(result.actions[0].actionType, "MORPHO_VAULT_WITHDRAW", "action type is 'MORPHO_VAULT_WITHDRAW'");
assertEq(result.actions[0].paymentMethod, "PAY_CALL", "payment method is 'PAY_CALL'");
assertEq(result.actions[0].paymentToken, USDC_1, "payment token is USDC");
assertEq(result.actions[0].paymentMaxCost, 0.1e6, "payment max is set to .1e6 in this test case");
Expand Down Expand Up @@ -206,7 +206,7 @@ contract QuarkBuilderMorphoVaultWithdrawTest is Test, QuarkBuilderTest {
assertEq(result.actions.length, 1, "one action");
assertEq(result.actions[0].chainId, 1, "operation is on chainid 1");
assertEq(result.actions[0].quarkAccount, address(0xa11ce), "0xa11ce sends the funds");
assertEq(result.actions[0].actionType, "WITHDRAW", "action type is 'WITHDRAW'");
assertEq(result.actions[0].actionType, "MORPHO_VAULT_WITHDRAW", "action type is 'MORPHO_VAULT_WITHDRAW'");
assertEq(result.actions[0].paymentMethod, "PAY_CALL", "payment method is 'PAY_CALL'");
assertEq(result.actions[0].paymentToken, USDC_1, "payment token is USDC");
assertEq(result.actions[0].paymentMaxCost, 0.5e6, "payment max is set to .5e6 in this test case");
Expand Down Expand Up @@ -356,7 +356,7 @@ contract QuarkBuilderMorphoVaultWithdrawTest is Test, QuarkBuilderTest {
// second action
assertEq(result.actions[1].chainId, 8453, "operation is on chainid 8453");
assertEq(result.actions[1].quarkAccount, address(0xa11ce), "0xa11ce sends the funds");
assertEq(result.actions[1].actionType, "WITHDRAW", "action type is 'WITHDRAW'");
assertEq(result.actions[1].actionType, "MORPHO_VAULT_WITHDRAW", "action type is 'MORPHO_VAULT_WITHDRAW'");
assertEq(result.actions[1].paymentMethod, "PAY_CALL", "payment method is 'PAY_CALL'");
assertEq(result.actions[1].paymentToken, USDC_8453, "payment token is USDC on Base");
assertEq(result.actions[1].paymentMaxCost, 1e6, "payment should have max cost of 1e6");
Expand Down Expand Up @@ -443,7 +443,7 @@ contract QuarkBuilderMorphoVaultWithdrawTest is Test, QuarkBuilderTest {
assertEq(result.actions.length, 1, "one action");
assertEq(result.actions[0].chainId, 1, "operation is on chainId 1");
assertEq(result.actions[0].quarkAccount, address(0xa11ce), "0xa11ce sends the funds");
assertEq(result.actions[0].actionType, "WITHDRAW", "action type is 'WITHDRAW'");
assertEq(result.actions[0].actionType, "MORPHO_VAULT_WITHDRAW", "action type is 'MORPHO_VAULT_WITHDRAW'");
assertEq(result.actions[0].paymentMethod, "PAY_CALL", "payment method is 'PAY_CALL'");
assertEq(result.actions[0].paymentToken, USDC_1, "payment token is USDC");
assertEq(result.actions[0].paymentMaxCost, 0.1e6, "payment max is set to 0.1e6");
Expand Down

0 comments on commit 31b32f7

Please sign in to comment.