opnet 1.2.2 → 1.2.4

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.
Files changed (82) hide show
  1. package/browser/_version.d.ts +1 -1
  2. package/browser/abi/shared/interfaces/motoswap/INativeSwapContract.d.ts +71 -0
  3. package/browser/abi/shared/json/motoswap/NATIVE_SWAP_ABI.d.ts +3 -0
  4. package/browser/bitcoin/UTXOs.d.ts +1 -1
  5. package/browser/bitcoin/interfaces/IUTXO.d.ts +1 -1
  6. package/browser/block/Block.d.ts +2 -1
  7. package/browser/contracts/CallResult.d.ts +1 -0
  8. package/browser/index.js +1 -1
  9. package/browser/opnet.d.ts +3 -2
  10. package/browser/providers/AbstractRpcProvider.d.ts +1 -1
  11. package/browser/transactions/Transaction.d.ts +5 -1
  12. package/browser/transactions/TransactionParser.d.ts +3 -2
  13. package/browser/transactions/decoders/DeploymentTransaction.d.ts +2 -1
  14. package/browser/transactions/decoders/GenericTransaction.d.ts +2 -1
  15. package/browser/transactions/decoders/InteractionTransaction.d.ts +2 -1
  16. package/browser/transactions/interfaces/ITransaction.d.ts +2 -0
  17. package/browser/transactions/interfaces/ProofOfWorkChallenge.d.ts +12 -0
  18. package/browser/transactions/interfaces/transactions/ICommonTransaction.d.ts +2 -0
  19. package/browser/transactions/metadata/TransactionInput.d.ts +1 -1
  20. package/browser/transactions/metadata/TransactionOutput.d.ts +1 -1
  21. package/browser/transactions/metadata/TransactionReceipt.d.ts +2 -1
  22. package/build/_version.d.ts +1 -1
  23. package/build/_version.js +1 -1
  24. package/build/abi/shared/interfaces/motoswap/INativeSwapContract.d.ts +71 -0
  25. package/build/abi/shared/json/motoswap/NATIVE_SWAP_ABI.d.ts +3 -0
  26. package/build/abi/shared/json/motoswap/{EWMA_ABI.js → NATIVE_SWAP_ABI.js} +208 -37
  27. package/build/bitcoin/UTXOs.d.ts +1 -1
  28. package/build/bitcoin/interfaces/IUTXO.d.ts +1 -1
  29. package/build/block/Block.d.ts +2 -1
  30. package/build/block/Block.js +2 -2
  31. package/build/contracts/CallResult.d.ts +1 -0
  32. package/build/contracts/CallResult.js +7 -3
  33. package/build/opnet.d.ts +3 -2
  34. package/build/opnet.js +3 -2
  35. package/build/providers/AbstractRpcProvider.d.ts +1 -1
  36. package/build/providers/AbstractRpcProvider.js +4 -4
  37. package/build/transactions/Transaction.d.ts +5 -1
  38. package/build/transactions/Transaction.js +14 -2
  39. package/build/transactions/TransactionParser.d.ts +3 -2
  40. package/build/transactions/TransactionParser.js +6 -6
  41. package/build/transactions/decoders/DeploymentTransaction.d.ts +2 -1
  42. package/build/transactions/decoders/DeploymentTransaction.js +2 -2
  43. package/build/transactions/decoders/GenericTransaction.d.ts +2 -1
  44. package/build/transactions/decoders/GenericTransaction.js +2 -2
  45. package/build/transactions/decoders/InteractionTransaction.d.ts +2 -1
  46. package/build/transactions/decoders/InteractionTransaction.js +2 -2
  47. package/build/transactions/interfaces/ITransaction.d.ts +2 -0
  48. package/build/transactions/interfaces/ProofOfWorkChallenge.d.ts +12 -0
  49. package/build/transactions/interfaces/ProofOfWorkChallenge.js +1 -0
  50. package/build/transactions/interfaces/transactions/ICommonTransaction.d.ts +2 -0
  51. package/build/transactions/metadata/TransactionInput.d.ts +1 -1
  52. package/build/transactions/metadata/TransactionOutput.d.ts +1 -1
  53. package/build/transactions/metadata/TransactionReceipt.d.ts +2 -1
  54. package/build/transactions/metadata/TransactionReceipt.js +12 -8
  55. package/package.json +14 -14
  56. package/src/_version.ts +1 -1
  57. package/src/abi/shared/interfaces/motoswap/INativeSwapContract.ts +267 -0
  58. package/src/abi/shared/json/motoswap/{EWMA_ABI.ts → NATIVE_SWAP_ABI.ts} +252 -37
  59. package/src/bitcoin/UTXOs.ts +2 -2
  60. package/src/bitcoin/interfaces/IUTXO.ts +1 -1
  61. package/src/block/Block.ts +3 -1
  62. package/src/contracts/CallResult.ts +9 -6
  63. package/src/opnet.ts +3 -2
  64. package/src/providers/AbstractRpcProvider.ts +5 -5
  65. package/src/providers/JSONRpcProvider.ts +1 -1
  66. package/src/transactions/Transaction.ts +30 -8
  67. package/src/transactions/TransactionParser.ts +7 -8
  68. package/src/transactions/decoders/DeploymentTransaction.ts +3 -2
  69. package/src/transactions/decoders/GenericTransaction.ts +3 -2
  70. package/src/transactions/decoders/InteractionTransaction.ts +3 -2
  71. package/src/transactions/interfaces/ITransaction.ts +6 -0
  72. package/src/transactions/interfaces/ProofOfWorkChallenge.ts +13 -0
  73. package/src/transactions/interfaces/transactions/ICommonTransaction.ts +6 -0
  74. package/src/transactions/metadata/TransactionInput.ts +1 -1
  75. package/src/transactions/metadata/TransactionOutput.ts +1 -1
  76. package/src/transactions/metadata/TransactionReceipt.ts +23 -11
  77. package/browser/abi/shared/interfaces/motoswap/IEwmaContract.d.ts +0 -46
  78. package/browser/abi/shared/json/motoswap/EWMA_ABI.d.ts +0 -3
  79. package/build/abi/shared/interfaces/motoswap/IEwmaContract.d.ts +0 -46
  80. package/build/abi/shared/json/motoswap/EWMA_ABI.d.ts +0 -3
  81. package/src/abi/shared/interfaces/motoswap/IEwmaContract.ts +0 -188
  82. /package/build/abi/shared/interfaces/motoswap/{IEwmaContract.js → INativeSwapContract.js} +0 -0
