@flashnet/sdk 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.
Files changed (50) hide show
  1. package/README.md +479 -0
  2. package/dist/index.d.ts +13 -0
  3. package/dist/index.d.ts.map +1 -0
  4. package/dist/index.js +15 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/src/api/client.d.ts +20 -0
  7. package/dist/src/api/client.d.ts.map +1 -0
  8. package/dist/src/api/client.js +85 -0
  9. package/dist/src/api/client.js.map +1 -0
  10. package/dist/src/api/typed-endpoints.d.ts +135 -0
  11. package/dist/src/api/typed-endpoints.d.ts.map +1 -0
  12. package/dist/src/api/typed-endpoints.js +202 -0
  13. package/dist/src/api/typed-endpoints.js.map +1 -0
  14. package/dist/src/api/validation.d.ts +114 -0
  15. package/dist/src/api/validation.d.ts.map +1 -0
  16. package/dist/src/api/validation.js +128 -0
  17. package/dist/src/api/validation.js.map +1 -0
  18. package/dist/src/client/FlashnetClient.d.ts +216 -0
  19. package/dist/src/client/FlashnetClient.d.ts.map +1 -0
  20. package/dist/src/client/FlashnetClient.js +800 -0
  21. package/dist/src/client/FlashnetClient.js.map +1 -0
  22. package/dist/src/config/index.d.ts +14 -0
  23. package/dist/src/config/index.d.ts.map +1 -0
  24. package/dist/src/config/index.js +40 -0
  25. package/dist/src/config/index.js.map +1 -0
  26. package/dist/src/types/index.d.ts +484 -0
  27. package/dist/src/types/index.d.ts.map +1 -0
  28. package/dist/src/types/index.js +2 -0
  29. package/dist/src/types/index.js.map +1 -0
  30. package/dist/src/utils/auth.d.ts +26 -0
  31. package/dist/src/utils/auth.d.ts.map +1 -0
  32. package/dist/src/utils/auth.js +85 -0
  33. package/dist/src/utils/auth.js.map +1 -0
  34. package/dist/src/utils/index.d.ts +8 -0
  35. package/dist/src/utils/index.d.ts.map +1 -0
  36. package/dist/src/utils/index.js +19 -0
  37. package/dist/src/utils/index.js.map +1 -0
  38. package/dist/src/utils/intents.d.ts +86 -0
  39. package/dist/src/utils/intents.d.ts.map +1 -0
  40. package/dist/src/utils/intents.js +133 -0
  41. package/dist/src/utils/intents.js.map +1 -0
  42. package/dist/src/utils/signer.d.ts +29 -0
  43. package/dist/src/utils/signer.d.ts.map +1 -0
  44. package/dist/src/utils/signer.js +34 -0
  45. package/dist/src/utils/signer.js.map +1 -0
  46. package/dist/src/utils/spark-address.d.ts +60 -0
  47. package/dist/src/utils/spark-address.d.ts.map +1 -0
  48. package/dist/src/utils/spark-address.js +227 -0
  49. package/dist/src/utils/spark-address.js.map +1 -0
  50. package/package.json +43 -0
