@bitflowlabs/core-sdk 1.0.0

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 (78) hide show
  1. package/README.md +205 -0
  2. package/dist/src/BitflowSDK.d.ts +14 -0
  3. package/dist/src/BitflowSDK.js +275 -0
  4. package/dist/src/BitflowSDK.js.map +1 -0
  5. package/dist/src/config.d.ts +3 -0
  6. package/dist/src/config.js +20 -0
  7. package/dist/src/config.js.map +1 -0
  8. package/dist/src/helpers/callGetSwapParams.d.ts +2 -0
  9. package/dist/src/helpers/callGetSwapParams.js +85 -0
  10. package/dist/src/helpers/callGetSwapParams.js.map +1 -0
  11. package/dist/src/helpers/callReadOnlyHelper.d.ts +8 -0
  12. package/dist/src/helpers/callReadOnlyHelper.js +191 -0
  13. package/dist/src/helpers/callReadOnlyHelper.js.map +1 -0
  14. package/dist/src/helpers/callSwapHelper.d.ts +9 -0
  15. package/dist/src/helpers/callSwapHelper.js +41 -0
  16. package/dist/src/helpers/callSwapHelper.js.map +1 -0
  17. package/dist/src/helpers/constructFunctionArgs.d.ts +1 -0
  18. package/dist/src/helpers/constructFunctionArgs.js +22 -0
  19. package/dist/src/helpers/constructFunctionArgs.js.map +1 -0
  20. package/dist/src/helpers/convertValuesHelper.d.ts +2 -0
  21. package/dist/src/helpers/convertValuesHelper.js +181 -0
  22. package/dist/src/helpers/convertValuesHelper.js.map +1 -0
  23. package/dist/src/helpers/fetchContractInterfaceHelper.d.ts +1 -0
  24. package/dist/src/helpers/fetchContractInterfaceHelper.js +20 -0
  25. package/dist/src/helpers/fetchContractInterfaceHelper.js.map +1 -0
  26. package/dist/src/helpers/fetchDataHelper.d.ts +2 -0
  27. package/dist/src/helpers/fetchDataHelper.js +44 -0
  28. package/dist/src/helpers/fetchDataHelper.js.map +1 -0
  29. package/dist/src/helpers/fetchPossibleSwap.d.ts +2 -0
  30. package/dist/src/helpers/fetchPossibleSwap.js +20 -0
  31. package/dist/src/helpers/fetchPossibleSwap.js.map +1 -0
  32. package/dist/src/helpers/getContractInterfaceAndFunction.d.ts +4 -0
  33. package/dist/src/helpers/getContractInterfaceAndFunction.js +15 -0
  34. package/dist/src/helpers/getContractInterfaceAndFunction.js.map +1 -0
  35. package/dist/src/helpers/getFunctionArgs.d.ts +1 -0
  36. package/dist/src/helpers/getFunctionArgs.js +12 -0
  37. package/dist/src/helpers/getFunctionArgs.js.map +1 -0
  38. package/dist/src/helpers/getTokenDecimalsHelper.d.ts +5 -0
  39. package/dist/src/helpers/getTokenDecimalsHelper.js +28 -0
  40. package/dist/src/helpers/getTokenDecimalsHelper.js.map +1 -0
  41. package/dist/src/helpers/getTokenNameHelper.d.ts +2 -0
  42. package/dist/src/helpers/getTokenNameHelper.js +22 -0
  43. package/dist/src/helpers/getTokenNameHelper.js.map +1 -0
  44. package/dist/src/helpers/handleResultHelper.d.ts +4 -0
  45. package/dist/src/helpers/handleResultHelper.js +80 -0
  46. package/dist/src/helpers/handleResultHelper.js.map +1 -0
  47. package/dist/src/helpers/postConditionsHelper.d.ts +2 -0
  48. package/dist/src/helpers/postConditionsHelper.js +135 -0
  49. package/dist/src/helpers/postConditionsHelper.js.map +1 -0
  50. package/dist/src/index.d.ts +2 -0
  51. package/dist/src/index.js +8 -0
  52. package/dist/src/index.js.map +1 -0
  53. package/dist/src/test/testMethods.d.ts +1 -0
  54. package/dist/src/test/testMethods.js +178 -0
  55. package/dist/src/test/testMethods.js.map +1 -0
  56. package/dist/src/types.d.ts +126 -0
  57. package/dist/src/types.js +3 -0
  58. package/dist/src/types.js.map +1 -0
  59. package/package.json +57 -0
  60. package/src/BitflowSDK.ts +385 -0
  61. package/src/config.ts +22 -0
  62. package/src/helpers/callGetSwapParams.ts +122 -0
  63. package/src/helpers/callReadOnlyHelper.ts +243 -0
  64. package/src/helpers/callSwapHelper.ts +53 -0
  65. package/src/helpers/constructFunctionArgs.ts +24 -0
  66. package/src/helpers/convertValuesHelper.ts +214 -0
  67. package/src/helpers/fetchContractInterfaceHelper.ts +19 -0
  68. package/src/helpers/fetchDataHelper.ts +41 -0
  69. package/src/helpers/fetchPossibleSwap.ts +18 -0
  70. package/src/helpers/getContractInterfaceAndFunction.ts +20 -0
  71. package/src/helpers/getFunctionArgs.ts +12 -0
  72. package/src/helpers/getTokenDecimalsHelper.ts +33 -0
  73. package/src/helpers/getTokenNameHelper.ts +26 -0
  74. package/src/helpers/handleResultHelper.ts +85 -0
  75. package/src/helpers/postConditionsHelper.ts +246 -0
  76. package/src/index.ts +2 -0
  77. package/src/test/testMethods.ts +227 -0
  78. package/src/types.ts +137 -0
