Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jung/staking #69

Open
wants to merge 158 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
158 commits
Select commit Hold shift + click to select a range
1be8e65
Add staking contracts with interfaces
Frenchkebab Aug 23, 2024
c8dedb3
add Enumerable Set for tokens
Frenchkebab Aug 28, 2024
67b6c38
add getter for stake amount
Frenchkebab Aug 28, 2024
bf7fdb6
add contract inheritance
Frenchkebab Aug 29, 2024
27fafca
add add/remove token feature
Frenchkebab Aug 29, 2024
f4441fd
add supportedSignature feature
Frenchkebab Aug 29, 2024
3b6dbca
implement stake/operatorSelfStake logic
Frenchkebab Aug 29, 2024
215b33c
add interfaces
Frenchkebab Aug 29, 2024
78f02d0
add getter for signature support
Frenchkebab Aug 29, 2024
9936d1c
add getters for stake
Frenchkebab Aug 29, 2024
9126919
add unstake
Frenchkebab Aug 29, 2024
5f873f6
add userStakeInfo mapping
Frenchkebab Aug 29, 2024
657119c
add token transfer logic
Frenchkebab Aug 29, 2024
170567c
todos
Frenchkebab Aug 29, 2024
c8928f1
add check logic for submitSnapshot
Frenchkebab Aug 29, 2024
4ba1ee4
implement submitSnapshot logic
Frenchkebab Aug 29, 2024
e3a947a
add mapping for slash result submission
Frenchkebab Aug 30, 2024
33c92e8
fix return fix logic for getters
Frenchkebab Aug 30, 2024
335deeb
add Snapshot submission logic
Frenchkebab Aug 30, 2024
7193efb
add operator snapshot update logic
Frenchkebab Aug 30, 2024
1291204
add vault snapshot logic
Frenchkebab Aug 30, 2024
98499ee
add slash result submission logic
Frenchkebab Aug 30, 2024
b27093d
refactor code
Frenchkebab Aug 30, 2024
4d8461e
finish submitSlashResultData logic
Frenchkebab Aug 30, 2024
42a6c02
fix typo
Frenchkebab Aug 30, 2024
933809d
fix typo
Frenchkebab Aug 30, 2024
0a277b7
add upgradeability to StakingManager
Frenchkebab Aug 31, 2024
40e0b01
add logic for jobCreation and stake lock
Frenchkebab Sep 1, 2024
2463e2c
implement unlock stake
Frenchkebab Sep 2, 2024
1d90243
fix compile erorrs
Frenchkebab Sep 3, 2024
2964e1d
remove slashjob
Frenchkebab Sep 3, 2024
40e4eee
add lockPool to IKalypsoStaking
Frenchkebab Sep 3, 2024
eb8a9af
add core feature in JobManager
Frenchkebab Sep 10, 2024
a65ea70
create SymbioticStakingReward contract
Frenchkebab Sep 12, 2024
5890845
add upgradeable contracts inheritance
Frenchkebab Sep 12, 2024
1738b0f
add logic
Frenchkebab Sep 13, 2024
e239d01
add _stakeToken and _rewardToken
Frenchkebab Sep 13, 2024
a10c4c3
import Math, EnumerableSet
Frenchkebab Sep 13, 2024
d6ebec6
add active stake and more update logic
Frenchkebab Sep 13, 2024
c788c51
refactor reward logic
Frenchkebab Sep 13, 2024
467efcd
refactor admin functions
Frenchkebab Sep 13, 2024
6525aa5
refactor code
Frenchkebab Sep 13, 2024
c2060cb
create NativeStakingReward contract
Frenchkebab Sep 14, 2024
5c00314
remove everything related to jobManager
Frenchkebab Sep 14, 2024
59e6209
add initialize
Frenchkebab Sep 14, 2024
3fe574e
add rewardPerToken logic
Frenchkebab Sep 14, 2024
46369f6
fix mappings structure
Frenchkebab Sep 15, 2024
66a646c
add update logic
Frenchkebab Sep 16, 2024
dac1008
remove lock getting deducted in RewardDistributors
Frenchkebab Sep 17, 2024
230b8ba
fix signature for lockStake
Frenchkebab Sep 18, 2024
dfc1a8b
fix jobCreation logic
Frenchkebab Sep 18, 2024
97d4152
add unlock logic
Frenchkebab Sep 18, 2024
7dab574
resolve cimpile error
Frenchkebab Sep 18, 2024
842c686
fix NativeStaking stake logic
Frenchkebab Sep 19, 2024
10d3ab6
hardhat config for compile
Frenchkebab Sep 19, 2024
3cc6914
fix withdrawStake logic
Frenchkebab Sep 19, 2024
5bb69e6
reflect review comments
Frenchkebab Sep 23, 2024
a464606
fix mask from bytes4 to bytes32
Frenchkebab Sep 23, 2024
fe4a8dc
move lockStake logic from StsakingManager to NativeStaking
Frenchkebab Sep 24, 2024
9f54798
refactor _selectToken logic
Frenchkebab Sep 24, 2024
2b5a282
move lockStake logic to SymbioticStaking from StakingManager
Frenchkebab Sep 24, 2024
a766094
refactor code
Frenchkebab Sep 24, 2024
8a1e5c2
fix SD, TC to be more verbose name
Frenchkebab Sep 25, 2024
f00b55a
minor fix
Frenchkebab Sep 25, 2024
cd62599
add comments
Frenchkebab Sep 25, 2024
2c6cb90
comment out unnecessary variables
Frenchkebab Sep 25, 2024
a2c92ed
force Snapshot submission to be sequential
Frenchkebab Sep 25, 2024
8d20006
consolidate OperatorSnapshot into VaultSnapshot
Frenchkebab Sep 25, 2024
6d0c15f
remove unnecessary comment
Frenchkebab Sep 25, 2024
2c8a0bc
fix typo
Frenchkebab Sep 25, 2024
c67c32b
fix transmitterComission to baseTransmitterComission
Frenchkebab Sep 25, 2024
b202fe8
fix IKalysoStaking to IStakingPool
Frenchkebab Sep 25, 2024
193a86b
init jobManager
Frenchkebab Sep 25, 2024
a3d605e
remove unused struct
Frenchkebab Sep 25, 2024
1f4afc1
remove minStake from StakingManager
Frenchkebab Sep 25, 2024
dac7f80
remove isEnabledPool mapping
Frenchkebab Sep 25, 2024
2262916
remove unlockEpoch
Frenchkebab Sep 25, 2024
8d86dd3
fix submitProof logic
Frenchkebab Sep 25, 2024
ffea6b6
remove operatorSet
Frenchkebab Sep 25, 2024
245beb7
fix lockStake logic
Frenchkebab Sep 26, 2024
d265222
fix account to msg.sender
Frenchkebab Sep 26, 2024
819c13f
remove selfstake
Frenchkebab Sep 26, 2024
f31ae90
remove account param
Frenchkebab Sep 26, 2024
2dce130
withdraw checks operatorActiveStakeAmount
Frenchkebab Sep 26, 2024
3195325
add todo comment
Frenchkebab Sep 26, 2024
fae46b1
remove minStakeAmount and fix typo
Frenchkebab Sep 26, 2024
948ea0e
remove locked token address from StakingManager
Frenchkebab Sep 26, 2024
e60d824
add deadline logic
Frenchkebab Sep 26, 2024
2575a1f
remove supported signature
Frenchkebab Sep 26, 2024
cd47892
add refundFee
Frenchkebab Sep 26, 2024
2204958
add upgradeability
Frenchkebab Sep 26, 2024
8c2cbe0
fix param variable
Frenchkebab Sep 26, 2024
c934123
resolve TODOs for StakingManager
Frenchkebab Sep 26, 2024
683e429
remove onlyAdmin
Frenchkebab Sep 26, 2024
f4df6e1
add missing admin functions
Frenchkebab Sep 26, 2024
a421c16
remove unnecessary functions
Frenchkebab Sep 26, 2024
f8422ec
add admin function
Frenchkebab Sep 26, 2024
96ffa9f
refactor code
Frenchkebab Sep 26, 2024
fb50a1c
add missing admin functions
Frenchkebab Sep 26, 2024
3c2e6fa
add upgradeability
Frenchkebab Sep 26, 2024
2a2c043
remove onlyAdmin
Frenchkebab Sep 26, 2024
a04883b
remove transmitter from setShare
Frenchkebab Sep 26, 2024
a5a761d
add unlockStake logic
Frenchkebab Sep 26, 2024
082b2e3
implement completeSubmission logic
Frenchkebab Sep 26, 2024
4d0357f
fix setShare logic
Frenchkebab Sep 26, 2024
4412bf6
update unlockStake logic
Frenchkebab Sep 26, 2024
42aba9f
implement slashing logic
Frenchkebab Sep 27, 2024
4bd8823
move struct to Struct.sol
Frenchkebab Sep 27, 2024
c716bd0
remove lock/unlock from SymbioticStakingReward
Frenchkebab Sep 28, 2024
6db8ede
complete reward distribution logic
Frenchkebab Sep 30, 2024
66ca214
refactor code
Frenchkebab Sep 30, 2024
2ca8ae2
refactor code
Frenchkebab Sep 30, 2024
9513350
logic when operatorStakeAmount < operatorLockAmount
Frenchkebab Sep 30, 2024
4b3dd14
add logic for inflation reward emission
Frenchkebab Oct 1, 2024
359f637
refactor reward distribution logic
Frenchkebab Oct 1, 2024
9671f96
refactor _update logic
Frenchkebab Oct 1, 2024
5ea15b5
update reward claim logic
Frenchkebab Oct 1, 2024
dec69fd
fix reward distribution logic
Frenchkebab Oct 2, 2024
d3d7f24
refactor code
Frenchkebab Oct 5, 2024
25a981f
reimplement symbioticStakingReward
Frenchkebab Oct 5, 2024
2696f61
fix symbiotic reward logic
Frenchkebab Oct 5, 2024
06276b8
fix compile errors
Frenchkebab Oct 5, 2024
9339d7d
fix transmitter comission rate logic
Frenchkebab Oct 5, 2024
a1798aa
add comments
Frenchkebab Oct 5, 2024
18c98a6
add getter for pendingInflationReward
Frenchkebab Oct 5, 2024
c2f1192
fix variable name
Frenchkebab Oct 5, 2024
5b75efa
temporarily comment out
Frenchkebab Oct 5, 2024
29fa07d
temporarily comment out
Frenchkebab Oct 5, 2024
a5d9da4
add comments
Frenchkebab Oct 5, 2024
99b3d3c
format code
Frenchkebab Oct 7, 2024
cc59e38
add 2step withdrawal
Frenchkebab Oct 7, 2024
e74888c
fix typo
Frenchkebab Oct 7, 2024
38fed2d
resolve compile error
Frenchkebab Oct 7, 2024
c6caeb0
remove totalFeeStored
Frenchkebab Oct 7, 2024
0d11aa9
symbioticStakingReward pulls reward
Frenchkebab Oct 8, 2024
5f8a4d3
initialize foundry
Frenchkebab Oct 8, 2024
77ca2da
add comment
Frenchkebab Oct 8, 2024
696b8e7
remove internal change to add public
Frenchkebab Oct 8, 2024
fb9aed3
refactor code
Frenchkebab Oct 8, 2024
974df18
refactor SymbioticStakingLock
Frenchkebab Oct 8, 2024
4b74dbd
remove epoch array and replace with single variable
Frenchkebab Oct 8, 2024
d1109ca
add InflationRewardManager contract
Frenchkebab Oct 9, 2024
106fc42
send comission to operator
Frenchkebab Oct 9, 2024
82442e3
add interaction with InflationRewardManager
Frenchkebab Oct 10, 2024
7ef70c5
add transmitter comission feature
Frenchkebab Oct 10, 2024
f6f8231
fix timestampIdx logic
Frenchkebab Oct 10, 2024
1376f23
implement weight based token selection
Frenchkebab Oct 10, 2024
7424f80
add gaps
Frenchkebab Oct 10, 2024
57ac65d
foundry test setup
Frenchkebab Oct 10, 2024
a245830
consider the case when inflation reward is not enough
Frenchkebab Oct 10, 2024
9a6019f
minor fix
Frenchkebab Oct 11, 2024
30e11a2
test setup
Frenchkebab Oct 11, 2024
22ddb9d
fix token selection algorithm in NativeStaking
Frenchkebab Oct 11, 2024
a4b58a2
minor fix
Frenchkebab Oct 11, 2024
ae2ac28
test operator self stake
Frenchkebab Oct 11, 2024
d1fba22
fix unexpected logic
Frenchkebab Oct 14, 2024
95f7fcb
e2e test
Frenchkebab Oct 14, 2024
45d17de
format import orders
Frenchkebab Oct 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[submodule "lib/forge-std"]
path = lib/forge-std
url = https://github.com/foundry-rs/forge-std
[submodule "lib/openzeppelin-foundry-upgrades"]
path = lib/openzeppelin-foundry-upgrades
url = https://github.com/OpenZeppelin/openzeppelin-foundry-upgrades
[submodule "lib/openzeppelin-contracts"]
path = lib/openzeppelin-contracts
url = https://github.com/OpenZeppelin/openzeppelin-contracts
[submodule "lib/openzeppelin-contracts-upgradeable"]
path = lib/openzeppelin-contracts-upgradeable
url = https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable
3 changes: 0 additions & 3 deletions .vscode/settings.json

