-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: move validateBurnedAmount into its own folder
- Loading branch information
1 parent
e071a75
commit 7502549
Showing
10 changed files
with
137 additions
and
94 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
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
16 changes: 8 additions & 8 deletions
16
src/utils/validateEvmBurnedAmount.test.ts → ...nedAmount/validateEvmBurnedAmount.test.ts
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,46 @@ | ||
import type { UnsignedTx } from '../../vms/common'; | ||
import { isImportExportTx as isEvmImportExportTx } from '../../serializable/evm'; | ||
import { costCorethTx } from '../costs'; | ||
|
||
/** | ||
* Validate burned amount for c-chain transactions | ||
* | ||
* @param unsignedTx: unsigned transaction | ||
* @param burnedAmount: burned amount in nAVAX | ||
* @param baseFee: fetched from the network and converted into nAvax (https://docs.avax.network/quickstart/transaction-fees#c-chain-fees) | ||
* @param feeTolerance: tolerance percentage range where the burned amount is considered valid. e.g.: with FeeTolerance = 20% -> (expectedFee <= burnedAmount <= expectedFee * 1.2) | ||
* @return {boolean} isValid: : true if the burned amount is valid, false otherwise. | ||
* @return {bigint} txFee: burned amount in nAVAX | ||
*/ | ||
export const validateEvmBurnedAmount = ({ | ||
unsignedTx, | ||
burnedAmount, | ||
baseFee, | ||
feeTolerance, | ||
}: { | ||
unsignedTx: UnsignedTx; | ||
burnedAmount: bigint; | ||
baseFee: bigint; | ||
feeTolerance: number; | ||
}): { isValid: boolean; txFee: bigint } => { | ||
const tx = unsignedTx.getTx(); | ||
|
||
if (!isEvmImportExportTx(tx)) { | ||
throw new Error(`tx type is not supported`); | ||
} | ||
|
||
const feeToleranceInt = Math.floor(feeTolerance); | ||
|
||
if (feeToleranceInt < 1 || feeToleranceInt > 100) { | ||
throw new Error('feeTolerance must be [1,100]'); | ||
} | ||
|
||
const feeAmount = baseFee * costCorethTx(unsignedTx); | ||
const min = (feeAmount * (100n - BigInt(feeToleranceInt))) / 100n; | ||
const max = (feeAmount * (100n + BigInt(feeToleranceInt))) / 100n; | ||
|
||
return { | ||
isValid: burnedAmount >= min && burnedAmount <= max, | ||
txFee: burnedAmount, | ||
}; | ||
}; |
This file was deleted.
Oops, something went wrong.
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,6 +1,7 @@ | ||
export * from './builder'; | ||
export * from './models'; | ||
export * from './api'; | ||
export { calculateFee } from './txs/fee/calculator'; | ||
|
||
// Exposed Etna builder functions under `e` namespace | ||
export * as e from './etna-builder'; |