UnUniFi / chain

GNU General Public License v3.0
33 stars 14 forks source link

Iya feecollector #669

Closed kimurayu45z closed 1 year ago

kimurayu45z commented 1 year ago
kimurayu45z commented 1 year ago

need to check

        withdrawModuleCommissionFee := sdk.NewDecFromInt(withdrawAmount).Mul(params.CommissionRate).RoundInt()
    withdrawVaultCommissionFee := sdk.NewDecFromInt(withdrawAmount).Mul(vault.WithdrawCommissionRate).RoundInt()
    withdrawAmountWithoutCommission := withdrawAmount.Sub(withdrawModuleCommissionFee).Sub(withdrawVaultCommissionFee)

    if withdrawModuleCommissionFee.IsPositive() {
        feeCollector, err := sdk.AccAddressFromBech32(params.FeeCollectorAddress)
        if err != nil {
            return err
        }
        err = k.bankKeeper.SendCoins(ctx, vaultModAddr, feeCollector, sdk.NewCoins(sdk.NewCoin(principal.Denom, withdrawModuleCommissionFee)))
        if err != nil {
            return err
        }
    }

    if withdrawVaultCommissionFee.IsPositive() {
        vaultOwner, err := sdk.AccAddressFromBech32(vault.Owner)
        if err != nil {
            return err
        }
        err = k.bankKeeper.SendCoins(ctx, vaultModAddr, vaultOwner, sdk.NewCoins(sdk.NewCoin(principal.Denom, withdrawVaultCommissionFee)))
        if err != nil {
            return err
        }
    }