@campnetwork/origin 1.4.0-alpha.1 → 1.4.0-alpha.3

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.
@@ -566,18 +566,20 @@ declare function getVaultRevenueTokens(this: Origin, tokenId: bigint): Promise<A
566
566
 
567
567
  /**
568
568
  * Returns the amount of revenue claimable by a holder for a given token and revenue token.
569
- * If no holder is provided, the connected wallet address is used.
569
+ * If no holder is provided, the NFT's Token Bound Account (TBA) is used,
570
+ * since RT tokens are held in the TBA by default.
570
571
  *
571
572
  * @param tokenId The token ID whose vault to query.
572
573
  * @param revenueToken The ERC20 revenue token address.
573
- * @param holder Optional holder address. Defaults to connected wallet.
574
+ * @param holder Optional holder address. Defaults to the NFT's TBA.
574
575
  * @returns The claimable amount in the revenue token's smallest unit.
575
576
  */
576
577
  declare function claimableRevenue(this: Origin, tokenId: bigint, revenueToken: Address, holder?: Address): Promise<bigint>;
577
578
 
578
579
  /**
579
580
  * Claims accumulated revenue for a token from a specific revenue token.
580
- * The caller must hold Royalty Tokens to claim their proportional share.
581
+ * Executes the claim through the NFT's Token Bound Account (TBA),
582
+ * since the TBA holds the Royalty Tokens.
581
583
  *
582
584
  * @param tokenId The token ID whose vault to claim from.
583
585
  * @param revenueToken The ERC20 revenue token address to claim.
@@ -587,7 +589,8 @@ declare function claimRevenue(this: Origin, tokenId: bigint, revenueToken: Addre
587
589
 
588
590
  /**
589
591
  * Claims accumulated revenue for a token from multiple revenue tokens in a single transaction.
590
- * The caller must hold Royalty Tokens to claim their proportional share.
592
+ * Executes the claim through the NFT's Token Bound Account (TBA),
593
+ * since the TBA holds the Royalty Tokens.
591
594
  *
592
595
  * @param tokenId The token ID whose vault to claim from.
593
596
  * @param revenueTokens Array of ERC20 revenue token addresses to claim.
@@ -1,6 +1,6 @@
1
1
  'use client';
2
2
  import React, { createContext, useState, useContext, useEffect, useLayoutEffect, useRef, useSyncExternalStore } from 'react';
3
- import { custom, createWalletClient, createPublicClient, http, zeroAddress, erc20Abi as erc20Abi$1, getAbiItem, formatEther, formatUnits, encodeFunctionData, checksumAddress, parseEther } from 'viem';
3
+ import { custom, createWalletClient, createPublicClient, http, zeroAddress, erc20Abi as erc20Abi$1, encodeFunctionData, getAbiItem, formatEther, formatUnits, checksumAddress, parseEther } from 'viem';
4
4
  import { toAccount } from 'viem/accounts';
5
5
  import { createSiweMessage } from 'viem/siwe';
6
6
  import axios from 'axios';
@@ -8032,16 +8032,17 @@ function getVaultRevenueTokens(tokenId) {
8032
8032
 
8033
8033
  /**
8034
8034
  * Returns the amount of revenue claimable by a holder for a given token and revenue token.
8035
- * If no holder is provided, the connected wallet address is used.
8035
+ * If no holder is provided, the NFT's Token Bound Account (TBA) is used,
8036
+ * since RT tokens are held in the TBA by default.
8036
8037
  *
8037
8038
  * @param tokenId The token ID whose vault to query.
8038
8039
  * @param revenueToken The ERC20 revenue token address.
8039
- * @param holder Optional holder address. Defaults to connected wallet.
8040
+ * @param holder Optional holder address. Defaults to the NFT's TBA.
8040
8041
  * @returns The claimable amount in the revenue token's smallest unit.
8041
8042
  */
