The home for Hyperlane core contracts, sdk packages, and other infrastructure
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
hyperlane-monorepo/typescript/optics-provider
Asa Oines 7f86a76597
Rename staging, prod to testnet, mainnet, remove community suffix and add legacy suffix (#69)
3 years ago
..
src Rename staging, prod to testnet, mainnet, remove community suffix and add legacy suffix (#69) 3 years ago
.eslintignore refactor: Annotated is now a proper class (#860) 3 years ago
.eslintrc.json refactor: Annotated is now a proper class (#860) 3 years ago
.gitignore feat/refactor: Multi-Provider improvements (#842) 3 years ago
.npmignore refactor: remove all relative imports in TS (#797) 3 years ago
.prettierrc a multi-provider and tool for interacting with deployed contracts (#763) 3 years ago
README.md feature: build typechain before publication (#794) 3 years ago
package-lock.json Rename staging, prod to testnet, mainnet, remove community suffix and add legacy suffix (#69) 3 years ago
package.json Rename staging, prod to testnet, mainnet, remove community suffix and add legacy suffix (#69) 3 years ago
tsconfig.json Update optics-provider with governance capabilities (#21) 3 years ago

README.md

Optics Provider

Optics Provider is a management system for ethers.js providers and signers that helps developers connect to multiple networks simultaneously. It is part of the Optics project, but may be useful to other multi-chain systems.

This package includes the MultiProvider, as well as an OpticsContext for interacting with deployed Optics systems. The dev, staging, and mainnet Optics systems have pre-built objects for quick development.

Intended Usage

import * as ethers from 'ethers';

import { mainnet } from 'optics-provider';

// Set up providers and signers
const someEthersProvider = ethers.providers.WsProvider('...');
const someEthersSigner = new AnySigner(...);
mainnet.registerProvider('ethereum', someEthersProvider);
mainnet.registerSigner('ethereum', someEthersSigner);

// We have shortcuts for common provider/signer types
mainnet.registerRpcProvider('celo', 'https://forno.celo.org');
mainnet.registerWalletSigner('celo', '0xabcd...');

// Interact with the Optics Bridge
// Send ETH from ethereum to celo
await mainnet.sendNative(
    'ethereum', // source
    'celo',  // destination
    ethers.constants.WeiPerEther, // amount
    '0x1234...',  // recipient
);

// Send Tokens from celo to ethereum
await mainnet.send(
    'celo',  // source
    'ethereum', // destination
    { domain: 'ethereum', id: "0xabcd..."} // token information
    ethers.constants.WeiPerEther, // amount
    '0x1234...'  // recipient
    { gasLimit: 300_000 } // standard ethers tx overrides
);

// so easy.