@gala-chain/launchpad 1.0.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 (200) hide show
  1. package/.dev-env +7 -0
  2. package/.dockerignore +9 -0
  3. package/.eslintignore +4 -0
  4. package/.eslintrc.json +37 -0
  5. package/.github/workflows/publish-on-tag.yml +72 -0
  6. package/.github/workflows/test-on-push.yml +32 -0
  7. package/.nvmrc +1 -0
  8. package/.prettierignore +4 -0
  9. package/.prettierrc +12 -0
  10. package/Dockerfile +31 -0
  11. package/LICENSE +201 -0
  12. package/README.md +2 -0
  13. package/api-config.json +16 -0
  14. package/e2e/__snapshots__/api.spec.ts.snap +2482 -0
  15. package/e2e/api-config.json +17 -0
  16. package/e2e/api.spec.ts +48 -0
  17. package/e2e/jest.config.js +42 -0
  18. package/e2e/tsconfig.json +10 -0
  19. package/jest.config.ts +27 -0
  20. package/lib/jest.config.d.ts +13 -0
  21. package/lib/jest.config.d.ts.map +1 -0
  22. package/lib/jest.config.js +28 -0
  23. package/lib/jest.config.js.map +1 -0
  24. package/lib/package.json +54 -0
  25. package/lib/src/api/index.d.ts +4 -0
  26. package/lib/src/api/index.d.ts.map +1 -0
  27. package/lib/src/api/index.js +21 -0
  28. package/lib/src/api/index.js.map +1 -0
  29. package/lib/src/api/types/LaunchpadDtos.d.ts +102 -0
  30. package/lib/src/api/types/LaunchpadDtos.d.ts.map +1 -0
  31. package/lib/src/api/types/LaunchpadDtos.js +410 -0
  32. package/lib/src/api/types/LaunchpadDtos.js.map +1 -0
  33. package/lib/src/api/types/LaunchpadFeeConfig.d.ts +9 -0
  34. package/lib/src/api/types/LaunchpadFeeConfig.d.ts.map +1 -0
  35. package/lib/src/api/types/LaunchpadFeeConfig.js +56 -0
  36. package/lib/src/api/types/LaunchpadFeeConfig.js.map +1 -0
  37. package/lib/src/api/types/LaunchpadFinalizeAllocation.d.ts +10 -0
  38. package/lib/src/api/types/LaunchpadFinalizeAllocation.d.ts.map +1 -0
  39. package/lib/src/api/types/LaunchpadFinalizeAllocation.js +70 -0
  40. package/lib/src/api/types/LaunchpadFinalizeAllocation.js.map +1 -0
  41. package/lib/src/api/types/LaunchpadSale.d.ts +35 -0
  42. package/lib/src/api/types/LaunchpadSale.d.ts.map +1 -0
  43. package/lib/src/api/types/LaunchpadSale.js +195 -0
  44. package/lib/src/api/types/LaunchpadSale.js.map +1 -0
  45. package/lib/src/api/types/index.d.ts +5 -0
  46. package/lib/src/api/types/index.d.ts.map +1 -0
  47. package/lib/src/api/types/index.js +22 -0
  48. package/lib/src/api/types/index.js.map +1 -0
  49. package/lib/src/api/utils/error.d.ts +20 -0
  50. package/lib/src/api/utils/error.d.ts.map +1 -0
  51. package/lib/src/api/utils/error.js +35 -0
  52. package/lib/src/api/utils/error.js.map +1 -0
  53. package/lib/src/api/utils/index.d.ts +2 -0
  54. package/lib/src/api/utils/index.d.ts.map +1 -0
  55. package/lib/src/api/utils/index.js +19 -0
  56. package/lib/src/api/utils/index.js.map +1 -0
  57. package/lib/src/api/validators/decorators.d.ts +19 -0
  58. package/lib/src/api/validators/decorators.d.ts.map +1 -0
  59. package/lib/src/api/validators/decorators.js +391 -0
  60. package/lib/src/api/validators/decorators.js.map +1 -0
  61. package/lib/src/api/validators/index.d.ts +2 -0
  62. package/lib/src/api/validators/index.d.ts.map +1 -0
  63. package/lib/src/api/validators/index.js +19 -0
  64. package/lib/src/api/validators/index.js.map +1 -0
  65. package/lib/src/chaincode/LaunchpadContract.d.ts +20 -0
  66. package/lib/src/chaincode/LaunchpadContract.d.ts.map +1 -0
  67. package/lib/src/chaincode/LaunchpadContract.js +217 -0
  68. package/lib/src/chaincode/LaunchpadContract.js.map +1 -0
  69. package/lib/src/chaincode/dexLaunchpadFeeGate.d.ts +14 -0
  70. package/lib/src/chaincode/dexLaunchpadFeeGate.d.ts.map +1 -0
  71. package/lib/src/chaincode/dexLaunchpadFeeGate.js +47 -0
  72. package/lib/src/chaincode/dexLaunchpadFeeGate.js.map +1 -0
  73. package/lib/src/chaincode/index.d.ts +2 -0
  74. package/lib/src/chaincode/index.d.ts.map +1 -0
  75. package/lib/src/chaincode/index.js +19 -0
  76. package/lib/src/chaincode/index.js.map +1 -0
  77. package/lib/src/chaincode/launchpad/buyExactToken.d.ts +20 -0
  78. package/lib/src/chaincode/launchpad/buyExactToken.d.ts.map +1 -0
  79. package/lib/src/chaincode/launchpad/buyExactToken.js +113 -0
  80. package/lib/src/chaincode/launchpad/buyExactToken.js.map +1 -0
  81. package/lib/src/chaincode/launchpad/buyWithNative.d.ts +22 -0
  82. package/lib/src/chaincode/launchpad/buyWithNative.d.ts.map +1 -0
  83. package/lib/src/chaincode/launchpad/buyWithNative.js +106 -0
  84. package/lib/src/chaincode/launchpad/buyWithNative.js.map +1 -0
  85. package/lib/src/chaincode/launchpad/callMemeTokenIn.d.ts +27 -0
  86. package/lib/src/chaincode/launchpad/callMemeTokenIn.d.ts.map +1 -0
  87. package/lib/src/chaincode/launchpad/callMemeTokenIn.js +76 -0
  88. package/lib/src/chaincode/launchpad/callMemeTokenIn.js.map +1 -0
  89. package/lib/src/chaincode/launchpad/callMemeTokenOut.d.ts +25 -0
  90. package/lib/src/chaincode/launchpad/callMemeTokenOut.d.ts.map +1 -0
  91. package/lib/src/chaincode/launchpad/callMemeTokenOut.js +56 -0
  92. package/lib/src/chaincode/launchpad/callMemeTokenOut.js.map +1 -0
  93. package/lib/src/chaincode/launchpad/callNativeTokenIn.d.ts +25 -0
  94. package/lib/src/chaincode/launchpad/callNativeTokenIn.d.ts.map +1 -0
  95. package/lib/src/chaincode/launchpad/callNativeTokenIn.js +51 -0
  96. package/lib/src/chaincode/launchpad/callNativeTokenIn.js.map +1 -0
  97. package/lib/src/chaincode/launchpad/callNativeTokenOut.d.ts +26 -0
  98. package/lib/src/chaincode/launchpad/callNativeTokenOut.d.ts.map +1 -0
  99. package/lib/src/chaincode/launchpad/callNativeTokenOut.js +60 -0
  100. package/lib/src/chaincode/launchpad/callNativeTokenOut.js.map +1 -0
  101. package/lib/src/chaincode/launchpad/configureLaunchpadFeeConfig.d.ts +4 -0
  102. package/lib/src/chaincode/launchpad/configureLaunchpadFeeConfig.d.ts.map +1 -0
  103. package/lib/src/chaincode/launchpad/configureLaunchpadFeeConfig.js +58 -0
  104. package/lib/src/chaincode/launchpad/configureLaunchpadFeeConfig.js.map +1 -0
  105. package/lib/src/chaincode/launchpad/createSale.d.ts +26 -0
  106. package/lib/src/chaincode/launchpad/createSale.d.ts.map +1 -0
  107. package/lib/src/chaincode/launchpad/createSale.js +129 -0
  108. package/lib/src/chaincode/launchpad/createSale.js.map +1 -0
  109. package/lib/src/chaincode/launchpad/fees.d.ts +6 -0
  110. package/lib/src/chaincode/launchpad/fees.d.ts.map +1 -0
  111. package/lib/src/chaincode/launchpad/fees.js +85 -0
  112. package/lib/src/chaincode/launchpad/fees.js.map +1 -0
  113. package/lib/src/chaincode/launchpad/fetchLaunchpadAdressConfig.d.ts +4 -0
  114. package/lib/src/chaincode/launchpad/fetchLaunchpadAdressConfig.d.ts.map +1 -0
  115. package/lib/src/chaincode/launchpad/fetchLaunchpadAdressConfig.js +36 -0
  116. package/lib/src/chaincode/launchpad/fetchLaunchpadAdressConfig.js.map +1 -0
  117. package/lib/src/chaincode/launchpad/fetchSaleDetails.d.ts +19 -0
  118. package/lib/src/chaincode/launchpad/fetchSaleDetails.d.ts.map +1 -0
  119. package/lib/src/chaincode/launchpad/fetchSaleDetails.js +49 -0
  120. package/lib/src/chaincode/launchpad/fetchSaleDetails.js.map +1 -0
  121. package/lib/src/chaincode/launchpad/finaliseSale.d.ts +4 -0
  122. package/lib/src/chaincode/launchpad/finaliseSale.d.ts.map +1 -0
  123. package/lib/src/chaincode/launchpad/finaliseSale.js +144 -0
  124. package/lib/src/chaincode/launchpad/finaliseSale.js.map +1 -0
  125. package/lib/src/chaincode/launchpad/finalizeTokenAllocation.d.ts +4 -0
  126. package/lib/src/chaincode/launchpad/finalizeTokenAllocation.d.ts.map +1 -0
  127. package/lib/src/chaincode/launchpad/finalizeTokenAllocation.js +43 -0
  128. package/lib/src/chaincode/launchpad/finalizeTokenAllocation.js.map +1 -0
  129. package/lib/src/chaincode/launchpad/index.d.ts +15 -0
  130. package/lib/src/chaincode/launchpad/index.d.ts.map +1 -0
  131. package/lib/src/chaincode/launchpad/index.js +32 -0
  132. package/lib/src/chaincode/launchpad/index.js.map +1 -0
  133. package/lib/src/chaincode/launchpad/preMintCalculation.d.ts +17 -0
  134. package/lib/src/chaincode/launchpad/preMintCalculation.d.ts.map +1 -0
  135. package/lib/src/chaincode/launchpad/preMintCalculation.js +56 -0
  136. package/lib/src/chaincode/launchpad/preMintCalculation.js.map +1 -0
  137. package/lib/src/chaincode/launchpad/sellExactToken.d.ts +22 -0
  138. package/lib/src/chaincode/launchpad/sellExactToken.d.ts.map +1 -0
  139. package/lib/src/chaincode/launchpad/sellExactToken.js +102 -0
  140. package/lib/src/chaincode/launchpad/sellExactToken.js.map +1 -0
  141. package/lib/src/chaincode/launchpad/sellWithNative.d.ts +23 -0
  142. package/lib/src/chaincode/launchpad/sellWithNative.d.ts.map +1 -0
  143. package/lib/src/chaincode/launchpad/sellWithNative.js +97 -0
  144. package/lib/src/chaincode/launchpad/sellWithNative.js.map +1 -0
  145. package/lib/src/chaincode/utils/index.d.ts +2 -0
  146. package/lib/src/chaincode/utils/index.d.ts.map +1 -0
  147. package/lib/src/chaincode/utils/index.js +19 -0
  148. package/lib/src/chaincode/utils/index.js.map +1 -0
  149. package/lib/src/chaincode/utils/launchpadSaleUtils.d.ts +11 -0
  150. package/lib/src/chaincode/utils/launchpadSaleUtils.d.ts.map +1 -0
  151. package/lib/src/chaincode/utils/launchpadSaleUtils.js +65 -0
  152. package/lib/src/chaincode/utils/launchpadSaleUtils.js.map +1 -0
  153. package/lib/src/cli.d.ts +3 -0
  154. package/lib/src/cli.d.ts.map +1 -0
  155. package/lib/src/cli.js +41 -0
  156. package/lib/src/cli.js.map +1 -0
  157. package/lib/src/index.d.ts +14 -0
  158. package/lib/src/index.d.ts.map +1 -0
  159. package/lib/src/index.js +32 -0
  160. package/lib/src/index.js.map +1 -0
  161. package/lib/tsconfig.tsbuildinfo +1 -0
  162. package/package.json +54 -0
  163. package/src/api/index.ts +18 -0
  164. package/src/api/types/LaunchpadDtos.ts +362 -0
  165. package/src/api/types/LaunchpadFeeConfig.ts +45 -0
  166. package/src/api/types/LaunchpadFinalizeAllocation.ts +65 -0
  167. package/src/api/types/LaunchpadSale.ts +200 -0
  168. package/src/api/types/index.ts +19 -0
  169. package/src/api/utils/error.ts +32 -0
  170. package/src/api/utils/index.ts +16 -0
  171. package/src/api/validators/decorators.spec.ts +277 -0
  172. package/src/api/validators/decorators.ts +401 -0
  173. package/src/api/validators/index.ts +16 -0
  174. package/src/chaincode/LaunchpadContract.ts +211 -0
  175. package/src/chaincode/dexLaunchpadFeeGate.ts +43 -0
  176. package/src/chaincode/index.ts +16 -0
  177. package/src/chaincode/launchpad/buyExactToken.ts +128 -0
  178. package/src/chaincode/launchpad/buyWithNative.ts +120 -0
  179. package/src/chaincode/launchpad/callMemeTokenIn.ts +82 -0
  180. package/src/chaincode/launchpad/callMemeTokenOut.ts +80 -0
  181. package/src/chaincode/launchpad/callNativeTokenIn.ts +71 -0
  182. package/src/chaincode/launchpad/callNativeTokenOut.ts +81 -0
  183. package/src/chaincode/launchpad/configureLaunchpadFeeConfig.ts +69 -0
  184. package/src/chaincode/launchpad/createSale.ts +157 -0
  185. package/src/chaincode/launchpad/fees.ts +105 -0
  186. package/src/chaincode/launchpad/fetchLaunchpadAdressConfig.ts +38 -0
  187. package/src/chaincode/launchpad/fetchSaleDetails.ts +53 -0
  188. package/src/chaincode/launchpad/finaliseSale.ts +217 -0
  189. package/src/chaincode/launchpad/finalizeTokenAllocation.ts +47 -0
  190. package/src/chaincode/launchpad/index.ts +28 -0
  191. package/src/chaincode/launchpad/preMintCalculation.ts +61 -0
  192. package/src/chaincode/launchpad/sellExactToken.ts +122 -0
  193. package/src/chaincode/launchpad/sellWithNative.ts +112 -0
  194. package/src/chaincode/utils/index.ts +15 -0
  195. package/src/chaincode/utils/launchpadSaleUtils.ts +68 -0
  196. package/src/cli.ts +63 -0
  197. package/src/index.ts +32 -0
  198. package/tsconfig.base.json +29 -0
  199. package/tsconfig.json +19 -0
  200. package/tsconfig.spec.json +11 -0
