@zkp2p/sdk 0.11.2 → 0.12.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +104 -9
- package/dist/{chunk-LPKFXAKY.mjs → chunk-DZQOCRT4.mjs} +44196 -1199
- package/dist/chunk-DZQOCRT4.mjs.map +1 -0
- package/dist/index.cjs +45095 -1568
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +33 -5
- package/dist/index.d.ts +33 -5
- package/dist/index.mjs +538 -16
- package/dist/index.mjs.map +1 -1
- package/dist/protocolViewerParsers-WK2QPJH7.mjs +5 -0
- package/dist/{protocolViewerParsers-M7C2ICV3.mjs.map → protocolViewerParsers-WK2QPJH7.mjs.map} +1 -1
- package/dist/react.d.mts +2 -2
- package/dist/react.d.ts +2 -2
- package/dist/{vaultUtils-CbfjrxgD.d.mts → vaultUtils-Bc9KwywX.d.mts} +330 -7
- package/dist/{vaultUtils-CbfjrxgD.d.ts → vaultUtils-Bc9KwywX.d.ts} +330 -7
- package/package.json +1 -1
- package/dist/chunk-LPKFXAKY.mjs.map +0 -1
- package/dist/protocolViewerParsers-M7C2ICV3.mjs +0 -5
package/README.md
CHANGED
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
|
|
7
7
|
Stable TypeScript SDK for trustless fiat-to-crypto on Base. ZKP2P combines escrowed on-chain settlement, TLS attestations for payment verification, and API/indexer helpers so makers, takers, wallets, and embedded ramps can ship production-grade fiat liquidity flows without building their own contract or indexing stack.
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
Install `@zkp2p/sdk@latest` for the stable Curator v3, OrchestratorV3, staking,
|
|
10
|
+
and chargeback-risk surface. The workspace version lives in `package.json`.
|
|
11
11
|
|
|
12
12
|
## Why This SDK
|
|
13
13
|
|
|
@@ -30,7 +30,7 @@ v3 routes and OrchestratorV3 hard cut.
|
|
|
30
30
|
- RPC-first reads: primary reads use ProtocolViewer and on-chain fallbacks, so `getDeposits()`, `getDeposit()`, `getIntents()`, `getIntent()`, and the `getPv*` methods are not blocked on indexer lag.
|
|
31
31
|
- Indexer for history and filtering: use `client.indexer.*` for pagination, historical volumes, fund activities, daily snapshots, and vault analytics.
|
|
32
32
|
- Version-aware routing: new intents use EscrowV2 and OrchestratorV3; existing intent reads and lifecycle writes resolve their OrchestratorV2 or V3 owner. Legacy V1 fallbacks have been removed.
|
|
33
|
-
- Modular internals: intent, guardian, access-policy, vault, and ProtocolViewer logic are extracted from `Zkp2pClient`, keeping the main client focused on orchestration.
|
|
33
|
+
- Modular internals: intent, guardian, access-policy, staking, vault, and ProtocolViewer logic are extracted from `Zkp2pClient`, keeping the main client focused on orchestration.
|
|
34
34
|
- App-level rollout control: the SDK is capability-based. Product gating and phase flags belong in your app layer, not inside transaction helpers.
|
|
35
35
|
|
|
36
36
|
## Installation
|
|
@@ -107,6 +107,8 @@ Indexer defaults by environment:
|
|
|
107
107
|
| Indexer | `client.indexer.getDeposits`, `getDepositsWithRelations`, `getDepositById`, `getDepositsByIds`, `getDepositsByIdsWithRelations`, `getDepositsByPayeeHash`, `getIntentsForDeposits`, `getOwnerIntents`, `getIntentsByRateManager`, `getIntentByHash`, `getExpiredIntents`, `getFulfilledIntentEvents`, `getIntentFulfillmentAmounts`, `getFulfillmentAndPayment`, `getDepositFundActivities`, `getMakerFundActivities`, `getDepositDailySnapshots`, `getProfitSnapshotsByDeposits`, `getRateManagers`, `getRateManagerDetail`, `getRateManagerDelegations`, `getDelegationForDeposit`, `getManagerDailySnapshots`, `getManualRateUpdates`, `getOracleConfigUpdates`, `query` |
|
|
108
108
|
| React hooks | `@zkp2p/sdk/react` exports hooks for deposits, intents, delegation, vaults, and payment methods |
|
|
109
109
|
| Attribution | ERC-8021 helpers like `sendTransactionWithAttribution`, `encodeWithAttribution`, and `txOverrides.referrer` support |
|
|
110
|
+
| Taker staking | `ensureStakeAllowance`, `depositStake`, `withdrawStake`, `claim`, `setTakerAuthorization`, `selectStakeOwner`, `clearStakeOwner`, direct StakeVault reads, and `client.indexer.getStakingState()` |
|
|
111
|
+
| Chargeback keepers | `releaseMaturedChargebackIntent`, `releaseMaturedChargebackIntents`, with caller-pinned `chargebackPolicyAddress` support |
|
|
110
112
|
|
|
111
113
|
## Extension Metadata Bridge
|
|
112
114
|
|
|
@@ -144,10 +146,11 @@ peer.authenticate({
|
|
|
144
146
|
});
|
|
145
147
|
```
|
|
146
148
|
|
|
147
|
-
`requestConnection()`
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
149
|
+
`requestConnection()` opens an extension-owned approval window for third-party
|
|
150
|
+
origins. Trusted Peer hosts and `localhost` are already connected.
|
|
151
|
+
`authenticate()` identifies the provider with `platform` and
|
|
152
|
+
`actionType`; the extension fetches the matching extension-managed template
|
|
153
|
+
from `https://api.zkp2p.xyz/providers/`. Buyer TEE is API/template driven: pass `captureMode: "buyerTee"` plus
|
|
151
154
|
`attestationServiceUrl`, and the extension returns encrypted session material.
|
|
152
155
|
For SAR, pass `captureMode: "sellerCredential"` and optionally pass
|
|
153
156
|
`attestationServiceUrl` only when overriding the extension's production
|
|
@@ -212,8 +215,8 @@ const { hashedOnchainIds } = await client.registerPayeeDetails({
|
|
|
212
215
|
const quote = await client.getQuote({
|
|
213
216
|
paymentPlatforms: ['wise'],
|
|
214
217
|
fiatCurrency: 'USD',
|
|
215
|
-
user: '
|
|
216
|
-
recipient: '
|
|
218
|
+
user: '0xBuyer',
|
|
219
|
+
recipient: '0xBuyer',
|
|
217
220
|
destinationChainId: 8453,
|
|
218
221
|
destinationToken: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',
|
|
219
222
|
amount: '250',
|
|
@@ -228,6 +231,79 @@ const payeeHash = await client.resolvePayeeHash(
|
|
|
228
231
|
|
|
229
232
|
`getQuote()` returns available liquidity plus payee details when authenticated. Use `getQuotesBestByPlatform()` to fetch the best quote per supported payment platform in a single call (handy for cross-platform comparison UIs).
|
|
230
233
|
|
|
234
|
+
## Taker Staking
|
|
235
|
+
|
|
236
|
+
```ts
|
|
237
|
+
const amount = 250_000000n;
|
|
238
|
+
const approval = await client.ensureStakeAllowance({ amount });
|
|
239
|
+
// Wait for approval.hash to confirm when hadAllowance is false.
|
|
240
|
+
|
|
241
|
+
await client.depositStake({ amount }); // sender becomes the stake owner
|
|
242
|
+
await client.withdrawStake({ amount: 50_000000n }); // immediate, free stake only
|
|
243
|
+
await client.claim(); // withdraws the caller's full claimable balance
|
|
244
|
+
|
|
245
|
+
// Safe sponsorship is a two-actor flow:
|
|
246
|
+
await client.setTakerAuthorization({ taker, authorized: true }); // signed by the Safe
|
|
247
|
+
await client.selectStakeOwner({ stakeOwner: safeAddress }); // signed by the taker
|
|
248
|
+
await client.clearStakeOwner(); // taker returns to self-stake
|
|
249
|
+
|
|
250
|
+
const onchain = await client.getStakeVaultState({
|
|
251
|
+
staker: takerAddress,
|
|
252
|
+
taker: takerAddress,
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
const indexed = await client.indexer.getStakingState({
|
|
256
|
+
chainId: 8453,
|
|
257
|
+
environment: 'base',
|
|
258
|
+
vaultAddress: client.getStakeVaultContract().address,
|
|
259
|
+
chargebackPolicyAddress: client.getChargebackPolicyContract().address,
|
|
260
|
+
taker: takerAddress,
|
|
261
|
+
// Always supply the effective owner from the fresh on-chain read.
|
|
262
|
+
stakeOwner: onchain.stakeOwner,
|
|
263
|
+
});
|
|
264
|
+
// indexed: effective/raw ownership, total/locked/free stake, claimable,
|
|
265
|
+
// authorizations, admissions-pause state, Vault controller, and per-row
|
|
266
|
+
// freshness.
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
Stake writes expose direct and `.prepare()` variants: `depositStake`,
|
|
270
|
+
`withdrawStake`, `claim`, `setTakerAuthorization`, `selectStakeOwner`, and
|
|
271
|
+
`clearStakeOwner`. There is no withdrawal request, cooldown, or exit
|
|
272
|
+
lifecycle — `withdrawStake` is immediate up to `freeStake`, and `claim`
|
|
273
|
+
withdraws the complete claimable balance. Chargebackable capacity is exactly
|
|
274
|
+
the effective owner's free stake (1:1); never sum a taker's self-stake with a
|
|
275
|
+
sponsor's stake.
|
|
276
|
+
|
|
277
|
+
The vault's controller is the `ChargebackPolicy` contract. It owns
|
|
278
|
+
per-payment-method risk windows (`getRiskWindow(paymentMethodHash)`),
|
|
279
|
+
per-deposit chargeback enablement (`isChargebackEnabled(escrow, depositId)`),
|
|
280
|
+
and the global `admissionsPaused()` switch. `@zkp2p/contracts-v2@0.4.0`
|
|
281
|
+
resolves the deployed StakeVault, ChargebackPolicy, and OrchestratorV3 for
|
|
282
|
+
both the production and staging bundles; a bundle without them fails closed
|
|
283
|
+
(`VITE_BASE_STAGING_STAKE_VAULT_ADDRESS` /
|
|
284
|
+
`VITE_BASE_STAGING_CHARGEBACK_POLICY_ADDRESS` overrides support local
|
|
285
|
+
deployments).
|
|
286
|
+
|
|
287
|
+
Keeper writes are direct and prepareable:
|
|
288
|
+
|
|
289
|
+
```ts
|
|
290
|
+
const release = await client.releaseMaturedChargebackIntents.prepare({
|
|
291
|
+
intentHashes: [intentHash],
|
|
292
|
+
chargebackPolicyAddress: snapshottedPolicyAddress,
|
|
293
|
+
});
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
An explicit `chargebackPolicyAddress` is caller-pinned and may be outside the
|
|
297
|
+
client's configured deployment context, allowing sweepers to group intents by
|
|
298
|
+
their snapshotted policy deployment without a later SDK configuration change
|
|
299
|
+
rerouting them.
|
|
300
|
+
|
|
301
|
+
`client.indexer.getStakingState()` composes the `@zkp2p/indexer-schema@0.20.0`
|
|
302
|
+
account rows and preserves their individual freshness. Its caller-supplied
|
|
303
|
+
`stakeOwner` must come from a fresh on-chain `stakeOwnerOf(taker)` read; stale
|
|
304
|
+
indexed ownership is reported without attributing another owner's balance.
|
|
305
|
+
Refetch immediately before signaling; the contract stays authoritative.
|
|
306
|
+
|
|
231
307
|
For table-style liquidity UIs, the low-level `apiGetOrderbookTable()` adapter exposes curator's paginated public/private orderbook rows and row-level privacy metadata.
|
|
232
308
|
|
|
233
309
|
## Seller Credential Status
|
|
@@ -644,6 +720,17 @@ const fulfilledEvents = await client.indexer.getFulfilledIntentEvents(['0xIntent
|
|
|
644
720
|
const fulfillment = await client.indexer.getIntentFulfillmentAmounts('0xIntentHash');
|
|
645
721
|
const fulfillmentAndPayment = await client.indexer.getFulfillmentAndPayment('0xIntentHash');
|
|
646
722
|
|
|
723
|
+
// Indexed staking state. stakeOwner must come from a fresh
|
|
724
|
+
// stakeOwnerOf(taker) read; the adapter checks it against indexed ownership.
|
|
725
|
+
const stakingState = await client.indexer.getStakingState({
|
|
726
|
+
chainId: 8453,
|
|
727
|
+
environment: 'base',
|
|
728
|
+
vaultAddress: '0xStakeVault',
|
|
729
|
+
chargebackPolicyAddress: '0xChargebackPolicy',
|
|
730
|
+
taker: '0xTaker',
|
|
731
|
+
stakeOwner: '0xEffectiveStakeOwner',
|
|
732
|
+
});
|
|
733
|
+
|
|
647
734
|
// Received USDC:
|
|
648
735
|
// - fulfilledEvents[0].amount is the net USDC transferred to the taker.
|
|
649
736
|
// - fulfillment.takerAmountNetFees is the same net taker amount from the Intent row.
|
|
@@ -713,15 +800,23 @@ Hook groups:
|
|
|
713
800
|
|
|
714
801
|
```ts
|
|
715
802
|
import {
|
|
803
|
+
DEFERRED_SETTLEMENT_FUNDED_EVENT_ABI,
|
|
716
804
|
getContracts,
|
|
805
|
+
getOrchestratorV3Contract,
|
|
717
806
|
getPaymentMethodsCatalog,
|
|
718
807
|
getRateManagerContracts,
|
|
808
|
+
getChargebackPolicyContract,
|
|
809
|
+
getStakeVaultContract,
|
|
810
|
+
RISK_POSITION_SETTLED_EVENT_ABI,
|
|
719
811
|
resolveFiatCurrencyBytes32,
|
|
720
812
|
resolvePaymentMethodHash,
|
|
721
813
|
} from '@zkp2p/sdk';
|
|
722
814
|
|
|
723
815
|
const contracts = getContracts(8453, 'production');
|
|
724
816
|
const rateManagerContracts = getRateManagerContracts(8453, 'production');
|
|
817
|
+
const stakeVault = getStakeVaultContract(8453, 'staging');
|
|
818
|
+
const orchestratorV3 = getOrchestratorV3Contract(8453, 'staging');
|
|
819
|
+
const chargebackPolicy = getChargebackPolicyContract(8453, 'staging');
|
|
725
820
|
const paymentMethods = getPaymentMethodsCatalog(8453, 'production');
|
|
726
821
|
const usdHash = resolveFiatCurrencyBytes32('USD');
|
|
727
822
|
const wiseHash = resolvePaymentMethodHash('wise', { env: 'production' });
|