@gala-chain/launchpad 1.0.0 → 1.0.2
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 +7 -7
- package/lib/src/api/types/LaunchpadBatchSubmitAuthorities.d.ts +12 -0
- package/lib/src/api/types/LaunchpadBatchSubmitAuthorities.d.ts.map +1 -0
- package/lib/src/api/types/LaunchpadBatchSubmitAuthorities.js +56 -0
- package/lib/src/api/types/LaunchpadBatchSubmitAuthorities.js.map +1 -0
- package/lib/src/api/types/LaunchpadDtos.d.ts +16 -0
- package/lib/src/api/types/LaunchpadDtos.d.ts.map +1 -1
- package/lib/src/api/types/LaunchpadDtos.js +53 -1
- package/lib/src/api/types/LaunchpadDtos.js.map +1 -1
- package/lib/src/api/types/LaunchpadFeeConfig.d.ts +3 -2
- package/lib/src/api/types/LaunchpadFeeConfig.d.ts.map +1 -1
- package/lib/src/api/types/LaunchpadFeeConfig.js +14 -4
- package/lib/src/api/types/LaunchpadFeeConfig.js.map +1 -1
- package/lib/src/api/types/index.d.ts +1 -0
- package/lib/src/api/types/index.d.ts.map +1 -1
- package/lib/src/api/types/index.js +1 -0
- package/lib/src/api/types/index.js.map +1 -1
- package/lib/src/chaincode/LaunchpadContract.d.ts +6 -1
- package/lib/src/chaincode/LaunchpadContract.d.ts.map +1 -1
- package/lib/src/chaincode/LaunchpadContract.js +85 -0
- 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 +15 -0
- 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 +24 -0
- package/lib/src/chaincode/launchpad/buyWithNative.js.map +1 -1
- package/lib/src/chaincode/launchpad/callMemeTokenIn.d.ts +1 -0
- package/lib/src/chaincode/launchpad/callMemeTokenIn.d.ts.map +1 -1
- package/lib/src/chaincode/launchpad/callMemeTokenIn.js +3 -1
- package/lib/src/chaincode/launchpad/callMemeTokenIn.js.map +1 -1
- package/lib/src/chaincode/launchpad/callMemeTokenOut.d.ts +1 -0
- package/lib/src/chaincode/launchpad/callMemeTokenOut.d.ts.map +1 -1
- package/lib/src/chaincode/launchpad/callMemeTokenOut.js +4 -1
- package/lib/src/chaincode/launchpad/callMemeTokenOut.js.map +1 -1
- package/lib/src/chaincode/launchpad/callNativeTokenIn.d.ts +1 -0
- package/lib/src/chaincode/launchpad/callNativeTokenIn.d.ts.map +1 -1
- package/lib/src/chaincode/launchpad/callNativeTokenIn.js +6 -2
- package/lib/src/chaincode/launchpad/callNativeTokenIn.js.map +1 -1
- package/lib/src/chaincode/launchpad/callNativeTokenOut.d.ts +1 -0
- package/lib/src/chaincode/launchpad/callNativeTokenOut.d.ts.map +1 -1
- package/lib/src/chaincode/launchpad/callNativeTokenOut.js +3 -1
- package/lib/src/chaincode/launchpad/callNativeTokenOut.js.map +1 -1
- package/lib/src/chaincode/launchpad/configureLaunchpadFeeConfig.d.ts +12 -0
- package/lib/src/chaincode/launchpad/configureLaunchpadFeeConfig.d.ts.map +1 -1
- package/lib/src/chaincode/launchpad/configureLaunchpadFeeConfig.js +26 -6
- package/lib/src/chaincode/launchpad/configureLaunchpadFeeConfig.js.map +1 -1
- package/lib/src/chaincode/launchpad/createSale.d.ts.map +1 -1
- package/lib/src/chaincode/launchpad/createSale.js +2 -0
- package/lib/src/chaincode/launchpad/createSale.js.map +1 -1
- package/lib/src/chaincode/launchpad/fees.d.ts +1 -0
- package/lib/src/chaincode/launchpad/fees.d.ts.map +1 -1
- package/lib/src/chaincode/launchpad/fees.js +6 -2
- package/lib/src/chaincode/launchpad/fees.js.map +1 -1
- package/lib/src/chaincode/launchpad/finaliseSale.js +3 -3
- package/lib/src/chaincode/launchpad/finaliseSale.js.map +1 -1
- package/lib/src/chaincode/launchpad/index.d.ts +1 -0
- package/lib/src/chaincode/launchpad/index.d.ts.map +1 -1
- package/lib/src/chaincode/launchpad/index.js +1 -0
- package/lib/src/chaincode/launchpad/index.js.map +1 -1
- package/lib/src/chaincode/launchpad/launchpadBatchSubmitAuthorizations.d.ts +24 -0
- package/lib/src/chaincode/launchpad/launchpadBatchSubmitAuthorizations.d.ts.map +1 -0
- package/lib/src/chaincode/launchpad/launchpadBatchSubmitAuthorizations.js +84 -0
- package/lib/src/chaincode/launchpad/launchpadBatchSubmitAuthorizations.js.map +1 -0
- package/lib/src/chaincode/launchpad/sellExactToken.d.ts.map +1 -1
- package/lib/src/chaincode/launchpad/sellExactToken.js +27 -8
- 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 +26 -2
- package/lib/src/chaincode/launchpad/sellWithNative.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +8 -8
- package/src/api/types/LaunchpadBatchSubmitAuthorities.ts +53 -0
- package/src/api/types/LaunchpadDtos.ts +44 -0
- package/src/api/types/LaunchpadFeeConfig.ts +13 -4
- package/src/api/types/index.ts +1 -0
- package/src/chaincode/LaunchpadContract.ts +96 -1
- package/src/chaincode/launchpad/buyExactToken.ts +17 -1
- package/src/chaincode/launchpad/buyWithNative.ts +28 -1
- package/src/chaincode/launchpad/callMemeTokenIn.ts +8 -3
- package/src/chaincode/launchpad/callMemeTokenOut.ts +8 -2
- package/src/chaincode/launchpad/callNativeTokenIn.ts +10 -3
- package/src/chaincode/launchpad/callNativeTokenOut.ts +8 -3
- package/src/chaincode/launchpad/configureLaunchpadFeeConfig.ts +27 -4
- package/src/chaincode/launchpad/createSale.ts +2 -0
- package/src/chaincode/launchpad/fees.ts +5 -1
- package/src/chaincode/launchpad/finaliseSale.ts +3 -3
- package/src/chaincode/launchpad/index.ts +1 -0
- package/src/chaincode/launchpad/launchpadBatchSubmitAuthorizations.spec.ts +185 -0
- package/src/chaincode/launchpad/launchpadBatchSubmitAuthorizations.ts +105 -0
- package/src/chaincode/launchpad/sellExactToken.ts +30 -11
- package/src/chaincode/launchpad/sellWithNative.ts +30 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gala-chain/launchpad",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "GalaChain Launchpad Chaincode",
|
|
5
5
|
"main": "lib/src/index.js",
|
|
6
6
|
"types": "lib/src/index.d.ts",
|
|
@@ -23,9 +23,9 @@
|
|
|
23
23
|
"update-snapshot": "jest --updateSnapshot"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@gala-chain/api": "2.3.
|
|
27
|
-
"@gala-chain/chaincode": "2.3.
|
|
28
|
-
"@gala-chain/dex": "1.0.
|
|
26
|
+
"@gala-chain/api": "~2.3.4",
|
|
27
|
+
"@gala-chain/chaincode": "~2.3.4",
|
|
28
|
+
"@gala-chain/dex": "1.0.4",
|
|
29
29
|
"@grpc/grpc-js": "1.10.10",
|
|
30
30
|
"decimal.js": "^10.5.0",
|
|
31
31
|
"dotenv": "^16.0.1",
|
|
@@ -33,9 +33,9 @@
|
|
|
33
33
|
"fabric-shim": "2.5.6"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@gala-chain/cli": "2.3.
|
|
37
|
-
"@gala-chain/client": "2.3.
|
|
38
|
-
"@gala-chain/test": "2.3.
|
|
36
|
+
"@gala-chain/cli": "~2.3.4",
|
|
37
|
+
"@gala-chain/client": "~2.3.4",
|
|
38
|
+
"@gala-chain/test": "~2.3.4",
|
|
39
39
|
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
|
|
40
40
|
"@types/jest": "^29.5.12",
|
|
41
41
|
"@types/node": "18.11.9",
|
|
@@ -51,4 +51,4 @@
|
|
|
51
51
|
"ts-node": "^10.9.1",
|
|
52
52
|
"typescript": "^5.3.3"
|
|
53
53
|
}
|
|
54
|
-
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
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 { ChainObject } from "@gala-chain/api";
|
|
16
|
+
import { Exclude } from "class-transformer";
|
|
17
|
+
import { ArrayNotEmpty, IsString } from "class-validator";
|
|
18
|
+
|
|
19
|
+
export class LaunchpadBatchSubmitAuthorities extends ChainObject {
|
|
20
|
+
@Exclude()
|
|
21
|
+
public static INDEX_KEY = "GCLBSA"; // GalaChain Launchpad Batch Submit Authorities
|
|
22
|
+
|
|
23
|
+
@ArrayNotEmpty()
|
|
24
|
+
@IsString({ each: true })
|
|
25
|
+
authorities: string[];
|
|
26
|
+
|
|
27
|
+
constructor(authorities: string[]) {
|
|
28
|
+
super();
|
|
29
|
+
this.authorities = authorities;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public addOrUpdateAuthorities(newAuthorities: string[]) {
|
|
33
|
+
this.authorities = newAuthorities;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
public addAuthority(authority: string) {
|
|
37
|
+
if (!this.authorities.includes(authority)) {
|
|
38
|
+
this.authorities.push(authority);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
public removeAuthority(authority: string) {
|
|
43
|
+
this.authorities = this.authorities.filter((auth) => auth !== authority);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
public isAuthorized(authority: string): boolean {
|
|
47
|
+
return this.authorities.includes(authority);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public getAuthorities(): string[] {
|
|
51
|
+
return [...this.authorities];
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -24,6 +24,8 @@ import {
|
|
|
24
24
|
import BigNumber from "bignumber.js";
|
|
25
25
|
import { Type } from "class-transformer";
|
|
26
26
|
import {
|
|
27
|
+
ArrayNotEmpty,
|
|
28
|
+
IsArray,
|
|
27
29
|
IsBoolean,
|
|
28
30
|
IsNotEmpty,
|
|
29
31
|
IsNumber,
|
|
@@ -180,6 +182,12 @@ export class CreateSaleResDto {
|
|
|
180
182
|
@IsNotEmpty()
|
|
181
183
|
public category: string;
|
|
182
184
|
|
|
185
|
+
@IsNotEmpty()
|
|
186
|
+
public type: string;
|
|
187
|
+
|
|
188
|
+
@IsNotEmpty()
|
|
189
|
+
public additionalKey: string;
|
|
190
|
+
|
|
183
191
|
@IsNotEmpty()
|
|
184
192
|
public functionName: string;
|
|
185
193
|
|
|
@@ -269,6 +277,9 @@ export class TradeResDto {
|
|
|
269
277
|
@IsNotEmpty()
|
|
270
278
|
public inputQuantity: string;
|
|
271
279
|
|
|
280
|
+
@IsNotEmpty()
|
|
281
|
+
public totalFees: string;
|
|
282
|
+
|
|
272
283
|
@IsNotEmpty()
|
|
273
284
|
public outputQuantity: string;
|
|
274
285
|
|
|
@@ -322,6 +333,12 @@ export class ConfigureLaunchpadFeeAddressDto extends SubmitCallDTO {
|
|
|
322
333
|
@IsUserAlias()
|
|
323
334
|
public newPlatformFeeAddress?: UserAlias;
|
|
324
335
|
|
|
336
|
+
@IsOptional()
|
|
337
|
+
@IsNumber()
|
|
338
|
+
@Min(0)
|
|
339
|
+
@Max(1)
|
|
340
|
+
public newFeeAmount?: number;
|
|
341
|
+
|
|
325
342
|
@IsOptional()
|
|
326
343
|
@IsUserAlias({ each: true })
|
|
327
344
|
public newAuthorities?: UserAlias[];
|
|
@@ -349,6 +366,10 @@ export class TradeCalculationResFeesDto {
|
|
|
349
366
|
@IsNotEmpty()
|
|
350
367
|
@IsString()
|
|
351
368
|
reverseBondingCurve: string;
|
|
369
|
+
|
|
370
|
+
@IsNotEmpty()
|
|
371
|
+
@IsString()
|
|
372
|
+
transactionFees: string;
|
|
352
373
|
}
|
|
353
374
|
|
|
354
375
|
export class TradeCalculationResDto {
|
|
@@ -360,3 +381,26 @@ export class TradeCalculationResDto {
|
|
|
360
381
|
@Type(() => TradeCalculationResFeesDto)
|
|
361
382
|
public extraFees: TradeCalculationResFeesDto;
|
|
362
383
|
}
|
|
384
|
+
|
|
385
|
+
export class AuthorizeBatchSubmitterDto extends SubmitCallDTO {
|
|
386
|
+
@IsArray()
|
|
387
|
+
@ArrayNotEmpty()
|
|
388
|
+
@IsString({ each: true })
|
|
389
|
+
authorities: string[];
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
export class DeauthorizeBatchSubmitterDto extends SubmitCallDTO {
|
|
393
|
+
@IsString()
|
|
394
|
+
authority: string;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
export class FetchBatchSubmitAuthoritiesDto extends ChainCallDTO {
|
|
398
|
+
// No additional fields needed for fetching all authorities
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
export class BatchSubmitAuthoritiesResDto extends ChainCallDTO {
|
|
402
|
+
@IsArray()
|
|
403
|
+
@ArrayNotEmpty()
|
|
404
|
+
@IsString({ each: true })
|
|
405
|
+
authorities: string[];
|
|
406
|
+
}
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
*/
|
|
15
15
|
import { ChainObject, IsUserAlias, UserAlias } from "@gala-chain/api";
|
|
16
16
|
import { Exclude } from "class-transformer";
|
|
17
|
-
import { ArrayNotEmpty, IsNotEmpty } from "class-validator";
|
|
17
|
+
import { ArrayNotEmpty, IsNotEmpty, IsNumber, Max, Min } from "class-validator";
|
|
18
18
|
import { JSONSchema } from "class-validator-jsonschema";
|
|
19
19
|
|
|
20
20
|
@JSONSchema({
|
|
@@ -22,24 +22,33 @@ import { JSONSchema } from "class-validator-jsonschema";
|
|
|
22
22
|
})
|
|
23
23
|
export class LaunchpadFeeConfig extends ChainObject {
|
|
24
24
|
@Exclude()
|
|
25
|
-
public static INDEX_KEY = "
|
|
25
|
+
public static INDEX_KEY = "GCLPFC"; // GalaChain Launchpad Fee Configuration
|
|
26
26
|
|
|
27
27
|
@IsNotEmpty()
|
|
28
28
|
@IsUserAlias()
|
|
29
29
|
feeAddress: UserAlias;
|
|
30
30
|
|
|
31
|
+
@IsNotEmpty()
|
|
32
|
+
@IsNumber()
|
|
33
|
+
@Min(0)
|
|
34
|
+
@Max(1)
|
|
35
|
+
public feeAmount: number;
|
|
36
|
+
|
|
31
37
|
@ArrayNotEmpty()
|
|
32
38
|
@IsUserAlias({ each: true })
|
|
33
39
|
authorities: UserAlias[];
|
|
34
40
|
|
|
35
|
-
constructor(feeAddress: UserAlias, authorities: UserAlias[]) {
|
|
41
|
+
constructor(feeAddress: UserAlias, feeAmount: number, authorities: UserAlias[]) {
|
|
36
42
|
super();
|
|
37
43
|
this.feeAddress = feeAddress;
|
|
44
|
+
this.feeAmount = feeAmount;
|
|
38
45
|
this.authorities = authorities;
|
|
39
46
|
}
|
|
40
47
|
|
|
41
|
-
public
|
|
48
|
+
public updateFeeConfig(newfeeAddress: UserAlias, newFeeAmount: number, newAuthorities: UserAlias[]) {
|
|
42
49
|
this.feeAddress = newfeeAddress;
|
|
50
|
+
this.feeAmount = newFeeAmount;
|
|
43
51
|
this.authorities = newAuthorities;
|
|
52
|
+
this.validate();
|
|
44
53
|
}
|
|
45
54
|
}
|
package/src/api/types/index.ts
CHANGED
|
@@ -12,21 +12,28 @@
|
|
|
12
12
|
* See the License for the specific language governing permissions and
|
|
13
13
|
* limitations under the License.
|
|
14
14
|
*/
|
|
15
|
+
import { BatchDto, GalaChainResponse, UnauthorizedError } from "@gala-chain/api";
|
|
15
16
|
import {
|
|
17
|
+
BatchWriteLimitExceededError,
|
|
16
18
|
EVALUATE,
|
|
17
19
|
Evaluate,
|
|
18
20
|
GalaChainContext,
|
|
19
21
|
GalaContract,
|
|
20
22
|
GalaTransaction,
|
|
21
|
-
Submit
|
|
23
|
+
Submit,
|
|
24
|
+
getApiMethod
|
|
22
25
|
} from "@gala-chain/chaincode";
|
|
23
26
|
|
|
24
27
|
import { version } from "../../package.json";
|
|
25
28
|
import {
|
|
29
|
+
AuthorizeBatchSubmitterDto,
|
|
30
|
+
BatchSubmitAuthoritiesResDto,
|
|
26
31
|
ConfigureLaunchpadFeeAddressDto,
|
|
27
32
|
CreateSaleResDto,
|
|
28
33
|
CreateTokenSaleDTO,
|
|
34
|
+
DeauthorizeBatchSubmitterDto,
|
|
29
35
|
ExactTokenQuantityDto,
|
|
36
|
+
FetchBatchSubmitAuthoritiesDto,
|
|
30
37
|
FetchSaleDto,
|
|
31
38
|
FinalizeTokenAllocationDto,
|
|
32
39
|
LaunchpadFeeConfig,
|
|
@@ -45,6 +52,7 @@ import {
|
|
|
45
52
|
sellWithNativeFeeGate
|
|
46
53
|
} from "./dexLaunchpadFeeGate";
|
|
47
54
|
import {
|
|
55
|
+
authorizeLaunchpadBatchSubmitter,
|
|
48
56
|
buyExactToken,
|
|
49
57
|
buyWithNative,
|
|
50
58
|
calculatePreMintTokens,
|
|
@@ -54,9 +62,12 @@ import {
|
|
|
54
62
|
callNativeTokenOut,
|
|
55
63
|
configureLaunchpadFeeAddress,
|
|
56
64
|
createSale,
|
|
65
|
+
deauthorizeLaunchpadBatchSubmitter,
|
|
66
|
+
fetchLaunchpadBatchSubmitAuthorities,
|
|
57
67
|
fetchLaunchpadFeeConfig,
|
|
58
68
|
fetchSaleDetails,
|
|
59
69
|
finalizeTokenAllocation,
|
|
70
|
+
getLaunchpadBatchSubmitAuthorities,
|
|
60
71
|
sellExactToken,
|
|
61
72
|
sellWithNative
|
|
62
73
|
} from "./launchpad";
|
|
@@ -208,4 +219,88 @@ export class LaunchpadContract extends GalaContract {
|
|
|
208
219
|
public async FetchLaunchpadFeeConfig(ctx: GalaChainContext): Promise<LaunchpadFeeConfig> {
|
|
209
220
|
return fetchLaunchpadFeeConfig(ctx);
|
|
210
221
|
}
|
|
222
|
+
|
|
223
|
+
public async BatchSubmit(ctx: GalaChainContext, batchDto: BatchDto): Promise<GalaChainResponse<unknown>[]> {
|
|
224
|
+
// Check if the calling user is authorized to submit batches
|
|
225
|
+
const batchAuthorities = await fetchLaunchpadBatchSubmitAuthorities(ctx);
|
|
226
|
+
if (!batchAuthorities.isAuthorized(ctx.callingUser)) {
|
|
227
|
+
throw new UnauthorizedError(
|
|
228
|
+
`CallingUser ${ctx.callingUser} is not authorized to submit batches. ` +
|
|
229
|
+
`Authorized users: ${batchAuthorities.getAuthorities().join(", ")}`
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
const responses: GalaChainResponse<unknown>[] = [];
|
|
234
|
+
|
|
235
|
+
const softWritesLimit = batchDto.writesLimit ?? BatchDto.WRITES_DEFAULT_LIMIT;
|
|
236
|
+
const writesLimit = Math.min(softWritesLimit, BatchDto.WRITES_HARD_LIMIT);
|
|
237
|
+
let writesCount = ctx.stub.getWritesCount();
|
|
238
|
+
|
|
239
|
+
for (const [index, op] of batchDto.operations.entries()) {
|
|
240
|
+
// Use sandboxed context to avoid flushes of writes and deletes, and populate
|
|
241
|
+
// the stub with current writes and deletes.
|
|
242
|
+
const sandboxCtx = ctx.createReadOnlyContext(index);
|
|
243
|
+
sandboxCtx.stub.setWrites(ctx.stub.getWrites());
|
|
244
|
+
sandboxCtx.stub.setDeletes(ctx.stub.getDeletes());
|
|
245
|
+
|
|
246
|
+
// Execute the operation. Collect both successful and failed responses.
|
|
247
|
+
let response: GalaChainResponse<unknown>;
|
|
248
|
+
try {
|
|
249
|
+
if (writesCount >= writesLimit) {
|
|
250
|
+
throw new BatchWriteLimitExceededError(writesLimit);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
const method = getApiMethod(this, op.method, (m) => m.isWrite && m.methodName !== "BatchSubmit");
|
|
254
|
+
response = await this[method.methodName](sandboxCtx, op.dto);
|
|
255
|
+
} catch (error) {
|
|
256
|
+
response = GalaChainResponse.Error(error);
|
|
257
|
+
}
|
|
258
|
+
responses.push(response);
|
|
259
|
+
|
|
260
|
+
// Update the current context with the writes and deletes if the operation
|
|
261
|
+
// is successful.
|
|
262
|
+
if (GalaChainResponse.isSuccess(response)) {
|
|
263
|
+
ctx.stub.setWrites(sandboxCtx.stub.getWrites());
|
|
264
|
+
ctx.stub.setDeletes(sandboxCtx.stub.getDeletes());
|
|
265
|
+
writesCount = ctx.stub.getWritesCount();
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
return responses;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
@Submit({
|
|
272
|
+
in: AuthorizeBatchSubmitterDto,
|
|
273
|
+
out: BatchSubmitAuthoritiesResDto,
|
|
274
|
+
allowedOrgs: [process.env.CURATOR_ORG_MSP ?? "CuratorOrg"]
|
|
275
|
+
})
|
|
276
|
+
public async AuthorizeBatchSubmitter(
|
|
277
|
+
ctx: GalaChainContext,
|
|
278
|
+
dto: AuthorizeBatchSubmitterDto
|
|
279
|
+
): Promise<BatchSubmitAuthoritiesResDto> {
|
|
280
|
+
return await authorizeLaunchpadBatchSubmitter(ctx, dto);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
@Submit({
|
|
284
|
+
in: DeauthorizeBatchSubmitterDto,
|
|
285
|
+
out: BatchSubmitAuthoritiesResDto,
|
|
286
|
+
allowedOrgs: [process.env.CURATOR_ORG_MSP ?? "CuratorOrg"]
|
|
287
|
+
})
|
|
288
|
+
public async DeauthorizeBatchSubmitter(
|
|
289
|
+
ctx: GalaChainContext,
|
|
290
|
+
dto: DeauthorizeBatchSubmitterDto
|
|
291
|
+
): Promise<BatchSubmitAuthoritiesResDto> {
|
|
292
|
+
return await deauthorizeLaunchpadBatchSubmitter(ctx, dto);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
@GalaTransaction({
|
|
296
|
+
type: EVALUATE,
|
|
297
|
+
in: FetchBatchSubmitAuthoritiesDto,
|
|
298
|
+
out: BatchSubmitAuthoritiesResDto
|
|
299
|
+
})
|
|
300
|
+
public async GetBatchSubmitAuthorities(
|
|
301
|
+
ctx: GalaChainContext,
|
|
302
|
+
dto: FetchBatchSubmitAuthoritiesDto
|
|
303
|
+
): Promise<BatchSubmitAuthoritiesResDto> {
|
|
304
|
+
return await getLaunchpadBatchSubmitAuthorities(ctx, dto);
|
|
305
|
+
}
|
|
211
306
|
}
|
|
@@ -17,7 +17,7 @@ import { BigNumber } from "bignumber.js";
|
|
|
17
17
|
|
|
18
18
|
import { ExactTokenQuantityDto, LaunchpadSale, TradeResDto } from "../../api/types";
|
|
19
19
|
import { SlippageToleranceExceededError } from "../../api/utils/error";
|
|
20
|
-
import { fetchAndValidateSale } from "../utils";
|
|
20
|
+
import { fetchAndValidateSale, fetchLaunchpadFeeAddress } from "../utils";
|
|
21
21
|
import { callNativeTokenIn } from "./callNativeTokenIn";
|
|
22
22
|
import { finalizeSale } from "./finaliseSale";
|
|
23
23
|
|
|
@@ -53,6 +53,7 @@ export async function buyExactToken(
|
|
|
53
53
|
|
|
54
54
|
// Calculate the required amount of native tokens to buy the specified token amount
|
|
55
55
|
const callNativeTokenInResult1 = await callNativeTokenIn(ctx, buyTokenDTO);
|
|
56
|
+
let transactionFees = callNativeTokenInResult1.extraFees.transactionFees;
|
|
56
57
|
let nativeTokensToBuy = new BigNumber(callNativeTokenInResult1.calculatedQuantity);
|
|
57
58
|
const nativeToken = sale.fetchNativeTokenInstanceKey();
|
|
58
59
|
const memeToken = sale.fetchSellingTokenInstanceKey();
|
|
@@ -62,6 +63,7 @@ export async function buyExactToken(
|
|
|
62
63
|
buyTokenDTO.tokenQuantity = tokenLeftInVault;
|
|
63
64
|
const callNativeTokenInResult2 = await callNativeTokenIn(ctx, buyTokenDTO);
|
|
64
65
|
nativeTokensToBuy = new BigNumber(callNativeTokenInResult2.calculatedQuantity);
|
|
66
|
+
transactionFees = callNativeTokenInResult2.extraFees.transactionFees;
|
|
65
67
|
isSaleFinalized = true;
|
|
66
68
|
}
|
|
67
69
|
|
|
@@ -81,6 +83,19 @@ export async function buyExactToken(
|
|
|
81
83
|
);
|
|
82
84
|
}
|
|
83
85
|
|
|
86
|
+
// Transfer transaction fees
|
|
87
|
+
const launchpadFeeAddressConfiguration = await fetchLaunchpadFeeAddress(ctx);
|
|
88
|
+
if (launchpadFeeAddressConfiguration && transactionFees) {
|
|
89
|
+
await transferToken(ctx, {
|
|
90
|
+
from: ctx.callingUser,
|
|
91
|
+
to: launchpadFeeAddressConfiguration.feeAddress,
|
|
92
|
+
tokenInstanceKey: nativeToken,
|
|
93
|
+
quantity: new BigNumber(transactionFees),
|
|
94
|
+
allowancesToUse: [],
|
|
95
|
+
authorizedOnBehalf: undefined
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
84
99
|
// Transfer native tokens from the buyer to the vault
|
|
85
100
|
await transferToken(ctx, {
|
|
86
101
|
from: ctx.callingUser,
|
|
@@ -117,6 +132,7 @@ export async function buyExactToken(
|
|
|
117
132
|
const token = await fetchTokenClass(ctx, sale.sellingToken);
|
|
118
133
|
return {
|
|
119
134
|
inputQuantity: nativeTokensToBuy.toFixed(),
|
|
135
|
+
totalFees: transactionFees,
|
|
120
136
|
outputQuantity: buyTokenDTO.tokenQuantity.toFixed(),
|
|
121
137
|
tokenName: token.name,
|
|
122
138
|
tradeType: "Buy",
|
|
@@ -17,7 +17,7 @@ import { BigNumber } from "bignumber.js";
|
|
|
17
17
|
|
|
18
18
|
import { ExactTokenQuantityDto, LaunchpadSale, NativeTokenQuantityDto, TradeResDto } from "../../api/types";
|
|
19
19
|
import { SlippageToleranceExceededError } from "../../api/utils/error";
|
|
20
|
-
import { fetchAndValidateSale } from "../utils";
|
|
20
|
+
import { fetchAndValidateSale, fetchLaunchpadFeeAddress } from "../utils";
|
|
21
21
|
import { callMemeTokenOut } from "./callMemeTokenOut";
|
|
22
22
|
import { callNativeTokenIn } from "./callNativeTokenIn";
|
|
23
23
|
import { finalizeSale } from "./finaliseSale";
|
|
@@ -49,22 +49,30 @@ export async function buyWithNative(
|
|
|
49
49
|
buyTokenDTO: NativeTokenQuantityDto
|
|
50
50
|
): Promise<TradeResDto> {
|
|
51
51
|
let isSaleFinalized = false;
|
|
52
|
+
|
|
53
|
+
// Fetch and validate sale state
|
|
52
54
|
const sale = await fetchAndValidateSale(ctx, buyTokenDTO.vaultAddress);
|
|
53
55
|
const tokensLeftInVault = new BigNumber(sale.sellingTokenQuantity);
|
|
56
|
+
|
|
57
|
+
// Calculate how many tokens the user can buy and fee info
|
|
54
58
|
const callMemeTokenOutResult = await callMemeTokenOut(ctx, buyTokenDTO);
|
|
59
|
+
let transactionFees = callMemeTokenOutResult.extraFees.transactionFees;
|
|
55
60
|
let tokensToBuy = new BigNumber(callMemeTokenOutResult.calculatedQuantity);
|
|
56
61
|
|
|
57
62
|
const nativeToken = sale.fetchNativeTokenInstanceKey();
|
|
58
63
|
const memeToken = sale.fetchSellingTokenInstanceKey();
|
|
59
64
|
|
|
65
|
+
// If vault has fewer tokens than what user wants to buy, cap the purchase
|
|
60
66
|
if (tokensLeftInVault.comparedTo(tokensToBuy) <= 0) {
|
|
61
67
|
tokensToBuy = tokensLeftInVault;
|
|
62
68
|
const nativeTokensrequiredToBuyDto = new ExactTokenQuantityDto(buyTokenDTO.vaultAddress, tokensToBuy);
|
|
63
69
|
const callNativeTokenInResult = await callNativeTokenIn(ctx, nativeTokensrequiredToBuyDto);
|
|
70
|
+
transactionFees = callMemeTokenOutResult.extraFees.transactionFees;
|
|
64
71
|
buyTokenDTO.nativeTokenQuantity = new BigNumber(callNativeTokenInResult.calculatedQuantity);
|
|
65
72
|
isSaleFinalized = true;
|
|
66
73
|
}
|
|
67
74
|
|
|
75
|
+
// Finalize sale if market cap is reached
|
|
68
76
|
if (
|
|
69
77
|
buyTokenDTO.nativeTokenQuantity
|
|
70
78
|
.plus(new BigNumber(sale.nativeTokenQuantity))
|
|
@@ -72,12 +80,27 @@ export async function buyWithNative(
|
|
|
72
80
|
)
|
|
73
81
|
isSaleFinalized = true;
|
|
74
82
|
|
|
83
|
+
// Check for slippage condition
|
|
75
84
|
if (buyTokenDTO.expectedToken && buyTokenDTO.expectedToken.comparedTo(tokensToBuy) > 0) {
|
|
76
85
|
throw new SlippageToleranceExceededError(
|
|
77
86
|
"Tokens expected from this operation are more than the the actual amount that will be provided."
|
|
78
87
|
);
|
|
79
88
|
}
|
|
80
89
|
|
|
90
|
+
// Transfer transaction fees to launchpad fee address
|
|
91
|
+
const launchpadFeeAddressConfiguration = await fetchLaunchpadFeeAddress(ctx);
|
|
92
|
+
if (launchpadFeeAddressConfiguration && transactionFees) {
|
|
93
|
+
await transferToken(ctx, {
|
|
94
|
+
from: ctx.callingUser,
|
|
95
|
+
to: launchpadFeeAddressConfiguration.feeAddress,
|
|
96
|
+
tokenInstanceKey: nativeToken,
|
|
97
|
+
quantity: new BigNumber(transactionFees),
|
|
98
|
+
allowancesToUse: [],
|
|
99
|
+
authorizedOnBehalf: undefined
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Transfer native tokens from buyer to vault
|
|
81
104
|
await transferToken(ctx, {
|
|
82
105
|
from: ctx.callingUser,
|
|
83
106
|
to: buyTokenDTO.vaultAddress,
|
|
@@ -87,6 +110,7 @@ export async function buyWithNative(
|
|
|
87
110
|
authorizedOnBehalf: undefined
|
|
88
111
|
});
|
|
89
112
|
|
|
113
|
+
// Transfer meme tokens from vault to buyer
|
|
90
114
|
await transferToken(ctx, {
|
|
91
115
|
from: buyTokenDTO.vaultAddress,
|
|
92
116
|
to: ctx.callingUser,
|
|
@@ -99,9 +123,11 @@ export async function buyWithNative(
|
|
|
99
123
|
}
|
|
100
124
|
});
|
|
101
125
|
|
|
126
|
+
// Update sale object with purchase data
|
|
102
127
|
sale.buyToken(tokensToBuy, buyTokenDTO.nativeTokenQuantity);
|
|
103
128
|
await putChainObject(ctx, sale);
|
|
104
129
|
|
|
130
|
+
// Finalize sale if it's complete
|
|
105
131
|
if (isSaleFinalized) {
|
|
106
132
|
await finalizeSale(ctx, sale);
|
|
107
133
|
}
|
|
@@ -109,6 +135,7 @@ export async function buyWithNative(
|
|
|
109
135
|
const token = await fetchTokenClass(ctx, sale.sellingToken);
|
|
110
136
|
return {
|
|
111
137
|
inputQuantity: buyTokenDTO.nativeTokenQuantity.toFixed(),
|
|
138
|
+
totalFees: transactionFees,
|
|
112
139
|
outputQuantity: tokensToBuy.toFixed(),
|
|
113
140
|
tokenName: token.name,
|
|
114
141
|
tradeType: "Buy",
|
|
@@ -18,8 +18,8 @@ import { BigNumber } from "bignumber.js";
|
|
|
18
18
|
import Decimal from "decimal.js";
|
|
19
19
|
|
|
20
20
|
import { LaunchpadSale, NativeTokenQuantityDto } from "../../api/types";
|
|
21
|
-
import { fetchAndValidateSale, getBondingConstants } from "../utils";
|
|
22
|
-
import { calculateReverseBondingCurveFee } from "./fees";
|
|
21
|
+
import { fetchAndValidateSale, fetchLaunchpadFeeAddress, getBondingConstants } from "../utils";
|
|
22
|
+
import { calculateReverseBondingCurveFee, calculateTransactionFee } from "./fees";
|
|
23
23
|
|
|
24
24
|
BigNumber.config({
|
|
25
25
|
ROUNDING_MODE: BigNumber.ROUND_UP
|
|
@@ -72,11 +72,16 @@ function calculateMemeTokensRequired(sale: LaunchpadSale, requestedNativeTokenQu
|
|
|
72
72
|
*/
|
|
73
73
|
export async function callMemeTokenIn(ctx: GalaChainContext, sellTokenDTO: NativeTokenQuantityDto) {
|
|
74
74
|
const sale = await fetchAndValidateSale(ctx, sellTokenDTO.vaultAddress);
|
|
75
|
+
const launchpadFeeAddressConfiguration = await fetchLaunchpadFeeAddress(ctx);
|
|
75
76
|
|
|
76
77
|
return {
|
|
77
78
|
calculatedQuantity: calculateMemeTokensRequired(sale, sellTokenDTO.nativeTokenQuantity),
|
|
78
79
|
extraFees: {
|
|
79
|
-
reverseBondingCurve: calculateReverseBondingCurveFee(sale, sellTokenDTO.nativeTokenQuantity).toString()
|
|
80
|
+
reverseBondingCurve: calculateReverseBondingCurveFee(sale, sellTokenDTO.nativeTokenQuantity).toString(),
|
|
81
|
+
transactionFees: calculateTransactionFee(
|
|
82
|
+
sellTokenDTO.nativeTokenQuantity,
|
|
83
|
+
launchpadFeeAddressConfiguration?.feeAmount
|
|
84
|
+
)
|
|
80
85
|
}
|
|
81
86
|
};
|
|
82
87
|
}
|
|
@@ -17,7 +17,8 @@ import { BigNumber } from "bignumber.js";
|
|
|
17
17
|
import Decimal from "decimal.js";
|
|
18
18
|
|
|
19
19
|
import { LaunchpadSale, NativeTokenQuantityDto } from "../../api/types";
|
|
20
|
-
import { fetchAndValidateSale, getBondingConstants } from "../utils";
|
|
20
|
+
import { fetchAndValidateSale, fetchLaunchpadFeeAddress, getBondingConstants } from "../utils";
|
|
21
|
+
import { calculateTransactionFee } from "./fees";
|
|
21
22
|
|
|
22
23
|
BigNumber.config({
|
|
23
24
|
ROUNDING_MODE: BigNumber.ROUND_UP
|
|
@@ -71,10 +72,15 @@ export async function callMemeTokenOut(ctx: GalaChainContext, buyTokenDTO: Nativ
|
|
|
71
72
|
roundedResult = new Decimal("1e+7").minus(new Decimal(totalTokensSold));
|
|
72
73
|
}
|
|
73
74
|
|
|
75
|
+
const launchpadFeeAddressConfiguration = await fetchLaunchpadFeeAddress(ctx);
|
|
74
76
|
return {
|
|
75
77
|
calculatedQuantity: roundedResult.toFixed(),
|
|
76
78
|
extraFees: {
|
|
77
|
-
reverseBondingCurve: "0"
|
|
79
|
+
reverseBondingCurve: "0",
|
|
80
|
+
transactionFees: calculateTransactionFee(
|
|
81
|
+
BigNumber(nativeTokens.toFixed()),
|
|
82
|
+
launchpadFeeAddressConfiguration?.feeAmount
|
|
83
|
+
)
|
|
78
84
|
}
|
|
79
85
|
};
|
|
80
86
|
}
|
|
@@ -17,7 +17,8 @@ import { BigNumber } from "bignumber.js";
|
|
|
17
17
|
import Decimal from "decimal.js";
|
|
18
18
|
|
|
19
19
|
import { ExactTokenQuantityDto } from "../../api/types";
|
|
20
|
-
import { fetchAndValidateSale, getBondingConstants } from "../utils";
|
|
20
|
+
import { fetchAndValidateSale, fetchLaunchpadFeeAddress, getBondingConstants } from "../utils";
|
|
21
|
+
import { calculateTransactionFee } from "./fees";
|
|
21
22
|
|
|
22
23
|
BigNumber.config({
|
|
23
24
|
ROUNDING_MODE: BigNumber.ROUND_UP
|
|
@@ -62,10 +63,16 @@ export async function callNativeTokenIn(ctx: GalaChainContext, buyTokenDTO: Exac
|
|
|
62
63
|
|
|
63
64
|
const price = constantFactor.mul(differenceOfExponentials);
|
|
64
65
|
|
|
66
|
+
const launchpadFeeAddressConfiguration = await fetchLaunchpadFeeAddress(ctx);
|
|
67
|
+
const roundedPrice = price.toDecimalPlaces(8, Decimal.ROUND_UP).toFixed();
|
|
65
68
|
return {
|
|
66
|
-
calculatedQuantity:
|
|
69
|
+
calculatedQuantity: roundedPrice,
|
|
67
70
|
extraFees: {
|
|
68
|
-
reverseBondingCurve: "0"
|
|
71
|
+
reverseBondingCurve: "0",
|
|
72
|
+
transactionFees: calculateTransactionFee(
|
|
73
|
+
BigNumber(roundedPrice),
|
|
74
|
+
launchpadFeeAddressConfiguration?.feeAmount
|
|
75
|
+
)
|
|
69
76
|
}
|
|
70
77
|
};
|
|
71
78
|
}
|
|
@@ -17,8 +17,8 @@ import { BigNumber } from "bignumber.js";
|
|
|
17
17
|
import Decimal from "decimal.js";
|
|
18
18
|
|
|
19
19
|
import { ExactTokenQuantityDto, LaunchpadSale } from "../../api/types";
|
|
20
|
-
import { fetchAndValidateSale, getBondingConstants } from "../utils";
|
|
21
|
-
import { calculateReverseBondingCurveFee } from "./fees";
|
|
20
|
+
import { fetchAndValidateSale, fetchLaunchpadFeeAddress, getBondingConstants } from "../utils";
|
|
21
|
+
import { calculateReverseBondingCurveFee, calculateTransactionFee } from "./fees";
|
|
22
22
|
|
|
23
23
|
BigNumber.config({
|
|
24
24
|
ROUNDING_MODE: BigNumber.ROUND_UP
|
|
@@ -72,10 +72,15 @@ function calculateNativeTokensReceived(sale: LaunchpadSale, tokensToSellBn: BigN
|
|
|
72
72
|
export async function callNativeTokenOut(ctx: GalaChainContext, sellTokenDTO: ExactTokenQuantityDto) {
|
|
73
73
|
const sale = await fetchAndValidateSale(ctx, sellTokenDTO.vaultAddress);
|
|
74
74
|
const nativeTokensReceived = calculateNativeTokensReceived(sale, sellTokenDTO.tokenQuantity);
|
|
75
|
+
const launchpadFeeAddressConfiguration = await fetchLaunchpadFeeAddress(ctx);
|
|
75
76
|
return {
|
|
76
77
|
calculatedQuantity: nativeTokensReceived,
|
|
77
78
|
extraFees: {
|
|
78
|
-
reverseBondingCurve: calculateReverseBondingCurveFee(sale, BigNumber(nativeTokensReceived)).toString()
|
|
79
|
+
reverseBondingCurve: calculateReverseBondingCurveFee(sale, BigNumber(nativeTokensReceived)).toString(),
|
|
80
|
+
transactionFees: calculateTransactionFee(
|
|
81
|
+
BigNumber(nativeTokensReceived),
|
|
82
|
+
launchpadFeeAddressConfiguration?.feeAmount
|
|
83
|
+
)
|
|
79
84
|
}
|
|
80
85
|
};
|
|
81
86
|
}
|