Skip to content

Commit 2189e68

Browse files
authored
Add TokenFactory module to support token management operations (#62)
1 parent f51235b commit 2189e68

File tree

11 files changed

+415
-0
lines changed

11 files changed

+415
-0
lines changed

apps/core/src/app.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { DeployModule } from './deploy/deploy.module';
99
import { LoansModule } from './loans/loans.module';
1010
import { ParticipationTokenModule } from './participation-token/participation-token.module';
1111
import { VaultModule } from './vault/vault.module';
12+
import { TokenFactoryModule } from './token-factory/token-factory.module';
1213

1314
@Module({
1415
imports: [
@@ -20,6 +21,7 @@ import { VaultModule } from './vault/vault.module';
2021
LoansModule,
2122
ParticipationTokenModule,
2223
VaultModule,
24+
TokenFactoryModule,
2325
],
2426
controllers: [AppController],
2527
providers: [AppService],
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { IsString, IsNumber, IsNotEmpty, IsPositive } from 'class-validator';
2+
3+
export class ApproveDto {
4+
@IsString()
5+
@IsNotEmpty()
6+
contractId: string;
7+
8+
@IsString()
9+
@IsNotEmpty()
10+
from: string;
11+
12+
@IsString()
13+
@IsNotEmpty()
14+
spender: string;
15+
16+
@IsNumber()
17+
@IsPositive()
18+
amount: number;
19+
20+
@IsNumber()
21+
@IsPositive()
22+
expirationLedger: number;
23+
24+
@IsString()
25+
@IsNotEmpty()
26+
callerPublicKey: string;
27+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { IsString, IsNumber, IsNotEmpty, IsPositive } from 'class-validator';
2+
3+
export class BurnFromDto {
4+
@IsString()
5+
@IsNotEmpty()
6+
contractId: string;
7+
8+
@IsString()
9+
@IsNotEmpty()
10+
spender: string;
11+
12+
@IsString()
13+
@IsNotEmpty()
14+
from: string;
15+
16+
@IsNumber()
17+
@IsPositive()
18+
amount: number;
19+
20+
@IsString()
21+
@IsNotEmpty()
22+
callerPublicKey: string;
23+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { IsString, IsNumber, IsNotEmpty, IsPositive } from 'class-validator';
2+
3+
export class BurnDto {
4+
@IsString()
5+
@IsNotEmpty()
6+
contractId: string;
7+
8+
@IsString()
9+
@IsNotEmpty()
10+
from: string;
11+
12+
@IsNumber()
13+
@IsPositive()
14+
amount: number;
15+
16+
@IsString()
17+
@IsNotEmpty()
18+
callerPublicKey: string;
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { IsString, IsNumber, IsNotEmpty, IsPositive } from 'class-validator';
2+
3+
export class MintDto {
4+
@IsString()
5+
@IsNotEmpty()
6+
contractId: string;
7+
8+
@IsString()
9+
@IsNotEmpty()
10+
to: string;
11+
12+
@IsNumber()
13+
@IsPositive()
14+
amount: number;
15+
16+
@IsString()
17+
@IsNotEmpty()
18+
callerPublicKey: string;
19+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { IsString, IsNotEmpty } from 'class-validator';
2+
3+
export class SetAdminDto {
4+
@IsString()
5+
@IsNotEmpty()
6+
contractId: string;
7+
8+
@IsString()
9+
@IsNotEmpty()
10+
newAdmin: string;
11+
12+
@IsString()
13+
@IsNotEmpty()
14+
callerPublicKey: string;
15+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { IsString, IsNumber, IsNotEmpty, IsPositive } from 'class-validator';
2+
3+
export class TransferFromDto {
4+
@IsString()
5+
@IsNotEmpty()
6+
contractId: string;
7+
8+
@IsString()
9+
@IsNotEmpty()
10+
spender: string;
11+
12+
@IsString()
13+
@IsNotEmpty()
14+
from: string;
15+
16+
@IsString()
17+
@IsNotEmpty()
18+
to: string;
19+
20+
@IsNumber()
21+
@IsPositive()
22+
amount: number;
23+
24+
@IsString()
25+
@IsNotEmpty()
26+
callerPublicKey: string;
27+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { IsString, IsNumber, IsNotEmpty, IsPositive } from 'class-validator';
2+
3+
export class TransferDto {
4+
@IsString()
5+
@IsNotEmpty()
6+
contractId: string;
7+
8+
@IsString()
9+
@IsNotEmpty()
10+
from: string;
11+
12+
@IsString()
13+
@IsNotEmpty()
14+
to: string;
15+
16+
@IsNumber()
17+
@IsPositive()
18+
amount: number;
19+
20+
@IsString()
21+
@IsNotEmpty()
22+
callerPublicKey: string;
23+
}
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
import { Controller, Post, Get, Body, Query } from '@nestjs/common';
2+
import { TokenFactoryService } from './token-factory.service';
3+
import { MintDto } from './dto/mint.dto';
4+
import { SetAdminDto } from './dto/set-admin.dto';
5+
import { ApproveDto } from './dto/approve.dto';
6+
import { TransferDto } from './dto/transfer.dto';
7+
import { TransferFromDto } from './dto/transfer-from.dto';
8+
import { BurnDto } from './dto/burn.dto';
9+
import { BurnFromDto } from './dto/burn-from.dto';
10+
11+
@Controller('token-factory')
12+
export class TokenFactoryController {
13+
constructor(private readonly tokenFactoryService: TokenFactoryService) {}
14+
15+
// ── POST endpoints (writes) ──
16+
17+
@Post('mint')
18+
async mint(@Body() dto: MintDto) {
19+
const unsignedXdr = await this.tokenFactoryService.mint(dto);
20+
return { unsignedXdr };
21+
}
22+
23+
@Post('set-admin')
24+
async setAdmin(@Body() dto: SetAdminDto) {
25+
const unsignedXdr = await this.tokenFactoryService.setAdmin(dto);
26+
return { unsignedXdr };
27+
}
28+
29+
@Post('approve')
30+
async approve(@Body() dto: ApproveDto) {
31+
const unsignedXdr = await this.tokenFactoryService.approve(dto);
32+
return { unsignedXdr };
33+
}
34+
35+
@Post('transfer')
36+
async transfer(@Body() dto: TransferDto) {
37+
const unsignedXdr = await this.tokenFactoryService.transfer(dto);
38+
return { unsignedXdr };
39+
}
40+
41+
@Post('transfer-from')
42+
async transferFrom(@Body() dto: TransferFromDto) {
43+
const unsignedXdr = await this.tokenFactoryService.transferFrom(dto);
44+
return { unsignedXdr };
45+
}
46+
47+
@Post('burn')
48+
async burn(@Body() dto: BurnDto) {
49+
const unsignedXdr = await this.tokenFactoryService.burn(dto);
50+
return { unsignedXdr };
51+
}
52+
53+
@Post('burn-from')
54+
async burnFrom(@Body() dto: BurnFromDto) {
55+
const unsignedXdr = await this.tokenFactoryService.burnFrom(dto);
56+
return { unsignedXdr };
57+
}
58+
59+
// ── GET endpoints (reads) ──
60+
61+
@Get('balance')
62+
async getBalance(
63+
@Query('contractId') contractId: string,
64+
@Query('address') address: string,
65+
@Query('callerPublicKey') callerPublicKey: string,
66+
) {
67+
const balance = await this.tokenFactoryService.getBalance(contractId, address, callerPublicKey);
68+
return { balance: String(balance) };
69+
}
70+
71+
@Get('allowance')
72+
async getAllowance(
73+
@Query('contractId') contractId: string,
74+
@Query('from') from: string,
75+
@Query('spender') spender: string,
76+
@Query('callerPublicKey') callerPublicKey: string,
77+
) {
78+
const allowance = await this.tokenFactoryService.getAllowance(
79+
contractId,
80+
from,
81+
spender,
82+
callerPublicKey,
83+
);
84+
return { allowance: String(allowance) };
85+
}
86+
87+
@Get('decimals')
88+
async getDecimals(
89+
@Query('contractId') contractId: string,
90+
@Query('callerPublicKey') callerPublicKey: string,
91+
) {
92+
const decimals = await this.tokenFactoryService.getDecimals(contractId, callerPublicKey);
93+
return { decimals };
94+
}
95+
96+
@Get('name')
97+
async getName(
98+
@Query('contractId') contractId: string,
99+
@Query('callerPublicKey') callerPublicKey: string,
100+
) {
101+
const name = await this.tokenFactoryService.getName(contractId, callerPublicKey);
102+
return { name: String(name) };
103+
}
104+
105+
@Get('symbol')
106+
async getSymbol(
107+
@Query('contractId') contractId: string,
108+
@Query('callerPublicKey') callerPublicKey: string,
109+
) {
110+
const symbol = await this.tokenFactoryService.getSymbol(contractId, callerPublicKey);
111+
return { symbol: String(symbol) };
112+
}
113+
114+
@Get('escrow-id')
115+
async getEscrowId(
116+
@Query('contractId') contractId: string,
117+
@Query('callerPublicKey') callerPublicKey: string,
118+
) {
119+
const escrowId = await this.tokenFactoryService.getEscrowId(contractId, callerPublicKey);
120+
return { escrowId: String(escrowId) };
121+
}
122+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { Module } from '@nestjs/common';
2+
import { TokenFactoryController } from './token-factory.controller';
3+
import { TokenFactoryService } from './token-factory.service';
4+
5+
@Module({
6+
controllers: [TokenFactoryController],
7+
providers: [TokenFactoryService],
8+
})
9+
export class TokenFactoryModule {}

0 commit comments

Comments
 (0)