Skip to content

Commit

Permalink
Merge pull request #28 from nervina-labs/feat/update-network-fee
Browse files Browse the repository at this point in the history
Update maker network fee for spore
  • Loading branch information
duanyytop authored Jul 11, 2024
2 parents 1f35955 + 72823a4 commit 3a1f4c5
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nervina-labs/ckb-dex",
"version": "0.3.2",
"version": "0.4.0",
"description": "The JavaScript SDK for CKB DEX",
"author": "duanyytop <[email protected]>",
"license": "MIT",
Expand Down
6 changes: 3 additions & 3 deletions src/order/maker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ import { CKBTransaction } from '@joyid/ckb'
import { OrderArgs } from './orderArgs'

// The difference between the capacity occupied by the owner lock and the seller lock and the result may be negative
export const calculateNFTMakerListPackage = (seller: string | CKBComponents.Script): bigint => {
export const calculateNFTMakerListPackage = (seller: string | CKBComponents.Script, buyer?: CKBComponents.Script): bigint => {
const sellerLock = typeof seller === 'string' ? addressToScript(seller) : seller
const sellerLockArgsSize = remove0x(sellerLock.args).length / 2
const buyerLockArgsSize = remove0x(buyer?.args ?? sellerLock.args).length / 2

// The setup and totalValue are only used as a placeholder and does not affect the final size calculation.
const setup = 4
const totalValue = BigInt(0)
const orderArgs = new OrderArgs(sellerLock, setup, totalValue)
const orderArgsSize = remove0x(orderArgs.toHex()).length / 2

return BigInt(orderArgsSize - sellerLockArgsSize) * CKB_UNIT
return BigInt(orderArgsSize - buyerLockArgsSize) * CKB_UNIT
}

export const calculateUDTMakerListPackage = (seller: string | CKBComponents.Script, assetType?: Hex | CKBComponents.Script): bigint => {
Expand Down
3 changes: 2 additions & 1 deletion src/order/taker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const matchNftOrderCells = (orderCells: CKBComponents.LiveCell[], buyerLo
dexOutputs.push(output)
dexOutputsData.push('0x')

makerNetworkFee += calculateNFTMakerListPackage(orderArgs.ownerLock)
makerNetworkFee += calculateNFTMakerListPackage(orderArgs.ownerLock, buyerLock)

const buyerNftCapacity = calculateNFTCellCapacity(buyerLock, orderCell)
buyerOutputs.push({
Expand Down Expand Up @@ -176,6 +176,7 @@ export const buildTakerTx = async ({
}

changeCapacity = inputsCapacity + makerNetworkFee - dexOutputsCapacity - txFee

const changeOutput: CKBComponents.CellOutput = {
lock: buyerLock,
capacity: append0x(changeCapacity.toString(16)),
Expand Down

0 comments on commit 3a1f4c5

Please sign in to comment.