@@ -1,4 +1,4 @@
1
- import { ScriptPubKey } from '@btc-vision/bsi-bitcoin-rpc';
1
+ import { ScriptPubKey } from '@btc-vision/bitcoin-rpc';
2
2
  import { IUTXO } from './interfaces/IUTXO.js';
3
3
 
4
4
  /**
@@ -22,7 +22,7 @@ export class UTXO implements Omit<IUTXO, 'raw'> {
22
22
  if (!iUTXO.raw) {
23
23
  throw new Error('Missing nonWitnessUtxo field in UTXO');
24
24
  }
25
-
25
+
26
26
  this.nonWitnessUtxo = Buffer.from(iUTXO.raw, 'base64');
27
27
  }
28
28
  }
@@ -1,4 +1,4 @@
1
- import { ScriptPubKey } from '@btc-vision/bsi-bitcoin-rpc';
1
+ import { ScriptPubKey } from '@btc-vision/bitcoin-rpc';
2
2
 
3
3
  /**
4
4
  * Unspent Transaction Output
@@ -1,3 +1,4 @@
1
+ import { Network } from '@btc-vision/bitcoin';
1
2
  import { BigNumberish } from '../common/CommonTypes.js';
2
3
  import { OPNetTransactionTypes } from '../interfaces/opnet/OPNetTransactionTypes.js';
3
4
  import { ITransaction } from '../transactions/interfaces/ITransaction.js';
@@ -42,7 +43,7 @@ export class Block implements Omit<IBlock, 'gasUsed' | 'ema' | 'baseGas'> {
42
43
 
43
44
  public readonly transactions: TransactionBase<OPNetTransactionTypes>[] = [];
44
45
 
45
- constructor(block: IBlock) {
46
+ constructor(block: IBlock, network: Network) {
46
47
  this.height = BigInt(block.height.toString());
47
48
 
48
49
  this.hash = block.hash;
@@ -74,6 +75,7 @@ export class Block implements Omit<IBlock, 'gasUsed' | 'ema' | 'baseGas'> {
74
75
 
75
76
  this.transactions = TransactionParser.parseTransactions(
76
77
  block.transactions as ITransaction[],
78
+ network
77
79
  );
78
80
  }
79
81
  }
@@ -1,5 +1,6 @@
1
1
  import { Network, PsbtOutputExtended, Signer } from '@btc-vision/bitcoin';
2
2
  import {
3
+ Address,
3
4
  BinaryReader,
4
5
  BufferHelper,
5
6
  IInteractionParameters,
@@ -59,12 +60,10 @@ export class CallResult<T extends ContractDecodedObjectResult = {}>
59
60
  readonly #rawEvents: EventList;
60
61
  readonly #provider: AbstractRpcProvider;
61
62
 
62
- //private readonly decoded: Array<DecodedCallResult> = [];
63
-
64
63
  constructor(callResult: ICallResultData, provider: AbstractRpcProvider) {
64
+ this.#provider = provider;
65
65
  this.#rawEvents = this.parseEvents(callResult.events);
66
66
  this.accessList = callResult.accessList;
67
- this.#provider = provider;
68
67
 
69
68
  if (callResult.estimatedGas) {
70
69
  this.estimatedGas = BigInt(callResult.estimatedGas);
@@ -167,8 +166,6 @@ export class CallResult<T extends ContractDecodedObjectResult = {}>
167
166
 
168
167
  public setDecoded(decoded: DecodedOutput): void {
169
168
  this.properties = Object.freeze(decoded.obj) as T;
170
-
171
- //this.decoded.push(...decoded.values);
172
169
  }
173
170
 
174
171
  public setCalldata(calldata: Buffer): void {
@@ -194,6 +191,12 @@ export class CallResult<T extends ContractDecodedObjectResult = {}>
194
191
  return utxos;
195
192
  }
196
193
 
194
+ private contractToString(contract: string): string {
195
+ const addressCa = Address.fromString(contract);
196
+
197
+ return addressCa.p2tr(this.#provider.network);
198
+ }
199
+
197
200
  private parseEvents(events: RawEventList): EventList {
198
201
  const eventsList: EventList = {};
199
202
 
@@ -206,7 +209,7 @@ export class CallResult<T extends ContractDecodedObjectResult = {}>
206
209
  events.push(eventData);
207
210
  }
208
211
 
209
- eventsList[contract] = events;
212
+ eventsList[this.contractToString(contract)] = events;
210
213
  }
211
214
 
212
215
  return eventsList;
package/src/opnet.ts CHANGED
@@ -15,6 +15,7 @@ export * from './transactions/Transaction.js';
15
15
  export * from './transactions/interfaces/transactions/ICommonTransaction.js';
16
16
  export * from './transactions/interfaces/transactions/IDeploymentTransaction.js';
17
17
  export * from './transactions/interfaces/transactions/IInteractionTransaction.js';
18
+ export * from './transactions/interfaces/ProofOfWorkChallenge.js';
18
19
 
19
20
  /** Providers */
