@openweb3-io/dex-aggregator
Version:
dex-aggregator API client and webhook verification library
374 lines (306 loc) • 16.1 kB
text/typescript
// TODO: better import syntax?
import {BaseAPIRequestFactory, RequiredError, COLLECTION_FORMATS} from './baseapi';
import {Configuration} from '../configuration';
import {RequestContext, HttpMethod, ResponseContext, HttpFile, HttpInfo} from '../http/http';
import {ObjectSerializer} from '../models/ObjectSerializer';
import {ApiException} from './exception';
import {canConsumeForm, isCodeInRange} from '../util';
import {SecurityAuthentication} from '../auth/auth';
import { DexMintInput } from '../models/DexMintInput';
import { DexPage } from '../models/DexPage';
import { SwapInput } from '../models/SwapInput';
import { SwapReply } from '../models/SwapReply';
import { SwapRouteInput } from '../models/SwapRouteInput';
import { SwapRouteResponse } from '../models/SwapRouteResponse';
/**
* no description
*/
export class DexApiRequestFactory extends BaseAPIRequestFactory {
/**
* CONTROLLER.DEX.LIST.DESCRIPTION
* CONTROLLER.DEX.LIST.SUMMARY
* @param chains
* @param limit DTO.DEX.QUERY.LIMIT
* @param dexProgram DTO.DEX.QUERY.DEX_PROGRAM
*/
public async list(chains?: Array<string>, limit?: number, dexProgram?: string, _options?: Configuration): Promise<RequestContext> {
let _config = _options || this.configuration;
// Path Params
const localVarPath = '/dex';
// Make Request Context
const requestContext = _config.baseServer.makeRequestContext(localVarPath, HttpMethod.GET);
requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
const randomId = Math.floor(Math.random() * Math.pow(2, 32))
requestContext.setHeaderParam("x-req-id", randomId.toString())
// Query Params
if (chains !== undefined) {
const serializedParams = ObjectSerializer.serialize(chains, "Array<string>", "");
for (const serializedParam of serializedParams) {
requestContext.appendQueryParam("chains", serializedParam);
}
}
// Query Params
if (limit !== undefined) {
requestContext.setQueryParam("limit", ObjectSerializer.serialize(limit, "number", ""));
}
// Query Params
if (dexProgram !== undefined) {
requestContext.setQueryParam("dexProgram", ObjectSerializer.serialize(dexProgram, "string", ""));
}
let authMethod: SecurityAuthentication | undefined;
// Apply auth methods
authMethod = _config.authMethods["bearer"]
if (authMethod?.applySecurityAuthentication) {
await authMethod?.applySecurityAuthentication(requestContext);
}
const defaultAuth: SecurityAuthentication | undefined = _options?.authMethods?.default || this.configuration?.authMethods?.default
if (defaultAuth?.applySecurityAuthentication) {
await defaultAuth?.applySecurityAuthentication(requestContext);
}
return requestContext;
}
/**
* CONTROLLER.DEX.MINT.DESCRIPTION
* CONTROLLER.DEX.MINT.SUMMARY
* @param chain GLOBAL.CHAIN.DESCRIPTION
* @param dexMintInput Token creation parameters
*/
public async mint(chain: 'sol' | 'base', dexMintInput: DexMintInput, _options?: Configuration): Promise<RequestContext> {
let _config = _options || this.configuration;
// verify required parameter 'chain' is not null or undefined
if (chain === null || chain === undefined) {
throw new RequiredError("DexApi", "mint", "chain");
}
// verify required parameter 'dexMintInput' is not null or undefined
if (dexMintInput === null || dexMintInput === undefined) {
throw new RequiredError("DexApi", "mint", "dexMintInput");
}
// Path Params
const localVarPath = '/dex/{chain}/mint'
.replace('{' + 'chain' + '}', encodeURIComponent(String(chain)));
// Make Request Context
const requestContext = _config.baseServer.makeRequestContext(localVarPath, HttpMethod.POST);
requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
const randomId = Math.floor(Math.random() * Math.pow(2, 32))
requestContext.setHeaderParam("x-req-id", randomId.toString())
// Body Params
const contentType = ObjectSerializer.getPreferredMediaType([
"application/json"
]);
requestContext.setHeaderParam("Content-Type", contentType);
const serializedBody = ObjectSerializer.stringify(
ObjectSerializer.serialize(dexMintInput, "DexMintInput", ""),
contentType
);
requestContext.setBody(serializedBody);
let authMethod: SecurityAuthentication | undefined;
// Apply auth methods
authMethod = _config.authMethods["bearer"]
if (authMethod?.applySecurityAuthentication) {
await authMethod?.applySecurityAuthentication(requestContext);
}
const defaultAuth: SecurityAuthentication | undefined = _options?.authMethods?.default || this.configuration?.authMethods?.default
if (defaultAuth?.applySecurityAuthentication) {
await defaultAuth?.applySecurityAuthentication(requestContext);
}
return requestContext;
}
/**
* CONTROLLER.DEX.ROUTE.DESCRIPTION
* CONTROLLER.DEX.ROUTE.SUMMARY
* @param chain GLOBAL.CHAIN.DESCRIPTION
* @param swapRouteInput
*/
public async route(chain: 'sol' | 'base', swapRouteInput: SwapRouteInput, _options?: Configuration): Promise<RequestContext> {
let _config = _options || this.configuration;
// verify required parameter 'chain' is not null or undefined
if (chain === null || chain === undefined) {
throw new RequiredError("DexApi", "route", "chain");
}
// verify required parameter 'swapRouteInput' is not null or undefined
if (swapRouteInput === null || swapRouteInput === undefined) {
throw new RequiredError("DexApi", "route", "swapRouteInput");
}
// Path Params
const localVarPath = '/dex/{chain}/route'
.replace('{' + 'chain' + '}', encodeURIComponent(String(chain)));
// Make Request Context
const requestContext = _config.baseServer.makeRequestContext(localVarPath, HttpMethod.POST);
requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
const randomId = Math.floor(Math.random() * Math.pow(2, 32))
requestContext.setHeaderParam("x-req-id", randomId.toString())
// Body Params
const contentType = ObjectSerializer.getPreferredMediaType([
"application/json"
]);
requestContext.setHeaderParam("Content-Type", contentType);
const serializedBody = ObjectSerializer.stringify(
ObjectSerializer.serialize(swapRouteInput, "SwapRouteInput", ""),
contentType
);
requestContext.setBody(serializedBody);
let authMethod: SecurityAuthentication | undefined;
// Apply auth methods
authMethod = _config.authMethods["bearer"]
if (authMethod?.applySecurityAuthentication) {
await authMethod?.applySecurityAuthentication(requestContext);
}
const defaultAuth: SecurityAuthentication | undefined = _options?.authMethods?.default || this.configuration?.authMethods?.default
if (defaultAuth?.applySecurityAuthentication) {
await defaultAuth?.applySecurityAuthentication(requestContext);
}
return requestContext;
}
/**
* CONTROLLER.DEX.SWAP.DESCRIPTION
* CONTROLLER.DEX.SWAP.SUMMARY
* @param chain GLOBAL.CHAIN.DESCRIPTION
* @param swapInput
*/
public async swap(chain: 'sol' | 'base', swapInput: SwapInput, _options?: Configuration): Promise<RequestContext> {
let _config = _options || this.configuration;
// verify required parameter 'chain' is not null or undefined
if (chain === null || chain === undefined) {
throw new RequiredError("DexApi", "swap", "chain");
}
// verify required parameter 'swapInput' is not null or undefined
if (swapInput === null || swapInput === undefined) {
throw new RequiredError("DexApi", "swap", "swapInput");
}
// Path Params
const localVarPath = '/dex/{chain}/swap'
.replace('{' + 'chain' + '}', encodeURIComponent(String(chain)));
// Make Request Context
const requestContext = _config.baseServer.makeRequestContext(localVarPath, HttpMethod.POST);
requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
const randomId = Math.floor(Math.random() * Math.pow(2, 32))
requestContext.setHeaderParam("x-req-id", randomId.toString())
// Body Params
const contentType = ObjectSerializer.getPreferredMediaType([
"application/json"
]);
requestContext.setHeaderParam("Content-Type", contentType);
const serializedBody = ObjectSerializer.stringify(
ObjectSerializer.serialize(swapInput, "SwapInput", ""),
contentType
);
requestContext.setBody(serializedBody);
let authMethod: SecurityAuthentication | undefined;
// Apply auth methods
authMethod = _config.authMethods["bearer"]
if (authMethod?.applySecurityAuthentication) {
await authMethod?.applySecurityAuthentication(requestContext);
}
const defaultAuth: SecurityAuthentication | undefined = _options?.authMethods?.default || this.configuration?.authMethods?.default
if (defaultAuth?.applySecurityAuthentication) {
await defaultAuth?.applySecurityAuthentication(requestContext);
}
return requestContext;
}
}
export class DexApiResponseProcessor {
/**
* Unwraps the actual response sent by the server from the response context and deserializes the response content
* to the expected objects
*
* @params response Response returned by the server for a request to list
* @throws ApiException if the response code was not in [200, 299]
*/
public async listWithHttpInfo(response: ResponseContext): Promise<HttpInfo<DexPage >> {
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
if (isCodeInRange("200", response.httpStatusCode)) {
const body: DexPage = ObjectSerializer.deserialize(
ObjectSerializer.parse(await response.body.text(), contentType),
"DexPage", ""
) as DexPage;
return new HttpInfo(response.httpStatusCode, response.headers, response.body, body);
}
// Work around for missing responses in specification, e.g. for petstore.yaml
if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) {
const body: DexPage = ObjectSerializer.deserialize(
ObjectSerializer.parse(await response.body.text(), contentType),
"DexPage", ""
) as DexPage;
return new HttpInfo(response.httpStatusCode, response.headers, response.body, body);
}
throw new ApiException<string | Blob | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny(), response.headers);
}
/**
* Unwraps the actual response sent by the server from the response context and deserializes the response content
* to the expected objects
*
* @params response Response returned by the server for a request to mint
* @throws ApiException if the response code was not in [200, 299]
*/
public async mintWithHttpInfo(response: ResponseContext): Promise<HttpInfo<SwapReply >> {
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
if (isCodeInRange("200", response.httpStatusCode)) {
const body: SwapReply = ObjectSerializer.deserialize(
ObjectSerializer.parse(await response.body.text(), contentType),
"SwapReply", ""
) as SwapReply;
return new HttpInfo(response.httpStatusCode, response.headers, response.body, body);
}
// Work around for missing responses in specification, e.g. for petstore.yaml
if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) {
const body: SwapReply = ObjectSerializer.deserialize(
ObjectSerializer.parse(await response.body.text(), contentType),
"SwapReply", ""
) as SwapReply;
return new HttpInfo(response.httpStatusCode, response.headers, response.body, body);
}
throw new ApiException<string | Blob | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny(), response.headers);
}
/**
* Unwraps the actual response sent by the server from the response context and deserializes the response content
* to the expected objects
*
* @params response Response returned by the server for a request to route
* @throws ApiException if the response code was not in [200, 299]
*/
public async routeWithHttpInfo(response: ResponseContext): Promise<HttpInfo<SwapRouteResponse >> {
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
if (isCodeInRange("200", response.httpStatusCode)) {
const body: SwapRouteResponse = ObjectSerializer.deserialize(
ObjectSerializer.parse(await response.body.text(), contentType),
"SwapRouteResponse", ""
) as SwapRouteResponse;
return new HttpInfo(response.httpStatusCode, response.headers, response.body, body);
}
// Work around for missing responses in specification, e.g. for petstore.yaml
if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) {
const body: SwapRouteResponse = ObjectSerializer.deserialize(
ObjectSerializer.parse(await response.body.text(), contentType),
"SwapRouteResponse", ""
) as SwapRouteResponse;
return new HttpInfo(response.httpStatusCode, response.headers, response.body, body);
}
throw new ApiException<string | Blob | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny(), response.headers);
}
/**
* Unwraps the actual response sent by the server from the response context and deserializes the response content
* to the expected objects
*
* @params response Response returned by the server for a request to swap
* @throws ApiException if the response code was not in [200, 299]
*/
public async swapWithHttpInfo(response: ResponseContext): Promise<HttpInfo<SwapReply >> {
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
if (isCodeInRange("200", response.httpStatusCode)) {
const body: SwapReply = ObjectSerializer.deserialize(
ObjectSerializer.parse(await response.body.text(), contentType),
"SwapReply", ""
) as SwapReply;
return new HttpInfo(response.httpStatusCode, response.headers, response.body, body);
}
// Work around for missing responses in specification, e.g. for petstore.yaml
if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) {
const body: SwapReply = ObjectSerializer.deserialize(
ObjectSerializer.parse(await response.body.text(), contentType),
"SwapReply", ""
) as SwapReply;
return new HttpInfo(response.httpStatusCode, response.headers, response.body, body);
}
throw new ApiException<string | Blob | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny(), response.headers);
}
}