Skip to content

Commit

Permalink
final polish
Browse files Browse the repository at this point in the history
refactor: make event queries rely on ethers type system

refactor: generic Annotated type

refactor: improve event cache in Optics message

refactor: non-looping array concat

refactor: use Annotated events for message instantiation

refactor: add concurrency limit to paginated event retrieval

refactor: break up annotate and rely on event.getTransactionReceipt

refactor: use annotated lifecycle events throughout

refactor: break out events into a folder

bug: check for id, not domain

bug: check for id, not domain (again)

bug: check for id, not domain (again)

Revert "bug: check for id, not domain (again)"

This reverts commit 8304985.

bug: pass through signer in fromObject

bug: improper fromObject checking re: domain

refactor: break trace out into its own package

remove .env
  • Loading branch information
anna-carroll authored and prestwich committed Sep 29, 2021
1 parent 370d519 commit 35cd8f9
Show file tree
Hide file tree
Showing 26 changed files with 623 additions and 304 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ node_modules
test_deploy.env

typescript/optics-deploy/.env
**/.env


rust/vendor/
rust/tmp_db
Expand Down
1 change: 1 addition & 0 deletions tools/contract-metrics/tsconfig.tsbuildinfo

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions typescript/optics-provider/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.env
dist
tsconfig.tsbuildinfo
38 changes: 37 additions & 1 deletion typescript/optics-provider/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions typescript/optics-provider/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@
"types": "dist/index.d.ts",
"scripts": {
"build": "tsc",
"check": "tsc --noEmit"
"check": "tsc --noEmit",
"prettier": "prettier --write ./src"
},
"prepublish": "tsc",
"author": "Celo Labs Inc.",
"license": "MIT OR Apache-2.0",
"devDependencies": {
"@types/node": "^16.9.1",
"dotenv": "^10.0.0",
"fs": "0.0.1-security"
"fs": "0.0.1-security",
"tsc": "^2.0.3",
"typescript": "^4.4.3"
},
"dependencies": {
"@optics-xyz/ts-interface": "^1.0.9",
Expand Down
8 changes: 7 additions & 1 deletion typescript/optics-provider/src/domains.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
export interface Pagination {
blocks: number;
from: number;
}

export interface Domain {
domain: number;
id: number;
name: string;
paginate?: Pagination;
}
11 changes: 10 additions & 1 deletion typescript/optics-provider/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
export { MultiProvider } from './provider';
export { mainnet, dev, staging, OpticsContext } from './optics';
export {
mainnet,
dev,
staging,
OpticsContext,
OpticsStatus,
OpticsMessage,
OpticsLifecyleEvent,
Annotated,
} from './optics';

// intended usage
// import {mainnet} from 'optics-provider';
Expand Down
8 changes: 4 additions & 4 deletions typescript/optics-provider/src/optics/OpticsContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ export class OpticsContext extends MultiProvider {
}

mustGetReplicaFor(
home: string | number,
remote: string | number,
home: string | number,
remote: string | number,
): core.Replica {
const replica = this.getReplicaFor(home, remote);
if (!replica) {
Expand Down Expand Up @@ -229,7 +229,7 @@ export class OpticsContext extends MultiProvider {
);
const receipt = await tx.wait();

const message = TransferMessage.fromReceipt(receipt, this);
const message = TransferMessage.singleFromReceipt(this, from, receipt);
if (!message) {
throw new Error();
}
Expand All @@ -256,7 +256,7 @@ export class OpticsContext extends MultiProvider {
const tx = await ethHelper.sendToEVMLike(toDomain, recipient, overrides);
const receipt = await tx.wait();

const message = TransferMessage.fromReceipt(receipt, this);
const message = TransferMessage.singleFromReceipt(this, from, receipt);
if (!message) {
throw new Error();
}
Expand Down
16 changes: 4 additions & 12 deletions typescript/optics-provider/src/optics/contracts/BridgeContracts.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import fs from 'fs';
import { ethers } from 'ethers';
import { xapps } from '@optics-xyz/ts-interface';
import { Contracts } from '../../contracts';
Expand Down Expand Up @@ -32,22 +31,15 @@ export class BridgeContracts extends Contracts {
}

static fromObject(data: any, signer?: ethers.Signer) {
if (!data.domain || !data.bridgeRouter) {
throw new Error('missing address');
if (!data.id || !data.bridgeRouter) {
throw new Error('missing address or domain');
}

const domain = data.domain;
const id = data.id;
const br = data.bridgeRouter.proxy ?? data.bridgeRouter;
const eh = data.ethHelper;

return new BridgeContracts(domain, br, eh);
}

static loadJson(filepath: string, signer?: ethers.Signer) {
return this.fromObject(
JSON.parse(fs.readFileSync(filepath, 'utf8')),
signer,
);
return new BridgeContracts(id, br, eh, signer);
}

toObject(): any {
Expand Down
13 changes: 2 additions & 11 deletions typescript/optics-provider/src/optics/contracts/CoreContracts.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import fs from 'fs';

import { ethers } from 'ethers';
import { core } from '@optics-xyz/ts-interface';
import { Contracts } from '../../contracts';
Expand Down Expand Up @@ -61,16 +59,9 @@ export class CoreContracts extends Contracts {
}

static fromObject(data: any, signer?: ethers.Signer): CoreContracts {
if (!data.domain || !data.home || !data.replicas) {
if (!data.id || !data.home || !data.replicas) {
throw new Error('Missing key');
}
return new CoreContracts(data.domain, data.home, data.replicas, signer);
}

static loadJson(filepath: string, signer?: ethers.Signer) {
return this.fromObject(
JSON.parse(fs.readFileSync(filepath, 'utf8')),
signer,
);
return new CoreContracts(data.id, data.home, data.replicas, signer);
}
}
6 changes: 3 additions & 3 deletions typescript/optics-provider/src/optics/domains/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { OpticsDomain } from './domain';

export const alfajores: OpticsDomain = {
name: 'alfajores',
domain: 1000,
id: 1000,
bridgeRouter: '0xdaa6e362f9BE0CDaCe107b298639034b8dEC617a',
home: '0x47AaF05B1C36015eC186892C43ba4BaF91246aaA',
replicas: [
Expand All @@ -16,7 +16,7 @@ export const alfajores: OpticsDomain = {

export const kovan: OpticsDomain = {
name: 'kovan',
domain: 3000,
id: 3000,
bridgeRouter: '0x383Eb849c707fE38f3DfBF45679C0c6f21Ba82fF',
ethHelper: '0x6D84B823D7FB68E4d6f7Cc334fDd393f6C3a6980',
home: '0x5B55C29A10aEe6D5750F128C6a8f490de763ccc7',
Expand All @@ -31,7 +31,7 @@ export const kovan: OpticsDomain = {

export const rinkeby: OpticsDomain = {
name: 'rinkeby',
domain: 2000,
id: 2000,
bridgeRouter: '0xE9fB0b6351Dec7d346282b8274653D36b8199AAF',
ethHelper: '0x7a539d7B7f4Acab1d7ce8b3681c3e286511ee444',
home: '0x6E6010E6bd43a9d2F7AE3b7eA9f61760e58758f3',
Expand Down
10 changes: 7 additions & 3 deletions typescript/optics-provider/src/optics/domains/mainnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { OpticsDomain } from './domain';

export const ethereum: OpticsDomain = {
name: 'ethereum',
domain: 6648936,
id: 6648936,
bridgeRouter: '0x6a39909e805A3eaDd2b61fFf61147796ca6aBB47',
ethHelper: '0xf1c1413096ff2278C3Df198a28F8D54e0369cF3A',
home: '0xf25C5932bb6EFc7afA4895D9916F2abD7151BF97',
Expand All @@ -20,7 +20,11 @@ export const ethereum: OpticsDomain = {

export const polygon: OpticsDomain = {
name: 'polygon',
domain: 1886350457,
id: 1886350457,
paginate: {
blocks: 1999,
from: 18895794,
},
bridgeRouter: '0xf244eA81F715F343040569398A4E7978De656bf6',
ethHelper: '0xc494bFEE14b5E1E118F93CfedF831f40dFA720fA',
home: '0x97bbda9A1D45D86631b243521380Bc070D6A4cBD',
Expand All @@ -35,7 +39,7 @@ export const polygon: OpticsDomain = {

export const celo: OpticsDomain = {
name: 'celo',
domain: 1667591279,
id: 1667591279,
bridgeRouter: '0xf244eA81F715F343040569398A4E7978De656bf6',
home: '0x97bbda9A1D45D86631b243521380Bc070D6A4cBD',
replicas: [
Expand Down
6 changes: 3 additions & 3 deletions typescript/optics-provider/src/optics/domains/staging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { OpticsDomain } from './domain';

export const alfajores: OpticsDomain = {
name: 'alfajores',
domain: 1000,
id: 1000,
bridgeRouter: '0xd6930Ee55C141E5Bb4079d5963cF64320956bb3E',
home: '0x47AaF05B1C36015eC186892C43ba4BaF91246aaA',
replicas: [
Expand All @@ -16,7 +16,7 @@ export const alfajores: OpticsDomain = {

export const kovan: OpticsDomain = {
name: 'kovan',
domain: 3000,
id: 3000,
bridgeRouter: '0x359089D34687bDbFD019fCC5093fFC21bE9905f5',
ethHelper: '0x411ABcFD947212a0D64b97C9882556367b61704a',
home: '0x5B55C29A10aEe6D5750F128C6a8f490de763ccc7',
Expand All @@ -31,7 +31,7 @@ export const kovan: OpticsDomain = {

export const rinkeby: OpticsDomain = {
name: 'rinkeby',
domain: 2000,
id: 2000,
bridgeRouter: '0x8FbEA25D0bFDbff68F2B920df180e9498E9c856A',
ethHelper: '0x1BEBC8F1260d16EE5d1CFEE9366bB474bD13DC5f',
home: '0x6E6010E6bd43a9d2F7AE3b7eA9f61760e58758f3',
Expand Down
Loading

0 comments on commit 35cd8f9

Please sign in to comment.