Skip to content

Commit

Permalink
Added getExchangeSupportedAssets endpoint (#49)
Browse files Browse the repository at this point in the history
* Added getExchangeSupportedAssets endpoint
* Bumped version
  • Loading branch information
kaushalrajbacancy authored Oct 31, 2023
1 parent a01b6b4 commit d6a6fc5
Show file tree
Hide file tree
Showing 12 changed files with 114 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 4 additions & 0 deletions examples/09-exchange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ async function main(): Promise<void> {
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';
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@etherspot/prime-sdk",
"version": "1.3.9",
"version": "1.3.10",
"description": "Etherspot Prime (Account Abstraction) SDK",
"keywords": [
"ether",
Expand Down
2 changes: 2 additions & 0 deletions src/sdk/data/classes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
8 changes: 8 additions & 0 deletions src/sdk/data/classes/paginated-tokens.ts
Original file line number Diff line number Diff line change
@@ -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<TokenListToken> {
@Type(() => TokenListToken)
items: TokenListToken[];
}
8 changes: 8 additions & 0 deletions src/sdk/data/classes/token-list-token copy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export class TokenListToken {
address: string;
chainId: number;
name: string;
symbol: string;
decimals: number;
logoURI: string;
}
45 changes: 44 additions & 1 deletion src/sdk/data/data.service.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -154,6 +154,49 @@ export class DataService extends Service {
return result;
}

async getExchangeSupportedAssets(page: number = null, limit: number = null, ChainId: number, account: string): Promise<PaginatedTokens> {
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,
Expand Down
8 changes: 8 additions & 0 deletions src/sdk/dto/get-exchange-supported-assets.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { IsOptional, IsPositive } from 'class-validator';
import { PaginationDto } from './pagination.dto';

export class GetExchangeSupportedAssetsDto extends PaginationDto {
@IsOptional()
@IsPositive()
chainId?: number;
}
2 changes: 2 additions & 0 deletions src/sdk/dto/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
14 changes: 14 additions & 0 deletions src/sdk/dto/pagination.dto.ts
Original file line number Diff line number Diff line change
@@ -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;
}
19 changes: 17 additions & 2 deletions src/sdk/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -361,6 +361,21 @@ export class PrimeSdk {
);
}

/**
* gets exchange supported tokens
* @param dto
* @return Promise<PaginatedTokens>
*/
async getExchangeSupportedAssets(dto: GetExchangeSupportedAssetsDto = {}): Promise<PaginatedTokens> {
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
Expand Down

0 comments on commit d6a6fc5

Please sign in to comment.