Skip to content

Commit b592128

Browse files
committed
Merge branch 'fix/perf' into development
2 parents 53ab0ec + 7855fbd commit b592128

File tree

10 files changed

+48
-25
lines changed

10 files changed

+48
-25
lines changed

.cspell.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
"useGitignore": true,
66
"language": "en",
77
"words": [
8-
"solmate",
98
"binkey",
109
"binsec",
10+
"chainlist",
1111
"cirip",
1212
"dataurl",
1313
"devpool",
@@ -25,6 +25,7 @@
2525
"Rpcs",
2626
"scalarmult",
2727
"servedir",
28+
"solmate",
2829
"sonarjs",
2930
"typebox",
3031
"TYPEHASH",

.eslintignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
build/esbuild-build.ts
2+
static/scripts/rewards/constants.ts
3+
static/scripts/rewards/render-transaction/render-transaction.ts
4+
**/lib/**

.github/workflows/build.yml

+4-15
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ name: Build & Deploy
22

33
on:
44
push:
5+
pull_request:
56
workflow_dispatch:
67

78
env:
@@ -16,6 +17,8 @@ jobs:
1617
steps:
1718
- name: Check out repository
1819
uses: actions/checkout@v4
20+
with:
21+
submodules: "recursive" # Ensures submodules are checked out
1922

2023
- name: Set up Node.js
2124
uses: actions/setup-node@v4
@@ -28,31 +31,17 @@ jobs:
2831
yarn build
2932
echo -n $(echo "${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}" | cut -c1-7) > static/commit.txt
3033
31-
- name: Check Cloudflare API Token
32-
id: check_token
33-
run: |
34-
if [[ -z "${{ secrets.CLOUDFLARE_API_TOKEN }}" ]]; then
35-
echo "Cloudflare API token is not set. Skipping deployment."
36-
echo "skip=true" >> $GITHUB_ENV
37-
else
38-
echo "skip=false" >> $GITHUB_ENV
39-
fi
40-
shell: bash
41-
4234
- name: Deploy to Cloudflare
4335
if: env.skip != 'true'
4436
uses: ubiquity/cloudflare-deploy-action@main
4537
with:
46-
cloudflare_api_token: ${{ secrets.CLOUDFLARE_API_TOKEN }}
38+
cloudflare_api_token: JWo5dPsoyohH5PRu89-RktjCvRN0-ODC6CC9ZBqF # Specifically scoped for public contributors to automatically deploy to our team Cloudflare account
4739
repository: ${{ github.repository }}
4840
production_branch: ${{ github.event.repository.default_branch }}
4941
output_directory: "static"
5042
current_branch: ${{ github.ref_name }}
5143
pull_request_number: ${{ github.event.pull_request.number }}
5244
commit_sha: ${{ github.sha }}
53-
app_private_key: ${{ secrets.APP_PRIVATE_KEY }}
54-
app_id: ${{ secrets.APP_ID }}
55-
app_installation_id: ${{ secrets.APP_INSTALLATION_ID }}
5645
# Add any environment variables you need to pass along here
5746
# SUPABASE_URL: ${{ secrets.SUPABASE_URL }}
5847
# SUPABASE_KEY: ${{ secrets.SUPABASE_KEY }}

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@
99
path = lib/ubiquibot
1010
url = https://github.com/ubiquity/ubiquibot
1111
shallow = true
12+
[submodule "lib/chainlist"]
13+
path = lib/chainlist
14+
url = https://github.com/DefiLlama/chainlist.git

build/esbuild-build.ts

+19-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import extraRpcs from "../lib/chainlist/constants/extraRpcs";
12
import esbuild from "esbuild";
23
import * as dotenv from "dotenv";
34
const typescriptEntries = [
@@ -9,6 +10,15 @@ const typescriptEntries = [
910
const cssEntries = ["static/styles/rewards/rewards.css", "static/styles/audit-report/audit.css", "static/styles/onboarding/onboarding.css"];
1011
export const entries = [...typescriptEntries, ...cssEntries];
1112

13+
const allNetworkUrls: Record<string, string[]> = {};
14+
// 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.
15+
16+
Object.keys(extraRpcs).forEach((networkId) => {
17+
const officialUrls = extraRpcs[networkId].rpcs.filter((rpc) => typeof rpc === "string");
18+
const extraUrls: string[] = extraRpcs[networkId].rpcs.filter((rpc) => rpc.url !== undefined).map((rpc) => rpc.url);
19+
allNetworkUrls[networkId] = [...officialUrls, ...extraUrls];
20+
});
21+
1222
export const esBuildContext: esbuild.BuildOptions = {
1323
sourcemap: true,
1424
entryPoints: entries,
@@ -23,7 +33,7 @@ export const esBuildContext: esbuild.BuildOptions = {
2333
".svg": "dataurl",
2434
},
2535
outdir: "static/out",
26-
define: createEnvDefines(["SUPABASE_URL", "SUPABASE_ANON_KEY"]),
36+
define: createEnvDefines(["SUPABASE_URL", "SUPABASE_ANON_KEY"], { allNetworkUrls }),
2737
};
2838

2939
esbuild
@@ -36,16 +46,22 @@ esbuild
3646
process.exit(1);
3747
});
3848

39-
function createEnvDefines(variableNames: string[]): Record<string, string> {
49+
function createEnvDefines(envVarNames: string[], extras: Record<string, unknown>): Record<string, string> {
4050
const defines: Record<string, string> = {};
4151
dotenv.config();
42-
for (const name of variableNames) {
52+
for (const name of envVarNames) {
4353
const envVar = process.env[name];
4454
if (envVar !== undefined) {
4555
defines[name] = JSON.stringify(envVar);
4656
} else {
4757
throw new Error(`Missing environment variable: ${name}`);
4858
}
4959
}
60+
for (const key in extras) {
61+
if (Object.prototype.hasOwnProperty.call(extras, key)) {
62+
defines[key] = JSON.stringify(extras[key]);
63+
}
64+
}
65+
defines["extraRpcs"] = JSON.stringify(extraRpcs);
5066
return defines;
5167
}

lib/chainlist

Submodule chainlist added at 8059283

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"format:lint": "eslint --fix .",
2121
"format:prettier": "prettier --write .",
2222
"format:cspell": "cspell **/*",
23-
"prepare": "husky install"
23+
"prepare": "husky install",
24+
"postinstall": "git submodule update --init --recursive"
2425
},
2526
"keywords": [
2627
"typescript",

static/scripts/rewards/constants.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1+
// type RPC = { url: string; tracking?: string; trackingDetails?: string };
2+
// type Network = { name?: string; rpcs: RPC[]; websiteDead?: boolean; rpcWorking?: boolean };
3+
// type Networks = { [key: string]: Network };
4+
5+
declare const extraRpcs: Record<string, string[]>; // @DEV: passed in at build time check build/esbuild-build.ts
6+
17
export enum NetworkIds {
28
Mainnet = 1,
39
Goerli = 5,
410
Gnosis = 100,
511
}
12+
console.trace({ extraRpcs });
613

714
export enum Tokens {
815
DAI = "0x6b175474e89094c44da98b954eedeac495271d0f",
@@ -36,9 +43,9 @@ export const networkExplorers: Record<number, string> = {
3643
};
3744

3845
export const networkRpcs: Record<number, string[]> = {
39-
[NetworkIds.Mainnet]: ["https://rpc-pay.ubq.fi/v1/mainnet"],
40-
[NetworkIds.Goerli]: ["https://rpc-pay.ubq.fi/v1/goerli"],
41-
[NetworkIds.Gnosis]: ["https://rpc.gnosischain.com"],
46+
[NetworkIds.Mainnet]: ["https://rpc-pay.ubq.fi/v1/mainnet", ...(extraRpcs[NetworkIds.Mainnet] || [])],
47+
[NetworkIds.Goerli]: ["https://rpc-pay.ubq.fi/v1/goerli", ...(extraRpcs[NetworkIds.Goerli] || [])],
48+
[NetworkIds.Gnosis]: [...(extraRpcs[NetworkIds.Gnosis] || [])],
4249
};
4350

4451
export const permit2Address = "0x000000000022D473030F116dDEE9F6B43aC78BA3";

static/scripts/rewards/web3/wallet.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ export async function handleNetwork(desiredNetworkId: number) {
3333
invalidateButton.disabled = true;
3434
}
3535

36-
const chainIdHex = String(web3provider.network.chainId);
37-
const currentNetworkId = parseInt(chainIdHex, 16);
36+
const network = await web3provider.getNetwork();
37+
const currentNetworkId = network.chainId;
3838

3939
// watch for network changes
4040
window.ethereum.on("chainChanged", <T>(newNetworkId: T | string) => handleIfOnCorrectNetwork(parseInt(newNetworkId as string, 16), desiredNetworkId));

tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"include": ["src", "lib/chainlist/constants/extraRpcs.js", "static", "build", "scripts/typescript", "globals.d.ts"],
23
"compilerOptions": {
34
/* Visit https://aka.ms/tsconfig to read more about this file */
45
/* Projects */

0 commit comments

Comments
 (0)