Using macros to apply variable damage

Haii! I am currently building a Minecraft-Dungeons-style RPG datapack for a server, and I want to make certain things (like custom enchantments) deal damage that scales the damage attribute modifier of the weapon a player is holding. How would I do this? I've watched some tutorials but still don't fully understand.
Continue to help post