Skip to content

Commit a4148c6

Browse files
committed
chore(dev-hub) Entropy code fixes
1 parent 045077b commit a4148c6

File tree

6 files changed

+100
-104
lines changed

6 files changed

+100
-104
lines changed

apps/developer-hub/content/docs/entropy/contract-addresses.mdx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Contract Addresses
2+
title: Contract & Provider Addresses
33
description: Pyth Entropy contract addresses on EVM networks
44
---
55

@@ -16,7 +16,8 @@ The Entropy contract is deployed on the following mainnet chains:
1616
The default provider on mainnet has a reveal delay to avoid changes on the outcome of the Entropy request because of block reorgs.
1717
The reveal delay shows how many blocks should be produced after the block including the request transaction in order to reveal and submit a callback transaction.
1818

19-
The default provider fulfills the request by sending a transaction with a gas limit as mentioned in above table. Entropy callbacks the consumer as part of this transaction.
19+
The default provider fulfills the request by sending a transaction with a gas limit as mentioned in above table or as set by the user in the request.
20+
Entropy callbacks the consumer as part of this transaction.
2021

2122
## Testnets
2223

apps/developer-hub/content/docs/entropy/current-fees.mdx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ title: Current Fees
33
description: Current fees for using Pyth Entropy
44
---
55

6-
# Current Fees
7-
86
The following tables shows the total fees payable when using the **default provider**.
97
Note that the fees shown below will vary over time with prevailing gas prices on each chain.
108

apps/developer-hub/content/docs/entropy/generate-random-numbers-evm.mdx

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ import { IEntropyV2 } from "@pythnetwork/entropy-sdk-solidity/IEntropyV2.sol";
5151
5252
// @param entropyAddress The address of the entropy contract.
5353
contract YourContract is IEntropyConsumer {
54-
IEntropyV2 public entropy;
54+
IEntropyV2 public entropy;
5555
56-
constructor(address entropyAddress) {
57-
entropy = IEntropyV2(entropyAddress);
58-
}
56+
constructor(address entropyAddress) {
57+
entropy = IEntropyV2(entropyAddress);
58+
}
5959
}
6060
`} />
6161

@@ -78,9 +78,9 @@ These methods use the default randomness provider ([see here](#randomness-provid
7878

7979
<DynamicCodeBlock lang="solidity"
8080
code={`function requestRandomNumber() external payable {
81-
uint256 fee = entropy.getFeeV2();
81+
uint256 fee = entropy.getFeeV2();
8282
83-
uint64 sequenceNumber = entropy.requestV2{ value: fee }();
83+
uint64 sequenceNumber = entropy.requestV2{ value: fee }();
8484
}
8585
`} />
8686

@@ -102,44 +102,44 @@ import { IEntropyConsumer } from "@pythnetwork/entropy-sdk-solidity/IEntropyCons
102102
import { IEntropyV2 } from "@pythnetwork/entropy-sdk-solidity/IEntropyV2.sol";
103103
104104
contract YourContract is IEntropyConsumer {
105-
IEntropyV2 entropy;
106-
107-
// @param entropyAddress The address of the entropy contract.
108-
constructor(address entropyAddress) {
109-
entropy = IEntropyV2(entropyAddress);
110-
}
111-
112-
function requestRandomNumber() external payable {
113-
// Get the fee for the request
114-
uint256 fee = entropy.getFeeV2();
115-
116-
// Request the random number with the callback
117-
uint64 sequenceNumber = entropy.requestV2{ value: fee }();
118-
// Store the sequence number to identify the callback request
119-
120-
}
121-
122-
// @param sequenceNumber The sequence number of the request.
123-
// @param provider The address of the provider that generated the random number. If your app uses multiple providers, you can use this argument to distinguish which one is calling the app back.
124-
// @param randomNumber The generated random number.
125-
// This method is called by the entropy contract when a random number is generated.
126-
// This method **must** be implemented on the same contract that requested the random number.
127-
// This method should **never** return an error -- if it returns an error, then the keeper will not be able to invoke the callback.
128-
// If you are having problems receiving the callback, the most likely cause is that the callback is erroring.
129-
// See the callback debugging guide here to identify the error https://docs.pyth.network/entropy/debug-callback-failures
130-
function entropyCallback(
131-
uint64 sequenceNumber,
132-
address provider,
133-
bytes32 randomNumber
134-
) internal override {
135-
// Implement your callback logic here.
136-
}
137-
138-
// This method is required by the IEntropyConsumer interface.
139-
// It returns the address of the entropy contract which will call the callback.
140-
function getEntropy() internal view override returns (address) {
141-
return address(entropy);
142-
}
105+
IEntropyV2 entropy;
106+
107+
// @param entropyAddress The address of the entropy contract.
108+
constructor(address entropyAddress) {
109+
entropy = IEntropyV2(entropyAddress);
110+
}
111+
112+
function requestRandomNumber() external payable {
113+
// Get the fee for the request
114+
uint256 fee = entropy.getFeeV2();
115+
116+
// Request the random number with the callback
117+
uint64 sequenceNumber = entropy.requestV2{ value: fee }();
118+
// Store the sequence number to identify the callback request
119+
120+
}
121+
122+
// @param sequenceNumber The sequence number of the request.
123+
// @param provider The address of the provider that generated the random number. If your app uses multiple providers, you can use this argument to distinguish which one is calling the app back.
124+
// @param randomNumber The generated random number.
125+
// This method is called by the entropy contract when a random number is generated.
126+
// This method **must** be implemented on the same contract that requested the random number.
127+
// This method should **never** return an error -- if it returns an error, then the keeper will not be able to invoke the callback.
128+
// If you are having problems receiving the callback, the most likely cause is that the callback is erroring.
129+
// See the callback debugging guide here to identify the error https://docs.pyth.network/entropy/debug-callback-failures
130+
function entropyCallback(
131+
uint64 sequenceNumber,
132+
address provider,
133+
bytes32 randomNumber
134+
) internal override {
135+
// Implement your callback logic here.
136+
}
137+
138+
// This method is required by the IEntropyConsumer interface.
139+
// It returns the address of the entropy contract which will call the callback.
140+
function getEntropy() internal view override returns (address) {
141+
return address(entropy);
142+
}
143143
}
144144
`} />
145145

