Skip to content

Commit

Permalink
feat(lumos): upgrade lumos
Browse files Browse the repository at this point in the history
  • Loading branch information
Daryl-L committed Dec 29, 2023
1 parent b2a4c35 commit 9abb302
Show file tree
Hide file tree
Showing 40 changed files with 742 additions and 865 deletions.
2 changes: 1 addition & 1 deletion docker/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
build:
cd ckb && docker build -t tockb/ckb-dev:v0.100.0 .
cd ckb && docker build -t nervos/ckb:v0.111.0 .
cd ckb-indexer && docker build -t tockb/ckb-indexer:v0.3.0 .
cd geth && docker build -t tockb/geth-priv:v1.10.10 .
cd bitcoin && docker build -t tockb/btc-regtest .
Expand Down
2 changes: 1 addition & 1 deletion docker/ckb/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM nervos/ckb:v0.100.0
FROM nervos/ckb:v0.111.0

ENV CKB_CHAIN=dev
ENV BA_ARG=0x839f6f4d6fdf773d3e015f8b19fe5c4ccb07723d
Expand Down
2 changes: 1 addition & 1 deletion docker/ckb/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

if ! [ -f ckb.toml ]; then
/bin/ckb init --chain "$CKB_CHAIN" --import-spec /var/dev.toml --ba-arg "$BA_ARG" --ba-code-hash "$BA_CODE_HASH" --ba-hash-type "$BA_HASH_TYPE" --ba-message "$BA_MESSAGE" \
&& sed -ic 's/filter = "info"/filter = "info,ckb-script=debug"/g' ckb.toml
&& sed -ic 's/filter = "info"/filter = "info,ckb-script=debug"/g' ckb.toml && sed -ic 's/modules = \[/modules = \["Indexer",/g' ckb.toml
fi

