-
Notifications
You must be signed in to change notification settings - Fork 91
/
transfer.go
84 lines (80 loc) · 2.43 KB
/
transfer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package events
import (
v1 "github.com/dydxprotocol/v4-chain/protocol/indexer/protocol/v1"
satypes "github.com/dydxprotocol/v4-chain/protocol/x/subaccounts/types"
)
// NewTransferEvent creates a TransferEvent representing a transfer of an asset between a sender
// and recipient subaccount.
func NewTransferEvent(
senderSubaccountId satypes.SubaccountId,
recipientSubaccountId satypes.SubaccountId,
assetId uint32,
amount satypes.BaseQuantums,
) *TransferEventV1 {
indexerSenderSubaccountId := v1.SubaccountIdToIndexerSubaccountId(senderSubaccountId)
indexerRecipientSubaccountId := v1.SubaccountIdToIndexerSubaccountId(recipientSubaccountId)
return &TransferEventV1{
SenderSubaccountId: &indexerSenderSubaccountId,
RecipientSubaccountId: &indexerRecipientSubaccountId,
Sender: &SourceOfFunds{
Source: &SourceOfFunds_SubaccountId{
SubaccountId: &indexerSenderSubaccountId,
},
},
Recipient: &SourceOfFunds{
Source: &SourceOfFunds_SubaccountId{
SubaccountId: &indexerRecipientSubaccountId,
},
},
AssetId: assetId,
Amount: amount.ToUint64(),
}
}
// NewDepositEvent creates a DepositEvent representing a deposit of an asset from a sender
// wallet address to a recipient subaccount.
func NewDepositEvent(
senderAddress string,
recipientSubaccountId satypes.SubaccountId,
assetId uint32,
amount satypes.BaseQuantums,
) *TransferEventV1 {
indexerRecipientSubaccountId := v1.SubaccountIdToIndexerSubaccountId(recipientSubaccountId)
return &TransferEventV1{
AssetId: assetId,
Amount: amount.ToUint64(),
Sender: &SourceOfFunds{
Source: &SourceOfFunds_Address{
Address: senderAddress,
},
},
Recipient: &SourceOfFunds{
Source: &SourceOfFunds_SubaccountId{
SubaccountId: &indexerRecipientSubaccountId,
},
},
}
}
// NewWithdrawEvent creates a WithdrawEvent representing a withdrawal of an asset from a sender
// subaccount to a recipient wallet address.
func NewWithdrawEvent(
senderSubaccountId satypes.SubaccountId,
recipientAddress string,
assetId uint32,
amount satypes.BaseQuantums,
) *TransferEventV1 {
indexerSenderSubaccountId := v1.SubaccountIdToIndexerSubaccountId(senderSubaccountId)
return &TransferEventV1{
AssetId: assetId,
Amount: amount.ToUint64(),
Sender: &SourceOfFunds{
Source: &SourceOfFunds_SubaccountId{
SubaccountId: &indexerSenderSubaccountId,
},
},
Recipient: &SourceOfFunds{
Source: &SourceOfFunds_Address{
Address: recipientAddress,
},
},
}
}