-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #295 from Uniswap/bump-sdk
feat: hard-quote integration tests
- Loading branch information
Showing
9 changed files
with
226 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import { ChainId } from '../util/chains'; | ||
|
||
export const SUPPORTED_CHAINS: ChainId[] = [ChainId.MAINNET, ChainId.GÖRLI, ChainId.POLYGON]; | ||
export const SUPPORTED_CHAINS: ChainId[] = [ChainId.MAINNET, ChainId.GÖRLI, ChainId.POLYGON, ChainId.SEPOLIA]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
import { V2DutchOrderBuilder } from '@uniswap/uniswapx-sdk'; | ||
import chai, { expect } from 'chai'; | ||
import chaiAsPromised from 'chai-as-promised'; | ||
import chaiSubset from 'chai-subset'; | ||
import { BigNumber, ethers } from 'ethers'; | ||
import { v4 as uuidv4 } from 'uuid'; | ||
|
||
import { HardQuoteRequestBody } from '../../lib/handlers/hard-quote'; | ||
import { checkDefined } from '../../lib/preconditions/preconditions'; | ||
import AxiosUtils from '../util/axios'; | ||
|
||
chai.use(chaiAsPromised); | ||
chai.use(chaiSubset); | ||
|
||
const COSIGNER_ADDR = checkDefined( | ||
process.env.COSIGNER_ADDR, | ||
'Must set COSIGNER_ADDR env variable for integ tests. See README' | ||
); | ||
const INTEG_TEST_PK = checkDefined( | ||
process.env.INTEG_TEST_PK, | ||
'Must set INTEG_TEST_PK env variable for integ tests. See README' | ||
); | ||
// PARAM_API base URL | ||
const UNISWAP_API = checkDefined( | ||
process.env.UNISWAP_API, | ||
'Must set UNISWAP_API env variable for integ tests. See README' | ||
); | ||
|
||
const SEPOLIA = 11155111; | ||
const PARAM_API = `${UNISWAP_API}hard-quote`; | ||
|
||
const REQUEST_ID = uuidv4(); | ||
const now = Math.floor(Date.now() / 1000); | ||
const swapper = new ethers.Wallet(INTEG_TEST_PK); | ||
const SWAPPER_ADDRESS = swapper.address; | ||
const TOKEN_IN = '0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238'; // USDC on Sepolia | ||
const TOKEN_OUT = '0xfFf9976782d46CC05630D1f6eBAb18b2324d6B14'; // WETH on Sepolia | ||
const AMOUNT = BigNumber.from('1'); | ||
|
||
let builder: V2DutchOrderBuilder; | ||
|
||
describe('Hard Quote endpoint integration test', function () { | ||
beforeEach(() => { | ||
builder = new V2DutchOrderBuilder(SEPOLIA); | ||
}); | ||
|
||
describe('Invalid requests', async () => { | ||
it('missing signature', async () => { | ||
const v2Order = builder | ||
.input({ token: TOKEN_IN, startAmount: AMOUNT, endAmount: AMOUNT }) | ||
.output({ token: TOKEN_OUT, startAmount: AMOUNT, endAmount: AMOUNT, recipient: SWAPPER_ADDRESS }) | ||
.nonce(BigNumber.from(100)) | ||
.cosigner(ethers.constants.AddressZero) | ||
.deadline(now + 1000) | ||
.swapper(SWAPPER_ADDRESS) | ||
.buildPartial(); | ||
|
||
const quoteReq = { | ||
requestId: REQUEST_ID, | ||
encodedInnerOrder: v2Order.serialize(), | ||
tokenInChainId: SEPOLIA, | ||
tokenOutChainId: SEPOLIA, | ||
}; | ||
|
||
const { data, status } = await AxiosUtils.callPassThroughFail('POST', PARAM_API, quoteReq); | ||
expect(data.detail).to.equal('"innerSig" is required'); | ||
expect(status).to.equal(400); | ||
}); | ||
|
||
it('missing encodedInnerOrder', async () => { | ||
const quoteReq = { | ||
requestId: REQUEST_ID, | ||
innerSig: '0x', | ||
tokenInChainId: SEPOLIA, | ||
tokenOutChainId: SEPOLIA, | ||
}; | ||
|
||
const { data, status } = await AxiosUtils.callPassThroughFail('POST', PARAM_API, quoteReq); | ||
expect(data.detail).to.equal('"encodedInnerOrder" is required'); | ||
expect(status).to.equal(400); | ||
}); | ||
|
||
it('missing requestId', async () => { | ||
const v2Order = builder | ||
.input({ token: TOKEN_IN, startAmount: AMOUNT, endAmount: AMOUNT }) | ||
.output({ token: TOKEN_OUT, startAmount: AMOUNT, endAmount: AMOUNT, recipient: SWAPPER_ADDRESS }) | ||
.nonce(BigNumber.from(100)) | ||
.cosigner(ethers.constants.AddressZero) | ||
.deadline(now + 1000) | ||
.swapper(SWAPPER_ADDRESS) | ||
.buildPartial(); | ||
const { domain, types, values } = v2Order.permitData(); | ||
const signature = await swapper._signTypedData(domain, types, values); | ||
|
||
const quoteReq = { | ||
encodedInnerOrder: v2Order.serialize(), | ||
innerSig: signature, | ||
tokenInChainId: SEPOLIA, | ||
tokenOutChainId: SEPOLIA, | ||
}; | ||
|
||
const { data, status } = await AxiosUtils.callPassThroughFail('POST', PARAM_API, quoteReq); | ||
expect(data.detail).to.equal('"requestId" is required'); | ||
expect(status).to.equal(400); | ||
}); | ||
|
||
it('unknown cosigner', async () => { | ||
const v2Order = builder | ||
.input({ token: TOKEN_IN, startAmount: AMOUNT, endAmount: AMOUNT }) | ||
.output({ token: TOKEN_OUT, startAmount: AMOUNT, endAmount: AMOUNT, recipient: SWAPPER_ADDRESS }) | ||
.nonce(BigNumber.from(100)) | ||
.cosigner(ethers.constants.AddressZero) | ||
.deadline(now + 1000) | ||
.swapper(SWAPPER_ADDRESS) | ||
.buildPartial(); | ||
const { domain, types, values } = v2Order.permitData(); | ||
const signature = await swapper._signTypedData(domain, types, values); | ||
|
||
const quoteReq: HardQuoteRequestBody = { | ||
requestId: REQUEST_ID, | ||
encodedInnerOrder: v2Order.serialize(), | ||
innerSig: signature, | ||
tokenInChainId: SEPOLIA, | ||
tokenOutChainId: SEPOLIA, | ||
}; | ||
|
||
const { data, status } = await AxiosUtils.callPassThroughFail('POST', PARAM_API, quoteReq); | ||
expect(data.detail).to.equal('Unknown cosigner'); | ||
expect(status).to.equal(400); | ||
}); | ||
}); | ||
|
||
describe('Valid requests', async () => { | ||
it('successfully posts to order service', async () => { | ||
const prebuildOrder = builder | ||
.input({ token: TOKEN_IN, startAmount: AMOUNT, endAmount: AMOUNT }) | ||
.output({ token: TOKEN_OUT, startAmount: AMOUNT, endAmount: AMOUNT, recipient: SWAPPER_ADDRESS }) | ||
.nonce(BigNumber.from(100)) | ||
.cosigner(COSIGNER_ADDR) | ||
.deadline(now + 1000) | ||
.swapper(SWAPPER_ADDRESS); | ||
|
||
const v2Order = prebuildOrder.buildPartial(); | ||
const { domain, types, values } = v2Order.permitData(); | ||
const signature = await swapper._signTypedData(domain, types, values); | ||
|
||
const quoteReq: HardQuoteRequestBody = { | ||
requestId: REQUEST_ID, | ||
encodedInnerOrder: v2Order.serialize(), | ||
innerSig: signature, | ||
tokenInChainId: SEPOLIA, | ||
tokenOutChainId: SEPOLIA, | ||
allowNoQuote: true, | ||
}; | ||
|
||
const { data, status } = await AxiosUtils.callPassThroughFail('POST', PARAM_API, quoteReq); | ||
console.log(data); | ||
expect(status).to.equal(200); | ||
expect(data.chainId).to.equal(SEPOLIA); | ||
expect(data.orderHash).to.match(/0x[0-9a-fA-F]{64}/); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5304,10 +5304,10 @@ | |
resolved "https://registry.yarnpkg.com/@uniswap/token-lists/-/token-lists-1.0.0-beta.33.tgz#966ba96c9ccc8f0e9e09809890b438203f2b1911" | ||
integrity sha512-JQkXcpRI3jFG8y3/CGC4TS8NkDgcxXaOQuYW8Qdvd6DcDiIyg2vVYCG9igFEzF0G6UvxgHkBKC7cWCgzZNYvQg== | ||
|
||
"@uniswap/[email protected].3": | ||
version "2.0.1-alpha.3" | ||
resolved "https://registry.npmjs.org/@uniswap/uniswapx-sdk/-/uniswapx-sdk-2.0.1-alpha.3.tgz#09992069e7de258504185a85512fc2a5b763713b" | ||
integrity sha512-0KUqmscaRPOL2QVguvZZq/573sQmNoohp7pRyxxuEqz0BSr91jxWe5j6UiSCL4SkACuI0Ti/hvyZAFQgue46YA== | ||
"@uniswap/[email protected].7": | ||
version "2.0.1-alpha.7" | ||
resolved "https://registry.npmjs.org/@uniswap/uniswapx-sdk/-/uniswapx-sdk-2.0.1-alpha.7.tgz#64c3283f78c6a8814d44d8cbe6c1b3ac400f34eb" | ||
integrity sha512-i4ie/NGK42AFDsoCbDYfvKKrJHy7UzWulCPj26USVbDq1goq9s0bIfxniMHEDL2nph47zSDLUzAYEtYbvqRKvw== | ||
dependencies: | ||
"@ethersproject/bytes" "^5.7.0" | ||
"@ethersproject/providers" "^5.7.0" | ||
|