-
Notifications
You must be signed in to change notification settings - Fork 267
feat: Add global contract support (NEP-591) #1369
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
Conversation
Implements both low-level FFI bindings and high-level Promise APIs for NEAR's global contract functionality, enabling cost-effective factory contract patterns. Changes: - Add 4 new host function bindings in near-sys - Extend Promise struct with chainable global contract methods - Add factory-contract-global example with comprehensive tests - Support multisig factories, business onboarding, and DeFi templates Addresses: #1365 Bounty: https://nearn.io/devhub/14/ NEP-591: https://github.com/near/NEPs/blob/master/neps/nep-0591.md
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #1369 +/- ##
==========================================
+ Coverage 80.63% 80.75% +0.11%
==========================================
Files 104 104
Lines 15457 15462 +5
==========================================
+ Hits 12464 12486 +22
+ Misses 2993 2976 -17 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
To ensure compatibility with older near-sandbox versions that don't support global contracts, gate all global contract functionality behind a 'global-contracts' feature flag. Changes: - Add 'global-contracts' feature flag to near-sdk and near-sys - Gate FFI bindings in near-sys behind feature flag - Gate env.rs functions behind feature flag - Gate Promise API methods and actions behind feature flag - Gate mock implementations behind feature flag - Update factory-contract-global example to use feature flag This prevents build failures in other examples when using older near-sandbox versions that lack global contract support.
Add fallback match arms for DeployGlobalContract and UseGlobalContract variants when the 'global-contracts' feature is not enabled. This prevents compilation errors due to non-exhaustive pattern matching when the feature flag is disabled but the upstream MockAction enum still contains these variants. The fallback cases panic with a helpful error message indicating that the 'global-contracts' feature flag is required.
- Add tests for Promise global contract methods (deploy_global_contract, use_global_contract, etc.) - Add tests for MockAction global contract variants and receipt_index() method - Add tests for LogicMockAction conversion with proper type handling - Add panic tests for global contract fallback when feature is disabled - All tests are properly feature-gated with #[cfg(feature = "global-contracts")] - Tests verify correct action creation and proper error handling
|
@r-near The implementation looks great! I only left a couple of comments in the contract-factory-global example. |
- Replace Vec<u8> with Base64VecU8 for code parameters to follow best practices - Use CryptoHash type for storing deployed contract hashes - Return Base58CryptoHash from get_global_contract_hash instead of raw bytes - Use env::attached_deposit() instead of explicit amount parameters - Fix type conversions and test compilation issues
|
I'm waiting for the nearcore release to testnet, and once it is there, I'll merge this PR, and once it is live on mainnet, I'll cut the next release for near-sdk |
|
Looking forward to see this merged @frol @r-near . It works great, I've tested all of it here: petersalomonsen/session_vault_factory#1 ( used the sandbox build for 2.7.0 btw ) |
Glad that it works for you! We still need to get the dependencies sorted out, but once those are published, I'll update the PR to use the new versions. |
…ion of near-sdk-rs will break contracts testing since near-workspaces-rs does not support latest nearcore 2.7.0+ and as such global contract host functions are not supported
…ract down to 0.01 NEAR
…for global contract deployments and usage
frol
left a comment
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.
@race-of-sloths score 8
|
@r-near Thank you for your contribution! Your pull request is now a part of the Race of Sloths! Current status: executed
Your contribution is much appreciated with a final score of 8! @frol received 25 Sloth Points for reviewing and scoring this pull request. Congratulations @r-near! Your PR was highly scored and you completed another monthly streak! To keep your monthly streak make another pull request next month and get 8+ score for it What is the Race of SlothsRace of Sloths is a friendly competition where you can participate in challenges and compete with other open-source contributors within your normal workflow For contributors:
For maintainers:
Feel free to check our website for additional details! Bot commands
|
Summary
Implements support for NEAR's global contract functionality (NEP-591) in near-sdk-rs, adding both low-level FFI bindings and high-level Promise APIs.
This addresses issue #1365 and implements the bounty requirements for global contract support.
Changes
Low-level API (near-sys):
promise_batch_action_deploy_global_contractpromise_batch_action_deploy_global_contract_by_account_idpromise_batch_action_use_global_contractpromise_batch_action_use_global_contract_by_account_idHigh-level API (near-sdk):
Promisestruct with chainable global contract methodsenv.rsFeature Gating:
global-contractsfeature flagnear-sdk = { features = ["global-contracts"] }Example & Tests:
factory-contract-globalexample demonstrating:Use Cases (from NEP-591)
This PR cannot be merged yet due to runtime dependencies:
Current Status
Required Release Order
Current Workarounds
This PR uses git branch dependencies in
Cargo.toml:These must be removed before merging once proper crate versions are available.
Test Plan
Links