Skip to content

Commit

Permalink
Merge pull request #384 from Concordium/pv7-conformance
Browse files Browse the repository at this point in the history
Pv7 conformance
  • Loading branch information
soerenbf authored Aug 29, 2024
2 parents e75709b + 1e4bbb6 commit 508ec9f
Show file tree
Hide file tree
Showing 12 changed files with 173 additions and 120 deletions.
14 changes: 10 additions & 4 deletions examples/nodejs/client/getPoolInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,17 @@ const client = new ConcordiumGRPCNodeClient(address, Number(port), credentials.c
const blockHash = cli.flags.block === undefined ? undefined : BlockHash.fromHexString(cli.flags.block);
const bakerPool: BakerPoolStatus = await client.getPoolInfo(BigInt(cli.flags.poolOwner), blockHash);

console.log('Open status:', bakerPool.poolInfo.openStatus);
console.log('Open status:', bakerPool.poolInfo?.openStatus);
console.log('Baker address:', bakerPool.bakerAddress);
console.log('CCD provided by the baker to the pool:', CcdAmount.toCcd(bakerPool.bakerEquityCapital));
console.log('CCD provided by the delegators to the pool:', CcdAmount.toCcd(bakerPool.delegatedCapital));
console.log(
'CCD provided by the baker to the pool:',
bakerPool.bakerEquityCapital !== undefined ? CcdAmount.toCcd(bakerPool.bakerEquityCapital) : undefined
);
console.log(
'CCD provided by the delegators to the pool:',
bakerPool.delegatedCapital !== undefined ? CcdAmount.toCcd(bakerPool.delegatedCapital) : undefined
);
console.log('Total capital in CCD of ALL pools:', CcdAmount.toCcd(bakerPool.allPoolTotalCapital));
console.log('Pool commision rates:', bakerPool.poolInfo.commissionRates);
console.log('Pool commision rates:', bakerPool.poolInfo?.commissionRates);
// #endregion documentation-snippet
})();
2 changes: 1 addition & 1 deletion examples/reactnative/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -716,4 +716,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: c70448f9d8b13c40c47391af88ee9f69ffe85d63

COCOAPODS: 1.14.3
COCOAPODS: 1.15.2
6 changes: 3 additions & 3 deletions packages/rust-bindings/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion packages/sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@

### Breaking changes

- Minimum supported Concordium node version changes to 7.0 with the changes introduced.

- `getEmbeddedModuleSchema` now uses the module version to determine in which custom wasm sections to look for the schema.
It also no longer is `async` because there isn't any need for it to be so.
- `ConcordiumGRPCClient.getEmbeddedSchema` now delegates to `getEmbeddedModuleSchema` instead of `wasmToSchema`
(which was removed as it was just a less capable version of `getEmbeddedModuleSchema`).
This means that it returns the complete `RawModuleSchema` instead of only the schema bytes.
It also means that it returns `null` instead of an error when no embedded schema was found.

- Update `AccountInfo` and `BakerPoolStatus` according to the changes introduced in the GRPC types introduced with node version 7

## 7.5.1

Expand Down
2 changes: 2 additions & 0 deletions packages/sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

Wrappers for interacting with the Concordium node, for the web environment.

**Minimum supported node version is 7.0**

Please see the
[documentation](https://developer.concordium.software/concordium-node-sdk-js/index.html)
for more information
Expand Down
46 changes: 34 additions & 12 deletions packages/sdk/src/grpc/translation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,10 +314,7 @@ function transPoolInfo(info: v2.BakerPoolInfo): v1.BakerPoolInfo {
};
}

