Skip to content

feat: add transfer_position action (0.2.2)#8

Open
goheesheng wants to merge 5 commits into
mainfrom
feat/transfer-position
Open

feat: add transfer_position action (0.2.2)#8
goheesheng wants to merge 5 commits into
mainfrom
feat/transfer-position

Conversation

@goheesheng

Copy link
Copy Markdown
Collaborator

Summary

Adds an 11th action, transfer_position, so an agent can hand a settled option position to another address. This unblocks flows where the agent settles an RFQ on its own wallet (the signer owns the minted position) and must then transfer it to an end user or counterparty — e.g. an ACP provider fulfilling a job for a client.

Changes

  • transfer_position action — encodes BaseOption.transfer(bool isBuyer, address target) and broadcasts via the wallet provider (the SDK client still holds no signer). isBuyer selects the long/short leg; optionAddress is resolved from get_user_positions.
  • TransferPositionSchema / TransferPositionArgs — exported from the package entry.
  • get_user_positions now returns optionAddress (needed to address a transfer).
  • Safety — new transferPosition action type, gated by SafetyPolicy. No ERC20 amount (amount: 0n, so the notional cap is N/A); the collateral allowlist is skipped; the recipient is passed to onWriteAction as spender so hosts can allowlist the target.

Testing

  • npm run typecheck clean.
  • npm test — 24/24, including 5 new transferPosition safety cases (fail-closed, zero-amount passes the cap, allowlist skipped, host hook receives the recipient and can reject/allow).

Version

Bumps to 0.2.2. Additive only — no breaking changes to existing actions.

Adds an 11th action so an agent can hand a settled option position to
another address — unblocks ACP-provider flows where the agent settles on
its own wallet and must transfer the minted position to the client.

- transfer_position: encodes BaseOption.transfer(bool,address), broadcasts
  via the wallet provider; gated by SafetyPolicy (new transferPosition type,
  amount 0n, recipient surfaced to onWriteAction for allowlisting).
- get_user_positions now returns optionAddress.
- TransferPositionSchema/Args exported; tests + CHANGELOG + version bump.
….2.3)

Action methods are annotated `wallet: EvmWalletProvider`, but it was imported
as `type EvmWalletProvider` (type-only). With emitDecoratorMetadata, a type-only
annotation degrades the recorded design:paramtypes to `Function` instead of the
class — so AgentKit's validateActionMethodArguments sees isWalletProvider=false
and NEVER injects the wallet as arg[0]. The action then receives the schema args
as arg[0] and calls buildClient(args) → 'wallet.getNetwork is not a function',
failing every on-chain action (approve/request_rfq/settle/transfer_position).

Fix: import EvmWalletProvider as a VALUE. design:paramtypes now records
[EvmWalletProvider, void 0]; AgentKit injects the wallet correctly.

Surfaced during a live Base-mainnet trade with a CDP smart-account wallet.
24 tests + typecheck green; metadata verified in the built dist.
get_market_prices threw 'Do not know how to serialize a BigInt' — API response
has BigInt fields. Added a replacer coercing bigint→string.
buildClient now reads THETANUTS_REFERRER and, when it's a valid EVM address,
constructs the ThetanutsClient with referrer set so RFQ referral fees can accrue
to that wallet. Inert/no-op when unset or invalid (never throws — an invalid
referrer must not break trade execution). Also export buildClient from the
package index so the provider's referral/claim script can build a client.
Typecheck green, dist rebuilt.
…ts-sdk

CI failed building the agentkit: 'Cannot find module @thetanuts-finance/
thetanuts-client'. Root cause: the devDependency was file:../thetanuts-sdk — a
THIRD private sibling repo that isn't checked out in CI (only agentkit + provider
are). Locally it resolved because thetanuts-sdk exists on disk, masking it.

Fix: use the PUBLISHED @thetanuts-finance/thetanuts-client@^0.3.0 (public on npm,
identical 0.3.0 to what the file: link provided, and it already satisfies the
peerDependency range). Lockfile regenerated to resolve from registry.npmjs.org.
Agentkit builds green; the provider (which consumes this via file: link)
typechecks + 55 tests pass against it.
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