Skip to content

Accept any TxSigner in PerpClient; add aws feature for KMS signing#62

Merged
Praz314159 merged 1 commit into
mainfrom
feat/generic-signer-kms
Jul 2, 2026
Merged

Accept any TxSigner in PerpClient; add aws feature for KMS signing#62
Praz314159 merged 1 commit into
mainfrom
feat/generic-signer-kms

Conversation

@Praz314159

@Praz314159 Praz314159 commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

PerpClient::new/new_arbitrum/new_arbitrum_sepolia are now generic over S: TxSigner + Send + Sync + 'static instead of requiring a concrete PrivateKeySigner. Signing already flowed through EthereumWallet asynchronously, so remote signers drop in with no pipeline changes, and existing PrivateKeySigner callers compile unchanged.

New opt-in aws cargo feature enables alloy/signer-aws, and examples/aws_kms_signer.rs shows the end-to-end flow: AWS credential chain -> KMS client -> AwsSigner -> PerpClient. This lets bots sign with a KMS asymmetric secp256k1 key that never leaves AWS, gated by IAM.

Summary by CodeRabbit

  • New Features

    • Added AWS KMS signing support behind an optional feature flag.
    • Added a new example showing how to sign and send transactions using a remote AWS KMS key.
  • Bug Fixes

    • Client setup now works with more signer types, including remote signers, instead of only local private keys.
  • Documentation

    • Updated release notes and crate docs to reflect the broader signer support and the new AWS KMS workflow.

PerpClient::new/new_arbitrum/new_arbitrum_sepolia are now generic over
S: TxSigner<Signature> + Send + Sync + 'static instead of requiring a
concrete PrivateKeySigner. Signing already flowed through EthereumWallet
asynchronously, so remote signers drop in with no pipeline changes, and
existing PrivateKeySigner callers compile unchanged.

New opt-in `aws` cargo feature enables alloy/signer-aws, and
examples/aws_kms_signer.rs shows the end-to-end flow: AWS credential
chain -> KMS client -> AwsSigner -> PerpClient. This lets bots sign with
a KMS asymmetric secp256k1 key that never leaves AWS, gated by IAM.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

PerpClient constructor methods (new, new_arbitrum, new_arbitrum_sepolia) are generalized to accept any signer implementing TxSigner<Signature> + Send + Sync + 'static instead of only PrivateKeySigner. An aws Cargo feature, AWS KMS dev-dependencies, and a new aws_kms_signer example are added, along with documentation and changelog updates.

Changes

Generic Signer Support and AWS KMS Example

Layer / File(s) Summary
Generalize PerpClient constructors
src/client/mod.rs
PerpClient::new, new_arbitrum, and new_arbitrum_sepolia accept a generic S: TxSigner<Signature> + Send + Sync + 'static instead of PrivateKeySigner, deriving the address via TxSigner::address and updating imports/docs.
aws feature and KMS dependencies
Cargo.toml
Adds an aws feature enabling alloy/signer-aws, aws-config/aws-sdk-kms dev-dependencies, and a new aws_kms_signer example gated behind the aws feature.
AWS KMS signer example
examples/aws_kms_signer.rs
New example demonstrates creating an AwsSigner from KMS, connecting via PerpClient::new_arbitrum_sepolia, syncing client state, and opening/closing a taker position.
Documentation and changelog
src/lib.rs, CHANGELOG.md
Crate docs and changelog updated to describe generic TxSigner support and the new AWS KMS feature/example.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Example as aws_kms_signer.rs
  participant KmsClient as aws_sdk_kms::Client
  participant AwsSigner
  participant PerpClient
  participant Chain as Arbitrum Sepolia

  Example->>KmsClient: create client from AWS config
  Example->>AwsSigner: create with KMS key id
  Example->>PerpClient: new_arbitrum_sepolia(transport, AwsSigner, deployments)
  PerpClient->>Chain: sync_nonce, refresh_gas, ensure_approval
  Example->>PerpClient: open_taker(...)
  PerpClient->>AwsSigner: sign transaction via KMS
  PerpClient->>Chain: submit tx
  Example->>PerpClient: adjust_taker(...) to close position
  PerpClient->>AwsSigner: sign transaction via KMS
  PerpClient->>Chain: submit tx
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the two main changes: generic TxSigner support in PerpClient and the new AWS KMS signing feature.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/generic-signer-kms

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
examples/aws_kms_signer.rs (1)

73-97: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Example uses no slippage bounds (amt1_limit: 0 / u128::MAX).

For a demo this is fine, but since this example is likely to be copy-pasted into real bots, consider a brief comment noting these are placeholder values and production code should set real slippage limits.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@examples/aws_kms_signer.rs` around lines 73 - 97, The example in
aws_kms_signer.rs uses placeholder slippage bounds in open_taker and
adjust_taker, which can be misleading if copied into production code. Add a
brief inline comment near the OpenTakerParams and AdjustTakerParams setup
explaining that amt1_limit values like 0 and u128::MAX are demo placeholders,
and that real bots should set explicit slippage limits before using
client.open_taker and client.adjust_taker.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@examples/aws_kms_signer.rs`:
- Around line 73-97: The example in aws_kms_signer.rs uses placeholder slippage
bounds in open_taker and adjust_taker, which can be misleading if copied into
production code. Add a brief inline comment near the OpenTakerParams and
AdjustTakerParams setup explaining that amt1_limit values like 0 and u128::MAX
are demo placeholders, and that real bots should set explicit slippage limits
before using client.open_taker and client.adjust_taker.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: df1d0297-2246-496e-8766-8c440dab7b5e

📥 Commits

Reviewing files that changed from the base of the PR and between 6f74cbc and 9e35094.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (5)
  • CHANGELOG.md
  • Cargo.toml
  • examples/aws_kms_signer.rs
  • src/client/mod.rs
  • src/lib.rs

@Praz314159
Praz314159 merged commit b1741a4 into main Jul 2, 2026
8 checks passed
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.

1 participant