function transPaydayStatus(status: v2.PoolCurrentPaydayInfo | undefined): v1.CurrentPaydayBakerPoolStatus | null {
if (!status) {
return null;
}
function transPaydayStatus(status: v2.PoolCurrentPaydayInfo): v1.CurrentPaydayBakerPoolStatus {
return {
blocksBaked: status.blocksBaked,
finalizationLive: status.finalizationLive,
Expand All @@ -330,6 +327,14 @@ function transPaydayStatus(status: v2.PoolCurrentPaydayInfo | undefined): v1.Cur
};
}

function transCooldown(cooldown: v2.Cooldown): v1.Cooldown {
return {
amount: CcdAmount.fromProto(unwrap(cooldown.amount)),
timestamp: Timestamp.fromProto(unwrap(cooldown.endTime)),
status: cooldown.status as number,
};
}

export function accountInfo(acc: v2.AccountInfo): v1.AccountInfo {
const aggAmount = acc.encryptedBalance?.aggregatedAmount?.value;
const numAggregated = acc.encryptedBalance?.numAggregated;
Expand All @@ -346,6 +351,8 @@ export function accountInfo(acc: v2.AccountInfo): v1.AccountInfo {
total: CcdAmount.fromProto(unwrap(acc.schedule?.total)),
schedule: unwrap(acc.schedule?.schedules).map(trRelease),
};
const cooldowns = acc.cooldowns.map(transCooldown);
const availableBalance = CcdAmount.fromProto(unwrap(acc.availableBalance));
const accInfoCommon: v1.AccountInfoSimple = {
type: v1.AccountInfoType.Simple,
accountAddress: AccountAddress.fromProto(unwrap(acc.address)),
Expand All @@ -357,6 +364,8 @@ export function accountInfo(acc: v2.AccountInfo): v1.AccountInfo {
accountEncryptedAmount: encryptedAmount,
accountReleaseSchedule: releaseSchedule,
accountCredentials: mapRecord(acc.creds, trCred),
accountCooldowns: cooldowns,
accountAvailableBalance: availableBalance,
};

if (acc.stake?.stakingInfo.oneofKind === 'delegator') {
Expand Down Expand Up @@ -531,12 +540,14 @@ export function bakerPoolInfo(info: v2.PoolInfoResponse): v1.BakerPoolStatus {
poolType: v1.PoolStatusType.BakerPool,
bakerId: unwrap(info.baker?.value),
bakerAddress: AccountAddress.fromProto(unwrap(info.address)),
bakerEquityCapital: CcdAmount.fromProto(unwrap(info.equityCapital)),
delegatedCapital: CcdAmount.fromProto(unwrap(info.delegatedCapital)),
delegatedCapitalCap: CcdAmount.fromProto(unwrap(info.delegatedCapitalCap)),
poolInfo: transPoolInfo(unwrap(info?.poolInfo)),
bakerEquityCapital: info.equityCapital !== undefined ? CcdAmount.fromProto(info.equityCapital) : undefined,
delegatedCapital: info.delegatedCapital !== undefined ? CcdAmount.fromProto(info.delegatedCapital) : undefined,
delegatedCapitalCap:
info.delegatedCapitalCap !== undefined ? CcdAmount.fromProto(info.delegatedCapitalCap) : undefined,
poolInfo: info.poolInfo !== undefined ? transPoolInfo(info.poolInfo) : undefined,
bakerStakePendingChange: transPoolPendingChange(info.equityPendingChange),
currentPaydayStatus: transPaydayStatus(info.currentPaydayInfo),
currentPaydayStatus:
info.currentPaydayInfo !== undefined ? transPaydayStatus(info.currentPaydayInfo) : undefined,
allPoolTotalCapital: CcdAmount.fromProto(unwrap(info.allPoolTotalCapital)),
};
}
Expand Down Expand Up @@ -830,8 +841,14 @@ function trBakerEvent(bakerEvent: v2.BakerEvent, account: AccountAddress.Type):
account,
};
}
case 'delegationRemoved': {
return {
tag: v1.TransactionEventTag.BakerDelegationRemoved,
delegatorId: unwrap(event.delegationRemoved.delegatorId?.id?.value),
};
}
case undefined:
throw Error('Failed translating BakerEvent, encountered undefined');
throw Error('Unrecognized event type. This should be impossible.');
}
}

Expand All @@ -847,7 +864,7 @@ function trDelegTarget(delegationTarget: v2.DelegationTarget | undefined): v1.Ev
delegateType: v1.DelegationTargetType.PassiveDelegation,
};
} else {
throw 'Failed translating DelegationTarget, encountered undefined';
throw Error('Failed translating DelegationTarget, encountered undefined');
}
}

