Skip to main content

Staking1155Base

EXTENSION: Staking1155 The Staking1155Base smart contract implements NFT staking mechanism. Allows users to stake their ERC-1155 NFTs and earn rewards in form of ERC-20 tokens. Following features and implementation setup must be noted: - ERC-1155 NFTs from only one collection can be staked. - Contract admin can choose to give out rewards by either transferring or minting the rewardToken, which is an ERC20 token. See {_mintRewards}. - To implement custom logic for staking, reward calculation, etc. corresponding functions can be overridden from the extension Staking1155. - Ownership of the contract, with the ability to restrict certain functions to only be called by the contract's owner. - Multicall capability to perform multiple actions atomically.

Methods

claimRewards

function claimRewards(uint256 _tokenId) external nonpayable

Claim accumulated rewards.

See {_claimRewards}. Override that to implement custom logic. See {_calculateRewards} for reward-calculation logic.

Parameters

NameTypeDescription
_tokenIduint256Staked token Id.

contractURI

function contractURI() external view returns (string)

Returns the contract metadata URI.

Returns

NameTypeDescription
_0stringundefined

getDefaultRewardsPerUnitTime

function getDefaultRewardsPerUnitTime() external view returns (uint256 _rewardsPerUnitTime)

Returns

NameTypeDescription
_rewardsPerUnitTimeuint256undefined

getDefaultTimeUnit

function getDefaultTimeUnit() external view returns (uint256 _timeUnit)

Returns

NameTypeDescription
_timeUnituint256undefined

getRewardTokenBalance

function getRewardTokenBalance() external view returns (uint256 _rewardsAvailableInContract)

View total rewards available in the staking contract.

Returns

NameTypeDescription
_rewardsAvailableInContractuint256undefined

getRewardsPerUnitTime

function getRewardsPerUnitTime(uint256 _tokenId) external view returns (uint256 _rewardsPerUnitTime)

Parameters

NameTypeDescription
_tokenIduint256undefined

Returns

NameTypeDescription
_rewardsPerUnitTimeuint256undefined

getStakeInfo

function getStakeInfo(address _staker) external view returns (uint256[] _tokensStaked, uint256[] _tokenAmounts, uint256 _totalRewards)

View all tokens staked and total rewards for a user.

Parameters

NameTypeDescription
_stakeraddressAddress for which to calculated rewards.

Returns

NameTypeDescription
_tokensStakeduint256[]List of token-ids staked.
_tokenAmountsuint256[]Amount of each token-id staked.
_totalRewardsuint256Total rewards available.

getStakeInfoForToken

function getStakeInfoForToken(uint256 _tokenId, address _staker) external view returns (uint256 _tokensStaked, uint256 _rewards)

View amount staked and rewards for a user, for a given token-id.

Parameters

NameTypeDescription
_tokenIduint256undefined
_stakeraddressAddress for which to calculated rewards.

Returns

NameTypeDescription
_tokensStakeduint256Amount of tokens staked for given token-id.
_rewardsuint256Available reward amount.

getTimeUnit

function getTimeUnit(uint256 _tokenId) external view returns (uint256 _timeUnit)

Parameters

NameTypeDescription
_tokenIduint256undefined

Returns

NameTypeDescription
_timeUnituint256undefined

indexedTokens

function indexedTokens(uint256) external view returns (uint256)

Parameters

NameTypeDescription
_0uint256undefined

Returns

NameTypeDescription
_0uint256undefined

isIndexed

function isIndexed(uint256) external view returns (bool)

Parameters

NameTypeDescription
_0uint256undefined

Returns

NameTypeDescription
_0boolundefined

multicall

function multicall(bytes[] data) external nonpayable returns (bytes[] results)

Receives and executes a batch of function calls on this contract.

Receives and executes a batch of function calls on this contract.

Parameters

NameTypeDescription
databytes[]The bytes data that makes up the batch of function calls to execute.

Returns

NameTypeDescription
resultsbytes[]The bytes data that makes up the result of the batch of function calls executed.

owner

function owner() external view returns (address)

Returns the owner of the contract.

Returns

NameTypeDescription
_0addressundefined

rewardToken

function rewardToken() external view returns (address)

ERC20 Reward Token address. See {_mintRewards} below.

Returns

NameTypeDescription
_0addressundefined

setContractURI

function setContractURI(string _uri) external nonpayable

Lets a contract admin set the URI for contract-level metadata.

Caller should be authorized to setup contractURI, e.g. contract admin. See {_canSetContractURI}. Emits {ContractURIUpdated Event}.

Parameters

NameTypeDescription
_uristringkeccak256 hash of the role. e.g. keccak256("TRANSFER_ROLE")

setDefaultRewardsPerUnitTime

function setDefaultRewardsPerUnitTime(uint256 _defaultRewardsPerUnitTime) external nonpayable

Set rewards per unit of time. Interpreted as x rewards per second/per day/etc based on time-unit.

Only admin/authorized-account can call it.

Parameters

NameTypeDescription
_defaultRewardsPerUnitTimeuint256New rewards per unit time.

