diff --git a/package.json b/package.json index 75029e9..842d76b 100644 --- a/package.json +++ b/package.json @@ -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 ", "license": "MIT", diff --git a/src/order/maker.ts b/src/order/maker.ts index 9628e22..80f4ce1 100644 --- a/src/order/maker.ts +++ b/src/order/maker.ts @@ -25,9 +25,9 @@ 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 @@ -35,7 +35,7 @@ export const calculateNFTMakerListPackage = (seller: string | CKBComponents.Scri 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 => { diff --git a/src/order/taker.ts b/src/order/taker.ts index 268217a..d9831dc 100644 --- a/src/order/taker.ts +++ b/src/order/taker.ts @@ -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({ @@ -176,6 +176,7 @@ export const buildTakerTx = async ({ } changeCapacity = inputsCapacity + makerNetworkFee - dexOutputsCapacity - txFee + const changeOutput: CKBComponents.CellOutput = { lock: buyerLock, capacity: append0x(changeCapacity.toString(16)),