opnet 1.5.13 → 1.5.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -19,6 +19,7 @@ export declare abstract class TransactionBase<T extends OPNetTransactionTypes> e
19
19
  readonly gasUsed: bigint;
20
20
  readonly specialGasUsed: bigint;
21
21
  readonly pow?: ProofOfWorkChallenge;
22
+ readonly blockNumber?: bigint;
22
23
  protected constructor(transaction: ITransactionBase<T>, network: Network);
23
24
  private decodeProofOfWorkChallenge;
24
25
  }
@@ -8,6 +8,7 @@ import { IDeploymentTransaction } from './transactions/IDeploymentTransaction.js
8
8
  import { IInteractionTransaction } from './transactions/IInteractionTransaction.js';
9
9
  export interface ITransactionBase<T extends OPNetTransactionTypes> extends ITransactionReceipt {
10
10
  readonly id: string;
11
+ readonly blockNumber?: string | bigint;
11
12
  readonly hash: string;
12
13
  readonly index: number;
13
14
  readonly burnedBitcoin: string | BigNumberish;
@@ -1 +1 @@
1
- export declare const version = "1.5.13";
1
+ export declare const version = "1.5.16";
package/build/_version.js CHANGED
@@ -1 +1 @@
1
- export const version = '1.5.13';
1
+ export const version = '1.5.16';
@@ -1,3 +1,20 @@
1
+ export interface FeeRecommendation {
2
+ low: string;
3
+ medium: string;
4
+ high: string;
5
+ }
6
+ export interface RawBitcoinFees {
7
+ readonly conservative: string;
8
+ readonly recommended: FeeRecommendation;
9
+ }
10
+ export interface BitcoinFees {
11
+ readonly conservative: number;
12
+ readonly recommended: {
13
+ readonly low: number;
14
+ readonly medium: number;
15
+ readonly high: number;
16
+ };
17
+ }
1
18
  export interface IBlockGasParameters {
2
19
  readonly blockNumber: bigint;
3
20
  readonly gasUsed: bigint;
@@ -5,6 +22,7 @@ export interface IBlockGasParameters {
5
22
  readonly ema: bigint;
6
23
  readonly baseGas: bigint;
7
24
  readonly gasPerSat: bigint;
25
+ readonly bitcoin: BitcoinFees;
8
26
  }
9
27
  export interface IBlockGasParametersInput {
10
28
  readonly blockNumber: string;
@@ -13,6 +31,7 @@ export interface IBlockGasParametersInput {
13
31
  readonly ema: string;
14
32
  readonly baseGas: string;
15
33
  readonly gasPerSat: string;
34
+ readonly bitcoin: RawBitcoinFees;
16
35
  }
17
36
  export declare class BlockGasParameters implements IBlockGasParameters {
18
37
  readonly blockNumber: bigint;
@@ -21,5 +40,6 @@ export declare class BlockGasParameters implements IBlockGasParameters {
21
40
  readonly ema: bigint;
22
41
  readonly baseGas: bigint;
23
42
  readonly gasPerSat: bigint;
43
+ readonly bitcoin: BitcoinFees;
24
44
  constructor(data: IBlockGasParametersInput);
25
45
  }
@@ -5,6 +5,7 @@ export class BlockGasParameters {
5
5
  ema;
6
6
  baseGas;
7
7
  gasPerSat;
8
+ bitcoin;
8
9
  constructor(data) {
9
10
  this.blockNumber = BigInt(data.blockNumber);
10
11
  this.gasUsed = BigInt(data.gasUsed);
@@ -12,5 +13,13 @@ export class BlockGasParameters {
12
13
  this.ema = BigInt(data.ema);
13
14
  this.baseGas = BigInt(data.baseGas);
14
15
  this.gasPerSat = BigInt(data.gasPerSat);
16
+ this.bitcoin = {
17
+ conservative: Number(data.bitcoin.conservative),
18
+ recommended: {
19
+ low: Number(data.bitcoin.recommended.low),
20
+ medium: Number(data.bitcoin.recommended.medium),
21
+ high: Number(data.bitcoin.recommended.high),
22
+ },
23
+ };
15
24
  }
16
25
  }
@@ -6,6 +6,7 @@ import { ContractDecodedObjectResult, DecodedOutput } from './Contract.js';
6
6
  import { IAccessList } from './interfaces/IAccessList.js';
7
7
  import { EventList, ICallResultData } from './interfaces/ICallResult.js';
8
8
  import { OPNetEvent } from './OPNetEvent.js';
9
+ import { BitcoinFees } from '../block/BlockGasParameters.js';
9
10
  export interface TransactionParameters {
10
11
  readonly signer?: Signer | ECPairInterface;
11
12
  readonly refundTo: string;
@@ -50,6 +51,7 @@ export declare class CallResult<T extends ContractDecodedObjectResult = {}, U ex
50
51
  setTo(to: string, address: Address): void;
51
52
  sendTransaction(interactionParams: TransactionParameters, amountAddition?: bigint): Promise<InteractionTransactionReceipt>;
52
53
  setGasEstimation(estimatedGas: bigint, refundedGas: bigint): void;
54
+ setBitcoinFee(fees: BitcoinFees): void;
53
55
  setDecoded(decoded: DecodedOutput): void;
54
56
  setEvents(events: U): void;
55
57
  setCalldata(calldata: Buffer): void;
@@ -15,6 +15,7 @@ export class CallResult {
15
15
  events = [];
16
16
  to;
17
17
  address;
18
+ #bitcoinFees;
18
19
  #rawEvents;
19
20
  #provider;
20
21
  constructor(callResult, provider) {
@@ -119,7 +120,7 @@ export class CallResult {
119
120
  calldata: this.calldata,
120
121
  priorityFee: priorityFee,
121
122
  gasSatFee: this.bigintMax(this.estimatedSatGas, interactionParams.minGas || 0n),
122
- feeRate: interactionParams.feeRate || 10,
123
+ feeRate: interactionParams.feeRate || this.#bitcoinFees?.conservative || 10,
123
124
  from: interactionParams.refundTo,
124
125
  utxos: UTXOs,
125
126
  to: this.to,
@@ -164,6 +165,9 @@ export class CallResult {
164
165
  this.estimatedSatGas = estimatedGas;
165
166
  this.estimatedRefundedGasInSat = refundedGas;
166
167
  }
168
+ setBitcoinFee(fees) {
169
+ this.#bitcoinFees = fees;
170
+ }
167
171
  setDecoded(decoded) {
168
172
  this.properties = Object.freeze(decoded.obj);
169
173
  }
@@ -452,8 +452,7 @@ export class IBaseContract {
452
452
  obj: obj,
453
453
  };
454
454
  }
455
- async estimateGas(gas) {
456
- const gasParameters = await this.currentGasParameters();
455
+ estimateGas(gas, gasParameters) {
457
456
  const gasPerSat = gasParameters.gasPerSat;
458
457
  const exactGas = (gas * gasPerSat) / 1000000000000n;
459
458
  const finalGas = (exactGas * 100n) / (100n - 30n);
@@ -484,8 +483,10 @@ export class IBaseContract {
484
483
  response.setTo(this.p2opOrTweaked, address);
485
484
  response.setDecoded(decoded);
486
485
  response.setCalldata(buffer);
487
- const gas = await this.estimateGas(response.estimatedGas || 0n);
488
- const gasRefunded = await this.estimateGas(response.refundedGas || 0n);
486
+ const gasParameters = await this.currentGasParameters();
487
+ const gas = this.estimateGas(response.estimatedGas || 0n, gasParameters);
488
+ const gasRefunded = this.estimateGas(response.refundedGas || 0n, gasParameters);
489
+ response.setBitcoinFee(gasParameters.bitcoin);
489
490
  response.setGasEstimation(gas, gasRefunded);
490
491
  response.setEvents(this.decodeEvents(response.rawEvents));
491
492
  return response;
@@ -19,6 +19,7 @@ export declare abstract class TransactionBase<T extends OPNetTransactionTypes> e
19
19
  readonly gasUsed: bigint;
20
20
  readonly specialGasUsed: bigint;
21
21
  readonly pow?: ProofOfWorkChallenge;
22
+ readonly blockNumber?: bigint;
22
23
  protected constructor(transaction: ITransactionBase<T>, network: Network);
23
24
  private decodeProofOfWorkChallenge;
24
25
  }
@@ -14,6 +14,7 @@ export class TransactionBase extends TransactionReceipt {
14
14
  gasUsed;
15
15
  specialGasUsed;
16
16
  pow;
17
+ blockNumber;
17
18
  constructor(transaction, network) {
18
19
  super({
19
20
  receipt: transaction.receipt,
@@ -26,6 +27,8 @@ export class TransactionBase extends TransactionReceipt {
26
27
  this.id = transaction.id;
27
28
  this.hash = transaction.hash;
28
29
  this.index = transaction.index;
30
+ if (transaction.blockNumber)
31
+ this.blockNumber = BigInt(transaction.blockNumber);
29
32
  this.burnedBitcoin = BigInt(transaction.burnedBitcoin) || 0n;
30
33
  this.priorityFee = BigInt(transaction.priorityFee) || 0n;
31
34
  this.inputs = transaction.inputs.map((input) => new TransactionInput(input));
@@ -8,6 +8,7 @@ import { IDeploymentTransaction } from './transactions/IDeploymentTransaction.js
8
8
  import { IInteractionTransaction } from './transactions/IInteractionTransaction.js';
9
9
  export interface ITransactionBase<T extends OPNetTransactionTypes> extends ITransactionReceipt {
10
10
  readonly id: string;
11
+ readonly blockNumber?: string | bigint;
11
12
  readonly hash: string;
12
13
  readonly index: number;
13
14
  readonly burnedBitcoin: string | BigNumberish;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "opnet",
3
3
  "type": "module",
4
- "version": "1.5.13",
4
+ "version": "1.5.16",
5
5
  "author": "OP_NET",
6
6
  "description": "The perfect library for building Bitcoin-based applications.",
7
7
  "engines": {
package/src/_version.ts CHANGED
@@ -1 +1 @@
1
- export const version = '1.5.13';
1
+ export const version = '1.5.16';
@@ -1,3 +1,23 @@
1
+ export interface FeeRecommendation {
2
+ low: string;
3
+ medium: string;
4
+ high: string;
5
+ }
6
+
7
+ export interface RawBitcoinFees {
8
+ readonly conservative: string;
9
+ readonly recommended: FeeRecommendation;
10
+ }
11
+
12
+ export interface BitcoinFees {
13
+ readonly conservative: number;
14
+ readonly recommended: {
15
+ readonly low: number;
16
+ readonly medium: number;
17
+ readonly high: number;
18
+ };
19
+ }
20
+
1
21
  export interface IBlockGasParameters {
2
22
  readonly blockNumber: bigint;
3
23
  readonly gasUsed: bigint;
@@ -5,6 +25,7 @@ export interface IBlockGasParameters {
5
25
  readonly ema: bigint;
6
26
  readonly baseGas: bigint;
7
27
  readonly gasPerSat: bigint;
28
+ readonly bitcoin: BitcoinFees;
8
29
  }
9
30
 
10
31
  export interface IBlockGasParametersInput {
@@ -14,6 +35,7 @@ export interface IBlockGasParametersInput {
14
35
  readonly ema: string;
15
36
  readonly baseGas: string;
16
37
  readonly gasPerSat: string;
38
+ readonly bitcoin: RawBitcoinFees;
17
39
  }
18
40
 
19
41
  export class BlockGasParameters implements IBlockGasParameters {
@@ -23,6 +45,7 @@ export class BlockGasParameters implements IBlockGasParameters {
23
45
  public readonly ema: bigint;
24
46
  public readonly baseGas: bigint;
25
47
  public readonly gasPerSat: bigint;
48
+ public readonly bitcoin: BitcoinFees;
26
49
 
27
50
  public constructor(data: IBlockGasParametersInput) {
28
51
  this.blockNumber = BigInt(data.blockNumber);
@@ -31,5 +54,14 @@ export class BlockGasParameters implements IBlockGasParameters {
31
54
  this.ema = BigInt(data.ema);
32
55
  this.baseGas = BigInt(data.baseGas);
33
56
  this.gasPerSat = BigInt(data.gasPerSat);
57
+
58
+ this.bitcoin = {
59
+ conservative: Number(data.bitcoin.conservative),
60
+ recommended: {
61
+ low: Number(data.bitcoin.recommended.low),
62
+ medium: Number(data.bitcoin.recommended.medium),
63
+ high: Number(data.bitcoin.recommended.high),
64
+ },
65
+ };
34
66
  }
35
67
  }
@@ -18,6 +18,7 @@ import { IAccessList } from './interfaces/IAccessList.js';
18
18
  import { EventList, ICallResultData, RawEventList } from './interfaces/ICallResult.js';
19
19
  import { OPNetEvent } from './OPNetEvent.js';
20
20
  import { TransactionHelper } from './TransactionHelpper.js';
21
+ import { BitcoinFees } from '../block/BlockGasParameters.js';
21
22
 
22
23
  const factory = new TransactionFactory();
23
24
 
@@ -73,6 +74,8 @@ export class CallResult<
73
74
  public to: string | undefined;
74
75
  public address: Address | undefined;
75
76
 
77
+ #bitcoinFees: BitcoinFees | undefined;
78
+
76
79
  readonly #rawEvents: EventList;
77
80
  readonly #provider: AbstractRpcProvider;
78
81
 
@@ -228,7 +231,7 @@ export class CallResult<
228
231
  calldata: this.calldata,
229
232
  priorityFee: priorityFee,
230
233
  gasSatFee: this.bigintMax(this.estimatedSatGas, interactionParams.minGas || 0n),
231
- feeRate: interactionParams.feeRate || 10,
234
+ feeRate: interactionParams.feeRate || this.#bitcoinFees?.conservative || 10,
232
235
  from: interactionParams.refundTo,
233
236
  utxos: UTXOs,
234
237
  to: this.to,
@@ -295,6 +298,10 @@ export class CallResult<
295
298
  this.estimatedRefundedGasInSat = refundedGas;
296
299
  }
297
300
 
301
+ public setBitcoinFee(fees: BitcoinFees): void {
302
+ this.#bitcoinFees = fees;
303
+ }
304
+
298
305
  public setDecoded(decoded: DecodedOutput): void {
299
306
  this.properties = Object.freeze(decoded.obj) as T;
300
307
  }
@@ -672,9 +672,7 @@ export abstract class IBaseContract<T extends BaseContractProperties> implements
672
672
  };
673
673
  }
674
674
 
675
- private async estimateGas(gas: bigint): Promise<bigint> {
676
- const gasParameters = await this.currentGasParameters();
677
-
675
+ private estimateGas(gas: bigint, gasParameters: BlockGasParameters): bigint {
678
676
  const gasPerSat = gasParameters.gasPerSat;
679
677
  const exactGas = (gas * gasPerSat) / 1000000000000n;
680
678
 
@@ -723,9 +721,11 @@ export abstract class IBaseContract<T extends BaseContractProperties> implements
723
721
  response.setDecoded(decoded);
724
722
  response.setCalldata(buffer);
725
723
 
726
- const gas = await this.estimateGas(response.estimatedGas || 0n);
727
- const gasRefunded = await this.estimateGas(response.refundedGas || 0n);
724
+ const gasParameters = await this.currentGasParameters();
725
+ const gas = this.estimateGas(response.estimatedGas || 0n, gasParameters);
726
+ const gasRefunded = this.estimateGas(response.refundedGas || 0n, gasParameters);
728
727
 
728
+ response.setBitcoinFee(gasParameters.bitcoin);
729
729
  response.setGasEstimation(gas, gasRefunded);
730
730
  response.setEvents(this.decodeEvents(response.rawEvents));
731
731
 
@@ -79,6 +79,11 @@ export abstract class TransactionBase<T extends OPNetTransactionTypes>
79
79
  */
80
80
  public readonly pow?: ProofOfWorkChallenge;
81
81
 
82
+ /**
83
+ * @description The block number in which the transaction was included.
84
+ */
85
+ public readonly blockNumber?: bigint;
86
+
82
87
  protected constructor(transaction: ITransactionBase<T>, network: Network) {
83
88
  super(
84
89
  {
@@ -96,6 +101,8 @@ export abstract class TransactionBase<T extends OPNetTransactionTypes>
96
101
  this.hash = transaction.hash;
97
102
  this.index = transaction.index;
98
103
 
104
+ if (transaction.blockNumber) this.blockNumber = BigInt(transaction.blockNumber);
105
+
99
106
  this.burnedBitcoin = BigInt(transaction.burnedBitcoin) || 0n;
100
107
  this.priorityFee = BigInt(transaction.priorityFee) || 0n;
101
108
 
@@ -19,6 +19,11 @@ export interface ITransactionBase<T extends OPNetTransactionTypes> extends ITran
19
19
  */
20
20
  readonly id: string;
21
21
 
22
+ /**
23
+ * @description The block number in which the transaction was included.
24
+ */
25
+ readonly blockNumber?: string | bigint;
26
+
22
27
  /**
23
28
  * @description The transaction "hash".
24
29
  */