@zubari/sdk 0.2.8 → 0.3.1

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.
Files changed (39) hide show
  1. package/dist/{TransactionService-8xSEGoWA.d.mts → TransactionService-DURp3bRL.d.ts} +34 -10
  2. package/dist/{TransactionService-CaIcCoqY.d.ts → TransactionService-DuMJmrG3.d.mts} +34 -10
  3. package/dist/{WalletManager-CCs4Jsv7.d.ts → WalletManager-CEjN-YBF.d.ts} +12 -12
  4. package/dist/{WalletManager-B1qvFF4K.d.mts → WalletManager-bo35aHOJ.d.mts} +12 -12
  5. package/dist/{index-BOc9U2TK.d.mts → index-BpjMiC3n.d.ts} +22 -11
  6. package/dist/{index-Cx389p_j.d.mts → index-DF0Gf8NK.d.mts} +7 -1
  7. package/dist/{index-Cx389p_j.d.ts → index-DF0Gf8NK.d.ts} +7 -1
  8. package/dist/{index-Cqrpp3XA.d.ts → index-DJnsirV5.d.mts} +22 -11
  9. package/dist/index.d.mts +4 -4
  10. package/dist/index.d.ts +4 -4
  11. package/dist/index.js +3064 -1770
  12. package/dist/index.js.map +1 -1
  13. package/dist/index.mjs +3064 -1770
  14. package/dist/index.mjs.map +1 -1
  15. package/dist/protocols/index.d.mts +54 -22
  16. package/dist/protocols/index.d.ts +54 -22
  17. package/dist/protocols/index.js +1008 -76
  18. package/dist/protocols/index.js.map +1 -1
  19. package/dist/protocols/index.mjs +1008 -76
  20. package/dist/protocols/index.mjs.map +1 -1
  21. package/dist/react/index.d.mts +3 -3
  22. package/dist/react/index.d.ts +3 -3
  23. package/dist/react/index.js +884 -884
  24. package/dist/react/index.js.map +1 -1
  25. package/dist/react/index.mjs +884 -884
  26. package/dist/react/index.mjs.map +1 -1
  27. package/dist/services/index.d.mts +2 -2
  28. package/dist/services/index.d.ts +2 -2
  29. package/dist/services/index.js +152 -75
  30. package/dist/services/index.js.map +1 -1
  31. package/dist/services/index.mjs +152 -75
  32. package/dist/services/index.mjs.map +1 -1
  33. package/dist/wallet/index.d.mts +3 -3
  34. package/dist/wallet/index.d.ts +3 -3
  35. package/dist/wallet/index.js +1352 -1105
  36. package/dist/wallet/index.js.map +1 -1
  37. package/dist/wallet/index.mjs +1352 -1105
  38. package/dist/wallet/index.mjs.map +1 -1
  39. package/package.json +13 -12
@@ -1,5 +1,5 @@
1
- export { B as BrowserAddressDerivation, C as BrowserChainAddress, a as BrowserMultiChainAddresses, l as ChainAddress, m as ChainBalance, D as DeriveAddressResponse, c as DeriveAllAddressesResponse, v as FeeEstimate, F as FeeRates, G as GenerateSeedResponse, M as MultiChainAddresses, e as SendTransactionResponse, k as SupportedChain, S as SwapService, u as TransactionHistoryItem, d as TransactionHistoryResponse, s as TransactionParams, t as TransactionResult, p as TransactionService, w as TransactionServiceConfig, f as TransactionStatusResponse, V as ValidateSeedResponse, W as WdkApiClient, b as WdkApiConfig, T as WdkTransactionHistoryItem, n as WdkTransactionResult, Z as ZubariWdkService, o as ZubariWdkServiceConfig, r as createTransactionService, i as createZubariWdkService, q as getTransactionService, g as getWdkApiClient, h as getZubariWdkService, j as isBrowser } from '../TransactionService-8xSEGoWA.mjs';
2
- import { N as NFTCurrency } from '../index-Cx389p_j.mjs';
1
+ export { B as BrowserAddressDerivation, C as BrowserChainAddress, a as BrowserMultiChainAddresses, l as ChainAddress, m as ChainBalance, D as DeriveAddressResponse, c as DeriveAllAddressesResponse, v as FeeEstimate, F as FeeRates, G as GenerateSeedResponse, M as MultiChainAddresses, e as SendTransactionResponse, k as SupportedChain, S as SwapService, u as TransactionHistoryItem, d as TransactionHistoryResponse, s as TransactionParams, t as TransactionResult, p as TransactionService, w as TransactionServiceConfig, f as TransactionStatusResponse, V as ValidateSeedResponse, W as WdkApiClient, b as WdkApiConfig, T as WdkTransactionHistoryItem, n as WdkTransactionResult, Z as ZubariWdkService, o as ZubariWdkServiceConfig, r as createTransactionService, i as createZubariWdkService, q as getTransactionService, g as getWdkApiClient, h as getZubariWdkService, j as isBrowser } from '../TransactionService-DuMJmrG3.mjs';
2
+ import { N as NFTCurrency } from '../index-DF0Gf8NK.mjs';
3
3
 
