Skip to content

Commit 93c98ed

Browse files
authored
Merge pull request #462 from api3dao/main
Initiate release
2 parents af5dfb8 + 4e1f6ed commit 93c98ed

11 files changed

+108
-14
lines changed

.github/workflows/validate-verify.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,12 @@ jobs:
3131

3232
- name: Build
3333
run: pnpm build
34-
35-
- name: Check local metadata
36-
run: pnpm check
34+
id: build
3735

3836
- name: Validate deployments
3937
run: pnpm validate-deployments
40-
if: always()
38+
if: steps.build.outcome == 'success'
4139

4240
- name: Verify deployments
4341
run: pnpm verify-deployments
44-
if: always()
42+
if: steps.build.outcome == 'success'

data/dapps/dtrinity.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"aliases": {
3-
"dtrinity": { "chains": ["fraxtal"], "title": "dTRINITY" }
3+
"dtrinity": { "chains": ["fraxtal", "sonic"], "title": "dTRINITY" }
44
},
55
"homepageUrl": "https://dtrinity.org/"
66
}

data/dapps/nerite.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"aliases": {
3+
"nerite": { "chains": ["arbitrum"], "title": "Nerite" }
4+
},
5+
"homepageUrl": "https://www.nerite.org/"
6+
}

data/dapps/segment-finance.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"aliases": {
3+
"segment-finance": { "chains": ["bob"], "title": "Segment Finance" }
4+
},
5+
"homepageUrl": "https://www.segment.finance/"
6+
}

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@
3232
"api3-contracts": "./dist/bin/cli.js"
3333
},
3434
"scripts": {
35-
"build": "pnpm build:hardhat && pnpm generate && pnpm check && tsc -p tsconfig.build.json",
35+
"build": "pnpm check && pnpm build:hardhat && pnpm generate && tsc -p tsconfig.build.json",
3636
"build:hardhat": "hardhat --config hardhat.build.config.ts compile",
37-
"check": "pnpm check:chains && pnpm check:deployment-addresses && pnpm check:deployment-config && pnpm check:chain-support-order",
37+
"check": "pnpm check:chains && pnpm check:dapps && pnpm check:deployment-addresses && pnpm check:deployment-config && pnpm check:chain-support-order",
3838
"check:chains": "ts-node scripts/check-chains.ts",
39+
"check:dapps": "ts-node scripts/check-dapps.ts",
3940
"check:deployment-addresses": "ts-node scripts/check-deployment-addresses.ts",
4041
"check:deployment-config": "ts-node scripts/check-deployment-config.ts",
4142
"check:chain-support-order": "ts-node scripts/check-chain-support-order.ts",

scripts/check-chains.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import fs from 'node:fs';
22
import path from 'node:path';
33

4-
import { CHAINS, chainSchema } from '../src';
4+
import { CHAINS } from '../src/generated/chains';
5+
import { chainSchema } from '../src/types';
56
import { deepEqual } from '../src/utils/deep-equal';
67

78
const INPUT_DIR = path.join('data', 'chains');

scripts/check-dapps.ts

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import fs from 'node:fs';
2+
import path from 'node:path';
3+
4+
import { DAPPS } from '../src/generated/dapps';
5+
import { dappSchema, type Dapp } from '../src/types';
6+
import { deepEqual } from '../src/utils/deep-equal';
7+
import { toLowerKebabCase } from '../src/utils/strings';
8+
9+
const INPUT_DIR = path.join('data', 'dapps');
10+
11+
const fileNames = fs.readdirSync(INPUT_DIR);
12+
const jsonFiles = fileNames.filter((fileName) => fileName.endsWith('.json'));
13+
14+
const jsonDapps: Dapp[] = jsonFiles.map((filePath: string) => {
15+
const fullPath = path.join(INPUT_DIR, filePath);
16+
const fileContentRaw = fs.readFileSync(fullPath, 'utf8');
17+
return JSON.parse(fileContentRaw);
18+
});
19+
20+
const logs: string[] = [];
21+
22+
// Validation: Ensure that each JSON file is represented in the DAPPS array
23+
if (DAPPS.length !== jsonDapps.length) {
24+
logs.push(
25+
'Generated dapps differs in length to the number of JSON files',
26+
`Generated DAPPS length = ${DAPPS.length}. Expected ${jsonDapps.length} dApps\n`
27+
);
28+
}
29+
30+
// Validation: Ensure that each JSON file is named as a prefix of one of the dApp's titles
31+
jsonFiles.forEach((filePath: string, index: number) => {
32+
const dapp: Dapp = jsonDapps[index]!;
33+
const uniqueDappTitles = [
34+
...new Set(Object.values(dapp.aliases).map((dappAliasValue) => toLowerKebabCase(dappAliasValue.title))),
35+
];
36+
if (!uniqueDappTitles.some((uniqueDappTitle) => uniqueDappTitle.startsWith(filePath.replace('.json', '')))) {
37+
logs.push(
38+
'JSON file name must be the prefix of a dApp title',
39+
`Current value: ${filePath}. Expected to be prefix of: ${uniqueDappTitles.join('/')}\n`
40+
);
41+
}
42+
});
43+
44+
jsonDapps.forEach((dapp: Dapp, index: number) => {
45+
const res = dappSchema.safeParse(dapp);
46+
// Validation: Ensure each JSON file content conforms to the required schema
47+
if (!res.success) {
48+
const errors = res.error.issues.map((issue) => {
49+
return ` path: '${issue.path.join('.')}' => '${issue.message}' `;
50+
});
51+
logs.push(`dApp '${Object.keys(dapp.aliases)}' contains the following errors:\n${errors.join('\n')}\n`);
52+
}
53+
54+
// Validation: Ensure that the latest JSON content is represented in each Dapp object
55+
const existingDapp = DAPPS[index];
56+
if (!deepEqual(dapp, existingDapp)) {
57+
logs.push(`dApp '${Object.keys(dapp.aliases)}' differs to the currently generated Dapp object in DAPPS\n`);
58+
}
59+
});
60+
61+
if (logs.length > 0) {
62+
// eslint-disable-next-line no-console
63+
logs.forEach((log) => console.error(log));
64+
process.exit(1);
65+
}
66+
67+
process.exit(0);

scripts/check-deployment-config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
chainsSupportedByMarket,
55
chainsSupportedByOevAuctions,
66
} from '../data/chain-support.json';
7-
import { CHAINS } from '../src/index';
7+
import { CHAINS } from '../src/generated/chains';
88

