Skip to content

Commit

Permalink
Merge branch 'alpha' into beta
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonKozAllB committed Feb 5, 2024
2 parents a6fc741 + 5224fb6 commit 86ea9f1
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/client/core-api/api-client-caching.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -48,6 +49,10 @@ export class ApiClientCaching implements ApiClient {
return gasBalancePromise;
}

async checkAddress(chainSymbol: ChainSymbol, address: string, tokenAddress?: string): Promise<CheckAddressResponse> {
return this.apiClient.checkAddress(chainSymbol, address, tokenAddress);
}

async getPendingInfo(): Promise<PendingInfoResponse> {
const PENDING_INFO_CACHE_KEY = "PENDING_INFO_CACHE_KEY";
const pendingInfo = this.pendingInfoCache.get(PENDING_INFO_CACHE_KEY);
Expand Down
19 changes: 19 additions & 0 deletions src/client/core-api/api-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
} from "./core-api-mapper";
import {
ChainDetailsResponse,
CheckAddressResponse,
GasBalanceResponse,
PendingInfoResponse,
PoolInfoResponse,
Expand All @@ -25,10 +26,17 @@ export interface TokenInfo {

export interface ApiClient {
getTokenInfo(): Promise<TokenInfo>;

getPendingInfo(): Promise<PendingInfoResponse>;

getGasBalance(chainSymbol: ChainSymbol, address: string): Promise<GasBalanceResponse>;

checkAddress(chainSymbol: ChainSymbol, address: string, tokenAddress?: string): Promise<CheckAddressResponse>;

getTransferStatus(chainSymbol: ChainSymbol, txId: string): Promise<TransferStatusResponse>;

getReceiveTransactionCost(args: ReceiveTransactionCostRequest): Promise<ReceiveTransactionCostResponse>;

getPoolInfoMap(pools: PoolKeyObject[] | PoolKeyObject): Promise<PoolInfoMap>;
}

Expand Down Expand Up @@ -65,6 +73,17 @@ export class ApiClientImpl implements ApiClient {
return data;
}

async checkAddress(chainSymbol: ChainSymbol, address: string, tokenAddress?: string): Promise<CheckAddressResponse> {
if (tokenAddress) {
const { data } = await this.api.get<CheckAddressResponse>(`/check/${chainSymbol}/${address}`, {
params: { token: tokenAddress, ...this.api.defaults.params },
});
return data;
}
const { data } = await this.api.get<CheckAddressResponse>(`/check/${chainSymbol}/${address}`);
return data;
}

async getTransferStatus(chainSymbol: ChainSymbol, txId: string): Promise<TransferStatusResponse> {
const { data } = await this.api.get<TransferStatusResponse>(`/chain/${chainSymbol}/${txId}`);
return data;
Expand Down
6 changes: 6 additions & 0 deletions src/client/core-api/core-api.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -87,6 +88,11 @@ export interface GasBalanceResponse {
status: AddressStatus;
}

export interface CheckAddressResponse {
gasBalance: string | null;
status: AddressStatus;
}

export interface TransferStatusResponse {
txId: string;

Expand Down
5 changes: 5 additions & 0 deletions src/client/core-api/core-client-pool-info-caching.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -44,6 +45,10 @@ export class AllbridgeCoreClientPoolInfoCaching implements AllbridgeCoreClient {
return this.client.getGasBalance(chainSymbol, address);
}

checkAddress(chainSymbol: ChainSymbol, address: string, tokenAddress?: string): Promise<CheckAddressResponse> {
return this.client.checkAddress(chainSymbol, address, tokenAddress);
}

async getPoolInfoByKey(poolKeyObject: PoolKeyObject): Promise<PoolInfo> {
this.poolInfoCache.putAllIfNotExists((await this.client.getChainDetailsMapAndPoolInfoMap()).poolInfoMap);
const poolInfo = this.poolInfoCache.get(poolKeyObject);
Expand Down
5 changes: 5 additions & 0 deletions src/client/core-api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -48,6 +49,10 @@ export class AllbridgeCoreClientImpl implements AllbridgeCoreClient {
return this.apiClient.getGasBalance(chainSymbol, address);
}

async checkAddress(chainSymbol: ChainSymbol, address: string, tokenAddress?: string): Promise<CheckAddressResponse> {
return this.apiClient.checkAddress(chainSymbol, address, tokenAddress);
}

async getChainDetailsMapAndPoolInfoMap(): Promise<{
chainDetailsMap: ChainDetailsMap;
poolInfoMap: PoolInfoMap;
Expand Down
12 changes: 11 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import {
BridgeService,
ChainDetailsMap,
ChainSymbol,
CheckAddressResponse,
ExtraGasMaxLimitResponse,
GasBalanceResponse,
GasFeeOptions,
GetNativeTokenBalanceParams,
GetTokenBalanceParams,
Expand All @@ -20,7 +22,6 @@ import {
SwapAndBridgeCalculationData,
TokenWithChainDetails,
TransferStatusResponse,
GasBalanceResponse,
} from "./models";
import { AllbridgeCoreSdkService, NodeRpcUrlsConfig } from "./services";
import { DefaultUtils, Utils } from "./utils";
Expand Down Expand Up @@ -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<CheckAddressResponse> {
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
Expand Down
1 change: 1 addition & 0 deletions src/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export {
TransferStatusResponse,
BridgeTransaction,
GasBalanceResponse,
CheckAddressResponse,
AddressStatus,
} from "../client/core-api/core-api.model";
export { ChainSymbol, ChainType } from "../chains/index";
Expand Down
5 changes: 5 additions & 0 deletions src/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -109,6 +110,10 @@ export class AllbridgeCoreSdkService {
return this.api.getGasBalance(chainSymbol, address);
}

async checkAddress(chainSymbol: ChainSymbol, address: string, tokenAddress?: string): Promise<CheckAddressResponse> {
return this.api.checkAddress(chainSymbol, address, tokenAddress);
}

async getPendingStatusInfo(
amount: string,
amountFormat: AmountFormat,
Expand Down

0 comments on commit 86ea9f1

Please sign in to comment.