Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Ordinals (& Runes!) support through plugin-ordinals #1699

Closed
wants to merge 32 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
953dfb1
upd: initial commit plugin ordinals
JoeyKhd Jan 2, 2025
e736193
upd: added more function to bitcoin wallet provider
JoeyKhd Jan 2, 2025
c2620cc
work in progress on initial setup of actions
JoeyKhd Jan 3, 2025
9d8f084
upd: retrieval of ordinals address is possible
JoeyKhd Jan 3, 2025
07ad7e7
upd: added the ability to retrieve ordinals bitcoin wallets btc balance
JoeyKhd Jan 3, 2025
853357d
upd: added the ability to retrieve utxos of ordinals wallet
JoeyKhd Jan 3, 2025
0c62627
upd: created action to retrieve bitcoin transaction status
JoeyKhd Jan 3, 2025
8653611
upd: work in progress on tx status
JoeyKhd Jan 3, 2025
2cb4250
upd: transaction status is fully operational
JoeyKhd Jan 3, 2025
9f64ee1
upd: created ordiscan api
JoeyKhd Jan 3, 2025
9fe74da
upd: added the ability to get the runes portfolio
JoeyKhd Jan 3, 2025
53af999
upd: refactored wallet to use 12 word seed phrase same as Xverse
JoeyKhd Jan 3, 2025
2d929b1
upd: get runes portfolio functional
JoeyKhd Jan 3, 2025
8157787
upd: moved formatBitcoinBalance to own utils file
JoeyKhd Jan 3, 2025
80c661d
upd: btc balance lookup can now be done for any address, not only the…
JoeyKhd Jan 3, 2025
db0d5b5
upd: retrieving runes portfolio can now be done not only for agents w…
JoeyKhd Jan 3, 2025
ee2ef32
upd: work in progress on Runes transactions builder for transfers
JoeyKhd Jan 4, 2025
1d4985a
upd: created generic error handler
JoeyKhd Jan 4, 2025
a2139c8
upd: added break words and whitespace to client so that \n gets appli…
JoeyKhd Jan 4, 2025
01452cc
upd: rune transfers functional
JoeyKhd Jan 4, 2025
b40d034
upd: runes transfer now calculate their fees properly
JoeyKhd Jan 4, 2025
10107e5
upd: code cleanups
JoeyKhd Jan 4, 2025
65142c6
upd: reworked runes portfolio to also show 24h change as well as the …
JoeyKhd Jan 4, 2025
716a68d
upd: added the ability to get back price information of a rune
JoeyKhd Jan 5, 2025
bb85a67
upd: work in progress on introducing much stricter types
JoeyKhd Jan 5, 2025
f2d9268
upd: removed unused imports and unused package
JoeyKhd Jan 5, 2025
1f80d5d
upd: desired fee rate is now possible for rune transfers
JoeyKhd Jan 5, 2025
04d8f2d
upd: reworked the way utxos are being formatted when returned
JoeyKhd Jan 5, 2025
40cff88
upd: reset eternalai character
JoeyKhd Jan 5, 2025
38eb0e0
upd: added the ability to retrieve rare sats for given address
JoeyKhd Jan 5, 2025
2c1be18
upd: increased batch size for call
JoeyKhd Jan 5, 2025
3587135
fix: batch size issue on rare sats
JoeyKhd Jan 5, 2025
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
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
Loading