Skip to content

Commit

Permalink
maint(pg): remove DeployedContractSize struct
Browse files Browse the repository at this point in the history
  • Loading branch information
sam-goldman committed Apr 7, 2024
1 parent 0daa8a7 commit c7af7ef
Show file tree
Hide file tree
Showing 13 changed files with 119 additions and 184 deletions.
7 changes: 7 additions & 0 deletions .changeset/honest-hats-promise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@sphinx-labs/contracts': patch
'@sphinx-labs/plugins': patch
'@sphinx-labs/core': patch
---

Remove deployedContractSizes
3 changes: 1 addition & 2 deletions packages/contracts/contracts/foundry/Sphinx.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ import {
GnosisSafeTransaction,
ExecutionMode,
SystemContractInfo,
ParsedAccountAccess,
DeployedContractSize
ParsedAccountAccess
} from "./SphinxPluginTypes.sol";
import { SphinxUtils } from "./SphinxUtils.sol";
import { SphinxConstants } from "./SphinxConstants.sol";
Expand Down
12 changes: 0 additions & 12 deletions packages/contracts/contracts/foundry/SphinxPluginTypes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,6 @@ struct ParsedAccountAccess {
Vm.AccountAccess[] nested;
}

struct DeployedContractSize {
address account;
uint size;
}

/**
* @notice Contains all of the information that's collected in a deployment on a single chain.
* The only difference between this struct and the TypeScript `DeploymentInfo` object is
Expand Down Expand Up @@ -112,7 +107,6 @@ struct FoundryDeploymentInfo {
string sphinxLibraryVersion;
bytes[] encodedAccountAccesses;
uint256[] gasEstimates;
bytes encodedDeployedContractSizes;
uint fundsRequestedForSafe;
uint safeStartingBalance;
}
Expand Down Expand Up @@ -261,10 +255,4 @@ contract SphinxPluginTypes {
view
returns (SphinxLeafWithProof[][] memory batches)
{}

function deployedContractSizesType()
external
view
returns (DeployedContractSize[] memory deployedContractSizes)
{}
}
41 changes: 1 addition & 40 deletions packages/contracts/contracts/foundry/SphinxUtils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ import {
ExecutionMode,
SystemContractInfo,
GnosisSafeTransaction,
ParsedAccountAccess,
DeployedContractSize
ParsedAccountAccess
} from "./SphinxPluginTypes.sol";
import { SphinxConstants } from "./SphinxConstants.sol";
import { ICreateCall } from "./interfaces/ICreateCall.sol";
Expand Down Expand Up @@ -1011,11 +1010,6 @@ contract SphinxUtils is SphinxConstants, StdUtils {
"encodedAccountAccesses",
_deployment.encodedAccountAccesses
);
vm.serializeBytes(
deploymentInfoKey,
"encodedDeployedContractSizes",
_deployment.encodedDeployedContractSizes
);

// Next, we'll serialize `uint` values as ABI encoded bytes. We don't serialize them as
// numbers to prevent the possibility that they lose precision due JavaScript's relatively
Expand Down Expand Up @@ -1134,35 +1128,6 @@ contract SphinxUtils is SphinxConstants, StdUtils {
_access.chainInfo.chainId == _chainId;
}

function fetchDeployedContractSizes(
Vm.AccountAccess[] memory _accesses,
uint256 _chainId
) private view returns (DeployedContractSize[] memory) {
uint numCreateAccesses = fetchNumCreateAccesses(_accesses, _chainId);
DeployedContractSize[] memory deployedContractSizes = new DeployedContractSize[](
numCreateAccesses
);
uint deployContractSizeIndex = 0;
for (uint i = 0; i < _accesses.length; i++) {
if (isCreateAccountAccess(_accesses[i], _chainId)) {
// We could also read the size of the code from the AccountAccess deployedCode field
// We don't do that because Foundry occasionally does not populate that field when
// it should.
address account = _accesses[i].account;
uint size;
assembly {
size := extcodesize(account)
}
deployedContractSizes[deployContractSizeIndex] = DeployedContractSize(
account,
size
);
deployContractSizeIndex += 1;
}
}
return deployedContractSizes;
}

function parseAccountAccesses(
Vm.AccountAccess[] memory _accesses,
address _safeAddress,
Expand Down Expand Up @@ -1568,10 +1533,6 @@ contract SphinxUtils is SphinxConstants, StdUtils {

parsedAccesses = addBalanceCheckAction(_deploymentInfo, parsedAccesses, _callDepth);

_deploymentInfo.encodedDeployedContractSizes = abi.encode(
fetchDeployedContractSizes(_accesses, _deploymentInfo.chainId)
);

// ABI encode each `ParsedAccountAccess` element individually. If, instead, we ABI encode
// the entire array as a unit, the encoded bytes will be too large for EthersJS to ABI
// decode, which causes an error. This occurs for large deployments, i.e. greater than 50
Expand Down
6 changes: 1 addition & 5 deletions packages/contracts/src/networks.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
import { DeployedContractSize, ParsedAccountAccess } from './types'
import { ParsedAccountAccess } from './types'

/**
* Return a hard-coded gas value for Moonbeam, Moonbase Alpha, and Moonriver. We hard-code this
* value as a temporary solution because these networks have a non-standard gas calculation
* mechanism.
*
* @param baseGas The estimated gas cost according to Foundry.
* @param deployedContractSizes The sizes of any contracts deployed during this transaction.
* @param access The ParsedAccountAccess for the transaction.
* @returns
*/
export const calculateActionLeafGasForMoonbeam = (
// eslint-disable-next-line @typescript-eslint/no-unused-vars
foundryGas: string,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
deployedContractSizes: DeployedContractSize[],
// eslint-disable-next-line @typescript-eslint/no-unused-vars
access: ParsedAccountAccess
): string => {
// This is the maximum Merkle leaf gas size that fits in a batch on these networks. (The max batch
Expand Down Expand Up @@ -65,7 +62,6 @@ export type SupportedNetwork = {
}
handleNetworkSpecificMerkleLeafGas?: (
foundryGas: string,
deployedContractSizes: DeployedContractSize[],
access: ParsedAccountAccess
) => string
}
Expand Down
5 changes: 0 additions & 5 deletions packages/contracts/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@ export type ParsedAccountAccess = {
nested: Array<AccountAccess>
}

