Skip to content

Commit

Permalink
feat(pool-interface-update): token uri update in interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexangelj committed Jan 7, 2022
1 parent 036151e commit f280769
Show file tree
Hide file tree
Showing 4 changed files with 166 additions and 132 deletions.
50 changes: 22 additions & 28 deletions src/entities/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,42 +81,36 @@ export interface PoolInterface {
factory: string

/** {@inheritdoc IEngine.risky} */
risky: {
address: string
decimals: string | number
symbol?: string
name?: string
}
riskyAddress: string
riskyDecimals: string | number
riskySymbol?: string
riskyName?: string

/** {@inheritdoc IEngine.stable} */
stable: {
address: string
decimals: string | number
symbol?: string
name?: string
}
stableAddress: string
stableDecimals: string | number
stableSymbol?: string
stableName?: string

/** {@inheritdoc IPool.invariant} */
invariant?: string

/** {@inheritdoc CalibrationStruct} */
calibration: {
strike: string
sigma: string
maturity: string
lastTimestamp: string
gamma: string
}
strike: string
sigma: string
maturity: string
lastTimestamp: string
gamma: string

/** {@inheritdoc ReserveStruct} */
reserve: {
blockTimestamp?: string
cumulativeLiquidity?: string
cumulativeRisky?: string
cumulativeStable?: string
liquidity: string
reserveRisky: string
reserveStable: string
}
blockTimestamp?: string
cumulativeLiquidity?: string
cumulativeRisky?: string
cumulativeStable?: string
liquidity: string
reserveRisky: string
reserveStable: string

chainId: string
}
}
32 changes: 28 additions & 4 deletions src/entities/pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,18 +186,42 @@ export class Pool extends Calibration {
*
* @beta
*/
public static from(pool: PoolInterface, referencePrice?: number, chainId: number = 1): Pool {
const { factory, risky, stable, calibration, reserve, invariant } = pool.properties
public static from(pool: PoolInterface, referencePrice?: number): Pool {
const {
factory,
riskyName,
riskySymbol,
riskyDecimals,
riskyAddress,
stableName,
stableSymbol,
stableDecimals,
stableAddress,
strike,
sigma,
gamma,
maturity,
lastTimestamp,
reserveRisky,
reserveStable,
liquidity,
invariant,
chainId
} = pool.properties

const risky = { address: riskyAddress, name: riskyName, symbol: riskySymbol, decimals: riskyDecimals }
const stable = { address: stableAddress, name: stableName, symbol: stableSymbol, decimals: stableDecimals }
const calibration = { strike, sigma, maturity, lastTimestamp, gamma }
const reserve = { reserveRisky, reserveStable, liquidity }
return new Pool(
chainId,
+chainId,
factory,
{ ...risky },
{ ...stable },
{ ...calibration },
{ ...reserve },
invariant,
referencePrice ?? undefined
referencePrice
)
}

Expand Down
56 changes: 31 additions & 25 deletions test/Pool.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Pool, PoolSides } from '../src/entities/pool'

import { usePool } from './shared/fixture'
import { AddressOne, EMPTY_CALIBRATION } from './shared'
import { PoolInterface } from 'src'

describe('Test pool', function() {
let pool: Pool
Expand All @@ -30,31 +31,36 @@ describe('Test pool', function() {
liquidity: parseWei(1, 18).toString()
}
const invariant = '3.345867008995041e+21'
const pool = Pool.from(
{
name: 'Pool',
image: '',
license: '',
creator: '',
description: 'Regular pool',
properties: {
factory: AddressOne,
risky: { ...token0 },
stable: { ...token1 },
invariant: invariant,
calibration: {
strike: strike.toString(),
sigma: sigma.toString(),
maturity: maturity.toString(),
gamma: gamma.toString(),
lastTimestamp: lastTimestamp.toString()
},
reserve: { ...reserve }
}
},
spot.float,
token0.chainId
)
const uri: PoolInterface = {
name: 'Pool',
image: '',
license: '',
creator: '',
description: 'Regular pool',
properties: {
chainId: '1',
factory: AddressOne,
riskyName: token0.name,
riskyAddress: token0.address,
riskySymbol: token0.symbol,
riskyDecimals: token0.decimals,
stableName: token1.name,
stableDecimals: token1.decimals,
stableSymbol: token1.symbol,
stableAddress: token1.address,
strike: strike.toString(),
sigma: sigma.toString(),
maturity: maturity.toString(),
gamma: gamma.toString(),
lastTimestamp: lastTimestamp.toString(),
reserveRisky: reserve.reserveRisky,
reserveStable: reserve.reserveStable,
liquidity: reserve.liquidity,
invariant: invariant
}
}

const pool = Pool.from(uri, spot.float)
expect(pool.poolId).toBeDefined()
})

Expand Down
160 changes: 85 additions & 75 deletions test/shared/fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Swaps } from '../../src/entities/swaps'
import { parseCalibration } from '../../src/utils/parseCalibration'

import { EMPTY_CALIBRATION } from './constants'
import { PoolInterface } from 'src'

export function usePoolWithDecimals(decimals: number): Pool {
const token0 = new Token(1, AddressZero, decimals)
Expand All @@ -28,31 +29,34 @@ export function usePoolWithDecimals(decimals: number): Pool {
reserveStable: stable ? parseWei(stable, token1.decimals).toString() : '0',
liquidity: parseWei(1, 18).toString()
}
const pool = Pool.from(
{
name: 'Pool',
image: '',
license: '',
creator: '',
description: 'Regular pool',
properties: {
factory: AddressZero,
risky: { ...token0 },
stable: { ...token1 },
invariant: '0',
calibration: {
strike: strike.toString(),
sigma: sigma.toString(),
maturity: maturity.toString(),
gamma: gamma.toString(),
lastTimestamp: lastTimestamp.toString()
},
reserve
}
},
spot.float,
token0.chainId
)
const uri: PoolInterface = {
name: 'Pool',
image: '',
license: '',
creator: '',
description: 'Regular pool',
properties: {
chainId: '1',
factory: AddressZero,
riskyName: token0.name,
riskyAddress: token0.address,
riskySymbol: token0.symbol,
riskyDecimals: token0.decimals,
stableName: token1.name,
stableDecimals: token1.decimals,
stableSymbol: token1.symbol,
stableAddress: token1.address,
strike: strike.toString(),
sigma: sigma.toString(),
maturity: maturity.toString(),
gamma: gamma.toString(),
lastTimestamp: lastTimestamp.toString(),
reserveRisky: reserve.reserveRisky,
reserveStable: reserve.reserveStable,
liquidity: reserve.liquidity
}
}
const pool = Pool.from(uri, spot.float)
return pool
}

Expand All @@ -71,31 +75,34 @@ export function usePool(): Pool {
reserveStable: stable ? parseWei(stable, token1.decimals).toString() : '0',
liquidity: parseWei(1, 18).toString()
}
const pool = Pool.from(
{
name: 'Pool',
image: '',
license: '',
creator: '',
description: 'Regular pool',
properties: {
factory: AddressZero,
risky: { ...token0 },
stable: { ...token1 },
invariant: '0',
calibration: {
strike: strike.toString(),
sigma: sigma.toString(),
maturity: maturity.toString(),
gamma: gamma.toString(),
lastTimestamp: lastTimestamp.toString()
},
reserve: { ...reserve }
}
},
spot.float,
token0.chainId
)
const uri: PoolInterface = {
name: 'Pool',
image: '',
license: '',
creator: '',
description: 'Regular pool',
properties: {
chainId: '1',
factory: AddressZero,
riskyName: token0.name,
riskyAddress: token0.address,
riskySymbol: token0.symbol,
riskyDecimals: token0.decimals,
stableName: token1.name,
stableDecimals: token1.decimals,
stableSymbol: token1.symbol,
stableAddress: token1.address,
strike: strike.toString(),
sigma: sigma.toString(),
maturity: maturity.toString(),
gamma: gamma.toString(),
lastTimestamp: lastTimestamp.toString(),
reserveRisky: reserve.reserveRisky,
reserveStable: reserve.reserveStable,
liquidity: reserve.liquidity
}
}
const pool = Pool.from(uri, spot.float)
return pool
}