8042
8043
  function claimableRevenue(tokenId, revenueToken, holder) {
8043
8044
  return __awaiter(this, void 0, void 0, function* () {
8044
- const holderAddress = yield resolveWalletAddress(this.viemClient, holder);
8045
+ const holderAddress = holder || (yield this.getTokenBoundAccount(tokenId));
8045
8046
  const amount = yield this.callContractMethod(this.environment.MARKETPLACE_CONTRACT_ADDRESS, this.environment.MARKETPLACE_ABI, "claimableRevenue", [tokenId, holderAddress, revenueToken]);
8046
8047
  return amount;
8047
8048
  });
@@ -8049,7 +8050,8 @@ function claimableRevenue(tokenId, revenueToken, holder) {
8049
8050
 
8050
8051
  /**
8051
8052
  * Claims accumulated revenue for a token from a specific revenue token.
8052
- * The caller must hold Royalty Tokens to claim their proportional share.
8053
+ * Executes the claim through the NFT's Token Bound Account (TBA),
8054
+ * since the TBA holds the Royalty Tokens.
8053
8055
  *
8054
8056
  * @param tokenId The token ID whose vault to claim from.
8055
8057
  * @param revenueToken The ERC20 revenue token address to claim.
@@ -8057,13 +8059,25 @@ function claimableRevenue(tokenId, revenueToken, holder) {
8057
8059
  */
8058
8060
  function claimRevenue(tokenId, revenueToken) {
8059
8061
  return __awaiter(this, void 0, void 0, function* () {
8060
- return this.callContractMethod(this.environment.MARKETPLACE_CONTRACT_ADDRESS, this.environment.MARKETPLACE_ABI, "claimRevenue", [tokenId, revenueToken], { waitForReceipt: true });
8062
+ const tokenBoundAccount = yield this.getTokenBoundAccount(tokenId);
8063
+ const data = encodeFunctionData({
8064
+ abi: this.environment.MARKETPLACE_ABI,
8065
+ functionName: "claimRevenue",
8066
+ args: [tokenId, revenueToken],
8067
+ });
8068
+ return this.callContractMethod(tokenBoundAccount, this.environment.TBA_ABI, "execute", [
8069
+ this.environment.MARKETPLACE_CONTRACT_ADDRESS,
8070
+ BigInt(0),
8071
+ data,
8072
+ 0,
8073
+ ], { waitForReceipt: true, value: BigInt(0) });
8061
8074
  });
8062
8075
  }
8063
8076
 
8064
8077
  /**
8065
8078
  * Claims accumulated revenue for a token from multiple revenue tokens in a single transaction.
8066
- * The caller must hold Royalty Tokens to claim their proportional share.
8079
+ * Executes the claim through the NFT's Token Bound Account (TBA),
8080
+ * since the TBA holds the Royalty Tokens.
8067
8081
  *
8068
8082
  * @param tokenId The token ID whose vault to claim from.
8069
8083
  * @param revenueTokens Array of ERC20 revenue token addresses to claim.
@@ -8071,7 +8085,18 @@ function claimRevenue(tokenId, revenueToken) {
8071
8085
  */
8072
8086
  function claimRevenueBatch(tokenId, revenueTokens) {
8073
8087
  return __awaiter(this, void 0, void 0, function* () {
8074
- return this.callContractMethod(this.environment.MARKETPLACE_CONTRACT_ADDRESS, this.environment.MARKETPLACE_ABI, "claimRevenueBatch", [tokenId, revenueTokens], { waitForReceipt: true });
8088
+ const tokenBoundAccount = yield this.getTokenBoundAccount(tokenId);
8089
+ const data = encodeFunctionData({
8090
+ abi: this.environment.MARKETPLACE_ABI,
8091
+ functionName: "claimRevenueBatch",
8092
+ args: [tokenId, revenueTokens],
8093
+ });
8094
+ return this.callContractMethod(tokenBoundAccount, this.environment.TBA_ABI, "execute", [
8095
+ this.environment.MARKETPLACE_CONTRACT_ADDRESS,
8096
+ BigInt(0),
8097
+ data,
8098
+ 0,
8099
+ ], { waitForReceipt: true, value: BigInt(0) });
8075
8100
  });
8076
8101
  }
8077
8102
 
@@ -8849,7 +8874,7 @@ class Origin {
8849
8874
  */
8850
8875
  callContractMethod(contractAddress_1, abi_1, methodName_1, params_1) {
8851
8876
  return __awaiter(this, arguments, void 0, function* (contractAddress, abi, methodName, params, options = {}) {
8852
- var _a;
8877
+ var _a, _b;
8853
8878
  let account = null;
8854
8879
  try {
8855
8880
  account = yield __classPrivateFieldGet(this, _Origin_instances, "m", _Origin_getCurrentAccount).call(this);
@@ -8864,12 +8889,12 @@ class Origin {
8864
8889
  abiItem.stateMutability === "pure");
8865
8890
  if (isView) {
8866
8891
  const publicClient = getPublicClient();
8867
- const result = (yield publicClient.readContract({
8892
+ const result = (_a = (yield publicClient.readContract({
8868
8893
  address: contractAddress,
8869
8894
  abi,
8870
8895
  functionName: methodName,
8871
8896
  args: params,
8872
- })) || null;
8897
+ }))) !== null && _a !== void 0 ? _a : null;
8873
8898
  return result;
8874
8899
  }
8875
8900
  yield __classPrivateFieldGet(this, _Origin_instances, "m", _Origin_ensureChainId).call(this, this.environment.CHAIN);
@@ -8887,7 +8912,7 @@ class Origin {
8887
8912
  return simulatedResult;
8888
8913
  }
8889
8914
  try {
8890
- const txHash = yield ((_a = this.viemClient) === null || _a === void 0 ? void 0 : _a.writeContract(request));
8915
+ const txHash = yield ((_b = this.viemClient) === null || _b === void 0 ? void 0 : _b.writeContract(request));
8891
8916
  if (typeof txHash !== "string") {
8892
8917
  throw new ContractError(`Transaction for "${methodName}" failed to send: no transaction hash returned`, { contractName: contractAddress, methodName });
8893
8918
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@campnetwork/origin",
3
- "version": "1.4.0-alpha.1",
3
+ "version": "1.4.0-alpha.3",
4
4
  "main": "dist/core.cjs",
5
5
  "exports": {
6
6
  ".": {