@zucchinifi/dapp-sdk 0.1.0 → 0.1.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.
package/dist/index.mjs CHANGED
@@ -605,6 +605,90 @@ async function generateQRCode(text, options = {}) {
605
605
 
606
606
  // src/index.ts
607
607
  var ZucchiniSDK = class {
608
+ constructor(config) {
609
+ this._apiUrl = "https://api.zucchinifi.xyz";
610
+ this.swap = {
611
+ getQuote: async (args) => {
612
+ const { from, to, amount, recipient, refundAddress, dry } = args;
613
+ const params = new URLSearchParams({
614
+ from,
615
+ to,
616
+ amount,
617
+ recipient: recipient || "0x0000000000000000000000000000000000000000",
618
+ refundAddress: refundAddress || "0x0000000000000000000000000000000000000000",
619
+ dry: dry !== void 0 ? dry.toString() : "true"
620
+ });
621
+ const res = await fetch(`${this.apiUrl}/swap/quote?${params.toString()}`);
622
+ const data = await res.json();
623
+ if (data.error) {
624
+ throw new Error(data.error);
625
+ }
626
+ const quote = data.quote;
627
+ return {
628
+ ...quote,
629
+ deadline: quote.deadline || data.quoteRequest?.deadline
630
+ };
631
+ },
632
+ submitDepositHash: async (args) => {
633
+ const res = await fetch(`${this.apiUrl}/swap/submit-deposit`, {
634
+ method: "POST",
635
+ headers: { "Content-Type": "application/json" },
636
+ body: JSON.stringify(args)
637
+ });
638
+ const data = await res.json();
639
+ if (data.error) throw new Error(data.error);
640
+ return data;
641
+ },
642
+ getStatus: async (depositAddress, memo) => {
643
+ const params = new URLSearchParams({ depositAddress });
644
+ if (memo) params.append("memo", memo);
645
+ const res = await fetch(`${this.apiUrl}/swap/status?${params.toString()}`);
646
+ const data = await res.json();
647
+ if (data.error) throw new Error(data.error);
648
+ return data;
649
+ },
650
+ getWithdrawals: async (depositAddress, options = {}) => {
651
+ const params = new URLSearchParams({ depositAddress });
652
+ if (options.memo) params.append("memo", options.memo);
653
+ if (options.timestampFrom) params.append("timestampFrom", options.timestampFrom);
654
+ if (options.page) params.append("page", options.page.toString());
655
+ if (options.limit) params.append("limit", options.limit.toString());
656
+ if (options.sortOrder) params.append("sortOrder", options.sortOrder);
657
+ const res = await fetch(`${this.apiUrl}/swap/withdrawals?${params.toString()}`);
658
+ const data = await res.json();
659
+ if (data.error) throw new Error(data.error);
660
+ return data;
661
+ }
662
+ };
663
+ this.explorer = {
664
+ getTransactions: async (params = {}) => {
665
+ const searchParams = new URLSearchParams();
666
+ Object.entries(params).forEach(([key, value]) => {
667
+ if (value !== void 0 && value !== null) searchParams.append(key, value.toString());
668
+ });
669
+ const res = await fetch(`${this.apiUrl}/explorer/transactions?${searchParams.toString()}`);
670
+ const data = await res.json();
671
+ if (data.error) throw new Error(data.error);
672
+ return data;
673
+ }
674
+ };
675
+ if (config) {
676
+ this.configure(config);
677
+ }
678
+ }
679
+ /**
680
+ * Configure the SDK at runtime.
681
+ */
682
+ configure(config) {
683
+ if (config.apiUrl) {
684
+ this._apiUrl = config.apiUrl;
685
+ } else if (config.dev) {
686
+ this._apiUrl = "http://localhost:3001";
687
+ }
688
+ }
689
+ get apiUrl() {
690
+ return this._apiUrl;
691
+ }
608
692
  /**
609
693
  * Check if the Zucchini extension is installed and the provider is injected.
610
694
  */
@@ -686,29 +770,10 @@ var ZucchiniSDK = class {
686
770
  return this.request({ method: "getWalletStatus" });
687
771
  }
688
772
  async getTokens() {
689
- const API_BASE_URL = "https://api.zucchinifi.xyz";
690
- const res = await fetch(`${API_BASE_URL}/tokens`);
773
+ const res = await fetch(`${this.apiUrl}/tokens`);
691
774
  if (!res.ok) throw new Error("Failed to fetch tokens");
692
775
  return res.json();
693
776
  }
694
- async getSwapQuote(args) {
695
- const API_BASE_URL = "https://api.zucchinifi.xyz";
696
- const { from, to, amount, recipient, refundAddress } = args;
697
- const params = new URLSearchParams({
698
- from,
699
- to,
700
- amount,
701
- recipient: recipient || "0x0000000000000000000000000000000000000000",
702
- refundAddress: refundAddress || "0x0000000000000000000000000000000000000000",
703
- dry: "true"
704
- });
705
- const res = await fetch(`${API_BASE_URL}/swap/quote?${params.toString()}`);
706
- const data = await res.json();
707
- if (data.error) {
708
- throw new Error(data.error);
709
- }
710
- return data.quote;
711
- }
712
777
  };
713
778
  var zucchini = new ZucchiniSDK();
714
779
  export {
package/dist/types.d.ts CHANGED
@@ -56,24 +56,21 @@ export interface DetailedKey {
56
56
  }
57
57
  export interface Token {
58
58
  symbol: string;
59
- name: string;
60
- icon: string;
59
+ assetId: string;
61
60
  decimals: number;
62
- assetId?: string;
61
+ blockchain: string;
62
+ price?: string;
63
+ name?: string;
64
+ icon?: string;
63
65
  }
64
66
  export interface SwapQuote {
65
- quote: {
66
- amountOutFormatted: string;
67
- amountIn: string;
68
- amountOut: string;
69
- depositAddress?: string;
70
- depositMemo?: string;
71
- timeEstimate: number;
72
- };
73
- quoteRequest: {
74
- deadline: string;
75
- };
67
+ amountOutFormatted: string;
68
+ amountIn: string;
69
+ amountOut: string;
76
70
  depositAddress?: string;
71
+ depositMemo?: string;
72
+ timeEstimate: number;
73
+ deadline?: string;
77
74
  }
78
75
  export interface QuoteRequestArgs {
79
76
  from: string;
@@ -81,6 +78,35 @@ export interface QuoteRequestArgs {
81
78
  amount: string;
82
79
  recipient?: string;
83
80
  refundAddress?: string;
81
+ dry?: boolean;
82
+ }
83
+ export interface DepositSubmitArgs {
84
+ transactionHash: string;
85
+ depositAddress: string;
86
+ memo?: string;
87
+ userAccount?: string;
88
+ }
89
+ export interface SwapStatus {
90
+ status: 'KNOWN_DEPOSIT_TX' | 'PENDING_DEPOSIT' | 'INCOMPLETE_DEPOSIT' | 'PROCESSING' | 'SUCCESS' | 'REFUNDED' | 'FAILED';
91
+ depositAddress: string;
92
+ depositMemo?: string;
93
+ swaps?: any[];
94
+ }
95
+ export interface Withdrawal {
96
+ id: string;
97
+ status: string;
98
+ amount: string;
99
+ assetId: string;
100
+ timestamp: string;
101
+ }
102
+ export interface ExplorerTransaction {
103
+ depositAddressAndMemo: string;
104
+ status: string;
105
+ originAsset: string;
106
+ destinationAsset: string;
107
+ amountIn: string;
108
+ amountOut: string;
109
+ timestamp: string;
84
110
  }
85
111
  declare global {
86
112
  interface Window {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@zucchinifi/dapp-sdk",
3
- "version": "0.1.0",
4
- "description": "TypeScript SDK for Zucchini Wallet",
3
+ "version": "0.1.1",
4
+ "description": "TypeScript SDK for Zcash self-custody browser wallet Zucchini",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
7
7
  "types": "dist/index.d.ts",