@jagad/icsi
Version:
Internet Computer Subaccount Indexer Library - TypeScript SDK for ICP multi-token subaccount management, transaction tracking, and automated sweeping with webhook support
132 lines (131 loc) • 8.38 kB
TypeScript
import { HttpAgent } from '@dfinity/agent';
import { Result as AddAccountResult, TokenType } from './userVault.did';
/**
* Calls the refund function on a canister with a specific amount.
* @param {HttpAgent} agent - The HTTP agent used for the call.
* @param {string} userVaultCanisterId - The canister ID of the user vault.
* @param {bigint} amount - The amount to refund.
* @returns {Promise<string>} - The result of the refund operation.
*/
export declare function refund(agent: HttpAgent, userVaultCanisterId: string, amount: bigint): Promise<AddAccountResult>;
/**
* Calls the set_interval function on a canister with a specific interval.
* @param {HttpAgent} agent - The HTTP agent used for the call.
* @param {string} userVaultCanisterId - The canister ID of the user vault.
* @param {bigint} interval - The interval to set.
* @returns {Promise<bigint>} - The set interval value.
*/
export declare function setUserVaultInterval(agent: HttpAgent, userVaultCanisterId: string, interval: bigint): Promise<import("./userVault.did").Result_11>;
/**
* Calls the sweep function on a canister.
* @param {HttpAgent} agent - The HTTP agent used for the call.
* @param {string} userVaultCanisterId - The canister ID of the user vault.
* @returns {Promise<string[]>} - The result of the sweep operation.
*/
export declare function sweep(agent: HttpAgent, userVaultCanisterId: string): Promise<import("./userVault.did").Result_12>;
/**
* Sweeps all subaccounts for a specific token type.
* @param {HttpAgent} agent - The HTTP agent used for the call.
* @param {string} userVaultCanisterId - The canister ID of the user vault.
* @param {TokenType} tokenType - The token type to sweep (ICP, CKUSDC, CKUSDT, or CKBTC).
* @returns {Promise<string[]>} - The result of the sweep operation.
*/
export declare function sweepByTokenType(agent: HttpAgent, userVaultCanisterId: string, tokenType: TokenType): Promise<import("./userVault.did").Result_12>;
/**
* Calls the add_subaccount function on a canister to add a generic subaccount for ICP.
* @param {HttpAgent} agent - The HTTP agent used for the call.
* @param {string} userVaultCanisterId - The canister ID of the user vault.
* @returns {Promise<string>} - The result of the add_subaccount operation.
*/
export declare function addSubaccount(agent: HttpAgent, userVaultCanisterId: string): Promise<AddAccountResult>;
/**
* Adds a new subaccount for a specific token type (ICP, CKUSDC, CKUSDT, or CKBTC).
* @param {HttpAgent} agent - The HTTP agent used for the call.
* @param {string} userVaultCanisterId - The canister ID of the user vault.
* @param {TokenType} tokenType - The token type to create a subaccount for.
* @param {Object} tokenCanisterIds - The canister IDs for the different token types.
* @param {string} [tokenCanisterIds.ckusdcCanisterId="xevnm-gaaaa-aaaar-qafnq-cai"] - The canister ID for CKUSDC token.
* @param {string} [tokenCanisterIds.ckusdtCanisterId="vgmay-piaaa-aaaar-qafoq-cai"] - The canister ID for CKUSDT token.
* @param {string} [tokenCanisterIds.ckbtcCanisterId="mxzaz-hqaaa-aaaar-qaada-cai"] - The canister ID for CKBTC token.
* @param {string} [tokenCanisterIds.icpLedgerCanisterId="ryjl3-tyaaa-aaaaa-aaaba-cai"] - The canister ID for ICP ledger.
* @returns {Promise<AddAccountResult>} - The result of the add_subaccount operation.
*/
export declare function addSubaccountForToken(agent: HttpAgent, userVaultCanisterId: string, tokenType: TokenType, tokenCanisterIds?: {
ckusdcCanisterId?: string;
ckusdtCanisterId?: string;
ckbtcCanisterId?: string;
icpLedgerCanisterId?: string;
}): Promise<AddAccountResult>;
/**
* Calls the clear_transactions function on a canister.
* @param {HttpAgent} agent - The HTTP agent used for the call.
* @param {string} userVaultCanisterId - The canister ID of the user vault.
* @param {bigint} [index] - The optional index to start clearing from.
* @param {object} [timestamp] - The optional timestamp to clear up to.
* @param {bigint} [timestamp.timestamp_nanos] - The timestamp in nanoseconds.
* @returns {Promise<any[]>} - The result of the clear transactions operation.
*/
export declare function clearTransactions(agent: HttpAgent, userVaultCanisterId: string, index?: bigint, timestamp?: {
timestamp_nanos: bigint;
}): Promise<import("./userVault.did").Result_2>;
/**
* Sets a new webhook URL for the user's vault.
* @param {HttpAgent} agent - The HTTP agent used for the call.
* @param {string} userVaultCanisterId - The canister ID of the user vault.
* @param {string} url - The new webhook URL to be set.
* @returns {Promise<void>} - A promise that resolves when the webhook URL is successfully set.
* @throws {Error} - Throws an error if the User Vault Canister ID is undefined.
*/
export declare function setWebhookUrl(agent: HttpAgent, userVaultCanisterId: string, url: string): Promise<AddAccountResult>;
/**
* Registers a new token type with the user vault canister.
* @param {HttpAgent} agent - The HTTP agent used for the call.
* @param {string} userVaultCanisterId - The canister ID of the user vault.
* @param {TokenType} tokenType - The token type to register (ICP, CKUSDC, CKUSDT, or CKBTC).
* @param {string} canisterId - The canister ID for the token ledger.
* @returns {Promise<any>} - A promise that resolves with the result of the register operation.
*/
export declare function registerToken(agent: HttpAgent, userVaultCanisterId: string, tokenType: TokenType, canisterId: string): Promise<import("./userVault.did").Result_10>;
/**
* Sweeps a specific amount from a given subaccount for a specific token type.
* @param {HttpAgent} agent - The HTTP agent used for the call.
* @param {string} userVaultCanisterId - The canister ID of the user vault.
* @param {string} subaccountId - The ID of the subaccount to sweep from.
* @param {number} amount - The amount to sweep.
* @param {TokenType} [tokenType] - The token type to sweep (ICP, CKUSDC, CKUSDT, or CKBTC). Defaults to ICP if not provided.
* @returns {Promise<any>} - A promise that resolves with the result of the sweep operation.
* @throws {Error} - Throws an error if the User Vault Canister ID is undefined.
*/
export declare function sweepSubaccountId(agent: HttpAgent, userVaultCanisterId: string, subaccountId: string, amount: number, tokenType?: TokenType): Promise<import("./userVault.did").Result_11>;
/**
* Converts a subaccount ID to an ICRC account.
* @param {HttpAgent} agent - The HTTP agent used for the call.
* @param {string} userVaultCanisterId - The canister ID of the user vault.
* @param {string} subaccountId - The ID of the subaccount to convert.
* @returns {Promise<AddAccountResult>} - A promise that resolves with the result of the conversion.
*/
export declare function convertToIcrcAccount(agent: HttpAgent, userVaultCanisterId: string, subaccountId: string): Promise<AddAccountResult>;
/**
* Validates if a string is a valid ICRC account.
* @param {HttpAgent} agent - The HTTP agent used for the call.
* @param {string} userVaultCanisterId - The canister ID of the user vault.
* @param {string} account - The account string to validate.
* @returns {Promise<boolean>} - A promise that resolves with the validation result.
*/
export declare function validateIcrcAccount(agent: HttpAgent, userVaultCanisterId: string, account: string): Promise<boolean>;
/**
* Performs a single sweep for a specific transaction.
* @param {HttpAgent} agent - The HTTP agent used for the call.
* @param {string} userVaultCanisterId - The canister ID of the user vault.
* @param {string} txHash - The transaction hash to sweep.
* @returns {Promise<string[]>} - A promise that resolves with the result of the sweep operation.
*/
export declare function singleSweep(agent: HttpAgent, userVaultCanisterId: string, txHash: string): Promise<import("./userVault.did").Result_12>;
/**
* Sets a transaction's sweep status to failed.
* @param {HttpAgent} agent - The HTTP agent used for the call.
* @param {string} userVaultCanisterId - The canister ID of the user vault.
* @param {string} txHash - The transaction hash to mark as failed.
* @returns {Promise<string[]>} - A promise that resolves with the result of the operation.
*/
export declare function setSweepFailed(agent: HttpAgent, userVaultCanisterId: string, txHash: string): Promise<import("./userVault.did").Result_12>;