Skip to content

Commit

Permalink
feat(evm-oracle): add Solidity contract that we can use to expose the…
Browse files Browse the repository at this point in the history
… Nibiru Oracle in the ChainLink interface
  • Loading branch information
Unique-Divine committed Jan 7, 2025
1 parent 7aebf75 commit b22338b
Show file tree
Hide file tree
Showing 9 changed files with 2,247 additions and 196 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
{
"_format": "hh-sol-artifact-1",
"contractName": "AggregatorV3Interface",
"sourceName": "@chainlink/contracts/src/v0.8/shared/interfaces/AggregatorV3Interface.sol",
"abi": [
{
"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"
}
],
"bytecode": "0x",
"deployedBytecode": "0x",
"linkReferences": {},
"deployedLinkReferences": {}
}
39 changes: 39 additions & 0 deletions x/evm/embeds/artifacts/contracts/IOracle.sol/IOracle.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,45 @@
"contractName": "IOracle",
"sourceName": "contracts/IOracle.sol",
"abi": [
{
"inputs": [
{
"internalType": "string",
"name": "pair",
"type": "string"
}
],
"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": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
{
"_format": "hh-sol-artifact-1",
"contractName": "OracleChainLinkLike",
"sourceName": "contracts/OracleChainLinkLike.sol",
"abi": [
{
"inputs": [
{
"internalType": "string",
"name": "_pair",
"type": "string"
}
],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"inputs": [],
"name": "decimals",
"outputs": [
{
"internalType": "uint8",
"name": "",
"type": "uint8"
}
],
"stateMutability": "pure",
"type": "function"
},
{
"inputs": [],
"name": "description",
"outputs": [
{
"internalType": "string",
"name": "",
"type": "string"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint80",
"name": "",
"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": "pair",
"outputs": [
{
"internalType": "string",
"name": "",
"type": "string"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "version",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "pure",
"type": "function"
}
],
"bytecode": "0x60806040523480156200001157600080fd5b5060405162000e0838038062000e088339818101604052810190620000379190620001e3565b80600090816200004891906200047f565b505062000566565b6000604051905090565b600080fd5b600080fd5b600080fd5b600080fd5b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b620000b9826200006e565b810181811067ffffffffffffffff82111715620000db57620000da6200007f565b5b80604052505050565b6000620000f062000050565b9050620000fe8282620000ae565b919050565b600067ffffffffffffffff8211156200012157620001206200007f565b5b6200012c826200006e565b9050602081019050919050565b60005b83811015620001595780820151818401526020810190506200013c565b60008484015250505050565b60006200017c620001768462000103565b620000e4565b9050828152602081018484840111156200019b576200019a62000069565b5b620001a884828562000139565b509392505050565b600082601f830112620001c857620001c762000064565b5b8151620001da84826020860162000165565b91505092915050565b600060208284031215620001fc57620001fb6200005a565b5b600082015167ffffffffffffffff8111156200021d576200021c6200005f565b5b6200022b84828501620001b0565b91505092915050565b600081519050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b600060028204905060018216806200028757607f821691505b6020821081036200029d576200029c6200023f565b5b50919050565b60008190508160005260206000209050919050565b60006020601f8301049050919050565b600082821b905092915050565b600060088302620003077fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff82620002c8565b620003138683620002c8565b95508019841693508086168417925050509392505050565b6000819050919050565b6000819050919050565b6000620003606200035a62000354846200032b565b62000335565b6200032b565b9050919050565b6000819050919050565b6200037c836200033f565b620003946200038b8262000367565b848454620002d5565b825550505050565b600090565b620003ab6200039c565b620003b881848462000371565b505050565b5b81811015620003e057620003d4600082620003a1565b600181019050620003be565b5050565b601f8211156200042f57620003f981620002a3565b6200040484620002b8565b8101602085101562000414578190505b6200042c6200042385620002b8565b830182620003bd565b50505b505050565b600082821c905092915050565b6000620004546000198460080262000434565b1980831691505092915050565b60006200046f838362000441565b9150826002028217905092915050565b6200048a8262000234565b67ffffffffffffffff811115620004a657620004a56200007f565b5b620004b282546200026e565b620004bf828285620003e4565b600060209050601f831160018114620004f75760008415620004e2578287015190505b620004ee858262000461565b8655506200055e565b601f1984166200050786620002a3565b60005b8281101562000531578489015182556001820191506020850194506020810190506200050a565b868310156200055157848901516200054d601f89168262000441565b8355505b6001600288020188555050505b505050505050565b61089280620005766000396000f3fe608060405234801561001057600080fd5b50600436106100625760003560e01c8063313ce5671461006757806354fd4d50146100855780637284e416146100a35780639a6fc8f5146100c1578063a8aa1b31146100f5578063feaf968c14610113575b600080fd5b61006f610135565b60405161007c9190610347565b60405180910390f35b61008d61013e565b60405161009a919061037b565b60405180910390f35b6100ab610147565b6040516100b89190610426565b60405180910390f35b6100db60048036038101906100d6919061048f565b61016f565b6040516100ec9594939291906104e4565b60405180910390f35b6100fd610207565b60405161010a9190610426565b60405180910390f35b61011b610295565b60405161012c9594939291906104e4565b60405180910390f35b60006008905090565b60006001905090565b6060600060405160200161015b91906106ac565b604051602081830303815290604052905090565b600080600080600061080173ffffffffffffffffffffffffffffffffffffffff166333f98c7760006040518263ffffffff1660e01b81526004016101b39190610752565b60a060405180830381865afa1580156101d0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101f491906107e1565b9450945094509450945091939590929450565b60008054610214906105e3565b80601f0160208091040260200160405190810160405280929190818152602001828054610240906105e3565b801561028d5780601f106102625761010080835404028352916020019161028d565b820191906000526020600020905b81548152906001019060200180831161027057829003601f168201915b505050505081565b600080600080600061080173ffffffffffffffffffffffffffffffffffffffff166333f98c7760006040518263ffffffff1660e01b81526004016102d99190610752565b60a060405180830381865afa1580156102f6573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061031a91906107e1565b945094509450945094509091929394565b600060ff82169050919050565b6103418161032b565b82525050565b600060208201905061035c6000830184610338565b92915050565b6000819050919050565b61037581610362565b82525050565b6000602082019050610390600083018461036c565b92915050565b600081519050919050565b600082825260208201905092915050565b60005b838110156103d05780820151818401526020810190506103b5565b60008484015250505050565b6000601f19601f8301169050919050565b60006103f882610396565b61040281856103a1565b93506104128185602086016103b2565b61041b816103dc565b840191505092915050565b6000602082019050818103600083015261044081846103ed565b905092915050565b600080fd5b600069ffffffffffffffffffff82169050919050565b61046c8161044d565b811461047757600080fd5b50565b60008135905061048981610463565b92915050565b6000602082840312156104a5576104a4610448565b5b60006104b38482850161047a565b91505092915050565b6104c58161044d565b82525050565b6000819050919050565b6104de816104cb565b82525050565b600060a0820190506104f960008301886104bc565b61050660208301876104d5565b610513604083018661036c565b610520606083018561036c565b61052d60808301846104bc565b9695505050505050565b600081905092915050565b7f4e6962697275204f7261636c6520436861696e4c696e6b2d6c696b652070726960008201527f6365206665656420666f72200000000000000000000000000000000000000000602082015250565b600061059e602c83610537565b91506105a982610542565b602c82019050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b600060028204905060018216806105fb57607f821691505b60208210810361060e5761060d6105b4565b5b50919050565b60008190508160005260206000209050919050565b60008154610636816105e3565b6106408186610537565b9450600182166000811461065b5760018114610670576106a3565b60ff19831686528115158202860193506106a3565b61067985610614565b60005b8381101561069b5781548189015260018201915060208101905061067c565b838801955050505b50505092915050565b60006106b782610591565b91506106c38284610629565b915081905092915050565b600081546106db816105e3565b6106e581866103a1565b94506001821660008114610700576001811461071657610749565b60ff198316865281151560200286019350610749565b61071f85610614565b60005b8381101561074157815481890152600182019150602081019050610722565b808801955050505b50505092915050565b6000602082019050818103600083015261076c81846106ce565b905092915050565b60008151905061078381610463565b92915050565b610792816104cb565b811461079d57600080fd5b50565b6000815190506107af81610789565b92915050565b6107be81610362565b81146107c957600080fd5b50565b6000815190506107db816107b5565b92915050565b600080600080600060a086880312156107fd576107fc610448565b5b600061080b88828901610774565b955050602061081c888289016107a0565b945050604061082d888289016107cc565b935050606061083e888289016107cc565b925050608061084f88828901610774565b915050929550929590935056fea26469706673582212203d026629d5410603909fa02a7f16b59174b603ec3934c5f963d443df76fe037564736f6c63430008180033",
"deployedBytecode": "0x608060405234801561001057600080fd5b50600436106100625760003560e01c8063313ce5671461006757806354fd4d50146100855780637284e416146100a35780639a6fc8f5146100c1578063a8aa1b31146100f5578063feaf968c14610113575b600080fd5b61006f610135565b60405161007c9190610347565b60405180910390f35b61008d61013e565b60405161009a919061037b565b60405180910390f35b6100ab610147565b6040516100b89190610426565b60405180910390f35b6100db60048036038101906100d6919061048f565b61016f565b6040516100ec9594939291906104e4565b60405180910390f35b6100fd610207565b60405161010a9190610426565b60405180910390f35b61011b610295565b60405161012c9594939291906104e4565b60405180910390f35b60006008905090565b60006001905090565b6060600060405160200161015b91906106ac565b604051602081830303815290604052905090565b600080600080600061080173ffffffffffffffffffffffffffffffffffffffff166333f98c7760006040518263ffffffff1660e01b81526004016101b39190610752565b60a060405180830381865afa1580156101d0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101f491906107e1565b9450945094509450945091939590929450565b60008054610214906105e3565b80601f0160208091040260200160405190810160405280929190818152602001828054610240906105e3565b801561028d5780601f106102625761010080835404028352916020019161028d565b820191906000526020600020905b81548152906001019060200180831161027057829003601f168201915b505050505081565b600080600080600061080173ffffffffffffffffffffffffffffffffffffffff166333f98c7760006040518263ffffffff1660e01b81526004016102d99190610752565b60a060405180830381865afa1580156102f6573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061031a91906107e1565b945094509450945094509091929394565b600060ff82169050919050565b6103418161032b565b82525050565b600060208201905061035c6000830184610338565b92915050565b6000819050919050565b61037581610362565b82525050565b6000602082019050610390600083018461036c565b92915050565b600081519050919050565b600082825260208201905092915050565b60005b838110156103d05780820151818401526020810190506103b5565b60008484015250505050565b6000601f19601f8301169050919050565b60006103f882610396565b61040281856103a1565b93506104128185602086016103b2565b61041b816103dc565b840191505092915050565b6000602082019050818103600083015261044081846103ed565b905092915050565b600080fd5b600069ffffffffffffffffffff82169050919050565b61046c8161044d565b811461047757600080fd5b50565b60008135905061048981610463565b92915050565b6000602082840312156104a5576104a4610448565b5b60006104b38482850161047a565b91505092915050565b6104c58161044d565b82525050565b6000819050919050565b6104de816104cb565b82525050565b600060a0820190506104f960008301886104bc565b61050660208301876104d5565b610513604083018661036c565b610520606083018561036c565b61052d60808301846104bc565b9695505050505050565b600081905092915050565b7f4e6962697275204f7261636c6520436861696e4c696e6b2d6c696b652070726960008201527f6365206665656420666f72200000000000000000000000000000000000000000602082015250565b600061059e602c83610537565b91506105a982610542565b602c82019050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b600060028204905060018216806105fb57607f821691505b60208210810361060e5761060d6105b4565b5b50919050565b60008190508160005260206000209050919050565b60008154610636816105e3565b6106408186610537565b9450600182166000811461065b5760018114610670576106a3565b60ff19831686528115158202860193506106a3565b61067985610614565b60005b8381101561069b5781548189015260018201915060208101905061067c565b838801955050505b50505092915050565b60006106b782610591565b91506106c38284610629565b915081905092915050565b600081546106db816105e3565b6106e581866103a1565b94506001821660008114610700576001811461071657610749565b60ff198316865281151560200286019350610749565b61071f85610614565b60005b8381101561074157815481890152600182019150602081019050610722565b808801955050505b50505092915050565b6000602082019050818103600083015261076c81846106ce565b905092915050565b60008151905061078381610463565b92915050565b610792816104cb565b811461079d57600080fd5b50565b6000815190506107af81610789565b92915050565b6107be81610362565b81146107c957600080fd5b50565b6000815190506107db816107b5565b92915050565b600080600080600060a086880312156107fd576107fc610448565b5b600061080b88828901610774565b955050602061081c888289016107a0565b945050604061082d888289016107cc565b935050606061083e888289016107cc565b925050608061084f88828901610774565b915050929550929590935056fea26469706673582212203d026629d5410603909fa02a7f16b59174b603ec3934c5f963d443df76fe037564736f6c63430008180033",
"linkReferences": {},
"deployedLinkReferences": {}
}
15 changes: 15 additions & 0 deletions x/evm/embeds/contracts/IOracle.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;

// import "@chainlink/contracts/src/v0.8/shared/interfaces/AggregatorV3Interface.sol";

/// @notice Oracle interface for querying exchange rates
interface IOracle {
/// @notice Queries the dated exchange rate for a given pair
Expand All @@ -17,6 +19,19 @@ interface IOracle {
external
view
returns (uint256 price, uint64 blockTimeMs, uint64 blockHeight);

function latestRoundData(
string memory pair
)
external
view
returns (
uint80 roundId,
int256 answer,
uint256 startedAt,
uint256 updatedAt,
uint80 answeredInRound
);
}

address constant ORACLE_PRECOMPILE_ADDRESS = 0x0000000000000000000000000000000000000801;
Expand Down
Loading

0 comments on commit b22338b

Please sign in to comment.