-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvalidate-entity.ts
More file actions
76 lines (64 loc) · 2.05 KB
/
validate-entity.ts
File metadata and controls
76 lines (64 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import { Address } from "viem";
import { createClient, getChain } from "./blockchain";
import * as github from "./github";
import * as messages from "./messages";
import { Entity, EntityType } from "./validate-fs";
type EntityMeta = {
contract: string;
label: string;
};
const isEntityAbi = [
{
inputs: [{ internalType: "address", name: "entity_", type: "address" }],
name: "isEntity",
outputs: [{ internalType: "bool", name: "", type: "bool" }],
stateMutability: "view",
type: "function",
},
] as const;
const entityMetaMap: Partial<Record<EntityType, EntityMeta>> = {
vaults: {
label: "Vault",
contract: github.getInput("vault-registry", { required: true }),
},
networks: {
label: "Network",
contract: github.getInput("network-registry", { required: true }),
},
operators: {
label: "Operator",
contract: github.getInput("operator-registry", { required: true }),
},
adapters: {
label: "Adapter",
contract: github.getInput("adapter-registry", { required: true }),
},
};
export const validateEntity = async ({ entityType, entityId }: Entity) => {
const entityAddress = entityId as Address;
const entityMeta = entityMetaMap[entityType];
if (!entityMeta) {
return;
}
const chain = getChain();
const client = createClient();
const isEntity = await client.readContract({
address: entityMeta.contract as Address,
abi: isEntityAbi,
functionName: "isEntity",
args: [entityAddress],
});
if (!isEntity) {
await github.addComment(
messages.notRegisteredEntity(
entityMeta.label,
entityAddress,
chain.name,
entityMeta.contract,
),
);
throw new Error(
`${entityMeta.label} \`${entityAddress}\` is not registered in ${entityMeta.label.toLowerCase()} registry on ${chain.name} network (registry address: \`${entityMeta.contract}\`)`,
);
}
};