-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new swap contract integration and fixed fee utilities
Also refactored fee resolver to make decision logic which fee to use based on asset correlation
- Loading branch information
1 parent
6149dbe
commit 78856d1
Showing
66 changed files
with
12,702 additions
and
440 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,25 @@ | ||
import { DEFAULT_FEE, FEE_BASE } from '@dma-common/constants' | ||
import BigNumber from 'bignumber.js' | ||
|
||
export function calculateFee(amountWei: BigNumber, fee: number = DEFAULT_FEE): BigNumber { | ||
export function calculatePercentageFee(amountWei: BigNumber, fee: number = DEFAULT_FEE): BigNumber { | ||
return amountWei | ||
.times(fee) | ||
.div(new BigNumber(fee).plus(new BigNumber(FEE_BASE))) | ||
.abs() | ||
.integerValue(BigNumber.ROUND_DOWN) | ||
} | ||
|
||
export function calculateFeeOnInputAmount( | ||
export function calculateFixedFee(amountWei: BigNumber, fee: string): BigNumber { | ||
return amountWei.minus(fee).integerValue(BigNumber.ROUND_DOWN) | ||
} | ||
|
||
export function calculatePercentageFeeOnInputAmount( | ||
amountWei: BigNumber, | ||
fee: number = DEFAULT_FEE, | ||
): BigNumber { | ||
return amountWei.times(fee).div(new BigNumber(FEE_BASE)).abs().integerValue(BigNumber.ROUND_UP) | ||
} | ||
|
||
export function calculateFixedFeeOnInputAmount(amountWei: BigNumber, fee: string): BigNumber { | ||
return amountWei.plus(fee).integerValue(BigNumber.ROUND_UP) | ||
} |
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 |
---|---|---|
@@ -1 +1,6 @@ | ||
export { calculateFee, calculateFeeOnInputAmount } from './calculate-fee' | ||
export { | ||
calculateFixedFee, | ||
calculateFixedFeeOnInputAmount, | ||
calculatePercentageFee, | ||
calculatePercentageFeeOnInputAmount, | ||
} from './calculate-fee' |
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
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
Oops, something went wrong.