export type DeployedContractSize = {
account: string
size: string
}

export type DecodedApproveLeafData = {
safeProxy: string
moduleProxy: string
Expand Down
80 changes: 61 additions & 19 deletions packages/contracts/test/SphinxInitCode.sol

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions packages/core/src/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
ContractArtifact,
SphinxMerkleTree,
ParsedAccountAccess,
DeployedContractSize,
} from '@sphinx-labs/contracts'

import { BuildInfo, CompilerInput } from '../languages/solidity/types'
Expand Down Expand Up @@ -119,7 +118,6 @@ export type DeploymentInfo = {
sphinxLibraryVersion: string
accountAccesses: Array<ParsedAccountAccess>
gasEstimates: Array<string>
deployedContractSizes: Array<DeployedContractSize>
fundsRequestedForSafe: string
safeStartingBalance: string
}
Expand Down
12 changes: 2 additions & 10 deletions packages/core/src/networks.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
// Warning: The constants in this file are commonly imported from the frontend of the Sphinx Managed website.
// Be careful when importing external dependencies to this file because they may cause issues when this file
// is imported by the website.
import {
DeployedContractSize,
ParsedAccountAccess,
} from '@sphinx-labs/contracts'
import { ParsedAccountAccess } from '@sphinx-labs/contracts'
import {
ExplorerName,
SPHINX_LOCAL_NETWORKS,
Expand Down Expand Up @@ -131,17 +128,12 @@ export const fetchDripVersionForNetwork = (chainId: bigint) => {
export const calculateMerkleLeafGas = (
chainId: bigint,
foundryGas: string,
deployedContractSizes: DeployedContractSize[],
access: ParsedAccountAccess
) => {
const network = SPHINX_NETWORKS.find((n) => n.chainId === chainId)

if (network?.handleNetworkSpecificMerkleLeafGas) {
return network.handleNetworkSpecificMerkleLeafGas(
foundryGas,
deployedContractSizes,
access
)
return network.handleNetworkSpecificMerkleLeafGas(foundryGas, access)
} else {
return foundryGas
}
Expand Down
18 changes: 0 additions & 18 deletions packages/plugins/src/foundry/decode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,6 @@ export const decodeDeploymentInfo = (
'parsedAccountAccessType'
)

const deployedContractSizesFragment = findFunctionFragment(
sphinxPluginTypesInterface,
'deployedContractSizesType'
)

const coder = AbiCoder.defaultAbiCoder()

const {
Expand All @@ -78,16 +73,6 @@ export const decodeDeploymentInfo = (

const gasEstimates = abiDecodeUint256Array(parsed.gasEstimates)

// ABI decode the `deployedContractSizes` array
const deployedContractSizesResult = coder.decode(
deployedContractSizesFragment.outputs,
parsed.encodedDeployedContractSizes
)
const { deployedContractSizes } = recursivelyConvertResult(
deployedContractSizesFragment.outputs,
deployedContractSizesResult
) as any

// ABI decode each `ParsedAccountAccess` individually.
const accountAccesses = parsed.encodedAccountAccesses.map((encoded) => {
const decodedResult = coder.decode(
Expand Down Expand Up @@ -129,7 +114,6 @@ export const decodeDeploymentInfo = (
sphinxLibraryVersion: abiDecodeString(sphinxLibraryVersion),
accountAccesses,
gasEstimates,
deployedContractSizes,
fundsRequestedForSafe,
safeStartingBalance,
}
Expand Down Expand Up @@ -164,7 +148,6 @@ export const makeNetworkConfig = (
requireSuccess,
accountAccesses,
gasEstimates,
deployedContractSizes,
fundsRequestedForSafe,
safeStartingBalance,
} = deploymentInfo
Expand All @@ -176,7 +159,6 @@ export const makeNetworkConfig = (
const gas = calculateMerkleLeafGas(
BigInt(chainId),
gasEstimates[i].toString(),
deployedContractSizes,
accountAccesses[i]
)

Expand Down
2 changes: 0 additions & 2 deletions packages/plugins/test/mocha/artifacts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,6 @@ const makeThenRunThenCheckDeployment = async (
threshold,
executionMode,
accountAccesses,
[],
getAnvilRpcUrl
)

Expand Down Expand Up @@ -362,7 +361,6 @@ const makeThenRunThenCheckRemoteDeployment = async (
threshold,
executionMode,
accountAccesses,
[],
getAnvilRpcUrl
)

Expand Down
Loading

0 comments on commit c7af7ef

Please sign in to comment.