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

Compare all deployment type addresses when relaying #1955

Merged
merged 4 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
12 changes: 12 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ export default tseslint.config(
],
'@typescript-eslint/no-explicit-any': 'error',
'@typescript-eslint/no-floating-promises': 'warn',
'no-restricted-imports': [
'error',
{
paths: [
{
name: '@safe-global/safe-deployments',
message:
'Please import from @/domain/common/utils/deployments instead.',
},
],
},
],
// TODO: Address these rules: (added to update to ESLint 9)
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
Expand Down
118 changes: 118 additions & 0 deletions src/domain/common/utils/deployments.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
// eslint-disable-next-line no-restricted-imports
import {
getMultiSendCallOnlyDeployments as _getMultiSendCallOnlyDeployments,
getMultiSendDeployments as _getMultiSendDeployments,
getProxyFactoryDeployments as _getProxyFactoryDeployments,
getSafeL2SingletonDeployments as _getSafeL2SingletonDeployments,
getSafeSingletonDeployments as _getSafeSingletonDeployments,
} from '@safe-global/safe-deployments';

type Filter = {
chainId: string;
version: string;
};

/**
* Returns a list of official ProxyFactory addresses based on given {@link Filter}.
*
* @param {string} args.chainId - the chain ID to filter deployments by
* @param {string} args.version - the version to filter deployments by
*
* @returns {Array<`0x${string}`>} - a list of checksummed ProxyFactory addresses
*/
export function getProxyFactoryDeployments(args: Filter): Array<`0x${string}`> {
return formatDeployments(_getProxyFactoryDeployments, args);
}

/**
* Returns a list of official L1 singleton addresses based on given {@link Filter}.
*
* @param {string} args.chainId - the chain ID to filter deployments by
* @param {string} args.version - the version to filter deployments by
*
* @returns {Array<`0x${string}`>} - a list of checksummed L1 singleton addresses
*/
export function getSafeSingletonDeployments(
args: Filter,
): Array<`0x${string}`> {
return formatDeployments(_getSafeSingletonDeployments, args);
}

/**
* Returns a list of official L2 singleton addresses based on given {@link Filter}.
*
* @param {string} args.chainId - the chain ID to filter deployments by
* @param {string} args.version - the version to filter deployments by
*
* @returns {Array<`0x${string}`>} - a list of checksummed L2 singleton addresses
*/
export function getSafeL2SingletonDeployments(
args: Filter,
): Array<`0x${string}`> {
return formatDeployments(_getSafeL2SingletonDeployments, args);
}

/**
* Returns a list of official MultiSendCallOnly addresses based on given {@link Filter}.
*
* @param {string} args.chainId - the chain ID to filter deployments by
* @param {string} args.version - the version to filter deployments by
*
* @returns {Array<`0x${string}`>} - a list of checksummed MultiSendCallOnly addresses
*/
export function getMultiSendCallOnlyDeployments(
args: Filter,
): Array<`0x${string}`> {
return formatDeployments(_getMultiSendCallOnlyDeployments, args);
}

/**
* Returns a list of official MultiSend addresses based on given {@link Filter}.
*
* @param {string} args.chainId - the chain ID to filter deployments by
* @param {string} args.version - the version to filter deployments by
*
* @returns {Array<`0x${string}`>} - a list of checksummed MultiSend addresses
*/
export function getMultiSendDeployments(args: Filter): Array<`0x${string}`> {
return formatDeployments(_getMultiSendDeployments, args);
}

/**
* Helper to remap {@link SingletonDeploymentV2} to a list of checksummed addresses.
*
* @param {Function} getDeployments - function to get deployments
* @param {Filter} filter - filter to apply to deployments
*
* @returns {Array<`0x${string}`>} - a list of checksummed addresses
*/
function formatDeployments(
getDeployments:
| typeof _getProxyFactoryDeployments
| typeof _getSafeSingletonDeployments
| typeof _getSafeL2SingletonDeployments
| typeof _getMultiSendCallOnlyDeployments
| typeof _getMultiSendDeployments,
filter: Filter,
): Array<`0x${string}`> {
const deployments = getDeployments({
network: filter.chainId,
version: filter.version,
});

if (!deployments) {
return [];
}

const chainDeployments = deployments.networkAddresses[filter.chainId];
if (!chainDeployments) {
return [];
}

// Note: can cast as deployment are inherently checksummed
if (!Array.isArray(chainDeployments)) {
return [chainDeployments as `0x${string}`];
}

return chainDeployments as Array<`0x${string}`>;
}
Loading