This is a smart contract that monitors the Chainlink staking pool for withdrawals and uses Chainlink Automation to make deposits.
The Chainlink v0.2 Community Staking Pool recently opened for early access and filled up in a matter of hours. Unlike the v0.1 iteration, v0.2 gives participants the option to unstake their tokens, freeing up space for other participants.
Chainlink Auto Stake is a contract that uses Chainlink Automation to monitor the Community Staking Pool contract for available space and immediately deposit LINK tokens into it when that space appears.
Custom Logic Automation is used.
The checkUpkeep()
function returns true if the amount returned by the staking pool contract's getTotalPrincipal()
function returns less than its getMaxPoolSize()
function.
The performUpkeep()
function calls the transferAndCall()
function on the LINK token contract to stake LINK tokens with the staking pool contract. The amount of tokens staked depends on the available space in the staking pool and the balance of the contract. If the available space is less than the balance, an amount equivalent to the available space will be staked. Whereas if the available space is more than the balance, the full balance will be staked.
An ICommunityStakingPool
interface is used for interacting with the staking pool contract.
onlyOwner
modifiers are used to ensure only the owner of a contract can migrate, unstake and withdraw their LINK tokens.
To use this contract it must be funded with LINK tokens and registered with Chainlink Custom Logic Automation.
Please provide a .env
file that includes a $PRIVATE_KEY
and $RPC_URL
.
Then to deploy the Chainlink Auto Stake contract run the following command:
forge script script/DeployChainlinkAutoStake.s.sol --rpc-url $RPC_URL --private-key $PRIVATE_KEY --broadcast
The Mock Staking Pool contract can be deployed for testing purposes with the following command:
forge script script/DeployMockStakingPool.s.sol --rpc-url $RPC_URL --private-key $PRIVATE_KEY --broadcast
Tx of Automation depositing into staking pool when space available
This project is licensed under the MIT License.