Expand Down Expand Up @@ -902,7 +919,12 @@ function trDelegationEvent(delegationEvent: v2.DelegationEvent, account: Account
delegatorId: unwrap(event.delegationRemoved.id?.value),
account,
};
default:
case 'bakerRemoved':
return {
tag: v1.TransactionEventTag.DelegationBakerRemoved,
bakerId: unwrap(event.bakerRemoved.bakerId?.value),
};
case undefined:
throw Error('Unrecognized event type. This should be impossible.');
}
}
Expand Down
98 changes: 93 additions & 5 deletions packages/sdk/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -939,27 +939,59 @@ type PoolStatusWrapper<T extends keyof typeof PoolStatusType, S> = S & {
};

export interface BakerPoolStatusDetails {
/** The pool owner */
bakerId: BakerId;
/** The account address of the pool owner */
bakerAddress: AccountAddress.Type;
bakerEquityCapital: CcdAmount.Type;
delegatedCapital: CcdAmount.Type;
delegatedCapitalCap: CcdAmount.Type;
poolInfo: BakerPoolInfo;
/** The equity capital provided by the pool owner. Absent if the pool is removed. */
bakerEquityCapital?: CcdAmount.Type;
/** The capital delegated to the pool by other accounts. Absent if the pool is removed. */
delegatedCapital?: CcdAmount.Type;
/**
* The maximum amount that may be delegated to the pool, accounting for leverage and stake limits.
* Absent if the pool is removed
*/
delegatedCapitalCap?: CcdAmount.Type;
/**
* The pool info associated with the pool: open status, metadata URL and commission rates.
* Absent if the pool is removed
*/
poolInfo?: BakerPoolInfo;
/** Any pending change to the equity capital. This is not used from protocol version 7 onwards, as stake changes are immediate. */
bakerStakePendingChange: BakerPoolPendingChange;
currentPaydayStatus: CurrentPaydayBakerPoolStatus | null;
/** Information of the pool in the current reward period. */
currentPaydayStatus?: CurrentPaydayBakerPoolStatus;
/** Total capital staked across all pools, including passive delegation. */
allPoolTotalCapital: CcdAmount.Type;
}

/**
* Contains information about a given pool at the end of a given block.
* From protocol version 7, pool removal has immediate effect, however, the
* pool may still be present for the current (and possibly next) reward period.
* In this case, the `current_payday_info` field will be set, but the
* `equity_capital`, `delegated_capital`, `delegated_capital_cap` and,
* `pool_info` fields will all be absent. The `equity_pending_change` field
* will also be absent, as stake changes are immediate.
*/
export type BakerPoolStatus = PoolStatusWrapper<PoolStatusType.BakerPool, BakerPoolStatusDetails>;

export interface PassiveDelegationStatusDetails {
/** The total capital delegated passively. */
delegatedCapital: CcdAmount.Type;
/** The passive delegation commission rates. */
commissionRates: CommissionRates;
/** The transaction fees accruing to the passive delegators in the current reward period. */
currentPaydayTransactionFeesEarned: CcdAmount.Type;
/** The effective delegated capital of passive delegators for the current reward period. */
currentPaydayDelegatedCapital: CcdAmount.Type;
/** Total capital staked across all pools, including passive delegation. */
allPoolTotalCapital: CcdAmount.Type;
}

/**
* Contains information about passive delegators at the end of a given block.
*/
export type PassiveDelegationStatus = PoolStatusWrapper<
PoolStatusType.PassiveDelegation,
PassiveDelegationStatusDetails
Expand Down Expand Up @@ -1037,6 +1069,21 @@ interface AccountInfoCommon {
accountEncryptedAmount: AccountEncryptedAmount;
accountReleaseSchedule: AccountReleaseSchedule;
accountCredentials: Record<number, AccountCredential>;
/**
* The stake on the account that is in cooldown.
* There can be multiple amounts in cooldown that expire at different times.
* This was introduced in protocol version 7, and will be empty in
* earlier protocol versions.
*/
accountCooldowns: Cooldown[];
/**
* The available (unencrypted) balance of the account (i.e. that can be transferred
* or used to pay for transactions). This is the balance minus the locked amount.
* The locked amount is the maximum of the amount in the release schedule and
* the total amount that is actively staked or in cooldown (inactive stake).
* This was introduced with node version 7.0
*/
accountAvailableBalance: CcdAmount.Type;
}

