UNPKG

@openweb3-io/dex-aggregator

Version:

dex-aggregator API client and webhook verification library

185 lines (148 loc) 8.26 kB
// 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 { DexPoolDTO } from '../models/DexPoolDTO'; /** * no description */ export class DexPoolApiRequestFactory extends BaseAPIRequestFactory { /** * CONTROLLER.DEXPOOL.GET.DESCRIPTION * CONTROLLER.DEXPOOL.GET.SUMMARY * @param chain GLOBAL.CHAIN.DESCRIPTION * @param poolAddress GLOBAL.POOLADDRESS.DESCRIPTION */ public async getDexpool(chain: 'sol' | 'base', poolAddress: string, _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("DexPoolApi", "getDexpool", "chain"); } // verify required parameter 'poolAddress' is not null or undefined if (poolAddress === null || poolAddress === undefined) { throw new RequiredError("DexPoolApi", "getDexpool", "poolAddress"); } // Path Params const localVarPath = '/dexpools/{chain}/{poolAddress}' .replace('{' + 'chain' + '}', encodeURIComponent(String(chain))) .replace('{' + 'poolAddress' + '}', encodeURIComponent(String(poolAddress))); // 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()) 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.DEXPOOL.STATS.DESCRIPTION * CONTROLLER.DEXPOOL.STATS.SUMMARY * @param chain GLOBAL.CHAIN.DESCRIPTION * @param tokenAddress GLOBAL.TOKENADDRESS.DESCRIPTION * @param poolAddress GLOBAL.POOLADDRESS.DESCRIPTION */ public async getDexpoolStats(chain: 'sol' | 'base', tokenAddress: string, poolAddress: string, _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("DexPoolApi", "getDexpoolStats", "chain"); } // verify required parameter 'tokenAddress' is not null or undefined if (tokenAddress === null || tokenAddress === undefined) { throw new RequiredError("DexPoolApi", "getDexpoolStats", "tokenAddress"); } // verify required parameter 'poolAddress' is not null or undefined if (poolAddress === null || poolAddress === undefined) { throw new RequiredError("DexPoolApi", "getDexpoolStats", "poolAddress"); } // Path Params const localVarPath = '/dexpools/{chain}/{tokenAddress}/{poolAddress}/stats' .replace('{' + 'chain' + '}', encodeURIComponent(String(chain))) .replace('{' + 'tokenAddress' + '}', encodeURIComponent(String(tokenAddress))) .replace('{' + 'poolAddress' + '}', encodeURIComponent(String(poolAddress))); // 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()) 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 DexPoolApiResponseProcessor { /** * 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 getDexpool * @throws ApiException if the response code was not in [200, 299] */ public async getDexpoolWithHttpInfo(response: ResponseContext): Promise<HttpInfo<DexPoolDTO >> { const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]); if (isCodeInRange("200", response.httpStatusCode)) { const body: DexPoolDTO = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "DexPoolDTO", "" ) as DexPoolDTO; 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: DexPoolDTO = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "DexPoolDTO", "" ) as DexPoolDTO; 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 getDexpoolStats * @throws ApiException if the response code was not in [200, 299] */ public async getDexpoolStatsWithHttpInfo(response: ResponseContext): Promise<HttpInfo<any >> { const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]); if (isCodeInRange("200", response.httpStatusCode)) { const body: any = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "any", "" ) as any; 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: any = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "any", "" ) as any; 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); } }