-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow configuration of Gnosis contractAddresses
Provide our own types as gnosis does not define adequate types. Signed-off-by: Ryan Goulding <[email protected]>
- Loading branch information
1 parent
cf3d897
commit baf0e15
Showing
3 changed files
with
59 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { readFileSync } from 'fs' | ||
|
||
const GNOSIS_SAFE_FILE_ENCODING = 'utf-8' | ||
|
||
/** | ||
* Gnosis Safe configuration for a specific network. | ||
*/ | ||
type SafeConfig = { | ||
safeAddress: string | ||
url: string | ||
contractNetworks?: ContractNetworks | ||
} | ||
|
||
/** | ||
* Contract addresses for each network. | ||
*/ | ||
type ContractNetworks = { | ||
[chainListId: number]: { | ||
multiSendAddress: string | ||
safeMasterCopyAddress: string | ||
safeProxyFactoryAddress: string | ||
} | ||
} | ||
|
||
/** | ||
* Converts a ContractNetworks object to a string. | ||
* @param {ContractNetworks} contractNetworks The ContractNetworks object to convert. | ||
*/ | ||
export const toContractNetworksString = (contractNetworks?: ContractNetworks): string => { | ||
if (contractNetworks === undefined) { | ||
return '' | ||
} | ||
return Object.entries(contractNetworks).reduce((accumulator, [chainListId, config]) => { | ||
return accumulator + `contractNetworks[chainListId=${chainListId}, multiSendAddress=${config.multiSendAddress}, safeMasterCopyAddress=${config.safeMasterCopyAddress}, safeProxyFactoryAddress=${config.safeProxyFactoryAddress}]`; | ||
}, ''); | ||
} | ||
|
||
/** | ||
* Gnosis Safe configuration per network. | ||
*/ | ||
export interface SafeConfigs { | ||
[chainName: string]: SafeConfig | ||
} | ||
|
||
/** | ||
* Reads the safe config file and returns the parsed SafeConfigs. | ||
* @param {string} fileName The name of the safe config file. | ||
*/ | ||
export const getSafeConfigs = (fileName: string): SafeConfigs => { | ||
return JSON.parse(readFileSync(fileName, GNOSIS_SAFE_FILE_ENCODING)) as SafeConfigs | ||
} |