@exodus/ethereum-api 6.2.5 → 6.2.6
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 +2 -2
- package/src/staking/matic-staking.js +22 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/ethereum-api",
|
|
3
|
-
"version": "6.2.
|
|
3
|
+
"version": "6.2.6",
|
|
4
4
|
"description": "Ethereum Api",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"files": [
|
|
@@ -36,5 +36,5 @@
|
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@exodus/models": "^8.10.4"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "267d6f4bdfeb19fc7cd060b67083ca45437e9bfd"
|
|
40
40
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import BN from 'bn.js'
|
|
2
2
|
import { createContract } from '@exodus/ethereum-lib'
|
|
3
|
+
import ethAssets from '@exodus/ethereum-meta'
|
|
3
4
|
import { asset as polygon } from '@exodus/matic-meta'
|
|
4
5
|
import { getServerByName } from '../exodus-eth-server'
|
|
5
6
|
import { retry } from '@exodus/simple-retry'
|
|
@@ -8,6 +9,8 @@ import { bufferToHex } from '@exodus/ethereumjs-util'
|
|
|
8
9
|
const EVERSTAKE_VALIDATOR_CONTRACT_ADDR = '0xf30cf4ed712d3734161fdaab5b1dbb49fd2d0e5c'
|
|
9
10
|
const STAKING_MANAGER_ADDR = '0x5e3ef299fddf15eaa0432e6e66473ace8c13d908'
|
|
10
11
|
|
|
12
|
+
const polygonEthToken = ethAssets.find(({ name: tokenName }) => tokenName === 'polygon')
|
|
13
|
+
|
|
11
14
|
const RETRY_DELAYS = ['10s']
|
|
12
15
|
|
|
13
16
|
export class MaticStaking {
|
|
@@ -17,6 +20,7 @@ export class MaticStaking {
|
|
|
17
20
|
) {
|
|
18
21
|
this.validatorShareContract = createContract(validatorId, 'maticValidatorShare')
|
|
19
22
|
this.stakingManagerContract = createContract(stakeManagerAddr, 'maticStakingManager')
|
|
23
|
+
this.polygonContract = createContract(polygonEthToken.contract.current, 'polygon')
|
|
20
24
|
}
|
|
21
25
|
|
|
22
26
|
buildTxData = (contract, method, ...args) => {
|
|
@@ -36,6 +40,24 @@ export class MaticStaking {
|
|
|
36
40
|
return retry(eth.ethCall, { delayTimesMs: RETRY_DELAYS })(data)
|
|
37
41
|
}
|
|
38
42
|
|
|
43
|
+
/**
|
|
44
|
+
* Approves StakeManager contract for withdrawing {amount} in Matic tokens
|
|
45
|
+
* when users stakes.
|
|
46
|
+
* This function needs to be called before calling delegate function so that staking
|
|
47
|
+
* can properly work
|
|
48
|
+
* This also partially address the front running attack on ERC20 approve function:
|
|
49
|
+
* https://github.com/OpenZeppelin/openzeppelin-contracts/blob/f959d7e4e6ee0b022b41e5b644c79369869d8411/contracts/token/ERC20/ERC20.sol#L165-L206
|
|
50
|
+
* @param amount Matic tokens to be approved for StakeManager to withdraw (polygon currency)
|
|
51
|
+
*/
|
|
52
|
+
approveStakeManager = (amount) => {
|
|
53
|
+
return this.buildTxData(
|
|
54
|
+
this.polygonContract,
|
|
55
|
+
'increaseAllowance',
|
|
56
|
+
this.polygonContract.address,
|
|
57
|
+
amount.toBaseString()
|
|
58
|
+
)
|
|
59
|
+
}
|
|
60
|
+
|
|
39
61
|
/**
|
|
40
62
|
* A checkpoint is an epoch value that increments in the contract, every epoch is
|
|
41
63
|
* stored in a list and points the events that happened in that epoch. (timeline)
|