@exodus/ethereum-plugin 2.4.1 → 2.4.2

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/CHANGELOG.md CHANGED
@@ -3,6 +3,16 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [2.4.2](https://github.com/ExodusMovement/assets/compare/@exodus/ethereum-plugin@2.4.1...@exodus/ethereum-plugin@2.4.2) (2024-10-09)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * hardening private methods ([#4165](https://github.com/ExodusMovement/assets/issues/4165)) ([cb04b39](https://github.com/ExodusMovement/assets/commit/cb04b39ee3a70abf9a13697e0998e1d55196aac7))
12
+ * staking splitIn32BytesArray hardening and improvements ([#4170](https://github.com/ExodusMovement/assets/issues/4170)) ([2a178ae](https://github.com/ExodusMovement/assets/commit/2a178aefc590186ee699e746d8e71bac1ab8198e))
13
+
14
+
15
+
6
16
  ## [2.4.1](https://github.com/ExodusMovement/assets/compare/@exodus/ethereum-plugin@2.4.0...@exodus/ethereum-plugin@2.4.1) (2024-09-12)
7
17
 
8
18
  **Note:** Version bump only for package @exodus/ethereum-plugin
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/ethereum-plugin",
3
- "version": "2.4.1",
3
+ "version": "2.4.2",
4
4
  "description": "Exodus ethereum-plugin",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -22,7 +22,7 @@
22
22
  "dependencies": {
23
23
  "@exodus/asset-lib": "^5.0.0",
24
24
  "@exodus/currency": "^5.0.2",
25
- "@exodus/ethereum-api": "^8.18.1",
25
+ "@exodus/ethereum-api": "^8.20.0",
26
26
  "@exodus/ethereum-lib": "^5.4.0",
27
27
  "@exodus/ethereum-meta": "^2.0.0",
28
28
  "@exodus/ethereumjs-util": "^7.1.0-exodus.7",
@@ -43,5 +43,5 @@
43
43
  "type": "git",
44
44
  "url": "git+https://github.com/ExodusMovement/assets.git"
45
45
  },
46
- "gitHead": "3885dfad0efad7a6f12053aab220f0b127039fcf"
46
+ "gitHead": "a3826445e762843c0bccc5d9f94ecbb9dfe9648d"
47
47
  }
@@ -1,3 +1,4 @@
1
+ import { fromHexToBN, fromHexToString, splitIn32BytesArray } from '@exodus/ethereum-api'
1
2
  import { createContract } from '@exodus/ethereum-lib'
2
3
  import { bufferToHex } from '@exodus/ethereumjs-util'
3
4
  import { retry } from '@exodus/simple-retry'
@@ -25,12 +26,12 @@ class StakingServer {
25
26
  this.server = server
26
27
  }
27
28
 
28
- buildTxData = (contract, method, ...args) => {
29
+ #buildTxData = (contract, method, ...args) => {
29
30
  return contract[method].build(...args)
30
31
  }
31
32
 
32
- callReadFunctionContract = (contract, method, ...args) => {
33
- const callData = this.buildTxData(contract, method, ...args)
33
+ #callReadFunctionContract = (contract, method, ...args) => {
34
+ const callData = this.#buildTxData(contract, method, ...args)
34
35
  const data = {
35
36
  data: bufferToHex(callData),
36
37
  to: contract.address,
@@ -42,15 +43,15 @@ class StakingServer {
42
43
  }
43
44
 
44
45
  getWithdrawalDelay = async () => {
45
- const withdrawalDelay = await this.callReadFunctionContract(
46
+ const withdrawalDelay = await this.#callReadFunctionContract(
46
47
  this.stakingManagerContract,
47
48
  'withdrawalDelay'
48
49
  )
49
- return toBN(withdrawalDelay)
50
+ return fromHexToBN(withdrawalDelay)
50
51
  }
51
52
 
52
53
  getMinRewardsToWithdraw = async () => {
53
- const minRewardsToWithdraw = await this.callReadFunctionContract(
54
+ const minRewardsToWithdraw = await this.#callReadFunctionContract(
54
55
  this.validatorShareContract,
55
56
  'minAmount'
56
57
  )
@@ -62,8 +63,8 @@ class StakingServer {
62
63
  * stored in a list and points the events that happened in that epoch. (timeline)
63
64
  */
64
65
  getCurrentCheckpoint = async () => {
65
- const currentEpoch = await this.callReadFunctionContract(this.stakingManagerContract, 'epoch')
66
- return toBN(currentEpoch)
66
+ const currentEpoch = await this.#callReadFunctionContract(this.stakingManagerContract, 'epoch')
67
+ return fromHexToBN(currentEpoch)
67
68
  }
68
69
 
69
70
  /**
@@ -77,7 +78,7 @@ class StakingServer {
77
78
  _nonce = await this.getCurrentUnbondNonce(address)
78
79
  }
79
80
 
80
- const unboundInfo = await this.callReadFunctionContract(
81
+ const unboundInfo = await this.#callReadFunctionContract(
81
82
  this.validatorShareContract,
82
83
  'unbonds_new',
83
84
  address,
@@ -86,8 +87,8 @@ class StakingServer {
86
87
 
87
88
  const [shares, withdrawEpoch] = splitIn32BytesArray(unboundInfo)
88
89
  return {
89
- withdrawEpoch: toBN(withdrawEpoch),
90
- shares: toBN(shares),
90
+ withdrawEpoch: fromHexToBN(withdrawEpoch),
91
+ shares: fromHexToBN(shares),
91
92
  }
92
93
  }
93
94
 
@@ -97,7 +98,7 @@ class StakingServer {
97
98
  * @returns current unbonded nonce
98
99
  */
99
100
  getCurrentUnbondNonce = async (address) => {
100
- const unbondNonce = await this.callReadFunctionContract(
101
+ const unbondNonce = await this.#callReadFunctionContract(
101
102
  this.validatorShareContract,
102
103
  'unbondNonces',
103
104
  address
@@ -106,7 +107,7 @@ class StakingServer {
106
107
  }
107
108
 
108
109
  getLiquidRewards = async (address) => {
109
- const liquidRewards = await this.callReadFunctionContract(
110
+ const liquidRewards = await this.#callReadFunctionContract(
110
111
  this.validatorShareContract,
111
112
  'getLiquidRewards',
112
113
  address
@@ -115,22 +116,22 @@ class StakingServer {
115
116
  }
116
117
 
117
118
  getTotalStake = async (address) => {
118
- const stakeInfo = await this.callReadFunctionContract(
119
+ const stakeInfo = await this.#callReadFunctionContract(
119
120
  this.validatorShareContract,
120
121
  'getTotalStake',
121
122
  address
122
123
  )
123
124
  const [amount] = splitIn32BytesArray(stakeInfo)
124
- return this.asset.currency.baseUnit(toBN(amount).toString())
125
+ return this.asset.currency.baseUnit(fromHexToString(amount))
125
126
  }
126
127
 
127
128
  getWithdrawExchangeRate = async () => {
128
- const withdrawExchangeRate = await this.callReadFunctionContract(
129
+ const withdrawExchangeRate = await this.#callReadFunctionContract(
129
130
  this.validatorShareContract,
130
131
  'withdrawExchangeRate'
131
132
  )
132
133
 
133
- return toBN(withdrawExchangeRate)
134
+ return fromHexToBN(withdrawExchangeRate)
134
135
  }
135
136
 
136
137
  /**
@@ -143,7 +144,7 @@ class StakingServer {
143
144
  * @param amount Matic tokens to be approved for StakeManager to withdraw (polygon currency)
144
145
  */
145
146
  approveStakeManager = (amount) => {
146
- return this.buildTxData(
147
+ return this.#buildTxData(
147
148
  this.polygonContract,
148
149
  'increaseAllowance',
149
150
  this.stakingManagerContract.address,
@@ -152,20 +153,20 @@ class StakingServer {
152
153
  }
153
154
 
154
155
  restakeReward = () => {
155
- return this.buildTxData(this.validatorShareContract, 'restake')
156
+ return this.#buildTxData(this.validatorShareContract, 'restake')
156
157
  }
157
158
 
158
159
  withdrawRewards = () => {
159
- return this.buildTxData(this.validatorShareContract, 'withdrawRewards')
160
+ return this.#buildTxData(this.validatorShareContract, 'withdrawRewards')
160
161
  }
161
162
 
162
163
  delegate = ({ amount }) => {
163
- return this.buildTxData(this.validatorShareContract, 'buyVoucher', amount.toBaseString(), '0')
164
+ return this.#buildTxData(this.validatorShareContract, 'buyVoucher', amount.toBaseString(), '0')
164
165
  }
165
166
 
166
167
  undelegate = ({ amount, maximumSharesToBurn }) => {
167
168
  const _maximumSharesToBurn = maximumSharesToBurn || amount
168
- return this.buildTxData(
169
+ return this.#buildTxData(
169
170
  this.validatorShareContract,
170
171
  'sellVoucher_new',
171
172
  amount.toBaseString(),
@@ -177,25 +178,9 @@ class StakingServer {
177
178
  * @param {number} unbondNonce the unbond nonce from where delegator claim its staked tokens
178
179
  */
179
180
  claimUndelegatedBalance = ({ unbondNonce }) => {
180
- return this.buildTxData(this.validatorShareContract, 'unstakeClaimTokens_new', unbondNonce)
181
+ return this.#buildTxData(this.validatorShareContract, 'unstakeClaimTokens_new', unbondNonce)
181
182
  }
182
183
  }
183
184
 
184
- // see arguments encoding standard (padded 32 bytes)
185
- // https://docs.soliditylang.org/en/v0.8.15/abi-spec.html?highlight=abi.encode#function-selector-and-argument-encoding
186
- const splitIn32BytesArray = (output) => removeHexPrefix(output).match(/[\da-f]{1,64}/gi) || []
187
-
188
- const toBN = (str) => new BN(removeLeadingZeroes(removeHexPrefix(str)), 16)
189
-
190
- const removeLeadingZeroes = (str) => str.replace(/^0+/, '')
191
-
192
- const removeHexPrefix = (str) => {
193
- if (typeof str !== 'string' || str === '') {
194
- return str
195
- }
196
-
197
- return str.startsWith('0x') ? str.slice(2) : str
198
- }
199
-
200
185
  export const stakingServerFactory = ({ asset, contracts, server }) =>
201
186
  new StakingServer({ asset, contracts, server })