@zubari/sdk 0.1.29 → 0.1.31

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.
@@ -1008,97 +1008,1713 @@ var ZubariMarketProtocol = class {
1008
1008
  }
1009
1009
  };
1010
1010
 
1011
+ // src/abi/ZubariTips.json
1012
+ var ZubariTips_default = [
1013
+ {
1014
+ inputs: [
1015
+ {
1016
+ internalType: "address",
1017
+ name: "_treasury",
1018
+ type: "address"
1019
+ },
1020
+ {
1021
+ internalType: "uint256",
1022
+ name: "_platformFeeBps",
1023
+ type: "uint256"
1024
+ }
1025
+ ],
1026
+ stateMutability: "nonpayable",
1027
+ type: "constructor"
1028
+ },
1029
+ {
1030
+ inputs: [],
1031
+ name: "EnforcedPause",
1032
+ type: "error"
1033
+ },
1034
+ {
1035
+ inputs: [],
1036
+ name: "ExpectedPause",
1037
+ type: "error"
1038
+ },
1039
+ {
1040
+ inputs: [],
1041
+ name: "InvalidAddress",
1042
+ type: "error"
1043
+ },
1044
+ {
1045
+ inputs: [],
1046
+ name: "InvalidAmount",
1047
+ type: "error"
1048
+ },
1049
+ {
1050
+ inputs: [],
1051
+ name: "InvalidFee",
1052
+ type: "error"
1053
+ },
1054
+ {
1055
+ inputs: [],
1056
+ name: "InvalidRecipient",
1057
+ type: "error"
1058
+ },
1059
+ {
1060
+ inputs: [
1061
+ {
1062
+ internalType: "address",
1063
+ name: "owner",
1064
+ type: "address"
1065
+ }
1066
+ ],
1067
+ name: "OwnableInvalidOwner",
1068
+ type: "error"
1069
+ },
1070
+ {
1071
+ inputs: [
1072
+ {
1073
+ internalType: "address",
1074
+ name: "account",
1075
+ type: "address"
1076
+ }
1077
+ ],
1078
+ name: "OwnableUnauthorizedAccount",
1079
+ type: "error"
1080
+ },
1081
+ {
1082
+ inputs: [],
1083
+ name: "ReentrancyGuardReentrantCall",
1084
+ type: "error"
1085
+ },
1086
+ {
1087
+ inputs: [
1088
+ {
1089
+ internalType: "address",
1090
+ name: "token",
1091
+ type: "address"
1092
+ }
1093
+ ],
1094
+ name: "SafeERC20FailedOperation",
1095
+ type: "error"
1096
+ },
1097
+ {
1098
+ inputs: [],
1099
+ name: "TransferFailed",
1100
+ type: "error"
1101
+ },
1102
+ {
1103
+ anonymous: false,
1104
+ inputs: [
1105
+ {
1106
+ indexed: false,
1107
+ internalType: "uint256[]",
1108
+ name: "tipIds",
1109
+ type: "uint256[]"
1110
+ },
1111
+ {
1112
+ indexed: true,
1113
+ internalType: "address",
1114
+ name: "sender",
1115
+ type: "address"
1116
+ }
1117
+ ],
1118
+ name: "BatchTipSent",
1119
+ type: "event"
1120
+ },
1121
+ {
1122
+ anonymous: false,
1123
+ inputs: [
1124
+ {
1125
+ indexed: true,
1126
+ internalType: "address",
1127
+ name: "previousOwner",
1128
+ type: "address"
1129
+ },
1130
+ {
1131
+ indexed: true,
1132
+ internalType: "address",
1133
+ name: "newOwner",
1134
+ type: "address"
1135
+ }
1136
+ ],
1137
+ name: "OwnershipTransferred",
1138
+ type: "event"
1139
+ },
1140
+ {
1141
+ anonymous: false,
1142
+ inputs: [
1143
+ {
1144
+ indexed: false,
1145
+ internalType: "address",
1146
+ name: "account",
1147
+ type: "address"
1148
+ }
1149
+ ],
1150
+ name: "Paused",
1151
+ type: "event"
1152
+ },
1153
+ {
1154
+ anonymous: false,
1155
+ inputs: [
1156
+ {
1157
+ indexed: false,
1158
+ internalType: "uint256",
1159
+ name: "oldFee",
1160
+ type: "uint256"
1161
+ },
1162
+ {
1163
+ indexed: false,
1164
+ internalType: "uint256",
1165
+ name: "newFee",
1166
+ type: "uint256"
1167
+ }
1168
+ ],
1169
+ name: "PlatformFeeUpdated",
1170
+ type: "event"
1171
+ },
1172
+ {
1173
+ anonymous: false,
1174
+ inputs: [
1175
+ {
1176
+ indexed: true,
1177
+ internalType: "uint256",
1178
+ name: "tipId",
1179
+ type: "uint256"
1180
+ },
1181
+ {
1182
+ indexed: true,
1183
+ internalType: "address",
1184
+ name: "sender",
1185
+ type: "address"
1186
+ },
1187
+ {
1188
+ indexed: true,
1189
+ internalType: "address",
1190
+ name: "recipient",
1191
+ type: "address"
1192
+ },
1193
+ {
1194
+ indexed: false,
1195
+ internalType: "address",
1196
+ name: "token",
1197
+ type: "address"
1198
+ },
1199
+ {
1200
+ indexed: false,
1201
+ internalType: "uint256",
1202
+ name: "amount",
1203
+ type: "uint256"
1204
+ },
1205
+ {
1206
+ indexed: false,
1207
+ internalType: "uint256",
1208
+ name: "platformFee",
1209
+ type: "uint256"
1210
+ },
1211
+ {
1212
+ indexed: false,
1213
+ internalType: "string",
1214
+ name: "message",
1215
+ type: "string"
1216
+ }
1217
+ ],
1218
+ name: "TipSent",
1219
+ type: "event"
1220
+ },
1221
+ {
1222
+ anonymous: false,
1223
+ inputs: [
1224
+ {
1225
+ indexed: false,
1226
+ internalType: "address",
1227
+ name: "oldTreasury",
1228
+ type: "address"
1229
+ },
1230
+ {
1231
+ indexed: false,
1232
+ internalType: "address",
1233
+ name: "newTreasury",
1234
+ type: "address"
1235
+ }
1236
+ ],
1237
+ name: "TreasuryUpdated",
1238
+ type: "event"
1239
+ },
1240
+ {
1241
+ anonymous: false,
1242
+ inputs: [
1243
+ {
1244
+ indexed: false,
1245
+ internalType: "address",
1246
+ name: "account",
1247
+ type: "address"
1248
+ }
1249
+ ],
1250
+ name: "Unpaused",
1251
+ type: "event"
1252
+ },
1253
+ {
1254
+ inputs: [
1255
+ {
1256
+ internalType: "uint256",
1257
+ name: "tipId",
1258
+ type: "uint256"
1259
+ }
1260
+ ],
1261
+ name: "getTip",
1262
+ outputs: [
1263
+ {
1264
+ components: [
1265
+ {
1266
+ internalType: "uint256",
1267
+ name: "tipId",
1268
+ type: "uint256"
1269
+ },
1270
+ {
1271
+ internalType: "address",
1272
+ name: "sender",
1273
+ type: "address"
1274
+ },
1275
+ {
1276
+ internalType: "address",
1277
+ name: "recipient",
1278
+ type: "address"
1279
+ },
1280
+ {
1281
+ internalType: "address",
1282
+ name: "token",
1283
+ type: "address"
1284
+ },
1285
+ {
1286
+ internalType: "uint256",
1287
+ name: "amount",
1288
+ type: "uint256"
1289
+ },
1290
+ {
1291
+ internalType: "uint256",
1292
+ name: "platformFee",
1293
+ type: "uint256"
1294
+ },
1295
+ {
1296
+ internalType: "string",
1297
+ name: "message",
1298
+ type: "string"
1299
+ },
1300
+ {
1301
+ internalType: "uint256",
1302
+ name: "timestamp",
1303
+ type: "uint256"
1304
+ }
1305
+ ],
1306
+ internalType: "struct ZubariTips.Tip",
1307
+ name: "",
1308
+ type: "tuple"
1309
+ }
1310
+ ],
1311
+ stateMutability: "view",
1312
+ type: "function"
1313
+ },
1314
+ {
1315
+ inputs: [],
1316
+ name: "owner",
1317
+ outputs: [
1318
+ {
1319
+ internalType: "address",
1320
+ name: "",
1321
+ type: "address"
1322
+ }
1323
+ ],
1324
+ stateMutability: "view",
1325
+ type: "function"
1326
+ },
1327
+ {
1328
+ inputs: [],
1329
+ name: "pause",
1330
+ outputs: [],
1331
+ stateMutability: "nonpayable",
1332
+ type: "function"
1333
+ },
1334
+ {
1335
+ inputs: [],
1336
+ name: "paused",
1337
+ outputs: [
1338
+ {
1339
+ internalType: "bool",
1340
+ name: "",
1341
+ type: "bool"
1342
+ }
1343
+ ],
1344
+ stateMutability: "view",
1345
+ type: "function"
1346
+ },
1347
+ {
1348
+ inputs: [],
1349
+ name: "platformFeeBps",
1350
+ outputs: [
1351
+ {
1352
+ internalType: "uint256",
1353
+ name: "",
1354
+ type: "uint256"
1355
+ }
1356
+ ],
1357
+ stateMutability: "view",
1358
+ type: "function"
1359
+ },
1360
+ {
1361
+ inputs: [],
1362
+ name: "renounceOwnership",
1363
+ outputs: [],
1364
+ stateMutability: "nonpayable",
1365
+ type: "function"
1366
+ },
1367
+ {
1368
+ inputs: [
1369
+ {
1370
+ internalType: "address[]",
1371
+ name: "recipients",
1372
+ type: "address[]"
1373
+ },
1374
+ {
1375
+ internalType: "uint256[]",
1376
+ name: "amounts",
1377
+ type: "uint256[]"
1378
+ },
1379
+ {
1380
+ internalType: "string[]",
1381
+ name: "messages",
1382
+ type: "string[]"
1383
+ }
1384
+ ],
1385
+ name: "sendBatchTips",
1386
+ outputs: [],
1387
+ stateMutability: "payable",
1388
+ type: "function"
1389
+ },
1390
+ {
1391
+ inputs: [
1392
+ {
1393
+ internalType: "uint256",
1394
+ name: "_feeBps",
1395
+ type: "uint256"
1396
+ }
1397
+ ],
1398
+ name: "setPlatformFee",
1399
+ outputs: [],
1400
+ stateMutability: "nonpayable",
1401
+ type: "function"
1402
+ },
1403
+ {
1404
+ inputs: [
1405
+ {
1406
+ internalType: "address",
1407
+ name: "_treasury",
1408
+ type: "address"
1409
+ }
1410
+ ],
1411
+ name: "setTreasury",
1412
+ outputs: [],
1413
+ stateMutability: "nonpayable",
1414
+ type: "function"
1415
+ },
1416
+ {
1417
+ inputs: [],
1418
+ name: "tipCounter",
1419
+ outputs: [
1420
+ {
1421
+ internalType: "uint256",
1422
+ name: "",
1423
+ type: "uint256"
1424
+ }
1425
+ ],
1426
+ stateMutability: "view",
1427
+ type: "function"
1428
+ },
1429
+ {
1430
+ inputs: [
1431
+ {
1432
+ internalType: "address",
1433
+ name: "recipient",
1434
+ type: "address"
1435
+ },
1436
+ {
1437
+ internalType: "string",
1438
+ name: "message",
1439
+ type: "string"
1440
+ }
1441
+ ],
1442
+ name: "tipETH",
1443
+ outputs: [],
1444
+ stateMutability: "payable",
1445
+ type: "function"
1446
+ },
1447
+ {
1448
+ inputs: [
1449
+ {
1450
+ internalType: "address",
1451
+ name: "recipient",
1452
+ type: "address"
1453
+ },
1454
+ {
1455
+ internalType: "address",
1456
+ name: "token",
1457
+ type: "address"
1458
+ },
1459
+ {
1460
+ internalType: "uint256",
1461
+ name: "amount",
1462
+ type: "uint256"
1463
+ },
1464
+ {
1465
+ internalType: "string",
1466
+ name: "message",
1467
+ type: "string"
1468
+ }
1469
+ ],
1470
+ name: "tipToken",
1471
+ outputs: [],
1472
+ stateMutability: "nonpayable",
1473
+ type: "function"
1474
+ },
1475
+ {
1476
+ inputs: [
1477
+ {
1478
+ internalType: "uint256",
1479
+ name: "",
1480
+ type: "uint256"
1481
+ }
1482
+ ],
1483
+ name: "tips",
1484
+ outputs: [
1485
+ {
1486
+ internalType: "uint256",
1487
+ name: "tipId",
1488
+ type: "uint256"
1489
+ },
1490
+ {
1491
+ internalType: "address",
1492
+ name: "sender",
1493
+ type: "address"
1494
+ },
1495
+ {
1496
+ internalType: "address",
1497
+ name: "recipient",
1498
+ type: "address"
1499
+ },
1500
+ {
1501
+ internalType: "address",
1502
+ name: "token",
1503
+ type: "address"
1504
+ },
1505
+ {
1506
+ internalType: "uint256",
1507
+ name: "amount",
1508
+ type: "uint256"
1509
+ },
1510
+ {
1511
+ internalType: "uint256",
1512
+ name: "platformFee",
1513
+ type: "uint256"
1514
+ },
1515
+ {
1516
+ internalType: "string",
1517
+ name: "message",
1518
+ type: "string"
1519
+ },
1520
+ {
1521
+ internalType: "uint256",
1522
+ name: "timestamp",
1523
+ type: "uint256"
1524
+ }
1525
+ ],
1526
+ stateMutability: "view",
1527
+ type: "function"
1528
+ },
1529
+ {
1530
+ inputs: [
1531
+ {
1532
+ internalType: "address",
1533
+ name: "",
1534
+ type: "address"
1535
+ }
1536
+ ],
1537
+ name: "totalTipsReceived",
1538
+ outputs: [
1539
+ {
1540
+ internalType: "uint256",
1541
+ name: "",
1542
+ type: "uint256"
1543
+ }
1544
+ ],
1545
+ stateMutability: "view",
1546
+ type: "function"
1547
+ },
1548
+ {
1549
+ inputs: [
1550
+ {
1551
+ internalType: "address",
1552
+ name: "newOwner",
1553
+ type: "address"
1554
+ }
1555
+ ],
1556
+ name: "transferOwnership",
1557
+ outputs: [],
1558
+ stateMutability: "nonpayable",
1559
+ type: "function"
1560
+ },
1561
+ {
1562
+ inputs: [],
1563
+ name: "treasury",
1564
+ outputs: [
1565
+ {
1566
+ internalType: "address",
1567
+ name: "",
1568
+ type: "address"
1569
+ }
1570
+ ],
1571
+ stateMutability: "view",
1572
+ type: "function"
1573
+ },
1574
+ {
1575
+ inputs: [],
1576
+ name: "unpause",
1577
+ outputs: [],
1578
+ stateMutability: "nonpayable",
1579
+ type: "function"
1580
+ }
1581
+ ];
1582
+
1011
1583
  // src/protocols/TipsProtocol.ts
