Skip to content

Conversation

@AdaJane-SxT
Copy link
Contributor

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

@AdaJane-SxT AdaJane-SxT requested review from a team as code owners September 22, 2025 15:38
@github-actions
Copy link

github-actions bot commented Sep 22, 2025

1.34.0

Features

  • Add support for drop_tables and the faster staking contract in (3b129e6
  • Add utility to load smart contracts (4516878

@AdaJane-SxT AdaJane-SxT force-pushed the feat/load-smartcontracts branch 2 times, most recently from 85f2fed to ce847af Compare September 24, 2025 15:47
@AdaJane-SxT AdaJane-SxT force-pushed the feat/load-smartcontracts branch from ce847af to 3b129e6 Compare October 1, 2025 15:22
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(),
)
}
Copy link
Contributor

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(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Suggested change
(SxtNetwork::Testnet, SystemContract::ZkPay) => contracts::mainnet_zkpay(),
(SxtNetwork::Testnet, SystemContract::ZkPay) => contracts::testnet_zkpay(),

error!("Failed to drop tables: {}", e);
process::exit(1);
}
}
Copy link
Contributor

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?

Comment on lines +62 to +63
name: BoundedVec(name.0.get(1)?.value.as_bytes().to_vec()),
namespace: BoundedVec(name.0.first()?.value.as_bytes().to_vec()),
Copy link
Contributor

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 {
Copy link
Contributor

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 {
Copy link
Contributor

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 {
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants