basileus-agentkit-plugin 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.nvmrc +1 -0
- package/.prettierrc +7 -0
- package/dist/actions/aleph.d.ts +2 -0
- package/dist/actions/aleph.js +114 -0
- package/dist/actions/aleph.js.map +1 -0
- package/dist/actions/compound/compoundActionProvider.d.ts +2 -0
- package/dist/actions/compound/compoundActionProvider.js +130 -0
- package/dist/actions/compound/compoundActionProvider.js.map +1 -0
- package/dist/actions/compound/constants.d.ts +194 -0
- package/dist/actions/compound/constants.js +134 -0
- package/dist/actions/compound/constants.js.map +1 -0
- package/dist/actions/compound/index.d.ts +1 -0
- package/dist/actions/compound/index.js +2 -0
- package/dist/actions/compound/index.js.map +1 -0
- package/dist/actions/compound/schemas.d.ts +42 -0
- package/dist/actions/compound/schemas.js +41 -0
- package/dist/actions/compound/schemas.js.map +1 -0
- package/dist/actions/compound/utils.d.ts +15 -0
- package/dist/actions/compound/utils.js +260 -0
- package/dist/actions/compound/utils.js.map +1 -0
- package/dist/actions/constants.d.ts +69 -0
- package/dist/actions/constants.js +50 -0
- package/dist/actions/constants.js.map +1 -0
- package/dist/actions/index.d.ts +2 -0
- package/dist/actions/index.js +3 -0
- package/dist/actions/index.js.map +1 -0
- package/dist/agent-loop.d.ts +14 -0
- package/dist/agent-loop.js +60 -0
- package/dist/agent-loop.js.map +1 -0
- package/dist/aleph-publisher.d.ts +9 -0
- package/dist/aleph-publisher.js +41 -0
- package/dist/aleph-publisher.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/summarizer.d.ts +3 -0
- package/dist/summarizer.js +21 -0
- package/dist/summarizer.js.map +1 -0
- package/dist/tools.d.ts +6 -0
- package/dist/tools.js +30 -0
- package/dist/tools.js.map +1 -0
- package/dist/types.d.ts +15 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/wallet.d.ts +17520 -0
- package/dist/wallet.js +47 -0
- package/dist/wallet.js.map +1 -0
- package/dist/x402-tracker.d.ts +2 -0
- package/dist/x402-tracker.js +39 -0
- package/dist/x402-tracker.js.map +1 -0
- package/eslint.config.js +26 -0
- package/package.json +86 -0
- package/src/actions/aleph.ts +145 -0
- package/src/actions/compound/compoundActionProvider.ts +166 -0
- package/src/actions/compound/constants.ts +140 -0
- package/src/actions/compound/index.ts +1 -0
- package/src/actions/compound/schemas.ts +45 -0
- package/src/actions/compound/utils.ts +367 -0
- package/src/actions/constants.ts +53 -0
- package/src/actions/index.ts +2 -0
- package/src/agent-loop.ts +93 -0
- package/src/aleph-publisher.ts +44 -0
- package/src/index.ts +11 -0
- package/src/summarizer.ts +30 -0
- package/src/tools.ts +40 -0
- package/src/types.ts +17 -0
- package/src/wallet.ts +73 -0
- package/src/x402-tracker.ts +43 -0
- package/tsconfig.json +15 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const CompoundSupplySchema: z.ZodObject<{
|
|
3
|
+
assetId: z.ZodEnum<["weth", "cbeth", "cbbtc", "wsteth", "usdc"]>;
|
|
4
|
+
amount: z.ZodString;
|
|
5
|
+
}, "strip", z.ZodTypeAny, {
|
|
6
|
+
amount: string;
|
|
7
|
+
assetId: "weth" | "cbeth" | "cbbtc" | "wsteth" | "usdc";
|
|
8
|
+
}, {
|
|
9
|
+
amount: string;
|
|
10
|
+
assetId: "weth" | "cbeth" | "cbbtc" | "wsteth" | "usdc";
|
|
11
|
+
}>;
|
|
12
|
+
export declare const CompoundWithdrawSchema: z.ZodObject<{
|
|
13
|
+
assetId: z.ZodEnum<["weth", "cbeth", "cbbtc", "wsteth", "usdc"]>;
|
|
14
|
+
amount: z.ZodString;
|
|
15
|
+
}, "strip", z.ZodTypeAny, {
|
|
16
|
+
amount: string;
|
|
17
|
+
assetId: "weth" | "cbeth" | "cbbtc" | "wsteth" | "usdc";
|
|
18
|
+
}, {
|
|
19
|
+
amount: string;
|
|
20
|
+
assetId: "weth" | "cbeth" | "cbbtc" | "wsteth" | "usdc";
|
|
21
|
+
}>;
|
|
22
|
+
export declare const CompoundBorrowSchema: z.ZodObject<{
|
|
23
|
+
assetId: z.ZodEnum<["weth", "usdc"]>;
|
|
24
|
+
amount: z.ZodString;
|
|
25
|
+
}, "strip", z.ZodTypeAny, {
|
|
26
|
+
amount: string;
|
|
27
|
+
assetId: "weth" | "usdc";
|
|
28
|
+
}, {
|
|
29
|
+
amount: string;
|
|
30
|
+
assetId: "weth" | "usdc";
|
|
31
|
+
}>;
|
|
32
|
+
export declare const CompoundRepaySchema: z.ZodObject<{
|
|
33
|
+
assetId: z.ZodEnum<["weth", "usdc"]>;
|
|
34
|
+
amount: z.ZodString;
|
|
35
|
+
}, "strip", z.ZodTypeAny, {
|
|
36
|
+
amount: string;
|
|
37
|
+
assetId: "weth" | "usdc";
|
|
38
|
+
}, {
|
|
39
|
+
amount: string;
|
|
40
|
+
assetId: "weth" | "usdc";
|
|
41
|
+
}>;
|
|
42
|
+
export declare const CompoundPortfolioSchema: z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export const CompoundSupplySchema = z
|
|
3
|
+
.object({
|
|
4
|
+
assetId: z.enum(["weth", "cbeth", "cbbtc", "wsteth", "usdc"]).describe("The asset to supply"),
|
|
5
|
+
amount: z
|
|
6
|
+
.string()
|
|
7
|
+
.regex(/^\d+(\.\d+)?$/, "Must be a valid integer or decimal value")
|
|
8
|
+
.describe("The amount of tokens to supply in human-readable format"),
|
|
9
|
+
})
|
|
10
|
+
.describe("Input schema for Compound supply action");
|
|
11
|
+
export const CompoundWithdrawSchema = z
|
|
12
|
+
.object({
|
|
13
|
+
assetId: z.enum(["weth", "cbeth", "cbbtc", "wsteth", "usdc"]).describe("The asset to withdraw"),
|
|
14
|
+
amount: z
|
|
15
|
+
.string()
|
|
16
|
+
.regex(/^\d+(\.\d+)?$/, "Must be a valid integer or decimal value")
|
|
17
|
+
.describe("The amount of tokens to withdraw in human-readable format"),
|
|
18
|
+
})
|
|
19
|
+
.describe("Input schema for Compound withdraw action");
|
|
20
|
+
export const CompoundBorrowSchema = z
|
|
21
|
+
.object({
|
|
22
|
+
assetId: z.enum(["weth", "usdc"]).describe("The asset to borrow"),
|
|
23
|
+
amount: z
|
|
24
|
+
.string()
|
|
25
|
+
.regex(/^\d+(\.\d+)?$/, "Must be a valid integer or decimal value")
|
|
26
|
+
.describe("The amount of base tokens to borrow in human-readable format"),
|
|
27
|
+
})
|
|
28
|
+
.describe("Input schema for Compound borrow action");
|
|
29
|
+
export const CompoundRepaySchema = z
|
|
30
|
+
.object({
|
|
31
|
+
assetId: z.enum(["weth", "usdc"]).describe("The asset to repay"),
|
|
32
|
+
amount: z
|
|
33
|
+
.string()
|
|
34
|
+
.regex(/^\d+(\.\d+)?$/, "Must be a valid integer or decimal value")
|
|
35
|
+
.describe("The amount of tokens to repay in human-readable format"),
|
|
36
|
+
})
|
|
37
|
+
.describe("Input schema for Compound repay action");
|
|
38
|
+
export const CompoundPortfolioSchema = z
|
|
39
|
+
.object({})
|
|
40
|
+
.describe("Input schema for Compound get portfolio action");
|
|
41
|
+
//# sourceMappingURL=schemas.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemas.js","sourceRoot":"","sources":["../../../src/actions/compound/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC;KAClC,MAAM,CAAC;IACN,OAAO,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,qBAAqB,CAAC;IAC7F,MAAM,EAAE,CAAC;SACN,MAAM,EAA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GAAG,CAAC;KACrC,MAAM,CAAC,EAAE,CAAC;KACV,QAAQ,CAAC,gDAAgD,CAAC,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Decimal } from "decimal.js";
|
|
2
|
+
import { type Address } from "viem";
|
|
3
|
+
import type { EvmWalletProvider, Network } from "@coinbase/agentkit";
|
|
4
|
+
export declare const getTokenDecimals: (wallet: EvmWalletProvider, tokenAddress: Address) => Promise<number>;
|
|
5
|
+
export declare const getTokenSymbol: (wallet: EvmWalletProvider, tokenAddress: Address) => Promise<string>;
|
|
6
|
+
export declare const getTokenBalance: (wallet: EvmWalletProvider, tokenAddress: Address) => Promise<bigint>;
|
|
7
|
+
export declare const getCollateralBalance: (wallet: EvmWalletProvider, cometAddress: Address, tokenAddress: Address) => Promise<bigint>;
|
|
8
|
+
export declare const getBaseAssetBalance: (wallet: EvmWalletProvider, cometAddress: Address) => Promise<bigint>;
|
|
9
|
+
export declare const getHealthRatio: (wallet: EvmWalletProvider, cometAddress: Address) => Promise<Decimal>;
|
|
10
|
+
export declare const getHealthRatioAfterWithdraw: (wallet: EvmWalletProvider, cometAddress: Address, tokenAddress: Address, amount: bigint) => Promise<Decimal>;
|
|
11
|
+
export declare const getHealthRatioAfterBorrow: (wallet: EvmWalletProvider, cometAddress: Address, amount: bigint) => Promise<Decimal>;
|
|
12
|
+
export declare const getPortfolioDetailsMarkdown: (wallet: EvmWalletProvider, cometAddress: Address) => Promise<string>;
|
|
13
|
+
export declare const getCometAddress: (network: Network) => Address;
|
|
14
|
+
export declare const getAssetAddress: (network: Network, assetId: string) => Address;
|
|
15
|
+
export declare const getBaseTokenAddress: (wallet: EvmWalletProvider, cometAddress: Address) => Promise<Address>;
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
import { Decimal } from "decimal.js";
|
|
2
|
+
import { formatUnits } from "viem";
|
|
3
|
+
import { ERC20_ABI, COMET_ABI, PRICE_FEED_ABI, COMET_ADDRESSES, ASSET_ADDRESSES, } from "./constants.js";
|
|
4
|
+
export const getTokenDecimals = async (wallet, tokenAddress) => {
|
|
5
|
+
const decimals = await wallet.readContract({
|
|
6
|
+
address: tokenAddress,
|
|
7
|
+
abi: ERC20_ABI,
|
|
8
|
+
functionName: "decimals",
|
|
9
|
+
});
|
|
10
|
+
return Number(decimals);
|
|
11
|
+
};
|
|
12
|
+
export const getTokenSymbol = async (wallet, tokenAddress) => {
|
|
13
|
+
return wallet.readContract({
|
|
14
|
+
address: tokenAddress,
|
|
15
|
+
abi: ERC20_ABI,
|
|
16
|
+
functionName: "symbol",
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
export const getTokenBalance = async (wallet, tokenAddress) => {
|
|
20
|
+
return wallet.readContract({
|
|
21
|
+
address: tokenAddress,
|
|
22
|
+
abi: ERC20_ABI,
|
|
23
|
+
functionName: "balanceOf",
|
|
24
|
+
args: [wallet.getAddress()],
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
export const getCollateralBalance = async (wallet, cometAddress, tokenAddress) => {
|
|
28
|
+
return wallet.readContract({
|
|
29
|
+
address: cometAddress,
|
|
30
|
+
abi: COMET_ABI,
|
|
31
|
+
functionName: "collateralBalanceOf",
|
|
32
|
+
args: [(await wallet.getAddress()), tokenAddress],
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
export const getBaseAssetBalance = async (wallet, cometAddress) => {
|
|
36
|
+
return wallet.readContract({
|
|
37
|
+
address: cometAddress,
|
|
38
|
+
abi: COMET_ABI,
|
|
39
|
+
functionName: "balanceOf",
|
|
40
|
+
args: [(await wallet.getAddress())],
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
export const getHealthRatio = async (wallet, cometAddress) => {
|
|
44
|
+
const borrowDetails = await getBorrowDetails(wallet, cometAddress);
|
|
45
|
+
const supplyDetails = await getSupplyDetails(wallet, cometAddress);
|
|
46
|
+
const borrowValue = borrowDetails.borrowAmount.mul(borrowDetails.price);
|
|
47
|
+
let totalAdjustedCollateral = new Decimal(0);
|
|
48
|
+
for (const supply of supplyDetails) {
|
|
49
|
+
const collateralValue = supply.supplyAmount.mul(supply.price);
|
|
50
|
+
const adjustedValue = collateralValue.mul(supply.collateralFactor);
|
|
51
|
+
totalAdjustedCollateral = totalAdjustedCollateral.add(adjustedValue);
|
|
52
|
+
}
|
|
53
|
+
return borrowValue.eq(0) ? new Decimal(Infinity) : totalAdjustedCollateral.div(borrowValue);
|
|
54
|
+
};
|
|
55
|
+
export const getHealthRatioAfterWithdraw = async (wallet, cometAddress, tokenAddress, amount) => {
|
|
56
|
+
const borrowDetails = await getBorrowDetails(wallet, cometAddress);
|
|
57
|
+
const supplyDetails = await getSupplyDetails(wallet, cometAddress);
|
|
58
|
+
const borrowValue = borrowDetails.borrowAmount.mul(borrowDetails.price);
|
|
59
|
+
let totalAdjustedCollateral = new Decimal(0);
|
|
60
|
+
for (const supply of supplyDetails) {
|
|
61
|
+
const supplyTokenSymbol = supply.tokenSymbol;
|
|
62
|
+
const withdrawTokenSymbol = await getTokenSymbol(wallet, tokenAddress);
|
|
63
|
+
if (supplyTokenSymbol === withdrawTokenSymbol) {
|
|
64
|
+
const decimals = await getTokenDecimals(wallet, tokenAddress);
|
|
65
|
+
const withdrawAmountHuman = new Decimal(formatUnits(amount, decimals));
|
|
66
|
+
const newSupplyAmount = supply.supplyAmount.sub(withdrawAmountHuman);
|
|
67
|
+
const assetValue = newSupplyAmount.mul(supply.price);
|
|
68
|
+
totalAdjustedCollateral = totalAdjustedCollateral.add(assetValue.mul(supply.collateralFactor));
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
totalAdjustedCollateral = totalAdjustedCollateral.add(supply.supplyAmount.mul(supply.price).mul(supply.collateralFactor));
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return borrowValue.eq(0) ? new Decimal(Infinity) : totalAdjustedCollateral.div(borrowValue);
|
|
75
|
+
};
|
|
76
|
+
export const getHealthRatioAfterBorrow = async (wallet, cometAddress, amount) => {
|
|
77
|
+
const borrowDetails = await getBorrowDetails(wallet, cometAddress);
|
|
78
|
+
const supplyDetails = await getSupplyDetails(wallet, cometAddress);
|
|
79
|
+
const baseToken = await getBaseTokenAddress(wallet, cometAddress);
|
|
80
|
+
const baseDecimals = await getTokenDecimals(wallet, baseToken);
|
|
81
|
+
const additionalBorrow = new Decimal(formatUnits(amount, baseDecimals));
|
|
82
|
+
const newBorrow = borrowDetails.borrowAmount.add(additionalBorrow);
|
|
83
|
+
const newBorrowValue = newBorrow.mul(borrowDetails.price);
|
|
84
|
+
let totalAdjustedCollateral = new Decimal(0);
|
|
85
|
+
for (const supply of supplyDetails) {
|
|
86
|
+
totalAdjustedCollateral = totalAdjustedCollateral.add(supply.supplyAmount.mul(supply.price).mul(supply.collateralFactor));
|
|
87
|
+
}
|
|
88
|
+
return newBorrowValue.eq(0) ? new Decimal(Infinity) : totalAdjustedCollateral.div(newBorrowValue);
|
|
89
|
+
};
|
|
90
|
+
export const getPortfolioDetailsMarkdown = async (wallet, cometAddress) => {
|
|
91
|
+
let markdownOutput = "# Portfolio Details\n\n";
|
|
92
|
+
let totalSupplyValue = new Decimal(0);
|
|
93
|
+
// Base asset supply (e.g. USDC) — tracked via Comet.balanceOf(), earns APY
|
|
94
|
+
markdownOutput += "## Base Asset Supply\n\n";
|
|
95
|
+
const baseAssetBalance = await getBaseAssetBalance(wallet, cometAddress);
|
|
96
|
+
const baseToken = await getBaseTokenAddress(wallet, cometAddress);
|
|
97
|
+
const baseDecimals = await getTokenDecimals(wallet, baseToken);
|
|
98
|
+
const baseSymbol = await getTokenSymbol(wallet, baseToken);
|
|
99
|
+
const basePriceFeed = await wallet.readContract({
|
|
100
|
+
address: cometAddress,
|
|
101
|
+
abi: COMET_ABI,
|
|
102
|
+
functionName: "baseTokenPriceFeed",
|
|
103
|
+
args: [],
|
|
104
|
+
});
|
|
105
|
+
const [basePriceRaw] = await getPriceFeedData(wallet, basePriceFeed);
|
|
106
|
+
const basePrice = new Decimal(basePriceRaw).div(new Decimal(10).pow(8));
|
|
107
|
+
const baseSupplyAmount = new Decimal(formatUnits(baseAssetBalance, baseDecimals));
|
|
108
|
+
if (baseAssetBalance > BigInt(0)) {
|
|
109
|
+
const baseValue = baseSupplyAmount.mul(basePrice);
|
|
110
|
+
markdownOutput += `### ${baseSymbol} (Base Asset — earns supply APY)\n`;
|
|
111
|
+
markdownOutput += `- **Supply Amount:** ${baseSupplyAmount.toFixed(baseDecimals)}\n`;
|
|
112
|
+
markdownOutput += `- **Price:** $${basePrice.toFixed(2)}\n`;
|
|
113
|
+
markdownOutput += `- **Asset Value:** $${baseValue.toFixed(2)}\n\n`;
|
|
114
|
+
totalSupplyValue = totalSupplyValue.add(baseValue);
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
markdownOutput += "No base asset supplied.\n\n";
|
|
118
|
+
}
|
|
119
|
+
// Collateral assets — tracked via collateralBalanceOf(), used to back borrows
|
|
120
|
+
markdownOutput += "## Collateral Details\n\n";
|
|
121
|
+
const supplyDetails = await getSupplyDetails(wallet, cometAddress);
|
|
122
|
+
if (supplyDetails.length > 0) {
|
|
123
|
+
for (const supply of supplyDetails) {
|
|
124
|
+
const assetValue = supply.supplyAmount.mul(supply.price);
|
|
125
|
+
markdownOutput += `### ${supply.tokenSymbol}\n`;
|
|
126
|
+
markdownOutput += `- **Supply Amount:** ${supply.supplyAmount.toFixed(supply.decimals)}\n`;
|
|
127
|
+
markdownOutput += `- **Price:** $${supply.price.toFixed(2)}\n`;
|
|
128
|
+
markdownOutput += `- **Collateral Factor:** ${supply.collateralFactor.toFixed(2)}\n`;
|
|
129
|
+
markdownOutput += `- **Asset Value:** $${assetValue.toFixed(2)}\n\n`;
|
|
130
|
+
totalSupplyValue = totalSupplyValue.add(assetValue);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
markdownOutput += "No collateral assets supplied.\n\n";
|
|
135
|
+
}
|
|
136
|
+
markdownOutput += `### Total Supply Value: $${totalSupplyValue.toFixed(2)}\n\n`;
|
|
137
|
+
markdownOutput += "## Borrow Details\n\n";
|
|
138
|
+
const borrowDetails = await getBorrowDetails(wallet, cometAddress);
|
|
139
|
+
if (borrowDetails.borrowAmount.gt(0)) {
|
|
140
|
+
const borrowValue = borrowDetails.borrowAmount.mul(borrowDetails.price);
|
|
141
|
+
markdownOutput += `### ${borrowDetails.tokenSymbol}\n`;
|
|
142
|
+
markdownOutput += `- **Borrow Amount:** ${borrowDetails.borrowAmount.toFixed(6)}\n`;
|
|
143
|
+
markdownOutput += `- **Price:** $${borrowDetails.price.toFixed(2)}\n`;
|
|
144
|
+
markdownOutput += `- **Borrow Value:** $${borrowValue.toFixed(2)}\n\n`;
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
markdownOutput += "No borrowed assets found in your Compound position.\n\n";
|
|
148
|
+
}
|
|
149
|
+
markdownOutput += "## Overall Health\n\n";
|
|
150
|
+
const healthRatio = await getHealthRatio(wallet, cometAddress);
|
|
151
|
+
markdownOutput += `- **Health Ratio:** ${healthRatio.toFixed(2)}\n`;
|
|
152
|
+
return markdownOutput;
|
|
153
|
+
};
|
|
154
|
+
const getPriceFeedData = async (wallet, priceFeedAddress) => {
|
|
155
|
+
const latestData = await wallet.readContract({
|
|
156
|
+
address: priceFeedAddress,
|
|
157
|
+
abi: PRICE_FEED_ABI,
|
|
158
|
+
functionName: "latestRoundData",
|
|
159
|
+
args: [],
|
|
160
|
+
});
|
|
161
|
+
const answer = latestData[1].toString();
|
|
162
|
+
const updatedAt = Number(latestData[3]);
|
|
163
|
+
return [answer, updatedAt];
|
|
164
|
+
};
|
|
165
|
+
const getBorrowDetails = async (wallet, cometAddress) => {
|
|
166
|
+
const borrowAmountRaw = await wallet.readContract({
|
|
167
|
+
address: cometAddress,
|
|
168
|
+
abi: COMET_ABI,
|
|
169
|
+
functionName: "borrowBalanceOf",
|
|
170
|
+
args: [(await wallet.getAddress())],
|
|
171
|
+
});
|
|
172
|
+
const baseToken = await getBaseTokenAddress(wallet, cometAddress);
|
|
173
|
+
const baseDecimals = await getTokenDecimals(wallet, baseToken);
|
|
174
|
+
const baseTokenSymbol = await getTokenSymbol(wallet, baseToken);
|
|
175
|
+
const basePriceFeed = await wallet.readContract({
|
|
176
|
+
address: cometAddress,
|
|
177
|
+
abi: COMET_ABI,
|
|
178
|
+
functionName: "baseTokenPriceFeed",
|
|
179
|
+
args: [],
|
|
180
|
+
});
|
|
181
|
+
const [basePriceRaw] = await getPriceFeedData(wallet, basePriceFeed);
|
|
182
|
+
const humanBorrowAmount = new Decimal(formatUnits(borrowAmountRaw, baseDecimals));
|
|
183
|
+
const price = new Decimal(basePriceRaw).div(new Decimal(10).pow(8));
|
|
184
|
+
return { tokenSymbol: baseTokenSymbol, borrowAmount: humanBorrowAmount, price };
|
|
185
|
+
};
|
|
186
|
+
const getSupplyDetails = async (wallet, cometAddress) => {
|
|
187
|
+
const numAssets = await wallet.readContract({
|
|
188
|
+
address: cometAddress,
|
|
189
|
+
abi: COMET_ABI,
|
|
190
|
+
functionName: "numAssets",
|
|
191
|
+
args: [],
|
|
192
|
+
});
|
|
193
|
+
const supplyDetails = [];
|
|
194
|
+
for (let i = 0; i < numAssets; i++) {
|
|
195
|
+
const assetInfo = await wallet.readContract({
|
|
196
|
+
address: cometAddress,
|
|
197
|
+
abi: COMET_ABI,
|
|
198
|
+
functionName: "getAssetInfo",
|
|
199
|
+
args: [i],
|
|
200
|
+
});
|
|
201
|
+
const assetAddress = assetInfo.asset;
|
|
202
|
+
const collateralBalance = await getCollateralBalance(wallet, cometAddress, assetAddress);
|
|
203
|
+
if (collateralBalance > BigInt(0)) {
|
|
204
|
+
const tokenSymbol = await getTokenSymbol(wallet, assetAddress);
|
|
205
|
+
const decimals = await getTokenDecimals(wallet, assetAddress);
|
|
206
|
+
const [priceRaw] = await getPriceFeedData(wallet, assetInfo.priceFeed);
|
|
207
|
+
const humanSupplyAmount = new Decimal(formatUnits(collateralBalance, decimals));
|
|
208
|
+
const price = new Decimal(priceRaw).div(new Decimal(10).pow(8));
|
|
209
|
+
const collateralFactor = new Decimal(assetInfo.borrowCollateralFactor.toString()).div(new Decimal(10).pow(18));
|
|
210
|
+
supplyDetails.push({
|
|
211
|
+
tokenSymbol,
|
|
212
|
+
supplyAmount: humanSupplyAmount,
|
|
213
|
+
price,
|
|
214
|
+
collateralFactor,
|
|
215
|
+
decimals,
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
return supplyDetails;
|
|
220
|
+
};
|
|
221
|
+
export const getCometAddress = (network) => {
|
|
222
|
+
if (!network.networkId) {
|
|
223
|
+
throw new Error("Network ID is required");
|
|
224
|
+
}
|
|
225
|
+
if (network.networkId === "base-mainnet") {
|
|
226
|
+
return COMET_ADDRESSES["base-mainnet"];
|
|
227
|
+
}
|
|
228
|
+
else if (network.networkId === "base-sepolia") {
|
|
229
|
+
return COMET_ADDRESSES["base-sepolia"];
|
|
230
|
+
}
|
|
231
|
+
throw new Error(`Network ${network.networkId} not supported`);
|
|
232
|
+
};
|
|
233
|
+
export const getAssetAddress = (network, assetId) => {
|
|
234
|
+
if (!network.networkId) {
|
|
235
|
+
throw new Error("Network ID is required");
|
|
236
|
+
}
|
|
237
|
+
const normalizedAssetId = assetId.toLowerCase();
|
|
238
|
+
if (network.networkId === "base-mainnet") {
|
|
239
|
+
const address = ASSET_ADDRESSES["base-mainnet"][normalizedAssetId];
|
|
240
|
+
if (!address)
|
|
241
|
+
throw new Error(`Asset ${assetId} not supported on Base Mainnet`);
|
|
242
|
+
return address;
|
|
243
|
+
}
|
|
244
|
+
else if (network.networkId === "base-sepolia") {
|
|
245
|
+
const address = ASSET_ADDRESSES["base-sepolia"][normalizedAssetId];
|
|
246
|
+
if (!address)
|
|
247
|
+
throw new Error(`Asset ${assetId} not supported on Base Sepolia`);
|
|
248
|
+
return address;
|
|
249
|
+
}
|
|
250
|
+
throw new Error(`Network ${network.networkId} not supported`);
|
|
251
|
+
};
|
|
252
|
+
export const getBaseTokenAddress = async (wallet, cometAddress) => {
|
|
253
|
+
return wallet.readContract({
|
|
254
|
+
address: cometAddress,
|
|
255
|
+
abi: COMET_ABI,
|
|
256
|
+
functionName: "baseToken",
|
|
257
|
+
args: [],
|
|
258
|
+
});
|
|
259
|
+
};
|
|
260
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/actions/compound/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAgB,WAAW,EAAE,MAAM,MAAM,CAAC;AAEjD,OAAO,EACL,SAAS,EACT,SAAS,EACT,cAAc,EACd,eAAe,EACf,eAAe,GAChB,MAAM,gBAAgB,CAAC;AAExB,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,EACnC,MAAyB,EACzB,YAAqB,EACJ,EAAE;IACnB,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,YAAY,CAAC;QACzC,OAAO,EAAE,YAAY;QACrB,GAAG,EAAE,SAAS;QACd,YAAY,EAAE,UAAU;KACzB,CAAC,CAAC;IACH,OAAO,MAAM,CAAC,QAAQ,CAAC,CAAC;AAC1B,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,cAAc,GAAG,KAAK,EACjC,MAAyB,EACzB,YAAqB,EACJ,EAAE;IACnB,OAAO,MAAM,CAAC,YAAY,CAAC;QACzB,OAAO,EAAE,YAAY;QACrB,GAAG,EAAE,SAAS;QACd,YAAY,EAAE,QAAQ;KACvB,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,eAAe,GAAG,KAAK,EAClC,MAAyB,EACzB,YAAqB,EACJ,EAAE;IACnB,OAAO,MAAM,CAAC,YAAY,CAAC;QACzB,OAAO,EAAE,YAAY;QACrB,GAAG,EAAE,SAAS;QACd,YAAY,EAAE,WAAW;QAC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const ALEPH_ADDRESS: "0xc0Fbc4967259786C743361a5885ef49380473dCF";
|
|
2
|
+
export declare const WETH_ADDRESS: "0x4200000000000000000000000000000000000006";
|
|
3
|
+
export declare const USDC_ADDRESS: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913";
|
|
4
|
+
export declare const COMPOUND_COMET: "0xb125E6687d4313864e53df431d5425969c15Eb2F";
|
|
5
|
+
export declare const UNISWAP_ROUTER: "0x2626664c2603336E57B271c5C0b26F421741e481";
|
|
6
|
+
export declare const UNISWAP_ALEPH_POOL: "0xe11C66b25F0e9a9eBEf1616B43424CC6E2168FC8";
|
|
7
|
+
export declare const uniswapV3PoolAbi: readonly [{
|
|
8
|
+
readonly inputs: readonly [];
|
|
9
|
+
readonly name: "slot0";
|
|
10
|
+
readonly outputs: readonly [{
|
|
11
|
+
readonly name: "sqrtPriceX96";
|
|
12
|
+
readonly type: "uint160";
|
|
13
|
+
}, {
|
|
14
|
+
readonly name: "tick";
|
|
15
|
+
readonly type: "int24";
|
|
16
|
+
}, {
|
|
17
|
+
readonly name: "observationIndex";
|
|
18
|
+
readonly type: "uint16";
|
|
19
|
+
}, {
|
|
20
|
+
readonly name: "observationCardinality";
|
|
21
|
+
readonly type: "uint16";
|
|
22
|
+
}, {
|
|
23
|
+
readonly name: "observationCardinalityNext";
|
|
24
|
+
readonly type: "uint16";
|
|
25
|
+
}, {
|
|
26
|
+
readonly name: "feeProtocol";
|
|
27
|
+
readonly type: "uint8";
|
|
28
|
+
}, {
|
|
29
|
+
readonly name: "unlocked";
|
|
30
|
+
readonly type: "bool";
|
|
31
|
+
}];
|
|
32
|
+
readonly stateMutability: "view";
|
|
33
|
+
readonly type: "function";
|
|
34
|
+
}];
|
|
35
|
+
export declare const uniswapRouterAbi: readonly [{
|
|
36
|
+
readonly inputs: readonly [{
|
|
37
|
+
readonly components: readonly [{
|
|
38
|
+
readonly name: "tokenIn";
|
|
39
|
+
readonly type: "address";
|
|
40
|
+
}, {
|
|
41
|
+
readonly name: "tokenOut";
|
|
42
|
+
readonly type: "address";
|
|
43
|
+
}, {
|
|
44
|
+
readonly name: "fee";
|
|
45
|
+
readonly type: "uint24";
|
|
46
|
+
}, {
|
|
47
|
+
readonly name: "recipient";
|
|
48
|
+
readonly type: "address";
|
|
49
|
+
}, {
|
|
50
|
+
readonly name: "amountIn";
|
|
51
|
+
readonly type: "uint256";
|
|
52
|
+
}, {
|
|
53
|
+
readonly name: "amountOutMinimum";
|
|
54
|
+
readonly type: "uint256";
|
|
55
|
+
}, {
|
|
56
|
+
readonly name: "sqrtPriceLimitX96";
|
|
57
|
+
readonly type: "uint160";
|
|
58
|
+
}];
|
|
59
|
+
readonly name: "params";
|
|
60
|
+
readonly type: "tuple";
|
|
61
|
+
}];
|
|
62
|
+
readonly name: "exactInputSingle";
|
|
63
|
+
readonly outputs: readonly [{
|
|
64
|
+
readonly name: "amountOut";
|
|
65
|
+
readonly type: "uint256";
|
|
66
|
+
}];
|
|
67
|
+
readonly stateMutability: "payable";
|
|
68
|
+
readonly type: "function";
|
|
69
|
+
}];
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// --- Contract addresses (Base mainnet) ---
|
|
2
|
+
export const ALEPH_ADDRESS = "0xc0Fbc4967259786C743361a5885ef49380473dCF";
|
|
3
|
+
export const WETH_ADDRESS = "0x4200000000000000000000000000000000000006";
|
|
4
|
+
export const USDC_ADDRESS = "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913";
|
|
5
|
+
export const COMPOUND_COMET = "0xb125E6687d4313864e53df431d5425969c15Eb2F";
|
|
6
|
+
export const UNISWAP_ROUTER = "0x2626664c2603336E57B271c5C0b26F421741e481";
|
|
7
|
+
export const UNISWAP_ALEPH_POOL = "0xe11C66b25F0e9a9eBEf1616B43424CC6E2168FC8";
|
|
8
|
+
// --- Uniswap V3 pool ABI (slot0 only) ---
|
|
9
|
+
export const uniswapV3PoolAbi = [
|
|
10
|
+
{
|
|
11
|
+
inputs: [],
|
|
12
|
+
name: "slot0",
|
|
13
|
+
outputs: [
|
|
14
|
+
{ name: "sqrtPriceX96", type: "uint160" },
|
|
15
|
+
{ name: "tick", type: "int24" },
|
|
16
|
+
{ name: "observationIndex", type: "uint16" },
|
|
17
|
+
{ name: "observationCardinality", type: "uint16" },
|
|
18
|
+
{ name: "observationCardinalityNext", type: "uint16" },
|
|
19
|
+
{ name: "feeProtocol", type: "uint8" },
|
|
20
|
+
{ name: "unlocked", type: "bool" },
|
|
21
|
+
],
|
|
22
|
+
stateMutability: "view",
|
|
23
|
+
type: "function",
|
|
24
|
+
},
|
|
25
|
+
];
|
|
26
|
+
// --- Uniswap V3 SwapRouter ABI (exactInputSingle only) ---
|
|
27
|
+
export const uniswapRouterAbi = [
|
|
28
|
+
{
|
|
29
|
+
inputs: [
|
|
30
|
+
{
|
|
31
|
+
components: [
|
|
32
|
+
{ name: "tokenIn", type: "address" },
|
|
33
|
+
{ name: "tokenOut", type: "address" },
|
|
34
|
+
{ name: "fee", type: "uint24" },
|
|
35
|
+
{ name: "recipient", type: "address" },
|
|
36
|
+
{ name: "amountIn", type: "uint256" },
|
|
37
|
+
{ name: "amountOutMinimum", type: "uint256" },
|
|
38
|
+
{ name: "sqrtPriceLimitX96", type: "uint160" },
|
|
39
|
+
],
|
|
40
|
+
name: "params",
|
|
41
|
+
type: "tuple",
|
|
42
|
+
},
|
|
43
|
+
],
|
|
44
|
+
name: "exactInputSingle",
|
|
45
|
+
outputs: [{ name: "amountOut", type: "uint256" }],
|
|
46
|
+
stateMutability: "payable",
|
|
47
|
+
type: "function",
|
|
48
|
+
},
|
|
49
|
+
];
|
|
50
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/actions/constants.ts"],"names":[],"mappings":"AAEA,4CAA4C;AAC5C,MAAM,CAAC,MAAM,aAAa,GAAG,4CAAqD,CAAC;AACnF,MAAM,CAAC,MAAM,YAAY,GAA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AE,IAAI,EAAE,SAAS,EAAE;oBACrC,EAAE,IAAI,EAAE,kBAAkB,EAAE,IAAI,EAAE,SAAS,EAAE;oBAC7C,EAAE,IAAI,EAAE,mBAAmB,EAAE,IAAI,EAAE,SAAS,EAAE;iBAC/C;gBACD,IAAI,EAAE,QAAQ;gBACd,IAAI,EAAE,OAAO;aACd;SACF;QACD,IAAI,EAAE,kBAAkB;QACxB,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;QACjD,eAAe,EAAE,SAAS;QAC1B,IAAI,EAAE,UAAU;KACjB;CACqB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/actions/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { LLMClient, type Tool } from "@blockrun/llm";
|
|
2
|
+
import { type Hex } from "viem";
|
|
3
|
+
import type { ToolExecution } from "./types.js";
|
|
4
|
+
export interface AgentLoopOptions {
|
|
5
|
+
maxRounds?: number;
|
|
6
|
+
extractTxHashes?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface AgentLoopResult {
|
|
9
|
+
response: string;
|
|
10
|
+
toolExecutions: ToolExecution[];
|
|
11
|
+
txHashes: string[];
|
|
12
|
+
}
|
|
13
|
+
export declare function createLLMClient(privateKey: Hex): LLMClient;
|
|
14
|
+
export declare function runAgentLoop(client: LLMClient, model: string, systemPrompt: string, userPrompt: string, tools: Tool[], executeTool: (name: string, argsJson: string) => Promise<string>, options?: AgentLoopOptions): Promise<AgentLoopResult>;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { LLMClient } from "@blockrun/llm";
|
|
2
|
+
export function createLLMClient(privateKey) {
|
|
3
|
+
return new LLMClient({ privateKey });
|
|
4
|
+
}
|
|
5
|
+
export async function runAgentLoop(client, model, systemPrompt, userPrompt, tools, executeTool, options) {
|
|
6
|
+
const maxRounds = options?.maxRounds ?? 10;
|
|
7
|
+
const extractTxHashes = options?.extractTxHashes ?? true;
|
|
8
|
+
const messages = [
|
|
9
|
+
{ role: "system", content: systemPrompt },
|
|
10
|
+
{ role: "user", content: userPrompt },
|
|
11
|
+
];
|
|
12
|
+
const toolExecutions = [];
|
|
13
|
+
const txHashes = [];
|
|
14
|
+
for (let round = 0; round < maxRounds; round++) {
|
|
15
|
+
const result = await client.chatCompletion(model, messages, {
|
|
16
|
+
tools: tools.length > 0 ? tools : undefined,
|
|
17
|
+
toolChoice: tools.length > 0 ? "auto" : undefined,
|
|
18
|
+
});
|
|
19
|
+
const choice = result.choices[0];
|
|
20
|
+
const msg = choice.message;
|
|
21
|
+
messages.push({
|
|
22
|
+
role: "assistant",
|
|
23
|
+
content: msg.content ?? null,
|
|
24
|
+
tool_calls: msg.tool_calls,
|
|
25
|
+
});
|
|
26
|
+
if (choice.finish_reason !== "tool_calls" || !msg.tool_calls?.length) {
|
|
27
|
+
return { response: msg.content ?? "", toolExecutions, txHashes };
|
|
28
|
+
}
|
|
29
|
+
for (const toolCall of msg.tool_calls) {
|
|
30
|
+
const { name, arguments: argsJson } = toolCall.function;
|
|
31
|
+
console.log(`[tool] calling ${name}(${argsJson})`);
|
|
32
|
+
const toolResult = await executeTool(name, argsJson);
|
|
33
|
+
console.log(`[tool] ${name} -> ${toolResult.slice(0, 200)}`);
|
|
34
|
+
let args;
|
|
35
|
+
try {
|
|
36
|
+
args = JSON.parse(argsJson);
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
args = undefined;
|
|
40
|
+
}
|
|
41
|
+
let txHash;
|
|
42
|
+
if (extractTxHashes) {
|
|
43
|
+
const txMatch = toolResult.match(/[Hh]ash:?\s*(0x[a-fA-F0-9]{64})/);
|
|
44
|
+
txHash = txMatch?.[1];
|
|
45
|
+
if (txHash)
|
|
46
|
+
txHashes.push(txHash);
|
|
47
|
+
}
|
|
48
|
+
toolExecutions.push({ name, args, result: toolResult, txHash });
|
|
49
|
+
messages.push({
|
|
50
|
+
role: "tool",
|
|
51
|
+
tool_call_id: toolCall.id,
|
|
52
|
+
content: toolResult,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
console.log("[llm] max tool rounds reached, getting final response");
|
|
57
|
+
const final = await client.chatCompletion(model, messages);
|
|
58
|
+
return { response: final.choices[0].message.content ?? "", toolExecutions, txHashes };
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=agent-loop.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-loop.js","sourceRoot":"","sources":["../src/agent-loop.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAA+B,MAAM,eAAe,CAAC;AAevE,MAAM,UAAU,eAAe,CAAC,UAAe;IAC7C,OAAO,IAAI,SAAS,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC;AACvC,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,MAAiB,EACjB,KAAa,EACb,YAAoB,EACpB,UAAkB,EAClB,KAAa,EACb,WAAgE,EAChE,OAA0B;IAE1B,MAAM,SAAS,GAAG,OAAO,EAAE,SAAS,IAAI,EAAE,CAAC;IAC3C,MAAM,eAAe,GAAG,OAAO,EAAE,eAAe,IAAI,IAAI,CAAC;IAEzD,MAAM,QAAQ,GAAkB;QAC9B,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,YAAY,EAAE;QACzC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE;KACtC,CAAC;IAEF,MAAM,cAAc,GAAoB,EAAE,CAAC;IAC3C,MAAM,QAAQ,GAAa,EAAE,CAAC;IAE9B,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,SAAS,EAA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wC,CAAC;YAC7C,IAAI,CAAC;gBACH,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;YAC9B,CAAC;YAAC,MAAM,CAAC;gBACP,IAAI,GAAG,SAAS,CAAC;YACnB,CAAC;YAED,IAAI,MAA0B,CAAC;YAC/B,IAAI,eAAe,EAAE,CAAC;gBACpB,MAAM,OAAO,GAAG,UAAU,CAAC,KAAK,CAAC,iCAAiC,CAAC,CAAC;gBACpE,MAAM,GAAG,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC;gBACtB,IAAI,MAAM;oBAAE,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YACpC,CAAC;YAED,cAAc,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC,CAAC;YAEhE,QAAQ,CAAC,IAAI,CAAC;gBACZ,IAAI,EAAE,MAAM;gBACZ,YAAY,EAAE,QAAQ,CAAC,EAAE;gBACzB,OAAO,EAAE,UAAU;aACpB,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,OAAO,CAAC,GAAG,CAAC,uDAAuD,CAAC,CAAC;IACrE,MAAM,KAAK,GAAG,MAAM,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IAC3D,OAAO,EAAE,QAAQ,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,IAAI,EAAE,EAAE,cAAc,EAAE,QAAQ,EAAE,CAAC;AACxF,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ActivityType, AgentActivity } from "./types.js";
|
|
2
|
+
export declare class AlephPublisher {
|
|
3
|
+
private privateKey;
|
|
4
|
+
private client;
|
|
5
|
+
private channel;
|
|
6
|
+
constructor(privateKey: string, channel?: string);
|
|
7
|
+
init(): Promise<void>;
|
|
8
|
+
publish(postType: ActivityType, activity: AgentActivity): Promise<void>;
|
|
9
|
+
}
|