1012
1584
  var ZubariTipsProtocol = class {
1013
1585
  contractAddress;
1014
1586
  chainId;
1015
- gaslessEnabled;
1016
- constructor(contractAddress, chainId, gaslessEnabled = false) {
1587
+ abi = ZubariTips_default;
1588
+ constructor(contractAddress, chainId) {
1589
+ this.contractAddress = contractAddress;
1590
+ this.chainId = chainId;
1591
+ }
1592
+ /**
1593
+ * Get the contract ABI
1594
+ */
1595
+ getAbi() {
1596
+ return this.abi;
1597
+ }
1598
+ /**
1599
+ * Get the contract address
1600
+ */
1601
+ getAddress() {
1602
+ return this.contractAddress;
1603
+ }
1604
+ /**
1605
+ * Send ETH tip to a creator
1606
+ * @param recipient The recipient address
1607
+ * @param message Optional tip message
1608
+ * @param signer Wallet signer with sendTransaction method
1609
+ * @param value ETH amount to tip (in wei)
1610
+ */
1611
+ async tipETH(recipient, message, signer, value) {
1612
+ if (!recipient || recipient === "0x0000000000000000000000000000000000000000") {
1613
+ throw new Error("Invalid recipient address");
1614
+ }
1615
+ if (value <= 0n) {
1616
+ throw new Error("Tip amount must be greater than 0");
1617
+ }
1618
+ const iface = new (await import('ethers')).Interface(this.abi);
1619
+ const data = iface.encodeFunctionData("tipETH", [recipient, message || ""]);
1620
+ const result = await signer.sendTransaction({
1621
+ to: this.contractAddress,
1622
+ value,
1623
+ data
1624
+ });
1625
+ return {
1626
+ hash: result.hash,
1627
+ network: "ethereum",
1628
+ status: "pending"
1629
+ };
1630
+ }
1631
+ /**
1632
+ * Send ERC-20 token tip to a creator
1633
+ * @param recipient The recipient address
1634
+ * @param token The ERC-20 token address
1635
+ * @param amount The amount of tokens to tip
1636
+ * @param message Optional tip message
1637
+ * @param signer Wallet signer
1638
+ */
1639
+ async tipToken(recipient, token, amount, message, signer) {
1640
+ if (!recipient || recipient === "0x0000000000000000000000000000000000000000") {
1641
+ throw new Error("Invalid recipient address");
1642
+ }
1643
+ if (!token || token === "0x0000000000000000000000000000000000000000") {
1644
+ throw new Error("Use tipETH for native ETH tips");
1645
+ }
1646
+ if (amount <= 0n) {
1647
+ throw new Error("Tip amount must be greater than 0");
1648
+ }
1649
+ const iface = new (await import('ethers')).Interface(this.abi);
1650
+ const data = iface.encodeFunctionData("tipToken", [recipient, token, amount, message || ""]);
1651
+ const result = await signer.sendTransaction({
1652
+ to: this.contractAddress,
1653
+ value: 0n,
1654
+ data
1655
+ });
1656
+ return {
1657
+ hash: result.hash,
1658
+ network: "ethereum",
1659
+ status: "pending"
1660
+ };
1661
+ }
1662
+ /**
1663
+ * Send batch tips to multiple creators in a single transaction
1664
+ * @param recipients Array of recipient addresses
1665
+ * @param amounts Array of tip amounts (in wei)
1666
+ * @param messages Array of tip messages
1667
+ * @param signer Wallet signer
1668
+ * @param value Total ETH to send
1669
+ */
1670
+ async sendBatchTips(recipients, amounts, messages, signer, value) {
1671
+ if (recipients.length === 0) {
1672
+ throw new Error("At least one recipient is required");
1673
+ }
1674
+ if (recipients.length !== amounts.length || recipients.length !== messages.length) {
1675
+ throw new Error("Recipients, amounts, and messages arrays must have the same length");
1676
+ }
1677
+ for (const recipient of recipients) {
1678
+ if (!recipient || recipient === "0x0000000000000000000000000000000000000000") {
1679
+ throw new Error("Invalid recipient address in batch");
1680
+ }
1681
+ }
1682
+ const totalAmount = amounts.reduce((sum, amount) => sum + amount, 0n);
1683
+ if (totalAmount <= 0n) {
1684
+ throw new Error("Total tip amount must be greater than 0");
1685
+ }
1686
+ const iface = new (await import('ethers')).Interface(this.abi);
1687
+ const data = iface.encodeFunctionData("sendBatchTips", [recipients, amounts, messages]);
1688
+ const result = await signer.sendTransaction({
1689
+ to: this.contractAddress,
1690
+ value,
1691
+ data
1692
+ });
1693
+ return {
1694
+ hash: result.hash,
1695
+ network: "ethereum",
1696
+ status: "pending"
1697
+ };
1698
+ }
1699
+ /**
1700
+ * Get tip details by ID
1701
+ * @param tipId The tip ID
1702
+ * @param provider JSON-RPC provider
1703
+ */
1704
+ async getTip(tipId, provider) {
1705
+ const iface = new (await import('ethers')).Interface(this.abi);
1706
+ const data = iface.encodeFunctionData("getTip", [tipId]);
1707
+ try {
1708
+ const result = await provider.call({
1709
+ to: this.contractAddress,
1710
+ data
1711
+ });
1712
+ const decoded = iface.decodeFunctionResult("getTip", result);
1713
+ const tip = decoded[0];
1714
+ if (BigInt(tip.tipId) === 0n) {
1715
+ return null;
1716
+ }
1717
+ return {
1718
+ tipId: tip.tipId.toString(),
1719
+ sender: tip.sender,
1720
+ recipient: tip.recipient,
1721
+ token: tip.token,
1722
+ amount: BigInt(tip.amount),
1723
+ platformFee: BigInt(tip.platformFee),
1724
+ message: tip.message,
1725
+ timestamp: Number(tip.timestamp)
1726
+ };
1727
+ } catch {
1728
+ return null;
1729
+ }
1730
+ }
1731
+ /**
1732
+ * Get total tips received by an address
1733
+ * @param address The address to query
1734
+ * @param provider JSON-RPC provider
1735
+ */
1736
+ async getTotalTipsReceived(address, provider) {
1737
+ const iface = new (await import('ethers')).Interface(this.abi);
1738
+ const data = iface.encodeFunctionData("totalTipsReceived", [address]);
1739
+ try {
1740
+ const result = await provider.call({
1741
+ to: this.contractAddress,
1742
+ data
1743
+ });
1744
+ const decoded = iface.decodeFunctionResult("totalTipsReceived", result);
1745
+ return BigInt(decoded[0]);
1746
+ } catch {
1747
+ return 0n;
1748
+ }
1749
+ }
1750
+ /**
1751
+ * Get platform fee in basis points
1752
+ * @param provider JSON-RPC provider
1753
+ */
1754
+ async getPlatformFeeBps(provider) {
1755
+ const iface = new (await import('ethers')).Interface(this.abi);
1756
+ const data = iface.encodeFunctionData("platformFeeBps", []);
1757
+ try {
1758
+ const result = await provider.call({
1759
+ to: this.contractAddress,
1760
+ data
1761
+ });
1762
+ const decoded = iface.decodeFunctionResult("platformFeeBps", result);
1763
+ return Number(decoded[0]);
1764
+ } catch {
1765
+ return 300;
1766
+ }
1767
+ }
1768
+ /**
1769
+ * Get current tip counter
1770
+ * @param provider JSON-RPC provider
1771
+ */
1772
+ async getTipCounter(provider) {
1773
+ const iface = new (await import('ethers')).Interface(this.abi);
1774
+ const data = iface.encodeFunctionData("tipCounter", []);
1775
+ try {
1776
+ const result = await provider.call({
1777
+ to: this.contractAddress,
1778
+ data
1779
+ });
1780
+ const decoded = iface.decodeFunctionResult("tipCounter", result);
1781
+ return BigInt(decoded[0]);
1782
+ } catch {
1783
+ return 0n;
1784
+ }
1785
+ }
1786
+ /**
1787
+ * Get treasury address
1788
+ * @param provider JSON-RPC provider
1789
+ */
1790
+ async getTreasury(provider) {
1791
+ const iface = new (await import('ethers')).Interface(this.abi);
1792
+ const data = iface.encodeFunctionData("treasury", []);
1793
+ try {
1794
+ const result = await provider.call({
1795
+ to: this.contractAddress,
1796
+ data
1797
+ });
1798
+ const decoded = iface.decodeFunctionResult("treasury", result);
1799
+ return decoded[0];
1800
+ } catch {
1801
+ return "0x0000000000000000000000000000000000000000";
1802
+ }
1803
+ }
1804
+ /**
1805
+ * Calculate platform fee for a given amount
1806
+ * @param amount The tip amount
1807
+ * @param feeBps Fee in basis points (default: 300 = 3%)
1808
+ */
1809
+ calculateFee(amount, feeBps = 300) {
1810
+ const fee = amount * BigInt(feeBps) / 10000n;
1811
+ return {
1812
+ fee,
1813
+ creatorAmount: amount - fee
1814
+ };
1815
+ }
1816
+ };
1817
+
1818
+ // src/abi/ZubariSubscription.json
1819
+ var ZubariSubscription_default = [
1820
+ {
1821
+ inputs: [
1822
+ {
1823
+ internalType: "address",
1824
+ name: "_treasury",
1825
+ type: "address"
1826
+ },
1827
+ {
1828
+ internalType: "uint256",
1829
+ name: "_platformFeeBps",
1830
+ type: "uint256"
1831
+ }
1832
+ ],
1833
+ stateMutability: "nonpayable",
1834
+ type: "constructor"
1835
+ },
1836
+ {
1837
+ inputs: [],
1838
+ name: "AlreadySubscribed",
1839
+ type: "error"
1840
+ },
1841
+ {
1842
+ inputs: [],
1843
+ name: "EnforcedPause",
1844
+ type: "error"
1845
+ },
1846
+ {
1847
+ inputs: [],
1848
+ name: "ExpectedPause",
1849
+ type: "error"
1850
+ },
1851
+ {
1852
+ inputs: [],
1853
+ name: "InvalidAddress",
1854
+ type: "error"
1855
+ },
1856
+ {
1857
+ inputs: [],
1858
+ name: "InvalidAmount",
1859
+ type: "error"
1860
+ },
1861
+ {
1862
+ inputs: [],
1863
+ name: "InvalidDuration",
1864
+ type: "error"
1865
+ },
1866
+ {
1867
+ inputs: [],
1868
+ name: "InvalidFee",
1869
+ type: "error"
1870
+ },
1871
+ {
1872
+ inputs: [],
1873
+ name: "NotSubscriber",
1874
+ type: "error"
1875
+ },
1876
+ {
1877
+ inputs: [
1878
+ {
1879
+ internalType: "address",
1880
+ name: "owner",
1881
+ type: "address"
1882
+ }
1883
+ ],
1884
+ name: "OwnableInvalidOwner",
1885
+ type: "error"
1886
+ },
1887
+ {
1888
+ inputs: [
1889
+ {
1890
+ internalType: "address",
1891
+ name: "account",
1892
+ type: "address"
1893
+ }
1894
+ ],
1895
+ name: "OwnableUnauthorizedAccount",
1896
+ type: "error"
1897
+ },
1898
+ {
1899
+ inputs: [],
1900
+ name: "PlanFull",
1901
+ type: "error"
1902
+ },
1903
+ {
1904
+ inputs: [],
1905
+ name: "PlanNotActive",
1906
+ type: "error"
1907
+ },
1908
+ {
1909
+ inputs: [],
1910
+ name: "PlanNotFound",
1911
+ type: "error"
1912
+ },
1913
+ {
1914
+ inputs: [],
1915
+ name: "ReentrancyGuardReentrantCall",
1916
+ type: "error"
1917
+ },
1918
+ {
1919
+ inputs: [
1920
+ {
1921
+ internalType: "address",
1922
+ name: "token",
1923
+ type: "address"
1924
+ }
1925
+ ],
1926
+ name: "SafeERC20FailedOperation",
1927
+ type: "error"
1928
+ },
1929
+ {
1930
+ anonymous: false,
1931
+ inputs: [
1932
+ {
1933
+ indexed: true,
1934
+ internalType: "address",
1935
+ name: "previousOwner",
1936
+ type: "address"
1937
+ },
1938
+ {
1939
+ indexed: true,
1940
+ internalType: "address",
1941
+ name: "newOwner",
1942
+ type: "address"
1943
+ }
1944
+ ],
1945
+ name: "OwnershipTransferred",
1946
+ type: "event"
1947
+ },
1948
+ {
1949
+ anonymous: false,
1950
+ inputs: [
1951
+ {
1952
+ indexed: false,
1953
+ internalType: "address",
1954
+ name: "account",
1955
+ type: "address"
1956
+ }
1957
+ ],
1958
+ name: "Paused",
1959
+ type: "event"
1960
+ },
1961
+ {
1962
+ anonymous: false,
1963
+ inputs: [
1964
+ {
1965
+ indexed: true,
1966
+ internalType: "bytes32",
1967
+ name: "planId",
1968
+ type: "bytes32"
1969
+ },
1970
+ {
1971
+ indexed: true,
1972
+ internalType: "address",
1973
+ name: "creator",
1974
+ type: "address"
1975
+ },
1976
+ {
1977
+ indexed: false,
1978
+ internalType: "string",
1979
+ name: "name",
1980
+ type: "string"
1981
+ },
1982
+ {
1983
+ indexed: false,
1984
+ internalType: "uint256",
1985
+ name: "price",
1986
+ type: "uint256"
1987
+ }
1988
+ ],
1989
+ name: "PlanCreated",
1990
+ type: "event"
1991
+ },
1992
+ {
1993
+ anonymous: false,
1994
+ inputs: [
1995
+ {
1996
+ indexed: true,
1997
+ internalType: "bytes32",
1998
+ name: "planId",
1999
+ type: "bytes32"
2000
+ }
2001
+ ],
2002
+ name: "PlanDeactivated",
2003
+ type: "event"
2004
+ },
2005
+ {
2006
+ anonymous: false,
2007
+ inputs: [
2008
+ {
2009
+ indexed: true,
2010
+ internalType: "bytes32",
2011
+ name: "planId",
2012
+ type: "bytes32"
2013
+ }
2014
+ ],
2015
+ name: "PlanUpdated",
2016
+ type: "event"
2017
+ },
2018
+ {
2019
+ anonymous: false,
2020
+ inputs: [
2021
+ {
2022
+ indexed: true,
2023
+ internalType: "bytes32",
2024
+ name: "subscriptionId",
2025
+ type: "bytes32"
2026
+ },
2027
+ {
2028
+ indexed: true,
2029
+ internalType: "bytes32",
2030
+ name: "planId",
2031
+ type: "bytes32"
2032
+ },
2033
+ {
2034
+ indexed: true,
2035
+ internalType: "address",
2036
+ name: "subscriber",
2037
+ type: "address"
2038
+ },
2039
+ {
2040
+ indexed: false,
2041
+ internalType: "address",
2042
+ name: "creator",
2043
+ type: "address"
2044
+ },
2045
+ {
2046
+ indexed: false,
2047
+ internalType: "uint256",
2048
+ name: "endTime",
2049
+ type: "uint256"
2050
+ }
2051
+ ],
2052
+ name: "Subscribed",
2053
+ type: "event"
2054
+ },
2055
+ {
2056
+ anonymous: false,
2057
+ inputs: [
2058
+ {
2059
+ indexed: true,
2060
+ internalType: "bytes32",
2061
+ name: "subscriptionId",
2062
+ type: "bytes32"
2063
+ }
2064
+ ],
2065
+ name: "SubscriptionCancelled",
2066
+ type: "event"
2067
+ },
2068
+ {
2069
+ anonymous: false,
2070
+ inputs: [
2071
+ {
2072
+ indexed: true,
2073
+ internalType: "bytes32",
2074
+ name: "subscriptionId",
2075
+ type: "bytes32"
2076
+ },
2077
+ {
2078
+ indexed: false,
2079
+ internalType: "uint256",
2080
+ name: "newEndTime",
2081
+ type: "uint256"
2082
+ }
2083
+ ],
2084
+ name: "SubscriptionRenewed",
2085
+ type: "event"
2086
+ },
2087
+ {
2088
+ anonymous: false,
2089
+ inputs: [
2090
+ {
2091
+ indexed: false,
2092
+ internalType: "address",
2093
+ name: "account",
2094
+ type: "address"
2095
+ }
2096
+ ],
2097
+ name: "Unpaused",
2098
+ type: "event"
2099
+ },
2100
+ {
2101
+ inputs: [
2102
+ {
2103
+ internalType: "address",
2104
+ name: "",
2105
+ type: "address"
2106
+ },
2107
+ {
2108
+ internalType: "address",
2109
+ name: "",
2110
+ type: "address"
2111
+ }
2112
+ ],
2113
+ name: "activeSubscription",
2114
+ outputs: [
2115
+ {
2116
+ internalType: "bytes32",
2117
+ name: "",
2118
+ type: "bytes32"
2119
+ }
2120
+ ],
2121
+ stateMutability: "view",
2122
+ type: "function"
2123
+ },
2124
+ {
2125
+ inputs: [
2126
+ {
2127
+ internalType: "bytes32",
2128
+ name: "subscriptionId",
2129
+ type: "bytes32"
2130
+ }
2131
+ ],
2132
+ name: "cancel",
2133
+ outputs: [],
2134
+ stateMutability: "nonpayable",
2135
+ type: "function"
2136
+ },
2137
+ {
2138
+ inputs: [
2139
+ {
2140
+ internalType: "string",
2141
+ name: "name",
2142
+ type: "string"
2143
+ },
2144
+ {
2145
+ internalType: "string",
2146
+ name: "description",
2147
+ type: "string"
2148
+ },
2149
+ {
2150
+ internalType: "uint256",
2151
+ name: "price",
2152
+ type: "uint256"
2153
+ },
2154
+ {
2155
+ internalType: "address",
2156
+ name: "paymentToken",
2157
+ type: "address"
2158
+ },
2159
+ {
2160
+ internalType: "uint256",
2161
+ name: "durationDays",
2162
+ type: "uint256"
2163
+ },
2164
+ {
2165
+ internalType: "uint256",
2166
+ name: "maxSubscribers",
2167
+ type: "uint256"
2168
+ }
2169
+ ],
2170
+ name: "createPlan",
2171
+ outputs: [
2172
+ {
2173
+ internalType: "bytes32",
2174
+ name: "",
2175
+ type: "bytes32"
2176
+ }
2177
+ ],
2178
+ stateMutability: "nonpayable",
2179
+ type: "function"
2180
+ },
2181
+ {
2182
+ inputs: [
2183
+ {
2184
+ internalType: "address",
2185
+ name: "",
2186
+ type: "address"
2187
+ },
2188
+ {
2189
+ internalType: "uint256",
2190
+ name: "",
2191
+ type: "uint256"
2192
+ }
2193
+ ],
2194
+ name: "creatorPlans",
2195
+ outputs: [
2196
+ {
2197
+ internalType: "bytes32",
2198
+ name: "",
2199
+ type: "bytes32"
2200
+ }
2201
+ ],
2202
+ stateMutability: "view",
2203
+ type: "function"
2204
+ },
2205
+ {
2206
+ inputs: [
2207
+ {
2208
+ internalType: "bytes32",
2209
+ name: "planId",
2210
+ type: "bytes32"
2211
+ }
2212
+ ],
2213
+ name: "deactivatePlan",
2214
+ outputs: [],
2215
+ stateMutability: "nonpayable",
2216
+ type: "function"
2217
+ },
2218
+ {
2219
+ inputs: [
2220
+ {
2221
+ internalType: "address",
2222
+ name: "creator",
2223
+ type: "address"
2224
+ }
2225
+ ],
2226
+ name: "getCreatorPlans",
2227
+ outputs: [
2228
+ {
2229
+ internalType: "bytes32[]",
2230
+ name: "",
2231
+ type: "bytes32[]"
2232
+ }
2233
+ ],
2234
+ stateMutability: "view",
2235
+ type: "function"
2236
+ },
2237
+ {
2238
+ inputs: [
2239
+ {
2240
+ internalType: "bytes32",
2241
+ name: "planId",
2242
+ type: "bytes32"
2243
+ }
2244
+ ],
2245
+ name: "getPlan",
2246
+ outputs: [
2247
+ {
2248
+ components: [
2249
+ {
2250
+ internalType: "bytes32",
2251
+ name: "planId",
2252
+ type: "bytes32"
2253
+ },
2254
+ {
2255
+ internalType: "address",
2256
+ name: "creator",
2257
+ type: "address"
2258
+ },
2259
+ {
2260
+ internalType: "string",
2261
+ name: "name",
2262
+ type: "string"
2263
+ },
2264
+ {
2265
+ internalType: "string",
2266
+ name: "description",
2267
+ type: "string"
2268
+ },
2269
+ {
2270
+ internalType: "uint256",
2271
+ name: "price",
2272
+ type: "uint256"
2273
+ },
2274
+ {
2275
+ internalType: "address",
2276
+ name: "paymentToken",
2277
+ type: "address"
2278
+ },
2279
+ {
2280
+ internalType: "uint256",
2281
+ name: "durationDays",
2282
+ type: "uint256"
2283
+ },
2284
+ {
2285
+ internalType: "uint256",
2286
+ name: "maxSubscribers",
2287
+ type: "uint256"
2288
+ },
2289
+ {
2290
+ internalType: "uint256",
2291
+ name: "subscriberCount",
2292
+ type: "uint256"
2293
+ },
2294
+ {
2295
+ internalType: "bool",
2296
+ name: "isActive",
2297
+ type: "bool"
2298
+ }
2299
+ ],
2300
+ internalType: "struct ZubariSubscription.SubscriptionPlan",
2301
+ name: "",
2302
+ type: "tuple"
2303
+ }
2304
+ ],
2305
+ stateMutability: "view",
2306
+ type: "function"
2307
+ },
2308
+ {
2309
+ inputs: [
2310
+ {
2311
+ internalType: "bytes32",
2312
+ name: "subscriptionId",
2313
+ type: "bytes32"
2314
+ }
2315
+ ],
2316
+ name: "getSubscription",
2317
+ outputs: [
2318
+ {
2319
+ components: [
2320
+ {
2321
+ internalType: "bytes32",
2322
+ name: "subscriptionId",
2323
+ type: "bytes32"
2324
+ },
2325
+ {
2326
+ internalType: "bytes32",
2327
+ name: "planId",
2328
+ type: "bytes32"
2329
+ },
2330
+ {
2331
+ internalType: "address",
2332
+ name: "creator",
2333
+ type: "address"
2334
+ },
2335
+ {
2336
+ internalType: "address",
2337
+ name: "subscriber",
2338
+ type: "address"
2339
+ },
2340
+ {
2341
+ internalType: "uint256",
2342
+ name: "startTime",
2343
+ type: "uint256"
2344
+ },
2345
+ {
2346
+ internalType: "uint256",
2347
+ name: "endTime",
2348
+ type: "uint256"
2349
+ },
2350
+ {
2351
+ internalType: "bool",
2352
+ name: "autoRenew",
2353
+ type: "bool"
2354
+ },
2355
+ {
2356
+ internalType: "enum ZubariSubscription.SubscriptionStatus",
2357
+ name: "status",
2358
+ type: "uint8"
2359
+ }
2360
+ ],
2361
+ internalType: "struct ZubariSubscription.Subscription",
2362
+ name: "",
2363
+ type: "tuple"
2364
+ }
2365
+ ],
2366
+ stateMutability: "view",
2367
+ type: "function"
2368
+ },
2369
+ {
2370
+ inputs: [
2371
+ {
2372
+ internalType: "address",
2373
+ name: "subscriber",
2374
+ type: "address"
2375
+ },
2376
+ {
2377
+ internalType: "address",
2378
+ name: "creator",
2379
+ type: "address"
2380
+ }
2381
+ ],
2382
+ name: "isSubscribed",
2383
+ outputs: [
2384
+ {
2385
+ internalType: "bool",
2386
+ name: "",
2387
+ type: "bool"
2388
+ }
2389
+ ],
2390
+ stateMutability: "view",
2391
+ type: "function"
2392
+ },
2393
+ {
2394
+ inputs: [],
2395
+ name: "owner",
2396
+ outputs: [
2397
+ {
2398
+ internalType: "address",
2399
+ name: "",
2400
+ type: "address"
2401
+ }
2402
+ ],
2403
+ stateMutability: "view",
2404
+ type: "function"
2405
+ },
2406
+ {
2407
+ inputs: [],
2408
+ name: "pause",
2409
+ outputs: [],
2410
+ stateMutability: "nonpayable",
2411
+ type: "function"
2412
+ },
2413
+ {
2414
+ inputs: [],
2415
+ name: "paused",
2416
+ outputs: [
2417
+ {
2418
+ internalType: "bool",
2419
+ name: "",
2420
+ type: "bool"
2421
+ }
2422
+ ],
2423
+ stateMutability: "view",
2424
+ type: "function"
2425
+ },
2426
+ {
2427
+ inputs: [
2428
+ {
2429
+ internalType: "bytes32",
2430
+ name: "",
2431
+ type: "bytes32"
2432
+ }
2433
+ ],
2434
+ name: "plans",
2435
+ outputs: [
2436
+ {
2437
+ internalType: "bytes32",
2438
+ name: "planId",
2439
+ type: "bytes32"
2440
+ },
2441
+ {
2442
+ internalType: "address",
2443
+ name: "creator",
2444
+ type: "address"
2445
+ },
2446
+ {
2447
+ internalType: "string",
2448
+ name: "name",
2449
+ type: "string"
2450
+ },
2451
+ {
2452
+ internalType: "string",
2453
+ name: "description",
2454
+ type: "string"
2455
+ },
2456
+ {
2457
+ internalType: "uint256",
2458
+ name: "price",
2459
+ type: "uint256"
2460
+ },
2461
+ {
2462
+ internalType: "address",
2463
+ name: "paymentToken",
2464
+ type: "address"
2465
+ },
2466
+ {
2467
+ internalType: "uint256",
2468
+ name: "durationDays",
2469
+ type: "uint256"
2470
+ },
2471
+ {
2472
+ internalType: "uint256",
2473
+ name: "maxSubscribers",
2474
+ type: "uint256"
2475
+ },
2476
+ {
2477
+ internalType: "uint256",
2478
+ name: "subscriberCount",
2479
+ type: "uint256"
2480
+ },
2481
+ {
2482
+ internalType: "bool",
2483
+ name: "isActive",
2484
+ type: "bool"
2485
+ }
2486
+ ],
2487
+ stateMutability: "view",
2488
+ type: "function"
2489
+ },
2490
+ {
2491
+ inputs: [],
2492
+ name: "platformFeeBps",
2493
+ outputs: [
2494
+ {
2495
+ internalType: "uint256",
2496
+ name: "",
2497
+ type: "uint256"
2498
+ }
2499
+ ],
2500
+ stateMutability: "view",
2501
+ type: "function"
2502
+ },
2503
+ {
2504
+ inputs: [],
2505
+ name: "renounceOwnership",
2506
+ outputs: [],
2507
+ stateMutability: "nonpayable",
2508
+ type: "function"
2509
+ },
2510
+ {
2511
+ inputs: [
2512
+ {
2513
+ internalType: "bytes32",
2514
+ name: "subscriptionId",
2515
+ type: "bytes32"
2516
+ },
2517
+ {
2518
+ internalType: "bool",
2519
+ name: "autoRenew",
2520
+ type: "bool"
2521
+ }
2522
+ ],
2523
+ name: "setAutoRenew",
2524
+ outputs: [],
2525
+ stateMutability: "nonpayable",
2526
+ type: "function"
2527
+ },
2528
+ {
2529
+ inputs: [
2530
+ {
2531
+ internalType: "uint256",
2532
+ name: "_feeBps",
2533
+ type: "uint256"
2534
+ }
2535
+ ],
2536
+ name: "setPlatformFee",
2537
+ outputs: [],
2538
+ stateMutability: "nonpayable",
2539
+ type: "function"
2540
+ },
2541
+ {
2542
+ inputs: [
2543
+ {
2544
+ internalType: "address",
2545
+ name: "_treasury",
2546
+ type: "address"
2547
+ }
2548
+ ],
2549
+ name: "setTreasury",
2550
+ outputs: [],
2551
+ stateMutability: "nonpayable",
2552
+ type: "function"
2553
+ },
2554
+ {
2555
+ inputs: [
2556
+ {
2557
+ internalType: "bytes32",
2558
+ name: "planId",
2559
+ type: "bytes32"
2560
+ },
2561
+ {
2562
+ internalType: "uint256",
2563
+ name: "months",
2564
+ type: "uint256"
2565
+ }
2566
+ ],
2567
+ name: "subscribe",
2568
+ outputs: [
2569
+ {
2570
+ internalType: "bytes32",
2571
+ name: "",
2572
+ type: "bytes32"
2573
+ }
2574
+ ],
2575
+ stateMutability: "payable",
2576
+ type: "function"
2577
+ },
2578
+ {
2579
+ inputs: [
2580
+ {
2581
+ internalType: "address",
2582
+ name: "",
2583
+ type: "address"
2584
+ },
2585
+ {
2586
+ internalType: "uint256",
2587
+ name: "",
2588
+ type: "uint256"
2589
+ }
2590
+ ],
2591
+ name: "subscriberSubscriptions",
2592
+ outputs: [
2593
+ {
2594
+ internalType: "bytes32",
2595
+ name: "",
2596
+ type: "bytes32"
2597
+ }
2598
+ ],
2599
+ stateMutability: "view",
2600
+ type: "function"
2601
+ },
2602
+ {
2603
+ inputs: [
2604
+ {
2605
+ internalType: "bytes32",
2606
+ name: "",
2607
+ type: "bytes32"
2608
+ }
2609
+ ],
2610
+ name: "subscriptions",
2611
+ outputs: [
2612
+ {
2613
+ internalType: "bytes32",
2614
+ name: "subscriptionId",
2615
+ type: "bytes32"
2616
+ },
2617
+ {
2618
+ internalType: "bytes32",
2619
+ name: "planId",
2620
+ type: "bytes32"
2621
+ },
2622
+ {
2623
+ internalType: "address",
2624
+ name: "creator",
2625
+ type: "address"
2626
+ },
2627
+ {
2628
+ internalType: "address",
2629
+ name: "subscriber",
2630
+ type: "address"
2631
+ },
2632
+ {
2633
+ internalType: "uint256",
2634
+ name: "startTime",
2635
+ type: "uint256"
2636
+ },
2637
+ {
2638
+ internalType: "uint256",
2639
+ name: "endTime",
2640
+ type: "uint256"
2641
+ },
2642
+ {
2643
+ internalType: "bool",
2644
+ name: "autoRenew",
2645
+ type: "bool"
2646
+ },
2647
+ {
2648
+ internalType: "enum ZubariSubscription.SubscriptionStatus",
2649
+ name: "status",
2650
+ type: "uint8"
2651
+ }
2652
+ ],
2653
+ stateMutability: "view",
2654
+ type: "function"
2655
+ },
2656
+ {
2657
+ inputs: [
2658
+ {
2659
+ internalType: "address",
2660
+ name: "newOwner",
2661
+ type: "address"
2662
+ }
2663
+ ],
2664
+ name: "transferOwnership",
2665
+ outputs: [],
2666
+ stateMutability: "nonpayable",
2667
+ type: "function"
2668
+ },
2669
+ {
2670
+ inputs: [],
2671
+ name: "treasury",
2672
+ outputs: [
2673
+ {
2674
+ internalType: "address",
2675
+ name: "",
2676
+ type: "address"
2677
+ }
2678
+ ],
2679
+ stateMutability: "view",
2680
+ type: "function"
2681
+ },
2682
+ {
2683
+ inputs: [],
2684
+ name: "unpause",
2685
+ outputs: [],
2686
+ stateMutability: "nonpayable",
2687
+ type: "function"
2688
+ }
2689
+ ];
2690
+
2691
+ // src/protocols/SubscriptionProtocol.ts
2692
+ var ZubariSubscriptionProtocol = class {
2693
+ contractAddress;
2694
+ chainId;
2695
+ abi = ZubariSubscription_default;
2696
+ constructor(contractAddress, chainId) {
1017
2697
  this.contractAddress = contractAddress;
1018
2698
  this.chainId = chainId;
1019
- this.gaslessEnabled = gaslessEnabled;
1020
- }
1021
- /**
1022
- * Send a tip to a creator
1023
- */
1024
- async sendTip(tip) {
1025
- const { recipient, amount, token, message } = tip;
1026
- const platformFee = amount * BigInt(PLATFORM_CONFIG.tipFeeBps) / BigInt(1e4);
1027
- const creatorAmount = amount - platformFee;
1028
- if (amount <= 0n) {
1029
- throw new Error("Tip amount must be greater than 0");
1030
- }
1031
- const txResult = {
1032
- hash: ""};
1033
- return {
1034
- txHash: txResult.hash,
1035
- tipId: "",
1036
- // Will be returned from contract event
1037
- recipient,
1038
- amount: creatorAmount,
1039
- platformFee,
1040
- timestamp: Math.floor(Date.now() / 1e3)
1041
- };
1042
- }
1043
- /**
1044
- * Send tips to multiple creators in a single transaction
1045
- */
1046
- async sendBatchTips(tips) {
1047
- if (tips.length === 0) {
1048
- throw new Error("At least one tip is required");
1049
- }
1050
- tips.reduce((sum, tip) => sum + tip.amount, BigInt(0));
1051
- return tips.map((tip) => ({
1052
- txHash: "",
1053
- tipId: "",
1054
- recipient: tip.recipient,
1055
- amount: tip.amount - tip.amount * BigInt(PLATFORM_CONFIG.tipFeeBps) / BigInt(1e4),
1056
- platformFee: tip.amount * BigInt(PLATFORM_CONFIG.tipFeeBps) / BigInt(1e4),
1057
- timestamp: Math.floor(Date.now() / 1e3)
1058
- }));
1059
- }
1060
- /**
1061
- * Get tips received by an address
1062
- */
1063
- async getTipsReceived(address) {
1064
- return [];
1065
- }
1066
- /**
1067
- * Get tips sent by an address
1068
- */
1069
- async getTipsSent(address) {
1070
- return [];
1071
2699
  }
1072
2700
  /**
1073
- * Get tip statistics for a creator
2701
+ * Get the contract ABI
1074
2702
  */
1075
- async getCreatorTipStats(creator) {
1076
- return {
1077
- totalReceived: BigInt(0),
1078
- tipCount: 0,
1079
- uniqueTippers: 0
1080
- };
2703
+ getAbi() {
2704
+ return this.abi;
1081
2705
  }
1082
2706
  /**
1083
- * Get platform fee in basis points
2707
+ * Get the contract address
1084
2708
  */
1085
- getPlatformFeeBps() {
1086
- return PLATFORM_CONFIG.tipFeeBps;
1087
- }
1088
- };
1089
-
1090
- // src/protocols/SubscriptionProtocol.ts
1091
- var ZubariSubscriptionProtocol = class {
1092
- contractAddress;
1093
- chainId;
1094
- constructor(contractAddress, chainId) {
1095
- this.contractAddress = contractAddress;
1096
- this.chainId = chainId;
2709
+ getAddress() {
2710
+ return this.contractAddress;
1097
2711
  }
1098
2712
  /**
1099
2713
  * Create a new subscription plan
2714
+ * @param plan The plan details
2715
+ * @param signer Wallet signer with sendTransaction method
1100
2716
  */
1101
- async createPlan(plan) {
2717
+ async createPlan(plan, signer) {
1102
2718
  if (!plan.name || plan.name.length === 0) {
1103
2719
  throw new Error("Plan name is required");
1104
2720
  }
@@ -1108,87 +2724,305 @@ var ZubariSubscriptionProtocol = class {
1108
2724
  if (plan.duration <= 0) {
1109
2725
  throw new Error("Plan duration must be greater than 0");
1110
2726
  }
1111
- const planId = this.generatePlanId(plan.name);
1112
- return planId;
2727
+ const iface = new (await import('ethers')).Interface(this.abi);
2728
+ const durationDays = Math.ceil(plan.duration / (24 * 60 * 60));
2729
+ const data = iface.encodeFunctionData("createPlan", [
2730
+ plan.name,
2731
+ plan.description || "",
2732
+ plan.price,
2733
+ plan.paymentToken || "0x0000000000000000000000000000000000000000",
2734
+ // ETH by default
2735
+ durationDays,
2736
+ plan.maxSubscribers || 0
2737
+ // 0 = unlimited
2738
+ ]);
2739
+ const result = await signer.sendTransaction({
2740
+ to: this.contractAddress,
2741
+ value: 0n,
2742
+ data
2743
+ });
2744
+ return result.hash;
1113
2745
  }
1114
2746
  /**
1115
- * Update an existing subscription plan
2747
+ * Deactivate a subscription plan (only creator can do this)
2748
+ * @param planId The plan ID to deactivate
2749
+ * @param signer Wallet signer
1116
2750
  */
1117
- async updatePlan(planId, updates) {
2751
+ async deactivatePlan(planId, signer) {
2752
+ const iface = new (await import('ethers')).Interface(this.abi);
2753
+ const data = iface.encodeFunctionData("deactivatePlan", [planId]);
2754
+ const result = await signer.sendTransaction({
2755
+ to: this.contractAddress,
2756
+ value: 0n,
2757
+ data
2758
+ });
1118
2759
  return {
1119
- hash: "",
2760
+ hash: result.hash,
1120
2761
  network: "ethereum",
1121
2762
  status: "pending"
1122
2763
  };
1123
2764
  }
1124
2765
  /**
1125
2766
  * Subscribe to a creator's plan
2767
+ * @param planId The plan ID to subscribe to
2768
+ * @param months Number of months to subscribe
2769
+ * @param signer Wallet signer
2770
+ * @param value ETH value to send (if paying with ETH)
1126
2771
  */
1127
- async subscribe(creator, planId, months = 1) {
2772
+ async subscribe(planId, months, signer, value) {
1128
2773
  if (months <= 0) {
1129
2774
  throw new Error("Subscription duration must be at least 1 month");
1130
2775
  }
1131
- const now = Math.floor(Date.now() / 1e3);
1132
- const durationSeconds = months * 30 * 24 * 60 * 60;
2776
+ const iface = new (await import('ethers')).Interface(this.abi);
2777
+ const data = iface.encodeFunctionData("subscribe", [planId, months]);
2778
+ const result = await signer.sendTransaction({
2779
+ to: this.contractAddress,
2780
+ value: value || 0n,
2781
+ data
2782
+ });
1133
2783
  return {
1134
- subscriptionId: "",
1135
- planId,
1136
- creator,
1137
- subscriber: "",
1138
- // Current user address
1139
- startTime: now,
1140
- endTime: now + durationSeconds,
1141
- autoRenew: false,
1142
- status: "active"
2784
+ hash: result.hash,
2785
+ network: "ethereum",
2786
+ status: "pending"
1143
2787
  };
1144
2788
  }
1145
2789
  /**
1146
2790
  * Cancel an active subscription
2791
+ * @param subscriptionId The subscription ID to cancel
2792
+ * @param signer Wallet signer
1147
2793
  */
1148
- async cancel(subscriptionId) {
2794
+ async cancel(subscriptionId, signer) {
2795
+ const iface = new (await import('ethers')).Interface(this.abi);
2796
+ const data = iface.encodeFunctionData("cancel", [subscriptionId]);
2797
+ const result = await signer.sendTransaction({
2798
+ to: this.contractAddress,
2799
+ value: 0n,
2800
+ data
2801
+ });
1149
2802
  return {
1150
- hash: "",
2803
+ hash: result.hash,
2804
+ network: "ethereum",
2805
+ status: "pending"
2806
+ };
2807
+ }
2808
+ /**
2809
+ * Set auto-renew for a subscription
2810
+ * @param subscriptionId The subscription ID
2811
+ * @param autoRenew Whether to enable auto-renew
2812
+ * @param signer Wallet signer
2813
+ */
2814
+ async setAutoRenew(subscriptionId, autoRenew, signer) {
2815
+ const iface = new (await import('ethers')).Interface(this.abi);
2816
+ const data = iface.encodeFunctionData("setAutoRenew", [subscriptionId, autoRenew]);
2817
+ const result = await signer.sendTransaction({
2818
+ to: this.contractAddress,
2819
+ value: 0n,
2820
+ data
2821
+ });
2822
+ return {
2823
+ hash: result.hash,
1151
2824
  network: "ethereum",
1152
2825
  status: "pending"
1153
2826
  };
1154
2827
  }
1155
2828
  /**
1156
2829
  * Check if an address is subscribed to a creator
2830
+ * @param subscriber The subscriber address
2831
+ * @param creator The creator address
2832
+ * @param provider JSON-RPC provider
1157
2833
  */
1158
- async isSubscribed(creator, subscriber) {
1159
- return false;
2834
+ async isSubscribed(subscriber, creator, provider) {
2835
+ const iface = new (await import('ethers')).Interface(this.abi);
2836
+ const data = iface.encodeFunctionData("isSubscribed", [subscriber, creator]);
2837
+ try {
2838
+ const result = await provider.call({
2839
+ to: this.contractAddress,
2840
+ data
2841
+ });
2842
+ const decoded = iface.decodeFunctionResult("isSubscribed", result);
2843
+ return decoded[0];
2844
+ } catch {
2845
+ return false;
2846
+ }
1160
2847
  }
1161
2848
  /**
1162
- * Get active subscriptions for a subscriber
2849
+ * Get the active subscription ID between subscriber and creator
2850
+ * @param subscriber The subscriber address
2851
+ * @param creator The creator address
2852
+ * @param provider JSON-RPC provider
1163
2853
  */
1164
- async getActiveSubscriptions(subscriber) {
1165
- return [];
2854
+ async getActiveSubscriptionId(subscriber, creator, provider) {
2855
+ const iface = new (await import('ethers')).Interface(this.abi);
2856
+ const data = iface.encodeFunctionData("activeSubscription", [subscriber, creator]);
2857
+ try {
2858
+ const result = await provider.call({
2859
+ to: this.contractAddress,
2860
+ data
2861
+ });
2862
+ const decoded = iface.decodeFunctionResult("activeSubscription", result);
2863
+ const subscriptionId = decoded[0];
2864
+ if (subscriptionId === "0x0000000000000000000000000000000000000000000000000000000000000000") {
2865
+ return null;
2866
+ }
2867
+ return subscriptionId;
2868
+ } catch {
2869
+ return null;
2870
+ }
1166
2871
  }
1167
2872
  /**
1168
- * Get all subscribers for a creator
2873
+ * Get subscription details by ID
2874
+ * @param subscriptionId The subscription ID
2875
+ * @param provider JSON-RPC provider
1169
2876
  */
1170
- async getSubscribers(creator) {
1171
- return [];
2877
+ async getSubscription(subscriptionId, provider) {
2878
+ const iface = new (await import('ethers')).Interface(this.abi);
2879
+ const data = iface.encodeFunctionData("getSubscription", [subscriptionId]);
2880
+ try {
2881
+ const result = await provider.call({
2882
+ to: this.contractAddress,
2883
+ data
2884
+ });
2885
+ const decoded = iface.decodeFunctionResult("getSubscription", result);
2886
+ const sub = decoded[0];
2887
+ if (sub.subscriptionId === "0x0000000000000000000000000000000000000000000000000000000000000000") {
2888
+ return null;
2889
+ }
2890
+ let status;
2891
+ switch (Number(sub.status)) {
2892
+ case 0 /* Active */:
2893
+ status = "active";
2894
+ break;
2895
+ case 1 /* Cancelled */:
2896
+ status = "cancelled";
2897
+ break;
2898
+ case 2 /* Expired */:
2899
+ status = "expired";
2900
+ break;
2901
+ default:
2902
+ status = "active";
2903
+ }
2904
+ return {
2905
+ subscriptionId: sub.subscriptionId,
2906
+ planId: sub.planId,
2907
+ creator: sub.creator,
2908
+ subscriber: sub.subscriber,
2909
+ startTime: Number(sub.startTime),
2910
+ endTime: Number(sub.endTime),
2911
+ autoRenew: sub.autoRenew,
2912
+ status
2913
+ };
2914
+ } catch {
2915
+ return null;
2916
+ }
1172
2917
  }
1173
2918
  /**
1174
2919
  * Get a specific plan by ID
2920
+ * @param planId The plan ID
2921
+ * @param provider JSON-RPC provider
1175
2922
  */
1176
- async getPlan(planId) {
1177
- return null;
2923
+ async getPlan(planId, provider) {
2924
+ const iface = new (await import('ethers')).Interface(this.abi);
2925
+ const data = iface.encodeFunctionData("getPlan", [planId]);
2926
+ try {
2927
+ const result = await provider.call({
2928
+ to: this.contractAddress,
2929
+ data
2930
+ });
2931
+ const decoded = iface.decodeFunctionResult("getPlan", result);
2932
+ const plan = decoded[0];
2933
+ if (plan.planId === "0x0000000000000000000000000000000000000000000000000000000000000000") {
2934
+ return null;
2935
+ }
2936
+ const durationSeconds = Number(plan.durationDays) * 24 * 60 * 60;
2937
+ return {
2938
+ planId: plan.planId,
2939
+ name: plan.name,
2940
+ description: plan.description,
2941
+ price: plan.price,
2942
+ paymentToken: plan.paymentToken,
2943
+ duration: durationSeconds,
2944
+ perks: [],
2945
+ // Not stored on-chain
2946
+ maxSubscribers: Number(plan.maxSubscribers),
2947
+ nftBadge: false
2948
+ // Not stored on-chain in this contract version
2949
+ };
2950
+ } catch {
2951
+ return null;
2952
+ }
1178
2953
  }
1179
2954
  /**
1180
- * Get all plans for a creator
2955
+ * Get all plan IDs for a creator
2956
+ * @param creator The creator address
2957
+ * @param provider JSON-RPC provider
1181
2958
  */
1182
- async getCreatorPlans(creator) {
1183
- return [];
2959
+ async getCreatorPlanIds(creator, provider) {
2960
+ const iface = new (await import('ethers')).Interface(this.abi);
2961
+ const data = iface.encodeFunctionData("getCreatorPlans", [creator]);
2962
+ try {
2963
+ const result = await provider.call({
2964
+ to: this.contractAddress,
2965
+ data
2966
+ });
2967
+ const decoded = iface.decodeFunctionResult("getCreatorPlans", result);
2968
+ return decoded[0];
2969
+ } catch {
2970
+ return [];
2971
+ }
1184
2972
  }
1185
2973
  /**
1186
- * Generate a unique plan ID
2974
+ * Get all plans for a creator with full details
2975
+ * @param creator The creator address
2976
+ * @param provider JSON-RPC provider
1187
2977
  */
1188
- generatePlanId(name) {
1189
- const bytes = new Uint8Array(16);
1190
- crypto.getRandomValues(bytes);
1191
- return "0x" + Array.from(bytes).map((b) => b.toString(16).padStart(2, "0")).join("");
2978
+ async getCreatorPlans(creator, provider) {
2979
+ const planIds = await this.getCreatorPlanIds(creator, provider);
2980
+ const plans = [];
2981
+ for (const planId of planIds) {
2982
+ const plan = await this.getPlan(planId, provider);
2983
+ if (plan && plan.planId) {
2984
+ plans.push(plan);
2985
+ }
2986
+ }
2987
+ return plans;
2988
+ }
2989
+ /**
2990
+ * Get platform fee in basis points
2991
+ * @param provider JSON-RPC provider
2992
+ */
2993
+ async getPlatformFeeBps(provider) {
2994
+ const iface = new (await import('ethers')).Interface(this.abi);
2995
+ const data = iface.encodeFunctionData("platformFeeBps", []);
2996
+ try {
2997
+ const result = await provider.call({
2998
+ to: this.contractAddress,
2999
+ data
3000
+ });
3001
+ const decoded = iface.decodeFunctionResult("platformFeeBps", result);
3002
+ return Number(decoded[0]);
3003
+ } catch {
3004
+ return 300;
3005
+ }
3006
+ }
3007
+ /**
3008
+ * Calculate the total cost for a subscription
3009
+ * @param planPrice The plan price per period
3010
+ * @param months Number of months
3011
+ */
3012
+ calculateSubscriptionCost(planPrice, months) {
3013
+ return planPrice * BigInt(months);
3014
+ }
3015
+ /**
3016
+ * Calculate platform fee for a given amount
3017
+ * @param amount The amount
3018
+ * @param feeBps Fee in basis points
3019
+ */
3020
+ calculateFee(amount, feeBps = 300) {
3021
+ const fee = amount * BigInt(feeBps) / 10000n;
3022
+ return {
3023
+ fee,
3024
+ creatorAmount: amount - fee
3025
+ };
1192
3026
  }
1193
3027
  };
1194
3028