clawntenna 0.8.7 → 0.8.8
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 +54 -8
- package/dist/cli/index.js +337 -8
- package/dist/index.cjs +185 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +84 -2
- package/dist/index.d.ts +84 -2
- package/dist/index.js +183 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -27,6 +27,8 @@ __export(index_exports, {
|
|
|
27
27
|
CHAINS: () => CHAINS,
|
|
28
28
|
CHAIN_IDS: () => CHAIN_IDS,
|
|
29
29
|
Clawntenna: () => Clawntenna,
|
|
30
|
+
DepositStatus: () => DepositStatus,
|
|
31
|
+
ESCROW_ABI: () => ESCROW_ABI,
|
|
30
32
|
IDENTITY_REGISTRY_ABI: () => IDENTITY_REGISTRY_ABI,
|
|
31
33
|
KEY_MANAGER_ABI: () => KEY_MANAGER_ABI,
|
|
32
34
|
PERMISSION_ADMIN: () => PERMISSION_ADMIN,
|
|
@@ -75,7 +77,8 @@ var CHAINS = {
|
|
|
75
77
|
registry: "0xf39b193aedC1Ec9FD6C5ccc24fBAe58ba9f52413",
|
|
76
78
|
keyManager: "0x5562B553a876CBdc8AA4B3fb0687f22760F4759e",
|
|
77
79
|
schemaRegistry: "0xB7eB50e9058198b99b5b2589E6D70b2d99d5440a",
|
|
78
|
-
identityRegistry: "0x8004AA63c570c570eBF15376c0dB199918BFe9Fb"
|
|
80
|
+
identityRegistry: "0x8004AA63c570c570eBF15376c0dB199918BFe9Fb",
|
|
81
|
+
escrow: "0x74e376C53f4afd5Cd32a77dDc627f477FcFC2333"
|
|
79
82
|
},
|
|
80
83
|
base: {
|
|
81
84
|
chainId: 8453,
|
|
@@ -146,6 +149,10 @@ var REGISTRY_ABI = [
|
|
|
146
149
|
"function appNicknameCooldown(uint256 appId) view returns (uint256)",
|
|
147
150
|
// Fees
|
|
148
151
|
"function getTopicMessageFee(uint256 topicId) view returns (address token, uint256 amount)",
|
|
152
|
+
"function PLATFORM_FEE_BPS() view returns (uint256)",
|
|
153
|
+
"function PLATFORM_FEE_BPS_V7() view returns (uint256)",
|
|
154
|
+
"function APP_OWNER_FEE_BPS() view returns (uint256)",
|
|
155
|
+
"function BPS_DENOMINATOR() view returns (uint256)",
|
|
149
156
|
// ===== WRITE FUNCTIONS =====
|
|
150
157
|
// Applications
|
|
151
158
|
"function createApplication(string name, string description, string frontendUrl, bool allowPublicTopicCreation) returns (uint256)",
|
|
@@ -178,6 +185,7 @@ var REGISTRY_ABI = [
|
|
|
178
185
|
"event TopicPermissionSet(uint256 indexed topicId, address indexed user, uint8 permission)",
|
|
179
186
|
"event MessageSent(uint256 indexed topicId, address indexed sender, bytes payload, uint256 timestamp)",
|
|
180
187
|
"event TopicMessageFeeUpdated(uint256 indexed topicId, address token, uint256 amount)",
|
|
188
|
+
"event FeeCollected(address indexed token, uint256 totalAmount, address indexed recipient, uint256 recipientAmount, address indexed appOwner, uint256 appOwnerAmount, uint256 platformAmount)",
|
|
181
189
|
// Agent identity (V5)
|
|
182
190
|
"function registerAgentIdentity(uint256 appId, uint256 tokenId)",
|
|
183
191
|
"function clearAgentIdentity(uint256 appId)",
|
|
@@ -239,6 +247,31 @@ var IDENTITY_REGISTRY_ABI = [
|
|
|
239
247
|
"function getVersion() pure returns (string)",
|
|
240
248
|
"event Registered(uint256 indexed agentId, string agentURI, address indexed owner)"
|
|
241
249
|
];
|
|
250
|
+
var ESCROW_ABI = [
|
|
251
|
+
// ===== READ FUNCTIONS =====
|
|
252
|
+
"function getVersion() pure returns (string)",
|
|
253
|
+
"function registry() view returns (address)",
|
|
254
|
+
"function treasury() view returns (address)",
|
|
255
|
+
"function depositCount() view returns (uint256)",
|
|
256
|
+
"function isEscrowEnabled(uint256 topicId) view returns (bool)",
|
|
257
|
+
"function topicEscrowEnabled(uint256 topicId) view returns (bool)",
|
|
258
|
+
"function topicEscrowTimeout(uint256 topicId) view returns (uint64)",
|
|
259
|
+
"function getDeposit(uint256 depositId) view returns (uint256 id, uint256 topicId, address sender, address recipient, address token, uint256 amount, address appOwner, uint64 depositedAt, uint64 timeout, uint8 status)",
|
|
260
|
+
"function getDepositStatus(uint256 depositId) view returns (uint8)",
|
|
261
|
+
"function getPendingDeposits(uint256 topicId) view returns (uint256[])",
|
|
262
|
+
"function canClaimRefund(uint256 depositId) view returns (bool)",
|
|
263
|
+
// ===== WRITE FUNCTIONS =====
|
|
264
|
+
"function enableEscrow(uint256 topicId, uint64 timeoutSeconds)",
|
|
265
|
+
"function disableEscrow(uint256 topicId)",
|
|
266
|
+
"function claimRefund(uint256 depositId)",
|
|
267
|
+
"function batchClaimRefunds(uint256[] depositIds)",
|
|
268
|
+
// ===== EVENTS =====
|
|
269
|
+
"event EscrowEnabled(uint256 indexed topicId, uint64 timeout)",
|
|
270
|
+
"event EscrowDisabled(uint256 indexed topicId)",
|
|
271
|
+
"event DepositRecorded(uint256 indexed depositId, uint256 indexed topicId, address indexed sender, uint256 amount)",
|
|
272
|
+
"event DepositReleased(uint256 indexed depositId, uint256 indexed topicId, uint256 recipientAmount, uint256 appOwnerAmount, uint256 platformAmount)",
|
|
273
|
+
"event DepositRefunded(uint256 indexed depositId, uint256 indexed topicId, address indexed sender, uint256 amount)"
|
|
274
|
+
];
|
|
242
275
|
var KEY_MANAGER_ABI = [
|
|
243
276
|
// ===== READ FUNCTIONS =====
|
|
244
277
|
"function hasPublicKey(address user) view returns (bool)",
|
|
@@ -293,6 +326,12 @@ var Role = /* @__PURE__ */ ((Role2) => {
|
|
|
293
326
|
Role2[Role2["OWNER_DELEGATE"] = 16] = "OWNER_DELEGATE";
|
|
294
327
|
return Role2;
|
|
295
328
|
})(Role || {});
|
|
329
|
+
var DepositStatus = /* @__PURE__ */ ((DepositStatus2) => {
|
|
330
|
+
DepositStatus2[DepositStatus2["Pending"] = 0] = "Pending";
|
|
331
|
+
DepositStatus2[DepositStatus2["Released"] = 1] = "Released";
|
|
332
|
+
DepositStatus2[DepositStatus2["Refunded"] = 2] = "Refunded";
|
|
333
|
+
return DepositStatus2;
|
|
334
|
+
})(DepositStatus || {});
|
|
296
335
|
|
|
297
336
|
// src/constants.ts
|
|
298
337
|
var ACCESS_PUBLIC = 0 /* PUBLIC */;
|
|
@@ -466,6 +505,7 @@ var Clawntenna = class {
|
|
|
466
505
|
keyManager;
|
|
467
506
|
schemaRegistry;
|
|
468
507
|
identityRegistry;
|
|
508
|
+
escrow;
|
|
469
509
|
chainName;
|
|
470
510
|
// In-memory ECDH state
|
|
471
511
|
ecdhPrivateKey = null;
|
|
@@ -481,12 +521,15 @@ var Clawntenna = class {
|
|
|
481
521
|
const registryAddr = options.registryAddress ?? chain.registry;
|
|
482
522
|
const keyManagerAddr = options.keyManagerAddress ?? chain.keyManager;
|
|
483
523
|
const schemaRegistryAddr = options.schemaRegistryAddress ?? chain.schemaRegistry;
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
this.
|
|
489
|
-
this.
|
|
524
|
+
const escrowAddr = options.escrowAddress ?? chain.escrow;
|
|
525
|
+
const signer = options.privateKey ? new import_ethers.ethers.Wallet(options.privateKey, this.provider) : null;
|
|
526
|
+
const runner = signer ?? this.provider;
|
|
527
|
+
if (signer) {
|
|
528
|
+
this.wallet = signer;
|
|
529
|
+
this.registry = new import_ethers.ethers.Contract(registryAddr, REGISTRY_ABI, signer);
|
|
530
|
+
this.keyManager = new import_ethers.ethers.Contract(keyManagerAddr, KEY_MANAGER_ABI, signer);
|
|
531
|
+
this.schemaRegistry = new import_ethers.ethers.Contract(schemaRegistryAddr, SCHEMA_REGISTRY_ABI, signer);
|
|
532
|
+
this.identityRegistry = chain.identityRegistry ? new import_ethers.ethers.Contract(chain.identityRegistry, IDENTITY_REGISTRY_ABI, signer) : null;
|
|
490
533
|
} else {
|
|
491
534
|
this.wallet = null;
|
|
492
535
|
this.registry = new import_ethers.ethers.Contract(registryAddr, REGISTRY_ABI, this.provider);
|
|
@@ -494,6 +537,7 @@ var Clawntenna = class {
|
|
|
494
537
|
this.schemaRegistry = new import_ethers.ethers.Contract(schemaRegistryAddr, SCHEMA_REGISTRY_ABI, this.provider);
|
|
495
538
|
this.identityRegistry = chain.identityRegistry ? new import_ethers.ethers.Contract(chain.identityRegistry, IDENTITY_REGISTRY_ABI, this.provider) : null;
|
|
496
539
|
}
|
|
540
|
+
this.escrow = escrowAddr ? new import_ethers.ethers.Contract(escrowAddr, ESCROW_ABI, runner) : null;
|
|
497
541
|
}
|
|
498
542
|
get address() {
|
|
499
543
|
return this.wallet?.address ?? null;
|
|
@@ -505,6 +549,12 @@ var Clawntenna = class {
|
|
|
505
549
|
*/
|
|
506
550
|
async sendMessage(topicId, text, options) {
|
|
507
551
|
if (!this.wallet) throw new Error("Wallet required to send messages");
|
|
552
|
+
if (options?.replyTo && this.escrow && !options?.skipRefundCheck) {
|
|
553
|
+
const refunded = await this.isMessageRefunded(options.replyTo);
|
|
554
|
+
if (refunded) {
|
|
555
|
+
throw new Error(`Cannot reply: escrow deposit was refunded (tx: ${options.replyTo})`);
|
|
556
|
+
}
|
|
557
|
+
}
|
|
508
558
|
let replyText = options?.replyText;
|
|
509
559
|
let replyAuthor = options?.replyAuthor;
|
|
510
560
|
if (options?.replyTo && (!replyText || !replyAuthor)) {
|
|
@@ -733,6 +783,132 @@ var Clawntenna = class {
|
|
|
733
783
|
if (!this.wallet) throw new Error("Wallet required");
|
|
734
784
|
return this.registry.setTopicMessageFee(topicId, feeToken, feeAmount);
|
|
735
785
|
}
|
|
786
|
+
// ===== ESCROW =====
|
|
787
|
+
requireEscrow() {
|
|
788
|
+
if (!this.escrow) {
|
|
789
|
+
throw new Error("Escrow not available on this chain. Use baseSepolia or pass escrowAddress.");
|
|
790
|
+
}
|
|
791
|
+
return this.escrow;
|
|
792
|
+
}
|
|
793
|
+
/**
|
|
794
|
+
* Enable escrow for a topic (topic owner only).
|
|
795
|
+
*/
|
|
796
|
+
async enableEscrow(topicId, timeout) {
|
|
797
|
+
if (!this.wallet) throw new Error("Wallet required");
|
|
798
|
+
return this.requireEscrow().enableEscrow(topicId, timeout);
|
|
799
|
+
}
|
|
800
|
+
/**
|
|
801
|
+
* Disable escrow for a topic (topic owner only).
|
|
802
|
+
*/
|
|
803
|
+
async disableEscrow(topicId) {
|
|
804
|
+
if (!this.wallet) throw new Error("Wallet required");
|
|
805
|
+
return this.requireEscrow().disableEscrow(topicId);
|
|
806
|
+
}
|
|
807
|
+
/**
|
|
808
|
+
* Check if escrow is enabled for a topic.
|
|
809
|
+
*/
|
|
810
|
+
async isEscrowEnabled(topicId) {
|
|
811
|
+
return this.requireEscrow().isEscrowEnabled(topicId);
|
|
812
|
+
}
|
|
813
|
+
/**
|
|
814
|
+
* Get escrow config for a topic (enabled + timeout).
|
|
815
|
+
*/
|
|
816
|
+
async getEscrowConfig(topicId) {
|
|
817
|
+
const escrow = this.requireEscrow();
|
|
818
|
+
const [enabled, timeout] = await Promise.all([
|
|
819
|
+
escrow.isEscrowEnabled(topicId),
|
|
820
|
+
escrow.topicEscrowTimeout(topicId)
|
|
821
|
+
]);
|
|
822
|
+
return { enabled, timeout };
|
|
823
|
+
}
|
|
824
|
+
/**
|
|
825
|
+
* Get full deposit details by ID.
|
|
826
|
+
*/
|
|
827
|
+
async getDeposit(depositId) {
|
|
828
|
+
const d = await this.requireEscrow().getDeposit(depositId);
|
|
829
|
+
return {
|
|
830
|
+
id: d.id,
|
|
831
|
+
topicId: d.topicId,
|
|
832
|
+
sender: d.sender,
|
|
833
|
+
recipient: d.recipient,
|
|
834
|
+
token: d.token,
|
|
835
|
+
amount: d.amount,
|
|
836
|
+
appOwner: d.appOwner,
|
|
837
|
+
depositedAt: d.depositedAt,
|
|
838
|
+
timeout: d.timeout,
|
|
839
|
+
status: Number(d.status)
|
|
840
|
+
};
|
|
841
|
+
}
|
|
842
|
+
/**
|
|
843
|
+
* Get deposit status (0=Pending, 1=Released, 2=Refunded).
|
|
844
|
+
*/
|
|
845
|
+
async getDepositStatus(depositId) {
|
|
846
|
+
const status = await this.requireEscrow().getDepositStatus(depositId);
|
|
847
|
+
return Number(status);
|
|
848
|
+
}
|
|
849
|
+
/**
|
|
850
|
+
* Get pending deposit IDs for a topic.
|
|
851
|
+
*/
|
|
852
|
+
async getPendingDeposits(topicId) {
|
|
853
|
+
return this.requireEscrow().getPendingDeposits(topicId);
|
|
854
|
+
}
|
|
855
|
+
/**
|
|
856
|
+
* Check if a deposit can be refunded (timeout expired and still pending).
|
|
857
|
+
*/
|
|
858
|
+
async canClaimRefund(depositId) {
|
|
859
|
+
return this.requireEscrow().canClaimRefund(depositId);
|
|
860
|
+
}
|
|
861
|
+
/**
|
|
862
|
+
* Claim a refund for a single deposit.
|
|
863
|
+
*/
|
|
864
|
+
async claimRefund(depositId) {
|
|
865
|
+
if (!this.wallet) throw new Error("Wallet required");
|
|
866
|
+
return this.requireEscrow().claimRefund(depositId);
|
|
867
|
+
}
|
|
868
|
+
/**
|
|
869
|
+
* Batch claim refunds for multiple deposits.
|
|
870
|
+
*/
|
|
871
|
+
async batchClaimRefunds(depositIds) {
|
|
872
|
+
if (!this.wallet) throw new Error("Wallet required");
|
|
873
|
+
return this.requireEscrow().batchClaimRefunds(depositIds);
|
|
874
|
+
}
|
|
875
|
+
/**
|
|
876
|
+
* Parse a transaction receipt to extract the depositId from a DepositRecorded event.
|
|
877
|
+
* Returns null if no DepositRecorded event is found (e.g. no escrow on this tx).
|
|
878
|
+
*/
|
|
879
|
+
async getMessageDepositId(txHash) {
|
|
880
|
+
if (!this.escrow) return null;
|
|
881
|
+
const receipt = await this.provider.getTransactionReceipt(txHash);
|
|
882
|
+
if (!receipt) return null;
|
|
883
|
+
const iface = this.escrow.interface;
|
|
884
|
+
for (const log of receipt.logs) {
|
|
885
|
+
try {
|
|
886
|
+
const parsed = iface.parseLog(log);
|
|
887
|
+
if (parsed?.name === "DepositRecorded") {
|
|
888
|
+
return parsed.args.depositId;
|
|
889
|
+
}
|
|
890
|
+
} catch {
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
return null;
|
|
894
|
+
}
|
|
895
|
+
/**
|
|
896
|
+
* Get the deposit status for a message by its transaction hash.
|
|
897
|
+
* Returns null if the message has no associated escrow deposit.
|
|
898
|
+
*/
|
|
899
|
+
async getMessageDepositStatus(txHash) {
|
|
900
|
+
const depositId = await this.getMessageDepositId(txHash);
|
|
901
|
+
if (depositId === null) return null;
|
|
902
|
+
return this.getDepositStatus(Number(depositId));
|
|
903
|
+
}
|
|
904
|
+
/**
|
|
905
|
+
* Check if a message's escrow deposit was refunded.
|
|
906
|
+
* Returns false if no escrow deposit exists for the tx.
|
|
907
|
+
*/
|
|
908
|
+
async isMessageRefunded(txHash) {
|
|
909
|
+
const status = await this.getMessageDepositStatus(txHash);
|
|
910
|
+
return status === 2 /* Refunded */;
|
|
911
|
+
}
|
|
736
912
|
// ===== ECDH (Private Topics) =====
|
|
737
913
|
/**
|
|
738
914
|
* Derive ECDH keypair from wallet signature (deterministic).
|
|
@@ -1250,6 +1426,8 @@ var Clawntenna = class {
|
|
|
1250
1426
|
CHAINS,
|
|
1251
1427
|
CHAIN_IDS,
|
|
1252
1428
|
Clawntenna,
|
|
1429
|
+
DepositStatus,
|
|
1430
|
+
ESCROW_ABI,
|
|
1253
1431
|
IDENTITY_REGISTRY_ABI,
|
|
1254
1432
|
KEY_MANAGER_ABI,
|
|
1255
1433
|
PERMISSION_ADMIN,
|