20
21
  export * from './providers/AbstractRpcProvider.js';
@@ -93,7 +94,7 @@ export * from './abi/shared/json/opnet/OP_20_ABI.js';
93
94
  export * from './abi/shared/json/opnet/OP_NET_ABI.js';
94
95
  export * from './abi/shared/json/generic/STAKING_ABI.js';
95
96
  export * from './abi/shared/json/tests/WBTC_ABI.js';
96
- export * from './abi/shared/json/motoswap/EWMA_ABI.js';
97
+ export * from './abi/shared/json/motoswap/NATIVE_SWAP_ABI.js';
97
98
 
98
99
  /** ABI Interfaces */
99
100
  export * from './abi/shared/interfaces/motoswap/IMotoswapFactoryContract.js';
@@ -105,4 +106,4 @@ export * from './abi/shared/interfaces/opnet/IOP_20Contract.js';
105
106
  export * from './abi/shared/interfaces/opnet/IOP_NETContract.js';
106
107
  export * from './abi/shared/interfaces/generic/IStackingContract.js';
107
108
  export * from './abi/shared/interfaces/tests/IWBTCContract.js';
108
- export * from './abi/shared/interfaces/motoswap/IEwmaContract.js';
109
+ export * from './abi/shared/interfaces/motoswap/INativeSwapContract.js';
@@ -42,7 +42,7 @@ export abstract class AbstractRpcProvider {
42
42
  private nextId: number = 0;
43
43
  private chainId: bigint | undefined;
44
44
 
45
- protected constructor(private readonly network: Network) {}
45
+ protected constructor(public readonly network: Network) {}
46
46
 
47
47
  private _utxoManager: UTXOsManager = new UTXOsManager(this);
48
48
 
@@ -139,7 +139,7 @@ export abstract class AbstractRpcProvider {
139
139
  const block: JsonRpcResult = await this.callPayloadSingle(payload);
140
140
 
141
141
  const result: IBlock = block.result as IBlock;
142
- return new Block(result);
142
+ return new Block(result, this.network);
143
143
  }
144
144
 
145
145
  /**
@@ -174,7 +174,7 @@ export abstract class AbstractRpcProvider {
174
174
 
175
175
  const result: IBlock = block.result as IBlock;
176
176
 
177
- return new Block(result);
177
+ return new Block(result, this.network);
178
178
  });
179
179
  }
180
180
 
@@ -236,7 +236,7 @@ export abstract class AbstractRpcProvider {
236
236
  );
237
237
  }
238
238
 
239
- return TransactionParser.parseTransaction(result);
239
+ return TransactionParser.parseTransaction(result, this.network);
240
240
  }
241
241
 
242
242
  /**
@@ -254,7 +254,7 @@ export abstract class AbstractRpcProvider {
254
254
  );
255
255
 
256
256
  const rawTransaction: JsonRpcResult = await this.callPayloadSingle(payload);
257
- return new TransactionReceipt(rawTransaction.result);
257
+ return new TransactionReceipt(rawTransaction.result, this.network);
258
258
  }
259
259
 
260
260
  /**
@@ -49,7 +49,7 @@ export class JSONRpcProvider extends AbstractRpcProvider {
49
49
  if (!resp.ok) {
50
50
  throw new Error(`Failed to fetch: ${resp.statusText}`);
51
51
  }
52
-
52
+
53
53
  clearTimeout(timeoutId);
54
54
 
55
55
  //const str = await resp.text();
@@ -1,6 +1,8 @@
1
+ import { Network } from '@btc-vision/bitcoin';
1
2
  import { BigNumberish } from '../common/CommonTypes.js';
2
3
  import { OPNetTransactionTypes } from '../interfaces/opnet/OPNetTransactionTypes.js';
3
4
  import { ITransactionBase } from './interfaces/ITransaction.js';
5
+ import { ProofOfWorkChallenge, RawProofOfWorkChallenge } from './interfaces/ProofOfWorkChallenge.js';
4
6
  import { TransactionInput } from './metadata/TransactionInput.js';
5
7
  import { ITransactionOutput, TransactionOutput } from './metadata/TransactionOutput.js';
6
8
  import { TransactionReceipt } from './metadata/TransactionReceipt.js';
@@ -57,13 +59,21 @@ export abstract class TransactionBase<T extends OPNetTransactionTypes>
57
59
  */
58
60
  public readonly gasUsed: bigint;
59
61
 
60
- protected constructor(transaction: ITransactionBase<T>) {
61
- super({
62
- receipt: transaction.receipt,
63
- receiptProofs: transaction.receiptProofs,
64
- events: transaction.events,
65
- revert: transaction.revert,
66
- });
62
+ /**
63
+ * @description The proof of work challenge.
64
+ */
65
+ public readonly pow?: ProofOfWorkChallenge;
66
+
67
+ protected constructor(transaction: ITransactionBase<T>, network: Network) {
68
+ super(
69
+ {
70
+ receipt: transaction.receipt,
71
+ receiptProofs: transaction.receiptProofs,
72
+ events: transaction.events,
73
+ revert: transaction.revert,
74
+ },
75
+ network,
76
+ );
67
77
 
68
78
  this.id = transaction.id;
69
79
  this.hash = transaction.hash;
@@ -77,7 +87,19 @@ export abstract class TransactionBase<T extends OPNetTransactionTypes>
77
87
  );
78
88
 
79
89
  this.OPNetType = transaction.OPNetType;
80
-
81
90
  this.gasUsed = BigInt(transaction.gasUsed || '0x00') || 0n;
91
+
92
+ if (transaction.pow) {
93
+ this.pow = this.decodeProofOfWorkChallenge(transaction.pow as RawProofOfWorkChallenge);
94
+ }
95
+ }
96
+
97
+ private decodeProofOfWorkChallenge(challenge: RawProofOfWorkChallenge): ProofOfWorkChallenge {
98
+ return {
99
+ preimage: Buffer.from(challenge.preimage, 'base64'),
100
+ reward: BigInt(challenge.reward) || 0n,
101
+ difficulty: BigInt(challenge.difficulty || '0'),
102
+ version: challenge.version || 0,
103
+ };
82
104
  }
83
105
  }
