Skip to content

Commit

Permalink
feat: add Tenderizer::adapter to Tenderizer API
Browse files Browse the repository at this point in the history
  • Loading branch information
kyriediculous committed Nov 30, 2023
1 parent f0258b5 commit 9c29cb6
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 17 deletions.
18 changes: 7 additions & 11 deletions src/tenderizer/Tenderizer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,6 @@ contract Tenderizer is TenderizerImmutableArgs, TenderizerEvents, TToken, Multic
return string.concat(ERC20(asset()).symbol(), "-", addressToString(validator()));
}

function _adapter() internal view returns (Adapter) {
return Adapter(_registry().adapter(asset()));
}

function previewDeposit(uint256 assets) external view returns (uint256) {
uint256 out = abi.decode(_staticcall(address(this), abi.encodeCall(this._previewDeposit, (assets))), (uint256));
Storage storage $ = _loadStorage();
Expand All @@ -201,31 +197,31 @@ contract Tenderizer is TenderizerImmutableArgs, TenderizerEvents, TToken, Multic
// using a `staticcall` to `this`.
// This is a hacky workaround while better solidity features are being developed.
function _previewDeposit(uint256 assets) public returns (uint256) {
return abi.decode(_adapter()._delegatecall(abi.encodeCall(_adapter().previewDeposit, (assets))), (uint256));
return abi.decode(adapter()._delegatecall(abi.encodeCall(adapter().previewDeposit, (assets))), (uint256));
}

function _previewWithdraw(uint256 unlockID) public returns (uint256) {
return abi.decode(_adapter()._delegatecall(abi.encodeCall(_adapter().previewWithdraw, (unlockID))), (uint256));
return abi.decode(adapter()._delegatecall(abi.encodeCall(adapter().previewWithdraw, (unlockID))), (uint256));
}

function _unlockMaturity(uint256 unlockID) public returns (uint256) {
return abi.decode(_adapter()._delegatecall(abi.encodeCall(_adapter().unlockMaturity, (unlockID))), (uint256));
return abi.decode(adapter()._delegatecall(abi.encodeCall(adapter().unlockMaturity, (unlockID))), (uint256));
}
// ===============================================================================================================

function _rebase(address validator, uint256 currentStake) internal returns (uint256 newStake) {
newStake = abi.decode(_adapter()._delegatecall(abi.encodeCall(_adapter().rebase, (validator, currentStake))), (uint256));
newStake = abi.decode(adapter()._delegatecall(abi.encodeCall(adapter().rebase, (validator, currentStake))), (uint256));
}

function _stake(address validator, uint256 amount) internal {
_adapter()._delegatecall(abi.encodeCall(_adapter().stake, (validator, amount)));
adapter()._delegatecall(abi.encodeCall(adapter().stake, (validator, amount)));
}

function _unstake(address validator, uint256 amount) internal returns (uint256 unlockID) {
unlockID = abi.decode(_adapter()._delegatecall(abi.encodeCall(_adapter().unstake, (validator, amount))), (uint256));
unlockID = abi.decode(adapter()._delegatecall(abi.encodeCall(adapter().unstake, (validator, amount))), (uint256));
}

function _withdraw(address validator, uint256 unlockID) internal returns (uint256 withdrawAmount) {
withdrawAmount = abi.decode(_adapter()._delegatecall(abi.encodeCall(_adapter().withdraw, (validator, unlockID))), (uint256));
withdrawAmount = abi.decode(adapter()._delegatecall(abi.encodeCall(adapter().withdraw, (validator, unlockID))), (uint256));
}
}
5 changes: 5 additions & 0 deletions src/tenderizer/TenderizerBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pragma solidity >=0.8.19;
import { Clone } from "clones/Clone.sol";
import { Unlocks } from "core/unlocks/Unlocks.sol";
import { Registry } from "core/registry/Registry.sol";
import { Adapter } from "core/adapters/Adapter.sol";

/// @title TenderizerImmutableArgs
/// @notice Immutable arguments for Tenderizer
Expand Down Expand Up @@ -46,6 +47,10 @@ abstract contract TenderizerImmutableArgs is Clone {
return _getArgAddress(20); // start: 20 end: 39
}

function adapter() public view returns (Adapter) {
return Adapter(_registry().adapter(asset()));
}

function _registry() internal view returns (Registry) {
return Registry(registry);
}
Expand Down
2 changes: 1 addition & 1 deletion test/helpers/StakingXYZ.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ contract StakingXYZ {
uint256 public constant APR_PRECISION = 1e6;
uint256 public constant SECONDS_IN_A_YEAR = 31_536_000;

uint256 immutable unlockTime;
uint256 public immutable unlockTime;

struct Unlock {
uint256 amount;
Expand Down
8 changes: 8 additions & 0 deletions test/helpers/XYZAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ contract XYZAdapter is Adapter {
(, maturity) = StakingXYZ(STAKINGXYZ).unlocks(address(this), unlockID);
}

function unlockTime() external view returns (uint256) {
return StakingXYZ(STAKINGXYZ).unlockTime();
}

function currentTime() external view returns (uint256) {
return block.timestamp;
}

function stake(address, uint256 amount) external {
ERC20(XYZ_TOKEN).approve(STAKINGXYZ, amount);
StakingXYZ(STAKINGXYZ).stake(amount);
Expand Down
4 changes: 0 additions & 4 deletions test/tenderizer/Tenderizer.harness.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ import { Registry } from "core/registry/Registry.sol";
contract TenderizerHarness is Tenderizer {
constructor(address _registry, address _unlocks) Tenderizer(_registry, _unlocks) { }

function exposed_adapter() public view returns (Adapter) {
return _adapter();
}

function exposed_registry() public view returns (Registry) {
return _registry();
}
Expand Down
2 changes: 1 addition & 1 deletion test/tenderizer/Tenderizer.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ contract TenderizerTest is TenderizerSetup, TenderizerEvents {
assertEq(address(tenderizer.validator()), validator, "invalid validator");
assertEq(address(tenderizer.exposed_registry()), registry, "invalid registry");
assertEq(address(tenderizer.exposed_unlocks()), unlocks, "invalid unlocks");
assertEq(address(tenderizer.exposed_adapter()), adapter, "invalid adapter");
assertEq(address(tenderizer.adapter()), adapter, "invalid adapter");
}

function test_PreviewDeposit() public {
Expand Down

0 comments on commit 9c29cb6

Please sign in to comment.