This file was deleted.

4 changes: 2 additions & 2 deletions contracts/interfaces/IL2Staking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
pragma solidity ^0.8.0;

interface IL2Staking {
function stake(address generatorAddress, uint256 amount) external returns (uint256);

function intendToReduceStake(uint256 stakeToReduce) external;

function stake(address generatorAddress, uint256 amount) external returns (uint256);

function unstake(address receiver) external;
}
10 changes: 10 additions & 0 deletions contracts/interfaces/staking/IInflationRewardManager.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;

interface IInflationRewardManager {
function updatePendingInflationReward(address _operator) external returns (uint256 timestampIdx, uint256 pendingInflationReward);

function updateEpochTimestampIdx() external;

function transferInflationRewardToken(address _to, uint256 _amount) external;
}
12 changes: 12 additions & 0 deletions contracts/interfaces/staking/IJobManager.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;

interface IJobManager {
function createJob(uint256 _jobId, address _requester, address _operator, uint256 _feeAmount) external;

function submitProof(uint256 jobId, bytes calldata proof) external;

function refundFee(uint256 jobId) external;

function operatorRewardShares(address _operator) external view returns (uint256);
}
13 changes: 13 additions & 0 deletions contracts/interfaces/staking/INativeStaking.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;

import {IStakingPool} from "../staking/IStakingPool.sol";

