@kaiachain/kaia-agent-kit
Version:
One stop solution for all Kaia Ecosystem projects
1,819 lines (1,768 loc) • 53.1 kB
JavaScript
var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
for (var prop in b || (b = {}))
if (__hasOwnProp.call(b, prop))
__defNormalProp(a, prop, b[prop]);
if (__getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(b)) {
if (__propIsEnum.call(b, prop))
__defNormalProp(a, prop, b[prop]);
}
return a;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
// src/kaia.plugin.ts
import { PluginBase, createTool } from "@goat-sdk/core";
// src/packages/kaiascan/index.ts
var kaiascan_exports = {};
__export(kaiascan_exports, {
Metadata: () => metadata_exports,
Services: () => services_exports
});
// src/packages/kaiascan/services.ts
var services_exports = {};
__export(services_exports, {
getAccountOverview: () => getAccountOverview,
getBlockInfo: () => getBlockInfo,
getCurrentBalance: () => getCurrentBalance,
getFTBalance: () => getFTBalance,
getKaiaInfo: () => getKaiaInfo,
getLatestBlock: () => getLatestBlock,
getNFTBalance: () => getNFTBalance,
getTransactionsByAccount: () => getTransactionsByAccount,
getTransactionsByBlockNumber: () => getTransactionsByBlockNumber
});
// src/utils/constants.ts
var API_DEFAULTS = {
BASE_URL: {
"kairos": "https://kairos-oapi.kaiascan.io/api/v1",
"kaia": "https://mainnet-oapi.kaiascan.io/api/v1"
}
};
// src/packages/kaiascan/utils/validations.ts
import { isAddress } from "viem";
var validations = {};
validations.checkApiKey = (apiKey) => {
if (!apiKey) {
throw new Error("Missing API key");
}
};
validations.checkAddress = (address) => {
return isAddress(address);
};
validations.checkNetwork = (network) => {
if (network !== "kairos" && network !== "kaia") {
throw new Error("Invalid network");
}
};
var validations_default = validations;
// src/packages/kaiascan/src/accounts/getAccountOverview.ts
var getAccountOverview = async (parameters, config) => {
let KAIA_KAIASCAN_API_KEY = config.KAIA_KAIASCAN_API_KEY;
let { address, network } = parameters;
network = network ? network.toLowerCase() : "kairos";
validations_default.checkApiKey(KAIA_KAIASCAN_API_KEY);
validations_default.checkAddress(address);
validations_default.checkNetwork(network);
const url = `${API_DEFAULTS.BASE_URL[network]}/accounts/${address}`;
const response = await fetch(url, {
method: "GET",
headers: {
Accept: "*/*",
Authorization: `Bearer ${KAIA_KAIASCAN_API_KEY}`
}
});
if (!response.ok) {
const error = await response.json();
throw new Error((error == null ? void 0 : error.message) || response.statusText);
}
const data = await response.json();
let responseText = `Here are the details
Account Details:
`;
responseText += `Address: ${data.address}
`;
responseText += `Account Type: ${data.account_type}
`;
responseText += `Balance: ${data.balance}
`;
responseText += `Total Transaction Count: ${data.total_transaction_count}
`;
return responseText;
};
// src/packages/kaiascan/src/accounts/getCurrentBalance.ts
var getCurrentBalance = async (parameters, config) => {
try {
let KAIA_KAIASCAN_API_KEY = config.KAIA_KAIASCAN_API_KEY;
let { address, network } = parameters;
network = network ? network.toLowerCase() : "kairos";
validations_default.checkApiKey(KAIA_KAIASCAN_API_KEY);
validations_default.checkAddress(address);
validations_default.checkNetwork(network);
const url = `${API_DEFAULTS.BASE_URL[network]}/accounts/${address}`;
const response = await fetch(url, {
method: "GET",
headers: {
Accept: "*/*",
Authorization: `Bearer ${KAIA_KAIASCAN_API_KEY}`
}
});
if (!response.ok) {
const error = await response.json();
throw new Error((error == null ? void 0 : error.message) || response.statusText);
}
const data = await response.json();
let responseText = `The current balance of ${address} is ${data.balance} KAIA on ${String(network)} network`;
return responseText;
} catch (error) {
return `Failed to fetch current balance : ${error.message}`;
}
};
// src/packages/kaiascan/src/accounts/getFTBalance.ts
var getFTBalance = async (parameters, config) => {
let KAIA_KAIASCAN_API_KEY = config.KAIA_KAIASCAN_API_KEY;
let { address, network } = parameters;
network = network ? network.toLowerCase() : "kairos";
validations_default.checkApiKey(KAIA_KAIASCAN_API_KEY);
validations_default.checkAddress(address);
validations_default.checkNetwork(network);
const url = `${API_DEFAULTS.BASE_URL[network]}/accounts/${address}/token-details`;
const response = await fetch(url, {
method: "GET",
headers: {
Accept: "*/*",
Authorization: `Bearer ${KAIA_KAIASCAN_API_KEY}`
}
});
if (!response.ok) {
const error = await response.json();
throw new Error((error == null ? void 0 : error.message) || response.statusText);
}
const data = await response.json();
const totalCount = data.paging.total_count;
let responseText = `Your account has ${totalCount} FTs. They are as follows:
`;
data.results.forEach((item, index) => {
responseText += `${index + 1}. Contract address = ${item.contract.contract_address} | symbol = ${item.contract.symbol} | name = ${item.contract.name} | total supply = ${item.contract.total_supply} | balance = ${item.balance}
`;
});
return responseText;
};
// src/packages/kaiascan/src/accounts/getNFTBalance.ts
var getNFTBalance = async (parameters, config) => {
let KAIA_KAIASCAN_API_KEY = config.KAIA_KAIASCAN_API_KEY;
let { address, network } = parameters;
network = network ? network.toLowerCase() : "kairos";
validations_default.checkApiKey(KAIA_KAIASCAN_API_KEY);
validations_default.checkAddress(address);
validations_default.checkNetwork(network);
const url = `${API_DEFAULTS.BASE_URL[network]}/accounts/${address}/nft-balances/kip17`;
const response = await fetch(url, {
method: "GET",
headers: {
Accept: "*/*",
Authorization: `Bearer ${KAIA_KAIASCAN_API_KEY}`
}
});
if (!response.ok) {
const error = await response.json();
throw new Error((error == null ? void 0 : error.message) || response.statusText);
}
const data = await response.json();
const totalCount = data.paging.total_count;
let responseText = `Your account has ${totalCount} NFT Collections. They are as follows:
`;
data.results.forEach((item, index) => {
responseText += `${index + 1}. Contract address - ${item.contract.contract_address} | Token count - ${item.token_count}
`;
});
return responseText;
};
// src/packages/kaiascan/src/kaiainfo/getKaiaInfo.ts
var getKaiaInfo = async (parameters, config) => {
let KAIA_KAIASCAN_API_KEY = config.KAIA_KAIASCAN_API_KEY;
validations_default.checkApiKey(KAIA_KAIASCAN_API_KEY);
const url = `${API_DEFAULTS.BASE_URL["kaia"]}/kaia`;
const response = await fetch(url, {
method: "GET",
headers: {
Accept: "*/*",
Authorization: `Bearer ${KAIA_KAIASCAN_API_KEY}`
}
});
if (!response.ok) {
const error = await response.json();
throw new Error((error == null ? void 0 : error.message) || response.statusText);
}
const data = await response.json();
let responseText = `Kaia Token Info:
`;
responseText += `- USD Price: ${data.klay_price.usd_price}
`;
responseText += `- BTC Price: ${data.klay_price.btc_price}
`;
responseText += `- USD Price Changes: ${data.klay_price.usd_price_changes}
`;
responseText += `- Market Cap: ${data.klay_price.market_cap}
`;
responseText += `- Total Supply: ${data.klay_price.total_supply}
`;
responseText += `- Volume: ${data.klay_price.volume}
`;
return responseText;
};
// src/packages/kaiascan/src/transactions/getBlockInfo.ts
var getBlockInfo = async (parameters, config) => {
let KAIA_KAIASCAN_API_KEY = config.KAIA_KAIASCAN_API_KEY;
let { blockNumber, network } = parameters;
network = network ? network.toLowerCase() : "kairos";
validations_default.checkApiKey(KAIA_KAIASCAN_API_KEY);
validations_default.checkNetwork(network);
const url = `${API_DEFAULTS.BASE_URL[network]}/blocks/${blockNumber}`;
const response = await fetch(url, {
method: "GET",
headers: {
Accept: "*/*",
Authorization: `Bearer ${KAIA_KAIASCAN_API_KEY}`
}
});
if (!response.ok) {
const error = await response.json();
throw new Error((error == null ? void 0 : error.message) || response.statusText);
}
const data = await response.json();
let blockInfo = `Block Number: ${data.block_id}
`;
blockInfo += `Block Time: ${data.datetime}
`;
blockInfo += `Block Hash: ${data.hash}
`;
blockInfo += `Total Transaction Count: ${data.total_transaction_count}`;
let responseText = `The block info for ${blockNumber} on ${network} is ${blockInfo}`;
return responseText;
};
// src/packages/kaiascan/src/transactions/getLatestBlock.ts
var getLatestBlock = async (parameters, config) => {
let KAIA_KAIASCAN_API_KEY = config.KAIA_KAIASCAN_API_KEY;
let { network } = parameters;
network = network ? network.toLowerCase() : "kairos";
validations_default.checkApiKey(KAIA_KAIASCAN_API_KEY);
validations_default.checkNetwork(network);
const url = `${API_DEFAULTS.BASE_URL[network]}/blocks/latest`;
const response = await fetch(url, {
method: "GET",
headers: {
Accept: "*/*",
Authorization: `Bearer ${KAIA_KAIASCAN_API_KEY}`
}
});
if (!response.ok) {
const error = await response.json();
throw new Error((error == null ? void 0 : error.message) || response.statusText);
}
const data = await response.json();
let responseText = `The latest block number of ${network} is ${data.block_id}`;
return responseText;
};
// src/packages/kaiascan/src/transactions/getTransactionsByAccount.ts
var getTransactionsByAccount = async (parameters, config) => {
let KAIA_KAIASCAN_API_KEY = config.KAIA_KAIASCAN_API_KEY;
let { address, network } = parameters;
network = network ? network.toLowerCase() : "kairos";
validations_default.checkApiKey(KAIA_KAIASCAN_API_KEY);
validations_default.checkAddress(address);
validations_default.checkNetwork(network);
const url = `${API_DEFAULTS.BASE_URL[network]}/accounts/${address}/transactions`;
const response = await fetch(url, {
method: "GET",
headers: {
Accept: "*/*",
Authorization: `Bearer ${KAIA_KAIASCAN_API_KEY}`
}
});
if (!response.ok) {
const error = await response.json();
throw new Error((error == null ? void 0 : error.message) || response.statusText);
}
const data = await response.json();
let accountTransactions = "";
if (data && data.results.length > 0) {
data.results.map((transaction, index) => {
if (index > 5)
return;
accountTransactions += ` -----------------------------------
`;
accountTransactions += `${index + 1}:
`;
accountTransactions += `from: ${transaction.from},
`;
accountTransactions += `to: ${transaction.to},
`;
accountTransactions += `value: ${transaction.amount},
`;
accountTransactions += `type: ${transaction.transaction_type},
`;
accountTransactions += `hash: ${transaction.transaction_hash}
`;
});
} else {
accountTransactions = "No transactions found for this address";
}
let responseText = `The transactions for ${address} account on ${network} is ${accountTransactions}`;
return responseText;
};
// src/packages/kaiascan/src/transactions/getTransactionsByBlockNumber.ts
var getTransactionsByBlockNumber = async (parameters, config) => {
let KAIA_KAIASCAN_API_KEY = config.KAIA_KAIASCAN_API_KEY;
let { blockNumber, network } = parameters;
network = network ? network.toLowerCase() : "kairos";
validations_default.checkApiKey(KAIA_KAIASCAN_API_KEY);
validations_default.checkNetwork(network);
const url = `${API_DEFAULTS.BASE_URL[network]}/transactions?blockNumberStart=${blockNumber}&blockNumberEnd=${blockNumber}`;
const response = await fetch(url, {
method: "GET",
headers: {
Accept: "*/*",
Authorization: `Bearer ${KAIA_KAIASCAN_API_KEY}`
}
});
if (!response.ok) {
const error = await response.json();
throw new Error((error == null ? void 0 : error.message) || response.statusText);
}
const data = await response.json();
let blockTransactions = "";
if (data && data.results.length > 0) {
data.results.map((transaction, index) => {
if (index > 5)
return;
blockTransactions += ` -----------------------------------
`;
blockTransactions += `${index + 1}:
`;
blockTransactions += `from: ${transaction.from},
`;
blockTransactions += `to: ${transaction.to},
`;
blockTransactions += `value: ${transaction.amount},
`;
blockTransactions += `type: ${transaction.transaction_type},
`;
blockTransactions += `hash: ${transaction.transaction_hash}
`;
});
} else {
blockTransactions = "No transactions found for this block";
}
let responseText = `The transactions in a block for ${blockNumber} on ${network} is ${blockTransactions}`;
return responseText;
};
// src/packages/kaiascan/metadata.ts
var metadata_exports = {};
__export(metadata_exports, {
getAccountOverview: () => getAccountOverview2,
getBlockInfo: () => getBlockInfo2,
getCurrentBalance: () => getCurrentBalance2,
getFTBalance: () => getFTBalance2,
getKaiaInfo: () => getKaiaInfo2,
getLatestBlock: () => getLatestBlock2,
getNFTBalance: () => getNFTBalance2,
getTransactionsByAccount: () => getTransactionsByAccount2,
getTransactionsByBlockNumber: () => getTransactionsByBlockNumber2
});
import { z } from "zod";
// src/packages/kaiascan/examples/getAccountOverview.ts
var getAccountOverviewExamples = [
[
{
user: "{{user1}}",
content: {
text: "Tell me about my account."
}
},
{
user: "{{agent}}",
content: {
text: "Which account address would you like to check? Also, please provide the network."
}
},
{
user: "{{user1}}",
content: {
text: "0x840e00ffc46734c3ac97b0e88b1589f83b3874ec"
}
},
{
user: "{{agent}}",
content: {
text: "Noted, since you didn't provide the network, I'll assume it's kaia mainnet. Let me fetch the details for 0x840e00ffc46734c3ac97b0e88b1589f83b3874ec.",
action: "get_account_overview"
}
}
],
[
{
user: "{{user1}}",
content: {
text: "Can you give me an overview of my account?"
}
},
{
user: "{{agent}}",
content: {
text: "Sure, which account address would you like to check?"
}
},
{
user: "{{user1}}",
content: {
text: "0x840e00ffc46734c3ac97b0e88b1589f83b3874ec"
}
},
{
user: "{{agent}}",
content: {
text: "Let me fetch the details for 0x840e00ffc46734c3ac97b0e88b1589f83b3874ec on kaia mainnet.",
action: "get_account_overview"
}
}
],
[
{
user: "{{user1}}",
content: {
text: "What's the overview of 0x840e00ffc46734c3ac97b0e88b1589f83b3874ec on kairos?"
}
},
{
user: "{{agent}}",
content: {
text: "I'll get the account details for 0x840e00ffc46734c3ac97b0e88b1589f83b3874ec on kairos network.",
action: "get_account_overview"
}
}
],
[
{
user: "{{user1}}",
content: {
text: "Can you show me the details of my portfolio?"
}
},
{
user: "{{agent}}",
content: {
text: "Which account address would you like to check?"
}
},
{
user: "{{user1}}",
content: {
text: "0x840e00ffc46734c3ac97b0e88b1589f83b3874ec on kairos network."
}
},
{
user: "{{agent}}",
content: {
text: "Fetching the portfolio details for 0x840e00ffc46734c3ac97b0e88b1589f83b3874ec on kairos network.",
action: "get_account_overview"
}
}
]
];
// src/packages/kaiascan/examples/getBlock.ts
var getBlockExamples = [
[
{
user: "{{user1}}",
content: {
text: "What's is the block info of 12345 like right now?"
}
},
{
user: "{{agent}}",
content: {
text: "In which network?"
}
},
{
user: "{{user1}}",
content: {
text: "kairos"
}
},
{
user: "{{agent}}",
content: {
text: "Let me check the latest block info in kairos for you.",
action: "GET_BLOCK"
}
},
{
user: "{{agent}}",
content: {
text: "It's Block Number: 1234 \n Block Time: 10/10/2025 \n Block Hash: 0x742d35Cc6634C0532925a3b844Bc454e4438f44e \n Block Size: 123. Please explore kaia ecosystem."
}
}
],
[
{
user: "{{user1}}",
content: {
text: "What's the block info for 12345 on kaia?"
}
},
{
user: "{{agent}}",
content: {
text: "I'll check the block info for 12345 in kaia for you.",
action: "GET_BLOCK"
}
},
{
user: "{{agent}}",
content: {
text: "It's Block Number: 1234 \n Block Time: 10/10/2025 \n Block Hash: 0x742d35Cc6634C0532925a3b844Bc454e4438f44e \n Block Size: 123. and can explore kaia minidapps."
}
}
]
];
// src/packages/kaiascan/examples/getCurrentBalance.ts
var getCurrentBalanceExamples = [
[
{
user: "{{user1}}",
content: {
text: "What's the kaia balance like right now?"
}
},
{
user: "{{agent}}",
content: {
text: "In which address?"
}
},
{
user: "{{user1}}",
content: {
text: "0x4d69770905f43c07d4085dfd296a03484d05280f"
}
},
{
user: "{{agent}}",
content: {
text: "Let me check the current balance in 0x4d69770905f43c07d4085dfd296a03484d05280f for you.",
action: "GET_CURRENT_BALANCE"
}
}
],
[
{
user: "{{user1}}",
content: {
text: "What's the balance of 0x4d69770905f43c07d4085dfd296a03484d05280f?"
}
},
{
user: "{{agent}}",
content: {
text: "I'll check the current balance in 0x4d69770905f43c07d4085dfd296a03484d05280f for you.",
action: "GET_CURRENT_BALANCE"
}
}
],
[
{
user: "{{user1}}",
content: {
text: "Is there any funds in 0x4d69770905f43c07d4085dfd296a03484d05280f?"
}
},
{
user: "{{agent}}",
content: {
text: "I'll check the current balance in 0x4d69770905f43c07d4085dfd296a03484d05280f.",
action: "GET_CURRENT_BALANCE"
}
}
]
];
// src/packages/kaiascan/examples/getFTBalanceDetails.ts
var getFTBalanceDetailsExamples = [
[
{
user: "{{user1}}",
content: {
text: "What's the fungible token balance of 0x4d69770905f43c07d4085dfd296a03484d05280f?"
}
},
{
user: "{{agent}}",
content: {
text: "I'll check the fungible token balance in 0x4d69770905f43c07d4085dfd296a03484d05280f for you.",
action: "GET_FT_BALANCE_DETAILS"
}
}
],
[
{
user: "{{user1}}",
content: {
text: "How many FT tokens are in 0x4d69770905f43c07d4085dfd296a03484d05280f?"
}
},
{
user: "{{agent}}",
content: {
text: "Let me see how many FT tokens are in 0x4d69770905f43c07d4085dfd296a03484d05280f.",
action: "GET_FT_BALANCE_DETAILS"
}
}
],
[
{
user: "{{user1}}",
content: {
text: "What's the balance of 0x4d69770905f43c07d4085dfd296a03484d05280f on kaia mainnet?"
}
},
{
user: "{{agent}}",
content: {
text: "I'll check the fungible token balance in 0x4d69770905f43c07d4085dfd296a03484d05280f on kaia mainnet for you.",
action: "GET_FT_BALANCE_DETAILS"
}
}
]
];
// src/packages/kaiascan/examples/getKaiaInfo.ts
var getKaiaInfoExamples = [
[
{
user: "{{user1}}",
content: {
text: "Can you give me overview of kaia?"
}
},
{
user: "{{agent}}",
content: {
text: "Sure, let me fetch the Kaia details for you.",
action: "GET_KAIA_INFO"
}
}
],
[
{
user: "{{user1}}",
content: {
text: "Can you tell me the Kaia price details?"
}
},
{
user: "{{agent}}",
content: {
text: "Sure, let me fetch the Kaia price details for you.",
action: "GET_KAIA_INFO"
}
}
],
[
{
user: "{{user1}}",
content: {
text: "What's the current market cap of Kaia?"
}
},
{
user: "{{agent}}",
content: {
text: "Let me check the current market cap of Kaia for you.",
action: "GET_KAIA_INFO"
}
}
],
[
{
user: "{{user1}}",
content: {
text: "How much is the total supply of Kaia?"
}
},
{
user: "{{agent}}",
content: {
text: "I'll check the total supply of Kaia for you.",
action: "GET_KAIA_INFO"
}
}
],
[
{
user: "{{user1}}",
content: {
text: "Can you provide the volume of Kaia?"
}
},
{
user: "{{agent}}",
content: {
text: "Let me fetch the volume of Kaia for you.",
action: "GET_KAIA_INFO"
}
}
]
];
// src/packages/kaiascan/examples/getLatestBlock.ts
var getLatestBlockExamples = [
[
{
user: "{{user1}}",
content: {
text: "What's is the latest block number like right now?"
}
},
{
user: "{{agent}}",
content: {
text: "In which network?",
action: "NONE"
}
},
{
user: "{{user1}}",
content: {
text: "kairos"
}
},
{
user: "{{agent}}",
content: {
text: "Let me check the latest block number in kairos for you.",
action: "GET_LATEST_BLOCK"
}
},
{
user: "{{agent}}",
content: {
text: "It's currently 1000000 block height. You can check the latest block number in kaia as well."
}
}
],
[
{
user: "{{user1}}",
content: {
text: "What's the latest block number of kaia?"
}
},
{
user: "{{agent}}",
content: {
text: "I'll check the current block height in kaia for you.",
action: "GET_LATEST_BLOCK"
}
},
{
user: "{{agent}}",
content: {
text: "It's currently 10000000 block height and can explore kaia minidapps."
}
}
]
];
// src/packages/kaiascan/examples/getNFTBalance.ts
var getNFTBalanceExamples = [
[
{
user: "{{user1}}",
content: {
text: "What's the NFT balance of 0x4d69770905f43c07d4085dfd296a03484d05280f?"
}
},
{
user: "{{agent}}",
content: {
text: "I'll check the NFT balance in 0x4d69770905f43c07d4085dfd296a03484d05280f for you.",
action: "GET_NFT_BALANCE"
}
}
],
[
{
user: "{{user1}}",
content: {
text: "Which NFTs are in 0x1a2b3c4d5e6f7g8h9i0j1k2l3m4n5o6p7q8r9s0t?"
}
},
{
user: "{{agent}}",
content: {
text: "Let me see which NFTs are in 0x1a2b3c4d5e6f7g8h9i0j1k2l3m4n5o6p7q8r9s0t.",
action: "GET_NFT_BALANCE"
}
}
],
[
{
user: "{{user1}}",
content: {
text: "What's the balance of 0x5e6f7g8h9i0j1k2l3m4n5o6p7q8r9s0t1u2v3w4 on kaia mainnet?"
}
},
{
user: "{{agent}}",
content: {
text: "I'll check the NFT balance in 0x5e6f7g8h9i0j1k2l3m4n5o6p7q8r9s0t1u2v3w4 on kaia mainnet for you.",
action: "GET_NFT_BALANCE"
}
}
],
[
{
user: "{{user1}}",
content: {
text: "What's the non fungible tokens balance of 0x9i0j1k2l3m4n5o6p7q8r9s0t1u2v3w4x5y6z7a8 on kaia mainnet?"
}
},
{
user: "{{agent}}",
content: {
text: "I'll check the non fungible tokens balance in 0x9i0j1k2l3m4n5o6p7q8r9s0t1u2v3w4x5y6z7a8 on kaia mainnet for you.",
action: "GET_NFT_BALANCE"
}
}
]
];
// src/packages/kaiascan/examples/getTransactionsByAccount.ts
var getTransactionsByAccountExamples = [
[
{
user: "{{user1}}",
content: {
text: "What's are the transactions for address 0x742d35Cc6634C0532925a3b844Bc454e4438f44e like right now?"
}
},
{
user: "{{agent}}",
content: {
text: "In which network?"
}
},
{
user: "{{user1}}",
content: {
text: "kairos"
}
},
{
user: "{{agent}}",
content: {
text: "Let me check the transactions for address 0x742d35Cc6634C0532925a3b844Bc454e4438f44e in kairos for you.",
action: "GET_TRANSACTIONS_BY_ACCOUNT"
}
},
{
user: "{{agent}}",
content: {
text: "It's Block Number: 1234 \n Block Time: 10/10/2025 \n Block Hash: 0x742d35Cc6634C0532925a3b844Bc454e4438f44e \n Block Size: 123. Please explore kaia ecosystem."
}
}
],
[
{
user: "{{user1}}",
content: {
text: "What's the list of transactions for address 0x742d35Cc6634C0532925a3b844Bc454e4438f44e on kaia?"
}
},
{
user: "{{agent}}",
content: {
text: "I'll check the address 0x742d35Cc6634C0532925a3b844Bc454e4438f44e for transactions in kaia for you.",
action: "GET_BLOCK"
}
},
{
user: "{{agent}}",
content: {
text: "It's Block Number: 1234 \n Block Time: 10/10/2025 \n Block Hash: 0x742d35Cc6634C0532925a3b844Bc454e4438f44e \n Block Size: 123. and can explore kaia minidapps."
}
}
]
];
// src/packages/kaiascan/examples/getTransactionsByBlock.ts
var getTransactionsByBlockExamples = [
[
{
user: "{{user1}}",
content: {
text: "What's are the transactions in block 12345 like right now?"
}
},
{
user: "{{agent}}",
content: {
text: "In which network?"
}
},
{
user: "{{user1}}",
content: {
text: "kairos"
}
},
{
user: "{{agent}}",
content: {
text: "Let me check the transactions in block 12345 in kairos for you.",
action: "GET_BLOCK"
}
},
{
user: "{{agent}}",
content: {
text: "It's Block Number: 1234 \n Block Time: 10/10/2025 \n Block Hash: 0x23kdhjsfsdkhfkjhkjhdf \n Block Size: 123. Please explore kaia ecosystem."
}
}
],
[
{
user: "{{user1}}",
content: {
text: "What's the list of transactions in block for 12345 on kaia?"
}
},
{
user: "{{agent}}",
content: {
text: "I'll check the block 12345 for transactions in kaia for you.",
action: "GET_BLOCK"
}
},
{
user: "{{agent}}",
content: {
text: "It's Block Number: 1234 \n Block Time: 10/10/2025 \n Block Hash: 0x23kdhjsfsdkhfkjhkjhdf \n Block Size: 123. and can explore kaia minidapps."
}
}
]
];
// src/packages/kaiascan/metadata.ts
var getAccountOverview2 = {
name: "get_account_overview",
description: "Get the Account Overview for a given address and network (kaia or kairos)",
params: z.object({
address: z.string(),
network: z.string()
}),
similes: ["get_account_overview"],
validate: async () => true,
examples: getAccountOverviewExamples
};
var getCurrentBalance2 = {
name: "get_current_balance",
description: "Get the current balance for a given address and network (kaia or kairos)",
params: z.object({
address: z.string(),
network: z.string()
}),
similes: ["get_current_balance"],
validate: async () => true,
examples: getCurrentBalanceExamples
};
var getFTBalance2 = {
name: "get_ft_balance",
description: "Get the Fungible token or ft or erc20 or kip 7 balances for a given address and network",
params: z.object({
address: z.string(),
network: z.string()
}),
similes: ["get_ft_balance"],
validate: async () => true,
examples: getFTBalanceDetailsExamples
};
var getNFTBalance2 = {
name: "get_nft_balance_details",
description: "Get the Non-Fungible token or nft or erc721 or kip17 balances for a given address and network (kaia or kairos)",
params: z.object({
address: z.string(),
network: z.string()
}),
similes: ["get_nft_balance_details"],
validate: async () => true,
examples: getNFTBalanceExamples
};
var getKaiaInfo2 = {
name: "get_kaia_info",
description: "Get the kaia current info or kaia overview about Kaia Token or gets current kaia price",
params: z.object({}),
similes: ["get_kaia_info"],
validate: async () => true,
examples: getKaiaInfoExamples
};
var getBlockInfo2 = {
name: "get_block_info",
description: "Get the block info for a given block number and network (kaia or kairos)",
params: z.object({
blockNumber: z.number(),
network: z.string()
}),
similes: ["get_block_info"],
validate: async () => true,
examples: getBlockExamples
};
var getLatestBlock2 = {
name: "get_latest_block",
description: "Get the latest block number or block height for a given network (kaia or kairos)",
params: z.object({
network: z.string()
}),
similes: ["get_latest_block"],
validate: async () => true,
examples: getLatestBlockExamples
};
var getTransactionsByAccount2 = {
name: "get_transactions_by_account",
description: "Get the transactions for given address and network (kaia or kairos)",
params: z.object({
address: z.string(),
network: z.string()
}),
similes: ["get_transactions_by_account"],
validate: async () => true,
examples: getTransactionsByAccountExamples
};
var getTransactionsByBlockNumber2 = {
name: "get_transactions_by_block_number",
description: "Get the transactions for given block number and network (kaia or kairos)",
params: z.object({
blockNumber: z.number(),
network: z.string()
}),
similes: ["get_transactions_by_block_number"],
validate: async () => true,
examples: getTransactionsByBlockExamples
};
// src/packages/web3/index.ts
var web3_exports = {};
__export(web3_exports, {
Metadata: () => metadata_exports2,
Services: () => services_exports2
});
// src/packages/web3/services.ts
var services_exports2 = {};
__export(services_exports2, {
transferErc1155: () => transferErc1155,
transferErc20: () => transferErc20,
transferErc721: () => transferErc721,
transferFaucet: () => transferFaucet,
transferNativeToken: () => transferNativeToken
});
// src/packages/web3/utils/token.ts
import assert from "assert";
import { encodeFunctionData } from "viem";
var AbiFactory = class {
constructor(params) {
this.params = params;
}
getErc20Params() {
const abi = [
{
constant: false,
inputs: [
{
name: "_to",
type: "address"
},
{
name: "_value",
type: "uint256"
}
],
name: "transfer",
outputs: [
{
name: "",
type: "bool"
}
],
type: "function"
}
];
assert(
this.params.receiver && this.params.amount,
"invalid params for transfer erc20"
);
const args = [this.params.receiver, this.params.amount];
const functionName = "transfer";
return { abi, args, functionName };
}
getErc721Params() {
const abi = [
{
constant: false,
inputs: [
{ "name": "from", "type": "address" },
{
name: "_to",
type: "address"
},
{
name: "_tokenId",
type: "uint256"
}
],
name: "transferFrom",
outputs: [],
type: "function"
}
];
assert(
this.params.sender && this.params.receiver && this.params.tokenId,
"invalid params for transfer erc721"
);
const args = [
this.params.sender,
this.params.receiver,
this.params.tokenId
];
const functionName = "transferFrom";
return { abi, args, functionName };
}
getErc1155Params() {
const abi = [
{
constant: false,
inputs: [
{
name: "from",
type: "address"
},
{
name: "to",
type: "address"
},
{
name: "id",
type: "uint256"
},
{
name: "amount",
type: "uint256"
},
{
name: "data",
type: "bytes"
}
],
name: "safeTransferFrom",
outputs: [],
stateMutability: "nonpayable",
type: "function"
}
];
assert(
this.params.sender && this.params.receiver && this.params.tokenId && this.params.amount,
"invalid params for transfer erc1155"
);
const args = [
this.params.sender,
this.params.receiver,
this.params.tokenId,
this.params.amount,
""
];
const functionName = "safeTransferFrom";
return { abi, args, functionName };
}
createParams() {
let params;
switch (this.params.type) {
case "erc20":
params = this.getErc20Params();
break;
case "erc721":
params = this.getErc721Params();
break;
case "erc1155":
params = this.getErc1155Params();
break;
default:
throw new Error("Unsupported token type");
}
const { abi, args, functionName } = params;
return encodeFunctionData({
abi,
functionName,
args
});
}
};
// src/packages/web3/src/transferErc20.ts
import { isKlaytnAccountKeyType, TxType } from "@kaiachain/ethers-ext";
import { keccak256 } from "viem";
// src/packages/web3/utils/helper.ts
async function getAccount(walletClient, sender) {
if (walletClient.provider) {
walletClient = walletClient.provider;
}
if (walletClient.send) {
return await walletClient.send("kaia_getAccount", [sender, "latest"]);
} else if (walletClient.request) {
return await walletClient.request({
method: "kaia_getAccount",
params: [sender, "latest"]
});
}
}
// src/packages/web3/src/transferErc20.ts
async function getContractDecimals(contractAddress, walletClient) {
try {
if (walletClient.call) {
const functionSignature = new TextEncoder().encode("decimals()");
const functionHash = keccak256(functionSignature);
const selector = functionHash.slice(0, 10);
const result = await walletClient.call({
to: contractAddress,
data: selector
});
const decimals = parseInt(result, 16);
return decimals;
} else if (walletClient.read) {
const result = await walletClient.read({
address: contractAddress,
abi: [
{
constant: true,
inputs: [],
name: "decimals",
outputs: [
{
name: "",
type: "uint8"
}
],
payable: false,
stateMutability: "view",
type: "function"
}
],
functionName: "decimals",
args: []
});
return (result == null ? void 0 : result.value) || 18;
} else {
throw new Error("Problem calculating the decimals");
}
} catch (err) {
console.error("Error fetching decimals:", err);
throw err;
}
}
var transferErc20 = async (parameters, config, walletClient) => {
var _a, _b;
try {
const sender = walletClient.address || ((_a = walletClient.account) == null ? void 0 : _a.address) || walletClient.getAddress();
const accountType = await await getAccount(
walletClient,
sender
);
parameters.sender = sender;
parameters.amount = await getContractDecimals(
parameters.contractAddress,
walletClient
);
const res = {
from: sender,
to: parameters.contractAddress,
data: new AbiFactory(__spreadProps(__spreadValues({}, parameters), {
type: "erc20"
})).createParams(),
type: void 0
};
if (((_b = walletClient.provider) == null ? void 0 : _b.kaia) && isKlaytnAccountKeyType(accountType.accType)) {
res.type = TxType.SmartContractExecution;
}
const sentTx = await walletClient.sendTransaction(res);
return {
transactionHash: sentTx.hash || sentTx
};
} catch (err) {
console.log(err);
throw err;
}
};
// src/packages/web3/src/transferErc721.ts
import { isKlaytnAccountKeyType as isKlaytnAccountKeyType2, TxType as TxType2 } from "@kaiachain/ethers-ext";
var transferErc721 = async (parameters, config, walletClient) => {
var _a, _b;
try {
const sender = walletClient.address || ((_a = walletClient.account) == null ? void 0 : _a.address) || walletClient.getAddress();
const accountType = await await getAccount(
walletClient,
sender
);
parameters.sender = sender;
const res = {
from: sender,
to: parameters.contractAddress,
data: new AbiFactory(__spreadProps(__spreadValues({}, parameters), {
type: "erc721"
})).createParams(),
type: void 0
};
if (((_b = walletClient.provider) == null ? void 0 : _b.kaia) && isKlaytnAccountKeyType2(accountType.accType)) {
res.type = TxType2.SmartContractExecution;
}
const sentTx = await walletClient.sendTransaction(res);
return {
transactionHash: sentTx.hash || sentTx
};
} catch (err) {
console.log(err);
throw err;
}
};
// src/packages/web3/src/transferErc1155.ts
import { isKlaytnAccountKeyType as isKlaytnAccountKeyType3, TxType as TxType3 } from "@kaiachain/ethers-ext";
var transferErc1155 = async (parameters, config, walletClient) => {
var _a, _b;
try {
const sender = walletClient.address || ((_a = walletClient.account) == null ? void 0 : _a.address) || walletClient.getAddress();
const accountType = await await getAccount(
walletClient,
sender
);
parameters.sender = sender;
const res = {
from: parameters.sender,
to: parameters.contractAddress,
data: new AbiFactory(__spreadProps(__spreadValues({}, parameters), {
type: "erc1155"
})).createParams(),
type: void 0
};
if (((_b = walletClient.provider) == null ? void 0 : _b.kaia) && isKlaytnAccountKeyType3(accountType.accType)) {
res.type = TxType3.SmartContractExecution;
}
const sentTx = await walletClient.sendTransaction(res);
return {
transactionHash: sentTx.hash || sentTx
};
} catch (err) {
console.log(err);
throw err;
}
};
// src/packages/web3/src/transferNativeToken.ts
import { isKlaytnAccountKeyType as isKlaytnAccountKeyType4, TxType as TxType4 } from "@kaiachain/ethers-ext";
import { parseEther } from "viem";
var transferNativeToken = async (parameters, config, walletClient) => {
var _a, _b;
try {
const sender = walletClient.address || ((_a = walletClient.account) == null ? void 0 : _a.address) || walletClient.getAddress();
const accountType = await await getAccount(
walletClient,
sender
);
parameters.sender = sender;
const res = {
from: parameters.sender,
to: parameters.receiver,
value: parseEther(parameters.amount.toString()),
type: void 0
};
if (((_b = walletClient.provider) == null ? void 0 : _b.kaia) && isKlaytnAccountKeyType4(accountType.accType)) {
res.type = TxType4.ValueTransfer;
}
const sentTx = await walletClient.sendTransaction(res);
return {
transactionHash: sentTx.hash || sentTx
};
} catch (err) {
console.log(err);
throw err;
}
};
// src/packages/web3/src/transferFaucet.ts
import { isKlaytnAccountKeyType as isKlaytnAccountKeyType5, TxType as TxType5 } from "@kaiachain/ethers-ext";
import { parseEther as parseEther2 } from "viem";
// src/packages/web3/utils/validations.ts
import { isAddress as isAddress2 } from "viem";
var validations2 = {};
validations2.checkApiKey = (apiKey) => {
if (!apiKey) {
throw new Error("Missing API key");
}
};
validations2.checkAddress = (address) => {
return isAddress2(address);
};
validations2.checkNetwork = (network) => {
if (network !== "kairos" && network !== "kaia") {
throw new Error("Invalid network");
}
};
var validations_default2 = validations2;
// src/packages/web3/src/transferFaucet.ts
var DEFAULT_KAIROS_FAUCET_AMOUNT = "1";
var transferFaucet = async (parameters, config, walletClient) => {
var _a, _b;
try {
let KAIROS_FAUCET_AMOUNT = config.KAIROS_FAUCET_AMOUNT || DEFAULT_KAIROS_FAUCET_AMOUNT;
const sender = walletClient.address || ((_a = walletClient.account) == null ? void 0 : _a.address) || walletClient.getAddress();
const accountType = await getAccount(
walletClient,
sender
);
parameters.sender = sender;
validations_default2.checkAddress(sender);
validations_default2.checkAddress(parameters.receiver);
const res = {
from: sender,
to: parameters.receiver,
value: parseEther2(KAIROS_FAUCET_AMOUNT.toString())
};
if (((_b = walletClient.provider) == null ? void 0 : _b.kaia) && isKlaytnAccountKeyType5(accountType == null ? void 0 : accountType.accType)) {
res.type = TxType5.ValueTransfer;
}
const sentTx = await walletClient.sendTransaction(res);
return {
transactionHash: sentTx.hash || sentTx
};
} catch (err) {
console.log(err);
throw err;
}
};
// src/packages/web3/metadata.ts
var metadata_exports2 = {};
__export(metadata_exports2, {
transferErc1155: () => transferErc11552,
transferErc20: () => transferErc202,
transferErc721: () => transferErc7212,
transferFaucet: () => transferFaucet2,
transferNativeToken: () => transferNativeToken2
});
import { z as z2 } from "zod";
// src/packages/web3/examples/faucet.ts
var faucetExamples = [
[
{
user: "user",
content: {
text: "Transfer some faucet kaia testnet tokens to 0x742d35Cc6634C0532925a3b844Bc454e4438f44e",
action: "FAUCET"
}
},
{
user: "assistant",
content: {
text: "I'll help you send some Kaia testnet tokens to 0x742d35Cc6634C0532925a3b844Bc454e4438f44e",
action: "FAUCET"
}
}
],
[
{
user: "{{user1}}",
content: {
text: "Can i get some test tokens to 0x4d69770905f43c07d4085dfd296a03484d05280f?"
}
},
{
user: "{{agent}}",
content: {
text: "let me transfer test tokens to 0x4d69770905f43c07d4085dfd296a03484d05280f for you.",
action: "FAUCET"
}
}
],
[
{
user: "{{user1}}",
content: {
text: "Can i get faucets to 0x4d69770905f43c07d4085dfd296a03484d05280f?"
}
},
{
user: "{{agent}}",
content: {
text: "let me transfer some test tokens to 0x4d69770905f43c07d4085dfd296a03484d05280f for you.",
action: "FAUCET"
}
}
]
];
// src/packages/web3/examples/transfer.ts
var transferExamples = [
[
{
user: "user",
content: {
text: "Transfer 1 ETH to 0x742d35Cc6634C0532925a3b844Bc454e4438f44e",
action: "SEND_TOKENS"
}
},
{
user: "assistant",
content: {
text: "I'll help you transfer 1 ETH to 0x742d35Cc6634C0532925a3b844Bc454e4438f44e",
action: "SEND_TOKENS"
}
}
]
];
// src/packages/web3/metadata.ts
var transferFaucet2 = {
name: "transfer_test_kaia_coins",
description: "transfer test kaia coins for a given receiver address",
params: z2.object({
receiver: z2.string()
}),
similes: ["transfer_test_kaia_coins"],
validate: async () => true,
examples: faucetExamples
};
var transferErc202 = {
name: "transfer_erc20",
description: "transfer erc20/FT/Fungible token for a given receiver address, amount and contract address",
params: z2.object({
receiver: z2.string(),
amount: z2.number(),
contractAddress: z2.string(),
network: z2.enum(["kaia", "kairos"])
}),
similes: ["transfer_erc20"],
validate: async () => true,
examples: []
};
var transferErc7212 = {
name: "transfer_erc721",
description: "transfer erc721/NFT/NonFungible token for a given receiver address, tokenId and contract address",
params: z2.object({
receiver: z2.string(),
tokenId: z2.string(),
contractAddress: z2.string(),
network: z2.enum(["kaia", "kairos"])
}),
similes: ["transfer_erc721"],
validate: async () => true,
examples: []
};
var transferErc11552 = {
name: "transfer_erc1155",
description: "transfer erc1155/multi token for a given receiver address, tokenId, amount and contract address",
params: z2.object({
receiver: z2.string(),
amount: z2.number(),
tokenId: z2.string(),
contractAddress: z2.string(),
network: z2.enum(["kaia", "kairos"])
}),
similes: ["transfer_erc1155"],
validate: async () => true,
examples: []
};
var transferNativeToken2 = {
name: "transfer_native_token",
description: "transfer native token for a given receiver address, amount and network",
params: z2.object({
receiver: z2.string(),
amount: z2.number(),
network: z2.enum(["kaia", "kairos"])
}),
similes: ["transfer_native_token"],
validate: async () => true,
examples: [transferExamples]
};
// src/packages/dgswap/index.ts
var dgswap_exports = {};
__export(dgswap_exports, {
Metadata: () => metadata_exports3,
Services: () => services_exports3
});
// src/packages/dgswap/services.ts
var services_exports3 = {};
__export(services_exports3, {
getPoolByTokenAddress: () => getPoolByTokenAddress,
getPoolByTokenSymbol: () => getPoolByTokenSymbol,
getPoolDayData: () => getPoolDayData,
getTokenDayData: () => getTokenDayData
});
// src/packages/dgswap/utils/gql.ts
var endpoint = "https://thegraph.com/explorer/api/playground/QmPxcJiVTvEJST2tEeeGUWTfcHZFus9o7MZQyUxTJyFfzs";
var queryGql = async (query, variables) => {
const res = await fetch(endpoint, {
method: "POST",
headers: {
"Content-type": "application/json"
},
body: JSON.stringify({
query,
variables
})
});
const { data, error } = await res.json();
if (error) {
console.log(error);
throw new Error("Unable to fetch data");
}
return data;
};
// src/packages/dgswap/src/pool/getPoolByTokenSymbol.ts
var GET_POOLS = `
query GetPools($symbol0: String!, $symbol1: String!) {
pools(
first: 1
where: {
or: [
{ token0_: { symbol: $symbol0 }, token1_: { symbol: $symbol1 } }
{ token0_: { symbol: $symbol1 }, token1_: { symbol: $symbol0 } }
]
}
) {
id
createdAtTimestamp
token0Price
token1Price
token0 {
derivedUSD
id
name
symbol
decimals
}
token1 {
id
derivedUSD
name
symbol
decimals
}
}
}
`;
var getPoolByTokenSymbol = async (parameters) => {
const { symbol0, symbol1 } = parameters;
const { pools = [] } = await queryGql(GET_POOLS, { symbol0, symbol1 });
if (pools.length === 0) {
throw new Error("No pool found");
}
return pools[0];
};
// src/packages/dgswap/src/pool/getPoolByTokenAddress.ts
var GET_POOLS2 = `
query GetPools($token0Address: String!, $token1Address: String!) {
pools(
first: 1
where: {
or: [
{ token0_: { id: $token0Address }, token1_: { id: $token1Address } }
{ token0_: { id: $token1Address }, token1_: { id: $token0Address } }
]
}
) {
id
createdAtTimestamp
token0Price
token1Price
token0 {
derivedUSD
id
name
symbol
decimals
}
token1 {
id
derivedUSD
name
symbol
decimals
}
}
}
`;
var getPoolByTokenAddress = async (parameters) => {
const { token0Address, token1Address } = parameters;
const { pools = [] } = await queryGql(GET_POOLS2, {
token0Address,
token1Address
});
if (pools.length === 0) {
throw new Error("No pool found");
}
return pools[0];
};
// src/packages/dgswap/src/data/getPoolDayData.ts
var GET_POOL_DAY_DATA = `
query PoolDayDatas(
$count: Int!
$poolAddress: String!
) {
poolDayDatas(
first: $count
where: { pool: $poolAddress }
) {
id
date
liquidity
token0Price
token1Price
open
close
high
low
}
}`;
var getPoolDayData = async (parameters) => {
const { poolAddress, count } = parameters;
const { poolDayDatas = [] } = await queryGql(GET_POOL_DAY_DATA, { poolAddress, count });
return poolDayDatas;
};
// src/packages/dgswap/src/data/getTokenDayData.ts
var GET_TOKEN_DAY_DATA = `
query tokenDayDatas(
$count: Int!
$tokenAddress: String!
) {
tokenDayDatas(
first: $count,
where:{
token :$tokenAddress
}
){
id
date
volumeUSD
volume
priceUSD
open
close
high
low
}
}`;
var getTokenDayData = async (parameters) => {
const { tokenAddress, count } = parameters;
const { tokenDayDatas = [] } = await queryGql(GET_TOKEN_DAY_DATA, {
tokenAddress,
count
});
return tokenDayDatas;
};
// src/packages/dgswap/metadata.ts
var metadata_exports3 = {};
__export(metadata_exports3, {