setDefaultTimeUnit

function setDefaultTimeUnit(uint256 _defaultTimeUnit) external nonpayable

Set time unit. Set as a number of seconds. Could be specified as -- x 1 hours, x 1 days, etc.

Only admin/authorized-account can call it.

Parameters

NameTypeDescription
_defaultTimeUnituint256New time unit.

setOwner

function setOwner(address _newOwner) external nonpayable

Lets an authorized wallet set a new owner for the contract.

Parameters

NameTypeDescription
_newOwneraddressThe address to set as the new owner of the contract.

setRewardsPerUnitTime

function setRewardsPerUnitTime(uint256 _tokenId, uint256 _rewardsPerUnitTime) external nonpayable

Set rewards per unit of time. Interpreted as x rewards per second/per day/etc based on time-unit.

Only admin/authorized-account can call it.

Parameters

NameTypeDescription
_tokenIduint256ERC1155 token Id.
_rewardsPerUnitTimeuint256New rewards per unit time.

setTimeUnit

function setTimeUnit(uint256 _tokenId, uint256 _timeUnit) external nonpayable

Set time unit. Set as a number of seconds. Could be specified as -- x 1 hours, x 1 days, etc.

Only admin/authorized-account can call it.

Parameters

NameTypeDescription
_tokenIduint256ERC1155 token Id.
_timeUnituint256New time unit.

stake

function stake(uint256 _tokenId, uint256 _amount) external nonpayable

Stake ERC721 Tokens.

See {_stake}. Override that to implement custom logic.

Parameters

NameTypeDescription
_tokenIduint256ERC1155 token-id to stake.
_amountuint256Amount to stake.

stakers

function stakers(uint256, address) external view returns (uint256 amountStaked, uint256 timeOfLastUpdate, uint256 unclaimedRewards, uint256 conditionIdOflastUpdate)

Parameters

NameTypeDescription
_0uint256undefined
_1addressundefined

Returns

NameTypeDescription
amountStakeduint256undefined
timeOfLastUpdateuint256undefined
unclaimedRewardsuint256undefined
conditionIdOflastUpdateuint256undefined

stakersArray

function stakersArray(uint256, uint256) external view returns (address)

Parameters

NameTypeDescription
_0uint256undefined
_1uint256undefined

Returns

NameTypeDescription
_0addressundefined

stakingToken

function stakingToken() external view returns (address)

Returns

NameTypeDescription
_0addressundefined

withdraw

function withdraw(uint256 _tokenId, uint256 _amount) external nonpayable

Withdraw staked tokens.

See {_withdraw}. Override that to implement custom logic.

Parameters

NameTypeDescription
_tokenIduint256ERC1155 token-id to withdraw.
_amountuint256Amount to withdraw.

Events

ContractURIUpdated

event ContractURIUpdated(string prevURI, string newURI)

Parameters

NameTypeDescription
prevURIstringundefined
newURIstringundefined

OwnerUpdated

event OwnerUpdated(address indexed prevOwner, address indexed newOwner)

Parameters

NameTypeDescription
prevOwner indexedaddressundefined
newOwner indexedaddressundefined

RewardsClaimed

event RewardsClaimed(address indexed staker, uint256 rewardAmount)

Parameters

NameTypeDescription
staker indexedaddressundefined
rewardAmountuint256undefined

TokensStaked

event TokensStaked(address indexed staker, uint256 indexed tokenId, uint256 amount)

Parameters

NameTypeDescription
staker indexedaddressundefined
tokenId indexeduint256undefined
amountuint256undefined

TokensWithdrawn

event TokensWithdrawn(address indexed staker, uint256 indexed tokenId, uint256 amount)

Parameters

NameTypeDescription
staker indexedaddressundefined
tokenId indexeduint256undefined
amountuint256undefined

UpdatedDefaultRewardsPerUnitTime

event UpdatedDefaultRewardsPerUnitTime(uint256 oldRewardsPerUnitTime, uint256 newRewardsPerUnitTime)

Parameters

NameTypeDescription
oldRewardsPerUnitTimeuint256undefined
newRewardsPerUnitTimeuint256undefined

UpdatedDefaultTimeUnit

event UpdatedDefaultTimeUnit(uint256 oldTimeUnit, uint256 newTimeUnit)

Parameters

NameTypeDescription
oldTimeUnituint256undefined
newTimeUnituint256undefined

UpdatedRewardsPerUnitTime

event UpdatedRewardsPerUnitTime(uint256 indexed _tokenId, uint256 oldRewardsPerUnitTime, uint256 newRewardsPerUnitTime)

Parameters

NameTypeDescription
_tokenId indexeduint256undefined
oldRewardsPerUnitTimeuint256undefined
newRewardsPerUnitTimeuint256undefined

UpdatedTimeUnit

event UpdatedTimeUnit(uint256 indexed _tokenId, uint256 oldTimeUnit, uint256 newTimeUnit)

Parameters

NameTypeDescription
_tokenId indexeduint256undefined
oldTimeUnituint256undefined
newTimeUnituint256undefined