@kaspacom/swap-sdk 1.1.6 → 1.1.7

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.d.cts CHANGED
@@ -37,6 +37,10 @@ interface SwapSdkOptions {
37
37
  walletProvider?: Eip1193Provider;
38
38
  partnerKey?: string;
39
39
  onChange?: (state: SwapControllerOutput, patch: Partial<SwapControllerOutput>) => Promise<void>;
40
+ refreshPairsInterval?: number;
41
+ updateQuoteAfterRefreshPairs?: boolean;
42
+ getPairsData?: () => Promise<KaspaComSdkPair[]>;
43
+ swapServiceClass?: any;
40
44
  }
41
45
  interface SwapControllerInput {
42
46
  fromToken?: Erc20Token | null;
@@ -64,7 +68,11 @@ interface SwapControllerOutput {
64
68
  error?: string;
65
69
  txHash?: string;
66
70
  approveTxHash?: string;
71
+ /**
72
+ * @deprecated Use `computed` instead, The tradeInfo can contain incorrect information
73
+ */
67
74
  tradeInfo?: Trade<Currency, Currency, TradeType.EXACT_INPUT> | Trade<Currency, Currency, TradeType.EXACT_OUTPUT>;
75
+ path?: Token[];
68
76
  computed?: ComputedAmounts;
69
77
  loader: LoaderStatuses | null;
70
78
  }
@@ -81,6 +89,25 @@ interface SwapSdkNetworkConfig {
81
89
  nativeToken: Erc20Token;
82
90
  wrappedToken: Erc20Token;
83
91
  }
92
+ interface KaspaComSdkPair {
93
+ id: string;
94
+ token0: {
95
+ id: string;
96
+ symbol: string;
97
+ name: string;
98
+ decimals: string | number;
99
+ };
100
+ token1: {
101
+ id: string;
102
+ symbol: string;
103
+ name: string;
104
+ decimals: string | number;
105
+ };
106
+ reserve0: string;
107
+ reserve1: string;
108
+ positionValueUsd?: number;
109
+ totalTokens?: number;
110
+ }
84
111
 
85
112
  declare class WalletService {
86
113
  private networkProvider;
@@ -95,10 +122,10 @@ declare class WalletService {
95
122
  isConnected(): boolean;
96
123
  getAddress(): string | null;
97
124
  getProvider(): BrowserProvider | JsonRpcProvider | null;
125
+ destroy(): void;
98
126
  getSigner(): Signer | null;
99
127
  getCurrentChainId(): Promise<number>;
100
128
  connectWallet(): Promise<string>;
101
- disconnectWallet(): void;
102
129
  }
103
130
 
104
131
  declare class SwapService {
@@ -106,19 +133,22 @@ declare class SwapService {
106
133
  private swapOptions;
107
134
  private provider;
108
135
  private signer;
109
- private routerContract;
110
- private factoryContract;
111
- private proxyContract?;
112
- private wethAddress;
113
- private chainId;
114
- private pairs;
115
- private pairsLoadedPromise;
116
- private resolvePairsLoaded;
117
- private partnerFeeLoadedPromise;
118
- private resolvePartnerFeeLoaded;
119
- private partnerFee;
120
- private wethToken;
136
+ protected routerContract: Contract;
137
+ protected factoryContract: Contract;
138
+ protected proxyContract?: Contract;
139
+ protected chainId: number;
140
+ protected pairs: Pair[];
141
+ protected pairsLoadedPromise: Promise<void>;
142
+ protected resolvePairsLoaded: (() => void) | null;
143
+ protected rejectPairsLoaded: ((error: any) => void) | null;
144
+ protected partnerFeeLoadedPromise: Promise<void>;
145
+ protected resolvePartnerFeeLoaded: (() => void) | null;
146
+ protected rejectPartnerFeeLoaded: ((error: any) => void) | null;
147
+ protected partnerFee: bigint;
121
148
  constructor(provider: BrowserProvider | JsonRpcProvider, config: SwapSdkNetworkConfig, swapOptions: SwapSdkOptions);
149
+ protected get routerAbi(): string[];
150
+ protected get factoryAbi(): string[];
151
+ protected get proxyAbi(): string[];
122
152
  loadPartnerFee(): Promise<bigint>;
123
153
  setSigner(signer: Signer): void;
124
154
  /**
@@ -126,32 +156,16 @@ declare class SwapService {
126
156
  * to avoid parseUnits errors with too many decimals
127
157
  */
128
158
  private roundToDecimals;
159
+ refreshPairsFromGraph(): Promise<KaspaComSdkPair[]>;
160
+ refreshPairs(): Promise<void>;
129
161
  /**
130
162
  * Loads all pairs from The Graph and caches them as Uniswap SDK Pair instances.
131
163
  * @param graphEndpoint The GraphQL endpoint URL
132
164
  */
133
- loadAllPairsFromGraph(): Promise<void>;
165
+ protected loadAllPairs(): Promise<void>;
134
166
  waitForPairsLoaded(): Promise<void>;
135
167
  waitForPartnerFeeLoaded(): Promise<void>;
136
- createSDKPair(pair: {
137
- id: string;
138
- token0: {
139
- id: string;
140
- symbol: string;
141
- name: string;
142
- decimals: string | number;
143
- };
144
- token1: {
145
- id: string;
146
- symbol: string;
147
- name: string;
148
- decimals: string | number;
149
- };
150
- reserve0?: string;
151
- reserve1?: string;
152
- positionValueUsd?: number;
153
- totalTokens?: number;
154
- }): Pair;
168
+ createSDKPair(pair: KaspaComSdkPair): Pair;
155
169
  /**
156
170
  * Returns the cached pairs for use in routing.
157
171
  */
@@ -162,6 +176,8 @@ declare class SwapService {
162
176
  */
163
177
  private getBestTrade;
164
178
  private trimTrailingZeros;
179
+ protected getAmountsIn(sellAmountWei: bigint, pathAddresses: string[]): Promise<bigint>;
180
+ protected getAmountsOut(buyAmountWei: bigint, pathAddresses: string[]): Promise<bigint>;
165
181
  /**
166
182
  *
167
183
  * @param sellToken
@@ -207,6 +223,7 @@ declare const DEFAULT_SETTINGS: SwapSettings;
207
223
  declare class SwapSdkController {
208
224
  private walletService;
209
225
  private swapService;
226
+ private refreshPairsTimeout;
210
227
  private state;
211
228
  private input;
212
229
  private options;
@@ -225,6 +242,9 @@ declare class SwapSdkController {
225
242
  getPartnerFee(): Promise<number>;
226
243
  getTokensFromGraph(limit?: number, search?: string): Promise<Erc20Token[]>;
227
244
  get currentNetworkConfig(): SwapSdkNetworkConfig;
245
+ destroy(): Promise<void>;
246
+ refreshTokensAndUpdateQuote(forceQuoteUpdate?: boolean): Promise<void>;
247
+ private refreshTokensAndUpdateQuoteAndSetTimeout;
228
248
  }
229
249
 
230
250
  declare const NETWORKS: Record<string, SwapSdkNetworkConfig>;
@@ -236,4 +256,4 @@ declare const NETWORKS: Record<string, SwapSdkNetworkConfig>;
236
256
  */
237
257
  declare function createKaspaComSwapController(options: SwapSdkOptions): SwapSdkController;
238
258
 
239
- export { type ComputedAmounts, DEFAULT_SETTINGS as DEFAULT_SWAP_SETTINGS, type Erc20Token, LoaderStatuses, NETWORKS, type SwapControllerInput, type SwapControllerOutput, SwapSdkController, type SwapSdkNetworkConfig, type SwapSdkOptions, type SwapSectionData, SwapService, type SwapSettings, type SwapState, WalletService, createKaspaComSwapController };
259
+ export { type ComputedAmounts, DEFAULT_SETTINGS as DEFAULT_SWAP_SETTINGS, type Erc20Token, type KaspaComSdkPair, LoaderStatuses, NETWORKS, type SwapControllerInput, type SwapControllerOutput, SwapSdkController, type SwapSdkNetworkConfig, type SwapSdkOptions, type SwapSectionData, SwapService, type SwapSettings, type SwapState, WalletService, createKaspaComSwapController };
package/dist/index.d.ts CHANGED
@@ -37,6 +37,10 @@ interface SwapSdkOptions {
37
37
  walletProvider?: Eip1193Provider;
38
38
  partnerKey?: string;
39
39
  onChange?: (state: SwapControllerOutput, patch: Partial<SwapControllerOutput>) => Promise<void>;
40
+ refreshPairsInterval?: number;
41
+ updateQuoteAfterRefreshPairs?: boolean;
42
+ getPairsData?: () => Promise<KaspaComSdkPair[]>;
43
+ swapServiceClass?: any;
40
44
  }
41
45
  interface SwapControllerInput {
42
46
  fromToken?: Erc20Token | null;
@@ -64,7 +68,11 @@ interface SwapControllerOutput {
64
68
  error?: string;
65
69
  txHash?: string;
66
70
  approveTxHash?: string;
71
+ /**
72
+ * @deprecated Use `computed` instead, The tradeInfo can contain incorrect information
73
+ */
67
74
  tradeInfo?: Trade<Currency, Currency, TradeType.EXACT_INPUT> | Trade<Currency, Currency, TradeType.EXACT_OUTPUT>;
75
+ path?: Token[];
68
76
  computed?: ComputedAmounts;
69
77
  loader: LoaderStatuses | null;
70
78
  }
@@ -81,6 +89,25 @@ interface SwapSdkNetworkConfig {
81
89
  nativeToken: Erc20Token;
82
90
  wrappedToken: Erc20Token;
83
91
  }
92
+ interface KaspaComSdkPair {
93
+ id: string;
94
+ token0: {
95
+ id: string;
96
+ symbol: string;
97
+ name: string;
98
+ decimals: string | number;
99
+ };
100
+ token1: {
101
+ id: string;
102
+ symbol: string;
103
+ name: string;
104
+ decimals: string | number;
105
+ };
106
+ reserve0: string;
107
+ reserve1: string;
108
+ positionValueUsd?: number;
109
+ totalTokens?: number;
110
+ }
84
111
 
85
112
  declare class WalletService {
86
113
  private networkProvider;
@@ -95,10 +122,10 @@ declare class WalletService {
95
122
  isConnected(): boolean;
96
123
  getAddress(): string | null;
97
124
  getProvider(): BrowserProvider | JsonRpcProvider | null;
125
+ destroy(): void;
98
126
  getSigner(): Signer | null;
99
127
  getCurrentChainId(): Promise<number>;
100
128
  connectWallet(): Promise<string>;
101
- disconnectWallet(): void;
102
129
  }
103
130
 
104
131
  declare class SwapService {
@@ -106,19 +133,22 @@ declare class SwapService {
106
133
  private swapOptions;
107
134
  private provider;
108
135
  private signer;
109
- private routerContract;
110
- private factoryContract;
111
- private proxyContract?;
112
- private wethAddress;
113
- private chainId;
114
- private pairs;
115
- private pairsLoadedPromise;
116
- private resolvePairsLoaded;
117
- private partnerFeeLoadedPromise;
118
- private resolvePartnerFeeLoaded;
119
- private partnerFee;
120
- private wethToken;
136
+ protected routerContract: Contract;
137
+ protected factoryContract: Contract;
138
+ protected proxyContract?: Contract;
139
+ protected chainId: number;
140
+ protected pairs: Pair[];
141
+ protected pairsLoadedPromise: Promise<void>;
142
+ protected resolvePairsLoaded: (() => void) | null;
143
+ protected rejectPairsLoaded: ((error: any) => void) | null;
144
+ protected partnerFeeLoadedPromise: Promise<void>;
145
+ protected resolvePartnerFeeLoaded: (() => void) | null;
146
+ protected rejectPartnerFeeLoaded: ((error: any) => void) | null;
147
+ protected partnerFee: bigint;
121
148
  constructor(provider: BrowserProvider | JsonRpcProvider, config: SwapSdkNetworkConfig, swapOptions: SwapSdkOptions);
149
+ protected get routerAbi(): string[];
150
+ protected get factoryAbi(): string[];
151
+ protected get proxyAbi(): string[];
122
152
  loadPartnerFee(): Promise<bigint>;
123
153
  setSigner(signer: Signer): void;
124
154
  /**
@@ -126,32 +156,16 @@ declare class SwapService {
126
156
  * to avoid parseUnits errors with too many decimals
127
157
  */
128
158
  private roundToDecimals;
159
+ refreshPairsFromGraph(): Promise<KaspaComSdkPair[]>;
160
+ refreshPairs(): Promise<void>;
129
161
  /**
130
162
  * Loads all pairs from The Graph and caches them as Uniswap SDK Pair instances.
131
163
  * @param graphEndpoint The GraphQL endpoint URL
132
164
  */
133
- loadAllPairsFromGraph(): Promise<void>;
165
+ protected loadAllPairs(): Promise<void>;
134
166
  waitForPairsLoaded(): Promise<void>;
135
167
  waitForPartnerFeeLoaded(): Promise<void>;
136
- createSDKPair(pair: {
137
- id: string;
138
- token0: {
139
- id: string;
140
- symbol: string;
141
- name: string;
142
- decimals: string | number;
143
- };
144
- token1: {
145
- id: string;
146
- symbol: string;
147
- name: string;
148
- decimals: string | number;
149
- };
150
- reserve0?: string;
151
- reserve1?: string;
152
- positionValueUsd?: number;
153
- totalTokens?: number;
154
- }): Pair;
168
+ createSDKPair(pair: KaspaComSdkPair): Pair;
155
169
  /**
156
170
  * Returns the cached pairs for use in routing.
157
171
  */
@@ -162,6 +176,8 @@ declare class SwapService {
162
176
  */
163
177
  private getBestTrade;
164
178
  private trimTrailingZeros;
179
+ protected getAmountsIn(sellAmountWei: bigint, pathAddresses: string[]): Promise<bigint>;
180
+ protected getAmountsOut(buyAmountWei: bigint, pathAddresses: string[]): Promise<bigint>;
165
181
  /**
166
182
  *
167
183
  * @param sellToken
@@ -207,6 +223,7 @@ declare const DEFAULT_SETTINGS: SwapSettings;
207
223
  declare class SwapSdkController {
208
224
  private walletService;
209
225
  private swapService;
226
+ private refreshPairsTimeout;
210
227
  private state;
211
228
  private input;
212
229
  private options;
@@ -225,6 +242,9 @@ declare class SwapSdkController {
225
242
  getPartnerFee(): Promise<number>;
226
243
  getTokensFromGraph(limit?: number, search?: string): Promise<Erc20Token[]>;
227
244
  get currentNetworkConfig(): SwapSdkNetworkConfig;
245
+ destroy(): Promise<void>;
246
+ refreshTokensAndUpdateQuote(forceQuoteUpdate?: boolean): Promise<void>;
247
+ private refreshTokensAndUpdateQuoteAndSetTimeout;
228
248
  }
229
249
 
230
250
  declare const NETWORKS: Record<string, SwapSdkNetworkConfig>;
@@ -236,4 +256,4 @@ declare const NETWORKS: Record<string, SwapSdkNetworkConfig>;
236
256
  */
237
257
  declare function createKaspaComSwapController(options: SwapSdkOptions): SwapSdkController;
238
258
 
239
- export { type ComputedAmounts, DEFAULT_SETTINGS as DEFAULT_SWAP_SETTINGS, type Erc20Token, LoaderStatuses, NETWORKS, type SwapControllerInput, type SwapControllerOutput, SwapSdkController, type SwapSdkNetworkConfig, type SwapSdkOptions, type SwapSectionData, SwapService, type SwapSettings, type SwapState, WalletService, createKaspaComSwapController };
259
+ export { type ComputedAmounts, DEFAULT_SETTINGS as DEFAULT_SWAP_SETTINGS, type Erc20Token, type KaspaComSdkPair, LoaderStatuses, NETWORKS, type SwapControllerInput, type SwapControllerOutput, SwapSdkController, type SwapSdkNetworkConfig, type SwapSdkOptions, type SwapSectionData, SwapService, type SwapSettings, type SwapState, WalletService, createKaspaComSwapController };