UNPKG

@okcontract/sdk

Version:

One-stop-shop permissionless SDK for building any blockchain frontend

89 lines (88 loc) 4.58 kB
import type { AnyCell, MapCell, SheetProxy } from "@okcontract/cells"; import type { ABI, ABIExtra, CacheQuery } from "@okcontract/coredata"; import { Rational } from "@okcontract/lambdascript"; import { type Address, type ChainAddress, type ChainType, type LocalRPCSubscriber, type Network } from "@okcontract/multichain"; import type { LocalSubscriber } from "@scv/cache"; import type { OKCore } from "./coreExecution"; import type { TokenQueryOrAddress } from "./types"; export declare const ERC20 = "20"; export declare const balance_of = "balanceOf"; export declare const approve_method = "approve"; export declare const approve_method_signature = "function approve(address _spender, uint256 _value) public returns (bool success)"; export declare const erc20: string[]; export declare const erc20AbiEVM: import("abitype").Abi; export declare const erc20AbiStarknet: { name: string; type: string; items: { name: string; type: string; inputs: { name: string; type: string; }[]; outputs: { type: string; }[]; state_mutability: string; }[]; }[]; /** * generated abix from any contract that is erc20. * @param chain * @param addr * @param tcd * @returns * @todo move is_erc20 check here * @todo extend to other interfaces (erc721, etc.) */ export declare const abix_erc20: (abi: ABI) => ABIExtra | null; export type TokenContractData = { decimals: AnyCell<number>; symbol: AnyCell<string>; }; export declare const valid_timestamp: (ts: number) => boolean; /** * get_allowance retrieves an allowance using the contract cache (shared with balance). * @param ch * @param addr * @param spender * @returns */ export declare const getAllowanceForWallet: <N extends Network>(core: OKCore, local: LocalRPCSubscriber, wallet: AnyCell<Address<N> | "none">, addr: AnyCell<ChainAddress>, spender: AnyCell<Address<N>>) => AnyCell<bigint | null>; /** * formatBig is an alternative to formatUnits from ethers. * @param v * @param keep significant digits to keep * @see https://docs.ethers.io/v5/api/utils/display-logic/ * @todo duplicate in uic */ export declare const formatBig: (v: bigint | number | string | null, dec: number | bigint, keep?: number) => any; /** * formatAmount returns a string representation of an amount for a given token. * @param v value * @param tok token (as hex address or "tok:" query) * @returns * @todo maybe Lambdascript evaluation should automatically enrich * token queries, addresses, etc. to OKToken objects which * stdlib functions such as `formatAmount` could use directly */ export declare const formatAmount: (core: OKCore, proxy: SheetProxy, rpc: LocalRPCSubscriber, local: LocalSubscriber<CacheQuery>, v: AnyCell<number | string | bigint | Rational>, tok: AnyCell<TokenQueryOrAddress>, chain: AnyCell<ChainType>, showSymbol?: AnyCell<boolean>) => MapCell<string, false>; /** * raw_balance * @param ch * @param tok (use nativeAddr for native chain balances) * @returns */ export declare const raw_balance: (core: OKCore, proxy: SheetProxy, rpc: LocalRPCSubscriber, local: LocalSubscriber<CacheQuery>, wallet: AnyCell<Address<Network>>, ch: AnyCell<ChainType>, tok: AnyCell<TokenQueryOrAddress>) => AnyCell<[Rational, Rational, string]>; /** * formatBalance returns the formatted balance for the current user. * @param ch chain * @param addr token address * @returns */ export declare const formatBalance: (core: OKCore, proxy: SheetProxy, rpc: LocalRPCSubscriber, local: LocalSubscriber<CacheQuery>, wallet: AnyCell<Address<Network>>, ch: AnyCell<ChainType>, tok: AnyCell<TokenQueryOrAddress>, show_symbol?: boolean) => MapCell<string, false>; export declare const getDecimals: <N extends Network>(local: LocalSubscriber<CacheQuery>, core: OKCore, proxy: SheetProxy, rpc: LocalRPCSubscriber, addr: AnyCell<ChainAddress<N>>) => MapCell<Rational, false>; export declare const getBalance: <N extends Network>(core: OKCore, proxy: SheetProxy, rpc: LocalRPCSubscriber, addr: AnyCell<ChainAddress<N>>, owner: AnyCell<Address<N> | null>) => MapCell<bigint | null, false>; export declare const getSymbol: <N extends Network>(local: LocalSubscriber<CacheQuery>, core: OKCore, proxy: SheetProxy, rpc: LocalRPCSubscriber, addr: AnyCell<ChainAddress<N>>, _where?: string) => MapCell<string, false>; export declare const getName: <N extends Network>(local: LocalSubscriber<CacheQuery>, core: OKCore, proxy: SheetProxy, rpc: LocalRPCSubscriber, addr: AnyCell<ChainAddress<N>>) => MapCell<string, false>;