import { ethers } from 'ethers' import { BaseProject } from './base' export const filecoinChain = { id: 314, name: 'Filecoin', nativeCurrency: { name: 'Filecoin', symbol: 'FIL', decimals: 18, }, rpcUrls: { default: { http: ['https://api.node.glif.io'], }, }, blockExplorers: { default: { name: 'Filecoin', url: 'https://filfox.info', }, }, } export const filecoinTestnetChain = { id: 314159, name: 'Calibration', nativeCurrency: { name: 'test FIL', symbol: 'tFIL', decimals: 18, }, rpcUrls: { default: { http: ['https://api.calibration.node.glif.io/rpc/v1'] }, }, blockExplorers: { default: { name: 'Calibration', url: 'https://calibration.filfox.info/en', }, }, testnet: true, } export const filecoinContract = { delegationPool: '0xD51Cb0FA9A91f156a80188a18f039140704b8df7', pToken: '0xAaa93ac72bECfbBc9149f293466bbdAa4b5Ef68C', miningToken: '0x0000000000000000000000000000000000000000', dataHelper: '0x65846aECBF23385F76B73ef1EDD1ebdFf7Ac258D', wpToken: '0x57E3BB9F790185Cfe70Cc2C15Ed5d6B84dCf4aDb', } export const filecoinTestnetContract = { delegationPool: '0x5c9d3502db845764240A38BD4a1AEDD2056DbCeA', pToken: '0xADD77Cb736Db6F4223776A3E4b173657D0d7F8c8', miningToken: '0x0000000000000000000000000000000000000000', dataHelper: '0xC4E65Dd0e535d2eEFC0545dc5A6606c6aB420396', wpToken: '0x07961742e79Cecf1171d2D5050ca489572C61384', } export class FilecoinProject extends BaseProject { name = 'Filecoin' thawingEnabled = false confirmations = 2 miningToken = { name: 'FIL', symbol: 'FIL', decimals: 18, isNative: true, icon: 'https://d135ugxgwtnu1c.cloudfront.net/fil1-3bfe11b7.svg', } pToken = { name: 'pFIL', symbol: 'pFIL', decimals: 18, icon: 'https://d135ugxgwtnu1c.cloudfront.net/fil1-3bfe11b7.svg', } wpToken = { name: 'wpFIL', symbol: 'wpFIL', decimals: 18, icon: 'https://d135ugxgwtnu1c.cloudfront.net/fil1-3bfe11b7.svg', } chainConfig = filecoinChain contracts: { delegationPool: string pToken: string miningToken: string dataHelper: string } metadata = { guideLink: 'https://docs.parasail.network/delegation-guides/guide-for-filecoin-users/', website: 'https://filecoin.io/', description: 'Filecoin is a peer-to-peer network that stores files, with built-in economic incentives and cryptography to ensure files are stored reliably over time.', about: 'Filecoin is a peer-to-peer network that stores files, with built-in economic incentives and cryptography to ensure files are stored reliably over time.', withdrawTips: 'The amount of tokens available for immediate withdrawal. Larger withdrawals need to 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 dataHelper?: string } }) { super(provider) this.chainConfig = isTestnet ? filecoinTestnetChain : filecoinChain this.contracts = isTestnet ? { ...filecoinTestnetContract, ...contracts } : { ...filecoinContract, ...contracts } this.isTestnet = isTestnet } getPoolContract = () => { const provider = this.getProvider() return new ethers.Contract( this.contracts.delegationPool, [ 'function depositFIL(uint256, address) external payable', 'function withdrawFIL(uint256) external', ], provider ) } deposit = async (address: string, amount: string, signer: ethers.Signer) => { const poolContract = this.getPoolContract().connect(signer) const tx = await poolContract.depositFIL( ethers.utils.parseEther(amount), address, { 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.withdrawFIL(ethers.utils.parseEther(amount)) return tx } getAssetsInfo = async () => { const data = await fetch( this.isTestnet ? 'https://test.parasail.network/api/staking-projects?project=FIL' : 'https://www.parasail.network/api/staking-projects?project=FIL' ) const json = await data.json() return { apy: json.apy, lockedAssets: json.tvl / json.price, } } convertToAssets = async (amount: string) => { const wTokenContract = this.getWPTokenContract() return await wTokenContract.getPFILByWPFIL( ethers.utils.parseUnits(amount, this.pToken.decimals) ) } convertToShares = async (amount: string) => { const wTokenContract = this.getWPTokenContract() return await wTokenContract.getWPFILByPFIL( ethers.utils.parseUnits(amount, this.pToken.decimals) ) } }