-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathswitch-rewards.mjs
More file actions
63 lines (50 loc) · 1.95 KB
/
switch-rewards.mjs
File metadata and controls
63 lines (50 loc) · 1.95 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
import { createWalletClient, createPublicClient, http, parseAbi, getAddress } from 'viem';
import { base } from 'viem/chains';
import { privateKeyToAccount } from 'viem/accounts';
const LOCKER = '0x63D2DfEA64b3433F4071A98665bcD7Ca14d93496';
const TOKEN = '0x98c51C8E958ccCD37F798b2B9332d148E2c05D57';
const REWARD_INDEX = 0n;
const NEW_FEE_PREF = 1; // 0=Both, 1=Paired (WETH), 2=Clanker
const abi = parseAbi([
'function updateFeePreference(address token, uint256 rewardIndex, uint8 newFeePreference)',
'function feePreferences(address token, uint256 index) view returns (uint8)',
]);
const key = process.env.PRIVATE_KEY;
if (!key) {
console.error('Missing PRIVATE_KEY env var');
process.exit(1);
}
const account = privateKeyToAccount(key);
const transport = http('https://mainnet.base.org');
const publicClient = createPublicClient({ chain: base, transport });
const walletClient = createWalletClient({ account, chain: base, transport });
// Pre-flight: check current fee preference
const currentPref = await publicClient.readContract({
address: LOCKER,
abi,
functionName: 'feePreferences',
args: [TOKEN, REWARD_INDEX],
});
const labels = ['Both', 'Paired (WETH)', 'Clanker'];
console.log(`Current fee preference: ${labels[currentPref]} (${currentPref})`);
if (currentPref === NEW_FEE_PREF) {
console.log('Already set to Paired (WETH). Nothing to do.');
process.exit(0);
}
// Send the transaction
console.log(`Switching to: ${labels[NEW_FEE_PREF]}...`);
const hash = await walletClient.writeContract({
address: LOCKER,
abi,
functionName: 'updateFeePreference',
args: [TOKEN, REWARD_INDEX, NEW_FEE_PREF],
});
console.log(`tx submitted: ${hash}`);
console.log('Waiting for confirmation...');
const receipt = await publicClient.waitForTransactionReceipt({ hash });
if (receipt.status === 'success') {
console.log(`Confirmed in block ${receipt.blockNumber}. Fees now collected in WETH.`);
} else {
console.error('Transaction reverted.');
process.exit(1);
}