diff --git a/src/client/core-api/api-client-caching.ts b/src/client/core-api/api-client-caching.ts index 999d7a14..d1d01272 100644 --- a/src/client/core-api/api-client-caching.ts +++ b/src/client/core-api/api-client-caching.ts @@ -3,6 +3,7 @@ import { ChainSymbol } from "../../chains"; import { PoolInfoMap, PoolKeyObject } from "../../tokens-info"; import { ApiClient, TokenInfo } from "./api-client"; import { + CheckAddressResponse, GasBalanceResponse, PendingInfoResponse, ReceiveTransactionCostRequest, @@ -48,6 +49,10 @@ export class ApiClientCaching implements ApiClient { return gasBalancePromise; } + async checkAddress(chainSymbol: ChainSymbol, address: string, tokenAddress?: string): Promise { + return this.apiClient.checkAddress(chainSymbol, address, tokenAddress); + } + async getPendingInfo(): Promise { const PENDING_INFO_CACHE_KEY = "PENDING_INFO_CACHE_KEY"; const pendingInfo = this.pendingInfoCache.get(PENDING_INFO_CACHE_KEY); diff --git a/src/client/core-api/api-client.ts b/src/client/core-api/api-client.ts index 25d15052..45709c4d 100644 --- a/src/client/core-api/api-client.ts +++ b/src/client/core-api/api-client.ts @@ -9,6 +9,7 @@ import { } from "./core-api-mapper"; import { ChainDetailsResponse, + CheckAddressResponse, GasBalanceResponse, PendingInfoResponse, PoolInfoResponse, @@ -25,10 +26,17 @@ export interface TokenInfo { export interface ApiClient { getTokenInfo(): Promise; + getPendingInfo(): Promise; + getGasBalance(chainSymbol: ChainSymbol, address: string): Promise; + + checkAddress(chainSymbol: ChainSymbol, address: string, tokenAddress?: string): Promise; + getTransferStatus(chainSymbol: ChainSymbol, txId: string): Promise; + getReceiveTransactionCost(args: ReceiveTransactionCostRequest): Promise; + getPoolInfoMap(pools: PoolKeyObject[] | PoolKeyObject): Promise; } @@ -65,6 +73,17 @@ export class ApiClientImpl implements ApiClient { return data; } + async checkAddress(chainSymbol: ChainSymbol, address: string, tokenAddress?: string): Promise { + if (tokenAddress) { + const { data } = await this.api.get(`/check/${chainSymbol}/${address}`, { + params: { token: tokenAddress, ...this.api.defaults.params }, + }); + return data; + } + const { data } = await this.api.get(`/check/${chainSymbol}/${address}`); + return data; + } + async getTransferStatus(chainSymbol: ChainSymbol, txId: string): Promise { const { data } = await this.api.get(`/chain/${chainSymbol}/${txId}`); return data; diff --git a/src/client/core-api/core-api.model.ts b/src/client/core-api/core-api.model.ts index d6b099d5..17605154 100644 --- a/src/client/core-api/core-api.model.ts +++ b/src/client/core-api/core-api.model.ts @@ -18,6 +18,7 @@ export enum AddressStatus { FORBIDDEN = "FORBIDDEN", UNINITIALIZED = "UNINITIALIZED", CONTRACT_ADDRESS = "CONTRACT_ADDRESS", + WRONG_ASSOCIATED_ACCOUNT_OWNER = "WRONG_ASSOCIATED_ACCOUNT_OWNER", } export interface TokenDTO { @@ -87,6 +88,11 @@ export interface GasBalanceResponse { status: AddressStatus; } +export interface CheckAddressResponse { + gasBalance: string | null; + status: AddressStatus; +} + export interface TransferStatusResponse { txId: string; diff --git a/src/client/core-api/core-client-pool-info-caching.ts b/src/client/core-api/core-client-pool-info-caching.ts index 1e38b800..7d2f6986 100644 --- a/src/client/core-api/core-client-pool-info-caching.ts +++ b/src/client/core-api/core-client-pool-info-caching.ts @@ -3,6 +3,7 @@ import { ChainSymbol } from "../../chains"; import { ChainDetailsMap, PoolInfo, PoolInfoMap, PoolKeyObject, TokenWithChainDetails } from "../../tokens-info"; import { mapChainDetailsMapToPoolKeyObjects, mapPoolKeyObjectToPoolKey } from "./core-api-mapper"; import { + CheckAddressResponse, GasBalanceResponse, PendingInfoResponse, ReceiveTransactionCostRequest, @@ -44,6 +45,10 @@ export class AllbridgeCoreClientPoolInfoCaching implements AllbridgeCoreClient { return this.client.getGasBalance(chainSymbol, address); } + checkAddress(chainSymbol: ChainSymbol, address: string, tokenAddress?: string): Promise { + return this.client.checkAddress(chainSymbol, address, tokenAddress); + } + async getPoolInfoByKey(poolKeyObject: PoolKeyObject): Promise { this.poolInfoCache.putAllIfNotExists((await this.client.getChainDetailsMapAndPoolInfoMap()).poolInfoMap); const poolInfo = this.poolInfoCache.get(poolKeyObject); diff --git a/src/client/core-api/index.ts b/src/client/core-api/index.ts index acd8dfc5..c8cb7843 100644 --- a/src/client/core-api/index.ts +++ b/src/client/core-api/index.ts @@ -2,6 +2,7 @@ import { ChainSymbol } from "../../chains"; import { ChainDetailsMap, PoolInfoMap, PoolKeyObject, TokenWithChainDetails } from "../../tokens-info"; import { ApiClient } from "./api-client"; import { + CheckAddressResponse, GasBalanceResponse, PendingInfoResponse, ReceiveTransactionCostRequest, @@ -48,6 +49,10 @@ export class AllbridgeCoreClientImpl implements AllbridgeCoreClient { return this.apiClient.getGasBalance(chainSymbol, address); } + async checkAddress(chainSymbol: ChainSymbol, address: string, tokenAddress?: string): Promise { + return this.apiClient.checkAddress(chainSymbol, address, tokenAddress); + } + async getChainDetailsMapAndPoolInfoMap(): Promise<{ chainDetailsMap: ChainDetailsMap; poolInfoMap: PoolInfoMap; diff --git a/src/index.ts b/src/index.ts index d423c6d3..299e2da2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,7 +7,9 @@ import { BridgeService, ChainDetailsMap, ChainSymbol, + CheckAddressResponse, ExtraGasMaxLimitResponse, + GasBalanceResponse, GasFeeOptions, GetNativeTokenBalanceParams, GetTokenBalanceParams, @@ -20,7 +22,6 @@ import { SwapAndBridgeCalculationData, TokenWithChainDetails, TransferStatusResponse, - GasBalanceResponse, } from "./models"; import { AllbridgeCoreSdkService, NodeRpcUrlsConfig } from "./services"; import { DefaultUtils, Utils } from "./utils"; @@ -142,6 +143,15 @@ export class AllbridgeCoreSdk { return this.service.getGasBalance(chainSymbol, address); } + /** + * Check address and show gas balance + * @param chainSymbol + * @param address + */ + async checkAddress(chainSymbol: ChainSymbol, address: string, tokenAddress?: string): Promise { + return this.service.checkAddress(chainSymbol, address, tokenAddress); + } + /** * Returns information about pending transactions for the same destination chain and the amount of tokens can be received as a result of transfer considering pending transactions. * @param amount the amount of tokens that will be sent diff --git a/src/models/index.ts b/src/models/index.ts index c851a4a0..d8ebe1e9 100644 --- a/src/models/index.ts +++ b/src/models/index.ts @@ -16,6 +16,7 @@ export { TransferStatusResponse, BridgeTransaction, GasBalanceResponse, + CheckAddressResponse, AddressStatus, } from "../client/core-api/core-api.model"; export { ChainSymbol, ChainType } from "../chains/index"; diff --git a/src/services/index.ts b/src/services/index.ts index fdd0d082..3ddad245 100644 --- a/src/services/index.ts +++ b/src/services/index.ts @@ -4,6 +4,7 @@ import { AllbridgeCoreClientImpl } from "../client/core-api"; import { ApiClientImpl } from "../client/core-api/api-client"; import { ApiClientCaching } from "../client/core-api/api-client-caching"; import { + CheckAddressResponse, GasBalanceResponse, Messenger, PendingInfoDTO, @@ -109,6 +110,10 @@ export class AllbridgeCoreSdkService { return this.api.getGasBalance(chainSymbol, address); } + async checkAddress(chainSymbol: ChainSymbol, address: string, tokenAddress?: string): Promise { + return this.api.checkAddress(chainSymbol, address, tokenAddress); + } + async getPendingStatusInfo( amount: string, amountFormat: AmountFormat,