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