-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbridge_listener.ts
88 lines (79 loc) · 2.54 KB
/
bridge_listener.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
/**
* Copyright 2025 Circle Internet Group, Inc. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {
AddressLike,
BigNumberish,
Contract,
WebSocketProvider,
formatEther,
// Wallet,
// JsonRpcProvider,
} from "ethers";
import BridgeContract from "./artifacts/hardhat/contracts/RadiusBridge.sol/RadiusBridge.json";
import { exec } from "child_process";
import * as dotenv from "dotenv";
dotenv.config();
const HOLESKY_WS_RPC_URL =
"wss://eth-holesky.g.alchemy.com/v2/zz9S1NLrUlFEBOvEhRktRxMJzXJYW30V";
const HOLESKY_BRIDGE_ADDRESS = "0xB10F4F97771F9B139637F23B20152F661dAcE269";
const RADIUS_BRIDGE_ADDRESS = "0x0320c72946E46E2bbb2d8700982e87c6f2c3503D";
const PRIVATE_KEY = "";
const holeskyProvider = new WebSocketProvider(HOLESKY_WS_RPC_URL, {
name: "holesky",
chainId: 17000,
});
const holeskyBridgeContract = new Contract(
HOLESKY_BRIDGE_ADDRESS,
BridgeContract.abi,
holeskyProvider
);
function runCommand(command: string): Promise<string> {
return new Promise((resolve, reject) => {
exec(command, (error, stdout) => {
if (error) {
console.error(error);
reject(error);
} else {
resolve(stdout.trim());
}
});
});
}
console.log("bot listening!");
void holeskyBridgeContract.on(
"Deposit",
async (depositor: AddressLike, amount: BigNumberish) => {
// TODO: edit command to use ${depositor}, ${amount}
console.log(`sending ${formatEther(amount)} tokens to ${depositor}`);
try {
const output = await runCommand(
`cast send ${RADIUS_BRIDGE_ADDRESS} --rpc-url https://rpc.testnet.tryradi.us/ac030419463f6b74251f4b090c743b051b3624eaf6d9e7c0 --private-key ${PRIVATE_KEY} "release(address,uint256)" ${depositor} ${parseInt(
formatEther(amount)
)}`
);
console.log(output);
} catch (err) {
console.error(err);
}
console.log(
`sent ${formatEther(
amount
)} tokens to ${depositor} on Radius contract: ${RADIUS_BRIDGE_ADDRESS}`
);
}
);