sei-agent-kit
Version:
A package for building AI agents on the SEI blockchain
33 lines (32 loc) • 1.61 kB
JavaScript
import { Toolkit } from '@bancor/carbon-sdk/strategy-management';
import { initSyncedCache } from '@bancor/carbon-sdk/chain-cache';
import { ContractsApi } from '@bancor/carbon-sdk/contracts-api';
import { JsonRpcProvider } from '@ethersproject/providers';
import { SEI_RPC_URL, MAX_BLOCK_AGE } from '../../constants';
/**
*/
export async function updateStrategy(agent, config, strategyId, update, encoded, buyPriceMarginal, sellPriceMarginal, overrides) {
try {
const provider = new JsonRpcProvider(SEI_RPC_URL);
const api = new ContractsApi(provider, config);
const { cache } = initSyncedCache(api.reader, undefined, MAX_BLOCK_AGE);
const carbonSDK = new Toolkit(api, cache, undefined);
const populatedTx = await carbonSDK.updateStrategy(strategyId, encoded, update, buyPriceMarginal, sellPriceMarginal, overrides);
const viemTx = {
chain: agent.walletClient.chain,
account: agent.walletClient.account?.address,
to: populatedTx.to,
data: populatedTx.data,
value: populatedTx.value ? BigInt(populatedTx.value.toString()) : 0n,
gas: populatedTx.gasLimit ? BigInt(populatedTx.gasLimit.toString()) : undefined,
nonce: populatedTx.nonce,
};
const txHash = await agent.walletClient.sendTransaction(viemTx);
return txHash;
}
catch (error) {
console.error(`Error fetching token address from DexScreener: ${error instanceof Error ? error.message : String(error)}`);
throw error;
}
}
//# sourceMappingURL=updateStrategy.js.map