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

#51 free liquidity -- Draft PR #66

Closed
wants to merge 42 commits into from
Closed
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
32f4b5f
#30 Add timeInForce to CancelOrReplace Msg
blewater May 7, 2021
5afe33a
Merge Develop into 30-emcli-market-cancelreplace
blewater May 7, 2021
82dd5cf
Add implementation
blewater May 10, 2021
ffebfd4
Undo refactoring
blewater May 11, 2021
8a18f69
Add keeper unit tests
blewater May 11, 2021
d76e843
Add documentation
blewater May 11, 2021
99a8031
Add proto msg type
blewater May 12, 2021
42d695b
Add Params
blewater May 12, 2021
7a5041e
Add trx params
blewater May 13, 2021
9c89590
Add trx type in orders
blewater May 13, 2021
bbd27af
Fix subspace init
blewater May 14, 2021
6862b28
Fix tests
blewater May 14, 2021
1621211
Add validation
blewater May 14, 2021
504821b
Add Implementation
blewater May 14, 2021
f9c6aa5
Add liquid tests, fixes
blewater May 15, 2021
bd9a33f
Fix test, refactor, documentation.
blewater May 16, 2021
e0f74cc
Test, Fix Cancel, Replacement orders
blewater May 16, 2021
7e0c45d
Refactor
blewater May 17, 2021
5c0ba33
Add params initialization
blewater May 18, 2021
b8553e9
Add panic stack trace
blewater May 18, 2021
8e687ed
Formatting, documentation
blewater May 18, 2021
c6091f3
Remove previous gas const
blewater May 18, 2021
62b38b7
Clarify expressions
blewater May 18, 2021
712cb96
Add Partial Gas Pricing Tests
blewater May 18, 2021
6f8810a
Dry
blewater May 18, 2021
671962b
Add non-covered tests
blewater May 19, 2021
0fe6d3f
Update swagger.json
blewater May 20, 2021
69db864
Revert KillOrder flag
blewater May 20, 2021
f170f28
Fix FOK, IOC gas, add tests
blewater May 20, 2021
f9f5efb
Fix sort
blewater May 20, 2021
baf359b
Add calcOrderGas tests
blewater May 20, 2021
67f1548
Remove panic handling
blewater May 21, 2021
d2a76c1
Add Market Chain Decorator
blewater May 24, 2021
685b5f6
WIP test chained AnteHandlers
blewater May 24, 2021
1a21a34
Add trx liquid order test
blewater May 25, 2021
26fc8a4
Add Market Msg Guard, App tests
blewater May 25, 2021
552a3c7
Remove OrigOrderCreated
blewater May 27, 2021
4d6f267
Remove ante handler, market order adj
blewater May 28, 2021
0ccc291
Merge develop into PR 66
blewater May 31, 2021
4d51236
Merge branch 'develop' into 51-free-liquidity
blewater Jun 1, 2021
c8baf6a
Adjust tests without ante handler
blewater Jun 1, 2021
45d2fbf
#51 Add unit test
blewater Jun 2, 2021
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
3 changes: 2 additions & 1 deletion app.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ func NewApp(
app.lpKeeper = liquidityprovider.NewKeeper(app.accountKeeper, app.bankKeeper)
app.issuerKeeper = issuer.NewKeeper(app.appCodec, keys[issuer.StoreKey], app.lpKeeper, app.inflationKeeper)
app.authorityKeeper = authority.NewKeeper(app.appCodec, keys[authority.StoreKey], app.issuerKeeper, app.bankKeeper, app)
app.marketKeeper = market.NewKeeper(app.appCodec, keys[market.StoreKey], keys[market.StoreKeyIdx], app.accountKeeper, app.bankKeeper, app.authorityKeeper)
app.marketKeeper = market.NewKeeper(app.appCodec, keys[market.StoreKey], keys[market.StoreKeyIdx], app.accountKeeper, app.bankKeeper, app.authorityKeeper, app.GetSubspace(market.ModuleName))
app.buybackKeeper = buyback.NewKeeper(app.appCodec, keys[buyback.StoreKey], app.marketKeeper, app.accountKeeper, app.stakingKeeper, app.bankKeeper)
app.bep3Keeper = bep3.NewKeeper(app.appCodec, keys[bep3.StoreKey], app.bankKeeper, app.accountKeeper, app.paramsKeeper.Subspace(bep3.ModuleName), GetMaccs())

Expand Down Expand Up @@ -624,6 +624,7 @@ func initParamsKeeper(appCodec codec.BinaryMarshaler, legacyAmino *codec.LegacyA
paramsKeeper.Subspace(distrtypes.ModuleName)
paramsKeeper.Subspace(emslashing.ModuleName)
paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govtypes.ParamKeyTable())
paramsKeeper.Subspace(market.ModuleName)
paramsKeeper.Subspace(crisistypes.ModuleName)
paramsKeeper.Subspace(ibctransfertypes.ModuleName)
paramsKeeper.Subspace(ibchost.ModuleName)
Expand Down
54 changes: 54 additions & 0 deletions docs/proto/em/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@
- [MsgCancelOrderResponse](#em.market.v1.MsgCancelOrderResponse)
- [MsgCancelReplaceLimitOrder](#em.market.v1.MsgCancelReplaceLimitOrder)
- [MsgCancelReplaceLimitOrderResponse](#em.market.v1.MsgCancelReplaceLimitOrderResponse)
- [MsgCancelReplaceMarketOrder](#em.market.v1.MsgCancelReplaceMarketOrder)
- [MsgCancelReplaceMarketOrderResponse](#em.market.v1.MsgCancelReplaceMarketOrderResponse)
- [TxParams](#em.market.v1.TxParams)

- [Msg](#em.market.v1.Msg)

Expand Down Expand Up @@ -1120,6 +1123,7 @@
| `destination` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | |
| `destination_filled` | [string](#string) | | |
| `created` | [google.protobuf.Timestamp](#google.protobuf.Timestamp) | | |
| `orig_order_created` | [google.protobuf.Timestamp](#google.protobuf.Timestamp) | | applicable to CancelReplace orders: the creation timestamp of the original order. |



Expand Down Expand Up @@ -1407,6 +1411,7 @@
| `owner` | [string](#string) | | |
| `original_client_order_id` | [string](#string) | | |
| `new_client_order_id` | [string](#string) | | |
| `time_in_force` | [TimeInForce](#em.market.v1.TimeInForce) | | |
| `source` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | |
| `destination` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | |

Expand All @@ -1424,6 +1429,54 @@




<a name="em.market.v1.MsgCancelReplaceMarketOrder"></a>

### MsgCancelReplaceMarketOrder



| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `owner` | [string](#string) | | |
| `original_client_order_id` | [string](#string) | | |
| `new_client_order_id` | [string](#string) | | |
| `time_in_force` | [TimeInForce](#em.market.v1.TimeInForce) | | |
| `source` | [string](#string) | | |
| `destination` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | |
| `maximum_slippage` | [string](#string) | | |






<a name="em.market.v1.MsgCancelReplaceMarketOrderResponse"></a>

### MsgCancelReplaceMarketOrderResponse







<a name="em.market.v1.TxParams"></a>

### TxParams



| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `trx_fee` | [uint64](#uint64) | | default fee for a market transaction. |
| `liquid_trx_fee` | [uint64](#uint64) | | Valid liquidity adding orders are free or adjusted to a minimum nominal/fee |
| `liquidity_rebate_minutes_span` | [int64](#int64) | | Minutes interval for eligible replacing transactions to receive a rebate. For a rebate to apply, the replacing transaction should occur these minutes after the signer's original trx. |





<!-- end messages -->

<!-- end enums -->
Expand All @@ -1442,6 +1495,7 @@
| `AddMarketOrder` | [MsgAddMarketOrder](#em.market.v1.MsgAddMarketOrder) | [MsgAddMarketOrderResponse](#em.market.v1.MsgAddMarketOrderResponse) | | |
| `CancelOrder` | [MsgCancelOrder](#em.market.v1.MsgCancelOrder) | [MsgCancelOrderResponse](#em.market.v1.MsgCancelOrderResponse) | | |
| `CancelReplaceLimitOrder` | [MsgCancelReplaceLimitOrder](#em.market.v1.MsgCancelReplaceLimitOrder) | [MsgCancelReplaceLimitOrderResponse](#em.market.v1.MsgCancelReplaceLimitOrderResponse) | | |
| `CancelReplaceMarketOrder` | [MsgCancelReplaceMarketOrder](#em.market.v1.MsgCancelReplaceMarketOrder) | [MsgCancelReplaceMarketOrderResponse](#em.market.v1.MsgCancelReplaceMarketOrderResponse) | | |

<!-- end services -->

Expand Down
8 changes: 8 additions & 0 deletions proto/em/market/v1/market.proto
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ message Order {
(gogoproto.nullable) = false,
(gogoproto.stdtime) = true
];

// applicable to CancelReplace orders: the creation timestamp of the original
// order.
google.protobuf.Timestamp orig_order_created = 11 [
(gogoproto.moretags) = "yaml:\"orig_order_created\"",
(gogoproto.nullable) = false,
(gogoproto.stdtime) = true
];
}

message ExecutionPlan {
Expand Down
59 changes: 56 additions & 3 deletions proto/em/market/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,23 @@ service Msg {
rpc CancelOrder(MsgCancelOrder) returns (MsgCancelOrderResponse);
rpc CancelReplaceLimitOrder(MsgCancelReplaceLimitOrder)
returns (MsgCancelReplaceLimitOrderResponse);
rpc CancelReplaceMarketOrder(MsgCancelReplaceMarketOrder)
returns (MsgCancelReplaceMarketOrderResponse);
}

message TxParams {
// default fee for a market transaction.
uint64 trx_fee = 1 [(gogoproto.moretags) = "yaml:\"trx_fee\""];

// Valid liquidity adding orders are free or adjusted to a minimum nominal/fee
uint64 liquid_trx_fee = 2 [(gogoproto.moretags) = "yaml:\"liquid_trx_fee\""];

// Minutes interval for eligible replacing transactions to receive a rebate.
// For a rebate to apply, the replacing transaction should occur these minutes
// after the signer's original trx.
int64 liquidity_rebate_minutes_span = 3 [
(gogoproto.moretags) = "yaml:\"liquidity_rebate_minutes_span\""
];
}

message MsgAddLimitOrder {
Expand Down Expand Up @@ -85,14 +102,50 @@ message MsgCancelReplaceLimitOrder {
(gogoproto.moretags) = "yaml:\"new_client_order_id\""
];

cosmos.base.v1beta1.Coin source = 4 [
TimeInForce time_in_force = 4
[ (gogoproto.moretags) = "yaml:\"time_in_force\"" ];

cosmos.base.v1beta1.Coin source = 5 [
(gogoproto.moretags) = "yaml:\"source\"",
(gogoproto.nullable) = false
];
cosmos.base.v1beta1.Coin destination = 5 [
cosmos.base.v1beta1.Coin destination = 6 [
(gogoproto.moretags) = "yaml:\"destination\"",
(gogoproto.nullable) = false
];
}

message MsgCancelReplaceLimitOrderResponse {}

message MsgCancelReplaceMarketOrder {
string owner = 1 [ (gogoproto.moretags) = "yaml:\"owner\"" ];

string original_client_order_id = 2 [
(gogoproto.customname) = "OrigClientOrderId",
(gogoproto.moretags) = "yaml:\"original_client_order_id\""
];

string new_client_order_id = 3 [
(gogoproto.customname) = "NewClientOrderId",
(gogoproto.moretags) = "yaml:\"new_client_order_id\""
];

TimeInForce time_in_force = 4
[ (gogoproto.moretags) = "yaml:\"time_in_force\"" ];

string source = 5 [ (gogoproto.moretags) = "yaml:\"source\"" ];

cosmos.base.v1beta1.Coin destination = 6 [
(gogoproto.moretags) = "yaml:\"destination\"",
(gogoproto.nullable) = false
];

string maximum_slippage = 7 [
(gogoproto.customname) = "MaxSlippage",
(gogoproto.moretags) = "yaml:\"maximum_slippage\"",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
}

message MsgCancelReplaceLimitOrderResponse {}
message MsgCancelReplaceMarketOrderResponse {}
2 changes: 2 additions & 0 deletions x/buyback/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/e-money/em-ledger/x/buyback/internal/types"
markettypes "github.com/e-money/em-ledger/x/market/types"
"time"
)

func BeginBlocker(ctx sdk.Context, k Keeper, bk types.BankKeeper) {
Expand Down Expand Up @@ -46,6 +47,7 @@ func BeginBlocker(ctx sdk.Context, k Keeper, bk types.BankKeeper) {
sdk.NewCoin(stakingDenom, destinationAmount),
account,
generateClientOrderId(ctx, balance),
time.Time{},
blewater marked this conversation as resolved.
Show resolved Hide resolved
)

if err != nil {
Expand Down
23 changes: 19 additions & 4 deletions x/buyback/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
embank "github.com/e-money/em-ledger/hooks/bank"
types2 "github.com/e-money/em-ledger/x/authority/types"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
Expand Down Expand Up @@ -209,7 +210,14 @@ func generateMarketActivity(ctx sdk.Context, marketKeeper *market.Keeper, ak ban
func order(account authtypes.AccountI, src, dst string) types.Order {
s, _ := sdk.ParseCoinNormalized(src)
d, _ := sdk.ParseCoinNormalized(dst)
o, err := types.NewOrder(time.Now(), types.TimeInForce_GoodTillCancel, s, d, account.GetAddress(), tmrand.Str(10))
o, err := types.NewOrder(
time.Now(),
types.TimeInForce_GoodTillCancel,
s, d,
account.GetAddress(),
tmrand.Str(10),
time.Time{},
)
if err != nil {
panic(err)
}
Expand All @@ -231,15 +239,15 @@ func createTestComponents(t *testing.T) (sdk.Context, keeper.Keeper, *market.Kee
encConfig := MakeTestEncodingConfig()

var (
keyMarket = sdk.NewKVStoreKey(types.ModuleName)
keyMarket = sdk.NewKVStoreKey(types.StoreKey)
keyIndices = sdk.NewKVStoreKey(types.StoreKeyIdx)
authCapKey = sdk.NewKVStoreKey("authCapKey")
keyParams = sdk.NewKVStoreKey("params")
stakingKey = sdk.NewKVStoreKey("staking")
buybackKey = sdk.NewKVStoreKey("buyback")
bankKey = sdk.NewKVStoreKey(banktypes.ModuleName)

tkeyParams = sdk.NewTransientStoreKey("transient_params")
tkeyParams = sdk.NewTransientStoreKey(paramstypes.TStoreKey)

blockedAddr = make(map[string]bool)
maccPerms = map[string][]string{
Expand All @@ -249,12 +257,14 @@ func createTestComponents(t *testing.T) (sdk.Context, keeper.Keeper, *market.Kee

db := dbm.NewMemDB()
ms := store.NewCommitMultiStore(db)
ms.MountStoreWithDB(keyParams, sdk.StoreTypeIAVL, db)
ms.MountStoreWithDB(authCapKey, sdk.StoreTypeIAVL, db)
ms.MountStoreWithDB(stakingKey, sdk.StoreTypeIAVL, db)
ms.MountStoreWithDB(keyMarket, sdk.StoreTypeIAVL, db)
ms.MountStoreWithDB(keyIndices, sdk.StoreTypeIAVL, db)
ms.MountStoreWithDB(buybackKey, sdk.StoreTypeIAVL, db)
ms.MountStoreWithDB(bankKey, sdk.StoreTypeIAVL, db)
ms.MountStoreWithDB(tkeyParams, sdk.StoreTypeTransient, db)

err := ms.LoadLatestVersion()
require.Nil(t, err)
Expand All @@ -271,12 +281,17 @@ func createTestComponents(t *testing.T) (sdk.Context, keeper.Keeper, *market.Kee
bk = embank.Wrap(bankkeeper.NewBaseKeeper(
encConfig.Marshaler, bankKey, ak, pk.Subspace(banktypes.ModuleName), blockedAddr,
), allowAllDenoms)

marketKeeper = market.NewKeeper(
encConfig.Marshaler, keyMarket, keyIndices, ak, bk, mockAuthority{},
pk.Subspace(market.ModuleName),
)
)

initialSupply := coins(fmt.Sprintf("1000000eur,1000000usd,1000000chf,1000000jpy,1000000gbp,1000000%v,500000000pesos", stakingDenom))
bk.SetSupply(ctx, banktypes.NewSupply(initialSupply))

marketKeeper := market.NewKeeper(encConfig.Marshaler, keyMarket, keyIndices, ak, bk, mockAuthority{})
marketKeeper.InitParamsStore(ctx)

keeper := NewKeeper(encConfig.Marshaler, buybackKey, marketKeeper, ak, mockStakingKeeper{}, bk)
keeper.SetUpdateInterval(ctx, time.Hour)
Expand Down
13 changes: 13 additions & 0 deletions x/market/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,19 @@ func CancelReplaceOrder() *cobra.Command {
origClientOrderID := args[0]
newClientOrderID := args[3]

tif, err := cmd.Flags().GetString(flag_TimeInForce)
if err != nil {
return err
}

timeInForce, err := types.TimeInForceFromString(tif)
if err != nil {
return err
}

msg := &types.MsgCancelReplaceLimitOrder{
Owner: clientCtx.GetFromAddress().String(),
TimeInForce: timeInForce,
Source: src,
Destination: dst,
OrigClientOrderId: origClientOrderID,
Expand All @@ -225,5 +236,7 @@ func CancelReplaceOrder() *cobra.Command {
},
}
flags.AddTxFlagsToCmd(cmd)
cmd.Flags().String(flag_TimeInForce, "GTC", flag_TimeInForceDescription)

return cmd
}
8 changes: 5 additions & 3 deletions x/market/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@ func TestQueryByAccount(t *testing.T) {
types.TimeInForce_GoodTillCancel,
sdk.NewCoin("alx", sdk.OneInt()),
sdk.NewCoin("blx", sdk.OneInt()),
myAddress, "myOrderID",
myAddress,"myOrderID",
time.Time{},
)
require.NoError(t, err)
k.setOrder(ctx, &o)

expectedPlusOne := o
expectedPlusOne.Created.Add(1*time.Second)
expectedPlusOne.Created = expectedPlusOne.Created.Add(1*time.Second)

specs := map[string]struct {
req *types.QueryByAccountRequest
Expand All @@ -47,6 +48,7 @@ func TestQueryByAccount(t *testing.T) {
"created plus a sec": {
req: &types.QueryByAccountRequest{Address: myAddress.String()},
expState: []*types.Order{&expectedPlusOne},
createdPlusOne: true,
},
"empty address": {
req: &types.QueryByAccountRequest{Address: ""},
Expand All @@ -72,7 +74,7 @@ func TestQueryByAccount(t *testing.T) {
if spec.createdPlusOne {
assert.NotEqual(t, spec.expState, gotRsp.Orders)
// set equal
gotRsp.Orders[0].Created.Add(1*time.Second)
gotRsp.Orders[0].Created = gotRsp.Orders[0].Created.Add(1*time.Second)
}

assert.Equal(t, spec.expState, gotRsp.Orders)
Expand Down
Loading