@zyfai/sdk 1.4.0 → 1.8.0
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 +118 -4
- package/dist/index.d.mts +275 -15
- package/dist/index.d.ts +275 -15
- package/dist/index.js +1149 -70
- package/dist/index.mjs +1148 -47
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -285,6 +285,40 @@ const provider = await connector.getProvider();
|
|
|
285
285
|
await sdk.connectAccount(provider); // Uses provider's current chain
|
|
286
286
|
```
|
|
287
287
|
|
|
288
|
+
**Nested Safe owners (multisig treasury):** connect the parent Safe, then pass the **parent Safe
|
|
289
|
+
address** (not an owner EOA) as `userAddress` on `sendDeposit`. Use a `chainId` where that Safe
|
|
290
|
+
is deployed (for example Ethereum `1` when the treasury only exists on mainnet). The SDK deploys
|
|
291
|
+
a child Zyfai Safe owned by the parent, enables the agent session with EIP-712
|
|
292
|
+
`MultiChainSession` signing, and proposes an ERC-20 `transfer` from the parent. The SDK polls
|
|
293
|
+
Safe Transaction Service and registers the on-chain hash when execution completes.
|
|
294
|
+
|
|
295
|
+
A threshold above 1 connects through WalletConnect or the Safe App, which collects the other
|
|
296
|
+
signatures. A threshold-1 Safe can connect from a script:
|
|
297
|
+
|
|
298
|
+
```typescript
|
|
299
|
+
import { createSafeOwnerProvider, ZyfaiSDK } from "@zyfai/sdk";
|
|
300
|
+
import { createWalletClient, custom } from "viem";
|
|
301
|
+
import { base } from "viem/chains";
|
|
302
|
+
|
|
303
|
+
// `owner` is the wallet the user already connected. A private key is not required.
|
|
304
|
+
const owner = createWalletClient({
|
|
305
|
+
chain: base,
|
|
306
|
+
transport: custom(window.ethereum),
|
|
307
|
+
});
|
|
308
|
+
const provider = await createSafeOwnerProvider({
|
|
309
|
+
safeAddress: "0xParentSafe",
|
|
310
|
+
owner,
|
|
311
|
+
chain: base,
|
|
312
|
+
});
|
|
313
|
+
const sdk = new ZyfaiSDK({ apiKey: process.env.ZYFAI_API_KEY! });
|
|
314
|
+
const parent = await sdk.connectAccount(provider, 8453);
|
|
315
|
+
await sdk.sendDeposit(parent, 8453, "100000", "USDC");
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
A 2-of-4 Safe does not use `createSafeOwnerProvider`. Connect that Safe with WalletConnect or
|
|
319
|
+
the Safe App, pass the Safe address to `sendDeposit`, and the other owners confirm in the Safe
|
|
320
|
+
UI. `sendDeposit` waits for that execution.
|
|
321
|
+
|
|
288
322
|
##### `disconnectAccount(): Promise<void>`
|
|
289
323
|
|
|
290
324
|
Disconnect account and clear all authentication state.
|
|
@@ -327,7 +361,7 @@ Get the Smart Wallet (Safe) address for a user.
|
|
|
327
361
|
|
|
328
362
|
##### `deploySafe(userAddress: string, chainId: SupportedChainId, strategy?: Strategy): Promise<DeploySafeResponse>`
|
|
329
363
|
|
|
330
|
-
>
|
|
364
|
+
> Not needed for a predeployed (pool) wallet: `sendDeposit()` deploys the Safe and enables the agent session on first deposit, and this method warns when called for one. Required for an owner that is not predeployed — a contract owner such as a nested Safe, or a legacy self-deployed wallet — where `sendDeposit()` calls it internally.
|
|
331
365
|
|
|
332
366
|
Deploy a Safe smart wallet for a user. **Deployment is handled by the backend API**, which manages all RPC calls and bundler interactions. This avoids rate limiting issues.
|
|
333
367
|
|
|
@@ -378,11 +412,89 @@ Add a wallet address to the SDK API key's allowedWallets list. This endpoint req
|
|
|
378
412
|
|
|
379
413
|
### 3. Session Keys
|
|
380
414
|
|
|
415
|
+
#### Verify a Smart Sessions v1 enable message
|
|
416
|
+
|
|
417
|
+
For the legacy EOA-owner personal-sign flow, construct an exact, ordered payload
|
|
418
|
+
from the same inputs used by the signer. All flags are explicit: do not guess
|
|
419
|
+
or substitute defaults. For the frontend flow, the Smart Sessions address must
|
|
420
|
+
match the address used by its installed Rhinestone module SDK, which may differ
|
|
421
|
+
from another validator installed on the account.
|
|
422
|
+
|
|
423
|
+
```ts
|
|
424
|
+
import {
|
|
425
|
+
buildV1ChainSessions, serializeV1ChainSessions, parseV1ChainSessions,
|
|
426
|
+
hashV1SessionEnable, type V1SessionEnableInput,
|
|
427
|
+
} from "@zyfai/sdk";
|
|
428
|
+
|
|
429
|
+
// These values must come from the actual pending signature request.
|
|
430
|
+
// Repeat the entry for every chain, in exactly the signer's order.
|
|
431
|
+
declare const actualInput: V1SessionEnableInput;
|
|
432
|
+
const payload = buildV1ChainSessions([actualInput]);
|
|
433
|
+
const jsonForReviewer = serializeV1ChainSessions(payload);
|
|
434
|
+
|
|
435
|
+
// The reviewer receives the full JSON and recomputes locally.
|
|
436
|
+
const reviewedPayload = parseV1ChainSessions(jsonForReviewer);
|
|
437
|
+
const { permissionEnableHash, personalSignDigest } = hashV1SessionEnable(reviewedPayload);
|
|
438
|
+
console.log({ permissionEnableHash, personalSignDigest });
|
|
439
|
+
```
|
|
440
|
+
|
|
441
|
+
Each `V1SessionEnableInput` requires the smart-account address, Smart Sessions
|
|
442
|
+
contract address, nonce, three permission flags, and a session containing chain
|
|
443
|
+
ID, session validator and initialisation bytes, salt, paymaster flag, user-op
|
|
444
|
+
policies, ERC-7739 policies and permitted actions. Each action includes its
|
|
445
|
+
contract address, four-byte selector and policy addresses and initialisation
|
|
446
|
+
bytes. The JSON format represents chain IDs and nonces as decimal strings.
|
|
447
|
+
Keep array order and all bytes unchanged. The helper rejects missing fields,
|
|
448
|
+
invalid addresses, malformed bytes, invalid integer ranges and numeric JSON
|
|
449
|
+
chain IDs or nonces.
|
|
450
|
+
|
|
451
|
+
Compare `permissionEnableHash` byte-for-byte with the wallet's displayed
|
|
452
|
+
message. The EIP-191 digest is different from that displayed message. Review
|
|
453
|
+
and decode every policy independently against the actual contracts and ABIs: a
|
|
454
|
+
matching hash does not establish what policy bytes mean or that permissions are
|
|
455
|
+
safe. The application must supply the exact payload; the helper cannot recover
|
|
456
|
+
it from a hash, verify on-chain state, or verify that the export is the one
|
|
457
|
+
passed to the wallet. Regenerate the package whenever inputs or nonces change.
|
|
458
|
+
|
|
459
|
+
#### Verify an owner-signed user operation
|
|
460
|
+
|
|
461
|
+
Partner smart accounts sign their deployment, module installs and session
|
|
462
|
+
enable as one ERC-4337 v0.7 user operation. The wallet shows only the 32-byte
|
|
463
|
+
user operation hash (`message - 0x…`). Ask the app for the exact user operation
|
|
464
|
+
JSON before signing, then recompute the hash and decode the calls offline:
|
|
465
|
+
|
|
466
|
+
```ts
|
|
467
|
+
import { readFileSync } from "node:fs";
|
|
468
|
+
import { parseUserOperationJson, hashUserOperationV07, decodeUserOperationCalls } from "@zyfai/sdk";
|
|
469
|
+
|
|
470
|
+
const userOp = parseUserOperationJson(readFileSync("userop.json", "utf8"));
|
|
471
|
+
console.log(hashUserOperationV07(userOp, 8453)); // must equal the wallet's message
|
|
472
|
+
console.dir(decodeUserOperationCalls(userOp), { depth: null });
|
|
473
|
+
```
|
|
474
|
+
|
|
475
|
+
From a checkout of this repository, `npm run build` then
|
|
476
|
+
`npx tsx examples/verify-user-operation.ts userop.json 0x<wallet message>`
|
|
477
|
+
prints the hash, `MATCH` or `MISMATCH`, and a readable list of the calls.
|
|
478
|
+
|
|
479
|
+
The JSON uses the unpacked v0.7 fields (`sender`, `nonce`, `factory`,
|
|
480
|
+
`factoryData`, `callData`, gas limits and fees, `paymaster`,
|
|
481
|
+
`paymasterVerificationGasLimit`, `paymasterPostOpGasLimit`, `paymasterData`).
|
|
482
|
+
Integers are decimal or hex strings. The hash covers every field except the
|
|
483
|
+
signature, so it must be the final operation, after gas and paymaster data
|
|
484
|
+
are filled. A single changed byte gives a different hash.
|
|
485
|
+
|
|
486
|
+
`decodeUserOperationCalls` unwraps the Safe7579 first-deploy `setupSafe`,
|
|
487
|
+
ERC-7579 `execute`, `setRegistry`, `installModule` and Smart Sessions
|
|
488
|
+
`enableSessions`. For a session, check the session signers in
|
|
489
|
+
`sessionValidatorInitData` and that every action targets only the modules you
|
|
490
|
+
expect. Any other call is returned with its target and selector only: decode
|
|
491
|
+
it yourself. A matching hash proves what you sign, not that it is safe.
|
|
492
|
+
|
|
381
493
|
Session keys enable delegated transaction execution without exposing the main private key.
|
|
382
494
|
|
|
383
|
-
#### Simple Usage
|
|
495
|
+
#### Simple Usage
|
|
384
496
|
|
|
385
|
-
>
|
|
497
|
+
> Not needed for a predeployed (pool) wallet: its agent session is already enabled on-chain, `sendDeposit()` records it after the first deposit, and this method warns when called for one. Required for an owner that is not predeployed — a contract owner such as a nested Safe, or a legacy self-deployed wallet — where `sendDeposit()` calls it internally.
|
|
386
498
|
|
|
387
499
|
The SDK automatically fetches optimal session configuration from Zyfai API:
|
|
388
500
|
|
|
@@ -414,7 +526,7 @@ console.log("User ID:", result.userId);
|
|
|
414
526
|
- The SDK proactively checks if the user already has an active session key and returns early without requiring any signature if one exists
|
|
415
527
|
- The user record must have `smartWallet` and `chainId` set (predeployed assignment / first deposit)
|
|
416
528
|
- Protocol selection is **not** touched by `createSessionKey` — it's set by `deploySafe` and on the first `sendDeposit` call if USDC `chains` are still empty
|
|
417
|
-
-
|
|
529
|
+
- Prefer `sendDeposit()` for partner onboarding; `createSessionKey` stays the explicit entry point for owners that are not predeployed
|
|
418
530
|
- When `alreadyActive` is `true`, `sessionKeyAddress` and `signature` are not available in the response
|
|
419
531
|
|
|
420
532
|
### 4. Send a Deposit
|
|
@@ -1568,6 +1680,7 @@ Vitest loads `.env.test` automatically (`vitest.config.ts`).
|
|
|
1568
1680
|
| `LOCAL_SDK_API_KEYS_ADMIN_API_KEY` | Admin key for `POST /admin/sdk-api-keys` when `ZYFAI_ENV=local` |
|
|
1569
1681
|
| `STAGING_SDK_API_KEYS_ADMIN_API_KEY` | Same when `ZYFAI_ENV=staging` |
|
|
1570
1682
|
| `PRODUCTION_SDK_API_KEYS_ADMIN_API_KEY` | Same when `ZYFAI_ENV=production` |
|
|
1683
|
+
| `NESTED_SAFE_ADDRESS` | Optional parent Safe for `nested-safe-deposit`. Threshold 1 on Base, `PRIVATE_KEY` is an owner, at least 0.1 USDC on the Safe. Omit to skip that suite. |
|
|
1571
1684
|
|
|
1572
1685
|
`ZYFAI_ENV` selects the API stack and which `*_ZYFAI_API_KEY` is passed to `integrationSdkConfig()`.
|
|
1573
1686
|
|
|
@@ -1598,6 +1711,7 @@ Each suite uses `describeIntegrationSuite()` from `utils.ts` with `spendProfile`
|
|
|
1598
1711
|
| Read-only (e.g. `get-protocols`) | local, staging, production | `{ spendProfile: "readonly" }` |
|
|
1599
1712
|
| Fresh funded user (`setupFreshFundedUser`) | local, staging | `{ spendProfile: "spends_funds", credentialGate: "fresh_user" }` — **0.1 USDC** per run |
|
|
1600
1713
|
| Persistent wallet (`PRIVATE_KEY` EOA) | local, staging | `{ spendProfile: "spends_funds" }` (default `credentialGate: "persistent_wallet"`) |
|
|
1714
|
+
| Nested Safe deposit (`NESTED_SAFE_ADDRESS`) | local, staging | `{ spendProfile: "spends_funds", additionalSkipReason: skipNestedSafeAddressReason }` — **0.1 USDC** from the parent Safe, then withdrawn back to that Safe. `sendDeposit` polls Safe Transaction Service for up to 20 minutes. |
|
|
1601
1715
|
|
|
1602
1716
|
Release prep on **staging**: run one file via workspace skill **[backend-smoke](../.cursor/skills/backend-smoke/SKILL.md)** (e.g. `deposit-withdraw` or `send-deposit-wait-credit` for wallet pool / handover). After prod deploy, use **`get-protocols`** (or another `readonly` suite) only.
|
|
1603
1717
|
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Chain, PublicClient, Address as Address$1 } from 'viem';
|
|
1
|
+
import { Chain, PublicClient, Address as Address$1, Hex as Hex$1, Account, WalletClient } from 'viem';
|
|
2
|
+
import { hashChainSessions } from '@rhinestone/module-sdk';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Public TypeScript types for `@zyfai/sdk` request/response shapes and events.
|
|
@@ -1293,11 +1294,15 @@ declare class ZyfaiSDK {
|
|
|
1293
1294
|
signature: Hex;
|
|
1294
1295
|
origin?: string;
|
|
1295
1296
|
}): Promise<LoginResponse>;
|
|
1297
|
+
/** Warn that a deprecated compatibility method was called. */
|
|
1298
|
+
private warnDeprecatedOnboardingMethod;
|
|
1296
1299
|
/**
|
|
1297
|
-
* Warn
|
|
1298
|
-
*
|
|
1300
|
+
* Warn only a pool wallet, which sendDeposit onboards on its own. A contract
|
|
1301
|
+
* owner is never predeployed and reaches these methods through sendDeposit,
|
|
1302
|
+
* so warning unconditionally tells that caller to use what it just called.
|
|
1303
|
+
* Call after authentication, once `isPredeployed` is resolved.
|
|
1299
1304
|
*/
|
|
1300
|
-
private
|
|
1305
|
+
private warnPredeployedOnboardingMethod;
|
|
1301
1306
|
private readonly executionApiUrl;
|
|
1302
1307
|
private readonly bypassMinPortfolio;
|
|
1303
1308
|
/**
|
|
@@ -1541,6 +1546,11 @@ declare class ZyfaiSDK {
|
|
|
1541
1546
|
* from the user record before allowing a transfer to an undeployed pool Safe.
|
|
1542
1547
|
* @private
|
|
1543
1548
|
*/
|
|
1549
|
+
/**
|
|
1550
|
+
* Deploy the child Zyfai Safe and session for a nested (contract) owner.
|
|
1551
|
+
* @private
|
|
1552
|
+
*/
|
|
1553
|
+
private ensureNestedOwnerReadyForDeposit;
|
|
1544
1554
|
private hydrateSessionWallet;
|
|
1545
1555
|
/**
|
|
1546
1556
|
* Resolve the Safe address: backend-assigned for the connected predeployed
|
|
@@ -1568,9 +1578,10 @@ declare class ZyfaiSDK {
|
|
|
1568
1578
|
/**
|
|
1569
1579
|
* Deploy Safe Smart Wallet for a user
|
|
1570
1580
|
*
|
|
1571
|
-
*
|
|
1572
|
-
*
|
|
1573
|
-
* legacy
|
|
1581
|
+
* Not needed for a predeployed (pool) wallet: {@link ZyfaiSDK.sendDeposit} deploys the Safe and
|
|
1582
|
+
* enables the agent session on first deposit. Required for an owner that is not predeployed —
|
|
1583
|
+
* a contract owner such as a nested Safe, or a legacy self-deployed wallet — where `sendDeposit`
|
|
1584
|
+
* calls this method internally.
|
|
1574
1585
|
*
|
|
1575
1586
|
* @see {@link ZyfaiSDK.sendDeposit}
|
|
1576
1587
|
*
|
|
@@ -1584,11 +1595,11 @@ declare class ZyfaiSDK {
|
|
|
1584
1595
|
*
|
|
1585
1596
|
* @example
|
|
1586
1597
|
* ```typescript
|
|
1587
|
-
* // Preferred: sendDeposit handles
|
|
1598
|
+
* // Preferred: sendDeposit handles onboarding for every owner type
|
|
1588
1599
|
* const sent = await sdk.sendDeposit(userAddress, 8453, amount, "USDC");
|
|
1589
1600
|
* await sdk.waitForDepositCredit(sent.registration.id, 8453);
|
|
1590
1601
|
*
|
|
1591
|
-
* //
|
|
1602
|
+
* // Explicit: deploy with default conservative strategy
|
|
1592
1603
|
* await sdk.deploySafe(userAddress, 8453);
|
|
1593
1604
|
* ```
|
|
1594
1605
|
*/
|
|
@@ -1597,9 +1608,10 @@ declare class ZyfaiSDK {
|
|
|
1597
1608
|
* Create session key with auto-fetched configuration from Zyfai API
|
|
1598
1609
|
* This is the simplified method that automatically fetches session configuration
|
|
1599
1610
|
*
|
|
1600
|
-
*
|
|
1601
|
-
*
|
|
1602
|
-
*
|
|
1611
|
+
* Not needed for a predeployed (pool) wallet: its agent session is already enabled on-chain and
|
|
1612
|
+
* {@link ZyfaiSDK.sendDeposit} records it after the first deposit. Required for an owner that is
|
|
1613
|
+
* not predeployed — a contract owner such as a nested Safe, or a legacy self-deployed wallet —
|
|
1614
|
+
* where `sendDeposit` calls this method internally.
|
|
1603
1615
|
*
|
|
1604
1616
|
* @see {@link ZyfaiSDK.sendDeposit}
|
|
1605
1617
|
*
|
|
@@ -1611,11 +1623,11 @@ declare class ZyfaiSDK {
|
|
|
1611
1623
|
*
|
|
1612
1624
|
* @example
|
|
1613
1625
|
* ```typescript
|
|
1614
|
-
* // Preferred: sendDeposit handles session onboarding for
|
|
1626
|
+
* // Preferred: sendDeposit handles session onboarding for every owner type
|
|
1615
1627
|
* const sent = await sdk.sendDeposit(userAddress, 8453, amount, "USDC");
|
|
1616
1628
|
* await sdk.waitForDepositCredit(sent.registration.id, 8453);
|
|
1617
1629
|
*
|
|
1618
|
-
* //
|
|
1630
|
+
* // Explicit:
|
|
1619
1631
|
* const result = await sdk.createSessionKey(userAddress, 8453);
|
|
1620
1632
|
* ```
|
|
1621
1633
|
*/
|
|
@@ -1624,6 +1636,18 @@ declare class ZyfaiSDK {
|
|
|
1624
1636
|
* Internal method to sign session key
|
|
1625
1637
|
* @private
|
|
1626
1638
|
*/
|
|
1639
|
+
/**
|
|
1640
|
+
* A nested Safe owner signs one MultiChainSession covering every chain in the
|
|
1641
|
+
* session configuration, and the child validates that signature against the
|
|
1642
|
+
* owner through ERC-1271 on each of them. A chain where the owner has no code
|
|
1643
|
+
* would accept the signature nowhere, so refuse rather than sign it.
|
|
1644
|
+
*
|
|
1645
|
+
* The session list is not filtered here: the execution API rebuilds the digest
|
|
1646
|
+
* from its own configuration, so dropping a chain client-side would change the
|
|
1647
|
+
* hash and the signature would be rejected everywhere.
|
|
1648
|
+
* @private
|
|
1649
|
+
*/
|
|
1650
|
+
private assertOwnerSafeOnSessionChains;
|
|
1627
1651
|
private signSessionKey;
|
|
1628
1652
|
/**
|
|
1629
1653
|
* Patch the user's protocol selection on USDC, WETH, and EURC across all
|
|
@@ -3144,6 +3168,109 @@ declare class ZyfaiSDK {
|
|
|
3144
3168
|
subscribeToEvents(handlers: ZyfaiEventHandlers, filters?: ZyfaiEventFilters): () => void;
|
|
3145
3169
|
}
|
|
3146
3170
|
|
|
3171
|
+
/** Exact ordered v1 chain sessions used to construct a permission enable hash. */
|
|
3172
|
+
type V1ChainSessions = Parameters<typeof hashChainSessions>[0];
|
|
3173
|
+
/** Inputs for one chain, with all signing flags specified explicitly. */
|
|
3174
|
+
interface V1SessionEnableInput {
|
|
3175
|
+
account: Address$1;
|
|
3176
|
+
smartSession: Address$1;
|
|
3177
|
+
nonce: bigint;
|
|
3178
|
+
session: Session;
|
|
3179
|
+
permitGenericPolicy: boolean;
|
|
3180
|
+
permitAdminAccess: boolean;
|
|
3181
|
+
ignoreSecurityAttestations: boolean;
|
|
3182
|
+
}
|
|
3183
|
+
/** Construct the ordered payload from the same inputs used by the v1 signer. */
|
|
3184
|
+
declare function buildV1ChainSessions(inputs: V1SessionEnableInput[]): V1ChainSessions;
|
|
3185
|
+
/** Encode a complete payload as JSON with decimal strings for chain IDs and nonces. */
|
|
3186
|
+
declare function serializeV1ChainSessions(chainSessions: V1ChainSessions): string;
|
|
3187
|
+
/** Parse and validate a JSON payload produced by {@link serializeV1ChainSessions}. */
|
|
3188
|
+
declare function parseV1ChainSessions(json: string): V1ChainSessions;
|
|
3189
|
+
/**
|
|
3190
|
+
* Recompute the message shown by personal-sign wallets and its EIP-191 digest.
|
|
3191
|
+
*
|
|
3192
|
+
* @remarks
|
|
3193
|
+
* The input must be the complete ordered payload used by the signer. A matching
|
|
3194
|
+
* hash does not establish that the encoded permissions are safe or intended.
|
|
3195
|
+
*/
|
|
3196
|
+
declare function hashV1SessionEnable(chainSessions: V1ChainSessions): {
|
|
3197
|
+
permissionEnableHash: Hex$1;
|
|
3198
|
+
personalSignDigest: Hex$1;
|
|
3199
|
+
};
|
|
3200
|
+
|
|
3201
|
+
/** ERC-4337 EntryPoint v0.7, the one Zyfai smart accounts use. */
|
|
3202
|
+
declare const ENTRY_POINT_V07_ADDRESS: Address$1;
|
|
3203
|
+
/**
|
|
3204
|
+
* Unpacked ERC-4337 v0.7 user operation, as held by the app before signing.
|
|
3205
|
+
* The signature is not part of the hash and is ignored.
|
|
3206
|
+
*/
|
|
3207
|
+
interface VerifiableUserOperation {
|
|
3208
|
+
sender: Address$1;
|
|
3209
|
+
nonce: bigint;
|
|
3210
|
+
factory?: Address$1;
|
|
3211
|
+
factoryData?: Hex$1;
|
|
3212
|
+
callData: Hex$1;
|
|
3213
|
+
callGasLimit: bigint;
|
|
3214
|
+
verificationGasLimit: bigint;
|
|
3215
|
+
preVerificationGas: bigint;
|
|
3216
|
+
maxFeePerGas: bigint;
|
|
3217
|
+
maxPriorityFeePerGas: bigint;
|
|
3218
|
+
paymaster?: Address$1;
|
|
3219
|
+
paymasterVerificationGasLimit?: bigint;
|
|
3220
|
+
paymasterPostOpGasLimit?: bigint;
|
|
3221
|
+
paymasterData?: Hex$1;
|
|
3222
|
+
}
|
|
3223
|
+
/** One call found inside a user operation's `callData`, nested calls included. */
|
|
3224
|
+
interface DecodedUserOperationCall {
|
|
3225
|
+
target: Address$1;
|
|
3226
|
+
value: bigint;
|
|
3227
|
+
selector: Hex$1;
|
|
3228
|
+
/** Set when the selector is one of the account, module or session functions this helper knows. */
|
|
3229
|
+
functionName?: "setupSafe" | "execute" | "setRegistry" | "installModule" | "enableSessions";
|
|
3230
|
+
args?: readonly unknown[];
|
|
3231
|
+
/** Calls executed by `setupSafe` or `execute`. */
|
|
3232
|
+
calls?: DecodedUserOperationCall[];
|
|
3233
|
+
}
|
|
3234
|
+
/**
|
|
3235
|
+
* Parse a user operation exported as JSON by the app that asks for the signature.
|
|
3236
|
+
*
|
|
3237
|
+
* @remarks
|
|
3238
|
+
* Integer fields must be strings, decimal (`"71473"`) or hex (`"0x11731"`), so large nonces keep
|
|
3239
|
+
* their precision. Addresses and bytes are hex strings. Unknown fields, such as `signature`, are ignored.
|
|
3240
|
+
*
|
|
3241
|
+
* @param json - The user operation JSON.
|
|
3242
|
+
* @returns The parsed {@link VerifiableUserOperation}.
|
|
3243
|
+
* @throws `Invalid user operation JSON` when a field is missing or malformed.
|
|
3244
|
+
*/
|
|
3245
|
+
declare function parseUserOperationJson(json: string): VerifiableUserOperation;
|
|
3246
|
+
/**
|
|
3247
|
+
* Recompute the ERC-4337 v0.7 user operation hash, the 32 bytes a wallet shows as `message - 0x…`.
|
|
3248
|
+
*
|
|
3249
|
+
* @remarks
|
|
3250
|
+
* Offline and dependency-free: this is `EntryPoint.getUserOpHash` written out field by field, so a
|
|
3251
|
+
* reviewer can check it against the EntryPoint source. Zyfai's owner-signed operations (account
|
|
3252
|
+
* deployment, module install, session enable) are signed with `personal_sign` over this hash.
|
|
3253
|
+
*
|
|
3254
|
+
* @param userOp - The exact user operation the app will submit, after gas and paymaster fields are filled.
|
|
3255
|
+
* @param chainId - The chain the operation runs on, for example `8453` for Base.
|
|
3256
|
+
* @param entryPoint - Defaults to {@link ENTRY_POINT_V07_ADDRESS}.
|
|
3257
|
+
* @returns The user operation hash.
|
|
3258
|
+
*/
|
|
3259
|
+
declare function hashUserOperationV07(userOp: VerifiableUserOperation, chainId: number | bigint, entryPoint?: Address$1): Hex$1;
|
|
3260
|
+
/**
|
|
3261
|
+
* Decode what a user operation will execute on the smart account.
|
|
3262
|
+
*
|
|
3263
|
+
* @remarks
|
|
3264
|
+
* Understands the Safe7579 first-deploy `setupSafe`, ERC-7579 `execute` (single and batch),
|
|
3265
|
+
* `setRegistry`, `installModule` and Smart Sessions `enableSessions`. Any other call is returned
|
|
3266
|
+
* with its target, value and selector only: decode it yourself before signing. Decoding does not
|
|
3267
|
+
* judge whether a module, policy or session signer is safe.
|
|
3268
|
+
*
|
|
3269
|
+
* @param userOp - The user operation, as parsed by {@link parseUserOperationJson}.
|
|
3270
|
+
* @returns The top-level call on the account, with nested calls under `calls`.
|
|
3271
|
+
*/
|
|
3272
|
+
declare function decodeUserOperationCalls(userOp: Pick<VerifiableUserOperation, "sender" | "callData">): DecodedUserOperationCall;
|
|
3273
|
+
|
|
3147
3274
|
/**
|
|
3148
3275
|
* Bankr EIP-1193 Provider Adapter
|
|
3149
3276
|
*
|
|
@@ -3208,6 +3335,139 @@ declare function createBankrProvider(config: BankrProviderConfig): {
|
|
|
3208
3335
|
};
|
|
3209
3336
|
type BankrProvider = ReturnType<typeof createBankrProvider>;
|
|
3210
3337
|
|
|
3338
|
+
/**
|
|
3339
|
+
* EIP-1193 provider for a threshold-1 parent Safe.
|
|
3340
|
+
*
|
|
3341
|
+
* The owner is the wallet already connected by the integrator (viem wallet
|
|
3342
|
+
* client, local account, or EIP-1193 provider). A 2-of-4 Safe connects through
|
|
3343
|
+
* WalletConnect or the Safe App instead, because one signer cannot execute it.
|
|
3344
|
+
*/
|
|
3345
|
+
|
|
3346
|
+
/**
|
|
3347
|
+
* EIP-1193 wallet, such as an injected provider or WalletConnect.
|
|
3348
|
+
*/
|
|
3349
|
+
interface SafeOwnerEip1193 {
|
|
3350
|
+
/**
|
|
3351
|
+
* JSON-RPC request on the owner wallet.
|
|
3352
|
+
*
|
|
3353
|
+
* @param args - Method and optional params.
|
|
3354
|
+
* @returns The wallet's RPC result.
|
|
3355
|
+
*/
|
|
3356
|
+
request: (args: {
|
|
3357
|
+
method: string;
|
|
3358
|
+
params?: readonly unknown[] | undefined;
|
|
3359
|
+
}) => Promise<unknown>;
|
|
3360
|
+
}
|
|
3361
|
+
/**
|
|
3362
|
+
* Owner wallet used to sign Safe hashes and pay gas for `execTransaction`.
|
|
3363
|
+
* Pass the wallet the integrator already connected. A raw private key is not required.
|
|
3364
|
+
*/
|
|
3365
|
+
type SafeOwnerWallet = Account | WalletClient | SafeOwnerEip1193;
|
|
3366
|
+
/**
|
|
3367
|
+
* Arguments for {@link createSafeOwnerProvider}.
|
|
3368
|
+
*
|
|
3369
|
+
* @remarks
|
|
3370
|
+
* The Safe must be deployed on `chain` and its threshold must be 1. `owner` is
|
|
3371
|
+
* that owner's existing wallet. For a 2-of-4 treasury, connect the Safe itself
|
|
3372
|
+
* with WalletConnect or the Safe App and pass that provider to
|
|
3373
|
+
* {@link ZyfaiSDK.connectAccount}. One signer cannot execute a 2-of-4.
|
|
3374
|
+
*/
|
|
3375
|
+
interface SafeOwnerProviderConfig {
|
|
3376
|
+
/**
|
|
3377
|
+
* Parent Safe that becomes the connected account and the `userAddress` on
|
|
3378
|
+
* `sendDeposit` and `withdrawFunds`.
|
|
3379
|
+
*/
|
|
3380
|
+
safeAddress: Address$1;
|
|
3381
|
+
/**
|
|
3382
|
+
* Wallet of an owner of `safeAddress`. A viem wallet client, a local account,
|
|
3383
|
+
* or an EIP-1193 provider. This wallet pays gas when the threshold is 1.
|
|
3384
|
+
*/
|
|
3385
|
+
owner: SafeOwnerWallet;
|
|
3386
|
+
/** Chain where `safeAddress` has contract code. A Safe on Ethereum is not usable on Base. */
|
|
3387
|
+
chain: Chain;
|
|
3388
|
+
}
|
|
3389
|
+
/**
|
|
3390
|
+
* EIP-1193 provider whose accounts are the parent Safe, not the owner EOA.
|
|
3391
|
+
*
|
|
3392
|
+
* @remarks
|
|
3393
|
+
* `eth_requestAccounts` returns the Safe. `personal_sign` and
|
|
3394
|
+
* `eth_signTypedData_v4` produce signatures the Safe accepts via `isValidSignature`.
|
|
3395
|
+
* `eth_sendTransaction` calls `execTransaction` and waits for the receipt.
|
|
3396
|
+
* Pass this object to {@link ZyfaiSDK.connectAccount}.
|
|
3397
|
+
*/
|
|
3398
|
+
interface SafeOwnerProvider {
|
|
3399
|
+
/**
|
|
3400
|
+
* JSON-RPC entry used by viem when the SDK signs or sends.
|
|
3401
|
+
*
|
|
3402
|
+
* @param args - Method name (`eth_requestAccounts`, `personal_sign`, `eth_signTypedData_v4`, `eth_sendTransaction`) and optional params.
|
|
3403
|
+
* @returns Accounts, a signature, or the executed transaction hash.
|
|
3404
|
+
*/
|
|
3405
|
+
request: (args: {
|
|
3406
|
+
method: string;
|
|
3407
|
+
params?: readonly unknown[] | undefined;
|
|
3408
|
+
}) => Promise<unknown>;
|
|
3409
|
+
}
|
|
3410
|
+
/**
|
|
3411
|
+
* Create an EIP-1193 provider that signs and executes as a threshold-1 Safe.
|
|
3412
|
+
*
|
|
3413
|
+
* @remarks
|
|
3414
|
+
* Pass the provider to {@link ZyfaiSDK.connectAccount}. The address it returns
|
|
3415
|
+
* is the Safe. Pass that same address as `userAddress` on
|
|
3416
|
+
* {@link ZyfaiSDK.sendDeposit} and {@link ZyfaiSDK.withdrawFunds}. Withdrawals
|
|
3417
|
+
* settle to the Safe. The owner wallet pays gas for `execTransaction`.
|
|
3418
|
+
*
|
|
3419
|
+
* This helper is only for threshold 1. A 2-of-4 Safe (four owners, two
|
|
3420
|
+
* signatures required) must be connected with WalletConnect or the Safe App.
|
|
3421
|
+
* That wallet collects the second signature. `sendDeposit` then proposes the
|
|
3422
|
+
* transfer from the parent Safe and polls Safe Transaction Service until the
|
|
3423
|
+
* co-signers execute it. Do not pass one signer of a 2-of-4 to this function.
|
|
3424
|
+
*
|
|
3425
|
+
* @param config - Safe address, the owner wallet, and the chain where the Safe is deployed.
|
|
3426
|
+
* @returns A provider whose account is `config.safeAddress`.
|
|
3427
|
+
*
|
|
3428
|
+
* @throws If `safeAddress` is not an address, or `owner` is not a wallet client, account, or EIP-1193 provider.
|
|
3429
|
+
* @throws If the Safe has no code on `config.chain`. Choose the chain where the Safe was deployed.
|
|
3430
|
+
* @throws If the threshold is above 1. Connect a 2-of-4 through its wallet provider.
|
|
3431
|
+
* @throws If the wallet address is not an owner of the Safe.
|
|
3432
|
+
* @throws If `isValidSignature` rejects the owner signature.
|
|
3433
|
+
*
|
|
3434
|
+
* @example
|
|
3435
|
+
* ```typescript
|
|
3436
|
+
* import { createSafeOwnerProvider, ZyfaiSDK } from "@zyfai/sdk";
|
|
3437
|
+
* import { createWalletClient, custom } from "viem";
|
|
3438
|
+
* import { base } from "viem/chains";
|
|
3439
|
+
*
|
|
3440
|
+
* // Threshold-1 Safe. `owner` is the wallet the user already connected.
|
|
3441
|
+
* const owner = createWalletClient({
|
|
3442
|
+
* chain: base,
|
|
3443
|
+
* transport: custom(window.ethereum),
|
|
3444
|
+
* });
|
|
3445
|
+
* const provider = await createSafeOwnerProvider({
|
|
3446
|
+
* safeAddress: "0xParentSafe",
|
|
3447
|
+
* owner,
|
|
3448
|
+
* chain: base,
|
|
3449
|
+
* });
|
|
3450
|
+
* const sdk = new ZyfaiSDK({ apiKey: process.env.ZYFAI_API_KEY! });
|
|
3451
|
+
* const parent = await sdk.connectAccount(provider, 8453);
|
|
3452
|
+
* const sent = await sdk.sendDeposit(parent, 8453, "100000", "USDC");
|
|
3453
|
+
* await sdk.waitForDepositCredit(sent.registration.id, 8453);
|
|
3454
|
+
* ```
|
|
3455
|
+
*
|
|
3456
|
+
* @example
|
|
3457
|
+
* ```typescript
|
|
3458
|
+
* // 2-of-4 treasury. Do not use createSafeOwnerProvider.
|
|
3459
|
+
* // safeWalletProvider is WalletConnect or the Safe App, connected as the Safe.
|
|
3460
|
+
* const parent = await sdk.connectAccount(safeWalletProvider, 1);
|
|
3461
|
+
* const sent = await sdk.sendDeposit(parent, 1, "1000000", "USDC");
|
|
3462
|
+
* // Returns after another owner executes the Safe transaction.
|
|
3463
|
+
* await sdk.waitForDepositCredit(sent.registration.id, 1);
|
|
3464
|
+
* ```
|
|
3465
|
+
*
|
|
3466
|
+
* @see ZyfaiSDK.connectAccount
|
|
3467
|
+
* @see ZyfaiSDK.sendDeposit
|
|
3468
|
+
*/
|
|
3469
|
+
declare function createSafeOwnerProvider(config: SafeOwnerProviderConfig): Promise<SafeOwnerProvider>;
|
|
3470
|
+
|
|
3211
3471
|
/**
|
|
3212
3472
|
* Assets the agent manages for pause, resume, first-deposit protocol setup,
|
|
3213
3473
|
* and bulk strategy changes. Derived from {@link ASSET_CONFIGS} where
|
|
@@ -3363,4 +3623,4 @@ declare const ERC7579_LAUNCHPAD_ADDRESS: Address$1;
|
|
|
3363
3623
|
*/
|
|
3364
3624
|
declare const POOL_MODULE_ADDRESSES: readonly Address$1[];
|
|
3365
3625
|
|
|
3366
|
-
export { ALLOWED_HISTORY_DAYS, API_ENDPOINT, type APYPerStrategy, type APYPerStrategyResponse, type ActionData, type ActiveWallet, type ActiveWalletsResponse, type AddWalletToSdkResponse, type Address, type AllocationDetail, type AllowedHistoryDays, type ApyPosition, type AsyncWithdrawal, type AsyncWithdrawalStatus, type BackendEnvironment, type BankrProvider, type BankrProviderConfig, type BaseMerklCampaignId, type BestOpportunityDetails, type BestOpportunityResponse, type ChainConfig, type ChainPortfolio, type ChainTokenEarnings, type CustomizationConfig, type CustomizeBatchRequest, type CustomizeBatchResponse, DATA_API_BASE_URLS, DATA_API_ENDPOINT, DEFAULT_RELAY_SLIPPAGE_BPS, DEFAULT_TOKEN_ADDRESSES, type DailyApyEntry, type DailyApyHistoryPeriod, type DailyApyHistoryResponse, type DailyEarning, type DailyEarningsResponse, type DebankPortfolioResponse, type DepegEvent, type DeploySafeResponse, type DepositLifecycleResponse, type DepositLifecycleStatus, type DepositPositionOutcome, type DepositResponse, type DepositRoute, type DepositRouteInput, ERC7579_LAUNCHPAD_ADDRESS, type ERC7739Context, type ERC7739Data, EXECUTION_API_BASE_URLS, type ExcludedPool, type FirstPermitDepositStatus, type FirstTopupResponse, type GetAvailablePoolsOptions, type GetPoolsResponse, type GetSelectedPoolsResponse, type Hex, type HistoryAssetType, type HistoryEntry, type HistoryFeeData, type HistoryPosition, type HistoryRebalanceLog, type HistoryResponse, INTENT_EXECUTOR, INTENT_SMART_SESSIONS, LOCAL_DATA_API_BASE_URL, LOCAL_EXECUTION_API_BASE_URL, LOCAL_WS_URL, type LiquidityDropEvent, type LogDepositResponse, MAX_RELAY_SLIPPAGE_BPS, type MerklCampaign, type NewCollateralDetectedEvent, OWNABLE_VALIDATOR, type OnchainEarnings, type OnchainEarningsResponse, type OpportunitiesResponse, type Opportunity, type OpportunityPosition, POOL_MODULE_ADDRESSES, PROXY_EXECUTOR, type PolicyData, type Pool, type Portfolio, type PortfolioAssetBalance, type PortfolioByAssetType, type PortfolioByChain, type PortfolioDetailed, type PortfolioDetailedResponse, type PortfolioResponse, type PortfolioToken, type PositionSlot, type Protocol, type ProtocolsResponse, RELAY_SLIPPAGE_PRESETS_BPS, type RebalanceFrequencyResponse, type RegisterAgentResponse, type RzfiClaimResponse, type RzfiClaimTransaction, SAFE_7579_ADDRESS, type SDKConfig, SMART_SESSIONS_FALLBACK, SMART_SESSIONS_VALIDATOR, STAGING_DATA_API_BASE_URL, STAGING_EXECUTION_API_BASE_URL, STAGING_WS_URL, type SdkKeyTVLResponse, type SendDepositParams, type Session, type SessionKeyResponse, type SimulateBestPositionsParams, type SimulateBestPositionsResponse, type SimulateCalldataItem, type SimulatedPosition, type SmartWalletByEOAResponse, type SmartWalletResponse, type Strategy, type SupportedAsset, type SupportedChainId, type SwapDepositOrder, type SwapDepositParams, type SwapDepositQuote, type TVLResponse, type TokenApy, type TokenEarnings, type UpdateUserProfileRequest, type UpdateUserProfileResponse, type UserPosition, type UserSessionAuth, VAULT_ADDRESS, type VaultAsset, type VaultClaimResponse, type VaultDepositResponse, type VaultSharesResponse, type VaultWithdrawResponse, type VaultWithdrawStatusResponse, type VolumeAssetType, type VolumeResponse, WS_ENDPOINT, WS_URLS, type WaitForDepositCreditOptions, type WaitForDepositPositionOptions, type WaitForWithdrawCompleteOptions, type WaitForWithdrawSettlementOptions, type WalletTVL, type WithdrawAsyncLeg, type WithdrawLifecycleResponse, type WithdrawLifecycleStatus, type WithdrawResponse, type ZyfaiEventFilters, type ZyfaiEventHandlers, ZyfaiSDK, createBankrProvider, getChainConfig, getDataApiBaseUrl, getDefaultTokenAddress, getExecutionApiBaseUrl, getManagedAssets, getSupportedChainIds, getWsUrl, isSupportedChain, resolveDepositRoute, resolveRelaySlippageBps, type staleBalances };
|
|
3626
|
+
export { ALLOWED_HISTORY_DAYS, API_ENDPOINT, type APYPerStrategy, type APYPerStrategyResponse, type ActionData, type ActiveWallet, type ActiveWalletsResponse, type AddWalletToSdkResponse, type Address, type AllocationDetail, type AllowedHistoryDays, type ApyPosition, type AsyncWithdrawal, type AsyncWithdrawalStatus, type BackendEnvironment, type BankrProvider, type BankrProviderConfig, type BaseMerklCampaignId, type BestOpportunityDetails, type BestOpportunityResponse, type ChainConfig, type ChainPortfolio, type ChainTokenEarnings, type CustomizationConfig, type CustomizeBatchRequest, type CustomizeBatchResponse, DATA_API_BASE_URLS, DATA_API_ENDPOINT, DEFAULT_RELAY_SLIPPAGE_BPS, DEFAULT_TOKEN_ADDRESSES, type DailyApyEntry, type DailyApyHistoryPeriod, type DailyApyHistoryResponse, type DailyEarning, type DailyEarningsResponse, type DebankPortfolioResponse, type DecodedUserOperationCall, type DepegEvent, type DeploySafeResponse, type DepositLifecycleResponse, type DepositLifecycleStatus, type DepositPositionOutcome, type DepositResponse, type DepositRoute, type DepositRouteInput, ENTRY_POINT_V07_ADDRESS, ERC7579_LAUNCHPAD_ADDRESS, type ERC7739Context, type ERC7739Data, EXECUTION_API_BASE_URLS, type ExcludedPool, type FirstPermitDepositStatus, type FirstTopupResponse, type GetAvailablePoolsOptions, type GetPoolsResponse, type GetSelectedPoolsResponse, type Hex, type HistoryAssetType, type HistoryEntry, type HistoryFeeData, type HistoryPosition, type HistoryRebalanceLog, type HistoryResponse, INTENT_EXECUTOR, INTENT_SMART_SESSIONS, LOCAL_DATA_API_BASE_URL, LOCAL_EXECUTION_API_BASE_URL, LOCAL_WS_URL, type LiquidityDropEvent, type LogDepositResponse, MAX_RELAY_SLIPPAGE_BPS, type MerklCampaign, type NewCollateralDetectedEvent, OWNABLE_VALIDATOR, type OnchainEarnings, type OnchainEarningsResponse, type OpportunitiesResponse, type Opportunity, type OpportunityPosition, POOL_MODULE_ADDRESSES, PROXY_EXECUTOR, type PolicyData, type Pool, type Portfolio, type PortfolioAssetBalance, type PortfolioByAssetType, type PortfolioByChain, type PortfolioDetailed, type PortfolioDetailedResponse, type PortfolioResponse, type PortfolioToken, type PositionSlot, type Protocol, type ProtocolsResponse, RELAY_SLIPPAGE_PRESETS_BPS, type RebalanceFrequencyResponse, type RegisterAgentResponse, type RzfiClaimResponse, type RzfiClaimTransaction, SAFE_7579_ADDRESS, type SDKConfig, SMART_SESSIONS_FALLBACK, SMART_SESSIONS_VALIDATOR, STAGING_DATA_API_BASE_URL, STAGING_EXECUTION_API_BASE_URL, STAGING_WS_URL, type SafeOwnerEip1193, type SafeOwnerProvider, type SafeOwnerProviderConfig, type SafeOwnerWallet, type SdkKeyTVLResponse, type SendDepositParams, type Session, type SessionKeyResponse, type SimulateBestPositionsParams, type SimulateBestPositionsResponse, type SimulateCalldataItem, type SimulatedPosition, type SmartWalletByEOAResponse, type SmartWalletResponse, type Strategy, type SupportedAsset, type SupportedChainId, type SwapDepositOrder, type SwapDepositParams, type SwapDepositQuote, type TVLResponse, type TokenApy, type TokenEarnings, type UpdateUserProfileRequest, type UpdateUserProfileResponse, type UserPosition, type UserSessionAuth, type V1ChainSessions, type V1SessionEnableInput, VAULT_ADDRESS, type VaultAsset, type VaultClaimResponse, type VaultDepositResponse, type VaultSharesResponse, type VaultWithdrawResponse, type VaultWithdrawStatusResponse, type VerifiableUserOperation, type VolumeAssetType, type VolumeResponse, WS_ENDPOINT, WS_URLS, type WaitForDepositCreditOptions, type WaitForDepositPositionOptions, type WaitForWithdrawCompleteOptions, type WaitForWithdrawSettlementOptions, type WalletTVL, type WithdrawAsyncLeg, type WithdrawLifecycleResponse, type WithdrawLifecycleStatus, type WithdrawResponse, type ZyfaiEventFilters, type ZyfaiEventHandlers, ZyfaiSDK, buildV1ChainSessions, createBankrProvider, createSafeOwnerProvider, decodeUserOperationCalls, getChainConfig, getDataApiBaseUrl, getDefaultTokenAddress, getExecutionApiBaseUrl, getManagedAssets, getSupportedChainIds, getWsUrl, hashUserOperationV07, hashV1SessionEnable, isSupportedChain, parseUserOperationJson, parseV1ChainSessions, resolveDepositRoute, resolveRelaySlippageBps, serializeV1ChainSessions, type staleBalances };
|