@bloque/sdk-swap 0.13.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/index.cjs +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/internal/wire-types.d.ts +16 -1
- package/dist/rtp/rtp-client.d.ts +5 -6
- package/dist/rtp/types.d.ts +18 -12
- 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
|
*/
|
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 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 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 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?.trim();if(!e)throw new sdk_core_namespaceObject.BloqueConfigError('fromMedium "base" requires args.txHash of the USDC transfer on Base.');return{urn:t.sourceAccountUrn,tx_hash:e}}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});
|
|
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,5 +1,5 @@
|
|
|
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';
|
|
@@ -7,6 +7,6 @@ export type { CreateExternalUsBankBaseOrderParams, CreateExternalUsBankKusamaOrd
|
|
|
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 { CreateRtpBaseOrderParams, CreateRtpKusamaOrderParams, CreateRtpOrderOptions, CreateRtpOrderParams, CreateRtpOrderResult, RtpDepositInformation, RtpSourceMedium, 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=e.toMedium??"kusama",i=this._mapDepositInformation(s,e.depositInformation),n={taker_urn:r,type:o,rate_sig:e.rateSig,from_medium:"external-us-bank",to_medium:s,webhook_url:e.webhookUrl,deposit_information:i,args:{account_urn:e.args.sourceAccountUrn}};"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 u=await this.httpClient.request({method:"PUT",path:"/api/order",body:n,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 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=e.fromMedium??"kusama",i={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?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 n=await this.httpClient.request({method:"PUT",path:"/api/order",body:i,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}}_mapArgs(e,a){if("base"===e){let e=a.txHash?.trim();if(!e)throw new t('fromMedium "base" requires args.txHash of the USDC transfer on Base.');return{urn:a.sourceAccountUrn,tx_hash:e}}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 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};
|
|
@@ -228,11 +228,26 @@ export interface ExecutionHowBrebDeposit {
|
|
|
228
228
|
/** `awaiting` on first pause; `partial` after an underpayment. */
|
|
229
229
|
deposit_status?: 'awaiting' | 'partial';
|
|
230
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
|
+
}
|
|
231
246
|
/**
|
|
232
247
|
* @internal
|
|
233
248
|
* Discriminated union of execution instructions
|
|
234
249
|
*/
|
|
235
|
-
export type ExecutionHow = ExecutionHowRedirect | ExecutionHowCallback | ExecutionHowIframe | ExecutionHowBrebDeposit;
|
|
250
|
+
export type ExecutionHow = ExecutionHowRedirect | ExecutionHowCallback | ExecutionHowIframe | ExecutionHowBrebDeposit | ExecutionHowWalletTransfer;
|
|
236
251
|
/**
|
|
237
252
|
* @internal
|
|
238
253
|
* Execution result from auto-execution
|
package/dist/rtp/rtp-client.d.ts
CHANGED
|
@@ -9,8 +9,10 @@ export declare class RtpClient extends BaseClient {
|
|
|
9
9
|
* a US bank).
|
|
10
10
|
*
|
|
11
11
|
* Omit `fromMedium` (or pass `'kusama'`) to debit DUSD from a Kusama
|
|
12
|
-
* account. Pass `fromMedium: 'base'`
|
|
13
|
-
*
|
|
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.
|
|
14
16
|
*
|
|
15
17
|
* @param params - RTP order parameters including destination bank details
|
|
16
18
|
* @returns Promise resolving to the created order
|
|
@@ -58,11 +60,8 @@ export declare class RtpClient extends BaseClient {
|
|
|
58
60
|
* routingNumber: '063108680',
|
|
59
61
|
* accountType: 'checking',
|
|
60
62
|
* },
|
|
61
|
-
* args: {
|
|
62
|
-
* sourceAccountUrn: 'did:bloque:account:polygon:abc123',
|
|
63
|
-
* txHash: '0xabc…',
|
|
64
|
-
* },
|
|
65
63
|
* });
|
|
64
|
+
* // result.execution?.result.how → WALLET_TRANSFER (Base USDC inbox 0x)
|
|
66
65
|
* ```
|
|
67
66
|
*/
|
|
68
67
|
create(params: CreateRtpOrderParams, options?: CreateRtpOrderOptions): Promise<CreateRtpOrderResult>;
|
package/dist/rtp/types.d.ts
CHANGED
|
@@ -19,15 +19,19 @@ export interface RtpDepositInformation {
|
|
|
19
19
|
}
|
|
20
20
|
export interface RtpSwapArgs {
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* Kusama: the Kusama account holding DUSD.
|
|
25
|
-
* Base: the EVM/Polygon account that received USDC on Base.
|
|
22
|
+
* Kusama account URN holding DUSD to debit.
|
|
26
23
|
*/
|
|
27
24
|
sourceAccountUrn: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
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.
|
|
30
|
+
*/
|
|
31
|
+
export interface RtpBaseSwapArgs {
|
|
28
32
|
/**
|
|
29
|
-
* Transaction hash of
|
|
30
|
-
*
|
|
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.
|
|
31
35
|
*/
|
|
32
36
|
txHash?: string;
|
|
33
37
|
}
|
|
@@ -73,19 +77,21 @@ export interface CreateRtpKusamaOrderParams extends CreateRtpOrderParamsBase {
|
|
|
73
77
|
args: RtpSwapArgs;
|
|
74
78
|
}
|
|
75
79
|
/**
|
|
76
|
-
* RTP payout from USDC on Base.
|
|
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`.
|
|
77
83
|
*/
|
|
78
84
|
export interface CreateRtpBaseOrderParams extends CreateRtpOrderParamsBase {
|
|
79
85
|
fromMedium: 'base';
|
|
80
|
-
args
|
|
81
|
-
txHash: string;
|
|
82
|
-
};
|
|
86
|
+
args?: RtpBaseSwapArgs;
|
|
83
87
|
}
|
|
84
88
|
/**
|
|
85
89
|
* Parameters for creating an RTP payout swap order.
|
|
86
90
|
*
|
|
87
|
-
* Defaults to Kusama (`fromMedium` omitted)
|
|
88
|
-
* `args.
|
|
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.
|
|
89
95
|
*/
|
|
90
96
|
export type CreateRtpOrderParams = CreateRtpKusamaOrderParams | CreateRtpBaseOrderParams;
|
|
91
97
|
export interface CreateRtpOrderOptions {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bloque/sdk-swap",
|
|
3
|
-
"version": "0.13.
|
|
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.13.
|
|
37
|
+
"@bloque/sdk-core": "0.13.1"
|
|
38
38
|
}
|
|
39
39
|
}
|