-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
90 lines (73 loc) · 2.85 KB
/
index.ts
File metadata and controls
90 lines (73 loc) · 2.85 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
import * as core from '@actions/core';
import SafeApiKit from "@safe-global/api-kit";
import Safe from "@safe-global/protocol-kit";
import { OperationType, MetaTransactionData } from "@safe-global/types-kit";
import { createPublicClient, http } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { env } from "./env.js";
async function run() {
const {
RPC_URL: rpcUrl,
SAFE_ADDRESS: safeAddress,
TRANSACTION_TO: transactionTo,
TRANSACTION_VALUE: transactionValue,
TRANSACTION_DATA: transactionData,
SAFE_PROPOSER_PRIVATE_KEY: safeProposerPrivateKey,
SAFE_API_KEY: safeApiKey,
} = env;
core.info(`🚀 Starting Safe transaction proposal...`);
core.info(`📍 Safe Address: ${safeAddress}`);
core.info(`🎯 Target Address: ${transactionTo}`);
const account = privateKeyToAccount(safeProposerPrivateKey as `0x${string}`);
core.info(`🔑 Proposer Address: ${account.address}`);
const publicClient = createPublicClient({
transport: http(rpcUrl),
});
const chainId = await publicClient.getChainId();
const apiKit = new SafeApiKit({
chainId: BigInt(chainId),
apiKey: safeApiKey,
});
const protocolKit = await Safe.init({
provider: rpcUrl,
signer: safeProposerPrivateKey,
safeAddress: safeAddress,
});
core.info(`👤 Safe initialized for: ${safeAddress}`);
const safeTransactionData: MetaTransactionData = {
to: transactionTo,
value: transactionValue,
data: transactionData,
operation: OperationType.Call,
};
core.info("📝 Creating Safe transaction...");
const safeTransaction = await protocolKit.createTransaction({
transactions: [safeTransactionData],
});
const safeTxHash = await protocolKit.getTransactionHash(safeTransaction);
const signature = await protocolKit.signHash(safeTxHash);
core.info(`🔐 Transaction signed - hash: ${safeTxHash}`);
await apiKit.proposeTransaction({
safeAddress: safeAddress,
safeTransactionData: safeTransaction.data,
safeTxHash: safeTxHash,
senderAddress: account.address,
senderSignature: signature.data,
origin: "GitHub Action - Propose Safe Multisig Transaction",
});
const transaction = await apiKit.getTransaction(safeTxHash);
core.setOutput("tx-hash", safeTxHash);
core.setOutput("tx-details", JSON.stringify(transaction));
core.info(`✅ Transaction proposed successfully!`);
core.info(`🔗 Transaction Hash: ${safeTxHash}`);
core.info(`⏳ Waiting for other owners to sign and execute...`);
core.info(`📋 Transaction Details: ${JSON.stringify(transaction, null, 2)}`);
}
run().catch((error) => {
const errorMessage = error instanceof Error ? error.message : "Unknown error";
const errorStack = error instanceof Error ? error.stack : undefined;
core.setFailed(`❌ Error proposing Safe transaction: ${errorMessage}`);
if (errorStack) {
core.error(errorStack);
}
});