@trufnetwork/sdk-js 0.5.9 → 0.6.0
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/README.md +45 -0
- package/dist/cjs/client/client.cjs +45 -20
- package/dist/cjs/client/client.cjs.map +2 -2
- package/dist/cjs/contracts-api/action.cjs +51 -26
- package/dist/cjs/contracts-api/action.cjs.map +2 -2
- package/dist/cjs/contracts-api/orderbookAction.cjs +880 -0
- package/dist/cjs/contracts-api/orderbookAction.cjs.map +7 -0
- package/dist/cjs/internal.cjs +9 -0
- package/dist/cjs/internal.cjs.map +2 -2
- package/dist/cjs/types/bridge.cjs.map +1 -1
- package/dist/cjs/types/orderbook.cjs +19 -0
- package/dist/cjs/types/orderbook.cjs.map +7 -0
- package/dist/cjs/util/AttestationEncoding.cjs +3 -2
- package/dist/cjs/util/AttestationEncoding.cjs.map +2 -2
- package/dist/cjs/util/orderbookHelpers.cjs +194 -0
- package/dist/cjs/util/orderbookHelpers.cjs.map +7 -0
- package/dist/cjs/util/orderbookHelpers.test.cjs +217 -0
- package/dist/cjs/util/orderbookHelpers.test.cjs.map +7 -0
- package/dist/esm/client/client.mjs +45 -20
- package/dist/esm/client/client.mjs.map +2 -2
- package/dist/esm/contracts-api/action.mjs +51 -26
- package/dist/esm/contracts-api/action.mjs.map +2 -2
- package/dist/esm/contracts-api/orderbookAction.mjs +875 -0
- package/dist/esm/contracts-api/orderbookAction.mjs.map +7 -0
- package/dist/esm/internal.mjs +16 -0
- package/dist/esm/internal.mjs.map +2 -2
- package/dist/esm/types/orderbook.mjs +1 -0
- package/dist/esm/types/orderbook.mjs.map +7 -0
- package/dist/esm/util/AttestationEncoding.mjs +3 -2
- package/dist/esm/util/AttestationEncoding.mjs.map +2 -2
- package/dist/esm/util/orderbookHelpers.mjs +173 -0
- package/dist/esm/util/orderbookHelpers.mjs.map +7 -0
- package/dist/esm/util/orderbookHelpers.test.mjs +229 -0
- package/dist/esm/util/orderbookHelpers.test.mjs.map +7 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/client/client.d.ts +36 -16
- package/dist/types/client/client.d.ts.map +1 -1
- package/dist/types/contracts-api/action.d.ts +47 -22
- package/dist/types/contracts-api/action.d.ts.map +1 -1
- package/dist/types/contracts-api/orderbookAction.d.ts +303 -0
- package/dist/types/contracts-api/orderbookAction.d.ts.map +1 -0
- package/dist/types/internal.d.ts +3 -0
- package/dist/types/internal.d.ts.map +1 -1
- package/dist/types/types/bridge.d.ts +3 -2
- package/dist/types/types/bridge.d.ts.map +1 -1
- package/dist/types/types/orderbook.d.ts +376 -0
- package/dist/types/types/orderbook.d.ts.map +1 -0
- package/dist/types/util/AttestationEncoding.d.ts +9 -1
- package/dist/types/util/AttestationEncoding.d.ts.map +1 -1
- package/dist/types/util/orderbookHelpers.d.ts +161 -0
- package/dist/types/util/orderbookHelpers.d.ts.map +1 -0
- package/dist/types/util/orderbookHelpers.test.d.ts +2 -0
- package/dist/types/util/orderbookHelpers.test.d.ts.map +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -396,6 +396,46 @@ await primitiveAction.insertRecord({
|
|
|
396
396
|
- ⚡ **High-throughput data insertion** (independent records)
|
|
397
397
|
- ⚡ **Fire-and-forget operations** (with proper error handling)
|
|
398
398
|
|
|
399
|
+
### Prediction Markets (Order Book)
|
|
400
|
+
|
|
401
|
+
The SDK supports binary prediction markets through the Order Book API. Markets are settled automatically based on real-world data from trusted data providers.
|
|
402
|
+
|
|
403
|
+
```typescript
|
|
404
|
+
// Load the order book action
|
|
405
|
+
const orderbook = client.loadOrderbookAction();
|
|
406
|
+
|
|
407
|
+
// Get market info
|
|
408
|
+
const market = await orderbook.getMarketInfo(queryId);
|
|
409
|
+
console.log(`Settles at: ${new Date(market.settleTime * 1000)}`);
|
|
410
|
+
|
|
411
|
+
// Place a buy order for YES shares at 55 cents
|
|
412
|
+
const result = await orderbook.placeBuyOrder({
|
|
413
|
+
queryId: market.id,
|
|
414
|
+
outcome: true, // YES
|
|
415
|
+
price: 55, // 55 cents = 55% implied probability
|
|
416
|
+
amount: 100, // 100 shares
|
|
417
|
+
});
|
|
418
|
+
await client.waitForTx(result.data!.tx_hash);
|
|
419
|
+
|
|
420
|
+
// Get best prices
|
|
421
|
+
const prices = await orderbook.getBestPrices(market.id, true);
|
|
422
|
+
console.log(`YES: Bid=${prices.bestBid}c, Ask=${prices.bestAsk}c`);
|
|
423
|
+
```
|
|
424
|
+
|
|
425
|
+
#### Market Making with Split Limit Orders
|
|
426
|
+
|
|
427
|
+
```typescript
|
|
428
|
+
// Create YES/NO pairs and provide liquidity
|
|
429
|
+
await orderbook.placeSplitLimitOrder({
|
|
430
|
+
queryId: market.id,
|
|
431
|
+
truePrice: 55, // YES at 55c, NO at 45c
|
|
432
|
+
amount: 100, // 100 pairs
|
|
433
|
+
});
|
|
434
|
+
// Result: 100 YES holdings + 100 NO sell orders at 45c
|
|
435
|
+
```
|
|
436
|
+
|
|
437
|
+
**📖 For complete documentation including market creation, order types, settlement, and examples, see the [Order Book Operations](./docs/api-reference.md#order-book-operations) section in the API Reference and [examples/orderbook](./examples/orderbook).**
|
|
438
|
+
|
|
399
439
|
### Using the SDK with Your Local Node
|
|
400
440
|
|
|
401
441
|
If you are running your own TRUF.NETWORK node, you can configure the SDK to interact with your local instance by changing the `endpoint` in the client configuration, as shown in the [Basic Client Initialization](#basic-client-initialization) section. This is useful for development, testing, or when operating within a private network.
|
|
@@ -488,6 +528,11 @@ For other bundlers or serverless platforms, consult their documentation on modul
|
|
|
488
528
|
| List attestations | `attestationAction.listAttestations({requester, limit, offset, orderBy})` |
|
|
489
529
|
| Get transaction event | `transactionAction.getTransactionEvent({txId})` |
|
|
490
530
|
| List transaction fees | `transactionAction.listTransactionFees({wallet, mode, limit, offset})` |
|
|
531
|
+
| Create prediction market | `orderbook.createMarket({bridge, queryComponents, settleTime, ...})` |
|
|
532
|
+
| Place buy order | `orderbook.placeBuyOrder({queryId, outcome, price, amount})` |
|
|
533
|
+
| Place split limit order | `orderbook.placeSplitLimitOrder({queryId, truePrice, amount})` |
|
|
534
|
+
| Get order book | `orderbook.getOrderBook(queryId, outcome)` |
|
|
535
|
+
| Get best prices | `orderbook.getBestPrices(queryId, outcome)` |
|
|
491
536
|
| Destroy stream | `client.destroyStream(streamLocator)` |
|
|
492
537
|
|
|
493
538
|
**Safe Operation Pattern:**
|
|
@@ -35,6 +35,7 @@ var import_getLastTransactions = require("./getLastTransactions.cjs");
|
|
|
35
35
|
var import_roleManagement = require("../contracts-api/roleManagement.cjs");
|
|
36
36
|
var import_attestationAction = require("../contracts-api/attestationAction.cjs");
|
|
37
37
|
var import_transactionAction = require("../contracts-api/transactionAction.cjs");
|
|
38
|
+
var import_orderbookAction = require("../contracts-api/orderbookAction.cjs");
|
|
38
39
|
var BaseTNClient = class {
|
|
39
40
|
kwilClient;
|
|
40
41
|
signerInfo;
|
|
@@ -184,6 +185,16 @@ var BaseTNClient = class {
|
|
|
184
185
|
this.getKwilSigner()
|
|
185
186
|
);
|
|
186
187
|
}
|
|
188
|
+
/**
|
|
189
|
+
* Loads the order book action API, permitting prediction market operations.
|
|
190
|
+
* @returns An instance of OrderbookAction.
|
|
191
|
+
*/
|
|
192
|
+
loadOrderbookAction() {
|
|
193
|
+
return new import_orderbookAction.OrderbookAction(
|
|
194
|
+
this.getKwilClient(),
|
|
195
|
+
this.getKwilSigner()
|
|
196
|
+
);
|
|
197
|
+
}
|
|
187
198
|
/**
|
|
188
199
|
* Creates a new stream locator.
|
|
189
200
|
* @param streamId - The ID of the stream.
|
|
@@ -243,19 +254,26 @@ var BaseTNClient = class {
|
|
|
243
254
|
const action = this.loadAction();
|
|
244
255
|
return action.listMetadataByHeight(params);
|
|
245
256
|
}
|
|
246
|
-
|
|
257
|
+
/**
|
|
258
|
+
* Gets the wallet balance for a specific bridge instance
|
|
259
|
+
* @param bridgeIdentifier The bridge instance identifier (e.g., "sepolia", "hoodi_tt", "ethereum")
|
|
260
|
+
* @param walletAddress The wallet address to check balance for
|
|
261
|
+
* @returns Promise that resolves to the balance as a string (in wei)
|
|
262
|
+
*/
|
|
263
|
+
async getWalletBalance(bridgeIdentifier, walletAddress) {
|
|
247
264
|
const action = this.loadAction();
|
|
248
|
-
return action.getWalletBalance(
|
|
265
|
+
return action.getWalletBalance(bridgeIdentifier, walletAddress);
|
|
249
266
|
}
|
|
250
267
|
/**
|
|
251
|
-
* Performs a withdrawal operation by bridging tokens
|
|
252
|
-
* @param
|
|
253
|
-
* @param amount The amount to withdraw
|
|
268
|
+
* Performs a withdrawal operation by bridging tokens from TN to a destination chain
|
|
269
|
+
* @param bridgeIdentifier The bridge instance identifier (e.g., "sepolia", "hoodi_tt")
|
|
270
|
+
* @param amount The amount to withdraw (in wei)
|
|
271
|
+
* @param recipient The recipient address on the destination chain
|
|
254
272
|
* @returns Promise that resolves to the transaction hash, or throws on error
|
|
255
273
|
*/
|
|
256
|
-
async withdraw(
|
|
274
|
+
async withdraw(bridgeIdentifier, amount, recipient) {
|
|
257
275
|
const action = this.loadAction();
|
|
258
|
-
const bridgeResult = await action.bridgeTokens(
|
|
276
|
+
const bridgeResult = await action.bridgeTokens(bridgeIdentifier, amount, recipient);
|
|
259
277
|
if (!bridgeResult.data?.tx_hash) {
|
|
260
278
|
throw new Error("Bridge tokens operation failed: no transaction hash returned");
|
|
261
279
|
}
|
|
@@ -267,32 +285,33 @@ var BaseTNClient = class {
|
|
|
267
285
|
return bridgeResult.data.tx_hash;
|
|
268
286
|
}
|
|
269
287
|
/**
|
|
270
|
-
* Lists wallet rewards for a specific
|
|
271
|
-
* @param
|
|
288
|
+
* Lists wallet rewards for a specific bridge instance
|
|
289
|
+
* @param bridgeIdentifier The bridge instance identifier (e.g., "sepolia", "hoodi_tt")
|
|
272
290
|
* @param wallet The wallet address to list rewards for
|
|
273
291
|
* @param withPending Whether to include pending rewards
|
|
274
292
|
* @returns Promise that resolves to an array of rewards data
|
|
293
|
+
* @deprecated This method uses the extension namespace directly. Most users should use getWithdrawalProof instead.
|
|
275
294
|
*/
|
|
276
|
-
async listWalletRewards(
|
|
295
|
+
async listWalletRewards(bridgeIdentifier, wallet, withPending) {
|
|
277
296
|
const action = this.loadAction();
|
|
278
|
-
return action.listWalletRewards(
|
|
297
|
+
return action.listWalletRewards(bridgeIdentifier, wallet, withPending);
|
|
279
298
|
}
|
|
280
299
|
/**
|
|
281
|
-
* Gets withdrawal proof for a specific
|
|
282
|
-
* Returns merkle proofs and validator signatures needed for
|
|
300
|
+
* Gets withdrawal proof for a specific bridge instance
|
|
301
|
+
* Returns merkle proofs and validator signatures needed for claiming withdrawals on the destination chain
|
|
283
302
|
*
|
|
284
303
|
* This method is used for non-custodial bridge withdrawals where users need to
|
|
285
|
-
* manually claim their withdrawals by submitting proofs to the destination chain.
|
|
304
|
+
* manually claim their withdrawals by submitting proofs to the destination chain contract.
|
|
286
305
|
* The proof includes validator signatures, merkle root, block hash, and amount.
|
|
287
306
|
*
|
|
288
|
-
* @param
|
|
307
|
+
* @param bridgeIdentifier The bridge instance identifier (e.g., "hoodi_tt", "sepolia", "ethereum")
|
|
289
308
|
* @param walletAddress The wallet address to get withdrawal proof for
|
|
290
|
-
* @returns Promise that resolves to an array of withdrawal proof data
|
|
309
|
+
* @returns Promise that resolves to an array of withdrawal proof data (empty array if no unclaimed withdrawals)
|
|
291
310
|
*
|
|
292
311
|
* @example
|
|
293
312
|
* ```typescript
|
|
294
|
-
* // Get withdrawal proofs for Hoodi
|
|
295
|
-
* const proofs = await client.getWithdrawalProof("
|
|
313
|
+
* // Get withdrawal proofs for Hoodi Test Token bridge
|
|
314
|
+
* const proofs = await client.getWithdrawalProof("hoodi_tt", "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb");
|
|
296
315
|
*
|
|
297
316
|
* // Proofs will be an array like:
|
|
298
317
|
* // [{
|
|
@@ -307,14 +326,20 @@ var BaseTNClient = class {
|
|
|
307
326
|
* // proofs: [],
|
|
308
327
|
* // signatures: [<base64-encoded-signatures>]
|
|
309
328
|
* // }]
|
|
329
|
+
*
|
|
330
|
+
* // Use the proofs to claim withdrawal on destination chain
|
|
331
|
+
* if (proofs.length > 0) {
|
|
332
|
+
* const proof = proofs[0];
|
|
333
|
+
* await bridgeContract.claimWithdrawal(proof.recipient, proof.amount, proof.root, proof.proofs, proof.signatures);
|
|
334
|
+
* }
|
|
310
335
|
* ```
|
|
311
336
|
*
|
|
312
337
|
* @note This method has been tested via integration tests in the node repository.
|
|
313
338
|
* See: https://github.com/trufnetwork/kwil-db/blob/main/node/exts/erc20-bridge/erc20/meta_extension_withdrawal_test.go
|
|
314
339
|
*/
|
|
315
|
-
async getWithdrawalProof(
|
|
340
|
+
async getWithdrawalProof(bridgeIdentifier, walletAddress) {
|
|
316
341
|
const action = this.loadAction();
|
|
317
|
-
return action.getWithdrawalProof(
|
|
342
|
+
return action.getWithdrawalProof(bridgeIdentifier, walletAddress);
|
|
318
343
|
}
|
|
319
344
|
/**
|
|
320
345
|
* 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 { 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 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 withdrawal proof for a specific wallet address on a blockchain network\n * Returns merkle proofs and validator signatures needed for withdrawal\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.\n * The proof includes validator signatures, merkle root, block hash, and amount.\n *\n * @param chain The chain identifier (e.g., \"hoodi\", \"sepolia\", etc.)\n * @param walletAddress The wallet address to get withdrawal proof for\n * @returns Promise that resolves to an array of withdrawal proof data\n *\n * @example\n * ```typescript\n * // Get withdrawal proofs for Hoodi\n * const proofs = await client.getWithdrawalProof(\"hoodi\", \"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 *\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(chain: string, walletAddress: string): Promise<WithdrawalProof[]> {\n const action = this.loadAction();\n return action.getWithdrawalProof(chain, 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;AAAA;AAAA;AAAA;AAAA;AAAA,qBAA8E;AAC9E,4BAAiH;AACjH,0BAA6B;AAC7B,0BAA6B;AAC7B,6BAAgC;AAChC,oBAAwE;AAIxE,6BAAgC;AAEhC,yBAA4B;AAC5B,iCAAoC;AACpC,4BAA+B;AAC/B,+BAAkC;AAClC,+BAAkC;AA+
|
|
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 { OrderbookAction } from \"../contracts-api/orderbookAction\";\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 * Loads the order book action API, permitting prediction market operations.\n * @returns An instance of OrderbookAction.\n */\n loadOrderbookAction(): OrderbookAction {\n return new OrderbookAction(\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;AAAA;AAAA;AAAA;AAAA;AAAA,qBAA8E;AAC9E,4BAAiH;AACjH,0BAA6B;AAC7B,0BAA6B;AAC7B,6BAAgC;AAChC,oBAAwE;AAIxE,6BAAgC;AAEhC,yBAA4B;AAC5B,iCAAoC;AACpC,4BAA+B;AAC/B,+BAAkC;AAClC,+BAAkC;AAClC,6BAAgC;AA+BzB,IAAe,eAAf,MAAuD;AAAA,EAClD;AAAA,EACA;AAAA,EAEA,YAAY,SAA0B;AAC9C,SAAK,aAAa,QAAQ;AAAA,EAC5B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,UAAU,QAAgB,UAAU,MAAqC;AAC7E,WAAO,IAAI,QAA6B,OAAO,SAAS,WAAW;AACjE,YAAM,WAAW,YAAY,YAAY;AACvC,cAAM,UAAU,MAAM,KAAK,cAAc,EACtC,cAAc,EAAE,MAAM,EACtB,MAAM,OAAO,EAAE,MAAM,QAAW,QAAQ,OAAU,EAAE;AACvD,gBAAQ,QAAQ,QAAQ;AAAA,UACtB,KAAK;AACH,gBAAI,QAAQ,MAAM,WAAW,QAAQ,UAAa,QAAQ,MAAM,WA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A,MAAM;AAAA,IACR;AACA,WAAO,GAAG,MAAM;AAAA,EAClB;AAAA;AAAA,EAGA,MAAM,WAAW,OAKG;AAClB,UAAM,KAAK,KAAK,yBAAyB;AACzC,UAAM,aAAgC,MAAM,QAAQ,MAAM,OAAO,IAC7D,MAAM,UACN,CAAC,MAAM,OAAO;AAClB,UAAM,KAAK,MAAM,GAAG;AAAA,MAClB;AAAA,QACE,OAAO,MAAM;AAAA,QACb,UAAU,MAAM;AAAA,QAChB,SAAS;AAAA,MACX;AAAA,MACA,MAAM;AAAA,IACR;AACA,WAAO,GAAG,MAAM;AAAA,EAClB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,WAAW,OAII;AACnB,UAAM,KAAK,KAAK,yBAAyB;AACzC,UAAM,MAAM,MAAM,GAAG,aAAa;AAAA,MAChC,OAAO,MAAM;AAAA,MACb,UAAU,MAAM;AAAA,MAChB,SAAS,CAAC,MAAM,MAAM;AAAA,IACxB,CAAC;AACD,WAAO,IAAI,SAAS,KAAK,IAAI,CAAC,EAAE;AAAA,EAClC;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,gBAAgB,OAK4B;AAChD,UAAM,KAAK,KAAK,yBAAyB;AACzC,WAAO,GAAG,gBAAgB;AAAA,MACxB,OAAO,MAAM;AAAA,MACb,UAAU,MAAM;AAAA,MAChB,OAAO,MAAM;AAAA,MACb,QAAQ,MAAM;AAAA,IAChB,CAAC;AAAA,EACH;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -660,14 +660,23 @@ var Action = class _Action {
|
|
|
660
660
|
return result.map((rows) => rows[0].database_size_pretty).throw();
|
|
661
661
|
}
|
|
662
662
|
/**
|
|
663
|
-
* Gets the wallet balance
|
|
664
|
-
* @param
|
|
663
|
+
* Gets the wallet balance for a specific bridge instance
|
|
664
|
+
* @param bridgeIdentifier The bridge instance identifier (e.g., "sepolia", "hoodi_tt", "ethereum")
|
|
665
|
+
* This corresponds to the bridge instance name in TN (e.g., hoodi_tt for Hoodi Test Token bridge)
|
|
665
666
|
* @param walletAddress The wallet address to check balance for
|
|
666
|
-
* @returns Promise that resolves to the balance as a string, or throws on error
|
|
667
|
+
* @returns Promise that resolves to the balance as a string (in wei), or throws on error
|
|
668
|
+
* @example
|
|
669
|
+
* ```typescript
|
|
670
|
+
* // Simple case - identifier matches network name
|
|
671
|
+
* const balance = await action.getWalletBalance("sepolia", "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb");
|
|
672
|
+
*
|
|
673
|
+
* // Multi-token bridge - specify bridge instance explicitly
|
|
674
|
+
* const balance = await action.getWalletBalance("hoodi_tt", "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb");
|
|
675
|
+
* ```
|
|
667
676
|
*/
|
|
668
|
-
async getWalletBalance(
|
|
677
|
+
async getWalletBalance(bridgeIdentifier, walletAddress) {
|
|
669
678
|
const result = await this.call(
|
|
670
|
-
`${
|
|
679
|
+
`${bridgeIdentifier}_wallet_balance`,
|
|
671
680
|
{
|
|
672
681
|
$wallet_address: walletAddress
|
|
673
682
|
}
|
|
@@ -705,32 +714,42 @@ var Action = class _Action {
|
|
|
705
714
|
}).throw();
|
|
706
715
|
}
|
|
707
716
|
/**
|
|
708
|
-
* Bridges tokens
|
|
709
|
-
* @param
|
|
710
|
-
* @param amount The amount to bridge
|
|
711
|
-
* @
|
|
717
|
+
* Bridges tokens by initiating a withdrawal from TN to a blockchain network
|
|
718
|
+
* @param bridgeIdentifier The bridge instance identifier (e.g., "sepolia", "hoodi_tt", "ethereum")
|
|
719
|
+
* @param amount The amount to bridge in wei (as string to preserve precision)
|
|
720
|
+
* @param recipient The recipient address on the destination chain
|
|
721
|
+
* @returns Promise that resolves to transaction receipt
|
|
722
|
+
* @example
|
|
723
|
+
* ```typescript
|
|
724
|
+
* // Bridge 100 tokens from TN to Sepolia
|
|
725
|
+
* const receipt = await action.bridgeTokens("sepolia", "100000000000000000000", "0x742d35Cc...");
|
|
726
|
+
*
|
|
727
|
+
* // Bridge from TN to Hoodi Test Token bridge
|
|
728
|
+
* const receipt = await action.bridgeTokens("hoodi_tt", "50000000000000000000", "0x742d35Cc...");
|
|
729
|
+
* ```
|
|
712
730
|
*/
|
|
713
|
-
async bridgeTokens(
|
|
731
|
+
async bridgeTokens(bridgeIdentifier, amount, recipient) {
|
|
714
732
|
const numAmount = parseFloat(amount);
|
|
715
733
|
if (isNaN(numAmount) || numAmount <= 0) {
|
|
716
734
|
throw new Error(`Invalid amount: ${amount}. Amount must be greater than 0.`);
|
|
717
735
|
}
|
|
718
|
-
return await this.executeWithNamedParams(`${
|
|
736
|
+
return await this.executeWithNamedParams(`${bridgeIdentifier}_bridge_tokens`, [{
|
|
719
737
|
$recipient: recipient,
|
|
720
738
|
$amount: amount
|
|
721
739
|
}]);
|
|
722
740
|
}
|
|
723
741
|
/**
|
|
724
|
-
* Lists wallet rewards
|
|
725
|
-
* @param
|
|
742
|
+
* Lists wallet rewards for a specific bridge instance
|
|
743
|
+
* @param bridgeIdentifier The bridge instance identifier (e.g., "sepolia", "hoodi_tt")
|
|
726
744
|
* @param wallet The wallet address to list rewards for
|
|
727
745
|
* @param withPending Whether to include pending rewards
|
|
728
|
-
* @returns Promise that resolves to
|
|
746
|
+
* @returns Promise that resolves to array of reward records
|
|
747
|
+
* @deprecated This method uses the extension namespace directly. Most users should use getWithdrawalProof instead.
|
|
729
748
|
*/
|
|
730
|
-
async listWalletRewards(
|
|
749
|
+
async listWalletRewards(bridgeIdentifier, wallet, withPending) {
|
|
731
750
|
const result = await this.kwilClient.call(
|
|
732
751
|
{
|
|
733
|
-
namespace: `${
|
|
752
|
+
namespace: `${bridgeIdentifier}_bridge`,
|
|
734
753
|
name: "list_wallet_rewards",
|
|
735
754
|
inputs: {
|
|
736
755
|
$param_1: wallet,
|
|
@@ -745,29 +764,35 @@ var Action = class _Action {
|
|
|
745
764
|
return result.data?.result || [];
|
|
746
765
|
}
|
|
747
766
|
/**
|
|
748
|
-
* Gets withdrawal proof for a wallet address on a
|
|
749
|
-
* Returns merkle proofs and validator signatures needed for
|
|
767
|
+
* Gets withdrawal proof for a wallet address on a specific bridge instance
|
|
768
|
+
* Returns merkle proofs and validator signatures needed for claiming withdrawals on the destination chain
|
|
750
769
|
*
|
|
751
770
|
* This method is used for non-custodial bridge withdrawals where users need to
|
|
752
|
-
* manually claim their withdrawals by submitting proofs to the destination chain.
|
|
771
|
+
* manually claim their withdrawals by submitting proofs to the destination chain contract.
|
|
753
772
|
*
|
|
754
|
-
* @param
|
|
773
|
+
* @param bridgeIdentifier The bridge instance identifier (e.g., "hoodi_tt", "sepolia", "ethereum")
|
|
755
774
|
* @param walletAddress The wallet address to get withdrawal proof for
|
|
756
|
-
* @returns Promise that resolves to array of withdrawal proofs
|
|
775
|
+
* @returns Promise that resolves to array of withdrawal proofs (empty array if no unclaimed withdrawals)
|
|
757
776
|
*
|
|
758
777
|
* @example
|
|
759
778
|
* ```typescript
|
|
760
|
-
* // Get withdrawal proofs for Hoodi
|
|
761
|
-
* const proofs = await action.getWithdrawalProof("
|
|
762
|
-
* // Returns: [{ chain: "hoodi", recipient: "0x...", amount: "100000000000000000000", ... }]
|
|
779
|
+
* // Get withdrawal proofs for Hoodi Test Token bridge
|
|
780
|
+
* const proofs = await action.getWithdrawalProof("hoodi_tt", "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb");
|
|
781
|
+
* // Returns: [{ chain: "hoodi", recipient: "0x...", amount: "100000000000000000000", proofs: [...], signatures: [...] }]
|
|
782
|
+
*
|
|
783
|
+
* // Use the proofs to claim withdrawal on destination chain
|
|
784
|
+
* if (proofs.length > 0) {
|
|
785
|
+
* const proof = proofs[0];
|
|
786
|
+
* await bridgeContract.claimWithdrawal(proof.recipient, proof.amount, proof.root, proof.proofs, proof.signatures);
|
|
787
|
+
* }
|
|
763
788
|
* ```
|
|
764
789
|
*
|
|
765
790
|
* @note This method has been tested via integration tests in the node repository.
|
|
766
791
|
* See: https://github.com/trufnetwork/kwil-db/blob/main/node/exts/erc20-bridge/erc20/meta_extension_withdrawal_test.go
|
|
767
792
|
*/
|
|
768
|
-
async getWithdrawalProof(
|
|
793
|
+
async getWithdrawalProof(bridgeIdentifier, walletAddress) {
|
|
769
794
|
const result = await this.call(
|
|
770
|
-
`${
|
|
795
|
+
`${bridgeIdentifier}_get_withdrawal_proof`,
|
|
771
796
|
{
|
|
772
797
|
$wallet_address: walletAddress
|
|
773
798
|
}
|