Skip to content

Commit

Permalink
feat: make use of Ethers' transaction replacement detection
Browse files Browse the repository at this point in the history
  • Loading branch information
danielattilasimon committed Jun 18, 2021
1 parent 8d7948d commit a56f9b6
Show file tree
Hide file tree
Showing 38 changed files with 250 additions and 39 deletions.
2 changes: 1 addition & 1 deletion docs/sdk/lib-ethers.ethersliquity.adjusttrove.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Promise&lt;[TroveAdjustmentDetails](./lib-base.troveadjustmentdetails.md)<!-- --

## Exceptions

Throws [EthersTransactionFailedError](./lib-ethers.etherstransactionfailederror.md) in case of transaction failure.
Throws [EthersTransactionFailedError](./lib-ethers.etherstransactionfailederror.md) in case of transaction failure. Throws [EthersTransactionCancelledError](./lib-ethers.etherstransactioncancellederror.md) if the transaction is cancelled or replaced.

## Remarks

Expand Down
2 changes: 1 addition & 1 deletion docs/sdk/lib-ethers.ethersliquity.approveunitokens.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Promise&lt;void&gt;

## Exceptions

Throws [EthersTransactionFailedError](./lib-ethers.etherstransactionfailederror.md) in case of transaction failure.
Throws [EthersTransactionFailedError](./lib-ethers.etherstransactionfailederror.md) in case of transaction failure. Throws [EthersTransactionCancelledError](./lib-ethers.etherstransactioncancellederror.md) if the transaction is cancelled or replaced.

## Remarks

Expand Down
2 changes: 1 addition & 1 deletion docs/sdk/lib-ethers.ethersliquity.borrowlusd.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Promise&lt;[TroveAdjustmentDetails](./lib-base.troveadjustmentdetails.md)<!-- --

## Exceptions

Throws [EthersTransactionFailedError](./lib-ethers.etherstransactionfailederror.md) in case of transaction failure.
Throws [EthersTransactionFailedError](./lib-ethers.etherstransactionfailederror.md) in case of transaction failure. Throws [EthersTransactionCancelledError](./lib-ethers.etherstransactioncancellederror.md) if the transaction is cancelled or replaced.

## Remarks

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Promise&lt;void&gt;

## Exceptions

Throws [EthersTransactionFailedError](./lib-ethers.etherstransactionfailederror.md) in case of transaction failure.
Throws [EthersTransactionFailedError](./lib-ethers.etherstransactionfailederror.md) in case of transaction failure. Throws [EthersTransactionCancelledError](./lib-ethers.etherstransactioncancellederror.md) if the transaction is cancelled or replaced.

## Remarks

Expand Down
2 changes: 1 addition & 1 deletion docs/sdk/lib-ethers.ethersliquity.closetrove.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ Promise&lt;[TroveClosureDetails](./lib-base.troveclosuredetails.md)<!-- -->&gt;

## Exceptions

Throws [EthersTransactionFailedError](./lib-ethers.etherstransactionfailederror.md) in case of transaction failure.
Throws [EthersTransactionFailedError](./lib-ethers.etherstransactionfailederror.md) in case of transaction failure. Throws [EthersTransactionCancelledError](./lib-ethers.etherstransactioncancellederror.md) if the transaction is cancelled or replaced.

2 changes: 1 addition & 1 deletion docs/sdk/lib-ethers.ethersliquity.depositcollateral.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Promise&lt;[TroveAdjustmentDetails](./lib-base.troveadjustmentdetails.md)<!-- --

## Exceptions

Throws [EthersTransactionFailedError](./lib-ethers.etherstransactionfailederror.md) in case of transaction failure.
Throws [EthersTransactionFailedError](./lib-ethers.etherstransactionfailederror.md) in case of transaction failure. Throws [EthersTransactionCancelledError](./lib-ethers.etherstransactioncancellederror.md) if the transaction is cancelled or replaced.

