Skip to content

Commit

Permalink
Implement DelegatorKind support fot Bid, Prepare 5.0.0-rc5
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmyshchyshyn committed Dec 2, 2024
1 parent 4397de1 commit 4d606c3
Show file tree
Hide file tree
Showing 5 changed files with 193 additions and 27 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
148 changes: 140 additions & 8 deletions src/types/Bid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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;
}
40 changes: 31 additions & 9 deletions src/types/BidKind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
17 changes: 8 additions & 9 deletions src/types/EraInfo.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
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.
*/
@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.
Expand All @@ -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;
}
Expand Down

0 comments on commit 4d606c3

Please sign in to comment.