-
Notifications
You must be signed in to change notification settings - Fork 302
feat(sdk-core): bulk TRX resource delegation SDK + Express layer #8572
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
bhavidhingra
merged 1 commit into
master
from
chalo-287-bulk-trx-resource-delegation-sdk
May 7, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
modules/express/src/typedRoutes/api/v2/delegateResources.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| import * as t from 'io-ts'; | ||
| import { httpRoute, httpRequest, optional } from '@api-ts/io-ts-http'; | ||
| import { BitgoExpressError } from '../../schemas/error'; | ||
|
|
||
| /** | ||
| * Path parameters for the delegate resources endpoint | ||
| */ | ||
| export const DelegateResourcesParams = { | ||
|
bhavidhingra marked this conversation as resolved.
|
||
| /** Coin identifier (e.g., 'trx', 'ttrx') */ | ||
| coin: t.string, | ||
| /** Wallet ID */ | ||
| id: t.string, | ||
| } as const; | ||
|
|
||
| /** | ||
| * A single resource delegation entry | ||
| */ | ||
| export const DelegationEntryCodec = t.type({ | ||
| /** On-chain address that will receive the delegated resources */ | ||
| receiverAddress: t.string, | ||
| /** Amount of TRX (in SUN) to stake for the delegation */ | ||
| amount: t.string, | ||
| /** Resource type to delegate (e.g. 'ENERGY', 'BANDWIDTH') */ | ||
| resource: t.string, | ||
| }); | ||
|
|
||
| /** | ||
| * Request body for delegating resources to multiple receiver addresses. | ||
| * Each delegation entry triggers a separate on-chain staking transaction | ||
| * from the wallet's root address to the receiver address. | ||
| * | ||
| * Signing behaviour by wallet type: | ||
| * - Hot (non-TSS) → signed locally with walletPassphrase and submitted | ||
| * - Custodial non-TSS → sent for BitGo approval via initiateTransaction | ||
| * - TSS (any) → build response contains txRequestId; signed by TSS service | ||
| */ | ||
| export const DelegateResourcesRequestBody = { | ||
| /** Delegation entries — one on-chain transaction is built per entry */ | ||
| delegations: t.array(DelegationEntryCodec), | ||
|
|
||
| /** Wallet passphrase to decrypt the user key (hot wallets) */ | ||
| walletPassphrase: optional(t.string), | ||
| /** Extended private key (alternative to walletPassphrase) */ | ||
| xprv: optional(t.string), | ||
| /** One-time password for 2FA */ | ||
| otp: optional(t.string), | ||
|
|
||
| /** API version for TSS transaction request response ('lite' or 'full') */ | ||
| apiVersion: optional(t.union([t.literal('lite'), t.literal('full')])), | ||
| } as const; | ||
|
|
||
| export const DelegationFailureEntry = t.type({ | ||
| /** Human-readable error message */ | ||
| message: t.string, | ||
| /** Receiver address that failed, if available */ | ||
| receiverAddress: optional(t.string), | ||
| }); | ||
|
bhavidhingra marked this conversation as resolved.
|
||
|
|
||
| /** | ||
| * Response for the delegate resources operation. | ||
| * Returns arrays of successful and failed delegation transactions. | ||
| */ | ||
| export const DelegateResourcesResponse = t.type({ | ||
| /** Successfully sent delegation transactions */ | ||
| success: t.array(t.unknown), | ||
| /** Errors from failed delegation transactions */ | ||
| failure: t.array(DelegationFailureEntry), | ||
| }); | ||
|
|
||
| /** | ||
| * Response for partial success or failure cases (202/400). | ||
| * Includes both the transaction results and error metadata. | ||
| */ | ||
| export const DelegateResourcesErrorResponse = t.intersection([DelegateResourcesResponse, BitgoExpressError]); | ||
|
|
||
| /** | ||
| * Bulk Resource Delegation | ||
| * | ||
| * Delegates resources (ENERGY or BANDWIDTH) from a wallet's root address to one or more | ||
| * receiver addresses. Each delegation entry produces a separate on-chain staking transaction. | ||
| * This is the resource-delegation analogue of the consolidateAccount endpoint. | ||
| * | ||
| * Supported coins: TRON (trx, ttrx) and any future coins that support resource delegation. | ||
| * | ||
| * The API may return partial success (status 202) if some delegations succeed but others fail. | ||
| * | ||
| * @operationId express.v2.wallet.delegateresources | ||
| * @tag express | ||
| */ | ||
| export const PostDelegateResources = httpRoute({ | ||
| path: '/api/v2/{coin}/wallet/{id}/delegateResources', | ||
| method: 'POST', | ||
| request: httpRequest({ | ||
| params: DelegateResourcesParams, | ||
| body: DelegateResourcesRequestBody, | ||
| }), | ||
| response: { | ||
| /** All delegations succeeded */ | ||
| 200: DelegateResourcesResponse, | ||
| /** Partial success — some delegations succeeded, others failed */ | ||
| 202: DelegateResourcesErrorResponse, | ||
| /** All delegations failed */ | ||
| 400: DelegateResourcesErrorResponse, | ||
| }, | ||
| }); | ||
75 changes: 75 additions & 0 deletions
75
modules/express/src/typedRoutes/api/v2/undelegateResources.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| import * as t from 'io-ts'; | ||
| import { httpRoute, httpRequest, optional } from '@api-ts/io-ts-http'; | ||
| import { BitgoExpressError } from '../../schemas/error'; | ||
| import { DelegateResourcesParams, DelegationEntryCodec, DelegationFailureEntry } from './delegateResources'; | ||
|
|
||
| /** | ||
| * Request body for undelegating resources from multiple receiver addresses. | ||
| * Each undelegation entry triggers a separate on-chain transaction that reclaims | ||
| * previously delegated resources back to the wallet's root address. | ||
| * | ||
| * Signing behaviour by wallet type: | ||
| * - Hot (non-TSS) → signed locally with walletPassphrase and submitted | ||
| * - Custodial non-TSS → sent for BitGo approval via initiateTransaction | ||
| * - TSS (any) → build response contains txRequestId; signed by TSS service | ||
| */ | ||
| export const UndelegateResourcesRequestBody = { | ||
| /** Undelegation entries — one on-chain transaction is built per entry */ | ||
| undelegations: t.array(DelegationEntryCodec), | ||
|
|
||
| /** Wallet passphrase to decrypt the user key (hot wallets) */ | ||
| walletPassphrase: optional(t.string), | ||
| /** Extended private key (alternative to walletPassphrase) */ | ||
| xprv: optional(t.string), | ||
| /** One-time password for 2FA */ | ||
| otp: optional(t.string), | ||
|
|
||
| /** API version for TSS transaction request response ('lite' or 'full') */ | ||
| apiVersion: optional(t.union([t.literal('lite'), t.literal('full')])), | ||
| } as const; | ||
|
|
||
| /** | ||
| * Response for the undelegate resources operation. | ||
| * Returns arrays of successful and failed undelegation transactions. | ||
| */ | ||
| export const UndelegateResourcesResponse = t.type({ | ||
| /** Successfully sent undelegation transactions */ | ||
| success: t.array(t.unknown), | ||
| /** Errors from failed undelegation transactions */ | ||
| failure: t.array(DelegationFailureEntry), | ||
| }); | ||
|
|
||
| /** | ||
| * Response for partial success or failure cases (202/400). | ||
| */ | ||
| export const UndelegateResourcesErrorResponse = t.intersection([UndelegateResourcesResponse, BitgoExpressError]); | ||
|
|
||
| /** | ||
| * Bulk Resource Undelegation | ||
| * | ||
| * Reclaims delegated resources (ENERGY or BANDWIDTH) back to a wallet's root address | ||
| * from one or more receiver addresses. Each entry produces a separate on-chain transaction. | ||
| * | ||
| * Supported coins: TRON (trx, ttrx) and any future coins that support resource delegation. | ||
| * | ||
| * The API may return partial success (status 202) if some undelegations succeed but others fail. | ||
| * | ||
| * @operationId express.v2.wallet.undelegateresources | ||
| * @tag express | ||
| */ | ||
| export const PostUndelegateResources = httpRoute({ | ||
| path: '/api/v2/{coin}/wallet/{id}/undelegateResources', | ||
| method: 'POST', | ||
| request: httpRequest({ | ||
| params: DelegateResourcesParams, | ||
| body: UndelegateResourcesRequestBody, | ||
| }), | ||
| response: { | ||
| /** All undelegations succeeded */ | ||
| 200: UndelegateResourcesResponse, | ||
| /** Partial success — some undelegations succeeded, others failed */ | ||
| 202: UndelegateResourcesErrorResponse, | ||
| /** All undelegations failed */ | ||
| 400: UndelegateResourcesErrorResponse, | ||
| }, | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.