Files
pwap/pezkuwi-sdk-ui/packages/page-referenda/src/util.spec.ts
T
pezkuwichain 971df8edba Rebrand: Remove 3rd party chains, update domains to PezkuwiChain
- Remove all 3rd party parachain configurations from endpoints:
  - productionRelayPolkadot.ts: Keep only system parachains
  - productionRelayDicle.ts: Keep only system parachains
  - testingRelayZagros.ts: Keep only system parachains
  - testingRelayTeyrChain.ts: Keep only system parachains

- Update domain references:
  - polkadot.js.org → pezkuwichain.app
  - wiki.polkadot.network → wiki.pezkuwichain.io
  - dotapps.io → pezkuwichain.app
  - statement.polkadot.network → docs.pezkuwichain.io/statement
  - support.polkadot.network → docs.pezkuwichain.io

- Update repository references:
  - github.com/pezkuwi-js/apps → github.com/pezkuwichain/pwap

- Rename system parachains to Pezkuwi ecosystem:
  - PolkadotAssetHub → PezkuwiAssetHub
  - polkadotBridgeHub → pezkuwiBridgeHub
  - polkadotCollectives → pezkuwiCollectives
  - polkadotCoretime → pezkuwiCoretime
  - polkadotPeople → pezkuwiPeople

- Update network name in claims utility:
  - Polkadot → Pezkuwi
2026-01-09 03:08:11 +03:00

132 lines
4.2 KiB
TypeScript

// Copyright 2017-2026 @pezkuwi/app-referenda authors & contributors
// SPDX-License-Identifier: Apache-2.0
/// <reference types="@pezkuwi/dev-test/globals.d.ts" />
import type { PezpalletReferendaCurve } from '@pezkuwi/types/lookup';
import type { BN } from '@pezkuwi/util';
import { BN_BILLION, BN_ZERO, bnToBn } from '@pezkuwi/util';
import { curveDelay, curveThreshold } from './util.js';
function curveLinear (ceil: BN | string | number, floor: BN | string | number, length: BN | string | number): PezpalletReferendaCurve {
return {
asLinearDecreasing: {
ceil: bnToBn(ceil),
floor: bnToBn(floor),
length: bnToBn(length)
},
isLinearDecreasing: true,
isReciprocal: false,
isSteppedDecreasing: false
} as PezpalletReferendaCurve;
}
function curveReciprocal (factor: BN | string | number, xOffset: BN | string | number, yOffset: BN | string | number): PezpalletReferendaCurve {
return {
asReciprocal: {
factor: bnToBn(factor),
xOffset: bnToBn(xOffset),
yOffset: bnToBn(yOffset)
},
isLinearDecreasing: false,
isReciprocal: true,
isSteppedDecreasing: false
} as PezpalletReferendaCurve;
}
// We don't currently have curves on Dicle for this, so needs a check
// function curveStepped (begin: BN | string | number, end: BN | string | number, period: BN | string | number, step: BN | string | number): PezpalletReferendaCurve {
// return {
// asSteppedDecreasing: {
// begin: bnToBn(begin),
// end: bnToBn(end),
// period: bnToBn(period),
// step: bnToBn(step)
// },
// isLinearDecreasing: false,
// isReciprocal: false,
// isSteppedDecreasing: true
// } as PezpalletReferendaCurve;
// }
function percentValue (percent: number): BN {
return BN_BILLION.muln(percent).divn(100);
}
describe('curveThreshold', (): void => {
describe('LinearDecreasing', (): void => {
// linear support curve from root track on Dicle
const rootCurve = curveLinear(BN_BILLION.divn(2), BN_ZERO, BN_BILLION);
it('has a correct starting point', (): void => {
expect(
curveThreshold(rootCurve, bnToBn(0), bnToBn(672)).toString()
).toEqual(percentValue(50).toString());
});
it('has the correct midpoint', (): void => {
expect(
curveThreshold(rootCurve, bnToBn(672 / 2), bnToBn(672)).toString()
).toEqual(percentValue(25).toString());
});
it('has a correct ending point', (): void => {
expect(
curveThreshold(rootCurve, bnToBn(672), bnToBn(672)).toString()
).toEqual(percentValue(0).toString());
});
});
describe('Reciprocal', (): void => {
// linear approval curve from root track on Dicle
const rootCurve = curveReciprocal(222_222_224, 333_333_335, 333_333_332);
it('has a correct starting point', (): void => {
expect(
curveThreshold(rootCurve, bnToBn(0), bnToBn(672)).toString()
).toEqual(percentValue(100).toString());
});
it('has the correct midpoints', (): void => {
expect(
curveThreshold(rootCurve, bnToBn(12), bnToBn(672)).toString()
).toEqual('966101697'); // 96.61%
expect(
curveThreshold(rootCurve, bnToBn(336), bnToBn(672)).toString()
).toEqual(percentValue(60).toString());
});
it('has a correct ending point', (): void => {
expect(
curveThreshold(rootCurve, bnToBn(672), bnToBn(672)).toString()
).toEqual('499999999');
});
});
});
describe('curveDelay', (): void => {
describe('LinearDecreasing', (): void => {
// linear support curve from root track on Dicle
const rootCurve = curveLinear(BN_BILLION.divn(2), BN_ZERO, BN_BILLION);
it('has the correct result for 25%', (): void => {
expect(
curveDelay(rootCurve, bnToBn(25), bnToBn(100)).toString()
).toEqual('500000000'); // 50% through
});
});
describe('Reciprocal', (): void => {
// linear approval curve from root track on Dicle
const rootCurve = curveReciprocal(222_222_224, 333_333_335, 333_333_332);
it('has the correct result for 75%', (): void => {
expect(
curveDelay(rootCurve, bnToBn(75), bnToBn(100)).toString()
).toEqual('200000000'); // 20% through
});
});
});