Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: rpc upgrade #204

Merged
merged 7 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
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
11 changes: 10 additions & 1 deletion .github/workflows/cypress-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,20 @@ jobs:
- name: Start Anvil
run: yarn test:anvil &

- name: Wait for Anvil
run: |
while ! curl -s http://localhost:8545; do
Keyrxng marked this conversation as resolved.
Show resolved Hide resolved
sleep 1
done

- name: Fund test accounts
run: yarn test:fund

- name: Cypress run
uses: cypress-io/github-action@v6
with:
build: yarn run build
start: yarn test:fund, yarn start
start: yarn start

env:
SUPABASE_URL: "https://wfzpewmlyiozupulbuur.supabase.co"
Expand Down
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,3 @@
[submodule "lib/permit2"]
path = lib/permit2
url = https://github.com/Uniswap/permit2
[submodule "lib/chainlist"]
path = lib/chainlist
url = https://github.com/DefiLlama/chainlist.git
11 changes: 0 additions & 11 deletions build/esbuild-build.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
import { execSync } from "child_process";
import { config } from "dotenv";
import esbuild from "esbuild";
import extraRpcs from "../lib/chainlist/constants/extraRpcs";
const typescriptEntries = ["static/scripts/rewards/init.ts"];
export const entries = [...typescriptEntries];

const allNetworkUrls: Record<string, string[]> = {};
// this flattens all the rpcs into a single object, with key names that match the networkIds. The arrays are just of URLs per network ID.

Object.keys(extraRpcs).forEach((networkId) => {
const officialUrls = extraRpcs[networkId].rpcs.filter((rpc) => typeof rpc === "string");
const extraUrls: string[] = extraRpcs[networkId].rpcs.filter((rpc) => rpc.url !== undefined).map((rpc) => rpc.url);
allNetworkUrls[networkId] = [...officialUrls, ...extraUrls];
});

export const esBuildContext: esbuild.BuildOptions = {
sourcemap: true,
entryPoints: entries,
Expand All @@ -29,7 +19,6 @@ export const esBuildContext: esbuild.BuildOptions = {
},
outdir: "static/out",
define: createEnvDefines(["SUPABASE_URL", "SUPABASE_ANON_KEY"], {
extraRpcs: allNetworkUrls,
commitHash: execSync(`git rev-parse --short HEAD`).toString().trim(),
}),
};
Expand Down
2 changes: 1 addition & 1 deletion cypress/scripts/anvil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { spawn } from "child_process";

const url = "http://localhost:8545";

