///
///
import { types as rtypes } from "@algorand-builder/runtime";
import type { LogicSig, LogicSigArgs } from "algosdk";
import * as algosdk from "algosdk";
import * as types from "./internal/core/params/argument-types";
export interface AlgobAccount {
name: string;
mnemonic: string;
}
export interface HDAccount {
mnemonic: string;
initialIndex?: number;
count?: number;
path: string;
}
export interface MnemonicAccount {
name: string;
addr: string;
mnemonic: string;
}
export declare type AccountDef = MnemonicAccount | HDAccount | rtypes.Account;
interface CommonNetworkConfig {
accounts: rtypes.Account[];
kmdCfg?: KmdCfg;
chainName?: string;
}
export interface AlgobChainCfg extends CommonNetworkConfig {
throwOnTransactionFailures?: boolean;
throwOnCallFailures?: boolean;
loggingEnabled?: boolean;
initialDate?: string;
}
export interface HttpNetworkConfig extends CommonNetworkConfig {
host: string;
port: number;
token: string;
httpHeaders?: {
[name: string]: string;
};
}
export declare type NetworkConfig = AlgobChainCfg | HttpNetworkConfig;
export interface Networks {
[networkName: string]: NetworkConfig;
}
export interface KmdWallet {
name: string;
password: string;
accounts: Array<{
name: string;
address: string;
}>;
}
export interface KmdCfg {
host: string;
port: number;
token: string;
wallets: KmdWallet[];
}
export interface NetworkCredentials {
host: string;
port: number;
token: string;
}
/**
* The project paths:
* * root: the project's root.
* * configFile: the algob's config filepath.
* * cache: project's cache directory.
* * artifacts: artifact's directory.
* * sources: project's sources directory.
* * tests: project's tests directory.
*/
export interface ProjectPaths {
root: string;
configFile: string;
cache: string;
artifacts: string;
sources: string;
tests: string;
}
export declare type UserPaths = Omit, "configFile">;
export interface AlgobConfig {
networks?: Networks;
paths?: UserPaths;
mocha?: Mocha.MochaOptions;
}
export interface ResolvedAlgobConfig extends AlgobConfig {
paths?: ProjectPaths;
networks: Networks;
}
/**
* A function that receives a AlgobRuntimeEnv and
* modify its properties or add new ones.
*/
export declare type EnvironmentExtender = (env: AlgobRuntimeEnv) => void;
export declare type ConfigExtender = (config: ResolvedAlgobConfig, userConfig: Readonly) => void;
export interface TasksMap {
[name: string]: TaskDefinition;
}
export interface ConfigurableTaskDefinition {
setDescription: (description: string) => this;
setAction: (action: ActionType) => this;
addParam: (name: string, description?: string, defaultValue?: T, type?: types.ArgumentType, isOptional?: boolean) => this;
addOptionalParam: (name: string, description?: string, defaultValue?: T, type?: types.ArgumentType) => this;
addPositionalParam: (name: string, description?: string, defaultValue?: T, type?: types.ArgumentType, isOptional?: boolean) => this;
addOptionalPositionalParam: (name: string, description?: string, defaultValue?: T, type?: types.ArgumentType) => this;
addVariadicPositionalParam: (name: string, description?: string, defaultValue?: T[], type?: types.ArgumentType, isOptional?: boolean) => this;
addOptionalVariadicPositionalParam: (name: string, description?: string, defaultValue?: T[], type?: types.ArgumentType) => this;
addFlag: (name: string, description?: string) => this;
}
export interface ParamDefinition {
name: string;
shortName?: string;
defaultValue?: T;
type: types.ArgumentType;
description?: string;
isOptional: boolean;
isFlag: boolean;
isVariadic: boolean;
}
export declare type ParamDefinitionAny = ParamDefinition;
export interface OptionalParamDefinition extends ParamDefinition {
defaultValue: T;
isOptional: true;
}
export interface ParamDefinitionsMap {
[paramName: string]: ParamDefinitionAny;
}
/**
* Algob arguments:
* + network: the network to be used (default="default").
* + showStackTraces: flag to show stack traces.
* + version: flag to show algob's version.
* + help: flag to show algob's help message.
* + config: used to specify algob's config file.
*/
export interface RuntimeArgs {
network: string;
showStackTraces: boolean;
version: boolean;
help: boolean;
config?: string;
verbose: boolean;
}
export declare type AlgobParamDefinitions = {
[param in keyof Required]: OptionalParamDefinition;
};
export interface AlgobShortParamSubstitutions {
[name: string]: string;
}
export interface TaskDefinition extends ConfigurableTaskDefinition {
readonly name: string;
readonly description?: string;
readonly action: ActionType;
readonly isInternal: boolean;
readonly paramDefinitions: ParamDefinitionsMap;
readonly positionalParamDefinitions: ParamDefinitionAny[];
}
/**
* @type TaskArguments {object-like} - the input arguments for a task.
*
* TaskArguments type is set to 'any' because it's interface is dynamic.
* It's impossible in TypeScript to statically specify a variadic
* number of fields and at the same time define specific types for\
* the argument values.
*
* For example, we could define:
* type TaskArguments = Record;
*
* ...but then, we couldn't narrow the actual argument value's type in compile time,
* thus we have no other option than forcing it to be just 'any'.
*/
export declare type TaskArguments = any;
export declare type RunTaskFunction = (name: string, taskArguments?: TaskArguments) => PromiseAny;
export interface RunSuperFunction {
(taskArguments?: ArgT): PromiseAny;
isDefined: boolean;
}
export declare type ActionType = (taskArgs: ArgsT, env: AlgobRuntimeEnv, runSuper: RunSuperFunction) => PromiseAny;
export interface Network {
name: string;
config: NetworkConfig;
}
export interface AlgobRuntimeEnv {
readonly config: ResolvedAlgobConfig;
readonly runtimeArgs: RuntimeArgs;
readonly tasks: TasksMap;
readonly run: RunTaskFunction;
readonly network: Network;
}
export interface Artifact {
contractName: string;
abi: any;
bytecode: string;
deployedBytecode: string;
linkReferences: LinkReferences;
deployedLinkReferences: LinkReferences;
}
export interface LinkReferences {
[libraryFileName: string]: {
[libraryName: string]: Array<{
length: number;
start: number;
}>;
};
}
export declare type AccountAddress = string;
export interface DeployedAssetInfo {
creator: AccountAddress;
txId: string;
confirmedRound: number;
}
export interface ASAInfo extends DeployedAssetInfo {
assetIndex: number;
}
export interface SSCInfo extends DeployedAssetInfo {
appID: number;
}
export interface LsigInfo {
creator: AccountAddress;
contractAddress: string;
lsig: LogicSig;
}
/**
* Checkpoint implementation
*/
export interface CheckpointRepo {
/**
* Accumulates state as scripts are executed. This way it hides values generated by
* remaining checkpoints. It is what should be exposed to the running scripts. */
precedingCP: Checkpoints;
/**
* Variables that current script introduced, short version of what was added.
* Used for state persistence. */
strippedCP: Checkpoints;
/**
* All possible values that are loaded in advance.
* This allows to prevent asset name clashes between scripts. */
allCPs: Checkpoints;
merge: (c: Checkpoints, scriptName: string) => CheckpointRepo;
mergeToGlobal: (c: Checkpoints, scriptName: string) => CheckpointRepo;
/**
* Sets metadata key-value for a specified network. */
putMetadata: (networkName: string, key: string, value: string) => CheckpointRepo;
/**
* Gets metadata key-value for a specified network. */
getMetadata: (networkName: string, key: string) => string | undefined;
registerASA: (networkName: string, name: string, info: ASAInfo) => CheckpointRepo;
registerSSC: (networkName: string, name: string, info: SSCInfo) => CheckpointRepo;
registerLsig: (networkName: string, name: string, info: LsigInfo) => CheckpointRepo;
isDefined: (networkName: string, name: string) => boolean;
networkExistsInCurrentCP: (networkName: string) => boolean;
}
export interface Checkpoints {
[network: string]: Checkpoint;
}
export interface Checkpoint {
timestamp: number;
metadata: Map;
asa: Map;
ssc: Map;
dLsig: Map;
}
export interface FundASCFlags {
funder: rtypes.Account;
fundingMicroAlgo: number;
}
export interface AssetScriptMap {
[assetName: string]: string;
}
export interface AlgobDeployer {
/**
* Allows user to know whether a script is running in a `deploy` or `run` mode. */
isDeployMode: boolean;
accounts: rtypes.Account[];
accountsByName: rtypes.AccountMap;
/**
* Mapping of ASA name to deployment log */
asa: Map;
/**
* Sets metadata key value for a current network in the chckpoint file based on the
* current deployment script. If run in a non deployment mode (eg `algob run script_name.js`)
* it will throw an exception. */
addCheckpointKV: (key: string, value: string) => void;
/**
* Queries metadata key in all checkpoint files of current network. If the key is not defined
* in any checkpoint then `undefined` is returned. Can be run in both _run_ and _deploy_ mode.
*/
getCheckpointKV: (key: string) => string | undefined;
/**
* Creates and deploys ASA.
* @name ASA name - deployer will search for the ASA in the /assets/asa.yaml file
* @flags deployment flags */
deployASA: (name: string, flags: rtypes.ASADeploymentFlags) => Promise;
/**
* Funds logic signature account (Contract Account).
* @name Stateless Smart Contract filename (must be present in assets folder)
* @payFlags Transaction Parameters
* @scParams Smart contract parameters (used while calling smart contract)
* @scTmplParams Smart contract template parameters
* (used only when compiling PyTEAL to TEAL)
*/
fundLsig: (name: string, flags: FundASCFlags, payFlags: rtypes.TxParams, scParams: LogicSigArgs, scTmplParams?: SCParams) => void;
/**
* Makes delegated logic signature signed by the `signer`.
* @name Stateless Smart Contract filename (must be present in assets folder)
* @signer Signer Account which will sign the smart contract
* @scParams Smart contract parameters (used while calling smart contract)
* @scTmplParams Smart contract template parameters
* (used only when compiling PyTEAL to TEAL)
*/
mkDelegatedLsig: (name: string, signer: rtypes.Account, scParams: LogicSigArgs, scTmplParams?: SCParams) => Promise;
/**
* Deploys stateful smart contract.
* @approvalProgram approval program filename (must be present in assets folder)
* @clearProgram clear program filename (must be present in assets folder)
* @flags SSCDeploymentFlags
* @payFlags Transaction Parameters
* @scTmplParams Smart contract template parameters
* (used only when compiling PyTEAL to TEAL)
*/
deploySSC: (approvalProgram: string, clearProgram: string, flags: rtypes.SSCDeploymentFlags, payFlags: rtypes.TxParams, scTmplParams?: SCParams) => Promise;
/**
* Returns true if ASA or DelegatedLsig or SSC were deployed in any script.
* Checks even for checkpoints which are out of scope from the execution
* session and are not obtainable using get methods.
*/
isDefined: (name: string) => boolean;
algodClient: algosdk.Algodv2;
/**
* Queries blockchain for a given transaction and waits until it will be processed. */
waitForConfirmation: (txId: string) => Promise;
/**
* Creates an opt-in transaction for given ASA name, which must be defined in
* `/assets/asa.yaml` file. The opt-in transaction is signed by the account secret key */
optInAcountToASA: (name: string, accountName: string, flags: rtypes.TxParams, sign: rtypes.Sign) => Promise;
/**
* Creates an opt-in transaction for given ASA name, which must be defined in
* `/assets/asa.yaml` file. The opt-in transaction is signed by the logic signature */
optInLsigToASA: (asaName: string, lsig: LogicSig, flags: rtypes.TxParams) => Promise;
/**
* Creates an opt-in transaction for given Stateful Smart Contract (SSC). The SSC must be
* already deployed.
* @sender Account for which opt-in is required
* @appId Application Index (ID of the application)
*/
optInToSSC: (sender: rtypes.Account, index: number, payFlags: rtypes.TxParams, flags: rtypes.SSCOptionalFlags) => Promise;
/**
* Create an entry in a script log (stored in artifacts/scripts/.log) file. */
log: (msg: string, obj: any) => void;
/**
* Extracts multi signed logic signature file from `assets/`. */
loadMultiSig: (name: string, scParams: LogicSigArgs) => Promise;
/**
* Queries a stateful smart contract info from checkpoint. */
getSSC: (nameApproval: string, nameClear: string) => SSCInfo | undefined;
/**
* Queries a delegated logic signature from checkpoint. */
getDelegatedLsig: (lsigName: string) => Object | undefined;
/**
* Loads contract mode logic signature (TEAL or PyTEAL)
* @name Smart Contract filename (must be present in assets folder)
* @scParams Smart contract parameters (Used while calling smart contract)
* @scTmplParams Smart contract template parameters
* (used only when compiling PyTEAL to TEAL)
*/
loadLogic: (name: string, scParams: LogicSigArgs, scTmplParams?: SCParams) => Promise;
/**
* Returns ASCCache (with compiled code)
* @name Smart Contract filename (must be present in assets folder)
* @force if force is true file will be compiled for sure, even if it's checkpoint exist
* @scTmplParams scTmplParams: Smart contract template parameters
* (used only when compiling PyTEAL to TEAL)
*/
ensureCompiled: (name: string, force?: boolean, scTmplParams?: SCParams) => Promise;
}
export interface ASCCache {
filename: string;
timestamp: number;
compiled: string;
compiledHash: string;
srcHash: number;
base64ToBytes: Uint8Array;
}
export interface PyASCCache extends ASCCache {
tealCode: string;
}
export interface StrMap {
[key: string]: string;
}
export interface SCParams {
[key: string]: string | bigint;
}
export interface AnyMap {
[key: string]: any;
}
export declare type PromiseAny = Promise;
export {};