-
Notifications
You must be signed in to change notification settings - Fork 105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: msg update withdraw fee #929
Merged
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
9badf51
make smoketest work
brewmaster012 4f859a1
Merge branch 'develop' into omnichain-remote-call-context
brewmaster012 e642a74
smoketest: add test for context in depositAndCall
2356487
add missing files
cd8c227
add Update System Contract Address msg
6005d7f
merge develop
93cdda3
fix linter complaints
44681fb
Merge branch 'develop' into omnichain-remote-call-context
brewmaster012 950baa5
fix openapi
742a42e
Merge branch 'develop' into omnichain-remote-call-context
brewmaster012 f4ce00f
fix gosec complaint and CI config
6cfd37c
fix linter config
e22c783
fix generated file check fail
e149519
try fix CI config
9cc3656
address PR comments
25c821b
add typed events
aefeffe
migrate one more event to typed event
dc51c33
cleanup fixme
34c91f3
update protocol-contract package to latest main branch
40f0c87
Merge branch 'develop' into omnichain-remote-call-context
brewmaster012 d5a93e3
Update x/fungible/keeper/evm.go
brewmaster012 0a843ca
PR comments address: error types
526973d
merge develop
1b1c663
re-generate go.sum
d192464
add msg & handler for MsgUpdateZRC20WithdrawFee
brewmaster012 f901421
add smoketest for this
brewmaster012 3dceaac
merge develop
34d2184
rename protobuf field
d666914
add missing file
37f7ab1
fix linter complaints
98a8e31
Merge branch 'develop' into msg-update-withdraw-fee
brewmaster012 54d32c9
Merge branch 'develop' into msg-update-withdraw-fee
lumtis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
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
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,84 @@ | ||
package keeper | ||
|
||
import ( | ||
"context" | ||
"math/big" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
ethcommon "github.com/ethereum/go-ethereum/common" | ||
"github.com/zeta-chain/protocol-contracts/pkg/contracts/zevm/zrc20.sol" | ||
"github.com/zeta-chain/zetacore/x/fungible/types" | ||
zetaObserverTypes "github.com/zeta-chain/zetacore/x/observer/types" | ||
) | ||
|
||
func (k Keeper) UpdateZRC20WithdrawFee(goCtx context.Context, msg *types.MsgUpdateZRC20WithdrawFee) (*types.MsgUpdateZRC20WithdrawFeeResponse, error) { | ||
ctx := sdk.UnwrapSDKContext(goCtx) | ||
if msg.Creator != k.zetaobserverKeeper.GetParams(ctx).GetAdminPolicyAccount(zetaObserverTypes.Policy_Type_deploy_fungible_coin) { | ||
return nil, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "Deploy can only be executed by the correct policy account") | ||
} | ||
zrc20Addr := ethcommon.HexToAddress(msg.Zrc20Address) | ||
if zrc20Addr == (ethcommon.Address{}) { | ||
return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid zrc20 contract address (%s)", msg.Zrc20Address) | ||
} | ||
|
||
// update contracts | ||
zrc20ABI, err := zrc20.ZRC20MetaData.GetAbi() | ||
if err != nil { | ||
return nil, sdkerrors.Wrapf(types.ErrABIGet, "failed to get zrc20 abi") | ||
} | ||
|
||
foreignCoins := k.GetAllForeignCoins(ctx) | ||
found := false | ||
var coin types.ForeignCoins | ||
for _, fcoin := range foreignCoins { | ||
coinZRC20Addr := ethcommon.HexToAddress(fcoin.Zrc20ContractAddress) | ||
if coinZRC20Addr == (ethcommon.Address{}) { | ||
k.Logger(ctx).Error("invalid zrc20 contract address", "address", fcoin.Zrc20ContractAddress) | ||
continue | ||
} | ||
if coinZRC20Addr == zrc20Addr { | ||
coin = fcoin | ||
found = true | ||
break | ||
} | ||
} | ||
|
||
if !found { | ||
return nil, sdkerrors.Wrapf(types.ErrInvalidAddress, "no foreign coin match requested zrc20 address (%s)", msg.Zrc20Address) | ||
} | ||
|
||
res, err := k.CallEVM(ctx, *zrc20ABI, types.ModuleAddressEVM, zrc20Addr, BigIntZero, nil, false, "PROTOCOL_FLAT_FEE") | ||
if err != nil { | ||
return nil, sdkerrors.Wrapf(types.ErrContractCall, "failed to call zrc20 contract PROTOCOL_FLAT_FEE method (%s)", err.Error()) | ||
} | ||
unpacked, err := zrc20ABI.Unpack("PROTOCOL_FLAT_FEE", res.Ret) | ||
if err != nil || len(unpacked) == 0 { | ||
return nil, sdkerrors.Wrapf(types.ErrContractCall, "failed to unpack zrc20 contract PROTOCOL_FLAT_FEE method (%s)", err.Error()) | ||
} | ||
oldWithdrawFee, ok := unpacked[0].(*big.Int) | ||
if !ok { | ||
return nil, sdkerrors.Wrapf(types.ErrContractCall, "failed to interpret the returned unpacked zrc20 contract PROTOCOL_FLAT_FEE method; ret %x", res.Ret) | ||
} | ||
|
||
tmpCtx, commit := ctx.CacheContext() | ||
_, err = k.CallEVM(tmpCtx, *zrc20ABI, types.ModuleAddressEVM, zrc20Addr, BigIntZero, nil, true, "updateProtocolFlatFee", msg.NewWithdrawFee.BigInt()) | ||
lumtis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
err = ctx.EventManager().EmitTypedEvent( | ||
&types.EventZRC20WithdrawFeeUpdated{ | ||
MsgTypeUrl: sdk.MsgTypeURL(&types.MsgUpdateZRC20WithdrawFee{}), | ||
ChainId: coin.ForeignChainId, | ||
CoinType: coin.CoinType, | ||
Zrc20Address: zrc20Addr.Hex(), | ||
OldWithdrawFee: oldWithdrawFee.String(), | ||
NewWithdrawFee: msg.NewWithdrawFee.BigInt().String(), | ||
Signer: msg.Creator, | ||
}, | ||
) | ||
if err != nil { | ||
k.Logger(ctx).Error("failed to emit event", "error", err.Error()) | ||
return nil, sdkerrors.Wrapf(types.ErrEmitEvent, "failed to emit event (%s)", err.Error()) | ||
} | ||
commit() | ||
return &types.MsgUpdateZRC20WithdrawFeeResponse{}, 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If commit after successfully emitting event is more correct, I‘m wondering if we have other places doing the same early commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
go hunt them down!