@zemyth/raise-sdk 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/README.md +416 -0
  2. package/dist/accounts/index.cjs +258 -0
  3. package/dist/accounts/index.cjs.map +1 -0
  4. package/dist/accounts/index.d.cts +115 -0
  5. package/dist/accounts/index.d.ts +115 -0
  6. package/dist/accounts/index.js +245 -0
  7. package/dist/accounts/index.js.map +1 -0
  8. package/dist/constants/index.cjs +174 -0
  9. package/dist/constants/index.cjs.map +1 -0
  10. package/dist/constants/index.d.cts +143 -0
  11. package/dist/constants/index.d.ts +143 -0
  12. package/dist/constants/index.js +158 -0
  13. package/dist/constants/index.js.map +1 -0
  14. package/dist/errors/index.cjs +177 -0
  15. package/dist/errors/index.cjs.map +1 -0
  16. package/dist/errors/index.d.cts +83 -0
  17. package/dist/errors/index.d.ts +83 -0
  18. package/dist/errors/index.js +170 -0
  19. package/dist/errors/index.js.map +1 -0
  20. package/dist/index.cjs +2063 -0
  21. package/dist/index.cjs.map +1 -0
  22. package/dist/index.d.cts +680 -0
  23. package/dist/index.d.ts +680 -0
  24. package/dist/index.js +1926 -0
  25. package/dist/index.js.map +1 -0
  26. package/dist/instructions/index.cjs +852 -0
  27. package/dist/instructions/index.cjs.map +1 -0
  28. package/dist/instructions/index.d.cts +452 -0
  29. package/dist/instructions/index.d.ts +452 -0
  30. package/dist/instructions/index.js +809 -0
  31. package/dist/instructions/index.js.map +1 -0
  32. package/dist/pdas/index.cjs +241 -0
  33. package/dist/pdas/index.cjs.map +1 -0
  34. package/dist/pdas/index.d.cts +171 -0
  35. package/dist/pdas/index.d.ts +171 -0
  36. package/dist/pdas/index.js +217 -0
  37. package/dist/pdas/index.js.map +1 -0
  38. package/dist/types/index.cjs +44 -0
  39. package/dist/types/index.cjs.map +1 -0
  40. package/dist/types/index.d.cts +229 -0
  41. package/dist/types/index.d.ts +229 -0
  42. package/dist/types/index.js +39 -0
  43. package/dist/types/index.js.map +1 -0
  44. package/package.json +130 -0
  45. package/src/accounts/index.ts +329 -0
  46. package/src/client.ts +715 -0
  47. package/src/constants/index.ts +205 -0
  48. package/src/errors/index.ts +222 -0
  49. package/src/events/index.ts +256 -0
  50. package/src/index.ts +253 -0
  51. package/src/instructions/index.ts +1504 -0
  52. package/src/pdas/index.ts +404 -0
  53. package/src/types/index.ts +267 -0
  54. package/src/utils/index.ts +277 -0
