Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add camelot tests #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions test/addresses.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,13 @@
"tokens": {
"usdt": "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9",
"usdc": "0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8",
"arb": "0x912CE59144191C1204E64559FE8253a0e49E6548"
"arb": "0x912CE59144191C1204E64559FE8253a0e49E6548",
"weth": "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1"
},
"protocols": {
"camelot": {
"factory": "0xd490F2F6990C0291597fd1247651b4E0dCF684Dd"
"factory": "0x1a3c9B1d2F0529D97f2afC5136Cc23e58f1FD35B",
"quoterV2": "0x0Fc73040b26E9bC8514fA028D998E73A254Fa76E"
},
"kyber": {
"quoterV2": "0x4d47fd5a29904Dae0Ef51b1c450C9750F15D7856",
Expand Down
125 changes: 125 additions & 0 deletions test/spec/camelot.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
import { BigNumber } from "ethers";
import { ethers } from "hardhat";
import { expect } from "chai";

import {
encodePathNoFees,
ThenArgRecursive,
deployContract,
forkNetwork,
} from "../helpers";
import addresses from "../addresses.json";

const { tokens } = addresses.arbitrum;
const { camelot } = addresses.arbitrum.protocols;

async function arbitrumFixture(blockNumber: number) {
await forkNetwork("arbitrum", blockNumber);
return fixture();
}

async function fixture() {
const StaticQuoter = await deployAlgebraStaticQuoter();
const OriginalQuoter = await getAlgebraQuoterV2();
return { StaticQuoter, OriginalQuoter };
}

async function deployAlgebraStaticQuoter() {
const [deployer] = await ethers.getSigners();
return deployContract(deployer, "AlgebraStaticQuoter", [camelot.factory]);
}

async function getAlgebraQuoterV2() {
return ethers.getContractAt(
require("../../abis/AlgebraQuoterV2.json"),
camelot.quoterV2
);
}

describe("Quoter:Quickswap", async () => {
context("arbitrum", () => {
async function checkStaticMatchesOriginalSingle(
amountIn: BigNumber,
tokenIn: string,
tokenOut: string
) {
const params = { sqrtPriceLimitX96: 0, amountIn, tokenIn, tokenOut };
const dyOriginal = await getOriginalQuoterV2QuoteSingle(params);
const dyStatic = await fix.StaticQuoter.quoteExactInputSingle(params);
expect(dyStatic).to.eq(dyOriginal);
logGasEstimate(params);
}

async function checkStaticMatchesOriginalPath(
amountIn: BigNumber,
tokens: string[]
) {
const path = encodePathNoFees(tokens);
const dyOriginal = await getOriginalQuoterV2QuotePath(path, amountIn);
const dyStatic = await fix.StaticQuoter.quoteExactInput(path, amountIn);
expect(dyStatic).to.eq(dyOriginal);
}

async function getOriginalQuoterV2QuoteSingle(params: any) {
return fix.OriginalQuoter.callStatic.quoteExactInputSingle(
params.tokenIn,
params.tokenOut,
params.amountIn,
params.sqrtPriceLimitX96
);
}

async function getOriginalQuoterV2QuotePath(
path: any,
amountIn: BigNumber
) {
return fix.OriginalQuoter.callStatic.quoteExactInput(path, amountIn);
}

async function logGasEstimate(params: any) {
const gas = await fix.StaticQuoter.estimateGas.quoteExactInputSingle(
params
);
console.log(`Gas: ${gas.toString()}`);
}

let fix: ThenArgRecursive<ReturnType<typeof arbitrumFixture>>;

context("130105395", async () => {
const FORK_BLOCK = 130105395;

beforeEach(async () => {
fix = await arbitrumFixture(FORK_BLOCK);
});

context(
"static-Quoter and original-Quoter quotes match :: single",
async () => {
it("ARB -> WETH :: 100 ARB", async () => {
await checkStaticMatchesOriginalSingle(
ethers.utils.parseUnits("100", 18),
tokens.arb,
tokens.weth
);
});

it("ARB -> WETH :: 1000 ARB", async () => {
await checkStaticMatchesOriginalSingle(
ethers.utils.parseUnits("1000", 18),
tokens.arb,
tokens.weth
);
});

it("USDC -> WETH :: 100 USDC", async () => {
await checkStaticMatchesOriginalSingle(
ethers.utils.parseUnits("1000", 6),
tokens.usdc,
tokens.weth
);
});
}
);
});
});
});