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

SRC14 add proxy_target() #110

Merged
merged 4 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Description of the upcoming release here.
### Added

- [#107](https://github.com/FuelLabs/sway-standards/pull/107) Adds the `proxy_owner()` function to the SRC-14 standard.
- [#110](https://github.com/FuelLabs/sway-standards/pull/110) Adds the `proxy_target()` function to the SRC-14 standard.
- Something new here 2

### Changed
Expand All @@ -25,5 +26,13 @@ Description of the upcoming release here.

#### Breaking

- Some breaking change here 1
- Some breaking change here 2
- [#110](https://github.com/FuelLabs/sway-standards/pull/110) Breaks the `SRC14` abi by adding the `proxy_target()` function. This will need to be added to any SRC14 implementation. The new abi is as follows:

```sway
abi SRC14 {
#[storage(read, write)]
fn set_proxy_target(new_target: ContractId);
#[storage(read)]
fn proxy_target() -> Option<ContractId>;
}
```
8 changes: 7 additions & 1 deletion docs/src/src-14-simple-upgradeable-proxies.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,13 @@ The following functions MUST be implemented by a proxy contract to follow the SR

#### `fn set_proxy_target(new_target: ContractId);`

If a valid call is made to this function it MUST change the target address of the proxy to `new_target`.
If a valid call is made to this function it MUST change the target contract of the proxy to `new_target`.
This method SHOULD implement access controls such that the target can only be changed by a user that possesses the right permissions (typically the proxy owner).

#### `fn proxy_target() -> Option<ContractId>;`

This function MUST return the target contract of the proxy as `Some`. If no proxy is set then `None` MUST be returned.

### Optional Public Functions

The following functions are RECOMMENDED to be implemented by a proxy contract to follow the SRC-14 standard:
Expand Down Expand Up @@ -73,6 +77,8 @@ Use of the [SRC-5; Ownership Standard](./src-5-ownership.md) is discouraged. If
abi SRC14 {
#[storage(read, write)]
fn set_proxy_target(new_target: ContractId);
#[storage(read)]
fn proxy_target() -> Option<ContractId>;
}

abi SRC14Extension {
Expand Down
5 changes: 5 additions & 0 deletions examples/src14-simple-proxy/minimal/src/minimal.sw
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ impl SRC14 for Contract {
fn set_proxy_target(new_target: ContractId) {
storage.target.write(new_target);
}

#[storage(read)]
fn proxy_target() -> Option<ContractId> {
storage.target.try_read()
}
}

#[fallback]
Expand Down
5 changes: 5 additions & 0 deletions examples/src14-simple-proxy/owned/src/owned.sw
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ impl SRC14 for Contract {
only_owner();
storage.target.write(new_target);
}

#[storage(read)]
fn proxy_target() -> Option<ContractId> {
storage.target.try_read()
}
}

impl SRC14Extension for Contract {
Expand Down
21 changes: 20 additions & 1 deletion standards/src/src14.sw
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ library;
use ::src5::State;

abi SRC14 {
/// Change the target address of a proxy contract.
/// Change the target contract of a proxy contract.
///
/// # Arguments
///
Expand All @@ -22,6 +22,25 @@ abi SRC14 {
/// ```
#[storage(read, write)]
fn set_proxy_target(new_target: ContractId);

/// Returns the target contract of a proxy contract.
///
/// # Returns
///
/// * [Option<ContractId>] - The new proxy contract to which all fallback calls will be passed or `None`.
///
/// # Examples
///
/// ```sway
/// use src14::SRC14;
///
/// fn foo(contract_id: ContractId) {
/// let contract_abi = abi(SRC14, contract_id.bits());
/// let target_contract: Option<ContractId> = contract_abi.proxy_target();
/// }
/// ```
#[storage(read)]
fn proxy_target() -> Option<ContractId>;
}

abi SRC14Extension {
Expand Down
Loading