@@ -0,0 +1,177 @@
1
+ 'use strict';
2
+
3
+ var anchor = require('@coral-xyz/anchor');
4
+
5
+ // src/errors/index.ts
6
+ var ERROR_CODES = {
7
+ // State Transition Errors (6000-6099)
8
+ InvalidStateTransition: 6e3,
9
+ ProjectNotInOpenState: 6001,
10
+ ProjectNotInProgress: 6002,
11
+ MilestoneNotUnderReview: 6003,
12
+ VotingPeriodEnded: 6004,
13
+ VotingPeriodNotEnded: 6005,
14
+ MilestoneNotPassed: 6006,
15
+ MilestoneAlreadyUnlocked: 6007,
16
+ ProjectAlreadyFunded: 6008,
17
+ ProjectNotFunded: 6009,
18
+ // Authorization Errors (6100-6199)
19
+ UnauthorizedFounder: 6100,
20
+ UnauthorizedAdmin: 6101,
21
+ NotInvestor: 6102,
22
+ AlreadyVoted: 6103,
23
+ // Investment Errors (6200-6299)
24
+ InvestmentBelowMinimum: 6200,
25
+ FundingGoalExceeded: 6201,
26
+ InvalidTier: 6202,
27
+ CoolingOffPeriodActive: 6203,
28
+ CoolingOffPeriodExpired: 6204,
29
+ // Milestone Errors (6300-6399)
30
+ InvalidMilestoneIndex: 6300,
31
+ MilestonePercentageInvalid: 6301,
32
+ TotalPercentageExceeded: 6302,
33
+ MilestoneNotInProgress: 6303,
34
+ MilestoneNotApproved: 6304,
35
+ // TGE Errors (6400-6499)
36
+ TgeDateNotSet: 6400,
37
+ TgeDateAlreadySet: 6401,
38
+ TgeDateTooSoon: 6402,
39
+ TgeDateTooLate: 6403,
40
+ TgeNotReached: 6404,
41
+ TokensAlreadyClaimed: 6405,
42
+ InsufficientTokensDeposited: 6406,
43
+ // Pivot Errors (6500-6599)
44
+ PivotAlreadyProposed: 6500,
45
+ NoPivotProposed: 6501,
46
+ PivotNotApproved: 6502,
47
+ PivotWindowNotEnded: 6503,
48
+ PivotWindowEnded: 6504,
49
+ AlreadyWithdrawnFromPivot: 6505,
50
+ // Refund Errors (6800-6899)
51
+ RefundAlreadyClaimed: 6800,
52
+ RefundNotAvailable: 6801,
53
+ ProjectNotAbandoned: 6802,
54
+ // Scam Errors (6900-6999)
55
+ ScamReportPeriodEnded: 6900,
56
+ ScamAlreadyReported: 6901,
57
+ ScamNotConfirmed: 6902,
58
+ HoldbackAlreadyReleased: 6903,
59
+ HoldbackPeriodNotEnded: 6904
60
+ };
61
+ var ERROR_MESSAGES = {
62
+ // State Transition Errors
63
+ [ERROR_CODES.InvalidStateTransition]: "Invalid project state transition",
64
+ [ERROR_CODES.ProjectNotInOpenState]: "Project must be in Open state to accept investments",
65
+ [ERROR_CODES.ProjectNotInProgress]: "Project must be InProgress to perform this action",
66
+ [ERROR_CODES.MilestoneNotUnderReview]: "Milestone must be under review to vote",
67
+ [ERROR_CODES.VotingPeriodEnded]: "Voting period has ended",
68
+ [ERROR_CODES.VotingPeriodNotEnded]: "Voting period has not ended yet",
69
+ [ERROR_CODES.MilestoneNotPassed]: "Milestone did not pass voting",
70
+ [ERROR_CODES.MilestoneAlreadyUnlocked]: "Milestone funds already unlocked",
71
+ [ERROR_CODES.ProjectAlreadyFunded]: "Project has already reached funding goal",
72
+ [ERROR_CODES.ProjectNotFunded]: "Project has not reached funding goal",
73
+ // Authorization Errors
74
+ [ERROR_CODES.UnauthorizedFounder]: "Only the project founder can perform this action",
75
+ [ERROR_CODES.UnauthorizedAdmin]: "Only the admin can perform this action",
76
+ [ERROR_CODES.NotInvestor]: "You must be an investor to perform this action",
77
+ [ERROR_CODES.AlreadyVoted]: "You have already voted on this",
78
+ // Investment Errors
79
+ [ERROR_CODES.InvestmentBelowMinimum]: "Investment amount below minimum tier requirement",
80
+ [ERROR_CODES.FundingGoalExceeded]: "Investment would exceed funding goal",
81
+ [ERROR_CODES.InvalidTier]: "Invalid investment tier",
82
+ [ERROR_CODES.CoolingOffPeriodActive]: "Investment is within 24-hour cooling-off period",
83
+ [ERROR_CODES.CoolingOffPeriodExpired]: "Cooling-off period has expired, cannot cancel",
84
+ // Milestone Errors
85
+ [ERROR_CODES.InvalidMilestoneIndex]: "Invalid milestone index",
86
+ [ERROR_CODES.MilestonePercentageInvalid]: "Milestone percentage must be between 1-100",
87
+ [ERROR_CODES.TotalPercentageExceeded]: "Total milestone percentages exceed 100%",
88
+ [ERROR_CODES.MilestoneNotInProgress]: "Milestone must be in progress",
89
+ [ERROR_CODES.MilestoneNotApproved]: "Milestone must be approved first",
90
+ // TGE Errors
91
+ [ERROR_CODES.TgeDateNotSet]: "TGE date has not been set",
92
+ [ERROR_CODES.TgeDateAlreadySet]: "TGE date has already been set",
93
+ [ERROR_CODES.TgeDateTooSoon]: "TGE date must be at least 15 days in the future",
94
+ [ERROR_CODES.TgeDateTooLate]: "TGE date must be within 90 days",
95
+ [ERROR_CODES.TgeNotReached]: "TGE date has not been reached",
96
+ [ERROR_CODES.TokensAlreadyClaimed]: "Tokens have already been claimed",
97
+ [ERROR_CODES.InsufficientTokensDeposited]: "Insufficient tokens deposited by founder",
98
+ // Pivot Errors
99
+ [ERROR_CODES.PivotAlreadyProposed]: "A pivot is already pending",
100
+ [ERROR_CODES.NoPivotProposed]: "No pivot has been proposed",
101
+ [ERROR_CODES.PivotNotApproved]: "Pivot has not been approved by admin",
102
+ [ERROR_CODES.PivotWindowNotEnded]: "7-day withdrawal window has not ended",
103
+ [ERROR_CODES.PivotWindowEnded]: "7-day withdrawal window has ended",
104
+ [ERROR_CODES.AlreadyWithdrawnFromPivot]: "Already withdrawn from this pivot",
105
+ // Refund Errors
106
+ [ERROR_CODES.RefundAlreadyClaimed]: "Refund has already been claimed",
107
+ [ERROR_CODES.RefundNotAvailable]: "Refund is not available",
108
+ [ERROR_CODES.ProjectNotAbandoned]: "Project has not been abandoned",
109
+ // Scam Errors
110
+ [ERROR_CODES.ScamReportPeriodEnded]: "30-day scam report period has ended",
111
+ [ERROR_CODES.ScamAlreadyReported]: "Already reported this project for scam",
112
+ [ERROR_CODES.ScamNotConfirmed]: "Scam has not been confirmed",
113
+ [ERROR_CODES.HoldbackAlreadyReleased]: "Holdback has already been released",
114
+ [ERROR_CODES.HoldbackPeriodNotEnded]: "30-day holdback period has not ended"
115
+ };
116
+ var RaiseError = class _RaiseError extends Error {
117
+ constructor(code, message, logs) {
118
+ super(message);
119
+ this.code = code;
120
+ this.logs = logs;
121
+ this.name = "RaiseError";
122
+ }
123
+ /**
124
+ * Create from an Anchor error
125
+ */
126
+ static fromAnchorError(error) {
127
+ const code = error.error.errorCode.number;
128
+ const message = ERROR_MESSAGES[code] || error.error.errorMessage;
129
+ return new _RaiseError(code, message, error.logs);
130
+ }
131
+ /**
132
+ * Check if this is a specific error type
133
+ */
134
+ is(errorCode) {
135
+ return this.code === errorCode;
136
+ }
137
+ };
138
+ function parseError(error) {
139
+ if (error instanceof anchor.AnchorError) {
140
+ return RaiseError.fromAnchorError(error);
141
+ }
142
+ if (error instanceof Error) {
143
+ return error;
144
+ }
145
+ return new Error(String(error));
146
+ }
147
+ function isRaiseError(error, code) {
148
+ if (!(error instanceof RaiseError)) {
149
+ return false;
150
+ }
151
+ if (code !== void 0) {
152
+ return error.code === code;
153
+ }
154
+ return true;
155
+ }
156
+ function getErrorMessage(error) {
157
+ if (error instanceof RaiseError) {
158
+ return error.message;
159
+ }
160
+ if (error instanceof anchor.AnchorError) {
161
+ const code = error.error.errorCode.number;
162
+ return ERROR_MESSAGES[code] || error.error.errorMessage;
163
+ }
164
+ if (error instanceof Error) {
165
+ return error.message;
166
+ }
167
+ return "An unknown error occurred";
168
+ }
169
+
170
+ exports.ERROR_CODES = ERROR_CODES;
171
+ exports.ERROR_MESSAGES = ERROR_MESSAGES;
172
+ exports.RaiseError = RaiseError;
173
+ exports.getErrorMessage = getErrorMessage;
174
+ exports.isRaiseError = isRaiseError;
175
+ exports.parseError = parseError;
176
+ //# sourceMappingURL=index.cjs.map
177
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/errors/index.ts"],"names":["AnchorError"],"mappings":";;;;;AAYO,IAAM,WAAA,GAAc;AAAA;AAAA,EAEzB,sBAAA,EAAwB,GAAA;AAAA,EACxB,qBAAA,EAAuB,IAAA;AAAA,EACvB,oBAAA,EAAsB,IAAA;AAAA,EACtB,uBAAA,EAAyB,IAAA;AAAA,EACzB,iBAAA,EAAmB,IAAA;AAAA,EACnB,oBAAA,EAAsB,IAAA;AAAA,EACtB,kBAAA,EAAoB,IAAA;AAAA,EACpB,wBAAA,EAA0B,IAAA;AAAA,EAC1B,oBAAA,EAAsB,IAAA;AAAA,EACtB,gBAAA,EAAkB,IAAA;AAAA;AAAA,EAGlB,mBAAA,EAAqB,IAAA;AAAA,EACrB,iBAAA,EAAmB,IAAA;AAAA,EACnB,WAAA,EAAa,IAAA;AAAA,EACb,YAAA,EAAc,IAAA;AAAA;AAAA,EAGd,sBAAA,EAAwB,IAAA;AAAA,EACxB,mBAAA,EAAqB,IAAA;AAAA,EACrB,WAAA,EAAa,IAAA;AAAA,EACb,sBAAA,EAAwB,IAAA;AAAA,EACxB,uBAAA,EAAyB,IAAA;AAAA;AAAA,EAGzB,qBAAA,EAAuB,IAAA;AAAA,EACvB,0BAAA,EAA4B,IAAA;AAAA,EAC5B,uBAAA,EAAyB,IAAA;AAAA,EACzB,sBAAA,EAAwB,IAAA;AAAA,EACxB,oBAAA,EAAsB,IAAA;AAAA;AAAA,EAGtB,aAAA,EAAe,IAAA;AAAA,EACf,iBAAA,EAAmB,IAAA;AAAA,EACnB,cAAA,EAAgB,IAAA;AAAA,EAChB,cAAA,EAAgB,IAAA;AAAA,EAChB,aAAA,EAAe,IAAA;AAAA,EACf,oB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EAAa;AAChC,IAAA,OAAO,UAAA,CAAW,gBAAgB,KAAK,CAAA;AAAA,EACzC;AACA,EAAA,IAAI,iBAAiB,KAAA,EAAO;AAC1B,IAAA,OAAO,KAAA;AAAA,EACT;AACA,EAAA,OAAO,IAAI,KAAA,CAAM,MAAA,CAAO,KAAK,CAAC,CAAA;AAChC;AAKO,SAAS,YAAA,CACd,OACA,IAAA,EACqB;AACrB,EAAA,IAAI,EAAE,iBAAiB,UAAA,CAAA,EAAa;AAClC,IAAA,OAAO,KAAA;AAAA,EACT;AACA,EAAA,IAAI,SAAS,MAAA,EAAW;AACtB,IAAA,OAAO,MAAM,IAAA,KAAS,IAAA;AAAA,EACxB;AACA,EAAA,OAAO,IAAA;AACT;AAKO,SAAS,gBAAgB,KAAA,EAAwB;AACtD,EAAA,IAAI,iBAAiB,UAAA,EAAY;AAC/B,IAAA,OAAO,KAAA,CAAM,OAAA;AAAA,EACf;AACA,EAAA,IAAI,iBAAiBA,kBAAA,EAAa;AAChC,IAAA,MAAM,IAAA,GAAO,KAAA,CAAM,KAAA,CAAM,SAAA,CAAU,MAAA;AACnC,IAAA,OAAO,cAAA,CAAe,IAAI,CAAA,IAAK,KAAA,CAAM,KAAA,CAAM,YAAA;AAAA,EAC7C;AACA,EAAA,IAAI,iBAAiB,KAAA,EAAO;AAC1B,IAAA,OAAO,KAAA,CAAM,OAAA;AAAA,EACf;AACA,EAAA,OAAO,2BAAA;AACT","file":"index.cjs","sourcesContent":["/**\n * Raise Error Handling\n *\n * Maps program error codes to SDK errors with helpful messages.\n */\n\nimport { AnchorError } from '@coral-xyz/anchor';\n\n// =============================================================================\n// Error Codes (matching Rust program)\n// =============================================================================\n\nexport const ERROR_CODES = {\n // State Transition Errors (6000-6099)\n InvalidStateTransition: 6000,\n ProjectNotInOpenState: 6001,\n ProjectNotInProgress: 6002,\n MilestoneNotUnderReview: 6003,\n VotingPeriodEnded: 6004,\n VotingPeriodNotEnded: 6005,\n MilestoneNotPassed: 6006,\n MilestoneAlreadyUnlocked: 6007,\n ProjectAlreadyFunded: 6008,\n ProjectNotFunded: 6009,\n\n // Authorization Errors (6100-6199)\n UnauthorizedFounder: 6100,\n UnauthorizedAdmin: 6101,\n NotInvestor: 6102,\n AlreadyVoted: 6103,\n\n // Investment Errors (6200-6299)\n InvestmentBelowMinimum: 6200,\n FundingGoalExceeded: 6201,\n InvalidTier: 6202,\n CoolingOffPeriodActive: 6203,\n CoolingOffPeriodExpired: 6204,\n\n // Milestone Errors (6300-6399)\n InvalidMilestoneIndex: 6300,\n MilestonePercentageInvalid: 6301,\n TotalPercentageExceeded: 6302,\n MilestoneNotInProgress: 6303,\n MilestoneNotApproved: 6304,\n\n // TGE Errors (6400-6499)\n TgeDateNotSet: 6400,\n TgeDateAlreadySet: 6401,\n TgeDateTooSoon: 6402,\n TgeDateTooLate: 6403,\n TgeNotReached: 6404,\n TokensAlreadyClaimed: 6405,\n InsufficientTokensDeposited: 6406,\n\n // Pivot Errors (6500-6599)\n PivotAlreadyProposed: 6500,\n NoPivotProposed: 6501,\n PivotNotApproved: 6502,\n PivotWindowNotEnded: 6503,\n PivotWindowEnded: 6504,\n AlreadyWithdrawnFromPivot: 6505,\n\n // Refund Errors (6800-6899)\n RefundAlreadyClaimed: 6800,\n RefundNotAvailable: 6801,\n ProjectNotAbandoned: 6802,\n\n // Scam Errors (6900-6999)\n ScamReportPeriodEnded: 6900,\n ScamAlreadyReported: 6901,\n ScamNotConfirmed: 6902,\n HoldbackAlreadyReleased: 6903,\n HoldbackPeriodNotEnded: 6904,\n} as const;\n\n// =============================================================================\n// Error Messages\n// =============================================================================\n\nexport const ERROR_MESSAGES: Record<number, string> = {\n // State Transition Errors\n [ERROR_CODES.InvalidStateTransition]: 'Invalid project state transition',\n [ERROR_CODES.ProjectNotInOpenState]: 'Project must be in Open state to accept investments',\n [ERROR_CODES.ProjectNotInProgress]: 'Project must be InProgress to perform this action',\n [ERROR_CODES.MilestoneNotUnderReview]: 'Milestone must be under review to vote',\n [ERROR_CODES.VotingPeriodEnded]: 'Voting period has ended',\n [ERROR_CODES.VotingPeriodNotEnded]: 'Voting period has not ended yet',\n [ERROR_CODES.MilestoneNotPassed]: 'Milestone did not pass voting',\n [ERROR_CODES.MilestoneAlreadyUnlocked]: 'Milestone funds already unlocked',\n [ERROR_CODES.ProjectAlreadyFunded]: 'Project has already reached funding goal',\n [ERROR_CODES.ProjectNotFunded]: 'Project has not reached funding goal',\n\n // Authorization Errors\n [ERROR_CODES.UnauthorizedFounder]: 'Only the project founder can perform this action',\n [ERROR_CODES.UnauthorizedAdmin]: 'Only the admin can perform this action',\n [ERROR_CODES.NotInvestor]: 'You must be an investor to perform this action',\n [ERROR_CODES.AlreadyVoted]: 'You have already voted on this',\n\n // Investment Errors\n [ERROR_CODES.InvestmentBelowMinimum]: 'Investment amount below minimum tier requirement',\n [ERROR_CODES.FundingGoalExceeded]: 'Investment would exceed funding goal',\n [ERROR_CODES.InvalidTier]: 'Invalid investment tier',\n [ERROR_CODES.CoolingOffPeriodActive]: 'Investment is within 24-hour cooling-off period',\n [ERROR_CODES.CoolingOffPeriodExpired]: 'Cooling-off period has expired, cannot cancel',\n\n // Milestone Errors\n [ERROR_CODES.InvalidMilestoneIndex]: 'Invalid milestone index',\n [ERROR_CODES.MilestonePercentageInvalid]: 'Milestone percentage must be between 1-100',\n [ERROR_CODES.TotalPercentageExceeded]: 'Total milestone percentages exceed 100%',\n [ERROR_CODES.MilestoneNotInProgress]: 'Milestone must be in progress',\n [ERROR_CODES.MilestoneNotApproved]: 'Milestone must be approved first',\n\n // TGE Errors\n [ERROR_CODES.TgeDateNotSet]: 'TGE date has not been set',\n [ERROR_CODES.TgeDateAlreadySet]: 'TGE date has already been set',\n [ERROR_CODES.TgeDateTooSoon]: 'TGE date must be at least 15 days in the future',\n [ERROR_CODES.TgeDateTooLate]: 'TGE date must be within 90 days',\n [ERROR_CODES.TgeNotReached]: 'TGE date has not been reached',\n [ERROR_CODES.TokensAlreadyClaimed]: 'Tokens have already been claimed',\n [ERROR_CODES.InsufficientTokensDeposited]: 'Insufficient tokens deposited by founder',\n\n // Pivot Errors\n [ERROR_CODES.PivotAlreadyProposed]: 'A pivot is already pending',\n [ERROR_CODES.NoPivotProposed]: 'No pivot has been proposed',\n [ERROR_CODES.PivotNotApproved]: 'Pivot has not been approved by admin',\n [ERROR_CODES.PivotWindowNotEnded]: '7-day withdrawal window has not ended',\n [ERROR_CODES.PivotWindowEnded]: '7-day withdrawal window has ended',\n [ERROR_CODES.AlreadyWithdrawnFromPivot]: 'Already withdrawn from this pivot',\n\n // Refund Errors\n [ERROR_CODES.RefundAlreadyClaimed]: 'Refund has already been claimed',\n [ERROR_CODES.RefundNotAvailable]: 'Refund is not available',\n [ERROR_CODES.ProjectNotAbandoned]: 'Project has not been abandoned',\n\n // Scam Errors\n [ERROR_CODES.ScamReportPeriodEnded]: '30-day scam report period has ended',\n [ERROR_CODES.ScamAlreadyReported]: 'Already reported this project for scam',\n [ERROR_CODES.ScamNotConfirmed]: 'Scam has not been confirmed',\n [ERROR_CODES.HoldbackAlreadyReleased]: 'Holdback has already been released',\n [ERROR_CODES.HoldbackPeriodNotEnded]: '30-day holdback period has not ended',\n};\n\n// =============================================================================\n// SDK Error Class\n// =============================================================================\n\nexport class RaiseError extends Error {\n constructor(\n public readonly code: number,\n message: string,\n public readonly logs?: string[]\n ) {\n super(message);\n this.name = 'RaiseError';\n }\n\n /**\n * Create from an Anchor error\n */\n static fromAnchorError(error: AnchorError): RaiseError {\n const code = error.error.errorCode.number;\n const message = ERROR_MESSAGES[code] || error.error.errorMessage;\n return new RaiseError(code, message, error.logs);\n }\n\n /**\n * Check if this is a specific error type\n */\n is(errorCode: number): boolean {\n return this.code === errorCode;\n }\n}\n\n// =============================================================================\n// Error Handling Utilities\n// =============================================================================\n\n/**\n * Parse an error and return a RaiseError if it's a program error\n */\nexport function parseError(error: unknown): RaiseError | Error {\n if (error instanceof AnchorError) {\n return RaiseError.fromAnchorError(error);\n }\n if (error instanceof Error) {\n return error;\n }\n return new Error(String(error));\n}\n\n/**\n * Check if an error is a specific Raise error\n */\nexport function isRaiseError(\n error: unknown,\n code?: number\n): error is RaiseError {\n if (!(error instanceof RaiseError)) {\n return false;\n }\n if (code !== undefined) {\n return error.code === code;\n }\n return true;\n}\n\n/**\n * Get a user-friendly error message\n */\nexport function getErrorMessage(error: unknown): string {\n if (error instanceof RaiseError) {\n return error.message;\n }\n if (error instanceof AnchorError) {\n const code = error.error.errorCode.number;\n return ERROR_MESSAGES[code] || error.error.errorMessage;\n }\n if (error instanceof Error) {\n return error.message;\n }\n return 'An unknown error occurred';\n}\n"]}
@@ -0,0 +1,83 @@
1
+ import { AnchorError } from '@coral-xyz/anchor';
2
+
3
+ /**
4
+ * Raise Error Handling
5
+ *
6
+ * Maps program error codes to SDK errors with helpful messages.
7
+ */
8
+
9
+ declare const ERROR_CODES: {
10
+ readonly InvalidStateTransition: 6000;
11
+ readonly ProjectNotInOpenState: 6001;
12
+ readonly ProjectNotInProgress: 6002;
13
+ readonly MilestoneNotUnderReview: 6003;
14
+ readonly VotingPeriodEnded: 6004;
15
+ readonly VotingPeriodNotEnded: 6005;
16
+ readonly MilestoneNotPassed: 6006;
17
+ readonly MilestoneAlreadyUnlocked: 6007;
18
+ readonly ProjectAlreadyFunded: 6008;
19
+ readonly ProjectNotFunded: 6009;
20
+ readonly UnauthorizedFounder: 6100;
21
+ readonly UnauthorizedAdmin: 6101;
22
+ readonly NotInvestor: 6102;
23
+ readonly AlreadyVoted: 6103;
24
+ readonly InvestmentBelowMinimum: 6200;
25
+ readonly FundingGoalExceeded: 6201;
26
+ readonly InvalidTier: 6202;
27
+ readonly CoolingOffPeriodActive: 6203;
28
+ readonly CoolingOffPeriodExpired: 6204;
29
+ readonly InvalidMilestoneIndex: 6300;
30
+ readonly MilestonePercentageInvalid: 6301;
31
+ readonly TotalPercentageExceeded: 6302;
32
+ readonly MilestoneNotInProgress: 6303;
33
+ readonly MilestoneNotApproved: 6304;
34
+ readonly TgeDateNotSet: 6400;
35
+ readonly TgeDateAlreadySet: 6401;
36
+ readonly TgeDateTooSoon: 6402;
37
+ readonly TgeDateTooLate: 6403;
38
+ readonly TgeNotReached: 6404;
39
+ readonly TokensAlreadyClaimed: 6405;
40
+ readonly InsufficientTokensDeposited: 6406;
41
+ readonly PivotAlreadyProposed: 6500;
42
+ readonly NoPivotProposed: 6501;
43
+ readonly PivotNotApproved: 6502;
44
+ readonly PivotWindowNotEnded: 6503;
45
+ readonly PivotWindowEnded: 6504;
46
+ readonly AlreadyWithdrawnFromPivot: 6505;
47
+ readonly RefundAlreadyClaimed: 6800;
48
+ readonly RefundNotAvailable: 6801;
49
+ readonly ProjectNotAbandoned: 6802;
50
+ readonly ScamReportPeriodEnded: 6900;
51
+ readonly ScamAlreadyReported: 6901;
52
+ readonly ScamNotConfirmed: 6902;
53
+ readonly HoldbackAlreadyReleased: 6903;
54
+ readonly HoldbackPeriodNotEnded: 6904;
55
+ };
56
+ declare const ERROR_MESSAGES: Record<number, string>;
57
+ declare class RaiseError extends Error {
58
+ readonly code: number;
59
+ readonly logs?: string[] | undefined;
60
+ constructor(code: number, message: string, logs?: string[] | undefined);
61
+ /**
62
+ * Create from an Anchor error
63
+ */
64
+ static fromAnchorError(error: AnchorError): RaiseError;
65
+ /**
66
+ * Check if this is a specific error type
67
+ */
68
+ is(errorCode: number): boolean;
69
+ }
70
+ /**
71
+ * Parse an error and return a RaiseError if it's a program error
72
+ */
73
+ declare function parseError(error: unknown): RaiseError | Error;
74
+ /**
75
+ * Check if an error is a specific Raise error
76
+ */
77
+ declare function isRaiseError(error: unknown, code?: number): error is RaiseError;
78
+ /**
79
+ * Get a user-friendly error message
80
+ */
81
+ declare function getErrorMessage(error: unknown): string;
82
+
83
+ export { ERROR_CODES, ERROR_MESSAGES, RaiseError, getErrorMessage, isRaiseError, parseError };
@@ -0,0 +1,83 @@
1
+ import { AnchorError } from '@coral-xyz/anchor';
2
+
3
+ /**
4
+ * Raise Error Handling
5
+ *
6
+ * Maps program error codes to SDK errors with helpful messages.
7
+ */
8
+
9
+ declare const ERROR_CODES: {
10
+ readonly InvalidStateTransition: 6000;
11
+ readonly ProjectNotInOpenState: 6001;
12
+ readonly ProjectNotInProgress: 6002;
13
+ readonly MilestoneNotUnderReview: 6003;
14
+ readonly VotingPeriodEnded: 6004;
15
+ readonly VotingPeriodNotEnded: 6005;
16
+ readonly MilestoneNotPassed: 6006;
17
+ readonly MilestoneAlreadyUnlocked: 6007;
18
+ readonly ProjectAlreadyFunded: 6008;
19
+ readonly ProjectNotFunded: 6009;
20
+ readonly UnauthorizedFounder: 6100;
21
+ readonly UnauthorizedAdmin: 6101;
22
+ readonly NotInvestor: 6102;
23
+ readonly AlreadyVoted: 6103;
24
+ readonly InvestmentBelowMinimum: 6200;
25
+ readonly FundingGoalExceeded: 6201;
26
+ readonly InvalidTier: 6202;
27
+ readonly CoolingOffPeriodActive: 6203;
28
+ readonly CoolingOffPeriodExpired: 6204;
29
+ readonly InvalidMilestoneIndex: 6300;
30
+ readonly MilestonePercentageInvalid: 6301;
31
+ readonly TotalPercentageExceeded: 6302;
32
+ readonly MilestoneNotInProgress: 6303;
33
+ readonly MilestoneNotApproved: 6304;
34
+ readonly TgeDateNotSet: 6400;
35
+ readonly TgeDateAlreadySet: 6401;
36
+ readonly TgeDateTooSoon: 6402;
37
+ readonly TgeDateTooLate: 6403;
38
+ readonly TgeNotReached: 6404;
39
+ readonly TokensAlreadyClaimed: 6405;
40
+ readonly InsufficientTokensDeposited: 6406;
41
+ readonly PivotAlreadyProposed: 6500;
42
+ readonly NoPivotProposed: 6501;
43
+ readonly PivotNotApproved: 6502;
44
+ readonly PivotWindowNotEnded: 6503;
45
+ readonly PivotWindowEnded: 6504;
46
+ readonly AlreadyWithdrawnFromPivot: 6505;
47
+ readonly RefundAlreadyClaimed: 6800;
48
+ readonly RefundNotAvailable: 6801;
49
+ readonly ProjectNotAbandoned: 6802;
50
+ readonly ScamReportPeriodEnded: 6900;
51
+ readonly ScamAlreadyReported: 6901;
52
+ readonly ScamNotConfirmed: 6902;
53
+ readonly HoldbackAlreadyReleased: 6903;
54
+ readonly HoldbackPeriodNotEnded: 6904;
55
+ };
56
+ declare const ERROR_MESSAGES: Record<number, string>;
57
+ declare class RaiseError extends Error {
58
+ readonly code: number;
59
+ readonly logs?: string[] | undefined;
60
+ constructor(code: number, message: string, logs?: string[] | undefined);
61
+ /**
62
+ * Create from an Anchor error
63
+ */
64
+ static fromAnchorError(error: AnchorError): RaiseError;
65
+ /**
66
+ * Check if this is a specific error type
67
+ */
68
+ is(errorCode: number): boolean;
69
+ }
70
+ /**
71
+ * Parse an error and return a RaiseError if it's a program error
72
+ */
73
+ declare function parseError(error: unknown): RaiseError | Error;
74
+ /**
75
+ * Check if an error is a specific Raise error
76
+ */
77
+ declare function isRaiseError(error: unknown, code?: number): error is RaiseError;
78
+ /**
79
+ * Get a user-friendly error message
80
+ */
81
+ declare function getErrorMessage(error: unknown): string;
82
+
83
+ export { ERROR_CODES, ERROR_MESSAGES, RaiseError, getErrorMessage, isRaiseError, parseError };
@@ -0,0 +1,170 @@
1
+ import { AnchorError } from '@coral-xyz/anchor';
2
+
3
+ // src/errors/index.ts
4
+ var ERROR_CODES = {
5
+ // State Transition Errors (6000-6099)
6
+ InvalidStateTransition: 6e3,
7
+ ProjectNotInOpenState: 6001,
8
+ ProjectNotInProgress: 6002,
9
+ MilestoneNotUnderReview: 6003,
10
+ VotingPeriodEnded: 6004,
11
+ VotingPeriodNotEnded: 6005,
12
+ MilestoneNotPassed: 6006,
13
+ MilestoneAlreadyUnlocked: 6007,
14
+ ProjectAlreadyFunded: 6008,
15
+ ProjectNotFunded: 6009,
16
+ // Authorization Errors (6100-6199)
17
+ UnauthorizedFounder: 6100,
18
+ UnauthorizedAdmin: 6101,
19
+ NotInvestor: 6102,
20
+ AlreadyVoted: 6103,
21
+ // Investment Errors (6200-6299)
22
+ InvestmentBelowMinimum: 6200,
23
+ FundingGoalExceeded: 6201,
24
+ InvalidTier: 6202,
25
+ CoolingOffPeriodActive: 6203,
26
+ CoolingOffPeriodExpired: 6204,
27
+ // Milestone Errors (6300-6399)
28
+ InvalidMilestoneIndex: 6300,
29
+ MilestonePercentageInvalid: 6301,
30
+ TotalPercentageExceeded: 6302,
31
+ MilestoneNotInProgress: 6303,
32
+ MilestoneNotApproved: 6304,
33
+ // TGE Errors (6400-6499)
34
+ TgeDateNotSet: 6400,
35
+ TgeDateAlreadySet: 6401,
36
+ TgeDateTooSoon: 6402,
37
+ TgeDateTooLate: 6403,
38
+ TgeNotReached: 6404,
39
+ TokensAlreadyClaimed: 6405,
40
+ InsufficientTokensDeposited: 6406,
41
+ // Pivot Errors (6500-6599)
42
+ PivotAlreadyProposed: 6500,
43
+ NoPivotProposed: 6501,
44
+ PivotNotApproved: 6502,
45
+ PivotWindowNotEnded: 6503,
46
+ PivotWindowEnded: 6504,
47
+ AlreadyWithdrawnFromPivot: 6505,
48
+ // Refund Errors (6800-6899)
49
+ RefundAlreadyClaimed: 6800,
50
+ RefundNotAvailable: 6801,
51
+ ProjectNotAbandoned: 6802,
52
+ // Scam Errors (6900-6999)
53
+ ScamReportPeriodEnded: 6900,
54
+ ScamAlreadyReported: 6901,
55
+ ScamNotConfirmed: 6902,
56
+ HoldbackAlreadyReleased: 6903,
57
+ HoldbackPeriodNotEnded: 6904
58
+ };
59
+ var ERROR_MESSAGES = {
60
+ // State Transition Errors
61
+ [ERROR_CODES.InvalidStateTransition]: "Invalid project state transition",
62
+ [ERROR_CODES.ProjectNotInOpenState]: "Project must be in Open state to accept investments",
63
+ [ERROR_CODES.ProjectNotInProgress]: "Project must be InProgress to perform this action",
64
+ [ERROR_CODES.MilestoneNotUnderReview]: "Milestone must be under review to vote",
65
+ [ERROR_CODES.VotingPeriodEnded]: "Voting period has ended",
66
+ [ERROR_CODES.VotingPeriodNotEnded]: "Voting period has not ended yet",
67
+ [ERROR_CODES.MilestoneNotPassed]: "Milestone did not pass voting",
68
+ [ERROR_CODES.MilestoneAlreadyUnlocked]: "Milestone funds already unlocked",
69
+ [ERROR_CODES.ProjectAlreadyFunded]: "Project has already reached funding goal",
70
+ [ERROR_CODES.ProjectNotFunded]: "Project has not reached funding goal",
71
+ // Authorization Errors
72
+ [ERROR_CODES.UnauthorizedFounder]: "Only the project founder can perform this action",
73
+ [ERROR_CODES.UnauthorizedAdmin]: "Only the admin can perform this action",
74
+ [ERROR_CODES.NotInvestor]: "You must be an investor to perform this action",
75
+ [ERROR_CODES.AlreadyVoted]: "You have already voted on this",
76
+ // Investment Errors
77
+ [ERROR_CODES.InvestmentBelowMinimum]: "Investment amount below minimum tier requirement",
78
+ [ERROR_CODES.FundingGoalExceeded]: "Investment would exceed funding goal",
79
+ [ERROR_CODES.InvalidTier]: "Invalid investment tier",
80
+ [ERROR_CODES.CoolingOffPeriodActive]: "Investment is within 24-hour cooling-off period",
81
+ [ERROR_CODES.CoolingOffPeriodExpired]: "Cooling-off period has expired, cannot cancel",
82
+ // Milestone Errors
83
+ [ERROR_CODES.InvalidMilestoneIndex]: "Invalid milestone index",
84
+ [ERROR_CODES.MilestonePercentageInvalid]: "Milestone percentage must be between 1-100",
85
+ [ERROR_CODES.TotalPercentageExceeded]: "Total milestone percentages exceed 100%",
86
+ [ERROR_CODES.MilestoneNotInProgress]: "Milestone must be in progress",
87
+ [ERROR_CODES.MilestoneNotApproved]: "Milestone must be approved first",
88
+ // TGE Errors
89
+ [ERROR_CODES.TgeDateNotSet]: "TGE date has not been set",
90
+ [ERROR_CODES.TgeDateAlreadySet]: "TGE date has already been set",
91
+ [ERROR_CODES.TgeDateTooSoon]: "TGE date must be at least 15 days in the future",
92
+ [ERROR_CODES.TgeDateTooLate]: "TGE date must be within 90 days",
93
+ [ERROR_CODES.TgeNotReached]: "TGE date has not been reached",
94
+ [ERROR_CODES.TokensAlreadyClaimed]: "Tokens have already been claimed",
95
+ [ERROR_CODES.InsufficientTokensDeposited]: "Insufficient tokens deposited by founder",
96
+ // Pivot Errors
97
+ [ERROR_CODES.PivotAlreadyProposed]: "A pivot is already pending",
98
+ [ERROR_CODES.NoPivotProposed]: "No pivot has been proposed",
99
+ [ERROR_CODES.PivotNotApproved]: "Pivot has not been approved by admin",
100
+ [ERROR_CODES.PivotWindowNotEnded]: "7-day withdrawal window has not ended",
101
+ [ERROR_CODES.PivotWindowEnded]: "7-day withdrawal window has ended",
102
+ [ERROR_CODES.AlreadyWithdrawnFromPivot]: "Already withdrawn from this pivot",
103
+ // Refund Errors
104
+ [ERROR_CODES.RefundAlreadyClaimed]: "Refund has already been claimed",
105
+ [ERROR_CODES.RefundNotAvailable]: "Refund is not available",
106
+ [ERROR_CODES.ProjectNotAbandoned]: "Project has not been abandoned",
107
+ // Scam Errors
108
+ [ERROR_CODES.ScamReportPeriodEnded]: "30-day scam report period has ended",
109
+ [ERROR_CODES.ScamAlreadyReported]: "Already reported this project for scam",
110
+ [ERROR_CODES.ScamNotConfirmed]: "Scam has not been confirmed",
111
+ [ERROR_CODES.HoldbackAlreadyReleased]: "Holdback has already been released",
112
+ [ERROR_CODES.HoldbackPeriodNotEnded]: "30-day holdback period has not ended"
113
+ };
114
+ var RaiseError = class _RaiseError extends Error {
115
+ constructor(code, message, logs) {
116
+ super(message);
117
+ this.code = code;
118
+ this.logs = logs;
119
+ this.name = "RaiseError";
120
+ }
121
+ /**
122
+ * Create from an Anchor error
123
+ */
124
+ static fromAnchorError(error) {
125
+ const code = error.error.errorCode.number;
126
+ const message = ERROR_MESSAGES[code] || error.error.errorMessage;
127
+ return new _RaiseError(code, message, error.logs);
128
+ }
129
+ /**
130
+ * Check if this is a specific error type
131
+ */
132
+ is(errorCode) {
133
+ return this.code === errorCode;
134
+ }
135
+ };
136
+ function parseError(error) {
137
+ if (error instanceof AnchorError) {
138
+ return RaiseError.fromAnchorError(error);
139
+ }
140
+ if (error instanceof Error) {
141
+ return error;
142
+ }
143
+ return new Error(String(error));
144
+ }
145
+ function isRaiseError(error, code) {
146
+ if (!(error instanceof RaiseError)) {
147
+ return false;
148
+ }
149
+ if (code !== void 0) {
150
+ return error.code === code;
151
+ }
152
+ return true;
153
+ }
154
+ function getErrorMessage(error) {
155
+ if (error instanceof RaiseError) {
156
+ return error.message;
157
+ }
158
+ if (error instanceof AnchorError) {
159
+ const code = error.error.errorCode.number;
160
+ return ERROR_MESSAGES[code] || error.error.errorMessage;
161
+ }
162
+ if (error instanceof Error) {
163
+ return error.message;
164
+ }
165
+ return "An unknown error occurred";
166
+ }
167
+
168
+ export { ERROR_CODES, ERROR_MESSAGES, RaiseError, getErrorMessage, isRaiseError, parseError };
169
+ //# sourceMappingURL=index.js.map
170
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/errors/index.ts"],"names":[],"mappings":";;;AAYO,IAAM,WAAA,GAAc;AAAA;AAAA,EAEzB,sBAAA,EAAwB,GAAA;AAAA,EACxB,qBAAA,EAAuB,IAAA;AAAA,EACvB,oBAAA,EAAsB,IAAA;AAAA,EACtB,uBAAA,EAAyB,IAAA;AAAA,EACzB,iBAAA,EAAmB,IAAA;AAAA,EACnB,oBAAA,EAAsB,IAAA;AAAA,EACtB,kBAAA,EAAoB,IAAA;AAAA,EACpB,wBAAA,EAA0B,IAAA;AAAA,EAC1B,oBAAA,EAAsB,IAAA;AAAA,EACtB,gBAAA,EAAkB,IAAA;AAAA;AAAA,EAGlB,mBAAA,EAAqB,IAAA;AAAA,EACrB,iBAAA,EAAmB,IAAA;AAAA,EACnB,WAAA,EAAa,IAAA;AAAA,EACb,YAAA,EAAc,IAAA;AAAA;AAAA,EAGd,sBAAA,EAAwB,IAAA;AAAA,EACxB,mBAAA,EAAqB,IAAA;AAAA,EACrB,WAAA,EAAa,IAAA;AAAA,EACb,sBAAA,EAAwB,IAAA;AAAA,EACxB,uBAAA,EAAyB,IAAA;AAAA;AAAA,EAGzB,qBAAA,EAAuB,IAAA;AAAA,EACvB,0BAAA,EAA4B,IAAA;AAAA,EAC5B,u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AAA,OAAO,IAAI,WAAA,CAAW,IAAA,EAAM,OAAA,EAAS,MAAM,IAAI,CAAA;AAAA,EACjD;AAAA;AAAA;AAAA;AAAA,EAKA,GAAG,SAAA,EAA4B;AAC7B,IAAA,OAAO,KAAK,IAAA,KAAS,SAAA;AAAA,EACvB;AACF;AASO,SAAS,WAAW,KAAA,EAAoC;AAC7D,EAAA,IAAI,iBAAiB,WAAA,EAAa;AAChC,IAAA,OAAO,UAAA,CAAW,gBAAgB,KAAK,CAAA;AAAA,EACzC;AACA,EAAA,IAAI,iBAAiB,KAAA,EAAO;AAC1B,IAAA,OAAO,KAAA;AAAA,EACT;AACA,EAAA,OAAO,IAAI,KAAA,CAAM,MAAA,CAAO,KAAK,CAAC,CAAA;AAChC;AAKO,SAAS,YAAA,CACd,OACA,IAAA,EACqB;AACrB,EAAA,IAAI,EAAE,iBAAiB,UAAA,CAAA,EAAa;AAClC,IAAA,OAAO,KAAA;AAAA,EACT;AACA,EAAA,IAAI,SAAS,MAAA,EAAW;AACtB,IAAA,OAAO,MAAM,IAAA,KAAS,IAAA;AAAA,EACxB;AACA,EAAA,OAAO,IAAA;AACT;AAKO,SAAS,gBAAgB,KAAA,EAAwB;AACtD,EAAA,IAAI,iBAAiB,UAAA,EAAY;AAC/B,IAAA,OAAO,KAAA,CAAM,OAAA;AAAA,EACf;AACA,EAAA,IAAI,iBAAiB,WAAA,EAAa;AAChC,IAAA,MAAM,IAAA,GAAO,KAAA,CAAM,KAAA,CAAM,SAAA,CAAU,MAAA;AACnC,IAAA,OAAO,cAAA,CAAe,IAAI,CAAA,IAAK,KAAA,CAAM,KAAA,CAAM,YAAA;AAAA,EAC7C;AACA,EAAA,IAAI,iBAAiB,KAAA,EAAO;AAC1B,IAAA,OAAO,KAAA,CAAM,OAAA;AAAA,EACf;AACA,EAAA,OAAO,2BAAA;AACT","file":"index.js","sourcesContent":["/**\n * Raise Error Handling\n *\n * Maps program error codes to SDK errors with helpful messages.\n */\n\nimport { AnchorError } from '@coral-xyz/anchor';\n\n// =============================================================================\n// Error Codes (matching Rust program)\n// =============================================================================\n\nexport const ERROR_CODES = {\n // State Transition Errors (6000-6099)\n InvalidStateTransition: 6000,\n ProjectNotInOpenState: 6001,\n ProjectNotInProgress: 6002,\n MilestoneNotUnderReview: 6003,\n VotingPeriodEnded: 6004,\n VotingPeriodNotEnded: 6005,\n MilestoneNotPassed: 6006,\n MilestoneAlreadyUnlocked: 6007,\n ProjectAlreadyFunded: 6008,\n ProjectNotFunded: 6009,\n\n // Authorization Errors (6100-6199)\n UnauthorizedFounder: 6100,\n UnauthorizedAdmin: 6101,\n NotInvestor: 6102,\n AlreadyVoted: 6103,\n\n // Investment Errors (6200-6299)\n InvestmentBelowMinimum: 6200,\n FundingGoalExceeded: 6201,\n InvalidTier: 6202,\n CoolingOffPeriodActive: 6203,\n CoolingOffPeriodExpired: 6204,\n\n // Milestone Errors (6300-6399)\n InvalidMilestoneIndex: 6300,\n MilestonePercentageInvalid: 6301,\n TotalPercentageExceeded: 6302,\n MilestoneNotInProgress: 6303,\n MilestoneNotApproved: 6304,\n\n // TGE Errors (6400-6499)\n TgeDateNotSet: 6400,\n TgeDateAlreadySet: 6401,\n TgeDateTooSoon: 6402,\n TgeDateTooLate: 6403,\n TgeNotReached: 6404,\n TokensAlreadyClaimed: 6405,\n InsufficientTokensDeposited: 6406,\n\n // Pivot Errors (6500-6599)\n PivotAlreadyProposed: 6500,\n NoPivotProposed: 6501,\n PivotNotApproved: 6502,\n PivotWindowNotEnded: 6503,\n PivotWindowEnded: 6504,\n AlreadyWithdrawnFromPivot: 6505,\n\n // Refund Errors (6800-6899)\n RefundAlreadyClaimed: 6800,\n RefundNotAvailable: 6801,\n ProjectNotAbandoned: 6802,\n\n // Scam Errors (6900-6999)\n ScamReportPeriodEnded: 6900,\n ScamAlreadyReported: 6901,\n ScamNotConfirmed: 6902,\n HoldbackAlreadyReleased: 6903,\n HoldbackPeriodNotEnded: 6904,\n} as const;\n\n// =============================================================================\n// Error Messages\n// =============================================================================\n\nexport const ERROR_MESSAGES: Record<number, string> = {\n // State Transition Errors\n [ERROR_CODES.InvalidStateTransition]: 'Invalid project state transition',\n [ERROR_CODES.ProjectNotInOpenState]: 'Project must be in Open state to accept investments',\n [ERROR_CODES.ProjectNotInProgress]: 'Project must be InProgress to perform this action',\n [ERROR_CODES.MilestoneNotUnderReview]: 'Milestone must be under review to vote',\n [ERROR_CODES.VotingPeriodEnded]: 'Voting period has ended',\n [ERROR_CODES.VotingPeriodNotEnded]: 'Voting period has not ended yet',\n [ERROR_CODES.MilestoneNotPassed]: 'Milestone did not pass voting',\n [ERROR_CODES.MilestoneAlreadyUnlocked]: 'Milestone funds already unlocked',\n [ERROR_CODES.ProjectAlreadyFunded]: 'Project has already reached funding goal',\n [ERROR_CODES.ProjectNotFunded]: 'Project has not reached funding goal',\n\n // Authorization Errors\n [ERROR_CODES.UnauthorizedFounder]: 'Only the project founder can perform this action',\n [ERROR_CODES.UnauthorizedAdmin]: 'Only the admin can perform this action',\n [ERROR_CODES.NotInvestor]: 'You must be an investor to perform this action',\n [ERROR_CODES.AlreadyVoted]: 'You have already voted on this',\n\n // Investment Errors\n [ERROR_CODES.InvestmentBelowMinimum]: 'Investment amount below minimum tier requirement',\n [ERROR_CODES.FundingGoalExceeded]: 'Investment would exceed funding goal',\n [ERROR_CODES.InvalidTier]: 'Invalid investment tier',\n [ERROR_CODES.CoolingOffPeriodActive]: 'Investment is within 24-hour cooling-off period',\n [ERROR_CODES.CoolingOffPeriodExpired]: 'Cooling-off period has expired, cannot cancel',\n\n // Milestone Errors\n [ERROR_CODES.InvalidMilestoneIndex]: 'Invalid milestone index',\n [ERROR_CODES.MilestonePercentageInvalid]: 'Milestone percentage must be between 1-100',\n [ERROR_CODES.TotalPercentageExceeded]: 'Total milestone percentages exceed 100%',\n [ERROR_CODES.MilestoneNotInProgress]: 'Milestone must be in progress',\n [ERROR_CODES.MilestoneNotApproved]: 'Milestone must be approved first',\n\n // TGE Errors\n [ERROR_CODES.TgeDateNotSet]: 'TGE date has not been set',\n [ERROR_CODES.TgeDateAlreadySet]: 'TGE date has already been set',\n [ERROR_CODES.TgeDateTooSoon]: 'TGE date must be at least 15 days in the future',\n [ERROR_CODES.TgeDateTooLate]: 'TGE date must be within 90 days',\n [ERROR_CODES.TgeNotReached]: 'TGE date has not been reached',\n [ERROR_CODES.TokensAlreadyClaimed]: 'Tokens have already been claimed',\n [ERROR_CODES.InsufficientTokensDeposited]: 'Insufficient tokens deposited by founder',\n\n // Pivot Errors\n [ERROR_CODES.PivotAlreadyProposed]: 'A pivot is already pending',\n [ERROR_CODES.NoPivotProposed]: 'No pivot has been proposed',\n [ERROR_CODES.PivotNotApproved]: 'Pivot has not been approved by admin',\n [ERROR_CODES.PivotWindowNotEnded]: '7-day withdrawal window has not ended',\n [ERROR_CODES.PivotWindowEnded]: '7-day withdrawal window has ended',\n [ERROR_CODES.AlreadyWithdrawnFromPivot]: 'Already withdrawn from this pivot',\n\n // Refund Errors\n [ERROR_CODES.RefundAlreadyClaimed]: 'Refund has already been claimed',\n [ERROR_CODES.RefundNotAvailable]: 'Refund is not available',\n [ERROR_CODES.ProjectNotAbandoned]: 'Project has not been abandoned',\n\n // Scam Errors\n [ERROR_CODES.ScamReportPeriodEnded]: '30-day scam report period has ended',\n [ERROR_CODES.ScamAlreadyReported]: 'Already reported this project for scam',\n [ERROR_CODES.ScamNotConfirmed]: 'Scam has not been confirmed',\n [ERROR_CODES.HoldbackAlreadyReleased]: 'Holdback has already been released',\n [ERROR_CODES.HoldbackPeriodNotEnded]: '30-day holdback period has not ended',\n};\n\n// =============================================================================\n// SDK Error Class\n// =============================================================================\n\nexport class RaiseError extends Error {\n constructor(\n public readonly code: number,\n message: string,\n public readonly logs?: string[]\n ) {\n super(message);\n this.name = 'RaiseError';\n }\n\n /**\n * Create from an Anchor error\n */\n static fromAnchorError(error: AnchorError): RaiseError {\n const code = error.error.errorCode.number;\n const message = ERROR_MESSAGES[code] || error.error.errorMessage;\n return new RaiseError(code, message, error.logs);\n }\n\n /**\n * Check if this is a specific error type\n */\n is(errorCode: number): boolean {\n return this.code === errorCode;\n }\n}\n\n// =============================================================================\n// Error Handling Utilities\n// =============================================================================\n\n/**\n * Parse an error and return a RaiseError if it's a program error\n */\nexport function parseError(error: unknown): RaiseError | Error {\n if (error instanceof AnchorError) {\n return RaiseError.fromAnchorError(error);\n }\n if (error instanceof Error) {\n return error;\n }\n return new Error(String(error));\n}\n\n/**\n * Check if an error is a specific Raise error\n */\nexport function isRaiseError(\n error: unknown,\n code?: number\n): error is RaiseError {\n if (!(error instanceof RaiseError)) {\n return false;\n }\n if (code !== undefined) {\n return error.code === code;\n }\n return true;\n}\n\n/**\n * Get a user-friendly error message\n */\nexport function getErrorMessage(error: unknown): string {\n if (error instanceof RaiseError) {\n return error.message;\n }\n if (error instanceof AnchorError) {\n const code = error.error.errorCode.number;\n return ERROR_MESSAGES[code] || error.error.errorMessage;\n }\n if (error instanceof Error) {\n return error.message;\n }\n return 'An unknown error occurred';\n}\n"]}