-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpauseAndContinueUSDC.ts
95 lines (80 loc) · 2.6 KB
/
pauseAndContinueUSDC.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
import {
createPublicClient,
createWalletClient,
http,
Address,
encodeFunctionData,
} 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', 'PUSDC_ADDRESS']);
// Configuration
const config = {
adminKey: process.env.ADMIN_PRIVATE_KEY!,
riskEngine: process.env.RISK_ENGINE_ADDRESS as Address,
pUSDC: process.env.PUSDC_ADDRESS as Address,
};
const setUSDCMintPauseState = async (pauseState: boolean) => {
// 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(`${pauseState ? 'Pausing' : 'Resuming'} minting for USDC...`);
// Encode and send transaction
const hash = await walletClient.sendTransaction({
account: adminAccount,
to: config.riskEngine,
data: encodeFunctionData({
abi: RiskEngineAbi,
functionName: 'setMintPaused',
args: [config.pUSDC, pauseState],
}),
});
// Wait for transaction confirmation
await publicClient.waitForTransactionReceipt({ hash });
console.log('Transaction successful!');
console.log('Transaction hash:', hash);
} catch (error) {
console.error(
`Error ${pauseState ? 'pausing' : 'resuming'} USDC minting:`,
error
);
throw error;
}
};
// Example usage - pause USDC minting, wait 1 minute, then resume
const pauseAndResumeUSDCMinting = async () => {
try {
// Pause USDC minting
console.log('Pausing USDC minting...');
await setUSDCMintPauseState(true);
console.log('\nWaiting 1 minute before resuming...');
await new Promise(resolve => setTimeout(resolve, 60000));
// Resume USDC minting
console.log('Resuming USDC minting...');
await setUSDCMintPauseState(false);
console.log('\nCompleted USDC pause and resume cycle!');
} catch (error) {
console.error('Error in USDC pause/resume cycle:', error);
throw error;
}
};
// Run the script
pauseAndResumeUSDCMinting().catch(error => {
console.error('Failed to complete USDC pause/resume cycle:', error);
process.exit(1);
});