thxprotocol / modules-solidity

Default Asset Pools are connected to an ERC20 contract. The pool is controlled by a permissioned (OAuth2.0) REST API which is responsible for paying the gas costs used to manage the pool. Access to the pool is managed with a flexible role-based access mechanism. Pools can hold various reward configurations for the connected ERC20 tokent contract and will manage the distribution of those token rewards with a withdrawal system. The poll system used to govern the reward configuration and withdrawals is optional.
4 stars 3 forks source link

As a user I want to swap a token amount against the pool token #48

Closed peterpolman closed 2 years ago

peterpolman commented 2 years ago

Pseudocode:


mapping(address => uint256) multipliers;

setSwapRule(address _tokenAddress, uint256 multiplier) {
    multiplies[_tokenAddress] = multiplier;
}

swap(uint256 _amountIn, address _tokenAddress) {
    LibTokenStorage.TokenStorage storage s = LibTokenStorage.tokenStorage();

        uint256 amountOut = _amountIn.mul(multipliers[_tokenAddress]);
        uint256 fee = _amountIn.mul(registry.feePercentage()).div(10**18);
        uint256 amount = _amountIn.sub(fee);

        if (fee > 0) {
            s.token.safeTransferFrom(_msgSender(), registry.feeCollector(), fee);
            emit DepositFeeCollected(fee);
        }

        s.token.safeTransferFrom(_msgSender(), address(this), amount);
        s.token.safeTransferFrom(address(this), _msgSender(), amountOut);

    emit Swap();
}

Usage flow: Alice is a XYZ pool owner and holds 10000 XYZ Bob is an ABC swapper and holds 100 ABC The FeeCollector holds nothing

  1. Alice deposits 100000 XYZ in her pool
  2. Alice configures an 1:10 ABC swap in her pool
  3. Bob is a member of Alice her XYZ pool
  4. Bob swaps 10 ABC in Alice her pool
  5. Bob receives 100 XYZ from the pool
  6. The pool receives 9.75 ABC from Bob
  7. The FeeCollector receives 0.25 ABC from the pool
valeriagrazzini commented 2 years ago

created branch origin/issue-48-implement-swap

peterpolman commented 2 years ago

created branch origin/issue-48-implement-swap

There is a feature for that! Please link the PR's to the related issue:) Ty! 🙏

valeriagrazzini commented 2 years ago

sure: https://github.com/thxprotocol/modules-solidity/pull/50 @peterpolman

peterpolman commented 2 years ago

It's on the PR level 😉

https://gyazo.com/45a535361aef7aef4456a69979547988

valeriagrazzini commented 2 years ago

got it ! :)