Skip to content

Commit

Permalink
feat: add liquidity cap parameter to ZRC20 creation (#3353)
Browse files Browse the repository at this point in the history
* add liquidity cap to message

* update messages and tests

* fix e2e tests

* changelog

* fix tests

* feat: allow nil liquidity cap (#3387)

* feat: allow nil liquidity cap

* restore inner nil check

* remove cli docs

* format

---------

Co-authored-by: Alex Gartner <[email protected]>
  • Loading branch information
lumtis and gartnera authored Jan 23, 2025
1 parent 9fc89e0 commit ac3b447
Show file tree
Hide file tree
Showing 33 changed files with 548 additions and 220 deletions.
6 changes: 5 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# CHANGELOG

## unreleased
## Unreleased

### Features

* [3353](https://github.com/zeta-chain/node/pull/3353) - add liquidity cap parameter to ZRC20 creation

### Refactor

Expand Down
1 change: 1 addition & 0 deletions docs/spec/crosschain/messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ message MsgWhitelistERC20 {
string symbol = 5;
uint32 decimals = 6;
int64 gas_limit = 7;
string liquidity_cap = 8;
}
```

Expand Down
1 change: 1 addition & 0 deletions docs/spec/fungible/messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ message MsgDeployFungibleCoinZRC20 {
string symbol = 6;
pkg.coin.CoinType coin_type = 7;
int64 gas_limit = 8;
string liquidity_cap = 9;
}
```

Expand Down
3 changes: 3 additions & 0 deletions e2e/e2etests/test_migrate_chain_support.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os/exec"
"time"

sdkmath "cosmossdk.io/math"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
ethcommon "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
Expand Down Expand Up @@ -79,6 +80,7 @@ func TestMigrateChainSupport(r *runner.E2ERunner, _ []string) {
"sETH",
coin.CoinType_Gas,
100000,
nil,
),
)
require.NoError(r, err)
Expand Down Expand Up @@ -165,6 +167,7 @@ func TestMigrateChainSupport(r *runner.E2ERunner, _ []string) {
"USDT",
18,
100000,
sdkmath.NewUintFromString("100000000000000000000000000"),
))
require.NoError(r, err)

Expand Down
2 changes: 2 additions & 0 deletions e2e/e2etests/test_solana_whitelist_spl.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package e2etests

import (
sdkmath "cosmossdk.io/math"
"github.com/gagliardetto/solana-go"
"github.com/gagliardetto/solana-go/rpc"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -45,6 +46,7 @@ func TestSolanaWhitelistSPL(r *runner.E2ERunner, _ []string) {
"TESTSPL",
6,
100000,
sdkmath.NewUintFromString("100000000000000000000000000"),
))
require.NoError(r, err)

Expand Down
2 changes: 2 additions & 0 deletions e2e/e2etests/test_whitelist_erc20.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package e2etests
import (
"math/big"

sdkmath "cosmossdk.io/math"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
ethcommon "github.com/ethereum/go-ethereum/common"
ethtypes "github.com/ethereum/go-ethereum/core/types"
Expand Down Expand Up @@ -40,6 +41,7 @@ func TestWhitelistERC20(r *runner.E2ERunner, _ []string) {
"NEWERC20",
6,
100000,
sdkmath.NewUintFromString("100000000000000000000000000"),
))
require.NoError(r, err)

Expand Down
6 changes: 6 additions & 0 deletions e2e/txserver/zeta_tx_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ func (zts ZetaTxServer) DeployZRC20s(
"gETH",
coin.CoinType_Gas,
100000,
nil,
),
fungibletypes.NewMsgDeployFungibleCoinZRC20(
deployerAddr,
Expand All @@ -453,6 +454,7 @@ func (zts ZetaTxServer) DeployZRC20s(
"tBTC",
coin.CoinType_Gas,
100000,
nil,
),
fungibletypes.NewMsgDeployFungibleCoinZRC20(
deployerAddr,
Expand All @@ -463,6 +465,7 @@ func (zts ZetaTxServer) DeployZRC20s(
"SOL",
coin.CoinType_Gas,
100000,
nil,
),
fungibletypes.NewMsgDeployFungibleCoinZRC20(
deployerAddr,
Expand All @@ -473,6 +476,7 @@ func (zts ZetaTxServer) DeployZRC20s(
"TON",
coin.CoinType_Gas,
100_000,
nil,
),
fungibletypes.NewMsgDeployFungibleCoinZRC20(
deployerAddr,
Expand All @@ -483,6 +487,7 @@ func (zts ZetaTxServer) DeployZRC20s(
"USDT",
coin.CoinType_ERC20,
100000,
nil,
),
}

Expand All @@ -496,6 +501,7 @@ func (zts ZetaTxServer) DeployZRC20s(
"USDT",
coin.CoinType_ERC20,
100000,
nil,
))
}

Expand Down
4 changes: 4 additions & 0 deletions precompiles/bank/method_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"math/big"
"testing"

sdkmath "cosmossdk.io/math"

storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/accounts/abi"
Expand All @@ -17,6 +19,7 @@ import (
"github.com/zeta-chain/ethermint/x/evm/statedb"
"github.com/zeta-chain/node/pkg/chains"
"github.com/zeta-chain/node/pkg/contracts/erc1967proxy"
"github.com/zeta-chain/node/pkg/ptr"
precompiletypes "github.com/zeta-chain/node/precompiles/types"
"github.com/zeta-chain/node/testutil/keeper"
"github.com/zeta-chain/node/testutil/sample"
Expand Down Expand Up @@ -634,6 +637,7 @@ func setupGasCoin(
symbol,
8,
nil,
ptr.Ptr(sdkmath.NewUintFromString("100000000000000000000000000")),
)
require.NoError(t, err)
assertContractDeployment(t, *evmk, ctx, addr)
Expand Down
2 changes: 2 additions & 0 deletions precompiles/staking/staking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/zeta-chain/node/cmd/zetacored/config"
"github.com/zeta-chain/node/pkg/chains"
"github.com/zeta-chain/node/pkg/contracts/erc1967proxy"
"github.com/zeta-chain/node/pkg/ptr"
"github.com/zeta-chain/node/precompiles/prototype"
"github.com/zeta-chain/node/testutil/keeper"
"github.com/zeta-chain/node/testutil/sample"
Expand Down Expand Up @@ -508,6 +509,7 @@ func setupGasCoin(
symbol,
8,
nil,
ptr.Ptr(math.NewUintFromString("100000000000000000000000000")),
)
require.NoError(t, err)
assertContractDeployment(t, *evmk, ctx, addr)
Expand Down
4 changes: 4 additions & 0 deletions proto/zetachain/zetacore/crosschain/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ message MsgWhitelistERC20 {
string symbol = 5;
uint32 decimals = 6;
int64 gas_limit = 7;
string liquidity_cap = 8 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Uint",
(gogoproto.nullable) = false
];
}

message MsgWhitelistERC20Response {
Expand Down
2 changes: 2 additions & 0 deletions proto/zetachain/zetacore/fungible/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ message MsgDeployFungibleCoinZRC20 {
string symbol = 6;
pkg.coin.CoinType coin_type = 7;
int64 gas_limit = 8;
string liquidity_cap = 9
[ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Uint" ];
}

message MsgDeployFungibleCoinZRC20Response { string address = 1; }
Expand Down
20 changes: 11 additions & 9 deletions testutil/keeper/mocks/crosschain/fungible.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions typescript/zetachain/zetacore/crosschain/tx_pb.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,11 @@ export declare class MsgWhitelistERC20 extends Message<MsgWhitelistERC20> {
*/
gasLimit: bigint;

/**
* @generated from field: string liquidity_cap = 8;
*/
liquidityCap: string;

constructor(data?: PartialMessage<MsgWhitelistERC20>);

static readonly runtime: typeof proto3;
Expand Down
5 changes: 5 additions & 0 deletions typescript/zetachain/zetacore/fungible/tx_pb.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,11 @@ export declare class MsgDeployFungibleCoinZRC20 extends Message<MsgDeployFungibl
*/
gasLimit: bigint;

/**
* @generated from field: string liquidity_cap = 9;
*/
liquidityCap: string;

constructor(data?: PartialMessage<MsgDeployFungibleCoinZRC20>);

static readonly runtime: typeof proto3;
Expand Down
8 changes: 6 additions & 2 deletions x/crosschain/client/cli/cli_whitelist_erc20.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"strconv"

sdkmath "cosmossdk.io/math"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"
Expand All @@ -14,9 +15,9 @@ import (

func CmdWhitelistERC20() *cobra.Command {
cmd := &cobra.Command{
Use: "whitelist-erc20 [erc20Address] [chainID] [name] [symbol] [decimals] [gasLimit]",
Use: "whitelist-erc20 [erc20Address] [chainID] [name] [symbol] [decimals] [gasLimit] [liquidityCap]",
Short: "Add a new erc20 token to whitelist",
Args: cobra.ExactArgs(6),
Args: cobra.ExactArgs(7),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
Expand Down Expand Up @@ -44,6 +45,8 @@ func CmdWhitelistERC20() *cobra.Command {
return err
}

liquidityCap := sdkmath.NewUintFromString(args[6])

msg := types.NewMsgWhitelistERC20(
clientCtx.GetFromAddress().String(),
erc20Address,
Expand All @@ -53,6 +56,7 @@ func CmdWhitelistERC20() *cobra.Command {
// #nosec G115 always in range
uint32(decimals),
gasLimit,
liquidityCap,
)

return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
Expand Down
5 changes: 4 additions & 1 deletion x/crosschain/keeper/msg_server_whitelist_erc20.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/gagliardetto/solana-go"

"github.com/zeta-chain/node/pkg/coin"
"github.com/zeta-chain/node/pkg/ptr"
authoritytypes "github.com/zeta-chain/node/x/authority/types"
"github.com/zeta-chain/node/x/crosschain/types"
fungibletypes "github.com/zeta-chain/node/x/fungible/types"
Expand Down Expand Up @@ -98,6 +99,7 @@ func (k msgServer) WhitelistERC20(
coin.CoinType_ERC20,
msg.Erc20Address,
big.NewInt(msg.GasLimit),
ptr.Ptr(msg.LiquidityCap),
)
if err != nil {
return nil, errorsmod.Wrapf(
Expand Down Expand Up @@ -172,7 +174,8 @@ func (k msgServer) WhitelistERC20(
Symbol: msg.Symbol,
CoinType: coin.CoinType_ERC20,
// #nosec G115 always positive
GasLimit: uint64(msg.GasLimit),
GasLimit: uint64(msg.GasLimit),
LiquidityCap: msg.LiquidityCap,
}
k.fungibleKeeper.SetForeignCoins(ctx, foreignCoin)
k.SaveCCTXUpdate(ctx, cctx, tss.TssPubkey)
Expand Down
Loading

0 comments on commit ac3b447

Please sign in to comment.