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β
| Parameter | Type | Description | Required |
|---|---|---|---|
| config | ReadConfig | Contract address and publicClient | Yes |
| args | [bigint] | Unix timestamp | Yes |
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β
| Parameter | Type | Description | Required |
|---|---|---|---|
| config | ReadConfig | Contract address and publicClient | Yes |
| args | [bigint] | Epoch number | Yes |
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)