Skip to content

Commit

Permalink
Merge pull request #53 from invariant-labs/refactor-get-next-sqrt-pri…
Browse files Browse the repository at this point in the history
…ce-from-input/output

add get next sqrt price from input/output tests
  • Loading branch information
zielvna authored Apr 11, 2024
2 parents a4fd3e8 + 57daf5f commit 3e11337
Showing 1 changed file with 146 additions and 0 deletions.
146 changes: 146 additions & 0 deletions test/clamm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1335,4 +1335,150 @@ describe('math tests', () => {
await expectError(clamm.methods.calculateAmountDelta(params))
})
})

describe('next sqrt price from input - domain', () => {
let clamm: CLAMMInstance
let maxLiquidity = MaxU256
let minLiquidity = 1n
let maxAmount = MaxU256
const maxSqrtPrice = 65535383934512647000000000000n
const minSqrtPrice = 15258932000000000000n
const almostMaxSqrtPrice = maxSqrtPrice - 1n
const almostMinSqrtPrice = minSqrtPrice + 1n

beforeEach(async () => {
const uints = await deployUints(sender)
clamm = (await deployCLAMM(sender, uints.contractInstance.contractId)).contractInstance
})

test('max result, increase sqrt_price case', async () => {
// const params = {
// args: {
// startingSqrtPrice: almostMaxSqrtPrice,
// liquidity: maxLiquidity,
// amount: 2n ** 128n + 10n ** 10n,
// xToY: false
// }
// }
// const result = (await clamm.methods.getNextSqrtPriceFromInput(params)).returns
// expect(result).toEqual(65535383934512647000000000001n)
})

test('min result, decrease sqrt_price case', async () => {
// const params = {
// args: {
// startingSqrtPrice: almostMinSqrtPrice,
// liquidity: maxLiquidity,
// amount: 2n ** 128n + 10n ** 20n,
// xToY: true
// }
// }
// const result = (await clamm.methods.getNextSqrtPriceFromInput(params)).returns
// expect(result).toEqual(65535383934512647000000000001n)
})

test('max result, increase sqrt_price case', async () => {
// const params = {
// args: { startingSqrtPrice: almostMaxSqrtPrice, liquidity: maxLiquidity, amount: maxAmount, xToY: true }
// }
// const result = (await clamm.methods.getNextSqrtPriceFromInput(params)).returns
// expect(result).toEqual(15258931999999999995n)
})

test('amount = 0', async () => {
const params = {
args: { startingSqrtPrice: minSqrtPrice, liquidity: maxLiquidity, amount: 0n, xToY: true }
}
const result = (await clamm.methods.getNextSqrtPriceFromInput(params)).returns
expect(result).toEqual(minSqrtPrice)
})

test('liquidity = 0', async () => {
// const params = {
// args: { startingSqrtPrice: minSqrtPrice, liquidity: 0n, amount: 20n, xToY: true }
// }
// const result = (await clamm.methods.getNextSqrtPriceFromInput(params)).returns
// expect(result).toEqual(0n)
})

test('error handling', async () => {
const params = {
args: { startingSqrtPrice: maxSqrtPrice, liquidity: minLiquidity, amount: maxAmount, xToY: false }
}
await expectError(clamm.methods.getNextSqrtPriceFromInput(params))
})
})

describe('next sqrt price from output - domain', () => {
let clamm: CLAMMInstance
let maxLiquidity = MaxU256
let minLiquidity = 1n
let maxAmount = MaxU256
const maxSqrtPrice = 65535383934512647000000000000n
const minSqrtPrice = 15258932000000000000n
const almostMaxSqrtPrice = maxSqrtPrice - 1n
const almostMinSqrtPrice = minSqrtPrice + 1n

beforeEach(async () => {
const uints = await deployUints(sender)
clamm = (await deployCLAMM(sender, uints.contractInstance.contractId)).contractInstance
})

test('max result, increase sqrt_price case', async () => {
// const params = {
// args: {
// startingSqrtPrice: almostMaxSqrtPrice,
// liquidity: maxLiquidity,
// amount: 1n,
// xToY: false
// }
// }
// const result = (await clamm.methods.getNextSqrtPriceFromOutput(params)).returns
// expect(result).toEqual(65535383934512647000000000000n)
})

test('min result, decrease sqrt_price case', async () => {
// const params = {
// args: {
// startingSqrtPrice: almostMinSqrtPrice,
// liquidity: maxLiquidity,
// amount: 1n,
// xToY: true
// }
// }
// const result = (await clamm.methods.getNextSqrtPriceFromOutput(params)).returns
// expect(result).toEqual(15258932000000000000n)
})

test('max result, increase sqrt_price case', async () => {
// const params = {
// args: { startingSqrtPrice: almostMaxSqrtPrice, liquidity: maxLiquidity, amount: maxAmount, xToY: true }
// }
// const result = (await clamm.methods.getNextSqrtPriceFromOutput(params)).returns
// expect(result).toEqual(15258931999999999995n)
})

test('amount = 0', async () => {
// const params = {
// args: { startingSqrtPrice: minSqrtPrice, liquidity: maxLiquidity, amount: 0n, xToY: true }
// }
// const result = (await clamm.methods.getNextSqrtPriceFromOutput(params)).returns
// expect(result).toEqual(minSqrtPrice)
})

test('liquidity = 0', async () => {
// const params = {
// args: { startingSqrtPrice: minSqrtPrice, liquidity: 0n, amount: 20n, xToY: true }
// }
// const result = (await clamm.methods.getNextSqrtPriceFromOutput(params)).returns
// expect(result).toEqual(0n)
})

test('error handling', async () => {
const params = {
args: { startingSqrtPrice: maxSqrtPrice, liquidity: minLiquidity, amount: maxAmount, xToY: false }
}
await expectError(clamm.methods.getNextSqrtPriceFromOutput(params))
})
})
})

0 comments on commit 3e11337

Please sign in to comment.