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

Feature/rooch pre mainnet #7

Merged
merged 4 commits into from
Oct 19, 2024
Merged
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 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ See [Rooch Network Doc](./docs/ROOCH.md) for more information on local developme
Contracts:

- **Testnet**: `0x9ce8eaf2166e9a6d4e8f1d27626297a0cf5ba1eaeb31137e08cc8f7773fb83f8`
- **Pre-mainnet**: `0x9ce8eaf2166e9a6d4e8f1d27626297a0cf5ba1eaeb31137e08cc8f7773fb83f8`

Oracles:

Expand Down
18 changes: 12 additions & 6 deletions orchestrator/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import { addressValidator, isRequiredWhenChainsInclude, privateKeyValidator } fr
const baseConfig = {
chains: (process.env.CHAINS ? process.env.CHAINS.split(",") : ChainList) as SupportedChain[],
// Rooch
roochChainId: process.env.ROOCH_CHAIN_ID,
roochChainId: (process.env.ROOCH_CHAIN_ID
? process.env.ROOCH_CHAIN_ID.split(",")
: ["testnet", "pre-mainnet"]) as RoochNetwork[],
roochPrivateKey: process.env.ROOCH_PRIVATE_KEY ?? "",
roochOracleAddress: process.env.ROOCH_ORACLE_ADDRESS ?? "",
roochIndexerCron: process.env.ROOCH_INDEXER_CRON,
Expand All @@ -27,7 +29,7 @@ const baseConfig = {

interface IEnvVars {
chains: SupportedChain[];
roochChainId: RoochNetwork;
roochChainId: RoochNetwork[];
roochOracleAddress: string;
roochPrivateKey: string;
roochIndexerCron: string;
Expand All @@ -52,10 +54,14 @@ const envVarsSchema = Joi.object({
.insensitive(),
)
.default(ChainList),
roochChainId: Joi.string()
.valid(...RoochNetworkList)
.insensitive()
.default(RoochNetworkList[0]),
roochChainId: Joi.array()
.items(
Joi.string()
.valid(...RoochNetworkList)
.insensitive()
.default(RoochNetworkList[0]),
)
.default([RoochNetworkList[0]]),
roochOracleAddress: isRequiredWhenChainsInclude(
Joi.string().custom((value, helper) => addressValidator(value, helper)),
SupportedChain.ROOCH,
Expand Down
23 changes: 13 additions & 10 deletions orchestrator/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,20 @@ import { log } from "./logger";
await xInstance.requestAccessToken();
}

if (env.rooch.privateKey && env.rooch.chainId && env.rooch.oracleAddress && env.chains.includes("ROOCH")) {
if (env.rooch.privateKey && env.rooch.chainId.length > 0 && env.rooch.oracleAddress && env.chains.includes("ROOCH")) {
// https://www.npmjs.com/package/cron#cronjob-class
const rooch = new RoochIndexer(env.rooch.privateKey, env.rooch.chainId, env.rooch.oracleAddress);
new CronJob(
env.rooch.indexerCron,
() => {
rooch.run();
},
null,
true,
);

env.rooch.chainId.map((chain) => {
const rooch = new RoochIndexer(env.rooch.privateKey, chain, env.rooch.oracleAddress);
new CronJob(
env.rooch.indexerCron,
() => {
rooch.run();
},
null,
true,
);
});
} else {
log.info(`Skipping Rooch Indexer initialization...`);
}
Expand Down
2 changes: 1 addition & 1 deletion orchestrator/src/indexer/aptos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default class AptosIndexer extends Indexer {
this.account = account;
this.lastTxVersion = 0;
log.info(`Aptos Indexer initialized`);
log.info(`Chain ID: ${this.chainId}`);
log.info(`Chain ID: ${this.getChainId()} \n\t\tOrchestrator Oracle Node Address: ${this.orchestrator}`);
}

getChainId(): string {
Expand Down
1 change: 0 additions & 1 deletion orchestrator/src/indexer/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export abstract class Indexer {
protected orchestrator: string,
) {
log.info(`Oracle Contract Address: ${this.oracleAddress}`);
log.info(`Orchestrator Oracle Node Address: ${this.orchestrator}`);
}

// Abstract: Implementation To fetch Data
Expand Down
17 changes: 13 additions & 4 deletions orchestrator/src/indexer/rooch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@ export default class RoochIndexer extends Indexer {
super(oracleAddress, Secp256k1Keypair.fromSecretKey(privateKey).getRoochAddress().toHexAddress());
this.keyPair = Secp256k1Keypair.fromSecretKey(this.privateKey);
log.info(`Rooch Indexer initialized`);
log.info(`Chain ID: ${this.chainId}`);
log.info(`Chain ID: ${this.getChainId()} \n\t\tOrchestrator Oracle Node Address: ${this.orchestrator}`);
}

getChainId(): string {
return `ROOCH-${this.chainId}`;
}

getRoochNodeUrl() {
return this.chainId === "pre-mainnet" ? "https://main-seed.rooch.network" : getRoochNodeUrl(this.chainId);
}

/**
* Fetches a list of RequestAdded events based on the provided cursor.
*
Expand All @@ -40,7 +44,7 @@ export default class RoochIndexer extends Indexer {
async fetchRequestAddedEvents(cursor: null | number | string = null): Promise<ProcessedRequestAdded<any>[]> {
try {
const response = await axios.post(
getRoochNodeUrl(this.chainId),
this.getRoochNodeUrl(),
{
id: 101,
jsonrpc: "2.0",
Expand Down Expand Up @@ -68,7 +72,12 @@ export default class RoochIndexer extends Indexer {
}

if (!newRequestsEvents.result?.data) {
log.debug("No new events found", newRequestsEvents);
log.debug("No new events found", newRequestsEvents, {
id: 101,
jsonrpc: "2.0",
method: "rooch_getEventsByEventHandle",
params: [`${this.oracleAddress}::oracles::RequestAdded`, cursor, `${env.batchSize}`, false, { decode: true }],
});
return [];
}

Expand Down Expand Up @@ -100,7 +109,7 @@ export default class RoochIndexer extends Indexer {
*/
async sendFulfillment(data: ProcessedRequestAdded<any>, status: number, result: string) {
const client = new RoochClient({
url: getRoochNodeUrl(this.chainId),
url: this.getRoochNodeUrl(),
});
log.debug({ notify: data.notify });

Expand Down
2 changes: 1 addition & 1 deletion orchestrator/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export type RoochEnv = {
};
export const ALLOWED_HOST = ["x.com", "api.x.com", "twitter.com", "api.twitter.com"];

export const RoochNetworkList = ["testnet", "devnet", "localnet"] as const;
export const RoochNetworkList = ["testnet", "devnet", "localnet", "pre-mainnet"] as const;

export const AptosNetworkList = ["testnet", "mainnet"] as const;

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"dependencies": {
"@aptos-labs/ts-sdk": "^1.29.1",
"@prisma/client": "5.19.1",
"@roochnetwork/rooch-sdk": "^0.2.3",
"@roochnetwork/rooch-sdk": "^0.2.7",
"@sentry/node": "^8.26.0",
"@sentry/profiling-node": "^8.26.0",
"axios": "^1.7.4",
Expand Down
Loading
Loading