From 75d40a83fda061c37704e7de8bcc3cdbca498b55 Mon Sep 17 00:00:00 2001 From: J M Rossy Date: Wed, 22 Feb 2023 16:40:23 -0500 Subject: [PATCH] Update for compat with SDK 1.2.0 (#44) --- package.json | 4 +-- src/app/app.ts | 54 ++++++++++++++--------------------- src/deploy/check.ts | 9 ++---- src/deploy/config.ts | 4 +-- src/deploy/deploy.ts | 13 ++++----- src/scripts/check.ts | 12 ++------ src/scripts/deploy.ts | 8 ++---- src/test/deploy.test.ts | 19 ++++++------- src/test/helloworld.test.ts | 27 +++++++++--------- yarn.lock | 57 +++++++++++++++++-------------------- 10 files changed, 84 insertions(+), 123 deletions(-) diff --git a/package.json b/package.json index e5fd5a391..a30909ed6 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,9 @@ { "name": "@hyperlane-xyz/helloworld", "description": "A basic skeleton of an Hyperlane app", - "version": "1.1.3", + "version": "1.2.0", "dependencies": { - "@hyperlane-xyz/sdk": "^1.1.3", + "@hyperlane-xyz/sdk": "1.2.0", "@openzeppelin/contracts-upgradeable": "^4.8.0", "ethers": "^5.7.2" }, diff --git a/src/app/app.ts b/src/app/app.ts index ed0ba6a9e..ecd1610f1 100644 --- a/src/app/app.ts +++ b/src/app/app.ts @@ -3,12 +3,10 @@ import { BigNumber, ethers } from 'ethers'; import { ChainMap, ChainName, - ChainNameToDomainId, HyperlaneApp, HyperlaneCore, InterchainGasCalculator, MultiProvider, - Remotes, } from '@hyperlane-xyz/sdk'; import { debug } from '@hyperlane-xyz/utils'; @@ -19,37 +17,36 @@ type Counts = { received: number; }; -export class HelloWorldApp< - Chain extends ChainName = ChainName, -> extends HyperlaneApp { +export class HelloWorldApp extends HyperlaneApp { constructor( - public readonly core: HyperlaneCore, - contractsMap: ChainMap, - multiProvider: MultiProvider, + public readonly core: HyperlaneCore, + contractsMap: ChainMap, + multiProvider: MultiProvider, ) { super(contractsMap, multiProvider); } - async sendHelloWorld( - from: From, - to: Remotes, + async sendHelloWorld( + from: ChainName, + to: ChainName, message: string, value: BigNumber, ): Promise { const sender = this.getContracts(from).router; - const toDomain = ChainNameToDomainId[to]; - const chainConnection = this.multiProvider.getChainConnection(from); + const toDomain = this.multiProvider.getDomainId(to); + const { blocks, transactionOverrides } = + this.multiProvider.getChainMetadata(from); // apply gas buffer due to https://github.com/hyperlane-xyz/hyperlane-monorepo/issues/634 const estimated = await sender.estimateGas.sendHelloWorld( toDomain, message, - { ...chainConnection.overrides, value }, + { ...transactionOverrides, value }, ); const gasLimit = estimated.mul(12).div(10); const tx = await sender.sendHelloWorld(toDomain, message, { - ...chainConnection.overrides, + ...transactionOverrides, gasLimit, value, }); @@ -59,13 +56,10 @@ export class HelloWorldApp< message, tx, }); - return tx.wait(chainConnection.confirmations); + return tx.wait(blocks?.confirmations || 1); } - async quoteGasPayment( - from: Exclude, - to: To, - ): Promise { + async quoteGasPayment(from: ChainName, to: ChainName): Promise { const sender = this.getContracts(from).router; const handleGasAmount = await sender.HANDLE_GAS_AMOUNT(); @@ -92,22 +86,19 @@ export class HelloWorldApp< return this.core.waitForMessageProcessed(receipt); } - async channelStats( - from: From, - to: Remotes, - ): Promise { + async channelStats(from: ChainName, to: ChainName): Promise { const sent = await this.getContracts(from).router.sentTo( - ChainNameToDomainId[to], + this.multiProvider.getDomainId(to), ); const received = await this.getContracts(to).router.receivedFrom( - ChainNameToDomainId[from], + this.multiProvider.getDomainId(from), ); return { sent: sent.toNumber(), received: received.toNumber() }; } - async stats(): Promise>> { - const entries: Array<[Chain, Record]> = await Promise.all( + async stats(): Promise>> { + const entries: Array<[ChainName, ChainMap]> = await Promise.all( this.chains().map(async (source) => { const destinationEntries = await Promise.all( this.remoteChains(source).map(async (destination) => [ @@ -115,12 +106,9 @@ export class HelloWorldApp< await this.channelStats(source, destination), ]), ); - return [ - source, - Object.fromEntries(destinationEntries) as Record, - ]; + return [source, Object.fromEntries(destinationEntries)]; }), ); - return Object.fromEntries(entries) as Record>; + return Object.fromEntries(entries); } } diff --git a/src/deploy/check.ts b/src/deploy/check.ts index ad0c0eb60..5f80474e1 100644 --- a/src/deploy/check.ts +++ b/src/deploy/check.ts @@ -1,15 +1,12 @@ -import { ChainName, HyperlaneRouterChecker } from '@hyperlane-xyz/sdk'; +import { HyperlaneRouterChecker } from '@hyperlane-xyz/sdk'; import { HelloWorldApp } from '../app/app'; import { HelloWorldContracts } from '../app/contracts'; import { HelloWorldConfig } from './config'; -export class HelloWorldChecker< - Chain extends ChainName, -> extends HyperlaneRouterChecker< - Chain, - HelloWorldApp, +export class HelloWorldChecker extends HyperlaneRouterChecker< + HelloWorldApp, HelloWorldConfig, HelloWorldContracts > {} diff --git a/src/deploy/config.ts b/src/deploy/config.ts index d52df55bb..d678e91aa 100644 --- a/src/deploy/config.ts +++ b/src/deploy/config.ts @@ -1,8 +1,8 @@ -import { RouterConfig, chainConnectionConfigs } from '@hyperlane-xyz/sdk'; +import { RouterConfig, chainMetadata } from '@hyperlane-xyz/sdk'; export type HelloWorldConfig = RouterConfig; // SET DESIRED NETWORKS HERE export const prodConfigs = { - alfajores: chainConnectionConfigs.alfajores, + alfajores: chainMetadata.alfajores, }; diff --git a/src/deploy/deploy.ts b/src/deploy/deploy.ts index d9e7b939d..4c55dcae8 100644 --- a/src/deploy/deploy.ts +++ b/src/deploy/deploy.ts @@ -14,25 +14,22 @@ import { import { HelloWorldConfig } from './config'; -export class HelloWorldDeployer< - Chain extends ChainName, -> extends HyperlaneRouterDeployer< - Chain, +export class HelloWorldDeployer extends HyperlaneRouterDeployer< HelloWorldConfig, HelloWorldContracts, HelloWorldFactories > { constructor( - multiProvider: MultiProvider, - configMap: ChainMap, - protected core: HyperlaneCore, + multiProvider: MultiProvider, + configMap: ChainMap, + protected core: HyperlaneCore, ) { super(multiProvider, configMap, helloWorldFactories, {}); } // Custom contract deployment logic can go here // If no custom logic is needed, call deployContract for the router - async deployContracts(chain: Chain, config: HelloWorldConfig) { + async deployContracts(chain: ChainName, config: HelloWorldConfig) { const router = await this.deployContract(chain, 'router', [ config.mailbox, config.interchainGasPaymaster, diff --git a/src/scripts/check.ts b/src/scripts/check.ts index 47b28b3b2..1be59f901 100644 --- a/src/scripts/check.ts +++ b/src/scripts/check.ts @@ -1,11 +1,9 @@ import { ChainMap, - ChainName, HyperlaneCore, MultiProvider, buildContracts, getChainToOwnerMap, - objMap, } from '@hyperlane-xyz/sdk'; import { HelloWorldApp } from '../app/app'; @@ -21,18 +19,12 @@ const ownerAddress = '0x123...'; async function check() { console.info('Preparing utilities'); - const chainProviders = objMap(prodConfigs, (_, config) => ({ - id: config.id, - provider: config.provider, - confirmations: config.confirmations, - overrides: config.overrides, - })); - const multiProvider = new MultiProvider(chainProviders); + const multiProvider = new MultiProvider(prodConfigs); const contractsMap = buildContracts( deploymentAddresses, helloWorldFactories, - ) as ChainMap; + ) as ChainMap; const core = HyperlaneCore.fromEnvironment('testnet', multiProvider); const app = new HelloWorldApp(core, contractsMap, multiProvider); diff --git a/src/scripts/deploy.ts b/src/scripts/deploy.ts index d1898a37c..a2a79ea83 100644 --- a/src/scripts/deploy.ts +++ b/src/scripts/deploy.ts @@ -4,7 +4,6 @@ import { HyperlaneCore, MultiProvider, getChainToOwnerMap, - objMap, serializeContracts, } from '@hyperlane-xyz/sdk'; @@ -16,11 +15,8 @@ async function main() { const signer = new Wallet('SET KEY HERE OR CREATE YOUR OWN SIGNER'); console.info('Preparing utilities'); - const chainProviders = objMap(prodConfigs, (_, config) => ({ - ...config, - signer: signer.connect(config.provider), - })); - const multiProvider = new MultiProvider(chainProviders); + const multiProvider = new MultiProvider(prodConfigs); + multiProvider.setSharedSigner(signer); const core = HyperlaneCore.fromEnvironment('testnet', multiProvider); const config = core.extendWithConnectionClientConfig( diff --git a/src/test/deploy.test.ts b/src/test/deploy.test.ts index 77c503606..db0b231b7 100644 --- a/src/test/deploy.test.ts +++ b/src/test/deploy.test.ts @@ -4,12 +4,9 @@ import { ethers } from 'hardhat'; import { ChainMap, MultiProvider, - TestChainNames, TestCoreApp, TestCoreDeployer, - getChainToOwnerMap, - getTestMultiProvider, - testChainConnectionConfigs, + getTestOwnerConfig, } from '@hyperlane-xyz/sdk'; import { HelloWorldApp } from '../app/app'; @@ -19,22 +16,22 @@ import { HelloWorldConfig } from '../deploy/config'; import { HelloWorldDeployer } from '../deploy/deploy'; describe('deploy', async () => { - let multiProvider: MultiProvider; + let multiProvider: MultiProvider; let core: TestCoreApp; - let config: ChainMap; - let deployer: HelloWorldDeployer; - let contracts: Record; - let app: HelloWorldApp; + let config: ChainMap; + let deployer: HelloWorldDeployer; + let contracts: ChainMap; + let app: HelloWorldApp; before(async () => { const [signer] = await ethers.getSigners(); - multiProvider = getTestMultiProvider(signer); + multiProvider = MultiProvider.createTestMultiProvider({ signer }); const coreDeployer = new TestCoreDeployer(multiProvider); const coreContractsMaps = await coreDeployer.deploy(); core = new TestCoreApp(coreContractsMaps, multiProvider); config = core.extendWithConnectionClientConfig( - getChainToOwnerMap(testChainConnectionConfigs, signer.address), + getTestOwnerConfig(signer.address), ); deployer = new HelloWorldDeployer(multiProvider, config, core); }); diff --git a/src/test/helloworld.test.ts b/src/test/helloworld.test.ts index 800088870..cd6178a56 100644 --- a/src/test/helloworld.test.ts +++ b/src/test/helloworld.test.ts @@ -4,14 +4,11 @@ import { ethers } from 'hardhat'; import { ChainMap, - ChainNameToDomainId, + Chains, MultiProvider, - TestChainNames, TestCoreApp, TestCoreDeployer, - getChainToOwnerMap, - getTestMultiProvider, - testChainConnectionConfigs, + getTestOwnerConfig, } from '@hyperlane-xyz/sdk'; import { HelloWorldConfig } from '../deploy/config'; @@ -23,29 +20,31 @@ import { } from '../types'; describe('HelloWorld', async () => { - const localChain = 'test1'; - const remoteChain = 'test2'; - const localDomain = ChainNameToDomainId[localChain]; - const remoteDomain = ChainNameToDomainId[remoteChain]; + const localChain = Chains.test1; + const remoteChain = Chains.test2; + let localDomain: number; + let remoteDomain: number; let signer: SignerWithAddress; let local: HelloWorld; let remote: HelloWorld; let localIgp: IInterchainGasPaymaster; - let multiProvider: MultiProvider; + let multiProvider: MultiProvider; let coreApp: TestCoreApp; - let config: ChainMap; + let config: ChainMap; before(async () => { [signer] = await ethers.getSigners(); - multiProvider = getTestMultiProvider(signer); + multiProvider = MultiProvider.createTestMultiProvider({ signer }); + localDomain = multiProvider.getDomainId(localChain); + remoteDomain = multiProvider.getDomainId(remoteChain); const coreDeployer = new TestCoreDeployer(multiProvider); const coreContractsMaps = await coreDeployer.deploy(); coreApp = new TestCoreApp(coreContractsMaps, multiProvider); config = coreApp.extendWithConnectionClientConfig( - getChainToOwnerMap(testChainConnectionConfigs, signer.address), + getTestOwnerConfig(signer.address), ); }); @@ -57,7 +56,7 @@ describe('HelloWorld', async () => { remote = contracts[remoteChain].router; localIgp = IInterchainGasPaymaster__factory.connect( config[localChain].interchainGasPaymaster, - multiProvider.getChainProvider(localChain), + multiProvider.getProvider(localChain), ); // The all counts start empty diff --git a/yarn.lock b/yarn.lock index d618d5cf1..b5e20ccc7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1350,23 +1350,14 @@ __metadata: languageName: node linkType: hard -"@hyperlane-xyz/celo-ethers-provider@npm:^0.1.1": - version: 0.1.1 - resolution: "@hyperlane-xyz/celo-ethers-provider@npm:0.1.1" - peerDependencies: - ethers: ^5 - checksum: 5ea495505b3e4338ec6c419f69b66af2d35b86e7cdab9bc7ee65ba4a233729b2143b0a72cc637f8e8795ecacc18eeda5ac803e8b3de9a63e7ceb5dc14014b3d4 - languageName: node - linkType: hard - -"@hyperlane-xyz/core@npm:1.1.3": - version: 1.1.3 - resolution: "@hyperlane-xyz/core@npm:1.1.3" +"@hyperlane-xyz/core@npm:1.2.0": + version: 1.2.0 + resolution: "@hyperlane-xyz/core@npm:1.2.0" dependencies: - "@hyperlane-xyz/utils": 1.1.3 + "@hyperlane-xyz/utils": 1.2.0 "@openzeppelin/contracts": ^4.8.0 "@openzeppelin/contracts-upgradeable": ^4.8.0 - checksum: 6872fcdac9add5ac55aad891a7c9fbd7709e30ad06ca6d063bf8b4752533d143cd8418c78218df4073a98b06e8ec4fc8b185444ac62e558498da09ef47efbe19 + checksum: be76b1dd90f8bf8b9f2c53a60f7a56ed6eead6e9a1336879795677fddb75e6fd1d092e6c24af0a7e972b35cfff3eb9056229c5df7a852bfbff9e84e6a8fcb9bc languageName: node linkType: hard @@ -1374,7 +1365,7 @@ __metadata: version: 0.0.0-use.local resolution: "@hyperlane-xyz/helloworld@workspace:." dependencies: - "@hyperlane-xyz/sdk": ^1.1.3 + "@hyperlane-xyz/sdk": 1.2.0 "@nomiclabs/hardhat-ethers": ^2.2.1 "@nomiclabs/hardhat-waffle": ^2.0.3 "@openzeppelin/contracts-upgradeable": ^4.8.0 @@ -1402,28 +1393,27 @@ __metadata: languageName: unknown linkType: soft -"@hyperlane-xyz/sdk@npm:^1.1.3": - version: 1.1.3 - resolution: "@hyperlane-xyz/sdk@npm:1.1.3" +"@hyperlane-xyz/sdk@npm:1.2.0": + version: 1.2.0 + resolution: "@hyperlane-xyz/sdk@npm:1.2.0" dependencies: - "@hyperlane-xyz/celo-ethers-provider": ^0.1.1 - "@hyperlane-xyz/core": 1.1.3 - "@hyperlane-xyz/utils": 1.1.3 - "@wagmi/chains": ^0.1.3 + "@hyperlane-xyz/core": 1.2.0 + "@hyperlane-xyz/utils": 1.2.0 + "@wagmi/chains": ^0.2.6 coingecko-api: ^1.0.10 cross-fetch: ^3.1.5 debug: ^4.3.4 ethers: ^5.7.2 - checksum: 20dabd0acc33d737c80af432605608e6cea1aaf6fa6db9839687a5427324e0044dcdf29b0f26bc2ba732eb6faf44f3c1ca226a3387c9e608ab1f25c6ec24332d + checksum: 16d0eeb2f48c656106f4e2fa9101b1ae1382cb04c31571fcc41f167c84bc5d9343d769fd1ce9fd27e7e9b41bc60b3ab4a72742664f129947932e6ef147d6ce72 languageName: node linkType: hard -"@hyperlane-xyz/utils@npm:1.1.3": - version: 1.1.3 - resolution: "@hyperlane-xyz/utils@npm:1.1.3" +"@hyperlane-xyz/utils@npm:1.2.0": + version: 1.2.0 + resolution: "@hyperlane-xyz/utils@npm:1.2.0" dependencies: ethers: ^5.7.2 - checksum: afe6847b0810b85ba1ddbe5c0e28718d86e1890220edf7ab3b629e1a8820c93405ec7265da6ce1b16d32b31947f8b4b912b7756cfd4f14f674f4dc48c4042f09 + checksum: 320e59e36a9349a8fa57c3bbc85faadbe5b591cd345165e9571511a51a38bcb07dd85026fdaf997db7bcaf1eeae8cc1c12962cf3154c2efcb570cd7df5b9bb7c languageName: node linkType: hard @@ -2296,10 +2286,15 @@ __metadata: languageName: node linkType: hard -"@wagmi/chains@npm:^0.1.3": - version: 0.1.5 - resolution: "@wagmi/chains@npm:0.1.5" - checksum: 17577eaecb94450b9cbc9c16fa7c95416a79437cebbcd4cf16515098d9bb562d227c55922f5fddd493de4747f4131977c0eeb82197beafce700af42c16740ec1 +"@wagmi/chains@npm:^0.2.6": + version: 0.2.8 + resolution: "@wagmi/chains@npm:0.2.8" + peerDependencies: + typescript: ">=4.9.4" + peerDependenciesMeta: + typescript: + optional: true + checksum: f68b16fa0620fe4162ad3412735a5c239f59c9a7b15e900a217ff7403d74c8a262fdcd77ab0b37cbc747e78c2c197272d9340d9ef091525d5e335e91905d3def languageName: node linkType: hard