2023-11-15 23:16:10 +00:00
|
|
|
import { createRoot } from 'react-dom/client';
|
|
|
|
|
import { WalletStatusBarItem} from './src/components/WalletStatusBarItem'
|
2023-10-25 16:39:07 +00:00
|
|
|
import { Notice, Plugin, ItemView } from 'obsidian';
|
2023-11-15 23:16:10 +00:00
|
|
|
import {
|
2023-10-23 16:42:22 +00:00
|
|
|
type CanvasView,
|
2023-11-15 23:16:10 +00:00
|
|
|
} from './src/utils/canvas-util'
|
2023-10-31 22:44:19 +00:00
|
|
|
import { getDpid } from './src/desci-nodes/getDpid'
|
|
|
|
|
import { runSdxl } from './src/lilypad/runSdxl'
|
|
|
|
|
import { runCowsay } from 'src/lilypad/runCowsay';
|
2023-11-15 23:16:10 +00:00
|
|
|
import { dagGet } from './src/ipfs/dagGet'
|
|
|
|
|
import { cat } from './src/ipfs/cat'
|
|
|
|
|
import { add } from './src/ipfs/add'
|
2024-10-28 14:25:46 +00:00
|
|
|
import { createWalletClient, createPublicClient, http, getContract } from 'viem'
|
|
|
|
|
import { privateKeyToAccount, type Account } from 'viem/accounts'
|
|
|
|
|
import { type WalletClient, type PublicClient } from 'viem'
|
|
|
|
|
import ExampleClient from './artifacts/LilypadClient.json'
|
|
|
|
|
import LilypadToken from './artifacts/LilypadToken.json'
|
2023-11-15 23:16:10 +00:00
|
|
|
import { getMolecule } from './src/plex/getMolecule'
|
|
|
|
|
import { getProtein } from './src/plex/getProtein'
|
2023-11-11 23:57:26 +00:00
|
|
|
import { runEquibind } from './src/plex/runEquibind'
|
2023-11-12 23:54:32 +00:00
|
|
|
import { viewMolecule } from 'src/plex/viewMolecule';
|
2023-11-15 23:16:10 +00:00
|
|
|
import {
|
2023-10-23 16:42:22 +00:00
|
|
|
ObsidianDesciSettings,
|
|
|
|
|
ObsidianDesciSettingTab,
|
|
|
|
|
DEFAULT_SETTINGS
|
2023-11-15 23:16:10 +00:00
|
|
|
} from './src/settings';
|
2023-09-03 08:01:12 +00:00
|
|
|
|
2023-11-14 20:04:14 +00:00
|
|
|
import { WalletModal } from './src/views/WalletView';
|
2024-10-28 14:25:46 +00:00
|
|
|
import {
|
|
|
|
|
localhost, arbitrumSepolia
|
|
|
|
|
} from 'viem/chains';
|
|
|
|
|
/*
|
2023-11-15 23:16:10 +00:00
|
|
|
import {
|
|
|
|
|
localhost,
|
|
|
|
|
mainnet,
|
|
|
|
|
optimism,
|
|
|
|
|
arbitrum,
|
|
|
|
|
evmosTestnet,
|
|
|
|
|
} from 'wagmi/chains';
|
|
|
|
|
|
|
|
|
|
import { createWeb3Modal, defaultWagmiConfig } from '@web3modal/wagmi/react'
|
|
|
|
|
import { WagmiConfig } from 'wagmi';
|
2024-10-28 14:25:46 +00:00
|
|
|
*/
|
|
|
|
|
|
2023-09-03 08:01:12 +00:00
|
|
|
|
2023-10-23 15:01:59 +00:00
|
|
|
export default class ObsidianDesci extends Plugin {
|
|
|
|
|
settings: ObsidianDesciSettings;
|
2023-09-04 19:24:13 +00:00
|
|
|
unloaded = false
|
2024-10-28 14:25:46 +00:00
|
|
|
account: Account
|
|
|
|
|
walletClient: WalletClient
|
|
|
|
|
publicClient: PublicClient
|
|
|
|
|
lilypadToken: any
|
|
|
|
|
exampleClient: any
|
2023-09-04 19:24:13 +00:00
|
|
|
logDebug: (...args: unknown[]) => void = () => { }
|
2023-09-03 08:01:12 +00:00
|
|
|
async onload() {
|
|
|
|
|
await this.loadSettings();
|
2024-10-28 14:25:46 +00:00
|
|
|
/*
|
2023-11-15 23:16:10 +00:00
|
|
|
const projectId = 'ded360a934deb7668cafc3d5ae1928e4'
|
2024-10-28 14:25:46 +00:00
|
|
|
const chainsModal = [arbitrumSepolia, localhost]
|
2023-11-15 23:16:10 +00:00
|
|
|
const metadata = {
|
|
|
|
|
name: 'Obsidian Desci',
|
|
|
|
|
description: 'Web3 x Obsidian.md x DeSci',
|
|
|
|
|
url: 'https://web3modal.com',
|
|
|
|
|
icons: ['https://avatars.githubusercontent.com/u/37784886']
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const wagmiConfig = defaultWagmiConfig({
|
|
|
|
|
chains: chainsModal,
|
|
|
|
|
projectId,
|
|
|
|
|
metadata,
|
|
|
|
|
})
|
|
|
|
|
createWeb3Modal({ wagmiConfig, projectId, chains: chainsModal })
|
2023-11-14 20:04:14 +00:00
|
|
|
const walletTab = this.addRibbonIcon("wallet", "Open Wallet", () => {
|
2023-11-15 23:16:10 +00:00
|
|
|
new WalletModal(this.app, wagmiConfig).open();
|
2023-11-14 20:04:14 +00:00
|
|
|
})
|
2023-11-15 23:16:10 +00:00
|
|
|
|
2024-10-28 14:25:46 +00:00
|
|
|
|
2023-11-15 23:16:10 +00:00
|
|
|
const walletStatus = this.addStatusBarItem()
|
|
|
|
|
const rootElement = walletStatus.createEl("span")
|
|
|
|
|
const root = createRoot(rootElement)
|
|
|
|
|
root.render(
|
|
|
|
|
<WagmiConfig config={wagmiConfig}>
|
|
|
|
|
<WalletStatusBarItem/>
|
|
|
|
|
</WagmiConfig>
|
|
|
|
|
)
|
2024-10-28 14:25:46 +00:00
|
|
|
*/
|
2023-11-15 23:16:10 +00:00
|
|
|
|
|
|
|
|
|
2024-10-28 14:25:46 +00:00
|
|
|
if (this.settings.privateKey) {
|
|
|
|
|
// walletClient from privateKey
|
|
|
|
|
const account = privateKeyToAccount('0x' + this.settings.privateKey as `0x${string}`)
|
|
|
|
|
this.account = account
|
|
|
|
|
this.walletClient = createWalletClient({
|
|
|
|
|
account: this.account,
|
|
|
|
|
chain: arbitrumSepolia,
|
|
|
|
|
transport: http(this.settings.chain.rpcUrl)
|
|
|
|
|
})
|
|
|
|
|
this.publicClient = createPublicClient({
|
|
|
|
|
chain: arbitrumSepolia,
|
|
|
|
|
transport: http(this.settings.chain.rpcUrl)
|
|
|
|
|
})
|
2023-11-15 23:16:10 +00:00
|
|
|
|
2024-10-28 14:25:46 +00:00
|
|
|
this.lilypadToken = getContract({
|
|
|
|
|
address: LilypadToken.address as `0x${string}`,
|
|
|
|
|
abi: LilypadToken.abi,
|
|
|
|
|
client: {
|
|
|
|
|
public: this.publicClient,
|
|
|
|
|
wallet: this.walletClient
|
|
|
|
|
}
|
|
|
|
|
})
|
2023-11-15 23:16:10 +00:00
|
|
|
|
2024-10-28 14:25:46 +00:00
|
|
|
this.exampleClient = getContract({
|
|
|
|
|
address: ExampleClient.address as `0x${string}`,
|
|
|
|
|
abi: ExampleClient.abi,
|
|
|
|
|
client: {
|
|
|
|
|
public: this.publicClient,
|
|
|
|
|
wallet: this.walletClient
|
|
|
|
|
}
|
|
|
|
|
})
|
2023-09-04 19:24:13 +00:00
|
|
|
} else {
|
2023-10-25 16:39:07 +00:00
|
|
|
}
|
2023-09-05 18:46:17 +00:00
|
|
|
this.addCommand({
|
|
|
|
|
id: 'runCowsay',
|
2023-09-17 11:45:29 +00:00
|
|
|
name: 'runCowsay - execute the cowsay program through a smart contract',
|
2023-10-23 20:26:53 +00:00
|
|
|
callback: runCowsay.bind(this)
|
2023-09-05 18:46:17 +00:00
|
|
|
});
|
2023-09-06 07:04:16 +00:00
|
|
|
this.addCommand({
|
|
|
|
|
id: 'runSDXL',
|
2023-09-17 11:45:29 +00:00
|
|
|
name: 'runSDXL - execute stable diffusion on a text node',
|
2023-10-23 19:54:41 +00:00
|
|
|
callback: runSdxl.bind(this)
|
2023-09-06 07:04:16 +00:00
|
|
|
});
|
2023-09-06 14:15:13 +00:00
|
|
|
this.addCommand({
|
|
|
|
|
id: 'getDpid',
|
2023-09-17 11:45:29 +00:00
|
|
|
name: 'getDpid - retreive the json of a desci nodes research object',
|
2023-10-23 19:54:41 +00:00
|
|
|
callback: getDpid.bind(this)
|
2023-09-06 14:15:13 +00:00
|
|
|
});
|
|
|
|
|
this.addCommand({
|
|
|
|
|
id: 'ipfsCat',
|
2023-09-17 11:45:29 +00:00
|
|
|
name: 'ipfsCat - attempt to fetch a cid from ipfs',
|
2023-10-23 20:26:53 +00:00
|
|
|
callback: cat.bind(this)
|
2023-09-06 14:15:13 +00:00
|
|
|
});
|
2023-09-17 11:45:29 +00:00
|
|
|
this.addCommand({
|
|
|
|
|
id: 'ipfsDagGet',
|
|
|
|
|
name: 'ipfsDagGet - fetch json behind a persistent identifer',
|
2023-10-23 19:54:41 +00:00
|
|
|
callback: dagGet.bind(this)
|
2023-09-17 11:45:29 +00:00
|
|
|
});
|
|
|
|
|
this.addCommand({
|
|
|
|
|
id: 'ipfsAdd',
|
|
|
|
|
name: 'ipfsAdd - Add Json objects referenced by CID',
|
2023-10-23 20:26:53 +00:00
|
|
|
callback: add.bind(this)
|
2023-09-17 11:45:29 +00:00
|
|
|
});
|
2023-11-11 23:57:26 +00:00
|
|
|
this.addCommand({
|
|
|
|
|
id: 'getMolecule',
|
|
|
|
|
name: 'getMolecule -fetch an .spf file for plex',
|
|
|
|
|
callback: getMolecule.bind(this)
|
|
|
|
|
}),
|
2023-11-15 23:16:10 +00:00
|
|
|
this.addCommand({
|
|
|
|
|
id: 'getProtein',
|
|
|
|
|
name: 'getProtein - fetch a .pdb file for plex',
|
|
|
|
|
callback: getProtein.bind(this)
|
|
|
|
|
})
|
2023-11-11 23:57:26 +00:00
|
|
|
this.addCommand({
|
|
|
|
|
id: 'runEquibind',
|
|
|
|
|
name: 'runEquibind - run equibind on a molecule and protein node',
|
|
|
|
|
callback: runEquibind.bind(this)
|
|
|
|
|
})
|
2023-11-12 23:54:32 +00:00
|
|
|
this.addCommand({
|
|
|
|
|
id: 'viewMolecule',
|
|
|
|
|
name: 'viewMolecule - view a molecule',
|
|
|
|
|
callback: viewMolecule.bind(this)
|
|
|
|
|
})
|
2023-10-23 15:01:59 +00:00
|
|
|
this.addSettingTab(new ObsidianDesciSettingTab(this.app, this));
|
2023-11-11 23:57:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
this.registerExtensions(["sdf"], "markdown");
|
|
|
|
|
this.registerExtensions(["pdb"], "markdown");
|
2023-09-03 08:01:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onunload() {
|
2023-09-05 18:46:17 +00:00
|
|
|
}
|
|
|
|
|
|
2023-09-17 11:45:29 +00:00
|
|
|
|
2023-09-25 15:56:52 +00:00
|
|
|
|
2023-09-04 19:24:13 +00:00
|
|
|
getActiveCanvas() {
|
|
|
|
|
const maybeCanvasView = this.app.workspace.getActiveViewOfType(ItemView) as CanvasView | null
|
|
|
|
|
return maybeCanvasView ? maybeCanvasView['canvas'] : null
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-03 08:01:12 +00:00
|
|
|
|
|
|
|
|
async loadSettings() {
|
|
|
|
|
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async saveSettings() {
|
|
|
|
|
await this.saveData(this.settings);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|