Skip to content

Commit

Permalink
feat: add support for quote ID in bridgeCall
Browse files Browse the repository at this point in the history
  • Loading branch information
zakir-code committed Nov 1, 2024
1 parent 7ff705d commit fc560de
Show file tree
Hide file tree
Showing 39 changed files with 779 additions and 514 deletions.
574 changes: 287 additions & 287 deletions api/fx/gravity/crosschain/v1/tx.pulsar.go

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ func NewAppKeeper(
appKeepers.AccountKeeper,
appKeepers.EvmKeeper,
contract.NewBridgeFeeQuoteKeeper(appKeepers.EvmKeeper, contract.BridgeFeeAddress),
contract.NewERC20TokenKeeper(appKeepers.EvmKeeper),
authAddr,
)
appKeepers.PolygonKeeper = crosschainkeeper.NewKeeper(
Expand All @@ -419,6 +420,7 @@ func NewAppKeeper(
appKeepers.AccountKeeper,
appKeepers.EvmKeeper,
contract.NewBridgeFeeQuoteKeeper(appKeepers.EvmKeeper, contract.BridgeFeeAddress),
contract.NewERC20TokenKeeper(appKeepers.EvmKeeper),
authAddr,
)
appKeepers.AvalancheKeeper = crosschainkeeper.NewKeeper(
Expand All @@ -434,6 +436,7 @@ func NewAppKeeper(
appKeepers.AccountKeeper,
appKeepers.EvmKeeper,
contract.NewBridgeFeeQuoteKeeper(appKeepers.EvmKeeper, contract.BridgeFeeAddress),
contract.NewERC20TokenKeeper(appKeepers.EvmKeeper),
authAddr,
)
appKeepers.EthKeeper = crosschainkeeper.NewKeeper(
Expand All @@ -449,6 +452,7 @@ func NewAppKeeper(
appKeepers.AccountKeeper,
appKeepers.EvmKeeper,
contract.NewBridgeFeeQuoteKeeper(appKeepers.EvmKeeper, contract.BridgeFeeAddress),
contract.NewERC20TokenKeeper(appKeepers.EvmKeeper),
authAddr,
)
appKeepers.ArbitrumKeeper = crosschainkeeper.NewKeeper(
Expand All @@ -464,6 +468,7 @@ func NewAppKeeper(
appKeepers.AccountKeeper,
appKeepers.EvmKeeper,
contract.NewBridgeFeeQuoteKeeper(appKeepers.EvmKeeper, contract.BridgeFeeAddress),
contract.NewERC20TokenKeeper(appKeepers.EvmKeeper),
authAddr,
)
appKeepers.OptimismKeeper = crosschainkeeper.NewKeeper(
Expand All @@ -479,6 +484,7 @@ func NewAppKeeper(
appKeepers.AccountKeeper,
appKeepers.EvmKeeper,
contract.NewBridgeFeeQuoteKeeper(appKeepers.EvmKeeper, contract.BridgeFeeAddress),
contract.NewERC20TokenKeeper(appKeepers.EvmKeeper),
authAddr,
)
appKeepers.Layer2Keeper = crosschainkeeper.NewKeeper(
Expand All @@ -494,6 +500,7 @@ func NewAppKeeper(
appKeepers.AccountKeeper,
appKeepers.EvmKeeper,
contract.NewBridgeFeeQuoteKeeper(appKeepers.EvmKeeper, contract.BridgeFeeAddress),
contract.NewERC20TokenKeeper(appKeepers.EvmKeeper),
authAddr,
)
appKeepers.TronKeeper = crosschainkeeper.NewKeeper(
Expand All @@ -509,6 +516,7 @@ func NewAppKeeper(
appKeepers.AccountKeeper,
appKeepers.EvmKeeper,
contract.NewBridgeFeeQuoteKeeper(appKeepers.EvmKeeper, contract.BridgeFeeAddress),
contract.NewERC20TokenKeeper(appKeepers.EvmKeeper),
authAddr,
)

Expand Down
8 changes: 4 additions & 4 deletions contract/crosschain.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,23 @@ type BridgeCallArgs struct {
Amounts []*big.Int `abi:"_amounts"`
To common.Address `abi:"_to"`
Data []byte `abi:"_data"`
Value *big.Int `abi:"_value"`
QuoteId *big.Int `abi:"_quoteId"`
Memo []byte `abi:"_memo"`
}

func (args *BridgeCallArgs) Validate() error {
if args.DstChain == "" {
return errors.New("empty chain")
}
if args.Value.Sign() != 0 {
return errors.New("value must be zero")
}
if len(args.Tokens) != len(args.Amounts) {
return errors.New("tokens and amounts do not match")
}
if len(args.Amounts) > 0 && IsZeroEthAddress(args.Refund) {
return errors.New("refund cannot be empty")
}
if args.QuoteId.Sign() < 0 {
return errors.New("quoteId cannot be negative")
}
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion contract/crosschain_precompile.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (k CrosschainPrecompileKeeper) IsOracleOnline(ctx context.Context, args IsO

func (k CrosschainPrecompileKeeper) BridgeCall(ctx context.Context, from common.Address, args BridgeCallArgs) (*evmtypes.MsgEthereumTxResponse, *big.Int, error) {
res, err := k.ApplyContract(ctx, from, k.contractAddr, nil, k.abi, "bridgeCall",
args.DstChain, args.Refund, args.Tokens, args.Amounts, args.To, args.Data, args.Value, args.Memo)
args.DstChain, args.Refund, args.Tokens, args.Amounts, args.To, args.Data, args.QuoteId, args.Memo)
if err != nil {
return nil, nil, err
}
Expand Down
34 changes: 17 additions & 17 deletions contract/icrosschain.sol.go

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions contract/ifx_bridge_logic.sol.go

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions contract/quote.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package contract

import (
"math/big"
"time"
)

func (i IBridgeFeeQuoteQuoteInfo) IsTimeout(blockTime time.Time) bool {
return new(big.Int).Sub(i.Expiry, big.NewInt(int64(blockTime.Second()))).Sign() <= 0
}
2 changes: 1 addition & 1 deletion docs/statik/statik.go

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions docs/swagger-ui/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2023,6 +2023,10 @@ paths:
EIP155

signed) transactions can be executed on the state machine.
header_hash_num:
type: string
format: uint64
description: header_hash_num is the number of header hash to persist.
title: Params defines the EVM module parameters
description: >-
QueryParamsResponse defines the response type for querying x/evm
Expand Down Expand Up @@ -40880,6 +40884,10 @@ definitions:
description: |-
allow_unprotected_txs defines if replay-protected (i.e non EIP155
signed) transactions can be executed on the state machine.
header_hash_num:
type: string
format: uint64
description: header_hash_num is the number of header hash to persist.
title: Params defines the EVM module parameters
ethermint.evm.v1.QueryAccountResponse:
type: object
Expand Down Expand Up @@ -41076,6 +41084,10 @@ definitions:
description: |-
allow_unprotected_txs defines if replay-protected (i.e non EIP155
signed) transactions can be executed on the state machine.
header_hash_num:
type: string
format: uint64
description: header_hash_num is the number of header hash to persist.
title: Params defines the EVM module parameters
description: >-
QueryParamsResponse defines the response type for querying x/evm
Expand Down
2 changes: 1 addition & 1 deletion proto/fx/gravity/crosschain/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ message MsgBridgeCallClaim {
];
string to = 9;
string data = 10;
string value = 11 [
string quote_id = 11 [
(cosmos_proto.scalar) = "cosmos.Int",
(gogoproto.customtype) = "cosmossdk.io/math.Int",
(gogoproto.nullable) = false
Expand Down
6 changes: 3 additions & 3 deletions solidity/contracts/bridge/FxBridgeLogic.sol
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ contract FxBridgeLogic is
uint256[] memory _amounts,
address _to,
bytes memory _data,
uint256 _value,
uint256 _quoteId,
bytes memory _memo
) external nonReentrant whenNotPaused returns (uint256) {
require(bytes(_dstChain).length == 0, "Invalid dstChain");
Expand All @@ -316,12 +316,12 @@ contract FxBridgeLogic is
_to,
// solhint-disable-next-line avoid-tx-origin
tx.origin,
_value,
state_lastEventNonce,
_dstChain,
_tokens,
_amounts,
_data,
_quoteId,
_memo
);

Expand Down Expand Up @@ -815,12 +815,12 @@ contract FxBridgeLogic is
address indexed _refund,
address indexed _to,
address _txOrigin,
uint256 _value,
uint256 _eventNonce,
string _dstChain,
address[] _tokens,
uint256[] _amounts,
bytes _data,
uint256 _quoteId,
bytes _memo
);

Expand Down
6 changes: 3 additions & 3 deletions solidity/contracts/bridge/FxBridgeLogicETH.sol
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ contract FxBridgeLogicETH is
uint256[] memory _amounts,
address _to,
bytes memory _data,
uint256 _value,
uint256 _quoteId,
bytes memory _memo
) external nonReentrant whenNotPaused returns (uint256) {
require(bytes(_dstChain).length == 0, "Invalid dstChain");
Expand All @@ -352,12 +352,12 @@ contract FxBridgeLogicETH is
_to,
// solhint-disable-next-line avoid-tx-origin
tx.origin,
_value,
state_lastEventNonce,
_dstChain,
_tokens,
_amounts,
_data,
_quoteId,
_memo
);

Expand Down Expand Up @@ -855,12 +855,12 @@ contract FxBridgeLogicETH is
address indexed _refund,
address indexed _to,
address _txOrigin,
uint256 _value,
uint256 _eventNonce,
string _dstChain,
address[] _tokens,
uint256[] _amounts,
bytes _data,
uint256 _quoteId,
bytes _memo
);

Expand Down
2 changes: 1 addition & 1 deletion solidity/contracts/bridge/IBridgeCall.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ interface IBridgeCall {
uint256[] memory _amounts,
address _to,
bytes memory _data,
uint256 _value,
uint256 _quoteId,
bytes memory _memo
) external payable returns (uint256 _eventNonce);
}
2 changes: 1 addition & 1 deletion solidity/contracts/bridge/ICrosschain.sol
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ interface ICrosschain is IBridgeCall {
address indexed _receiver,
address indexed _to,
address _txOrigin,
uint256 _value,
uint256 _eventNonce,
string _dstChain,
address[] _tokens,
uint256[] _amounts,
bytes _data,
uint256 _quoteId,
bytes _memo
);

Expand Down
4 changes: 2 additions & 2 deletions solidity/contracts/test/CrosschainTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ contract CrosschainTest {
uint256[] memory _amounts,
address _to,
bytes memory _data,
uint256 _value,
uint256 _quoteId,
bytes memory _memo
) internal returns (uint256) {
return
Expand All @@ -86,7 +86,7 @@ contract CrosschainTest {
_amounts,
_to,
_data,
_value,
_quoteId,
_memo
);
}
Expand Down
18 changes: 9 additions & 9 deletions solidity/test/bridge_call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ describe("bridge call tests", function () {
const tokens = [await erc20Token.getAddress()];
const amount = ethers.parseEther("1");
const amounts: BigNumberish[] = [amount];
const value = ethers.parseEther("9");
const quoteId = 1;
const lastEventNonce = await fxBridge.state_lastEventNonce();

await erc20Token.approve(await fxBridge.getAddress(), amount);
Expand All @@ -124,7 +124,7 @@ describe("bridge call tests", function () {
amounts,
user1.address,
"0x",
value,
quoteId,
"0x"
)
)
Expand All @@ -134,12 +134,12 @@ describe("bridge call tests", function () {
user1.address,
user1.address,
deploy.address,
value,
BigInt(Number(lastEventNonce) + 1),
fxcoreChainId,
tokens,
amounts,
"0x",
quoteId,
"0x"
);
});
Expand All @@ -148,7 +148,7 @@ describe("bridge call tests", function () {
const tokens = [await erc20Token.getAddress()];
const amount = ethers.parseEther("1");
const amounts: BigNumberish[] = [amount];
const value = ethers.parseEther("9");
const quoteId = 1;
const lastEventNonce = await fxBridge.state_lastEventNonce();
const data = encodeFunctionData(
erc20Token.interface.formatJson(),
Expand All @@ -165,7 +165,7 @@ describe("bridge call tests", function () {
amounts,
user1.address,
data,
value,
quoteId,
"0x"
)
)
Expand All @@ -175,12 +175,12 @@ describe("bridge call tests", function () {
user1.address,
user1.address,
deploy.address,
value,
BigInt(Number(lastEventNonce) + 1),
fxcoreChainId,
tokens,
amounts,
data,
quoteId,
"0x"
);
});
Expand All @@ -189,7 +189,7 @@ describe("bridge call tests", function () {
const tokens = [await erc20Token.getAddress()];
const amount = ethers.parseEther("1");
const amounts: BigNumberish[] = [amount];
const value = ethers.parseEther("9");
const quoteId = 1;
const lastEventNonce = await fxBridge.state_lastEventNonce();
const data = encodeFunctionData(
erc20Token.interface.formatJson(),
Expand All @@ -212,7 +212,7 @@ describe("bridge call tests", function () {
amounts,
user1.address,
data,
value,
quoteId,
demo
)
)
Expand All @@ -222,12 +222,12 @@ describe("bridge call tests", function () {
user1.address,
user1.address,
deploy.address,
value,
BigInt(Number(lastEventNonce) + 1),
fxcoreChainId,
tokens,
amounts,
data,
quoteId,
demo
);
});
Expand Down
Loading

0 comments on commit fc560de

Please sign in to comment.