Skip to content

Commit

Permalink
Merge branch 'master' into yaroslav/ibc-hooks-integration
Browse files Browse the repository at this point in the history
  • Loading branch information
ysv authored Apr 29, 2024
2 parents b24c96d + b8a5277 commit 17c0511
Show file tree
Hide file tree
Showing 26 changed files with 1,489 additions and 178 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ vendor
/bin
*.iml
go.work*
.DS_Store
1 change: 1 addition & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ func New(
// pointer is used here because there is cycle in keeper dependencies:
// AssetFTKeeper -> WasmKeeper -> BankKeeper -> AssetFTKeeper
&app.WasmKeeper,
&app.AccountKeeper,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

Expand Down
27 changes: 15 additions & 12 deletions build/coreum/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ const (
cosmovisorBinaryPath = "bin/cosmovisor"
goCoverFlag = "-cover"
tagsFlag = "-tags"
linkStaticallyLDFlag = "-ldflags=-extldflags=-static"
ldFlagsFlag = "-ldflags"
linkStaticallyValue = "-extldflags=-static"
)

var (
Expand Down Expand Up @@ -52,7 +53,7 @@ func BuildCoredLocally(ctx context.Context, deps build.DepsFunc) error {
CGOEnabled: true,
Flags: []string{
goCoverFlag,
versionFlags,
convertToLdFlags(versionFlags),
tagsFlag + "=" + strings.Join(tagsLocal, ","),
},
})
Expand Down Expand Up @@ -86,8 +87,7 @@ func buildCoredInDocker(
CGOEnabled: true,
Flags: append(
extraFlags,
versionFlags,
linkStaticallyLDFlag,
convertToLdFlags(append(versionFlags, linkStaticallyValue)),
tagsFlag+"="+strings.Join(tagsDocker, ","),
),
})
Expand Down Expand Up @@ -115,8 +115,7 @@ func buildCoredClientInDocker(ctx context.Context, deps build.DepsFunc, targetPl
BinOutputPath: binOutputPath,
CGOEnabled: false,
Flags: []string{
versionFlags,
linkStaticallyLDFlag,
convertToLdFlags(append(versionFlags, linkStaticallyValue)),
tagsFlag + "=" + strings.Join(tagsDocker, ","),
},
})
Expand All @@ -143,15 +142,15 @@ func DownloadDependencies(ctx context.Context, deps build.DepsFunc) error {
return golang.DownloadDependencies(ctx, repoPath, deps)
}

