Skip to content

Commit

Permalink
chore: wip on splitting for code size
Browse files Browse the repository at this point in the history
  • Loading branch information
pcarranzav committed Apr 13, 2024
1 parent 954bc48 commit e4eb030
Show file tree
Hide file tree
Showing 19 changed files with 371 additions and 289 deletions.
2 changes: 1 addition & 1 deletion packages/contracts/contracts/governance/IManaged.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-2.0-or-later

pragma solidity ^0.7.6;
pragma solidity >=0.6.12 <0.9.0;

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

Expand Down
1 change: 1 addition & 0 deletions packages/contracts/contracts/l2/staking/IL2Staking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pragma abicoder v2;

import { IStaking } from "../../staking/IStaking.sol";
import { IL2StakingBase } from "./IL2StakingBase.sol";
import { IL2StakingTypes } from "./IL2StakingTypes.sol";

/**
* @title Interface for the L2 Staking contract
Expand Down
2 changes: 2 additions & 0 deletions packages/contracts/contracts/l2/staking/IL2StakingTypes.sol
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: GPL-2.0-or-later

pragma solidity >=0.6.12 <0.9.0;

interface IL2StakingTypes {
Expand Down
23 changes: 15 additions & 8 deletions packages/contracts/contracts/l2/staking/L2Staking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Staking } from "../../staking/Staking.sol";
import { IL2StakingBase } from "./IL2StakingBase.sol";
import { IL2Staking } from "./IL2Staking.sol";
import { Stakes } from "../../staking/libs/Stakes.sol";
import { IL2StakingTypes } from "./IL2StakingTypes.sol";

/**
* @title L2Staking contract
Expand Down Expand Up @@ -63,16 +64,16 @@ contract L2Staking is Staking, IL2StakingBase {
require(_from == counterpartStakingAddress, "ONLY_L1_STAKING_THROUGH_BRIDGE");
(uint8 code, bytes memory functionData) = abi.decode(_data, (uint8, bytes));

if (code == uint8(IL2Staking.L1MessageCodes.RECEIVE_INDEXER_STAKE_CODE)) {
IL2Staking.ReceiveIndexerStakeData memory indexerData = abi.decode(
if (code == uint8(IL2StakingTypes.L1MessageCodes.RECEIVE_INDEXER_STAKE_CODE)) {
IL2StakingTypes.ReceiveIndexerStakeData memory indexerData = abi.decode(
functionData,
(IL2Staking.ReceiveIndexerStakeData)
(IL2StakingTypes.ReceiveIndexerStakeData)
);
_receiveIndexerStake(_amount, indexerData);
} else if (code == uint8(IL2Staking.L1MessageCodes.RECEIVE_DELEGATION_CODE)) {
IL2Staking.ReceiveDelegationData memory delegationData = abi.decode(
} else if (code == uint8(IL2StakingTypes.L1MessageCodes.RECEIVE_DELEGATION_CODE)) {
IL2StakingTypes.ReceiveDelegationData memory delegationData = abi.decode(
functionData,
(IL2Staking.ReceiveDelegationData)
(IL2StakingTypes.ReceiveDelegationData)
);
_receiveDelegation(_amount, delegationData);
} else {
Expand All @@ -87,7 +88,10 @@ contract L2Staking is Staking, IL2StakingBase {
* @param _amount Amount of tokens that were transferred
* @param _indexerData struct containing the indexer's address
*/
function _receiveIndexerStake(uint256 _amount, IL2Staking.ReceiveIndexerStakeData memory _indexerData) internal {
function _receiveIndexerStake(
uint256 _amount,
IL2StakingTypes.ReceiveIndexerStakeData memory _indexerData
) internal {
address _indexer = _indexerData.indexer;
// Deposit tokens into the indexer stake
__stakes[_indexer].deposit(_amount);
Expand All @@ -108,7 +112,10 @@ contract L2Staking is Staking, IL2StakingBase {
* @param _amount Amount of tokens that were transferred
* @param _delegationData struct containing the delegator's address and the indexer's address
*/
function _receiveDelegation(uint256 _amount, IL2Staking.ReceiveDelegationData memory _delegationData) internal {
function _receiveDelegation(
uint256 _amount,
IL2StakingTypes.ReceiveDelegationData memory _delegationData
) internal {
// Get the delegation pool of the indexer
DelegationPool storage pool = __delegationPools[_delegationData.indexer];
Delegation storage delegation = pool.delegators[_delegationData.delegator];
Expand Down
149 changes: 0 additions & 149 deletions packages/contracts/contracts/staking/IHorizonStaking.sol

This file was deleted.

13 changes: 8 additions & 5 deletions packages/contracts/contracts/staking/L1Staking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import { ITokenGateway } from "../arbitrum/ITokenGateway.sol";
import { Staking } from "./Staking.sol";
import { Stakes } from "./libs/Stakes.sol";
import { IStakingData } from "./IStakingData.sol";
import { IL2Staking } from "../l2/staking/IL2Staking.sol";
import { L1StakingV1Storage } from "./L1StakingStorage.sol";
import { IGraphToken } from "../token/IGraphToken.sol";
import { IL1StakingBase } from "./IL1StakingBase.sol";
import { MathUtils } from "./libs/MathUtils.sol";
import { IL1GraphTokenLockTransferTool } from "./IL1GraphTokenLockTransferTool.sol";
import { IL2StakingTypes } from "../l2/staking/IL2StakingTypes.sol";

/**
* @title L1Staking contract
Expand Down Expand Up @@ -267,11 +267,11 @@ contract L1Staking is Staking, L1StakingV1Storage, IL1StakingBase {
);
}

IL2Staking.ReceiveIndexerStakeData memory functionData;
IL2StakingTypes.ReceiveIndexerStakeData memory functionData;
functionData.indexer = _l2Beneficiary;

bytes memory extraData = abi.encode(
uint8(IL2Staking.L1MessageCodes.RECEIVE_INDEXER_STAKE_CODE),
uint8(IL2StakingTypes.L1MessageCodes.RECEIVE_INDEXER_STAKE_CODE),
abi.encode(functionData)
);

Expand Down Expand Up @@ -324,10 +324,13 @@ contract L1Staking is Staking, L1StakingV1Storage, IL1StakingBase {
delegation.shares = 0;
bytes memory extraData;
{
IL2Staking.ReceiveDelegationData memory functionData;
IL2StakingTypes.ReceiveDelegationData memory functionData;
functionData.indexer = indexerTransferredToL2[_indexer];
functionData.delegator = _l2Beneficiary;
extraData = abi.encode(uint8(IL2Staking.L1MessageCodes.RECEIVE_DELEGATION_CODE), abi.encode(functionData));
extraData = abi.encode(
uint8(IL2StakingTypes.L1MessageCodes.RECEIVE_DELEGATION_CODE),
abi.encode(functionData)
);
}

_sendTokensAndMessageToL2Staking(
Expand Down
Loading

0 comments on commit e4eb030

Please sign in to comment.