interface INativeStaking is IStakingPool {

function stake(address stakeToken, address operator, uint256 amount) external;

// TODO: check if timestamp is needed
event Staked(address indexed account, address indexed operator, address indexed token, uint256 amount, uint256 timestamp);
event StakeWithdrawn(address indexed account, address indexed operator, address indexed token, uint256 amount, uint256 timestamp);
}
9 changes: 9 additions & 0 deletions contracts/interfaces/staking/INativeStakingReward.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.26;

import {IRewardDistributor} from "./IRewardDistributor.sol";

interface INativeStakingReward is IRewardDistributor {
function update(address account, address _stakeToken, address _operator) external;
}
17 changes: 17 additions & 0 deletions contracts/interfaces/staking/IRewardDistributor.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.26;

interface IRewardDistributor {
function updateFeeReward(address _stakeToken, address _operator, uint256 _rewardAmount) external;

function updateInflationReward(address _operator, uint256 _rewardAmount) external;

function onStakeUpdate(address _account, address _stakeToken, address _operator) external;

function onClaimReward(address _account, address _operator) external;

function onSlash() external;

function setStakeToken(address _stakingPool, bool _isSupported) external;
}
17 changes: 17 additions & 0 deletions contracts/interfaces/staking/IStakingManager.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// SPDX-License-Identifier: MIT

