@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,76 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.callMemeTokenIn = void 0;
4
+ const tslib_1 = require("tslib");
5
+ /*
6
+ * Copyright (c) Gala Games Inc. All rights reserved.
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+ const api_1 = require("@gala-chain/api");
20
+ const bignumber_js_1 = require("bignumber.js");
21
+ const decimal_js_1 = tslib_1.__importDefault(require("decimal.js"));
22
+ const utils_1 = require("../utils");
23
+ const fees_1 = require("./fees");
24
+ bignumber_js_1.BigNumber.config({
25
+ ROUNDING_MODE: bignumber_js_1.BigNumber.ROUND_UP
26
+ });
27
+ function calculateMemeTokensRequired(sale, requestedNativeTokenQuantity) {
28
+ const totalTokensSold = new decimal_js_1.default(sale.fetchTokensSold()); // current tokens sold / x
29
+ let nativeTokens = new decimal_js_1.default(requestedNativeTokenQuantity.toString()); // native tokens used to buy / y
30
+ const basePrice = new decimal_js_1.default(sale.fetchBasePrice()); // base price / a
31
+ const { exponentFactor, euler, decimals } = (0, utils_1.getBondingConstants)();
32
+ const nativeTokenInVault = new decimal_js_1.default(sale.nativeTokenQuantity);
33
+ if (nativeTokens.greaterThan(nativeTokenInVault)) {
34
+ nativeTokens = nativeTokenInVault;
35
+ }
36
+ const exponent = exponentFactor.mul(totalTokensSold).div(decimals);
37
+ const exp1 = euler.pow(exponent);
38
+ const constantFactor = nativeTokens.mul(exponentFactor).div(basePrice);
39
+ if (exp1.lte(constantFactor)) {
40
+ throw new api_1.ValidationFailedError("Cannot sell more tokens than have been bought in this sale.");
41
+ }
42
+ const adjustedExp = exp1.minus(constantFactor);
43
+ const lnAdjustedExp = adjustedExp.ln();
44
+ const tokensSent = totalTokensSold.minus(lnAdjustedExp.mul(decimals).div(exponentFactor));
45
+ const roundedTokenSent = tokensSent.toDecimalPlaces(18, decimal_js_1.default.ROUND_UP);
46
+ return roundedTokenSent.toFixed();
47
+ }
48
+ /**
49
+ * Calculates the number of tokens that can be sold in exchange for a specified amount
50
+ * of native tokens using a bonding curve mechanism.
51
+ *
52
+ * This function retrieves the sale details and applies the bonding curve formula
53
+ * to determine the number of tokens the user can sell based on the provided native token amount.
54
+ *
55
+ * @param ctx - The context object that provides access to the GalaChain environment.
56
+ * @param sellTokenDTO - An object containing the sale details:
57
+ * - `vaultAddress`: The address of the sale.
58
+ * - `nativeTokenAmount`: The amount of native tokens to be recieved from sale.
59
+ * - `expectedToken` (optional): The expected amount of tokens to be sold.
60
+ *
61
+ * @returns A promise that resolves to a string representing the calculated amount of
62
+ * tokens to be sent, rounded up to 18 decimal places.
63
+ *
64
+ * @throws Error if the calculation results in an invalid amount (e.g., `InvalidAmountError`).
65
+ */
66
+ async function callMemeTokenIn(ctx, sellTokenDTO) {
67
+ const sale = await (0, utils_1.fetchAndValidateSale)(ctx, sellTokenDTO.vaultAddress);
68
+ return {
69
+ calculatedQuantity: calculateMemeTokensRequired(sale, sellTokenDTO.nativeTokenQuantity),
70
+ extraFees: {
71
+ reverseBondingCurve: (0, fees_1.calculateReverseBondingCurveFee)(sale, sellTokenDTO.nativeTokenQuantity).toString()
72
+ }
73
+ };
74
+ }
75
+ exports.callMemeTokenIn = callMemeTokenIn;
76
+ //# sourceMappingURL=callMemeTokenIn.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"callMemeTokenIn.js","sourceRoot":"","sources":["../../../../src/chaincode/launchpad/callMemeTokenIn.ts"],"names":[],"mappings":";;;;AAAA;;;;;;;;;;;;;GAaG;AACH,yCAAwD;AAExD,+CAAyC;AACzC,oEAAiC;AAGjC,oCAAqE;AACrE,iCAAyD;AAEzD,wBAAS,CAAC,MAAM,CAAC;IACf,aAAa,EAAE,wBAAS,CAAC,QAAQ;CAClC,CAAC,CAAC;AAEH,SAAS,2BAA2B,CAAC,IAAmB,EAAE,4BAAuC;IAC/F,MAAM,eAAe,GAAG,IAAI,oBAAO,CAAC,IAAI,CAAC,eAAe,EAAE,CAAC,CAAC,CAAC,0BAA0B;IACvF,IAAI,YAAY,GAAG,IAAI,oBAAO,CAAC,4BAA4B,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,gCAAgC;IACzG,MAAM,SAAS,GAAG,IAAI,oBAAO,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC,CAAC,CAAC,iBAAiB;IACvE,MAAM,EAAE,cAAc,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,IAAA,2BAAmB,GAAE,CAAC;IAElE,MAAM,kBAAkB,GAAG,IAAI,oBAAO,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;IACjE,IAAI,YAAY,CAAC,WAAW,CAAC,kBAAkB,CAAC,EAAE,CAAC;QACjD,YAAY,GAAG,kBAAkB,CAAC;IACpC,CAAC;IAED,MAAM,QAAQ,GAAG,cAAc,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACnE,MAAM,IAAI,GAAG,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACjC,MAAM,cAAc,GAAG,YAAY,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IAEvE,IAAI,IAAI,CAAC,GAAG,CAAC,cAAc,CAAC,EAAE,CAAC;QAC7B,MAAM,IAAI,2BAAqB,CAAC,6DAA6D,CAAC,CAAC;IACjG,CAAC;IAED,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;IAC/C,MAAM,aAAa,GAAG,WAAW,CAAC,EAAE,EAAE,CAAC;IACvC,MAAM,UAAU,GAAG,eAAe,CAAC,KAAK,CAAC,aAAa,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,CAAC;IAC1F,MAAM,gBAAgB,GAAG,UAAU,CAAC,eAAe,CAAC,EAAE,EAAE,oBAAO,CAAC,QAAQ,CAAC,CAAC;IAE1E,OAAO,gBAAgB,CAAC,OAAO,EAAE,CAAC;AACpC,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACI,KAAK,UAAU,eAAe,CAAC,GAAqB,EAAE,YAAoC;IAC/F,MAAM,IAAI,GAAG,MAAM,IAAA,4BAAoB,EAAC,GAAG,EAAE,YAAY,CAAC,YAAY,CAAC,CAAC;IAExE,OAAO;QACL,kBAAkB,EAAE,2BAA2B,CAAC,IAAI,EAAE,YAAY,CAAC,mBAAmB,CAAC;QACvF,SAAS,EAAE;YACT,mBAAmB,EAAE,IAAA,sCAA+B,EAAC,IAAI,EAAE,YAAY,CAAC,mBAAmB,CAAC,CAAC,QAAQ,EAAE;SACxG;KACF,CAAC;AACJ,CAAC;AATD,0CASC"}
@@ -0,0 +1,25 @@
1
+ import { GalaChainContext } from "@gala-chain/chaincode";
2
+ import { NativeTokenQuantityDto } from "../../api/types";
3
+ /**
4
+ * Calculates the number of tokens that can be purchased using a specified amount
5
+ * of native tokens based on a bonding curve mechanism.
6
+ *
7
+ * This function retrieves the sale details and applies the bonding curve formula
8
+ * to determine the number of tokens the user can buy with the provided native token amount.
9
+ *
10
+ * @param ctx - The context object providing access to the GalaChain environment.
11
+ * @param buyTokenDTO - The data transfer object containing the sale address
12
+ * and the amount of native tokens to spend for the purchase.
13
+ *
14
+ * @returns A promise that resolves to a string representing the calculated amount of
15
+ * tokens to be received, rounded down to 18 decimal places.
16
+ *
17
+ * @throws Error if the calculation results in an invalid state.
18
+ */
19
+ export declare function callMemeTokenOut(ctx: GalaChainContext, buyTokenDTO: NativeTokenQuantityDto): Promise<{
20
+ calculatedQuantity: string;
21
+ extraFees: {
22
+ reverseBondingCurve: string;
23
+ };
24
+ }>;
25
+ //# sourceMappingURL=callMemeTokenOut.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"callMemeTokenOut.d.ts","sourceRoot":"","sources":["../../../../src/chaincode/launchpad/callMemeTokenOut.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAIzD,OAAO,EAAiB,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAOxE;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,gBAAgB,CAAC,GAAG,EAAE,gBAAgB,EAAE,WAAW,EAAE,sBAAsB;;;;;GAsChG"}
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.callMemeTokenOut = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const bignumber_js_1 = require("bignumber.js");
6
+ const decimal_js_1 = tslib_1.__importDefault(require("decimal.js"));
7
+ const types_1 = require("../../api/types");
8
+ const utils_1 = require("../utils");
9
+ bignumber_js_1.BigNumber.config({
10
+ ROUNDING_MODE: bignumber_js_1.BigNumber.ROUND_UP
11
+ });
12
+ /**
13
+ * Calculates the number of tokens that can be purchased using a specified amount
14
+ * of native tokens based on a bonding curve mechanism.
15
+ *
16
+ * This function retrieves the sale details and applies the bonding curve formula
17
+ * to determine the number of tokens the user can buy with the provided native token amount.
18
+ *
19
+ * @param ctx - The context object providing access to the GalaChain environment.
20
+ * @param buyTokenDTO - The data transfer object containing the sale address
21
+ * and the amount of native tokens to spend for the purchase.
22
+ *
23
+ * @returns A promise that resolves to a string representing the calculated amount of
24
+ * tokens to be received, rounded down to 18 decimal places.
25
+ *
26
+ * @throws Error if the calculation results in an invalid state.
27
+ */
28
+ async function callMemeTokenOut(ctx, buyTokenDTO) {
29
+ const sale = await (0, utils_1.fetchAndValidateSale)(ctx, buyTokenDTO.vaultAddress);
30
+ const totalTokensSold = new decimal_js_1.default(sale.fetchTokensSold()); // current tokens sold / x
31
+ let nativeTokens = new decimal_js_1.default(buyTokenDTO.nativeTokenQuantity.toString()); // native tokens used to buy / y
32
+ const basePrice = new decimal_js_1.default(sale.fetchBasePrice()); // base price / a
33
+ const { exponentFactor, euler, decimals } = (0, utils_1.getBondingConstants)();
34
+ if (nativeTokens.add(new decimal_js_1.default(sale.nativeTokenQuantity)).greaterThan(new decimal_js_1.default(types_1.LaunchpadSale.MARKET_CAP))) {
35
+ nativeTokens = new decimal_js_1.default(types_1.LaunchpadSale.MARKET_CAP).minus(new decimal_js_1.default(sale.nativeTokenQuantity));
36
+ }
37
+ const constant = nativeTokens.mul(exponentFactor).div(basePrice);
38
+ const exponent1 = exponentFactor.mul(totalTokensSold).div(decimals);
39
+ const eResult1 = euler.pow(exponent1);
40
+ const ethScaled = constant.add(eResult1);
41
+ const lnEthScaled = ethScaled.ln().mul(decimals);
42
+ const lnEthScaledBase = lnEthScaled.div(exponentFactor);
43
+ const result = lnEthScaledBase.minus(totalTokensSold);
44
+ let roundedResult = result.toDecimalPlaces(18, decimal_js_1.default.ROUND_DOWN);
45
+ if (roundedResult.add(totalTokensSold).greaterThan(new decimal_js_1.default("1e+7"))) {
46
+ roundedResult = new decimal_js_1.default("1e+7").minus(new decimal_js_1.default(totalTokensSold));
47
+ }
48
+ return {
49
+ calculatedQuantity: roundedResult.toFixed(),
50
+ extraFees: {
51
+ reverseBondingCurve: "0"
52
+ }
53
+ };
54
+ }
55
+ exports.callMemeTokenOut = callMemeTokenOut;
56
+ //# sourceMappingURL=callMemeTokenOut.js.map
@@ -0,0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jE,MAAM,SAAS,GAAG,cAAc,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAEpE,MAAM,QAAQ,GAAG,KAAK,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IAEtC,MAAM,SAAS,GAAG,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAEzC,MAAM,WAAW,GAAG,SAAS,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAEjD,MAAM,eAAe,GAAG,WAAW,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;IAExD,MAAM,MAAM,GAAG,eAAe,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;IACtD,IAAI,aAAa,GAAG,MAAM,CAAC,eAAe,CAAC,EAAE,EAAE,oBAAO,CAAC,UAAU,CAAC,CAAC;IAEnE,IAAI,aAAa,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC,WAAW,CAAC,IAAI,oBAAO,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC;QACxE,aAAa,GAAG,IAAI,oBAAO,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,IAAI,oBAAO,CAAC,eAAe,CAAC,CAAC,CAAC;IAC1E,CAAC;IAED,OAAO;QACL,kBAAkB,EAAE,aAAa,CAAC,OAAO,EAAE;QAC3C,SAAS,EAAE;YACT,mBAAmB,EAAE,GAAG;SACzB;KACF,CAAC;AACJ,CAAC;AAtCD,4CAsCC"}
@@ -0,0 +1,25 @@
1
+ import { GalaChainContext } from "@gala-chain/chaincode";
2
+ import { ExactTokenQuantityDto } from "../../api/types";
3
+ /**
4
+ * Calculates the amount of native tokens required to purchase a specified amount
5
+ * of tokens using a bonding curve mechanism.
6
+ *
7
+ * This function retrieves the sale details and applies the bonding curve formula
8
+ * to determine the cost in native tokens for the given token amount.
9
+ *
10
+ * @param ctx - The context object providing access to the GalaChain environment.
11
+ * @param buyTokenDTO - The data transfer object containing the sale address
12
+ * and the exact amount of tokens to be purchased.
13
+ *
14
+ * @returns A promise that resolves to a string representing the calculated amount of
15
+ * native tokens required for the purchase, rounded up to 8 decimal places.
16
+ *
17
+ * @throws Error if the calculation encounters an invalid state or data.
18
+ */
19
+ export declare function callNativeTokenIn(ctx: GalaChainContext, buyTokenDTO: ExactTokenQuantityDto): Promise<{
20
+ calculatedQuantity: string;
21
+ extraFees: {
22
+ reverseBondingCurve: string;
23
+ };
24
+ }>;
25
+ //# sourceMappingURL=callNativeTokenIn.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"callNativeTokenIn.d.ts","sourceRoot":"","sources":["../../../../src/chaincode/launchpad/callNativeTokenIn.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAIzD,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAOxD;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,iBAAiB,CAAC,GAAG,EAAE,gBAAgB,EAAE,WAAW,EAAE,qBAAqB;;;;;GA6BhG"}
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.callNativeTokenIn = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const bignumber_js_1 = require("bignumber.js");
6
+ const decimal_js_1 = tslib_1.__importDefault(require("decimal.js"));
7
+ const utils_1 = require("../utils");
8
+ bignumber_js_1.BigNumber.config({
9
+ ROUNDING_MODE: bignumber_js_1.BigNumber.ROUND_UP
10
+ });
11
+ /**
12
+ * Calculates the amount of native tokens required to purchase a specified amount
13
+ * of tokens using a bonding curve mechanism.
14
+ *
15
+ * This function retrieves the sale details and applies the bonding curve formula
16
+ * to determine the cost in native tokens for the given token amount.
17
+ *
18
+ * @param ctx - The context object providing access to the GalaChain environment.
19
+ * @param buyTokenDTO - The data transfer object containing the sale address
20
+ * and the exact amount of tokens to be purchased.
21
+ *
22
+ * @returns A promise that resolves to a string representing the calculated amount of
23
+ * native tokens required for the purchase, rounded up to 8 decimal places.
24
+ *
25
+ * @throws Error if the calculation encounters an invalid state or data.
26
+ */
27
+ async function callNativeTokenIn(ctx, buyTokenDTO) {
28
+ const sale = await (0, utils_1.fetchAndValidateSale)(ctx, buyTokenDTO.vaultAddress);
29
+ const totalTokensSold = new decimal_js_1.default(sale.fetchTokensSold());
30
+ let tokensToBuy = new decimal_js_1.default(buyTokenDTO.tokenQuantity.toString());
31
+ const basePrice = new decimal_js_1.default(sale.fetchBasePrice());
32
+ const { exponentFactor, euler, decimals } = (0, utils_1.getBondingConstants)();
33
+ if (tokensToBuy.add(totalTokensSold).greaterThan(new decimal_js_1.default("1e+7"))) {
34
+ tokensToBuy = new decimal_js_1.default(sale.sellingTokenQuantity);
35
+ }
36
+ const exponent1 = exponentFactor.mul(totalTokensSold.add(tokensToBuy)).div(decimals);
37
+ const exponent2 = exponentFactor.mul(totalTokensSold).div(decimals);
38
+ const eResult1 = euler.pow(exponent1);
39
+ const eResult2 = euler.pow(exponent2);
40
+ const constantFactor = basePrice.div(exponentFactor);
41
+ const differenceOfExponentials = eResult1.minus(eResult2);
42
+ const price = constantFactor.mul(differenceOfExponentials);
43
+ return {
44
+ calculatedQuantity: price.toDecimalPlaces(8, decimal_js_1.default.ROUND_UP).toFixed(),
45
+ extraFees: {
46
+ reverseBondingCurve: "0"
47
+ }
48
+ };
49
+ }
50
+ exports.callNativeTokenIn = callNativeTokenIn;
51
+ //# sourceMappingURL=callNativeTokenIn.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"callNativeTokenIn.js","sourceRoot":"","sources":["../../../../src/chaincode/launchpad/callNativeTokenIn.ts"],"names":[],"mappings":";;;;AAeA,+CAAyC;AACzC,oEAAiC;AAGjC,oCAAqE;AAErE,wBAAS,CAAC,MAAM,CAAC;IACf,aAAa,EAAE,wBAAS,CAAC,QAAQ;CAClC,CAAC,CAAC;AAEH;;;;;;;;;;;;;;;GAeG;AACI,KAAK,UAAU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AC;IAE3D,OAAO;QACL,kBAAkB,EAAE,KAAK,CAAC,eAAe,CAAC,CAAC,EAAE,oBAAO,CAAC,QAAQ,CAAC,CAAC,OAAO,EAAE;QACxE,SAAS,EAAE;YACT,mBAAmB,EAAE,GAAG;SACzB;KACF,CAAC;AACJ,CAAC;AA7BD,8CA6BC"}
@@ -0,0 +1,26 @@
1
+ import { GalaChainContext } from "@gala-chain/chaincode";
2
+ import { ExactTokenQuantityDto } from "../../api/types";
3
+ /**
4
+ * Calculates the amount of native tokens a user would receive when selling
5
+ * a specified amount of tokens based on a bonding curve mechanism.
6
+ *
7
+ * This function retrieves the sale details and applies the bonding curve formula
8
+ * to determine the value in native tokens for the given token amount.
9
+ *
10
+ * @param ctx - The context object providing access to the GalaChain environment.
11
+ * @param sellTokenDTO - The data transfer object containing the sale address
12
+ * and the exact amount of tokens to be sold.
13
+ *
14
+ * @returns A promise that resolves to a string representing the calculated amount of
15
+ * native tokens to be received, rounded down to 8 decimal places.
16
+ *
17
+ * @throws DefaultError if the calculated new total tokens sold is less than zero
18
+ * or if the input amount is invalid.
19
+ */
20
+ export declare function callNativeTokenOut(ctx: GalaChainContext, sellTokenDTO: ExactTokenQuantityDto): Promise<{
21
+ calculatedQuantity: string;
22
+ extraFees: {
23
+ reverseBondingCurve: string;
24
+ };
25
+ }>;
26
+ //# sourceMappingURL=callNativeTokenOut.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"callNativeTokenOut.d.ts","sourceRoot":"","sources":["../../../../src/chaincode/launchpad/callNativeTokenOut.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAIzD,OAAO,EAAE,qBAAqB,EAAiB,MAAM,iBAAiB,CAAC;AAoCvE;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,kBAAkB,CAAC,GAAG,EAAE,gBAAgB,EAAE,YAAY,EAAE,qBAAqB;;;;;GASlG"}
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.callNativeTokenOut = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const bignumber_js_1 = require("bignumber.js");
6
+ const decimal_js_1 = tslib_1.__importDefault(require("decimal.js"));
7
+ const utils_1 = require("../utils");
8
+ const fees_1 = require("./fees");
9
+ bignumber_js_1.BigNumber.config({
10
+ ROUNDING_MODE: bignumber_js_1.BigNumber.ROUND_UP
11
+ });
12
+ function calculateNativeTokensReceived(sale, tokensToSellBn) {
13
+ const totalTokensSold = new decimal_js_1.default(sale.fetchTokensSold());
14
+ let tokensToSell = new decimal_js_1.default(tokensToSellBn.toString());
15
+ const basePrice = new decimal_js_1.default(sale.fetchBasePrice());
16
+ const { exponentFactor, euler, decimals } = (0, utils_1.getBondingConstants)();
17
+ let newTotalTokensSold = totalTokensSold.minus(tokensToSell);
18
+ if (newTotalTokensSold.comparedTo(0) < 0) {
19
+ tokensToSell = totalTokensSold;
20
+ newTotalTokensSold = new decimal_js_1.default(0);
21
+ }
22
+ const exponent1 = exponentFactor.mul(newTotalTokensSold.add(tokensToSell)).div(decimals);
23
+ const exponent2 = exponentFactor.mul(newTotalTokensSold).div(decimals);
24
+ const eResult1 = euler.pow(exponent1);
25
+ const eResult2 = euler.pow(exponent2);
26
+ const constantFactor = basePrice.div(exponentFactor);
27
+ const differenceOfExponentials = eResult1.minus(eResult2);
28
+ const price = constantFactor.mul(differenceOfExponentials);
29
+ const roundedPrice = price.toDecimalPlaces(8, decimal_js_1.default.ROUND_DOWN);
30
+ return roundedPrice.toFixed();
31
+ }
32
+ /**
33
+ * Calculates the amount of native tokens a user would receive when selling
34
+ * a specified amount of tokens based on a bonding curve mechanism.
35
+ *
36
+ * This function retrieves the sale details and applies the bonding curve formula
37
+ * to determine the value in native tokens for the given token amount.
38
+ *
39
+ * @param ctx - The context object providing access to the GalaChain environment.
40
+ * @param sellTokenDTO - The data transfer object containing the sale address
41
+ * and the exact amount of tokens to be sold.
42
+ *
43
+ * @returns A promise that resolves to a string representing the calculated amount of
44
+ * native tokens to be received, rounded down to 8 decimal places.
45
+ *
46
+ * @throws DefaultError if the calculated new total tokens sold is less than zero
47
+ * or if the input amount is invalid.
48
+ */
49
+ async function callNativeTokenOut(ctx, sellTokenDTO) {
50
+ const sale = await (0, utils_1.fetchAndValidateSale)(ctx, sellTokenDTO.vaultAddress);
51
+ const nativeTokensReceived = calculateNativeTokensReceived(sale, sellTokenDTO.tokenQuantity);
52
+ return {
53
+ calculatedQuantity: nativeTokensReceived,
54
+ extraFees: {
55
+ reverseBondingCurve: (0, fees_1.calculateReverseBondingCurveFee)(sale, (0, bignumber_js_1.BigNumber)(nativeTokensReceived)).toString()
56
+ }
57
+ };
58
+ }
59
+ exports.callNativeTokenOut = callNativeTokenOut;
60
+ //# sourceMappingURL=callNativeTokenOut.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"callNativeTokenOut.js","sourceRoot":"","sources":["../../../../src/chaincode/launchpad/callNativeTokenOut.ts"],"names":[],"mappings":";;;;AAeA,+CAAyC;AACzC,oEAAiC;AAGjC,oCAAqE;AACrE,iCAAyD;AAEzD,wBAAS,CAAC,MAAM,CAAC;IACf,aAAa,EAAE,wBAAS,CAAC,QAAQ;CAClC,CAAC,CAAC;AAEH,SAAS,6BAA6B,CAAC,IAAmB,EAAE,cAAyB;IACnF,MAAM,eAAe,GAAG,IAAI,oBAAO,CAAC,IAAI,CAAC,eAAe,EAAE,CAAC,CAAC;IAE5D,IAAI,YAAY,GAAG,IAAI,oBAAO,CAAC,cAAc,CAAC,QAAQ,EAAE,CAAC,CAAC;IAC1D,MAAM,SAAS,GAAG,IAAI,oBAAO,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC,CAAC;IACrD,MAAM,EAAE,cAAc,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,IAAA,2BAAmB,GAAE,CAAC;IAElE,IAAI,kBAAkB,GAAG,eAAe,CAAC,KAAK,CAAC,YAAY,CAAC,CA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AE,IAAA,sCAA+B,EAAC,IAAI,EAAE,IAAA,wBAAS,EAAC,oBAAoB,CAAC,CAAC,CAAC,QAAQ,EAAE;SACvG;KACF,CAAC;AACJ,CAAC;AATD,gDASC"}
@@ -0,0 +1,4 @@
1
+ import { GalaChainContext } from "@gala-chain/chaincode";
2
+ import { ConfigureLaunchpadFeeAddressDto, LaunchpadFeeConfig } from "../../api/types";
3
+ export declare function configureLaunchpadFeeAddress(ctx: GalaChainContext, dto: ConfigureLaunchpadFeeAddressDto): Promise<LaunchpadFeeConfig>;
4
+ //# sourceMappingURL=configureLaunchpadFeeConfig.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"configureLaunchpadFeeConfig.d.ts","sourceRoot":"","sources":["../../../../src/chaincode/launchpad/configureLaunchpadFeeConfig.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAGzD,OAAO,EAAE,+BAA+B,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAEtF,wBAAsB,4BAA4B,CAChD,GAAG,EAAE,gBAAgB,EACrB,GAAG,EAAE,+BAA+B,GACnC,OAAO,CAAC,kBAAkB,CAAC,CA6C7B"}
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.configureLaunchpadFeeAddress = void 0;
4
+ /*
5
+ * Copyright (c) Gala Games Inc. All rights reserved.
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+ const api_1 = require("@gala-chain/api");
19
+ const chaincode_1 = require("@gala-chain/chaincode");
20
+ const types_1 = require("../../api/types");
21
+ async function configureLaunchpadFeeAddress(ctx, dto) {
22
+ var _a, _b, _c, _d, _e;
23
+ if (!dto.newPlatformFeeAddress && !((_a = dto.newAuthorities) === null || _a === void 0 ? void 0 : _a.length)) {
24
+ throw new api_1.ValidationFailedError("None of the input fields are present.");
25
+ }
26
+ const curatorOrgMsp = (_b = process.env.CURATOR_ORG_MSP) !== null && _b !== void 0 ? _b : "CuratorOrg";
27
+ const key = ctx.stub.createCompositeKey(types_1.LaunchpadFeeConfig.INDEX_KEY, []);
28
+ let platformFeeAddress = await (0, chaincode_1.getObjectByKey)(ctx, types_1.LaunchpadFeeConfig, key).catch((e) => {
29
+ const chainError = api_1.ChainError.from(e);
30
+ if (chainError.matches(api_1.ErrorCode.NOT_FOUND)) {
31
+ return undefined;
32
+ }
33
+ else {
34
+ throw chainError;
35
+ }
36
+ });
37
+ if (ctx.clientIdentity.getMSPID() !== curatorOrgMsp) {
38
+ if (!platformFeeAddress || !platformFeeAddress.authorities.includes(ctx.callingUser)) {
39
+ throw new api_1.UnauthorizedError(`CallingUser ${ctx.callingUser} is not authorized to create or update`);
40
+ }
41
+ }
42
+ if (!platformFeeAddress) {
43
+ if (!dto.newPlatformFeeAddress) {
44
+ throw new api_1.ValidationFailedError("Must provide a platform fee address in the initial setup of the configuration.");
45
+ }
46
+ platformFeeAddress = new types_1.LaunchpadFeeConfig(dto.newPlatformFeeAddress, (_c = dto.newAuthorities) !== null && _c !== void 0 ? _c : [ctx.callingUser]);
47
+ }
48
+ else if (platformFeeAddress && platformFeeAddress.authorities.includes(ctx.callingUser)) {
49
+ platformFeeAddress.setNewFeeAddress((_d = dto.newPlatformFeeAddress) !== null && _d !== void 0 ? _d : platformFeeAddress.feeAddress, (_e = dto.newAuthorities) !== null && _e !== void 0 ? _e : platformFeeAddress.authorities);
50
+ }
51
+ else {
52
+ throw new api_1.UnauthorizedError(`CallingUser ${ctx.callingUser} is not authorized to create or update`);
53
+ }
54
+ await (0, chaincode_1.putChainObject)(ctx, platformFeeAddress);
55
+ return platformFeeAddress;
56
+ }
57
+ exports.configureLaunchpadFeeAddress = configureLaunchpadFeeAddress;
58
+ //# sourceMappingURL=configureLaunchpadFeeConfig.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"configureLaunchpadFeeConfig.js","sourceRoot":"","sources":["../../../../src/chaincode/launchpad/configureLaunchpadFeeConfig.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;GAaG;AACH,yCAAkG;AAElG,qDAAuE;AAEvE,2CAAsF;AAE/E,KAAK,UAAU,4BAA4B,CAChD,GAAqB,EACrB,GAAoC;;IAEpC,IAAI,CAAC,GAAG,CAAC,qBAAqB,IAAI,CAAC,CAAA,MAAA,GAAG,CAAC,cAAc,0CAAE,MAAM,CAAA,EAAE,CAAC;QAC9D,MAAM,IAAI,2BAAqB,CAAC,uCAAuC,CAAC,CAAC;IAC3E,CAAC;IAED,MAAM,aAAa,GAAG,MAAA,OAAO,CAAC,GAAG,CAAC,eAAe,mCAAI,YAAY,CAAC;IAElE,MAAM,GAAG,GAAG,GAAG,CAAC,IAAI,CAAC,kBAAkB,CAAC,0BAAkB,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;IAC1E,IAAI,kBAAkB,GAAG,MAAM,IAAA,0BAAc,EAAC,GAAG,EAAE,0BAAkB,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;QACtF,MAAM,UAAU,GAAG,gBAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACtC,IAAI,UAAU,CAAC,OAAO,CAAC,eAAS,CAAC,SAAS,CAAC,EAAE,CAAC;YAC5C,OAAO,SAAS,CAAC;QACnB,CAAC;aAAM,CAAC;YACN,MAAM,UAAU,CAAC;QACnB,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,IAAI,GAAG,CAAC,cAAc,CAAC,QAAQ,EAAE,KAAK,aAAa,EAAE,CAAC;QACpD,IAAI,CAAC,kBAAkB,IAAI,CAAC,kBAAkB,CAAC,WAAW,CAAC,QAAQ,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,CAAC;YACrF,MAAM,IAAI,uBAAiB,CAAC,eAAe,GAAG,CAAC,WAAW,wCAAwC,CAAC,CAAC;QACtG,CAAC;IACH,CAAC;IAED,IAAI,CAAC,kBAAkB,EAAE,CAAC;QACxB,IAAI,CAAC,GAAG,CAAC,qBAAqB,EAAE,CAAC;YAC/B,MAAM,IAAI,2BAAqB,CAC7B,gFAAgF,CACjF,CAAC;QACJ,CAAC;QACD,kBAAkB,GAAG,IAAI,0BAAkB,CACzC,GAAG,CAAC,qBAAqB,EACzB,MAAA,GAAG,CAAC,cAAc,mCAAI,CAAC,GAAG,CAAC,WAAW,CAAC,CACxC,CAAC;IACJ,CAAC;SAAM,IAAI,kBAAkB,IAAI,kBAAkB,CAAC,WAAW,CAAC,QAAQ,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,CAAC;QAC1F,kBAAkB,CAAC,gBAAgB,CACjC,MAAA,GAAG,CAAC,qBAAqB,mCAAI,kBAAkB,CAAC,UAAU,EAC1D,MAAA,GAAG,CAAC,cAAc,mCAAI,kBAAkB,CAAC,WAAW,CACrD,CAAC;IACJ,CAAC;SAAM,CAAC;QACN,MAAM,IAAI,uBAAiB,CAAC,eAAe,GAAG,CAAC,WAAW,wCAAwC,CAAC,CAAC;IACtG,CAAC;IAED,MAAM,IAAA,0BAAc,EAAC,GAAG,EAAE,kBAAkB,CAAC,CAAC;IAE9C,OAAO,kBAAkB,CAAC;AAC5B,CAAC;AAhDD,oEAgDC"}
@@ -0,0 +1,26 @@
1
+ import { GalaChainContext } from "@gala-chain/chaincode";
2
+ import { CreateSaleResDto, CreateTokenSaleDTO } from "../../api/types";
3
+ /**
4
+ * Creates a new token sale (Launchpad) in the GalaChain environment.
5
+ *
6
+ * This function validates input parameters, creates a token class, mints an initial supply
7
+ * of tokens, and initializes the Launchpad sale object. If a pre-buy amount is specified,
8
+ * it simulates a token purchase using native tokens.
9
+ *
10
+ * @param ctx - The context object providing access to the GalaChain environment.
11
+ * @param launchpadDetails - An object containing details for the token sale, including:
12
+ * - `tokenName`: The name of the token being created.
13
+ * - `tokenSymbol`: The symbol for the token.
14
+ * - `tokenDescription`: A description of the token.
15
+ * - `tokenImage`: An optional image URL for the token.
16
+ * - `preBuyAmount`: The amount of native tokens to use for a pre-buy (optional).
17
+ *
18
+ * @returns A promise that resolves to a `CreateSaleResDto` object containing details about
19
+ * the created sale, including the vault address and token collection name.
20
+ *
21
+ * @throws DefaultError if:
22
+ * - Required fields (`tokenName`, `tokenSymbol`, `tokenDescription`) are missing or empty.
23
+ * - The token class creation fails (no response key returned).
24
+ */
25
+ export declare function createSale(ctx: GalaChainContext, launchpadDetails: CreateTokenSaleDTO): Promise<CreateSaleResDto>;
26
+ //# sourceMappingURL=createSale.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createSale.d.ts","sourceRoot":"","sources":["../../../../src/chaincode/launchpad/createSale.ts"],"names":[],"mappings":"AAeA,OAAO,EACL,gBAAgB,EAMjB,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAyC,MAAM,iBAAiB,CAAC;AAQ9G;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAsB,UAAU,CAC9B,GAAG,EAAE,gBAAgB,EACrB,gBAAgB,EAAE,kBAAkB,GACnC,OAAO,CAAC,gBAAgB,CAAC,CAkG3B"}
@@ -0,0 +1,129 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createSale = void 0;
4
+ /*
5
+ * Copyright (c) Gala Games Inc. All rights reserved.
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+ const api_1 = require("@gala-chain/api");
19
+ const chaincode_1 = require("@gala-chain/chaincode");
20
+ const bignumber_js_1 = require("bignumber.js");
21
+ const types_1 = require("../../api/types");
22
+ const error_1 = require("../../api/utils/error");
23
+ const buyWithNative_1 = require("./buyWithNative");
24
+ bignumber_js_1.BigNumber.config({
25
+ ROUNDING_MODE: bignumber_js_1.BigNumber.ROUND_UP
26
+ });
27
+ /**
28
+ * Creates a new token sale (Launchpad) in the GalaChain environment.
29
+ *
30
+ * This function validates input parameters, creates a token class, mints an initial supply
31
+ * of tokens, and initializes the Launchpad sale object. If a pre-buy amount is specified,
32
+ * it simulates a token purchase using native tokens.
33
+ *
34
+ * @param ctx - The context object providing access to the GalaChain environment.
35
+ * @param launchpadDetails - An object containing details for the token sale, including:
36
+ * - `tokenName`: The name of the token being created.
37
+ * - `tokenSymbol`: The symbol for the token.
38
+ * - `tokenDescription`: A description of the token.
39
+ * - `tokenImage`: An optional image URL for the token.
40
+ * - `preBuyAmount`: The amount of native tokens to use for a pre-buy (optional).
41
+ *
42
+ * @returns A promise that resolves to a `CreateSaleResDto` object containing details about
43
+ * the created sale, including the vault address and token collection name.
44
+ *
45
+ * @throws DefaultError if:
46
+ * - Required fields (`tokenName`, `tokenSymbol`, `tokenDescription`) are missing or empty.
47
+ * - The token class creation fails (no response key returned).
48
+ */
49
+ async function createSale(ctx, launchpadDetails) {
50
+ var _a;
51
+ let isSaleFinalized = false;
52
+ // Validate input parameters
53
+ if (!launchpadDetails.websiteUrl && !launchpadDetails.telegramUrl && !launchpadDetails.twitterUrl) {
54
+ throw new error_1.PreConditionFailedError("Token sale creation requires atleast one social link.");
55
+ }
56
+ launchpadDetails.tokenSymbol = launchpadDetails.tokenSymbol.toUpperCase();
57
+ // Define the token class key
58
+ const tokenInstanceKey = new api_1.TokenInstanceKey();
59
+ tokenInstanceKey.collection = `${launchpadDetails.tokenCollection}`;
60
+ tokenInstanceKey.category = `${launchpadDetails.tokenCategory}`;
61
+ tokenInstanceKey.type = `${launchpadDetails.tokenSymbol}`;
62
+ tokenInstanceKey.additionalKey = `${ctx.callingUser.replace(/\|/, ":")}`;
63
+ tokenInstanceKey.instance = new bignumber_js_1.BigNumber(0);
64
+ // Validate uniqueness of sale and token
65
+ const vaultAddress = (0, api_1.asValidUserAlias)(`service|${tokenInstanceKey.getTokenClassKey().toStringKey()}$launchpad`);
66
+ const key = ctx.stub.createCompositeKey(types_1.LaunchpadSale.INDEX_KEY, [vaultAddress]);
67
+ const sale = await (0, chaincode_1.getObjectByKey)(ctx, types_1.LaunchpadSale, key).catch(() => undefined);
68
+ if (sale) {
69
+ throw new api_1.ConflictError("This token and a sale associated with it already exists");
70
+ }
71
+ // Call createTokenClass
72
+ await (0, chaincode_1.createTokenClass)(ctx, {
73
+ network: "GC",
74
+ tokenClass: tokenInstanceKey.getTokenClassKey(),
75
+ isNonFungible: false,
76
+ decimals: 18,
77
+ name: launchpadDetails.tokenName,
78
+ symbol: launchpadDetails.tokenSymbol,
79
+ description: launchpadDetails.tokenDescription,
80
+ image: launchpadDetails.tokenImage,
81
+ maxSupply: new bignumber_js_1.BigNumber("2e+7"),
82
+ maxCapacity: new bignumber_js_1.BigNumber("2e+7"),
83
+ totalMintAllowance: new bignumber_js_1.BigNumber(0),
84
+ totalSupply: new bignumber_js_1.BigNumber(0),
85
+ totalBurned: new bignumber_js_1.BigNumber(0),
86
+ authorities: [vaultAddress, ctx.callingUser]
87
+ });
88
+ // Mint tokens using the calling user's allowance
89
+ await (0, chaincode_1.mintTokenWithAllowance)(ctx, {
90
+ tokenClassKey: tokenInstanceKey.getTokenClassKey(),
91
+ tokenInstance: new bignumber_js_1.BigNumber(0),
92
+ owner: vaultAddress,
93
+ quantity: new bignumber_js_1.BigNumber("2e+7")
94
+ });
95
+ //Update token class to remove the calling user as an authority in the token class
96
+ await (0, chaincode_1.updateTokenClass)(ctx, {
97
+ tokenClass: tokenInstanceKey.getTokenClassKey(),
98
+ authorities: [vaultAddress]
99
+ });
100
+ // Create the LaunchpadSale object
101
+ const launchpad = new types_1.LaunchpadSale(vaultAddress, tokenInstanceKey, (_a = launchpadDetails.reverseBondingCurveConfiguration) === null || _a === void 0 ? void 0 : _a.toChainObject(), ctx.callingUser);
102
+ await (0, chaincode_1.putChainObject)(ctx, launchpad);
103
+ if (launchpadDetails.preBuyQuantity.isGreaterThan(0)) {
104
+ const nativeTokenDto = new types_1.NativeTokenQuantityDto((0, api_1.asValidUserAlias)(launchpad.vaultAddress), launchpadDetails.preBuyQuantity);
105
+ const tradeStatus = await (0, buyWithNative_1.buyWithNative)(ctx, nativeTokenDto);
106
+ isSaleFinalized = tradeStatus.isFinalized;
107
+ }
108
+ // Return the response object
109
+ return {
110
+ image: launchpadDetails.tokenImage,
111
+ tokenName: launchpadDetails.tokenName,
112
+ symbol: launchpadDetails.tokenSymbol,
113
+ description: launchpadDetails.tokenDescription,
114
+ websiteUrl: launchpadDetails.websiteUrl ? launchpadDetails.websiteUrl : "",
115
+ telegramUrl: launchpadDetails.telegramUrl ? launchpadDetails.telegramUrl : "",
116
+ twitterUrl: launchpadDetails.twitterUrl ? launchpadDetails.twitterUrl : "",
117
+ initialBuyQuantity: launchpadDetails.preBuyQuantity.toFixed(),
118
+ vaultAddress: vaultAddress,
119
+ creatorAddress: ctx.callingUser,
120
+ collection: launchpadDetails.tokenCollection,
121
+ category: launchpadDetails.tokenCategory,
122
+ functionName: "CreateSale",
123
+ isFinalized: isSaleFinalized,
124
+ tokenStringKey: tokenInstanceKey.getTokenClassKey().toStringKey(),
125
+ reverseBondingCurveConfiguration: launchpadDetails.reverseBondingCurveConfiguration
126
+ };
127
+ }
128
+ exports.createSale = createSale;
129
+ //# sourceMappingURL=createSale.js.map
@@ -0,0 +1 @@
1
+ {"version":3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AAU,CAAC,CAAC,CAAC,gBAAgB,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE;QAC1E,kBAAkB,EAAE,gBAAgB,CAAC,cAAc,CAAC,OAAO,EAAE;QAC7D,YAAY,EAAE,YAAY;QAC1B,cAAc,EAAE,GAAG,CAAC,WAAW;QAC/B,UAAU,EAAE,gBAAgB,CAAC,eAAe;QAC5C,QAAQ,EAAE,gBAAgB,CAAC,aAAa;QACxC,YAAY,EAAE,YAAY;QAC1B,WAAW,EAAE,eAAe;QAC5B,cAAc,EAAE,gBAAgB,CAAC,gBAAgB,EAAE,CAAC,WAAW,EAAE;QACjE,gCAAgC,EAAE,gBAAgB,CAAC,gCAAgC;KACzD,CAAC;AAC/B,CAAC;AArGD,gCAqGC"}
@@ -0,0 +1,6 @@
1
+ import { GalaChainContext } from "@gala-chain/chaincode";
2
+ import BigNumber from "bignumber.js";
3
+ import { LaunchpadSale } from "../../api/types";
4
+ export declare function calculateReverseBondingCurveFee(sale: LaunchpadSale, nativeTokensToReceive: BigNumber): BigNumber;
5
+ export declare function payReverseBondingCurveFee(ctx: GalaChainContext, sale: LaunchpadSale, nativeTokensToReceive: BigNumber, maxAcceptableFee?: BigNumber): Promise<void>;
6
+ //# sourceMappingURL=fees.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fees.d.ts","sourceRoot":"","sources":["../../../../src/chaincode/launchpad/fees.ts"],"names":[],"mappings":"AAeA,OAAO,EACL,gBAAgB,EAMjB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,SAAS,MAAM,cAAc,CAAC;AAErC,OAAO,EAAsB,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAMpE,wBAAgB,+BAA+B,CAAC,IAAI,EAAE,aAAa,EAAE,qBAAqB,EAAE,SAAS,aAmBpG;AAED,wBAAsB,yBAAyB,CAC7C,GAAG,EAAE,gBAAgB,EACrB,IAAI,EAAE,aAAa,EACnB,qBAAqB,EAAE,SAAS,EAChC,gBAAgB,CAAC,EAAE,SAAS,iBAgD7B"}