-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Chainlink Pricefeed Example PriceConsumerV3.sol With AggregatorV3Interface.sol Directly In Contract #7
Open
MarcusWentz
wants to merge
1
commit into
main
Choose a base branch
from
chainlinkPricefeed
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Chainlink Pricefeed Example PriceConsumerV3.sol With AggregatorV3Interface.sol Directly In Contract #7
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -1,2 +1,18 @@ | ||
# warping-contracts | ||
Example Solidity contracts transpiled to Cairo using Warp | ||
|
||
Transpiles in Warp with no errors in Solidity 0.8.14 with: | ||
|
||
```shell | ||
bin/warp transpile exampleContracts/chainlink/pricefeed/pricefeedExample.sol | ||
``` | ||
|
||
Modified: | ||
|
||
-put contract AggregatorV3Interface.sol | ||
https://github.com/smartcontractkit/chainlink/blob/develop/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol | ||
directly into the pricefeed example contract instead of importing it to get around syntax transpiler issue. | ||
|
||
Contract from: | ||
|
||
https://docs.chain.link/data-feeds/using-data-feeds/#examine-the-sample-contract | ||
|
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,59 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.14; | ||
|
||
// AggregatorV3Interface contract from: https://github.com/smartcontractkit/chainlink/blob/develop/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol"; | ||
|
||
interface AggregatorV3Interface { | ||
|
||
function decimals() external view returns (uint8); | ||
|
||
function description() external view returns (string memory); | ||
|
||
function version() external view returns (uint256); | ||
|
||
function getRoundData(uint80 _roundId) | ||
external | ||
view | ||
returns ( | ||
uint80 roundId, | ||
int256 answer, | ||
uint256 startedAt, | ||
uint256 updatedAt, | ||
uint80 answeredInRound | ||
); | ||
|
||
function latestRoundData() | ||
external | ||
view | ||
returns ( | ||
uint80 roundId, | ||
int256 answer, | ||
uint256 startedAt, | ||
uint256 updatedAt, | ||
uint80 answeredInRound | ||
); | ||
} | ||
|
||
// Pricefeed example from: https://docs.chain.link/data-feeds/using-data-feeds/#examine-the-sample-contract | ||
|
||
contract PriceConsumerV3 { | ||
|
||
/** | ||
* Network: Sepolia | ||
* Aggregator: BTC/USD | ||
* Address: 0x1b44F3514812d835EB1BDB0acB33d3fA3351Ee43 | ||
*/ | ||
|
||
AggregatorV3Interface internal priceFeed = AggregatorV3Interface(address(0x1b44F3514812d835EB1BDB0acB33d3fA3351Ee43)); //Added address type wrapper to resolve Starknet type error. | ||
|
||
function getLatestPrice() public view returns (int) { | ||
( | ||
/* uint80 roundID */, | ||
int price, | ||
/*uint startedAt*/, | ||
/*uint timeStamp*/, | ||
/*uint80 answeredInRound*/ | ||
) = priceFeed.latestRoundData(); | ||
return price; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...put/exampleContracts/chainlink/pricefeed/pricefeedExample.sol/AggregatorV3Interface.cairo
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,22 @@ | ||
%lang starknet | ||
|
||
|
||
from starkware.cairo.common.uint256 import Uint256 | ||
|
||
|
||
// Contract Def AggregatorV3Interface | ||
|
||
|
||
@contract_interface | ||
namespace AggregatorV3Interface{ | ||
func decimals_313ce567()-> (__warp_0 : felt){ | ||
} | ||
func description_7284e416()-> (__warp_1_len : felt, __warp_1 : felt*){ | ||
} | ||
func version_54fd4d50()-> (__warp_2 : Uint256){ | ||
} | ||
func getRoundData_9a6fc8f5(_roundId : felt)-> (roundId : felt, answer : Uint256, startedAt : Uint256, updatedAt : Uint256, answeredInRound : felt){ | ||
} | ||
func latestRoundData_feaf968c()-> (roundId : felt, answer : Uint256, startedAt : Uint256, updatedAt : Uint256, answeredInRound : felt){ | ||
} | ||
} |
113 changes: 113 additions & 0 deletions
113
...mpleContracts/chainlink/pricefeed/pricefeedExample.sol/AggregatorV3Interface_sol_abi.json
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,113 @@ | ||
[ | ||
{ | ||
"inputs": [], | ||
"name": "decimals", | ||
"outputs": [ | ||
{ | ||
"internalType": "uint8", | ||
"name": "", | ||
"type": "uint8" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "description", | ||
"outputs": [ | ||
{ | ||
"internalType": "string", | ||
"name": "", | ||
"type": "string" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "uint80", | ||
"name": "_roundId", | ||
"type": "uint80" | ||
} | ||
], | ||
"name": "getRoundData", | ||
"outputs": [ | ||
{ | ||
"internalType": "uint80", | ||
"name": "roundId", | ||
"type": "uint80" | ||
}, | ||
{ | ||
"internalType": "int256", | ||
"name": "answer", | ||
"type": "int256" | ||
}, | ||
{ | ||
"internalType": "uint256", | ||
"name": "startedAt", | ||
"type": "uint256" | ||
}, | ||
{ | ||
"internalType": "uint256", | ||
"name": "updatedAt", | ||
"type": "uint256" | ||
}, | ||
{ | ||
"internalType": "uint80", | ||
"name": "answeredInRound", | ||
"type": "uint80" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "latestRoundData", | ||
"outputs": [ | ||
{ | ||
"internalType": "uint80", | ||
"name": "roundId", | ||
"type": "uint80" | ||
}, | ||
{ | ||
"internalType": "int256", | ||
"name": "answer", | ||
"type": "int256" | ||
}, | ||
{ | ||
"internalType": "uint256", | ||
"name": "startedAt", | ||
"type": "uint256" | ||
}, | ||
{ | ||
"internalType": "uint256", | ||
"name": "updatedAt", | ||
"type": "uint256" | ||
}, | ||
{ | ||
"internalType": "uint80", | ||
"name": "answeredInRound", | ||
"type": "uint80" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "version", | ||
"outputs": [ | ||
{ | ||
"internalType": "uint256", | ||
"name": "", | ||
"type": "uint256" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
} | ||
] |
122 changes: 122 additions & 0 deletions
122
warp_output/exampleContracts/chainlink/pricefeed/pricefeedExample.sol/PriceConsumerV3.cairo
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,122 @@ | ||
%lang starknet | ||
|
||
|
||
from starkware.cairo.common.cairo_builtins import HashBuiltin | ||
from starkware.cairo.common.uint256 import Uint256 | ||
from warplib.maths.external_input_check_ints import warp_external_input_check_int256 | ||
|
||
|
||
func WS_WRITE0{syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, range_check_ptr : felt}(loc: felt, value: felt) -> (res: felt){ | ||
WARP_STORAGE.write(loc, value); | ||
return (value,); | ||
} | ||
|
||
|
||
func WS0_READ_felt{syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, range_check_ptr : felt}(loc: felt) ->(val: felt){ | ||
alloc_locals; | ||
let (read0) = WARP_STORAGE.read(loc); | ||
return (read0,); | ||
} | ||
|
||
|
||
// Contract Def PriceConsumerV3 | ||
|
||
|
||
namespace PriceConsumerV3{ | ||
|
||
// Dynamic variables - Arrays and Maps | ||
|
||
// Static variables | ||
|
||
const __warp_0_priceFeed = 0; | ||
|
||
|
||
func __warp_init_PriceConsumerV3{syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, range_check_ptr : felt}()-> (){ | ||
alloc_locals; | ||
|
||
|
||
|
||
WS_WRITE0(__warp_0_priceFeed, 155680397429899150176167208149732158272590442051); | ||
|
||
|
||
|
||
return (); | ||
|
||
} | ||
|
||
} | ||
|
||
|
||
@view | ||
func getLatestPrice_8e15f473{syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, range_check_ptr : felt}()-> (__warp_1 : Uint256){ | ||
alloc_locals; | ||
|
||
|
||
|
||
let (__warp_se_0) = WS0_READ_felt(PriceConsumerV3.__warp_0_priceFeed); | ||
|
||
let (__warp_gv0, __warp_2_price, __warp_gv1, __warp_gv2, __warp_gv3) = AggregatorV3Interface_warped_interface.latestRoundData_feaf968c(__warp_se_0); | ||
|
||
warp_external_input_check_int256(__warp_2_price); | ||
|
||
|
||
|
||
return (__warp_2_price,); | ||
|
||
} | ||
|
||
|
||
@constructor | ||
func constructor{syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, range_check_ptr : felt}(){ | ||
alloc_locals; | ||
WARP_USED_STORAGE.write(1); | ||
|
||
|
||
|
||
PriceConsumerV3.__warp_init_PriceConsumerV3(); | ||
|
||
|
||
|
||
return (); | ||
|
||
} | ||
|
||
@storage_var | ||
func WARP_STORAGE(index: felt) -> (val: felt){ | ||
} | ||
@storage_var | ||
func WARP_USED_STORAGE() -> (val: felt){ | ||
} | ||
@storage_var | ||
func WARP_NAMEGEN() -> (name: felt){ | ||
} | ||
func readId{syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, range_check_ptr : felt}(loc: felt) -> (val: felt){ | ||
alloc_locals; | ||
let (id) = WARP_STORAGE.read(loc); | ||
if (id == 0){ | ||
let (id) = WARP_NAMEGEN.read(); | ||
WARP_NAMEGEN.write(id + 1); | ||
WARP_STORAGE.write(loc, id + 1); | ||
return (id + 1,); | ||
}else{ | ||
return (id,); | ||
} | ||
} | ||
|
||
|
||
// Contract Def AggregatorV3Interface@interface | ||
|
||
|
||
@contract_interface | ||
namespace AggregatorV3Interface_warped_interface{ | ||
func decimals_313ce567()-> (__warp_0 : felt){ | ||
} | ||
func description_7284e416()-> (__warp_1_len : felt, __warp_1 : felt*){ | ||
} | ||
func version_54fd4d50()-> (__warp_2 : Uint256){ | ||
} | ||
func getRoundData_9a6fc8f5(_roundId : felt)-> (roundId : felt, answer : Uint256, startedAt : Uint256, updatedAt : Uint256, answeredInRound : felt){ | ||
} | ||
func latestRoundData_feaf968c()-> (roundId : felt, answer : Uint256, startedAt : Uint256, updatedAt : Uint256, answeredInRound : felt){ | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...ut/exampleContracts/chainlink/pricefeed/pricefeedExample.sol/PriceConsumerV3_sol_abi.json
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,15 @@ | ||
[ | ||
{ | ||
"inputs": [], | ||
"name": "getLatestPrice", | ||
"outputs": [ | ||
{ | ||
"internalType": "int256", | ||
"name": "", | ||
"type": "int256" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
} | ||
] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you try installing
chainlink
inside the warp folder using npm? I think that should add the dependencies you need so you don't have to use this get around to use the interface