-
Notifications
You must be signed in to change notification settings - Fork 2
/
liquidStaking.go
52 lines (46 loc) · 2.02 KB
/
liquidStaking.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
Copyright [2019] - [2021], PERSISTENCE TECHNOLOGIES PTE. LTD. and the persistenceBridge contributors
SPDX-License-Identifier: Apache-2.0
*/
package contracts
import (
"math/big"
sdkTypes "github.com/cosmos/cosmos-sdk/types"
stakingTypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
"github.com/persistenceOne/persistenceBridge/application/configuration"
"github.com/persistenceOne/persistenceBridge/application/constants"
"github.com/persistenceOne/persistenceBridge/utilities/logging"
)
var LiquidStaking = Contract{
name: "LIQUID_STAKING",
address: common.HexToAddress(configuration.GetAppConfig().Ethereum.LiquidStakingAddress),
abi: abi.ABI{},
methods: map[string]func(arguments []interface{}) (sdkTypes.Msg, common.Address, error){
constants.LiquidStakingStake: onStake,
constants.LiquidStakingUnStake: onUnStake,
},
}
func onStake(arguments []interface{}) (sdkTypes.Msg, common.Address, error) {
ercAddress := arguments[0].(common.Address)
amount := sdkTypes.NewIntFromBigInt(arguments[1].(*big.Int))
stakeMsg := &stakingTypes.MsgDelegate{
DelegatorAddress: configuration.GetAppConfig().Tendermint.GetWrapAddress(),
ValidatorAddress: "",
Amount: sdkTypes.NewCoin(configuration.GetAppConfig().Tendermint.Denom, amount),
}
logging.Info("Received ETH Stake Tx from:", ercAddress.String(), "amount:", amount.String())
return stakeMsg, ercAddress, nil
}
func onUnStake(arguments []interface{}) (sdkTypes.Msg, common.Address, error) {
ercAddress := arguments[0].(common.Address)
amount := sdkTypes.NewIntFromBigInt(arguments[1].(*big.Int))
unStakeMsg := &stakingTypes.MsgUndelegate{
DelegatorAddress: configuration.GetAppConfig().Tendermint.GetWrapAddress(),
ValidatorAddress: "",
Amount: sdkTypes.NewCoin(configuration.GetAppConfig().Tendermint.Denom, amount),
}
logging.Info("Received ETH UnStake Tx from:", ercAddress.String(), "amount:", amount.String())
return unStakeMsg, ercAddress, nil
}