Skip to content

Commit

Permalink
Merge pull request #108 from lighthouse-web3/v0.3.0
Browse files Browse the repository at this point in the history
V0.3.0
  • Loading branch information
ravish1729 authored Nov 30, 2023
2 parents 3950993 + a0208f7 commit 4504f6e
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Lighthouse <img src="https://img.shields.io/badge/BETA-v0.2.9-green"/>
# Lighthouse <img src="https://img.shields.io/badge/BETA-v0.3.0-green"/>

Lighthouse is a permanent decentralized file storage protocol that allows the ability to pay once and store forever. While traditionally, users need to repeatedly keep track and pay for their storage after every fixed amount of time, Lighthouse manages this for them and makes sure that user files are stored forever. The aim is to move users from a rent-based cost model where they are renting their own files on cloud storage to a permanent ownership model. It is built on top of IPFS, Filecoin, and Polygon. It uses the existing miner network and storage capacity of the filecoin network.

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lighthouse-web3/sdk",
"version": "0.2.9",
"version": "0.3.0",
"description": "NPM package and CLI tool to interact with lighthouse protocol",
"main": "./dist/Lighthouse/index.js",
"types": "./dist/Lighthouse/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Command.prototype.helpInformation = function (context: any) {
}

widgets.addHelpText('before', 'Welcome to lighthouse-web3')
widgets.version('0.2.9')
widgets.version('0.3.0')

widgets
.command('wallet')
Expand Down
33 changes: 29 additions & 4 deletions src/Lighthouse/payPerDeal/fund/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,46 @@ export default async (amount: number, network: string, token: string) => {
}
//@ts-ignore
const provider = new ethers.BrowserProvider((window as any).ethereum)
const getFeeData=await provider.getFeeData()
const signer = await provider.getSigner()
if(token.toLowerCase()==="native") {
const gasEstimate = await signer.estimateGas({
to: config.lighthouse_contract_address,
value: amount,
})
const tx = await signer.sendTransaction({
to: config.lighthouse_contract_address,
value: amount,
to: config.lighthouse_contract_address,
value: amount,
gasLimit: gasEstimate,
gasPrice: getFeeData.gasPrice,
})
await tx.wait()
return tx
} else{
const tokenAddress = config[`${token.toLowerCase()}_contract_address`]
const paymentContract = new ethers.Contract(config.lighthouse_contract_address, lighthuseContract, signer)
const erc20Contract = new ethers.Contract(tokenAddress, erc20, signer)
const approvalTx = await erc20Contract.approve(config.lighthouse_contract_address, amount)
const approvalData = erc20Contract.interface.encodeFunctionData("approve", [config.lighthouse_contract_address, amount]);
const approvalTxObject = {
to: tokenAddress,
data: approvalData,
}
const gasEstimateForApproval = await signer.estimateGas(approvalTxObject);
const approvalTx = await erc20Contract.approve(config.lighthouse_contract_address, amount, {
gasLimit: gasEstimateForApproval,
gasPrice: getFeeData.gasPrice,
})
await approvalTx.wait()
const tx = await paymentContract.receiveToken(amount, tokenAddress)
const transferData = paymentContract.interface.encodeFunctionData("receiveToken", [amount, tokenAddress])
const transferTxObject = {
to: config.lighthouse_contract_address,
data: transferData,
}
const gasEstimateForTransfer = await signer.estimateGas(transferTxObject)
const tx = await paymentContract.receiveToken(amount, tokenAddress, {
gasLimit: gasEstimateForTransfer,
gasPrice: getFeeData.gasPrice,
})
await tx.wait()
return tx
}
Expand Down
29 changes: 27 additions & 2 deletions src/Lighthouse/payPerDeal/fund/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,46 @@ export default async (amount: number, network: string, token: string, privateKey
throw new Error("Unsupported Network!!!")
}
const provider = new ethers.JsonRpcProvider(config.rpc)
const getFeeData=await provider.getFeeData()
const signer = new ethers.Wallet(privateKey, provider)
if(token.toLowerCase()==="native") {
const gasEstimate = await signer.estimateGas({
to: config.lighthouse_contract_address,
value: amount,
})
const tx = await signer.sendTransaction({
to: config.lighthouse_contract_address,
value: amount,
gasLimit: gasEstimate,
gasPrice: getFeeData.gasPrice,
})
await tx.wait()
return tx
} else{
const tokenAddress = config[`${token.toLowerCase()}_contract_address`]
const paymentContract = new ethers.Contract(config.lighthouse_contract_address, lighthuseContract, signer)
const erc20Contract = new ethers.Contract(tokenAddress, erc20, signer)
const approvalTx = await erc20Contract.approve(config.lighthouse_contract_address, amount)
const approvalData = erc20Contract.interface.encodeFunctionData("approve", [config.lighthouse_contract_address, amount])
const approvalTxObject = {
to: tokenAddress,
data: approvalData,
}
const gasEstimateForApproval = await signer.estimateGas(approvalTxObject)
const approvalTx = await erc20Contract.approve(config.lighthouse_contract_address, amount, {
gasLimit: gasEstimateForApproval,
gasPrice: getFeeData.gasPrice,
})
await approvalTx.wait()
const tx = await paymentContract.receiveToken(amount, tokenAddress)
const transferData = paymentContract.interface.encodeFunctionData("receiveToken", [amount, tokenAddress])
const transferTxObject = {
to: config.lighthouse_contract_address,
data: transferData,
}
const gasEstimateForTransfer = await signer.estimateGas(transferTxObject)
const tx = await paymentContract.receiveToken(amount, tokenAddress, {
gasLimit: gasEstimateForTransfer,
gasPrice: getFeeData.gasPrice,
})
await tx.wait()
return tx
}
Expand Down
4 changes: 2 additions & 2 deletions src/lighthouse.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ const defaultConfig = {
},
filecoin: {
symbol: 'FIL',
rpc: 'https://mainnet.optimism.io',
rpc: 'https://api.node.glif.io',
scan: 'https://filfox.info/en/message/',
chain_id: '10',
chain_id: '314',
lighthouse_contract_address: '0x9297A1eD441eA63257e933DCC335EE4D1E562C37',
usdc_contract_address: '0xEB466342C4d449BC9f53A865D5Cb90586f405215',
usdc_contract_decimal: 6,
Expand Down

0 comments on commit 4504f6e

Please sign in to comment.