-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwithdraw.ts
67 lines (57 loc) · 2.13 KB
/
withdraw.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
import { task } from "hardhat/config";
import { TaskArguments } from "hardhat/types";
import { getPrivateKey, getProviderRpcUrl } from "../helpers/utils";
import { Wallet, JsonRpcProvider } from "ethers";
import { Withdraw } from "../typechain-types/contracts/utils";
import { Withdraw__factory } from "../typechain-types/factories/contracts/utils";
import { Spinner } from "../helpers/spinner";
task(
`withdraw`,
`Withdraws tokens and coins from Withdraw.sol. Must be called by an Owner, otherwise it will revert`
)
.addParam(
`blockchain`,
`The name of the blockchain (for example ethereumSepolia)`
)
.addParam(
`from`,
`The address of the Withdraw.sol smart contract from which funds should be withdrawn`
)
.addParam(`beneficiary`, `The address to withdraw to`)
.addOptionalParam(`tokenAddress`, `The address of a token to withdraw`)
.setAction(async (taskArguments: TaskArguments) => {
const { blockchain, from, beneficiary, tokenAddress } = taskArguments;
const privateKey = getPrivateKey();
const rpcProviderUrl = getProviderRpcUrl(blockchain);
const provider = new JsonRpcProvider(rpcProviderUrl);
const wallet = new Wallet(privateKey);
const signer = wallet.connect(provider);
const withdraw: Withdraw = Withdraw__factory.connect(from, signer);
const spinner: Spinner = new Spinner();
if (tokenAddress) {
console.log(
`ℹ️ Attempting to withdraw ${tokenAddress} tokens from ${from} to ${beneficiary}`
);
spinner.start();
const withdrawalTx = await withdraw.withdrawToken(
beneficiary,
tokenAddress
);
await withdrawalTx.wait();
spinner.stop();
console.log(
`✅ Withdrawal successful, transaction hash: ${withdrawalTx.hash}`
);
} else {
console.log(
`ℹ️ Attempting to withdraw coins from ${from} to ${beneficiary}`
);
spinner.start();
const withdrawalTx = await withdraw.withdraw(beneficiary);
await withdrawalTx.wait();
spinner.stop();
console.log(
`✅ Withdrawal successful, transaction hash: ${withdrawalTx.hash}`
);
}
});