4
4
  /**
5
5
  * Zubari API Client
@@ -1,5 +1,5 @@
1
- export { B as BrowserAddressDerivation, C as BrowserChainAddress, a as BrowserMultiChainAddresses, l as ChainAddress, m as ChainBalance, D as DeriveAddressResponse, c as DeriveAllAddressesResponse, v as FeeEstimate, F as FeeRates, G as GenerateSeedResponse, M as MultiChainAddresses, e as SendTransactionResponse, k as SupportedChain, S as SwapService, u as TransactionHistoryItem, d as TransactionHistoryResponse, s as TransactionParams, t as TransactionResult, p as TransactionService, w as TransactionServiceConfig, f as TransactionStatusResponse, V as ValidateSeedResponse, W as WdkApiClient, b as WdkApiConfig, T as WdkTransactionHistoryItem, n as WdkTransactionResult, Z as ZubariWdkService, o as ZubariWdkServiceConfig, r as createTransactionService, i as createZubariWdkService, q as getTransactionService, g as getWdkApiClient, h as getZubariWdkService, j as isBrowser } from '../TransactionService-CaIcCoqY.js';
2
- import { N as NFTCurrency } from '../index-Cx389p_j.js';
1
+ export { B as BrowserAddressDerivation, C as BrowserChainAddress, a as BrowserMultiChainAddresses, l as ChainAddress, m as ChainBalance, D as DeriveAddressResponse, c as DeriveAllAddressesResponse, v as FeeEstimate, F as FeeRates, G as GenerateSeedResponse, M as MultiChainAddresses, e as SendTransactionResponse, k as SupportedChain, S as SwapService, u as TransactionHistoryItem, d as TransactionHistoryResponse, s as TransactionParams, t as TransactionResult, p as TransactionService, w as TransactionServiceConfig, f as TransactionStatusResponse, V as ValidateSeedResponse, W as WdkApiClient, b as WdkApiConfig, T as WdkTransactionHistoryItem, n as WdkTransactionResult, Z as ZubariWdkService, o as ZubariWdkServiceConfig, r as createTransactionService, i as createZubariWdkService, q as getTransactionService, g as getWdkApiClient, h as getZubariWdkService, j as isBrowser } from '../TransactionService-DURp3bRL.js';
2
+ import { N as NFTCurrency } from '../index-DF0Gf8NK.js';
3
3
 
4
4
  /**
5
5
  * Zubari API Client
@@ -15,115 +15,171 @@ var __export = (target, all) => {
15
15
  };
16
16
 
17
17
  // src/config/contracts.ts
18
- var ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
19
- var ZUBARI_CONTRACTS = {
20
- testnet: {
21
- // Ethereum Sepolia (11155111) - Deployed 2024-12-31
22
- registry: "0xe5CE1Eb986f58BE42EEDFe5C18ee5956803b2BDC",
23
- nft: "0xc165b8C6843e8f0B1489525D0f853d23f22c677B",
24
- // ZubariNFT ERC-721 with payment
25
- nft1155: "0x5e618B5bEaE1dc41369E7aa235Cc3b9245905192",
26
- // Zubari1155 ERC-1155 multi-edition
27
- marketplace: "0xfcEfDa6C73aC357b8695E5F8F8d17820750BF207",
28
- tips: "0x86a9A306C7fCC9e0B8cd6859f6f15498d0046BB7",
29
- subscriptions: "0xaB7F17A85F61d9ab9f96bCB4e73e910D019978F7",
30
- payouts: "0x8aaB23Fb2a83A259E965Aae8Ee0938b1400B7E6b",
31
- entryPoint: "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789",
32
- paymaster: ZERO_ADDRESS,
33
- // Deploy with: npx hardhat run deploy/deploy.ts --network ethereum-sepolia
34
- accountFactory: ZERO_ADDRESS,
35
- // Not yet deployed
36
- usdt: "0xaA8E23Fb1079EA71e0a56F48a2aA51851D8433D0",
37
- // USDT on Sepolia
38
- weth: "0xfFf9976782d46CC05630D1f6eBAb18b2324d6B14"
39
- },
40
- mainnet: {
41
- // Ethereum Mainnet (1)
42
- registry: ZERO_ADDRESS,
43
- nft: ZERO_ADDRESS,
44
- nft1155: ZERO_ADDRESS,
45
- marketplace: ZERO_ADDRESS,
46
- tips: ZERO_ADDRESS,
47
- subscriptions: ZERO_ADDRESS,
48
- payouts: ZERO_ADDRESS,
49
- entryPoint: "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789",
50
- paymaster: ZERO_ADDRESS,
51
- accountFactory: ZERO_ADDRESS,
52
- usdt: "0xdAC17F958D2ee523a2206206994597C13D831ec7",
53
- // USDT on Ethereum
54
- weth: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
55
- }
56
- };
57
18
  var PLATFORM_CONFIG = {
58
19
  // Default slippage tolerance for swaps (50 = 0.5%)
59
- defaultSlippageBps: 50};
60
- function getContractAddresses(network) {
61
- return ZUBARI_CONTRACTS[network];
62
- }
20
+ defaultSlippageBps: 50,
21
+ // Swap deadline in seconds (30 minutes)
22
+ swapDeadlineSecs: 30 * 60
23
+ };
63
24
 
64
25
  // src/services/SwapService.ts
26
+ var UNISWAP_ADDRESSES = {
27
+ mainnet: {
28
+ swapRouter: "0xE592427A0AEce92De3Edee1F18E0157C05861564",
29
+ quoter: "0xb27308f9F90D607463bb33eA1BeBb41C27CE5AB6",
30
+ factory: "0x1F98431c8aD98523631AE4a59f267346ea31F984"
31
+ },
32
+ sepolia: {
33
+ swapRouter: "0x3bFA4769FB09eefC5a80d6E87c3B9C650f7Ae48E",
34
+ quoter: "0xEd1f6473345F45b75F8179591dd5bA1888cf2FB3",
35
+ factory: "0x0227628f3F023bb0B980b67D528571c95c6DaC1c"
36
+ }
37
+ };
38
+ var UNISWAP_SELECTORS = {
39
+ quoteExactInputSingle: "0xf7729d43",
40
+ // quoteExactInputSingle(address,address,uint24,uint256,uint160)
41
+ exactInputSingle: "0x414bf389"
42
+ // exactInputSingle((address,address,uint24,address,uint256,uint256,uint256,uint160))
43
+ };
44
+ var TOKENS = {
45
+ mainnet: {
46
+ WETH: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
47
+ USDT: "0xdAC17F958D2ee523a2206206994597C13D831ec7",
48
+ USDC: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
49
+ },
50
+ sepolia: {
51
+ WETH: "0xfFf9976782d46CC05630D1f6eBAb18b2324d6B14",
52
+ USDT: "0x7169D38820dfd117C3FA1f22a697dBA58d90BA06",
53
+ USDC: "0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238"
54
+ }
55
+ };
56
+ var ETH_ADDRESS = "0x0000000000000000000000000000000000000000";
65
57
  var SwapService = class {
66
- _chainId;
58
+ chainId;
67
59
  isTestnet;
60
+ addresses;
61
+ tokens;
68
62
  constructor(chainId, isTestnet = false) {
69
- this._chainId = chainId;
63
+ this.chainId = chainId;
70
64
  this.isTestnet = isTestnet;
65
+ this.addresses = isTestnet ? UNISWAP_ADDRESSES.sepolia : UNISWAP_ADDRESSES.mainnet;
66
+ this.tokens = isTestnet ? TOKENS.sepolia : TOKENS.mainnet;
71
67
  }
72
68
  /**
73
- * Get a swap quote
69
+ * Get a swap quote from Uniswap V3 Quoter
74
70
  */
