From 4d606c3c4cbb8b0234a8b52a3477788cd279cf97 Mon Sep 17 00:00:00 2001 From: Oleksandr Myshchyshyn Date: Mon, 2 Dec 2024 17:46:56 +0200 Subject: [PATCH] Implement DelegatorKind support fot Bid, Prepare 5.0.0-rc5 --- CHANGELOG.md | 13 ++++ package.json | 2 +- src/types/Bid.ts | 148 ++++++++++++++++++++++++++++++++++++++++--- src/types/BidKind.ts | 40 +++++++++--- src/types/EraInfo.ts | 17 +++-- 5 files changed, 193 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c9ea43f..778428ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,19 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ### Removed --> +## [5.0.0-rc5] - 2024-12-01 + +### Added + +- DelegatorKind support fot Bid +- Calltable serialization for `TransactionV1` - [Reference of changes](https://github.com/casper-network/casper-node/pull/4823) +- Custom ttl for `makeCsprTransferDeploy` and `makeAuctionManagerDeploy` + +### Changed + +- `TransactionV1` structure. From now on a TransactionV1 consists of `hash`, `payload` and `approvals`. `payload` is a merge of `header` and `body` concepts from before. +- Updated documentation + ## [5.0.0-rc4] - 2024-11-25 ### Added diff --git a/package.json b/package.json index 5ca162a7..fafa9661 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "casper-js-sdk", - "version": "5.0.0-rc4", + "version": "5.0.0-rc5", "license": "Apache 2.0", "description": "SDK to interact with the Casper blockchain", "homepage": "https://github.com/casper-ecosystem/casper-js-sdk#README.md", diff --git a/src/types/Bid.ts b/src/types/Bid.ts index f9cd9d75..16a32000 100644 --- a/src/types/Bid.ts +++ b/src/types/Bid.ts @@ -3,6 +3,142 @@ import { PublicKey } from './keypair'; import { CLValueUInt512 } from './clvalue'; import { URef } from './key'; +/** + * Represents the details of an era where an unbonding request was initiated. + */ +@jsonObject +export class UnbondEra { + /** + * The amount of tokens to be unbonded during this era. + */ + @jsonMember({ + name: 'amount', + constructor: CLValueUInt512, + deserializer: json => CLValueUInt512.fromJSON(json), + serializer: value => value.toJSON() + }) + amount: CLValueUInt512; + + /** + * The era in which the unbonding request was created. + */ + @jsonMember({ name: 'era_of_creation', constructor: Number }) + eraOfCreation: number; + + /** + * The bonding purse associated with the unbonding request. + */ + @jsonMember({ + name: 'bonding_purse', + constructor: URef, + deserializer: json => URef.fromJSON(json), + serializer: value => value.toJSON() + }) + bondingPurse: URef; +} + +/** + * Represents the kind of unbonding request, including information about the validator, + * delegated public key, and delegated purse. + */ +@jsonObject +export class UnbondKind { + /** + * The public key of the validator who the tokens are being unbonded from. + */ + @jsonMember({ + name: 'Validator', + constructor: PublicKey, + deserializer: json => PublicKey.fromJSON(json), + serializer: value => value.toJSON() + }) + validator: PublicKey; + + /** + * The public key of the delegated account involved in the unbonding. + */ + @jsonMember({ + name: 'DelegatedPublicKey', + constructor: PublicKey, + deserializer: json => PublicKey.fromJSON(json), + serializer: value => value.toJSON() + }) + delegatedPublicKey: PublicKey; + + /** + * The purse associated with the delegation from which tokens will be unbonded. + */ + @jsonMember({ + name: 'DelegatedPurse', + constructor: URef, + deserializer: json => URef.fromJSON(json), + serializer: value => value.toJSON() + }) + delegatedPurse: URef; +} + +/** + * Represents a request to unbond tokens, specifying the validator, unbond kind, and eras. + */ +@jsonObject +export class Unbond { + /** + * The public key of the validator from which tokens are being unbonded. + */ + @jsonMember({ + name: 'validator_public_key', + constructor: PublicKey, + deserializer: json => PublicKey.fromJSON(json), + serializer: value => value.toJSON() + }) + validatorPublicKey: PublicKey; + + /** + * The kind of unbonding request, detailing whether it's from a validator, delegated public key, or delegated purse. + */ + @jsonMember({ + name: 'unbond_kind', + constructor: UnbondKind + }) + unbondKind: UnbondKind; + + /** + * A list of eras during which unbonding occurred. + */ + @jsonArrayMember(UnbondEra, { name: 'eras' }) + eras: UnbondEra[]; +} + +/** + * Represents a delegation bid, which can be made from either a public key or a purse. + */ +@jsonObject +export class DelegationKind { + /** + * A delegation bid made using a public key. + */ + @jsonMember({ + name: 'PublicKey', + constructor: PublicKey, + deserializer: json => PublicKey.fromJSON(json), + serializer: value => value.toJSON(), + preserveNull: true + }) + publicKey?: PublicKey; + + /** + * A delegation bid made using a purse. + */ + @jsonMember({ + name: 'Purse', + constructor: URef, + deserializer: json => URef.fromJSON(json), + serializer: value => value.toJSON(), + preserveNull: true + }) + purse?: URef; +} + /** * Represents a vesting schedule for staked amounts, including an initial release timestamp and locked amounts. */ @@ -333,15 +469,11 @@ export class Reservation { validatorPublicKey: PublicKey; /** - * The public key of the delegator associated with this reservation. - * - * This key is used to identify the delegator who initiated the reservation. + * Kinds of delegation bids. */ @jsonMember({ - name: 'delegator_public_key', - constructor: PublicKey, - deserializer: json => PublicKey.fromJSON(json), - serializer: value => value.toJSON() + name: 'delegator_kind', + constructor: DelegationKind }) - delegatorPublicKey: PublicKey; + delegatorKind: DelegationKind; } diff --git a/src/types/BidKind.ts b/src/types/BidKind.ts index a997da72..0919ed0d 100644 --- a/src/types/BidKind.ts +++ b/src/types/BidKind.ts @@ -5,49 +5,71 @@ import { Credit, Delegator, Reservation, + Unbond, ValidatorBid } from './Bid'; /** - * Represents a polymorphic bid kind, allowing for different types of bid-related entities. - * This class contains properties for various bid types, including unified bids, validator bids, - * delegators, bridge transitions, and credits. + * Represents a polymorphic bid kind, which can hold different types of bid-related entities. + * This class allows for various bid types, such as unified bids, validator bids, delegator bids, + * bridge transitions, credits, and reservations. It provides flexibility to manage various bidding + * scenarios in a decentralized system. */ @jsonObject export class BidKind { /** - * A unified bid that combines multiple bid attributes. + * A unified bid that combines multiple bid attributes, serving as a general bid type. + * This type can hold any bid-related information that doesn't fit into the specific categories + * below, allowing for a broader range of bidding scenarios. */ @jsonMember({ name: 'Unified', constructor: Bid }) unified?: Bid; /** - * A validator-specific bid, containing information unique to validators. + * A bid specific to a validator, containing information unique to the validator's bid. + * This may include details such as the validator's identity, bid amount, and other relevant + * parameters that differentiate it from other types of bids. */ @jsonMember({ name: 'Validator', constructor: ValidatorBid }) validator?: ValidatorBid; /** - * A bid specific to a delegator, which represents a user delegating their stake to a validator. + * A bid from a delegator, representing a user delegating their stake to a validator. + * This field holds information about the delegator's public key, amount of stake delegated, + * and any other relevant data specific to the delegation process. */ @jsonMember({ name: 'Delegator', constructor: Delegator }) delegator?: Delegator; /** - * Represents a transition bridge between validators, connecting an old validator with a new one. + * Represents a bridge transition between validators, allowing for the transfer of a validator's + * responsibilities to another validator. This can be useful in the context of network upgrades + * or validator rotations. */ @jsonMember({ name: 'Bridge', constructor: Bridge }) bridge?: Bridge; /** - * Represents a credit entry for a validator, specifying an amount and era. + * A credit entry for a validator, specifying an amount of credit and the era in which the credit + * is awarded. This can be used to track validator performance, reputation, or other forms of credit + * that might be relevant in the ecosystem. */ @jsonMember({ name: 'Credit', constructor: Credit }) credit?: Credit; /** - * Represents a validator reserving a slot for specific delegator + * Represents a reservation made by a validator for a specific delegator, ensuring that a slot + * is reserved for the delegator to join the validator's pool. This may be used in scenarios where + * validators want to guarantee space for specific delegators. */ @jsonMember({ name: 'Reservation', constructor: Reservation }) reservation?: Reservation; + + /** + * Represents an unbonding request, where a delegator or validator requests to unbond previously + * bonded assets. This could involve the release of staked tokens and their return to the original + * owner, with associated properties like bonding era and validator information. + */ + @jsonMember({ name: 'Unbond', constructor: Unbond }) + unbond?: Unbond; } diff --git a/src/types/EraInfo.ts b/src/types/EraInfo.ts index 2ebc9447..cbc8c440 100644 --- a/src/types/EraInfo.ts +++ b/src/types/EraInfo.ts @@ -1,6 +1,7 @@ import { jsonArrayMember, jsonMember, jsonObject } from 'typedjson'; import { PublicKey } from './keypair'; import { CLValueUInt512 } from './clvalue'; +import { DelegationKind } from './Bid'; /** * Class representing the allocation of seigniorage to a delegator. @@ -8,15 +9,13 @@ import { CLValueUInt512 } from './clvalue'; @jsonObject export class DelegatorAllocation { /** - * The public key of the delegator receiving the allocation. + * Kinds of delegation bids. */ @jsonMember({ - name: 'delegator_public_key', - constructor: PublicKey, - deserializer: json => PublicKey.fromJSON(json), - serializer: value => value.toJSON() + name: 'delegator_kind', + constructor: DelegationKind }) - delegatorPublicKey: PublicKey; + delegatorKind: DelegationKind; /** * The public key of the validator associated with the delegator's allocation. @@ -43,16 +42,16 @@ export class DelegatorAllocation { /** * Constructs a `DelegatorAllocation` instance. * - * @param delegatorPublicKey The public key of the delegator. + * @param delegatorKind Kinds of delegation bids. * @param validatorPublicKey The public key of the associated validator. * @param amount The amount of seigniorage allocated to the delegator. */ constructor( - delegatorPublicKey: PublicKey, + delegatorKind: DelegationKind, validatorPublicKey: PublicKey, amount: CLValueUInt512 ) { - this.delegatorPublicKey = delegatorPublicKey; + this.delegatorKind = delegatorKind; this.validatorPublicKey = validatorPublicKey; this.amount = amount; }