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

Add Voltr check balance, deposit and withdraw strategy #128

Merged
merged 6 commits into from
Jan 17, 2025

Conversation

jakeyvee
Copy link
Contributor

@jakeyvee jakeyvee commented Jan 4, 2025

Pull Request Description

Related Issue

Fixes # (issue number)

Changes Made

This PR adds the following changes:

  • Query Voltr vault and strategies balances
  • Withdraw from Voltr strategies
  • Deposit into Voltr strategies

Implementation Details

  • utilises Voltr's SDK @voltr/sdk to instantiate a VoltrClient
  • find and fetch relevant accounts to create instructions using VoltrClient

Transaction executed by agent

Example transaction: https://solana.fm/tx/GnUd38TMhtBYNv29nNAyESEWLwjHhUW6hraNrPE3RTF6LtdqNtnoBBqEKptT5JaWqv6TiFp6MeooUa9Rt7vMAu9?cluster=mainnet-alpha
Demo: https://x.com/voltrxyz/status/1875204418465059189

Prompt Used

Tested on autonomous mode.

async function runAutonomousMode(agent: any, config: any, interval = 10) {
  console.log("Starting autonomous mode...");

  let iterations = 0;

  while (true) {
    try {
      const evenThought =
        "1. Get the total amount and amount for each strategy of a Voltr vault: 3ab3KVY9GbDbUUbRnYNSBDQqABTDup7HmdgADHGpB8Bq. " +
        "2. Take note of the strategies id with the their respective amount. " +
        "3. Calculate the sum of all strategy amounts. " +
        "4. Subtract that sum from the vault total to get the excess amount. " +
        "5. Indicate the excess amount and the strategy id with the lowest amount.";

      const oddThought =
        "Using the latest excess amount, if it is 0 then do nothing. " +
        "Else if it is more than 0, deposit the excess amount into the lowest strategy and vault: 3ab3KVY9GbDbUUbRnYNSBDQqABTDup7HmdgADHGpB8Bq.";

      const thought = iterations % 2 === 0 ? evenThought : oddThought;

      const stream = await agent.stream(
        { messages: [new HumanMessage(thought)] },
        config,
      );

      for await (const chunk of stream) {
        if ("agent" in chunk) {
          for (const message of chunk.agent.messages) {
            console.log(message.content);
          }
        } else if ("tools" in chunk) {
          for (const message of chunk.tools.messages) {
            console.log(message.content);
          }
        }
        console.log("-------------------");
      }

      iterations++;

      await new Promise((resolve) => setTimeout(resolve, interval * 1000));
    } catch (error) {
      if (error instanceof Error) {
        console.error("Error:", error.message);
      }
      process.exit(1);
    }
  }
}

Additional Notes

Checklist

  • I have tested these changes locally
  • I have updated the documentation
  • I have added a transaction link
  • I have added the prompt used to test it

@arihantbansal
Copy link
Member

arihantbansal commented Jan 11, 2025

Hey, could you resolve merge conflicts and also implement Action for each of your tools as https://github.com/sendaifun/solana-agent-kit/tree/main/src/actions?

@jakeyvee
Copy link
Contributor Author

hey Arihant, done. Appreciate your work.

@arihantbansal
Copy link
Member

arihantbansal commented Jan 15, 2025

@jakeyvee Thanks, lgtm but I think it might be better if the action and langchain tool prompts didn't require user to specify the pubkey of the strategy/vault and rather it could be abstracted. I saw your autonomous mode demo and wanted to know what prompt have you specified such that the agent is able to figure out the strategy pubkey and then act on it?

Also, pls resolve merge conflicts.

@jakeyvee
Copy link
Contributor Author

@jakeyvee Thanks, lgtm but I think it might be better if the action and langchain tool prompts didn't require user to specify the pubkey of the strategy/vault and rather it could be abstracted. I saw your autonomous mode demo and wanted to know what prompt have you specified such that the agent is able to figure out the strategy pubkey and then act on it?

Also, pls resolve merge conflicts.

Hey Arihant, the person who will be using Voltr on Solana Agent Kit would most likely be a Vault Manager who is aware of the vault's pubkey they are managing, so providing the vault's address is trivial. In my example above on autonomous mode, the manager can simply request to view the position of all strategies connected to the vault and do necessary rebalancing methods -- no strategy address is needed. Hope this clarifies. Thanks again for reviewing this PR.

@jakeyvee
Copy link
Contributor Author

@arihantbansal Resolved!

@arihantbansal
Copy link
Member

@jakeyvee Thanks, lgtm but I think it might be better if the action and langchain tool prompts didn't require user to specify the pubkey of the strategy/vault and rather it could be abstracted. I saw your autonomous mode demo and wanted to know what prompt have you specified such that the agent is able to figure out the strategy pubkey and then act on it?
Also, pls resolve merge conflicts.

Hey Arihant, the person who will be using Voltr on Solana Agent Kit would most likely be a Vault Manager who is aware of the vault's pubkey they are managing, so providing the vault's address is trivial. In my example above on autonomous mode, the manager can simply request to view the position of all strategies connected to the vault and do necessary rebalancing methods -- no strategy address is needed. Hope this clarifies. Thanks again for reviewing this PR.

You are assuming that Voltr integration here would be for your platform or for someone who knows about it. But, what about cases where people are interested in building Defi agents which trade / invest for you. In this scenario, we do require ability to fetch details of different vaults.

@thearyanag thearyanag merged commit d8c6731 into sendaifun:main Jan 17, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants