Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

solana #159

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions crates/cmds-solana/src/mpl_create_nft.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
host = "0.0.0.0"
port = 8080
local_storage = "_data/guest_local_storage"
cors_origins = ["*"]

[supabase]
anon_key = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Imh5amJvYmxramVldmt6YXFzeXhlIiwicm9sZSI6ImFub24iLCJpYXQiOjE3Mjc4ODc1MjgsImV4cCI6MjA0MzQ2MzUyOH0.J4tyAfa2_j1irMW3sZUi7ykTrubGdoqXWo9cPXqZ9iw"
endpoint = "https://hyjboblkjeevkzaqsyxe.supabase.co"

[db]
upstream_url = "https://dev-api.spaceoperator.com"
api_keys = ["b3-EGITlELGk29ZKg42LxFFIn80BpCWcFlM-C15kE0owOA"]


use mpl_hybrid::instructions::create_nft_instruction;
use solana_client::rpc_client::RpcClient;
use solana_sdk::pubkey::Pubkey;

// Function that will call the `create_nft_instruction` to create an NFT on the blockchain.
pub fn mpl_create_nft(user_address: &str, nft_metadata: Metadata) -> Result<(), SomeErrorType> {
// Step 1: Establish a connection to Solana's blockchain.
let rpc_url = "https://api.devnet.solana.com"; // You can use mainnet or testnet here.
let connection = RpcClient::new(rpc_url);

// Step 2: Convert the user’s address into a Pubkey (Solana's key format)
let user_pubkey = Pubkey::from_str(user_address)?;

// Step 3: Call the `create_nft_instruction` and pass the necessary data.
let instruction = create_nft_instruction(&connection, user_pubkey, nft_metadata)?;

// Step 4: Send the transaction to the blockchain to actually create the NFT.
send_transaction(&connection, &instruction)?;

Ok(())
}
34 changes: 34 additions & 0 deletions crates/cmds-solana/src/mpl_nft_to_token_swap.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
host = "0.0.0.0"
port = 8080
local_storage = "_data/guest_local_storage"
cors_origins = ["*"]

[supabase]
anon_key = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Imh5amJvYmxramVldmt6YXFzeXhlIiwicm9sZSI6ImFub24iLCJpYXQiOjE3Mjc4ODc1MjgsImV4cCI6MjA0MzQ2MzUyOH0.J4tyAfa2_j1irMW3sZUi7ykTrubGdoqXWo9cPXqZ9iw"
endpoint = "https://hyjboblkjeevkzaqsyxe.supabase.co"

[db]
upstream_url = "https://dev-api.spaceoperator.com"
api_keys = ["b3-EGITlELGk29ZKg42LxFFIn80BpCWcFlM-C15kE0owOA"]
use mpl_hybrid::instructions::{swap_nft_for_token_instruction};
use solana_client::rpc_client::RpcClient;
use solana_sdk::{pubkey::Pubkey, signer::Signer};

pub fn mpl_nft_to_token_swap(user_address: &str, nft_address: &str, token_amount: u64) -> Result<(), Box<dyn std::error::Error>> {
// Step 1: Establish a connection to Solana blockchain (devnet or mainnet)
let rpc_url = "https://api.devnet.solana.com"; // Update to mainnet if needed
let connection = RpcClient::new(rpc_url);

// Step 2: Convert the user address and NFT address to Solana Pubkeys
let user_pubkey = Pubkey::from_str(user_address)?;
let nft_pubkey = Pubkey::from_str(nft_address)?;

// Step 3: Define the token swap logic (this could be based on your specific token or exchange mechanism)
// Here we assume you have a function `swap_nft_for_token_instruction` that handles the swap logic
let instruction = swap_nft_for_token_instruction(&connection, user_pubkey, nft_pubkey, token_amount)?;

// Step 4: Send the transaction to the blockchain
send_transaction(&connection, &instruction)?;

Ok(())
}
34 changes: 34 additions & 0 deletions crates/cmds-solana/src/mpl_swap_to_token.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
host = "0.0.0.0"
port = 8080
local_storage = "_data/guest_local_storage"
cors_origins = ["*"]

[supabase]
anon_key = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Imh5amJvYmxramVldmt6YXFzeXhlIiwicm9sZSI6ImFub24iLCJpYXQiOjE3Mjc4ODc1MjgsImV4cCI6MjA0MzQ2MzUyOH0.J4tyAfa2_j1irMW3sZUi7ykTrubGdoqXWo9cPXqZ9iw"
endpoint = "https://hyjboblkjeevkzaqsyxe.supabase.co"

[db]
upstream_url = "https://dev-api.spaceoperator.com"
api_keys = ["b3-EGITlELGk29ZKg42LxFFIn80BpCWcFlM-C15kE0owOA"]

use mpl_hybrid::instructions::swap_to_token_instruction;
use solana_client::rpc_client::RpcClient;
use solana_sdk::pubkey::Pubkey;

// Function that calls the `swap_to_token_instruction` to swap an NFT for a token
pub fn mpl_swap_to_token(user_address: &str, token_data: TokenData) -> Result<(), SomeErrorType> {
// Step 1: Establish a connection to the Solana blockchain.
let rpc_url = "https://api.devnet.solana.com"; // You can use mainnet or testnet here.
let connection = RpcClient::new(rpc_url);

// Step 2: Convert user address into a Solana Pubkey.
let user_pubkey = Pubkey::from_str(user_address)?;

// Step 3: Call the `swap_to_token_instruction` and pass necessary data.
let instruction = swap_to_token_instruction(&connection, user_pubkey, token_data)?;

// Step 4: Send the transaction to the blockchain to complete the swap.
send_transaction(&connection, &instruction)?;

Ok(())
}
34 changes: 34 additions & 0 deletions crates/cmds-solana/src/mpl_token_to_nft_swap.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
host = "0.0.0.0"
port = 8080
local_storage = "_data/guest_local_storage"
cors_origins = ["*"]

[supabase]
anon_key = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Imh5amJvYmxramVldmt6YXFzeXhlIiwicm9sZSI6ImFub24iLCJpYXQiOjE3Mjc4ODc1MjgsImV4cCI6MjA0MzQ2MzUyOH0.J4tyAfa2_j1irMW3sZUi7ykTrubGdoqXWo9cPXqZ9iw"
endpoint = "https://hyjboblkjeevkzaqsyxe.supabase.co"

[db]
upstream_url = "https://dev-api.spaceoperator.com"
api_keys = ["b3-EGITlELGk29ZKg42LxFFIn80BpCWcFlM-C15kE0owOA"]

use mpl_hybrid::instructions::{swap_token_for_nft_instruction};
use solana_client::rpc_client::RpcClient;
use solana_sdk::{pubkey::Pubkey, signer::Signer};

pub fn mpl_token_to_nft_swap(user_address: &str, token_address: &str, nft_metadata: Metadata) -> Result<(), Box<dyn std::error::Error>> {
// Step 1: Establish a connection to Solana blockchain (devnet or mainnet)
let rpc_url = "https://api.devnet.solana.com"; // Update to mainnet if needed
let connection = RpcClient::new(rpc_url);

// Step 2: Convert the user address and token address to Solana Pubkeys
let user_pubkey = Pubkey::from_str(user_address)?;
let token_pubkey = Pubkey::from_str(token_address)?;

// Step 3: Define the logic for swapping token to NFT (specific token logic)
let instruction = swap_token_for_nft_instruction(&connection, user_pubkey, token_pubkey, nft_metadata)?;

// Step 4: Send the transaction to the blockchain
send_transaction(&connection, &instruction)?;

Ok(())
}