Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
SwayStar123 committed Sep 10, 2024
1 parent 29986f1 commit d467526
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Description of the upcoming release here.
- [#149](https://github.com/FuelLabs/sway-standards/pull/149) Adds `Eq` implementation to SRC-5's `AccessError` error.
- [#149](https://github.com/FuelLabs/sway-standards/pull/149) Adds check functions and `Eq` implementation to SRC-5's `State` type and SRC-10's `DepositType` type.
- [#149](https://github.com/FuelLabs/sway-standards/pull/149) Adds struct field getters, `new()`, `log()`, and `Eq` implementations to SRC-6's `Deposit`, and `Withdraw` types, SRC-20's `SetNameEvent`, `SetSymbolEvent`, `SetDecimalsEvent`, and `TotalSupplyEvent` events, and SRC-7's `SetMetadataEvent` event.
- [#152](https://github.com/FuelLabs/sway-standards/pull/152) Adds inline documentation examples to the SRC-6 standard.

### Changed v0.6.1

Expand Down
92 changes: 92 additions & 0 deletions standards/src/src6.sw
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,28 @@ abi SRC6 {
/// * If the asset is not supported by the contract.
/// * If the amount of assets forwarded to the contract is zero.
/// * The user crosses any global or user specific deposit limits.
///
/// # Examples
///
/// ```sway
/// use standards::src6::SRC6;
///
/// fn foo(
/// contract_id: ContractId,
/// receiver: Identity,
/// vault_sub_id: SubId,
/// amount: u64,
/// asset_id: AssetId
/// ) {
/// let contract_abi = abi(SRC6, contract_id.bits());
/// let minted_shares: u64 = contract_abi.deposit {
/// gas: 10000,
/// coins: amount,
/// asset_id: asset_id.bits()
/// } (receiver, vault_sub_id);
/// assert(minted_shares != 0);
/// }
/// ```
#[payable]
#[storage(read, write)]
fn deposit(receiver: Identity, vault_sub_id: SubId) -> u64;
Expand All @@ -79,6 +101,27 @@ abi SRC6 {
/// * If the amount of shares is zero.
/// * If the transferred shares do not corresspond to the given asset.
/// * The user crosses any global or user specific withdrawal limits.
///
/// # Examples
///
/// ```sway
/// use standards::src6::SRC6;
///
/// fn foo(
/// contract_id: ContractId,
/// receiver: Identity,
/// underlying_asset: AssetId,
/// vault_sub_id: SubId,
/// share_asset_id: AssetId,
/// amount: u64
/// ) {
/// let contract_abi = abi(SRC6, contract_id.bits());
/// let withdrawn_amount: u64 = contract_abi.withdraw {
/// gas: 10000,
/// coins: amount,
/// asset_id: share_asset_id.bits()
/// } (receiver, underlying_asset, vault_sub_id);
/// assert(withdrawn_amount != 0);
#[payable]
#[storage(read, write)]
fn withdraw(
Expand All @@ -97,6 +140,22 @@ abi SRC6 {
/// # Returns
///
/// * [u64] - The amount of managed assets of the given asset.
///
/// # Examples
///
/// ```sway
/// use standards::src6::SRC6;
///
/// fn foo(
/// contract_id: ContractId,
/// underlying_asset: AssetId,
/// vault_sub_id: SubId
/// ) {
/// let contract_abi = abi(SRC6, contract_id.bits());
/// let managed_assets: u64 = contract_abi.managed_assets(underlying_asset, vault_sub_id);
/// assert(managed_assets != 0);
/// }
/// ```
#[storage(read)]
fn managed_assets(underlying_asset: AssetId, vault_sub_id: SubId) -> u64;

Expand All @@ -116,6 +175,23 @@ abi SRC6 {
///
/// * [Some(u64)] - The maximum amount of assets that can be deposited into the contract, for the given asset.
/// * [None] - If the asset is not supported by the contract.
///
/// # Examples
///
/// ```sway
/// use standards::src6::SRC6;
///
/// fn foo(
/// contract_id: ContractId,
/// receiver: Identity,
/// underlying_asset: AssetId,
/// vault_sub_id: SubId
/// ) {
/// let contract_abi = abi(SRC6, contract_id.bits());
/// let max_depositable: u64 = contract_abi.max_depositable(receiver, underlying_asset, vault_sub_id).unwrap();
/// assert(max_depositable != 0);
/// }
/// ```
#[storage(read)]
fn max_depositable(
receiver: Identity,
Expand All @@ -138,6 +214,22 @@ abi SRC6 {
///
/// * [Some(u64)] - The maximum amount of assets that can be withdrawn from the contract, for the given asset.
/// * [None] - If the asset is not supported by the contract.
///
/// # Examples
///
/// ```sway
/// use standards::src6::SRC6;
///
/// fn foo(
/// contract_id: ContractId,
/// underlying_asset: AssetId,
/// vault_sub_id: SubId
/// ) {
/// let contract_abi = abi(SRC6, contract_id.bits());
/// let max_withdrawable: u64 = contract_abi.max_withdrawable(underlying_asset, vault_sub_id).unwrap();
/// assert(max_withdrawable != 0);
/// }
/// ```
#[storage(read)]
fn max_withdrawable(underlying_asset: AssetId, vault_sub_id: SubId) -> Option<u64>;
}
Expand Down

0 comments on commit d467526

Please sign in to comment.