@gala-chain/launchpad-sdk 0.4.0 โ 0.4.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/CHANGELOG.md +24 -32
- package/README.md +181 -481
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -6,41 +6,33 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
|
6
6
|
|
|
7
7
|
## [0.4.0] - 2024-01-24
|
|
8
8
|
|
|
9
|
-
###
|
|
10
|
-
|
|
9
|
+
### First Public Release
|
|
10
|
+
|
|
11
|
+
A comprehensive TypeScript SDK for the Gala Launchpad Backend API, providing type-safe authentication, trading, and real-time features for DeFi applications.
|
|
12
|
+
|
|
13
|
+
### Core Features
|
|
14
|
+
- **Flat API Architecture**: All methods directly accessible on SDK root for simplicity
|
|
15
|
+
- Pool management, trading, user operations, and comments all on `sdk.methodName()`
|
|
16
|
+
- No nested controllers or complex navigation patterns
|
|
17
|
+
- **Wallet Creation with Auto-Detection**: Smart `createWallet()` function
|
|
11
18
|
- Automatically detects private key vs mnemonic input format
|
|
12
19
|
- Supports 12-word and 24-word mnemonics
|
|
13
20
|
- Handles 64-character hex private keys (with or without 0x prefix)
|
|
14
21
|
- Generates random wallets when no input provided
|
|
15
|
-
- **SDK Factory Functions**: Simplified
|
|
22
|
+
- **SDK Factory Functions**: Simplified initialization
|
|
16
23
|
- `createLaunchpadSDK()` - Main factory with wallet auto-detection
|
|
17
24
|
- `createTestLaunchpadSDK()` - Test-optimized configuration
|
|
18
|
-
- **Input Validation**:
|
|
19
|
-
- **
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
###
|
|
25
|
-
- **
|
|
26
|
-
- **
|
|
27
|
-
- **
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
- **
|
|
31
|
-
|
|
32
|
-
### Developer Experience
|
|
33
|
-
- **Auto-Detection**: No need to specify input type - helpers detect format automatically
|
|
34
|
-
- **Error Messages**: Clear, helpful error messages for invalid inputs
|
|
35
|
-
- **Type Safety**: Full TypeScript support with strict typing
|
|
36
|
-
- **Test Coverage**: 100% line coverage for all helper functions
|
|
37
|
-
|
|
38
|
-
### Technical Details
|
|
39
|
-
- 132 total tests passing (27 new helper tests)
|
|
40
|
-
- Bundle size maintained under 50KB limit
|
|
41
|
-
- Full backward compatibility preserved
|
|
42
|
-
- Production-ready with comprehensive error handling
|
|
43
|
-
|
|
44
|
-
## Previous Releases
|
|
45
|
-
|
|
46
|
-
See git commit history for changes in versions prior to 0.4.0.
|
|
25
|
+
- **Input Validation**: `validateWalletInput()` for format validation
|
|
26
|
+
- **Type-Safe Authentication**: Ethereum wallet-based authentication with automatic signature generation
|
|
27
|
+
- **Comprehensive Trading**: Buy/sell tokens with slippage protection via GalaChain
|
|
28
|
+
- **Real-time Features**: WebSocket support for live data feeds
|
|
29
|
+
- **Multi-Environment Support**: Production, staging, and custom backend URLs
|
|
30
|
+
|
|
31
|
+
### Technical Implementation
|
|
32
|
+
- **Complete API Coverage**: 22/22 backend endpoints working
|
|
33
|
+
- **TypeScript-First**: Full type safety with comprehensive type definitions
|
|
34
|
+
- **Multi-Target**: Compatible with Node.js and browser environments
|
|
35
|
+
- **Framework Integration**: React hooks and Vue composables available
|
|
36
|
+
- **High Test Coverage**: 132 tests passing with 80%+ line coverage
|
|
37
|
+
- **Production Ready**: Bundle size under 50KB, comprehensive error handling
|
|
38
|
+
- **Security**: Input validation, secure defaults, no credential exposure
|
package/README.md
CHANGED
|
@@ -1,135 +1,91 @@
|
|
|
1
|
-
# Gala Launchpad SDK
|
|
1
|
+
# Gala Launchpad SDK v0.4.0
|
|
2
2
|
|
|
3
|
-
A comprehensive TypeScript SDK for the Gala Launchpad Backend API, providing type-safe authentication,
|
|
3
|
+
A comprehensive TypeScript SDK for the Gala Launchpad Backend API, providing type-safe authentication, trading, and real-time features for DeFi applications.
|
|
4
4
|
|
|
5
5
|
[](https://badge.fury.io/js/@gala-chain%2Flaunchpad-sdk)
|
|
6
6
|
[](https://opensource.org/licenses/MIT)
|
|
7
7
|
[](http://www.typescriptlang.org/)
|
|
8
8
|
|
|
9
|
-
## ๐
|
|
9
|
+
## ๐ Features
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
**Wallet Creation with Auto-Detection:**
|
|
12
12
|
|
|
13
|
-
- **
|
|
14
|
-
- **
|
|
15
|
-
- **
|
|
16
|
-
- **
|
|
17
|
-
- **
|
|
13
|
+
- **Auto-Detection**: Automatically detects private key vs mnemonic input format
|
|
14
|
+
- **Flexible Input**: Supports 12/24-word mnemonics and 64-character hex private keys
|
|
15
|
+
- **SDK Factory Functions**: Simplified SDK initialization with `createLaunchpadSDK()`
|
|
16
|
+
- **Input Validation**: Built-in `validateWalletInput()` for format validation
|
|
17
|
+
- **Test Support**: `createTestLaunchpadSDK()` for testing environments
|
|
18
|
+
- **Flat API Design**: All methods directly on SDK root for simplicity
|
|
18
19
|
|
|
19
|
-
###
|
|
20
|
+
### Developer Experience
|
|
20
21
|
|
|
21
|
-
**Before v3.0 (Nested APIs):**
|
|
22
22
|
```typescript
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
23
|
+
import { createLaunchpadSDK, createWallet } from '@gala-chain/launchpad-sdk';
|
|
24
|
+
|
|
25
|
+
// Auto-detect wallet format and create SDK
|
|
26
|
+
const sdk = createLaunchpadSDK({
|
|
27
|
+
wallet: 'your-private-key-or-mnemonic' // Auto-detects format!
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
// Or create wallet separately with auto-detection
|
|
31
|
+
const wallet = createWallet('private-key-or-mnemonic');
|
|
32
|
+
const sdk = createLaunchpadSDK({ wallet });
|
|
33
|
+
|
|
34
|
+
// Test SDK with defaults
|
|
35
|
+
const testSDK = createTestLaunchpadSDK();
|
|
29
36
|
```
|
|
30
37
|
|
|
31
|
-
|
|
38
|
+
## ๐ Flat API Architecture
|
|
39
|
+
|
|
40
|
+
**All methods directly on SDK root - simple and clean:**
|
|
41
|
+
|
|
32
42
|
```typescript
|
|
33
|
-
//
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
43
|
+
// Everything is directly on sdk!
|
|
44
|
+
await sdk.fetchPools({ type: 'recent' });
|
|
45
|
+
await sdk.calculateBuyAmount({ tokenName: 'token', amount: '100', type: 'native' });
|
|
46
|
+
await sdk.buy({ tokenName: 'token', amount: '100', type: 'native' });
|
|
47
|
+
await sdk.fetchGalaBalance();
|
|
48
|
+
await sdk.postComment({ tokenName: 'token', content: 'Great project!' });
|
|
39
49
|
```
|
|
40
50
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
**Pool & Token Operations:**
|
|
44
|
-
- `sdk.fetchPools()` - Get pools (recent, popular, search)
|
|
45
|
-
- `sdk.fetchTokenDistribution()` - Token holder distribution
|
|
46
|
-
- `sdk.fetchTokenBadges()` - Volume and engagement badges
|
|
47
|
-
- `sdk.fetchSaleDetails()` - Token sale information
|
|
48
|
-
- `sdk.createSale()` - Create new token sale
|
|
49
|
-
- `sdk.uploadTokenImage()` - Upload token images
|
|
50
|
-
|
|
51
|
-
**Price Calculations:**
|
|
52
|
-
- `sdk.calculateBuyAmount()` - Calculate GALA cost for tokens
|
|
53
|
-
- `sdk.calculateSellAmount()` - Calculate GALA received from tokens
|
|
54
|
-
- `sdk.calculateInitialBuyAmount()` - Pre-mint calculations
|
|
55
|
-
|
|
56
|
-
**Trading Operations:**
|
|
57
|
-
- `sdk.buy()` - Buy tokens with slippage protection
|
|
58
|
-
- `sdk.sell()` - Sell tokens with slippage protection
|
|
59
|
-
|
|
60
|
-
**Data & Analytics:**
|
|
61
|
-
- `sdk.fetchTrades()` - Trade history with filtering
|
|
62
|
-
- `sdk.fetchComments()` - Token comments
|
|
63
|
-
- `sdk.createComment()` - Post new comment
|
|
64
|
-
- `sdk.fetchGalaBalance()` - User GALA balance
|
|
65
|
-
- `sdk.fetchTokenBalance()` - User token holdings
|
|
66
|
-
|
|
67
|
-
**User Operations:**
|
|
68
|
-
- `sdk.fetchUserProfile()` - User profile data
|
|
69
|
-
- `sdk.updateProfile()` - Update user profile
|
|
70
|
-
- `sdk.requestFaucet()` - Request test tokens
|
|
71
|
-
|
|
72
|
-
## ๐ Features
|
|
51
|
+
## ๐ Key Features
|
|
73
52
|
|
|
74
53
|
- **Type-Safe API Client**: Full TypeScript support with comprehensive type definitions
|
|
75
54
|
- **Signature Authentication**: Ethereum wallet-based authentication with automatic signature generation
|
|
76
|
-
- **
|
|
55
|
+
- **Helper Functions**: Auto-detecting wallet creation and SDK factory functions
|
|
56
|
+
- **Flat API Design**: All methods directly accessible on SDK root
|
|
77
57
|
- **Pool Management**: Create, fetch, and check token pools on the launchpad
|
|
78
58
|
- **Token Trading**: Buy and sell tokens with slippage protection via GalaChain
|
|
79
|
-
- **
|
|
80
|
-
- **User Operations**: Profile management, token balances, and faucet transfers
|
|
59
|
+
- **User Operations**: Portfolio management, token balances, and account management
|
|
81
60
|
- **Comment System**: Post and retrieve comments on token pools
|
|
82
61
|
- **Comprehensive Validation**: Input validation and error handling for all operations
|
|
83
62
|
- **Multi-Environment Support**: Production, staging, and custom backend URLs
|
|
84
63
|
|
|
85
|
-
### ๐ฏ **Complete API Restructure**
|
|
86
|
-
- โ
**Flat Structure**: 22 methods directly on SDK root
|
|
87
|
-
- โ
**Semantic Naming**: `fetch*`, `calculate*`, action verbs
|
|
88
|
-
- โ
**Options Bag**: Consistent `{tokenName, ...}` pattern
|
|
89
|
-
- โ
**Legacy Removal**: All deprecated methods removed
|
|
90
|
-
- โ
**Type Safety**: Full TypeScript support maintained
|
|
91
|
-
- โ
**User API**: Profile and account management (6 methods)
|
|
92
|
-
- โ
**Comment API**: TokenName-based comment system (2 methods)
|
|
93
|
-
|
|
94
|
-
### ๐ **Token Architecture**
|
|
95
|
-
**Important:** Tokens are created as pools and traded through GalaChain integration.
|
|
96
|
-
- โ
**Token Creation**: Create token sales via `/launchpad/create-sale`
|
|
97
|
-
- โ
**Pool Management**: Unified pool fetching with flexible filtering
|
|
98
|
-
- โ
**Trading Integration**: Simplified buy/sell operations with GalaChain Gateway
|
|
99
|
-
- โ
**Real-time Data**: Graph data and sale details for market analysis
|
|
100
|
-
|
|
101
64
|
## ๐ฆ Installation
|
|
102
65
|
|
|
103
66
|
```bash
|
|
104
|
-
npm install @gala-chain/launchpad-sdk@^
|
|
67
|
+
npm install @gala-chain/launchpad-sdk@^0.4.0
|
|
105
68
|
```
|
|
106
69
|
|
|
107
70
|
Or with yarn:
|
|
108
71
|
|
|
109
72
|
```bash
|
|
110
|
-
yarn add @gala-chain/launchpad-sdk@^
|
|
73
|
+
yarn add @gala-chain/launchpad-sdk@^0.4.0
|
|
111
74
|
```
|
|
112
75
|
|
|
113
|
-
> **โ ๏ธ Breaking Changes in v3.0**: Complete API restructure with flat design. See migration guide below.
|
|
114
|
-
|
|
115
76
|
## ๐ Quick Start
|
|
116
77
|
|
|
117
|
-
###
|
|
78
|
+
### Using Helper Functions (Recommended)
|
|
118
79
|
|
|
119
80
|
```typescript
|
|
120
|
-
import {
|
|
121
|
-
import { LaunchpadSDK } from '@gala-chain/launchpad-sdk';
|
|
81
|
+
import { createLaunchpadSDK } from '@gala-chain/launchpad-sdk';
|
|
122
82
|
|
|
123
|
-
//
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
wallet: wallet,
|
|
127
|
-
baseUrl: 'https://lpad-backend-dev1.defi.gala.com',
|
|
128
|
-
timeout: 30000,
|
|
129
|
-
debug: false
|
|
83
|
+
// Auto-detecting SDK creation (easiest method)
|
|
84
|
+
const sdk = createLaunchpadSDK({
|
|
85
|
+
wallet: 'your-private-key-or-mnemonic' // Auto-detects format!
|
|
130
86
|
});
|
|
131
87
|
|
|
132
|
-
//
|
|
88
|
+
// Flat API - All methods directly on SDK root
|
|
133
89
|
|
|
134
90
|
// Pool Management
|
|
135
91
|
const pools = await sdk.fetchPools({ type: 'recent', limit: 10 });
|
|
@@ -152,477 +108,221 @@ const buyResult = await sdk.buy({
|
|
|
152
108
|
});
|
|
153
109
|
|
|
154
110
|
// Data & Analytics
|
|
155
|
-
const trades = await sdk.fetchTrades('dragnrkti');
|
|
156
|
-
const comments = await sdk.fetchComments('dragnrkti');
|
|
157
|
-
const balance = await sdk.fetchGalaBalance(
|
|
111
|
+
const trades = await sdk.fetchTrades({ tokenName: 'dragnrkti' });
|
|
112
|
+
const comments = await sdk.fetchComments({ tokenName: 'dragnrkti' });
|
|
113
|
+
const balance = await sdk.fetchGalaBalance();
|
|
158
114
|
|
|
159
115
|
// User Operations
|
|
160
|
-
const profile = await sdk.
|
|
116
|
+
const profile = await sdk.fetchProfile();
|
|
161
117
|
const tokenBalance = await sdk.fetchTokenBalance({
|
|
162
118
|
tokenName: 'dragnrkti',
|
|
163
119
|
walletAddress: sdk.getAddress()
|
|
164
120
|
});
|
|
165
|
-
|
|
166
|
-
// Create a new token sale
|
|
167
|
-
const sale = await sdk.launchpad.createSale({
|
|
168
|
-
tokenName: 'MyToken',
|
|
169
|
-
tokenSymbol: 'MTK',
|
|
170
|
-
tokenDescription: 'My awesome token',
|
|
171
|
-
preBuyQuantity: '100', // Initial GALA to invest
|
|
172
|
-
tokenImage: 'https://example.com/token-image.png',
|
|
173
|
-
websiteUrl: 'https://mytoken.com'
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
// Fetch pools with unified API
|
|
177
|
-
const recentPools = await sdk.launchpad.getPools({
|
|
178
|
-
type: 'recent',
|
|
179
|
-
page: 1,
|
|
180
|
-
limit: 10
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
// Get price calculation with unified API
|
|
184
|
-
const buyAmount = await sdk.launchpad.getBuyTokenAmount('tinyevil', {
|
|
185
|
-
amount: '10', // 10 GALA
|
|
186
|
-
type: 'native'
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
// Buy tokens with unified API
|
|
190
|
-
const buyResult = await sdk.trading.buyToken('tinyevil', {
|
|
191
|
-
amount: '10', // 10 GALA
|
|
192
|
-
type: 'native',
|
|
193
|
-
slippage: 5 // 5% slippage tolerance
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
// Check user's GALA balance
|
|
197
|
-
const balance = await sdk.user.getGalaBalance({
|
|
198
|
-
userAddress: sdk.getAddress()
|
|
199
|
-
});
|
|
200
121
|
```
|
|
201
122
|
|
|
202
|
-
###
|
|
123
|
+
### Manual SDK Creation (Alternative)
|
|
203
124
|
|
|
204
125
|
```typescript
|
|
205
126
|
import { Wallet } from 'ethers';
|
|
206
127
|
import { LaunchpadSDK } from '@gala-chain/launchpad-sdk';
|
|
207
128
|
|
|
208
|
-
|
|
129
|
+
// Create wallet manually
|
|
130
|
+
const wallet = new Wallet(process.env.PRIVATE_KEY);
|
|
209
131
|
|
|
210
|
-
//
|
|
132
|
+
// Initialize SDK
|
|
211
133
|
const sdk = new LaunchpadSDK({
|
|
212
|
-
wallet: wallet,
|
|
134
|
+
wallet: wallet,
|
|
213
135
|
baseUrl: 'https://lpad-backend-dev1.defi.gala.com',
|
|
214
136
|
timeout: 30000,
|
|
215
137
|
debug: false
|
|
216
138
|
});
|
|
217
139
|
|
|
218
|
-
//
|
|
219
|
-
const
|
|
220
|
-
wallet: wallet,
|
|
221
|
-
baseUrl: 'https://your-custom-backend.com',
|
|
222
|
-
timeout: 60000,
|
|
223
|
-
debug: true, // Enable request/response logging
|
|
224
|
-
maxRetries: 3,
|
|
225
|
-
retryDelay: 1000
|
|
226
|
-
});
|
|
227
|
-
```
|
|
228
|
-
|
|
229
|
-
**Common Backend URLs:**
|
|
230
|
-
- **Development**: `https://lpad-backend-dev1.defi.gala.com`
|
|
231
|
-
- **Custom**: Specify your own backend URL
|
|
232
|
-
|
|
233
|
-
### Address Format Utilities
|
|
234
|
-
|
|
235
|
-
The SDK includes utilities for converting between Ethereum and backend address formats:
|
|
236
|
-
|
|
237
|
-
```typescript
|
|
238
|
-
// Get wallet address in different formats
|
|
239
|
-
const ethereumAddress = sdk.getEthereumAddress(); // "0x742d35Cc..."
|
|
240
|
-
const backendAddress = sdk.getAddress(); // "eth|742d35Cc..."
|
|
241
|
-
|
|
242
|
-
// Manual conversion utilities
|
|
243
|
-
import { formatAddressForBackend, formatAddressForEthereum } from '@gala-chain/launchpad-sdk';
|
|
244
|
-
|
|
245
|
-
const backendFormat = formatAddressForBackend('0x742d35Cc...'); // "eth|742d35Cc..."
|
|
246
|
-
const ethFormat = formatAddressForEthereum('eth|742d35Cc...'); // "0x742d35Cc..."
|
|
247
|
-
```
|
|
248
|
-
|
|
249
|
-
## ๐ API Reference
|
|
250
|
-
|
|
251
|
-
### Core SDK
|
|
252
|
-
|
|
253
|
-
- **`LaunchpadSDK`** - Main SDK class with wallet-based authentication
|
|
254
|
-
- **`launchpad`** - Unified pool operations and price calculations (6 methods)
|
|
255
|
-
- **`trading`** - Unified trading operations (2 methods)
|
|
256
|
-
- **`trade`** - Simplified trade history with client-side filtering (1 method)
|
|
257
|
-
- **`user`** - Profile and balance management (6 methods)
|
|
258
|
-
- **`comment`** - TokenName-based comment system (2 methods)
|
|
259
|
-
|
|
260
|
-
### New Unified API Methods
|
|
261
|
-
|
|
262
|
-
#### Unified Pool Management
|
|
263
|
-
```typescript
|
|
264
|
-
// Get pools with flexible filtering (replaces 4 separate methods)
|
|
265
|
-
const pools = await sdk.launchpad.getPools({
|
|
266
|
-
type: 'recent' | 'popular', // Optional filter
|
|
267
|
-
search: 'keyword', // Optional search
|
|
268
|
-
tokenName: 'specific_token', // Optional token filter
|
|
269
|
-
page: 1,
|
|
270
|
-
limit: 20
|
|
271
|
-
});
|
|
272
|
-
```
|
|
273
|
-
|
|
274
|
-
#### Unified Price Calculations
|
|
275
|
-
```typescript
|
|
276
|
-
// Buy calculations (replaces 2 separate methods)
|
|
277
|
-
const buyCalc = await sdk.launchpad.getBuyTokenAmount('tokenName', {
|
|
278
|
-
amount: '100',
|
|
279
|
-
type: 'native' | 'exact'
|
|
280
|
-
});
|
|
281
|
-
|
|
282
|
-
// Sell calculations (replaces 2 separate methods)
|
|
283
|
-
const sellCalc = await sdk.launchpad.getSellTokenAmount('tokenName', {
|
|
284
|
-
amount: '50',
|
|
285
|
-
type: 'exact' | 'native'
|
|
286
|
-
});
|
|
287
|
-
```
|
|
288
|
-
|
|
289
|
-
#### Unified Trading Operations
|
|
290
|
-
```typescript
|
|
291
|
-
// Buy tokens (replaces 2 separate methods)
|
|
292
|
-
const buyResult = await sdk.trading.buyToken('tokenName', {
|
|
293
|
-
amount: '100',
|
|
294
|
-
type: 'native' | 'exact',
|
|
295
|
-
slippage: 5 // Optional, defaults to 5%
|
|
296
|
-
});
|
|
297
|
-
|
|
298
|
-
// Sell tokens (replaces 2 separate methods)
|
|
299
|
-
const sellResult = await sdk.trading.sellToken('tokenName', {
|
|
300
|
-
amount: '50',
|
|
301
|
-
type: 'exact' | 'native',
|
|
302
|
-
slippage: 3 // Optional, defaults to 5%
|
|
303
|
-
});
|
|
304
|
-
```
|
|
305
|
-
|
|
306
|
-
#### Unified Trade History
|
|
307
|
-
```typescript
|
|
308
|
-
// Get all trades and filter client-side (more performant)
|
|
309
|
-
const allTrades = await sdk.trade.getTrades('tokenName', { page: 1, limit: 20 });
|
|
310
|
-
|
|
311
|
-
// Filter client-side for specific trade types
|
|
312
|
-
const buyTrades = allTrades.data.filter(trade => trade.tradeType === 'buy');
|
|
313
|
-
const sellTrades = allTrades.data.filter(trade => trade.tradeType === 'sell');
|
|
140
|
+
// Same flat API available
|
|
141
|
+
const pools = await sdk.fetchPools({ type: 'recent' });
|
|
314
142
|
```
|
|
315
143
|
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
### Authentication
|
|
319
|
-
|
|
320
|
-
Authentication is handled automatically using wallet signatures:
|
|
144
|
+
## ๐ฏ Complete Example: Trading Flow
|
|
321
145
|
|
|
322
146
|
```typescript
|
|
323
|
-
import {
|
|
147
|
+
import { createLaunchpadSDK } from '@gala-chain/launchpad-sdk';
|
|
324
148
|
|
|
325
|
-
//
|
|
326
|
-
const
|
|
327
|
-
|
|
328
|
-
wallet: wallet,
|
|
329
|
-
baseUrl: 'https://lpad-backend-dev1.defi.gala.com'
|
|
149
|
+
// 1. Create SDK with auto-detection
|
|
150
|
+
const sdk = createLaunchpadSDK({
|
|
151
|
+
wallet: 'your-private-key-or-mnemonic'
|
|
330
152
|
});
|
|
331
153
|
|
|
332
|
-
//
|
|
333
|
-
const pools = await sdk.
|
|
334
|
-
|
|
335
|
-
// Get wallet addresses
|
|
336
|
-
const ethAddress = sdk.getEthereumAddress(); // 0x format
|
|
337
|
-
const backendAddress = sdk.getAddress(); // eth| format
|
|
338
|
-
```
|
|
339
|
-
|
|
340
|
-
The SDK automatically generates and signs authentication messages for each request using your wallet private key.
|
|
341
|
-
|
|
342
|
-
### Pool Management
|
|
343
|
-
|
|
344
|
-
```typescript
|
|
345
|
-
// Create a new token sale
|
|
346
|
-
const sale = await sdk.launchpad.createSale({
|
|
347
|
-
tokenName: 'MyToken',
|
|
348
|
-
tokenSymbol: 'MTK',
|
|
349
|
-
tokenDescription: 'My awesome token',
|
|
350
|
-
preBuyQuantity: '100', // Initial GALA investment
|
|
351
|
-
tokenImage: 'https://example.com/token.png',
|
|
352
|
-
websiteUrl: 'https://mytoken.com'
|
|
353
|
-
});
|
|
354
|
-
|
|
355
|
-
// Fetch pools with unified API
|
|
356
|
-
const recentPools = await sdk.launchpad.getPools({
|
|
154
|
+
// 2. Check available pools
|
|
155
|
+
const pools = await sdk.fetchPools({
|
|
357
156
|
type: 'recent',
|
|
358
|
-
page: 1,
|
|
359
|
-
limit: 20
|
|
360
|
-
});
|
|
361
|
-
|
|
362
|
-
const popularPools = await sdk.launchpad.getPools({
|
|
363
|
-
type: 'popular',
|
|
364
|
-
page: 1,
|
|
365
|
-
limit: 20
|
|
366
|
-
});
|
|
367
|
-
|
|
368
|
-
const searchResults = await sdk.launchpad.getPools({
|
|
369
|
-
search: 'gaming',
|
|
370
|
-
page: 1,
|
|
371
157
|
limit: 10
|
|
372
158
|
});
|
|
373
159
|
|
|
374
|
-
//
|
|
375
|
-
const
|
|
376
|
-
tokenName: 'tinyevil'
|
|
377
|
-
});
|
|
378
|
-
|
|
379
|
-
// Get graph data for token
|
|
380
|
-
const graphData = await sdk.launchpad.getGraphData({
|
|
160
|
+
// 3. Get price quote
|
|
161
|
+
const quote = await sdk.calculateBuyAmount({
|
|
381
162
|
tokenName: 'tinyevil',
|
|
382
|
-
|
|
383
|
-
to: Date.now(),
|
|
384
|
-
resolution: 3600 // 1 hour
|
|
385
|
-
});
|
|
386
|
-
```
|
|
387
|
-
|
|
388
|
-
### Price Calculations with Unified API
|
|
389
|
-
|
|
390
|
-
The SDK provides unified methods for all price calculation scenarios:
|
|
391
|
-
|
|
392
|
-
```typescript
|
|
393
|
-
// Buy with GALA - Calculate tokens you'll receive
|
|
394
|
-
const buyWithGala = await sdk.launchpad.getBuyTokenAmount('tinyevil', {
|
|
395
|
-
amount: '10', // 10 GALA
|
|
396
|
-
type: 'native'
|
|
397
|
-
});
|
|
398
|
-
console.log('Tokens to receive:', buyWithGala.data.calculatedQuantity);
|
|
399
|
-
|
|
400
|
-
// Buy exact tokens - Calculate GALA needed
|
|
401
|
-
const buyExactTokens = await sdk.launchpad.getBuyTokenAmount('tinyevil', {
|
|
402
|
-
amount: '100', // 100 tokens
|
|
403
|
-
type: 'exact'
|
|
404
|
-
});
|
|
405
|
-
console.log('GALA needed:', buyExactTokens.data.calculatedQuantity);
|
|
406
|
-
|
|
407
|
-
// Sell exact tokens - Calculate GALA you'll receive
|
|
408
|
-
const sellExactTokens = await sdk.launchpad.getSellTokenAmount('tinyevil', {
|
|
409
|
-
amount: '50', // 50 tokens
|
|
410
|
-
type: 'exact'
|
|
411
|
-
});
|
|
412
|
-
console.log('GALA to receive:', sellExactTokens.data.calculatedQuantity);
|
|
413
|
-
|
|
414
|
-
// Sell for exact GALA - Calculate tokens needed
|
|
415
|
-
const sellForGala = await sdk.launchpad.getSellTokenAmount('tinyevil', {
|
|
416
|
-
amount: '5', // 5 GALA
|
|
163
|
+
amount: '100',
|
|
417
164
|
type: 'native'
|
|
418
165
|
});
|
|
419
|
-
console.log('Tokens needed:', sellForGala.data.calculatedQuantity);
|
|
420
|
-
|
|
421
|
-
// Pre-mint calculation during token launch
|
|
422
|
-
const preMintResult = await sdk.launchpad.calculatePreMintTokens({
|
|
423
|
-
nativeTokenQuantity: '1000000000000000000' // 1 GALA for pre-buy
|
|
424
|
-
});
|
|
425
|
-
if (preMintResult.Status === 1) {
|
|
426
|
-
console.log('Pre-mint tokens:', preMintResult.Data.calculatedQuantity);
|
|
427
|
-
console.log('Fees:', preMintResult.Data.extraFees);
|
|
428
|
-
}
|
|
429
|
-
```
|
|
430
166
|
|
|
431
|
-
|
|
167
|
+
console.log(`Buying 100 GALA worth of tokens will get you: ${quote.outTokenAmount} TINYEVIL`);
|
|
432
168
|
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
amount: '
|
|
437
|
-
type: 'native',
|
|
169
|
+
// 4. Execute trade with slippage protection
|
|
170
|
+
const buyResult = await sdk.buy({
|
|
171
|
+
tokenName: 'tinyevil',
|
|
172
|
+
amount: '100',
|
|
173
|
+
type: 'native',
|
|
438
174
|
slippage: 5 // 5% slippage tolerance
|
|
439
175
|
});
|
|
440
176
|
|
|
441
|
-
//
|
|
442
|
-
const
|
|
443
|
-
amount: '50', // 50 tokens or 50 GALA depending on type
|
|
444
|
-
type: 'exact', // 'exact' = selling exact tokens, 'native' = receiving exact GALA
|
|
445
|
-
slippage: 3 // 3% slippage tolerance
|
|
446
|
-
});
|
|
447
|
-
|
|
448
|
-
// Get trade history with client-side filtering (more performant)
|
|
449
|
-
const allTrades = await sdk.trade.getTrades('tinyevil', { page: 1, limit: 20 });
|
|
450
|
-
|
|
451
|
-
// Filter client-side for specific analysis
|
|
452
|
-
const buyTrades = allTrades.data.filter(trade => trade.tradeType === 'buy');
|
|
453
|
-
const sellTrades = allTrades.data.filter(trade => trade.tradeType === 'sell');
|
|
454
|
-
|
|
455
|
-
// Get current sale details
|
|
456
|
-
const saleDetails = await sdk.trade.getSaleDetailsByTokenName('tinyevil');
|
|
457
|
-
```
|
|
458
|
-
|
|
459
|
-
### User Operations
|
|
460
|
-
|
|
461
|
-
```typescript
|
|
462
|
-
// Get user's created tokens
|
|
463
|
-
const tokenList = await sdk.user.getTokenList({
|
|
464
|
-
address: sdk.getAddress(),
|
|
465
|
-
type: 'DEFI', // or 'ASSET'
|
|
466
|
-
page: 1,
|
|
467
|
-
limit: 10
|
|
468
|
-
});
|
|
469
|
-
|
|
470
|
-
// Get user's token holdings
|
|
471
|
-
const holdings = await sdk.user.getTokensHeld({
|
|
472
|
-
address: sdk.getAddress(),
|
|
473
|
-
page: 1,
|
|
474
|
-
limit: 10
|
|
475
|
-
});
|
|
476
|
-
|
|
477
|
-
// Check GALA balance
|
|
478
|
-
const balance = await sdk.user.getGalaBalance({
|
|
479
|
-
userAddress: sdk.getAddress()
|
|
480
|
-
});
|
|
177
|
+
// 5. Check trade history
|
|
178
|
+
const trades = await sdk.fetchTrades({ tokenName: 'tinyevil' });
|
|
481
179
|
|
|
482
|
-
//
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
userAddress: sdk.getAddress()
|
|
180
|
+
// 6. Post a comment about your trade
|
|
181
|
+
await sdk.postComment({
|
|
182
|
+
tokenName: 'tinyevil',
|
|
183
|
+
content: 'Just bought some tokens! Great project!'
|
|
487
184
|
});
|
|
488
185
|
|
|
489
|
-
//
|
|
490
|
-
const
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
userAddress: sdk.getAddress(),
|
|
495
|
-
amount: '1000000000000000000' // 1 token with 18 decimals
|
|
186
|
+
// 7. Check your balance
|
|
187
|
+
const balance = await sdk.fetchGalaBalance();
|
|
188
|
+
const tokenBalance = await sdk.fetchTokenBalance({
|
|
189
|
+
tokenName: 'tinyevil',
|
|
190
|
+
walletAddress: sdk.getAddress()
|
|
496
191
|
});
|
|
497
192
|
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
console.log('Faucet transfer successful:', faucet.message);
|
|
501
|
-
}
|
|
193
|
+
console.log(`GALA Balance: ${balance.balance}`);
|
|
194
|
+
console.log(`TINYEVIL Balance: ${tokenBalance.balance}`);
|
|
502
195
|
```
|
|
503
196
|
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
**
|
|
507
|
-
|
|
197
|
+
## ๐ฏ Available Methods
|
|
198
|
+
|
|
199
|
+
### **Fetch Operations**
|
|
200
|
+
- `fetchPools(options?)` - Get pools (recent, popular, search)
|
|
201
|
+
- `fetchTokenDistribution(tokenName)` - Token holder distribution
|
|
202
|
+
- `fetchTokenBadges(tokenName)` - Volume and engagement badges
|
|
203
|
+
- `fetchSaleDetails(tokenName)` - Token sale information
|
|
204
|
+
- `fetchGraphData(options)` - Price chart data
|
|
205
|
+
- `fetchTrades(options)` - Trade history
|
|
206
|
+
- `fetchGalaBalance(walletAddress?)` - User GALA balance
|
|
207
|
+
- `fetchTokenBalance(options)` - User token balance
|
|
208
|
+
- `fetchComments(options)` - Token comments
|
|
209
|
+
- `fetchProfile(walletAddress?)` - User profile
|
|
210
|
+
|
|
211
|
+
### **Calculate Operations**
|
|
212
|
+
- `calculateBuyAmount(options)` - Calculate GALA cost for tokens
|
|
213
|
+
- `calculateSellAmount(options)` - Calculate GALA received from tokens
|
|
214
|
+
- `calculateInitialBuyAmount(options)` - Pre-mint calculations
|
|
215
|
+
|
|
216
|
+
### **Trading Operations**
|
|
217
|
+
- `buy(options)` - Buy tokens with slippage protection
|
|
218
|
+
- `sell(options)` - Sell tokens with slippage protection
|
|
219
|
+
|
|
220
|
+
### **Content Operations**
|
|
221
|
+
- `postComment(options)` - Post comment on token
|
|
222
|
+
- `createTokenAndPool(data)` - Create new token sale
|
|
223
|
+
- `uploadTokenImage(options)` - Upload token image
|
|
224
|
+
- `updateProfile(data)` - Update user profile
|
|
225
|
+
- `uploadProfileImage(options)` - Upload profile image
|
|
226
|
+
|
|
227
|
+
### **Validation & Utilities**
|
|
228
|
+
- `isTokenNameAvailable(tokenName)` - Check name availability
|
|
229
|
+
- `isTokenSymbolAvailable(symbol)` - Check symbol availability
|
|
230
|
+
- `getAddress()` - Get backend format address (eth|...)
|
|
231
|
+
- `getEthereumAddress()` - Get Ethereum format address (0x...)
|
|
232
|
+
- `resolveVaultAddress(tokenName)` - Get token vault address
|
|
233
|
+
- `cleanup()` - Cleanup resources
|
|
234
|
+
|
|
235
|
+
## ๐ง Helper Functions
|
|
236
|
+
|
|
237
|
+
### **Wallet Creation**
|
|
508
238
|
```typescript
|
|
509
|
-
|
|
510
|
-
const comments = await sdk.comment.getCommentsByTokenName("dragnrkti", 1, 10);
|
|
511
|
-
console.log('Comments:', comments.data?.comments);
|
|
239
|
+
import { createWallet, validateWalletInput } from '@gala-chain/launchpad-sdk';
|
|
512
240
|
|
|
513
|
-
//
|
|
514
|
-
|
|
241
|
+
// Auto-detect format and create wallet
|
|
242
|
+
const wallet = createWallet('private-key-or-24-word-mnemonic');
|
|
243
|
+
const randomWallet = createWallet(); // Generate random wallet
|
|
515
244
|
|
|
516
|
-
//
|
|
517
|
-
|
|
245
|
+
// Validate input format without creating wallet
|
|
246
|
+
const isValid = validateWalletInput('0x1234...'); // boolean
|
|
518
247
|
```
|
|
519
248
|
|
|
520
|
-
|
|
521
|
-
|
|
249
|
+
### **SDK Factory Functions**
|
|
522
250
|
```typescript
|
|
523
|
-
import {
|
|
524
|
-
import { LaunchpadSDK } from '@gala-chain/launchpad-sdk';
|
|
251
|
+
import { createLaunchpadSDK, createTestLaunchpadSDK } from '@gala-chain/launchpad-sdk';
|
|
525
252
|
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
253
|
+
// Main factory with auto-detection
|
|
254
|
+
const sdk = createLaunchpadSDK({
|
|
255
|
+
wallet: 'your-private-key-or-mnemonic',
|
|
256
|
+
config: {
|
|
257
|
+
baseUrl: 'https://lpad-backend-dev1.defi.gala.com',
|
|
258
|
+
debug: true
|
|
259
|
+
}
|
|
531
260
|
});
|
|
532
|
-
```
|
|
533
261
|
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
262
|
+
// Test-optimized SDK
|
|
263
|
+
const testSDK = createTestLaunchpadSDK({
|
|
264
|
+
wallet: 'test-private-key'
|
|
265
|
+
});
|
|
266
|
+
```
|
|
537
267
|
|
|
538
|
-
|
|
268
|
+
## ๐ง Configuration
|
|
539
269
|
|
|
540
270
|
```typescript
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
const buyTrades = await sdk.trade.getBuyTradesByTokenName('token', { page: 1, limit: 10 });
|
|
553
|
-
const sellTrades = await sdk.trade.getSellTradesByTokenName('token', { page: 1, limit: 10 });
|
|
554
|
-
|
|
555
|
-
// โ
NEW UNIFIED API (recommended)
|
|
556
|
-
const recentPools = await sdk.launchpad.getPools({ type: 'recent', page: 1, limit: 10 });
|
|
557
|
-
const popularPools = await sdk.launchpad.getPools({ type: 'popular', page: 1, limit: 10 });
|
|
558
|
-
const searchResults = await sdk.launchpad.getPools({ search: 'gaming', page: 1, limit: 10 });
|
|
559
|
-
|
|
560
|
-
const buyAmount = await sdk.launchpad.getBuyTokenAmount('token', { amount: '100', type: 'native' });
|
|
561
|
-
const sellAmount = await sdk.launchpad.getSellTokenAmount('token', { amount: '50', type: 'exact' });
|
|
562
|
-
|
|
563
|
-
const buyResult = await sdk.trading.buyToken('token', { amount: '100', type: 'native', slippage: 5 });
|
|
564
|
-
const sellResult = await sdk.trading.sellToken('token', { amount: '50', type: 'exact', slippage: 5 });
|
|
565
|
-
|
|
566
|
-
const allTrades = await sdk.trade.getTrades('token', { page: 1, limit: 10 });
|
|
567
|
-
const buyTrades = allTrades.data.filter(t => t.tradeType === 'buy');
|
|
568
|
-
const sellTrades = allTrades.data.filter(t => t.tradeType === 'sell');
|
|
271
|
+
interface LaunchpadSDKConfig {
|
|
272
|
+
wallet: Wallet; // ethers.js Wallet instance
|
|
273
|
+
baseUrl?: string; // Backend URL (default: dev environment)
|
|
274
|
+
galaChainBaseUrl?: string; // GalaChain gateway URL
|
|
275
|
+
bundleBaseUrl?: string; // Bundle service URL
|
|
276
|
+
webSocketUrl?: string; // WebSocket URL for monitoring
|
|
277
|
+
timeout?: number; // Request timeout (default: 30000ms)
|
|
278
|
+
debug?: boolean; // Enable debug logging
|
|
279
|
+
maxRetries?: number; // Retry attempts (default: 3)
|
|
280
|
+
retryDelay?: number; // Retry delay (default: 1000ms)
|
|
281
|
+
}
|
|
569
282
|
```
|
|
570
283
|
|
|
571
|
-
### Benefits of the New API
|
|
572
|
-
|
|
573
|
-
โ
**47% fewer methods** - Easier to learn and use
|
|
574
|
-
โ
**Consistent patterns** - All methods follow similar interfaces
|
|
575
|
-
โ
**Better TypeScript support** - Enhanced IntelliSense and autocomplete
|
|
576
|
-
โ
**Improved performance** - Client-side filtering reduces API calls
|
|
577
|
-
โ
**Unified error handling** - Consistent error patterns across all methods
|
|
578
|
-
โ
**Future-proof design** - Easier to extend with new functionality
|
|
579
|
-
|
|
580
284
|
## ๐งช Testing
|
|
581
285
|
|
|
582
286
|
```bash
|
|
583
|
-
# Run tests
|
|
287
|
+
# Run all tests
|
|
584
288
|
npm test
|
|
585
289
|
|
|
586
|
-
# Run tests
|
|
587
|
-
npm run test:
|
|
290
|
+
# Run integration tests (requires environment setup)
|
|
291
|
+
npm run test:integration
|
|
588
292
|
|
|
589
|
-
# Run
|
|
590
|
-
npm run
|
|
591
|
-
```
|
|
592
|
-
|
|
593
|
-
## ๐๏ธ Development
|
|
293
|
+
# Run type checking
|
|
294
|
+
npm run typecheck
|
|
594
295
|
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
296
|
+
# Run linting
|
|
297
|
+
npm run lint
|
|
298
|
+
```
|
|
598
299
|
|
|
599
|
-
|
|
600
|
-
npm run dev
|
|
300
|
+
## ๐ Documentation
|
|
601
301
|
|
|
602
|
-
|
|
603
|
-
|
|
302
|
+
- [SDK Method Reference](./SDK-METHOD-GRAPH.md) - Complete flat API reference
|
|
303
|
+
- [AI Agent Guide](./docs/AI_AGENT_GUIDE.md) - Integration with AI agents
|
|
304
|
+
- [API Documentation](../../API.md) - Detailed API documentation
|
|
305
|
+
- [Examples](./examples/) - Code examples and demos
|
|
604
306
|
|
|
605
|
-
|
|
606
|
-
npm run lint
|
|
307
|
+
## ๐ Environment URLs
|
|
607
308
|
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
```
|
|
309
|
+
- **Development**: `https://lpad-backend-dev1.defi.gala.com`
|
|
310
|
+
- **Production**: `https://lpad-backend-prod1.defi.gala.com`
|
|
611
311
|
|
|
612
312
|
## ๐ License
|
|
613
313
|
|
|
614
|
-
MIT
|
|
314
|
+
MIT License - see [LICENSE](../../LICENSE) file for details.
|
|
615
315
|
|
|
616
316
|
## ๐ค Contributing
|
|
617
317
|
|
|
618
|
-
|
|
318
|
+
Please read [CONTRIBUTING.md](../../CONTRIBUTING.md) for guidelines on contributing to this project.
|
|
619
319
|
|
|
620
320
|
## ๐ Support
|
|
621
321
|
|
|
622
|
-
-
|
|
623
|
-
-
|
|
624
|
-
-
|
|
322
|
+
- GitHub Issues: [Report bugs and request features](https://github.com/gala-chain/launchpad-sdk/issues)
|
|
323
|
+
- Documentation: [Full documentation and examples](./docs/)
|
|
324
|
+
- API Status: All 22/22 endpoints working โ
|
|
625
325
|
|
|
626
326
|
---
|
|
627
327
|
|
|
628
|
-
Built with โค๏ธ
|
|
328
|
+
**Built with โค๏ธ for the Gala ecosystem**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gala-chain/launchpad-sdk",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"description": "TypeScript SDK for Gala Launchpad Backend API - Production-ready DeFi token launchpad integration with wallet-based authentication, GalaChain trading, and comprehensive user operations. 100% tested (22/22 endpoints working).",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.esm.js",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"typecheck:examples": "tsc --project tsconfig.examples.json --noEmit",
|
|
52
52
|
"format": "prettier --write \"src/**/*.{ts,tsx,json,md}\"",
|
|
53
53
|
"format:check": "prettier --check \"src/**/*.{ts,tsx,json,md}\"",
|
|
54
|
-
"prepublishOnly": "npm run
|
|
54
|
+
"prepublishOnly": "npm run build",
|
|
55
55
|
"validate": "npm run lint:check && npm run typecheck && npm run test:ci",
|
|
56
56
|
"publish:beta": "npm run prepublishOnly && npm publish --tag beta",
|
|
57
57
|
"publish:stable": "npm run prepublishOnly && npm publish",
|