Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/FuelLabs/sway-applications
Browse files Browse the repository at this point in the history
…into unarchive-amm
  • Loading branch information
SwayStar123 committed Feb 6, 2024
2 parents 05bbd5f + b9970a1 commit dd47c38
Show file tree
Hide file tree
Showing 67 changed files with 348 additions and 359 deletions.
2 changes: 1 addition & 1 deletion .devops/aurora/apps.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ games/TicTacToe
multisig-wallet
name-registry
native-assets/NFT
native-assets/native-asset
native-assets/fractional-NFT
native-assets/token
oracle
timelock
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ For simplicity, a specification can be broken into two levels of detail and the

A non-technical specification is aimed at an audience that may not have the expertise in an area to appreciate the technical challenges involved in achieving the goals and thus it can be seen as an overview or summary.

As an example, this may be a developer explaining how a user would interact with the user interface in order to send a coin / token to someone, without revealing the functionality behind signing a transaction and why a transaction may take some amount of time to be confirmed.
As an example, this may be a developer explaining how a user would interact with the user interface in order to send a coin / asset to someone, without revealing the functionality behind signing a transaction and why a transaction may take some amount of time to be confirmed.

This type of specification is simple so that any layperson can follow the basic concepts of the workflow.

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ jobs:
"multisig-wallet",
"name-registry",
"native-assets/NFT",
"native-assets/native-asset",
"native-assets/fractional-NFT",
"native-assets/token",
"oracle",
"OTC-swap-predicate",
".devops/.template",
Expand Down
2 changes: 1 addition & 1 deletion AMM/project/contracts/exchange-contract/src/events.sw
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub struct RemoveLiquidityEvent {
burned_liquidity: Asset,
}

