UNPKG

shield-bridge-sdk

Version:
354 lines (353 loc) 15.9 kB
import { ContractMethodObject, Estimate, TezosToolkit, Wallet } from '@taquito/taquito'; export declare const tzktApiMap: { mainnet: string; ghostnet: string; }; export declare const saplingStateMapContract: { mainnet: string; ghostnet: string; }; type OrderedTransactionList = [ ContractMethodObject<Wallet>[], ContractMethodObject<Wallet>[], { txns: (string | void)[]; contract?: string; token_id?: number; amount?: number | string; }[], ContractMethodObject<Wallet>[] ]; interface SaplingDeposits { amount: number | string; saplingTransactions: (string | void)[]; owner?: string; contract?: string; tokenId?: number; } interface SaplingTransactions { saplingTransactions: (string | void)[]; contract?: string; tokenId?: number; } interface ShieldParams { amount: number; shieldedAddress?: string; contract?: string; tokenId?: number; memo?: string; } interface UnshieldParams { amount: number; unshieldedAddress?: string; contract?: string; tokenId?: number; } interface TransferParams { contract?: string; tokenId?: number; transfers: { amount: number; to: string; memo?: string; }[]; } interface SaplingTokenInfo { saplingId?: number; contract?: string; tokenId?: number; } type ShieldBridgeSDKConfig = { client: TezosToolkit; tzktApi?: 'mainnet' | 'ghostnet'; minConfirmations?: number; saplingStateMapContract?: string; gasLimitBuffer?: number; storageLimitBuffer?: number; useBaseUnits?: boolean; parallelThreads?: boolean; } & ({ saplingSecret: string; saplingMnemonic?: never; } | { saplingSecret?: never; saplingMnemonic: string; }); /** * ShieldBridgeSDK provides an abstraction to interact with the Shield Bridge smart contract * to shield, unshield, and transfer sapling tokens. * @class * @param {ShieldBridgeSDKConfig} config The configuration object for the Shield Bridge SDK * @param {TezosToolkit} config.client The TezosToolkit instance * @param {'mainnet' | 'ghostnet'} [config.tzktApi='mainnet'] The tzkt API to use * @param {number} [config.minConfirmations=1] The minimum number of confirmations for the transaction * @param {string} [config.saplingStateMapContract='KT1WorWEWjfQqQ1X2BFQiCc4hE3DuDKQVH4U'] The sapling state map contract address * @param {number} [config.gasLimitBuffer=2_000] The buffer to add to the estimated gas limit * @param {number} [config.storageLimitBuffer=500] The buffer to add to the estimated storage limit * @param {boolean} [config.useBaseUnits=false] Whether to use base unit for the token amounts (mutez or token units with decimals) * @param {number} [config.parallelThreads=false] Whether to spawn parallel threads for the sapling worker * @param {string} [config.saplingSecret] The sapling secret key * @param {string} [config.saplingMnemonic] The sapling mnemonic * @returns {ShieldBridgeSDK} The Shield Bridge SDK instance * @example * const tezos = new TezosToolkit('https://mainnet.api.tez.ie'); * const signerProvider = await InMemorySigner.fromSecretKey('edsk...'); * tezos.setSignerProvider(signerProvider); * const shieldBridge = new ShieldBridgeSDK({ * client: tezos, * saplingSecret: 'sask...' * }); * await shieldBridge.shield([ * { * amount: 1, * contract: 'KT1...', * tokenId: 0, * memo: 'abcdefgh' * } * ]); */ export declare class ShieldBridgeSDK { private config; private tezosClient; private saplingWorker; saplingStateMapContract: string; minConfirmations: number; gasLimitBuffer: number; storageLimitBuffer: number; useBaseUnits: boolean; parallelThreads: boolean; ready: Promise<boolean>; constructor(config: ShieldBridgeSDKConfig); initializeSaplingWorker: () => Promise<boolean>; /** * @description Get the sapling id for the token contract and token id if provided * @param {string} [contract] The token contract address * @param {number} [tokenId] The token id * @returns The sapling id for the token contract and token id if provided */ getSaplingId: (contract?: string, tokenId?: number) => Promise<number | undefined>; /** * @description Get the metadata for the token contract and token id if provided * @param {string} contract The token contract address * @param {number} [tokenId] The token id * @returns The metadata for the token contract and token id if provided */ getTokenMetadata: (contract: string, tokenId?: number) => Promise<import("@tzkt/sdk-api").Token>; /** * @description Get the number of decimals for the token contract and token id if provided * @param {string} contract The token contract address * @param {number} [tokenId] The token id * @returns The number of decimals for the token contract and token id if provided */ getTokenDecimals: (contract: string, tokenId?: number) => Promise<number>; /** * @description Estimate the gas and storage limits for the transaction list of shielding transactions * @param {OrderedTransactionList} transactionList The constructed transaction list * @returns The estimated gas and storage limits for the transaction list */ estimateShieldTransactionLimits: (transactionList: OrderedTransactionList) => Promise<Estimate[]>; /** * @description Get the estimated fee for the transaction * @param {Estimate} estimate The estimate object * @returns The estimated fee for the transaction */ getEstimatedFee: (estimate: Estimate) => number; /** * @description Submit sapling deposits/shielding transactions * @param {SaplingDeposits} saplingDeposits Sapling deposits/shielding transactions to be submitted * @param {number} saplingDeposits.amount The amount to be shielded * @param {string[]} saplingDeposits.saplingTransactions The sapling transactions to be submitted * @param {string} [saplingDeposits.contract] The token contract address * @param {number} [saplingDeposits.tokenId] The token id * @param {string} [saplingDeposits.owner] The shielded address to apply the shielded tokens * @returns The confirmation of the submitted sapling deposits/shielding transactions */ submitSaplingShieldTransaction: (saplingDeposits: SaplingDeposits[]) => Promise<{ block: import("@taquito/rpc").BlockResponse; expectedConfirmation: number; currentConfirmation: number; completed: boolean; isInCurrentBranch: () => Promise<boolean>; } | undefined>; /** * @description Submit sapling withdrawals/unshielding transactions * @param {SaplingTransactions} saplingWithdrawals Sapling withdrawals/unshielding transactions to be submitted * @param {string[]} saplingWithdrawals.saplingTransactions The sapling transactions to be submitted * @param {string} [saplingWithdrawals.contract] The token contract address * @param {number} [saplingWithdrawals.tokenId] The token id * @returns The confirmation of the submitted sapling withdrawals/unshielding transactions */ submitSaplingUnshieldTransaction: (saplingWithdrawals: SaplingTransactions[]) => Promise<{ block: import("@taquito/rpc").BlockResponse; expectedConfirmation: number; currentConfirmation: number; completed: boolean; isInCurrentBranch: () => Promise<boolean>; } | undefined>; /** * @description Submit sapling transfers transactions * @param {SaplingTransactions} saplingTransfers Sapling transfers to be submitted * @param {string[]} saplingTransfers.saplingTransactions The sapling transactions to be submitted * @param {string} [saplingTransfers.contract] The token contract address * @param {number} [saplingTransfers.tokenId] The token id * @returns The confirmation of the submitted sapling transfers */ submitSaplingTransferTransaction: (saplingTransfers: SaplingTransactions[]) => Promise<{ block: import("@taquito/rpc").BlockResponse; expectedConfirmation: number; currentConfirmation: number; completed: boolean; isInCurrentBranch: () => Promise<boolean>; } | undefined>; /** * @description Construct the sapling parameters for the shielded transaction * @param shieldParam The sapling shielding parameters * @param {number} shieldParam.amount The amount to be shielded * @param {string} [shieldParam.shieldedAddress] The shielded address to apply the shielded tokens * @param {string} [shieldParam.contract] The token contract address * @param {number} [shieldParam.tokenId] The token id * @param {string} [shieldParam.memo] The memo to be included in the sapling transaction * @returns The sapling parameters for the shielded transaction */ constructShieldTokenParams: (shieldParam: ShieldParams) => Promise<{ saplingTransactions: (string | void)[]; owner: string; amount: string | number; contract: string | undefined; tokenId: number | undefined; }>; /** * @description Shield the specified amount of unshielded tokens to the sapling address * @param {ShieldParams} shieldParams Sapling shielding parameters to be constructed into sapling transactions * @param {number} shieldParams.amount The amount to be shielded * @param {string} [shieldParams.shieldedAddress] The shielded address to apply the shielded tokens * @param {string} [shieldParams.contract] The token contract address * @param {number} [shieldParams.tokenId] The token id * @param {string} [shieldParams.memo] The memo to be included in the sapling transaction * @returns The confirmation of the submitted sapling shielding transactions */ shield: (shieldParams: ShieldParams[]) => Promise<{ block: import("@taquito/rpc").BlockResponse; expectedConfirmation: number; currentConfirmation: number; completed: boolean; isInCurrentBranch: () => Promise<boolean>; } | undefined>; /** * @description Construct the sapling parameters for the unshielded transaction * @param unshieldParam The sapling unshielding parameters * @param {number} unshieldParam.amount The amount to be unshielded * @param {string} [unshieldParam.unshieldedAddress] The unshielded address to apply the unshielded tokens * @param {string} [unshieldParam.contract] The token contract address * @param {number} [unshieldParam.tokenId] The token id * @returns The sapling parameters for the unshielded transaction */ constructUnshieldTokenParams: (unshieldParam: UnshieldParams) => Promise<{ saplingTransactions: (string | void)[]; contract: string | undefined; tokenId: number | undefined; }>; /** * @description Unshield the specified amount of shielded tokens from the sapling address * @param {UnshieldParams} unshieldParams Sapling unshielding parameters to be constructed into sapling transactions * @param {number} unshieldParams.amount The amount to be unshielded * @param {string} [unshieldParams.unshieldedAddress] The unshielded address to apply the unshielded tokens * @param {string} [unshieldParams.contract] The token contract address * @param {number} [unshieldParams.tokenId] The token id * @returns The confirmation of the submitted sapling unshielding transactions */ unshield: (unshieldParams: UnshieldParams[]) => Promise<{ block: import("@taquito/rpc").BlockResponse; expectedConfirmation: number; currentConfirmation: number; completed: boolean; isInCurrentBranch: () => Promise<boolean>; } | undefined>; /** * @description Construct the sapling parameters for the transfer transaction * @param transferParam The sapling transfer parameters * @param {string} [transferParam.contract] The token contract address * @param {number} [transferParam.tokenId] The token id * @param {object} transferParam.transfers The transfers to be made * @returns The sapling parameters for the transfer transaction */ constructTransferTokenParams: (transferParam: TransferParams) => Promise<{ saplingTransactions: (string | void)[]; contract: string | undefined; tokenId: number | undefined; }>; /** * @description Transfer the specified amount of shielded tokens to the specified shielded address * @param {TransferParams[]} transferParams Sapling transfer parameters to be constructed into sapling transactions * @param {string} [transferParams.contract] The token contract address * @param {number} [transferParams.tokenId] The token id * @param {object} transferParams.transfers The transfers to be made * @returns The confirmation of the submitted sapling transfer transactions */ transfer: (transferParams: TransferParams[]) => Promise<{ block: import("@taquito/rpc").BlockResponse; expectedConfirmation: number; currentConfirmation: number; completed: boolean; isInCurrentBranch: () => Promise<boolean>; } | undefined>; /** * @description Get the shielded sapling token balance for the currently loaded shielded address * @param {SaplingTokenInfo} saplingTokenInfo The sapling token information * @param {number} [saplingTokenInfo.saplingId] The sapling id * @param {string} [saplingTokenInfo.contract] The token contract address * @param {number} [saplingTokenInfo.tokenId] The token id * @returns The shielded sapling token balance for the currently loaded shielded address */ getShieldedBalance: ({ saplingId, contract, tokenId, }: SaplingTokenInfo) => Promise<number>; /** * @description Get all the shielded sapling tokens * @param includeMetadata Include the metadata for the shielded sapling tokens * @returns The shielded sapling tokens */ getAllShieldedAssets: (includeMetadata?: boolean) => Promise<{ saplingId: number; contract?: string; tokenId?: number; metadata?: any; }[]>; /** * @description Get the shielded sapling token balances for all the sapling tokens * @returns The shielded sapling token balances for all the sapling tokens */ getAllShieldedBalances: () => Promise<{ saplingId: number; contract?: string; tokenId?: number; balance: number; }[]>; /** * @description Get the shielded incoming and outgoing transactions for the specified sapling contract and token id * @param {string} [contract] Sapling contract address * @param {number} [tokenId] Token id * @returns The shielded incoming and outgoing transactions for the specified sapling contract and token id */ getShieldedTransactions: (contract?: string, tokenId?: number) => Promise<{ incoming: any[]; outgoing: any[]; }>; /** * @description Get the sapling payment address of the currently loaded sapling key * @returns The sapling payment address */ getShieldedAddress: () => Promise<string>; /** * @description Initialize the sapling pool for the specified token contract and token id * @param {string} contract The token contract address * @param {number} [tokenId] The token id * @returns The confirmation of the initialized sapling pool */ initTokenSaplingPool: (contract: string, tokenId?: number) => Promise<{ block: import("@taquito/rpc").BlockResponse; expectedConfirmation: number; currentConfirmation: number; completed: boolean; isInCurrentBranch: () => Promise<boolean>; } | undefined>; } export {};