@coinbase/agentkit
Version:
Coinbase AgentKit core primitives
72 lines (71 loc) • 3.69 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.superfluidQueryActionProvider = exports.SuperfluidQueryActionProvider = void 0;
const actionProvider_1 = require("../actionProvider");
const wallet_providers_1 = require("../../wallet-providers");
const actionDecorator_1 = require("../actionDecorator");
const schemas_1 = require("./schemas");
const superfluidGraphQueries_1 = require("./graphQueries/superfluidGraphQueries");
/**
* SuperfluidQueryActionProvider is an action provider for Superfluid interactions.
*/
class SuperfluidQueryActionProvider extends actionProvider_1.ActionProvider {
/**
* Constructor for the SuperfluidQueryActionProvider class.
*/
constructor() {
super("superfluid-query", []);
/**
* Checks if the Superfluid action provider supports the given network.
*
* @param network - The network to check.
* @returns True if the Superfluid action provider supports the network, false otherwise.
*/
this.supportsNetwork = (network) => network.networkId === "base-mainnet" || network.networkId === "base-sepolia";
}
/**
* Gets a list of addresses to which a stream is open
*
* @param walletProvider - The wallet of the agent.
* @returns A JSON string containing the account details or error message
*/
async queryStreams(walletProvider) {
try {
const accountData = await (0, superfluidGraphQueries_1.getAccountOutflow)(walletProvider.getAddress());
const outflows = accountData?.accounts?.length ? accountData?.accounts[0].outflows : [];
const activeOutflows = outflows.filter(o => {
return parseInt(o.currentFlowRate) > 0;
});
return `Current outflows are ${JSON.stringify(activeOutflows)}`;
}
catch (error) {
return `Error querying Superfluid streams: ${error}`;
}
}
}
exports.SuperfluidQueryActionProvider = SuperfluidQueryActionProvider;
__decorate([
(0, actionDecorator_1.CreateAction)({
name: "query_streams",
description: `
This tool will query the Superfluid subgraph to find a list of addresses to which you are streaming a token.
It takes nothing as input; you will be checking against your own wallet.
It returns an array of account outflows, each with a receiver (wallet address), a token, and a flow rate. If the flow rate is greater than zero, there is a current flow.
`,
schema: schemas_1.EmptySchema,
}),
__metadata("design:type", Function),
__metadata("design:paramtypes", [wallet_providers_1.EvmWalletProvider]),
__metadata("design:returntype", Promise)
], SuperfluidQueryActionProvider.prototype, "queryStreams", null);
const superfluidQueryActionProvider = () => new SuperfluidQueryActionProvider();
exports.superfluidQueryActionProvider = superfluidQueryActionProvider;