From a7ef817d956d0646bce139ffd0c666f9a9599b96 Mon Sep 17 00:00:00 2001 From: "zapaz.eth" Date: Sat, 16 Oct 2021 11:40:18 +0200 Subject: [PATCH] improvments --- .../mainnet/connectors/ubiquity/main.sol | 46 +-- test/ubiquity/ubiquity.test.js | 264 ++++++++---------- 2 files changed, 143 insertions(+), 167 deletions(-) diff --git a/contracts/mainnet/connectors/ubiquity/main.sol b/contracts/mainnet/connectors/ubiquity/main.sol index 3031c3d5..88067259 100644 --- a/contracts/mainnet/connectors/ubiquity/main.sol +++ b/contracts/mainnet/connectors/ubiquity/main.sol @@ -38,17 +38,20 @@ contract ConnectV2Ubiquity is Helpers, Events { payable returns (string memory _eventName, bytes memory _eventParam) { - address UAD = getUAD(); 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( - token == DAI || - token == USDC || - token == USDT || - token == UAD || - token == CRV3 || - token == UAD3CRVf, - "Invalid token: must be DAI, USDC, USDT, uAD, 3CRV or uAD3CRV-f" + // DAI / USDC / USDT / CRV3 / UAD / UAD3CRVF + tok[0] || tok[1] || tok[2] || tok[3] || tok[4] || tok[5], + "Invalid token: must be DAI, USDC, USDT, 3CRV, uAD or uAD3CRV-f" ); 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 - if (token == DAI || token == USDC || token == USDT) { + // DAI / USDC / USDT + if (tok[0] || tok[1] || tok[2]) { uint256[3] memory amounts1; - if (token == DAI) amounts1[0] = _amount; - else if (token == USDC) amounts1[1] = _amount; - else if (token == USDT) amounts1[2] = _amount; + if (tok[0]) amounts1[0] = _amount; + else if (tok[1]) amounts1[1] = _amount; + else if (tok[2]) amounts1[2] = _amount; approve(TokenInterface(token), Pool3, _amount); I3Pool(Pool3).add_liquidity(amounts1, 0); } // STEP 2 : ProvideLiquidityToMetapool : Deposit in uAD3CRV pool to get uAD3CRV-f LPs - if ( - token == DAI || - token == USDC || - token == USDT || - token == UAD || - token == CRV3 - ) { + // DAI / USDC / USDT / CRV3 / UAD + if (tok[0] || tok[1] || tok[2] || tok[3] || tok[4]) { uint256[2] memory amounts2; address token2 = token; uint256 _amount2; - if (token == UAD) { + if (tok[4]) { _amount2 = _amount; amounts2[0] = _amount2; } else { - if (token == CRV3) { + if (tok[3]) { _amount2 = _amount; } else { 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 - if (token == UAD3CRVf) { + // UAD3CRVF + if (tok[5]) { lpAmount = _amount; } @@ -161,7 +161,7 @@ contract ConnectV2Ubiquity is Helpers, Events { require( // DAI / USDC / USDT / CRV3 / UAD / UAD3CRVF 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); diff --git a/test/ubiquity/ubiquity.test.js b/test/ubiquity/ubiquity.test.js index 3df3feb9..723946d2 100644 --- a/test/ubiquity/ubiquity.test.js +++ b/test/ubiquity/ubiquity.test.js @@ -194,48 +194,113 @@ describe("Ubiquity", function () { await USDTContract.transfer(dsa.address, onep.mul(amount)); }; - describe("DSA wallet setup", 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 () { + describe("Deposit", function () { + it("should deposit uAD3CRVf to get Ubiquity Bonding Shares", async function () { + await logAll(); 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); - 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); - 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); - 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); - 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); - 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; before(async () => { @@ -343,133 +408,44 @@ describe("Ubiquity", function () { }); }); - describe("Deposit", function () { - it("should deposit uAD3CRVf to get Ubiquity Bonding Shares", async function () { + describe("DSA wallet setup", 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); - expect((await bondingShare(dsa.address)).lpAmount).to.be.equal(0); - 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); + expect(await uAD3CRVfContract.balanceOf(dsa.address)).to.be.gte(one.mul(100)); }); - - it("should deposit uAD to get Ubiquity Bonding Shares", async function () { + it("Should deposit uAD into DSA wallet", async function () { await dsaDepositUAD(100); - expect((await bondingShare(dsa.address)).lpAmount).to.be.equal(0); - 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); + expect(await uADContract.balanceOf(dsa.address)).to.be.gte(one.mul(100)); }); - - it("should deposit 3CRV to get Ubiquity Bonding Shares", async function () { + it("Should deposit 3CRV into DSA wallet", async function () { await dsaDepositCRV3(100); - expect((await bondingShare(dsa.address)).lpAmount).to.be.equal(0); - 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); + expect(await CRV3Contract.balanceOf(dsa.address)).to.be.gte(one.mul(100)); }); - - it("should deposit DAI to get Ubiquity Bonding Shares", async function () { + it("Should deposit DAI into DSA wallet", async function () { await dsaDepositDAI(100); - expect((await bondingShare(dsa.address)).lpAmount).to.be.equal(0); - 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); + expect(await DAIContract.balanceOf(dsa.address)).to.be.gte(one.mul(100)); }); - - it("should deposit USDC to get Ubiquity Bonding Shares", async function () { + it("Should deposit USDC into DSA wallet", async function () { await dsaDepositUSDC(100); - expect((await bondingShare(dsa.address)).lpAmount).to.be.equal(0); - 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); + expect(await USDCContract.balanceOf(dsa.address)).to.be.gte(onep.mul(100)); }); - - it("should deposit USDT to get Ubiquity Bonding Shares", async function () { + it("Should deposit USDT into DSA wallet", async function () { await dsaDepositUSDT(100); - expect((await bondingShare(dsa.address)).lpAmount).to.be.equal(0); - 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)); + expect(await USDTContract.balanceOf(dsa.address)).to.be.gte(onep.mul(100)); }); }); });