@@ -0,0 +1,401 @@
1
+ /*
2
+ * Copyright (c) Gala Games Inc. All rights reserved.
3
+ * Licensed under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License.
5
+ * You may obtain a copy of the License at
6
+ *
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software
10
+ * distributed under the License is distributed on an "AS IS" BASIS,
11
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ * See the License for the specific language governing permissions and
13
+ * limitations under the License.
14
+ */
15
+ import { NotImplementedError } from "@gala-chain/api";
16
+ import BigNumber from "bignumber.js";
17
+ import { ValidationArguments, ValidationOptions, registerDecorator } from "class-validator";
18
+
19
+ export function IsWholeNumber(property: string, validationOptions?: ValidationOptions) {
20
+ return function (object: Record<string, unknown>, propertyName: string): void {
21
+ registerDecorator({
22
+ name: "isWholeNumber",
23
+ target: object.constructor,
24
+ propertyName,
25
+ constraints: [property],
26
+ options: validationOptions,
27
+ validator: {
28
+ validate(value: Record<string, unknown>, args: ValidationArguments) {
29
+ const [relatedPropertyName] = args.constraints;
30
+ const relatedValue = args.object[relatedPropertyName];
31
+ const num = Number(relatedValue);
32
+
33
+ return num - Math.floor(num) === 0;
34
+ }
35
+ }
36
+ });
37
+ };
38
+ }
39
+
40
+ export function IsDifferentValue(property: string, validationOptions?: ValidationOptions) {
41
+ return function (object: object, propertyName: string): void {
42
+ registerDecorator({
43
+ name: "IsDifferentValue",
44
+ target: object.constructor,
45
+ propertyName,
46
+ constraints: [property],
47
+ options: validationOptions,
48
+ validator: {
49
+ validate(value: Record<string, unknown>, args: ValidationArguments) {
50
+ const [relatedPropertyName] = args.constraints;
51
+ const relatedValue = args.object[relatedPropertyName];
52
+ if (
53
+ (typeof value !== "string" && value !== undefined) ||
54
+ (typeof relatedValue !== "string" && relatedValue !== undefined)
55
+ ) {
56
+ throw new NotImplementedError("IsDifferentValue only works with string or undefined");
57
+ }
58
+ return value !== relatedValue;
59
+ }
60
+ }
61
+ });
62
+ };
63
+ }
64
+
65
+ export function ArrayUniqueConcat(property: string, validationOptions?: ValidationOptions) {
66
+ return function (object: object, propertyName: string): void {
67
+ registerDecorator({
68
+ name: "ArrayUniqueConcat",
69
+ target: object.constructor,
70
+ propertyName,
71
+ constraints: [property],
72
+ options: validationOptions,
73
+ validator: {
74
+ validate(value: unknown[], args: ValidationArguments) {
75
+ const [relatedPropertyName] = args.constraints;
76
+ const relatedValue = args.object[relatedPropertyName];
77
+
78
+ // Cannot have tokens duplicated between from or to, or within the from or to itself
79
+ const totalUniques = new Set(relatedValue.concat(value)).size;
80
+
81
+ return totalUniques === relatedValue.length + value.length;
82
+ }
83
+ }
84
+ });
85
+ };
86
+ }
87
+
88
+ export function ArrayUniqueObjects(property: string, validationOptions?: ValidationOptions) {
89
+ return function (object: object, propertyName: string): void {
90
+ registerDecorator({
91
+ name: "ArrayUniqueObjects",
92
+ target: object.constructor,
93
+ propertyName,
94
+ constraints: [property],
95
+ options: validationOptions,
96
+ validator: {
97
+ validate(value: unknown[]): boolean {
98
+ if (Array.isArray(value)) {
99
+ const propertyValues = value.map((v) => (typeof v === "object" && !!v ? v[property] : undefined));
100
+ return new Set(propertyValues).size === value.length;
101
+ }
102
+ return false;
103
+ },
104
+ defaultMessage(args: ValidationArguments): string {
105
+ return `${args.property} must not contains duplicate entry for ${args.constraints[0]}`;
106
+ }
107
+ }
108
+ });
109
+ };
110
+ }
111
+
112
+ export function IsBigNumber(validationOptions?: ValidationOptions) {
113
+ return function (object: object, propertyName: string) {
114
+ registerDecorator({
115
+ name: "IsBigNumber",
116
+ target: object.constructor,
117
+ propertyName,
118
+ options: validationOptions,
119
+ validator: {
120
+ validate(value: unknown) {
121
+ return BigNumber.isBigNumber(value);
122
+ },
123
+ defaultMessage(args: ValidationArguments) {
124
+ const bn =
125
+ typeof args.value === "string" || typeof args.value === "number"
126
+ ? new BigNumber(args.value)
127
+ : undefined;
128
+
129
+ const suggestion = bn && !bn.isNaN() ? ` (valid value: ${bn?.toFixed()})` : "";
130
+
131
+ return (
132
+ `${args.property} should be a stringified number with fixed notation (not an exponential notation) ` +
133
+ `and no trailing zeros in decimal part${suggestion}`
134
+ );
135
+ }
136
+ }
137
+ });
138
+ };
139
+ }
140
+
141
+ function validateBigNumberOrIgnore(obj: unknown, fn: (bn: BigNumber) => boolean): boolean {
142
+ if (BigNumber.isBigNumber(obj)) {
143
+ return fn(obj);
144
+ } else {
145
+ return true;
146
+ }
147
+ }
148
+
149
+ export function BigNumberIsPositive(validationOptions?: ValidationOptions) {
150
+ return function (object: object, propertyName: string) {
151
+ IsBigNumber(validationOptions)(object, propertyName);
152
+ registerDecorator({
153
+ name: "BigNumberIsPositive",
154
+ target: object.constructor,
155
+ propertyName,
156
+ options: validationOptions,
157
+ validator: {
158
+ validate(value: unknown) {
159
+ return validateBigNumberOrIgnore(value, (b) => b.isPositive());
160
+ },
161
+ defaultMessage(args: ValidationArguments) {
162
+ // here you can provide default error message if validation failed
163
+ return `${args.property} must be positive but is ${args.value?.toString() ?? args.value}`;
164
+ }
165
+ }
166
+ });
167
+ };
168
+ }
169
+
170
+ export function BigNumberIsNegative(validationOptions?: ValidationOptions) {
171
+ return function (object: object, propertyName: string) {
172
+ IsBigNumber(validationOptions)(object, propertyName);
173
+ registerDecorator({
174
+ name: "BigNumberIsNegative",
175
+ target: object.constructor,
176
+ propertyName,
177
+ options: validationOptions,
178
+ validator: {
179
+ validate(value: unknown) {
180
+ return validateBigNumberOrIgnore(value, (b) => b.isNegative());
181
+ },
182
+ defaultMessage(args: ValidationArguments) {
183
+ // here you can provide default error message if validation failed
184
+ return `${args.property} must be negative but is ${args.value?.toString() ?? args.value}`;
185
+ }
186
+ }
187
+ });
188
+ };
189
+ }
190
+
191
+ export function BigNumberIsNotInfinity(validationOptions?: ValidationOptions) {
192
+ return function (object: object, propertyName: string) {
193
+ IsBigNumber(validationOptions)(object, propertyName);
194
+ registerDecorator({
195
+ name: "BigNumberIsNotInfinity",
196
+ target: object.constructor,
197
+ propertyName,
198
+ options: validationOptions,
199
+ validator: {
200
+ validate(value: unknown) {
201
+ return validateBigNumberOrIgnore(value, (b) => b.isFinite());
202
+ },
203
+ defaultMessage(args: ValidationArguments) {
204
+ // here you can provide default error message if validation failed
205
+ return `${args.property} must be finite BigNumber but is ${args.value?.toString() ?? args.value}`;
206
+ }
207
+ }
208
+ });
209
+ };
210
+ }
211
+
212
+ export function BigNumberIsNotNegative(validationOptions?: ValidationOptions) {
213
+ return function (object: object, propertyName: string) {
214
+ IsBigNumber(validationOptions)(object, propertyName);
215
+ registerDecorator({
216
+ name: "BigNumberIsNotNegative",
217
+ target: object.constructor,
218
+ propertyName,
219
+ options: validationOptions,
220
+ validator: {
221
+ validate(value: unknown) {
222
+ return validateBigNumberOrIgnore(value, (b) => !b.isNegative());
223
+ },
224
+ defaultMessage(args: ValidationArguments) {
225
+ // here you can provide default error message if validation failed
226
+ return `${args.property} must be non-negative BigNumber but is ${
227
+ args.value?.toString() ?? args.value
228
+ }`;
229
+ }
230
+ }
231
+ });
232
+ };
233
+ }
234
+
235
+ export function BigNumberIsInteger(validationOptions?: ValidationOptions) {
236
+ return function (object: object, propertyName: string) {
237
+ IsBigNumber(validationOptions)(object, propertyName);
238
+ registerDecorator({
239
+ name: "BigNumberIsInteger",
240
+ target: object.constructor,
241
+ propertyName,
242
+ options: validationOptions,
243
+ validator: {
244
+ validate(value: unknown) {
245
+ return validateBigNumberOrIgnore(value, (b) => b.isInteger());
246
+ },
247
+ defaultMessage(args: ValidationArguments) {
248
+ // here you can provide default error message if validation failed
249
+ return `${args.property} must be integer BigNumber but is ${args.value?.toString() ?? args.value}`;
250
+ }
251
+ }
252
+ });
253
+ };
254
+ }
255
+
256
+ export function IsNonZeroBigNumber(validationOptions?: ValidationOptions) {
257
+ return function (object: object, propertyName: string) {
258
+ registerDecorator({
259
+ name: "isNonZeroBigNumber",
260
+ target: object.constructor,
261
+ propertyName: propertyName,
262
+ options: validationOptions,
263
+ validator: {
264
+ validate(value: unknown) {
265
+ return value instanceof BigNumber && !value.isZero();
266
+ },
267
+ defaultMessage(args: ValidationArguments) {
268
+ return `${args.property} must be a BigNumber and cannot be zero.`;
269
+ }
270
+ }
271
+ });
272
+ };
273
+ }
274
+
275
+ export function IsLessThan(property: string, validationOptions?: ValidationOptions) {
276
+ return function (object: object, propertyName: string) {
277
+ registerDecorator({
278
+ name: "isLessThan",
279
+ target: object.constructor,
280
+ propertyName: propertyName,
281
+ constraints: [property],
282
+ options: validationOptions,
283
+ validator: {
284
+ validate(value: unknown, args: ValidationArguments) {
285
+ const [relatedPropertyName] = args.constraints;
286
+ const relatedValue = (args.object as Record<string, unknown>)[relatedPropertyName];
287
+ return typeof value === "number" && typeof relatedValue === "number" && value < relatedValue;
288
+ },
289
+ defaultMessage(args: ValidationArguments) {
290
+ const [relatedPropertyName] = args.constraints;
291
+ return `${args.property} must be less than ${relatedPropertyName}`;
292
+ }
293
+ }
294
+ });
295
+ };
296
+ }
297
+
298
+ export function IsStringRecord(validationOptions?: ValidationOptions) {
299
+ return function (object: object, propertyName: string) {
300
+ registerDecorator({
301
+ name: "isStringRecord",
302
+ target: object.constructor,
303
+ propertyName,
304
+ options: validationOptions,
305
+ validator: {
306
+ validate(value: unknown) {
307
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
308
+
309
+ return Object.entries(value).every(
310
+ ([key, val]) => typeof key === "string" && typeof val === "string"
311
+ );
312
+ },
313
+ defaultMessage(args: ValidationArguments) {
314
+ return `${args.property} must be a Record<string, string>`;
315
+ }
316
+ }
317
+ });
318
+ };
319
+ }
320
+
321
+ export function IsStringArrayRecord(validationOptions?: ValidationOptions) {
322
+ return function (object: object, propertyName: string) {
323
+ registerDecorator({
324
+ name: "isStringArrayRecord",
325
+ target: object.constructor,
326
+ propertyName,
327
+ options: validationOptions,
328
+ validator: {
329
+ validate(value: unknown) {
330
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
331
+ return false;
332
+ }
333
+
334
+ return Object.entries(value).every(
335
+ ([key, val]) =>
336
+ typeof key === "string" && Array.isArray(val) && val.every((item) => typeof item === "string")
337
+ );
338
+ },
339
+ defaultMessage(args: ValidationArguments) {
340
+ return `${args.property} must be a Record<string, string[]>`;
341
+ }
342
+ }
343
+ });
344
+ };
345
+ }
346
+
347
+ export function BigNumberMax(maxValue: BigNumber.Value, options?: ValidationOptions) {
348
+ const max = new BigNumber(maxValue);
349
+
350
+ return function (object: object, propertyName: string) {
351
+ registerDecorator({
352
+ name: "BigNumberMax",
353
+ target: object.constructor,
354
+ propertyName,
355
+ options,
356
+ constraints: [max],
357
+ validator: {
358
+ validate(value: unknown): boolean {
359
+ try {
360
+ const bn = new BigNumber(value as BigNumber.Value);
361
+ return bn.isLessThanOrEqualTo(max);
362
+ } catch {
363
+ return false;
364
+ }
365
+ },
366
+
367
+ defaultMessage(args: ValidationArguments): string {
368
+ const [maxConstraint] = args.constraints as [BigNumber];
369
+ return `${args.property} must be ≤ ${maxConstraint.toFixed()}`;
370
+ }
371
+ }
372
+ });
373
+ };
374
+ }
375
+
376
+ export function BigNumberLessThanOrEqualOther(property: string, validationOptions?: ValidationOptions) {
377
+ return function (object: object, propertyName: string) {
378
+ registerDecorator({
379
+ name: "BigNumberLessThanOrEqualOther",
380
+ target: object.constructor,
381
+ propertyName: propertyName,
382
+ constraints: [property],
383
+ options: validationOptions,
384
+ validator: {
385
+ validate(value: unknown, args: ValidationArguments) {
386
+ const [relatedPropertyName] = args.constraints;
387
+ const relatedValue = (args.object as Record<string, unknown>)[relatedPropertyName];
388
+ if (!(value instanceof BigNumber) || !(relatedValue instanceof BigNumber)) {
389
+ return false;
390
+ }
391
+
392
+ return value.isLessThanOrEqualTo(relatedValue);
393
+ },
394
+ defaultMessage(args: ValidationArguments) {
395
+ const [relatedPropertyName] = args.constraints;
396
+ return `${args.property} must be less than or equal to ${relatedPropertyName}`;
397
+ }
398
+ }
399
+ });
400
+ };
401
+ }
@@ -0,0 +1,16 @@
1
+ /*
2
+ * Copyright (c) Gala Games Inc. All rights reserved.
3
+ * Licensed under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License.
5
+ * You may obtain a copy of the License at
6
+ *
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software
10
+ * distributed under the License is distributed on an "AS IS" BASIS,
11
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ * See the License for the specific language governing permissions and
13
+ * limitations under the License.
14
+ */
15
+
16
+ export * from "./decorators";
@@ -0,0 +1,211 @@
1
+ /*
2
+ * Copyright (c) Gala Games Inc. All rights reserved.
3
+ * Licensed under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License.
5
+ * You may obtain a copy of the License at
6
+ *
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software
10
+ * distributed under the License is distributed on an "AS IS" BASIS,
11
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ * See the License for the specific language governing permissions and
13
+ * limitations under the License.
14
+ */
15
+ import {
16
+ EVALUATE,
17
+ Evaluate,
18
+ GalaChainContext,
19
+ GalaContract,
20
+ GalaTransaction,
21
+ Submit
22
+ } from "@gala-chain/chaincode";
23
+
24
+ import { version } from "../../package.json";
25
+ import {
26
+ ConfigureLaunchpadFeeAddressDto,
27
+ CreateSaleResDto,
28
+ CreateTokenSaleDTO,
29
+ ExactTokenQuantityDto,
30
+ FetchSaleDto,
31
+ FinalizeTokenAllocationDto,
32
+ LaunchpadFeeConfig,
33
+ LaunchpadFinalizeFeeAllocation,
34
+ LaunchpadSale,
35
+ NativeTokenQuantityDto,
36
+ PreMintCalculationDto,
37
+ TradeCalculationResDto,
38
+ TradeResDto
39
+ } from "../api/types";
40
+ import {
41
+ buyExactTokenFeeGate,
42
+ buyWithNativeFeeGate,
43
+ createSaleFeeGate,
44
+ sellExactTokenFeeGate,
45
+ sellWithNativeFeeGate
46
+ } from "./dexLaunchpadFeeGate";
47
+ import {
48
+ buyExactToken,
49
+ buyWithNative,
50
+ calculatePreMintTokens,
51
+ callMemeTokenIn,
52
+ callMemeTokenOut,
53
+ callNativeTokenIn,
54
+ callNativeTokenOut,
55
+ configureLaunchpadFeeAddress,
56
+ createSale,
57
+ fetchLaunchpadFeeConfig,
58
+ fetchSaleDetails,
59
+ finalizeTokenAllocation,
60
+ sellExactToken,
61
+ sellWithNative
62
+ } from "./launchpad";
63
+
64
+ export class LaunchpadContract extends GalaContract {
65
+ constructor() {
66
+ super("Launchpad", version);
67
+ }
68
+
69
+ @Submit({
70
+ in: CreateTokenSaleDTO,
71
+ out: CreateSaleResDto,
72
+ before: createSaleFeeGate
73
+ })
74
+ public async CreateSale(ctx: GalaChainContext, dto: CreateTokenSaleDTO): Promise<CreateSaleResDto> {
75
+ return createSale(ctx, dto);
76
+ }
77
+
78
+ @GalaTransaction({
79
+ type: EVALUATE,
80
+ in: FetchSaleDto,
81
+ out: LaunchpadSale
82
+ })
83
+ public async FetchSaleDetails(ctx: GalaChainContext, dto: FetchSaleDto): Promise<LaunchpadSale> {
84
+ return fetchSaleDetails(ctx, dto);
85
+ }
86
+
87
+ @Submit({
88
+ in: ExactTokenQuantityDto,
89
+ out: TradeResDto,
90
+ before: buyExactTokenFeeGate
91
+ })
92
+ public async BuyExactToken(ctx: GalaChainContext, dto: ExactTokenQuantityDto): Promise<TradeResDto> {
93
+ return buyExactToken(ctx, dto);
94
+ }
95
+
96
+ @Submit({
97
+ in: ExactTokenQuantityDto,
98
+ out: TradeResDto,
99
+ before: sellExactTokenFeeGate
100
+ })
101
+ public async SellExactToken(ctx: GalaChainContext, dto: ExactTokenQuantityDto): Promise<TradeResDto> {
102
+ return sellExactToken(ctx, dto);
103
+ }
104
+
105
+ @Submit({
106
+ in: NativeTokenQuantityDto,
107
+ out: TradeResDto,
108
+ before: buyWithNativeFeeGate
109
+ })
110
+ public async BuyWithNative(ctx: GalaChainContext, dto: NativeTokenQuantityDto): Promise<TradeResDto> {
111
+ return buyWithNative(ctx, dto);
112
+ }
113
+
114
+ @Submit({
115
+ in: NativeTokenQuantityDto,
116
+ out: TradeResDto,
117
+ before: sellWithNativeFeeGate
118
+ })
119
+ public async SellWithNative(ctx: GalaChainContext, dto: NativeTokenQuantityDto): Promise<TradeResDto> {
120
+ return sellWithNative(ctx, dto);
121
+ }
122
+
123
+ @Submit({
124
+ in: ConfigureLaunchpadFeeAddressDto,
125
+ out: LaunchpadFeeConfig,
126
+ allowedOrgs: ["CuratorOrg"]
127
+ })
128
+ public async ConfigureLaunchpadFeeAddress(
129
+ ctx: GalaChainContext,
130
+ dto: ConfigureLaunchpadFeeAddressDto
131
+ ): Promise<LaunchpadFeeConfig> {
132
+ return configureLaunchpadFeeAddress(ctx, dto);
133
+ }
134
+
135
+ @Submit({
136
+ in: FinalizeTokenAllocationDto,
137
+ out: LaunchpadFinalizeFeeAllocation,
138
+ allowedOrgs: ["CuratorOrg"]
139
+ })
140
+ public async FinalizeTokenAllocation(
141
+ ctx: GalaChainContext,
142
+ dto: FinalizeTokenAllocationDto
143
+ ): Promise<LaunchpadFinalizeFeeAllocation> {
144
+ return finalizeTokenAllocation(ctx, dto);
145
+ }
146
+
147
+ @GalaTransaction({
148
+ type: EVALUATE,
149
+ in: ExactTokenQuantityDto,
150
+ out: TradeCalculationResDto
151
+ })
152
+ public async CallNativeTokenIn(
153
+ ctx: GalaChainContext,
154
+ dto: ExactTokenQuantityDto
155
+ ): Promise<TradeCalculationResDto> {
156
+ return callNativeTokenIn(ctx, dto);
157
+ }
158
+
159
+ @GalaTransaction({
160
+ type: EVALUATE,
161
+ in: NativeTokenQuantityDto,
162
+ out: TradeCalculationResDto
163
+ })
164
+ public async CallMemeTokenOut(
165
+ ctx: GalaChainContext,
166
+ dto: NativeTokenQuantityDto
167
+ ): Promise<TradeCalculationResDto> {
168
+ return callMemeTokenOut(ctx, dto);
169
+ }
170
+
171
+ @GalaTransaction({
172
+ type: EVALUATE,
173
+ in: ExactTokenQuantityDto,
174
+ out: TradeCalculationResDto
175
+ })
176
+ public async CallNativeTokenOut(
177
+ ctx: GalaChainContext,
178
+ dto: ExactTokenQuantityDto
179
+ ): Promise<TradeCalculationResDto> {
180
+ return callNativeTokenOut(ctx, dto);
181
+ }
182
+
183
+ @GalaTransaction({
184
+ type: EVALUATE,
185
+ in: NativeTokenQuantityDto,
186
+ out: TradeCalculationResDto
187
+ })
188
+ public async CallMemeTokenIn(
189
+ ctx: GalaChainContext,
190
+ dto: NativeTokenQuantityDto
191
+ ): Promise<TradeCalculationResDto> {
192
+ return callMemeTokenIn(ctx, dto);
193
+ }
194
+
195
+ @GalaTransaction({
196
+ type: EVALUATE,
197
+ in: PreMintCalculationDto,
198
+ out: String
199
+ })
200
+ public async CalculatePreMintTokens(dto: PreMintCalculationDto): Promise<string> {
201
+ return calculatePreMintTokens(dto);
202
+ }
203
+
204
+ @Evaluate({
205
+ out: LaunchpadFeeConfig,
206
+ allowedOrgs: ["CuratorOrg"]
207
+ })
208
+ public async FetchLaunchpadFeeConfig(ctx: GalaChainContext): Promise<LaunchpadFeeConfig> {
209
+ return fetchLaunchpadFeeConfig(ctx);
210
+ }
211
+ }
@@ -0,0 +1,43 @@
1
+ /*
2
+ * Copyright (c) Gala Games Inc. All rights reserved.
3
+ * Licensed under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License.
5
+ * You may obtain a copy of the License at
6
+ *
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software
10
+ * distributed under the License is distributed on an "AS IS" BASIS,
11
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ * See the License for the specific language governing permissions and
13
+ * limitations under the License.
14
+ */
15
+ import { GalaChainContext, galaFeeGate } from "@gala-chain/chaincode";
16
+
17
+ export enum FeeGateCodes {
18
+ CreateSale = "CreateSale",
19
+ BuyExactToken = "BuyExactToken",
20
+ SellExactToken = "SellExactToken",
21
+ BuyWithNative = "BuyWithNative",
22
+ SellWithNative = "SellWithNative"
23
+ }
24
+
25
+ export async function createSaleFeeGate(ctx: GalaChainContext) {
26
+ return galaFeeGate(ctx, { feeCode: FeeGateCodes.CreateSale });
27
+ }
28
+
29
+ export async function buyExactTokenFeeGate(ctx: GalaChainContext) {
30
+ return galaFeeGate(ctx, { feeCode: FeeGateCodes.BuyExactToken });
31
+ }
32
+
33
+ export async function sellExactTokenFeeGate(ctx: GalaChainContext) {
34
+ return galaFeeGate(ctx, { feeCode: FeeGateCodes.SellExactToken });
35
+ }
36
+
37
+ export async function buyWithNativeFeeGate(ctx: GalaChainContext) {
38
+ return galaFeeGate(ctx, { feeCode: FeeGateCodes.BuyWithNative });
39
+ }
40
+
41
+ export async function sellWithNativeFeeGate(ctx: GalaChainContext) {
42
+ return galaFeeGate(ctx, { feeCode: FeeGateCodes.SellWithNative });
43
+ }
@@ -0,0 +1,16 @@
1
+ /*
2
+ * Copyright (c) Gala Games Inc. All rights reserved.
3
+ * Licensed under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License.
5
+ * You may obtain a copy of the License at
6
+ *
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software
10
+ * distributed under the License is distributed on an "AS IS" BASIS,
11
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ * See the License for the specific language governing permissions and
13
+ * limitations under the License.
14
+ */
15
+
16
+ export * from "./LaunchpadContract";