-
Notifications
You must be signed in to change notification settings - Fork 313
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
61abe10
commit e186960
Showing
8 changed files
with
340 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { Action } from "../types/action"; | ||
import { SolanaAgentKit } from "../agent"; | ||
import { z } from "zod"; | ||
import { depositWithLulo } from "../tools"; | ||
|
||
const depositWithLuloAction: Action = { | ||
name: "DEPOSIT_WITH_LULO", | ||
similes: [ | ||
"deposit with lulo", | ||
"deposit usdc with lulo", | ||
"deposit pyusc with lulo", | ||
"deposit usds with lulo", | ||
"deposit usdt with lulo", | ||
"deposit SOL with lulo", | ||
"deposit jitoSOL with lulo", | ||
"deposit bSOL with lulo", | ||
"deposit mSOL with lulo", | ||
"deposit BONK with lulo", | ||
"deposit JUP with lulo", | ||
], | ||
description: | ||
"Deposit tokens with Lulo staking protocol", | ||
examples: [ | ||
[ | ||
{ | ||
input: { | ||
mintAddress: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", | ||
amount: 1.5, | ||
}, | ||
output: { | ||
status: "success", | ||
signature: "5KtPn3...", | ||
message: "Successfully deposited 1.5 SOL with lulo", | ||
}, | ||
explanation: "Deposit 1.5 SOL with lulo", | ||
}, | ||
], | ||
], | ||
schema: z.object({ | ||
mintAddress: z.string().describe("Token mint address to deposit"), | ||
amount: z.number().positive().describe("Amount to deposit"), | ||
}), | ||
handler: async (agent: SolanaAgentKit, input: Record<string, any>) => { | ||
try { | ||
const mintAddress = input.mintAddress as string; | ||
const amount = input.amount as number; | ||
|
||
const res = await depositWithLulo(agent, mintAddress, amount); | ||
return { | ||
status: "success", | ||
res, | ||
message: `Successfully deposited ${amount} of ${mintAddress}`, | ||
}; | ||
} catch (error: any) { | ||
return { | ||
status: "error", | ||
message: `deposit failed: ${error.message}`, | ||
}; | ||
} | ||
}, | ||
}; | ||
|
||
export default depositWithLuloAction; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { Action } from "../types/action"; | ||
import { SolanaAgentKit } from "../agent"; | ||
import { z } from "zod"; | ||
import { withdrawWithLulo } from "../tools"; | ||
|
||
const withdrawWithLuloAction: Action = { | ||
name: "WITHDRAW_WITH_LULO", | ||
similes: [ | ||
"withdraw with lulo", | ||
"withdraw usdc with lulo", | ||
"withdraw pyusc with lulo", | ||
"withdraw usds with lulo", | ||
"withdraw usdt with lulo", | ||
"withdraw SOL with lulo", | ||
"withdraw jitoSOL with lulo", | ||
"withdraw bSOL with lulo", | ||
"withdraw mSOL with lulo", | ||
"withdraw BONK with lulo", | ||
"withdraw JUP with lulo", | ||
], | ||
description: | ||
"Withdraw tokens with Lulo staking protocol", | ||
examples: [ | ||
[ | ||
{ | ||
input: { | ||
mintAddress: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", | ||
amount: 1.5, | ||
}, | ||
output: { | ||
status: "success", | ||
signature: "5KtPn3...", | ||
message: "Successfully withdrawed 1.5 SOL with lulo", | ||
}, | ||
explanation: "Withdraw 1.5 SOL with lulo", | ||
}, | ||
], | ||
], | ||
schema: z.object({ | ||
mintAddress: z.string().describe("Token mint address to withdraw"), | ||
amount: z.number().positive().describe("Amount to withdraw"), | ||
}), | ||
handler: async (agent: SolanaAgentKit, input: Record<string, any>) => { | ||
try { | ||
const mintAddress = input.mintAddress as string; | ||
const amount = input.amount as number; | ||
|
||
const res = await withdrawWithLulo(agent, mintAddress, amount); | ||
return { | ||
status: "success", | ||
res, | ||
message: `Successfully withdrawed ${amount} of ${mintAddress}`, | ||
}; | ||
} catch (error: any) { | ||
return { | ||
status: "error", | ||
message: `withdraw failed: ${error.message}`, | ||
}; | ||
} | ||
}, | ||
}; | ||
|
||
export default withdrawWithLuloAction; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
import { VersionedTransaction } from "@solana/web3.js"; | ||
import { SolanaAgentKit } from "../index"; | ||
|
||
/** | ||
* Deposit tokens for yields using Lulo | ||
* @param agent SolanaAgentKit instance | ||
* @param mintAddress Mint address to deposit | ||
* @param amount Amount to deposit | ||
* @returns Transaction signature | ||
*/ | ||
export async function depositWithLulo( | ||
agent: SolanaAgentKit, | ||
mintAddress: string, | ||
amount: number, | ||
): Promise<string> { | ||
try { | ||
const response = await fetch( | ||
`https://api.flexlend.fi/generate/account/deposit`, | ||
{ | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
"x-wallet-pubkey": agent.wallet.publicKey.toBase58(), | ||
"x-api-key": process.env.FLEXLEND_API_KEY! | ||
}, | ||
body: JSON.stringify({ | ||
owner: agent.wallet.publicKey.toBase58(), | ||
mintAddress: mintAddress, | ||
depositAmount: amount, | ||
}), | ||
}, | ||
); | ||
|
||
const data = await response.json(); | ||
|
||
// Deserialize the transaction | ||
const luloTxn = VersionedTransaction.deserialize( | ||
Buffer.from(data.transaction, "base64"), | ||
); | ||
|
||
// Get a recent blockhash and set it | ||
const { blockhash } = await agent.connection.getLatestBlockhash(); | ||
luloTxn.message.recentBlockhash = blockhash; | ||
|
||
// Sign and send transaction | ||
luloTxn.sign([agent.wallet]); | ||
|
||
const signature = await agent.connection.sendTransaction(luloTxn, { | ||
preflightCommitment: "confirmed", | ||
maxRetries: 3, | ||
}); | ||
|
||
// Wait for confirmation using the latest strategy | ||
const latestBlockhash = await agent.connection.getLatestBlockhash(); | ||
await agent.connection.confirmTransaction({ | ||
signature, | ||
blockhash: latestBlockhash.blockhash, | ||
lastValidBlockHeight: latestBlockhash.lastValidBlockHeight, | ||
}); | ||
|
||
return signature; | ||
} catch (error: any) { | ||
throw new Error(`Deposit failed: ${error.message}`); | ||
} | ||
} | ||
|
||
/** | ||
* Withdraw tokens for yields using Lulo | ||
* @param agent SolanaAgentKit instance | ||
* @param mintAddress Mint address to deposit | ||
* @param amount Amount to deposit | ||
* @returns Transaction signature | ||
*/ | ||
export async function withdrawWithLulo( | ||
agent: SolanaAgentKit, | ||
mintAddress: string, | ||
amount: number, | ||
): Promise<string> { | ||
try { | ||
const response = await fetch( | ||
`https://api.flexlend.fi/generate/account/withdraw`, | ||
{ | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
"x-wallet-pubkey": agent.wallet.publicKey.toBase58(), | ||
"x-api-key": process.env.FLEXLEND_API_KEY! | ||
}, | ||
body: JSON.stringify({ | ||
owner: agent.wallet.publicKey.toBase58(), | ||
mintAddress: mintAddress, | ||
depositAmount: amount, | ||
}), | ||
}, | ||
); | ||
|
||
const data = await response.json(); | ||
|
||
const luloTxn = VersionedTransaction.deserialize( | ||
Buffer.from(data.transaction, "base64"), | ||
); | ||
|
||
const { blockhash } = await agent.connection.getLatestBlockhash(); | ||
luloTxn.message.recentBlockhash = blockhash; | ||
|
||
luloTxn.sign([agent.wallet]); | ||
|
||
const signature = await agent.connection.sendTransaction(luloTxn, { | ||
preflightCommitment: "confirmed", | ||
maxRetries: 3, | ||
}); | ||
|
||
const latestBlockhash = await agent.connection.getLatestBlockhash(); | ||
await agent.connection.confirmTransaction({ | ||
signature, | ||
blockhash: latestBlockhash.blockhash, | ||
lastValidBlockHeight: latestBlockhash.lastValidBlockHeight, | ||
}); | ||
|
||
return signature; | ||
} catch (error: any) { | ||
throw new Error(`Withdraw failed: ${error.message}`); | ||
} | ||
} | ||
|