Walkthrough: Adding Price Index Data
A specific example of using an adapter
Follow these instructions to bring the most recent price data on-chain for a given price index.
Complete Example:
/**
* @notice Example for calling a protocol function with a prediction value from the Upshot Adapter
*
* @param protocolFunctionArgument An argument for the protocol function
* @param upshotAdapterData The signed data from the Upshot Adapter
*/
function callProtocolFunctionWithUpshotAdapterPredictionValue(
uint256 protocolFunctionArgument,
UpshotAdapterNumericData calldata upshotAdapterData
) external {
uint256 value = upshotAdapter.verifyData(upshotAdapterData);
_protocolFunctionRequiringPredictionValue(protocolFunctionArgument, value);
}
function _protocolFunctionRequiringPredictionValue(uint256 protocolFunctionArgument, uint256 value) internal {
// use arguments and value
}
Step by Step Guide:
- Create an Upshot API key by creating an account (opens in a new tab).
- Call the Adapter Index Prices API using the
topicId
found in the deployed topics list and the correct chainId. For example, if you use sepolia, you would provideethereum-11155111
. - Construct a call to the Allora Adapter contract on the chain of your choice (options listed under deployments) using the returned
signature
andnumeric_data
as follows:
Creating the Transaction:
await alloraAdapter.verifyData({
signedNumericData: [{
signature: signature,
numericData: {
topicId: topicId,
timestamp: timestamp,
numericValue: numericValue,
extraData: extraData
}
}],
extraData: '0x'
})
AlloraAdatper alloraAdatper = AlloraAdatper(0x238D0abD53fC68fAfa0CCD860446e381b400b5Be);
SignedNumericData[] memory signedNumericData = new SignedNumericData[](1);
signedNumericData[0] = SignedNumericData({
signature: signature,
numericData: NumericData({
topicId: topicId,
timestamp: timestamp,
numericValue: numericValue,
extraData: extraData
});
});
alloraAdapter.verifyData(AlloraAdapterNumericData({
signedNumericData: signedNumericData,
extraData: ''
}));
Notes
- The API endpoint uses
snake_case
, while the smart contract usescamelCase
for attribute names. - Ethers.js does not accept
''
forextraData
. EmptyextraData
should be denoted with'0x'
.
Code Links
- Open source adapter code (opens in a new tab)
- IAlloraAdapter (opens in a new tab), including the structs used for Solidity code.