Skip to content

Commit

Permalink
MERC-5642 LWBA Invariant validation (#3344)
Browse files Browse the repository at this point in the history
* Update coinmetrics to framework version 1.1.0 . Add lwba validation integration test

* Update tiingo to framework version 1.1.0 . Add lwba validation integration test

* Bump framework version

* Update yarn cache

* Add LWBA validation test to cfbenchmarks

* Update snapshot

* Add LWBA validation test to blocksize

* Add changeset for LWBA adapters

* Add alongside to soak test blacklist
  • Loading branch information
mjk90 authored Jul 11, 2024
1 parent 380ee79 commit 9f98cbf
Show file tree
Hide file tree
Showing 90 changed files with 454 additions and 248 deletions.
8 changes: 8 additions & 0 deletions .changeset/seven-grapes-provide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@chainlink/blocksize-capital-adapter': minor
'@chainlink/cfbenchmarks-adapter': minor
'@chainlink/coinmetrics-adapter': minor
'@chainlink/tiingo-adapter': minor
---

Add LWBA validation tests
72 changes: 72 additions & 0 deletions .changeset/solid-cloths-run.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
---
'@chainlink/dydx-stark-adapter': patch
'@chainlink/historical-average-adapter': patch
'@chainlink/apy-finance-test-adapter': patch
'@chainlink/gm-token-adapter': patch
'@chainlink/proof-of-reserves-adapter': patch
'@chainlink/stader-address-list-adapter': patch
'@chainlink/eth-beacon-adapter': patch
'@chainlink/frxeth-exchange-rate-adapter': patch
'@chainlink/tradermade-adapter': patch
'@chainlink/finage-adapter': patch
'@chainlink/elwood-adapter': patch
'@chainlink/cfbenchmarks-adapter': patch
'@chainlink/alphavantage-adapter': patch
'@chainlink/dxfeed-secondary-adapter': patch
'@chainlink/moore-hk-adapter': patch
'@chainlink/gemini-adapter': patch
'@chainlink/gsr-adapter': patch
'@chainlink/alongside-adapter': patch
'@chainlink/elven-adapter': patch
'@chainlink/dlc-btc-por-adapter': patch
'@chainlink/por-indexer-adapter': patch
'@chainlink/stader-balance-adapter': patch
'@chainlink/icap-adapter': patch
'@chainlink/view-function-multi-chain-adapter': patch
'@chainlink/dar-adapter': patch
'@chainlink/s3-csv-reader-adapter': patch
'@chainlink/iex-cloud-adapter': patch
'@chainlink/avalanche-platform-adapter': patch
'@chainlink/lotus-adapter': patch
'@chainlink/openexchangerates-adapter': patch
'@chainlink/por-address-list-adapter': patch
'@chainlink/view-starknet-latest-answer-adapter': patch
'@chainlink/polygon-adapter': patch
'@chainlink/view-function-adapter': patch
'@chainlink/tp-adapter': patch
'@chainlink/moonbeam-address-list-adapter': patch
'@chainlink/gramchain-adapter': patch
'@chainlink/galaxy-adapter': patch
'@chainlink/superstate-adapter': patch
'@chainlink/bank-frick-adapter': patch
'@chainlink/kaiko-adapter': patch
'@chainlink/finnhub-adapter': patch
'@chainlink/wbtc-address-set-adapter': patch
'@chainlink/finalto-adapter': patch
'@chainlink/polkadot-balance-adapter': patch
'@chainlink/finnhub-secondary-adapter': patch
'@chainlink/coingecko-adapter': patch
'@chainlink/coinbase-prime-adapter': patch
'@chainlink/nft-blue-chip-adapter': patch
'@chainlink/ion.au-adapter': patch
'@chainlink/starknet-gas-price-adapter': patch
'@chainlink/clear-bank-adapter': patch
'@chainlink/dxfeed-adapter': patch
'@chainlink/oanda-adapter': patch
'@chainlink/the-network-firm-adapter': patch
'@chainlink/blocksize-capital-adapter': patch
'@chainlink/ncfx-adapter': patch
'@chainlink/trueusd-adapter': patch
'@chainlink/cryptocompare-adapter': patch
'@chainlink/harris-and-trotter-adapter': patch
'@chainlink/intrinio-adapter': patch
'@chainlink/twosigma-adapter': patch
'@chainlink/coinmarketcap-adapter': patch
'@chainlink/coinpaprika-adapter': patch
'@chainlink/trumatic-matic-exchange-rate-adapter': patch
'@chainlink/tradingeconomics-adapter': patch
'@chainlink/token-allocation-adapter': patch
'@chainlink/token-allocation-test-adapter': patch
---

Bumped framework version
186 changes: 93 additions & 93 deletions .pnp.cjs

Large diffs are not rendered by default.

Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"source-map-support": "0.5.21"
},
"devDependencies": {
"@chainlink/external-adapter-framework": "1.0.0",
"@chainlink/external-adapter-framework": "1.1.0",
"@changesets/changelog-github": "0.5.0",
"@changesets/cli": "2.27.1",
"@types/babel__core": "7.20.5",
Expand Down
2 changes: 1 addition & 1 deletion packages/composites/apy-finance-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"start": "yarn server:dist"
},
"dependencies": {
"@chainlink/external-adapter-framework": "1.0.0",
"@chainlink/external-adapter-framework": "1.1.0",
"@chainlink/token-allocation-test-adapter": "workspace:*",
"axios": "1.6.8",
"ethers": "5.4.7",
Expand Down
2 changes: 1 addition & 1 deletion packages/composites/gm-token/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"typescript": "5.0.4"
},
"dependencies": {
"@chainlink/external-adapter-framework": "1.0.0",
"@chainlink/external-adapter-framework": "1.1.0",
"decimal.js": "^10.3.1",
"ethers": "^5.4.6",
"tslib": "2.4.1"
Expand Down
2 changes: 1 addition & 1 deletion packages/composites/historical-average/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
},
"devDependencies": {
"@chainlink/ea-test-helpers": "workspace:*",
"@chainlink/external-adapter-framework": "1.0.0",
"@chainlink/external-adapter-framework": "1.1.0",
"@types/jest": "27.5.2",
"@types/node": "16.18.96",
"@types/supertest": "2.0.16",
Expand Down
2 changes: 1 addition & 1 deletion packages/composites/proof-of-reserves/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"tslib": "^2.3.1"
},
"devDependencies": {
"@chainlink/external-adapter-framework": "1.0.0",
"@chainlink/external-adapter-framework": "1.1.0",
"@types/jest": "27.5.2",
"@types/node": "16.18.96",
"@types/supertest": "2.0.16",
Expand Down
2 changes: 1 addition & 1 deletion packages/non-deployable/token-allocation-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"build": "tsc -b"
},
"dependencies": {
"@chainlink/external-adapter-framework": "1.0.0",
"@chainlink/external-adapter-framework": "1.1.0",
"axios": "1.6.8",
"decimal.js": "^10.3.1",
"ethers": "^5.4.6",
Expand Down
2 changes: 1 addition & 1 deletion packages/non-deployable/token-allocation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"tslib": "^2.3.1"
},
"devDependencies": {
"@chainlink/external-adapter-framework": "1.0.0",
"@chainlink/external-adapter-framework": "1.1.0",
"@types/jest": "27.5.2",
"@types/node": "16.18.96",
"nock": "13.5.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"@apidevtools/json-schema-ref-parser": "9.1.2",
"@chainlink/ea-bootstrap": "workspace:*",
"@chainlink/ea-factories": "workspace:*",
"@chainlink/external-adapter-framework": "1.0.0",
"@chainlink/external-adapter-framework": "1.1.0",
"airtable": "0.11.6",
"axios": "1.6.8",
"axios-mock-adapter": "1.20.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export const SoakTestBlacklist: string[] = [
'accuweather',
'ada-balance', // Missing: RPC URL
'agoric',
'alongside', // Missing: RPC URL
'alphachain',
'alpine',
'anchor', // Missing: RPC URL
Expand Down
2 changes: 1 addition & 1 deletion packages/sources/alongside/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"start": "yarn server:dist"
},
"dependencies": {
"@chainlink/external-adapter-framework": "1.0.0",
"@chainlink/external-adapter-framework": "1.1.0",
"@types/crypto-js": "^4.1.1",
"axios": "1.6.8",
"crypto-js": "^4.2.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/sources/alphavantage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"start": "yarn server:dist"
},
"dependencies": {
"@chainlink/external-adapter-framework": "1.0.0",
"@chainlink/external-adapter-framework": "1.1.0",
"tslib": "2.4.1"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/sources/avalanche-platform/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"typescript": "5.0.4"
},
"dependencies": {
"@chainlink/external-adapter-framework": "1.0.0",
"@chainlink/external-adapter-framework": "1.1.0",
"tslib": "2.4.1"
}
}
2 changes: 1 addition & 1 deletion packages/sources/bank-frick/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"start": "yarn server:dist"
},
"dependencies": {
"@chainlink/external-adapter-framework": "1.0.0",
"@chainlink/external-adapter-framework": "1.1.0",
"axios": "1.6.8",
"fastify": "^3.29.4",
"tslib": "^2.3.1"
Expand Down
2 changes: 1 addition & 1 deletion packages/sources/blocksize-capital/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"start": "yarn server:dist"
},
"dependencies": {
"@chainlink/external-adapter-framework": "1.0.0",
"@chainlink/external-adapter-framework": "1.1.0",
"tslib": "^2.3.1"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`websocket lwba endpoint should return error (LWBA invariant violation) 1`] = `
{
"error": {
"message": "Invariant violation. Mid price must be between bid and ask prices. Got: (bid: 123.123, mid: 123.125, ask: 123.124)",
"name": "AdapterLWBAError",
},
"status": "errored",
"statusCode": 500,
}
`;

