Skip to content

feat(sdk-core): bulk TRX resource delegation SDK + Express layer#8572

Open
bhavidhingra wants to merge 1 commit intomasterfrom
chalo-287-bulk-trx-resource-delegation-sdk
Open

feat(sdk-core): bulk TRX resource delegation SDK + Express layer#8572
bhavidhingra wants to merge 1 commit intomasterfrom
chalo-287-bulk-trx-resource-delegation-sdk

Conversation

@bhavidhingra
Copy link
Copy Markdown
Contributor

@bhavidhingra bhavidhingra commented Apr 20, 2026

Summary

Resource Delegation

  • Adds buildResourceDelegations, sendResourceDelegation, sendResourceDelegations to Wallet and IWallet
  • buildResourceDelegations: POSTs to /:coin/wallet/:id/delegateResources/build, post-processes prebuilds
  • sendResourceDelegation: dispatches per wallet type — TSS → sendManyTxRequests, custodial → initiateTransaction, hot → prebuildAndSignTransaction + submitTransaction
  • sendResourceDelegations: validates passphrase, builds all, sends sequentially, collects { success, failure }
  • Adds typed Express route (PostDelegateResources) and handleV2DelegateResources handler with partial-success 202/400 response logic

Resource Undelegation

  • Adds buildResourceUndelegations, sendResourceUndelegation, sendResourceUndelegations to Wallet and IWallet — mirrors delegation API exactly
  • buildResourceUndelegations: POSTs to /:coin/wallet/:id/undelegateResources/build
  • Adds typed Express route (PostUndelegateResources) and handleV2UndelegateResources handler
  • Delegation and undelegation share private helpers (buildResourceManagements, sendResourceManagement, sendResourceManagements) to eliminate code duplication

stakingParams relay

  • Adds stakingParams?: unknown to PrebuildTransactionResult so staking metadata flows from the build response through to submitTransaction, enabling the indexer to identify resource management transfers correctly

Test plan

  • Unit test: buildResourceDelegations / buildResourceUndelegations call the right endpoints and post-process prebuilds
  • Unit test: sendResourceDelegation / sendResourceUndelegation route correctly per wallet type
  • Express: POST /api/v2/ttrx/wallet/:id/delegateResources returns 200/202/400 as appropriate
  • Express: POST /api/v2/ttrx/wallet/:id/undelegateResources returns 200/202/400 as appropriate

Linear: CHALO-287

@bhavidhingra bhavidhingra requested review from a team as code owners April 20, 2026 09:06
@linear
Copy link
Copy Markdown

linear Bot commented Apr 20, 2026

@bhavidhingra bhavidhingra force-pushed the chalo-287-bulk-trx-resource-delegation-sdk branch from 496a288 to 5bc64a4 Compare April 20, 2026 10:01
@bhavidhingra
Copy link
Copy Markdown
Contributor Author

@claude review

@bhavidhingra bhavidhingra force-pushed the chalo-287-bulk-trx-resource-delegation-sdk branch from 5bc64a4 to 42b5824 Compare April 20, 2026 10:52
@bhavidhingra bhavidhingra marked this pull request as draft April 20, 2026 10:54
@bhavidhingra bhavidhingra force-pushed the chalo-287-bulk-trx-resource-delegation-sdk branch 6 times, most recently from 15b4e19 to 5019af4 Compare April 22, 2026 15:09
@pranavjain97
Copy link
Copy Markdown
Contributor

Flush, please request re-review when ready for review.

@bhavidhingra bhavidhingra force-pushed the chalo-287-bulk-trx-resource-delegation-sdk branch 3 times, most recently from 982359a to b22a03a Compare April 23, 2026 13:28
@bhavidhingra bhavidhingra marked this pull request as ready for review April 25, 2026 12:20
Copy link
Copy Markdown
Contributor

@pranavjain97 pranavjain97 left a comment

Choose a reason for hiding this comment

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

TSS detection uses coin-level check instead of wallet-level, receiverAddress never populated, and no tests included

const params = coin.supportsTss() ? createTSSSendParams(req, wallet) : createSendParams(req);
result =
type === 'delegateResource'
? await wallet.sendResourceDelegations(params)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

existing handlers check wallet._wallet.multisigType === 'tss', not coin.supportsTss(). these can diverge, should use the wallet-level check

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

// Surface unexpected errors as 400 rather than 500
(err as any).status = 400;
throw err;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

all other handlers assign err.status = 400 directly without a cast. use the same pattern

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

message: t.string,
/** Receiver address that failed, if available */
receiverAddress: t.union([t.string, t.undefined]),
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

t.union([t.string, t.undefined]) doesn't decode an absent JSON key correctly, use optional(t.string) consistent with the other fields

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

*/
async buildResourceDelegations(
params: BuildResourceDelegationTransactionOptions
): Promise<PrebuildTransactionResult[]> {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

receiverAddress is typed as available but never populated here. either populate it from unsignedBuild or remove the field from the types


if (!Array.isArray(buildResponse.transactions)) {
throw new Error(`Unexpected response from ${endpoint}: missing transactions array`);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

build errors are swallowed at debug level. if some entries failed to build, those failures won't appear in the final { success, failure } response. should these be surfaced?

sendResourceDelegations(params: BuildResourceDelegationTransactionOptions): Promise<{
success: any[];
failure: { message: string; receiverAddress?: string }[];
}>;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

sendResourceDelegation and sendResourceUndelegation return Promise<any>, define a typed result interface

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

defined ResourceManagementSendResult

@@ -1096,6 +1117,18 @@ export interface IWallet {
buildAccountConsolidations(params?: BuildConsolidationTransactionOptions): Promise<PrebuildTransactionResult[]>;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is resource delegation going to be used by other coins, or is this TRX-specific? if it's only TRX, every other coin gets 6 dead methods. consider keeping these on the coin class or as standalone helpers instead of bloating the wallet interface

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

keeping it as is - it follows the identical pattern of buildAccountConsolidations/sendAccountConsolidation with a supportsResourceDelegation() guard

Adds buildAccountDelegations, sendAccountDelegation, sendAccountDelegations
to the Wallet class and IWallet interface, mirroring the consolidation API.
Adds Express typed route schema and handler for
POST /api/v2/:coin/wallet/:id/delegateResources with TSS/custodial/hot wallet
branching and partial-success (202) response handling.

CHALO-287

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@bhavidhingra bhavidhingra force-pushed the chalo-287-bulk-trx-resource-delegation-sdk branch from b22a03a to aaf7a36 Compare April 28, 2026 07:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants