Skip to content

Commit 0b475d5

Browse files
committed
add isValidPool tests
1 parent 4193b04 commit 0b475d5

File tree

4 files changed

+90
-28
lines changed

4 files changed

+90
-28
lines changed

contracts/protocol/integration/amm/ArrakisUniswapV3AmmAdapter.sol

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -231,38 +231,20 @@ contract ArrakisUniswapV3AmmAdapter is IAmmAdapter {
231231

232232
// Make sure the tokens stored in the arrakis pools matches the
233233
// tokens provided in the components
234-
if(
234+
if (
235235
_components.length != 2 ||
236236
!(token0 == _components[0] || token0 == _components[1]) ||
237237
!(token1 == _components[0] || token1 == _components[1])
238238
) {
239239
return false;
240240
}
241241

242-
// Attempt to get the UniswapV3 pool in the provided Arrakis pool
243-
IUniswapV3Pool uniV3PairPool;
244-
try IArrakisVaultV1(_pool).pool() returns (IUniswapV3Pool _uniV3PairPool) {
245-
uniV3PairPool = _uniV3PairPool;
242+
// Make sure the pool address follows IERC20 interface
243+
try IArrakisVaultV1(_pool).totalSupply() returns (uint256 _totalSupply) {
246244
} catch {
247245
return false;
248246
}
249-
250-
// Attempt to get the UniswapV3 pool fee from the UniV3 pool stored in Arrakis pool
251-
uint24 uniFee;
252-
try uniV3PairPool.fee() returns (uint24 _uniFee) {
253-
uniFee = _uniFee;
254-
} catch {
255-
return false;
256-
}
257-
258-
// Make sure that the pool address returned by the factory
259-
// matches uniswapV3 pool address stored in the provided arrakis pool
260-
if(
261-
uniV3Factory.getPool(_components[0], _components[1], uniFee) != address(uniV3PairPool)
262-
) {
263-
return false;
264-
}
265-
247+
266248
return true;
267249
}
268250
}

test/protocol/integration/amm/ArrakisUniswapV3AmmAdapter.spec.ts

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,68 @@ describe("ArrakisUniswapV3AmmAdapter", () => {
120120
});
121121
});
122122

123+
describe("isValidPool", async () => {
124+
let subjectAmmPool: Address;
125+
let subjectComponents: Address[];
126+
127+
beforeEach(async () => {
128+
subjectAmmPool = arrakisV1Setup.wethDaiPool.address;
129+
subjectComponents = [setup.weth.address, setup.dai.address];
130+
});
131+
132+
async function subject(): Promise<any> {
133+
return await arrakisUniswapV3AmmAdapter.isValidPool(subjectAmmPool, subjectComponents);
134+
}
135+
136+
it("should be a valid pool", async () => {
137+
const status = await subject();
138+
expect(status).to.be.true;
139+
});
140+
141+
describe("when the pool address is invalid", async () => {
142+
beforeEach(async () => {
143+
subjectAmmPool = setup.weth.address;
144+
});
145+
146+
it("should be an invalid pool", async () => {
147+
const status = await subject();
148+
expect(status).to.be.false;
149+
});
150+
});
151+
152+
describe("when the components don't match", async () => {
153+
beforeEach(async () => {
154+
subjectComponents = [setup.weth.address, setup.wbtc.address];
155+
});
156+
157+
it("should be an invalid pool", async () => {
158+
const status = await subject();
159+
expect(status).to.be.false;
160+
});
161+
});
162+
163+
describe("when the number of components is incorrect", async () => {
164+
beforeEach(async () => {
165+
subjectComponents = [setup.weth.address];
166+
});
167+
168+
it("should be an invalid pool", async () => {
169+
const status = await subject();
170+
expect(status).to.be.false;
171+
});
172+
});
173+
174+
describe("when the pool address is not an ERC20", async () => {
175+
beforeEach(async () => {
176+
subjectAmmPool = uniswapV3Setup.wethDaiPool.address;
177+
});
178+
179+
it("should be an invalid pool", async () => {
180+
const status = await subject();
181+
expect(status).to.be.false;
182+
});
183+
});
184+
185+
});
186+
123187
});

