Skip to content

Commit

Permalink
feat(ChainSymbol): make work with ChainSymbol in string way (return s…
Browse files Browse the repository at this point in the history
…till ChainSymbol)
  • Loading branch information
AntonKozAllB committed Aug 12, 2024
1 parent e0c8821 commit 1bc964a
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 24 deletions.
10 changes: 5 additions & 5 deletions src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ describe("SDK", () => {

const sourceChainToken: TokenWithChainDetails = {
...basicTokenInfoWithChainDetails,
chainSymbol: "GRL",
chainSymbol: "GRL" as ChainSymbol,
decimals: 18,
feeShare: "0",
};
Expand Down Expand Up @@ -134,7 +134,7 @@ describe("SDK", () => {
const scope: nock.Scope = nock("http://localhost");
const sourceChainToken: TokenWithChainDetails = {
...basicTokenInfoWithChainDetails,
chainSymbol: "GRL",
chainSymbol: "GRL" as ChainSymbol,
decimals: 6,
feeShare: "0",
};
Expand Down Expand Up @@ -194,7 +194,7 @@ describe("SDK", () => {
const scope: nock.Scope = nock("http://localhost");
const sourceChainToken: TokenWithChainDetails = {
...basicTokenInfoWithChainDetails,
chainSymbol: "GRL",
chainSymbol: "GRL" as ChainSymbol,
decimals: 18,
feeShare: "0.003",
};
Expand Down Expand Up @@ -613,7 +613,7 @@ describe("SDK", () => {
const grlChainToken: TokenWithChainDetails = {
...basicTokenInfoWithChainDetails,
allbridgeChainId: 2,
chainSymbol: "GRL",
chainSymbol: "GRL" as ChainSymbol,
bridgeAddress: "0xba285A8F52601EabCc769706FcBDe2645aa0AF18",
tokenAddress: "0xDdaC3cb57DEa3fBEFF4997d78215535Eb5787117",
decimals: 18,
Expand All @@ -622,7 +622,7 @@ describe("SDK", () => {
const grlChainToken2: TokenWithChainDetails = {
...basicTokenInfoWithChainDetails,
allbridgeChainId: 2,
chainSymbol: "GRL",
chainSymbol: "GRL" as ChainSymbol,
bridgeAddress: "0xba285A8F52601EabCc769706FcBDe2645aa0AF18",
tokenAddress: "0xC7DBC4A896b34B7a10ddA2ef72052145A9122F43",
decimals: 18,
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/mock/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import nock, { Body, RequestBodyMatcher } from "nock";
import { Chains } from "../../chains";
import { ChainType } from "../../chains/chain.enums";
import { ChainSymbol, ChainType } from "../../chains/chain.enums";
import { PoolInfo, TokenWithChainDetails } from "../../tokens-info";

export function getRequestBodyMatcher(expectedBody: any): RequestBodyMatcher {
Expand All @@ -9,7 +9,7 @@ export function getRequestBodyMatcher(expectedBody: any): RequestBodyMatcher {
export function initChainsWithTestnet() {
Chains.addChainsProperties({
GRL: {
chainSymbol: "GRL",
chainSymbol: "GRL" as ChainSymbol,
chainId: "0x5",
name: "Goerli",
chainType: ChainType.EVM,
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/services/bridge/evm/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Web3 from "web3";
import { Messenger } from "../../../../client/core-api/core-api.model";
import { AllbridgeCoreClientWithPoolInfo } from "../../../../client/core-api/core-client-base";
import { FeePaymentMethod, SendParams, TokenWithChainDetails } from "../../../../models";
import { ChainSymbol, FeePaymentMethod, SendParams, TokenWithChainDetails } from "../../../../models";
import { NodeRpcUrlsConfig } from "../../../../services";
import { EvmBridgeService } from "../../../../services/bridge/evm";
import { ChainDetailsMapWithFlags } from "../../../../tokens-info";
Expand Down Expand Up @@ -42,14 +42,14 @@ describe("EvmBridge", () => {
sourceToken: {
bridgeAddress: bridgeAddress,
allbridgeChainId: 2,
chainSymbol: "GRL",
chainSymbol: "GRL" as ChainSymbol,
decimals: 18,
tokenAddress: "0xc7dbc4a896b34b7a10dda2ef72052145a9122f43",
} as TokenWithChainDetails,
fromAccountAddress: from,
destinationToken: {
allbridgeChainId: 4,
chainSymbol: "GRL",
chainSymbol: "GRL" as ChainSymbol,
decimals: 18,
tokenAddress: "0xb10388f04f8331b59a02732cc1b6ac0d7045574b",
} as TokenWithChainDetails,
Expand Down
10 changes: 8 additions & 2 deletions src/chains/models.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChainType } from "./chain.enums";
import { ChainSymbol, ChainType } from "./chain.enums";

/**
* Contains blockchain's basic information
Expand All @@ -7,7 +7,7 @@ export interface BasicChainProperties {
/**
* The symbol of the chain representing one of the supported blockchain networks (e.g., "ETH" for Ethereum). For more details, see: {@link ChainSymbol}.
*/
chainSymbol: string;
chainSymbol: ChainSymbol;
/**
* Common Blockchain Id</br>
* A 0x-prefixed hexadecimal string</br>
Expand All @@ -23,3 +23,9 @@ export interface BasicChainProperties {
*/
chainType: ChainType;
}
export interface AdditionalBasicChainProperties extends Omit<BasicChainProperties, "chainSymbol"> {
/**
* The symbol of the chain representing one of the supported blockchain networks (e.g., "ETH" for Ethereum). For more details, see: {@link ChainSymbol}.
*/
chainSymbol: string;
}
3 changes: 2 additions & 1 deletion src/client/core-api/core-api-mapper.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Chains } from "../../chains";
import { ChainSymbol } from "../../chains/chain.enums";
import {
ChainDetails,
ChainDetailsMap,
Expand Down Expand Up @@ -75,7 +76,7 @@ function mapMessengerKeyDtoToMessenger(dto: MessengerKeyDTO): Messenger | null {

function mapTransferTimeFromDto(dto: TransferTimeDTO): TransferTime {
return Object.entries(dto).reduce<TransferTime>((result, [key, value]) => {
result[key] = mapMessengerTransferTimeFromDto(value);
result[key as ChainSymbol] = mapMessengerTransferTimeFromDto(value);
return result;
}, {});
}
Expand Down
9 changes: 5 additions & 4 deletions src/client/core-api/core-api.model.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ChainSymbol } from "../../chains/chain.enums";
import { PoolInfo } from "../../tokens-info";

export type ChainDetailsResponse = Record<string, ChainDetailsDTO>;
Expand Down Expand Up @@ -97,8 +98,8 @@ export interface CheckAddressResponse {
export interface TransferStatusResponse {
txId: string;

sourceChainSymbol: string;
destinationChainSymbol: string;
sourceChainSymbol: ChainSymbol;
destinationChainSymbol: ChainSymbol;

sendAmount: string;
sendAmountFormatted: number;
Expand Down Expand Up @@ -155,8 +156,8 @@ export interface BridgeTransaction {
isClaimable?: boolean;
}

export type PoolInfoResponse = Record<string, PoolInfo>;
export type PendingInfoResponse = Record<string, TokenPendingInfoDTO>;
export type PoolInfoResponse = Record<ChainSymbol, PoolInfo>;
export type PendingInfoResponse = Partial<Record<ChainSymbol, TokenPendingInfoDTO>>;
export type TokenPendingInfoDTO = Record<string, PendingInfoDTO>;

export interface PendingInfoDTO {
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BigSource } from "big.js";
import { BasicChainProperties } from "./chains/models";
import { AdditionalBasicChainProperties } from "./chains/models";
import { mainnet } from "./configs";
import {
AmountFormat,
Expand Down Expand Up @@ -65,7 +65,7 @@ export interface AllbridgeCoreSdkOptions {
* @Internal
* Optional additional properties to merge with the default properties.
*/
additionalChainsProperties?: Record<string, BasicChainProperties>;
additionalChainsProperties?: Record<string, AdditionalBasicChainProperties>;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export { SrbUtils, TrustLineParams } from "../utils/srb";
export { SolUtils } from "../utils/sol";
export * from "../exceptions";
export { ChainSymbol, ChainType } from "../chains/chain.enums";
export { BasicChainProperties } from "../chains/models";
export { AdditionalBasicChainProperties, BasicChainProperties } from "../chains/models";

export enum FeePaymentMethod {
/**
Expand Down
4 changes: 2 additions & 2 deletions src/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { AllbridgeCoreClientImpl } from "../client/core-api/core-client-base";
import { AllbridgeCoreClientFiltered, AllbridgeCoreClientFilteredImpl } from "../client/core-api/core-client-filtered";
import { AllbridgeCoreClientPoolInfoCaching } from "../client/core-api/core-client-pool-info-caching";
import { mainnet } from "../configs";
import { AllbridgeCoreSdkOptions, NodeRpcUrls, SdkError } from "../index";
import { AllbridgeCoreSdkOptions, BasicChainProperties, NodeRpcUrls, SdkError } from "../index";
import {
AmountFormat,
AmountFormatted,
Expand Down Expand Up @@ -81,7 +81,7 @@ export class AllbridgeCoreSdkService {
pool: LiquidityPoolService;

constructor(nodeRpcUrlsConfig: NodeRpcUrlsConfig, params: AllbridgeCoreSdkOptions = mainnet) {
Chains.addChainsProperties(params.additionalChainsProperties);
Chains.addChainsProperties(params.additionalChainsProperties as Record<string, BasicChainProperties>);
const apiClient = new ApiClientImpl(params);
const apiClientCaching = new ApiClientCaching(apiClient);
const coreClient = new AllbridgeCoreClientImpl(apiClientCaching);
Expand Down
7 changes: 5 additions & 2 deletions src/tokens-info/tokens-info.model.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ChainSymbol } from "../chains/chain.enums";
import { BasicChainProperties } from "../chains/models";
import { Messenger } from "../client/core-api/core-api.model";

Expand Down Expand Up @@ -175,10 +176,12 @@ export interface PoolInfo {
* Type representing transfer times for various blockchain chains.
*
* @typedef {Record<string, MessengerTransferTime>} TransferTime
* @property {string} chainSymbol - The symbol of the chain representing one of the supported blockchain networks (e.g., "ETH" for Ethereum). For more details, see: {@link ChainSymbol}.
* @property {chain} chainSymbol
* @property {MessengerTransferTime} transferTime - The average transfer time details for the specified chain.
*/
export type TransferTime = Record<string, MessengerTransferTime>;
export type TransferTime = {
[chain in ChainSymbol]?: MessengerTransferTime;
};

/**
* Contains Avg transaction time withing different messenger protocols
Expand Down

0 comments on commit 1bc964a

Please sign in to comment.