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

Added command to deploy subgraph #178

Merged
merged 23 commits into from
Oct 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
1e8197f
Added command to deploy subgraph
Oct 10, 2019
6443cd8
Removed assertion of subgraph deployment as mosaic start no more depl…
Oct 11, 2019
5125207
Fixed smoke test and refactor code to plug token config
Oct 11, 2019
ddc6548
Merge remote-tracking branch 'upstream/develop' into add_subgraph_com…
Oct 11, 2019
b0181cc
Merge remote-tracking branch 'upstream/pr/177' into add_subgraph_command
Oct 15, 2019
3f8384b
Added gateway addresses file.
Oct 15, 2019
04db517
Added support of gateway config
Oct 15, 2019
65c0854
Merge remote-tracking branch 'upstream/develop' into add_subgraph_com…
Oct 15, 2019
57ac493
Updated name of subgraph
Oct 15, 2019
61ac82e
Revert "Updated name of subgraph"
Oct 15, 2019
12ad125
Added dev chain subgraph deployment in smoke test
Oct 15, 2019
ba8992d
Corrected data type of aux chain in subgraph command
Oct 15, 2019
dfbf7f8
Update docker image version
Oct 15, 2019
9bf7362
smoke test for subgraph deployment with gateway config
Oct 15, 2019
16eb761
Merge remote-tracking branch 'upstream/develop' into add_subgraph_com…
Oct 16, 2019
cc36441
Dynamic name of subgraph
Oct 16, 2019
e2dd7e6
Added variable in smoke test
Oct 16, 2019
7656d1a
Using variables in smoke test
Oct 16, 2019
4324640
PR feedback refacotring, typos and imporved documentation
Oct 16, 2019
7dabbe6
Corrected smoke tests
Oct 16, 2019
bd02cc9
Merge remote-tracking branch 'upstream/develop' into add_subgraph_com…
Oct 16, 2019
f9830c5
Added log for file path
Oct 17, 2019
e0bb4a8
Converted gateway address to lower case
Oct 17, 2019
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
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,35 @@ Where:

*Refer integration test of mosaic-create command to understand end to end flow.*

