From ade5a541f00f6c3b2fe2c92bc0ecc559adc0baa2 Mon Sep 17 00:00:00 2001 From: mul53 Date: Mon, 19 Jun 2023 17:58:09 +0200 Subject: [PATCH] add sfuse (#38) --- package.json | 5 +- src/constants/abi/LiquidStaking.json | 879 +++++++++++++++++++++++++++ src/constants/index.ts | 4 + src/rewards/ChefRewardProgram.ts | 19 +- 4 files changed, 904 insertions(+), 3 deletions(-) create mode 100644 src/constants/abi/LiquidStaking.json diff --git a/package.json b/package.json index 7143fc0..2fa4c7c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@fuseio/earn-sdk", - "version": "1.0.5", + "version": "1.0.6", "description": "", "main": "dist/index.js", "types": "dist/index.d.ts", @@ -48,5 +48,6 @@ "typedoc": "^0.21.5", "typedoc-plugin-markdown": "^3.10.4", "typescript": "^4.3.5" - } + }, + "packageManager": "yarn@1.22.19" } diff --git a/src/constants/abi/LiquidStaking.json b/src/constants/abi/LiquidStaking.json new file mode 100644 index 0000000..24405a6 --- /dev/null +++ b/src/constants/abi/LiquidStaking.json @@ -0,0 +1,879 @@ +[ + { + "type": "constructor", + "stateMutability": "nonpayable", + "inputs": [] + }, + { + "type": "event", + "name": "AddedValidator", + "inputs": [ + { + "type": "address", + "name": "admin", + "internalType": "address", + "indexed": true + }, + { + "type": "address", + "name": "validatorAdded", + "internalType": "address", + "indexed": false + } + ], + "anonymous": false + }, + { + "type": "event", + "name": "AdminChanged", + "inputs": [ + { + "type": "address", + "name": "previousAdmin", + "internalType": "address", + "indexed": false + }, + { + "type": "address", + "name": "newAdmin", + "internalType": "address", + "indexed": false + } + ], + "anonymous": false + }, + { + "type": "event", + "name": "BeaconUpgraded", + "inputs": [ + { + "type": "address", + "name": "beacon", + "internalType": "address", + "indexed": true + } + ], + "anonymous": false + }, + { + "type": "event", + "name": "Burned", + "inputs": [ + { + "type": "uint256", + "name": "tokens", + "internalType": "uint256", + "indexed": false + }, + { + "type": "address", + "name": "exchanger", + "internalType": "address", + "indexed": false + } + ], + "anonymous": false + }, + { + "type": "event", + "name": "ChangedProtocolFee", + "inputs": [ + { + "type": "address", + "name": "admin", + "internalType": "address", + "indexed": true + }, + { + "type": "uint256", + "name": "newBasisRate", + "internalType": "uint256", + "indexed": false + } + ], + "anonymous": false + }, + { + "type": "event", + "name": "ChangedValidatorIndex", + "inputs": [ + { + "type": "uint256", + "name": "newIndex", + "internalType": "uint256", + "indexed": false + }, + { + "type": "uint256", + "name": "priorIndex", + "internalType": "uint256", + "indexed": false + } + ], + "anonymous": false + }, + { + "type": "event", + "name": "Deposited", + "inputs": [ + { + "type": "address", + "name": "user", + "internalType": "address", + "indexed": true + }, + { + "type": "uint256", + "name": "deposit", + "internalType": "uint256", + "indexed": false + }, + { + "type": "uint256", + "name": "tokens", + "internalType": "uint256", + "indexed": false + } + ], + "anonymous": false + }, + { + "type": "event", + "name": "DisabledSafeguard", + "inputs": [ + { + "type": "address", + "name": "admin", + "internalType": "address", + "indexed": true + } + ], + "anonymous": false + }, + { + "type": "event", + "name": "DistributedProtocolFee", + "inputs": [ + { + "type": "address", + "name": "treasury", + "internalType": "address", + "indexed": true + }, + { + "type": "uint256", + "name": "rewardedShares", + "internalType": "uint256", + "indexed": false + }, + { + "type": "uint256", + "name": "protocolFees", + "internalType": "uint256", + "indexed": false + }, + { + "type": "uint256", + "name": "priceRatio", + "internalType": "uint256", + "indexed": false + } + ], + "anonymous": false + }, + { + "type": "event", + "name": "Initialized", + "inputs": [ + { + "type": "uint8", + "name": "version", + "internalType": "uint8", + "indexed": false + } + ], + "anonymous": false + }, + { + "type": "event", + "name": "NewSystemStakeLimit", + "inputs": [ + { + "type": "uint256", + "name": "newLimit", + "internalType": "uint256", + "indexed": false + }, + { + "type": "uint256", + "name": "priorLimit", + "internalType": "uint256", + "indexed": false + } + ], + "anonymous": false + }, + { + "type": "event", + "name": "OwnershipTransferred", + "inputs": [ + { + "type": "address", + "name": "previousOwner", + "internalType": "address", + "indexed": true + }, + { + "type": "address", + "name": "newOwner", + "internalType": "address", + "indexed": true + } + ], + "anonymous": false + }, + { + "type": "event", + "name": "Paused", + "inputs": [], + "anonymous": false + }, + { + "type": "event", + "name": "ReenabledSafeguard", + "inputs": [ + { + "type": "address", + "name": "admin", + "internalType": "address", + "indexed": true + }, + { + "type": "uint256", + "name": "newLimit", + "internalType": "uint256", + "indexed": false + } + ], + "anonymous": false + }, + { + "type": "event", + "name": "RemovedValidator", + "inputs": [ + { + "type": "address", + "name": "validatorRemoved", + "internalType": "address", + "indexed": false + }, + { + "type": "address", + "name": "admin", + "internalType": "address", + "indexed": true + } + ], + "anonymous": false + }, + { + "type": "event", + "name": "ReplacedValidator", + "inputs": [ + { + "type": "address", + "name": "newValidator", + "internalType": "address", + "indexed": false + }, + { + "type": "address", + "name": "oldValidator", + "internalType": "address", + "indexed": false + } + ], + "anonymous": false + }, + { + "type": "event", + "name": "Unpaused", + "inputs": [], + "anonymous": false + }, + { + "type": "event", + "name": "UpdatedPriceRatio", + "inputs": [ + { + "type": "uint256", + "name": "updatedRatio", + "internalType": "uint256", + "indexed": false + }, + { + "type": "uint256", + "name": "accumulatedRewards", + "internalType": "uint256", + "indexed": false + }, + { + "type": "uint256", + "name": "totalSupply", + "internalType": "uint256", + "indexed": false + } + ], + "anonymous": false + }, + { + "type": "event", + "name": "Upgraded", + "inputs": [ + { + "type": "address", + "name": "implementation", + "internalType": "address", + "indexed": true + } + ], + "anonymous": false + }, + { + "type": "event", + "name": "Withdrawn", + "inputs": [ + { + "type": "address", + "name": "user", + "internalType": "address", + "indexed": true + }, + { + "type": "uint256", + "name": "tokens", + "internalType": "uint256", + "indexed": false + }, + { + "type": "uint256", + "name": "rate", + "internalType": "uint256", + "indexed": false + }, + { + "type": "uint256", + "name": "payout", + "internalType": "uint256", + "indexed": false + } + ], + "anonymous": false + }, + { + "type": "fallback", + "stateMutability": "payable" + }, + { + "type": "function", + "stateMutability": "nonpayable", + "outputs": [], + "name": "addValidator", + "inputs": [ + { + "type": "address", + "name": "_newValidator", + "internalType": "address" + } + ] + }, + { + "type": "function", + "stateMutability": "nonpayable", + "outputs": [], + "name": "changeProtocolFeeBasis", + "inputs": [ + { + "type": "uint256", + "name": "_amount", + "internalType": "uint256" + } + ] + }, + { + "type": "function", + "stateMutability": "view", + "outputs": [ + { + "type": "address", + "name": "", + "internalType": "address" + } + ], + "name": "consensus", + "inputs": [] + }, + { + "type": "function", + "stateMutability": "payable", + "outputs": [], + "name": "deposit", + "inputs": [] + }, + { + "type": "function", + "stateMutability": "view", + "outputs": [ + { + "type": "uint256", + "name": "", + "internalType": "uint256" + } + ], + "name": "getProtocolFeeBasis", + "inputs": [] + }, + { + "type": "function", + "stateMutability": "view", + "outputs": [ + { + "type": "address", + "name": "", + "internalType": "address" + } + ], + "name": "getSFToken", + "inputs": [] + }, + { + "type": "function", + "stateMutability": "view", + "outputs": [ + { + "type": "address", + "name": "", + "internalType": "address" + } + ], + "name": "getTreasury", + "inputs": [] + }, + { + "type": "function", + "stateMutability": "view", + "outputs": [ + { + "type": "address", + "name": "", + "internalType": "address" + } + ], + "name": "getValidatorAt", + "inputs": [ + { + "type": "uint256", + "name": "_position", + "internalType": "uint256" + } + ] + }, + { + "type": "function", + "stateMutability": "view", + "outputs": [ + { + "type": "uint256", + "name": "", + "internalType": "uint256" + } + ], + "name": "getValidatorIndex", + "inputs": [] + }, + { + "type": "function", + "stateMutability": "view", + "outputs": [ + { + "type": "address[]", + "name": "", + "internalType": "address[]" + } + ], + "name": "getValidators", + "inputs": [] + }, + { + "type": "function", + "stateMutability": "view", + "outputs": [ + { + "type": "uint256", + "name": "", + "internalType": "uint256" + } + ], + "name": "getValidatorsLength", + "inputs": [] + }, + { + "type": "function", + "stateMutability": "nonpayable", + "outputs": [], + "name": "initialize", + "inputs": [ + { + "type": "address", + "name": "_initialValidator", + "internalType": "address" + }, + { + "type": "address", + "name": "_consensusAddress", + "internalType": "address" + }, + { + "type": "address", + "name": "_tokenAddress", + "internalType": "address" + }, + { + "type": "address", + "name": "_treasuryAddress", + "internalType": "address" + }, + { + "type": "uint256", + "name": "_systemLimit", + "internalType": "uint256" + }, + { + "type": "uint256", + "name": "_feeBasis", + "internalType": "uint256" + } + ] + }, + { + "type": "function", + "stateMutability": "view", + "outputs": [ + { + "type": "bool", + "name": "", + "internalType": "bool" + } + ], + "name": "isInValidatorList", + "inputs": [ + { + "type": "address", + "name": "_validator", + "internalType": "address" + } + ] + }, + { + "type": "function", + "stateMutability": "view", + "outputs": [ + { + "type": "bool", + "name": "", + "internalType": "bool" + } + ], + "name": "isOverLimit", + "inputs": [] + }, + { + "type": "function", + "stateMutability": "view", + "outputs": [ + { + "type": "bool", + "name": "", + "internalType": "bool" + } + ], + "name": "isPaused", + "inputs": [] + }, + { + "type": "function", + "stateMutability": "view", + "outputs": [ + { + "type": "bool", + "name": "", + "internalType": "bool" + } + ], + "name": "isSafeguardLimitEnabled", + "inputs": [] + }, + { + "type": "function", + "stateMutability": "view", + "outputs": [ + { + "type": "address", + "name": "", + "internalType": "address" + } + ], + "name": "owner", + "inputs": [] + }, + { + "type": "function", + "stateMutability": "nonpayable", + "outputs": [], + "name": "pause", + "inputs": [] + }, + { + "type": "function", + "stateMutability": "view", + "outputs": [ + { + "type": "uint256", + "name": "", + "internalType": "uint256" + } + ], + "name": "priceRatio", + "inputs": [] + }, + { + "type": "function", + "stateMutability": "view", + "outputs": [ + { + "type": "bytes32", + "name": "", + "internalType": "bytes32" + } + ], + "name": "proxiableUUID", + "inputs": [] + }, + { + "type": "function", + "stateMutability": "nonpayable", + "outputs": [], + "name": "reenableLimit", + "inputs": [ + { + "type": "uint256", + "name": "_limit", + "internalType": "uint256" + } + ] + }, + { + "type": "function", + "stateMutability": "nonpayable", + "outputs": [], + "name": "removeLimit", + "inputs": [] + }, + { + "type": "function", + "stateMutability": "nonpayable", + "outputs": [], + "name": "removeValidator", + "inputs": [ + { + "type": "address", + "name": "_validator", + "internalType": "address" + } + ] + }, + { + "type": "function", + "stateMutability": "nonpayable", + "outputs": [], + "name": "renounceOwnership", + "inputs": [] + }, + { + "type": "function", + "stateMutability": "nonpayable", + "outputs": [], + "name": "replaceValidator", + "inputs": [ + { + "type": "address", + "name": "_validator", + "internalType": "address" + }, + { + "type": "address", + "name": "_replacement", + "internalType": "address" + } + ] + }, + { + "type": "function", + "stateMutability": "nonpayable", + "outputs": [], + "name": "replaceValidatorByIndex", + "inputs": [ + { + "type": "uint256", + "name": "_index", + "internalType": "uint256" + }, + { + "type": "address", + "name": "_replacement", + "internalType": "address" + } + ] + }, + { + "type": "function", + "stateMutability": "nonpayable", + "outputs": [], + "name": "setSystemStakeLimit", + "inputs": [ + { + "type": "uint256", + "name": "_amount", + "internalType": "uint256" + } + ] + }, + { + "type": "function", + "stateMutability": "nonpayable", + "outputs": [], + "name": "setValidatorIndex", + "inputs": [ + { + "type": "uint256", + "name": "_index", + "internalType": "uint256" + } + ] + }, + { + "type": "function", + "stateMutability": "view", + "outputs": [ + { + "type": "uint256", + "name": "", + "internalType": "uint256" + } + ], + "name": "systemStakeLimit", + "inputs": [] + }, + { + "type": "function", + "stateMutability": "view", + "outputs": [ + { + "type": "uint256", + "name": "", + "internalType": "uint256" + } + ], + "name": "systemTotalStaked", + "inputs": [] + }, + { + "type": "function", + "stateMutability": "nonpayable", + "outputs": [], + "name": "transferOwnership", + "inputs": [ + { + "type": "address", + "name": "newOwner", + "internalType": "address" + } + ] + }, + { + "type": "function", + "stateMutability": "nonpayable", + "outputs": [], + "name": "unpause", + "inputs": [] + }, + { + "type": "function", + "stateMutability": "nonpayable", + "outputs": [], + "name": "update", + "inputs": [] + }, + { + "type": "function", + "stateMutability": "nonpayable", + "outputs": [], + "name": "upgradeTo", + "inputs": [ + { + "type": "address", + "name": "newImplementation", + "internalType": "address" + } + ] + }, + { + "type": "function", + "stateMutability": "payable", + "outputs": [], + "name": "upgradeToAndCall", + "inputs": [ + { + "type": "address", + "name": "newImplementation", + "internalType": "address" + }, + { + "type": "bytes", + "name": "data", + "internalType": "bytes" + } + ] + }, + { + "type": "function", + "stateMutability": "nonpayable", + "outputs": [], + "name": "withdraw", + "inputs": [ + { + "type": "uint256", + "name": "_amount", + "internalType": "uint256" + } + ] + }, + { + "type": "function", + "stateMutability": "nonpayable", + "outputs": [], + "name": "withdraw", + "inputs": [ + { + "type": "uint256", + "name": "_amount", + "internalType": "uint256" + }, + { + "type": "uint256", + "name": "_validatorPosition", + "internalType": "uint256" + } + ] + } +] diff --git a/src/constants/index.ts b/src/constants/index.ts index 6fd6181..ac0a4b3 100644 --- a/src/constants/index.ts +++ b/src/constants/index.ts @@ -19,6 +19,10 @@ export const MASTERCHEF_V3_SUBGRAPH_URL = 'https://api.thegraph.com/subgraphs/na export const xVOLT = '0x97a6e78c9208c21afaDa67e7E61d7ad27688eFd1' export const VOLT = '0x34Ef2Cc892a88415e9f02b91BfA9c91fC0bE6bD4' export const FUSD = '0xd0ce1b4A349C35e61Af02f5971e71ac502441E49' +export const sFUSE = '0xb1DD0B683d9A56525cC096fbF5eec6E60FE79871' +export const WFUSE = '0x0BE9e53fd7EDaC9F859882AfdDa116645287C629' + +export const LIQUID_STAKING = '0xa3dc222eC847Aac61FB6910496295bF344Ea46be' export const STABLESWAP_POOL_LP_HASH = { '0xa3c1046290b490e629e11ace35863cb0cae382ab': '0x2a68d7c6ea986fa06b2665d08b4d08f5e7af960c', diff --git a/src/rewards/ChefRewardProgram.ts b/src/rewards/ChefRewardProgram.ts index 0a3a5db..65f020a 100644 --- a/src/rewards/ChefRewardProgram.ts +++ b/src/rewards/ChefRewardProgram.ts @@ -1,9 +1,10 @@ import RewardProgram from './RewardProgam' import ABI from '../constants/abi/MasterChef.json' +import LIQUID_STAKING_ABI from '../constants/abi/LiquidStaking.json' import { calculateReserves, getChef, weiToNumber } from '../utils' import { ethCall, ethTransaction } from '../utils/eth' import { getChefPool, getChefUser } from '../graphql/fetcher' -import { FUSD, VOLT, xVOLT } from '../constants' +import { FUSD, LIQUID_STAKING, sFUSE, VOLT, WFUSE, xVOLT } from '../constants' import fetchVoltageTokenPrice from '../utils/fetchVoltageTokenPrice' import fetchTokenInfo from '../utils/fetchTokenInfo' import fetchChefPairInfo from '../utils/fetchChefPairInfo' @@ -91,6 +92,22 @@ export default class ChefRewardProgram extends RewardProgram { reserves = [globalTotalStake, null] pairPrice = 1 + } else if (pairAddress.toLowerCase() === sFUSE.toLowerCase()) { + const token0 = await fetchTokenInfo(sFUSE, this.web3) + tokens = [{ id: sFUSE, ...token0 }, null] + + reserves = [globalTotalStake, null] + + const fusePrice = await fetchVoltageTokenPrice(WFUSE, networkId) + + const priceRatio = await ethCall( + LIQUID_STAKING, + 'priceRatio', + LIQUID_STAKING_ABI, + this.web3 + ) + + pairPrice = fusePrice * weiToNumber(priceRatio) } else { const { reserveUSD,