This project demonstrates how to call Pyth network Entropy contract using a SponsoredCall request
In order to do so, we will transfer USDC to the contract with the relayer using the permit()
, swapping on-chain USDC
for ETH
using PancakeSwap router and finally calling entropy.requestWithCallback{value: pythFee}
-
Calling Permit and transfer
token.permit(owner, address(this), fee, deadline, v, r, s); token.transferFrom(owner, address(this), fee);
-
Swapping the USDC for ETH with exact ETH amount
router.swapTokensForExactETH( pythFee, fee, path, address(this), deadline );
-
Requesting Entropy Randomnumber
address provider = entropy.getDefaultProvider(); uint64 sequenceNumber = entropy.requestWithCallback{value: pythFee}( provider, randomNumber );
We are forking arbitrum using USDC, the Pancake Router
In this test we are mocking the sponsoredCall
calling increment()
method and checking that the entropy contract balance should increase with the entropy fee
In this test we are mocking the sponsoredCall
calling the multiCallIncrement()
sending two txs, and checking that the entropy contract balance should increase with 2 x entropy fee
- Install dependencies
yarn install
- Compile smart contracts
yarn run hardhat compile
- Run unit tests
yarn run hardhat test