///
import type { ChainId, CodeHash, CodeId, Address, Message } from '@fadroma/agent';
import { Chain, Stub, Token, Deploy } from '@fadroma/agent';
import { ScrtConsole as Console } from "./scrt-base.dist";
/** Chain instance containing a local mocknet. */
declare class ScrtMocknetConnection extends Stub.StubConnection {
static gasToken: Token.Native;
backend: ScrtMocknetBackend;
constructor(options?: Partial);
get height(): Promise;
get nextBlock(): Promise;
getApi(): Promise<{}>;
doInstantiate(...args: Parameters): Promise;
doExecute(...args: Parameters): Promise;
doQuery(contract: Address | {
address: Address;
}, message: Message): Promise;
}
export { ScrtMocknetConnection as Connection };
declare class ScrtMocknetBatch extends Chain.Batch {
messages: any[];
submit(memo?: string): Promise;
save(name: string): Promise;
upload(...args: Parameters["upload"]>): this;
instantiate(...args: Parameters["instantiate"]>): this;
execute(...args: Parameters["execute"]>): this;
}
export { ScrtMocknetBatch as Batch };
type ScrtCWVersion = '0.x' | '1.x';
interface ScrtMocknetUpload {
chainId: ChainId;
codeId: CodeId;
codeHash: CodeHash;
codeData: Uint8Array;
wasmModule: WebAssembly.Module;
cosmWasmVersion: ScrtCWVersion;
instances: Set;
}
declare class ScrtMocknetBackend extends Stub.StubBackend {
/** Current block height. Increments when accessing nextBlock */
height: number;
uploads: Map;
contracts: Record>;
constructor({ gasToken, prefix, chainId, url, ...args }?: ConstructorParameters[0]);
upload(codeData: Uint8Array): Promise;
instantiate(creator: Address, ...args: Parameters): Promise;
getContract(address?: Address | {
address: Address;
}): ScrtMocknetContract;
execute(sender: Address, { address }: Partial, message: Message, options?: {
execSend?: unknown;
execMemo?: unknown;
execFee?: unknown;
}): Promise;
protected checkVersion(exports: string[]): ScrtCWVersion | null;
protected passCallbacks(cosmWasmVersion: ScrtCWVersion, sender: Address, messages: unknown[]): Promise;
protected passCallbacks_CW0(sender: Address, messages: unknown[]): Promise;
protected passCallbacks_CW1(sender: Address, messages: unknown[]): Promise;
getIdentity(name: string): Promise;
connect(parameter?: string | Partial): Promise;
}
export { ScrtMocknetBackend as Backend };
export type ScrtCWAPI = {
imports: {
memory: WebAssembly.Memory;
env: {
debug(msg: Pointer): Pointer;
db_read(key: Pointer): Pointer;
db_write(key: Pointer, val: Pointer): void;
db_remove(key: Pointer): void;
query_chain(req: Pointer): Pointer;
};
};
exports: Allocator & {
query(msg: Pointer): Pointer;
};
} & ({
/** CosmWasm v0 API */
'0.x': {
imports: {
env: {
canonicalize_address(src: Pointer, dst: Pointer): ErrCode;
humanize_address(src: Pointer, dst: Pointer): ErrCode;
};
};
exports: {
init(env: Pointer, msg: Pointer): Pointer;
handle(env: Pointer, msg: Pointer): Pointer;
};
};
/** CosmWasm v0 API */
'1.x': {
imports: {
memory: WebAssembly.Memory;
env: {
addr_canonicalize(src: Pointer, dst: Pointer): ErrCode;
addr_humanize(src: Pointer, dst: Pointer): ErrCode;
addr_validate(addr: Pointer): ErrCode;
ed25519_sign(msg: Pointer, priv: Pointer): Pointer;
ed25519_verify(msg: Pointer, sig: Pointer, pub: Pointer): Pointer;
ed25519_batch_verify(msgs: Pointer, sigs: Pointer, pubs: Pointer): Pointer;
secp256k1_sign(msg: Pointer, priv: Pointer): Pointer;
secp256k1_verify(hash: Pointer, sig: Pointer, pub: Pointer): Pointer;
secp256k1_recover_pubkey(hash: Pointer, sig: Pointer, param: Pointer): Pointer;
gas_evaporate(...args: any): any;
};
};
exports: {
requires_staking(): Pointer;
instantiate(env: Pointer, info: Pointer, msg: Pointer): Pointer;
execute(env: Pointer, info: Pointer, msg: Pointer): Pointer;
};
};
}[V]);
declare class ScrtMocknetContract {
readonly mocknet: ScrtMocknetBackend;
prefix: string;
log: Console;
address?: Address;
codeHash?: CodeHash;
codeId?: CodeId;
cosmWasmVersion?: V;
runtime?: WebAssembly.Instance['exports']>;
storage: Map;
constructor(mocknet: ScrtMocknetBackend, options?: Partial>);
get initMethod(): Function;
get execMethod(): Function;
get queryMethod(): Function;
pass: (data: any) => Pointer;
readUtf8: (ptr: Pointer) => any;
initPointers: ({ env, info, msg }?: any) => Pointer[];
execPointers: ({ env, info, msg }?: any) => Pointer[];
queryPointers: ({ env, msg }?: any) => Pointer[];
init: ({ sender, env, info, msg }?: Partial<{
sender: Address;
env: object;
info: object;
msg: Message;
}>) => any;
execute: ({ sender, env, info, msg }: {
sender: Address;
env?: object;
info?: object;
msg: Message;
}) => any;
query: ({ env, msg }: {
msg: Message;
env?: object;
}) => any;
makeContext: (sender: Address, now?: number) => {
env: {
block: {
height: number;
time: number;
chain_id: string;
};
message: {
sender: string;
sent_funds: any[];
};
contract: {
address: string;
};
contract_key: string;
contract_code_hash: string;
transaction?: undefined;
};
info?: undefined;
} | {
env: {
block: {
height: number;
time: string;
chain_id: string;
};
transaction: {
index: number;
};
contract: {
address: string;
};
message?: undefined;
contract_key?: undefined;
contract_code_hash?: undefined;
};
info: {
sender: string;
funds: any[];
};
};
makeImports: () => {
imports: ScrtCWAPI['imports'];
refresh: Function;
};
}
export { ScrtMocknetContract as Contract };
declare namespace WebAssembly {
class Module {
static exports(module: Module): {
name: string;
kind: string;
}[];
}
function compile(code: unknown): Promise;
class Instance {
exports: T;
}
function instantiate(code: unknown, world: unknown): Promise['exports']>>;
class Memory {
constructor(options: {
initial: number;
maximum: number;
});
buffer: any;
}
}
/** Error code returned by contract. */
type ErrCode = number;
/** Address in WASM VM memory. */
type Pointer = number;
/** Number of bytes. */
type Size = number;
/** Memory region as allocated by CosmWasm */
type Region = [Pointer, Size, Size, Uint32Array?];
/** Heap with allocator for talking to WASM-land */
interface Allocator {
memory: WebAssembly.Memory;
allocate(len: Size): Pointer;
deallocate?(ptr: Pointer): void;
}
export declare const codeHashForBlob: (blob: Uint8Array) => string;
/** Convert a Result returned from Rust side to Ok or throw */
export declare const parseResult: (response: {
Ok: any;
Err: any;
}, action: 'instantiate' | 'execute' | 'query' | 'query_chain', address?: Address) => any;
/** Read region properties from pointer to region. */
export declare const region: (buffer: any, ptr: Pointer) => Region;
/** Read contents of region referenced by region pointer into a string. */
export declare const readUtf8: ({ memory: { buffer }, deallocate }: Allocator, ptr: Pointer) => string;
/** Read contents of region referenced by region pointer into a string. */
export declare const readBuffer: ({ memory: { buffer } }: Allocator, ptr: Pointer) => Buffer;
/** Serialize a datum into a JSON string and pass it into the contract. */
export declare const passJson: (memory: Allocator, data: T) => Pointer;
/** Allocate region, write data to it, and return the pointer.
* See: https://github.com/KhronosGroup/KTX-Software/issues/371#issuecomment-822299324 */
export declare const passBuffer: ({ memory, allocate }: Allocator, data: ArrayLike) => Pointer;
/** Write UTF8-encoded data to address of region referenced by pointer. */
export declare const writeToRegionUtf8: (memory: Allocator, ptr: Pointer, data: string) => void;
/** Write data to address of region referenced by pointer. */
export declare const writeToRegion: ({ memory: { buffer } }: Allocator, ptr: Pointer, data: ArrayLike) => void;
/** Write data to memory address. */
export declare const write: (buffer: ArrayLike, addr: number, data: ArrayLike) => void;
/** Write UTF8-encoded data to memory address. */
export declare const writeUtf8: (buffer: ArrayLike, addr: number, data: string) => void;
/** Deallocate memory. Fails silently if no deallocate callback is exposed by the blob. */
export declare const drop: ({ deallocate }: {
deallocate: Allocator['deallocate'];
}, ptr: Pointer) => void;
/** Convert base64 string to utf8 string */
export declare const b64toUtf8: (str: string) => string;
/** Convert utf8 string to base64 string */
export declare const utf8toB64: (str: string) => string;
/** Convert utf8 string to buffer. */
export declare const utf8toBuffer: (str: string) => Buffer;
/** Convert buffer to utf8 string. */
export declare const bufferToUtf8: (buf: Buffer) => string;
//# sourceMappingURL=scrt-mocknet.d.ts.map