opnet 1.1.2 → 1.1.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.
- package/README.md +3 -2
- package/browser/_version.d.ts +1 -1
- package/browser/abi/shared/interfaces/IMotoswapFactoryContract.d.ts +7 -2
- package/browser/abi/shared/interfaces/IMotoswapPoolContract.d.ts +33 -7
- package/browser/abi/shared/interfaces/IMotoswapRouterContract.d.ts +30 -10
- package/browser/abi/shared/interfaces/IOP_20Contract.d.ts +1 -1
- package/browser/abi/shared/interfaces/IOP_NETContract.d.ts +3 -3
- package/browser/abi/shared/interfaces/IStackingContract.d.ts +22 -8
- package/browser/abi/shared/interfaces/IWBTCContract.d.ts +7 -2
- package/browser/index.js +1 -1
- package/browser/opnet.d.ts +0 -1
- package/browser/providers/AbstractRpcProvider.d.ts +6 -5
- package/browser/providers/JSONRpcProvider.d.ts +2 -1
- package/browser/providers/WebsocketRpcProvider.d.ts +2 -1
- package/browser/utxos/UTXOsManager.d.ts +1 -0
- package/build/_version.d.ts +1 -1
- package/build/_version.js +1 -1
- package/build/abi/shared/interfaces/IMotoswapFactoryContract.d.ts +7 -2
- package/build/abi/shared/interfaces/IMotoswapPoolContract.d.ts +33 -7
- package/build/abi/shared/interfaces/IMotoswapRouterContract.d.ts +30 -10
- package/build/abi/shared/interfaces/IOP_20Contract.d.ts +1 -1
- package/build/abi/shared/interfaces/IOP_NETContract.d.ts +3 -3
- package/build/abi/shared/interfaces/IStackingContract.d.ts +22 -8
- package/build/abi/shared/interfaces/IWBTCContract.d.ts +7 -2
- package/build/abi/shared/json/MOTOSWAP_FACTORY_ABI.js +1 -1
- package/build/abi/shared/json/MOTOSWAP_ROUTER_ABI.js +1 -12
- package/build/abi/shared/json/OP_NET_ABI.js +11 -0
- package/build/contracts/CallResult.js +34 -28
- package/build/opnet.d.ts +0 -1
- package/build/opnet.js +0 -1
- package/build/providers/AbstractRpcProvider.d.ts +6 -5
- package/build/providers/AbstractRpcProvider.js +35 -20
- package/build/providers/JSONRpcProvider.d.ts +2 -1
- package/build/providers/JSONRpcProvider.js +2 -2
- package/build/providers/WebsocketRpcProvider.d.ts +2 -1
- package/build/providers/WebsocketRpcProvider.js +2 -2
- package/build/utxos/UTXOsManager.d.ts +1 -0
- package/build/utxos/UTXOsManager.js +6 -0
- package/package.json +1 -1
- package/src/_version.ts +1 -1
- package/src/abi/shared/interfaces/IMotoswapFactoryContract.ts +7 -4
- package/src/abi/shared/interfaces/IMotoswapPoolContract.ts +40 -10
- package/src/abi/shared/interfaces/IMotoswapRouterContract.ts +21 -14
- package/src/abi/shared/interfaces/IOP_20Contract.ts +1 -1
- package/src/abi/shared/interfaces/IOP_NETContract.ts +1 -4
- package/src/abi/shared/interfaces/IStackingContract.ts +9 -9
- package/src/abi/shared/interfaces/IWBTCContract.ts +3 -2
- package/src/abi/shared/json/MOTOSWAP_FACTORY_ABI.ts +1 -1
- package/src/abi/shared/json/MOTOSWAP_ROUTER_ABI.ts +1 -12
- package/src/abi/shared/json/OP_NET_ABI.ts +12 -0
- package/src/contracts/CallResult.ts +42 -35
- package/src/opnet.ts +0 -1
- package/src/providers/AbstractRpcProvider.ts +56 -48
- package/src/providers/JSONRpcProvider.ts +3 -1
- package/src/providers/WebsocketRpcProvider.ts +3 -2
- package/src/providers/interfaces/PublicKeyInfo.d.ts +6 -0
- package/src/utxos/UTXOsManager.ts +9 -0
- package/browser/abi/shared/json/MOTO_TOKEN_ABI.d.ts +0 -2
- package/build/abi/shared/json/MOTO_TOKEN_ABI.d.ts +0 -2
- package/build/abi/shared/json/MOTO_TOKEN_ABI.js +0 -22
- package/src/abi/shared/json/MOTO_TOKEN_ABI.ts +0 -29
package/browser/opnet.d.ts
CHANGED
|
@@ -53,7 +53,6 @@ export * from './common/CommonTypes.js';
|
|
|
53
53
|
export * from './bitcoin/interfaces/IUTXO.js';
|
|
54
54
|
export * from './bitcoin/UTXOs.js';
|
|
55
55
|
export { ABIDataTypes } from '@btc-vision/transaction';
|
|
56
|
-
export * from './abi/shared/json/MOTO_TOKEN_ABI.js';
|
|
57
56
|
export * from './abi/shared/json/MOTOSWAP_FACTORY_ABI.js';
|
|
58
57
|
export * from './abi/shared/json/MOTOSWAP_POOL_ABI.js';
|
|
59
58
|
export * from './abi/shared/json/MOTOSWAP_ROUTER_ABI.js';
|
|
@@ -17,16 +17,16 @@ import { UTXOsManager } from '../utxos/UTXOsManager.js';
|
|
|
17
17
|
import { JsonRpcPayload } from './interfaces/JSONRpc.js';
|
|
18
18
|
import { JSONRpcMethods } from './interfaces/JSONRpcMethods.js';
|
|
19
19
|
import { JsonRpcCallResult, JsonRpcResult } from './interfaces/JSONRpcResult.js';
|
|
20
|
-
import {
|
|
20
|
+
import { AddressesInfo } from './interfaces/PublicKeyInfo.js';
|
|
21
21
|
import { ReorgInformation } from './interfaces/ReorgInformation.js';
|
|
22
22
|
export declare abstract class AbstractRpcProvider {
|
|
23
|
+
private readonly network;
|
|
23
24
|
private nextId;
|
|
24
|
-
private network;
|
|
25
25
|
private chainId;
|
|
26
|
-
protected constructor();
|
|
26
|
+
protected constructor(network: Network);
|
|
27
27
|
private _utxoManager;
|
|
28
28
|
get utxoManager(): UTXOsManager;
|
|
29
|
-
getPublicKeyInfo(address: string
|
|
29
|
+
getPublicKeyInfo(address: string): Promise<Address>;
|
|
30
30
|
validateAddress(addr: string | Address, network: Network): AddressTypes | null;
|
|
31
31
|
getBlockNumber(): Promise<bigint>;
|
|
32
32
|
getBlock(blockNumberOrHash: BlockTag, prefetchTxs?: boolean): Promise<Block>;
|
|
@@ -35,7 +35,7 @@ export declare abstract class AbstractRpcProvider {
|
|
|
35
35
|
getBalance(addressLike: string, filterOrdinals?: boolean): Promise<bigint>;
|
|
36
36
|
getTransaction(txHash: string): Promise<TransactionBase<OPNetTransactionTypes>>;
|
|
37
37
|
getTransactionReceipt(txHash: string): Promise<TransactionReceipt>;
|
|
38
|
-
getNetwork():
|
|
38
|
+
getNetwork(): Network;
|
|
39
39
|
getChainId(): Promise<bigint>;
|
|
40
40
|
getCode(address: string | Address, onlyBytecode?: boolean): Promise<ContractData | Buffer>;
|
|
41
41
|
getStorageAt(address: string | Address, rawPointer: bigint | string, proofs?: boolean, height?: BigNumberish): Promise<StoredValue>;
|
|
@@ -49,6 +49,7 @@ export declare abstract class AbstractRpcProvider {
|
|
|
49
49
|
callPayloadSingle(payload: JsonRpcPayload): Promise<JsonRpcResult>;
|
|
50
50
|
callMultiplePayloads(payloads: JsonRpcPayload[]): Promise<JsonRpcCallResult>;
|
|
51
51
|
buildJsonRpcPayload<T extends JSONRpcMethods>(method: T, params: unknown[]): JsonRpcPayload;
|
|
52
|
+
getPublicKeysInfo(addresses: string | string[] | Address | Address[]): Promise<AddressesInfo>;
|
|
52
53
|
protected abstract providerUrl(url: string): string;
|
|
53
54
|
private bufferToHex;
|
|
54
55
|
private bigintToBase64;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { Network } from 'bitcoinjs-lib';
|
|
1
2
|
import { AbstractRpcProvider } from './AbstractRpcProvider.js';
|
|
2
3
|
import { JsonRpcPayload } from './interfaces/JSONRpc.js';
|
|
3
4
|
import { JsonRpcCallResult } from './interfaces/JSONRpcResult.js';
|
|
4
5
|
export declare class JSONRpcProvider extends AbstractRpcProvider {
|
|
5
6
|
private readonly timeout;
|
|
6
7
|
readonly url: string;
|
|
7
|
-
constructor(url: string, timeout?: number);
|
|
8
|
+
constructor(url: string, network: Network, timeout?: number);
|
|
8
9
|
_send(payload: JsonRpcPayload | JsonRpcPayload[]): Promise<JsonRpcCallResult>;
|
|
9
10
|
protected providerUrl(url: string): string;
|
|
10
11
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { Network } from 'bitcoinjs-lib';
|
|
1
2
|
import { AbstractRpcProvider } from './AbstractRpcProvider.js';
|
|
2
3
|
import { JsonRpcPayload } from './interfaces/JSONRpc.js';
|
|
3
4
|
import { JsonRpcCallResult } from './interfaces/JSONRpcResult.js';
|
|
4
5
|
export declare class WebSocketRpcProvider extends AbstractRpcProvider {
|
|
5
6
|
private readonly wsUrl;
|
|
6
|
-
constructor(url: string);
|
|
7
|
+
constructor(url: string, network: Network);
|
|
7
8
|
_send(payload: JsonRpcPayload): Promise<JsonRpcCallResult>;
|
|
8
9
|
protected providerUrl(url: string): string;
|
|
9
10
|
}
|
package/build/_version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "1.1.
|
|
1
|
+
export declare const version = "1.1.4";
|
package/build/_version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '1.1.
|
|
1
|
+
export const version = '1.1.4';
|
|
@@ -2,6 +2,11 @@ import { Address } from '@btc-vision/transaction';
|
|
|
2
2
|
import { CallResult } from '../../../contracts/CallResult.js';
|
|
3
3
|
import { IOP_NETContract } from './IOP_NETContract.js';
|
|
4
4
|
export interface IMotoswapFactoryContract extends IOP_NETContract {
|
|
5
|
-
getPool(token0: Address, token1: Address): Promise<CallResult
|
|
6
|
-
|
|
5
|
+
getPool(token0: Address, token1: Address): Promise<CallResult<{
|
|
6
|
+
pool: bigint;
|
|
7
|
+
}>>;
|
|
8
|
+
createPool(token0: Address, token1: Address): Promise<CallResult<{
|
|
9
|
+
pool: bigint;
|
|
10
|
+
address: Address;
|
|
11
|
+
}>>;
|
|
7
12
|
}
|
|
@@ -1,13 +1,39 @@
|
|
|
1
1
|
import { Address } from '@btc-vision/transaction';
|
|
2
2
|
import { CallResult } from '../../../contracts/CallResult.js';
|
|
3
3
|
import { IOP_20Contract } from './IOP_20Contract.js';
|
|
4
|
+
export type Reserves = {
|
|
5
|
+
readonly reserve0: bigint;
|
|
6
|
+
readonly reserve1: bigint;
|
|
7
|
+
readonly blockTimestampLast: bigint;
|
|
8
|
+
};
|
|
4
9
|
export interface IMotoswapPoolContract extends Omit<IOP_20Contract, 'burn' | 'mint'> {
|
|
5
|
-
token0(): Promise<CallResult
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
10
|
+
token0(): Promise<CallResult<{
|
|
11
|
+
token0: Address;
|
|
12
|
+
}>>;
|
|
13
|
+
token1(): Promise<CallResult<{
|
|
14
|
+
token1: Address;
|
|
15
|
+
}>>;
|
|
16
|
+
getReserves(): Promise<CallResult<Reserves>>;
|
|
17
|
+
swap(amount0Out: bigint, amount1Out: bigint, to: string, data: Uint8Array): Promise<CallResult<{
|
|
18
|
+
success: boolean;
|
|
19
|
+
}>>;
|
|
20
|
+
skim(): Promise<CallResult<{
|
|
21
|
+
success: boolean;
|
|
22
|
+
}>>;
|
|
23
|
+
kLast(): Promise<CallResult<{
|
|
24
|
+
kLast: bigint;
|
|
25
|
+
}>>;
|
|
9
26
|
burn(to: Address): Promise<CallResult>;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
27
|
+
blockTimestampLast(): Promise<CallResult<{
|
|
28
|
+
blockTimestampLast: bigint;
|
|
29
|
+
}>>;
|
|
30
|
+
sync(): Promise<CallResult<{
|
|
31
|
+
success: boolean;
|
|
32
|
+
}>>;
|
|
33
|
+
price0CumulativeLast(): Promise<CallResult<{
|
|
34
|
+
price0CumulativeLast: bigint;
|
|
35
|
+
}>>;
|
|
36
|
+
price1CumulativeLast(): Promise<CallResult<{
|
|
37
|
+
price1CumulativeLast: bigint;
|
|
38
|
+
}>>;
|
|
13
39
|
}
|
|
@@ -2,14 +2,34 @@ import { Address } from '@btc-vision/transaction';
|
|
|
2
2
|
import { CallResult } from '../../../contracts/CallResult.js';
|
|
3
3
|
import { IOP_NETContract } from './IOP_NETContract.js';
|
|
4
4
|
export interface IMotoswapRouterContract extends IOP_NETContract {
|
|
5
|
-
addLiquidity(tokenA: Address, tokenB: Address, amountADesired: bigint, amountBDesired: bigint, amountAMin: bigint, amountBMin: bigint, to: Address, deadline: bigint): Promise<CallResult
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
5
|
+
addLiquidity(tokenA: Address, tokenB: Address, amountADesired: bigint, amountBDesired: bigint, amountAMin: bigint, amountBMin: bigint, to: Address, deadline: bigint): Promise<CallResult<{
|
|
6
|
+
amountA: bigint;
|
|
7
|
+
amountB: bigint;
|
|
8
|
+
liquidity: bigint;
|
|
9
|
+
}>>;
|
|
10
|
+
removeLiquidity(tokenA: Address, tokenB: Address, liquidity: bigint, amountAMin: bigint, amountBMin: bigint, to: Address, deadline: bigint): Promise<CallResult<{
|
|
11
|
+
amountA: bigint;
|
|
12
|
+
amountB: bigint;
|
|
13
|
+
}>>;
|
|
14
|
+
quote(amountA: bigint, reserveA: bigint, reserveB: bigint): Promise<CallResult<{
|
|
15
|
+
quote: bigint;
|
|
16
|
+
}>>;
|
|
17
|
+
getAmountOut(amountIn: bigint, reserveIn: bigint, reserveOut: bigint): Promise<CallResult<{
|
|
18
|
+
amountOut: bigint;
|
|
19
|
+
}>>;
|
|
20
|
+
getAmountIn(amountOut: bigint, reserveIn: bigint, reserveOut: bigint): Promise<CallResult<{
|
|
21
|
+
amountIn: bigint;
|
|
22
|
+
}>>;
|
|
23
|
+
getAmountsOut(amountIn: bigint, path: Address[]): Promise<CallResult<{
|
|
24
|
+
amountsOut: bigint[];
|
|
25
|
+
}>>;
|
|
26
|
+
getAmountsIn(amountOut: bigint, path: Address[]): Promise<CallResult<{
|
|
27
|
+
amountsIn: bigint[];
|
|
28
|
+
}>>;
|
|
29
|
+
swapExactTokensForTokensSupportingFeeOnTransferTokens(amountIn: bigint, amountOutMin: bigint, path: Address[], to: Address, deadline: bigint): Promise<CallResult<{
|
|
30
|
+
success: boolean;
|
|
31
|
+
}>>;
|
|
32
|
+
factory(): Promise<CallResult<{
|
|
33
|
+
factory: Address;
|
|
34
|
+
}>>;
|
|
15
35
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Address } from '@btc-vision/transaction';
|
|
2
1
|
import { CallResult } from '../../../contracts/CallResult.js';
|
|
3
2
|
import { BaseContractProperties } from '../../interfaces/BaseContractProperties.js';
|
|
4
3
|
export interface IOP_NETContract extends BaseContractProperties {
|
|
5
|
-
owner(): Promise<CallResult
|
|
6
|
-
|
|
4
|
+
owner(): Promise<CallResult<{
|
|
5
|
+
owner: string;
|
|
6
|
+
}>>;
|
|
7
7
|
}
|
|
@@ -1,11 +1,25 @@
|
|
|
1
1
|
import { Address } from '@btc-vision/transaction';
|
|
2
|
-
import {
|
|
2
|
+
import { CallResult } from '../../../contracts/CallResult.js';
|
|
3
3
|
export interface IStackingContract {
|
|
4
|
-
stake(amount: bigint): Promise<
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
stake(amount: bigint): Promise<CallResult<{
|
|
5
|
+
success: boolean;
|
|
6
|
+
}>>;
|
|
7
|
+
unstake(): Promise<CallResult<{
|
|
8
|
+
success: boolean;
|
|
9
|
+
}>>;
|
|
10
|
+
stakedAmount(address: Address): Promise<CallResult<{
|
|
11
|
+
amount: bigint;
|
|
12
|
+
}>>;
|
|
13
|
+
stakedReward(address: Address): Promise<CallResult<{
|
|
14
|
+
amount: bigint;
|
|
15
|
+
}>>;
|
|
16
|
+
claim(): Promise<CallResult<{
|
|
17
|
+
success: boolean;
|
|
18
|
+
}>>;
|
|
19
|
+
rewardPool(): Promise<CallResult<{
|
|
20
|
+
reward: bigint;
|
|
21
|
+
}>>;
|
|
22
|
+
totalStaked(): Promise<CallResult<{
|
|
23
|
+
total: bigint;
|
|
24
|
+
}>>;
|
|
11
25
|
}
|
|
@@ -1,8 +1,13 @@
|
|
|
1
|
+
import { Address } from '@btc-vision/transaction';
|
|
1
2
|
import { CallResult } from '../../../contracts/CallResult.js';
|
|
2
3
|
import { IOP_20Contract } from './IOP_20Contract.js';
|
|
3
4
|
import { IStackingContract } from './IStackingContract.js';
|
|
4
5
|
export type MergedOP_20AndStackingContract = IOP_20Contract & IStackingContract;
|
|
5
6
|
export interface IWBTCContract extends MergedOP_20AndStackingContract {
|
|
6
|
-
requestWithdrawal(amount: bigint): Promise<CallResult
|
|
7
|
-
|
|
7
|
+
requestWithdrawal(amount: bigint): Promise<CallResult<{
|
|
8
|
+
success: boolean;
|
|
9
|
+
}>>;
|
|
10
|
+
withdrawableBalanceOf(address: Address): Promise<CallResult<{
|
|
11
|
+
balance: bigint;
|
|
12
|
+
}>>;
|
|
8
13
|
}
|
|
@@ -207,7 +207,7 @@ export const MOTOSWAP_ROUTER_ABI = [
|
|
|
207
207
|
],
|
|
208
208
|
outputs: [
|
|
209
209
|
{
|
|
210
|
-
name: '
|
|
210
|
+
name: 'amountsIn',
|
|
211
211
|
type: ABIDataTypes.TUPLE,
|
|
212
212
|
},
|
|
213
213
|
],
|
|
@@ -256,17 +256,6 @@ export const MOTOSWAP_ROUTER_ABI = [
|
|
|
256
256
|
],
|
|
257
257
|
type: BitcoinAbiTypes.Function,
|
|
258
258
|
},
|
|
259
|
-
{
|
|
260
|
-
name: 'WBTC',
|
|
261
|
-
inputs: [],
|
|
262
|
-
outputs: [
|
|
263
|
-
{
|
|
264
|
-
name: 'WBTC',
|
|
265
|
-
type: ABIDataTypes.ADDRESS,
|
|
266
|
-
},
|
|
267
|
-
],
|
|
268
|
-
type: BitcoinAbiTypes.Function,
|
|
269
|
-
},
|
|
270
259
|
...MotoSwapFactoryEvents,
|
|
271
260
|
...OP20Events,
|
|
272
261
|
...MotoSwapPoolEvents,
|
|
@@ -12,4 +12,15 @@ export const OP_NET_ABI = [
|
|
|
12
12
|
],
|
|
13
13
|
type: BitcoinAbiTypes.Function,
|
|
14
14
|
},
|
|
15
|
+
{
|
|
16
|
+
name: 'address',
|
|
17
|
+
constant: true,
|
|
18
|
+
outputs: [
|
|
19
|
+
{
|
|
20
|
+
name: 'address',
|
|
21
|
+
type: ABIDataTypes.ADDRESS,
|
|
22
|
+
},
|
|
23
|
+
],
|
|
24
|
+
type: BitcoinAbiTypes.Function,
|
|
25
|
+
},
|
|
15
26
|
];
|
|
@@ -40,36 +40,42 @@ export class CallResult {
|
|
|
40
40
|
throw new Error('To address not set');
|
|
41
41
|
}
|
|
42
42
|
const priorityFee = this.estimatedSatGas + (interactionParams.priorityFee || 0n);
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
43
|
+
try {
|
|
44
|
+
const UTXOs = interactionParams.utxos ||
|
|
45
|
+
(await this.#fetchUTXOs(priorityFee + interactionParams.maximumAllowedSatToSpend, interactionParams));
|
|
46
|
+
const params = {
|
|
47
|
+
calldata: this.calldata,
|
|
48
|
+
priorityFee: priorityFee,
|
|
49
|
+
feeRate: interactionParams.feeRate || 10,
|
|
50
|
+
from: interactionParams.refundTo,
|
|
51
|
+
signer: interactionParams.signer,
|
|
52
|
+
utxos: UTXOs,
|
|
53
|
+
to: this.to,
|
|
54
|
+
network: interactionParams.network,
|
|
55
|
+
};
|
|
56
|
+
const transaction = await factory.signInteraction(params);
|
|
57
|
+
const tx1 = await this.#provider.sendRawTransaction(transaction[0], false);
|
|
58
|
+
if (!tx1 || tx1.error) {
|
|
59
|
+
throw new Error(`Error sending transaction: ${tx1?.error || 'Unknown error'}`);
|
|
60
|
+
}
|
|
61
|
+
this.#provider.utxoManager.spentUTXO(UTXOs, transaction[2]);
|
|
62
|
+
const tx2 = await this.#provider.sendRawTransaction(transaction[1], false);
|
|
63
|
+
if (!tx2 || tx2.error) {
|
|
64
|
+
throw new Error(`Error sending transaction: ${tx2?.error || 'Unknown error'}`);
|
|
65
|
+
}
|
|
66
|
+
if (!tx2.result) {
|
|
67
|
+
throw new Error('No transaction ID returned');
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
transactionId: tx2.result,
|
|
71
|
+
peerAcknowledgements: tx2.peers || 0,
|
|
72
|
+
newUTXOs: transaction[2],
|
|
73
|
+
};
|
|
64
74
|
}
|
|
65
|
-
|
|
66
|
-
|
|
75
|
+
catch (e) {
|
|
76
|
+
this.#provider.utxoManager.clean();
|
|
77
|
+
throw e;
|
|
67
78
|
}
|
|
68
|
-
return {
|
|
69
|
-
transactionId: tx2.result,
|
|
70
|
-
peerAcknowledgements: tx2.peers || 0,
|
|
71
|
-
newUTXOs: transaction[2],
|
|
72
|
-
};
|
|
73
79
|
}
|
|
74
80
|
setGasEstimation(estimatedGas) {
|
|
75
81
|
this.estimatedSatGas = estimatedGas;
|
package/build/opnet.d.ts
CHANGED
|
@@ -53,7 +53,6 @@ export * from './common/CommonTypes.js';
|
|
|
53
53
|
export * from './bitcoin/interfaces/IUTXO.js';
|
|
54
54
|
export * from './bitcoin/UTXOs.js';
|
|
55
55
|
export { ABIDataTypes } from '@btc-vision/transaction';
|
|
56
|
-
export * from './abi/shared/json/MOTO_TOKEN_ABI.js';
|
|
57
56
|
export * from './abi/shared/json/MOTOSWAP_FACTORY_ABI.js';
|
|
58
57
|
export * from './abi/shared/json/MOTOSWAP_POOL_ABI.js';
|
|
59
58
|
export * from './abi/shared/json/MOTOSWAP_ROUTER_ABI.js';
|
package/build/opnet.js
CHANGED
|
@@ -53,7 +53,6 @@ export * from './common/CommonTypes.js';
|
|
|
53
53
|
export * from './bitcoin/interfaces/IUTXO.js';
|
|
54
54
|
export * from './bitcoin/UTXOs.js';
|
|
55
55
|
export { ABIDataTypes } from '@btc-vision/transaction';
|
|
56
|
-
export * from './abi/shared/json/MOTO_TOKEN_ABI.js';
|
|
57
56
|
export * from './abi/shared/json/MOTOSWAP_FACTORY_ABI.js';
|
|
58
57
|
export * from './abi/shared/json/MOTOSWAP_POOL_ABI.js';
|
|
59
58
|
export * from './abi/shared/json/MOTOSWAP_ROUTER_ABI.js';
|
|
@@ -17,16 +17,16 @@ import { UTXOsManager } from '../utxos/UTXOsManager.js';
|
|
|
17
17
|
import { JsonRpcPayload } from './interfaces/JSONRpc.js';
|
|
18
18
|
import { JSONRpcMethods } from './interfaces/JSONRpcMethods.js';
|
|
19
19
|
import { JsonRpcCallResult, JsonRpcResult } from './interfaces/JSONRpcResult.js';
|
|
20
|
-
import {
|
|
20
|
+
import { AddressesInfo } from './interfaces/PublicKeyInfo.js';
|
|
21
21
|
import { ReorgInformation } from './interfaces/ReorgInformation.js';
|
|
22
22
|
export declare abstract class AbstractRpcProvider {
|
|
23
|
+
private readonly network;
|
|
23
24
|
private nextId;
|
|
24
|
-
private network;
|
|
25
25
|
private chainId;
|
|
26
|
-
protected constructor();
|
|
26
|
+
protected constructor(network: Network);
|
|
27
27
|
private _utxoManager;
|
|
28
28
|
get utxoManager(): UTXOsManager;
|
|
29
|
-
getPublicKeyInfo(address: string
|
|
29
|
+
getPublicKeyInfo(address: string): Promise<Address>;
|
|
30
30
|
validateAddress(addr: string | Address, network: Network): AddressTypes | null;
|
|
31
31
|
getBlockNumber(): Promise<bigint>;
|
|
32
32
|
getBlock(blockNumberOrHash: BlockTag, prefetchTxs?: boolean): Promise<Block>;
|
|
@@ -35,7 +35,7 @@ export declare abstract class AbstractRpcProvider {
|
|
|
35
35
|
getBalance(addressLike: string, filterOrdinals?: boolean): Promise<bigint>;
|
|
36
36
|
getTransaction(txHash: string): Promise<TransactionBase<OPNetTransactionTypes>>;
|
|
37
37
|
getTransactionReceipt(txHash: string): Promise<TransactionReceipt>;
|
|
38
|
-
getNetwork():
|
|
38
|
+
getNetwork(): Network;
|
|
39
39
|
getChainId(): Promise<bigint>;
|
|
40
40
|
getCode(address: string | Address, onlyBytecode?: boolean): Promise<ContractData | Buffer>;
|
|
41
41
|
getStorageAt(address: string | Address, rawPointer: bigint | string, proofs?: boolean, height?: BigNumberish): Promise<StoredValue>;
|
|
@@ -49,6 +49,7 @@ export declare abstract class AbstractRpcProvider {
|
|
|
49
49
|
callPayloadSingle(payload: JsonRpcPayload): Promise<JsonRpcResult>;
|
|
50
50
|
callMultiplePayloads(payloads: JsonRpcPayload[]): Promise<JsonRpcCallResult>;
|
|
51
51
|
buildJsonRpcPayload<T extends JSONRpcMethods>(method: T, params: unknown[]): JsonRpcPayload;
|
|
52
|
+
getPublicKeysInfo(addresses: string | string[] | Address | Address[]): Promise<AddressesInfo>;
|
|
52
53
|
protected abstract providerUrl(url: string): string;
|
|
53
54
|
private bufferToHex;
|
|
54
55
|
private bigintToBase64;
|
|
@@ -11,28 +11,19 @@ import { UTXOsManager } from '../utxos/UTXOsManager.js';
|
|
|
11
11
|
import { GenerateTarget } from './interfaces/Generate.js';
|
|
12
12
|
import { JSONRpcMethods } from './interfaces/JSONRpcMethods.js';
|
|
13
13
|
export class AbstractRpcProvider {
|
|
14
|
-
nextId = 0;
|
|
15
14
|
network;
|
|
15
|
+
nextId = 0;
|
|
16
16
|
chainId;
|
|
17
|
-
constructor() {
|
|
17
|
+
constructor(network) {
|
|
18
|
+
this.network = network;
|
|
19
|
+
}
|
|
18
20
|
_utxoManager = new UTXOsManager(this);
|
|
19
21
|
get utxoManager() {
|
|
20
22
|
return this._utxoManager;
|
|
21
23
|
}
|
|
22
|
-
async getPublicKeyInfo(address
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
if (this.validateAddress(addr, network) === null) {
|
|
26
|
-
throw new Error(`Invalid address: ${addr}`);
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
const method = JSONRpcMethods.PUBLIC_KEY_INFO;
|
|
30
|
-
const payload = this.buildJsonRpcPayload(method, [addressArray]);
|
|
31
|
-
const data = await this.callPayloadSingle(payload);
|
|
32
|
-
if ('error' in data) {
|
|
33
|
-
throw new Error(`Error fetching public key info: ${data.error}`);
|
|
34
|
-
}
|
|
35
|
-
return data.result;
|
|
24
|
+
async getPublicKeyInfo(address) {
|
|
25
|
+
const pubKeyInfo = await this.getPublicKeysInfo(address);
|
|
26
|
+
return pubKeyInfo[address];
|
|
36
27
|
}
|
|
37
28
|
validateAddress(addr, network) {
|
|
38
29
|
let validationResult = null;
|
|
@@ -116,10 +107,7 @@ export class AbstractRpcProvider {
|
|
|
116
107
|
return new TransactionReceipt(rawTransaction.result);
|
|
117
108
|
}
|
|
118
109
|
getNetwork() {
|
|
119
|
-
|
|
120
|
-
return Promise.resolve(this.network);
|
|
121
|
-
}
|
|
122
|
-
throw new Error('Not implemented');
|
|
110
|
+
return this.network;
|
|
123
111
|
}
|
|
124
112
|
async getChainId() {
|
|
125
113
|
if (this.chainId !== undefined)
|
|
@@ -287,6 +275,33 @@ export class AbstractRpcProvider {
|
|
|
287
275
|
jsonrpc: '2.0',
|
|
288
276
|
};
|
|
289
277
|
}
|
|
278
|
+
async getPublicKeysInfo(addresses) {
|
|
279
|
+
const addressArray = Array.isArray(addresses) ? addresses : [addresses];
|
|
280
|
+
addressArray.forEach((addr) => {
|
|
281
|
+
if (this.validateAddress(addr, this.network) === null) {
|
|
282
|
+
throw new Error(`Invalid address: ${addr}`);
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
const method = JSONRpcMethods.PUBLIC_KEY_INFO;
|
|
286
|
+
const payload = this.buildJsonRpcPayload(method, [addressArray]);
|
|
287
|
+
const data = await this.callPayloadSingle(payload);
|
|
288
|
+
if ('error' in data) {
|
|
289
|
+
throw new Error(`Error fetching public key info: ${data.error}`);
|
|
290
|
+
}
|
|
291
|
+
const response = {};
|
|
292
|
+
const result = data.result;
|
|
293
|
+
const keys = Object.keys(result);
|
|
294
|
+
for (const pubKey of keys) {
|
|
295
|
+
const pubKeyValue = result[pubKey];
|
|
296
|
+
if ('error' in pubKeyValue) {
|
|
297
|
+
throw new Error(`Error fetching public key info: ${pubKeyValue.error}`);
|
|
298
|
+
}
|
|
299
|
+
response[pubKey] = pubKeyValue.originalPubKey
|
|
300
|
+
? Address.fromString(pubKeyValue.originalPubKey)
|
|
301
|
+
: Address.fromString(pubKeyValue.tweakedPubkey);
|
|
302
|
+
}
|
|
303
|
+
return response;
|
|
304
|
+
}
|
|
290
305
|
bufferToHex(buffer) {
|
|
291
306
|
return buffer.toString('hex');
|
|
292
307
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { Network } from 'bitcoinjs-lib';
|
|
1
2
|
import { AbstractRpcProvider } from './AbstractRpcProvider.js';
|
|
2
3
|
import { JsonRpcPayload } from './interfaces/JSONRpc.js';
|
|
3
4
|
import { JsonRpcCallResult } from './interfaces/JSONRpcResult.js';
|
|
4
5
|
export declare class JSONRpcProvider extends AbstractRpcProvider {
|
|
5
6
|
private readonly timeout;
|
|
6
7
|
readonly url: string;
|
|
7
|
-
constructor(url: string, timeout?: number);
|
|
8
|
+
constructor(url: string, network: Network, timeout?: number);
|
|
8
9
|
_send(payload: JsonRpcPayload | JsonRpcPayload[]): Promise<JsonRpcCallResult>;
|
|
9
10
|
protected providerUrl(url: string): string;
|
|
10
11
|
}
|
|
@@ -2,8 +2,8 @@ import { AbstractRpcProvider } from './AbstractRpcProvider.js';
|
|
|
2
2
|
export class JSONRpcProvider extends AbstractRpcProvider {
|
|
3
3
|
timeout;
|
|
4
4
|
url;
|
|
5
|
-
constructor(url, timeout = 10_000) {
|
|
6
|
-
super();
|
|
5
|
+
constructor(url, network, timeout = 10_000) {
|
|
6
|
+
super(network);
|
|
7
7
|
this.timeout = timeout;
|
|
8
8
|
this.url = this.providerUrl(url);
|
|
9
9
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { Network } from 'bitcoinjs-lib';
|
|
1
2
|
import { AbstractRpcProvider } from './AbstractRpcProvider.js';
|
|
2
3
|
import { JsonRpcPayload } from './interfaces/JSONRpc.js';
|
|
3
4
|
import { JsonRpcCallResult } from './interfaces/JSONRpcResult.js';
|
|
4
5
|
export declare class WebSocketRpcProvider extends AbstractRpcProvider {
|
|
5
6
|
private readonly wsUrl;
|
|
6
|
-
constructor(url: string);
|
|
7
|
+
constructor(url: string, network: Network);
|
|
7
8
|
_send(payload: JsonRpcPayload): Promise<JsonRpcCallResult>;
|
|
8
9
|
protected providerUrl(url: string): string;
|
|
9
10
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { AbstractRpcProvider } from './AbstractRpcProvider.js';
|
|
2
2
|
export class WebSocketRpcProvider extends AbstractRpcProvider {
|
|
3
3
|
wsUrl;
|
|
4
|
-
constructor(url) {
|
|
5
|
-
super();
|
|
4
|
+
constructor(url, network) {
|
|
5
|
+
super(network);
|
|
6
6
|
this.wsUrl = this.providerUrl(url);
|
|
7
7
|
}
|
|
8
8
|
_send(payload) {
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { UTXO } from '../bitcoin/UTXOs.js';
|
|
2
2
|
import { JSONRpcMethods } from '../providers/interfaces/JSONRpcMethods.js';
|
|
3
|
+
const AUTO_PURGE_AFTER = 1000 * 60;
|
|
3
4
|
export class UTXOsManager {
|
|
4
5
|
provider;
|
|
5
6
|
spentUTXOs = [];
|
|
6
7
|
pendingUTXOs = [];
|
|
8
|
+
lastCleanup = Date.now();
|
|
7
9
|
constructor(provider) {
|
|
8
10
|
this.provider = provider;
|
|
9
11
|
}
|
|
@@ -16,6 +18,7 @@ export class UTXOsManager {
|
|
|
16
18
|
clean() {
|
|
17
19
|
this.spentUTXOs = [];
|
|
18
20
|
this.pendingUTXOs = [];
|
|
21
|
+
this.lastCleanup = Date.now();
|
|
19
22
|
}
|
|
20
23
|
async getUTXOs({ address, optimize = true, mergePendingUTXOs = true, filterSpentUTXOs = true, }) {
|
|
21
24
|
const fetchedData = await this.fetchUTXOs(address, optimize);
|
|
@@ -53,6 +56,9 @@ export class UTXOsManager {
|
|
|
53
56
|
return utxoUntilAmount;
|
|
54
57
|
}
|
|
55
58
|
async fetchUTXOs(address, optimize = false) {
|
|
59
|
+
if (Date.now() - this.lastCleanup > AUTO_PURGE_AFTER) {
|
|
60
|
+
this.clean();
|
|
61
|
+
}
|
|
56
62
|
const addressStr = address.toString();
|
|
57
63
|
const payload = this.provider.buildJsonRpcPayload(JSONRpcMethods.GET_UTXOS, [addressStr, optimize]);
|
|
58
64
|
const rawUXTOs = await this.provider.callPayloadSingle(payload);
|
package/package.json
CHANGED
package/src/_version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '1.1.
|
|
1
|
+
export const version = '1.1.4';
|