-
Notifications
You must be signed in to change notification settings - Fork 307
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Proof of Reserves Aggregator (#3563)
* Proof of Reserves Aggregator * Add timestamps * Fix multichainAddress input convention
- Loading branch information
Showing
8 changed files
with
176 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/proof-of-reserves-adapter': minor | ||
--- | ||
|
||
Add multiReserves 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@chainlink/por-address-list-adapter': patch | ||
--- | ||
|
||
Fix input convension |
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,7 @@ | ||
import * as reserves from './reserves' | ||
import type { TInputParameters as SingleTInputParameters } from './reserves' | ||
import type { TInputParameters as MultiTInputParameters } from './multiReserves' | ||
|
||
export type TInputParameters = reserves.TInputParameters | ||
export type TInputParameters = SingleTInputParameters | MultiTInputParameters | ||
|
||
export * as reserves from './reserves' | ||
export * as multiReserves from './multiReserves' |
77 changes: 77 additions & 0 deletions
77
packages/composites/proof-of-reserves/src/endpoint/multiReserves.ts
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,77 @@ | ||
import type { ExecuteWithConfig, InputParameters } from '@chainlink/ea-bootstrap' | ||
import type { TInputParameters as SingleTInputParameters } from './reserves' | ||
import { execute as singleExecute } from './reserves' | ||
import { Validator } from '@chainlink/ea-bootstrap' | ||
import { Config } from '../config' | ||
import { AdapterError } from '@chainlink/ea-bootstrap' | ||
|
||
export const supportedEndpoints = ['multiReserves'] | ||
|
||
export type TInputParameters = { | ||
input: SingleTInputParameters[] | ||
} | ||
|
||
const inputParameters: InputParameters<TInputParameters> = { | ||
input: { | ||
required: true, | ||
type: 'array', | ||
description: 'An array of PoR request, each request is a request to the reserves endpoint', | ||
}, | ||
} | ||
|
||
export const execute: ExecuteWithConfig<Config> = async (input, context, config) => { | ||
const providerDataRequestedUnixMs = Date.now() | ||
|
||
const validator = new Validator(input, inputParameters) | ||
const jobRunID = validator.validated.id | ||
|
||
const results = await Promise.all( | ||
validator.validated.data.input.map((input) => | ||
singleExecute( | ||
{ | ||
id: jobRunID, | ||
data: input, | ||
}, | ||
context, | ||
config, | ||
), | ||
), | ||
) | ||
|
||
const result = results | ||
.map((result) => { | ||
if (result.statusCode != 200 || !result.result) { | ||
throw new AdapterError({ | ||
...result, | ||
}) | ||
} else { | ||
return scale(BigInt(result.result.toString()), result.data.decimals?.toString()) | ||
} | ||
}) | ||
.reduce((s, e) => s + e) | ||
.toString() | ||
|
||
return { | ||
jobRunID, | ||
result: result, | ||
statusCode: 200, | ||
data: { | ||
result: result, | ||
statusCode: 200, | ||
decimals: 18, | ||
timestamps: { | ||
providerDataRequestedUnixMs, | ||
providerDataReceivedUnixMs: Date.now(), | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
const scale = (value: bigint, decimal?: string) => { | ||
if (decimal) { | ||
// Scale to 18 decimals | ||
return value * 10n ** (18n - BigInt(decimal)) | ||
} else { | ||
return value | ||
} | ||
} |
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