-
Notifications
You must be signed in to change notification settings - Fork 309
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Refactor adapter to have price/lwba endoints * Add LWBA response verification in test
- Loading branch information
Showing
10 changed files
with
178 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@chainlink/glv-token-adapter': minor | ||
--- | ||
|
||
Add LWBA endpoint |
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 +1,2 @@ | ||
export { endpoint as price } from './price' | ||
export { endpoint as lwba } from './lwba' |
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,38 @@ | ||
import { | ||
AdapterEndpoint, | ||
LwbaResponseDataFields, | ||
} from '@chainlink/external-adapter-framework/adapter' | ||
import { InputParameters } from '@chainlink/external-adapter-framework/validation' | ||
import { config } from '../config' | ||
import { glvLwbaTransport } from '../transport/lwba' | ||
|
||
export const inputParameters = new InputParameters( | ||
{ | ||
glv: { | ||
required: true, | ||
type: 'string', | ||
description: 'Glv address', | ||
}, | ||
}, | ||
[ | ||
{ | ||
glv: '0x528A5bac7E746C9A509A1f4F6dF58A03d44279F9', | ||
}, | ||
], | ||
) | ||
|
||
export type BaseEndpointTypesLwba = { | ||
Parameters: typeof inputParameters.definition | ||
Response: LwbaResponseDataFields & { | ||
Data: { | ||
sources: Record<string, string[]> | ||
} | ||
} | ||
Settings: typeof config.settings | ||
} | ||
|
||
export const endpoint = new AdapterEndpoint({ | ||
name: 'crypto-lwba', | ||
transport: glvLwbaTransport, | ||
inputParameters, | ||
}) |
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,13 +1,13 @@ | ||
import { expose, ServerInstance } from '@chainlink/external-adapter-framework' | ||
import { Adapter } from '@chainlink/external-adapter-framework/adapter' | ||
import { config } from './config' | ||
import { price } from './endpoint' | ||
import { lwba, price } from './endpoint' | ||
|
||
export const adapter = new Adapter({ | ||
defaultEndpoint: price.name, | ||
name: 'GLV_TOKEN', | ||
config, | ||
endpoints: [price], | ||
endpoints: [price, lwba], | ||
}) | ||
|
||
export const server = (): Promise<ServerInstance | undefined> => expose(adapter) |
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,44 @@ | ||
import { BaseGlvTransport } from './base' | ||
import { EndpointContext } from '@chainlink/external-adapter-framework/adapter' | ||
import { TypeFromDefinition } from '@chainlink/external-adapter-framework/validation/input-params' | ||
import { AdapterResponse, sleep } from '@chainlink/external-adapter-framework/util' | ||
import { BaseEndpointTypesLwba } from '../endpoint/lwba' | ||
|
||
export class GlvLwbaTransport extends BaseGlvTransport<BaseEndpointTypesLwba> { | ||
async backgroundHandler( | ||
context: EndpointContext<BaseEndpointTypesLwba>, | ||
entries: TypeFromDefinition<BaseEndpointTypesLwba['Parameters']>[], | ||
): Promise<void> { | ||
await Promise.all(entries.map(async (param) => this.handleRequest(param))) | ||
await sleep(context.adapterSettings.BACKGROUND_EXECUTE_MS) | ||
} | ||
|
||
async handleRequest( | ||
param: TypeFromDefinition<BaseEndpointTypesLwba['Parameters']>, | ||
): Promise<void> { | ||
const response = await this._handleRequest(param).catch((e) => this.handleError(e)) | ||
await this.responseCache.write(this.name, [{ params: param, response }]) | ||
} | ||
|
||
protected formatResponse( | ||
result: number, | ||
minimizedValue: number, | ||
maximizedValue: number, | ||
sources: Record<string, string[]>, | ||
timestamps: any, | ||
): AdapterResponse<BaseEndpointTypesLwba['Response']> { | ||
return { | ||
data: { | ||
mid: result, | ||
bid: minimizedValue, | ||
ask: maximizedValue, | ||
sources, | ||
}, | ||
statusCode: 200, | ||
result: null, | ||
timestamps, | ||
} | ||
} | ||
} | ||
|
||
export const glvLwbaTransport = new GlvLwbaTransport() |
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,5 +1,15 @@ | ||
{ | ||
"requests": [{ | ||
"glv": "0x528A5bac7E746C9A509A1f4F6dF58A03d44279F9" | ||
}] | ||
"requests": [ | ||
{ | ||
"glv": "0x528A5bac7E746C9A509A1f4F6dF58A03d44279F9" | ||
}, | ||
{ | ||
"endpoint": "price", | ||
"glv": "0x528A5bac7E746C9A509A1f4F6dF58A03d44279F9" | ||
}, | ||
{ | ||
"endpoint": "crypto-lwba", | ||
"glv": "0x528A5bac7E746C9A509A1f4F6dF58A03d44279F9" | ||
} | ||
] | ||
} |
28 changes: 28 additions & 0 deletions
28
packages/composites/glv-token/test/integration/__snapshots__/adapter.test.ts.snap
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