Skip to content

Commit

Permalink
feat(addresses): Get context addresses from context-addresses package
Browse files Browse the repository at this point in the history
This is a first version that only loads default tokens and associates them with the token symbol.
  • Loading branch information
espendk committed Nov 10, 2023
1 parent 5ae4875 commit b691cff
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 10 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
},
"dependencies": {
"@ethersproject/experimental": "^5.7.0",
"@mangrovedao/context-addresses": "next",
"@mangrovedao/mangrove-core": "^2.0.0-3",
"@mangrovedao/mangrove-deployments": "next",
"@mangrovedao/mangrove-strats": "next",
Expand Down
55 changes: 45 additions & 10 deletions src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { Bigish, Provider, typechain } from "./types";
import mgvCore from "@mangrovedao/mangrove-core";
import mgvStrats from "@mangrovedao/mangrove-strats";
import * as mgvDeployments from "@mangrovedao/mangrove-deployments";
import * as contextAddresses from "@mangrovedao/context-addresses";
import * as eth from "./eth";
import clone from "just-clone";
import deepmerge from "deepmerge";
Expand Down Expand Up @@ -521,6 +522,7 @@ export function resetConfiguration(): void {
readContractPackageContextAddresses(mgvCore.addresses.context);
readContractPackageContextAddresses(mgvStrats.addresses.context);
readMangroveDeploymentAddresses();
readContextAddresses();
}

function readContractPackageContextAddresses(
Expand Down Expand Up @@ -555,16 +557,6 @@ function readMangroveDeploymentAddresses() {
released: mgvStratsReleasedFilter,
});
readVersionDeploymentsAddresses(mgvStratsContractsDeployments);

// For ERC20s we do not care about the versions nor whether they are released or not
const testErc20VersionPattern = undefined;
const testErc20ReleasedFilter = undefined; // undefined => released & unreleased
const testErc20ContractsDeployments =
mgvDeployments.getAllTestErc20VersionDeployments({
version: testErc20VersionPattern,
released: testErc20ReleasedFilter,
});
readVersionDeploymentsAddresses(testErc20ContractsDeployments);
}

function readVersionDeploymentsAddresses(
Expand All @@ -584,6 +576,49 @@ function readVersionDeploymentsAddresses(
}
}

function readContextAddresses() {
readContextErc20Addresses();
readContextAaveAddresses();
}

function readContextErc20Addresses() {
for (const [, /*tokenId*/ erc20] of Object.entries(
contextAddresses.getAllErc20s()
)) {
for (const [networkId, networkInstances] of Object.entries(
erc20.networkInstances
)) {
const networkName = eth.getNetworkName(+networkId);
for (const [, /*erc20InstanceId*/ erc20Instance] of Object.entries(
networkInstances
)) {
// FIXME: All instances should be available, not just the default.
// This requires regisering the address ID instead of the token symbol
// + changes to configuration, but probably not more than that?
if (!erc20Instance.default) {
continue;
}
addressesConfiguration.setAddress(
erc20.symbol,
erc20Instance.address,
networkName
);
break;
}
}
}
}

function readContextAaveAddresses() {
const allAaveV3Addresses = contextAddresses.getAllAaveV3Addresses();
for (const [addressId, role] of Object.entries(allAaveV3Addresses)) {
for (const [networkId, address] of Object.entries(role.networkAddresses)) {
const networkName = eth.getNetworkName(+networkId);
addressesConfiguration.setAddress(addressId, address, networkName);
}
}
}

/** Update the configuration by providing a partial configuration containing only the values that should be changed/added.
*
* Example for adding configuration for a new token with symbol "SYM":
Expand Down
10 changes: 10 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1236,6 +1236,15 @@ __metadata:
languageName: node
linkType: hard

"@mangrovedao/context-addresses@npm:next":
version: 0.0.2-1
resolution: "@mangrovedao/context-addresses@npm:0.0.2-1"
dependencies:
semver: ^7.5.4
checksum: b4d1a36868af691d99fe18485a3c903b53dfeb7b3866382021971f10026ae4bcd259ced9efe56a04f1d2a6b1f90ff55e9213d3e676e2e4d9a3435ae836a01904
languageName: node
linkType: hard

"@mangrovedao/mangrove-core@npm:^2.0.0-3":
version: 2.0.0-3
resolution: "@mangrovedao/mangrove-core@npm:2.0.0-3"
Expand Down Expand Up @@ -1278,6 +1287,7 @@ __metadata:
"@ethersproject/experimental": ^5.7.0
"@ethersproject/hardware-wallets": ^5.7.0
"@ethersproject/providers": ^5.7.2
"@mangrovedao/context-addresses": next
"@mangrovedao/mangrove-core": ^2.0.0-3
"@mangrovedao/mangrove-deployments": next
"@mangrovedao/mangrove-strats": next
Expand Down

0 comments on commit b691cff

Please sign in to comment.