Skip to content

Commit db72d96

Browse files
AlbertoMolinaIoBuildersluigi-io
authored andcommitted
Bug/bbnd 1127 coupon rate decimals (#642)
Signed-off-by: Alberto Molina <[email protected]> Signed-off-by: Luigi Navarro <[email protected]> Co-authored-by: Luigi Navarro <[email protected]> Signed-off-by: Mario Francia <[email protected]>
1 parent 12c248c commit db72d96

File tree

24 files changed

+92
-19
lines changed

24 files changed

+92
-19
lines changed

apps/ats/web/src/utils/format.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ import _capitalize from 'lodash/capitalize';
207207
import _formatDate from 'date-fns/format';
208208
import { TimeUnit } from './types';
209209
import i18n from '../i18n';
210-
import { LOCALE } from './constants';
210+
import { LOCALE, TIME_PERIODS_S } from './constants';
211211

212212
export const formatAddressAccount = (address: string) => `${_capitalize(
213213
address.slice(0, 2),
@@ -296,8 +296,6 @@ export const formatPeriod = ({
296296
* Formats a period in seconds to human-readable format
297297
*/
298298
export const formatCouponPeriod = (periodInSeconds: number): string => {
299-
const { TIME_PERIODS_S } = require('./constants');
300-
301299
if (periodInSeconds >= TIME_PERIODS_S.YEAR) {
302300
const years = Math.floor(periodInSeconds / TIME_PERIODS_S.YEAR);
303301
return `${years} ${years === 1 ? 'Year' : 'Years'}`;

apps/ats/web/src/utils/rules.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ import isBefore from 'date-fns/isBefore';
208208
import isToday from 'date-fns/isToday';
209209
import isEqual from 'date-fns/isEqual';
210210
import i18n from '../i18n';
211-
import { formatDate, toDate } from './format';
211+
import { formatDate, toDate, validateCouponPeriod } from './format';
212212

213213
const t = (key: string, options?: Record<string, unknown>) => {
214214
return i18n.t(`rules:${key}`, options);
@@ -334,7 +334,6 @@ export const isValidCouponPeriod = (val: string) => {
334334
return 'Coupon period must be a valid positive number';
335335
}
336336

337-
const { validateCouponPeriod } = require('./format');
338337
const validation = validateCouponPeriod(periodValue);
339338
return validation === true || validation;
340339
} catch (error) {

apps/ats/web/src/views/DigitalSecurityDetails/Components/Coupons/CouponsList.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@ import { useParams } from 'react-router-dom';
77
import { createColumnHelper } from '@tanstack/table-core';
88
import { Table, Text } from 'io-bricks-ui';
99
import { useTranslation } from 'react-i18next';
10-
import { COUPONS_FACTOR, DATE_TIME_FORMAT } from '../../../../utils/constants';
11-
import { formatDate, formatCouponPeriod } from '../../../../utils/format';
10+
import { DATE_TIME_FORMAT } from '../../../../utils/constants';
11+
import {
12+
formatDate,
13+
formatCouponPeriod,
14+
formatNumberLocale,
15+
} from '../../../../utils/format';
1216

1317
export const CouponsList = () => {
1418
const { id } = useParams();
@@ -46,7 +50,8 @@ export const CouponsList = () => {
4650
}),
4751
columnHelper.accessor('rate', {
4852
header: t('columns.rate'),
49-
cell: (row) => `${parseInt(row.getValue()) / COUPONS_FACTOR}%`,
53+
cell: (row) =>
54+
`${formatNumberLocale(row.getValue(), row.row.original.rateDecimals ?? 0)}%`,
5055
enableSorting: false,
5156
}),
5257
columnHelper.accessor('period', {

apps/ats/web/src/views/DigitalSecurityDetails/Components/Coupons/ProgramCoupon.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -227,11 +227,7 @@ import {
227227
dateToUnixTimestamp,
228228
validateCouponPeriod,
229229
} from '../../../../utils/format';
230-
import {
231-
COUPONS_FACTOR,
232-
DATE_TIME_FORMAT,
233-
TIME_PERIODS_S,
234-
} from '../../../../utils/constants';
230+
import { DATE_TIME_FORMAT, TIME_PERIODS_S } from '../../../../utils/constants';
235231
import { isBeforeDate } from '../../../../utils/helpers';
236232

237233
interface ProgramCouponFormValues {
@@ -263,7 +259,7 @@ export const ProgramCoupon = () => {
263259
const submit: SubmitHandler<ProgramCouponFormValues> = (params) => {
264260
const request = new SetCouponRequest({
265261
securityId: id ?? '',
266-
rate: (params.rate * COUPONS_FACTOR).toString(),
262+
rate: params.rate.toString(),
267263
recordTimestamp: dateToUnixTimestamp(params.recordTimestamp),
268264
executionTimestamp: dateToUnixTimestamp(params.executionTimestamp),
269265
period: params.period,

packages/ats/contracts/contracts/factory/ERC3643/interfaces/IBondRead.sol

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ interface TRexIBondRead {
218218
uint256 recordDate;
219219
uint256 executionDate;
220220
uint256 rate;
221+
uint8 rateDecimals;
221222
uint256 period;
222223
}
223224

@@ -229,6 +230,7 @@ interface TRexIBondRead {
229230
struct CouponFor {
230231
uint256 tokenBalance;
231232
uint256 rate;
233+
uint8 rateDecimals;
232234
uint256 recordDate;
233235
uint256 executionDate;
234236
uint256 period;

packages/ats/contracts/contracts/layer_0/bond/BondStorageWrapper.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ abstract contract BondStorageWrapper is
314314
);
315315

316316
couponFor_.rate = registeredCoupon.coupon.rate;
317+
couponFor_.rateDecimals = registeredCoupon.coupon.rateDecimals;
317318
couponFor_.recordDate = registeredCoupon.coupon.recordDate;
318319
couponFor_.executionDate = registeredCoupon.coupon.executionDate;
319320
couponFor_.period = registeredCoupon.coupon.period;

packages/ats/contracts/contracts/layer_2/bond/Bond.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ abstract contract Bond is IBond, Common {
265265
_newCoupon.recordDate,
266266
_newCoupon.executionDate,
267267
_newCoupon.rate,
268+
_newCoupon.rateDecimals,
268269
_newCoupon.period
269270
);
270271
}

packages/ats/contracts/contracts/layer_2/interfaces/bond/IBondRead.sol

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ interface IBondRead {
218218
uint256 recordDate;
219219
uint256 executionDate;
220220
uint256 rate;
221+
uint8 rateDecimals;
221222
uint256 period;
222223
}
223224

@@ -229,6 +230,7 @@ interface IBondRead {
229230
struct CouponFor {
230231
uint256 tokenBalance;
231232
uint256 rate;
233+
uint8 rateDecimals;
232234
uint256 recordDate;
233235
uint256 executionDate;
234236
uint256 period;

packages/ats/contracts/contracts/layer_2/interfaces/bond/IBondStorageWrapper.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ interface IBondStorageWrapper {
224224
uint256 indexed recordDate,
225225
uint256 indexed executionDate,
226226
uint256 rate,
227+
uint256 rateDecimals,
227228
uint256 period
228229
);
229230

packages/ats/contracts/scripts/factory.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,13 +270,15 @@ export interface BondDetailsData {
270270
export interface CouponDetailsData {
271271
couponFrequency: number
272272
couponRate: number
273+
couponRateDecimals: number
273274
firstCouponDate: number
274275
}
275276

276277
export interface CouponData {
277278
recordDate: number
278279
executionDate: number
279280
rate: number
281+
rateDecimals: number
280282
period: number
281283
}
282284

@@ -509,6 +511,7 @@ export async function setBondData({
509511
maturityDate,
510512
couponFrequency,
511513
couponRate,
514+
couponRateDecimals,
512515
firstCouponDate,
513516
init_rbacs,
514517
addAdmin = true,
@@ -538,6 +541,7 @@ export async function setBondData({
538541
maturityDate: number
539542
couponFrequency: number
540543
couponRate: number
544+
couponRateDecimals: number
541545
firstCouponDate: number
542546
init_rbacs?: Rbac[]
543547
addAdmin: boolean
@@ -604,6 +608,7 @@ export async function setBondData({
604608
const couponDetails: CouponDetailsData = {
605609
couponFrequency: couponFrequency,
606610
couponRate: couponRate,
611+
couponRateDecimals: couponRateDecimals,
607612
firstCouponDate: firstCouponDate,
608613
}
609614

@@ -762,6 +767,7 @@ export async function deployBondFromFactory({
762767
maturityDate,
763768
couponFrequency,
764769
couponRate,
770+
couponRateDecimals,
765771
firstCouponDate,
766772
regulationType,
767773
regulationSubType,
@@ -794,6 +800,7 @@ export async function deployBondFromFactory({
794800
maturityDate: number
795801
couponFrequency: number
796802
couponRate: number
803+
couponRateDecimals: number
797804
firstCouponDate: number
798805
regulationType: number
799806
regulationSubType: number
@@ -827,6 +834,7 @@ export async function deployBondFromFactory({
827834
maturityDate,
828835
couponFrequency,
829836
couponRate,
837+
couponRateDecimals,
830838
firstCouponDate,
831839
init_rbacs,
832840
addAdmin,

0 commit comments

Comments
 (0)