As I was reading @MichaelMaggs answer, I recalled that there was also a treasure involved somehow. That led me back to google and I found the book, the unsubtly titled: Trapped in Death Cave by Bill Wallace
Two boys get trapped by the bad guy in a pit in a cave full of hibernating rattlesnakes to dig up some stolen gold. A rainstorm outside causes the cave to fill with water, and the boys use the crate that the gold was in to float out of the pit and out to safety. As I recall, on their way out, they see the bad guy also floating along, dead with lots of visible rattlesnake bites. It was a fun read for a late-elementary boy. :)