## Subgraph deployment
Subgraph command can be used to deploy mosaic subgraph. Subgraph by [thegraph](https://thegraph.com) protocol is used to index transactions and events by mosaic smart contract.

#### Prerequisite: Below commands assumes the blockchain node and graph node is already running. You can use `mosaic start` command to start a node and graph node.

##### Subgraph deployment for mosaic gateways:
Below command deploys subgraph of mosaic gateways.

```bash
./mosaic subgraph <origin-chain-identifier> <auxiliary-chain-identifier> <chainType> <admin-graph-rpc> <graph-ipfs>
```
**where:**
1. origin-chain-identifier: Origin chain identifier like ropsten, goerli, dev-origin
2. auxiliary-chain-identifier: Auxiliary chain ID like 1405, 1406, 1407 or 1000(dev-auxiliary).
3. chainType: Either`origin` or `auxiliary` chain.
4. admin-graph-rpc: RPC endpoint of graph node.
5. graph-ipfs: IPFS endpoint used by graph node.

Optionally `--mosaic-config` option can be used to pass mosaic config otherwise command will search on default path.

#### Subgraph deployment for any EIP20 gateways:
Below command deploys subgraph of any eip20gateway.
```bash
./mosaic subgraph <origin-chain-identifier> <auxiliary-chain-identifier> <chain> <admin-graph-rpc> <graph-ipfs> --gateway-config <gateway-config>
```
**where:**
1. gateway-config: Path of gateway config.

Optionally `gateway-address` option can be passed which will search gateway config on default path.
## Chain Verifier

Chain verifier makes sure that newly created chain is being setup correctly.
Expand Down
94 changes: 94 additions & 0 deletions src/Config/GatewayAddresses.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import MosaicConfig from './MosaicConfig';
import GatewayConfig from './GatewayConfig';

/**
* This class represents set of addresses specific to a gateway pair.
*/
export default class GatewayAddresses {
public readonly stakePoolAddress: string;

public readonly eip20GatewayAddress: string;

public readonly anchorAddress: string;

public readonly coAnchorAddress: string;

public readonly eip20CoGatewayAddress: string;

public readonly redeemPoolAddress: string;

/**
* Constructor
* @param stakePoolAddress StakePool address.
* @param eip20GatewayAddress eip20Gateway address.
* @param anchorAddress anchor address.
* @param coAnchorAddress coanchor address.
* @param eip20CoGatewayAddress cogateway address.
* @param redeemPoolAddress redeem pool address.
*/
private constructor(
stakePoolAddress: string,
eip20GatewayAddress: string,
anchorAddress: string,
coAnchorAddress: string,
eip20CoGatewayAddress: string,
redeemPoolAddress: string,
) {
this.stakePoolAddress = stakePoolAddress;
this.eip20GatewayAddress = eip20GatewayAddress;
this.anchorAddress = anchorAddress;
this.coAnchorAddress = coAnchorAddress;
this.eip20CoGatewayAddress = eip20CoGatewayAddress;
this.redeemPoolAddress = redeemPoolAddress;
}

abhayks1 marked this conversation as resolved.
Show resolved Hide resolved
/**
* Create Gateway address instance based on mosaic config.
* @param mosaicConfig Mosaic config object.
* @param auxiliaryChain aux chain identifier.
*/
public static fromMosaicConfig(
mosaicConfig: MosaicConfig,
auxiliaryChain: string,
abhayks1 marked this conversation as resolved.
Show resolved Hide resolved
): GatewayAddresses {
const auxiliaryContractAddresses = mosaicConfig.auxiliaryChains[auxiliaryChain]
.contractAddresses.auxiliary;
const originContractAddresses = mosaicConfig.auxiliaryChains[auxiliaryChain]
.contractAddresses.origin;
return new GatewayAddresses(
mosaicConfig.originChain.contractAddresses.stakePoolAddress,
originContractAddresses.eip20GatewayAddress,
originContractAddresses.anchorAddress,
auxiliaryContractAddresses.anchorAddress,
auxiliaryContractAddresses.eip20CoGatewayAddress,
auxiliaryContractAddresses.redeemPoolAddress,
);
}

/**
* Creates gateway address instance from gateway config.
* @param gatewayConfig GatewayConfig instance.
*/
public static fromGatewayConfig(
gatewayConfig: GatewayConfig,
): GatewayAddresses {
const { auxChainId } = gatewayConfig;
const stakePoolAddress = gatewayConfig.originContracts.stakePoolAddress
|| gatewayConfig.mosaicConfig.originChain.contractAddresses.stakePoolAddress;

const auxiliaryChain = gatewayConfig.mosaicConfig.auxiliaryChains[auxChainId];
const auxiliaryContracts = auxiliaryChain.contractAddresses.auxiliary;
const redeemPool = gatewayConfig.auxiliaryContracts.redeemPoolAddress
|| auxiliaryContracts.redeemPoolAddress;

const originContracts = auxiliaryChain.contractAddresses.origin;
return new GatewayAddresses(
stakePoolAddress,
gatewayConfig.originContracts.eip20GatewayAddress,
originContracts.anchorAddress,
auxiliaryContracts.anchorAddress,
gatewayConfig.auxiliaryContracts.eip20CoGatewayAddress,
redeemPool,
);
}
}
2 changes: 2 additions & 0 deletions src/Config/GatewayConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
} from '../Exception';
import FileSystem from '../FileSystem ';
import Directory from '../Directory';
import Logger from "../Logger";

/* eslint-disable @typescript-eslint/no-var-requires */
const schema = require('./GatewayConfig.schema.json');
Expand Down Expand Up @@ -95,6 +96,7 @@ export default class GatewayConfig {
public static fromChain(originChain: string, auxChainId: number, gatewayAddress: string):
GatewayConfig {
const filePath = Directory.getGatewayConfigPath(originChain, auxChainId, gatewayAddress);
Logger.info(`filepath for gateway config ${filePath}`);
if (GatewayConfig.exists(filePath)) {
const configObject = GatewayConfig.readConfigFromFile(filePath);
return new GatewayConfig(configObject);
Expand Down
9 changes: 3 additions & 6 deletions src/Directory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,15 @@ export default class Directory {
*
* @param originChain
* @param auxiliaryChain
* @param chainClient
* @return
*/
public static getOriginSubGraphProjectDirSuffix(
originChain: string,
auxiliaryChain: string,
chainClient: string
): string {
return path.join(
originChain,
`origin-${chainClient}`,
'subgraph',
'origin-subgraph',
auxiliaryChain,
);
}
Expand Down Expand Up @@ -175,12 +172,12 @@ export default class Directory {
* @return Path of gateway config file.
*/
public static getGatewayConfigPath(originChain: string, auxChainId: number, gatewayAddress: string):
string {
string {
return path.join(
Directory.getDefaultMosaicDataDir,
originChain,
auxChainId.toString(),
gatewayAddress.toLowerCase()+'.json',
`${gatewayAddress.toLowerCase()}.json`,
);
}
}
Loading