package/README.md ADDED
@@ -0,0 +1,205 @@
1
+ # Bitflow SDK
2
+
3
+ Bitflow SDK is a powerful and easy-to-use library for interacting with the Bitflow Protocol. It provides a set of tools to seamlessly integrate Bitflow functionality into your applications. Currently, the SDK is available by request only. If you are interested in integrating with the BitFlow SDK please reach out to the team on [Discord](https://discord.gg/DY4yNyHyhT).
4
+
5
+ # Table of Contents
6
+
7
+ - [Bitflow SDK](#bitflow-sdk)
8
+ - [Table of Contents](#table-of-contents)
9
+ - [Installation](#installation)
10
+ - [Configuration](#configuration)
11
+ - [Usage](#usage)
12
+ - [Available Functions](#available-functions)
13
+ - [Get Available Tokens](#get-available-tokens)
14
+ - [Get Possible Swaps](#get-possible-swaps)
15
+ - [Get All Possible Token Y](#get-all-possible-token-y)
16
+ - [Get All Possible Token Y Routes](#get-all-possible-token-y-routes)
17
+ - [Getting Quote for Route](#getting-quote-for-route)
18
+ - [Getting Swap Parameters](#getting-swap-parameters)
19
+ - [Executing Swap (uses `@stacks/connect`)](#executing-swap-uses-stacksconnect)
20
+ - [Types](#types)
21
+ - [Troubleshooting](#troubleshooting)
22
+ - [License](#license)
23
+
24
+ # Installation
25
+
26
+ Install the Bitflow SDK using npm:
27
+
28
+ ```bash
29
+ npm install bitflow-sdk
30
+ ```
31
+
32
+ **Latest Stable Version is 1.6.1**
33
+
34
+ # Configuration
35
+
36
+ Before using the Bitflow SDK, you need to set up your environment variables. Create a `.env` file in your project root with the following variables:
37
+
38
+ ```bash
39
+ # will be provided by Bitflow
40
+ BITFLOW_API_HOST=https://example-api-host.com
41
+ # will be provided by Bitflow
42
+ BITFLOW_API_KEY=<your_api_key_here>
43
+ # will be provided by Bitflow
44
+ READONLY_CALL_API_HOST=https://example-readonly-api.com
45
+ ```
46
+
47
+ # Usage
48
+
49
+ Here's a step-by-step guide to implement the Bitflow SDK in your project:
50
+
51
+ 1. Import the SDK:
52
+
53
+ ```ts
54
+ import { BitflowSDK } from 'bitflow-sdk';
55
+ ```
56
+
57
+ 2. Initialize the SDK:
58
+
59
+ ```ts
60
+ // if no parameters are provided, the SDK will try to use the environment variables
61
+ const bitflow = new BitflowSDK({
62
+ BITFLOW_API_HOST: string,
63
+ BITFLOW_API_KEY: string,
64
+ READONLY_CALL_API_HOST: string
65
+ });
66
+ ```
67
+
68
+ 3. Use the SDK methods to interact with the Bitflow Protocol. Here are some common operations:
69
+
70
+ # Available Functions
71
+
72
+ ## Get Available Tokens
73
+
74
+ Retrieve a list of all available tokens:
75
+
76
+ ```ts
77
+ const tokens = await bitflow.getAvailableTokens();
78
+ console.log(tokens);
79
+ ```
80
+
81
+ ## Get Possible Swaps
82
+
83
+ Get all possible swap options for a given token:
84
+
85
+ ```ts
86
+ const tokenXId = 'token-stx'; // the `tokenId` prop from `Token` interface
87
+ const swapOptions = await bitflow.getPossibleSwaps(tokenXId);
88
+ console.log(swapOptions);
89
+ ```
90
+
91
+ ## Get All Possible Token Y
92
+
93
+ Retrieve all possible tokens that can be swapped for a given token:
94
+
95
+ ```ts
96
+ const tokenXId = 'token-stx';
97
+ const possibleTokens = await bitflow.getAllPossibleTokenY(tokenXId);
98
+ console.log(possibleTokens);
99
+ ```
100
+
101
+ ## Get All Possible Token Y Routes
102
+
103
+ Get all possible routes for swapping between two tokens:
104
+
105
+ ```ts
106
+ const tokenXId = 'token-usda';
107
+ const tokenYId = 'token-stx';
108
+ const routes = await bitflow.getAllPossibleTokenYRoutes(tokenXId, tokenYId);
109
+ console.log(routes);
110
+ ```
111
+
112
+ ## Getting Quote for Route
113
+
114
+ Get the quotes for a swap between two tokens:
115
+
116
+ ```ts
117
+ const tokenXId = 'token-usda';
118
+ const tokenYId = 'token-stx';
119
+ const amount = 100; // Amount of tokenX to swap
120
+ const quoteResult = await bitflow.getQuoteForRoute(tokenXId, tokenYId, amount);
121
+ console.log(quoteResult);
122
+ ```
123
+
124
+ ## Getting Swap Parameters
125
+
126
+ Get the necessary parameters for signing a swap transaction:
127
+
128
+ ```ts
129
+ const swapExecutionData = {
130
+ route: selectedRoute,
131
+ amount: 100,
132
+ tokenXDecimals: selectedRoute.tokenXDecimals,
133
+ tokenYDecimals: selectedRoute.tokenYDecimals,
134
+ };
135
+ const senderAddress = 'your_stacks_address';
136
+ const slippageTolerance = 0.01; // 1%
137
+
138
+ const swapParams = await bitflow.getSwapParams(
139
+ swapExecutionData,
140
+ senderAddress,
141
+ slippageTolerance
142
+ );
143
+ console.log(swapParams);
144
+ ```
145
+
146
+ ## Executing Swap (uses `@stacks/connect`)
147
+
148
+ This function uses the `@stacks/connect` library to execute a swap transaction:
149
+
150
+ ```ts
151
+ const swapExecutionData = {
152
+ route: selectedRoute,
153
+ amount: 100,
154
+ tokenXDecimals: selectedRoute.tokenXDecimals,
155
+ tokenYDecimals: selectedRoute.tokenYDecimals,
156
+ };
157
+ const senderAddress = 'your_stacks_address';
158
+ const slippageTolerance = 0.01; // 1%
159
+
160
+ await bitflow.executeSwap(
161
+ swapExecutionData,
162
+ senderAddress,
163
+ slippageTolerance,
164
+ stacksProvider, // a valid object of type `StacksProvider` from `@stacks/connect`
165
+ (data) => console.log('Swap executed:', data),
166
+ () => console.log('Swap cancelled')
167
+ );
168
+ ```
169
+
170
+ # Types
171
+
172
+ The SDK exports several TypeScript types that you can use in your application:
173
+
174
+ - **BitflowSDKConfig:** Represents the configuration object for the Bitflow SDK.
175
+ - **Token:** Represents a token with its properties.
176
+ - **SwapOptions:** Represents possible swap options for a token.
177
+ - **PostConditionType:** Represents the type of a post-condition used in transactions.
178
+ - **SelectedSwapRoute:** Represents a selected swap route with its details.
179
+ - **RouteQuote:** Represents the quote for a swap route.
180
+ - **QuoteResult:** Represents the result of a quote request, including the best `RouteQuote` and all possible routes.
181
+ - **SwapExecutionData:** Represents the data needed to execute a swap.
182
+ - **SwapDataParamsAndPostConditions:** Represents the parameters and post-conditions needed to execute/sign a swap transaction.
183
+
184
+ ```ts
185
+ import {
186
+ Token,
187
+ SwapOptions,
188
+ SelectedSwapRoute,
189
+ QuoteResult,
190
+ SwapExecutionData,
191
+ SwapDataParamsAndPostConditions,
192
+ } from 'bitflow-sdk';
193
+ ```
194
+
195
+ # Troubleshooting
196
+
197
+ If you encounter any issues while using the Bitflow SDK, please check the following:
198
+
199
+ 1. Ensure all environment variables are correctly set in your .env file.
200
+ 2. Make sure you have the latest version of the SDK installed.
201
+ 3. Check that you're using a valid Stacks address for the senderAddress parameter.
202
+
203
+ # License
204
+
205
+ This project is licensed under the MIT License - see the LICENSE file for details.
@@ -0,0 +1,14 @@
1
+ import { StacksProvider } from '@stacks/connect';
2
+ import { Token, SwapOptions, SelectedSwapRoute, QuoteResult, SwapExecutionData, SwapDataParamsAndPostConditions, BitflowSDKConfig } from './types';
3
+ export declare class BitflowSDK {
4
+ private context;
5
+ constructor(config?: Partial<BitflowSDKConfig>);
6
+ private initializeContext;
7
+ getAvailableTokens(): Promise<Token[]>;
8
+ getPossibleSwaps(tokenX: string): Promise<SwapOptions>;
9
+ getAllPossibleTokenY(tokenX: string): Promise<string[]>;
10
+ getAllPossibleTokenYRoutes(tokenX: string, tokenY: string): Promise<SelectedSwapRoute[]>;
11
+ getQuoteForRoute(tokenX: string, tokenY: string, amountInput: number): Promise<QuoteResult>;
12
+ getSwapParams(swapExecutionData: SwapExecutionData, senderAddress: string, slippageTolerance?: number): Promise<SwapDataParamsAndPostConditions>;
13
+ executeSwap(swapExecutionData: SwapExecutionData, senderAddress: string, slippageTolerance?: number, stacksProvider?: StacksProvider, onFinish?: (data: any) => void, onCancel?: () => void): Promise<void>;
14
+ }
@@ -0,0 +1,275 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BitflowSDK = void 0;
4
+ const network_1 = require("@stacks/network");
5
+ const fetchDataHelper_1 = require("./helpers/fetchDataHelper");
6
+ const callSwapHelper_1 = require("./helpers/callSwapHelper");
7
+ const callReadOnlyHelper_1 = require("./helpers/callReadOnlyHelper");
8
+ const fetchPossibleSwap_1 = require("./helpers/fetchPossibleSwap");
9
+ const getContractInterfaceAndFunction_1 = require("./helpers/getContractInterfaceAndFunction");
10
+ const config_1 = require("./config");
11
+ const callGetSwapParams_1 = require("./helpers/callGetSwapParams");
12
+ class BitflowSDK {
13
+ constructor(config) {
14
+ if (config)
15
+ Object.assign(config_1.configs, config);
16
+ (0, config_1.validateConfig)();
17
+ this.context = {
18
+ availableTokens: [],
19
+ contractInterfaces: {},
20
+ functionArgs: {},
21
+ network: new network_1.StacksMainnet(),
22
+ swapOptions: {},
23
+ };
24
+ this.initializeContext();
25
+ }
26
+ async initializeContext() {
27
+ this.context.availableTokens = await (0, fetchDataHelper_1.fetchAllTokensFromAPI)();
28
+ }
29
+ async getAvailableTokens() {
30
+ if (this.context.availableTokens.length === 0) {
31
+ await this.initializeContext();
32
+ }
33
+ return this.context.availableTokens;
34
+ }
35
+ async getPossibleSwaps(tokenX) {
36
+ if (!this.context.swapOptions[tokenX]) {
37
+ this.context.swapOptions[tokenX] = await (0, fetchPossibleSwap_1.fetchPossibleSwapsFromAPI)(tokenX);
38
+ }
39
+ return this.context.swapOptions[tokenX];
40
+ }
41
+ async getAllPossibleTokenY(tokenX) {
42
+ const swapOptions = await this.getPossibleSwaps(tokenX);
43
+ return Object.keys(swapOptions);
44
+ }
45
+ async getAllPossibleTokenYRoutes(tokenX, tokenY) {
46
+ const swapOptions = await this.getPossibleSwaps(tokenX);
47
+ return swapOptions[tokenY] || [];
48
+ }
49
+ async getQuoteForRoute(tokenX, tokenY, amountInput) {
50
+ var _a;
51
+ const routes = await this.getAllPossibleTokenYRoutes(tokenX, tokenY);
52
+ const allRoutes = [];
53
+ for (let routeIndex = 0; routeIndex < routes.length; routeIndex++) {
54
+ const route = routes[routeIndex];
55
+ try {
56
+ // Check if quoteData is null or undefined
57
+ if (!route.quoteData) {
58
+ console.warn(`Skipping route ${routeIndex + 1} due to null quoteData:`, route);
59
+ continue;
60
+ }
61
+ const { contract, function: functionName, parameters, } = route.quoteData;
62
+ // Check if any required property is missing
63
+ if (!contract || !functionName || !parameters) {
64
+ console.warn(`Skipping route ${routeIndex + 1} due to missing required properties:`, route.quoteData);
65
+ continue;
66
+ }
67
+ const [contractDeployer, contractName] = contract.split('.');
68
+ if (!this.context.contractInterfaces[contract]) {
69
+ this.context.contractInterfaces[contract] =
70
+ await (0, getContractInterfaceAndFunction_1.getContractInterfaceAndFunction)(contractDeployer, contractName, functionName);
71
+ }
72
+ const { interface: contractInterface, functionArgs } = this.context.contractInterfaces[contract];
73
+ const params = { ...parameters };
74
+ if ('dx' in params && params.dx === null) {
75
+ params.dx = amountInput;
76
+ }
77
+ else if ('dy' in params && params.dy === null) {
78
+ params.dy = amountInput;
79
+ }
80
+ else if ('amount' in params && params.amount === null) {
81
+ params.amount = amountInput;
82
+ }
83
+ else if ('amt-in' in params && params['amt-in'] === null) {
84
+ params['amt-in'] = amountInput;
85
+ }
86
+ else if ('amt-in-max' in params && params['amt-in-max'] === null) {
87
+ params['amt-in-max'] = amountInput;
88
+ }
89
+ else if ('y-amount' in params && params['y-amount'] === null) {
90
+ params['y-amount'] = amountInput;
91
+ params['x-amount'] = amountInput;
92
+ }
93
+ else if ('x-amount' in params && params['x-amount'] === null) {
94
+ params['x-amount'] = amountInput;
95
+ }
96
+ else {
97
+ params.dx = amountInput;
98
+ }
99
+ const { convertedResult, rawResult, tokenXDecimals, tokenYDecimals } = await (0, callReadOnlyHelper_1.callReadOnlyFunctionHelper)(contractDeployer, contractName, functionName, params, contractDeployer, tokenX, tokenY, route.swapData, this.context);
100
+ if (typeof convertedResult === 'number' && convertedResult > 0) {
101
+ const updatedQuoteData = {
102
+ ...route.quoteData,
103
+ parameters: { ...params },
104
+ };
105
+ const updatedSwapData = {
106
+ ...route.swapData,
107
+ parameters: {
108
+ ...route.swapData.parameters,
109
+ amount: params.amount ||
110
+ params.dx ||
111
+ params['amt-in'] ||
112
+ params['amt-in-max'] ||
113
+ params['y-amount'] ||
114
+ params['x-amount'] ||
115
+ params.dy,
116
+ dx: params.amount ||
117
+ params.dx ||
118
+ params['amt-in'] ||
119
+ params['amt-in-max'] ||
120
+ params['y-amount'] ||
121
+ params['x-amount'] ||
122
+ params.dy,
123
+ dy: params.amount ||
124
+ params.dx ||
125
+ params['amt-in'] ||
126
+ params['amt-in-max'] ||
127
+ params['y-amount'] ||
128
+ params['x-amount'] ||
129
+ params.dy,
130
+ 'amt-in': params.amount ||
131
+ params.dx ||
132
+ params['amt-in'] ||
133
+ params['amt-in-max'] ||
134
+ params['y-amount'] ||
135
+ params['x-amount'] ||
136
+ params.dy,
137
+ 'amt-in-max': params.amount ||
138
+ params.dx ||
139
+ params['amt-in'] ||
140
+ params['amt-in-max'] ||
141
+ params['y-amount'] ||
142
+ params['x-amount'] ||
143
+ params.dy,
144
+ 'y-amount': params.amount ||
145
+ params.dx ||
146
+ params['amt-in'] ||
147
+ params['amt-in-max'] ||
148
+ params['y-amount'] ||
149
+ params['x-amount'] ||
150
+ params.dy,
151
+ 'x-amount': params.amount ||
152
+ params.dx ||
153
+ params['amt-in'] ||
154
+ params['amt-in-max'] ||
155
+ params['y-amount'] ||
156
+ params['x-amount'] ||
157
+ params.dy,
158
+ 'min-received': rawResult,
159
+ 'min-dy': rawResult,
160
+ 'min-dz': rawResult,
161
+ 'min-dw': rawResult,
162
+ 'amt-out': rawResult,
163
+ 'amt-out-min': rawResult,
164
+ 'min-x-amount': rawResult,
165
+ 'min-dv': rawResult,
166
+ 'min-y-amount': rawResult,
167
+ 'min-dx': rawResult,
168
+ },
169
+ };
170
+ const quoteResult = {
171
+ route: {
172
+ ...route,
173
+ quoteData: updatedQuoteData,
174
+ swapData: updatedSwapData,
175
+ },
176
+ quote: convertedResult,
177
+ params: params,
178
+ quoteData: updatedQuoteData,
179
+ swapData: updatedSwapData,
180
+ dexPath: route.dex_path,
181
+ tokenPath: route.token_path,
182
+ tokenXDecimals: tokenXDecimals,
183
+ tokenYDecimals: tokenYDecimals,
184
+ };
185
+ allRoutes.push(quoteResult);
186
+ }
187
+ else {
188
+ throw new Error('Invalid quote result');
189
+ }
190
+ }
191
+ catch (error) {
192
+ console.warn(`Failed to get quote for route ${routeIndex + 1}:`, route, error);
193
+ allRoutes.push({
194
+ route,
195
+ quote: null,
196
+ params: route.quoteData
197
+ ? { ...route.quoteData.parameters, amountInput }
198
+ : { amountInput },
199
+ quoteData: route.quoteData,
200
+ swapData: route.swapData,
201
+ dexPath: route.dex_path,
202
+ tokenPath: route.token_path,
203
+ tokenXDecimals: route.tokenXDecimals,
204
+ tokenYDecimals: route.tokenYDecimals,
205
+ error: error.message,
206
+ });
207
+ }
208
+ }
209
+ allRoutes.sort((a, b) => (b.quote || 0) - (a.quote || 0));
210
+ const result = {
211
+ bestRoute: ((_a = allRoutes[0]) === null || _a === void 0 ? void 0 : _a.quote) !== null ? allRoutes[0] : null,
212
+ allRoutes,
213
+ inputData: { tokenX, tokenY, amountInput },
214
+ };
215
+ return result;
216
+ }
217
+ async getSwapParams(swapExecutionData, senderAddress, slippageTolerance = 0.015) {
218
+ const { route, amount, tokenXDecimals, tokenYDecimals } = swapExecutionData;
219
+ const executionData = {
220
+ route: {
221
+ ...route,
222
+ swapData: {
223
+ ...route.swapData,
224
+ parameters: {
225
+ ...route.swapData.parameters,
226
+ amount: route.swapData.parameters.amount ||
227
+ amount ||
228
+ route.swapData.parameters['amt-in'] ||
229
+ route.swapData.parameters['amt-in-max'] ||
230
+ route.swapData.parameters['y-amount'],
231
+ dx: route.swapData.parameters.dx ||
232
+ amount ||
233
+ route.swapData.parameters['amt-in'] ||
234
+ route.swapData.parameters['amt-in-max'] ||
235
+ route.swapData.parameters['y-amount'],
236
+ 'amt-in': route.swapData.parameters.dx ||
237
+ amount ||
238
+ route.swapData.parameters['amt-in'] ||
239
+ route.swapData.parameters['amt-in-max'] ||
240
+ route.swapData.parameters['y-amount'] ||
241
+ route.swapData.parameters.dy,
242
+ 'amt-in-max': route.swapData.parameters.dx ||
243
+ amount ||
244
+ route.swapData.parameters['amt-in'] ||
245
+ route.swapData.parameters['amt-in-max'] ||
246
+ route.swapData.parameters['y-amount'] ||
247
+ route.swapData.parameters.dy,
248
+ 'y-amount': route.swapData.parameters.dx ||
249
+ amount ||
250
+ route.swapData.parameters['amt-in'] ||
251
+ route.swapData.parameters['amt-in-max'] ||
252
+ route.swapData.parameters['y-amount'] ||
253
+ route.swapData.parameters.dy,
254
+ dy: route.swapData.parameters.dy ||
255
+ amount ||
256
+ route.swapData.parameters['amt-in'] ||
257
+ route.swapData.parameters['amt-in-max'] ||
258
+ route.swapData.parameters['y-amount'] ||
259
+ route.swapData.parameters.dy,
260
+ },
261
+ },
262
+ },
263
+ amount,
264
+ tokenXDecimals: tokenXDecimals,
265
+ tokenYDecimals: tokenYDecimals,
266
+ };
267
+ return await (0, callGetSwapParams_1.executeGetParams)(executionData, senderAddress, slippageTolerance, this.context);
268
+ }
269
+ async executeSwap(swapExecutionData, senderAddress, slippageTolerance = 0.015, stacksProvider, onFinish, onCancel) {
270
+ const swapParams = await this.getSwapParams(swapExecutionData, senderAddress, slippageTolerance);
271
+ await (0, callSwapHelper_1.executeSwapHelper)(swapParams, senderAddress, this.context, stacksProvider, onFinish, onCancel);
272
+ }
273
+ }
274
+ exports.BitflowSDK = BitflowSDK;
275
+ //# sourceMappingURL=BitflowSDK.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BitflowSDK.js","sourceRoot":"","sources":["../../src/BitflowSDK.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AAC,UAAU,CAAC,YAAY,CAAC;4BACvC,KAAK,CAAC,QAAQ,CAAC,UAAU,CAAC,UAAU,CAAC;4BACrC,KAAK,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE;qBAC/B;iBACF;aACF;YACD,MAAM;YACN,cAAc,EAAE,cAAc;YAC9B,cAAc,EAAE,cAAc;SAC/B,CAAC;QAEF,OAAO,MAAM,IAAA,oCAAgB,EAC3B,aAAa,EACb,aAAa,EACb,iBAAiB,EACjB,IAAI,CAAC,OAAO,CACb,CAAC;IACJ,CAAC;IAEM,KAAK,CAAC,WAAW,CACtB,iBAAoC,EACpC,aAAqB,EACrB,oBAA4B,KAAK,EACjC,cAA+B,EAC/B,QAA8B,EAC9B,QAAqB;QAErB,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,aAAa,CACzC,iBAAiB,EACjB,aAAa,EACb,iBAAiB,CAClB,CAAC;QAEF,MAAM,IAAA,kCAAiB,EACrB,UAAU,EACV,aAAa,EACb,IAAI,CAAC,OAAO,EACZ,cAAc,EACd,QAAQ,EACR,QAAQ,CACT,CAAC;IACJ,CAAC;CACF;AA3WD,gCA2WC"}
@@ -0,0 +1,3 @@
1
+ import { BitflowSDKConfig } from './types';
2
+ export declare const configs: BitflowSDKConfig;
3
+ export declare function validateConfig(): void;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var _a, _b, _c;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.configs = void 0;
5
+ exports.validateConfig = validateConfig;
6
+ exports.configs = {
7
+ BITFLOW_API_HOST: (_a = process.env.NEXT_PUBLIC_BITFLOW_API_HOST) !== null && _a !== void 0 ? _a : process.env.BITFLOW_API_HOST,
8
+ BITFLOW_API_KEY: (_b = process.env.NEXT_PUBLIC_BITFLOW_API_KEY) !== null && _b !== void 0 ? _b : process.env.BITFLOW_API_KEY,
9
+ READONLY_CALL_API_HOST: (_c = process.env.NEXT_PUBLIC_READONLY_CALL_API_HOST) !== null && _c !== void 0 ? _c : process.env.READONLY_CALL_API_HOST,
10
+ };
11
+ function validateConfig() {
12
+ const requiredEnvVars = Object.keys(exports.configs);
13
+ for (const envVar of requiredEnvVars) {
14
+ if (!exports.configs[envVar]) {
15
+ console.error(`Missing required configuration: ${envVar}`);
16
+ throw new Error(`Missing required configuration: ${envVar}`);
17
+ }
18
+ }
19
+ }
20
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":";;;;AAYA,wCASC;AAnBY,QAAA,OAAO,GAAqB;IACvC,gBAAgB,EACd,MAAA,OAAO,CAAC,GAAG,CAAC,4BAA4B,mCAAI,OAAO,CAAC,GAAG,CAAC,gBAAgB;IAC1E,eAAe,EACb,MAAA,OAAO,CAAC,GAAG,CAAC,2BAA2B,mCAAI,OAAO,CAAC,GAAG,CAAC,eAAe;IACxE,sBAAsB,EACpB,MAAA,OAAO,CAAC,GAAG,CAAC,kCAAkC,mCAC9C,OAAO,CAAC,GAAG,CAAC,sBAAsB;CACrC,CAAC;AAEF,SAAgB,cAAc;IAC5B,MAAM,eAAe,GAAG,MAAM,CAAC,IAAI,CAAC,eAAO,CAA+B,CAAC;IAE3E,KAAK,MAAM,MAAM,IAAI,eAAe,EAAE,CAAC;QACrC,IAAI,CAAC,eAAO,CAAC,MAAM,CAAC,EAAE,CAAC;YACrB,OAAO,CAAC,KAAK,CAAC,mCAAmC,MAAM,EAAE,CAAC,CAAC;YAC3D,MAAM,IAAI,KAAK,CAAC,mCAAmC,MAAM,EAAE,CAAC,CAAC;QAC/D,CAAC;IACH,CAAC;AACH,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { SwapContext, SwapDataParamsAndPostConditions, SwapExecutionData } from "../types";
2
+ export declare const executeGetParams: (swapExecutionData: SwapExecutionData, senderAddress: string, slippageTolerance: number, context: SwapContext) => Promise<SwapDataParamsAndPostConditions>;
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.executeGetParams = void 0;
4
+ const postConditionsHelper_1 = require("./postConditionsHelper");
5
+ const constructFunctionArgs_1 = require("./constructFunctionArgs");
6
+ const getContractInterfaceAndFunction_1 = require("./getContractInterfaceAndFunction");
7
+ const applySlippage = (value, slippageTolerance) => {
8
+ const bigIntValue = BigInt(value);
9
+ const slippageFactor = BigInt(Math.floor((1 - slippageTolerance) * 10000));
10
+ return (bigIntValue * slippageFactor) / BigInt(10000);
11
+ };
12
+ const executeGetParams = async (swapExecutionData, senderAddress, slippageTolerance, context) => {
13
+ var _a;
14
+ const network = context.network;
15
+ const { route, amount, tokenXDecimals, tokenYDecimals } = swapExecutionData;
16
+ const [contractAddress, contractName] = route.swapData.contract.split(".");
17
+ try {
18
+ const contractKey = `${contractAddress}.${contractName}`;
19
+ let contractInterface = context.contractInterfaces[contractKey];
20
+ let functionArgsDefinition = (_a = context.functionArgs[contractKey]) === null || _a === void 0 ? void 0 : _a[route.swapData.function];
21
+ if (!contractInterface || !functionArgsDefinition) {
22
+ const result = await (0, getContractInterfaceAndFunction_1.getContractInterfaceAndFunction)(contractAddress, contractName, route.swapData.function);
23
+ if (!contractInterface) {
24
+ contractInterface = result.contractInterface;
25
+ context.contractInterfaces[contractKey] = contractInterface;
26
+ }
27
+ if (!functionArgsDefinition) {
28
+ functionArgsDefinition = result.functionArgs;
29
+ if (!context.functionArgs[contractKey]) {
30
+ context.functionArgs[contractKey] = {};
31
+ }
32
+ context.functionArgs[contractKey][route.swapData.function] =
33
+ functionArgsDefinition;
34
+ }
35
+ }
36
+ const swapParameters = { ...route.swapData.parameters };
37
+ // Apply slippage to various parameters
38
+ const slippageParams = [
39
+ "min-received",
40
+ "min-dy",
41
+ "min-dx",
42
+ "min-dz",
43
+ "min-dw",
44
+ "amt-out",
45
+ "amt-out-min",
46
+ "min-x-amount",
47
+ "min-dv",
48
+ "min-y-amount",
49
+ ];
50
+ slippageParams.forEach((param) => {
51
+ if (swapParameters[param]) {
52
+ swapParameters[param] = applySlippage(swapParameters[param], slippageTolerance);
53
+ }
54
+ });
55
+ // Convert input amounts to BigInt
56
+ const inputParams = [
57
+ "amount",
58
+ "dx",
59
+ "amt-in",
60
+ "amt-in-max",
61
+ "y-amount",
62
+ "dy",
63
+ ];
64
+ inputParams.forEach((param) => {
65
+ if (param in swapParameters) {
66
+ swapParameters[param] = BigInt(swapParameters[param]);
67
+ }
68
+ });
69
+ const functionArgs = (0, constructFunctionArgs_1.constructFunctionArgs)(swapParameters, functionArgsDefinition);
70
+ const postConditions = await (0, postConditionsHelper_1.createSwapPostConditions)(swapParameters, route.postConditions, senderAddress, tokenXDecimals, tokenYDecimals);
71
+ return {
72
+ functionArgs,
73
+ postConditions,
74
+ contractAddress,
75
+ contractName,
76
+ functionName: route.swapData.function,
77
+ };
78
+ }
79
+ catch (error) {
80
+ console.error("Error getting swap parameters:", error);
81
+ throw error;
82
+ }
83
+ };
84
+ exports.executeGetParams = executeGetParams;
85
+ //# sourceMappingURL=callGetSwapParams.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"callGetSwapParams.js","sourceRoot":"","sources":["../../../src/helpers/callGetSwapParams.ts"],"names":[],"mappings":";;;AAAA,iEAAkE;AAMlE,mEAAgE;AAChE,uFAAoF;AAGpF,MAAM,aAAa,GAAG,CACpB,KAA+B,EAC/B,iBAAyB,EACjB,EAAE;IACV,MAAM,WAAW,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAClC,MAAM,cAAc,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,iBAAiB,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC;IAC3E,OAAO,CAAC,WAAW,GAAG,cAAc,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;AACxD,CAAC,CAAC;AAEK,MAAM,gBAAgB,GAAG,KAAK,EACnC,iBAAoC,EACpC,aAAqB,EACrB,iBAAyB,EACzB,OAAoB,EACsB,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K,CAAC,CAAC;QACvD,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC,CAAC;AAtGW,QAAA,gBAAgB,oBAsG3B"}
@@ -0,0 +1,8 @@
1
+ import { SwapContext } from "../types";
2
+ export declare const stringifyWithBigInt: (obj: any) => string;
3
+ export declare const callReadOnlyFunctionHelper: (contractDeployer: string, contractName: string, functionName: string, parameters: any, senderAddress: string, tokenXId: string, tokenYId: string, swapData: any, context: SwapContext) => Promise<{
4
+ convertedResult: number;
5
+ rawResult: number;
6
+ tokenXDecimals: number;
7
+ tokenYDecimals: number;
8
+ }>;