Git Product home page Git Product logo

superfluid-finance / protocol-monorepo Goto Github PK

View Code? Open in Web Editor NEW
871.0 871.0 230.0 39.34 MB

Superfluid Protocol Monorepo: the specification, implementations, peripherals and development kits.

Home Page: https://www.superfluid.finance

License: Other

JavaScript 10.65% Shell 0.95% Solidity 31.49% TypeScript 46.28% Python 0.19% HTML 1.53% Makefile 0.11% Haskell 3.78% Perl 0.02% TeX 1.13% Handlebars 0.04% CSS 0.02% Nix 0.07% C++ 0.21% Cairo 3.52%
defi ethereum fintech haskell solidity typescript web3

protocol-monorepo's People

Contributors

0xdavinchee avatar allcontributors[bot] avatar bertux avatar d10r avatar dependabot[bot] avatar elvijstdl avatar fakefraud avatar hellwolf avatar jtriley-eth avatar kasparkallas avatar kobuta23 avatar markcarey avatar mjaago avatar mmd-afegbua avatar msoni89 avatar ngmachado avatar pi0neerpat avatar rootulp avatar saflamini avatar santteegt avatar shafu0x avatar shih-yu avatar shreyaspapi avatar sunnyjaycer avatar tokdaniel avatar trozler avatar wp-lai avatar xiaoxianboy avatar yanhuijessica avatar yuliyu123 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

protocol-monorepo's Issues

Implement deposit and deposit allowance feature

ACs:

  • Agreement.realtimeBalanceOf should return margin amount.
  • SuperToken should reserve margin sums of each account as not usable amount by the user, until the agreement ends.
  • app framework should implement deposit allowance feature

Spec:

function realtimeBalanceOf(
         address account,
         uint256 timestamp
     )
         external
         virtual
         view
         returns (int256 balance, int256 deposit);
  • Insolvent account: balance < 0
  • Critical account: balance < - margin

NatSpec integration review

Check if NatSpec integration is properly incorporated.

ACs:

  • NatSpec shipped with json ABIs.
  • UIs showing NatSpec enabled transaction description properly.

Basic implement flow agreement and flow payment

Acceptance criteria

  • FlowAgreement can creates a new flow, with FLOW_PER_SECOND type of flowRate.
  • FlowAgreement can calculate realtime balance of a account.
  • SuperToken as ERC20 token, with realtime balance.
  • Implement all FlowAgreement functions.
  • All test cases.

Specifications

FlowAgreement functions

state update functions:

  • createFlow (token, sender, receiver, flowRate)
  • updateFlow (token, sender, receiver, newFlowRate)
  • deleteFlow (token, sender, receiver) should be equivalent to updateFlow with newFlowRate = 0

view functions:

  • getFlowRate (token, sender, receiver)
  • getTotalInflowRate (token, account)
  • getTotalOutflowRate (token, account)

Test cases

  • Create a new flow (test createFlow function)
    • create user1 -> user2 a new flow
    • verify realtime balances
  • Create additional flow (test createFlow function for multiple flows)
    • create user1 -> user2 a new flow
    • create user3 -> user2 a new flow
    • verify realtime balances
  • Update an existing flow (test updateFlow function)
    • create user1 -> user2 a new flow
    • create user3 -> user2 a new flow
    • update user3 -> user2 with new flow rate
    • verify realtime balances
  • Delete a flow (test deleteFlow function for multiple flows)
    • create user1 -> user2 a new flow
    • create user3 -> user2 a new flow
    • delete user3 -> user2 flow
    • verify realtime balances

permission-less liquidation function for SuperToken

ACs:

  • If the account has less than X-time amount of liquidity, any agent could call the FlowAgreement.deleteFlow
  • FlowAgreement.deleteFlow should allow agent to close if the sender account is in insolvent state. (Currently it only allows sender or recipient). This is temporary until liquidation permission system is setup.

Spec:

FlowAgreement.deleteFlow implementation:

(1) if not sender nor receiver,
(2) check if it allows liquidation: this will check ISuperToken.isAccountInsolvent(sender) or ISuperToken.isAccountInsolvent(receiver)
(3) if (2) is true, then allowing the msg.sender to close the agreement for sender or receiver
(4) distribute the margin as reward

SuperToken.isAccountInsolvent(account) implementation:

  • when account.realtimeBalanceOf(block.timestamp).balance < 0
  • margin is to be implemented in #24

Token Upgrader

Synopsis: a non-upgradable simple contract that upgrades the token for the approving user and transfer all back to the user (for free).

Target Release: v0.2

Spec

TBD.

ACs:

TBD.

Support mutliple Superfluid Tokens

Multiple test tokens have been created and super token wrapper have also been created for them.

They can be resolved to :

  • tokens.fUSDC
  • tokens.fDAI
  • tokens.fUSDT
  • tokens.fTUSD

And their wrapper could be fetched by using:

