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

feat: add liquidity cap parameter to ZRC20 creation #3353

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
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
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
4 changes: 2 additions & 2 deletions docs/cli/zetacored/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -9543,7 +9543,7 @@ zetacored tx crosschain vote-outbound [sendHash] [outboundHash] [outBlockHeight]
Add a new erc20 token to whitelist

```
zetacored tx crosschain whitelist-erc20 [erc20Address] [chainID] [name] [symbol] [decimals] [gasLimit] [flags]
zetacored tx crosschain whitelist-erc20 [erc20Address] [chainID] [name] [symbol] [decimals] [gasLimit] [liquidityCap] [flags]
lumtis marked this conversation as resolved.
Show resolved Hide resolved
```

### Options
Expand Down Expand Up @@ -10219,7 +10219,7 @@ zetacored tx fungible [flags]
Broadcast message DeployFungibleCoinZRC20

```
zetacored tx fungible deploy-fungible-coin-zrc-4 [erc-20] [foreign-chain] [decimals] [name] [symbol] [coin-type] [gas-limit] [flags]
zetacored tx fungible deploy-fungible-coin-zrc-4 [erc-20] [foreign-chain] [decimals] [name] [symbol] [coin-type] [gas-limit] [liquidity-cap] [flags]
lumtis marked this conversation as resolved.
Show resolved Hide resolved
```

### Options
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,
sdkmath.NewUintFromString("100000000000000000000000000"),
),
)
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/stretchr/testify/require"

Expand Down Expand Up @@ -40,6 +41,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
9 changes: 9 additions & 0 deletions e2e/txserver/zeta_tx_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,9 @@ func (zts ZetaTxServer) DeployZRC20s(
deployerAddr = addrOperational.String()
}

// 100M * 10^18
liquidityCap := sdkmath.NewUintFromString("100000000000000000000000000")

deployMsgs := []*fungibletypes.MsgDeployFungibleCoinZRC20{
fungibletypes.NewMsgDeployFungibleCoinZRC20(
deployerAddr,
Expand All @@ -443,6 +446,7 @@ func (zts ZetaTxServer) DeployZRC20s(
"gETH",
coin.CoinType_Gas,
100000,
liquidityCap,
),
fungibletypes.NewMsgDeployFungibleCoinZRC20(
deployerAddr,
Expand All @@ -453,6 +457,7 @@ func (zts ZetaTxServer) DeployZRC20s(
"tBTC",
coin.CoinType_Gas,
100000,
liquidityCap,
),
fungibletypes.NewMsgDeployFungibleCoinZRC20(
deployerAddr,
Expand All @@ -463,6 +468,7 @@ func (zts ZetaTxServer) DeployZRC20s(
"SOL",
coin.CoinType_Gas,
100000,
liquidityCap,
),
fungibletypes.NewMsgDeployFungibleCoinZRC20(
deployerAddr,
Expand All @@ -473,6 +479,7 @@ func (zts ZetaTxServer) DeployZRC20s(
"TON",
coin.CoinType_Gas,
100_000,
liquidityCap,
),
fungibletypes.NewMsgDeployFungibleCoinZRC20(
deployerAddr,
Expand All @@ -483,6 +490,7 @@ func (zts ZetaTxServer) DeployZRC20s(
"USDT",
coin.CoinType_ERC20,
100000,
liquidityCap,
),
}

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

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

import (
sdkmath "cosmossdk.io/math"
"math/big"
"testing"

Expand Down Expand Up @@ -634,6 +635,7 @@ func setupGasCoin(
symbol,
8,
nil,
sdkmath.NewUintFromString("100000000000000000000000000"),
)
require.NoError(t, err)
assertContractDeployment(t, *evmk, ctx, addr)
Expand Down
1 change: 1 addition & 0 deletions precompiles/staking/staking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,7 @@ func setupGasCoin(
symbol,
8,
nil,
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;
lumtis marked this conversation as resolved.
Show resolved Hide resolved
string liquidity_cap = 8 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Uint",
(gogoproto.nullable) = false
];
}

message MsgWhitelistERC20Response {
Expand Down
4 changes: 4 additions & 0 deletions proto/zetachain/zetacore/fungible/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ 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",
(gogoproto.nullable) = false
];
}

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])

lumtis marked this conversation as resolved.
Show resolved Hide resolved
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
4 changes: 3 additions & 1 deletion x/crosschain/keeper/msg_server_whitelist_erc20.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ func (k msgServer) WhitelistERC20(
coin.CoinType_ERC20,
msg.Erc20Address,
big.NewInt(msg.GasLimit),
msg.LiquidityCap,
lumtis marked this conversation as resolved.
Show resolved Hide resolved
)
if err != nil {
return nil, errorsmod.Wrapf(
Expand Down Expand Up @@ -172,7 +173,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
Loading