Skip to content
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

fix: refine function handling in 807 #808

Merged
merged 1 commit into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ func (app *App) InitChainer(ctx sdk.Context, req *abci.RequestInitChain) (*abci.
}

bridgeFeeQuoteKeeper := contract.NewBridgeFeeQuoteKeeper(app.EvmKeeper, contract.BridgeFeeAddress)
bridgeFeeOracleKeeper := contract.NewBrideFeeOracleKeeper(app.EvmKeeper, contract.BridgeFeeOracleAddress)
bridgeFeeOracleKeeper := contract.NewBridgeFeeOracleKeeper(app.EvmKeeper, contract.BridgeFeeOracleAddress)

acc := app.AccountKeeper.GetModuleAddress(evmtypes.ModuleName)
moduleAddress := common.BytesToAddress(acc.Bytes())
Expand All @@ -361,15 +361,18 @@ func (app *App) InitChainer(ctx sdk.Context, req *abci.RequestInitChain) (*abci.
if len(delegations) == 0 {
return nil, errors.New("no delegations found")
}

bridgeDenoms := []contract.BridgeDenoms{
{
ChainName: ethtypes.ModuleName,
Denoms: []string{fxtypes.DefaultDenom},
},
}
if err = contract.DeployBridgeFeeContract(
ctx,
app.EvmKeeper,
bridgeFeeQuoteKeeper,
bridgeFeeOracleKeeper,
map[string][]string{
ethtypes.ModuleName: {fxtypes.DefaultDenom},
},
bridgeDenoms,
moduleAddress, moduleAddress,
common.BytesToAddress(sdk.MustAccAddressFromBech32(delegations[0].DelegatorAddress).Bytes()),
); err != nil {
Expand Down
15 changes: 9 additions & 6 deletions app/upgrades/v8/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,22 @@ func CreateUpgradeHandler(cdc codec.Codec, mm *module.Manager, configurator modu
store.RemoveStoreKeys(cacheCtx, app.GetKey(erc20types.StoreKey), erc20v8.GetRemovedStoreKeys())

quoteKeeper := contract.NewBridgeFeeQuoteKeeper(app.EvmKeeper, contract.BridgeFeeAddress)
oracleKeeper := contract.NewBrideFeeOracleKeeper(app.EvmKeeper, contract.BridgeFeeOracleAddress)
bridgeDenomWithChain := make(map[string][]string)
oracleKeeper := contract.NewBridgeFeeOracleKeeper(app.EvmKeeper, contract.BridgeFeeOracleAddress)
chains := crosschaintypes.GetSupportChains()
for _, chain := range chains {
bridgeDenoms := make([]contract.BridgeDenoms, len(chains))
for index, chain := range chains {
denoms := make([]string, 0)
bridgeTokens, err := app.Erc20Keeper.GetBridgeTokens(ctx, chain)
bridgeTokens, err := app.Erc20Keeper.GetBridgeTokens(cacheCtx, chain)
if err != nil {
return fromVM, err
}
for _, token := range bridgeTokens {
denoms = append(denoms, token.GetDenom())
}
bridgeDenomWithChain[chain] = denoms
bridgeDenoms[index] = contract.BridgeDenoms{
ChainName: chain,
Denoms: denoms,
}
}
acc := app.AccountKeeper.GetModuleAddress(evmtypes.ModuleName)
moduleAddress := common.BytesToAddress(acc.Bytes())
Expand All @@ -103,7 +106,7 @@ func CreateUpgradeHandler(cdc codec.Codec, mm *module.Manager, configurator modu
app.EvmKeeper,
quoteKeeper,
oracleKeeper,
bridgeDenomWithChain,
bridgeDenoms,
moduleAddress,
// TODO set bridge fee contract owner address before mainnet upgrade
moduleAddress,
Expand Down
10 changes: 5 additions & 5 deletions contract/bridge_fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func DeployBridgeFeeContract(
evmKeeper EvmKeeper,
bridgeFeeQuoteKeeper BridgeFeeQuoteKeeper,
bridgeFeeOracleKeeper BridgeFeeOracleKeeper,
bridgeDenomWithChain map[string][]string,
bridgeDenoms []BridgeDenoms,
evmModuleAddress, owner, defaultOracleAddress common.Address,
) error {
if err := deployBridgeProxy(
Expand All @@ -40,7 +40,7 @@ func DeployBridgeFeeContract(
if err := initBridgeFeeOracle(ctx, bridgeFeeOracleKeeper, owner, defaultOracleAddress); err != nil {
return err
}
return initBridgeFeeQuote(ctx, bridgeFeeQuoteKeeper, bridgeDenomWithChain, owner)
return initBridgeFeeQuote(ctx, bridgeFeeQuoteKeeper, bridgeDenoms, owner)
}

func deployBridgeProxy(
Expand Down Expand Up @@ -101,7 +101,7 @@ func initBridgeFeeOracle(
func initBridgeFeeQuote(
ctx sdk.Context,
bridgeFeeQuoteKeeper BridgeFeeQuoteKeeper,
bridgeDenomWithChain map[string][]string,
bridgeDenoms []BridgeDenoms,
owner common.Address,
) error {
if _, err := bridgeFeeQuoteKeeper.Initialize(ctx, common.HexToAddress(BridgeFeeOracleAddress), big.NewInt(DefaultMaxQuoteIndex)); err != nil {
Expand All @@ -121,8 +121,8 @@ func initBridgeFeeQuote(
if _, err = bridgeFeeQuoteKeeper.GrantRole(ctx, upgradeRole, owner); err != nil {
return err
}
for chainName, denoms := range bridgeDenomWithChain {
if _, err = bridgeFeeQuoteKeeper.RegisterChain(ctx, chainName, denoms...); err != nil {
for _, bridgeDenom := range bridgeDenoms {
if _, err = bridgeFeeQuoteKeeper.RegisterChain(ctx, bridgeDenom.ChainName, bridgeDenom.Denoms...); err != nil {
return err
}
}
Expand Down
2 changes: 1 addition & 1 deletion contract/bridge_fee_oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type BridgeFeeOracleKeeper struct {
contract common.Address
}

func NewBrideFeeOracleKeeper(caller Caller, contract string) BridgeFeeOracleKeeper {
func NewBridgeFeeOracleKeeper(caller Caller, contract string) BridgeFeeOracleKeeper {
return BridgeFeeOracleKeeper{
Caller: caller,
abi: GetBridgeFeeOracle().ABI,
Expand Down
2 changes: 1 addition & 1 deletion contract/bridge_fee_oracle.sol.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion contract/bridge_fee_quote.sol.go

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions contract/types.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
package contract

const DefaultMaxQuoteIndex = 3

type BridgeDenoms struct {
ChainName string
Denoms []string
}
8 changes: 4 additions & 4 deletions solidity/contracts/bridge/BridgeFeeOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ contract BridgeFeeOracle is
function initialize(address _crosschain) public initializer {
crosschainContract = _crosschain;

_grantRole(DEFAULT_ADMIN_ROLE, msg.sender);
_grantRole(UPGRADE_ROLE, msg.sender);
_grantRole(OWNER_ROLE, msg.sender);

__AccessControl_init();
__UUPSUpgradeable_init();
__ReentrancyGuard_init();

_grantRole(DEFAULT_ADMIN_ROLE, msg.sender);
_grantRole(UPGRADE_ROLE, msg.sender);
_grantRole(OWNER_ROLE, msg.sender);
}

/**
Expand Down
11 changes: 7 additions & 4 deletions solidity/contracts/bridge/BridgeFeeQuote.sol
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ contract BridgeFeeQuote is
oracleContract = _oracleContract;
maxQuoteIndex = _maxQuoteIndex;

_grantRole(DEFAULT_ADMIN_ROLE, msg.sender);
_grantRole(UPGRADE_ROLE, msg.sender);
_grantRole(OWNER_ROLE, msg.sender);

__AccessControl_init();
__UUPSUpgradeable_init();
__ReentrancyGuard_init();

_grantRole(DEFAULT_ADMIN_ROLE, msg.sender);
_grantRole(UPGRADE_ROLE, msg.sender);
_grantRole(OWNER_ROLE, msg.sender);
}

event NewQuote(
Expand Down Expand Up @@ -415,6 +415,9 @@ contract BridgeFeeQuote is
if (assets[_chainName].isActive) {
revert ChainNameAlreadyExists();
}
if (_chainName.equal("")) {
revert ChainNameInvalid();
}
assets[_chainName] = Asset({isActive: true, tokenNames: _tokenNames});
chainNames.push(_chainName);
return true;
Expand Down
Loading