exports[`websocket lwba endpoint should return success 1`] = `
{
"data": {
Expand Down Expand Up @@ -39,8 +50,8 @@ exports[`websocket vwap endpoint should return success 1`] = `
"result": 1.7748077041598187,
"statusCode": 200,
"timestamps": {
"providerDataReceivedUnixMs": 3042,
"providerDataStreamEstablishedUnixMs": 3030,
"providerDataReceivedUnixMs": 4052,
"providerDataStreamEstablishedUnixMs": 4040,
"providerIndicatedTimeUnixMs": 1670630400000,
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ describe('websocket', () => {
const response = await testAdapter.request(lwbaData)
expect(response.json()).toMatchSnapshot()
})
it('should return error (LWBA invariant violation)', async () => {
const lwbaData = {
base: 'LINK',
quote: 'USD',
endpoint: 'crypto-lwba',
}
const response = await testAdapter.request(lwbaData)
expect(response.json()).toMatchSnapshot()
})
})
describe('vwap endpoint', () => {
it('should return success', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ export const mockLwbaResponse = {
agg_mid_price: '1702.034150611851',
ts: 1693425803028,
},
{
ticker: 'LINKUSD',
agg_bid_price: '123.123',
agg_bid_size: '208.51838798',
agg_ask_price: '123.124',
agg_ask_size: '11.44083383',
agg_mid_price: '123.125',
ts: 1693425803029,
},
],
},
}
Expand Down
2 changes: 1 addition & 1 deletion packages/sources/cfbenchmarks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"start": "yarn server:dist"
},
"dependencies": {
"@chainlink/external-adapter-framework": "1.0.0",
"@chainlink/external-adapter-framework": "1.1.0",
"tslib": "2.4.1"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ exports[`websocket crypto endpoint with override should return success 1`] = `
}
`;

exports[`websocket lwba endpoint should return error (LWBA violation) 1`] = `
{
"error": {
"message": "Invariant violation. Mid price must be between bid and ask prices. Got: (bid: 1.123, mid: 1.1635, ask: 1.125)",
"name": "AdapterLWBAError",
},
"status": "errored",
"statusCode": 500,
}
`;

exports[`websocket lwba endpoint should return success 1`] = `
{
"data": {
Expand All @@ -50,8 +61,8 @@ exports[`websocket lwba endpoint should return success 1`] = `
exports[`websocket lwba endpoint with override should return success 1`] = `
{
"data": {
"ask": 2651.01,
"bid": 2652.26,
"ask": 2652.26,
"bid": 2651.01,
"mid": 2651.63,
},
"result": null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ describe('websocket', () => {
quote: 'USD',
endpoint: 'cryptolwba',
}
const dataLwbaInvariantViolation = {
from: 'BTC',
quote: 'USD',
endpoint: 'cryptolwba',
}
const dataLwbaOverride = {
endpoint: 'cryptolwba',
base: 'LINK',
Expand Down Expand Up @@ -64,7 +69,8 @@ describe('websocket', () => {
await testAdapter.request(dataCryptoOverride)
await testAdapter.request(dataLwba)
await testAdapter.request(dataLwbaOverride)
await testAdapter.waitForCache(3)
await testAdapter.request(dataLwbaInvariantViolation)
await testAdapter.waitForCache(4)
})

afterAll(async () => {
Expand Down Expand Up @@ -115,6 +121,12 @@ describe('websocket', () => {
expect(response.statusCode).toEqual(200)
expect(response.json()).toMatchSnapshot()
})

it('should return error (LWBA violation)', async () => {
const response = await testAdapter.request(dataLwbaInvariantViolation)
expect(response.statusCode).toEqual(500)
expect(response.json()).toMatchSnapshot()
})
})

describe('lwba input validation', () => {
Expand Down
19 changes: 17 additions & 2 deletions packages/sources/cfbenchmarks/test/integration/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,21 @@ export const mockWebSocketServer = (URL: string): MockWebsocketServer => {
midPrice: '1.1631',
}),
)
} else if (parsed.id === 'U_BTCUSD_RTI') {
// lwba endpoint invariant violation
console.log('return second eth request')
return socket.send(
JSON.stringify({
type: 'rti_stats',
time: 1677876163000,
id: 'U_BTCUSD_RTI',
value: '1.1635',
utilizedDepth: '1888000.0',
valueAsk: '1.125',
midPrice: '1.126',
valueBid: '1.123',
}),
)
} else if (parsed.id === 'U_LINKUSD_CHA_RTI') {
// lwba endpoint
return socket.send(
Expand All @@ -92,8 +107,8 @@ export const mockWebSocketServer = (URL: string): MockWebsocketServer => {
id: 'U_LINKUSD_CHA_RTI',
value: '2651.63',
utilizedDepth: '1888000.0',
valueAsk: '2651.01',
valueBid: '2652.26',
valueAsk: '2652.26',
valueBid: '2651.01',
midPrice: '2651.63',
}),
)
Expand Down
2 changes: 1 addition & 1 deletion packages/sources/clear-bank/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"typescript": "5.0.4"
},
"dependencies": {
"@chainlink/external-adapter-framework": "1.0.0",
"@chainlink/external-adapter-framework": "1.1.0",
"tslib": "2.4.1"
}
}
2 changes: 1 addition & 1 deletion packages/sources/coinbase-prime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"typescript": "5.0.4"
},
"dependencies": {
"@chainlink/external-adapter-framework": "1.0.0",
"@chainlink/external-adapter-framework": "1.1.0",
"@types/crypto-js": "4.2.2",
"crypto-js": "4.2.0",
"tslib": "2.4.1"
Expand Down
2 changes: 1 addition & 1 deletion packages/sources/coingecko/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"start": "yarn server:dist"
},
"dependencies": {
"@chainlink/external-adapter-framework": "1.0.0",
"@chainlink/external-adapter-framework": "1.1.0",
"tslib": "2.4.1"
},
"devDependencies": {
Expand Down
Loading

0 comments on commit 9f98cbf

Please sign in to comment.