diff --git a/src/data/enrichers/onChainPoolDataEnricher.ts b/src/data/enrichers/onChainPoolDataEnricher.ts index 3903e565..e7cb9773 100644 --- a/src/data/enrichers/onChainPoolDataEnricher.ts +++ b/src/data/enrichers/onChainPoolDataEnricher.ts @@ -6,6 +6,7 @@ import { RawPool, RawPoolTokenWithRate, RawWeightedPoolToken, + HumanAmount, } from '../types'; import { @@ -16,7 +17,7 @@ import { poolHasVirtualSupply, poolIsLinearPool, } from '../../utils'; -import { HumanAmount, SwapOptions } from '../../types'; +import { SwapOptions } from '../../types'; interface OnChainPoolData { id: string; diff --git a/src/data/types.ts b/src/data/types.ts index fa08eb3d..d322afab 100644 --- a/src/data/types.ts +++ b/src/data/types.ts @@ -1,5 +1,6 @@ import { Address, Hex } from 'viem'; -import { HumanAmount } from '../types'; + +export type HumanAmount = `${number}`; // These are only the known pool types, additional pool types can be added via // extension through custom PoolFactories and PoolDataProviders diff --git a/src/entities/exit/weighted/validateInputs.ts b/src/entities/exit/weighted/validateInputs.ts index 2b89aab7..aaf86f10 100644 --- a/src/entities/exit/weighted/validateInputs.ts +++ b/src/entities/exit/weighted/validateInputs.ts @@ -1,4 +1,4 @@ -import { ExitInput, ExitKind } from '..'; +import { ExitInput, ExitKind } from '../types'; import { PoolStateInput } from '../../types'; import { areTokensInArray } from '../../utils/areTokensInArray'; diff --git a/src/entities/join/weighted/validateInputs.ts b/src/entities/join/weighted/validateInputs.ts index 02a9b053..733073c8 100644 --- a/src/entities/join/weighted/validateInputs.ts +++ b/src/entities/join/weighted/validateInputs.ts @@ -1,4 +1,4 @@ -import { JoinInput, JoinKind } from '..'; +import { JoinInput, JoinKind } from '../types'; import { PoolStateInput } from '../../types'; import { areTokensInArray } from '../../utils/areTokensInArray'; diff --git a/src/entities/join/weighted/weightedJoin.ts b/src/entities/join/weighted/weightedJoin.ts index b10fe0fc..262b52b8 100644 --- a/src/entities/join/weighted/weightedJoin.ts +++ b/src/entities/join/weighted/weightedJoin.ts @@ -1,5 +1,7 @@ import { encodeFunctionData } from 'viem'; -import { Token, TokenAmount, WeightedEncoder } from '../../..'; +import { Token } from '../../../entities/token'; +import { TokenAmount } from '../../../entities/tokenAmount'; +import { WeightedEncoder } from '../../../entities/encoders/weighted'; import { Address } from '../../../types'; import { BALANCER_VAULT, MAX_UINT256, ZERO_ADDRESS } from '../../../utils'; import { vaultAbi } from '../../../abi'; @@ -10,7 +12,7 @@ import { JoinInput, JoinKind, JoinQueryResult, -} from '..'; +} from '../types'; import { AmountsJoin, PoolState } from '../../types'; import { doQueryJoin, getAmounts, parseJoinArgs } from '../../utils'; diff --git a/src/entities/path.ts b/src/entities/path.ts index 8055a2e2..d9053a8d 100644 --- a/src/entities/path.ts +++ b/src/entities/path.ts @@ -1,5 +1,6 @@ import { BasePool } from './pools/'; -import { Token, TokenAmount } from './'; +import { Token } from './token'; +import { TokenAmount } from './tokenAmount'; import { SwapKind } from '../types'; export class Path { diff --git a/src/entities/pools/fx/fxFactory.ts b/src/entities/pools/fx/fxFactory.ts index 04d17822..b2c9dca9 100644 --- a/src/entities/pools/fx/fxFactory.ts +++ b/src/entities/pools/fx/fxFactory.ts @@ -1,5 +1,5 @@ import { BasePool, BasePoolFactory } from '../'; -import { FxPool } from './'; +import { FxPool } from './fxPool'; import { RawFxPool, RawPool } from '../../../data/types'; export class FxPoolFactory implements BasePoolFactory { diff --git a/src/entities/pools/fx/fxMath.ts b/src/entities/pools/fx/fxMath.ts index e73f6ead..70b15b21 100644 --- a/src/entities/pools/fx/fxMath.ts +++ b/src/entities/pools/fx/fxMath.ts @@ -1,6 +1,6 @@ import { parseUnits } from 'viem'; -import { RAY } from '../../../utils'; -import { FxPoolPairData } from './fxPool'; +import { RAY } from '../../../utils/math'; +import { FxPoolPairData } from './types'; import { SwapKind } from '../../../types'; export const CURVEMATH_MAX_DIFF = parseUnits('-0.000001000000000000024', 36); diff --git a/src/entities/pools/fx/fxPool.ts b/src/entities/pools/fx/fxPool.ts index afc163f9..d264efc5 100644 --- a/src/entities/pools/fx/fxPool.ts +++ b/src/entities/pools/fx/fxPool.ts @@ -1,11 +1,14 @@ import { Hex, parseEther, parseUnits } from 'viem'; -import { HumanAmount, PoolType, SwapKind } from '../../../types'; -import { BigintIsh, Token, TokenAmount } from '../../'; +import { PoolType, SwapKind } from '../../../types'; +import { Token } from '../../token'; +import { TokenAmount } from '../../tokenAmount'; import { BasePool } from '../../pools'; -import { RAY, WAD, getPoolAddress } from '../../../utils'; +import { RAY, getPoolAddress } from '../../../utils'; import { _calcInGivenOut, _calcOutGivenIn } from './fxMath'; import { RawFxPool } from '../../../data/types'; import { MathFx, parseFixedCurveParam } from './helpers'; +import { FxPoolPairData } from './types'; +import { FxPoolToken } from './fxPoolToken'; const isUSDC = (address: string): boolean => { return ( @@ -15,104 +18,6 @@ const isUSDC = (address: string): boolean => { ); }; -export type FxPoolPairData = { - tIn: FxPoolToken; - tOut: FxPoolToken; - alpha: bigint; - beta: bigint; - delta: bigint; - lambda: bigint; - _oGLiq: bigint; - _nGLiq: bigint; - _oBals: bigint[]; - _nBals: bigint[]; - givenToken: FxPoolToken; - swapKind: SwapKind; -}; - -export class FxPoolToken extends TokenAmount { - public readonly index: number; - public readonly latestFXPrice: HumanAmount; - public readonly fxOracleDecimals: number; - public numeraire: bigint; // in 36 decimals - private readonly scalar36 = this.scalar * WAD; - - public constructor( - token: Token, - amount: BigintIsh, - latestFXPrice: HumanAmount, - fxOracleDecimals: number, - index: number, - ) { - super(token, amount); - this.latestFXPrice = latestFXPrice; - this.fxOracleDecimals = fxOracleDecimals; - const truncatedNumeraire = MathFx.mulDownFixed( - this.amount, - parseUnits(this.latestFXPrice, this.fxOracleDecimals), - this.fxOracleDecimals, - ); - this.numeraire = truncatedNumeraire * this.scalar36; - this.index = index; - } - - public increase(amount: bigint): TokenAmount { - this.amount = this.amount + amount; - this.scale18 = this.amount * this.scalar; - const truncatedNumeraire = MathFx.mulDownFixed( - this.amount, - parseUnits(this.latestFXPrice, this.fxOracleDecimals), - this.fxOracleDecimals, - ); - this.numeraire = truncatedNumeraire * this.scalar36; - return this; - } - - public decrease(amount: bigint): TokenAmount { - this.amount = this.amount - amount; - this.scale18 = this.amount * this.scalar; - const truncatedNumeraire = MathFx.mulDownFixed( - this.amount, - parseUnits(this.latestFXPrice, this.fxOracleDecimals), - this.fxOracleDecimals, - ); - this.numeraire = truncatedNumeraire * this.scalar36; - return this; - } - - public static fromNumeraire( - poolToken: FxPoolToken, - numeraire: BigintIsh, - divUp?: boolean, - ): FxPoolToken { - const truncatedNumeraire = BigInt(numeraire) / poolToken.scalar36; // loss of precision required to match SC implementation - const amount = divUp - ? MathFx.divUpFixed( - BigInt(truncatedNumeraire), - parseUnits( - poolToken.latestFXPrice, - poolToken.fxOracleDecimals, - ), - poolToken.fxOracleDecimals, - ) - : MathFx.divDownFixed( - BigInt(truncatedNumeraire), - parseUnits( - poolToken.latestFXPrice, - poolToken.fxOracleDecimals, - ), - poolToken.fxOracleDecimals, - ); - return new FxPoolToken( - poolToken.token, - amount, - poolToken.latestFXPrice, - poolToken.fxOracleDecimals, - poolToken.index, - ); - } -} - export class FxPool implements BasePool { public readonly chainId: number; public readonly id: Hex; diff --git a/src/entities/pools/fx/fxPoolToken.ts b/src/entities/pools/fx/fxPoolToken.ts new file mode 100644 index 00000000..75f2d1f4 --- /dev/null +++ b/src/entities/pools/fx/fxPoolToken.ts @@ -0,0 +1,90 @@ +import { parseUnits } from 'viem'; +import { Token } from '../../token'; +import { TokenAmount, BigintIsh } from '../../tokenAmount'; +import { WAD } from '../../../utils/math'; +import { _calcInGivenOut, _calcOutGivenIn } from './fxMath'; +import { HumanAmount } from '../../../data/types'; +import { MathFx } from './helpers'; + +export class FxPoolToken extends TokenAmount { + public readonly index: number; + public readonly latestFXPrice: HumanAmount; + public readonly fxOracleDecimals: number; + public numeraire: bigint; // in 36 decimals + private readonly scalar36 = this.scalar * WAD; + + public constructor( + token: Token, + amount: BigintIsh, + latestFXPrice: HumanAmount, + fxOracleDecimals: number, + index: number, + ) { + super(token, amount); + this.latestFXPrice = latestFXPrice; + this.fxOracleDecimals = fxOracleDecimals; + const truncatedNumeraire = MathFx.mulDownFixed( + this.amount, + parseUnits(this.latestFXPrice, this.fxOracleDecimals), + this.fxOracleDecimals, + ); + this.numeraire = truncatedNumeraire * this.scalar36; + this.index = index; + } + + public increase(amount: bigint): TokenAmount { + this.amount = this.amount + amount; + this.scale18 = this.amount * this.scalar; + const truncatedNumeraire = MathFx.mulDownFixed( + this.amount, + parseUnits(this.latestFXPrice, this.fxOracleDecimals), + this.fxOracleDecimals, + ); + this.numeraire = truncatedNumeraire * this.scalar36; + return this; + } + + public decrease(amount: bigint): TokenAmount { + this.amount = this.amount - amount; + this.scale18 = this.amount * this.scalar; + const truncatedNumeraire = MathFx.mulDownFixed( + this.amount, + parseUnits(this.latestFXPrice, this.fxOracleDecimals), + this.fxOracleDecimals, + ); + this.numeraire = truncatedNumeraire * this.scalar36; + return this; + } + + public static fromNumeraire( + poolToken: FxPoolToken, + numeraire: BigintIsh, + divUp?: boolean, + ): FxPoolToken { + const truncatedNumeraire = BigInt(numeraire) / poolToken.scalar36; // loss of precision required to match SC implementation + const amount = divUp + ? MathFx.divUpFixed( + BigInt(truncatedNumeraire), + parseUnits( + poolToken.latestFXPrice, + poolToken.fxOracleDecimals, + ), + poolToken.fxOracleDecimals, + ) + : MathFx.divDownFixed( + BigInt(truncatedNumeraire), + parseUnits( + poolToken.latestFXPrice, + poolToken.fxOracleDecimals, + ), + poolToken.fxOracleDecimals, + ); + return new FxPoolToken( + poolToken.token, + amount, + poolToken.latestFXPrice, + poolToken.fxOracleDecimals, + poolToken.index, + ); + } +} diff --git a/src/entities/pools/fx/helpers.ts b/src/entities/pools/fx/helpers.ts index ddd9bb52..cfedbb46 100644 --- a/src/entities/pools/fx/helpers.ts +++ b/src/entities/pools/fx/helpers.ts @@ -1,5 +1,5 @@ import { parseUnits } from 'viem'; -import { HumanAmount } from '../../../types'; +import { HumanAmount } from '../../../data/types'; export class MathFx { static mulDownFixed(a: bigint, b: bigint, decimals = 36): bigint { diff --git a/src/entities/pools/fx/index.ts b/src/entities/pools/fx/index.ts index 6686b03e..ca789301 100644 --- a/src/entities/pools/fx/index.ts +++ b/src/entities/pools/fx/index.ts @@ -1,3 +1,5 @@ export * from './fxFactory'; export * from './fxPool'; export * from './fxMath'; +export * from './types'; +export * from './fxPoolToken'; diff --git a/src/entities/pools/fx/types.ts b/src/entities/pools/fx/types.ts new file mode 100644 index 00000000..c1a28fb0 --- /dev/null +++ b/src/entities/pools/fx/types.ts @@ -0,0 +1,17 @@ +import { SwapKind } from '../../../types'; +import { FxPoolToken } from './fxPoolToken'; + +export type FxPoolPairData = { + tIn: FxPoolToken; + tOut: FxPoolToken; + alpha: bigint; + beta: bigint; + delta: bigint; + lambda: bigint; + _oGLiq: bigint; + _nGLiq: bigint; + _oBals: bigint[]; + _nBals: bigint[]; + givenToken: FxPoolToken; + swapKind: SwapKind; +}; diff --git a/src/entities/pools/gyro2/gyro2Factory.ts b/src/entities/pools/gyro2/gyro2Factory.ts index a57272fa..9014c7a4 100644 --- a/src/entities/pools/gyro2/gyro2Factory.ts +++ b/src/entities/pools/gyro2/gyro2Factory.ts @@ -1,5 +1,5 @@ -import { Gyro2Pool } from '.'; -import { BasePool, BasePoolFactory } from '..'; +import { Gyro2Pool } from './gyro2Pool'; +import { BasePool, BasePoolFactory } from '../index'; import { RawGyro2Pool, RawPool } from '../../../data/types'; export class Gyro2PoolFactory implements BasePoolFactory { diff --git a/src/entities/pools/gyro2/gyro2Pool.ts b/src/entities/pools/gyro2/gyro2Pool.ts index 4e0711dd..bf9274a4 100644 --- a/src/entities/pools/gyro2/gyro2Pool.ts +++ b/src/entities/pools/gyro2/gyro2Pool.ts @@ -7,7 +7,8 @@ import { _findVirtualParams, } from './gyro2Math'; import { BasePool } from '..'; -import { BigintIsh, Token, TokenAmount } from '../..'; +import { Token } from '../../token'; +import { TokenAmount, BigintIsh } from '../../tokenAmount'; import { RawGyro2Pool } from '../../../data/types'; import { PoolType, SwapKind } from '../../../types'; import { getPoolAddress, MathSol, WAD } from '../../../utils'; diff --git a/src/entities/pools/gyro3/gyro3Factory.ts b/src/entities/pools/gyro3/gyro3Factory.ts index e938f5e0..75d038a3 100644 --- a/src/entities/pools/gyro3/gyro3Factory.ts +++ b/src/entities/pools/gyro3/gyro3Factory.ts @@ -1,5 +1,5 @@ -import { Gyro3Pool } from '.'; -import { BasePool, BasePoolFactory } from '..'; +import { Gyro3Pool } from './gyro3Pool'; +import { BasePool, BasePoolFactory } from '../index'; import { RawGyro3Pool, RawPool } from '../../../data/types'; export class Gyro3PoolFactory implements BasePoolFactory { diff --git a/src/entities/pools/gyro3/gyro3Pool.ts b/src/entities/pools/gyro3/gyro3Pool.ts index 0a7d3093..b4f7a6a2 100644 --- a/src/entities/pools/gyro3/gyro3Pool.ts +++ b/src/entities/pools/gyro3/gyro3Pool.ts @@ -6,7 +6,8 @@ import { _calculateInvariant, } from './gyro3Math'; import { BasePool } from '..'; -import { BigintIsh, Token, TokenAmount } from '../..'; +import { Token } from '../../token'; +import { TokenAmount, BigintIsh } from '../../tokenAmount'; import { RawGyro3Pool } from '../../../data/types'; import { PoolType, SwapKind } from '../../../types'; import { getPoolAddress, MathSol, WAD } from '../../../utils'; diff --git a/src/entities/pools/gyroE/gyroEFactory.ts b/src/entities/pools/gyroE/gyroEFactory.ts index 98a527d6..63e0816e 100644 --- a/src/entities/pools/gyroE/gyroEFactory.ts +++ b/src/entities/pools/gyroE/gyroEFactory.ts @@ -1,5 +1,5 @@ -import { GyroEPool } from '.'; -import { BasePool, BasePoolFactory } from '..'; +import { GyroEPool } from './gyroEPool'; +import { BasePool, BasePoolFactory } from '../index'; import { RawGyroEPool, RawPool } from '../../../data/types'; export class GyroEPoolFactory implements BasePoolFactory { diff --git a/src/entities/pools/gyroE/gyroEMath.ts b/src/entities/pools/gyroE/gyroEMath.ts index c5c909cc..690244ab 100644 --- a/src/entities/pools/gyroE/gyroEMath.ts +++ b/src/entities/pools/gyroE/gyroEMath.ts @@ -11,7 +11,7 @@ import { normalizedLiquidityXIn, normalizedLiquidityYIn, } from './gyroEMathFunctions'; -import { DerivedGyroEParams, GyroEParams, Vector2 } from './gyroEPool'; +import { DerivedGyroEParams, GyroEParams, Vector2 } from './types'; import { MathGyro, ONE_XP, SMALL } from '../../../utils/gyroHelpers/math'; export function calculateNormalizedLiquidity( diff --git a/src/entities/pools/gyroE/gyroEMathFunctions.ts b/src/entities/pools/gyroE/gyroEMathFunctions.ts index 48ad7bd7..2893c5d6 100644 --- a/src/entities/pools/gyroE/gyroEMathFunctions.ts +++ b/src/entities/pools/gyroE/gyroEMathFunctions.ts @@ -1,7 +1,7 @@ import { WAD } from '../../../utils'; import { MathGyro } from '../../../utils/gyroHelpers/math'; import { virtualOffset0, virtualOffset1 } from './gyroEMathHelpers'; -import { DerivedGyroEParams, GyroEParams, Vector2 } from './gyroEPool'; +import { DerivedGyroEParams, GyroEParams, Vector2 } from './types'; ///////// /// SPOT PRICE DERIVATIVE CALCULATIONS diff --git a/src/entities/pools/gyroE/gyroEMathHelpers.ts b/src/entities/pools/gyroE/gyroEMathHelpers.ts index 799d7970..7ba22411 100644 --- a/src/entities/pools/gyroE/gyroEMathHelpers.ts +++ b/src/entities/pools/gyroE/gyroEMathHelpers.ts @@ -1,5 +1,5 @@ import { MAX_BALANCES } from './constants'; -import { DerivedGyroEParams, GyroEParams, Vector2 } from './gyroEPool'; +import { DerivedGyroEParams, GyroEParams, Vector2 } from './types'; import { MathGyro, ONE_XP } from '../../../utils/gyroHelpers/math'; ///////// diff --git a/src/entities/pools/gyroE/gyroEPool.ts b/src/entities/pools/gyroE/gyroEPool.ts index 13868f64..4f165152 100644 --- a/src/entities/pools/gyroE/gyroEPool.ts +++ b/src/entities/pools/gyroE/gyroEPool.ts @@ -1,7 +1,8 @@ import { Hex, parseEther, parseUnits } from 'viem'; -import { BasePool } from '..'; -import { BigintIsh, Token, TokenAmount } from '../..'; +import { BasePool } from '../index'; +import { Token } from '../../token'; +import { TokenAmount, BigintIsh } from '../../tokenAmount'; import { RawGyroEPool } from '../../../data/types'; import { PoolType, SwapKind } from '../../../types'; import { MathSol, WAD, getPoolAddress } from '../../../utils'; @@ -16,6 +17,7 @@ import { calculateInvariantWithError, } from './gyroEMath'; import { MathGyro, SWAP_LIMIT_FACTOR } from '../../../utils/gyroHelpers/math'; +import { GyroEParams, Vector2, DerivedGyroEParams } from './types'; export class GyroEPoolToken extends TokenAmount { public readonly rate: bigint; @@ -46,29 +48,6 @@ export class GyroEPoolToken extends TokenAmount { } } -export type GyroEParams = { - alpha: bigint; - beta: bigint; - c: bigint; - s: bigint; - lambda: bigint; -}; - -export type Vector2 = { - x: bigint; - y: bigint; -}; - -export type DerivedGyroEParams = { - tauAlpha: Vector2; - tauBeta: Vector2; - u: bigint; - v: bigint; - w: bigint; - z: bigint; - dSq: bigint; -}; - export class GyroEPool implements BasePool { public readonly chainId: number; public readonly id: Hex; diff --git a/src/entities/pools/gyroE/index.ts b/src/entities/pools/gyroE/index.ts index 0fabeb53..d9d4c7c7 100644 --- a/src/entities/pools/gyroE/index.ts +++ b/src/entities/pools/gyroE/index.ts @@ -1,3 +1,4 @@ export * from './gyroEFactory'; export * from './gyroEPool'; export * from './gyroEMath'; +export * from './types'; diff --git a/src/entities/pools/gyroE/types.ts b/src/entities/pools/gyroE/types.ts new file mode 100644 index 00000000..5fda0b2b --- /dev/null +++ b/src/entities/pools/gyroE/types.ts @@ -0,0 +1,22 @@ +export type GyroEParams = { + alpha: bigint; + beta: bigint; + c: bigint; + s: bigint; + lambda: bigint; +}; + +export type Vector2 = { + x: bigint; + y: bigint; +}; + +export type DerivedGyroEParams = { + tauAlpha: Vector2; + tauBeta: Vector2; + u: bigint; + v: bigint; + w: bigint; + z: bigint; + dSq: bigint; +}; diff --git a/src/entities/pools/index.ts b/src/entities/pools/index.ts index fc7d6e9a..23298f2f 100644 --- a/src/entities/pools/index.ts +++ b/src/entities/pools/index.ts @@ -1,6 +1,7 @@ import { Hex } from 'viem'; import { PoolType, SwapKind } from '../../types'; -import { Token, TokenAmount } from '../'; +import { Token } from '../token'; +import { TokenAmount } from '../tokenAmount'; import { RawPool } from '../../data/types'; export interface BasePool { diff --git a/src/entities/pools/linear/index.ts b/src/entities/pools/linear/index.ts index e64a3b8e..f2a02c35 100644 --- a/src/entities/pools/linear/index.ts +++ b/src/entities/pools/linear/index.ts @@ -1,3 +1,4 @@ export * from './linearFactory'; export * from './linearPool'; export * from './linearMath'; +export * from './types'; diff --git a/src/entities/pools/linear/linearFactory.ts b/src/entities/pools/linear/linearFactory.ts index e53c7abb..d7e3aac1 100644 --- a/src/entities/pools/linear/linearFactory.ts +++ b/src/entities/pools/linear/linearFactory.ts @@ -1,5 +1,5 @@ -import { BasePool, BasePoolFactory } from '../'; -import { LinearPool } from './'; +import { BasePool, BasePoolFactory } from '../index'; +import { LinearPool } from './linearPool'; import { RawLinearPool, RawPool } from '../../../data/types'; export class LinearPoolFactory implements BasePoolFactory { diff --git a/src/entities/pools/linear/linearMath.ts b/src/entities/pools/linear/linearMath.ts index 56383314..8c18e0bb 100644 --- a/src/entities/pools/linear/linearMath.ts +++ b/src/entities/pools/linear/linearMath.ts @@ -1,5 +1,5 @@ -import { MathSol, WAD } from '../../../utils/'; -import { Params } from './'; +import { MathSol, WAD } from '../../../utils/math'; +import { Params } from './types'; export function _calcWrappedOutPerMainIn( mainIn: bigint, diff --git a/src/entities/pools/linear/linearPool.ts b/src/entities/pools/linear/linearPool.ts index 840831e4..2cefa1ec 100644 --- a/src/entities/pools/linear/linearPool.ts +++ b/src/entities/pools/linear/linearPool.ts @@ -1,6 +1,7 @@ import { Hex, parseEther } from 'viem'; import { PoolType, SwapKind } from '../../../types'; -import { BigintIsh, Token, TokenAmount } from '../../'; +import { Token } from '../../token'; +import { TokenAmount, BigintIsh } from '../../tokenAmount'; import { BasePool } from '../../pools'; import { getPoolAddress, MAX_UINT112, WAD } from '../../../utils'; import { @@ -19,6 +20,7 @@ import { } from './linearMath'; import { StablePoolToken } from '../stable/stablePool'; import { RawLinearPool } from '../../../data/types'; +import { Params } from './types'; const MAX_RATIO = parseEther('10'); const MAX_TOKEN_BALANCE = MAX_UINT112 - 1n; @@ -52,13 +54,6 @@ class BPT extends TokenAmount { } } -export type Params = { - fee: bigint; - rate: bigint; - lowerTarget: bigint; - upperTarget: bigint; -}; - export class LinearPool implements BasePool { public readonly chainId: number; public readonly id: Hex; diff --git a/src/entities/pools/linear/types.ts b/src/entities/pools/linear/types.ts new file mode 100644 index 00000000..399c93c1 --- /dev/null +++ b/src/entities/pools/linear/types.ts @@ -0,0 +1,6 @@ +export type Params = { + fee: bigint; + rate: bigint; + lowerTarget: bigint; + upperTarget: bigint; +}; diff --git a/src/entities/pools/metastable/metastableFactory.ts b/src/entities/pools/metastable/metastableFactory.ts index bd86bd09..e5190d79 100644 --- a/src/entities/pools/metastable/metastableFactory.ts +++ b/src/entities/pools/metastable/metastableFactory.ts @@ -1,5 +1,5 @@ -import { BasePool, BasePoolFactory } from '..'; -import { MetaStablePool } from '.'; +import { BasePool, BasePoolFactory } from '../index'; +import { MetaStablePool } from './metastablePool'; import { RawMetaStablePool, RawPool } from '../../../data/types'; export class MetaStablePoolFactory implements BasePoolFactory { diff --git a/src/entities/pools/stable/stableFactory.ts b/src/entities/pools/stable/stableFactory.ts index 3bc486af..1c313030 100644 --- a/src/entities/pools/stable/stableFactory.ts +++ b/src/entities/pools/stable/stableFactory.ts @@ -1,5 +1,5 @@ -import { BasePool, BasePoolFactory } from '../'; -import { StablePool } from './'; +import { BasePool, BasePoolFactory } from '../index'; +import { StablePool } from './stablePool'; import { RawComposableStablePool, RawPool } from '../../../data/types'; export class StablePoolFactory implements BasePoolFactory { diff --git a/src/entities/pools/stable/stablePool.ts b/src/entities/pools/stable/stablePool.ts index 3d4b2bfd..c3b8ce94 100644 --- a/src/entities/pools/stable/stablePool.ts +++ b/src/entities/pools/stable/stablePool.ts @@ -1,6 +1,7 @@ import { Hex, parseEther, parseUnits } from 'viem'; import { PoolType, SwapKind } from '../../../types'; -import { BigintIsh, Token, TokenAmount } from '../../'; +import { Token } from '../../token'; +import { TokenAmount, BigintIsh } from '../../tokenAmount'; import { BasePool } from '../'; import { getPoolAddress, MathSol, WAD } from '../../../utils'; import { diff --git a/src/entities/pools/weighted/weightedFactory.ts b/src/entities/pools/weighted/weightedFactory.ts index 53d5f300..5a36c0d8 100644 --- a/src/entities/pools/weighted/weightedFactory.ts +++ b/src/entities/pools/weighted/weightedFactory.ts @@ -1,5 +1,5 @@ -import { BasePool, BasePoolFactory } from '../'; -import { WeightedPool } from './'; +import { BasePool, BasePoolFactory } from '../index'; +import { WeightedPool } from './weightedPool'; import { RawPool, RawWeightedPool } from '../../../data/types'; export class WeightedPoolFactory implements BasePoolFactory { diff --git a/src/entities/pools/weighted/weightedPool.ts b/src/entities/pools/weighted/weightedPool.ts index baecc0f9..f47a5104 100644 --- a/src/entities/pools/weighted/weightedPool.ts +++ b/src/entities/pools/weighted/weightedPool.ts @@ -1,6 +1,7 @@ import { Hex, parseEther } from 'viem'; import { PoolType, SwapKind } from '../../../types'; -import { Token, TokenAmount, BigintIsh } from '../../'; +import { Token } from '../../token'; +import { TokenAmount, BigintIsh } from '../../tokenAmount'; import { BasePool } from '../'; import { MathSol, WAD, getPoolAddress } from '../../../utils'; import { _calcOutGivenIn, _calcInGivenOut } from './weightedMath'; diff --git a/src/entities/tokenAmount.ts b/src/entities/tokenAmount.ts index e41397bd..9b9a5cb0 100644 --- a/src/entities/tokenAmount.ts +++ b/src/entities/tokenAmount.ts @@ -1,7 +1,8 @@ import { Token } from './token'; import _Decimal from 'decimal.js-light'; import { parseUnits } from 'viem'; -import { DECIMAL_SCALES, WAD } from '../utils'; +import { DECIMAL_SCALES } from '../utils/constants'; +import { WAD } from '../utils/math'; export type BigintIsh = bigint | string | number; diff --git a/src/entities/utils/doQueryExit.ts b/src/entities/utils/doQueryExit.ts index 1cd1ecf2..7cc8124c 100644 --- a/src/entities/utils/doQueryExit.ts +++ b/src/entities/utils/doQueryExit.ts @@ -1,8 +1,8 @@ import { createPublicClient, http } from 'viem'; import { Address } from '../../types'; -import { BALANCER_HELPERS, CHAINS } from '../../utils'; +import { BALANCER_HELPERS, CHAINS } from '../../utils/constants'; import { balancerHelpersAbi } from '../../abi'; -import { ExitPoolRequest } from '../exit'; +import { ExitPoolRequest } from '../exit/types'; export async function doQueryExit( rpcUrl: string, diff --git a/src/pathGraph/pathGraphTypes.ts b/src/pathGraph/pathGraphTypes.ts index 673a4a99..4a08bbf2 100644 --- a/src/pathGraph/pathGraphTypes.ts +++ b/src/pathGraph/pathGraphTypes.ts @@ -1,5 +1,12 @@ -import { PoolTokenPair } from '../types'; -import { BasePool, Token } from '../entities'; +import { Token } from '../entities/token'; +import { BasePool } from '../entities/pools/index'; + +export interface PoolTokenPair { + id: string; + pool: BasePool; + tokenIn: Token; + tokenOut: Token; +} export type PoolAddressDictionary = { [address: string]: BasePool; diff --git a/src/types.ts b/src/types.ts index c7a66698..b89b0b93 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,6 +1,7 @@ -import { BigintIsh, Token, BasePool, BasePoolFactory } from './entities'; import { PoolDataEnricher, PoolDataProvider } from './data/types'; import { PathGraphTraversalConfig } from './pathGraph/pathGraphTypes'; +import { BigintIsh } from './entities/tokenAmount'; +import { BasePoolFactory } from './entities/pools/index'; export type Address = `0x${string}`; export type Hex = `0x${string}`; @@ -45,13 +46,6 @@ export type SorConfig = { customPoolFactories?: BasePoolFactory[]; }; -export interface PoolTokenPair { - id: string; - pool: BasePool; - tokenIn: Token; - tokenOut: Token; -} - export interface SingleSwap { poolId: Hex; kind: SwapKind; @@ -68,5 +62,3 @@ export interface BatchSwapStep { amount: bigint; userData: Hex; } - -export type HumanAmount = `${number}`; diff --git a/src/utils/helpers.ts b/src/utils/helpers.ts index 02620be0..f895d370 100644 --- a/src/utils/helpers.ts +++ b/src/utils/helpers.ts @@ -1,4 +1,5 @@ -import { BigintIsh, Token, TokenAmount } from '../entities'; +import { Token } from '../entities/token'; +import { TokenAmount, BigintIsh } from '../entities/tokenAmount'; import { SwapKind } from '../types'; export function checkInputs(