-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Calculating max swap/liquidity (#1306)
* calc max * more max checks * fix description
- Loading branch information
Showing
2 changed files
with
93 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import Decimal from 'decimal.js' | ||
import { Pool } from '..' | ||
|
||
export function calcMaxExactOut(balance: string): Decimal { | ||
return new Decimal(balance).div(3.01) | ||
} | ||
|
||
export function calcMaxExactIn(balance: string): Decimal { | ||
return new Decimal(balance).div(2.01) | ||
} | ||
export async function getMaxSwapExactOut( | ||
poolInstance: Pool, | ||
poolAddress: string, | ||
tokenAddress: string | ||
): Promise<Decimal> { | ||
const reserve = await poolInstance.getReserve(poolAddress, tokenAddress) | ||
return calcMaxExactOut(reserve) | ||
} | ||
|
||
export async function getMaxSwapExactIn( | ||
poolInstance: Pool, | ||
poolAddress: string, | ||
tokenAddress: string | ||
): Promise<Decimal> { | ||
const reserve = await poolInstance.getReserve(poolAddress, tokenAddress) | ||
return calcMaxExactIn(reserve) | ||
} | ||
|
||
export async function getMaxAddLiquidity( | ||
poolInstance: Pool, | ||
poolAddress: string, | ||
tokenAddress: string | ||
): Promise<Decimal> { | ||
const reserve = await poolInstance.getReserve(poolAddress, tokenAddress) | ||
|
||
return calcMaxExactIn(reserve) | ||
} | ||
|
||
export async function getMaxRemoveLiquidity( | ||
poolInstance: Pool, | ||
poolAddress: string, | ||
tokenAddress: string | ||
): Promise<Decimal> { | ||
const reserve = await poolInstance.getReserve(poolAddress, tokenAddress) | ||
|
||
return calcMaxExactIn(reserve) | ||
} |