-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upstream/feat/solana sample elevenlabs (#62)
* Gutted out wagmi for dynamic, so we can add solana too * feat: wip solana support * fix: adapt dynamic signer to solana wallet client type * fix: type for solana wallet client * fix: new env default * fix: add loading state * fix: commit lockfile changes * fix: cleanup tools initialization * fix: remove dynamic example in favour of default one * fix: import sendEth plugin from sdk package * fix: regen lock file after removing dynamic specific example * fix: lint errors --------- Co-authored-by: alfonso-paella <[email protected]>
- Loading branch information
1 parent
a92d30f
commit 9a80478
Showing
27 changed files
with
1,511 additions
and
2,004 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 11 additions & 28 deletions
39
typescript/examples/eleven-labs/conversational-agent/src/app/providers.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,18 @@ | ||
"use client"; | ||
|
||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; | ||
import { ConnectKitProvider, getDefaultConfig } from "connectkit"; | ||
import { http, WagmiProvider, createConfig } from "wagmi"; | ||
import { sepolia } from "wagmi/chains"; | ||
|
||
const config = createConfig( | ||
getDefaultConfig({ | ||
// Your dApps chains | ||
chains: [sepolia], | ||
transports: { | ||
// RPC URL for each chain | ||
[sepolia.id]: http(process.env.NEXT_PUBLIC_SEPOLIA_RPC_URL ?? ""), | ||
}, | ||
|
||
// Required API Keys | ||
walletConnectProjectId: process.env.NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID ?? "", | ||
|
||
// Required App Info | ||
appName: "GOAT Conversational AI", | ||
}), | ||
); | ||
|
||
const queryClient = new QueryClient(); | ||
import { EthereumWalletConnectors } from "@dynamic-labs/ethereum"; | ||
import { DynamicContextProvider } from "@dynamic-labs/sdk-react-core"; | ||
import { SolanaWalletConnectors } from "@dynamic-labs/solana"; | ||
|
||
export const Web3Provider = ({ children }: { children: React.ReactNode }) => { | ||
return ( | ||
<WagmiProvider config={config}> | ||
<QueryClientProvider client={queryClient}> | ||
<ConnectKitProvider>{children}</ConnectKitProvider> | ||
</QueryClientProvider> | ||
</WagmiProvider> | ||
<DynamicContextProvider | ||
settings={{ | ||
environmentId: "f268a013-0fa0-4d9d-9314-c6919e2dfde7", // TODO replace in prod | ||
walletConnectors: [EthereumWalletConnectors, SolanaWalletConnectors], | ||
}} | ||
> | ||
{children} | ||
</DynamicContextProvider> | ||
); | ||
}; |
68 changes: 68 additions & 0 deletions
68
typescript/examples/eleven-labs/conversational-agent/src/app/utils/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import type { ISolana } from "@dynamic-labs/solana-core"; | ||
import type { SolanaReadRequest, SolanaTransaction, SolanaWalletClient } from "@goat-sdk/core"; | ||
import { type Connection, PublicKey, TransactionMessage, VersionedTransaction } from "@solana/web3.js"; | ||
|
||
export function createSolanaWalletFromDynamic(connection: Connection, signer: ISolana): SolanaWalletClient { | ||
const publicKey = signer.publicKey; | ||
if (!publicKey) { | ||
throw new Error("Signer public key is undefined"); | ||
} | ||
|
||
return { | ||
getAddress: () => new PublicKey(publicKey.toBytes()).toBase58(), | ||
getChain() { | ||
return { | ||
type: "solana", | ||
}; | ||
}, | ||
async signMessage(message: string) { | ||
const messageBytes = Buffer.from(message); | ||
const signature = await signer.signMessage(messageBytes); | ||
return { | ||
signature: Buffer.from(signature.signature).toString("hex"), | ||
}; | ||
}, | ||
async sendTransaction({ instructions }: SolanaTransaction) { | ||
const latestBlockhash = await connection.getLatestBlockhash("confirmed"); | ||
const message = new TransactionMessage({ | ||
payerKey: new PublicKey(publicKey.toBytes()), | ||
recentBlockhash: latestBlockhash.blockhash, | ||
instructions, | ||
}).compileToV0Message(); | ||
const transaction = new VersionedTransaction(message); | ||
const signedTx = await signer.signTransaction(transaction); | ||
|
||
const txid = await connection.sendTransaction(signedTx, { | ||
maxRetries: 5, | ||
}); | ||
|
||
return { | ||
hash: txid, | ||
}; | ||
}, | ||
async read(request: SolanaReadRequest) { | ||
const { accountAddress } = request; | ||
const pubkey = new PublicKey(accountAddress); | ||
const accountInfo = await connection.getAccountInfo(pubkey); | ||
|
||
if (!accountInfo) { | ||
throw new Error(`Account ${accountAddress} not found`); | ||
} | ||
|
||
return { | ||
value: accountInfo, | ||
}; | ||
}, | ||
async balanceOf(address: string) { | ||
const pubkey = new PublicKey(address); | ||
const balance = await connection.getBalance(pubkey); | ||
|
||
return { | ||
decimals: 9, | ||
symbol: "SOL", | ||
name: "Solana", | ||
value: BigInt(balance), | ||
}; | ||
}, | ||
}; | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.