Exemplo n.º 1
0
 def rebind(self, token_address: str, balance_base: int, weight_base: int,
            from_wallet: web3wallet.Web3Wallet):
     """
     Changes the parameters of an already-bound token. Performs the same 
     validation on the parameters.
     """
     func = self.f.rebind(token_address, balance_base, weight_base)
     web3wallet.buildAndSendTx(func, from_wallet)
Exemplo n.º 2
0
 def unbind(self, token_address: str, from_wallet: web3wallet.Web3Wallet):
     """
     Unbinds a token, clearing all of its parameters. Exit fee is charged
     and the remaining balance is sent to caller.
     """
     func = self.f.unbind(token_address)
     return web3wallet.buildAndSendTx(func, from_wallet)
Exemplo n.º 3
0
 def setSwapFee(self, swapFee_base: int,
                from_wallet: web3wallet.Web3Wallet):
     """
     Caller must be controller. Pool must NOT be finalized.
     """
     func = self.f.setSwapFee(swapFee_base)
     return web3wallet.buildAndSendTx(func, from_wallet)
Exemplo n.º 4
0
 def swapExactAmountIn(
         self,
         tokenIn_address: str,
         tokenAmountIn_base: int,
         tokenOut_address: str,
         minAmountOut_base: int,
         maxPrice_base: int,
         from_wallet: web3wallet.Web3Wallet):
     """
     Trades an exact `tokenAmountIn` of `tokenIn` taken from the caller by 
     the pool, in exchange for at least `minAmountOut` of `tokenOut` given 
     to the caller from the pool, with a maximum marginal price of 
     `maxPrice`.
     
     Returns `(tokenAmountOut`, `spotPriceAfter)`, where `tokenAmountOut` 
     is the amount of token that came out of the pool, and `spotPriceAfter`
     is the new marginal spot price, ie, the result of `getSpotPrice` after
     the call. (These values are what are limited by the arguments; you are 
     guaranteed `tokenAmountOut >= minAmountOut` and 
     `spotPriceAfter <= maxPrice)`.
     """
     func = self.f.swapExactAmountIn(
         tokenIn_address, tokenAmountIn_base,
         tokenOut_address, minAmountOut_base, maxPrice_base)
     return web3wallet.buildAndSendTx(func, from_wallet)
Exemplo n.º 5
0
 def swapExactAmountOut(self, tokenIn_address: str, maxAmountIn_base: int,
                        tokenOut_address: str, tokenAmountOut_base: int,
                        maxPrice_base: int,
                        from_wallet: web3wallet.Web3Wallet):
     func = self.f.swapExactAmountOut(tokenIn_address, maxAmountIn_base,
                                      tokenOut_address, tokenAmountOut_base,
                                      maxPrice_base)
     return web3wallet.buildAndSendTx(func, from_wallet)
Exemplo n.º 6
0
 def setPublicSwap(self, public: bool, from_wallet: web3wallet.Web3Wallet):
     """
     Makes `isPublicSwap` return `_publicSwap`. Requires caller to be 
     controller and pool not to be finalized. Finalized pools always have 
     public swap.
     """
     func = self.f.setPublicSwap(public)
     return web3wallet.buildAndSendTx(func, from_wallet)
Exemplo n.º 7
0
 def finalize(self, from_wallet: web3wallet.Web3Wallet):
     """
     This makes the pool **finalized**. This is a one-way transition. `bind`,
     `rebind`, `unbind`, `setSwapFee` and `setPublicSwap` will all throw 
     `ERR_IS_FINALIZED` after pool is finalized. This also switches 
     `isSwapPublic` to true.
     """
     func = self.f.finalize()
     return web3wallet.buildAndSendTx(func, from_wallet)
Exemplo n.º 8
0
 def exitswapPoolAmountIn(self, tokenOut_address: str,
                          poolAmountIn_base: int, minAmountOut_base: int,
                          from_wallet: web3wallet.Web3Wallet):
     """
     Pay `poolAmountIn` pool shares into the pool, getting `tokenAmountOut` 
     of the given token `tokenOut` out of the pool.
     """
     func = self.f.exitswapPoolAmountIn(tokenOut_address, poolAmountIn_base,
                                        minAmountOut_base)
     return web3wallet.buildAndSendTx(func, from_wallet)
