Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

sense-finance/sense-v1

Repository files navigation

Sense v1 • ci codecov License: AGPL v3

The Sense Protocol is a decentralized fixed-income protocol on Ethereum, allowing users to manage risk through fixed rates and future yield trading on existing yield bearing-assets.

Extensive documentation and use cases are available within this README and in the Sense docs here.

One way to interact with Sense is through our official app

Active development occurs in this repository, which means some contracts in it might not be production-ready. Proceed with caution.

Community

Discord Twitter Follow

Deployments

Underlying & Targets

Token Address
WETH 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2
USDC 0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48
wstETH 0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0
cUSDC 0x39aa39c021dfbae8fac545936693ac917d5e7563

v1.4.0

Contract Address
Divider 0x86bA3E96Be68563E41c2f5769F1AF9fAf758e6E0
Periphery 0xaa17633AA5A3Cb56698838561161bdb16Cebb8E3
PoolManager 0x9BFcA4882c1D8CDE3b4f787d3d74eb0E1bb0ec1B
TokenHandler 0x4933494b4070c01bfFBd3c53C1E44A3d9d95DD8e
EmergencyStop 0xdC2eDFf06AF7944F4eFd22A105ac693d848Ee52f
WstETHAdapter 0x36c744Dd2916E9E04173Bee9d93D554f955a999d
CFactory 0xeC0E2e78BbEcFA2313150Edb273a429C9D4B25Da
cUSDC-CAdapter 0xEc30fEaC79898aC5FFe055bD128BBbA9584080eC
sP-wstETH:01-05-2022:5 0x923d411E62Cd3727e0B7dec458Ba89B0191A7067
sY-wstETH:01-05-2022:5 0x3A3359af098bb20a4EB1809a298Ca7B1d5B6Be94
sP-wstETH:01-07-2022:5 0xc1Fd90b0C31CF4BF16C04Ed8c6A05105EFc7c989
sY-wstETH:01-07-2022:5 0x7ecE94fD7F997800F7bfE2D53B9D0AABcE05d10b
sP-cUSDC:01-05-2022:6 0xa93fBC8114f6AD04B59426A2aFc1dB9eDB841f7a
sY-cUSDC:01-05-2022:6 0xA5240A4a27817135E2aB30c8f1996a2d460C9Db4
sP-cUSDC:01-07-2022:6 0xb636ADB2031DCbf6e2A04498e8Af494A819d4CB9
sY-cUSDC:01-07-2022:6 0x4ACA82E5686226A679875AACde7ECdf5fC5477ec
SpaceFactory 0x9e629751b3FE0b030C219e567156adCB70ad5541
Space LP Share-wstETH:01-05-2022:5 * 0xbB6C7b5E0804d07aE31A43E6E83Ea66fb128a3BB
Space LP Share-wstETH:01-07-2022:5 * 0x34d179259336812A1C7d320A0972e949dA5fa26d
Space LP Share-cUSDC:01-05-2022:6 * 0x64db005d040EE62E8fa202291C73E8a6151A0399
Space LP Share-cUSDC:01-07-2022:6 * 0x76E5F9860Bd5b8666DE322496f114B8a89183A2E

* We are aware that the Name and Symbol does not include the Space LP Share. This will be fixed in the next version of Space.

Goerli v1.4.0

Contract Address
Divider 0x09B10E45A912BcD4E80a8A3119f0cfCcad1e1f12
Periphery 0x4bCBA1316C95B812cC014CA18C08971Ce1C10861
BalancerVault 0x1aB16CB0cb0e5520e0C081530C679B2e846e4D37

Development

This repo uses Foundry: forge for development and testing and git submodules for dependency management (we previously used dapp and nix, so there are vestiges from those tools around).

To install Foundry Foundry: Forge, use the instructions in the linked repo.

In addition, this repo uses just as our command runner:

brew install just
# or
cargo install just

Test

# Get contract dependencies
git submodule update --init --recursive
yarn install # or npm install

# Run basic tests suite against a local chain. This is all tests ending in .t.sol
# All tests run with underlying, target and stake as ERC20 compliant tokens with 18 decimals
yarn test

# Run mainnet tests (against a mainnet fork). This is all tests ending in .tm.sol
# All tests run with underlying, target and stake as ERC20 compliant tokens with 18 decimals
# (unless they use existing tokens)
yarn test:mainnet

