Skip to content

Commit

Permalink
Merge pull request #115 from clober-dex/fix/get-pool
Browse files Browse the repository at this point in the history
fix: get pool dto
  • Loading branch information
Dorvin authored Oct 1, 2024
2 parents a8b5200 + 0177520 commit acbfc7b
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 40 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@clober/v2-sdk",
"version": "0.0.71",
"version": "0.0.72",
"description": "🛠 An SDK for building applications on top of Clober V2",
"files": [
"dist"
Expand Down
18 changes: 9 additions & 9 deletions src/model/pool.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { formatUnits } from 'viem'

import { Pool as PoolType, CHAIN_IDS, Currency, Market } from '../type'
import { CHAIN_IDS, Currency, Market, Pool as PoolType } from '../type'
import { CONTRACT_ADDRESSES } from '../constants/addresses'
import { toPoolKey } from '../utils/pool-key'

Expand Down Expand Up @@ -124,14 +124,14 @@ export class Pool {
strategy: this.strategy,
currencyA: this.currencyA,
currencyB: this.currencyB,
reserveA: {
liquidityA: {
total: {
currency: this.currencyA,
value: formatUnits(this.reserveA, this.currencyA.decimals),
value: formatUnits(this.liquidityA, this.currencyA.decimals),
},
liquidity: {
reserve: {
currency: this.currencyA,
value: formatUnits(this.liquidityA, this.currencyA.decimals),
value: formatUnits(this.reserveA, this.currencyA.decimals),
},
cancelable: {
currency: this.currencyA,
Expand All @@ -142,14 +142,14 @@ export class Pool {
value: formatUnits(this.claimableA, this.currencyA.decimals),
},
},
reserveB: {
liquidityB: {
total: {
currency: this.currencyB,
value: formatUnits(this.reserveB, this.currencyB.decimals),
value: formatUnits(this.liquidityB, this.currencyB.decimals),
},
liquidity: {
reserve: {
currency: this.currencyB,
value: formatUnits(this.liquidityB, this.currencyB.decimals),
value: formatUnits(this.reserveB, this.currencyB.decimals),
},
cancelable: {
currency: this.currencyB,
Expand Down
8 changes: 4 additions & 4 deletions src/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ export type Pool = {
strategy: `0x${string}`
currencyA: Currency
currencyB: Currency
reserveA: {
liquidityA: {
total: CurrencyAmount
liquidity: CurrencyAmount
reserve: CurrencyAmount
cancelable: CurrencyAmount
claimable: CurrencyAmount
}
reserveB: {
liquidityB: {
total: CurrencyAmount
liquidity: CurrencyAmount
reserve: CurrencyAmount
cancelable: CurrencyAmount
claimable: CurrencyAmount
}
Expand Down
32 changes: 16 additions & 16 deletions test/adjust-order-price.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,25 +139,25 @@ test('Adjust order price', async () => {
})

expect(
BigNumber(poolStep1.reserveA.total.value).plus('2000').toString(),
).toBe(poolStep2.reserveA.total.value)
expect(BigNumber(poolStep1.reserveB.total.value).plus('1').toString()).toBe(
poolStep2.reserveB.total.value,
BigNumber(poolStep1.liquidityA.total.value).plus('2000').toString(),
).toBe(poolStep2.liquidityA.total.value)
expect(BigNumber(poolStep1.liquidityB.total.value).plus('1').toString()).toBe(
poolStep2.liquidityB.total.value,
)
expect(poolStep1.reserveA.cancelable.value).toBe('0')
expect(poolStep1.reserveB.cancelable.value).toBe('0')
expect(poolStep1.reserveA.claimable.value).toBe('0')
expect(poolStep1.reserveB.claimable.value).toBe('0')
expect(poolStep1.liquidityA.cancelable.value).toBe('0')
expect(poolStep1.liquidityB.cancelable.value).toBe('0')
expect(poolStep1.liquidityA.claimable.value).toBe('0')
expect(poolStep1.liquidityB.claimable.value).toBe('0')

expect(poolStep2.reserveA.cancelable.value).toBe('0')
expect(poolStep2.reserveB.cancelable.value).toBe('0')
expect(poolStep2.reserveA.claimable.value).toBe('0')
expect(poolStep2.reserveB.claimable.value).toBe('0')
expect(poolStep2.liquidityA.cancelable.value).toBe('0')
expect(poolStep2.liquidityB.cancelable.value).toBe('0')
expect(poolStep2.liquidityA.claimable.value).toBe('0')
expect(poolStep2.liquidityB.claimable.value).toBe('0')

expect(poolStep3.reserveA.cancelable.value).toBe('99.999999')
expect(poolStep3.reserveB.cancelable.value).toBe('0.0381675463')
expect(poolStep3.reserveA.claimable.value).toBe('0')
expect(poolStep3.reserveB.claimable.value).toBe('0')
expect(poolStep3.liquidityA.cancelable.value).toBe('99.999999')
expect(poolStep3.liquidityB.cancelable.value).toBe('0.0381675463')
expect(poolStep3.liquidityA.claimable.value).toBe('0')
expect(poolStep3.liquidityB.claimable.value).toBe('0')
})

test('Adjust order price with invalid alpha', async () => {
Expand Down
16 changes: 8 additions & 8 deletions test/refill-order.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,13 @@ test('Refill order', async () => {
},
})

expect(poolStep4.reserveA.cancelable.value).toBe('0')
expect(poolStep4.reserveB.cancelable.value).toBe('0.0001559532')
expect(poolStep4.reserveA.claimable.value).toBe('99.997469')
expect(poolStep4.reserveB.claimable.value).toBe('0.038329361063758775')
expect(poolStep4.liquidityA.cancelable.value).toBe('0')
expect(poolStep4.liquidityB.cancelable.value).toBe('0.0001559532')
expect(poolStep4.liquidityA.claimable.value).toBe('99.997469')
expect(poolStep4.liquidityB.claimable.value).toBe('0.038329361063758775')

expect(poolStep5.reserveA.cancelable.value).toBe('99.999872')
expect(poolStep5.reserveB.cancelable.value).toBe('0.0381675463')
expect(poolStep5.reserveA.claimable.value).toBe('0')
expect(poolStep5.reserveB.claimable.value).toBe('0')
expect(poolStep5.liquidityA.cancelable.value).toBe('99.999872')
expect(poolStep5.liquidityB.cancelable.value).toBe('0.0381675463')
expect(poolStep5.liquidityA.claimable.value).toBe('0')
expect(poolStep5.liquidityB.claimable.value).toBe('0')
})

0 comments on commit acbfc7b

Please sign in to comment.