import {Struct} from "../../lib/staking/Struct.sol";

pragma solidity ^0.8.26;

interface IStakingManager {
function onJobCreation(uint256 jobId, address operator) external;

function onJobCompletion(uint256 jobId, address operator, uint256 feePaid) external;

function onSlashResult(Struct.JobSlashed[] calldata slashedJobs) external;

function distributeInflationReward(address operator, uint256 rewardAmount, uint256 timestampIdx) external;

function getPoolConfig(address pool) external view returns (Struct.PoolConfig memory);
}
30 changes: 30 additions & 0 deletions contracts/interfaces/staking/IStakingPool.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;

import {Struct} from "../../lib/staking/Struct.sol";

interface IStakingPool {
function isSupportedStakeToken(address stakeToken) external view returns (bool);

function lockStake(uint256 jobId, address operator) external; // Staking Manager only

function onJobCompletion(uint256 jobId, address operator, uint256 feeRewardAmount, uint256 inflationRewardAmount, uint256 timestampIdx) external; // Staking Manager only

function slash(Struct.JobSlashed[] calldata slashedJobs) external; // Staking Manager only

function getOperatorStakeAmount(address stakeToken, address operator) external view returns (uint256);

function getOperatorActiveStakeAmount(address stakeToken, address operator) external view returns (uint256);

function rewardDistributor() external view returns (address);

function distributeInflationReward(address operator, uint256 rewardAmount, uint256 timestampIdx) external; // Staking Manager only

function getStakeTokenList() external view returns (address[] memory);

function getStakeTokenWeights() external view returns (address[] memory, uint256[] memory);

function tokenSelectionWeightSum() external view returns (uint256);

function getStakeAmount(address stakeToken, address staker, address operator) external view returns (uint256);
}
44 changes: 44 additions & 0 deletions contracts/interfaces/staking/ISymbioticStaking.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;

