Reading State
Contract state can be gathered via multicall or by calling individual functions. The SDK provides some convenience functions for fetching state.
contractDetail()
The contractDetail
function returns a subset of the contract state and configuration. The response payload is the following struct:
struct ContractView {
/// @dev The number of tiers
uint16 tierCount;
/// @dev The number of subscriptions
uint64 subCount;
/// @dev The global supply cap
uint64 supplyCap;
/// @dev The transfer recipient address (0x0 for none)
address transferRecipient;
/// @dev The token address or 0x0 for ETH
address currency;
/// @dev The creator balance
uint256 creatorBalance;
/// @dev The total reward curves
uint8 numCurves;
/// @dev The number of issued shares
uint256 rewardShares;
/// @dev The current reward balance
uint256 rewardBalance;
/// @dev The reward slash grace period
uint32 rewardSlashGracePeriod;
/// @dev whether the pool is slashable
bool rewardSlashable;
}
subscriptionOf(address account)
The subscriptionOf
function returns the subscription state for a given account. The response payload is the following struct:
struct SubscriberView {
/// @dev The tier id of the subscription
uint16 tierId;
/// @dev The tokenId for the subscription
uint64 tokenId;
/// @dev The expiration timestamp of the subscription
uint48 expiresAt;
/// @dev The number of reward shares held
uint256 rewardShares;
/// @dev The claimable reward balance
uint256 rewardBalance;
}
tierDetail(uint16 tierId)
The tierDetail
function returns the tier state for a given tier. The response payload is the following struct:
struct State {
/// @dev The number of subscriptions in this tier
uint32 subCount;
/// @dev The id of the tier
uint16 id;
/// @dev The parameters for the tier
Tier params;
}
struct Tier {
/// @dev The minimimum subscription time for the tier
uint32 periodDurationSeconds;
/// @dev The maximum number of subscribers the tier can have (0 = unlimited)
uint32 maxSupply;
/// @dev The maximum number of future seconds a subscriber can hold (0 = unlimited)
uint48 maxCommitmentSeconds;
/// @dev The start timestamp for the tier (0 for deploy block time)
uint48 startTimestamp;
/// @dev The end timestamp for the tier (0 for never)
uint48 endTimestamp;
/// @dev The reward curve id to use
uint8 rewardCurveId;
/// @dev The reward bps
uint16 rewardBasisPoints;
/// @dev Whether the tier is paused (can subs mint or renew?)
bool paused;
/// @dev A flag to indicate if tokens can be transferred
bool transferrable;
/// @dev The initial mint price to join the tier
uint256 initialMintPrice;
/// @dev The price per period to renew the subscription (can be 0 for pay what you want tiers)
uint256 pricePerPeriod;
/// @dev The gate to use to check for subscription eligibility
Gate gate;
}
struct Gate {
/// @dev The type of gate to use
GateType gateType;
/// @dev The address of the gate contract
address contractAddress;
/// @dev The id of the component to check for eligibility (for 1155 its the token id, for STP its the tier id)
uint256 componentId;
/// @dev The minimum balance required to join the tier
uint256 balanceMin;
}
enum GateType {
NONE, // 0
ERC20, // 1
ERC721, // 2
ERC1155, // 3
STPV2 // 4
}
curveDetail(uint8 curveId)
The curveDetail
function returns the curve config for a given curve. The response payload is the following struct:
struct CurveParams {
/// @dev the number of periods for which rewards are paid (acts as the exponent)
uint8 numPeriods;
/// @dev The base of the exponential formula for reward calculations
uint8 formulaBase;
/// @dev the period duration in seconds
uint48 periodSeconds;
/// @dev the start timestamp for rewards
uint48 startTimestamp;
/// @dev the minimum multiplier for rewards
uint8 minMultiplier;
}
feeDetail()
The feeDetail
function returns the fee configuration for the contract. The response payload is the following struct:
struct FeeParams {
/// @dev the protocol fee recipient
address protocolRecipient;
/// @dev the protocol fee in basis points
uint16 protocolBps;
/// @dev the client fee recipient
address clientRecipient;
/// @dev the client fee in basis points
uint16 clientBps;
}
ERC721 Functions
name()
- Returns the name of the contractsymbol()
- Returns the symbol of the contractcontractURI()
- The contract level metadata URItokenURI(uint256 tokenId)
- Returns the token URI for a given token IDbalanceOf(address account)
- Returns the balance of a given account (seconds remaining)ownerOf(uint256 tokenId)
- Returns the owner of a given token IDgetApproved(uint256 tokenId)
- Returns the approved address for a given token IDisApprovedForAll(address owner, address operator)
- Returns if an operator is approved for a given owner
AccessControl Functions
owner()
- The owner of the contractpendingOwner()
- The pending owner of the contract (for ownership acceptance)
SDK Usage
import {
fetchState,
ContractState,
} from '@withfabric/protocol-sdks/stpv2';
// Fetches contract state along with tiers and curves
const state = await fetchState({
contractAddress: '0x...',
chainId: 8453,
});
console.log(state.subCount);