@circle-fin/provider-borrow-service

中文文档
1.0.5发布于 2026/11/06TypeScriptESM + CJS近 30 天下载 9136

Provider for BorrowKit's Circle-hosted lending backend

原始使用文档
文档目录4 节
  1. Installation
  2. Quick Start
  3. Configuration
  4. License

Borrow Service Provider

License

Borrow Service Provider defines the provider contract used by Borrow Kit and ships the default HTTP implementation for Circle's Borrow Service, covering loan listing (getLoans), partial repayment (repay, getRepayQuote), loan position reads (getPosition), collateral management (addCollateral, withdrawCollateral), reward claiming (claimRewards, getRewards), and registerWebhook.

registerWebhook builds the EIP-712 WebhookRegistration typed data, obtains a signature via the connected adapter, and submits the signed registration for verification (including EIP-1271 support for smart contract accounts). This is a permissionless, client-signed flow with no on-chain transaction and no API key.

Health-band notifications sent to the registered URL are delivered at-least-once: the same crossing can arrive more than once. Deduplicate on the notification's event_id, which is stable across redeliveries of one crossing.

Installation

npm install @circle-fin/provider-borrow-service
# or
yarn add @circle-fin/provider-borrow-service

This provider is included by default in @circle-fin/borrow-kit. Import it directly when you need to customize provider construction or compose your own Borrow Kit context.

Quick Start

Note: @circle-fin/borrow-kit is not yet published — this example shows the intended usage once it ships. Until then, construct BorrowServiceProvider and call registerWebhook on it directly with a resolved EVMChainDefinition; see Configuration below.

import {
  createBorrowKitContext,
  registerWebhook,
} from "@circle-fin/borrow-kit";
import { BorrowServiceProvider } from "@circle-fin/provider-borrow-service";
import { createViemAdapterFromPrivateKey } from "@circle-fin/adapter-viem-v2";

const provider = new BorrowServiceProvider();
const context = createBorrowKitContext({ providers: [provider] });
const privateKey = process.env.PRIVATE_KEY;
if (!privateKey) throw new Error("PRIVATE_KEY is required");
const adapter = createViemAdapterFromPrivateKey({ privateKey });

const result = await registerWebhook(context, {
  from: { adapter, chain: "Arc_Testnet" },
  loanId: "11111111-1111-4111-8111-111111111111",
  webhookUrl: "https://example.com/webhook",
});

console.log(`Registered webhook: ${result.webhookUrl}`);

Configuration

BorrowServiceProvider accepts default configuration in the constructor and per-operation configuration on each request. Per-operation values take precedence, while omitted values continue to use constructor defaults.

An API key is optional only for borrow and getBorrowQuote, and required for getIntegratorConfig and setIntegratorConfig. Every other API rejects a configured key before making a request (or, for registerWebhook, before signing).

const provider = new BorrowServiceProvider({
  apiKey: process.env.CIRCLE_API_KEY,
  baseUrl: "https://api-staging.circle.com",
});

apiKey takes a Circle API key (<ENV>_API_KEY:<keyId>:<keySecret>). A legacy KIT_KEY:<keyId>:<keySecret> value goes in the same field and still authenticates; the console no longer issues them. It is a server-only secret and is refused in a browser. Omit it for keyless routes.

Calling registerWebhook directly on the provider requires a resolved EVMChainDefinition and the connected wallet's address in addition to the adapter. EVMChainDefinition values (such as ArcTestnet) currently live in the internal @core/chains package, which is not published standalone — the snippet below illustrates the shape expected until @circle-fin/borrow-kit (which resolves chains by name, as shown in Quick Start) is published:

import { ArcTestnet } from "@core/chains";

const result = await provider.registerWebhook({
  adapter,
  chain: ArcTestnet,
  address: "0x1234567890123456789012345678901234567890",
  loanId: "11111111-1111-4111-8111-111111111111",
  webhookUrl: "https://example.com/webhook",
  deadline: Math.floor(Date.now() / 1000) + 300,
});

console.log(`Registered webhook: ${result.webhookUrl}`);

The BorrowServiceProvider implements wallet-scoped loan listing through GET /v1/borrowKit/loans, including cursor pagination, response validation, retry behavior, and structured errors.

It also implements the partial-repayment and full-close prepare/quote endpoints. Repay requests reuse a caller-provided idempotency key or generate one when omitted; full-close writes generate one. Quote requests remain side-effect free and omit it.

License

This project is licensed under the Apache 2.0 License. Contact support for details.

版本与发布记录

@circle-fin/provider-borrow-service 共发布 7 个版本,首次发布于 2026/09/30;过去 12 个月发布了 7 个版本。

版本发布日期距今
1.0.5latest2026/11/063 天前
1.0.42026/10/3110 天前
1.0.32026/10/2317 天前
1.0.22026/10/2119 天前
1.0.12026/10/1624 天前
1.0.02026/09/301 个月前

关于 @circle-fin/provider-borrow-service 的常见问题

@circle-fin/provider-borrow-service 是什么?

Provider for BorrowKit's Circle-hosted lending backend

如何安装 @circle-fin/provider-borrow-service?

在项目目录运行 npm install @circle-fin/provider-borrow-service,或使用 pnpm add / yarn add / bun add。

@circle-fin/provider-borrow-service 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@circle-fin/provider-borrow-service 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@circle-fin/provider-borrow-service 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@circle-fin/provider-borrow-service 可以商用吗?

@circle-fin/provider-borrow-service 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@circle-fin/provider-borrow-service 的下载量有多少?

根据 npm 官方下载统计,@circle-fin/provider-borrow-service 在 2026/10/10 – 2026/11/08 这 30 天内被下载 9,136 次,日均约 305 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@circle-fin/provider-borrow-service 还在维护吗?

最新版本 1.0.5 发布于 2026/11/06(3 天前);至今共发布 7 个版本,其中过去 12 个月发布了 7 个;首次发布于 2026/09/30。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。