import {IStakingPool} from "./IStakingPool.sol";

import {Struct} from "../../lib/staking/Struct.sol";

interface ISymbioticStaking is IStakingPool {
function submitVaultSnapshot(
uint256 _index,
uint256 _numOfTxs, // number of total transactions
bytes calldata _vaultSnapshotData,
bytes calldata _signature
) external;

function submitSlashResult(
uint256 _index,
uint256 _numOfTxs, // number of total transactions
bytes memory _slashResultData,
bytes memory _signature
) external;

function getTxCountInfo(uint256 _captureTimestamp, address _transmitter, bytes32 _type) external view returns (Struct.SnapshotTxCountInfo memory);

function getSubmissionStatus(uint256 _captureTimestamp, address _transmitter) external view returns (bytes32);



function confirmedTimestampInfo(uint256 _idx) external view returns (Struct.ConfirmedTimestamp memory);

// event OperatorSnapshotSubmitted

// event VaultSnapshotSubmitted

// event SlashResultSubmitted

// event SubmissionCompleted

/// @notice Returns the captureTimestamp of latest completed snapshot submission
function latestConfirmedTimestamp() external view returns (uint256);

/// @notice Returns the timestampIdx of latest completed snapshot submission
function latestConfirmedTimestampIdx() external view returns (uint256);
}
17 changes: 17 additions & 0 deletions contracts/interfaces/staking/ISymbioticStakingReward.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// SPDX-License-Identifier: MIT

import {Struct} from "../../lib/staking/Struct.sol";

pragma solidity ^0.8.26;

interface ISymbioticStakingReward {
function claimReward(address _operator) external;

function updateFeeReward(address _stakeToken, address _operator, uint256 _amount) external;

function updateInflationReward(address _operator, uint256 _rewardAmount) external;

function onSnapshotSubmission(Struct.VaultSnapshot[] calldata _vaultSnapshots) external;

function onSnapshotSubmission(address _vault, address _operator) external;
}
72 changes: 72 additions & 0 deletions contracts/lib/staking/Struct.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;

library Struct {

/*=========================== Job Manager =============================*/
struct JobInfo {
address requester;
address operator;
uint256 feePaid;
uint256 deadline;
}

/*========================= Staking Manager ===========================*/

struct PoolConfig {
uint256 share;
bool enabled;
}

/*=========================== Staking Pool ============================*/

struct PoolLockInfo {
address token;
uint256 amount;
address transmitter;
}

/*========================== Native Staking ===========================*/

struct NativeStakingLock {
address token;
uint256 amount;
}

struct JobSlashed {
uint256 jobId;
address operator; // TODO: check if cheaper than pulling from JobManager
address rewardAddress;
}

struct WithdrawalRequest {
address stakeToken;
uint256 amount;
uint256 withdrawalTime;
}

/*========================= Symbiotic Staking =========================*/

struct VaultSnapshot {
address operator;
address vault;
address stakeToken;
uint256 stakeAmount;
}

struct SnapshotTxCountInfo {
uint256 idxToSubmit; // idx of pratial snapshot tx to submit
uint256 numOfTxs; // total number of txs for the snapshot
}

struct ConfirmedTimestamp {
uint256 captureTimestamp;
address transmitter;
uint256 transmitterComissionRate;
}

struct SymbioticStakingLock {
address stakeToken;
uint256 amount;
}
}
Loading