@okcontract/sdk
Version:
One-stop-shop permissionless SDK for building any blockchain frontend
138 lines (137 loc) • 5.96 kB
TypeScript
import type { AbiFunction } from "abitype";
import { type Abi, type Log, type TransactionReceipt } from "viem";
import { type AnyCell, type CellArray, type Cellified, type MapCell, type ValueCell } from "@okcontract/cells";
import { type ABI, type ABIExtra, type OKToken, type OKWidgetStepType, type TokenMarketData } from "@okcontract/coredata";
import { DataEditor, type TypeScheme } from "@okcontract/fred";
import { type Environment, Rational, type ValueDefinition } from "@okcontract/lambdascript";
import type { Value } from "@okcontract/lambdascript/src/eval";
import type { Chain, ChainAddress, ChainType, GetEstimateGas, Network } from "@okcontract/multichain";
import { type RawRPCQuery } from "@okcontract/multichain";
import type { AnalyzedLog } from "./analyze";
import type { OKPage } from "./instance";
import { type AnyContractQuery, type DataOfContractQuery, type OKContract, OKContractManager } from "./okcontract";
import { type Step, type TXRequest } from "./steps";
import type { SentTransaction } from "./tx";
import type { Transaction } from "./wallet";
type Options = {
abi?: Abi;
extraEnv?: ValueDefinition[];
settingsEnv?: Environment;
forceTXGeneration?: boolean;
/** override title */
title?: MapCell<unknown[], false>;
/** override info */
info?: MapCell<unknown[], false>;
/** override org */
org?: MapCell<string, false>;
okc?: OKContractManager;
editor?: AnyCell<DataEditor>;
isPreOk?: MapCell<boolean, false>;
};
export declare const filterMapByKeys: <T>(map: Map<string, T>, predicate: (key: string) => boolean) => Map<string, T>;
/**
* OKTransaction is a class containing all information relating to a
* single blockchain transaction from its creation (inputs), computations,
* submission and log analysis after mining.
*/
export declare class OKTransaction<Query extends AnyContractQuery> {
private readonly _instance;
private _counter;
private readonly _core;
private readonly _okc;
private readonly _options;
readonly okStep: Cellified<Step<OKWidgetStepType>>;
/** stepper env */
readonly $value: ValueCell<Rational>;
readonly function: AnyCell<AbiFunction>;
/** check if target method is on the right chain*/
readonly chainOK: AnyCell<boolean>;
readonly okContract: AnyCell<OKContract<Query>>;
readonly contractChain: AnyCell<ChainType>;
readonly chain: AnyCell<Chain>;
readonly chains: AnyCell<Map<ChainType, ChainAddress<"evm">>>;
readonly address: AnyCell<ChainAddress>;
readonly contractData: AnyCell<DataOfContractQuery<Query>>;
readonly abi: AnyCell<ABI>;
readonly abix: AnyCell<ABIExtra>;
readonly inputEnv: Environment;
/** schema of the transaction */
readonly schema: TypeScheme;
/** tx data (from schema values) */
readonly data: AnyCell<Environment>;
readonly editor: AnyCell<DataEditor>;
/** OKTransaction environment */
readonly env: MapCell<Environment, false>;
readonly missingInputs: MapCell<string[], false>;
readonly org: MapCell<string, false>;
readonly btnLabel: MapCell<string, false>;
readonly title: MapCell<unknown[], false>;
readonly info: MapCell<unknown[], false>;
readonly infoLine: MapCell<string, false>;
readonly button: MapCell<Value<string>[], false>;
readonly image: MapCell<string, boolean>;
readonly allowances: MapCell<[string, Value<unknown>][], boolean>;
/** tx inputs */
readonly txInputs: MapCell<AnyCell<unknown>[], false>;
private _txInputsUncellified;
readonly inputsOK: MapCell<boolean, false>;
/** if preconditions are met */
readonly isPreOk: MapCell<boolean, false>;
/** if tx can be sent */
readonly canSendTX: MapCell<boolean, false>;
/** this transaction can be skipped */
readonly skip: AnyCell<boolean>;
/** encoded data */
readonly encodedData: MapCell<`0x${string}`, false>;
/** the tx to be sent */
readonly tx: MapCell<{
tx: TXRequest;
gas_amount: bigint;
}, false>;
/** built tx to be sent */
readonly readyTx: MapCell<Transaction<Network>, false>;
/** the result of readonly method */
readonly readOutput: MapCell<Record<number, AnyCell<unknown>>, false>;
/** the sent transaction */
readonly sentTx: ValueCell<SentTransaction[]>;
/** tx receipt */
readonly receipt: AnyCell<TransactionReceipt>;
/** list of receipts */
readonly receipts: ValueCell<TransactionReceipt[]>;
/** raw logs from receipt */
readonly rawLogs: AnyCell<AnyCell<Log>[]>;
/** tx logs */
readonly $logs: AnyCell<AnyCell<AnalyzedLog>[]>;
/** prettified logs */
readonly prettyLogs: CellArray<string[]>;
/** tx is processing */
readonly isSending: ValueCell<boolean>;
/** tx has be processed */
readonly isDone: ValueCell<boolean>;
readonly decimals: AnyCell<Rational>;
readonly tokenPriceData: AnyCell<TokenMarketData>;
readonly currency: AnyCell<OKToken>;
constructor(instance: OKPage, step: Cellified<Step<OKWidgetStepType>>, opts?: Options);
/**
* setValue sets the $value cell containing the transaction value.
* @param v any float or integer number, without decimals conversion, or exact `bigint`
* @example tx.setValue(0.001)
*/
setValue: (v: number | bigint) => void;
/**
* sendTX submits the transaction on-chain.
* @returns block hash
*
* @todo sendTX should be synchronous and return a cell of the hash
*/
sendTX: () => Promise<`0x${string}`>;
/**
* Sign the raw transaction, for the few EOAs that support it.
* @todo should be a ValueCell?
*/
signTX: () => Promise<any>;
switchChain: () => void;
_approvalRefresh: (_receipt: TransactionReceipt | Error, _allowanceQuery: AnyCell<[ChainType, RawRPCQuery]>, _estimateQuery: AnyCell<[ChainType, GetEstimateGas]>) => Promise<void>;
wait(): Promise<void>;
}
export {};