📄 Accountant.sol
D-OPEN SOVEREIGN

Documentation & Insights

The smallest unit of Ether, known as "wei," is used to describe the cost of gas.
One Ether has 1,000,000,000,000,000,000 wei.
Wei is the most common unit used to specify the price of gas, however,
it is also possible to use wei or ether
(1 ether equals 1,000,000,000,000,000,000 wei).
Members can interact with the Project Manager (PM) trough D-Accountant.
    For every donation received, D-Accountant provides the information to the PM with your donated amount.
Debt FREE !!
        80% of all donations goes to projects
1/*
2 * Copyright (c) 2026 DataPond D-Library Pty Ltd. ("The Sanctuary")
3 * Non-Profit Public Library — The World Library
4 * 
5 * D-SAFE Certification issued by POND Enterprise.
6 * Published under the D-Open Code Sovereign Licence v1.0 framework
7 * DataPond D-Library All exclusive Right reserved on modifiying the code - CC Attribution to data pond, Non modifiable, Non Commercial.
8 * https://registry.world.bibliotech.com/licence
9 * Source code donated to DataPond D-Library by it's author: data pond.
10 * 
11 * Technical Guardian ("The Shield"): Pond Enterprise Pty Ltd. (ACN 694 747 987)
12 * All liability claims about D-SAFE certification issues coming from the published D-Safe direction must be addressed with Pond Enterprise Pty Ltd.
13 * Code Modification automatically voids the certified liability protection provided by Pond Enterprise.
14 */
15
16// SPDX-License-Identifier: Apache-2.0
17pragma solidity ^0.8.24;
18
19import {ProjectManager} from "./ProjectManager.sol";
20import {ErrorLibrary} from "./ErrorLibrary.sol";
21import "@pythnetwork/pyth-sdk-solidity/IPyth.sol";
22import "@pythnetwork/pyth-sdk-solidity/PythStructs.sol";
23
24/**
25The smallest unit of Ether, known as "wei," is used to describe the cost of gas.
26One Ether has 1,000,000,000,000,000,000 wei.
27Wei is the most common unit used to specify the price of gas, however,
28it is also possible to use wei or ether
29(1 ether equals 1,000,000,000,000,000,000 wei).
30**/
31
32abstract contract Accountant is ProjectManager {
33    /**
34    Members can interact with the Project Manager (PM) trough D-Accountant.
35    For every donation received, D-Accountant provides the information to the PM with your donated amount.
36    */
37
38    address payable private _projectsAccount;
39    address payable private _maintenanceAccount;
40    address payable private _marketingAccount;
41    IPyth public pyth;
42    bytes32 public ethUsdPriceId;
43
44    constructor(
45        address payable projectsAccount,
46        address payable maintenanceAccount,
47        address payable marketingAccount,
48        address _pyth,
49        bytes32 _ethUsdPriceId
50    ) ProjectManager() {
51        require(projectsAccount != address(0), "zero projectsAccount");
52        require(maintenanceAccount != address(0), "zero maintenanceAccount");
53        require(marketingAccount != address(0), "zero marketingAccount");
54        require(_pyth != address(0), "zero pyth");
55        pyth = IPyth(_pyth);
56        ethUsdPriceId = _ethUsdPriceId;
57        _projectsAccount = projectsAccount;
58        _maintenanceAccount = maintenanceAccount;
59        _marketingAccount = marketingAccount;
60    }
61    //    function getPrice() public  returns ( PythStructs.Price memory price) {
62    //        IPyth pyth = IPyth(0x9b4503710cc8c53f75c30e6e4fda1a7064680ef2e0ee97acd2e3a7c37b3c830c); // CORE/USD on CORE
63    //        PythStructs.Price memory price = pyth.getPriceNoOlderThan(0x9b4503710cc8c53f75c30e6e4fda1a7064680ef2e0ee97acd2e3a7c37b3c830c, 60);
64    //        return price;
65    //    }
66
67    function getPrice() public view returns (uint256) {
68        PythStructs.Price memory pythPrice = pyth.getPriceNoOlderThan(ethUsdPriceId, 3600);
69        require(pythPrice.price > 0, "Pyth: invalid price");
70        require(pythPrice.expo < 0, "Pyth: unexpected positive exponent");
71        uint256 ethPrice18Decimals = (uint256(uint64(pythPrice.price)) * (10 ** 18)) /
72            (10 ** uint8(uint32(-1 * pythPrice.expo)));
73        require(ethPrice18Decimals > 0, "Pyth: price underflow");
74        uint256 oneDollarInWei = ((10 ** 18) * (10 ** 18)) / ethPrice18Decimals;
75        return oneDollarInWei;
76    }
77
78    function donateFunds() public payable {
79        uint256 value = msg.value;
80        address sender = msg.sender;
81        uint256 oneDollarInWei = getPrice();
82        if (value < 10 * oneDollarInWei) revert ErrorLibrary.MinDonationNotMet();
83
84        /**
85        Debt FREE !!
86        80% of all donations goes to projects
87        **/
88        uint256 eighty = (value * 8) / 10;
89        uint256 ten = value / 10;
90
91        _transfer(_projectsAccount, eighty);
92        _transfer(_marketingAccount, ten);
93        _transfer(_maintenanceAccount, ten);
94        // Store votes in dollar units (1 vote = $1 USD) so vote counts are
95        // stable across native-token price fluctuations.
96        fundAddress(sender, eighty / oneDollarInWei);
97    }
98    // Plain ETH transfers (empty calldata) route to donateFunds.
99    // Calls with non-empty calldata (mismatched function selectors) revert — no silent donations.
100    receive() external payable {
101        donateFunds();
102    }
103    function _transfer(address payable addr, uint256 amount) private {
104        (bool success, ) = addr.call{value: amount}("");
105        if (!success) revert ErrorLibrary.ETHTransferFailed();
106    }
107}
108