const anvil = spawn("anvil", ["--chain-id", "31337", "--fork-url", "https://gnosis.drpc.org", "--host", "127.0.0.1", "--port", "8545"], {
const anvil = spawn("anvil", ["--chain-id", "31337", "--fork-url", "https://gnosis-pokt.nodies.app", "--host", "127.0.0.1", "--port", "8545"], {
stdio: "inherit",
});

Expand Down
1 change: 0 additions & 1 deletion lib/chainlist
Submodule chainlist deleted from 805928
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"test:start": "yarn start",
"test:run": "cypress run",
"test:open": "cypress open",
"test:fund": "cast rpc --rpc-url http://127.0.0.1:8545 anvil_impersonateAccount 0xba12222222228d8ba445958a75a0704d566bf2c8 & cast send --rpc-url http://127.0.0.1:8545 0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d --unlocked --from 0xba12222222228d8ba445958a75a0704d566bf2c8 'transfer(address,uint256)(bool)' 0x70997970C51812dc3A010C7d01b50e0d17dc79C8 337888400000000000000000 & cast send --rpc-url http://127.0.0.1:8545 0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d --unlocked --from 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 'approve(address,uint256)(bool)' 0x000000000022D473030F116dDEE9F6B43aC78BA3 9999999999999991111111119999999999999999 & cast send --rpc-url http://127.0.0.1:8545 0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d --unlocked --from 0x70997970C51812dc3A010C7d01b50e0d17dc79C8 'approve(address,uint256)(bool)' 0x000000000022D473030F116dDEE9F6B43aC78BA3 999999999999999111119999999999999999"
"test:fund": "cast rpc --rpc-url http://127.0.0.1:8545 anvil_impersonateAccount 0xba12222222228d8ba445958a75a0704d566bf2c8 & cast send --rpc-url http://127.0.0.1:8545 0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d --unlocked --from 0xba12222222228d8ba445958a75a0704d566bf2c8 \"transfer(address,uint256)(bool)\" 0x70997970C51812dc3A010C7d01b50e0d17dc79C8 337888400000000000000000 & cast send --rpc-url http://127.0.0.1:8545 0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d --unlocked --from 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 \"approve(address,uint256)(bool)\" 0x000000000022D473030F116dDEE9F6B43aC78BA3 9999999999999991111111119999999999999999 & cast send --rpc-url http://127.0.0.1:8545 0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d --unlocked --from 0x70997970C51812dc3A010C7d01b50e0d17dc79C8 \"approve(address,uint256)(bool)\" 0x000000000022D473030F116dDEE9F6B43aC78BA3 999999999999999111119999999999999999 & cast send --rpc-url http://127.0.0.1:8545 0xfB9124a8Bd01c250942de7beeE1E50aB9Ce36493 --unlocked --from 0xba12222222228d8ba445958a75a0704d566bf2c8 --value 0.1ether"
},
"keywords": [
"typescript",
Expand All @@ -38,14 +38,12 @@
],
"dependencies": {
"@ethersproject/providers": "^5.7.2",
"@sinclair/typebox": "^0.32.15",
"@supabase/supabase-js": "^2.39.8",
"@ubiquibot/permit-generation": "1.2.2",
"@ubiquity-dao/rpc-handler": "^1.1.0",
"@uniswap/permit2-sdk": "^1.2.0",
"axios": "^1.6.7",
"dotenv": "^16.4.4",
"ethers": "^5.7.2",
"node-fetch": "^3.3.2",
"npm-run-all": "^4.1.5"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion static/scripts/rewards/app-state.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { JsonRpcProvider, JsonRpcSigner } from "@ethersproject/providers";
import { Permit } from "@ubiquibot/permit-generation/types";
import { networkExplorers } from "./constants";
import { networkExplorers } from "@ubiquity-dao/rpc-handler";

export class AppState {
public claims: Permit[] = [];
Expand Down
5 changes: 2 additions & 3 deletions static/scripts/rewards/cirip/ens-lookup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ import abi from "../abis/cirip.json";
import { fetchEns } from "./fetch-ens";
import { queryReverseEns } from "./query-reverse-ens";

export const UBIQUITY_RPC_ENDPOINT = "https://rpc-pay.ubq.fi/v1/mainnet";
export const reverseEnsInterface = new ethers.utils.Interface(abi);

// addEventListener("fetch", event => {
// event.respondWith(handleRequest(event.request).catch(err => new Response(err.stack, { status: 500 })));
// });

export async function ensLookup(addr: string) {
export async function ensLookup(addr: string, networkID: number) {
const _address = "/".concat(addr); // quick adapter

// try {
Expand All @@ -24,7 +23,7 @@ export async function ensLookup(addr: string) {
let reverseRecord = null as null | string;
// let response = "";
try {
reverseRecord = await queryReverseEns(address);
reverseRecord = await queryReverseEns(address, networkID);
const responseParsed = JSON.parse(reverseRecord).result;
const _reverseRecord = ethers.utils.defaultAbiCoder.decode([ethers.utils.ParamType.from("string[]")], responseParsed);
reverseRecord = _reverseRecord[0][0];
Expand Down
19 changes: 16 additions & 3 deletions static/scripts/rewards/cirip/query-reverse-ens.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
import { reverseEnsInterface, UBIQUITY_RPC_ENDPOINT } from "./ens-lookup";
import { AppState } from "../app-state";
import { useRpcHandler } from "../web3/use-rpc-handler";
import { reverseEnsInterface } from "./ens-lookup";

export async function queryReverseEns(address: string) {
export async function queryReverseEns(address: string, networkID: number) {
// Try to get the ENS name from localStorage
const cachedEnsName = localStorage.getItem(address);
const endpoint = (await useRpcHandler({ networkId: networkID } as AppState)).connection.url;

if (!endpoint) {
console.error("ENS lookup failed: No endpoint found for network ID", networkID);
if (cachedEnsName) return cachedEnsName;
}

if (cachedEnsName) {
// If the ENS name is in localStorage, return it
Expand All @@ -11,7 +19,7 @@ export async function queryReverseEns(address: string) {
// If the ENS name is not in localStorage, fetch it from the API
const data = reverseEnsInterface.encodeFunctionData("getNames", [[address.substring(2)]]);

const response = await fetch(UBIQUITY_RPC_ENDPOINT, {
const response = await fetch(endpoint, {
method: "POST",
headers: {
"Content-Type": "application/json",
Expand All @@ -24,6 +32,11 @@ export async function queryReverseEns(address: string) {
}),
});

if (!response.ok) {
Keyrxng marked this conversation as resolved.
Show resolved Hide resolved
console.error("ENS lookup failed: API request failed");
return "";
}

const ensName = await response.text();

// Store the ENS name in localStorage for future use
Expand Down
56 changes: 0 additions & 56 deletions static/scripts/rewards/constants.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { createClient } from "@supabase/supabase-js";
import { decodePermits } from "@ubiquibot/permit-generation/handlers";
import { Permit } from "@ubiquibot/permit-generation/types";
import { app, AppState } from "../app-state";
import { useFastestRpc } from "../rpc-optimization/get-optimal-provider";
import { buttonController, toaster } from "../toaster";
import { connectWallet } from "../web3/connect-wallet";
import { checkRenderInvalidatePermitAdminControl, checkRenderMakeClaimControl } from "../web3/erc20-permit";
import { verifyCurrentNetwork } from "../web3/verify-current-network";
import { claimRewardsPagination } from "./claim-rewards-pagination";
import { renderTransaction } from "./render-transaction";
import { setClaimMessage } from "./set-claim-message";
import { useRpcHandler } from "../web3/use-rpc-handler";

declare const SUPABASE_URL: string;
declare const SUPABASE_ANON_KEY: string;
Expand All @@ -31,9 +31,9 @@ export async function readClaimDataFromUrl(app: AppState) {
app.claims = decodeClaimData(base64encodedTxData);
app.claimTxs = await getClaimedTxs(app);
try {
app.provider = await useFastestRpc(app);
app.provider = await useRpcHandler(app);
} catch (e) {
toaster.create("error", `${e}`);
toaster.create("error", `e`);
}

if (window.ethereum) {
Expand Down
6 changes: 4 additions & 2 deletions static/scripts/rewards/render-transaction/render-ens-name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,20 @@ type EnsParams =
address: string;
tokenAddress: string;
tokenView: true;
networkID: number;
}
| {
element: Element;
address: string;
tokenAddress?: undefined;
tokenView?: false;
networkID: number;
};

export async function renderEnsName({ element, address, tokenAddress, tokenView }: EnsParams): Promise<void> {
export async function renderEnsName({ element, address, tokenAddress, tokenView, networkID }: EnsParams): Promise<void> {
let href: string = "";
try {
const resolved = await ensLookup(address);
const resolved = await ensLookup(address, networkID);
let ensName: undefined | string;
if (resolved.reverseRecord) {
ensName = resolved.reverseRecord;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { app } from "../app-state";
import { networkExplorers } from "../constants";
import { networkExplorers } from "@ubiquity-dao/rpc-handler";
import { buttonController, getMakeClaimButton, viewClaimButton } from "../toaster";
import { checkRenderInvalidatePermitAdminControl, claimErc20PermitHandlerWrapper, fetchTreasury } from "../web3/erc20-permit";
import { claimErc721PermitHandler } from "../web3/erc721-permit";
Expand Down Expand Up @@ -44,7 +44,7 @@ export async function renderTransaction(): Promise<Success> {
}).catch(console.error);

const toElement = document.getElementById(`rewardRecipient`) as Element;
renderEnsName({ element: toElement, address: app.reward.beneficiary }).catch(console.error);
renderEnsName({ element: toElement, address: app.reward.beneficiary, networkID: app.networkId }).catch(console.error);

if (app.provider) {
checkRenderInvalidatePermitAdminControl(app).catch(console.error);
Expand Down

This file was deleted.

31 changes: 0 additions & 31 deletions static/scripts/rewards/rpc-optimization/get-optimal-provider.ts

This file was deleted.

Loading
Loading