Skip to content

Commit 4917f0e

Browse files
committed
add SendRequestToGetBalance script for balance retrieval functionality
1 parent ea063c9 commit 4917f0e

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity 0.8.26;
3+
4+
import {Script, console} from "forge-std/Script.sol";
5+
import {HelperConfig} from "./HelperConfig.s.sol";
6+
import {CheckBalance} from "../src/CheckBalance.sol";
7+
import {DevOpsTools} from "lib/foundry-devops/src/DevOpsTools.sol";
8+
import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";
9+
10+
contract SendRequestToGetBalance is Script {
11+
using Strings for uint256;
12+
13+
HelperConfig public helperConfig;
14+
CheckBalance public checkBalance;
15+
uint64 constant SEPOLIA_SUBSCRIPTION_ID = 3995;
16+
17+
function sendRequestToGetBalance(
18+
address checkBalanceAddress,
19+
string memory chainBaseUrl,
20+
address tokenAddress,
21+
address subscriber
22+
) public {
23+
checkBalance = CheckBalance(checkBalanceAddress);
24+
string[] memory args = new string[](3);
25+
args[0] = chainBaseUrl;
26+
args[1] = uint256(uint160(tokenAddress)).toHexString();
27+
args[2] = uint256(uint160(subscriber)).toHexString();
28+
29+
vm.startBroadcast();
30+
checkBalance.sendRequest(SEPOLIA_SUBSCRIPTION_ID, args);
31+
vm.stopBroadcast();
32+
console.log("Request sent to get balance.");
33+
}
34+
35+
function run() public {
36+
address mostRecentlyDeployed = DevOpsTools.get_most_recent_deployment(
37+
"CheckBalance",
38+
block.chainid
39+
);
40+
console.log("Most recently deployed address: ", mostRecentlyDeployed);
41+
42+
helperConfig = new HelperConfig();
43+
(
44+
string memory chainBaseUrl,
45+
address tokenAddress,
46+
address subscriber,
47+
,
48+
49+
) = helperConfig.activeNetworkConfig();
50+
51+
sendRequestToGetBalance(
52+
mostRecentlyDeployed,
53+
chainBaseUrl,
54+
tokenAddress,
55+
subscriber
56+
);
57+
}
58+
}

0 commit comments

Comments
 (0)