@cityofzion/bs-ethereum 3.1.10 → 3.1.12
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/dist/BSEthereum.d.ts +4 -3
- package/dist/BSEthereum.js +19 -18
- package/dist/constants/BSEthereumConstants.d.ts +2 -2
- package/dist/constants/BSEthereumConstants.js +2 -1
- package/dist/services/blockchain-data/MoralisBDSEthereum.js +8 -24
- package/dist/services/blockchain-data/RpcBDSEthereum.js +3 -9
- package/dist/services/full-transactions-data/MoralisFullTransactionsDataServiceEthereum.js +2 -2
- package/dist/services/ledger/EthersLedgerServiceEthereum.js +1 -1
- package/dist/services/nft-data/GhostMarketNDSEthereum.d.ts +8 -0
- package/dist/services/nft-data/GhostMarketNDSEthereum.js +41 -0
- package/dist/services/wallet-connect/WalletConnectServiceEthereum.d.ts +79 -26
- package/dist/services/wallet-connect/WalletConnectServiceEthereum.js +206 -130
- package/dist/types.d.ts +1 -0
- package/package.json +3 -2
package/dist/BSEthereum.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { type TBSAccount, type TTransferIntent, type TBSToken, type TTransferParams, type TGetLedgerTransport, type ITokenService, type TBSNetwork, type IBlockchainDataService, type IExchangeDataService, type INftDataService, type IExplorerService, type TPingNetworkResponse, type
|
|
1
|
+
import { type TBSAccount, type TTransferIntent, type TBSToken, type TTransferParams, type TGetLedgerTransport, type ITokenService, type TBSNetwork, type IBlockchainDataService, type IExchangeDataService, type INftDataService, type IExplorerService, type TPingNetworkResponse, type IFullTransactionsDataService, type TTransactionDefault, type TBSNetworkId, BSBigUnitAmount } from '@cityofzion/blockchain-service';
|
|
2
2
|
import { ethers } from 'ethers';
|
|
3
3
|
import { EthersLedgerServiceEthereum } from './services/ledger/EthersLedgerServiceEthereum';
|
|
4
4
|
import type { IBSEthereum, TBSEthereumName, TBSEthereumNetworkId } from './types';
|
|
5
5
|
import { TypedDataSigner } from '@ethersproject/abstract-signer';
|
|
6
|
+
import { WalletConnectServiceEthereum } from './services/wallet-connect/WalletConnectServiceEthereum';
|
|
6
7
|
export declare class BSEthereum<N extends string = TBSEthereumName, A extends TBSNetworkId = TBSEthereumNetworkId> implements IBSEthereum<N, A> {
|
|
7
8
|
#private;
|
|
8
9
|
readonly name: N;
|
|
@@ -22,13 +23,13 @@ export declare class BSEthereum<N extends string = TBSEthereumName, A extends TB
|
|
|
22
23
|
nftDataService: INftDataService;
|
|
23
24
|
explorerService: IExplorerService;
|
|
24
25
|
tokenService: ITokenService;
|
|
25
|
-
walletConnectService:
|
|
26
|
+
walletConnectService: WalletConnectServiceEthereum<N, A>;
|
|
26
27
|
fullTransactionsDataService: IFullTransactionsDataService<N>;
|
|
27
28
|
constructor(name: N, network?: TBSNetwork<A>, getLedgerTransport?: TGetLedgerTransport<N>);
|
|
28
29
|
_generateSigner(account: TBSAccount<N>): Promise<ethers.Signer & TypedDataSigner>;
|
|
29
30
|
_buildTransferParams(intent: TTransferIntent): Promise<{
|
|
30
31
|
transactionParams: ethers.utils.Deferrable<ethers.providers.TransactionRequest>;
|
|
31
|
-
|
|
32
|
+
gasPriceBn: BSBigUnitAmount;
|
|
32
33
|
}>;
|
|
33
34
|
setNetwork(network: TBSNetwork<A>): void;
|
|
34
35
|
pingNetwork(url: string): Promise<TPingNetworkResponse>;
|
package/dist/BSEthereum.js
CHANGED
|
@@ -47,7 +47,6 @@ const blockchain_service_1 = require("@cityofzion/blockchain-service");
|
|
|
47
47
|
const ethers_1 = require("ethers");
|
|
48
48
|
const ethersJsonWallets = __importStar(require("@ethersproject/json-wallets"));
|
|
49
49
|
const ethersBytes = __importStar(require("@ethersproject/bytes"));
|
|
50
|
-
const ethersBigNumber = __importStar(require("@ethersproject/bignumber"));
|
|
51
50
|
const BSEthereumConstants_1 = require("./constants/BSEthereumConstants");
|
|
52
51
|
const EthersLedgerServiceEthereum_1 = require("./services/ledger/EthersLedgerServiceEthereum");
|
|
53
52
|
const BSEthereumHelper_1 = require("./helpers/BSEthereumHelper");
|
|
@@ -91,8 +90,9 @@ class BSEthereum {
|
|
|
91
90
|
}
|
|
92
91
|
async _buildTransferParams(intent) {
|
|
93
92
|
const provider = new ethers_1.ethers.providers.JsonRpcProvider(this.network.url);
|
|
94
|
-
const amount =
|
|
93
|
+
const amount = new blockchain_service_1.BSBigHumanAmount(intent.amount, intent.token.decimals).toUnit().toString();
|
|
95
94
|
const gasPrice = await provider.getGasPrice();
|
|
95
|
+
const gasPriceBn = new blockchain_service_1.BSBigUnitAmount(gasPrice.toString(), BSEthereumConstants_1.BSEthereumConstants.DEFAULT_DECIMALS);
|
|
96
96
|
let transactionParams = {
|
|
97
97
|
type: 2,
|
|
98
98
|
};
|
|
@@ -113,7 +113,7 @@ class BSEthereum {
|
|
|
113
113
|
}
|
|
114
114
|
return {
|
|
115
115
|
transactionParams,
|
|
116
|
-
|
|
116
|
+
gasPriceBn,
|
|
117
117
|
};
|
|
118
118
|
}
|
|
119
119
|
setNetwork(network) {
|
|
@@ -146,7 +146,7 @@ class BSEthereum {
|
|
|
146
146
|
return {
|
|
147
147
|
latency,
|
|
148
148
|
url,
|
|
149
|
-
height:
|
|
149
|
+
height: blockchain_service_1.BSBigNumber.ensureNumber(response.data.result),
|
|
150
150
|
};
|
|
151
151
|
}
|
|
152
152
|
validateAddress(address) {
|
|
@@ -220,21 +220,22 @@ class BSEthereum {
|
|
|
220
220
|
let nonce = await signer.getTransactionCount('pending');
|
|
221
221
|
for (const intent of intents) {
|
|
222
222
|
try {
|
|
223
|
-
const { transactionParams,
|
|
224
|
-
let gasLimit;
|
|
223
|
+
const { transactionParams, gasPriceBn } = await this._buildTransferParams(intent);
|
|
225
224
|
transactionParams.nonce = nonce++;
|
|
225
|
+
let gasLimitBn;
|
|
226
226
|
try {
|
|
227
|
-
|
|
227
|
+
const estimatedGas = await signer.estimateGas(transactionParams);
|
|
228
|
+
gasLimitBn = new blockchain_service_1.BSBigUnitAmount(estimatedGas.toString(), BSEthereumConstants_1.BSEthereumConstants.DEFAULT_DECIMALS);
|
|
228
229
|
}
|
|
229
230
|
catch {
|
|
230
|
-
|
|
231
|
+
gasLimitBn = BSEthereumConstants_1.BSEthereumConstants.DEFAULT_GAS_LIMIT_BN;
|
|
231
232
|
}
|
|
232
|
-
const fee =
|
|
233
|
+
const fee = gasPriceBn.multipliedBy(gasLimitBn).toHuman().toFormatted();
|
|
233
234
|
const transaction = await signer.sendTransaction({
|
|
234
235
|
...transactionParams,
|
|
235
|
-
gasLimit,
|
|
236
|
-
maxPriorityFeePerGas:
|
|
237
|
-
maxFeePerGas:
|
|
236
|
+
gasLimit: gasLimitBn.toString(),
|
|
237
|
+
maxPriorityFeePerGas: gasPriceBn.toString(),
|
|
238
|
+
maxFeePerGas: gasPriceBn.toString(),
|
|
238
239
|
});
|
|
239
240
|
const txId = transaction.hash;
|
|
240
241
|
if (txId) {
|
|
@@ -277,14 +278,14 @@ class BSEthereum {
|
|
|
277
278
|
}
|
|
278
279
|
async calculateTransferFee(params) {
|
|
279
280
|
const signer = await this._generateSigner(params.senderAccount);
|
|
280
|
-
let
|
|
281
|
+
let feeBn = new blockchain_service_1.BSBigUnitAmount(0, BSEthereumConstants_1.BSEthereumConstants.DEFAULT_DECIMALS);
|
|
281
282
|
for (const intent of params.intents) {
|
|
282
|
-
const {
|
|
283
|
-
const
|
|
284
|
-
const
|
|
285
|
-
|
|
283
|
+
const { gasPriceBn, transactionParams } = await this._buildTransferParams(intent);
|
|
284
|
+
const estimatedGas = await signer.estimateGas(transactionParams);
|
|
285
|
+
const intentFeeBn = gasPriceBn.multipliedBy(estimatedGas.toString());
|
|
286
|
+
feeBn = feeBn.plus(intentFeeBn);
|
|
286
287
|
}
|
|
287
|
-
return
|
|
288
|
+
return feeBn.toHuman().toFormatted();
|
|
288
289
|
}
|
|
289
290
|
async resolveNameServiceDomain(domainName) {
|
|
290
291
|
const provider = new ethers_1.ethers.providers.JsonRpcProvider(this.network.url);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { BSBigUnitAmount, type TBSNetwork } from '@cityofzion/blockchain-service';
|
|
2
2
|
import type { TBSEthereumNetworkId, TBSEthereumName } from '../types';
|
|
3
3
|
export declare class BSEthereumConstants {
|
|
4
4
|
static readonly DEFAULT_DECIMALS = 18;
|
|
5
|
-
static readonly
|
|
5
|
+
static readonly DEFAULT_GAS_LIMIT_BN: BSBigUnitAmount;
|
|
6
6
|
static readonly DEFAULT_BIP_DERIVATION_PATH = "m/44'/60'/0'/0/?";
|
|
7
7
|
static readonly NATIVE_SYMBOL_BY_NETWORK_ID: Record<TBSEthereumNetworkId, string>;
|
|
8
8
|
static readonly NATIVE_WRAPPED_HASH_BY_NETWORK_ID: Partial<Record<TBSEthereumNetworkId, string>>;
|
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
var _a;
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.BSEthereumConstants = void 0;
|
|
5
|
+
const blockchain_service_1 = require("@cityofzion/blockchain-service");
|
|
5
6
|
class BSEthereumConstants {
|
|
6
7
|
}
|
|
7
8
|
exports.BSEthereumConstants = BSEthereumConstants;
|
|
8
9
|
_a = BSEthereumConstants;
|
|
9
10
|
BSEthereumConstants.DEFAULT_DECIMALS = 18;
|
|
10
|
-
BSEthereumConstants.
|
|
11
|
+
BSEthereumConstants.DEFAULT_GAS_LIMIT_BN = new blockchain_service_1.BSBigUnitAmount(0x5208, _a.DEFAULT_DECIMALS);
|
|
11
12
|
BSEthereumConstants.DEFAULT_BIP_DERIVATION_PATH = "m/44'/60'/0'/0/?";
|
|
12
13
|
BSEthereumConstants.NATIVE_SYMBOL_BY_NETWORK_ID = {
|
|
13
14
|
'1': 'ETH',
|
|
@@ -47,9 +47,7 @@ class MoralisBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
|
|
|
47
47
|
const nativeToken = BSEthereumHelper_1.BSEthereumHelper.getNativeAsset(this._service.network);
|
|
48
48
|
const balances = [
|
|
49
49
|
{
|
|
50
|
-
amount: blockchain_service_1.
|
|
51
|
-
decimals: nativeToken.decimals,
|
|
52
|
-
}),
|
|
50
|
+
amount: new blockchain_service_1.BSBigUnitAmount(nativeBalance, nativeToken.decimals).toHuman().toFormatted(),
|
|
53
51
|
token: nativeToken,
|
|
54
52
|
},
|
|
55
53
|
];
|
|
@@ -58,9 +56,7 @@ class MoralisBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
|
|
|
58
56
|
if (balance.possible_spam || !balance.decimals || !balance.token_address || !balance.symbol)
|
|
59
57
|
return;
|
|
60
58
|
balances.push({
|
|
61
|
-
amount: blockchain_service_1.
|
|
62
|
-
decimals: balance.decimals,
|
|
63
|
-
}),
|
|
59
|
+
amount: new blockchain_service_1.BSBigUnitAmount(balance.balance, balance.decimals).toHuman().toFormatted(),
|
|
64
60
|
token: this._service.tokenService.normalizeToken({
|
|
65
61
|
decimals: balance.decimals,
|
|
66
62
|
hash: balance.token_address,
|
|
@@ -108,9 +104,7 @@ class MoralisBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
|
|
|
108
104
|
const toUrl = this._service.explorerService.buildAddressUrl(data.to_address);
|
|
109
105
|
events.push({
|
|
110
106
|
eventType: 'token',
|
|
111
|
-
amount: blockchain_service_1.
|
|
112
|
-
decimals: nativeToken.decimals,
|
|
113
|
-
}),
|
|
107
|
+
amount: new blockchain_service_1.BSBigUnitAmount(data.value, nativeToken.decimals).toHuman().toFormatted(),
|
|
114
108
|
methodName: 'transfer',
|
|
115
109
|
from: data.from_address,
|
|
116
110
|
fromUrl,
|
|
@@ -138,9 +132,7 @@ class MoralisBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
|
|
|
138
132
|
const token = await this.getTokenInfo(contractHash);
|
|
139
133
|
events.push({
|
|
140
134
|
eventType: 'token',
|
|
141
|
-
amount: blockchain_service_1.
|
|
142
|
-
decimals: token.decimals,
|
|
143
|
-
}),
|
|
135
|
+
amount: new blockchain_service_1.BSBigUnitAmount(amount, token.decimals).toHuman().toFormatted(),
|
|
144
136
|
methodName: 'transfer',
|
|
145
137
|
from,
|
|
146
138
|
fromUrl,
|
|
@@ -174,9 +166,7 @@ class MoralisBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
|
|
|
174
166
|
txIdUrl: this._service.explorerService.buildTransactionUrl(hash),
|
|
175
167
|
block: Number(data.block_number),
|
|
176
168
|
date: new Date(data.block_timestamp).toJSON(),
|
|
177
|
-
networkFeeAmount: blockchain_service_1.
|
|
178
|
-
decimals: this._service.feeToken.decimals,
|
|
179
|
-
}),
|
|
169
|
+
networkFeeAmount: new blockchain_service_1.BSBigHumanAmount(data.transaction_fee, this._service.feeToken.decimals).toFormatted(),
|
|
180
170
|
view: 'default',
|
|
181
171
|
events,
|
|
182
172
|
};
|
|
@@ -200,9 +190,7 @@ class MoralisBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
|
|
|
200
190
|
const toUrl = this._service.explorerService.buildAddressUrl(transfer.to_address);
|
|
201
191
|
events.push({
|
|
202
192
|
eventType: 'token',
|
|
203
|
-
amount: blockchain_service_1.
|
|
204
|
-
decimals: nativeAsset.decimals,
|
|
205
|
-
}),
|
|
193
|
+
amount: new blockchain_service_1.BSBigUnitAmount(transfer.value, nativeAsset.decimals).toHuman().toFormatted(),
|
|
206
194
|
methodName: 'transfer',
|
|
207
195
|
from: transfer.from_address,
|
|
208
196
|
fromUrl,
|
|
@@ -226,9 +214,7 @@ class MoralisBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
|
|
|
226
214
|
});
|
|
227
215
|
events.push({
|
|
228
216
|
eventType: 'token',
|
|
229
|
-
amount: blockchain_service_1.
|
|
230
|
-
decimals: tokenDecimals,
|
|
231
|
-
}),
|
|
217
|
+
amount: new blockchain_service_1.BSBigUnitAmount(transfer.value, tokenDecimals).toHuman().toFormatted(),
|
|
232
218
|
methodName: 'transfer',
|
|
233
219
|
from: transfer.from_address,
|
|
234
220
|
fromUrl,
|
|
@@ -263,9 +249,7 @@ class MoralisBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
|
|
|
263
249
|
txIdUrl: this._service.explorerService.buildTransactionUrl(item.hash),
|
|
264
250
|
block: Number(item.block_number),
|
|
265
251
|
date: new Date(item.block_timestamp).toJSON(),
|
|
266
|
-
networkFeeAmount: blockchain_service_1.
|
|
267
|
-
decimals: this._service.feeToken.decimals,
|
|
268
|
-
}),
|
|
252
|
+
networkFeeAmount: new blockchain_service_1.BSBigHumanAmount(item.transaction_fee, this._service.feeToken.decimals).toFormatted(),
|
|
269
253
|
view: 'default',
|
|
270
254
|
events,
|
|
271
255
|
});
|
|
@@ -45,16 +45,12 @@ class RpcBDSEthereum {
|
|
|
45
45
|
txIdUrl: this._service.explorerService.buildTransactionUrl(hash),
|
|
46
46
|
block: receipt.blockNumber,
|
|
47
47
|
date: new Date(timestamp).toJSON(),
|
|
48
|
-
networkFeeAmount: blockchain_service_1.
|
|
49
|
-
decimals: this._service.feeToken.decimals,
|
|
50
|
-
}),
|
|
48
|
+
networkFeeAmount: new blockchain_service_1.BSBigUnitAmount(fee.toString(), token.decimals).toHuman().toFormatted(),
|
|
51
49
|
view: 'default',
|
|
52
50
|
events: [
|
|
53
51
|
{
|
|
54
52
|
eventType: 'token',
|
|
55
|
-
amount: blockchain_service_1.
|
|
56
|
-
decimals: token.decimals,
|
|
57
|
-
}),
|
|
53
|
+
amount: new blockchain_service_1.BSBigUnitAmount(transaction.value.toString(), token.decimals).toHuman().toFormatted(),
|
|
58
54
|
methodName: 'transfer',
|
|
59
55
|
from: transaction.from,
|
|
60
56
|
fromUrl,
|
|
@@ -96,9 +92,7 @@ class RpcBDSEthereum {
|
|
|
96
92
|
const token = BSEthereumHelper_1.BSEthereumHelper.getNativeAsset(this._service.network);
|
|
97
93
|
return [
|
|
98
94
|
{
|
|
99
|
-
amount: blockchain_service_1.
|
|
100
|
-
decimals: token.decimals,
|
|
101
|
-
}),
|
|
95
|
+
amount: new blockchain_service_1.BSBigUnitAmount(balance.toString(), token.decimals).toHuman().toFormatted(),
|
|
102
96
|
token,
|
|
103
97
|
},
|
|
104
98
|
];
|
|
@@ -49,7 +49,7 @@ class MoralisFullTransactionsDataServiceEthereum {
|
|
|
49
49
|
block: item.block,
|
|
50
50
|
date: item.date,
|
|
51
51
|
networkFeeAmount: networkFeeAmount
|
|
52
|
-
? blockchain_service_1.
|
|
52
|
+
? new blockchain_service_1.BSBigHumanAmount(networkFeeAmount, nativeToken.decimals).toFormatted()
|
|
53
53
|
: undefined,
|
|
54
54
|
view: 'default',
|
|
55
55
|
events: [],
|
|
@@ -82,7 +82,7 @@ class MoralisFullTransactionsDataServiceEthereum {
|
|
|
82
82
|
newItem.events.splice(eventIndex, 0, {
|
|
83
83
|
eventType: 'token',
|
|
84
84
|
amount: event.amount
|
|
85
|
-
? blockchain_service_1.
|
|
85
|
+
? new blockchain_service_1.BSBigHumanAmount(event.amount, token?.decimals ?? event.tokenDecimals).toFormatted()
|
|
86
86
|
: undefined,
|
|
87
87
|
methodName,
|
|
88
88
|
from,
|
|
@@ -105,7 +105,7 @@ class EthersLedgerSigner extends ethers_1.Signer {
|
|
|
105
105
|
const signature = await __classPrivateFieldGet(this, _EthersLedgerSigner_ledgerApp, "f").signTransaction(__classPrivateFieldGet(this, _EthersLedgerSigner_bipPath, "f"), serializedUnsignedTransaction, resolution);
|
|
106
106
|
__classPrivateFieldGet(this, _EthersLedgerSigner_emitter, "f")?.emit('getSignatureEnd');
|
|
107
107
|
return ethers_1.ethers.utils.serializeTransaction(tx, {
|
|
108
|
-
v:
|
|
108
|
+
v: blockchain_service_1.BSBigNumber.ensureNumber('0x' + signature.v),
|
|
109
109
|
r: '0x' + signature.r,
|
|
110
110
|
s: '0x' + signature.s,
|
|
111
111
|
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { GhostMarketNDS, type TBSNetworkId, type THasTokenParams } from '@cityofzion/blockchain-service';
|
|
2
|
+
import type { IBSEthereum, TBSEthereumNetworkId } from '../../types';
|
|
3
|
+
export declare class GhostMarketNDSEthereum<N extends string, A extends TBSNetworkId> extends GhostMarketNDS<N, A, IBSEthereum<N, A>> {
|
|
4
|
+
static readonly CHAIN_BY_NETWORK_ID: Partial<Record<TBSEthereumNetworkId, string>>;
|
|
5
|
+
constructor(service: IBSEthereum<N, A>);
|
|
6
|
+
hasToken({ address, collectionHash }: THasTokenParams): Promise<boolean>;
|
|
7
|
+
getChain(): string;
|
|
8
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GhostMarketNDSEthereum = void 0;
|
|
4
|
+
const blockchain_service_1 = require("@cityofzion/blockchain-service");
|
|
5
|
+
const ethers_1 = require("ethers");
|
|
6
|
+
const ERC20_1 = require("../../assets/abis/ERC20");
|
|
7
|
+
class GhostMarketNDSEthereum extends blockchain_service_1.GhostMarketNDS {
|
|
8
|
+
constructor(service) {
|
|
9
|
+
super(service);
|
|
10
|
+
}
|
|
11
|
+
async hasToken({ address, collectionHash }) {
|
|
12
|
+
try {
|
|
13
|
+
if (!collectionHash)
|
|
14
|
+
return false;
|
|
15
|
+
const provider = new ethers_1.ethers.providers.JsonRpcProvider(this._service.network.url);
|
|
16
|
+
const contract = new ethers_1.ethers.Contract(collectionHash, ERC20_1.ERC20_ABI, provider);
|
|
17
|
+
const response = await contract.balanceOf(address);
|
|
18
|
+
if (!response)
|
|
19
|
+
return false;
|
|
20
|
+
const parsedResponse = new blockchain_service_1.BSBigUnitAmount(response.toString(), 0);
|
|
21
|
+
return parsedResponse.isGreaterThan(0);
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
getChain() {
|
|
28
|
+
const chain = GhostMarketNDSEthereum.CHAIN_BY_NETWORK_ID[this._service.network.id];
|
|
29
|
+
if (!chain)
|
|
30
|
+
throw new Error('Network not supported');
|
|
31
|
+
return chain;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.GhostMarketNDSEthereum = GhostMarketNDSEthereum;
|
|
35
|
+
GhostMarketNDSEthereum.CHAIN_BY_NETWORK_ID = {
|
|
36
|
+
'1': 'eth',
|
|
37
|
+
'56': 'bsc',
|
|
38
|
+
'137': 'polygon',
|
|
39
|
+
'43114': 'avalanche',
|
|
40
|
+
'8453': 'base',
|
|
41
|
+
};
|
|
@@ -1,36 +1,89 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type { IBSEthereum } from '../../types';
|
|
1
|
+
import { type IWalletConnectService, type TBSNetworkId, type TWalletConnectServiceHandlers, type TWalletConnectServiceMethodHandler, type TWalletConnectServiceRequestMethodParams } from '@cityofzion/blockchain-service';
|
|
2
|
+
import type { IBSEthereum, TWalletConnectServiceEthereumMethod } from '../../types';
|
|
3
|
+
import { z } from 'zod';
|
|
3
4
|
import { ethers } from 'ethers';
|
|
4
|
-
|
|
5
|
+
declare const personalSignParamsSchema: z.ZodTuple<[z.ZodString, z.ZodString], null>;
|
|
6
|
+
declare const signTypedDataParamsSchema: z.ZodTuple<[z.ZodString, z.ZodUnion<readonly [z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<any, string>>, z.ZodObject<{
|
|
7
|
+
primaryType: z.ZodString;
|
|
8
|
+
types: z.ZodRecord<z.ZodString, z.ZodAny>;
|
|
9
|
+
domain: z.ZodObject<{
|
|
10
|
+
chainId: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodBigInt, z.ZodString]>>;
|
|
11
|
+
name: z.ZodOptional<z.ZodString>;
|
|
12
|
+
salt: z.ZodOptional<z.ZodString>;
|
|
13
|
+
verifyingContract: z.ZodOptional<z.ZodString>;
|
|
14
|
+
version: z.ZodOptional<z.ZodString>;
|
|
15
|
+
}, z.core.$strip>;
|
|
16
|
+
message: z.ZodRecord<z.ZodString, z.ZodAny>;
|
|
17
|
+
account: z.ZodOptional<z.ZodString>;
|
|
18
|
+
}, z.core.$strip>>, z.ZodObject<{
|
|
19
|
+
primaryType: z.ZodString;
|
|
20
|
+
types: z.ZodRecord<z.ZodString, z.ZodAny>;
|
|
21
|
+
domain: z.ZodObject<{
|
|
22
|
+
chainId: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodBigInt, z.ZodString]>>;
|
|
23
|
+
name: z.ZodOptional<z.ZodString>;
|
|
24
|
+
salt: z.ZodOptional<z.ZodString>;
|
|
25
|
+
verifyingContract: z.ZodOptional<z.ZodString>;
|
|
26
|
+
version: z.ZodOptional<z.ZodString>;
|
|
27
|
+
}, z.core.$strip>;
|
|
28
|
+
message: z.ZodRecord<z.ZodString, z.ZodAny>;
|
|
29
|
+
account: z.ZodOptional<z.ZodString>;
|
|
30
|
+
}, z.core.$strip>]>], null>;
|
|
31
|
+
declare const signTransactionParamsSchema: z.ZodTuple<[z.ZodObject<{
|
|
32
|
+
to: z.ZodOptional<z.ZodString>;
|
|
33
|
+
value: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
34
|
+
data: z.ZodOptional<z.ZodString>;
|
|
35
|
+
gas: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
36
|
+
maxPriorityFeePerGas: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
37
|
+
maxFeePerGas: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
38
|
+
nonce: z.ZodOptional<z.ZodNumber>;
|
|
39
|
+
chainId: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>>;
|
|
40
|
+
gasLimit: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
41
|
+
type: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
42
|
+
gasPrice: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
43
|
+
}, z.core.$strip>], null>;
|
|
44
|
+
declare const sendRawTransactionParamsSchema: z.ZodTuple<[z.ZodString], null>;
|
|
45
|
+
export type TWalletConnectEthereumHandlers = {
|
|
46
|
+
personal_sign: z.infer<typeof personalSignParamsSchema>;
|
|
47
|
+
eth_sign: z.infer<typeof personalSignParamsSchema>;
|
|
48
|
+
eth_signTypedData: z.infer<typeof signTypedDataParamsSchema>;
|
|
49
|
+
eth_signTypedData_v3: z.infer<typeof signTypedDataParamsSchema>;
|
|
50
|
+
eth_signTypedData_v4: z.infer<typeof signTypedDataParamsSchema>;
|
|
51
|
+
eth_signTransaction: z.infer<typeof signTransactionParamsSchema>;
|
|
52
|
+
eth_sendTransaction: z.infer<typeof signTransactionParamsSchema>;
|
|
53
|
+
eth_sendRawTransaction: z.infer<typeof sendRawTransactionParamsSchema>;
|
|
54
|
+
eth_call: z.infer<typeof signTransactionParamsSchema>;
|
|
55
|
+
eth_requestAccounts: unknown;
|
|
56
|
+
eth_switchEthereumChain: unknown;
|
|
57
|
+
eth_addEthereumChain: unknown;
|
|
58
|
+
wallet_switchEthereumChain: unknown;
|
|
59
|
+
wallet_addEthereumChain: unknown;
|
|
60
|
+
wallet_getPermissions: unknown;
|
|
61
|
+
wallet_requestPermissions: unknown;
|
|
62
|
+
};
|
|
63
|
+
export declare class WalletConnectServiceEthereum<N extends string, A extends TBSNetworkId, M extends string = TWalletConnectServiceEthereumMethod, H extends Record<string, any> = TWalletConnectEthereumHandlers> implements IWalletConnectService<N, M> {
|
|
5
64
|
#private;
|
|
6
65
|
readonly namespace: string;
|
|
7
66
|
readonly chain: string;
|
|
8
|
-
|
|
67
|
+
supportedMethods: M[];
|
|
9
68
|
readonly supportedEvents: string[];
|
|
10
|
-
|
|
11
|
-
|
|
69
|
+
calculableMethods: M[];
|
|
70
|
+
autoApproveMethods: M[];
|
|
12
71
|
protected readonly _service: IBSEthereum<N, A>;
|
|
72
|
+
handlers: TWalletConnectServiceHandlers<N, H>;
|
|
13
73
|
constructor(service: IBSEthereum<N, A>);
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
74
|
+
_personalSignHandler: TWalletConnectServiceMethodHandler<N, z.infer<typeof personalSignParamsSchema>>;
|
|
75
|
+
_signTypedDataHandlers: TWalletConnectServiceMethodHandler<N, z.infer<typeof signTypedDataParamsSchema>>;
|
|
76
|
+
_signTransactionHandler: TWalletConnectServiceMethodHandler<N, z.infer<typeof signTransactionParamsSchema>>;
|
|
77
|
+
_sendTransactionHandler: TWalletConnectServiceMethodHandler<N, z.infer<typeof signTransactionParamsSchema>>;
|
|
78
|
+
_sendRawTransactionHandler: TWalletConnectServiceMethodHandler<N, z.infer<typeof sendRawTransactionParamsSchema>>;
|
|
79
|
+
_callHandler: TWalletConnectServiceMethodHandler<N, z.infer<typeof signTransactionParamsSchema>>;
|
|
80
|
+
_requestAccount: TWalletConnectServiceMethodHandler<N>;
|
|
81
|
+
_nullHandlers: TWalletConnectServiceMethodHandler<N>;
|
|
82
|
+
_emptyHandlers: TWalletConnectServiceMethodHandler<N>;
|
|
83
|
+
_resolveTransactionParams(args: TWalletConnectServiceRequestMethodParams<N, z.infer<typeof signTransactionParamsSchema>>): Promise<{
|
|
84
|
+
connectedWallet: ethers.Signer;
|
|
85
|
+
transaction: ethers.providers.TransactionRequest;
|
|
18
86
|
}>;
|
|
19
|
-
personal_sign(args: TWalletConnectServiceRequestMethodParams<N>): Promise<string>;
|
|
20
|
-
eth_sign(args: TWalletConnectServiceRequestMethodParams<N>): Promise<string>;
|
|
21
|
-
eth_signTransaction(args: TWalletConnectServiceRequestMethodParams<N>): Promise<string>;
|
|
22
|
-
eth_signTypedData(args: TWalletConnectServiceRequestMethodParams<N>): Promise<string>;
|
|
23
|
-
eth_signTypedData_v3(args: TWalletConnectServiceRequestMethodParams<N>): Promise<string>;
|
|
24
|
-
eth_signTypedData_v4(args: TWalletConnectServiceRequestMethodParams<N>): Promise<string>;
|
|
25
|
-
eth_sendTransaction(args: TWalletConnectServiceRequestMethodParams<N>): Promise<string>;
|
|
26
|
-
eth_call(args: TWalletConnectServiceRequestMethodParams<N>): Promise<string>;
|
|
27
|
-
eth_requestAccounts(args: TWalletConnectServiceRequestMethodParams<N>): Promise<string[]>;
|
|
28
|
-
eth_sendRawTransaction(args: TWalletConnectServiceRequestMethodParams<N>): Promise<string>;
|
|
29
|
-
wallet_switchEthereumChain(): Promise<string>;
|
|
30
|
-
eth_addEthereumChain(): Promise<string>;
|
|
31
|
-
eth_switchEthereumChain(): Promise<string>;
|
|
32
|
-
wallet_getPermissions(): Promise<any[]>;
|
|
33
|
-
wallet_requestPermissions(): Promise<any[]>;
|
|
34
|
-
wallet_addEthereumChain(): Promise<string>;
|
|
35
87
|
calculateRequestFee(args: TWalletConnectServiceRequestMethodParams<N>): Promise<string>;
|
|
36
88
|
}
|
|
89
|
+
export {};
|
|
@@ -7,168 +7,244 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
7
7
|
var _WalletConnectServiceEthereum_instances, _WalletConnectServiceEthereum_convertHexToUtf8;
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.WalletConnectServiceEthereum = void 0;
|
|
10
|
+
const blockchain_service_1 = require("@cityofzion/blockchain-service");
|
|
11
|
+
const zod_1 = require("zod");
|
|
10
12
|
const ethers_1 = require("ethers");
|
|
11
13
|
const BSEthereumConstants_1 = require("../../constants/BSEthereumConstants");
|
|
14
|
+
const utils_1 = require("ethers/lib/utils");
|
|
15
|
+
const personalSignParamsSchema = zod_1.z.tuple([zod_1.z.string(), zod_1.z.string()]);
|
|
16
|
+
const typedDataParamSchema = zod_1.z.object({
|
|
17
|
+
primaryType: zod_1.z.string(),
|
|
18
|
+
types: zod_1.z.record(zod_1.z.string(), zod_1.z.any()),
|
|
19
|
+
domain: zod_1.z.object({
|
|
20
|
+
chainId: zod_1.z.union([zod_1.z.number(), zod_1.z.bigint(), zod_1.z.string()]).optional(),
|
|
21
|
+
name: zod_1.z.string().optional(),
|
|
22
|
+
salt: zod_1.z.string().optional(),
|
|
23
|
+
verifyingContract: zod_1.z.string().optional(),
|
|
24
|
+
version: zod_1.z.string().optional(),
|
|
25
|
+
}),
|
|
26
|
+
message: zod_1.z.record(zod_1.z.string(), zod_1.z.any()),
|
|
27
|
+
account: zod_1.z.string().optional(),
|
|
28
|
+
});
|
|
29
|
+
const jsonStringifiedTypedDataParamSchema = zod_1.z
|
|
30
|
+
.string()
|
|
31
|
+
.transform((val, ctx) => {
|
|
32
|
+
try {
|
|
33
|
+
return JSON.parse(val);
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
ctx.addIssue({ code: zod_1.z.ZodIssueCode.custom, message: 'Invalid JSON string' });
|
|
37
|
+
return zod_1.z.NEVER;
|
|
38
|
+
}
|
|
39
|
+
})
|
|
40
|
+
.pipe(typedDataParamSchema);
|
|
41
|
+
const signTypedDataParamsSchema = zod_1.z.tuple([
|
|
42
|
+
zod_1.z.string(),
|
|
43
|
+
zod_1.z.union([jsonStringifiedTypedDataParamSchema, typedDataParamSchema]),
|
|
44
|
+
]);
|
|
45
|
+
const signTransactionParamsSchema = zod_1.z.tuple([
|
|
46
|
+
zod_1.z.object({
|
|
47
|
+
to: zod_1.z.string().optional(),
|
|
48
|
+
value: zod_1.z.union([zod_1.z.string(), zod_1.z.number()]).optional(),
|
|
49
|
+
data: zod_1.z.string().optional(),
|
|
50
|
+
gas: zod_1.z.union([zod_1.z.string(), zod_1.z.number()]).optional(),
|
|
51
|
+
maxPriorityFeePerGas: zod_1.z.union([zod_1.z.string(), zod_1.z.number()]).optional(),
|
|
52
|
+
maxFeePerGas: zod_1.z.union([zod_1.z.string(), zod_1.z.number()]).optional(),
|
|
53
|
+
nonce: zod_1.z.number().optional(),
|
|
54
|
+
chainId: zod_1.z.union([zod_1.z.number(), zod_1.z.string()]).optional(),
|
|
55
|
+
gasLimit: zod_1.z.union([zod_1.z.string(), zod_1.z.number()]).optional(),
|
|
56
|
+
type: zod_1.z.union([zod_1.z.string(), zod_1.z.number()]).optional(),
|
|
57
|
+
gasPrice: zod_1.z.union([zod_1.z.string(), zod_1.z.number()]).optional(),
|
|
58
|
+
}),
|
|
59
|
+
]);
|
|
60
|
+
const sendRawTransactionParamsSchema = zod_1.z.tuple([zod_1.z.string()]);
|
|
12
61
|
class WalletConnectServiceEthereum {
|
|
13
62
|
constructor(service) {
|
|
14
63
|
_WalletConnectServiceEthereum_instances.add(this);
|
|
15
64
|
this.namespace = 'eip155';
|
|
65
|
+
// prettier-ignore
|
|
16
66
|
this.supportedMethods = [
|
|
17
|
-
'personal_sign',
|
|
18
|
-
'
|
|
19
|
-
'
|
|
20
|
-
'
|
|
21
|
-
'eth_signTypedData_v3',
|
|
22
|
-
'eth_signTypedData_v4',
|
|
23
|
-
'eth_sendTransaction',
|
|
24
|
-
'eth_call',
|
|
25
|
-
'eth_requestAccounts',
|
|
26
|
-
'eth_sendRawTransaction',
|
|
27
|
-
'eth_addEthereumChain',
|
|
28
|
-
'eth_switchEthereumChain',
|
|
29
|
-
'wallet_switchEthereumChain',
|
|
30
|
-
'wallet_getPermissions',
|
|
31
|
-
'wallet_requestPermissions',
|
|
32
|
-
'wallet_addEthereumChain',
|
|
67
|
+
'personal_sign', 'eth_sign', 'eth_signTransaction', 'eth_signTypedData',
|
|
68
|
+
'eth_signTypedData_v3', 'eth_signTypedData_v4', 'eth_sendTransaction', 'eth_call',
|
|
69
|
+
'eth_requestAccounts', 'eth_sendRawTransaction', 'eth_addEthereumChain', 'eth_switchEthereumChain',
|
|
70
|
+
'wallet_switchEthereumChain', 'wallet_getPermissions', 'wallet_requestPermissions', 'wallet_addEthereumChain',
|
|
33
71
|
];
|
|
34
72
|
this.supportedEvents = ['chainChanged', 'accountsChanged', 'disconnect', 'connect'];
|
|
35
|
-
this.calculableMethods = ['eth_sendTransaction', '
|
|
73
|
+
this.calculableMethods = ['eth_sendTransaction', 'eth_sendRawTransaction'];
|
|
74
|
+
// prettier-ignore
|
|
36
75
|
this.autoApproveMethods = [
|
|
37
|
-
'eth_requestAccounts',
|
|
38
|
-
'
|
|
39
|
-
'eth_switchEthereumChain',
|
|
40
|
-
'wallet_switchEthereumChain',
|
|
41
|
-
'wallet_getPermissions',
|
|
42
|
-
'wallet_requestPermissions',
|
|
43
|
-
'wallet_addEthereumChain',
|
|
76
|
+
'eth_requestAccounts', 'eth_addEthereumChain', 'eth_switchEthereumChain', 'wallet_switchEthereumChain',
|
|
77
|
+
'wallet_getPermissions', 'wallet_requestPermissions', 'wallet_addEthereumChain', 'eth_call',
|
|
44
78
|
];
|
|
79
|
+
this._personalSignHandler = {
|
|
80
|
+
validate: async (params) => await personalSignParamsSchema.parseAsync(params),
|
|
81
|
+
process: async (args) => {
|
|
82
|
+
const wallet = await this._service._generateSigner(args.account);
|
|
83
|
+
const convertedMessage = __classPrivateFieldGet(this, _WalletConnectServiceEthereum_instances, "m", _WalletConnectServiceEthereum_convertHexToUtf8).call(this, args.params[0]);
|
|
84
|
+
return await wallet.signMessage(convertedMessage);
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
this._signTypedDataHandlers = {
|
|
88
|
+
validate: async (params) => await signTypedDataParamsSchema.parseAsync(params),
|
|
89
|
+
process: async (args) => {
|
|
90
|
+
const wallet = await this._service._generateSigner(args.account);
|
|
91
|
+
const { domain, types, message } = args.params[1];
|
|
92
|
+
// https://github.com/ethers-io/ethers.js/issues/687#issuecomment-714069471
|
|
93
|
+
delete types?.EIP712Domain;
|
|
94
|
+
return await wallet._signTypedData(domain, types, message);
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
this._signTransactionHandler = {
|
|
98
|
+
validate: async (params) => await signTransactionParamsSchema.parseAsync(params),
|
|
99
|
+
process: async (args) => {
|
|
100
|
+
const { connectedWallet, transaction } = await this._resolveTransactionParams(args);
|
|
101
|
+
return await connectedWallet.signTransaction(transaction);
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
this._sendTransactionHandler = {
|
|
105
|
+
validate: async (params) => await signTransactionParamsSchema.parseAsync(params),
|
|
106
|
+
process: async (args) => {
|
|
107
|
+
const { transaction, connectedWallet } = await this._resolveTransactionParams(args);
|
|
108
|
+
const { hash } = await connectedWallet.sendTransaction(transaction);
|
|
109
|
+
return hash;
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
this._sendRawTransactionHandler = {
|
|
113
|
+
validate: async (params) => await sendRawTransactionParamsSchema.parseAsync(params),
|
|
114
|
+
process: async (args) => {
|
|
115
|
+
const provider = new ethers_1.ethers.providers.JsonRpcProvider(this._service.network.url);
|
|
116
|
+
const { hash } = await provider.sendTransaction(args.params[0]);
|
|
117
|
+
return hash;
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
this._callHandler = {
|
|
121
|
+
validate: async (params) => await signTransactionParamsSchema.parseAsync(params),
|
|
122
|
+
process: async (args) => {
|
|
123
|
+
const { transaction, connectedWallet } = await this._resolveTransactionParams(args);
|
|
124
|
+
return await connectedWallet.call(transaction);
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
this._requestAccount = {
|
|
128
|
+
validate: async () => { },
|
|
129
|
+
process: async (args) => {
|
|
130
|
+
const wallet = await this._service._generateSigner(args.account);
|
|
131
|
+
return [await wallet.getAddress()];
|
|
132
|
+
},
|
|
133
|
+
};
|
|
134
|
+
this._nullHandlers = {
|
|
135
|
+
validate: async () => { },
|
|
136
|
+
process: async () => {
|
|
137
|
+
return 'null';
|
|
138
|
+
},
|
|
139
|
+
};
|
|
140
|
+
this._emptyHandlers = {
|
|
141
|
+
validate: async () => { },
|
|
142
|
+
process: async () => {
|
|
143
|
+
return [];
|
|
144
|
+
},
|
|
145
|
+
};
|
|
45
146
|
this._service = service;
|
|
46
147
|
this.chain = `${this.namespace}:${this._service.network.id.toString()}`;
|
|
148
|
+
this.handlers = {
|
|
149
|
+
personal_sign: this._personalSignHandler,
|
|
150
|
+
eth_sign: this._personalSignHandler,
|
|
151
|
+
eth_signTypedData: this._signTypedDataHandlers,
|
|
152
|
+
eth_signTypedData_v3: this._signTypedDataHandlers,
|
|
153
|
+
eth_signTypedData_v4: this._signTypedDataHandlers,
|
|
154
|
+
eth_signTransaction: this._signTransactionHandler,
|
|
155
|
+
eth_sendTransaction: this._sendTransactionHandler,
|
|
156
|
+
eth_sendRawTransaction: this._sendRawTransactionHandler,
|
|
157
|
+
eth_call: this._callHandler,
|
|
158
|
+
eth_requestAccounts: this._requestAccount,
|
|
159
|
+
eth_switchEthereumChain: this._nullHandlers,
|
|
160
|
+
eth_addEthereumChain: this._nullHandlers,
|
|
161
|
+
wallet_switchEthereumChain: this._nullHandlers,
|
|
162
|
+
wallet_addEthereumChain: this._nullHandlers,
|
|
163
|
+
wallet_getPermissions: this._emptyHandlers,
|
|
164
|
+
wallet_requestPermissions: this._emptyHandlers,
|
|
165
|
+
};
|
|
47
166
|
}
|
|
48
|
-
async
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
167
|
+
async _resolveTransactionParams(args) {
|
|
168
|
+
const params = args.params[0];
|
|
169
|
+
const provider = new ethers_1.ethers.providers.JsonRpcProvider(this._service.network.url);
|
|
170
|
+
const wallet = await this._service._generateSigner(args.account);
|
|
171
|
+
const connectedWallet = wallet.connect(provider);
|
|
172
|
+
const transaction = {
|
|
173
|
+
to: params.to,
|
|
174
|
+
value: params.value,
|
|
175
|
+
data: params.data,
|
|
176
|
+
};
|
|
177
|
+
transaction.chainId = parseInt(params.chainId?.toString() ?? this._service.network.id);
|
|
178
|
+
transaction.nonce = params.nonce;
|
|
179
|
+
if (!transaction.nonce) {
|
|
180
|
+
transaction.nonce = await connectedWallet.getTransactionCount('pending');
|
|
59
181
|
}
|
|
60
|
-
if (
|
|
61
|
-
const typeAsNumber = parseInt(
|
|
62
|
-
if (!isNaN(typeAsNumber))
|
|
63
|
-
|
|
182
|
+
if (params.type) {
|
|
183
|
+
const typeAsNumber = parseInt(params.type.toString());
|
|
184
|
+
if (!isNaN(typeAsNumber)) {
|
|
185
|
+
transaction.type = typeAsNumber;
|
|
186
|
+
}
|
|
64
187
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
188
|
+
if (transaction.type === 2) {
|
|
189
|
+
transaction.maxFeePerGas = params.maxFeePerGas;
|
|
190
|
+
transaction.maxPriorityFeePerGas = params.maxPriorityFeePerGas;
|
|
191
|
+
if (!transaction.maxFeePerGas || !transaction.maxPriorityFeePerGas) {
|
|
192
|
+
const feeData = await connectedWallet.getFeeData();
|
|
193
|
+
transaction.maxFeePerGas = transaction.maxFeePerGas ?? feeData.maxFeePerGas ?? undefined;
|
|
194
|
+
transaction.maxPriorityFeePerGas = transaction.maxPriorityFeePerGas ?? feeData.maxPriorityFeePerGas ?? undefined;
|
|
195
|
+
}
|
|
70
196
|
}
|
|
71
197
|
else {
|
|
72
|
-
|
|
198
|
+
transaction.gasPrice = params.gasPrice?.toString();
|
|
199
|
+
if (!transaction.gasPrice) {
|
|
200
|
+
const gasPrice = await provider.getGasPrice();
|
|
201
|
+
transaction.gasPrice = gasPrice;
|
|
202
|
+
}
|
|
73
203
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
if (!param.gasLimit) {
|
|
204
|
+
transaction.gasLimit = params.gasLimit ?? params.gas;
|
|
205
|
+
if (!transaction.gasLimit) {
|
|
77
206
|
try {
|
|
78
|
-
|
|
79
|
-
...
|
|
207
|
+
const estimatedGas = await connectedWallet.estimateGas({
|
|
208
|
+
...transaction,
|
|
80
209
|
gasPrice: undefined,
|
|
81
210
|
maxFeePerGas: undefined,
|
|
82
211
|
maxPriorityFeePerGas: undefined,
|
|
83
212
|
});
|
|
213
|
+
transaction.gasLimit = estimatedGas;
|
|
84
214
|
}
|
|
85
215
|
catch {
|
|
86
|
-
|
|
216
|
+
transaction.gasLimit = BSEthereumConstants_1.BSEthereumConstants.DEFAULT_GAS_LIMIT_BN.toString();
|
|
87
217
|
}
|
|
88
218
|
}
|
|
89
|
-
|
|
90
|
-
param.nonce = await connectedWallet.getTransactionCount('pending');
|
|
91
|
-
}
|
|
92
|
-
return { wallet, provider, param };
|
|
93
|
-
}
|
|
94
|
-
async personal_sign(args) {
|
|
95
|
-
const wallet = await this._service._generateSigner(args.account);
|
|
96
|
-
const message = args.params.filter((param) => !ethers_1.ethers.utils.isAddress(param))[0];
|
|
97
|
-
const convertedMessage = __classPrivateFieldGet(this, _WalletConnectServiceEthereum_instances, "m", _WalletConnectServiceEthereum_convertHexToUtf8).call(this, message);
|
|
98
|
-
return await wallet.signMessage(convertedMessage);
|
|
99
|
-
}
|
|
100
|
-
async eth_sign(args) {
|
|
101
|
-
return await this.personal_sign(args);
|
|
102
|
-
}
|
|
103
|
-
async eth_signTransaction(args) {
|
|
104
|
-
const { param, wallet } = await this._resolveParams(args);
|
|
105
|
-
return await wallet.signTransaction(param);
|
|
106
|
-
}
|
|
107
|
-
async eth_signTypedData(args) {
|
|
108
|
-
const wallet = await this._service._generateSigner(args.account);
|
|
109
|
-
const data = args.params.filter((param) => !ethers_1.ethers.utils.isAddress(param))[0];
|
|
110
|
-
const parsedData = typeof data === 'string' ? JSON.parse(data) : data;
|
|
111
|
-
const { domain, types, message } = parsedData;
|
|
112
|
-
// https://github.com/ethers-io/ethers.js/issues/687#issuecomment-714069471
|
|
113
|
-
delete types.EIP712Domain;
|
|
114
|
-
return await wallet._signTypedData(domain, types, message);
|
|
115
|
-
}
|
|
116
|
-
async eth_signTypedData_v3(args) {
|
|
117
|
-
return await this.eth_signTypedData(args);
|
|
118
|
-
}
|
|
119
|
-
async eth_signTypedData_v4(args) {
|
|
120
|
-
return await this.eth_signTypedData(args);
|
|
121
|
-
}
|
|
122
|
-
async eth_sendTransaction(args) {
|
|
123
|
-
const { param, provider, wallet } = await this._resolveParams(args);
|
|
124
|
-
const connectedWallet = wallet.connect(provider);
|
|
125
|
-
const { hash } = await connectedWallet.sendTransaction(param);
|
|
126
|
-
return hash;
|
|
127
|
-
}
|
|
128
|
-
async eth_call(args) {
|
|
129
|
-
const { param, provider, wallet } = await this._resolveParams(args);
|
|
130
|
-
const connectedWallet = wallet.connect(provider);
|
|
131
|
-
return await connectedWallet.call(param);
|
|
132
|
-
}
|
|
133
|
-
async eth_requestAccounts(args) {
|
|
134
|
-
const wallet = await this._service._generateSigner(args.account);
|
|
135
|
-
return [await wallet.getAddress()];
|
|
136
|
-
}
|
|
137
|
-
async eth_sendRawTransaction(args) {
|
|
138
|
-
const provider = new ethers_1.ethers.providers.JsonRpcProvider(this._service.network.url);
|
|
139
|
-
const { hash } = await provider.sendTransaction(args.params[0]);
|
|
140
|
-
return hash;
|
|
141
|
-
}
|
|
142
|
-
async wallet_switchEthereumChain() {
|
|
143
|
-
return 'null';
|
|
144
|
-
}
|
|
145
|
-
async eth_addEthereumChain() {
|
|
146
|
-
return 'null';
|
|
147
|
-
}
|
|
148
|
-
async eth_switchEthereumChain() {
|
|
149
|
-
return 'null';
|
|
150
|
-
}
|
|
151
|
-
async wallet_getPermissions() {
|
|
152
|
-
return [];
|
|
153
|
-
}
|
|
154
|
-
async wallet_requestPermissions() {
|
|
155
|
-
return [];
|
|
156
|
-
}
|
|
157
|
-
async wallet_addEthereumChain() {
|
|
158
|
-
return 'null';
|
|
219
|
+
return { connectedWallet, transaction };
|
|
159
220
|
}
|
|
160
221
|
async calculateRequestFee(args) {
|
|
161
|
-
|
|
222
|
+
let transactionToEstimate;
|
|
223
|
+
if (args.method === 'eth_sendTransaction') {
|
|
224
|
+
const params = await this._sendTransactionHandler.validate(args.params).catch(error => {
|
|
225
|
+
throw new blockchain_service_1.BSError('Params validation failed: ' + error.message, 'INVALID_PARAMS');
|
|
226
|
+
});
|
|
227
|
+
const { transaction } = await this._resolveTransactionParams({ ...args, params });
|
|
228
|
+
transactionToEstimate = transaction;
|
|
229
|
+
}
|
|
230
|
+
else if (args.method === 'eth_sendRawTransaction') {
|
|
231
|
+
const params = await this._sendRawTransactionHandler.validate(args.params).catch(error => {
|
|
232
|
+
throw new blockchain_service_1.BSError('Params validation failed: ' + error.message, 'INVALID_PARAMS');
|
|
233
|
+
});
|
|
234
|
+
transactionToEstimate = (0, utils_1.parseTransaction)(params[0]);
|
|
235
|
+
}
|
|
236
|
+
else {
|
|
237
|
+
throw new blockchain_service_1.BSError(`Method ${args.method} is not supported for fee calculation`, 'UNSUPPORTED_METHOD');
|
|
238
|
+
}
|
|
239
|
+
const provider = new ethers_1.ethers.providers.JsonRpcProvider(this._service.network.url);
|
|
240
|
+
const wallet = await this._service._generateSigner(args.account);
|
|
162
241
|
const connectedWallet = wallet.connect(provider);
|
|
163
242
|
const gasPrice = await connectedWallet.getGasPrice();
|
|
164
|
-
const
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
maxPriorityFeePerGas: undefined,
|
|
170
|
-
});
|
|
171
|
-
return ethers_1.ethers.utils.formatEther(gasPrice.mul(estimated));
|
|
243
|
+
const gasPriceBn = new blockchain_service_1.BSBigUnitAmount(gasPrice.toString(), this._service.feeToken.decimals);
|
|
244
|
+
const estimatedGas = await connectedWallet.estimateGas(transactionToEstimate);
|
|
245
|
+
const estimatedGasBn = new blockchain_service_1.BSBigUnitAmount(estimatedGas.toString(), this._service.feeToken.decimals);
|
|
246
|
+
const feeFormatted = gasPriceBn.multipliedBy(estimatedGasBn).toHuman().toFormatted();
|
|
247
|
+
return feeFormatted;
|
|
172
248
|
}
|
|
173
249
|
}
|
|
174
250
|
exports.WalletConnectServiceEthereum = WalletConnectServiceEthereum;
|
package/dist/types.d.ts
CHANGED
|
@@ -174,4 +174,5 @@ export type TMoralisNDSEthereumNftsByAddressApiResponse = {
|
|
|
174
174
|
page?: number;
|
|
175
175
|
page_size?: number;
|
|
176
176
|
};
|
|
177
|
+
export type TWalletConnectServiceEthereumMethod = 'personal_sign' | 'eth_sign' | 'eth_signTransaction' | 'eth_signTypedData' | 'eth_signTypedData_v3' | 'eth_signTypedData_v4' | 'eth_sendTransaction' | 'eth_call' | 'eth_requestAccounts' | 'eth_sendRawTransaction' | 'eth_addEthereumChain' | 'eth_switchEthereumChain' | 'wallet_switchEthereumChain' | 'wallet_getPermissions' | 'wallet_requestPermissions' | 'wallet_addEthereumChain' | (string & {});
|
|
177
178
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cityofzion/bs-ethereum",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.12",
|
|
4
4
|
"repository": "https://github.com/CityOfZion/blockchain-services",
|
|
5
5
|
"license": "GPL-3.0-only",
|
|
6
6
|
"author": "Coz",
|
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
"@ledgerhq/hw-app-eth": "~7.3.0",
|
|
20
20
|
"axios": "~1.15.0",
|
|
21
21
|
"ethers": "5.8.0",
|
|
22
|
-
"
|
|
22
|
+
"zod": "~4.3.6",
|
|
23
|
+
"@cityofzion/blockchain-service": "3.1.12"
|
|
23
24
|
},
|
|
24
25
|
"devDependencies": {
|
|
25
26
|
"@ledgerhq/hw-transport": "~6.32.0",
|