@nexex/cli
Version:
57 lines • 2.68 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const utils_1 = require("ethers/utils");
const Base_1 = require("../../Base");
const WalletBase_1 = __importDefault(require("../../WalletBase"));
class TokenWeth2Eth extends WalletBase_1.default {
async run() {
const { flags, args: { amount } } = this.parse(TokenWeth2Eth);
const [api, walletAddr] = [await this.initApi(), await this.readWalletAddr()];
const weth = await api.tokenRegistry.getTokenAddressBySymbol('WETH');
const weiAmount = utils_1.parseEther(amount);
const wethBefore = await api.token.balanceOf(weth, walletAddr);
if (wethBefore.lt(weiAmount)) {
console.log('not enough balance');
this.exit(1);
}
const wallet = await this.readWallet();
const tx = await api.token.unwrapEth(wallet.connect(api.eth), weiAmount);
await tx.wait();
const [ethBalance, wethBalance] = await Promise.all([
api.eth.getBalance(wallet.address),
api.token.balanceOf(weth, wallet.address)
]);
console.log('eth:', utils_1.commify(utils_1.formatEther(ethBalance)));
console.log('weth', utils_1.commify(utils_1.formatEther(wethBalance)));
}
}
TokenWeth2Eth.description = 'describe the command here';
TokenWeth2Eth.examples = [
`$ nexex-cli hello
hello world from ./src/hello.ts!
`
];
TokenWeth2Eth.flags = {
...WalletBase_1.default.flags
};
TokenWeth2Eth.args = [{ name: 'amount' }];
__decorate([
Base_1.initDir,
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", Promise)
], TokenWeth2Eth.prototype, "run", null);
exports.default = TokenWeth2Eth;
//# sourceMappingURL=weth2eth.js.map