Skip to content

Commit

Permalink
chore: update script
Browse files Browse the repository at this point in the history
  • Loading branch information
pbkompasz committed Sep 4, 2024
1 parent 3149497 commit 1e9a074
Showing 1 changed file with 58 additions and 32 deletions.
90 changes: 58 additions & 32 deletions vitest/web3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ import { spawn } from "child_process";
import express from "express";
import dotenv from "dotenv";
import { JsonRpcProvider } from "@ethersproject/providers";
// @ts-expect-error Types missing
import { decodePermits } from "@ubiquibot/permit-generation/handlers";
// import { ethers } from "ethers";
// import { permit2Address } from "../shared/constants";
// import { permit2Abi } from "../static/scripts/rewards/abis/permit2-abi";
// import { Erc20PermitReward } from "@ubiquibot/permit-generation";
import { ethers } from "ethers";
import { permit2Address } from "@ubiquity-dao/rpc-handler";
import { giftCardTreasuryAddress } from "../shared/constants";
import { permit2Abi } from "../static/scripts/rewards/abis/permit2-abi";
import { PermitReward } from "@ubiquibot/permit-generation";
import { generateErc20Permit } from "../scripts/typescript/generate-erc20-permit-url";
import { AppState } from "../static/scripts/rewards/app-state";

const beneficiary = "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266";
// const SENDER_PRIVATE_KEY = "0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d";
const SENDER_PRIVATE_KEY = "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80";
const app = new AppState();

// Run anvil
Expand All @@ -37,30 +38,41 @@ async function createMockApp() {
app.claims = decodePermits(base64encodedTxData);
app.claimTxs = {};
const provider = new JsonRpcProvider("http://localhost:8545");
console.log(provider);
app.signer = provider.getSigner(beneficiary);
}

// async function createMockTransfer(reward: Erc20PermitReward) {
// if (!app.signer) return;
// const permit2Contract = new ethers.Contract(permit2Address, permit2Abi, app.signer);
async function createMockTransfer(reward: PermitReward) {
if (!app.signer) return;
const provider = new JsonRpcProvider(process.env.RPC_PROVIDER_URL);
const wallet = new ethers.Wallet(SENDER_PRIVATE_KEY, provider);
const permit2Contract = new ethers.Contract(permit2Address, permit2Abi, wallet);

// const { tokenAddress, amount, nonce, deadline, owner, signature, beneficiary } = reward;
reward.beneficiary = giftCardTreasuryAddress;
const { tokenAddress, amount, nonce, deadline, owner, signature, beneficiary } = reward;

// return await permit2Contract.permitTransferFrom(
// {
// permitted: {
// token: tokenAddress,
// amount,
// },
// nonce,
// deadline,
// },
// { to: beneficiary, requestedAmount: amount },
// owner,
// signature
// );
// }
try {
const tx = await permit2Contract.permitTransferFrom(
{
permitted: {
token: tokenAddress,
amount,
},
nonce,
deadline,
},
{ to: beneficiary, requestedAmount: amount },
owner,
signature,
{
gasLimit: 100000,
}
);
await tx.wait();
return tx;
} catch (err) {
console.log(err);
}
}

dotenv.config();

Expand All @@ -72,16 +84,30 @@ webApp.get("/", (_req, res: { send: (arg0: string) => void }) => {
res.send("Express + TypeScript Server");
});

// eslint-disable-next-line @typescript-eslint/naming-convention
webApp.get("/create-mock-app", async (_req, res: { send: (arg0: string) => void }) => {
await createMockApp();
res.send("Express + TypeScript ");
webApp.post("/create-mock-app", async (req, res) => {
try {
await createMockApp();
res.json({
success: true,
permits: app.claims,
});
} catch (error) {
res.status(500).json({
error: "Error creating mock app",
});
}
});

// eslint-disable-next-line @typescript-eslint/naming-convention
webApp.get("/create-mock-transfer", async (_req, res: { send: (arg0: string) => void }) => {
// await createMockTransfer();
res.send("Express + TypeScript Server");
webApp.post("/create-mock-transfer", async (req, res) => {
try {
await createMockTransfer(app.claims[1]);
} catch (error) {
res.status(500).json({
// @ts-expect-error you suck
error: error.message,
reward: app.claims[0],
});
}
});

webApp.listen(port, async () => {
Expand Down

0 comments on commit 1e9a074

Please sign in to comment.