-
Notifications
You must be signed in to change notification settings - Fork 5
feat: Add utility to load smart contracts #77
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
base: main
Are you sure you want to change the base?
Conversation
85f2fed to
ce847af
Compare
ce847af to
3b129e6
Compare
| br#"[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"AssetIsNotSupportedForThisMethod","type":"error"},{"inputs":[],"name":"AssetNotFound","type":"error"},{"inputs":[],"name":"CallbackClientAddressShouldBeMsgSender","type":"error"},{"inputs":[],"name":"CallbackGasLimitTooHigh","type":"error"},{"inputs":[],"name":"InvalidInitialization","type":"error"},{"inputs":[],"name":"InvalidPriceFeed","type":"error"},{"inputs":[],"name":"InvalidPriceFeedData","type":"error"},{"inputs":[],"name":"InvalidQueryHash","type":"error"},{"inputs":[],"name":"InvalidQueryTimeout","type":"error"},{"inputs":[],"name":"NativePaymentFailed","type":"error"},{"inputs":[],"name":"NativeTokenCannotBeRemoved","type":"error"},{"inputs":[],"name":"NotEnoughGasToExecuteCallback","type":"error"},{"inputs":[],"name":"NotInitializing","type":"error"},{"inputs":[],"name":"OnlyQuerySourceCanCancel","type":"error"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"OwnableInvalidOwner","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"OwnableUnauthorizedAccount","type":"error"},{"inputs":[],"name":"QueryHasNotExpired","type":"error"},{"inputs":[],"name":"QueryTimeout","type":"error"},{"inputs":[],"name":"ReentrancyGuardReentrantCall","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"SafeERC20FailedOperation","type":"error"},{"inputs":[],"name":"StalePriceFeedData","type":"error"},{"inputs":[],"name":"TargetAddressCannotBeZero","type":"error"},{"inputs":[],"name":"TreasuryAddressCannotBeZero","type":"error"},{"inputs":[],"name":"TreasuryAddressSameAsCurrent","type":"error"},{"inputs":[],"name":"ValueExceedsUint248Limit","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"asset","type":"address"},{"indexed":false,"internalType":"bytes1","name":"allowedPaymentTypes","type":"bytes1"},{"indexed":false,"internalType":"address","name":"priceFeed","type":"address"},{"indexed":false,"internalType":"uint8","name":"tokenDecimals","type":"uint8"},{"indexed":false,"internalType":"uint64","name":"stalePriceThresholdInSeconds","type":"uint64"}],"name":"AssetAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"asset","type":"address"}],"name":"AssetRemoved","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"queryHash","type":"bytes32"},{"indexed":true,"internalType":"address","name":"callbackClientContractAddress","type":"address"}],"name":"CallbackFailed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"queryHash","type":"bytes32"},{"indexed":true,"internalType":"address","name":"callbackClientContractAddress","type":"address"}],"name":"CallbackSucceeded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint64","name":"version","type":"uint64"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"queryHash","type":"bytes32"},{"indexed":true,"internalType":"address","name":"asset","type":"address"},{"indexed":false,"internalType":"uint248","name":"amount","type":"uint248"},{"indexed":true,"internalType":"address","name":"source","type":"address"},{"indexed":false,"internalType":"uint248","name":"amountInUSD","type":"uint248"}],"name":"NewQueryPayment","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"queryHash","type":"bytes32"},{"indexed":true,"internalType":"address","name":"asset","type":"address"},{"indexed":true,"internalType":"address","name":"source","type":"address"},{"indexed":false,"internalType":"uint248","name":"amount","type":"uint248"}],"name":"PaymentRefunded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"queryHash","type":"bytes32"},{"indexed":false,"internalType":"uint248","name":"usedAmount","type":"uint248"},{"indexed":false,"internalType":"uint248","name":"remainingAmount","type":"uint248"}],"name":"PaymentSettled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"queryHash","type":"bytes32"},{"indexed":true,"internalType":"address","name":"caller","type":"address"}],"name":"QueryCanceled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"queryHash","type":"bytes32"}],"name":"QueryFulfilled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint248","name":"queryNonce","type":"uint248"},{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"bytes","name":"query","type":"bytes"},{"indexed":false,"internalType":"bytes","name":"queryParameters","type":"bytes"},{"indexed":false,"internalType":"uint64","name":"timeout","type":"uint64"},{"indexed":false,"internalType":"address","name":"callbackClientContractAddress","type":"address"},{"indexed":false,"internalType":"uint64","name":"callbackGasLimit","type":"uint64"},{"indexed":false,"internalType":"bytes","name":"callbackData","type":"bytes"},{"indexed":false,"internalType":"address","name":"customLogicContractAddress","type":"address"},{"indexed":false,"internalType":"bytes32","name":"queryHash","type":"bytes32"}],"name":"QueryReceived","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"asset","type":"address"},{"indexed":false,"internalType":"uint248","name":"amount","type":"uint248"},{"indexed":false,"internalType":"bytes32","name":"onBehalfOf","type":"bytes32"},{"indexed":true,"internalType":"address","name":"target","type":"address"},{"indexed":false,"internalType":"bytes","name":"memo","type":"bytes"},{"indexed":false,"internalType":"uint248","name":"amountInUSD","type":"uint248"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"SendPayment","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"treasury","type":"address"}],"name":"TreasurySet","type":"event"},{"inputs":[{"internalType":"bytes32","name":"queryHash","type":"bytes32"},{"components":[{"internalType":"bytes","name":"query","type":"bytes"},{"internalType":"bytes","name":"queryParameters","type":"bytes"},{"internalType":"uint64","name":"timeout","type":"uint64"},{"internalType":"address","name":"callbackClientContractAddress","type":"address"},{"internalType":"uint64","name":"callbackGasLimit","type":"uint64"},{"internalType":"address","name":"customLogicContractAddress","type":"address"},{"internalType":"bytes","name":"callbackData","type":"bytes"}],"internalType":"struct QueryLogic.QueryRequest","name":"queryRequest","type":"tuple"}],"name":"cancelExpiredQuery","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"queryHash","type":"bytes32"},{"components":[{"internalType":"bytes","name":"query","type":"bytes"},{"internalType":"bytes","name":"queryParameters","type":"bytes"},{"internalType":"uint64","name":"timeout","type":"uint64"},{"internalType":"address","name":"callbackClientContractAddress","type":"address"},{"internalType":"uint64","name":"callbackGasLimit","type":"uint64"},{"internalType":"address","name":"customLogicContractAddress","type":"address"},{"internalType":"bytes","name":"callbackData","type":"bytes"}],"internalType":"struct QueryLogic.QueryRequest","name":"queryRequest","type":"tuple"},{"internalType":"bytes","name":"queryResult","type":"bytes"}],"name":"fulfillQuery","outputs":[{"internalType":"uint248","name":"gasUsed","type":"uint248"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"asset","type":"address"}],"name":"getPaymentAsset","outputs":[{"components":[{"internalType":"bytes1","name":"allowedPaymentTypes","type":"bytes1"},{"internalType":"address","name":"priceFeed","type":"address"},{"internalType":"uint8","name":"tokenDecimals","type":"uint8"},{"internalType":"uint64","name":"stalePriceThresholdInSeconds","type":"uint64"}],"internalType":"struct AssetManagement.PaymentAsset","name":"paymentAsset","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getTreasury","outputs":[{"internalType":"address","name":"treasury","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"treasury","type":"address"},{"internalType":"address","name":"nativeTokenPriceFeed","type":"address"},{"internalType":"uint8","name":"nativeTokenDecimals","type":"uint8"},{"internalType":"uint64","name":"nativeTokenStalePriceThresholdInSeconds","type":"uint64"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"initialize2","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"asset","type":"address"},{"internalType":"uint248","name":"amount","type":"uint248"},{"components":[{"internalType":"bytes","name":"query","type":"bytes"},{"internalType":"bytes","name":"queryParameters","type":"bytes"},{"internalType":"uint64","name":"timeout","type":"uint64"},{"internalType":"address","name":"callbackClientContractAddress","type":"address"},{"internalType":"uint64","name":"callbackGasLimit","type":"uint64"},{"internalType":"address","name":"customLogicContractAddress","type":"address"},{"internalType":"bytes","name":"callbackData","type":"bytes"}],"internalType":"struct QueryLogic.QueryRequest","name":"queryRequest","type":"tuple"}],"name":"query","outputs":[{"internalType":"bytes32","name":"queryHash","type":"bytes32"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"asset","type":"address"}],"name":"removePaymentAsset","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"asset","type":"address"},{"internalType":"uint248","name":"amount","type":"uint248"},{"internalType":"bytes32","name":"onBehalfOf","type":"bytes32"},{"internalType":"address","name":"target","type":"address"},{"internalType":"bytes","name":"memo","type":"bytes"}],"name":"send","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"onBehalfOf","type":"bytes32"},{"internalType":"address","name":"target","type":"address"},{"internalType":"bytes","name":"memo","type":"bytes"}],"name":"sendNative","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"assetAddress","type":"address"},{"components":[{"internalType":"bytes1","name":"allowedPaymentTypes","type":"bytes1"},{"internalType":"address","name":"priceFeed","type":"address"},{"internalType":"uint8","name":"tokenDecimals","type":"uint8"},{"internalType":"uint64","name":"stalePriceThresholdInSeconds","type":"uint64"}],"internalType":"struct AssetManagement.PaymentAsset","name":"paymentAsset","type":"tuple"}],"name":"setPaymentAsset","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"treasury","type":"address"}],"name":"setTreasury","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"queryHash","type":"bytes32"},{"components":[{"internalType":"bytes","name":"query","type":"bytes"},{"internalType":"bytes","name":"queryParameters","type":"bytes"},{"internalType":"uint64","name":"timeout","type":"uint64"},{"internalType":"address","name":"callbackClientContractAddress","type":"address"},{"internalType":"uint64","name":"callbackGasLimit","type":"uint64"},{"internalType":"address","name":"customLogicContractAddress","type":"address"},{"internalType":"bytes","name":"callbackData","type":"bytes"}],"internalType":"struct QueryLogic.QueryRequest","name":"queryRequest","type":"tuple"}],"name":"validateQueryRequest","outputs":[],"stateMutability":"view","type":"function"}]"# | ||
| .to_vec(), | ||
| ) | ||
| } |
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.
These kinda seem like the kind of thing that should be in separate files and then loaded by these functions, or statically included?
| (SxtNetwork::Mainnet, SystemContract::ZkPay) => contracts::mainnet_zkpay(), | ||
| (SxtNetwork::Mainnet, SystemContract::Staking) => contracts::mainnet_staking(), | ||
| (SxtNetwork::Mainnet, SystemContract::Messaging) => contracts::mainnet_messaging(), | ||
| (SxtNetwork::Testnet, SystemContract::ZkPay) => contracts::mainnet_zkpay(), |
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.
?
| (SxtNetwork::Testnet, SystemContract::ZkPay) => contracts::mainnet_zkpay(), | |
| (SxtNetwork::Testnet, SystemContract::ZkPay) => contracts::testnet_zkpay(), |
| error!("Failed to drop tables: {}", e); | ||
| process::exit(1); | ||
| } | ||
| } |
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 mean to add drop tables in the same PR?
| name: BoundedVec(name.0.get(1)?.value.as_bytes().to_vec()), | ||
| namespace: BoundedVec(name.0.first()?.value.as_bytes().to_vec()), |
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.
maybe to_uppercase this?
| ZkPay, | ||
| } | ||
|
|
||
| pub fn get_contract(network: SxtNetwork, contract: SystemContract) -> Contract { |
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.
NIT: I'd slightly prefer for the mod.rs to not really have anything but re-exports. Maybe SxtNetwork and SystemContract could be in a keys.rs module, then get_contract could just move into the contracts module.
| staking_contract("93d176dd54FF38b08f33b4Fc62573ec80F1da185", Source::Ethereum, 22347700) | ||
| } | ||
|
|
||
| pub fn mainnet_zkpay() -> Contract { |
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.
Most of these don't need to be pub
| zkpay_contract("27d4D2AF364c1ad2eBDB2a28D6cb7B99EdE1D450", Source::Ethereum, 22427605) | ||
| } | ||
|
|
||
| pub fn messaging_contract(address: &str, source: Source, starting_block: u64) -> Contract { |
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.
it'd be nice if pub items had brief docs.
Rationale for this change
This PR introduces a new chain-utils utility to ease the creation and uploading of smart contracts and their tables to the SXT Chain.
Are these changes tested?
Yes