Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
112 commits
Select commit Hold shift + click to select a range
ebbb944
🚧 inprogress
Apr 7, 2023
8fae922
🤕🚑 worked version, but need to refactor
Apr 7, 2023
955d8b3
removed old token abi and change account balances update time
lzhabo Apr 7, 2023
7903cfa
updated fuels rs
Apr 7, 2023
df4ff3e
Merge branch 'updateFuels' into forc-v0.37
lzhabo Apr 7, 2023
8725323
updated contract abis to latest fuels version
lzhabo Apr 7, 2023
fe22fb2
remove console logs
lzhabo Apr 7, 2023
aecb72f
updated liqidator forc version
Apr 7, 2023
bbe03d2
Merge remote-tracking branch 'origin/forc-v0.37' into forc-v0.37
Apr 7, 2023
7aaad72
updated liquidator market address
Apr 7, 2023
22ee6f3
started refactoring
Aug 25, 2023
0497dc7
forc : 0.42.1
Aug 28, 2023
90f6c19
Sway 0.45 (#26)
chlenc Aug 29, 2023
b182b0b
deployment of market
Aug 31, 2023
2f37004
updated frontend packaged to latest
lzhabo Aug 31, 2023
6e2eaed
updated contact abis
Aug 31, 2023
7b9ac48
updated token addresses an node url
lzhabo Aug 31, 2023
9c20926
added oracle service
Aug 31, 2023
8f217ba
replaced init function into configurables
Sep 1, 2023
6773f45
remove check if token was minted
lzhabo Sep 1, 2023
4092f50
removed private key auth method, updated mint fn to use token factory
lzhabo Sep 1, 2023
dba4025
♻ ️refactoing
Sep 1, 2023
2243f25
work in progress
lzhabo Sep 1, 2023
64c7a0e
♻ refactoring
Sep 1, 2023
c185ffc
Merge remote-tracking branch 'origin/beta-4' into beta-4
Sep 1, 2023
2b9374e
work in progress
lzhabo Sep 1, 2023
1440793
Merge remote-tracking branch 'origin/beta-4' into beta-4
lzhabo Sep 1, 2023
4b00db6
changed deploy flow: added contract's reward token as the sway collat…
Sep 1, 2023
81004e2
Merge remote-tracking branch 'origin/beta-4' into beta-4
Sep 1, 2023
2179cd5
updaged market abi
lzhabo Sep 1, 2023
6abbb85
deployed market contract with sway token, updated oracle, added events
Sep 3, 2023
ed910f8
Merge remote-tracking branch 'origin/beta-4' into beta-4
Sep 3, 2023
e1f7544
change txParams for supply base and supply collateral functions
lzhabo Sep 4, 2023
a120ec0
Merge remote-tracking branch 'origin/beta-4' into beta-4
lzhabo Sep 4, 2023
d512479
variables refactoring
Sep 4, 2023
85624b0
Merge remote-tracking branch 'origin/beta-4' into beta-4
Sep 4, 2023
9e1f1e1
swaylend deploy
Sep 4, 2023
a4f564a
update config
lzhabo Sep 4, 2023
2d65575
Merge remote-tracking branch 'origin/beta-4' into beta-4
lzhabo Sep 4, 2023
c80177d
update config
lzhabo Sep 4, 2023
74ca08a
added start_block and handle_block into indexer
Sep 4, 2023
db4a251
Merge remote-tracking branch 'origin/beta-4' into beta-4
Sep 4, 2023
3cb0a0e
updated market abi
lzhabo Sep 4, 2023
b4aa1f6
add call params for withdraw collateral fn and updated fuels to 0.55 v
lzhabo Sep 4, 2023
e3e3bc5
missing generics for enum `std::option::Option` fix
Sep 4, 2023
d8b956b
Merge remote-tracking branch 'origin/beta-4' into beta-4
Sep 4, 2023
ef703a4
removed SWAY from faucet table
lzhabo Sep 4, 2023
082d6d5
Merge remote-tracking branch 'origin/beta-4' into beta-4
lzhabo Sep 4, 2023
cdc836a
optimised imports
Sep 7, 2023
9414b34
updated fuels to 0.56.1
Sep 11, 2023
0642488
Merge remote-tracking branch 'origin/beta-4' into beta-4
Sep 11, 2023
8157cdb
added testnet tests and updated local tests
Sep 11, 2023
1d8da03
updated rust sdk and indexer
Sep 14, 2023
2c1c4b4
updated rust sdk and indexer
Sep 14, 2023
d681934
added src 20 from git
Sep 14, 2023
f837bec
updated fuels package and removed gasLimit for available_to_borrow fn
lzhabo Sep 15, 2023
8f1dd76
removed log
lzhabo Sep 15, 2023
ae505f7
fixed price store error
lzhabo Sep 15, 2023
0b99b13
updated indexer file
Sep 15, 2023
f1bae85
Merge remote-tracking branch 'origin/beta-4' into beta-4
Sep 15, 2023
fad4514
redeployed swaylend
Sep 15, 2023
1b2d75d
redeployed swaylend
Sep 15, 2023
cfe94df
used indexer
Sep 16, 2023
8f1261e
🐲 added prices in liquidator
Sep 16, 2023
a609aa4
🧨 Added liquidator and refactored the code
Sep 18, 2023
31f4b90
🧨 Added liquidator and refactored the code
Sep 18, 2023
e1719f1
:recycle: removed some comment
Sep 18, 2023
4fd60e8
updated readme
Sep 18, 2023
542c10e
rebuild market abi and added way to get data for account without eth
lzhabo Sep 18, 2023
ee9db26
added minted tokens value to settings store to disable mint if it was…
lzhabo Sep 18, 2023
b8b5d96
removed gaslimit for withdraw collateral and discord notification aft…
lzhabo Sep 18, 2023
a1809b9
fixed juming apy and commented unused code
Sep 20, 2023
2e8305d
added log file in case of errors
lzhabo Sep 20, 2023
fae692f
Merge remote-tracking branch 'origin/beta-4' into beta-4
lzhabo Sep 20, 2023
6d8f7a2
added copy tx id button in notifications and removed auto delete
lzhabo Sep 20, 2023
da3041e
remove gasLImit
lzhabo Sep 20, 2023
4f0ea8e
🐲 added docker-compose into indexer
Sep 20, 2023
92eddb5
🧨 updated indexer
Sep 20, 2023
68f0880
updated compose file to beta4
lzhabo Sep 20, 2023
e582f96
changed INDEXER_URL in liquidator
Sep 20, 2023
b276e52
Merge remote-tracking branch 'origin/beta-4' into beta-4
Sep 20, 2023
0552374
added copy tx id button in notification
lzhabo Sep 21, 2023
0ac874a
added tutorial page and fixed notification
Sep 22, 2023
f948b7b
fxied copy address form
Sep 22, 2023
dc1001b
:recycle: small ui fixes
Sep 22, 2023
cdf2681
updated sway to v0.46
Sep 23, 2023
4b5836c
fixed available to borrow according to already borrowed amount
lzhabo Sep 25, 2023
5d51421
✅ fixed buy_collateral error on liquidator and enabled to borrow more…
Sep 27, 2023
89ba297
fixed go to beta-4 notification
Sep 27, 2023
466c7b7
Tutorial cards (#29)
lzhabo Sep 27, 2023
dd77680
updated logo 192 and logo 512
Sep 28, 2023
e159834
updated short_name and name in manifest
Sep 28, 2023
efb3c0e
added predeploy script
Sep 28, 2023
27222af
updated logo 192 and logo 512
Sep 28, 2023
af61186
Indexer v0.21 (#31)
chlenc Oct 10, 2023
5cb4104
fixed liquidator a bit
Oct 10, 2023
2c0bdab
added testnet man test
Oct 10, 2023
a954c84
fixed withdraw_base
Oct 10, 2023
8cf8af5
clearify comments
Oct 10, 2023
0f16825
fixed main test seto0 amount
Oct 10, 2023
f09e368
🚀 redeploy
Oct 10, 2023
89fc794
🐲 played with tests a bit
Oct 11, 2023
e1da718
updated fuel wallet code to latest version
lzhabo Oct 16, 2023
b0b4044
Fixed available to borrow and loading state for dashboard page (#32)
lzhabo Oct 17, 2023
693e81e
fixed loading state for input card
lzhabo Oct 17, 2023
0d388cd
added decimals
Oct 19, 2023
d5a4f05
upgrades mint ux
Oct 19, 2023
ffada92
indexing of data in progress
Oct 25, 2023
8d538e3
added
Oct 30, 2023
7ffaea9
New wallets (#34)
lzhabo Nov 1, 2023
be72d44
Added abi imports (#33)
chlenc Nov 15, 2023
73e97c2
Merge remote-tracking branch 'origin/beta-4' into beta-4
Nov 15, 2023
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
64 changes: 64 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# [🌴 ✨ Swaylend ⛽️ ⚡️](https://swaylend.com/)
## First ever Lending protocol on Fuel Network

<figure><img src="https://static.tildacdn.com/tild3165-3835-4163-b062-666230613733/Tilda_badge_1200x630.jpg" alt=""><figcaption></figcaption></figure>

# Introduction

Sway Lend is a decentralized lending platform that operates on the [Fuel Network](https://fuel.network), which has an Ethereum consensus layer. Our platform provides a secure and trustful place for crypto users to earn passive income by supplying liquidity to the market.

With Sway Lend, users can supply up to 6 different crypto assets as collateral and borrow USDC, the base asset. Suppliers earn a passive income by providing liquidity, while borrowers have the option to borrow in either an overcollateralized (perpetually) or undercollateralized manner. \
\
The Sway Lend protocol is built on a re-engineered solution from the Ethereum blockchain, rewritten in the Sway programming language. Our platform is a re-imagining of the [Compound](https://compound.finance/) architecture offers all the features and benefits of the [Compound](https://compound.finance/) with the added security and stability of the [Fuel Network.](https://fuel.network) Our platform is constantly monitored and improved by our dedicated team, who are always available to answer any questions or provide support. Join our [Discord](https://discord.gg/Fwpqpk6vDB) community to learn more about how you can use Sway Lend to achieve your financial goals.

The Sway Lend alive on [https://swaylend.com](https://swaylend.com)


>Please note that Sway Lend is in the alpha testing phase and contracts may change in the future, leading to potential loss of supply/borrow amount.
---



```
██████╗ ██████╗ ███╗ ███╗██████╗ ██████╗ ███████╗ █████╗ ██████╗ ██╗██╗ ██╗████████╗██╗ ██╗
██╔════╝██╔═══██╗████╗ ████║██╔══██╗██╔═══██╗██╔════╝██╔══██╗██╔══██╗██║██║ ██║╚══██╔══╝╚██╗ ██╔╝
██║ ██║ ██║██╔████╔██║██████╔╝██║ ██║███████╗███████║██████╔╝██║██║ ██║ ██║ ╚████╔╝
██║ ██║ ██║██║╚██╔╝██║██╔═══╝ ██║ ██║╚════██║██╔══██║██╔══██╗██║██║ ██║ ██║ ╚██╔╝
╚██████╗╚██████╔╝██║ ╚═╝ ██║██║ ╚██████╔╝███████║██║ ██║██████╔╝██║███████╗██║ ██║ ██║
╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═════╝ ╚══════╝╚═╝ ╚═╝╚═════╝ ╚═╝╚══════╝╚═╝ ╚═╝ ╚═╝

██╗ █████╗ ██████╗ ███████╗
██║ ██╔══██╗██╔══██╗██╔════╝
██║ ███████║██████╔╝███████╗
██║ ██╔══██║██╔══██╗╚════██║
███████╗██║ ██║██████╔╝███████║
╚══════╝╚═╝ ╚═╝╚═════╝ ╚══════╝

SWAY Address = 0xcb3bc832cf32125ce4bd559022aa1b50ff2ac64c578c6343808457a78c1c799a
Market contract = 0x3fffc28bdb0a460263eeda9b56f9c5157c8048c25ed116c3a4e5cee78bb24bb9
Market contract = fuel18llu9z7mpfrqyclwm2d4d7w9z47gqjxztmg3dsayuh8w0zajfwus34ml3a
start_block: 4593788

SWAY = 0xcb3bc832cf32125ce4bd559022aa1b50ff2ac64c578c6343808457a78c1c799a
USDC = 0x8bf7951ea3222fe0bae9b811c2b142a1ff417361dcf7457855ed477d2d9a8550
ETH = 0x0000000000000000000000000000000000000000000000000000000000000000
LINK = 0xfa36ce38f74ee0bcd12c11ec367ca237cee3e6b7a937761f4f762bbc11d2da21
BTC = 0x49fab925448594b61c280b5c580b2a63a6f6a8aaa3c199a06798b1c568808158
UNI = 0xae37bc0feb66e60a89e301d450bb4640aa9bd7cedd856e253e23989eae536e92
COMP = 0xc23da8f4073523e84e4fdd2b6a28f3273af2b70361345a63307313f0f489c48b

start_block: 4593788
Market contract = 0x3fffc28bdb0a460263eeda9b56f9c5157c8048c25ed116c3a4e5cee78bb24bb9
Market contract = fuel18llu9z7mpfrqyclwm2d4d7w9z47gqjxztmg3dsayuh8w0zajfwus34ml3a

Oracle contract = 0x8f7a76602f1fce4e4f20135a0ab4d22b3d9a230215ccee16c0980cf286aaa93c

Token Factory Contract = 0xd8c627b9cd9ee42e2c2bd9793b13bc9f8e9aad32e25a99ea574f23c1dd17685a

```

---
[Twitter](https://twitter.com/swaylend)
[Discord](https://discord.gg/YT9kv2PF)


File renamed without changes.
8 changes: 8 additions & 0 deletions abi/market_abi/Forc.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[project]
authors = ["Alexey"]
entry = "abi.sw"
license = "Apache-2.0"
name = "market_abi"

[dependencies]
i64 = { path = "../../libraries/i64" }
148 changes: 148 additions & 0 deletions abi/market_abi/src/abi.sw
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
library;
pub mod structs;

use structs::*;
use i64::I64;

abi Market {

// ## 1. Debug Functionality
// This functionality is exclusively utilized in local tests to evaluate interest accrual. It works by advancing the timestamp within the contract at specific intervals defined as `DEBUG_STEP`.

#[storage(read, write)]
fn debug_increment_timestamp();


// ## 2. User Account Initialization
// This is an administrative function that allows the system's governor to set up new collateral assets. Each collateral assets may have different characteristics.

#[storage(write, read)]
fn add_collateral_asset(configuration: CollateralConfiguration);

#[storage(read, write)]
fn pause_collateral_asset(asset_id: b256);

#[storage(read, write)]
fn resume_collateral_asset(asset_id: b256);

#[storage(read)]
fn get_collateral_configurations() -> Vec<CollateralConfiguration>; //todo add this data to indexer


// ## 3. Supply and Withdraw collateral
// Users can deposit and withdraw collateral (e.g., BTC, ETH, UNI...). This collateral is necessary to borrow.

#[payable, storage(read, write)]
fn supply_collateral(); //Payment is required: any collateral asset

#[storage(read, write)]
fn withdraw_collateral(asset: b256, amount: u64);

#[storage(read)]
fn get_user_collateral(address: Address, asset_id: b256) -> u64; //todo add this data to indexer

#[storage(read)]
fn totals_collateral(asset_id: b256) -> u64; //todo add this data to indexer


// ## 4. Supply and Withdraw base
// If the user has enough collateral, `withdraw_base` performs the borrow function

#[payable, storage(read, write)]
fn supply_base(); //Payment is required: base asset (USDC)

#[storage(read, write)]
fn withdraw_base(amount: u64);

#[storage(read)]
fn get_user_supply_borrow(account: Address) -> (u64, u64); //todo add this data to indexer

#[storage(read)]
fn available_to_borrow(account: Address) -> u64; //todo add this data to indexer


// ## 4. Absorbation
// Liquidates the user if there is insufficient collateral for the borrowing.

#[storage(read, write)]
fn absorb(accounts: Vec<Address>);

#[storage(read)]
fn is_liquidatable(account: Address) -> bool;


// ## 5. Buying collateral
// Purchase of collateral for liquidated positions

//Function for buying the collateral of a liquidated user
#[payable, storage(read)]
fn buy_collateral(asset_id: b256, min_amount: u64, recipient: Address); //Payment is required: base asset (USDC)

#[storage(read)]
fn collateral_value_to_sell(asset_id: b256, collateral_amount: u64) -> u64;

// A function that counts the collateral purchase rate of the user from our protocol (how much collateral the user gets for redeeming one dollar of debt to be liquidated)
#[storage(read)]
fn quote_collateral(asset_id: b256, base_amount: u64) -> u64;


// ## 6. Reward stuff
// todo add description and test reward stuff

fn get_reward_token_asset_id() -> b256;

//function for claiming reward tokens by admin. `reward_token` is set in merket config
fn withdraw_reward_token(recipient: Address, amount: u64);

#[storage(read, write)]
fn get_reward_owed(account: Address) -> u64;

#[storage(read, write)]
fn claim();


// ## 7. Reserves stuff
// todo add description and test reserves stuff

// Gets the total amount of protocol reserves of the base asset
#[storage(read)]
fn get_reserves() -> I64; //todo add this data to indexer

// Withdraws base token reserves if called by the governor
#[storage(read)]
fn withdraw_reserves(to: Address, amount: u64);

#[storage(read)]
fn get_collateral_reserves(asset_id: b256) -> I64;

// ## 8. Pause settings
// This is an administrative function that allows the system's governor to pause supply, withdraw, absorb, buy and claim

#[storage(write, read)]
fn pause(config: PauseConfiguration);

// ## 9. Getters
// Data that will be useful in the calculations

fn get_configuration() -> MarketConfiguration;

#[storage(read)]
fn get_market_basics() -> MarketBasics;

#[storage(read)]
fn get_user_basic(account: Address) -> UserBasic;

#[storage(read)]
fn get_utilization() -> u64;

fn balance_of(asset: b256) -> u64;


// ## 10. Supply and Borrow rates
// Formulas to help calculate supply and borrow rates

fn get_supply_rate(utilization: u64) -> u64; //todo add this data to indexer

fn get_borrow_rate(utilization: u64) -> u64; //todo add this data to indexer

}
49 changes: 38 additions & 11 deletions contracts/market/src/structs.sw → abi/market_abi/src/structs.sw
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
// SPDX-License-Identifier: BUSL-1.1
library structs;
dep i64;

library;
use i64::I64;

const SCALE_18: u64 = 1_000_000_000_000_000_000; // 1e18

pub struct MarketConfiguration {
governor: Address,
pause_guardian: Address,
base_token: ContractId,
base_token_decimals: u8,
base_token: b256,
base_token_decimals: u64,
base_token_price_feed: ContractId,
kink: u64, // decimals: 18
supply_per_second_interest_rate_slope_low: u64, // decimals: 18
Expand All @@ -23,25 +22,38 @@ pub struct MarketConfiguration {
base_min_for_rewards: u64, // decimals base_token_decimals
base_borrow_min: u64, // decimals: base_token_decimals
target_reserves: u64, // decimals: base_token_decimals
reward_token: ContractId,
// reward_token: b256,
}

pub struct AssetConfig {
asset: ContractId,
pub struct CollateralConfiguration {
asset_id: b256,
price_feed: ContractId,
decimals: u8,
decimals: u64,
borrow_collateral_factor: u64, // decimals: 4
liquidate_collateral_factor: u64, // decimals: 4
liquidation_penalty: u64, // decimals: 4
supply_cap: u64, // decimals: asset decimals
paused: bool,
}

pub struct PauseConfiguration {
supply_paused: bool,
withdraw_paused: bool,
absorb_paused: bool,
buy_pause: bool,
// claim_paused: bool,
buy_paused: bool,
claim_paused: bool,
}

impl PauseConfiguration {
pub fn default() -> Self {
PauseConfiguration {
supply_paused: false,
withdraw_paused: false,
absorb_paused: false,
buy_paused: false,
claim_paused: false,
}
}
}

pub struct UserBasic {
Expand Down Expand Up @@ -72,6 +84,20 @@ pub struct MarketBasics {
last_accrual_time: u64,
}

impl MarketBasics {
pub fn default() -> Self {
MarketBasics {
base_supply_index: SCALE_18,
base_borrow_index: SCALE_18,
tracking_supply_index: SCALE_18,
tracking_borrow_index: SCALE_18,
total_supply_base: 0,
total_borrow_base: 0,
last_accrual_time: 0,
}
}
}

pub enum Error {
AlreadyInitialized: (),
Paused: (),
Expand All @@ -85,5 +111,6 @@ pub enum Error {
BorrowTooSmall: (),
NotPermitted: (),
InvalidPayment: (),
UnknownAsset: (),
DebuggingDisabled: (),
}
29 changes: 10 additions & 19 deletions abi/oracle_abi/src/main.sw
Original file line number Diff line number Diff line change
@@ -1,25 +1,16 @@
library oracle_abi;

pub struct Price {
asset_id: ContractId,
price: u64,
last_update: u64,
}
library ;

abi Oracle {
#[storage(read)]
fn owner() -> Address;

fn owner() -> Identity;
#[storage(read, write)]
fn initialize(owner: Address);

fn set_price(asset_id: b256, price_value: u64);
#[storage(read, write)]
fn set_price(asset_id: ContractId, price_value: u64);

#[storage(read, write)]
fn set_prices(prices: Vec<(ContractId, u64)>);

fn set_prices(prices: Vec<(b256, u64)>);
#[storage(read)]
fn get_price(asset_id: ContractId) -> Price;
fn get_price(asset_id: b256) -> Price;
}

struct Price {
asset_id: b256,
price: u64,
last_update: u64,
}
Loading