-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add ClaimAndStake contract (#32)
* feat: Add claimAndStake method To make dApp more useful, add method to claim from external merkle distributor and stake atomically * store merkle distributor in state * use contracts 1.0.5 * Fix * Rename * Update AcceleratingDistributor.ClaimAndStake.ts * Add ADClaimAndStake * Update AcceleratingDistributor.ClaimAndStake.ts * Update AcceleratingDistributorClaimAndStake.sol * Refactor with ClaimAndStake * Update AcceleratingDistributor.sol * matts comments * Update ClaimAndStake.sol * Reverse param order for stakeFor * Update yarn.lock * fix * fix
- Loading branch information
1 parent
1838f45
commit dde7aed
Showing
13 changed files
with
2,602 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// SPDX-License-Identifier: GPL-3.0-only | ||
pragma solidity ^0.8.0; | ||
|
||
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; | ||
import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; | ||
import "@openzeppelin/contracts/security/ReentrancyGuard.sol"; | ||
import "@openzeppelin/contracts/utils/Multicall.sol"; | ||
import "@across-protocol/contracts-v2/contracts/merkle-distributor/AcrossMerkleDistributor.sol"; | ||
import "./AcceleratingDistributor.sol"; | ||
|
||
/** | ||
* @notice Allows claimer to claim tokens from AcrossMerkleDistributor and stake into AcceleratingDistributor | ||
* atomically in a single transaction. This intermediary contract also removes the need for claimer to approve | ||
* AcceleratingDistributor to spend its staking tokens. | ||
*/ | ||
|
||
contract ClaimAndStake is ReentrancyGuard, Multicall { | ||
using SafeERC20 for IERC20; | ||
|
||
// Contract which rewards tokens to users that they can then stake. | ||
AcrossMerkleDistributor public immutable merkleDistributor; | ||
|
||
// Contract that user stakes claimed tokens into. | ||
AcceleratingDistributor public immutable acceleratingDistributor; | ||
|
||
constructor(AcrossMerkleDistributor _merkleDistributor, AcceleratingDistributor _acceleratingDistributor) { | ||
merkleDistributor = _merkleDistributor; | ||
acceleratingDistributor = _acceleratingDistributor; | ||
} | ||
|
||
/************************************** | ||
* ADMIN FUNCTIONS * | ||
**************************************/ | ||
|
||
/** | ||
* @notice Claim tokens from a MerkleDistributor contract and stake them for rewards in AcceleratingDistributor. | ||
* @dev Will revert if `merkleDistributor` is not set to valid MerkleDistributor contract. | ||
* @dev Will revert if the claim recipient account is not equal to caller, or if the reward token | ||
* for claim is not a valid staking token. | ||
* @dev Will revert if this contract is not a "whitelisted claimer" on the MerkleDistributor contract. | ||
* @param _claim Claim leaf to retrieve from MerkleDistributor. | ||
*/ | ||
function claimAndStake(MerkleDistributorInterface.Claim memory _claim) external nonReentrant { | ||
require(_claim.account == msg.sender, "claim account not caller"); | ||
address stakedToken = merkleDistributor.getRewardTokenForWindow(_claim.windowIndex); | ||
merkleDistributor.claimFor(_claim); | ||
IERC20(stakedToken).safeIncreaseAllowance(address(acceleratingDistributor), _claim.amount); | ||
acceleratingDistributor.stakeFor(stakedToken, _claim.amount, msg.sender); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// SPDX-License-Identifier: GPL-3.0-only | ||
import "@across-protocol/contracts-v2/contracts/merkle-distributor/AcrossMerkleDistributor.sol"; | ||
|
||
pragma solidity ^0.8.0; | ||
|
||
/// @notice Pass through contract that allows tests to access MerkleDistributor from /artifacts via | ||
// utils.getContractFactory() | ||
contract MerkleDistributorTest is AcrossMerkleDistributor { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import "hardhat-deploy"; | ||
import { HardhatRuntimeEnvironment } from "hardhat/types/runtime"; | ||
|
||
const func = async function (hre: HardhatRuntimeEnvironment) { | ||
const { deployments, getNamedAccounts } = hre; | ||
const { deploy } = deployments; | ||
const { deployer } = await getNamedAccounts(); | ||
|
||
await deploy("AcrossMerkleDistributor", { | ||
from: deployer, | ||
log: true, | ||
skipIfAlreadyDeployed: true, | ||
args: [], | ||
}); | ||
}; | ||
|
||
module.exports = func; | ||
func.tags = ["AcrossMerkleDistributor", "mainnet"]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import "hardhat-deploy"; | ||
import { HardhatRuntimeEnvironment } from "hardhat/types/runtime"; | ||
|
||
const func = async function (hre: HardhatRuntimeEnvironment) { | ||
const { deployments, getNamedAccounts } = hre; | ||
const { deploy } = deployments; | ||
const { deployer } = await getNamedAccounts(); | ||
|
||
const merkleDistributor = await deployments.get("AcrossMerkleDistributor"); | ||
const acceleratingDistributor = await deployments.get("AcceleratingDistributor"); | ||
|
||
await deploy("ClaimAndStake", { | ||
from: deployer, | ||
log: true, | ||
skipIfAlreadyDeployed: true, | ||
args: [merkleDistributor.address, acceleratingDistributor.address], | ||
}); | ||
}; | ||
|
||
module.exports = func; | ||
func.tags = ["ClaimAndStake", "mainnet"]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.