@trufnetwork/sdk-js 0.5.8 → 0.5.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/client/client.cjs +64 -11
- package/dist/cjs/client/client.cjs.map +2 -2
- package/dist/cjs/contracts-api/action.cjs +73 -16
- package/dist/cjs/contracts-api/action.cjs.map +2 -2
- package/dist/cjs/internal.cjs.map +1 -1
- package/dist/cjs/types/bridge.cjs +19 -0
- package/dist/cjs/types/bridge.cjs.map +7 -0
- package/dist/esm/client/client.mjs +64 -11
- package/dist/esm/client/client.mjs.map +2 -2
- package/dist/esm/contracts-api/action.mjs +73 -16
- package/dist/esm/contracts-api/action.mjs.map +2 -2
- package/dist/esm/internal.mjs.map +1 -1
- package/dist/esm/types/bridge.mjs +1 -0
- package/dist/esm/types/bridge.mjs.map +7 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/client/client.d.ts +59 -8
- package/dist/types/client/client.d.ts.map +1 -1
- package/dist/types/contracts-api/action.d.ts +61 -13
- package/dist/types/contracts-api/action.d.ts.map +1 -1
- package/dist/types/internal.d.ts +1 -0
- package/dist/types/internal.d.ts.map +1 -1
- package/dist/types/types/bridge.d.ts +69 -0
- package/dist/types/types/bridge.d.ts.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
|
|
16
|
+
// src/types/bridge.ts
|
|
17
|
+
var bridge_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(bridge_exports);
|
|
19
|
+
//# sourceMappingURL=bridge.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/types/bridge.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Types for bridge-related operations\n */\n\n/**\n * Withdrawal proof returned from getWithdrawalProof()\n *\n * This proof contains all the data needed for a user to claim their withdrawal\n * on the destination chain by submitting a transaction to the bridge contract.\n *\n * @example\n * ```typescript\n * const proofs = await client.getWithdrawalProof(\"hoodi_tt\", \"0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb\");\n * const proof = proofs[0];\n *\n * // Decode base64 data to use in smart contract call\n * const blockHash = Buffer.from(proof.block_hash, 'base64').toString('hex');\n * const root = Buffer.from(proof.root, 'base64').toString('hex');\n * const signatures = proof.signatures.map(sig => Buffer.from(sig, 'base64'));\n * ```\n */\nexport interface WithdrawalProof {\n /**\n * The source chain name (e.g., \"hoodi\", \"sepolia\")\n * Note: This is the chain name, not the bridge identifier\n */\n chain: string;\n\n /**\n * The numeric chain ID (e.g., \"3639\" for Hoodi)\n */\n chain_id: string;\n\n /**\n * The bridge contract address on the destination chain\n */\n contract: string;\n\n /**\n * The block number when the epoch was created\n */\n created_at: number;\n\n /**\n * The recipient wallet address\n */\n recipient: string;\n\n /**\n * The withdrawal amount in wei (as string to handle large numbers)\n */\n amount: string;\n\n /**\n * The Kwil block hash (base64-encoded bytes)\n * Decode to bytes32 for smart contract call\n */\n block_hash: string;\n\n /**\n * The merkle root (base64-encoded bytes)\n * Decode to bytes32 for smart contract call\n */\n root: string;\n\n /**\n * Array of merkle proofs (base64-encoded bytes)\n * Usually empty for single withdrawals\n */\n proofs: string[];\n\n /**\n * Array of validator signatures (base64-encoded bytes)\n * Each signature is 65 bytes: r[32] || s[32] || v[1]\n * Decode and split into (v, r, s) for smart contract call\n */\n signatures: string[];\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;AAAA;AAAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -223,19 +223,26 @@ var BaseTNClient = class {
|
|
|
223
223
|
const action = this.loadAction();
|
|
224
224
|
return action.listMetadataByHeight(params);
|
|
225
225
|
}
|
|
226
|
-
|
|
226
|
+
/**
|
|
227
|
+
* Gets the wallet balance for a specific bridge instance
|
|
228
|
+
* @param bridgeIdentifier The bridge instance identifier (e.g., "sepolia", "hoodi_tt", "ethereum")
|
|
229
|
+
* @param walletAddress The wallet address to check balance for
|
|
230
|
+
* @returns Promise that resolves to the balance as a string (in wei)
|
|
231
|
+
*/
|
|
232
|
+
async getWalletBalance(bridgeIdentifier, walletAddress) {
|
|
227
233
|
const action = this.loadAction();
|
|
228
|
-
return action.getWalletBalance(
|
|
234
|
+
return action.getWalletBalance(bridgeIdentifier, walletAddress);
|
|
229
235
|
}
|
|
230
236
|
/**
|
|
231
|
-
* Performs a withdrawal operation by bridging tokens
|
|
232
|
-
* @param
|
|
233
|
-
* @param amount The amount to withdraw
|
|
237
|
+
* Performs a withdrawal operation by bridging tokens from TN to a destination chain
|
|
238
|
+
* @param bridgeIdentifier The bridge instance identifier (e.g., "sepolia", "hoodi_tt")
|
|
239
|
+
* @param amount The amount to withdraw (in wei)
|
|
240
|
+
* @param recipient The recipient address on the destination chain
|
|
234
241
|
* @returns Promise that resolves to the transaction hash, or throws on error
|
|
235
242
|
*/
|
|
236
|
-
async withdraw(
|
|
243
|
+
async withdraw(bridgeIdentifier, amount, recipient) {
|
|
237
244
|
const action = this.loadAction();
|
|
238
|
-
const bridgeResult = await action.bridgeTokens(
|
|
245
|
+
const bridgeResult = await action.bridgeTokens(bridgeIdentifier, amount, recipient);
|
|
239
246
|
if (!bridgeResult.data?.tx_hash) {
|
|
240
247
|
throw new Error("Bridge tokens operation failed: no transaction hash returned");
|
|
241
248
|
}
|
|
@@ -247,15 +254,61 @@ var BaseTNClient = class {
|
|
|
247
254
|
return bridgeResult.data.tx_hash;
|
|
248
255
|
}
|
|
249
256
|
/**
|
|
250
|
-
* Lists wallet rewards for a specific
|
|
251
|
-
* @param
|
|
257
|
+
* Lists wallet rewards for a specific bridge instance
|
|
258
|
+
* @param bridgeIdentifier The bridge instance identifier (e.g., "sepolia", "hoodi_tt")
|
|
252
259
|
* @param wallet The wallet address to list rewards for
|
|
253
260
|
* @param withPending Whether to include pending rewards
|
|
254
261
|
* @returns Promise that resolves to an array of rewards data
|
|
262
|
+
* @deprecated This method uses the extension namespace directly. Most users should use getWithdrawalProof instead.
|
|
263
|
+
*/
|
|
264
|
+
async listWalletRewards(bridgeIdentifier, wallet, withPending) {
|
|
265
|
+
const action = this.loadAction();
|
|
266
|
+
return action.listWalletRewards(bridgeIdentifier, wallet, withPending);
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Gets withdrawal proof for a specific bridge instance
|
|
270
|
+
* Returns merkle proofs and validator signatures needed for claiming withdrawals on the destination chain
|
|
271
|
+
*
|
|
272
|
+
* This method is used for non-custodial bridge withdrawals where users need to
|
|
273
|
+
* manually claim their withdrawals by submitting proofs to the destination chain contract.
|
|
274
|
+
* The proof includes validator signatures, merkle root, block hash, and amount.
|
|
275
|
+
*
|
|
276
|
+
* @param bridgeIdentifier The bridge instance identifier (e.g., "hoodi_tt", "sepolia", "ethereum")
|
|
277
|
+
* @param walletAddress The wallet address to get withdrawal proof for
|
|
278
|
+
* @returns Promise that resolves to an array of withdrawal proof data (empty array if no unclaimed withdrawals)
|
|
279
|
+
*
|
|
280
|
+
* @example
|
|
281
|
+
* ```typescript
|
|
282
|
+
* // Get withdrawal proofs for Hoodi Test Token bridge
|
|
283
|
+
* const proofs = await client.getWithdrawalProof("hoodi_tt", "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb");
|
|
284
|
+
*
|
|
285
|
+
* // Proofs will be an array like:
|
|
286
|
+
* // [{
|
|
287
|
+
* // chain: "hoodi",
|
|
288
|
+
* // chain_id: "3639",
|
|
289
|
+
* // contract: "0x878D6aaeB6e746033f50B8dC268d54B4631554E7",
|
|
290
|
+
* // created_at: 3080,
|
|
291
|
+
* // recipient: "0x...",
|
|
292
|
+
* // amount: "100000000000000000000",
|
|
293
|
+
* // block_hash: <base64-encoded>,
|
|
294
|
+
* // root: <base64-encoded>,
|
|
295
|
+
* // proofs: [],
|
|
296
|
+
* // signatures: [<base64-encoded-signatures>]
|
|
297
|
+
* // }]
|
|
298
|
+
*
|
|
299
|
+
* // Use the proofs to claim withdrawal on destination chain
|
|
300
|
+
* if (proofs.length > 0) {
|
|
301
|
+
* const proof = proofs[0];
|
|
302
|
+
* await bridgeContract.claimWithdrawal(proof.recipient, proof.amount, proof.root, proof.proofs, proof.signatures);
|
|
303
|
+
* }
|
|
304
|
+
* ```
|
|
305
|
+
*
|
|
306
|
+
* @note This method has been tested via integration tests in the node repository.
|
|
307
|
+
* See: https://github.com/trufnetwork/kwil-db/blob/main/node/exts/erc20-bridge/erc20/meta_extension_withdrawal_test.go
|
|
255
308
|
*/
|
|
256
|
-
async
|
|
309
|
+
async getWithdrawalProof(bridgeIdentifier, walletAddress) {
|
|
257
310
|
const action = this.loadAction();
|
|
258
|
-
return action.
|
|
311
|
+
return action.getWithdrawalProof(bridgeIdentifier, walletAddress);
|
|
259
312
|
}
|
|
260
313
|
/**
|
|
261
314
|
* Gets taxonomies for specific streams in batch.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/client/client.ts"],
|
|
4
|
-
"sourcesContent": ["import { Client, KwilSigner, NodeKwil, WebKwil, Types, EnvironmentType } from \"@trufnetwork/kwil-js\";\nimport { ComposedAction, ListTaxonomiesByHeightParams, GetTaxonomiesForStreamsParams, TaxonomyQueryResult } from \"../contracts-api/composedAction\";\nimport { deployStream } from \"../contracts-api/deployStream\";\nimport { deleteStream } from \"../contracts-api/deleteStream\";\nimport { PrimitiveAction } from \"../contracts-api/primitiveAction\";\nimport { Action, ListMetadataByHeightParams, MetadataQueryResult } from \"../contracts-api/action\";\nimport { StreamType } from \"../contracts-api/contractValues\";\nimport { StreamLocator, TNStream } from \"../types/stream\";\nimport { EthereumAddress } from \"../util/EthereumAddress\";\nimport { StreamId } from \"../util/StreamId\";\nimport { listStreams } from \"./listStreams\";\nimport { getLastTransactions } from \"./getLastTransactions\";\nimport { RoleManagement } from \"../contracts-api/roleManagement\";\nimport { AttestationAction } from \"../contracts-api/attestationAction\";\nimport { TransactionAction } from \"../contracts-api/transactionAction\";\nimport { OwnerIdentifier } from \"../types/role\";\n\nexport interface SignerInfo {\n // we need to have the address upfront to create the KwilSigner, instead of relying on the signer to return it asynchronously\n address: string;\n signer: Types.EthSigner;\n}\n\nexport type TNClientOptions = {\n endpoint: string;\n signerInfo: SignerInfo;\n} & Omit<Types.KwilConfig, \"kwilProvider\">;\n\nexport interface ListStreamsInput {\n dataProvider?: string;\n limit?: number;\n offset?: number;\n orderBy?: string;\n blockHeight?: number;\n}\n\n/**\n * @param dataProvider optional address; when omitted or null, returns for all providers\n * @param limitSize max rows to return (default 6, max 100)\n */\nexport interface GetLastTransactionsInput {\n dataProvider?: string;\n limitSize?: number;\n}\n\nexport abstract class BaseTNClient<T extends EnvironmentType> {\n protected kwilClient: Types.Kwil<T> | undefined;\n protected signerInfo: SignerInfo;\n\n protected constructor(options: TNClientOptions) {\n this.signerInfo = options.signerInfo;\n }\n\n /**\n * Waits for a transaction to be mined by TN.\n * @param txHash - The transaction hash to wait for.\n * @param timeout - The timeout in milliseconds.\n * @returns A promise that resolves to the transaction info receipt.\n */\n async waitForTx(txHash: string, timeout = 12000): Promise<Types.TxInfoReceipt> {\n return new Promise<Types.TxInfoReceipt>(async (resolve, reject) => {\n const interval = setInterval(async () => {\n const receipt = await this.getKwilClient()\n [\"txInfoClient\"](txHash)\n .catch(() => ({ data: undefined, status: undefined }));\n switch (receipt.status) {\n case 200:\n if (receipt.data?.tx_result?.log !== undefined && receipt.data?.tx_result?.log.includes(\"ERROR\")) {\n reject(\n new Error(\n `Transaction failed: status ${receipt.status} : log message ${receipt.data?.tx_result.log}`,\n ))\n } else {\n resolve(receipt.data!);\n }\n break;\n case undefined:\n break;\n default:\n reject(\n new Error(\n `Transaction failed: status ${receipt.status} : log message ${receipt.data?.tx_result.log}`,\n ),\n );\n }\n }, 1000);\n setTimeout(() => {\n clearInterval(interval);\n reject(new Error(\"Transaction failed: Timeout\"));\n }, timeout);\n });\n }\n\n /**\n * Returns the Kwil signer used by the client.\n * @returns An instance of KwilSigner.\n */\n getKwilSigner(): KwilSigner {\n return new KwilSigner(\n this.signerInfo.signer,\n this.address().getAddress(),\n );\n }\n\n /**\n * Returns the Kwil client used by the client.\n * @returns An instance of Kwil.\n * @throws If the Kwil client is not initialized.\n */\n getKwilClient(): Types.Kwil<EnvironmentType> {\n if (!this.kwilClient) {\n throw new Error(\"Kwil client not initialized\");\n }\n return this.kwilClient;\n }\n\n /**\n * Deploys a new stream.\n * @param streamId - The ID of the stream to deploy.\n * @param streamType - The type of the stream.\n * @param synchronous - Whether the deployment should be synchronous.\n * @param contractVersion\n * @returns A promise that resolves to a generic response containing the transaction receipt.\n */\n async deployStream(\n streamId: StreamId,\n streamType: StreamType,\n synchronous?: boolean,\n ): Promise<Types.GenericResponse<Types.TxReceipt>> {\n return await deployStream({\n streamId,\n streamType,\n synchronous,\n kwilClient: this.getKwilClient(),\n kwilSigner: this.getKwilSigner(),\n });\n }\n\n /**\n * Destroys a stream.\n * @param stream - The StreamLocator of the stream to destroy.\n * @param synchronous - Whether the destruction should be synchronous.\n * @returns A promise that resolves to a generic response containing the transaction receipt.\n */\n async destroyStream(\n stream: StreamLocator,\n synchronous?: boolean,\n ): Promise<Types.GenericResponse<Types.TxReceipt>> {\n return await deleteStream({\n stream,\n synchronous,\n kwilClient: this.getKwilClient(),\n kwilSigner: this.getKwilSigner(),\n });\n }\n\n /**\n * Loads an already deployed stream, permitting its API usage.\n * @returns An instance of IStream.\n */\n loadAction(): Action {\n return new Action(\n this.getKwilClient() as WebKwil | NodeKwil,\n this.getKwilSigner(),\n );\n }\n\n /**\n * Loads a primitive stream.\n * @returns An instance of IPrimitiveStream.\n */\n loadPrimitiveAction(): PrimitiveAction {\n return PrimitiveAction.fromStream(this.loadAction());\n }\n\n /**\n * Loads a composed stream.\n * @returns An instance of IComposedStream.\n */\n loadComposedAction(): ComposedAction {\n return ComposedAction.fromStream(this.loadAction());\n }\n\n /**\n * Loads the role management contract API, permitting its RBAC usage.\n */\n loadRoleManagementAction(): RoleManagement {\n return RoleManagement.fromClient(\n this.getKwilClient() as WebKwil | NodeKwil,\n this.getKwilSigner(),\n );\n }\n\n /**\n * Loads the attestation action API, permitting attestation operations.\n * @returns An instance of AttestationAction.\n */\n loadAttestationAction(): AttestationAction {\n return new AttestationAction(\n this.getKwilClient() as WebKwil | NodeKwil,\n this.getKwilSigner(),\n );\n }\n\n /**\n * Loads the transaction action API, permitting transaction ledger queries.\n * @returns An instance of TransactionAction.\n */\n loadTransactionAction(): TransactionAction {\n return new TransactionAction(\n this.getKwilClient() as WebKwil | NodeKwil,\n this.getKwilSigner(),\n );\n }\n\n /**\n * Creates a new stream locator.\n * @param streamId - The ID of the stream.\n * @returns A StreamLocator object.\n */\n ownStreamLocator(streamId: StreamId): StreamLocator {\n return {\n streamId,\n dataProvider: this.address(),\n };\n }\n\n /**\n * Returns the address of the signer used by the client.\n * @returns An instance of EthereumAddress.\n */\n address(): EthereumAddress {\n return new EthereumAddress(this.signerInfo.address);\n }\n\n /**\n * Returns all streams from the TN network.\n * @param input - The input parameters for listing streams.\n * @returns A promise that resolves to a list of stream locators.\n */\n async getListStreams(input: ListStreamsInput): Promise<TNStream[]> {\n return listStreams(this.getKwilClient() as WebKwil | NodeKwil,this.getKwilSigner(),input);\n }\n\n /**\n * Returns the last write activity across streams.\n * @param input - The input parameters for getting last transactions.\n * @returns A promise that resolves to a list of last transactions.\n */\n async getLastTransactions(input: GetLastTransactionsInput): Promise<any[]> {\n return getLastTransactions(this.getKwilClient() as WebKwil | NodeKwil,this.getKwilSigner(),input);\n }\n\n /**\n * Lists taxonomies by height range for incremental synchronization.\n * High-level wrapper for ComposedAction.listTaxonomiesByHeight()\n * \n * @param params Height range and pagination parameters \n * @returns Promise resolving to taxonomy query results\n * \n * @example\n * ```typescript\n * const taxonomies = await client.listTaxonomiesByHeight({\n * fromHeight: 1000,\n * toHeight: 2000,\n * limit: 100,\n * latestOnly: true\n * });\n * ```\n */\n async listTaxonomiesByHeight(params: ListTaxonomiesByHeightParams = {}): Promise<TaxonomyQueryResult[]> {\n const composedAction = this.loadComposedAction();\n return composedAction.listTaxonomiesByHeight(params);\n }\n\n async listMetadataByHeight(params: ListMetadataByHeightParams = {}): Promise<MetadataQueryResult[]> {\n const action = this.loadAction();\n return action.listMetadataByHeight(params);\n }\n\n async getWalletBalance(chain: string, walletAddress: string) {\n const action = this.loadAction();\n return action.getWalletBalance(chain, walletAddress);\n }\n\n /**\n * Performs a withdrawal operation by bridging tokens\n * @param chain The chain identifier (e.g., \"sepolia\", \"mainnet\", \"polygon\", etc.)\n * @param amount The amount to withdraw\n * @returns Promise that resolves to the transaction hash, or throws on error\n */\n async withdraw(chain: string, amount: string, recipient: string): Promise<string> {\n const action = this.loadAction();\n \n // Bridge tokens in a single operation\n const bridgeResult = await action.bridgeTokens(chain, amount, recipient);\n if (!bridgeResult.data?.tx_hash) {\n throw new Error(\"Bridge tokens operation failed: no transaction hash returned\");\n }\n \n // Wait for bridge transaction to be mined - let waitForTx errors bubble up\n try {\n await this.waitForTx(bridgeResult.data.tx_hash);\n } catch (error) {\n throw new Error(`Bridge tokens transaction failed: ${error instanceof Error ? error.message : String(error)}`);\n }\n \n // Return the transaction hash\n return bridgeResult.data.tx_hash;\n }\n\n /**\n * Lists wallet rewards for a specific wallet address on a blockchain network\n * @param chain The chain identifier (e.g., \"sepolia\", \"mainnet\", \"polygon\", etc.)\n * @param wallet The wallet address to list rewards for\n * @param withPending Whether to include pending rewards\n * @returns Promise that resolves to an array of rewards data\n */\n async listWalletRewards(chain: string, wallet: string, withPending: boolean): Promise<any[]> {\n const action = this.loadAction();\n return action.listWalletRewards(chain, wallet, withPending);\n }\n\n /**\n * Gets taxonomies for specific streams in batch.\n * High-level wrapper for ComposedAction.getTaxonomiesForStreams()\n * \n * @param params Stream locators and options\n * @returns Promise resolving to taxonomy query results\n * \n * @example\n * ```typescript\n * const streams = [\n * { dataProvider: provider1, streamId: streamId1 },\n * { dataProvider: provider2, streamId: streamId2 }\n * ];\n * const taxonomies = await client.getTaxonomiesForStreams({\n * streams,\n * latestOnly: true\n * });\n * ```\n */\n async getTaxonomiesForStreams(params: GetTaxonomiesForStreamsParams): Promise<TaxonomyQueryResult[]> {\n const composedAction = this.loadComposedAction();\n return composedAction.getTaxonomiesForStreams(params);\n }\n\n /**\n * Get the default chain id for a provider. Use with caution, as this decreases the security of the TN.\n * @param provider - The provider URL.\n * @returns A promise that resolves to the chain ID.\n */\n public static async getDefaultChainId(provider: string) {\n const kwilClient = new Client({\n kwilProvider: provider,\n });\n const chainInfo = await kwilClient[\"chainInfoClient\"]();\n return chainInfo.data?.chain_id;\n }\n\n /*\n * High-level role-management helpers. These wrap the lower-level\n * RoleManagement contract calls and expose a simpler API on the\n * TN client.\n */\n\n /** Grants a role to one or more wallets. */\n async grantRole(input: {\n owner: OwnerIdentifier;\n roleName: string;\n wallets: EthereumAddress | EthereumAddress[];\n synchronous?: boolean;\n }): Promise<string> {\n const rm = this.loadRoleManagementAction();\n const walletsArr: EthereumAddress[] = Array.isArray(input.wallets)\n ? input.wallets\n : [input.wallets];\n const tx = await rm.grantRole(\n {\n owner: input.owner,\n roleName: input.roleName,\n wallets: walletsArr,\n },\n input.synchronous,\n );\n return tx.data?.tx_hash as unknown as string;\n }\n\n /** Revokes a role from one or more wallets. */\n async revokeRole(input: {\n owner: OwnerIdentifier;\n roleName: string;\n wallets: EthereumAddress | EthereumAddress[];\n synchronous?: boolean;\n }): Promise<string> {\n const rm = this.loadRoleManagementAction();\n const walletsArr: EthereumAddress[] = Array.isArray(input.wallets)\n ? input.wallets\n : [input.wallets];\n const tx = await rm.revokeRole(\n {\n owner: input.owner,\n roleName: input.roleName,\n wallets: walletsArr,\n },\n input.synchronous,\n );\n return tx.data?.tx_hash as unknown as string;\n }\n\n /**\n * Checks if a wallet is member of a role.\n * Returns true if the wallet is a member.\n */\n async isMemberOf(input: {\n owner: OwnerIdentifier;\n roleName: string;\n wallet: EthereumAddress;\n }): Promise<boolean> {\n const rm = this.loadRoleManagementAction();\n const res = await rm.areMembersOf({\n owner: input.owner,\n roleName: input.roleName,\n wallets: [input.wallet],\n });\n return res.length > 0 && res[0].isMember;\n }\n\n /**\n * Lists role members \u2013 currently unsupported in the\n * smart-contract layer.\n */\n async listRoleMembers(input: {\n owner: OwnerIdentifier;\n roleName: string;\n limit?: number;\n offset?: number;\n }): Promise<import(\"../types/role\").RoleMember[]> {\n const rm = this.loadRoleManagementAction();\n return rm.listRoleMembers({\n owner: input.owner,\n roleName: input.roleName,\n limit: input.limit,\n offset: input.offset,\n });\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;;;AAAA,SAAS,QAAQ,kBAA6D;AAC9E,SAAS,sBAAwG;AACjH,SAAS,oBAAoB;AAC7B,SAAS,oBAAoB;AAC7B,SAAS,uBAAuB;AAChC,SAAS,cAA+D;
|
|
4
|
+
"sourcesContent": ["import { Client, KwilSigner, NodeKwil, WebKwil, Types, EnvironmentType } from \"@trufnetwork/kwil-js\";\nimport { ComposedAction, ListTaxonomiesByHeightParams, GetTaxonomiesForStreamsParams, TaxonomyQueryResult } from \"../contracts-api/composedAction\";\nimport { deployStream } from \"../contracts-api/deployStream\";\nimport { deleteStream } from \"../contracts-api/deleteStream\";\nimport { PrimitiveAction } from \"../contracts-api/primitiveAction\";\nimport { Action, ListMetadataByHeightParams, MetadataQueryResult } from \"../contracts-api/action\";\nimport { StreamType } from \"../contracts-api/contractValues\";\nimport { WithdrawalProof } from \"../types/bridge\";\nimport { StreamLocator, TNStream } from \"../types/stream\";\nimport { EthereumAddress } from \"../util/EthereumAddress\";\nimport { StreamId } from \"../util/StreamId\";\nimport { listStreams } from \"./listStreams\";\nimport { getLastTransactions } from \"./getLastTransactions\";\nimport { RoleManagement } from \"../contracts-api/roleManagement\";\nimport { AttestationAction } from \"../contracts-api/attestationAction\";\nimport { TransactionAction } from \"../contracts-api/transactionAction\";\nimport { OwnerIdentifier } from \"../types/role\";\n\nexport interface SignerInfo {\n // we need to have the address upfront to create the KwilSigner, instead of relying on the signer to return it asynchronously\n address: string;\n signer: Types.EthSigner;\n}\n\nexport type TNClientOptions = {\n endpoint: string;\n signerInfo: SignerInfo;\n} & Omit<Types.KwilConfig, \"kwilProvider\">;\n\nexport interface ListStreamsInput {\n dataProvider?: string;\n limit?: number;\n offset?: number;\n orderBy?: string;\n blockHeight?: number;\n}\n\n/**\n * @param dataProvider optional address; when omitted or null, returns for all providers\n * @param limitSize max rows to return (default 6, max 100)\n */\nexport interface GetLastTransactionsInput {\n dataProvider?: string;\n limitSize?: number;\n}\n\nexport abstract class BaseTNClient<T extends EnvironmentType> {\n protected kwilClient: Types.Kwil<T> | undefined;\n protected signerInfo: SignerInfo;\n\n protected constructor(options: TNClientOptions) {\n this.signerInfo = options.signerInfo;\n }\n\n /**\n * Waits for a transaction to be mined by TN.\n * @param txHash - The transaction hash to wait for.\n * @param timeout - The timeout in milliseconds.\n * @returns A promise that resolves to the transaction info receipt.\n */\n async waitForTx(txHash: string, timeout = 12000): Promise<Types.TxInfoReceipt> {\n return new Promise<Types.TxInfoReceipt>(async (resolve, reject) => {\n const interval = setInterval(async () => {\n const receipt = await this.getKwilClient()\n [\"txInfoClient\"](txHash)\n .catch(() => ({ data: undefined, status: undefined }));\n switch (receipt.status) {\n case 200:\n if (receipt.data?.tx_result?.log !== undefined && receipt.data?.tx_result?.log.includes(\"ERROR\")) {\n reject(\n new Error(\n `Transaction failed: status ${receipt.status} : log message ${receipt.data?.tx_result.log}`,\n ))\n } else {\n resolve(receipt.data!);\n }\n break;\n case undefined:\n break;\n default:\n reject(\n new Error(\n `Transaction failed: status ${receipt.status} : log message ${receipt.data?.tx_result.log}`,\n ),\n );\n }\n }, 1000);\n setTimeout(() => {\n clearInterval(interval);\n reject(new Error(\"Transaction failed: Timeout\"));\n }, timeout);\n });\n }\n\n /**\n * Returns the Kwil signer used by the client.\n * @returns An instance of KwilSigner.\n */\n getKwilSigner(): KwilSigner {\n return new KwilSigner(\n this.signerInfo.signer,\n this.address().getAddress(),\n );\n }\n\n /**\n * Returns the Kwil client used by the client.\n * @returns An instance of Kwil.\n * @throws If the Kwil client is not initialized.\n */\n getKwilClient(): Types.Kwil<EnvironmentType> {\n if (!this.kwilClient) {\n throw new Error(\"Kwil client not initialized\");\n }\n return this.kwilClient;\n }\n\n /**\n * Deploys a new stream.\n * @param streamId - The ID of the stream to deploy.\n * @param streamType - The type of the stream.\n * @param synchronous - Whether the deployment should be synchronous.\n * @param contractVersion\n * @returns A promise that resolves to a generic response containing the transaction receipt.\n */\n async deployStream(\n streamId: StreamId,\n streamType: StreamType,\n synchronous?: boolean,\n ): Promise<Types.GenericResponse<Types.TxReceipt>> {\n return await deployStream({\n streamId,\n streamType,\n synchronous,\n kwilClient: this.getKwilClient(),\n kwilSigner: this.getKwilSigner(),\n });\n }\n\n /**\n * Destroys a stream.\n * @param stream - The StreamLocator of the stream to destroy.\n * @param synchronous - Whether the destruction should be synchronous.\n * @returns A promise that resolves to a generic response containing the transaction receipt.\n */\n async destroyStream(\n stream: StreamLocator,\n synchronous?: boolean,\n ): Promise<Types.GenericResponse<Types.TxReceipt>> {\n return await deleteStream({\n stream,\n synchronous,\n kwilClient: this.getKwilClient(),\n kwilSigner: this.getKwilSigner(),\n });\n }\n\n /**\n * Loads an already deployed stream, permitting its API usage.\n * @returns An instance of IStream.\n */\n loadAction(): Action {\n return new Action(\n this.getKwilClient() as WebKwil | NodeKwil,\n this.getKwilSigner(),\n );\n }\n\n /**\n * Loads a primitive stream.\n * @returns An instance of IPrimitiveStream.\n */\n loadPrimitiveAction(): PrimitiveAction {\n return PrimitiveAction.fromStream(this.loadAction());\n }\n\n /**\n * Loads a composed stream.\n * @returns An instance of IComposedStream.\n */\n loadComposedAction(): ComposedAction {\n return ComposedAction.fromStream(this.loadAction());\n }\n\n /**\n * Loads the role management contract API, permitting its RBAC usage.\n */\n loadRoleManagementAction(): RoleManagement {\n return RoleManagement.fromClient(\n this.getKwilClient() as WebKwil | NodeKwil,\n this.getKwilSigner(),\n );\n }\n\n /**\n * Loads the attestation action API, permitting attestation operations.\n * @returns An instance of AttestationAction.\n */\n loadAttestationAction(): AttestationAction {\n return new AttestationAction(\n this.getKwilClient() as WebKwil | NodeKwil,\n this.getKwilSigner(),\n );\n }\n\n /**\n * Loads the transaction action API, permitting transaction ledger queries.\n * @returns An instance of TransactionAction.\n */\n loadTransactionAction(): TransactionAction {\n return new TransactionAction(\n this.getKwilClient() as WebKwil | NodeKwil,\n this.getKwilSigner(),\n );\n }\n\n /**\n * Creates a new stream locator.\n * @param streamId - The ID of the stream.\n * @returns A StreamLocator object.\n */\n ownStreamLocator(streamId: StreamId): StreamLocator {\n return {\n streamId,\n dataProvider: this.address(),\n };\n }\n\n /**\n * Returns the address of the signer used by the client.\n * @returns An instance of EthereumAddress.\n */\n address(): EthereumAddress {\n return new EthereumAddress(this.signerInfo.address);\n }\n\n /**\n * Returns all streams from the TN network.\n * @param input - The input parameters for listing streams.\n * @returns A promise that resolves to a list of stream locators.\n */\n async getListStreams(input: ListStreamsInput): Promise<TNStream[]> {\n return listStreams(this.getKwilClient() as WebKwil | NodeKwil,this.getKwilSigner(),input);\n }\n\n /**\n * Returns the last write activity across streams.\n * @param input - The input parameters for getting last transactions.\n * @returns A promise that resolves to a list of last transactions.\n */\n async getLastTransactions(input: GetLastTransactionsInput): Promise<any[]> {\n return getLastTransactions(this.getKwilClient() as WebKwil | NodeKwil,this.getKwilSigner(),input);\n }\n\n /**\n * Lists taxonomies by height range for incremental synchronization.\n * High-level wrapper for ComposedAction.listTaxonomiesByHeight()\n * \n * @param params Height range and pagination parameters \n * @returns Promise resolving to taxonomy query results\n * \n * @example\n * ```typescript\n * const taxonomies = await client.listTaxonomiesByHeight({\n * fromHeight: 1000,\n * toHeight: 2000,\n * limit: 100,\n * latestOnly: true\n * });\n * ```\n */\n async listTaxonomiesByHeight(params: ListTaxonomiesByHeightParams = {}): Promise<TaxonomyQueryResult[]> {\n const composedAction = this.loadComposedAction();\n return composedAction.listTaxonomiesByHeight(params);\n }\n\n async listMetadataByHeight(params: ListMetadataByHeightParams = {}): Promise<MetadataQueryResult[]> {\n const action = this.loadAction();\n return action.listMetadataByHeight(params);\n }\n\n /**\n * Gets the wallet balance for a specific bridge instance\n * @param bridgeIdentifier The bridge instance identifier (e.g., \"sepolia\", \"hoodi_tt\", \"ethereum\")\n * @param walletAddress The wallet address to check balance for\n * @returns Promise that resolves to the balance as a string (in wei)\n */\n async getWalletBalance(bridgeIdentifier: string, walletAddress: string) {\n const action = this.loadAction();\n return action.getWalletBalance(bridgeIdentifier, walletAddress);\n }\n\n /**\n * Performs a withdrawal operation by bridging tokens from TN to a destination chain\n * @param bridgeIdentifier The bridge instance identifier (e.g., \"sepolia\", \"hoodi_tt\")\n * @param amount The amount to withdraw (in wei)\n * @param recipient The recipient address on the destination chain\n * @returns Promise that resolves to the transaction hash, or throws on error\n */\n async withdraw(bridgeIdentifier: string, amount: string, recipient: string): Promise<string> {\n const action = this.loadAction();\n\n // Bridge tokens in a single operation\n const bridgeResult = await action.bridgeTokens(bridgeIdentifier, amount, recipient);\n if (!bridgeResult.data?.tx_hash) {\n throw new Error(\"Bridge tokens operation failed: no transaction hash returned\");\n }\n\n // Wait for bridge transaction to be mined - let waitForTx errors bubble up\n try {\n await this.waitForTx(bridgeResult.data.tx_hash);\n } catch (error) {\n throw new Error(`Bridge tokens transaction failed: ${error instanceof Error ? error.message : String(error)}`);\n }\n\n // Return the transaction hash\n return bridgeResult.data.tx_hash;\n }\n\n /**\n * Lists wallet rewards for a specific bridge instance\n * @param bridgeIdentifier The bridge instance identifier (e.g., \"sepolia\", \"hoodi_tt\")\n * @param wallet The wallet address to list rewards for\n * @param withPending Whether to include pending rewards\n * @returns Promise that resolves to an array of rewards data\n * @deprecated This method uses the extension namespace directly. Most users should use getWithdrawalProof instead.\n */\n async listWalletRewards(bridgeIdentifier: string, wallet: string, withPending: boolean): Promise<any[]> {\n const action = this.loadAction();\n return action.listWalletRewards(bridgeIdentifier, wallet, withPending);\n }\n\n /**\n * Gets withdrawal proof for a specific bridge instance\n * Returns merkle proofs and validator signatures needed for claiming withdrawals on the destination chain\n *\n * This method is used for non-custodial bridge withdrawals where users need to\n * manually claim their withdrawals by submitting proofs to the destination chain contract.\n * The proof includes validator signatures, merkle root, block hash, and amount.\n *\n * @param bridgeIdentifier The bridge instance identifier (e.g., \"hoodi_tt\", \"sepolia\", \"ethereum\")\n * @param walletAddress The wallet address to get withdrawal proof for\n * @returns Promise that resolves to an array of withdrawal proof data (empty array if no unclaimed withdrawals)\n *\n * @example\n * ```typescript\n * // Get withdrawal proofs for Hoodi Test Token bridge\n * const proofs = await client.getWithdrawalProof(\"hoodi_tt\", \"0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb\");\n *\n * // Proofs will be an array like:\n * // [{\n * // chain: \"hoodi\",\n * // chain_id: \"3639\",\n * // contract: \"0x878D6aaeB6e746033f50B8dC268d54B4631554E7\",\n * // created_at: 3080,\n * // recipient: \"0x...\",\n * // amount: \"100000000000000000000\",\n * // block_hash: <base64-encoded>,\n * // root: <base64-encoded>,\n * // proofs: [],\n * // signatures: [<base64-encoded-signatures>]\n * // }]\n *\n * // Use the proofs to claim withdrawal on destination chain\n * if (proofs.length > 0) {\n * const proof = proofs[0];\n * await bridgeContract.claimWithdrawal(proof.recipient, proof.amount, proof.root, proof.proofs, proof.signatures);\n * }\n * ```\n *\n * @note This method has been tested via integration tests in the node repository.\n * See: https://github.com/trufnetwork/kwil-db/blob/main/node/exts/erc20-bridge/erc20/meta_extension_withdrawal_test.go\n */\n async getWithdrawalProof(bridgeIdentifier: string, walletAddress: string): Promise<WithdrawalProof[]> {\n const action = this.loadAction();\n return action.getWithdrawalProof(bridgeIdentifier, walletAddress);\n }\n\n /**\n * Gets taxonomies for specific streams in batch.\n * High-level wrapper for ComposedAction.getTaxonomiesForStreams()\n * \n * @param params Stream locators and options\n * @returns Promise resolving to taxonomy query results\n * \n * @example\n * ```typescript\n * const streams = [\n * { dataProvider: provider1, streamId: streamId1 },\n * { dataProvider: provider2, streamId: streamId2 }\n * ];\n * const taxonomies = await client.getTaxonomiesForStreams({\n * streams,\n * latestOnly: true\n * });\n * ```\n */\n async getTaxonomiesForStreams(params: GetTaxonomiesForStreamsParams): Promise<TaxonomyQueryResult[]> {\n const composedAction = this.loadComposedAction();\n return composedAction.getTaxonomiesForStreams(params);\n }\n\n /**\n * Get the default chain id for a provider. Use with caution, as this decreases the security of the TN.\n * @param provider - The provider URL.\n * @returns A promise that resolves to the chain ID.\n */\n public static async getDefaultChainId(provider: string) {\n const kwilClient = new Client({\n kwilProvider: provider,\n });\n const chainInfo = await kwilClient[\"chainInfoClient\"]();\n return chainInfo.data?.chain_id;\n }\n\n /*\n * High-level role-management helpers. These wrap the lower-level\n * RoleManagement contract calls and expose a simpler API on the\n * TN client.\n */\n\n /** Grants a role to one or more wallets. */\n async grantRole(input: {\n owner: OwnerIdentifier;\n roleName: string;\n wallets: EthereumAddress | EthereumAddress[];\n synchronous?: boolean;\n }): Promise<string> {\n const rm = this.loadRoleManagementAction();\n const walletsArr: EthereumAddress[] = Array.isArray(input.wallets)\n ? input.wallets\n : [input.wallets];\n const tx = await rm.grantRole(\n {\n owner: input.owner,\n roleName: input.roleName,\n wallets: walletsArr,\n },\n input.synchronous,\n );\n return tx.data?.tx_hash as unknown as string;\n }\n\n /** Revokes a role from one or more wallets. */\n async revokeRole(input: {\n owner: OwnerIdentifier;\n roleName: string;\n wallets: EthereumAddress | EthereumAddress[];\n synchronous?: boolean;\n }): Promise<string> {\n const rm = this.loadRoleManagementAction();\n const walletsArr: EthereumAddress[] = Array.isArray(input.wallets)\n ? input.wallets\n : [input.wallets];\n const tx = await rm.revokeRole(\n {\n owner: input.owner,\n roleName: input.roleName,\n wallets: walletsArr,\n },\n input.synchronous,\n );\n return tx.data?.tx_hash as unknown as string;\n }\n\n /**\n * Checks if a wallet is member of a role.\n * Returns true if the wallet is a member.\n */\n async isMemberOf(input: {\n owner: OwnerIdentifier;\n roleName: string;\n wallet: EthereumAddress;\n }): Promise<boolean> {\n const rm = this.loadRoleManagementAction();\n const res = await rm.areMembersOf({\n owner: input.owner,\n roleName: input.roleName,\n wallets: [input.wallet],\n });\n return res.length > 0 && res[0].isMember;\n }\n\n /**\n * Lists role members \u2013 currently unsupported in the\n * smart-contract layer.\n */\n async listRoleMembers(input: {\n owner: OwnerIdentifier;\n roleName: string;\n limit?: number;\n offset?: number;\n }): Promise<import(\"../types/role\").RoleMember[]> {\n const rm = this.loadRoleManagementAction();\n return rm.listRoleMembers({\n owner: input.owner,\n roleName: input.roleName,\n limit: input.limit,\n offset: input.offset,\n });\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;AAAA,SAAS,QAAQ,kBAA6D;AAC9E,SAAS,sBAAwG;AACjH,SAAS,oBAAoB;AAC7B,SAAS,oBAAoB;AAC7B,SAAS,uBAAuB;AAChC,SAAS,cAA+D;AAIxE,SAAS,uBAAuB;AAEhC,SAAS,mBAAmB;AAC5B,SAAS,2BAA2B;AACpC,SAAS,sBAAsB;AAC/B,SAAS,yBAAyB;AAClC,SAAS,yBAAyB;AA+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AA,IAChB,CAAC;AAAA,EACH;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -638,14 +638,23 @@ var _Action = class _Action {
|
|
|
638
638
|
return result.map((rows) => rows[0].database_size_pretty).throw();
|
|
639
639
|
}
|
|
640
640
|
/**
|
|
641
|
-
* Gets the wallet balance
|
|
642
|
-
* @param
|
|
641
|
+
* Gets the wallet balance for a specific bridge instance
|
|
642
|
+
* @param bridgeIdentifier The bridge instance identifier (e.g., "sepolia", "hoodi_tt", "ethereum")
|
|
643
|
+
* This corresponds to the bridge instance name in TN (e.g., hoodi_tt for Hoodi Test Token bridge)
|
|
643
644
|
* @param walletAddress The wallet address to check balance for
|
|
644
|
-
* @returns Promise that resolves to the balance as a string, or throws on error
|
|
645
|
+
* @returns Promise that resolves to the balance as a string (in wei), or throws on error
|
|
646
|
+
* @example
|
|
647
|
+
* ```typescript
|
|
648
|
+
* // Simple case - identifier matches network name
|
|
649
|
+
* const balance = await action.getWalletBalance("sepolia", "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb");
|
|
650
|
+
*
|
|
651
|
+
* // Multi-token bridge - specify bridge instance explicitly
|
|
652
|
+
* const balance = await action.getWalletBalance("hoodi_tt", "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb");
|
|
653
|
+
* ```
|
|
645
654
|
*/
|
|
646
|
-
async getWalletBalance(
|
|
655
|
+
async getWalletBalance(bridgeIdentifier, walletAddress) {
|
|
647
656
|
const result = await this.call(
|
|
648
|
-
`${
|
|
657
|
+
`${bridgeIdentifier}_wallet_balance`,
|
|
649
658
|
{
|
|
650
659
|
$wallet_address: walletAddress
|
|
651
660
|
}
|
|
@@ -683,32 +692,42 @@ var _Action = class _Action {
|
|
|
683
692
|
}).throw();
|
|
684
693
|
}
|
|
685
694
|
/**
|
|
686
|
-
* Bridges tokens
|
|
687
|
-
* @param
|
|
688
|
-
* @param amount The amount to bridge
|
|
689
|
-
* @
|
|
695
|
+
* Bridges tokens by initiating a withdrawal from TN to a blockchain network
|
|
696
|
+
* @param bridgeIdentifier The bridge instance identifier (e.g., "sepolia", "hoodi_tt", "ethereum")
|
|
697
|
+
* @param amount The amount to bridge in wei (as string to preserve precision)
|
|
698
|
+
* @param recipient The recipient address on the destination chain
|
|
699
|
+
* @returns Promise that resolves to transaction receipt
|
|
700
|
+
* @example
|
|
701
|
+
* ```typescript
|
|
702
|
+
* // Bridge 100 tokens from TN to Sepolia
|
|
703
|
+
* const receipt = await action.bridgeTokens("sepolia", "100000000000000000000", "0x742d35Cc...");
|
|
704
|
+
*
|
|
705
|
+
* // Bridge from TN to Hoodi Test Token bridge
|
|
706
|
+
* const receipt = await action.bridgeTokens("hoodi_tt", "50000000000000000000", "0x742d35Cc...");
|
|
707
|
+
* ```
|
|
690
708
|
*/
|
|
691
|
-
async bridgeTokens(
|
|
709
|
+
async bridgeTokens(bridgeIdentifier, amount, recipient) {
|
|
692
710
|
const numAmount = parseFloat(amount);
|
|
693
711
|
if (isNaN(numAmount) || numAmount <= 0) {
|
|
694
712
|
throw new Error(`Invalid amount: ${amount}. Amount must be greater than 0.`);
|
|
695
713
|
}
|
|
696
|
-
return await this.executeWithNamedParams(`${
|
|
714
|
+
return await this.executeWithNamedParams(`${bridgeIdentifier}_bridge_tokens`, [{
|
|
697
715
|
$recipient: recipient,
|
|
698
716
|
$amount: amount
|
|
699
717
|
}]);
|
|
700
718
|
}
|
|
701
719
|
/**
|
|
702
|
-
* Lists wallet rewards
|
|
703
|
-
* @param
|
|
720
|
+
* Lists wallet rewards for a specific bridge instance
|
|
721
|
+
* @param bridgeIdentifier The bridge instance identifier (e.g., "sepolia", "hoodi_tt")
|
|
704
722
|
* @param wallet The wallet address to list rewards for
|
|
705
723
|
* @param withPending Whether to include pending rewards
|
|
706
|
-
* @returns Promise that resolves to
|
|
724
|
+
* @returns Promise that resolves to array of reward records
|
|
725
|
+
* @deprecated This method uses the extension namespace directly. Most users should use getWithdrawalProof instead.
|
|
707
726
|
*/
|
|
708
|
-
async listWalletRewards(
|
|
727
|
+
async listWalletRewards(bridgeIdentifier, wallet, withPending) {
|
|
709
728
|
const result = await this.kwilClient.call(
|
|
710
729
|
{
|
|
711
|
-
namespace: `${
|
|
730
|
+
namespace: `${bridgeIdentifier}_bridge`,
|
|
712
731
|
name: "list_wallet_rewards",
|
|
713
732
|
inputs: {
|
|
714
733
|
$param_1: wallet,
|
|
@@ -722,6 +741,44 @@ var _Action = class _Action {
|
|
|
722
741
|
}
|
|
723
742
|
return result.data?.result || [];
|
|
724
743
|
}
|
|
744
|
+
/**
|
|
745
|
+
* Gets withdrawal proof for a wallet address on a specific bridge instance
|
|
746
|
+
* Returns merkle proofs and validator signatures needed for claiming withdrawals on the destination chain
|
|
747
|
+
*
|
|
748
|
+
* This method is used for non-custodial bridge withdrawals where users need to
|
|
749
|
+
* manually claim their withdrawals by submitting proofs to the destination chain contract.
|
|
750
|
+
*
|
|
751
|
+
* @param bridgeIdentifier The bridge instance identifier (e.g., "hoodi_tt", "sepolia", "ethereum")
|
|
752
|
+
* @param walletAddress The wallet address to get withdrawal proof for
|
|
753
|
+
* @returns Promise that resolves to array of withdrawal proofs (empty array if no unclaimed withdrawals)
|
|
754
|
+
*
|
|
755
|
+
* @example
|
|
756
|
+
* ```typescript
|
|
757
|
+
* // Get withdrawal proofs for Hoodi Test Token bridge
|
|
758
|
+
* const proofs = await action.getWithdrawalProof("hoodi_tt", "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb");
|
|
759
|
+
* // Returns: [{ chain: "hoodi", recipient: "0x...", amount: "100000000000000000000", proofs: [...], signatures: [...] }]
|
|
760
|
+
*
|
|
761
|
+
* // Use the proofs to claim withdrawal on destination chain
|
|
762
|
+
* if (proofs.length > 0) {
|
|
763
|
+
* const proof = proofs[0];
|
|
764
|
+
* await bridgeContract.claimWithdrawal(proof.recipient, proof.amount, proof.root, proof.proofs, proof.signatures);
|
|
765
|
+
* }
|
|
766
|
+
* ```
|
|
767
|
+
*
|
|
768
|
+
* @note This method has been tested via integration tests in the node repository.
|
|
769
|
+
* See: https://github.com/trufnetwork/kwil-db/blob/main/node/exts/erc20-bridge/erc20/meta_extension_withdrawal_test.go
|
|
770
|
+
*/
|
|
771
|
+
async getWithdrawalProof(bridgeIdentifier, walletAddress) {
|
|
772
|
+
const result = await this.call(
|
|
773
|
+
`${bridgeIdentifier}_get_withdrawal_proof`,
|
|
774
|
+
{
|
|
775
|
+
$wallet_address: walletAddress
|
|
776
|
+
}
|
|
777
|
+
);
|
|
778
|
+
return result.mapRight((rows) => {
|
|
779
|
+
return rows || [];
|
|
780
|
+
}).throw();
|
|
781
|
+
}
|
|
725
782
|
};
|
|
726
783
|
/** Track if deprecation warnings were already emitted */
|
|
727
784
|
__publicField(_Action, "_legacyWarnEmitted", {
|