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
7 changes: 6 additions & 1 deletion sdk/__tests__/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,12 @@ export const PROXY_ADMIN_CONTRACT_ID = '0.0.2';
export const MAX_SUPPLY = '100000000000';
export const INITIAL_SUPPLY = '1000000000';
export const INITIAL_HBAR_SUPPLY = '10000000000000000000';
export const EXPIRATION_TIMESTAMP = '1759047276000000000';
export const EXPIRATION_TIMESTAMP = (
(Date.now() + 30 * 24 * 60 * 60 * 1000) *
1_000_000
)
.toString()
.padStart(19, '0');
export const AUTO_RENEW_ACCOUNT = '0.0.5';
export const RESERVE_AMOUNT = '100000000000000';
export const RESERVE_ADDRESS = '0.0.7654321';
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
*/

import { ICommandHandler } from '../../../../../../core/command/CommandHandler.js';
import { UINT256_MAX } from '../../../../../../core/Constants.js';
import { CommandHandler } from '../../../../../../core/decorator/CommandHandlerDecorator.js';
import { lazyInject } from '../../../../../../core/decorator/LazyInjectDecorator.js';
import BigDecimal from '../../../../../../domain/context/shared/BigDecimal.js';
Expand Down Expand Up @@ -73,13 +72,9 @@ export class GrantMultiRolesCommandHandler

const amountsFormatted: BigDecimal[] = [];
amounts.forEach((amount) => {
if (amount == '0') {
amountsFormatted.push(BigDecimal.fromString(UINT256_MAX));
} else {
amountsFormatted.push(
BigDecimal.fromString(amount, capabilities.coin.decimals),
);
}
amountsFormatted.push(
BigDecimal.fromString(amount, capabilities.coin.decimals),
);
});

const res = await handler.grantRoles(
Expand Down
3 changes: 1 addition & 2 deletions sdk/src/core/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,4 @@ export const DEFAULT_VERSION = 1;

export const ONE_THOUSAND = 1000;

export const UINT256_MAX =
'0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff';
export const UINT256_MAX = (1n << 256n) - 1n;
29 changes: 24 additions & 5 deletions sdk/src/port/out/hs/HederaTransactionAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ import {
RELEASE_HOLD_GAS,
RECLAIM_HOLD_GAS,
CONTROLLER_CREATE_HOLD_GAS,
UINT256_MAX,
} from '../../../core/Constants.js';
import LogService from '../../../app/service/LogService.js';
import { RESERVE_DECIMALS } from '../../../domain/context/reserve/Reserve.js';
Expand Down Expand Up @@ -658,10 +659,18 @@ export abstract class HederaTransactionAdapter extends TransactionAdapter {
amounts: BigDecimal[],
startDate?: string,
): Promise<TransactionResponse> {
const amountsFormatted: bigint[] = [];

amounts.forEach((amount) => {
if (amount == BigDecimal.fromString('0')) {
amountsFormatted.push(UINT256_MAX);
} else amountsFormatted.push(amount.toBigInt());
});

const params = new Params({
roles: roles,
targetsId: targetsId,
amounts: amounts,
amounts: amountsFormatted,
});

let gas = targetsId.length * roles.length * GRANT_ROLES_GAS;
Expand Down Expand Up @@ -1189,10 +1198,16 @@ export abstract class HederaTransactionAdapter extends TransactionAdapter {
targetsId: HederaId[],
targetId: HederaId,
): Promise<TransactionResponse<any, Error>> {
const amountsFormatted: bigint[] = [];

amounts.forEach((amount) => {
amountsFormatted.push(amount.toBigInt());
});

const params = new Params({
targetId: targetId,
targetsId: targetsId,
amounts: amounts,
amounts: amountsFormatted,
});
if (!coin.coin.tokenId)
throw new Error(
Expand Down Expand Up @@ -1521,7 +1536,11 @@ export abstract class HederaTransactionAdapter extends TransactionAdapter {
const targetsIdString: string[] = [];

for (let i = 0; i < params.amounts!.length; i++) {
amountsLong.push(params.amounts![i].toLong());
amountsLong.push(
BigDecimal.fromString(
params.amounts![i].toString(),
).toLong(),
);
targetsIdString.push(params.targetsId![i].toString());
}

Expand Down Expand Up @@ -1710,7 +1729,7 @@ class Params {
customFees?: HCustomFee[];
roles?: string[];
targetsId?: HederaId[];
amounts?: BigDecimal[];
amounts?: bigint[];
name?: string;
symbol?: string;
autoRenewPeriod?: number;
Expand Down Expand Up @@ -1767,7 +1786,7 @@ class Params {
customFees?: HCustomFee[];
roles?: string[];
targetsId?: HederaId[];
amounts?: BigDecimal[];
amounts?: bigint[];
name?: string;
symbol?: string;
autoRenewPeriod?: number;
Expand Down
5 changes: 4 additions & 1 deletion sdk/src/port/out/rpc/RPCTransactionAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ import {
RELEASE_HOLD_GAS,
RECLAIM_HOLD_GAS,
CONTROLLER_CREATE_HOLD_GAS,
UINT256_MAX,
} from '../../../core/Constants.js';
import { MetaMaskInpageProvider } from '@metamask/providers';
import { WalletConnectError } from '../../../domain/context/network/error/WalletConnectError.js';
Expand Down Expand Up @@ -886,7 +887,9 @@ export default class RPCTransactionAdapter extends TransactionAdapter {

const amountsFormatted: bigint[] = [];
amounts.forEach((amount) => {
amountsFormatted.push(amount.toBigInt());
if (amount == BigDecimal.fromString('0')) {
amountsFormatted.push(UINT256_MAX);
} else amountsFormatted.push(amount.toBigInt());
});

const accounts: string[] = [];
Expand Down
Loading