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