-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathrevoke.ts
64 lines (58 loc) · 1.81 KB
/
revoke.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
import { Command } from "@oclif/command";
import chalk from "chalk";
import { ethers } from "ethers";
import { REVOKE_AMOUNT } from "../../lib/constants.json";
import { cancelled, confirm } from "../../lib/prompt";
import * as utils from "../../lib/utils";
import { getWallet } from "../../lib/wallet";
import { Registry } from "@airswap/libraries";
const IERC20 = require("@airswap/utils/build/src/abis/ERC20.json");
export default class RegistryRevoke extends Command {
public static description = "disable staking on the registry";
public async run() {
try {
const wallet = await getWallet(this, true);
const chainId = (await wallet.provider.getNetwork()).chainId;
const metadata = await utils.getMetadata(this, chainId);
const gasPrice = await utils.getGasPrice(this);
utils.displayDescription(this, RegistryRevoke.description, chainId);
const registryContract = Registry.getContract(wallet, chainId);
const stakingTokenContract = new ethers.Contract(
await registryContract.stakingToken(),
IERC20.abi,
wallet,
);
const allowance = await stakingTokenContract.allowance(
wallet.address,
Registry.getAddress(chainId),
);
if (allowance.eq(0)) {
this.log(chalk.yellow("Registry already revoked"));
} else {
const stakingToken =
metadata.byAddress[stakingTokenContract.address.toLowerCase()];
if (
await confirm(
this,
metadata,
"revoke",
{
token: `${stakingToken.address} ${stakingToken.symbol}`,
spender: `${Registry.getAddress(chainId)} (Registry)`,
},
chainId,
)
) {
stakingTokenContract
.approve(Registry.getAddress(chainId), REVOKE_AMOUNT, {
gasPrice,
})
.then(utils.handleTransaction)
.catch(utils.handleError);
}
}
} catch (e) {
cancelled(e);
}
}
}