18awg is small for power wires. With 5VAC 2A:
- At 20ft you're going to get ~4.5V
- At 40ft, about ~4.0V.
For comparison, if it was 16awg, at 20ft you'd get ~4.7V. With 22awg, at 20ft you'd get ~3.7V.
You should check the specs on the camera: they'll often give a voltage tolerance. On top of that, some transformers (especially cheap ones) don't exactly supply the voltage they say they will, especially as the current draw is higher. A crappy transformer coupled with under-sized wiring may mean not enough power for the camera, which will result in it either not working or being "glitchy".
Because you also have a wifi camera, the lower the wifi signal it gets, the more power it will take. I'm not sure how significant this actually is, but wifi is likely to be one of the main demands for power in the camera.
You can compensate for the voltage loss with a slightly higher input voltage (a 5.5V transformer would work perfectly for you). Power over Ethernet compensates for this by supplying a higher voltage (48VDC) and requiring devices can accept as low as 44V DC.
You could also potentially use the existing wire as a fish to pull a larger wire though, but that of course depends on if it's exposed in an unfinished basement or how willing you are to open and patch drywall. If you're going to pull wires, it may just be easier to pull ethernet and use a PoE hard-wired camera (more reliable, plus the power problem is taken care of).