Skip to main content

Module: cubist

This module exports a simple interface for working with Cubist projects and their smart contracts:

It also re-exports several references and type definitions (e.g., BigNumber).

All these definitions are exposed at the top-level, so you can simply import them as:

import { Cubist, } from '@cubist-labs/cubist'

// ...
async function main() {
const cubist = new Cubist(); // create new project
await cubist.getContractFactory('MyContract').deploy()
// ...
}
note

We classify exports into two categories: core and internal. As a user, you should not really need to use or think abot internals; we only include them in the documentation because you might encounter them reading our code.

Exports

References

Core

Internal

References

AvalancheConfig

Re-exports AvalancheConfig


CommonConfig

Re-exports CommonConfig


Compiler

Re-exports Compiler


Config

Re-exports Config


ContractName

Re-exports ContractName


ContractsConfig

Re-exports ContractsConfig


EndpointConfig

Re-exports EndpointConfig


EthereumConfig

Re-exports EthereumConfig


NetworkProfile

Re-exports NetworkProfile


NetworkProfileName

Re-exports NetworkProfileName


PathBuf

Re-exports PathBuf


PolygonConfig

Re-exports PolygonConfig


ProjType

Re-exports ProjType


ProxyConfig

Re-exports ProxyConfig


SubnetInfo

Re-exports SubnetInfo


Target

Re-exports Target


TargetConfig

Re-exports TargetConfig

Core

BigNumber

Re-exports BigNumber


Contract<T>: Object

Multi-chain contract abstraction. Each Cubist contract encapsulates (for now) an ethers.js Contract) that runs on a native target chain and zero or more shim contracts running on other chains.

A contract deployed with ContractFactory is deployed to the chain specified in the cubist-config.json configuration file; this is the native target chain. If this contract is called on another chain, we also deploy a shim for this contract on that chain (either automatically when you use deploy or manually when you use deployShims).

This class exposes the contract on the native target chains (via inner), and several methods for getting the contract target chain, its address on the native target chain, and its shims' addresses on other chains.

Example

ERC20 bridged from Avalanche to Polygon and Ethereum has a native contract on Avalanche and corresponding shims on the other two chains.

// ...
const cubist = new Cubist();
// get contract
const e20Bridged = cubist.getContract('ERC20Bridged');
// print its address on native chain
console.log(`address on ${e20Bridged.target()}: ${e20Bridged.address()}`);
// print its shims' addresses
console.log(`address on Polygon: ${e20Bridged.addressOn(Target.Polygon)}`);
console.log(`address on Ethereum: ${e20Bridged.addressOn(Target.Ethereum)}`);

Type parameters

NameType
Textends Contract

Defined in

submodules/cubist-node-sdk/src/cubist.ts:595

ContractFactory<T>: Object

Contract factories are used to create Contracts that span multiple chains. Specifically, with a factory you can use:

  • deploy to deploy a Contract to its native target chain and automatically deploy its shims to the chains where this contract gets called.
  • deployShims to deploy only the shims of the contract on all the chains the contract is called.
  • deployWithShims to deploy the contract to its native target chain (given its already deployed shims). Together, deployShims and deployWithShims, make it possible to deploy shims before the native contract.
  • attach to attach to an already deployed contract. This is the same as getContract. We expose attach because the well-typed Cubist interface we generate at build time (with cubist build)---CubistORM---exports the project factories as properties on the object, eliding the need to use getContractFactory and getContract.

Example

Get factory and deploy contract and its shims with Cubist.

const StorageReceiver = cubist.getContractFactory('StorageReceiver');
const receiver = await StorageReceiver.deploy(33);

Example

Get factory and attach to existing deployed contract.

import { CubistORM, } from '../build/orm/index.js';
// ...
const StorageReceiver = cubist.StorageReceiver;
const receiver = StorageReceiver.attach();

Type parameters

NameType
Textends Contract

Defined in

submodules/cubist-node-sdk/src/cubist.ts:394

Cubist: Object

This class is the way to work with interface with your cubist projects. This class abstracts over all contracts and contract factories.

Example

Create a new project to access contracts and their factories:

const cubist = new Cubist();
// get contract factory
const Receiver = cubist.getContractFactory('Receiver');
// deploy Receiver, ...

// get already deployed Sender contract
const senderInstance = cubist.getContract('Sender');

// wait for bridge to spin up
assert(await cubist.whenBridged());

Beyond exposing project contracts (via getContract) and contract factories (via getContractFactory), projects can wait for bridges (between contracts and cross-chain shims they call) to start up with whenBridged.

At build time, cubist build generates a CubistORM class that extends Cubist with the project-specific factories (see Overview). This means, in practice, you don't even need to use getContract and getContractFactory.

Example

Create a new project to access contracts and their factories with CubistORM:

import { CubistORM, } from '../build/orm/index.js';

const cubist = new CubistORM();
// get contract factory
const Receiver = cubist.Receiver;
// deploy Receiver, ...

// get already deployed Sender contract
const senderInstance = cubist.Sender.attach();

// wait for bridge to spin up
assert(await cubist.whenBridged());

Defined in

submodules/cubist-node-sdk/src/cubist.ts:170

AccountAddress

Ƭ AccountAddress: AccountAddress

Account address (string)

Defined in

submodules/cubist-node-sdk/src/cubist.ts:63


ContractAddress

Ƭ ContractAddress: ContractAddress

Contract address (string).

Defined in

submodules/cubist-node-sdk/src/cubist.ts:57


EthersContract

Ƭ EthersContract: Contract

Alias to ether.js' Contract.

Defined in

submodules/cubist-node-sdk/src/cubist.ts:76

Internal

solidity

Re-exports solidity


internal: Object

Defined in

submodules/cubist-node-sdk/src/internal/index.ts:12

ContractFQN: Object

Fully qualified contracts name.

Defined in

submodules/cubist-node-sdk/src/cubist.ts:84