Skip to content

Commit 372c50b

Browse files
committed
feat(1636): New command- allowance for fungible token
Signed-off-by: matevszm <mateusz.marcinkowski@blockydevs.com>
1 parent 94cf56a commit 372c50b

File tree

11 files changed

+689
-0
lines changed

11 files changed

+689
-0
lines changed

src/core/services/token/token-service.interface.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
* All token services must implement this interface
44
*/
55
import type {
6+
AccountAllowanceApproveTransaction,
67
TokenAssociateTransaction,
78
TokenCreateTransaction,
89
TokenMintTransaction,
910
TransferTransaction,
1011
} from '@hashgraph/sdk';
1112
import type {
1213
NftTransferParams,
14+
TokenAllowanceFtParams,
1315
TokenAssociationParams,
1416
TokenCreateParams,
1517
TokenMintParams,
@@ -44,4 +46,8 @@ export interface TokenService {
4446
* Create an NFT transfer transaction (without execution)
4547
*/
4648
createNftTransferTransaction(params: NftTransferParams): TransferTransaction;
49+
50+
createFungibleTokenAllowanceTransaction(
51+
params: TokenAllowanceFtParams,
52+
): AccountAllowanceApproveTransaction;
4753
}

src/core/services/token/token-service.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type { Logger } from '@/core/services/logger/logger-service.interface';
77
import type {
88
CustomFee as CustomFeeParams,
99
NftTransferParams,
10+
TokenAllowanceFtParams,
1011
TokenAssociationParams,
1112
TokenCreateParams,
1213
TokenMintParams,
@@ -15,6 +16,7 @@ import type {
1516
import type { TokenService } from './token-service.interface';
1617

1718
import {
19+
AccountAllowanceApproveTransaction,
1820
AccountId,
1921
CustomFixedFee,
2022
CustomFractionalFee,
@@ -267,6 +269,21 @@ export class TokenServiceImpl implements TokenService {
267269
return transferTx;
268270
}
269271

272+
createFungibleTokenAllowanceTransaction(
273+
params: TokenAllowanceFtParams,
274+
): AccountAllowanceApproveTransaction {
275+
const { tokenId, ownerAccountId, spenderAccountId, amount } = params;
276+
this.logger.debug(
277+
`[TOKEN SERVICE] Creating FT allowance: ${amount.toString()} tokens of ${tokenId} from ${ownerAccountId} to spender ${spenderAccountId}`,
278+
);
279+
return new AccountAllowanceApproveTransaction().approveTokenAllowance(
280+
TokenId.fromString(tokenId),
281+
AccountId.fromString(ownerAccountId),
282+
AccountId.fromString(spenderAccountId),
283+
amount,
284+
);
285+
}
286+
270287
/**
271288
* Process custom fees and convert them to Hedera CustomFee objects
272289
*/

src/core/types/token.types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,10 @@ export interface NftTransferParams {
101101
toAccountId: string;
102102
serialNumbers: number[];
103103
}
104+
105+
export interface TokenAllowanceFtParams {
106+
tokenId: string;
107+
ownerAccountId: string;
108+
spenderAccountId: string;
109+
amount: bigint;
110+
}

0 commit comments

Comments
 (0)