exec /bin/ckb run &
Expand Down
30 changes: 15 additions & 15 deletions docker/docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,28 @@ services:
aliases:
- geth-dev
ckb-dev:
image: tockb/ckb-dev:v0.100.0
image: nervos/ckb:v0.111.0
ports:
- "3001:8114"
networks:
force-dev-net:
ipv4_address: 10.4.0.11
aliases:
- ckb-dev
ckb-indexer-dev:
image: tockb/ckb-indexer:v0.3.0
ports:
- "3002:8116"
environment:
- RUST_LOG=info
command: ckb-indexer -s /tmp/ckb-indexer-test -c http://ckb-dev:8114 -l 0.0.0.0:8116
depends_on:
- ckb-dev
networks:
force-dev-net:
ipv4_address: 10.4.0.12
aliases:
- ckb-indexer-dev
# ckb-indexer-dev:
# image: tockb/ckb-indexer:v0.3.0
# ports:
# - "3002:8116"
# environment:
# - RUST_LOG=info
# command: ckb-indexer -s /tmp/ckb-indexer-test -c http://ckb-dev:8114 -l 0.0.0.0:8116
# depends_on:
# - ckb-dev
# networks:
# force-dev-net:
# ipv4_address: 10.4.0.12
# aliases:
# - ckb-indexer-dev
volumes:
geth-dag:
networks:
Expand Down
30 changes: 15 additions & 15 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,28 @@ services:
aliases:
- mysql
ckb:
image: tockb/ckb-dev:v0.100.0
image: forcebridge/ckb-dev:v0.111.0
ports:
- "8114:8114"
networks:
forcenet:
ipv4_address: 10.5.0.11
aliases:
- ckb
ckb-indexer:
image: tockb/ckb-indexer:v0.3.0
ports:
- "8116:8116"
environment:
- RUST_LOG=info
command: ckb-indexer -s /tmp/ckb-indexer-test -c http://ckb:8114 -l 0.0.0.0:8116
depends_on:
- ckb
networks:
forcenet:
ipv4_address: 10.5.0.12
aliases:
- ckb-indexer
# ckb-indexer:
# image: tockb/ckb-indexer:v0.3.0
# ports:
# - "8116:8116"
# environment:
# - RUST_LOG=info
# command: ckb-indexer -s /tmp/ckb-indexer-test -c http://ckb:8114 -l 0.0.0.0:8116
# depends_on:
# - ckb
# networks:
# forcenet:
# ipv4_address: 10.5.0.12
# aliases:
# - ckb-indexer
geth:
image: tockb/geth-priv:v1.10.10
volumes:
Expand Down
7 changes: 5 additions & 2 deletions offchain-modules/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@
"nyc": "^15.1.0",
"prettier": "^2.2.1",
"rimraf": "^3.0.2",
"ts-node-dev": "^1.1.1",
"typescript": "^4.2.2"
"ts-node-dev": "^2.0.0",
"typescript": "^4.5"
},
"ava": {
"files": [
Expand Down Expand Up @@ -123,5 +123,8 @@
},
"engines": {
"node": "14.x"
},
"dependencies": {
"ts-node": "^10.9.2"
}
}
4 changes: 0 additions & 4 deletions offchain-modules/packages/app-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@
"test": "yarn run build"
},
"dependencies": {
"@ckb-lumos/base": "0.18.0-rc3",
"@ckb-lumos/common-scripts": "0.18.0-rc3",
"@ckb-lumos/hd": "0.18.0-rc3",
"@ckb-lumos/helpers": "0.18.0-rc3",
"@force-bridge/app-monitor": "^0.0.38",
"@force-bridge/app-multisign-server": "^0.0.38",
"@force-bridge/app-relayer": "^0.0.38",
Expand Down
4 changes: 2 additions & 2 deletions offchain-modules/packages/app-cli/src/bridgeFee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { bootstrap, ForceBridgeCore } from '@force-bridge/x/dist/core';
import { BridgeFeeDB } from '@force-bridge/x/dist/db';
import { getDBConnection, parsePrivateKey } from '@force-bridge/x/dist/utils';
import { EthChain, WithdrawBridgeFeeTopic } from '@force-bridge/x/dist/xchain/eth';
import { Amount } from '@lay2/pw-core';
import commander from 'commander';
import { ecsign, toRpcSig } from 'ethereumjs-util';
import { BigNumber } from 'ethers';

const defaultConfig = './config.json';

Expand Down Expand Up @@ -103,7 +103,7 @@ async function getTotalAvailable(opts: Record<string, string>) {

const withdrawedBridgeFee = await bridgeFeeDB.getEthTotalWithdrawedBridgeFee(asset);
const generatedBridgeFee = await bridgeFeeDB.getEthTotalGeneratedBridgeFee(asset);
const availableBridgeFee = new Amount(generatedBridgeFee, 0).sub(new Amount(withdrawedBridgeFee, 0)).toString(0);
const availableBridgeFee = BigNumber.from(generatedBridgeFee).sub(BigNumber.from(withdrawedBridgeFee)).toString();
const humanizedAvailableBridgeFee = ethAsset.getHumanizedDescription(availableBridgeFee);
console.log('total available bridge fee:', humanizedAvailableBridgeFee);
}
Expand Down
23 changes: 12 additions & 11 deletions offchain-modules/packages/app-cli/src/changeVal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
generateSecp256k1Blake160Address,
minimalCellCapacity,
objectToTransactionSkeleton,
transactionSkeletonToObject,
sealTransaction,
TransactionSkeleton,
TransactionSkeletonObject,
Expand All @@ -18,7 +19,7 @@ import { initLumosConfig } from '@force-bridge/x/dist/ckb/tx-helper/init_lumos_c
import { getMultisigLock } from '@force-bridge/x/dist/ckb/tx-helper/multisig/multisig_helper';
import { MultisigItem } from '@force-bridge/x/dist/config';
import { httpRequest } from '@force-bridge/x/dist/multisig/client';
import { privateKeyToCkbPubkeyHash, transactionSkeletonToJSON, writeJsonToFile } from '@force-bridge/x/dist/utils';
import { privateKeyToCkbPubkeyHash, writeJsonToFile } from '@force-bridge/x/dist/utils';
import { buildChangeValidatorsSigRawData } from '@force-bridge/x/dist/xchain/eth';
import { abi } from '@force-bridge/x/dist/xchain/eth/abi/ForceBridge.json';
import commander from 'commander';
Expand Down Expand Up @@ -155,7 +156,7 @@ async function doMakeTx(opts: Record<string, string>): Promise<void> {
newMultisigScript: newMultisigItem,
oldMultisigItem: valInfos.ckb.oldValInfos,
signature: [],
txSkeleton: txSkeleton.toJS(),
txSkeleton: transactionSkeletonToObject(txSkeleton),
};
}

