UNPKG

@celo/contractkit

Version:

Celo's ContractKit to interact with Celo network

108 lines (107 loc) 4.82 kB
import { CeloTokenType, StableToken, Token } from '@celo/base'; import { BigNumber } from 'bignumber.js'; import { AddressRegistry } from './address-registry'; import { CeloContract, CeloTokenContract, StableTokenContract } from './base'; import { ContractCacheType } from './basic-contract-cache-type'; import { GoldTokenWrapper } from './wrappers/GoldTokenWrapper'; import { StableTokenWrapper } from './wrappers/StableTokenWrapper'; export { CeloTokenType, StableToken, Token } from '@celo/base'; export type EachCeloToken<T> = { [key in CeloTokenType]?: T; }; export type CeloTokenWrapper = GoldTokenWrapper | StableTokenWrapper; export interface CeloTokenInfo { contract: CeloTokenContract; symbol: CeloTokenType; } export interface StableTokenInfo extends CeloTokenInfo { contract: StableTokenContract; } /** Basic info for each stable token */ export declare const stableTokenInfos: { [key in StableToken]: StableTokenInfo; }; /** Basic info for each supported celo token, including stable tokens */ export declare const celoTokenInfos: { [key in CeloTokenType]: CeloTokenInfo; }; /** * A helper class to interact with all Celo tokens, ie CELO and stable tokens */ export declare class CeloTokens { readonly contracts: ContractCacheType; readonly registry: AddressRegistry; constructor(contracts: ContractCacheType, registry: AddressRegistry); /** * Gets an address's balance for each celo token. * @param address the address to look up the balances for * @return a promise resolving to an object containing the address's balance * for each celo token */ balancesOf(address: string): Promise<EachCeloToken<BigNumber>>; /** * Gets the wrapper for each celo token. * @return an promise resolving to an object containing the wrapper for each celo token. */ getWrappers(): Promise<EachCeloToken<CeloTokenWrapper>>; /** * Gets the address for each celo token proxy contract. * @return an promise resolving to an object containing the address for each celo token proxy. */ getAddresses(): Promise<EachCeloToken<string>>; getStablesConfigs(humanReadable?: boolean): Promise<EachCeloToken<import("./wrappers/StableTokenWrapper").StableTokenConfig>>; /** * Runs fn for each celo token found in celoTokenInfos, and returns the * value of each call in an object keyed by the token. * @param fn the function to be called for each CeloTokenInfo. * @return an object containing the resolved value the call to fn for each * celo token. */ forEachCeloToken<T>(fn: (info: CeloTokenInfo) => T | Promise<T>): Promise<EachCeloToken<T>>; /** * Runs fn for each stable token found in stableTokenInfos, and returns the * value of each call in an object keyed by the token. * @param fn the function to be called for each StableTokenInfo. * @return an object containing the resolved value the call to fn for each * celo token. */ forStableCeloToken<T>(fn: (info: StableTokenInfo) => T | Promise<T>): Promise<EachCeloToken<T>>; private forEachWrapperInfo; validCeloTokenInfos(): Promise<CeloTokenInfo[]>; validStableTokenInfos(): Promise<StableTokenInfo[]>; /** * Gets the wrapper for a given celo token. * @param token the token to get the appropriate wrapper for * @return an promise resolving to the wrapper for the token */ getWrapper(token: StableToken): Promise<StableTokenWrapper>; getWrapper(token: Token): Promise<GoldTokenWrapper>; getWrapper(token: CeloTokenType): Promise<CeloTokenWrapper>; /** * Gets the contract for the provided token * @param token the token to get the contract of * @return The contract for the token */ getContract(token: StableToken): StableTokenContract; /** * Gets the address of the contract for the provided token. * @param token the token to get the (proxy) contract address for * @return A promise resolving to the address of the token's contract */ getAddress: (token: CeloTokenType) => Promise<`0x${string}`>; /** * Gets the address to use as the feeCurrency when paying for gas with the * provided token. * @param token the token to get the feeCurrency address for * @return If not CELO, the address of the token's contract. If CELO, undefined. */ getFeeCurrencyAddress(token: CeloTokenType): Promise<`0x${string}`> | undefined; /** * Returns if the provided token is a StableToken * @param token the token * @return if token is a StableToken */ isStableToken(token: CeloTokenType): boolean; isStableTokenContract: typeof isStableTokenContract; } export declare function isStableTokenContract(contract: CeloContract): boolean;