wojake / DKM

Decentralized Key Management NodeJS library for HP dApps. Do not use in production!
8 stars 2 forks source link

Fee's are handled incorrectly. #6

Closed shortthefomo closed 1 year ago

shortthefomo commented 1 year ago

https://github.com/wojake/DKM/blob/e35ddc683c07b9d749d76de2a98699c9cafd3e5b/index.js#L192

the formula for calculating the fee is incorrectly implemented here.

Screen Shot 2023-04-27 at 09 36 58
shortthefomo commented 1 year ago
Screen Shot 2023-04-27 at 09 41 27

From my understanding this is what needs to be used as the base not the 11 drops you have hardcoded there.

wojake commented 1 year ago
async function AutofillTx({tx, multisig, signer_list, signerlist_quorum, fee, client}) {
    try {
        if (multisig) {
            if (!(signer_list.length > 0)) {
                throw new Error(`${AutofillTx.name}: signer list has less than 1 signer, value: ${signer_list}`);
            }
            if (!(signerlist_quorum > 0)) {
                throw new Error(`${AutofillTx.name}: signerlist_quorum is less than 0, value: ${signerlist_quorum}`);
            }
            if (!(signerlist_quorum < 1)) {
                throw new Error(`${AutofillTx.name}: signerlist_quorum is more than 1, value: ${signerlist_quorum}`);
            }

            if (signer_list.length > 0 && signerlist_quorum > 0 && signerlist_quorum < 1) {
                if (tx.Fee === undefined) {
                    const fee_set = fee ?? GetConfig().config.default_fee_per_signer;
                    tx.Fee = ((signer_count + 1) * fee_set).toString();
                }
                var prepared_tx = await client.autofill(tx, signer_count);
            }
        } else {
            var prepared_tx = await client.autofill(tx);
        }
    } catch (err) {
        console.log("LINE 208", err);
        return err;
    }
    return prepared_tx;
}

In DKM v0.1.0, I used a hard coded value (11) for the default tx fee for each signer in DKM.AutofillTx(), if the instance didn't parse a fee for its transaction. This was a mistake on my part.

I made some changes in v0.2.0: if the instance didn't pass a fee for a transaction in DKM.AutofillTx(), it'll use the set value for default_fee_per_signer on's DKM's config file. This value is mutable.

Some explanation: The instance should parse in a fee for its transaction according to the network's traffic but if it doesn't, DKM would use the set value for default_fee_per_signer in DKM.AutofillTx().

wojake commented 1 year ago

Fixed :)