99
function main() {
1010
const chainAliases = new Set(CHAINS.map((chain) => chain.alias));

scripts/src/deployment-addresses.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import * as fs from 'node:fs';
22
import { join } from 'node:path';
33

44
import type { AddressLike } from 'ethers';
5-
import { config } from 'hardhat';
65

76
import {
87
chainsSupportedByManagerMultisig,
98
chainsSupportedByDapis,
109
chainsSupportedByMarket,
1110
chainsSupportedByOevAuctions,
1211
} from '../../data/chain-support.json';
12+
import { CHAINS } from '../../src/generated/chains';
1313

1414
function getDeploymentAddresses() {
1515
const references: Record<string, Record<string, AddressLike>> = {
@@ -31,7 +31,7 @@ function getDeploymentAddresses() {
3131
]);
3232

3333
for (const network of networks) {
34-
const chainId = config.networks[network]!.chainId!;
34+
const chainId = CHAINS.find((chain) => chain.alias === network)?.id;
3535
const contractNames = [
3636
...(chainsSupportedByManagerMultisig.includes(network) ? ['GnosisSafeWithoutProxy', 'OwnableCallForwarder'] : []),
3737
...(chainsSupportedByDapis.includes(network)
@@ -42,7 +42,7 @@ function getDeploymentAddresses() {
4242
];
4343
for (const contractName of contractNames) {
4444
const deployment = JSON.parse(fs.readFileSync(join('deployments', network, `${contractName}.json`), 'utf8'));
45-
references[contractName] = { ...references[contractName], [chainId]: deployment.address };
45+
references[contractName] = { ...references[contractName], [chainId!]: deployment.address };
4646
}
4747
}
4848
return `${JSON.stringify(references, null, 2)}\n`;

src/generated/dapps.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export const DAPPS: Dapp[] = [
2020
},
2121
homepageUrl: 'https://compound.finance/',
2222
},
23-
{ aliases: { dtrinity: { chains: ['fraxtal'], title: 'dTRINITY' } }, homepageUrl: 'https://dtrinity.org/' },
23+
{ aliases: { dtrinity: { chains: ['fraxtal', 'sonic'], title: 'dTRINITY' } }, homepageUrl: 'https://dtrinity.org/' },
2424
{ aliases: { elara: { chains: ['zircuit'], title: 'Elara' } }, homepageUrl: 'https://app.elara.finance/' },
2525
{ aliases: { enclabs: { chains: ['sonic'], title: 'Enclabs' } }, homepageUrl: 'https://www.enclabs.finance/' },
2626
{ aliases: { hana: { chains: ['taiko'], title: 'Hana Finance' } }, homepageUrl: 'https://www.hana.finance/' },
@@ -32,8 +32,13 @@ export const DAPPS: Dapp[] = [
3232
{ aliases: { lendle: { chains: ['mantle'], title: 'Lendle' } }, homepageUrl: 'https://www.lendle.xyz/' },
3333
{ aliases: { 'mach-finance': { chains: ['sonic'], title: 'MachFi' } }, homepageUrl: 'https://www.machfi.xyz/' },
3434
{ aliases: { moonwell: { chains: ['moonbeam'], title: 'Moonwell' } }, homepageUrl: 'https://moonwell.fi/' },
35+
{ aliases: { nerite: { chains: ['arbitrum'], title: 'Nerite' } }, homepageUrl: 'https://www.nerite.org/' },
3536
{ aliases: { omega: { chains: ['mantle'], title: 'Omega' } }, homepageUrl: 'https://www.omega.xyz/' },
3637
{ aliases: { orbit: { chains: ['blast'], title: 'Orbit Protocol' } }, homepageUrl: 'https://orbitlending.io/' },
38+
{
39+
aliases: { 'segment-finance': { chains: ['bob'], title: 'Segment Finance' } },
40+
homepageUrl: 'https://www.segment.finance/',
41+
},
3742
{
3843
aliases: {
3944
'silo-finance-v1-rdnt': {

src/utils/strings.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,13 @@ export function toUpperSnakeCase(input: string): string {
77
.join('_')
88
.toUpperCase();
99
}
10+
11+
export function toLowerKebabCase(input: string): string {
12+
return input
13+
.replaceAll(/[^\d\sA-Za-z]+/g, ' ') // replace each non-alphanumeric character with a space
14+
.replaceAll(/\s+/g, ' ') // replace consecutive spaces with a single space
15+
.trim()
16+
.split(' ')
17+
.join('-')
18+
.toLowerCase();
19+
}

0 commit comments

Comments
 (0)