-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.js
More file actions
164 lines (139 loc) · 5.64 KB
/
build.js
File metadata and controls
164 lines (139 loc) · 5.64 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
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
require("dotenv").config();
const fs = require("fs");
// Network-specific contract addresses
const CONTRACT_ADDRESSES = {
mainnet: {
chainId: 1,
uniswapV3Factory: "0x1F98431c8aD98523631AE4a59f267346ea31F984",
usdStablecoin: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC
weth: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
startBlock: "22931060"
},
sepolia: {
chainId: 11155111,
uniswapV3Factory: "0x0227628f3F023bb0B980b67D528571c95c6DaC1c",
usdStablecoin: "0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238", // USDC
weth: "0xfFf9976782d46CC05630D1f6eBAb18b2324d6B14",
startBlock: "8619003"
},
hyperevm: {
chainId: 999,
uniswapV3Factory: "0xB1c0fa0B789320044A6F623cFe5eBda9562602E3",
usdStablecoin: "0xB8CE59FC3717ada4C02eaDF9682A9e934F625ebb", // USDT0
weth: "0x5555555555555555555555555555555555555555", // WHYPE (wrapped HYPE)
startBlock: "17597148"
},
"hyperevm-testnet": {
chainId: 998,
uniswapV3Factory: "0x22B0768972bB7f1F5ea7a8740BB8f94b32483826",
usdStablecoin: "0xd9CBEC81df392A88AEff575E962d149d57F4d6bc", // USDC
weth: "0xADcb2f358Eae6492F61A5F87eb8893d09391d160", // WHYPE (wrapped HYPE)
startBlock: "31893543"
},
"megaeth-testnet-v2": {
chainId: 6342,
uniswapV3Factory: "0x94996d371622304F2eB85df1eb7f328F7B317C3E",
usdStablecoin: "0x56C00C15453DcbE86faBa6147cf02E2C64c74959", // USDC
weth: "0x4200000000000000000000000000000000000006",
startBlock: "8354242"
},
"megaeth-mainnet": {
chainId: 4326,
uniswapV3Factory: "0x68b34591f662508076927803c567Cc8006988a09",
usdStablecoin: "0xFAfDdbb3FC7688494971a79cc65DCa3EF82079E7", // USDM
weth: "0x4200000000000000000000000000000000000006",
startBlock: "7419443"
},
localhost: {
chainId: 31337,
uniswapV3Factory: process.env.UNISWAP_V3_FACTORY_ADDRESS,
usdStablecoin: process.env.USDC_ADDRESS,
weth: process.env.WETH_ADDRESS,
startBlock: "0"
}
};
// Networks that use the old Mint event (without portionLockTime parameter)
// All other networks use the new Mint event with portionLockTime
const LEGACY_MINT_NETWORKS = ["mainnet", "sepolia", "hyperevm", "hyperevm-testnet"];
// Mint event signatures
const MINT_EVENT_OLD = "Mint(indexed uint48,indexed address,bool,uint144,uint144,uint144,uint256)";
const MINT_EVENT_NEW = "Mint(indexed uint48,indexed address,bool,uint144,uint144,uint144,uint256,uint8)";
function generateSubgraphYaml() {
const network = process.env.NETWORK || "localhost";
const addresses = CONTRACT_ADDRESSES[network];
if (!addresses) {
throw new Error(`Unsupported network: ${network}`);
}
// Determine which Mint event signature to use based on network
const mintEvent = LEGACY_MINT_NETWORKS.includes(network) ? MINT_EVENT_OLD : MINT_EVENT_NEW;
const subgraphTemplate = fs.readFileSync("subgraph.template.yaml", "utf-8");
const replaced = subgraphTemplate
.replaceAll("{{VAULT_ADDRESS}}", process.env.VAULT_ADDRESS)
.replaceAll("{{SIR_ADDRESS}}", process.env.SIR_ADDRESS)
.replaceAll("{{NETWORK}}", network)
.replaceAll("{{START_BLOCK}}", addresses.startBlock)
.replaceAll("{{MINT_EVENT}}", mintEvent);
fs.writeFileSync("subgraph.yaml", replaced);
console.log(`✅ Generated subgraph.yaml for ${network} network`);
console.log(` Using Mint event: ${mintEvent}`);
}
function generateContractsFile() {
const network = process.env.NETWORK || "localhost";
const addresses = CONTRACT_ADDRESSES[network];
if (!addresses) {
throw new Error(`Unsupported network: ${network}`);
}
const contractsContent = `// Auto-generated contract addresses for ${network} network
// Do not edit this file manually - it's generated by build.js
export const vaultAddress = "${process.env.VAULT_ADDRESS}";
export const sirAddress = "${process.env.SIR_ADDRESS}";
export const oracleAddress = "${process.env.ORACLE_ADDRESS}";
// Uniswap V3 Factory (same address on all networks)
export const uniswapV3FactoryAddress = "${addresses.uniswapV3Factory}";
// Network-specific token addresses
export const usdStablecoinAddress = "${addresses.usdStablecoin}";
export const wethAddress = "${addresses.weth}";
`;
fs.writeFileSync("src/contracts.ts", contractsContent);
console.log(`✅ Generated src/contracts.ts for ${network} network`);
}
function generateVaultAbi() {
const network = process.env.NETWORK || "localhost";
const isLegacy = LEGACY_MINT_NETWORKS.includes(network);
// Read the base Vault ABI
const vaultAbi = JSON.parse(fs.readFileSync("abis/VaultBase.json", "utf-8"));
// Find the Mint event and update it based on network
const mintEventIndex = vaultAbi.findIndex(
(item) => item.type === "event" && item.name === "Mint"
);
if (mintEventIndex !== -1 && !isLegacy) {
// Add portionLockTime parameter for new networks
vaultAbi[mintEventIndex].inputs.push({
name: "portionLockTime",
type: "uint8",
indexed: false,
internalType: "uint8"
});
}
fs.writeFileSync("abis/Vault.json", JSON.stringify(vaultAbi, null, 2));
console.log(`✅ Generated abis/Vault.json for ${network} network (${isLegacy ? "legacy" : "with portionLockTime"})`);
}
function main() {
try {
// Validate required environment variables
const requiredVars = ["VAULT_ADDRESS", "SIR_ADDRESS", "ORACLE_ADDRESS"];
for (const varName of requiredVars) {
if (!process.env[varName]) {
throw new Error(`Missing required environment variable: ${varName}`);
}
}
generateVaultAbi();
generateSubgraphYaml();
generateContractsFile();
console.log("🎉 Build completed successfully!");
} catch (error) {
console.error("❌ Build failed:", error.message);
process.exit(1);
}
}
main();