-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Use addresses from mangrove-deployments and context-addresses p…
…ackages (#651)
- Loading branch information
Showing
18 changed files
with
274 additions
and
186 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Ignore files | ||
* | ||
# Ignore subdirectories | ||
*/ | ||
# Don't ignore the README nor this file | ||
!.gitignore | ||
!README.md |
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,7 @@ | ||
# context directory | ||
|
||
The committed version of this directory should be empty (except for this README.md file). | ||
|
||
It will contain context addresses read by forge script. None of them will be committed. | ||
|
||
This directory must exist so forge script can write to it. |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,7 @@ | ||
# Ignore files | ||
* | ||
# Ignore subdirectories | ||
*/ | ||
# Don't ignore the README nor this file | ||
!.gitignore | ||
!README.md |
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,7 @@ | ||
# deployed directory | ||
|
||
The committed version of this directory should be empty (except for this README.md file). | ||
|
||
It will contain deployment addresses read by forge script. None of them will be committed. | ||
|
||
This directory must exist so forge script can write to it. |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,94 @@ | ||
const contextAddresses = require("@mangrovedao/context-addresses"); | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
const config = require("./config"); | ||
|
||
const script = path.basename(__filename); | ||
|
||
if (!config.copyContextAddresses) { | ||
console.group( | ||
"Skipping copying context addresses from the context-addresses package.", | ||
); | ||
console.log( | ||
"Set copyContextAddresses = true in config.js to enable copying.", | ||
); | ||
console.log("Using addresses/context/*.json files as-is instead."); | ||
console.groupEnd(); | ||
process.exit(0); | ||
} | ||
|
||
console.log(`${script}: Copying context addresses...`); | ||
|
||
// This is a hack to get the network names because the addresses | ||
// file names use non-canonical network names from ethers.js | ||
const networkNames = { | ||
1: "mainnet", | ||
5: "goerli", | ||
137: "matic", | ||
42161: "arbitrum", | ||
80001: "maticmum", | ||
}; | ||
|
||
// Construct the addresses object for each network | ||
const contextAddressesByNetwork = {}; // network name => { name: string, address: string }[] | ||
function getOrCreateNetworkAddresses(networkId) { | ||
const networkName = networkNames[+networkId]; | ||
let networkAddresses = contextAddressesByNetwork[networkName]; | ||
if (networkAddresses === undefined) { | ||
networkAddresses = []; | ||
contextAddressesByNetwork[networkName] = networkAddresses; | ||
} | ||
return networkAddresses; | ||
} | ||
|
||
// Accounts | ||
const allAccounts = contextAddresses.getAllAccounts(); | ||
for (const [accountId, account] of Object.entries(allAccounts)) { | ||
for (const [networkId, address] of Object.entries(account.networkAddresses)) { | ||
const networkAddresses = getOrCreateNetworkAddresses(networkId); | ||
networkAddresses.push({ | ||
name: accountId, | ||
address: address, | ||
}); | ||
} | ||
} | ||
|
||
// Token addresses | ||
const allErc20s = contextAddresses.getAllErc20s(); | ||
for (const [erc20Id, erc20] of Object.entries(allErc20s)) { | ||
for (const [networkId, networkInstances] of Object.entries( | ||
erc20.networkInstances, | ||
)) { | ||
const networkAddresses = getOrCreateNetworkAddresses(networkId); | ||
for (const [instanceId, networkInstance] of Object.entries( | ||
networkInstances, | ||
)) { | ||
networkAddresses.push({ | ||
name: instanceId, | ||
address: networkInstance.address, | ||
}); | ||
// Also register the default instance as the token symbol for convenience | ||
if (networkInstance.default) { | ||
networkAddresses.push({ | ||
name: erc20.symbol, | ||
address: networkInstance.address, | ||
}); | ||
} | ||
} | ||
} | ||
} | ||
|
||
// Create the addresses files with the loaded context addresses | ||
for (const networkName in contextAddressesByNetwork) { | ||
let addressesToWrite = contextAddressesByNetwork[networkName]; | ||
const networkAddressesFilePath = path.join( | ||
__dirname, | ||
`./addresses/context/${networkName}.json`, | ||
); | ||
fs.writeFileSync( | ||
networkAddressesFilePath, | ||
JSON.stringify(addressesToWrite, null, 2), | ||
); | ||
} | ||
|
||
console.log(`${script}: ...Done copying context addresses`); |
Oops, something went wrong.