Skip to content

Commit

Permalink
refactor(evm): Use instance tokens in EvmConnection.getPoolState
Browse files Browse the repository at this point in the history
  • Loading branch information
wormat committed Sep 20, 2022
1 parent 328fc19 commit 2d74210
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions packages/evm/src/EvmConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
createNonce,
getAllowanceEth,
} from "@certusone/wormhole-sdk";
import type { PoolState, TokenConfig, TokenDetails } from "@swim-io/core";
import type { PoolState, TokenDetails } from "@swim-io/core";
import { ERC20__factory, Routing__factory } from "@swim-io/evm-contracts";
import { atomicToHuman, findOrThrow, isNotNull } from "@swim-io/utils";
import Decimal from "decimal.js";
Expand Down Expand Up @@ -32,8 +32,11 @@ export type GetHistoryProvider = BaseProvider & {
) => Promise<readonly TransactionResponse[]>;
};

// @TODO remove this minimal type after ui mirgate to TokenConfig
type MinimalChainConfig = Pick<EvmChainConfig, "name" | "chainId" | "wormhole">;
// @TODO remove this minimal type after ui migrates to TokenConfig
type MinimalChainConfig = Pick<
EvmChainConfig,
"name" | "chainId" | "tokens" | "wormhole"
>;

const bigNumberToAtomicDecimal = (bigNumber: BigNumber): Decimal =>
new Decimal(bigNumber.toString());
Expand Down Expand Up @@ -320,16 +323,18 @@ export class EvmConnection {

public async getPoolState(
{ address, lpTokenId, tokenIds }: EvmPoolConfig,
tokens: readonly TokenConfig[],
routingContractAddress: string,
): Promise<PoolState> {
const routingContract = Routing__factory.connect(
routingContractAddress,
this.provider,
);
const lpToken = findOrThrow(tokens, ({ id }) => id === lpTokenId);
const lpToken = findOrThrow(
this.chainConfig.tokens,
({ id }) => id === lpTokenId,
);
const poolTokens = tokenIds.map((tokenId) =>
findOrThrow(tokens, ({ id }) => id === tokenId),
findOrThrow(this.chainConfig.tokens, ({ id }) => id === tokenId),
);

const [state] = await routingContract.getPoolStates([address]);
Expand Down

0 comments on commit 2d74210

Please sign in to comment.