Skip to content
This repository was archived by the owner on Aug 26, 2024. It is now read-only.

Commit 30dca11

Browse files
tx logging for multisig
1 parent 6adb73e commit 30dca11

File tree

3 files changed

+235
-109
lines changed

3 files changed

+235
-109
lines changed

chainDeploy/helpers/logging.ts

Lines changed: 87 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,102 @@
1+
import { encodeFunctionData } from "@viem/utils"; // Adjust the import path according to your project structure
12
import { promises as fs } from "fs";
23

4+
interface PrepareAndLogTransactionParams {
5+
contractInstance: any; // Replace `any` with the correct contract type if available
6+
functionName: string;
7+
args: any[];
8+
description: string;
9+
walletClient: any;
10+
inputs: {
11+
internalType: string;
12+
name: string;
13+
type: string;
14+
}[];
15+
}
16+
317
export const logTransaction = (description: string, data: string) => {
418
console.log(`Transaction: ${description}`);
519
console.log(`Data: ${data}`);
620
};
721

822
const transactions: any[] = [];
923

10-
export const addTransaction = (tx: any) => {
24+
export const addTransaction = async (tx: any) => {
1125
transactions.push(tx);
26+
await writeSingleTransactionToFile(tx);
27+
};
28+
29+
const writeSingleTransactionToFile = async (tx: any) => {
30+
const filePath = "./transactions.json";
31+
try {
32+
const fileContent = await fs.readFile(filePath, 'utf8');
33+
const batch = JSON.parse(fileContent);
34+
35+
batch.transactions.push(tx);
36+
37+
await fs.writeFile(filePath, JSON.stringify(batch, null, 2));
38+
console.log(`Transaction added and written to ${filePath}`);
39+
} catch (error) {
40+
if (error.code === 'ENOENT') {
41+
const batch = {
42+
version: "1.0",
43+
chainId: "34443",
44+
createdAt: Math.floor(Date.now() / 1000),
45+
meta: {
46+
name: "Transactions Batch",
47+
description: "",
48+
txBuilderVersion: "1.16.5",
49+
createdFromSafeAddress: "0x8Fba84867Ba458E7c6E2c024D2DE3d0b5C3ea1C2",
50+
createdFromOwnerAddress: "",
51+
checksum: "0x"
52+
},
53+
transactions: [tx]
54+
};
55+
56+
await fs.writeFile(filePath, JSON.stringify(batch, null, 2));
57+
console.log(`Transaction added and file created at ${filePath}`);
58+
} else {
59+
console.error(`Failed to write transaction to ${filePath}`, error);
60+
}
61+
}
1262
};
1363

14-
export const writeTransactionsToFile = async () => {
15-
const batch = {
16-
version: "1.0",
17-
chainId: "34443",
18-
createdAt: Math.floor(Date.now() / 1000),
19-
meta: {
20-
name: "Transactions Batch",
21-
description: "",
22-
txBuilderVersion: "1.16.5",
23-
createdFromSafeAddress: "0x8Fba84867Ba458E7c6E2c024D2DE3d0b5C3ea1C2",
24-
createdFromOwnerAddress: "",
25-
checksum: "0x"
64+
export const prepareAndLogTransaction = async ({
65+
contractInstance,
66+
functionName,
67+
args,
68+
description,
69+
walletClient,
70+
inputs
71+
}: PrepareAndLogTransactionParams) => {
72+
const account = await contractInstance.read.owner();
73+
const to = contractInstance.address;
74+
const data = encodeFunctionData({
75+
abi: contractInstance.abi,
76+
functionName,
77+
args
78+
});
79+
80+
const tx = await walletClient.prepareTransactionRequest({
81+
account,
82+
to,
83+
data
84+
});
85+
86+
addTransaction({
87+
to: tx.to,
88+
value: tx.value ? tx.value.toString() : "0",
89+
data: null,
90+
contractMethod: {
91+
inputs,
92+
name: functionName,
93+
payable: false
2694
},
27-
transactions
28-
};
95+
contractInputsValues: args.reduce((acc: any, arg: any, index: number) => {
96+
acc[inputs[index].name] = arg;
97+
return acc;
98+
}, {})
99+
});
29100

30-
const filePath = "./transactions.json";
31-
await fs.writeFile(filePath, JSON.stringify(batch, null, 2));
32-
console.log(`Transactions written to ${filePath}`);
101+
logTransaction(description, data);
33102
};

deploy/03-deploy-ctokens-set-extensions.ts

Lines changed: 103 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { DeployFunction } from "hardhat-deploy/types";
22
import { Address, encodeAbiParameters, encodeFunctionData, Hash, parseAbiParameters, zeroAddress } from "viem";
33

4-
import { logTransaction } from "../chainDeploy/helpers/logging";
4+
import { prepareAndLogTransaction } from "../chainDeploy/helpers/logging";
55

66
const func: DeployFunction = async ({ viem, getNamedAccounts, deployments }) => {
77
const { deployer, multisig } = await getNamedAccounts();
88
const publicClient = await viem.getPublicClient();
9+
const walletClient = await viem.getWalletClient(deployer as Address);
910

1011
const fuseFeeDistributor = await viem.getContractAt(
1112
"FeeDistributor",
@@ -64,14 +65,17 @@ const func: DeployFunction = async ({ viem, getNamedAccounts, deployments }) =>
6465
const erc20DelExtensions = await fuseFeeDistributor.read.getCErc20DelegateExtensions([erc20Del.address as Address]);
6566
if (erc20DelExtensions.length == 0 || erc20DelExtensions[0] != erc20Del.address) {
6667
if ((await fuseFeeDistributor.read.owner()).toLowerCase() !== deployer.toLowerCase()) {
67-
logTransaction(
68-
"Set CErc20Delegate Extensions",
69-
encodeFunctionData({
70-
abi: fuseFeeDistributor.abi,
71-
functionName: "_setCErc20DelegateExtensions",
72-
args: [erc20Del.address as Address, [erc20Del.address as Address, cTokenFirstExtension.address as Address]]
73-
})
74-
);
68+
await prepareAndLogTransaction({
69+
contractInstance: fuseFeeDistributor,
70+
functionName: "_setCErc20DelegateExtensions",
71+
args: [erc20Del.address as Address, [erc20Del.address as Address, cTokenFirstExtension.address as Address]],
72+
description: "Set CErc20Delegate Extensions",
73+
walletClient,
74+
inputs: [
75+
{ internalType: "address", name: "cErc20Delegate", type: "address" },
76+
{ internalType: "address[]", name: "extensions", type: "address[]" }
77+
]
78+
});
7579
} else {
7680
tx = await fuseFeeDistributor.write._setCErc20DelegateExtensions([
7781
erc20Del.address as Address,
@@ -86,14 +90,18 @@ const func: DeployFunction = async ({ viem, getNamedAccounts, deployments }) =>
8690
const [latestCErc20Delegate] = await fuseFeeDistributor.read.latestCErc20Delegate([1]);
8791
if (latestCErc20Delegate === zeroAddress || latestCErc20Delegate !== erc20Del.address) {
8892
if (multisig && (await fuseFeeDistributor.read.owner()).toLowerCase() !== deployer.toLowerCase()) {
89-
logTransaction(
90-
"Set Latest CErc20Delegate",
91-
encodeFunctionData({
92-
abi: fuseFeeDistributor.abi,
93-
functionName: "_setLatestCErc20Delegate",
94-
args: [1, erc20Del.address as Address, becomeImplementationData]
95-
})
96-
);
93+
await prepareAndLogTransaction({
94+
contractInstance: fuseFeeDistributor,
95+
functionName: "_setLatestCErc20Delegate",
96+
args: [1, erc20Del.address as Address, becomeImplementationData],
97+
description: "Set Latest CErc20Delegate",
98+
walletClient,
99+
inputs: [
100+
{ internalType: "uint8", name: "delegateType", type: "uint8" },
101+
{ internalType: "address", name: "newImplementation", type: "address" },
102+
{ internalType: "bytes", name: "becomeImplementationData", type: "bytes" }
103+
]
104+
});
97105
} else {
98106
tx = await fuseFeeDistributor.write._setLatestCErc20Delegate([
99107
1,
@@ -115,17 +123,20 @@ const func: DeployFunction = async ({ viem, getNamedAccounts, deployments }) =>
115123
]);
116124
if (erc20PluginDelExtensions.length == 0 || erc20PluginDelExtensions[0] != erc20PluginDel.address) {
117125
if (multisig && (await fuseFeeDistributor.read.owner()).toLowerCase() !== deployer.toLowerCase()) {
118-
logTransaction(
119-
"Set CErc20PluginDelegate Extensions",
120-
encodeFunctionData({
121-
abi: fuseFeeDistributor.abi,
122-
functionName: "_setCErc20DelegateExtensions",
123-
args: [
124-
erc20PluginDel.address as Address,
125-
[erc20PluginDel.address as Address, cTokenFirstExtension.address as Address]
126-
]
127-
})
128-
);
126+
await prepareAndLogTransaction({
127+
contractInstance: fuseFeeDistributor,
128+
functionName: "_setCErc20DelegateExtensions",
129+
args: [
130+
erc20PluginDel.address as Address,
131+
[erc20PluginDel.address as Address, cTokenFirstExtension.address as Address]
132+
],
133+
description: "Set CErc20PluginDelegate Extensions",
134+
walletClient,
135+
inputs: [
136+
{ internalType: "address", name: "cErc20Delegate", type: "address" },
137+
{ internalType: "address[]", name: "extensions", type: "address[]" }
138+
]
139+
});
129140
} else {
130141
tx = await fuseFeeDistributor.write._setCErc20DelegateExtensions([
131142
erc20PluginDel.address as Address,
@@ -141,14 +152,18 @@ const func: DeployFunction = async ({ viem, getNamedAccounts, deployments }) =>
141152
const [latestCErc20PluginDelegate] = await fuseFeeDistributor.read.latestCErc20Delegate([2]);
142153
if (latestCErc20PluginDelegate === zeroAddress || latestCErc20PluginDelegate !== erc20PluginDel.address) {
143154
if (multisig && (await fuseFeeDistributor.read.owner()).toLowerCase() !== deployer.toLowerCase()) {
144-
logTransaction(
145-
"Set Latest CErc20PluginDelegate",
146-
encodeFunctionData({
147-
abi: fuseFeeDistributor.abi,
148-
functionName: "_setLatestCErc20Delegate",
149-
args: [2, erc20PluginDel.address as Address, becomeImplementationData]
150-
})
151-
);
155+
await prepareAndLogTransaction({
156+
contractInstance: fuseFeeDistributor,
157+
functionName: "_setLatestCErc20Delegate",
158+
args: [2, erc20PluginDel.address as Address, becomeImplementationData],
159+
description: "Set Latest CErc20PluginDelegate",
160+
walletClient,
161+
inputs: [
162+
{ internalType: "uint8", name: "delegateType", type: "uint8" },
163+
{ internalType: "address", name: "newImplementation", type: "address" },
164+
{ internalType: "bytes", name: "becomeImplementationData", type: "bytes" }
165+
]
166+
});
152167
} else {
153168
tx = await fuseFeeDistributor.write._setLatestCErc20Delegate([
154169
2,
@@ -172,17 +187,20 @@ const func: DeployFunction = async ({ viem, getNamedAccounts, deployments }) =>
172187
]);
173188
if (erc20RewardsDelExtensions.length == 0 || erc20RewardsDelExtensions[0] != erc20RewardsDel.address) {
174189
if ((await fuseFeeDistributor.read.owner()).toLowerCase() !== deployer.toLowerCase()) {
175-
logTransaction(
176-
"Set CErc20RewardsDelegate Extensions",
177-
encodeFunctionData({
178-
abi: fuseFeeDistributor.abi,
179-
functionName: "_setCErc20DelegateExtensions",
180-
args: [
181-
erc20RewardsDel.address as Address,
182-
[erc20RewardsDel.address as Address, cTokenFirstExtension.address as Address]
183-
]
184-
})
185-
);
190+
await prepareAndLogTransaction({
191+
contractInstance: fuseFeeDistributor,
192+
functionName: "_setCErc20DelegateExtensions",
193+
args: [
194+
erc20RewardsDel.address as Address,
195+
[erc20RewardsDel.address as Address, cTokenFirstExtension.address as Address]
196+
],
197+
description: "Set CErc20RewardsDelegate Extensions",
198+
walletClient,
199+
inputs: [
200+
{ internalType: "address", name: "cErc20Delegate", type: "address" },
201+
{ internalType: "address[]", name: "extensions", type: "address[]" }
202+
]
203+
});
186204
} else {
187205
tx = await fuseFeeDistributor.write._setCErc20DelegateExtensions([
188206
erc20RewardsDel.address as Address,
@@ -197,14 +215,18 @@ const func: DeployFunction = async ({ viem, getNamedAccounts, deployments }) =>
197215
const [latestCErc20RewardsDelegate] = await fuseFeeDistributor.read.latestCErc20Delegate([3]);
198216
if (latestCErc20RewardsDelegate === zeroAddress || latestCErc20RewardsDelegate !== erc20RewardsDel.address) {
199217
if ((await fuseFeeDistributor.read.owner()).toLowerCase() !== deployer.toLowerCase()) {
200-
logTransaction(
201-
"Set Latest CErc20RewardsDelegate",
202-
encodeFunctionData({
203-
abi: fuseFeeDistributor.abi,
204-
functionName: "_setLatestCErc20Delegate",
205-
args: [3, erc20RewardsDel.address as Address, becomeImplementationData]
206-
})
207-
);
218+
await prepareAndLogTransaction({
219+
contractInstance: fuseFeeDistributor,
220+
functionName: "_setLatestCErc20Delegate",
221+
args: [3, erc20RewardsDel.address as Address, becomeImplementationData],
222+
description: "Set Latest CErc20RewardsDelegate",
223+
walletClient,
224+
inputs: [
225+
{ internalType: "uint8", name: "delegateType", type: "uint8" },
226+
{ internalType: "address", name: "newImplementation", type: "address" },
227+
{ internalType: "bytes", name: "becomeImplementationData", type: "bytes" }
228+
]
229+
});
208230
} else {
209231
tx = await fuseFeeDistributor.write._setLatestCErc20Delegate([
210232
3,
@@ -231,17 +253,20 @@ const func: DeployFunction = async ({ viem, getNamedAccounts, deployments }) =>
231253
erc20PluginRewardsDelExtensions[0] != erc20PluginRewardsDel.address
232254
) {
233255
if ((await fuseFeeDistributor.read.owner()).toLowerCase() !== deployer.toLowerCase()) {
234-
logTransaction(
235-
"Set CErc20PluginRewardsDelegate Extensions",
236-
encodeFunctionData({
237-
abi: fuseFeeDistributor.abi,
238-
functionName: "_setCErc20DelegateExtensions",
239-
args: [
240-
erc20PluginRewardsDel.address as Address,
241-
[erc20PluginRewardsDel.address as Address, cTokenFirstExtension.address as Address]
242-
]
243-
})
244-
);
256+
await prepareAndLogTransaction({
257+
contractInstance: fuseFeeDistributor,
258+
functionName: "_setCErc20DelegateExtensions",
259+
args: [
260+
erc20PluginRewardsDel.address as Address,
261+
[erc20PluginRewardsDel.address as Address, cTokenFirstExtension.address as Address]
262+
],
263+
description: "Set CErc20PluginRewardsDelegate Extensions",
264+
walletClient,
265+
inputs: [
266+
{ internalType: "address", name: "cErc20Delegate", type: "address" },
267+
{ internalType: "address[]", name: "extensions", type: "address[]" }
268+
]
269+
});
245270
} else {
246271
tx = await fuseFeeDistributor.write._setCErc20DelegateExtensions([
247272
erc20PluginRewardsDel.address as Address,
@@ -259,14 +284,18 @@ const func: DeployFunction = async ({ viem, getNamedAccounts, deployments }) =>
259284
latestCErc20PluginRewardsDelegate !== erc20PluginRewardsDel.address
260285
) {
261286
if ((await fuseFeeDistributor.read.owner()).toLowerCase() !== deployer.toLowerCase()) {
262-
logTransaction(
263-
"Set Latest CErc20PluginRewardsDelegate",
264-
encodeFunctionData({
265-
abi: fuseFeeDistributor.abi,
266-
functionName: "_setLatestCErc20Delegate",
267-
args: [4, erc20PluginRewardsDel.address as Address, becomeImplementationData]
268-
})
269-
);
287+
await prepareAndLogTransaction({
288+
contractInstance: fuseFeeDistributor,
289+
functionName: "_setLatestCErc20Delegate",
290+
args: [4, erc20PluginRewardsDel.address as Address, becomeImplementationData],
291+
description: "Set Latest CErc20PluginRewardsDelegate",
292+
walletClient,
293+
inputs: [
294+
{ internalType: "uint8", name: "delegateType", type: "uint8" },
295+
{ internalType: "address", name: "newImplementation", type: "address" },
296+
{ internalType: "bytes", name: "becomeImplementationData", type: "bytes" }
297+
]
298+
});
270299
} else {
271300
tx = await fuseFeeDistributor.write._setLatestCErc20Delegate([
272301
4,

0 commit comments

Comments
 (0)