@gala-chain/launchpad 1.0.5 → 1.0.7
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.
- package/lib/package.json +1 -1
- package/lib/src/api/types/LaunchpadDtos.d.ts +5 -4
- package/lib/src/api/types/LaunchpadDtos.d.ts.map +1 -1
- package/lib/src/api/types/LaunchpadDtos.js +17 -15
- package/lib/src/api/types/LaunchpadDtos.js.map +1 -1
- package/lib/src/chaincode/LaunchpadContract.d.ts +4 -4
- package/lib/src/chaincode/LaunchpadContract.d.ts.map +1 -1
- package/lib/src/chaincode/LaunchpadContract.js +22 -16
- package/lib/src/chaincode/LaunchpadContract.js.map +1 -1
- package/lib/src/chaincode/launchpad/buyExactToken.d.ts.map +1 -1
- package/lib/src/chaincode/launchpad/buyExactToken.js +8 -1
- package/lib/src/chaincode/launchpad/buyExactToken.js.map +1 -1
- package/lib/src/chaincode/launchpad/buyWithNative.d.ts.map +1 -1
- package/lib/src/chaincode/launchpad/buyWithNative.js +9 -2
- package/lib/src/chaincode/launchpad/buyWithNative.js.map +1 -1
- package/lib/src/chaincode/launchpad/callMemeTokenOut.d.ts.map +1 -1
- package/lib/src/chaincode/launchpad/callMemeTokenOut.js +20 -7
- package/lib/src/chaincode/launchpad/callMemeTokenOut.js.map +1 -1
- package/lib/src/chaincode/launchpad/callNativeTokenIn.d.ts.map +1 -1
- package/lib/src/chaincode/launchpad/callNativeTokenIn.js.map +1 -1
- package/lib/src/chaincode/launchpad/callNativeTokenOut.d.ts.map +1 -1
- package/lib/src/chaincode/launchpad/callNativeTokenOut.js.map +1 -1
- package/lib/src/chaincode/launchpad/fetchLaunchpadAdressConfig.d.ts +2 -1
- package/lib/src/chaincode/launchpad/fetchLaunchpadAdressConfig.d.ts.map +1 -1
- package/lib/src/chaincode/launchpad/fetchLaunchpadAdressConfig.js +1 -1
- package/lib/src/chaincode/launchpad/fetchLaunchpadAdressConfig.js.map +1 -1
- package/lib/src/chaincode/launchpad/fetchLaunchpadFeeAmount.d.ts +12 -0
- package/lib/src/chaincode/launchpad/fetchLaunchpadFeeAmount.d.ts.map +1 -0
- package/lib/src/chaincode/launchpad/fetchLaunchpadFeeAmount.js +37 -0
- package/lib/src/chaincode/launchpad/fetchLaunchpadFeeAmount.js.map +1 -0
- package/lib/src/chaincode/launchpad/index.d.ts +0 -1
- package/lib/src/chaincode/launchpad/index.d.ts.map +1 -1
- package/lib/src/chaincode/launchpad/index.js +0 -1
- package/lib/src/chaincode/launchpad/index.js.map +1 -1
- package/lib/src/chaincode/launchpad/sellExactToken.d.ts.map +1 -1
- package/lib/src/chaincode/launchpad/sellExactToken.js +2 -1
- package/lib/src/chaincode/launchpad/sellExactToken.js.map +1 -1
- package/lib/src/chaincode/launchpad/sellWithNative.d.ts.map +1 -1
- package/lib/src/chaincode/launchpad/sellWithNative.js +2 -1
- package/lib/src/chaincode/launchpad/sellWithNative.js.map +1 -1
- package/lib/src/chaincode/test/launchpadgala.d.ts +154 -0
- package/lib/src/chaincode/test/launchpadgala.d.ts.map +1 -0
- package/lib/src/chaincode/test/launchpadgala.js +152 -0
- package/lib/src/chaincode/test/launchpadgala.js.map +1 -0
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/api/types/LaunchpadDtos.ts +12 -14
- package/src/chaincode/LaunchpadContract.ts +25 -16
- package/src/chaincode/launchpad/buyExactToken.spec.ts +222 -0
- package/src/chaincode/launchpad/buyExactToken.ts +18 -2
- package/src/chaincode/launchpad/buyWithNative.spec.ts +221 -0
- package/src/chaincode/launchpad/buyWithNative.ts +20 -3
- package/src/chaincode/launchpad/callMemeTokenOut.spec.ts +150 -0
- package/src/chaincode/launchpad/callMemeTokenOut.ts +26 -15
- package/src/chaincode/launchpad/callNativeTokenIn.ts +1 -0
- package/src/chaincode/launchpad/callNativeTokenOut.ts +1 -0
- package/src/chaincode/launchpad/fetchLaunchpadAdressConfig.ts +5 -2
- package/src/chaincode/launchpad/fetchLaunchpadFeeAmount.spec.ts +67 -0
- package/src/chaincode/launchpad/fetchLaunchpadFeeAmount.ts +40 -0
- package/src/chaincode/launchpad/index.ts +0 -1
- package/src/chaincode/launchpad/sellExactToken.ts +2 -1
- package/src/chaincode/launchpad/sellWithNative.ts +2 -1
- package/src/chaincode/test/launchpadgala.ts +174 -0
- package/lib/src/chaincode/launchpad/preMintCalculation.d.ts +0 -17
- package/lib/src/chaincode/launchpad/preMintCalculation.d.ts.map +0 -1
- package/lib/src/chaincode/launchpad/preMintCalculation.js +0 -52
- package/lib/src/chaincode/launchpad/preMintCalculation.js.map +0 -1
- package/src/chaincode/launchpad/preMintCalculation.ts +0 -56
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) Gala Games Inc. All rights reserved.
|
|
3
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
* you may not use this file except in compliance with the License.
|
|
5
|
-
* You may obtain a copy of the License at
|
|
6
|
-
*
|
|
7
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
*
|
|
9
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
* See the License for the specific language governing permissions and
|
|
13
|
-
* limitations under the License.
|
|
14
|
-
*/
|
|
15
|
-
import Decimal from "decimal.js";
|
|
16
|
-
|
|
17
|
-
import { LaunchpadSale, PreMintCalculationDto } from "../../api/types";
|
|
18
|
-
import { getBondingConstants } from "../utils";
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Calculates the number of tokens that can be purchased using a specified amount
|
|
22
|
-
* of native tokens based on a bonding curve mechanism.
|
|
23
|
-
*
|
|
24
|
-
* This function applies the bonding curve formula for a brand new sale with zero tokens sold
|
|
25
|
-
* to determine the number of tokens the user can buy with the provided native token amount.
|
|
26
|
-
*
|
|
27
|
-
* @param buyTokenDTO - The Amount of native tokens to spend for the purchase.
|
|
28
|
-
*
|
|
29
|
-
* @returns A promise that resolves to a string representing the calculated amount of
|
|
30
|
-
* tokens to be received, rounded down to 18 decimal places.
|
|
31
|
-
*
|
|
32
|
-
* @throws Error if the calculation results in an invalid state.
|
|
33
|
-
*/
|
|
34
|
-
export async function calculatePreMintTokens(buyTokenDTO: PreMintCalculationDto): Promise<string> {
|
|
35
|
-
const totalTokensSold = new Decimal(0); // current tokens sold / x
|
|
36
|
-
const nativeTokens = new Decimal(buyTokenDTO.nativeTokenQuantity.toString()); // native tokens used to buy / y
|
|
37
|
-
const basePrice = new Decimal(LaunchpadSale.BASE_PRICE); // base price / a
|
|
38
|
-
const { exponentFactor, euler, decimals } = getBondingConstants();
|
|
39
|
-
|
|
40
|
-
const constant = nativeTokens.mul(exponentFactor).div(basePrice);
|
|
41
|
-
|
|
42
|
-
const exponent1 = exponentFactor.mul(totalTokensSold).div(decimals);
|
|
43
|
-
|
|
44
|
-
const eResult1 = euler.pow(exponent1);
|
|
45
|
-
|
|
46
|
-
const ethScaled = constant.add(eResult1);
|
|
47
|
-
|
|
48
|
-
const lnEthScaled = ethScaled.ln().mul(decimals);
|
|
49
|
-
|
|
50
|
-
const lnEthScaledBase = lnEthScaled.div(exponentFactor);
|
|
51
|
-
|
|
52
|
-
const result = lnEthScaledBase.minus(totalTokensSold);
|
|
53
|
-
const roundedResult = result.toDecimalPlaces(18, Decimal.ROUND_DOWN);
|
|
54
|
-
|
|
55
|
-
return roundedResult.toString();
|
|
56
|
-
}
|