-
Notifications
You must be signed in to change notification settings - Fork 0
/
wagmi.config.ts
119 lines (110 loc) · 4.07 KB
/
wagmi.config.ts
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import "dotenv/config";
import { defineConfig, type Plugin } from "@wagmi/cli";
import { foundry, react } from "@wagmi/cli/plugins";
import { execSync } from "node:child_process";
import { readFileSync } from "node:fs";
import { type Abi, getAddress } from "viem";
import { optimism, optimismSepolia } from "viem/chains";
const easBuild = process.env.EAS_BUILD_RUNNER === "eas-build";
const chainId = Number(process.env.CHAIN_ID ?? String(easBuild ? optimism.id : optimismSepolia.id));
if (easBuild) {
execSync(
"export FOUNDRY_DIR=${FOUNDRY_DIR-$HOME/workingdir} && curl -L https://foundry.paradigm.xyz | bash || true && foundryup",
);
}
const auditor = loadDeployment("Auditor");
const marketUSDC = loadDeployment("MarketUSDC");
const marketWETH = loadDeployment("MarketWETH");
const previewer = loadDeployment("Previewer");
const ratePreviewer = loadDeployment("RatePreviewer");
const usdc = loadDeployment("USDC");
const weth = loadDeployment("WETH");
const [exaPlugin, factory] = loadBroadcast("Deploy").transactions;
const [issuerChecker] = loadBroadcast("IssuerChecker").transactions;
const [installmentsPreviewer] = loadBroadcast("InstallmentsPreviewer").transactions;
if (!exaPlugin || !factory || !issuerChecker || !installmentsPreviewer) throw new Error("missing contracts");
export default defineConfig([
{
out: "src/generated/contracts.ts",
contracts: [
{ name: "Auditor", abi: auditor.abi },
{ name: "Market", abi: marketWETH.abi },
{ name: "Previewer", abi: previewer.abi },
{ name: "RatePreviewer", abi: ratePreviewer.abi },
],
plugins: [
foundry({
project: "contracts",
include: ["ExaPlugin.sol/ExaPlugin.json", "UpgradeableModularAccount.sol/UpgradeableModularAccount.json"],
}),
react(),
],
},
{
out: "common/generated/chain.ts",
plugins: [
addresses({
auditor: auditor.address,
exaAccountFactory: factory.contractAddress,
exaPlugin: exaPlugin.contractAddress,
installmentsPreviewer: installmentsPreviewer.contractAddress,
marketUSDC: marketUSDC.address,
marketWETH: marketWETH.address,
previewer: previewer.address,
ratePreviewer: ratePreviewer.address,
usdc: usdc.address,
weth: weth.address,
}),
foundry({
project: "contracts",
include: [
"ExaAccountFactory.sol/ExaAccountFactory.json",
"ExaPlugin.sol/ExaPlugin.json",
"InstallmentsPreviewer.sol/InstallmentsPreviewer.json",
"UpgradeableModularAccount.sol/UpgradeableModularAccount.json",
],
}),
chain(),
],
},
{
out: "server/generated/contracts.ts",
contracts: [
{ name: "Auditor", abi: auditor.abi },
{ name: "Market", abi: marketWETH.abi },
{ name: "Previewer", abi: previewer.abi },
],
plugins: [
addresses({ issuerChecker: issuerChecker.contractAddress }),
foundry({ project: "contracts", include: ["IssuerChecker.sol/IssuerChecker.json"] }),
],
},
]);
function addresses(contracts: Record<string, string>): Plugin {
return {
name: "Addresses",
run: () => ({
content: `${Object.entries(contracts)
.map(([key, value]) => `export const ${key}Address = "${getAddress(value)}" as const`)
.join("\n")}\n`,
}),
};
}
function chain(): Plugin {
const importName = { [optimism.id]: "optimism", [optimismSepolia.id]: "optimismSepolia" }[chainId];
if (!importName) throw new Error("unknown chain");
return { name: "Chain", run: () => ({ content: `export { ${importName} as default } from "@alchemy/aa-core"` }) };
}
function loadDeployment(contract: string) {
return JSON.parse(
readFileSync(
`node_modules/@exactly/protocol/deployments/${chainId === optimism.id ? "optimism" : "op-sepolia"}/${contract}.json`,
"utf8",
),
) as { address: string; abi: Abi };
}
function loadBroadcast(script: string) {
return JSON.parse(
readFileSync(`node_modules/@exactly/plugin/broadcast/${script}.s.sol/${chainId}/run-latest.json`, "utf8"),
) as { transactions: { contractAddress: string }[] };
}