@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.
package/dist/index.js CHANGED
@@ -3294,97 +3294,1713 @@ var ZubariMarketProtocol = class {
3294
3294
  }
3295
3295
  };
3296
3296
 
3297
+ // src/abi/ZubariTips.json
3298
+ var ZubariTips_default = [
3299
+ {
3300
+ inputs: [
3301
+ {
3302
+ internalType: "address",
3303
+ name: "_treasury",
3304
+ type: "address"
3305
+ },
3306
+ {
3307
+ internalType: "uint256",
3308
+ name: "_platformFeeBps",
3309
+ type: "uint256"
3310
+ }
3311
+ ],
3312
+ stateMutability: "nonpayable",
3313
+ type: "constructor"
3314
+ },
3315
+ {
3316
+ inputs: [],
3317
+ name: "EnforcedPause",
3318
+ type: "error"
3319
+ },
3320
+ {
3321
+ inputs: [],
3322
+ name: "ExpectedPause",
3323
+ type: "error"
3324
+ },
3325
+ {
3326
+ inputs: [],
3327
+ name: "InvalidAddress",
3328
+ type: "error"
3329
+ },
3330
+ {
3331
+ inputs: [],
3332
+ name: "InvalidAmount",
3333
+ type: "error"
3334
+ },
3335
+ {
3336
+ inputs: [],
3337
+ name: "InvalidFee",
3338
+ type: "error"
3339
+ },
3340
+ {
3341
+ inputs: [],
3342
+ name: "InvalidRecipient",
3343
+ type: "error"
3344
+ },
3345
+ {
3346
+ inputs: [
3347
+ {
3348
+ internalType: "address",
3349
+ name: "owner",
3350
+ type: "address"
3351
+ }
3352
+ ],
3353
+ name: "OwnableInvalidOwner",
3354
+ type: "error"
3355
+ },
3356
+ {
3357
+ inputs: [
3358
+ {
3359
+ internalType: "address",
3360
+ name: "account",
3361
+ type: "address"
3362
+ }
3363
+ ],
3364
+ name: "OwnableUnauthorizedAccount",
3365
+ type: "error"
3366
+ },
3367
+ {
3368
+ inputs: [],
3369
+ name: "ReentrancyGuardReentrantCall",
3370
+ type: "error"
3371
+ },
3372
+ {
3373
+ inputs: [
3374
+ {
3375
+ internalType: "address",
3376
+ name: "token",
3377
+ type: "address"
3378
+ }
3379
+ ],
3380
+ name: "SafeERC20FailedOperation",
3381
+ type: "error"
3382
+ },
3383
+ {
3384
+ inputs: [],
3385
+ name: "TransferFailed",
3386
+ type: "error"
3387
+ },
3388
+ {
3389
+ anonymous: false,
3390
+ inputs: [
3391
+ {
3392
+ indexed: false,
3393
+ internalType: "uint256[]",
3394
+ name: "tipIds",
3395
+ type: "uint256[]"
3396
+ },
3397
+ {
3398
+ indexed: true,
3399
+ internalType: "address",
3400
+ name: "sender",
3401
+ type: "address"
3402
+ }
3403
+ ],
3404
+ name: "BatchTipSent",
3405
+ type: "event"
3406
+ },
3407
+ {
3408
+ anonymous: false,
3409
+ inputs: [
3410
+ {
3411
+ indexed: true,
3412
+ internalType: "address",
3413
+ name: "previousOwner",
3414
+ type: "address"
3415
+ },
3416
+ {
3417
+ indexed: true,
3418
+ internalType: "address",
3419
+ name: "newOwner",
3420
+ type: "address"
3421
+ }
3422
+ ],
3423
+ name: "OwnershipTransferred",
3424
+ type: "event"
3425
+ },
3426
+ {
3427
+ anonymous: false,
3428
+ inputs: [
3429
+ {
3430
+ indexed: false,
3431
+ internalType: "address",
3432
+ name: "account",
3433
+ type: "address"
3434
+ }
3435
+ ],
3436
+ name: "Paused",
3437
+ type: "event"
3438
+ },
3439
+ {
3440
+ anonymous: false,
3441
+ inputs: [
3442
+ {
3443
+ indexed: false,
3444
+ internalType: "uint256",
3445
+ name: "oldFee",
3446
+ type: "uint256"
3447
+ },
3448
+ {
3449
+ indexed: false,
3450
+ internalType: "uint256",
3451
+ name: "newFee",
3452
+ type: "uint256"
3453
+ }
3454
+ ],
3455
+ name: "PlatformFeeUpdated",
3456
+ type: "event"
3457
+ },
3458
+ {
3459
+ anonymous: false,
3460
+ inputs: [
3461
+ {
3462
+ indexed: true,
3463
+ internalType: "uint256",
3464
+ name: "tipId",
3465
+ type: "uint256"
3466
+ },
3467
+ {
3468
+ indexed: true,
3469
+ internalType: "address",
3470
+ name: "sender",
3471
+ type: "address"
3472
+ },
3473
+ {
3474
+ indexed: true,
3475
+ internalType: "address",
3476
+ name: "recipient",
3477
+ type: "address"
3478
+ },
3479
+ {
3480
+ indexed: false,
3481
+ internalType: "address",
3482
+ name: "token",
3483
+ type: "address"
3484
+ },
3485
+ {
3486
+ indexed: false,
3487
+ internalType: "uint256",
3488
+ name: "amount",
3489
+ type: "uint256"
3490
+ },
3491
+ {
3492
+ indexed: false,
3493
+ internalType: "uint256",
3494
+ name: "platformFee",
3495
+ type: "uint256"
3496
+ },
3497
+ {
3498
+ indexed: false,
3499
+ internalType: "string",
3500
+ name: "message",
3501
+ type: "string"
3502
+ }
3503
+ ],
3504
+ name: "TipSent",
3505
+ type: "event"
3506
+ },
3507
+ {
3508
+ anonymous: false,
3509
+ inputs: [
3510
+ {
3511
+ indexed: false,
3512
+ internalType: "address",
3513
+ name: "oldTreasury",
3514
+ type: "address"
3515
+ },
3516
+ {
3517
+ indexed: false,
3518
+ internalType: "address",
3519
+ name: "newTreasury",
3520
+ type: "address"
3521
+ }
3522
+ ],
3523
+ name: "TreasuryUpdated",
3524
+ type: "event"
3525
+ },
3526
+ {
3527
+ anonymous: false,
3528
+ inputs: [
3529
+ {
3530
+ indexed: false,
3531
+ internalType: "address",
3532
+ name: "account",
3533
+ type: "address"
3534
+ }
3535
+ ],
3536
+ name: "Unpaused",
3537
+ type: "event"
3538
+ },
3539
+ {
3540
+ inputs: [
3541
+ {
3542
+ internalType: "uint256",
3543
+ name: "tipId",
3544
+ type: "uint256"
3545
+ }
3546
+ ],
3547
+ name: "getTip",
3548
+ outputs: [
3549
+ {
3550
+ components: [
3551
+ {
3552
+ internalType: "uint256",
3553
+ name: "tipId",
3554
+ type: "uint256"
3555
+ },
3556
+ {
3557
+ internalType: "address",
3558
+ name: "sender",
3559
+ type: "address"
3560
+ },
3561
+ {
3562
+ internalType: "address",
3563
+ name: "recipient",
3564
+ type: "address"
3565
+ },
3566
+ {
3567
+ internalType: "address",
3568
+ name: "token",
3569
+ type: "address"
3570
+ },
3571
+ {
3572
+ internalType: "uint256",
3573
+ name: "amount",
3574
+ type: "uint256"
3575
+ },
3576
+ {
3577
+ internalType: "uint256",
3578
+ name: "platformFee",
3579
+ type: "uint256"
3580
+ },
3581
+ {
3582
+ internalType: "string",
3583
+ name: "message",
3584
+ type: "string"
3585
+ },
3586
+ {
3587
+ internalType: "uint256",
3588
+ name: "timestamp",
3589
+ type: "uint256"
3590
+ }
3591
+ ],
3592
+ internalType: "struct ZubariTips.Tip",
3593
+ name: "",
3594
+ type: "tuple"
3595
+ }
3596
+ ],
3597
+ stateMutability: "view",
3598
+ type: "function"
3599
+ },
3600
+ {
3601
+ inputs: [],
3602
+ name: "owner",
3603
+ outputs: [
3604
+ {
3605
+ internalType: "address",
3606
+ name: "",
3607
+ type: "address"
3608
+ }
3609
+ ],
3610
+ stateMutability: "view",
3611
+ type: "function"
3612
+ },
3613
+ {
3614
+ inputs: [],
3615
+ name: "pause",
3616
+ outputs: [],
3617
+ stateMutability: "nonpayable",
3618
+ type: "function"
3619
+ },
3620
+ {
3621
+ inputs: [],
3622
+ name: "paused",
3623
+ outputs: [
3624
+ {
3625
+ internalType: "bool",
3626
+ name: "",
3627
+ type: "bool"
3628
+ }
3629
+ ],
3630
+ stateMutability: "view",
3631
+ type: "function"
3632
+ },
3633
+ {
3634
+ inputs: [],
3635
+ name: "platformFeeBps",
3636
+ outputs: [
3637
+ {
3638
+ internalType: "uint256",
3639
+ name: "",
3640
+ type: "uint256"
3641
+ }
3642
+ ],
3643
+ stateMutability: "view",
3644
+ type: "function"
3645
+ },
3646
+ {
3647
+ inputs: [],
3648
+ name: "renounceOwnership",
3649
+ outputs: [],
3650
+ stateMutability: "nonpayable",
3651
+ type: "function"
3652
+ },
3653
+ {
3654
+ inputs: [
3655
+ {
3656
+ internalType: "address[]",
3657
+ name: "recipients",
3658
+ type: "address[]"
3659
+ },
3660
+ {
3661
+ internalType: "uint256[]",
3662
+ name: "amounts",
3663
+ type: "uint256[]"
3664
+ },
3665
+ {
3666
+ internalType: "string[]",
3667
+ name: "messages",
3668
+ type: "string[]"
3669
+ }
3670
+ ],
3671
+ name: "sendBatchTips",
3672
+ outputs: [],
3673
+ stateMutability: "payable",
3674
+ type: "function"
3675
+ },
3676
+ {
3677
+ inputs: [
3678
+ {
3679
+ internalType: "uint256",
3680
+ name: "_feeBps",
3681
+ type: "uint256"
3682
+ }
3683
+ ],
3684
+ name: "setPlatformFee",
3685
+ outputs: [],
3686
+ stateMutability: "nonpayable",
3687
+ type: "function"
3688
+ },
3689
+ {
3690
+ inputs: [
3691
+ {
3692
+ internalType: "address",
3693
+ name: "_treasury",
3694
+ type: "address"
3695
+ }
3696
+ ],
3697
+ name: "setTreasury",
3698
+ outputs: [],
3699
+ stateMutability: "nonpayable",
3700
+ type: "function"
3701
+ },
3702
+ {
3703
+ inputs: [],
3704
+ name: "tipCounter",
3705
+ outputs: [
3706
+ {
3707
+ internalType: "uint256",
3708
+ name: "",
3709
+ type: "uint256"
3710
+ }
3711
+ ],
3712
+ stateMutability: "view",
3713
+ type: "function"
3714
+ },
3715
+ {
3716
+ inputs: [
3717
+ {
3718
+ internalType: "address",
3719
+ name: "recipient",
3720
+ type: "address"
3721
+ },
3722
+ {
3723
+ internalType: "string",
3724
+ name: "message",
3725
+ type: "string"
3726
+ }
3727
+ ],
3728
+ name: "tipETH",
3729
+ outputs: [],
3730
+ stateMutability: "payable",
3731
+ type: "function"
3732
+ },
3733
+ {
3734
+ inputs: [
3735
+ {
3736
+ internalType: "address",
3737
+ name: "recipient",
3738
+ type: "address"
3739
+ },
3740
+ {
3741
+ internalType: "address",
3742
+ name: "token",
3743
+ type: "address"
3744
+ },
3745
+ {
3746
+ internalType: "uint256",
3747
+ name: "amount",
3748
+ type: "uint256"
3749
+ },
3750
+ {
3751
+ internalType: "string",
3752
+ name: "message",
3753
+ type: "string"
3754
+ }
3755
+ ],
3756
+ name: "tipToken",
3757
+ outputs: [],
3758
+ stateMutability: "nonpayable",
3759
+ type: "function"
3760
+ },
3761
+ {
3762
+ inputs: [
3763
+ {
3764
+ internalType: "uint256",
3765
+ name: "",
3766
+ type: "uint256"
3767
+ }
3768
+ ],
3769
+ name: "tips",
3770
+ outputs: [
3771
+ {
3772
+ internalType: "uint256",
3773
+ name: "tipId",
3774
+ type: "uint256"
3775
+ },
3776
+ {
3777
+ internalType: "address",
3778
+ name: "sender",
3779
+ type: "address"
3780
+ },
3781
+ {
3782
+ internalType: "address",
3783
+ name: "recipient",
3784
+ type: "address"
3785
+ },
3786
+ {
3787
+ internalType: "address",
3788
+ name: "token",
3789
+ type: "address"
3790
+ },
3791
+ {
3792
+ internalType: "uint256",
3793
+ name: "amount",
3794
+ type: "uint256"
3795
+ },
3796
+ {
3797
+ internalType: "uint256",
3798
+ name: "platformFee",
3799
+ type: "uint256"
3800
+ },
3801
+ {
3802
+ internalType: "string",
3803
+ name: "message",
3804
+ type: "string"
3805
+ },
3806
+ {
3807
+ internalType: "uint256",
3808
+ name: "timestamp",
3809
+ type: "uint256"
3810
+ }
3811
+ ],
3812
+ stateMutability: "view",
3813
+ type: "function"
3814
+ },
3815
+ {
3816
+ inputs: [
3817
+ {
3818
+ internalType: "address",
3819
+ name: "",
3820
+ type: "address"
3821
+ }
3822
+ ],
3823
+ name: "totalTipsReceived",
3824
+ outputs: [
3825
+ {
3826
+ internalType: "uint256",
3827
+ name: "",
3828
+ type: "uint256"
3829
+ }
3830
+ ],
3831
+ stateMutability: "view",
3832
+ type: "function"
3833
+ },
3834
+ {
3835
+ inputs: [
3836
+ {
3837
+ internalType: "address",
3838
+ name: "newOwner",
3839
+ type: "address"
3840
+ }
3841
+ ],
3842
+ name: "transferOwnership",
3843
+ outputs: [],
3844
+ stateMutability: "nonpayable",
3845
+ type: "function"
3846
+ },
3847
+ {
3848
+ inputs: [],
3849
+ name: "treasury",
3850
+ outputs: [
3851
+ {
3852
+ internalType: "address",
3853
+ name: "",
3854
+ type: "address"
3855
+ }
3856
+ ],
3857
+ stateMutability: "view",
3858
+ type: "function"
3859
+ },
3860
+ {
3861
+ inputs: [],
3862
+ name: "unpause",
3863
+ outputs: [],
3864
+ stateMutability: "nonpayable",
3865
+ type: "function"
3866
+ }
3867
+ ];
3868
+
3297
3869
  // src/protocols/TipsProtocol.ts
