Skip to content
This repository has been archived by the owner on Dec 27, 2022. It is now read-only.

Commit

Permalink
update : usage of JsonRpcProvider -> ChainProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
jakekidd committed May 18, 2021
1 parent bc20c0c commit bd7795e
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 36 deletions.
10 changes: 5 additions & 5 deletions modules/contracts/src.ts/services/ethReader.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ChainError, FullChannelState, Result } from "@connext/vector-types";
import { ChainError, ChainProvider, FullChannelState, Result } from "@connext/vector-types";
import { createTestChannelState, expect, getTestLoggers, mkHash } from "@connext/vector-utils";
import { JsonRpcProvider, TransactionReceipt } from "@ethersproject/providers";
import { TransactionReceipt } from "@ethersproject/providers";
import { AddressZero, One, Zero } from "@ethersproject/constants";
import { parseUnits } from "@ethersproject/units";
import { restore, reset, createStubInstance, SinonStubbedInstance } from "sinon";
Expand All @@ -9,8 +9,8 @@ import { EthereumChainReader, MIN_GAS_PRICE, BUMP_GAS_PRICE } from "./ethReader"

let ethReader: EthereumChainReader;
let channelState: FullChannelState;
let provider1337: SinonStubbedInstance<JsonRpcProvider>;
let provider1338: SinonStubbedInstance<JsonRpcProvider>;
let provider1337: SinonStubbedInstance<ChainProvider>;
let provider1338: SinonStubbedInstance<ChainProvider>;

