Sync with monorepo for v0.4.0 release (#24)

pull/2435/head
J M Rossy 2 years ago committed by GitHub
parent c2ffdff14b
commit 83af39875d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      package.json
  2. 66
      src/app/app.ts
  3. 11
      src/app/environments/test.json
  4. 4
      src/deploy/check.ts
  5. 32
      src/deploy/config.ts
  6. 4
      src/deploy/deploy.ts
  7. 37
      src/scripts/check.ts
  8. 28
      src/scripts/deploy.ts
  9. 12
      src/test/deploy.test.ts
  10. 10
      src/test/helloworld.test.ts
  11. 55
      yarn.lock

@ -1,9 +1,10 @@
{
"name": "@abacus-network/helloworld",
"description": "A basic skeleton of an Abacus app",
"version": "0.3.1",
"version": "0.5.0",
"dependencies": {
"@abacus-network/sdk": "^0.3.1",
"@abacus-network/sdk": "^0.4.0",
"@abacus-network/utils": "^0.4.0",
"@openzeppelin/contracts-upgradeable": "^4.6.0",
"ethers": "^5.6.8"
},

@ -1,49 +1,70 @@
import { ethers } from 'ethers';
import { BigNumber, ethers } from 'ethers';
import { TypedListener } from '@abacus-network/core/dist/common';
import {
AbacusApp,
AbacusCore,
ChainMap,
ChainName,
ChainNameToDomainId,
MultiProvider,
Remotes,
} from '@abacus-network/sdk';
import { ReceivedHelloWorldEvent } from '../types/contracts/HelloWorld';
import { HelloWorldContracts } from './contracts';
type Counts = {
sent: number;
received: number;
};
export class HelloWorldApp<
Chain extends ChainName = ChainName,
> extends AbacusApp<HelloWorldContracts, Chain> {
constructor(
public readonly core: AbacusCore<Chain>,
contractsMap: ChainMap<Chain, HelloWorldContracts>,
multiProvider: MultiProvider<Chain>,
) {
super(contractsMap, multiProvider);
}
async sendHelloWorld<From extends Chain>(
from: From,
to: Remotes<Chain, From>,
message: string,
receiveHandler?: TypedListener<ReceivedHelloWorldEvent>,
value: BigNumber,
): Promise<ethers.ContractReceipt> {
const sender = this.getContracts(from).router;
const toDomain = ChainNameToDomainId[to];
const chainConnection = this.multiProvider.getChainConnection(from);
const tx = await sender.sendHelloWorld(
// apply gas buffer due to https://github.com/abacus-network/abacus-monorepo/issues/634
const estimated = await sender.estimateGas.sendHelloWorld(
toDomain,
message,
chainConnection.overrides,
{ ...chainConnection.overrides, value },
);
const receipt = await tx.wait(chainConnection.confirmations);
const gasLimit = estimated.mul(12).div(10);
if (receiveHandler) {
const recipient = this.getContracts(to).router;
const filter = recipient.filters.ReceivedHelloWorld(
ChainNameToDomainId[from],
ChainNameToDomainId[to],
);
recipient.once(filter, receiveHandler);
const tx = await sender.sendHelloWorld(toDomain, message, {
...chainConnection.overrides,
gasLimit,
value,
});
console.log(tx);
return tx.wait(chainConnection.confirmations);
}
return receipt;
async waitForMessageReceipt(
receipt: ethers.ContractReceipt,
): Promise<ethers.ContractReceipt[]> {
return this.core.waitForMessageProcessing(receipt);
}
async channelStats<From extends Chain>(from: From, to: Remotes<Chain, From>) {
async channelStats<From extends Chain>(
from: From,
to: Remotes<Chain, From>,
): Promise<Counts> {
const sent = await this.getContracts(from).router.sentTo(
ChainNameToDomainId[to],
);
@ -54,8 +75,8 @@ export class HelloWorldApp<
return { sent: sent.toNumber(), received: received.toNumber() };
}
async stats() {
const entries = await Promise.all(
async stats(): Promise<Record<Chain, Record<Chain, Counts>>> {
const entries: Array<[Chain, Record<Chain, Counts>]> = await Promise.all(
this.chains().map(async (source) => {
const destinationEntries = await Promise.all(
this.remoteChains(source).map(async (destination) => [
@ -63,9 +84,12 @@ export class HelloWorldApp<
await this.channelStats(source, destination),
]),
);
return [source, Object.fromEntries(destinationEntries)];
return [
source,
Object.fromEntries(destinationEntries) as Record<Chain, Counts>,
];
}),
);
return Object.fromEntries(entries);
return Object.fromEntries(entries) as Record<Chain, Record<Chain, Counts>>;
}
}

@ -1,11 +0,0 @@
{
"test1": {
"router": "0x5FbDB2315678afecb367f032d93F642f64180aa3"
},
"test2": {
"router": "0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0"
},
"test3": {
"router": "0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9"
}
}

@ -9,7 +9,7 @@ export class HelloWorldChecker<
Chain extends ChainName,
> extends AbacusRouterChecker<
Chain,
HelloWorldContracts,
HelloWorldApp<Chain>,
HelloWorldConfig
HelloWorldConfig,
HelloWorldContracts
> {}

@ -1,32 +1,8 @@
import {
ChainMap,
RouterConfig,
TestChainNames,
chainConnectionConfigs,
} from '@abacus-network/sdk';
import { RouterConfig, chainConnectionConfigs } from '@abacus-network/sdk';
export type HelloWorldConfig = RouterConfig;
// TODO reduce this config boilerplate
export const testConfigs = {
test1: chainConnectionConfigs.test1,
test2: chainConnectionConfigs.test2,
test3: chainConnectionConfigs.test3,
};
export function getConfigMap(
signerAddress: string,
): ChainMap<TestChainNames, { owner: string }> {
return {
test1: {
owner: signerAddress,
},
test2: {
owner: signerAddress,
},
test3: {
owner: signerAddress,
},
// SET DESIRED NETWORKS HERE
export const prodConfigs = {
alfajores: chainConnectionConfigs.alfajores,
};
}

@ -18,9 +18,9 @@ export class HelloWorldDeployer<
Chain extends ChainName,
> extends AbacusRouterDeployer<
Chain,
HelloWorldConfig,
HelloWorldContracts,
HelloWorldFactories,
HelloWorldConfig
HelloWorldFactories
> {
constructor(
multiProvider: MultiProvider<Chain>,

@ -1,38 +1,45 @@
import { ethers } from 'hardhat';
import {
AbacusCore,
ChainMap,
ChainName,
MultiProvider,
buildContracts,
getMultiProviderFromConfigAndSigner,
getChainToOwnerMap,
objMap,
} from '@abacus-network/sdk';
import { HelloWorldApp } from '../app/app';
import { HelloWorldContracts, helloWorldFactories } from '../app/contracts';
import testEnvironmentAddresses from '../app/environments/test.json';
import { HelloWorldChecker } from '../deploy/check';
import { getConfigMap, testConfigs } from '../deploy/config';
import { prodConfigs } from '../deploy/config';
// COPY FROM OUTPUT OF DEPLOYMENT SCRIPT OR IMPORT FROM ELSEWHERE
const deploymentAddresses = {};
// SET CONTRACT OWNER ADDRESS HERE
const ownerAddress = '0x123...';
async function check() {
const [signer] = await ethers.getSigners();
const multiProvider = getMultiProviderFromConfigAndSigner(
testConfigs,
signer,
);
console.info('Preparing utilities');
const chainProviders = objMap(prodConfigs, (_, config) => ({
provider: config.provider,
confirmations: config.confirmations,
overrides: config.overrides,
}));
const multiProvider = new MultiProvider(chainProviders);
const contractsMap = buildContracts(
testEnvironmentAddresses,
deploymentAddresses,
helloWorldFactories,
) as ChainMap<ChainName, HelloWorldContracts>;
const app = new HelloWorldApp(contractsMap, multiProvider);
const core = AbacusCore.fromEnvironment('test', multiProvider);
const core = AbacusCore.fromEnvironment('testnet2', multiProvider);
const app = new HelloWorldApp(core, contractsMap, multiProvider);
const config = core.extendWithConnectionClientConfig(
getConfigMap(signer.address),
getChainToOwnerMap(prodConfigs, ownerAddress),
);
console.info('Starting check');
const helloWorldChecker = new HelloWorldChecker(multiProvider, app, config);
await helloWorldChecker.check();
helloWorldChecker.expectEmpty();

@ -1,25 +1,31 @@
import '@nomiclabs/hardhat-ethers';
import { ethers } from 'hardhat';
import { Wallet } from 'ethers';
import {
AbacusCore,
getMultiProviderFromConfigAndSigner,
MultiProvider,
getChainToOwnerMap,
objMap,
serializeContracts,
} from '@abacus-network/sdk';
import { getConfigMap, testConfigs } from '../deploy/config';
import { prodConfigs } from '../deploy/config';
import { HelloWorldDeployer } from '../deploy/deploy';
async function main() {
const [signer] = await ethers.getSigners();
const multiProvider = getMultiProviderFromConfigAndSigner(
testConfigs,
signer,
);
console.info('Getting signer');
const signer = new Wallet('SET KEY HERE OR CREATE YOUR OWN SIGNER');
console.info('Preparing utilities');
const chainProviders = objMap(prodConfigs, (_, config) => ({
provider: config.provider,
confirmations: config.confirmations,
overrides: config.overrides,
}));
const multiProvider = new MultiProvider(chainProviders);
const core = AbacusCore.fromEnvironment('test', multiProvider);
const core = AbacusCore.fromEnvironment('testnet2', multiProvider);
const config = core.extendWithConnectionClientConfig(
getConfigMap(signer.address),
getChainToOwnerMap(prodConfigs, signer.address),
);
const deployer = new HelloWorldDeployer(multiProvider, config, core);

@ -7,13 +7,15 @@ import {
TestChainNames,
TestCoreApp,
TestCoreDeployer,
getMultiProviderFromConfigAndSigner,
getChainToOwnerMap,
getTestMultiProvider,
testChainConnectionConfigs,
} from '@abacus-network/sdk';
import { HelloWorldApp } from '../app/app';
import { HelloWorldContracts } from '../app/contracts';
import { HelloWorldChecker } from '../deploy/check';
import { HelloWorldConfig, getConfigMap, testConfigs } from '../deploy/config';
import { HelloWorldConfig } from '../deploy/config';
import { HelloWorldDeployer } from '../deploy/deploy';
describe('deploy', async () => {
@ -26,13 +28,13 @@ describe('deploy', async () => {
before(async () => {
const [signer] = await ethers.getSigners();
multiProvider = getMultiProviderFromConfigAndSigner(testConfigs, signer);
multiProvider = getTestMultiProvider(signer);
const coreDeployer = new TestCoreDeployer(multiProvider);
const coreContractsMaps = await coreDeployer.deploy();
core = new TestCoreApp(coreContractsMaps, multiProvider);
config = core.extendWithConnectionClientConfig(
getConfigMap(signer.address),
getChainToOwnerMap(testChainConnectionConfigs, signer.address),
);
deployer = new HelloWorldDeployer(multiProvider, config, core);
});
@ -43,7 +45,7 @@ describe('deploy', async () => {
it('builds app', async () => {
contracts = await deployer.deploy();
app = new HelloWorldApp(contracts, multiProvider);
app = new HelloWorldApp(core, contracts, multiProvider);
});
it('checks', async () => {

@ -9,10 +9,12 @@ import {
TestChainNames,
TestCoreApp,
TestCoreDeployer,
getMultiProviderFromConfigAndSigner,
getChainToOwnerMap,
getTestMultiProvider,
testChainConnectionConfigs,
} from '@abacus-network/sdk';
import { HelloWorldConfig, getConfigMap, testConfigs } from '../deploy/config';
import { HelloWorldConfig } from '../deploy/config';
import { HelloWorldDeployer } from '../deploy/deploy';
import { HelloWorld } from '../types';
@ -32,13 +34,13 @@ describe('HelloWorld', async () => {
before(async () => {
[signer] = await ethers.getSigners();
multiProvider = getMultiProviderFromConfigAndSigner(testConfigs, signer);
multiProvider = getTestMultiProvider(signer);
const coreDeployer = new TestCoreDeployer(multiProvider);
const coreContractsMaps = await coreDeployer.deploy();
coreApp = new TestCoreApp(coreContractsMaps, multiProvider);
config = coreApp.extendWithConnectionClientConfig(
getConfigMap(signer.address),
getChainToOwnerMap(testChainConnectionConfigs, signer.address),
);
});

@ -5,14 +5,14 @@ __metadata:
version: 6
cacheKey: 8
"@abacus-network/app@npm:0.3.1":
version: 0.3.1
resolution: "@abacus-network/app@npm:0.3.1"
"@abacus-network/app@npm:0.4.0":
version: 0.4.0
resolution: "@abacus-network/app@npm:0.4.0"
dependencies:
"@abacus-network/core": 0.3.1
"@abacus-network/utils": 0.3.1
"@abacus-network/core": 0.4.0
"@abacus-network/utils": 0.4.0
"@openzeppelin/contracts-upgradeable": ^4.5.0
checksum: 9cfc42d4f496792b02c5d95e4f55fe161e0e4c539f0e28a8822b05ddc33ab24635d026b874fcf2a3bafc21db64254bb96c5369487c3c85f9bde37a4e98ac1eb0
checksum: 943e86f932b14e9273de14844f7ab80995098a502fe4eb5b4546966a0a28aa377f092e1d33e96718ba8f1379d9052ff7cedf63baef4a1384f8af14e785979fc4
languageName: node
linkType: hard
@ -25,15 +25,15 @@ __metadata:
languageName: node
linkType: hard
"@abacus-network/core@npm:0.3.1":
version: 0.3.1
resolution: "@abacus-network/core@npm:0.3.1"
"@abacus-network/core@npm:0.4.0":
version: 0.4.0
resolution: "@abacus-network/core@npm:0.4.0"
dependencies:
"@abacus-network/utils": 0.3.1
"@abacus-network/utils": 0.4.0
"@openzeppelin/contracts": ^4.6.0
"@openzeppelin/contracts-upgradeable": ^4.6.0
"@summa-tx/memview-sol": ^2.0.0
checksum: 0e3ec428059d8488be742e27e32cfcbe983704dd32c359ad4389c686adb13506043f067c2e38dafdc2703d9d7c224a9d05b4b148a939a059f672e3960cda5dd0
checksum: 8094df2b9fdbd0e865d9cd3a6d3b65f79dad9ee0edda7e7336d594c1ff5633dc0e1b0e9c6bcdd3f3a5b174e5c8b5d5315733d7a00ef58143786e80588d50f110
languageName: node
linkType: hard
@ -41,7 +41,8 @@ __metadata:
version: 0.0.0-use.local
resolution: "@abacus-network/helloworld@workspace:."
dependencies:
"@abacus-network/sdk": ^0.3.1
"@abacus-network/sdk": ^0.4.0
"@abacus-network/utils": ^0.4.0
"@nomiclabs/hardhat-ethers": ^2.0.5
"@nomiclabs/hardhat-waffle": ^2.0.2
"@openzeppelin/contracts-upgradeable": ^4.6.0
@ -69,28 +70,29 @@ __metadata:
languageName: unknown
linkType: soft
"@abacus-network/sdk@npm:^0.3.1":
version: 0.3.1
resolution: "@abacus-network/sdk@npm:0.3.1"
"@abacus-network/sdk@npm:^0.4.0":
version: 0.4.0
resolution: "@abacus-network/sdk@npm:0.4.0"
dependencies:
"@abacus-network/app": 0.3.1
"@abacus-network/app": 0.4.0
"@abacus-network/celo-ethers-provider": ^0.1.0
"@abacus-network/core": 0.3.1
"@abacus-network/utils": 0.3.1
"@abacus-network/core": 0.4.0
"@abacus-network/utils": 0.4.0
"@types/debug": ^4.1.7
coingecko-api: ^1.0.10
cross-fetch: ^3.1.5
debug: ^4.3.4
ethers: ^5.6.8
checksum: 53081f88aa9f8cf8750d5a4135d01b618505843681ac199387a98d0794904cc9ef23dbcb2a63db92ff31f6e1f1a34c5b52612c914cc618617285d0a73383b077
checksum: ddf7ec4f5a6f3949d01d512e3eb85303302179cc44b4765d6e0c0869696ecab5a5e0b8f6a6192e78d4eabe0cf81f7bdac7076a034ae2d3db2bd95dbb7df704cd
languageName: node
linkType: hard
"@abacus-network/utils@npm:0.3.1":
version: 0.3.1
resolution: "@abacus-network/utils@npm:0.3.1"
"@abacus-network/utils@npm:0.4.0, @abacus-network/utils@npm:^0.4.0":
version: 0.4.0
resolution: "@abacus-network/utils@npm:0.4.0"
dependencies:
ethers: ^5.6.8
checksum: b0871b3c28f523348e1c12a1dd5c3a4c037cb671d767010e71ebdd46d7e8af918c8bae80875662720b0f8973ca71af53df1178f31e6a9b390a14c3bcd16577c7
checksum: 1234fcc302a82f7ff7419eca2c0f257748b91689c484057f945856780691219a1c219041cfbbf57d5dff6fcc9de92999c1f685c10538c538e123ccf246f2a938
languageName: node
linkType: hard
@ -3976,6 +3978,13 @@ __metadata:
languageName: node
linkType: hard
"coingecko-api@npm:^1.0.10":
version: 1.0.10
resolution: "coingecko-api@npm:1.0.10"
checksum: c900f5f7261dbfa2ecf3f6a2b018eb9de445db17bf9ef331e2751904f24c4e361144e9aa8ab1501fb4e741fa900dd61007e330a6b95a778d35b48d2ca5b61148
languageName: node
linkType: hard
"collection-visit@npm:^1.0.0":
version: 1.0.0
resolution: "collection-visit@npm:1.0.0"

Loading…
Cancel
Save