Skip to content
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

Integrated the SmartContractFactory #361

Merged
merged 6 commits into from
Nov 28, 2023
Merged

Conversation

popenta
Copy link
Contributor

@popenta popenta commented Nov 21, 2023

Integrated the SmartContractFactory into mxpy.

@popenta popenta self-assigned this Nov 21, 2023
@ssd04 ssd04 self-requested a review November 22, 2023 14:41
Comment on lines +219 to +229
def prepare_execute_transaction_data(function: str, arguments: List[Any]) -> TransactionPayload:
tx_data = function

for arg in arguments:
tx_data += f"@{_prepare_argument(arg)}"

return TransactionPayload.from_str(tx_data)


def prepare_args_for_factory(arguments: List[str]) -> List[Any]:
args: List[Any] = []
Copy link
Contributor

Choose a reason for hiding this comment

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

unit tests for these functions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a unit test for prepare_args_for_factory

function: str,
arguments: List[Any],
value: int = 0,
caller: Optional[Address] = None
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
caller: Optional[Address] = None
caller: Optional[IAddress] = None

?

Copy link
Contributor

Choose a reason for hiding this comment

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

and also in other places

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Replaced where possible

Comment on lines +67 to +69
class IConfig(Protocol):
chain_id: str
min_gas_limit: int
Copy link
Contributor

Choose a reason for hiding this comment

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

from what i've seen IConfig and ITokenComputer are defined also in core, i'm thinking if it might be better to reuse from core

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These are just their interfaces. In the cli_contracts.py the objects are imported from core.
Config is imported here, and used here.

@andreibancioiu andreibancioiu self-requested a review November 24, 2023 13:20
Copy link
Contributor

@andreibancioiu andreibancioiu left a comment

Choose a reason for hiding this comment

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

🙌

Some tests are failing, though (due to Testnet reset).

multiversx_sdk_cli/contracts.py Outdated Show resolved Hide resolved
multiversx_sdk_cli/localnet/genesis.py Show resolved Hide resolved
@@ -68,7 +68,7 @@ def prepare_transaction_data_for_stake(node_operator_address: Address, validator
if reward_address:
call_arguments.append(f"0x{reward_address.to_hex()}")

data = SmartContract().prepare_execute_transaction_data("stake", call_arguments)
data = prepare_execute_transaction_data("stake", call_arguments)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think in the next PR, it will use the factory for staking operations, correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not really. I think this is for legacy staking? This is within the mxpy validator command group while the delegation factory from sdk-core is used for mxpy staking-provider command group.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I mean this is used for the staking smart contract

Copy link
Contributor

@andreibancioiu andreibancioiu Nov 27, 2023

Choose a reason for hiding this comment

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

Not for legacy delegation. For the "lower-level" / "core" staking: https://docs.multiversx.com/validators/staking/staking-smart-contract/#staking.

@@ -11,3 +11,5 @@

DEFAULT_HRP = "erd"
ADDRESS_ZERO_BECH32 = "erd1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq6gq4hu"

NUMBER_OF_SHARDS = 3
Copy link
Contributor

Choose a reason for hiding this comment

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

I see it was set to 3 before, as well (hardcoded).

But it seems there were no issues when performing deploys on localnet (2 shards, by default)?

Indeed, the contract address computation algorithm does not depend on the number of shards:

https://github.com/multiversx/mx-sdk-py-core/blob/main/multiversx_sdk_core/address.py#L109

Thus, we have a slightly unfortunate design (specs) of the AddressComputer. It requires the number of shards as a parameter, but that isn't required in all circumstances.

Can stay as it is 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed the number_of_shards is not used to compute the contract address, added it to be more explicit, but it can be deleted since the default value is already 3. Let me know what you think.

def __init__(self, config: IConfig, token_computer: ITokenComputer):
self._factory = SmartContractTransactionsFactory(config, token_computer)

def get_deploy_transaction(self, owner: Account, args: Any) -> Transaction:
Copy link
Contributor

Choose a reason for hiding this comment

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

Makes quite a few assumptions about the content of args. Separate parameters (e.g. gasLimit, bytecode and so on) would work as well.

Can also stay as it is (this PR), since, as far as I see, SmartContract is only used by cli_contracts, correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it's only used by cli_contracts.py. I thought it's a little bit "cleaner" to use args since gasLimit, bytecode and so on are required arguments, and we also check for the nonce and chainID args.

multiversx_sdk_cli/contracts.py Outdated Show resolved Hide resolved
multiversx_sdk_cli/contracts.py Show resolved Hide resolved
multiversx_sdk_cli/contracts.py Show resolved Hide resolved
multiversx_sdk_cli/contracts.py Show resolved Hide resolved
@popenta popenta merged commit 210082e into feat/next Nov 28, 2023
9 checks passed
@popenta popenta deleted the integrate-sc-factory branch November 28, 2023 15:00
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.

4 participants