-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #223 from morpho-org/fix/fetch-eip712-domain-in-token
Fix/fetch eip712 domain in token
- Loading branch information
Showing
36 changed files
with
540 additions
and
262 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
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
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 |
---|---|---|
@@ -1,55 +1,35 @@ | ||
import type { Provider } from "ethers"; | ||
import { MetaMorpho__factory } from "ethers-types"; | ||
|
||
import { | ||
type Address, | ||
type ChainId, | ||
ChainUtils, | ||
UnknownVaultConfigError, | ||
VaultConfig, | ||
_try, | ||
} from "@morpho-org/blue-sdk"; | ||
import { type Address, ChainUtils, VaultConfig } from "@morpho-org/blue-sdk"; | ||
import type { FetchOptions } from "../types"; | ||
import { fetchToken } from "./Token"; | ||
|
||
export async function fetchVaultConfig( | ||
address: Address, | ||
runner: { provider: Provider }, | ||
{ chainId }: { chainId?: ChainId } = {}, | ||
options: FetchOptions = {}, | ||
) { | ||
chainId = ChainUtils.parseSupportedChainId( | ||
chainId ?? (await runner.provider.getNetwork()).chainId, | ||
options.chainId = ChainUtils.parseSupportedChainId( | ||
options.chainId ?? (await runner.provider.getNetwork()).chainId, | ||
); | ||
|
||
let config = _try( | ||
() => VaultConfig.get(address, chainId), | ||
UnknownVaultConfigError, | ||
); | ||
|
||
if (!config) { | ||
const mm = MetaMorpho__factory.connect( | ||
address, | ||
// @ts-ignore incompatible commonjs type | ||
runner, | ||
); | ||
const mm = MetaMorpho__factory.connect(address, runner); | ||
|
||
// always fetch at latest block because config is immutable | ||
const [asset, symbol, name, decimalsOffset] = await Promise.all([ | ||
mm.asset() as Promise<Address>, | ||
mm.symbol(), | ||
mm.name(), | ||
mm.DECIMALS_OFFSET(), | ||
]); | ||
const { overrides = {} } = options; | ||
|
||
config = new VaultConfig( | ||
{ | ||
address, | ||
asset, | ||
symbol, | ||
name, | ||
decimalsOffset, | ||
}, | ||
chainId, | ||
); | ||
} | ||
const [token, asset, decimalsOffset] = await Promise.all([ | ||
fetchToken(address, runner, options), // TODO: avoid fetching decimals | ||
mm.asset() as Promise<Address>, | ||
mm.DECIMALS_OFFSET(overrides), | ||
]); | ||
|
||
return config; | ||
return new VaultConfig( | ||
{ | ||
...token, | ||
asset, | ||
decimalsOffset, | ||
}, | ||
options.chainId, | ||
); | ||
} |
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
Oops, something went wrong.