diff --git a/.gitignore b/.gitignore index db454d2..149de7c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ .DS_Store node_modules dist +build .env # Remove some common IDE working directories diff --git a/build/ABI/openStakingContractAbi.json b/build/ABI/openStakingContractAbi.json deleted file mode 100644 index 7a1115f..0000000 --- a/build/ABI/openStakingContractAbi.json +++ /dev/null @@ -1,953 +0,0 @@ -[ - { - "inputs": [], - "stateMutability": "nonpayable", - "type": "constructor" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "address", - "name": "id", - "type": "address" - }, - { - "indexed": false, - "internalType": "address", - "name": "staker", - "type": "address" - }, - { - "indexed": false, - "internalType": "address", - "name": "to", - "type": "address" - }, - { - "indexed": false, - "internalType": "address", - "name": "token", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "amountPaid", - "type": "uint256" - } - ], - "name": "BasePaid", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "previousOwner", - "type": "address" - }, - { - "indexed": true, - "internalType": "address", - "name": "newOwner", - "type": "address" - } - ], - "name": "OwnershipTransferred", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "address", - "name": "id", - "type": "address" - }, - { - "indexed": false, - "internalType": "address", - "name": "rewardToken", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "rewardAmount", - "type": "uint256" - } - ], - "name": "RewardAdded", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "address", - "name": "id", - "type": "address" - }, - { - "indexed": false, - "internalType": "address", - "name": "staker", - "type": "address" - }, - { - "indexed": false, - "internalType": "address", - "name": "to", - "type": "address" - }, - { - "indexed": false, - "internalType": "address[]", - "name": "rewardTokens", - "type": "address[]" - }, - { - "indexed": false, - "internalType": "uint256[]", - "name": "rewards", - "type": "uint256[]" - } - ], - "name": "RewardPaid", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "address", - "name": "id", - "type": "address" - }, - { - "indexed": false, - "internalType": "address", - "name": "tokenAddress", - "type": "address" - }, - { - "indexed": false, - "internalType": "address", - "name": "staker", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "amount", - "type": "uint256" - } - ], - "name": "Staked", - "type": "event" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "rewardToken", - "type": "address" - } - ], - "name": "addMarginalReward", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "id", - "type": "address" - }, - { - "internalType": "address", - "name": "rewardToken", - "type": "address" - } - ], - "name": "addMarginalRewardToPool", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - }, - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "name": "admins", - "outputs": [ - { - "internalType": "enum StakingBasics.AdminRole", - "name": "", - "type": "uint8" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "id", - "type": "address" - } - ], - "name": "allowedRewardTokenList", - "outputs": [ - { - "internalType": "address[]", - "name": "", - "type": "address[]" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "id", - "type": "address" - }, - { - "internalType": "address", - "name": "rewardToken", - "type": "address" - } - ], - "name": "allowedRewardTokens", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "id", - "type": "address" - } - ], - "name": "baseToken", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "creationSigner", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "factory", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "id", - "type": "address" - }, - { - "internalType": "address", - "name": "staker", - "type": "address" - }, - { - "internalType": "address", - "name": "rewardToken", - "type": "address" - } - ], - "name": "fakeRewardOf", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "id", - "type": "address" - }, - { - "internalType": "address", - "name": "rewardToken", - "type": "address" - } - ], - "name": "fakeRewardsTotal", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "freezeSweep", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "token", - "type": "address" - }, - { - "internalType": "string", - "name": "name", - "type": "string" - }, - { - "internalType": "address[]", - "name": "rewardTokens", - "type": "address[]" - } - ], - "name": "init", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "token", - "type": "address" - } - ], - "name": "initDefault", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "name": "inventory", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "id", - "type": "address" - } - ], - "name": "isTokenizable", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "id", - "type": "address" - } - ], - "name": "lockSeconds", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "id", - "type": "address" - } - ], - "name": "name", - "outputs": [ - { - "internalType": "string", - "name": "_name", - "type": "string" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "owner", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "renounceOwnership", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "id", - "type": "address" - }, - { - "internalType": "address", - "name": "staker", - "type": "address" - }, - { - "internalType": "address[]", - "name": "rewardTokens", - "type": "address[]" - } - ], - "name": "rewardOf", - "outputs": [ - { - "internalType": "uint256[]", - "name": "amounts", - "type": "uint256[]" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "id", - "type": "address" - }, - { - "internalType": "address", - "name": "rewardAddress", - "type": "address" - } - ], - "name": "rewardsTotal", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "id", - "type": "address" - }, - { - "internalType": "address", - "name": "admin", - "type": "address" - }, - { - "internalType": "enum StakingBasics.AdminRole", - "name": "role", - "type": "uint8" - } - ], - "name": "setAdmin", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "_signer", - "type": "address" - } - ], - "name": "setCreationSigner", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "id", - "type": "address" - }, - { - "internalType": "uint256", - "name": "_lockSeconds", - "type": "uint256" - } - ], - "name": "setLockSeconds", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "to", - "type": "address" - }, - { - "internalType": "address", - "name": "id", - "type": "address" - } - ], - "name": "stake", - "outputs": [ - { - "internalType": "uint256", - "name": "stakeAmount", - "type": "uint256" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "to", - "type": "address" - }, - { - "internalType": "address", - "name": "id", - "type": "address" - } - ], - "name": "stakeFor", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "id", - "type": "address" - }, - { - "internalType": "address", - "name": "staker", - "type": "address" - } - ], - "name": "stakeOf", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "staker", - "type": "address" - }, - { - "internalType": "address", - "name": "id", - "type": "address" - }, - { - "internalType": "uint256", - "name": "allocation", - "type": "uint256" - }, - { - "internalType": "bytes32", - "name": "salt", - "type": "bytes32" - }, - { - "internalType": "bytes", - "name": "allocatorSignature", - "type": "bytes" - } - ], - "name": "stakeWithAllocation", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "id", - "type": "address" - } - ], - "name": "stakedBalance", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "name": "stakings", - "outputs": [ - { - "internalType": "enum Staking.StakeType", - "name": "stakeType", - "type": "uint8" - }, - { - "internalType": "bool", - "name": "restrictedRewards", - "type": "bool" - }, - { - "internalType": "uint32", - "name": "contribStart", - "type": "uint32" - }, - { - "internalType": "uint32", - "name": "contribEnd", - "type": "uint32" - }, - { - "internalType": "uint32", - "name": "endOfLife", - "type": "uint32" - }, - { - "internalType": "uint32", - "name": "configHardCutOff", - "type": "uint32" - }, - { - "internalType": "uint16", - "name": "flags", - "type": "uint16" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "id", - "type": "address" - } - ], - "name": "sweepBase", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "sweepFrozen", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "id", - "type": "address" - }, - { - "internalType": "address[]", - "name": "rewardTokens", - "type": "address[]" - } - ], - "name": "sweepRewards", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "token", - "type": "address" - }, - { - "internalType": "address", - "name": "to", - "type": "address" - }, - { - "internalType": "uint256", - "name": "amount", - "type": "uint256" - } - ], - "name": "sweepToken", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "newOwner", - "type": "address" - } - ], - "name": "transferOwnership", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "bytes32", - "name": "", - "type": "bytes32" - } - ], - "name": "usedHashes", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "to", - "type": "address" - }, - { - "internalType": "address", - "name": "id", - "type": "address" - }, - { - "internalType": "uint256", - "name": "amount", - "type": "uint256" - } - ], - "name": "withdraw", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "to", - "type": "address" - }, - { - "internalType": "address", - "name": "id", - "type": "address" - } - ], - "name": "withdrawRewards", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "id", - "type": "address" - }, - { - "internalType": "address", - "name": "staker", - "type": "address" - } - ], - "name": "withdrawTimeOf", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - } -] diff --git a/build/ABI/standardStakingContractAbi.json b/build/ABI/standardStakingContractAbi.json deleted file mode 100644 index 6151123..0000000 --- a/build/ABI/standardStakingContractAbi.json +++ /dev/null @@ -1,430 +0,0 @@ -[ - { - "inputs": [ - { - "internalType": "string", - "name": "name_", - "type": "string" - }, - { - "internalType": "address", - "name": "tokenAddress_", - "type": "address" - }, - { - "internalType": "address", - "name": "rewardTokenAddress_", - "type": "address" - }, - { - "internalType": "uint256", - "name": "stakingStarts_", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "stakingEnds_", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "withdrawStarts_", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "withdrawEnds_", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "stakingCap_", - "type": "uint256" - } - ], - "stateMutability": "nonpayable", - "type": "constructor" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "token", - "type": "address" - }, - { - "indexed": true, - "internalType": "address", - "name": "staker_", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "requestedAmount_", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "stakedAmount_", - "type": "uint256" - } - ], - "name": "Staked", - "type": "event" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "withdrawableAmount", - "type": "uint256" - } - ], - "name": "addMarginalReward", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "rewardAmount", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "withdrawableAmount", - "type": "uint256" - } - ], - "name": "addReward", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "earlyWithdrawReward", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "name", - "outputs": [ - { - "internalType": "string", - "name": "", - "type": "string" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "rewardBalance", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "rewardSetter", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "rewardState", - "outputs": [ - { - "internalType": "uint256", - "name": "rewardBalance", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "rewardsTotal", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "earlyWithdrawReward", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "rewardTokenAddress", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "rewardsTotal", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "amount", - "type": "uint256" - } - ], - "name": "stake", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "staker", - "type": "address" - }, - { - "internalType": "uint256", - "name": "amount", - "type": "uint256" - } - ], - "name": "stakeFor", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "account", - "type": "address" - } - ], - "name": "stakeOf", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "stakeState", - "outputs": [ - { - "internalType": "uint256", - "name": "stakedTotal", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "stakingCap", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "stakedBalance", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "withdrawnEarly", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "stakedBalance", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "stakedTotal", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "stakingCap", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "stakingEnds", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "stakingStarts", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "tokenAddress", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "amount", - "type": "uint256" - } - ], - "name": "withdraw", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "withdrawEnds", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "withdrawStarts", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - } -] diff --git a/build/ABI/tokenContractAbi.json b/build/ABI/tokenContractAbi.json deleted file mode 100644 index 893aec6..0000000 --- a/build/ABI/tokenContractAbi.json +++ /dev/null @@ -1,563 +0,0 @@ -[ - { - "inputs": [ - { - "internalType": "uint256", - "name": "chainId_", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "nonpayable", - "type": "constructor" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "src", - "type": "address" - }, - { - "indexed": true, - "internalType": "address", - "name": "guy", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "wad", - "type": "uint256" - } - ], - "name": "Approval", - "type": "event" - }, - { - "anonymous": true, - "inputs": [ - { - "indexed": true, - "internalType": "bytes4", - "name": "sig", - "type": "bytes4" - }, - { - "indexed": true, - "internalType": "address", - "name": "usr", - "type": "address" - }, - { - "indexed": true, - "internalType": "bytes32", - "name": "arg1", - "type": "bytes32" - }, - { - "indexed": true, - "internalType": "bytes32", - "name": "arg2", - "type": "bytes32" - }, - { - "indexed": false, - "internalType": "bytes", - "name": "data", - "type": "bytes" - } - ], - "name": "LogNote", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "src", - "type": "address" - }, - { - "indexed": true, - "internalType": "address", - "name": "dst", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "wad", - "type": "uint256" - } - ], - "name": "Transfer", - "type": "event" - }, - { - "constant": true, - "inputs": [], - "name": "DOMAIN_SEPARATOR", - "outputs": [ - { - "internalType": "bytes32", - "name": "", - "type": "bytes32" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "PERMIT_TYPEHASH", - "outputs": [ - { - "internalType": "bytes32", - "name": "", - "type": "bytes32" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - }, - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "name": "allowance", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "address", - "name": "usr", - "type": "address" - }, - { - "internalType": "uint256", - "name": "wad", - "type": "uint256" - } - ], - "name": "approve", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "name": "balanceOf", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "address", - "name": "usr", - "type": "address" - }, - { - "internalType": "uint256", - "name": "wad", - "type": "uint256" - } - ], - "name": "burn", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "decimals", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "address", - "name": "guy", - "type": "address" - } - ], - "name": "deny", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "address", - "name": "usr", - "type": "address" - }, - { - "internalType": "uint256", - "name": "wad", - "type": "uint256" - } - ], - "name": "mint", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "address", - "name": "src", - "type": "address" - }, - { - "internalType": "address", - "name": "dst", - "type": "address" - }, - { - "internalType": "uint256", - "name": "wad", - "type": "uint256" - } - ], - "name": "move", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "name", - "outputs": [ - { - "internalType": "string", - "name": "", - "type": "string" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "name": "nonces", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "address", - "name": "holder", - "type": "address" - }, - { - "internalType": "address", - "name": "spender", - "type": "address" - }, - { - "internalType": "uint256", - "name": "nonce", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "expiry", - "type": "uint256" - }, - { - "internalType": "bool", - "name": "allowed", - "type": "bool" - }, - { - "internalType": "uint8", - "name": "v", - "type": "uint8" - }, - { - "internalType": "bytes32", - "name": "r", - "type": "bytes32" - }, - { - "internalType": "bytes32", - "name": "s", - "type": "bytes32" - } - ], - "name": "permit", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "address", - "name": "usr", - "type": "address" - }, - { - "internalType": "uint256", - "name": "wad", - "type": "uint256" - } - ], - "name": "pull", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "address", - "name": "usr", - "type": "address" - }, - { - "internalType": "uint256", - "name": "wad", - "type": "uint256" - } - ], - "name": "push", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "address", - "name": "guy", - "type": "address" - } - ], - "name": "rely", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "symbol", - "outputs": [ - { - "internalType": "string", - "name": "", - "type": "string" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "totalSupply", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "address", - "name": "dst", - "type": "address" - }, - { - "internalType": "uint256", - "name": "wad", - "type": "uint256" - } - ], - "name": "transfer", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "address", - "name": "src", - "type": "address" - }, - { - "internalType": "address", - "name": "dst", - "type": "address" - }, - { - "internalType": "uint256", - "name": "wad", - "type": "uint256" - } - ], - "name": "transferFrom", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "version", - "outputs": [ - { - "internalType": "string", - "name": "", - "type": "string" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "name": "wards", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - } -] diff --git a/build/src/config.js b/build/src/config.js deleted file mode 100644 index c7d2474..0000000 --- a/build/src/config.js +++ /dev/null @@ -1,34 +0,0 @@ -"use strict"; -// src/config.ts -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.PORT = exports.CRON_SCHEDULE = exports.DB_COLLECTION_SNAP_HODL_CONFIG = exports.DB_COLLECTION_SNAP_CONFIG_BALANCE = exports.DB_COLLECTION_STAKING_SNAPSHOT = exports.DB_COLLECTION = exports.DB_NAME = exports.DB_CONNECTION_STRING = exports.APP_NAME = void 0; -const dotenv_1 = __importDefault(require("dotenv")); -dotenv_1.default.config(); -exports.APP_NAME = process.env.APP_NAME; -exports.DB_CONNECTION_STRING = process.env.DB_CONNECTION_STRING; -exports.DB_NAME = process.env.DB_NAME; -exports.DB_COLLECTION = process.env.DB_COLLECTION; -exports.DB_COLLECTION_STAKING_SNAPSHOT = process.env.DB_COLLECTION_STAKING_SNAPSHOT; -exports.DB_COLLECTION_SNAP_CONFIG_BALANCE = process.env.DB_COLLECTION_SNAP_CONFIG_BALANCE; -exports.DB_COLLECTION_SNAP_HODL_CONFIG = process.env.DB_COLLECTION_SNAP_HODL_CONFIG; -exports.CRON_SCHEDULE = process.env.CRON_SCHEDULE; -exports.PORT = process.env.PORT; -// An array to hold the environment variables -const envVariables = [ - { name: 'APP_NAME', value: exports.APP_NAME }, - { name: 'DB_CONNECTION_STRING', value: exports.DB_CONNECTION_STRING }, - { name: 'DB_NAME', value: exports.DB_NAME }, - { name: 'DB_COLLECTION', value: exports.DB_COLLECTION }, - { name: 'DB_COLLECTION_STAKING_SNAPSHOT', value: exports.DB_COLLECTION_STAKING_SNAPSHOT }, - { name: 'DB_COLLECTION_SNAP_CONFIG_BALANCE', value: exports.DB_COLLECTION_SNAP_CONFIG_BALANCE }, - { name: 'CRON_SCHEDULE', value: exports.CRON_SCHEDULE } -]; -// Check if each environment variable is set -envVariables.forEach(envVar => { - if (!envVar.value) { - throw new Error(`${envVar.name} is not set. Please set this environment variable.`); - } -}); diff --git a/build/src/controllers/snapHodlConfigController.js b/build/src/controllers/snapHodlConfigController.js deleted file mode 100644 index 58d015f..0000000 --- a/build/src/controllers/snapHodlConfigController.js +++ /dev/null @@ -1,144 +0,0 @@ -"use strict"; -// src/controllers/snapHodlConfigController.ts -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.getAllSnapShots = exports.getSnapShotBySnapShotIdAndAddress = exports.createSnapHodlConfig = exports.getSnapHodlConfigs = exports.retrieveSnapHodlConfigs = void 0; -const SnapHodlConfig_1 = __importDefault(require("../models/SnapHodlConfig")); -const SnapHodlConfigBalance_1 = __importDefault(require("../models/SnapHodlConfigBalance")); -function sortStakingContractData(data) { - return data.sort((a, b) => a.stakingPoolName.localeCompare(b.stakingPoolName)); -} -function toLowerCaseStakingContractData(data) { - return data.map(item => (Object.assign(Object.assign({}, item), { stakingContractAddress: item.stakingContractAddress.toLowerCase(), tokenContractAddress: item.tokenContractAddress.toLowerCase(), stakingPoolType: item.stakingPoolType.toLowerCase() }))); -} -const retrieveSnapHodlConfigs = () => __awaiter(void 0, void 0, void 0, function* () { - try { - return yield SnapHodlConfig_1.default.find(); - } - catch (err) { - if (err instanceof Error) { - throw new Error(err.message); - } - else { - throw new Error('An error occurred when attempting to fetch SnapHodlConfigs'); - } - } -}); -exports.retrieveSnapHodlConfigs = retrieveSnapHodlConfigs; -const getSnapHodlConfigs = (req, res) => __awaiter(void 0, void 0, void 0, function* () { - try { - const snapHodlConfigs = yield (0, exports.retrieveSnapHodlConfigs)(); - res.json(snapHodlConfigs); - } - catch (err) { - if (err instanceof Error) { - res.status(500).json({ message: err.message }); - } - else { - res.status(500).json({ message: 'An error occurred when attempting to request SnapHodlConfigs to be retrieved' }); - } - } -}); -exports.getSnapHodlConfigs = getSnapHodlConfigs; -const createSnapHodlConfig = (req, res) => __awaiter(void 0, void 0, void 0, function* () { - const { snapShotConfigName, isActive, stakingContractData } = req.body; - // Convert stakingContractData values to lower case - const lowerCaseStakingContractData = toLowerCaseStakingContractData(stakingContractData); - // Sort stakingContractData by stakingPoolName for consistent comparison - const sortedStakingContractData = sortStakingContractData(lowerCaseStakingContractData); - // Check for duplicate stakingContractData - const duplicateConfig = yield SnapHodlConfig_1.default.findOne({ - stakingContractData: { $eq: sortedStakingContractData }, - }); - if (duplicateConfig) { - return res.status(400).json({ - message: `Duplicate stakingContractData detected. Please use the ${duplicateConfig.snapShotConfigName} config, which has the same stakingContractData, or change the stakingContractData for the new config.` - }); - } - const newSnapHodlConfig = new SnapHodlConfig_1.default({ - snapShotConfigName, - isActive, - stakingContractData: sortedStakingContractData, - }); - try { - const savedSnapHodlConfig = yield newSnapHodlConfig.save(); - res.json(savedSnapHodlConfig); - } - catch (err) { - if (err instanceof Error) { - res.status(500).json({ message: err.message }); - } - else { - res.status(500).json({ message: 'An error occurred' }); - } - } -}); -exports.createSnapHodlConfig = createSnapHodlConfig; -const getSnapShotBySnapShotIdAndAddress = (req, res) => __awaiter(void 0, void 0, void 0, function* () { - try { - let { snapShotId, address } = req.params; - const { raw } = req.query; - address = address.toLowerCase(); - const snapHodlConfigBalance = yield SnapHodlConfigBalance_1.default.findOne({ snapHodlConfigId: snapShotId }); - if (!snapHodlConfigBalance) { - return res.status(404).json({ message: 'SnapShot not found' }); - } - const snapShotBalance = snapHodlConfigBalance.totalStakedBalance.get(address); - if (!snapShotBalance) { - return res.status(404).json({ message: 'Address not found in SnapShot' }); - } - if (raw === 'true') { - return res.send(snapShotBalance.toString()); - } - else { - const result = { - snapShotConfigName: snapHodlConfigBalance.snapShotConfigName, - address: address, - snapShotBalance: snapShotBalance, - updatedAt: snapHodlConfigBalance.updatedAt, - }; - return res.json(result); - } - } - catch (error) { - if (error instanceof Error) { - return res.status(500).json({ message: error.message }); - } - else { - return res.status(500).json({ message: "An unexpected error occurred." }); - } - } -}); -exports.getSnapShotBySnapShotIdAndAddress = getSnapShotBySnapShotIdAndAddress; -// New function to retrieve all documents from DB_COLLECTION_SNAP_CONFIG_BALANCE -const getAllSnapShots = (req, res) => __awaiter(void 0, void 0, void 0, function* () { - try { - const page = parseInt(req.query.page) || 1; // defaults to 1 if not provided - const limit = parseInt(req.query.limit) || 10; // defaults to 10 if not provided - const skip = (page - 1) * limit; - // Find all documents in the collection with pagination - const snapHodlConfigBalances = yield SnapHodlConfigBalance_1.default.find({}).skip(skip).limit(limit); - // Send the result as a JSON response - return res.json(snapHodlConfigBalances); - } - catch (error) { - if (error instanceof Error) { - return res.status(500).json({ message: error.message }); - } - else { - return res.status(500).json({ message: "An unexpected error occurred." }); - } - } -}); -exports.getAllSnapShots = getAllSnapShots; diff --git a/build/src/cronJobs.js b/build/src/cronJobs.js deleted file mode 100644 index d1575b1..0000000 --- a/build/src/cronJobs.js +++ /dev/null @@ -1,55 +0,0 @@ -"use strict"; -// src/cronJobs.ts -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.scheduleJobs = void 0; -const node_cron_1 = __importDefault(require("node-cron")); -const lodash_1 = __importDefault(require("lodash")); -const snapHodlConfigController_1 = require("./controllers/snapHodlConfigController"); -const helpers_1 = require("./utils/helpers"); -const config_1 = require("./config"); -const scheduleJobs = () => { - // Schedule cron job - node_cron_1.default.schedule(config_1.CRON_SCHEDULE, () => __awaiter(void 0, void 0, void 0, function* () { - console.log('Running the job every 5 minutes'); - try { - // Fetch data from the API - const snapHodlConfigs = yield (0, snapHodlConfigController_1.retrieveSnapHodlConfigs)(); - let uniqueStakingContractDataItems = []; - for (const item of snapHodlConfigs) { - const { stakingContractData, isActive } = item; - if (isActive) { - uniqueStakingContractDataItems = [ - ...uniqueStakingContractDataItems, - ...stakingContractData - ]; - } - } - // Filter unique stakingContractData based on stakingContractAddress, tokenContractAddress, and chainId - uniqueStakingContractDataItems = lodash_1.default.uniqBy(uniqueStakingContractDataItems, ({ stakingContractAddress, tokenContractAddress, chainId }) => { - return `${stakingContractAddress}-${tokenContractAddress}-${chainId}`; - }); - // Start processing uniqueStakingContractDataItems concurrently - yield Promise.all(uniqueStakingContractDataItems.map(item => (0, helpers_1.processStakingContractDataItem)(item, config_1.DB_NAME, config_1.DB_COLLECTION_STAKING_SNAPSHOT, config_1.DB_CONNECTION_STRING, config_1.APP_NAME))); - // After processStakingContractDataItem function calls - yield Promise.all(snapHodlConfigs.map(helpers_1.getSnapHodlConfigBalance)); - const utcStr = new Date().toUTCString(); - console.log(`Cron finished at:`, utcStr); - } - catch (error) { - console.error("Error fetching data from the API or processing data:", error); - } - })); -}; -exports.scheduleJobs = scheduleJobs; diff --git a/build/src/index.js b/build/src/index.js deleted file mode 100644 index 4d43a3c..0000000 --- a/build/src/index.js +++ /dev/null @@ -1,45 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -// src/index.ts -const config_1 = require("./config"); -const express_1 = __importDefault(require("express")); -const dotenv_1 = __importDefault(require("dotenv")); -const mongoose_1 = __importDefault(require("mongoose")); -const cronJobs_1 = require("./cronJobs"); -const snapHodlConfigController_1 = require("./controllers/snapHodlConfigController"); -const cors_1 = __importDefault(require("cors")); -dotenv_1.default.config(); -const app = (0, express_1.default)(); -app.use(express_1.default.json()); -// Enable all CORS requests -app.use((0, cors_1.default)()); -mongoose_1.default.connect(config_1.DB_CONNECTION_STRING, { - dbName: config_1.DB_NAME -}) - .then(() => console.log('MongoDB connection established')) - .catch(err => console.log('MongoDB connection error:', err)); -(0, cronJobs_1.scheduleJobs)(); -app.get('/', (req, res) => __awaiter(void 0, void 0, void 0, function* () { - res.send('Server running'); -})); -app.get('/snapHodlConfig', snapHodlConfigController_1.getSnapHodlConfigs); -app.post('/snapHodlConfig', snapHodlConfigController_1.createSnapHodlConfig); -app.get('/getSnapShotBySnapShotIdAndAddress/:snapShotId/:address', snapHodlConfigController_1.getSnapShotBySnapShotIdAndAddress); -app.get('/getSnapShotBySnapShotIdAndAddress/:snapShotId/:address/raw', snapHodlConfigController_1.getSnapShotBySnapShotIdAndAddress); -app.get('/getAllSnapShots', snapHodlConfigController_1.getAllSnapShots); -// added snapshots -app.listen(config_1.PORT, () => { - console.log(`Server is running on ${config_1.PORT}`); -}); diff --git a/build/src/models/SnapHodlConfig.js b/build/src/models/SnapHodlConfig.js deleted file mode 100644 index e0615cc..0000000 --- a/build/src/models/SnapHodlConfig.js +++ /dev/null @@ -1,83 +0,0 @@ -"use strict"; -// src/SnapHodlConfig.ts -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { - desc = { enumerable: true, get: function() { return m[k]; } }; - } - Object.defineProperty(o, k2, desc); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.stakingContractDataSchema = void 0; -const mongoose_1 = __importStar(require("mongoose")); -const config_1 = require("../config"); -const dotenv_1 = __importDefault(require("dotenv")); -dotenv_1.default.config(); -const ethereumAddressRegex = /^(0x)?[0-9a-f]{40}$/i; -exports.stakingContractDataSchema = new mongoose_1.Schema({ - _id: false, - stakingPoolName: { type: String, required: true }, - stakingContractAddress: { - type: String, - required: true, - validate: { - validator: function (value) { - return ethereumAddressRegex.test(value); - }, - message: 'A valid EVM address is required for stakingContractAddress.' - } - }, - stakingPoolType: { type: String, enum: ['standard', 'open'], required: true }, - tokenContractAddress: { - type: String, - required: true, - validate: { - validator: function (value) { - return ethereumAddressRegex.test(value); - }, - message: 'A valid EVM address is required for tokenContractAddress.' - } - }, - chainId: { type: String, required: true }, - fromBlock: { type: Number, min: 0, required: true }, - toBlock: { - type: mongoose_1.Schema.Types.Mixed, - required: true, - validate: { - validator: function (value) { - if (typeof value === 'string') { - return value === 'latest'; - } - return Number.isInteger(value) && value >= 0; - }, - message: 'Invalid value for `toBlock`. Must be a non-negative integer or "latest".' - } - }, - blockIterationSize: { type: Number, min: 0, required: true }, -}); -const SnapHodlConfigSchema = new mongoose_1.Schema({ - snapShotConfigName: { type: String, required: true }, - isActive: { type: Boolean, required: true }, - stakingContractData: [exports.stakingContractDataSchema] -}, { collection: config_1.DB_COLLECTION_SNAP_HODL_CONFIG }); -const SnapHodlConfigModel = mongoose_1.default.model('SnapHodlConfigModel', SnapHodlConfigSchema); -exports.default = SnapHodlConfigModel; diff --git a/build/src/models/SnapHodlConfigBalance.js b/build/src/models/SnapHodlConfigBalance.js deleted file mode 100644 index 9ee43f3..0000000 --- a/build/src/models/SnapHodlConfigBalance.js +++ /dev/null @@ -1,39 +0,0 @@ -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { - desc = { enumerable: true, get: function() { return m[k]; } }; - } - Object.defineProperty(o, k2, desc); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const mongoose_1 = __importStar(require("mongoose")); -const SnapHodlConfig_1 = require("./SnapHodlConfig"); -const config_1 = require("../config"); -const stakingContractDataBalanceSchema = new mongoose_1.Schema(Object.assign(Object.assign({}, SnapHodlConfig_1.stakingContractDataSchema.obj), { totalStakedBalance: { type: String, required: true } })); -const SnapHodlConfigBalanceSchema = new mongoose_1.Schema({ - snapHodlConfigId: { type: mongoose_1.Schema.Types.ObjectId, required: true }, - snapShotConfigName: { type: String, required: true }, - stakingContractDataBalances: [stakingContractDataBalanceSchema], - totalStakedBalance: { type: Map, of: String }, - createdAt: { type: Date, required: true }, - updatedAt: { type: Date, required: true }, -}, { collection: config_1.DB_COLLECTION_SNAP_CONFIG_BALANCE }); -const SnapHodlConfigBalanceModel = mongoose_1.default.model('SnapHodlConfigBalanceModel', SnapHodlConfigBalanceSchema); -exports.default = SnapHodlConfigBalanceModel; diff --git a/build/src/openStaking.js b/build/src/openStaking.js deleted file mode 100644 index 6772763..0000000 --- a/build/src/openStaking.js +++ /dev/null @@ -1,93 +0,0 @@ -"use strict"; -// src/openStaking.ts -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.getOpenStakingStakedBalances = exports.getUniqueStakersFromOpenStaking = void 0; -const bignumber_js_1 = require("bignumber.js"); -const tokenContractAbi_json_1 = __importDefault(require("../ABI/tokenContractAbi.json")); -const openStakingContractAbi_json_1 = __importDefault(require("../ABI/openStakingContractAbi.json")); -const stakingService_1 = require("./services/stakingService"); -function getUniqueStakersFromOpenStaking(stakingPoolName, stakingContractAddress, stakingPoolType, tokenContractAddress, chainId, web3Instance, fromBlock, toBlock, blockIterationSize, dbName, dbCollection, connectionString) { - return __awaiter(this, void 0, void 0, function* () { - console.log(`Fetching Unique Stakers from Open Staking Contract: `, stakingPoolName, " | ", stakingContractAddress); - const existingSnapshot = yield (0, stakingService_1.getLatestStakingSnapshot)(stakingContractAddress, tokenContractAddress, chainId, dbName, dbCollection, connectionString); - const uniqueStakers = new Set(existingSnapshot ? existingSnapshot.uniqueStakers : []); - // Convert block identifiers to actual block numbers - const currentBlockNumber = yield web3Instance.eth.getBlockNumber(); - const resolvedFromBlock = fromBlock === "latest" ? currentBlockNumber : fromBlock; - const resolvedToBlock = toBlock === "latest" ? currentBlockNumber : toBlock; - const step = blockIterationSize; - let startBlock = resolvedFromBlock; - if (existingSnapshot && existingSnapshot.latestBlockCaptured >= resolvedFromBlock) { - startBlock = existingSnapshot.latestBlockCaptured + 1; - } - const tokenContract = new web3Instance.eth.Contract(tokenContractAbi_json_1.default, tokenContractAddress); - const transferEventSignature = tokenContract.events.Transfer.signature; - for (let currentBlock = startBlock; currentBlock < resolvedToBlock; currentBlock += step) { - const endBlock = Math.min(currentBlock + step - 1, resolvedToBlock); - const transferEventFilter = { - fromBlock: currentBlock, - toBlock: endBlock, - address: tokenContractAddress, - topics: [transferEventSignature, null, web3Instance.eth.abi.encodeParameter("address", stakingContractAddress)], - }; - try { - const logs = yield web3Instance.eth.getPastLogs(transferEventFilter); - console.log("Fetched logs:", logs); - logs.forEach((log) => { - console.log("Log:", log); - const eventInterface = tokenContract.options.jsonInterface.find((i) => i.signature === log.topics[0]); - if (!eventInterface) { - console.error("Event interface not found for signature:", log.topics[0]); - return; - } - const inputs = eventInterface.inputs; - const event = web3Instance.eth.abi.decodeLog(inputs, log.data, log.topics.slice(1)); - console.log("Decoded event:", event); - // Check if the destination address matches the staking contract address - if (event.dst.toLowerCase() === stakingContractAddress.toLowerCase()) { - uniqueStakers.add(event.src.toLowerCase()); - } - }); - console.log("Unique stakers fetched for blocks", currentBlock, "to", endBlock); - yield (0, stakingService_1.saveStakingSnapshot)(stakingPoolName, stakingContractAddress, stakingPoolType, tokenContractAddress, chainId, endBlock, Array.from(uniqueStakers), dbName, dbCollection, connectionString); - } - catch (error) { - console.error("Error fetching ERC20 transfers to Staking Contract:", error); - } - } - return uniqueStakers; - }); -} -exports.getUniqueStakersFromOpenStaking = getUniqueStakersFromOpenStaking; -function getOpenStakingStakedBalances(stakingPoolName, stakingContractAddress, tokenContractAddress, chainId, uniqueStakers, decimals, web3Instance, dbName, dbCollection, connectionString) { - return __awaiter(this, void 0, void 0, function* () { - console.log(`Fetching staked balances from Open Staking Contract: `, stakingPoolName, " | ", stakingContractAddress); - const stakingContract = new web3Instance.eth.Contract(openStakingContractAbi_json_1.default, stakingContractAddress); - const stakedBalances = {}; - try { - for (const stakerAddress of uniqueStakers) { - const balanceRaw = yield stakingContract.methods.stakeOf(tokenContractAddress, stakerAddress).call(); - const humanReadableBalance = new bignumber_js_1.BigNumber(balanceRaw).dividedBy(new bignumber_js_1.BigNumber(10).pow(decimals)).toString(); - stakedBalances[stakerAddress] = humanReadableBalance; - } - yield (0, stakingService_1.saveStakedBalances)(stakingContractAddress, tokenContractAddress, chainId, stakedBalances, dbName, dbCollection, connectionString); - } - catch (error) { - console.error("Error fetching staked balances from Open Staking Contract:", error); - } - return stakedBalances; - }); -} -exports.getOpenStakingStakedBalances = getOpenStakingStakedBalances; diff --git a/build/src/services/stakingService.js b/build/src/services/stakingService.js deleted file mode 100644 index b22b5a7..0000000 --- a/build/src/services/stakingService.js +++ /dev/null @@ -1,110 +0,0 @@ -"use strict"; -// src/services/stakingService.ts -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.saveStakedBalances = exports.saveStakingSnapshot = exports.getLatestStakingSnapshot = void 0; -const mongodb_1 = require("mongodb"); -function getLatestStakingSnapshot(stakingContractAddress, tokenContractAddress, chainId, dbName, dbCollection, connectionString) { - return __awaiter(this, void 0, void 0, function* () { - const client = new mongodb_1.MongoClient(connectionString); - let snapshot = null; - try { - yield client.connect(); - const database = client.db(dbName); - const collection = database.collection(dbCollection); - const filter = { - stakingContractAddress, - tokenContractAddress, - chainId - }; - snapshot = yield collection.findOne(filter); - } - catch (err) { - console.error("Error fetching the latest staking snapshot from the database:", err); - } - finally { - yield client.close(); - } - return snapshot; - }); -} -exports.getLatestStakingSnapshot = getLatestStakingSnapshot; -function saveStakingSnapshot(stakingPoolName, stakingContractAddress, stakingPoolType, tokenContractAddress, chainId, latestBlockCaptured, uniqueStakers, dbName, dbCollection, connectionString) { - return __awaiter(this, void 0, void 0, function* () { - const client = new mongodb_1.MongoClient(connectionString); - try { - yield client.connect(); - const database = client.db(dbName); - const collection = database.collection(dbCollection); - const snapshot = { - stakingPoolName, - stakingContractAddress, - stakingPoolType, - tokenContractAddress, - chainId, - latestBlockCaptured, - uniqueStakers, - timestamp: new Date() - }; - const filter = { - stakingContractAddress, - tokenContractAddress, - chainId - }; - const update = { - $set: snapshot - }; - const options = { - upsert: true - }; - yield collection.updateOne(filter, update, options); - } - catch (err) { - console.error("Error saving staking snapshot to the database:", err); - } - finally { - yield client.close(); - } - }); -} -exports.saveStakingSnapshot = saveStakingSnapshot; -function saveStakedBalances(stakingContractAddress, tokenContractAddress, chainId, stakedBalances, dbName, dbCollection, connectionString) { - return __awaiter(this, void 0, void 0, function* () { - const client = new mongodb_1.MongoClient(connectionString); - try { - yield client.connect(); - const database = client.db(dbName); - const collection = database.collection(dbCollection); - const filter = { - stakingContractAddress, - tokenContractAddress, - chainId - }; - const update = { - $set: { - stakedBalances, - timestamp: new Date() - } - }; - const options = { - upsert: true - }; - yield collection.updateOne(filter, update, options); - } - catch (err) { - console.error("Error saving staked balances to the database:", err); - } - finally { - yield client.close(); - } - }); -} -exports.saveStakedBalances = saveStakedBalances; diff --git a/build/src/standardStaking.js b/build/src/standardStaking.js deleted file mode 100644 index 891afda..0000000 --- a/build/src/standardStaking.js +++ /dev/null @@ -1,96 +0,0 @@ -"use strict"; -// src/standardStaking.ts -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.getStakedBalances = exports.getUniqueStakers = void 0; -const standardStakingContractAbi_json_1 = __importDefault(require("../ABI/standardStakingContractAbi.json")); -const bignumber_js_1 = require("bignumber.js"); -const stakingService_1 = require("./services/stakingService"); -function getUniqueStakers(stakingPoolName, stakingContractAddress, stakingPoolType, tokenContractAddress, chainId, web3Instance, fromBlock, toBlock, blockIterationSize, dbName, dbCollection, connectionString) { - return __awaiter(this, void 0, void 0, function* () { - console.log(`Fetching unique stakers from Staking Contract: `, stakingPoolName, " | ", stakingContractAddress); - const existingSnapshot = yield (0, stakingService_1.getLatestStakingSnapshot)(stakingContractAddress, tokenContractAddress, chainId, dbName, dbCollection, connectionString); - const uniqueStakers = new Set(existingSnapshot ? existingSnapshot.uniqueStakers : []); - const step = blockIterationSize; - // Convert block identifiers to actual block numbers - const currentBlockNumber = yield web3Instance.eth.getBlockNumber(); - const resolvedFromBlock = fromBlock === "latest" ? currentBlockNumber : fromBlock; - const resolvedToBlock = toBlock === "latest" ? currentBlockNumber : toBlock; - const stakingContract = new web3Instance.eth.Contract(standardStakingContractAbi_json_1.default, stakingContractAddress); - let startBlock = resolvedFromBlock; - if (existingSnapshot && existingSnapshot.latestBlockCaptured >= resolvedFromBlock) { - startBlock = existingSnapshot.latestBlockCaptured + 1; - } - for (let currentBlock = startBlock; currentBlock < resolvedToBlock; currentBlock += step) { - const endBlock = Math.min(currentBlock + step - 1, resolvedToBlock); - const stakedEventFilter = { - fromBlock: currentBlock, - toBlock: endBlock, - address: stakingContractAddress, - topics: [stakingContract.events.Staked.signature], - }; - try { - const logs = yield web3Instance.eth.getPastLogs(stakedEventFilter); - // console.log("Fetched logs:", logs); - logs.forEach((log) => { - const eventInterface = stakingContract.options.jsonInterface.find((i) => i.signature === log.topics[0]); - if (!eventInterface) { - console.error("Event interface not found for signature:", log.topics[0]); - return; - } - const inputs = eventInterface.inputs; - const event = web3Instance.eth.abi.decodeLog(inputs, log.data, log.topics.slice(1)); - console.log("Decoded event:", event); - const stakerAddress = event["staker_"].toLowerCase(); - uniqueStakers.add(stakerAddress); - }); - console.log("Unique stakers fetched for blocks", currentBlock, "to", endBlock); - yield (0, stakingService_1.saveStakingSnapshot)(stakingPoolName, stakingContractAddress, stakingPoolType, tokenContractAddress, chainId, endBlock, Array.from(uniqueStakers), dbName, dbCollection, connectionString); - } - catch (error) { - console.error("Error fetching unique stakers:", error); - } - } - return Array.from(uniqueStakers); - }); -} -exports.getUniqueStakers = getUniqueStakers; -function getStakedBalances(stakingPoolName, stakingContractAddress, stakingPoolType, tokenContractAddress, chainId, stakers, decimals, web3Instance, dbName, dbCollection, connectionString) { - return __awaiter(this, void 0, void 0, function* () { - console.log(`Fetching staked balances: `, stakingPoolName, " | ", stakingContractAddress); - const stakedBalances = {}; - const stakingContract = new web3Instance.eth.Contract(standardStakingContractAbi_json_1.default, stakingContractAddress); - try { - for (const staker of stakers) { - try { - const balanceRaw = yield stakingContract.methods.stakeOf(staker).call(); - const humanReadableBalance = new bignumber_js_1.BigNumber(balanceRaw) - .dividedBy(new bignumber_js_1.BigNumber(10).pow(decimals)) - .toString(); - stakedBalances[staker] = humanReadableBalance; - } - catch (error) { - console.error(`Error fetching staked balance for ${staker}:`, error); - } - } - yield (0, stakingService_1.saveStakedBalances)(stakingContractAddress, tokenContractAddress, chainId, stakedBalances, dbName, dbCollection, connectionString); - } - catch (error) { - console.error("Error fetching staked balances from Standard Staking Contract:", error); - } - console.log("Staked balances fetched."); - return stakedBalances; - }); -} -exports.getStakedBalances = getStakedBalances; diff --git a/build/src/types.js b/build/src/types.js deleted file mode 100644 index 1ef6be6..0000000 --- a/build/src/types.js +++ /dev/null @@ -1,3 +0,0 @@ -"use strict"; -// src/types.ts -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/build/src/utils/getRpcUrl.js b/build/src/utils/getRpcUrl.js deleted file mode 100644 index 7afcf05..0000000 --- a/build/src/utils/getRpcUrl.js +++ /dev/null @@ -1,38 +0,0 @@ -"use strict"; -// src/utils/getRpcUrl.ts -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.getRpcUrl = void 0; -const mongodb_1 = require("mongodb"); -const getRpcUrl = (chainId, appName = "snapshot", DB_CONNECTION_STRING, DB_NAME, DB_COLLECTION) => __awaiter(void 0, void 0, void 0, function* () { - const client = new mongodb_1.MongoClient(DB_CONNECTION_STRING); - try { - yield client.connect(); - const db = client.db(DB_NAME); - const collection = db.collection(DB_COLLECTION); - const document = yield collection.findOne({ appName }); - if (document) { - const chainIdToNetworkMap = document.chainIdToNetworkMap; - const rpcDetails = chainIdToNetworkMap.find((item) => item.chainId === chainId); - if (rpcDetails) { - return rpcDetails.jsonRpcUrl; - } - } - } - catch (error) { - console.error("Error fetching RPC URL:", error); - } - finally { - yield client.close(); - } - return undefined; -}); -exports.getRpcUrl = getRpcUrl; diff --git a/build/src/utils/getTokenDecimals.js b/build/src/utils/getTokenDecimals.js deleted file mode 100644 index 30f8291..0000000 --- a/build/src/utils/getTokenDecimals.js +++ /dev/null @@ -1,33 +0,0 @@ -"use strict"; -// src/utils/getTokenDecimals.ts -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.getTokenDecimals = void 0; -const tokenContractAbi_json_1 = __importDefault(require("../../ABI/tokenContractAbi.json")); -function getTokenDecimals(tokenContractAddress, web3) { - return __awaiter(this, void 0, void 0, function* () { - console.log("Fetching token decimals..."); - let decimals = 18; - try { - const tokenContract = new web3.eth.Contract(tokenContractAbi_json_1.default, tokenContractAddress); - decimals = parseInt(yield tokenContract.methods.decimals().call()); - } - catch (error) { - console.error("Error fetching token decimals:", error); - } - console.log("Token decimals fetched."); - return decimals; - }); -} -exports.getTokenDecimals = getTokenDecimals; diff --git a/build/src/utils/helpers.js b/build/src/utils/helpers.js deleted file mode 100644 index a46f291..0000000 --- a/build/src/utils/helpers.js +++ /dev/null @@ -1,152 +0,0 @@ -"use strict"; -// src/utils/helpers.ts -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.getSnapHodlConfigBalance = exports.processStakingContractDataItem = exports.getWeb3Instance = void 0; -const config_1 = require("../config"); -const mongodb_1 = require("mongodb"); -const web3_1 = __importDefault(require("web3")); -const bignumber_js_1 = __importDefault(require("bignumber.js")); -const getRpcUrl_1 = require("./getRpcUrl"); -const openStaking_1 = require("../openStaking"); -const standardStaking_1 = require("../standardStaking"); -const getTokenDecimals_1 = require("./getTokenDecimals"); -const updateTotalStakedBalances_1 = require("./updateTotalStakedBalances"); -const getWeb3Instance = (rpcUrl) => { - if (!rpcUrl) { - throw new Error("RPC URL is undefined."); - } - return new web3_1.default(rpcUrl); -}; -exports.getWeb3Instance = getWeb3Instance; -const processStakingContractDataItem = (item, dbName, collectionName, connectionString, appName) => __awaiter(void 0, void 0, void 0, function* () { - let totalStakedBalances = {}; - let finalResults = []; - const stakingPoolName = item.stakingPoolName; - const stakingContractAddress = item.stakingContractAddress; - const stakingPoolType = item.stakingPoolType; - const tokenContractAddress = item.tokenContractAddress; - const chainId = item.chainId; - const fromBlock = item.fromBlock; - const toBlock = item.toBlock; - const blockIterationSize = item.blockIterationSize; - const rpcUrl = yield (0, getRpcUrl_1.getRpcUrl)(chainId, config_1.APP_NAME, config_1.DB_CONNECTION_STRING, config_1.DB_NAME, config_1.DB_COLLECTION); - try { - const web3Instance = (0, exports.getWeb3Instance)(rpcUrl); - const decimals = yield (0, getTokenDecimals_1.getTokenDecimals)(tokenContractAddress, web3Instance); - console.log("Token decimals:", decimals); - if (stakingPoolType === "standard") { - const stakers = yield (0, standardStaking_1.getUniqueStakers)(stakingPoolName, stakingContractAddress, stakingPoolType, tokenContractAddress, chainId, web3Instance, fromBlock, toBlock, blockIterationSize, config_1.DB_NAME, config_1.DB_COLLECTION_STAKING_SNAPSHOT, config_1.DB_CONNECTION_STRING); - console.log("Unique staker addresses:", stakers); - const stakedBalances = yield (0, standardStaking_1.getStakedBalances)(stakingPoolName, stakingContractAddress, stakingPoolType, tokenContractAddress, chainId, stakers, decimals, web3Instance, config_1.DB_NAME, config_1.DB_COLLECTION_STAKING_SNAPSHOT, config_1.DB_CONNECTION_STRING); - console.log("Staked balances:", stakedBalances); - const result = { - stakingPoolName: stakingPoolName, - stakedBalances: stakedBalances, - }; - console.log("Result:", JSON.stringify(result, null, 2)); - // Update the totalStakedBalances object - (0, updateTotalStakedBalances_1.updateTotalStakedBalances)(stakedBalances, totalStakedBalances); - // Add the result to the finalResults array - finalResults.push(result); - } - else if (stakingPoolType === "open") { - const uniqueStakers = yield (0, openStaking_1.getUniqueStakersFromOpenStaking)(stakingPoolName, stakingContractAddress, stakingPoolType, tokenContractAddress, chainId, web3Instance, fromBlock, toBlock, blockIterationSize, config_1.DB_NAME, config_1.DB_COLLECTION_STAKING_SNAPSHOT, config_1.DB_CONNECTION_STRING); - console.log("Unique staker addresses from open staking:", uniqueStakers); - const stakedBalances = yield (0, openStaking_1.getOpenStakingStakedBalances)(stakingPoolName, stakingContractAddress, tokenContractAddress, chainId, uniqueStakers, decimals, web3Instance, config_1.DB_NAME, config_1.DB_COLLECTION_STAKING_SNAPSHOT, config_1.DB_CONNECTION_STRING); - console.log("Staked balances from open staking:", stakedBalances); - const result = { - stakingPoolName: stakingPoolName, - stakedBalances: stakedBalances, - }; - console.log("Result:", JSON.stringify(result, null, 2)); - // Update the totalStakedBalances object - (0, updateTotalStakedBalances_1.updateTotalStakedBalances)(stakedBalances, totalStakedBalances); - // Add the result to the finalResults array - finalResults.push(result); - } - // Add logic for other staking pool types here if needed - } - catch (error) { - console.error("Error processing data item:", error); - } - // Add the total staked balances to the finalResults array - finalResults.push({ stakingPoolName: "totalStakedBalances", stakedBalances: totalStakedBalances }); - console.log("Final Results:", JSON.stringify(finalResults, null, 2)); - return finalResults; -}); -exports.processStakingContractDataItem = processStakingContractDataItem; -const getSnapHodlConfigBalance = (snapHodlConfig) => __awaiter(void 0, void 0, void 0, function* () { - if (!snapHodlConfig.isActive) { - return; - } - const client = new mongodb_1.MongoClient(config_1.DB_CONNECTION_STRING); - yield client.connect(); - console.log(`${snapHodlConfig.snapShotConfigName} isActive:`, snapHodlConfig.isActive); - const stakingContractObjects = snapHodlConfig.stakingContractData; - const stakingContractDataBalances = []; - const totalStakedBalance = {}; - for (const stakingContractObject of stakingContractObjects) { - const { stakingContractAddress, tokenContractAddress, chainId } = stakingContractObject; - const query = { - stakingContractAddress, - tokenContractAddress, - chainId, - }; - const snapshots = yield client.db(config_1.DB_NAME).collection(config_1.DB_COLLECTION_STAKING_SNAPSHOT).find(query).toArray(); - let totalBalance = new bignumber_js_1.default(0); - snapshots.forEach((snapshot) => { - Object.entries(snapshot.stakedBalances).forEach(([address, balance]) => { - const balanceBN = new bignumber_js_1.default(balance); - totalBalance = totalBalance.plus(balanceBN); - if (totalStakedBalance[address]) { - totalStakedBalance[address] = totalStakedBalance[address].plus(balanceBN); - } - else { - totalStakedBalance[address] = balanceBN; - } - }); - }); - stakingContractDataBalances.push({ - stakingContractAddress, - tokenContractAddress, - chainId, - totalStakedBalance: totalBalance.toString(), - }); - } - yield client.close(); - const result = { - snapHodlConfigId: new mongodb_1.ObjectId(snapHodlConfig._id), - snapShotConfigName: snapHodlConfig.snapShotConfigName, - stakingContractDataBalances, - totalStakedBalance: Object.fromEntries(Object.entries(totalStakedBalance).map(([address, balance]) => [address, balance.toString()])), - createdAt: new Date(), - updatedAt: new Date(), // add this - }; - // Reconnect to the database to insert the result - yield client.connect(); - const collection = client.db(config_1.DB_NAME).collection(config_1.DB_COLLECTION_SNAP_CONFIG_BALANCE); - const existingDoc = yield collection.findOne({ snapHodlConfigId: new mongodb_1.ObjectId(snapHodlConfig._id) }); - if (existingDoc) { - yield collection.updateOne({ snapHodlConfigId: new mongodb_1.ObjectId(snapHodlConfig._id) }, { - $set: Object.assign(Object.assign({}, result), { updatedAt: new Date(), createdAt: existingDoc.createdAt ? existingDoc.createdAt : new Date() }), - }); - } - else { - yield collection.insertOne(Object.assign(Object.assign({}, result), { createdAt: new Date(), updatedAt: new Date() })); - } - yield client.close(); - return result; -}); -exports.getSnapHodlConfigBalance = getSnapHodlConfigBalance; diff --git a/build/src/utils/updateTotalStakedBalances.js b/build/src/utils/updateTotalStakedBalances.js deleted file mode 100644 index bb24a64..0000000 --- a/build/src/utils/updateTotalStakedBalances.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict"; -// src/utils/updateTotalStakedBalances.ts -Object.defineProperty(exports, "__esModule", { value: true }); -exports.updateTotalStakedBalances = void 0; -const bignumber_js_1 = require("bignumber.js"); -function updateTotalStakedBalances(stakedBalances, totalStakedBalances) { - for (const key in stakedBalances) { - const value = stakedBalances[key]; - if (totalStakedBalances[key]) { - const existingBalance = new bignumber_js_1.BigNumber(totalStakedBalances[key]); - const newBalance = existingBalance.plus(value); - totalStakedBalances[key] = newBalance.toString(); - } - else { - totalStakedBalances[key] = value; - } - } -} -exports.updateTotalStakedBalances = updateTotalStakedBalances;