@zubari/sdk 0.3.2 → 0.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -7,7 +7,6 @@ import { sha256 } from '@noble/hashes/sha256';
7
7
  import { ripemd160 } from '@noble/hashes/ripemd160';
8
8
  import { createPublicClient, http, formatEther } from 'viem';
9
9
  import { mainnet, sepolia } from 'viem/chains';
10
- import { useMemo, useState, useCallback, useEffect } from 'react';
11
10
 
12
11
  var __defProp = Object.defineProperty;
13
12
  var __export = (target, all) => {
@@ -182,8 +181,11 @@ var ZUBARI_CONTRACTS = {
182
181
  }
183
182
  };
184
183
  var PLATFORM_CONFIG = {
185
- // Platform fee in basis points (300 = 3%)
186
- tipFeeBps: 300,
184
+ // Platform fee in basis points (1000 = 10%)
185
+ // Zubari keeps 10%, Creator receives 90%
186
+ platformFeeBps: 1e3,
187
+ tipFeeBps: 1e3,
188
+ // Alias for backward compatibility
187
189
  // Maximum royalty in basis points (1000 = 10%)
188
190
  maxRoyaltyBps: 1e3,
189
191
  // Default slippage tolerance for swaps (50 = 0.5%)
@@ -4420,10 +4422,11 @@ var ZubariMarketProtocol = class {
4420
4422
  }
4421
4423
  /**
4422
4424
  * Calculate platform fee for a given price
4425
+ * Platform keeps 10%, Creator/Seller receives 90%
4423
4426
  * @param price The sale price
4424
4427
  */
4425
4428
  calculateFee(price) {
4426
- const fee = price * BigInt(PLATFORM_CONFIG.tipFeeBps) / 10000n;
4429
+ const fee = price * BigInt(PLATFORM_CONFIG.platformFeeBps) / 10000n;
4427
4430
  return {
4428
4431
  fee,
4429
4432
  sellerAmount: price - fee
@@ -5227,9 +5230,10 @@ var ZubariTipsProtocol = class {
5227
5230
  /**
5228
5231
  * Calculate platform fee for a given amount
5229
5232
  * @param amount The tip amount
5230
- * @param feeBps Fee in basis points (default: 300 = 3%)
5233
+ * @param feeBps Fee in basis points (default: 1000 = 10%)
5234
+ * Platform keeps 10%, Creator receives 90%
5231
5235
  */
5232
- calculateFee(amount, feeBps = 300) {
5236
+ calculateFee(amount, feeBps = 1e3) {
5233
5237
  const fee = amount * BigInt(feeBps) / 10000n;
5234
5238
  return {
5235
5239
  fee,
@@ -6438,9 +6442,10 @@ var ZubariSubscriptionProtocol = class {
6438
6442
  /**
6439
6443
  * Calculate platform fee for a given amount
6440
6444
  * @param amount The amount
6441
- * @param feeBps Fee in basis points
6445
+ * @param feeBps Fee in basis points (default: 1000 = 10%)
6446
+ * Platform keeps 10%, Creator receives 90%
6442
6447
  */
6443
- calculateFee(amount, feeBps = 300) {
6448
+ calculateFee(amount, feeBps = 1e3) {
6444
6449
  const fee = amount * BigInt(feeBps) / 10000n;
6445
6450
  return {
6446
6451
  fee,
@@ -7450,245 +7455,6 @@ var ZubariError = class extends Error {
7450
7455
  this.name = "ZubariError";
7451
7456
  }
7452
7457
  };
7453
- function useWalletManager(options = {}) {
7454
- const { autoCheckWallet = true, ...config } = options;
7455
- const manager = useMemo(() => new WalletManager(config), [
7456
- config.network,
7457
- config.rpcUrl
7458
- ]);
7459
- const [state, setState] = useState({
7460
- isInitialized: false,
7461
- isLocked: true,
7462
- address: null,
7463
- balance: null
7464
- });
7465
- const [isLoading, setIsLoading] = useState(false);
7466
- const [error, setError] = useState(null);
7467
- const [selectedChain, setSelectedChainState] = useState("ethereum");
7468
- const [chainBalances, setChainBalances] = useState([]);
7469
- const updateState = useCallback(() => {
7470
- setState(manager.getExtendedState());
7471
- }, [manager]);
7472
- useEffect(() => {
7473
- if (autoCheckWallet) {
7474
- manager.hasWallet().then((exists) => {
7475
- if (exists) {
7476
- setState((prev) => ({
7477
- ...prev,
7478
- isInitialized: true,
7479
- isLocked: true
7480
- }));
7481
- }
7482
- });
7483
- }
7484
- }, [manager, autoCheckWallet]);
7485
- const createWallet = useCallback(
7486
- async (password) => {
7487
- setIsLoading(true);
7488
- setError(null);
7489
- try {
7490
- await manager.initializeStorage(password);
7491
- const result = await manager.createWallet(password);
7492
- try {
7493
- await manager.deriveAllAddressesAsync();
7494
- } catch {
7495
- manager.deriveAllAddresses();
7496
- }
7497
- updateState();
7498
- try {
7499
- const balances = await manager.fetchAllBalances();
7500
- setChainBalances(balances);
7501
- } catch (err) {
7502
- console.warn("Failed to fetch balances after create:", err);
7503
- }
7504
- return result;
7505
- } catch (err) {
7506
- const message = err instanceof Error ? err.message : "Failed to create wallet";
7507
- setError(message);
7508
- throw err;
7509
- } finally {
7510
- setIsLoading(false);
7511
- }
7512
- },
7513
- [manager, updateState]
7514
- );
7515
- const importWallet = useCallback(
7516
- async (seed, password) => {
7517
- setIsLoading(true);
7518
- setError(null);
7519
- try {
7520
- await manager.initializeStorage(password);
7521
- await manager.importWallet(seed, password);
7522
- try {
7523
- await manager.deriveAllAddressesAsync();
7524
- } catch {
7525
- manager.deriveAllAddresses();
7526
- }
7527
- updateState();
7528
- try {
7529
- const balances = await manager.fetchAllBalances();
7530
- setChainBalances(balances);
7531
- } catch (err) {
7532
- console.warn("Failed to fetch balances after import:", err);
7533
- }
7534
- } catch (err) {
7535
- const message = err instanceof Error ? err.message : "Failed to import wallet";
7536
- setError(message);
7537
- throw err;
7538
- } finally {
7539
- setIsLoading(false);
7540
- }
7541
- },
7542
- [manager, updateState]
7543
- );
7544
- const unlock = useCallback(
7545
- async (password) => {
7546
- setIsLoading(true);
7547
- setError(null);
7548
- try {
7549
- await manager.initializeStorage(password);
7550
- await manager.unlock(password);
7551
- try {
7552
- await manager.deriveAllAddressesAsync();
7553
- } catch {
7554
- manager.deriveAllAddresses();
7555
- }
7556
- updateState();
7557
- try {
7558
- const balances = await manager.fetchAllBalances();
7559
- setChainBalances(balances);
7560
- } catch (err) {
7561
- console.warn("Failed to fetch balances after unlock:", err);
7562
- }
7563
- } catch (err) {
7564
- const message = err instanceof Error ? err.message : "Invalid password";
7565
- setError(message);
7566
- throw err;
7567
- } finally {
7568
- setIsLoading(false);
7569
- }
7570
- },
7571
- [manager, updateState]
7572
- );
7573
- const lock = useCallback(() => {
7574
- manager.lock();
7575
- setChainBalances([]);
7576
- updateState();
7577
- }, [manager, updateState]);
7578
- const deleteWallet = useCallback(async () => {
7579
- setIsLoading(true);
7580
- setError(null);
7581
- try {
7582
- await manager.deleteWallet();
7583
- setChainBalances([]);
7584
- setState({
7585
- isInitialized: false,
7586
- isLocked: true,
7587
- address: null,
7588
- balance: null
7589
- });
7590
- } catch (err) {
7591
- const message = err instanceof Error ? err.message : "Failed to delete wallet";
7592
- setError(message);
7593
- throw err;
7594
- } finally {
7595
- setIsLoading(false);
7596
- }
7597
- }, [manager]);
7598
- const fetchBalance = useCallback(async () => {
7599
- setIsLoading(true);
7600
- try {
7601
- const balance = await manager.fetchBalance();
7602
- setState((prev) => ({ ...prev, balance }));
7603
- return balance;
7604
- } catch (err) {
7605
- console.warn("Failed to fetch balance:", err);
7606
- setState((prev) => ({ ...prev, balance: "0" }));
7607
- return "0";
7608
- } finally {
7609
- setIsLoading(false);
7610
- }
7611
- }, [manager]);
7612
- const fetchAllBalances = useCallback(async () => {
7613
- setIsLoading(true);
7614
- try {
7615
- const balances = await manager.fetchAllBalances();
7616
- setChainBalances(balances);
7617
- return balances;
7618
- } catch (err) {
7619
- console.warn("Failed to fetch all balances:", err);
7620
- return [];
7621
- } finally {
7622
- setIsLoading(false);
7623
- }
7624
- }, [manager]);
7625
- const setSelectedChain = useCallback((chain) => {
7626
- manager.setSelectedChain(chain);
7627
- setSelectedChainState(chain);
7628
- }, [manager]);
7629
- const getAddressForChain = useCallback(
7630
- (chain) => manager.getAddressForChain(chain),
7631
- [manager]
7632
- );
7633
- const getAllAddresses = useCallback(
7634
- () => manager.getAllAddresses(),
7635
- [manager]
7636
- );
7637
- const hasWallet = useCallback(() => manager.hasWallet(), [manager]);
7638
- const getSeed = useCallback(() => manager.getSeed(), [manager]);
7639
- const sendTransaction = useCallback(
7640
- async (chain, to, amount, token) => {
7641
- setIsLoading(true);
7642
- try {
7643
- const result = await manager.sendTransaction(chain, to, amount, token);
7644
- if (result.success) {
7645
- try {
7646
- const balances = await manager.fetchAllBalances();
7647
- setChainBalances(balances);
7648
- } catch (err) {
7649
- console.warn("Failed to refresh balances after transaction:", err);
7650
- }
7651
- }
7652
- return result;
7653
- } finally {
7654
- setIsLoading(false);
7655
- }
7656
- },
7657
- [manager]
7658
- );
7659
- const estimateFee = useCallback(
7660
- async (chain, to, amount, token) => {
7661
- return manager.estimateFee(chain, to, amount, token);
7662
- },
7663
- [manager]
7664
- );
7665
- return {
7666
- state,
7667
- isLoading,
7668
- error,
7669
- createWallet,
7670
- importWallet,
7671
- unlock,
7672
- lock,
7673
- deleteWallet,
7674
- fetchBalance,
7675
- // Multi-chain
7676
- selectedChain,
7677
- setSelectedChain,
7678
- chainBalances,
7679
- fetchAllBalances,
7680
- getAddressForChain,
7681
- getAllAddresses,
7682
- supportedChains: SUPPORTED_CHAINS,
7683
- // Transaction Actions (Powered by Tether WDK)
7684
- sendTransaction,
7685
- estimateFee,
7686
- // Utilities
7687
- hasWallet,
7688
- getSeed,
7689
- manager
7690
- };
7691
- }
7692
7458
 
7693
7459
  // src/utils/index.ts
7694
7460
  function formatAddress(address, chars = 4) {
@@ -7712,6 +7478,6 @@ function normalizeAddress(address) {
7712
7478
  return address.toLowerCase();
7713
7479
  }
7714
7480
 
7715
- 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 };
7481
+ 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 };
7716
7482
  //# sourceMappingURL=index.mjs.map
7717
7483
  //# sourceMappingURL=index.mjs.map