@zyfai/sdk 0.11.2 → 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 +38 -0
- package/dist/index.d.mts +115 -1
- package/dist/index.d.ts +115 -1
- package/dist/index.js +271 -30
- package/dist/index.mjs +249 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -654,6 +654,33 @@ const redeeming = (portfolio.pendingAsyncWithdrawals ?? []).some(
|
|
|
654
654
|
);
|
|
655
655
|
```
|
|
656
656
|
|
|
657
|
+
### Claim rZFI Rewards
|
|
658
|
+
|
|
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
|
+
|
|
663
|
+
```typescript
|
|
664
|
+
const tx = await sdk.buildRzfiClaimTransaction(userAddress);
|
|
665
|
+
// tx.claimableAmount (wei), tx.to, tx.data, tx.value
|
|
666
|
+
|
|
667
|
+
// Send from userAddress on Base (8453). Any other sender reverts.
|
|
668
|
+
const hash = await walletClient.sendTransaction({
|
|
669
|
+
account: userAddress,
|
|
670
|
+
chain: base,
|
|
671
|
+
to: tx.to,
|
|
672
|
+
data: tx.data,
|
|
673
|
+
value: BigInt(tx.value),
|
|
674
|
+
});
|
|
675
|
+
```
|
|
676
|
+
|
|
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)`.
|
|
683
|
+
|
|
657
684
|
### 6. Get Available Protocols
|
|
658
685
|
|
|
659
686
|
Retrieve all available DeFi protocols and pools for a specific chain:
|
|
@@ -1186,6 +1213,17 @@ console.log("APY per strategy:", apyPerStrategy.data);
|
|
|
1186
1213
|
// Each item includes average_apy_withFee and average_apy_with_rzfi_withFee
|
|
1187
1214
|
```
|
|
1188
1215
|
|
|
1216
|
+
### Base Merkl Campaign APR
|
|
1217
|
+
|
|
1218
|
+
Current APR of Zyfai's Merkl incentive campaigns on Base (paid on top of
|
|
1219
|
+
strategy yield). APR is a decimal: `0.011` = 1.1%.
|
|
1220
|
+
|
|
1221
|
+
```typescript
|
|
1222
|
+
const campaigns = await sdk.getBaseMerklCampaigns();
|
|
1223
|
+
// [{ id: "base/rzfi", name, apr, tvlUsd, activeWallets, rewardToken,
|
|
1224
|
+
// totalRewards, dailyRewardAmount, startDate, endDate, isActive }, ...]
|
|
1225
|
+
```
|
|
1226
|
+
|
|
1189
1227
|
### 12. SDK API Key Management
|
|
1190
1228
|
|
|
1191
1229
|
#### Add Wallet to SDK API Key
|
package/dist/index.d.mts
CHANGED
|
@@ -776,6 +776,53 @@ interface WithdrawLifecycleResponse {
|
|
|
776
776
|
statusUrl: string;
|
|
777
777
|
estimatedClaimAt?: string | null;
|
|
778
778
|
}
|
|
779
|
+
/** Base Merkl campaign slots served by the data API. */
|
|
780
|
+
type BaseMerklCampaignId = "base" | "base-new-tvl" | "base/rzfi";
|
|
781
|
+
/** A Zyfai Merkl incentive campaign on Base, from {@link ZyfaiSDK.getBaseMerklCampaigns}. */
|
|
782
|
+
interface MerklCampaign {
|
|
783
|
+
id: BaseMerklCampaignId;
|
|
784
|
+
name: string;
|
|
785
|
+
/** Current campaign APR as a decimal (0.011 = 1.1%), on top of strategy yield. */
|
|
786
|
+
apr: number;
|
|
787
|
+
tvlUsd: number;
|
|
788
|
+
activeWallets: number;
|
|
789
|
+
rewardToken: Address;
|
|
790
|
+
totalRewards: number;
|
|
791
|
+
dailyRewardAmount: number;
|
|
792
|
+
startDate: string;
|
|
793
|
+
endDate: string;
|
|
794
|
+
/** True while now is between startDate and endDate. */
|
|
795
|
+
isActive: boolean;
|
|
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
|
+
}
|
|
808
|
+
/**
|
|
809
|
+
* Two-step rZFI claim state from {@link ZyfaiSDK.prepareRzfiClaim} and
|
|
810
|
+
* {@link ZyfaiSDK.submitRzfiClaim}.
|
|
811
|
+
*/
|
|
812
|
+
interface RzfiClaimResponse {
|
|
813
|
+
success: boolean;
|
|
814
|
+
status: "pending" | "claimed";
|
|
815
|
+
/** Safe that receives the rZFI (Base). */
|
|
816
|
+
safeAddress: Address;
|
|
817
|
+
/** rZFI being claimed, in wei (18 decimals). */
|
|
818
|
+
claimableAmount: string;
|
|
819
|
+
/** Present when pending: sign with the owner EOA (personal_sign of the raw hash). */
|
|
820
|
+
userOpHashToSign?: Hex;
|
|
821
|
+
/** Present when pending: the userOperation behind the hash, for verification. */
|
|
822
|
+
userOperation?: Record<string, unknown>;
|
|
823
|
+
/** Present when claimed. */
|
|
824
|
+
txHash?: Hex;
|
|
825
|
+
}
|
|
779
826
|
interface LogDepositResponse {
|
|
780
827
|
success: boolean;
|
|
781
828
|
message: string;
|
|
@@ -1903,6 +1950,55 @@ declare class ZyfaiSDK {
|
|
|
1903
1950
|
data: Hex;
|
|
1904
1951
|
value: "0";
|
|
1905
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>;
|
|
1971
|
+
/**
|
|
1972
|
+
* Prepare a gas-sponsored rZFI claim into the user's Safe on Base.
|
|
1973
|
+
*
|
|
1974
|
+
* @remarks
|
|
1975
|
+
* The SDK never signs. Sign `userOpHashToSign` with the owner EOA as a
|
|
1976
|
+
* personal_sign of the raw 32-byte hash (viem:
|
|
1977
|
+
* `signMessage({ message: { raw: userOpHashToSign } })`), then pass the
|
|
1978
|
+
* signature to {@link ZyfaiSDK.submitRzfiClaim} within 5 minutes.
|
|
1979
|
+
* Requires an authenticated user session.
|
|
1980
|
+
*
|
|
1981
|
+
* @group Rewards
|
|
1982
|
+
*
|
|
1983
|
+
* @param userAddress - Owner EOA
|
|
1984
|
+
* @returns `status: "pending"` with the hash to sign and the amount
|
|
1985
|
+
*
|
|
1986
|
+
* @throws If there is no rZFI to claim, or the reward tree is updating (retry later)
|
|
1987
|
+
*/
|
|
1988
|
+
prepareRzfiClaim(userAddress: string): Promise<RzfiClaimResponse>;
|
|
1989
|
+
/**
|
|
1990
|
+
* Submit the owner-signed rZFI claim prepared by {@link ZyfaiSDK.prepareRzfiClaim}.
|
|
1991
|
+
*
|
|
1992
|
+
* @group Rewards
|
|
1993
|
+
*
|
|
1994
|
+
* @param userAddress - Owner EOA
|
|
1995
|
+
* @param userOpSignature - Owner EOA signature over `userOpHashToSign`
|
|
1996
|
+
* @returns `status: "claimed"` with the on-chain `txHash`
|
|
1997
|
+
*
|
|
1998
|
+
* @throws If the signature is not the owner's, the claim expired, or it reverted
|
|
1999
|
+
*/
|
|
2000
|
+
submitRzfiClaim(userAddress: string, userOpSignature: Hex): Promise<RzfiClaimResponse>;
|
|
2001
|
+
private assertRzfiClaimUser;
|
|
1906
2002
|
/** Apply the same per-asset minimum portfolio rule as sendDeposit. */
|
|
1907
2003
|
private enforceMinimumPortfolioBalance;
|
|
1908
2004
|
/**
|
|
@@ -2258,6 +2354,24 @@ declare class ZyfaiSDK {
|
|
|
2258
2354
|
* ```
|
|
2259
2355
|
*/
|
|
2260
2356
|
getUserDetails(asset?: SupportedAsset): Promise<UpdateUserProfileResponse>;
|
|
2357
|
+
/**
|
|
2358
|
+
* Get Zyfai's Merkl incentive campaigns on Base with their current APR.
|
|
2359
|
+
*
|
|
2360
|
+
* @group Analytics and opportunities
|
|
2361
|
+
*
|
|
2362
|
+
* @remarks Data API. Partner API key only; SIWE not required.
|
|
2363
|
+
*
|
|
2364
|
+
* @returns One entry per campaign slot (rZFI, new TVL, season campaign)
|
|
2365
|
+
*
|
|
2366
|
+
* @example
|
|
2367
|
+
* ```typescript
|
|
2368
|
+
* const campaigns = await sdk.getBaseMerklCampaigns();
|
|
2369
|
+
* for (const c of campaigns.filter((c) => c.isActive)) {
|
|
2370
|
+
* console.log(c.name, `${(c.apr * 100).toFixed(2)}%`);
|
|
2371
|
+
* }
|
|
2372
|
+
* ```
|
|
2373
|
+
*/
|
|
2374
|
+
getBaseMerklCampaigns(): Promise<MerklCampaign[]>;
|
|
2261
2375
|
/**
|
|
2262
2376
|
* Get total value locked (TVL) across all Zyfai accounts.
|
|
2263
2377
|
*
|
|
@@ -3165,4 +3279,4 @@ declare const ERC7579_LAUNCHPAD_ADDRESS: Address$1;
|
|
|
3165
3279
|
*/
|
|
3166
3280
|
declare const POOL_MODULE_ADDRESSES: readonly Address$1[];
|
|
3167
3281
|
|
|
3168
|
-
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 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 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, 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
|
@@ -776,6 +776,53 @@ interface WithdrawLifecycleResponse {
|
|
|
776
776
|
statusUrl: string;
|
|
777
777
|
estimatedClaimAt?: string | null;
|
|
778
778
|
}
|
|
779
|
+
/** Base Merkl campaign slots served by the data API. */
|
|
780
|
+
type BaseMerklCampaignId = "base" | "base-new-tvl" | "base/rzfi";
|
|
781
|
+
/** A Zyfai Merkl incentive campaign on Base, from {@link ZyfaiSDK.getBaseMerklCampaigns}. */
|
|
782
|
+
interface MerklCampaign {
|
|
783
|
+
id: BaseMerklCampaignId;
|
|
784
|
+
name: string;
|
|
785
|
+
/** Current campaign APR as a decimal (0.011 = 1.1%), on top of strategy yield. */
|
|
786
|
+
apr: number;
|
|
787
|
+
tvlUsd: number;
|
|
788
|
+
activeWallets: number;
|
|
789
|
+
rewardToken: Address;
|
|
790
|
+
totalRewards: number;
|
|
791
|
+
dailyRewardAmount: number;
|
|
792
|
+
startDate: string;
|
|
793
|
+
endDate: string;
|
|
794
|
+
/** True while now is between startDate and endDate. */
|
|
795
|
+
isActive: boolean;
|
|
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
|
+
}
|
|
808
|
+
/**
|
|
809
|
+
* Two-step rZFI claim state from {@link ZyfaiSDK.prepareRzfiClaim} and
|
|
810
|
+
* {@link ZyfaiSDK.submitRzfiClaim}.
|
|
811
|
+
*/
|
|
812
|
+
interface RzfiClaimResponse {
|
|
813
|
+
success: boolean;
|
|
814
|
+
status: "pending" | "claimed";
|
|
815
|
+
/** Safe that receives the rZFI (Base). */
|
|
816
|
+
safeAddress: Address;
|
|
817
|
+
/** rZFI being claimed, in wei (18 decimals). */
|
|
818
|
+
claimableAmount: string;
|
|
819
|
+
/** Present when pending: sign with the owner EOA (personal_sign of the raw hash). */
|
|
820
|
+
userOpHashToSign?: Hex;
|
|
821
|
+
/** Present when pending: the userOperation behind the hash, for verification. */
|
|
822
|
+
userOperation?: Record<string, unknown>;
|
|
823
|
+
/** Present when claimed. */
|
|
824
|
+
txHash?: Hex;
|
|
825
|
+
}
|
|
779
826
|
interface LogDepositResponse {
|
|
780
827
|
success: boolean;
|
|
781
828
|
message: string;
|
|
@@ -1903,6 +1950,55 @@ declare class ZyfaiSDK {
|
|
|
1903
1950
|
data: Hex;
|
|
1904
1951
|
value: "0";
|
|
1905
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>;
|
|
1971
|
+
/**
|
|
1972
|
+
* Prepare a gas-sponsored rZFI claim into the user's Safe on Base.
|
|
1973
|
+
*
|
|
1974
|
+
* @remarks
|
|
1975
|
+
* The SDK never signs. Sign `userOpHashToSign` with the owner EOA as a
|
|
1976
|
+
* personal_sign of the raw 32-byte hash (viem:
|
|
1977
|
+
* `signMessage({ message: { raw: userOpHashToSign } })`), then pass the
|
|
1978
|
+
* signature to {@link ZyfaiSDK.submitRzfiClaim} within 5 minutes.
|
|
1979
|
+
* Requires an authenticated user session.
|
|
1980
|
+
*
|
|
1981
|
+
* @group Rewards
|
|
1982
|
+
*
|
|
1983
|
+
* @param userAddress - Owner EOA
|
|
1984
|
+
* @returns `status: "pending"` with the hash to sign and the amount
|
|
1985
|
+
*
|
|
1986
|
+
* @throws If there is no rZFI to claim, or the reward tree is updating (retry later)
|
|
1987
|
+
*/
|
|
1988
|
+
prepareRzfiClaim(userAddress: string): Promise<RzfiClaimResponse>;
|
|
1989
|
+
/**
|
|
1990
|
+
* Submit the owner-signed rZFI claim prepared by {@link ZyfaiSDK.prepareRzfiClaim}.
|
|
1991
|
+
*
|
|
1992
|
+
* @group Rewards
|
|
1993
|
+
*
|
|
1994
|
+
* @param userAddress - Owner EOA
|
|
1995
|
+
* @param userOpSignature - Owner EOA signature over `userOpHashToSign`
|
|
1996
|
+
* @returns `status: "claimed"` with the on-chain `txHash`
|
|
1997
|
+
*
|
|
1998
|
+
* @throws If the signature is not the owner's, the claim expired, or it reverted
|
|
1999
|
+
*/
|
|
2000
|
+
submitRzfiClaim(userAddress: string, userOpSignature: Hex): Promise<RzfiClaimResponse>;
|
|
2001
|
+
private assertRzfiClaimUser;
|
|
1906
2002
|
/** Apply the same per-asset minimum portfolio rule as sendDeposit. */
|
|
1907
2003
|
private enforceMinimumPortfolioBalance;
|
|
1908
2004
|
/**
|
|
@@ -2258,6 +2354,24 @@ declare class ZyfaiSDK {
|
|
|
2258
2354
|
* ```
|
|
2259
2355
|
*/
|
|
2260
2356
|
getUserDetails(asset?: SupportedAsset): Promise<UpdateUserProfileResponse>;
|
|
2357
|
+
/**
|
|
2358
|
+
* Get Zyfai's Merkl incentive campaigns on Base with their current APR.
|
|
2359
|
+
*
|
|
2360
|
+
* @group Analytics and opportunities
|
|
2361
|
+
*
|
|
2362
|
+
* @remarks Data API. Partner API key only; SIWE not required.
|
|
2363
|
+
*
|
|
2364
|
+
* @returns One entry per campaign slot (rZFI, new TVL, season campaign)
|
|
2365
|
+
*
|
|
2366
|
+
* @example
|
|
2367
|
+
* ```typescript
|
|
2368
|
+
* const campaigns = await sdk.getBaseMerklCampaigns();
|
|
2369
|
+
* for (const c of campaigns.filter((c) => c.isActive)) {
|
|
2370
|
+
* console.log(c.name, `${(c.apr * 100).toFixed(2)}%`);
|
|
2371
|
+
* }
|
|
2372
|
+
* ```
|
|
2373
|
+
*/
|
|
2374
|
+
getBaseMerklCampaigns(): Promise<MerklCampaign[]>;
|
|
2261
2375
|
/**
|
|
2262
2376
|
* Get total value locked (TVL) across all Zyfai accounts.
|
|
2263
2377
|
*
|
|
@@ -3165,4 +3279,4 @@ declare const ERC7579_LAUNCHPAD_ADDRESS: Address$1;
|
|
|
3165
3279
|
*/
|
|
3166
3280
|
declare const POOL_MODULE_ADDRESSES: readonly Address$1[];
|
|
3167
3281
|
|
|
3168
|
-
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 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 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, 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
|
@@ -136,6 +136,7 @@ var ENDPOINTS = {
|
|
|
136
136
|
WITHDRAW_STATUS: (withdrawalId) => `/users/withdrawals/${withdrawalId}`,
|
|
137
137
|
// Safe Deployment (single endpoint)
|
|
138
138
|
SAFE_DEPLOY: "/users/safe-deploy",
|
|
139
|
+
RZFI_CLAIM: "/users/rzfi-claim",
|
|
139
140
|
// Multichain deploy for predeployed (pool) wallets — deploys + rotates the
|
|
140
141
|
// same address on the requested chains (sponsored, no user signature).
|
|
141
142
|
DEPLOY_CHAINS: "/users/deploy-chains",
|
|
@@ -187,6 +188,8 @@ var ENDPOINTS = {
|
|
|
187
188
|
CUSTOMIZATION_SELECTED_POOLS: (protocolId, chainId) => `/customization/selected-pools?protocolId=${protocolId}&chainId=${chainId}`
|
|
188
189
|
};
|
|
189
190
|
var DATA_ENDPOINTS = {
|
|
191
|
+
// Merkl incentive campaigns
|
|
192
|
+
MERKL_CAMPAIGN_INFO: (campaign) => `/merkl/${campaign}/campaign-info`,
|
|
190
193
|
// User Initialization
|
|
191
194
|
USER_INITIALIZE: "/api/earnings/initialize",
|
|
192
195
|
// Earnings
|
|
@@ -688,6 +691,63 @@ var VAULT_ABI = [
|
|
|
688
691
|
}
|
|
689
692
|
];
|
|
690
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
|
+
}
|
|
691
751
|
|
|
692
752
|
// src/config/constants.ts
|
|
693
753
|
var ZYFI_FEE_RATE = 0.1;
|
|
@@ -822,11 +882,11 @@ function isMainnetMinPortfolioExempt(chainId, ...addresses) {
|
|
|
822
882
|
|
|
823
883
|
// src/core/ZyfaiSDK.ts
|
|
824
884
|
var import_accounts2 = require("viem/accounts");
|
|
825
|
-
var
|
|
885
|
+
var import_viem5 = require("viem");
|
|
826
886
|
var import_relay_sdk2 = require("@relayprotocol/relay-sdk");
|
|
827
887
|
|
|
828
888
|
// src/config/chains.ts
|
|
829
|
-
var
|
|
889
|
+
var import_viem3 = require("viem");
|
|
830
890
|
var import_chains = require("viem/chains");
|
|
831
891
|
var DEFAULT_TOKEN_ADDRESSES = {
|
|
832
892
|
1: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
|
@@ -1001,9 +1061,9 @@ var getChainConfig = (chainId, rpcUrls) => {
|
|
|
1001
1061
|
throw new Error(`Unsupported chain ID: ${chainId}`);
|
|
1002
1062
|
}
|
|
1003
1063
|
const rpcUrl = rpcUrls && rpcUrls[chainId] || DEFAULT_RPC_URLS[chainId];
|
|
1004
|
-
const publicClient = (0,
|
|
1064
|
+
const publicClient = (0, import_viem3.createPublicClient)({
|
|
1005
1065
|
chain,
|
|
1006
|
-
transport: (0,
|
|
1066
|
+
transport: (0, import_viem3.http)(rpcUrl)
|
|
1007
1067
|
});
|
|
1008
1068
|
return {
|
|
1009
1069
|
chain,
|
|
@@ -1261,7 +1321,7 @@ function getManagedAssets() {
|
|
|
1261
1321
|
// src/utils/safe-account.ts
|
|
1262
1322
|
var import_module_sdk = require("@rhinestone/module-sdk");
|
|
1263
1323
|
var import_accounts = require("permissionless/accounts");
|
|
1264
|
-
var
|
|
1324
|
+
var import_viem4 = require("viem");
|
|
1265
1325
|
var import_account_abstraction = require("viem/account-abstraction");
|
|
1266
1326
|
|
|
1267
1327
|
// src/config/modules.ts
|
|
@@ -1291,12 +1351,12 @@ var getSafeAccount = async (config) => {
|
|
|
1291
1351
|
if (!safeOwnerAddress) {
|
|
1292
1352
|
throw new Error("Safe owner address is required");
|
|
1293
1353
|
}
|
|
1294
|
-
const formattedOwnerAddress = (0,
|
|
1354
|
+
const formattedOwnerAddress = (0, import_viem4.getAddress)(safeOwnerAddress);
|
|
1295
1355
|
const ownableValidator = (0, import_module_sdk.getOwnableValidator)({
|
|
1296
1356
|
owners: [formattedOwnerAddress],
|
|
1297
1357
|
threshold: 1
|
|
1298
1358
|
});
|
|
1299
|
-
const saltHex = (0,
|
|
1359
|
+
const saltHex = (0, import_viem4.fromHex)((0, import_viem4.toHex)(ACCOUNT_SALT), "bigint");
|
|
1300
1360
|
const tempOwner = {
|
|
1301
1361
|
address: formattedOwnerAddress,
|
|
1302
1362
|
type: "json-rpc"
|
|
@@ -1343,12 +1403,12 @@ var isSafeDeployed = async (address, publicClient) => {
|
|
|
1343
1403
|
}
|
|
1344
1404
|
};
|
|
1345
1405
|
var isOwnableValidatorOwner = async (safeAddress, userAddress, publicClient) => {
|
|
1346
|
-
const normalizedUser = (0,
|
|
1347
|
-
const normalizedSafe = (0,
|
|
1406
|
+
const normalizedUser = (0, import_viem4.getAddress)(userAddress);
|
|
1407
|
+
const normalizedSafe = (0, import_viem4.getAddress)(safeAddress);
|
|
1348
1408
|
const validatorAddresses = Array.from(
|
|
1349
1409
|
/* @__PURE__ */ new Set([
|
|
1350
|
-
(0,
|
|
1351
|
-
(0,
|
|
1410
|
+
(0, import_viem4.getAddress)(OWNABLE_VALIDATOR),
|
|
1411
|
+
(0, import_viem4.getAddress)(import_module_sdk.OWNABLE_VALIDATOR_ADDRESS)
|
|
1352
1412
|
])
|
|
1353
1413
|
);
|
|
1354
1414
|
for (const validatorAddress of validatorAddresses) {
|
|
@@ -1359,7 +1419,7 @@ var isOwnableValidatorOwner = async (safeAddress, userAddress, publicClient) =>
|
|
|
1359
1419
|
functionName: "getOwners",
|
|
1360
1420
|
args: [normalizedSafe]
|
|
1361
1421
|
});
|
|
1362
|
-
if (owners.some((owner) => (0,
|
|
1422
|
+
if (owners.some((owner) => (0, import_viem4.getAddress)(owner) === normalizedUser)) {
|
|
1363
1423
|
return true;
|
|
1364
1424
|
}
|
|
1365
1425
|
} catch {
|
|
@@ -2137,7 +2197,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2137
2197
|
}
|
|
2138
2198
|
this.httpClient.setAuthToken(session.accessToken);
|
|
2139
2199
|
this.authenticatedUserId = session.userId ?? "bearer-session";
|
|
2140
|
-
this.sessionEoa = session.eoa ? (0,
|
|
2200
|
+
this.sessionEoa = session.eoa ? (0, import_viem5.getAddress)(session.eoa) : null;
|
|
2141
2201
|
this.sessionChannel = session.channel;
|
|
2142
2202
|
this.isPredeployed = false;
|
|
2143
2203
|
this.predeployedResolved = false;
|
|
@@ -2186,7 +2246,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2186
2246
|
this.isPredeployed = loginResponse.predeployed || false;
|
|
2187
2247
|
this.predeployedResolved = true;
|
|
2188
2248
|
this.connectedSmartWallet = loginResponse.smartWallet || null;
|
|
2189
|
-
this.sessionEoa = (0,
|
|
2249
|
+
this.sessionEoa = (0, import_viem5.getAddress)(params.message.address);
|
|
2190
2250
|
this.sessionChannel = void 0;
|
|
2191
2251
|
return loginResponse;
|
|
2192
2252
|
}
|
|
@@ -2215,7 +2275,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2215
2275
|
return;
|
|
2216
2276
|
}
|
|
2217
2277
|
const walletClient = this.getWalletClient();
|
|
2218
|
-
const userAddress = (0,
|
|
2278
|
+
const userAddress = (0, import_viem5.getAddress)(walletClient.account.address);
|
|
2219
2279
|
const chainId = this.currentChainId || walletClient.chain?.id || 8453;
|
|
2220
2280
|
const challengeResponse = await this.httpClient.post(ENDPOINTS.AUTH_CHALLENGE, {});
|
|
2221
2281
|
let uri;
|
|
@@ -2593,10 +2653,10 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2593
2653
|
this.walletClient.chain?.id || 8453,
|
|
2594
2654
|
this.rpcUrls
|
|
2595
2655
|
);
|
|
2596
|
-
this.walletClient = (0,
|
|
2656
|
+
this.walletClient = (0, import_viem5.createWalletClient)({
|
|
2597
2657
|
account: newAddress,
|
|
2598
2658
|
chain: chainConfig.chain,
|
|
2599
|
-
transport: (0,
|
|
2659
|
+
transport: (0, import_viem5.custom)(this.currentProvider)
|
|
2600
2660
|
});
|
|
2601
2661
|
this.currentChainId = this.walletClient.chain?.id || null;
|
|
2602
2662
|
try {
|
|
@@ -2661,10 +2721,10 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2661
2721
|
}
|
|
2662
2722
|
this.signer = (0, import_accounts2.privateKeyToAccount)(privateKey);
|
|
2663
2723
|
this.currentChainId = chainId;
|
|
2664
|
-
this.walletClient = (0,
|
|
2724
|
+
this.walletClient = (0, import_viem5.createWalletClient)({
|
|
2665
2725
|
account: this.signer,
|
|
2666
2726
|
chain: chainConfig.chain,
|
|
2667
|
-
transport: (0,
|
|
2727
|
+
transport: (0, import_viem5.http)(chainConfig.rpcUrl)
|
|
2668
2728
|
});
|
|
2669
2729
|
connectedAddress = this.signer.address;
|
|
2670
2730
|
this.currentProvider = null;
|
|
@@ -2682,10 +2742,10 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2682
2742
|
if (!accounts || accounts.length === 0) {
|
|
2683
2743
|
throw new Error("No accounts found in wallet provider");
|
|
2684
2744
|
}
|
|
2685
|
-
this.walletClient = (0,
|
|
2745
|
+
this.walletClient = (0, import_viem5.createWalletClient)({
|
|
2686
2746
|
account: accounts[0],
|
|
2687
2747
|
chain: chainConfig.chain,
|
|
2688
|
-
transport: (0,
|
|
2748
|
+
transport: (0, import_viem5.custom)(provider)
|
|
2689
2749
|
});
|
|
2690
2750
|
connectedAddress = accounts[0];
|
|
2691
2751
|
this.currentProvider = provider;
|
|
@@ -2694,7 +2754,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2694
2754
|
provider.on("accountsChanged", this.handleAccountsChanged.bind(this));
|
|
2695
2755
|
}
|
|
2696
2756
|
} else if (provider.account && provider.transport) {
|
|
2697
|
-
this.walletClient = (0,
|
|
2757
|
+
this.walletClient = (0, import_viem5.createWalletClient)({
|
|
2698
2758
|
account: provider.account,
|
|
2699
2759
|
chain: chainConfig.chain,
|
|
2700
2760
|
transport: provider.transport
|
|
@@ -2755,10 +2815,10 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2755
2815
|
targetChainId,
|
|
2756
2816
|
this.rpcUrls
|
|
2757
2817
|
);
|
|
2758
|
-
return (0,
|
|
2818
|
+
return (0, import_viem5.createWalletClient)({
|
|
2759
2819
|
account: this.signer,
|
|
2760
2820
|
chain: targetChainConfig.chain,
|
|
2761
|
-
transport: (0,
|
|
2821
|
+
transport: (0, import_viem5.http)(targetChainConfig.rpcUrl)
|
|
2762
2822
|
});
|
|
2763
2823
|
} else {
|
|
2764
2824
|
if (!this.walletClient) {
|
|
@@ -4063,16 +4123,16 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
4063
4123
|
method: "wallet_switchEthereumChain",
|
|
4064
4124
|
params: [{ chainId: `0x${originChainId.toString(16)}` }]
|
|
4065
4125
|
});
|
|
4066
|
-
const chain = isSupportedChain(originChainId) ? getChainConfig(originChainId, this.rpcUrls).chain : (0,
|
|
4126
|
+
const chain = isSupportedChain(originChainId) ? getChainConfig(originChainId, this.rpcUrls).chain : (0, import_viem5.defineChain)({
|
|
4067
4127
|
id: originChainId,
|
|
4068
4128
|
name: `Chain ${originChainId}`,
|
|
4069
4129
|
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
|
|
4070
4130
|
rpcUrls: { default: { http: ["http://127.0.0.1"] } }
|
|
4071
4131
|
});
|
|
4072
|
-
this.walletClient = (0,
|
|
4132
|
+
this.walletClient = (0, import_viem5.createWalletClient)({
|
|
4073
4133
|
account: this.walletClient.account,
|
|
4074
4134
|
chain,
|
|
4075
|
-
transport: (0,
|
|
4135
|
+
transport: (0, import_viem5.custom)(this.currentProvider)
|
|
4076
4136
|
});
|
|
4077
4137
|
if (isSupportedChain(originChainId)) {
|
|
4078
4138
|
this.currentChainId = originChainId;
|
|
@@ -4248,7 +4308,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
4248
4308
|
safeAddress,
|
|
4249
4309
|
tokenAddress,
|
|
4250
4310
|
to: tokenAddress,
|
|
4251
|
-
data: (0,
|
|
4311
|
+
data: (0, import_viem5.encodeFunctionData)({
|
|
4252
4312
|
abi: ERC20_ABI,
|
|
4253
4313
|
functionName: "transfer",
|
|
4254
4314
|
args: [safeAddress, amountBigInt]
|
|
@@ -4256,6 +4316,142 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
4256
4316
|
value: "0"
|
|
4257
4317
|
};
|
|
4258
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
|
+
}
|
|
4404
|
+
/**
|
|
4405
|
+
* Prepare a gas-sponsored rZFI claim into the user's Safe on Base.
|
|
4406
|
+
*
|
|
4407
|
+
* @remarks
|
|
4408
|
+
* The SDK never signs. Sign `userOpHashToSign` with the owner EOA as a
|
|
4409
|
+
* personal_sign of the raw 32-byte hash (viem:
|
|
4410
|
+
* `signMessage({ message: { raw: userOpHashToSign } })`), then pass the
|
|
4411
|
+
* signature to {@link ZyfaiSDK.submitRzfiClaim} within 5 minutes.
|
|
4412
|
+
* Requires an authenticated user session.
|
|
4413
|
+
*
|
|
4414
|
+
* @group Rewards
|
|
4415
|
+
*
|
|
4416
|
+
* @param userAddress - Owner EOA
|
|
4417
|
+
* @returns `status: "pending"` with the hash to sign and the amount
|
|
4418
|
+
*
|
|
4419
|
+
* @throws If there is no rZFI to claim, or the reward tree is updating (retry later)
|
|
4420
|
+
*/
|
|
4421
|
+
async prepareRzfiClaim(userAddress) {
|
|
4422
|
+
this.assertRzfiClaimUser(userAddress);
|
|
4423
|
+
await this.authenticateUser();
|
|
4424
|
+
return this.httpClient.post(ENDPOINTS.RZFI_CLAIM, {});
|
|
4425
|
+
}
|
|
4426
|
+
/**
|
|
4427
|
+
* Submit the owner-signed rZFI claim prepared by {@link ZyfaiSDK.prepareRzfiClaim}.
|
|
4428
|
+
*
|
|
4429
|
+
* @group Rewards
|
|
4430
|
+
*
|
|
4431
|
+
* @param userAddress - Owner EOA
|
|
4432
|
+
* @param userOpSignature - Owner EOA signature over `userOpHashToSign`
|
|
4433
|
+
* @returns `status: "claimed"` with the on-chain `txHash`
|
|
4434
|
+
*
|
|
4435
|
+
* @throws If the signature is not the owner's, the claim expired, or it reverted
|
|
4436
|
+
*/
|
|
4437
|
+
async submitRzfiClaim(userAddress, userOpSignature) {
|
|
4438
|
+
this.assertRzfiClaimUser(userAddress);
|
|
4439
|
+
if (!userOpSignature?.startsWith("0x")) {
|
|
4440
|
+
throw new Error("A 0x-prefixed userOpSignature is required");
|
|
4441
|
+
}
|
|
4442
|
+
await this.authenticateUser();
|
|
4443
|
+
return this.httpClient.post(ENDPOINTS.RZFI_CLAIM, {
|
|
4444
|
+
userOpSignature
|
|
4445
|
+
});
|
|
4446
|
+
}
|
|
4447
|
+
assertRzfiClaimUser(userAddress) {
|
|
4448
|
+
if (!userAddress) {
|
|
4449
|
+
throw new Error("A user address is required");
|
|
4450
|
+
}
|
|
4451
|
+
if (this.sessionEoa && (0, import_viem5.getAddress)(userAddress) !== this.sessionEoa) {
|
|
4452
|
+
throw new Error("userAddress does not match authenticated session EOA");
|
|
4453
|
+
}
|
|
4454
|
+
}
|
|
4259
4455
|
/** Apply the same per-asset minimum portfolio rule as sendDeposit. */
|
|
4260
4456
|
async enforceMinimumPortfolioBalance(chainId, asset, amount, safeAddress, userAddress) {
|
|
4261
4457
|
if (this.bypassMinPortfolio || isMainnetMinPortfolioExempt(chainId, userAddress, safeAddress)) {
|
|
@@ -4398,7 +4594,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
4398
4594
|
*/
|
|
4399
4595
|
async prepareDeposit(params) {
|
|
4400
4596
|
const { userAddress, chainId, amount, asset } = params;
|
|
4401
|
-
if (this.sessionEoa && (0,
|
|
4597
|
+
if (this.sessionEoa && (0, import_viem5.getAddress)(userAddress) !== this.sessionEoa) {
|
|
4402
4598
|
throw new Error("userAddress does not match authenticated session EOA");
|
|
4403
4599
|
}
|
|
4404
4600
|
const setup = await this.ensureDepositProfileForPrepare({
|
|
@@ -5121,6 +5317,51 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
5121
5317
|
// ============================================================================
|
|
5122
5318
|
// TVL & Volume Methods
|
|
5123
5319
|
// ============================================================================
|
|
5320
|
+
/**
|
|
5321
|
+
* Get Zyfai's Merkl incentive campaigns on Base with their current APR.
|
|
5322
|
+
*
|
|
5323
|
+
* @group Analytics and opportunities
|
|
5324
|
+
*
|
|
5325
|
+
* @remarks Data API. Partner API key only; SIWE not required.
|
|
5326
|
+
*
|
|
5327
|
+
* @returns One entry per campaign slot (rZFI, new TVL, season campaign)
|
|
5328
|
+
*
|
|
5329
|
+
* @example
|
|
5330
|
+
* ```typescript
|
|
5331
|
+
* const campaigns = await sdk.getBaseMerklCampaigns();
|
|
5332
|
+
* for (const c of campaigns.filter((c) => c.isActive)) {
|
|
5333
|
+
* console.log(c.name, `${(c.apr * 100).toFixed(2)}%`);
|
|
5334
|
+
* }
|
|
5335
|
+
* ```
|
|
5336
|
+
*/
|
|
5337
|
+
async getBaseMerklCampaigns() {
|
|
5338
|
+
const ids = ["base/rzfi", "base-new-tvl", "base"];
|
|
5339
|
+
try {
|
|
5340
|
+
const now = Date.now();
|
|
5341
|
+
return await Promise.all(
|
|
5342
|
+
ids.map(async (id) => {
|
|
5343
|
+
const { campaign, currentStats } = await this.httpClient.dataGet(DATA_ENDPOINTS.MERKL_CAMPAIGN_INFO(id));
|
|
5344
|
+
return {
|
|
5345
|
+
id,
|
|
5346
|
+
name: campaign.name,
|
|
5347
|
+
apr: Number(currentStats.currentAPR),
|
|
5348
|
+
tvlUsd: currentStats.totalTVL,
|
|
5349
|
+
activeWallets: currentStats.activeWallets,
|
|
5350
|
+
rewardToken: campaign.rewardToken,
|
|
5351
|
+
totalRewards: campaign.totalRewards,
|
|
5352
|
+
dailyRewardAmount: campaign.dailyRewardAmount,
|
|
5353
|
+
startDate: campaign.startDate,
|
|
5354
|
+
endDate: campaign.endDate,
|
|
5355
|
+
isActive: now >= Date.parse(campaign.startDate) && now < Date.parse(campaign.endDate)
|
|
5356
|
+
};
|
|
5357
|
+
})
|
|
5358
|
+
);
|
|
5359
|
+
} catch (error) {
|
|
5360
|
+
throw new Error(
|
|
5361
|
+
`Failed to get Base Merkl campaigns: ${error.message}`
|
|
5362
|
+
);
|
|
5363
|
+
}
|
|
5364
|
+
}
|
|
5124
5365
|
/**
|
|
5125
5366
|
* Get total value locked (TVL) across all Zyfai accounts.
|
|
5126
5367
|
*
|
|
@@ -6373,7 +6614,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
6373
6614
|
if (!tokenUriResponse.tokenUri) {
|
|
6374
6615
|
throw new Error("API did not return a tokenUri");
|
|
6375
6616
|
}
|
|
6376
|
-
const callData = (0,
|
|
6617
|
+
const callData = (0, import_viem5.encodeFunctionData)({
|
|
6377
6618
|
abi: IDENTITY_REGISTRY_ABI,
|
|
6378
6619
|
functionName: "register",
|
|
6379
6620
|
args: [tokenUriResponse.tokenUri]
|
package/dist/index.mjs
CHANGED
|
@@ -62,6 +62,7 @@ var ENDPOINTS = {
|
|
|
62
62
|
WITHDRAW_STATUS: (withdrawalId) => `/users/withdrawals/${withdrawalId}`,
|
|
63
63
|
// Safe Deployment (single endpoint)
|
|
64
64
|
SAFE_DEPLOY: "/users/safe-deploy",
|
|
65
|
+
RZFI_CLAIM: "/users/rzfi-claim",
|
|
65
66
|
// Multichain deploy for predeployed (pool) wallets — deploys + rotates the
|
|
66
67
|
// same address on the requested chains (sponsored, no user signature).
|
|
67
68
|
DEPLOY_CHAINS: "/users/deploy-chains",
|
|
@@ -113,6 +114,8 @@ var ENDPOINTS = {
|
|
|
113
114
|
CUSTOMIZATION_SELECTED_POOLS: (protocolId, chainId) => `/customization/selected-pools?protocolId=${protocolId}&chainId=${chainId}`
|
|
114
115
|
};
|
|
115
116
|
var DATA_ENDPOINTS = {
|
|
117
|
+
// Merkl incentive campaigns
|
|
118
|
+
MERKL_CAMPAIGN_INFO: (campaign) => `/merkl/${campaign}/campaign-info`,
|
|
116
119
|
// User Initialization
|
|
117
120
|
USER_INITIALIZE: "/api/earnings/initialize",
|
|
118
121
|
// Earnings
|
|
@@ -614,6 +617,68 @@ var VAULT_ABI = [
|
|
|
614
617
|
}
|
|
615
618
|
];
|
|
616
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
|
+
}
|
|
617
682
|
|
|
618
683
|
// src/config/constants.ts
|
|
619
684
|
var ZYFI_FEE_RATE = 0.1;
|
|
@@ -753,7 +818,7 @@ import {
|
|
|
753
818
|
custom,
|
|
754
819
|
http as http2,
|
|
755
820
|
getAddress as getAddress2,
|
|
756
|
-
encodeFunctionData,
|
|
821
|
+
encodeFunctionData as encodeFunctionData2,
|
|
757
822
|
defineChain
|
|
758
823
|
} from "viem";
|
|
759
824
|
import { execute } from "@relayprotocol/relay-sdk";
|
|
@@ -4200,7 +4265,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
4200
4265
|
safeAddress,
|
|
4201
4266
|
tokenAddress,
|
|
4202
4267
|
to: tokenAddress,
|
|
4203
|
-
data:
|
|
4268
|
+
data: encodeFunctionData2({
|
|
4204
4269
|
abi: ERC20_ABI,
|
|
4205
4270
|
functionName: "transfer",
|
|
4206
4271
|
args: [safeAddress, amountBigInt]
|
|
@@ -4208,6 +4273,142 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
4208
4273
|
value: "0"
|
|
4209
4274
|
};
|
|
4210
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
|
+
}
|
|
4361
|
+
/**
|
|
4362
|
+
* Prepare a gas-sponsored rZFI claim into the user's Safe on Base.
|
|
4363
|
+
*
|
|
4364
|
+
* @remarks
|
|
4365
|
+
* The SDK never signs. Sign `userOpHashToSign` with the owner EOA as a
|
|
4366
|
+
* personal_sign of the raw 32-byte hash (viem:
|
|
4367
|
+
* `signMessage({ message: { raw: userOpHashToSign } })`), then pass the
|
|
4368
|
+
* signature to {@link ZyfaiSDK.submitRzfiClaim} within 5 minutes.
|
|
4369
|
+
* Requires an authenticated user session.
|
|
4370
|
+
*
|
|
4371
|
+
* @group Rewards
|
|
4372
|
+
*
|
|
4373
|
+
* @param userAddress - Owner EOA
|
|
4374
|
+
* @returns `status: "pending"` with the hash to sign and the amount
|
|
4375
|
+
*
|
|
4376
|
+
* @throws If there is no rZFI to claim, or the reward tree is updating (retry later)
|
|
4377
|
+
*/
|
|
4378
|
+
async prepareRzfiClaim(userAddress) {
|
|
4379
|
+
this.assertRzfiClaimUser(userAddress);
|
|
4380
|
+
await this.authenticateUser();
|
|
4381
|
+
return this.httpClient.post(ENDPOINTS.RZFI_CLAIM, {});
|
|
4382
|
+
}
|
|
4383
|
+
/**
|
|
4384
|
+
* Submit the owner-signed rZFI claim prepared by {@link ZyfaiSDK.prepareRzfiClaim}.
|
|
4385
|
+
*
|
|
4386
|
+
* @group Rewards
|
|
4387
|
+
*
|
|
4388
|
+
* @param userAddress - Owner EOA
|
|
4389
|
+
* @param userOpSignature - Owner EOA signature over `userOpHashToSign`
|
|
4390
|
+
* @returns `status: "claimed"` with the on-chain `txHash`
|
|
4391
|
+
*
|
|
4392
|
+
* @throws If the signature is not the owner's, the claim expired, or it reverted
|
|
4393
|
+
*/
|
|
4394
|
+
async submitRzfiClaim(userAddress, userOpSignature) {
|
|
4395
|
+
this.assertRzfiClaimUser(userAddress);
|
|
4396
|
+
if (!userOpSignature?.startsWith("0x")) {
|
|
4397
|
+
throw new Error("A 0x-prefixed userOpSignature is required");
|
|
4398
|
+
}
|
|
4399
|
+
await this.authenticateUser();
|
|
4400
|
+
return this.httpClient.post(ENDPOINTS.RZFI_CLAIM, {
|
|
4401
|
+
userOpSignature
|
|
4402
|
+
});
|
|
4403
|
+
}
|
|
4404
|
+
assertRzfiClaimUser(userAddress) {
|
|
4405
|
+
if (!userAddress) {
|
|
4406
|
+
throw new Error("A user address is required");
|
|
4407
|
+
}
|
|
4408
|
+
if (this.sessionEoa && getAddress2(userAddress) !== this.sessionEoa) {
|
|
4409
|
+
throw new Error("userAddress does not match authenticated session EOA");
|
|
4410
|
+
}
|
|
4411
|
+
}
|
|
4211
4412
|
/** Apply the same per-asset minimum portfolio rule as sendDeposit. */
|
|
4212
4413
|
async enforceMinimumPortfolioBalance(chainId, asset, amount, safeAddress, userAddress) {
|
|
4213
4414
|
if (this.bypassMinPortfolio || isMainnetMinPortfolioExempt(chainId, userAddress, safeAddress)) {
|
|
@@ -5073,6 +5274,51 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
5073
5274
|
// ============================================================================
|
|
5074
5275
|
// TVL & Volume Methods
|
|
5075
5276
|
// ============================================================================
|
|
5277
|
+
/**
|
|
5278
|
+
* Get Zyfai's Merkl incentive campaigns on Base with their current APR.
|
|
5279
|
+
*
|
|
5280
|
+
* @group Analytics and opportunities
|
|
5281
|
+
*
|
|
5282
|
+
* @remarks Data API. Partner API key only; SIWE not required.
|
|
5283
|
+
*
|
|
5284
|
+
* @returns One entry per campaign slot (rZFI, new TVL, season campaign)
|
|
5285
|
+
*
|
|
5286
|
+
* @example
|
|
5287
|
+
* ```typescript
|
|
5288
|
+
* const campaigns = await sdk.getBaseMerklCampaigns();
|
|
5289
|
+
* for (const c of campaigns.filter((c) => c.isActive)) {
|
|
5290
|
+
* console.log(c.name, `${(c.apr * 100).toFixed(2)}%`);
|
|
5291
|
+
* }
|
|
5292
|
+
* ```
|
|
5293
|
+
*/
|
|
5294
|
+
async getBaseMerklCampaigns() {
|
|
5295
|
+
const ids = ["base/rzfi", "base-new-tvl", "base"];
|
|
5296
|
+
try {
|
|
5297
|
+
const now = Date.now();
|
|
5298
|
+
return await Promise.all(
|
|
5299
|
+
ids.map(async (id) => {
|
|
5300
|
+
const { campaign, currentStats } = await this.httpClient.dataGet(DATA_ENDPOINTS.MERKL_CAMPAIGN_INFO(id));
|
|
5301
|
+
return {
|
|
5302
|
+
id,
|
|
5303
|
+
name: campaign.name,
|
|
5304
|
+
apr: Number(currentStats.currentAPR),
|
|
5305
|
+
tvlUsd: currentStats.totalTVL,
|
|
5306
|
+
activeWallets: currentStats.activeWallets,
|
|
5307
|
+
rewardToken: campaign.rewardToken,
|
|
5308
|
+
totalRewards: campaign.totalRewards,
|
|
5309
|
+
dailyRewardAmount: campaign.dailyRewardAmount,
|
|
5310
|
+
startDate: campaign.startDate,
|
|
5311
|
+
endDate: campaign.endDate,
|
|
5312
|
+
isActive: now >= Date.parse(campaign.startDate) && now < Date.parse(campaign.endDate)
|
|
5313
|
+
};
|
|
5314
|
+
})
|
|
5315
|
+
);
|
|
5316
|
+
} catch (error) {
|
|
5317
|
+
throw new Error(
|
|
5318
|
+
`Failed to get Base Merkl campaigns: ${error.message}`
|
|
5319
|
+
);
|
|
5320
|
+
}
|
|
5321
|
+
}
|
|
5076
5322
|
/**
|
|
5077
5323
|
* Get total value locked (TVL) across all Zyfai accounts.
|
|
5078
5324
|
*
|
|
@@ -6325,7 +6571,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
6325
6571
|
if (!tokenUriResponse.tokenUri) {
|
|
6326
6572
|
throw new Error("API did not return a tokenUri");
|
|
6327
6573
|
}
|
|
6328
|
-
const callData =
|
|
6574
|
+
const callData = encodeFunctionData2({
|
|
6329
6575
|
abi: IDENTITY_REGISTRY_ABI,
|
|
6330
6576
|
functionName: "register",
|
|
6331
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",
|