Skip to content

Commit 3aa13c7

Browse files
committed
add arrakis abis, fixtures, and constructor tests
1 parent b02754f commit 3aa13c7

File tree

11 files changed

+2301
-5
lines changed

11 files changed

+2301
-5
lines changed

external/abi/arrakis/ArrakisFactoryV1.json

Lines changed: 459 additions & 0 deletions
Large diffs are not rendered by default.

external/abi/arrakis/GUniPool.json

Lines changed: 1159 additions & 0 deletions
Large diffs are not rendered by default.

external/abi/arrakis/GUniRouter.json

Lines changed: 448 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 83 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,105 @@
11
import "module-alias/register";
22
import { Account } from "@utils/test/types";
3-
// import DeployHelper from "@utils/deploys";
3+
import { AmmModule, ArrakisUniswapV3AmmAdapter } from "@utils/contracts";
4+
import DeployHelper from "@utils/deploys";
45
import {
6+
addSnapshotBeforeRestoreAfterEach,
57
getAccounts,
68
getSystemFixture,
9+
getUniswapV3Fixture,
10+
getArrakisV1Fixture,
11+
getWaffleExpect
712
} from "@utils/test/index";
813

9-
import { SystemFixture } from "@utils/fixtures";
14+
import { SystemFixture, UniswapV3Fixture, ArrakisV1Fixture } from "@utils/fixtures";
15+
16+
const expect = getWaffleExpect();
1017

1118
describe("ArrakisUniswapV3AmmAdapter", () => {
1219
let owner: Account;
13-
// let deployer: DeployHelper;
20+
let deployer: DeployHelper;
1421
let setup: SystemFixture;
22+
let uniswapV3Setup: UniswapV3Fixture;
23+
let arrakisV1Setup: ArrakisV1Fixture;
24+
let ammModule: AmmModule;
25+
let arrakisUniswapV3AmmAdapter: ArrakisUniswapV3AmmAdapter;
26+
let arrakisUniswapV3AmmAdapterName: string;
1527

1628
before(async () => {
1729
[
1830
owner,
1931
] = await getAccounts();
2032

21-
// deployer = new DeployHelper(owner.wallet);
33+
deployer = new DeployHelper(owner.wallet);
2234
setup = getSystemFixture(owner.address);
2335
await setup.initialize();
36+
37+
uniswapV3Setup = getUniswapV3Fixture(owner.address);
38+
await uniswapV3Setup.initialize(
39+
owner,
40+
setup.weth,
41+
2500,
42+
setup.wbtc,
43+
35000,
44+
setup.dai
45+
);
46+
// await setup.weth.connect(owner.wallet)
47+
// .approve(uniswapV3Setup.router.address, MAX_UINT_256);
48+
// await setup.dai.connect(owner.wallet)
49+
// .approve(uniswapV3Setup.router.address, MAX_UINT_256);
50+
// await uniswapV3Setup.router.connect(owner.wallet).addLiquidity(
51+
// setup.weth.address,
52+
// setup.dai.address,
53+
// ether(200),
54+
// ether(600000),
55+
// ether(0),
56+
// ether(0),
57+
// owner.address,
58+
// MAX_UINT_256
59+
// );
60+
61+
arrakisV1Setup = getArrakisV1Fixture(owner.address);
62+
await arrakisV1Setup.initialize(owner, uniswapV3Setup, setup.weth, 2500, setup.wbtc, 35000, setup.dai);
63+
64+
ammModule = await deployer.modules.deployAmmModule(setup.controller.address);
65+
await setup.controller.addModule(ammModule.address);
66+
67+
arrakisUniswapV3AmmAdapter = await deployer.adapters.deployArrakisUniswapV3AmmAdapter(
68+
arrakisV1Setup.router.address,
69+
uniswapV3Setup.factory.address
70+
);
71+
arrakisUniswapV3AmmAdapterName = "ARRAKISUNISWAPV3AMM";
72+
73+
await setup.integrationRegistry.addIntegration(
74+
ammModule.address,
75+
arrakisUniswapV3AmmAdapterName,
76+
arrakisUniswapV3AmmAdapter.address
77+
);
78+
});
79+
80+
addSnapshotBeforeRestoreAfterEach();
81+
82+
describe("constructor", async () => {
83+
async function subject(): Promise<ArrakisUniswapV3AmmAdapter> {
84+
return await deployer.adapters.deployArrakisUniswapV3AmmAdapter(
85+
arrakisV1Setup.router.address,
86+
uniswapV3Setup.factory.address
87+
);
88+
}
89+
90+
it("should have the correct router address", async () => {
91+
const deployedArrakisUniswapV3AmmAdapter = await subject();
92+
93+
const actualRouterAddress = await deployedArrakisUniswapV3AmmAdapter.router();
94+
expect(actualRouterAddress).to.eq(arrakisV1Setup.router.address);
95+
});
96+
97+
it("should have the correct uniswapV3 factory address", async () => {
98+
const deployedArrakisUniswapV3AmmAdapter = await subject();
99+
100+
const actualUniV3FactoryAddress = await deployedArrakisUniswapV3AmmAdapter.uniV3Factory();
101+
expect(actualUniV3FactoryAddress).to.eq(uniswapV3Setup.factory.address);
102+
});
24103
});
25104

26105
});

