opnet 1.2.1 → 1.2.3

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 (118) hide show
  1. package/browser/_version.d.ts +1 -1
  2. package/browser/abi/shared/interfaces/motoswap/IAdministeredOP20.d.ts +21 -0
  3. package/browser/abi/shared/interfaces/motoswap/IMotoChefContract.d.ts +121 -0
  4. package/browser/abi/shared/interfaces/motoswap/INativeSwapContract.d.ts +71 -0
  5. package/browser/abi/shared/interfaces/motoswap/IOwnableContract.d.ts +12 -0
  6. package/browser/abi/shared/interfaces/motoswap/IOwnableReentrancyGuardContract.d.ts +13 -0
  7. package/browser/abi/shared/interfaces/motoswap/IReentrancyGuardContract.d.ts +7 -0
  8. package/browser/abi/shared/json/motoswap/ADMINISTERD_OP_20_ABI.d.ts +3 -0
  9. package/browser/abi/shared/json/motoswap/MOTOSWAP_MOTOCHEF_ABI.d.ts +4 -0
  10. package/browser/abi/shared/json/motoswap/NATIVE_SWAP_ABI.d.ts +3 -0
  11. package/browser/abi/shared/json/motoswap/OWNABLE_ABI.d.ts +3 -0
  12. package/browser/abi/shared/json/motoswap/REENTRANCY_GUARD_ABI.d.ts +2 -0
  13. package/browser/bitcoin/UTXOs.d.ts +1 -1
  14. package/browser/bitcoin/interfaces/IUTXO.d.ts +1 -1
  15. package/browser/block/Block.d.ts +2 -1
  16. package/browser/contracts/CallResult.d.ts +1 -0
  17. package/browser/index.js +1 -1
  18. package/browser/opnet.d.ts +7 -2
  19. package/browser/providers/AbstractRpcProvider.d.ts +1 -1
  20. package/browser/transactions/Transaction.d.ts +5 -1
  21. package/browser/transactions/TransactionParser.d.ts +3 -2
  22. package/browser/transactions/decoders/DeploymentTransaction.d.ts +2 -1
  23. package/browser/transactions/decoders/GenericTransaction.d.ts +2 -1
  24. package/browser/transactions/decoders/InteractionTransaction.d.ts +2 -1
  25. package/browser/transactions/interfaces/ITransaction.d.ts +2 -0
  26. package/browser/transactions/interfaces/ProofOfWorkChallenge.d.ts +12 -0
  27. package/browser/transactions/interfaces/transactions/ICommonTransaction.d.ts +2 -0
  28. package/browser/transactions/metadata/TransactionInput.d.ts +1 -1
  29. package/browser/transactions/metadata/TransactionOutput.d.ts +1 -1
  30. package/browser/transactions/metadata/TransactionReceipt.d.ts +2 -1
  31. package/build/_version.d.ts +1 -1
  32. package/build/_version.js +1 -1
  33. package/build/abi/shared/interfaces/motoswap/IAdministeredOP20.d.ts +21 -0
  34. package/build/abi/shared/interfaces/motoswap/IMotoChefContract.d.ts +121 -0
  35. package/build/abi/shared/interfaces/motoswap/IMotoChefContract.js +1 -0
  36. package/build/abi/shared/interfaces/motoswap/INativeSwapContract.d.ts +71 -0
  37. package/build/abi/shared/interfaces/motoswap/INativeSwapContract.js +1 -0
  38. package/build/abi/shared/interfaces/motoswap/IOwnableContract.d.ts +12 -0
  39. package/build/abi/shared/interfaces/motoswap/IOwnableContract.js +1 -0
  40. package/build/abi/shared/interfaces/motoswap/IOwnableReentrancyGuardContract.d.ts +13 -0
  41. package/build/abi/shared/interfaces/motoswap/IOwnableReentrancyGuardContract.js +1 -0
  42. package/build/abi/shared/interfaces/motoswap/IReentrancyGuardContract.d.ts +7 -0
  43. package/build/abi/shared/interfaces/motoswap/IReentrancyGuardContract.js +1 -0
  44. package/build/abi/shared/json/motoswap/ADMINISTERD_OP_20_ABI.d.ts +3 -0
  45. package/build/abi/shared/json/motoswap/ADMINISTERD_OP_20_ABI.js +81 -0
  46. package/build/abi/shared/json/motoswap/MOTOSWAP_MOTOCHEF_ABI.d.ts +4 -0
  47. package/build/abi/shared/json/motoswap/MOTOSWAP_MOTOCHEF_ABI.js +443 -0
  48. package/build/abi/shared/json/motoswap/NATIVE_SWAP_ABI.d.ts +3 -0
  49. package/build/abi/shared/json/motoswap/{EWMA_ABI.js → NATIVE_SWAP_ABI.js} +208 -37
  50. package/build/abi/shared/json/motoswap/OWNABLE_ABI.d.ts +3 -0
  51. package/build/abi/shared/json/motoswap/OWNABLE_ABI.js +35 -0
  52. package/build/abi/shared/json/motoswap/REENTRANCY_GUARD_ABI.d.ts +2 -0
  53. package/build/abi/shared/json/motoswap/REENTRANCY_GUARD_ABI.js +15 -0
  54. package/build/bitcoin/UTXOs.d.ts +1 -1
  55. package/build/bitcoin/interfaces/IUTXO.d.ts +1 -1
  56. package/build/block/Block.d.ts +2 -1
  57. package/build/block/Block.js +2 -2
  58. package/build/contracts/CallResult.d.ts +1 -0
  59. package/build/contracts/CallResult.js +7 -3
  60. package/build/opnet.d.ts +7 -2
  61. package/build/opnet.js +7 -2
  62. package/build/providers/AbstractRpcProvider.d.ts +1 -1
  63. package/build/providers/AbstractRpcProvider.js +4 -4
  64. package/build/transactions/Transaction.d.ts +5 -1
  65. package/build/transactions/Transaction.js +14 -2
  66. package/build/transactions/TransactionParser.d.ts +3 -2
  67. package/build/transactions/TransactionParser.js +6 -6
  68. package/build/transactions/decoders/DeploymentTransaction.d.ts +2 -1
  69. package/build/transactions/decoders/DeploymentTransaction.js +2 -2
  70. package/build/transactions/decoders/GenericTransaction.d.ts +2 -1
  71. package/build/transactions/decoders/GenericTransaction.js +2 -2
  72. package/build/transactions/decoders/InteractionTransaction.d.ts +2 -1
  73. package/build/transactions/decoders/InteractionTransaction.js +2 -2
  74. package/build/transactions/interfaces/ITransaction.d.ts +2 -0
  75. package/build/transactions/interfaces/ProofOfWorkChallenge.d.ts +12 -0
  76. package/build/transactions/interfaces/ProofOfWorkChallenge.js +1 -0
  77. package/build/transactions/interfaces/transactions/ICommonTransaction.d.ts +2 -0
  78. package/build/transactions/metadata/TransactionInput.d.ts +1 -1
  79. package/build/transactions/metadata/TransactionOutput.d.ts +1 -1
  80. package/build/transactions/metadata/TransactionReceipt.d.ts +2 -1
  81. package/build/transactions/metadata/TransactionReceipt.js +12 -8
  82. package/package.json +14 -14
  83. package/src/_version.ts +1 -1
  84. package/src/abi/shared/interfaces/motoswap/IAdministeredOP20.ts +56 -0
  85. package/src/abi/shared/interfaces/motoswap/IMotoChefContract.ts +348 -0
  86. package/src/abi/shared/interfaces/motoswap/INativeSwapContract.ts +267 -0
  87. package/src/abi/shared/interfaces/motoswap/IOwnableContract.ts +32 -0
  88. package/src/abi/shared/interfaces/motoswap/IOwnableReentrancyGuardContract.ts +33 -0
  89. package/src/abi/shared/interfaces/motoswap/IReentrancyGuardContract.ts +18 -0
  90. package/src/abi/shared/json/motoswap/ADMINISTERD_OP_20_ABI.ts +85 -0
  91. package/src/abi/shared/json/motoswap/MOTOSWAP_MOTOCHEF_ABI.ts +455 -0
  92. package/src/abi/shared/json/motoswap/{EWMA_ABI.ts → NATIVE_SWAP_ABI.ts} +252 -37
  93. package/src/abi/shared/json/motoswap/OWNABLE_ABI.ts +38 -0
  94. package/src/abi/shared/json/motoswap/REENTRANCY_GUARD_ABI.ts +20 -0
  95. package/src/bitcoin/UTXOs.ts +2 -2
  96. package/src/bitcoin/interfaces/IUTXO.ts +1 -1
  97. package/src/block/Block.ts +3 -1
  98. package/src/contracts/CallResult.ts +9 -6
  99. package/src/opnet.ts +7 -2
  100. package/src/providers/AbstractRpcProvider.ts +5 -5
  101. package/src/providers/JSONRpcProvider.ts +1 -1
  102. package/src/transactions/Transaction.ts +30 -8
  103. package/src/transactions/TransactionParser.ts +7 -8
  104. package/src/transactions/decoders/DeploymentTransaction.ts +3 -2
  105. package/src/transactions/decoders/GenericTransaction.ts +3 -2
  106. package/src/transactions/decoders/InteractionTransaction.ts +3 -2
  107. package/src/transactions/interfaces/ITransaction.ts +6 -0
  108. package/src/transactions/interfaces/ProofOfWorkChallenge.ts +13 -0
  109. package/src/transactions/interfaces/transactions/ICommonTransaction.ts +6 -0
  110. package/src/transactions/metadata/TransactionInput.ts +1 -1
  111. package/src/transactions/metadata/TransactionOutput.ts +1 -1
  112. package/src/transactions/metadata/TransactionReceipt.ts +23 -11
  113. package/browser/abi/shared/interfaces/motoswap/IEwmaContract.d.ts +0 -46
  114. package/browser/abi/shared/json/motoswap/EWMA_ABI.d.ts +0 -3
  115. package/build/abi/shared/interfaces/motoswap/IEwmaContract.d.ts +0 -46
  116. package/build/abi/shared/json/motoswap/EWMA_ABI.d.ts +0 -3
  117. package/src/abi/shared/interfaces/motoswap/IEwmaContract.ts +0 -188
  118. /package/build/abi/shared/interfaces/motoswap/{IEwmaContract.js → IAdministeredOP20.js} +0 -0
