Verified contractPartialMIT
ArkVault
Address0x2d5de2109a183170ee3aca46c92df65ab8b56b0e
- Balance
0 ETH
- Transactions
271
- Compiler
solc 0.8.26
- Same code
Only this contract
Details
- Compiler
- solc 0.8.26+commit.8a97fa7a
- Language
- solidity
- Optimization
- Yes, 200 runs
- EVM version
- cancun
- License
- MIT
- Match
- Partialcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 25,100,064
- Creation transaction
- 0x6f92d7507c…aeb775c4d5
17 files
- src/vault/ArkVault.solmain46.08 KB
- lib/v4-core/lib/openzeppelin-contracts/contracts/access/Ownable.sol3.1 KB
- lib/v4-core/lib/openzeppelin-contracts/contracts/access/Ownable2Step.sol1.99 KB
- lib/v4-core/lib/openzeppelin-contracts/contracts/utils/Context.sol963 B
- src/interfaces/IArkBoarding.sol1.4 KB
- src/interfaces/IArkBuybackLogic.sol246 B
- src/interfaces/IArkLaunchExposureGuard.sol1.9 KB
- src/interfaces/IArkNoahPass.sol181 B
- src/interfaces/IArkRewardReservoir.sol189 B
- src/interfaces/IArkVault.sol842 B
- src/interfaces/IERC20.sol708 B
- src/interfaces/IWrappedNative.sol224 B
- src/locking/ArkLock.sol3.05 KB
- src/security/ArkOwnable.sol474 B
- src/security/ArkRecoverable.sol1.68 KB
- src/security/ArkReentrancyGuard.sol912 B
- src/token/ArkLark.sol2.34 KB
src/vault/ArkVault.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
import {IArkBoarding} from "../interfaces/IArkBoarding.sol";
import {IArkBuybackLogic} from "../interfaces/IArkBuybackLogic.sol";
import {IArkLaunchExposureGuard} from "../interfaces/IArkLaunchExposureGuard.sol";
import {IArkRewardReservoir} from "../interfaces/IArkRewardReservoir.sol";
import {IArkNoahPass} from "../interfaces/IArkNoahPass.sol";
import {IArkVault} from "../interfaces/IArkVault.sol";
import {IERC20} from "../interfaces/IERC20.sol";
import {IWrappedNative} from "../interfaces/IWrappedNative.sol";
import {ArkLock} from "../locking/ArkLock.sol";
import {ArkRecoverable} from "../security/ArkRecoverable.sol";
import {ArkLark} from "../token/ArkLark.sol";
contract ArkVault is IArkVault, ArkRecoverable {
error ZeroAddress();
error ZeroAmount();
error UnsupportedAsset();
error Unauthorized();
error NoValue();
error InactivePosition();
error TransferFailed();
error AlreadySet();
error ReceiptsNotSet();
error LockClosed();
error LockNotMatured();
error LockMatured();
error InvalidDuration();
error LaunchExposureGuardAlreadySet();
error EmptyBatch();
error BatchTooLarge(uint256 size, uint256 maxSize);
event VaultValueReceived(address indexed asset, address indexed from, uint256 amount);
event VaultValueBuffered(bytes32 indexed lane, address indexed asset, uint256 amount);
event VaultValueClaimed(
address indexed user,
uint256 indexed positionId,
address indexed asset,
uint256 grossAmount,
uint256 feeAmount,
uint256 netAmount
);
event VaultValueCompounded(
address indexed user, uint256 indexed positionId, address indexed asset, uint256 amount
);
event PositionSettled(uint256 indexed positionId, address indexed asset, uint256 amount);
event LockCreated(
address indexed user,
uint256 indexed lockId,
uint256 amount,
uint256 lockedAt,
uint256 unlocksAt,
uint256 maturityEpoch
);
event LockSettled(uint256 indexed lockId, address indexed asset, uint256 amount);
event LockedValueClaimed(
address indexed user, uint256 indexed lockId, address indexed asset, uint256 amount
);
event LockedValueCompounded(
address indexed user,
uint256 indexed sourceLockId,
uint256 indexed newLockId,
uint256 amount
);
event LockUnlocked(address indexed user, uint256 indexed lockId, uint256 amount);
event Checkpoint(uint256 timestamp, uint256 baseTokenReleased, uint256 lockedTokenReleased);
event LockReceiptsSet(address indexed lockReceipt, address indexed lockNft);
event ReservoirSet(address indexed reservoir);
event LaunchExposureGuardSet(address indexed guard);
event SpecialLockPassSet(address indexed specialLockPass);
event LockedWethRedirectTargetSet(address indexed target);
event PositionCreatedSynced(uint256 indexed positionId, uint256 rewardPerActiveBoarded);
event PositionClosedSynced(uint256 indexed positionId, uint256 rewardPerActiveBoarded);
event NativeEthPaymentFallback(address indexed receiver, uint256 amount);
event UnallocatedLockedTokenBurned(uint256 indexed epoch, uint256 amount);
event UnallocatedLockedWethRedirected(
uint256 indexed epoch, address indexed target, uint256 amount
);
uint256 internal constant SCALE = 1e18;
uint256 internal constant BPS = 10_000;
uint256 public constant GENESIS_STREAM_DURATION = 200 days;
uint256 internal constant GENESIS_BASE_BPS = 3_400;
uint256 internal constant GENESIS_LOCKED_BPS = 6_600;
uint256 public constant GENESIS_BASE_BUDGET = 27_200e18;
uint256 public constant GENESIS_LOCKED_BUDGET = 52_800e18;
uint256 public constant MAX_LOCK_ACCOUNTING_BUCKETS = 64;
uint256 public constant MAX_CLAIM_BATCH_SIZE = 20;
uint256 public constant MAX_UNLOCK_BATCH_SIZE = 8;
address internal constant DEAD = 0x000000000000000000000000000000000000dEaD;
bytes32 internal constant BASE_LANE = keccak256("ARK_BASE_LANE");
bytes32 internal constant LOCKED_LANE = keccak256("ARK_LOCKED_LANE");
struct LockPosition {
address owner;
uint256 amount;
uint64 lockedAt;
uint64 unlocksAt;
uint64 maturityEpoch;
bool closed;
}
IArkBoarding public immutable boarding;
address public immutable tokenAsset;
address public immutable wethAsset;
address public immutable feeRouter;
uint256 public immutable lockDuration;
uint256 public immutable maturityEpochDuration;
ArkLark public lockReceipt;
ArkLock public lockNft;
IArkRewardReservoir public reservoir;
IArkLaunchExposureGuard public launchExposureGuard;
IArkNoahPass public specialLockPass;
IArkBuybackLogic public lockedWethRedirectTarget;
uint256 public genesisStreamStart;
uint256 private lastCheckpointTime;
uint256 private lastLockedCheckpointTime;
uint256 private genesisBaseReleased;
uint256 private genesisLockedReleased;
uint256 public rewardPerActiveBoarded;
uint256 public rewardPerLocked;
uint256 public rewardPerLockedWeth;
uint256 private undistributedLockedTokenScaled;
uint256 private undistributedLockedWethScaled;
uint256 private undistributedBaseTokenScaled;
uint256 public unallocatedBaseToken;
uint256 public unallocatedLockedToken;
uint256 public unallocatedLockedWeth;
uint256 public burnedUnallocatedLockedToken;
uint256 public redirectedUnallocatedLockedWeth;
uint256 public nextLockId = 1;
uint256 public activeTotalLocked;
uint256 public rewardActiveTotalLocked;
uint256 public nextActivationSettlementIndex;
uint256 private nextMaturitySettlementIndex;
mapping(uint256 positionId => uint256 debt) private positionBaseRewardPaid;
mapping(uint256 positionId => uint256 amount) private accruedBaseToken;
mapping(uint256 positionId => bool closed) private isClosed;
mapping(uint256 lockId => LockPosition position) public locks;
mapping(address owner => uint256[] lockIds) private ownerLocks;
mapping(uint256 lockId => uint256 epoch) public lockRewardStartEpoch;
mapping(uint256 lockId => uint256 epoch) public lockNextSettlementEpoch;
mapping(uint256 lockId => uint256 amount) private accruedLockedToken;
mapping(uint256 lockId => uint256 amount) private accruedLockedWeth;
mapping(uint256 lockId => uint256 rewardPerLockedPaid) private lockRewardPerLockedPaid;
mapping(uint256 lockId => uint256 rewardPerLockedWethPaid) private lockRewardPerLockedWethPaid;
mapping(uint256 epoch => uint256 amount) private activatingLockedAtEpoch;
mapping(uint256 epoch => uint256 amount) private maturingActiveLockedAtEpoch;
mapping(uint256 epoch => uint256 rewardPerLockedSnapshot) private activationRewardPerLocked;
mapping(uint256 epoch => uint256 rewardPerLockedWethSnapshot) private
activationRewardPerLockedWeth;
mapping(uint256 epoch => bool settled) private activationEpochSettled;
mapping(uint256 epoch => uint256 rewardPerLockedSnapshot) private maturityRewardPerLocked;
mapping(uint256 epoch => uint256 rewardPerLockedWethSnapshot) private
maturityRewardPerLockedWeth;
mapping(uint256 epoch => bool settled) private maturityEpochSettled;
uint256[] private activationEpochList;
mapping(uint256 epoch => bool listed) private activationEpochListed;
uint256[] private maturityEpochList;
mapping(uint256 epoch => bool listed) private maturityEpochListed;
address[2] private assets;
constructor(
IArkBoarding boarding_,
address tokenAsset_,
address wethAsset_,
address feeRouter_,
uint256 lockDuration_,
uint256 maturityEpochDuration_,
address initialOwner
) ArkRecoverable(initialOwner) {
if (address(boarding_) == address(0)) revert ZeroAddress();
if (tokenAsset_ == address(0)) revert ZeroAddress();
if (wethAsset_ == address(0)) revert ZeroAddress();
if (feeRouter_ == address(0)) revert ZeroAddress();
if (lockDuration_ == 0 || maturityEpochDuration_ == 0) revert InvalidDuration();
boarding = boarding_;
tokenAsset = tokenAsset_;
wethAsset = wethAsset_;
feeRouter = feeRouter_;
lockDuration = lockDuration_;
maturityEpochDuration = maturityEpochDuration_;
genesisStreamStart = block.timestamp;
lastCheckpointTime = block.timestamp;
lastLockedCheckpointTime = block.timestamp;
assets[0] = tokenAsset_;
assets[1] = wethAsset_;
}
receive() external payable {
if (msg.sender != wethAsset) revert Unauthorized();
}
function _isRecoverableToken(address asset) internal view override returns (bool) {
return asset != tokenAsset && asset != wethAsset;
}
modifier onlyBoarding() {
if (msg.sender != address(boarding)) revert Unauthorized();
_;
}
modifier onlyFeeRouter() {
if (msg.sender != feeRouter) revert Unauthorized();
_;
}
function setLockReceipts(ArkLark lark_, ArkLock lockNft_) external onlyOwner {
if (address(lark_) == address(0) || address(lockNft_) == address(0)) revert ZeroAddress();
if (address(lockReceipt) != address(0) || address(lockNft) != address(0)) {
revert AlreadySet();
}
lockReceipt = lark_;
lockNft = lockNft_;
emit LockReceiptsSet(address(lark_), address(lockNft_));
}
function setReservoir(IArkRewardReservoir reservoir_) external onlyOwner {
if (address(reservoir_) == address(0)) revert ZeroAddress();
if (address(reservoir) != address(0)) revert AlreadySet();
reservoir = reservoir_;
genesisStreamStart = block.timestamp;
lastCheckpointTime = block.timestamp;
lastLockedCheckpointTime = block.timestamp;
emit ReservoirSet(address(reservoir_));
}
function setLaunchExposureGuard(IArkLaunchExposureGuard guard_) external onlyOwner {
if (address(guard_) == address(0)) revert ZeroAddress();
if (address(launchExposureGuard) != address(0)) revert LaunchExposureGuardAlreadySet();
launchExposureGuard = guard_;
emit LaunchExposureGuardSet(address(guard_));
}
function setSpecialLockPass(IArkNoahPass specialLockPass_) external onlyOwner {
if (address(specialLockPass_) == address(0)) revert ZeroAddress();
if (address(specialLockPass) != address(0)) revert AlreadySet();
specialLockPass = specialLockPass_;
emit SpecialLockPassSet(address(specialLockPass_));
}
function setLockedWethRedirectTarget(IArkBuybackLogic target_) external onlyOwner {
if (address(target_) == address(0)) revert ZeroAddress();
if (address(lockedWethRedirectTarget) != address(0)) revert AlreadySet();
lockedWethRedirectTarget = target_;
emit LockedWethRedirectTargetSet(address(target_));
}
function notifyBaseReward(address asset, uint256 amount) external nonReentrant onlyFeeRouter {
_receiveBaseReward(asset, amount);
}
function notifyLockedReward(address asset, uint256 amount) external nonReentrant onlyFeeRouter {
_receiveLockedReward(asset, amount);
}
function beforePositionCreated() external nonReentrant onlyBoarding {
_syncBase();
}
function onPositionCreated(uint256 positionId) external nonReentrant onlyBoarding {
positionBaseRewardPaid[positionId] = rewardPerActiveBoarded;
_distributeUnallocatedBase();
emit PositionCreatedSynced(positionId, rewardPerActiveBoarded);
}
function beforePositionAmountChange(uint256 positionId) external nonReentrant onlyBoarding {
_syncBase();
_settleBase(positionId);
}
function onPositionClosed(uint256 positionId) external nonReentrant onlyBoarding {
isClosed[positionId] = true;
positionBaseRewardPaid[positionId] = rewardPerActiveBoarded;
emit PositionClosedSynced(positionId, rewardPerActiveBoarded);
}
function claimPositionRewardFromBoarding(uint256 positionId, address receiver)
external
nonReentrant
onlyBoarding
{
if (receiver == address(0)) revert ZeroAddress();
address owner = boarding.positionOwner(positionId);
_payBaseAccrued(owner, positionId, receiver);
}
function lock(uint256 amount, address receiver) external nonReentrant returns (uint256 lockId) {
_requireReceipts();
if (amount == 0) revert ZeroAmount();
if (receiver == address(0)) revert ZeroAddress();
if (!IERC20(tokenAsset).transferFrom(msg.sender, address(this), amount)) {
revert TransferFailed();
}
if (address(launchExposureGuard) != address(0)) {
launchExposureGuard.increaseLocked(receiver, msg.sender, amount);
}
lockId = _createLock(receiver, amount);
}
function unlock(uint256 lockId, address receiver) external nonReentrant {
_unlock(lockId, receiver, true);
}
function unlockAsWeth(uint256 lockId, address receiver) external nonReentrant {
_unlock(lockId, receiver, false);
}
function unlockMany(uint256[] calldata lockIds, address receiver) external nonReentrant {
_unlockMany(lockIds, receiver, true);
}
function unlockManyAsWeth(uint256[] calldata lockIds, address receiver) external nonReentrant {
_unlockMany(lockIds, receiver, false);
}
function _unlockMany(uint256[] calldata lockIds, address receiver, bool unwrapWeth) internal {
uint256 count = lockIds.length;
if (count == 0) revert EmptyBatch();
if (count > MAX_UNLOCK_BATCH_SIZE) revert BatchTooLarge(count, MAX_UNLOCK_BATCH_SIZE);
for (uint256 i = 0; i < count; i++) {
_unlock(lockIds[i], receiver, unwrapWeth);
}
}
function _unlock(uint256 lockId, address receiver, bool unwrapWeth) internal {
if (receiver == address(0)) revert ZeroAddress();
LockPosition storage position = locks[lockId];
address owner = _requireLockOwner(lockId);
if (position.closed) revert LockClosed();
if (block.timestamp < position.maturityEpoch) revert LockNotMatured();
_settleLocked(lockId);
uint256 amount = position.amount;
uint256 tokenReward = accruedLockedToken[lockId];
uint256 wethReward = accruedLockedWeth[lockId];
if (tokenReward != 0) accruedLockedToken[lockId] = 0;
if (wethReward != 0) accruedLockedWeth[lockId] = 0;
position.closed = true;
activeTotalLocked -= amount;
if (address(launchExposureGuard) != address(0)) {
launchExposureGuard.decreaseLocked(owner, amount);
}
lockReceipt.burn(owner, amount);
lockNft.burn(lockId);
if (address(launchExposureGuard) != address(0)) {
launchExposureGuard.allowTokenRelease(owner, receiver, amount + tokenReward);
}
if (!IERC20(tokenAsset).transfer(receiver, amount + tokenReward)) revert TransferFailed();
if (tokenReward != 0) {
emit LockedValueClaimed(owner, lockId, tokenAsset, tokenReward);
}
if (wethReward != 0) {
_payLockedWeth(receiver, wethReward, unwrapWeth);
emit LockedValueClaimed(owner, lockId, wethAsset, wethReward);
}
emit LockUnlocked(owner, lockId, amount);
}
function pendingValue(uint256 positionId, address asset) public view returns (uint256) {
if (asset == wethAsset) return 0;
if (asset != tokenAsset) revert UnsupportedAsset();
uint256 pending = accruedBaseToken[positionId];
uint256 indexDelta = rewardPerActiveBoarded - positionBaseRewardPaid[positionId];
uint256 amount = boarding.activeBoardedAmount(positionId);
return pending + amount * indexDelta / SCALE;
}
function pendingLockedValue(uint256 lockId, address asset) public view returns (uint256) {
if (asset != tokenAsset && asset != wethAsset) revert UnsupportedAsset();
LockPosition storage position = locks[lockId];
if (position.owner == address(0)) return 0;
(uint256 tokenAmount, uint256 wethAmount) = _previewLockedSettlement(lockId);
if (asset == tokenAsset) return accruedLockedToken[lockId] + tokenAmount;
return accruedLockedWeth[lockId] + wethAmount;
}
function claim(uint256 positionId, address receiver) external nonReentrant {
_claimBase(positionId, receiver);
}
function claim(uint256 positionId, address asset, address receiver) external nonReentrant {
if (asset != tokenAsset) revert UnsupportedAsset();
_claimBase(positionId, receiver);
}
function claimMany(uint256[] calldata positionIds, uint256[] calldata lockIds, address receiver)
external
nonReentrant
{
uint256 positionCount = positionIds.length;
uint256 lockCount = lockIds.length;
uint256 count = positionCount + lockCount;
if (count == 0) revert EmptyBatch();
if (count > MAX_CLAIM_BATCH_SIZE) revert BatchTooLarge(count, MAX_CLAIM_BATCH_SIZE);
for (uint256 i = 0; i < positionCount; i++) {
_claimBase(positionIds[i], receiver);
}
for (uint256 i = 0; i < lockCount; i++) {
_claimLockedAll(lockIds[i], receiver, true);
}
}
function claimLocked(uint256 lockId, address receiver) external nonReentrant {
_claimLockedAll(lockId, receiver, true);
}
function claimLockedAsWeth(uint256 lockId, address receiver) external nonReentrant {
_claimLockedAll(lockId, receiver, false);
}
function claimLocked(uint256 lockId, address asset, address receiver) external nonReentrant {
_claimLocked(lockId, asset, receiver, true);
}
function claimLockedAsWeth(uint256 lockId, address asset, address receiver)
external
nonReentrant
{
_claimLocked(lockId, asset, receiver, false);
}
function compound(uint256 positionId) external nonReentrant {
_compoundBase(positionId);
}
function compound(uint256 positionId, address asset) external nonReentrant {
if (asset != tokenAsset) revert UnsupportedAsset();
_compoundBase(positionId);
}
function compoundLocked(uint256 lockId) external nonReentrant returns (uint256 newLockId) {
_requireReceipts();
address owner = _requireLockOwner(lockId);
LockPosition storage position = locks[lockId];
if (position.closed) revert LockClosed();
if (block.timestamp >= position.maturityEpoch) revert LockMatured();
_settleLocked(lockId);
uint256 amount = accruedLockedToken[lockId];
if (amount == 0) revert NoValue();
accruedLockedToken[lockId] = 0;
if (address(launchExposureGuard) != address(0)) {
launchExposureGuard.increaseLockedFromReward(owner, amount);
}
newLockId = _createLock(owner, amount);
emit LockedValueCompounded(owner, lockId, newLockId, amount);
}
function supportedAssetAt(uint256 index) external view returns (address) {
return assets[index];
}
function lockIdsOf(address owner) external view returns (uint256[] memory) {
return ownerLocks[owner];
}
function maturityEpochCount() external view returns (uint256) {
return maturityEpochList.length;
}
function maturityEpochAt(uint256 index) external view returns (uint256) {
return maturityEpochList[index];
}
function settleMaturityBuckets(uint256 maxBuckets)
external
nonReentrant
returns (uint256 processed)
{
if (maxBuckets == 0) revert EmptyBatch();
if (maxBuckets > MAX_LOCK_ACCOUNTING_BUCKETS) {
revert BatchTooLarge(maxBuckets, MAX_LOCK_ACCOUNTING_BUCKETS);
}
return _syncLocked(maxBuckets);
}
function _receiveBaseReward(address asset, uint256 amount) internal {
if (asset != tokenAsset) revert UnsupportedAsset();
if (amount == 0) revert ZeroAmount();
_syncBase();
if (!IERC20(asset).transferFrom(msg.sender, address(this), amount)) {
revert TransferFailed();
}
_fundBaseArk(amount);
emit VaultValueReceived(asset, msg.sender, amount);
}
function _receiveLockedReward(address asset, uint256 amount) internal {
if (asset != tokenAsset && asset != wethAsset) revert UnsupportedAsset();
if (amount == 0) revert ZeroAmount();
_syncLocked();
if (!IERC20(asset).transferFrom(msg.sender, address(this), amount)) {
revert TransferFailed();
}
uint256 epoch = _epochStart(block.timestamp);
if (asset == tokenAsset) {
_fundLockedArk(epoch, amount);
} else {
_fundLockedWeth(epoch, amount);
}
emit VaultValueReceived(asset, msg.sender, amount);
}
function _claimBase(uint256 positionId, address receiver) internal {
if (receiver == address(0)) revert ZeroAddress();
address owner = _requirePositionOwner(positionId);
_syncBase();
_settleBase(positionId);
uint256 amount = accruedBaseToken[positionId];
if (amount == 0) return;
accruedBaseToken[positionId] = 0;
_payBaseAmount(owner, positionId, receiver, amount);
}
function _claimLocked(uint256 lockId, address asset, address receiver, bool unwrapWeth)
internal
{
if (asset != tokenAsset && asset != wethAsset) revert UnsupportedAsset();
if (receiver == address(0)) revert ZeroAddress();
address owner = _requireLockOwner(lockId);
_settleLocked(lockId);
uint256 amount;
if (asset == tokenAsset) {
amount = accruedLockedToken[lockId];
accruedLockedToken[lockId] = 0;
} else {
amount = accruedLockedWeth[lockId];
accruedLockedWeth[lockId] = 0;
}
if (amount == 0) return;
if (asset == tokenAsset) {
if (address(launchExposureGuard) != address(0)) {
launchExposureGuard.allowTokenRelease(owner, receiver, amount);
}
if (!IERC20(tokenAsset).transfer(receiver, amount)) revert TransferFailed();
} else {
_payLockedWeth(receiver, amount, unwrapWeth);
}
emit LockedValueClaimed(owner, lockId, asset, amount);
}
function _claimLockedAll(uint256 lockId, address receiver, bool unwrapWeth) internal {
if (receiver == address(0)) revert ZeroAddress();
address owner = _requireLockOwner(lockId);
_settleLocked(lockId);
uint256 tokenAmount = accruedLockedToken[lockId];
uint256 wethAmount = accruedLockedWeth[lockId];
if (tokenAmount != 0) accruedLockedToken[lockId] = 0;
if (wethAmount != 0) accruedLockedWeth[lockId] = 0;
if (tokenAmount != 0) {
if (address(launchExposureGuard) != address(0)) {
launchExposureGuard.allowTokenRelease(owner, receiver, tokenAmount);
}
if (!IERC20(tokenAsset).transfer(receiver, tokenAmount)) revert TransferFailed();
emit LockedValueClaimed(owner, lockId, tokenAsset, tokenAmount);
}
if (wethAmount != 0) {
_payLockedWeth(receiver, wethAmount, unwrapWeth);
emit LockedValueClaimed(owner, lockId, wethAsset, wethAmount);
}
}
function _compoundBase(uint256 positionId) internal {
if (!boarding.isPositionActive(positionId)) revert InactivePosition();
address owner = _requirePositionOwner(positionId);
_syncBase();
_settleBase(positionId);
uint256 amount = accruedBaseToken[positionId];
if (amount == 0) revert NoValue();
accruedBaseToken[positionId] = 0;
if (!IERC20(tokenAsset).approve(address(boarding), amount)) revert TransferFailed();
boarding.addPrincipalFromVault(positionId, amount);
if (!IERC20(tokenAsset).approve(address(boarding), 0)) revert TransferFailed();
positionBaseRewardPaid[positionId] = rewardPerActiveBoarded;
emit VaultValueCompounded(owner, positionId, tokenAsset, amount);
}
function _settleBase(uint256 positionId) internal {
uint256 amount = boarding.activeBoardedAmount(positionId);
uint256 indexDelta = rewardPerActiveBoarded - positionBaseRewardPaid[positionId];
if (indexDelta != 0 && amount != 0) {
uint256 rewardAmount = amount * indexDelta / SCALE;
accruedBaseToken[positionId] += rewardAmount;
emit PositionSettled(positionId, tokenAsset, rewardAmount);
}
positionBaseRewardPaid[positionId] = rewardPerActiveBoarded;
}
function _settleLocked(uint256 lockId) internal {
LockPosition storage position = locks[lockId];
_syncLocked();
uint256 startEpoch = lockRewardStartEpoch[lockId];
if (startEpoch == 0 || block.timestamp < startEpoch || startEpoch >= position.maturityEpoch)
{
return;
}
uint256 tokenIndex = _lockTokenRewardCap(position);
uint256 tokenPaid = _lockTokenRewardPaid(lockId);
if (tokenIndex > tokenPaid && position.amount != 0) {
uint256 tokenAmount = position.amount * (tokenIndex - tokenPaid) / SCALE;
accruedLockedToken[lockId] += tokenAmount;
emit LockSettled(lockId, tokenAsset, tokenAmount);
}
lockRewardPerLockedPaid[lockId] = tokenIndex;
uint256 wethIndex = _lockWethRewardCap(position);
uint256 wethPaid = _lockWethRewardPaid(lockId);
if (wethIndex > wethPaid && position.amount != 0) {
uint256 wethAmount = position.amount * (wethIndex - wethPaid) / SCALE;
accruedLockedWeth[lockId] += wethAmount;
emit LockSettled(lockId, wethAsset, wethAmount);
}
lockRewardPerLockedWethPaid[lockId] = wethIndex;
uint256 nextSettlementEpoch = block.timestamp >= position.maturityEpoch
? uint256(position.maturityEpoch)
: _epochStart(block.timestamp);
if (nextSettlementEpoch > startEpoch) {
lockNextSettlementEpoch[lockId] = nextSettlementEpoch;
}
}
function _previewLockedSettlement(uint256 lockId)
internal
view
returns (uint256 tokenAmount, uint256 wethAmount)
{
LockPosition storage position = locks[lockId];
uint256 startEpoch = lockRewardStartEpoch[lockId];
if (startEpoch == 0 || block.timestamp < startEpoch || startEpoch >= position.maturityEpoch)
{
return (0, 0);
}
uint256 tokenIndex = _previewLockTokenRewardCap(position);
uint256 tokenPaid = _previewLockTokenRewardPaid(lockId);
if (tokenIndex > tokenPaid && position.amount != 0) {
tokenAmount = position.amount * (tokenIndex - tokenPaid) / SCALE;
}
uint256 wethIndex = _previewLockWethRewardCap(position);
uint256 wethPaid = _previewLockWethRewardPaid(lockId);
if (wethIndex > wethPaid && position.amount != 0) {
wethAmount = position.amount * (wethIndex - wethPaid) / SCALE;
}
}
function _createLock(address owner, uint256 amount) internal returns (uint256 lockId) {
_syncLocked();
lockId = nextLockId++;
uint64 lockedAt = uint64(block.timestamp);
uint64 unlocksAt = uint64(block.timestamp + lockDuration);
uint64 maturityEpoch = uint64(_nextMaturityEpoch(unlocksAt));
uint256 startEpoch = _epochStart(block.timestamp) + maturityEpochDuration;
if (startEpoch >= maturityEpoch) startEpoch = uint256(maturityEpoch);
locks[lockId] = LockPosition({
owner: owner,
amount: amount,
lockedAt: lockedAt,
unlocksAt: unlocksAt,
maturityEpoch: maturityEpoch,
closed: false
});
ownerLocks[owner].push(lockId);
lockRewardStartEpoch[lockId] = startEpoch;
lockNextSettlementEpoch[lockId] = startEpoch;
activeTotalLocked += amount;
if (startEpoch < maturityEpoch) {
_scheduleLockActivation(startEpoch, amount);
_scheduleMaturity(maturityEpoch, amount, amount);
} else {
_scheduleMaturity(maturityEpoch, amount, 0);
}
lockReceipt.mint(owner, amount);
lockNft.mint(owner, lockId);
if (address(specialLockPass) != address(0)) {
specialLockPass.mintIfEligible(owner, amount);
}
emit LockCreated(owner, lockId, amount, lockedAt, unlocksAt, maturityEpoch);
}
function _syncBase() internal returns (uint256 baseReleased) {
uint256 targetTime = block.timestamp;
if (targetTime <= lastCheckpointTime) {
emit Checkpoint(targetTime, 0, 0);
return 0;
}
baseReleased = _releaseBaseGenesisUntil(targetTime);
lastCheckpointTime = targetTime;
emit Checkpoint(targetTime, baseReleased, 0);
}
function _releaseBaseGenesisUntil(uint256 targetTime) internal returns (uint256 baseAmount) {
if (address(reservoir) == address(0)) return 0;
uint256 vestedBase = _vestedGenesis(GENESIS_BASE_BUDGET, targetTime);
if (vestedBase <= genesisBaseReleased) return 0;
if (boarding.activeTotalBoarded() == 0) {
genesisBaseReleased = vestedBase;
return 0;
}
baseAmount = vestedBase - genesisBaseReleased;
uint256 released = reservoir.releaseGenesisRewards(address(this), baseAmount);
if (released != baseAmount) revert TransferFailed();
genesisBaseReleased = vestedBase;
_fundBaseArk(baseAmount);
}
function _vestedGenesis(uint256 budget, uint256 targetTime) internal view returns (uint256) {
if (targetTime <= genesisStreamStart) return 0;
uint256 elapsed = targetTime - genesisStreamStart;
if (elapsed >= GENESIS_STREAM_DURATION) return budget;
return budget * elapsed / GENESIS_STREAM_DURATION;
}
function _fundBaseArk(uint256 amount) internal {
uint256 total = boarding.activeTotalBoarded();
if (total == 0) {
unallocatedBaseToken += amount;
emit VaultValueBuffered(BASE_LANE, tokenAsset, amount);
return;
}
_distributeBaseArk(amount, total);
}
function _fundLockedArk(uint256 epoch, uint256 amount) internal {
uint256 total = rewardActiveTotalLocked;
if (total == 0) {
burnedUnallocatedLockedToken += amount;
if (!IERC20(tokenAsset).transfer(DEAD, amount)) revert TransferFailed();
emit UnallocatedLockedTokenBurned(epoch, amount);
return;
}
_distributeLockedArkAtEpoch(epoch, amount, total);
}
function _fundLockedWeth(uint256 epoch, uint256 amount) internal {
uint256 total = rewardActiveTotalLocked;
if (total == 0) {
IArkBuybackLogic target = lockedWethRedirectTarget;
if (address(target) == address(0)) revert ZeroAddress();
redirectedUnallocatedLockedWeth += amount;
if (!IERC20(wethAsset).transfer(address(target), amount)) revert TransferFailed();
target.notifyRedirectedLockedReward(wethAsset, amount);
emit UnallocatedLockedWethRedirected(epoch, address(target), amount);
return;
}
_distributeLockedWethAtEpoch(epoch, amount, total);
}
function _distributeUnallocatedBase() internal {
uint256 amount = unallocatedBaseToken;
if (amount == 0) return;
uint256 total = boarding.activeTotalBoarded();
if (total == 0) return;
unallocatedBaseToken = 0;
_distributeBaseArk(amount, total);
}
function _distributeBaseArk(uint256 amount, uint256 total) internal {
uint256 scaledValue = amount * SCALE + undistributedBaseTokenScaled;
rewardPerActiveBoarded += scaledValue / total;
undistributedBaseTokenScaled = scaledValue % total;
}
function _distributeLockedArkAtEpoch(uint256 epoch, uint256 amount, uint256 total) internal {
uint256 scaledValue = amount * SCALE + undistributedLockedTokenScaled;
rewardPerLocked += scaledValue / total;
undistributedLockedTokenScaled = scaledValue % total;
}
function _distributeLockedWethAtEpoch(uint256 epoch, uint256 amount, uint256 total) internal {
uint256 scaledValue = amount * SCALE + undistributedLockedWethScaled;
rewardPerLockedWeth += scaledValue / total;
undistributedLockedWethScaled = scaledValue % total;
}
function _scheduleLockActivation(uint256 startEpoch, uint256 amount) internal {
if (!activationEpochListed[startEpoch]) {
activationEpochListed[startEpoch] = true;
activationEpochList.push(startEpoch);
}
activatingLockedAtEpoch[startEpoch] += amount;
}
function _scheduleMaturity(uint256 maturityEpoch, uint256 amount, uint256 rewardActiveAmount)
internal
{
if (!maturityEpochListed[maturityEpoch]) {
maturityEpochListed[maturityEpoch] = true;
maturityEpochList.push(maturityEpoch);
}
maturingActiveLockedAtEpoch[maturityEpoch] += rewardActiveAmount;
}
function _syncLocked() internal returns (uint256 processed) {
return _syncLocked(type(uint256).max);
}
function _syncLocked(uint256 maxBuckets) internal returns (uint256 processed) {
uint256 targetTime = block.timestamp;
if (lastLockedCheckpointTime == 0) {
lastLockedCheckpointTime = targetTime;
return 0;
}
bool limitReached;
while (true) {
uint256 nextEpoch = _nextLockAccountingEpoch();
if (nextEpoch > targetTime) break;
if (processed == maxBuckets) {
limitReached = true;
break;
}
if (nextEpoch > lastLockedCheckpointTime) {
_releaseLockedGenesisInterval(lastLockedCheckpointTime, nextEpoch);
lastLockedCheckpointTime = nextEpoch;
}
_settleLockAccountingEpoch(nextEpoch);
processed += 1;
}
if (!limitReached && lastLockedCheckpointTime < targetTime) {
_releaseLockedGenesisInterval(lastLockedCheckpointTime, targetTime);
lastLockedCheckpointTime = targetTime;
}
}
function _nextLockAccountingEpoch() internal view returns (uint256 nextEpoch) {
nextEpoch = type(uint256).max;
if (nextActivationSettlementIndex < activationEpochList.length) {
nextEpoch = activationEpochList[nextActivationSettlementIndex];
}
if (nextMaturitySettlementIndex < maturityEpochList.length) {
uint256 maturityEpoch = maturityEpochList[nextMaturitySettlementIndex];
if (maturityEpoch < nextEpoch) nextEpoch = maturityEpoch;
}
}
function _settleLockAccountingEpoch(uint256 epoch) internal {
while (
nextMaturitySettlementIndex < maturityEpochList.length
&& maturityEpochList[nextMaturitySettlementIndex] == epoch
) {
_settleMaturityEpoch(epoch);
nextMaturitySettlementIndex += 1;
}
while (
nextActivationSettlementIndex < activationEpochList.length
&& activationEpochList[nextActivationSettlementIndex] == epoch
) {
_settleActivationEpoch(epoch);
nextActivationSettlementIndex += 1;
}
}
function _settleActivationEpoch(uint256 epoch) internal {
if (!activationEpochSettled[epoch]) {
activationRewardPerLocked[epoch] = rewardPerLocked;
activationRewardPerLockedWeth[epoch] = rewardPerLockedWeth;
activationEpochSettled[epoch] = true;
}
rewardActiveTotalLocked += activatingLockedAtEpoch[epoch];
}
function _settleMaturityEpoch(uint256 epoch) internal {
if (!maturityEpochSettled[epoch]) {
maturityRewardPerLocked[epoch] = rewardPerLocked;
maturityRewardPerLockedWeth[epoch] = rewardPerLockedWeth;
maturityEpochSettled[epoch] = true;
}
uint256 amount = maturingActiveLockedAtEpoch[epoch];
if (amount == 0) return;
if (amount > rewardActiveTotalLocked) revert InvalidDuration();
rewardActiveTotalLocked -= amount;
}
function _releaseLockedGenesisInterval(uint256 fromTime, uint256 toTime)
internal
returns (uint256 amount)
{
if (toTime <= fromTime || address(reservoir) == address(0)) return 0;
uint256 vestedTo = _vestedGenesis(GENESIS_LOCKED_BUDGET, toTime);
uint256 vestedFrom = _vestedGenesis(GENESIS_LOCKED_BUDGET, fromTime);
if (vestedTo <= vestedFrom) return 0;
amount = vestedTo - vestedFrom;
if (amount == 0 || rewardActiveTotalLocked == 0) return 0;
genesisLockedReleased += amount;
uint256 released = reservoir.releaseGenesisRewards(address(this), amount);
if (released != amount) revert TransferFailed();
_distributeLockedArkAtEpoch(_epochStart(toTime), amount, rewardActiveTotalLocked);
}
function _nextMaturityEpoch(uint256 timestamp) internal view returns (uint256) {
uint256 remainder = timestamp % maturityEpochDuration;
if (remainder == 0) return timestamp;
return timestamp + maturityEpochDuration - remainder;
}
function _epochStart(uint256 timestamp) internal view returns (uint256) {
return timestamp - (timestamp % maturityEpochDuration);
}
function _lockTokenRewardCap(LockPosition storage position) internal view returns (uint256) {
if (block.timestamp >= position.maturityEpoch) {
return maturityRewardPerLocked[position.maturityEpoch];
}
return rewardPerLocked;
}
function _lockWethRewardCap(LockPosition storage position) internal view returns (uint256) {
if (block.timestamp >= position.maturityEpoch) {
return maturityRewardPerLockedWeth[position.maturityEpoch];
}
return rewardPerLockedWeth;
}
function _lockTokenRewardPaid(uint256 lockId) internal view returns (uint256) {
uint256 paid = lockRewardPerLockedPaid[lockId];
if (paid != 0) return paid;
return activationRewardPerLocked[lockRewardStartEpoch[lockId]];
}
function _lockWethRewardPaid(uint256 lockId) internal view returns (uint256) {
uint256 paid = lockRewardPerLockedWethPaid[lockId];
if (paid != 0) return paid;
return activationRewardPerLockedWeth[lockRewardStartEpoch[lockId]];
}
function _previewLockTokenRewardCap(LockPosition storage position)
internal
view
returns (uint256)
{
if (block.timestamp >= position.maturityEpoch) {
if (maturityEpochSettled[position.maturityEpoch]) {
return maturityRewardPerLocked[position.maturityEpoch];
}
return _previewLockedTokenRewardPerShareAt(position.maturityEpoch);
}
return _previewLockedTokenRewardPerShareAt(block.timestamp);
}
function _previewLockWethRewardCap(LockPosition storage position)
internal
view
returns (uint256)
{
if (
block.timestamp >= position.maturityEpoch
&& maturityEpochSettled[position.maturityEpoch]
) {
return maturityRewardPerLockedWeth[position.maturityEpoch];
}
return rewardPerLockedWeth;
}
function _previewLockTokenRewardPaid(uint256 lockId) internal view returns (uint256) {
uint256 paid = lockRewardPerLockedPaid[lockId];
if (paid != 0) return paid;
uint256 startEpoch = lockRewardStartEpoch[lockId];
if (activationEpochSettled[startEpoch]) return activationRewardPerLocked[startEpoch];
return _previewLockedTokenRewardPerShareAt(startEpoch);
}
function _previewLockWethRewardPaid(uint256 lockId) internal view returns (uint256) {
uint256 paid = lockRewardPerLockedWethPaid[lockId];
if (paid != 0) return paid;
uint256 startEpoch = lockRewardStartEpoch[lockId];
if (activationEpochSettled[startEpoch]) return activationRewardPerLockedWeth[startEpoch];
return rewardPerLockedWeth;
}
function _previewLockedTokenRewardPerShareAt(uint256 targetTime)
internal
view
returns (uint256 index)
{
index = rewardPerLocked;
uint256 remainder = undistributedLockedTokenScaled;
uint256 active = rewardActiveTotalLocked;
uint256 cursor = lastLockedCheckpointTime;
if (targetTime <= cursor) return index;
uint256 activationIndex = nextActivationSettlementIndex;
uint256 maturityIndex = nextMaturitySettlementIndex;
while (cursor < targetTime) {
uint256 nextEpoch = targetTime;
if (activationIndex < activationEpochList.length) {
uint256 activationEpoch = activationEpochList[activationIndex];
if (activationEpoch < nextEpoch) nextEpoch = activationEpoch;
}
if (maturityIndex < maturityEpochList.length) {
uint256 maturityEpoch = maturityEpochList[maturityIndex];
if (maturityEpoch < nextEpoch) nextEpoch = maturityEpoch;
}
if (nextEpoch > cursor) {
(index, remainder) =
_previewLockedGenesisInterval(cursor, nextEpoch, active, index, remainder);
cursor = nextEpoch;
}
if (cursor == targetTime) break;
while (
maturityIndex < maturityEpochList.length
&& maturityEpochList[maturityIndex] == cursor
) {
uint256 amount = maturingActiveLockedAtEpoch[cursor];
if (amount >= active) {
active = 0;
} else {
active -= amount;
}
maturityIndex += 1;
}
while (
activationIndex < activationEpochList.length
&& activationEpochList[activationIndex] == cursor
) {
active += activatingLockedAtEpoch[cursor];
activationIndex += 1;
}
}
}
function _previewLockedGenesisInterval(
uint256 fromTime,
uint256 toTime,
uint256 active,
uint256 index,
uint256 remainder
) internal view returns (uint256 nextIndex, uint256 nextRemainder) {
nextIndex = index;
nextRemainder = remainder;
if (toTime <= fromTime || active == 0 || address(reservoir) == address(0)) {
return (nextIndex, nextRemainder);
}
uint256 vestedTo = _vestedGenesis(GENESIS_LOCKED_BUDGET, toTime);
uint256 vestedFrom = _vestedGenesis(GENESIS_LOCKED_BUDGET, fromTime);
if (vestedTo <= vestedFrom) return (nextIndex, nextRemainder);
uint256 scaledValue = (vestedTo - vestedFrom) * SCALE + nextRemainder;
nextIndex += scaledValue / active;
nextRemainder = scaledValue % active;
}
function _payBaseAccrued(address owner, uint256 positionId, address receiver) internal {
uint256 amount = accruedBaseToken[positionId];
if (amount == 0) return;
accruedBaseToken[positionId] = 0;
_payBaseAmount(owner, positionId, receiver, amount);
}
function _payBaseAmount(address owner, uint256 positionId, address receiver, uint256 amount)
internal
{
if (address(launchExposureGuard) != address(0)) {
launchExposureGuard.allowTokenRelease(owner, receiver, amount);
}
if (!IERC20(tokenAsset).transfer(receiver, amount)) revert TransferFailed();
emit VaultValueClaimed(owner, positionId, tokenAsset, amount, 0, amount);
}
function _payNativeEth(address receiver, uint256 amount) internal {
IWrappedNative(wethAsset).withdraw(amount);
(bool sent,) = payable(receiver).call{value: amount}("");
if (sent) return;
IWrappedNative(wethAsset).deposit{value: amount}();
if (!IERC20(wethAsset).transfer(receiver, amount)) revert TransferFailed();
emit NativeEthPaymentFallback(receiver, amount);
}
function _payLockedWeth(address receiver, uint256 amount, bool unwrapWeth) internal {
if (unwrapWeth) {
_payNativeEth(receiver, amount);
} else if (!IERC20(wethAsset).transfer(receiver, amount)) {
revert TransferFailed();
}
}
function _requirePositionOwner(uint256 positionId) internal view returns (address owner) {
owner = boarding.positionOwner(positionId);
if (owner != msg.sender && !boarding.isOperatorFor(owner, msg.sender)) {
revert Unauthorized();
}
}
function _requireLockOwner(uint256 lockId) internal view returns (address owner) {
owner = locks[lockId].owner;
if (owner == address(0)) revert LockClosed();
if (owner != msg.sender) revert Unauthorized();
}
function _requireReceipts() internal view {
if (address(lockReceipt) == address(0) || address(lockNft) == address(0)) {
revert ReceiptsNotSet();
}
}
}
lib/v4-core/lib/openzeppelin-contracts/contracts/access/Ownable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)
pragma solidity ^0.8.20;
import {Context} from "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* The initial owner is set to the address provided by the deployer. This can
* later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
/**
* @dev The caller account is not authorized to perform an operation.
*/
error OwnableUnauthorizedAccount(address account);
/**
* @dev The owner is not a valid owner account. (eg. `address(0)`)
*/
error OwnableInvalidOwner(address owner);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the address provided by the deployer as the initial owner.
*/
constructor(address initialOwner) {
if (initialOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(initialOwner);
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
if (owner() != _msgSender()) {
revert OwnableUnauthorizedAccount(_msgSender());
}
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
if (newOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
lib/v4-core/lib/openzeppelin-contracts/contracts/access/Ownable2Step.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable2Step.sol)
pragma solidity ^0.8.20;
import {Ownable} from "./Ownable.sol";
/**
* @dev Contract module which provides access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* The initial owner is specified at deployment time in the constructor for `Ownable`. This
* can later be changed with {transferOwnership} and {acceptOwnership}.
*
* This module is used through inheritance. It will make available all functions
* from parent (Ownable).
*/
abstract contract Ownable2Step is Ownable {
address private _pendingOwner;
event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);
/**
* @dev Returns the address of the pending owner.
*/
function pendingOwner() public view virtual returns (address) {
return _pendingOwner;
}
/**
* @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one.
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual override onlyOwner {
_pendingOwner = newOwner;
emit OwnershipTransferStarted(owner(), newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending owner.
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual override {
delete _pendingOwner;
super._transferOwnership(newOwner);
}
/**
* @dev The new owner accepts the ownership transfer.
*/
function acceptOwnership() public virtual {
address sender = _msgSender();
if (pendingOwner() != sender) {
revert OwnableUnauthorizedAccount(sender);
}
_transferOwnership(sender);
}
}
lib/v4-core/lib/openzeppelin-contracts/contracts/utils/Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)
pragma solidity ^0.8.20;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}
src/interfaces/IArkBoarding.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
interface IArkBoarding {
function addPrincipalFromVault(uint256 positionId, uint256 amount) external;
function exitMany(uint256[] calldata positionIds, uint256[] calldata amounts, address receiver)
external;
function exitAll(uint256 positionId, address receiver) external;
function exitAllMany(uint256[] calldata positionIds, address receiver) external;
function exitAllFrom(uint256 positionId, address receiver) external;
function exitFrom(uint256 positionId, uint256 amount, address receiver) external;
function exitFee(uint256 positionId, uint256 amount) external view returns (uint256);
function activeBoardedAmount(uint256 positionId) external view returns (uint256);
function activeTotalBoarded() external view returns (uint256);
function isOperatorFor(address owner, address operator) external view returns (bool);
function isPositionActive(uint256 positionId) external view returns (bool);
function positionOwner(uint256 positionId) external view returns (address);
function positionPrincipal(uint256 positionId) external view returns (uint256);
function positionsOf(address owner) external view returns (uint256[] memory);
function timeUntilFreeExit(uint256 positionId) external view returns (uint256);
function totalBoarded() external view returns (uint256);
}
src/interfaces/IArkBuybackLogic.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
interface IArkBuybackLogic {
function notifyBuybackBudget(address asset, uint256 amount) external;
function notifyRedirectedLockedReward(address asset, uint256 amount) external;
}
src/interfaces/IArkLaunchExposureGuard.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
interface IArkLaunchExposureGuard {
function token() external view returns (address);
function boarding() external view returns (address);
function vault() external view returns (address);
function exposureCap() external view returns (uint256);
function limitsDisabled() external view returns (bool);
function boardedExposure(address account) external view returns (uint256);
function lockedExposure(address account) external view returns (uint256);
function releaseCredit(address source, address receiver) external view returns (uint256);
function isExempt(address account) external view returns (bool);
function exemptCount() external view returns (uint256);
function exemptAt(uint256 index) external view returns (address);
function exposureOf(address account) external view returns (uint256);
function remainingExposure(address account) external view returns (uint256);
function setBoarding(address boarding_) external;
function setVault(address vault_) external;
function setExempt(address account, bool exempt) external;
function disableLimits() external;
function validateTokenReceive(
address from,
address to,
uint256 amount,
uint256 nextLiquidBalance
) external;
function increaseBoarded(address owner, address source, uint256 amount) external;
function increaseBoardedFromReward(address owner, uint256 amount) external;
function decreaseBoarded(address owner, uint256 amount) external;
function increaseLocked(address owner, address source, uint256 amount) external;
function increaseLockedFromReward(address owner, uint256 amount) external;
function decreaseLocked(address owner, uint256 amount) external;
function allowTokenRelease(address owner, address receiver, uint256 amount) external;
}
src/interfaces/IArkNoahPass.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
interface IArkNoahPass {
function mintIfEligible(address to, uint256 lockAmount) external returns (uint256 tokenId);
}
src/interfaces/IArkRewardReservoir.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
interface IArkRewardReservoir {
function releaseGenesisRewards(address receiver, uint256 amount) external returns (uint256);
}
src/interfaces/IArkVault.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
interface IArkVault {
function notifyBaseReward(address asset, uint256 amount) external;
function notifyLockedReward(address asset, uint256 amount) external;
function beforePositionCreated() external;
function onPositionCreated(uint256 positionId) external;
function beforePositionAmountChange(uint256 positionId) external;
function onPositionClosed(uint256 positionId) external;
function claimPositionRewardFromBoarding(uint256 positionId, address receiver) external;
function claimMany(uint256[] calldata positionIds, uint256[] calldata lockIds, address receiver)
external;
function unlockMany(uint256[] calldata lockIds, address receiver) external;
function unlockManyAsWeth(uint256[] calldata lockIds, address receiver) external;
}
src/interfaces/IERC20.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
interface IERC20 {
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function allowance(address owner, address spender) external view returns (uint256);
function transfer(address to, uint256 amount) external returns (bool);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(address from, address to, uint256 amount) external returns (bool);
}
src/interfaces/IWrappedNative.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
import {IERC20} from "./IERC20.sol";
interface IWrappedNative is IERC20 {
function deposit() external payable;
function withdraw(uint256 amount) external;
}
src/locking/ArkLock.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
import {ArkOwnable} from "../security/ArkOwnable.sol";
contract ArkLock is ArkOwnable {
error ZeroAddress();
error EmptyMetadata();
error Unauthorized();
error VaultAlreadySet();
error TokenAlreadyMinted();
error TokenDoesNotExist();
error TransfersDisabled();
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
event VaultSet(address indexed vault);
string public name;
string public symbol;
address public vault;
mapping(uint256 tokenId => address owner) public ownerOf;
mapping(address owner => uint256 balance) public balanceOf;
constructor(address initialOwner, string memory name_, string memory symbol_)
ArkOwnable(initialOwner)
{
if (bytes(name_).length == 0 || bytes(symbol_).length == 0) revert EmptyMetadata();
name = name_;
symbol = symbol_;
}
modifier onlyVault() {
if (msg.sender != vault) revert Unauthorized();
_;
}
function setVault(address vault_) external onlyOwner {
if (vault_ == address(0)) revert ZeroAddress();
if (vault != address(0)) revert VaultAlreadySet();
vault = vault_;
emit VaultSet(vault_);
}
function mint(address to, uint256 tokenId) external onlyVault {
if (to == address(0)) revert ZeroAddress();
if (ownerOf[tokenId] != address(0)) revert TokenAlreadyMinted();
ownerOf[tokenId] = to;
balanceOf[to] += 1;
emit Transfer(address(0), to, tokenId);
}
function burn(uint256 tokenId) external onlyVault {
address owner = ownerOf[tokenId];
if (owner == address(0)) revert TokenDoesNotExist();
delete ownerOf[tokenId];
balanceOf[owner] -= 1;
emit Transfer(owner, address(0), tokenId);
}
function isActive(uint256 tokenId) external view returns (bool) {
return ownerOf[tokenId] != address(0);
}
function getApproved(uint256 tokenId) external view returns (address) {
if (ownerOf[tokenId] == address(0)) revert TokenDoesNotExist();
return address(0);
}
function isApprovedForAll(address, address) external pure returns (bool) {
return false;
}
function approve(address, uint256) external pure {
revert TransfersDisabled();
}
function setApprovalForAll(address, bool) external pure {
revert TransfersDisabled();
}
function transferFrom(address, address, uint256) external pure {
revert TransfersDisabled();
}
function safeTransferFrom(address, address, uint256) external pure {
revert TransfersDisabled();
}
function safeTransferFrom(address, address, uint256, bytes calldata) external pure {
revert TransfersDisabled();
}
}
src/security/ArkOwnable.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {Ownable2Step} from "@openzeppelin/contracts/access/Ownable2Step.sol";
abstract contract ArkOwnable is Ownable2Step {
error OwnershipRenounceDisabled();
constructor(address initialOwner) Ownable(initialOwner) {}
function renounceOwnership() public view override onlyOwner {
revert OwnershipRenounceDisabled();
}
}
src/security/ArkRecoverable.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
import {IERC20} from "../interfaces/IERC20.sol";
import {ArkOwnable} from "./ArkOwnable.sol";
import {ArkReentrancyGuard} from "./ArkReentrancyGuard.sol";
abstract contract ArkRecoverable is ArkOwnable, ArkReentrancyGuard {
error NoRecoverableBalance();
error ProtectedRecoveryAsset();
error RecoveryTransferFailed();
event NativeRecovered(address indexed recipient, uint256 amount);
event TokenRecovered(address indexed asset, address indexed recipient, uint256 amount);
constructor(address initialOwner) ArkOwnable(initialOwner) {}
function recoverNative() external nonReentrant onlyOwner returns (uint256 amount) {
amount = address(this).balance;
if (amount == 0) revert NoRecoverableBalance();
address recipient = owner();
(bool success,) = payable(recipient).call{value: amount}("");
if (!success) revert RecoveryTransferFailed();
emit NativeRecovered(recipient, amount);
}
function recoverToken(address asset) external nonReentrant onlyOwner returns (uint256 amount) {
if (asset == address(0)) revert ProtectedRecoveryAsset();
if (!_isRecoverableToken(asset)) revert ProtectedRecoveryAsset();
amount = IERC20(asset).balanceOf(address(this));
if (amount == 0) revert NoRecoverableBalance();
address recipient = owner();
if (!IERC20(asset).transfer(recipient, amount)) revert RecoveryTransferFailed();
emit TokenRecovered(asset, recipient, amount);
}
function _isRecoverableToken(address) internal view virtual returns (bool) {
return true;
}
}
src/security/ArkReentrancyGuard.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
abstract contract ArkReentrancyGuard {
error ReentrantCall();
uint256 private constant ENTERED = 1;
bytes32 private constant REENTRANCY_GUARD_SLOT =
0x3a6f8673abc4ff4f17461e886ecbdb6f0f20d51c49db9bac70360d14b8040ec4;
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
bytes32 slot = REENTRANCY_GUARD_SLOT;
uint256 status;
assembly ("memory-safe") {
status := tload(slot)
}
if (status == ENTERED) revert ReentrantCall();
assembly ("memory-safe") {
tstore(slot, ENTERED)
}
}
function _nonReentrantAfter() private {
bytes32 slot = REENTRANCY_GUARD_SLOT;
assembly ("memory-safe") {
tstore(slot, 0)
}
}
}
src/token/ArkLark.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
import {IERC20} from "../interfaces/IERC20.sol";
import {ArkOwnable} from "../security/ArkOwnable.sol";
contract ArkLark is IERC20, ArkOwnable {
error ZeroAddress();
error EmptyMetadata();
error Unauthorized();
error VaultAlreadySet();
error TransfersDisabled();
error InsufficientBalance();
event VaultSet(address indexed vault);
string public name;
string public symbol;
uint8 public constant decimals = 18;
address public vault;
uint256 public override totalSupply;
mapping(address account => uint256 balance) public override balanceOf;
constructor(address initialOwner, string memory name_, string memory symbol_)
ArkOwnable(initialOwner)
{
if (bytes(name_).length == 0 || bytes(symbol_).length == 0) revert EmptyMetadata();
name = name_;
symbol = symbol_;
}
modifier onlyVault() {
if (msg.sender != vault) revert Unauthorized();
_;
}
function setVault(address vault_) external onlyOwner {
if (vault_ == address(0)) revert ZeroAddress();
if (vault != address(0)) revert VaultAlreadySet();
vault = vault_;
emit VaultSet(vault_);
}
function mint(address to, uint256 amount) external onlyVault {
if (to == address(0)) revert ZeroAddress();
totalSupply += amount;
balanceOf[to] += amount;
emit Transfer(address(0), to, amount);
}
function burn(address from, uint256 amount) external onlyVault {
uint256 balance = balanceOf[from];
if (balance < amount) revert InsufficientBalance();
unchecked {
balanceOf[from] = balance - amount;
totalSupply -= amount;
}
emit Transfer(from, address(0), amount);
}
function allowance(address, address) external pure override returns (uint256) {
return 0;
}
function transfer(address, uint256) external pure override returns (bool) {
revert TransfersDisabled();
}
function approve(address, uint256) external pure override returns (bool) {
revert TransfersDisabled();
}
function transferFrom(address, address, uint256) external pure override returns (bool) {
revert TransfersDisabled();
}
}
Compiler settingsShow
{
"viaIR": false,
"metadata": {
"appendCBOR": false,
"bytecodeHash": "none",
"useLiteralContent": false
},
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "cancun",
"remappings": [
"@ensdomains/=lib/v4-core/node_modules/@ensdomains/",
"@openzeppelin/=lib/v4-core/lib/openzeppelin-contracts/",
"@uniswap/v4-core/=lib/v4-periphery/lib/v4-core/",
"ds-test/=lib/v4-core/lib/forge-std/lib/ds-test/src/",
"erc4626-tests/=lib/v4-core/lib/openzeppelin-contracts/lib/erc4626-tests/",
"forge-gas-snapshot/=lib/v4-periphery/lib/permit2/lib/forge-gas-snapshot/src/",
"forge-std/=lib/v4-core/lib/forge-std/src/",
"hardhat/=lib/v4-core/node_modules/hardhat/",
"openzeppelin-contracts/=lib/v4-core/lib/openzeppelin-contracts/",
"permit2/=lib/v4-periphery/lib/permit2/",
"solmate/=lib/v4-core/lib/solmate/",
"v4-core/=lib/v4-core/src/",
"v4-periphery/=lib/v4-periphery/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.