@zyfai/sdk 0.12.0 → 0.13.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 +17 -15
- package/dist/index.d.mts +30 -1
- package/dist/index.d.ts +30 -1
- package/dist/index.js +173 -31
- package/dist/index.mjs +150 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -656,28 +656,30 @@ const redeeming = (portfolio.pendingAsyncWithdrawals ?? []).some(
|
|
|
656
656
|
|
|
657
657
|
### Claim rZFI Rewards
|
|
658
658
|
|
|
659
|
-
rZFI accrues to the user's Safe on Base
|
|
660
|
-
|
|
661
|
-
|
|
659
|
+
rZFI accrues to the user's Safe on Base. Build the claim as an unsigned
|
|
660
|
+
transaction and sign and send it with your own signer, like
|
|
661
|
+
`buildDepositTransfer`:
|
|
662
662
|
|
|
663
663
|
```typescript
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
// prepared.claimableAmount (wei), prepared.userOpHashToSign
|
|
664
|
+
const tx = await sdk.buildRzfiClaimTransaction(userAddress);
|
|
665
|
+
// tx.claimableAmount (wei), tx.to, tx.data, tx.value
|
|
667
666
|
|
|
668
|
-
//
|
|
669
|
-
const
|
|
667
|
+
// Send from userAddress on Base (8453). Any other sender reverts.
|
|
668
|
+
const hash = await walletClient.sendTransaction({
|
|
670
669
|
account: userAddress,
|
|
671
|
-
|
|
670
|
+
chain: base,
|
|
671
|
+
to: tx.to,
|
|
672
|
+
data: tx.data,
|
|
673
|
+
value: BigInt(tx.value),
|
|
672
674
|
});
|
|
673
|
-
|
|
674
|
-
// 3. Submit within 5 minutes
|
|
675
|
-
const { txHash } = await sdk.submitRzfiClaim(userAddress, signature);
|
|
676
675
|
```
|
|
677
676
|
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
677
|
+
The sender pays the gas (about 250k on Base). It throws when there is nothing
|
|
678
|
+
to claim, or asks you to retry while Merkl's reward tree is updating on-chain.
|
|
679
|
+
|
|
680
|
+
For a gas-sponsored claim, use `prepareRzfiClaim(userAddress)`, sign the
|
|
681
|
+
returned `userOpHashToSign` (personal_sign of the raw hash), then
|
|
682
|
+
`submitRzfiClaim(userAddress, signature)`.
|
|
681
683
|
|
|
682
684
|
### 6. Get Available Protocols
|
|
683
685
|
|
package/dist/index.d.mts
CHANGED
|
@@ -794,6 +794,17 @@ interface MerklCampaign {
|
|
|
794
794
|
/** True while now is between startDate and endDate. */
|
|
795
795
|
isActive: boolean;
|
|
796
796
|
}
|
|
797
|
+
/** Unsigned rZFI claim from {@link ZyfaiSDK.buildRzfiClaimTransaction}. */
|
|
798
|
+
interface RzfiClaimTransaction {
|
|
799
|
+
/** Safe that receives the rZFI. */
|
|
800
|
+
safeAddress: Address;
|
|
801
|
+
chainId: 8453;
|
|
802
|
+
/** rZFI being claimed, in wei (18 decimals). */
|
|
803
|
+
claimableAmount: string;
|
|
804
|
+
to: Address;
|
|
805
|
+
data: Hex;
|
|
806
|
+
value: "0";
|
|
807
|
+
}
|
|
797
808
|
/**
|
|
798
809
|
* Two-step rZFI claim state from {@link ZyfaiSDK.prepareRzfiClaim} and
|
|
799
810
|
* {@link ZyfaiSDK.submitRzfiClaim}.
|
|
@@ -1939,6 +1950,24 @@ declare class ZyfaiSDK {
|
|
|
1939
1950
|
data: Hex;
|
|
1940
1951
|
value: "0";
|
|
1941
1952
|
}>;
|
|
1953
|
+
/**
|
|
1954
|
+
* Build the rZFI claim as an unsigned transaction for your own signer.
|
|
1955
|
+
*
|
|
1956
|
+
* @remarks
|
|
1957
|
+
* Same pattern as {@link ZyfaiSDK.buildDepositTransfer}: sign and send
|
|
1958
|
+
* `{ to, data, value }` from `userAddress` on Base (chain 8453). It must be
|
|
1959
|
+
* sent by `userAddress` itself; any other sender reverts. The sender pays the
|
|
1960
|
+
* gas. Claims all unclaimed rZFI into the user's Safe.
|
|
1961
|
+
*
|
|
1962
|
+
* @group Rewards
|
|
1963
|
+
*
|
|
1964
|
+
* @param userAddress - Owner EOA, which must send the transaction
|
|
1965
|
+
* @returns Safe address, claimable amount, and the transaction to send
|
|
1966
|
+
*
|
|
1967
|
+
* @throws If there is no rZFI to claim, the reward tree is updating (retry
|
|
1968
|
+
* later), or `userAddress` cannot execute the Safe alone (not an owner, or threshold above 1)
|
|
1969
|
+
*/
|
|
1970
|
+
buildRzfiClaimTransaction(userAddress: string): Promise<RzfiClaimTransaction>;
|
|
1942
1971
|
/**
|
|
1943
1972
|
* Prepare a gas-sponsored rZFI claim into the user's Safe on Base.
|
|
1944
1973
|
*
|
|
@@ -3250,4 +3279,4 @@ declare const ERC7579_LAUNCHPAD_ADDRESS: Address$1;
|
|
|
3250
3279
|
*/
|
|
3251
3280
|
declare const POOL_MODULE_ADDRESSES: readonly Address$1[];
|
|
3252
3281
|
|
|
3253
|
-
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 FirstTopupResponse, type GetPoolsResponse, type GetSelectedPoolsResponse, type Hex, 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, 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 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 };
|
|
3282
|
+
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 FirstTopupResponse, type GetPoolsResponse, type GetSelectedPoolsResponse, type Hex, 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 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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -794,6 +794,17 @@ interface MerklCampaign {
|
|
|
794
794
|
/** True while now is between startDate and endDate. */
|
|
795
795
|
isActive: boolean;
|
|
796
796
|
}
|
|
797
|
+
/** Unsigned rZFI claim from {@link ZyfaiSDK.buildRzfiClaimTransaction}. */
|
|
798
|
+
interface RzfiClaimTransaction {
|
|
799
|
+
/** Safe that receives the rZFI. */
|
|
800
|
+
safeAddress: Address;
|
|
801
|
+
chainId: 8453;
|
|
802
|
+
/** rZFI being claimed, in wei (18 decimals). */
|
|
803
|
+
claimableAmount: string;
|
|
804
|
+
to: Address;
|
|
805
|
+
data: Hex;
|
|
806
|
+
value: "0";
|
|
807
|
+
}
|
|
797
808
|
/**
|
|
798
809
|
* Two-step rZFI claim state from {@link ZyfaiSDK.prepareRzfiClaim} and
|
|
799
810
|
* {@link ZyfaiSDK.submitRzfiClaim}.
|
|
@@ -1939,6 +1950,24 @@ declare class ZyfaiSDK {
|
|
|
1939
1950
|
data: Hex;
|
|
1940
1951
|
value: "0";
|
|
1941
1952
|
}>;
|
|
1953
|
+
/**
|
|
1954
|
+
* Build the rZFI claim as an unsigned transaction for your own signer.
|
|
1955
|
+
*
|
|
1956
|
+
* @remarks
|
|
1957
|
+
* Same pattern as {@link ZyfaiSDK.buildDepositTransfer}: sign and send
|
|
1958
|
+
* `{ to, data, value }` from `userAddress` on Base (chain 8453). It must be
|
|
1959
|
+
* sent by `userAddress` itself; any other sender reverts. The sender pays the
|
|
1960
|
+
* gas. Claims all unclaimed rZFI into the user's Safe.
|
|
1961
|
+
*
|
|
1962
|
+
* @group Rewards
|
|
1963
|
+
*
|
|
1964
|
+
* @param userAddress - Owner EOA, which must send the transaction
|
|
1965
|
+
* @returns Safe address, claimable amount, and the transaction to send
|
|
1966
|
+
*
|
|
1967
|
+
* @throws If there is no rZFI to claim, the reward tree is updating (retry
|
|
1968
|
+
* later), or `userAddress` cannot execute the Safe alone (not an owner, or threshold above 1)
|
|
1969
|
+
*/
|
|
1970
|
+
buildRzfiClaimTransaction(userAddress: string): Promise<RzfiClaimTransaction>;
|
|
1942
1971
|
/**
|
|
1943
1972
|
* Prepare a gas-sponsored rZFI claim into the user's Safe on Base.
|
|
1944
1973
|
*
|
|
@@ -3250,4 +3279,4 @@ declare const ERC7579_LAUNCHPAD_ADDRESS: Address$1;
|
|
|
3250
3279
|
*/
|
|
3251
3280
|
declare const POOL_MODULE_ADDRESSES: readonly Address$1[];
|
|
3252
3281
|
|
|
3253
|
-
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 FirstTopupResponse, type GetPoolsResponse, type GetSelectedPoolsResponse, type Hex, 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, 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 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 };
|
|
3282
|
+
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 FirstTopupResponse, type GetPoolsResponse, type GetSelectedPoolsResponse, type Hex, 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 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 };
|
package/dist/index.js
CHANGED
|
@@ -691,6 +691,63 @@ var VAULT_ABI = [
|
|
|
691
691
|
}
|
|
692
692
|
];
|
|
693
693
|
var VAULT_ADDRESS = "0xD580071c47d4a667858B5FafAb85BC9C609beC5D";
|
|
694
|
+
var MERKL_DISTRIBUTOR_ADDRESS = "0x3Ef3D8bA38EBe18DB133cEc108f4D14CE00Dd9Ae";
|
|
695
|
+
var RZFI_TOKEN_ADDRESS = "0x1c08C7df416062b472F553DCC1ed3045489520C5";
|
|
696
|
+
var MERKL_DISTRIBUTOR_ABI = (0, import_viem.parseAbi)([
|
|
697
|
+
"function claim(address[] users, address[] tokens, uint256[] amounts, bytes32[][] proofs)",
|
|
698
|
+
"function claimed(address user, address token) view returns (uint208 amount, uint48 timestamp, bytes32 merkleRoot)",
|
|
699
|
+
"function getMerkleRoot() view returns (bytes32)"
|
|
700
|
+
]);
|
|
701
|
+
var SAFE_ABI = (0, import_viem.parseAbi)([
|
|
702
|
+
"function execTransaction(address to, uint256 value, bytes data, uint8 operation, uint256 safeTxGas, uint256 baseGas, uint256 gasPrice, address gasToken, address refundReceiver, bytes signatures) payable returns (bool success)",
|
|
703
|
+
"function getOwners() view returns (address[])",
|
|
704
|
+
"function getThreshold() view returns (uint256)"
|
|
705
|
+
]);
|
|
706
|
+
|
|
707
|
+
// src/utils/rzfi-claim.ts
|
|
708
|
+
var import_viem2 = require("viem");
|
|
709
|
+
var MERKL_API_URL = "https://api.merkl.xyz/v4";
|
|
710
|
+
async function fetchMerklRzfiReward(safe) {
|
|
711
|
+
const response = await fetch(
|
|
712
|
+
`${MERKL_API_URL}/users/${safe}/rewards?chainId=8453`
|
|
713
|
+
);
|
|
714
|
+
if (!response.ok) {
|
|
715
|
+
throw new Error(`Merkl API error: ${response.status}`);
|
|
716
|
+
}
|
|
717
|
+
const body = await response.json();
|
|
718
|
+
const reward = body[0]?.rewards?.find(
|
|
719
|
+
(r) => r.token.address.toLowerCase() === RZFI_TOKEN_ADDRESS.toLowerCase()
|
|
720
|
+
);
|
|
721
|
+
return reward ? { amount: BigInt(reward.amount), root: reward.root, proofs: reward.proofs } : null;
|
|
722
|
+
}
|
|
723
|
+
function encodeRzfiClaimExecTransaction(params) {
|
|
724
|
+
const { safe, owner, amount, proofs } = params;
|
|
725
|
+
const claimData = (0, import_viem2.encodeFunctionData)({
|
|
726
|
+
abi: MERKL_DISTRIBUTOR_ABI,
|
|
727
|
+
functionName: "claim",
|
|
728
|
+
args: [[safe], [RZFI_TOKEN_ADDRESS], [amount], [proofs]]
|
|
729
|
+
});
|
|
730
|
+
const signature = (0, import_viem2.encodePacked)(
|
|
731
|
+
["bytes32", "bytes32", "uint8"],
|
|
732
|
+
[(0, import_viem2.pad)(owner), (0, import_viem2.pad)("0x00"), 1]
|
|
733
|
+
);
|
|
734
|
+
return (0, import_viem2.encodeFunctionData)({
|
|
735
|
+
abi: SAFE_ABI,
|
|
736
|
+
functionName: "execTransaction",
|
|
737
|
+
args: [
|
|
738
|
+
MERKL_DISTRIBUTOR_ADDRESS,
|
|
739
|
+
0n,
|
|
740
|
+
claimData,
|
|
741
|
+
0,
|
|
742
|
+
0n,
|
|
743
|
+
0n,
|
|
744
|
+
0n,
|
|
745
|
+
import_viem2.zeroAddress,
|
|
746
|
+
import_viem2.zeroAddress,
|
|
747
|
+
signature
|
|
748
|
+
]
|
|
749
|
+
});
|
|
750
|
+
}
|
|
694
751
|
|
|
695
752
|
// src/config/constants.ts
|
|
696
753
|
var ZYFI_FEE_RATE = 0.1;
|
|
@@ -825,11 +882,11 @@ function isMainnetMinPortfolioExempt(chainId, ...addresses) {
|
|
|
825
882
|
|
|
826
883
|
// src/core/ZyfaiSDK.ts
|
|
827
884
|
var import_accounts2 = require("viem/accounts");
|
|
828
|
-
var
|
|
885
|
+
var import_viem5 = require("viem");
|
|
829
886
|
var import_relay_sdk2 = require("@relayprotocol/relay-sdk");
|
|
830
887
|
|
|
831
888
|
// src/config/chains.ts
|
|
832
|
-
var
|
|
889
|
+
var import_viem3 = require("viem");
|
|
833
890
|
var import_chains = require("viem/chains");
|
|
834
891
|
var DEFAULT_TOKEN_ADDRESSES = {
|
|
835
892
|
1: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
|
@@ -1004,9 +1061,9 @@ var getChainConfig = (chainId, rpcUrls) => {
|
|
|
1004
1061
|
throw new Error(`Unsupported chain ID: ${chainId}`);
|
|
1005
1062
|
}
|
|
1006
1063
|
const rpcUrl = rpcUrls && rpcUrls[chainId] || DEFAULT_RPC_URLS[chainId];
|
|
1007
|
-
const publicClient = (0,
|
|
1064
|
+
const publicClient = (0, import_viem3.createPublicClient)({
|
|
1008
1065
|
chain,
|
|
1009
|
-
transport: (0,
|
|
1066
|
+
transport: (0, import_viem3.http)(rpcUrl)
|
|
1010
1067
|
});
|
|
1011
1068
|
return {
|
|
1012
1069
|
chain,
|
|
@@ -1264,7 +1321,7 @@ function getManagedAssets() {
|
|
|
1264
1321
|
// src/utils/safe-account.ts
|
|
1265
1322
|
var import_module_sdk = require("@rhinestone/module-sdk");
|
|
1266
1323
|
var import_accounts = require("permissionless/accounts");
|
|
1267
|
-
var
|
|
1324
|
+
var import_viem4 = require("viem");
|
|
1268
1325
|
var import_account_abstraction = require("viem/account-abstraction");
|
|
1269
1326
|
|
|
1270
1327
|
// src/config/modules.ts
|
|
@@ -1294,12 +1351,12 @@ var getSafeAccount = async (config) => {
|
|
|
1294
1351
|
if (!safeOwnerAddress) {
|
|
1295
1352
|
throw new Error("Safe owner address is required");
|
|
1296
1353
|
}
|
|
1297
|
-
const formattedOwnerAddress = (0,
|
|
1354
|
+
const formattedOwnerAddress = (0, import_viem4.getAddress)(safeOwnerAddress);
|
|
1298
1355
|
const ownableValidator = (0, import_module_sdk.getOwnableValidator)({
|
|
1299
1356
|
owners: [formattedOwnerAddress],
|
|
1300
1357
|
threshold: 1
|
|
1301
1358
|
});
|
|
1302
|
-
const saltHex = (0,
|
|
1359
|
+
const saltHex = (0, import_viem4.fromHex)((0, import_viem4.toHex)(ACCOUNT_SALT), "bigint");
|
|
1303
1360
|
const tempOwner = {
|
|
1304
1361
|
address: formattedOwnerAddress,
|
|
1305
1362
|
type: "json-rpc"
|
|
@@ -1346,12 +1403,12 @@ var isSafeDeployed = async (address, publicClient) => {
|
|
|
1346
1403
|
}
|
|
1347
1404
|
};
|
|
1348
1405
|
var isOwnableValidatorOwner = async (safeAddress, userAddress, publicClient) => {
|
|
1349
|
-
const normalizedUser = (0,
|
|
1350
|
-
const normalizedSafe = (0,
|
|
1406
|
+
const normalizedUser = (0, import_viem4.getAddress)(userAddress);
|
|
1407
|
+
const normalizedSafe = (0, import_viem4.getAddress)(safeAddress);
|
|
1351
1408
|
const validatorAddresses = Array.from(
|
|
1352
1409
|
/* @__PURE__ */ new Set([
|
|
1353
|
-
(0,
|
|
1354
|
-
(0,
|
|
1410
|
+
(0, import_viem4.getAddress)(OWNABLE_VALIDATOR),
|
|
1411
|
+
(0, import_viem4.getAddress)(import_module_sdk.OWNABLE_VALIDATOR_ADDRESS)
|
|
1355
1412
|
])
|
|
1356
1413
|
);
|
|
1357
1414
|
for (const validatorAddress of validatorAddresses) {
|
|
@@ -1362,7 +1419,7 @@ var isOwnableValidatorOwner = async (safeAddress, userAddress, publicClient) =>
|
|
|
1362
1419
|
functionName: "getOwners",
|
|
1363
1420
|
args: [normalizedSafe]
|
|
1364
1421
|
});
|
|
1365
|
-
if (owners.some((owner) => (0,
|
|
1422
|
+
if (owners.some((owner) => (0, import_viem4.getAddress)(owner) === normalizedUser)) {
|
|
1366
1423
|
return true;
|
|
1367
1424
|
}
|
|
1368
1425
|
} catch {
|
|
@@ -2140,7 +2197,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2140
2197
|
}
|
|
2141
2198
|
this.httpClient.setAuthToken(session.accessToken);
|
|
2142
2199
|
this.authenticatedUserId = session.userId ?? "bearer-session";
|
|
2143
|
-
this.sessionEoa = session.eoa ? (0,
|
|
2200
|
+
this.sessionEoa = session.eoa ? (0, import_viem5.getAddress)(session.eoa) : null;
|
|
2144
2201
|
this.sessionChannel = session.channel;
|
|
2145
2202
|
this.isPredeployed = false;
|
|
2146
2203
|
this.predeployedResolved = false;
|
|
@@ -2189,7 +2246,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2189
2246
|
this.isPredeployed = loginResponse.predeployed || false;
|
|
2190
2247
|
this.predeployedResolved = true;
|
|
2191
2248
|
this.connectedSmartWallet = loginResponse.smartWallet || null;
|
|
2192
|
-
this.sessionEoa = (0,
|
|
2249
|
+
this.sessionEoa = (0, import_viem5.getAddress)(params.message.address);
|
|
2193
2250
|
this.sessionChannel = void 0;
|
|
2194
2251
|
return loginResponse;
|
|
2195
2252
|
}
|
|
@@ -2218,7 +2275,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2218
2275
|
return;
|
|
2219
2276
|
}
|
|
2220
2277
|
const walletClient = this.getWalletClient();
|
|
2221
|
-
const userAddress = (0,
|
|
2278
|
+
const userAddress = (0, import_viem5.getAddress)(walletClient.account.address);
|
|
2222
2279
|
const chainId = this.currentChainId || walletClient.chain?.id || 8453;
|
|
2223
2280
|
const challengeResponse = await this.httpClient.post(ENDPOINTS.AUTH_CHALLENGE, {});
|
|
2224
2281
|
let uri;
|
|
@@ -2596,10 +2653,10 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2596
2653
|
this.walletClient.chain?.id || 8453,
|
|
2597
2654
|
this.rpcUrls
|
|
2598
2655
|
);
|
|
2599
|
-
this.walletClient = (0,
|
|
2656
|
+
this.walletClient = (0, import_viem5.createWalletClient)({
|
|
2600
2657
|
account: newAddress,
|
|
2601
2658
|
chain: chainConfig.chain,
|
|
2602
|
-
transport: (0,
|
|
2659
|
+
transport: (0, import_viem5.custom)(this.currentProvider)
|
|
2603
2660
|
});
|
|
2604
2661
|
this.currentChainId = this.walletClient.chain?.id || null;
|
|
2605
2662
|
try {
|
|
@@ -2664,10 +2721,10 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2664
2721
|
}
|
|
2665
2722
|
this.signer = (0, import_accounts2.privateKeyToAccount)(privateKey);
|
|
2666
2723
|
this.currentChainId = chainId;
|
|
2667
|
-
this.walletClient = (0,
|
|
2724
|
+
this.walletClient = (0, import_viem5.createWalletClient)({
|
|
2668
2725
|
account: this.signer,
|
|
2669
2726
|
chain: chainConfig.chain,
|
|
2670
|
-
transport: (0,
|
|
2727
|
+
transport: (0, import_viem5.http)(chainConfig.rpcUrl)
|
|
2671
2728
|
});
|
|
2672
2729
|
connectedAddress = this.signer.address;
|
|
2673
2730
|
this.currentProvider = null;
|
|
@@ -2685,10 +2742,10 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2685
2742
|
if (!accounts || accounts.length === 0) {
|
|
2686
2743
|
throw new Error("No accounts found in wallet provider");
|
|
2687
2744
|
}
|
|
2688
|
-
this.walletClient = (0,
|
|
2745
|
+
this.walletClient = (0, import_viem5.createWalletClient)({
|
|
2689
2746
|
account: accounts[0],
|
|
2690
2747
|
chain: chainConfig.chain,
|
|
2691
|
-
transport: (0,
|
|
2748
|
+
transport: (0, import_viem5.custom)(provider)
|
|
2692
2749
|
});
|
|
2693
2750
|
connectedAddress = accounts[0];
|
|
2694
2751
|
this.currentProvider = provider;
|
|
@@ -2697,7 +2754,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2697
2754
|
provider.on("accountsChanged", this.handleAccountsChanged.bind(this));
|
|
2698
2755
|
}
|
|
2699
2756
|
} else if (provider.account && provider.transport) {
|
|
2700
|
-
this.walletClient = (0,
|
|
2757
|
+
this.walletClient = (0, import_viem5.createWalletClient)({
|
|
2701
2758
|
account: provider.account,
|
|
2702
2759
|
chain: chainConfig.chain,
|
|
2703
2760
|
transport: provider.transport
|
|
@@ -2758,10 +2815,10 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2758
2815
|
targetChainId,
|
|
2759
2816
|
this.rpcUrls
|
|
2760
2817
|
);
|
|
2761
|
-
return (0,
|
|
2818
|
+
return (0, import_viem5.createWalletClient)({
|
|
2762
2819
|
account: this.signer,
|
|
2763
2820
|
chain: targetChainConfig.chain,
|
|
2764
|
-
transport: (0,
|
|
2821
|
+
transport: (0, import_viem5.http)(targetChainConfig.rpcUrl)
|
|
2765
2822
|
});
|
|
2766
2823
|
} else {
|
|
2767
2824
|
if (!this.walletClient) {
|
|
@@ -4066,16 +4123,16 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
4066
4123
|
method: "wallet_switchEthereumChain",
|
|
4067
4124
|
params: [{ chainId: `0x${originChainId.toString(16)}` }]
|
|
4068
4125
|
});
|
|
4069
|
-
const chain = isSupportedChain(originChainId) ? getChainConfig(originChainId, this.rpcUrls).chain : (0,
|
|
4126
|
+
const chain = isSupportedChain(originChainId) ? getChainConfig(originChainId, this.rpcUrls).chain : (0, import_viem5.defineChain)({
|
|
4070
4127
|
id: originChainId,
|
|
4071
4128
|
name: `Chain ${originChainId}`,
|
|
4072
4129
|
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
|
|
4073
4130
|
rpcUrls: { default: { http: ["http://127.0.0.1"] } }
|
|
4074
4131
|
});
|
|
4075
|
-
this.walletClient = (0,
|
|
4132
|
+
this.walletClient = (0, import_viem5.createWalletClient)({
|
|
4076
4133
|
account: this.walletClient.account,
|
|
4077
4134
|
chain,
|
|
4078
|
-
transport: (0,
|
|
4135
|
+
transport: (0, import_viem5.custom)(this.currentProvider)
|
|
4079
4136
|
});
|
|
4080
4137
|
if (isSupportedChain(originChainId)) {
|
|
4081
4138
|
this.currentChainId = originChainId;
|
|
@@ -4251,7 +4308,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
4251
4308
|
safeAddress,
|
|
4252
4309
|
tokenAddress,
|
|
4253
4310
|
to: tokenAddress,
|
|
4254
|
-
data: (0,
|
|
4311
|
+
data: (0, import_viem5.encodeFunctionData)({
|
|
4255
4312
|
abi: ERC20_ABI,
|
|
4256
4313
|
functionName: "transfer",
|
|
4257
4314
|
args: [safeAddress, amountBigInt]
|
|
@@ -4259,6 +4316,91 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
4259
4316
|
value: "0"
|
|
4260
4317
|
};
|
|
4261
4318
|
}
|
|
4319
|
+
/**
|
|
4320
|
+
* Build the rZFI claim as an unsigned transaction for your own signer.
|
|
4321
|
+
*
|
|
4322
|
+
* @remarks
|
|
4323
|
+
* Same pattern as {@link ZyfaiSDK.buildDepositTransfer}: sign and send
|
|
4324
|
+
* `{ to, data, value }` from `userAddress` on Base (chain 8453). It must be
|
|
4325
|
+
* sent by `userAddress` itself; any other sender reverts. The sender pays the
|
|
4326
|
+
* gas. Claims all unclaimed rZFI into the user's Safe.
|
|
4327
|
+
*
|
|
4328
|
+
* @group Rewards
|
|
4329
|
+
*
|
|
4330
|
+
* @param userAddress - Owner EOA, which must send the transaction
|
|
4331
|
+
* @returns Safe address, claimable amount, and the transaction to send
|
|
4332
|
+
*
|
|
4333
|
+
* @throws If there is no rZFI to claim, the reward tree is updating (retry
|
|
4334
|
+
* later), or `userAddress` cannot execute the Safe alone (not an owner, or threshold above 1)
|
|
4335
|
+
*/
|
|
4336
|
+
async buildRzfiClaimTransaction(userAddress) {
|
|
4337
|
+
if (!userAddress) {
|
|
4338
|
+
throw new Error("A user address is required");
|
|
4339
|
+
}
|
|
4340
|
+
const owner = (0, import_viem5.getAddress)(userAddress);
|
|
4341
|
+
const chainId = 8453;
|
|
4342
|
+
await this.hydrateSessionWallet();
|
|
4343
|
+
const safe = await this.getSafeAddressFor(owner, chainId);
|
|
4344
|
+
if (!safe) {
|
|
4345
|
+
throw new Error("Smart wallet address is not available");
|
|
4346
|
+
}
|
|
4347
|
+
const { publicClient } = getChainConfig(chainId, this.rpcUrls);
|
|
4348
|
+
const [owners, threshold] = await Promise.all([
|
|
4349
|
+
publicClient.readContract({
|
|
4350
|
+
address: safe,
|
|
4351
|
+
abi: SAFE_ABI,
|
|
4352
|
+
functionName: "getOwners"
|
|
4353
|
+
}),
|
|
4354
|
+
publicClient.readContract({
|
|
4355
|
+
address: safe,
|
|
4356
|
+
abi: SAFE_ABI,
|
|
4357
|
+
functionName: "getThreshold"
|
|
4358
|
+
})
|
|
4359
|
+
]).catch(() => {
|
|
4360
|
+
throw new Error(`Safe ${safe} is not deployed on Base`);
|
|
4361
|
+
});
|
|
4362
|
+
if (threshold !== 1n || !owners.some((o) => (0, import_viem5.getAddress)(o) === owner)) {
|
|
4363
|
+
throw new Error(
|
|
4364
|
+
`${owner} cannot execute Safe ${safe} alone (not an owner, or threshold above 1)`
|
|
4365
|
+
);
|
|
4366
|
+
}
|
|
4367
|
+
const [reward, [claimed], liveRoot] = await Promise.all([
|
|
4368
|
+
fetchMerklRzfiReward(safe),
|
|
4369
|
+
publicClient.readContract({
|
|
4370
|
+
address: MERKL_DISTRIBUTOR_ADDRESS,
|
|
4371
|
+
abi: MERKL_DISTRIBUTOR_ABI,
|
|
4372
|
+
functionName: "claimed",
|
|
4373
|
+
args: [safe, RZFI_TOKEN_ADDRESS]
|
|
4374
|
+
}),
|
|
4375
|
+
publicClient.readContract({
|
|
4376
|
+
address: MERKL_DISTRIBUTOR_ADDRESS,
|
|
4377
|
+
abi: MERKL_DISTRIBUTOR_ABI,
|
|
4378
|
+
functionName: "getMerkleRoot"
|
|
4379
|
+
})
|
|
4380
|
+
]);
|
|
4381
|
+
const claimable = reward ? reward.amount - claimed : 0n;
|
|
4382
|
+
if (!reward || claimable <= 0n) {
|
|
4383
|
+
throw new Error("No rZFI available to claim");
|
|
4384
|
+
}
|
|
4385
|
+
if (reward.root.toLowerCase() !== liveRoot.toLowerCase()) {
|
|
4386
|
+
throw new Error(
|
|
4387
|
+
"rZFI rewards are being updated on-chain. Retry in a few minutes."
|
|
4388
|
+
);
|
|
4389
|
+
}
|
|
4390
|
+
return {
|
|
4391
|
+
safeAddress: safe,
|
|
4392
|
+
chainId: 8453,
|
|
4393
|
+
claimableAmount: claimable.toString(),
|
|
4394
|
+
to: safe,
|
|
4395
|
+
data: encodeRzfiClaimExecTransaction({
|
|
4396
|
+
safe,
|
|
4397
|
+
owner,
|
|
4398
|
+
amount: reward.amount,
|
|
4399
|
+
proofs: reward.proofs
|
|
4400
|
+
}),
|
|
4401
|
+
value: "0"
|
|
4402
|
+
};
|
|
4403
|
+
}
|
|
4262
4404
|
/**
|
|
4263
4405
|
* Prepare a gas-sponsored rZFI claim into the user's Safe on Base.
|
|
4264
4406
|
*
|
|
@@ -4306,7 +4448,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
4306
4448
|
if (!userAddress) {
|
|
4307
4449
|
throw new Error("A user address is required");
|
|
4308
4450
|
}
|
|
4309
|
-
if (this.sessionEoa && (0,
|
|
4451
|
+
if (this.sessionEoa && (0, import_viem5.getAddress)(userAddress) !== this.sessionEoa) {
|
|
4310
4452
|
throw new Error("userAddress does not match authenticated session EOA");
|
|
4311
4453
|
}
|
|
4312
4454
|
}
|
|
@@ -4452,7 +4594,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
4452
4594
|
*/
|
|
4453
4595
|
async prepareDeposit(params) {
|
|
4454
4596
|
const { userAddress, chainId, amount, asset } = params;
|
|
4455
|
-
if (this.sessionEoa && (0,
|
|
4597
|
+
if (this.sessionEoa && (0, import_viem5.getAddress)(userAddress) !== this.sessionEoa) {
|
|
4456
4598
|
throw new Error("userAddress does not match authenticated session EOA");
|
|
4457
4599
|
}
|
|
4458
4600
|
const setup = await this.ensureDepositProfileForPrepare({
|
|
@@ -6472,7 +6614,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
6472
6614
|
if (!tokenUriResponse.tokenUri) {
|
|
6473
6615
|
throw new Error("API did not return a tokenUri");
|
|
6474
6616
|
}
|
|
6475
|
-
const callData = (0,
|
|
6617
|
+
const callData = (0, import_viem5.encodeFunctionData)({
|
|
6476
6618
|
abi: IDENTITY_REGISTRY_ABI,
|
|
6477
6619
|
functionName: "register",
|
|
6478
6620
|
args: [tokenUriResponse.tokenUri]
|
package/dist/index.mjs
CHANGED
|
@@ -617,6 +617,68 @@ var VAULT_ABI = [
|
|
|
617
617
|
}
|
|
618
618
|
];
|
|
619
619
|
var VAULT_ADDRESS = "0xD580071c47d4a667858B5FafAb85BC9C609beC5D";
|
|
620
|
+
var MERKL_DISTRIBUTOR_ADDRESS = "0x3Ef3D8bA38EBe18DB133cEc108f4D14CE00Dd9Ae";
|
|
621
|
+
var RZFI_TOKEN_ADDRESS = "0x1c08C7df416062b472F553DCC1ed3045489520C5";
|
|
622
|
+
var MERKL_DISTRIBUTOR_ABI = parseAbi([
|
|
623
|
+
"function claim(address[] users, address[] tokens, uint256[] amounts, bytes32[][] proofs)",
|
|
624
|
+
"function claimed(address user, address token) view returns (uint208 amount, uint48 timestamp, bytes32 merkleRoot)",
|
|
625
|
+
"function getMerkleRoot() view returns (bytes32)"
|
|
626
|
+
]);
|
|
627
|
+
var SAFE_ABI = parseAbi([
|
|
628
|
+
"function execTransaction(address to, uint256 value, bytes data, uint8 operation, uint256 safeTxGas, uint256 baseGas, uint256 gasPrice, address gasToken, address refundReceiver, bytes signatures) payable returns (bool success)",
|
|
629
|
+
"function getOwners() view returns (address[])",
|
|
630
|
+
"function getThreshold() view returns (uint256)"
|
|
631
|
+
]);
|
|
632
|
+
|
|
633
|
+
// src/utils/rzfi-claim.ts
|
|
634
|
+
import {
|
|
635
|
+
encodeFunctionData,
|
|
636
|
+
encodePacked,
|
|
637
|
+
pad,
|
|
638
|
+
zeroAddress
|
|
639
|
+
} from "viem";
|
|
640
|
+
var MERKL_API_URL = "https://api.merkl.xyz/v4";
|
|
641
|
+
async function fetchMerklRzfiReward(safe) {
|
|
642
|
+
const response = await fetch(
|
|
643
|
+
`${MERKL_API_URL}/users/${safe}/rewards?chainId=8453`
|
|
644
|
+
);
|
|
645
|
+
if (!response.ok) {
|
|
646
|
+
throw new Error(`Merkl API error: ${response.status}`);
|
|
647
|
+
}
|
|
648
|
+
const body = await response.json();
|
|
649
|
+
const reward = body[0]?.rewards?.find(
|
|
650
|
+
(r) => r.token.address.toLowerCase() === RZFI_TOKEN_ADDRESS.toLowerCase()
|
|
651
|
+
);
|
|
652
|
+
return reward ? { amount: BigInt(reward.amount), root: reward.root, proofs: reward.proofs } : null;
|
|
653
|
+
}
|
|
654
|
+
function encodeRzfiClaimExecTransaction(params) {
|
|
655
|
+
const { safe, owner, amount, proofs } = params;
|
|
656
|
+
const claimData = encodeFunctionData({
|
|
657
|
+
abi: MERKL_DISTRIBUTOR_ABI,
|
|
658
|
+
functionName: "claim",
|
|
659
|
+
args: [[safe], [RZFI_TOKEN_ADDRESS], [amount], [proofs]]
|
|
660
|
+
});
|
|
661
|
+
const signature = encodePacked(
|
|
662
|
+
["bytes32", "bytes32", "uint8"],
|
|
663
|
+
[pad(owner), pad("0x00"), 1]
|
|
664
|
+
);
|
|
665
|
+
return encodeFunctionData({
|
|
666
|
+
abi: SAFE_ABI,
|
|
667
|
+
functionName: "execTransaction",
|
|
668
|
+
args: [
|
|
669
|
+
MERKL_DISTRIBUTOR_ADDRESS,
|
|
670
|
+
0n,
|
|
671
|
+
claimData,
|
|
672
|
+
0,
|
|
673
|
+
0n,
|
|
674
|
+
0n,
|
|
675
|
+
0n,
|
|
676
|
+
zeroAddress,
|
|
677
|
+
zeroAddress,
|
|
678
|
+
signature
|
|
679
|
+
]
|
|
680
|
+
});
|
|
681
|
+
}
|
|
620
682
|
|
|
621
683
|
// src/config/constants.ts
|
|
622
684
|
var ZYFI_FEE_RATE = 0.1;
|
|
@@ -756,7 +818,7 @@ import {
|
|
|
756
818
|
custom,
|
|
757
819
|
http as http2,
|
|
758
820
|
getAddress as getAddress2,
|
|
759
|
-
encodeFunctionData,
|
|
821
|
+
encodeFunctionData as encodeFunctionData2,
|
|
760
822
|
defineChain
|
|
761
823
|
} from "viem";
|
|
762
824
|
import { execute } from "@relayprotocol/relay-sdk";
|
|
@@ -4203,7 +4265,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
4203
4265
|
safeAddress,
|
|
4204
4266
|
tokenAddress,
|
|
4205
4267
|
to: tokenAddress,
|
|
4206
|
-
data:
|
|
4268
|
+
data: encodeFunctionData2({
|
|
4207
4269
|
abi: ERC20_ABI,
|
|
4208
4270
|
functionName: "transfer",
|
|
4209
4271
|
args: [safeAddress, amountBigInt]
|
|
@@ -4211,6 +4273,91 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
4211
4273
|
value: "0"
|
|
4212
4274
|
};
|
|
4213
4275
|
}
|
|
4276
|
+
/**
|
|
4277
|
+
* Build the rZFI claim as an unsigned transaction for your own signer.
|
|
4278
|
+
*
|
|
4279
|
+
* @remarks
|
|
4280
|
+
* Same pattern as {@link ZyfaiSDK.buildDepositTransfer}: sign and send
|
|
4281
|
+
* `{ to, data, value }` from `userAddress` on Base (chain 8453). It must be
|
|
4282
|
+
* sent by `userAddress` itself; any other sender reverts. The sender pays the
|
|
4283
|
+
* gas. Claims all unclaimed rZFI into the user's Safe.
|
|
4284
|
+
*
|
|
4285
|
+
* @group Rewards
|
|
4286
|
+
*
|
|
4287
|
+
* @param userAddress - Owner EOA, which must send the transaction
|
|
4288
|
+
* @returns Safe address, claimable amount, and the transaction to send
|
|
4289
|
+
*
|
|
4290
|
+
* @throws If there is no rZFI to claim, the reward tree is updating (retry
|
|
4291
|
+
* later), or `userAddress` cannot execute the Safe alone (not an owner, or threshold above 1)
|
|
4292
|
+
*/
|
|
4293
|
+
async buildRzfiClaimTransaction(userAddress) {
|
|
4294
|
+
if (!userAddress) {
|
|
4295
|
+
throw new Error("A user address is required");
|
|
4296
|
+
}
|
|
4297
|
+
const owner = getAddress2(userAddress);
|
|
4298
|
+
const chainId = 8453;
|
|
4299
|
+
await this.hydrateSessionWallet();
|
|
4300
|
+
const safe = await this.getSafeAddressFor(owner, chainId);
|
|
4301
|
+
if (!safe) {
|
|
4302
|
+
throw new Error("Smart wallet address is not available");
|
|
4303
|
+
}
|
|
4304
|
+
const { publicClient } = getChainConfig(chainId, this.rpcUrls);
|
|
4305
|
+
const [owners, threshold] = await Promise.all([
|
|
4306
|
+
publicClient.readContract({
|
|
4307
|
+
address: safe,
|
|
4308
|
+
abi: SAFE_ABI,
|
|
4309
|
+
functionName: "getOwners"
|
|
4310
|
+
}),
|
|
4311
|
+
publicClient.readContract({
|
|
4312
|
+
address: safe,
|
|
4313
|
+
abi: SAFE_ABI,
|
|
4314
|
+
functionName: "getThreshold"
|
|
4315
|
+
})
|
|
4316
|
+
]).catch(() => {
|
|
4317
|
+
throw new Error(`Safe ${safe} is not deployed on Base`);
|
|
4318
|
+
});
|
|
4319
|
+
if (threshold !== 1n || !owners.some((o) => getAddress2(o) === owner)) {
|
|
4320
|
+
throw new Error(
|
|
4321
|
+
`${owner} cannot execute Safe ${safe} alone (not an owner, or threshold above 1)`
|
|
4322
|
+
);
|
|
4323
|
+
}
|
|
4324
|
+
const [reward, [claimed], liveRoot] = await Promise.all([
|
|
4325
|
+
fetchMerklRzfiReward(safe),
|
|
4326
|
+
publicClient.readContract({
|
|
4327
|
+
address: MERKL_DISTRIBUTOR_ADDRESS,
|
|
4328
|
+
abi: MERKL_DISTRIBUTOR_ABI,
|
|
4329
|
+
functionName: "claimed",
|
|
4330
|
+
args: [safe, RZFI_TOKEN_ADDRESS]
|
|
4331
|
+
}),
|
|
4332
|
+
publicClient.readContract({
|
|
4333
|
+
address: MERKL_DISTRIBUTOR_ADDRESS,
|
|
4334
|
+
abi: MERKL_DISTRIBUTOR_ABI,
|
|
4335
|
+
functionName: "getMerkleRoot"
|
|
4336
|
+
})
|
|
4337
|
+
]);
|
|
4338
|
+
const claimable = reward ? reward.amount - claimed : 0n;
|
|
4339
|
+
if (!reward || claimable <= 0n) {
|
|
4340
|
+
throw new Error("No rZFI available to claim");
|
|
4341
|
+
}
|
|
4342
|
+
if (reward.root.toLowerCase() !== liveRoot.toLowerCase()) {
|
|
4343
|
+
throw new Error(
|
|
4344
|
+
"rZFI rewards are being updated on-chain. Retry in a few minutes."
|
|
4345
|
+
);
|
|
4346
|
+
}
|
|
4347
|
+
return {
|
|
4348
|
+
safeAddress: safe,
|
|
4349
|
+
chainId: 8453,
|
|
4350
|
+
claimableAmount: claimable.toString(),
|
|
4351
|
+
to: safe,
|
|
4352
|
+
data: encodeRzfiClaimExecTransaction({
|
|
4353
|
+
safe,
|
|
4354
|
+
owner,
|
|
4355
|
+
amount: reward.amount,
|
|
4356
|
+
proofs: reward.proofs
|
|
4357
|
+
}),
|
|
4358
|
+
value: "0"
|
|
4359
|
+
};
|
|
4360
|
+
}
|
|
4214
4361
|
/**
|
|
4215
4362
|
* Prepare a gas-sponsored rZFI claim into the user's Safe on Base.
|
|
4216
4363
|
*
|
|
@@ -6424,7 +6571,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
6424
6571
|
if (!tokenUriResponse.tokenUri) {
|
|
6425
6572
|
throw new Error("API did not return a tokenUri");
|
|
6426
6573
|
}
|
|
6427
|
-
const callData =
|
|
6574
|
+
const callData = encodeFunctionData2({
|
|
6428
6575
|
abi: IDENTITY_REGISTRY_ABI,
|
|
6429
6576
|
functionName: "register",
|
|
6430
6577
|
args: [tokenUriResponse.tokenUri]
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zyfai/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"description": "TypeScript SDK for self-custodial Zyfai yield agents: discover DeFi opportunities and manage deposits, withdrawals, positions, and strategies across Ethereum, Base, and Arbitrum",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|