Hello again!
Recently I have been thinking about global variables in Move. Some time ago it was proposed, that there could be a convenience variable to get the deployer’s address, and store global singletons there (Any notion of global variables?).
However, I was thinking, because of Move’s transaction script structure, what if ditching globals alltogether?
I mean, that transaction script could point to a account with a configuration resource.
By designing your smart contract like this, you would automatically add a layer of configurability.
Let’s say you have an auction smart contract X. and an admin has created a configuration to account A. Then B could issue a transaction script to bid on C’s resource like this:
X.place_bid(A, C, 1234);
By accepting parameters (such as C and the amount 1234), a transaction script could trivially hide the selection of the configuration. This depends, how flexible the final script implementation is in terms of arguments to main(), but the transaction script could look like this (quick mock-up):
script {
use 0xFF::X;
const CONF: address = 0xCOFFEE;
fun main(a: address, amount: XUS) {
X.place_bid(CONF, a, amount);
}
}
The multiple configuration setting could be part of the design, like with Uniswap, which lets anyone to create markets, or admins (if any) could grant permissions to create configurations.
This would provide flexibility in the future, and make “global” variables obsolete.
What do you think?
Best regards,
Ville