func coredVersionLDFlags(ctx context.Context, buildTags []string) (string, error) {
func coredVersionLDFlags(ctx context.Context, buildTags []string) ([]string, error) {
hash, err := git.DirtyHeadHash(ctx, repoPath)
if err != nil {
return "", err
return nil, err
}

version, err := git.VersionFromTag(ctx, repoPath)
if err != nil {
return "", err
return nil, err
}
if version == "" {
version = hash
Expand All @@ -167,12 +166,12 @@ func coredVersionLDFlags(ctx context.Context, buildTags []string) (string, error
ps["github.com/cosmos/cosmos-sdk/version.BuildTags"] = strings.Join(buildTags, ",")
}

var ldFlags []string
var values []string
for k, v := range ps {
ldFlags = append(ldFlags, fmt.Sprintf("-X %s=%s", k, v))
values = append(values, fmt.Sprintf("-X %s=%s", k, v))
}

return "-ldflags=" + strings.Join(ldFlags, " "), nil
return values, nil
}

func formatProto(ctx context.Context, deps build.DepsFunc) error {
Expand All @@ -182,3 +181,7 @@ func formatProto(ctx context.Context, deps build.DepsFunc) error {
cmd.Dir = filepath.Join(repoPath, "proto", "coreum")
return libexec.Exec(ctx, cmd)
}

func convertToLdFlags(values []string) string {
return "-" + ldFlagsFlag + "=" + strings.Join(values, " ")
}
38 changes: 38 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- [MintAuthorization](#coreum.asset.ft.v1.MintAuthorization)

- [coreum/asset/ft/v1/event.proto](#coreum/asset/ft/v1/event.proto)
- [EventAmountClawedBack](#coreum.asset.ft.v1.EventAmountClawedBack)
- [EventFrozenAmountChanged](#coreum.asset.ft.v1.EventFrozenAmountChanged)
- [EventIssued](#coreum.asset.ft.v1.EventIssued)
- [EventWhitelistedAmountChanged](#coreum.asset.ft.v1.EventWhitelistedAmountChanged)
Expand Down Expand Up @@ -56,6 +57,7 @@
- [coreum/asset/ft/v1/tx.proto](#coreum/asset/ft/v1/tx.proto)
- [EmptyResponse](#coreum.asset.ft.v1.EmptyResponse)
- [MsgBurn](#coreum.asset.ft.v1.MsgBurn)
- [MsgClawback](#coreum.asset.ft.v1.MsgClawback)
- [MsgFreeze](#coreum.asset.ft.v1.MsgFreeze)
- [MsgGloballyFreeze](#coreum.asset.ft.v1.MsgGloballyFreeze)
- [MsgGloballyUnfreeze](#coreum.asset.ft.v1.MsgGloballyUnfreeze)
Expand Down Expand Up @@ -1579,6 +1581,23 @@ the granter's account.



<a name="coreum.asset.ft.v1.EventAmountClawedBack"></a>

### EventAmountClawedBack



| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `account` | [string](#string) | | |
| `denom` | [string](#string) | | |
| `amount` | [string](#string) | | |






<a name="coreum.asset.ft.v1.EventFrozenAmountChanged"></a>

### EventFrozenAmountChanged
Expand Down Expand Up @@ -2236,6 +2255,7 @@ Feature defines possible features of fungible token.
| whitelisting | 3 | |
| ibc | 4 | |
| block_smart_contracts | 5 | |
| clawback | 6 | |


<!-- end enums -->
Expand Down Expand Up @@ -2279,6 +2299,23 @@ Feature defines possible features of fungible token.



<a name="coreum.asset.ft.v1.MsgClawback"></a>

### MsgClawback



| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `sender` | [string](#string) | | |
| `account` | [string](#string) | | |
| `coin` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | |






<a name="coreum.asset.ft.v1.MsgFreeze"></a>

### MsgFreeze
Expand Down Expand Up @@ -2487,6 +2524,7 @@ Msg defines the Msg service.
| `SetFrozen` | [MsgSetFrozen](#coreum.asset.ft.v1.MsgSetFrozen) | [EmptyResponse](#coreum.asset.ft.v1.EmptyResponse) | `SetFrozen sets the absolute value of frozen amount.` | |
| `GloballyFreeze` | [MsgGloballyFreeze](#coreum.asset.ft.v1.MsgGloballyFreeze) | [EmptyResponse](#coreum.asset.ft.v1.EmptyResponse) | `GloballyFreeze freezes fungible token so no operations are allowed with it before unfrozen. This operation is idempotent so global freeze of already frozen token does nothing.` | |
| `GloballyUnfreeze` | [MsgGloballyUnfreeze](#coreum.asset.ft.v1.MsgGloballyUnfreeze) | [EmptyResponse](#coreum.asset.ft.v1.EmptyResponse) | `GloballyUnfreeze unfreezes fungible token and unblocks basic operations on it. This operation is idempotent so global unfreezing of non-frozen token does nothing.` | |
| `Clawback` | [MsgClawback](#coreum.asset.ft.v1.MsgClawback) | [EmptyResponse](#coreum.asset.ft.v1.EmptyResponse) | `Clawback confiscates a part of fungible tokens from an account to the issuer, only if the clawback feature is enabled on that token.` | |
| `SetWhitelistedLimit` | [MsgSetWhitelistedLimit](#coreum.asset.ft.v1.MsgSetWhitelistedLimit) | [EmptyResponse](#coreum.asset.ft.v1.EmptyResponse) | `SetWhitelistedLimit sets the limit of how many tokens a specific account may hold.` | |
| `UpgradeTokenV1` | [MsgUpgradeTokenV1](#coreum.asset.ft.v1.MsgUpgradeTokenV1) | [EmptyResponse](#coreum.asset.ft.v1.EmptyResponse) | `TokenUpgradeV1 upgrades token to version V1.` | |
| `UpdateParams` | [MsgUpdateParams](#coreum.asset.ft.v1.MsgUpdateParams) | [EmptyResponse](#coreum.asset.ft.v1.EmptyResponse) | `UpdateParams is a governance operation to modify the parameters of the module. NOTE: all parameters must be provided.` | |
Expand Down
3 changes: 2 additions & 1 deletion docs/static/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -9090,7 +9090,8 @@
"freezing",
"whitelisting",
"ibc",
"block_smart_contracts"
"block_smart_contracts",
"clawback"
],
"default": "minting",
"description": "Feature defines possible features of fungible token."
Expand Down
99 changes: 99 additions & 0 deletions integration-tests/ibc/asset_ft_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,105 @@ func TestIBCGlobalFreeze(t *testing.T) {
requireT.NoError(coreumChain.AwaitForBalance(ctx, t, coreumRecipient, sendCoinBack))
}

func TestIBCAssetFTClawback(t *testing.T) {
t.Parallel()

ctx, chains := integrationtests.NewChainsTestingContext(t)
requireT := require.New(t)
assertT := assert.New(t)
coreumChain := chains.Coreum
gaiaChain := chains.Gaia

gaiaToCoreumChannelID := gaiaChain.AwaitForIBCChannelID(
ctx, t, ibctransfertypes.PortID, coreumChain.ChainSettings.ChainID,
)

coreumIssuer := coreumChain.GenAccount()
coreumSender := coreumChain.GenAccount()
gaiaRecipient := gaiaChain.GenAccount()

gaiaChain.Faucet.FundAccounts(ctx, t, integration.FundedAccount{
Address: gaiaRecipient,
Amount: gaiaChain.NewCoin(sdkmath.NewInt(1000000)), // coin for the fees
})

issueFee := coreumChain.QueryAssetFTParams(ctx, t).IssueFee.Amount
coreumChain.FundAccountWithOptions(ctx, t, coreumIssuer, integration.BalancesOptions{
Messages: []sdk.Msg{
&assetfttypes.MsgIssue{},
&banktypes.MsgSend{},
&assetfttypes.MsgClawback{},
},
Amount: issueFee,
})
coreumChain.FundAccountWithOptions(ctx, t, coreumSender, integration.BalancesOptions{
Messages: []sdk.Msg{
&ibctransfertypes.MsgTransfer{},
&ibctransfertypes.MsgTransfer{},
},
})

issueMsg := &assetfttypes.MsgIssue{
Issuer: coreumIssuer.String(),
Symbol: "mysymbol",
Subunit: "mysubunit",
Precision: 8,
InitialAmount: sdkmath.NewInt(1_000_000),
Features: []assetfttypes.Feature{
assetfttypes.Feature_block_smart_contracts,
assetfttypes.Feature_ibc,
assetfttypes.Feature_clawback,
},
}
_, err := client.BroadcastTx(
ctx,
coreumChain.ClientContext.WithFromAddress(coreumIssuer),
coreumChain.TxFactory().WithGas(coreumChain.GasLimitByMsgs(issueMsg)),
issueMsg,
)
require.NoError(t, err)
denom := assetfttypes.BuildDenom(issueMsg.Subunit, coreumIssuer)

sendCoin := sdk.NewCoin(denom, sdkmath.NewInt(1000))
halfCoin := sdk.NewCoin(denom, sdkmath.NewInt(500))
msgSend := &banktypes.MsgSend{
FromAddress: coreumIssuer.String(),
ToAddress: coreumSender.String(),
Amount: sdk.NewCoins(sendCoin),
}
_, err = client.BroadcastTx(
ctx,
coreumChain.ClientContext.WithFromAddress(coreumIssuer),
coreumChain.TxFactory().WithGas(coreumChain.GasLimitByMsgs(msgSend)),
msgSend,
)
requireT.NoError(err)

clawbackMsg := &assetfttypes.MsgClawback{
Sender: coreumIssuer.String(),
Account: coreumSender.String(),
Coin: halfCoin,
}
_, err = client.BroadcastTx(
ctx,
coreumChain.ClientContext.WithFromAddress(coreumIssuer),
coreumChain.TxFactory().WithGas(coreumChain.GasLimitByMsgs(clawbackMsg)),
clawbackMsg,
)
require.NoError(t, err)

// send more than allowed, should fail
_, err = coreumChain.ExecuteIBCTransfer(ctx, t, coreumSender, sendCoin, gaiaChain.ChainContext, gaiaRecipient)
requireT.Error(err)
assertT.Contains(err.Error(), cosmoserrors.ErrInsufficientFunds.Error())

// send up to the limit, should succeed
ibcCoin := sdk.NewCoin(ConvertToIBCDenom(gaiaToCoreumChannelID, denom), halfCoin.Amount)
_, err = coreumChain.ExecuteIBCTransfer(ctx, t, coreumSender, halfCoin, gaiaChain.ChainContext, gaiaRecipient)
requireT.NoError(err)
requireT.NoError(gaiaChain.AwaitForBalance(ctx, t, gaiaRecipient, ibcCoin))
}

func TestIBCAssetFTTimedOutTransfer(t *testing.T) {
t.Parallel()

Expand Down
Loading

0 comments on commit 17c0511

Please sign in to comment.