Skip to content

Commit

Permalink
upd: initial commit plugin ordinals
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeyKhd committed Jan 2, 2025
1 parent 76d4f42 commit 953dfb1
Show file tree
Hide file tree
Showing 11 changed files with 712 additions and 446 deletions.
6 changes: 6 additions & 0 deletions packages/plugin-ordinals/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*

!dist/**
!package.json
!readme.md
!tsup.config.ts
3 changes: 3 additions & 0 deletions packages/plugin-ordinals/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import eslintGlobalConfig from "../../eslint.config.mjs";

export default [...eslintGlobalConfig];
27 changes: 27 additions & 0 deletions packages/plugin-ordinals/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "@elizaos/plugin-ordinals",
"version": "0.1.7-alpha.2",
"main": "dist/index.js",
"type": "module",
"types": "dist/index.d.ts",
"dependencies": {
"@elizaos/core": "workspace:*",
"@magiceden-oss/runestone-lib": "^1.0.2",
"@mempool/mempool.js": "^3.0.0",
"@noble/curves": "^1.7.0",
"@scure/base": "^1.2.1",
"@scure/btc-signer": "^1.5.0",
"tsup": "8.3.5",
"vitest": "2.1.4"
},
"scripts": {
"build": "tsup --format esm --dts",
"dev": "tsup --format esm --dts --watch",
"lint": "eslint --fix --cache .",
"test": "vitest run"
},
"peerDependencies": {
"form-data": "4.0.1",
"whatwg-url": "7.1.0"
}
}
11 changes: 11 additions & 0 deletions packages/plugin-ordinals/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Plugin } from "@elizaos/core";

export const ordinalsPlugin: Plugin = {
name: "ordinals",
description: "Ordinals Plugin for Eliza",
actions: [],
evaluators: [],
providers: [],
};

export default ordinalsPlugin;
Empty file.
8 changes: 8 additions & 0 deletions packages/plugin-ordinals/src/providers/runes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { encodeRunestone } from "@magiceden-oss/runestone-lib";

class Runes {
getRuneBalance() {}
etchRune(){}
mintRune(){}
transferRune(){}
}
92 changes: 92 additions & 0 deletions packages/plugin-ordinals/src/providers/wallet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import { IAgentRuntime, Memory, Provider, State } from "@elizaos/core";
import * as btc from "@scure/btc-signer";
import { secp256k1 } from "@noble/curves/secp256k1";
import { hex } from "@scure/base";
import mempoolJS from "@mempool/mempool.js";
import { MempoolReturn } from "@mempool/mempool.js/lib/interfaces";
import { IAccount } from "../types";

export class WalletProvider {
mempool: MempoolReturn;
account: IAccount;

constructor(privateKey: string) {
this.account = this.getAccount(privateKey);
this.mempool = mempoolJS({
hostname: "mempool.space",
});
}

getAccount(privateKey: string): IAccount {
const privateKeyA = hex.decode(privateKey);
const publicKey = secp256k1.getPublicKey(privateKeyA, true);
const schnorrPublicKey = btc.utils.pubSchnorr(privateKeyA);
const network = btc.NETWORK;

const nestedSegwitAddress = btc.p2sh(
btc.p2wpkh(publicKey, network),
network
).address;

const taprootAddress = btc.p2tr(
schnorrPublicKey,
undefined,
network
).address;

return {
nestedSegwitAddress,
taprootAddress,
privateKey,
};
}

getAddresses() {
return {
nestedSegwitAddress: this.account.nestedSegwitAddress,
taprootAddress: this.account.taprootAddress,
};
}

async getBalance() {
const data = await this.mempool.bitcoin.addresses.getAddress({
address: this.account.nestedSegwitAddress,
});
return data?.mempool_stats?.funded_txo_sum || 0;
}

async getTransactionHistory() {
return await this.mempool.bitcoin.addresses.getAddressTxs({
address: this.account.nestedSegwitAddress,
});
}

async getTransactionStatus(txid: string) {
return await this.mempool.bitcoin.transactions.getTxStatus({ txid });
}

async signPsbt(){}
}

const walletProvider: Provider = {
get: async (
runtime: IAgentRuntime,
_message: Memory,
_state?: State
): Promise<string | null> => {
try {
const BTC_PK = runtime.getSetting("BITCOIN_PRIVATE_KEY");
const provider = new WalletProvider(BTC_PK);
const balance = await provider.getBalance();
const addresses = provider.getAddresses();

return `Ordinals wallet => ${addresses.nestedSegwitAddress} / ${addresses.taprootAddress} | Balance: ${balance}`;
} catch (error) {
console.error("Error in wallet provider:", error);
return null;
}
},
};

// Module exports
export { walletProvider };
5 changes: 5 additions & 0 deletions packages/plugin-ordinals/src/types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface IAccount {
nestedSegwitAddress: string;
taprootAddress: string;
privateKey?: string;
}
10 changes: 10 additions & 0 deletions packages/plugin-ordinals/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "../core/tsconfig.json",
"compilerOptions": {
"outDir": "dist",
"rootDir": "src"
},
"include": [
"src/**/*.ts"
]
}
29 changes: 29 additions & 0 deletions packages/plugin-ordinals/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { defineConfig } from "tsup";

export default defineConfig({
entry: ["src/index.ts"],
outDir: "dist",
sourcemap: true,
clean: true,
format: ["esm"], // Ensure you're targeting CommonJS
external: [
"dotenv", // Externalize dotenv to prevent bundling
"fs", // Externalize fs to use Node.js built-in module
"path", // Externalize other built-ins if necessary
"@reflink/reflink",
"@node-llama-cpp",
"https",
"http",
"agentkeepalive",
"safe-buffer",
"base-x",
"bs58",
"borsh",
"@solana/buffer-layout",
"stream",
"buffer",
"querystring",
"amqplib",
// Add other modules you want to externalize
],
});
Loading

0 comments on commit 953dfb1

Please sign in to comment.