@zyfai/sdk 0.1.19 → 0.1.20
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/dist/index.js +141 -17
- package/dist/index.mjs +150 -19
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -436,12 +436,98 @@ var import_pimlico = require("permissionless/clients/pimlico");
|
|
|
436
436
|
var import_accounts = require("permissionless/accounts");
|
|
437
437
|
var import_viem3 = require("viem");
|
|
438
438
|
var import_account_abstraction = require("viem/account-abstraction");
|
|
439
|
+
var import_actions = require("permissionless/actions");
|
|
440
|
+
var import_account_abstraction2 = require("viem/account-abstraction");
|
|
439
441
|
var SAFE_7579_ADDRESS = "0x7579EE8307284F293B1927136486880611F20002";
|
|
440
442
|
var ERC7579_LAUNCHPAD_ADDRESS = "0x7579011aB74c46090561ea277Ba79D510c6C00ff";
|
|
441
443
|
var ACCOUNT_SALTS = {
|
|
442
444
|
staging: "zyfai-staging",
|
|
443
445
|
production: "zyfai"
|
|
444
446
|
};
|
|
447
|
+
var MODULE_TYPE_IDS = {
|
|
448
|
+
validator: 1n,
|
|
449
|
+
executor: 2n,
|
|
450
|
+
fallback: 3n,
|
|
451
|
+
hook: 4n
|
|
452
|
+
};
|
|
453
|
+
var SMART_SESSIONS_FALLBACK = {
|
|
454
|
+
module: "0x12cae64c42f362e7d5a847c2d33388373f629177",
|
|
455
|
+
address: "0x12cae64c42f362e7d5a847c2d33388373f629177",
|
|
456
|
+
type: "fallback",
|
|
457
|
+
selector: (0, import_viem3.encodeAbiParameters)(
|
|
458
|
+
[{ name: "functionSignature", type: "bytes4" }],
|
|
459
|
+
["0x84b0196e"]
|
|
460
|
+
),
|
|
461
|
+
initData: "0x84b0196e00000000000000000000000000000000000000000000000000000000fe0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000"
|
|
462
|
+
};
|
|
463
|
+
var INTENT_EXECUTOR = {
|
|
464
|
+
address: "0x00000000005aD9ce1f5035FD62CA96CEf16AdAAF",
|
|
465
|
+
type: "executor",
|
|
466
|
+
initData: "0x"
|
|
467
|
+
};
|
|
468
|
+
var PROXY_EXECUTOR = {
|
|
469
|
+
address: "0xF659d30D4EB88B06A909F20839D8959Bd77d8790",
|
|
470
|
+
type: "executor",
|
|
471
|
+
initData: "0x"
|
|
472
|
+
};
|
|
473
|
+
var getModulesToInstall = (chainId) => {
|
|
474
|
+
const smartSessions = (0, import_module_sdk.getSmartSessionsValidator)({});
|
|
475
|
+
const accountLockerHook = (0, import_module_sdk.getAccountLockerHook)({ isOmniMode: true });
|
|
476
|
+
const accountLockerSourceExecutor = (0, import_module_sdk.getAccountLockerSourceExecutor)();
|
|
477
|
+
const accountLockerTargetExecutor = (0, import_module_sdk.getAccountLockerTargetExecutor)();
|
|
478
|
+
if (chainId === 9745) {
|
|
479
|
+
return [
|
|
480
|
+
smartSessions,
|
|
481
|
+
SMART_SESSIONS_FALLBACK,
|
|
482
|
+
INTENT_EXECUTOR,
|
|
483
|
+
PROXY_EXECUTOR
|
|
484
|
+
];
|
|
485
|
+
}
|
|
486
|
+
return [
|
|
487
|
+
smartSessions,
|
|
488
|
+
{
|
|
489
|
+
...accountLockerHook,
|
|
490
|
+
type: "executor"
|
|
491
|
+
},
|
|
492
|
+
accountLockerSourceExecutor,
|
|
493
|
+
accountLockerTargetExecutor,
|
|
494
|
+
SMART_SESSIONS_FALLBACK,
|
|
495
|
+
INTENT_EXECUTOR,
|
|
496
|
+
PROXY_EXECUTOR
|
|
497
|
+
];
|
|
498
|
+
};
|
|
499
|
+
var getInstallModuleCallData = (module2) => {
|
|
500
|
+
return (0, import_viem3.encodeFunctionData)({
|
|
501
|
+
abi: [
|
|
502
|
+
{
|
|
503
|
+
type: "function",
|
|
504
|
+
name: "installModule",
|
|
505
|
+
inputs: [
|
|
506
|
+
{
|
|
507
|
+
type: "uint256",
|
|
508
|
+
name: "moduleTypeId"
|
|
509
|
+
},
|
|
510
|
+
{
|
|
511
|
+
type: "address",
|
|
512
|
+
name: "module"
|
|
513
|
+
},
|
|
514
|
+
{
|
|
515
|
+
type: "bytes",
|
|
516
|
+
name: "initData"
|
|
517
|
+
}
|
|
518
|
+
],
|
|
519
|
+
outputs: [],
|
|
520
|
+
stateMutability: "nonpayable"
|
|
521
|
+
}
|
|
522
|
+
],
|
|
523
|
+
functionName: "installModule",
|
|
524
|
+
args: [
|
|
525
|
+
MODULE_TYPE_IDS[module2.type],
|
|
526
|
+
module2.address,
|
|
527
|
+
module2.initData || "0x"
|
|
528
|
+
]
|
|
529
|
+
});
|
|
530
|
+
};
|
|
445
531
|
var getSafeAccount = async (config) => {
|
|
446
532
|
const {
|
|
447
533
|
owner,
|
|
@@ -592,7 +678,7 @@ var getSmartAccountClient = async (config) => {
|
|
|
592
678
|
};
|
|
593
679
|
var deploySafeAccount = async (config) => {
|
|
594
680
|
try {
|
|
595
|
-
const { owner, publicClient } = config;
|
|
681
|
+
const { owner, publicClient, chainId } = config;
|
|
596
682
|
if (!owner || !owner.account) {
|
|
597
683
|
throw new Error(
|
|
598
684
|
"Wallet not connected. Please connect your wallet first."
|
|
@@ -606,24 +692,61 @@ var deploySafeAccount = async (config) => {
|
|
|
606
692
|
isDeployed: true
|
|
607
693
|
};
|
|
608
694
|
}
|
|
695
|
+
const modulesToInstall = getModulesToInstall(chainId);
|
|
696
|
+
const installCalls = modulesToInstall.map((module2) => ({
|
|
697
|
+
to: safeAddress,
|
|
698
|
+
data: getInstallModuleCallData(module2)
|
|
699
|
+
}));
|
|
609
700
|
const smartAccountClient = await getSmartAccountClient(config);
|
|
610
|
-
const
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
value: BigInt(0),
|
|
615
|
-
data: "0x"
|
|
616
|
-
}
|
|
617
|
-
]
|
|
701
|
+
const safeAccount = await getSafeAccount(config);
|
|
702
|
+
const ownableValidator = (0, import_module_sdk.getOwnableValidator)({
|
|
703
|
+
owners: [owner.account.address],
|
|
704
|
+
threshold: 1
|
|
618
705
|
});
|
|
619
|
-
const
|
|
620
|
-
|
|
706
|
+
const nonce = await (0, import_actions.getAccountNonce)(publicClient, {
|
|
707
|
+
address: safeAddress,
|
|
708
|
+
entryPointAddress: import_account_abstraction.entryPoint07Address,
|
|
709
|
+
key: BigInt(
|
|
710
|
+
(0, import_viem3.pad)(ownableValidator.address, {
|
|
711
|
+
dir: "right",
|
|
712
|
+
size: 24
|
|
713
|
+
}) || 0
|
|
714
|
+
)
|
|
621
715
|
});
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
};
|
|
716
|
+
const userOperation = await smartAccountClient.prepareUserOperation({
|
|
717
|
+
account: safeAccount,
|
|
718
|
+
calls: installCalls,
|
|
719
|
+
nonce
|
|
720
|
+
});
|
|
721
|
+
const userOpHashToSign = (0, import_account_abstraction2.getUserOperationHash)({
|
|
722
|
+
chainId,
|
|
723
|
+
entryPointAddress: import_account_abstraction.entryPoint07Address,
|
|
724
|
+
entryPointVersion: "0.7",
|
|
725
|
+
userOperation
|
|
726
|
+
});
|
|
727
|
+
if (!owner.account) {
|
|
728
|
+
throw new Error("Owner account is required for signing");
|
|
729
|
+
}
|
|
730
|
+
userOperation.signature = await owner.signMessage({
|
|
731
|
+
account: owner.account,
|
|
732
|
+
message: { raw: userOpHashToSign }
|
|
733
|
+
});
|
|
734
|
+
const userOpHash = await smartAccountClient.sendUserOperation(
|
|
735
|
+
userOperation
|
|
736
|
+
);
|
|
737
|
+
try {
|
|
738
|
+
const transaction = await smartAccountClient.waitForUserOperationReceipt({
|
|
739
|
+
hash: userOpHash
|
|
740
|
+
});
|
|
741
|
+
return {
|
|
742
|
+
safeAddress,
|
|
743
|
+
txHash: transaction.receipt.transactionHash,
|
|
744
|
+
isDeployed: true
|
|
745
|
+
};
|
|
746
|
+
} catch (error) {
|
|
747
|
+
console.error("Transaction failed:", error);
|
|
748
|
+
throw new Error("Failed to execute transaction");
|
|
749
|
+
}
|
|
627
750
|
} catch (error) {
|
|
628
751
|
throw new Error(
|
|
629
752
|
`Failed to deploy Safe account: ${error.message}`
|
|
@@ -1109,7 +1232,8 @@ var ZyfaiSDK = class {
|
|
|
1109
1232
|
chain: chainConfig.chain,
|
|
1110
1233
|
publicClient: chainConfig.publicClient,
|
|
1111
1234
|
bundlerUrl,
|
|
1112
|
-
environment: this.environment
|
|
1235
|
+
environment: this.environment,
|
|
1236
|
+
chainId
|
|
1113
1237
|
});
|
|
1114
1238
|
try {
|
|
1115
1239
|
await this.updateUserProfile({
|
package/dist/index.mjs
CHANGED
|
@@ -401,7 +401,11 @@ import {
|
|
|
401
401
|
getAccount,
|
|
402
402
|
getEnableSessionDetails,
|
|
403
403
|
getPermissionId,
|
|
404
|
-
getSessionNonce
|
|
404
|
+
getSessionNonce,
|
|
405
|
+
getSmartSessionsValidator,
|
|
406
|
+
getAccountLockerHook,
|
|
407
|
+
getAccountLockerSourceExecutor,
|
|
408
|
+
getAccountLockerTargetExecutor
|
|
405
409
|
} from "@rhinestone/module-sdk";
|
|
406
410
|
import { createSmartAccountClient } from "permissionless";
|
|
407
411
|
import { erc7579Actions } from "permissionless/actions/erc7579";
|
|
@@ -410,18 +414,107 @@ import { toSafeSmartAccount } from "permissionless/accounts";
|
|
|
410
414
|
import {
|
|
411
415
|
http as http2,
|
|
412
416
|
getAddress,
|
|
417
|
+
encodeFunctionData,
|
|
413
418
|
fromHex,
|
|
414
|
-
toHex
|
|
419
|
+
toHex,
|
|
420
|
+
encodeAbiParameters,
|
|
421
|
+
pad
|
|
415
422
|
} from "viem";
|
|
416
423
|
import {
|
|
417
424
|
entryPoint07Address
|
|
418
425
|
} from "viem/account-abstraction";
|
|
426
|
+
import { getAccountNonce } from "permissionless/actions";
|
|
427
|
+
import { getUserOperationHash } from "viem/account-abstraction";
|
|
419
428
|
var SAFE_7579_ADDRESS = "0x7579EE8307284F293B1927136486880611F20002";
|
|
420
429
|
var ERC7579_LAUNCHPAD_ADDRESS = "0x7579011aB74c46090561ea277Ba79D510c6C00ff";
|
|
421
430
|
var ACCOUNT_SALTS = {
|
|
422
431
|
staging: "zyfai-staging",
|
|
423
432
|
production: "zyfai"
|
|
424
433
|
};
|
|
434
|
+
var MODULE_TYPE_IDS = {
|
|
435
|
+
validator: 1n,
|
|
436
|
+
executor: 2n,
|
|
437
|
+
fallback: 3n,
|
|
438
|
+
hook: 4n
|
|
439
|
+
};
|
|
440
|
+
var SMART_SESSIONS_FALLBACK = {
|
|
441
|
+
module: "0x12cae64c42f362e7d5a847c2d33388373f629177",
|
|
442
|
+
address: "0x12cae64c42f362e7d5a847c2d33388373f629177",
|
|
443
|
+
type: "fallback",
|
|
444
|
+
selector: encodeAbiParameters(
|
|
445
|
+
[{ name: "functionSignature", type: "bytes4" }],
|
|
446
|
+
["0x84b0196e"]
|
|
447
|
+
),
|
|
448
|
+
initData: "0x84b0196e00000000000000000000000000000000000000000000000000000000fe0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000"
|
|
449
|
+
};
|
|
450
|
+
var INTENT_EXECUTOR = {
|
|
451
|
+
address: "0x00000000005aD9ce1f5035FD62CA96CEf16AdAAF",
|
|
452
|
+
type: "executor",
|
|
453
|
+
initData: "0x"
|
|
454
|
+
};
|
|
455
|
+
var PROXY_EXECUTOR = {
|
|
456
|
+
address: "0xF659d30D4EB88B06A909F20839D8959Bd77d8790",
|
|
457
|
+
type: "executor",
|
|
458
|
+
initData: "0x"
|
|
459
|
+
};
|
|
460
|
+
var getModulesToInstall = (chainId) => {
|
|
461
|
+
const smartSessions = getSmartSessionsValidator({});
|
|
462
|
+
const accountLockerHook = getAccountLockerHook({ isOmniMode: true });
|
|
463
|
+
const accountLockerSourceExecutor = getAccountLockerSourceExecutor();
|
|
464
|
+
const accountLockerTargetExecutor = getAccountLockerTargetExecutor();
|
|
465
|
+
if (chainId === 9745) {
|
|
466
|
+
return [
|
|
467
|
+
smartSessions,
|
|
468
|
+
SMART_SESSIONS_FALLBACK,
|
|
469
|
+
INTENT_EXECUTOR,
|
|
470
|
+
PROXY_EXECUTOR
|
|
471
|
+
];
|
|
472
|
+
}
|
|
473
|
+
return [
|
|
474
|
+
smartSessions,
|
|
475
|
+
{
|
|
476
|
+
...accountLockerHook,
|
|
477
|
+
type: "executor"
|
|
478
|
+
},
|
|
479
|
+
accountLockerSourceExecutor,
|
|
480
|
+
accountLockerTargetExecutor,
|
|
481
|
+
SMART_SESSIONS_FALLBACK,
|
|
482
|
+
INTENT_EXECUTOR,
|
|
483
|
+
PROXY_EXECUTOR
|
|
484
|
+
];
|
|
485
|
+
};
|
|
486
|
+
var getInstallModuleCallData = (module) => {
|
|
487
|
+
return encodeFunctionData({
|
|
488
|
+
abi: [
|
|
489
|
+
{
|
|
490
|
+
type: "function",
|
|
491
|
+
name: "installModule",
|
|
492
|
+
inputs: [
|
|
493
|
+
{
|
|
494
|
+
type: "uint256",
|
|
495
|
+
name: "moduleTypeId"
|
|
496
|
+
},
|
|
497
|
+
{
|
|
498
|
+
type: "address",
|
|
499
|
+
name: "module"
|
|
500
|
+
},
|
|
501
|
+
{
|
|
502
|
+
type: "bytes",
|
|
503
|
+
name: "initData"
|
|
504
|
+
}
|
|
505
|
+
],
|
|
506
|
+
outputs: [],
|
|
507
|
+
stateMutability: "nonpayable"
|
|
508
|
+
}
|
|
509
|
+
],
|
|
510
|
+
functionName: "installModule",
|
|
511
|
+
args: [
|
|
512
|
+
MODULE_TYPE_IDS[module.type],
|
|
513
|
+
module.address,
|
|
514
|
+
module.initData || "0x"
|
|
515
|
+
]
|
|
516
|
+
});
|
|
517
|
+
};
|
|
425
518
|
var getSafeAccount = async (config) => {
|
|
426
519
|
const {
|
|
427
520
|
owner,
|
|
@@ -572,7 +665,7 @@ var getSmartAccountClient = async (config) => {
|
|
|
572
665
|
};
|
|
573
666
|
var deploySafeAccount = async (config) => {
|
|
574
667
|
try {
|
|
575
|
-
const { owner, publicClient } = config;
|
|
668
|
+
const { owner, publicClient, chainId } = config;
|
|
576
669
|
if (!owner || !owner.account) {
|
|
577
670
|
throw new Error(
|
|
578
671
|
"Wallet not connected. Please connect your wallet first."
|
|
@@ -586,24 +679,61 @@ var deploySafeAccount = async (config) => {
|
|
|
586
679
|
isDeployed: true
|
|
587
680
|
};
|
|
588
681
|
}
|
|
682
|
+
const modulesToInstall = getModulesToInstall(chainId);
|
|
683
|
+
const installCalls = modulesToInstall.map((module) => ({
|
|
684
|
+
to: safeAddress,
|
|
685
|
+
data: getInstallModuleCallData(module)
|
|
686
|
+
}));
|
|
589
687
|
const smartAccountClient = await getSmartAccountClient(config);
|
|
590
|
-
const
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
value: BigInt(0),
|
|
595
|
-
data: "0x"
|
|
596
|
-
}
|
|
597
|
-
]
|
|
688
|
+
const safeAccount = await getSafeAccount(config);
|
|
689
|
+
const ownableValidator = getOwnableValidator({
|
|
690
|
+
owners: [owner.account.address],
|
|
691
|
+
threshold: 1
|
|
598
692
|
});
|
|
599
|
-
const
|
|
600
|
-
|
|
693
|
+
const nonce = await getAccountNonce(publicClient, {
|
|
694
|
+
address: safeAddress,
|
|
695
|
+
entryPointAddress: entryPoint07Address,
|
|
696
|
+
key: BigInt(
|
|
697
|
+
pad(ownableValidator.address, {
|
|
698
|
+
dir: "right",
|
|
699
|
+
size: 24
|
|
700
|
+
}) || 0
|
|
701
|
+
)
|
|
601
702
|
});
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
};
|
|
703
|
+
const userOperation = await smartAccountClient.prepareUserOperation({
|
|
704
|
+
account: safeAccount,
|
|
705
|
+
calls: installCalls,
|
|
706
|
+
nonce
|
|
707
|
+
});
|
|
708
|
+
const userOpHashToSign = getUserOperationHash({
|
|
709
|
+
chainId,
|
|
710
|
+
entryPointAddress: entryPoint07Address,
|
|
711
|
+
entryPointVersion: "0.7",
|
|
712
|
+
userOperation
|
|
713
|
+
});
|
|
714
|
+
if (!owner.account) {
|
|
715
|
+
throw new Error("Owner account is required for signing");
|
|
716
|
+
}
|
|
717
|
+
userOperation.signature = await owner.signMessage({
|
|
718
|
+
account: owner.account,
|
|
719
|
+
message: { raw: userOpHashToSign }
|
|
720
|
+
});
|
|
721
|
+
const userOpHash = await smartAccountClient.sendUserOperation(
|
|
722
|
+
userOperation
|
|
723
|
+
);
|
|
724
|
+
try {
|
|
725
|
+
const transaction = await smartAccountClient.waitForUserOperationReceipt({
|
|
726
|
+
hash: userOpHash
|
|
727
|
+
});
|
|
728
|
+
return {
|
|
729
|
+
safeAddress,
|
|
730
|
+
txHash: transaction.receipt.transactionHash,
|
|
731
|
+
isDeployed: true
|
|
732
|
+
};
|
|
733
|
+
} catch (error) {
|
|
734
|
+
console.error("Transaction failed:", error);
|
|
735
|
+
throw new Error("Failed to execute transaction");
|
|
736
|
+
}
|
|
607
737
|
} catch (error) {
|
|
608
738
|
throw new Error(
|
|
609
739
|
`Failed to deploy Safe account: ${error.message}`
|
|
@@ -1089,7 +1219,8 @@ var ZyfaiSDK = class {
|
|
|
1089
1219
|
chain: chainConfig.chain,
|
|
1090
1220
|
publicClient: chainConfig.publicClient,
|
|
1091
1221
|
bundlerUrl,
|
|
1092
|
-
environment: this.environment
|
|
1222
|
+
environment: this.environment,
|
|
1223
|
+
chainId
|
|
1093
1224
|
});
|
|
1094
1225
|
try {
|
|
1095
1226
|
await this.updateUserProfile({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zyfai/sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.20",
|
|
4
4
|
"description": "TypeScript SDK for ZyFAI Yield Optimization Engine - Deploy Safe smart wallets, manage session keys, and interact with DeFi protocols",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|