Skip to content

feat: add Based Loans action provider - #1653

Open
0xVarius wants to merge 1 commit into
coinbase:mainfrom
0xVarius:feat/basedloans-action-provider
Open

0xVarius wants to merge 1 commit into
coinbase:mainfrom
0xVarius:feat/basedloans-action-provider

Conversation

@0xVarius

Copy link
Copy Markdown

Description

Adds a Based Loans action provider. Based Loans is a fixed-term lending protocol on Base with no liquidations:

  • Borrowers deposit a token as collateral and receive USDC right away. They can buy the collateral back at a fixed price any time before the due date. If they don't, they keep the USDC and the lenders receive the collateral. Price moves during the loan never sell the collateral early.
  • Lenders deposit USDC and choose which tokens they lend against, with a USDC limit per token.

The provider wraps @basedloans/sdk (MIT, source). It reads every number live from Base mainnet, reads contract addresses from the protocol at runtime, and never holds keys. Write actions are signed by the agent's own wallet via EvmWalletProvider.sendTransaction.

14 actions

  • Read: get_protocol_info, list_markets, get_risk_report, quote_borrow, get_my_loans, get_my_lending, request_token_listing
  • Write: borrow, buyback, lend, set_lending_limits, withdraw, claim_proceeds, claim_collateral

Design notes:

  • get_risk_report gives the agent raw risk data for a token (price sources and whether they agree, pool history, trading needed to move the pool price 2x and 10x) with plain-language explanations, so it can judge a token before lending against it.
  • borrow replays the protocol's lender queue before sending anything. It refuses loans the contracts would reject (for example below the minimum size) with a readable reason, and warns when lenders can only part-fund the request.
  • Approvals are sent only when the current allowance is too low.
  • Tokens can be passed by address or symbol; ambiguous or unknown symbols return an error instead of guessing.
  • Every action returns a readable error string instead of throwing.
  • Supported network: base-mainnet only.

Files: the provider folder (provider, schemas, tests, README), the export in action-providers/index.ts, the actions table in typescript/agentkit/README.md, a patch changeset, and the dependency. The lockfile change is limited to the 16 lines for @basedloans/sdk, and pnpm install --frozen-lockfile passes.

The commit is signed.

Tests

Unit: pnpm test in typescript/agentkit gives 15 new tests passing (SDK mocked). They cover network support, symbol and address resolution, multi-step sending in order, stopping at a failed step, and error handling. tsc, ESLint and Prettier are clean.

End-to-end: this ran on an Anvil fork of Base mainnet at block 58283648. It used AgentKit's own CommonJS build (dist/) with a ViemWalletProvider and the published @basedloans/sdk@0.1.1, and invoked actions through agentKit.getActions():

PASS  AgentKit loads the provider  14 actions
PASS  read action via AgentKit (get_protocol_info)
PASS  lend action (wallet injected, approve + deposit)  Deposit 1000 USDC to lend on Based Loans.
PASS  quote via AgentKit  receive 89.012751
PASS  borrow action signed by the agent wallet  Borrow 89.012751 USDC (after a 2.273016 USDC fee) against 0.1 WETH.
PASS  get_my_loans sees the new loan
PASS  buyback action  Buy back all remaining collateral on loan 201.
PASS  doomed loan refused before sending  Error: Not building this loan: This collateral supports at most 9.12 USDC, below the 50 USDC minimum loan. Offer more collateral.
PASS  bad input returns a readable error, not a throw  Error: Unknown token "NOTATOKEN". Pass its contract address, or use request_token_listing.
ALL PASSED

Separately, on current main, invoking actions still produced 7 unhandled rejections from failed analytics requests (HTTP error! status: ...). Without a process.on("unhandledRejection") handler that crashes Node. #1408 handled this for trackInitialization; the per-action analytics call looks like it needs the same treatment. It is unrelated to this PR and noted in case it's useful.

Based Loans is a fixed-term lending protocol on Base with no
liquidations. The provider lets an agent quote and open loans, buy
collateral back, check a token's risk data, and lend USDC against tokens
it chooses. It wraps @basedloans/sdk; write actions are signed by the
agent's own wallet.
@cb-heimdall

Copy link
Copy Markdown

🟡 Heimdall Review Status

Requirement Status More Info
Reviews 🟡 0/1
Denominator calculation
Show calculation
1 if user is bot 0
1 if user is external 0
2 if repo is sensitive 0
From .codeflow.yml 1
Additional review requirements
Show calculation
Max 0
0
From CODEOWNERS 0
Global minimum 0
Max 1
1
1 if commit is unverified 0
1 if authored by an app that is not allowlisted and lacks verified human attribution 0
Sum 1

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants