Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ This block is responsible for adding configurations on calculating the amount of

<table><thead><tr><th width="208">Block Property</th><th>Definition</th><th>Example Input</th><th>Status</th></tr></thead><tbody><tr><td>tag</td><td>Unique name for the logic block.</td><td><strong>mintDocumentBlock</strong></td><td></td></tr><tr><td>permissions</td><td>Which entity has rights to interact at this part of the workflow.</td><td>VVB</td><td></td></tr><tr><td>defaultActive</td><td>Shows whether this block is active at this time and whether it needs to be shown.</td><td>Checked or unchecked.</td><td></td></tr><tr><td>On errors</td><td>Called if the system error has occurs in the Block</td><td><ul><li>No action</li><li>Retry</li><li>Go to step</li><li>Go to tag</li></ul></td><td></td></tr><tr><td>Stop Propagation</td><td>End processing here, don't pass control to the next block.</td><td>Checked or unchecked.</td><td></td></tr></tbody></table>

### Additional Properties

<table><thead><tr><th width="208">Block Property</th><th>Definition</th><th>Example Input</th><th>Status</th></tr></thead><tbody><tr><td>Round Method</td><td>The method used to round the number of tokens.</td><td>
Select an option from the dropdown ('Round to nearest' is selected by default):<ul><li>Round up</li><li>Round down</li><li>Round to nearest</li></ul></td><td></td></tr><tr></tbody></table>

### UI Properties

| UI Property | Definition | Example Input |
Expand Down
25 changes: 23 additions & 2 deletions policy-service/src/policy-engine/blocks/mint-block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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: [
Expand Down Expand Up @@ -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);
Expand Down
25 changes: 23 additions & 2 deletions policy-service/src/policy-engine/blocks/retirement-block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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: [
Expand Down Expand Up @@ -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);
Expand Down
16 changes: 14 additions & 2 deletions policy-service/src/policy-engine/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down