Aller au contenu principal

Attest to Triple

Attestations in the Intuition system allow users to signal their agreement or disagreement with Triples by depositing ETH into either the positive or negative vault. Each deposit represents a stake in the Triple's validity, with the ability to redeem these stakes later.

Context

The depositTriple and redeemTriple functions are part of the EthMultiVault contract, which manages the staking and signaling mechanisms for Triples. When attesting to a Triple, users deposit ETH into either the positive or negative 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 losses.

For example, given the Triple:

  • Subject: "Bob" (Atom ID: "1")
  • Predicate: "is" (Atom ID: "2")
  • Object: "Trustworthy" (Atom ID: "3")

Users can:

  • Deposit into the positive vault to agree with "Bob is Trustworthy"
  • Deposit into the negative vault to disagree with "Bob is Trustworthy"
  • Not deposit to remain neutral

depositTriple

function depositTriple(
address receiver,
uint256 id
) external payable nonReentrant whenNotPaused returns (uint256)

Parameters

  • receiver: Address to receive the vault shares
  • id: Vault ID of the Triple (positive or negative vault)
  • value: Amount of ETH to deposit
  • Returns: uint256 - Amount of shares received

Implementation

// useDepositTriple Hook
import { type GetContractReturnType } from 'viem'
import { base } from 'viem/chains'
import { useContractWriteAndWait } from './useContractWriteAndWait'
import { useMultivaultContract } from './useMultivaultContract'

export const useDepositTriple = () => {
const multivault = useMultivaultContract(
base.id
) as GetContractReturnType

return useContractWriteAndWait({
...multivault,
functionName: 'depositTriple',
})
}

// Usage Example
const {
writeAsync: writeDepositTriple,
awaitingWalletConfirmation,
awaitingOnChainConfirmation,
} = useDepositTriple()

async function handleDepositTriple(tripleId: string, amount: bigint, isPositive: boolean) {
if (!awaitingOnChainConfirmation && !awaitingWalletConfirmation && writeDepositTriple) {
try {
// Get the appropriate vault ID based on positive/negative attestation
const vaultId = isPositive ? tripleId : await getCounterIdFromTriple(tripleId)

const tx = await writeDepositTriple({
address: MULTIVAULT_CONTRACT_ADDRESS,
abi: multivaultAbi,
functionName: 'depositTriple',
args: [address, BigInt(vaultId)],
value: amount,
})

if (tx?.hash) {
const receipt = await publicClient.waitForTransactionReceipt({
hash: tx.hash,
})
// Handle success
}
} catch (error) {
// Handle error
}
}
}

redeemTriple

function redeemTriple(
uint256 shares,
address receiver,
uint256 id
) external nonReentrant returns (uint256)

Parameters

  • shares: Number of vault shares to redeem
  • receiver: Address to receive the redeemed ETH
  • id: Vault ID of the Triple (positive or negative vault)
  • Returns: uint256 - Amount of ETH received

Implementation

// useRedeemTriple Hook
import { type GetContractReturnType } from 'viem'
import { base } from 'viem/chains'
import { useContractWriteAndWait } from './useContractWriteAndWait'
import { useMultivaultContract } from './useMultivaultContract'

export const useRedeemTriple = () => {
const multivault = useMultivaultContract(
base.id
) as GetContractReturnType

return useContractWriteAndWait({
...multivault,
functionName: 'redeemTriple',
})
}

// Usage Example
const {
writeAsync: writeRedeemTriple,
awaitingWalletConfirmation,
awaitingOnChainConfirmation,
} = useRedeemTriple()

async function handleRedeemTriple(tripleId: string, shares: bigint, isPositive: boolean) {
if (!awaitingOnChainConfirmation && !awaitingWalletConfirmation && writeRedeemTriple) {
try {
// Get the appropriate vault ID based on positive/negative attestation
const vaultId = isPositive ? tripleId : await getCounterIdFromTriple(tripleId)

const tx = await writeRedeemTriple({
address: MULTIVAULT_CONTRACT_ADDRESS,
abi: multivaultAbi,
functionName: 'redeemTriple',
args: [shares, address, BigInt(vaultId)],
})

if (tx?.hash) {
const receipt = await publicClient.waitForTransactionReceipt({
hash: tx.hash,
})
// Handle success
}
} catch (error) {
// Handle error
}
}
}

Triple Vaults

Each Triple has two associated vaults:

  1. Positive Vault:
    • Used for agreeing with the Triple's statement
    • Shares represent support for the claim
    • Value increases with positive attestations
    • ID is the same as the Triple's ID
  2. Negative Vault:
    • Used for disagreeing with the Triple's statement
    • Shares represent opposition to the claim
    • Value increases with negative attestations
    • ID can be retrieved using getCounterIdFromTriple(tripleId)

Users can only attest to one vault at a time for a given Triple. To switch positions, users must first redeem their shares from one vault before depositing into the other.

Cost Considerations

  1. Deposit Fees:
    • Entry fee: Percentage taken from deposit
    • Protocol fee: Portion sent to protocol treasury
  2. Redemption Fees:
    • Exit fee: Percentage taken from withdrawal
    • Protocol fee: Portion sent to protocol treasury

See also: