2018-12-01 20:32:00 +00:00
|
|
|
import LPVault from 'Embark/contracts/LPVault'
|
2018-12-21 19:31:46 +00:00
|
|
|
import LiquidPledging from 'Embark/contracts/LiquidPledging'
|
2019-01-04 21:34:26 +00:00
|
|
|
import SNT from 'Embark/contracts/SNT'
|
2018-12-08 17:52:22 +00:00
|
|
|
import web3 from 'Embark/web3'
|
2018-12-01 20:32:00 +00:00
|
|
|
|
2018-12-01 22:16:58 +00:00
|
|
|
export const initVaultAndLP = async () => {
|
2018-12-10 19:04:31 +00:00
|
|
|
let estimateGas;
|
|
|
|
let toSend;
|
|
|
|
|
|
|
|
|
2018-12-21 19:31:46 +00:00
|
|
|
toSend = LiquidPledging.methods.initialize(LPVault._address);
|
2018-12-10 19:04:31 +00:00
|
|
|
estimateGas = await toSend.estimateGas();
|
|
|
|
const lpInit = await toSend.send({gas: estimateGas + 1000})
|
2018-12-01 14:31:04 +00:00
|
|
|
console.log(lpInit)
|
2018-12-10 19:04:31 +00:00
|
|
|
|
2018-12-21 19:31:46 +00:00
|
|
|
toSend = LPVault.methods.initialize(LiquidPledging._address);
|
2018-12-10 19:04:31 +00:00
|
|
|
estimateGas = await toSend.estimateGas();
|
|
|
|
const vaultInit = await toSend.send({gas: estimateGas + 1000})
|
2018-12-08 17:52:22 +00:00
|
|
|
console.log(vaultInit)
|
2018-12-01 14:31:04 +00:00
|
|
|
}
|
2018-12-01 20:32:00 +00:00
|
|
|
|
|
|
|
export const vaultPledgingNeedsInit = async () => {
|
2018-12-21 19:31:46 +00:00
|
|
|
const needsInit = !!Number(await LiquidPledging.methods.getInitializationBlock().call())
|
2018-12-08 17:52:22 +00:00
|
|
|
&& !!Number(await LPVault.methods.getInitializationBlock().call())
|
2018-12-01 20:32:00 +00:00
|
|
|
return needsInit
|
|
|
|
}
|
|
|
|
|
2019-02-06 23:02:03 +00:00
|
|
|
export const standardTokenApproval = async (contract, amount = '10000000') => {
|
|
|
|
const { methods: { approve } } = contract || SNT
|
2018-12-21 19:31:46 +00:00
|
|
|
const spender = LiquidPledging._address
|
2018-12-01 22:16:58 +00:00
|
|
|
return await approve(
|
|
|
|
spender,
|
2019-02-06 23:02:03 +00:00
|
|
|
web3.utils.toWei(amount, 'tether')
|
2018-12-01 22:16:58 +00:00
|
|
|
).send()
|
|
|
|
}
|
|
|
|
|
2019-02-06 23:02:03 +00:00
|
|
|
export const getLpAllowance = async contract => {
|
|
|
|
const { methods: { allowance } } = contract || SNT
|
2018-12-01 20:32:00 +00:00
|
|
|
const account = await web3.eth.getCoinbase()
|
2018-12-21 19:31:46 +00:00
|
|
|
const spender = LiquidPledging._address
|
2019-02-06 23:02:03 +00:00
|
|
|
const allowanceAmt = await allowance(account, spender).call()
|
2018-12-01 22:16:58 +00:00
|
|
|
return allowanceAmt
|
2018-12-01 20:32:00 +00:00
|
|
|
}
|