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