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

Feature/redelegation #298

Merged
merged 5 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
23 changes: 23 additions & 0 deletions abi/StakingV2.json
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,29 @@
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint72",
"name": "from",
"type": "uint72"
},
{
"internalType": "uint72",
"name": "to",
"type": "uint72"
},
{
"internalType": "uint96",
"name": "sharesToBurn",
"type": "uint96"
}
],
"name": "redelegate",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "serviceAgreementStorageProxy",
Expand Down
76 changes: 75 additions & 1 deletion contracts/v2/Staking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ contract StakingV2 is Named, Versioned, ContractStatusV2, Initializable {
event OperatorFeeChangeFinished(uint72 indexed identityId, bytes nodeId, uint8 operatorFee);

string private constant _NAME = "Staking";
string private constant _VERSION = "2.2.0";
string private constant _VERSION = "2.3.0";

ShardingTableV2 public shardingTableContract;
IdentityStorageV2 public identityStorage;
Expand Down Expand Up @@ -212,6 +212,80 @@ contract StakingV2 is Named, Versioned, ContractStatusV2, Initializable {
emit SharesMinted(identityId, address(sharesContract), msg.sender, sharesMinted, sharesContract.totalSupply());
}

function redelegate(uint72 from, uint72 to, uint96 sharesToBurn) external {
if (sharesToBurn == 0) {
revert StakingErrors.ZeroSharesAmount();
}

ProfileStorage ps = profileStorage;
StakingStorage ss = stakingStorage;
ShardingTableStorageV2 sts = shardingTableStorage;

if (!ps.profileExists(from)) {
revert ProfileErrors.ProfileDoesntExist(from);
}

if (!ps.profileExists(to)) {
revert ProfileErrors.ProfileDoesntExist(to);
}

Shares fromSharesContract = Shares(ps.getSharesContractAddress(from));
Shares toSharesContract = Shares(ps.getSharesContractAddress(to));

if (sharesToBurn > fromSharesContract.balanceOf(msg.sender)) {
revert TokenErrors.TooLowBalance(address(fromSharesContract), fromSharesContract.balanceOf(msg.sender));
}

ParametersStorage params = parametersStorage;

uint96 fromCurrentStake = ss.totalStakes(from);
uint96 toCurrentStake = ss.totalStakes(to);

uint96 redelegationAmount = uint96(
(uint256(fromCurrentStake) * sharesToBurn) / fromSharesContract.totalSupply()
);

if (toCurrentStake + redelegationAmount > params.maximumStake()) {
revert StakingErrors.MaximumStakeExceeded(params.maximumStake());
}

fromSharesContract.burnFrom(msg.sender, sharesToBurn);

uint256 sharesToMint;
if (toSharesContract.totalSupply() == 0) {
sharesToMint = redelegationAmount;
} else {
sharesToMint = ((uint256(redelegationAmount) * toSharesContract.totalSupply()) / toCurrentStake);
}
toSharesContract.mint(msg.sender, sharesToMint);

ss.setTotalStake(from, fromCurrentStake - redelegationAmount);

if (sts.nodeExists(from) && (fromCurrentStake - redelegationAmount) < params.minimumStake()) {
shardingTableContract.removeNode(from);
}

ss.setTotalStake(to, toCurrentStake + redelegationAmount);

if (!sts.nodeExists(to) && (toCurrentStake + redelegationAmount >= params.minimumStake())) {
if (sts.nodesCount() >= params.shardingTableSizeLimit()) {
revert ShardingTableErrors.ShardingTableIsFull();
}
shardingTableContract.insertNode(to);
}

emit SharesBurned(
from,
address(fromSharesContract),
msg.sender,
sharesToBurn,
fromSharesContract.totalSupply()
);
emit StakeWithdrawn(from, ps.getNodeId(from), msg.sender, redelegationAmount);
emit SharesMinted(to, address(toSharesContract), msg.sender, sharesToMint, toSharesContract.totalSupply());
emit StakeIncreased(to, ps.getNodeId(to), msg.sender, toCurrentStake, toCurrentStake + redelegationAmount);
}

function startStakeWithdrawal(uint72 identityId, uint96 sharesToBurn) external {
if (sharesToBurn == 0) {
revert StakingErrors.ZeroSharesAmount();
Expand Down
12 changes: 6 additions & 6 deletions deployments/base_mainnet_contracts.json
Original file line number Diff line number Diff line change
Expand Up @@ -239,12 +239,12 @@
"deployed": true
},
"Staking": {
"evmAddress": "0x39713a4E7d05dAB796fCA6e84cBA5aFC905822d9",
"version": "2.2.0",
"gitBranch": "main",
"gitCommitHash": "b9e7dede2a75acf193272f84b1a5ce155210e47a",
"deploymentBlock": 19022524,
"deploymentTimestamp": 1724834405325,
"evmAddress": "0xb4a9CF231FC623498347ecb0859E2BC3Ad9ad110",
"version": "2.3.0",
"gitBranch": "feature/redelegation",
"gitCommitHash": "d72f5fcd0e6159f1cf8dccd033cbeca63595953d",
"deploymentBlock": 21665377,
"deploymentTimestamp": 1730120110036,
"deployed": true
},
"Profile": {
Expand Down
2 changes: 1 addition & 1 deletion deployments/base_sepolia_dev_contracts.json
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@
"gitCommitHash": "b9e7dede2a75acf193272f84b1a5ce155210e47a",
"deploymentBlock": 14543288,
"deploymentTimestamp": 1724854871142,
"deployed": true
"deployed": false
},
"Profile": {
"evmAddress": "0x2Ff4C4CAc001CBcC1893620Ef2a261071dB2498A",
Expand Down
12 changes: 6 additions & 6 deletions deployments/base_sepolia_test_contracts.json
Original file line number Diff line number Diff line change
Expand Up @@ -239,12 +239,12 @@
"deployed": true
},
"Staking": {
"evmAddress": "0x1dD6bE1EC9410aff2E95685d84cEA6aCf40bFBa9",
"version": "2.2.0",
"gitBranch": "main",
"gitCommitHash": "b9e7dede2a75acf193272f84b1a5ce155210e47a",
"deploymentBlock": 14543315,
"deploymentTimestamp": 1724854925334,
"evmAddress": "0x1E8317d7A84eD72Bbfb421454cD8c6881F935010",
"version": "2.3.0",
"gitBranch": "feature/redelegation",
"gitCommitHash": "19ee7ca7323be5ef8a30ae3482d64c1d51b9bd44",
"deploymentBlock": 17048866,
"deploymentTimestamp": 1729866025390,
"deployed": true
},
"Profile": {
Expand Down
12 changes: 6 additions & 6 deletions deployments/gnosis_chiado_dev_contracts.json
Original file line number Diff line number Diff line change
Expand Up @@ -265,12 +265,12 @@
"deployed": true
},
"Staking": {
"evmAddress": "0x4991C23D82469e1b9b583515Ed400e5B0437d499",
"version": "2.2.0",
"gitBranch": "main",
"gitCommitHash": "b9e7dede2a75acf193272f84b1a5ce155210e47a",
"deploymentBlock": 11519675,
"deploymentTimestamp": 1724854757920,
"evmAddress": "0x6EE3DbEd6477320A6CBb399cC08862BEB327d81b",
"version": "2.3.0",
"gitBranch": "feature/redelegation",
"gitCommitHash": "d72f5fcd0e6159f1cf8dccd033cbeca63595953d",
"deploymentBlock": 12524619,
"deploymentTimestamp": 1730119900339,
"deployed": true
},
"ParanetsRegistry": {
Expand Down
2 changes: 1 addition & 1 deletion deployments/gnosis_chiado_test_contracts.json
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@
"gitCommitHash": "b9e7dede2a75acf193272f84b1a5ce155210e47a",
"deploymentBlock": 11519686,
"deploymentTimestamp": 1724854815721,
"deployed": true
"deployed": false
},
"ContentAsset": {
"evmAddress": "0x20A489D9dc7d2D241AF24C650d71631722aF0Aa1",
Expand Down
12 changes: 6 additions & 6 deletions deployments/gnosis_mainnet_contracts.json
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,12 @@
"deployed": true
},
"Staking": {
"evmAddress": "0x8883aA8cd98fCf6D9203b731F843Fe9eed09E3bb",
"version": "2.2.0",
"gitBranch": "main",
"gitCommitHash": "b9e7dede2a75acf193272f84b1a5ce155210e47a",
"deploymentBlock": 35708723,
"deploymentTimestamp": 1724834659300,
"evmAddress": "0xbce4d40D93B8bE20E8Ad689Dd00D03A7e17f57dD",
"version": "2.3.0",
"gitBranch": "feature/redelegation",
"gitCommitHash": "d72f5fcd0e6159f1cf8dccd033cbeca63595953d",
"deploymentBlock": 36734779,
"deploymentTimestamp": 1730120579662,
"deployed": true
},
"Profile": {
Expand Down
14 changes: 7 additions & 7 deletions deployments/otp_mainnet_contracts.json
Original file line number Diff line number Diff line change
Expand Up @@ -207,13 +207,13 @@
"deployed": true
},
"Staking": {
"evmAddress": "0x666B604B1b32ca467a6eEF3257475D32f8ADD04b",
"substrateAddress": "5EMjsczghQorAAxG77BAa4V9YSAkJ8TfGRJsvaARzTNHdDgn",
"version": "2.2.0",
"gitBranch": "main",
"gitCommitHash": "b9e7dede2a75acf193272f84b1a5ce155210e47a",
"deploymentBlock": 5672930,
"deploymentTimestamp": 1724834500366,
"evmAddress": "0x4039101dFD15AB3cDBBb44F5b46687a4fAE1893B",
"substrateAddress": "5EMjsczZ3WFMFrHbF7aTAa7i744NsqyoYZDbZg6s8ca2Zucc",
"version": "2.3.0",
"gitBranch": "feature/redelegation",
"gitCommitHash": "d72f5fcd0e6159f1cf8dccd033cbeca63595953d",
"deploymentBlock": 6422825,
"deploymentTimestamp": 1730120359479,
"deployed": true
},
"CommitManagerV1": {
Expand Down
14 changes: 7 additions & 7 deletions deployments/otp_testnet_contracts.json
Original file line number Diff line number Diff line change
Expand Up @@ -216,13 +216,13 @@
"deployed": true
},
"Staking": {
"evmAddress": "0x873d2Ac030ba5cb14184E6Af3152fcfF7555b432",
"substrateAddress": "5EMjsczoGpwyeX7YPDeYFej1RGnqi8CeW6b6Vw5xA4P6pN3k",
"version": "2.2.0",
"gitBranch": "main",
"gitCommitHash": "b9e7dede2a75acf193272f84b1a5ce155210e47a",
"deploymentBlock": 4354638,
"deploymentTimestamp": 1724854704943,
"evmAddress": "0x2127A10E32034107a68301544d863c6833072457",
"substrateAddress": "5EMjsczSpSeJw1TKkhh1tXZvaHqDvyBXd39K88BDPDJaPSsb",
"version": "2.3.0",
"gitBranch": "feature/redelegation",
"gitCommitHash": "d72f5fcd0e6159f1cf8dccd033cbeca63595953d",
"deploymentBlock": 4939016,
"deploymentTimestamp": 1730120002198,
"deployed": true
},
"CommitManagerV1": {
Expand Down
3 changes: 3 additions & 0 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ config.abiExporter = {
'IERC721Metadata.sol',
'IERC721Receiver.sol',
'IERC734Extended.sol',
'IERC1155.sol',
'IERC1155MetadataURI.sol',
'IERC1155Receiver.sol',
'IERC4906.sol',
'Ownable.sol',
'CommitManagerErrorsV2.sol',
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dkg-evm-module",
"version": "4.3.4",
"version": "4.4.0",
"description": "Smart contracts for OriginTrail V6",
"main": "index.ts",
"files": [
Expand Down
Loading
Loading