mirror of
https://github.com/Instadapp/dsa-connectors-old.git
synced 2024-07-29 22:47:46 +00:00
added deposit method and test;
This commit is contained in:
parent
b3da8dcba0
commit
0ff06b28f1
|
@ -112,4 +112,48 @@ contract CurveSBTCProtocol is CurveSBTCHelpers {
|
||||||
emitEvent(_eventCode, _eventParam);
|
emitEvent(_eventCode, _eventParam);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Deposit Token.
|
||||||
|
* @param token token address.
|
||||||
|
* @param amt token amount.
|
||||||
|
* @param unitAmt unit amount of curve_amt/token_amt with slippage.
|
||||||
|
* @param getId Get token amount at this ID from `InstaMemory` Contract.
|
||||||
|
* @param setId Set token amount at this ID in `InstaMemory` Contract.
|
||||||
|
*/
|
||||||
|
function deposit(
|
||||||
|
address token,
|
||||||
|
uint amt,
|
||||||
|
uint unitAmt,
|
||||||
|
uint getId,
|
||||||
|
uint setId
|
||||||
|
) external payable {
|
||||||
|
uint256 _amt = getUint(getId, amt);
|
||||||
|
ERC20 tokenContract = ERC20(token);
|
||||||
|
|
||||||
|
_amt = _amt == uint(-1) ? tokenContract.balanceOf(address(this)) : _amt;
|
||||||
|
uint[3] memory _amts;
|
||||||
|
_amts[uint(getTokenI(token))] = _amt;
|
||||||
|
|
||||||
|
tokenContract.approve(getCurveSwapAddr(), _amt);
|
||||||
|
|
||||||
|
uint _amt18 = convertTo18(tokenContract.decimals(), _amt);
|
||||||
|
uint _slippageAmt = wmul(unitAmt, _amt18);
|
||||||
|
|
||||||
|
ERC20 curveTokenContract = ERC20(getCurveTokenAddr());
|
||||||
|
uint initialCurveBal = curveTokenContract.balanceOf(address(this));
|
||||||
|
|
||||||
|
ICurve(getCurveSwapAddr()).add_liquidity(_amts, _slippageAmt);
|
||||||
|
|
||||||
|
uint finalCurveBal = curveTokenContract.balanceOf(address(this));
|
||||||
|
|
||||||
|
uint mintAmt = sub(finalCurveBal, initialCurveBal);
|
||||||
|
|
||||||
|
setUint(setId, mintAmt);
|
||||||
|
|
||||||
|
emit LogDeposit(token, _amt, mintAmt, getId, setId);
|
||||||
|
bytes32 _eventCode = keccak256("LogDeposit(address,uint256,uint256,uint256,uint256)");
|
||||||
|
bytes memory _eventParam = abi.encode(token, _amt, mintAmt, getId, setId);
|
||||||
|
emitEvent(_eventCode, _eventParam);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ const CurveSBTCProtocol = artifacts.require('CurveSBTCProtocol');
|
||||||
const erc20 = require("@studydefi/money-legos/erc20");
|
const erc20 = require("@studydefi/money-legos/erc20");
|
||||||
const uniswap = require("@studydefi/money-legos/uniswap");
|
const uniswap = require("@studydefi/money-legos/uniswap");
|
||||||
const sbtcABI = require("./abi/sbtc.json");
|
const sbtcABI = require("./abi/sbtc.json");
|
||||||
|
const erc20ABI = require("./abi/erc20.js");
|
||||||
|
|
||||||
contract('CurveSBTCProtocol', async accounts => {
|
contract('CurveSBTCProtocol', async accounts => {
|
||||||
const [sender, receiver] = accounts;
|
const [sender, receiver] = accounts;
|
||||||
|
@ -74,4 +75,29 @@ contract('CurveSBTCProtocol', async accounts => {
|
||||||
const sbtcAfter = await sbtcContract.methods.balanceOf(sender).call();
|
const sbtcAfter = await sbtcContract.methods.balanceOf(sender).call();
|
||||||
expect(sbtcAfter - sbtcBefore).to.be.at.least(ether("0.09"));
|
expect(sbtcAfter - sbtcBefore).to.be.at.least(ether("0.09"));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('can add liquidity for wbtc', async function() {
|
||||||
|
const curveTokenContract = new web3.eth.Contract(
|
||||||
|
erc20ABI,
|
||||||
|
"0x075b1bb99792c9e1041ba13afef80c91a1e70fb3"
|
||||||
|
)
|
||||||
|
|
||||||
|
const tx = await contract.deposit(
|
||||||
|
erc20.wbtc.address,
|
||||||
|
10000000,
|
||||||
|
( 0.09 / 0.1 * 1e18 ).toString(),
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
{
|
||||||
|
gas: 4000000,
|
||||||
|
from: sender
|
||||||
|
}
|
||||||
|
);
|
||||||
|
console.log(tx);
|
||||||
|
|
||||||
|
const balance = await curveTokenContract.methods.balanceOf(sender);
|
||||||
|
|
||||||
|
expect(balance).to.be.at.least(ether("0.09"));
|
||||||
|
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user