@@ -1,3 +1,4 @@
1
+ import { Network } from '@btc-vision/bitcoin';
1
2
  import { OPNetTransactionTypes } from '../interfaces/opnet/OPNetTransactionTypes.js';
2
3
  import { DeploymentTransaction } from './decoders/DeploymentTransaction.js';
3
4
  import { GenericTransaction } from './decoders/GenericTransaction.js';
@@ -14,6 +15,7 @@ import { TransactionBase } from './Transaction.js';
14
15
  export class TransactionParser {
15
16
  public static parseTransactions(
16
17
  transactions: ITransaction[],
18
+ network: Network,
17
19
  ): TransactionBase<OPNetTransactionTypes>[] {
18
20
  if (!transactions) {
19
21
  return [];
@@ -23,7 +25,7 @@ export class TransactionParser {
23
25
  for (const transaction of transactions) {
24
26
  if (!transaction) throw new Error(`Something went wrong while parsing transactions`);
25
27
 
26
- transactionArray.push(this.parseTransaction(transaction));
28
+ transactionArray.push(this.parseTransaction(transaction, network));
27
29
  }
28
30
 
29
31
  return transactionArray;
@@ -31,6 +33,7 @@ export class TransactionParser {
31
33
 
32
34
  public static parseTransaction(
33
35
  transaction: ITransaction,
36
+ network: Network,
34
37
  ): TransactionBase<OPNetTransactionTypes> {
35
38
  if (!transaction) throw new Error('Transaction is required');
36
39
 
@@ -38,15 +41,11 @@ export class TransactionParser {
38
41
 
39
42
  switch (opnetType) {
40
43
  case OPNetTransactionTypes.Generic:
41
- return new GenericTransaction(transaction as IGenericTransaction);
44
+ return new GenericTransaction(transaction as IGenericTransaction, network);
42
45
  case OPNetTransactionTypes.Interaction:
43
- return new InteractionTransaction(transaction as IInteractionTransaction);
46
+ return new InteractionTransaction(transaction as IInteractionTransaction, network);
44
47
  case OPNetTransactionTypes.Deployment:
45
- return new DeploymentTransaction(transaction as IDeploymentTransaction);
46
- //case OPNetTransactionTypes.WrapInteraction:
47
- // return new WrapTransaction(transaction as IWrapTransaction);
48
- //case OPNetTransactionTypes.UnwrapInteraction:
49
- // return new UnwrapTransaction(transaction as IUnwrapTransaction);
48
+ return new DeploymentTransaction(transaction as IDeploymentTransaction, network);
50
49
  default:
51
50
  throw new Error('Unknown transaction type');
52
51
  }
@@ -1,3 +1,4 @@
1
+ import { Network } from '@btc-vision/bitcoin';
1
2
  import { Address } from '@btc-vision/transaction';
2
3
  import { OPNetTransactionTypes } from '../../interfaces/opnet/OPNetTransactionTypes.js';
3
4
  import { IDeploymentTransaction } from '../interfaces/transactions/IDeploymentTransaction.js';
@@ -26,8 +27,8 @@ export class DeploymentTransaction
26
27
 
27
28
  public readonly from?: Address;
28
29
 
29
- constructor(transaction: IDeploymentTransaction) {
30
- super(transaction);
30
+ constructor(transaction: IDeploymentTransaction, network: Network) {
31
+ super(transaction, network);
31
32
 
32
33
  try {
33
34
  this.from = new Address(Buffer.from(transaction.from as string, 'base64'));
@@ -1,3 +1,4 @@
1
+ import { Network } from '@btc-vision/bitcoin';
1
2
  import { OPNetTransactionTypes } from '../../interfaces/opnet/OPNetTransactionTypes.js';
2
3
  import { IGenericTransaction } from '../interfaces/ITransaction.js';
3
4
  import { TransactionBase } from '../Transaction.js';
@@ -13,7 +14,7 @@ export class GenericTransaction
13
14
  extends TransactionBase<OPNetTransactionTypes.Generic>
14
15
  implements IGenericTransaction
15
16
  {
16
- public constructor(transaction: IGenericTransaction) {
17
- super(transaction);
17
+ public constructor(transaction: IGenericTransaction, network: Network) {
18
+ super(transaction, network);
18
19
  }
19
20
  }
@@ -1,3 +1,4 @@
1
+ import { Network } from '@btc-vision/bitcoin';
1
2
  import { Address } from '@btc-vision/transaction';
2
3
  import { Buffer } from 'buffer';
3
4
  import { InteractionType } from '../../interfaces/opnet/OPNetTransactionTypes.js';
@@ -52,8 +53,8 @@ export class InteractionTransaction
52
53
  */
53
54
  public readonly contractTweakedPublicKey: Address;
54
55
 
55
- constructor(transaction: IInteractionTransaction) {
56
- super(transaction);
56
+ constructor(transaction: IInteractionTransaction, network: Network) {
57
+ super(transaction, network);
57
58
 
58
59
  this.contractTweakedPublicKey = new Address(
59
60
  Buffer.from(transaction.contractTweakedPublicKey as string, 'base64'),
@@ -3,6 +3,7 @@ import { OPNetTransactionTypes } from '../../interfaces/opnet/OPNetTransactionTy
3
3
  import { ITransactionInput, TransactionInput } from '../metadata/TransactionInput.js';
4
4
  import { ITransactionOutput, TransactionOutput } from '../metadata/TransactionOutput.js';
5
5
  import { ITransactionReceipt } from './ITransactionReceipt.js';
6
+ import { ProofOfWorkChallenge, RawProofOfWorkChallenge } from './ProofOfWorkChallenge.js';
6
7
  import { IDeploymentTransaction } from './transactions/IDeploymentTransaction.js';
7
8
  import { IInteractionTransaction } from './transactions/IInteractionTransaction.js';
8
9
 
@@ -57,6 +58,11 @@ export interface ITransactionBase<T extends OPNetTransactionTypes> extends ITran
57
58
  * @description The amount of gas used by the transaction.
58
59
  */
59
60
  readonly gasUsed: string | bigint;
61
+
62
+ /**
63
+ * @description The raw proof of work challenge.
64
+ */
65
+ readonly pow?: RawProofOfWorkChallenge | ProofOfWorkChallenge;
60
66
  }
61
67
 
62
68
  /**
@@ -0,0 +1,13 @@
1
+ export interface ProofOfWorkChallenge {
2
+ readonly preimage: Buffer;
3
+ readonly reward: bigint;
4
+ readonly difficulty?: bigint;
5
+ readonly version?: number;
6
+ }
7
+
8
+ export interface RawProofOfWorkChallenge {
9
+ readonly preimage: string;
10
+ readonly reward: string;
11
+ readonly difficulty?: string;
12
+ readonly version?: number;
13
+ }
@@ -1,6 +1,7 @@
1
1
  import { Address } from '@btc-vision/transaction';
2
2
  import { OPNetTransactionTypes } from '../../../interfaces/opnet/OPNetTransactionTypes.js';
3
3
  import { ITransactionBase } from '../ITransaction.js';
4
+ import { ProofOfWorkChallenge } from '../ProofOfWorkChallenge.js';
4
5
 
5
6
  export interface ICommonTransaction<T extends OPNetTransactionTypes> extends ITransactionBase<T> {
6
7
  /**
@@ -22,4 +23,9 @@ export interface ICommonTransaction<T extends OPNetTransactionTypes> extends ITr
22
23
  * @description Was the binary data compressed?
23
24
  */
24
25
  readonly wasCompressed?: boolean;
26
+
27
+ /**
28
+ * @description The proof of work challenge.
29
+ */
30
+ readonly pow?: ProofOfWorkChallenge;
25
31
  }
@@ -1,4 +1,4 @@
1
- import { ScriptSig } from '@btc-vision/bsi-bitcoin-rpc';
1
+ import { ScriptSig } from '@btc-vision/bitcoin-rpc';
2
2
 
3
3
  /**
4
4
  * Transaction input interface
@@ -1,5 +1,5 @@
1
1
  import { script } from '@btc-vision/bitcoin';
2
- import { ScriptPubKey } from '@btc-vision/bsi-bitcoin-rpc';
2
+ import { ScriptPubKey } from '@btc-vision/bitcoin-rpc';
3
3
 
4
4
  /**
5
5
  * Transaction output interface
@@ -1,4 +1,5 @@
1
- import { NetEvent } from '@btc-vision/transaction';
1
+ import { Network } from '@btc-vision/bitcoin';
2
+ import { Address, NetEvent } from '@btc-vision/transaction';
2
3
  import {
3
4
  ContractEvents,
4
5
  ITransactionReceipt,
@@ -31,41 +32,53 @@ export class TransactionReceipt implements ITransactionReceipt {
31
32
  */
32
33
  public readonly revert?: Buffer;
33
34
 
34
- constructor(receipt: ITransactionReceipt) {
35
+ constructor(receipt: ITransactionReceipt, network: Network) {
35
36
  this.receipt = receipt.receipt
36
37
  ? Buffer.from(receipt.receipt as string, 'base64')
37
38
  : undefined;
38
39
 
39
40
  this.receiptProofs = receipt.receiptProofs || [];
40
41
 
41
- this.events = receipt.events ? this.parseEvents(receipt.events) : {};
42
+ this.events = receipt.events ? this.parseEvents(receipt.events, network) : {};
42
43
  this.revert = receipt.revert ? Buffer.from(receipt.revert as string, 'base64') : undefined;
43
44
  }
44
45
 
45
46
  /**
46
47
  * @description Parse transaction events.
47
48
  * @param events - The events to parse.
49
+ * @param network - The network to use.
48
50
  * @private
49
51
  */
50
- private parseEvents(events: RawContractEvents | ContractEvents): ContractEvents {
52
+ private parseEvents(
53
+ events: RawContractEvents | ContractEvents,
54
+ network: Network,
55
+ ): ContractEvents {
51
56
  const parsedEvents: ContractEvents = {};
52
57
 
53
58
  if (!Array.isArray(events)) {
54
59
  for (const [key, value] of Object.entries(events)) {
55
- parsedEvents[key] = (value as NetEventDocument[]).map((event: NetEventDocument) => {
56
- return this.decodeEvent(event);
57
- });
60
+ const ca = Address.fromString(key);
61
+ const caP2tr = ca.p2tr(network);
62
+ parsedEvents[caP2tr] = (value as NetEventDocument[]).map(
63
+ (event: NetEventDocument) => {
64
+ return this.decodeEvent(event);
65
+ },
66
+ );
58
67
  }
59
68
  } else {
60
69
  for (const event of events) {
61
70
  const parsedEvent = this.decodeEvent(event);
62
71
  const contractAddress = event.contractAddress;
63
72
 
64
- if (!parsedEvents[contractAddress]) {
65
- parsedEvents[contractAddress] = [];
73
+ // TODO: Add a weak cache to avoid parsing the same address multiple times?
74
+ const ca = Address.fromString(contractAddress);
75
+ const caP2tr = ca.p2tr(network);
76
+
77
+ if (!parsedEvents[caP2tr]) {
78
+ parsedEvents[caP2tr] = [];
66
79
  }
67
80
 
68
- parsedEvents[contractAddress].push(parsedEvent);
81
+ parsedEvents[caP2tr].push(parsedEvent);
69
82
  }
70
83
  }
71
84
 
@@ -74,7 +87,6 @@ export class TransactionReceipt implements ITransactionReceipt {
74
87
 
75
88
  private decodeEvent(event: NetEventDocument): NetEvent {
76
89
  let eventData: Uint8Array;
77
-
78
90
  if (typeof event.data === 'string') {
79
91
  const buf = Buffer.from(event.data, 'base64');
80
92
  eventData = new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
@@ -1,46 +0,0 @@
1
- import { Address } from '@btc-vision/transaction';
2
- import { CallResult } from '../../../../contracts/CallResult.js';
3
- import { IOP_NETContract } from '../opnet/IOP_NETContract.js';
4
- export type ReserveEWMA = CallResult<{
5
- reserved: bigint;
6
- }>;
7
- export type AddLiquidity = CallResult<{
8
- ok: boolean;
9
- }>;
10
- export type RemoveLiquidity = CallResult<{
11
- totalTokensReturned: bigint;
12
- }>;
13
- export type Swap = CallResult<{
14
- ok: boolean;
15
- }>;
16
- export type GetReserve = CallResult<{
17
- liquidity: bigint;
18
- reservedLiquidity: bigint;
19
- }>;
20
- export type GetQuote = CallResult<{
21
- tokensOut: bigint;
22
- requiredSatoshis: bigint;
23
- currentPrice: bigint;
24
- }>;
25
- export type SetQuote = CallResult<{
26
- ok: boolean;
27
- }>;
28
- export type PriorityQueueCost = CallResult<{
29
- cost: bigint;
30
- }>;
31
- export type GetProviderDetails = CallResult<{
32
- liquidity: bigint;
33
- reserved: bigint;
34
- btcReceiver: string;
35
- }>;
36
- export interface IEwmaContract extends IOP_NETContract {
37
- reserve(token: Address, maximumAmountIn: bigint, minimumAmountOut: bigint): Promise<ReserveEWMA>;
38
- addLiquidity(token: Address, receiver: string, amountIn: bigint, priority: boolean): Promise<AddLiquidity>;
39
- removeLiquidity(token: Address): Promise<RemoveLiquidity>;
40
- swap(token: Address, isSimulation: boolean): Promise<Swap>;
41
- getReserve(token: Address): Promise<GetReserve>;
42
- getQuote(token: Address, satoshisIn: bigint): Promise<GetQuote>;
43
- setQuote(token: Address, p0: bigint): Promise<SetQuote>;
44
- priorityQueueCost(token: Address): Promise<PriorityQueueCost>;
45
- getProviderDetails(token: Address): Promise<GetProviderDetails>;
46
- }
@@ -1,3 +0,0 @@
1
- import { BitcoinInterfaceAbi } from '../../../interfaces/BitcoinInterfaceAbi.js';
2
- export declare const EwmaEvents: BitcoinInterfaceAbi;
3
- export declare const EwmaAbi: BitcoinInterfaceAbi;
@@ -1,46 +0,0 @@
1
- import { Address } from '@btc-vision/transaction';
2
- import { CallResult } from '../../../../contracts/CallResult.js';
3
- import { IOP_NETContract } from '../opnet/IOP_NETContract.js';
4
- export type ReserveEWMA = CallResult<{
5
- reserved: bigint;
6
- }>;
7
- export type AddLiquidity = CallResult<{
8
- ok: boolean;
9
- }>;
10
- export type RemoveLiquidity = CallResult<{
11
- totalTokensReturned: bigint;
12
- }>;
13
- export type Swap = CallResult<{
14
- ok: boolean;
15
- }>;
16
- export type GetReserve = CallResult<{
17
- liquidity: bigint;
18
- reservedLiquidity: bigint;
19
- }>;
20
- export type GetQuote = CallResult<{
21
- tokensOut: bigint;
22
- requiredSatoshis: bigint;
23
- currentPrice: bigint;
24
- }>;
25
- export type SetQuote = CallResult<{
26
- ok: boolean;
27
- }>;
28
- export type PriorityQueueCost = CallResult<{
29
- cost: bigint;
30
- }>;
31
- export type GetProviderDetails = CallResult<{
32
- liquidity: bigint;
33
- reserved: bigint;
34
- btcReceiver: string;
35
- }>;
36
- export interface IEwmaContract extends IOP_NETContract {
37
- reserve(token: Address, maximumAmountIn: bigint, minimumAmountOut: bigint): Promise<ReserveEWMA>;
38
- addLiquidity(token: Address, receiver: string, amountIn: bigint, priority: boolean): Promise<AddLiquidity>;
39
- removeLiquidity(token: Address): Promise<RemoveLiquidity>;
40
- swap(token: Address, isSimulation: boolean): Promise<Swap>;
41
- getReserve(token: Address): Promise<GetReserve>;
42
- getQuote(token: Address, satoshisIn: bigint): Promise<GetQuote>;
43
- setQuote(token: Address, p0: bigint): Promise<SetQuote>;
44
- priorityQueueCost(token: Address): Promise<PriorityQueueCost>;
45
- getProviderDetails(token: Address): Promise<GetProviderDetails>;
46
- }
@@ -1,3 +0,0 @@
1
- import { BitcoinInterfaceAbi } from '../../../interfaces/BitcoinInterfaceAbi.js';
2
- export declare const EwmaEvents: BitcoinInterfaceAbi;
3
- export declare const EwmaAbi: BitcoinInterfaceAbi;