@gala-chain/launchpad 1.0.13 → 1.0.14
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 +1 -0
- package/lib/src/api/types/LaunchpadDtos.d.ts.map +1 -1
- package/lib/src/api/types/LaunchpadDtos.js +5 -0
- package/lib/src/api/types/LaunchpadDtos.js.map +1 -1
- package/lib/src/api/types/LaunchpadSale.d.ts +2 -1
- package/lib/src/api/types/LaunchpadSale.d.ts.map +1 -1
- package/lib/src/api/types/LaunchpadSale.js +18 -6
- package/lib/src/api/types/LaunchpadSale.js.map +1 -1
- package/lib/src/chaincode/LaunchpadContract.js +6 -6
- 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 +18 -42
- 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 +12 -43
- package/lib/src/chaincode/launchpad/buyWithNative.js.map +1 -1
- package/lib/src/chaincode/launchpad/callMemeTokenIn.d.ts +4 -10
- package/lib/src/chaincode/launchpad/callMemeTokenIn.d.ts.map +1 -1
- package/lib/src/chaincode/launchpad/callMemeTokenIn.js +13 -9
- package/lib/src/chaincode/launchpad/callMemeTokenIn.js.map +1 -1
- package/lib/src/chaincode/launchpad/callMemeTokenOut.d.ts +4 -10
- package/lib/src/chaincode/launchpad/callMemeTokenOut.d.ts.map +1 -1
- package/lib/src/chaincode/launchpad/callMemeTokenOut.js +46 -22
- package/lib/src/chaincode/launchpad/callMemeTokenOut.js.map +1 -1
- package/lib/src/chaincode/launchpad/callNativeTokenIn.d.ts +4 -10
- package/lib/src/chaincode/launchpad/callNativeTokenIn.d.ts.map +1 -1
- package/lib/src/chaincode/launchpad/callNativeTokenIn.js +35 -14
- package/lib/src/chaincode/launchpad/callNativeTokenIn.js.map +1 -1
- package/lib/src/chaincode/launchpad/callNativeTokenOut.d.ts +4 -10
- package/lib/src/chaincode/launchpad/callNativeTokenOut.d.ts.map +1 -1
- package/lib/src/chaincode/launchpad/callNativeTokenOut.js +17 -12
- package/lib/src/chaincode/launchpad/callNativeTokenOut.js.map +1 -1
- package/lib/src/chaincode/launchpad/configureLaunchpadFeeConfig.js +1 -1
- package/lib/src/chaincode/launchpad/configureLaunchpadFeeConfig.js.map +1 -1
- package/lib/src/chaincode/launchpad/createSale.js +1 -1
- package/lib/src/chaincode/launchpad/createSale.js.map +1 -1
- package/lib/src/chaincode/launchpad/fees.d.ts +11 -0
- package/lib/src/chaincode/launchpad/fees.d.ts.map +1 -1
- package/lib/src/chaincode/launchpad/fees.js +42 -3
- package/lib/src/chaincode/launchpad/fees.js.map +1 -1
- package/lib/src/chaincode/launchpad/finaliseSale.d.ts.map +1 -1
- package/lib/src/chaincode/launchpad/finaliseSale.js +7 -4
- package/lib/src/chaincode/launchpad/finaliseSale.js.map +1 -1
- package/lib/src/chaincode/launchpad/sellExactToken.d.ts.map +1 -1
- package/lib/src/chaincode/launchpad/sellExactToken.js +14 -23
- 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 +10 -19
- package/lib/src/chaincode/launchpad/sellWithNative.js.map +1 -1
- package/lib/src/chaincode/test/launchpadgala.d.ts.map +1 -1
- package/lib/src/chaincode/test/launchpadgala.js +2 -1
- package/lib/src/chaincode/test/launchpadgala.js.map +1 -1
- package/lib/src/chaincode/utils/launchpadSaleUtils.d.ts +4 -0
- package/lib/src/chaincode/utils/launchpadSaleUtils.d.ts.map +1 -1
- package/lib/src/chaincode/utils/launchpadSaleUtils.js +10 -1
- package/lib/src/chaincode/utils/launchpadSaleUtils.js.map +1 -1
- package/lib/src/cli.js +3 -1
- package/lib/src/cli.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/api/types/LaunchpadDtos.ts +4 -0
- package/src/api/types/LaunchpadSale.ts +14 -7
- package/src/chaincode/LaunchpadContract.ts +3 -3
- package/src/chaincode/launchpad/buyExactToken.spec.ts +2 -37
- package/src/chaincode/launchpad/buyExactToken.ts +22 -56
- package/src/chaincode/launchpad/buyWithNative.spec.ts +2 -37
- package/src/chaincode/launchpad/buyWithNative.ts +15 -65
- package/src/chaincode/launchpad/callMemeTokenIn.ts +36 -12
- package/src/chaincode/launchpad/callMemeTokenOut.spec.ts +1 -1
- package/src/chaincode/launchpad/callMemeTokenOut.ts +72 -26
- package/src/chaincode/launchpad/callNativeTokenIn.ts +62 -19
- package/src/chaincode/launchpad/callNativeTokenOut.ts +38 -15
- package/src/chaincode/launchpad/configureLaunchpadFeeConfig.spec.ts +0 -1
- package/src/chaincode/launchpad/configureLaunchpadFeeConfig.ts +1 -1
- package/src/chaincode/launchpad/createSale.ts +1 -1
- package/src/chaincode/launchpad/fees.ts +55 -3
- package/src/chaincode/launchpad/finaliseSale.ts +7 -4
- package/src/chaincode/launchpad/launchpadBatchSubmitAuthorizations.spec.ts +150 -68
- package/src/chaincode/launchpad/sellExactToken.spec.ts +4 -81
- package/src/chaincode/launchpad/sellExactToken.ts +16 -25
- package/src/chaincode/launchpad/sellWithNative.spec.ts +2 -42
- package/src/chaincode/launchpad/sellWithNative.ts +14 -23
- package/src/chaincode/test/launchpadgala.ts +3 -1
- package/src/chaincode/utils/launchpadSaleUtils.ts +13 -1
- package/src/cli.ts +3 -1
|
@@ -22,11 +22,11 @@ import {
|
|
|
22
22
|
} from "@gala-chain/chaincode";
|
|
23
23
|
import BigNumber from "bignumber.js";
|
|
24
24
|
|
|
25
|
-
import {
|
|
25
|
+
import { NativeTokenQuantityDto, TradeResDto } from "../../api/types";
|
|
26
26
|
import { SlippageToleranceExceededError } from "../../api/utils/error";
|
|
27
|
-
import { fetchAndValidateSale
|
|
27
|
+
import { fetchAndValidateSale } from "../utils";
|
|
28
28
|
import { callMemeTokenIn } from "./callMemeTokenIn";
|
|
29
|
-
import { payReverseBondingCurveFee } from "./fees";
|
|
29
|
+
import { payReverseBondingCurveFee, transferTransactionFees } from "./fees";
|
|
30
30
|
|
|
31
31
|
/**
|
|
32
32
|
* Executes a sale of tokens using native tokens (e.g., GALA) in exchange for the specified token amount.
|
|
@@ -52,7 +52,7 @@ export async function sellWithNative(
|
|
|
52
52
|
sellTokenDTO: NativeTokenQuantityDto
|
|
53
53
|
): Promise<TradeResDto> {
|
|
54
54
|
// Fetch and validate the sale object
|
|
55
|
-
const sale
|
|
55
|
+
const sale = await fetchAndValidateSale(ctx, sellTokenDTO.vaultAddress);
|
|
56
56
|
|
|
57
57
|
const { collection, category, type, additionalKey } = sale.sellingToken;
|
|
58
58
|
const sellingTokenCompositeKey = TokenClass.getCompositeKeyFromParts(TokenClass.INDEX_KEY, [
|
|
@@ -66,22 +66,23 @@ export async function sellWithNative(
|
|
|
66
66
|
const nativeTokensLeftInVault = new BigNumber(sale.nativeTokenQuantity);
|
|
67
67
|
|
|
68
68
|
// Cap nativeTokenQuantity to the vault balance if the requested amount exceeds it
|
|
69
|
-
if (nativeTokensLeftInVault.
|
|
69
|
+
if (nativeTokensLeftInVault.isLessThan(sellTokenDTO.nativeTokenQuantity)) {
|
|
70
70
|
throw new ValidationFailedError("Not enough GALA in sale contract to carry out this operation.");
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
// Calculate how many tokens need to be sold to get the requested native amount
|
|
74
74
|
const callMemeTokenInResult = await callMemeTokenIn(ctx, sellTokenDTO);
|
|
75
|
-
const transactionFees = callMemeTokenInResult.extraFees.transactionFees;
|
|
75
|
+
const transactionFees = callMemeTokenInResult.extraFees.transactionFees; // transaction fees
|
|
76
|
+
const nativeTokensPayout = new BigNumber(callMemeTokenInResult.originalQuantity); // number of native tokens user wants to receive
|
|
76
77
|
const tokensToSell = new BigNumber(callMemeTokenInResult.calculatedQuantity).decimalPlaces(
|
|
77
78
|
sellingToken.decimals
|
|
78
|
-
);
|
|
79
|
+
); // number of tokens user needs to sell
|
|
79
80
|
|
|
80
81
|
const nativeToken = sale.fetchNativeTokenInstanceKey();
|
|
81
82
|
const memeToken = sale.fetchSellingTokenInstanceKey();
|
|
82
83
|
|
|
83
84
|
// Enforce slippage tolerance
|
|
84
|
-
if (sellTokenDTO.expectedToken && sellTokenDTO.expectedToken.
|
|
85
|
+
if (sellTokenDTO.expectedToken && sellTokenDTO.expectedToken.isLessThan(tokensToSell)) {
|
|
85
86
|
throw new SlippageToleranceExceededError(
|
|
86
87
|
`expected ${sellTokenDTO.expectedToken.toString()}, but at least ${tokensToSell.toString()} tokens are required. Increase the expected amount or adjust your slippage tolerance.`
|
|
87
88
|
);
|
|
@@ -92,22 +93,12 @@ export async function sellWithNative(
|
|
|
92
93
|
await payReverseBondingCurveFee(
|
|
93
94
|
ctx,
|
|
94
95
|
sale,
|
|
95
|
-
|
|
96
|
+
nativeTokensPayout,
|
|
96
97
|
sellTokenDTO.extraFees?.maxAcceptableReverseBondingCurveFee
|
|
97
98
|
);
|
|
98
99
|
|
|
99
100
|
// Transfer launchpad transaction fees if applicable
|
|
100
|
-
|
|
101
|
-
if (launchpadFeeAddressConfiguration && transactionFees) {
|
|
102
|
-
await transferToken(ctx, {
|
|
103
|
-
from: ctx.callingUser,
|
|
104
|
-
to: launchpadFeeAddressConfiguration.feeAddress,
|
|
105
|
-
tokenInstanceKey: nativeToken,
|
|
106
|
-
quantity: new BigNumber(transactionFees),
|
|
107
|
-
allowancesToUse: [],
|
|
108
|
-
authorizedOnBehalf: undefined
|
|
109
|
-
});
|
|
110
|
-
}
|
|
101
|
+
await transferTransactionFees(ctx, sale, transactionFees, nativeToken);
|
|
111
102
|
|
|
112
103
|
// Send meme tokens from user to vault
|
|
113
104
|
await transferToken(ctx, {
|
|
@@ -124,7 +115,7 @@ export async function sellWithNative(
|
|
|
124
115
|
from: sellTokenDTO.vaultAddress,
|
|
125
116
|
to: ctx.callingUser,
|
|
126
117
|
tokenInstanceKey: nativeToken,
|
|
127
|
-
quantity:
|
|
118
|
+
quantity: nativeTokensPayout,
|
|
128
119
|
allowancesToUse: [],
|
|
129
120
|
authorizedOnBehalf: {
|
|
130
121
|
callingOnBehalf: sellTokenDTO.vaultAddress,
|
|
@@ -133,7 +124,7 @@ export async function sellWithNative(
|
|
|
133
124
|
});
|
|
134
125
|
|
|
135
126
|
// Update internal sale tracking
|
|
136
|
-
sale.sellToken(tokensToSell,
|
|
127
|
+
sale.sellToken(tokensToSell, nativeTokensPayout);
|
|
137
128
|
await putChainObject(ctx, sale);
|
|
138
129
|
|
|
139
130
|
const token = await fetchTokenClass(ctx, sale.sellingToken);
|
|
@@ -142,7 +133,7 @@ export async function sellWithNative(
|
|
|
142
133
|
totalFees: new BigNumber(transactionFees)
|
|
143
134
|
.plus(sellTokenDTO.extraFees?.maxAcceptableReverseBondingCurveFee ?? 0)
|
|
144
135
|
.toFixed(),
|
|
145
|
-
outputQuantity:
|
|
136
|
+
outputQuantity: nativeTokensPayout.toFixed(),
|
|
146
137
|
tokenName: token.name,
|
|
147
138
|
tradeType: "Sell",
|
|
148
139
|
vaultAddress: sellTokenDTO.vaultAddress,
|
|
@@ -26,6 +26,8 @@ import { users } from "@gala-chain/test";
|
|
|
26
26
|
import { createInstanceFn, createPlainFn } from "@gala-chain/test/lib/src/data/utils";
|
|
27
27
|
import BigNumber from "bignumber.js";
|
|
28
28
|
|
|
29
|
+
import { LaunchpadSale } from "../../api/types";
|
|
30
|
+
|
|
29
31
|
process.env.LAUNCHPAD_GALA_CLASS_COLLECTION = process.env.LAUNCHPAD_GALA_CLASS_COLLECTION ?? "GALA";
|
|
30
32
|
process.env.LAUNCHPAD_GALA_CLASS_CATEGORY = process.env.LAUNCHPAD_GALA_CLASS_CATEGORY ?? "Unit";
|
|
31
33
|
process.env.LAUNCHPAD_GALA_CLASS_TYPE = process.env.LAUNCHPAD_GALA_CLASS_TYPE ?? "none";
|
|
@@ -41,7 +43,7 @@ const tokenClassKeyPlain = createPlainFn({
|
|
|
41
43
|
const tokenClassPlain = createPlainFn({
|
|
42
44
|
...tokenClassKeyPlain(),
|
|
43
45
|
description: "Generated via automated test suite.",
|
|
44
|
-
decimals:
|
|
46
|
+
decimals: LaunchpadSale.NATIVE_TOKEN_DECIMALS,
|
|
45
47
|
image: "https://app.gala.games/test-image-placeholder-url.png",
|
|
46
48
|
isNonFungible: false,
|
|
47
49
|
maxCapacity: new BigNumber(100000000000000),
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* limitations under the License.
|
|
14
14
|
*/
|
|
15
15
|
import { ChainError, DefaultError, ErrorCode, NotFoundError } from "@gala-chain/api";
|
|
16
|
-
import { GalaChainContext, getObjectByKey } from "@gala-chain/chaincode";
|
|
16
|
+
import { GalaChainContext, fetchTokenClass, getObjectByKey } from "@gala-chain/chaincode";
|
|
17
17
|
import Decimal from "decimal.js";
|
|
18
18
|
|
|
19
19
|
import { LaunchpadFeeConfig, LaunchpadSale, SaleStatus } from "../../api/types";
|
|
@@ -66,3 +66,15 @@ export async function fetchLaunchpadFeeAddress(
|
|
|
66
66
|
|
|
67
67
|
return platformFeeAddress;
|
|
68
68
|
}
|
|
69
|
+
|
|
70
|
+
export async function fetchTokenDecimals(
|
|
71
|
+
ctx: GalaChainContext,
|
|
72
|
+
sale: LaunchpadSale
|
|
73
|
+
): Promise<{ sellingTokenDecimals: number; nativeTokenDecimals: number }> {
|
|
74
|
+
const sellingToken = await fetchTokenClass(ctx, sale.fetchSellingTokenInstanceKey());
|
|
75
|
+
const nativeToken = await fetchTokenClass(ctx, sale.fetchNativeTokenInstanceKey());
|
|
76
|
+
return {
|
|
77
|
+
sellingTokenDecimals: sellingToken.decimals,
|
|
78
|
+
nativeTokenDecimals: nativeToken.decimals
|
|
79
|
+
};
|
|
80
|
+
}
|
package/src/cli.ts
CHANGED
|
@@ -19,6 +19,8 @@ import type { ContractAPI } from "@gala-chain/api";
|
|
|
19
19
|
import type { GalaContract } from "@gala-chain/chaincode";
|
|
20
20
|
import "fabric-shim/cli";
|
|
21
21
|
import fs from "fs";
|
|
22
|
+
import os from "os";
|
|
23
|
+
import path from "path";
|
|
22
24
|
|
|
23
25
|
const [, , customCommand] = process.argv;
|
|
24
26
|
if (customCommand === "get-contract-names") {
|
|
@@ -27,7 +29,7 @@ if (customCommand === "get-contract-names") {
|
|
|
27
29
|
}
|
|
28
30
|
|
|
29
31
|
if (customCommand === "get-contract-api") {
|
|
30
|
-
saveContractAPI("
|
|
32
|
+
saveContractAPI(path.join(os.tmpdir(), "contract-api.json")); // output is stored at the operating system's default directory
|
|
31
33
|
process.exit(0);
|
|
32
34
|
}
|
|
33
35
|
|