Skip to content

Commit

Permalink
Merge pull request #24 from XP-NETWORK/test
Browse files Browse the repository at this point in the history
Test
  • Loading branch information
D4mph1r authored Dec 7, 2024
2 parents 5e76c2c + 165f8ed commit 1fceef6
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 15 deletions.
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"@dfinity/ledger-icp": "^2.4.0",
"@dfinity/principal": "^2.0.0",
"@dfinity/utils": "^2.4.0",
"@ethersproject/providers": "^5.7.0",
"@make-software/ces-js-parser": "^1.3.3",
"@mikro-orm/core": "^6.1.4",
"@mikro-orm/migrations": "^6.1.4",
Expand All @@ -55,11 +56,13 @@
"@ton/core": "^0.54.0",
"@ton/crypto": "^3.2.0",
"@ton/ton": "^13.9.0",
"@vechain/connex-driver": "^2.0.8",
"@vechain/connex-framework": "^2.0.8",
"@xp/cosmos-client": "git+https://github.com/XP-NETWORK/cosmos-client#bleeding-edge",
"async-mutex": "^0.5.0",
"axios": "^1.6.7",
"casper-cep78-js-client": "^1.5.1",
"casper-js-sdk": "=2.15.2",
"casper-js-sdk": "=2.15.2",
"chalk": "4",
"dotenv": "^16.4.5",
"elysia": "^1.0.25",
Expand All @@ -80,6 +83,7 @@
"tonweb": "^0.0.62",
"tslog": "^4.9.3",
"web3-eth-accounts": "^4.1.1",
"web3-providers-connex": "^0.3.1",
"xp-decentralized-sdk": "git+https://github.com/XP-NETWORK/xp-decentralized-client-library#bleeding-edge",
"zod": "^3.22.4"
}
Expand Down
11 changes: 11 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,17 @@ export const bridgeTestChains = [
nativeCoinSymbol: "CSPR",
rpcURL: "https://rpc.testnet.casperlabs.io",
},
{
chain: "VECHAIN",
rpcURL: "https://sync-testnet.veblocks.net",
nativeCoinSymbol: "ETH",
intialFund: "50000000000000000",
contractAddress: "0x7111eb5f8d9dA472e9608f2ab3De275C040D60B2",
chainType: "evm",
lastBlock: 20343220,
decimals: 18,
blockChunks: 1000,
},
] as const satisfies TChain[];

export const storageTestnetConfig: IEvmChainConfig = {
Expand Down
6 changes: 4 additions & 2 deletions src/handler/chains/evm/config-hedera.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { EntityManager } from "@mikro-orm/sqlite";
import { Mutex } from "async-mutex";
import type { AxiosInstance } from "axios";
import { JsonRpcProvider, Wallet } from "ethers";
import { type BrowserProvider, JsonRpcProvider, Wallet } from "ethers";
import { privateKeyToAccount } from "web3-eth-accounts";
import type { TSupportedChainTypes, TSupportedChains } from "../../../config";
import type { BridgeStorage, ERC20Staking } from "../../../contractsTypes/evm";
Expand All @@ -27,7 +27,9 @@ export async function configHederaHandler(
});
const mutex = new Mutex();
const provider = new JsonRpcProvider(conf.rpcURL);
const fetchProvider = async (): Promise<[JsonRpcProvider, MutexReleaser]> => {
const fetchProvider = async (): Promise<
[JsonRpcProvider | BrowserProvider, MutexReleaser]
> => {
const release = await mutex.acquire();
return [provider, release];
};
Expand Down
23 changes: 20 additions & 3 deletions src/handler/chains/evm/config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import type { EntityManager } from "@mikro-orm/sqlite";
import { Driver, SimpleNet } from "@vechain/connex-driver";
import { Framework } from "@vechain/connex-framework";
import { Mutex } from "async-mutex";
import type { AxiosInstance } from "axios";
import { JsonRpcProvider, Wallet } from "ethers";
import { BrowserProvider, JsonRpcProvider, Wallet } from "ethers";
import { privateKeyToAccount } from "web3-eth-accounts";
import * as thor from "web3-providers-connex";
import type { TSupportedChainTypes, TSupportedChains } from "../../../config";
import type { BridgeStorage, ERC20Staking } from "../../../contractsTypes/evm";
import { Block } from "../../../persistence/entities/block";
Expand All @@ -26,8 +29,22 @@ export async function configEvmHandler(
contractAddress: conf.contractAddress,
});
const mutex = new Mutex();
const provider = new JsonRpcProvider(conf.rpcURL);
const fetchProvider = async (): Promise<[JsonRpcProvider, MutexReleaser]> => {
let provider: JsonRpcProvider | BrowserProvider;
if (conf.chain === "VECHAIN") {
const net = new SimpleNet(conf.rpcURL);
const driver = await Driver.connect(net);
const connexObj = new Framework(driver);
provider = new BrowserProvider(
new thor.ConnexProvider({
connex: connexObj,
}),
);
} else {
provider = new JsonRpcProvider(conf.rpcURL);
}
const fetchProvider = async (): Promise<
[JsonRpcProvider | BrowserProvider, MutexReleaser]
> => {
const release = await mutex.acquire();
return [provider, release];
};
Expand Down
6 changes: 4 additions & 2 deletions src/handler/chains/evm/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { EntityManager } from "@mikro-orm/sqlite";
import type { AxiosInstance } from "axios";
import type { JsonRpcProvider, Wallet } from "ethers";
import type { BrowserProvider, JsonRpcProvider, Wallet } from "ethers";
import type { Web3Account } from "web3-eth-accounts";
import type {
TSupportedChainTypes,
Expand Down Expand Up @@ -34,4 +34,6 @@ export type EVMHandlerParams = {

export type MutexReleaser = () => void;

export type EVMProviderFetch = () => Promise<[JsonRpcProvider, MutexReleaser]>;
export type EVMProviderFetch = () => Promise<
[JsonRpcProvider | BrowserProvider, MutexReleaser]
>;
10 changes: 5 additions & 5 deletions src/handler/chains/near/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ export async function configNearHandler(
staking: ERC20Staking,
validatorAddress: string,
) {
const near = await connect({
networkId: conf.networkId,
nodeUrl: conf.rpcURL,
});

const lb = await em.findOne(Block, {
chain: conf.chain,
contractAddress: conf.contractAddress,
Expand All @@ -42,6 +37,11 @@ export async function configNearHandler(
nearWallet.accountId,
KeyPair.fromString(nearWallet.secretKey as never),
);
const near = await connect({
networkId: conf.networkId,
nodeUrl: conf.rpcURL,
keyStore: ks,
});
const mutex = new Mutex();
async function fetchProvider() {
const release = await mutex.acquire();
Expand Down
4 changes: 2 additions & 2 deletions src/handler/chains/near/utils/signData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import type { KeyPairEd25519 } from "near-api-js/lib/utils";

export class AddValidator {
@field({ type: "string" })
account_id: string;
public_key: string;

@field({ type: "string" })
public_key: string;
account_id: string;

constructor(account_id: string, public_key: string) {
this.account_id = account_id;
Expand Down

0 comments on commit 1fceef6

Please sign in to comment.