Skip to content

Commit

Permalink
fix: sdk bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
jaybuidl committed Jun 1, 2023
1 parent 6642db9 commit 5b8c6f7
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 32 deletions.
28 changes: 19 additions & 9 deletions vea-sdk/examples/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,24 @@ import { Wallet } from "@ethersproject/wallet";
import VeaSdk from "../src/index";
import envVar from "../src/utils/envVar";

// Create the Vea client
const vea = VeaSdk.ClientFactory.arbitrumGoerliToChiadoDevnet(envVar("RPC_ARB_GOERLI"), envVar("RPC_CHIADO"));
async function main() {
// Create the Vea client
const vea = VeaSdk.ClientFactory.arbitrumGoerliToChiadoDevnet(envVar("RPC_ARB_GOERLI"), envVar("RPC_CHIADO"));

// Get the message info
const messageId = 42;
const messageInfo = await vea.getMessageInfo(messageId);
// Get the current state root
console.log(`stateRoot=${await vea.outbox.stateRoot()}`);

// Relay the message
const privateKey = envVar("PRIVATE_KEY");
const wallet = new Wallet(privateKey, vea.outboxProvider);
await vea.relay(messageInfo, wallet);
// Get a message info
const messageId = 1;
const messageInfo = await vea.getMessageInfo(messageId);

// Relay the message
const privateKey = envVar("PRIVATE_KEY");
const wallet = new Wallet(privateKey, vea.outboxProvider);
await vea.relay(messageInfo, wallet);
}

