@cityofzion/bs-neox 3.1.16 → 3.1.18
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/BSNeoX.js +8 -6
- package/dist/constants/BSNeoXConstants.d.ts +1 -0
- package/dist/constants/BSNeoXConstants.js +6 -0
- package/dist/helpers/BSNeoXHelper.d.ts +1 -0
- package/dist/helpers/BSNeoXHelper.js +7 -0
- package/dist/services/blockchain-data/BlockscoutBDSNeoX.js +1 -5
- package/dist/services/full-transactions-data/BlockscoutFullTransactionsDataService.js +13 -9
- package/dist/services/neo3-neox-bridge/Neo3NeoXBridgeService.d.ts +3 -2
- package/dist/services/neo3-neox-bridge/Neo3NeoXBridgeService.js +40 -57
- package/dist/services/nft-data/GhostMarketNDSNeoX.js +1 -1
- package/dist/services/wallet-connect/WalletConnectServiceNeoX.d.ts +2 -0
- package/dist/services/wallet-connect/WalletConnectServiceNeoX.js +23 -12
- package/dist/types.d.ts +3 -3
- package/package.json +15 -14
package/dist/BSNeoX.js
CHANGED
|
@@ -36,7 +36,7 @@ class BSNeoX extends bs_ethereum_1.BSEthereum {
|
|
|
36
36
|
throw new Error('Invalid chainId');
|
|
37
37
|
}
|
|
38
38
|
transactionParams.chainId = chainId;
|
|
39
|
-
const nonce = await signer.
|
|
39
|
+
const nonce = await signer.getNonce('pending');
|
|
40
40
|
if (isNaN(nonce)) {
|
|
41
41
|
throw new Error('Invalid nonce');
|
|
42
42
|
}
|
|
@@ -104,10 +104,12 @@ class BSNeoX extends bs_ethereum_1.BSEthereum {
|
|
|
104
104
|
}
|
|
105
105
|
newParams.maxPriorityFeePerGas = gasPriceBn.toString();
|
|
106
106
|
newParams.maxFeePerGas = gasPriceBn.toString();
|
|
107
|
-
const
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
|
|
107
|
+
const provider = new ethers_1.JsonRpcProvider(this.network.url);
|
|
108
|
+
const signedTransaction = await signer.signTransaction(newParams);
|
|
109
|
+
const transactionHash = await provider.send('eth_sendRawTransaction', [signedTransaction]);
|
|
110
|
+
if (!transactionHash) {
|
|
111
|
+
throw new blockchain_service_1.BSError('Transaction error', 'TRANSACTION_ERROR');
|
|
112
|
+
}
|
|
111
113
|
const fee = gasPriceBn.multipliedBy(newParams.gasLimit).toHuman().toFormatted();
|
|
112
114
|
return { transactionHash, fee };
|
|
113
115
|
}
|
|
@@ -130,7 +132,7 @@ class BSNeoX extends bs_ethereum_1.BSEthereum {
|
|
|
130
132
|
this.fullTransactionsDataService = new BlockscoutFullTransactionsDataService_1.BlockscoutFullTransactionsDataService(this);
|
|
131
133
|
}
|
|
132
134
|
async transfer({ senderAccount, intents, }) {
|
|
133
|
-
const signer = await this.
|
|
135
|
+
const signer = await this._getSigner(senderAccount);
|
|
134
136
|
const { address } = senderAccount;
|
|
135
137
|
const addressUrl = this.explorerService.buildAddressUrl(address);
|
|
136
138
|
const transactions = [];
|
|
@@ -2,6 +2,7 @@ import type { TBSNetwork, TBSToken } from '@cityofzion/blockchain-service';
|
|
|
2
2
|
import type { TBSNeoXNetworkId } from '../types';
|
|
3
3
|
export declare class BSNeoXConstants {
|
|
4
4
|
static readonly NATIVE_ASSET: TBSToken;
|
|
5
|
+
static readonly NDMEME_TOKEN: TBSToken;
|
|
5
6
|
static readonly ANTI_MEV_RPC_LIST_BY_NETWORK_ID: Record<TBSNeoXNetworkId, string[]>;
|
|
6
7
|
static readonly RPC_LIST_BY_NETWORK_ID: Record<TBSNeoXNetworkId, string[]>;
|
|
7
8
|
static readonly MAINNET_NETWORK: TBSNetwork<TBSNeoXNetworkId>;
|
|
@@ -12,6 +12,12 @@ BSNeoXConstants.NATIVE_ASSET = {
|
|
|
12
12
|
decimals: 18,
|
|
13
13
|
hash: '-',
|
|
14
14
|
};
|
|
15
|
+
BSNeoXConstants.NDMEME_TOKEN = {
|
|
16
|
+
symbol: 'NDMEME',
|
|
17
|
+
name: 'NDMEME',
|
|
18
|
+
hash: '0xe816dee05cf6d0f2a57eb4c489241d8326b5d106',
|
|
19
|
+
decimals: 18,
|
|
20
|
+
};
|
|
15
21
|
BSNeoXConstants.ANTI_MEV_RPC_LIST_BY_NETWORK_ID = {
|
|
16
22
|
'47763': ['https://mainnet-5.rpc.banelabs.org'],
|
|
17
23
|
'12227332': ['https://neoxt4seed5.ngd.network'],
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BSNeoXHelper = void 0;
|
|
4
4
|
const blockchain_service_1 = require("@cityofzion/blockchain-service");
|
|
5
|
+
const BSNeoXConstants_1 = require("../constants/BSNeoXConstants");
|
|
5
6
|
class BSNeoXHelper {
|
|
6
7
|
static getNeoToken(network) {
|
|
7
8
|
if (network.type === 'custom') {
|
|
@@ -13,5 +14,11 @@ class BSNeoXHelper {
|
|
|
13
14
|
}
|
|
14
15
|
return { name: 'NEO', symbol: 'NEO', decimals: 18, hash };
|
|
15
16
|
}
|
|
17
|
+
static getNdmemeToken(network) {
|
|
18
|
+
if (network.type !== 'mainnet') {
|
|
19
|
+
return { ...BSNeoXConstants_1.BSNeoXConstants.NDMEME_TOKEN, hash: '-' };
|
|
20
|
+
}
|
|
21
|
+
return BSNeoXConstants_1.BSNeoXConstants.NDMEME_TOKEN;
|
|
22
|
+
}
|
|
16
23
|
}
|
|
17
24
|
exports.BSNeoXHelper = BSNeoXHelper;
|
|
@@ -101,7 +101,6 @@ class BlockscoutBDSNeoX extends bs_ethereum_1.RpcBDSEthereum {
|
|
|
101
101
|
});
|
|
102
102
|
await Promise.allSettled(promises);
|
|
103
103
|
}
|
|
104
|
-
const data = this._service.neo3NeoXBridgeService._getDataFromBlockscoutTransaction(response);
|
|
105
104
|
const txId = response.hash;
|
|
106
105
|
return {
|
|
107
106
|
blockchain: this._service.name,
|
|
@@ -115,7 +114,6 @@ class BlockscoutBDSNeoX extends bs_ethereum_1.RpcBDSEthereum {
|
|
|
115
114
|
.toFormatted(),
|
|
116
115
|
view: 'default',
|
|
117
116
|
events,
|
|
118
|
-
data,
|
|
119
117
|
};
|
|
120
118
|
}
|
|
121
119
|
async getTransactionsByAddress(params) {
|
|
@@ -152,7 +150,7 @@ class BlockscoutBDSNeoX extends bs_ethereum_1.RpcBDSEthereum {
|
|
|
152
150
|
const rawInput = item.raw_input;
|
|
153
151
|
if (rawInput) {
|
|
154
152
|
try {
|
|
155
|
-
const ERC20Interface = new ethers_1.
|
|
153
|
+
const ERC20Interface = new ethers_1.Interface(bs_ethereum_1.ERC20_ABI);
|
|
156
154
|
const result = ERC20Interface.decodeFunctionData('transfer', rawInput);
|
|
157
155
|
if (!result)
|
|
158
156
|
throw new Error('Invalid ERC20 transfer');
|
|
@@ -179,7 +177,6 @@ class BlockscoutBDSNeoX extends bs_ethereum_1.RpcBDSEthereum {
|
|
|
179
177
|
/* empty */
|
|
180
178
|
}
|
|
181
179
|
}
|
|
182
|
-
const data = this._service.neo3NeoXBridgeService._getDataFromBlockscoutTransaction(item);
|
|
183
180
|
const txId = item.hash;
|
|
184
181
|
const transaction = {
|
|
185
182
|
blockchain: this._service.name,
|
|
@@ -192,7 +189,6 @@ class BlockscoutBDSNeoX extends bs_ethereum_1.RpcBDSEthereum {
|
|
|
192
189
|
networkFeeAmount: new blockchain_service_1.BSBigUnitAmount(item.fee.value, this._service.feeToken.decimals).toHuman().toFormatted(),
|
|
193
190
|
view: 'default',
|
|
194
191
|
events,
|
|
195
|
-
data,
|
|
196
192
|
};
|
|
197
193
|
transactions.splice(index, 0, transaction);
|
|
198
194
|
});
|
|
@@ -92,25 +92,29 @@ class BlockscoutFullTransactionsDataService {
|
|
|
92
92
|
tokenUrl: token ? __classPrivateFieldGet(this, _BlockscoutFullTransactionsDataService_service, "f").explorerService.buildContractUrl(token.hash) : undefined,
|
|
93
93
|
token,
|
|
94
94
|
});
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
95
|
+
});
|
|
96
|
+
await Promise.allSettled(eventPromises);
|
|
97
|
+
const itemData = 'data' in item ? item.data : undefined;
|
|
98
|
+
const bridgeData = itemData?.bridgeData;
|
|
99
|
+
if (bridgeData) {
|
|
100
|
+
const bridgeService = __classPrivateFieldGet(this, _BlockscoutFullTransactionsDataService_service, "f").neo3NeoXBridgeService;
|
|
101
|
+
const tokenService = __classPrivateFieldGet(this, _BlockscoutFullTransactionsDataService_service, "f").tokenService;
|
|
102
|
+
const tokenToUse = !bridgeData.neoXTokenHash
|
|
103
|
+
? bridgeService.gasToken
|
|
104
|
+
: bridgeService.tokens.find(token => tokenService.predicateByHash(bridgeData.neoXTokenHash, token));
|
|
105
|
+
if (tokenToUse) {
|
|
101
106
|
newItem = {
|
|
102
107
|
...newItem,
|
|
103
108
|
data: {
|
|
104
109
|
neo3NeoxBridge: {
|
|
105
110
|
amount: new blockchain_service_1.BSBigHumanAmount(bridgeData.amount, tokenToUse.decimals).toFormatted(),
|
|
106
111
|
tokenToUse,
|
|
107
|
-
receiverAddress: bridgeData.
|
|
112
|
+
receiverAddress: bridgeData.receiverAddress,
|
|
108
113
|
},
|
|
109
114
|
},
|
|
110
115
|
};
|
|
111
116
|
}
|
|
112
|
-
}
|
|
113
|
-
await Promise.allSettled(eventPromises);
|
|
117
|
+
}
|
|
114
118
|
transactions.splice(index, 0, newItem);
|
|
115
119
|
});
|
|
116
120
|
await Promise.allSettled(itemPromises);
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { INeo3NeoXBridgeService, TBridgeToken, TNeo3NeoXBridgeServiceBridgeParam, TNeo3NeoXBridgeServiceConstants, TNeo3NeoXBridgeServiceGetApprovalParam, TNeo3NeoXBridgeServiceGetNonceParams, TNeo3NeoXBridgeServiceGetTransactionHashByNonceParams, type TNeo3NeoXBridgeTransactionData, type TTransactionBase } from '@cityofzion/blockchain-service';
|
|
2
|
-
import type { IBSNeoX, TBSNeoXName
|
|
2
|
+
import type { IBSNeoX, TBSNeoXName } from '../../types';
|
|
3
3
|
export declare class Neo3NeoXBridgeService implements INeo3NeoXBridgeService<TBSNeoXName> {
|
|
4
4
|
#private;
|
|
5
5
|
static readonly BRIDGE_SCRIPT_HASH = "0x1212000000000000000000000000000000000004";
|
|
6
6
|
static readonly BRIDGE_BASE_CONFIRMATION_URL = "https://xexplorer.neo.org:8877/api/v1/transactions/deposits";
|
|
7
7
|
readonly gasToken: TBridgeToken<TBSNeoXName>;
|
|
8
8
|
readonly neoToken: TBridgeToken<TBSNeoXName>;
|
|
9
|
+
readonly ndmemeToken: TBridgeToken<TBSNeoXName>;
|
|
10
|
+
readonly tokens: TBridgeToken<TBSNeoXName>[];
|
|
9
11
|
constructor(service: IBSNeoX);
|
|
10
|
-
_getDataFromBlockscoutTransaction(response: TBlockscoutBDSNeoXTransactionApiResponse): TNeo3NeoXBridgeTransactionData<TBSNeoXName> | undefined;
|
|
11
12
|
getBridgeConstants(token: TBridgeToken<TBSNeoXName>): Promise<TNeo3NeoXBridgeServiceConstants>;
|
|
12
13
|
getApprovalFee(params: TNeo3NeoXBridgeServiceGetApprovalParam<TBSNeoXName>): Promise<string>;
|
|
13
14
|
bridge(params: TNeo3NeoXBridgeServiceBridgeParam<TBSNeoXName>): Promise<string>;
|
|
@@ -31,38 +31,19 @@ class Neo3NeoXBridgeService {
|
|
|
31
31
|
_Neo3NeoXBridgeService_service.set(this, void 0);
|
|
32
32
|
__classPrivateFieldSet(this, _Neo3NeoXBridgeService_service, service, "f");
|
|
33
33
|
const neoToken = BSNeoXHelper_1.BSNeoXHelper.getNeoToken(__classPrivateFieldGet(this, _Neo3NeoXBridgeService_service, "f").network);
|
|
34
|
+
const ndmemeToken = BSNeoXHelper_1.BSNeoXHelper.getNdmemeToken(__classPrivateFieldGet(this, _Neo3NeoXBridgeService_service, "f").network);
|
|
34
35
|
this.gasToken = { ...BSNeoXConstants_1.BSNeoXConstants.NATIVE_ASSET, blockchain: service.name, multichainId: 'gas' };
|
|
35
36
|
this.neoToken = { ...neoToken, blockchain: service.name, multichainId: 'neo' };
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const input = BridgeInterface.parseTransaction({ data: response.raw_input });
|
|
43
|
-
const { wallet } = bs_neo3_1.BSNeo3NeonJsSingletonHelper.getInstance();
|
|
44
|
-
const to = input.args._to;
|
|
45
|
-
const receiverAddress = wallet.getAddressFromScriptHash(to.startsWith('0x') ? to.slice(2) : to);
|
|
46
|
-
let tokenToUse;
|
|
47
|
-
let amount;
|
|
48
|
-
if (input.name === 'withdrawNative') {
|
|
49
|
-
tokenToUse = this.gasToken;
|
|
50
|
-
amount = new blockchain_service_1.BSBigUnitAmount(response.value, tokenToUse.decimals)
|
|
51
|
-
.minus(input.args._maxFee.toString())
|
|
52
|
-
.toHuman()
|
|
53
|
-
.toFormatted();
|
|
54
|
-
}
|
|
55
|
-
else if (input.name === 'withdrawToken') {
|
|
56
|
-
tokenToUse = this.neoToken;
|
|
57
|
-
amount = new blockchain_service_1.BSBigUnitAmount(input.args._amount.toString(), tokenToUse.decimals).toHuman().toFormatted();
|
|
58
|
-
}
|
|
59
|
-
if (!tokenToUse || !amount)
|
|
60
|
-
return undefined;
|
|
61
|
-
return { neo3NeoxBridge: { tokenToUse, receiverAddress, amount } };
|
|
37
|
+
this.ndmemeToken = {
|
|
38
|
+
...ndmemeToken,
|
|
39
|
+
blockchain: service.name,
|
|
40
|
+
multichainId: 'ndmeme',
|
|
41
|
+
};
|
|
42
|
+
this.tokens = [this.gasToken, this.neoToken, this.ndmemeToken];
|
|
62
43
|
}
|
|
63
44
|
async getBridgeConstants(token) {
|
|
64
45
|
try {
|
|
65
|
-
const provider = new ethers_1.
|
|
46
|
+
const provider = new ethers_1.JsonRpcProvider(__classPrivateFieldGet(this, _Neo3NeoXBridgeService_service, "f").network.url);
|
|
66
47
|
const bridgeContract = new ethers_1.ethers.Contract(_a.BRIDGE_SCRIPT_HASH, bridge_1.BRIDGE_ABI, provider);
|
|
67
48
|
const isNativeToken = __classPrivateFieldGet(this, _Neo3NeoXBridgeService_service, "f").tokenService.predicateByHash(token, BSNeoXConstants_1.BSNeoXConstants.NATIVE_ASSET);
|
|
68
49
|
const response = isNativeToken
|
|
@@ -101,15 +82,15 @@ class Neo3NeoXBridgeService {
|
|
|
101
82
|
if (isNaN(chainId)) {
|
|
102
83
|
throw new Error('Invalid chainId');
|
|
103
84
|
}
|
|
104
|
-
const signer = await __classPrivateFieldGet(this, _Neo3NeoXBridgeService_service, "f").
|
|
105
|
-
const nonce = await signer.
|
|
85
|
+
const signer = await __classPrivateFieldGet(this, _Neo3NeoXBridgeService_service, "f")._getSigner(params.account);
|
|
86
|
+
const nonce = await signer.getNonce('pending');
|
|
106
87
|
if (isNaN(nonce)) {
|
|
107
88
|
throw new Error('Invalid nonce');
|
|
108
89
|
}
|
|
109
90
|
const approvedEstimated = await signer.estimateGas({ ...populatedApproveTransaction, chainId, nonce, type: 2 });
|
|
110
|
-
const provider = new ethers_1.
|
|
111
|
-
const gasPrice = await provider.
|
|
112
|
-
return new blockchain_service_1.BSBigUnitAmount(gasPrice
|
|
91
|
+
const provider = new ethers_1.JsonRpcProvider(__classPrivateFieldGet(this, _Neo3NeoXBridgeService_service, "f").network.url);
|
|
92
|
+
const { gasPrice } = await provider.getFeeData();
|
|
93
|
+
return new blockchain_service_1.BSBigUnitAmount(gasPrice?.toString() || '0', bs_ethereum_1.BSEthereumConstants.DEFAULT_DECIMALS)
|
|
113
94
|
.multipliedBy(approvedEstimated.toString())
|
|
114
95
|
.toHuman()
|
|
115
96
|
.toFormatted();
|
|
@@ -125,18 +106,19 @@ class Neo3NeoXBridgeService {
|
|
|
125
106
|
if (__classPrivateFieldGet(this, _Neo3NeoXBridgeService_service, "f").network.type !== 'mainnet') {
|
|
126
107
|
throw new blockchain_service_1.BSError('Bridging to Neo3 is only supported on mainnet', 'UNSUPPORTED_NETWORK');
|
|
127
108
|
}
|
|
128
|
-
const signer = await __classPrivateFieldGet(this, _Neo3NeoXBridgeService_service, "f").
|
|
109
|
+
const signer = await __classPrivateFieldGet(this, _Neo3NeoXBridgeService_service, "f")._getSigner(params.account);
|
|
129
110
|
const bridgeContract = new ethers_1.ethers.Contract(_a.BRIDGE_SCRIPT_HASH, bridge_1.BRIDGE_ABI);
|
|
130
111
|
const { wallet } = bs_neo3_1.BSNeo3NeonJsSingletonHelper.getInstance();
|
|
131
112
|
const to = `0x${wallet.getScriptHashFromAddress(params.receiverAddress)}`;
|
|
132
|
-
const bridgeFee = new blockchain_service_1.BSBigHumanAmount(params.bridgeFee, BSNeoXConstants_1.BSNeoXConstants.NATIVE_ASSET.decimals).toUnit().
|
|
113
|
+
const bridgeFee = new blockchain_service_1.BSBigHumanAmount(params.bridgeFee, BSNeoXConstants_1.BSNeoXConstants.NATIVE_ASSET.decimals).toUnit().toFixed();
|
|
133
114
|
const isNativeToken = __classPrivateFieldGet(this, _Neo3NeoXBridgeService_service, "f").tokenService.predicateByHash(params.token, BSNeoXConstants_1.BSNeoXConstants.NATIVE_ASSET);
|
|
134
|
-
const
|
|
135
|
-
const
|
|
115
|
+
const provider = new ethers_1.JsonRpcProvider(__classPrivateFieldGet(this, _Neo3NeoXBridgeService_service, "f").network.url);
|
|
116
|
+
const { gasPrice } = await provider.getFeeData();
|
|
117
|
+
const gasPriceBn = new blockchain_service_1.BSBigUnitAmount(gasPrice?.toString() || '0', bs_ethereum_1.BSEthereumConstants.DEFAULT_DECIMALS);
|
|
136
118
|
const transactionParams = { type: 2 };
|
|
137
119
|
if (isNativeToken) {
|
|
138
|
-
const populatedTransactionParams = await bridgeContract.populateTransaction
|
|
139
|
-
const value = new blockchain_service_1.BSBigHumanAmount(params.amount, params.token.decimals).toUnit().plus(bridgeFee).
|
|
120
|
+
const populatedTransactionParams = await bridgeContract.withdrawNative.populateTransaction(to, bridgeFee);
|
|
121
|
+
const value = new blockchain_service_1.BSBigHumanAmount(params.amount, params.token.decimals).toUnit().plus(bridgeFee).toFixed();
|
|
140
122
|
Object.assign(transactionParams, populatedTransactionParams, { value });
|
|
141
123
|
}
|
|
142
124
|
else {
|
|
@@ -147,12 +129,12 @@ class Neo3NeoXBridgeService {
|
|
|
147
129
|
gasPriceBn,
|
|
148
130
|
transactionParams: approveTransactionParam,
|
|
149
131
|
});
|
|
150
|
-
const provider = new ethers_1.
|
|
132
|
+
const provider = new ethers_1.JsonRpcProvider(__classPrivateFieldGet(this, _Neo3NeoXBridgeService_service, "f").network.url);
|
|
151
133
|
await provider.waitForTransaction(transactionHash);
|
|
152
134
|
}
|
|
153
135
|
const fixedAmount = new blockchain_service_1.BSBigHumanAmount(params.amount, 0).toFormatted();
|
|
154
|
-
const amount = new blockchain_service_1.BSBigHumanAmount(fixedAmount, params.token.decimals).toUnit().
|
|
155
|
-
const populatedTransactionParams = await bridgeContract.populateTransaction
|
|
136
|
+
const amount = new blockchain_service_1.BSBigHumanAmount(fixedAmount, params.token.decimals).toUnit().toFixed();
|
|
137
|
+
const populatedTransactionParams = await bridgeContract.withdrawToken.populateTransaction(params.token.hash, to, amount);
|
|
156
138
|
Object.assign(transactionParams, populatedTransactionParams, { value: bridgeFee });
|
|
157
139
|
}
|
|
158
140
|
const { transactionHash } = await __classPrivateFieldGet(this, _Neo3NeoXBridgeService_service, "f")._sendTransaction({ signer, gasPriceBn, transactionParams });
|
|
@@ -165,16 +147,18 @@ class Neo3NeoXBridgeService {
|
|
|
165
147
|
});
|
|
166
148
|
if (!transactionLogsResponse)
|
|
167
149
|
throw new blockchain_service_1.BSError('Failed to get nonce from transaction log', 'FAILED_TO_GET_NONCE', transactionLogsResponseError);
|
|
168
|
-
const [nonce, nonceError] = await blockchain_service_1.BSUtilsHelper.tryCatch(() => {
|
|
169
|
-
const BridgeInterface = new ethers_1.
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
150
|
+
const [nonce, nonceError] = await blockchain_service_1.BSUtilsHelper.tryCatch(async () => {
|
|
151
|
+
const BridgeInterface = new ethers_1.Interface(bridge_1.BRIDGE_ABI);
|
|
152
|
+
for (const log of transactionLogsResponse.data.items) {
|
|
153
|
+
const [parsedNonce] = await blockchain_service_1.BSUtilsHelper.tryCatch(() => {
|
|
154
|
+
const parsedLog = BridgeInterface.parseLog({ data: log.data, topics: log.topics.filter(Boolean) });
|
|
155
|
+
const nonce = parsedLog?.args?.nonce;
|
|
156
|
+
return nonce !== undefined && nonce !== null ? nonce.toString() : undefined;
|
|
157
|
+
});
|
|
158
|
+
if (parsedNonce)
|
|
159
|
+
return parsedNonce;
|
|
160
|
+
}
|
|
161
|
+
return undefined;
|
|
178
162
|
});
|
|
179
163
|
if (!nonce) {
|
|
180
164
|
throw new blockchain_service_1.BSError('Failed to get nonce from transaction log', 'FAILED_TO_GET_NONCE', nonceError);
|
|
@@ -189,7 +173,7 @@ class Neo3NeoXBridgeService {
|
|
|
189
173
|
url = `${_a.BRIDGE_BASE_CONFIRMATION_URL}/${params.nonce}`;
|
|
190
174
|
}
|
|
191
175
|
else {
|
|
192
|
-
url = `${_a.BRIDGE_BASE_CONFIRMATION_URL}/${
|
|
176
|
+
url = `${_a.BRIDGE_BASE_CONFIRMATION_URL}/${params.token.hash}/${params.nonce}`;
|
|
193
177
|
}
|
|
194
178
|
const response = await axios_1.default.get(url);
|
|
195
179
|
if (!response.data?.txid) {
|
|
@@ -202,8 +186,7 @@ class Neo3NeoXBridgeService {
|
|
|
202
186
|
}
|
|
203
187
|
}
|
|
204
188
|
getTokenByMultichainId(multichainId) {
|
|
205
|
-
|
|
206
|
-
return tokens.find(token => token.multichainId === multichainId);
|
|
189
|
+
return this.tokens.find(token => token.multichainId === multichainId);
|
|
207
190
|
}
|
|
208
191
|
getTransactionData(transaction) {
|
|
209
192
|
return transaction.data?.neo3NeoxBridge ? transaction.data : undefined;
|
|
@@ -211,17 +194,17 @@ class Neo3NeoXBridgeService {
|
|
|
211
194
|
}
|
|
212
195
|
exports.Neo3NeoXBridgeService = Neo3NeoXBridgeService;
|
|
213
196
|
_a = Neo3NeoXBridgeService, _Neo3NeoXBridgeService_service = new WeakMap(), _Neo3NeoXBridgeService_instances = new WeakSet(), _Neo3NeoXBridgeService_buildApproveTransactionParam = async function _Neo3NeoXBridgeService_buildApproveTransactionParam(params) {
|
|
214
|
-
const provider = new ethers_1.
|
|
197
|
+
const provider = new ethers_1.JsonRpcProvider(__classPrivateFieldGet(this, _Neo3NeoXBridgeService_service, "f").network.url);
|
|
215
198
|
const erc20Contract = new ethers_1.ethers.Contract(params.token.hash, bs_ethereum_1.ERC20_ABI, provider);
|
|
216
199
|
const allowance = await erc20Contract.allowance(params.account.address, _a.BRIDGE_SCRIPT_HASH);
|
|
217
200
|
const allowanceNumber = new blockchain_service_1.BSBigUnitAmount(allowance.toString(), this.neoToken.decimals);
|
|
218
201
|
// We are using 0 as the decimals because the NEO token in Neo3 has 0 decimals
|
|
219
202
|
const fixedAmount = new blockchain_service_1.BSBigHumanAmount(params.amount, 0).toFormatted();
|
|
220
|
-
const amount = new blockchain_service_1.BSBigHumanAmount(fixedAmount, params.token.decimals).toUnit().
|
|
203
|
+
const amount = new blockchain_service_1.BSBigHumanAmount(fixedAmount, params.token.decimals).toUnit().toFixed();
|
|
221
204
|
if (allowanceNumber.isGreaterThanOrEqualTo(amount)) {
|
|
222
205
|
return null;
|
|
223
206
|
}
|
|
224
|
-
return await erc20Contract.populateTransaction
|
|
207
|
+
return await erc20Contract.approve.populateTransaction(_a.BRIDGE_SCRIPT_HASH, amount);
|
|
225
208
|
};
|
|
226
209
|
Neo3NeoXBridgeService.BRIDGE_SCRIPT_HASH = '0x1212000000000000000000000000000000000004';
|
|
227
210
|
Neo3NeoXBridgeService.BRIDGE_BASE_CONFIRMATION_URL = 'https://xexplorer.neo.org:8877/api/v1/transactions/deposits';
|
|
@@ -12,7 +12,7 @@ class GhostMarketNDSNeoX extends blockchain_service_1.GhostMarketNDS {
|
|
|
12
12
|
try {
|
|
13
13
|
if (!collectionHash)
|
|
14
14
|
return false;
|
|
15
|
-
const provider = new ethers_1.
|
|
15
|
+
const provider = new ethers_1.JsonRpcProvider(this._service.network.url);
|
|
16
16
|
const contract = new ethers_1.ethers.Contract(collectionHash, bs_ethereum_1.ERC20_ABI, provider);
|
|
17
17
|
const response = await contract.balanceOf(address);
|
|
18
18
|
if (!response)
|
|
@@ -2,9 +2,11 @@ import { type TWalletConnectEthereumHandlers, WalletConnectServiceEthereum } fro
|
|
|
2
2
|
import type { IBSNeoX, TBSNeoXName, TBSNeoXNetworkId, TWalletConnectServiceNeoxMethod } from '../../types';
|
|
3
3
|
import z from 'zod';
|
|
4
4
|
declare const getCachedTransactionParamsSchema: z.ZodTuple<[z.ZodString, z.ZodString], null>;
|
|
5
|
+
declare const getNonceParamsSchema: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
5
6
|
type TWalletConnectNeoXHandlers = TWalletConnectEthereumHandlers & {
|
|
6
7
|
eth_getTransactionCount: unknown;
|
|
7
8
|
eth_getCachedTransaction: z.infer<typeof getCachedTransactionParamsSchema>;
|
|
9
|
+
eth_getNonce: z.infer<typeof getNonceParamsSchema>;
|
|
8
10
|
};
|
|
9
11
|
export declare class WalletConnectServiceNeoX extends WalletConnectServiceEthereum<TBSNeoXName, TBSNeoXNetworkId, TWalletConnectServiceNeoxMethod, TWalletConnectNeoXHandlers> {
|
|
10
12
|
#private;
|
|
@@ -7,7 +7,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
7
7
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
8
8
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
9
9
|
};
|
|
10
|
-
var _WalletConnectServiceNeoX_getTransactionCountHandler, _WalletConnectServiceNeoX_getCachedTransactionHandler, _WalletConnectServiceNeoX_sendTransactionHandler;
|
|
10
|
+
var _WalletConnectServiceNeoX_getTransactionCountHandler, _WalletConnectServiceNeoX_getCachedTransactionHandler, _WalletConnectServiceNeoX_getNonce, _WalletConnectServiceNeoX_sendTransactionHandler;
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.WalletConnectServiceNeoX = void 0;
|
|
13
13
|
const blockchain_service_1 = require("@cityofzion/blockchain-service");
|
|
@@ -17,24 +17,25 @@ const viem_1 = require("viem");
|
|
|
17
17
|
const axios_1 = __importDefault(require("axios"));
|
|
18
18
|
const zod_1 = __importDefault(require("zod"));
|
|
19
19
|
const getCachedTransactionParamsSchema = zod_1.default.tuple([zod_1.default.string(), zod_1.default.string()]);
|
|
20
|
+
const getNonceParamsSchema = zod_1.default.union([zod_1.default.string(), zod_1.default.number()]).optional();
|
|
20
21
|
class WalletConnectServiceNeoX extends bs_ethereum_1.WalletConnectServiceEthereum {
|
|
21
22
|
constructor(service) {
|
|
22
23
|
super(service);
|
|
23
24
|
_WalletConnectServiceNeoX_getTransactionCountHandler.set(this, {
|
|
24
25
|
validate: async () => { },
|
|
25
26
|
process: async (args) => {
|
|
26
|
-
const wallet = await this._service.
|
|
27
|
-
const provider = new ethers_1.
|
|
27
|
+
const wallet = await this._service._getSigner(args.account);
|
|
28
|
+
const provider = new ethers_1.JsonRpcProvider(this._service.network.url);
|
|
28
29
|
const connectedWallet = wallet.connect(provider);
|
|
29
|
-
return await connectedWallet.
|
|
30
|
+
return await connectedWallet.getNonce('pending');
|
|
30
31
|
},
|
|
31
32
|
});
|
|
32
33
|
_WalletConnectServiceNeoX_getCachedTransactionHandler.set(this, {
|
|
33
34
|
validate: async (params) => await getCachedTransactionParamsSchema.parseAsync(params),
|
|
34
35
|
process: async (args) => {
|
|
35
36
|
const url = this._service.network.url;
|
|
36
|
-
const wallet = await this._service.
|
|
37
|
-
const provider = new ethers_1.
|
|
37
|
+
const wallet = await this._service._getSigner(args.account);
|
|
38
|
+
const provider = new ethers_1.JsonRpcProvider(url);
|
|
38
39
|
const connectedWallet = wallet.connect(provider);
|
|
39
40
|
const nonce = args.params[0];
|
|
40
41
|
const signature = await connectedWallet.signMessage(nonce.toString());
|
|
@@ -49,27 +50,37 @@ class WalletConnectServiceNeoX extends bs_ethereum_1.WalletConnectServiceEthereu
|
|
|
49
50
|
return cachedTransactionResponse.data.result;
|
|
50
51
|
},
|
|
51
52
|
});
|
|
53
|
+
_WalletConnectServiceNeoX_getNonce.set(this, {
|
|
54
|
+
validate: async (params) => await getNonceParamsSchema.parseAsync(params),
|
|
55
|
+
process: async (args) => {
|
|
56
|
+
const wallet = await this._service._getSigner(args.account);
|
|
57
|
+
return await wallet.getNonce(args.params || 'pending');
|
|
58
|
+
},
|
|
59
|
+
});
|
|
52
60
|
_WalletConnectServiceNeoX_sendTransactionHandler.set(this, {
|
|
53
61
|
validate: async (params) => await this._sendTransactionHandler.validate(params),
|
|
54
62
|
process: async (args) => {
|
|
55
63
|
const { transaction, connectedWallet } = await this._resolveTransactionParams(args);
|
|
56
|
-
const
|
|
57
|
-
const
|
|
64
|
+
const provider = new ethers_1.JsonRpcProvider(this._service.network.url);
|
|
65
|
+
const populatedTransaction = await connectedWallet.populateTransaction(transaction);
|
|
66
|
+
const signedTransaction = await connectedWallet.signTransaction(populatedTransaction);
|
|
67
|
+
const transactionHash = await provider.send('eth_sendRawTransaction', [signedTransaction]);
|
|
58
68
|
if (!transactionHash) {
|
|
59
|
-
throw
|
|
69
|
+
throw new blockchain_service_1.BSError('Transaction error', 'TRANSACTION_ERROR');
|
|
60
70
|
}
|
|
61
71
|
return transactionHash;
|
|
62
72
|
},
|
|
63
73
|
});
|
|
64
|
-
this.supportedMethods.push('eth_getTransactionCount', 'eth_getCachedTransaction');
|
|
65
|
-
this.autoApproveMethods.push('eth_getTransactionCount', 'eth_getCachedTransaction');
|
|
74
|
+
this.supportedMethods.push('eth_getTransactionCount', 'eth_getCachedTransaction', 'eth_getNonce');
|
|
75
|
+
this.autoApproveMethods.push('eth_getTransactionCount', 'eth_getCachedTransaction', 'eth_getNonce');
|
|
66
76
|
this.handlers = {
|
|
67
77
|
...this.handlers,
|
|
68
78
|
eth_getTransactionCount: __classPrivateFieldGet(this, _WalletConnectServiceNeoX_getTransactionCountHandler, "f"),
|
|
69
79
|
eth_getCachedTransaction: __classPrivateFieldGet(this, _WalletConnectServiceNeoX_getCachedTransactionHandler, "f"),
|
|
80
|
+
eth_getNonce: __classPrivateFieldGet(this, _WalletConnectServiceNeoX_getNonce, "f"),
|
|
70
81
|
eth_sendTransaction: __classPrivateFieldGet(this, _WalletConnectServiceNeoX_sendTransactionHandler, "f"),
|
|
71
82
|
};
|
|
72
83
|
}
|
|
73
84
|
}
|
|
74
85
|
exports.WalletConnectServiceNeoX = WalletConnectServiceNeoX;
|
|
75
|
-
_WalletConnectServiceNeoX_getTransactionCountHandler = new WeakMap(), _WalletConnectServiceNeoX_getCachedTransactionHandler = new WeakMap(), _WalletConnectServiceNeoX_sendTransactionHandler = new WeakMap();
|
|
86
|
+
_WalletConnectServiceNeoX_getTransactionCountHandler = new WeakMap(), _WalletConnectServiceNeoX_getCachedTransactionHandler = new WeakMap(), _WalletConnectServiceNeoX_getNonce = new WeakMap(), _WalletConnectServiceNeoX_sendTransactionHandler = new WeakMap();
|
package/dist/types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { BSBigUnitAmount, IBSWithNeo3NeoXBridge, TBSNetworkId } from '@cityofzion/blockchain-service';
|
|
2
2
|
import { ERC20_ABI, IBSEthereum, type TWalletConnectServiceEthereumMethod } from '@cityofzion/bs-ethereum';
|
|
3
|
-
import {
|
|
3
|
+
import { Signer, type TransactionRequest } from 'ethers';
|
|
4
4
|
import type { Neo3NeoXBridgeService } from './services/neo3-neox-bridge/Neo3NeoXBridgeService';
|
|
5
5
|
export type TBSNeoXNetworkId = TBSNetworkId<'47763' | '12227332'>;
|
|
6
6
|
export type TBSNeoXName = 'neox';
|
|
@@ -94,10 +94,10 @@ export type TNeo3NeoXBridgeServiceGetTransactionByNonceApiReponse = {
|
|
|
94
94
|
export type TSendTransactionParams = {
|
|
95
95
|
signer: Signer;
|
|
96
96
|
gasPriceBn: BSBigUnitAmount;
|
|
97
|
-
transactionParams:
|
|
97
|
+
transactionParams: TransactionRequest;
|
|
98
98
|
};
|
|
99
99
|
export type TSendTransactionResponse = {
|
|
100
100
|
transactionHash: string;
|
|
101
101
|
fee: string;
|
|
102
102
|
};
|
|
103
|
-
export type TWalletConnectServiceNeoxMethod = TWalletConnectServiceEthereumMethod | 'eth_getTransactionCount' | 'eth_getCachedTransaction';
|
|
103
|
+
export type TWalletConnectServiceNeoxMethod = TWalletConnectServiceEthereumMethod | 'eth_getTransactionCount' | 'eth_getCachedTransaction' | 'eth_getNonce';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cityofzion/bs-neox",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.18",
|
|
4
4
|
"repository": "https://github.com/CityOfZion/blockchain-services",
|
|
5
5
|
"license": "GPL-3.0-only",
|
|
6
6
|
"author": "Coz",
|
|
@@ -11,23 +11,24 @@
|
|
|
11
11
|
],
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"@cityofzion/dora-ts": "0.6.2",
|
|
14
|
-
"axios": "
|
|
15
|
-
"ethers": "
|
|
14
|
+
"axios": "1.16.0",
|
|
15
|
+
"ethers": "6.16.0",
|
|
16
16
|
"neox-tpke": "~1.0.5",
|
|
17
|
-
"viem": "~2.
|
|
18
|
-
"zod": "~4.3
|
|
19
|
-
"@cityofzion/bs-
|
|
20
|
-
"@cityofzion/bs-
|
|
21
|
-
"@cityofzion/blockchain-service": "3.1.
|
|
17
|
+
"viem": "~2.48.8",
|
|
18
|
+
"zod": "~4.4.3",
|
|
19
|
+
"@cityofzion/bs-neo3": "3.1.18",
|
|
20
|
+
"@cityofzion/bs-ethereum": "3.1.18",
|
|
21
|
+
"@cityofzion/blockchain-service": "3.1.18"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@ledgerhq/hw-transport": "
|
|
25
|
-
"@ledgerhq/hw-transport-node-hid": "~6.
|
|
24
|
+
"@ledgerhq/hw-transport": "6.35.1",
|
|
25
|
+
"@ledgerhq/hw-transport-node-hid": "~6.33.1",
|
|
26
|
+
"@types/node": "~25.6.0",
|
|
26
27
|
"date-fns": "~4.1.0",
|
|
27
|
-
"dotenv": "~17.
|
|
28
|
-
"eslint": "~
|
|
29
|
-
"typescript": "~
|
|
30
|
-
"vitest": "~4.
|
|
28
|
+
"dotenv": "~17.4.2",
|
|
29
|
+
"eslint": "~10.3.0",
|
|
30
|
+
"typescript": "~6.0.3",
|
|
31
|
+
"vitest": "~4.1.5"
|
|
31
32
|
},
|
|
32
33
|
"scripts": {
|
|
33
34
|
"build": "rm -rf ./dist && rm -f *.tgz && npm run typecheck && tsc --project tsconfig.build.json",
|