qvtx-developer-kit 1.1.0 → 1.2.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.
@@ -0,0 +1,300 @@
1
+ /**
2
+ * QVTX Direct Purchase Example
3
+ *
4
+ * This example demonstrates how to use the QVTXDirectPurchase SDK
5
+ * to buy QVTX tokens directly from the ecosystem.
6
+ *
7
+ * Features shown:
8
+ * - Getting pricing information
9
+ * - Calculating costs
10
+ * - Purchasing with native currency (ETH/BNB/MATIC)
11
+ * - Purchasing with stablecoins (USDT/USDC)
12
+ * - Using referral codes for discounts
13
+ * - Managing vested tokens
14
+ * - Generating referral links
15
+ */
16
+
17
+ const { createDirectPurchase, STABLECOINS } = require('qvtx-developer-kit/purchase');
18
+ require('dotenv').config();
19
+
20
+ // Configuration
21
+ const CONFIG = {
22
+ // Replace with actual deployed contract address
23
+ purchaseContract: process.env.QVTX_PURCHASE_CONTRACT || '0x...',
24
+
25
+ // BSC Mainnet RPC
26
+ rpcUrl: process.env.BSC_RPC || 'https://bsc-dataseed.binance.org/',
27
+
28
+ // Your private key (NEVER commit this!)
29
+ privateKey: process.env.PRIVATE_KEY,
30
+
31
+ // QVTX Token on BSC
32
+ qvtxToken: '0x5ad163056FC308C5ab88bf9295EAA2C16F3db400'
33
+ };
34
+
35
+ async function main() {
36
+ console.log('='.repeat(60));
37
+ console.log('QVTX Direct Purchase Example');
38
+ console.log('='.repeat(60));
39
+
40
+ // Initialize the SDK
41
+ const purchase = createDirectPurchase({
42
+ provider: CONFIG.rpcUrl,
43
+ contractAddress: CONFIG.purchaseContract,
44
+ privateKey: CONFIG.privateKey
45
+ });
46
+
47
+ // ============================================
48
+ // 1. GET SALE INFORMATION
49
+ // ============================================
50
+ console.log('\n--- Sale Information ---\n');
51
+
52
+ // Check if sale is active
53
+ const isPaused = await purchase.isPaused();
54
+ console.log(`Sale Status: ${isPaused ? 'PAUSED' : 'ACTIVE'}`);
55
+
56
+ // Get purchase limits
57
+ const limits = await purchase.getPurchaseLimits();
58
+ console.log(`Min Purchase: ${limits.minPurchase} QVTX`);
59
+ console.log(`Max Purchase: ${limits.maxPurchase} QVTX`);
60
+ console.log(`Max Per Wallet: ${limits.maxWalletPurchase} QVTX`);
61
+ console.log(`Total Sale Cap: ${limits.totalSaleCap} QVTX`);
62
+ console.log(`Already Sold: ${limits.totalSold} QVTX`);
63
+ console.log(`Remaining: ${limits.remainingSupply} QVTX`);
64
+
65
+ // Get current price
66
+ const priceInBNB = await purchase.getPriceInNative();
67
+ console.log(`\nPrice: ${priceInBNB} BNB per QVTX`);
68
+
69
+ // ============================================
70
+ // 2. CALCULATE PURCHASE COSTS
71
+ // ============================================
72
+ console.log('\n--- Calculate Costs ---\n');
73
+
74
+ const buyAmount = '10000'; // Buy 10,000 QVTX
75
+
76
+ // Calculate cost in native currency
77
+ const nativeCost = await purchase.calculateNativeCost(buyAmount);
78
+ console.log(`Cost for ${buyAmount} QVTX: ${nativeCost} BNB`);
79
+
80
+ // Calculate cost with referral discount
81
+ const referrer = '0x1234567890123456789012345678901234567890';
82
+ const discountedCost = await purchase.calculateNativeCost(buyAmount, referrer);
83
+ console.log(`Cost with referral: ${discountedCost} BNB`);
84
+ console.log(`Savings: ${(parseFloat(nativeCost) - parseFloat(discountedCost)).toFixed(6)} BNB`);
85
+
86
+ // Get QVTX amount for specific BNB amount
87
+ const bnbAmount = '1.0';
88
+ const qvtxForBNB = await purchase.getQVTXForNative(bnbAmount);
89
+ console.log(`\n${bnbAmount} BNB = ${qvtxForBNB} QVTX`);
90
+
91
+ // ============================================
92
+ // 3. CHECK IF PURCHASE IS VALID
93
+ // ============================================
94
+ console.log('\n--- Validate Purchase ---\n');
95
+
96
+ // Get connected wallet address
97
+ const walletAddress = CONFIG.privateKey
98
+ ? new (require('ethers').Wallet)(CONFIG.privateKey).address
99
+ : '0x0000000000000000000000000000000000000000';
100
+
101
+ const validation = await purchase.canPurchase(walletAddress, buyAmount);
102
+ console.log(`Can purchase ${buyAmount} QVTX: ${validation.valid}`);
103
+ if (!validation.valid) {
104
+ console.log(`Reason: ${validation.reason}`);
105
+ }
106
+
107
+ // ============================================
108
+ // 4. GET WALLET INFORMATION
109
+ // ============================================
110
+ console.log('\n--- Wallet Info ---\n');
111
+
112
+ const walletInfo = await purchase.getWalletInfo(walletAddress);
113
+ console.log(`Total Purchased: ${walletInfo.totalPurchased} QVTX`);
114
+ console.log(`Remaining Allocation: ${walletInfo.remainingAllocation} QVTX`);
115
+ console.log(`Purchase Count: ${walletInfo.purchaseCount}`);
116
+
117
+ if (walletInfo.purchases.length > 0) {
118
+ console.log('\nPurchase History:');
119
+ walletInfo.purchases.forEach((p, i) => {
120
+ console.log(` ${i + 1}. ${p.amount} QVTX on ${p.timestamp.toLocaleDateString()}`);
121
+ });
122
+ }
123
+
124
+ // ============================================
125
+ // 5. GET REFERRAL INFORMATION
126
+ // ============================================
127
+ console.log('\n--- Referral Info ---\n');
128
+
129
+ const referralInfo = await purchase.getReferralInfo(walletAddress);
130
+ console.log(`Referral Reward: ${referralInfo.rewardPercent}%`);
131
+ console.log(`Buyer Discount: ${referralInfo.discountPercent}%`);
132
+ console.log(`Your Referrals: ${referralInfo.referralCount}`);
133
+ console.log(`Total Earnings: ${referralInfo.totalEarnings} QVTX`);
134
+
135
+ // Generate your referral link
136
+ const referralLink = purchase.generateReferralLink(walletAddress);
137
+ console.log(`\nYour Referral Link: ${referralLink}`);
138
+
139
+ // ============================================
140
+ // 6. PURCHASE WITH NATIVE CURRENCY (BNB)
141
+ // ============================================
142
+ console.log('\n--- Purchase with BNB ---\n');
143
+
144
+ // IMPORTANT: Only run this if you want to make a real purchase!
145
+ const EXECUTE_PURCHASE = false;
146
+
147
+ if (EXECUTE_PURCHASE && CONFIG.privateKey) {
148
+ try {
149
+ // Get purchase summary before buying
150
+ const summary = await purchase.getPurchaseSummary(buyAmount, referrer);
151
+ console.log('Purchase Summary:');
152
+ console.log(` Amount: ${summary.qvtxAmount} QVTX`);
153
+ console.log(` Cost: ${summary.nativeCost} BNB`);
154
+ console.log(` Referrer: ${summary.referrer}`);
155
+ console.log(` Discount: ${summary.discount}`);
156
+
157
+ // Execute purchase
158
+ console.log('\nExecuting purchase...');
159
+ const tx = await purchase.purchaseWithNative(buyAmount, {
160
+ referrer: referrer
161
+ });
162
+
163
+ console.log(`Transaction Hash: ${tx.hash}`);
164
+ console.log('Waiting for confirmation...');
165
+
166
+ const receipt = await tx.wait();
167
+ console.log(`Confirmed in block: ${receipt.blockNumber}`);
168
+ console.log(`Gas Used: ${receipt.gasUsed.toString()}`);
169
+ } catch (error) {
170
+ console.error('Purchase failed:', error.message);
171
+ }
172
+ } else {
173
+ console.log('(Purchase execution disabled - set EXECUTE_PURCHASE = true to buy)');
174
+ }
175
+
176
+ // ============================================
177
+ // 7. PURCHASE WITH STABLECOIN (USDT)
178
+ // ============================================
179
+ console.log('\n--- Purchase with USDT ---\n');
180
+
181
+ const usdtAddress = STABLECOINS.bsc.USDT;
182
+ console.log(`USDT Address: ${usdtAddress}`);
183
+
184
+ // Check if USDT is supported
185
+ const supportedTokens = await purchase.getSupportedTokens();
186
+ const usdtSupported = supportedTokens.includes(usdtAddress);
187
+ console.log(`USDT Supported: ${usdtSupported}`);
188
+
189
+ if (usdtSupported) {
190
+ const usdtCost = await purchase.calculateTokenCost(usdtAddress, buyAmount);
191
+ console.log(`Cost for ${buyAmount} QVTX: ${usdtCost} USDT`);
192
+
193
+ // IMPORTANT: Only run this if you want to make a real purchase!
194
+ if (EXECUTE_PURCHASE && CONFIG.privateKey) {
195
+ try {
196
+ console.log('\nExecuting USDT purchase...');
197
+ const tx = await purchase.purchaseWithToken(usdtAddress, buyAmount, {
198
+ referrer: referrer,
199
+ approve: true // Auto-approve USDT spending
200
+ });
201
+
202
+ console.log(`Transaction Hash: ${tx.hash}`);
203
+ const receipt = await tx.wait();
204
+ console.log(`Confirmed in block: ${receipt.blockNumber}`);
205
+ } catch (error) {
206
+ console.error('USDT purchase failed:', error.message);
207
+ }
208
+ }
209
+ }
210
+
211
+ // ============================================
212
+ // 8. VESTING SCHEDULE MANAGEMENT
213
+ // ============================================
214
+ console.log('\n--- Vesting Schedules ---\n');
215
+
216
+ const vestingSchedules = await purchase.getVestingSchedules(walletAddress);
217
+
218
+ if (vestingSchedules.length === 0) {
219
+ console.log('No vesting schedules found.');
220
+ console.log('(Large purchases over threshold will have vesting)');
221
+ } else {
222
+ console.log(`Found ${vestingSchedules.length} vesting schedule(s):\n`);
223
+
224
+ for (const schedule of vestingSchedules) {
225
+ console.log(`Schedule #${schedule.index}:`);
226
+ console.log(` Total: ${schedule.totalAmount} QVTX`);
227
+ console.log(` Released: ${schedule.released} QVTX`);
228
+ console.log(` Remaining: ${schedule.remaining} QVTX`);
229
+ console.log(` Start: ${schedule.startTime.toLocaleDateString()}`);
230
+ console.log(` End: ${schedule.endTime.toLocaleDateString()}`);
231
+ console.log(` Duration: ${schedule.duration} days`);
232
+ console.log(` Progress: ${schedule.percentVested.toFixed(2)}%\n`);
233
+
234
+ // Release vested tokens
235
+ if (EXECUTE_PURCHASE && parseFloat(schedule.remaining) > 0) {
236
+ try {
237
+ console.log(' Releasing vested tokens...');
238
+ const tx = await purchase.releaseVested(schedule.index);
239
+ await tx.wait();
240
+ console.log(' Released successfully!');
241
+ } catch (error) {
242
+ console.error(` Release failed: ${error.message}`);
243
+ }
244
+ }
245
+ }
246
+ }
247
+
248
+ // ============================================
249
+ // 9. WHITELIST CHECK (FOR PRIVATE SALES)
250
+ // ============================================
251
+ console.log('\n--- Whitelist Status ---\n');
252
+
253
+ const whitelistEnabled = await purchase.isWhitelistEnabled();
254
+ console.log(`Whitelist Mode: ${whitelistEnabled ? 'ENABLED (Private Sale)' : 'DISABLED (Public Sale)'}`);
255
+
256
+ if (whitelistEnabled) {
257
+ const isWhitelisted = await purchase.isWhitelisted(walletAddress);
258
+ console.log(`Your Status: ${isWhitelisted ? 'WHITELISTED' : 'NOT WHITELISTED'}`);
259
+ }
260
+
261
+ // ============================================
262
+ // DONE
263
+ // ============================================
264
+ console.log('\n' + '='.repeat(60));
265
+ console.log('Example complete!');
266
+ console.log('='.repeat(60));
267
+ }
268
+
269
+ // Run the example
270
+ main().catch(console.error);
271
+
272
+ /**
273
+ * Quick Purchase Function
274
+ * Use this for simple purchases in your own code
275
+ */
276
+ async function quickPurchase(amount, options = {}) {
277
+ const purchase = createDirectPurchase({
278
+ provider: options.rpcUrl || CONFIG.rpcUrl,
279
+ contractAddress: options.contractAddress || CONFIG.purchaseContract,
280
+ privateKey: options.privateKey || CONFIG.privateKey
281
+ });
282
+
283
+ // Validate first
284
+ const wallet = new (require('ethers').Wallet)(options.privateKey || CONFIG.privateKey);
285
+ const { valid, reason } = await purchase.canPurchase(wallet.address, amount);
286
+
287
+ if (!valid) {
288
+ throw new Error(`Cannot purchase: ${reason}`);
289
+ }
290
+
291
+ // Execute purchase
292
+ const tx = await purchase.purchaseWithNative(amount, {
293
+ referrer: options.referrer
294
+ });
295
+
296
+ return tx;
297
+ }
298
+
299
+ // Export for use in other files
300
+ module.exports = { quickPurchase };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qvtx-developer-kit",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "Complete QuantVestrix QVTX Developer Package - Build infinite throughput blockchain applications with cross-chain rewards and neural storage",
5
5
  "main": "index.js",
6
6
  "types": "types/index.d.ts",
@@ -16,6 +16,7 @@
16
16
  "./storage": "./storage/index.js",
17
17
  "./config": "./config/index.js",
18
18
  "./test": "./test/index.js",
19
+ "./purchase": "./purchase/index.js",
19
20
  "./solana": "./languages/solana_sdk.js",
20
21
  "./blockchain-ai": "./languages/blockchain_ai_sdk.js",
21
22
  "./node-sdk": "./languages/node_sdk.js"
@@ -30,6 +31,7 @@
30
31
  "smart-contracts/",
31
32
  "rewards/",
32
33
  "storage/",
34
+ "purchase/",
33
35
  "bin/",
34
36
  "abis/",
35
37
  "types/",