This repository has been archived by the owner on Apr 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Feat: Add fixFactory Signed-off-by: Stanislaw Mazowiecki <[email protected]> --------- Signed-off-by: Stanislaw Mazowiecki <[email protected]>
- Loading branch information
1 parent
8f9a4ad
commit 07353d2
Showing
15 changed files
with
437 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { FixedFeeType, RoyaltyFeeType } from './types/fees'; | ||
import { createFixedFeeFunction } from './functions/createFixedFeeFunction'; | ||
import { CustomFixedFee, CustomRoyaltyFee } from '@hashgraph/sdk'; | ||
import { createRoyaltyFeeFunction } from './functions/createRoyaltyFeeFunction'; | ||
|
||
export class FeeFactory { | ||
fixedFee({ | ||
collectorAccountId, | ||
hbarAmount, | ||
amount, | ||
denominatingTokenId, | ||
allCollectorsAreExempt, | ||
}: FixedFeeType): CustomFixedFee { | ||
return createFixedFeeFunction({ | ||
collectorAccountId, | ||
hbarAmount, | ||
amount, | ||
denominatingTokenId, | ||
allCollectorsAreExempt, | ||
}); | ||
} | ||
|
||
royaltyFee({ | ||
collectorAccountId, | ||
numerator, | ||
denominator, | ||
fallbackFee, | ||
allCollectorsAreExempt, | ||
}: RoyaltyFeeType): CustomRoyaltyFee { | ||
return createRoyaltyFeeFunction({ | ||
collectorAccountId, | ||
numerator, | ||
denominator, | ||
fallbackFee, | ||
allCollectorsAreExempt, | ||
}); | ||
} | ||
} |
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,32 @@ | ||
import { FixedFeeType } from '../types/fees'; | ||
import { CustomFixedFee, Hbar } from '@hashgraph/sdk'; | ||
import { validatePropsForFixedFeeFunction } from '../utils/validateProps'; | ||
|
||
export const createFixedFeeFunction = ({ | ||
collectorAccountId, | ||
hbarAmount, | ||
amount, | ||
denominatingTokenId, | ||
allCollectorsAreExempt, | ||
}: FixedFeeType): CustomFixedFee => { | ||
validatePropsForFixedFeeFunction({ collectorAccountId, hbarAmount, amount, denominatingTokenId }); | ||
const fixedFee = new CustomFixedFee().setFeeCollectorAccountId(collectorAccountId); | ||
|
||
if (hbarAmount) { | ||
fixedFee.setHbarAmount(Hbar.fromString(hbarAmount.toString())); | ||
} | ||
|
||
if (amount) { | ||
fixedFee.setAmount(amount); | ||
} | ||
|
||
if (denominatingTokenId) { | ||
fixedFee.setDenominatingTokenId(denominatingTokenId); | ||
} | ||
|
||
if (allCollectorsAreExempt) { | ||
fixedFee.setAllCollectorsAreExempt(allCollectorsAreExempt); | ||
} | ||
|
||
return fixedFee; | ||
}; |
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,37 @@ | ||
import { CustomRoyaltyFee } from '@hashgraph/sdk'; | ||
import { RoyaltyFeeType } from '../types/fees'; | ||
import { createFixedFeeFunction } from './createFixedFeeFunction'; | ||
import { validatePropsForRoyaltyFeeFunction } from '../utils/validateProps'; | ||
|
||
export const createRoyaltyFeeFunction = ({ | ||
collectorAccountId, | ||
numerator, | ||
denominator, | ||
fallbackFee, | ||
allCollectorsAreExempt, | ||
}: RoyaltyFeeType) => { | ||
validatePropsForRoyaltyFeeFunction({ collectorAccountId, numerator, denominator }); | ||
|
||
const royaltyFee = new CustomRoyaltyFee() | ||
.setFeeCollectorAccountId(collectorAccountId) | ||
.setNumerator(numerator) | ||
.setDenominator(denominator); | ||
|
||
if (allCollectorsAreExempt) { | ||
royaltyFee.setAllCollectorsAreExempt(allCollectorsAreExempt); | ||
} | ||
|
||
if (fallbackFee) { | ||
royaltyFee.setFallbackFee( | ||
createFixedFeeFunction({ | ||
collectorAccountId: fallbackFee.collectorAccountId, | ||
hbarAmount: fallbackFee.hbarAmount, | ||
amount: fallbackFee.amount, | ||
denominatingTokenId: fallbackFee.denominatingTokenId, | ||
allCollectorsAreExempt: fallbackFee.allCollectorsAreExempt, | ||
}) | ||
); | ||
} | ||
|
||
return royaltyFee; | ||
}; |
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,15 @@ | ||
export type FixedFeeType = { | ||
collectorAccountId: string; | ||
hbarAmount?: number; | ||
amount?: number; | ||
denominatingTokenId?: string; | ||
allCollectorsAreExempt?: boolean; | ||
}; | ||
|
||
export type RoyaltyFeeType = { | ||
collectorAccountId: string; | ||
numerator: number; | ||
denominator: number; | ||
fallbackFee?: FixedFeeType; | ||
allCollectorsAreExempt?: boolean; | ||
}; |
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.