UNPKG

@okcontract/sdk

Version:

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

87 lines (86 loc) 3.95 kB
import type { AbiFunction, AbiParameter } from "abitype"; import { type Abi } from "viem"; import { type AnyCell, type Cellified, type MapCell, type SheetProxy } from "@okcontract/cells"; import { type ABI, type ABIMethod, type ABIValue, type CacheQuery } from "@okcontract/coredata"; import { type LabelledTypeDefinition, type TypeDefinition, type TypeDefinitionFn } from "@okcontract/fred"; import { type ASTNode, type Environment, type MonoType } 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 { OKPage } from "./instance"; export declare const ARG_PREFIX = "__arg"; export declare const anonymousArg: (i: number) => string; export declare const isAnonymousArg: (arg: string) => boolean; export declare const extractArgIndex: (arg: string) => number | null; export declare const getArgName: (pt: AbiParameter, i: number) => string; /** * inputsPosition map inputs to values * @param fn * @param env * @returns */ export declare const inputsPosition: (fn: AbiFunction, env: Environment) => AnyCell<unknown>[]; /** * isInputDefined checks if a given input is defined */ export declare const isInputDefined: (isOK: boolean, input: unknown) => boolean; /** make ABI creates a new ABI object */ export declare const makeABI: (chain: ChainType, addr: Address<Network>, abi: string[]) => ABI; export declare const mapHumanABI: (l: string[]) => string[]; /** * getABI returns an ABI * @param proxy * @param local * @param addr * @returns * @todo non-EVM */ export declare const getABI: (proxy: SheetProxy, local: LocalSubscriber<CacheQuery>, addr: AnyCell<ChainAddress>, parsedAbi?: Abi) => AnyCell<ABI>; /** * ABIMethodToASTMap takes an ABIMethod, discards its ABIMethodFields * and parses each ABIValue expression into its ASTNode. * * @param method the ABIMethod to parsed expressions. * @returns a map of ASTNode */ export declare const ABIMethodToASTMap: (method: ABIMethod) => Promise<{ [name: string]: ASTNode; }>; /** * abiArgDefinition return a definition for a given ABI argument * @param proxy * @param env * @param fn * @param a * @param pt * @returns */ export declare const abiArgDefinition: (instance: OKPage, env: AnyCell<Environment>, fn: AnyCell<AbiFunction>, a: AnyCell<ABIValue>, pt: AnyCell<AbiParameter>) => AnyCell<LabelledTypeDefinition>; export declare const ABIValueToTypeDefinition: (instance: OKPage, value: AnyCell<ABIValue> | Cellified<ABIValue>, env: AnyCell<Environment>, opts?: { pt?: AnyCell<AbiParameter>; fn?: AnyCell<AbiFunction>; label?: string; }) => MapCell<LabelledTypeDefinition, false>; /** * typeFromABIParam creates a λs type from an AbiParameter. * @param AbiParameter * @returns * @see The generated structure should match the schema definition that * will create inputs in `ABIValueToTypeDefinition`. */ export declare const typeFromABIParam: (param: AbiParameter, av: ABIValue) => MonoType | null; export declare const findMethod: (m: ABIMethod, key: string) => ABIValue | null; /** * $valueDefinition returns a TypeDefinitionFn for the special $value. * @returns */ export declare const $valueDefinition: (instance: OKPage, abi: AnyCell<ABI>) => TypeDefinitionFn; export declare const mergeExtraABIValue: (proxy: SheetProxy, from: AnyCell<TypeDefinition>, m: AnyCell<ABIMethod>, key: string) => MapCell<LabelledTypeDefinition, boolean>; /** * getAbiFunction searches in an ABI a given method or return the first * with at least one input * @param abi * @param name optional method name * @returns AbiFunction */ export declare const getAbiFunction: (abi: Abi, name?: string) => AbiFunction; export declare const proxyImplementation: (proxy: SheetProxy, rpc: LocalRPCSubscriber, chain: AnyCell<ChainType>, addr: AnyCell<Address<Network>>) => MapCell<string, false>;