75
- async getQuote(tokenIn, tokenOut, amountIn) {
71
+ async getQuote(tokenIn, tokenOut, amountIn, provider) {
76
72
  if (amountIn <= 0n) {
77
73
  throw new Error("Amount must be greater than 0");
78
74
  }
79
- return {
80
- tokenIn,
81
- tokenOut,
82
- amountIn,
83
- amountOut: BigInt(0),
84
- priceImpact: 0,
85
- route: [tokenIn, tokenOut],
86
- estimatedGas: BigInt(0)
87
- };
75
+ const actualTokenIn = tokenIn === ETH_ADDRESS ? this.tokens.WETH : tokenIn;
76
+ const actualTokenOut = tokenOut === ETH_ADDRESS ? this.tokens.WETH : tokenOut;
77
+ if (!provider) {
78
+ console.warn("No provider for quote, returning estimate");
79
+ return {
80
+ tokenIn,
81
+ tokenOut,
82
+ amountIn,
83
+ amountOut: amountIn * BigInt(95) / BigInt(100),
84
+ // Rough estimate
85
+ priceImpact: 0.5,
86
+ route: [tokenIn, tokenOut],
87
+ estimatedGas: BigInt(15e4)
88
+ };
89
+ }
90
+ try {
91
+ const encodedTokenIn = actualTokenIn.toLowerCase().replace("0x", "").padStart(64, "0");
92
+ const encodedTokenOut = actualTokenOut.toLowerCase().replace("0x", "").padStart(64, "0");
93
+ const encodedFee = 3e3.toString(16).padStart(64, "0");
94
+ const encodedAmountIn = amountIn.toString(16).padStart(64, "0");
95
+ const encodedSqrtPriceLimit = "0".padStart(64, "0");
96
+ const data = `${UNISWAP_SELECTORS.quoteExactInputSingle}${encodedTokenIn}${encodedTokenOut}${encodedFee}${encodedAmountIn}${encodedSqrtPriceLimit}`;
97
+ const result = await provider.call({
98
+ to: this.addresses.quoter,
99
+ data
100
+ });
101
+ const amountOut = BigInt(result);
102
+ const priceImpact = this.calculatePriceImpact(amountIn, amountOut, tokenIn, tokenOut);
103
+ return {
104
+ tokenIn,
105
+ tokenOut,
106
+ amountIn,
107
+ amountOut,
108
+ priceImpact,
109
+ route: [tokenIn, tokenOut],
110
+ estimatedGas: BigInt(15e4)
111
+ };
112
+ } catch (error) {
113
+ console.error("Failed to get quote:", error);
114
+ throw new Error(`Quote failed: ${error instanceof Error ? error.message : "Unknown error"}`);
115
+ }
88
116
  }
89
117
  /**
90
- * Execute a swap with slippage protection
118
+ * Execute a swap with slippage protection via Uniswap V3 SwapRouter
91
119
  */
92
- async executeSwap(quote, slippageToleranceBps = PLATFORM_CONFIG.defaultSlippageBps) {
93
- quote.amountOut - quote.amountOut * BigInt(slippageToleranceBps) / BigInt(1e4);
120
+ async executeSwap(quote, signer, recipient, slippageToleranceBps = PLATFORM_CONFIG.defaultSlippageBps) {
121
+ const minAmountOut = quote.amountOut - quote.amountOut * BigInt(slippageToleranceBps) / BigInt(1e4);
122
+ const deadline = Math.floor(Date.now() / 1e3) + PLATFORM_CONFIG.swapDeadlineSecs;
94
123
  if (quote.priceImpact > 5) {
95
124
  console.warn(`High price impact: ${quote.priceImpact}%`);
96
125
  }
97
- return {
98
- hash: "",
99
- network: "ethereum",
100
- status: "pending"
101
- };
126
+ const actualTokenIn = quote.tokenIn === ETH_ADDRESS ? this.tokens.WETH : quote.tokenIn;
127
+ const actualTokenOut = quote.tokenOut === ETH_ADDRESS ? this.tokens.WETH : quote.tokenOut;
128
+ const isETHIn = quote.tokenIn === ETH_ADDRESS;
129
+ try {
130
+ const encodedTokenIn = actualTokenIn.toLowerCase().replace("0x", "").padStart(64, "0");
131
+ const encodedTokenOut = actualTokenOut.toLowerCase().replace("0x", "").padStart(64, "0");
132
+ const encodedFee = 3e3.toString(16).padStart(64, "0");
133
+ const encodedRecipient = recipient.toLowerCase().replace("0x", "").padStart(64, "0");
134
+ const encodedDeadline = deadline.toString(16).padStart(64, "0");
135
+ const encodedAmountIn = quote.amountIn.toString(16).padStart(64, "0");
136
+ const encodedMinAmountOut = minAmountOut.toString(16).padStart(64, "0");
137
+ const encodedSqrtPriceLimit = "0".padStart(64, "0");
138
+ const data = `${UNISWAP_SELECTORS.exactInputSingle}${encodedTokenIn}${encodedTokenOut}${encodedFee}${encodedRecipient}${encodedDeadline}${encodedAmountIn}${encodedMinAmountOut}${encodedSqrtPriceLimit}`;
139
+ const tx = await signer.sendTransaction({
140
+ to: this.addresses.swapRouter,
141
+ data,
142
+ value: isETHIn ? `0x${quote.amountIn.toString(16)}` : "0x0"
143
+ });
144
+ return {
145
+ hash: tx.hash,
146
+ network: "ethereum",
147
+ status: "pending",
148
+ metadata: {
149
+ tokenIn: quote.tokenIn,
150
+ tokenOut: quote.tokenOut,
151
+ amountIn: quote.amountIn.toString(),
152
+ minAmountOut: minAmountOut.toString(),
153
+ deadline
154
+ }
155
+ };
156
+ } catch (error) {
157
+ console.error("Failed to execute swap:", error);
158
+ throw new Error(`Swap failed: ${error instanceof Error ? error.message : "Unknown error"}`);
159
+ }
102
160
  }
103
161
  /**
104
162
  * Convert earnings to USDT, keeping some ETH for gas
105
163
  */
106
- async convertEarningsToStable(ethBalance, reserveForGas = BigInt("10000000000000000")) {
164
+ async convertEarningsToStable(ethBalance, signer, recipient, provider, reserveForGas = BigInt("10000000000000000")) {
107
165
  const amountToSwap = ethBalance - reserveForGas;
108
166
  if (amountToSwap <= 0n) {
109
167
  throw new Error("Insufficient balance after gas reserve");
110
168
  }
111
- const contracts = getContractAddresses(this.isTestnet ? "testnet" : "mainnet");
112
169
  const quote = await this.getQuote(
113
- "0x0000000000000000000000000000000000000000",
114
- // ETH
115
- contracts.usdt,
116
- // USDT on Ethereum
117
- amountToSwap
170
+ ETH_ADDRESS,
171
+ this.tokens.USDT,
172
+ amountToSwap,
173
+ provider
118
174
  );
119
- return this.executeSwap(quote);
175
+ return this.executeSwap(quote, signer, recipient);
120
176
  }
121
177
  /**
122
178
  * Check if a swap route exists
123
179
  */
124
- async hasRoute(tokenIn, tokenOut) {
180
+ async hasRoute(tokenIn, tokenOut, provider) {
125
181
  try {
126
- const quote = await this.getQuote(tokenIn, tokenOut, BigInt(1));
182
+ const quote = await this.getQuote(tokenIn, tokenOut, BigInt(10 ** 18), provider);
127
183
  return quote.amountOut > 0n;
128
184
  } catch {
129
185
  return false;
@@ -133,7 +189,28 @@ var SwapService = class {
133
189
  * Get supported tokens for swapping
134
190
  */
135
191
  async getSupportedTokens() {
136
- return [];
192
+ return [
193
+ { address: ETH_ADDRESS, symbol: "ETH", decimals: 18, name: "Ether" },
194
+ { address: this.tokens.WETH, symbol: "WETH", decimals: 18, name: "Wrapped Ether" },
195
+ { address: this.tokens.USDT, symbol: "USDT", decimals: 6, name: "Tether USD" },
196
+ { address: this.tokens.USDC, symbol: "USDC", decimals: 6, name: "USD Coin" }
197
+ ];
198
+ }
199
+ /**
200
+ * Get Uniswap router address for approvals
201
+ */
202
+ getRouterAddress() {
203
+ return this.addresses.swapRouter;
204
+ }
205
+ /**
206
+ * Calculate price impact (simplified)
207
+ */
208
+ calculatePriceImpact(amountIn, amountOut, _tokenIn, _tokenOut) {
209
+ if (amountIn === 0n || amountOut === 0n) return 0;
210
+ const expectedOut = amountIn;
211
+ const actualRatio = Number(amountOut) / Number(expectedOut);
212
+ const impact = (1 - actualRatio) * 100;
213
+ return Math.max(0, impact);
137
214
  }
138
215
  };
139
216