@@ -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;
@@ -1,188 +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
-
5
- /**
6
- * @description Represents the result of the reserve function call.
7
- */
8
- export type ReserveEWMA = CallResult<{
9
- reserved: bigint;
10
- }>;
11
-
12
- /**
13
- * @description Represents the result of the addLiquidity function call.
14
- */
15
- export type AddLiquidity = CallResult<{
16
- ok: boolean;
17
- }>;
18
-
19
- /**
20
- * @description Represents the result of the removeLiquidity function call.
21
- */
22
- export type RemoveLiquidity = CallResult<{
23
- totalTokensReturned: bigint;
24
- }>;
25
-
26
- /**
27
- * @description Represents the result of the swap function call.
28
- */
29
- export type Swap = CallResult<{
30
- ok: boolean;
31
- }>;
32
-
33
- /**
34
- * @description Represents the result of the getReserve function call.
35
- */
36
- export type GetReserve = CallResult<{
37
- liquidity: bigint;
38
- reservedLiquidity: bigint;
39
- }>;
40
-
41
- /**
42
- * @description Represents the result of the getQuote function call.
43
- */
44
- export type GetQuote = CallResult<{
45
- tokensOut: bigint;
46
- requiredSatoshis: bigint;
47
- currentPrice: bigint;
48
- }>;
49
-
50
- /**
51
- * @description Represents the result of the setQuote function call.
52
- */
53
- export type SetQuote = CallResult<{
54
- ok: boolean;
55
- }>;
56
-
57
- /**
58
- * @description Represents the result of the priorityQueueCost function call.
59
- */
60
- export type PriorityQueueCost = CallResult<{
61
- cost: bigint;
62
- }>;
63
-
64
- /**
65
- * @description Represents the result of the getProviderDetails function call.
66
- */
67
- export type GetProviderDetails = CallResult<{
68
- liquidity: bigint;
69
- reserved: bigint;
70
- btcReceiver: string;
71
- }>;
72
-
73
- /**
74
- * @description This interface represents the OP_NET contract.
75
- * @interface IOP_NETContract
76
- * @extends {IOP_NETContract}
77
- * @category Contracts
78
- *
79
- * @example
80
- * import { Address } from '@btc-vision/transaction';
81
- * import { IOP_NETContract } from '../abi/shared/interfaces/IOP_NETContract.js';
82
- * import { OP_NET_ABI } from '../abi/shared/json/OP_NET_ABI.js';
83
- * import { CallResult } from '../contracts/CallResult.js';
84
- * import { getContract } from '../contracts/Contract.js';
85
- * import { JSONRpcProvider } from '../providers/JSONRpcProvider.js';
86
- *
87
- * const provider: JSONRpcProvider = new JSONRpcProvider('https://regtest.opnet.org');
88
- * const contract: IOP_NETContract = getContract<IOP_NETContract>(
89
- * 'bcrt1pyrs3eqwnrmd4ql3nwvx66yzp0wc24xd2t9pf8699ln340pjs7f3sar3tum',
90
- * OP_NET_ABI,
91
- * provider,
92
- * networks.regtest,
93
- * );
94
- *
95
- * const tokenAddress: Address = new Address([
96
- * 40, 11, 228, 172, 219, 50, 169, 155, 163, 235, 250, 102, 169, 29, 219, 65, 167, 183, 161, 210,
97
- * 254, 244, 21, 57, 153, 34, 205, 138, 4, 72, 92, 2,
98
- * ]);
99
- *
100
- * const reserveExample = await contract.reserve(
101
- * tokenAddress,
102
- * BigInt("1000000000000000000"), // maximumAmountIn
103
- * BigInt("500000000000000000") // minimumAmountOut
104
- * );
105
- *
106
- * console.log('Reserved:', reserveExample.properties.reserved);
107
- */
108
- export interface IEwmaContract extends IOP_NETContract {
109
- /**
110
- * @description Reserves a certain amount of tokens.
111
- * @param token - The address of the token to reserve.
112
- * @param maximumAmountIn - The maximum amount of tokens to reserve.
113
- * @param minimumAmountOut - The minimum amount of tokens expected out.
114
- * @returns {Promise<ReserveEWMA>}
115
- */
116
- reserve(
117
- token: Address,
118
- maximumAmountIn: bigint,
119
- minimumAmountOut: bigint,
120
- ): Promise<ReserveEWMA>;
121
-
122
- /**
123
- * @description Adds liquidity to the contract.
124
- * @param token - The address of the token to add liquidity for.
125
- * @param receiver - The receiver of the liquidity.
126
- * @param amountIn - The amount of tokens to add.
127
- * @param priority - Whether to prioritize the liquidity addition.
128
- * @returns {Promise<AddLiquidity>}
129
- */
130
- addLiquidity(
131
- token: Address,
132
- receiver: string,
133
- amountIn: bigint,
134
- priority: boolean,
135
- ): Promise<AddLiquidity>;
136
-
137
- /**
138
- * @description Removes liquidity from the contract.
139
- * @param token - The address of the token to remove liquidity for.
140
- * @returns {Promise<RemoveLiquidity>}
141
- */
142
- removeLiquidity(token: Address): Promise<RemoveLiquidity>;
143
-
144
- /**
145
- * @description Executes a swap operation.
146
- * @param token - The address of the token to swap.
147
- * @param isSimulation - Whether the swap is a simulation.
148
- * @returns {Promise<Swap>}
149
- */
150
- swap(token: Address, isSimulation: boolean): Promise<Swap>;
151
-
152
- /**
153
- * @description Retrieves the reserve information for a token.
154
- * @param token - The address of the token.
155
- * @returns {Promise<GetReserve>}
156
- */
157
- getReserve(token: Address): Promise<GetReserve>;
158
-
159
- /**
160
- * @description Retrieves a quote for swapping tokens.
161
- * @param token - The address of the token.
162
- * @param satoshisIn - The amount of satoshis to swap.
163
- * @returns {Promise<GetQuote>}
164
- */
165
- getQuote(token: Address, satoshisIn: bigint): Promise<GetQuote>;
166
-
167
- /**
168
- * @description Sets a new quote for a token.
169
- * @param token - The address of the token.
170
- * @param p0 - The new quote parameter.
171
- * @returns {Promise<SetQuote>}
172
- */
173
- setQuote(token: Address, p0: bigint): Promise<SetQuote>;
174
-
175
- /**
176
- * @description Retrieves the cost of the priority queue for a token.
177
- * @param token - The address of the token.
178
- * @returns {Promise<PriorityQueueCost>}
179
- */
180
- priorityQueueCost(token: Address): Promise<PriorityQueueCost>;
181
-
182
- /**
183
- * @description Retrieves the provider details for a token.
184
- * @param token - The address of the token.
185
- * @returns {Promise<GetProviderDetails>}
186
- */
187
- getProviderDetails(token: Address): Promise<GetProviderDetails>;
188
- }