@exodus/ethereum-api 5.0.13 → 5.1.0-alpha.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/package.json +3 -3
- package/src/index.js +1 -0
- package/src/optimism-gas/addresses.js +1 -0
- package/src/optimism-gas/index.js +16 -0
- package/src/tx-log/clarity-monitor.js +4 -7
- package/src/tx-log/ethereum-monitor.js +3 -7
- package/src/tx-log/ethereum-no-history-monitor.js +8 -18
- package/src/tx-log/monitor-utils/index.js +0 -2
- package/src/tx-log/monitor-utils/exclude-unchaged-token-balances.js +0 -13
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/ethereum-api",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.1.0-alpha.0",
|
|
4
4
|
"description": "Ethereum Api",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"files": [
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@exodus/asset-lib": "^3.7.1",
|
|
18
18
|
"@exodus/crypto": "^1.0.0-rc.0",
|
|
19
|
-
"@exodus/ethereum-lib": "^2.
|
|
19
|
+
"@exodus/ethereum-lib": "^2.27.0-alpha.0",
|
|
20
20
|
"@exodus/ethereumjs-util": "^7.1.0-exodus.6",
|
|
21
21
|
"@exodus/fetch": "^1.2.1",
|
|
22
22
|
"@exodus/simple-retry": "^0.0.6",
|
|
@@ -36,5 +36,5 @@
|
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@exodus/models": "^8.10.4"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "3241be77078ca4bf456bd7b2e8f3fe545142c92e"
|
|
40
40
|
}
|
package/src/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const GAS_ORACLE_ADDRESS = '0x420000000000000000000000000000000000000F'
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as ethUtil from '@exodus/ethereumjs-util'
|
|
2
|
+
import { convertUnsignedTx, createContract } from '@exodus/ethereum-lib'
|
|
3
|
+
import { getServerByName } from '../exodus-eth-server'
|
|
4
|
+
import { GAS_ORACLE_ADDRESS } from './addresses'
|
|
5
|
+
|
|
6
|
+
const gasContract = createContract(GAS_ORACLE_ADDRESS, 'optimismGasOracle')
|
|
7
|
+
|
|
8
|
+
export async function estimateOptimismL1DataFee({ unsignedTx }) {
|
|
9
|
+
const ethjsTx = convertUnsignedTx(unsignedTx)
|
|
10
|
+
const serialized = ethjsTx.serialize()
|
|
11
|
+
const callData = gasContract.getL1Fee.build(serialized)
|
|
12
|
+
const buffer = Buffer.from(callData)
|
|
13
|
+
const data = ethUtil.bufferToHex(buffer)
|
|
14
|
+
const server = getServerByName('optimism')
|
|
15
|
+
return server.ethCall({ to: GAS_ORACLE_ADDRESS, data }, 'latest')
|
|
16
|
+
}
|
|
@@ -8,7 +8,6 @@ import {
|
|
|
8
8
|
getAllLogItemsByAsset,
|
|
9
9
|
checkPendingTransactions,
|
|
10
10
|
getDeriveTransactionsToCheck,
|
|
11
|
-
excludeUnchangedTokenBalances,
|
|
12
11
|
} from './monitor-utils'
|
|
13
12
|
import { getLogItemsFromServerTx, getDeriveDataNeededForTick, filterEffects } from './clarity-utils'
|
|
14
13
|
|
|
@@ -159,7 +158,6 @@ export class ClarityMonitor extends BaseMonitor {
|
|
|
159
158
|
|
|
160
159
|
const accountState = await this.getNewAccountState({
|
|
161
160
|
tokens,
|
|
162
|
-
currentTokenBalances: derivedData.currentAccountState?.tokenBalances,
|
|
163
161
|
ourWalletAddress: derivedData.ourWalletAddress,
|
|
164
162
|
})
|
|
165
163
|
await this.updateAccountState({
|
|
@@ -189,7 +187,7 @@ export class ClarityMonitor extends BaseMonitor {
|
|
|
189
187
|
}
|
|
190
188
|
}
|
|
191
189
|
|
|
192
|
-
async getNewAccountState({ tokens,
|
|
190
|
+
async getNewAccountState({ tokens, ourWalletAddress }) {
|
|
193
191
|
const asset = this.asset
|
|
194
192
|
const newAccountState = {}
|
|
195
193
|
const balances = await this.getBalances({ tokens, ourWalletAddress })
|
|
@@ -198,15 +196,14 @@ export class ClarityMonitor extends BaseMonitor {
|
|
|
198
196
|
newAccountState.balance = asset.currency.baseUnit(balance)
|
|
199
197
|
}
|
|
200
198
|
const tokenBalancePairs = Object.entries(balances).filter((entry) => entry[0] !== asset.name)
|
|
201
|
-
const
|
|
199
|
+
const entries = tokenBalancePairs
|
|
202
200
|
.map((pair) => {
|
|
203
201
|
const token = tokens.find((token) => token.name === pair[0])
|
|
204
202
|
const value = token.currency.baseUnit(pair[1] || 0)
|
|
205
|
-
return [token.name, value]
|
|
203
|
+
return value.isZero ? null : [token.name, value]
|
|
206
204
|
})
|
|
207
205
|
.filter((pair) => pair)
|
|
208
|
-
|
|
209
|
-
const tokenBalances = excludeUnchangedTokenBalances(currentTokenBalances, tokenBalanceEntries)
|
|
206
|
+
const tokenBalances = Object.fromEntries(entries)
|
|
210
207
|
if (!isEmpty(tokenBalances)) newAccountState.tokenBalances = tokenBalances
|
|
211
208
|
return newAccountState
|
|
212
209
|
}
|
|
@@ -11,7 +11,6 @@ import {
|
|
|
11
11
|
getDeriveDataNeededForTick,
|
|
12
12
|
getDeriveTransactionsToCheck,
|
|
13
13
|
getHistoryFromServer,
|
|
14
|
-
excludeUnchangedTokenBalances,
|
|
15
14
|
} from './monitor-utils'
|
|
16
15
|
|
|
17
16
|
import {
|
|
@@ -186,10 +185,8 @@ export class EthereumMonitor extends BaseMonitor {
|
|
|
186
185
|
|
|
187
186
|
const accountState = await this.getNewAccountState({
|
|
188
187
|
tokens,
|
|
189
|
-
currentTokenBalances: derivedData.currentAccountState?.tokenBalances,
|
|
190
188
|
ourWalletAddress: derivedData.ourWalletAddress,
|
|
191
189
|
})
|
|
192
|
-
|
|
193
190
|
await this.updateAccountState({ newData: { index, ...accountState }, walletAccount })
|
|
194
191
|
|
|
195
192
|
await this.removeFromTxLog(txsToRemove)
|
|
@@ -223,7 +220,7 @@ export class EthereumMonitor extends BaseMonitor {
|
|
|
223
220
|
}
|
|
224
221
|
}
|
|
225
222
|
|
|
226
|
-
async getNewAccountState({ tokens,
|
|
223
|
+
async getNewAccountState({ tokens, ourWalletAddress }) {
|
|
227
224
|
const asset = this.asset
|
|
228
225
|
const newAccountState = {}
|
|
229
226
|
const server = this.server
|
|
@@ -239,11 +236,10 @@ export class EthereumMonitor extends BaseMonitor {
|
|
|
239
236
|
.map(async (token) => {
|
|
240
237
|
const { confirmed } = await server.balanceOf(ourWalletAddress, token.contract.address)
|
|
241
238
|
const value = token.currency.baseUnit(confirmed[token.contract.address] || 0)
|
|
242
|
-
return [token.name, value]
|
|
239
|
+
return value.isZero ? null : [token.name, value]
|
|
243
240
|
})
|
|
244
241
|
)
|
|
245
|
-
|
|
246
|
-
const tokenBalances = excludeUnchangedTokenBalances(currentTokenBalances, tokenBalancePairs)
|
|
242
|
+
const tokenBalances = Object.fromEntries(tokenBalancePairs.filter((pair) => pair))
|
|
247
243
|
if (!isEmpty(tokenBalances)) newAccountState.tokenBalances = tokenBalances
|
|
248
244
|
return newAccountState
|
|
249
245
|
}
|
|
@@ -3,11 +3,7 @@ import { getServer } from '@exodus/ethereum-api'
|
|
|
3
3
|
import { DEFAULT_SERVER_URLS } from '@exodus/ethereum-lib'
|
|
4
4
|
import { Tx } from '@exodus/models'
|
|
5
5
|
|
|
6
|
-
import {
|
|
7
|
-
getDeriveDataNeededForTick,
|
|
8
|
-
getDeriveTransactionsToCheck,
|
|
9
|
-
excludeUnchangedTokenBalances,
|
|
10
|
-
} from './monitor-utils'
|
|
6
|
+
import { getDeriveDataNeededForTick, getDeriveTransactionsToCheck } from './monitor-utils'
|
|
11
7
|
|
|
12
8
|
import { isEmpty, unionBy, zipObject } from 'lodash'
|
|
13
9
|
|
|
@@ -61,22 +57,21 @@ export class EthereumNoHistoryMonitor extends BaseMonitor {
|
|
|
61
57
|
return Object.fromEntries(entries)
|
|
62
58
|
}
|
|
63
59
|
|
|
64
|
-
async getNewAccountState({ tokens,
|
|
60
|
+
async getNewAccountState({ tokens, ourWalletAddress }) {
|
|
65
61
|
const asset = this.asset
|
|
66
62
|
const newAccountState = {}
|
|
67
63
|
const balances = await this.getBalances({ tokens, ourWalletAddress })
|
|
68
64
|
const balance = balances[asset.name]
|
|
69
65
|
newAccountState.balance = asset.currency.baseUnit(balance)
|
|
70
66
|
const tokenBalancePairs = Object.entries(balances).filter((entry) => entry[0] !== asset.name)
|
|
71
|
-
const
|
|
67
|
+
const entries = tokenBalancePairs
|
|
72
68
|
.map((pair) => {
|
|
73
69
|
const token = tokens.find((token) => token.name === pair[0])
|
|
74
70
|
const value = token.currency.baseUnit(pair[1] || 0)
|
|
75
|
-
return [token.name, value]
|
|
71
|
+
return value.isZero ? null : [token.name, value]
|
|
76
72
|
})
|
|
77
73
|
.filter((pair) => pair)
|
|
78
|
-
|
|
79
|
-
const tokenBalances = excludeUnchangedTokenBalances(currentTokenBalances, tokenBalanceEntries)
|
|
74
|
+
const tokenBalances = Object.fromEntries(entries)
|
|
80
75
|
if (!isEmpty(tokenBalances)) newAccountState.tokenBalances = tokenBalances
|
|
81
76
|
return newAccountState
|
|
82
77
|
}
|
|
@@ -84,11 +79,7 @@ export class EthereumNoHistoryMonitor extends BaseMonitor {
|
|
|
84
79
|
async deriveData({ assetSource, tokens }) {
|
|
85
80
|
const { assetName, walletAccount } = assetSource
|
|
86
81
|
|
|
87
|
-
const { ourWalletAddress
|
|
88
|
-
assetName,
|
|
89
|
-
walletAccount,
|
|
90
|
-
})
|
|
91
|
-
|
|
82
|
+
const { ourWalletAddress } = await this.deriveDataNeededForTick({ assetName, walletAccount })
|
|
92
83
|
const {
|
|
93
84
|
pendingTransactionsGroupedByAddressAndNonce,
|
|
94
85
|
pendingTransactionsToCheck,
|
|
@@ -105,7 +96,7 @@ export class EthereumNoHistoryMonitor extends BaseMonitor {
|
|
|
105
96
|
'tx.txId'
|
|
106
97
|
)
|
|
107
98
|
|
|
108
|
-
return { ourWalletAddress, pendingTransactions
|
|
99
|
+
return { ourWalletAddress, pendingTransactions }
|
|
109
100
|
}
|
|
110
101
|
|
|
111
102
|
async getTransactionsFromNode(transactions) {
|
|
@@ -157,7 +148,7 @@ export class EthereumNoHistoryMonitor extends BaseMonitor {
|
|
|
157
148
|
|
|
158
149
|
const assetSource = { assetName: this.asset.name, walletAccount }
|
|
159
150
|
|
|
160
|
-
const { ourWalletAddress, pendingTransactions
|
|
151
|
+
const { ourWalletAddress, pendingTransactions } = await this.deriveData({
|
|
161
152
|
assetSource,
|
|
162
153
|
tokens,
|
|
163
154
|
})
|
|
@@ -180,7 +171,6 @@ export class EthereumNoHistoryMonitor extends BaseMonitor {
|
|
|
180
171
|
|
|
181
172
|
const accountState = await this.getNewAccountState({
|
|
182
173
|
tokens,
|
|
183
|
-
currentTokenBalances: currentAccountState?.tokenBalances,
|
|
184
174
|
ourWalletAddress,
|
|
185
175
|
})
|
|
186
176
|
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
export { default as getDeriveDataNeededForTick } from './get-derive-data-needed-for-tick'
|
|
2
|
-
|
|
3
2
|
export { default as getAllLogItemsByAsset } from './get-all-log-items-by-asset'
|
|
4
3
|
export { default as getLogItemsFromServerTx } from './get-log-items-from-server-tx'
|
|
5
4
|
export { default as getHistoryFromServer } from './get-history-from-server'
|
|
6
5
|
export { default as checkPendingTransactions } from './check-pending-transactions'
|
|
7
6
|
export { default as getDeriveTransactionsToCheck } from './get-derive-transactions-to-check'
|
|
8
|
-
export * from './exclude-unchaged-token-balances'
|
|
9
7
|
|
|
10
8
|
export type { PendingTransactionsDictionary } from './types'
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export function excludeUnchangedTokenBalances(currentTokenBalances, newTokenBalancePairs) {
|
|
2
|
-
const newTokenBalances = Object.fromEntries(newTokenBalancePairs)
|
|
3
|
-
|
|
4
|
-
const tokenBalances = newTokenBalancePairs.reduce((tokenBalancesAcc, [token, balance]) => {
|
|
5
|
-
const currentBalance = currentTokenBalances[token]
|
|
6
|
-
if (!newTokenBalances[token].isZero || (currentBalance && !currentBalance.isZero)) {
|
|
7
|
-
tokenBalancesAcc[token] = balance
|
|
8
|
-
}
|
|
9
|
-
return tokenBalancesAcc
|
|
10
|
-
}, {})
|
|
11
|
-
|
|
12
|
-
return tokenBalances
|
|
13
|
-
}
|