Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Roloi logo

Streams Smart Contract

Built with ink! Twitter Follow

Roloi is a payment customization platform that provides money streams, recurring and conditional payments. Roloi converts money into a fluid asset that can flow through a blockchain network. In a dynamic financial world, dynamic payments are necessary.

Environment setup

To compile the smart contract, Rust and Cargo are required. Here is an installation guide.

cargo-contract is required too. Install it using this command:

cargo install cargo-contract --force

Run tests off-chain

To run the tests off-chain, execute this command:

cargo +nightly contract test

Generate technical documentation

To generate the technical documentation, execute this command:

cargo doc

Build smart contract

To compile the smart contract and generates the optimized WebAssembly bytecode, the metadata and bundles, execute this command:

cargo +nightly contract build

Upload & Instantiate

Open the Substrate Contracts-UI.

Choose a chain in the dropdown placed in the top section of the left menu.

Follow the ink! guide to upload and instantiate the smart contract.

Data Model

Stream

pub struct Stream {
    pub payer: AccountId,
    pub recipient: AccountId,
    pub original_balance: u128,
    pub current_balance: u128,
    pub start_date: u64,
    pub end_date: u64
}

Storage

#[ink(storage)]
#[derive(SpreadAllocate)]
pub struct StreamsContract {
    owner: AccountId,
    next_stream_id: u64,
    streams: Mapping<u64, Stream>
}

Messages

Create Stream

Creates a token stream from the sender to the specified recipient setting the end date or the duration.

create_stream(
    recipient: AccountId,
    end_date: Option<u64>,
    duration: Option<u64>,
) -> Result<u64, ContractError>

Parameters:

  • recipient: The recipient wallet address of the stream.
  • end_date: The end date of the stream measured in seconds. If not specified, the stream will be created with the duration.
  • duration: The duration of the stream measured in seconds. If not specified, the stream will be created with the end date.
  • Transaction funds: The amount of funds to be transferred to the recipient through the stream.

Returns:

  • The created stream ID.

Examples:

  • Using end_date: 01/01/2024 01:00:00 GMT
    create_stream(
        "5FPE9bPa2yx8dhREN6iZ3PhAJqhbY87Gfg4ELJiRt8P5xUqN",
        Some(1704070800),
        None
    );
  • Using duration: 5 minutes
    create_stream(
        "5FPE9bPa2yx8dhREN6iZ3PhAJqhbY87Gfg4ELJiRt8P5xUqN",
        None,
        Some(300)
    );

Recipient Withdraw

Withdraws tokens from a stream. The recipient can specify the expected amount of tokens or withdraw all the available balance.

recipient_withdraw(
    stream_id: u64,
    withdrawal_amount: Option<u128>,
) -> Result<u128, ContractError>

Parameters:

  • stream_id: The stream ID.
  • withdrawal_amount: The amount of tokens to be withdrawn. If not specified, all the available balance will be withdrawn.

Returns:

  • The amount of tokens withdrawn.

Examples:

  • Specifying withdrawal_amount: 1000
recipient_withdraw(1, Some(1000));
  • Without specifying withdrawal_amount
recipient_withdraw(1, None);

Get Stream by ID

Returns a stream by its ID.

get_stream_by_id(
    stream_id: u64
) -> Result<Stream, ContractError>

Parameters:

  • stream_id: The expected stream ID.

Returns:

  • The expected stream.

Example:

get_stream_by_id(1);

About

Payment customization platform for the Web3

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages