-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetSupplyCap.ts
124 lines (107 loc) · 3.13 KB
/
setSupplyCap.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
120
121
122
123
124
import {
createPublicClient,
createWalletClient,
http,
Address,
parseEther,
encodeFunctionData,
parseUnits,
} from 'viem';
import { privateKeyToAccount } from 'viem/accounts';
import { baseSepolia } from 'viem/chains';
import { RiskEngineAbi } from '../abis/RiskEngineAbi';
import dotenv from 'dotenv';
import { resolve } from 'path';
import { validateEnvKeys } from './utils/validateEnvKeys';
// Load environment variables
dotenv.config({ path: resolve(process.cwd(), '.env.local') });
validateEnvKeys([
'ADMIN_PRIVATE_KEY',
'RISK_ENGINE_ADDRESS',
'PSTETH_ADDRESS',
'PUSDC_ADDRESS',
'PWETH_ADDRESS',
]);
// Configuration
const config = {
adminKey: process.env.ADMIN_PRIVATE_KEY!,
riskEngine: process.env.RISK_ENGINE_ADDRESS as Address,
pTokens: {
pSTETH: process.env.PSTETH_ADDRESS as Address,
pUSDC: process.env.PUSDC_ADDRESS as Address,
pWETH: process.env.PWETH_ADDRESS as Address,
},
};
const setSupplyCaps = async (
pTokenAddresses: Address[],
newSupplyCaps: bigint[]
) => {
// Validate input arrays
if (pTokenAddresses.length !== newSupplyCaps.length) {
throw new Error(
'Arrays length mismatch: pTokens and supply caps must match'
);
}
// Create admin account
const adminAccount = privateKeyToAccount(config.adminKey as `0x${string}`);
// Initialize clients
const publicClient = createPublicClient({
chain: baseSepolia,
transport: http(),
});
const walletClient = createWalletClient({
chain: baseSepolia,
transport: http(),
});
try {
console.log('Setting new supply caps...');
// Encode and send transaction
const hash = await walletClient.sendTransaction({
account: adminAccount,
to: config.riskEngine,
data: encodeFunctionData({
abi: RiskEngineAbi,
functionName: 'setMarketSupplyCaps',
args: [pTokenAddresses, newSupplyCaps],
}),
});
// Wait for transaction confirmation
await publicClient.waitForTransactionReceipt({ hash });
console.log('Transaction successful!');
console.log('Transaction hash:', hash);
// Log new supply caps for verification
console.log('\nVerifying new supply caps:');
for (let i = 0; i < pTokenAddresses.length; i++) {
const newCap = await publicClient.readContract({
address: config.riskEngine,
abi: RiskEngineAbi,
functionName: 'supplyCap',
args: [pTokenAddresses[i] as Address],
});
console.log(`${pTokenAddresses[i]}: ${newCap.toString()}`);
}
} catch (error) {
console.error('Error setting supply caps:', error);
throw error;
}
};
// Example usage
const updateSupplyCaps = async () => {
// Example supply caps (18 decimals for ETH/stETH, 6 for USDC)
const newCaps = [
parseEther('1000'), // 1000 stETH
parseUnits('1000000', 6), // 1_00_000 USDC
parseEther('1000'), // 1000 WETH
];
const pTokenAddresses = [
config.pTokens.pSTETH,
config.pTokens.pUSDC,
config.pTokens.pWETH,
];
await setSupplyCaps(pTokenAddresses, newCaps);
};
// Run the script
updateSupplyCaps().catch(error => {
console.error('Failed to update supply caps:', error);
process.exit(1);
});