import { ethers } from 'ethers' import { BaseProject, WithdrawStatus } from './base' import FluencePoolABI from '../abis/fluencePool.json' export const fluenceChain = { id: 9999999, name: 'Fluence', nativeCurrency: { name: 'Fluence coin', symbol: 'FLT', decimals: 18, }, rpcUrls: { default: { http: ['https://rpc.mainnet.fluence.dev'] }, }, blockExplorers: { default: { name: 'Fluence', url: 'https://blockscout.mainnet.fluence.dev', }, }, } export const fluenceTestnetChain = { id: 52164803, name: 'Fluence Testnet', nativeCurrency: { name: 'Fluence Testnet coin', symbol: 'tFLT', decimals: 18, }, rpcUrls: { default: { http: ['https://rpc.testnet.fluence.dev'] }, }, blockExplorers: { default: { name: 'Testnet Fluence', url: 'https://blockscout.testnet.fluence.dev', }, }, testnet: true, } export const fluenceContract = { delegationPool: '0x51DC712d5070f91BfD3e1d9de9E8e0d3D2C1C468', pToken: '0xa1cF424EE59d9B5C5B7F6801FE510E430cA1AEA8', miningToken: '0x0000000000000000000000000000000000000000', wpToken: '0xdB49Cc86F799804F4a966dc0c7707c2AFF6a2F28', withdrawQueue: '0x51DC712d5070f91BfD3e1d9de9E8e0d3D2C1C468', } export const fluenceTestnetContract = { delegationPool: '0x2EC40624264fD738b473F7e1a759B0Dc84563e3A', pToken: '0x1Efc5A99A95c542839539f701Eafd9bA863b6F2d', miningToken: '0x0000000000000000000000000000000000000000', wpToken: '0x8Fb5D7EE4998f5db0584FCcB7Eb3194Da789e5F3', withdrawQueue: '0x2EC40624264fD738b473F7e1a759B0Dc84563e3A', } export class FluenceProject extends BaseProject { name = 'Fluence' thawingEnabled = false withdrawQueueEnabled = true miningToken = { name: 'FLT', symbol: 'FLT', decimals: 18, isNative: true, icon: 'https://d135ugxgwtnu1c.cloudfront.net/fluence-2c217536.svg', } pToken = { name: 'pFLT', symbol: 'pFLT', decimals: 18, icon: 'https://d135ugxgwtnu1c.cloudfront.net/fluence-2c217536.svg', } wpToken = { name: 'wpFLT', symbol: 'wpFLT', decimals: 18, icon: 'https://d135ugxgwtnu1c.cloudfront.net/fluence-2c217536.svg', } chainConfig = fluenceChain contracts: { delegationPool: string pToken: string miningToken: string } metadata = { guideLink: 'https://docs.parasail.network/delegation-guides/guide-for-fluence-users/', website: 'https://fluence.network', description: 'Fluence is a decentralized, high-performance computing platform designed for seamless scalability, enabling secure, verifiable and low-cost compute.', about: 'Fluence is a decentralized, high-performance computing platform designed for seamless scalability, enabling secure, verifiable and low-cost compute.', withdrawTips: 'The amount of tokens available for immediate withdrawal. Larger withdrawals need to request withdraw and wait for the reserve to be replenished by new deposits or operator repayments', } constructor({ isTestnet, provider, contracts = {}, }: { isTestnet: boolean provider?: ethers.providers.JsonRpcProvider contracts?: { delegationPool?: string pToken?: string miningToken?: string } }) { super(provider) this.chainConfig = isTestnet ? fluenceTestnetChain : fluenceChain this.contracts = isTestnet ? { ...fluenceTestnetContract, ...contracts } : { ...fluenceContract, ...contracts } this.isTestnet = isTestnet } getPoolContract = () => { const provider = this.getProvider() return new ethers.Contract( this.contracts.delegationPool, FluencePoolABI, provider ) } deposit = async (address: string, amount: string, signer: ethers.Signer) => { const poolContract = this.getPoolContract().connect(signer) const tx = await poolContract.deposit({ value: ethers.utils.parseEther(amount), }) return tx } withdraw = async (address: string, amount: string, signer: ethers.Signer) => { const poolContract = this.getPoolContract().connect(signer) const tx = await poolContract.withdraw(ethers.utils.parseEther(amount)) return tx } approveWithdrawQueue = async (amount: string, signer: ethers.Signer) => { const erc20 = this.getTokenContract(this.contracts.pToken).connect(signer) const allowance = await erc20.allowance( signer.getAddress(), this.contracts.delegationPool! ) if (allowance.lt(ethers.utils.parseUnits(amount, this.pToken.decimals))) { const tx = await erc20.approve( this.contracts.delegationPool!, ethers.utils.parseUnits(amount, this.pToken.decimals) ) return tx } return null } requestWithdrawQueue = async (amount: string, signer: ethers.Signer) => { const poolContract = this.getPoolContract().connect(signer) const tx = await poolContract.requestWithdraw( ethers.utils.parseEther(amount) ) return tx } getWithdrawQueueByAddress = async (address: string) => { const poolContract = this.getPoolContract() const result = await poolContract.getUserWithdrawRequests(address) return result.map((item: any) => ({ owner: address, totalShares: item.shares, remainingShares: item.fullfilled ? 0 : item.shares, timestamp: item.timestamp, status: item.fullfilled ? WithdrawStatus.Completed : WithdrawStatus.Pending, })) } getRequestCountInQueue = async (address: string) => { const poolContract = this.getPoolContract() const count = await poolContract.getUserWithdrawalRequestCount(address) return Number(count) } getWithdrawStorage = async () => { const poolContract = this.getPoolContract() const result = await poolContract.withdrawalStorage() return result } getAssetsInfo = async () => { const data = await fetch( this.isTestnet ? 'https://test.parasail.network/api/fluence' : 'https://www.parasail.network/api/fluence' ) const json = await data.json() return { apy: json.apy, lockedAssets: json.tvl / json.price, } } }