Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
c169e7a
Added SPL Support temporarily
calc1f4r Nov 17, 2024
31d5065
Fixed payment in spl tokens
calc1f4r Nov 17, 2024
8c5ca77
Added two separate functions for spl payment
calc1f4r Nov 17, 2024
aed3c3d
Fixed linting
calc1f4r Nov 17, 2024
a5b71cb
Fixed linting🚀
calc1f4r Nov 17, 2024
b553d73
rebuild program
csmarc Nov 17, 2024
b1c9247
commit left out files
csmarc Nov 17, 2024
b6f8e89
linting and fix typos
csmarc Nov 17, 2024
7dbcf8e
fix test bug with code docs
csmarc Nov 17, 2024
6958c5b
fix typos
csmarc Nov 17, 2024
d480638
Added SPL Support temporarily
calc1f4r Nov 17, 2024
776f242
Fixed payment in spl tokens
calc1f4r Nov 17, 2024
53905cd
Added two separate functions for spl payment
calc1f4r Nov 17, 2024
cae11b9
Fixed linting
calc1f4r Nov 17, 2024
a445dde
Fixed linting🚀
calc1f4r Nov 17, 2024
f89a96f
commit left out files
csmarc Nov 17, 2024
a8af829
fix test bug with code docs
csmarc Nov 17, 2024
3444533
fix typos
csmarc Nov 17, 2024
a45249c
Merge remote-tracking branch 'origin/SolSupport-mtest' into SolSuppor…
csmarc Nov 22, 2024
6ae223c
fix refactoring
csmarc Nov 22, 2024
0f26ecb
fix more refactoring and comment out spl code
csmarc Nov 22, 2024
6bf0860
test with SOL payment works
csmarc Nov 22, 2024
0494c7e
fix refactor bugs and now builds and SOL tests work
csmarc Nov 22, 2024
001a33e
lint IDL
csmarc Nov 22, 2024
ef72fdf
Refacting Done
calc1f4r Nov 22, 2024
62adf39
Fixed linting for review
calc1f4r Nov 22, 2024
f9e009b
Merge pull request #42 from Gigentic/solsupport-ytest
csmarc Nov 22, 2024
0fe3c7d
add spl diagram
csmarc Nov 22, 2024
862929b
Merge branch 'main' into SolSupport-mtest
csmarc Nov 22, 2024
f949e63
fix add service
csmarc Nov 22, 2024
778479b
fixed admin scripts
calc1f4r Nov 23, 2024
ede6f85
clean up changes
csmarc Nov 25, 2024
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,4 @@ fileScript-add.js
log*.md
accounts.csv
/keys
Token.json
2 changes: 2 additions & 0 deletions anchor/admin/createService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export async function createService(
price: number,
serviceDescription: string,
uniqueId: string,
serviceProviderTokenAccount: PublicKey,
) {
await program.methods
.initializeService(
Expand All @@ -35,6 +36,7 @@ export async function createService(
provider: serviceDeployer.publicKey,
serviceRegistry: serviceRegistryPubkey,
mint: _mint,
serviceProviderTokenAccount,
tokenProgram: TOKEN_PROGRAM_ID,
})
.signers([serviceDeployer]) // Include both deployer and the new service keypair as signers
Expand Down
56 changes: 34 additions & 22 deletions anchor/admin/deploy-registry.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import * as dotenv from 'dotenv';
import * as fs from 'fs'; // Import the fs module

import { Program, workspace, setProvider } from '@coral-xyz/anchor';

import {
Connection,
SystemProgram,
Transaction,
sendAndConfirmTransaction,
PublicKey,
} from '@solana/web3.js';

import { Gigentic } from '../target/types/gigentic';
import { PROVIDER } from '../tests/constants';
import { loadKeypairBs58FromEnv } from '../tests/utils';
import { airdrop, loadKeypairBs58FromEnv } from '../tests/utils';
import { createMintToken, createTokenAccount } from './init';

dotenv.config();

Expand Down Expand Up @@ -39,20 +41,45 @@ console.log('serviceRegistry', serviceRegistryKeypair.publicKey.toString());

async function initServiceRegistry() {
try {
const mint: PublicKey =
(await createMintToken(connection, serviceRegistryDeployer)) ||
new PublicKey(0); // Provide a default value or handle the error appropriately
console.log('Mint Public Key:', mint.toString());

const feeTokenAccount: PublicKey = await createTokenAccount(
connection,
serviceRegistryDeployer,
mint,
);

// Create a JSON object to write to a file
const output = {
mintPublicKey: mint,
feeTokenAccountPublicKey: feeTokenAccount,
};
fs.writeFileSync('Token.json', JSON.stringify(output, null, 2)); // Write to Token.json

// Add the fee token account to the output
output.feeTokenAccountPublicKey = feeTokenAccount; // Ensure this is included
fs.writeFileSync('Token.json', JSON.stringify(output, null, 2)); // Write to Token.json again
console.log('Fee Token Account Public Key:', feeTokenAccount.toString());

const feeAccount = serviceRegistryDeployer.publicKey;
console.log('Fee Account Public Key:', feeAccount.toString());

const feePercentage = 1;
console.log('Fee Percentage:', feePercentage);

// Create the service registry account
const serviceRegistryAccountSize = 20000; // Adjust the size based on the ServiceRegistry struct
const serviceRegistryAccountSize = 2000; // Adjust the size based on the ServiceRegistry struct
console.log('Service Registry Account Size: ', serviceRegistryAccountSize);

const rentExemptionAmount =
await connection.getMinimumBalanceForRentExemption(
serviceRegistryAccountSize,
);
console.log('Rent Exemption Amount: ', rentExemptionAmount);

const createAccountParams = {
fromPubkey: serviceRegistryDeployer.publicKey, // Account paying for the creation of the new account
newAccountPubkey: serviceRegistryKeypair.publicKey, // Public key of the new account to be created
Expand All @@ -69,7 +96,7 @@ async function initServiceRegistry() {
]);

const transactionSignature = await program.methods
.initializeServiceRegistry(feeAccount, feePercentage)
.initializeServiceRegistry(feeAccount, feeTokenAccount, feePercentage)
.accounts({
initializer: serviceRegistryDeployer.publicKey,
serviceRegistry: serviceRegistryKeypair.publicKey,
Expand All @@ -90,29 +117,14 @@ async function initServiceRegistry() {

async function main() {
try {
console.log('========== Airdrop serviceRegistry deployer');
// console.log('========== Airdrop serviceRegistry deployer');
// await airdrop(connection, serviceRegistryDeployer.publicKey);
console.log('skip airdrop serviceRegistryDeployer');
console.log('\n');
// console.log('skip airdrop serviceRegistryDeployer');
// console.log('\n');

console.log('========== Initialize service registry');
await initServiceRegistry();
console.log('\n');

console.log('========== Read service registry');
const serviceRegistry = await program.account.serviceRegistry.fetch(
serviceRegistryKeypair.publicKey,
);

for (const serviceAddress of serviceRegistry.serviceAccountAddresses) {
console.log('Service Account Address:', serviceAddress.toString());

const serviceAccount =
await program.account.service.fetch(serviceAddress);
// console.log('Service Account Unique ID:', serviceAccount.uniqueId);
console.log('Service Account Description:', serviceAccount.description);
console.log('Service Account Price:', serviceAccount.price.toString());
}
} catch (error) {
console.error('Error in main execution:', error);
}
Expand Down
42 changes: 42 additions & 0 deletions anchor/admin/init.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { createMint } from '@solana/spl-token';
import { createAccount } from '@solana/spl-token';
import { PublicKey, Keypair } from '@solana/web3.js';

import { Connection } from '@solana/web3.js';

export async function createMintToken(
connection: Connection,
deployer: Keypair,
) {
try {
const mint = await createMint(
connection,
deployer, // payer FEE
deployer.publicKey, // owner, mint authority who can mint new tokens
deployer.publicKey, // freeze authority
8,
);
return mint;
} catch (error) {
console.error('Error creating mint token:', error);
}
}

export async function createTokenAccount(
connection: Connection,
payerKeypair: Keypair,
mint: PublicKey,
): Promise<PublicKey> {
try {
const tokenAccount: PublicKey = await createAccount(
connection,
payerKeypair, // Payer
mint, // Mint
payerKeypair.publicKey, // Owner
);
return tokenAccount;
} catch (error) {
console.error('Error creating token account:', error);
throw new Error('Failed to create token account');
}
}
97 changes: 45 additions & 52 deletions anchor/admin/write-services.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import * as dotenv from 'dotenv';
import * as fs from 'fs';

import { Program, workspace, setProvider } from '@coral-xyz/anchor';
import { createMint } from '@solana/spl-token';

import { Connection, LAMPORTS_PER_SOL, PublicKey } from '@solana/web3.js';

import { services } from './Services'; // Import services from Services.ts
import { Gigentic } from '../target/types/gigentic';
import { PROVIDER } from '../tests/constants';
import { airdrop, loadKeypairBs58FromEnv } from '../tests/utils';

import { createTokenAccount } from './init';
import { createService } from './createService';
import { services } from './Services';

dotenv.config();

// Configure the client to use the local cluster
// Use cluster configured in local CLI environment
setProvider(PROVIDER);

// Initialize connection and program
Expand All @@ -24,88 +24,81 @@ const program: Program<Gigentic> = workspace.Gigentic as Program<Gigentic>;
const serviceRegistryDeployer = loadKeypairBs58FromEnv(
'SERVICE_REGISTRY_DEPLOYER_KEYPAIR',
);
const serviceRegistryKeypair = loadKeypairBs58FromEnv(
'SERVICE_REGISTRY_KEYPAIR',
);
console.log(
'serviceRegistryDeployer',
'Service Registry Deployer Public Key:',
serviceRegistryDeployer.publicKey.toString(),
);

const serviceRegistryKeypair = loadKeypairBs58FromEnv(
'SERVICE_REGISTRY_KEYPAIR',
);
console.log(
'serviceRegistryKeypair',
'Service Registry Keypair Public Key:',
serviceRegistryKeypair.publicKey.toString(),
);

// Load service deployer keypair
const serviceDeployer = loadKeypairBs58FromEnv('SERVICE_DEPLOYER_KEYPAIR');
console.log('serviceDeployer', serviceDeployer.publicKey.toString());

let mint: PublicKey;

async function createMintToken() {
try {
mint = await createMint(
connection,
serviceRegistryDeployer,
serviceRegistryDeployer.publicKey,
serviceRegistryDeployer.publicKey,
8,
);
console.log('Mint token created:', mint.toString());
} catch (error) {
console.error('Error creating mint token:', error);
}
}
console.log(
'Service Deployer Public Key:',
serviceDeployer.publicKey.toString(),
);

async function main() {
try {
console.log('========== Create mint token');
await createMintToken();
console.log('\n');
// console.log('========== Airdrop for Service Deployer ==========');
// await airdrop(connection, serviceDeployer.publicKey);
// console.log('Airdrop completed successfully.\n');
// console.log('skip airdrop serviceDeployer');

const data = fs.readFileSync('Token.json', 'utf-8');
const parsedData = JSON.parse(data);
const tokenMint = new PublicKey(parsedData.mintPublicKey);

console.log('========== Airdrop service deployer');
await airdrop(connection, serviceDeployer.publicKey);
console.log('\n');
// Creating a token account
const serviceProviderTokenAccount = await createTokenAccount(
connection,
serviceDeployer,
tokenMint,
);

console.log('========== Prepare data and Create services');
console.log('\n');
// Update Token.json with the service provider token account
parsedData.serviceProviderTokenAccountPublicKey =
serviceProviderTokenAccount;
fs.writeFileSync('Token.json', JSON.stringify(parsedData, null, 2));

console.log('========== Prepare Data and Create Services ==========');
let index = 0;

for (const service of services) {
const description = `chatWalletAddress: ${service.chatWalletAddress} | title: ${service.title} | experience: ${service.experience} | price: ${service.price} ${service.currency} | avgRating: ${service.avgRating}`;
console.log(description);

// Update to use services array
const uniqueId = `${Date.now()}-${Math.random().toString(36).substring(2, 15)}`;
console.log(
`Creating service ${index + 1}/${services.length} with ID ${uniqueId}:`,
`Creating service ${index + 1}/${services.length}: ${description}`,
);

const uniqueId = `${Date.now()}-${Math.random().toString(36).substring(2, 15)}`;
await createService(
serviceRegistryKeypair.publicKey,
mint,
tokenMint,
program,
LAMPORTS_PER_SOL * service.price, // Use price from services
description, // Use description from services
// index.toString(), // unique id
LAMPORTS_PER_SOL * service.price,
description,
uniqueId,
serviceProviderTokenAccount,
);
index++;
}

console.log('========== Fetch service registry');
console.log('========== Fetch Service Registry ==========');
const serviceRegistry = await program.account.serviceRegistry.fetch(
serviceRegistryKeypair.publicKey,
);

for (const serviceAddress of serviceRegistry.serviceAccountAddresses) {
console.log('Service Account Address:', serviceAddress.toString());

const serviceAccount =
await program.account.service.fetch(serviceAddress);
console.log('Service Account Description:', serviceAccount.description);
console.log('Service Account Price:', serviceAccount.price.toString());
// console.log('Service Account Mint:', serviceAccount.mint.toString());
console.log(`Service Account Address: ${serviceAddress.toString()}`);
console.log(`Service Account Description: ${serviceAccount.description}`);
console.log(`Service Account Price: ${serviceAccount.price.toString()}`);
}
} catch (error) {
console.error('Error in main execution:', error);
Expand Down
2 changes: 1 addition & 1 deletion anchor/programs/gigentic/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ default = []
idl-build = ["anchor-lang/idl-build", "anchor-spl/idl-build"]

[dependencies]
anchor-lang = "0.30.1"
anchor-lang = "0.30.1"
anchor-spl = "0.30.1"
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ pub struct ReviewCustomerToProviderService<'info> {
// The account of the user deploying and paying for the initialization.
// Marked as `mut` because it will be charged for rent.
#[account(mut)]
pub signer: Signer<'info>,
pub customer: Signer<'info>,

#[account(mut, constraint = review.customer == signer.key())]
#[account(mut, constraint = review.customer == customer.key())]
pub review: Account<'info, Review>,

pub system_program: Program<'info, System>,
Expand Down
18 changes: 16 additions & 2 deletions anchor/programs/gigentic/src/contexts/init_service.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use crate::states::{service_registry::ServiceRegistry, Service};
use crate::states::{
service_authority::ServiceAuthority, service_registry::ServiceRegistry, Service,
};
use crate::ErrorCode;
use anchor_lang::prelude::*;
use anchor_spl::token::TokenAccount;
use anchor_spl::token_interface::{Mint, TokenInterface};

#[derive(Accounts)]
Expand All @@ -24,6 +27,17 @@ pub struct InitializeService<'info> {
)]
service: Account<'info, Service>,

pub service_provider_token_account: Account<'info, TokenAccount>,

#[account(
init,
payer = provider,
space = 8,
seeds = ["service_authority".as_bytes(), service.key().as_ref()],
bump
)]
service_authority: Account<'info, ServiceAuthority>,

// The mint account for the token
#[account(
mint::token_program = token_program
Expand Down Expand Up @@ -74,8 +88,8 @@ impl<'info> InitializeService<'info> {
description,
price,
reviews: Vec::new(), // Initialize reviews as an empty vector
service_provider_token_account: self.service_provider_token_account.key(),
});

Ok(())
}
}
Loading