UNPKG

@tempus-labs/utils

Version:

Tempus utility helpers

77 lines 3.23 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ERC20Ether = void 0; const hardhat_1 = require("hardhat"); const Decimal_1 = require("../utils/Decimal"); const DecimalConvertible_1 = require("../utils/DecimalConvertible"); const ContractBase_1 = require("../utils/ContractBase"); /** * Typed wrapper for Ether which implements ERC20, * so that we can simplify tests on native ETH based pools */ class ERC20Ether extends DecimalConvertible_1.DecimalConvertible { constructor() { super(18); // Address of this contract - ETH is Zero address this.address = '0x0000000000000000000000000000000000000000'; } /** @return ERC20 name of this contract */ async name() { return "Ether"; } /** @return ERC20 symbol of this contract */ async symbol() { return "ETH"; } /** * @returns Total supply of this ERC20 token as a decimal, such as 10.0 */ async totalSupply() { return (0, Decimal_1.decimal)(117766454); } /** * @param account ERC20 account's address * @returns Balance of ERC20 address in decimals, eg 2.0 */ async balanceOf(account) { const balance = await hardhat_1.ethers.provider.getBalance((0, ContractBase_1.addressOf)(account)); return this.toDecimal(balance.toString()); } /** * @dev Moves `amount` tokens from the sender's account to `recipient`. * @param sender The sender/caller of this transfer * @param recipient ERC20 transfer recipient's address * @param amount Amount of tokens to send in contract decimals, eg 2.0 or "0.00001" */ async transfer(sender, recipient, amount) { return sender.sendTransaction({ from: sender.address, to: (0, ContractBase_1.addressOf)(recipient), value: this.toBigNum(amount) }); } /** * @param owner ERC20 owner's address * @param spender ERC20 spender's address * @returns The remaining number of tokens that `spender` will be allowed to * spend on behalf of `owner` through {transferFrom}. This is zero by default. */ async allowance(owner, spender) { return (0, Decimal_1.decimal)(0); } /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * @param caller The caller who is sending this approve * @param spender ERC20 approve's, spender's address * @param amount Amount of tokens to approve in contract decimals, eg 2.0 or "0.00001" */ async approve(caller, spender, amount) { return; } /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's allowance. * @param sender ERC20 transferFrom sender's address * @param recipient ERC20 transferFrom recipient's address * @param amount Amount of tokens to send in contract decimals, eg 2.0 or "0.00001" */ async transferFrom(sender, recipient, amount) { return this.transfer(sender, recipient, amount); } } exports.ERC20Ether = ERC20Ether; //# sourceMappingURL=ERC20Ether.js.map