Skip to content

feat(global-deployer): gd_init() method - #340

Merged
mitinarseny merged 7 commits into
mainfrom
feat/gd-init
Aug 8, 2026
Merged

feat(global-deployer): gd_init() method#340
mitinarseny merged 7 commits into
mainfrom
feat/gd-init

Conversation

@mitinarseny

@mitinarseny mitinarseny commented Aug 8, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • New Features

    • Added client bindings for global deployment approval, deployment, ownership transfer, and state queries.
    • Added structured deployment events and approval reasons.
    • Added explicit global deployer initialization support.
  • Improvements

    • Simplified integration with generated contract clients and argument types.
    • Renamed Outlayer application events to OaEvent.
  • Bug Fixes

    • Improved error handling for authorization, invalid hashes, payment requirements, and self-transfers.

@coderabbitai

coderabbitai Bot commented Aug 8, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@mitinarseny, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 20 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 3d66dc06-6209-45a9-b38d-6ca2808d9ed8

📥 Commits

Reviewing files that changed from the base of the PR and between 968b3ec and e78d103.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (7)
  • contracts/global-deployer/Cargo.toml
  • contracts/global-deployer/README.md
  • contracts/global-deployer/src/state.rs
  • contracts/outlayer/app/src/contract.rs
  • contracts/wallet/README.md
  • crates/borsh-utils/src/lib.rs
  • crates/serde-utils/src/hex.rs
📝 Walkthrough

Walkthrough

The PR consolidates GlobalDeployer functionality in defuse-global-deployer, adds feature-gated contract and client APIs, removes the former core crate, updates sandbox and CLI integrations, and renames the Outlayer application event type.

Changes

Global Deployer modularization