utils/deploys/deployExternal.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,10 @@ export default class DeployExternalContracts {
759759
return await new GUniRouter__factory(this._deployerSigner).deploy(uniswapV3factory, weth);
760760
}
761761

762+
public async deployArrakisVaultV1(_gelato: Address, _arrakisTreasury: Address): Promise<ArrakisVaultV1> {
763+
return await new ArrakisVaultV1__factory(this._deployerSigner).deploy(_gelato, _arrakisTreasury);
764+
}
765+
762766
public async getArrakisVaultV1Instance(pool: Address): Promise<ArrakisVaultV1> {
763767
return await new ArrakisVaultV1__factory(this._deployerSigner).attach(pool);
764768
}

utils/fixtures/arrakisV1Fixture.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import DeployHelper from "../deploys";
2-
// import { MAX_UINT_256 } from "../constants";
32
import { Signer, providers } from "ethers";
43
import { Address } from "../types";
54
import { Account } from "../test/types";
@@ -10,13 +9,9 @@ import {
109
ArrakisVaultV1
1110
} from "../contracts/arrakis";
1211

13-
// import { UniswapV3Pool } from "../contracts/uniswapV3";
1412
import { UniswapV3Fixture } from "@utils/fixtures";
15-
// import { UniswapV3Pool__factory } from "../../typechain/factories/UniswapV3Pool__factory";
16-
// import { ether } from "../index";
1713
import { StandardTokenMock } from "../../typechain/StandardTokenMock";
1814
import { WETH9 } from "../../typechain/WETH9";
19-
// import { parseEther } from "ethers/lib/utils";
2015

2116
type Token = StandardTokenMock | WETH9;
2217

@@ -62,17 +57,34 @@ export class ArrakisV1Fixture {
6257
_wbtcPrice: number,
6358
_dai: Token
6459
): Promise<void> {
65-
this.factory = await this._deployer.external.deployArrakisFactoryV1(_uniswapV3Setup.factory.address);
60+
await this.deployVaultAndFactoryAndinitialize(_owner, _uniswapV3Setup);
6661
this.router = await this._deployer.external.deployGUniRouter(_uniswapV3Setup.factory.address, _weth.address);
6762

6863
this.wethDaiPool = await this.createNewPair(_owner, _uniswapV3Setup, _weth, _dai, 3000, _wethPrice);
6964
this.wethWbtcPool = await this.createNewPair(_owner, _uniswapV3Setup, _weth, _wbtc, 3000, _wethPrice / _wbtcPrice);
7065
}
7166

67+
/**
68+
* Creates and initializes a new arrakis factory
69+
*
70+
* @param _owner the owner of the deployed Arrakis system
71+
* @param _uniswapV3Setup uniswapV3Fixture
72+
* @returns a new Arrakis Vault holding UniswapV3 position on given tokens
73+
*/
74+
public async deployVaultAndFactoryAndinitialize(
75+
_owner: Account,
76+
_uniswapV3Setup: UniswapV3Fixture
77+
): Promise<void> {
78+
const vaultImplementation = await this._deployer.external.deployArrakisVaultV1(_owner.address, _owner.address);
79+
this.factory = await this._deployer.external.deployArrakisFactoryV1(_uniswapV3Setup.factory.address);
80+
await this.factory.initialize(vaultImplementation.address, _owner.address);
81+
}
82+
7283
/**
7384
* Creates and initializes a new arrakis vault pool
7485
*
7586
* @param _owner the owner of the deployed Arrakis system
87+
* @param _uniswapV3Setup uniswapV3Fixture
7688
* @param _token0 first token
7789
* @param _token1 second token
7890
* @param _fee fee tier of either 500, 3000, or 10000

0 commit comments

Comments
 (0)