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