Update for compat with SDK 1.2.0 (#44)

pull/2435/head
J M Rossy 2 years ago committed by GitHub
parent 264839c0bf
commit 75d40a83fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      package.json
  2. 54
      src/app/app.ts
  3. 9
      src/deploy/check.ts
  4. 4
      src/deploy/config.ts
  5. 13
      src/deploy/deploy.ts
  6. 12
      src/scripts/check.ts
  7. 8
      src/scripts/deploy.ts
  8. 19
      src/test/deploy.test.ts
  9. 27
      src/test/helloworld.test.ts
  10. 57
      yarn.lock

@ -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"
},

@ -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<HelloWorldContracts, Chain> {
export class HelloWorldApp extends HyperlaneApp<HelloWorldContracts> {
constructor(
public readonly core: HyperlaneCore<Chain>,
contractsMap: ChainMap<Chain, HelloWorldContracts>,
multiProvider: MultiProvider<Chain>,
public readonly core: HyperlaneCore,
contractsMap: ChainMap<HelloWorldContracts>,
multiProvider: MultiProvider,
) {
super(contractsMap, multiProvider);
}
async sendHelloWorld<From extends Chain>(
from: From,
to: Remotes<Chain, From>,
async sendHelloWorld(
from: ChainName,
to: ChainName,
message: string,
value: BigNumber,
): Promise<ethers.ContractReceipt> {
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<To extends Chain>(
from: Exclude<Chain, To>,
to: To,
): Promise<BigNumber> {
async quoteGasPayment(from: ChainName, to: ChainName): Promise<BigNumber> {
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 extends Chain>(
from: From,
to: Remotes<Chain, From>,
): Promise<Counts> {
async channelStats(from: ChainName, to: ChainName): Promise<Counts> {
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<Record<Chain, Record<Chain, Counts>>> {
const entries: Array<[Chain, Record<Chain, Counts>]> = await Promise.all(
async stats(): Promise<ChainMap<ChainMap<Counts>>> {
const entries: Array<[ChainName, ChainMap<Counts>]> = 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<Chain, Counts>,
];
return [source, Object.fromEntries(destinationEntries)];
}),
);
return Object.fromEntries(entries) as Record<Chain, Record<Chain, Counts>>;
return Object.fromEntries(entries);
}
}

@ -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<Chain>,
export class HelloWorldChecker extends HyperlaneRouterChecker<
HelloWorldApp,
HelloWorldConfig,
HelloWorldContracts
> {}

@ -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,
};

@ -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<Chain>,
configMap: ChainMap<Chain, HelloWorldConfig>,
protected core: HyperlaneCore<Chain>,
multiProvider: MultiProvider,
configMap: ChainMap<HelloWorldConfig>,
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,

@ -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<ChainName, HelloWorldContracts>;
) as ChainMap<HelloWorldContracts>;
const core = HyperlaneCore.fromEnvironment('testnet', multiProvider);
const app = new HelloWorldApp(core, contractsMap, multiProvider);

@ -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(

@ -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<TestChainNames>;
let multiProvider: MultiProvider;
let core: TestCoreApp;
let config: ChainMap<TestChainNames, HelloWorldConfig>;
let deployer: HelloWorldDeployer<TestChainNames>;
let contracts: Record<TestChainNames, HelloWorldContracts>;
let app: HelloWorldApp<TestChainNames>;
let config: ChainMap<HelloWorldConfig>;
let deployer: HelloWorldDeployer;
let contracts: ChainMap<HelloWorldContracts>;
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);
});

@ -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<TestChainNames>;
let multiProvider: MultiProvider;
let coreApp: TestCoreApp;
let config: ChainMap<TestChainNames, HelloWorldConfig>;
let config: ChainMap<HelloWorldConfig>;
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

@ -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

Loading…
Cancel
Save