## Remarks

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Promise&lt;[StabilityDepositChangeDetails](./lib-base.stabilitydepositchangedeta

## Exceptions

Throws [EthersTransactionFailedError](./lib-ethers.etherstransactionfailederror.md) in case of transaction failure.
Throws [EthersTransactionFailedError](./lib-ethers.etherstransactionfailederror.md) in case of transaction failure. Throws [EthersTransactionCancelledError](./lib-ethers.etherstransactioncancellederror.md) if the transaction is cancelled or replaced.

## Remarks

Expand Down
2 changes: 1 addition & 1 deletion docs/sdk/lib-ethers.ethersliquity.exitliquiditymining.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ Promise&lt;void&gt;

## Exceptions

Throws [EthersTransactionFailedError](./lib-ethers.etherstransactionfailederror.md) in case of transaction failure.
Throws [EthersTransactionFailedError](./lib-ethers.etherstransactionfailederror.md) in case of transaction failure. Throws [EthersTransactionCancelledError](./lib-ethers.etherstransactioncancellederror.md) if the transaction is cancelled or replaced.

2 changes: 1 addition & 1 deletion docs/sdk/lib-ethers.ethersliquity.liquidate.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ Promise&lt;[LiquidationDetails](./lib-base.liquidationdetails.md)<!-- -->&gt;

## Exceptions

Throws [EthersTransactionFailedError](./lib-ethers.etherstransactionfailederror.md) in case of transaction failure.
Throws [EthersTransactionFailedError](./lib-ethers.etherstransactionfailederror.md) in case of transaction failure. Throws [EthersTransactionCancelledError](./lib-ethers.etherstransactioncancellederror.md) if the transaction is cancelled or replaced.

2 changes: 1 addition & 1 deletion docs/sdk/lib-ethers.ethersliquity.liquidateupto.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ Promise&lt;[LiquidationDetails](./lib-base.liquidationdetails.md)<!-- -->&gt;

## Exceptions

Throws [EthersTransactionFailedError](./lib-ethers.etherstransactionfailederror.md) in case of transaction failure.
Throws [EthersTransactionFailedError](./lib-ethers.etherstransactionfailederror.md) in case of transaction failure. Throws [EthersTransactionCancelledError](./lib-ethers.etherstransactioncancellederror.md) if the transaction is cancelled or replaced.

2 changes: 1 addition & 1 deletion docs/sdk/lib-ethers.ethersliquity.opentrove.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Promise&lt;[TroveCreationDetails](./lib-base.trovecreationdetails.md)<!-- -->&gt

## Exceptions

Throws [EthersTransactionFailedError](./lib-ethers.etherstransactionfailederror.md) in case of transaction failure.
Throws [EthersTransactionFailedError](./lib-ethers.etherstransactionfailederror.md) in case of transaction failure. Throws [EthersTransactionCancelledError](./lib-ethers.etherstransactioncancellederror.md) if the transaction is cancelled or replaced.

## Remarks

Expand Down
2 changes: 1 addition & 1 deletion docs/sdk/lib-ethers.ethersliquity.redeemlusd.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Promise&lt;[RedemptionDetails](./lib-base.redemptiondetails.md)<!-- -->&gt;

## Exceptions

Throws [EthersTransactionFailedError](./lib-ethers.etherstransactionfailederror.md) in case of transaction failure.
Throws [EthersTransactionFailedError](./lib-ethers.etherstransactionfailederror.md) in case of transaction failure. Throws [EthersTransactionCancelledError](./lib-ethers.etherstransactioncancellederror.md) if the transaction is cancelled or replaced.

## Remarks

Expand Down
2 changes: 1 addition & 1 deletion docs/sdk/lib-ethers.ethersliquity.registerfrontend.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ Promise&lt;void&gt;

## Exceptions

Throws [EthersTransactionFailedError](./lib-ethers.etherstransactionfailederror.md) in case of transaction failure.
Throws [EthersTransactionFailedError](./lib-ethers.etherstransactionfailederror.md) in case of transaction failure. Throws [EthersTransactionCancelledError](./lib-ethers.etherstransactioncancellederror.md) if the transaction is cancelled or replaced.

2 changes: 1 addition & 1 deletion docs/sdk/lib-ethers.ethersliquity.repaylusd.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Promise&lt;[TroveAdjustmentDetails](./lib-base.troveadjustmentdetails.md)<!-- --

## Exceptions

Throws [EthersTransactionFailedError](./lib-ethers.etherstransactionfailederror.md) in case of transaction failure.
Throws [EthersTransactionFailedError](./lib-ethers.etherstransactionfailederror.md) in case of transaction failure. Throws [EthersTransactionCancelledError](./lib-ethers.etherstransactioncancellederror.md) if the transaction is cancelled or replaced.

## Remarks

Expand Down
2 changes: 1 addition & 1 deletion docs/sdk/lib-ethers.ethersliquity.sendlqty.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ Promise&lt;void&gt;

## Exceptions

Throws [EthersTransactionFailedError](./lib-ethers.etherstransactionfailederror.md) in case of transaction failure.
Throws [EthersTransactionFailedError](./lib-ethers.etherstransactionfailederror.md) in case of transaction failure. Throws [EthersTransactionCancelledError](./lib-ethers.etherstransactioncancellederror.md) if the transaction is cancelled or replaced.

2 changes: 1 addition & 1 deletion docs/sdk/lib-ethers.ethersliquity.sendlusd.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ Promise&lt;void&gt;

## Exceptions

Throws [EthersTransactionFailedError](./lib-ethers.etherstransactionfailederror.md) in case of transaction failure.
Throws [EthersTransactionFailedError](./lib-ethers.etherstransactionfailederror.md) in case of transaction failure. Throws [EthersTransactionCancelledError](./lib-ethers.etherstransactioncancellederror.md) if the transaction is cancelled or replaced.

2 changes: 1 addition & 1 deletion docs/sdk/lib-ethers.ethersliquity.stakelqty.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Promise&lt;void&gt;

## Exceptions

Throws [EthersTransactionFailedError](./lib-ethers.etherstransactionfailederror.md) in case of transaction failure.
Throws [EthersTransactionFailedError](./lib-ethers.etherstransactionfailederror.md) in case of transaction failure. Throws [EthersTransactionCancelledError](./lib-ethers.etherstransactioncancellederror.md) if the transaction is cancelled or replaced.

## Remarks

Expand Down
2 changes: 1 addition & 1 deletion docs/sdk/lib-ethers.ethersliquity.stakeunitokens.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ Promise&lt;void&gt;

## Exceptions

Throws [EthersTransactionFailedError](./lib-ethers.etherstransactionfailederror.md) in case of transaction failure.
Throws [EthersTransactionFailedError](./lib-ethers.etherstransactionfailederror.md) in case of transaction failure. Throws [EthersTransactionCancelledError](./lib-ethers.etherstransactioncancellederror.md) if the transaction is cancelled or replaced.

Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Promise&lt;[CollateralGainTransferDetails](./lib-base.collateralgaintransferdeta

## Exceptions

Throws [EthersTransactionFailedError](./lib-ethers.etherstransactionfailederror.md) in case of transaction failure.
Throws [EthersTransactionFailedError](./lib-ethers.etherstransactionfailederror.md) in case of transaction failure. Throws [EthersTransactionCancelledError](./lib-ethers.etherstransactioncancellederror.md) if the transaction is cancelled or replaced.

## Remarks

Expand Down
2 changes: 1 addition & 1 deletion docs/sdk/lib-ethers.ethersliquity.unstakelqty.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Promise&lt;void&gt;

## Exceptions

Throws [EthersTransactionFailedError](./lib-ethers.etherstransactionfailederror.md) in case of transaction failure.
Throws [EthersTransactionFailedError](./lib-ethers.etherstransactionfailederror.md) in case of transaction failure. Throws [EthersTransactionCancelledError](./lib-ethers.etherstransactioncancellederror.md) if the transaction is cancelled or replaced.

## Remarks

Expand Down
2 changes: 1 addition & 1 deletion docs/sdk/lib-ethers.ethersliquity.unstakeunitokens.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ Promise&lt;void&gt;

## Exceptions

Throws [EthersTransactionFailedError](./lib-ethers.etherstransactionfailederror.md) in case of transaction failure.
Throws [EthersTransactionFailedError](./lib-ethers.etherstransactionfailederror.md) in case of transaction failure. Throws [EthersTransactionCancelledError](./lib-ethers.etherstransactioncancellederror.md) if the transaction is cancelled or replaced.

2 changes: 1 addition & 1 deletion docs/sdk/lib-ethers.ethersliquity.withdrawcollateral.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Promise&lt;[TroveAdjustmentDetails](./lib-base.troveadjustmentdetails.md)<!-- --

## Exceptions

Throws [EthersTransactionFailedError](./lib-ethers.etherstransactionfailederror.md) in case of transaction failure.
Throws [EthersTransactionFailedError](./lib-ethers.etherstransactionfailederror.md) in case of transaction failure. Throws [EthersTransactionCancelledError](./lib-ethers.etherstransactioncancellederror.md) if the transaction is cancelled or replaced.

## Remarks

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ Promise&lt;[StabilityPoolGainsWithdrawalDetails](./lib-base.stabilitypoolgainswi

## Exceptions

Throws [EthersTransactionFailedError](./lib-ethers.etherstransactionfailederror.md) in case of transaction failure.
Throws [EthersTransactionFailedError](./lib-ethers.etherstransactionfailederror.md) in case of transaction failure. Throws [EthersTransactionCancelledError](./lib-ethers.etherstransactioncancellederror.md) if the transaction is cancelled or replaced.

Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ Promise&lt;void&gt;

## Exceptions

Throws [EthersTransactionFailedError](./lib-ethers.etherstransactionfailederror.md) in case of transaction failure.
Throws [EthersTransactionFailedError](./lib-ethers.etherstransactionfailederror.md) in case of transaction failure. Throws [EthersTransactionCancelledError](./lib-ethers.etherstransactioncancellederror.md) if the transaction is cancelled or replaced.

Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ Promise&lt;void&gt;

## Exceptions

Throws [EthersTransactionFailedError](./lib-ethers.etherstransactionfailederror.md) in case of transaction failure.
Throws [EthersTransactionFailedError](./lib-ethers.etherstransactionfailederror.md) in case of transaction failure. Throws [EthersTransactionCancelledError](./lib-ethers.etherstransactioncancellederror.md) if the transaction is cancelled or replaced.

Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Promise&lt;[StabilityDepositChangeDetails](./lib-base.stabilitydepositchangedeta

## Exceptions

Throws [EthersTransactionFailedError](./lib-ethers.etherstransactionfailederror.md) in case of transaction failure.
Throws [EthersTransactionFailedError](./lib-ethers.etherstransactionfailederror.md) in case of transaction failure. Throws [EthersTransactionCancelledError](./lib-ethers.etherstransactioncancellederror.md) if the transaction is cancelled or replaced.

## Remarks

Expand Down
26 changes: 26 additions & 0 deletions docs/sdk/lib-ethers.etherstransactioncancellederror.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@liquity/lib-ethers](./lib-ethers.md) &gt; [EthersTransactionCancelledError](./lib-ethers.etherstransactioncancellederror.md)

## EthersTransactionCancelledError class

Thrown when a transaction is cancelled or replaced by a different transaction.

<b>Signature:</b>

```typescript
export declare class EthersTransactionCancelledError extends Error
```
<b>Extends:</b> Error
## Remarks
The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the `EthersTransactionCancelledError` class.
## Properties
| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [rawError](./lib-ethers.etherstransactioncancellederror.rawerror.md) | | Error | |
| [rawReplacementReceipt](./lib-ethers.etherstransactioncancellederror.rawreplacementreceipt.md) | | [EthersTransactionReceipt](./lib-ethers.etherstransactionreceipt.md) | |
11 changes: 11 additions & 0 deletions docs/sdk/lib-ethers.etherstransactioncancellederror.rawerror.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@liquity/lib-ethers](./lib-ethers.md) &gt; [EthersTransactionCancelledError](./lib-ethers.etherstransactioncancellederror.md) &gt; [rawError](./lib-ethers.etherstransactioncancellederror.rawerror.md)

## EthersTransactionCancelledError.rawError property

<b>Signature:</b>

```typescript
readonly rawError: Error;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@liquity/lib-ethers](./lib-ethers.md) &gt; [EthersTransactionCancelledError](./lib-ethers.etherstransactioncancellederror.md) &gt; [rawReplacementReceipt](./lib-ethers.etherstransactioncancellederror.rawreplacementreceipt.md)

## EthersTransactionCancelledError.rawReplacementReceipt property

<b>Signature:</b>

```typescript
readonly rawReplacementReceipt: EthersTransactionReceipt;
```
1 change: 1 addition & 0 deletions docs/sdk/lib-ethers.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
| --- | --- |
| [BlockPolledLiquityStore](./lib-ethers.blockpolledliquitystore.md) | Ethers-based [LiquityStore](./lib-base.liquitystore.md) that updates state whenever there's a new block. |
| [EthersLiquity](./lib-ethers.ethersliquity.md) | Convenience class that combines multiple interfaces of the library in one object. |
| [EthersTransactionCancelledError](./lib-ethers.etherstransactioncancellederror.md) | Thrown when a transaction is cancelled or replaced by a different transaction. |
| [EthersTransactionFailedError](./lib-ethers.etherstransactionfailederror.md) | Thrown by [EthersLiquity](./lib-ethers.ethersliquity.md) in case of transaction failure. |
| [PopulatableEthersLiquity](./lib-ethers.populatableethersliquity.md) | Ethers-based implementation of [PopulatableLiquity](./lib-base.populatableliquity.md)<!-- -->. |
| [PopulatedEthersLiquityTransaction](./lib-ethers.populatedethersliquitytransaction.md) | A transaction that has been prepared for sending. |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ Promise&lt;[MinedReceipt](./lib-base.minedreceipt.md)<!-- -->&lt;[EthersTransact

Either a [FailedReceipt](./lib-base.failedreceipt.md) or a [SuccessfulReceipt](./lib-base.successfulreceipt.md)<!-- -->.

## Exceptions

Throws [EthersTransactionCancelledError](./lib-ethers.etherstransactioncancellederror.md) if the transaction is cancelled or replaced.

2 changes: 1 addition & 1 deletion packages/examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"devDependencies": {
"chalk": "^4.1.0",
"ethers": "^5.0.0"
"ethers": "^5.3.0"
},
"scripts": {
"liqbot": "node src/liqbot.js"
Expand Down
2 changes: 1 addition & 1 deletion packages/fuzzer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"@types/yargs": "^16.0.0",
"colors": "^1.4.0",
"dotenv": "^8.2.0",
"ethers": "^5.0.0",
"ethers": "^5.3.0",
"ts-node": "^9.0.0",
"typescript": "~4.1.0",
"yargs": "^16.0.3"
Expand Down
39 changes: 39 additions & 0 deletions packages/lib-ethers/etc/lib-ethers.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { BlockTag } from '@ethersproject/abstract-provider';
import { CollateralGainTransferDetails } from '@liquity/lib-base';
import { Decimal } from '@liquity/lib-base';
import { Decimalish } from '@liquity/lib-base';
import { ErrorCode } from '@ethersproject/logger';
import { FailedReceipt } from '@liquity/lib-base';
import { Fees } from '@liquity/lib-base';
import { FrontendStatus } from '@liquity/lib-base';
Expand Down Expand Up @@ -262,6 +263,16 @@ export type EthersProvider = Provider;
// @public
export type EthersSigner = Signer;

// @public
export class EthersTransactionCancelledError extends Error {
// @internal
constructor(rawError: _RawTransactionReplacedError);
// (undocumented)
readonly rawError: Error;
// (undocumented)
readonly rawReplacementReceipt: EthersTransactionReceipt;
}

// @public
export class EthersTransactionFailedError extends TransactionFailedError<FailedReceipt<EthersTransactionReceipt>> {
constructor(message: string, failedReceipt: FailedReceipt<EthersTransactionReceipt>);
Expand Down Expand Up @@ -390,6 +401,34 @@ export class PopulatedEthersRedemption extends PopulatedEthersLiquityTransaction
readonly redeemableLUSDAmount: Decimal;
}

// @internal (undocumented)
export enum _RawErrorReason {
// (undocumented)
TRANSACTION_CANCELLED = "cancelled",
// (undocumented)
TRANSACTION_FAILED = "transaction failed",
// (undocumented)
TRANSACTION_REPLACED = "replaced",
// (undocumented)
TRANSACTION_REPRICED = "repriced"
}

// @internal (undocumented)
export interface _RawTransactionReplacedError extends Error {
// (undocumented)
cancelled: boolean;
// (undocumented)
code: ErrorCode.TRANSACTION_REPLACED;
// (undocumented)
hash: string;
// (undocumented)
reason: _RawErrorReason.TRANSACTION_CANCELLED | _RawErrorReason.TRANSACTION_REPLACED | _RawErrorReason.TRANSACTION_REPRICED;
// (undocumented)
receipt: EthersTransactionReceipt;
// (undocumented)
replacement: EthersTransactionResponse;
}

// @public
export class ReadableEthersLiquity implements ReadableLiquity {
// @internal
Expand Down
2 changes: 1 addition & 1 deletion packages/lib-ethers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
},
"peerDependencies": {
"@liquity/lib-base": "^3.0.0",
"ethers": "^5.0.0"
"ethers": "^5.3.0"
},
"devDependencies": {
"@microsoft/api-extractor": "7.13.2",
Expand Down
Loading

0 comments on commit a56f9b6

Please sign in to comment.