@morpho-labs/v2-deployment
Version:
Morpho v2 chain configurations for viem
236 lines • 8.28 kB
JavaScript
/**
* @fileoverview Morpho Ethereum fork chain configurations for viem
*/
import { defineChain } from 'viem';
/**
* Morpho Ethereum Fork - Tenderly Virtual Testnet
*
* This chain configuration represents a Tenderly virtual testnet that forks Ethereum mainnet
* with Morpho protocol deployed and configured for testing purposes.
*
* Chain Details:
* - Fork of Ethereum mainnet
* - Tenderly Virtual Network ID: 03ab649e-b1f3-4e0a-8a75-cedd386802b0
* - Pre-deployed Morpho v2 contracts
* - Enhanced for testing and development
*/
export const morphoEthereumFork = defineChain({
id: 1111,
name: 'Morpho Ethereum Fork',
nativeCurrency: {
decimals: 18,
name: 'Ether',
symbol: 'ETH',
},
rpcUrls: {
default: {
http: ['https://virtual.mainnet.rpc.tenderly.co/03ab649e-b1f3-4e0a-8a75-cedd386802b0'],
},
public: {
http: ['https://virtual.mainnet.rpc.tenderly.co/03ab649e-b1f3-4e0a-8a75-cedd386802b0'],
},
},
blockExplorers: {
default: {
name: 'Tenderly Explorer',
url: 'https://dashboard.tenderly.co/explorer/vnet/03ab649e-b1f3-4e0a-8a75-cedd386802b0',
},
},
contracts: {
// Standard Ethereum contracts that are available in the fork
ensRegistry: {
address: '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e',
},
ensUniversalResolver: {
address: '0xE4Acdd618deED4e6d2f03b9bf62dc6118FC9A4da',
blockCreated: 16773775,
},
multicall3: {
address: '0xca11bde05977b3631167028862be2a173976ca11',
blockCreated: 14353601,
},
},
testnet: true,
sourceId: 1, // Forked from Ethereum mainnet
});
/**
* Alternative configuration for local development
* Uses a more generic setup for cases where you want to use your own Tenderly fork
*/
export const createMorphoFork = (params) => {
return defineChain({
id: params.chainId ?? 1337,
name: params.name ?? 'Morpho Fork',
nativeCurrency: {
decimals: 18,
name: 'Ether',
symbol: 'ETH',
},
rpcUrls: {
default: {
http: [`https://virtual.mainnet.rpc.tenderly.co/${params.vnetId}`],
},
public: {
http: [`https://virtual.mainnet.rpc.tenderly.co/${params.vnetId}`],
},
},
blockExplorers: {
default: {
name: 'Tenderly Explorer',
url: `https://dashboard.tenderly.co/explorer/vnet/${params.vnetId}`,
},
},
contracts: {
ensRegistry: {
address: '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e',
},
ensUniversalResolver: {
address: '0xE4Acdd618deED4e6d2f03b9bf62dc6118FC9A4da',
blockCreated: 16773775,
},
multicall3: {
address: '0xca11bde05977b3631167028862be2a173976ca11',
blockCreated: 14353601,
},
},
testnet: true,
sourceId: 1,
});
};
/**
* Export commonly used chain configurations
*/
export const chains = {
morphoEthereumFork,
};
/**
* Helper function to register Morpho contract addresses, deployments, and unwrapped tokens
* for fork chains with the blue-sdk registry.
*
* This enables the blue-sdk to work seamlessly with Morpho fork chains
* by providing the necessary contract addresses, deployment block numbers, and token mappings.
*
* @param options - Configuration object
* @param options.addresses - Morpho contract addresses for the fork chain
* @param options.deployments - Optional deployment block numbers for the contracts
* @param options.unwrappedTokens - Optional mapping of wrapped tokens to their unwrapped equivalents
* @param options.chainId - Chain ID of the fork (defaults to 1111 for morphoEthereumFork)
*
* @example
* import { registerMorphoForkAddresses } from '@morpho-labs/v2-deployment';
*
* // Register addresses for the default Morpho fork
* registerMorphoForkAddresses({
* addresses: {
* morpho: '0xBBBBBbbBBb9cC5e90e3b3Af64bdAF62C37EEFFCb',
* permit2: '0x000000000022D473030F116dDEE9F6B43aC78BA3',
* adaptiveCurveIrm: '0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC',
* wNative: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
* },
* deployments: {
* morpho: 18883124n,
* permit2: 15986406n,
* },
* unwrappedTokens: {
* '0xWrappedToken': '0xUnderlyingToken'
* }
* });
*
*/
export function registerMorphoForkAddresses({ addresses, deployments, unwrappedTokens, chainId = morphoEthereumFork.id, }) {
const { registerCustomAddresses } = require('@morpho-org/blue-sdk');
registerCustomAddresses({
addresses: {
[chainId]: addresses,
},
deployments: deployments
? {
[chainId]: deployments,
}
: undefined,
unwrappedTokens: unwrappedTokens
? {
[chainId]: unwrappedTokens,
}
: undefined,
});
}
/**
* Gets the Morpho mainnet addresses from blue-sdk.
* These addresses are available on the Tenderly fork since it's
* forked from Ethereum mainnet.
*/
function getMorphoMainnetAddresses() {
const { getChainAddresses } = require('@morpho-org/blue-sdk');
return getChainAddresses(1); // Ethereum mainnet
}
/**
* Gets the Morpho mainnet deployments from blue-sdk.
* These deployment block numbers correspond to the mainnet contracts.
*/
function getMorphoMainnetDeployments() {
const { deployments } = require('@morpho-org/blue-sdk');
return deployments[1]; // Ethereum mainnet
}
/**
* Gets the Morpho mainnet unwrapped token mappings from blue-sdk.
* These mappings are used to resolve wrapped tokens to their underlying assets.
*/
function getMorphoMainnetUnwrappedTokens() {
const { unwrappedTokensMapping } = require('@morpho-org/blue-sdk');
return unwrappedTokensMapping[1] || {}; // Ethereum mainnet
}
/**
* Convenience function to register the complete Morpho mainnet configuration
* (addresses, deployments, and unwrapped tokens) for the morphoEthereumFork chain.
*
* This function automatically pulls the latest mainnet data from blue-sdk
* and registers it for the fork chain, providing a complete setup.
*
* @param chainId - Optional chain ID to register for (defaults to 1111 for morphoEthereumFork)
*
* @example
* import { setupMorphoFork } from '@morpho-labs/v2-deployment';
*
* // Set up blue-sdk to work with the Morpho fork
* setupMorphoFork();
*
* // Now you can use blue-sdk with the morphoEthereumFork chain
* import { getChainAddresses, addressesRegistry } from '@morpho-org/blue-sdk';
* const addresses = getChainAddresses(1111); // morphoEthereumFork.id
* console.log(addresses.morpho); // Will be properly typed and available
*/
export function setupMorphoFork(chainId = morphoEthereumFork.id) {
const addresses = getMorphoMainnetAddresses();
const deployments = getMorphoMainnetDeployments();
const unwrappedTokens = getMorphoMainnetUnwrappedTokens();
registerMorphoForkAddresses({
addresses,
deployments,
unwrappedTokens,
chainId,
});
}
/**
* Get the properly typed addresses for the Morpho Ethereum fork chain.
* This function ensures that after setup, the addresses are correctly typed
* and available for use with blue-sdk.
*
* @param chainId - Chain ID to get addresses for (defaults to 1111 for morphoEthereumFork)
* @returns Properly typed ChainAddresses for the fork chain
*
* @example
* import { setupMorphoFork, getMorphoForkAddresses } from '@morpho-labs/v2-deployment';
*
* // First set up the fork
* setupMorphoFork();
*
* // Then get the addresses with proper typing
* const addresses = getMorphoForkAddresses(); // Properly typed as ChainAddresses
* console.log(addresses.morpho); // TypeScript knows this is an Address
*/
export function getMorphoForkAddresses(chainId = morphoEthereumFork.id) {
const { getChainAddresses } = require('@morpho-org/blue-sdk');
return getChainAddresses(chainId);
}
//# sourceMappingURL=chains.js.map