@vetro-protocol/earn
v1.2.0
Published
Vetro Protocol staking-vault actions for viem.
Readme
@vetro-protocol/earn
Vetro Protocol staking-vault actions for viem clients. Wraps the sVUSD and sVetBTC ERC-4626 vaults with their deposit, cooldown, and withdraw flows.
Installation
pnpm add @vetro-protocol/earn viemOverview
- Targets the two whitelisted staking vaults —
sVUSDandsVetBTC— exported assVusdAddress,sVetBtcAddress, and the combinedstakingVaultAddresseslist. depositruns the full ERC-4626 deposit: on-chain allowance check, approval if needed, thendeposit(assets, receiver). Each step emits through anEventEmitter.- Withdrawals follow the vault's cooldown protocol:
requestRedeem/requestWithdrawopens a cooldown,claimWithdraw/claimWithdrawBatchfinalises it once the cooldown elapses, andcancelWithdrawaborts an open request. - Read actions (
getCooldownDuration,getCooldownEnabled,getInstantWithdrawWhitelist,getPendingRequests,getActiveRequestIds,getClaimableRequests,getRequestDetails,getTotalAssetsInCooldown,getYieldDistributor) cover the data needed to drive a UI around the flows above.
Usage
import {
deposit,
getPendingRequests,
sVusdAddress,
} from "@vetro-protocol/earn";
import { createPublicClient, createWalletClient, custom, http } from "viem";
import { hemi } from "viem/chains";
const publicClient = createPublicClient({ chain: hemi, transport: http() });
const walletClient = createWalletClient({
chain: hemi,
transport: custom(window.ethereum),
});
// Stake VUSD into sVUSD (approval handled automatically).
const { emitter, promise } = deposit(walletClient, {
assets: 1_000_000_000_000_000_000n,
receiver: "0x...",
token: "0x...", // underlying VUSD address
vaultAddress: sVusdAddress,
});
emitter.on("user-signed-deposit", (hash) => console.log("tx hash:", hash));
emitter.on("deposit-transaction-succeeded", (receipt) =>
console.log("deposited:", receipt),
);
await promise;
// Inspect any pending withdraw requests for the user.
const pending = await getPendingRequests(publicClient, {
account: "0x...",
address: sVusdAddress,
});The same actions are also available via .extend() factories (earnPublicActions(), earnWalletActions()) for callers who prefer viem's extension pattern.
API
- Public actions (reads):
getActiveRequestIds(client, params)— open withdraw request IDs for an account.getClaimableRequests(client, params)— request IDs whose cooldown has elapsed.getCooldownDuration(client, params)— cooldown length in seconds.getCooldownEnabled(client, params)— whether the cooldown is enforced.getInstantWithdrawWhitelist(client, params)— accounts allowed to bypass cooldown.getPendingRequests(client, params)— full pending-request structs for an account.getRequestDetails(client, params)— details for a specific request ID.getTotalAssetsInCooldown(client, params)— assets locked across all pending requests.getYieldDistributor(client, params)— address of the vault's yield distributor.
- Wallet actions (writes):
deposit,requestRedeem,requestWithdraw,claimWithdraw,claimWithdrawBatch,cancelWithdraw. Each returns{ emitter, promise }. - Calldata encoders, exported from
/actions: each returns the calldata of one write without sending anything, so a caller can sign and broadcast it elsewhere, or batch it into a multicall:encodeCancelWithdraw({ requestId })—cancelWithdraw(requestId).encodeClaimWithdraw({ receiver, requestId })—claimWithdraw(requestId, receiver).encodeClaimWithdrawBatch({ receiver, requestIds })—claimWithdrawBatch(requestIds, receiver).encodeDeposit({ assets, receiver })—deposit(assets, receiver). Unlikedeposit, it does not approve the pegged token first. It throws whenassetsis not greater than 0 orreceiveris not a valid address.encodeRedeem({ owner, receiver, shares })—redeem(shares, receiver, owner). The vault accepts it only when the cooldown is disabled orowneris on the instant-withdraw whitelist. It throws whensharesis not greater than 0 or an address is not valid.encodeRequestRedeem({ owner, shares })—requestRedeem(shares, owner).encodeRequestWithdraw({ assets, owner })—requestWithdraw(assets, owner).encodeWithdraw({ assets, owner, receiver })—withdraw(assets, receiver, owner). The vault accepts it only when the cooldown is disabled orowneris on the instant-withdraw whitelist. It throws whenassetsis not greater than 0 or an address is not valid.
earnPublicActions()/earnWalletActions()— viem extension factories that wire the same actions onto a client via.extend().stakingVaultAbi— the minimal ABI subset used by the package.- Constants:
sVusdAddress,sVetBtcAddress,stakingVaultAddresses. - Hemi Earn metadata, exported from
@vetro-protocol/earn/hemiEarn: off-chain information that Hemi Earn frontends show for Vetro vaults.hemiEarnVaults— orderedHemiEarnVault[]; frontends show only these vaults, in this order. Each entry hasaddress(Ethereum staking vault),apyIncludesFees(whether the Vetro API APY is net of fees),curators?(brand names of the curators running the vault's live strategies; only if different from the operator),operator(full legal name) andtypicalTransferTime(seconds; how long a cross-chain transfer usually takes, in either direction).hemiEarnLinks— URLs of pages hosted by Vetro:privacyPolicyUrl,supportUrlandtermsOfUseUrl.
- Types:
CancelWithdrawEvents,ClaimWithdrawBatchEvents,ClaimWithdrawEvents,CooldownRequest,DepositEvents,RequestRedeemEvents,RequestWithdrawEvents.
