forked from kwilteam/kwil_db_api
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
52 additions
and
29 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,26 @@ | ||
const fundingPools = require('./fundingPools.json') | ||
const abi = require('./abi.json') | ||
const Web3 = require('web3') | ||
const { initContract } = require('./utils') | ||
|
||
const fundPool = async (_name, _chain, _token, _amt, _privateKey = null) => { | ||
try { | ||
const contract = await initContract(_chain, _token, _privateKey) | ||
|
||
const fundPool = async (_name, _chain, _token, _privateKey = null) => { | ||
const gasPrice = await web3.eth.getGasPrice() | ||
const gasEstimate = await contract.methods.fundMoat(_name, _amt).estimateGas({gasPrice: gasPrice}) | ||
const response = await contract.methods.fundMoat(_name, _amt).send({ | ||
gasPrice: gasPrice, | ||
gas: gasEstimate * 1.2, | ||
from: _addr | ||
}) | ||
|
||
} | ||
return response | ||
|
||
} catch(e) { | ||
console.log(e) | ||
return 'failure' | ||
} | ||
} | ||
|
||
module.exports = {fundPool} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const Web3 = require('web3') | ||
const fundingPools = require('./fundingPools.json') | ||
const abi = require('./abi.json') | ||
|
||
const initContract = async (_chain, _token, _privateKey = null) => { | ||
const endpoint = fundingPools[_chain].RPC | ||
const web3 = new Web3(endpoint) | ||
const contractAddr = fundingPools[_chain].tokens[_token] | ||
const accounts = await web3.eth.getAccounts() | ||
|
||
if (accounts.length < 1 && _privateKey == null) { | ||
throw new Error('Must have an Eth account') | ||
} else if (_privateKey != null) { | ||
web3.eth.accounts.wallet.add(_privateKey) | ||
} | ||
const contract = new web3.eth.Contract(abi.abi, contractAddr) | ||
|
||
return contract | ||
} | ||
|
||
const isValidAddress = (_addr) => { | ||
return Web3.utils.isAddress(_addr) | ||
} | ||
|
||
module.exports = {initContract, isValidAddress} |
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