test: updated integration script

This commit is contained in:
Francisco Bezzecchi
2025-04-14 21:06:40 -03:00
parent 95d71ad971
commit 6ace565fe5
3 changed files with 109 additions and 12 deletions

View File

@@ -29,3 +29,16 @@ export const request = async (requestBody) => {
});
console.log(JSON.stringify(await r.json(), null, 2));
};
export const quote = async (quoteBody) => {
let r = await fetch("http://localhost:3000/relayer/quote", {
method: "post",
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(quoteBody)
})
const quoteResponse = await r.json();
console.log(JSON.stringify(quoteResponse, null, 2))
return quoteResponse;
}

View File

@@ -1,6 +1,12 @@
import { Address, Hex } from "viem";
// // mainnet
// export const ENTRYPOINT_ADDRESS: Address = "0x6818809EefCe719E480a7526D76bD3e561526b46";
// export const ETH_POOL_ADDRESS: Address = "0xF241d57C6DebAe225c0F2e6eA1529373C9A9C9fB";
// localnet
export const ENTRYPOINT_ADDRESS: Address = "0xd6DB18A83F9eE4e2d0FC8D6BEd075A2905A83FDA";
export const ETH_POOL_ADDRESS: Address = "0x4Cb503503047b66aA5e64b9BDC8148E769ac52f6";
export const LOCAL_ANVIL_RPC = "http://127.0.0.1:8545";
export const PRIVATE_KEY: Hex = "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80";

View File

@@ -1,10 +1,20 @@
import { Hash, Withdrawal } from "@0xbow/privacy-pools-core-sdk";
import { encodeAbiParameters, getAddress, Hex } from "viem";
import { request } from "./api-test.js";
import { request, quote } from "./api-test.js";
import { anvilChain, pool } from "./chain.js";
import { ENTRYPOINT_ADDRESS } from "./constants.js";
import { deposit, proveWithdrawal } from "./create-withdrawal.js";
interface QuoteResponse {
baseFeeBPS: bigint,
feeBPS: bigint,
feeCommitment?: {
expiration: number,
withdrawalData: `0x${string}`,
signedRelayerCommitment: `0x${string}`,
}
}
const FeeDataAbi = [
{
name: "FeeData",
@@ -25,36 +35,104 @@ async function prove(w: Withdrawal, scope: bigint) {
return proveWithdrawal(w, scope);
}
async function depositEth() {
async function depositCli() {
const r = await deposit();
await r.wait();
console.log(`Successful deposit, hash := ${r.hash}`);
}
(async () => {
async function quoteReq(chainId: number, asset: string, recipient: string, amount: string) {
return (await quote({
chainId,
amount,
asset,
recipient
}) as QuoteResponse);
}
async function quoteCli(chainId: string, asset: string, amount?: string) {
const _amount = amount ? Number(amount) : 100_000_000_000_000_000n
quoteReq(Number(chainId), asset, recipient, _amount.toString())
}
async function relayCli(chainId: string, asset: string, withQuote: boolean) {
const scope = await pool.read.SCOPE() as Hash;
const data = encodeAbiParameters(FeeDataAbi, [
{
recipient,
feeRecipient: FEE_RECEIVER_ADDRESS,
relayFeeBPS: 1_000n,
},
]) as Hex;
let data;
let feeCommitment = undefined;
if (withQuote) {
const amount = "100000000000000000"; // 0.1 ETH
const quoteRes = await quoteReq(Number(chainId), asset, recipient, amount);
data = quoteRes.feeCommitment!.withdrawalData as Hex
feeCommitment = {
...quoteRes.feeCommitment,
};
} else {
data = encodeAbiParameters(FeeDataAbi, [
{
recipient,
feeRecipient: FEE_RECEIVER_ADDRESS,
relayFeeBPS: 100n,
},
]) as Hex;
}
const withdrawal = { processooor, data };
await depositEth();
// prove
const { proof, publicSignals } = await prove(withdrawal, scope);
const requestBody = {
scope: scope.toString(),
chainId: anvilChain.id,
withdrawal,
publicSignals,
proof,
feeCommitment
};
await request(requestBody);
}
async function cli() {
const args = process.argv.slice(2)
const action = args[0];
switch (action) {
case "deposit": {
console.log(action)
await depositCli();
break;
}
case "quote": {
console.log(action)
if (args.length < 3) {
throw Error("Not enough args")
}
await quoteCli(args[1]!, args[2]!, args[3])
break;
}
case "relay": {
console.log(...args)
const withQuote = args.includes("--with-quote")
const noFlags = args.slice(1).filter(a => a !== "--with-quote")
if (noFlags.length < 2) {
throw Error("Not enough args")
}
await relayCli(noFlags[0]!, noFlags[1]!, withQuote);
break;
}
case undefined: {
console.log("No action selected")
break;
}
}
}
(async () => {
cli();
})();