Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add get next sqrt price from input/output tests #53

Merged
merged 4 commits into from
Apr 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
})
})
})
Loading