Skip to content

Commit

Permalink
create product tx
Browse files Browse the repository at this point in the history
  • Loading branch information
0x0ece committed Apr 5, 2024
1 parent 773602c commit 0a8a820
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 65 deletions.
7 changes: 5 additions & 2 deletions web/src/app/app-routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,23 @@ import { Navigate, useRoutes } from 'react-router-dom';
import AccountDetailFeature from './account/account-detail-feature';
import AccountListFeature from './account/account-list-feature';
import CreateProduct from './manage/CreateProduct';
import GlamFeature from './glam/glam-feature';
import Manage from './manage/Manage';
import ProductPage from './products/product-page';
import ProductsOverview from './products/products-overview';

import GlamFeature from './glam/glam-feature';
import ClusterFeature from './cluster/cluster-feature';

export function AppRoutes() {
return useRoutes([
{ index: true, element: <Navigate to={'/products'} replace={true} /> },
{ path: '/account/', element: <AccountListFeature /> },
{ path: '/account/:address', element: <AccountDetailFeature /> },
{ path: '/manage', element: <Manage /> },
{ path: '/create-product', element: <CreateProduct /> },

{ path: '/glam', element: <GlamFeature /> },
{ path: '/create-product', element: <CreateProduct /> },
{ path: '/cluster', element: <ClusterFeature /> },

{ path: '/products', element: <ProductsOverview /> },
{ path: '/products/:id', element: <ProductPage /> },
Expand Down
21 changes: 14 additions & 7 deletions web/src/app/data/tokenList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ export const tokenList = [
{
id: 0,
symbol: "USDC",
name: "USD Coin",
tokenMint: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
// name: "USD Coin",
name: "USD Coin (Drift Devnet)",
// tokenMint: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
tokenMint: "8zGuJQqwhZafTah7Uc7Z4tXRnguqkn5KLFAP8oV6PHe2",
decimals: 6,
coingeckoId: "usd-coin",
oracle: "Pyth",
oracleAccount: "Gnt27xtC473ZT2Mw5u8wZ68Z3gULkSTb5DuxJy7eJotD",
// oracleAccount: "Gnt27xtC473ZT2Mw5u8wZ68Z3gULkSTb5DuxJy7eJotD",
oracleAccount: "5SSkXsEKQepHHAewytPVwdej4epN1nxgLVM84L4KXgy7",
imgURL:
"https://raw.githubusercontent.com/solana-labs/token-list/main/assets/mainnet/EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v/logo.png"
},
Expand All @@ -19,19 +22,23 @@ export const tokenList = [
decimals: 9,
coingeckoId: "solana",
oracle: "Pyth",
oracleAccount: "H6ARHf6YXhGYeQfUzQNGk6rDNnLBQKrenN712K4AQJEG",
// oracleAccount: "H6ARHf6YXhGYeQfUzQNGk6rDNnLBQKrenN712K4AQJEG",
oracleAccount: "J83w4HKfqxwcq3BEMMkPFSppX3gqekLyLJBexebFVkix",
imgURL:
"https://assets.coingecko.com/coins/images/4128/standard/solana.png?1696504756"
},
{
id: 2,
symbol: "WBTC",
name: "Wrapped BTC (Portal)",
tokenMint: "3NZ9JMVBmGAqocybic2c7LQCJScmgsAZ6vQqTDzcqmJh",
// name: "Wrapped BTC (Portal)",
name: "Wrapped BTC (Drift Devnet)",
// tokenMint: "3NZ9JMVBmGAqocybic2c7LQCJScmgsAZ6vQqTDzcqmJh",
tokenMint: "3BZPwbcqB5kKScF3TEXxwNfx5ipV13kbRVDvfVp5c6fv",
decimals: 8,
coingeckoId: "bitcoin",
oracle: "Pyth",
oracleAccount: "GVXRSBjFk6e6J3NbVPXohDJetcTjaeeuykUpbQF8UoMU",
// oracleAccount: "GVXRSBjFk6e6J3NbVPXohDJetcTjaeeuykUpbQF8UoMU",
oracleAccount: "HovQMDrbAgAYPCmHVSrezcSmkMtXSSUsLDFANExrZh2J",
imgURL:
"https://assets.coingecko.com/coins/images/1/standard/bitcoin.png?1696501400"
},
Expand Down
97 changes: 51 additions & 46 deletions web/src/app/glam/glam-data-access.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
getAssociatedTokenAddressSync
} from "@solana/spl-token";
import { BN, Program } from "@coral-xyz/anchor";
import { Cluster, Keypair, PublicKey } from "@solana/web3.js";
import { ComputeBudgetProgram, Cluster, AccountMeta, PublicKey } from "@solana/web3.js";
import { GlamIDL, getGlamProgramId } from "@glam/anchor";
import { useConnection, useWallet } from "@solana/wallet-adapter-react";
import { useMutation, useQuery } from "@tanstack/react-query";
Expand Down Expand Up @@ -65,70 +65,75 @@ export function useGlamProgram() {
mutationFn: ({
fundName,
fundSymbol,
fundUri,
manager,
feeStructure,
assets,
assetsStructure,
shareClassMetadata
}: {
fundName: string;
fundSymbol: string;
fundUri: string;
manager: PublicKey;
feeStructure: number[];
assets: string[],
assetsStructure: number[];
shareClassMetadata: ShareClassMetadata;
}) =>
program.methods
}) => {
const [fundPDA, fundBump] = PublicKey.findProgramAddressSync(
[
anchor.utils.bytes.utf8.encode("fund"),
manager.toBuffer(),
anchor.utils.bytes.utf8.encode(fundName)
],
program.programId
);
const fundUri = `https://devnet.glam.systems/#/products/${fundPDA.toBase58()}`;

const [treasuryPDA, treasuryBump] = PublicKey.findProgramAddressSync(
[anchor.utils.bytes.utf8.encode("treasury"), fundPDA.toBuffer()],
program.programId
);

const [sharePDA, shareBump] = PublicKey.findProgramAddressSync(
[anchor.utils.bytes.utf8.encode("share-0"), fundPDA.toBuffer()],
program.programId
);

shareClassMetadata.uri = `https://api.glam.systems/metadata/${sharePDA.toBase58()}`;
shareClassMetadata.imageUri = `https://api.glam.systems/image/${sharePDA.toBase58()}.png`;

const remainingAccounts: Array<AccountMeta> = assets.map(a => (
{ pubkey: new PublicKey(a), isSigner: false, isWritable: false }
));
return program.methods
.initialize(
fundName,
fundSymbol,
fundUri,
feeStructure,
assetsStructure,
true,
shareClassMetadata
)
.accounts({
fund: PublicKey.findProgramAddressSync(
[
anchor.utils.bytes.utf8.encode("fund"),
manager.toBuffer(),
anchor.utils.bytes.utf8.encode("fundName")
],
program.programId
)[0],
treasury: PublicKey.findProgramAddressSync(
[
anchor.utils.bytes.utf8.encode("treasury"),
// fundPDA.toBuffer(),
PublicKey.findProgramAddressSync(
[
anchor.utils.bytes.utf8.encode("fund"),
manager.toBuffer(),
anchor.utils.bytes.utf8.encode("fundName")
],
program.programId
)[0].toBuffer()
],
program.programId
)[0],
share: PublicKey.findProgramAddressSync(
[
anchor.utils.bytes.utf8.encode("share"),
// fundPDA.toBuffer(),
PublicKey.findProgramAddressSync(
[
anchor.utils.bytes.utf8.encode("fund"),
manager.toBuffer(),
anchor.utils.bytes.utf8.encode("fundName")
],
program.programId
)[0].toBuffer()
],
program.programId
)[0],
fund: fundPDA,
treasury: treasuryPDA,
share: sharePDA,
manager: manager,
tokenProgram: TOKEN_2022_PROGRAM_ID
})
.remainingAccounts(remainingAccounts)
.preInstructions([
ComputeBudgetProgram.setComputeUnitLimit({ units: 500_000 })
])
.rpc()
},
onSuccess: (tx) => {
console.log(tx);
transactionToast(tx);
return accounts.refetch();
},
onError: (e) => {
console.error("Failed to initialize: ", e);
return toast.error("Failed to create product");
}
});

