-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpropose-create.ts
More file actions
executable file
·101 lines (75 loc) · 2.46 KB
/
Copy pathpropose-create.ts
File metadata and controls
executable file
·101 lines (75 loc) · 2.46 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
91
92
93
94
95
96
97
98
99
100
101
import hre from "hardhat";
import Safe, {
EthersAdapter,
} from "@safe-global/protocol-kit";
import {
MetaTransactionData,
OperationType,
} from "@safe-global/safe-core-sdk-types";
import * as dotenv from "dotenv";
dotenv.config({ path: ".env" });
import SafeApiKit from "@safe-global/api-kit";
import { AutomateSDK, TriggerType } from "@gelatonetwork/automate-sdk";
import { safeAddress } from "../safe";
import { task } from "hardhat/config";
const { ethers } = hre;
async function main() {
const [deployer] = await ethers.getSigners();
const ethAdapter = new EthersAdapter({
ethers,
signerOrProvider: deployer,
});
const protocolKit = await Safe.create({
ethAdapter,
safeAddress,
});
const predictedSafeAddress =
await protocolKit.getAddress();
console.log({ predictedSafeAddress });
const isSafeDeployed =
await protocolKit.isSafeDeployed();
console.log({ isSafeDeployed });
const chainId = (await ethers.provider.getNetwork()).chainId;
const automate = new AutomateSDK(chainId, deployer);
const cid="QmSBdgzCUYcpwAWQPZc4oFn1zYwb4LovCXMPyrHUncBQ7S"
const { taskId, tx } = await automate.prepareBatchExecTask({
name: "heartbeat",
web3FunctionHash: cid,
web3FunctionArgs: {
// "arg1":"value",
},
trigger: {
interval: 30 * 1000,
type: TriggerType.TIME,
},
},
{},
safeAddress // important to pass the safe address as task creator
);
const txServiceUrl = 'https://safe-transaction-sepolia.safe.global'
const service = new SafeApiKit({ txServiceUrl, ethAdapter: ethAdapter })
const safeTransactionData: MetaTransactionData = {
to: tx.to!,
data: tx.data!,
value: "0",
operation: OperationType.Call,
};
// Propose transaction to the service
const safeTransaction = await protocolKit.createTransaction({ safeTransactionData })
const senderAddress = await deployer.getAddress()
const safeTxHash = await protocolKit.getTransactionHash(safeTransaction)
const signature = await protocolKit.signTransactionHash(safeTxHash)
await service.proposeTransaction({
safeAddress: safeAddress,
safeTransactionData: safeTransaction.data,
safeTxHash,
senderAddress ,
senderSignature: signature.data
})
console.log('Proposed a transaction with Safe:', safeAddress)
console.log('- safeTxHash:', safeTxHash)
console.log('- Sender:', senderAddress)
console.log('- Sender signature:', signature.data)
console.log('- TaskId:', taskId)
}
main();