apps/developer-hub/content/docs/entropy/meta.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
"debug-callback-failures",
1414
"---Reference Material---",
1515
"contract-addresses",
16+
"current-fees",
1617
"best-practices",
1718
"fees",
1819
"protocol-design",
19-
"current-fees",
2020
"error-codes",
2121
"examples",
2222
"request-callback-variants",

apps/developer-hub/content/docs/entropy/set-custom-gas-limits.mdx

Lines changed: 48 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ Instead of the basic `requestV2()` method, use the variant that accepts a `gasLi
3333

3434
<DynamicCodeBlock lang="solidity"
3535
code={`function requestRandomNumberWithCustomGas(
36-
uint32 customGasLimit
36+
uint32 customGasLimit
3737
) external payable {
38-
// Calculate the fee for the custom gas limit
39-
uint256 fee = entropy.getFeeV2(customGasLimit);
38+
// Calculate the fee for the custom gas limit
39+
uint256 fee = entropy.getFeeV2(customGasLimit);
4040
41-
// Request random number with custom gas limit
42-
uint64 sequenceNumber = entropy.requestV2{ value: fee }(customGasLimit);
41+
// Request random number with custom gas limit
42+
uint64 sequenceNumber = entropy.requestV2{ value: fee }(customGasLimit);
4343
44-
// Store the sequence number for tracking if needed
44+
// Store the sequence number for tracking if needed
4545
}
4646
`} />
4747

@@ -67,61 +67,58 @@ import { IEntropyConsumer } from "@pythnetwork/entropy-sdk-solidity/IEntropyCons
6767
import { IEntropyV2 } from "@pythnetwork/entropy-sdk-solidity/IEntropyV2.sol";
6868
6969
contract CustomGasLimitExample is IEntropyConsumer {
70-
IEntropyV2 public entropy;
71-
mapping(uint64 => bool) public processedRequests;
72-
73-
constructor(address entropyAddress) {
74-
entropy = IEntropyV2(entropyAddress);
75-
}
76-
77-
// Request with custom gas limit for complex callback
78-
function requestComplexRandomNumber() external payable {
79-
uint32 customGasLimit = 200000; // Higher limit for complex operations
80-
uint256 fee = entropy.getFeeV2(customGasLimit);
70+
IEntropyV2 public entropy;
71+
mapping(uint64 => bool) public processedRequests;
8172
82-
require(msg.value >= fee, "Insufficient fee");
83-
84-
uint64 sequenceNumber = entropy.requestV2{ value: fee }(customGasLimit);
85-
// Store sequence number if needed for tracking
73+
constructor(address entropyAddress) {
74+
entropy = IEntropyV2(entropyAddress);
75+
}
8676
87-
}
77+
// Request with custom gas limit for complex callback
78+
function requestComplexRandomNumber() external payable {
79+
uint32 customGasLimit = 200000; // Higher limit for complex operations
80+
uint256 fee = entropy.getFeeV2(customGasLimit);
8881
89-
// Request with lower gas limit for simple callback
90-
function requestSimpleRandomNumber() external payable {
91-
uint32 customGasLimit = 50000; // Lower limit for simple operations
92-
uint256 fee = entropy.getFeeV2(customGasLimit);
82+
require(msg.value >= fee, "Insufficient fee");
9383
94-
require(msg.value >= fee, "Insufficient fee");
84+
uint64 sequenceNumber = entropy.requestV2{ value: fee }(customGasLimit);
85+
// Store sequence number if needed for tracking
86+
}
9587
96-
uint64 sequenceNumber = entropy.requestV2{ value: fee }(customGasLimit);
88+
// Request with lower gas limit for simple callback
89+
function requestSimpleRandomNumber() external payable {
90+
uint32 customGasLimit = 50000; // Lower limit for simple operations
91+
uint256 fee = entropy.getFeeV2(customGasLimit);
9792
98-
}
93+
require(msg.value >= fee, "Insufficient fee");
9994
100-
// Complex callback that requires more gas
101-
function entropyCallback(
102-
uint64 sequenceNumber,
103-
address provider,
104-
bytes32 randomNumber
105-
) internal override {
106-
// Prevent duplicate processing
107-
require(!processedRequests[sequenceNumber], "Already processed");
108-
processedRequests[sequenceNumber] = true;
109-
110-
// Complex operations that require more gas
111-
for (uint i = 0; i < 10; i++) {
112-
// Simulate complex state changes
113-
// This would require more gas than the default limit
95+
uint64 sequenceNumber = entropy.requestV2{ value: fee }(customGasLimit);
11496
}
11597
116-
// Use the random number for your application logic
117-
uint256 randomValue = uint256(randomNumber);
118-
// Your application logic here...
119-
120-
}
98+
// Complex callback that requires more gas
99+
function entropyCallback(
100+
uint64 sequenceNumber,
101+
address provider,
102+
bytes32 randomNumber
103+
) internal override {
104+
// Prevent duplicate processing
105+
require(!processedRequests[sequenceNumber], "Already processed");
106+
processedRequests[sequenceNumber] = true;
107+
108+
// Complex operations that require more gas
109+
for (uint i = 0; i < 10; i++) {
110+
// Simulate complex state changes
111+
// This would require more gas than the default limit
112+
}
113+
114+
// Use the random number for your application logic
115+
uint256 randomValue = uint256(randomNumber);
116+
// Your application logic here...
117+
}
121118
122-
function getEntropy() internal view override returns (address) {
123-
return address(entropy);
124-
}
119+
function getEntropy() internal view override returns (address) {
120+
return address(entropy);
121+
}
125122
}
126123
`} />
127124

apps/developer-hub/src/components/EntropyTable/index.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,9 @@ const EntropyTableContent = ({
6363
{ id: "gasLimit", name: "Default Gas Limit" },
6464
];
6565

66-
const rows: RowConfig<Col>[] = Object.entries(chains).map(
67-
([chainName, d]) => ({
66+
const rows: RowConfig<Col>[] = Object.entries(chains)
67+
.sort(([a], [b]) => a.localeCompare(b))
68+
.map(([chainName, d]) => ({
6869
id: chainName,
6970
data: {
7071
chain: chainName,
@@ -79,8 +80,7 @@ const EntropyTableContent = ({
7980
delay: d.delay,
8081
gasLimit: d.gasLimit,
8182
},
82-
}),
83-
);
83+
}));
8484

8585
return (
8686
<Table<Col>

0 commit comments

Comments
 (0)