utils/contracts/arrakis.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// External Arrakis/Gelato contracts
2+
export { ArrakisFactoryV1 } from "../../typechain/ArrakisFactoryV1";
3+
export { GUniPool } from "../../typechain/GUniPool";
4+
export { GUniRouter } from "../../typechain/GUniRouter";

utils/contracts/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export { AddressArrayUtilsMock } from "../../typechain/AddressArrayUtilsMock";
99
export { AirdropModule } from "../../typechain/AirdropModule";
1010
export { AmmAdapterMock } from "../../typechain/AmmAdapterMock";
1111
export { AmmModule } from "../../typechain/AmmModule";
12+
export { ArrakisUniswapV3AmmAdapter } from "../../typechain/ArrakisUniswapV3AmmAdapter";
1213
export { AssetLimitHook } from "../../typechain/AssetLimitHook";
1314
export { BalancerV1IndexExchangeAdapter } from "../../typechain/BalancerV1IndexExchangeAdapter";
1415
export { BasicIssuanceModule } from "../../typechain/BasicIssuanceModule";

utils/deploys/deployAdapters.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { BigNumber, Signer } from "ethers";
33
import {
44
AaveGovernanceV2Adapter,
55
AaveV2WrapV2Adapter,
6+
ArrakisUniswapV3AmmAdapter,
67
BalancerV1IndexExchangeAdapter,
78
CompoundLikeGovernanceAdapter,
89
CurveExchangeAdapter,
@@ -33,6 +34,7 @@ import { Address, Bytes } from "./../types";
3334

3435
import { AaveGovernanceV2Adapter__factory } from "../../typechain/factories/AaveGovernanceV2Adapter__factory";
3536
import { AaveV2WrapV2Adapter__factory } from "../../typechain/factories/AaveV2WrapV2Adapter__factory";
37+
import { ArrakisUniswapV3AmmAdapter__factory } from "../../typechain/factories/ArrakisUniswapV3AmmAdapter__factory";
3638
import { BalancerV1IndexExchangeAdapter__factory } from "../../typechain/factories/BalancerV1IndexExchangeAdapter__factory";
3739
import { CompoundLikeGovernanceAdapter__factory } from "../../typechain/factories/CompoundLikeGovernanceAdapter__factory";
3840
import { CurveExchangeAdapter__factory } from "../../typechain/factories/CurveExchangeAdapter__factory";
@@ -88,6 +90,13 @@ export default class DeployAdapters {
8890
return await new UniswapV2AmmAdapter__factory(this._deployerSigner).deploy(uniswapV2Router);
8991
}
9092

93+
public async deployArrakisUniswapV3AmmAdapter(
94+
arrakisRouter: Address,
95+
uniswapV3Factory: Address
96+
): Promise<ArrakisUniswapV3AmmAdapter> {
97+
return await new ArrakisUniswapV3AmmAdapter__factory(this._deployerSigner).deploy(arrakisRouter, uniswapV3Factory);
98+
}
99+
91100
public async deployUniswapV2ExchangeAdapter(
92101
uniswapV2Router: Address,
93102
): Promise<UniswapV2ExchangeAdapter> {

utils/deploys/deployExternal.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,15 @@ import { PerpV2InsuranceFund__factory } from "../../typechain/factories/PerpV2In
203203
import { PerpV2AccountBalance__factory } from "../../typechain/factories/PerpV2AccountBalance__factory";
204204
import { PerpV2Exchange__factory } from "../../typechain/factories/PerpV2Exchange__factory";
205205

206+
import {
207+
GUniRouter,
208+
ArrakisFactoryV1,
209+
GUniPool
210+
} from "../contracts/arrakis";
211+
import { ArrakisFactoryV1__factory } from "../../typechain/factories/ArrakisFactoryV1__factory";
212+
import { GUniPool__factory } from "../../typechain/factories/GUniPool__factory";
213+
import { GUniRouter__factory } from "../../typechain/factories/GUniRouter__factory";
214+
206215

207216
export default class DeployExternalContracts {
208217
private _deployerSigner: Signer;
@@ -740,4 +749,17 @@ export default class DeployExternalContracts {
740749
public async getVToken(token: Address): Promise<PerpV2BaseToken> {
741750
return await new PerpV2BaseToken__factory(this._deployerSigner).attach(token);
742751
}
752+
753+
// Arrakis/Gelato
754+
public async deployArrakisFactoryV1(uniswapV3factory: Address): Promise<ArrakisFactoryV1> {
755+
return await new ArrakisFactoryV1__factory(this._deployerSigner).deploy(uniswapV3factory);
756+
}
757+
758+
public async deployGUniRouter(uniswapV3factory: Address, weth: Address): Promise<GUniRouter> {
759+
return await new GUniRouter__factory(this._deployerSigner).deploy(uniswapV3factory, weth);
760+
}
761+
762+
public async getGUniPoolInstance(pool: Address): Promise<GUniPool> {
763+
return await new GUniPool__factory(this._deployerSigner).attach(pool);
764+
}
743765
}

utils/fixtures/arrakisV1Fixture.ts

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
import DeployHelper from "../deploys";
2+
// import { MAX_UINT_256 } from "../constants";
3+
import { Signer, providers } from "ethers";
4+
import { Address } from "../types";
5+
import { Account } from "../test/types";
6+
7+
import {
8+
ArrakisFactoryV1,
9+
GUniRouter,
10+
GUniPool
11+
} from "../contracts/arrakis";
12+
13+
// import { UniswapV3Pool } from "../contracts/uniswapV3";
14+
import { UniswapV3Fixture } from "@utils/fixtures";
15+
// import { UniswapV3Pool__factory } from "../../typechain/factories/UniswapV3Pool__factory";
16+
// import { ether } from "../index";
17+
import { StandardTokenMock } from "../../typechain/StandardTokenMock";
18+
import { WETH9 } from "../../typechain/WETH9";
19+
// import { parseEther } from "ethers/lib/utils";
20+
21+
type Token = StandardTokenMock | WETH9;
22+
23+
export class ArrakisV1Fixture {
24+
25+
private _deployer: DeployHelper;
26+
private _ownerSigner: Signer;
27+
28+
public factory: ArrakisFactoryV1;
29+
public router: GUniRouter;
30+
31+
public wethDaiPool: GUniPool;
32+
public wethWbtcPool: GUniPool;
33+
34+
/**
35+
* Instantiates a new ArrakisFixture
36+
*
37+
* @param provider the ethers web3 provider to use
38+
* @param ownerAddress the address of the owner
39+
*/
40+
constructor(provider: providers.Web3Provider | providers.JsonRpcProvider, ownerAddress: Address) {
41+
this._ownerSigner = provider.getSigner(ownerAddress);
42+
this._deployer = new DeployHelper(this._ownerSigner);
43+
}
44+
45+
/**
46+
* Deploys contracts and creates weth-dai and weth-wbtc arrakis pools
47+
*
48+
* @param _owner the owner of the deployed Arrakis system
49+
* @param _uniswapV3Factory uniswapV3 factory address
50+
* @param _weth weth address
51+
* @param _wethPrice weth price
52+
* @param _wbtc wbtc address
53+
* @param _wbtcPrice wbtc price
54+
* @param _dai dai address
55+
*/
56+
public async initialize(
57+
_owner: Account,
58+
_uniswapV3Setup: UniswapV3Fixture,
59+
_weth: Token,
60+
_wethPrice: number,
61+
_wbtc: Token,
62+
_wbtcPrice: number,
63+
_dai: Token
64+
): Promise<void> {
65+
this.factory = await this._deployer.external.deployArrakisFactoryV1(_uniswapV3Setup.factory.address);
66+
this.router = await this._deployer.external.deployGUniRouter(_uniswapV3Setup.factory.address, _weth.address);
67+
68+
this.wethDaiPool = await this.createNewPair(_owner, _uniswapV3Setup, _weth, _dai, 3000, _wethPrice);
69+
this.wethWbtcPool = await this.createNewPair(_owner, _uniswapV3Setup, _weth, _wbtc, 3000, _wethPrice / _wbtcPrice);
70+
}
71+
72+
/**
73+
* Creates and initializes a new arrakis vault pool
74+
*
75+
* @param _owner the owner of the deployed Arrakis system
76+
* @param _token0 first token
77+
* @param _token1 second token
78+
* @param _fee fee tier of either 500, 3000, or 10000
79+
* @param _ratio the initial price ratio of the pool equal to priceToken0 / priceToken1
80+
* @returns a new Arrakis GUniPool holding UniswapV3 position on given tokens
81+
*/
82+
public async createNewPair(
83+
_owner: Account,
84+
_uniswapV3Setup: UniswapV3Fixture,
85+
_token0: Token,
86+
_token1: Token,
87+
_fee: number,
88+
_ratio: number,
89+
): Promise<GUniPool> {
90+
await _uniswapV3Setup.createNewPair(_token0, _token1, _fee, _ratio);
91+
92+
const tickSpacing = _fee / 50; // ticks can only be initialized if they are a multiple of fee / 50
93+
const maxTick = 887272; // the maximum tick index that Uniswap V3 allows
94+
const maxValidTick = Math.floor(maxTick / tickSpacing) * tickSpacing; // valid ticks must be a multiple of tickSpacing
95+
const minValidTick = Math.ceil(-maxTick / tickSpacing) * tickSpacing;
96+
97+
const txReceipt = await (
98+
await this.factory.deployVault(
99+
_token0.address,
100+
_token1.address,
101+
_fee,
102+
_owner.address,
103+
0,
104+
minValidTick,
105+
maxValidTick
106+
)
107+
).wait();
108+
109+
const poolAddress = txReceipt.events![2].args!.pool;
110+
return this._deployer.external.getGUniPoolInstance(poolAddress);
111+
}
112+
}

utils/fixtures/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ export { UniswapFixture } from "./uniswapFixture";
88
export { UniswapV3Fixture } from "./uniswapV3Fixture";
99
export { YearnFixture } from "./yearnFixture";
1010
export { PerpV2Fixture } from "./perpV2Fixture";
11+
export { ArrakisV1Fixture } from "./arrakisV1Fixture";

0 commit comments

Comments
 (0)