clawntenna 0.11.2 → 0.11.4

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/index.d.cts CHANGED
@@ -270,6 +270,11 @@ declare class Clawntenna {
270
270
  * Automatically determines encryption key based on topic access level.
271
271
  */
272
272
  sendMessage(topicId: number, text: string, options?: SendOptions): Promise<ethers.TransactionResponse>;
273
+ /**
274
+ * Check if the current signer is exempt from message fees on a topic.
275
+ * Mirrors contract logic: topic owner, app owner, ROLE_ADMIN, PERMISSION_ADMIN.
276
+ */
277
+ private _isFeeExempt;
273
278
  /**
274
279
  * Read and decrypt recent messages from a topic.
275
280
  */
package/dist/index.d.ts CHANGED
@@ -270,6 +270,11 @@ declare class Clawntenna {
270
270
  * Automatically determines encryption key based on topic access level.
271
271
  */
272
272
  sendMessage(topicId: number, text: string, options?: SendOptions): Promise<ethers.TransactionResponse>;
273
+ /**
274
+ * Check if the current signer is exempt from message fees on a topic.
275
+ * Mirrors contract logic: topic owner, app owner, ROLE_ADMIN, PERMISSION_ADMIN.
276
+ */
277
+ private _isFeeExempt;
273
278
  /**
274
279
  * Read and decrypt recent messages from a topic.
275
280
  */
package/dist/index.js CHANGED
@@ -692,7 +692,53 @@ var Clawntenna = class _Clawntenna {
692
692
  replyAuthor,
693
693
  mentions: options?.mentions
694
694
  });
695
- return this.registry.sendMessage(topicId, ethers.toUtf8Bytes(encrypted));
695
+ const txOverrides = {};
696
+ try {
697
+ const fee = await this.getTopicMessageFee(topicId);
698
+ if (fee.amount > BigInt(0)) {
699
+ const exempt = await this._isFeeExempt(topicId);
700
+ if (!exempt) {
701
+ if (fee.token === ethers.ZeroAddress) {
702
+ txOverrides.value = fee.amount;
703
+ } else {
704
+ const token = new ethers.Contract(fee.token, [
705
+ "function allowance(address,address) view returns (uint256)",
706
+ "function approve(address,uint256) returns (bool)"
707
+ ], this._signer);
708
+ const registryAddr = await this._registry.getAddress();
709
+ const allowance = await token.allowance(this._address, registryAddr);
710
+ if (allowance < fee.amount) {
711
+ const approveTx = await token.approve(registryAddr, fee.amount);
712
+ await approveTx.wait();
713
+ }
714
+ }
715
+ }
716
+ }
717
+ } catch {
718
+ }
719
+ return this.registry.sendMessage(topicId, ethers.toUtf8Bytes(encrypted), txOverrides);
720
+ }
721
+ /**
722
+ * Check if the current signer is exempt from message fees on a topic.
723
+ * Mirrors contract logic: topic owner, app owner, ROLE_ADMIN, PERMISSION_ADMIN.
724
+ */
725
+ async _isFeeExempt(topicId) {
726
+ const addr = this._address.toLowerCase();
727
+ const topic = await this.getTopic(topicId);
728
+ if (topic.owner.toLowerCase() === addr) return true;
729
+ const app = await this.getApplication(Number(topic.applicationId));
730
+ if (app.owner.toLowerCase() === addr) return true;
731
+ try {
732
+ const member = await this.getMember(Number(topic.applicationId), this._address);
733
+ if ((member.roles & 8 /* ADMIN */) !== 0) return true;
734
+ } catch {
735
+ }
736
+ try {
737
+ const perm = await this.getTopicPermission(topicId, this._address);
738
+ if (perm === 4 /* ADMIN */) return true;
739
+ } catch {
740
+ }
741
+ return false;
696
742
  }
697
743
  /**
698
744
  * Read and decrypt recent messages from a topic.
@@ -793,7 +839,28 @@ var Clawntenna = class _Clawntenna {
793
839
  // ===== TOPICS =====
794
840
  async createTopic(appId, name, description, accessLevel) {
795
841
  this.requireSigner();
796
- return this.registry.createTopic(appId, name, description, accessLevel);
842
+ const txOverrides = {};
843
+ try {
844
+ const app = await this.getApplication(appId);
845
+ const feeAmount = app.topicCreationFeeAmount ?? BigInt(0);
846
+ const feeToken = app.topicCreationFeeToken ?? ethers.ZeroAddress;
847
+ if (feeAmount > BigInt(0) && feeToken === ethers.ZeroAddress) {
848
+ txOverrides.value = feeAmount;
849
+ } else if (feeAmount > BigInt(0)) {
850
+ const token = new ethers.Contract(feeToken, [
851
+ "function allowance(address,address) view returns (uint256)",
852
+ "function approve(address,uint256) returns (bool)"
853
+ ], this._signer);
854
+ const registryAddr = await this._registry.getAddress();
855
+ const allowance = await token.allowance(this._address, registryAddr);
856
+ if (allowance < feeAmount) {
857
+ const approveTx = await token.approve(registryAddr, feeAmount);
858
+ await approveTx.wait();
859
+ }
860
+ }
861
+ } catch {
862
+ }
863
+ return this.registry.createTopic(appId, name, description, accessLevel, txOverrides);
797
864
  }
798
865
  async getTopic(topicId) {
799
866
  return this._wrapRpcError(async () => {