stampchain-io / BTCStampsExplorer

Bitcoin Stamps API / Explorer
https://bitcoinstamps.xyz
GNU Affero General Public License v3.0
0 stars 2 forks source link

OLGA / SRC-20 Fee Output on Create API Function #22

Open reinamora137 opened 4 months ago

reinamora137 commented 4 months ago

currently the src-20 create only outputs the fees

{"hex": "xyz","fee":113400,"change":35607757}

and the olga mint doesn't output fees in the api json. need to update this for more detail on the dust fees and the trx fees used.

reinamora137 commented 4 months ago
 curl -X 'POST' \Z","creator_name":null,"destination_name":null}}ubuntu@dev:~$ curl -X 'POST' \
  'http://dev.bitcoinstamps.xyz/api/v2/olga/mint' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
  "sourceWallet": "bc1ql49ydapnjafl5t2cp9zqpjwe6pdgmxy98859v2",
  "qty": 1,
  "locked": true,
  "divisible": true,
  "filename": "test.png",
  "file": "iVBORw0KGgoAAAANSUhEUgAAACAAAAAgBAMAAACBVGfHAAAAG1BMVEUAAAALOzcKBiAJTzz/1lqZoxgIaSyfQuJmIslgvM+QAAAAAXRSTlMAQObYZgAAAMlJREFUeNp9kNVhAzEMQFVtYE+ge8HfxhsUFkjuFih4gPJ3Jz9mMPuJJVvjzkR0CBJf7CFQB05GKs75EVCwEbAa+3Wg9XmZ5rOz7gljoE9ZmSydzT67lqcdaWrhUCo8m8baKDEt7Qqz4wtVKTVHRI8R2N1bW7wqMb4GLya0KQOYVOUrXfIaHKWY1lsCTfKXyih0msQXeA1td/RoHGOk++8figPKo67o+dqappTnx8FakD2Vxf11QA78F+cZ6cC5BCrd0F+T8UDmIwdjIhoVAu1hnQAAAABJRU5ErkJggg==",
  "satsPerKB": 20,
  "service_fee": null,
  "service_fee_address": null
}'

Now returns:

{"hex":"7073627....a8d98850000000000000000000000000000",
"est_tx_size":734,"input_value":13629481239780,
"total_dust_value":3375,
"est_miner_fee":14680,
"change_value":189999959113}
reinamora137 commented 3 months ago

The current fee calculation is not very accurate - appears to be high.

reinamora137 commented 3 months ago

This should be more accurate for calculations

        let outputVB = Math.ceil(fileSize / 32) * 43;
        let overHeadVB = 185; // estimate based on 1 input 1 op return and 2 outputs 
        let totalSizeInB = overHeadVB + outputVB;

        let totalMiningFee = (totalSizeInB * feeSatsPerVByte); // total mining fee in sats
        // round to 8 decimal places
        totalMiningFee = Math.round(totalMiningFee * 100000000) / 100000000;

        return parseInt(totalMiningFee);