3298
3870
  var ZubariTipsProtocol = class {
3299
3871
  contractAddress;
3300
3872
  chainId;
3301
- gaslessEnabled;
3302
- constructor(contractAddress, chainId, gaslessEnabled = false) {
3873
+ abi = ZubariTips_default;
3874
+ constructor(contractAddress, chainId) {
3875
+ this.contractAddress = contractAddress;
3876
+ this.chainId = chainId;
3877
+ }
3878
+ /**
3879
+ * Get the contract ABI
3880
+ */
3881
+ getAbi() {
3882
+ return this.abi;
3883
+ }
3884
+ /**
3885
+ * Get the contract address
3886
+ */
3887
+ getAddress() {
3888
+ return this.contractAddress;
3889
+ }
3890
+ /**
3891
+ * Send ETH tip to a creator
3892
+ * @param recipient The recipient address
3893
+ * @param message Optional tip message
3894
+ * @param signer Wallet signer with sendTransaction method
3895
+ * @param value ETH amount to tip (in wei)
3896
+ */
3897
+ async tipETH(recipient, message, signer, value) {
3898
+ if (!recipient || recipient === "0x0000000000000000000000000000000000000000") {
3899
+ throw new Error("Invalid recipient address");
3900
+ }
3901
+ if (value <= 0n) {
3902
+ throw new Error("Tip amount must be greater than 0");
3903
+ }
3904
+ const iface = new (await import('ethers')).Interface(this.abi);
3905
+ const data = iface.encodeFunctionData("tipETH", [recipient, message || ""]);
3906
+ const result = await signer.sendTransaction({
3907
+ to: this.contractAddress,
3908
+ value,
3909
+ data
3910
+ });
3911
+ return {
3912
+ hash: result.hash,
3913
+ network: "ethereum",
3914
+ status: "pending"
3915
+ };
3916
+ }
3917
+ /**
3918
+ * Send ERC-20 token tip to a creator
3919
+ * @param recipient The recipient address
3920
+ * @param token The ERC-20 token address
3921
+ * @param amount The amount of tokens to tip
3922
+ * @param message Optional tip message
3923
+ * @param signer Wallet signer
3924
+ */
3925
+ async tipToken(recipient, token, amount, message, signer) {
3926
+ if (!recipient || recipient === "0x0000000000000000000000000000000000000000") {
3927
+ throw new Error("Invalid recipient address");
3928
+ }
3929
+ if (!token || token === "0x0000000000000000000000000000000000000000") {
3930
+ throw new Error("Use tipETH for native ETH tips");
3931
+ }
3932
+ if (amount <= 0n) {
3933
+ throw new Error("Tip amount must be greater than 0");
3934
+ }
3935
+ const iface = new (await import('ethers')).Interface(this.abi);
3936
+ const data = iface.encodeFunctionData("tipToken", [recipient, token, amount, message || ""]);
3937
+ const result = await signer.sendTransaction({
3938
+ to: this.contractAddress,
3939
+ value: 0n,
3940
+ data
3941
+ });
3942
+ return {
3943
+ hash: result.hash,
3944
+ network: "ethereum",
3945
+ status: "pending"
3946
+ };
3947
+ }
3948
+ /**
3949
+ * Send batch tips to multiple creators in a single transaction
3950
+ * @param recipients Array of recipient addresses
3951
+ * @param amounts Array of tip amounts (in wei)
3952
+ * @param messages Array of tip messages
3953
+ * @param signer Wallet signer
3954
+ * @param value Total ETH to send
3955
+ */
3956
+ async sendBatchTips(recipients, amounts, messages, signer, value) {
3957
+ if (recipients.length === 0) {
3958
+ throw new Error("At least one recipient is required");
3959
+ }
3960
+ if (recipients.length !== amounts.length || recipients.length !== messages.length) {
3961
+ throw new Error("Recipients, amounts, and messages arrays must have the same length");
3962
+ }
3963
+ for (const recipient of recipients) {
3964
+ if (!recipient || recipient === "0x0000000000000000000000000000000000000000") {
3965
+ throw new Error("Invalid recipient address in batch");
3966
+ }
3967
+ }
3968
+ const totalAmount = amounts.reduce((sum, amount) => sum + amount, 0n);
3969
+ if (totalAmount <= 0n) {
3970
+ throw new Error("Total tip amount must be greater than 0");
3971
+ }
3972
+ const iface = new (await import('ethers')).Interface(this.abi);
3973
+ const data = iface.encodeFunctionData("sendBatchTips", [recipients, amounts, messages]);
3974
+ const result = await signer.sendTransaction({
3975
+ to: this.contractAddress,
3976
+ value,
3977
+ data
3978
+ });
3979
+ return {
3980
+ hash: result.hash,
3981
+ network: "ethereum",
3982
+ status: "pending"
3983
+ };
3984
+ }
3985
+ /**
3986
+ * Get tip details by ID
3987
+ * @param tipId The tip ID
3988
+ * @param provider JSON-RPC provider
3989
+ */
3990
+ async getTip(tipId, provider) {
3991
+ const iface = new (await import('ethers')).Interface(this.abi);
3992
+ const data = iface.encodeFunctionData("getTip", [tipId]);
3993
+ try {
3994
+ const result = await provider.call({
3995
+ to: this.contractAddress,
3996
+ data
3997
+ });
3998
+ const decoded = iface.decodeFunctionResult("getTip", result);
3999
+ const tip = decoded[0];
4000
+ if (BigInt(tip.tipId) === 0n) {
4001
+ return null;
4002
+ }
4003
+ return {
4004
+ tipId: tip.tipId.toString(),
4005
+ sender: tip.sender,
4006
+ recipient: tip.recipient,
4007
+ token: tip.token,
4008
+ amount: BigInt(tip.amount),
4009
+ platformFee: BigInt(tip.platformFee),
4010
+ message: tip.message,
4011
+ timestamp: Number(tip.timestamp)
4012
+ };
4013
+ } catch {
4014
+ return null;
4015
+ }
4016
+ }
4017
+ /**
4018
+ * Get total tips received by an address
4019
+ * @param address The address to query
4020
+ * @param provider JSON-RPC provider
4021
+ */
4022
+ async getTotalTipsReceived(address, provider) {
4023
+ const iface = new (await import('ethers')).Interface(this.abi);
4024
+ const data = iface.encodeFunctionData("totalTipsReceived", [address]);
4025
+ try {
4026
+ const result = await provider.call({
4027
+ to: this.contractAddress,
4028
+ data
4029
+ });
4030
+ const decoded = iface.decodeFunctionResult("totalTipsReceived", result);
4031
+ return BigInt(decoded[0]);
4032
+ } catch {
4033
+ return 0n;
4034
+ }
4035
+ }
4036
+ /**
4037
+ * Get platform fee in basis points
4038
+ * @param provider JSON-RPC provider
4039
+ */
4040
+ async getPlatformFeeBps(provider) {
4041
+ const iface = new (await import('ethers')).Interface(this.abi);
4042
+ const data = iface.encodeFunctionData("platformFeeBps", []);
4043
+ try {
4044
+ const result = await provider.call({
4045
+ to: this.contractAddress,
4046
+ data
4047
+ });
4048
+ const decoded = iface.decodeFunctionResult("platformFeeBps", result);
4049
+ return Number(decoded[0]);
4050
+ } catch {
4051
+ return 300;
4052
+ }
4053
+ }
4054
+ /**
4055
+ * Get current tip counter
4056
+ * @param provider JSON-RPC provider
4057
+ */
4058
+ async getTipCounter(provider) {
4059
+ const iface = new (await import('ethers')).Interface(this.abi);
4060
+ const data = iface.encodeFunctionData("tipCounter", []);
4061
+ try {
4062
+ const result = await provider.call({
4063
+ to: this.contractAddress,
4064
+ data
4065
+ });
4066
+ const decoded = iface.decodeFunctionResult("tipCounter", result);
4067
+ return BigInt(decoded[0]);
4068
+ } catch {
4069
+ return 0n;
4070
+ }
4071
+ }
4072
+ /**
4073
+ * Get treasury address
4074
+ * @param provider JSON-RPC provider
4075
+ */
4076
+ async getTreasury(provider) {
4077
+ const iface = new (await import('ethers')).Interface(this.abi);
4078
+ const data = iface.encodeFunctionData("treasury", []);
4079
+ try {
4080
+ const result = await provider.call({
4081
+ to: this.contractAddress,
4082
+ data
4083
+ });
4084
+ const decoded = iface.decodeFunctionResult("treasury", result);
4085
+ return decoded[0];
4086
+ } catch {
4087
+ return "0x0000000000000000000000000000000000000000";
4088
+ }
4089
+ }
4090
+ /**
4091
+ * Calculate platform fee for a given amount
4092
+ * @param amount The tip amount
4093
+ * @param feeBps Fee in basis points (default: 300 = 3%)
4094
+ */
4095
+ calculateFee(amount, feeBps = 300) {
4096
+ const fee = amount * BigInt(feeBps) / 10000n;
4097
+ return {
4098
+ fee,
4099
+ creatorAmount: amount - fee
4100
+ };
4101
+ }
4102
+ };
4103
+
4104
+ // src/abi/ZubariSubscription.json
4105
+ var ZubariSubscription_default = [
4106
+ {
4107
+ inputs: [
4108
+ {
4109
+ internalType: "address",
4110
+ name: "_treasury",
4111
+ type: "address"
4112
+ },
4113
+ {
4114
+ internalType: "uint256",
4115
+ name: "_platformFeeBps",
4116
+ type: "uint256"
4117
+ }
4118
+ ],
4119
+ stateMutability: "nonpayable",
4120
+ type: "constructor"
4121
+ },
4122
+ {
4123
+ inputs: [],
4124
+ name: "AlreadySubscribed",
4125
+ type: "error"
4126
+ },
4127
+ {
4128
+ inputs: [],
4129
+ name: "EnforcedPause",
4130
+ type: "error"
4131
+ },
4132
+ {
4133
+ inputs: [],
4134
+ name: "ExpectedPause",
4135
+ type: "error"
4136
+ },
4137
+ {
4138
+ inputs: [],
4139
+ name: "InvalidAddress",
4140
+ type: "error"
4141
+ },
4142
+ {
4143
+ inputs: [],
4144
+ name: "InvalidAmount",
4145
+ type: "error"
4146
+ },
4147
+ {
4148
+ inputs: [],
4149
+ name: "InvalidDuration",
4150
+ type: "error"
4151
+ },
4152
+ {
4153
+ inputs: [],
4154
+ name: "InvalidFee",
4155
+ type: "error"
4156
+ },
4157
+ {
4158
+ inputs: [],
4159
+ name: "NotSubscriber",
4160
+ type: "error"
4161
+ },
4162
+ {
4163
+ inputs: [
4164
+ {
4165
+ internalType: "address",
4166
+ name: "owner",
4167
+ type: "address"
4168
+ }
4169
+ ],
4170
+ name: "OwnableInvalidOwner",
4171
+ type: "error"
4172
+ },
4173
+ {
4174
+ inputs: [
4175
+ {
4176
+ internalType: "address",
4177
+ name: "account",
4178
+ type: "address"
4179
+ }
4180
+ ],
4181
+ name: "OwnableUnauthorizedAccount",
4182
+ type: "error"
4183
+ },
4184
+ {
4185
+ inputs: [],
4186
+ name: "PlanFull",
4187
+ type: "error"
4188
+ },
4189
+ {
4190
+ inputs: [],
4191
+ name: "PlanNotActive",
4192
+ type: "error"
4193
+ },
4194
+ {
4195
+ inputs: [],
4196
+ name: "PlanNotFound",
4197
+ type: "error"
4198
+ },
4199
+ {
4200
+ inputs: [],
4201
+ name: "ReentrancyGuardReentrantCall",
4202
+ type: "error"
4203
+ },
4204
+ {
4205
+ inputs: [
4206
+ {
4207
+ internalType: "address",
4208
+ name: "token",
4209
+ type: "address"
4210
+ }
4211
+ ],
4212
+ name: "SafeERC20FailedOperation",
4213
+ type: "error"
4214
+ },
4215
+ {
4216
+ anonymous: false,
4217
+ inputs: [
4218
+ {
4219
+ indexed: true,
4220
+ internalType: "address",
4221
+ name: "previousOwner",
4222
+ type: "address"
4223
+ },
4224
+ {
4225
+ indexed: true,
4226
+ internalType: "address",
4227
+ name: "newOwner",
4228
+ type: "address"
4229
+ }
4230
+ ],
4231
+ name: "OwnershipTransferred",
4232
+ type: "event"
4233
+ },
4234
+ {
4235
+ anonymous: false,
4236
+ inputs: [
4237
+ {
4238
+ indexed: false,
4239
+ internalType: "address",
4240
+ name: "account",
4241
+ type: "address"
4242
+ }
4243
+ ],
4244
+ name: "Paused",
4245
+ type: "event"
4246
+ },
4247
+ {
4248
+ anonymous: false,
4249
+ inputs: [
4250
+ {
4251
+ indexed: true,
4252
+ internalType: "bytes32",
4253
+ name: "planId",
4254
+ type: "bytes32"
4255
+ },
4256
+ {
4257
+ indexed: true,
4258
+ internalType: "address",
4259
+ name: "creator",
4260
+ type: "address"
4261
+ },
4262
+ {
4263
+ indexed: false,
4264
+ internalType: "string",
4265
+ name: "name",
4266
+ type: "string"
4267
+ },
4268
+ {
4269
+ indexed: false,
4270
+ internalType: "uint256",
4271
+ name: "price",
4272
+ type: "uint256"
4273
+ }
4274
+ ],
4275
+ name: "PlanCreated",
4276
+ type: "event"
4277
+ },
4278
+ {
4279
+ anonymous: false,
4280
+ inputs: [
4281
+ {
4282
+ indexed: true,
4283
+ internalType: "bytes32",
4284
+ name: "planId",
4285
+ type: "bytes32"
4286
+ }
4287
+ ],
4288
+ name: "PlanDeactivated",
4289
+ type: "event"
4290
+ },
4291
+ {
4292
+ anonymous: false,
4293
+ inputs: [
4294
+ {
4295
+ indexed: true,
4296
+ internalType: "bytes32",
4297
+ name: "planId",
4298
+ type: "bytes32"
4299
+ }
4300
+ ],
4301
+ name: "PlanUpdated",
4302
+ type: "event"
4303
+ },
4304
+ {
4305
+ anonymous: false,
4306
+ inputs: [
4307
+ {
4308
+ indexed: true,
4309
+ internalType: "bytes32",
4310
+ name: "subscriptionId",
4311
+ type: "bytes32"
4312
+ },
4313
+ {
4314
+ indexed: true,
4315
+ internalType: "bytes32",
4316
+ name: "planId",
4317
+ type: "bytes32"
4318
+ },
4319
+ {
4320
+ indexed: true,
4321
+ internalType: "address",
4322
+ name: "subscriber",
4323
+ type: "address"
4324
+ },
4325
+ {
4326
+ indexed: false,
4327
+ internalType: "address",
4328
+ name: "creator",
4329
+ type: "address"
4330
+ },
4331
+ {
4332
+ indexed: false,
4333
+ internalType: "uint256",
4334
+ name: "endTime",
4335
+ type: "uint256"
4336
+ }
4337
+ ],
4338
+ name: "Subscribed",
4339
+ type: "event"
4340
+ },
4341
+ {
4342
+ anonymous: false,
4343
+ inputs: [
4344
+ {
4345
+ indexed: true,
4346
+ internalType: "bytes32",
4347
+ name: "subscriptionId",
4348
+ type: "bytes32"
4349
+ }
4350
+ ],
4351
+ name: "SubscriptionCancelled",
4352
+ type: "event"
4353
+ },
4354
+ {
4355
+ anonymous: false,
4356
+ inputs: [
4357
+ {
4358
+ indexed: true,
4359
+ internalType: "bytes32",
4360
+ name: "subscriptionId",
4361
+ type: "bytes32"
4362
+ },
4363
+ {
4364
+ indexed: false,
4365
+ internalType: "uint256",
4366
+ name: "newEndTime",
4367
+ type: "uint256"
4368
+ }
4369
+ ],
4370
+ name: "SubscriptionRenewed",
4371
+ type: "event"
4372
+ },
4373
+ {
4374
+ anonymous: false,
4375
+ inputs: [
4376
+ {
4377
+ indexed: false,
4378
+ internalType: "address",
4379
+ name: "account",
4380
+ type: "address"
4381
+ }
4382
+ ],
4383
+ name: "Unpaused",
4384
+ type: "event"
4385
+ },
4386
+ {
4387
+ inputs: [
4388
+ {
4389
+ internalType: "address",
4390
+ name: "",
4391
+ type: "address"
4392
+ },
4393
+ {
4394
+ internalType: "address",
4395
+ name: "",
4396
+ type: "address"
4397
+ }
4398
+ ],
4399
+ name: "activeSubscription",
4400
+ outputs: [
4401
+ {
4402
+ internalType: "bytes32",
4403
+ name: "",
4404
+ type: "bytes32"
4405
+ }
4406
+ ],
4407
+ stateMutability: "view",
4408
+ type: "function"
4409
+ },
4410
+ {
4411
+ inputs: [
4412
+ {
4413
+ internalType: "bytes32",
4414
+ name: "subscriptionId",
4415
+ type: "bytes32"
4416
+ }
4417
+ ],
4418
+ name: "cancel",
4419
+ outputs: [],
4420
+ stateMutability: "nonpayable",
4421
+ type: "function"
4422
+ },
4423
+ {
4424
+ inputs: [
4425
+ {
4426
+ internalType: "string",
4427
+ name: "name",
4428
+ type: "string"
4429
+ },
4430
+ {
4431
+ internalType: "string",
4432
+ name: "description",
4433
+ type: "string"
4434
+ },
4435
+ {
4436
+ internalType: "uint256",
4437
+ name: "price",
4438
+ type: "uint256"
4439
+ },
4440
+ {
4441
+ internalType: "address",
4442
+ name: "paymentToken",
4443
+ type: "address"
4444
+ },
4445
+ {
4446
+ internalType: "uint256",
4447
+ name: "durationDays",
4448
+ type: "uint256"
4449
+ },
4450
+ {
4451
+ internalType: "uint256",
4452
+ name: "maxSubscribers",
4453
+ type: "uint256"
4454
+ }
4455
+ ],
4456
+ name: "createPlan",
4457
+ outputs: [
4458
+ {
4459
+ internalType: "bytes32",
4460
+ name: "",
4461
+ type: "bytes32"
4462
+ }
4463
+ ],
4464
+ stateMutability: "nonpayable",
4465
+ type: "function"
4466
+ },
4467
+ {
4468
+ inputs: [
4469
+ {
4470
+ internalType: "address",
4471
+ name: "",
4472
+ type: "address"
4473
+ },
4474
+ {
4475
+ internalType: "uint256",
4476
+ name: "",
4477
+ type: "uint256"
4478
+ }
4479
+ ],
4480
+ name: "creatorPlans",
4481
+ outputs: [
4482
+ {
4483
+ internalType: "bytes32",
4484
+ name: "",
4485
+ type: "bytes32"
4486
+ }
4487
+ ],
4488
+ stateMutability: "view",
4489
+ type: "function"
4490
+ },
4491
+ {
4492
+ inputs: [
4493
+ {
4494
+ internalType: "bytes32",
4495
+ name: "planId",
4496
+ type: "bytes32"
4497
+ }
4498
+ ],
4499
+ name: "deactivatePlan",
4500
+ outputs: [],
4501
+ stateMutability: "nonpayable",
4502
+ type: "function"
4503
+ },
4504
+ {
4505
+ inputs: [
4506
+ {
4507
+ internalType: "address",
4508
+ name: "creator",
4509
+ type: "address"
4510
+ }
4511
+ ],
4512
+ name: "getCreatorPlans",
4513
+ outputs: [
4514
+ {
4515
+ internalType: "bytes32[]",
4516
+ name: "",
4517
+ type: "bytes32[]"
4518
+ }
4519
+ ],
4520
+ stateMutability: "view",
4521
+ type: "function"
4522
+ },
4523
+ {
4524
+ inputs: [
4525
+ {
4526
+ internalType: "bytes32",
4527
+ name: "planId",
4528
+ type: "bytes32"
4529
+ }
4530
+ ],
4531
+ name: "getPlan",
4532
+ outputs: [
4533
+ {
4534
+ components: [
4535
+ {
4536
+ internalType: "bytes32",
4537
+ name: "planId",
4538
+ type: "bytes32"
4539
+ },
4540
+ {
4541
+ internalType: "address",
4542
+ name: "creator",
4543
+ type: "address"
4544
+ },
4545
+ {
4546
+ internalType: "string",
4547
+ name: "name",
4548
+ type: "string"
4549
+ },
4550
+ {
4551
+ internalType: "string",
4552
+ name: "description",
4553
+ type: "string"
4554
+ },
4555
+ {
4556
+ internalType: "uint256",
4557
+ name: "price",
4558
+ type: "uint256"
4559
+ },
4560
+ {
4561
+ internalType: "address",
4562
+ name: "paymentToken",
4563
+ type: "address"
4564
+ },
4565
+ {
4566
+ internalType: "uint256",
4567
+ name: "durationDays",
4568
+ type: "uint256"
4569
+ },
4570
+ {
4571
+ internalType: "uint256",
4572
+ name: "maxSubscribers",
4573
+ type: "uint256"
4574
+ },
4575
+ {
4576
+ internalType: "uint256",
4577
+ name: "subscriberCount",
4578
+ type: "uint256"
4579
+ },
4580
+ {
4581
+ internalType: "bool",
4582
+ name: "isActive",
4583
+ type: "bool"
4584
+ }
4585
+ ],
4586
+ internalType: "struct ZubariSubscription.SubscriptionPlan",
4587
+ name: "",
4588
+ type: "tuple"
4589
+ }
4590
+ ],
4591
+ stateMutability: "view",
4592
+ type: "function"
4593
+ },
4594
+ {
4595
+ inputs: [
4596
+ {
4597
+ internalType: "bytes32",
4598
+ name: "subscriptionId",
4599
+ type: "bytes32"
4600
+ }
4601
+ ],
4602
+ name: "getSubscription",
4603
+ outputs: [
4604
+ {
4605
+ components: [
4606
+ {
4607
+ internalType: "bytes32",
4608
+ name: "subscriptionId",
4609
+ type: "bytes32"
4610
+ },
4611
+ {
4612
+ internalType: "bytes32",
4613
+ name: "planId",
4614
+ type: "bytes32"
4615
+ },
4616
+ {
4617
+ internalType: "address",
4618
+ name: "creator",
4619
+ type: "address"
4620
+ },
4621
+ {
4622
+ internalType: "address",
4623
+ name: "subscriber",
4624
+ type: "address"
4625
+ },
4626
+ {
4627
+ internalType: "uint256",
4628
+ name: "startTime",
4629
+ type: "uint256"
4630
+ },
4631
+ {
4632
+ internalType: "uint256",
4633
+ name: "endTime",
4634
+ type: "uint256"
4635
+ },
4636
+ {
4637
+ internalType: "bool",
4638
+ name: "autoRenew",
4639
+ type: "bool"
4640
+ },
4641
+ {
4642
+ internalType: "enum ZubariSubscription.SubscriptionStatus",
4643
+ name: "status",
4644
+ type: "uint8"
4645
+ }
4646
+ ],
4647
+ internalType: "struct ZubariSubscription.Subscription",
4648
+ name: "",
4649
+ type: "tuple"
4650
+ }
4651
+ ],
4652
+ stateMutability: "view",
4653
+ type: "function"
4654
+ },
4655
+ {
4656
+ inputs: [
4657
+ {
4658
+ internalType: "address",
4659
+ name: "subscriber",
4660
+ type: "address"
4661
+ },
4662
+ {
4663
+ internalType: "address",
4664
+ name: "creator",
4665
+ type: "address"
4666
+ }
4667
+ ],
4668
+ name: "isSubscribed",
4669
+ outputs: [
4670
+ {
4671
+ internalType: "bool",
4672
+ name: "",
4673
+ type: "bool"
4674
+ }
4675
+ ],
4676
+ stateMutability: "view",
4677
+ type: "function"
4678
+ },
4679
+ {
4680
+ inputs: [],
4681
+ name: "owner",
4682
+ outputs: [
4683
+ {
4684
+ internalType: "address",
4685
+ name: "",
4686
+ type: "address"
4687
+ }
4688
+ ],
4689
+ stateMutability: "view",
4690
+ type: "function"
4691
+ },
4692
+ {
4693
+ inputs: [],
4694
+ name: "pause",
4695
+ outputs: [],
4696
+ stateMutability: "nonpayable",
4697
+ type: "function"
4698
+ },
4699
+ {
4700
+ inputs: [],
4701
+ name: "paused",
4702
+ outputs: [
4703
+ {
4704
+ internalType: "bool",
4705
+ name: "",
4706
+ type: "bool"
4707
+ }
4708
+ ],
4709
+ stateMutability: "view",
4710
+ type: "function"
4711
+ },
4712
+ {
4713
+ inputs: [
4714
+ {
4715
+ internalType: "bytes32",
4716
+ name: "",
4717
+ type: "bytes32"
4718
+ }
4719
+ ],
4720
+ name: "plans",
4721
+ outputs: [
4722
+ {
4723
+ internalType: "bytes32",
4724
+ name: "planId",
4725
+ type: "bytes32"
4726
+ },
4727
+ {
4728
+ internalType: "address",
4729
+ name: "creator",
4730
+ type: "address"
4731
+ },
4732
+ {
4733
+ internalType: "string",
4734
+ name: "name",
4735
+ type: "string"
4736
+ },
4737
+ {
4738
+ internalType: "string",
4739
+ name: "description",
4740
+ type: "string"
4741
+ },
4742
+ {
4743
+ internalType: "uint256",
4744
+ name: "price",
4745
+ type: "uint256"
4746
+ },
4747
+ {
4748
+ internalType: "address",
4749
+ name: "paymentToken",
4750
+ type: "address"
4751
+ },
4752
+ {
4753
+ internalType: "uint256",
4754
+ name: "durationDays",
4755
+ type: "uint256"
4756
+ },
4757
+ {
4758
+ internalType: "uint256",
4759
+ name: "maxSubscribers",
4760
+ type: "uint256"
4761
+ },
4762
+ {
4763
+ internalType: "uint256",
4764
+ name: "subscriberCount",
4765
+ type: "uint256"
4766
+ },
4767
+ {
4768
+ internalType: "bool",
4769
+ name: "isActive",
4770
+ type: "bool"
4771
+ }
4772
+ ],
4773
+ stateMutability: "view",
4774
+ type: "function"
4775
+ },
4776
+ {
4777
+ inputs: [],
4778
+ name: "platformFeeBps",
4779
+ outputs: [
4780
+ {
4781
+ internalType: "uint256",
4782
+ name: "",
4783
+ type: "uint256"
4784
+ }
4785
+ ],
4786
+ stateMutability: "view",
4787
+ type: "function"
4788
+ },
4789
+ {
4790
+ inputs: [],
4791
+ name: "renounceOwnership",
4792
+ outputs: [],
4793
+ stateMutability: "nonpayable",
4794
+ type: "function"
4795
+ },
4796
+ {
4797
+ inputs: [
4798
+ {
4799
+ internalType: "bytes32",
4800
+ name: "subscriptionId",
4801
+ type: "bytes32"
4802
+ },
4803
+ {
4804
+ internalType: "bool",
4805
+ name: "autoRenew",
4806
+ type: "bool"
4807
+ }
4808
+ ],
4809
+ name: "setAutoRenew",
4810
+ outputs: [],
4811
+ stateMutability: "nonpayable",
4812
+ type: "function"
4813
+ },
4814
+ {
4815
+ inputs: [
4816
+ {
4817
+ internalType: "uint256",
4818
+ name: "_feeBps",
4819
+ type: "uint256"
4820
+ }
4821
+ ],
4822
+ name: "setPlatformFee",
4823
+ outputs: [],
4824
+ stateMutability: "nonpayable",
4825
+ type: "function"
4826
+ },
4827
+ {
4828
+ inputs: [
4829
+ {
4830
+ internalType: "address",
4831
+ name: "_treasury",
4832
+ type: "address"
4833
+ }
4834
+ ],
4835
+ name: "setTreasury",
4836
+ outputs: [],
4837
+ stateMutability: "nonpayable",
4838
+ type: "function"
4839
+ },
4840
+ {
4841
+ inputs: [
4842
+ {
4843
+ internalType: "bytes32",
4844
+ name: "planId",
4845
+ type: "bytes32"
4846
+ },
4847
+ {
4848
+ internalType: "uint256",
4849
+ name: "months",
4850
+ type: "uint256"
4851
+ }
4852
+ ],
4853
+ name: "subscribe",
4854
+ outputs: [
4855
+ {
4856
+ internalType: "bytes32",
4857
+ name: "",
4858
+ type: "bytes32"
4859
+ }
4860
+ ],
4861
+ stateMutability: "payable",
4862
+ type: "function"
4863
+ },
4864
+ {
4865
+ inputs: [
4866
+ {
4867
+ internalType: "address",
4868
+ name: "",
4869
+ type: "address"
4870
+ },
4871
+ {
4872
+ internalType: "uint256",
4873
+ name: "",
4874
+ type: "uint256"
4875
+ }
4876
+ ],
4877
+ name: "subscriberSubscriptions",
4878
+ outputs: [
4879
+ {
4880
+ internalType: "bytes32",
4881
+ name: "",
4882
+ type: "bytes32"
4883
+ }
4884
+ ],
4885
+ stateMutability: "view",
4886
+ type: "function"
4887
+ },
4888
+ {
4889
+ inputs: [
4890
+ {
4891
+ internalType: "bytes32",
4892
+ name: "",
4893
+ type: "bytes32"
4894
+ }
4895
+ ],
4896
+ name: "subscriptions",
4897
+ outputs: [
4898
+ {
4899
+ internalType: "bytes32",
4900
+ name: "subscriptionId",
4901
+ type: "bytes32"
4902
+ },
4903
+ {
4904
+ internalType: "bytes32",
4905
+ name: "planId",
4906
+ type: "bytes32"
4907
+ },
4908
+ {
4909
+ internalType: "address",
4910
+ name: "creator",
4911
+ type: "address"
4912
+ },
4913
+ {
4914
+ internalType: "address",
4915
+ name: "subscriber",
4916
+ type: "address"
4917
+ },
4918
+ {
4919
+ internalType: "uint256",
4920
+ name: "startTime",
4921
+ type: "uint256"
4922
+ },
4923
+ {
4924
+ internalType: "uint256",
4925
+ name: "endTime",
4926
+ type: "uint256"
4927
+ },
4928
+ {
4929
+ internalType: "bool",
4930
+ name: "autoRenew",
4931
+ type: "bool"
4932
+ },
4933
+ {
4934
+ internalType: "enum ZubariSubscription.SubscriptionStatus",
4935
+ name: "status",
4936
+ type: "uint8"
4937
+ }
4938
+ ],
4939
+ stateMutability: "view",
4940
+ type: "function"
4941
+ },
4942
+ {
4943
+ inputs: [
4944
+ {
4945
+ internalType: "address",
4946
+ name: "newOwner",
4947
+ type: "address"
4948
+ }
4949
+ ],
4950
+ name: "transferOwnership",
4951
+ outputs: [],
4952
+ stateMutability: "nonpayable",
4953
+ type: "function"
4954
+ },
4955
+ {
4956
+ inputs: [],
4957
+ name: "treasury",
4958
+ outputs: [
4959
+ {
4960
+ internalType: "address",
4961
+ name: "",
4962
+ type: "address"
4963
+ }
4964
+ ],
4965
+ stateMutability: "view",
4966
+ type: "function"
4967
+ },
4968
+ {
4969
+ inputs: [],
4970
+ name: "unpause",
4971
+ outputs: [],
4972
+ stateMutability: "nonpayable",
4973
+ type: "function"
4974
+ }
4975
+ ];
4976
+
4977
+ // src/protocols/SubscriptionProtocol.ts
4978
+ var ZubariSubscriptionProtocol = class {
4979
+ contractAddress;
4980
+ chainId;
4981
+ abi = ZubariSubscription_default;
4982
+ constructor(contractAddress, chainId) {
3303
4983
  this.contractAddress = contractAddress;
3304
4984
  this.chainId = chainId;
3305
- this.gaslessEnabled = gaslessEnabled;
3306
- }
3307
- /**
3308
- * Send a tip to a creator
3309
- */
3310
- async sendTip(tip) {
3311
- const { recipient, amount, token, message } = tip;
3312
- const platformFee = amount * BigInt(PLATFORM_CONFIG.tipFeeBps) / BigInt(1e4);
3313
- const creatorAmount = amount - platformFee;
3314
- if (amount <= 0n) {
3315
- throw new Error("Tip amount must be greater than 0");
3316
- }
3317
- const txResult = {
3318
- hash: ""};
3319
- return {
3320
- txHash: txResult.hash,
3321
- tipId: "",
3322
- // Will be returned from contract event
3323
- recipient,
3324
- amount: creatorAmount,
3325
- platformFee,
3326
- timestamp: Math.floor(Date.now() / 1e3)
3327
- };
3328
- }
3329
- /**
3330
- * Send tips to multiple creators in a single transaction
3331
- */
3332
- async sendBatchTips(tips) {
3333
- if (tips.length === 0) {
3334
- throw new Error("At least one tip is required");
3335
- }
3336
- tips.reduce((sum, tip) => sum + tip.amount, BigInt(0));
3337
- return tips.map((tip) => ({
3338
- txHash: "",
3339
- tipId: "",
3340
- recipient: tip.recipient,
3341
- amount: tip.amount - tip.amount * BigInt(PLATFORM_CONFIG.tipFeeBps) / BigInt(1e4),
3342
- platformFee: tip.amount * BigInt(PLATFORM_CONFIG.tipFeeBps) / BigInt(1e4),
3343
- timestamp: Math.floor(Date.now() / 1e3)
3344
- }));
3345
- }
3346
- /**
3347
- * Get tips received by an address
3348
- */
3349
- async getTipsReceived(address) {
3350
- return [];
3351
- }
3352
- /**
3353
- * Get tips sent by an address
3354
- */
3355
- async getTipsSent(address) {
3356
- return [];
3357
4985
  }
3358
4986
  /**
3359
- * Get tip statistics for a creator
4987
+ * Get the contract ABI
3360
4988
  */
3361
- async getCreatorTipStats(creator) {
3362
- return {
3363
- totalReceived: BigInt(0),
3364
- tipCount: 0,
3365
- uniqueTippers: 0
3366
- };
4989
+ getAbi() {
4990
+ return this.abi;
3367
4991
  }
3368
4992
  /**
3369
- * Get platform fee in basis points
4993
+ * Get the contract address
3370
4994
  */
3371
- getPlatformFeeBps() {
3372
- return PLATFORM_CONFIG.tipFeeBps;
3373
- }
3374
- };
3375
-
3376
- // src/protocols/SubscriptionProtocol.ts
3377
- var ZubariSubscriptionProtocol = class {
3378
- contractAddress;
3379
- chainId;
3380
- constructor(contractAddress, chainId) {
3381
- this.contractAddress = contractAddress;
3382
- this.chainId = chainId;
4995
+ getAddress() {
4996
+ return this.contractAddress;
3383
4997
  }
3384
4998
  /**
3385
4999
  * Create a new subscription plan
5000
+ * @param plan The plan details
5001
+ * @param signer Wallet signer with sendTransaction method
3386
5002
  */
3387
- async createPlan(plan) {
5003
+ async createPlan(plan, signer) {
3388
5004
  if (!plan.name || plan.name.length === 0) {
3389
5005
  throw new Error("Plan name is required");
3390
5006
  }
@@ -3394,87 +5010,305 @@ var ZubariSubscriptionProtocol = class {
3394
5010
  if (plan.duration <= 0) {
3395
5011
  throw new Error("Plan duration must be greater than 0");
3396
5012
  }
3397
- const planId = this.generatePlanId(plan.name);
3398
- return planId;
5013
+ const iface = new (await import('ethers')).Interface(this.abi);
5014
+ const durationDays = Math.ceil(plan.duration / (24 * 60 * 60));
5015
+ const data = iface.encodeFunctionData("createPlan", [
5016
+ plan.name,
5017
+ plan.description || "",
5018
+ plan.price,
5019
+ plan.paymentToken || "0x0000000000000000000000000000000000000000",
5020
+ // ETH by default
5021
+ durationDays,
5022
+ plan.maxSubscribers || 0
5023
+ // 0 = unlimited
5024
+ ]);
5025
+ const result = await signer.sendTransaction({
5026
+ to: this.contractAddress,
5027
+ value: 0n,
5028
+ data
5029
+ });
5030
+ return result.hash;
3399
5031
  }
3400
5032
  /**
3401
- * Update an existing subscription plan
5033
+ * Deactivate a subscription plan (only creator can do this)
5034
+ * @param planId The plan ID to deactivate
5035
+ * @param signer Wallet signer
3402
5036
  */
3403
- async updatePlan(planId, updates) {
5037
+ async deactivatePlan(planId, signer) {
5038
+ const iface = new (await import('ethers')).Interface(this.abi);
5039
+ const data = iface.encodeFunctionData("deactivatePlan", [planId]);
5040
+ const result = await signer.sendTransaction({
5041
+ to: this.contractAddress,
5042
+ value: 0n,
5043
+ data
5044
+ });
3404
5045
  return {
3405
- hash: "",
5046
+ hash: result.hash,
3406
5047
  network: "ethereum",
3407
5048
  status: "pending"
3408
5049
  };
3409
5050
  }
3410
5051
  /**
3411
5052
  * Subscribe to a creator's plan
5053
+ * @param planId The plan ID to subscribe to
5054
+ * @param months Number of months to subscribe
5055
+ * @param signer Wallet signer
5056
+ * @param value ETH value to send (if paying with ETH)
3412
5057
  */
3413
- async subscribe(creator, planId, months = 1) {
5058
+ async subscribe(planId, months, signer, value) {
3414
5059
  if (months <= 0) {
3415
5060
  throw new Error("Subscription duration must be at least 1 month");
3416
5061
  }
3417
- const now = Math.floor(Date.now() / 1e3);
3418
- const durationSeconds = months * 30 * 24 * 60 * 60;
5062
+ const iface = new (await import('ethers')).Interface(this.abi);
5063
+ const data = iface.encodeFunctionData("subscribe", [planId, months]);
5064
+ const result = await signer.sendTransaction({
5065
+ to: this.contractAddress,
5066
+ value: value || 0n,
5067
+ data
5068
+ });
3419
5069
  return {
3420
- subscriptionId: "",
3421
- planId,
3422
- creator,
3423
- subscriber: "",
3424
- // Current user address
3425
- startTime: now,
3426
- endTime: now + durationSeconds,
3427
- autoRenew: false,
3428
- status: "active"
5070
+ hash: result.hash,
5071
+ network: "ethereum",
5072
+ status: "pending"
3429
5073
  };
3430
5074
  }
3431
5075
  /**
3432
5076
  * Cancel an active subscription
5077
+ * @param subscriptionId The subscription ID to cancel
5078
+ * @param signer Wallet signer
3433
5079
  */
3434
- async cancel(subscriptionId) {
5080
+ async cancel(subscriptionId, signer) {
5081
+ const iface = new (await import('ethers')).Interface(this.abi);
5082
+ const data = iface.encodeFunctionData("cancel", [subscriptionId]);
5083
+ const result = await signer.sendTransaction({
5084
+ to: this.contractAddress,
5085
+ value: 0n,
5086
+ data
5087
+ });
3435
5088
  return {
3436
- hash: "",
5089
+ hash: result.hash,
5090
+ network: "ethereum",
5091
+ status: "pending"
5092
+ };
5093
+ }
5094
+ /**
5095
+ * Set auto-renew for a subscription
5096
+ * @param subscriptionId The subscription ID
5097
+ * @param autoRenew Whether to enable auto-renew
5098
+ * @param signer Wallet signer
5099
+ */
5100
+ async setAutoRenew(subscriptionId, autoRenew, signer) {
5101
+ const iface = new (await import('ethers')).Interface(this.abi);
5102
+ const data = iface.encodeFunctionData("setAutoRenew", [subscriptionId, autoRenew]);
5103
+ const result = await signer.sendTransaction({
5104
+ to: this.contractAddress,
5105
+ value: 0n,
5106
+ data
5107
+ });
5108
+ return {
5109
+ hash: result.hash,
3437
5110
  network: "ethereum",
3438
5111
  status: "pending"
3439
5112
  };
3440
5113
  }
3441
5114
  /**
3442
5115
  * Check if an address is subscribed to a creator
5116
+ * @param subscriber The subscriber address
5117
+ * @param creator The creator address
5118
+ * @param provider JSON-RPC provider
3443
5119
  */
3444
- async isSubscribed(creator, subscriber) {
3445
- return false;
5120
+ async isSubscribed(subscriber, creator, provider) {
5121
+ const iface = new (await import('ethers')).Interface(this.abi);
5122
+ const data = iface.encodeFunctionData("isSubscribed", [subscriber, creator]);
5123
+ try {
5124
+ const result = await provider.call({
5125
+ to: this.contractAddress,
5126
+ data
5127
+ });
5128
+ const decoded = iface.decodeFunctionResult("isSubscribed", result);
5129
+ return decoded[0];
5130
+ } catch {
5131
+ return false;
5132
+ }
3446
5133
  }
3447
5134
  /**
3448
- * Get active subscriptions for a subscriber
5135
+ * Get the active subscription ID between subscriber and creator
5136
+ * @param subscriber The subscriber address
5137
+ * @param creator The creator address
5138
+ * @param provider JSON-RPC provider
3449
5139
  */
3450
- async getActiveSubscriptions(subscriber) {
3451
- return [];
5140
+ async getActiveSubscriptionId(subscriber, creator, provider) {
5141
+ const iface = new (await import('ethers')).Interface(this.abi);
5142
+ const data = iface.encodeFunctionData("activeSubscription", [subscriber, creator]);
5143
+ try {
5144
+ const result = await provider.call({
5145
+ to: this.contractAddress,
5146
+ data
5147
+ });
5148
+ const decoded = iface.decodeFunctionResult("activeSubscription", result);
5149
+ const subscriptionId = decoded[0];
5150
+ if (subscriptionId === "0x0000000000000000000000000000000000000000000000000000000000000000") {
5151
+ return null;
5152
+ }
5153
+ return subscriptionId;
5154
+ } catch {
5155
+ return null;
5156
+ }
3452
5157
  }
3453
5158
  /**
3454
- * Get all subscribers for a creator
5159
+ * Get subscription details by ID
5160
+ * @param subscriptionId The subscription ID
5161
+ * @param provider JSON-RPC provider
3455
5162
  */
3456
- async getSubscribers(creator) {
3457
- return [];
5163
+ async getSubscription(subscriptionId, provider) {
5164
+ const iface = new (await import('ethers')).Interface(this.abi);
5165
+ const data = iface.encodeFunctionData("getSubscription", [subscriptionId]);
5166
+ try {
5167
+ const result = await provider.call({
5168
+ to: this.contractAddress,
5169
+ data
5170
+ });
5171
+ const decoded = iface.decodeFunctionResult("getSubscription", result);
5172
+ const sub = decoded[0];
5173
+ if (sub.subscriptionId === "0x0000000000000000000000000000000000000000000000000000000000000000") {
5174
+ return null;
5175
+ }
5176
+ let status;
5177
+ switch (Number(sub.status)) {
5178
+ case 0 /* Active */:
5179
+ status = "active";
5180
+ break;
5181
+ case 1 /* Cancelled */:
5182
+ status = "cancelled";
5183
+ break;
5184
+ case 2 /* Expired */:
5185
+ status = "expired";
5186
+ break;
5187
+ default:
5188
+ status = "active";
5189
+ }
5190
+ return {
5191
+ subscriptionId: sub.subscriptionId,
5192
+ planId: sub.planId,
5193
+ creator: sub.creator,
5194
+ subscriber: sub.subscriber,
5195
+ startTime: Number(sub.startTime),
5196
+ endTime: Number(sub.endTime),
5197
+ autoRenew: sub.autoRenew,
5198
+ status
5199
+ };
5200
+ } catch {
5201
+ return null;
5202
+ }
3458
5203
  }
3459
5204
  /**
3460
5205
  * Get a specific plan by ID
5206
+ * @param planId The plan ID
5207
+ * @param provider JSON-RPC provider
3461
5208
  */
3462
- async getPlan(planId) {
3463
- return null;
5209
+ async getPlan(planId, provider) {
5210
+ const iface = new (await import('ethers')).Interface(this.abi);
5211
+ const data = iface.encodeFunctionData("getPlan", [planId]);
5212
+ try {
5213
+ const result = await provider.call({
5214
+ to: this.contractAddress,
5215
+ data
5216
+ });
5217
+ const decoded = iface.decodeFunctionResult("getPlan", result);
5218
+ const plan = decoded[0];
5219
+ if (plan.planId === "0x0000000000000000000000000000000000000000000000000000000000000000") {
5220
+ return null;
5221
+ }
5222
+ const durationSeconds = Number(plan.durationDays) * 24 * 60 * 60;
5223
+ return {
5224
+ planId: plan.planId,
5225
+ name: plan.name,
5226
+ description: plan.description,
5227
+ price: plan.price,
5228
+ paymentToken: plan.paymentToken,
5229
+ duration: durationSeconds,
5230
+ perks: [],
5231
+ // Not stored on-chain
5232
+ maxSubscribers: Number(plan.maxSubscribers),
5233
+ nftBadge: false
5234
+ // Not stored on-chain in this contract version
5235
+ };
5236
+ } catch {
5237
+ return null;
5238
+ }
3464
5239
  }
3465
5240
  /**
3466
- * Get all plans for a creator
5241
+ * Get all plan IDs for a creator
5242
+ * @param creator The creator address
5243
+ * @param provider JSON-RPC provider
3467
5244
  */
3468
- async getCreatorPlans(creator) {
3469
- return [];
5245
+ async getCreatorPlanIds(creator, provider) {
5246
+ const iface = new (await import('ethers')).Interface(this.abi);
5247
+ const data = iface.encodeFunctionData("getCreatorPlans", [creator]);
5248
+ try {
5249
+ const result = await provider.call({
5250
+ to: this.contractAddress,
5251
+ data
5252
+ });
5253
+ const decoded = iface.decodeFunctionResult("getCreatorPlans", result);
5254
+ return decoded[0];
5255
+ } catch {
5256
+ return [];
5257
+ }
3470
5258
  }
3471
5259
  /**
3472
- * Generate a unique plan ID
5260
+ * Get all plans for a creator with full details
5261
+ * @param creator The creator address
5262
+ * @param provider JSON-RPC provider
3473
5263
  */
3474
- generatePlanId(name) {
3475
- const bytes = new Uint8Array(16);
3476
- crypto.getRandomValues(bytes);
3477
- return "0x" + Array.from(bytes).map((b) => b.toString(16).padStart(2, "0")).join("");
5264
+ async getCreatorPlans(creator, provider) {
5265
+ const planIds = await this.getCreatorPlanIds(creator, provider);
5266
+ const plans = [];
5267
+ for (const planId of planIds) {
5268
+ const plan = await this.getPlan(planId, provider);
5269
+ if (plan && plan.planId) {
5270
+ plans.push(plan);
5271
+ }
5272
+ }
5273
+ return plans;
5274
+ }
5275
+ /**
5276
+ * Get platform fee in basis points
5277
+ * @param provider JSON-RPC provider
5278
+ */
5279
+ async getPlatformFeeBps(provider) {
5280
+ const iface = new (await import('ethers')).Interface(this.abi);
5281
+ const data = iface.encodeFunctionData("platformFeeBps", []);
5282
+ try {
5283
+ const result = await provider.call({
5284
+ to: this.contractAddress,
5285
+ data
5286
+ });
5287
+ const decoded = iface.decodeFunctionResult("platformFeeBps", result);
5288
+ return Number(decoded[0]);
5289
+ } catch {
5290
+ return 300;
5291
+ }
5292
+ }
5293
+ /**
5294
+ * Calculate the total cost for a subscription
5295
+ * @param planPrice The plan price per period
5296
+ * @param months Number of months
5297
+ */
5298
+ calculateSubscriptionCost(planPrice, months) {
5299
+ return planPrice * BigInt(months);
5300
+ }
5301
+ /**
5302
+ * Calculate platform fee for a given amount
5303
+ * @param amount The amount
5304
+ * @param feeBps Fee in basis points
5305
+ */
5306
+ calculateFee(amount, feeBps = 300) {
5307
+ const fee = amount * BigInt(feeBps) / 10000n;
5308
+ return {
5309
+ fee,
5310
+ creatorAmount: amount - fee
5311
+ };
3478
5312
  }
3479
5313
  };
3480
5314