mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
improvments
This commit is contained in:
parent
dffd14c2fe
commit
a7ef817d95
|
@ -38,17 +38,20 @@ contract ConnectV2Ubiquity is Helpers, Events {
|
||||||
payable
|
payable
|
||||||
returns (string memory _eventName, bytes memory _eventParam)
|
returns (string memory _eventName, bytes memory _eventParam)
|
||||||
{
|
{
|
||||||
address UAD = getUAD();
|
|
||||||
address UAD3CRVf = getUADCRV3();
|
address UAD3CRVf = getUADCRV3();
|
||||||
|
bool[6] memory tok = [
|
||||||
|
token == DAI, // 0
|
||||||
|
token == USDC, // 1
|
||||||
|
token == USDT, // 2
|
||||||
|
token == CRV3, // 3
|
||||||
|
token == getUAD(), // 4
|
||||||
|
token == UAD3CRVf // 5
|
||||||
|
];
|
||||||
|
|
||||||
require(
|
require(
|
||||||
token == DAI ||
|
// DAI / USDC / USDT / CRV3 / UAD / UAD3CRVF
|
||||||
token == USDC ||
|
tok[0] || tok[1] || tok[2] || tok[3] || tok[4] || tok[5],
|
||||||
token == USDT ||
|
"Invalid token: must be DAI, USDC, USDT, 3CRV, uAD or uAD3CRV-f"
|
||||||
token == UAD ||
|
|
||||||
token == CRV3 ||
|
|
||||||
token == UAD3CRVf,
|
|
||||||
"Invalid token: must be DAI, USDC, USDT, uAD, 3CRV or uAD3CRV-f"
|
|
||||||
);
|
);
|
||||||
|
|
||||||
uint256 _amount = getUint(getId, amount);
|
uint256 _amount = getUint(getId, amount);
|
||||||
|
@ -60,34 +63,30 @@ contract ConnectV2Ubiquity is Helpers, Events {
|
||||||
}
|
}
|
||||||
|
|
||||||
// STEP 1 : SwapTo3CRV : Deposit DAI, USDC or USDT into 3Pool to get 3Crv LPs
|
// STEP 1 : SwapTo3CRV : Deposit DAI, USDC or USDT into 3Pool to get 3Crv LPs
|
||||||
if (token == DAI || token == USDC || token == USDT) {
|
// DAI / USDC / USDT
|
||||||
|
if (tok[0] || tok[1] || tok[2]) {
|
||||||
uint256[3] memory amounts1;
|
uint256[3] memory amounts1;
|
||||||
|
|
||||||
if (token == DAI) amounts1[0] = _amount;
|
if (tok[0]) amounts1[0] = _amount;
|
||||||
else if (token == USDC) amounts1[1] = _amount;
|
else if (tok[1]) amounts1[1] = _amount;
|
||||||
else if (token == USDT) amounts1[2] = _amount;
|
else if (tok[2]) amounts1[2] = _amount;
|
||||||
|
|
||||||
approve(TokenInterface(token), Pool3, _amount);
|
approve(TokenInterface(token), Pool3, _amount);
|
||||||
I3Pool(Pool3).add_liquidity(amounts1, 0);
|
I3Pool(Pool3).add_liquidity(amounts1, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// STEP 2 : ProvideLiquidityToMetapool : Deposit in uAD3CRV pool to get uAD3CRV-f LPs
|
// STEP 2 : ProvideLiquidityToMetapool : Deposit in uAD3CRV pool to get uAD3CRV-f LPs
|
||||||
if (
|
// DAI / USDC / USDT / CRV3 / UAD
|
||||||
token == DAI ||
|
if (tok[0] || tok[1] || tok[2] || tok[3] || tok[4]) {
|
||||||
token == USDC ||
|
|
||||||
token == USDT ||
|
|
||||||
token == UAD ||
|
|
||||||
token == CRV3
|
|
||||||
) {
|
|
||||||
uint256[2] memory amounts2;
|
uint256[2] memory amounts2;
|
||||||
address token2 = token;
|
address token2 = token;
|
||||||
uint256 _amount2;
|
uint256 _amount2;
|
||||||
|
|
||||||
if (token == UAD) {
|
if (tok[4]) {
|
||||||
_amount2 = _amount;
|
_amount2 = _amount;
|
||||||
amounts2[0] = _amount2;
|
amounts2[0] = _amount2;
|
||||||
} else {
|
} else {
|
||||||
if (token == CRV3) {
|
if (tok[3]) {
|
||||||
_amount2 = _amount;
|
_amount2 = _amount;
|
||||||
} else {
|
} else {
|
||||||
token2 = CRV3;
|
token2 = CRV3;
|
||||||
|
@ -101,7 +100,8 @@ contract ConnectV2Ubiquity is Helpers, Events {
|
||||||
}
|
}
|
||||||
|
|
||||||
// STEP 3 : Farm/ApeIn : Deposit uAD3CRV-f LPs into UbiquityBondingV2 and get Ubiquity Bonding Shares
|
// STEP 3 : Farm/ApeIn : Deposit uAD3CRV-f LPs into UbiquityBondingV2 and get Ubiquity Bonding Shares
|
||||||
if (token == UAD3CRVf) {
|
// UAD3CRVF
|
||||||
|
if (tok[5]) {
|
||||||
lpAmount = _amount;
|
lpAmount = _amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,7 +161,7 @@ contract ConnectV2Ubiquity is Helpers, Events {
|
||||||
require(
|
require(
|
||||||
// DAI / USDC / USDT / CRV3 / UAD / UAD3CRVF
|
// DAI / USDC / USDT / CRV3 / UAD / UAD3CRVF
|
||||||
tok[0] || tok[1] || tok[2] || tok[3] || tok[4] || tok[5],
|
tok[0] || tok[1] || tok[2] || tok[3] || tok[4] || tok[5],
|
||||||
"Invalid token: must be DAI, USDC, USDT, uAD, 3CRV or uAD3CRV-f"
|
"Invalid token: must be DAI, USDC, USDT, 3CRV, uAD or uAD3CRV-f"
|
||||||
);
|
);
|
||||||
|
|
||||||
uint256 _bondingShareId = getUint(getId, bondingShareId);
|
uint256 _bondingShareId = getUint(getId, bondingShareId);
|
||||||
|
|
|
@ -194,48 +194,113 @@ describe("Ubiquity", function () {
|
||||||
await USDTContract.transfer(dsa.address, onep.mul(amount));
|
await USDTContract.transfer(dsa.address, onep.mul(amount));
|
||||||
};
|
};
|
||||||
|
|
||||||
describe("DSA wallet setup", function () {
|
describe("Deposit", function () {
|
||||||
it("Should have contracts deployed.", async function () {
|
it("should deposit uAD3CRVf to get Ubiquity Bonding Shares", async function () {
|
||||||
expect(POOL3Contract.address).to.be.properAddress;
|
await logAll();
|
||||||
expect(CRV3Contract.address).to.be.properAddress;
|
|
||||||
expect(uADContract.address).to.be.properAddress;
|
|
||||||
expect(uAD3CRVfContract.address).to.be.properAddress;
|
|
||||||
expect(DAIContract.address).to.be.properAddress;
|
|
||||||
expect(USDCContract.address).to.be.properAddress;
|
|
||||||
expect(USDTContract.address).to.be.properAddress;
|
|
||||||
expect(BONDContract.address).to.be.properAddress;
|
|
||||||
expect(instaIndex.address).to.be.properAddress;
|
|
||||||
expect(instaConnectorsV2.address).to.be.properAddress;
|
|
||||||
expect(connector.address).to.be.properAddress;
|
|
||||||
expect(dsa.address).to.be.properAddress;
|
|
||||||
});
|
|
||||||
it("Should deposit uAD3CRVf into DSA wallet", async function () {
|
|
||||||
await dsaDepositUAD3CRVf(100);
|
await dsaDepositUAD3CRVf(100);
|
||||||
expect(await uAD3CRVfContract.balanceOf(dsa.address)).to.be.gte(one.mul(100));
|
expect((await bondingShare(dsa.address)).lpAmount).to.be.equal(0);
|
||||||
|
await expect(
|
||||||
|
dsa.cast(
|
||||||
|
...encodeSpells([
|
||||||
|
{
|
||||||
|
connector: ubiquityTest,
|
||||||
|
method: "deposit",
|
||||||
|
args: [UAD3CRVF, one.mul(100), 4, 0, 0]
|
||||||
|
}
|
||||||
|
]),
|
||||||
|
uadWhaleAddress
|
||||||
|
)
|
||||||
|
).to.be.not.reverted;
|
||||||
|
expect((await bondingShare(dsa.address)).lpAmount).to.be.gt(0);
|
||||||
});
|
});
|
||||||
it("Should deposit uAD into DSA wallet", async function () {
|
|
||||||
|
it("should deposit uAD to get Ubiquity Bonding Shares", async function () {
|
||||||
await dsaDepositUAD(100);
|
await dsaDepositUAD(100);
|
||||||
expect(await uADContract.balanceOf(dsa.address)).to.be.gte(one.mul(100));
|
await expect(
|
||||||
|
dsa.cast(
|
||||||
|
...encodeSpells([
|
||||||
|
{
|
||||||
|
connector: ubiquityTest,
|
||||||
|
method: "deposit",
|
||||||
|
args: [UAD, one.mul(100), 4, 0, 0]
|
||||||
|
}
|
||||||
|
]),
|
||||||
|
uadWhaleAddress
|
||||||
|
)
|
||||||
|
).to.be.not.reverted;
|
||||||
|
expect((await bondingShare(dsa.address)).lpAmount).to.be.gt(0);
|
||||||
});
|
});
|
||||||
it("Should deposit 3CRV into DSA wallet", async function () {
|
|
||||||
|
it("should deposit 3CRV to get Ubiquity Bonding Shares", async function () {
|
||||||
await dsaDepositCRV3(100);
|
await dsaDepositCRV3(100);
|
||||||
expect(await CRV3Contract.balanceOf(dsa.address)).to.be.gte(one.mul(100));
|
await expect(
|
||||||
|
dsa.cast(
|
||||||
|
...encodeSpells([
|
||||||
|
{
|
||||||
|
connector: ubiquityTest,
|
||||||
|
method: "deposit",
|
||||||
|
args: [CRV3, one.mul(100), 4, 0, 0]
|
||||||
|
}
|
||||||
|
]),
|
||||||
|
uadWhaleAddress
|
||||||
|
)
|
||||||
|
).to.be.not.reverted;
|
||||||
|
expect((await bondingShare(dsa.address)).lpAmount).to.be.gt(0);
|
||||||
});
|
});
|
||||||
it("Should deposit DAI into DSA wallet", async function () {
|
|
||||||
|
it("should deposit DAI to get Ubiquity Bonding Shares", async function () {
|
||||||
await dsaDepositDAI(100);
|
await dsaDepositDAI(100);
|
||||||
expect(await DAIContract.balanceOf(dsa.address)).to.be.gte(one.mul(100));
|
await expect(
|
||||||
|
dsa.cast(
|
||||||
|
...encodeSpells([
|
||||||
|
{
|
||||||
|
connector: ubiquityTest,
|
||||||
|
method: "deposit",
|
||||||
|
args: [DAI, one.mul(100), 4, 0, 0]
|
||||||
|
}
|
||||||
|
]),
|
||||||
|
uadWhaleAddress
|
||||||
|
)
|
||||||
|
).to.be.not.reverted;
|
||||||
|
expect((await bondingShare(dsa.address)).lpAmount).to.be.gt(0);
|
||||||
});
|
});
|
||||||
it("Should deposit USDC into DSA wallet", async function () {
|
|
||||||
|
it("should deposit USDC to get Ubiquity Bonding Shares", async function () {
|
||||||
await dsaDepositUSDC(100);
|
await dsaDepositUSDC(100);
|
||||||
expect(await USDCContract.balanceOf(dsa.address)).to.be.gte(onep.mul(100));
|
await expect(
|
||||||
|
dsa.cast(
|
||||||
|
...encodeSpells([
|
||||||
|
{
|
||||||
|
connector: ubiquityTest,
|
||||||
|
method: "deposit",
|
||||||
|
args: [USDC, onep.mul(100), 4, 0, 0]
|
||||||
|
}
|
||||||
|
]),
|
||||||
|
uadWhaleAddress
|
||||||
|
)
|
||||||
|
).to.be.not.reverted;
|
||||||
|
expect((await bondingShare(dsa.address)).lpAmount).to.be.gt(0);
|
||||||
});
|
});
|
||||||
it("Should deposit USDT into DSA wallet", async function () {
|
|
||||||
|
it("should deposit USDT to get Ubiquity Bonding Shares", async function () {
|
||||||
await dsaDepositUSDT(100);
|
await dsaDepositUSDT(100);
|
||||||
expect(await USDTContract.balanceOf(dsa.address)).to.be.gte(onep.mul(100));
|
await expect(
|
||||||
|
dsa.cast(
|
||||||
|
...encodeSpells([
|
||||||
|
{
|
||||||
|
connector: ubiquityTest,
|
||||||
|
method: "deposit",
|
||||||
|
args: [USDT, onep.mul(100), 4, 0, 0]
|
||||||
|
}
|
||||||
|
]),
|
||||||
|
uadWhaleAddress
|
||||||
|
)
|
||||||
|
).to.be.not.reverted;
|
||||||
|
expect((await bondingShare(dsa.address)).lpAmount).to.be.gt(0);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe.only("Withdraw", function () {
|
describe("Withdraw", function () {
|
||||||
let bondId = -1;
|
let bondId = -1;
|
||||||
|
|
||||||
before(async () => {
|
before(async () => {
|
||||||
|
@ -343,133 +408,44 @@ describe("Ubiquity", function () {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("Deposit", function () {
|
describe("DSA wallet setup", function () {
|
||||||
it("should deposit uAD3CRVf to get Ubiquity Bonding Shares", async function () {
|
it("Should have contracts deployed.", async function () {
|
||||||
|
expect(POOL3Contract.address).to.be.properAddress;
|
||||||
|
expect(CRV3Contract.address).to.be.properAddress;
|
||||||
|
expect(uADContract.address).to.be.properAddress;
|
||||||
|
expect(uAD3CRVfContract.address).to.be.properAddress;
|
||||||
|
expect(DAIContract.address).to.be.properAddress;
|
||||||
|
expect(USDCContract.address).to.be.properAddress;
|
||||||
|
expect(USDTContract.address).to.be.properAddress;
|
||||||
|
expect(BONDContract.address).to.be.properAddress;
|
||||||
|
expect(instaIndex.address).to.be.properAddress;
|
||||||
|
expect(instaConnectorsV2.address).to.be.properAddress;
|
||||||
|
expect(connector.address).to.be.properAddress;
|
||||||
|
expect(dsa.address).to.be.properAddress;
|
||||||
|
});
|
||||||
|
it("Should deposit uAD3CRVf into DSA wallet", async function () {
|
||||||
await dsaDepositUAD3CRVf(100);
|
await dsaDepositUAD3CRVf(100);
|
||||||
expect((await bondingShare(dsa.address)).lpAmount).to.be.equal(0);
|
expect(await uAD3CRVfContract.balanceOf(dsa.address)).to.be.gte(one.mul(100));
|
||||||
await expect(
|
|
||||||
dsa.cast(
|
|
||||||
...encodeSpells([
|
|
||||||
{
|
|
||||||
connector: ubiquityTest,
|
|
||||||
method: "deposit",
|
|
||||||
args: [UAD3CRVF, one, 4, 0, 0]
|
|
||||||
}
|
|
||||||
]),
|
|
||||||
uadWhaleAddress
|
|
||||||
)
|
|
||||||
).to.be.not.reverted;
|
|
||||||
expect((await bondingShare(dsa.address)).lpAmount).to.be.gt(0);
|
|
||||||
});
|
});
|
||||||
|
it("Should deposit uAD into DSA wallet", async function () {
|
||||||
it("should deposit uAD to get Ubiquity Bonding Shares", async function () {
|
|
||||||
await dsaDepositUAD(100);
|
await dsaDepositUAD(100);
|
||||||
expect((await bondingShare(dsa.address)).lpAmount).to.be.equal(0);
|
expect(await uADContract.balanceOf(dsa.address)).to.be.gte(one.mul(100));
|
||||||
await expect(
|
|
||||||
dsa.cast(
|
|
||||||
...encodeSpells([
|
|
||||||
{
|
|
||||||
connector: ubiquityTest,
|
|
||||||
method: "deposit",
|
|
||||||
args: [UAD, one, 4, 0, 0]
|
|
||||||
}
|
|
||||||
]),
|
|
||||||
uadWhaleAddress
|
|
||||||
)
|
|
||||||
).to.be.not.reverted;
|
|
||||||
expect((await bondingShare(dsa.address)).lpAmount).to.be.gt(0);
|
|
||||||
});
|
});
|
||||||
|
it("Should deposit 3CRV into DSA wallet", async function () {
|
||||||
it("should deposit 3CRV to get Ubiquity Bonding Shares", async function () {
|
|
||||||
await dsaDepositCRV3(100);
|
await dsaDepositCRV3(100);
|
||||||
expect((await bondingShare(dsa.address)).lpAmount).to.be.equal(0);
|
expect(await CRV3Contract.balanceOf(dsa.address)).to.be.gte(one.mul(100));
|
||||||
await expect(
|
|
||||||
dsa.cast(
|
|
||||||
...encodeSpells([
|
|
||||||
{
|
|
||||||
connector: ubiquityTest,
|
|
||||||
method: "deposit",
|
|
||||||
args: [CRV3, one, 4, 0, 0]
|
|
||||||
}
|
|
||||||
]),
|
|
||||||
uadWhaleAddress
|
|
||||||
)
|
|
||||||
).to.be.not.reverted;
|
|
||||||
expect((await bondingShare(dsa.address)).lpAmount).to.be.gt(0);
|
|
||||||
});
|
});
|
||||||
|
it("Should deposit DAI into DSA wallet", async function () {
|
||||||
it("should deposit DAI to get Ubiquity Bonding Shares", async function () {
|
|
||||||
await dsaDepositDAI(100);
|
await dsaDepositDAI(100);
|
||||||
expect((await bondingShare(dsa.address)).lpAmount).to.be.equal(0);
|
expect(await DAIContract.balanceOf(dsa.address)).to.be.gte(one.mul(100));
|
||||||
await expect(
|
|
||||||
dsa.cast(
|
|
||||||
...encodeSpells([
|
|
||||||
{
|
|
||||||
connector: ubiquityTest,
|
|
||||||
method: "deposit",
|
|
||||||
args: [DAI, one.mul(100), 4, 0, 0]
|
|
||||||
}
|
|
||||||
]),
|
|
||||||
uadWhaleAddress
|
|
||||||
)
|
|
||||||
).to.be.not.reverted;
|
|
||||||
expect((await bondingShare(dsa.address)).lpAmount).to.be.gt(0);
|
|
||||||
});
|
});
|
||||||
|
it("Should deposit USDC into DSA wallet", async function () {
|
||||||
it("should deposit USDC to get Ubiquity Bonding Shares", async function () {
|
|
||||||
await dsaDepositUSDC(100);
|
await dsaDepositUSDC(100);
|
||||||
expect((await bondingShare(dsa.address)).lpAmount).to.be.equal(0);
|
expect(await USDCContract.balanceOf(dsa.address)).to.be.gte(onep.mul(100));
|
||||||
await expect(
|
|
||||||
dsa.cast(
|
|
||||||
...encodeSpells([
|
|
||||||
{
|
|
||||||
connector: ubiquityTest,
|
|
||||||
method: "deposit",
|
|
||||||
args: [USDC, onep.mul(100), 4, 0, 0]
|
|
||||||
}
|
|
||||||
]),
|
|
||||||
uadWhaleAddress
|
|
||||||
)
|
|
||||||
).to.be.not.reverted;
|
|
||||||
expect((await bondingShare(dsa.address)).lpAmount).to.be.gt(0);
|
|
||||||
});
|
});
|
||||||
|
it("Should deposit USDT into DSA wallet", async function () {
|
||||||
it("should deposit USDT to get Ubiquity Bonding Shares", async function () {
|
|
||||||
await dsaDepositUSDT(100);
|
await dsaDepositUSDT(100);
|
||||||
expect((await bondingShare(dsa.address)).lpAmount).to.be.equal(0);
|
expect(await USDTContract.balanceOf(dsa.address)).to.be.gte(onep.mul(100));
|
||||||
await expect(
|
|
||||||
dsa.cast(
|
|
||||||
...encodeSpells([
|
|
||||||
{
|
|
||||||
connector: ubiquityTest,
|
|
||||||
method: "deposit",
|
|
||||||
args: [USDT, onep.mul(100), 4, 0, 0]
|
|
||||||
}
|
|
||||||
]),
|
|
||||||
uadWhaleAddress
|
|
||||||
)
|
|
||||||
).to.be.not.reverted;
|
|
||||||
expect((await bondingShare(dsa.address)).lpAmount).to.be.gt(0);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("3Pool test", function () {
|
|
||||||
it("Should add DAI liquidity to 3Pool", async function () {
|
|
||||||
const n = 100;
|
|
||||||
await dsaDepositDAI(n);
|
|
||||||
const amount = one.mul(n);
|
|
||||||
const [dsaSigner] = await impersonate([dsa.address]);
|
|
||||||
|
|
||||||
expect(await DAIContract.balanceOf(dsa.address)).to.be.equal(amount);
|
|
||||||
expect(await CRV3Contract.balanceOf(dsa.address)).to.be.equal(0);
|
|
||||||
|
|
||||||
await (await DAIContract.connect(dsaSigner).approve(POOL3, amount)).wait();
|
|
||||||
await (await POOL3Contract.connect(dsaSigner).add_liquidity([amount, 0, 0], amount.mul(98).div(100))).wait();
|
|
||||||
|
|
||||||
expect(await DAIContract.balanceOf(dsa.address)).to.be.equal(0);
|
|
||||||
expect(await CRV3Contract.balanceOf(dsa.address))
|
|
||||||
.to.be.gte(amount.mul(98).div(100))
|
|
||||||
.to.be.lte(amount.mul(102).div(100));
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user