Created
October 4, 2024 11:03
-
-
Save parva-jain/16429130fc2958c286287db8fe8ae28a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { ethers } = require("ethers"); | |
const { EvmPriceServiceConnection } = require("@pythnetwork/pyth-evm-js"); | |
const userPrivateKey = "YOUR_PRIVATE_KEY"; // Enter private key | |
const depositAmount = "0.01"; // Enter amount to deposit, example - 0.01 FIL | |
const contractAddress = "0x0E8b07CefDC0363cA6e0Ca06093c2596746f7d3d"; | |
const depositABI = [ | |
{ | |
inputs: [ | |
{ | |
internalType: "address", | |
name: "_token", | |
type: "address", | |
}, | |
{ | |
internalType: "uint256", | |
name: "_amount", | |
type: "uint256", | |
}, | |
{ | |
internalType: "bool", | |
name: "_purchase", | |
type: "bool", | |
}, | |
{ | |
internalType: "bytes[]", | |
name: "_offchainPriceUpdate", | |
type: "bytes[]", | |
}, | |
], | |
name: "depositFund", | |
outputs: [], | |
stateMutability: "payable", | |
type: "function", | |
}, | |
]; | |
const provider = new ethers.JsonRpcProvider("https://api.node.glif.io"); | |
const user = new ethers.Wallet(userPrivateKey, provider); | |
const endowmentContract = new ethers.Contract( | |
contractAddress, | |
depositABI, | |
provider | |
); | |
const depositFunds = async () => { | |
console.log(`Depositing ${depositAmount} FIL to Endowment Pool...`); | |
const value = ethers.parseEther(depositAmount); | |
const feeData = await provider.getFeeData(); | |
// for pyth offchain price update data | |
const connection = new EvmPriceServiceConnection( | |
"https://hermes.pyth.network" | |
); | |
const priceIds = [ | |
"0x150ac9b959aee0051e4091f0ef5216d941f590e1c5e7f91cf7635b5c11628c0e", | |
]; | |
const offchainPriceUpdate = await connection.getPriceFeedsUpdateData( | |
priceIds | |
); | |
const tx = await endowmentContract.connect(user).depositFund( | |
ethers.ZeroAddress, | |
value, | |
true, // | |
offchainPriceUpdate, | |
{ | |
value: value, | |
gasPrice: feeData.gasPrice, | |
} | |
); | |
await tx.wait(); | |
console.log("Native deposit successful:", tx.hash); | |
}; | |
depositFunds() | |
.then(() => process.exit(0)) | |
.catch((error) => { | |
console.error(error); | |
process.exit(1); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment