Attest Atom
Attestations allow users to signal support for Atoms by depositing ETH into their associated vaults. Each deposit represents a stake in the Atom's relevance and validity, with the ability to redeem these stakes later.
Context
The depositAtom
and redeemAtom
functions are part of the EthMultiVault contract, which manages the staking and signaling mechanisms for Atoms. When attesting to an Atom, users deposit ETH into the Atom's vault, receiving shares proportional to their deposit. These shares can later be redeemed to withdraw the original deposit plus any accrued rewards or minus any fees.
depositAtom
function depositAtom(
address receiver,
uint256 id
) external payable nonReentrant whenNotPaused returns (uint256)
Parameters
receiver
: Address to receive the vault sharesid
: Vault ID of the Atomvalue
: Amount of ETH to deposit- Returns:
uint256
- Amount of shares received
Implementation
// useDepositAtom Hook
import { type GetContractReturnType } from 'viem'
import { base } from 'viem/chains'
import { useContractWriteAndWait } from './useContractWriteAndWait'
import { useMultivaultContract } from './useMultivaultContract'
export const useDepositAtom = () => {
const multivault = useMultivaultContract(
base.id,
) as GetContractReturnType
return useContractWriteAndWait({
...multivault,
functionName: 'depositAtom',
})
}
// Usage Example
const {
writeAsync: writeDepositAtom,
awaitingWalletConfirmation,
awaitingOnChainConfirmation,
} = useDepositAtom()
async function handleDepositAtom(atomId: string, amount: bigint) {
if (
!awaitingOnChainConfirmation &&
!awaitingWalletConfirmation &&
writeDepositAtom
) {
try {
const tx = await writeDepositAtom({
address: MULTIVAULT_CONTRACT_ADDRESS,
abi: multivaultAbi,
functionName: 'depositAtom',
args: [address, BigInt(atomId)],
value: amount,
})
if (tx?.hash) {
const receipt = await publicClient.waitForTransactionReceipt({
hash: tx.hash,
})
// Handle success
}
} catch (error) {
// Handle error
}
}
}
redeemAtom
function redeemAtom(
uint256 shares,
address receiver,
uint256 id
) external nonReentrant returns (uint256)
Parameters
shares
: Number of vault shares to redeemreceiver
: Address to receive the redeemed ETHid
: Vault ID of the Atom- Returns:
uint256
- Amount of ETH received
Implementation
// useRedeemAtom Hook
import { type GetContractReturnType } from 'viem'
import { base } from 'viem/chains'
import { useContractWriteAndWait } from './useContractWriteAndWait'
import { useMultivaultContract } from './useMultivaultContract'
export const useRedeemAtom = () => {
const multivault = useMultivaultContract(
base.id,
) as GetContractReturnType
return useContractWriteAndWait({
...multivault,
functionName: 'redeemAtom',
})
}
// Usage Example
const {
writeAsync: writeRedeemAtom,
awaitingWalletConfirmation,
awaitingOnChainConfirmation,
} = useRedeemAtom()
async function handleRedeemAtom(atomId: string, shares: bigint) {
if (
!awaitingOnChainConfirmation &&
!awaitingWalletConfirmation &&
writeRedeemAtom
) {
try {
const tx = await writeRedeemAtom({
address: MULTIVAULT_CONTRACT_ADDRESS,
abi: multivaultAbi,
functionName: 'redeemAtom',
args: [shares, address, BigInt(atomId)],
})
if (tx?.hash) {
const receipt = await publicClient.waitForTransactionReceipt({
hash: tx.hash,
})
// Handle success
}
} catch (error) {
// Handle error
}
}
}
Cost Considerations
- Deposit Fees:
- Entry fee: Percentage taken from deposit
- Protocol fee: Portion sent to protocol treasury
- Gas fees: Network transaction costs
- Redemption Fees:
- Exit fee: Percentage taken from withdrawal
- Protocol fee: Portion sent to protocol treasury
See also: