opnet 1.2.10 → 1.2.13

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.
@@ -27,6 +27,8 @@ export declare abstract class AbstractRpcProvider {
27
27
  private chainId;
28
28
  protected constructor(network: Network);
29
29
  private _utxoManager;
30
+ private gasCache;
31
+ private lastFetchedGas;
30
32
  get utxoManager(): UTXOsManager;
31
33
  getPublicKeyInfo(address: string): Promise<Address>;
32
34
  validateAddress(addr: string | Address, network: Network): AddressTypes | null;
@@ -43,6 +45,7 @@ export declare abstract class AbstractRpcProvider {
43
45
  getStorageAt(address: string | Address, rawPointer: bigint | string, proofs?: boolean, height?: BigNumberish): Promise<StoredValue>;
44
46
  call(to: string | Address, data: Buffer | string, from?: Address, height?: BigNumberish, simulatedTransaction?: ParsedSimulatedTransaction, accessList?: IAccessList): Promise<CallResult | ICallRequestError>;
45
47
  gasParameters(): Promise<BlockGasParameters>;
48
+ private _gasParameters;
46
49
  sendRawTransaction(tx: string, psbt: boolean): Promise<BroadcastedTransaction>;
47
50
  getBlockWitness(height?: BigNumberish, trusted?: boolean, limit?: number, page?: number): Promise<BlockWitnesses>;
48
51
  getReorg(fromBlock?: BigNumberish, toBlock?: BigNumberish): Promise<ReorgInformation[]>;
@@ -1 +1 @@
1
- export declare const version = "1.2.10";
1
+ export declare const version = "1.2.13";
package/build/_version.js CHANGED
@@ -1 +1 @@
1
- export const version = '1.2.10';
1
+ export const version = '1.2.13';
@@ -2,7 +2,7 @@ import { Address } from '@btc-vision/transaction';
2
2
  import { CallResult } from '../../../../contracts/CallResult.js';
3
3
  import { IOP_NETContract } from '../opnet/IOP_NETContract.js';
4
4
  export type ReserveNativeSwap = CallResult<{
5
- reserved: bigint;
5
+ ok: boolean;
6
6
  }>;
7
7
  export type AddLiquidity = CallResult<{
8
8
  ok: boolean;
@@ -14,7 +14,7 @@ export type ListLiquidity = CallResult<{
14
14
  ok: boolean;
15
15
  }>;
16
16
  export type CancelListing = CallResult<{
17
- totalTokensReturned: bigint;
17
+ ok: boolean;
18
18
  }>;
19
19
  export type CreatePool = CallResult<{
20
20
  ok: boolean;
@@ -140,8 +140,8 @@ export const NativeSwapAbi = [
140
140
  ],
141
141
  outputs: [
142
142
  {
143
- name: 'reserved',
144
- type: ABIDataTypes.UINT256,
143
+ name: 'ok',
144
+ type: ABIDataTypes.BOOL,
145
145
  },
146
146
  ],
147
147
  type: BitcoinAbiTypes.Function,
@@ -184,8 +184,8 @@ export const NativeSwapAbi = [
184
184
  ],
185
185
  outputs: [
186
186
  {
187
- name: 'totalTokensReturned',
188
- type: ABIDataTypes.UINT128,
187
+ name: 'ok',
188
+ type: ABIDataTypes.BOOL,
189
189
  },
190
190
  ],
191
191
  type: BitcoinAbiTypes.Function,
@@ -27,6 +27,8 @@ export declare abstract class AbstractRpcProvider {
27
27
  private chainId;
28
28
  protected constructor(network: Network);
29
29
  private _utxoManager;
30
+ private gasCache;
31
+ private lastFetchedGas;
30
32
  get utxoManager(): UTXOsManager;
31
33
  getPublicKeyInfo(address: string): Promise<Address>;
32
34
  validateAddress(addr: string | Address, network: Network): AddressTypes | null;
@@ -43,6 +45,7 @@ export declare abstract class AbstractRpcProvider {
43
45
  getStorageAt(address: string | Address, rawPointer: bigint | string, proofs?: boolean, height?: BigNumberish): Promise<StoredValue>;
44
46
  call(to: string | Address, data: Buffer | string, from?: Address, height?: BigNumberish, simulatedTransaction?: ParsedSimulatedTransaction, accessList?: IAccessList): Promise<CallResult | ICallRequestError>;
45
47
  gasParameters(): Promise<BlockGasParameters>;
48
+ private _gasParameters;
46
49
  sendRawTransaction(tx: string, psbt: boolean): Promise<BroadcastedTransaction>;
47
50
  getBlockWitness(height?: BigNumberish, trusted?: boolean, limit?: number, page?: number): Promise<BlockWitnesses>;
48
51
  getReorg(fromBlock?: BigNumberish, toBlock?: BigNumberish): Promise<ReorgInformation[]>;
@@ -17,6 +17,8 @@ export class AbstractRpcProvider {
17
17
  this.network = network;
18
18
  }
19
19
  _utxoManager = new UTXOsManager(this);
20
+ gasCache;
21
+ lastFetchedGas = 0;
20
22
  get utxoManager() {
21
23
  return this._utxoManager;
22
24
  }
@@ -181,9 +183,15 @@ export class AbstractRpcProvider {
181
183
  if (simulatedTransaction) {
182
184
  params.push(this.parseSimulatedTransaction(simulatedTransaction));
183
185
  }
186
+ else {
187
+ params.push(undefined);
188
+ }
184
189
  if (accessList) {
185
190
  params.push(accessList);
186
191
  }
192
+ else {
193
+ params.push(undefined);
194
+ }
187
195
  const payload = this.buildJsonRpcPayload(JSONRpcMethods.CALL, params);
188
196
  const rawCall = await this.callPayloadSingle(payload);
189
197
  const result = rawCall.result || rawCall;
@@ -203,6 +211,13 @@ export class AbstractRpcProvider {
203
211
  return new CallResult(result, this);
204
212
  }
205
213
  async gasParameters() {
214
+ if (!this.gasCache || Date.now() - this.lastFetchedGas > 10000) {
215
+ this.lastFetchedGas = Date.now();
216
+ this.gasCache = await this._gasParameters();
217
+ }
218
+ return this.gasCache;
219
+ }
220
+ async _gasParameters() {
206
221
  const payload = this.buildJsonRpcPayload(JSONRpcMethods.GAS, []);
207
222
  const rawCall = await this.callPayloadSingle(payload);
208
223
  if ('error' in rawCall) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "opnet",
3
3
  "type": "module",
4
- "version": "1.2.10",
4
+ "version": "1.2.13",
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.2.10';
1
+ export const version = '1.2.13';
@@ -6,7 +6,7 @@ import { IOP_NETContract } from '../opnet/IOP_NETContract.js';
6
6
  * @description Represents the result of the reserve function call.
7
7
  */
8
8
  export type ReserveNativeSwap = CallResult<{
9
- reserved: bigint;
9
+ ok: boolean;
10
10
  }>;
11
11
 
12
12
  /**
@@ -34,7 +34,7 @@ export type ListLiquidity = CallResult<{
34
34
  * @description Represents the result of canceling a listing (new).
35
35
  */
36
36
  export type CancelListing = CallResult<{
37
- totalTokensReturned: bigint;
37
+ ok: boolean;
38
38
  }>;
39
39
 
40
40
  /**
@@ -152,8 +152,8 @@ export const NativeSwapAbi: BitcoinInterfaceAbi = [
152
152
  ],
153
153
  outputs: [
154
154
  {
155
- name: 'reserved',
156
- type: ABIDataTypes.UINT256,
155
+ name: 'ok',
156
+ type: ABIDataTypes.BOOL,
157
157
  },
158
158
  ],
159
159
  type: BitcoinAbiTypes.Function,
@@ -204,8 +204,8 @@ export const NativeSwapAbi: BitcoinInterfaceAbi = [
204
204
  ],
205
205
  outputs: [
206
206
  {
207
- name: 'totalTokensReturned',
208
- type: ABIDataTypes.UINT128,
207
+ name: 'ok',
208
+ type: ABIDataTypes.BOOL,
209
209
  },
210
210
  ],
211
211
  type: BitcoinAbiTypes.Function,
@@ -50,6 +50,9 @@ export abstract class AbstractRpcProvider {
50
50
 
51
51
  private _utxoManager: UTXOsManager = new UTXOsManager(this);
52
52
 
53
+ private gasCache: BlockGasParameters | undefined;
54
+ private lastFetchedGas: number = 0;
55
+
53
56
  /**
54
57
  * Get the UTXO manager.
55
58
  */
@@ -399,6 +402,7 @@ export abstract class AbstractRpcProvider {
399
402
  toStr,
400
403
  dataStr,
401
404
  ];
405
+
402
406
  if (fromStr) {
403
407
  params.push(fromStr);
404
408
  }
@@ -411,10 +415,14 @@ export abstract class AbstractRpcProvider {
411
415
 
412
416
  if (simulatedTransaction) {
413
417
  params.push(this.parseSimulatedTransaction(simulatedTransaction));
418
+ } else {
419
+ params.push(undefined);
414
420
  }
415
421
 
416
422
  if (accessList) {
417
423
  params.push(accessList);
424
+ } else {
425
+ params.push(undefined);
418
426
  }
419
427
 
420
428
  const payload: JsonRpcPayload = this.buildJsonRpcPayload(JSONRpcMethods.CALL, params);
@@ -448,6 +456,15 @@ export abstract class AbstractRpcProvider {
448
456
  * @throws {Error} If something went wrong while calling the contract
449
457
  */
450
458
  public async gasParameters(): Promise<BlockGasParameters> {
459
+ if (!this.gasCache || Date.now() - this.lastFetchedGas > 10000) {
460
+ this.lastFetchedGas = Date.now();
461
+ this.gasCache = await this._gasParameters();
462
+ }
463
+
464
+ return this.gasCache;
465
+ }
466
+
467
+ private async _gasParameters(): Promise<BlockGasParameters> {
451
468
  const payload: JsonRpcPayload = this.buildJsonRpcPayload(JSONRpcMethods.GAS, []);
452
469
  const rawCall: JsonRpcResult = await this.callPayloadSingle(payload);
453
470