-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: slippage calculations and validations
- Loading branch information
Showing
6 changed files
with
122 additions
and
39 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
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,25 @@ | ||
/** | ||
* Calculates the maximum value considering the slippage percentage. | ||
* | ||
* @param {number} maxValue - The original maximum value before slippage adjustment. | ||
* @param {number} slippage - The slippage rate as a whole percentage (not decimal). i.e. if your slippage is 0.3%, pass in 0.3. | ||
* This value will be divided by 100 internally to calculate the slippage percentage. | ||
* @returns {number} The maximum value adjusted for slippage. | ||
*/ | ||
export function calculateMaxWithSlippage(maxValue: number, slippage: number) { | ||
const slippagePercent = slippage / 100; | ||
return maxValue * (1 + slippagePercent); | ||
} | ||
|
||
/** | ||
* Calculates the minimum value considering the slippage percentage. | ||
* | ||
* @param {number} minValue - The original minimum value before slippage adjustment. | ||
* @param {number} slippage - The slippage rate as a whole percentage (not decimal). i.e. if your slippage is 0.3%, pass in 0.3. | ||
* This value will be divided by 100 internally to calculate the slippage percentage. | ||
* @returns {number} The minimum value adjusted for slippage. | ||
*/ | ||
export function calculateMinWithSlippage(minValue: number, slippage: number) { | ||
const slippagePercent = slippage / 100; | ||
return minValue * (1 - slippagePercent); | ||
} |
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