Skip to content

Commit 5672d15

Browse files
committed
Use wrap up to scripts in QuarkBuilder
1 parent 108c525 commit 5672d15

11 files changed

+64
-50
lines changed

src/builder/QuarkBuilderBase.sol

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,15 @@ contract QuarkBuilderBase {
229229
uint256 supplementalBalance = HashMap.contains(assetsBridged, abi.encode(assetSymbolOut))
230230
? HashMap.getUint256(assetsBridged, abi.encode(assetSymbolOut))
231231
: 0;
232+
// Note: Right now, ETH/WETH is only bridged via Across. Across has a weird quirk where it will send ETH to EOAs and
233+
// WETH to contracts. Since the QuarkBuilder cannot know if a QuarkWallet is deployed before the operation is actually
234+
// executed on-chain, it needs to handle the worst case scenario and assume wrapping will be needed.
235+
if (
236+
Strings.stringEqIgnoreCase(assetSymbolOut, "ETH")
237+
|| Strings.stringEqIgnoreCase(assetSymbolOut, "WETH")
238+
) {
239+
supplementalBalance = 0;
240+
}
232241
checkAndInsertWrapOrUnwrapAction({
233242
actions: actions,
234243
quarkOperations: quarkOperations,

src/builder/TokenWrapper.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ library TokenWrapper {
128128
{
129129
if (Strings.stringEqIgnoreCase(tokenSymbol, "ETH")) {
130130
return abi.encodeWithSelector(
131-
WrapperActions.wrapETH.selector, getKnownWrapperTokenPair(chainId, tokenSymbol).wrapper, amount
131+
WrapperActions.wrapETHUpTo.selector, getKnownWrapperTokenPair(chainId, tokenSymbol).wrapper, amount
132132
);
133133
} else if (Strings.stringEqIgnoreCase(tokenSymbol, "stETH")) {
134134
return abi.encodeWithSelector(
@@ -148,7 +148,7 @@ library TokenWrapper {
148148
{
149149
if (Strings.stringEqIgnoreCase(tokenSymbol, "WETH")) {
150150
return abi.encodeWithSelector(
151-
WrapperActions.unwrapWETH.selector, getKnownWrapperTokenPair(chainId, tokenSymbol).wrapper, amount
151+
WrapperActions.unwrapWETHUpTo.selector, getKnownWrapperTokenPair(chainId, tokenSymbol).wrapper, amount
152152
);
153153
} else if (Strings.stringEqIgnoreCase(tokenSymbol, "wstETH")) {
154154
return abi.encodeWithSelector(

test/builder/BridgingLogic.t.sol

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {PaymentInfo} from "src/builder/PaymentInfo.sol";
2323
import {QuarkBuilder} from "src/builder/QuarkBuilder.sol";
2424
import {QuarkBuilderBase} from "src/builder/QuarkBuilderBase.sol";
2525
import {Quotecall} from "src/Quotecall.sol";
26+
import {TokenWrapper} from "src/builder/TokenWrapper.sol";
2627
import {YulHelper} from "test/lib/YulHelper.sol";
2728

2829
import {AcrossFFI} from "test/builder/mocks/AcrossFFI.sol";
@@ -69,6 +70,10 @@ contract BridgingLogicTest is Test, QuarkBuilderTest {
6970

7071
assertEq(result.paymentCurrency, "usd", "usd currency");
7172

73+
address multicallAddress = CodeJarHelper.getCodeAddress(type(Multicall).creationCode);
74+
address wrapperActionsAddress = CodeJarHelper.getCodeAddress(type(WrapperActions).creationCode);
75+
address transferActionsAddress = CodeJarHelper.getCodeAddress(type(TransferActions).creationCode);
76+
7277
// Check the quark operations
7378
assertEq(result.quarkOperations.length, 2, "two operations");
7479
assertEq(
@@ -122,28 +127,21 @@ contract BridgingLogicTest is Test, QuarkBuilderTest {
122127

123128
assertEq(
124129
result.quarkOperations[1].scriptAddress,
125-
address(
126-
uint160(
127-
uint256(
128-
keccak256(
129-
abi.encodePacked(
130-
bytes1(0xff),
131-
/* codeJar address */
132-
address(CodeJarHelper.CODE_JAR_ADDRESS),
133-
uint256(0),
134-
/* script bytecode */
135-
keccak256(type(TransferActions).creationCode)
136-
)
137-
)
138-
)
139-
)
140-
),
141-
"script address for transfer is correct given the code jar address"
130+
multicallAddress,
131+
"script address for Multicall is correct given the code jar address"
132+
);
133+
address[] memory callContracts = new address[](2);
134+
callContracts[0] = wrapperActionsAddress;
135+
callContracts[1] = transferActionsAddress;
136+
bytes[] memory callDatas = new bytes[](2);
137+
callDatas[0] = abi.encodeWithSelector(
138+
WrapperActions.wrapETHUpTo.selector, TokenWrapper.getKnownWrapperTokenPair(8453, "WETH").wrapper, 1e18
142139
);
140+
callDatas[1] = abi.encodeCall(TransferActions.transferERC20Token, (weth_(8453), address(0xceecee), 1e18));
143141
assertEq(
144142
result.quarkOperations[1].scriptCalldata,
145-
abi.encodeCall(TransferActions.transferERC20Token, (weth_(8453), address(0xceecee), 1e18)),
146-
"calldata is TransferActions.transferERC20Token(USDC_8453, address(0xceecee), 5e6);"
143+
abi.encodeWithSelector(Multicall.run.selector, callContracts, callDatas),
144+
"calldata is Multicall.run([wrapperActionsAddress, transferActionsAddress], [WrapperActions.wrapETHUpTo(USDC_8453, 1e18), TransferActions.transferERC20Token(USDC_8453, address(0xceecee), 1e18))"
147145
);
148146
assertEq(
149147
result.quarkOperations[1].expiry, BLOCK_TIMESTAMP + 7 days, "expiry is current blockTimestamp + 7 days"

test/builder/QuarkBuilderCometBorrow.t.sol

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,16 +262,17 @@ contract QuarkBuilderCometBorrowTest is Test, QuarkBuilderTest {
262262
callContracts[0] = wrapperActionsAddress;
263263
callContracts[1] = cometSupplyMultipleAssetsAndBorrowAddress;
264264
bytes[] memory callDatas = new bytes[](2);
265-
callDatas[0] =
266-
abi.encodeWithSelector(WrapperActions.wrapETH.selector, 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2, 1e18);
265+
callDatas[0] = abi.encodeWithSelector(
266+
WrapperActions.wrapETHUpTo.selector, 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2, 1e18
267+
);
267268
callDatas[1] = abi.encodeCall(
268269
CometSupplyMultipleAssetsAndBorrow.run, (cometUsdc_(1), collateralTokens, collateralAmounts, usdc_(1), 1e6)
269270
);
270271

271272
assertEq(
272273
result.quarkOperations[0].scriptCalldata,
273274
abi.encodeWithSelector(Multicall.run.selector, callContracts, callDatas),
274-
"calldata is Multicall.run([wrapperActionsAddress, cometSupplyMultipleAssetsAndBorrowAddress], [WrapperActions.wrapWETH(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2, 10e18), CometSupplyMultipleAssetsAndBorrow.run(COMET_1, collateralTokens, collateralAmounts, usdc_(1), 1e6)"
275+
"calldata is Multicall.run([wrapperActionsAddress, cometSupplyMultipleAssetsAndBorrowAddress], [WrapperActions.wrapETHUpTo(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2, 10e18), CometSupplyMultipleAssetsAndBorrow.run(COMET_1, collateralTokens, collateralAmounts, usdc_(1), 1e6)"
275276
);
276277
assertEq(result.quarkOperations[0].scriptSources.length, 3);
277278
assertEq(result.quarkOperations[0].scriptSources[0], type(WrapperActions).creationCode);

test/builder/QuarkBuilderCometRepay.t.sol

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,9 @@ contract QuarkBuilderCometRepayTest is Test, QuarkBuilderTest {
290290
callContracts[0] = wrapperActionsAddress;
291291
callContracts[1] = cometRepayAndWithdrawMultipleAssetsAddress;
292292
bytes[] memory callDatas = new bytes[](2);
293-
callDatas[0] =
294-
abi.encodeWithSelector(WrapperActions.wrapETH.selector, 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2, 1e18);
293+
callDatas[0] = abi.encodeWithSelector(
294+
WrapperActions.wrapETHUpTo.selector, 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2, 1e18
295+
);
295296
callDatas[1] = abi.encodeCall(
296297
CometRepayAndWithdrawMultipleAssets.run,
297298
(cometWeth_(1), collateralTokens, collateralAmounts, weth_(1), 1e18)
@@ -300,7 +301,7 @@ contract QuarkBuilderCometRepayTest is Test, QuarkBuilderTest {
300301
assertEq(
301302
result.quarkOperations[0].scriptCalldata,
302303
abi.encodeWithSelector(Multicall.run.selector, callContracts, callDatas),
303-
"calldata is Multicall.run([wrapperActionsAddress, cometRepayAndWithdrawMultipleAssetsAddress], [WrapperActions.wrapWETH(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2, 1e18), CometRepayAndWithdrawMultipleAssets.run(COMET_1_WETH, collateralTokens, collateralAmounts, weth_(1), 1e18)"
304+
"calldata is Multicall.run([wrapperActionsAddress, cometRepayAndWithdrawMultipleAssetsAddress], [WrapperActions.wrapETHUpTo(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2, 1e18), CometRepayAndWithdrawMultipleAssets.run(COMET_1_WETH, collateralTokens, collateralAmounts, weth_(1), 1e18)"
304305
);
305306
assertEq(result.quarkOperations[0].scriptSources.length, 3);
306307
assertEq(result.quarkOperations[0].scriptSources[0], type(WrapperActions).creationCode);

test/builder/QuarkBuilderCometSupply.t.sol

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,13 +303,14 @@ contract QuarkBuilderCometSupplyTest is Test, QuarkBuilderTest {
303303
callContracts[0] = wrapperActionsAddress;
304304
callContracts[1] = cometSupplyActionsAddress;
305305
bytes[] memory callDatas = new bytes[](2);
306-
callDatas[0] =
307-
abi.encodeWithSelector(WrapperActions.wrapETH.selector, 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2, 1e18);
306+
callDatas[0] = abi.encodeWithSelector(
307+
WrapperActions.wrapETHUpTo.selector, 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2, 1e18
308+
);
308309
callDatas[1] = abi.encodeCall(CometSupplyActions.supply, (COMET_ETH, weth_(1), 1e18));
309310
assertEq(
310311
result.quarkOperations[0].scriptCalldata,
311312
abi.encodeWithSelector(Multicall.run.selector, callContracts, callDatas),
312-
"calldata is Multicall.run([wrapperActionsAddress, cometSupplyActionsAddress], [WrapperActions.wrapWETH(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2, 1e18), CometSupplyActions.supply(COMET_ETH, weth_(1), 1e18)"
313+
"calldata is Multicall.run([wrapperActionsAddress, cometSupplyActionsAddress], [WrapperActions.wrapETHUpTo(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2, 1e18), CometSupplyActions.supply(COMET_ETH, weth_(1), 1e18)"
313314
);
314315
assertEq(
315316
result.quarkOperations[0].expiry, BLOCK_TIMESTAMP + 7 days, "expiry is current blockTimestamp + 3 days"

test/builder/QuarkBuilderMorphoBorrow.t.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ contract QuarkBuilderMorphoBorrowTest is Test, QuarkBuilderTest {
233233
callContracts[1] = MorphoActionsAddress;
234234
bytes[] memory callDatas = new bytes[](2);
235235
callDatas[0] = abi.encodeWithSelector(
236-
WrapperActions.wrapETH.selector, TokenWrapper.getKnownWrapperTokenPair(8453, "WETH").wrapper, 1e18
236+
WrapperActions.wrapETHUpTo.selector, TokenWrapper.getKnownWrapperTokenPair(8453, "WETH").wrapper, 1e18
237237
);
238238
callDatas[1] = abi.encodeCall(
239239
MorphoActions.supplyCollateralAndBorrow,
@@ -243,7 +243,7 @@ contract QuarkBuilderMorphoBorrowTest is Test, QuarkBuilderTest {
243243
assertEq(
244244
result.quarkOperations[0].scriptCalldata,
245245
abi.encodeWithSelector(Multicall.run.selector, callContracts, callDatas),
246-
"calldata is Multicall.run([wrapperActionsAddress, MorphoActionsAddress], [WrapperActions.wrapWETH(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2, 10e18), MorphoActions.supplyCollateralAndBorrow(MorphoInfo.getMorphoAddress(8453), MorphoInfo.getMarketParams(8453, WETH, USDC), 1e18, 1e6, address(0xa11ce), address(0xa11ce))"
246+
"calldata is Multicall.run([wrapperActionsAddress, MorphoActionsAddress], [WrapperActions.wrapETHUpTo(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2, 10e18), MorphoActions.supplyCollateralAndBorrow(MorphoInfo.getMorphoAddress(8453), MorphoInfo.getMarketParams(8453, WETH, USDC), 1e18, 1e6, address(0xa11ce), address(0xa11ce))"
247247
);
248248
assertEq(result.quarkOperations[0].scriptSources.length, 3);
249249
assertEq(result.quarkOperations[0].scriptSources[0], type(WrapperActions).creationCode);

test/builder/QuarkBuilderMorphoRepay.t.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ contract QuarkBuilderMorphoRepayTest is Test, QuarkBuilderTest {
245245
callContracts[1] = morphoActionsAddress;
246246
bytes[] memory callDatas = new bytes[](2);
247247
callDatas[0] = abi.encodeWithSelector(
248-
WrapperActions.wrapETH.selector, TokenWrapper.getKnownWrapperTokenPair(8453, "WETH").wrapper, 1e18
248+
WrapperActions.wrapETHUpTo.selector, TokenWrapper.getKnownWrapperTokenPair(8453, "WETH").wrapper, 1e18
249249
);
250250
callDatas[1] = abi.encodeCall(
251251
MorphoActions.repayAndWithdrawCollateral,
@@ -255,7 +255,7 @@ contract QuarkBuilderMorphoRepayTest is Test, QuarkBuilderTest {
255255
assertEq(
256256
result.quarkOperations[0].scriptCalldata,
257257
abi.encodeWithSelector(Multicall.run.selector, callContracts, callDatas),
258-
"calldata is Multicall.run([wrapperActionsAddress, morphoActionsAddress], [WrapperActions.wrapWETH(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2, 1e18), MorphoActions.repayAndWithdrawCollateral(MorphoInfo.getMorphoAddress(8453), MorphoInfo.getMarketParams(8453, WETH, USDC), 1e18, 0, 0e18, address(0xa11ce), address(0xa11ce))"
258+
"calldata is Multicall.run([wrapperActionsAddress, morphoActionsAddress], [WrapperActions.wrapETHUpTo(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2, 1e18), MorphoActions.repayAndWithdrawCollateral(MorphoInfo.getMorphoAddress(8453), MorphoInfo.getMarketParams(8453, WETH, USDC), 1e18, 0, 0e18, address(0xa11ce), address(0xa11ce))"
259259
);
260260
assertEq(result.quarkOperations[0].scriptSources.length, 3);
261261
assertEq(result.quarkOperations[0].scriptSources[0], type(WrapperActions).creationCode);

test/builder/QuarkBuilderMorphoVaultSupply.t.sol

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,14 +313,15 @@ contract QuarkBuilderMorphoVaultTest is Test, QuarkBuilderTest {
313313
callContracts[0] = wrapperActionsAddress;
314314
callContracts[1] = morphoVaultActionsAddress;
315315
bytes[] memory callDatas = new bytes[](2);
316-
callDatas[0] =
317-
abi.encodeWithSelector(WrapperActions.wrapETH.selector, 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2, 1e18);
316+
callDatas[0] = abi.encodeWithSelector(
317+
WrapperActions.wrapETHUpTo.selector, 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2, 1e18
318+
);
318319
callDatas[1] =
319320
abi.encodeCall(MorphoVaultActions.deposit, (MorphoInfo.getMorphoVaultAddress(1, "WETH"), weth_(1), 1e18));
320321
assertEq(
321322
result.quarkOperations[0].scriptCalldata,
322323
abi.encodeWithSelector(Multicall.run.selector, callContracts, callDatas),
323-
"calldata is Multicall.run([wrapperActionsAddress, morphoVaultActionsAddress], [WrapperActions.wrapWETH(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2, 1e18), MorphoVaultActions.deposit(MorphoInfo.getMorphoVaultAddress(1, WETH), weth_(1), 1e18)"
324+
"calldata is Multicall.run([wrapperActionsAddress, morphoVaultActionsAddress], [WrapperActions.wrapETHUpTo(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2, 1e18), MorphoVaultActions.deposit(MorphoInfo.getMorphoVaultAddress(1, WETH), weth_(1), 1e18)"
324325
);
325326
assertEq(
326327
result.quarkOperations[0].expiry, BLOCK_TIMESTAMP + 7 days, "expiry is current blockTimestamp + 3 days"

test/builder/QuarkBuilderSwap.t.sol

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,14 +281,15 @@ contract QuarkBuilderSwapTest is Test, QuarkBuilderTest {
281281
callContracts[0] = wrapperActionsAddress;
282282
callContracts[1] = approveAndSwapAddress;
283283
bytes[] memory callDatas = new bytes[](2);
284-
callDatas[0] =
285-
abi.encodeWithSelector(WrapperActions.wrapETH.selector, 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2, 1e18);
284+
callDatas[0] = abi.encodeWithSelector(
285+
WrapperActions.wrapETHUpTo.selector, 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2, 1e18
286+
);
286287
callDatas[1] =
287288
abi.encodeCall(ApproveAndSwap.run, (ZERO_EX_ENTRY_POINT, WETH_1, 1e18, USDC_1, 3000e6, ZERO_EX_SWAP_DATA));
288289
assertEq(
289290
result.quarkOperations[0].scriptCalldata,
290291
abi.encodeWithSelector(Multicall.run.selector, callContracts, callDatas),
291-
"calldata is Multicall.run([wrapperActionsAddress, approveAndSwapAddress], [WrapperActions.wrapWETH(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2, 1e18), ApproveAndSwap.run (ZERO_EX_ENTRY_POINT, WETH_1, 1e18, USDC_1, 3000e6, ZERO_EX_SWAP_DATA)]);"
292+
"calldata is Multicall.run([wrapperActionsAddress, approveAndSwapAddress], [WrapperActions.wrapETHUpTo(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2, 1e18), ApproveAndSwap.run (ZERO_EX_ENTRY_POINT, WETH_1, 1e18, USDC_1, 3000e6, ZERO_EX_SWAP_DATA)]);"
292293
);
293294
assertEq(
294295
result.quarkOperations[0].expiry, BLOCK_TIMESTAMP + 3 days, "expiry is current blockTimestamp + 3 days"

0 commit comments

Comments
 (0)