diff --git a/.changelog/config.toml b/.changelog/config.toml new file mode 100644 index 0000000..9d706fd --- /dev/null +++ b/.changelog/config.toml @@ -0,0 +1 @@ +project_url = "https://github.com/noble-assets/halo" diff --git a/.changelog/unreleased/.gitkeep b/.changelog/unreleased/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/.changelog/v1.0.0/summary.md b/.changelog/v1.0.0/summary.md new file mode 100644 index 0000000..23c9e9b --- /dev/null +++ b/.changelog/v1.0.0/summary.md @@ -0,0 +1,3 @@ +*Aug 26, 2024* + +Initial release of the `x/halo` module, allowing [USYC](https://usyc.hashnote.com) native issuance on Noble. diff --git a/.changelog/v1.0.1/bug-fixes/8-recipient-check.md b/.changelog/v1.0.1/bug-fixes/8-recipient-check.md new file mode 100644 index 0000000..b21da27 --- /dev/null +++ b/.changelog/v1.0.1/bug-fixes/8-recipient-check.md @@ -0,0 +1 @@ +- Ensure the recipient is a liquidity provider when trading to fiat. ([#8](https://github.com/noble-assets/halo/pull/8)) diff --git a/.changelog/v1.0.1/summary.md b/.changelog/v1.0.1/summary.md new file mode 100644 index 0000000..e6bda10 --- /dev/null +++ b/.changelog/v1.0.1/summary.md @@ -0,0 +1,3 @@ +*Sep 12, 2024* + +This is a consensus breaking patch to the `v1` release line. diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..f880389 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,18 @@ +# CHANGELOG + +## v1.0.1 + +*Sep 12, 2024* + +This is a consensus breaking patch to the `v1` release line. + +### BUG FIXES + +- Ensure the recipient is a liquidity provider when trading to fiat. ([#8](https://github.com/noble-assets/halo/pull/8)) + +## v1.0.0 + +*Aug 26, 2024* + +Initial release of the `x/halo` module, allowing [USYC](https://usyc.hashnote.com) native issuance on Noble. + diff --git a/x/halo/keeper/msg_server.go b/x/halo/keeper/msg_server.go index f9d88cb..c4ccbb4 100644 --- a/x/halo/keeper/msg_server.go +++ b/x/halo/keeper/msg_server.go @@ -231,7 +231,7 @@ func (k msgServer) TradeToFiat(goCtx context.Context, msg *types.MsgTradeToFiat) if err != nil { return nil, errors.Wrapf(err, "unable to decode recipient address %s", msg.Recipient) } - if !k.HasRole(ctx, signer, entitlements.ROLE_LIQUIDITY_PROVIDER) { + if !k.HasRole(ctx, recipient, entitlements.ROLE_LIQUIDITY_PROVIDER) { return nil, types.ErrInvalidLiquidityProvider } if !msg.Amount.IsPositive() { diff --git a/x/halo/keeper/msg_server_test.go b/x/halo/keeper/msg_server_test.go index a779c71..d07c89a 100644 --- a/x/halo/keeper/msg_server_test.go +++ b/x/halo/keeper/msg_server_test.go @@ -913,8 +913,8 @@ func TestTradeToFiat(t *testing.T) { goCtx := sdk.WrapSDKContext(ctx) server := keeper.NewMsgServer(k) - // ARRANGE: Generate an admin account. - admin := utils.TestAccount() + // ARRANGE: Generate an admin and recipient account. + admin, recipient := utils.TestAccount(), utils.TestAccount() // ACT: Attempt to trade to fiat with an invalid signer address. _, err := server.TradeToFiat(goCtx, &types.MsgTradeToFiat{ @@ -936,7 +936,7 @@ func TestTradeToFiat(t *testing.T) { // ACT: Attempt to trade to fiat with an invalid recipient address. _, err = server.TradeToFiat(goCtx, &types.MsgTradeToFiat{ Signer: admin.Address, - Recipient: admin.Invalid, + Recipient: recipient.Invalid, }) // ASSERT: The action should've failed due to invalid recipient address. require.ErrorContains(t, err, "unable to decode recipient address") @@ -944,19 +944,19 @@ func TestTradeToFiat(t *testing.T) { // ACT: Attempt to trade to fiat with invalid recipient permissions. _, err = server.TradeToFiat(goCtx, &types.MsgTradeToFiat{ Signer: admin.Address, - Recipient: admin.Address, + Recipient: recipient.Address, }) // ASSERT: The action should've failed due to invalid recipient permissions. require.ErrorContains(t, err, types.ErrInvalidLiquidityProvider.Error()) // ARRANGE: Set liquidity provider in state. - k.SetUserRole(ctx, admin.Bytes, entitlements.ROLE_LIQUIDITY_PROVIDER, true) + k.SetUserRole(ctx, recipient.Bytes, entitlements.ROLE_LIQUIDITY_PROVIDER, true) // ACT: Attempt to trade to fiat with insufficient funds. _, err = server.TradeToFiat(goCtx, &types.MsgTradeToFiat{ Signer: admin.Address, Amount: ONE, - Recipient: admin.Address, + Recipient: recipient.Address, }) // ASSERT: The action should've failed due to insufficient funds. require.ErrorContains(t, err, "insufficient funds") @@ -968,7 +968,7 @@ func TestTradeToFiat(t *testing.T) { _, err = server.TradeToFiat(goCtx, &types.MsgTradeToFiat{ Signer: admin.Address, Amount: sdk.NewInt(-1_000_000), - Recipient: admin.Address, + Recipient: recipient.Address, }) // ASSERT: The action should've failed due to invalid amount. require.ErrorContains(t, err, "invalid amount") @@ -977,11 +977,11 @@ func TestTradeToFiat(t *testing.T) { _, err = server.TradeToFiat(goCtx, &types.MsgTradeToFiat{ Signer: admin.Address, Amount: ONE, - Recipient: admin.Address, + Recipient: recipient.Address, }) // ASSERT: The action should've succeeded. require.NoError(t, err) - require.Equal(t, ONE, bank.Balances[admin.Address].AmountOf(k.Underlying)) + require.Equal(t, ONE, bank.Balances[recipient.Address].AmountOf(k.Underlying)) require.True(t, bank.Balances[types.ModuleName].IsZero()) }