Skip to content

Commit

Permalink
refactor(tx schema)!: remove default NAME_FEE equal to 0
Browse files Browse the repository at this point in the history
  • Loading branch information
davidyuk committed Feb 11, 2022
1 parent 18e4bab commit 9d8339a
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 10 deletions.
7 changes: 3 additions & 4 deletions src/ae/aens.js
Expand Up @@ -29,7 +29,7 @@
import { salt } from '../utils/crypto'
import { commitmentHash, ensureNameValid, isAuctionName } from '../tx/builder/helpers'
import Ae from './'
import { CLIENT_TTL, NAME_FEE, NAME_TTL } from '../tx/builder/schema'
import { CLIENT_TTL, NAME_TTL } from '../tx/builder/schema'
import { IllegalArgumentError } from '../utils/errors'

/**
Expand Down Expand Up @@ -321,7 +321,7 @@ async function preclaim (name, options = {}) {
*
* await sdkInstance.aensBid(name, 213109412839123, { ttl, fee, nonce })
*/
async function bid (name, nameFee = NAME_FEE, options = {}) {
async function bid (name, nameFee, options = {}) {
return this.aensClaim(name, 0, { ...options, nameFee, vsn: 2 })
}

Expand Down Expand Up @@ -350,8 +350,7 @@ const Aens = Ae.compose({
Ae: {
defaults: {
clientTtl: CLIENT_TTL,
nameTtl: NAME_TTL, // aec_governance:name_claim_max_expiration() => 50000
nameFee: NAME_FEE
nameTtl: NAME_TTL // aec_governance:name_claim_max_expiration() => 50000
}
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/tx/builder/helpers.js
Expand Up @@ -12,7 +12,6 @@ import {
ID_TAG_PREFIX,
PREFIX_ID_TAG,
NAME_BID_RANGES,
NAME_FEE,
NAME_FEE_BID_INCREMENT,
NAME_BID_TIMEOUTS,
NAME_MAX_LENGTH_FEE,
Expand Down Expand Up @@ -326,12 +325,11 @@ export function getMinimumNameFee (name) {
* @param {Number} [increment=0.5] Bid multiplier(In percentage, must be between 0 and 1)
* @return {String} Bid fee
*/
export function computeBidFee (name, startFee = NAME_FEE, increment = NAME_FEE_BID_INCREMENT) {
export function computeBidFee (name, startFee, increment = NAME_FEE_BID_INCREMENT) {
if (!(Number(increment) === increment && increment % 1 !== 0)) throw new IllegalBidFeeError(`Increment must be float. Current increment ${increment}`)
if (increment < NAME_FEE_BID_INCREMENT) throw new IllegalBidFeeError(`minimum increment percentage is ${NAME_FEE_BID_INCREMENT}`)
return ceil(
BigNumber(BigNumber(startFee).eq(NAME_FEE) ? getMinimumNameFee(name) : startFee)
.times(BigNumber(NAME_FEE_BID_INCREMENT).plus(1))
BigNumber(startFee ?? getMinimumNameFee(name)).times(BigNumber(NAME_FEE_BID_INCREMENT).plus(1))
)
}

Expand Down
3 changes: 2 additions & 1 deletion src/tx/builder/index.js
Expand Up @@ -305,7 +305,8 @@ export function calculateFee (fee = 0, txType, { gas = 0, params, showWarning =
export function validateParams (params, schema, { excludeKeys = [] }) {
return Object.fromEntries(
schema
.filter(([key]) => !excludeKeys.includes(key) && key !== 'payload')
// TODO: allow optional keys in schema
.filter(([key]) => !excludeKeys.includes(key) && !['payload', 'nameFee'].includes(key))
.map(([key, type, prefix]) => [key, validateField(params[key], type, prefix)])
.filter(([, message]) => message)
)
Expand Down
1 change: 0 additions & 1 deletion src/tx/builder/schema.js
Expand Up @@ -35,7 +35,6 @@ export const NAME_TTL = 180000
export const NAME_MAX_TTL = 36000
export const NAME_MAX_CLIENT_TTL = 84600
export const CLIENT_TTL = NAME_MAX_CLIENT_TTL
export const NAME_FEE = 0
// # see https://github.com/aeternity/aeternity/blob/72e440b8731422e335f879a31ecbbee7ac23a1cf/apps/aecore/src/aec_governance.erl#L67
export const NAME_FEE_MULTIPLIER = 1e14 // 100000000000000
export const NAME_FEE_BID_INCREMENT = 0.05 // # the increment is in percentage
Expand Down

0 comments on commit 9d8339a

Please sign in to comment.