/// The information logged when a token swap is made.
/// The information logged when an asset swap is made.
pub struct SwapEvent {
/// Identifier and amount of sold asset.
input: Asset,
Expand Down
2 changes: 1 addition & 1 deletion AMM/project/scripts/atomic-add-liquidity/src/main.sw
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ enum InputError {
///
/// # Returns
///
/// * The amount of liquidity tokens minted.
/// * The amount of liquidity assets minted.
///
/// # Reverts
///
Expand Down
2 changes: 1 addition & 1 deletion DAO/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

## Overview

A decentralized autonomous organization (DAO) is akin to an on-chain government where participants are able to cast votes on proposals using some governance token. Various consensus mechanisms may be implemented in order to determine whether a proposal will pass and if that happens then the DAO will begin to operate under the rules of the new proposal. In this implementation the user deposits governance tokens and receives some number of votes that can be cast and recast on different proposals. They can vote in favour or against proposals and they can transform their votes back into the governance tokens if they wish to withdraw.
A decentralized autonomous organization (DAO) is akin to an on-chain government where participants are able to cast votes on proposals using some governance asset. Various consensus mechanisms may be implemented in order to determine whether a proposal will pass and if that happens then the DAO will begin to operate under the rules of the new proposal. In this implementation the user deposits governance assets and receives some number of votes that can be cast and recast on different proposals. They can vote in favour or against proposals and they can transform their votes back into the governance assets if they wish to withdraw.

More information can be found in the [specification](./project/SPECIFICATION.md).

Expand Down
22 changes: 11 additions & 11 deletions DAO/project/SPECIFICATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Table of Content
- [`user_balance()`](#user_balance)
- [`user_votes()`](#user_votes)
- [`proposal()`](#proposal)
- [`governance_token_id()`](#governance_token_id)
- [`governance_asset_id()`](#governance_asset_id)
- [`proposal_count()`](#proposal_count)
- [Sequence diagram](#sequence-diagram)

Expand All @@ -34,7 +34,7 @@ If you are interested in a functional overview then this is the section for you.

### `constructor()`

1. Initializes the contract by setting the governance token used for voting
1. Initializes the contract by setting the governance asset used for voting

### `create_proposal()`

Expand All @@ -44,13 +44,13 @@ If you are interested in a functional overview then this is the section for you.

### `deposit()`

1. Allows a user to deposit any number of governance tokens
1. Each token deposited equates to one vote the user can cast
1. Allows a user to deposit any number of governance assets
1. Each coin deposited equates to one vote the user can cast

### `withdraw()`

1. Allows a user to withdraw any number of governance tokens that they have deposited
1. The user can only withdraw tokens that have not been bonded as votes in proposals
1. Allows a user to withdraw any number of governance assets that they have deposited
1. The user can only withdraw coins that have not been bonded as votes in proposals

### `vote()`

Expand All @@ -76,12 +76,12 @@ If you are interested in a functional overview then this is the section for you.

### `balance()`

1. Returns the total balance of the governance tokens deposited in the contract
1. Returns the total balance of the governance coins deposited in the contract

### `user_balance()`

1. Returns the number of unlocked governance tokens for a user
1. If a user has voted on a proposal then those tokens will not be reflected in this balance
1. Returns the number of unlocked governance coins for a user
1. If a user has voted on a proposal then those coins will not be reflected in this balance

### `user_votes()`

Expand All @@ -98,9 +98,9 @@ If you are interested in a functional overview then this is the section for you.
5. The raw number of "yes" and "no" votes
6. Arbitrary data required for the proposal to execute

### `governance_token_id()`
### `governance_asset_id()`

1. Returns the ID of the governance token
1. Returns the ID of the governance asset

### `proposal_count()`

Expand Down
8 changes: 4 additions & 4 deletions DAO/project/contracts/DAO-contract/src/events.sw
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ pub struct ExecuteEvent {
pub struct InitializeEvent {
/// User who initialized the contract.
author: Identity,
/// AssetId of the token used for DAO governance.
token: AssetId,
/// AssetId of the asset used for DAO governance.
asset: AssetId,
}

/// Event for unlocking of governance tokens.
/// Event for unlocking of governance coins.
pub struct UnlockVotesEvent {
/// The unique identifier for the proposal.
id: u64,
/// User who unlocks the tokens.
/// User who unlocks the coins.
user: Identity,
/// Amount of votes unlocked.
vote_amount: u64,
Expand Down
44 changes: 22 additions & 22 deletions DAO/project/contracts/DAO-contract/src/interface.sw
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ library;
use ::data_structures::{Proposal, ProposalInfo, Votes};

abi DaoVoting {
/// Initialize the dao with the governance token.
/// Initialize the dao with the governance asset.
///
/// # Arguments
///
/// * `gov_token`: [AssetId] - AssetId of the token used to vote on governance proposals.
/// * `gov_asset`: [AssetId] - AssetId of the asset used to vote on governance proposals.
///
/// # Reverts
///
/// * When the constructor is called more than once.
#[storage(read, write)]
fn constructor(gov_token: AssetId);
fn constructor(gov_asset: AssetId);

/// Create a new proposal.
///
Expand All @@ -35,28 +35,28 @@ abi DaoVoting {
proposal_transaction: Proposal,
);

/// Deposit governance tokens into contract.
/// Deposit governance assets into contract.
///
/// # Additional Information
///
/// Update the user balance to indicate they have deposited governance tokens.
/// Update the user balance to indicate they have deposited governance assets.
/// A successful deposit unlocks voting functionality.
/// Voting power is directly proportional to the amount of deposited governance tokens,
/// That is: 1 governance token = 1 vote.
/// Voting power is directly proportional to the amount of deposited governance coins,
/// That is: 1 governance coin = 1 vote.
///
/// # Reverts
///
/// * When the constructor has not been called to initialize.
/// * When the user deposits an asset that is not the specified governance token.
/// * When the user deposits an asset that is not the specified governance asset.
/// * When the user does not deposit any assets.
#[payable, storage(read, write)]
fn deposit();

/// Update the user balance to indicate they have withdrawn governance tokens.
/// Update the user balance to indicate they have withdrawn governance assets.
///
/// # Arguments
///
/// * `amount`: [u64] - amount of governance tokens to withdraw from the contract.
/// * `amount`: [u64] - amount of governance coins to withdraw from the contract.
///
/// # Reverts
///
Expand Down Expand Up @@ -97,13 +97,13 @@ abi DaoVoting {
#[storage(read, write)]
fn execute(proposal_id: u64);

/// Unlock governance tokens from a proposal.
/// Unlock governance assets from a proposal.
///
/// # Additional Information
///
/// Governance tokens are locked whenever a user votes on a proposal.
/// This is to ensure a user cannot vote twice on a proposal with the same governance token.
/// As 1 token = 1 vote.
/// Governance assets are locked whenever a user votes on a proposal.
/// This is to ensure a user cannot vote twice on a proposal with the same governance asset.
/// As 1 coin = 1 vote.
/// If the user did not vote on the proposal then nothing happens.
///
/// # Arguments
Expand All @@ -119,23 +119,23 @@ abi DaoVoting {
}

abi Info {
/// Return the amount of governance tokens in this contract.
/// Return the amount of governance coins in this contract.
///
/// # Returns
///
/// * [u64] - the amount of governance tokens in this contract.
/// * [u64] - the amount of governance coin in this contract.
#[storage(read)]
fn balance() -> u64;

/// Return the amount of governance tokens a user has in this contract.
/// Return the amount of governance coins a user has in this contract.
///
/// # Arguments
///
/// * `user`: [Identity] - Identity to look up governance token balance in this contract.
/// * `user`: [Identity] - Identity to look up governance coin balance in this contract.
///
/// # Returns
///
/// * [u64] - the amount of governance tokens a user has in this contract.
/// * [u64] - the amount of governance coins a user has in this contract.
#[storage(read)]
fn user_balance(user: Identity) -> u64;

Expand Down Expand Up @@ -168,17 +168,17 @@ abi Info {
#[storage(read)]
fn proposal(id: u64) -> ProposalInfo;

/// Return governance token id
/// Return governance asset id
///
/// # Returns
///
/// * [AssetId] - AssetId of the token used to vote on governance proposals.
/// * [AssetId] - AssetId of the asset used to vote on governance proposals.
///
/// # Reverts
///
/// * When the constructor has not been called to initialize
#[storage(read)]
fn governance_token_id() -> AssetId;
fn governance_asset_id() -> AssetId;

/// Return proposal count
///
Expand Down
24 changes: 12 additions & 12 deletions DAO/project/contracts/DAO-contract/src/main.sw
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use ::interface::{DaoVoting, Info};
use ::utils::validate_id;

storage {
/// The amount of governance tokens a user has deposited
/// The amount of governance coins a user has deposited
balances: StorageMap<Identity, u64> = StorageMap {},
/// Information describing a proposal created via create_proposal(...)
proposals: StorageMap<u64, ProposalInfo> = StorageMap {},
Expand All @@ -43,28 +43,28 @@ storage {
proposal_count: u64 = 0,
/// The initialization state of the contract.
state: State = State::NotInitialized,
/// Contract Id of the governance token
token: AssetId = AssetId::base_asset_id(),
/// Contract Id of the governance asset
asset: AssetId = AssetId::base_asset_id(),
/// The amount of votes a user has used on a proposal
votes: StorageMap<(Identity, u64), Votes> = StorageMap {},
}

impl DaoVoting for Contract {
#[storage(read, write)]
fn constructor(token: AssetId) {
fn constructor(asset: AssetId) {
require(
storage
.state
.read() == State::NotInitialized,
InitializationError::CannotReinitialize,
);

storage.token.write(token);
storage.asset.write(asset);
storage.state.write(State::Initialized);

log(InitializeEvent {
author: msg_sender().unwrap(),
token,
asset,
})
}

Expand Down Expand Up @@ -111,7 +111,7 @@ impl DaoVoting for Contract {
);
require(
storage
.token
.asset
.read() == msg_asset_id(),
UserError::IncorrectAssetSent,
);
Expand Down Expand Up @@ -147,7 +147,7 @@ impl DaoVoting for Contract {
storage.balances.insert(user, prev_balance - amount);

// Transfer the asset back to the user
transfer(user, storage.token.read(), amount);
transfer(user, storage.asset.read(), amount);

log(WithdrawEvent { amount, user })
}
Expand Down Expand Up @@ -225,7 +225,7 @@ impl DaoVoting for Contract {
call call_data amount asset gas;
}

// Users can now convert their votes back into tokens
// Users can now convert their votes back into assets
log(ExecuteEvent {
user: msg_sender().unwrap(),
acceptance_percentage,
Expand Down Expand Up @@ -273,7 +273,7 @@ impl DaoVoting for Contract {
impl Info for Contract {
#[storage(read)]
fn balance() -> u64 {
this_balance(storage.token.read())
this_balance(storage.asset.read())
}

#[storage(read)]
Expand All @@ -294,14 +294,14 @@ impl Info for Contract {
}

#[storage(read)]
fn governance_token_id() -> AssetId {
fn governance_asset_id() -> AssetId {
require(
storage
.state
.read() == State::Initialized,
InitializationError::ContractNotInitialized,
);
storage.token.read()
storage.asset.read()
}

#[storage(read)]
Expand Down
Loading

0 comments on commit dd47c38

Please sign in to comment.