@exodus/ethereum-lib 2.13.3 → 2.13.5

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/ethereum-lib",
3
- "version": "2.13.3",
3
+ "version": "2.13.5",
4
4
  "description": "Ethereum Library",
5
5
  "main": "src/index.js",
6
6
  "author": "Exodus Movement, Inc.",
@@ -24,5 +24,5 @@
24
24
  "peerDependencies": {
25
25
  "@exodus/assets": "8.0.x"
26
26
  },
27
- "gitHead": "163192db3e616071238360a14577e6a5c570a51e"
27
+ "gitHead": "7d9f726b6115d756d5fbed46664d466972c0f314"
28
28
  }
package/src/abi/index.js CHANGED
@@ -7,6 +7,7 @@ import kyberv2 from './kyberv2.js'
7
7
  import loomv2Swap from './loomv2-swap'
8
8
  import repv2 from './repv2'
9
9
  import scdMcdMigration from './scd-mcd-migration'
10
+ import maticValidatorShare from './matic-validator-share'
10
11
 
11
12
  export default {
12
13
  ant,
@@ -18,4 +19,5 @@ export default {
18
19
  loomv2Swap,
19
20
  repv2,
20
21
  scdMcdMigration,
22
+ maticValidatorShare,
21
23
  }
@@ -0,0 +1,87 @@
1
+ // Everstake Validator
2
+ // https://etherscan.io/address/0xf30cf4ed712d3734161fdaab5b1dbb49fd2d0e5c#code
3
+
4
+ export default [
5
+ {
6
+ inputs: [{ internalType: 'address', name: '_registry', type: 'address' }],
7
+ payable: false,
8
+ stateMutability: 'nonpayable',
9
+ type: 'constructor',
10
+ },
11
+ {
12
+ anonymous: false,
13
+ inputs: [
14
+ { indexed: false, internalType: 'address', name: '_new', type: 'address' },
15
+ { indexed: false, internalType: 'address', name: '_old', type: 'address' },
16
+ ],
17
+ name: 'OwnerUpdate',
18
+ type: 'event',
19
+ },
20
+ {
21
+ anonymous: false,
22
+ inputs: [
23
+ { indexed: true, internalType: 'address', name: '_new', type: 'address' },
24
+ { indexed: true, internalType: 'address', name: '_old', type: 'address' },
25
+ ],
26
+ name: 'ProxyUpdated',
27
+ type: 'event',
28
+ },
29
+ { payable: true, stateMutability: 'payable', type: 'fallback' },
30
+ {
31
+ constant: true,
32
+ inputs: [],
33
+ name: 'implementation',
34
+ outputs: [{ internalType: 'address', name: '', type: 'address' }],
35
+ payable: false,
36
+ stateMutability: 'view',
37
+ type: 'function',
38
+ },
39
+ {
40
+ constant: true,
41
+ inputs: [],
42
+ name: 'owner',
43
+ outputs: [{ internalType: 'address', name: '', type: 'address' }],
44
+ payable: false,
45
+ stateMutability: 'view',
46
+ type: 'function',
47
+ },
48
+ {
49
+ constant: true,
50
+ inputs: [],
51
+ name: 'proxyType',
52
+ outputs: [{ internalType: 'uint256', name: 'proxyTypeId', type: 'uint256' }],
53
+ payable: false,
54
+ stateMutability: 'pure',
55
+ type: 'function',
56
+ },
57
+ {
58
+ constant: false,
59
+ inputs: [{ internalType: 'address', name: 'newOwner', type: 'address' }],
60
+ name: 'transferOwnership',
61
+ outputs: [],
62
+ payable: false,
63
+ stateMutability: 'nonpayable',
64
+ type: 'function',
65
+ },
66
+ {
67
+ constant: false,
68
+ inputs: [
69
+ { internalType: 'address', name: '_newProxyTo', type: 'address' },
70
+ { internalType: 'bytes', name: 'data', type: 'bytes' },
71
+ ],
72
+ name: 'updateAndCall',
73
+ outputs: [],
74
+ payable: true,
75
+ stateMutability: 'payable',
76
+ type: 'function',
77
+ },
78
+ {
79
+ constant: false,
80
+ inputs: [{ internalType: 'address', name: '_newProxyTo', type: 'address' }],
81
+ name: 'updateImplementation',
82
+ outputs: [],
83
+ payable: false,
84
+ stateMutability: 'nonpayable',
85
+ type: 'function',
86
+ },
87
+ ]
package/src/constants.js CHANGED
@@ -35,3 +35,14 @@ export const ETHEREUM_LIKE_TOKEN_TYPES = [
35
35
  'FTM_ERC20',
36
36
  ]
37
37
  export const BUMP_RATE = 1.2
38
+ export const TX_METHOD = {
39
+ MaticStaking: {
40
+ Stake: 'stake_matic',
41
+ Unstake: 'unstake_matic',
42
+ WithdrawRewards: 'withdraw_rewards_matic',
43
+ },
44
+ }
45
+
46
+ export const MATIC_VALIDATOR = {
47
+ EverStake: '0xf30cf4ed712d3734161fdaab5b1dbb49fd2d0e5c',
48
+ }
@@ -1,9 +1,9 @@
1
1
  import SolidityContract from '@exodus/solidity-contract'
2
2
  import ABI from '../abi'
3
3
 
4
- export default function createContract(address, assetName) {
4
+ export default function createContract(address, contractName) {
5
5
  // keep switch logic in anticipation of support for ERC721
6
- switch (assetName) {
6
+ switch (contractName) {
7
7
  // case 'dai':
8
8
  // return new SolidityContract(ABI.dai, address)
9
9
  // case 'cdai':
@@ -18,6 +18,8 @@ export default function createContract(address, assetName) {
18
18
  return new SolidityContract(ABI.loomv2Swap, address)
19
19
  case 'kyberv2':
20
20
  return new SolidityContract(ABI.kyberv2, address)
21
+ case 'maticValidatorShare':
22
+ return new SolidityContract(ABI.maticValidatorShare, address)
21
23
  default:
22
24
  return SolidityContract.erc20(address)
23
25
  }
@@ -20,15 +20,15 @@ export default function createUnsignedTx({
20
20
  chainId,
21
21
  eip1559Enabled,
22
22
  }): UnsignedTransaction {
23
+ const baseAsset = asset.baseAsset
24
+ if (!chainId) chainId = CHAIN_IDS[baseAsset.name] // mainnet
25
+
23
26
  if (txInput) {
24
27
  txInput = toBuffer(txInput) // If txInput is already a Buffer, then it is passed through
25
28
  } else {
26
29
  txInput = Buffer.alloc(0)
27
30
  }
28
31
 
29
- const baseAsset = asset.baseAsset
30
- if (!chainId) chainId = CHAIN_IDS[baseAsset.name] // mainnet
31
-
32
32
  const _isToken = isToken(asset)
33
33
  const to = _isToken ? asset.contract.address : address
34
34
  let value = currency2buffer(_isToken ? baseAsset.currency.ZERO : amount)
@@ -6,6 +6,7 @@ import { FeeMarketEIP1559Transaction, Transaction } from '@exodus/ethereumjs-tx'
6
6
  import { uniq } from 'lodash'
7
7
 
8
8
  export { default as calculateExtraEth } from './calculate-extra-eth'
9
+ export { getMaticStaking } from './matic-staking'
9
10
 
10
11
  const base10 = baseX('0123456789')
11
12
  const base16 = baseX('0123456789abcdef')
@@ -80,7 +81,8 @@ export const isApproveTx = (tx) => tx?.data?.data?.startsWith(APPROVE_METHOD_ID)
80
81
 
81
82
  export const isFeePaymentTx = (tx) => tx?.data?.data?.startsWith(FEE_PAYMENT_PREFIX)
82
83
 
83
- export const isRpcBalanceAsset = (asset) => ['bsc', 'matic', 'babydoge_bsc'].includes(asset.name)
84
+ export const isRpcBalanceAsset = (asset) =>
85
+ ['bsc', 'matic', 'babydoge_bsc', 'steth'].includes(asset.name)
84
86
 
85
87
  export const getAssetAddresses = (asset) => {
86
88
  // It seems to be two schemas of assets. The original and the transformed by the client.
@@ -0,0 +1,34 @@
1
+ import assert from 'assert'
2
+ import { MATIC_VALIDATOR, TX_METHOD } from '../constants'
3
+ import createContract from '../create-contract'
4
+
5
+ const maticValidatorShareContract = createContract(MATIC_VALIDATOR.EverStake, 'maticValidatorShare')
6
+
7
+ const getBuyVoucherTxData = ({ contract, amount }) => {
8
+ return contract.buyVoucher(amount.toBase().toString({ unit: false }), 0)
9
+ }
10
+
11
+ const getSellVoucherTxData = ({ contract, amount }) => {
12
+ return contract.sellVoucher_new(
13
+ amount.toBase().toString({ unit: false }),
14
+ amount.toBase().toString({ unit: false })
15
+ )
16
+ }
17
+
18
+ const getWidthrawRewardsTxData = ({ contract }) => {
19
+ return contract.withdrawRewards()
20
+ }
21
+
22
+ const getTxDataMapping = {
23
+ [TX_METHOD.MaticStaking.Stake]: getBuyVoucherTxData,
24
+ [TX_METHOD.MaticStaking.Unstake]: getSellVoucherTxData,
25
+ [TX_METHOD.MaticStaking.WithdrawRewards]: getWidthrawRewardsTxData,
26
+ }
27
+
28
+ export function getMaticStaking({ method, amount }) {
29
+ assert(method, 'Missing methid')
30
+ if (getTxDataMapping[method]) {
31
+ return getTxDataMapping[method]({ maticValidatorShareContract, amount })
32
+ }
33
+ throw new Error(`calculateTxInputData > Unsupport method ${method}`)
34
+ }