UNPKG

eulith-web3js

Version:

Official Eulith Typescript client library

150 lines (149 loc) 6.66 kB
import { Contract as Web3Contract } from "web3-eth-contract"; import { TransactionConfig } from "web3-core"; import * as Eulith from "./index"; import * as ImportedInterfaces from "./contractInterfaces"; import BN from "bn.js"; /** * Code useful for managing on-chain contract interactions */ export declare module Contracts { /** * Contract wraps the native Web3js.eth.Contract object. By itself it provides little value. * * The value is found in specific subclasses of Eulith.Contract */ class Contract { protected constructor(nativeContract: any); get native(): ImportedInterfaces.BaseContract; /** * The Web3js options object, containing the address and ABI */ get options(): import("web3-eth-contract").Options; /** * The address of this contract */ get address(): string; protected _contract: Web3Contract; } /** * Wrapper on an ERC20 ethereum token contract. * * Designed to provider very convenient interactions with ERC20 implementing contracts */ class ERC20TokenContract extends Contract { /** * Construct an ERC20 contract (ERC20TokenContract) object from a provider, an address, and optionally pre-specify * the number of decimals, and symbol associated with that contract (as a performance optimization, else will be construed from * the contract via a web call) */ static new({ provider, contractAddress, decimals, symbol }: { provider: Eulith.Provider; contractAddress: string; decimals?: number; symbol?: string; }): Promise<ERC20TokenContract>; /** * Typically use ERC20TokenContract::new API (since its async) but you can use this API if you have a pre-constructed * contract object, and know the # of decimals. */ protected constructor(provider: Eulith.Provider, nativeContract: any, decimals: number, symbol: string); get nativeERC20(): ImportedInterfaces.IERCDetailed; /** * Return the number of decimals of precision used in converting from this ERC20 contracts Tokens to * its wire (transmission/interchange) format. */ get decimals(): number; /** * The Eulith provider managing the contract interactions */ get provider(): Eulith.Provider; /** * This symbol associated with an ERC20 contract */ get symbol(): string; /** * Argument 'v' - is a number (either in float, or wire-format) - interpreted as being in the native contract * units. It's converted to an object that knows this, and the native number of decimals, so it can be rendered properly * automatically in wire format. * * if v is a number, it's interpreted in ERC20 token units * if v is a string, it's interpreted as being in fundamental units. */ asTokenValue(v: number | string): Eulith.Tokens.Value.ERC20; /** * Convenience wrapper around ERC20.approve */ approve(spender: string, amount: Eulith.Tokens.Value.ITokenValue, txOpts?: Partial<TransactionConfig>): Eulith.Signing.UnsignedTransaction; /** * Convenience wrapper around ERC20.transfer */ transfer(to: string, amount: Eulith.Tokens.Value.ITokenValue, txOpts?: Partial<TransactionConfig>): Eulith.Signing.UnsignedTransaction; /** * Convenience wrapper around ERC20.transferFrom */ transferFrom(from: string, to: string, amount: Eulith.Tokens.Value.ITokenValue, txOpts?: Partial<TransactionConfig>): Eulith.Signing.UnsignedTransaction; /** * Convenience wrapper around ERC20.balanceOf */ balanceOf(address: string): Promise<Eulith.Tokens.Value.ERC20>; /** * Convenience wrapper around ERC20.allowance */ allowance(owner: string, spender: string): Promise<Eulith.Tokens.Value.ERC20>; private readonly provider_?; private readonly decimals_; private readonly symbol_; } /** * The WETH contract is special because it allows for deposit/withdraw of native ETH */ class WethTokenContract extends ERC20TokenContract { /** */ static new({ provider, contractAddress }: { provider: Eulith.Provider; contractAddress: string; }): Promise<WethTokenContract>; /** * Typically use WethTokenContract::new API (since its async) but you can use this API if you have a pre-constructed * contract object, and know the # of decimals. */ constructor(provider: Eulith.Provider, nativeContract: any); /** * Returns the native contract binding */ nativeWETH(): ImportedInterfaces.WETHInterface; /** * Convenience wrapper around ERC20.balanceOf */ balanceOf(address: string): Promise<Eulith.Tokens.Value.ERC20>; /** * Convenience wrapper around ERC20.deposit */ deposit(v: Eulith.Tokens.Value.ETH, txOpts?: Partial<TransactionConfig>): Eulith.Signing.UnsignedTransaction; /** * Convenience wrapper around ERC20.withdraw */ withdraw(v: Eulith.Tokens.Value.ETH, txOpts?: Partial<TransactionConfig>): Eulith.Signing.UnsignedTransaction; } class EOAProxyContract extends Contract { constructor(provider: Eulith.Provider, contractAddress: string); getProxyTransaction(tx: TransactionConfig, fromEoa: string): TransactionConfig; getReimburseTransaction(from: string): TransactionConfig; } class AaveLendingPoolV2 extends Contract { constructor(provider: Eulith.Provider, contractAddress: string); deposit(asset: string, amount: number | string | BN, onBehalfOf: string, referralCode: number): TransactionConfig; withdraw(asset: string, amount: number | string | BN, to: string): TransactionConfig; borrow(asset: string, amount: number | string | BN, interestRateMode: number, referralCode: number, onBehalfOf: string): TransactionConfig; repay(asset: string, amount: number | string | BN, rateMode: number, onBehalfOf: string): { to: string; data: string; }; } class Safe extends Contract { constructor(provider: Eulith.Provider, contractAddress: string); getOwners(): Promise<string[]>; getThreshold(): Promise<number>; } }