@exodus/web3-ethereum-utils 3.34.0 → 3.35.0
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/lib/createSimulateMessage.js +7 -0
- package/lib/simulation/common.d.ts +8 -0
- package/lib/simulation/common.js +6 -0
- package/lib/simulation/estimateFee.js +4 -3
- package/lib/simulation/estimateSimpleTransfer.d.ts +1 -2
- package/lib/simulation/estimateSimpleTransfer.js +3 -2
- package/lib/simulation/tryEstimatingChangesLocally.js +3 -1
- package/lib/simulation/tryParsingSIWE.d.ts +8 -0
- package/lib/simulation/tryParsingSIWE.js +20 -0
- package/package.json +4 -4
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { getMessageType } from './simulation/getMessageType.js';
|
|
2
2
|
import { simulateMessage } from './simulation/simulateMessage.js';
|
|
3
|
+
import { tryParsingSIWE } from './simulation/tryParsingSIWE.js';
|
|
3
4
|
export const createSimulateMessage = ({ apiEndpoint = 'https://simulation.a.exodus.io/simulateMessage', headers = {
|
|
4
5
|
'X-Api-Version': '2023-06-05',
|
|
5
6
|
}, } = {}) => async ({ message, origin, asset, address, }) => {
|
|
@@ -11,6 +12,12 @@ export const createSimulateMessage = ({ apiEndpoint = 'https://simulation.a.exod
|
|
|
11
12
|
if (messageType === 2 /* MessageTypeEnum.Unknown */) {
|
|
12
13
|
return simulationResult;
|
|
13
14
|
}
|
|
15
|
+
tryParsingSIWE({
|
|
16
|
+
message,
|
|
17
|
+
messageType,
|
|
18
|
+
origin,
|
|
19
|
+
simulationResult,
|
|
20
|
+
});
|
|
14
21
|
await simulateMessage({
|
|
15
22
|
address,
|
|
16
23
|
message: {
|
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
import BN from 'bn.js';
|
|
2
|
+
import type { Asset } from '@exodus/web3-types';
|
|
3
|
+
import type { CreateCurrencyParams } from '@exodus/web3-utils';
|
|
4
|
+
export declare const getCreateCurrencyParams: (asset: Asset, amount: CreateCurrencyParams['amount']) => {
|
|
5
|
+
amount: string | number | BN;
|
|
6
|
+
base: string;
|
|
7
|
+
symbol: string;
|
|
8
|
+
denominator: number;
|
|
9
|
+
};
|
|
2
10
|
interface BlowfishEvmChain {
|
|
3
11
|
[key: string]: {
|
|
4
12
|
network: string;
|
package/lib/simulation/common.js
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import BN from 'bn.js';
|
|
2
|
+
export const getCreateCurrencyParams = (asset, amount) => ({
|
|
3
|
+
amount,
|
|
4
|
+
base: 'wei',
|
|
5
|
+
symbol: asset.displayTicker,
|
|
6
|
+
denominator: asset.units[asset.ticker],
|
|
7
|
+
});
|
|
2
8
|
export const BLOWFISH_EVM_CHAINS = {
|
|
3
9
|
ethereum: {
|
|
4
10
|
network: 'ethereum',
|
|
@@ -8,14 +8,15 @@
|
|
|
8
8
|
However, a final fee for non-simple transfers is always calculated on-chain once the EVM executes a transaction
|
|
9
9
|
and has the number of gas consumed.
|
|
10
10
|
*/
|
|
11
|
-
import { hexToBN } from '@exodus/web3-utils';
|
|
11
|
+
import { createCurrency, hexToBN } from '@exodus/web3-utils';
|
|
12
|
+
import { getCreateCurrencyParams } from './common.js';
|
|
12
13
|
export const estimateFee = ({ asset, transaction, }) => {
|
|
13
14
|
const gas = hexToBN(transaction.gas);
|
|
14
15
|
if (transaction.maxFeePerGas) {
|
|
15
16
|
const maxFeePerGas = hexToBN(transaction.maxFeePerGas);
|
|
16
17
|
const maximumFee = gas.mul(maxFeePerGas);
|
|
17
|
-
return asset
|
|
18
|
+
return createCurrency(getCreateCurrencyParams(asset, maximumFee.toString()));
|
|
18
19
|
}
|
|
19
20
|
const gasPrice = hexToBN(transaction.gasPrice);
|
|
20
|
-
return asset
|
|
21
|
+
return createCurrency(getCreateCurrencyParams(asset, gas.mul(gasPrice).toString()));
|
|
21
22
|
};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { EthTransaction } from '../types.js';
|
|
2
|
-
import type { NumberUnit } from '@exodus/web3-types';
|
|
3
|
-
import type { Asset } from '@exodus/web3-types';
|
|
2
|
+
import type { Asset, NumberUnit } from '@exodus/web3-types';
|
|
4
3
|
export declare class NotSimpleTransferError extends Error {
|
|
5
4
|
constructor(msg: string);
|
|
6
5
|
}
|
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
Even empty `data` field transactions ("0x") can cause unexpected state changes if sent to a smart contract
|
|
7
7
|
with a gas limit exceeding 21000 units.
|
|
8
8
|
*/
|
|
9
|
-
import { hexToBN } from '@exodus/web3-utils';
|
|
9
|
+
import { createCurrency, hexToBN } from '@exodus/web3-utils';
|
|
10
|
+
import { getCreateCurrencyParams } from './common.js';
|
|
10
11
|
export class NotSimpleTransferError extends Error {
|
|
11
12
|
constructor(msg) {
|
|
12
13
|
super(msg);
|
|
@@ -18,5 +19,5 @@ export const estimateSimpleTransfer = ({ asset, transaction, }) => {
|
|
|
18
19
|
throw new NotSimpleTransferError('The transaction input should be empty ("0x").');
|
|
19
20
|
}
|
|
20
21
|
const txValue = hexToBN(transaction.value || '0x0').toString();
|
|
21
|
-
return asset
|
|
22
|
+
return createCurrency(getCreateCurrencyParams(asset, txValue));
|
|
22
23
|
};
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { createCurrency } from '@exodus/web3-utils';
|
|
2
|
+
import { getCreateCurrencyParams } from './common.js';
|
|
1
3
|
import { estimateSimpleTransfer, NotSimpleTransferError, } from './estimateSimpleTransfer.js';
|
|
2
4
|
/*
|
|
3
5
|
Mutates the provided 'simulationResult' adding a 'willSend' entry if the transaction is a simple transfer.
|
|
@@ -6,7 +8,7 @@ export const tryEstimatingChangesLocally = ({ asset, simulationResult, transacti
|
|
|
6
8
|
try {
|
|
7
9
|
const estimatedValue = estimateSimpleTransfer({ asset, transaction });
|
|
8
10
|
const actualTransferValue = transaction.from.toLowerCase() === transaction.to.toLowerCase()
|
|
9
|
-
? asset.
|
|
11
|
+
? createCurrency(getCreateCurrencyParams(asset, 0)) // A self-send does not transfer any funds.
|
|
10
12
|
: estimatedValue;
|
|
11
13
|
simulationResult.balanceChanges.willSend.push({
|
|
12
14
|
balance: actualTransferValue,
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { MessageTypeEnum } from './getMessageType.js';
|
|
2
|
+
import type { MessageSimulationResult } from '@exodus/web3-types';
|
|
3
|
+
export declare const tryParsingSIWE: ({ message, messageType, origin, simulationResult, }: {
|
|
4
|
+
message: string;
|
|
5
|
+
messageType: MessageTypeEnum;
|
|
6
|
+
origin: string;
|
|
7
|
+
simulationResult: MessageSimulationResult;
|
|
8
|
+
}) => void;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export const tryParsingSIWE = ({ message, messageType, origin, simulationResult, }) => {
|
|
2
|
+
if (messageType === 1 /* MessageTypeEnum.TypedData */) {
|
|
3
|
+
return;
|
|
4
|
+
}
|
|
5
|
+
/*
|
|
6
|
+
Some dApps don't comply with EIP-4361 and use their custom Sign-In messages. This code block detects such known custom SIWE messages.
|
|
7
|
+
*/
|
|
8
|
+
if (origin.includes('rarible.com') &&
|
|
9
|
+
message.includes('I want to login on Rarible')) {
|
|
10
|
+
simulationResult.kind = {
|
|
11
|
+
kind: 'SIWE',
|
|
12
|
+
info: {
|
|
13
|
+
date: new Date(),
|
|
14
|
+
statement: 'I accept the Rarible Terms of Service https://static.rarible.com/terms.pdf and I am at least 13 years old.',
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
// TODO: add proper EIP-4361 parsing.
|
|
19
|
+
return;
|
|
20
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/web3-ethereum-utils",
|
|
3
3
|
"description": "Web3 Ethereum utils.",
|
|
4
|
-
"version": "3.
|
|
4
|
+
"version": "3.35.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"module": "lib/index.js",
|
|
@@ -27,14 +27,14 @@
|
|
|
27
27
|
"build": "yarn clean && run -T tsc"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@exodus/web3-types": "
|
|
30
|
+
"@exodus/web3-types": "1.49.0"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@exodus/basic-utils": "^2.5.1",
|
|
34
34
|
"@exodus/ethereumjs-common": "^2.4.0-exodus.6",
|
|
35
35
|
"@exodus/ethereumjs-tx": "^3.3.0-exodus.6",
|
|
36
|
-
"@exodus/web3-utils": "^1.47.
|
|
36
|
+
"@exodus/web3-utils": "^1.47.1",
|
|
37
37
|
"@metamask/eth-sig-util": "^4.0.1"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "97a9adffba6edc4a782f45ebbf2fc5f6c188dc4b"
|
|
40
40
|
}
|