Skip to content

Commit 9a5fdf8

Browse files
committed
feat: vault account
1 parent e2230d9 commit 9a5fdf8

File tree

86 files changed

+12499
-5843
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+12499
-5843
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@
3232
- [11685](https://github.com/vegaprotocol/vega/issues/11685) - Automated purchase support added.
3333
- [11726](https://github.com/vegaprotocol/vega/issues/11726) - Combined `AMM` uncrossing orders for better performance when uncrossing the book.
3434
- [11711](https://github.com/vegaprotocol/vega/issues/11711) - Manage closed team membership by updating the allow list.
35-
- [11722](https://github.com/vegaprotocol/vega/issues/11722) - Expose active protocol automated purchase identifier in market data API.
35+
- [11722](https://github.com/vegaprotocol/vega/issues/11722) - Expose active protocol automated purchase identifier in market data API.
3636
- [11744](https://github.com/vegaprotocol/vega/issues/11744) - Staking from collateral bridged assets.
37+
- [11745](https://github.com/vegaprotocol/vega/issues/11745) - Implement vault accounts
3738

3839
### 🐛 Fixes
3940

commands/amend_amm.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ func checkAmendAMM(cmd *commandspb.AmendAMM) Errors {
4848
errs.AddForProperty("amend_amm.slippage_tolerance", ErrMustBeBetween01)
4949
}
5050

51+
if cmd.VaultId != nil && !IsVegaID(*cmd.VaultId) {
52+
errs.AddForProperty("amend_amm.vault_id", ErrInvalidVaultID)
53+
}
54+
5155
var hasUpdate bool
5256

5357
if cmd.CommitmentAmount != nil {

commands/amend_amm_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
)
2828

2929
func TestCheckAmendAMM(t *testing.T) {
30+
banana := "banana"
3031
cases := []struct {
3132
submission commandspb.AmendAMM
3233
errStr string
@@ -270,6 +271,14 @@ func TestCheckAmendAMM(t *testing.T) {
270271
},
271272
errStr: "* (no updates provided)",
272273
},
274+
{
275+
submission: commandspb.AmendAMM{
276+
MarketId: "e9982447fb4128f9968f9981612c5ea85d19b62058ec2636efc812dcbbc745ca",
277+
SlippageTolerance: "0.09",
278+
VaultId: &banana,
279+
},
280+
errStr: "amend_amm.vault_id (is not a valid vault identifier)",
281+
},
273282
{
274283
submission: commandspb.AmendAMM{
275284
MarketId: "e9982447fb4128f9968f9981612c5ea85d19b62058ec2636efc812dcbbc745ca",

commands/cancel_amm.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ func checkCancelAMM(cmd *commandspb.CancelAMM) Errors {
3636
errs.AddForProperty("cancel_amm.market_id", ErrShouldBeAValidVegaID)
3737
}
3838

39+
if cmd.VaultId != nil && !IsVegaID(*cmd.VaultId) {
40+
errs.AddForProperty("cancel_amm.vault_id", ErrInvalidVaultID)
41+
}
42+
3943
if cmd.Method == commandspb.CancelAMM_METHOD_UNSPECIFIED {
4044
errs.AddForProperty("cancel_amm.method", ErrIsRequired)
4145
}

commands/cancel_amm_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
)
2727

2828
func TestCheckCancelAMM(t *testing.T) {
29+
banana := "banana"
2930
cases := []struct {
3031
submission commandspb.CancelAMM
3132
errStr string
@@ -61,6 +62,14 @@ func TestCheckCancelAMM(t *testing.T) {
6162
},
6263
errStr: "cancel_amm.method (is not a valid value)",
6364
},
65+
{
66+
submission: commandspb.CancelAMM{
67+
MarketId: "e9982447fb4128f9968f9981612c5ea85d19b62058ec2636efc812dcbbc745ca",
68+
Method: commandspb.CancelAMM_Method(999),
69+
VaultId: &banana,
70+
},
71+
errStr: "cancel_amm.vault_id (is not a valid vault identifier)",
72+
},
6473
}
6574

6675
for n, c := range cases {

commands/errors.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ var (
9797
ErrMustBeAtMost250 = errors.New("must be at most 250")
9898
ErrNoUpdatesProvided = errors.New("no updates provided")
9999
ErrMaxPriceMustRespectTickSize = errors.New("must respect tick size")
100+
ErrInvalidVaultID = errors.New("is not a valid vault identifier")
100101
)
101102

102103
type Errors map[string][]error

commands/liquidity_provision_submission.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ func checkLiquidityProvisionSubmission(cmd *commandspb.LiquidityProvisionSubmiss
5555
errs.AddForProperty("liquidity_provision_submission.reference", ErrReferenceTooLong)
5656
}
5757

58+
if cmd.VaultId != nil && !IsVegaID(*cmd.VaultId) {
59+
errs.AddForProperty("liquidity_provision_submission.vault_id", ErrInvalidVaultID)
60+
}
61+
5862
// if the commitment amount is 0, then the command should be interpreted as
5963
// a cancellation of the liquidity provision. As a result, the validation
6064
// shouldn't be made on the rest of the field.

commands/liquidity_provision_submission_test.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ func TestNilLiquidityProvisionSubmissionFails(t *testing.T) {
3232
}
3333

3434
func TestLiquidityProvisionSubmission(t *testing.T) {
35+
banana := "banana"
3536
cases := []struct {
3637
lp commandspb.LiquidityProvisionSubmission
3738
errString string
@@ -67,7 +68,15 @@ func TestLiquidityProvisionSubmission(t *testing.T) {
6768
},
6869
errString: "liquidity_provision_submission.market_id (is required)",
6970
},
70-
71+
{
72+
lp: commandspb.LiquidityProvisionSubmission{
73+
CommitmentAmount: "100",
74+
MarketId: "08dce6ebf50e34fedee32860b6f459824e4b834762ea66a96504fdc57a9c4741",
75+
Fee: "0.1",
76+
VaultId: &banana,
77+
},
78+
errString: "liquidity_provision_submission.vault_id (is not a valid vault identifier)",
79+
},
7180
{
7281
lp: commandspb.LiquidityProvisionSubmission{
7382
CommitmentAmount: "100",

commands/order_amendment.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ func checkOrderAmendment(cmd *commandspb.OrderAmendment) Errors {
123123
}
124124
}
125125

126+
if cmd.VaultId != nil && !IsVegaID(*cmd.VaultId) {
127+
errs.AddForProperty("order_amendment.vault_id", ErrInvalidVaultID)
128+
}
129+
126130
if !isAmending {
127131
errs.Add(errors.New("order_amendment does not amend anything"))
128132
}

commands/order_amendment_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ func TestCheckOrderAmendment(t *testing.T) {
4545
t.Run("amend order tif to GFA - fail", testAmendOrderToGFA)
4646
t.Run("amend order tif to GFN - fail", testAmendOrderToGFN)
4747
t.Run("amend order pegged_offset", testAmendOrderPeggedOffset)
48+
t.Run("amend order on bahalf of a vault with invalid id", testAmendInvalidVaultID)
4849
}
4950

5051
func testNilOrderAmendmentFails(t *testing.T) {
@@ -214,6 +215,18 @@ func testAmendOrderToGFN(t *testing.T) {
214215
assert.Error(t, err)
215216
}
216217

218+
func testAmendInvalidVaultID(t *testing.T) {
219+
banana := "banana"
220+
arg := &commandspb.OrderAmendment{
221+
OrderId: "08dce6ebf50e34fedee32860b6f459824e4b834762ea66a96504fdc57a9c4741",
222+
MarketId: "08dce6ebf50e34fedee32860b6f459824e4b834762ea66a96504fdc57a9c4741",
223+
SizeDelta: 100,
224+
VaultId: &banana,
225+
}
226+
err := checkOrderAmendment(arg)
227+
assert.Equal(t, "order_amendment.vault_id (is not a valid vault identifier)", err.Error())
228+
}
229+
217230
func testAmendOrderToGFA(t *testing.T) {
218231
arg := &commandspb.OrderAmendment{
219232
OrderId: "08dce6ebf50e34fedee32860b6f459824e4b834762ea66a96504fdc57a9c4741",

commands/order_cancellation.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,8 @@ func checkOrderCancellation(cmd *commandspb.OrderCancellation) Errors {
3838
errs.AddForProperty("order_cancellation.order_id", ErrShouldBeAValidVegaID)
3939
}
4040

41+
if cmd.VaultId != nil && !IsVegaID(*cmd.VaultId) {
42+
errs.AddForProperty("order_cancellation.vault_id", ErrInvalidVaultID)
43+
}
4144
return errs
4245
}

commands/order_submission.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ func checkOrderSubmission(cmd *commandspb.OrderSubmission) Errors {
146146
}
147147
}
148148

149+
if cmd.VaultId != nil && !IsVegaID(*cmd.VaultId) {
150+
errs.AddForProperty("order_submission.vault_id", ErrInvalidVaultID)
151+
}
152+
149153
if cmd.PeggedOrder != nil {
150154
if cmd.PeggedOrder.Reference == types.PeggedReference_PEGGED_REFERENCE_UNSPECIFIED {
151155
errs.AddForProperty("order_submission.pegged_order.reference", ErrIsRequired)

commands/order_submission_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"testing"
2222

2323
"code.vegaprotocol.io/vega/commands"
24+
"code.vegaprotocol.io/vega/libs/crypto"
2425
"code.vegaprotocol.io/vega/libs/test"
2526
types "code.vegaprotocol.io/vega/protos/vega"
2627
commandspb "code.vegaprotocol.io/vega/protos/vega/commands/v1"
@@ -775,6 +776,21 @@ func testPeggedOrderSubmissionWithSideSellAndMidReferenceAndPositiveOffsetSuccee
775776
assert.NotContains(t, err.Get("order_submission.pegged_order.offset"), errors.New("must be positive"))
776777
}
777778

779+
func TestOrderSubmissionWithInvalidVaultIDFails(t *testing.T) {
780+
banana := "banana"
781+
err := checkOrderSubmission(&commandspb.OrderSubmission{
782+
MarketId: crypto.RandomHash(),
783+
Price: "100",
784+
Size: 100,
785+
TimeInForce: types.Order_TIME_IN_FORCE_FOK,
786+
Side: types.Side_SIDE_SELL,
787+
Type: types.Order_TYPE_LIMIT,
788+
VaultId: &banana,
789+
})
790+
791+
assert.Equal(t, "order_submission.vault_id (is not a valid vault identifier)", err.Error())
792+
}
793+
778794
func checkOrderSubmission(cmd *commandspb.OrderSubmission) commands.Errors {
779795
err := commands.CheckOrderSubmission(cmd)
780796

commands/stop_orders_cancellation.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,9 @@ func checkStopOrdersCancellation(cmd *commandspb.StopOrdersCancellation) Errors
3838
errs.AddForProperty("stop_orders_cancellation.stop_order_id", ErrShouldBeAValidVegaID)
3939
}
4040

41+
if cmd.VaultId != nil && !IsVegaID(*cmd.VaultId) {
42+
errs.AddForProperty("stop_orders_cancellation.vault_id", ErrInvalidVaultID)
43+
}
44+
4145
return errs
4246
}

commands/stop_orders_submission.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ func checkStopOrdersSubmission(cmd *commandspb.StopOrdersSubmission) Errors {
4141
"stop_orders_submission.falls_below", errs, cmd.FallsBelow, cmd.RisesAbove != nil)
4242
if cmd.FallsBelow.OrderSubmission != nil {
4343
market1 = cmd.FallsBelow.OrderSubmission.MarketId
44+
if cmd.FallsBelow.OrderSubmission.VaultId != nil && !IsVegaID(*cmd.FallsBelow.OrderSubmission.VaultId) {
45+
errs.AddForProperty("stop_orders_submission.falls_below.vault_id", ErrInvalidVaultID)
46+
}
4447
if cmd.FallsBelow.SizeOverrideSetting != nil {
4548
if *cmd.FallsBelow.SizeOverrideSetting == types.StopOrder_SIZE_OVERRIDE_SETTING_POSITION {
4649
if cmd.FallsBelow.SizeOverrideValue != nil {
@@ -66,6 +69,9 @@ func checkStopOrdersSubmission(cmd *commandspb.StopOrdersSubmission) Errors {
6669
checkStopOrderSetup(
6770
"stop_orders_submission.rises_below", errs, cmd.RisesAbove, cmd.FallsBelow != nil)
6871
if cmd.RisesAbove.OrderSubmission != nil {
72+
if cmd.RisesAbove.OrderSubmission.VaultId != nil && !IsVegaID(*cmd.RisesAbove.OrderSubmission.VaultId) {
73+
errs.AddForProperty("stop_orders_submission.rises_above.vault_id", ErrInvalidVaultID)
74+
}
6975
market2 = cmd.RisesAbove.OrderSubmission.MarketId
7076
if cmd.RisesAbove.SizeOverrideSetting != nil {
7177
if *cmd.RisesAbove.SizeOverrideSetting == types.StopOrder_SIZE_OVERRIDE_SETTING_POSITION {

commands/submit_amm.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,5 +157,9 @@ func checkSubmitAMM(cmd *commandspb.SubmitAMM) Errors {
157157
}
158158
}
159159

160+
if cmd.VaultId != nil && !IsVegaID(*cmd.VaultId) {
161+
errs.AddForProperty("submit_amm.vault_id", ErrInvalidVaultID)
162+
}
163+
160164
return errs
161165
}

commands/submit_amm_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
)
2828

2929
func TestCheckSubmitAMM(t *testing.T) {
30+
banana := "banana"
3031
cases := []struct {
3132
submission commandspb.SubmitAMM
3233
errStr string
@@ -300,6 +301,23 @@ func TestCheckSubmitAMM(t *testing.T) {
300301
},
301302
errStr: "submit_amm.concentrated_liquidity_parameters.lower_bound (lower_bound and upper_bound cannot both be empty)",
302303
},
304+
{
305+
submission: commandspb.SubmitAMM{
306+
MarketId: "e9982447fb4128f9968f9981612c5ea85d19b62058ec2636efc812dcbbc745ca",
307+
SlippageTolerance: "0.09",
308+
CommitmentAmount: "10000",
309+
ProposedFee: "0.03",
310+
ConcentratedLiquidityParameters: &commandspb.SubmitAMM_ConcentratedLiquidityParameters{
311+
Base: "20000",
312+
UpperBound: ptr.From("30000"),
313+
LowerBound: ptr.From("10000"),
314+
LeverageAtUpperBound: ptr.From("0.1"),
315+
LeverageAtLowerBound: ptr.From("0.1"),
316+
},
317+
VaultId: &banana,
318+
},
319+
errStr: "submit_amm.vault_id (is not a valid vault identifier)",
320+
},
303321
{
304322
submission: commandspb.SubmitAMM{
305323
MarketId: "e9982447fb4128f9968f9981612c5ea85d19b62058ec2636efc812dcbbc745ca",

commands/transaction.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,16 @@ func CheckInputData(rawInputData []byte) (*commandspb.InputData, Errors) {
264264
errs.Merge(checkAmendAMM(cmd.AmendAmm))
265265
case *commandspb.InputData_CancelAmm:
266266
errs.Merge(checkCancelAMM(cmd.CancelAmm))
267+
case *commandspb.InputData_CreateVault:
268+
errs.Merge(checkCreateVault(cmd.CreateVault))
269+
case *commandspb.InputData_UpdateVault:
270+
errs.Merge(checkUpdateVault(cmd.UpdateVault))
271+
case *commandspb.InputData_DepositToVault:
272+
errs.Merge(checkDepositToVault(cmd.DepositToVault))
273+
case *commandspb.InputData_WithdrawFromVault:
274+
errs.Merge(checkWithdrawFromVault(cmd.WithdrawFromVault))
275+
case *commandspb.InputData_ChangeVaultOwnership:
276+
errs.Merge(checkChangeVaultOwnership(cmd.ChangeVaultOwnership))
267277
case *commandspb.InputData_DelayedTransactionsWrapper:
268278
break
269279
default:

commands/update_margin_mode.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,9 @@ func checkUpdateMarginMode(cmd *commandspb.UpdateMarginMode) Errors {
6060
errs.AddForProperty("update_margin_mode.market_id", ErrIsRequired)
6161
}
6262

63+
if cmd.VaultId != nil && !IsVegaID(*cmd.VaultId) {
64+
errs.AddForProperty("update_margin_mode.vault_id", ErrInvalidVaultID)
65+
}
66+
6367
return errs
6468
}

commands/update_margin_mode_test.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828

2929
func TestUpdateMarginMode(t *testing.T) {
3030
positiveMarginFactor := "123"
31-
invalidNumderMarginFactor := "banana"
31+
banana := "banana"
3232
invalidDecimalMarginFactor := "1.2.3"
3333
negativeMarginFactor := "-0.2"
3434
zeroMarginFactor := "0"
@@ -77,7 +77,7 @@ func TestUpdateMarginMode(t *testing.T) {
7777
"cross margin mode with invalid number as margin factor 1",
7878
&commandspb.UpdateMarginMode{
7979
Mode: commandspb.UpdateMarginMode_MODE_ISOLATED_MARGIN,
80-
MarginFactor: &invalidNumderMarginFactor,
80+
MarginFactor: &banana,
8181
},
8282
"update_margin_mode.margin_factor",
8383
commands.ErrIsNotValidNumber,
@@ -128,6 +128,17 @@ func TestUpdateMarginMode(t *testing.T) {
128128
"update_margin_mode.market_id",
129129
commands.ErrIsRequired,
130130
},
131+
{
132+
"invalid vault ID",
133+
&commandspb.UpdateMarginMode{
134+
Mode: commandspb.UpdateMarginMode_MODE_ISOLATED_MARGIN,
135+
MarginFactor: &validMarginFactor1,
136+
MarketId: "123",
137+
VaultId: &banana,
138+
},
139+
"update_margin_mode.vault_id",
140+
commands.ErrInvalidVaultID,
141+
},
131142
{
132143
"valid cross margin update",
133144
&commandspb.UpdateMarginMode{

0 commit comments

Comments
 (0)