Skip to content

Commit

Permalink
upgrate lumos to 0.19
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangyouxin committed Aug 12, 2022
1 parent 9f4fbd2 commit 306ae30
Show file tree
Hide file tree
Showing 21 changed files with 464 additions and 384 deletions.
8 changes: 4 additions & 4 deletions packages/light-godwoken/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
"dist"
],
"dependencies": {
"@ckb-lumos/bi": "^0.17.0-rc10",
"@ckb-lumos/base": "^0.17.0-rc10",
"@ckb-lumos/codec": "^0.17.0-rc10",
"@ckb-lumos/lumos": "^0.17.0-rc10",
"@ckb-lumos/bi": "^0.19.0-alpha.0",
"@ckb-lumos/base": "^0.19.0-alpha.0",
"@ckb-lumos/codec": "^0.19.0-alpha.0",
"@ckb-lumos/lumos": "^0.19.0-alpha.0",
"@polyjuice-provider/base": "^0.1.1",
"@polyjuice-provider/ethers": "^0.1.5",
"@polyjuice-provider/godwoken": "^0.1.1",
Expand Down
31 changes: 15 additions & 16 deletions packages/light-godwoken/src/LightGodwokenV0.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { BI, Hash, HashType, helpers, HexNumber, HexString, Script, toolkit, utils } from "@ckb-lumos/lumos";
import { Hexadecimal } from "@ckb-lumos/base";
import EventEmitter from "events";
import DefaultLightGodwoken from "./lightGodwoken";
import {
Expand Down Expand Up @@ -61,11 +60,11 @@ export default class DefaultLightGodwokenV0 extends DefaultLightGodwoken impleme
getMinimalWithdrawalCapacity(): BI {
const minimalCapacity =
8 + // capacity
32 + // withdrawal_lock.code_hash
1 + // withdrawal_lock.hash_type
32 + // withdrawal_lock.codeHash
1 + // withdrawal_lock.hashType
303 + // withdrawal_lock.args TODO: explain why this is 303
32 + // sudt_type.code_hash
1 + // sudt_type.hash_type
32 + // sudt_type.codeHash
1 + // sudt_type.hashType
32 + // sudt_type.args
16; // sudt_amount

Expand Down Expand Up @@ -104,8 +103,8 @@ export default class DefaultLightGodwokenV0 extends DefaultLightGodwoken impleme
const sudtScriptConfig = this.provider.getConfig().layer1Config.SCRIPTS.sudt;
getTokenList().v0.forEach((token) => {
const tokenL1Script: Script = {
code_hash: sudtScriptConfig.code_hash,
hash_type: sudtScriptConfig.hash_type as HashType,
codeHash: sudtScriptConfig.codeHash,
hashType: sudtScriptConfig.hashType as HashType,
args: token.l1LockArgs,
};
const tokenScriptHash = utils.computeScriptHash(tokenL1Script);
Expand Down Expand Up @@ -138,8 +137,8 @@ export default class DefaultLightGodwokenV0 extends DefaultLightGodwoken impleme
const sudtScriptConfig = this.provider.getConfig().layer1Config.SCRIPTS.sudt;
getTokenList().v0.forEach((token) => {
const tokenL1Script: Script = {
code_hash: sudtScriptConfig.code_hash,
hash_type: sudtScriptConfig.hash_type as HashType,
codeHash: sudtScriptConfig.codeHash,
hashType: sudtScriptConfig.hashType as HashType,
args: token.l1LockArgs,
};
map.push({
Expand Down Expand Up @@ -223,7 +222,7 @@ export default class DefaultLightGodwokenV0 extends DefaultLightGodwoken impleme
return { balances: balances.map((b) => b.toHexString()) };
}

async getErc20Balance(address: HexString): Promise<Hexadecimal> {
async getErc20Balance(address: HexString): Promise<HexNumber> {
const contract = new this.provider.web3.eth.Contract(SUDT_ERC20_PROXY_ABI as AbiItems, address);
return await contract.methods.balanceOf(this.provider.l2Address).call();
}
Expand Down Expand Up @@ -253,8 +252,8 @@ export default class DefaultLightGodwokenV0 extends DefaultLightGodwoken impleme
return {
isFastWithdrawal: item.is_fast_withdrawal,
layer1TxHash: item.layer1_tx_hash,
withdrawalBlockNumber: item.block_number,
remainingBlockNumber: Math.max(0, item.block_number - lastFinalizedBlockNumber),
withdrawalBlockNumber: item.blockNumber,
remainingBlockNumber: Math.max(0, item.blockNumber - lastFinalizedBlockNumber),
capacity: BI.from(item.capacity).toHexString(),
amount,
sudt_script_hash: item.udt_script_hash,
Expand All @@ -273,8 +272,8 @@ export default class DefaultLightGodwokenV0 extends DefaultLightGodwoken impleme
const { layer2Config } = this.provider.getLightGodwokenConfig();
return {
script: {
code_hash: layer2Config.SCRIPTS.withdrawal_lock.script_type_hash,
hash_type: "type" as HashType,
codeHash: layer2Config.SCRIPTS.withdrawal_lock.script_type_hash,
hashType: "type" as HashType,
args: `${layer2Config.ROLLUP_CONFIG.rollup_type_hash}${accountScriptHash.slice(2)}`,
},
script_type: "lock",
Expand Down Expand Up @@ -480,8 +479,8 @@ export default class DefaultLightGodwokenV0 extends DefaultLightGodwoken impleme
).serializeJson();
const { SCRIPTS, ROLLUP_CONFIG } = this.provider.getLightGodwokenConfig().layer2Config;
const depositLock: Script = {
code_hash: SCRIPTS.deposit_lock.script_type_hash,
hash_type: "type",
codeHash: SCRIPTS.deposit_lock.script_type_hash,
hashType: "type",
args: ROLLUP_CONFIG.rollup_type_hash + depositLockArgsHexString.slice(2),
};
return depositLock;
Expand Down
28 changes: 14 additions & 14 deletions packages/light-godwoken/src/LightGodwokenV1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ export default class DefaultLightGodwokenV1 extends DefaultLightGodwoken impleme
const sudtScriptConfig = this.provider.getConfig().layer1Config.SCRIPTS.sudt;
getTokenList().v1.forEach((token) => {
const tokenL1Script: Script = {
code_hash: sudtScriptConfig.code_hash,
hash_type: sudtScriptConfig.hash_type as HashType,
codeHash: sudtScriptConfig.codeHash,
hashType: sudtScriptConfig.hashType as HashType,
args: token.l1LockArgs,
};
sudtList.push({
Expand All @@ -134,8 +134,8 @@ export default class DefaultLightGodwokenV1 extends DefaultLightGodwoken impleme
const sudtScriptConfig = this.provider.getConfig().layer1Config.SCRIPTS.sudt;
getTokenList().v1.forEach((token) => {
const tokenL1Script: Script = {
code_hash: sudtScriptConfig.code_hash,
hash_type: sudtScriptConfig.hash_type as HashType,
codeHash: sudtScriptConfig.codeHash,
hashType: sudtScriptConfig.hashType as HashType,
args: token.l1LockArgs,
};
const tokenScriptHash = utils.computeScriptHash(tokenL1Script);
Expand Down Expand Up @@ -229,8 +229,8 @@ export default class DefaultLightGodwokenV1 extends DefaultLightGodwoken impleme
}
return {
layer1TxHash: item.layer1_tx_hash,
withdrawalBlockNumber: item.block_number,
remainingBlockNumber: Math.max(0, item.block_number - lastFinalizedBlockNumber),
withdrawalBlockNumber: item.blockNumber,
remainingBlockNumber: Math.max(0, item.blockNumber - lastFinalizedBlockNumber),
capacity: BI.from(item.capacity).toHexString(),
amount,
sudt_script_hash: item.udt_script_hash,
Expand All @@ -248,8 +248,8 @@ export default class DefaultLightGodwokenV1 extends DefaultLightGodwoken impleme
const { layer2Config } = this.provider.getLightGodwokenConfig();
return {
script: {
code_hash: layer2Config.SCRIPTS.withdrawal_lock.script_type_hash,
hash_type: "type" as HashType,
codeHash: layer2Config.SCRIPTS.withdrawal_lock.script_type_hash,
hashType: "type" as HashType,
args: "0x",
},
script_type: "lock",
Expand Down Expand Up @@ -329,8 +329,8 @@ export default class DefaultLightGodwokenV1 extends DefaultLightGodwoken impleme
chainId: Number(rawWithdrawalRequest.chain_id),
fee: 0,
layer1OwnerLock: {
codeHash: ownerLock.code_hash,
hashType: ownerLock.hash_type,
codeHash: ownerLock.codeHash,
hashType: ownerLock.hashType,
args: ownerLock.args,
},
withdraw: {
Expand Down Expand Up @@ -384,8 +384,8 @@ export default class DefaultLightGodwokenV1 extends DefaultLightGodwoken impleme
const ownerLockHash = utils.computeScriptHash(ownerLock);
const ethAddress = this.provider.l2Address;
const l2AccountScript: Script = {
code_hash: layer2Config.SCRIPTS.eth_account_lock.script_type_hash,
hash_type: "type",
codeHash: layer2Config.SCRIPTS.eth_account_lock.script_type_hash,
hashType: "type",
args: layer2Config.ROLLUP_CONFIG.rollup_type_hash + ethAddress.slice(2),
};
const layer2AccountScriptHash = utils.computeScriptHash(l2AccountScript);
Expand Down Expand Up @@ -464,8 +464,8 @@ export default class DefaultLightGodwokenV1 extends DefaultLightGodwoken impleme
const { SCRIPTS, ROLLUP_CONFIG } = this.provider.getLightGodwokenConfig().layer2Config;

const depositLock: Script = {
code_hash: SCRIPTS.deposit_lock.script_type_hash,
hash_type: "type",
codeHash: SCRIPTS.deposit_lock.script_type_hash,
hashType: "type",
args: ROLLUP_CONFIG.rollup_type_hash + depositLockArgsHexString.slice(2),
};
return depositLock;
Expand Down
8 changes: 4 additions & 4 deletions packages/light-godwoken/src/__tests__/codec.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ describe("test codec", () => {
const depositArgs = {
owner_lock_hash: "0xea8e5a6ed260ee56af7d66ddb8c7c09a3ade6c38d207c30a6d11b3d8e11387df",
layer2_lock: {
code_hash: "0x07521d0aa8e66ef441ebc31204d86bb23fc83e9edc58c19dbb1b0ebe64336ec0",
hash_type: "type",
codeHash: "0x07521d0aa8e66ef441ebc31204d86bb23fc83e9edc58c19dbb1b0ebe64336ec0",
hashType: "type",
args: "0x702359ea7f073558921eb50d8c1c77e92f760c8f8656bde4995f26b8963e2dd862a67949836b389ec146b3b2187e949f7faef679",
},
cancel_timeout: BI.from("0xc0000000000004b0"),
Expand All @@ -35,8 +35,8 @@ describe("test codec", () => {
const depositArgs = {
owner_lock_hash: "0xea8e5a6ed260ee56af7d66ddb8c7c09a3ade6c38d207c30a6d11b3d8e11387df",
layer2_lock: {
code_hash: "0x07521d0aa8e66ef441ebc31204d86bb23fc83e9edc58c19dbb1b0ebe64336ec0",
hash_type: "type",
codeHash: "0x07521d0aa8e66ef441ebc31204d86bb23fc83e9edc58c19dbb1b0ebe64336ec0",
hashType: "type",
args: "0x702359ea7f073558921eb50d8c1c77e92f760c8f8656bde4995f26b8963e2dd862a67949836b389ec146b3b2187e949f7faef679",
},
cancel_timeout: BI.from("0xc000000000093a81"),
Expand Down
22 changes: 11 additions & 11 deletions packages/light-godwoken/src/__tests__/lightGodwoken.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe("test light godwoken generateDepositOutputCell", () => {
capacity: BI.from(400e8).toHexString(),
});
expect(outputCells.length).toEqual(1);
expect(outputCells[0].cell_output.capacity).toEqual(BI.from(400e8).toHexString());
expect(outputCells[0].cellOutput.capacity).toEqual(BI.from(400e8).toHexString());
});
it("should deposit 400 CKB, 300 pure CKB and 100 free CKB", async () => {
const typeScript: Script = randomSudtTypeScript(lightGodwokenV1.getConfig());
Expand All @@ -40,9 +40,9 @@ describe("test light godwoken generateDepositOutputCell", () => {
});
const [sudtExchangeCell, depositCell] = outputCells;
expect(outputCells.length).toEqual(2);
expect(sudtExchangeCell.cell_output.capacity).toEqual(BI.from(144e8).toHexString());
expect(sudtExchangeCell.cell_output.type).toEqual(typeScript);
expect(depositCell.cell_output.capacity).toEqual(BI.from(400e8).toHexString());
expect(sudtExchangeCell.cellOutput.capacity).toEqual(BI.from(144e8).toHexString());
expect(sudtExchangeCell.cellOutput.type).toEqual(typeScript);
expect(depositCell.cellOutput.capacity).toEqual(BI.from(400e8).toHexString());
});
it("should deposit 400 CKB, 250 pure CKB and 100 from free CKB and 50 from sudt cell", async () => {
const freeTypeScript: Script = randomSudtTypeScript(lightGodwokenV1.getConfig());
Expand All @@ -58,15 +58,15 @@ describe("test light godwoken generateDepositOutputCell", () => {
const [sudtExchangeCell, depositCell, ckbExchangeCell] = outputCells;
expect(outputCells.length).toEqual(3);
// output 0 is free ckb provider cell after taken free ckb away
expect(sudtExchangeCell.cell_output.capacity).toEqual(BI.from(144e8).toHexString());
expect(sudtExchangeCell.cell_output.type).toEqual(freeTypeScript);
expect(sudtExchangeCell.cellOutput.capacity).toEqual(BI.from(144e8).toHexString());
expect(sudtExchangeCell.cellOutput.type).toEqual(freeTypeScript);
// output 1 is deposit cell
expect(depositCell.cell_output.capacity).toEqual(BI.from(400e8).toHexString());
expect(depositCell.cell_output.type).toEqual(depositSudtTypeScript);
expect(depositCell.cellOutput.capacity).toEqual(BI.from(400e8).toHexString());
expect(depositCell.cellOutput.type).toEqual(depositSudtTypeScript);
// output 2 is exchangecell
expect(ckbExchangeCell.cell_output.capacity).toEqual(BI.from(144e8).toHexString());
expect(ckbExchangeCell.cell_output.type).toEqual(undefined);
expect(ckbExchangeCell.cell_output.lock).toEqual(lightGodwokenV1.provider.getLayer1Lock());
expect(ckbExchangeCell.cellOutput.capacity).toEqual(BI.from(144e8).toHexString());
expect(ckbExchangeCell.cellOutput.type).toEqual(undefined);
expect(ckbExchangeCell.cellOutput.lock).toEqual(lightGodwokenV1.provider.getLayer1Lock());
});
it("should generateDepositTx if user deposit 400 CKB, and user has 250 pure CKB and 100 from free CKB and 50 from sudt cell", async () => {
const freeTypeScript: Script = randomSudtTypeScript(lightGodwokenV1.getConfig());
Expand Down
56 changes: 28 additions & 28 deletions packages/light-godwoken/src/__tests__/lightGodwokenConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@ import { Layer1Config, LightGodwokenConfigMap } from "../constants/configTypes";
const layer1ConfigAggron: Layer1Config = {
SCRIPTS: {
omni_lock: {
code_hash: "0x79f90bb5e892d80dd213439eeab551120eb417678824f282b4ffb5f21bad2e1e",
hash_type: "type",
tx_hash: "0x9154df4f7336402114d04495175b37390ce86a4906d2d4001cf02c3e6d97f39c",
codeHash: "0x79f90bb5e892d80dd213439eeab551120eb417678824f282b4ffb5f21bad2e1e",
hashType: "type",
txHash: "0x9154df4f7336402114d04495175b37390ce86a4906d2d4001cf02c3e6d97f39c",
index: "0x0",
dep_type: "code",
depType: "code",
},
secp256k1_blake160: {
code_hash: "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8",
hash_type: "type",
tx_hash: "0xf8de3bb47d055cdf460d93a2a6e1b05f7432f9777c8c474abf4eec1d4aee5d37",
codeHash: "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8",
hashType: "type",
txHash: "0xf8de3bb47d055cdf460d93a2a6e1b05f7432f9777c8c474abf4eec1d4aee5d37",
index: "0x0",
dep_type: "dep_group",
depType: "depGroup",
},
sudt: {
code_hash: "0xc5e5dcf215925f7ef4dfaf5f4b4f105bc321c02776d6e7d52a1db3fcd9d011a4",
hash_type: "type",
tx_hash: "0xe12877ebd2c3c364dc46c5c992bcfaf4fee33fa13eebdf82c591fc9825aab769",
codeHash: "0xc5e5dcf215925f7ef4dfaf5f4b4f105bc321c02776d6e7d52a1db3fcd9d011a4",
hashType: "type",
txHash: "0xe12877ebd2c3c364dc46c5c992bcfaf4fee33fa13eebdf82c591fc9825aab769",
index: "0x0",
dep_type: "code",
depType: "code",
},
},
CKB_INDEXER_URL: "https://testnet.ckb.dev/indexer",
Expand All @@ -37,21 +37,21 @@ export const testConfig: LightGodwokenConfigMap = {
deposit_lock: {
script_type_hash: "0x5a2506bb68d81a11dcadad4cb7eae62a17c43c619fe47ac8037bc8ce2dd90360",
cell_dep: {
out_point: {
tx_hash: "0x9caeec735f3cd2a60b9d12be59bb161f7c61ddab1ac22c4383a94c33ba6404a2",
outPoint: {
txHash: "0x9caeec735f3cd2a60b9d12be59bb161f7c61ddab1ac22c4383a94c33ba6404a2",
index: "0x0",
},
dep_type: "code",
depType: "code",
},
},
withdrawal_lock: {
script_type_hash: "0x170ef156e9f6132dbca6069dfd3e436f7d91c29d3ac7332c4b33e633b6a299b5",
cell_dep: {
out_point: {
tx_hash: "0xb4b07dcd1571ac18683b515ada40e13b99bd0622197b6817047adc9f407f4828",
outPoint: {
txHash: "0xb4b07dcd1571ac18683b515ada40e13b99bd0622197b6817047adc9f407f4828",
index: "0x0",
},
dep_type: "code",
depType: "code",
},
},
eth_account_lock: {
Expand All @@ -61,8 +61,8 @@ export const testConfig: LightGodwokenConfigMap = {
ROLLUP_CONFIG: {
rollup_type_hash: "0x4cc2e6526204ae6a2e8fcf12f7ad472f41a1606d5b9624beebd215d780809f6a",
rollup_type_script: {
code_hash: "0x5c365147bb6c40e817a2a53e0dec3661f7390cc77f0c02db138303177b12e9fb",
hash_type: "type",
codeHash: "0x5c365147bb6c40e817a2a53e0dec3661f7390cc77f0c02db138303177b12e9fb",
hashType: "type",
args: "0x213743d13048e9f36728c547ab736023a7426e15a3d7d1c82f43ec3b5f266df2",
},
},
Expand All @@ -82,21 +82,21 @@ export const testConfig: LightGodwokenConfigMap = {
deposit_lock: {
script_type_hash: "0x50704b84ecb4c4b12b43c7acb260ddd69171c21b4c0ba15f3c469b7d143f6f18",
cell_dep: {
out_point: {
tx_hash: "0x9caeec735f3cd2a60b9d12be59bb161f7c61ddab1ac22c4383a94c33ba6404a2",
outPoint: {
txHash: "0x9caeec735f3cd2a60b9d12be59bb161f7c61ddab1ac22c4383a94c33ba6404a2",
index: "0x0",
},
dep_type: "code",
depType: "code",
},
},
withdrawal_lock: {
script_type_hash: "0x06ae0706bb2d7997d66224741d3ec7c173dbb2854a6d2cf97088796b677269c6",
cell_dep: {
out_point: {
tx_hash: "0x9c607a9a75ea4699dd01b1c2a478002343998cac8346d2aa582f35b532bd2b93",
outPoint: {
txHash: "0x9c607a9a75ea4699dd01b1c2a478002343998cac8346d2aa582f35b532bd2b93",
index: "0x0",
},
dep_type: "code",
depType: "code",
},
},
eth_account_lock: {
Expand All @@ -106,8 +106,8 @@ export const testConfig: LightGodwokenConfigMap = {
ROLLUP_CONFIG: {
rollup_type_hash: "0x702359ea7f073558921eb50d8c1c77e92f760c8f8656bde4995f26b8963e2dd8",
rollup_type_script: {
code_hash: "0x1e44736436b406f8e48a30dfbddcf044feb0c9eebfe63b0f81cb5bb727d84854",
hash_type: "type",
codeHash: "0x1e44736436b406f8e48a30dfbddcf044feb0c9eebfe63b0f81cb5bb727d84854",
hashType: "type",
args: "0x86c7429247beba7ddd6e4361bcdfc0510b0b644131e2afb7e486375249a01802",
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ describe("test light godwoken v1 deposit", () => {
const lock = await lightGodwokenV1.generateDepositLock();
expect(lock).toEqual({
args: "0x702359ea7f073558921eb50d8c1c77e92f760c8f8656bde4995f26b8963e2dd8a900000014000000340000009d000000a50000003837aad0e28da55d366d62b7df9b1b0613c39c730c4c409b9722d4bed8cfa9266900000010000000300000003100000007521d0aa8e66ef441ebc31204d86bb23fc83e9edc58c19dbb1b0ebe64336ec00134000000702359ea7f073558921eb50d8c1c77e92f760c8f8656bde4995f26b8963e2dd80c1efcca2bcb65a532274f3ef24c044ef4ab6d73803a0900000000c002000000",
code_hash: "0x50704b84ecb4c4b12b43c7acb260ddd69171c21b4c0ba15f3c469b7d143f6f18",
hash_type: "type",
codeHash: "0x50704b84ecb4c4b12b43c7acb260ddd69171c21b4c0ba15f3c469b7d143f6f18",
hashType: "type",
});
});
it("should deposit 2000 ckb ok when user balance is 2000", async () => {
Expand All @@ -95,7 +95,7 @@ describe("test light godwoken v1 deposit", () => {
capacity: BI.from(2000).mul(BI.from(10).pow(8)).toHexString(),
});

expect(tx.outputs.get(0)?.cell_output.capacity).toEqual(BI.from(2000).mul(BI.from(10).pow(8)).toHexString());
expect(tx.outputs.get(0)?.cellOutput.capacity).toEqual(BI.from(2000).mul(BI.from(10).pow(8)).toHexString());
expect(outputCapacityOf(tx).toString()).toEqual("2000");
});
it("should deposit 2000 ckb fail when user balance is 1999", async () => {
Expand Down Expand Up @@ -158,7 +158,7 @@ describe("test light godwoken v0 deposit", () => {
capacity: BI.from(2000).mul(BI.from(10).pow(8)).toHexString(),
});

expect(tx.outputs.get(0)?.cell_output.capacity).toEqual(BI.from(2000).mul(BI.from(10).pow(8)).toHexString());
expect(tx.outputs.get(0)?.cellOutput.capacity).toEqual(BI.from(2000).mul(BI.from(10).pow(8)).toHexString());
expect(outputCapacityOf(tx).toString()).toEqual("2000");
});
it("should deposit 2000 ckb fail when user balance is 1999", async () => {
Expand Down
Loading

0 comments on commit 306ae30

Please sign in to comment.