I’m not sure about the inner workings of the Trinity but God is the source of grace–Jesus is rightly said to the source, the sole Mediator between God and man. Mary helps distribute that grace, just as the Church as a whole does (the grace of Christ the head flows down and through His body, the Church–Mary is often considered the neck–the first member of the body in whom all grace is found).
The treasury of merit is a little different, but related. There are three parts to repentance: contrition, confession, and bringing forth fruits worthy of repentance (aka make satisfaction). The treasury of merit is related to the third part. Since we are all one body, we can do that part on behalf of one another. The treasury of merit is the superabundant fruits brought forth by the whole Church for this purpose (including Christ, Mary, and all the Saints). They are applied to individual souls by the bishops–in light of their power to bind and loose–by what we call an indulgence.