From d6a6fc55ab504068edf0c9593255987f3db4afbc Mon Sep 17 00:00:00 2001 From: kaushalrajbacancy <78725072+kaushalrajbacancy@users.noreply.github.com> Date: Tue, 31 Oct 2023 16:07:14 +0530 Subject: [PATCH] Added getExchangeSupportedAssets endpoint (#49) * Added getExchangeSupportedAssets endpoint * Bumped version --- CHANGELOG.md | 4 ++ examples/09-exchange.ts | 4 ++ package-lock.json | 4 +- package.json | 2 +- src/sdk/data/classes/index.ts | 2 + src/sdk/data/classes/paginated-tokens.ts | 8 ++++ src/sdk/data/classes/token-list-token copy.ts | 8 ++++ src/sdk/data/data.service.ts | 45 ++++++++++++++++++- .../dto/get-exchange-supported-assets.dto.ts | 8 ++++ src/sdk/dto/index.ts | 2 + src/sdk/dto/pagination.dto.ts | 14 ++++++ src/sdk/sdk.ts | 19 +++++++- 12 files changed, 114 insertions(+), 6 deletions(-) create mode 100644 src/sdk/data/classes/paginated-tokens.ts create mode 100644 src/sdk/data/classes/token-list-token copy.ts create mode 100644 src/sdk/dto/get-exchange-supported-assets.dto.ts create mode 100644 src/sdk/dto/pagination.dto.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index ba618a4f..4025221a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,8 @@ # Changelog +## [1.3.10] - 2023-10-31 +### New +- Added getExchangeSupportedAssets to gets exchange supported tokens + ## [1.3.9] - 2023-10-28 ### Bug Fixes - Upgraded Apollo package dependencies diff --git a/examples/09-exchange.ts b/examples/09-exchange.ts index ab0ba63f..3548cf0a 100644 --- a/examples/09-exchange.ts +++ b/examples/09-exchange.ts @@ -9,6 +9,10 @@ async function main(): Promise { chainId: Number(process.env.CHAIN_ID), projectKey: '', // project key }); + + const exchangeSupportedAssets = await primeSdk.getExchangeSupportedAssets({ page: 1, limit: 100 }); + console.log('\x1b[33m%s\x1b[0m', `Found exchange supported assets:`, exchangeSupportedAssets.items.length); + const fromTokenAddress = '0xe3818504c1b32bf1557b16c238b2e01fd3149c17'; const toTokenAddress = constants.AddressZero; const fromAmount = '1000000000000000000'; diff --git a/package-lock.json b/package-lock.json index 6e76f3ff..a348da27 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@etherspot/prime-sdk", - "version": "1.3.9", + "version": "1.3.10", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@etherspot/prime-sdk", - "version": "1.3.9", + "version": "1.3.10", "license": "MIT", "dependencies": { "@apollo/client": "3.8.6", diff --git a/package.json b/package.json index c58d8126..4bbacbde 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@etherspot/prime-sdk", - "version": "1.3.9", + "version": "1.3.10", "description": "Etherspot Prime (Account Abstraction) SDK", "keywords": [ "ether", diff --git a/src/sdk/data/classes/index.ts b/src/sdk/data/classes/index.ts index 71f4aca0..7fe2e204 100644 --- a/src/sdk/data/classes/index.ts +++ b/src/sdk/data/classes/index.ts @@ -21,3 +21,5 @@ export * from './rate-data'; export * from './token-list-token'; export * from './token-list'; export * from './token-lists'; +export * from './token-list-token'; +export * from './paginated-tokens'; diff --git a/src/sdk/data/classes/paginated-tokens.ts b/src/sdk/data/classes/paginated-tokens.ts new file mode 100644 index 00000000..50a9ecd5 --- /dev/null +++ b/src/sdk/data/classes/paginated-tokens.ts @@ -0,0 +1,8 @@ +import { Type } from 'class-transformer'; +import { PaginationResult } from '../../common/classes/pagination-result'; +import { TokenListToken } from './token-list-token'; + +export class PaginatedTokens extends PaginationResult { + @Type(() => TokenListToken) + items: TokenListToken[]; +} diff --git a/src/sdk/data/classes/token-list-token copy.ts b/src/sdk/data/classes/token-list-token copy.ts new file mode 100644 index 00000000..10d089fe --- /dev/null +++ b/src/sdk/data/classes/token-list-token copy.ts @@ -0,0 +1,8 @@ +export class TokenListToken { + address: string; + chainId: number; + name: string; + symbol: string; + decimals: number; + logoURI: string; +} diff --git a/src/sdk/data/data.service.ts b/src/sdk/data/data.service.ts index 521b167d..c8b85e1a 100644 --- a/src/sdk/data/data.service.ts +++ b/src/sdk/data/data.service.ts @@ -1,7 +1,7 @@ import { gql } from '@apollo/client/core'; import { HeaderNames, ObjectSubject, Service } from '../common'; import { Route } from '@lifi/sdk'; -import { AccountBalances, AdvanceRoutesLiFi, BridgingQuotes, ExchangeOffer, ExchangeOffers, NftList, RateData, StepTransaction, StepTransactions, TokenList, TokenListToken, TokenLists, Transaction } from './classes'; +import { AccountBalances, AdvanceRoutesLiFi, BridgingQuotes, ExchangeOffer, ExchangeOffers, NftList, PaginatedTokens, RateData, StepTransaction, StepTransactions, TokenList, TokenListToken, TokenLists, Transaction } from './classes'; import { BigNumber } from 'ethers'; import { CrossChainServiceProvider, LiFiBridge } from './constants'; @@ -154,6 +154,49 @@ export class DataService extends Service { return result; } + async getExchangeSupportedAssets(page: number = null, limit: number = null, ChainId: number, account: string): Promise { + const { apiService } = this.services; + + try { + const { result } = await apiService.query<{ + result: PaginatedTokens; + }>( + gql` + query($ChainId: Int, $account: String!, $page: Int, $limit: Int) { + result: exchangeSupportedAssets(chainId: $ChainId, account: $account, page: $page, limit: $limit) { + items { + address + name + symbol + decimals + logoURI + } + currentPage + nextPage + } + } + `, + { + variables: { + account, + ChainId, + page: page || 1, + limit: limit || 100, + }, + models: { + result: PaginatedTokens, + }, + }, + ); + + return result; + + } catch (error) { + console.error(error); + return null; + } + } + async getExchangeOffers( fromTokenAddress: string, toTokenAddress: string, diff --git a/src/sdk/dto/get-exchange-supported-assets.dto.ts b/src/sdk/dto/get-exchange-supported-assets.dto.ts new file mode 100644 index 00000000..64df4443 --- /dev/null +++ b/src/sdk/dto/get-exchange-supported-assets.dto.ts @@ -0,0 +1,8 @@ +import { IsOptional, IsPositive } from 'class-validator'; +import { PaginationDto } from './pagination.dto'; + +export class GetExchangeSupportedAssetsDto extends PaginationDto { + @IsOptional() + @IsPositive() + chainId?: number; +} diff --git a/src/sdk/dto/index.ts b/src/sdk/dto/index.ts index e6bd233a..c4950412 100644 --- a/src/sdk/dto/index.ts +++ b/src/sdk/dto/index.ts @@ -12,3 +12,5 @@ export * from './get-step-transactions-lifi.dto'; export * from './get-exchange-cross-chain-quote.dto'; export * from './fetch-exchange-rates.dto'; export * from './get-token-list.dto'; +export * from './pagination.dto'; +export * from './get-exchange-supported-assets.dto'; diff --git a/src/sdk/dto/pagination.dto.ts b/src/sdk/dto/pagination.dto.ts new file mode 100644 index 00000000..22846674 --- /dev/null +++ b/src/sdk/dto/pagination.dto.ts @@ -0,0 +1,14 @@ +import { IsOptional, IsPositive, IsInt, Max } from 'class-validator'; + +export class PaginationDto { + @IsOptional() + @IsPositive() + @IsInt() + page?: number = null; + + @IsOptional() + @IsPositive() + @IsInt() + @Max(100) + limit?: number = null; +} diff --git a/src/sdk/sdk.ts b/src/sdk/sdk.ts index 028ff20f..665303e3 100644 --- a/src/sdk/sdk.ts +++ b/src/sdk/sdk.ts @@ -15,8 +15,8 @@ import { getNetworkConfig, Networks, onRamperAllNetworks } from './network/const import { UserOperationStruct } from './contracts/account-abstraction/contracts/core/BaseAccount'; import { EtherspotWalletAPI, HttpRpcClient, VerifyingPaymasterAPI } from './base'; import { TransactionDetailsForUserOp, TransactionGasInfoForUserOp } from './base/TransactionDetailsForUserOp'; -import { CreateSessionDto, OnRamperDto, GetAccountBalancesDto, GetAdvanceRoutesLiFiDto, GetExchangeCrossChainQuoteDto, GetExchangeOffersDto, GetNftListDto, GetStepTransactionsLiFiDto, GetTransactionDto, SignMessageDto, validateDto, FetchExchangeRatesDto, GetTokenListDto } from './dto'; -import { AccountBalances, AdvanceRoutesLiFi, BridgingQuotes, ExchangeOffer, NftList, StepTransactions, Transaction, Session, RateData, TokenListToken, TokenList } from './'; +import { CreateSessionDto, OnRamperDto, GetAccountBalancesDto, GetAdvanceRoutesLiFiDto, GetExchangeCrossChainQuoteDto, GetExchangeOffersDto, GetNftListDto, GetStepTransactionsLiFiDto, GetTransactionDto, SignMessageDto, validateDto, FetchExchangeRatesDto, GetTokenListDto, GetExchangeSupportedAssetsDto } from './dto'; +import { AccountBalances, AdvanceRoutesLiFi, BridgingQuotes, ExchangeOffer, NftList, StepTransactions, Transaction, Session, RateData, TokenListToken, TokenList, PaginatedTokens } from './'; import { ZeroDevWalletAPI } from './base/ZeroDevWalletAPI'; import { SimpleAccountAPI } from './base/SimpleAccountWalletAPI'; import { ErrorHandler } from './errorHandler/errorHandler.service'; @@ -361,6 +361,21 @@ export class PrimeSdk { ); } + /** + * gets exchange supported tokens + * @param dto + * @return Promise + */ + async getExchangeSupportedAssets(dto: GetExchangeSupportedAssetsDto = {}): Promise { + const { page, limit, chainId } = await validateDto(dto, GetExchangeSupportedAssetsDto); + + const account = await this.getCounterFactualAddress(); + + const getChainId = chainId ? chainId : this.etherspotWallet.services.walletService.chainId; + + return this.etherspotWallet.services.dataService.getExchangeSupportedAssets(page, limit, getChainId, account); + } + /** * gets exchange offers * @param dto