-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bb1fad1
commit c86c575
Showing
6 changed files
with
1,284 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package bex | ||
|
||
import ( | ||
"crypto/ecdsa" | ||
"github.com/ethereum/go-ethereum/accounts/abi/bind" | ||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/common/hexutil" | ||
"github.com/ethereum/go-ethereum/core/types" | ||
"github.com/ethereum/go-ethereum/ethclient" | ||
"github.com/tiennampham23/berachain-airdrop/pkg/log" | ||
"github.com/tiennampham23/berachain-airdrop/pkg/utilties/eth" | ||
) | ||
|
||
var ( | ||
ParsedRewardModuleABI, _ = RewardModuleMetaData.GetAbi() | ||
) | ||
|
||
func WithdrawAllDepositorRewards( | ||
c *ethclient.Client, | ||
privateKey *ecdsa.PrivateKey, | ||
poolAddress common.Address, | ||
) (*types.Transaction, error) { | ||
//coins, err := CheckBGT(c, privateKey, poolAddress) | ||
//if err != nil { | ||
// return nil, err | ||
//} | ||
//canClaimFunc := func(coin CosmosCoin) bool { | ||
// return coin.Amount.Cmp(MinRewardAmountToClaim) > 0 | ||
//} | ||
// | ||
//canClaim := false | ||
//for _, coin := range coins { | ||
// if canClaimFunc(coin) { | ||
// canClaim = true | ||
// } | ||
//} | ||
// | ||
//if !canClaim { | ||
// return nil, nil | ||
//} | ||
// | ||
claimRewardPayload, err := ParsedRewardModuleABI.Pack("withdrawAllDepositorRewards", poolAddress) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
log.Logger().Infow("Claim reward payload", "payload", hexutil.Encode(claimRewardPayload)) | ||
|
||
tx, err := eth.SendTx(c, privateKey, claimRewardPayload, nil, RewardModuleContract) | ||
if err != nil { | ||
log.Logger().Errorw("Claim reward failed", "err", err) | ||
return nil, err | ||
} | ||
|
||
log.Logger().Infow("Claim reward successfully", "txHash", tx.Hash().Hex()) | ||
return tx, nil | ||
} | ||
|
||
func CheckBGT( | ||
c *ethclient.Client, | ||
privateKey *ecdsa.PrivateKey, | ||
poolAddress common.Address, | ||
) ([]CosmosCoin, error) { | ||
var ( | ||
from, _ = eth.GetAddressFromPrivateKey(privateKey) | ||
) | ||
|
||
// function getCurrentRewards(address depositor, address receiver) external view returns (Cosmos.Coin[] memory); | ||
rewardModuleContract, err := NewRewardModuleCaller(RewardModuleContract, c) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
coins, err := rewardModuleContract.GetCurrentRewards(&bind.CallOpts{}, poolAddress, from) | ||
if err != nil { | ||
log.Logger().Errorw("Failed to get current rewards", "error", err) | ||
return nil, err | ||
} | ||
|
||
return coins, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package bex | ||
|
||
import ( | ||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/stretchr/testify/require" | ||
"testing" | ||
) | ||
|
||
func Test_ClaimBGT(t *testing.T) { | ||
poolAddress := common.HexToAddress("0xa88572F08f79D28b8f864350f122c1CC0AbB0d96") | ||
|
||
tx, err := WithdrawAllDepositorRewards( | ||
c, | ||
privateKey, | ||
poolAddress, | ||
) | ||
require.NoError(t, err) | ||
|
||
if tx == nil { | ||
t.Log("Tx is nil") | ||
return | ||
} | ||
t.Log("tx:", tx.Hash().Hex()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
abigen --abi=bex_abi.json --pkg=bex --out=bex_generated.go -type BexGenerated | ||
abigen --abi=bex_abi.json --pkg=bex --out=bex_generated.go -type BexGenerated | ||
abigen --abi=reward_module.json --pkg=bex --out=reward_module_generated.go -type RewardModule |
Oops, something went wrong.