From b7e6fad27430ace0be86bdbe618f326fc79369b6 Mon Sep 17 00:00:00 2001 From: hydtdev <148316976+hydtdev@users.noreply.github.com> Date: Fri, 10 Nov 2023 10:36:35 +0500 Subject: [PATCH] feat: add hydt yield adapter (#1071) * add hydt yield adapter * Update index.js --- src/adaptors/hydt-protocol/earnABI.js | 957 ++++++++++++++++++++++++++ src/adaptors/hydt-protocol/farmABI.js | 682 ++++++++++++++++++ src/adaptors/hydt-protocol/index.js | 403 +++++++++++ src/adaptors/hydt-protocol/pairABI.js | 440 ++++++++++++ 4 files changed, 2482 insertions(+) create mode 100644 src/adaptors/hydt-protocol/earnABI.js create mode 100644 src/adaptors/hydt-protocol/farmABI.js create mode 100644 src/adaptors/hydt-protocol/index.js create mode 100644 src/adaptors/hydt-protocol/pairABI.js diff --git a/src/adaptors/hydt-protocol/earnABI.js b/src/adaptors/hydt-protocol/earnABI.js new file mode 100644 index 0000000000..b85d2b2405 --- /dev/null +++ b/src/adaptors/hydt-protocol/earnABI.js @@ -0,0 +1,957 @@ +module.exports = [ + { + inputs: [], + stateMutability: "nonpayable", + type: "constructor" + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "user", + type: "address" + }, + { + indexed: false, + internalType: "uint256", + name: "index", + type: "uint256" + }, + { + indexed: false, + internalType: "uint256", + name: "payout", + type: "uint256" + } + ], + name: "Payout", + type: "event" + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "bytes32", + name: "role", + type: "bytes32" + }, + { + indexed: true, + internalType: "bytes32", + name: "previousAdminRole", + type: "bytes32" + }, + { + indexed: true, + internalType: "bytes32", + name: "newAdminRole", + type: "bytes32" + } + ], + name: "RoleAdminChanged", + type: "event" + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "bytes32", + name: "role", + type: "bytes32" + }, + { + indexed: true, + internalType: "address", + name: "account", + type: "address" + }, + { + indexed: true, + internalType: "address", + name: "sender", + type: "address" + } + ], + name: "RoleGranted", + type: "event" + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "bytes32", + name: "role", + type: "bytes32" + }, + { + indexed: true, + internalType: "address", + name: "account", + type: "address" + }, + { + indexed: true, + internalType: "address", + name: "sender", + type: "address" + } + ], + name: "RoleRevoked", + type: "event" + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "user", + type: "address" + }, + { + indexed: false, + internalType: "uint256", + name: "index", + type: "uint256" + }, + { + indexed: false, + internalType: "uint256", + name: "amount", + type: "uint256" + }, + { + indexed: false, + internalType: "uint8", + name: "stakeType", + type: "uint8" + }, + { + indexed: false, + internalType: "uint256", + name: "startTime", + type: "uint256" + }, + { + indexed: false, + internalType: "uint256", + name: "endTime", + type: "uint256" + }, + { + indexed: false, + internalType: "uint256", + name: "activeDeposits", + type: "uint256" + } + ], + name: "Stake", + type: "event" + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "user", + type: "address" + }, + { + indexed: false, + internalType: "uint256", + name: "index", + type: "uint256" + }, + { + indexed: false, + internalType: "uint256", + name: "amount", + type: "uint256" + }, + { + indexed: false, + internalType: "uint256", + name: "activeDeposits", + type: "uint256" + } + ], + name: "Unstake", + type: "event" + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "uint256", + name: "stakeType", + type: "uint256" + }, + { + indexed: false, + internalType: "uint256", + name: "newAllocPoint", + type: "uint256" + }, + { + indexed: false, + internalType: "uint256", + name: "oldAllocPoint", + type: "uint256" + } + ], + name: "UpdateAllocationWithUpdate", + type: "event" + }, + { + inputs: [], + name: "DEFAULT_ADMIN_ROLE", + outputs: [ + { + internalType: "bytes32", + name: "", + type: "bytes32" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [], + name: "GOVERNOR_ROLE", + outputs: [ + { + internalType: "bytes32", + name: "", + type: "bytes32" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [], + name: "HYDT", + outputs: [ + { + internalType: "contract IHYDT", + name: "", + type: "address" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [], + name: "HYGT", + outputs: [ + { + internalType: "contract IHYGT", + name: "", + type: "address" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [], + name: "HYGTPerSecond", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [], + name: "TREASURY", + outputs: [ + { + internalType: "address", + name: "", + type: "address" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + { + internalType: "uint256", + name: "stakeType", + type: "uint256" + }, + { + internalType: "uint256", + name: "index", + type: "uint256" + } + ], + name: "allPoolInfo", + outputs: [ + { + components: [ + { + internalType: "uint8", + name: "stakeType", + type: "uint8" + }, + { + internalType: "uint256", + name: "allocPoint", + type: "uint256" + }, + { + internalType: "uint256", + name: "stakeSupply", + type: "uint256" + }, + { + internalType: "uint256", + name: "accHYGTPerShare", + type: "uint256" + }, + { + internalType: "uint256", + name: "lastRewardTime", + type: "uint256" + } + ], + internalType: "struct Earn.PoolInfo", + name: "", + type: "tuple" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + { + internalType: "uint256", + name: "index", + type: "uint256" + } + ], + name: "claimPayout", + outputs: [], + stateMutability: "nonpayable", + type: "function" + }, + { + inputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + name: "dailyPayouts", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [], + name: "depositFee", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + { + internalType: "address", + name: "user", + type: "address" + } + ], + name: "getDailyPayoutBatch", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + { + internalType: "address", + name: "user", + type: "address" + }, + { + internalType: "uint256", + name: "index", + type: "uint256" + } + ], + name: "getPayout", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + { + internalType: "address", + name: "user", + type: "address" + } + ], + name: "getPayoutBatch", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + { + internalType: "address", + name: "user", + type: "address" + }, + { + internalType: "uint8", + name: "stakeType", + type: "uint8" + } + ], + name: "getPayoutType", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + { + internalType: "address", + name: "user", + type: "address" + }, + { + internalType: "uint256", + name: "index", + type: "uint256" + } + ], + name: "getPending", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + { + internalType: "address", + name: "user", + type: "address" + } + ], + name: "getPendingBatch", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + { + internalType: "address", + name: "user", + type: "address" + }, + { + internalType: "uint8", + name: "stakeType", + type: "uint8" + } + ], + name: "getPendingType", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + { + internalType: "bytes32", + name: "role", + type: "bytes32" + } + ], + name: "getRoleAdmin", + outputs: [ + { + internalType: "bytes32", + name: "", + type: "bytes32" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + { + internalType: "address", + name: "", + type: "address" + } + ], + name: "getStakingLengths", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + { + internalType: "address", + name: "", + type: "address" + }, + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + name: "getStakings", + outputs: [ + { + internalType: "uint256", + name: "index", + type: "uint256" + }, + { + internalType: "bool", + name: "status", + type: "bool" + }, + { + internalType: "uint256", + name: "amount", + type: "uint256" + }, + { + internalType: "uint8", + name: "stakeType", + type: "uint8" + }, + { + internalType: "uint256", + name: "startTime", + type: "uint256" + }, + { + internalType: "uint256", + name: "endTime", + type: "uint256" + }, + { + internalType: "uint256", + name: "lastClaimTime", + type: "uint256" + }, + { + internalType: "uint256", + name: "rewardDebt", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + { + internalType: "bytes32", + name: "role", + type: "bytes32" + }, + { + internalType: "address", + name: "account", + type: "address" + } + ], + name: "grantRole", + outputs: [], + stateMutability: "nonpayable", + type: "function" + }, + { + inputs: [ + { + internalType: "bytes32", + name: "role", + type: "bytes32" + }, + { + internalType: "address", + name: "account", + type: "address" + } + ], + name: "hasRole", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + { + internalType: "address", + name: "hydt_", + type: "address" + }, + { + internalType: "address", + name: "hygt_", + type: "address" + }, + { + internalType: "address", + name: "shydt_", + type: "address" + }, + { + internalType: "address", + name: "treasury_", + type: "address" + }, + { + internalType: "uint256", + name: "initialMintStartTime_", + type: "uint256" + } + ], + name: "initialize", + outputs: [], + stateMutability: "nonpayable", + type: "function" + }, + { + inputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + name: "lockPeriods", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [], + name: "massUpdatePools", + outputs: [], + stateMutability: "nonpayable", + type: "function" + }, + { + inputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + name: "poolInfo", + outputs: [ + { + internalType: "uint8", + name: "stakeType", + type: "uint8" + }, + { + internalType: "uint256", + name: "allocPoint", + type: "uint256" + }, + { + internalType: "uint256", + name: "stakeSupply", + type: "uint256" + }, + { + internalType: "uint256", + name: "accHYGTPerShare", + type: "uint256" + }, + { + internalType: "uint256", + name: "lastRewardTime", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [], + name: "poolLength", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + { + internalType: "bytes32", + name: "role", + type: "bytes32" + }, + { + internalType: "address", + name: "account", + type: "address" + } + ], + name: "renounceRole", + outputs: [], + stateMutability: "nonpayable", + type: "function" + }, + { + inputs: [ + { + internalType: "bytes32", + name: "role", + type: "bytes32" + }, + { + internalType: "address", + name: "account", + type: "address" + } + ], + name: "revokeRole", + outputs: [], + stateMutability: "nonpayable", + type: "function" + }, + { + inputs: [], + name: "sHYDT", + outputs: [ + { + internalType: "contract IHYDT", + name: "", + type: "address" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + { + internalType: "uint256", + name: "amount", + type: "uint256" + }, + { + internalType: "uint8", + name: "stakeType", + type: "uint8" + } + ], + name: "stake", + outputs: [], + stateMutability: "nonpayable", + type: "function" + }, + { + inputs: [], + name: "startTime", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + { + internalType: "bytes4", + name: "interfaceId", + type: "bytes4" + } + ], + name: "supportsInterface", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [], + name: "totalAllocPoint", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + { + internalType: "uint8", + name: "stakeType", + type: "uint8" + }, + { + internalType: "uint256", + name: "newAllocPoint", + type: "uint256" + } + ], + name: "updateAllocationWithUpdate", + outputs: [], + stateMutability: "nonpayable", + type: "function" + }, + { + inputs: [ + { + internalType: "uint8", + name: "stakeType", + type: "uint8" + } + ], + name: "updatePool", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "nonpayable", + type: "function" + }, + { + inputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + name: "yearlyYields", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + } +]; \ No newline at end of file diff --git a/src/adaptors/hydt-protocol/farmABI.js b/src/adaptors/hydt-protocol/farmABI.js new file mode 100644 index 0000000000..e78a65aa5b --- /dev/null +++ b/src/adaptors/hydt-protocol/farmABI.js @@ -0,0 +1,682 @@ +module.exports = [ + { + inputs: [], + stateMutability: "nonpayable", + type: "constructor" + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "uint256", + name: "pid", + type: "uint256" + }, + { + indexed: false, + internalType: "address", + name: "lpToken", + type: "address" + }, + { + indexed: false, + internalType: "string", + name: "symbol", + type: "string" + }, + { + indexed: false, + internalType: "uint256", + name: "allocPoint", + type: "uint256" + } + ], + name: "AddPool", + type: "event" + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "user", + type: "address" + }, + { + indexed: true, + internalType: "uint256", + name: "pid", + type: "uint256" + }, + { + indexed: false, + internalType: "uint256", + name: "amount", + type: "uint256" + } + ], + name: "Deposit", + type: "event" + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "user", + type: "address" + }, + { + indexed: true, + internalType: "uint256", + name: "pid", + type: "uint256" + }, + { + indexed: false, + internalType: "uint256", + name: "amount", + type: "uint256" + } + ], + name: "EmergencyWithdraw", + type: "event" + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "bytes32", + name: "role", + type: "bytes32" + }, + { + indexed: true, + internalType: "bytes32", + name: "previousAdminRole", + type: "bytes32" + }, + { + indexed: true, + internalType: "bytes32", + name: "newAdminRole", + type: "bytes32" + } + ], + name: "RoleAdminChanged", + type: "event" + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "bytes32", + name: "role", + type: "bytes32" + }, + { + indexed: true, + internalType: "address", + name: "account", + type: "address" + }, + { + indexed: true, + internalType: "address", + name: "sender", + type: "address" + } + ], + name: "RoleGranted", + type: "event" + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "bytes32", + name: "role", + type: "bytes32" + }, + { + indexed: true, + internalType: "address", + name: "account", + type: "address" + }, + { + indexed: true, + internalType: "address", + name: "sender", + type: "address" + } + ], + name: "RoleRevoked", + type: "event" + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "uint256", + name: "pid", + type: "uint256" + }, + { + indexed: false, + internalType: "uint256", + name: "newAllocPoint", + type: "uint256" + }, + { + indexed: false, + internalType: "uint256", + name: "oldAllocPoint", + type: "uint256" + } + ], + name: "UpdateAllocation", + type: "event" + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "user", + type: "address" + }, + { + indexed: true, + internalType: "uint256", + name: "pid", + type: "uint256" + }, + { + indexed: false, + internalType: "uint256", + name: "amount", + type: "uint256" + } + ], + name: "Withdraw", + type: "event" + }, + { + inputs: [], + name: "DEFAULT_ADMIN_ROLE", + outputs: [ + { + internalType: "bytes32", + name: "", + type: "bytes32" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [], + name: "GOVERNOR_ROLE", + outputs: [ + { + internalType: "bytes32", + name: "", + type: "bytes32" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [], + name: "HYGT", + outputs: [ + { + internalType: "contract IHYGT", + name: "", + type: "address" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [], + name: "HYGTPerBlock", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + { + internalType: "contract IERC20", + name: "lpToken", + type: "address" + }, + { + internalType: "uint256", + name: "allocPoint", + type: "uint256" + }, + { + internalType: "string", + name: "symbol", + type: "string" + }, + { + internalType: "bool", + name: "withUpdate", + type: "bool" + } + ], + name: "addPool", + outputs: [], + stateMutability: "nonpayable", + type: "function" + }, + { + inputs: [ + { + internalType: "uint256", + name: "pid", + type: "uint256" + }, + { + internalType: "uint256", + name: "amount", + type: "uint256" + } + ], + name: "deposit", + outputs: [], + stateMutability: "nonpayable", + type: "function" + }, + { + inputs: [ + { + internalType: "uint256", + name: "pid", + type: "uint256" + } + ], + name: "emergencyWithdraw", + outputs: [], + stateMutability: "nonpayable", + type: "function" + }, + { + inputs: [ + { + internalType: "uint256", + name: "pid", + type: "uint256" + }, + { + internalType: "address", + name: "user", + type: "address" + } + ], + name: "getPending", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + { + internalType: "address", + name: "user", + type: "address" + } + ], + name: "getPendingBatch", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + { + internalType: "bytes32", + name: "role", + type: "bytes32" + } + ], + name: "getRoleAdmin", + outputs: [ + { + internalType: "bytes32", + name: "", + type: "bytes32" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + { + internalType: "bytes32", + name: "role", + type: "bytes32" + }, + { + internalType: "address", + name: "account", + type: "address" + } + ], + name: "grantRole", + outputs: [], + stateMutability: "nonpayable", + type: "function" + }, + { + inputs: [ + { + internalType: "bytes32", + name: "role", + type: "bytes32" + }, + { + internalType: "address", + name: "account", + type: "address" + } + ], + name: "hasRole", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + { + internalType: "address", + name: "hygt_", + type: "address" + }, + { + internalType: "address[3]", + name: "lpTokens_", + type: "address[3]" + }, + { + internalType: "uint256", + name: "initialMintStartTime_", + type: "uint256" + } + ], + name: "initialize", + outputs: [], + stateMutability: "nonpayable", + type: "function" + }, + { + inputs: [], + name: "massUpdatePools", + outputs: [], + stateMutability: "nonpayable", + type: "function" + }, + { + inputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + name: "poolInfo", + outputs: [ + { + internalType: "contract IERC20", + name: "lpToken", + type: "address" + }, + { + internalType: "uint256", + name: "allocPoint", + type: "uint256" + }, + { + internalType: "uint256", + name: "lastRewardBlock", + type: "uint256" + }, + { + internalType: "uint256", + name: "accHYGTPerShare", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [], + name: "poolLength", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + { + internalType: "bytes32", + name: "role", + type: "bytes32" + }, + { + internalType: "address", + name: "account", + type: "address" + } + ], + name: "renounceRole", + outputs: [], + stateMutability: "nonpayable", + type: "function" + }, + { + inputs: [ + { + internalType: "bytes32", + name: "role", + type: "bytes32" + }, + { + internalType: "address", + name: "account", + type: "address" + } + ], + name: "revokeRole", + outputs: [], + stateMutability: "nonpayable", + type: "function" + }, + { + inputs: [], + name: "startBlock", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + { + internalType: "bytes4", + name: "interfaceId", + type: "bytes4" + } + ], + name: "supportsInterface", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [], + name: "totalAllocPoint", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + { + internalType: "uint256", + name: "pid", + type: "uint256" + }, + { + internalType: "uint256", + name: "newAllocPoint", + type: "uint256" + }, + { + internalType: "bool", + name: "withUpdate", + type: "bool" + } + ], + name: "updateAllocation", + outputs: [], + stateMutability: "nonpayable", + type: "function" + }, + { + inputs: [ + { + internalType: "uint256", + name: "pid", + type: "uint256" + } + ], + name: "updatePool", + outputs: [], + stateMutability: "nonpayable", + type: "function" + }, + { + inputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + }, + { + internalType: "address", + name: "", + type: "address" + } + ], + name: "userInfo", + outputs: [ + { + internalType: "uint256", + name: "amount", + type: "uint256" + }, + { + internalType: "uint256", + name: "rewardDebt", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + { + internalType: "uint256", + name: "pid", + type: "uint256" + }, + { + internalType: "uint256", + name: "amount", + type: "uint256" + } + ], + name: "withdraw", + outputs: [], + stateMutability: "nonpayable", + type: "function" + }, + { + inputs: [ + { + internalType: "uint256", + name: "pid", + type: "uint256" + } + ], + name: "withdrawRewards", + outputs: [], + stateMutability: "nonpayable", + type: "function" + } +]; \ No newline at end of file diff --git a/src/adaptors/hydt-protocol/index.js b/src/adaptors/hydt-protocol/index.js new file mode 100644 index 0000000000..3eac60587d --- /dev/null +++ b/src/adaptors/hydt-protocol/index.js @@ -0,0 +1,403 @@ +const sdk = require('@defillama/sdk4'); +const farmABI = require('./farmABI'); +const earnABI = require('./earnABI'); +const pairABI = require('./pairABI'); +const axios = require('axios'); +const BigNumber = require('bignumber.js'); + +const utils = require('../utils'); + +const chain = 'bsc'; + +const project = 'hydt-protocol'; + +const earn = '0x8e48d5b2Ac80d9861d07127F06BbF02F73520Ced'; +const farm = '0x4590BaD61aE62ACFF33032e3Bf64b52b7264A779'; +const hydt = '0x9810512Be701801954449408966c630595D0cD51'; +const hygt = '0x100995a7e5fFd8Ee60cc18A10C75CEe8C572c59b'; + +const hygtPair = [{ lpToken: '0xE0e9bBc7aE8EBE4D74065F6EBD710665DA285a0B' }]; + +const getEarnPoolInfo = async (block, poolInfo) => { + const apys = [16, 20, 30] + const poolDetails = []; + + for (let i = 0; i < poolInfo.length; i++) { + poolDetails.push({ + id: poolInfo[i].stakeType, + allocPoint: poolInfo[i].allocPoint, + totalDeposit: poolInfo[i].stakeSupply, + apy: apys[i], + }); + } + + return poolDetails; +}; + +const getFarmPoolInfo = async (block, poolInfo) => { + const poolDetails = []; + + for (let i = 0; i < poolInfo.length; i++) { + const token0Id = ( + await sdk.api.abi.call({ + target: poolInfo[i].lpToken, + abi: pairABI.find((m) => m.name === 'token0'), + chain, + }) + ).output; + const token0Symbol = ( + await sdk.api.abi.call({ + target: token0Id, + abi: pairABI.find((m) => m.name === 'symbol'), + chain, + }) + ).output; + const token0Decimals = ( + await sdk.api.abi.call({ + target: token0Id, + abi: pairABI.find((m) => m.name === 'decimals'), + chain, + }) + ).output; + const token1Id = ( + await sdk.api.abi.call({ + target: poolInfo[i].lpToken, + abi: pairABI.find((m) => m.name === 'token1'), + chain, + }) + ).output; + const token1Symbol = ( + await sdk.api.abi.call({ + target: token1Id, + abi: pairABI.find((m) => m.name === 'symbol'), + chain, + }) + ).output; + const token1Decimals = ( + await sdk.api.abi.call({ + target: token1Id, + abi: pairABI.find((m) => m.name === 'decimals'), + chain, + }) + ).output; + + try { + // lpToken variables + const reserves = ( + await sdk.api.abi.call({ + target: poolInfo[i].lpToken, + abi: pairABI.find((m) => m.name === 'getReserves'), + block, + chain, + }) + ).output; + const totalSupply = ( + await sdk.api.abi.call({ + target: poolInfo[i].lpToken, + abi: pairABI.find((m) => m.name === 'totalSupply'), + block, + chain, + }) + ).output; + const totalDeposit = ( + await sdk.api.abi.call({ + target: poolInfo[i].lpToken, + abi: pairABI.find((m) => m.name === 'balanceOf'), + params: farm, + block, + chain, + }) + ).output; + + // pool details + poolDetails.push({ + id: poolInfo[i].lpToken, + allocPoint: poolInfo[i].allocPoint, + reserve0: reserves._reserve0 / (1 * 10 ** token0Decimals), + reserve1: reserves._reserve1 / (1 * 10 ** token1Decimals), + totalSupply: totalSupply, + totalDeposit: totalDeposit, + token0: { + symbol: token0Symbol, + id: token0Id, + }, + token1: { + symbol: token1Symbol, + id: token1Id, + }, + }); + } catch (e) { + // default pool details + poolDetails.push({ + id: poolInfo[i].lpToken, + allocPoint: poolInfo[i].allocPoint, + reserve0: 0, + reserve1: 0, + totalSupply: 0, + token0: { + symbol: token0Symbol, + id: token0Id, + }, + token1: { + symbol: token1Symbol, + id: token1Id, + }, + }); + } + } + + return poolDetails; +}; + +const getData = async (target, block, hydtPrice) => { + let targetABI + let abiParameter; + + if (target === earn) { + targetABI = earnABI; + abiParameter = 'HYGTPerSecond'; + } else { + targetABI = farmABI; + abiParameter = 'HYGTPerBlock'; + } + + const poolLength = ( + await sdk.api.abi.call({ + target, + abi: targetABI.find((m) => m.name === 'poolLength'), + chain, + }) + ).output; + + let poolInfo = ( + await sdk.api.abi.multiCall({ + calls: [...Array(Number(poolLength)).keys()].map((i) => ({ + target, + params: i, + })), + abi: targetABI.find((m) => m.name === 'poolInfo'), + chain, + }) + ).output.map((o) => o.output); + + poolInfo = poolInfo.filter(i => i.allocPoint > 0); + + const totalAllocPoint = ( + await sdk.api.abi.call({ + target, + abi: targetABI.find((m) => m.name === 'totalAllocPoint'), + chain, + }) + ).output; + + const hygtPer = ( + await sdk.api.abi.call({ + target, + abi: targetABI.find((m) => m.name === abiParameter), + chain, + }) + ).output / 1e18; + + // getting hygt price + const hygtPairInfo = await getFarmPoolInfo(block, hygtPair, chain); + const hygtPrice = (parseFloat(hydtPrice) * hygtPairInfo[0].reserve1) / parseFloat(hygtPairInfo[0].reserve0); + + return [ + poolInfo, + totalAllocPoint, + hygtPer, + hygtPrice + ]; +} + +const getEarnAPY = async (block, blockPrior, blockPrior7d, hydtPrice) => { + const [ + poolInfo, + totalAllocPoint, + hygtPer, + hygtPrice + ] = await getData(earn, block, hydtPrice); + + const secondsPerYear = 86400 * 365; + const hygtPerYearUSD = hygtPer * secondsPerYear * hygtPrice; + + // pull data + let data = await getEarnPoolInfo(block, poolInfo, chain); + + // pull data 24h offest + let dataPrior = await getEarnPoolInfo(blockPrior, poolInfo, chain); + + // pull data 7d offest + let dataPrior7d = await getEarnPoolInfo(blockPrior7d, poolInfo, chain); + + // calculate apy + data = data.map((i) => + utils.apy(i, dataPrior, dataPrior7d, 'v2') + ); + + const formattedChain = utils.formatChain(chain); + const pool = `${hydt}-${formattedChain}`.toLowerCase(); + const symbol = 'HYDT'; + const rewardTokens = [hydt, hygt]; + const underlyingTokens = [hydt]; + const url = 'https://app.hydtprotocol.com/HYDT/earn'; + + let apyTotal = 0; + let tvlTotal = 0; + let volumeUsd1dTotal = 0; + let volumeUsd7dTotal = 0; + + data.forEach((p) => { + const totalDeposit = new BigNumber(p.totalDeposit).dividedBy(new BigNumber(10).pow(18)).toFixed(18); + const tvlUSD = totalDeposit * hydtPrice; + + const apyBase = (( + ((p.allocPoint / totalAllocPoint) * hygtPerYearUSD) / + tvlUSD + ) * 100) + p.apy; + + apyTotal += apyBase; + tvlTotal += tvlUSD; + volumeUsd1dTotal += p?.volumeUsd1d || 0; + volumeUsd7dTotal += p?.volumeUsd7d || 0; + }); + + apyTotal /= data.length; + + return [ + { + pool, + chain: formattedChain, + project, + symbol, + url, + tvlUsd: tvlTotal, + apyBase: 0, + apyBase7d: 0, + apyReward: apyTotal || 0, + rewardTokens, + underlyingTokens, + volumeUsd1d: volumeUsd1dTotal, + volumeUsd7d: volumeUsd7dTotal, + } + ]; +} + +const getFarmAPY = async (block, blockPrior, blockPrior7d, hydtPrice) => { + const [ + poolInfo, + totalAllocPoint, + hygtPer, + hygtPrice + ] = await getData(farm, block, hydtPrice); + + const blocksPerYear = (86400 * 365) / 3; + const hygtPerYearUSD = hygtPer * blocksPerYear * hygtPrice; + + // pull data + let data = await getFarmPoolInfo(block, poolInfo, chain); + + // pull data 24h offest + let dataPrior = await getFarmPoolInfo(blockPrior, poolInfo, chain); + + // pull data 7d offest + let dataPrior7d = await getFarmPoolInfo(blockPrior7d, poolInfo, chain); + + // calculate tvl + data = await utils.tvl(data, chain); + + data = data.map(i => { + const price0 = i.token0.id == hydt ? hydtPrice : i.token0.id == hygt ? hygtPrice : i.price0; + const price1 = i.token1.id == hydt ? hydtPrice : i.token1.id == hygt ? hygtPrice : i.price1; + const totalValueLockedUSD = price0 * i.reserve0 + price1 * i.reserve1; + return { + ...i, + price0, + price1, + totalValueLockedUSD, + }; + }); + + // calculate apy + data = data.map((i) => + utils.apy(i, dataPrior, dataPrior7d, 'v2') + ); + + data = data.map((p) => { + const formattedChain = utils.formatChain(chain); + const pool = `${p.id}-${formattedChain}`.toLowerCase(); + const symbol = + p.token0.symbol === 'HYDT' ? + utils.formatSymbol(`${p.token0.symbol}-${p.token1.symbol}`) : + p.token1.symbol === 'HYDT' ? + utils.formatSymbol(`${p.token1.symbol}-${p.token0.symbol}`) : + utils.formatSymbol(`${p.token0.symbol}-${p.token1.symbol}`); + const rewardTokens = [hygt]; + const underlyingTokens = [p.id]; + const url = 'https://app.hydtprotocol.com/HYDT/farm'; + + const totalDeposit = new BigNumber(p.totalDeposit).dividedBy(new BigNumber(10).pow(18)).toFixed(18); + const totalSupply = new BigNumber(p.totalSupply).dividedBy(new BigNumber(10).pow(18)).toFixed(18); + const ratio = totalDeposit / totalSupply || 1; + const tvlUsd = p.totalValueLockedUSD * ratio; + + const rewardAPY = ( + ((p.allocPoint / totalAllocPoint) * hygtPerYearUSD) / + tvlUsd + ) * 100; + + return { + pool, + chain: formattedChain, + project, + symbol, + url, + tvlUsd, + apyBase: 0, + apyBase7d: 0, + apyReward: rewardAPY || 0, + rewardTokens, + underlyingTokens, + volumeUsd1d: p?.volumeUSD1d || 0, + volumeUsd7d: p?.volumeUSD7d || 0, + }; + }); + + return data; +}; + +const getAPY = async () => { + // getting all block variables + const timestamp = Date.now() / 1000; + const [block, blockPrior] = await utils.getBlocks(chain, timestamp, []); + const [_, blockPrior7d] = await utils.getBlocks( + chain, + timestamp, + [], + 604800 + ); + + // getting hydt price + const hydtPrice = ( + await axios.get(`https://api.dexscreener.com/latest/dex/tokens/${hydt}`) + ).data.pairs[0]?.priceUsd; + + let data = await getEarnAPY(block, blockPrior, blockPrior7d, hydtPrice); + let farmData = await getFarmAPY(block, blockPrior, blockPrior7d, hydtPrice); + + farmData.forEach(i => data.push(i)); + + return data; +} + +const main = async () => { + let data = await getAPY(); + + // process.exit(1) + return data.filter((i) => utils.keepFinite(i)); +}; + +module.exports = { + timetravel: false, + apy: main, +}; diff --git a/src/adaptors/hydt-protocol/pairABI.js b/src/adaptors/hydt-protocol/pairABI.js new file mode 100644 index 0000000000..a868a25e29 --- /dev/null +++ b/src/adaptors/hydt-protocol/pairABI.js @@ -0,0 +1,440 @@ +module.exports = [ + { + inputs: [], + payable: false, + stateMutability: 'nonpayable', + type: 'constructor', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'owner', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: 'spender', + type: 'address', + }, + { + indexed: false, + internalType: 'uint256', + name: 'value', + type: 'uint256', + }, + ], + name: 'Approval', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'sender', + type: 'address', + }, + { + indexed: false, + internalType: 'uint256', + name: 'amount0', + type: 'uint256', + }, + { + indexed: false, + internalType: 'uint256', + name: 'amount1', + type: 'uint256', + }, + { indexed: true, internalType: 'address', name: 'to', type: 'address' }, + ], + name: 'Burn', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'sender', + type: 'address', + }, + { + indexed: false, + internalType: 'uint256', + name: 'amount0', + type: 'uint256', + }, + { + indexed: false, + internalType: 'uint256', + name: 'amount1', + type: 'uint256', + }, + ], + name: 'Mint', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'sender', + type: 'address', + }, + { + indexed: false, + internalType: 'uint256', + name: 'amount0In', + type: 'uint256', + }, + { + indexed: false, + internalType: 'uint256', + name: 'amount1In', + type: 'uint256', + }, + { + indexed: false, + internalType: 'uint256', + name: 'amount0Out', + type: 'uint256', + }, + { + indexed: false, + internalType: 'uint256', + name: 'amount1Out', + type: 'uint256', + }, + { indexed: true, internalType: 'address', name: 'to', type: 'address' }, + ], + name: 'Swap', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: 'uint112', + name: 'reserve0', + type: 'uint112', + }, + { + indexed: false, + internalType: 'uint112', + name: 'reserve1', + type: 'uint112', + }, + ], + name: 'Sync', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'from', + type: 'address', + }, + { indexed: true, internalType: 'address', name: 'to', type: 'address' }, + { + indexed: false, + internalType: 'uint256', + name: 'value', + 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: 'MINIMUM_LIQUIDITY', + outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], + 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: 'spender', type: 'address' }, + { internalType: 'uint256', name: 'value', 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: 'to', type: 'address' }], + name: 'burn', + outputs: [ + { internalType: 'uint256', name: 'amount0', type: 'uint256' }, + { internalType: 'uint256', name: 'amount1', type: 'uint256' }, + ], + payable: false, + stateMutability: 'nonpayable', + type: 'function', + }, + { + constant: true, + inputs: [], + name: 'decimals', + outputs: [{ internalType: 'uint8', name: '', type: 'uint8' }], + payable: false, + stateMutability: 'view', + type: 'function', + }, + { + constant: true, + inputs: [], + name: 'factory', + outputs: [{ internalType: 'address', name: '', type: 'address' }], + payable: false, + stateMutability: 'view', + type: 'function', + }, + { + constant: true, + inputs: [], + name: 'getReserves', + outputs: [ + { internalType: 'uint112', name: '_reserve0', type: 'uint112' }, + { internalType: 'uint112', name: '_reserve1', type: 'uint112' }, + { internalType: 'uint32', name: '_blockTimestampLast', type: 'uint32' }, + ], + payable: false, + stateMutability: 'view', + type: 'function', + }, + { + constant: false, + inputs: [ + { internalType: 'address', name: '_token0', type: 'address' }, + { internalType: 'address', name: '_token1', type: 'address' }, + ], + name: 'initialize', + outputs: [], + payable: false, + stateMutability: 'nonpayable', + type: 'function', + }, + { + constant: true, + inputs: [], + name: 'kLast', + outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], + payable: false, + stateMutability: 'view', + type: 'function', + }, + { + constant: false, + inputs: [{ internalType: 'address', name: 'to', type: 'address' }], + name: 'mint', + outputs: [{ internalType: 'uint256', name: 'liquidity', type: 'uint256' }], + 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: 'owner', type: 'address' }, + { internalType: 'address', name: 'spender', type: 'address' }, + { internalType: 'uint256', name: 'value', type: 'uint256' }, + { internalType: 'uint256', name: 'deadline', type: 'uint256' }, + { 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: true, + inputs: [], + name: 'price0CumulativeLast', + outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], + payable: false, + stateMutability: 'view', + type: 'function', + }, + { + constant: true, + inputs: [], + name: 'price1CumulativeLast', + outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], + payable: false, + stateMutability: 'view', + type: 'function', + }, + { + constant: false, + inputs: [{ internalType: 'address', name: 'to', type: 'address' }], + name: 'skim', + outputs: [], + payable: false, + stateMutability: 'nonpayable', + type: 'function', + }, + { + constant: false, + inputs: [ + { internalType: 'uint256', name: 'amount0Out', type: 'uint256' }, + { internalType: 'uint256', name: 'amount1Out', type: 'uint256' }, + { internalType: 'address', name: 'to', type: 'address' }, + { internalType: 'bytes', name: 'data', type: 'bytes' }, + ], + name: 'swap', + 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: false, + inputs: [], + name: 'sync', + outputs: [], + payable: false, + stateMutability: 'nonpayable', + type: 'function', + }, + { + constant: true, + inputs: [], + name: 'token0', + outputs: [{ internalType: 'address', name: '', type: 'address' }], + payable: false, + stateMutability: 'view', + type: 'function', + }, + { + constant: true, + inputs: [], + name: 'token1', + outputs: [{ internalType: 'address', name: '', type: 'address' }], + 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: 'to', type: 'address' }, + { internalType: 'uint256', name: 'value', type: 'uint256' }, + ], + name: 'transfer', + outputs: [{ internalType: 'bool', name: '', type: 'bool' }], + payable: false, + stateMutability: 'nonpayable', + type: 'function', + }, + { + constant: false, + inputs: [ + { internalType: 'address', name: 'from', type: 'address' }, + { internalType: 'address', name: 'to', type: 'address' }, + { internalType: 'uint256', name: 'value', type: 'uint256' }, + ], + name: 'transferFrom', + outputs: [{ internalType: 'bool', name: '', type: 'bool' }], + payable: false, + stateMutability: 'nonpayable', + type: 'function', + }, +]; \ No newline at end of file