const registryAddress = await testResolver.get("SuperfluidRegistry.master");
const registry = await SuperfluidRegistry.at(registryAddress);
const tokenInfo = await TokenInfo.at(tokenAddress);
const superTokenWrapper = Superfluid.getERC20Wrapper(registry, tokenInfo);
const superToken = await SuperToken.at(superTokenWrapper.address)

Agreement data and state slots refactoring

Synopsis: Currently agreement data is stored as bytes[], and using solidity mapping for addressing, instead we could use fixed sized bytes32[] and direct addressing in assembly to not save the "length" field of the dynamic bytes array.

Target release: v0.1

Spec

Changes required in agreements:

  • all agreement data function require length as input
  • use getAgreementStateSlot/updateAgreementStateSlot and provide data length
  • explicit setAgreementInactive call to deactivate agreement from user account.

ACs

  • agreements updated
  • test passes
  • gas usage reduced

SuperToken.downgrade function

The opposite of upgrading token to super token is downgrading, it is important that one can downgrade and see the underlying token again. Checks must be in place to assure the solvency, and one cannot downgrade more than he owns.

Specifications

SuperToken

  • function downgrade(uint256 amount)

Test Cases

  • All test cases should end up with downgrading existing super tokens, and token balances should be tested according to the spec.
    • one can settle and downgrade/withdraw up to static balance + realtime balance
    • one cannot settle and withdraw more than static balance + realtime balance

[ETHEREUM-CONTRACTS] ERC-712 type signature based meta tx support

Rationale

With typed signature specified in ERC-712, batch operations could be signed in a human readable way in supported wallet interface.

It provides a great UX improvement, as an alternative to the radspec approach.

Target release: v0.2

Spec

  • TODO

ACs

  • TODO

Notes

  • function selector could be part of the typed signature, looking like "foobar(address,uint256)". The function name part is the human readable part, however the parameter list unfortunately cannot be ommitted.
  • the signed signature could be relayed as a meta tx, and be broadcasted by the user directly.
  • should review delegatable framework for composable 712 signatures.

ERC-777 Support

Synopsis: By enforcing ERC-777, a super token cannot be sent directly to a contract, instead the contract must implement the IERC777Recipient interface. By doing so the contract could implement additional logic reacting on super token received event.

Target release: v0.1

Specs

ERC-777

ACs:

TBD

Official Super Tokens set to always 18 decimals

In relation to #43, one solution is to always set super token decimals to 18 decimals.

As a consequence:

  • Downgrade/Upgrade needs to convert decimals between the underlying and super tokens
  • For 112 bits flow rate, the maximum flow rate for 18 decimals underlying is 519229685853482.75 / sec

ACs:

  • Supertoken downgrade/upgrade to convert decimals
  • Re-deploy all super token wrappers with fixed 18 decimals

Liquidation rules abstraction

Synopsis: The agreement should be implemented in such way that when bond system is put in place, its code needs not to be updated.

Spec

  • The agreement can check if the account is solvent, and decide if the agreement can be "liquidated".
  • The agreement must not transfer the deposit directly, but instruct the release of the deposit to the reward address.
  • The superfluid framework transfer the deposit to the rightful owner, be it the liquidator or the liquidation agent or the bond holder, depending on the system in place.

ACs

  • code reviewed
  • start with free agent system, liquidation agent takes it all
  • tested

Agreement Introspection Data

Include agreementClass and version.

Tips for the agent:

  1. Try to use introspect to detect what type of agreement it is.
  2. If introspection failed (try/catch) assume it uses the current constant flow agreement interface.
  3. If introspection succeed, and agent doesn't know understand the type of agreement, crash/assert.
  4. Use the constant flow agreement abi from the installed npm package.

«JS-SDK» Framework class + ConstantFlowAgreementV1Helper class

Synopsis: Due to the use of call proxy, batch call, etc, it is not a simple web3 call to interact with the superfluid frameworks, a minimalistic js-sdk is shipped along with the project to simplify the usages. Framework class is the main class used for that purpose.

Specs

  • initialize
    • token list
  • token registry
    • getERC20Wrapper
    • createERC20Wrapper
  • sf.cfa
    • createFlow
    • updateFlow
    • deleteFlow
    • getFlow
    • getNetFlow
    • listFlows

Deferring these to new tickets:

- [ ] sf.ida
  - [ ] createIndex
  - [ ] updateIndex/distribute
  - [ ] approveSubcription
  - [ ] updateSubscription
  - [ ] listSubscription
  - [ ] deleteSubscription
- [ ] sf.callAppAction
- [ ] sf.batchCall

Implement UQ56x56 for flowrate

Related to #43

Rationale:

  • Underlying tokens could have very different decimals
  • To avoid granularity problem due to low decimals of underlying tokens(for example using USDC at 6 decimals, ~2.5 USDC/mo granularity), flow rate could be with an underlying token independent unit: "1.0 underlying token"
  • Further more, to squeeze in/out flow rates in one word, UQ56x56 could be utilized. Which could encode up to 72057594037927936 / sec

--

Alright, we are not doing this. But I will write it down as a archived issue.

We are opting for 18 decimals super tokens.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.