Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ describe("VaultsfyiActionProvider", () => {
getNetwork: jest.fn().mockReturnValue({
protocolFamily: "evm",
networkId: "test-network",
chainId: "1",
}),
nativeTransfer: jest.fn(),
readContract: jest.fn(() => Promise.resolve(18)), // token decimals
Expand Down Expand Up @@ -461,6 +462,40 @@ describe("VaultsfyiActionProvider", () => {
"Failed to execute step: some more info",
);
});

it("should reject when args.network does not match the wallet chain", async () => {
const args = {
vaultAddress: "0x123",
assetAddress: "0x456",
network: "base",
amount: 1n,
action: "deposit",
} as const;
mockedFetch.mockClear();
expect(await provider.executeStep(mockWalletProvider, args)).toBe(
"Error: You're trying to execute a step on a different network. Agent network is mainnet.",
);
expect(mockedFetch).not.toHaveBeenCalled();
expect(mockWalletProvider.sendTransaction).not.toHaveBeenCalled();
});

it("should reject when the wallet network is missing a chainId", async () => {
mockWalletProvider.getNetwork.mockReturnValue({
protocolFamily: "evm",
networkId: "test-network",
});
const args = {
vaultAddress: "0x123",
assetAddress: "0x456",
network: "mainnet",
amount: 1n,
action: "deposit",
} as const;
mockedFetch.mockClear();
expect(await provider.executeStep(mockWalletProvider, args)).toBe("Invalid network");
expect(mockedFetch).not.toHaveBeenCalled();
expect(mockWalletProvider.sendTransaction).not.toHaveBeenCalled();
});
});

describe("user_idle_assets action", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,13 @@ export class VaultsfyiActionProvider extends ActionProvider<EvmWalletProvider> {
wallet: EvmWalletProvider,
args: z.infer<typeof executeStepActionSchema>,
): Promise<string> {
const chainId = wallet.getNetwork().chainId;
if (!chainId) return "Invalid network";
const networkName = getNetworkNameFromChainId(chainId);
if (!networkName) return "Invalid network";
if (args.network !== networkName) {
return `Error: You're trying to execute a step on a different network. Agent network is ${networkName}.`;
}
try {
const sdk = getVaultsSdk(this.apiKey);
const amount = args.amount === "all" ? 0 : args.amount;
Expand Down
Loading