Skip to content

Commit

Permalink
Merge pull request #292 from invariant-labs/update-fee-tiers
Browse files Browse the repository at this point in the history
Update fee tiers
  • Loading branch information
wojciech-cichocki authored Oct 29, 2023
2 parents be3aad5 + 379737f commit d800f25
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 14 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

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

4 changes: 2 additions & 2 deletions sdk/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 sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@invariant-labs/sdk",
"version": "0.9.57",
"version": "0.9.58",
"description": "",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
23 changes: 14 additions & 9 deletions sdk/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ export const arithmeticalAvg = <T extends BN>(...args: T[]): T => {
return sum.divn(args.length) as T
}

export const weightedArithmeticAvg = <T extends BN>(...args: { val: T, weight: BN }[]): T => {
export const weightedArithmeticAvg = <T extends BN>(...args: { val: T; weight: BN }[]): T => {
if (args.length === 0) {
throw new Error('requires at least one argument')
}
Expand Down Expand Up @@ -283,8 +283,10 @@ export const feeToTickSpacing = (fee: BN): number => {
}

export const FEE_TIERS: FeeTier[] = [
{ fee: fromFee(new BN(1)) },
{ fee: fromFee(new BN(10)) },
{ fee: fromFee(new BN(1)), tickSpacing: 1 },
{ fee: fromFee(new BN(3)), tickSpacing: 1 },
{ fee: fromFee(new BN(5)), tickSpacing: 1 },
{ fee: fromFee(new BN(10)), tickSpacing: 1 },
{ fee: fromFee(new BN(50)) },
{ fee: fromFee(new BN(100)) },
{ fee: fromFee(new BN(300)) },
Expand Down Expand Up @@ -1126,16 +1128,19 @@ export const poolAPY = (params: ApyPoolParams): WeeklyData => {
let dailyTokens: BN = new BN(0)
let dailyVolumeX: number = 0
try {
const { tickLower, tickUpper, tokens: avgTokensFromRange } = calculateTokensRange(
ticksPreviousSnapshot,
ticksCurrentSnapshot,
currentTickIndex
)
const {
tickLower,
tickUpper,
tokens: avgTokensFromRange
} = calculateTokensRange(ticksPreviousSnapshot, ticksCurrentSnapshot, currentTickIndex)

const previousSqrtPrice = calculatePriceSqrt(tickLower)
const currentSqrtPrice = calculatePriceSqrt(tickUpper)
const volume = getVolume(volumeX, volumeY, previousSqrtPrice, currentSqrtPrice)
const tokenAvgFactor = weightedArithmeticAvg({ val: activeTokens, weight: new BN(9) }, { val: avgTokensFromRange, weight: new BN(1) })
const tokenAvgFactor = weightedArithmeticAvg(
{ val: activeTokens, weight: new BN(9) },
{ val: avgTokensFromRange, weight: new BN(1) }
)
dailyFactor = dailyFactorPool(tokenAvgFactor, volume, feeTier)
dailyRange = { tickLower, tickUpper }
dailyTokens = tokenAvgFactor
Expand Down
2 changes: 1 addition & 1 deletion tests/math.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2052,7 +2052,7 @@ describe('Math', () => {
it('case 1', async () => {
const volume = 125000
const tokenXamount = new BN(1000000)
const feeTier = FEE_TIERS[4] // 0.3%
const feeTier = FEE_TIERS[6] // 0.3%

const result = dailyFactorPool(tokenXamount, volume, feeTier)
assert.equal(result, 0.00037125)
Expand Down

1 comment on commit d800f25

@vercel
Copy link

@vercel vercel bot commented on d800f25 Oct 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.