diff --git a/core/collateral/engine.go b/core/collateral/engine.go index 31a943b6a7..8aac500128 100644 --- a/core/collateral/engine.go +++ b/core/collateral/engine.go @@ -2832,6 +2832,17 @@ func (e *Engine) getTransferFundsTransferRequest(ctx context.Context, t *types.T // we always pay onto the pending transfers accounts toAcc = e.GetPendingTransfersAccount(t.Amount.Asset) + case types.AccountTypeLockedForStaking: + fromAcc, err = e.GetPartyLockedForStaking(t.Owner, t.Amount.Asset) + if err != nil { + return nil, fmt.Errorf("account does not exists: %v, %v, %v", + accountType, t.Owner, t.Amount.Asset, + ) + } + + // we always pay onto the pending transfers accounts + toAcc = e.GetPendingTransfersAccount(t.Amount.Asset) + case types.AccountTypeVestedRewards: fromAcc = e.GetOrCreatePartyVestedRewardAccount(ctx, t.Owner, t.Amount.Asset) // we always pay onto the pending transfers accounts @@ -2861,6 +2872,21 @@ func (e *Engine) getTransferFundsTransferRequest(ctx context.Context, t *types.T } } + case types.AccountTypeLockedForStaking: + toAcc, err = e.GetPartyLockedForStaking(t.Owner, t.Amount.Asset) + if err != nil { + // account does not exists, let's just create it + id, err := e.CreatePartyLockedForStakingAccount(ctx, t.Owner, t.Amount.Asset) + if err != nil { + return nil, err + } + toAcc, err = e.GetAccountByID(id) + if err != nil { + // shouldn't happen, we just created it... + return nil, err + } + } + // this could not exists as well, let's just create in this case case types.AccountTypeGlobalReward, types.AccountTypeLPFeeReward, types.AccountTypeMakerReceivedFeeReward, types.AccountTypeNetworkTreasury, types.AccountTypeMakerPaidFeeReward, types.AccountTypeMarketProposerReward, types.AccountTypeAverageNotionalReward, @@ -2918,6 +2944,13 @@ func (e *Engine) getTransferFundsFeesTransferRequest(ctx context.Context, t *typ accountType, t.Owner, t.Amount.Asset, ) } + case types.AccountTypeLockedForStaking: + fromAcc, err = e.GetPartyLockedForStaking(t.Owner, t.Amount.Asset) + if err != nil { + return nil, fmt.Errorf("account does not exists: %v, %v, %v", + accountType, t.Owner, t.Amount.Asset, + ) + } case types.AccountTypeVestedRewards: fromAcc = e.GetOrCreatePartyVestedRewardAccount(ctx, t.Owner, t.Amount.Asset) @@ -4137,6 +4170,32 @@ func (e *Engine) CreatePartyGeneralAccount(ctx context.Context, partyID, asset s return generalID, nil } +// CreatePartyLockedForStakingAccount create the general account for a party. +func (e *Engine) CreatePartyLockedForStakingAccount(ctx context.Context, partyID, asset string) (string, error) { + if !e.AssetExists(asset) { + return "", ErrInvalidAssetID + } + + lockedForStakingID := e.accountID(noMarket, partyID, asset, types.AccountTypeLockedForStaking) + if _, ok := e.accs[lockedForStakingID]; !ok { + acc := types.Account{ + ID: lockedForStakingID, + Asset: asset, + MarketID: noMarket, + Balance: num.UintZero(), + Owner: partyID, + Type: types.AccountTypeLockedForStaking, + } + e.accs[lockedForStakingID] = &acc + e.addPartyAccount(partyID, lockedForStakingID, &acc) + e.addAccountToHashableSlice(&acc) + e.broker.Send(events.NewPartyEvent(ctx, types.Party{Id: partyID})) + e.broker.Send(events.NewAccountEvent(ctx, acc)) + } + + return lockedForStakingID, nil +} + // GetOrCreatePartyVestingRewardAccount create the general account for a party. func (e *Engine) GetOrCreatePartyVestingRewardAccount(ctx context.Context, partyID, asset string) *types.Account { if !e.AssetExists(asset) {