main().catch((e) => {
console.error(e);
process.exit(1);
});
2 changes: 1 addition & 1 deletion vea-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"tag": "latest"
},
"scripts": {
"start": "NODE_NO_WARNINGS=1 NODE_OPTIONS=--experimental-fetch ts-node ./src/run.ts",
"start": "NODE_NO_WARNINGS=1 NODE_OPTIONS=--experimental-fetch ts-node ./examples/index.ts",
"release:patch": "yarn version patch && yarn npm publish",
"release:minor": "yarn version minor && yarn npm publish",
"release:major": "yarn version major && yarn npm publish",
Expand Down
28 changes: 14 additions & 14 deletions vea-sdk/src/bridges.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import VeaInboxArbToGnosisDevnetDeployment from "@kleros/vea-contracts/deployments/arbitrumGoerli/VeaInboxArbToGnosisDevnet.json";
import VeaOutboxArbToGnosisDevnetDeployment from "@kleros/vea-contracts/deployments/chiado/VeaOutboxArbToGnosisDevnet.json";
import { address as veaInboxArbToGnosisDevnet } from "@kleros/vea-contracts/deployments/arbitrumGoerli/VeaInboxArbToGnosisDevnet.json";
import { address as veaOutboxArbToGnosisDevnet } from "@kleros/vea-contracts/deployments/chiado/VeaOutboxArbToGnosisDevnet.json";

import VeaInboxArbToEthDevnetDeployment from "@kleros/vea-contracts/deployments/arbitrumGoerli/VeaInboxArbToEthDevnet.json";
import VeaOutboxArbToEthDevnetDeployment from "@kleros/vea-contracts/deployments/goerli/VeaOutboxArbToEthDevnet.json";
import { address as veaInboxArbToEthDevnet } from "@kleros/vea-contracts/deployments/arbitrumGoerli/VeaInboxArbToEthDevnet.json";
import { address as veaOutboxArbToEthDevnet } from "@kleros/vea-contracts/deployments/goerli/VeaOutboxArbToEthDevnet.json";

import {
VeaInboxArbToEth__factory,
VeaOutboxArbToGnosisDevnet__factory,
VeaOutboxArbToEthDevnet__factory,
} from "@kleros/vea-contracts/typechain-types";

export type VeaInboxFactory = typeof VeaInboxArbToEth__factory;
export type VeaOutboxFactory = typeof VeaOutboxArbToGnosisDevnet__factory | typeof VeaOutboxArbToEthDevnet__factory;
export type VeaInboxFactory = VeaInboxArbToEth__factory;
export type VeaOutboxFactory = VeaOutboxArbToGnosisDevnet__factory | VeaOutboxArbToEthDevnet__factory;

export type Bridge = {
label: string;
Expand All @@ -33,10 +33,10 @@ export const arbitrumGoerliToChiadoDevnet: Bridge = {
label: "Arbitrum to Chiado Devnet",
inboxChainId: 421613,
outboxChainId: 10200,
inboxAddress: VeaInboxArbToGnosisDevnetDeployment.address as `0x${string}`,
outboxAddress: VeaOutboxArbToGnosisDevnetDeployment.address as `0x${string}`,
inboxFactory: VeaInboxArbToEth__factory,
outboxFactory: VeaOutboxArbToGnosisDevnet__factory,
inboxAddress: veaInboxArbToGnosisDevnet as `0x${string}`,
outboxAddress: veaOutboxArbToGnosisDevnet as `0x${string}`,
inboxFactory: new VeaInboxArbToEth__factory(),
outboxFactory: new VeaOutboxArbToGnosisDevnet__factory(),
inboxSubgraph: getSubgraphUrl("vea-inbox-arbgoerli-to-chiado"),
outboxSubgraph: getSubgraphUrl("FIX ME"), // TODO
};
Expand All @@ -45,10 +45,10 @@ export const arbitrumGoerliToGoerliDevnet: Bridge = {
label: "Arbitrum to Goerli Devnet",
inboxChainId: 5,
outboxChainId: 10200,
inboxAddress: VeaInboxArbToEthDevnetDeployment.address as `0x${string}`,
outboxAddress: VeaOutboxArbToEthDevnetDeployment.address as `0x${string}`,
inboxFactory: VeaInboxArbToEth__factory,
outboxFactory: VeaOutboxArbToEthDevnet__factory,
inboxAddress: veaInboxArbToEthDevnet as `0x${string}`,
outboxAddress: veaOutboxArbToEthDevnet as `0x${string}`,
inboxFactory: new VeaInboxArbToEth__factory(),
outboxFactory: new VeaOutboxArbToEthDevnet__factory(),
inboxSubgraph: getSubgraphUrl("vea-inbox-arbgoerli-to-goerli"),
outboxSubgraph: getSubgraphUrl("FIXME"), // TODO,
};
10 changes: 5 additions & 5 deletions vea-sdk/src/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const getMessageInfo = async (client: VeaClient, messageId: number): Prom
};

const getCount = async (client: VeaClient): Promise<number> => {
const subgraph = client.config.bridge.outboxSubgraph;
const subgraph = client.config.bridge.inboxSubgraph;
const stateRoot = await client.outbox.stateRoot();
const query = `{
snapshotSaveds(first: 1, where: { stateRoot: "${stateRoot}" }) {
Expand All @@ -58,7 +58,7 @@ const getProofAtCount = async (client: VeaClient, messageId: number, count: numb

const proof: any[] = [];
try {
const subgraph = client.config.bridge.outboxSubgraph;
const subgraph = client.config.bridge.inboxSubgraph;
const result: any = await request(subgraph, query);
for (let i = 0; i < proofIndices.length; i++) {
proof.push(result[`layer${i}`][0].hash);
Expand Down Expand Up @@ -90,10 +90,10 @@ const getProofIndices = (messageId: number, count: number) => {
const getMessageDataToRelay = async (client: VeaClient, messageId: number): Promise<[string, string]> => {
let dataAndTo: [string, string] = ["", ""];
try {
const subgraph = client.config.bridge.outboxSubgraph;
const subgraph = client.config.bridge.inboxSubgraph;
const query = `{
messageSents(first: 5, where: {messageId: ${messageId}}) {
messageId
messageSents(first: 5, where: {nonce: ${messageId}}) {
nonce
to {
id
}
Expand Down
14 changes: 11 additions & 3 deletions vea-sdk/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,17 @@ export class ClientFactory {
};
const inboxProvider = new JsonRpcProvider(inboxRpc);
const outboxProvider = new JsonRpcProvider(outboxRpc);
const veaInbox = bridge.inboxFactory.connect(bridge.inboxAddress, inboxProvider);
const veaOutbox = bridge.outboxFactory.connect(bridge.outboxAddress, outboxProvider);
// TODO: Check if the RPCs chainIds match the bridge chainIds
const veaInbox = Object.getPrototypeOf(bridge.inboxFactory).constructor.connect(bridge.inboxAddress, inboxProvider);
const veaOutbox = Object.getPrototypeOf(bridge.outboxFactory).constructor.connect(
bridge.outboxAddress,
outboxProvider
);
inboxProvider.getNetwork().then((network) => {
if (network.chainId !== bridge.inboxChainId) throw new Error("Incorrect Inbox RPC");
});
outboxProvider.getNetwork().then((network) => {
if (network.chainId !== bridge.outboxChainId) throw new Error("Incorrect Outbox RPC");
});
return new VeaClient(config, inboxProvider, outboxProvider, veaInbox, veaOutbox);
}

Expand Down

0 comments on commit 5b8c6f7

Please sign in to comment.