@@ -0,0 +1,216 @@
1
+ import type { IssuerSparkWallet } from "@buildonspark/issuer-sdk";
2
+ import type { SparkWallet } from "@buildonspark/spark-sdk";
3
+ import type { NetworkType, ListPoolsQuery, ListPoolsResponse, PoolDetailsResponse, LpPositionDetailsResponse, SimulateSwapRequest, SimulateSwapResponse, SwapResponse, SimulateAddLiquidityRequest, SimulateAddLiquidityResponse, AddLiquidityResponse, SimulateRemoveLiquidityRequest, SimulateRemoveLiquidityResponse, RemoveLiquidityResponse, CreatePoolResponse, ConfirmDepositResponse, RegisterHostResponse, GetHostResponse, WithdrawHostFeesResponse, GetPoolHostFeesResponse, ListPoolSwapsQuery, ListPoolSwapsResponse, ListGlobalSwapsQuery, ListGlobalSwapsResponse, ListUserSwapsQuery, ListUserSwapsResponse, SettlementPingResponse } from "../types";
4
+ export interface TokenBalance {
5
+ balance: bigint;
6
+ tokenInfo?: {
7
+ tokenPublicKey: string;
8
+ tokenName: string;
9
+ tokenSymbol: string;
10
+ tokenDecimals: number;
11
+ maxSupply: bigint;
12
+ };
13
+ }
14
+ export interface WalletBalance {
15
+ balance: bigint;
16
+ tokenBalances: Map<string, TokenBalance>;
17
+ }
18
+ export interface FlashnetClientOptions {
19
+ autoAuthenticate?: boolean;
20
+ }
21
+ /**
22
+ * FlashnetClient - A comprehensive client for interacting with Flashnet AMM
23
+ *
24
+ * This client wraps a SparkWallet and provides:
25
+ * - Automatic network detection from the wallet
26
+ * - Automatic authentication
27
+ * - Balance checking before operations
28
+ * - All AMM operations (pools, swaps, liquidity, hosts)
29
+ * - Direct wallet access via client.wallet
30
+ */
31
+ export declare class FlashnetClient {
32
+ private _wallet;
33
+ private apiClient;
34
+ private typedApi;
35
+ private authManager;
36
+ private network;
37
+ private publicKey;
38
+ private sparkAddress;
39
+ private isAuthenticated;
40
+ /**
41
+ * Get the underlying wallet instance for direct wallet operations
42
+ */
43
+ get wallet(): IssuerSparkWallet | SparkWallet;
44
+ /**
45
+ * Get the network type
46
+ */
47
+ get networkType(): NetworkType;
48
+ /**
49
+ * Get the wallet's public key
50
+ */
51
+ get pubkey(): string;
52
+ /**
53
+ * Get the wallet's Spark address
54
+ */
55
+ get address(): string;
56
+ /**
57
+ * Create a new FlashnetClient instance
58
+ * @param wallet - The SparkWallet to use
59
+ * @param options - Client options
60
+ */
61
+ constructor(wallet: IssuerSparkWallet | SparkWallet, options?: FlashnetClientOptions);
62
+ /**
63
+ * Initialize the client by deducing network and authenticating
64
+ * This is called automatically on first use if not called manually
65
+ */
66
+ initialize(): Promise<void>;
67
+ /**
68
+ * Ensure the client is initialized
69
+ */
70
+ private ensureInitialized;
71
+ /**
72
+ * Get wallet balance including BTC and token balances
73
+ */
74
+ getBalance(): Promise<WalletBalance>;
75
+ /**
76
+ * Check if wallet has sufficient balance for an operation
77
+ */
78
+ private checkBalance;
79
+ /**
80
+ * List pools with optional filters
81
+ */
82
+ listPools(query?: ListPoolsQuery): Promise<ListPoolsResponse>;
83
+ /**
84
+ * Get detailed information about a specific pool
85
+ */
86
+ getPool(poolId: string): Promise<PoolDetailsResponse>;
87
+ /**
88
+ * Get LP position details for a provider in a pool
89
+ */
90
+ getLpPosition(poolId: string, providerPublicKey?: string): Promise<LpPositionDetailsResponse>;
91
+ /**
92
+ * Create a constant product pool
93
+ */
94
+ createConstantProductPool(params: {
95
+ assetATokenPublicKey: string;
96
+ assetBTokenPublicKey: string;
97
+ lpFeeRateBps: number;
98
+ totalHostFeeRateBps: number;
99
+ integratorNamespace?: string;
100
+ initialLiquidity?: {
101
+ assetAAmount: bigint;
102
+ assetBAmount: bigint;
103
+ };
104
+ }): Promise<CreatePoolResponse>;
105
+ /**
106
+ * Create a single-sided pool with automatic initial deposit
107
+ *
108
+ * This method creates a single-sided pool and automatically handles the initial deposit.
109
+ * The initial reserve amount will be transferred to the pool and confirmed.
110
+ */
111
+ createSingleSidedPool(params: {
112
+ assetATokenPublicKey: string;
113
+ assetBTokenPublicKey: string;
114
+ assetAInitialReserve: string;
115
+ assetAInitialVirtualReserve: string;
116
+ assetBInitialVirtualReserve: string;
117
+ threshold: string;
118
+ lpFeeRateBps: number;
119
+ totalHostFeeRateBps: number;
120
+ hostNamespace?: string;
121
+ }): Promise<CreatePoolResponse>;
122
+ /**
123
+ * Confirm initial deposit for single-sided pool
124
+ *
125
+ * Note: This is typically handled automatically by createSingleSidedPool().
126
+ * Use this method only if you need to manually confirm a deposit (e.g., after a failed attempt).
127
+ */
128
+ confirmInitialDeposit(poolId: string, assetASparkTransferId: string): Promise<ConfirmDepositResponse>;
129
+ /**
130
+ * Simulate a swap without executing it
131
+ */
132
+ simulateSwap(params: SimulateSwapRequest): Promise<SimulateSwapResponse>;
133
+ /**
134
+ * Execute a swap
135
+ */
136
+ executeSwap(params: {
137
+ poolId: string;
138
+ assetInTokenPublicKey: string;
139
+ assetOutTokenPublicKey: string;
140
+ amountIn: bigint;
141
+ minAmountOut: bigint;
142
+ maxSlippageBps: number;
143
+ }): Promise<SwapResponse>;
144
+ /**
145
+ * Simulate adding liquidity
146
+ */
147
+ simulateAddLiquidity(params: SimulateAddLiquidityRequest): Promise<SimulateAddLiquidityResponse>;
148
+ /**
149
+ * Add liquidity to a pool
150
+ */
151
+ addLiquidity(params: {
152
+ poolId: string;
153
+ assetAAmount: bigint;
154
+ assetBAmount: bigint;
155
+ }): Promise<AddLiquidityResponse>;
156
+ /**
157
+ * Simulate removing liquidity
158
+ */
159
+ simulateRemoveLiquidity(params: SimulateRemoveLiquidityRequest): Promise<SimulateRemoveLiquidityResponse>;
160
+ /**
161
+ * Remove liquidity from a pool
162
+ */
163
+ removeLiquidity(params: {
164
+ poolId: string;
165
+ lpTokensToRemove: string;
166
+ }): Promise<RemoveLiquidityResponse>;
167
+ /**
168
+ * Register as a host
169
+ */
170
+ registerHost(params: {
171
+ namespace: string;
172
+ minFeeBps: number;
173
+ feeRecipientPublicKey?: string;
174
+ }): Promise<RegisterHostResponse>;
175
+ /**
176
+ * Get host information
177
+ */
178
+ getHost(namespace: string): Promise<GetHostResponse>;
179
+ /**
180
+ * Get pool host fees
181
+ */
182
+ getPoolHostFees(hostNamespace: string, poolId: string): Promise<GetPoolHostFeesResponse>;
183
+ /**
184
+ * Withdraw host fees
185
+ */
186
+ withdrawHostFees(params: {
187
+ lpIdentityPublicKey: string;
188
+ assetAAmount?: string;
189
+ assetBAmount?: string;
190
+ }): Promise<WithdrawHostFeesResponse>;
191
+ /**
192
+ * Get swaps for a specific pool
193
+ */
194
+ getPoolSwaps(lpPubkey: string, query?: ListPoolSwapsQuery): Promise<ListPoolSwapsResponse>;
195
+ /**
196
+ * Get global swaps across all pools
197
+ */
198
+ getGlobalSwaps(query?: ListGlobalSwapsQuery): Promise<ListGlobalSwapsResponse>;
199
+ /**
200
+ * Get swaps for a specific user
201
+ */
202
+ getUserSwaps(userPublicKey?: string, query?: ListUserSwapsQuery): Promise<ListUserSwapsResponse>;
203
+ /**
204
+ * Ping the settlement service
205
+ */
206
+ ping(): Promise<SettlementPingResponse>;
207
+ /**
208
+ * Helper method to add initial liquidity after pool creation
209
+ */
210
+ private addInitialLiquidity;
211
+ /**
212
+ * Clean up wallet connections
213
+ */
214
+ cleanup(): Promise<void>;
215
+ }
216
+ //# sourceMappingURL=FlashnetClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FlashnetClient.d.ts","sourceRoot":"","sources":["../../../src/client/FlashnetClient.ts"],"names":[],"m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