-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from NeurProjects/main
Added code
- Loading branch information
Showing
36 changed files
with
4,584 additions
and
1,371 deletions.
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
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 |
---|---|---|
@@ -1,13 +1,55 @@ | ||
diff --git a/dist/tools/trade.js b/dist/tools/trade.js | ||
index 280aa7564613238857477f791f7f7522a8faca83..47ad1ffee7884cb6a2e19e00d410fb2677ad8e2c 100644 | ||
index 280aa7564613238857477f791f7f7522a8faca83..b9345cbcc4ffc31665e51ecc9ad6396dc2a693fc 100755 | ||
--- a/dist/tools/trade.js | ||
+++ b/dist/tools/trade.js | ||
@@ -29,7 +29,7 @@ async function trade(agent, outputMint, inputAmount, inputMint = constants_1.TOK | ||
@@ -4,6 +4,10 @@ exports.trade = trade; | ||
const web3_js_1 = require("@solana/web3.js"); | ||
const constants_1 = require("../constants"); | ||
const spl_token_1 = require("@solana/spl-token"); | ||
+const { Helius } = require("helius-sdk"); | ||
+ | ||
+const helius = new Helius(process.env.HELIUS_API_KEY); | ||
+ | ||
/** | ||
* Swap tokens using Jupiter Exchange | ||
* @param agent SolanaAgentKit instance | ||
@@ -29,7 +33,8 @@ async function trade(agent, outputMint, inputAmount, inputMint = constants_1.TOK | ||
`&amount=${scaledAmount}` + | ||
`&slippageBps=${slippageBps}` + | ||
`&onlyDirectRoutes=true` + | ||
- `&maxAccounts=20` + | ||
+ `&maxAccounts=64` + | ||
+ `&asLegacyTransaction=true` + | ||
`${agent.config.JUPITER_FEE_BPS ? `&platformFeeBps=${agent.config.JUPITER_FEE_BPS}` : ""}`)).json(); | ||
// Get serialized transaction | ||
let feeAccount; | ||
@@ -49,17 +54,25 @@ async function trade(agent, outputMint, inputAmount, inputMint = constants_1.TOK | ||
quoteResponse, | ||
userPublicKey: agent.wallet_address.toString(), | ||
wrapAndUnwrapSol: true, | ||
- dynamicComputeUnitLimit: true, | ||
+ dynamicComputeUnitLimit: false, | ||
prioritizationFeeLamports: "auto", | ||
feeAccount: feeAccount ? feeAccount.toString() : null, | ||
+ asLegacyTransaction: true, | ||
}), | ||
})).json(); | ||
// Deserialize transaction | ||
const swapTransactionBuf = Buffer.from(swapTransaction, "base64"); | ||
- const transaction = web3_js_1.VersionedTransaction.deserialize(swapTransactionBuf); | ||
+ const transaction = web3_js_1.Transaction.from(swapTransactionBuf); | ||
+ | ||
+ // Remove the instruction that sets the compute unit price/limit | ||
+ const filteredInstructions = transaction.instructions.filter((instruction) => { | ||
+ const programId = instruction.programId; | ||
+ return !programId.equals(web3_js_1.ComputeBudgetProgram.programId); | ||
+ }); | ||
+ | ||
// Sign and send transaction | ||
- transaction.sign([agent.wallet]); | ||
- const signature = await agent.connection.sendTransaction(transaction); | ||
+ const signature = await helius.rpc.sendSmartTransaction(filteredInstructions, [agent.wallet]); | ||
+ | ||
return signature; | ||
} | ||
catch (error) { |
Oops, something went wrong.