const assertResult = (result: Result<any>, isError: boolean, unwrappedVal?: any) => {
if (isError) {
Expand Down Expand Up @@ -46,7 +46,7 @@ describe("ethReader", () => {
beforeEach(() => {
// eth service deps

const _provider = createStubInstance(JsonRpcProvider);
const _provider = createStubInstance(ChainProvider);
_provider.getTransaction.resolves(_txResponse);
provider1337 = _provider;
provider1338 = _provider;
Expand Down
9 changes: 5 additions & 4 deletions modules/contracts/src.ts/services/ethService.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
ChainError,
ChainProvider,
FullChannelState,
IChainServiceStore,
IChannelSigner,
Expand All @@ -20,7 +21,7 @@ import {
mkHash,
} from "@connext/vector-utils";
import { AddressZero, One, Zero } from "@ethersproject/constants";
import { JsonRpcProvider, TransactionReceipt, TransactionResponse } from "@ethersproject/providers";
import { TransactionReceipt, TransactionResponse } from "@ethersproject/providers";
import { BigNumber } from "ethers";
import { parseUnits } from "ethers/lib/utils";
import { restore, reset, createStubInstance, SinonStubbedInstance, stub, SinonStub } from "sinon";
Expand All @@ -30,8 +31,8 @@ import { BIG_GAS_PRICE, EthereumChainService } from "./ethService";
let storeMock: SinonStubbedInstance<IChainServiceStore>;
let signer: SinonStubbedInstance<IChannelSigner>;
let ethService: EthereumChainService;
let provider1337: SinonStubbedInstance<JsonRpcProvider>;
let provider1338: SinonStubbedInstance<JsonRpcProvider>;
let provider1337: SinonStubbedInstance<ChainProvider>;
let provider1338: SinonStubbedInstance<ChainProvider>;

let sendTxWithRetriesMock: SinonStub;
let approveMock: SinonStub;
Expand Down Expand Up @@ -96,7 +97,7 @@ describe("ethService unit test", () => {
signer.connect.returns(signer as any);
(signer as any)._isSigner = true;

const _provider = createStubInstance(JsonRpcProvider);
const _provider = createStubInstance(ChainProvider);
_provider.getTransaction.resolves(txResponse);
provider1337 = _provider;
provider1338 = _provider;
Expand Down
2 changes: 1 addition & 1 deletion modules/contracts/src.ts/services/ethService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ export class EthereumChainService extends EthereumChainReader implements IVector
}

public async waitForConfirmation(chainId: number, response: TransactionResponse): Promise<TransactionReceipt> {
const provider: JsonRpcProvider = this.chainProviders[chainId];
const provider = this.chainProviders[chainId];
if (!provider) {
throw new ChainError(ChainError.reasons.ProviderNotFound);
}
Expand Down
4 changes: 2 additions & 2 deletions modules/router/src/services/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import {
jsonifyError,
IVectorChainReader,
DEFAULT_ROUTER_MAX_SAFE_PRICE_IMPACT,
ChainProvider,
} from "@connext/vector-types";
import { JsonRpcProvider } from "@ethersproject/providers";
import { StableSwap } from "@connext/vector-contracts";
import { getAddress } from "@ethersproject/address";
import { BigNumber } from "@ethersproject/bignumber";
Expand Down Expand Up @@ -132,7 +132,7 @@ export const onSwapGivenIn = async (
logger: BaseLogger,
): Promise<Result<{ priceImpact: string; amountOut: BigNumber }, ConfigServiceError>> => {
const { stableAmmChainId, stableAmmAddress } = getConfig();
const stableAmmProvider: JsonRpcProvider = new JsonRpcProvider(getConfig().chainProviders[stableAmmChainId!]);
const stableAmmProvider: ChainProvider = new ChainProvider(stableAmmChainId!, [getConfig().chainProviders[stableAmmChainId!]]);

// if there's no swap, rate is 1:1
if (fromAssetId === toAssetId && fromChainId === toChainId) {
Expand Down
4 changes: 1 addition & 3 deletions modules/router/src/test/autoRebalance.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ import { Wallet } from "@ethersproject/wallet";
import { BigNumber } from "@ethersproject/bignumber";
import { parseEther } from "@ethersproject/units";
import axios from "axios";
import PriorityQueue from "p-queue";

import { rebalanceIfNeeded } from "../services/autoRebalance";
import { getConfig } from "../config";
import * as metrics from "../metrics";
import { PrismaStore, RouterRebalanceStatus } from "../services/store";
import { _createQueueForSwap } from "../services/rebalanceQueue";
import { AutoRebalanceServiceError } from "../errors";

const config = getConfig();

Expand All @@ -24,7 +22,7 @@ const { log } = getTestLoggers(testName, config.logLevel as any);
const setupForRebalance = (
mockAxios: Sinon.SinonStubbedInstance<any>,
wallet: Sinon.SinonStubbedInstance<Wallet>,
hydratedProviders: { [chainId: number]: Sinon.SinonStubbedInstance<JsonRpcProvider> },
hydratedProviders: { [chainId: number]: Sinon.SinonStubbedInstance<ChainProvider> },
chainService: Sinon.SinonStubbedInstance<VectorChainReader>,
): {
transaction: {
Expand Down
23 changes: 2 additions & 21 deletions modules/types/src/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,26 +89,6 @@ export class ChainProvider implements BaseProvider {
this._provider = provider;
this.chainId = chainId;
this.providerUrls = providerUrls;

// for (var member in BaseProvider) {
// if (typeof BaseProvider[member] === "function") {
// // if (T.hasOwnProperty(member)) {
// this[member] = this._provider[member];
// // }
// }
// }

// Object.assign(this, this._provider); -> TypeError: Cannot assign to read only property '_isProvider' of object '#<ChainProvider>'
// for (var key in Object.keys(this._provider)) {
// console.log("DEBUG MESSAGE:")
// console.log(key, this._provider[key]);
// if (typeof this._provider[key] == "function") {
// Object.assign(this, {
// key: this._provider[key]
// });
// console.log(this[key]);
// }
// }
}

send(method: string, params: any[]): Promise<any> {
Expand Down Expand Up @@ -181,9 +161,10 @@ export class ChainProvider implements BaseProvider {
this._provider.polling = value;
}
get pollingInterval(): number {
return this._provider.pollingInterval;
return this._provider ? this._provider.pollingInterval : this._pollingInterval;
}
set pollingInterval(value: number) {
this._pollingInterval = value;
this._provider.pollingInterval = value;
}
_getFastBlockNumber(): Promise<number> {
Expand Down

0 comments on commit bd7795e

Please sign in to comment.