Layer / File(s) Summary
Public API and crate packaging
Cargo.toml, contracts/global-deployer/Cargo.toml, contracts/global-deployer/src/{lib.rs,state.rs,error.rs,events.rs,client.rs,contract.rs}
The workspace and crate now use feature-gated dependencies. The crate exports typed errors, events, state, client bindings, and the GlobalDeployer contract interface.
Contract initialization and deployment flow
contracts/global-deployer/src/contract.rs
The contract adds gd_init, typed validation errors, deployment receipt construction, post-deployment processing, refunds, ownership transfer, and approval handling.
CLI, sandbox, and integration updates
contracts/global-deployer/near-gds/*, crates/testing/sandbox/*, tests/src/tests/global_deployer/mod.rs
The CLI, sandbox extension, and tests use the consolidated crate, generated clients, typed arguments, new events, and typed errors.

Outlayer event rename

Layer / File(s) Summary
Outlayer event references
contracts/outlayer/app/src/{contract.rs,events.rs}, tests/src/tests/outlayer_app/mod.rs
The public event enum is renamed from OutlayerAppEvent to OaEvent, and contract emissions and test assertions use the new name.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Sandbox
  participant GlobalDeployerContractClient
  participant GlobalDeployer
  participant State
  Sandbox->>GlobalDeployerContractClient: Build approval and deployment actions
  GlobalDeployerContractClient->>GlobalDeployer: gd_approve and gd_deploy
  GlobalDeployer->>State: Validate and update approval state
  GlobalDeployer->>GlobalDeployer: Execute deployment callback
  GlobalDeployer->>State: Store deployed hash and clear approval
Loading

Possibly related PRs

  • near/intents#208: Refactors and relocates the same GlobalDeployer crate, interfaces, sandbox extension, and tests.
  • near/intents#216: Refactors the GlobalDeployer approval and deployment APIs, state, errors, events, clients, and tests.
  • near/intents#310: Refactors the GlobalDeployer core and near-gds crates and their workspace, state, CLI, and sandbox integrations.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately identifies the added gd_init() method, which is a substantive part of the global deployer changes.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/gd-init

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (4)
contracts/global-deployer/src/client.rs (2)

38-43: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Remove the blank line between the doc comment and the struct.

Line 39 separates the doc comment from GdTransferOwnershipArgs. Keep the doc comment adjacent to the item for consistency with GdApproveArgs.

♻️ Proposed change
 /// Arguments for [`gd_transfer_ownership()`](GlobalDeployerContract::gd_transfer_ownership) method
-
 #[derive(Serialize, Deserialize)]
 pub struct GdTransferOwnershipArgs<'a> {
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@contracts/global-deployer/src/client.rs` around lines 38 - 43, Remove the
blank line between the doc comment and the GdTransferOwnershipArgs declaration,
keeping the comment directly adjacent to the struct as done for GdApproveArgs.

11-26: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider adding a gd_init binding.

The contract exposes gd_init as a payable init method. The client omits it, so tests/src/tests/global_deployer/mod.rs line 171 calls it through a raw FunctionCall::new("gd_init") with a string literal. A generated binding removes the string literal and keeps the deposit requirement documented in one place.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@contracts/global-deployer/src/client.rs` around lines 11 - 26, Add a payable
gd_init method binding to the GlobalDeployerContract trait alongside the other
call methods, matching the contract’s initialization signature and deposit
requirement. Update the related test to invoke gd_init through the generated
client method instead of a raw FunctionCall string literal.
contracts/global-deployer/src/contract.rs (1)

66-85: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Document the ownership lock risk and align the terminology.

gd_init sets the owner to the current account ID. If the caller does not transfer ownership in the same receipt and then deletes the access keys, no external account can call gd_approve or gd_transfer_ownership. The account is then permanently locked. The test at tests/src/tests/global_deployer/mod.rs lines 165-184 performs the transfer and the key deletion in one transaction, so the recommended flow works.

State this consequence in the doc comment. Line 66 also says "admin", while the rest of the API uses "owner". Use "owner".

📝 Proposed doc change
-        /// Initialize a global deployer on the existing account and set admin to current account ID.
+        /// Initialize a global deployer on the existing account and set the owner to the current
+        /// account ID.
         ///
         /// It's recommended to call this method in the same receipt right after `UseGlobalContract` action.
+        /// Transfer the ownership in the same receipt. If the ownership stays with this account and
+        /// all access keys are deleted, no account can call `gd_approve()` or
+        /// `gd_transfer_ownership()` anymore.
         /// Requires exactly 1yN attached.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@contracts/global-deployer/src/contract.rs` around lines 66 - 85, Update the
gd_init doc comment to call the initialized account ID the “owner” instead of
“admin,” and document that failing to transfer ownership in the same receipt
before deleting access keys permanently locks the account because no external
account can call gd_approve or gd_transfer_ownership. Preserve the existing
recommended same-receipt flow guidance.
tests/src/tests/global_deployer/mod.rs (1)

154-226: 🔒 Security & Privacy | 🔵 Trivial | ⚡ Quick win

Add negative coverage for gd_init.

The test covers the success path only. gd_init carries two guards that no test exercises:

  1. The 1yN requirement, which rejects function-call access keys.
  2. The #[init] re-initialization guard, which must stop a second gd_init from resetting the owner.

Guard 2 is the security-relevant one. A test that calls gd_init again after ownership transfer proves that an attacker cannot reclaim ownership.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/src/tests/global_deployer/mod.rs` around lines 154 - 226, Extend
test_gd_init with negative coverage for both gd_init guards: attempt
initialization using a function-call access key and assert rejection, then
invoke gd_init a second time after gd_transfer_ownership and assert it fails
while gd_owner_id remains the original root account. Reuse the existing
DeployerEnv setup and transaction helpers, preserving the current successful
initialization and deployment assertions.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@contracts/global-deployer/src/lib.rs`:
- Around line 5-6: Update the public documentation references in state.rs,
error.rs, and events.rs that link to crate::contract::GlobalDeployer, replacing
them with conditional links or plain code text so documentation resolves when
near-contract is disabled. Leave the contract module gating unchanged.

In `@contracts/global-deployer/src/state.rs`:
- Line 85: Update the digest-gated doctest import near the cfg(feature =
"digest") section to import State from the public defuse_global_deployer crate
instead of defuse_global_deployer_core, ensuring the example resolves within the
consolidated crate.

---

Nitpick comments:
In `@contracts/global-deployer/src/client.rs`:
- Around line 38-43: Remove the blank line between the doc comment and the
GdTransferOwnershipArgs declaration, keeping the comment directly adjacent to
the struct as done for GdApproveArgs.
- Around line 11-26: Add a payable gd_init method binding to the
GlobalDeployerContract trait alongside the other call methods, matching the
contract’s initialization signature and deposit requirement. Update the related
test to invoke gd_init through the generated client method instead of a raw
FunctionCall string literal.

In `@contracts/global-deployer/src/contract.rs`:
- Around line 66-85: Update the gd_init doc comment to call the initialized
account ID the “owner” instead of “admin,” and document that failing to transfer
ownership in the same receipt before deleting access keys permanently locks the
account because no external account can call gd_approve or
gd_transfer_ownership. Preserve the existing recommended same-receipt flow
guidance.

In `@tests/src/tests/global_deployer/mod.rs`:
- Around line 154-226: Extend test_gd_init with negative coverage for both
gd_init guards: attempt initialization using a function-call access key and
assert rejection, then invoke gd_init a second time after gd_transfer_ownership
and assert it fails while gd_owner_id remains the original root account. Reuse
the existing DeployerEnv setup and transaction helpers, preserving the current
successful initialization and deployment assertions.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: f68e7cde-cd0d-4dd8-8b57-7a6a50e320c3

📥 Commits

Reviewing files that changed from the base of the PR and between e34d819 and 968b3ec.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (17)
  • Cargo.toml
  • contracts/global-deployer/Cargo.toml
  • contracts/global-deployer/near-gds/Cargo.toml
  • contracts/global-deployer/near-gds/src/main.rs
  • contracts/global-deployer/src/client.rs
  • contracts/global-deployer/src/contract.rs
  • contracts/global-deployer/src/error.rs
  • contracts/global-deployer/src/events.rs
  • contracts/global-deployer/src/lib.rs
  • contracts/global-deployer/src/state.rs
  • contracts/outlayer/app/src/contract.rs
  • contracts/outlayer/app/src/events.rs
  • crates/global-deployer/core/Cargo.toml
  • crates/testing/sandbox/Cargo.toml
  • crates/testing/sandbox/src/extensions/global_deployer.rs
  • tests/src/tests/global_deployer/mod.rs
  • tests/src/tests/outlayer_app/mod.rs
💤 Files with no reviewable changes (1)
  • crates/global-deployer/core/Cargo.toml

Comment thread contracts/global-deployer/src/lib.rs
Comment thread contracts/global-deployer/src/state.rs
@mitinarseny
mitinarseny merged commit 773b1c5 into main Aug 8, 2026
3 checks passed
@mitinarseny
mitinarseny deleted the feat/gd-init branch August 8, 2026 12:52
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.

1 participant