Skip to content

Commit

Permalink
fix: make it work
Browse files Browse the repository at this point in the history
  • Loading branch information
Haypierre committed Jan 13, 2025
1 parent 48bef5e commit 47cbc13
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 55 deletions.
24 changes: 12 additions & 12 deletions demo/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,33 +29,33 @@ export type OpenfortContracts = {

export const openfortContracts: Record<supportedChain, OpenfortContracts> = {
base: {
paymaster: "0x3cB057Fd3BE519cB50788b8b282732edBF533DC6",
invoiceManager: "0x666eB01fBba3F3D5f7e5d8e72c6Ea57B6AF09798",
vaultManager: "0xEA7aa047c78c5583a2896e18E127A5C2E59C0887",
paymaster: "0x9B1D4356014e36d95b0b00251770d641ea02979f",
invoiceManager: "0xBC11EE7d2F3D74F5A6a5aDD3457908870BFcF37b",
vaultManager: "0x047F60FE3243d1C54740AD11109f95E9ba927c6D",
vaults: {
"0xfF3311cd15aB091B00421B23BcB60df02EFD8db7":
"0x21c14066F5D62Cbec3c42e2c718Ce82E72fCBF87",
"0x5502B2Da288Be13F48eE46E3261690Ed4a1e71f9",
"0xa9a0179e045cF39C5F4d914583dc3648DfBDeeF1":
"0x742d0fc742B89267411c5AC24a5fdA3CA264eeC2",
"0x0230a6641Fb11e760f2f7A263F6Fe2a9b0476b44",
},
},
optimism: {
paymaster: "0x48c2DE32E983cD077486c218a2f6A0119E1446cF",
invoiceManager: "0x2C4511a143e9C583B5Ae5c4206A4C9D3882F35Bf",
vaultManager: "0x1EEb54d847BC170a4F1e12312f9b5D74EeCF1018",
paymaster: "0x511985306FDDE63cda68F5675EC296AAd826b5b8",
invoiceManager: "0x9dDB3Af574307DFEfE9d69D09A0BBcF55b9e2D34",
vaultManager: "0xd454fbc6Df5D9d91Fa02e60fD46CDD2208d0b33b",
vaults: {
"0x2522F4Fc9aF2E1954a3D13f7a5B2683A00a4543A":
"0xeFb7144787FFFCEF306bC99cEBF42AB08d5609c8",
"0xaF45f62eB99AD2091440336ca714B21F06525978",
"0xd926e338e047aF920F59390fF98A3114CCDcab4a":
"0x34BC35Ff16C1ab0e5123D5De58eC8d1353B09968",
"0x5b306B655B84Bc3201e6f9577d0CDcc7C2e9Ebfb",
},
},
};

// TODO: refactor this to only refer to openfortContracts
export const vaultA = {
base: "0x21c14066F5D62Cbec3c42e2c718Ce82E72fCBF87",
optimism: "0xeFb7144787FFFCEF306bC99cEBF42AB08d5609c8",
base: "0x5502B2Da288Be13F48eE46E3261690Ed4a1e71f9",
optimism: "0xaF45f62eB99AD2091440336ca714B21F06525978",
};

export const tokenA = {
Expand Down
42 changes: 25 additions & 17 deletions demo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,20 +93,20 @@ program
const walletClient = walletClients[chain];
const publicClient = publicClients[chain];

// Get the current nonce for the account
// const nonce = await publicClient.getTransactionCount({
// address: walletClient.account?.address as Address,
// });
// const approveHash = await walletClient.writeContract({
// address: token,
// abi: parseAbi(["function approve(address, uint256)"]),
// functionName: "approve",
// args: [vaultManager, amount],
// chain: walletClient.chain,
// account: walletClient.account || null,
// nonce,
// });
//console.log(`Approve transaction sent: ${approveHash}`);
const nonce = await publicClient.getTransactionCount({
address: walletClient.account?.address as Address,
});

const approveHash = await walletClient.writeContract({
address: token,
abi: parseAbi(["function approve(address, uint256)"]),
functionName: "approve",
args: [vaultManager, amount],
chain: walletClient.chain,
account: walletClient.account || null,
nonce,
});
console.log(`Approve transaction sent: ${approveHash}`);

const hash = await walletClient.writeContract({
address: vaultManager,
Expand All @@ -117,6 +117,7 @@ program
args: [recipient, token, vault, amount, false],
chain: walletClient.chain,
account: walletClient.account || null,
nonce: nonce + 1,
});
console.log(`Deposit transaction sent: ${hash}`);
});
Expand Down Expand Up @@ -167,6 +168,7 @@ program
const accountAddress = await account.getAddress();
console.log(`Account Address: ${accountAddress}`);
const paymaster = openfortContracts[chain].paymaster;
console.log(`Paymaster: ${paymaster}`);
const unsignedUserOp = await bundlerClient.prepareUserOperation({
account: account,
calls: [
Expand All @@ -193,6 +195,7 @@ program
postVerificationGasLimit: 1000000n,
preVerificationGas: 1000000n,
callGasLimit: 1000000n,
paymasterPostOpGasLimit: 1000000n,
/** Concatenation of {@link UserOperation`verificationGasLimit`} (16 bytes) and {@link UserOperation`callGasLimit`} (16 bytes) */
accountGasLimits:
`0x${1000000n.toString(16)}${1000000n.toString(16)}` as Hex,
Expand Down Expand Up @@ -313,6 +316,9 @@ program
throw new Error(`Unsupported chain: ${chain}`);
}
const invoiceWithRepayTokens = await invoiceManager.readInvoice(invoiceId);

console.log("invoiceWithRepayTokens");
console.log(invoiceWithRepayTokens);
const walletClient = walletClients[chain];

// we can hard code logIndex since it is the index of the log within the tx
Expand Down Expand Up @@ -353,14 +359,16 @@ program
if (!isValidChain(chain)) {
throw new Error(`Unsupported chain: ${chain}`);
}
const paymaster = openfortContracts[chain].paymaster;
const invoiceManager = openfortContracts[chain].invoiceManager;
const publicClient = publicClients[chain];

const currentBlock = await getBlockNumber(chain);

const logs = await publicClient.getLogs({
address: paymaster,
event: parseAbi(["event InvoiceCreated(bytes32 indexed invoiceId)"])[0],
address: invoiceManager,
event: parseAbi([
"event InvoiceCreated(bytes32 indexed invoiceId, address indexed account, address indexed paymaster)",
])[0],
fromBlock: currentBlock - 10000n,
toBlock: currentBlock,
});
Expand Down
1 change: 0 additions & 1 deletion demo/paymaster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
GetPaymasterDataReturnType,
GetPaymasterStubDataParameters,
GetPaymasterStubDataReturnType,
UserOperation,
PackedUserOperation,
} from "viem/account-abstraction";
import {
Expand Down
1 change: 1 addition & 0 deletions src/mocks/CrossL2Prover.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

2 changes: 1 addition & 1 deletion src/mocks/MockCrossL2Prover.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ contract MockCrossL2Prover is ICrossL2Prover {
returns (string memory chainId, address emittingContract, bytes[] memory topics, bytes memory unindexedData)
{
(chainId, emittingContract, topics, unindexedData) = abi.decode(
hex"00000000000000000000000000000000000000000000000000000000000000800000000000000000000000003cb057fd3be519cb50788b8b282732edbf533dc600000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000001a0000000000000000000000000000000000000000000000000000000000000000538343533320000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000020ab6994bba319b437692f1dbbe4d689382f25c4cfa9a291959e0af1ca5cd9e13f0000000000000000000000000000000000000000000000000000000000000020886f7a98cfb9c6f2b6a6b4be00a89b75c0a846bf1c9b265b17ba4f9452acbc640000000000000000000000000000000000000000000000000000000000000000",
hex"00000000000000000000000000000000000000000000000000000000000000800000000000000000000000003cb057fd3be519cb50788b8b282732edbf533dc600000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000001a00000000000000000000000000000000000000000000000000000000000000005383435333200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000205243d6c5479d93025de9e138a29c467868f762bb78591e96299fb3f437afcc04000000000000000000000000000000000000000000000000000000000000002028a285ad4af66f8b864972de6e0ea1095667e73ade7db3d93151c0c2660229050000000000000000000000000000000000000000000000000000000000000000",
(string, address, bytes[], bytes)
);
}
Expand Down
8 changes: 5 additions & 3 deletions src/paymasters/CABPaymaster.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {IPaymasterVerifier} from "../interfaces/IPaymasterVerifier.sol";
import {ICrossL2Prover} from "@vibc-core-smart-contracts/contracts/interfaces/ICrossL2Prover.sol";
import {LibBytes} from "@solady/utils/LibBytes.sol";


/**
* @title CABPaymaster
* @dev A paymaster used in chain abstracted balance to sponsor the gas fee and tokens cross-chain.
Expand Down Expand Up @@ -61,8 +62,9 @@ contract CABPaymaster is IPaymasterVerifier, BasePaymaster {
(uint256 logIndex, bytes memory proof) = abi.decode(_proof, (uint256, bytes));
(,, bytes[] memory topics,) = crossL2Prover.validateEvent(logIndex, proof);

return LibBytes.eq(
abi.encode(topics[0], topics[1]), abi.encode(IInvoiceManager.InvoiceCreated.selector, invoiceId)
return (
LibBytes.eqs(topics[0], IInvoiceManager.InvoiceCreated.selector) &&
LibBytes.eqs(topics[1], invoiceId)
);
}

Expand Down Expand Up @@ -106,7 +108,7 @@ contract CABPaymaster is IPaymasterVerifier, BasePaymaster {
invoice.nonce,
invoice.paymaster,
invoice.sponsorChainId,
keccak256(abi.encode(invoice.repayTokenInfos)) // vault, amount, chain
keccak256(abi.encode(invoice.repayTokenInfos))
)
);
}
Expand Down
42 changes: 21 additions & 21 deletions test/CABPaymater.t.sol

Large diffs are not rendered by default.

0 comments on commit 47cbc13

Please sign in to comment.