# Run full local test suite (against a local chain) which includes combinations for:
# 1. ERC4626, ERC20 and non-ERC20 for target, underlying and stake
# 2. 6, 8 and 18 decimals for target, underlying and stake
yarn test:fuzz

Format

# Run linter
yarn lint

# Run formatter
yarn fix

Environment

  1. Create a local .env file in the root directory of this project
  2. Set ALCHEMY_KEY to a valid Alchemy API key
  3. Set MNEMONIC to a valid seed phrase for deployments
  4. Set ETHERSCAN_API_KEY to a valid Etherscan API key (used for verification)

Deployment & upgrades

This repo uses hardhat deploy for replicable deployments. To create a new deployment:

# Navigate to the `deployments` package
cd pkg/deployments

# Deploy the protocol with mocks on a forked network
yarn deploy:hardhat-fork:sim

# Deploy the protocol with production config on a forked network
yarn deploy:hardhat-fork:sim

# Deploy the protocol with mocks on a live network
yarn hardhat deploy --network <network> --tags scenario:simulated

# Deploy the protocol with production config on a live network
yarn hardhat deploy --network <network> --tags scenario:prod

New contracts or contract modifications/upgrades are deployed and configured using a Hardhat tasks. Tasks live in the [tasks](https://github.com/sense-finance/sense-v1/tree/dev/pkg/deployments/tasks) directory of the deployment package of the sense-v1 repository.

Aside from deployment, tasks are also responsible for ensuring:

  • other contracts are aware of the new contract,

  • the newly deployed contract is aware of existing contracts, and

  • permissions are set appropriately.

    IMPORTANT: After configuring every new contract, these permissions must be set:

    // Set the multisig as trusted
    newContract.setIsTrusted(multisig, true)
    
    // Set the deployer as non-trusted
    newContract.setIsTrusted(deployer, false)
  • contracts are verified on Etherscan

To create a new task:

  1. Create the task folder and its related files:

    # Navigate to the `deployments/tasks` folder
    cd pkg/deployments/tasks
    
    # Create a new folder with a name following the YYYYMMYY-TASK_NAME pattern
    mkdir YYYYMMYY-TASK_NAME

    Each task folder must contain 2 files:

    • index.js: where the hardhat task logic lives (what should the task do)
    • input.js which contains all the input addresses that the task needs in order to be executed

    Optionally (though most likely), the task will need to instantiate some contracts, requiring the ABIs of them. Create a pkg/deployments/tasks/YYYYMMYY-TASK_NAME/abi folder to store these ABIs.

  2. Add the task into pkg/deployments/tasks/index.js.

  3. Run the new task:

    # Navigate to the `deployments/tasks` folder
    cd pkg/deployments/tasks
    
    # Execute hardhat task
    yarn hardhat 20220517-long-wsteth-adapter --network mainnet

    It is important that you first test that your task does what's intended by running it on a fork from mainnet and, optionally, on Goerli. Just use --network hardhat or --network goerli when executing the command.

  4. Add output files into task folder:

    After successfully executing the task, Hardhat would have saved the resulting deployments (contract addresses along their abi, bytecode, metadata...) on pkg/deployments/deployments. Move that folder inside pkg/deployments/tasks/YYYYMMYY-TASK_NAME and rename it to output.

  5. Commit and push code to GitHub.

NOTE: check existing tasks as a guide on how to create and execute a new one.

Security

Sense-v1 has been audited by four, independent smart contract auditors, ranked by recency:

  1. 2022-02/03 Space AMM - Fixed Point Solutions (Kurt Barry)
  2. 2022-03 Sense - ABDK
  3. 2022-01 Sense & Space AMM - Spearbit
  4. 2021-11/12 Sense - Fixed Point Solutions (Kurt Barry)
  5. 2021-11 Sense - ABDK
  6. 2021-11 Sense - Peckshield

Bug Bounties

Sense has an active bug bounty on ImmuneFi, with up to $50,000 for reporting a bug in deployed contracts & the Sense Portal.

Conventions

Branching

Right now, we are using dev and main branches.

  • main represents the contracts live on mainnet and all testnets
  • dev is for the newest version of contracts, and is reserved for deployments to goerli

When a new version of the contracts makes its way through the testnet, it eventually becomes promoted in main, with semver reflecting contract changes in the major or minor portion of the version (depending on backwards compatibility).