opnet 1.0.39 → 1.0.40
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/browser/_version.d.ts +1 -1
- package/browser/index.js +1 -1
- package/build/_version.d.ts +1 -1
- package/build/_version.js +1 -1
- package/build/abi/shared/json/MOTOSWAP_POOL_ABI.js +0 -2
- package/build/scripts/testMethodsReg.js +4 -12
- package/cjs/_version.d.ts +1 -1
- package/cjs/_version.js +1 -1
- package/cjs/abi/shared/interfaces/IMotoContract.d.ts +6 -0
- package/cjs/abi/shared/interfaces/IMotoContract.js +2 -0
- package/cjs/abi/shared/interfaces/IMotoswapFactoryContract.d.ts +7 -0
- package/cjs/abi/shared/interfaces/IMotoswapFactoryContract.js +2 -0
- package/cjs/abi/shared/interfaces/IMotoswapPoolContract.d.ts +13 -0
- package/cjs/abi/shared/interfaces/IMotoswapPoolContract.js +2 -0
- package/cjs/abi/shared/interfaces/IMotoswapRouterContract.d.ts +15 -0
- package/cjs/abi/shared/interfaces/IMotoswapRouterContract.js +2 -0
- package/cjs/abi/shared/interfaces/IOP_20Contract.d.ts +16 -0
- package/cjs/abi/shared/interfaces/IOP_20Contract.js +2 -0
- package/cjs/abi/shared/interfaces/IOP_NETContract.d.ts +7 -0
- package/cjs/abi/shared/interfaces/IOP_NETContract.js +2 -0
- package/cjs/abi/shared/interfaces/IStackingContract.d.ts +11 -0
- package/cjs/abi/shared/interfaces/IStackingContract.js +2 -0
- package/cjs/abi/shared/interfaces/IWBTCContract.d.ts +8 -0
- package/cjs/abi/shared/interfaces/IWBTCContract.js +2 -0
- package/cjs/abi/shared/json/MOTOSWAP_FACTORY_ABI.d.ts +3 -0
- package/cjs/abi/shared/json/MOTOSWAP_FACTORY_ABI.js +74 -0
- package/cjs/abi/shared/json/MOTOSWAP_POOL_ABI.d.ts +3 -0
- package/cjs/abi/shared/json/MOTOSWAP_POOL_ABI.js +280 -0
- package/cjs/abi/shared/json/MOTOSWAP_ROUTER_ABI.d.ts +2 -0
- package/cjs/abi/shared/json/MOTOSWAP_ROUTER_ABI.js +277 -0
- package/cjs/abi/shared/json/MOTO_TOKEN_ABI.d.ts +2 -0
- package/cjs/abi/shared/json/MOTO_TOKEN_ABI.js +25 -0
- package/cjs/abi/shared/json/OP_20_ABI.d.ts +3 -0
- package/cjs/abi/shared/json/OP_20_ABI.js +259 -0
- package/cjs/abi/shared/json/OP_NET_ABI.d.ts +2 -0
- package/cjs/abi/shared/json/OP_NET_ABI.js +34 -0
- package/cjs/abi/shared/json/STAKING_ABI.d.ts +3 -0
- package/cjs/abi/shared/json/STAKING_ABI.js +132 -0
- package/cjs/abi/shared/json/WBTC_ABI.d.ts +3 -0
- package/cjs/abi/shared/json/WBTC_ABI.js +60 -0
- package/cjs/common/CommonTypes.d.ts +2 -1
- package/cjs/contracts/CallResult.d.ts +6 -2
- package/cjs/contracts/CallResult.js +14 -6
- package/cjs/contracts/Contract.d.ts +8 -4
- package/cjs/contracts/Contract.js +172 -19
- package/cjs/contracts/interfaces/ICallResult.d.ts +1 -0
- package/cjs/contracts/interfaces/IContract.d.ts +3 -0
- package/cjs/opnet.d.ts +18 -0
- package/cjs/opnet.js +18 -0
- package/cjs/providers/AbstractRpcProvider.d.ts +5 -3
- package/cjs/providers/AbstractRpcProvider.js +41 -7
- package/cjs/providers/JSONRpcProvider.d.ts +1 -1
- package/cjs/scripts/testMethods.js +3 -10
- package/cjs/scripts/testMethodsReg.js +6 -8
- package/cjs/scripts/testWBTCContract.d.ts +1 -0
- package/cjs/scripts/testWBTCContract.js +13 -0
- package/cjs/transactions/TransactionParser.js +7 -0
- package/cjs/transactions/decoders/UnwrapTransaction.d.ts +11 -0
- package/cjs/transactions/decoders/UnwrapTransaction.js +33 -0
- package/cjs/transactions/interfaces/transactions/IUnwrapTransaction.d.ts +28 -0
- package/cjs/transactions/interfaces/transactions/IUnwrapTransaction.js +2 -0
- package/package.json +1 -1
- package/src/_version.ts +1 -1
- package/src/abi/shared/json/MOTOSWAP_POOL_ABI.ts +0 -4
- package/src/scripts/testMethodsReg.ts +8 -3
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.STAKING_ABI = exports.StackingEvents = void 0;
|
|
4
|
+
const bsi_binary_1 = require("@btc-vision/bsi-binary");
|
|
5
|
+
const BitcoinAbiTypes_js_1 = require("../../BitcoinAbiTypes.js");
|
|
6
|
+
exports.StackingEvents = [
|
|
7
|
+
{
|
|
8
|
+
name: 'Stake',
|
|
9
|
+
values: [
|
|
10
|
+
{
|
|
11
|
+
name: 'amount',
|
|
12
|
+
type: bsi_binary_1.ABIDataTypes.UINT256,
|
|
13
|
+
},
|
|
14
|
+
],
|
|
15
|
+
type: BitcoinAbiTypes_js_1.BitcoinAbiTypes.Event,
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
name: 'Unstake',
|
|
19
|
+
values: [
|
|
20
|
+
{
|
|
21
|
+
name: 'amount',
|
|
22
|
+
type: bsi_binary_1.ABIDataTypes.UINT256,
|
|
23
|
+
},
|
|
24
|
+
],
|
|
25
|
+
type: BitcoinAbiTypes_js_1.BitcoinAbiTypes.Event,
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
name: 'Claim',
|
|
29
|
+
values: [
|
|
30
|
+
{
|
|
31
|
+
name: 'amount',
|
|
32
|
+
type: bsi_binary_1.ABIDataTypes.UINT256,
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
type: BitcoinAbiTypes_js_1.BitcoinAbiTypes.Event,
|
|
36
|
+
},
|
|
37
|
+
];
|
|
38
|
+
exports.STAKING_ABI = [
|
|
39
|
+
{
|
|
40
|
+
name: 'stake',
|
|
41
|
+
inputs: [
|
|
42
|
+
{
|
|
43
|
+
name: 'amount',
|
|
44
|
+
type: bsi_binary_1.ABIDataTypes.UINT256,
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
outputs: [
|
|
48
|
+
{
|
|
49
|
+
name: 'success',
|
|
50
|
+
type: bsi_binary_1.ABIDataTypes.BOOL,
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
type: BitcoinAbiTypes_js_1.BitcoinAbiTypes.Function,
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
name: 'unstake',
|
|
57
|
+
inputs: [],
|
|
58
|
+
outputs: [
|
|
59
|
+
{
|
|
60
|
+
name: 'success',
|
|
61
|
+
type: bsi_binary_1.ABIDataTypes.BOOL,
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
type: BitcoinAbiTypes_js_1.BitcoinAbiTypes.Function,
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
name: 'stakedAmount',
|
|
68
|
+
inputs: [
|
|
69
|
+
{
|
|
70
|
+
name: 'address',
|
|
71
|
+
type: bsi_binary_1.ABIDataTypes.ADDRESS,
|
|
72
|
+
},
|
|
73
|
+
],
|
|
74
|
+
outputs: [
|
|
75
|
+
{
|
|
76
|
+
name: 'amount',
|
|
77
|
+
type: bsi_binary_1.ABIDataTypes.UINT256,
|
|
78
|
+
},
|
|
79
|
+
],
|
|
80
|
+
type: BitcoinAbiTypes_js_1.BitcoinAbiTypes.Function,
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
name: 'stakedReward',
|
|
84
|
+
inputs: [
|
|
85
|
+
{
|
|
86
|
+
name: 'address',
|
|
87
|
+
type: bsi_binary_1.ABIDataTypes.ADDRESS,
|
|
88
|
+
},
|
|
89
|
+
],
|
|
90
|
+
outputs: [
|
|
91
|
+
{
|
|
92
|
+
name: 'amount',
|
|
93
|
+
type: bsi_binary_1.ABIDataTypes.UINT256,
|
|
94
|
+
},
|
|
95
|
+
],
|
|
96
|
+
type: BitcoinAbiTypes_js_1.BitcoinAbiTypes.Function,
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
name: 'claim',
|
|
100
|
+
inputs: [],
|
|
101
|
+
outputs: [
|
|
102
|
+
{
|
|
103
|
+
name: 'success',
|
|
104
|
+
type: bsi_binary_1.ABIDataTypes.BOOL,
|
|
105
|
+
},
|
|
106
|
+
],
|
|
107
|
+
type: BitcoinAbiTypes_js_1.BitcoinAbiTypes.Function,
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
name: 'rewardPool',
|
|
111
|
+
inputs: [],
|
|
112
|
+
outputs: [
|
|
113
|
+
{
|
|
114
|
+
name: 'reward',
|
|
115
|
+
type: bsi_binary_1.ABIDataTypes.UINT256,
|
|
116
|
+
},
|
|
117
|
+
],
|
|
118
|
+
type: BitcoinAbiTypes_js_1.BitcoinAbiTypes.Function,
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
name: 'totalStaked',
|
|
122
|
+
inputs: [],
|
|
123
|
+
outputs: [
|
|
124
|
+
{
|
|
125
|
+
name: 'total',
|
|
126
|
+
type: bsi_binary_1.ABIDataTypes.UINT256,
|
|
127
|
+
},
|
|
128
|
+
],
|
|
129
|
+
type: BitcoinAbiTypes_js_1.BitcoinAbiTypes.Function,
|
|
130
|
+
},
|
|
131
|
+
...exports.StackingEvents,
|
|
132
|
+
];
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WBTC_ABI = exports.WBTCEvents = void 0;
|
|
4
|
+
const bsi_binary_1 = require("@btc-vision/bsi-binary");
|
|
5
|
+
const BitcoinAbiTypes_js_1 = require("../../BitcoinAbiTypes.js");
|
|
6
|
+
const OP_20_ABI_js_1 = require("./OP_20_ABI.js");
|
|
7
|
+
const STAKING_ABI_js_1 = require("./STAKING_ABI.js");
|
|
8
|
+
exports.WBTCEvents = [
|
|
9
|
+
{
|
|
10
|
+
name: 'WithdrawalRequest',
|
|
11
|
+
values: [
|
|
12
|
+
{
|
|
13
|
+
name: 'address',
|
|
14
|
+
type: bsi_binary_1.ABIDataTypes.ADDRESS,
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
name: 'amount',
|
|
18
|
+
type: bsi_binary_1.ABIDataTypes.UINT256,
|
|
19
|
+
},
|
|
20
|
+
],
|
|
21
|
+
type: BitcoinAbiTypes_js_1.BitcoinAbiTypes.Event,
|
|
22
|
+
},
|
|
23
|
+
];
|
|
24
|
+
exports.WBTC_ABI = [
|
|
25
|
+
{
|
|
26
|
+
name: 'requestWithdrawal',
|
|
27
|
+
inputs: [
|
|
28
|
+
{
|
|
29
|
+
name: 'amount',
|
|
30
|
+
type: bsi_binary_1.ABIDataTypes.UINT256,
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
outputs: [
|
|
34
|
+
{
|
|
35
|
+
name: 'success',
|
|
36
|
+
type: bsi_binary_1.ABIDataTypes.BOOL,
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
type: BitcoinAbiTypes_js_1.BitcoinAbiTypes.Function,
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
name: 'withdrawableBalanceOf',
|
|
43
|
+
inputs: [
|
|
44
|
+
{
|
|
45
|
+
name: 'address',
|
|
46
|
+
type: bsi_binary_1.ABIDataTypes.ADDRESS,
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
outputs: [
|
|
50
|
+
{
|
|
51
|
+
name: 'balance',
|
|
52
|
+
type: bsi_binary_1.ABIDataTypes.UINT256,
|
|
53
|
+
},
|
|
54
|
+
],
|
|
55
|
+
type: BitcoinAbiTypes_js_1.BitcoinAbiTypes.Function,
|
|
56
|
+
},
|
|
57
|
+
...exports.WBTCEvents,
|
|
58
|
+
...STAKING_ABI_js_1.STAKING_ABI,
|
|
59
|
+
...OP_20_ABI_js_1.OP_20_ABI,
|
|
60
|
+
];
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { Address } from '@btc-vision/bsi-binary';
|
|
1
2
|
import { BitcoinAddress } from '../bitcoin/BitcoinAddress.js';
|
|
2
3
|
export type BitcoinAddressLike = string | BitcoinAddress;
|
|
3
4
|
export type PointerLike = bigint | string;
|
|
4
|
-
export type DecodedCallResult = bigint | string | boolean | number | Uint8Array | Array<bigint> | Array<string> | Array<boolean> | Array<number> | Array<Uint8Array>;
|
|
5
|
+
export type DecodedCallResult = bigint | string | boolean | number | Uint8Array | Array<bigint> | Array<string> | Array<boolean> | Array<number> | Array<Uint8Array> | Map<Address, bigint>;
|
|
5
6
|
export type Numeric = number | bigint;
|
|
6
7
|
export type BigNumberish = Numeric | string;
|
|
7
8
|
export type BlockTag = BigNumberish | 'latest' | 'pending' | 'earliest';
|
|
@@ -1,15 +1,19 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import { BinaryReader, NetEvent } from '@btc-vision/bsi-binary';
|
|
2
3
|
import { DecodedCallResult } from '../common/CommonTypes.js';
|
|
3
4
|
import { ContractDecodedObjectResult, DecodedOutput } from './Contract.js';
|
|
4
5
|
import { IAccessList } from './interfaces/IAccessList.js';
|
|
5
6
|
import { ICallResultData } from './interfaces/ICallResult.js';
|
|
6
|
-
export declare class CallResult<T extends ContractDecodedObjectResult = {}> implements ICallResultData {
|
|
7
|
+
export declare class CallResult<T extends ContractDecodedObjectResult = {}> implements Omit<ICallResultData, 'estimatedGas'> {
|
|
7
8
|
readonly result: BinaryReader;
|
|
8
9
|
readonly events: NetEvent[];
|
|
9
10
|
readonly accessList: IAccessList;
|
|
11
|
+
calldata: Buffer | undefined;
|
|
12
|
+
readonly estimatedGas: bigint | undefined;
|
|
10
13
|
readonly decoded: Array<DecodedCallResult>;
|
|
11
14
|
properties: T;
|
|
12
|
-
constructor(
|
|
15
|
+
constructor(callResult: ICallResultData);
|
|
13
16
|
setDecoded(decoded: DecodedOutput): void;
|
|
17
|
+
setCalldata(calldata: Buffer): void;
|
|
14
18
|
private base64ToUint8Array;
|
|
15
19
|
}
|
|
@@ -6,20 +6,28 @@ class CallResult {
|
|
|
6
6
|
result;
|
|
7
7
|
events;
|
|
8
8
|
accessList;
|
|
9
|
+
calldata;
|
|
10
|
+
estimatedGas;
|
|
9
11
|
decoded = [];
|
|
10
12
|
properties = {};
|
|
11
|
-
constructor(
|
|
12
|
-
this.events =
|
|
13
|
-
this.accessList =
|
|
13
|
+
constructor(callResult) {
|
|
14
|
+
this.events = callResult.events;
|
|
15
|
+
this.accessList = callResult.accessList;
|
|
16
|
+
if (callResult.estimatedGas) {
|
|
17
|
+
this.estimatedGas = BigInt(callResult.estimatedGas);
|
|
18
|
+
}
|
|
14
19
|
this.result =
|
|
15
|
-
typeof
|
|
16
|
-
? new bsi_binary_1.BinaryReader(this.base64ToUint8Array(
|
|
17
|
-
:
|
|
20
|
+
typeof callResult.result === 'string'
|
|
21
|
+
? new bsi_binary_1.BinaryReader(this.base64ToUint8Array(callResult.result))
|
|
22
|
+
: callResult.result;
|
|
18
23
|
}
|
|
19
24
|
setDecoded(decoded) {
|
|
20
25
|
this.properties = Object.freeze(decoded.obj);
|
|
21
26
|
this.decoded.push(...decoded.values);
|
|
22
27
|
}
|
|
28
|
+
setCalldata(calldata) {
|
|
29
|
+
this.calldata = calldata;
|
|
30
|
+
}
|
|
23
31
|
base64ToUint8Array(base64) {
|
|
24
32
|
return bsi_binary_1.BufferHelper.bufferToUint8Array(Buffer.from(base64, 'base64'));
|
|
25
33
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Address, NetEvent } from '@btc-vision/bsi-binary';
|
|
2
3
|
import { BaseContractProperty } from '../abi/BaseContractProperty.js';
|
|
3
4
|
import { BitcoinInterface } from '../abi/BitcoinInterface.js';
|
|
4
5
|
import { BaseContractProperties } from '../abi/interfaces/BaseContractProperties.js';
|
|
@@ -20,11 +21,14 @@ export declare abstract class IBaseContract<T extends BaseContractProperties> im
|
|
|
20
21
|
readonly address: BitcoinAddressLike;
|
|
21
22
|
readonly interface: BitcoinInterface;
|
|
22
23
|
readonly provider: AbstractRpcProvider;
|
|
24
|
+
from?: Address;
|
|
23
25
|
readonly [internal]: keyof T | undefined;
|
|
24
26
|
private events;
|
|
25
|
-
protected constructor(address: BitcoinAddressLike, abi: BitcoinInterface | BitcoinInterfaceAbi, provider: AbstractRpcProvider);
|
|
27
|
+
protected constructor(address: BitcoinAddressLike, abi: BitcoinInterface | BitcoinInterfaceAbi, provider: AbstractRpcProvider, from?: Address);
|
|
28
|
+
setSender(sender: Address): void;
|
|
26
29
|
decodeEvents(events: NetEvent[] | ContractEvents): OPNetEvent[];
|
|
27
30
|
decodeEvent(event: NetEvent): OPNetEvent;
|
|
31
|
+
encodeCalldata(functionName: string, args: unknown[]): Buffer;
|
|
28
32
|
protected getFunction(name: symbol): BaseContractProperty | undefined | string | number | symbol;
|
|
29
33
|
private defineInternalFunctions;
|
|
30
34
|
private encodeFunctionData;
|
|
@@ -33,8 +37,8 @@ export declare abstract class IBaseContract<T extends BaseContractProperties> im
|
|
|
33
37
|
private callFunction;
|
|
34
38
|
}
|
|
35
39
|
export declare class BaseContract<T extends BaseContractProperties> extends IBaseContract<T> {
|
|
36
|
-
constructor(address: BitcoinAddressLike, abi: BitcoinInterface | BitcoinInterfaceAbi, provider: AbstractRpcProvider);
|
|
40
|
+
constructor(address: BitcoinAddressLike, abi: BitcoinInterface | BitcoinInterfaceAbi, provider: AbstractRpcProvider, sender?: Address);
|
|
37
41
|
private proxify;
|
|
38
42
|
}
|
|
39
|
-
export declare function getContract<T extends BaseContractProperties>(address: BitcoinAddressLike, abi: BitcoinInterface | BitcoinInterfaceAbi, provider: AbstractRpcProvider): BaseContract<T> & Omit<T, keyof BaseContract<T>>;
|
|
43
|
+
export declare function getContract<T extends BaseContractProperties>(address: BitcoinAddressLike, abi: BitcoinInterface | BitcoinInterfaceAbi, provider: AbstractRpcProvider, sender?: Address): BaseContract<T> & Omit<T, keyof BaseContract<T>>;
|
|
40
44
|
export {};
|
|
@@ -11,15 +11,20 @@ class IBaseContract {
|
|
|
11
11
|
address;
|
|
12
12
|
interface;
|
|
13
13
|
provider;
|
|
14
|
+
from;
|
|
14
15
|
[internal];
|
|
15
16
|
events = new Map();
|
|
16
|
-
constructor(address, abi, provider) {
|
|
17
|
+
constructor(address, abi, provider, from) {
|
|
17
18
|
this.address = address;
|
|
18
19
|
this.provider = provider;
|
|
19
20
|
this.interface = BitcoinInterface_js_1.BitcoinInterface.from(abi);
|
|
21
|
+
this.from = from;
|
|
20
22
|
Object.defineProperty(this, internal, { value: {} });
|
|
21
23
|
this.defineInternalFunctions();
|
|
22
24
|
}
|
|
25
|
+
setSender(sender) {
|
|
26
|
+
this.from = sender;
|
|
27
|
+
}
|
|
23
28
|
decodeEvents(events) {
|
|
24
29
|
const decodedEvents = [];
|
|
25
30
|
if (!Array.isArray(events)) {
|
|
@@ -44,6 +49,15 @@ class IBaseContract {
|
|
|
44
49
|
decodedEvent.setDecoded(out);
|
|
45
50
|
return decodedEvent;
|
|
46
51
|
}
|
|
52
|
+
encodeCalldata(functionName, args) {
|
|
53
|
+
for (const element of this.interface.abi) {
|
|
54
|
+
if (element.name === functionName) {
|
|
55
|
+
const data = this.encodeFunctionData(element, args);
|
|
56
|
+
return Buffer.from(data.getBuffer());
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
throw new Error(`Function not found: ${functionName}`);
|
|
60
|
+
}
|
|
47
61
|
getFunction(name) {
|
|
48
62
|
const key = name;
|
|
49
63
|
return this[key];
|
|
@@ -51,16 +65,24 @@ class IBaseContract {
|
|
|
51
65
|
defineInternalFunctions() {
|
|
52
66
|
for (const element of this.interface.abi) {
|
|
53
67
|
switch (element.type) {
|
|
54
|
-
case BitcoinAbiTypes_js_1.BitcoinAbiTypes.Function:
|
|
68
|
+
case BitcoinAbiTypes_js_1.BitcoinAbiTypes.Function: {
|
|
69
|
+
if (this[element.name]) {
|
|
70
|
+
throw new Error(`Duplicate function found in the ABI: ${element.name}.`);
|
|
71
|
+
}
|
|
55
72
|
Object.defineProperty(this, element.name, {
|
|
56
73
|
value: this.callFunction(element).bind(this),
|
|
57
74
|
});
|
|
58
75
|
break;
|
|
59
|
-
|
|
76
|
+
}
|
|
77
|
+
case BitcoinAbiTypes_js_1.BitcoinAbiTypes.Event: {
|
|
78
|
+
if (this.events.has(element.name)) {
|
|
79
|
+
throw new Error(`Duplicate event found in the ABI: ${element.name}.`);
|
|
80
|
+
}
|
|
60
81
|
this.events.set(element.name, element);
|
|
61
82
|
break;
|
|
83
|
+
}
|
|
62
84
|
default:
|
|
63
|
-
|
|
85
|
+
throw new Error(`Unsupported type.`);
|
|
64
86
|
}
|
|
65
87
|
}
|
|
66
88
|
}
|
|
@@ -83,60 +105,147 @@ class IBaseContract {
|
|
|
83
105
|
const type = abi.type;
|
|
84
106
|
const name = abi.name;
|
|
85
107
|
switch (type) {
|
|
86
|
-
case bsi_binary_1.ABIDataTypes.UINT256:
|
|
108
|
+
case bsi_binary_1.ABIDataTypes.UINT256: {
|
|
87
109
|
if (typeof value !== 'bigint') {
|
|
88
110
|
throw new Error(`Expected value to be of type bigint (${name})`);
|
|
89
111
|
}
|
|
90
112
|
writer.writeU256(value);
|
|
91
113
|
break;
|
|
92
|
-
|
|
114
|
+
}
|
|
115
|
+
case bsi_binary_1.ABIDataTypes.BOOL: {
|
|
93
116
|
if (typeof value !== 'boolean') {
|
|
94
117
|
throw new Error(`Expected value to be of type boolean (${name})`);
|
|
95
118
|
}
|
|
96
119
|
writer.writeBoolean(value);
|
|
97
120
|
break;
|
|
98
|
-
|
|
121
|
+
}
|
|
122
|
+
case bsi_binary_1.ABIDataTypes.STRING: {
|
|
99
123
|
if (typeof value !== 'string') {
|
|
100
124
|
throw new Error(`Expected value to be of type string (${name})`);
|
|
101
125
|
}
|
|
102
126
|
writer.writeStringWithLength(value);
|
|
103
127
|
break;
|
|
104
|
-
|
|
128
|
+
}
|
|
129
|
+
case bsi_binary_1.ABIDataTypes.ADDRESS: {
|
|
105
130
|
const address = value;
|
|
106
131
|
writer.writeAddress(address.toString());
|
|
107
132
|
break;
|
|
108
|
-
|
|
133
|
+
}
|
|
134
|
+
case bsi_binary_1.ABIDataTypes.TUPLE: {
|
|
109
135
|
if (!(value instanceof Array)) {
|
|
110
136
|
throw new Error(`Expected value to be of type Array (${name})`);
|
|
111
137
|
}
|
|
112
138
|
writer.writeTuple(value);
|
|
113
139
|
break;
|
|
114
|
-
|
|
140
|
+
}
|
|
141
|
+
case bsi_binary_1.ABIDataTypes.UINT8: {
|
|
115
142
|
if (typeof value !== 'number') {
|
|
116
143
|
throw new Error(`Expected value to be of type number (${name})`);
|
|
117
144
|
}
|
|
118
145
|
writer.writeU8(value);
|
|
119
146
|
break;
|
|
120
|
-
|
|
147
|
+
}
|
|
148
|
+
case bsi_binary_1.ABIDataTypes.UINT16: {
|
|
121
149
|
if (typeof value !== 'number') {
|
|
122
150
|
throw new Error(`Expected value to be of type number (${name})`);
|
|
123
151
|
}
|
|
124
152
|
writer.writeU16(value);
|
|
125
153
|
break;
|
|
126
|
-
|
|
154
|
+
}
|
|
155
|
+
case bsi_binary_1.ABIDataTypes.UINT32: {
|
|
127
156
|
if (typeof value !== 'number') {
|
|
128
157
|
throw new Error(`Expected value to be of type number (${name})`);
|
|
129
158
|
}
|
|
130
159
|
writer.writeU32(value);
|
|
131
160
|
break;
|
|
132
|
-
|
|
161
|
+
}
|
|
162
|
+
case bsi_binary_1.ABIDataTypes.BYTES32: {
|
|
133
163
|
if (!(value instanceof Uint8Array)) {
|
|
134
164
|
throw new Error(`Expected value to be of type Uint8Array (${name})`);
|
|
135
165
|
}
|
|
136
166
|
writer.writeBytes(value);
|
|
137
167
|
break;
|
|
138
|
-
|
|
168
|
+
}
|
|
169
|
+
case bsi_binary_1.ABIDataTypes.ADDRESS_UINT256_TUPLE: {
|
|
170
|
+
if (!(value instanceof Map)) {
|
|
171
|
+
throw new Error(`Expected value to be of type Array (${name})`);
|
|
172
|
+
}
|
|
173
|
+
writer.writeAddressValueTupleMap(value);
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
case bsi_binary_1.ABIDataTypes.BYTES: {
|
|
177
|
+
if (!(value instanceof Uint8Array)) {
|
|
178
|
+
throw new Error(`Expected value to be of type Uint8Array (${name})`);
|
|
179
|
+
}
|
|
180
|
+
writer.writeBytesWithLength(value);
|
|
181
|
+
break;
|
|
182
|
+
}
|
|
183
|
+
case bsi_binary_1.ABIDataTypes.UINT64: {
|
|
184
|
+
if (typeof value !== 'bigint') {
|
|
185
|
+
throw new Error(`Expected value to be of type bigint (${name})`);
|
|
186
|
+
}
|
|
187
|
+
writer.writeU64(value);
|
|
188
|
+
break;
|
|
189
|
+
}
|
|
190
|
+
case bsi_binary_1.ABIDataTypes.ARRAY_OF_ADDRESSES: {
|
|
191
|
+
if (!(value instanceof Array)) {
|
|
192
|
+
throw new Error(`Expected value to be of type Array (${name})`);
|
|
193
|
+
}
|
|
194
|
+
writer.writeAddressArray(value);
|
|
195
|
+
break;
|
|
196
|
+
}
|
|
197
|
+
case bsi_binary_1.ABIDataTypes.ARRAY_OF_UINT256: {
|
|
198
|
+
if (!(value instanceof Array)) {
|
|
199
|
+
throw new Error(`Expected value to be of type Array (${name})`);
|
|
200
|
+
}
|
|
201
|
+
writer.writeU256Array(value);
|
|
202
|
+
break;
|
|
203
|
+
}
|
|
204
|
+
case bsi_binary_1.ABIDataTypes.ARRAY_OF_UINT32: {
|
|
205
|
+
if (!(value instanceof Array)) {
|
|
206
|
+
throw new Error(`Expected value to be of type Array (${name})`);
|
|
207
|
+
}
|
|
208
|
+
writer.writeU32Array(value);
|
|
209
|
+
break;
|
|
210
|
+
}
|
|
211
|
+
case bsi_binary_1.ABIDataTypes.ARRAY_OF_STRING: {
|
|
212
|
+
if (!(value instanceof Array)) {
|
|
213
|
+
throw new Error(`Expected value to be of type Array (${name})`);
|
|
214
|
+
}
|
|
215
|
+
writer.writeStringArray(value);
|
|
216
|
+
break;
|
|
217
|
+
}
|
|
218
|
+
case bsi_binary_1.ABIDataTypes.ARRAY_OF_BYTES: {
|
|
219
|
+
if (!(value instanceof Array)) {
|
|
220
|
+
throw new Error(`Expected value to be of type Array (${name})`);
|
|
221
|
+
}
|
|
222
|
+
writer.writeBytesArray(value);
|
|
223
|
+
break;
|
|
224
|
+
}
|
|
225
|
+
case bsi_binary_1.ABIDataTypes.ARRAY_OF_UINT64: {
|
|
226
|
+
if (!(value instanceof Array)) {
|
|
227
|
+
throw new Error(`Expected value to be of type Array (${name})`);
|
|
228
|
+
}
|
|
229
|
+
writer.writeU64Array(value);
|
|
230
|
+
break;
|
|
231
|
+
}
|
|
232
|
+
case bsi_binary_1.ABIDataTypes.ARRAY_OF_UINT8: {
|
|
233
|
+
if (!(value instanceof Array)) {
|
|
234
|
+
throw new Error(`Expected value to be of type Array (${name})`);
|
|
235
|
+
}
|
|
236
|
+
writer.writeU8Array(value);
|
|
237
|
+
break;
|
|
238
|
+
}
|
|
239
|
+
case bsi_binary_1.ABIDataTypes.ARRAY_OF_UINT16: {
|
|
240
|
+
if (!(value instanceof Array)) {
|
|
241
|
+
throw new Error(`Expected value to be of type Array (${name})`);
|
|
242
|
+
}
|
|
243
|
+
writer.writeU16Array(value);
|
|
244
|
+
break;
|
|
245
|
+
}
|
|
246
|
+
default: {
|
|
139
247
|
throw new Error(`Unsupported type: ${type} (${name})`);
|
|
248
|
+
}
|
|
140
249
|
}
|
|
141
250
|
}
|
|
142
251
|
decodeOutput(abi, reader) {
|
|
@@ -174,6 +283,49 @@ class IBaseContract {
|
|
|
174
283
|
case bsi_binary_1.ABIDataTypes.BYTES32:
|
|
175
284
|
decodedResult = reader.readBytes(32);
|
|
176
285
|
break;
|
|
286
|
+
case bsi_binary_1.ABIDataTypes.ADDRESS_UINT256_TUPLE:
|
|
287
|
+
decodedResult = reader.readAddressValueTuple();
|
|
288
|
+
break;
|
|
289
|
+
case bsi_binary_1.ABIDataTypes.BYTES: {
|
|
290
|
+
decodedResult = reader.readBytesWithLength();
|
|
291
|
+
break;
|
|
292
|
+
}
|
|
293
|
+
case bsi_binary_1.ABIDataTypes.UINT64: {
|
|
294
|
+
decodedResult = reader.readU64();
|
|
295
|
+
break;
|
|
296
|
+
}
|
|
297
|
+
case bsi_binary_1.ABIDataTypes.ARRAY_OF_ADDRESSES: {
|
|
298
|
+
decodedResult = reader.readAddressArray();
|
|
299
|
+
break;
|
|
300
|
+
}
|
|
301
|
+
case bsi_binary_1.ABIDataTypes.ARRAY_OF_UINT256: {
|
|
302
|
+
decodedResult = reader.readU256Array();
|
|
303
|
+
break;
|
|
304
|
+
}
|
|
305
|
+
case bsi_binary_1.ABIDataTypes.ARRAY_OF_UINT32: {
|
|
306
|
+
decodedResult = reader.readU32Array();
|
|
307
|
+
break;
|
|
308
|
+
}
|
|
309
|
+
case bsi_binary_1.ABIDataTypes.ARRAY_OF_STRING: {
|
|
310
|
+
decodedResult = reader.readStringArray();
|
|
311
|
+
break;
|
|
312
|
+
}
|
|
313
|
+
case bsi_binary_1.ABIDataTypes.ARRAY_OF_BYTES: {
|
|
314
|
+
decodedResult = reader.readBytesArray();
|
|
315
|
+
break;
|
|
316
|
+
}
|
|
317
|
+
case bsi_binary_1.ABIDataTypes.ARRAY_OF_UINT64: {
|
|
318
|
+
decodedResult = reader.readU64Array();
|
|
319
|
+
break;
|
|
320
|
+
}
|
|
321
|
+
case bsi_binary_1.ABIDataTypes.ARRAY_OF_UINT8: {
|
|
322
|
+
decodedResult = reader.readU8Array();
|
|
323
|
+
break;
|
|
324
|
+
}
|
|
325
|
+
case bsi_binary_1.ABIDataTypes.ARRAY_OF_UINT16: {
|
|
326
|
+
decodedResult = reader.readU16Array();
|
|
327
|
+
break;
|
|
328
|
+
}
|
|
177
329
|
default:
|
|
178
330
|
throw new Error(`Unsupported type: ${type} (${name})`);
|
|
179
331
|
}
|
|
@@ -189,7 +341,7 @@ class IBaseContract {
|
|
|
189
341
|
return async (...args) => {
|
|
190
342
|
const data = this.encodeFunctionData(element, args);
|
|
191
343
|
const buffer = Buffer.from(data.getBuffer());
|
|
192
|
-
const response = await this.provider.call(this.address, buffer);
|
|
344
|
+
const response = await this.provider.call(this.address, buffer, this.from);
|
|
193
345
|
if ('error' in response) {
|
|
194
346
|
return response;
|
|
195
347
|
}
|
|
@@ -197,14 +349,15 @@ class IBaseContract {
|
|
|
197
349
|
? this.decodeOutput(element.outputs, response.result)
|
|
198
350
|
: { values: [], obj: {} };
|
|
199
351
|
response.setDecoded(decoded);
|
|
352
|
+
response.setCalldata(buffer);
|
|
200
353
|
return response;
|
|
201
354
|
};
|
|
202
355
|
}
|
|
203
356
|
}
|
|
204
357
|
exports.IBaseContract = IBaseContract;
|
|
205
358
|
class BaseContract extends IBaseContract {
|
|
206
|
-
constructor(address, abi, provider) {
|
|
207
|
-
super(address, abi, provider);
|
|
359
|
+
constructor(address, abi, provider, sender) {
|
|
360
|
+
super(address, abi, provider, sender);
|
|
208
361
|
return this.proxify();
|
|
209
362
|
}
|
|
210
363
|
proxify() {
|
|
@@ -238,8 +391,8 @@ exports.BaseContract = BaseContract;
|
|
|
238
391
|
function contractBase() {
|
|
239
392
|
return BaseContract;
|
|
240
393
|
}
|
|
241
|
-
function getContract(address, abi, provider) {
|
|
394
|
+
function getContract(address, abi, provider, sender) {
|
|
242
395
|
const base = contractBase();
|
|
243
|
-
return new base(address, abi, provider);
|
|
396
|
+
return new base(address, abi, provider, sender);
|
|
244
397
|
}
|
|
245
398
|
exports.getContract = getContract;
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import { NetEvent } from '@btc-vision/bsi-binary';
|
|
2
3
|
import { BitcoinAddressLike } from '../../common/CommonTypes.js';
|
|
3
4
|
import { ContractEvents } from '../../transactions/interfaces/ITransactionReceipt.js';
|
|
4
5
|
import { OPNetEvent } from '../OPNetEvent.js';
|
|
5
6
|
export interface IContract {
|
|
6
7
|
readonly address: BitcoinAddressLike;
|
|
8
|
+
setSender(sender: BitcoinAddressLike): void;
|
|
7
9
|
decodeEvents(events: NetEvent[] | ContractEvents): OPNetEvent[];
|
|
8
10
|
decodeEvent(event: NetEvent): OPNetEvent;
|
|
11
|
+
encodeCalldata(method: string, ...args: unknown[]): Buffer;
|
|
9
12
|
}
|
package/cjs/opnet.d.ts
CHANGED
|
@@ -45,8 +45,26 @@ export * from './providers/interfaces/JSONRpc.js';
|
|
|
45
45
|
export * from './providers/interfaces/JSONRpcMethods.js';
|
|
46
46
|
export * from './providers/interfaces/JSONRpcParams.js';
|
|
47
47
|
export * from './providers/interfaces/JSONRpcResult.js';
|
|
48
|
+
export * from './transactions/decoders/UnwrapTransaction.js';
|
|
49
|
+
export * from './transactions/interfaces/transactions/IUnwrapTransaction.js';
|
|
48
50
|
export * from './common/CommonTypes.js';
|
|
49
51
|
export * from './bitcoin/BitcoinAddress.js';
|
|
50
52
|
export * from './bitcoin/UTXOs.js';
|
|
51
53
|
export * from './bitcoin/interfaces/IUTXO.js';
|
|
52
54
|
export { ABIDataTypes } from '@btc-vision/bsi-binary';
|
|
55
|
+
export * from './abi/shared/json/OP_20_ABI.js';
|
|
56
|
+
export * from './abi/shared/json/OP_NET_ABI.js';
|
|
57
|
+
export * from './abi/shared/json/WBTC_ABI.js';
|
|
58
|
+
export * from './abi/shared/json/STAKING_ABI.js';
|
|
59
|
+
export * from './abi/shared/json/MOTOSWAP_FACTORY_ABI.js';
|
|
60
|
+
export * from './abi/shared/json/MOTO_TOKEN_ABI.js';
|
|
61
|
+
export * from './abi/shared/json/MOTOSWAP_POOL_ABI.js';
|
|
62
|
+
export * from './abi/shared/json/MOTOSWAP_ROUTER_ABI.js';
|
|
63
|
+
export * from './abi/shared/interfaces/IOP_20Contract.js';
|
|
64
|
+
export * from './abi/shared/interfaces/IOP_NETContract.js';
|
|
65
|
+
export * from './abi/shared/interfaces/IWBTCContract.js';
|
|
66
|
+
export * from './abi/shared/interfaces/IStackingContract.js';
|
|
67
|
+
export * from './abi/shared/interfaces/IMotoswapFactoryContract.js';
|
|
68
|
+
export * from './abi/shared/interfaces/IMotoContract.js';
|
|
69
|
+
export * from './abi/shared/interfaces/IMotoswapPoolContract.js';
|
|
70
|
+
export * from './abi/shared/interfaces/IMotoswapRouterContract.js';
|