Skip to content

Commit eb30574

Browse files
committed
hyperliquid testnet still down, pushing to base sepolia
1 parent 6250078 commit eb30574

File tree

5 files changed

+92
-188
lines changed

5 files changed

+92
-188
lines changed

integrations/evm-hardhat/contracts/PriceFeed.sol

Lines changed: 52 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,18 @@ contract PriceFeed {
2828
/// @notice The latest prices for each token ID
2929
uint256[] public latestPrices;
3030

31+
/// @notice The token IDs for each price (same order as latestPrices)
32+
string[] public storedTokenIds;
33+
3134
/// @notice Thrown when trying to fetch results before any request is transmitted
3235
error RequestNotTransmitted();
3336

3437
/// @notice Thrown when trying to access an invalid token index
3538
error InvalidTokenIndex();
3639

40+
/// @notice Thrown when trying to access a token ID that doesn't exist
41+
error TokenIdNotFound();
42+
3743
/**
3844
* @notice Sets up the contract with SEDA network parameters
3945
* @param _sedaCoreAddress Address of the SedaCore contract
@@ -74,6 +80,26 @@ contract PriceFeed {
7480

7581
// Pass the msg.value as fees to the SEDA core
7682
requestId = SEDA_CORE.postRequest{value: msg.value}(inputs, requestFee, resultFee, batchFee);
83+
84+
// Parse and store the token IDs
85+
bytes memory tokenIdsBytes = bytes(tokenIds);
86+
delete storedTokenIds; // Clear previous token IDs
87+
88+
// Simple parsing: split by comma
89+
uint256 start = 0;
90+
for (uint256 i = 0; i <= tokenIdsBytes.length; i++) {
91+
if (i == tokenIdsBytes.length || tokenIdsBytes[i] == ",") {
92+
if (i > start) {
93+
bytes memory tokenIdBytes = new bytes(i - start);
94+
for (uint256 j = 0; j < i - start; j++) {
95+
tokenIdBytes[j] = tokenIdsBytes[start + j];
96+
}
97+
storedTokenIds.push(string(tokenIdBytes));
98+
}
99+
start = i + 1;
100+
}
101+
}
102+
77103
return requestId;
78104
}
79105

@@ -98,40 +124,45 @@ contract PriceFeed {
98124
}
99125

100126
/**
101-
* @notice Manual function to set prices (for testing/debugging)
102-
* @param prices Array of prices to set
127+
* @notice Gets the price for a specific token by token ID
128+
* @param tokenId The token ID string
129+
* @return The price for the specified token
103130
*/
104-
function setPricesManually(uint256[] calldata prices) external {
105-
latestPrices = prices;
131+
function getPriceByTokenId(string calldata tokenId) external view returns (uint256) {
132+
// Find the index of the token ID
133+
for (uint256 i = 0; i < storedTokenIds.length; i++) {
134+
if (keccak256(abi.encodePacked(storedTokenIds[i])) == keccak256(abi.encodePacked(tokenId))) {
135+
if (i >= latestPrices.length) revert InvalidTokenIndex();
136+
return latestPrices[i];
137+
}
138+
}
139+
revert TokenIdNotFound(); // Token ID not found
106140
}
107141

108142
/**
109-
* @notice Debug function to see what data the oracle returned
110-
* @return The raw result data from the latest request
143+
* @notice Gets all latest prices
144+
* @return Array of all latest prices
111145
*/
112-
function getLastResult() external view returns (bytes memory, bool, uint8) {
113-
if (requestId == bytes32(0)) revert RequestNotTransmitted();
114-
115-
SedaDataTypes.Result memory result = SEDA_CORE.getResult(requestId);
116-
return (result.result, result.consensus, result.exitCode);
146+
function getAllPrices() external view returns (uint256[] memory) {
147+
return latestPrices;
117148
}
118149

119150
/**
120-
* @notice Gets the price for a specific token by index
121-
* @param tokenIndex The index of the token in the original request
122-
* @return The price for the specified token, or 0 if no consensus was reached
151+
* @notice Gets the token ID for a specific index
152+
* @param tokenIndex The index of the token
153+
* @return The token ID string
123154
*/
124-
function getPrice(uint256 tokenIndex) external view returns (uint256) {
125-
if (tokenIndex >= latestPrices.length) revert InvalidTokenIndex();
126-
return latestPrices[tokenIndex];
155+
function getTokenId(uint256 tokenIndex) external view returns (string memory) {
156+
if (tokenIndex >= storedTokenIds.length) revert InvalidTokenIndex();
157+
return storedTokenIds[tokenIndex];
127158
}
128159

129160
/**
130-
* @notice Gets all latest prices
131-
* @return Array of all latest prices
161+
* @notice Gets all stored token IDs
162+
* @return Array of all token ID strings
132163
*/
133-
function getAllPrices() external view returns (uint256[] memory) {
134-
return latestPrices;
164+
function getAllTokenIds() external view returns (string[] memory) {
165+
return storedTokenIds;
135166
}
136167

137168
/**
@@ -141,19 +172,4 @@ contract PriceFeed {
141172
function getTokenCount() external view returns (uint256) {
142173
return latestPrices.length;
143174
}
144-
145-
/**
146-
* @notice Legacy function for backward compatibility
147-
* @dev Returns the first price if available
148-
* @return The first price as uint128, or 0 if no consensus was reached
149-
*/
150-
function latestAnswer() public view returns (uint128) {
151-
if (requestId == bytes32(0)) revert RequestNotTransmitted();
152-
153-
if (latestPrices.length == 0) {
154-
return 0;
155-
}
156-
157-
return uint128(latestPrices[0]);
158-
}
159175
}

integrations/evm-hardhat/tasks/debug-result.ts

Lines changed: 0 additions & 54 deletions
This file was deleted.

integrations/evm-hardhat/tasks/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,3 @@ import './deploy';
99
import './latest';
1010
import './transmit';
1111
import './update';
12-
import './set-prices';
13-
import './debug-result';

integrations/evm-hardhat/tasks/latest.ts

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,18 @@
11
import { priceFeedScope } from '.';
22
import { getDeployedContract } from './utils';
33

4-
// Common token IDs used in testing - update this as needed
5-
const KNOWN_TOKEN_IDS = [
6-
'21742633143463906290569050155826241533067272736897614950488156847949938836455',
7-
'21742633143463906290569050155826241533067272736897614950488156847949938836456'
8-
];
9-
104
/**
115
* Task: Fetches the latest answers from the PriceFeed contract.
126
* Optional parameters:
137
* - contract: PriceFeed contract address
14-
* - tokenId: Specific Polymarket token ID to fetch (if not provided, shows all prices)
8+
* - tokenId: Specific token ID to fetch (if not provided, shows all prices)
159
* - tokenIndex: Specific token index to fetch (if not provided, shows all prices)
1610
* If the contract address is not provided, fetches from previous deployments.
1711
*/
1812
priceFeedScope
19-
.task('latest', 'Calls the latestAnswer function on the PriceFeed contract')
13+
.task('latest', 'Fetches the latest prices from the PriceFeed contract')
2014
.addOptionalParam('contract', 'The PriceFeed contract address')
21-
.addOptionalParam('tokenId', 'Specific Polymarket token ID to fetch')
15+
.addOptionalParam('tokenId', 'Specific token ID to fetch')
2216
.addOptionalParam('tokenIndex', 'Specific token index to fetch')
2317
.setAction(async ({ contract, tokenId, tokenIndex }, hre) => {
2418
try {
@@ -42,30 +36,36 @@ priceFeedScope
4236
console.log('Could not update latest answers. Using cached data if available.\n');
4337
}
4438

45-
// Handle tokenId parameter by finding its index in known token IDs
46-
let targetIndex = tokenIndex;
39+
// Handle tokenId parameter using direct lookup
4740
if (tokenId !== undefined) {
48-
const foundIndex = KNOWN_TOKEN_IDS.findIndex(id => id === tokenId);
49-
if (foundIndex === -1) {
50-
console.error(`Token ID ${tokenId} not found in known token IDs. Known token IDs:`);
51-
KNOWN_TOKEN_IDS.forEach((id, index) => {
52-
console.log(` Index ${index}: ${id}`);
53-
});
41+
try {
42+
// Use generic contract call since TypeScript interface might not be updated yet
43+
const price = await priceFeed.getFunction('getPriceByTokenId')(tokenId);
44+
console.log(`Price for token ID ${tokenId}: ${price.toString()}`);
45+
return;
46+
} catch (error) {
47+
console.error(`Error getting price for token ID ${tokenId}: ${error}`);
48+
try {
49+
const allTokenIds = await priceFeed.getAllTokenIds();
50+
console.log('Available token IDs:');
51+
allTokenIds.forEach((id, index) => {
52+
console.log(` Index ${index}: ${id}`);
53+
});
54+
} catch (listError) {
55+
console.log('Could not retrieve available token IDs');
56+
}
5457
return;
5558
}
56-
targetIndex = foundIndex.toString();
5759
}
5860

59-
if (targetIndex !== undefined) {
60-
// Fetch specific token price
61-
const price = await priceFeed.getPrice(targetIndex);
62-
63-
// Show token ID if we know it
64-
const knownTokenId = KNOWN_TOKEN_IDS[parseInt(targetIndex)];
65-
if (knownTokenId) {
66-
console.log(`Price for token ID ${knownTokenId} (index ${targetIndex}): ${price.toString()}`);
67-
} else {
68-
console.log(`Price for token index ${targetIndex}: ${price.toString()}`);
61+
if (tokenIndex !== undefined) {
62+
// Fetch specific token price by index
63+
const price = await priceFeed.getPrice(tokenIndex);
64+
try {
65+
const tokenIdDisplay = await priceFeed.getTokenId(tokenIndex);
66+
console.log(`Price for token ID ${tokenIdDisplay} (index ${tokenIndex}): ${price.toString()}`);
67+
} catch (error) {
68+
console.log(`Price for token index ${tokenIndex}: ${price.toString()}`);
6969
}
7070
} else {
7171
// Fetch all prices
@@ -75,21 +75,21 @@ priceFeedScope
7575

7676
console.log(`\nToken Count: ${tokenCount.toString()}`);
7777
console.log('All Prices:');
78-
allPrices.forEach((price, index) => {
79-
const knownTokenId = KNOWN_TOKEN_IDS[index];
80-
if (knownTokenId) {
81-
console.log(` Token ID ${knownTokenId} (index ${index}): ${price.toString()}`);
82-
} else {
83-
console.log(` Token index ${index}: ${price.toString()}`);
84-
}
85-
});
8678

87-
// Also show legacy latestAnswer for backward compatibility
8879
try {
89-
const legacyAnswer = await priceFeed.latestAnswer();
90-
console.log(`\nLegacy Latest Answer (first price): ${legacyAnswer.toString()}`);
80+
const allTokenIds = await priceFeed.getAllTokenIds();
81+
console.log(`Found ${allTokenIds.length} stored token IDs`);
82+
allPrices.forEach((price, index) => {
83+
const tokenId = allTokenIds[index] || `index-${index}`;
84+
console.log(` Token ID ${tokenId} (index ${index}): ${price.toString()}`);
85+
});
9186
} catch (error) {
92-
console.log('\nLegacy Latest Answer: Not available');
87+
console.log(`Error getting token IDs: ${error}`);
88+
console.log('Fallback to index-based display');
89+
// Fallback to index-based display if token IDs not available
90+
allPrices.forEach((price, index) => {
91+
console.log(` Token index ${index}: ${price.toString()}`);
92+
});
9393
}
9494
}
9595
} catch (error: unknown) {

integrations/evm-hardhat/tasks/set-prices.ts

Lines changed: 0 additions & 56 deletions
This file was deleted.

0 commit comments

Comments
 (0)