Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempt to bring changes to optics-multiprovider #1053

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,753 changes: 1,297 additions & 456 deletions typescript/optics-provider/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion typescript/optics-provider/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export { MultiProvider } from './provider';
export {
mainnet,
mainnetCommunity,
dev,
devCommunity,
staging,
stagingCommunity,
OpticsContext,
Expand Down
4 changes: 2 additions & 2 deletions typescript/optics-provider/src/optics/OpticsContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { CoreContracts } from './contracts/CoreContracts';
import { ResolvedTokenInfo, TokenIdentifier } from './tokens';
import { canonizeId, evmId } from '../utils';
import {
devDomains,
devCommunityDomains,
mainnetDomains,
mainnetCommunityDomains,
OpticsDomain,
Expand Down Expand Up @@ -473,6 +473,6 @@ export class OpticsContext extends MultiProvider {

export const mainnet = OpticsContext.fromDomains(mainnetDomains);
export const mainnetCommunity = OpticsContext.fromDomains(mainnetCommunityDomains);
export const dev = OpticsContext.fromDomains(devDomains);
export const devCommunity = OpticsContext.fromDomains(devCommunityDomains);
export const staging = OpticsContext.fromDomains(stagingDomains);
export const stagingCommunity = OpticsContext.fromDomains(stagingCommunityDomains);
47 changes: 0 additions & 47 deletions typescript/optics-provider/src/optics/domains/dev.ts

This file was deleted.

72 changes: 72 additions & 0 deletions typescript/optics-provider/src/optics/domains/devCommunity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { OpticsDomain } from './domain';

export const alfajores: OpticsDomain = {
name: 'alfajores',
id: 1000,
bridgeRouter: '0x684C74fBA4dF7F7A542709C5f9688AB806C7B828',
home: '0xeA057840858645bb68134a913A252a44a0C58652',
replicas: [
{ domain: 5, address: '0x3354D5956612C38D0dD831dcdf83CF30BC674231' },
{ domain: 3000, address: '0x6AdB8ba7C826d70506D26eDdc74236fB88Fa647F' },
{ domain: 43113, address: '0x570EDeF0c271E3f1ba6B5C66D040195750a79762' },
{ domain: 80001, address: '0xbA00eF80A55d4EefcF3d7971270D2c233F9d315e' },
],
};

export const kovan: OpticsDomain = {
name: 'kovan',
id: 3000,
bridgeRouter: '0x53d09A4B49443F7f7C66321C306601dC9d483D4F',
ethHelper: '0xFE7c9Cc7116429Ae50823a218315C7E01EC7A761',
home: '0xc53F82FAF17B4c521A85C514791593847Bdf1655',
replicas: [
{ domain: 5, address: '0xc501ad2163Ebd9921B4a6E46B344Ef7bA76A2cBa' },
{ domain: 1000, address: '0xEdDA4762fe6388C69d37b8Ee15B1deC10cA3B964' },
{ domain: 43113, address: '0xf3855B99b7cEfa56C66f0C2d0550b545df11d54A' },
{ domain: 80001, address: '0xeAc82476aF67dca63B04a66EA8D7230EfB4028DB' },
],
};

export const gorli: OpticsDomain = {
name: 'gorli',
id: 5,
bridgeRouter: '0x53d09A4B49443F7f7C66321C306601dC9d483D4F',
ethHelper: '0xFE7c9Cc7116429Ae50823a218315C7E01EC7A761',
home: '0xc53F82FAF17B4c521A85C514791593847Bdf1655',
replicas: [
{ domain: 1000, address: '0xEdDA4762fe6388C69d37b8Ee15B1deC10cA3B964' },
{ domain: 3000, address: '0xc501ad2163Ebd9921B4a6E46B344Ef7bA76A2cBa' },
{ domain: 43113, address: '0xf3855B99b7cEfa56C66f0C2d0550b545df11d54A' },
{ domain: 80001, address: '0xeAc82476aF67dca63B04a66EA8D7230EfB4028DB' },
],
};

export const fuji: OpticsDomain = {
name: 'fuji',
id: 43113,
bridgeRouter: '0xFE7c9Cc7116429Ae50823a218315C7E01EC7A761',
ethHelper: '0x7B99a9cf26c9813b16E3DDb3D6E593c3624c9EBA',
home: '0xc53F82FAF17B4c521A85C514791593847Bdf1655',
replicas: [
{ domain: 5, address: '0xf3855B99b7cEfa56C66f0C2d0550b545df11d54A' },
{ domain: 1000, address: '0xEdDA4762fe6388C69d37b8Ee15B1deC10cA3B964' },
{ domain: 3000, address: '0xc501ad2163Ebd9921B4a6E46B344Ef7bA76A2cBa' },
{ domain: 80001, address: '0xeAc82476aF67dca63B04a66EA8D7230EfB4028DB' },
],
};

export const mumbai: OpticsDomain = {
name: 'mumbai',
id: 80001,
bridgeRouter: '0xFE7c9Cc7116429Ae50823a218315C7E01EC7A761',
ethHelper: '0x7B99a9cf26c9813b16E3DDb3D6E593c3624c9EBA',
home: '0xc53F82FAF17B4c521A85C514791593847Bdf1655',
replicas: [
{ domain: 5, address: '0xf3855B99b7cEfa56C66f0C2d0550b545df11d54A' },
{ domain: 1000, address: '0xEdDA4762fe6388C69d37b8Ee15B1deC10cA3B964' },
{ domain: 3000, address: '0xc501ad2163Ebd9921B4a6E46B344Ef7bA76A2cBa' },
{ domain: 43113, address: '0xeAc82476aF67dca63B04a66EA8D7230EfB4028DB' },
],
};

export const devCommunityDomains = [alfajores, kovan, gorli, fuji, mumbai];
2 changes: 1 addition & 1 deletion typescript/optics-provider/src/optics/domains/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export type { OpticsDomain, ReplicaInfo } from './domain';
export { mainnetDomains } from './mainnet';
export { mainnetCommunityDomains } from './mainnetCommunity';
export { devDomains } from './dev';
export { devCommunityDomains } from './devCommunity';
export { stagingDomains } from './staging';
export { stagingCommunityDomains } from './stagingCommunity';
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@ export const alfajores: OpticsDomain = {
home: '0xDf89d5d4039ada018BCDb992Bb6C2e05fEf86328',
replicas: [
{
domain: 2000, // ropsten
domain: 3, // ropsten
address: '0xC9e581Cd4fF6533f5ccBA4Dc5d5f642B8b658B93'
},
{
domain: 3000, // kovan
address: '0x15fA9169F7495162ac52b4A7957c9054097Ab0FF',
},
{
domain: 4000, // gorli
domain: 5, // gorli
address: '0x4eAD31e37b950B32b9EBbE747f0ef4BffAc336a5',
},
],
};

export const ropsten: OpticsDomain = {
name: 'ropsten',
id: 2000,
id: 3,
bridgeRouter: '0xe29Abbc3669064d8aF9F6BE378179a133664a92C',
ethHelper: '0x9A0e88a3D8CF09F3dc5Ba65640299DE3D87f926C',
home: '0x7E26E170dB94E81979927d2D39CB703048Ad599D',
Expand All @@ -37,7 +37,7 @@ export const ropsten: OpticsDomain = {
address: '0xF782C67AA111a9D75f6ccEf3d7aDB54620D5A8e9',
},
{
domain: 4000, // gorli
domain: 5, // gorli
address: '0x15C1edbf6E6161d50d58682dF7587F0d61db5C38',
},
],
Expand All @@ -55,19 +55,19 @@ export const kovan: OpticsDomain = {
address: '0x30dAE25E9eBd644841d1A1fF25e303331B1CdEb3'
},
{
domain: 2000, // ropsten
domain: 3, // ropsten
address: '0x15C1edbf6E6161d50d58682dF7587F0d61db5C38',
},
{
domain: 4000, // gorli
domain: 5, // gorli
address: '0xF782C67AA111a9D75f6ccEf3d7aDB54620D5A8e9',
},
],
};

export const gorli: OpticsDomain = {
name: 'gorli',
id: 4000,
id: 5,
bridgeRouter: '0xe29Abbc3669064d8aF9F6BE378179a133664a92C',
ethHelper: '0x9A0e88a3D8CF09F3dc5Ba65640299DE3D87f926C',
home: '0xDf89d5d4039ada018BCDb992Bb6C2e05fEf86328',
Expand All @@ -77,7 +77,7 @@ export const gorli: OpticsDomain = {
address: '0x15fA9169F7495162ac52b4A7957c9054097Ab0FF'
},
{
domain: 2000, // ropsten
domain: 3, // ropsten
address: '0xC9e581Cd4fF6533f5ccBA4Dc5d5f642B8b658B93',
},
{
Expand Down
80 changes: 80 additions & 0 deletions typescript/optics-provider/src/optics/events/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,23 @@ export async function queryAnnotatedEvents<T extends Result, U>(
return Annotated.fromEvents(context.resolveDomain(nameOrDomain), events);
}

export async function findAnnotatedSingleEvent<T extends Result, U>(
context: OpticsContext,
nameOrDomain: string | number,
contract: TSContract<T, U>,
filter: TypedEventFilter<T, U>,
startBlock?: number,
): Promise<Array<Annotated<T, TypedEvent<T & U>>>> {
const events = await findEvent(
context,
nameOrDomain,
contract,
filter,
startBlock,
);
return Annotated.fromEvents(context.resolveDomain(nameOrDomain), events);
}

export async function getEvents<T extends Result, U>(
context: OpticsContext,
nameOrDomain: string | number,
Expand All @@ -57,6 +74,26 @@ export async function getEvents<T extends Result, U>(
return contract.queryFilter(filter, startBlock, endBlock);
}

export async function findEvent<T extends Result, U>(
context: OpticsContext,
nameOrDomain: string | number,
contract: TSContract<T, U>,
filter: TypedEventFilter<T, U>,
startBlock?: number,
): Promise<Array<TypedEvent<T & U>>> {
const domain = context.mustGetDomain(nameOrDomain);
if (domain.paginate) {
return findFromPaginatedEvents(
context,
domain,
contract,
filter,
startBlock,
);
}
return contract.queryFilter(filter, startBlock);
}

async function getPaginatedEvents<T extends Result, U>(
context: OpticsContext,
domain: Domain,
Expand Down Expand Up @@ -102,3 +139,46 @@ async function getPaginatedEvents<T extends Result, U>(
}
return events;
}

async function findFromPaginatedEvents<T extends Result, U>(
context: OpticsContext,
domain: Domain,
contract: TSContract<T, U>,
filter: TypedEventFilter<T, U>,
startBlock?: number,
endBlock?: number,
): Promise<Array<TypedEvent<T & U>>> {
if (!domain.paginate) {
throw new Error('Domain need not be paginated');
}
// get the first block by params
// or domain deployment block
const firstBlock = startBlock
? Math.max(startBlock, domain.paginate.from)
: domain.paginate.from;
// get the last block by params
// or current block number
let lastBlock;
if (!endBlock) {
const provider = context.mustGetProvider(domain.id);
lastBlock = await provider.getBlockNumber();
} else {
lastBlock = endBlock;
}
// query domain pagination limit at a time, concurrently
// eslint-disable-next-line for-direction
for (
let end = lastBlock;
end > firstBlock;
end -= domain.paginate.blocks
) {

const nextEnd = end - domain.paginate.blocks;
const from = Math.max(nextEnd, firstBlock);
const queriedEvents = await contract.queryFilter(filter, from, end);
if (queriedEvents.length > 0) {
return queriedEvents;
}
}
return [];
}
2 changes: 1 addition & 1 deletion typescript/optics-provider/src/optics/events/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ export type {
AnnotatedTokenDeployed,
} from './bridgeEvents';

export { queryAnnotatedEvents } from './fetch';
export { queryAnnotatedEvents, findAnnotatedSingleEvent } from './fetch';
36 changes: 36 additions & 0 deletions typescript/optics-provider/src/optics/examples/proveMessage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { config } from "dotenv";
import fetch from "cross-fetch";
import { stagingCommunity } from '..';

config();

const privkey = process.env.PRIVKEY_LMAO;
if (!privkey) {
throw new Error('set PRIVKEY_LMAO');
}

const rpc = process.env.KOVAN_RPC;
stagingCommunity.registerRpcProvider('kovan', rpc!);
stagingCommunity.registerWalletSigner('kovan', privkey);

async function doThing() {
const address = await stagingCommunity.getAddress('kovan');
if (!address) {
throw new Error('no address');
}

const replica = await stagingCommunity.mustGetReplicaFor('alfajores', 'kovan');
const S3_BUCKET_URL = 'https://optics-staging-community.s3.us-west-2.amazonaws.com/';
const response = await fetch(`${S3_BUCKET_URL}alfajores_36`);

const s3Data = await response.json();

const processTx = await replica.callStatic.proveAndProcess(s3Data.message, s3Data.proof.path, s3Data.proof.index);

console.log(processTx);

// await processTx.wait(1);
// console.log(processTx.hash);
}

doThing();
6 changes: 3 additions & 3 deletions typescript/optics-provider/src/optics/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ export type { ResolvedTokenInfo, TokenIdentifier } from './tokens';
export { tokens, testnetTokens } from './tokens';

export type { OpticsDomain } from './domains';
export { mainnetDomains, mainnetCommunityDomains, devDomains, stagingDomains, stagingCommunityDomains } from './domains';
export { mainnetDomains, mainnetCommunityDomains, devCommunityDomains, stagingDomains, stagingCommunityDomains } from './domains';

export type { AnnotatedLifecycleEvent, OpticsLifecyleEvent } from './events';
export { queryAnnotatedEvents, Annotated } from './events';
export { queryAnnotatedEvents, findAnnotatedSingleEvent, Annotated } from './events';

export { OpticsContext, mainnet, mainnetCommunity, dev, staging, stagingCommunity } from './OpticsContext';
export { OpticsContext, mainnet, mainnetCommunity, devCommunity, staging, stagingCommunity } from './OpticsContext';
Loading
Loading