Skip to content

Commit bf49450

Browse files
abhijit0943Vijay-Jagannathan
authored andcommitted
feat(sdk-coin-trx): add unfreeze and withdraw for tron unstaking
Ticket: SC-1670
1 parent 39cae57 commit bf49450

File tree

10 files changed

+1341
-2
lines changed

10 files changed

+1341
-2
lines changed

modules/sdk-coin-trx/src/lib/enum.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ export enum ContractType {
2222
* This is the contract for voting for witnesses
2323
*/
2424
VoteWitness,
25+
/**
26+
* This is the contract for unfreezing balances
27+
*/
28+
UnfreezeBalanceV2,
29+
/**
30+
* This is the contract for withdrawing expired unfrozen balances
31+
*/
32+
WithdrawExpireUnfreeze,
2533
}
2634

2735
export enum PermissionType {

modules/sdk-coin-trx/src/lib/iface.ts

Lines changed: 88 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ export interface RawData {
4747
| AccountPermissionUpdateContract[]
4848
| TriggerSmartContract[]
4949
| FreezeBalanceV2Contract[]
50-
| VoteWitnessContract[];
50+
| VoteWitnessContract[]
51+
| UnfreezeBalanceV2Contract[]
52+
| WithdrawExpireUnfreezeContract[];
5153
}
5254

5355
export interface Value {
@@ -132,6 +134,15 @@ export interface FreezeBalanceValueFields {
132134
owner_address: string;
133135
}
134136

137+
/**
138+
* Unfreeze transaction value fields
139+
*/
140+
export interface UnfreezeBalanceValueFields {
141+
resource: string;
142+
unfreeze_balance: number;
143+
owner_address: string;
144+
}
145+
135146
/**
136147
* Freeze balance contract value interface
137148
*/
@@ -148,6 +159,22 @@ export interface FreezeBalanceV2Contract {
148159
type?: string;
149160
}
150161

162+
/**
163+
* Unfreeze balance contract value interface
164+
*/
165+
export interface UnfreezeBalanceValue {
166+
type_url?: string;
167+
value: UnfreezeBalanceValueFields;
168+
}
169+
170+
/**
171+
* Unfreeze balance v2 contract interface
172+
*/
173+
export interface UnfreezeBalanceV2Contract {
174+
parameter: UnfreezeBalanceValue;
175+
type?: string;
176+
}
177+
151178
/**
152179
* Freeze balance contract parameter interface
153180
*/
@@ -161,6 +188,39 @@ export interface FreezeBalanceContractParameter {
161188
};
162189
}
163190

191+
/**
192+
* Withdraw transaction value fields
193+
*/
194+
export interface WithdrawExpireUnfreezeValueFields {
195+
owner_address: string;
196+
}
197+
198+
/**
199+
* Withdraw balance contract value interface
200+
*/
201+
export interface WithdrawExpireUnfreezeValue {
202+
type_url?: string;
203+
value: WithdrawExpireUnfreezeValueFields;
204+
}
205+
206+
/**
207+
* Withdraw expire unfreeze contract interface
208+
*/
209+
export interface WithdrawExpireUnfreezeContract {
210+
parameter: WithdrawExpireUnfreezeValue;
211+
type?: string;
212+
}
213+
214+
export interface UnfreezeBalanceContractParameter {
215+
parameter: {
216+
value: {
217+
resource: TronResource;
218+
unfreeze_balance: number;
219+
owner_address: string;
220+
};
221+
};
222+
}
223+
164224
/**
165225
* Freeze balance contract decoded interface
166226
*/
@@ -170,6 +230,22 @@ export interface FreezeContractDecoded {
170230
frozenBalance?: string | number;
171231
}
172232

233+
/**
234+
* Unfreeze balance contract decoded interface
235+
*/
236+
export interface UnfreezeContractDecoded {
237+
ownerAddress?: string;
238+
resource?: number;
239+
unfreezeBalance?: string | number;
240+
}
241+
242+
/**
243+
* Withdraw expire unfreeze contract decoded interface
244+
*/
245+
export interface WithdrawContractDecoded {
246+
ownerAddress?: string;
247+
}
248+
173249
/**
174250
* Vote data in a vote transaction
175251
*/
@@ -227,3 +303,14 @@ export interface VoteWitnessContractParameter {
227303
};
228304
};
229305
}
306+
307+
/**
308+
* Withdraw expire unfreeze contract parameter interface
309+
*/
310+
export interface WithdrawExpireUnfreezeContractParameter {
311+
parameter: {
312+
value: {
313+
owner_address: string;
314+
};
315+
};
316+
}

modules/sdk-coin-trx/src/lib/transaction.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import {
2525
TransferContract,
2626
TriggerSmartContract,
2727
VoteWitnessContract,
28+
UnfreezeBalanceV2Contract,
29+
WithdrawExpireUnfreezeContract,
2830
} from './iface';
2931

3032
/**
@@ -162,6 +164,30 @@ export class Transaction extends BaseTransaction {
162164
value: totalVoteCount.toString(),
163165
};
164166
break;
167+
case ContractType.UnfreezeBalanceV2:
168+
this._type = TransactionType.StakingDeactivate;
169+
const unfreezeValues = (rawData.contract[0] as UnfreezeBalanceV2Contract).parameter.value;
170+
output = {
171+
address: unfreezeValues.owner_address,
172+
value: unfreezeValues.unfreeze_balance.toString(),
173+
};
174+
input = {
175+
address: unfreezeValues.owner_address,
176+
value: unfreezeValues.unfreeze_balance.toString(),
177+
};
178+
break;
179+
case ContractType.WithdrawExpireUnfreeze:
180+
this._type = TransactionType.StakingWithdraw;
181+
const withdrawValues = (rawData.contract[0] as WithdrawExpireUnfreezeContract).parameter.value;
182+
output = {
183+
address: withdrawValues.owner_address,
184+
value: '0', // no value field
185+
};
186+
input = {
187+
address: withdrawValues.owner_address,
188+
value: '0',
189+
};
190+
break;
165191
default:
166192
throw new ParseTransactionError('Unsupported contract type');
167193
}

0 commit comments

Comments
 (0)