Skip to content

Commit

Permalink
lib-ethers: Use LiquityConnection everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
danielattilasimon committed Feb 5, 2021
1 parent 48ff08e commit 66364e4
Show file tree
Hide file tree
Showing 15 changed files with 279 additions and 249 deletions.
17 changes: 10 additions & 7 deletions api-extractor.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -330,14 +330,17 @@
"default": {
"logLevel": "warning"
// "addToApiReportFile": false
}
},

// "ae-extra-release-tag": {
// "logLevel": "warning",
// "addToApiReportFile": true
// },
//
// . . .
"ae-forgotten-export": {
"logLevel": "warning",
"addToApiReportFile": false
},

"ae-internal-missing-underscore": {
"logLevel": "warning",
"addToApiReportFile": false
}
},

/**
Expand Down
8 changes: 4 additions & 4 deletions docs/sdk/lib-ethers.blockpolledliquitystore._constructor_.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ Constructs a new instance of the `BlockPolledLiquityStore` class
<b>Signature:</b>

```typescript
constructor(provider: Provider, account: string, liquity: ReadableEthersLiquity, frontendTag?: string);
constructor(connection: LiquityConnection, readableLiquity?: ReadableEthersLiquity, frontendTag?: string, userAddress?: string);
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| provider | Provider | |
| account | string | |
| liquity | [ReadableEthersLiquity](./lib-ethers.readableethersliquity.md) | |
| connection | [LiquityConnection](./lib-ethers.liquityconnection.md) | |
| readableLiquity | [ReadableEthersLiquity](./lib-ethers.readableethersliquity.md) | |
| frontendTag | string | |
| userAddress | string | |

2 changes: 1 addition & 1 deletion docs/sdk/lib-ethers.blockpolledliquitystore.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export declare class BlockPolledLiquityStore extends LiquityStore<BlockPolledLiq
| Constructor | Modifiers | Description |
| --- | --- | --- |
| [(constructor)(provider, account, liquity, frontendTag)](./lib-ethers.blockpolledliquitystore._constructor_.md) | | Constructs a new instance of the <code>BlockPolledLiquityStore</code> class |
| [(constructor)(connection, readableLiquity, frontendTag, userAddress)](./lib-ethers.blockpolledliquitystore._constructor_.md) | | Constructs a new instance of the <code>BlockPolledLiquityStore</code> class |
## Methods
Expand Down
2 changes: 1 addition & 1 deletion packages/dev-frontend/src/hooks/LiquityContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export const LiquityProvider: React.FC<LiquityProviderProps> = ({
}

const readable = new ReadableEthersLiquity(connection, account);
const store = new BlockPolledLiquityStore(provider, account, readable, config.frontendTag);
const store = new BlockPolledLiquityStore(connection, readable, config.frontendTag, account);
const populatable = new PopulatableEthersLiquity(connection, readable, store);
const liquity = new EthersLiquity(readable, populatable);

Expand Down
16 changes: 7 additions & 9 deletions packages/lib-ethers/etc/lib-ethers.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ import { TroveWithPendingRedistribution } from '@liquity/lib-base';

// @public
export class BlockPolledLiquityStore extends LiquityStore<BlockPolledLiquityStoreExtraState> {
constructor(provider: Provider, account: string, liquity: ReadableEthersLiquity, frontendTag?: string);
constructor(connection: LiquityConnection, readableLiquity?: ReadableEthersLiquity, frontendTag?: string, userAddress?: string);
// @override (undocumented)
protected _doStart(): () => void;
// @override (undocumented)
protected _reduceExtra(oldState: BlockPolledLiquityStoreExtraState, stateUpdate: Partial<BlockPolledLiquityStoreExtraState>): BlockPolledLiquityStoreExtraState;
}
}

// @public
export interface BlockPolledLiquityStoreExtraState {
Expand All @@ -71,8 +71,6 @@ export interface EthersCallOverrides {
from?: string;
}

// Warning: (ae-forgotten-export) The symbol "GluedEthersLiquity" needs to be exported by the entry point index.d.ts
//
// @public
export class EthersLiquity extends GluedEthersLiquity {
constructor(readable: ReadableEthersLiquity, populatable: PopulatableEthersLiquity);
Expand Down Expand Up @@ -215,14 +213,14 @@ export class PopulatableEthersLiquity extends _PopulatableEthersLiquityBase impl
export class _PopulatableEthersLiquityBase extends _EthersLiquityBase {
constructor(connection: LiquityConnection, readableLiquity: ReadableLiquity, store?: LiquityStore);
// (undocumented)
protected readonly _connection: LiquityConnection;
// (undocumented)
protected _findHints(trove: Trove): Promise<[string, string]>;
// (undocumented)
protected _findRedemptionHints(amount: Decimal): Promise<[string, string, string, Decimal]>;
// (undocumented)
protected readonly _readableLiquity: ReadableLiquity;
// (undocumented)
protected readonly _signer: Signer;
// (undocumented)
protected readonly _store?: LiquityStore;
// (undocumented)
protected _wrapCollateralGainTransfer(rawPopulatedTransaction: EthersPopulatedTransaction): PopulatedEthersLiquityTransaction<CollateralGainTransferDetails>;
Expand All @@ -249,11 +247,11 @@ export class _PopulatableEthersLiquityBase extends _EthersLiquityBase {
// @public
export class PopulatedEthersLiquityTransaction<T = unknown> implements PopulatedLiquityTransaction<EthersPopulatedTransaction, SentEthersLiquityTransaction<T>> {
// @internal
constructor(rawPopulatedTransaction: EthersPopulatedTransaction, parse: (rawReceipt: EthersTransactionReceipt) => T, signer: Signer, connection: LiquityConnection);
constructor(rawPopulatedTransaction: EthersPopulatedTransaction, connection: LiquityConnection, parse: (rawReceipt: EthersTransactionReceipt) => T);
readonly rawPopulatedTransaction: EthersPopulatedTransaction;
// (undocumented)
send(): Promise<SentEthersLiquityTransaction<T>>;
}
}

// Warning: (ae-incompatible-release-tags) The symbol "ReadableEthersLiquity" is marked as @public, but its signature references "_EthersLiquityBase" which is marked as @internal
//
Expand Down Expand Up @@ -351,7 +349,7 @@ export class SendableEthersLiquity implements _SendableFrom<PopulatableEthersLiq
// @public
export class SentEthersLiquityTransaction<T = unknown> implements SentLiquityTransaction<EthersTransactionResponse, LiquityReceipt<EthersTransactionReceipt, T>> {
// @internal
constructor(rawSentTransaction: EthersTransactionResponse, parse: (rawReceipt: EthersTransactionReceipt) => T, provider: Provider, connection: LiquityConnection);
constructor(rawSentTransaction: EthersTransactionResponse, connection: LiquityConnection, parse: (rawReceipt: EthersTransactionReceipt) => T);
// (undocumented)
getReceipt(): Promise<LiquityReceipt<EthersTransactionReceipt, T>>;
readonly rawSentTransaction: EthersTransactionResponse;
Expand Down
2 changes: 1 addition & 1 deletion packages/lib-ethers/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { connectToLiquity, LiquityConnection, UnsupportedNetworkError } from "./src/contracts";
export { connectToLiquity, LiquityConnection, UnsupportedNetworkError } from "./src/connection";

export * from "./src/types";
export * from "./src/ReadableEthersLiquity";
Expand Down
90 changes: 59 additions & 31 deletions packages/lib-ethers/src/BlockPolledLiquityStore.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import { AddressZero } from "@ethersproject/constants";
import { BigNumber } from "@ethersproject/bignumber";
import { Provider } from "@ethersproject/abstract-provider";

import { Decimal } from "@liquity/decimal";
import { LiquityStore, LiquityStoreState, LiquityStoreBaseState } from "@liquity/lib-base";
import {
LiquityStore,
LiquityStoreState,
LiquityStoreBaseState,
TroveWithPendingRedistribution,
StabilityDeposit,
LQTYStake
} from "@liquity/lib-base";

import { ReadableEthersLiquity } from "./ReadableEthersLiquity";
import { LiquityConnection, _getProvider } from "./connection";

/**
* Extra state added to {@link @liquity/lib-base#LiquityStoreState} by
Expand Down Expand Up @@ -51,45 +58,66 @@ const decimalify = (bigNumber: BigNumber) => new Decimal(bigNumber);
* @public
*/
export class BlockPolledLiquityStore extends LiquityStore<BlockPolledLiquityStoreExtraState> {
private _provider: Provider;
private _account: string;
private _liquity: ReadableEthersLiquity;
private _frontendTag: string;
private readonly _provider: Provider;
private readonly _readableLiquity: ReadableEthersLiquity;
private readonly _frontendTag?: string;
private readonly _userAddress?: string;

constructor(
provider: Provider,
account: string,
liquity: ReadableEthersLiquity,
frontendTag = AddressZero
connection: LiquityConnection,
readableLiquity?: ReadableEthersLiquity,
frontendTag?: string,
userAddress?: string
) {
super();

this._provider = provider;
this._account = account;
this._liquity = liquity;
this._provider = _getProvider(connection);
this._readableLiquity = readableLiquity ?? new ReadableEthersLiquity(connection);
this._frontendTag = frontendTag;
this._userAddress = userAddress;
}

private _get(blockTag?: number): Promise<LiquityStoreBaseState> {
return promiseAllValues({
frontend: this._liquity.getFrontendStatus(this._frontendTag, { blockTag }),
ownFrontend: this._liquity.getFrontendStatus(this._account, { blockTag }),
accountBalance: this._provider.getBalance(this._account, blockTag).then(decimalify),
lusdBalance: this._liquity.getLUSDBalance(this._account, { blockTag }),
lqtyBalance: this._liquity.getLQTYBalance(this._account, { blockTag }),
collateralSurplusBalance: this._liquity.getCollateralSurplusBalance(this._account, {
blockTag
}),
price: this._liquity.getPrice({ blockTag }),
numberOfTroves: this._liquity.getNumberOfTroves({ blockTag }),
troveWithoutRedistribution: this._liquity.getTroveWithoutRewards(this._account, { blockTag }),
totalRedistributed: this._liquity.getTotalRedistributed({ blockTag }),
deposit: this._liquity.getStabilityDeposit(this._account, { blockTag }),
total: this._liquity.getTotal({ blockTag }),
lusdInStabilityPool: this._liquity.getLUSDInStabilityPool({ blockTag }),
fees: this._liquity.getFees({ blockTag }),
lqtyStake: this._liquity.getLQTYStake(this._account, { blockTag }),
totalStakedLQTY: this._liquity.getTotalStakedLQTY({ blockTag })
price: this._readableLiquity.getPrice({ blockTag }),
numberOfTroves: this._readableLiquity.getNumberOfTroves({ blockTag }),
totalRedistributed: this._readableLiquity.getTotalRedistributed({ blockTag }),
total: this._readableLiquity.getTotal({ blockTag }),
lusdInStabilityPool: this._readableLiquity.getLUSDInStabilityPool({ blockTag }),
fees: this._readableLiquity.getFees({ blockTag }),
totalStakedLQTY: this._readableLiquity.getTotalStakedLQTY({ blockTag }),

frontend: this._frontendTag
? this._readableLiquity.getFrontendStatus(this._frontendTag, { blockTag })
: { status: "unregistered" },

...(this._userAddress
? {
accountBalance: this._provider.getBalance(this._userAddress, blockTag).then(decimalify),
lusdBalance: this._readableLiquity.getLUSDBalance(this._userAddress, { blockTag }),
lqtyBalance: this._readableLiquity.getLQTYBalance(this._userAddress, { blockTag }),
collateralSurplusBalance: this._readableLiquity.getCollateralSurplusBalance(
this._userAddress,
{ blockTag }
),
troveWithoutRedistribution: this._readableLiquity.getTroveWithoutRewards(
this._userAddress,
{ blockTag }
),
deposit: this._readableLiquity.getStabilityDeposit(this._userAddress, { blockTag }),
lqtyStake: this._readableLiquity.getLQTYStake(this._userAddress, { blockTag }),
ownFrontend: this._readableLiquity.getFrontendStatus(this._userAddress, { blockTag })
}
: {
accountBalance: Decimal.ZERO,
lusdBalance: Decimal.ZERO,
lqtyBalance: Decimal.ZERO,
collateralSurplusBalance: Decimal.ZERO,
troveWithoutRedistribution: new TroveWithPendingRedistribution(),
deposit: new StabilityDeposit(),
lqtyStake: new LQTYStake(),
ownFrontend: { status: "unregistered" }
})
});
}

Expand Down
2 changes: 1 addition & 1 deletion packages/lib-ethers/src/EthersLiquity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Signer } from "@ethersproject/abstract-signer";

import { _glue } from "@liquity/lib-base";

import { LiquityConnection, connectToLiquity } from "./contracts";
import { LiquityConnection, connectToLiquity } from "./connection";

import {
PopulatableEthersLiquity,
Expand Down
2 changes: 1 addition & 1 deletion packages/lib-ethers/src/EthersLiquityBase.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LiquityConnection } from "./contracts";
import { LiquityConnection } from "./connection";

/** @internal */
export class _EthersLiquityBase {
Expand Down
2 changes: 1 addition & 1 deletion packages/lib-ethers/src/ObservableEthersLiquity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
TroveWithPendingRedistribution
} from "@liquity/lib-base";

import { LiquityConnection, _getContracts } from "./contracts";
import { LiquityConnection, _getContracts } from "./connection";
import { _EthersLiquityBase } from "./EthersLiquityBase";
import { ReadableEthersLiquity } from "./ReadableEthersLiquity";

Expand Down
Loading

0 comments on commit 66364e4

Please sign in to comment.