export interface AccountInfoSimple extends AccountInfoCommon {
Expand Down Expand Up @@ -1832,3 +1879,44 @@ export type BlockItem =
expiry: number;
};
};

/**
* The status of a cooldown. When stake is removed from a baker or delegator
* (from protocol version 7) it first enters the pre-pre-cooldown state.
* The next time the stake snaphot is taken (at the epoch transition before
* a payday) it enters the pre-cooldown state. At the subsequent payday, it
* enters the cooldown state. At the payday after the end of the cooldown
* period, the stake is finally released.
*/
export enum CooldownStatus {
/**
* The amount is in cooldown and will expire at the specified time, becoming available
* at the subsequent pay day.
*/
Cooldown,
/**
* The amount will enter cooldown at the next pay day. The specified end time is
* projected to be the end of the cooldown period, but the actual end time will be
* determined at the payday, and may be different if the global cooldown period
* changes.
*/
PreCooldown,
/**
* The amount will enter pre-cooldown at the next snapshot epoch (i.e. the epoch
* transition before a pay day transition). As with pre-cooldown, the specified
* end time is projected, but the actual end time will be determined later.
*/
PrePreCooldown,
}

/**
* Describes a cooldown associated with removal of stake from a baker/delegator account
*/
export type Cooldown = {
/** The time at which the cooldown will end */
timestamp: Timestamp.Type;
/** The amount that is in cooldown and set to be released at the end of the cooldown period */
amount: CcdAmount.Type;
/** The status of the cooldown */
status: CooldownStatus;
};
18 changes: 16 additions & 2 deletions packages/sdk/src/types/transactionEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,14 @@ export enum TransactionEventTag {
BakerSetTransactionFeeCommission = 'BakerSetTransactionFeeCommission',
BakerSetBakingRewardCommission = 'BakerSetBakingRewardCommission',
BakerSetFinalizationRewardCommission = 'BakerSetFinalizationRewardCommission',
BakerDelegationRemoved = 'BakerDelegationRemoved',
DelegationStakeIncreased = 'DelegationStakeIncreased',
DelegationStakeDecreased = 'DelegationStakeDecreased',
DelegationSetRestakeEarnings = 'DelegationSetRestakeEarnings',
DelegationSetDelegationTarget = 'DelegationSetDelegationTarget',
DelegationAdded = 'DelegationAdded',
DelegationRemoved = 'DelegationRemoved',
DelegationBakerRemoved = 'DelegationBakerRemoved',
TransferMemo = 'TransferMemo',
Transferred = 'Transferred',
Interrupted = 'Interrupted',
Expand Down Expand Up @@ -247,6 +249,11 @@ export interface DelegationStakeChangedEvent {
newStake: CcdAmount.Type;
}

export interface DelegationBakerRemovedEvent {
tag: TransactionEventTag.DelegationBakerRemoved;
bakerId: BakerId;
}

// Baker Events

export interface BakerAddedEvent {
Expand Down Expand Up @@ -324,6 +331,11 @@ export interface BakerSetTransactionFeeCommissionEvent {
transactionFeeCommission: number;
}

export interface BakerDelegationRemovedEvent {
tag: TransactionEventTag.BakerDelegationRemoved;
delegatorId: DelegatorId;
}

export interface UpdateEnqueuedEvent {
tag: TransactionEventTag.UpdateEnqueued;
effectiveTime: number;
Expand All @@ -341,9 +353,11 @@ export type BakerEvent =
| BakerStakeChangedEvent
| BakerAddedEvent
| BakerRemovedEvent
| BakerKeysUpdatedEvent;
| BakerKeysUpdatedEvent
| BakerDelegationRemovedEvent;
export type DelegationEvent =
| DelegatorEvent
| DelegationSetDelegationTargetEvent
| DelegationSetRestakeEarningsEvent
| DelegationStakeChangedEvent;
| DelegationStakeChangedEvent
| DelegationBakerRemovedEvent;
Loading

0 comments on commit 508ec9f

Please sign in to comment.