diff --git a/docs/guardian/standard-registry/policies/policy-creation/introduction/mintdocumentblock.md b/docs/guardian/standard-registry/policies/policy-creation/introduction/mintdocumentblock.md
index b526173c18..47adf6f5b1 100644
--- a/docs/guardian/standard-registry/policies/policy-creation/introduction/mintdocumentblock.md
+++ b/docs/guardian/standard-registry/policies/policy-creation/introduction/mintdocumentblock.md
@@ -6,6 +6,11 @@ This block is responsible for adding configurations on calculating the amount of
| Block Property | Definition | Example Input | Status |
|---|
| tag | Unique name for the logic block. | mintDocumentBlock | |
| permissions | Which entity has rights to interact at this part of the workflow. | VVB | |
| defaultActive | Shows whether this block is active at this time and whether it needs to be shown. | Checked or unchecked. | |
| On errors | Called if the system error has occurs in the Block | - No action
- Retry
- Go to step
- Go to tag
| |
| Stop Propagation | End processing here, don't pass control to the next block. | Checked or unchecked. | |
+### Additional Properties
+
+| Block Property | Definition | Example Input | Status |
|---|
| Round Method | The method used to round the number of tokens. |
+Select an option from the dropdown ('Round to nearest' is selected by default):- Round up
- Round down
- Round to nearest
| |
|
+
### UI Properties
| UI Property | Definition | Example Input |
diff --git a/policy-service/src/policy-engine/blocks/mint-block.ts b/policy-service/src/policy-engine/blocks/mint-block.ts
index 444a80d043..c200e652a0 100644
--- a/policy-service/src/policy-engine/blocks/mint-block.ts
+++ b/policy-service/src/policy-engine/blocks/mint-block.ts
@@ -8,7 +8,7 @@ import { HederaDidDocument, MessageAction, MessageMemo, MessageServer, Token as
import { PolicyUtils } from '../helpers/utils.js';
import { AnyBlockType, IPolicyDocument, IPolicyEventState, IPolicyTokenBlock } from '../policy-engine.interface.js';
import { IPolicyEvent, PolicyInputEventType, PolicyOutputEventType } from '../interfaces/index.js';
-import { ChildrenType, ControlType } from '../interfaces/block-about.js';
+import { ChildrenType, ControlType, PropertyType } from '../interfaces/block-about.js';
import { PolicyUser, UserCredentials } from '../policy-user.js';
import { ExternalDocuments, ExternalEvent, ExternalEventType } from '../interfaces/external-event.js';
import { MintService } from '../mint/mint-service.js';
@@ -38,6 +38,27 @@ import { RecordActionStep } from '../record-action-step.js';
PolicyOutputEventType.RefreshEvent,
PolicyOutputEventType.ErrorEvent
],
+ properties: [{
+ name: 'roundMethod',
+ label: 'Round Method',
+ title: 'Round Method',
+ type: PropertyType.Select,
+ items: [
+ {
+ label: 'Round up',
+ value: 'ceil'
+ },
+ {
+ label: 'Round down',
+ value: 'floor'
+ },
+ {
+ label: 'Round to nearest',
+ value: 'round'
+ }
+ ],
+ default: 'round'
+ }],
defaultEvent: true
},
variables: [
@@ -296,7 +317,7 @@ export class MintBlock {
if (Number.isNaN(amount) || !Number.isFinite(amount) || amount < 0) {
throw new BlockActionError(`Invalid token value: ${amount}`, ref.blockType, ref.uuid);
}
- const [tokenValue, tokenAmount] = PolicyUtils.tokenAmount(token, amount);
+ const [tokenValue, tokenAmount] = PolicyUtils.tokenAmount(token, amount, ref.options.roundMethod);
const policyOwnerCred = await PolicyUtils.getUserCredentials(ref, ref.policyOwner, userId);
const policyOwnerDid = await policyOwnerCred.loadDidDocument(ref, userId);
diff --git a/policy-service/src/policy-engine/blocks/retirement-block.ts b/policy-service/src/policy-engine/blocks/retirement-block.ts
index b20406f59b..56730ec67a 100644
--- a/policy-service/src/policy-engine/blocks/retirement-block.ts
+++ b/policy-service/src/policy-engine/blocks/retirement-block.ts
@@ -7,7 +7,7 @@ import { Token as TokenCollection, VcHelper, VcDocumentDefinition as VcDocument,
import { PolicyUtils } from '../helpers/utils.js';
import { AnyBlockType, IPolicyDocument, IPolicyEventState } from '../policy-engine.interface.js';
import { IPolicyEvent, PolicyInputEventType, PolicyOutputEventType } from '../interfaces/index.js';
-import { ChildrenType, ControlType } from '../interfaces/block-about.js';
+import { ChildrenType, ControlType, PropertyType } from '../interfaces/block-about.js';
import { PolicyUser, UserCredentials } from '../policy-user.js';
import { ExternalDocuments, ExternalEvent, ExternalEventType } from '../interfaces/external-event.js';
import { MintService } from '../mint/mint-service.js';
@@ -35,6 +35,27 @@ import { RecordActionStep } from '../record-action-step.js';
PolicyOutputEventType.RefreshEvent,
PolicyOutputEventType.ErrorEvent
],
+ properties: [{
+ name: 'roundMethod',
+ label: 'Round Method',
+ title: 'Round Method',
+ type: PropertyType.Select,
+ items: [
+ {
+ label: 'Round up',
+ value: 'ceil'
+ },
+ {
+ label: 'Round down',
+ value: 'floor'
+ },
+ {
+ label: 'Round to nearest',
+ value: 'round'
+ }
+ ],
+ default: 'round'
+ }],
defaultEvent: true
},
variables: [
@@ -194,7 +215,7 @@ export class RetirementBlock {
throw new Error('For FUNGIBLE tokens, Rule is required');
}
const amount = PolicyUtils.aggregate(ref.options.rule, documents);
- [tokenValue, tokenAmount] = PolicyUtils.tokenAmount(token, amount);
+ [tokenValue, tokenAmount] = PolicyUtils.tokenAmount(token, amount, ref.options.roundMethod);
}
const wipeVC = await this.createWipeVC(policyOwnerDidDocument, token, tokenAmount, ref, serialNumbers, actionStatus?.id);
diff --git a/policy-service/src/policy-engine/helpers/utils.ts b/policy-service/src/policy-engine/helpers/utils.ts
index 1f4c4b50d7..13449754fa 100644
--- a/policy-service/src/policy-engine/helpers/utils.ts
+++ b/policy-service/src/policy-engine/helpers/utils.ts
@@ -187,11 +187,23 @@ export class PolicyUtils {
* Token amount
* @param token
* @param amount
+ * @param method
*/
- public static tokenAmount(token: Token, amount: number): [number, string] {
+ public static tokenAmount(token: Token, amount: number, method: string): [number, string] {
const decimals = parseFloat(token.decimals) || 0;
const _decimals = Math.pow(10, decimals);
- const tokenValue = Math.round(amount * _decimals);
+ let tokenValue: number;
+ switch (method) {
+ case 'ceil':
+ tokenValue = Math.ceil(amount * _decimals);
+ break;
+ case 'floor':
+ tokenValue = Math.floor(amount * _decimals);
+ break;
+ case 'round':
+ default:
+ tokenValue = Math.round(amount * _decimals);
+ }
const tokenAmount = (tokenValue / _decimals).toFixed(decimals);
return [tokenValue, tokenAmount];
}