Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(ckb): Remove 1CKB from BTC time cell capacity #263

Merged
merged 2 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
};