return {
Expand Down
20 changes: 10 additions & 10 deletions web/src/app/manage/CreateProduct.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -223,21 +223,19 @@ export const CreateProduct = () => {
alert("Please connect your wallet.");
return;
}
const assetsLen = assets.length;
const assetsPercentage = 10_000 / assetsLen;
let assetsStructure = assets.map( (a, i) => (i==0 ? 0 : assetsPercentage) );
initialize.mutate(
{
fundName: data.fundName,
fundSymbol: data.fundSymbol,
fundUri: "https://glam.systems/",
feeStructure: [
+(data.managementFee ?? 0),
0,
+(data.performanceFee ?? 0)
],
assets,
assetsStructure,
manager: wallet.publicKey,
shareClassMetadata: {
name: `${data.fundName} ${data.extension} ${data.shareClassAsset}`,
symbol: data.shareClassSymbol ?? "--",
uri: "https://api.glam.systems/metadata/xyz",
name: data.fundName, //FIXME
symbol: data.fundSymbol, //FIXME
shareClassAsset: data.shareClassAsset,
shareClassAssetId: new PublicKey(data.shareClassAssetID),
isin: "XS1082172823",
Expand All @@ -248,7 +246,9 @@ export const CreateProduct = () => {
extension: data.extension,
launchDate: new Date().toISOString().split("T")[0],
lifecycle: data.shareClassLifecycle.toLowerCase(),
imageUri: "https://api.glam.systems/image/xyz.png"
// these will be updated by initialize
uri: "",
imageUri: "",
}
},
{
Expand Down

0 comments on commit 0a8a820

Please sign in to comment.