@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,85 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.payReverseBondingCurveFee = exports.calculateReverseBondingCurveFee = 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 chaincode_1 = require("@gala-chain/chaincode");
21
+ const bignumber_js_1 = tslib_1.__importDefault(require("bignumber.js"));
22
+ const types_1 = require("../../api/types");
23
+ const error_1 = require("../../api/utils/error");
24
+ const REVERSE_BONDING_CURVE_FEE_CODE = "LaunchpadReverseBondingCurveFee";
25
+ const NATIVE_TOKEN_DECIMALS = 8;
26
+ function calculateReverseBondingCurveFee(sale, nativeTokensToReceive) {
27
+ if (!sale.reverseBondingCurveConfiguration ||
28
+ sale.reverseBondingCurveConfiguration.maxFeePortion.isZero()) {
29
+ return (0, bignumber_js_1.default)(0);
30
+ }
31
+ const circulatingSupplyProportional = sale.fetchCirculatingSupplyProportional();
32
+ const { minFeePortion, maxFeePortion } = sale.reverseBondingCurveConfiguration;
33
+ const feePortionDiff = maxFeePortion.minus(minFeePortion);
34
+ const portionAboveBaseline = circulatingSupplyProportional.multipliedBy(feePortionDiff);
35
+ const feePortion = minFeePortion.plus(portionAboveBaseline);
36
+ const feeAmount = nativeTokensToReceive
37
+ .multipliedBy(feePortion)
38
+ .decimalPlaces(NATIVE_TOKEN_DECIMALS, bignumber_js_1.default.ROUND_UP);
39
+ return feeAmount;
40
+ }
41
+ exports.calculateReverseBondingCurveFee = calculateReverseBondingCurveFee;
42
+ async function payReverseBondingCurveFee(ctx, sale, nativeTokensToReceive, maxAcceptableFee) {
43
+ const feeAmount = await calculateReverseBondingCurveFee(sale, nativeTokensToReceive);
44
+ if (feeAmount.isZero()) {
45
+ return; // No fee
46
+ }
47
+ if (maxAcceptableFee && feeAmount.isGreaterThan(maxAcceptableFee)) {
48
+ throw new error_1.SlippageToleranceExceededError("Fee exceeds maximum acceptable amount");
49
+ }
50
+ const launchpadConfigKey = ctx.stub.createCompositeKey(types_1.LaunchpadFeeConfig.INDEX_KEY, []);
51
+ const launchpadConfig = await (0, chaincode_1.getObjectByKey)(ctx, types_1.LaunchpadFeeConfig, launchpadConfigKey);
52
+ const nativeToken = sale.fetchNativeTokenInstanceKey();
53
+ const { year, month, day } = (0, chaincode_1.txUnixTimeToDateIndexKeys)(ctx.txUnixTime);
54
+ const txId = ctx.stub.getTxID();
55
+ await (0, chaincode_1.writeChannelPaymentReceipt)(ctx, {
56
+ year,
57
+ month,
58
+ day,
59
+ feeCode: REVERSE_BONDING_CURVE_FEE_CODE,
60
+ paidByUser: ctx.callingUser,
61
+ txId,
62
+ quantity: feeAmount,
63
+ status: api_1.FeeReceiptStatus.Settled
64
+ });
65
+ await (0, chaincode_1.writeUserPaymentReceipt)(ctx, {
66
+ paidByUser: ctx.callingUser,
67
+ year,
68
+ month,
69
+ day,
70
+ feeCode: REVERSE_BONDING_CURVE_FEE_CODE,
71
+ txId,
72
+ quantity: feeAmount,
73
+ status: api_1.FeeReceiptStatus.Settled
74
+ });
75
+ await (0, chaincode_1.transferToken)(ctx, {
76
+ to: launchpadConfig.feeAddress,
77
+ from: ctx.callingUser,
78
+ tokenInstanceKey: nativeToken,
79
+ quantity: feeAmount,
80
+ allowancesToUse: [],
81
+ authorizedOnBehalf: undefined
82
+ });
83
+ }
84
+ exports.payReverseBondingCurveFee = payReverseBondingCurveFee;
85
+ //# sourceMappingURL=fees.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fees.js","sourceRoot":"","sources":["../../../../src/chaincode/launchpad/fees.ts"],"names":[],"mappings":";;;;AAAA;;;;;;;;;;;;;GAaG;AACH,yCAAmD;AACnD,qDAO+B;AAC/B,wEAAqC;AAErC,2CAAoE;AACpE,iDAAuE;AAEvE,MAAM,8BAA8B,GAAG,iCAAiC,CAAC;AACzE,MAAM,qBAAqB,GAAG,CAAC,CAAC;AAEhC,SAAgB,+BAA+B,CAAC,IAAmB,EAAE,qBAAgC;IACnG,IACE,CAAC,IAAI,CAAC,gCAAgC;QACtC,IAAI,CAAC,gCAAgC,CAAC,aAAa,CAAC,MAAM,EAAE,EAC5D,CAAC;QACD,OAAO,IAAA,sBAAS,EAAC,CAAC,CAAC,CAAC;IACtB,CAAC;IAED,MAAM,6BAA6B,GAAG,IAAI,CAAC,kCAAkC,EAAE,CAAC;IAChF,MAAM,EAAE,aAAa,EAAE,aAAa,EAAE,GAAG,IAAI,CAAC,gCAAgC,CAAC;IAC/E,MAAM,cAAc,GAAG,aAAa,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;IAC1D,MAAM,oBAAoB,GAAG,6BAA6B,CAAC,YAAY,CAAC,cAAc,CAAC,CAAC;IACxF,MAAM,UAAU,GAAG,aAAa,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;IAE5D,MAAM,SAAS,GAAG,qBAAqB;SACpC,YAAY,CAAC,UAAU,CAAC;SACxB,aAAa,CAAC,qBAAqB,EAAE,sBAAS,CAAC,QAAQ,CAAC,CAAC;IAE5D,OAAO,SAAS,CAAC;AACnB,CAAC;AAnBD,0E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Q,EAAE,SAAS;QACnB,MAAM,EAAE,sBAAgB,CAAC,OAAO;KACjC,CAAC,CAAC;IAEH,MAAM,IAAA,yBAAa,EAAC,GAAG,EAAE;QACvB,EAAE,EAAE,eAAe,CAAC,UAAU;QAC9B,IAAI,EAAE,GAAG,CAAC,WAAW;QACrB,gBAAgB,EAAE,WAAW;QAC7B,QAAQ,EAAE,SAAS;QACnB,eAAe,EAAE,EAAE;QACnB,kBAAkB,EAAE,SAAS;KAC9B,CAAC,CAAC;AACL,CAAC;AApDD,8DAoDC"}
@@ -0,0 +1,4 @@
1
+ import { GalaChainContext } from "@gala-chain/chaincode";
2
+ import { LaunchpadFeeConfig } from "../../api/types";
3
+ export declare function fetchLaunchpadFeeConfig(ctx: GalaChainContext): Promise<LaunchpadFeeConfig>;
4
+ //# sourceMappingURL=fetchLaunchpadAdressConfig.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetchLaunchpadAdressConfig.d.ts","sourceRoot":"","sources":["../../../../src/chaincode/launchpad/fetchLaunchpadAdressConfig.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAGrD,wBAAsB,uBAAuB,CAAC,GAAG,EAAE,gBAAgB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAiBhG"}
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fetchLaunchpadFeeConfig = 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 utils_1 = require("../utils");
20
+ async function fetchLaunchpadFeeConfig(ctx) {
21
+ var _a;
22
+ const curatorOrgMsp = (_a = process.env.CURATOR_ORG_MSP) !== null && _a !== void 0 ? _a : "CuratorOrg";
23
+ const platformFeeAddress = await (0, utils_1.fetchLaunchpadFeeAddress)(ctx);
24
+ if (ctx.clientIdentity.getMSPID() !== curatorOrgMsp) {
25
+ throw new api_1.UnauthorizedError(`CallingUser ${ctx.callingUser} is not authorized to create or update`);
26
+ }
27
+ if (!platformFeeAddress) {
28
+ throw new api_1.NotFoundError("Platform fee configuration has yet to be defined. Platform fee configuration is not defined.");
29
+ }
30
+ else if (!platformFeeAddress.authorities.includes(ctx.callingUser)) {
31
+ throw new api_1.UnauthorizedError(`CallingUser ${ctx.callingUser} is not authorized to create or update`);
32
+ }
33
+ return platformFeeAddress;
34
+ }
35
+ exports.fetchLaunchpadFeeConfig = fetchLaunchpadFeeConfig;
36
+ //# sourceMappingURL=fetchLaunchpadAdressConfig.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetchLaunchpadAdressConfig.js","sourceRoot":"","sources":["../../../../src/chaincode/launchpad/fetchLaunchpadAdressConfig.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;GAaG;AACH,yCAAmE;AAInE,oCAAoD;AAE7C,KAAK,UAAU,uBAAuB,CAAC,GAAqB;;IACjE,MAAM,aAAa,GAAG,MAAA,OAAO,CAAC,GAAG,CAAC,eAAe,mCAAI,YAAY,CAAC;IAElE,MAAM,kBAAkB,GAAG,MAAM,IAAA,gCAAwB,EAAC,GAAG,CAAC,CAAC;IAE/D,IAAI,GAAG,CAAC,cAAc,CAAC,QAAQ,EAAE,KAAK,aAAa,EAAE,CAAC;QACpD,MAAM,IAAI,uBAAiB,CAAC,eAAe,GAAG,CAAC,WAAW,wCAAwC,CAAC,CAAC;IACtG,CAAC;IAED,IAAI,CAAC,kBAAkB,EAAE,CAAC;QACxB,MAAM,IAAI,mBAAa,CACrB,8FAA8F,CAC/F,CAAC;IACJ,CAAC;SAAM,IAAI,CAAC,kBAAkB,CAAC,WAAW,CAAC,QAAQ,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,CAAC;QACrE,MAAM,IAAI,uBAAiB,CAAC,eAAe,GAAG,CAAC,WAAW,wCAAwC,CAAC,CAAC;IACtG,CAAC;IACD,OAAO,kBAAkB,CAAC;AAC5B,CAAC;AAjBD,0DAiBC"}
@@ -0,0 +1,19 @@
1
+ import { GalaChainContext } from "@gala-chain/chaincode";
2
+ import { FetchSaleDto, LaunchpadSale } from "../../api/types";
3
+ /**
4
+ * Fetches the details of a specific token sale (LaunchpadSale) using its sale address.
5
+ *
6
+ * This function retrieves the sale object from the chain using a composite key derived
7
+ * from the sale address. If the sale record is not found, an error is thrown.
8
+ *
9
+ * @param ctx - The context object providing access to the GalaChain environment.
10
+ * @param fetchSaleDTO - An object containing the sale address:
11
+ * - `vaultAddress`: The address of the sale to be fetched.
12
+ *
13
+ * @returns A promise that resolves to a `LaunchpadSale` object containing details about
14
+ * the specified token sale.
15
+ *
16
+ * @throws NotFoundError if no sale record is found for the provided sale address.
17
+ */
18
+ export declare function fetchSaleDetails(ctx: GalaChainContext, fetchSaleDTO: FetchSaleDto): Promise<LaunchpadSale>;
19
+ //# sourceMappingURL=fetchSaleDetails.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetchSaleDetails.d.ts","sourceRoot":"","sources":["../../../../src/chaincode/launchpad/fetchSaleDetails.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,gBAAgB,EAAkB,MAAM,uBAAuB,CAAC;AAGzE,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAM9D;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,gBAAgB,CACpC,GAAG,EAAE,gBAAgB,EACrB,YAAY,EAAE,YAAY,GACzB,OAAO,CAAC,aAAa,CAAC,CAUxB"}
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fetchSaleDetails = 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
+ bignumber_js_1.BigNumber.config({
23
+ ROUNDING_MODE: bignumber_js_1.BigNumber.ROUND_UP
24
+ });
25
+ /**
26
+ * Fetches the details of a specific token sale (LaunchpadSale) using its sale address.
27
+ *
28
+ * This function retrieves the sale object from the chain using a composite key derived
29
+ * from the sale address. If the sale record is not found, an error is thrown.
30
+ *
31
+ * @param ctx - The context object providing access to the GalaChain environment.
32
+ * @param fetchSaleDTO - An object containing the sale address:
33
+ * - `vaultAddress`: The address of the sale to be fetched.
34
+ *
35
+ * @returns A promise that resolves to a `LaunchpadSale` object containing details about
36
+ * the specified token sale.
37
+ *
38
+ * @throws NotFoundError if no sale record is found for the provided sale address.
39
+ */
40
+ async function fetchSaleDetails(ctx, fetchSaleDTO) {
41
+ const key = ctx.stub.createCompositeKey(types_1.LaunchpadSale.INDEX_KEY, [fetchSaleDTO.vaultAddress]);
42
+ const sale = await (0, chaincode_1.getObjectByKey)(ctx, types_1.LaunchpadSale, key);
43
+ if (sale === undefined) {
44
+ throw new api_1.NotFoundError("Sale record not found.");
45
+ }
46
+ return sale;
47
+ }
48
+ exports.fetchSaleDetails = fetchSaleDetails;
49
+ //# sourceMappingURL=fetchSaleDetails.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetchSaleDetails.js","sourceRoot":"","sources":["../../../../src/chaincode/launchpad/fetchSaleDetails.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;GAaG;AACH,yCAAgD;AAChD,qDAAyE;AACzE,+CAAyC;AAEzC,2CAA8D;AAE9D,wBAAS,CAAC,MAAM,CAAC;IACf,aAAa,EAAE,wBAAS,CAAC,QAAQ;CAClC,CAAC,CAAC;AAEH;;;;;;;;;;;;;;GAcG;AACI,KAAK,UAAU,gBAAgB,CACpC,GAAqB,EACrB,YAA0B;IAE1B,MAAM,GAAG,GAAG,GAAG,CAAC,IAAI,CAAC,kBAAkB,CAAC,qBAAa,CAAC,SAAS,EAAE,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC,CAAC;IAE9F,MAAM,IAAI,GAAG,MAAM,IAAA,0BAAc,EAAC,GAAG,EAAE,qBAAa,EAAE,GAAG,CAAC,CAAC;IAE3D,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACvB,MAAM,IAAI,mBAAa,CAAC,wBAAwB,CAAC,CAAC;IACpD,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAbD,4CAaC"}
@@ -0,0 +1,4 @@
1
+ import { GalaChainContext } from "@gala-chain/chaincode";
2
+ import { LaunchpadSale } from "../../api/types";
3
+ export declare function finalizeSale(ctx: GalaChainContext, sale: LaunchpadSale): Promise<void>;
4
+ //# sourceMappingURL=finaliseSale.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"finaliseSale.d.ts","sourceRoot":"","sources":["../../../../src/chaincode/launchpad/finaliseSale.ts"],"names":[],"mappings":"AAgBA,OAAO,EACL,gBAAgB,EAOjB,MAAM,uBAAuB,CAAC;AAgB/B,OAAO,EAAkC,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAIhF,wBAAsB,YAAY,CAAC,GAAG,EAAE,gBAAgB,EAAE,IAAI,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAuJ5F"}
@@ -0,0 +1,144 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.finalizeSale = 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
+ // TODO: dependencies on DEX
20
+ const api_1 = require("@gala-chain/api");
21
+ const chaincode_1 = require("@gala-chain/chaincode");
22
+ const dex_1 = require("@gala-chain/dex");
23
+ const bignumber_js_1 = tslib_1.__importDefault(require("bignumber.js"));
24
+ const decimal_js_1 = tslib_1.__importDefault(require("decimal.js"));
25
+ const types_1 = require("../../api/types");
26
+ const error_1 = require("../../api/utils/error");
27
+ const utils_1 = require("../utils");
28
+ async function finalizeSale(ctx, sale) {
29
+ const key = ctx.stub.createCompositeKey(types_1.LaunchpadFinalizeFeeAllocation.INDEX_KEY, []);
30
+ const feeAllocation = await (0, chaincode_1.getObjectByKey)(ctx, types_1.LaunchpadFinalizeFeeAllocation, key).catch(() => undefined);
31
+ const platformFeeAddressConfiguration = await (0, utils_1.fetchLaunchpadFeeAddress)(ctx);
32
+ if (!platformFeeAddressConfiguration) {
33
+ throw new error_1.PreConditionFailedError("Platform fee configuration is yet to be defined.");
34
+ }
35
+ const platformFeePercentage = feeAllocation ? feeAllocation.platformFeePercentage : 0.1;
36
+ const ownerAllocationPercentage = feeAllocation ? feeAllocation.ownerAllocationPercentage : 0.6;
37
+ const liquidityAllocationPercentage = feeAllocation ? feeAllocation.liquidityAllocationPercentage : 0.3;
38
+ const nativeToken = sale.fetchNativeTokenInstanceKey();
39
+ const memeToken = sale.fetchSellingTokenInstanceKey();
40
+ const vaultAddressAlias = await (0, chaincode_1.resolveUserAlias)(ctx, sale.vaultAddress);
41
+ await (0, chaincode_1.transferToken)(ctx, {
42
+ from: vaultAddressAlias,
43
+ to: sale.saleOwner,
44
+ tokenInstanceKey: nativeToken,
45
+ quantity: new bignumber_js_1.default(sale.nativeTokenQuantity)
46
+ .times(ownerAllocationPercentage)
47
+ .decimalPlaces(8, bignumber_js_1.default.ROUND_DOWN),
48
+ allowancesToUse: [],
49
+ authorizedOnBehalf: {
50
+ callingOnBehalf: vaultAddressAlias,
51
+ callingUser: ctx.callingUser
52
+ }
53
+ });
54
+ await (0, chaincode_1.transferToken)(ctx, {
55
+ from: vaultAddressAlias,
56
+ to: platformFeeAddressConfiguration.feeAddress,
57
+ tokenInstanceKey: nativeToken,
58
+ quantity: new bignumber_js_1.default(sale.nativeTokenQuantity)
59
+ .times(platformFeePercentage)
60
+ .decimalPlaces(8, bignumber_js_1.default.ROUND_DOWN),
61
+ allowancesToUse: [],
62
+ authorizedOnBehalf: {
63
+ callingOnBehalf: vaultAddressAlias,
64
+ callingUser: ctx.callingUser
65
+ }
66
+ });
67
+ const sellingTokenClassKey = sale.fetchSellingTokenInstanceKey().getTokenClassKey();
68
+ const nativeTokenClassKey = sale.fetchNativeTokenInstanceKey().getTokenClassKey();
69
+ const { isChanged: areTokensSorted } = (0, dex_1.sortString)([sellingTokenClassKey, nativeTokenClassKey].map(dex_1.generateKeyFromClassKey));
70
+ const { sqrtPrice, finalPrice } = calculateFinalLaunchpadPrice(sale, areTokensSorted);
71
+ const poolDTO = new dex_1.CreatePoolDto(areTokensSorted ? nativeTokenClassKey : sellingTokenClassKey, areTokensSorted ? sellingTokenClassKey : nativeTokenClassKey, 3000, sqrtPrice);
72
+ // Check if a pool for this token already exists
73
+ const pool = await (0, dex_1.getPoolData)(ctx, poolDTO);
74
+ if (!pool) {
75
+ await (0, dex_1.createPool)(ctx, poolDTO);
76
+ }
77
+ const poolInfo = await (0, dex_1.getSlot0)(ctx, poolDTO);
78
+ // Proceed normally if price in the pool is within an acceptable range
79
+ const priceCloseEnough = sqrtPrice.minus(poolInfo.sqrtPrice).abs().lte(sqrtPrice.multipliedBy(0.05));
80
+ const expectedNativeTokenRequired = new bignumber_js_1.default(sale.nativeTokenQuantity).times(liquidityAllocationPercentage);
81
+ const isPriceGreaterThanExpected = poolInfo.sqrtPrice.isGreaterThan(sqrtPrice);
82
+ const expectedSaleTokenRequired = expectedNativeTokenRequired.times(finalPrice);
83
+ // Determine token amounts and token ordering
84
+ const token0 = areTokensSorted ? nativeTokenClassKey : sellingTokenClassKey;
85
+ const token1 = areTokensSorted ? sellingTokenClassKey : nativeTokenClassKey;
86
+ const liquidityAmount = priceCloseEnough
87
+ ? expectedNativeTokenRequired
88
+ : isPriceGreaterThanExpected
89
+ ? expectedSaleTokenRequired
90
+ : expectedNativeTokenRequired;
91
+ const zeroForOne = priceCloseEnough
92
+ ? areTokensSorted
93
+ : isPriceGreaterThanExpected
94
+ ? !areTokensSorted
95
+ : areTokensSorted;
96
+ const expectedTokenDTO = new dex_1.GetAddLiquidityEstimationDto(token0, token1, 3000, liquidityAmount, -887220, 887220, zeroForOne);
97
+ const addLiquidityEstimate = await (0, dex_1.getAddLiquidityEstimation)(ctx, expectedTokenDTO);
98
+ const amount0 = new bignumber_js_1.default(addLiquidityEstimate.amount0.toString());
99
+ const amount1 = new bignumber_js_1.default(addLiquidityEstimate.amount1.toString());
100
+ const positionDto = new dex_1.AddLiquidityDTO(token0, token1, 3000, -887220, 887220, amount0, amount1, amount0.times(0.9999999), amount1.times(0.9999999), undefined);
101
+ positionDto.uniqueKey = sale.vaultAddress.toString();
102
+ await (0, dex_1.addLiquidity)(ctx, positionDto, vaultAddressAlias);
103
+ // Burn any extra meme tokens
104
+ const sellingTokenToBurn = await (0, chaincode_1.fetchOrCreateBalance)(ctx, vaultAddressAlias, memeToken);
105
+ const burnSellingTokenQuantity = new api_1.BurnTokenQuantity();
106
+ burnSellingTokenQuantity.tokenInstanceKey = memeToken;
107
+ burnSellingTokenQuantity.quantity = sellingTokenToBurn.getQuantityTotal();
108
+ await (0, chaincode_1.burnTokens)(ctx, {
109
+ owner: vaultAddressAlias,
110
+ toBurn: [burnSellingTokenQuantity],
111
+ preValidated: true
112
+ });
113
+ // Burn any extra GALA
114
+ const nativeTokenToBurn = await (0, chaincode_1.fetchOrCreateBalance)(ctx, vaultAddressAlias, nativeToken);
115
+ const burnNativeTokenQuantity = new api_1.BurnTokenQuantity();
116
+ burnNativeTokenQuantity.tokenInstanceKey = nativeToken;
117
+ burnNativeTokenQuantity.quantity = nativeTokenToBurn.getQuantityTotal();
118
+ if (burnNativeTokenQuantity.quantity) {
119
+ await (0, chaincode_1.burnTokens)(ctx, {
120
+ owner: vaultAddressAlias,
121
+ toBurn: [burnNativeTokenQuantity],
122
+ preValidated: true
123
+ });
124
+ }
125
+ // update sale status
126
+ sale.finalizeSale();
127
+ await (0, chaincode_1.putChainObject)(ctx, sale);
128
+ }
129
+ exports.finalizeSale = finalizeSale;
130
+ function calculateFinalLaunchpadPrice(sale, areTokensSorted) {
131
+ const totalTokensSold = new decimal_js_1.default(sale.fetchTokensSold());
132
+ const basePrice = new decimal_js_1.default(sale.fetchBasePrice());
133
+ const { exponentFactor, euler, decimals } = (0, utils_1.getBondingConstants)();
134
+ const exponent = exponentFactor.mul(totalTokensSold).div(decimals);
135
+ const multiplicand = euler.pow(exponent);
136
+ const finalPriceDecimal = multiplicand.mul(basePrice).div(decimals);
137
+ const priceDecimal = areTokensSorted ? new decimal_js_1.default(1).dividedBy(finalPriceDecimal) : finalPriceDecimal;
138
+ const sqrtPriceDecimal = priceDecimal.pow("0.5");
139
+ return {
140
+ finalPrice: new bignumber_js_1.default(new decimal_js_1.default(1).dividedBy(finalPriceDecimal).toString()),
141
+ sqrtPrice: new bignumber_js_1.default(sqrtPriceDecimal.toString())
142
+ };
143
+ }
144
+ //# sourceMappingURL=finaliseSale.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"finaliseSale.js","sourceRoot":"","sources":["../../../../src/chaincode/launchpad/finaliseSale.ts"],"names":[],"mappings":";;;;AAAA;;;;;;;;;;;;;GAaG;AACH,4BAA4B;AAC5B,yCAAoD;AACpD,qDAQ+B;AAC/B,yCAWyB;AACzB,wEAAqC;AACrC,oEAAiC;AAEjC,2CAAgF;AAChF,iDAAgE;AAChE,oCAAyE;AAElE,KAAK,UAAU,YAAY,CAAC,GAAqB,EAAE,IAAmB;IAC3E,MAAM,GAAG,GAAG,GAAG,CAAC,IAAI,CAAC,kBAAkB,CAAC,sCAA8B,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;IACtF,MAAM,aAAa,GAAG,MAAM,IAAA,0BAAc,EAAC,GAAG,EAAE,sCAA8B,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;IAE5G,MAAM,+BAA+B,GAAG,MAAM,IAAA,gCAAwB,EAAC,GAAG,CAAC,CAAC;IAC5E,IAAI,CAAC,+BAA+B,EAAE,CAAC;QACrC,MAAM,IAAI,+BAAuB,CAAC,kDAAkD,CAAC,CAAC;IACxF,CAAC;IAED,MAAM,qBAAqB,GAAG,aAAa,CAAC,CAAC,CAAC,aAAa,CAAC,qBAAqB,CAAC,CAAC,CAAC,GAAG,CAAC;IACxF,MAAM,yBAAyB,GAAG,aAAa,CAAC,CAAC,CAAC,aAAa,CAAC,yBAAyB,CAAC,CAAC,CAAC,GAAG,CAAC;IAChG,MAAM,6BAA6B,GAAG,aAAa,CAAC,CAAC,CAAC,aAAa,CAAC,6BAA6B,CAAC,CAAC,CAAC,GAAG,CAAC;IAExG,MAAM,WAA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,cAAc,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,IAAA,2BAAmB,GAAE,CAAC;IAElE,MAAM,QAAQ,GAAG,cAAc,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACnE,MAAM,YAAY,GAAG,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACzC,MAAM,iBAAiB,GAAG,YAAY,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAEpE,MAAM,YAAY,GAAG,eAAe,CAAC,CAAC,CAAC,IAAI,oBAAO,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,iBAAiB,CAAC;IACvG,MAAM,gBAAgB,GAAG,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAEjD,OAAO;QACL,UAAU,EAAE,IAAI,sBAAS,CAAC,IAAI,oBAAO,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,iBAAiB,CAAC,CAAC,QAAQ,EAAE,CAAC;QACjF,SAAS,EAAE,IAAI,sBAAS,CAAC,gBAAgB,CAAC,QAAQ,EAAE,CAAC;KACtD,CAAC;AACJ,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { GalaChainContext } from "@gala-chain/chaincode";
2
+ import { FinalizeTokenAllocationDto, LaunchpadFinalizeFeeAllocation } from "../../api/types";
3
+ export declare function finalizeTokenAllocation(ctx: GalaChainContext, dto: FinalizeTokenAllocationDto): Promise<LaunchpadFinalizeFeeAllocation>;
4
+ //# sourceMappingURL=finalizeTokenAllocation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"finalizeTokenAllocation.d.ts","sourceRoot":"","sources":["../../../../src/chaincode/launchpad/finalizeTokenAllocation.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAGzD,OAAO,EAAE,0BAA0B,EAAE,8BAA8B,EAAE,MAAM,iBAAiB,CAAC;AAI7F,wBAAsB,uBAAuB,CAC3C,GAAG,EAAE,gBAAgB,EACrB,GAAG,EAAE,0BAA0B,GAC9B,OAAO,CAAC,8BAA8B,CAAC,CAqBzC"}
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.finalizeTokenAllocation = 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
+ const error_1 = require("../../api/utils/error");
22
+ const utils_1 = require("../utils");
23
+ async function finalizeTokenAllocation(ctx, dto) {
24
+ const platformFeeAddress = await (0, utils_1.fetchLaunchpadFeeAddress)(ctx);
25
+ if (!platformFeeAddress) {
26
+ throw new error_1.PreConditionFailedError("Platform fee configuration has yet to be defined. Platform fee configuration is not defined.");
27
+ }
28
+ else if (!platformFeeAddress.authorities.includes(ctx.callingUser)) {
29
+ throw new api_1.UnauthorizedError(`CallingUser ${ctx.callingUser} is not authorized to create or update`);
30
+ }
31
+ const key = ctx.stub.createCompositeKey(types_1.LaunchpadFinalizeFeeAllocation.INDEX_KEY, []);
32
+ let feeAllocation = await (0, chaincode_1.getObjectByKey)(ctx, types_1.LaunchpadFinalizeFeeAllocation, key).catch(() => undefined);
33
+ if (!feeAllocation) {
34
+ feeAllocation = new types_1.LaunchpadFinalizeFeeAllocation(dto.platformFeePercentage, dto.ownerFeePercentage);
35
+ }
36
+ else {
37
+ feeAllocation.setAllocation(dto.platformFeePercentage, dto.ownerFeePercentage);
38
+ }
39
+ await (0, chaincode_1.putChainObject)(ctx, feeAllocation);
40
+ return feeAllocation;
41
+ }
42
+ exports.finalizeTokenAllocation = finalizeTokenAllocation;
43
+ //# sourceMappingURL=finalizeTokenAllocation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"finalizeTokenAllocation.js","sourceRoot":"","sources":["../../../../src/chaincode/launchpad/finalizeTokenAllocation.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;GAaG;AACH,yCAAoD;AAEpD,qDAAuE;AAEvE,2CAA6F;AAC7F,iDAAgE;AAChE,oCAAoD;AAE7C,KAAK,UAAU,uBAAuB,CAC3C,GAAqB,EACrB,GAA+B;IAE/B,MAAM,kBAAkB,GAAG,MAAM,IAAA,gCAAwB,EAAC,GAAG,CAAC,CAAC;IAC/D,IAAI,CAAC,kBAAkB,EAAE,CAAC;QACxB,MAAM,IAAI,+BAAuB,CAC/B,8FAA8F,CAC/F,CAAC;IACJ,CAAC;SAAM,IAAI,CAAC,kBAAkB,CAAC,WAAW,CAAC,QAAQ,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,CAAC;QACrE,MAAM,IAAI,uBAAiB,CAAC,eAAe,GAAG,CAAC,WAAW,wCAAwC,CAAC,CAAC;IACtG,CAAC;IAED,MAAM,GAAG,GAAG,GAAG,CAAC,IAAI,CAAC,kBAAkB,CAAC,sCAA8B,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;IACtF,IAAI,aAAa,GAAG,MAAM,IAAA,0BAAc,EAAC,GAAG,EAAE,sCAA8B,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;IAE1G,IAAI,CAAC,aAAa,EAAE,CAAC;QACnB,aAAa,GAAG,IAAI,sCAA8B,CAAC,GAAG,CAAC,qBAAqB,EAAE,GAAG,CAAC,kBAAkB,CAAC,CAAC;IACxG,CAAC;SAAM,CAAC;QACN,aAAa,CAAC,aAAa,CAAC,GAAG,CAAC,qBAAqB,EAAE,GAAG,CAAC,kBAAkB,CAAC,CAAC;IACjF,CAAC;IAED,MAAM,IAAA,0BAAc,EAAC,GAAG,EAAE,aAAa,CAAC,CAAC;IACzC,OAAO,aAAa,CAAC;AACvB,CAAC;AAxBD,0DAwBC"}
@@ -0,0 +1,15 @@
1
+ export * from "./buyExactToken";
2
+ export * from "./buyWithNative";
3
+ export * from "./callMemeTokenIn";
4
+ export * from "./callMemeTokenOut";
5
+ export * from "./callNativeTokenIn";
6
+ export * from "./callNativeTokenOut";
7
+ export * from "./createSale";
8
+ export * from "./fetchSaleDetails";
9
+ export * from "./preMintCalculation";
10
+ export * from "./sellExactToken";
11
+ export * from "./finalizeTokenAllocation";
12
+ export * from "./sellWithNative";
13
+ export * from "./configureLaunchpadFeeConfig";
14
+ export * from "./fetchLaunchpadAdressConfig";
15
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/chaincode/launchpad/index.ts"],"names":[],"mappings":"AAcA,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,cAAc,CAAC;AAC7B,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,kBAAkB,CAAC;AACjC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,8BAA8B,CAAC"}
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
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
+ tslib_1.__exportStar(require("./buyExactToken"), exports);
19
+ tslib_1.__exportStar(require("./buyWithNative"), exports);
20
+ tslib_1.__exportStar(require("./callMemeTokenIn"), exports);
21
+ tslib_1.__exportStar(require("./callMemeTokenOut"), exports);
22
+ tslib_1.__exportStar(require("./callNativeTokenIn"), exports);
23
+ tslib_1.__exportStar(require("./callNativeTokenOut"), exports);
24
+ tslib_1.__exportStar(require("./createSale"), exports);
25
+ tslib_1.__exportStar(require("./fetchSaleDetails"), exports);
26
+ tslib_1.__exportStar(require("./preMintCalculation"), exports);
27
+ tslib_1.__exportStar(require("./sellExactToken"), exports);
28
+ tslib_1.__exportStar(require("./finalizeTokenAllocation"), exports);
29
+ tslib_1.__exportStar(require("./sellWithNative"), exports);
30
+ tslib_1.__exportStar(require("./configureLaunchpadFeeConfig"), exports);
31
+ tslib_1.__exportStar(require("./fetchLaunchpadAdressConfig"), exports);
32
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/chaincode/launchpad/index.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;GAaG;AACH,0DAAgC;AAChC,0DAAgC;AAChC,4DAAkC;AAClC,6DAAmC;AACnC,8DAAoC;AACpC,+DAAqC;AACrC,uDAA6B;AAC7B,6DAAmC;AACnC,+DAAqC;AACrC,2DAAiC;AACjC,oEAA0C;AAC1C,2DAAiC;AACjC,wEAA8C;AAC9C,uEAA6C"}
@@ -0,0 +1,17 @@
1
+ import { PreMintCalculationDto } from "../../api/types";
2
+ /**
3
+ * Calculates the number of tokens that can be purchased using a specified amount
4
+ * of native tokens based on a bonding curve mechanism.
5
+ *
6
+ * This function applies the bonding curve formula for a brand new sale with zero tokens sold
7
+ * to determine the number of tokens the user can buy with the provided native token amount.
8
+ *
9
+ * @param buyTokenDTO - The Amount of native tokens to spend for the purchase.
10
+ *
11
+ * @returns A promise that resolves to a string representing the calculated amount of
12
+ * tokens to be received, rounded down to 18 decimal places.
13
+ *
14
+ * @throws Error if the calculation results in an invalid state.
15
+ */
16
+ export declare function calculatePreMintTokens(buyTokenDTO: PreMintCalculationDto): Promise<string>;
17
+ //# sourceMappingURL=preMintCalculation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preMintCalculation.d.ts","sourceRoot":"","sources":["../../../../src/chaincode/launchpad/preMintCalculation.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAiB,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAOvE;;;;;;;;;;;;;GAaG;AACH,wBAAsB,sBAAsB,CAAC,WAAW,EAAE,qBAAqB,GAAG,OAAO,CAAC,MAAM,CAAC,CAsBhG"}
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.calculatePreMintTokens = 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 bignumber_js_1 = require("bignumber.js");
20
+ const decimal_js_1 = tslib_1.__importDefault(require("decimal.js"));
21
+ const types_1 = require("../../api/types");
22
+ const utils_1 = require("../utils");
23
+ bignumber_js_1.BigNumber.config({
24
+ ROUNDING_MODE: bignumber_js_1.BigNumber.ROUND_UP
25
+ });
26
+ /**
27
+ * Calculates the number of tokens that can be purchased using a specified amount
28
+ * of native tokens based on a bonding curve mechanism.
29
+ *
30
+ * This function applies the bonding curve formula for a brand new sale with zero tokens sold
31
+ * to determine the number of tokens the user can buy with the provided native token amount.
32
+ *
33
+ * @param buyTokenDTO - The Amount of native tokens to spend for the purchase.
34
+ *
35
+ * @returns A promise that resolves to a string representing the calculated amount of
36
+ * tokens to be received, rounded down to 18 decimal places.
37
+ *
38
+ * @throws Error if the calculation results in an invalid state.
39
+ */
40
+ async function calculatePreMintTokens(buyTokenDTO) {
41
+ const totalTokensSold = new decimal_js_1.default(0); // current tokens sold / x
42
+ const nativeTokens = new decimal_js_1.default(buyTokenDTO.nativeTokenQuantity.toString()); // native tokens used to buy / y
43
+ const basePrice = new decimal_js_1.default(types_1.LaunchpadSale.BASE_PRICE); // base price / a
44
+ const { exponentFactor, euler, decimals } = (0, utils_1.getBondingConstants)();
45
+ const constant = nativeTokens.mul(exponentFactor).div(basePrice);
46
+ const exponent1 = exponentFactor.mul(totalTokensSold).div(decimals);
47
+ const eResult1 = euler.pow(exponent1);
48
+ const ethScaled = constant.add(eResult1);
49
+ const lnEthScaled = ethScaled.ln().mul(decimals);
50
+ const lnEthScaledBase = lnEthScaled.div(exponentFactor);
51
+ const result = lnEthScaledBase.minus(totalTokensSold);
52
+ const roundedResult = result.toDecimalPlaces(18, decimal_js_1.default.ROUND_DOWN);
53
+ return roundedResult.toString();
54
+ }
55
+ exports.calculatePreMintTokens = calculatePreMintTokens;
56
+ //# sourceMappingURL=preMintCalculation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preMintCalculation.js","sourceRoot":"","sources":["../../../../src/chaincode/launchpad/preMintCalculation.ts"],"names":[],"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O,CAAC,UAAU,CAAC,CAAC;IAErE,OAAO,aAAa,CAAC,QAAQ,EAAE,CAAC;AAClC,CAAC;AAtBD,wDAsBC"}
@@ -0,0 +1,22 @@
1
+ import { GalaChainContext } from "@gala-chain/chaincode";
2
+ import { ExactTokenQuantityDto, TradeResDto } from "../../api/types";
3
+ /**
4
+ * Executes the sale of an exact amount of tokens for native tokens (e.g., GALA).
5
+ *
6
+ * This function facilitates selling a specific token amount by transferring the tokens to
7
+ * the sale vault and providing the calculated native tokens in return. It ensures validation
8
+ * of the sale, handles insufficient vault balances, and checks expected vs. actual native tokens.
9
+ *
10
+ * @param ctx - The context object providing access to the GalaChain environment.
11
+ * @param sellTokenDTO - An object containing the sale details:
12
+ * - `vaultAddress`: The address of the sale.
13
+ * - `tokenAmount`: The exact amount of tokens to sell.
14
+ * - `expectedNativeToken` (optional): The expected amount of native tokens in return.
15
+ *
16
+ * @returns A promise that resolves to a `TradeResDto` object containing the updated
17
+ * balances of the seller's tokens and native tokens.
18
+ *
19
+ * @throws DefaultError if the expected native tokens exceed the actual amount to be provided.
20
+ */
21
+ export declare function sellExactToken(ctx: GalaChainContext, sellTokenDTO: ExactTokenQuantityDto): Promise<TradeResDto>;
22
+ //# sourceMappingURL=sellExactToken.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sellExactToken.d.ts","sourceRoot":"","sources":["../../../../src/chaincode/launchpad/sellExactToken.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,gBAAgB,EAAkD,MAAM,uBAAuB,CAAC;AAGzG,OAAO,EAAE,qBAAqB,EAA0B,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAW7F;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,cAAc,CAClC,GAAG,EAAE,gBAAgB,EACrB,YAAY,EAAE,qBAAqB,GAClC,OAAO,CAAC,WAAW,CAAC,CAwEtB"}