mirror of
https://github.com/luxfi/uni-v4-subgraph.git
synced 2026-10-30 15:14:12 +00:00
* v4 init * remove unused lines * fix lint errors * fix(lint): auto-fix [ci] * more cleanup * fix(lint): auto-fix [ci] * more clean * fix(lint): auto-fix [ci] * save hooks * remove unsed code * fix(lint): auto-fix [ci] * fix liq amount bug * chore: add pre-commit lint checks * address comments * clean * set roundup flag true for amounts * lint * address comments * fix lint --------- Co-authored-by: matteenm <[email protected]>
71 lines
3.3 KiB
TypeScript
71 lines
3.3 KiB
TypeScript
import { BigInt } from '@graphprotocol/graph-ts'
|
|
import { assert, describe, test } from 'matchstick-as/assembly/index'
|
|
|
|
import { SqrtPriceMath } from '../../../src/utils/liquidityMath/sqrtPriceMath'
|
|
|
|
describe('SqrtPriceMath', () => {
|
|
describe('getAmount0Delta', () => {
|
|
test('calculates amount0 correctly when sqrtRatioAX96 < sqrtRatioBX96', () => {
|
|
const sqrtRatioAX96 = BigInt.fromString('1000000000000000000') // 1e18
|
|
const sqrtRatioBX96 = BigInt.fromString('1500000000000000000') // 1.5e18
|
|
const liquidity = BigInt.fromString('1000000000000000000') // 1e18
|
|
const roundUp = false
|
|
|
|
const result = SqrtPriceMath.getAmount0Delta(sqrtRatioAX96, sqrtRatioBX96, liquidity, roundUp)
|
|
assert.bigIntEquals(result, BigInt.fromString('26409387504754779197847983445'))
|
|
})
|
|
|
|
test('calculates amount0 correctly when sqrtRatioAX96 > sqrtRatioBX96', () => {
|
|
const sqrtRatioAX96 = BigInt.fromString('1500000000000000000') // 1.5e18
|
|
const sqrtRatioBX96 = BigInt.fromString('1000000000000000000') // 1e18
|
|
const liquidity = BigInt.fromString('1000000000000000000') // 1e18
|
|
const roundUp = false
|
|
|
|
const result = SqrtPriceMath.getAmount0Delta(sqrtRatioAX96, sqrtRatioBX96, liquidity, roundUp)
|
|
assert.bigIntEquals(result, BigInt.fromString('26409387504754779197847983445'))
|
|
})
|
|
|
|
test('rounds up when specified', () => {
|
|
const sqrtRatioAX96 = BigInt.fromString('1000000000000000000') // 1e18
|
|
const sqrtRatioBX96 = BigInt.fromString('1500000000000000000') // 1.5e18
|
|
const liquidity = BigInt.fromString('1000000000000000000') // 1e18
|
|
const roundUp = true
|
|
|
|
const result = SqrtPriceMath.getAmount0Delta(sqrtRatioAX96, sqrtRatioBX96, liquidity, roundUp)
|
|
assert.bigIntEquals(result, BigInt.fromString('26409387504754779197847983446'))
|
|
})
|
|
})
|
|
|
|
describe('getAmount1Delta', () => {
|
|
test('calculates amount1 correctly when sqrtRatioAX96 < sqrtRatioBX96', () => {
|
|
const sqrtRatioAX96 = BigInt.fromString('1000000000000000000') // 1e18
|
|
const sqrtRatioBX96 = BigInt.fromString('1500000000000000000') // 1.5e18
|
|
const liquidity = BigInt.fromString('1000000000000000000') // 1e18
|
|
const roundUp = false
|
|
|
|
const result = SqrtPriceMath.getAmount1Delta(sqrtRatioAX96, sqrtRatioBX96, liquidity, roundUp)
|
|
assert.bigIntEquals(result, BigInt.fromString('6310887'))
|
|
})
|
|
|
|
test('calculates amount1 correctly when sqrtRatioAX96 > sqrtRatioBX96', () => {
|
|
const sqrtRatioAX96 = BigInt.fromString('1500000000000000000') // 1.5e18
|
|
const sqrtRatioBX96 = BigInt.fromString('1000000000000000000') // 1e18
|
|
const liquidity = BigInt.fromString('1000000000000000000') // 1e18
|
|
const roundUp = false
|
|
|
|
const result = SqrtPriceMath.getAmount1Delta(sqrtRatioAX96, sqrtRatioBX96, liquidity, roundUp)
|
|
assert.bigIntEquals(result, BigInt.fromString('6310887'))
|
|
})
|
|
|
|
test('rounds up when specified', () => {
|
|
const sqrtRatioAX96 = BigInt.fromString('1000000000000000000') // 1e18
|
|
const sqrtRatioBX96 = BigInt.fromString('1500000000000000000') // 1.5e18
|
|
const liquidity = BigInt.fromString('1000000000000000000') // 1e18
|
|
const roundUp = true
|
|
|
|
const result = SqrtPriceMath.getAmount1Delta(sqrtRatioAX96, sqrtRatioBX96, liquidity, roundUp)
|
|
assert.bigIntEquals(result, BigInt.fromString('6310888'))
|
|
})
|
|
})
|
|
})
|