1- Add the total collateral in the availability table

2- Define the min price per byte as 1
3- Use `0.1` step for the availability size
4- Round the total size number
5- Use the total size value (= 1 token per byte) by default for the total collateral
6- Do not allow negative numbers when creating the storage requests
7- Reduce the default reward and collateral for the storage request
This commit is contained in:
Arnaud 2025-03-04 13:59:46 +01:00
parent d44a8dc95f
commit 19d045e714
No known key found for this signature in database
GPG Key ID: 69D6CE281FCAE663
8 changed files with 29 additions and 12 deletions

View File

@ -49,8 +49,11 @@ export function AvailabilitiesTable({ availabilities, space }: Props) {
const onSortByPrice = (state: TabSortState) =>
setSortFn(() => AvailabilityUtils.sortByPrice(state));
const onSortByCollateral = (state: TabSortState) =>
setSortFn(() => AvailabilityUtils.sortByCollateral(state));
const onSortByRemainingCollateral = (state: TabSortState) =>
setSortFn(() => AvailabilityUtils.sortByRemainingCollateral(state));
const onSortByTotalCollateral = (state: TabSortState) =>
setSortFn(() => AvailabilityUtils.sortByTotalCollateral(state));
const headers = [
[""],
@ -58,7 +61,8 @@ export function AvailabilitiesTable({ availabilities, space }: Props) {
["total size", onSortBySize],
["duration", onSortByDuration],
["min price per byte", onSortByPrice],
["remaining collateral", onSortByCollateral],
["remaining collateral", onSortByRemainingCollateral],
["total collateral", onSortByTotalCollateral],
["actions"],
] satisfies [string, ((state: TabSortState) => void)?][];
@ -90,6 +94,7 @@ export function AvailabilitiesTable({ availabilities, space }: Props) {
<Cell>{Times.pretty(a.duration)}</Cell>,
<Cell>{a.minPricePerBytePerSecond.toString()}</Cell>,
<Cell>{a.totalRemainingCollateral.toString()}</Cell>,
<Cell>{a.totalCollateral.toString()}</Cell>,
<AvailabilityActionsCell availability={a} />,
]}></Row>

View File

@ -30,7 +30,7 @@ const CONFIRM_STATE = 2;
const defaultAvailabilityData: AvailabilityState = {
totalSize: 0.5,
duration: 1,
minPricePerBytePerSecond: 0,
minPricePerBytePerSecond: 1,
totalCollateral: 0,
totalSizeUnit: "gb",
durationUnit: "days",

View File

@ -11,6 +11,7 @@ import NodesIcon from "../../assets/icons/nodes.svg?react";
import InfoIcon from "../../assets/icons/info.svg?react";
import { attributes } from "../../utils/attributes";
import { AvailabilityUtils } from "./availability.utils";
import { GB } from "../../utils/constants";
export function AvailabilityForm({
dispatch,
@ -144,12 +145,13 @@ export function AvailabilityForm({
max={available.toFixed(2)}
onChange={onAvailablityChange}
onGroupChange={onTotalSizeUnitChange}
value={availability.totalSize.toString()}
value={availability.totalSize.toFixed(2)}
min={"0"}
group={[
["gb", "GB"],
// ["tb", "TB"],
]}
step="0.1"
groupValue={availability.totalSizeUnit}
extra={<a onClick={onMaxSize}>Use max size</a>}
/>
@ -208,7 +210,10 @@ export function AvailabilityForm({
label="Total collateral"
min={0}
onChange={onInputChange}
value={availability.totalCollateral.toString()}
value={(
availability.totalCollateral ||
Math.round(availability.totalSize * GB)
).toString()}
/>
<Tooltip
message={

View File

@ -179,13 +179,13 @@ describe("files", () => {
const descSorted = items
.slice()
.sort(AvailabilityUtils.sortByCollateral("desc"));
.sort(AvailabilityUtils.sortByRemainingCollateral("desc"));
assert.deepEqual(descSorted, [b, a]);
const ascSorted = items
.slice()
.sort(AvailabilityUtils.sortByCollateral("asc"));
.sort(AvailabilityUtils.sortByRemainingCollateral("asc"));
assert.deepEqual(ascSorted, [a, b]);
});

View File

@ -25,12 +25,18 @@ export const AvailabilityUtils = {
state === "desc"
? b.minPricePerBytePerSecond - a.minPricePerBytePerSecond
: a.minPricePerBytePerSecond - b.minPricePerBytePerSecond,
sortByCollateral:
sortByRemainingCollateral:
(state: TabSortState) =>
(a: AvailabilityWithSlots, b: AvailabilityWithSlots) =>
state === "desc"
? b.totalRemainingCollateral - a.totalRemainingCollateral
: a.totalRemainingCollateral - b.totalRemainingCollateral,
sortByTotalCollateral:
(state: TabSortState) =>
(a: AvailabilityWithSlots, b: AvailabilityWithSlots) =>
state === "desc"
? b.totalCollateral - a.totalCollateral
: a.totalCollateral - b.totalCollateral,
toUnit(bytes: number, unit: "gb" | "tb") {
return bytes / this.unitValue(unit || "gb");
},

View File

@ -52,6 +52,7 @@ export function CardNumbers({
value={value}
type="number"
isInvalid={!!error}
min={0}
onChange={onInternalChange}></Input>
<Tooltip message={error || helper}>

View File

@ -27,8 +27,8 @@ const defaultStorageRequest: StorageRequest = {
tolerance: 1,
proofProbability: 1,
nodes: 3,
reward: 10,
collateral: 10,
reward: 1,
collateral: 1,
expiration: 5,
};

View File

@ -288,7 +288,7 @@ export function StorageRequestReview({
value={storageRequest.collateral.toString()}
onChange={onCollateralChange}
onValidation={isInvalidNumber}
title="Penality tokens"></CardNumbers>
title="Penality tokens per byte"></CardNumbers>
<CardNumbers
helper="The maximum amount of tokens paid per second per byte to hosts the client is willing to pay."
id="reward"