Skip to content

Commit

Permalink
chore: proto and schema renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
ze97286 committed Nov 5, 2024
1 parent 78e0172 commit e15a15d
Show file tree
Hide file tree
Showing 18 changed files with 103 additions and 102 deletions.
4 changes: 2 additions & 2 deletions commands/vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func checkUpdateVault(cmd *commandspb.UpdateVault) Errors {
errs.AddForProperty("update_vault.redemption_dates", ErrIsRequired)
} else {
for i, rd := range cmd.RedemptionDates {
if rd.RedemptionType != vega.RedemptionType_REDEMPTION_TYPE_NORMAL && rd.RedemptionType != vega.RedemptionType_REDEMPTION_TYPE_FREE_CASH_ONLY {
if rd.RedemptionType != vega.RedemptionType_REDEMPTION_TYPE_NORMAL && rd.RedemptionType != vega.RedemptionType_REDEMPTION_TYPE_AVAILABLE_FUNDS_ONLY {
errs.AddForProperty(fmt.Sprintf("update_vault.redemption_dates.%d.redemption_type", i), ErrIsNotValid)
}
if len(rd.MaxFraction) == 0 {
Expand Down Expand Up @@ -231,7 +231,7 @@ func checkCreateVault(cmd *commandspb.CreateVault) Errors {
errs.AddForProperty("create_vault.redemption_dates", ErrIsRequired)
} else {
for i, rd := range cmd.RedemptionDates {
if rd.RedemptionType != vega.RedemptionType_REDEMPTION_TYPE_NORMAL && rd.RedemptionType != vega.RedemptionType_REDEMPTION_TYPE_FREE_CASH_ONLY {
if rd.RedemptionType != vega.RedemptionType_REDEMPTION_TYPE_NORMAL && rd.RedemptionType != vega.RedemptionType_REDEMPTION_TYPE_AVAILABLE_FUNDS_ONLY {
errs.AddForProperty(fmt.Sprintf("create_vault.redemption_dates.%d.redemption_type", i), ErrIsNotValid)
}
if len(rd.MaxFraction) == 0 {
Expand Down
4 changes: 2 additions & 2 deletions commands/vault_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ func TestCheckCreateVault(t *testing.T) {
RedemptionDates: []*vega.RedemptionDate{
{
RedemptionDate: 1234,
RedemptionType: vega.RedemptionType_REDEMPTION_TYPE_FREE_CASH_ONLY,
RedemptionType: vega.RedemptionType_REDEMPTION_TYPE_AVAILABLE_FUNDS_ONLY,
MaxFraction: "0.1",
},
},
Expand Down Expand Up @@ -661,7 +661,7 @@ func TestCheckUpdateVault(t *testing.T) {
RedemptionDates: []*vega.RedemptionDate{
{
RedemptionDate: 1234,
RedemptionType: vega.RedemptionType_REDEMPTION_TYPE_FREE_CASH_ONLY,
RedemptionType: vega.RedemptionType_REDEMPTION_TYPE_AVAILABLE_FUNDS_ONLY,
MaxFraction: "0.1",
},
},
Expand Down
2 changes: 1 addition & 1 deletion core/types/vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ const (
// Default value.
RedemptionTypeUnspecified RedemptionType = vega.RedemptionType_REDEMPTION_TYPE_UNSPECIFIED
// Consider only general account balance.
RedemptionTypeFreeCashOnly RedemptionType = vega.RedemptionType_REDEMPTION_TYPE_FREE_CASH_ONLY
RedemptionTypeAvailableFundsOnly RedemptionType = vega.RedemptionType_REDEMPTION_TYPE_AVAILABLE_FUNDS_ONLY
// Consider all vault accounts balance.
RedemptionTypeNormal RedemptionType = vega.RedemptionType_REDEMPTION_TYPE_NORMAL
)
Expand Down
4 changes: 2 additions & 2 deletions core/types/vault_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestVaultIntoProto(t *testing.T) {
CutOffPeriodLength: 10,
RedemptionDates: []*types.RedemptionDate{
{
RedemptionType: types.RedemptionTypeFreeCashOnly,
RedemptionType: types.RedemptionTypeAvailableFundsOnly,
RedemptionDate: time.Unix(1729451525, 0),
MaxFraction: num.NewDecimalFromFloat(0.5),
},
Expand All @@ -69,7 +69,7 @@ func TestVaultIntoProto(t *testing.T) {
require.Equal(t, 2, len(protoV.RedemptionDates))
require.Equal(t, "0.5", protoV.RedemptionDates[0].MaxFraction)
require.Equal(t, "0.7", protoV.RedemptionDates[1].MaxFraction)
require.Equal(t, types.RedemptionTypeFreeCashOnly, protoV.RedemptionDates[0].RedemptionType)
require.Equal(t, types.RedemptionTypeAvailableFundsOnly, protoV.RedemptionDates[0].RedemptionType)
require.Equal(t, types.RedemptionTypeNormal, protoV.RedemptionDates[1].RedemptionType)
require.Equal(t, int64(1729451525), protoV.RedemptionDates[0].RedemptionDate)
require.Equal(t, int64(1729537925), protoV.RedemptionDates[1].RedemptionDate)
Expand Down
4 changes: 2 additions & 2 deletions core/vault/vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ func PrepareRedemptions(now time.Time, shareHolders map[string]num.Decimal, rede
continue
}
redeem = num.Min(num.UintZero().Sub(partyShareOfLiquid, alreadyRedeemedThisDate), partyShareOfTotal)
} else if redemptionType == types.RedemptionTypeFreeCashOnly {
} else if redemptionType == types.RedemptionTypeAvailableFundsOnly {
if alreadyRedeemedThisDate.EQ(partyShareOfLiquid) {
rr.Status = types.RedeemStatusCompleted
rr.Remaining = num.UintZero()
Expand All @@ -531,7 +531,7 @@ func PrepareRedemptions(now time.Time, shareHolders map[string]num.Decimal, rede
redeem = num.Min(num.UintZero().Sub(partyShareOfLiquid, alreadyRedeemedThisDate), rr.Amount)
}
partyToRedeemed[rr.Party] = alreadyRedeemedThisDate.AddSum(redeem)
if redemptionType == types.RedemptionTypeFreeCashOnly {
if redemptionType == types.RedemptionTypeAvailableFundsOnly {
rr.Status = types.RedeemStatusCompleted
rr.Remaining = num.UintZero()
rr.LastUpdated = now
Expand Down
54 changes: 27 additions & 27 deletions core/vault/vault_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,17 +170,17 @@ func TestUpdateVault(t *testing.T) {
CutOffPeriodLength: 5,
RedemptionDates: []*types.RedemptionDate{
{
RedemptionType: types.RedemptionTypeFreeCashOnly,
RedemptionType: types.RedemptionTypeAvailableFundsOnly,
RedemptionDate: now.Add(2 * 24 * time.Hour),
MaxFraction: num.DecimalFromFloat(0.5),
},
{
RedemptionType: types.RedemptionTypeFreeCashOnly,
RedemptionType: types.RedemptionTypeAvailableFundsOnly,
RedemptionDate: now.Add(3 * 24 * time.Hour),
MaxFraction: num.DecimalFromFloat(0.3),
},
{
RedemptionType: types.RedemptionTypeFreeCashOnly,
RedemptionType: types.RedemptionTypeAvailableFundsOnly,
RedemptionDate: now.Add(10 * 24 * time.Hour),
MaxFraction: num.DecimalFromFloat(0.3),
},
Expand All @@ -205,7 +205,7 @@ func TestUpdateVault(t *testing.T) {
CutOffPeriodLength: 5,
RedemptionDates: []*types.RedemptionDate{
{
RedemptionType: types.RedemptionTypeFreeCashOnly,
RedemptionType: types.RedemptionTypeAvailableFundsOnly,
RedemptionDate: now.Add(-24 * time.Hour),
MaxFraction: num.DecimalFromFloat(0.5),
},
Expand All @@ -230,12 +230,12 @@ func TestUpdateVault(t *testing.T) {
CutOffPeriodLength: 5,
RedemptionDates: []*types.RedemptionDate{
{
RedemptionType: types.RedemptionTypeFreeCashOnly,
RedemptionType: types.RedemptionTypeAvailableFundsOnly,
RedemptionDate: now.Add(3 * 24 * time.Hour),
MaxFraction: num.DecimalFromFloat(0.3),
},
{
RedemptionType: types.RedemptionTypeFreeCashOnly,
RedemptionType: types.RedemptionTypeAvailableFundsOnly,
RedemptionDate: now.Add(10 * 24 * time.Hour),
MaxFraction: num.DecimalFromFloat(0.3),
},
Expand All @@ -260,17 +260,17 @@ func TestUpdateVault(t *testing.T) {
CutOffPeriodLength: 5,
RedemptionDates: []*types.RedemptionDate{
{
RedemptionType: types.RedemptionTypeFreeCashOnly,
RedemptionType: types.RedemptionTypeAvailableFundsOnly,
RedemptionDate: now.Add(2 * 24 * time.Hour),
MaxFraction: num.DecimalFromFloat(0.99),
},
{
RedemptionType: types.RedemptionTypeFreeCashOnly,
RedemptionType: types.RedemptionTypeAvailableFundsOnly,
RedemptionDate: now.Add(3 * 24 * time.Hour),
MaxFraction: num.DecimalFromFloat(0.3),
},
{
RedemptionType: types.RedemptionTypeFreeCashOnly,
RedemptionType: types.RedemptionTypeAvailableFundsOnly,
RedemptionDate: now.Add(10 * 24 * time.Hour),
MaxFraction: num.DecimalFromFloat(0.3),
},
Expand Down Expand Up @@ -301,7 +301,7 @@ func TestUpdateVault(t *testing.T) {
CutOffPeriodLength: 5,
RedemptionDates: []*types.RedemptionDate{
{
RedemptionType: types.RedemptionTypeFreeCashOnly,
RedemptionType: types.RedemptionTypeAvailableFundsOnly,
RedemptionDate: now.Add(2 * 24 * time.Hour),
MaxFraction: num.DecimalFromFloat(0.5),
},
Expand All @@ -311,7 +311,7 @@ func TestUpdateVault(t *testing.T) {
MaxFraction: num.DecimalFromFloat(0.3),
},
{
RedemptionType: types.RedemptionTypeFreeCashOnly,
RedemptionType: types.RedemptionTypeAvailableFundsOnly,
RedemptionDate: now.Add(10 * 24 * time.Hour),
MaxFraction: num.DecimalFromFloat(0.3),
},
Expand All @@ -321,13 +321,13 @@ func TestUpdateVault(t *testing.T) {

// try to change the max fraction
v4_2 := v4_1
v4_2.RedemptionDates[1].RedemptionType = types.RedemptionTypeFreeCashOnly
v4_2.RedemptionDates[1].RedemptionType = types.RedemptionTypeAvailableFundsOnly
v4_2.RedemptionDates[1].MaxFraction = num.DecimalFromFloat(0.99)
require.Equal(t, "redemption dates within notice period are not allowed to change", vault.UpdateVault(v4_2, now, 5).Error())

// try to change the date
v4_3 := v4_1
v4_3.RedemptionDates[1].RedemptionType = types.RedemptionTypeFreeCashOnly
v4_3.RedemptionDates[1].RedemptionType = types.RedemptionTypeAvailableFundsOnly
v4_3.RedemptionDates[1].MaxFraction = num.DecimalFromFloat(0.3)
v4_3.RedemptionDates[1].RedemptionDate = now.Add(4 * 24 * time.Hour)
require.Equal(t, "redemption dates within notice period are not allowed to change", vault.UpdateVault(v4_3, now, 5).Error())
Expand All @@ -349,17 +349,17 @@ func TestUpdateVault(t *testing.T) {
CutOffPeriodLength: 5,
RedemptionDates: []*types.RedemptionDate{
{
RedemptionType: types.RedemptionTypeFreeCashOnly,
RedemptionType: types.RedemptionTypeAvailableFundsOnly,
RedemptionDate: now.Add(2 * 24 * time.Hour),
MaxFraction: num.DecimalFromFloat(0.5),
},
{
RedemptionType: types.RedemptionTypeFreeCashOnly,
RedemptionType: types.RedemptionTypeAvailableFundsOnly,
RedemptionDate: now.Add(3 * 24 * time.Hour),
MaxFraction: num.DecimalFromFloat(0.3),
},
{
RedemptionType: types.RedemptionTypeFreeCashOnly,
RedemptionType: types.RedemptionTypeAvailableFundsOnly,
RedemptionDate: now.Add(10 * 24 * time.Hour),
MaxFraction: num.DecimalFromFloat(0.3),
},
Expand Down Expand Up @@ -547,7 +547,7 @@ func TestGetRedemptionRequestForDateLastDate(t *testing.T) {
PerformanceFeeFactor: num.DecimalZero(),
CutOffPeriodLength: 5,
RedemptionDates: []*types.RedemptionDate{
{RedemptionType: types.RedemptionTypeFreeCashOnly, RedemptionDate: now, MaxFraction: num.DecimalFromFloat(0.1)},
{RedemptionType: types.RedemptionTypeAvailableFundsOnly, RedemptionDate: now, MaxFraction: num.DecimalFromFloat(0.1)},
},
}, col, time.Now(), broker)
ctx := context.Background()
Expand Down Expand Up @@ -597,8 +597,8 @@ func TestGetRedemptionRequestForADate(t *testing.T) {
PerformanceFeeFactor: num.DecimalZero(),
CutOffPeriodLength: 3,
RedemptionDates: []*types.RedemptionDate{
{RedemptionType: types.RedemptionTypeFreeCashOnly, RedemptionDate: now.Add(3 * 24 * time.Hour), MaxFraction: num.DecimalFromFloat(0.1)},
{RedemptionType: types.RedemptionTypeFreeCashOnly, RedemptionDate: now.Add(5 * 24 * time.Hour), MaxFraction: num.DecimalFromFloat(0.1)},
{RedemptionType: types.RedemptionTypeAvailableFundsOnly, RedemptionDate: now.Add(3 * 24 * time.Hour), MaxFraction: num.DecimalFromFloat(0.1)},
{RedemptionType: types.RedemptionTypeAvailableFundsOnly, RedemptionDate: now.Add(5 * 24 * time.Hour), MaxFraction: num.DecimalFromFloat(0.1)},
},
}, col, time.Now(), broker)
ctx := context.Background()
Expand Down Expand Up @@ -637,15 +637,15 @@ func TestPrepareRedemptions(t *testing.T) {
requests := []*vault.RedeemRequest{
{Party: "p1", Date: time.Time{}, Amount: num.NewUint(100), Remaining: num.NewUint(100), Status: types.RedeemStatusPending},
}
partyToRedeemed, lateRedemptions := vault.PrepareRedemptions(time.Now(), map[string]num.Decimal{}, requests, num.NewUint(0), num.NewUint(0), types.RedemptionTypeFreeCashOnly, num.DecimalOne(), false)
partyToRedeemed, lateRedemptions := vault.PrepareRedemptions(time.Now(), map[string]num.Decimal{}, requests, num.NewUint(0), num.NewUint(0), types.RedemptionTypeAvailableFundsOnly, num.DecimalOne(), false)

require.Equal(t, 0, len(partyToRedeemed))
require.Equal(t, 0, len(lateRedemptions))
for _, rr := range requests {
require.True(t, rr.Status == types.RedeemStatusCompleted)
}

partyToRedeemed, lateRedemptions = vault.PrepareRedemptions(time.Now(), map[string]num.Decimal{}, requests, num.NewUint(100), num.NewUint(200), types.RedemptionTypeFreeCashOnly, num.DecimalOne(), false)
partyToRedeemed, lateRedemptions = vault.PrepareRedemptions(time.Now(), map[string]num.Decimal{}, requests, num.NewUint(100), num.NewUint(200), types.RedemptionTypeAvailableFundsOnly, num.DecimalOne(), false)

require.Equal(t, 0, len(partyToRedeemed))
require.Equal(t, 0, len(lateRedemptions))
Expand All @@ -666,7 +666,7 @@ func TestPrepareRedemptions(t *testing.T) {
{Party: "p1", Date: time.Time{}, Amount: num.NewUint(50), Remaining: num.NewUint(50), Status: types.RedeemStatusPending},
{Party: "p2", Date: time.Time{}, Amount: num.NewUint(30), Remaining: num.NewUint(30), Status: types.RedeemStatusPending},
}
partyToRedeemed, lateRedemptions = vault.PrepareRedemptions(time.Now(), map[string]num.Decimal{"p1": num.DecimalFromFloat(0.75), "p2": num.DecimalFromFloat(0.25)}, requests, num.NewUint(200), num.NewUint(160), types.RedemptionTypeFreeCashOnly, num.DecimalOne(), false)
partyToRedeemed, lateRedemptions = vault.PrepareRedemptions(time.Now(), map[string]num.Decimal{"p1": num.DecimalFromFloat(0.75), "p2": num.DecimalFromFloat(0.25)}, requests, num.NewUint(200), num.NewUint(160), types.RedemptionTypeAvailableFundsOnly, num.DecimalOne(), false)

require.Equal(t, 2, len(partyToRedeemed))
require.Equal(t, "50", partyToRedeemed["p1"].String())
Expand All @@ -690,7 +690,7 @@ func TestPrepareRedemptions(t *testing.T) {
{Party: "p1", Date: time.Time{}, Amount: num.NewUint(80), Remaining: num.NewUint(80), Status: types.RedeemStatusPending},
{Party: "p2", Date: time.Time{}, Amount: num.NewUint(30), Remaining: num.NewUint(30), Status: types.RedeemStatusPending},
}
partyToRedeemed, lateRedemptions = vault.PrepareRedemptions(time.Now(), map[string]num.Decimal{"p1": num.DecimalFromFloat(0.75), "p2": num.DecimalFromFloat(0.25)}, requests, num.NewUint(200), num.NewUint(100), types.RedemptionTypeFreeCashOnly, num.DecimalOne(), false)
partyToRedeemed, lateRedemptions = vault.PrepareRedemptions(time.Now(), map[string]num.Decimal{"p1": num.DecimalFromFloat(0.75), "p2": num.DecimalFromFloat(0.25)}, requests, num.NewUint(200), num.NewUint(100), types.RedemptionTypeAvailableFundsOnly, num.DecimalOne(), false)
require.Equal(t, 2, len(partyToRedeemed))
require.Equal(t, "75", partyToRedeemed["p1"].String())
require.Equal(t, "25", partyToRedeemed["p2"].String())
Expand All @@ -713,7 +713,7 @@ func TestPrepareRedemptions(t *testing.T) {
{Party: "p1", Date: time.Time{}, Amount: num.NewUint(30), Remaining: num.NewUint(30), Status: types.RedeemStatusPending},
{Party: "p1", Date: time.Time{}, Amount: num.NewUint(10), Remaining: num.NewUint(10), Status: types.RedeemStatusPending},
}
partyToRedeemed, lateRedemptions = vault.PrepareRedemptions(time.Now(), map[string]num.Decimal{"p1": num.DecimalFromFloat(0.75), "p2": num.DecimalFromFloat(0.25)}, requests, num.NewUint(200), num.NewUint(100), types.RedemptionTypeFreeCashOnly, num.DecimalOne(), false)
partyToRedeemed, lateRedemptions = vault.PrepareRedemptions(time.Now(), map[string]num.Decimal{"p1": num.DecimalFromFloat(0.75), "p2": num.DecimalFromFloat(0.25)}, requests, num.NewUint(200), num.NewUint(100), types.RedemptionTypeAvailableFundsOnly, num.DecimalOne(), false)
require.Equal(t, 1, len(partyToRedeemed))
require.Equal(t, "75", partyToRedeemed["p1"].String())
require.Equal(t, 0, len(lateRedemptions))
Expand All @@ -735,7 +735,7 @@ func TestPrepareRedemptions(t *testing.T) {
{Party: "p1", Date: time.Time{}, Amount: num.NewUint(30), Remaining: num.NewUint(30), Status: types.RedeemStatusPending},
{Party: "p1", Date: time.Time{}, Amount: num.NewUint(10), Remaining: num.NewUint(10), Status: types.RedeemStatusPending},
}
partyToRedeemed, lateRedemptions = vault.PrepareRedemptions(time.Now(), map[string]num.Decimal{"p1": num.DecimalFromFloat(0.75), "p2": num.DecimalFromFloat(0.25)}, requests, num.NewUint(200), num.NewUint(100), types.RedemptionTypeFreeCashOnly, num.DecimalOne(), false)
partyToRedeemed, lateRedemptions = vault.PrepareRedemptions(time.Now(), map[string]num.Decimal{"p1": num.DecimalFromFloat(0.75), "p2": num.DecimalFromFloat(0.25)}, requests, num.NewUint(200), num.NewUint(100), types.RedemptionTypeAvailableFundsOnly, num.DecimalOne(), false)
require.Equal(t, 1, len(partyToRedeemed))
require.Equal(t, "75", partyToRedeemed["p1"].String())
require.Equal(t, 0, len(lateRedemptions))
Expand Down Expand Up @@ -905,9 +905,9 @@ func setupVault(t *testing.T) *testVault {
PerformanceFeeFactor: num.DecimalZero(),
CutOffPeriodLength: 3,
RedemptionDates: []*types.RedemptionDate{
{RedemptionType: types.RedemptionTypeFreeCashOnly, RedemptionDate: now.Add(3 * 24 * time.Hour), MaxFraction: num.DecimalFromFloat(0.1)},
{RedemptionType: types.RedemptionTypeAvailableFundsOnly, RedemptionDate: now.Add(3 * 24 * time.Hour), MaxFraction: num.DecimalFromFloat(0.1)},
{RedemptionType: types.RedemptionTypeNormal, RedemptionDate: now.Add(4 * 24 * time.Hour), MaxFraction: num.DecimalFromFloat(0.1)},
{RedemptionType: types.RedemptionTypeFreeCashOnly, RedemptionDate: now.Add(5 * 24 * time.Hour), MaxFraction: num.DecimalFromFloat(0.1)},
{RedemptionType: types.RedemptionTypeAvailableFundsOnly, RedemptionDate: now.Add(5 * 24 * time.Hour), MaxFraction: num.DecimalFromFloat(0.1)},
},
}, col, time.Now(), broker)
ctx := context.Background()
Expand Down
8 changes: 4 additions & 4 deletions datanode/gateway/graphql/models.go

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

6 changes: 3 additions & 3 deletions datanode/gateway/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -8043,7 +8043,7 @@ type RedemptionRequest {
lastUpdated: Timestamp
"The amount requested in the redemption request"
requestedAmount: String!
"The amount remaining to be redeemed on the request"
"The amount remaining to be redeemed from the request"
remainingAmount: String!
"The status of the redemption request"
status: RedeemStatus!
Expand Down Expand Up @@ -8108,8 +8108,8 @@ enum RedemptionType {
REDEMPTION_TYPE_UNSPECIFIED
"Normal - use full vault balance on this date to satisfy requests"
REDEMPTION_TYPE_NORMAL
"Free cash only - consider only general account on this date to satisfy redemptions"
REDEMPTION_TYPE_FREE_CASH_ONLY
"Available funds only - consider only general account on this date to satisfy redemptions"
REDEMPTION_TYPE_AVAILABLE_FUNDS_ONLY
}

type RedemptionDate {
Expand Down
2 changes: 1 addition & 1 deletion protos/data-node/api/v2/trading_data.pb.go

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

2 changes: 1 addition & 1 deletion protos/sources/data-node/api/v2/trading_data.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5102,7 +5102,7 @@ message RedemptionRequestConnection {
}

message RedemptionRequestEdge {
// vault data.
// Vault data.
vega.events.v1.RedemptionRequest node = 1;
// Cursor that can be used to fetch further pages.
string cursor = 2;
Expand Down
Loading

0 comments on commit e15a15d

Please sign in to comment.