Expand Down Expand Up @@ -260,22 +261,22 @@ async function generateCkbChangeValTx(
const oldMultisigCell = await ckbClient.fetchMultisigCell(oldMultisigLockscript, xchainCellData);

const newOwnerCell: Cell = {
cell_output: {
cellOutput: {
capacity: '0x0',
lock: newMultisigLockscript,
type: oldOwnerCell!.cell_output.type,
type: oldOwnerCell!.cellOutput.type,
},
data: '0x',
};
newOwnerCell.cell_output.capacity = `0x${minimalCellCapacity(newOwnerCell).toString(16)}`;
newOwnerCell.cellOutput.capacity = `0x${minimalCellCapacity(newOwnerCell).toString(16)}`;
const newMultiCell: Cell = {
cell_output: {
cellOutput: {
capacity: '0x0',
lock: newMultisigLockscript,
},
data: xchainCellData,
};
newMultiCell.cell_output.capacity = `0x${minimalCellCapacity(newMultiCell).toString(16)}`;
newMultiCell.cellOutput.capacity = `0x${minimalCellCapacity(newMultiCell).toString(16)}`;

txSkeleton = await common.setupInputCell(txSkeleton, oldOwnerCell!, oldMultisigItem);
txSkeleton = await common.setupInputCell(txSkeleton, oldMultisigCell!, oldMultisigItem);
Expand Down Expand Up @@ -320,9 +321,9 @@ async function sendCkbChangeValTx(
});
content1 += signatures.join('');

console.debug(`txSkeleton: ${transactionSkeletonToJSON(txSkeleton)}`);
console.debug(`txSkeleton: ${txSkeleton.toJSON()}`);
const tx = sealTransaction(txSkeleton, [content0, content1]);
const hash = await ckbClient.ckb.send_transaction(tx, 'passthrough');
const hash = await ckbClient.ckb.sendTransaction(tx, 'passthrough');
console.log(`change tx hash ${hash}`);
await ckbClient.waitUntilCommitted(hash);
return;
Expand Down Expand Up @@ -423,7 +424,7 @@ export class CkbChangeValClient extends CkbTxHelper {
data: '0x',
});
for await (const cell of cellCollector.collect()) {
if (cell.cell_output.type && cell.cell_output.type.args === ownerCellTypescriptArgs) {
if (cell.cellOutput.type && cell.cellOutput.type.args === ownerCellTypescriptArgs) {
return cell;
}
}
Expand All @@ -435,7 +436,7 @@ export class CkbChangeValClient extends CkbTxHelper {
data: xchainCellData,
});
for await (const cell of cellCollector.collect()) {
if (cell.cell_output.type === null && cell.data === xchainCellData) {
if (cell.cellOutput.type === null && cell.data === xchainCellData) {
return cell;
}
}
Expand Down
10 changes: 5 additions & 5 deletions offchain-modules/packages/app-cli/src/eth.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { ForceBridgeAPIV1Client } from '@force-bridge/app-rpc-server/dist/client';
import { nonNullable } from '@force-bridge/x';
import { privateKeyToCkbAddress } from '@force-bridge/x/dist/utils';
import { Amount } from '@lay2/pw-core';
import CKB from '@nervosnetwork/ckb-sdk-core';
import commander from 'commander';
import { ethers } from 'ethers';
import { BigNumber, ethers } from 'ethers';
import { parseUnits, formatUnits } from 'ethers/lib/utils';
import { waitUnlockCompleted } from './utils';

const ForceBridgeRpc = 'http://47.56.233.149:3083/force-bridge/api/v1';
Expand Down Expand Up @@ -82,7 +82,7 @@ async function doLock(opts: Record<string, string | boolean>) {
asset: {
network: 'Ethereum',
ident: assetInfo.ident,
amount: new Amount(amount, assetInfo.info.decimals).toString(0),
amount: parseUnits(amount, assetInfo.info.decimals).toString(),
},
};
const lockTx = nonNullable(
Expand Down Expand Up @@ -139,7 +139,7 @@ async function doUnlock(opts: Record<string, string | boolean>) {
sender: ckbAddress,
recipient: recipientAddress,
asset: assetInfo.info.shadow.ident,
amount: new Amount(amount, assetInfo.info.decimals).toString(0),
amount: parseUnits(amount, assetInfo.info.decimals).toString(),
};

const unlockTx = await new ForceBridgeAPIV1Client(forceBridgeRpc).generateBridgeOutNervosTransaction(burnPayload);
Expand Down Expand Up @@ -178,7 +178,7 @@ async function doBalanceOf(opts: Record<string, string>) {
]);
balances.forEach((balance) => {
console.log(
`Address:${address} balance:${new Amount(balance.amount, 0).toString(assetInfo.info.decimals)} ${
`Address:${address} balance:${formatUnits(BigNumber.from(balance.amount), assetInfo.info.decimals)} ${
assetInfo.info.symbol
}`,
);
Expand Down
4 changes: 2 additions & 2 deletions offchain-modules/packages/app-cli/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export async function getSudtBalance(address: string, asset: Asset): Promise<big
};
const sudtArgs = ForceBridgeCore.ckb.utils.scriptToHash(<CKBComponents.Script>bridgeCellLockscript);
const sudtType = {
code_hash: ForceBridgeCore.config.ckb.deps.sudtType.script.codeHash,
hash_type: ForceBridgeCore.config.ckb.deps.sudtType.script.hashType,
codeHash: ForceBridgeCore.config.ckb.deps.sudtType.script.codeHash,
hashType: ForceBridgeCore.config.ckb.deps.sudtType.script.hashType,
args: sudtArgs,
};

Expand Down
4 changes: 2 additions & 2 deletions offchain-modules/packages/app-monitor/src/balanceProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ export class BalanceProvider {
async ckbSudtBalance(tokenAddress: string, name: string): Promise<bigint> {
const typescriptLike = new EthAsset(tokenAddress, this.ownerTypeHash).toTypeScript();
const typescript = {
code_hash: typescriptLike.codeHash,
hash_type: typescriptLike.hashType,
codeHash: typescriptLike.codeHash,
hashType: typescriptLike.hashType,
args: typescriptLike.args,
};
const searchKey: SearchKey = {
Expand Down
4 changes: 2 additions & 2 deletions offchain-modules/packages/app-monitor/src/monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ export class Monitor {
const mintRecipientLockscript = parseAddress(mint.recipient);
if (
lockRecipientLockscript.args !== mintRecipientLockscript.args ||
lockRecipientLockscript.hash_type !== mintRecipientLockscript.hash_type ||
lockRecipientLockscript.code_hash !== mintRecipientLockscript.code_hash
lockRecipientLockscript.hashType !== mintRecipientLockscript.hashType ||
lockRecipientLockscript.codeHash !== mintRecipientLockscript.codeHash
) {
return `lock.recipient:${lock.recipient} != mint.recipient:${mint.recipient}`;
}
Expand Down
Loading

0 comments on commit 9abb302

Please sign in to comment.