-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #426 from nervosnetwork/rc/v0.29.1
[ᚬmaster] Rc/v0.29.1
- Loading branch information
Showing
14 changed files
with
250 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,5 +4,5 @@ | |
], | ||
"npmClient": "yarn", | ||
"useWorkspaces": true, | ||
"version": "0.29.0" | ||
"version": "0.29.1" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
{ | ||
"calculateLockEpochs": [ | ||
{ | ||
"depositEpoch": { | ||
"number": "0", | ||
"index": "0", | ||
"length": "100" | ||
}, | ||
"withdrawEpoch": { | ||
"number": "0", | ||
"index": "0", | ||
"length": "100" | ||
}, | ||
"expected": "180" | ||
}, | ||
{ | ||
"depositEpoch": { | ||
"number": "1", | ||
"index": "0", | ||
"length": "100" | ||
}, | ||
"withdrawEpoch": { | ||
"number": "1", | ||
"index": "0", | ||
"length": "100" | ||
}, | ||
"expected": "180" | ||
}, | ||
{ | ||
"depositEpoch": { | ||
"number": "0", | ||
"index": "0", | ||
"length": "100" | ||
}, | ||
"withdrawEpoch": { | ||
"number": "179", | ||
"index": "0", | ||
"length": "100" | ||
}, | ||
"expected": "180" | ||
}, | ||
{ | ||
"depositEpoch": { | ||
"number": "0", | ||
"index": "0", | ||
"length": "100" | ||
}, | ||
"withdrawEpoch": { | ||
"number": "179", | ||
"index": "0", | ||
"length": "100" | ||
}, | ||
"expected": "180" | ||
}, | ||
{ | ||
"depositEpoch": { | ||
"number": "0", | ||
"index": "1", | ||
"length": "100" | ||
}, | ||
"withdrawEpoch": { | ||
"number": "179", | ||
"index": "0", | ||
"length": "100" | ||
}, | ||
"expected": "180" | ||
}, | ||
{ | ||
"depositEpoch": { | ||
"number": "0", | ||
"index": "0", | ||
"length": "100" | ||
}, | ||
"withdrawEpoch": { | ||
"number": "179", | ||
"index": "1", | ||
"length": "100" | ||
}, | ||
"expected": "180" | ||
}, | ||
{ | ||
"depositEpoch": { | ||
"number": "0", | ||
"index": "0", | ||
"length": "100" | ||
}, | ||
"withdrawEpoch": { | ||
"number": "180", | ||
"index": "0", | ||
"length": "100" | ||
}, | ||
"expected": "180" | ||
}, | ||
{ | ||
"depositEpoch": { | ||
"number": "0", | ||
"index": "0", | ||
"length": "100" | ||
}, | ||
"withdrawEpoch": { | ||
"number": "180", | ||
"index": "1", | ||
"length": "100" | ||
}, | ||
"expected": "360" | ||
}, | ||
{ | ||
"depositEpoch": { | ||
"number": "1", | ||
"index": "634", | ||
"length": "1800" | ||
}, | ||
"withdrawEpoch": { | ||
"number": "4", | ||
"index": "820", | ||
"length": "1800" | ||
}, | ||
"expected": "180" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const { calculateLockEpochs } = require('../../lib/utils') | ||
const fixtures = require('./fixtures.json') | ||
|
||
describe('Test utils', () => { | ||
describe('Test calculate lock epochs', () => { | ||
const fixtureTable = fixtures.calculateLockEpochs.map(({ depositEpoch, withdrawEpoch, expected }) => [ | ||
depositEpoch, | ||
withdrawEpoch, | ||
expected, | ||
]) | ||
|
||
test.each(fixtureTable)(`(%s, %s) => %s`, (depositEpoch, withdrawEpoch, expected) => { | ||
const actual = calculateLockEpochs({ | ||
depositEpoch, | ||
withdrawEpoch, | ||
DAO_LOCK_PERIOD_EPOCHS: 180, | ||
}) | ||
expect(actual.toString()).toBe(expected) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "@nervosnetwork/ckb-sdk-core", | ||
"version": "0.29.0", | ||
"version": "0.29.1", | ||
"description": "JavaScript SDK for Nervos Network CKB Project", | ||
"author": "Nervos <[email protected]>", | ||
"homepage": "https://github.com/nervosnetwork/ckb-sdk-js#readme", | ||
|
@@ -31,9 +31,9 @@ | |
"url": "https://github.com/nervosnetwork/ckb-sdk-js/issues" | ||
}, | ||
"dependencies": { | ||
"@nervosnetwork/ckb-sdk-rpc": "0.29.0", | ||
"@nervosnetwork/ckb-sdk-utils": "0.29.0", | ||
"@nervosnetwork/ckb-types": "0.29.0" | ||
"@nervosnetwork/ckb-sdk-rpc": "0.29.1", | ||
"@nervosnetwork/ckb-sdk-utils": "0.29.1", | ||
"@nervosnetwork/ckb-types": "0.29.1" | ||
}, | ||
"gitHead": "0907e4ead0d2ff70dab46fd9ba637d9ee9f02a15" | ||
"gitHead": "dacec65239c3683f4ea0e5b1946f9ec74d275500" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { JSBI } from '@nervosnetwork/ckb-sdk-utils' | ||
|
||
interface EpochInfo { | ||
index: string | ||
length: string | ||
number: string | ||
} | ||
|
||
export const calculateLockEpochs = ({ | ||
withdrawEpoch, | ||
depositEpoch, | ||
DAO_LOCK_PERIOD_EPOCHS, | ||
}: { | ||
withdrawEpoch: EpochInfo | ||
depositEpoch: EpochInfo | ||
DAO_LOCK_PERIOD_EPOCHS: number | ||
}) => { | ||
const withdrawFraction = JSBI.multiply(JSBI.BigInt(withdrawEpoch.index), JSBI.BigInt(depositEpoch.length)) | ||
const depositFraction = JSBI.multiply(JSBI.BigInt(depositEpoch.index), JSBI.BigInt(withdrawEpoch.length)) | ||
let depositedEpochs = JSBI.subtract(JSBI.BigInt(withdrawEpoch.number), JSBI.BigInt(depositEpoch.number)) | ||
if (JSBI.greaterThan(withdrawFraction, depositFraction)) { | ||
depositedEpochs = JSBI.add(depositedEpochs, JSBI.BigInt(1)) | ||
} | ||
/* eslint-disable indent */ | ||
const lockEpochs = JSBI.lessThan(depositedEpochs, JSBI.BigInt(DAO_LOCK_PERIOD_EPOCHS)) | ||
? JSBI.BigInt(DAO_LOCK_PERIOD_EPOCHS) | ||
: JSBI.multiply( | ||
JSBI.divide( | ||
JSBI.add(depositedEpochs, JSBI.BigInt(DAO_LOCK_PERIOD_EPOCHS - 1)), | ||
JSBI.BigInt(DAO_LOCK_PERIOD_EPOCHS), | ||
), | ||
JSBI.BigInt(DAO_LOCK_PERIOD_EPOCHS), | ||
) | ||
/* eslint-enable indent */ | ||
return lockEpochs | ||
} | ||
export default { calculateLockEpochs } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "@nervosnetwork/ckb-sdk-rpc", | ||
"version": "0.29.0", | ||
"version": "0.29.1", | ||
"description": "RPC module of @nervosnetwork/ckb-sdk-core", | ||
"author": "Nervos <[email protected]>", | ||
"homepage": "https://github.com/nervosnetwork/ckb-sdk-js/packages/ckb-rpc#readme", | ||
|
@@ -33,12 +33,12 @@ | |
"url": "https://github.com/nervosnetwork/ckb-sdk-js/issues" | ||
}, | ||
"dependencies": { | ||
"@nervosnetwork/ckb-sdk-utils": "0.29.0", | ||
"@nervosnetwork/ckb-sdk-utils": "0.29.1", | ||
"axios": "0.19.0" | ||
}, | ||
"devDependencies": { | ||
"@nervosnetwork/ckb-types": "0.29.0", | ||
"@nervosnetwork/ckb-types": "0.29.1", | ||
"dotenv": "8.1.0" | ||
}, | ||
"gitHead": "0907e4ead0d2ff70dab46fd9ba637d9ee9f02a15" | ||
"gitHead": "dacec65239c3683f4ea0e5b1946f9ec74d275500" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "@nervosnetwork/ckb-sdk-utils", | ||
"version": "0.29.0", | ||
"version": "0.29.1", | ||
"description": "Utils module of @nervosnetwork/ckb-sdk-core", | ||
"author": "Nervos <[email protected]>", | ||
"homepage": "https://github.com/nervosnetwork/ckb-sdk-js#readme", | ||
|
@@ -31,7 +31,7 @@ | |
"url": "https://github.com/nervosnetwork/ckb-sdk-js/issues" | ||
}, | ||
"dependencies": { | ||
"@nervosnetwork/ckb-types": "0.29.0", | ||
"@nervosnetwork/ckb-types": "0.29.1", | ||
"blake2b-wasm": "2.1.0", | ||
"elliptic": "6.5.2", | ||
"jsbi": "3.1.1" | ||
|
@@ -41,5 +41,5 @@ | |
"@types/elliptic": "6.4.8", | ||
"@types/utf8": "2.1.6" | ||
}, | ||
"gitHead": "0907e4ead0d2ff70dab46fd9ba637d9ee9f02a15" | ||
"gitHead": "dacec65239c3683f4ea0e5b1946f9ec74d275500" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "@nervosnetwork/ckb-types", | ||
"version": "0.29.0", | ||
"version": "0.29.1", | ||
"description": "Type module of @nervosnetwork/ckb-sdk-core", | ||
"author": "Nervos <[email protected]>", | ||
"homepage": "https://github.com/nervosnetwork/ckb-sdk-js#readme", | ||
|
@@ -23,5 +23,5 @@ | |
"scripts": { | ||
"doc": "../../node_modules/.bin/typedoc --out docs ./index.d.ts --mode modules --includeDeclarations --excludeExternals --ignoreCompilerErrors --theme default --readme README.md" | ||
}, | ||
"gitHead": "0907e4ead0d2ff70dab46fd9ba637d9ee9f02a15" | ||
"gitHead": "dacec65239c3683f4ea0e5b1946f9ec74d275500" | ||
} |