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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
use anchor_lang::prelude::*;
use pyth_client::PythError;

#[error_code]
pub enum DFlowError {
    BidDidNotExceedBest = 9000,
    RetailOrderQueueFull = 9001,
    MarketMakerOrderQueueFull = 9002,
    _MessageNotSignedByRetailTrader = 9003, // TODO: used when ED25519 verification is ready
    _NoDesignatedMarketMakerAvailable = 9004,
    _OrdersRequestedExceedsMax = 9005,
    OverFill = 9006,
    InvalidFillPrice = 9007,
    InvalidAuctionSpecified = 9008,
    PriceOracleNotTrading = 9009,
    InvalidVaultMetaVecMismatch = 9010,
    OrderDetailsParsingError = 9011,
    InvalidFillAmount = 9012,
    InvalidMinFillPrice = 9013,
    AuctionEpochInitInvalidOwner = 9014,
    NotAllRewardsDistributed = 9015,
    FillVotingHitMax = 9016,
    InvalidAuctionEpoch = 9017,
    InvalidFillVoteValue = 9018,
    VotingClosed = 9019,
    VoteRewardClaimingClosed = 9020,
    OverflowError = 9021,
    AuctionNotTakingOrders = 9022,
    InvalidOrderType = 9023,
    InvalidMarketMakerAccountAddress = 9024,
    AuctionIdAlreadyExists = 9025,
    InvalidNewOrderEpoch = 9026,
    InvalidYMint = 9027,
    OrderNotInRetailQueue = 9028,
    OrderNotInMarketMakerQueue = 9029,
    InvalidAuctionStatus = 9030,
    AuctionIsHalted = 9031,
    InvalidAuctionInit = 9032,
    InvalidXMint = 9033,
    InvalidOracles = 9034,
    UnableToFindMarketPrice = 9035,
    UnableToIdentifyCurrencyPair = 9036,
    MintDecimalsTooLarge = 9037,
    MintCaptureListEmpty = 9038,
    MintCaptureListSizeMismatch = 9039,
    QuoteCurrencyConversionOverflow = 9040,
    InvalidPriceOraclesPassed = 9041,
    OracleCaptureListEmpty = 9042,
    OracleForXMintNotFound = 9043,
    PythInvalidAccountData = 9044,
    PythBadVersionNumber = 9045,
    PythWrongAccountType = 9046,
    OtherPythError = 9047,
    InvalidNextAuctionEpoch = 9048,
    ArbiterDoesNotDeserveReward = 9049,

    /// Notional size outside of auction specification
    InvalidNotionalSize = 9050,
    UnexpectedBufferSize = 9051,
    Ed25519InstructionNotIncluded = 9052,
    Ed25519InstructionInvalidSigCount = 9053,
    Ed25519InstructionInvalidSigOffset = 9054,
    Ed25519InstructionInvalidSigIndex = 9055,
    Ed25519InstructionInvalidSig = 9056,
    Ed25519InstructionInvalidPubKeyOffset = 9057,
    Ed25519InstructionInvalidPubKeyIndex = 9058,
    Ed25519InstructionInvalidPubKey = 9059,
    Ed25519InstructionInvalidMsgOffset = 9060,
    Ed25519InstructionInvalidMsgIndex = 9061,
    Ed25519InstructionInvalidMsg = 9062,
    InvalidMarketMakerEncryptionPubKey = 9063,
    InvalidRebateReceiverTokenAccount = 9064,
    InvalidMarketMaker = 9065,

    InvalidRetailYTokenAccount = 9067,
    FillNotYetCloseable = 9068,
    NoAuctionWinner = 9069,

    /// CloseFillAccounts
    InvalidMarketMakerXTokenAccount = 9070,
    InvalidMarketMakerAccountOwner = 9071,
    InvalidBidRecoveryVaultAccountAddress = 9072,
    InvalidBidRecoveryVaultAccountNotWritable = 9073,
    InvalidXRecoveryVaultAccountAddress = 9074,
    InvalidXRecoveryVaultAccountNotWritable = 9075,
    InvalidCloseFillRemainingAccounts = 9076,
    InvalidCloseFillRetailDataAccount = 9077,

    /// CloseRetailDataAccount
    InvalidCloseRetailDataAccountOpenOrders = 9080,
    InvalidCloseRetailDataAccountUnsettledFills = 9081,
    InvalidCloseRetailDataAccountWrongOwner = 9082,

    /// CloseAuctionEpochState
    InvalidCloseAuctionEpochStateOpenOrders = 9090,
    InvalidCloseAuctionEpochStateUnsettledFills = 9091,
    InvalidCloseAuctionEpochStateAuctionActive = 9092,
    InvalidCloseAuctionEpochStateOwner = 9093,

    NotReclaimableByCurrentLeader = 9100,
    NotReclaimableInvalidMarketMakerOwner = 9101,
    InvalidAuctionStatusChange = 9102,

    InvalidYRecoveryVaultAccountAddress = 9110,
    InvalidYRecoveryVaultAccountNotWritable = 9111,
    InvalidFillOrderRemainingAccounts = 9112,

    /// Signatory
    InvalidEndorsement = 9200,
    InsufficientSignatoryStake = 9201,

    /// Access control
    InvalidDFlowAdmin = 9300,
    InvalidWhitelistEntryType = 9301,
    AlreadyWhitelisted = 9302,
    NotWhitelisted = 9303,
    InvalidAuctionOwner = 9304,

    InvalidVotePeriod = 9800,
    InvalidClaimPeriod = 9801,
    NegativeClockUnixTimestamp = 9802,

    /// A DFlow program invariant was violated
    DFlowInvariantViolated = 9999,
}

impl From<PythError> for DFlowError {
    fn from(code: PythError) -> DFlowError {
        match code {
            PythError::BadVersionNumber => DFlowError::PythBadVersionNumber,
            PythError::InvalidAccountData => DFlowError::PythInvalidAccountData,
            PythError::WrongAccountType => DFlowError::PythWrongAccountType
        }
    }
}