@bloque/sdk-swap 0.0.28

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/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # `@bloque/sdk-swap`
2
+
3
+ ⚠️ **Warning**: This package is intended for internal use. Its release cycle does not follow SemVer, which means we might release breaking changes (change APIs, remove functionality) without any prior warning.
4
+
5
+ For documentation, please refer to the [main SDK documentation](../sdk/README.md).
package/dist/index.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";const __rslib_import_meta_url__="u"<typeof document?new(require("url".replace("",""))).URL("file:"+__filename).href:document.currentScript&&document.currentScript.src||new URL("main.js",document.baseURI).href;var __webpack_require__={};__webpack_require__.d=(e,t)=>{for(var a in t)__webpack_require__.o(t,a)&&!__webpack_require__.o(e,a)&&Object.defineProperty(e,a,{enumerable:!0,get:t[a]})},__webpack_require__.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),__webpack_require__.r=e=>{"u">typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var __webpack_exports__={};__webpack_require__.r(__webpack_exports__),__webpack_require__.d(__webpack_exports__,{SwapClient:()=>SwapClient,PseClient:()=>PseClient});const sdk_core_namespaceObject=require("@bloque/sdk-core");class PseClient extends sdk_core_namespaceObject.BaseClient{async banks(){return{banks:(await this.httpClient.request({method:"GET",path:"/api/utils/pse/banks"})).banks.map(e=>this._mapBankResponse(e))}}_mapBankResponse(e){return{code:e.financial_institution_code,name:e.financial_institution_name}}}class SwapClient extends sdk_core_namespaceObject.BaseClient{pse;constructor(e){super(e),this.pse=new PseClient(this.httpClient)}async findRates(e){let t=new URLSearchParams,a=JSON.stringify([e.fromAsset,e.toAsset]);t.append("edge",a),t.append("from_medium",JSON.stringify(e.fromMediums)),t.append("to_medium",JSON.stringify(e.toMediums)),void 0!==e.amountSrc&&t.append("amount_src",e.amountSrc),void 0!==e.amountDst&&t.append("amount_dst",e.amountDst),e.sort&&t.append("sort",e.sort),e.sortBy&&t.append("sort_by",e.sortBy);let r=t.toString(),_=`/api/rates?${r}`;return{rates:(await this.httpClient.request({method:"GET",path:_})).rates.map(e=>this._mapRateResponse(e))}}_mapRateResponse(e){return{id:e.id,sig:e.sig,swapSig:e.swap_sig,maker:e.maker,edge:e.edge,fee:{at:e.fee.at,value:e.fee.value,formula:e.fee.formula,components:e.fee.components.map(e=>({at:e.at,name:e.name,type:e.type,value:e.value,percentage:e.percentage,pair:e.pair,amount:e.amount}))},at:e.at,until:e.until,fromMediums:e.from_medium,toMediums:e.to_medium,rate:e.rate,ratio:e.ratio,fromLimits:e.from_limits,toLimits:e.to_limits,createdAt:e.created_at,updatedAt:e.updated_at}}}for(var __rspack_i in exports.PseClient=__webpack_exports__.PseClient,exports.SwapClient=__webpack_exports__.SwapClient,__webpack_exports__)-1===["PseClient","SwapClient"].indexOf(__rspack_i)&&(exports[__rspack_i]=__webpack_exports__[__rspack_i]);Object.defineProperty(exports,"__esModule",{value:!0});
@@ -0,0 +1,4 @@
1
+ export * from './pse/pse-client';
2
+ export * from './pse/types';
3
+ export * from './swap-client';
4
+ export * from './types';
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ import{BaseClient as t}from"@bloque/sdk-core";class e extends t{async banks(){return{banks:(await this.httpClient.request({method:"GET",path:"/api/utils/pse/banks"})).banks.map(t=>this._mapBankResponse(t))}}_mapBankResponse(t){return{code:t.financial_institution_code,name:t.financial_institution_name}}}class a extends t{pse;constructor(t){super(t),this.pse=new e(this.httpClient)}async findRates(t){let e=new URLSearchParams,a=JSON.stringify([t.fromAsset,t.toAsset]);e.append("edge",a),e.append("from_medium",JSON.stringify(t.fromMediums)),e.append("to_medium",JSON.stringify(t.toMediums)),void 0!==t.amountSrc&&e.append("amount_src",t.amountSrc),void 0!==t.amountDst&&e.append("amount_dst",t.amountDst),t.sort&&e.append("sort",t.sort),t.sortBy&&e.append("sort_by",t.sortBy);let s=e.toString(),n=`/api/rates?${s}`;return{rates:(await this.httpClient.request({method:"GET",path:n})).rates.map(t=>this._mapRateResponse(t))}}_mapRateResponse(t){return{id:t.id,sig:t.sig,swapSig:t.swap_sig,maker:t.maker,edge:t.edge,fee:{at:t.fee.at,value:t.fee.value,formula:t.fee.formula,components:t.fee.components.map(t=>({at:t.at,name:t.name,type:t.type,value:t.value,percentage:t.percentage,pair:t.pair,amount:t.amount}))},at:t.at,until:t.until,fromMediums:t.from_medium,toMediums:t.to_medium,rate:t.rate,ratio:t.ratio,fromLimits:t.from_limits,toLimits:t.to_limits,createdAt:t.created_at,updatedAt:t.updated_at}}}export{e as PseClient,a as SwapClient};
@@ -0,0 +1,70 @@
1
+ /**
2
+ * @internal
3
+ * Wire types for API communication (snake_case format)
4
+ * These types represent the raw API request/response format
5
+ * and should not be used directly by SDK consumers.
6
+ */
7
+ /**
8
+ * @internal
9
+ * Fee component type from API
10
+ */
11
+ export type FeeComponentType = 'percentage' | 'rate' | 'fixed';
12
+ /**
13
+ * @internal
14
+ * Fee component from API
15
+ */
16
+ export interface FeeComponent {
17
+ at: number;
18
+ name: string;
19
+ type: FeeComponentType;
20
+ value: number | string;
21
+ percentage?: number;
22
+ pair?: string;
23
+ amount?: number;
24
+ }
25
+ /**
26
+ * @internal
27
+ * Fee details from API
28
+ */
29
+ export interface Fee {
30
+ at: number;
31
+ value: number;
32
+ formula: string;
33
+ components: FeeComponent[];
34
+ }
35
+ /**
36
+ * @internal
37
+ * Rate from API
38
+ */
39
+ export interface Rate {
40
+ id: string;
41
+ sig: string;
42
+ swap_sig: string;
43
+ maker: string;
44
+ edge: [string, string];
45
+ fee: Fee;
46
+ at: string;
47
+ until: string;
48
+ from_medium: string[];
49
+ to_medium: string[];
50
+ rate: [number, number];
51
+ ratio: number;
52
+ from_limits: [string, string];
53
+ to_limits: [string, string];
54
+ created_at: string;
55
+ updated_at: string;
56
+ }
57
+ /**
58
+ * @internal
59
+ * Find rates response from API
60
+ */
61
+ export interface FindRatesResponse {
62
+ rates: Rate[];
63
+ }
64
+ export interface PseBank {
65
+ financial_institution_code: string;
66
+ financial_institution_name: string;
67
+ }
68
+ export interface ListPseBanksResponse {
69
+ banks: PseBank[];
70
+ }
@@ -0,0 +1,31 @@
1
+ import { BaseClient } from '@bloque/sdk-core';
2
+ import type { ListBanksResult } from './types';
3
+ /**
4
+ * PSE client for PSE-related utilities
5
+ *
6
+ * Provides access to PSE (Pagos Seguros en Línea) utilities like bank listing.
7
+ */
8
+ export declare class PseClient extends BaseClient {
9
+ /**
10
+ * List available PSE banks
11
+ *
12
+ * Retrieves the list of financial institutions available for PSE payments.
13
+ *
14
+ * @returns Promise resolving to list of banks
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * const result = await bloque.swap.pse.banks();
19
+ *
20
+ * for (const bank of result.banks) {
21
+ * console.log(`${bank.code}: ${bank.name}`);
22
+ * }
23
+ * ```
24
+ */
25
+ banks(): Promise<ListBanksResult>;
26
+ /**
27
+ * Maps API bank response to SDK format
28
+ * @internal
29
+ */
30
+ private _mapBankResponse;
31
+ }
@@ -0,0 +1,13 @@
1
+ export interface Bank {
2
+ /**
3
+ * Financial institution code
4
+ */
5
+ code: string;
6
+ /**
7
+ * Financial institution name
8
+ */
9
+ name: string;
10
+ }
11
+ export interface ListBanksResult {
12
+ banks: Bank[];
13
+ }
@@ -0,0 +1,41 @@
1
+ import type { HttpClient } from '@bloque/sdk-core';
2
+ import { BaseClient } from '@bloque/sdk-core';
3
+ import { PseClient } from './pse/pse-client';
4
+ import type { FindRatesParams, FindRatesResult } from './types';
5
+ /**
6
+ * Swap client for finding exchange rates
7
+ *
8
+ * Provides access to exchange rate discovery and swapping functionality.
9
+ * - pse: PSE utilities (bank listing, etc.)
10
+ */
11
+ export declare class SwapClient extends BaseClient {
12
+ readonly pse: PseClient;
13
+ constructor(httpClient: HttpClient);
14
+ /**
15
+ * Find available exchange rates
16
+ *
17
+ * Retrieves exchange rates for a given asset pair and optional filters.
18
+ *
19
+ * @param params - Rate search parameters
20
+ * @returns Promise resolving to available rates
21
+ *
22
+ * @example
23
+ * ```typescript
24
+ * const result = await bloque.swap.findRates({
25
+ * fromAsset: 'COP/2',
26
+ * toAsset: 'DUSD/6',
27
+ * fromMediums: ['bancolombia'],
28
+ * toMediums: ['kusama'],
29
+ * amountSrc: '50000000' // 500000.00 COP (scaled by 2 decimals)
30
+ * });
31
+ *
32
+ * console.log(result.rates[0].ratio);
33
+ * ```
34
+ */
35
+ findRates(params: FindRatesParams): Promise<FindRatesResult>;
36
+ /**
37
+ * Maps API rate response to SDK format
38
+ * @internal
39
+ */
40
+ private _mapRateResponse;
41
+ }
@@ -0,0 +1,138 @@
1
+ /**
2
+ * Public types for @bloque/sdk-swap
3
+ */
4
+ /**
5
+ * Fee component type
6
+ */
7
+ export type FeeComponentType = 'percentage' | 'rate' | 'fixed';
8
+ /**
9
+ * Fee component details
10
+ */
11
+ export interface FeeComponent {
12
+ /** Timestamp when this component was calculated */
13
+ at: number;
14
+ /** Component name (e.g., 'take_rate', 'exchange_rate', 'pse_fee') */
15
+ name: string;
16
+ /** Type of fee component */
17
+ type: FeeComponentType;
18
+ /** Component value */
19
+ value: number | string;
20
+ /** Percentage value (only for percentage type) */
21
+ percentage?: number;
22
+ /** Currency pair (only for rate type) */
23
+ pair?: string;
24
+ /** Fixed amount (only for fixed type) */
25
+ amount?: number;
26
+ }
27
+ /**
28
+ * Fee details for a rate
29
+ */
30
+ export interface Fee {
31
+ /** Timestamp when the fee was calculated */
32
+ at: number;
33
+ /** Fee value */
34
+ value: number;
35
+ /** Formula used to calculate the fee */
36
+ formula: string;
37
+ /** Components that make up the fee */
38
+ components: FeeComponent[];
39
+ }
40
+ /**
41
+ * Rate limits tuple [min, max]
42
+ */
43
+ export type RateLimits = [string, string];
44
+ /**
45
+ * Rate tuple [sourceAmount, destinationAmount]
46
+ */
47
+ export type RateTuple = [number, number];
48
+ /**
49
+ * Exchange rate information
50
+ */
51
+ export interface SwapRate {
52
+ /** Unique rate identifier */
53
+ id: string;
54
+ /** Rate signature */
55
+ sig: string;
56
+ /** Swap signature */
57
+ swapSig: string;
58
+ /** Maker identifier */
59
+ maker: string;
60
+ /** Asset edge [fromAsset, toAsset] */
61
+ edge: [string, string];
62
+ /** Fee details */
63
+ fee: Fee;
64
+ /** Timestamp when the rate was created */
65
+ at: string;
66
+ /** Timestamp until the rate is valid */
67
+ until: string;
68
+ /** Available source mediums */
69
+ fromMediums: string[];
70
+ /** Available destination mediums */
71
+ toMediums: string[];
72
+ /** Rate tuple [sourceAmount, destinationAmount] */
73
+ rate: RateTuple;
74
+ /** Exchange ratio */
75
+ ratio: number;
76
+ /** Source amount limits [min, max] */
77
+ fromLimits: RateLimits;
78
+ /** Destination amount limits [min, max] */
79
+ toLimits: RateLimits;
80
+ /** Creation timestamp */
81
+ createdAt: string;
82
+ /** Last update timestamp */
83
+ updatedAt: string;
84
+ }
85
+ /**
86
+ * Parameters for finding exchange rates
87
+ */
88
+ export interface FindRatesParams {
89
+ /**
90
+ * Source asset with precision (e.g., "COP/2" where /2 indicates 2 decimal places)
91
+ * @example "COP/2"
92
+ */
93
+ fromAsset: string;
94
+ /**
95
+ * Destination asset with precision (e.g., "DUSD/6" where /6 indicates 6 decimal places)
96
+ * @example "DUSD/6"
97
+ */
98
+ toAsset: string;
99
+ /**
100
+ * Source payment mediums (e.g., PSE, Bancolombia, Nequi)
101
+ * @example ["bancolombia", "pse"]
102
+ */
103
+ fromMediums: string[];
104
+ /**
105
+ * Destination payment mediums (e.g., Pomelo, Kreivo)
106
+ * @example ["kusama", "pomelo"]
107
+ */
108
+ toMediums: string[];
109
+ /**
110
+ * Source amount as bigint string (scaled by asset precision).
111
+ * Provide this OR amountDst, not both.
112
+ * @example "1000000" represents 10000.00 for COP/2
113
+ */
114
+ amountSrc?: string;
115
+ /**
116
+ * Destination amount as bigint string (scaled by asset precision).
117
+ * Provide this OR amountSrc, not both.
118
+ * @example "50000" represents 0.5000 for USD/4
119
+ */
120
+ amountDst?: string;
121
+ /**
122
+ * Sort order: 'asc' (best rate first) or 'desc' (highest rate first)
123
+ * @default "asc"
124
+ */
125
+ sort?: 'asc' | 'desc';
126
+ /**
127
+ * Sort by field: 'rate' (by exchange ratio) or 'at' (by calculation time)
128
+ * @default "rate"
129
+ */
130
+ sortBy?: 'rate' | 'at';
131
+ }
132
+ /**
133
+ * Result of finding exchange rates
134
+ */
135
+ export interface FindRatesResult {
136
+ /** Array of available rates */
137
+ rates: SwapRate[];
138
+ }
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@bloque/sdk-swap",
3
+ "version": "0.0.28",
4
+ "type": "module",
5
+ "keywords": [
6
+ "bloque",
7
+ "sdk",
8
+ "api"
9
+ ],
10
+ "license": "MIT",
11
+ "publishConfig": {
12
+ "access": "public",
13
+ "provenance": true
14
+ },
15
+ "homepage": "git+https://github.com/bloque-app/sdk.git#readme",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/bloque-app/sdk.git",
19
+ "directory": "packages/swap"
20
+ },
21
+ "exports": {
22
+ ".": {
23
+ "types": "./dist/index.d.ts",
24
+ "import": "./dist/index.js",
25
+ "require": "./dist/index.cjs"
26
+ }
27
+ },
28
+ "main": "./dist/index.cjs",
29
+ "types": "./dist/index.d.ts",
30
+ "files": [
31
+ "dist"
32
+ ],
33
+ "engines": {
34
+ "node": ">=22"
35
+ },
36
+ "dependencies": {
37
+ "@bloque/sdk-core": "0.0.28"
38
+ }
39
+ }