-
Notifications
You must be signed in to change notification settings - Fork 502
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
Unified trades and offers processor #5545
Open
karthikiyer56
wants to merge
6
commits into
master
Choose a base branch
from
karthik/5543/unified-trade-offer-lp-processor
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
fd69ebc
sample test to test offer updates
karthikiyer56 acdf16e
Initial commit for generic trades processor
karthikiyer56 3b3bf8c
Helper functions for xdr.LedgerCloseMeta
karthikiyer56 b4cf033
scaffolding code for generic trade processor
karthikiyer56 e303f42
fix staticcheck
karthikiyer56 b8c1cee
All temp code
karthikiyer56 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
package trades | ||
|
||
import "github.com/stellar/go/xdr" | ||
|
||
type TradeEventType int | ||
|
||
const ( | ||
TradeEventTypeUnknown TradeEventType = iota // Default value | ||
TradeEventTypeOfferCreated // Offer created event | ||
TradeEventTypeOfferUpdated // Offer updated event | ||
TradeEventTypeOfferClosed // Offer closed event | ||
TradeEventTypeLiquidityPoolUpdated // Liquidity pool update event | ||
) | ||
|
||
type TradeEvent interface { | ||
GetTradeEventType() TradeEventType // Method to retrieve the type of the trade event | ||
} | ||
|
||
type OfferBase struct { | ||
Selling xdr.Asset // Asset being sold | ||
Buying xdr.Asset // Asset being bought | ||
Amount xdr.Int64 // Total amount of the selling asset | ||
Price xdr.Price // Price of the offer | ||
Flags uint32 // Flags for the offer (e.g., passive, sell offers) | ||
} | ||
|
||
type OfferCreatedEvent struct { | ||
SellerId xdr.AccountId // Account ID of the seller | ||
OfferId xdr.Int64 // ID of the created offer | ||
OfferState OfferBase // Initial state of the offer | ||
CreatedLedgerSeq uint32 // Ledger sequence where the offer was created | ||
Fills []FillInfo // List of fills that occurred during the creation | ||
} | ||
|
||
func (e OfferCreatedEvent) GetTradeEventType() TradeEventType { | ||
return TradeEventTypeOfferCreated | ||
} | ||
|
||
type OfferUpdatedEvent struct { | ||
SellerId xdr.AccountId // Account ID of the seller | ||
OfferId xdr.Int64 // ID of the updated offer | ||
PrevUpdatedLedgerSeq uint32 // Ledger sequence of the previous update | ||
PreviousOfferState OfferBase // Previous state of the offer | ||
UpdatedOfferState OfferBase // Updated state of the offer | ||
UpdatedLedgerSeq uint32 // Ledger sequence where the offer was updated | ||
Fills []FillInfo // List of fills that occurred during the update | ||
} | ||
|
||
func (e OfferUpdatedEvent) GetTradeEventType() TradeEventType { | ||
return TradeEventTypeOfferUpdated | ||
} | ||
|
||
type OfferClosedEvent struct { | ||
SellerId xdr.AccountId // Account ID of the seller | ||
OfferId xdr.Int64 // ID of the closed offer | ||
LastOfferState OfferBase // Last state of the offer before closing | ||
ClosedLedgerSeq uint32 // Ledger sequence where the offer was closed | ||
} | ||
|
||
func (e OfferClosedEvent) GetTradeEventType() TradeEventType { | ||
return TradeEventTypeOfferClosed | ||
} | ||
|
||
type LiquidityPoolUpdateEvent struct { | ||
Fills []FillInfo // List of fills for this liquidity pool update | ||
} | ||
|
||
func (e LiquidityPoolUpdateEvent) GetTradeEventType() TradeEventType { | ||
return TradeEventTypeLiquidityPoolUpdated | ||
} | ||
|
||
type FillSourceOperationType uint32 | ||
|
||
const ( | ||
FillSourceOperationTypeUnknown FillSourceOperationType = iota | ||
FillSourceOperationTypeManageBuy | ||
FillSourceOperationTypeManageSell | ||
FillSourceOperationTypePathPaymentStrictSend | ||
FillSourceOperationTypePathPaymentStrictReceive | ||
) | ||
|
||
type FillSource struct { | ||
// Type of the operation that caused this fill (ManageBuyOffer, ManageSellOffer, PathPaymentStrictSend, PathPaymentStrictReceive) | ||
SourceOperation FillSourceOperationType | ||
|
||
// The taker's information. Who caused this fill??? | ||
ManageOfferInfo *ManageOfferInfo // Details of a ManageBuy/ManageSell operation (optional) | ||
PathPaymentInfo *PathPaymentInfo // Details of a PathPayment operation (optional) | ||
} | ||
|
||
// ManageBuy/ManageSell operation details | ||
type ManageOfferInfo struct { | ||
// Account that initiated the operation. Source of operation or source of transaction | ||
SourceAccount xdr.AccountId | ||
|
||
// Did the taking operation create an offerId/offerEntry that rested after being partially filled OR Was it fully filled | ||
OfferFullyFilled bool | ||
|
||
OfferId *xdr.Int64 // Offer ID, if an offer entry was created (nil if fully filled) | ||
} | ||
|
||
type PathPaymentInfo struct { | ||
SourceAccount xdr.AccountId // Source account of the PathPayment | ||
DestinationAccount xdr.AccountId // Destination account of the PathPayment | ||
} | ||
|
||
type FillInfo struct { | ||
AssetSold xdr.Asset // Asset sold in this fill | ||
AmountSold xdr.Int64 // Amount of the asset sold in this fill | ||
AssetBought xdr.Asset // Asset bought in this fill | ||
AmountBought xdr.Int64 // Amount of the asset bought in this fill | ||
LedgerSeq uint32 // Ledger sequence in which the fill occurred | ||
|
||
FillSourceInfo FillSource // Details about what operation (and details) caused this fill | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no mention of sellerId or offerId
just amounts, price and flags.
The reason why I am not using
xdr.OfferEntry
struct for this is:It is not a given that an offer will ever create an entry (if it is fully filled)
this distinction helps in the
OfferUpdatedEvent
where I am capturing prev state and updated stateAnd also the fact that there is no offerId or sellerId