@nosana/kit 1.0.7 → 1.0.9

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.
@@ -1,160 +0,0 @@
1
- import { NosanaClient, NosanaNetwork } from '@nosana/kit';
2
- import path from 'path';
3
-
4
- async function main() {
5
- console.log('šŸš€ Nosana Job Posting Example');
6
- console.log('===============================\n');
7
-
8
- try {
9
- // Initialize the client
10
- console.log('šŸ“” Initializing Nosana client...');
11
- const client = new NosanaClient(NosanaNetwork.DEVNET);
12
-
13
- // Set up the wallet using the example keypair
14
- const keypairPath = path.join(__dirname, 'example-keypair.json');
15
- console.log('šŸ”‘ Setting up wallet from:', keypairPath);
16
-
17
- const wallet = await client.setWallet(keypairPath);
18
- console.log('āœ… Wallet address:', wallet?.address);
19
-
20
- // Get available markets
21
- console.log('\nšŸ“Š Fetching available markets...');
22
- const markets = await client.jobs.markets();
23
-
24
- if (markets.length === 0) {
25
- throw new Error('No markets available. Please check your network connection and try again.');
26
- }
27
-
28
- console.log(`āœ… Found ${markets.length} market(s)`);
29
- const market = markets[0]; // Use the first available market
30
- console.log(`šŸ“ˆ Using market: ${market.address}`);
31
-
32
- // Example job configuration
33
- const jobConfig = {
34
- // Market to post the job to
35
- market: market.address,
36
-
37
- // Job timeout in seconds (1 hour)
38
- timeout: 3600,
39
-
40
- // IPFS hash of the job specification
41
- // In a real scenario, you would upload your job specification to IPFS first
42
- ipfsHash: 'QmYyQSo1c1Ym7orWxLYvCrM2EmxFTANf8wXmmE7DWjhx5N', // Example IPFS hash
43
-
44
- // Optional: specify a particular node (leave undefined for open market)
45
- // node: 'NodeAddressHere'
46
- };
47
-
48
- console.log('\nšŸ“ Job Configuration:');
49
- console.log(' Market:', jobConfig.market.toString());
50
- console.log(' Timeout:', jobConfig.timeout, 'seconds');
51
- console.log(' IPFS Hash:', jobConfig.ipfsHash);
52
-
53
- // Step 1: Create the job listing instruction
54
- console.log('\nšŸ”§ Creating job listing instruction...');
55
- const instruction = await client.jobs.post(jobConfig);
56
- console.log('āœ… Instruction created successfully');
57
- console.log(' Program Address:', instruction.programAddress);
58
- console.log(' Accounts:', instruction.accounts.length);
59
-
60
- // Step 2: Send the instruction using the send utility
61
- console.log('\nšŸ“¤ Sending job listing transaction...');
62
- const signature = await client.solana.send(instruction);
63
- console.log('āœ… Transaction sent successfully!');
64
- console.log(' Transaction Signature:', signature);
65
-
66
- // You can view the transaction on Solana Explorer
67
- const explorerUrl = `https://explorer.solana.com/tx/${signature}?cluster=${client.config.solana.cluster}`;
68
- console.log(' View on Explorer:', explorerUrl);
69
-
70
- console.log('\nšŸŽ‰ Job posted successfully!');
71
- console.log('šŸ’” Your job is now listed on the Nosana network and waiting for nodes to pick it up.');
72
-
73
- } catch (error) {
74
- console.error('\nāŒ Error posting job:', error);
75
- process.exit(1);
76
- }
77
- }
78
-
79
- // Advanced example showing multiple instructions in one transaction
80
- async function advancedExample() {
81
- console.log('\n\nšŸ”¬ Advanced Example: Multiple Instructions');
82
- console.log('==========================================\n');
83
-
84
- try {
85
- const client = new NosanaClient(NosanaNetwork.DEVNET);
86
- const keypairPath = path.join(__dirname, 'example-keypair.json');
87
- await client.setWallet(keypairPath);
88
-
89
- const markets = await client.jobs.markets();
90
- if (markets.length === 0) {
91
- throw new Error('No markets available');
92
- }
93
-
94
- // Create multiple job instructions
95
- const instructions = [];
96
-
97
- for (let i = 0; i < 2; i++) {
98
- const jobConfig = {
99
- market: markets[0].address,
100
- timeout: 3600,
101
- ipfsHash: `QmYyQSo1c1Ym7orWxLYvCrM2EmxFTANf8wXmmE7DWjhx${i}N`, // Different IPFS hashes
102
- };
103
-
104
- console.log(`šŸ”§ Creating job ${i + 1} instruction...`);
105
- const instruction = await client.jobs.post(jobConfig);
106
- instructions.push(instruction);
107
- }
108
-
109
- // Send all instructions in a single transaction
110
- console.log('\nšŸ“¤ Sending batch transaction with multiple jobs...');
111
- const signature = await client.solana.send(instructions);
112
- console.log('āœ… Batch transaction sent successfully!');
113
- console.log(' Transaction Signature:', signature);
114
-
115
- console.log('\nšŸŽ‰ Multiple jobs posted in a single transaction!');
116
-
117
- } catch (error) {
118
- console.error('\nāŒ Error in advanced example:', error);
119
- }
120
- }
121
-
122
- // Example of error handling
123
- async function errorHandlingExample() {
124
- console.log('\n\nāš ļø Error Handling Example');
125
- console.log('==========================\n');
126
-
127
- try {
128
- const client = new NosanaClient(NosanaNetwork.DEVNET);
129
-
130
- // Try to post without setting a wallet (this will fail)
131
- console.log('šŸ”§ Attempting to post job without wallet...');
132
-
133
- const jobConfig = {
134
- market: 'InvalidMarketAddress' as any,
135
- timeout: 3600,
136
- ipfsHash: 'QmYyQSo1c1Ym7orWxLYvCrM2EmxFTANf8wXmmE7DWjhx5N',
137
- };
138
-
139
- await client.jobs.post(jobConfig);
140
-
141
- } catch (error) {
142
- console.log('āœ… Caught expected error:', error.message);
143
- console.log('šŸ’” Always ensure your wallet is set before posting jobs!');
144
- }
145
- }
146
-
147
- // Run all examples
148
- if (require.main === module) {
149
- main()
150
- .then(() => advancedExample())
151
- .then(() => errorHandlingExample())
152
- .then(() => {
153
- console.log('\n✨ All examples completed!');
154
- process.exit(0);
155
- })
156
- .catch((error) => {
157
- console.error('Fatal error:', error);
158
- process.exit(1);
159
- });
160
- }
@@ -1,18 +0,0 @@
1
- import { address, NosanaClient, NosanaNetwork } from '@nosana/kit';
2
-
3
- async function main() {
4
- // Initialize the client with devnet for testing
5
- const client = new NosanaClient(NosanaNetwork.DEVNET);
6
-
7
- try {
8
- // Example: Get job details
9
- const jobAddress = 'FMbwxyhhAwXzixRqoSFhYzbx6RAQE4kgoTCdHXkNQ6AR'; // Replace with actual job address
10
- const jobDetails = await client.jobs.get(address(jobAddress));
11
- console.log('Job details:', jobDetails);
12
-
13
- } catch (error) {
14
- console.error('Error:', error);
15
- }
16
- }
17
-
18
- main();
@@ -1,87 +0,0 @@
1
- import { NosanaClient, NosanaNetwork } from '@nosana/kit';
2
- import * as path from 'path';
3
- import { fileURLToPath } from 'url';
4
-
5
- const __filename = fileURLToPath(import.meta.url);
6
- const __dirname = path.dirname(__filename);
7
-
8
- async function main() {
9
- console.log('šŸš€ Nosana Client setWallet Examples\n');
10
-
11
- // Initialize the client
12
- const client = new NosanaClient(NosanaNetwork.DEVNET);
13
-
14
- // Example 1: Set wallet from file path
15
- console.log('1. Setting wallet from file path...');
16
- try {
17
- const keypairPath = path.join(__dirname, 'example-keypair.json');
18
-
19
- const wallet1 = await client.setWallet(keypairPath);
20
- console.log('āœ… Wallet set from file path successfully');
21
- console.log(' Address:', wallet1?.address);
22
- } catch (error) {
23
- console.error('āŒ Error setting wallet from file:', error);
24
- }
25
-
26
- // Example 2: Set wallet from JSON array string
27
- console.log('\n2. Setting wallet from JSON array string...');
28
- try {
29
- const jsonArrayString = '[66,240,117,68,169,30,179,62,57,123,28,249,122,218,186,173,196,222,208,58,126,168,32,91,126,64,102,33,220,51,49,97,6,197,228,206,210,117,23,184,89,48,217,110,194,137,242,129,112,23,140,120,148,249,210,18,105,192,40,197,250,132,40,149]';
30
- const wallet2 = await client.setWallet(jsonArrayString);
31
- console.log('āœ… Wallet set from JSON array string successfully');
32
- console.log(' Address:', wallet2?.address);
33
- } catch (error) {
34
- console.error('āŒ Error setting wallet from JSON array string:', error);
35
- }
36
-
37
- // Example 3: Set wallet from number array
38
- console.log('\n3. Setting wallet from number array...');
39
- try {
40
- const numberArray = [66, 240, 117, 68, 169, 30, 179, 62, 57, 123, 28, 249, 122, 218, 186, 173, 196, 222, 208, 58, 126, 168, 32, 91, 126, 64, 102, 33, 220, 51, 49, 97, 6, 197, 228, 206, 210, 117, 23, 184, 89, 48, 217, 110, 194, 137, 242, 129, 112, 23, 140, 120, 148, 249, 210, 18, 105, 192, 40, 197, 250, 132, 40, 149];
41
- const wallet3 = await client.setWallet(numberArray);
42
- console.log('āœ… Wallet set from number array successfully');
43
- console.log(' Address:', wallet3?.address);
44
- } catch (error) {
45
- console.error('āŒ Error setting wallet from number array:', error);
46
- }
47
-
48
- // Example 4: Set wallet from base58 string
49
- console.log('\n4. Setting wallet from base58 string...');
50
- try {
51
- // This is the base58 encoded version of the same keypair
52
- const base58String = '2Ld9Q8E9TxsSPf9Zkxn55u2EuuXBZUiV3XJf1duTnKmH1GgEfhW4tYoTRh5GKMWSd8j853YrtJMN74hixjLsnkRJ';
53
- const wallet4 = await client.setWallet(base58String);
54
- console.log('āœ… Wallet set from base58 string successfully');
55
- console.log(' Address:', wallet4?.address);
56
- } catch (error) {
57
- console.error('āŒ Error setting wallet from base58 string:', error);
58
- }
59
-
60
- // Example 5: Set wallet from environment variable
61
- console.log('\n5. Setting wallet from environment variable...');
62
- try {
63
- // Set an environment variable with the keypair
64
- process.env.EXAMPLE_WALLET_KEY = '[66,240,117,68,169,30,179,62,57,123,28,249,122,218,186,173,196,222,208,58,126,168,32,91,126,64,102,33,220,51,49,97,6,197,228,206,210,117,23,184,89,48,217,110,194,137,242,129,112,23,140,120,148,249,210,18,105,192,40,197,250,132,40,149]';
65
-
66
- const wallet5 = await client.setWallet('EXAMPLE_WALLET_KEY');
67
- console.log('āœ… Wallet set from environment variable successfully');
68
- console.log(' Address:', wallet5?.address);
69
-
70
- // Clean up
71
- delete process.env.EXAMPLE_WALLET_KEY;
72
- } catch (error) {
73
- console.error('āŒ Error setting wallet from environment variable:', error);
74
- }
75
-
76
- // Example 6: Demonstrate error handling
77
- console.log('\n6. Demonstrating error handling...');
78
- try {
79
- await client.setWallet('invalid-wallet-data');
80
- } catch (error) {
81
- console.log('āœ… Error handling works correctly:', error instanceof Error ? error.message : error);
82
- }
83
-
84
- console.log('\nšŸŽ‰ All setWallet examples completed!');
85
- }
86
-
87
- main().catch(console.error);
@@ -1,84 +0,0 @@
1
- /**
2
- * Example: Using the StakeProgram to interact with staking accounts
3
- *
4
- * This example demonstrates how to use the StakeProgram to:
5
- * 1. Get all stake accounts
6
- * 2. Get stake accounts for a specific authority
7
- * 3. Get a single stake account by address
8
- */
9
-
10
- import { NosanaClient, NosanaNetwork } from '@nosana/kit';
11
-
12
- async function main() {
13
- // Initialize the client
14
- const client = new NosanaClient(NosanaNetwork.MAINNET);
15
-
16
- console.log('=== Stake Program Example ===\n');
17
-
18
- try {
19
- // Example 1: Get all stake accounts
20
- console.log('1. Fetching all stake accounts...');
21
- const allStakes = await client.stake.all();
22
- console.log(` Found ${allStakes.length} stake accounts`);
23
-
24
- if (allStakes.length > 0) {
25
- const firstStake = allStakes[0];
26
- console.log(' First stake account:');
27
- console.log(` - Address: ${firstStake.address}`);
28
- console.log(` - Authority: ${firstStake.authority}`);
29
- console.log(` - Amount: ${firstStake.amount}`);
30
- console.log(` - xNOS: ${firstStake.xnos}`);
31
- console.log(` - Duration: ${firstStake.duration}`);
32
- console.log(` - Time Unstake: ${firstStake.timeUnstake}`);
33
- console.log(` - Vault: ${firstStake.vault}`);
34
- console.log(` - Vault Bump: ${firstStake.vaultBump}`);
35
- }
36
- console.log();
37
-
38
- // Example 2: Get a single stake account (if you know a stake account address)
39
- if (allStakes.length > 0) {
40
- console.log('2. Fetching single stake account...');
41
- const stakeAddress = allStakes[0].address;
42
- const stake = await client.stake.get(stakeAddress);
43
- console.log(` Retrieved stake account: ${stake.address}`);
44
- console.log(` - Authority: ${stake.authority}`);
45
- console.log(` - Staked Amount: ${stake.amount}`);
46
- console.log(` - xNOS Tokens: ${stake.xnos}`);
47
- console.log();
48
- }
49
-
50
- // Example 3: Get multiple stake accounts by address
51
- if (allStakes.length >= 2) {
52
- console.log('3. Fetching multiple stake accounts...');
53
- const addresses = allStakes.slice(0, 2).map(s => s.address);
54
- const stakes = await client.stake.multiple(addresses);
55
- console.log(` Retrieved ${stakes.length} stake accounts`);
56
- stakes.forEach((stake, i) => {
57
- console.log(` Stake ${i + 1}:`);
58
- console.log(` - Address: ${stake.address}`);
59
- console.log(` - Authority: ${stake.authority}`);
60
- console.log(` - Amount: ${stake.amount}`);
61
- });
62
- console.log();
63
- }
64
-
65
- // Example 4: Analyze staking distribution
66
- console.log('4. Analyzing staking distribution...');
67
- const totalStaked = allStakes.reduce((sum, stake) => sum + stake.amount, 0);
68
- const averageStake = allStakes.length > 0 ? totalStaked / allStakes.length : 0;
69
- const largestStake = allStakes.reduce((max, stake) =>
70
- stake.amount > max ? stake.amount : max, 0
71
- );
72
-
73
- console.log(` Total staked: ${totalStaked}`);
74
- console.log(` Average stake: ${averageStake.toFixed(2)}`);
75
- console.log(` Largest stake: ${largestStake}`);
76
- console.log(` Number of stakers: ${allStakes.length}`);
77
-
78
- } catch (error) {
79
- console.error('Error:', error);
80
- }
81
- }
82
-
83
- main();
84
-
@@ -1,33 +0,0 @@
1
- import { createFromRoot } from 'codama';
2
- import { rootNodeFromAnchor, AnchorIdl } from '@codama/nodes-from-anchor';
3
- import { renderVisitor as renderJavaScriptVisitor } from '@codama/renderers-js';
4
- import anchorJobsIdl from '../../spl/target/idl/nosana_jobs.json';
5
- import anchorStakingIdl from '../../spl/target/idl/nosana_staking.json';
6
- import merkleDistributorIdl from '../src/idl/merkle_distributor.json';
7
- import path from 'path';
8
- import { fileURLToPath } from 'url';
9
-
10
- // Get __dirname equivalent in ES modules
11
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
12
-
13
- const codamaJobs = createFromRoot(rootNodeFromAnchor(anchorJobsIdl as AnchorIdl));
14
-
15
- codamaJobs.accept(
16
- renderJavaScriptVisitor(path.join(__dirname, '..', 'src', 'generated_clients', 'jobs'))
17
- );
18
-
19
- const codamaStaking = createFromRoot(rootNodeFromAnchor(anchorStakingIdl as AnchorIdl));
20
-
21
- codamaStaking.accept(
22
- renderJavaScriptVisitor(path.join(__dirname, '..', 'src', 'generated_clients', 'staking'))
23
- );
24
-
25
- const codamaMerkleDistributor = createFromRoot(
26
- rootNodeFromAnchor(merkleDistributorIdl as AnchorIdl)
27
- );
28
-
29
- codamaMerkleDistributor.accept(
30
- renderJavaScriptVisitor(
31
- path.join(__dirname, '..', 'src', 'generated_clients', 'merkle_distributor')
32
- )
33
- );
package/vitest.config.ts DELETED
@@ -1,31 +0,0 @@
1
- import { defineConfig } from 'vitest/config';
2
-
3
- export default defineConfig({
4
- test: {
5
- environment: 'node',
6
- globals: true,
7
- include: ['tests/**/*.test.ts'],
8
- coverage: {
9
- provider: 'v8',
10
- reporter: ['text', 'json', 'html'],
11
- include: ['src/**/*.ts'],
12
- exclude: [
13
- 'node_modules/',
14
- 'dist/',
15
- 'tests/',
16
- 'scripts/',
17
- 'examples/',
18
- '**/*.d.ts',
19
- '**/*.config.*',
20
- '**/generated_clients/**',
21
- '**/.nuxt/**',
22
- ],
23
- thresholds: {
24
- lines: 70,
25
- functions: 70,
26
- branches: 60,
27
- statements: 70,
28
- },
29
- },
30
- },
31
- });