@bloque/sdk-swap 0.12.0 → 0.13.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/bank-transfer/types.d.ts +18 -1
- package/dist/external-us-bank/external-us-bank-client.d.ts +33 -3
- package/dist/external-us-bank/types.d.ts +44 -9
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1 -1
- package/dist/internal/wire-types.d.ts +20 -1
- package/dist/rtp/rtp-client.d.ts +34 -2
- package/dist/rtp/types.d.ts +40 -8
- package/package.json +2 -2
|
@@ -293,10 +293,27 @@ export interface ExecutionHowBrebDeposit {
|
|
|
293
293
|
/** `awaiting` on first pause; `partial` after an underpayment. */
|
|
294
294
|
depositStatus?: 'awaiting' | 'partial';
|
|
295
295
|
}
|
|
296
|
+
/**
|
|
297
|
+
* Instruct the payer to send native USDC on Base to a deposit 0x
|
|
298
|
+
* (base → rtp inbox pause).
|
|
299
|
+
*/
|
|
300
|
+
export interface ExecutionHowWalletTransfer {
|
|
301
|
+
type: 'WALLET_TRANSFER';
|
|
302
|
+
chain: 'base';
|
|
303
|
+
/** Inbox 0x that receives native USDC */
|
|
304
|
+
address: string;
|
|
305
|
+
tokenAddress: string;
|
|
306
|
+
tokenSymbol: 'USDC';
|
|
307
|
+
tokenDecimals: 6;
|
|
308
|
+
/** Atomic USDC amount (same precision as order.fromAmount) */
|
|
309
|
+
amount: string;
|
|
310
|
+
currency: 'USDC';
|
|
311
|
+
depositAccountUrn: string;
|
|
312
|
+
}
|
|
296
313
|
/**
|
|
297
314
|
* Instructions for completing a paused execution step
|
|
298
315
|
*/
|
|
299
|
-
export type ExecutionHow = ExecutionHowRedirect | ExecutionHowCallback | ExecutionHowIframe | ExecutionHowBrebDeposit;
|
|
316
|
+
export type ExecutionHow = ExecutionHowRedirect | ExecutionHowCallback | ExecutionHowIframe | ExecutionHowBrebDeposit | ExecutionHowWalletTransfer;
|
|
300
317
|
/**
|
|
301
318
|
* Execution result from auto-execution
|
|
302
319
|
*/
|
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
import { BaseClient } from '@bloque/sdk-core';
|
|
2
2
|
import type { CreateExternalUsBankOrderOptions, CreateExternalUsBankOrderParams, CreateExternalUsBankOrderResult } from './types';
|
|
3
3
|
/**
|
|
4
|
-
* External US bank client for ACH on-ramp (US bank → Kusama DUSD).
|
|
4
|
+
* External US bank client for ACH on-ramp (US bank → Kusama DUSD or Base USDC).
|
|
5
5
|
*/
|
|
6
6
|
export declare class ExternalUsBankSwapClient extends BaseClient {
|
|
7
7
|
/**
|
|
8
|
-
* Create an external US bank on-ramp order (ACH pull → DUSD on Kusama
|
|
8
|
+
* Create an external US bank on-ramp order (ACH pull → DUSD on Kusama, or
|
|
9
|
+
* USDC on Base).
|
|
9
10
|
*
|
|
10
|
-
*
|
|
11
|
+
* Omit `toMedium` (or pass `'kusama'`) and supply
|
|
12
|
+
* `depositInformation.ledgerAccountId` for the Kusama path. Pass
|
|
13
|
+
* `toMedium: 'base'` with `depositInformation.walletAddress` to land USDC
|
|
14
|
+
* on Base at that 0x.
|
|
15
|
+
*
|
|
16
|
+
* @param params - Order parameters including destination and linked bank
|
|
11
17
|
* @returns Promise resolving to the created order
|
|
12
18
|
*
|
|
13
19
|
* @example
|
|
@@ -31,8 +37,32 @@ export declare class ExternalUsBankSwapClient extends BaseClient {
|
|
|
31
37
|
* },
|
|
32
38
|
* });
|
|
33
39
|
* ```
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```typescript
|
|
43
|
+
* const rates = await bloque.swap.findRates({
|
|
44
|
+
* fromAsset: 'USD/2',
|
|
45
|
+
* toAsset: 'USDC/6',
|
|
46
|
+
* fromMediums: ['external-us-bank'],
|
|
47
|
+
* toMediums: ['base'],
|
|
48
|
+
* amountSrc: '10000',
|
|
49
|
+
* });
|
|
50
|
+
*
|
|
51
|
+
* const result = await bloque.swap.externalUsBank.create({
|
|
52
|
+
* rateSig: rates.rates[0].sig,
|
|
53
|
+
* amountSrc: '10000',
|
|
54
|
+
* toMedium: 'base',
|
|
55
|
+
* depositInformation: {
|
|
56
|
+
* walletAddress: '0x1234567890abcdef1234567890abcdef12345678',
|
|
57
|
+
* },
|
|
58
|
+
* args: {
|
|
59
|
+
* sourceAccountUrn: 'did:bloque:account:external-us-bank:abc123',
|
|
60
|
+
* },
|
|
61
|
+
* });
|
|
62
|
+
* ```
|
|
34
63
|
*/
|
|
35
64
|
create(params: CreateExternalUsBankOrderParams, options?: CreateExternalUsBankOrderOptions): Promise<CreateExternalUsBankOrderResult>;
|
|
65
|
+
private _mapDepositInformation;
|
|
36
66
|
private _mapOrderResponse;
|
|
37
67
|
private _mapExecutionResult;
|
|
38
68
|
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { ExecutionHow, ExecutionResult, OrderType, SwapOrder } from '../bank-transfer/types';
|
|
2
2
|
export type { ExecutionHow, ExecutionResult, OrderType, SwapOrder };
|
|
3
|
+
/** Destination medium for an external US bank ACH on-ramp. */
|
|
4
|
+
export type ExternalUsBankDestination = 'kusama' | 'base';
|
|
3
5
|
/**
|
|
4
|
-
* Deposit information for external US bank on-ramp (ACH pull →
|
|
6
|
+
* Deposit information for external US bank on-ramp to Kusama (ACH pull → DUSD).
|
|
5
7
|
*/
|
|
6
8
|
export interface ExternalUsBankDepositInformation {
|
|
7
9
|
/**
|
|
@@ -9,6 +11,19 @@ export interface ExternalUsBankDepositInformation {
|
|
|
9
11
|
*/
|
|
10
12
|
ledgerAccountId: string;
|
|
11
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* Deposit information for external US bank on-ramp to Base (ACH pull → USDC).
|
|
16
|
+
*/
|
|
17
|
+
export interface ExternalUsBankBaseDepositInformation {
|
|
18
|
+
/**
|
|
19
|
+
* Destination 0x on Base to receive USDC.
|
|
20
|
+
*/
|
|
21
|
+
walletAddress: string;
|
|
22
|
+
/**
|
|
23
|
+
* Optional label for the destination wallet. Defaults server-side when omitted.
|
|
24
|
+
*/
|
|
25
|
+
walletName?: string;
|
|
26
|
+
}
|
|
12
27
|
/**
|
|
13
28
|
* Arguments for external US bank on-ramp auto-execution.
|
|
14
29
|
*/
|
|
@@ -18,10 +33,7 @@ export interface ExternalUsBankArgs {
|
|
|
18
33
|
*/
|
|
19
34
|
sourceAccountUrn: string;
|
|
20
35
|
}
|
|
21
|
-
|
|
22
|
-
* Parameters for creating an external US bank on-ramp order.
|
|
23
|
-
*/
|
|
24
|
-
export interface CreateExternalUsBankOrderParams {
|
|
36
|
+
interface CreateExternalUsBankOrderParamsBase {
|
|
25
37
|
/**
|
|
26
38
|
* Rate signature from findRates.
|
|
27
39
|
*/
|
|
@@ -42,10 +54,6 @@ export interface CreateExternalUsBankOrderParams {
|
|
|
42
54
|
* Order type (default: 'src').
|
|
43
55
|
*/
|
|
44
56
|
type?: OrderType;
|
|
45
|
-
/**
|
|
46
|
-
* Destination ledger account to credit on Kusama.
|
|
47
|
-
*/
|
|
48
|
-
depositInformation: ExternalUsBankDepositInformation;
|
|
49
57
|
/**
|
|
50
58
|
* Linked bank account and auto-execution arguments.
|
|
51
59
|
*/
|
|
@@ -59,6 +67,33 @@ export interface CreateExternalUsBankOrderParams {
|
|
|
59
67
|
*/
|
|
60
68
|
metadata?: Record<string, unknown>;
|
|
61
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* ACH on-ramp to Kusama DUSD. `toMedium` may be omitted — Kusama is the default.
|
|
72
|
+
*/
|
|
73
|
+
export interface CreateExternalUsBankKusamaOrderParams extends CreateExternalUsBankOrderParamsBase {
|
|
74
|
+
toMedium?: 'kusama';
|
|
75
|
+
/**
|
|
76
|
+
* Destination ledger account to credit on Kusama.
|
|
77
|
+
*/
|
|
78
|
+
depositInformation: ExternalUsBankDepositInformation;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* ACH on-ramp to USDC on Base.
|
|
82
|
+
*/
|
|
83
|
+
export interface CreateExternalUsBankBaseOrderParams extends CreateExternalUsBankOrderParamsBase {
|
|
84
|
+
toMedium: 'base';
|
|
85
|
+
/**
|
|
86
|
+
* Destination 0x on Base to receive USDC.
|
|
87
|
+
*/
|
|
88
|
+
depositInformation: ExternalUsBankBaseDepositInformation;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Parameters for creating an external US bank on-ramp order.
|
|
92
|
+
*
|
|
93
|
+
* Defaults to Kusama (`toMedium` omitted). Pass `toMedium: 'base'` with
|
|
94
|
+
* `depositInformation.walletAddress` to land USDC on Base.
|
|
95
|
+
*/
|
|
96
|
+
export type CreateExternalUsBankOrderParams = CreateExternalUsBankKusamaOrderParams | CreateExternalUsBankBaseOrderParams;
|
|
62
97
|
export interface CreateExternalUsBankOrderOptions {
|
|
63
98
|
/**
|
|
64
99
|
* Optional custom idempotency key sent as `Idempotency-Key` header.
|
package/dist/index.cjs
CHANGED
|
@@ -1 +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__,{PseClient:()=>PseClient,ExternalUsBankSwapClient:()=>ExternalUsBankSwapClient,RtpClient:()=>RtpClient,SwapClient:()=>SwapClient,BankTransferClient:()=>BankTransferClient,BrebClient:()=>BrebClient});const sdk_core_namespaceObject=require("@bloque/sdk-core");function isWireBrebDepositHow(e){return"BREB_DEPOSIT"===e.type}function isWireCallbackHow(e){return"CALLBACK"===e.type&&"args"in e}function isWireIframeHow(e){return"IFRAME"===e.type&&"iframe"in e}function mapExecutionHow(e){return isWireBrebDepositHow(e)?{type:"BREB_DEPOSIT",medium:e.medium,keyType:e.key_type,keyValue:e.key_value,amount:e.amount,currency:e.currency,reference:e.reference,depositAccountUrn:e.deposit_account_urn,expectedAmount:e.expected_amount,receivedAmount:e.received_amount,remainingAmount:e.remaining_amount,depositStatus:e.deposit_status}:isWireCallbackHow(e)?{type:"CALLBACK",args:e.args}:isWireIframeHow(e)?{type:"IFRAME",iframe:e.iframe}:{type:e.type,url:e.url??""}}class BankTransferClient extends sdk_core_namespaceObject.BaseClient{async create(e,t){let a=this.httpClient.urn;if(!a)throw new sdk_core_namespaceObject.BloqueConfigError("User URN is not available. Please connect to a session first.");let r=e.type??"src",o={taker_urn:a,type:r,rate_sig:e.rateSig,from_medium:"kusama",to_medium:e.toMedium,webhook_url:e.webhookUrl,deposit_information:this._mapDepositInformationToWire(e.depositInformation)};"src"===r&&e.amountSrc?o.amount_src=e.amountSrc:"dst"===r&&e.amountDst&&(o.amount_dst=e.amountDst),e.args&&(o.args={account_urn:e.args.sourceAccountUrn}),e.nodeId&&(o.node_id=e.nodeId),e.metadata&&(o.metadata=e.metadata);let s=await this.httpClient.request({method:"PUT",path:"/api/order",body:o,headers:t?.idempotencyKey?{"Idempotency-Key":t.idempotencyKey}:void 0});return{order:this._mapOrderResponse(s.result.order),execution:s.result.execution?this._mapExecutionResult(s.result.execution):void 0,requestId:s.req_id}}_mapDepositInformationToWire(e){return{bank_account_type:e.bankAccountType,bank_account_number:e.bankAccountNumber,bank_account_holder_name:e.bankAccountHolderName,bank_account_holder_identification_type:e.bankAccountHolderIdentificationType,bank_account_holder_identification_value:e.bankAccountHolderIdentificationValue}}_mapOrderResponse(e){return{id:e.id,orderSig:e.order_sig,rateSig:e.rate_sig,swapSig:e.swap_sig,taker:e.taker,maker:e.maker,fromAsset:e.from_asset,toAsset:e.to_asset,fromMedium:e.from_medium,toMedium:e.to_medium,fromAmount:e.from_amount,toAmount:e.to_amount,at:e.at,graphId:e.graph_id,status:e.status,metadata:e.metadata,webhookUrl:e.webhook_url,failureReason:e.failure_reason,failureDetails:e.failure_details,createdAt:e.created_at,updatedAt:e.updated_at}}_mapExecutionResult(e){return{nodeId:e.node_id,result:{status:e.result.status,name:e.result.name,description:e.result.description,how:e.result.how?mapExecutionHow(e.result.how):void 0,callbackToken:e.result.callback_token}}}}class BrebClient extends sdk_core_namespaceObject.BaseClient{async create(e,t){let a=this.httpClient.urn;if(!a)throw new sdk_core_namespaceObject.BloqueConfigError("User URN is not available. Please connect to a session first.");let r=e.type??"src",o={taker_urn:a,type:r,rate_sig:e.rateSig,from_medium:"kusama",to_medium:"breb",webhook_url:e.webhookUrl,deposit_information:this._mapPayoutDepositInformationToWire(e.depositInformation),args:{account_urn:e.args.sourceAccountUrn}};"src"===r&&e.amountSrc?o.amount_src=e.amountSrc:"dst"===r&&e.amountDst&&(o.amount_dst=e.amountDst),e.nodeId&&(o.node_id=e.nodeId),e.metadata&&(o.metadata=e.metadata);let s=await this.httpClient.request({method:"PUT",path:"/api/order",body:o,headers:t?.idempotencyKey?{"Idempotency-Key":t.idempotencyKey}:void 0});return{order:this._mapOrderResponse(s.result.order),execution:s.result.execution?this._mapExecutionResult(s.result.execution):void 0,requestId:s.req_id}}async createDeposit(e,t){let a=this.httpClient.urn;if(!a)throw new sdk_core_namespaceObject.BloqueConfigError("User URN is not available. Please connect to a session first.");let r=e.type??"src",o={taker_urn:a,type:r,rate_sig:e.rateSig,from_medium:"breb",to_medium:"kusama",webhook_url:e.webhookUrl,deposit_information:{urn:e.depositInformation.urn}};"src"===r&&e.amountSrc?o.amount_src=e.amountSrc:"dst"===r&&e.amountDst&&(o.amount_dst=e.amountDst),void 0!==e.args&&(o.args=e.args),e.nodeId&&(o.node_id=e.nodeId),e.metadata&&(o.metadata=e.metadata);let s=await this.httpClient.request({method:"PUT",path:"/api/order",body:o,headers:t?.idempotencyKey?{"Idempotency-Key":t.idempotencyKey}:void 0});return{order:this._mapOrderResponse(s.result.order),execution:s.result.execution?this._mapExecutionResult(s.result.execution):void 0,requestId:s.req_id}}_mapPayoutDepositInformationToWire(e){return{resolution_id:e.resolutionId,destination_key:{key_value:e.destinationKey.keyValue,key_type:e.destinationKey.keyType,...e.destinationKey.displayName?{display_name:e.destinationKey.displayName}:{}}}}_mapOrderResponse(e){return{id:e.id,orderSig:e.order_sig,rateSig:e.rate_sig,swapSig:e.swap_sig,taker:e.taker,maker:e.maker,fromAsset:e.from_asset,toAsset:e.to_asset,fromMedium:e.from_medium,toMedium:e.to_medium,fromAmount:e.from_amount,toAmount:e.to_amount,at:e.at,graphId:e.graph_id,status:e.status,metadata:e.metadata,createdAt:e.created_at,updatedAt:e.updated_at}}_mapExecutionResult(e){return{nodeId:e.node_id,result:{status:e.result.status,name:e.result.name,description:e.result.description,how:e.result.how?mapExecutionHow(e.result.how):void 0,callbackToken:e.result.callback_token}}}}class ExternalUsBankSwapClient extends sdk_core_namespaceObject.BaseClient{async create(e,t){let a=this.httpClient.urn;if(!a)throw new sdk_core_namespaceObject.BloqueConfigError("User URN is not available. Please connect to a session first.");let r=e.type??"src",o={taker_urn:a,type:r,rate_sig:e.rateSig,from_medium:"external-us-bank",to_medium:"kusama",webhook_url:e.webhookUrl,deposit_information:{ledger_account_id:e.depositInformation.ledgerAccountId},args:{account_urn:e.args.sourceAccountUrn}};"src"===r&&e.amountSrc?o.amount_src=e.amountSrc:"dst"===r&&e.amountDst&&(o.amount_dst=e.amountDst),e.nodeId&&(o.node_id=e.nodeId),e.metadata&&(o.metadata=e.metadata);let s=await this.httpClient.request({method:"PUT",path:"/api/order",body:o,headers:t?.idempotencyKey?{"Idempotency-Key":t.idempotencyKey}:void 0});return{order:this._mapOrderResponse(s.result.order),execution:s.result.execution?this._mapExecutionResult(s.result.execution):void 0,requestId:s.req_id}}_mapOrderResponse(e){return{id:e.id,orderSig:e.order_sig,rateSig:e.rate_sig,swapSig:e.swap_sig,taker:e.taker,maker:e.maker,fromAsset:e.from_asset,toAsset:e.to_asset,fromMedium:e.from_medium,toMedium:e.to_medium,fromAmount:e.from_amount,toAmount:e.to_amount,at:e.at,graphId:e.graph_id,status:e.status,metadata:e.metadata,webhookUrl:e.webhook_url,failureReason:e.failure_reason,failureDetails:e.failure_details,createdAt:e.created_at,updatedAt:e.updated_at}}_mapExecutionResult(e){return{nodeId:e.node_id,result:{status:e.result.status,name:e.result.name,description:e.result.description,how:e.result.how?mapExecutionHow(e.result.how):void 0,callbackToken:e.result.callback_token}}}}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))}}async create(e,t){let a=this.httpClient.urn;if(!a)throw new sdk_core_namespaceObject.BloqueConfigError("User URN is not available. Please connect to a session first.");let r=e.type??"src",o={taker_urn:a,type:r,rate_sig:e.rateSig,from_medium:"pse",to_medium:e.toMedium,webhook_url:e.webhookUrl,deposit_information:this._mapDepositInformationToWire(e.depositInformation)};"src"===r&&e.amountSrc?o.amount_src=e.amountSrc:"dst"===r&&e.amountDst&&(o.amount_dst=e.amountDst),e.args&&(o.args={bank_code:e.args.bankCode,user_type:e.args.userType,customer_email:e.args.customerEmail,user_legal_id_type:e.args.userLegalIdType,user_legal_id:e.args.userLegalId,redirect_url:e.args.redirectUrl,...e.args.customerData&&{customer_data:{full_name:e.args.customerData.fullName,phone_number:e.args.customerData.phoneNumber}}}),e.nodeId&&(o.node_id=e.nodeId),e.metadata&&(o.metadata=e.metadata);let s=await this.httpClient.request({method:"PUT",path:"/api/order",body:o,headers:t?.idempotencyKey?{"Idempotency-Key":t.idempotencyKey}:void 0});return{order:this._mapOrderResponse(s.result.order),execution:s.result.execution?this._mapExecutionResult(s.result.execution):void 0,requestId:s.req_id}}_mapBankResponse(e){return{code:e.financial_institution_code,name:e.financial_institution_name}}_mapDepositInformationToWire(e){return{urn:e.urn}}_mapOrderResponse(e){return{id:e.id,orderSig:e.order_sig,rateSig:e.rate_sig,swapSig:e.swap_sig,taker:e.taker,maker:e.maker,fromAsset:e.from_asset,toAsset:e.to_asset,fromMedium:e.from_medium,toMedium:e.to_medium,fromAmount:e.from_amount,toAmount:e.to_amount,at:e.at,graphId:e.graph_id,status:e.status,metadata:e.metadata,createdAt:e.created_at,updatedAt:e.updated_at}}_mapExecutionResult(e){return{nodeId:e.node_id,result:{status:e.result.status,name:e.result.name,description:e.result.description,how:e.result.how?mapExecutionHow(e.result.how):void 0,callbackToken:e.result.callback_token}}}}class RtpClient extends sdk_core_namespaceObject.BaseClient{async create(e,t){let a=this.httpClient.urn;if(!a)throw new sdk_core_namespaceObject.BloqueConfigError("User URN is not available. Please connect to a session first.");let r=e.type??"src",o={taker_urn:a,type:r,rate_sig:e.rateSig,from_medium:"kusama",to_medium:"rtp",webhook_url:e.webhookUrl,deposit_information:this._mapDepositInformationToWire(e.depositInformation),args:{account_urn:e.args.sourceAccountUrn}};"src"===r&&e.amountSrc?o.amount_src=e.amountSrc:"dst"===r&&e.amountDst&&(o.amount_dst=e.amountDst),e.nodeId&&(o.node_id=e.nodeId),e.metadata&&(o.metadata=e.metadata);let s=await this.httpClient.request({method:"PUT",path:"/api/order",body:o,headers:t?.idempotencyKey?{"Idempotency-Key":t.idempotencyKey}:void 0});return{order:this._mapOrderResponse(s.result.order),execution:s.result.execution?this._mapExecutionResult(s.result.execution):void 0,requestId:s.req_id}}_mapDepositInformationToWire(e){return{owner:e.owner,account_number:e.accountNumber,routing_number:e.routingNumber,account_type:e.accountType,...e.bankName&&{bank_name:e.bankName}}}_mapOrderResponse(e){return{id:e.id,orderSig:e.order_sig,rateSig:e.rate_sig,swapSig:e.swap_sig,taker:e.taker,maker:e.maker,fromAsset:e.from_asset,toAsset:e.to_asset,fromMedium:e.from_medium,toMedium:e.to_medium,fromAmount:e.from_amount,toAmount:e.to_amount,at:e.at,graphId:e.graph_id,status:e.status,metadata:e.metadata,webhookUrl:e.webhook_url,failureReason:e.failure_reason,failureDetails:e.failure_details,createdAt:e.created_at,updatedAt:e.updated_at}}_mapExecutionResult(e){return{nodeId:e.node_id,result:{status:e.result.status,name:e.result.name,description:e.result.description,how:e.result.how?mapExecutionHow(e.result.how):void 0,callbackToken:e.result.callback_token}}}}class SwapClient extends sdk_core_namespaceObject.BaseClient{pse;bankTransfer;breb;rtp;externalUsBank;constructor(e){super(e),this.pse=new PseClient(this.httpClient),this.bankTransfer=new BankTransferClient(this.httpClient),this.breb=new BrebClient(this.httpClient),this.rtp=new RtpClient(this.httpClient),this.externalUsBank=new ExternalUsBankSwapClient(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(),o=`/api/rates?${r}`;return{rates:(await this.httpClient.request({method:"GET",path:o})).rates.map(e=>this._mapRateResponse(e))}}async listOrders(e={}){let t=this.httpClient.urn;if(!t)throw new sdk_core_namespaceObject.BloqueConfigError("User URN is not available. Please connect to a session first.");let a=new URLSearchParams;e.orderSig&&a.set("order_sig",e.orderSig),e.swapSig&&a.set("swap_sig",e.swapSig),e.rateSig&&a.set("rate_sig",e.rateSig),e.makerUrn&&a.set("maker_urn",e.makerUrn),e.status&&a.set("status",e.status),e.graphId&&a.set("graph_id",e.graphId),void 0!==e.after&&a.set("after",e.after.toString()),void 0!==e.before&&a.set("before",e.before.toString());let r=a.toString(),o=`/api/order/taker/${t}${r?`?${r}`:""}`;return{orders:(await this.httpClient.request({method:"GET",path:o})).orders.map(e=>this._mapOrderResponse(e))}}async cancelSubscription(e){let t=await this.httpClient.request({method:"POST",path:`/api/order/${e.orderId}/cancel-subscription`});return{status:t.result.status,cursor:t.result.cursor,orderId:t.result.order_id,graphId:t.result.graph_id}}_mapOrderResponse(e){return{id:e.id,orderSig:e.order_sig,rateSig:e.rate_sig,swapSig:e.swap_sig,taker:e.taker,maker:e.maker,fromAsset:e.from_asset,toAsset:e.to_asset,fromMedium:e.from_medium,toMedium:e.to_medium,fromAmount:e.from_amount,toAmount:e.to_amount,at:e.at,graphId:e.graph_id,status:e.status,metadata:e.metadata,webhookUrl:e.webhook_url,failureReason:e.failure_reason,failureDetails:e.failure_details,createdAt:e.created_at,updatedAt:e.updated_at}}_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.BankTransferClient=__webpack_exports__.BankTransferClient,exports.BrebClient=__webpack_exports__.BrebClient,exports.ExternalUsBankSwapClient=__webpack_exports__.ExternalUsBankSwapClient,exports.PseClient=__webpack_exports__.PseClient,exports.RtpClient=__webpack_exports__.RtpClient,exports.SwapClient=__webpack_exports__.SwapClient,__webpack_exports__)-1===["BankTransferClient","BrebClient","ExternalUsBankSwapClient","PseClient","RtpClient","SwapClient"].indexOf(__rspack_i)&&(exports[__rspack_i]=__webpack_exports__[__rspack_i]);Object.defineProperty(exports,"__esModule",{value:!0});
|
|
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 r in t)__webpack_require__.o(t,r)&&!__webpack_require__.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},__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__,{PseClient:()=>PseClient,ExternalUsBankSwapClient:()=>ExternalUsBankSwapClient,RtpClient:()=>RtpClient,SwapClient:()=>SwapClient,BankTransferClient:()=>BankTransferClient,BrebClient:()=>BrebClient});const sdk_core_namespaceObject=require("@bloque/sdk-core");function isWireBrebDepositHow(e){return"BREB_DEPOSIT"===e.type}function isWireCallbackHow(e){return"CALLBACK"===e.type&&"args"in e}function isWireIframeHow(e){return"IFRAME"===e.type&&"iframe"in e}function isWireWalletTransferHow(e){return"WALLET_TRANSFER"===e.type&&"address"in e}function mapExecutionHow(e){return isWireBrebDepositHow(e)?{type:"BREB_DEPOSIT",medium:e.medium,keyType:e.key_type,keyValue:e.key_value,amount:e.amount,currency:e.currency,reference:e.reference,depositAccountUrn:e.deposit_account_urn,expectedAmount:e.expected_amount,receivedAmount:e.received_amount,remainingAmount:e.remaining_amount,depositStatus:e.deposit_status}:isWireCallbackHow(e)?{type:"CALLBACK",args:e.args}:isWireIframeHow(e)?{type:"IFRAME",iframe:e.iframe}:isWireWalletTransferHow(e)?{type:"WALLET_TRANSFER",chain:e.chain,address:e.address,tokenAddress:e.token_address,tokenSymbol:e.token_symbol,tokenDecimals:e.token_decimals,amount:e.amount,currency:e.currency,depositAccountUrn:e.deposit_account_urn}:{type:e.type,url:e.url??""}}class BankTransferClient extends sdk_core_namespaceObject.BaseClient{async create(e,t){let r=this.httpClient.urn;if(!r)throw new sdk_core_namespaceObject.BloqueConfigError("User URN is not available. Please connect to a session first.");let a=e.type??"src",o={taker_urn:r,type:a,rate_sig:e.rateSig,from_medium:"kusama",to_medium:e.toMedium,webhook_url:e.webhookUrl,deposit_information:this._mapDepositInformationToWire(e.depositInformation)};"src"===a&&e.amountSrc?o.amount_src=e.amountSrc:"dst"===a&&e.amountDst&&(o.amount_dst=e.amountDst),e.args&&(o.args={account_urn:e.args.sourceAccountUrn}),e.nodeId&&(o.node_id=e.nodeId),e.metadata&&(o.metadata=e.metadata);let s=await this.httpClient.request({method:"PUT",path:"/api/order",body:o,headers:t?.idempotencyKey?{"Idempotency-Key":t.idempotencyKey}:void 0});return{order:this._mapOrderResponse(s.result.order),execution:s.result.execution?this._mapExecutionResult(s.result.execution):void 0,requestId:s.req_id}}_mapDepositInformationToWire(e){return{bank_account_type:e.bankAccountType,bank_account_number:e.bankAccountNumber,bank_account_holder_name:e.bankAccountHolderName,bank_account_holder_identification_type:e.bankAccountHolderIdentificationType,bank_account_holder_identification_value:e.bankAccountHolderIdentificationValue}}_mapOrderResponse(e){return{id:e.id,orderSig:e.order_sig,rateSig:e.rate_sig,swapSig:e.swap_sig,taker:e.taker,maker:e.maker,fromAsset:e.from_asset,toAsset:e.to_asset,fromMedium:e.from_medium,toMedium:e.to_medium,fromAmount:e.from_amount,toAmount:e.to_amount,at:e.at,graphId:e.graph_id,status:e.status,metadata:e.metadata,webhookUrl:e.webhook_url,failureReason:e.failure_reason,failureDetails:e.failure_details,createdAt:e.created_at,updatedAt:e.updated_at}}_mapExecutionResult(e){return{nodeId:e.node_id,result:{status:e.result.status,name:e.result.name,description:e.result.description,how:e.result.how?mapExecutionHow(e.result.how):void 0,callbackToken:e.result.callback_token}}}}class BrebClient extends sdk_core_namespaceObject.BaseClient{async create(e,t){let r=this.httpClient.urn;if(!r)throw new sdk_core_namespaceObject.BloqueConfigError("User URN is not available. Please connect to a session first.");let a=e.type??"src",o={taker_urn:r,type:a,rate_sig:e.rateSig,from_medium:"kusama",to_medium:"breb",webhook_url:e.webhookUrl,deposit_information:this._mapPayoutDepositInformationToWire(e.depositInformation),args:{account_urn:e.args.sourceAccountUrn}};"src"===a&&e.amountSrc?o.amount_src=e.amountSrc:"dst"===a&&e.amountDst&&(o.amount_dst=e.amountDst),e.nodeId&&(o.node_id=e.nodeId),e.metadata&&(o.metadata=e.metadata);let s=await this.httpClient.request({method:"PUT",path:"/api/order",body:o,headers:t?.idempotencyKey?{"Idempotency-Key":t.idempotencyKey}:void 0});return{order:this._mapOrderResponse(s.result.order),execution:s.result.execution?this._mapExecutionResult(s.result.execution):void 0,requestId:s.req_id}}async createDeposit(e,t){let r=this.httpClient.urn;if(!r)throw new sdk_core_namespaceObject.BloqueConfigError("User URN is not available. Please connect to a session first.");let a=e.type??"src",o={taker_urn:r,type:a,rate_sig:e.rateSig,from_medium:"breb",to_medium:"kusama",webhook_url:e.webhookUrl,deposit_information:{urn:e.depositInformation.urn}};"src"===a&&e.amountSrc?o.amount_src=e.amountSrc:"dst"===a&&e.amountDst&&(o.amount_dst=e.amountDst),void 0!==e.args&&(o.args=e.args),e.nodeId&&(o.node_id=e.nodeId),e.metadata&&(o.metadata=e.metadata);let s=await this.httpClient.request({method:"PUT",path:"/api/order",body:o,headers:t?.idempotencyKey?{"Idempotency-Key":t.idempotencyKey}:void 0});return{order:this._mapOrderResponse(s.result.order),execution:s.result.execution?this._mapExecutionResult(s.result.execution):void 0,requestId:s.req_id}}_mapPayoutDepositInformationToWire(e){return{resolution_id:e.resolutionId,destination_key:{key_value:e.destinationKey.keyValue,key_type:e.destinationKey.keyType,...e.destinationKey.displayName?{display_name:e.destinationKey.displayName}:{}}}}_mapOrderResponse(e){return{id:e.id,orderSig:e.order_sig,rateSig:e.rate_sig,swapSig:e.swap_sig,taker:e.taker,maker:e.maker,fromAsset:e.from_asset,toAsset:e.to_asset,fromMedium:e.from_medium,toMedium:e.to_medium,fromAmount:e.from_amount,toAmount:e.to_amount,at:e.at,graphId:e.graph_id,status:e.status,metadata:e.metadata,createdAt:e.created_at,updatedAt:e.updated_at}}_mapExecutionResult(e){return{nodeId:e.node_id,result:{status:e.result.status,name:e.result.name,description:e.result.description,how:e.result.how?mapExecutionHow(e.result.how):void 0,callbackToken:e.result.callback_token}}}}class ExternalUsBankSwapClient extends sdk_core_namespaceObject.BaseClient{async create(e,t){let r=this.httpClient.urn;if(!r)throw new sdk_core_namespaceObject.BloqueConfigError("User URN is not available. Please connect to a session first.");let a=e.type??"src",o=e.toMedium??"kusama",s=this._mapDepositInformation(o,e.depositInformation),n={taker_urn:r,type:a,rate_sig:e.rateSig,from_medium:"external-us-bank",to_medium:o,webhook_url:e.webhookUrl,deposit_information:s,args:{account_urn:e.args.sourceAccountUrn}};"src"===a&&e.amountSrc?n.amount_src=e.amountSrc:"dst"===a&&e.amountDst&&(n.amount_dst=e.amountDst),e.nodeId&&(n.node_id=e.nodeId),e.metadata&&(n.metadata=e.metadata);let i=await this.httpClient.request({method:"PUT",path:"/api/order",body:n,headers:t?.idempotencyKey?{"Idempotency-Key":t.idempotencyKey}:void 0});return{order:this._mapOrderResponse(i.result.order),execution:i.result.execution?this._mapExecutionResult(i.result.execution):void 0,requestId:i.req_id}}_mapDepositInformation(e,t){if("base"===e){if(!("walletAddress"in t)||!t.walletAddress.trim())throw new sdk_core_namespaceObject.BloqueConfigError('toMedium "base" requires depositInformation.walletAddress (0x on Base).');return{wallet_address:t.walletAddress,...t.walletName?{wallet_name:t.walletName}:{}}}if(!("ledgerAccountId"in t)||!t.ledgerAccountId.trim())throw new sdk_core_namespaceObject.BloqueConfigError('toMedium "kusama" requires depositInformation.ledgerAccountId.');return{ledger_account_id:t.ledgerAccountId}}_mapOrderResponse(e){return{id:e.id,orderSig:e.order_sig,rateSig:e.rate_sig,swapSig:e.swap_sig,taker:e.taker,maker:e.maker,fromAsset:e.from_asset,toAsset:e.to_asset,fromMedium:e.from_medium,toMedium:e.to_medium,fromAmount:e.from_amount,toAmount:e.to_amount,at:e.at,graphId:e.graph_id,status:e.status,metadata:e.metadata,webhookUrl:e.webhook_url,failureReason:e.failure_reason,failureDetails:e.failure_details,createdAt:e.created_at,updatedAt:e.updated_at}}_mapExecutionResult(e){return{nodeId:e.node_id,result:{status:e.result.status,name:e.result.name,description:e.result.description,how:e.result.how?mapExecutionHow(e.result.how):void 0,callbackToken:e.result.callback_token}}}}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))}}async create(e,t){let r=this.httpClient.urn;if(!r)throw new sdk_core_namespaceObject.BloqueConfigError("User URN is not available. Please connect to a session first.");let a=e.type??"src",o={taker_urn:r,type:a,rate_sig:e.rateSig,from_medium:"pse",to_medium:e.toMedium,webhook_url:e.webhookUrl,deposit_information:this._mapDepositInformationToWire(e.depositInformation)};"src"===a&&e.amountSrc?o.amount_src=e.amountSrc:"dst"===a&&e.amountDst&&(o.amount_dst=e.amountDst),e.args&&(o.args={bank_code:e.args.bankCode,user_type:e.args.userType,customer_email:e.args.customerEmail,user_legal_id_type:e.args.userLegalIdType,user_legal_id:e.args.userLegalId,redirect_url:e.args.redirectUrl,...e.args.customerData&&{customer_data:{full_name:e.args.customerData.fullName,phone_number:e.args.customerData.phoneNumber}}}),e.nodeId&&(o.node_id=e.nodeId),e.metadata&&(o.metadata=e.metadata);let s=await this.httpClient.request({method:"PUT",path:"/api/order",body:o,headers:t?.idempotencyKey?{"Idempotency-Key":t.idempotencyKey}:void 0});return{order:this._mapOrderResponse(s.result.order),execution:s.result.execution?this._mapExecutionResult(s.result.execution):void 0,requestId:s.req_id}}_mapBankResponse(e){return{code:e.financial_institution_code,name:e.financial_institution_name}}_mapDepositInformationToWire(e){return{urn:e.urn}}_mapOrderResponse(e){return{id:e.id,orderSig:e.order_sig,rateSig:e.rate_sig,swapSig:e.swap_sig,taker:e.taker,maker:e.maker,fromAsset:e.from_asset,toAsset:e.to_asset,fromMedium:e.from_medium,toMedium:e.to_medium,fromAmount:e.from_amount,toAmount:e.to_amount,at:e.at,graphId:e.graph_id,status:e.status,metadata:e.metadata,createdAt:e.created_at,updatedAt:e.updated_at}}_mapExecutionResult(e){return{nodeId:e.node_id,result:{status:e.result.status,name:e.result.name,description:e.result.description,how:e.result.how?mapExecutionHow(e.result.how):void 0,callbackToken:e.result.callback_token}}}}class RtpClient extends sdk_core_namespaceObject.BaseClient{async create(e,t){let r=this.httpClient.urn;if(!r)throw new sdk_core_namespaceObject.BloqueConfigError("User URN is not available. Please connect to a session first.");let a=e.type??"src",o=e.fromMedium??"kusama",s={taker_urn:r,type:a,rate_sig:e.rateSig,from_medium:o,to_medium:"rtp",webhook_url:e.webhookUrl,deposit_information:this._mapDepositInformationToWire(e.depositInformation),args:this._mapArgs(o,e.args)};"src"===a&&e.amountSrc?s.amount_src=e.amountSrc:"dst"===a&&e.amountDst&&(s.amount_dst=e.amountDst),e.nodeId&&(s.node_id=e.nodeId),e.metadata&&(s.metadata=e.metadata);let n=await this.httpClient.request({method:"PUT",path:"/api/order",body:s,headers:t?.idempotencyKey?{"Idempotency-Key":t.idempotencyKey}:void 0});return{order:this._mapOrderResponse(n.result.order),execution:n.result.execution?this._mapExecutionResult(n.result.execution):void 0,requestId:n.req_id}}_mapArgs(e,t){if("base"===e){let e=t&&"txHash"in t?t.txHash?.trim():void 0;return e?{tx_hash:e}:{}}if(!t||!("sourceAccountUrn"in t)||!t.sourceAccountUrn)throw new sdk_core_namespaceObject.BloqueConfigError('fromMedium "kusama" requires args.sourceAccountUrn');return{account_urn:t.sourceAccountUrn}}_mapDepositInformationToWire(e){return{owner:e.owner,account_number:e.accountNumber,routing_number:e.routingNumber,account_type:e.accountType,...e.bankName&&{bank_name:e.bankName}}}_mapOrderResponse(e){return{id:e.id,orderSig:e.order_sig,rateSig:e.rate_sig,swapSig:e.swap_sig,taker:e.taker,maker:e.maker,fromAsset:e.from_asset,toAsset:e.to_asset,fromMedium:e.from_medium,toMedium:e.to_medium,fromAmount:e.from_amount,toAmount:e.to_amount,at:e.at,graphId:e.graph_id,status:e.status,metadata:e.metadata,webhookUrl:e.webhook_url,failureReason:e.failure_reason,failureDetails:e.failure_details,createdAt:e.created_at,updatedAt:e.updated_at}}_mapExecutionResult(e){return{nodeId:e.node_id,result:{status:e.result.status,name:e.result.name,description:e.result.description,how:e.result.how?mapExecutionHow(e.result.how):void 0,callbackToken:e.result.callback_token}}}}class SwapClient extends sdk_core_namespaceObject.BaseClient{pse;bankTransfer;breb;rtp;externalUsBank;constructor(e){super(e),this.pse=new PseClient(this.httpClient),this.bankTransfer=new BankTransferClient(this.httpClient),this.breb=new BrebClient(this.httpClient),this.rtp=new RtpClient(this.httpClient),this.externalUsBank=new ExternalUsBankSwapClient(this.httpClient)}async findRates(e){let t=new URLSearchParams,r=JSON.stringify([e.fromAsset,e.toAsset]);t.append("edge",r),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 a=t.toString(),o=`/api/rates?${a}`;return{rates:(await this.httpClient.request({method:"GET",path:o})).rates.map(e=>this._mapRateResponse(e))}}async listOrders(e={}){let t=this.httpClient.urn;if(!t)throw new sdk_core_namespaceObject.BloqueConfigError("User URN is not available. Please connect to a session first.");let r=new URLSearchParams;e.orderSig&&r.set("order_sig",e.orderSig),e.swapSig&&r.set("swap_sig",e.swapSig),e.rateSig&&r.set("rate_sig",e.rateSig),e.makerUrn&&r.set("maker_urn",e.makerUrn),e.status&&r.set("status",e.status),e.graphId&&r.set("graph_id",e.graphId),void 0!==e.after&&r.set("after",e.after.toString()),void 0!==e.before&&r.set("before",e.before.toString());let a=r.toString(),o=`/api/order/taker/${t}${a?`?${a}`:""}`;return{orders:(await this.httpClient.request({method:"GET",path:o})).orders.map(e=>this._mapOrderResponse(e))}}async cancelSubscription(e){let t=await this.httpClient.request({method:"POST",path:`/api/order/${e.orderId}/cancel-subscription`});return{status:t.result.status,cursor:t.result.cursor,orderId:t.result.order_id,graphId:t.result.graph_id}}_mapOrderResponse(e){return{id:e.id,orderSig:e.order_sig,rateSig:e.rate_sig,swapSig:e.swap_sig,taker:e.taker,maker:e.maker,fromAsset:e.from_asset,toAsset:e.to_asset,fromMedium:e.from_medium,toMedium:e.to_medium,fromAmount:e.from_amount,toAmount:e.to_amount,at:e.at,graphId:e.graph_id,status:e.status,metadata:e.metadata,webhookUrl:e.webhook_url,failureReason:e.failure_reason,failureDetails:e.failure_details,createdAt:e.created_at,updatedAt:e.updated_at}}_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.BankTransferClient=__webpack_exports__.BankTransferClient,exports.BrebClient=__webpack_exports__.BrebClient,exports.ExternalUsBankSwapClient=__webpack_exports__.ExternalUsBankSwapClient,exports.PseClient=__webpack_exports__.PseClient,exports.RtpClient=__webpack_exports__.RtpClient,exports.SwapClient=__webpack_exports__.SwapClient,__webpack_exports__)-1===["BankTransferClient","BrebClient","ExternalUsBankSwapClient","PseClient","RtpClient","SwapClient"].indexOf(__rspack_i)&&(exports[__rspack_i]=__webpack_exports__[__rspack_i]);Object.defineProperty(exports,"__esModule",{value:!0});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
export { BankTransferClient } from './bank-transfer/bank-transfer-client';
|
|
2
|
-
export type { BankAccountType, BankDepositInformation, CreateBankTransferOrderOptions, CreateBankTransferOrderParams, CreateBankTransferOrderResult, ExecutionCallbackArg, ExecutionHow, ExecutionHowBrebDeposit, ExecutionHowCallback, ExecutionHowIframe, ExecutionHowRedirect, ExecutionResult, IdentificationType, KusamaAccountArgs, OrderType, SupportedBank, SwapOrder, } from './bank-transfer/types';
|
|
2
|
+
export type { BankAccountType, BankDepositInformation, CreateBankTransferOrderOptions, CreateBankTransferOrderParams, CreateBankTransferOrderResult, ExecutionCallbackArg, ExecutionHow, ExecutionHowBrebDeposit, ExecutionHowCallback, ExecutionHowIframe, ExecutionHowRedirect, ExecutionHowWalletTransfer, ExecutionResult, IdentificationType, KusamaAccountArgs, OrderType, SupportedBank, SwapOrder, } from './bank-transfer/types';
|
|
3
3
|
export { BrebClient } from './breb/breb-client';
|
|
4
4
|
export type { BrebDepositInformation, BrebDepositOnRampInformation, BrebDestinationKey, BrebSwapArgs, CreateBrebDepositOptions, CreateBrebDepositParams, CreateBrebDepositResult, CreateBrebOrderOptions, CreateBrebOrderParams, CreateBrebOrderResult, } from './breb/types';
|
|
5
5
|
export { ExternalUsBankSwapClient } from './external-us-bank/external-us-bank-client';
|
|
6
|
-
export type { CreateExternalUsBankOrderOptions, CreateExternalUsBankOrderParams, CreateExternalUsBankOrderResult, ExternalUsBankArgs, ExternalUsBankDepositInformation, } from './external-us-bank/types';
|
|
6
|
+
export type { CreateExternalUsBankBaseOrderParams, CreateExternalUsBankKusamaOrderParams, CreateExternalUsBankOrderOptions, CreateExternalUsBankOrderParams, CreateExternalUsBankOrderResult, ExternalUsBankArgs, ExternalUsBankBaseDepositInformation, ExternalUsBankDepositInformation, ExternalUsBankDestination, } from './external-us-bank/types';
|
|
7
7
|
export { PseClient } from './pse/pse-client';
|
|
8
8
|
export type { Bank, CreatePseOrderOptions, CreatePseOrderParams, CreatePseOrderResult, DepositInformation, ListBanksResult, PseCustomerData, PsePaymentArgs, } from './pse/types';
|
|
9
9
|
export { RtpClient } from './rtp/rtp-client';
|
|
10
|
-
export type { CreateRtpOrderOptions, CreateRtpOrderParams, CreateRtpOrderResult, RtpDepositInformation, RtpSwapArgs, } from './rtp/types';
|
|
10
|
+
export type { CreateRtpBaseOrderParams, CreateRtpKusamaOrderParams, CreateRtpOrderOptions, CreateRtpOrderParams, CreateRtpOrderResult, RtpBaseSwapArgs, RtpDepositInformation, RtpSourceMedium, RtpSwapArgs, } from './rtp/types';
|
|
11
11
|
export { SwapClient } from './swap-client';
|
|
12
12
|
export type { Fee, FeeComponent, FeeComponentType, FindRatesParams, FindRatesResult, ListOrdersParams, ListOrdersResult, OrderStatus, RateLimits, RateTuple, SwapRate, } from './types';
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{BaseClient as e,BloqueConfigError as t}from"@bloque/sdk-core";function a(e){return"BREB_DEPOSIT"===e.type?{type:"BREB_DEPOSIT",medium:e.medium,keyType:e.key_type,keyValue:e.key_value,amount:e.amount,currency:e.currency,reference:e.reference,depositAccountUrn:e.deposit_account_urn,expectedAmount:e.expected_amount,receivedAmount:e.received_amount,remainingAmount:e.remaining_amount,depositStatus:e.deposit_status}:"CALLBACK"===e.type&&"args"in e?{type:"CALLBACK",args:e.args}:"IFRAME"===e.type&&"iframe"in e?{type:"IFRAME",iframe:e.iframe}:{type:e.type,url:e.url??""}}class r extends e{async create(e,a){let r=this.httpClient.urn;if(!r)throw new t("User URN is not available. Please connect to a session first.");let o=e.type??"src",s={taker_urn:r,type:o,rate_sig:e.rateSig,from_medium:"kusama",to_medium:e.toMedium,webhook_url:e.webhookUrl,deposit_information:this._mapDepositInformationToWire(e.depositInformation)};"src"===o&&e.amountSrc?s.amount_src=e.amountSrc:"dst"===o&&e.amountDst&&(s.amount_dst=e.amountDst),e.args&&(s.args={account_urn:e.args.sourceAccountUrn}),e.nodeId&&(s.node_id=e.nodeId),e.metadata&&(s.metadata=e.metadata);let i=await this.httpClient.request({method:"PUT",path:"/api/order",body:s,headers:a?.idempotencyKey?{"Idempotency-Key":a.idempotencyKey}:void 0});return{order:this._mapOrderResponse(i.result.order),execution:i.result.execution?this._mapExecutionResult(i.result.execution):void 0,requestId:i.req_id}}_mapDepositInformationToWire(e){return{bank_account_type:e.bankAccountType,bank_account_number:e.bankAccountNumber,bank_account_holder_name:e.bankAccountHolderName,bank_account_holder_identification_type:e.bankAccountHolderIdentificationType,bank_account_holder_identification_value:e.bankAccountHolderIdentificationValue}}_mapOrderResponse(e){return{id:e.id,orderSig:e.order_sig,rateSig:e.rate_sig,swapSig:e.swap_sig,taker:e.taker,maker:e.maker,fromAsset:e.from_asset,toAsset:e.to_asset,fromMedium:e.from_medium,toMedium:e.to_medium,fromAmount:e.from_amount,toAmount:e.to_amount,at:e.at,graphId:e.graph_id,status:e.status,metadata:e.metadata,webhookUrl:e.webhook_url,failureReason:e.failure_reason,failureDetails:e.failure_details,createdAt:e.created_at,updatedAt:e.updated_at}}_mapExecutionResult(e){return{nodeId:e.node_id,result:{status:e.result.status,name:e.result.name,description:e.result.description,how:e.result.how?a(e.result.how):void 0,callbackToken:e.result.callback_token}}}}class o extends e{async create(e,a){let r=this.httpClient.urn;if(!r)throw new t("User URN is not available. Please connect to a session first.");let o=e.type??"src",s={taker_urn:r,type:o,rate_sig:e.rateSig,from_medium:"kusama",to_medium:"breb",webhook_url:e.webhookUrl,deposit_information:this._mapPayoutDepositInformationToWire(e.depositInformation),args:{account_urn:e.args.sourceAccountUrn}};"src"===o&&e.amountSrc?s.amount_src=e.amountSrc:"dst"===o&&e.amountDst&&(s.amount_dst=e.amountDst),e.nodeId&&(s.node_id=e.nodeId),e.metadata&&(s.metadata=e.metadata);let i=await this.httpClient.request({method:"PUT",path:"/api/order",body:s,headers:a?.idempotencyKey?{"Idempotency-Key":a.idempotencyKey}:void 0});return{order:this._mapOrderResponse(i.result.order),execution:i.result.execution?this._mapExecutionResult(i.result.execution):void 0,requestId:i.req_id}}async createDeposit(e,a){let r=this.httpClient.urn;if(!r)throw new t("User URN is not available. Please connect to a session first.");let o=e.type??"src",s={taker_urn:r,type:o,rate_sig:e.rateSig,from_medium:"breb",to_medium:"kusama",webhook_url:e.webhookUrl,deposit_information:{urn:e.depositInformation.urn}};"src"===o&&e.amountSrc?s.amount_src=e.amountSrc:"dst"===o&&e.amountDst&&(s.amount_dst=e.amountDst),void 0!==e.args&&(s.args=e.args),e.nodeId&&(s.node_id=e.nodeId),e.metadata&&(s.metadata=e.metadata);let i=await this.httpClient.request({method:"PUT",path:"/api/order",body:s,headers:a?.idempotencyKey?{"Idempotency-Key":a.idempotencyKey}:void 0});return{order:this._mapOrderResponse(i.result.order),execution:i.result.execution?this._mapExecutionResult(i.result.execution):void 0,requestId:i.req_id}}_mapPayoutDepositInformationToWire(e){return{resolution_id:e.resolutionId,destination_key:{key_value:e.destinationKey.keyValue,key_type:e.destinationKey.keyType,...e.destinationKey.displayName?{display_name:e.destinationKey.displayName}:{}}}}_mapOrderResponse(e){return{id:e.id,orderSig:e.order_sig,rateSig:e.rate_sig,swapSig:e.swap_sig,taker:e.taker,maker:e.maker,fromAsset:e.from_asset,toAsset:e.to_asset,fromMedium:e.from_medium,toMedium:e.to_medium,fromAmount:e.from_amount,toAmount:e.to_amount,at:e.at,graphId:e.graph_id,status:e.status,metadata:e.metadata,createdAt:e.created_at,updatedAt:e.updated_at}}_mapExecutionResult(e){return{nodeId:e.node_id,result:{status:e.result.status,name:e.result.name,description:e.result.description,how:e.result.how?a(e.result.how):void 0,callbackToken:e.result.callback_token}}}}class s extends e{async create(e,a){let r=this.httpClient.urn;if(!r)throw new t("User URN is not available. Please connect to a session first.");let o=e.type??"src",s={taker_urn:r,type:o,rate_sig:e.rateSig,from_medium:"external-us-bank",to_medium:"kusama",webhook_url:e.webhookUrl,deposit_information:{ledger_account_id:e.depositInformation.ledgerAccountId},args:{account_urn:e.args.sourceAccountUrn}};"src"===o&&e.amountSrc?s.amount_src=e.amountSrc:"dst"===o&&e.amountDst&&(s.amount_dst=e.amountDst),e.nodeId&&(s.node_id=e.nodeId),e.metadata&&(s.metadata=e.metadata);let i=await this.httpClient.request({method:"PUT",path:"/api/order",body:s,headers:a?.idempotencyKey?{"Idempotency-Key":a.idempotencyKey}:void 0});return{order:this._mapOrderResponse(i.result.order),execution:i.result.execution?this._mapExecutionResult(i.result.execution):void 0,requestId:i.req_id}}_mapOrderResponse(e){return{id:e.id,orderSig:e.order_sig,rateSig:e.rate_sig,swapSig:e.swap_sig,taker:e.taker,maker:e.maker,fromAsset:e.from_asset,toAsset:e.to_asset,fromMedium:e.from_medium,toMedium:e.to_medium,fromAmount:e.from_amount,toAmount:e.to_amount,at:e.at,graphId:e.graph_id,status:e.status,metadata:e.metadata,webhookUrl:e.webhook_url,failureReason:e.failure_reason,failureDetails:e.failure_details,createdAt:e.created_at,updatedAt:e.updated_at}}_mapExecutionResult(e){return{nodeId:e.node_id,result:{status:e.result.status,name:e.result.name,description:e.result.description,how:e.result.how?a(e.result.how):void 0,callbackToken:e.result.callback_token}}}}class i extends e{async banks(){return{banks:(await this.httpClient.request({method:"GET",path:"/api/utils/pse/banks"})).banks.map(e=>this._mapBankResponse(e))}}async create(e,a){let r=this.httpClient.urn;if(!r)throw new t("User URN is not available. Please connect to a session first.");let o=e.type??"src",s={taker_urn:r,type:o,rate_sig:e.rateSig,from_medium:"pse",to_medium:e.toMedium,webhook_url:e.webhookUrl,deposit_information:this._mapDepositInformationToWire(e.depositInformation)};"src"===o&&e.amountSrc?s.amount_src=e.amountSrc:"dst"===o&&e.amountDst&&(s.amount_dst=e.amountDst),e.args&&(s.args={bank_code:e.args.bankCode,user_type:e.args.userType,customer_email:e.args.customerEmail,user_legal_id_type:e.args.userLegalIdType,user_legal_id:e.args.userLegalId,redirect_url:e.args.redirectUrl,...e.args.customerData&&{customer_data:{full_name:e.args.customerData.fullName,phone_number:e.args.customerData.phoneNumber}}}),e.nodeId&&(s.node_id=e.nodeId),e.metadata&&(s.metadata=e.metadata);let i=await this.httpClient.request({method:"PUT",path:"/api/order",body:s,headers:a?.idempotencyKey?{"Idempotency-Key":a.idempotencyKey}:void 0});return{order:this._mapOrderResponse(i.result.order),execution:i.result.execution?this._mapExecutionResult(i.result.execution):void 0,requestId:i.req_id}}_mapBankResponse(e){return{code:e.financial_institution_code,name:e.financial_institution_name}}_mapDepositInformationToWire(e){return{urn:e.urn}}_mapOrderResponse(e){return{id:e.id,orderSig:e.order_sig,rateSig:e.rate_sig,swapSig:e.swap_sig,taker:e.taker,maker:e.maker,fromAsset:e.from_asset,toAsset:e.to_asset,fromMedium:e.from_medium,toMedium:e.to_medium,fromAmount:e.from_amount,toAmount:e.to_amount,at:e.at,graphId:e.graph_id,status:e.status,metadata:e.metadata,createdAt:e.created_at,updatedAt:e.updated_at}}_mapExecutionResult(e){return{nodeId:e.node_id,result:{status:e.result.status,name:e.result.name,description:e.result.description,how:e.result.how?a(e.result.how):void 0,callbackToken:e.result.callback_token}}}}class n extends e{async create(e,a){let r=this.httpClient.urn;if(!r)throw new t("User URN is not available. Please connect to a session first.");let o=e.type??"src",s={taker_urn:r,type:o,rate_sig:e.rateSig,from_medium:"kusama",to_medium:"rtp",webhook_url:e.webhookUrl,deposit_information:this._mapDepositInformationToWire(e.depositInformation),args:{account_urn:e.args.sourceAccountUrn}};"src"===o&&e.amountSrc?s.amount_src=e.amountSrc:"dst"===o&&e.amountDst&&(s.amount_dst=e.amountDst),e.nodeId&&(s.node_id=e.nodeId),e.metadata&&(s.metadata=e.metadata);let i=await this.httpClient.request({method:"PUT",path:"/api/order",body:s,headers:a?.idempotencyKey?{"Idempotency-Key":a.idempotencyKey}:void 0});return{order:this._mapOrderResponse(i.result.order),execution:i.result.execution?this._mapExecutionResult(i.result.execution):void 0,requestId:i.req_id}}_mapDepositInformationToWire(e){return{owner:e.owner,account_number:e.accountNumber,routing_number:e.routingNumber,account_type:e.accountType,...e.bankName&&{bank_name:e.bankName}}}_mapOrderResponse(e){return{id:e.id,orderSig:e.order_sig,rateSig:e.rate_sig,swapSig:e.swap_sig,taker:e.taker,maker:e.maker,fromAsset:e.from_asset,toAsset:e.to_asset,fromMedium:e.from_medium,toMedium:e.to_medium,fromAmount:e.from_amount,toAmount:e.to_amount,at:e.at,graphId:e.graph_id,status:e.status,metadata:e.metadata,webhookUrl:e.webhook_url,failureReason:e.failure_reason,failureDetails:e.failure_details,createdAt:e.created_at,updatedAt:e.updated_at}}_mapExecutionResult(e){return{nodeId:e.node_id,result:{status:e.result.status,name:e.result.name,description:e.result.description,how:e.result.how?a(e.result.how):void 0,callbackToken:e.result.callback_token}}}}class u extends e{pse;bankTransfer;breb;rtp;externalUsBank;constructor(e){super(e),this.pse=new i(this.httpClient),this.bankTransfer=new r(this.httpClient),this.breb=new o(this.httpClient),this.rtp=new n(this.httpClient),this.externalUsBank=new s(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(),o=`/api/rates?${r}`;return{rates:(await this.httpClient.request({method:"GET",path:o})).rates.map(e=>this._mapRateResponse(e))}}async listOrders(e={}){let a=this.httpClient.urn;if(!a)throw new t("User URN is not available. Please connect to a session first.");let r=new URLSearchParams;e.orderSig&&r.set("order_sig",e.orderSig),e.swapSig&&r.set("swap_sig",e.swapSig),e.rateSig&&r.set("rate_sig",e.rateSig),e.makerUrn&&r.set("maker_urn",e.makerUrn),e.status&&r.set("status",e.status),e.graphId&&r.set("graph_id",e.graphId),void 0!==e.after&&r.set("after",e.after.toString()),void 0!==e.before&&r.set("before",e.before.toString());let o=r.toString(),s=`/api/order/taker/${a}${o?`?${o}`:""}`;return{orders:(await this.httpClient.request({method:"GET",path:s})).orders.map(e=>this._mapOrderResponse(e))}}async cancelSubscription(e){let t=await this.httpClient.request({method:"POST",path:`/api/order/${e.orderId}/cancel-subscription`});return{status:t.result.status,cursor:t.result.cursor,orderId:t.result.order_id,graphId:t.result.graph_id}}_mapOrderResponse(e){return{id:e.id,orderSig:e.order_sig,rateSig:e.rate_sig,swapSig:e.swap_sig,taker:e.taker,maker:e.maker,fromAsset:e.from_asset,toAsset:e.to_asset,fromMedium:e.from_medium,toMedium:e.to_medium,fromAmount:e.from_amount,toAmount:e.to_amount,at:e.at,graphId:e.graph_id,status:e.status,metadata:e.metadata,webhookUrl:e.webhook_url,failureReason:e.failure_reason,failureDetails:e.failure_details,createdAt:e.created_at,updatedAt:e.updated_at}}_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}}}export{r as BankTransferClient,o as BrebClient,s as ExternalUsBankSwapClient,i as PseClient,n as RtpClient,u as SwapClient};
|
|
1
|
+
import{BaseClient as e,BloqueConfigError as t}from"@bloque/sdk-core";function a(e){return"BREB_DEPOSIT"===e.type?{type:"BREB_DEPOSIT",medium:e.medium,keyType:e.key_type,keyValue:e.key_value,amount:e.amount,currency:e.currency,reference:e.reference,depositAccountUrn:e.deposit_account_urn,expectedAmount:e.expected_amount,receivedAmount:e.received_amount,remainingAmount:e.remaining_amount,depositStatus:e.deposit_status}:"CALLBACK"===e.type&&"args"in e?{type:"CALLBACK",args:e.args}:"IFRAME"===e.type&&"iframe"in e?{type:"IFRAME",iframe:e.iframe}:"WALLET_TRANSFER"===e.type&&"address"in e?{type:"WALLET_TRANSFER",chain:e.chain,address:e.address,tokenAddress:e.token_address,tokenSymbol:e.token_symbol,tokenDecimals:e.token_decimals,amount:e.amount,currency:e.currency,depositAccountUrn:e.deposit_account_urn}:{type:e.type,url:e.url??""}}class r extends e{async create(e,a){let r=this.httpClient.urn;if(!r)throw new t("User URN is not available. Please connect to a session first.");let o=e.type??"src",s={taker_urn:r,type:o,rate_sig:e.rateSig,from_medium:"kusama",to_medium:e.toMedium,webhook_url:e.webhookUrl,deposit_information:this._mapDepositInformationToWire(e.depositInformation)};"src"===o&&e.amountSrc?s.amount_src=e.amountSrc:"dst"===o&&e.amountDst&&(s.amount_dst=e.amountDst),e.args&&(s.args={account_urn:e.args.sourceAccountUrn}),e.nodeId&&(s.node_id=e.nodeId),e.metadata&&(s.metadata=e.metadata);let n=await this.httpClient.request({method:"PUT",path:"/api/order",body:s,headers:a?.idempotencyKey?{"Idempotency-Key":a.idempotencyKey}:void 0});return{order:this._mapOrderResponse(n.result.order),execution:n.result.execution?this._mapExecutionResult(n.result.execution):void 0,requestId:n.req_id}}_mapDepositInformationToWire(e){return{bank_account_type:e.bankAccountType,bank_account_number:e.bankAccountNumber,bank_account_holder_name:e.bankAccountHolderName,bank_account_holder_identification_type:e.bankAccountHolderIdentificationType,bank_account_holder_identification_value:e.bankAccountHolderIdentificationValue}}_mapOrderResponse(e){return{id:e.id,orderSig:e.order_sig,rateSig:e.rate_sig,swapSig:e.swap_sig,taker:e.taker,maker:e.maker,fromAsset:e.from_asset,toAsset:e.to_asset,fromMedium:e.from_medium,toMedium:e.to_medium,fromAmount:e.from_amount,toAmount:e.to_amount,at:e.at,graphId:e.graph_id,status:e.status,metadata:e.metadata,webhookUrl:e.webhook_url,failureReason:e.failure_reason,failureDetails:e.failure_details,createdAt:e.created_at,updatedAt:e.updated_at}}_mapExecutionResult(e){return{nodeId:e.node_id,result:{status:e.result.status,name:e.result.name,description:e.result.description,how:e.result.how?a(e.result.how):void 0,callbackToken:e.result.callback_token}}}}class o extends e{async create(e,a){let r=this.httpClient.urn;if(!r)throw new t("User URN is not available. Please connect to a session first.");let o=e.type??"src",s={taker_urn:r,type:o,rate_sig:e.rateSig,from_medium:"kusama",to_medium:"breb",webhook_url:e.webhookUrl,deposit_information:this._mapPayoutDepositInformationToWire(e.depositInformation),args:{account_urn:e.args.sourceAccountUrn}};"src"===o&&e.amountSrc?s.amount_src=e.amountSrc:"dst"===o&&e.amountDst&&(s.amount_dst=e.amountDst),e.nodeId&&(s.node_id=e.nodeId),e.metadata&&(s.metadata=e.metadata);let n=await this.httpClient.request({method:"PUT",path:"/api/order",body:s,headers:a?.idempotencyKey?{"Idempotency-Key":a.idempotencyKey}:void 0});return{order:this._mapOrderResponse(n.result.order),execution:n.result.execution?this._mapExecutionResult(n.result.execution):void 0,requestId:n.req_id}}async createDeposit(e,a){let r=this.httpClient.urn;if(!r)throw new t("User URN is not available. Please connect to a session first.");let o=e.type??"src",s={taker_urn:r,type:o,rate_sig:e.rateSig,from_medium:"breb",to_medium:"kusama",webhook_url:e.webhookUrl,deposit_information:{urn:e.depositInformation.urn}};"src"===o&&e.amountSrc?s.amount_src=e.amountSrc:"dst"===o&&e.amountDst&&(s.amount_dst=e.amountDst),void 0!==e.args&&(s.args=e.args),e.nodeId&&(s.node_id=e.nodeId),e.metadata&&(s.metadata=e.metadata);let n=await this.httpClient.request({method:"PUT",path:"/api/order",body:s,headers:a?.idempotencyKey?{"Idempotency-Key":a.idempotencyKey}:void 0});return{order:this._mapOrderResponse(n.result.order),execution:n.result.execution?this._mapExecutionResult(n.result.execution):void 0,requestId:n.req_id}}_mapPayoutDepositInformationToWire(e){return{resolution_id:e.resolutionId,destination_key:{key_value:e.destinationKey.keyValue,key_type:e.destinationKey.keyType,...e.destinationKey.displayName?{display_name:e.destinationKey.displayName}:{}}}}_mapOrderResponse(e){return{id:e.id,orderSig:e.order_sig,rateSig:e.rate_sig,swapSig:e.swap_sig,taker:e.taker,maker:e.maker,fromAsset:e.from_asset,toAsset:e.to_asset,fromMedium:e.from_medium,toMedium:e.to_medium,fromAmount:e.from_amount,toAmount:e.to_amount,at:e.at,graphId:e.graph_id,status:e.status,metadata:e.metadata,createdAt:e.created_at,updatedAt:e.updated_at}}_mapExecutionResult(e){return{nodeId:e.node_id,result:{status:e.result.status,name:e.result.name,description:e.result.description,how:e.result.how?a(e.result.how):void 0,callbackToken:e.result.callback_token}}}}class s extends e{async create(e,a){let r=this.httpClient.urn;if(!r)throw new t("User URN is not available. Please connect to a session first.");let o=e.type??"src",s=e.toMedium??"kusama",n=this._mapDepositInformation(s,e.depositInformation),i={taker_urn:r,type:o,rate_sig:e.rateSig,from_medium:"external-us-bank",to_medium:s,webhook_url:e.webhookUrl,deposit_information:n,args:{account_urn:e.args.sourceAccountUrn}};"src"===o&&e.amountSrc?i.amount_src=e.amountSrc:"dst"===o&&e.amountDst&&(i.amount_dst=e.amountDst),e.nodeId&&(i.node_id=e.nodeId),e.metadata&&(i.metadata=e.metadata);let u=await this.httpClient.request({method:"PUT",path:"/api/order",body:i,headers:a?.idempotencyKey?{"Idempotency-Key":a.idempotencyKey}:void 0});return{order:this._mapOrderResponse(u.result.order),execution:u.result.execution?this._mapExecutionResult(u.result.execution):void 0,requestId:u.req_id}}_mapDepositInformation(e,a){if("base"===e){if(!("walletAddress"in a)||!a.walletAddress.trim())throw new t('toMedium "base" requires depositInformation.walletAddress (0x on Base).');return{wallet_address:a.walletAddress,...a.walletName?{wallet_name:a.walletName}:{}}}if(!("ledgerAccountId"in a)||!a.ledgerAccountId.trim())throw new t('toMedium "kusama" requires depositInformation.ledgerAccountId.');return{ledger_account_id:a.ledgerAccountId}}_mapOrderResponse(e){return{id:e.id,orderSig:e.order_sig,rateSig:e.rate_sig,swapSig:e.swap_sig,taker:e.taker,maker:e.maker,fromAsset:e.from_asset,toAsset:e.to_asset,fromMedium:e.from_medium,toMedium:e.to_medium,fromAmount:e.from_amount,toAmount:e.to_amount,at:e.at,graphId:e.graph_id,status:e.status,metadata:e.metadata,webhookUrl:e.webhook_url,failureReason:e.failure_reason,failureDetails:e.failure_details,createdAt:e.created_at,updatedAt:e.updated_at}}_mapExecutionResult(e){return{nodeId:e.node_id,result:{status:e.result.status,name:e.result.name,description:e.result.description,how:e.result.how?a(e.result.how):void 0,callbackToken:e.result.callback_token}}}}class n extends e{async banks(){return{banks:(await this.httpClient.request({method:"GET",path:"/api/utils/pse/banks"})).banks.map(e=>this._mapBankResponse(e))}}async create(e,a){let r=this.httpClient.urn;if(!r)throw new t("User URN is not available. Please connect to a session first.");let o=e.type??"src",s={taker_urn:r,type:o,rate_sig:e.rateSig,from_medium:"pse",to_medium:e.toMedium,webhook_url:e.webhookUrl,deposit_information:this._mapDepositInformationToWire(e.depositInformation)};"src"===o&&e.amountSrc?s.amount_src=e.amountSrc:"dst"===o&&e.amountDst&&(s.amount_dst=e.amountDst),e.args&&(s.args={bank_code:e.args.bankCode,user_type:e.args.userType,customer_email:e.args.customerEmail,user_legal_id_type:e.args.userLegalIdType,user_legal_id:e.args.userLegalId,redirect_url:e.args.redirectUrl,...e.args.customerData&&{customer_data:{full_name:e.args.customerData.fullName,phone_number:e.args.customerData.phoneNumber}}}),e.nodeId&&(s.node_id=e.nodeId),e.metadata&&(s.metadata=e.metadata);let n=await this.httpClient.request({method:"PUT",path:"/api/order",body:s,headers:a?.idempotencyKey?{"Idempotency-Key":a.idempotencyKey}:void 0});return{order:this._mapOrderResponse(n.result.order),execution:n.result.execution?this._mapExecutionResult(n.result.execution):void 0,requestId:n.req_id}}_mapBankResponse(e){return{code:e.financial_institution_code,name:e.financial_institution_name}}_mapDepositInformationToWire(e){return{urn:e.urn}}_mapOrderResponse(e){return{id:e.id,orderSig:e.order_sig,rateSig:e.rate_sig,swapSig:e.swap_sig,taker:e.taker,maker:e.maker,fromAsset:e.from_asset,toAsset:e.to_asset,fromMedium:e.from_medium,toMedium:e.to_medium,fromAmount:e.from_amount,toAmount:e.to_amount,at:e.at,graphId:e.graph_id,status:e.status,metadata:e.metadata,createdAt:e.created_at,updatedAt:e.updated_at}}_mapExecutionResult(e){return{nodeId:e.node_id,result:{status:e.result.status,name:e.result.name,description:e.result.description,how:e.result.how?a(e.result.how):void 0,callbackToken:e.result.callback_token}}}}class i extends e{async create(e,a){let r=this.httpClient.urn;if(!r)throw new t("User URN is not available. Please connect to a session first.");let o=e.type??"src",s=e.fromMedium??"kusama",n={taker_urn:r,type:o,rate_sig:e.rateSig,from_medium:s,to_medium:"rtp",webhook_url:e.webhookUrl,deposit_information:this._mapDepositInformationToWire(e.depositInformation),args:this._mapArgs(s,e.args)};"src"===o&&e.amountSrc?n.amount_src=e.amountSrc:"dst"===o&&e.amountDst&&(n.amount_dst=e.amountDst),e.nodeId&&(n.node_id=e.nodeId),e.metadata&&(n.metadata=e.metadata);let i=await this.httpClient.request({method:"PUT",path:"/api/order",body:n,headers:a?.idempotencyKey?{"Idempotency-Key":a.idempotencyKey}:void 0});return{order:this._mapOrderResponse(i.result.order),execution:i.result.execution?this._mapExecutionResult(i.result.execution):void 0,requestId:i.req_id}}_mapArgs(e,a){if("base"===e){let e=a&&"txHash"in a?a.txHash?.trim():void 0;return e?{tx_hash:e}:{}}if(!a||!("sourceAccountUrn"in a)||!a.sourceAccountUrn)throw new t('fromMedium "kusama" requires args.sourceAccountUrn');return{account_urn:a.sourceAccountUrn}}_mapDepositInformationToWire(e){return{owner:e.owner,account_number:e.accountNumber,routing_number:e.routingNumber,account_type:e.accountType,...e.bankName&&{bank_name:e.bankName}}}_mapOrderResponse(e){return{id:e.id,orderSig:e.order_sig,rateSig:e.rate_sig,swapSig:e.swap_sig,taker:e.taker,maker:e.maker,fromAsset:e.from_asset,toAsset:e.to_asset,fromMedium:e.from_medium,toMedium:e.to_medium,fromAmount:e.from_amount,toAmount:e.to_amount,at:e.at,graphId:e.graph_id,status:e.status,metadata:e.metadata,webhookUrl:e.webhook_url,failureReason:e.failure_reason,failureDetails:e.failure_details,createdAt:e.created_at,updatedAt:e.updated_at}}_mapExecutionResult(e){return{nodeId:e.node_id,result:{status:e.result.status,name:e.result.name,description:e.result.description,how:e.result.how?a(e.result.how):void 0,callbackToken:e.result.callback_token}}}}class u extends e{pse;bankTransfer;breb;rtp;externalUsBank;constructor(e){super(e),this.pse=new n(this.httpClient),this.bankTransfer=new r(this.httpClient),this.breb=new o(this.httpClient),this.rtp=new i(this.httpClient),this.externalUsBank=new s(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(),o=`/api/rates?${r}`;return{rates:(await this.httpClient.request({method:"GET",path:o})).rates.map(e=>this._mapRateResponse(e))}}async listOrders(e={}){let a=this.httpClient.urn;if(!a)throw new t("User URN is not available. Please connect to a session first.");let r=new URLSearchParams;e.orderSig&&r.set("order_sig",e.orderSig),e.swapSig&&r.set("swap_sig",e.swapSig),e.rateSig&&r.set("rate_sig",e.rateSig),e.makerUrn&&r.set("maker_urn",e.makerUrn),e.status&&r.set("status",e.status),e.graphId&&r.set("graph_id",e.graphId),void 0!==e.after&&r.set("after",e.after.toString()),void 0!==e.before&&r.set("before",e.before.toString());let o=r.toString(),s=`/api/order/taker/${a}${o?`?${o}`:""}`;return{orders:(await this.httpClient.request({method:"GET",path:s})).orders.map(e=>this._mapOrderResponse(e))}}async cancelSubscription(e){let t=await this.httpClient.request({method:"POST",path:`/api/order/${e.orderId}/cancel-subscription`});return{status:t.result.status,cursor:t.result.cursor,orderId:t.result.order_id,graphId:t.result.graph_id}}_mapOrderResponse(e){return{id:e.id,orderSig:e.order_sig,rateSig:e.rate_sig,swapSig:e.swap_sig,taker:e.taker,maker:e.maker,fromAsset:e.from_asset,toAsset:e.to_asset,fromMedium:e.from_medium,toMedium:e.to_medium,fromAmount:e.from_amount,toAmount:e.to_amount,at:e.at,graphId:e.graph_id,status:e.status,metadata:e.metadata,webhookUrl:e.webhook_url,failureReason:e.failure_reason,failureDetails:e.failure_details,createdAt:e.created_at,updatedAt:e.updated_at}}_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}}}export{r as BankTransferClient,o as BrebClient,s as ExternalUsBankSwapClient,n as PseClient,i as RtpClient,u as SwapClient};
|
|
@@ -90,6 +90,10 @@ export interface DepositInformation {
|
|
|
90
90
|
};
|
|
91
91
|
/** External US bank on-ramp: destination Kusama ledger account id */
|
|
92
92
|
ledger_account_id?: string;
|
|
93
|
+
/** External US bank on-ramp to Base: destination 0x */
|
|
94
|
+
wallet_address?: string;
|
|
95
|
+
/** External US bank on-ramp to Base: optional destination wallet label */
|
|
96
|
+
wallet_name?: string;
|
|
93
97
|
/** RTP payout: account holder name */
|
|
94
98
|
owner?: string;
|
|
95
99
|
/** RTP payout: bank account number */
|
|
@@ -224,11 +228,26 @@ export interface ExecutionHowBrebDeposit {
|
|
|
224
228
|
/** `awaiting` on first pause; `partial` after an underpayment. */
|
|
225
229
|
deposit_status?: 'awaiting' | 'partial';
|
|
226
230
|
}
|
|
231
|
+
/**
|
|
232
|
+
* @internal
|
|
233
|
+
* Base USDC inbox transfer instructions when the graph pauses
|
|
234
|
+
*/
|
|
235
|
+
export interface ExecutionHowWalletTransfer {
|
|
236
|
+
type: 'WALLET_TRANSFER';
|
|
237
|
+
chain: 'base';
|
|
238
|
+
address: string;
|
|
239
|
+
token_address: string;
|
|
240
|
+
token_symbol: 'USDC';
|
|
241
|
+
token_decimals: 6;
|
|
242
|
+
amount: string;
|
|
243
|
+
currency: 'USDC';
|
|
244
|
+
deposit_account_urn: string;
|
|
245
|
+
}
|
|
227
246
|
/**
|
|
228
247
|
* @internal
|
|
229
248
|
* Discriminated union of execution instructions
|
|
230
249
|
*/
|
|
231
|
-
export type ExecutionHow = ExecutionHowRedirect | ExecutionHowCallback | ExecutionHowIframe | ExecutionHowBrebDeposit;
|
|
250
|
+
export type ExecutionHow = ExecutionHowRedirect | ExecutionHowCallback | ExecutionHowIframe | ExecutionHowBrebDeposit | ExecutionHowWalletTransfer;
|
|
232
251
|
/**
|
|
233
252
|
* @internal
|
|
234
253
|
* Execution result from auto-execution
|
package/dist/rtp/rtp-client.d.ts
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
import { BaseClient } from '@bloque/sdk-core';
|
|
2
2
|
import type { CreateRtpOrderOptions, CreateRtpOrderParams, CreateRtpOrderResult } from './types';
|
|
3
3
|
/**
|
|
4
|
-
* RTP client for US instant bank payouts (Kusama → US bank
|
|
4
|
+
* RTP client for US instant bank payouts (Kusama DUSD or Base USDC → US bank).
|
|
5
5
|
*/
|
|
6
6
|
export declare class RtpClient extends BaseClient {
|
|
7
7
|
/**
|
|
8
|
-
* Create an RTP payout swap order (DUSD on Kusama → USD to
|
|
8
|
+
* Create an RTP payout swap order (DUSD on Kusama or USDC on Base → USD to
|
|
9
|
+
* a US bank).
|
|
10
|
+
*
|
|
11
|
+
* Omit `fromMedium` (or pass `'kusama'`) to debit DUSD from a Kusama
|
|
12
|
+
* account (`args.sourceAccountUrn` required). Pass `fromMedium: 'base'`
|
|
13
|
+
* with bank `depositInformation` only — the graph ensures a `base-rtp`
|
|
14
|
+
* inbox and pauses with `WALLET_TRANSFER` how. Optional `args.txHash`
|
|
15
|
+
* skips the pause when USDC is already in that inbox.
|
|
9
16
|
*
|
|
10
17
|
* @param params - RTP order parameters including destination bank details
|
|
11
18
|
* @returns Promise resolving to the created order
|
|
@@ -32,8 +39,33 @@ export declare class RtpClient extends BaseClient {
|
|
|
32
39
|
* args: { sourceAccountUrn: 'did:bloque:account:kusama-user-001' },
|
|
33
40
|
* });
|
|
34
41
|
* ```
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* const rates = await bloque.swap.findRates({
|
|
46
|
+
* fromAsset: 'USDC/6',
|
|
47
|
+
* toAsset: 'USD/2',
|
|
48
|
+
* fromMediums: ['base'],
|
|
49
|
+
* toMediums: ['rtp'],
|
|
50
|
+
* amountSrc: '100000000',
|
|
51
|
+
* });
|
|
52
|
+
*
|
|
53
|
+
* const result = await bloque.swap.rtp.create({
|
|
54
|
+
* rateSig: rates.rates[0].sig,
|
|
55
|
+
* amountSrc: '100000000',
|
|
56
|
+
* fromMedium: 'base',
|
|
57
|
+
* depositInformation: {
|
|
58
|
+
* owner: 'Jane Doe',
|
|
59
|
+
* accountNumber: '1234567890',
|
|
60
|
+
* routingNumber: '063108680',
|
|
61
|
+
* accountType: 'checking',
|
|
62
|
+
* },
|
|
63
|
+
* });
|
|
64
|
+
* // result.execution?.result.how → WALLET_TRANSFER (Base USDC inbox 0x)
|
|
65
|
+
* ```
|
|
35
66
|
*/
|
|
36
67
|
create(params: CreateRtpOrderParams, options?: CreateRtpOrderOptions): Promise<CreateRtpOrderResult>;
|
|
68
|
+
private _mapArgs;
|
|
37
69
|
private _mapDepositInformationToWire;
|
|
38
70
|
private _mapOrderResponse;
|
|
39
71
|
private _mapExecutionResult;
|
package/dist/rtp/types.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { ExecutionHow, ExecutionResult, OrderType, SwapOrder } from '../bank-transfer/types';
|
|
2
2
|
export type { ExecutionHow, ExecutionResult, OrderType, SwapOrder };
|
|
3
|
+
/** Source medium for an RTP payout. */
|
|
4
|
+
export type RtpSourceMedium = 'kusama' | 'base';
|
|
3
5
|
/**
|
|
4
|
-
* US bank details for RTP payout (Kusama → US bank via RTP).
|
|
6
|
+
* US bank details for RTP payout (Kusama or Base → US bank via RTP).
|
|
5
7
|
*/
|
|
6
8
|
export interface RtpDepositInformation {
|
|
7
9
|
/** Account holder name */
|
|
@@ -17,14 +19,23 @@ export interface RtpDepositInformation {
|
|
|
17
19
|
}
|
|
18
20
|
export interface RtpSwapArgs {
|
|
19
21
|
/**
|
|
20
|
-
* Kusama account URN
|
|
22
|
+
* Kusama account URN holding DUSD to debit.
|
|
21
23
|
*/
|
|
22
24
|
sourceAccountUrn: string;
|
|
23
25
|
}
|
|
24
26
|
/**
|
|
25
|
-
*
|
|
27
|
+
* Optional Base RTP take args. Omit the object entirely to pause for a
|
|
28
|
+
* USDC deposit (`execution.how` is `WALLET_TRANSFER`). Pass `txHash` only
|
|
29
|
+
* when USDC is already in the inbox and you want to skip the pause.
|
|
26
30
|
*/
|
|
27
|
-
export interface
|
|
31
|
+
export interface RtpBaseSwapArgs {
|
|
32
|
+
/**
|
|
33
|
+
* Transaction hash of a native USDC transfer **into the Base RTP inbox**.
|
|
34
|
+
* Omit or leave empty to pause; do not invent a hash.
|
|
35
|
+
*/
|
|
36
|
+
txHash?: string;
|
|
37
|
+
}
|
|
38
|
+
interface CreateRtpOrderParamsBase {
|
|
28
39
|
/**
|
|
29
40
|
* Rate signature from findRates.
|
|
30
41
|
*/
|
|
@@ -49,10 +60,6 @@ export interface CreateRtpOrderParams {
|
|
|
49
60
|
* Destination US bank account details.
|
|
50
61
|
*/
|
|
51
62
|
depositInformation: RtpDepositInformation;
|
|
52
|
-
/**
|
|
53
|
-
* Source Kusama account for the debit leg.
|
|
54
|
-
*/
|
|
55
|
-
args: RtpSwapArgs;
|
|
56
63
|
/**
|
|
57
64
|
* Specific node ID to execute (defaults to first node).
|
|
58
65
|
*/
|
|
@@ -62,6 +69,31 @@ export interface CreateRtpOrderParams {
|
|
|
62
69
|
*/
|
|
63
70
|
metadata?: Record<string, unknown>;
|
|
64
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* RTP payout from DUSD on Kusama. `fromMedium` may be omitted — Kusama is the default.
|
|
74
|
+
*/
|
|
75
|
+
export interface CreateRtpKusamaOrderParams extends CreateRtpOrderParamsBase {
|
|
76
|
+
fromMedium?: 'kusama';
|
|
77
|
+
args: RtpSwapArgs;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* RTP payout from USDC on Base. `args` is optional — the live API does not
|
|
81
|
+
* require a source URN or tx hash. The create call still sends empty `args`
|
|
82
|
+
* so the first graph node auto-executes and returns the deposit `how`.
|
|
83
|
+
*/
|
|
84
|
+
export interface CreateRtpBaseOrderParams extends CreateRtpOrderParamsBase {
|
|
85
|
+
fromMedium: 'base';
|
|
86
|
+
args?: RtpBaseSwapArgs;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Parameters for creating an RTP payout swap order.
|
|
90
|
+
*
|
|
91
|
+
* Defaults to Kusama (`fromMedium` omitted), which still requires
|
|
92
|
+
* `args.sourceAccountUrn`. Pass `fromMedium: 'base'` with bank
|
|
93
|
+
* `depositInformation` only to cash out USDC on Base; optional `args.txHash`
|
|
94
|
+
* skips the wallet-transfer pause.
|
|
95
|
+
*/
|
|
96
|
+
export type CreateRtpOrderParams = CreateRtpKusamaOrderParams | CreateRtpBaseOrderParams;
|
|
65
97
|
export interface CreateRtpOrderOptions {
|
|
66
98
|
/**
|
|
67
99
|
* Optional custom idempotency key sent as `Idempotency-Key` header.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bloque/sdk-swap",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bloque",
|
|
@@ -34,6 +34,6 @@
|
|
|
34
34
|
"node": ">=22"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@bloque/sdk-core": "0.
|
|
37
|
+
"@bloque/sdk-core": "0.13.1"
|
|
38
38
|
}
|
|
39
39
|
}
|