Skip to content

Adding unfreeze and withdraw for tron unstaking #6013

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 23, 2025
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
8 changes: 8 additions & 0 deletions modules/sdk-coin-trx/src/lib/enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ export enum ContractType {
* This is the contract for voting for witnesses
*/
VoteWitness,
/**
* This is the contract for unfreezing balances
*/
UnfreezeBalanceV2,
/**
* This is the contract for withdrawing expired unfrozen balances
*/
WithdrawExpireUnfreeze,
}

export enum PermissionType {
Expand Down
89 changes: 88 additions & 1 deletion modules/sdk-coin-trx/src/lib/iface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ export interface RawData {
| AccountPermissionUpdateContract[]
| TriggerSmartContract[]
| FreezeBalanceV2Contract[]
| VoteWitnessContract[];
| VoteWitnessContract[]
| UnfreezeBalanceV2Contract[]
| WithdrawExpireUnfreezeContract[];
}

export interface Value {
Expand Down Expand Up @@ -132,6 +134,15 @@ export interface FreezeBalanceValueFields {
owner_address: string;
}

/**
* Unfreeze transaction value fields
*/
export interface UnfreezeBalanceValueFields {
resource: string;
unfreeze_balance: number;
owner_address: string;
}

/**
* Freeze balance contract value interface
*/
Expand All @@ -148,6 +159,22 @@ export interface FreezeBalanceV2Contract {
type?: string;
}

/**
* Unfreeze balance contract value interface
*/
export interface UnfreezeBalanceValue {
type_url?: string;
value: UnfreezeBalanceValueFields;
}

/**
* Unfreeze balance v2 contract interface
*/
export interface UnfreezeBalanceV2Contract {
parameter: UnfreezeBalanceValue;
type?: string;
}

/**
* Freeze balance contract parameter interface
*/
Expand All @@ -161,6 +188,39 @@ export interface FreezeBalanceContractParameter {
};
}

/**
* Withdraw transaction value fields
*/
export interface WithdrawExpireUnfreezeValueFields {
owner_address: string;
}

/**
* Withdraw balance contract value interface
*/
export interface WithdrawExpireUnfreezeValue {
type_url?: string;
value: WithdrawExpireUnfreezeValueFields;
}

/**
* Withdraw expire unfreeze contract interface
*/
export interface WithdrawExpireUnfreezeContract {
parameter: WithdrawExpireUnfreezeValue;
type?: string;
}

export interface UnfreezeBalanceContractParameter {
parameter: {
value: {
resource: TronResource;
unfreeze_balance: number;
owner_address: string;
};
};
}

/**
* Freeze balance contract decoded interface
*/
Expand All @@ -170,6 +230,22 @@ export interface FreezeContractDecoded {
frozenBalance?: string | number;
}

/**
* Unfreeze balance contract decoded interface
*/
export interface UnfreezeContractDecoded {
ownerAddress?: string;
resource?: number;
unfreezeBalance?: string | number;
}

/**
* Withdraw expire unfreeze contract decoded interface
*/
export interface WithdrawContractDecoded {
ownerAddress?: string;
}

/**
* Vote data in a vote transaction
*/
Expand Down Expand Up @@ -227,3 +303,14 @@ export interface VoteWitnessContractParameter {
};
};
}

/**
* Withdraw expire unfreeze contract parameter interface
*/
export interface WithdrawExpireUnfreezeContractParameter {
parameter: {
value: {
owner_address: string;
};
};
}
26 changes: 26 additions & 0 deletions modules/sdk-coin-trx/src/lib/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import {
TransferContract,
TriggerSmartContract,
VoteWitnessContract,
UnfreezeBalanceV2Contract,
WithdrawExpireUnfreezeContract,
} from './iface';

/**
Expand Down Expand Up @@ -162,6 +164,30 @@ export class Transaction extends BaseTransaction {
value: totalVoteCount.toString(),
};
break;
case ContractType.UnfreezeBalanceV2:
this._type = TransactionType.StakingDeactivate;
const unfreezeValues = (rawData.contract[0] as UnfreezeBalanceV2Contract).parameter.value;
output = {
address: unfreezeValues.owner_address,
value: unfreezeValues.unfreeze_balance.toString(),
};
input = {
address: unfreezeValues.owner_address,
value: unfreezeValues.unfreeze_balance.toString(),
};
break;
case ContractType.WithdrawExpireUnfreeze:
this._type = TransactionType.StakingWithdraw;
const withdrawValues = (rawData.contract[0] as WithdrawExpireUnfreezeContract).parameter.value;
output = {
address: withdrawValues.owner_address,
value: '0', // no value field
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just trying to understand, why this is 0 in StakingWithdraw type?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just set as a placeholder as we don't provide any explicit value for the amount to be withdrawn

};
input = {
address: withdrawValues.owner_address,
value: '0',
};
break;
default:
throw new ParseTransactionError('Unsupported contract type');
}
Expand Down
Loading