Safe Deployments

repository·main·Indexed 41 days ago

https://github.com/safe-global/safe-deployments

A library providing a collection of deployment addresses and ABIs for Safe smart account contracts across various networks. It allows developers to programmatically retrieve contract addresses for different versions and deployment types, including canonical, EIP-155, and zkSync, using V1 and V2 query methods.

Tokens
6.3K
Snippets
29
Records
29
Agent score
51%

What's inside Safe Deployments

  1. How to use DeploymentFilter to query deployments

    main

    When using the library's query methods, you can pass an optional DeploymentFilter object to refine your search.

    • version: A specific version string (e.g., '1.3.0').
    • released: A boolean. If undefined, it returns the latest version even if not yet released. Defaults to true if not specified.
    • network: The chain ID of the network as a string (e.g., '5' for Goerli).
    interface DeploymentFilter {
      version?: string;
      released?: boolean; // Defaults to true if no filter is specified
      network?: string; // Chain id of the network
    }
  2. Install @safe-global/safe-deployments

    main

    You can install the library using npm, yarn, or pnpm to access Safe contract addresses and ABIs programmatically.

    npm i @safe-global/safe-deployments
    yarn add @safe-global/safe-deployments
    pnpm add @safe-global/safe-deployments
    npm i @safe-global/safe-deployments
  3. Get Safe Singleton deployments (V2)

    main

    Use the V2 methods to retrieve a SingletonDeployment object that supports multiple addresses per network. This is the preferred method for modern integrations.

    Available V2 methods:

    • getSafeSingletonDeployments()
    • getSafeL2SingletonDeployments()
    • getProxyFactoryDeployments()
    • getMultiSendDeployments()
    • getMultiSendCallOnlyDeployments()
    • getCreateCallDeployments()
    • getSignMessageLibDeployments()
    • getFallbackHandlerDeployments()
    • getTokenCallbackHandlerDeployments()
    • getCompatibilityFallbackHandlerDeployments()
    • getExtensibleFallbackHandlerDeployments()
    // Returns latest contract version, even if not finally released yet
    const safeSingletonNightly = getSafeSingletonDeployments({ released: undefined });
    
    // Returns released contract version for specific network
    const safeSingletonGörli = getSafeSingletonDeployments({ network: '5' });
    
    // Returns released contract version for specific version
    const safeSingleton100 = getSafeSingletonDeployments({ version: '1.0.0' });
  4. Get Safe Singleton deployments (V1)

    main

    Use the V1 methods to retrieve a SingletonDeployment object for a single contract. These methods are suitable when you expect only one address per network.

    Available V1 methods:

    • getSafeSingletonDeployment()
    • getSafeL2SingletonDeployment()
    • getProxyFactoryDeployment()
    • getMultiSendDeployment()
    • getMultiSendCallOnlyDeployment()
    • getCreateCallDeployment()
    • getSignMessageLibDeployment()
    • getFallbackHandlerDeployment()
    • getTokenCallbackHandlerDeployment()
    • getCompatibilityFallbackHandlerDeployment()
    • getExtensibleFallbackHandlerDeployment()
    // Returns latest contract version, even if not finally released yet
    const safeSingletonNightly = getSafeSingletonDeployment({ released: undefined });
    
    // Returns released contract version for specific network
    const safeSingletonGörli = getSafeSingletonDeployment({ network: '5' });
    
    // Returns released contract version for specific version
    const safeSingleton100 = getSafeSingletonDeployment({ version: '1.0.0' });
  5. Reference: SingletonDeployment interface (V1 vs V2)

    main

    The SingletonDeployment object contains the contract's metadata, addresses, and ABI. The primary difference between V1 and V2 is the structure of the networkAddresses field.

    V1 Structure: networkAddresses is a Record<string, string> (one address per network). V2 Structure: networkAddresses is a Record<string, string | string[]> (allows multiple addresses per network).

    To maintain backward compatibility, the first address in a V2 string[] array matches the address used in V1.

    // V1 Interface
    export interface SingletonDeployment {
      defaultAddress: string;
      released: boolean;
      contractName: string;
      version: string;
      deployments: Record<string, { address: string; codeHash: string }>;
      networkAddresses: Record<string, string>; // Single address
      abi: any[];
    }
    
    // V2 Interface
    export interface SingletonDeployment {
      defaultAddress: string;
      released: boolean;
      contractName: string;
      version: string;
      deployments: Record<string, { address: string; codeHash: string }>;
      networkAddresses: Record<string, string | string[]>; // Multiple addresses allowed
      abi: any[];
    }
  6. Retrieve multiple Safe Singleton deployments

    main

    Use getSafeSingletonDeployments to retrieve an array of all Safe Singleton deployments that match the provided DeploymentFilter. This uses DeploymentFormats.MULTIPLE internally to return a collection rather than a single instance.

    import { getSafeSingletonDeployments } from '@safe-global/safe-deployments';
    
    // Example: finding all deployments matching a filter
    const deployments = getSafeSingletonDeployments({ chainId: 137 });
    
    if (deployments) {
      deployments.forEach(d => console.log(d.address));
    }
  7. Retrieve multiple Safe L2 Singleton deployments

    main

    Use getSafeL2SingletonDeployments to retrieve an array of all Safe L2 Singleton deployments that match the provided DeploymentFilter.

    import { getSafeL2SingletonDeployments } from '@safe-global/safe-deployments';
    
    const deployments = getSafeL2SingletonDeployments({ chainId: 42161 });
    
    if (deployments) {
      deployments.forEach(d => console.log(d.address));
    }
  8. Retrieve SafeToL2Migration deployments

    main

    Use getSafeToL2MigrationDeployment to retrieve a single SafeToL2Migration deployment or getSafeToL2MigrationDeployments to retrieve multiple deployments based on a provided DeploymentFilter.

    import { getSafeToL2MigrationDeployment, getSafeToL2MigrationDeployments } from '@safe-global/safe-deployments';
    
    const deployment = getSafeToL2MigrationDeployment({ chain: 1 });
    const deployments = getSafeToL2MigrationDeployments({ chain: 1 });
  9. Retrieve SignMessageLib deployments

    main

    Use getSignMessageLibDeployment to retrieve a single SignMessageLib deployment or getSignMessageLibDeployments to retrieve multiple deployments based on a provided DeploymentFilter.

    import { getSignMessageLibDeployment, getSignMessageLibDeployments } from '@safe-global/safe-deployments';
    
    const deployment = getSignMessageLibDeployment({ chain: 1 });
    const deployments = getSignMessageLibDeployments({ chain: 1 });
  10. Retrieve a single Safe Singleton deployment

    main

    Use getSafeSingletonDeployment to find the latest Safe Singleton deployment matching a specific DeploymentFilter. If no deployment matches the filter, it returns undefined.

    import { getSafeSingletonDeployment } from '@safe-global/safe-deployments';
    
    // Example: finding a deployment with a specific filter
    const deployment = getSafeSingletonDeployment({ chainId: 1 });
    
    if (deployment) {
      console.log('Found deployment:', deployment.address);
    }
  11. Retrieve MultiSendCallOnly deployments

    main

    Use getMultiSendCallOnlyDeployment to retrieve a single MultiSendCallOnly deployment or getMultiSendCallOnlyDeployments to retrieve multiple deployments based on a provided DeploymentFilter. These are specialized versions of MultiSend.

    import { getMultiSendCallOnlyDeployment, getMultiSendCallOnlyDeployments } from '@safe-global/safe-deployments';
    
    const deployment = getMultiSendCallOnlyDeployment({ chain: 1 });
    const deployments = getMultiSendCallOnlyDeployments({ chain: 1 });
  12. Retrieve a single Safe L2 Singleton deployment

    main

    Use getSafeL2SingletonDeployment to find the latest Safe L2 Singleton deployment matching a specific DeploymentFilter. This searches specifically within the L2 deployment registry.

    import { getSafeL2SingletonDeployment } from '@safe-global/safe-deployments';
    
    const deployment = getSafeL2SingletonDeployment({ chainId: 10 });
    
    if (deployment) {
      console.log('Found L2 deployment:', deployment.address);
    }