Skip to main content

Epoch Management

Functions for managing and querying epoch information in the Trust Bonding contract.

trustBondingCurrentEpoch​

Get the current epoch number.

Returns​

Promise<bigint> // Current epoch number

Example​

import { trustBondingCurrentEpoch, getContractAddressFromChainId } from '@0xintuition/protocol'

const bondingAddress = getContractAddressFromChainId('TrustBonding', chainId)
const epoch = await trustBondingCurrentEpoch({ address: bondingAddress, publicClient })
console.log('Current epoch:', epoch)

trustBondingPreviousEpoch​

Get the previous epoch number.

Returns​

Promise<bigint>

Example​

import { trustBondingPreviousEpoch } from '@0xintuition/protocol'

const prevEpoch = await trustBondingPreviousEpoch({ address: bondingAddress, publicClient })
console.log('Previous epoch:', prevEpoch)

trustBondingEpochAtTimestamp​

Get the epoch number for a specific timestamp.

Parameters​

ParameterTypeDescriptionRequired
configReadConfigContract address and publicClientYes
args[bigint]Unix timestampYes

Returns​

Promise<bigint> // Epoch number at timestamp

Example​

import { trustBondingEpochAtTimestamp } from '@0xintuition/protocol'

const timestamp = BigInt(Math.floor(Date.now() / 1000))
const epoch = await trustBondingEpochAtTimestamp(
{ address: bondingAddress, publicClient },
{ args: [timestamp] }
)
console.log('Epoch at timestamp:', epoch)

trustBondingEpochTimestampEnd​

Get the end timestamp for an epoch.

Parameters​

ParameterTypeDescriptionRequired
configReadConfigContract address and publicClientYes
args[bigint]Epoch numberYes

Returns​

Promise<bigint> // Epoch end timestamp

Example​

import { trustBondingEpochTimestampEnd } from '@0xintuition/protocol'

const endTime = await trustBondingEpochTimestampEnd(
{ address: bondingAddress, publicClient },
{ args: [epochNumber] }
)

const endDate = new Date(Number(endTime) * 1000)
console.log('Epoch ends:', endDate.toISOString())

trustBondingEpochLength​

Get the length of an epoch in seconds.

Returns​

Promise<bigint> // Epoch duration in seconds

Example​

import { trustBondingEpochLength } from '@0xintuition/protocol'

const length = await trustBondingEpochLength({ address: bondingAddress, publicClient })
console.log('Epoch length:', length, 'seconds')
console.log('In days:', Number(length) / 86400)

trustBondingEpochsPerYear​

Get the number of epochs per year.

Returns​

Promise<bigint>

Example​

import { trustBondingEpochsPerYear } from '@0xintuition/protocol'

const epochsPerYear = await trustBondingEpochsPerYear({ address: bondingAddress, publicClient })
console.log('Epochs per year:', epochsPerYear)

See Also​