Skip to content

Commit

Permalink
refactor(ckb): Remove 1CKB from BTC time cell capacity (#263)
Browse files Browse the repository at this point in the history
* refactor: Remove 1CKB from btc time cell capacity
* chore: Add changeset
  • Loading branch information
duanyytop authored Jul 30, 2024
1 parent a73806c commit 25aea1e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/sharp-wasps-punch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rgbpp-sdk/ckb': minor
---

refactor: Remove 1CKB from btc time cell capacity
6 changes: 3 additions & 3 deletions packages/ckb/src/utils/ckb-tx.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ describe('ckb tx utils', () => {
args: '0x06ec22c2def100bba3e295a1ff279c490d227151bf3166a4f3f008906c849399',
};
const capacity = calculateRgbppCellCapacity(xudtType);
expect(BigInt(254_0000_0000)).toBe(capacity);
expect(BigInt(253_0000_0000)).toBe(capacity);

const actual = calculateRgbppCellCapacity();
expect(actual).toBe(BigInt(254_0000_0000));
expect(actual).toBe(BigInt(253_0000_0000));
});

it('isClusterSporeTypeSupported', () => {
Expand Down Expand Up @@ -109,7 +109,7 @@ describe('ckb tx utils', () => {
expect(isTypeAssetSupported(xudtMainnetErrorType, true)).toBe(false);
});

it('calculateRgbppCellCapacity', () => {
it('generateUniqueTypeArgs', () => {
const firstInput = {
previousOutput: {
txHash: '0x047b6894a0b7a4d7a73b1503d1ae35c51fc5fa6306776dcf22b1fb3daaa32a29',
Expand Down
4 changes: 2 additions & 2 deletions packages/ckb/src/utils/ckb-tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const isLockArgsSizeExceeded = (args: Hex) => remove0x(args).length > LOC
const BTC_TIME_CELL_INCREASED_SIZE = 95;

// For simplicity, we keep the capacity of the RGBPP cell the same as the BTC time cell
// minimum occupied capacity and 1 ckb for transaction fee and assume UDT cell data size is 16bytes
// minimum occupied capacity and assume UDT cell data size is 16bytes
/**
* RGB_lock:
code_hash:
Expand All @@ -77,7 +77,7 @@ export const calculateRgbppCellCapacity = (xudtType?: CKBComponents.Script): big
const udtTypeSize = 33 + typeArgsSize;
const cellSize =
RGBPP_LOCK_SIZE + udtTypeSize + CELL_CAPACITY_SIZE + UDT_CELL_DATA_SIZE + BTC_TIME_CELL_INCREASED_SIZE;
return BigInt(cellSize + 1) * CKB_UNIT;
return BigInt(cellSize) * CKB_UNIT;
};

// Minimum occupied capacity and 1 ckb for transaction fee
Expand Down
3 changes: 1 addition & 2 deletions packages/ckb/src/utils/rgbpp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { BTCTestnetType, Hex, IndexerCell, RgbppCkbVirtualTx, RgbppTokenInfo, Sp
import { append0x, remove0x, reverseHex, u32ToLe, u8ToHex, utf8ToHex } from './hex';
import {
BTC_JUMP_CONFIRMATION_BLOCKS,
CKB_UNIT,
RGBPP_TX_ID_PLACEHOLDER,
RGBPP_TX_INPUTS_MAX_LENGTH,
RGBPP_TX_WITNESS_MAX_SIZE,
Expand Down Expand Up @@ -286,6 +285,6 @@ export const isRgbppCapacitySufficientForChange = (
sumUdtInputsCapacity: bigint,
receiverOutputCapacity: bigint,
): boolean => {
const rgbppOccupiedCapacity = calculateRgbppCellCapacity() - CKB_UNIT;
const rgbppOccupiedCapacity = calculateRgbppCellCapacity();
return sumUdtInputsCapacity > receiverOutputCapacity + rgbppOccupiedCapacity;
};

1 comment on commit 25aea1e

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New snapshot version of the rgbpp-sdk packages have been released:

Name Version
@rgbpp-sdk/btc 0.0.0-snap-20240730161218
@rgbpp-sdk/ckb 0.0.0-snap-20240730161218
rgbpp 0.0.0-snap-20240730161218
@rgbpp-sdk/service 0.0.0-snap-20240730161218

Please sign in to comment.