Exemplo n.º 9
0
 def exitPool(self, poolAmountIn_base: int,
              minAmountsOut_base: typing.List[int],
              from_wallet: web3wallet.Web3Wallet):
     """
     Exit the pool, paying `poolAmountIn` pool tokens and getting some of 
     each of the currently trading tokens in return. These values are 
     limited by the array of `minAmountsOut` in the order of the pool tokens.
     """
     func = self.f.exitPool(poolAmountIn_base, minAmountsOut_base)
     return web3wallet.buildAndSendTx(func, from_wallet)
Exemplo n.º 10
0
 def joinPool(self, poolAmountOut_base: int,
              maxAmountsIn_base: typing.List[int],
              from_wallet: web3wallet.Web3Wallet):
     """
     Join the pool, getting `poolAmountOut` pool tokens. This will pull some
     of each of the currently trading tokens in the pool, meaning you must 
     have called `approve` for each token for this pool. These values are
     limited by the array of `maxAmountsIn` in the order of the pool tokens.
     """
     func = self.f.joinPool(poolAmountOut_base, maxAmountsIn_base)
     return web3wallet.buildAndSendTx(func, from_wallet)
Exemplo n.º 11
0
 def joinswapExternAmountIn(self, tokenIn_address: str,
                            tokenAmountIn_base: int,
                            minPoolAmountOut_base: int,
                            from_wallet: web3wallet.Web3Wallet):
     """
     Pay `tokenAmountIn` of token `tokenIn` to join the pool, getting
     `poolAmountOut` of the pool shares.
     """
     func = self.f.joinswapExternAmountIn(tokenIn_address,
                                          tokenAmountIn_base,
                                          minPoolAmountOut_base)
     return web3wallet.buildAndSendTx(func, from_wallet)
Exemplo n.º 12
0
 def joinswapPoolAmountOut(self, tokenIn_address: str,
                           poolAmountOut_base: int, maxAmountIn_base: int,
                           from_wallet: web3wallet.Web3Wallet):
     """
     Specify `poolAmountOut` pool shares that you want to get, and a token
     `tokenIn` to pay with. This costs `maxAmountIn` tokens (these went 
     into the pool).
     """
     func = self.f.joinswapPoolAmountOut(tokenIn_address,
                                         poolAmountOut_base,
                                         maxAmountIn_base)
     return web3wallet.buildAndSendTx(func, from_wallet)
Exemplo n.º 13
0
    def createToken(self, blob: str, name: str, symbol: str, cap_base: int,
                    from_wallet: web3wallet.Web3Wallet) -> str:
        f = self.contract.functions.createToken(blob, name, symbol, cap_base)
        (tx_hash, tx_receipt) = web3wallet.buildAndSendTx(f, from_wallet)

        warnings.filterwarnings("ignore")  #ignore unwarranted warning up next
        rich_logs = getattr(self.contract.events,
                            'TokenCreated')().processReceipt(tx_receipt)
        token_address = rich_logs[0]['args']['newTokenAddress']
        warnings.resetwarnings()

        return token_address
Exemplo n.º 14
0
 def exitswapExternAmountOut(self, tokenOut_address: str,
                             tokenAmountOut_base: int,
                             maxPoolAmountIn_base: int,
                             from_wallet: web3wallet.Web3Wallet):
     """
     Specify `tokenAmountOut` of token `tokenOut` that you want to get out
     of the pool. This costs `poolAmountIn` pool shares (these went into 
     the pool).
     """
     func = self.f.exitswapExternAmountOut(tokenOut_address,
                                           tokenAmountOut_base,
                                           maxPoolAmountIn_base)
     return web3wallet.buildAndSendTx(func, from_wallet)
