From acbe8c6696b0aa54a7f886a90d6de8d5ada44dd5 Mon Sep 17 00:00:00 2001 From: Felipe Tavares Date: Fri, 11 Nov 2022 09:12:27 +1100 Subject: [PATCH] PT-64: add exchange flows (#201) * PT-64: Add exchange flow * Add methods for Exchange * Adding new line in the EOF for code standards. * Adding line break in the EOF for code standards * remove walletConnection where not used * [PT-153] Add example for exchange transfer * remove outaded comments * update parameters for example Co-authored-by: Anastasia Bashkirtseva Co-authored-by: Deepti Luthra <109640446+deepti-imx@users.noreply.github.com> Co-authored-by: Renato Lucas Chitolina Co-authored-by: Deepti Luthra --- examples/createExchangeTransfer.ts | 24 + examples/package.json | 1 + openapi.json | 621 +++++++++++++- src/ImmutableX.ts | 74 ++ src/api/.openapi-generator/FILES | 10 + src/api/.openapi-generator/VERSION | 2 +- src/api/api.ts | 1 + src/api/base.ts | 2 +- src/api/domain/exchanges-api.ts | 769 ++++++++++++++++++ src/api/models/aggregate-limit.ts | 36 + .../create-exchange-and-urlapirequest.ts | 59 ++ src/api/models/currency-with-limits.ts | 51 ++ ...xchange-create-exchange-and-urlresponse.ts | 54 ++ src/api/models/exchange.ts | 75 ++ src/api/models/get-transactions-response.ts | 45 + src/api/models/index.ts | 9 + src/api/models/lambdas-apierror.ts | 48 ++ src/api/models/mint-token-data-v2.ts | 2 +- src/api/models/optional-exchange-data.ts | 72 ++ src/api/models/signable-token.ts | 2 +- src/api/models/widget-params.ts | 42 + src/types/requests.ts | 17 +- src/types/tokens.ts | 5 + src/workflows/exchangeTransfers.ts | 63 ++ src/workflows/workflows.ts | 18 + 25 files changed, 2090 insertions(+), 12 deletions(-) create mode 100644 examples/createExchangeTransfer.ts create mode 100644 src/api/domain/exchanges-api.ts create mode 100644 src/api/models/aggregate-limit.ts create mode 100644 src/api/models/create-exchange-and-urlapirequest.ts create mode 100644 src/api/models/currency-with-limits.ts create mode 100644 src/api/models/exchange-create-exchange-and-urlresponse.ts create mode 100644 src/api/models/exchange.ts create mode 100644 src/api/models/get-transactions-response.ts create mode 100644 src/api/models/lambdas-apierror.ts create mode 100644 src/api/models/optional-exchange-data.ts create mode 100644 src/api/models/widget-params.ts create mode 100644 src/workflows/exchangeTransfers.ts diff --git a/examples/createExchangeTransfer.ts b/examples/createExchangeTransfer.ts new file mode 100644 index 00000000..05f665dc --- /dev/null +++ b/examples/createExchangeTransfer.ts @@ -0,0 +1,24 @@ +import { ImmutableX, Config, UnsignedExchangeTransferRequest } from '@imtbl/core-sdk'; +import { generateWalletConnection } from './libs/walletConnection'; + +(async () => { + const walletConnection = await generateWalletConnection('goerli'); + + const imxClient = new ImmutableX(Config.SANDBOX); + + const exchangeTransferParams: UnsignedExchangeTransferRequest = { + type: "ETH", + amount:'0.001', + transactionID: '0', + receiver: '' + }; + + try { + const exchangeTransferResponse = await imxClient.exchangeTransfer(walletConnection, exchangeTransferParams) + + console.log('exchangeTransferResponse', exchangeTransferResponse); + } catch (error) { + console.error(error); + process.exit(1); + } +})(); diff --git a/examples/package.json b/examples/package.json index 1b22c776..9616d364 100644 --- a/examples/package.json +++ b/examples/package.json @@ -6,6 +6,7 @@ "scripts": { "create-order": "ts-node -r dotenv/config createOrder.ts", "create-trade": "ts-node -r dotenv/config createTrade.ts", + "create-exchange-transfer": "ts-node -r dotenv/config createExchangeTransfer.ts", "deposit-eth": "ts-node -r dotenv/config depositEth.ts", "create-eth-withdrawal": "ts-node -r dotenv/config createEthWithdrawal.ts", "complete-eth-withdrawal": "ts-node -r dotenv/config completeEthWithdrawal.ts", diff --git a/openapi.json b/openapi.json index eb23e649..fea4b5f7 100644 --- a/openapi.json +++ b/openapi.json @@ -11,7 +11,7 @@ }, "version": "3.0" }, - "host": "api.ropsten.x.immutable.com", + "host": "api.sandbox.x.immutable.com", "basePath": "/", "paths": { "/v1/assets": { @@ -1080,15 +1080,15 @@ "$ref": "#/definitions/CreateMetadataRefreshResponse" }, "headers": { - "Refresh_Limit_Reset": { + "x-imx-refresh-limit-reset": { "type": "string", "description": "The expiry date of the current one-hour window." }, - "Refreshes_Limit": { + "x-imx-refreshes-limit": { "type": "string", "description": "The refresh request limit available to the project for each one-hour window." }, - "Remaining_Refreshes": { + "x-imx-remaining-refreshes": { "type": "string", "description": "The amount of refresh requests remaining for current one-hour window." } @@ -1116,6 +1116,20 @@ "description": "Too Many Requests", "schema": { "$ref": "#/definitions/APIError" + }, + "headers": { + "x-imx-refresh-limit-reset": { + "type": "string", + "description": "The expiry date of the current one-hour window." + }, + "x-imx-refreshes-limit": { + "type": "string", + "description": "The refresh request limit available to the project for each one-hour window." + }, + "x-imx-remaining-refreshes": { + "type": "string", + "description": "The amount of refresh requests remaining for current one-hour window." + } } }, "500": { @@ -3255,6 +3269,116 @@ } } }, + "/v2/exchanges/{id}/signable-transfer-details": { + "post": { + "description": "Send a request for signable-transfer-details (offramp)", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "exchanges" + ], + "summary": "Send a request for signable-transfer-details (offramp)", + "operationId": "getExchangeSignableTransfer", + "parameters": [ + { + "description": "get details of signable transfer", + "name": "GetSignableTransferRequest", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/GetSignableTransferRequestV1" + } + }, + { + "type": "string", + "description": "Transaction ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/GetSignableTransferResponseV1" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/lambdas.APIError" + } + } + } + } + }, + "/v2/exchanges/{id}/transfers": { + "post": { + "description": "Accepts a transfer request and updates the transfer_status after processing transfer (offramp)", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "exchanges" + ], + "summary": "Accepts a transfer request and updates the transfer_status after processing transfer (offramp)", + "operationId": "createExchangeTransfer", + "parameters": [ + { + "description": "Create a transfer", + "name": "CreateTransferRequest", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/CreateTransferRequestV1" + } + }, + { + "type": "string", + "description": "Transaction ID", + "name": "id", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "eth address", + "name": "x-imx-eth-address", + "in": "header", + "required": true + }, + { + "type": "string", + "description": "eth signature", + "name": "x-imx-eth-signature", + "in": "header", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/CreateTransferResponseV1" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/lambdas.APIError" + } + } + } + } + }, "/v2/mints": { "post": { "description": "Mint tokens in a batch with fees", @@ -3463,6 +3587,256 @@ } } }, + "/v3/exchanges": { + "get": { + "description": "Returns a list of exchanges based on the request", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "exchanges" + ], + "summary": "Returns a list of exchanges based on the request", + "operationId": "getExchanges", + "parameters": [ + { + "type": "integer", + "description": "Page size of the result", + "name": "page_size", + "in": "query" + }, + { + "type": "string", + "description": "Cursor", + "name": "cursor", + "in": "query" + }, + { + "enum": [ + "id", + "status", + "exchange", + "amount", + "transfer_id" + ], + "type": "string", + "description": "Property to sort by", + "name": "order_by", + "in": "query" + }, + { + "enum": [ + "asc", + "desc" + ], + "type": "string", + "description": "Direction to sort", + "name": "direction", + "in": "query" + }, + { + "type": "integer", + "description": "Transaction ID", + "name": "id", + "in": "query" + }, + { + "type": "string", + "description": "Ethereum address of the user who created transaction", + "name": "wallet_address", + "in": "query" + }, + { + "enum": [ + "created", + "pending", + "completed", + "failed", + "waitingPayment", + "timedOut" + ], + "type": "string", + "description": "Transaction status", + "name": "status", + "in": "query" + }, + { + "enum": [ + "moonpay" + ], + "type": "string", + "description": "Provider name", + "name": "provider", + "in": "query" + }, + { + "type": "string", + "description": "Transfer ID", + "name": "transfer_id", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/GetTransactionsResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/lambdas.APIError" + } + } + } + }, + "post": { + "description": "Receive wallet_address, provider, type and widget information to create a base exchange transaction and return widget URL", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "exchanges" + ], + "summary": "Create an exchange with URL", + "operationId": "createExchange", + "parameters": [ + { + "description": "req", + "name": "CreateExchangeAPIRequest", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/CreateExchangeAndURLAPIRequest" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/exchange.CreateExchangeAndURLResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/lambdas.APIError" + } + } + } + } + }, + "/v3/exchanges/currencies/{type}": { + "get": { + "description": "Returns a list of supported currencies and their limits", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "exchanges" + ], + "summary": "Get currencies with limits", + "operationId": "getCurrencies", + "parameters": [ + { + "enum": [ + "onramp", + "offramp" + ], + "type": "string", + "description": "Exchange type", + "name": "type", + "in": "path", + "required": true + }, + { + "enum": [ + "moonpay" + ], + "type": "string", + "description": "Provider name", + "name": "provider", + "in": "query" + }, + { + "type": "boolean", + "description": "Flag if limits should be included in the response or not", + "name": "include_limits", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/CurrencyWithLimits" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/lambdas.APIError" + } + } + } + } + }, + "/v3/exchanges/{id}": { + "get": { + "description": "Get an exchange by ID", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "exchanges" + ], + "summary": "Get an exchange by ID", + "operationId": "getExchange", + "parameters": [ + { + "type": "string", + "description": "Exchange ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/Exchange" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/lambdas.APIError" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/lambdas.APIError" + } + } + } + } + }, "/v3/signable-order-details": { "post": { "description": "Get a signable order request (V3)", @@ -3985,6 +4359,32 @@ } } }, + "CreateExchangeAndURLAPIRequest": { + "type": "object", + "properties": { + "provider": { + "description": "Provider name", + "type": "string", + "example": "moonpay" + }, + "type": { + "description": "Transaction type", + "type": "string", + "enum": [ + "onramp", + "offramp" + ] + }, + "wallet_address": { + "description": "Ethereum address of the user who wants to create transaction", + "type": "string" + }, + "widget": { + "description": "Optional widget params", + "$ref": "#/definitions/WidgetParams" + } + } + }, "CreateMetadataRefreshRequest": { "type": "object", "required": [ @@ -4416,6 +4816,30 @@ } } }, + "CurrencyWithLimits": { + "type": "object", + "properties": { + "currency_code": { + "description": "Provider currency code", + "type": "string", + "example": "eth_immutable" + }, + "limits": { + "description": "Currency limits will be null by default", + "$ref": "#/definitions/aggregate.Limit" + }, + "provider": { + "description": "Provider name (e.g. moonpay)", + "type": "string", + "example": "moonpay" + }, + "symbol": { + "description": "Currency Symbol", + "type": "string", + "example": "ETH" + } + } + }, "Deposit": { "type": "object", "required": [ @@ -4497,6 +4921,46 @@ } } }, + "Exchange": { + "type": "object", + "properties": { + "created_at": { + "description": "Time this transaction was created", + "type": "string" + }, + "data": { + "description": "Additional transaction data", + "$ref": "#/definitions/OptionalExchangeData" + }, + "id": { + "description": "Transaction ID", + "type": "integer" + }, + "provider": { + "description": "Provider name", + "type": "string", + "example": "moonpay" + }, + "status": { + "description": "Transaction status", + "type": "string", + "example": "created, pending, completed, failed, waitingPayment, timedOut" + }, + "type": { + "description": "Transaction type", + "type": "string", + "example": "onramp" + }, + "updated_at": { + "description": "Time this transaction was updates", + "type": "string" + }, + "wallet_address": { + "description": "Ethereum address of the user who created transaction", + "type": "string" + } + } + }, "Fee": { "type": "object", "required": [ @@ -5237,6 +5701,26 @@ } } }, + "GetTransactionsResponse": { + "type": "object", + "properties": { + "cursor": { + "description": "Generated cursor returned by previous query", + "type": "string" + }, + "remaining": { + "description": "Remaining results flag. 1: there are remaining results matching this query, 0: no remaining results", + "type": "integer" + }, + "result": { + "description": "Transactions matching query parameters", + "type": "array", + "items": { + "$ref": "#/definitions/Exchange" + } + } + } + }, "GetUsersApiResponse": { "type": "object", "required": [ @@ -5759,7 +6243,7 @@ "type": "string" }, "id": { - "description": "Token ID", + "description": "Token ID\nNote: While the Token ID is required to be a string, it still needs to be a valid uint256 as per the ERC-721 token standard.", "type": "string" }, "royalties": { @@ -5828,6 +6312,43 @@ } } }, + "OptionalExchangeData": { + "type": "object", + "properties": { + "external_id": { + "description": "Provider transaction ID", + "type": "string" + }, + "fees_amount": { + "description": "Fees amount", + "type": "number" + }, + "from_amount": { + "description": "Amount that was exchanged from", + "type": "number" + }, + "from_currency": { + "description": "Currency that was exchanged from", + "type": "string" + }, + "provider_wallet_address": { + "description": "Provider wallet address that was used for transferring crypto", + "type": "string" + }, + "to_amount": { + "description": "Amount that was exchanged to", + "type": "number" + }, + "to_currency": { + "description": "Currency that was exchanged to", + "type": "string" + }, + "transfer_id": { + "description": "Transfer ID", + "type": "string" + } + } + }, "Order": { "type": "object", "required": [ @@ -6045,7 +6566,7 @@ "type": "object", "properties": { "data": { - "description": "Token data. See https://docs.x.immutable.com/docs/token-data-object\"" + "description": "Token data. See https://docs.x.immutable.com/docs/token-data-object" }, "type": { "description": "Type of token", @@ -6407,6 +6928,31 @@ } } }, + "WidgetParams": { + "type": "object", + "properties": { + "amount": { + "description": "Amount that will be prefilled in the widget", + "type": "string" + }, + "supported_currencies": { + "description": "Currencies that will be available in the widget. If not defined all available currencies will be shown", + "type": "array", + "items": { + "type": "string" + }, + "example": [ + "ETH", + "USDC" + ] + }, + "theme": { + "description": "Widget theme dark by default", + "type": "string", + "example": "light" + } + } + }, "Withdrawal": { "type": "object", "required": [ @@ -6449,6 +6995,19 @@ } } }, + "aggregate.Limit": { + "type": "object", + "properties": { + "max_amount": { + "description": "Max transaction amount", + "type": "number" + }, + "min_amount": { + "description": "Min transaction amount", + "type": "number" + } + } + }, "encodeAssetRequestToken": { "type": "object", "properties": { @@ -6467,6 +7026,54 @@ } }, "x-go-gen-location": "models" + }, + "exchange.CreateExchangeAndURLResponse": { + "type": "object", + "properties": { + "id": { + "description": "Created transaction ID", + "type": "integer" + }, + "provider": { + "description": "Provider name (e.g. moonpay)", + "type": "string", + "example": "moonpay" + }, + "type": { + "description": "Transaction type", + "type": "string", + "example": "onramp" + }, + "url": { + "description": "Widget URL", + "type": "string" + }, + "wallet_address": { + "description": "Ethereum address of the user who created transaction", + "type": "string" + } + } + }, + "lambdas.APIError": { + "type": "object", + "properties": { + "code": { + "description": "The error code", + "type": "string" + }, + "details": { + "description": "The error details", + "type": "string" + }, + "message": { + "description": "The error message", + "type": "string" + }, + "status_code": { + "description": "The error status code", + "type": "integer" + } + } } } -} \ No newline at end of file +} diff --git a/src/ImmutableX.ts b/src/ImmutableX.ts index 745047f9..a5054a2c 100644 --- a/src/ImmutableX.ts +++ b/src/ImmutableX.ts @@ -3,6 +3,7 @@ import { EthSigner, NftTransferDetails, TokenAmount, + UnsignedExchangeTransferRequest, UnsignedMintRequest, UnsignedOrderRequest, UnsignedTransferRequest, @@ -54,6 +55,11 @@ import { TransfersApiListTransfersRequest, MetadataRefreshesApi, CreateMetadataRefreshRequest, + ExchangesApi, + ExchangesApiCreateExchangeRequest, + ExchangesApiGetExchangeRequest, + ExchangesApiGetExchangesRequest, + ExchangesApiGetCurrenciesRequest, } from './api'; import { formatError } from './utils/formatError'; import { ImmutableXConfiguration } from './config'; @@ -68,6 +74,7 @@ export class ImmutableX { private tokensApi: TokensApi; private tradesApi: TradesApi; private transfersApi: TransfersApi; + private exchangeApi: ExchangesApi; private usersApi: UsersApi; private withdrawalsApi: WithdrawalsApi; private balanceApi: BalancesApi; @@ -85,6 +92,7 @@ export class ImmutableX { this.tokensApi = new TokensApi(config.apiConfiguration); this.tradesApi = new TradesApi(config.apiConfiguration); this.transfersApi = new TransfersApi(config.apiConfiguration); + this.exchangeApi = new ExchangesApi(config.apiConfiguration); this.usersApi = new UsersApi(config.apiConfiguration); this.withdrawalsApi = new WithdrawalsApi(config.apiConfiguration); this.balanceApi = new BalancesApi(config.apiConfiguration); @@ -839,4 +847,70 @@ export class ImmutableX { throw formatError(err); }); } + + /** + * Create a new Exchange transaction + * @param request - the request object to be provided in the API request + * @returns a promise that resolves with the created Exchange Transaction + * @throws {@link index.IMXError} + */ + public createExchange(request: ExchangesApiCreateExchangeRequest) { + return this.exchangeApi.createExchange(request).catch(err => { + throw formatError(err); + }); + } + + /** + * Get an Exchange transaction + * @param request - the request object to be provided in the API request + * @returns a promise that resolves with the Exchange Transaction + * @throws {@link index.IMXError} + */ + public getExchange(request: ExchangesApiGetExchangeRequest) { + return this.exchangeApi.getExchange(request).catch(err => { + throw formatError(err); + }); + } + + /** + * Get Exchange transactions + * @param request - the request object to be provided in the API request + * @returns a promise that resolves with Exchange Transactions + * @throws {@link index.IMXError} + */ + public getExchanges(request: ExchangesApiGetExchangesRequest) { + return this.exchangeApi.getExchanges(request).catch(err => { + throw formatError(err); + }); + } + + /** + * Get Exchange currencies + * @param request - the request object to be provided in the API request + * @returns a promise that resolves with Exchange Currencies + * @throws {@link index.IMXError} + */ + public getExchangeCurrencies(request: ExchangesApiGetCurrenciesRequest) { + return this.exchangeApi.getCurrencies(request).catch(err => { + throw formatError(err); + }); + } + + /** + * Create a new Transfer request + * @param walletConnection - the pair of Eth/Stark signers + * @param request - the request object to be provided in the API request + * @returns a promise that resolves with the created Exchange Transfer + * @throws {@link index.IMXError} + */ + public exchangeTransfer( + walletConnection: WalletConnection, + request: UnsignedExchangeTransferRequest, + ) { + return this.workflows + .exchangeTransfer(walletConnection, request) + .catch(err => { + throw formatError(err); + }); + } } diff --git a/src/api/.openapi-generator/FILES b/src/api/.openapi-generator/FILES index 725c65a6..67a214f2 100644 --- a/src/api/.openapi-generator/FILES +++ b/src/api/.openapi-generator/FILES @@ -10,6 +10,7 @@ domain/balances-api.ts domain/collections-api.ts domain/deposits-api.ts domain/encoding-api.ts +domain/exchanges-api.ts domain/metadata-api.ts domain/metadata-refreshes-api.ts domain/mints-api.ts @@ -23,6 +24,7 @@ domain/withdrawals-api.ts git_push.sh index.ts models/add-metadata-schema-to-collection-request.ts +models/aggregate-limit.ts models/apierror.ts models/asset-properties.ts models/asset-with-orders.ts @@ -34,6 +36,7 @@ models/collection-details.ts models/collection-filter.ts models/collection.ts models/create-collection-request.ts +models/create-exchange-and-urlapirequest.ts models/create-metadata-refresh-request.ts models/create-metadata-refresh-response.ts models/create-order-request.ts @@ -48,11 +51,14 @@ models/create-transfer-response-v1.ts models/create-transfer-response.ts models/create-withdrawal-request.ts models/create-withdrawal-response.ts +models/currency-with-limits.ts models/deposit.ts models/encode-asset-request-token.ts models/encode-asset-request.ts models/encode-asset-response.ts models/encode-asset-token-data.ts +models/exchange-create-exchange-and-urlresponse.ts +models/exchange.ts models/fee-data.ts models/fee-entry.ts models/fee-info.ts @@ -79,8 +85,10 @@ models/get-signable-transfer-response-v1.ts models/get-signable-transfer-response.ts models/get-signable-withdrawal-request.ts models/get-signable-withdrawal-response.ts +models/get-transactions-response.ts models/get-users-api-response.ts models/index.ts +models/lambdas-apierror.ts models/list-assets-response.ts models/list-balances-response.ts models/list-collections-response.ts @@ -104,6 +112,7 @@ models/mint-tokens-response.ts models/mint-user.ts models/mint.ts models/mintable-token-details.ts +models/optional-exchange-data.ts models/order-details.ts models/order-fee-info.ts models/order.ts @@ -123,4 +132,5 @@ models/trade.ts models/transfer-request.ts models/transfer.ts models/update-collection-request.ts +models/widget-params.ts models/withdrawal.ts diff --git a/src/api/.openapi-generator/VERSION b/src/api/.openapi-generator/VERSION index 7b7e20b5..adebc31e 100644 --- a/src/api/.openapi-generator/VERSION +++ b/src/api/.openapi-generator/VERSION @@ -1 +1 @@ -6.1.1-SNAPSHOT \ No newline at end of file +6.2.1-SNAPSHOT diff --git a/src/api/api.ts b/src/api/api.ts index f2d05af7..a65dffbd 100644 --- a/src/api/api.ts +++ b/src/api/api.ts @@ -19,6 +19,7 @@ export * from './domain/balances-api'; export * from './domain/collections-api'; export * from './domain/deposits-api'; export * from './domain/encoding-api'; +export * from './domain/exchanges-api'; export * from './domain/metadata-api'; export * from './domain/metadata-refreshes-api'; export * from './domain/mints-api'; diff --git a/src/api/base.ts b/src/api/base.ts index fd8781c0..5f82b77a 100644 --- a/src/api/base.ts +++ b/src/api/base.ts @@ -18,7 +18,7 @@ import { Configuration } from "./configuration"; // @ts-ignore import globalAxios, { AxiosPromise, AxiosInstance, AxiosRequestConfig } from 'axios'; -export const BASE_PATH = "https://api.ropsten.x.immutable.com".replace(/\/+$/, ""); +export const BASE_PATH = "https://api.sandbox.x.immutable.com".replace(/\/+$/, ""); /** * diff --git a/src/api/domain/exchanges-api.ts b/src/api/domain/exchanges-api.ts new file mode 100644 index 00000000..94950bd9 --- /dev/null +++ b/src/api/domain/exchanges-api.ts @@ -0,0 +1,769 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * Immutable X API + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 3.0 + * Contact: support@immutable.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +import globalAxios, { AxiosPromise, AxiosInstance, AxiosRequestConfig } from 'axios'; +import { Configuration } from '../configuration'; +// Some imports not used depending on template conditions +// @ts-ignore +import { DUMMY_BASE_URL, assertParamExists, setApiKeyToObject, setBasicAuthToObject, setBearerAuthToObject, setOAuthToObject, setSearchParams, serializeDataIfNeeded, toPathString, createRequestFunction } from '../common'; +// @ts-ignore +import { BASE_PATH, COLLECTION_FORMATS, RequestArgs, BaseAPI, RequiredError } from '../base'; +// @ts-ignore +import { CreateExchangeAndURLAPIRequest } from '../models'; +// @ts-ignore +import { CreateTransferRequestV1 } from '../models'; +// @ts-ignore +import { CreateTransferResponseV1 } from '../models'; +// @ts-ignore +import { CurrencyWithLimits } from '../models'; +// @ts-ignore +import { Exchange } from '../models'; +// @ts-ignore +import { ExchangeCreateExchangeAndURLResponse } from '../models'; +// @ts-ignore +import { GetSignableTransferRequestV1 } from '../models'; +// @ts-ignore +import { GetSignableTransferResponseV1 } from '../models'; +// @ts-ignore +import { GetTransactionsResponse } from '../models'; +// @ts-ignore +import { LambdasAPIError } from '../models'; +/** + * ExchangesApi - axios parameter creator + * @export + */ +export const ExchangesApiAxiosParamCreator = function (configuration?: Configuration) { + return { + /** + * Receive wallet_address, provider, type and widget information to create a base exchange transaction and return widget URL + * @summary Create an exchange with URL + * @param {CreateExchangeAndURLAPIRequest} createExchangeAPIRequest req + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + createExchange: async (createExchangeAPIRequest: CreateExchangeAndURLAPIRequest, options: AxiosRequestConfig = {}): Promise => { + // verify required parameter 'createExchangeAPIRequest' is not null or undefined + assertParamExists('createExchange', 'createExchangeAPIRequest', createExchangeAPIRequest) + const localVarPath = `/v3/exchanges`; + // use dummy base URL string because the URL constructor only accepts absolute URLs. + const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); + let baseOptions; + if (configuration) { + baseOptions = configuration.baseOptions; + } + + const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options}; + const localVarHeaderParameter = {} as any; + const localVarQueryParameter = {} as any; + + + + localVarHeaderParameter['Content-Type'] = 'application/json'; + + setSearchParams(localVarUrlObj, localVarQueryParameter); + let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; + localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; + localVarRequestOptions.data = serializeDataIfNeeded(createExchangeAPIRequest, localVarRequestOptions, configuration) + + return { + url: toPathString(localVarUrlObj), + options: localVarRequestOptions, + }; + }, + /** + * Accepts a transfer request and updates the transfer_status after processing transfer (offramp) + * @summary Accepts a transfer request and updates the transfer_status after processing transfer (offramp) + * @param {string} id Transaction ID + * @param {string} xImxEthAddress eth address + * @param {string} xImxEthSignature eth signature + * @param {CreateTransferRequestV1} createTransferRequest Create a transfer + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + createExchangeTransfer: async (id: string, xImxEthAddress: string, xImxEthSignature: string, createTransferRequest: CreateTransferRequestV1, options: AxiosRequestConfig = {}): Promise => { + // verify required parameter 'id' is not null or undefined + assertParamExists('createExchangeTransfer', 'id', id) + // verify required parameter 'xImxEthAddress' is not null or undefined + assertParamExists('createExchangeTransfer', 'xImxEthAddress', xImxEthAddress) + // verify required parameter 'xImxEthSignature' is not null or undefined + assertParamExists('createExchangeTransfer', 'xImxEthSignature', xImxEthSignature) + // verify required parameter 'createTransferRequest' is not null or undefined + assertParamExists('createExchangeTransfer', 'createTransferRequest', createTransferRequest) + const localVarPath = `/v2/exchanges/{id}/transfers` + .replace(`{${"id"}}`, encodeURIComponent(String(id))); + // use dummy base URL string because the URL constructor only accepts absolute URLs. + const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); + let baseOptions; + if (configuration) { + baseOptions = configuration.baseOptions; + } + + const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options}; + const localVarHeaderParameter = {} as any; + const localVarQueryParameter = {} as any; + + if (xImxEthAddress != null) { + localVarHeaderParameter['x-imx-eth-address'] = String(xImxEthAddress); + } + + if (xImxEthSignature != null) { + localVarHeaderParameter['x-imx-eth-signature'] = String(xImxEthSignature); + } + + + + localVarHeaderParameter['Content-Type'] = 'application/json'; + + setSearchParams(localVarUrlObj, localVarQueryParameter); + let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; + localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; + localVarRequestOptions.data = serializeDataIfNeeded(createTransferRequest, localVarRequestOptions, configuration) + + return { + url: toPathString(localVarUrlObj), + options: localVarRequestOptions, + }; + }, + /** + * Returns a list of supported currencies and their limits + * @summary Get currencies with limits + * @param {'onramp' | 'offramp'} type Exchange type + * @param {'moonpay'} [provider] Provider name + * @param {boolean} [includeLimits] Flag if limits should be included in the response or not + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + getCurrencies: async (type: 'onramp' | 'offramp', provider?: 'moonpay', includeLimits?: boolean, options: AxiosRequestConfig = {}): Promise => { + // verify required parameter 'type' is not null or undefined + assertParamExists('getCurrencies', 'type', type) + const localVarPath = `/v3/exchanges/currencies/{type}` + .replace(`{${"type"}}`, encodeURIComponent(String(type))); + // use dummy base URL string because the URL constructor only accepts absolute URLs. + const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); + let baseOptions; + if (configuration) { + baseOptions = configuration.baseOptions; + } + + const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options}; + const localVarHeaderParameter = {} as any; + const localVarQueryParameter = {} as any; + + if (provider !== undefined) { + localVarQueryParameter['provider'] = provider; + } + + if (includeLimits !== undefined) { + localVarQueryParameter['include_limits'] = includeLimits; + } + + + + setSearchParams(localVarUrlObj, localVarQueryParameter); + let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; + localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; + + return { + url: toPathString(localVarUrlObj), + options: localVarRequestOptions, + }; + }, + /** + * Get an exchange by ID + * @summary Get an exchange by ID + * @param {string} id Exchange ID + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + getExchange: async (id: string, options: AxiosRequestConfig = {}): Promise => { + // verify required parameter 'id' is not null or undefined + assertParamExists('getExchange', 'id', id) + const localVarPath = `/v3/exchanges/{id}` + .replace(`{${"id"}}`, encodeURIComponent(String(id))); + // use dummy base URL string because the URL constructor only accepts absolute URLs. + const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); + let baseOptions; + if (configuration) { + baseOptions = configuration.baseOptions; + } + + const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options}; + const localVarHeaderParameter = {} as any; + const localVarQueryParameter = {} as any; + + + + setSearchParams(localVarUrlObj, localVarQueryParameter); + let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; + localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; + + return { + url: toPathString(localVarUrlObj), + options: localVarRequestOptions, + }; + }, + /** + * Send a request for signable-transfer-details (offramp) + * @summary Send a request for signable-transfer-details (offramp) + * @param {string} id Transaction ID + * @param {GetSignableTransferRequestV1} getSignableTransferRequest get details of signable transfer + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + getExchangeSignableTransfer: async (id: string, getSignableTransferRequest: GetSignableTransferRequestV1, options: AxiosRequestConfig = {}): Promise => { + // verify required parameter 'id' is not null or undefined + assertParamExists('getExchangeSignableTransfer', 'id', id) + // verify required parameter 'getSignableTransferRequest' is not null or undefined + assertParamExists('getExchangeSignableTransfer', 'getSignableTransferRequest', getSignableTransferRequest) + const localVarPath = `/v2/exchanges/{id}/signable-transfer-details` + .replace(`{${"id"}}`, encodeURIComponent(String(id))); + // use dummy base URL string because the URL constructor only accepts absolute URLs. + const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); + let baseOptions; + if (configuration) { + baseOptions = configuration.baseOptions; + } + + const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options}; + const localVarHeaderParameter = {} as any; + const localVarQueryParameter = {} as any; + + + + localVarHeaderParameter['Content-Type'] = 'application/json'; + + setSearchParams(localVarUrlObj, localVarQueryParameter); + let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; + localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; + localVarRequestOptions.data = serializeDataIfNeeded(getSignableTransferRequest, localVarRequestOptions, configuration) + + return { + url: toPathString(localVarUrlObj), + options: localVarRequestOptions, + }; + }, + /** + * Returns a list of exchanges based on the request + * @summary Returns a list of exchanges based on the request + * @param {number} [pageSize] Page size of the result + * @param {string} [cursor] Cursor + * @param {'id' | 'status' | 'exchange' | 'amount' | 'transfer_id'} [orderBy] Property to sort by + * @param {'asc' | 'desc'} [direction] Direction to sort + * @param {number} [id] Transaction ID + * @param {string} [walletAddress] Ethereum address of the user who created transaction + * @param {'created' | 'pending' | 'completed' | 'failed' | 'waitingPayment' | 'timedOut'} [status] Transaction status + * @param {'moonpay'} [provider] Provider name + * @param {string} [transferId] Transfer ID + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + getExchanges: async (pageSize?: number, cursor?: string, orderBy?: 'id' | 'status' | 'exchange' | 'amount' | 'transfer_id', direction?: 'asc' | 'desc', id?: number, walletAddress?: string, status?: 'created' | 'pending' | 'completed' | 'failed' | 'waitingPayment' | 'timedOut', provider?: 'moonpay', transferId?: string, options: AxiosRequestConfig = {}): Promise => { + const localVarPath = `/v3/exchanges`; + // use dummy base URL string because the URL constructor only accepts absolute URLs. + const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); + let baseOptions; + if (configuration) { + baseOptions = configuration.baseOptions; + } + + const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options}; + const localVarHeaderParameter = {} as any; + const localVarQueryParameter = {} as any; + + if (pageSize !== undefined) { + localVarQueryParameter['page_size'] = pageSize; + } + + if (cursor !== undefined) { + localVarQueryParameter['cursor'] = cursor; + } + + if (orderBy !== undefined) { + localVarQueryParameter['order_by'] = orderBy; + } + + if (direction !== undefined) { + localVarQueryParameter['direction'] = direction; + } + + if (id !== undefined) { + localVarQueryParameter['id'] = id; + } + + if (walletAddress !== undefined) { + localVarQueryParameter['wallet_address'] = walletAddress; + } + + if (status !== undefined) { + localVarQueryParameter['status'] = status; + } + + if (provider !== undefined) { + localVarQueryParameter['provider'] = provider; + } + + if (transferId !== undefined) { + localVarQueryParameter['transfer_id'] = transferId; + } + + + + setSearchParams(localVarUrlObj, localVarQueryParameter); + let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; + localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; + + return { + url: toPathString(localVarUrlObj), + options: localVarRequestOptions, + }; + }, + } +}; + +/** + * ExchangesApi - functional programming interface + * @export + */ +export const ExchangesApiFp = function(configuration?: Configuration) { + const localVarAxiosParamCreator = ExchangesApiAxiosParamCreator(configuration) + return { + /** + * Receive wallet_address, provider, type and widget information to create a base exchange transaction and return widget URL + * @summary Create an exchange with URL + * @param {CreateExchangeAndURLAPIRequest} createExchangeAPIRequest req + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async createExchange(createExchangeAPIRequest: CreateExchangeAndURLAPIRequest, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + const localVarAxiosArgs = await localVarAxiosParamCreator.createExchange(createExchangeAPIRequest, options); + return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); + }, + /** + * Accepts a transfer request and updates the transfer_status after processing transfer (offramp) + * @summary Accepts a transfer request and updates the transfer_status after processing transfer (offramp) + * @param {string} id Transaction ID + * @param {string} xImxEthAddress eth address + * @param {string} xImxEthSignature eth signature + * @param {CreateTransferRequestV1} createTransferRequest Create a transfer + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async createExchangeTransfer(id: string, xImxEthAddress: string, xImxEthSignature: string, createTransferRequest: CreateTransferRequestV1, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + const localVarAxiosArgs = await localVarAxiosParamCreator.createExchangeTransfer(id, xImxEthAddress, xImxEthSignature, createTransferRequest, options); + return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); + }, + /** + * Returns a list of supported currencies and their limits + * @summary Get currencies with limits + * @param {'onramp' | 'offramp'} type Exchange type + * @param {'moonpay'} [provider] Provider name + * @param {boolean} [includeLimits] Flag if limits should be included in the response or not + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async getCurrencies(type: 'onramp' | 'offramp', provider?: 'moonpay', includeLimits?: boolean, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + const localVarAxiosArgs = await localVarAxiosParamCreator.getCurrencies(type, provider, includeLimits, options); + return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); + }, + /** + * Get an exchange by ID + * @summary Get an exchange by ID + * @param {string} id Exchange ID + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async getExchange(id: string, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + const localVarAxiosArgs = await localVarAxiosParamCreator.getExchange(id, options); + return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); + }, + /** + * Send a request for signable-transfer-details (offramp) + * @summary Send a request for signable-transfer-details (offramp) + * @param {string} id Transaction ID + * @param {GetSignableTransferRequestV1} getSignableTransferRequest get details of signable transfer + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async getExchangeSignableTransfer(id: string, getSignableTransferRequest: GetSignableTransferRequestV1, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + const localVarAxiosArgs = await localVarAxiosParamCreator.getExchangeSignableTransfer(id, getSignableTransferRequest, options); + return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); + }, + /** + * Returns a list of exchanges based on the request + * @summary Returns a list of exchanges based on the request + * @param {number} [pageSize] Page size of the result + * @param {string} [cursor] Cursor + * @param {'id' | 'status' | 'exchange' | 'amount' | 'transfer_id'} [orderBy] Property to sort by + * @param {'asc' | 'desc'} [direction] Direction to sort + * @param {number} [id] Transaction ID + * @param {string} [walletAddress] Ethereum address of the user who created transaction + * @param {'created' | 'pending' | 'completed' | 'failed' | 'waitingPayment' | 'timedOut'} [status] Transaction status + * @param {'moonpay'} [provider] Provider name + * @param {string} [transferId] Transfer ID + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async getExchanges(pageSize?: number, cursor?: string, orderBy?: 'id' | 'status' | 'exchange' | 'amount' | 'transfer_id', direction?: 'asc' | 'desc', id?: number, walletAddress?: string, status?: 'created' | 'pending' | 'completed' | 'failed' | 'waitingPayment' | 'timedOut', provider?: 'moonpay', transferId?: string, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + const localVarAxiosArgs = await localVarAxiosParamCreator.getExchanges(pageSize, cursor, orderBy, direction, id, walletAddress, status, provider, transferId, options); + return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); + }, + } +}; + +/** + * ExchangesApi - factory interface + * @export + */ +export const ExchangesApiFactory = function (configuration?: Configuration, basePath?: string, axios?: AxiosInstance) { + const localVarFp = ExchangesApiFp(configuration) + return { + /** + * Receive wallet_address, provider, type and widget information to create a base exchange transaction and return widget URL + * @summary Create an exchange with URL + * @param {CreateExchangeAndURLAPIRequest} createExchangeAPIRequest req + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + createExchange(createExchangeAPIRequest: CreateExchangeAndURLAPIRequest, options?: any): AxiosPromise { + return localVarFp.createExchange(createExchangeAPIRequest, options).then((request) => request(axios, basePath)); + }, + /** + * Accepts a transfer request and updates the transfer_status after processing transfer (offramp) + * @summary Accepts a transfer request and updates the transfer_status after processing transfer (offramp) + * @param {string} id Transaction ID + * @param {string} xImxEthAddress eth address + * @param {string} xImxEthSignature eth signature + * @param {CreateTransferRequestV1} createTransferRequest Create a transfer + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + createExchangeTransfer(id: string, xImxEthAddress: string, xImxEthSignature: string, createTransferRequest: CreateTransferRequestV1, options?: any): AxiosPromise { + return localVarFp.createExchangeTransfer(id, xImxEthAddress, xImxEthSignature, createTransferRequest, options).then((request) => request(axios, basePath)); + }, + /** + * Returns a list of supported currencies and their limits + * @summary Get currencies with limits + * @param {'onramp' | 'offramp'} type Exchange type + * @param {'moonpay'} [provider] Provider name + * @param {boolean} [includeLimits] Flag if limits should be included in the response or not + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + getCurrencies(type: 'onramp' | 'offramp', provider?: 'moonpay', includeLimits?: boolean, options?: any): AxiosPromise { + return localVarFp.getCurrencies(type, provider, includeLimits, options).then((request) => request(axios, basePath)); + }, + /** + * Get an exchange by ID + * @summary Get an exchange by ID + * @param {string} id Exchange ID + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + getExchange(id: string, options?: any): AxiosPromise { + return localVarFp.getExchange(id, options).then((request) => request(axios, basePath)); + }, + /** + * Send a request for signable-transfer-details (offramp) + * @summary Send a request for signable-transfer-details (offramp) + * @param {string} id Transaction ID + * @param {GetSignableTransferRequestV1} getSignableTransferRequest get details of signable transfer + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + getExchangeSignableTransfer(id: string, getSignableTransferRequest: GetSignableTransferRequestV1, options?: any): AxiosPromise { + return localVarFp.getExchangeSignableTransfer(id, getSignableTransferRequest, options).then((request) => request(axios, basePath)); + }, + /** + * Returns a list of exchanges based on the request + * @summary Returns a list of exchanges based on the request + * @param {number} [pageSize] Page size of the result + * @param {string} [cursor] Cursor + * @param {'id' | 'status' | 'exchange' | 'amount' | 'transfer_id'} [orderBy] Property to sort by + * @param {'asc' | 'desc'} [direction] Direction to sort + * @param {number} [id] Transaction ID + * @param {string} [walletAddress] Ethereum address of the user who created transaction + * @param {'created' | 'pending' | 'completed' | 'failed' | 'waitingPayment' | 'timedOut'} [status] Transaction status + * @param {'moonpay'} [provider] Provider name + * @param {string} [transferId] Transfer ID + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + getExchanges(pageSize?: number, cursor?: string, orderBy?: 'id' | 'status' | 'exchange' | 'amount' | 'transfer_id', direction?: 'asc' | 'desc', id?: number, walletAddress?: string, status?: 'created' | 'pending' | 'completed' | 'failed' | 'waitingPayment' | 'timedOut', provider?: 'moonpay', transferId?: string, options?: any): AxiosPromise { + return localVarFp.getExchanges(pageSize, cursor, orderBy, direction, id, walletAddress, status, provider, transferId, options).then((request) => request(axios, basePath)); + }, + }; +}; + +/** + * Request parameters for createExchange operation in ExchangesApi. + * @export + * @interface ExchangesApiCreateExchangeRequest + */ +export interface ExchangesApiCreateExchangeRequest { + /** + * req + * @type {CreateExchangeAndURLAPIRequest} + * @memberof ExchangesApiCreateExchange + */ + readonly createExchangeAPIRequest: CreateExchangeAndURLAPIRequest +} + +/** + * Request parameters for createExchangeTransfer operation in ExchangesApi. + * @export + * @interface ExchangesApiCreateExchangeTransferRequest + */ +export interface ExchangesApiCreateExchangeTransferRequest { + /** + * Transaction ID + * @type {string} + * @memberof ExchangesApiCreateExchangeTransfer + */ + readonly id: string + + /** + * eth address + * @type {string} + * @memberof ExchangesApiCreateExchangeTransfer + */ + readonly xImxEthAddress: string + + /** + * eth signature + * @type {string} + * @memberof ExchangesApiCreateExchangeTransfer + */ + readonly xImxEthSignature: string + + /** + * Create a transfer + * @type {CreateTransferRequestV1} + * @memberof ExchangesApiCreateExchangeTransfer + */ + readonly createTransferRequest: CreateTransferRequestV1 +} + +/** + * Request parameters for getCurrencies operation in ExchangesApi. + * @export + * @interface ExchangesApiGetCurrenciesRequest + */ +export interface ExchangesApiGetCurrenciesRequest { + /** + * Exchange type + * @type {'onramp' | 'offramp'} + * @memberof ExchangesApiGetCurrencies + */ + readonly type: 'onramp' | 'offramp' + + /** + * Provider name + * @type {'moonpay'} + * @memberof ExchangesApiGetCurrencies + */ + readonly provider?: 'moonpay' + + /** + * Flag if limits should be included in the response or not + * @type {boolean} + * @memberof ExchangesApiGetCurrencies + */ + readonly includeLimits?: boolean +} + +/** + * Request parameters for getExchange operation in ExchangesApi. + * @export + * @interface ExchangesApiGetExchangeRequest + */ +export interface ExchangesApiGetExchangeRequest { + /** + * Exchange ID + * @type {string} + * @memberof ExchangesApiGetExchange + */ + readonly id: string +} + +/** + * Request parameters for getExchangeSignableTransfer operation in ExchangesApi. + * @export + * @interface ExchangesApiGetExchangeSignableTransferRequest + */ +export interface ExchangesApiGetExchangeSignableTransferRequest { + /** + * Transaction ID + * @type {string} + * @memberof ExchangesApiGetExchangeSignableTransfer + */ + readonly id: string + + /** + * get details of signable transfer + * @type {GetSignableTransferRequestV1} + * @memberof ExchangesApiGetExchangeSignableTransfer + */ + readonly getSignableTransferRequest: GetSignableTransferRequestV1 +} + +/** + * Request parameters for getExchanges operation in ExchangesApi. + * @export + * @interface ExchangesApiGetExchangesRequest + */ +export interface ExchangesApiGetExchangesRequest { + /** + * Page size of the result + * @type {number} + * @memberof ExchangesApiGetExchanges + */ + readonly pageSize?: number + + /** + * Cursor + * @type {string} + * @memberof ExchangesApiGetExchanges + */ + readonly cursor?: string + + /** + * Property to sort by + * @type {'id' | 'status' | 'exchange' | 'amount' | 'transfer_id'} + * @memberof ExchangesApiGetExchanges + */ + readonly orderBy?: 'id' | 'status' | 'exchange' | 'amount' | 'transfer_id' + + /** + * Direction to sort + * @type {'asc' | 'desc'} + * @memberof ExchangesApiGetExchanges + */ + readonly direction?: 'asc' | 'desc' + + /** + * Transaction ID + * @type {number} + * @memberof ExchangesApiGetExchanges + */ + readonly id?: number + + /** + * Ethereum address of the user who created transaction + * @type {string} + * @memberof ExchangesApiGetExchanges + */ + readonly walletAddress?: string + + /** + * Transaction status + * @type {'created' | 'pending' | 'completed' | 'failed' | 'waitingPayment' | 'timedOut'} + * @memberof ExchangesApiGetExchanges + */ + readonly status?: 'created' | 'pending' | 'completed' | 'failed' | 'waitingPayment' | 'timedOut' + + /** + * Provider name + * @type {'moonpay'} + * @memberof ExchangesApiGetExchanges + */ + readonly provider?: 'moonpay' + + /** + * Transfer ID + * @type {string} + * @memberof ExchangesApiGetExchanges + */ + readonly transferId?: string +} + +/** + * ExchangesApi - object-oriented interface + * @export + * @class ExchangesApi + * @extends {BaseAPI} + */ +export class ExchangesApi extends BaseAPI { + /** + * Receive wallet_address, provider, type and widget information to create a base exchange transaction and return widget URL + * @summary Create an exchange with URL + * @param {ExchangesApiCreateExchangeRequest} requestParameters Request parameters. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof ExchangesApi + */ + public createExchange(requestParameters: ExchangesApiCreateExchangeRequest, options?: AxiosRequestConfig) { + return ExchangesApiFp(this.configuration).createExchange(requestParameters.createExchangeAPIRequest, options).then((request) => request(this.axios, this.basePath)); + } + + /** + * Accepts a transfer request and updates the transfer_status after processing transfer (offramp) + * @summary Accepts a transfer request and updates the transfer_status after processing transfer (offramp) + * @param {ExchangesApiCreateExchangeTransferRequest} requestParameters Request parameters. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof ExchangesApi + */ + public createExchangeTransfer(requestParameters: ExchangesApiCreateExchangeTransferRequest, options?: AxiosRequestConfig) { + return ExchangesApiFp(this.configuration).createExchangeTransfer(requestParameters.id, requestParameters.xImxEthAddress, requestParameters.xImxEthSignature, requestParameters.createTransferRequest, options).then((request) => request(this.axios, this.basePath)); + } + + /** + * Returns a list of supported currencies and their limits + * @summary Get currencies with limits + * @param {ExchangesApiGetCurrenciesRequest} requestParameters Request parameters. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof ExchangesApi + */ + public getCurrencies(requestParameters: ExchangesApiGetCurrenciesRequest, options?: AxiosRequestConfig) { + return ExchangesApiFp(this.configuration).getCurrencies(requestParameters.type, requestParameters.provider, requestParameters.includeLimits, options).then((request) => request(this.axios, this.basePath)); + } + + /** + * Get an exchange by ID + * @summary Get an exchange by ID + * @param {ExchangesApiGetExchangeRequest} requestParameters Request parameters. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof ExchangesApi + */ + public getExchange(requestParameters: ExchangesApiGetExchangeRequest, options?: AxiosRequestConfig) { + return ExchangesApiFp(this.configuration).getExchange(requestParameters.id, options).then((request) => request(this.axios, this.basePath)); + } + + /** + * Send a request for signable-transfer-details (offramp) + * @summary Send a request for signable-transfer-details (offramp) + * @param {ExchangesApiGetExchangeSignableTransferRequest} requestParameters Request parameters. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof ExchangesApi + */ + public getExchangeSignableTransfer(requestParameters: ExchangesApiGetExchangeSignableTransferRequest, options?: AxiosRequestConfig) { + return ExchangesApiFp(this.configuration).getExchangeSignableTransfer(requestParameters.id, requestParameters.getSignableTransferRequest, options).then((request) => request(this.axios, this.basePath)); + } + + /** + * Returns a list of exchanges based on the request + * @summary Returns a list of exchanges based on the request + * @param {ExchangesApiGetExchangesRequest} requestParameters Request parameters. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof ExchangesApi + */ + public getExchanges(requestParameters: ExchangesApiGetExchangesRequest = {}, options?: AxiosRequestConfig) { + return ExchangesApiFp(this.configuration).getExchanges(requestParameters.pageSize, requestParameters.cursor, requestParameters.orderBy, requestParameters.direction, requestParameters.id, requestParameters.walletAddress, requestParameters.status, requestParameters.provider, requestParameters.transferId, options).then((request) => request(this.axios, this.basePath)); + } +} diff --git a/src/api/models/aggregate-limit.ts b/src/api/models/aggregate-limit.ts new file mode 100644 index 00000000..e3f21651 --- /dev/null +++ b/src/api/models/aggregate-limit.ts @@ -0,0 +1,36 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * Immutable X API + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 3.0 + * Contact: support@immutable.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + + +/** + * + * @export + * @interface AggregateLimit + */ +export interface AggregateLimit { + /** + * Max transaction amount + * @type {number} + * @memberof AggregateLimit + */ + 'max_amount'?: number; + /** + * Min transaction amount + * @type {number} + * @memberof AggregateLimit + */ + 'min_amount'?: number; +} + diff --git a/src/api/models/create-exchange-and-urlapirequest.ts b/src/api/models/create-exchange-and-urlapirequest.ts new file mode 100644 index 00000000..c1bb8a6b --- /dev/null +++ b/src/api/models/create-exchange-and-urlapirequest.ts @@ -0,0 +1,59 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * Immutable X API + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 3.0 + * Contact: support@immutable.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +// May contain unused imports in some cases +// @ts-ignore +import { WidgetParams } from './widget-params'; + +/** + * + * @export + * @interface CreateExchangeAndURLAPIRequest + */ +export interface CreateExchangeAndURLAPIRequest { + /** + * Provider name + * @type {string} + * @memberof CreateExchangeAndURLAPIRequest + */ + 'provider'?: string; + /** + * Transaction type + * @type {string} + * @memberof CreateExchangeAndURLAPIRequest + */ + 'type'?: CreateExchangeAndURLAPIRequestTypeEnum; + /** + * Ethereum address of the user who wants to create transaction + * @type {string} + * @memberof CreateExchangeAndURLAPIRequest + */ + 'wallet_address'?: string; + /** + * + * @type {WidgetParams} + * @memberof CreateExchangeAndURLAPIRequest + */ + 'widget'?: WidgetParams; +} + +export const CreateExchangeAndURLAPIRequestTypeEnum = { + Onramp: 'onramp', + Offramp: 'offramp' +} as const; + +export type CreateExchangeAndURLAPIRequestTypeEnum = typeof CreateExchangeAndURLAPIRequestTypeEnum[keyof typeof CreateExchangeAndURLAPIRequestTypeEnum]; + + diff --git a/src/api/models/currency-with-limits.ts b/src/api/models/currency-with-limits.ts new file mode 100644 index 00000000..123c1896 --- /dev/null +++ b/src/api/models/currency-with-limits.ts @@ -0,0 +1,51 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * Immutable X API + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 3.0 + * Contact: support@immutable.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +// May contain unused imports in some cases +// @ts-ignore +import { AggregateLimit } from './aggregate-limit'; + +/** + * + * @export + * @interface CurrencyWithLimits + */ +export interface CurrencyWithLimits { + /** + * Provider currency code + * @type {string} + * @memberof CurrencyWithLimits + */ + 'currency_code'?: string; + /** + * + * @type {AggregateLimit} + * @memberof CurrencyWithLimits + */ + 'limits'?: AggregateLimit; + /** + * Provider name (e.g. moonpay) + * @type {string} + * @memberof CurrencyWithLimits + */ + 'provider'?: string; + /** + * Currency Symbol + * @type {string} + * @memberof CurrencyWithLimits + */ + 'symbol'?: string; +} + diff --git a/src/api/models/exchange-create-exchange-and-urlresponse.ts b/src/api/models/exchange-create-exchange-and-urlresponse.ts new file mode 100644 index 00000000..f34d89cc --- /dev/null +++ b/src/api/models/exchange-create-exchange-and-urlresponse.ts @@ -0,0 +1,54 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * Immutable X API + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 3.0 + * Contact: support@immutable.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + + +/** + * + * @export + * @interface ExchangeCreateExchangeAndURLResponse + */ +export interface ExchangeCreateExchangeAndURLResponse { + /** + * Created transaction ID + * @type {number} + * @memberof ExchangeCreateExchangeAndURLResponse + */ + 'id'?: number; + /** + * Provider name (e.g. moonpay) + * @type {string} + * @memberof ExchangeCreateExchangeAndURLResponse + */ + 'provider'?: string; + /** + * Transaction type + * @type {string} + * @memberof ExchangeCreateExchangeAndURLResponse + */ + 'type'?: string; + /** + * Widget URL + * @type {string} + * @memberof ExchangeCreateExchangeAndURLResponse + */ + 'url'?: string; + /** + * Ethereum address of the user who created transaction + * @type {string} + * @memberof ExchangeCreateExchangeAndURLResponse + */ + 'wallet_address'?: string; +} + diff --git a/src/api/models/exchange.ts b/src/api/models/exchange.ts new file mode 100644 index 00000000..962f32c2 --- /dev/null +++ b/src/api/models/exchange.ts @@ -0,0 +1,75 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * Immutable X API + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 3.0 + * Contact: support@immutable.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +// May contain unused imports in some cases +// @ts-ignore +import { OptionalExchangeData } from './optional-exchange-data'; + +/** + * + * @export + * @interface Exchange + */ +export interface Exchange { + /** + * Time this transaction was created + * @type {string} + * @memberof Exchange + */ + 'created_at'?: string; + /** + * + * @type {OptionalExchangeData} + * @memberof Exchange + */ + 'data'?: OptionalExchangeData; + /** + * Transaction ID + * @type {number} + * @memberof Exchange + */ + 'id'?: number; + /** + * Provider name + * @type {string} + * @memberof Exchange + */ + 'provider'?: string; + /** + * Transaction status + * @type {string} + * @memberof Exchange + */ + 'status'?: string; + /** + * Transaction type + * @type {string} + * @memberof Exchange + */ + 'type'?: string; + /** + * Time this transaction was updates + * @type {string} + * @memberof Exchange + */ + 'updated_at'?: string; + /** + * Ethereum address of the user who created transaction + * @type {string} + * @memberof Exchange + */ + 'wallet_address'?: string; +} + diff --git a/src/api/models/get-transactions-response.ts b/src/api/models/get-transactions-response.ts new file mode 100644 index 00000000..49be8d10 --- /dev/null +++ b/src/api/models/get-transactions-response.ts @@ -0,0 +1,45 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * Immutable X API + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 3.0 + * Contact: support@immutable.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +// May contain unused imports in some cases +// @ts-ignore +import { Exchange } from './exchange'; + +/** + * + * @export + * @interface GetTransactionsResponse + */ +export interface GetTransactionsResponse { + /** + * Generated cursor returned by previous query + * @type {string} + * @memberof GetTransactionsResponse + */ + 'cursor'?: string; + /** + * Remaining results flag. 1: there are remaining results matching this query, 0: no remaining results + * @type {number} + * @memberof GetTransactionsResponse + */ + 'remaining'?: number; + /** + * Transactions matching query parameters + * @type {Array} + * @memberof GetTransactionsResponse + */ + 'result'?: Array; +} + diff --git a/src/api/models/index.ts b/src/api/models/index.ts index 5a882437..3c443f46 100644 --- a/src/api/models/index.ts +++ b/src/api/models/index.ts @@ -1,5 +1,6 @@ export * from './apierror'; export * from './add-metadata-schema-to-collection-request'; +export * from './aggregate-limit'; export * from './asset'; export * from './asset-properties'; export * from './asset-with-orders'; @@ -10,6 +11,7 @@ export * from './collection'; export * from './collection-details'; export * from './collection-filter'; export * from './create-collection-request'; +export * from './create-exchange-and-urlapirequest'; export * from './create-metadata-refresh-request'; export * from './create-metadata-refresh-response'; export * from './create-order-request'; @@ -24,11 +26,14 @@ export * from './create-transfer-response'; export * from './create-transfer-response-v1'; export * from './create-withdrawal-request'; export * from './create-withdrawal-response'; +export * from './currency-with-limits'; export * from './deposit'; export * from './encode-asset-request'; export * from './encode-asset-request-token'; export * from './encode-asset-response'; export * from './encode-asset-token-data'; +export * from './exchange'; +export * from './exchange-create-exchange-and-urlresponse'; export * from './fee'; export * from './fee-data'; export * from './fee-entry'; @@ -55,7 +60,9 @@ export * from './get-signable-transfer-response'; export * from './get-signable-transfer-response-v1'; export * from './get-signable-withdrawal-request'; export * from './get-signable-withdrawal-response'; +export * from './get-transactions-response'; export * from './get-users-api-response'; +export * from './lambdas-apierror'; export * from './list-assets-response'; export * from './list-balances-response'; export * from './list-collections-response'; @@ -79,6 +86,7 @@ export * from './mint-token-data-v2'; export * from './mint-tokens-response'; export * from './mint-user'; export * from './mintable-token-details'; +export * from './optional-exchange-data'; export * from './order'; export * from './order-details'; export * from './order-fee-info'; @@ -98,4 +106,5 @@ export * from './trade-side'; export * from './transfer'; export * from './transfer-request'; export * from './update-collection-request'; +export * from './widget-params'; export * from './withdrawal'; diff --git a/src/api/models/lambdas-apierror.ts b/src/api/models/lambdas-apierror.ts new file mode 100644 index 00000000..ae7c2012 --- /dev/null +++ b/src/api/models/lambdas-apierror.ts @@ -0,0 +1,48 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * Immutable X API + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 3.0 + * Contact: support@immutable.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + + +/** + * + * @export + * @interface LambdasAPIError + */ +export interface LambdasAPIError { + /** + * The error code + * @type {string} + * @memberof LambdasAPIError + */ + 'code'?: string; + /** + * The error details + * @type {string} + * @memberof LambdasAPIError + */ + 'details'?: string; + /** + * The error message + * @type {string} + * @memberof LambdasAPIError + */ + 'message'?: string; + /** + * The error status code + * @type {number} + * @memberof LambdasAPIError + */ + 'status_code'?: number; +} + diff --git a/src/api/models/mint-token-data-v2.ts b/src/api/models/mint-token-data-v2.ts index b0d0db05..5db99a80 100644 --- a/src/api/models/mint-token-data-v2.ts +++ b/src/api/models/mint-token-data-v2.ts @@ -30,7 +30,7 @@ export interface MintTokenDataV2 { */ 'blueprint'?: string; /** - * Token ID + * Token ID Note: While the Token ID is required to be a string, it still needs to be a valid uint256 as per the ERC-721 token standard. * @type {string} * @memberof MintTokenDataV2 */ diff --git a/src/api/models/optional-exchange-data.ts b/src/api/models/optional-exchange-data.ts new file mode 100644 index 00000000..3083578a --- /dev/null +++ b/src/api/models/optional-exchange-data.ts @@ -0,0 +1,72 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * Immutable X API + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 3.0 + * Contact: support@immutable.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + + +/** + * + * @export + * @interface OptionalExchangeData + */ +export interface OptionalExchangeData { + /** + * Provider transaction ID + * @type {string} + * @memberof OptionalExchangeData + */ + 'external_id'?: string; + /** + * Fees amount + * @type {number} + * @memberof OptionalExchangeData + */ + 'fees_amount'?: number; + /** + * Amount that was exchanged from + * @type {number} + * @memberof OptionalExchangeData + */ + 'from_amount'?: number; + /** + * Currency that was exchanged from + * @type {string} + * @memberof OptionalExchangeData + */ + 'from_currency'?: string; + /** + * Provider wallet address that was used for transferring crypto + * @type {string} + * @memberof OptionalExchangeData + */ + 'provider_wallet_address'?: string; + /** + * Amount that was exchanged to + * @type {number} + * @memberof OptionalExchangeData + */ + 'to_amount'?: number; + /** + * Currency that was exchanged to + * @type {string} + * @memberof OptionalExchangeData + */ + 'to_currency'?: string; + /** + * Transfer ID + * @type {string} + * @memberof OptionalExchangeData + */ + 'transfer_id'?: string; +} + diff --git a/src/api/models/signable-token.ts b/src/api/models/signable-token.ts index b43fd8c2..f8107861 100644 --- a/src/api/models/signable-token.ts +++ b/src/api/models/signable-token.ts @@ -21,7 +21,7 @@ */ export interface SignableToken { /** - * Token data. See https://docs.x.immutable.com/docs/token-data-object\" + * Token data. See https://docs.x.immutable.com/docs/token-data-object * @type {object} * @memberof SignableToken */ diff --git a/src/api/models/widget-params.ts b/src/api/models/widget-params.ts new file mode 100644 index 00000000..ae0c8922 --- /dev/null +++ b/src/api/models/widget-params.ts @@ -0,0 +1,42 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * Immutable X API + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 3.0 + * Contact: support@immutable.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + + +/** + * + * @export + * @interface WidgetParams + */ +export interface WidgetParams { + /** + * Amount that will be prefilled in the widget + * @type {string} + * @memberof WidgetParams + */ + 'amount'?: string; + /** + * Currencies that will be available in the widget. If not defined all available currencies will be shown + * @type {Array} + * @memberof WidgetParams + */ + 'supported_currencies'?: Array; + /** + * Widget theme dark by default + * @type {string} + * @memberof WidgetParams + */ + 'theme'?: string; +} + diff --git a/src/types/requests.ts b/src/types/requests.ts index 07f1c3df..62e2b401 100644 --- a/src/types/requests.ts +++ b/src/types/requests.ts @@ -1,4 +1,4 @@ -import { TokenAmount } from './tokens'; +import { TokenAmount, ExchangeTokenAmount } from './tokens'; import { FeeEntry, MintRequest } from '../api'; // These custom request interfaces are used because API.SignableToken is not yet a union type due to OAS 2.0 spec not supporting `OneOf` @@ -41,3 +41,18 @@ export type UnsignedTransferRequest = TokenAmount & { * Parameter required to Mint tokens */ export type UnsignedMintRequest = Omit; + +/** + * Parameter required to create a Transfer + */ +export type UnsignedExchangeTransferRequest = ExchangeTokenAmount & { + /** + * Ethereum address of the receiving user + */ + receiver: string; + + /** + * Exchange transaction ID + */ + transactionID: string; +}; diff --git a/src/types/tokens.ts b/src/types/tokens.ts index d0eebef2..ee833874 100644 --- a/src/types/tokens.ts +++ b/src/types/tokens.ts @@ -51,3 +51,8 @@ export type AnyToken = ETHToken | ERC721Token | ERC20Token; * Union type that represents all token type amounts */ export type TokenAmount = ETHAmount | ERC20Amount | ERC721Token; + +/** + * Union type that represents exchange token type amounts + */ +export type ExchangeTokenAmount = ETHAmount | ERC20Amount; diff --git a/src/workflows/exchangeTransfers.ts b/src/workflows/exchangeTransfers.ts new file mode 100644 index 00000000..ffe5e2f8 --- /dev/null +++ b/src/workflows/exchangeTransfers.ts @@ -0,0 +1,63 @@ +import { CreateTransferResponseV1, ExchangesApi } from '../api'; +import { UnsignedExchangeTransferRequest, WalletConnection } from '../types'; +import { signRaw } from '../utils'; +import { convertToSignableToken } from '../utils/convertToSignableToken'; + +type TransfersWorkflowParams = WalletConnection & { + request: UnsignedExchangeTransferRequest; + exchangesApi: ExchangesApi; +}; + +export async function exchangeTransfersWorkflow({ + ethSigner, + starkSigner, + request, + exchangesApi, +}: TransfersWorkflowParams): Promise { + const ethAddress = await ethSigner.getAddress(); + + const transferAmount = request.amount; + const signableResult = await exchangesApi.getExchangeSignableTransfer({ + id: request.transactionID, + getSignableTransferRequest: { + sender: ethAddress, + token: convertToSignableToken(request), + amount: transferAmount, + receiver: request.receiver, + }, + }); + + const { signable_message: signableMessage, payload_hash: payloadHash } = + signableResult.data; + + const ethSignature = await signRaw(signableMessage, ethSigner); + + const starkSignature = await starkSigner.signMessage(payloadHash); + + const transferSigningParams = { + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + sender_stark_key: signableResult.data.sender_stark_key!, + sender_vault_id: signableResult.data.sender_vault_id, + receiver_stark_key: signableResult.data.receiver_stark_key, + receiver_vault_id: signableResult.data.receiver_vault_id, + asset_id: signableResult.data.asset_id, + amount: signableResult.data.amount, + nonce: signableResult.data.nonce, + expiration_timestamp: signableResult.data.expiration_timestamp, + stark_signature: starkSignature, + }; + + const response = await exchangesApi.createExchangeTransfer({ + id: request.transactionID, + createTransferRequest: transferSigningParams, + xImxEthAddress: ethAddress, + xImxEthSignature: ethSignature, + }); + + return { + sent_signature: response?.data.sent_signature, + status: response?.data.status?.toString(), + time: response?.data.time, + transfer_id: response?.data.transfer_id, + }; +} diff --git a/src/workflows/workflows.ts b/src/workflows/workflows.ts index da1c3206..b3fbc670 100644 --- a/src/workflows/workflows.ts +++ b/src/workflows/workflows.ts @@ -21,6 +21,7 @@ import { MetadataSchemaRequest, MetadataRefreshesApi, CreateMetadataRefreshRequest, + ExchangesApi, } from '../api'; import { UnsignedMintRequest, @@ -35,6 +36,7 @@ import { AnyToken, ERC20Token, EthSigner, + UnsignedExchangeTransferRequest, } from '../types'; import { Registration__factory } from '../contracts'; import { @@ -58,6 +60,7 @@ import { cancelOrderWorkflow, createOrderWorkflow } from './orders'; import { createTradeWorkflow } from './trades'; import { generateIMXAuthorisationHeaders } from '../utils'; import { ImmutableXConfiguration } from '../config'; +import { exchangeTransfersWorkflow } from './exchangeTransfers'; export class Workflows { private readonly depositsApi: DepositsApi; @@ -73,6 +76,7 @@ export class Workflows { private readonly collectionsApi: CollectionsApi; private readonly metadataApi: MetadataApi; private readonly metadataRefreshesApi: MetadataRefreshesApi; + private readonly exchangesApi: ExchangesApi; private isChainValid(chainID: number) { return chainID === this.config.ethConfiguration.chainID; @@ -95,6 +99,7 @@ export class Workflows { this.collectionsApi = new CollectionsApi(apiConfiguration); this.metadataApi = new MetadataApi(apiConfiguration); this.metadataRefreshesApi = new MetadataRefreshesApi(apiConfiguration); + this.exchangesApi = new ExchangesApi(apiConfiguration); } private async validateChain(signer: Signer) { @@ -147,6 +152,19 @@ export class Workflows { }); } + public async exchangeTransfer( + walletConnection: WalletConnection, + request: UnsignedExchangeTransferRequest, + ) { + await this.validateChain(walletConnection.ethSigner); + + return exchangeTransfersWorkflow({ + ...walletConnection, + request, + exchangesApi: this.exchangesApi, + }); + } + public async batchNftTransfer( walletConnection: WalletConnection, request: Array,