Skip to content

Commit

Permalink
rename stable to composablestable
Browse files Browse the repository at this point in the history
  • Loading branch information
franzns committed Feb 9, 2024
1 parent 78223fc commit 9547467
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { chainToIdMap } from '../../../../../network/network-config';
import { StableData } from '../../../../../pool/subgraph-mapper';
import { TokenPairData } from '../../../../../pool/lib/pool-on-chain-tokenpair-data';

export class StablePoolToken extends TokenAmount {
export class ComposableStablePoolToken extends TokenAmount {
public readonly rate: bigint;
public readonly index: number;

Expand All @@ -40,24 +40,24 @@ export class StablePoolToken extends TokenAmount {
}
}

export class StablePool implements BasePool {
export class ComposableStablePool implements BasePool {
public readonly chain: Chain;
public readonly id: Hex;
public readonly address: string;
public readonly poolType: PoolType = PoolType.MetaStable;
public readonly poolType: PoolType = PoolType.ComposableStable;
public readonly amp: bigint;
public readonly swapFee: bigint;
public readonly bptIndex: number;
public readonly tokenPairs: TokenPairData[];

public totalShares: bigint;
public tokens: StablePoolToken[];
public tokens: ComposableStablePoolToken[];

private readonly tokenMap: Map<string, StablePoolToken>;
private readonly tokenMap: Map<string, ComposableStablePoolToken>;
private readonly tokenIndexMap: Map<string, number>;

static fromPrismaPool(pool: PrismaPoolWithDynamic): StablePool {
const poolTokens: StablePoolToken[] = [];
static fromPrismaPool(pool: PrismaPoolWithDynamic): ComposableStablePool {
const poolTokens: ComposableStablePoolToken[] = [];

if (!pool.dynamicData) throw new Error('Stable pool has no dynamic data');

Expand All @@ -73,7 +73,7 @@ export class StablePool implements BasePool {
const tokenAmount = TokenAmount.fromHumanAmount(token, `${parseFloat(poolToken.dynamicData.balance)}`);

poolTokens.push(
new StablePoolToken(
new ComposableStablePoolToken(
token,
tokenAmount.amount,
parseEther(poolToken.dynamicData.priceRate),
Expand All @@ -85,7 +85,7 @@ export class StablePool implements BasePool {
const totalShares = parseEther(pool.dynamicData.totalShares);
const amp = parseUnits((pool.typeData as StableData).amp, 3);

return new StablePool(
return new ComposableStablePool(
pool.id as Hex,
pool.address,
pool.chain,
Expand All @@ -103,7 +103,7 @@ export class StablePool implements BasePool {
chain: Chain,
amp: bigint,
swapFee: bigint,
tokens: StablePoolToken[],
tokens: ComposableStablePoolToken[],
totalShares: bigint,
tokenPairs: TokenPairData[],
) {
Expand Down
14 changes: 7 additions & 7 deletions modules/sor/sorV2/lib/pools/metastable/metastablePool.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Chain } from '@prisma/client';
import { Address, Hex, parseEther, parseUnits } from 'viem';
import { StablePoolToken } from '../stable/stablePool';
import { ComposableStablePoolToken } from '../composableStable/composableStablePool';
import { PrismaPoolWithDynamic } from '../../../../../../prisma/prisma-types';
import { _calcInGivenOut, _calcOutGivenIn, _calculateInvariant } from '../stable/stableMath';
import { _calcInGivenOut, _calcOutGivenIn, _calculateInvariant } from '../composableStable/stableMath';
import { MathSol, WAD } from '../../utils/math';
import { BasePool, PoolType, SwapKind, Token, TokenAmount } from '@balancer/sdk';
import { chainToIdMap } from '../../../../../network/network-config';
Expand All @@ -16,14 +16,14 @@ export class MetaStablePool implements BasePool {
public readonly poolType: PoolType = PoolType.MetaStable;
public readonly amp: bigint;
public readonly swapFee: bigint;
public readonly tokens: StablePoolToken[];
public readonly tokens: ComposableStablePoolToken[];
public readonly tokenPairs: TokenPairData[];

private readonly tokenMap: Map<string, StablePoolToken>;
private readonly tokenMap: Map<string, ComposableStablePoolToken>;
private readonly tokenIndexMap: Map<string, number>;

static fromPrismaPool(pool: PrismaPoolWithDynamic): MetaStablePool {
const poolTokens: StablePoolToken[] = [];
const poolTokens: ComposableStablePoolToken[] = [];

if (!pool.dynamicData) throw new Error('Stable pool has no dynamic data');

Expand All @@ -39,7 +39,7 @@ export class MetaStablePool implements BasePool {
const tokenAmount = TokenAmount.fromHumanAmount(token, `${parseFloat(poolToken.dynamicData.balance)}`);

poolTokens.push(
new StablePoolToken(
new ComposableStablePoolToken(
token,
tokenAmount.amount,
parseEther(poolToken.dynamicData.priceRate),
Expand Down Expand Up @@ -67,7 +67,7 @@ export class MetaStablePool implements BasePool {
chain: Chain,
amp: bigint,
swapFee: bigint,
tokens: StablePoolToken[],
tokens: ComposableStablePoolToken[],
tokenPairs: TokenPairData[],
) {
this.id = id;
Expand Down
4 changes: 2 additions & 2 deletions modules/sor/sorV2/lib/static.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import { Router } from './router';
import { PrismaPoolWithDynamic } from '../../../../prisma/prisma-types';
import { checkInputs } from './utils/helpers';
import { WeightedPool } from './pools/weighted/weightedPool';
import { StablePool } from './pools/stable/stablePool';
import { MetaStablePool } from './pools/metastable/metastablePool';
import { FxPool } from './pools/fx/fxPool';
import { Gyro2Pool } from './pools/gyro2/gyro2Pool';
import { Gyro3Pool } from './pools/gyro3/gyro3Pool';
import { GyroEPool } from './pools/gyroE/gyroEPool';
import { BasePool, Swap, SwapKind, SwapOptions, Token } from '@balancer/sdk';
import { ComposableStablePool } from './pools/composableStable/composableStablePool';

export async function sorGetSwapsWithPools(
tokenIn: Token,
Expand All @@ -29,7 +29,7 @@ export async function sorGetSwapsWithPools(
break;
case 'COMPOSABLE_STABLE':
case 'PHANTOM_STABLE':
basePools.push(StablePool.fromPrismaPool(prismaPool));
basePools.push(ComposableStablePool.fromPrismaPool(prismaPool));
break;
case 'META_STABLE':
basePools.push(MetaStablePool.fromPrismaPool(prismaPool));
Expand Down

0 comments on commit 9547467

Please sign in to comment.