Exemplo n.º 15
0
    def newBPool(self, from_wallet: web3wallet.Web3Wallet) -> str:
        print("BPool.newSPool(). Begin.")
        f = self.contract.functions.newBPool()
        (tx_hash, tx_receipt) = web3wallet.buildAndSendTx(f, from_wallet)

        # grab pool_address
        warnings.filterwarnings("ignore")  #ignore unwarranted warning up next
        rich_logs = self.contract.events.BPoolCreated().processReceipt(
            tx_receipt)
        warnings.resetwarnings()
        pool_address = rich_logs[0]['args']['newBPoolAddress']
        print(f"  pool_address = {pool_address}")

        print("BPool.newSPool(). Done.")
        return pool_address
Exemplo n.º 16
0
    def gulp(self, token_address: str, from_wallet: web3wallet.Web3Wallet):
        """
        This syncs the internal `balance` of `token` within a pool with the 
        actual `balance` registered on the ERC20 contract. This is useful to 
        wallet for airdropped tokens or any tokens sent to the pool without 
        using the `join` or `joinSwap` methods. 

        As an example, pools that contain `COMP` tokens can have the `COMP`
        balance updated with the rewards sent by Compound (https://etherscan.io/tx/0xeccd42bf2b8a180a561c026717707d9024a083059af2f22c197ee511d1010e23). 
        In order for any airdrop balance to be gulped, the token must be bound 
        to the pool. So if a shared pool (which is immutable) does not have a 
        given token, any airdrops in that token will be locked in the pool 
        forever. 
        """
        func = self.f.gulp(token_address)
        return web3wallet.buildAndSendTx(func, from_wallet)
Exemplo n.º 17
0
    def bind(self, token_address: str, balance_base: int, weight_base: int,
             from_wallet: web3wallet.Web3Wallet):
        """
        Binds the token with address `token`. Tokens will be pushed/pulled from 
        caller to adjust match new balance. Token must not already be bound. 
        `balance` must be a valid balance and denorm must be a valid denormalized
        weight. `bind` creates the token record and then calls `rebind` for 
        updating pool weights and token transfers.

        Possible errors:
        -`ERR_NOT_CONTROLLER` -- caller is not the controller
        -`ERR_IS_BOUND` -- T is already bound
        -`ERR_IS_FINALIZED` -- isFinalized() is true
        -`ERR_ERC20_FALSE` -- ERC20 token returned false
        -`ERR_MAX_TOKENS` -- Only 8 tokens are allowed per pool
        -unspecified error thrown by token
        """
        func = self.f.bind(token_address, balance_base, weight_base)
        return web3wallet.buildAndSendTx(func, from_wallet)
Exemplo n.º 18
0
 def approve(self, spender_address: str, amt_base: int,
             from_wallet: web3wallet.Web3Wallet):
     f = self.contract.functions.approve(spender_address, amt_base)
     return web3wallet.buildAndSendTx(f, from_wallet)
Exemplo n.º 19
0
 def transfer(self, dst_address: str, amt_base: int,
              from_wallet: web3wallet.Web3Wallet):
     f = self.contract.functions.transfer(dst_address, amt_base)
     return web3wallet.buildAndSendTx(f, from_wallet)
Exemplo n.º 20
0
 def setMinter(self, minter: str, from_wallet: web3wallet.Web3Wallet):
     f = self.contract.functions.setMinter(minter)
     return web3wallet.buildAndSendTx(f, from_wallet)
Exemplo n.º 21
0
 def mint(self, account: str, value_base: int,
          from_wallet: web3wallet.Web3Wallet):
     f = self.contract.functions.mint(account, value_base)
     return web3wallet.buildAndSendTx(f, from_wallet)
Exemplo n.º 22
0
 def transferFrom(self, src_address: str, dst_address: str, amt_base: int,
                  from_wallet: web3wallet.Web3Wallet):
     func = self.f.transferFrom(dst_address, src_address, amt_base)
     return web3wallet.buildAndSendTx(func, from_wallet)
Exemplo n.º 23
0
 def approve(self, dst_address: str, amt_base: int,
             from_wallet: web3wallet.Web3Wallet):
     func = self.f.approve(dst_address, amt_base)
     return web3wallet.buildAndSendTx(func, from_wallet)
Exemplo n.º 24
0
 def setController(self, manager_address: str,
                   from_wallet: web3wallet.Web3Wallet):
     func = self.f.setController(manager_address)
     return web3wallet.buildAndSendTx(func, from_wallet)