@zyfai/sdk 0.2.9 → 0.2.10
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.d.mts +35 -1
- package/dist/index.d.ts +35 -1
- package/dist/index.js +111 -21
- package/dist/index.mjs +94 -3
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -425,6 +425,12 @@ interface BestOpportunityResponse {
|
|
|
425
425
|
};
|
|
426
426
|
enabledChains?: number[];
|
|
427
427
|
}
|
|
428
|
+
interface RegisterAgentResponse {
|
|
429
|
+
success: boolean;
|
|
430
|
+
txHash: string;
|
|
431
|
+
chainId: number;
|
|
432
|
+
smartWallet: string;
|
|
433
|
+
}
|
|
428
434
|
interface PolicyData {
|
|
429
435
|
policy: Address;
|
|
430
436
|
initData: Hex;
|
|
@@ -1082,6 +1088,34 @@ declare class ZyfaiSDK {
|
|
|
1082
1088
|
* ```
|
|
1083
1089
|
*/
|
|
1084
1090
|
getBestOpportunity(walletAddress: Address, chainId: SupportedChainId): Promise<BestOpportunityResponse>;
|
|
1091
|
+
/**
|
|
1092
|
+
* Supported chain IDs for the Identity Registry (ERC-8004)
|
|
1093
|
+
*/
|
|
1094
|
+
private static readonly IDENTITY_REGISTRY_CHAIN_IDS;
|
|
1095
|
+
/**
|
|
1096
|
+
* Check if a chain ID supports the Identity Registry
|
|
1097
|
+
*/
|
|
1098
|
+
private isSupportedIdentityRegistryChain;
|
|
1099
|
+
/**
|
|
1100
|
+
* Register an agent on the Identity Registry (ERC-8004)
|
|
1101
|
+
*
|
|
1102
|
+
* Fetches a tokenUri from the Zyfai API for the given smart wallet,
|
|
1103
|
+
* then calls `register(tokenUri)` on the Identity Registry contract.
|
|
1104
|
+
*
|
|
1105
|
+
* @param smartWallet - The smart wallet address to register as an agent
|
|
1106
|
+
* @param chainId - Chain ID to register on (only Base 8453 and Arbitrum 42161 supported)
|
|
1107
|
+
* @returns Response with transaction hash and registration details
|
|
1108
|
+
*
|
|
1109
|
+
* @example
|
|
1110
|
+
* ```typescript
|
|
1111
|
+
* const sdk = new ZyfaiSDK({ apiKey: "your-api-key" });
|
|
1112
|
+
* await sdk.connectAccount(privateKey, 8453);
|
|
1113
|
+
*
|
|
1114
|
+
* const result = await sdk.registerAgentOnIdentityRegistry("0xSmartWallet", 8453);
|
|
1115
|
+
* console.log("Tx hash:", result.txHash);
|
|
1116
|
+
* ```
|
|
1117
|
+
*/
|
|
1118
|
+
registerAgentOnIdentityRegistry(smartWallet: string, chainId: SupportedChainId): Promise<RegisterAgentResponse>;
|
|
1085
1119
|
}
|
|
1086
1120
|
|
|
1087
|
-
export { type APYPerStrategy, type APYPerStrategyResponse, type ActionData, type ActiveWallet, type ActiveWalletsResponse, type AddWalletToSdkResponse, type Address, type BestOpportunityDetails, type BestOpportunityResponse, type ChainConfig, type ChainPortfolio, DEFAULT_TOKEN_ADDRESSES, type DailyApyEntry, type DailyApyHistoryResponse, type DailyEarning, type DailyEarningsResponse, type DebankPortfolioResponse, type DeploySafeResponse, type DepositResponse, type ERC7739Context, type ERC7739Data, type FirstTopupResponse, type Hex, type HistoryEntry, type HistoryPosition, type HistoryResponse, type OnchainEarnings, type OnchainEarningsResponse, type OpportunitiesResponse, type Opportunity, type OpportunityPosition, type PolicyData, type Pool, type PortfolioToken, type Position, type PositionSlot, type PositionsResponse, type Protocol, type ProtocolsResponse, type RebalanceFrequencyResponse, type SDKConfig, type SdkKeyTVLResponse, type Session, type SessionKeyResponse, type SmartWalletByEOAResponse, type SmartWalletResponse, type Strategy, type SupportedChainId, type TVLResponse, type UserDetails, type UserDetailsResponse, type VolumeResponse, type WalletTVL, type WithdrawResponse, ZyfaiSDK, getChainConfig, getDefaultTokenAddress, getSupportedChainIds, isSupportedChain };
|
|
1121
|
+
export { type APYPerStrategy, type APYPerStrategyResponse, type ActionData, type ActiveWallet, type ActiveWalletsResponse, type AddWalletToSdkResponse, type Address, type BestOpportunityDetails, type BestOpportunityResponse, type ChainConfig, type ChainPortfolio, DEFAULT_TOKEN_ADDRESSES, type DailyApyEntry, type DailyApyHistoryResponse, type DailyEarning, type DailyEarningsResponse, type DebankPortfolioResponse, type DeploySafeResponse, type DepositResponse, type ERC7739Context, type ERC7739Data, type FirstTopupResponse, type Hex, type HistoryEntry, type HistoryPosition, type HistoryResponse, type OnchainEarnings, type OnchainEarningsResponse, type OpportunitiesResponse, type Opportunity, type OpportunityPosition, type PolicyData, type Pool, type PortfolioToken, type Position, type PositionSlot, type PositionsResponse, type Protocol, type ProtocolsResponse, type RebalanceFrequencyResponse, type RegisterAgentResponse, type SDKConfig, type SdkKeyTVLResponse, type Session, type SessionKeyResponse, type SmartWalletByEOAResponse, type SmartWalletResponse, type Strategy, type SupportedChainId, type TVLResponse, type UserDetails, type UserDetailsResponse, type VolumeResponse, type WalletTVL, type WithdrawResponse, ZyfaiSDK, getChainConfig, getDefaultTokenAddress, getSupportedChainIds, isSupportedChain };
|
package/dist/index.d.ts
CHANGED
|
@@ -425,6 +425,12 @@ interface BestOpportunityResponse {
|
|
|
425
425
|
};
|
|
426
426
|
enabledChains?: number[];
|
|
427
427
|
}
|
|
428
|
+
interface RegisterAgentResponse {
|
|
429
|
+
success: boolean;
|
|
430
|
+
txHash: string;
|
|
431
|
+
chainId: number;
|
|
432
|
+
smartWallet: string;
|
|
433
|
+
}
|
|
428
434
|
interface PolicyData {
|
|
429
435
|
policy: Address;
|
|
430
436
|
initData: Hex;
|
|
@@ -1082,6 +1088,34 @@ declare class ZyfaiSDK {
|
|
|
1082
1088
|
* ```
|
|
1083
1089
|
*/
|
|
1084
1090
|
getBestOpportunity(walletAddress: Address, chainId: SupportedChainId): Promise<BestOpportunityResponse>;
|
|
1091
|
+
/**
|
|
1092
|
+
* Supported chain IDs for the Identity Registry (ERC-8004)
|
|
1093
|
+
*/
|
|
1094
|
+
private static readonly IDENTITY_REGISTRY_CHAIN_IDS;
|
|
1095
|
+
/**
|
|
1096
|
+
* Check if a chain ID supports the Identity Registry
|
|
1097
|
+
*/
|
|
1098
|
+
private isSupportedIdentityRegistryChain;
|
|
1099
|
+
/**
|
|
1100
|
+
* Register an agent on the Identity Registry (ERC-8004)
|
|
1101
|
+
*
|
|
1102
|
+
* Fetches a tokenUri from the Zyfai API for the given smart wallet,
|
|
1103
|
+
* then calls `register(tokenUri)` on the Identity Registry contract.
|
|
1104
|
+
*
|
|
1105
|
+
* @param smartWallet - The smart wallet address to register as an agent
|
|
1106
|
+
* @param chainId - Chain ID to register on (only Base 8453 and Arbitrum 42161 supported)
|
|
1107
|
+
* @returns Response with transaction hash and registration details
|
|
1108
|
+
*
|
|
1109
|
+
* @example
|
|
1110
|
+
* ```typescript
|
|
1111
|
+
* const sdk = new ZyfaiSDK({ apiKey: "your-api-key" });
|
|
1112
|
+
* await sdk.connectAccount(privateKey, 8453);
|
|
1113
|
+
*
|
|
1114
|
+
* const result = await sdk.registerAgentOnIdentityRegistry("0xSmartWallet", 8453);
|
|
1115
|
+
* console.log("Tx hash:", result.txHash);
|
|
1116
|
+
* ```
|
|
1117
|
+
*/
|
|
1118
|
+
registerAgentOnIdentityRegistry(smartWallet: string, chainId: SupportedChainId): Promise<RegisterAgentResponse>;
|
|
1085
1119
|
}
|
|
1086
1120
|
|
|
1087
|
-
export { type APYPerStrategy, type APYPerStrategyResponse, type ActionData, type ActiveWallet, type ActiveWalletsResponse, type AddWalletToSdkResponse, type Address, type BestOpportunityDetails, type BestOpportunityResponse, type ChainConfig, type ChainPortfolio, DEFAULT_TOKEN_ADDRESSES, type DailyApyEntry, type DailyApyHistoryResponse, type DailyEarning, type DailyEarningsResponse, type DebankPortfolioResponse, type DeploySafeResponse, type DepositResponse, type ERC7739Context, type ERC7739Data, type FirstTopupResponse, type Hex, type HistoryEntry, type HistoryPosition, type HistoryResponse, type OnchainEarnings, type OnchainEarningsResponse, type OpportunitiesResponse, type Opportunity, type OpportunityPosition, type PolicyData, type Pool, type PortfolioToken, type Position, type PositionSlot, type PositionsResponse, type Protocol, type ProtocolsResponse, type RebalanceFrequencyResponse, type SDKConfig, type SdkKeyTVLResponse, type Session, type SessionKeyResponse, type SmartWalletByEOAResponse, type SmartWalletResponse, type Strategy, type SupportedChainId, type TVLResponse, type UserDetails, type UserDetailsResponse, type VolumeResponse, type WalletTVL, type WithdrawResponse, ZyfaiSDK, getChainConfig, getDefaultTokenAddress, getSupportedChainIds, isSupportedChain };
|
|
1121
|
+
export { type APYPerStrategy, type APYPerStrategyResponse, type ActionData, type ActiveWallet, type ActiveWalletsResponse, type AddWalletToSdkResponse, type Address, type BestOpportunityDetails, type BestOpportunityResponse, type ChainConfig, type ChainPortfolio, DEFAULT_TOKEN_ADDRESSES, type DailyApyEntry, type DailyApyHistoryResponse, type DailyEarning, type DailyEarningsResponse, type DebankPortfolioResponse, type DeploySafeResponse, type DepositResponse, type ERC7739Context, type ERC7739Data, type FirstTopupResponse, type Hex, type HistoryEntry, type HistoryPosition, type HistoryResponse, type OnchainEarnings, type OnchainEarningsResponse, type OpportunitiesResponse, type Opportunity, type OpportunityPosition, type PolicyData, type Pool, type PortfolioToken, type Position, type PositionSlot, type PositionsResponse, type Protocol, type ProtocolsResponse, type RebalanceFrequencyResponse, type RegisterAgentResponse, type SDKConfig, type SdkKeyTVLResponse, type Session, type SessionKeyResponse, type SmartWalletByEOAResponse, type SmartWalletResponse, type Strategy, type SupportedChainId, type TVLResponse, type UserDetails, type UserDetailsResponse, type VolumeResponse, type WalletTVL, type WithdrawResponse, ZyfaiSDK, getChainConfig, getDefaultTokenAddress, getSupportedChainIds, isSupportedChain };
|
package/dist/index.js
CHANGED
|
@@ -76,7 +76,9 @@ var ENDPOINTS = {
|
|
|
76
76
|
SDK_ALLOWED_WALLETS: "/data/sdk-allowed-wallets",
|
|
77
77
|
SDK_TVL: "/data/sdk-tvl",
|
|
78
78
|
// Best Opportunity
|
|
79
|
-
BEST_OPPORTUNITY: (walletAddress, chainId) => `/data/best-opportunity?walletAddress=${walletAddress}&chainId=${chainId}
|
|
79
|
+
BEST_OPPORTUNITY: (walletAddress, chainId) => `/data/best-opportunity?walletAddress=${walletAddress}&chainId=${chainId}`,
|
|
80
|
+
// Agent Identity Registry
|
|
81
|
+
AGENT_TOKEN_URI: "/users/me/agent-token-uri"
|
|
80
82
|
};
|
|
81
83
|
var DATA_ENDPOINTS = {
|
|
82
84
|
// User Initialization
|
|
@@ -288,6 +290,7 @@ var HttpClient = class {
|
|
|
288
290
|
};
|
|
289
291
|
|
|
290
292
|
// src/config/abis.ts
|
|
293
|
+
var import_viem = require("viem");
|
|
291
294
|
var ERC20_ABI = [
|
|
292
295
|
{
|
|
293
296
|
name: "transfer",
|
|
@@ -355,16 +358,22 @@ var ERC20_ABI = [
|
|
|
355
358
|
outputs: [{ name: "", type: "uint256" }]
|
|
356
359
|
}
|
|
357
360
|
];
|
|
361
|
+
var IDENTITY_REGISTRY_ABI = (0, import_viem.parseAbi)([
|
|
362
|
+
"function register() external returns (uint256 agentId)",
|
|
363
|
+
"function register(string tokenUri) external returns (uint256 agentId)",
|
|
364
|
+
"function register(string tokenUri, (string key, bytes value)[] metadata) external returns (uint256 agentId)"
|
|
365
|
+
]);
|
|
366
|
+
var IDENTITY_REGISTRY_ADDRESS = "0x8004A169FB4a3325136EB29fA0ceB6D2e539a432";
|
|
358
367
|
|
|
359
368
|
// src/core/ZyfaiSDK.ts
|
|
360
369
|
var import_accounts2 = require("viem/accounts");
|
|
361
|
-
var
|
|
370
|
+
var import_viem5 = require("viem");
|
|
362
371
|
|
|
363
372
|
// src/config/chains.ts
|
|
364
|
-
var import_viem = require("viem");
|
|
365
|
-
var import_chains = require("viem/chains");
|
|
366
373
|
var import_viem2 = require("viem");
|
|
367
|
-
var
|
|
374
|
+
var import_chains = require("viem/chains");
|
|
375
|
+
var import_viem3 = require("viem");
|
|
376
|
+
var plasma = (0, import_viem3.defineChain)({
|
|
368
377
|
id: 9745,
|
|
369
378
|
name: "Plasma",
|
|
370
379
|
nativeCurrency: {
|
|
@@ -417,9 +426,9 @@ var getChainConfig = (chainId, rpcUrls) => {
|
|
|
417
426
|
throw new Error(`Unsupported chain ID: ${chainId}`);
|
|
418
427
|
}
|
|
419
428
|
const rpcUrl = rpcUrls && rpcUrls[chainId] || DEFAULT_RPC_URLS[chainId];
|
|
420
|
-
const publicClient = (0,
|
|
429
|
+
const publicClient = (0, import_viem2.createPublicClient)({
|
|
421
430
|
chain,
|
|
422
|
-
transport: (0,
|
|
431
|
+
transport: (0, import_viem2.http)(rpcUrl)
|
|
423
432
|
});
|
|
424
433
|
return {
|
|
425
434
|
chain,
|
|
@@ -437,7 +446,7 @@ var getSupportedChainIds = () => {
|
|
|
437
446
|
// src/utils/safe-account.ts
|
|
438
447
|
var import_module_sdk = require("@rhinestone/module-sdk");
|
|
439
448
|
var import_accounts = require("permissionless/accounts");
|
|
440
|
-
var
|
|
449
|
+
var import_viem4 = require("viem");
|
|
441
450
|
var import_account_abstraction = require("viem/account-abstraction");
|
|
442
451
|
var SAFE_7579_ADDRESS = "0x7579EE8307284F293B1927136486880611F20002";
|
|
443
452
|
var ERC7579_LAUNCHPAD_ADDRESS = "0x7579011aB74c46090561ea277Ba79D510c6C00ff";
|
|
@@ -447,12 +456,12 @@ var getSafeAccount = async (config) => {
|
|
|
447
456
|
if (!safeOwnerAddress) {
|
|
448
457
|
throw new Error("Safe owner address is required");
|
|
449
458
|
}
|
|
450
|
-
const formattedOwnerAddress = (0,
|
|
459
|
+
const formattedOwnerAddress = (0, import_viem4.getAddress)(safeOwnerAddress);
|
|
451
460
|
const ownableValidator = (0, import_module_sdk.getOwnableValidator)({
|
|
452
461
|
owners: [formattedOwnerAddress],
|
|
453
462
|
threshold: 1
|
|
454
463
|
});
|
|
455
|
-
const saltHex = (0,
|
|
464
|
+
const saltHex = (0, import_viem4.fromHex)((0, import_viem4.toHex)(ACCOUNT_SALT), "bigint");
|
|
456
465
|
const tempOwner = {
|
|
457
466
|
address: formattedOwnerAddress,
|
|
458
467
|
type: "json-rpc"
|
|
@@ -663,7 +672,7 @@ function convertStrategiesToPublic(array) {
|
|
|
663
672
|
|
|
664
673
|
// src/core/ZyfaiSDK.ts
|
|
665
674
|
var import_siwe = require("siwe");
|
|
666
|
-
var
|
|
675
|
+
var _ZyfaiSDK = class _ZyfaiSDK {
|
|
667
676
|
constructor(config) {
|
|
668
677
|
this.signer = null;
|
|
669
678
|
this.walletClient = null;
|
|
@@ -692,7 +701,7 @@ var ZyfaiSDK = class {
|
|
|
692
701
|
return;
|
|
693
702
|
}
|
|
694
703
|
const walletClient = this.getWalletClient();
|
|
695
|
-
const userAddress = (0,
|
|
704
|
+
const userAddress = (0, import_viem5.getAddress)(walletClient.account.address);
|
|
696
705
|
const chainId = this.currentChainId || walletClient.chain?.id || 8453;
|
|
697
706
|
const challengeResponse = await this.httpClient.post(ENDPOINTS.AUTH_CHALLENGE, {});
|
|
698
707
|
let uri;
|
|
@@ -971,10 +980,10 @@ var ZyfaiSDK = class {
|
|
|
971
980
|
this.walletClient.chain?.id || 8453,
|
|
972
981
|
this.rpcUrls
|
|
973
982
|
);
|
|
974
|
-
this.walletClient = (0,
|
|
983
|
+
this.walletClient = (0, import_viem5.createWalletClient)({
|
|
975
984
|
account: newAddress,
|
|
976
985
|
chain: chainConfig.chain,
|
|
977
|
-
transport: (0,
|
|
986
|
+
transport: (0, import_viem5.custom)(this.currentProvider)
|
|
978
987
|
});
|
|
979
988
|
this.currentChainId = this.walletClient.chain?.id || null;
|
|
980
989
|
try {
|
|
@@ -1026,10 +1035,10 @@ var ZyfaiSDK = class {
|
|
|
1026
1035
|
}
|
|
1027
1036
|
this.signer = (0, import_accounts2.privateKeyToAccount)(privateKey);
|
|
1028
1037
|
this.currentChainId = chainId;
|
|
1029
|
-
this.walletClient = (0,
|
|
1038
|
+
this.walletClient = (0, import_viem5.createWalletClient)({
|
|
1030
1039
|
account: this.signer,
|
|
1031
1040
|
chain: chainConfig.chain,
|
|
1032
|
-
transport: (0,
|
|
1041
|
+
transport: (0, import_viem5.http)(chainConfig.rpcUrl)
|
|
1033
1042
|
});
|
|
1034
1043
|
connectedAddress = this.signer.address;
|
|
1035
1044
|
this.currentProvider = null;
|
|
@@ -1047,10 +1056,10 @@ var ZyfaiSDK = class {
|
|
|
1047
1056
|
if (!accounts || accounts.length === 0) {
|
|
1048
1057
|
throw new Error("No accounts found in wallet provider");
|
|
1049
1058
|
}
|
|
1050
|
-
this.walletClient = (0,
|
|
1059
|
+
this.walletClient = (0, import_viem5.createWalletClient)({
|
|
1051
1060
|
account: accounts[0],
|
|
1052
1061
|
chain: chainConfig.chain,
|
|
1053
|
-
transport: (0,
|
|
1062
|
+
transport: (0, import_viem5.custom)(provider)
|
|
1054
1063
|
});
|
|
1055
1064
|
connectedAddress = accounts[0];
|
|
1056
1065
|
this.currentProvider = provider;
|
|
@@ -1059,7 +1068,7 @@ var ZyfaiSDK = class {
|
|
|
1059
1068
|
provider.on("accountsChanged", this.handleAccountsChanged.bind(this));
|
|
1060
1069
|
}
|
|
1061
1070
|
} else if (provider.account && provider.transport) {
|
|
1062
|
-
this.walletClient = (0,
|
|
1071
|
+
this.walletClient = (0, import_viem5.createWalletClient)({
|
|
1063
1072
|
account: provider.account,
|
|
1064
1073
|
chain: chainConfig.chain,
|
|
1065
1074
|
transport: provider.transport
|
|
@@ -1112,10 +1121,10 @@ var ZyfaiSDK = class {
|
|
|
1112
1121
|
targetChainId,
|
|
1113
1122
|
this.rpcUrls
|
|
1114
1123
|
);
|
|
1115
|
-
return (0,
|
|
1124
|
+
return (0, import_viem5.createWalletClient)({
|
|
1116
1125
|
account: this.signer,
|
|
1117
1126
|
chain: targetChainConfig.chain,
|
|
1118
|
-
transport: (0,
|
|
1127
|
+
transport: (0, import_viem5.http)(targetChainConfig.rpcUrl)
|
|
1119
1128
|
});
|
|
1120
1129
|
} else {
|
|
1121
1130
|
if (!this.walletClient) {
|
|
@@ -2424,7 +2433,88 @@ var ZyfaiSDK = class {
|
|
|
2424
2433
|
);
|
|
2425
2434
|
}
|
|
2426
2435
|
}
|
|
2436
|
+
/**
|
|
2437
|
+
* Check if a chain ID supports the Identity Registry
|
|
2438
|
+
*/
|
|
2439
|
+
isSupportedIdentityRegistryChain(chainId) {
|
|
2440
|
+
return _ZyfaiSDK.IDENTITY_REGISTRY_CHAIN_IDS.includes(chainId);
|
|
2441
|
+
}
|
|
2442
|
+
/**
|
|
2443
|
+
* Register an agent on the Identity Registry (ERC-8004)
|
|
2444
|
+
*
|
|
2445
|
+
* Fetches a tokenUri from the Zyfai API for the given smart wallet,
|
|
2446
|
+
* then calls `register(tokenUri)` on the Identity Registry contract.
|
|
2447
|
+
*
|
|
2448
|
+
* @param smartWallet - The smart wallet address to register as an agent
|
|
2449
|
+
* @param chainId - Chain ID to register on (only Base 8453 and Arbitrum 42161 supported)
|
|
2450
|
+
* @returns Response with transaction hash and registration details
|
|
2451
|
+
*
|
|
2452
|
+
* @example
|
|
2453
|
+
* ```typescript
|
|
2454
|
+
* const sdk = new ZyfaiSDK({ apiKey: "your-api-key" });
|
|
2455
|
+
* await sdk.connectAccount(privateKey, 8453);
|
|
2456
|
+
*
|
|
2457
|
+
* const result = await sdk.registerAgentOnIdentityRegistry("0xSmartWallet", 8453);
|
|
2458
|
+
* console.log("Tx hash:", result.txHash);
|
|
2459
|
+
* ```
|
|
2460
|
+
*/
|
|
2461
|
+
async registerAgentOnIdentityRegistry(smartWallet, chainId) {
|
|
2462
|
+
if (!smartWallet) {
|
|
2463
|
+
throw new Error("Smart wallet address is required");
|
|
2464
|
+
}
|
|
2465
|
+
if (!this.isSupportedIdentityRegistryChain(chainId)) {
|
|
2466
|
+
throw new Error(
|
|
2467
|
+
`Chain ${chainId} is not supported for Identity Registry. Supported chains: Base (8453), Arbitrum (42161)`
|
|
2468
|
+
);
|
|
2469
|
+
}
|
|
2470
|
+
try {
|
|
2471
|
+
const tokenUriResponse = await this.httpClient.post(
|
|
2472
|
+
ENDPOINTS.AGENT_TOKEN_URI,
|
|
2473
|
+
{ smartWallet }
|
|
2474
|
+
);
|
|
2475
|
+
if (!tokenUriResponse.tokenUri) {
|
|
2476
|
+
throw new Error("API did not return a tokenUri");
|
|
2477
|
+
}
|
|
2478
|
+
const callData = (0, import_viem5.encodeFunctionData)({
|
|
2479
|
+
abi: IDENTITY_REGISTRY_ABI,
|
|
2480
|
+
functionName: "register",
|
|
2481
|
+
args: [tokenUriResponse.tokenUri]
|
|
2482
|
+
});
|
|
2483
|
+
const walletClient = this.getWalletClient(chainId);
|
|
2484
|
+
const chainConfig = getChainConfig(chainId, this.rpcUrls);
|
|
2485
|
+
const txHash = await walletClient.sendTransaction({
|
|
2486
|
+
to: IDENTITY_REGISTRY_ADDRESS,
|
|
2487
|
+
data: callData,
|
|
2488
|
+
chain: chainConfig.chain,
|
|
2489
|
+
account: walletClient.account
|
|
2490
|
+
});
|
|
2491
|
+
const receipt = await chainConfig.publicClient.waitForTransactionReceipt({
|
|
2492
|
+
hash: txHash
|
|
2493
|
+
});
|
|
2494
|
+
if (receipt.status !== "success") {
|
|
2495
|
+
throw new Error("Identity Registry registration transaction failed");
|
|
2496
|
+
}
|
|
2497
|
+
return {
|
|
2498
|
+
success: true,
|
|
2499
|
+
txHash,
|
|
2500
|
+
chainId,
|
|
2501
|
+
smartWallet
|
|
2502
|
+
};
|
|
2503
|
+
} catch (error) {
|
|
2504
|
+
throw new Error(
|
|
2505
|
+
`Failed to register agent on Identity Registry: ${error.message}`
|
|
2506
|
+
);
|
|
2507
|
+
}
|
|
2508
|
+
}
|
|
2427
2509
|
};
|
|
2510
|
+
// ============================================================================
|
|
2511
|
+
// Agent Identity Registry
|
|
2512
|
+
// ============================================================================
|
|
2513
|
+
/**
|
|
2514
|
+
* Supported chain IDs for the Identity Registry (ERC-8004)
|
|
2515
|
+
*/
|
|
2516
|
+
_ZyfaiSDK.IDENTITY_REGISTRY_CHAIN_IDS = [8453, 42161];
|
|
2517
|
+
var ZyfaiSDK = _ZyfaiSDK;
|
|
2428
2518
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2429
2519
|
0 && (module.exports = {
|
|
2430
2520
|
DEFAULT_TOKEN_ADDRESSES,
|
package/dist/index.mjs
CHANGED
|
@@ -35,7 +35,9 @@ var ENDPOINTS = {
|
|
|
35
35
|
SDK_ALLOWED_WALLETS: "/data/sdk-allowed-wallets",
|
|
36
36
|
SDK_TVL: "/data/sdk-tvl",
|
|
37
37
|
// Best Opportunity
|
|
38
|
-
BEST_OPPORTUNITY: (walletAddress, chainId) => `/data/best-opportunity?walletAddress=${walletAddress}&chainId=${chainId}
|
|
38
|
+
BEST_OPPORTUNITY: (walletAddress, chainId) => `/data/best-opportunity?walletAddress=${walletAddress}&chainId=${chainId}`,
|
|
39
|
+
// Agent Identity Registry
|
|
40
|
+
AGENT_TOKEN_URI: "/users/me/agent-token-uri"
|
|
39
41
|
};
|
|
40
42
|
var DATA_ENDPOINTS = {
|
|
41
43
|
// User Initialization
|
|
@@ -247,6 +249,7 @@ var HttpClient = class {
|
|
|
247
249
|
};
|
|
248
250
|
|
|
249
251
|
// src/config/abis.ts
|
|
252
|
+
import { parseAbi } from "viem";
|
|
250
253
|
var ERC20_ABI = [
|
|
251
254
|
{
|
|
252
255
|
name: "transfer",
|
|
@@ -314,6 +317,12 @@ var ERC20_ABI = [
|
|
|
314
317
|
outputs: [{ name: "", type: "uint256" }]
|
|
315
318
|
}
|
|
316
319
|
];
|
|
320
|
+
var IDENTITY_REGISTRY_ABI = parseAbi([
|
|
321
|
+
"function register() external returns (uint256 agentId)",
|
|
322
|
+
"function register(string tokenUri) external returns (uint256 agentId)",
|
|
323
|
+
"function register(string tokenUri, (string key, bytes value)[] metadata) external returns (uint256 agentId)"
|
|
324
|
+
]);
|
|
325
|
+
var IDENTITY_REGISTRY_ADDRESS = "0x8004A169FB4a3325136EB29fA0ceB6D2e539a432";
|
|
317
326
|
|
|
318
327
|
// src/core/ZyfaiSDK.ts
|
|
319
328
|
import { privateKeyToAccount } from "viem/accounts";
|
|
@@ -321,7 +330,8 @@ import {
|
|
|
321
330
|
createWalletClient,
|
|
322
331
|
custom,
|
|
323
332
|
http as http2,
|
|
324
|
-
getAddress as getAddress2
|
|
333
|
+
getAddress as getAddress2,
|
|
334
|
+
encodeFunctionData
|
|
325
335
|
} from "viem";
|
|
326
336
|
|
|
327
337
|
// src/config/chains.ts
|
|
@@ -640,7 +650,7 @@ function convertStrategiesToPublic(array) {
|
|
|
640
650
|
|
|
641
651
|
// src/core/ZyfaiSDK.ts
|
|
642
652
|
import { SiweMessage } from "siwe";
|
|
643
|
-
var
|
|
653
|
+
var _ZyfaiSDK = class _ZyfaiSDK {
|
|
644
654
|
constructor(config) {
|
|
645
655
|
this.signer = null;
|
|
646
656
|
this.walletClient = null;
|
|
@@ -2401,7 +2411,88 @@ var ZyfaiSDK = class {
|
|
|
2401
2411
|
);
|
|
2402
2412
|
}
|
|
2403
2413
|
}
|
|
2414
|
+
/**
|
|
2415
|
+
* Check if a chain ID supports the Identity Registry
|
|
2416
|
+
*/
|
|
2417
|
+
isSupportedIdentityRegistryChain(chainId) {
|
|
2418
|
+
return _ZyfaiSDK.IDENTITY_REGISTRY_CHAIN_IDS.includes(chainId);
|
|
2419
|
+
}
|
|
2420
|
+
/**
|
|
2421
|
+
* Register an agent on the Identity Registry (ERC-8004)
|
|
2422
|
+
*
|
|
2423
|
+
* Fetches a tokenUri from the Zyfai API for the given smart wallet,
|
|
2424
|
+
* then calls `register(tokenUri)` on the Identity Registry contract.
|
|
2425
|
+
*
|
|
2426
|
+
* @param smartWallet - The smart wallet address to register as an agent
|
|
2427
|
+
* @param chainId - Chain ID to register on (only Base 8453 and Arbitrum 42161 supported)
|
|
2428
|
+
* @returns Response with transaction hash and registration details
|
|
2429
|
+
*
|
|
2430
|
+
* @example
|
|
2431
|
+
* ```typescript
|
|
2432
|
+
* const sdk = new ZyfaiSDK({ apiKey: "your-api-key" });
|
|
2433
|
+
* await sdk.connectAccount(privateKey, 8453);
|
|
2434
|
+
*
|
|
2435
|
+
* const result = await sdk.registerAgentOnIdentityRegistry("0xSmartWallet", 8453);
|
|
2436
|
+
* console.log("Tx hash:", result.txHash);
|
|
2437
|
+
* ```
|
|
2438
|
+
*/
|
|
2439
|
+
async registerAgentOnIdentityRegistry(smartWallet, chainId) {
|
|
2440
|
+
if (!smartWallet) {
|
|
2441
|
+
throw new Error("Smart wallet address is required");
|
|
2442
|
+
}
|
|
2443
|
+
if (!this.isSupportedIdentityRegistryChain(chainId)) {
|
|
2444
|
+
throw new Error(
|
|
2445
|
+
`Chain ${chainId} is not supported for Identity Registry. Supported chains: Base (8453), Arbitrum (42161)`
|
|
2446
|
+
);
|
|
2447
|
+
}
|
|
2448
|
+
try {
|
|
2449
|
+
const tokenUriResponse = await this.httpClient.post(
|
|
2450
|
+
ENDPOINTS.AGENT_TOKEN_URI,
|
|
2451
|
+
{ smartWallet }
|
|
2452
|
+
);
|
|
2453
|
+
if (!tokenUriResponse.tokenUri) {
|
|
2454
|
+
throw new Error("API did not return a tokenUri");
|
|
2455
|
+
}
|
|
2456
|
+
const callData = encodeFunctionData({
|
|
2457
|
+
abi: IDENTITY_REGISTRY_ABI,
|
|
2458
|
+
functionName: "register",
|
|
2459
|
+
args: [tokenUriResponse.tokenUri]
|
|
2460
|
+
});
|
|
2461
|
+
const walletClient = this.getWalletClient(chainId);
|
|
2462
|
+
const chainConfig = getChainConfig(chainId, this.rpcUrls);
|
|
2463
|
+
const txHash = await walletClient.sendTransaction({
|
|
2464
|
+
to: IDENTITY_REGISTRY_ADDRESS,
|
|
2465
|
+
data: callData,
|
|
2466
|
+
chain: chainConfig.chain,
|
|
2467
|
+
account: walletClient.account
|
|
2468
|
+
});
|
|
2469
|
+
const receipt = await chainConfig.publicClient.waitForTransactionReceipt({
|
|
2470
|
+
hash: txHash
|
|
2471
|
+
});
|
|
2472
|
+
if (receipt.status !== "success") {
|
|
2473
|
+
throw new Error("Identity Registry registration transaction failed");
|
|
2474
|
+
}
|
|
2475
|
+
return {
|
|
2476
|
+
success: true,
|
|
2477
|
+
txHash,
|
|
2478
|
+
chainId,
|
|
2479
|
+
smartWallet
|
|
2480
|
+
};
|
|
2481
|
+
} catch (error) {
|
|
2482
|
+
throw new Error(
|
|
2483
|
+
`Failed to register agent on Identity Registry: ${error.message}`
|
|
2484
|
+
);
|
|
2485
|
+
}
|
|
2486
|
+
}
|
|
2404
2487
|
};
|
|
2488
|
+
// ============================================================================
|
|
2489
|
+
// Agent Identity Registry
|
|
2490
|
+
// ============================================================================
|
|
2491
|
+
/**
|
|
2492
|
+
* Supported chain IDs for the Identity Registry (ERC-8004)
|
|
2493
|
+
*/
|
|
2494
|
+
_ZyfaiSDK.IDENTITY_REGISTRY_CHAIN_IDS = [8453, 42161];
|
|
2495
|
+
var ZyfaiSDK = _ZyfaiSDK;
|
|
2405
2496
|
export {
|
|
2406
2497
|
DEFAULT_TOKEN_ADDRESSES,
|
|
2407
2498
|
ZyfaiSDK,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zyfai/sdk",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.10",
|
|
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",
|