@okcontract/sdk
Version:
One-stop-shop permissionless SDK for building any blockchain frontend
121 lines (120 loc) • 4.49 kB
TypeScript
import { type TransactionRequest } from "viem";
import type { AnyCell, SheetProxy } from "@okcontract/cells";
import { type CacheQuery, type NetworkTXQueryType, OKWidgetApproveStep, type OKWidgetStep, type OKWidgetStepType } from "@okcontract/coredata";
import type { Environment, Rational } from "@okcontract/lambdascript";
import { type Address, type ChainAddress, type ChainType, type LocalRPCSubscriber, type Network } from "@okcontract/multichain";
import type { OKCore } from "./coreExecution";
import type { OKPage } from "./instance";
/**
* Step
*/
export type Step<T extends OKWidgetStepType> = OKWidgetStep<T> & (T extends typeof OKWidgetApproveStep ? Approval & ERC721ApprovalStep : {});
export type ApprovalStep = OKWidgetStep<typeof OKWidgetApproveStep> & (Approval | ERC721ApprovalStep);
export type Stepper = {
/** current step*/
cur: number;
/** total nb steps without approvals*/
sub_total: number;
/** steps */
steps: Step<OKWidgetStepType>[];
/** @deprecated */
txs?: string[];
/** is loading from a tx */
loading: boolean;
};
export type Approval = {
amount?: number | bigint;
allowance?: bigint;
done: boolean;
spender: Address<Network>;
tx?: Address<Network>;
def: unknown;
};
export type ERC721ApprovalStep = {
tokenID?: number | bigint;
done: boolean;
spender: Address<Network>;
tx?: Address<Network>;
def: unknown;
};
/**
* approval computes the approval parameters for all steps.
* @param ch chain
* @param spender address
* @deprecated
* @returns ApprovalStep
*/
export declare const approval: (instance: OKPage, step: Step<OKWidgetStepType>, spender: Address<Network>, env: Environment) => ([evm, desiredAmount, def]: [ChainAddress, bigint | number, unknown]) => import("@okcontract/cells").MapCell<OKWidgetStep<"app" | "sig" | "wait" | "ntx" | "call" | "aft"> | {
xm: {
[x: string]: Address<Network> | import("@okcontract/coredata").ABIValue;
"@t"?: string[];
"@i"?: string[];
"@b"?: string[];
"@img"?: string;
"@a"?: Record<string, string>;
"@rcpt"?: string[];
"@pre"?: string[];
"@adm"?: boolean;
"@aft"?: Record<string, string>;
};
sty: string;
tokenID: number | bigint;
done: boolean;
def: unknown;
org?: string;
q?: import("@okcontract/coredata").ContractQueryType | import("@okcontract/coredata").TokenQueryType | import("@okcontract/coredata").AnonContractQueryType<ChainType>;
chain?: ChainType;
m?: string;
sig?: string;
ntx?: string;
fch?: ChainType[];
skip?: string;
} | {
xm: {
[x: string]: Address<Network> | import("@okcontract/coredata").ABIValue;
"@t"?: string[];
"@i"?: string[];
"@b"?: string[];
"@img"?: string;
"@a"?: Record<string, string>;
"@rcpt"?: string[];
"@pre"?: string[];
"@adm"?: boolean;
"@aft"?: Record<string, string>;
};
sty: string;
tokenID: number | bigint;
done: boolean;
def: unknown;
org?: string;
q?: import("@okcontract/coredata").ContractQueryType | import("@okcontract/coredata").TokenQueryType | import("@okcontract/coredata").AnonContractQueryType<ChainType>;
chain?: ChainType;
m?: string;
sig?: string;
ntx?: string;
fch?: ChainType[];
skip?: string;
amount?: number | bigint;
allowance?: bigint;
spender: Address<Network>;
tx?: Address<Network>;
}, false>;
export type TXRequest = TransactionRequest & {
gasLimit: `0x${string}`;
};
export declare const generateTX: (rpc: LocalRPCSubscriber, proxy: SheetProxy, core: OKCore, contractAddr: AnyCell<ChainAddress>, data: AnyCell<`0x${string}`>, value: AnyCell<Rational>, enableGasEstimation?: boolean) => import("@okcontract/cells").MapCell<{
tx: {
from: `0x${string}` | import("@okcontract/multichain/src/address").StringAddressTON;
to: `0x${string}` | import("@okcontract/multichain/src/address").StringAddressTON;
data: `0x${string}`;
value: `0x${string}`;
};
}, false>;
export declare const generate_ntx_query: (env: Environment, step: Step<OKWidgetStepType>) => Promise<NetworkTXQueryType>;
/**
* getOrgName returns org name
* @param core
* @param currentStep
* @returns
*/
export declare const getOrgName: (core: OKCore, env: Environment, query: CacheQuery, sty: OKWidgetStepType, org?: string) => Promise<string | AnyCell<string>>;