Expand All @@ -119,30 +126,33 @@ export function useWethPool(): Pool {
reserveStable: stable ? parseWei(stable, token1.decimals).toString() : '0',
liquidity: parseWei(1, 18).toString()
}
const pool = Pool.from(
{
name: 'Pool',
image: '',
license: '',
creator: '',
description: 'Regular pool',
properties: {
factory: AddressZero,
risky: { ...token0 },
stable: { ...token1 },
invariant: '0',
calibration: {
strike: strike.toString(),
sigma: sigma.toString(),
maturity: maturity.toString(),
gamma: gamma.toString(),
lastTimestamp: lastTimestamp.toString()
},
reserve
}
},
spot.float,
token0.chainId
)
const uri: PoolInterface = {
name: 'Pool',
image: '',
license: '',
creator: '',
description: 'Regular pool',
properties: {
chainId: '1',
factory: AddressZero,
riskyName: token0.name,
riskyAddress: token0.address,
riskySymbol: token0.symbol,
riskyDecimals: token0.decimals,
stableName: token1.name,
stableDecimals: token1.decimals,
stableSymbol: token1.symbol,
stableAddress: token1.address,
strike: strike.toString(),
sigma: sigma.toString(),
maturity: maturity.toString(),
gamma: gamma.toString(),
lastTimestamp: lastTimestamp.toString(),
reserveRisky: reserve.reserveRisky,
reserveStable: reserve.reserveStable,
liquidity: reserve.liquidity
}
}
const pool = Pool.from(uri, spot.float)
return pool
}

0 comments on commit f280769

Please sign in to comment.