Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
b04f11e
Initial commit
kevincheng96 Jun 5, 2024
8d8b1c0
Implement validation for Builder
kevincheng96 Jun 6, 2024
6427949
Move bridge routing logic into separate library
kevincheng96 Jun 6, 2024
a94b132
Actually push BridgeRoutes
kevincheng96 Jun 6, 2024
0c4ef34
Create Strings library, create PaymentMaxCost struct, rename some fun…
kevincheng96 Jun 6, 2024
822843f
Small PR suggestions
kevincheng96 Jun 6, 2024
649a734
bugfix: found some missing semicolons, fixed some compiler errors (#4)
fluffywaffles Jun 7, 2024
2b775f9
bugfix: compiles (without viaIR)
fluffywaffles Jun 6, 2024
1f9c2db
infra: do not default to ir
fluffywaffles Jun 6, 2024
bdec9f5
refactor: mostly fixed ERC20Transfer operation builder
fluffywaffles Jun 6, 2024
e069dbe
chore: forge fmt
fluffywaffles Jun 6, 2024
beb1b1d
minor: do not rely on ChainAccounts having only one AssetPositions
fluffywaffles Jun 6, 2024
f9072b8
well, stack too deep. but close.
fluffywaffles Jun 6, 2024
19ad822
who knows
fluffywaffles Jun 7, 2024
1ca0ce4
stack attack
fluffywaffles Jun 7, 2024
825c079
refactor: no more silly filtering
fluffywaffles Jun 7, 2024
421f2c5
refactor: address some PR feedback
fluffywaffles Jun 7, 2024
9087095
refactor/minor: bridgeAddress
fluffywaffles Jun 7, 2024
df61498
refactor: clean up the bridge routes library
fluffywaffles Jun 7, 2024
729d665
some tests
fluffywaffles Jun 7, 2024
11836e6
test: add a case for a transfer that should succeed
fluffywaffles Jun 7, 2024
aa8818b
refactor: organize types and helpers into libraries
fluffywaffles Jun 7, 2024
8e0d413
refactor: actually organize the sub-libraries into modules
fluffywaffles Jun 7, 2024
82a2592
minor: commentary
fluffywaffles Jun 7, 2024
114528a
wrap paycall
Jun 11, 2024
ff9f616
pure test
Jun 12, 2024
9495e4a
Merge remote-tracking branch 'origin/main' into hans/paycall
Jun 12, 2024
b53cc63
make test pass
Jun 12, 2024
6e61da3
fmt
Jun 12, 2024
c5fc5d9
fmt descrepency between forge versions
Jun 12, 2024
8f92f68
lint..
Jun 12, 2024
d1f4341
update on assert failure message
Jun 12, 2024
be936f7
address comment to keep all scriptSources in the list
Jun 12, 2024
5623b3c
remove dup transfer
Jun 12, 2024
ccbf274
Merge remote-tracking branch 'origin/main' into hans/paycall
Jun 12, 2024
62af6b0
paymenttoken with hard-coded info for finding address for paycall
Jun 13, 2024
65b8ad0
add token symbol input into PaymentTokens.sol
Jun 13, 2024
739f8bf
remove extra line after loop
Jun 13, 2024
2877fe7
changed to tokenSymbol
Jun 13, 2024
f68d1cc
oops lint failing cuz tokenSymbol is long enought to go to next line
Jun 13, 2024
64b02e1
replace some //wrap paycall blocks
Jun 13, 2024
0d879b9
add one test for wrapper
Jun 13, 2024
d47544e
update wrap call for symbol
Jun 13, 2024
9df9709
Merge remote-tracking branch 'origin/main' into hans/paycall-in-builder
Jun 13, 2024
046ce0a
Merge remote-tracking branch 'origin/main' into hans/paycall-in-builder
cwang25 Jun 17, 2024
3c283b8
fix errors
cwang25 Jun 17, 2024
67f76c9
forge fmt
cwang25 Jun 17, 2024
8f24804
use bridgepayload struct to avoid from having to use --via-ir
cwang25 Jun 17, 2024
6bac10c
better struct init
cwang25 Jun 17, 2024
e65113e
remove comments
cwang25 Jun 17, 2024
905876c
Revert "remove comments"
cwang25 Jun 17, 2024
3252975
Revert "better struct init"
cwang25 Jun 17, 2024
a5c2326
Revert "use bridgepayload struct to avoid from having to use --via-ir"
cwang25 Jun 17, 2024
aa24853
lint
cwang25 Jun 17, 2024
caf1d7d
address comments, move payment info from quarkbuilder to paymentinfo
cwang25 Jun 17, 2024
c72df5a
test rename
cwang25 Jun 17, 2024
bba1d7d
verify digest
cwang25 Jun 17, 2024
e7111f3
Updated on merges, added bridge paycall test as well, Updated assert…
cwang25 Jun 18, 2024
8cf6fc9
debug mystery test error
cwang25 Jun 18, 2024
7a884b3
add the same block back
cwang25 Jun 18, 2024
b96cefb
its 6 arguments! not sure why only CI complains abt 7 arguments...
cwang25 Jun 18, 2024
ad3bc2b
7?
cwang25 Jun 18, 2024
3bfc106
add it back
cwang25 Jun 18, 2024
e80ae4b
Merge remote-tracking branch 'origin/main' into hans/paycall-in-builder
cwang25 Jun 18, 2024
47b1c22
oh main has new chnages in tests. xD
cwang25 Jun 18, 2024
b67cefd
update doc
cwang25 Jun 18, 2024
6d9336e
update doc
cwang25 Jun 18, 2024
da9a9c6
quotecall wrapper
Jun 12, 2024
5400fcd
forge fmt
Jun 12, 2024
2f1f790
old forge fmt
Jun 12, 2024
51c2be2
remove dup Transfer from test
Jun 13, 2024
17a7ecd
quotecall changed to use paymenttoken.sol to create correct address
Jun 13, 2024
f09c23e
update function call for wrap
Jun 13, 2024
f10a921
some files went missing during rebase due to overlapping file names
cwang25 Jun 18, 2024
47e4cbe
lint
cwang25 Jun 18, 2024
365eb63
remove chainId from CodeJarHelper call
cwang25 Jun 18, 2024
e2eda02
fix import changes
cwang25 Jun 18, 2024
0c168db
Merge remote-tracking branch 'origin/main' into hans/quotecall
Jun 21, 2024
a3ce09a
remove default
Jun 21, 2024
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
37 changes: 37 additions & 0 deletions src/builder/QuotecallWrapper.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity ^0.8.23;

import {CodeJarHelper} from "./CodeJarHelper.sol";
import {IQuarkWallet} from "quark-core/src/interfaces/IQuarkWallet.sol";
import {Quotecall} from "../Quotecall.sol";
import {PaymentInfo} from "./PaymentInfo.sol";

// Helper library to wrap a QuarkOperation from Actions.sol for a Paycall
library QuotecallWrapper {
function wrap(
IQuarkWallet.QuarkOperation memory operation,
uint256 chainId,
string memory paymentTokenSymbol,
uint256 quotedAmount
) internal pure returns (IQuarkWallet.QuarkOperation memory) {
PaymentInfo.PaymentToken memory paymentToken = PaymentInfo.knownToken(paymentTokenSymbol, chainId);
bytes memory quotecallSource =
abi.encodePacked(type(Quotecall).creationCode, abi.encode(paymentToken.priceFeed, paymentToken.token));
bytes[] memory scriptSources = new bytes[](operation.scriptSources.length + 1);
for (uint256 i = 0; i < operation.scriptSources.length; i++) {
scriptSources[i] = operation.scriptSources[i];
}

scriptSources[operation.scriptSources.length] = quotecallSource;

return IQuarkWallet.QuarkOperation({
nonce: operation.nonce,
scriptAddress: CodeJarHelper.getCodeAddress(quotecallSource),
scriptCalldata: abi.encodeWithSelector(
Quotecall.run.selector, operation.scriptAddress, operation.scriptCalldata, quotedAmount
),
scriptSources: scriptSources,
expiry: operation.expiry
});
}
}
76 changes: 76 additions & 0 deletions test/QuotecallWrapper.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity 0.8.23;

import "forge-std/Test.sol";
import "forge-std/console.sol";
import "forge-std/StdUtils.sol";

import {CodeJar} from "codejar/src/CodeJar.sol";
import {QuarkWallet} from "quark-core/src/QuarkWallet.sol";
import {QuarkStateManager} from "quark-core/src/QuarkStateManager.sol";
import {QuarkWalletProxyFactory} from "quark-proxy/src/QuarkWalletProxyFactory.sol";
import {IQuarkWallet} from "quark-core/src/interfaces/IQuarkWallet.sol";
import {CodeJarHelper} from "src/builder/CodeJarHelper.sol";
import {Quotecall} from "src/Quotecall.sol";
import {QuotecallWrapper} from "src/builder/QuotecallWrapper.sol";
import {TransferActions} from "src/DeFiScripts.sol";

contract QuotecallWrapperTest is Test {
QuarkWalletProxyFactory public factory;
uint256 alicePrivateKey = 0xa11ce;
address alice = vm.addr(alicePrivateKey);
CodeJar codeJar;

address constant USDC = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48;
address constant ETH_USD_PRICE_FEED = 0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419;

function setUp() public {
factory = new QuarkWalletProxyFactory(address(new QuarkWallet(new CodeJar(), new QuarkStateManager())));
codeJar = QuarkWallet(payable(factory.walletImplementation())).codeJar();
}

/* ===== general tests ===== */
function testSimpleTransferAndWrapForQuotecall() public {
// Create operation for just TransferActions
QuarkWallet wallet = QuarkWallet(factory.create(alice, address(0)));
bytes[] memory scriptSources = new bytes[](1);
scriptSources[0] = type(TransferActions).creationCode;
IQuarkWallet.QuarkOperation memory op = IQuarkWallet.QuarkOperation({
nonce: wallet.stateManager().nextNonce(address(wallet)),
scriptAddress: CodeJarHelper.getCodeAddress(type(TransferActions).creationCode),
scriptCalldata: abi.encodeWithSelector(TransferActions.transferERC20Token.selector, USDC, address(this), 10e6),
scriptSources: scriptSources,
expiry: 99999999999
});

// Wrap with Quotecall wrapper
IQuarkWallet.QuarkOperation memory wrappedQuotecallOp = QuotecallWrapper.wrap(op, 1, "USDC", 20e6);

// Check the transfer action is wrapped in a Quotecall
assertEq(wrappedQuotecallOp.nonce, op.nonce, "nonce should be the same");
assertEq(
wrappedQuotecallOp.scriptAddress,
CodeJarHelper.getCodeAddress(
abi.encodePacked(type(Quotecall).creationCode, abi.encode(ETH_USD_PRICE_FEED, USDC))
),
"script address should be Quotecall"
);
assertEq(wrappedQuotecallOp.scriptSources.length, 2, "script sources should be 2 (TransferAction + Quotecall)");
assertEq(
wrappedQuotecallOp.scriptSources[0],
type(TransferActions).creationCode,
"script sources [0] should be TransferAction"
);
assertEq(
wrappedQuotecallOp.scriptSources[1],
abi.encodePacked(type(Quotecall).creationCode, abi.encode(ETH_USD_PRICE_FEED, USDC)),
"script sources [1] should be Quotecall"
);
assertEq(wrappedQuotecallOp.expiry, 99999999999, "expiry should be the same");
assertEq(
wrappedQuotecallOp.scriptCalldata,
abi.encodeWithSelector(Quotecall.run.selector, op.scriptAddress, op.scriptCalldata, 20e6),
"calldata should be Quotecall.run(op.scriptAddress, op.scriptCalldata, 20e6)"
);
}
}