Skip to content

Commit

Permalink
Merge pull request #416 from input-output-hk/fix/remove-nullability-o…
Browse files Browse the repository at this point in the history
…f-protocol-params-babbage

fix: Remove nullability of ProtocolParametersBabbage properties
  • Loading branch information
rhyslbw authored Sep 12, 2022
2 parents c5ddf7c + f75859d commit 3b69ea4
Show file tree
Hide file tree
Showing 9 changed files with 191 additions and 51 deletions.
23 changes: 22 additions & 1 deletion packages/blockfrost/src/BlockfrostToCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,36 @@ export const BlockfrostToCore = {
blockfrost: Responses['epoch_param_content']
): ProtocolParametersRequiredByWallet => ({
coinsPerUtxoByte: Number(blockfrost.coins_per_utxo_word),
collateralPercentage: Number(blockfrost.collateral_percent),
decentralizationParameter: String(blockfrost.decentralisation_param),
desiredNumberOfPools: blockfrost.n_opt,
maxBlockBodySize: blockfrost.max_block_size,
maxBlockHeaderSize: blockfrost.max_block_header_size,
maxCollateralInputs: Number(blockfrost.max_collateral_inputs),
maxExecutionUnitsPerBlock: {
memory: Number(blockfrost.max_block_ex_mem),
steps: Number(blockfrost.max_block_ex_mem)
},
maxExecutionUnitsPerTransaction: {
memory: Number(blockfrost.max_tx_ex_mem),
steps: Number(blockfrost.max_tx_ex_steps)
},
maxTxSize: Number(blockfrost.max_tx_size),
maxValueSize: Number(blockfrost.max_val_size),
minFeeCoefficient: blockfrost.min_fee_a,
minFeeConstant: blockfrost.min_fee_b,
minPoolCost: Number(blockfrost.min_pool_cost),
monetaryExpansion: String(blockfrost.rho),
poolDeposit: Number(blockfrost.pool_deposit),
poolInfluence: String(blockfrost.a0),
poolRetirementEpochBound: blockfrost.e_max,
prices: {
memory: Number(blockfrost.price_mem),
steps: Number(blockfrost.price_step)
},
protocolVersion: { major: blockfrost.protocol_major_ver, minor: blockfrost.protocol_minor_ver },
stakeKeyDeposit: Number(blockfrost.key_deposit)
stakeKeyDeposit: Number(blockfrost.key_deposit),
treasuryExpansion: String(blockfrost.tau)
}),

inputFromUtxo: (address: string, utxo: BlockfrostUtxo): BlockfrostInput => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,57 @@ export const toWalletProtocolParams = ({
protocol_major,
protocol_minor,
min_fee_a,
min_fee_b
min_fee_b,
max_block_size,
max_bh_size,
optimal_pool_count,
influence,
monetary_expand_rate,
treasury_growth_rate,
decentralisation,
collateral_percent,
price_mem,
price_step,
max_tx_ex_mem,
max_tx_ex_steps,
max_block_ex_mem,
max_block_ex_steps,
max_epoch
}: WalletProtocolParamsModel): ProtocolParametersRequiredByWallet => ({
coinsPerUtxoByte: Number(coins_per_utxo_size),
collateralPercentage: collateral_percent,
decentralizationParameter: String(decentralisation),
desiredNumberOfPools: optimal_pool_count,
maxBlockBodySize: max_block_size,
maxBlockHeaderSize: max_bh_size,
maxCollateralInputs: max_collateral_inputs,
maxExecutionUnitsPerBlock: {
memory: Number(max_block_ex_mem),
steps: Number(max_block_ex_steps)
},
maxExecutionUnitsPerTransaction: {
memory: Number(max_tx_ex_mem),
steps: Number(max_tx_ex_steps)
},
maxTxSize: max_tx_size,
maxValueSize: Number(max_val_size),
minFeeCoefficient: min_fee_a,
minFeeConstant: min_fee_b,
minPoolCost: Number(min_pool_cost),
monetaryExpansion: String(monetary_expand_rate),
poolDeposit: Number(pool_deposit),
poolInfluence: String(influence),
poolRetirementEpochBound: max_epoch,
prices: {
memory: price_mem,
steps: price_step
},
protocolVersion: {
major: protocol_major,
minor: protocol_minor
},
stakeKeyDeposit: Number(key_deposit)
stakeKeyDeposit: Number(key_deposit),
treasuryExpansion: String(treasury_growth_rate)
});

export const toGenesisParams = (genesis: GenesisData): Cardano.CompactGenesis => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,31 @@ export const findLedgerTip = `
export const findCurrentWalletProtocolParams = `
SELECT
min_fee_a,
min_fee_b, max_tx_size,
min_fee_b,
max_tx_size,
key_deposit,
pool_deposit,
protocol_major,
protocol_minor,
min_pool_cost,
coins_per_utxo_size,
max_val_size,
max_collateral_inputs
max_collateral_inputs,
max_block_size,
max_bh_size,
optimal_pool_count,
influence,
monetary_expand_rate,
treasury_growth_rate,
decentralisation,
collateral_percent,
price_mem,
price_step,
max_tx_ex_mem,
max_tx_ex_steps,
max_block_ex_mem,
max_block_ex_steps,
max_epoch
FROM public.epoch_param
ORDER BY epoch_no DESC NULLS LAST
LIMIT 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,21 @@ export interface WalletProtocolParamsModel {
min_fee_a: number;
min_fee_b: number;
max_collateral_inputs: number;
max_block_size: number;
max_bh_size: number;
optimal_pool_count: number;
influence: number;
monetary_expand_rate: number;
treasury_growth_rate: number;
decentralisation: number;
collateral_percent: number;
price_mem: number;
price_step: number;
max_tx_ex_mem: string;
max_tx_ex_steps: string;
max_block_ex_mem: string;
max_block_ex_steps: string;
max_epoch: number;
}

export interface GenesisData {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,31 @@ exports[`NetworkInfoBuilder queryCirculatingSupply query circulating supply 1`]
exports[`NetworkInfoBuilder queryCurrentWalletProtocolParams query wallet protocol params from current epoch 1`] = `
Object {
"coins_per_utxo_size": "34482",
"collateral_percent": 150,
"decentralisation": 0,
"influence": 0.3,
"key_deposit": "2000000",
"max_bh_size": 1100,
"max_block_ex_mem": "80000000",
"max_block_ex_steps": "40000000000",
"max_block_size": 98304,
"max_collateral_inputs": 3,
"max_epoch": 18,
"max_tx_ex_mem": "16000000",
"max_tx_ex_steps": "10000000000",
"max_tx_size": 16384,
"max_val_size": "5000",
"min_fee_a": 44,
"min_fee_b": 155381,
"min_pool_cost": "340000000",
"monetary_expand_rate": 0.003,
"optimal_pool_count": 500,
"pool_deposit": "500000000",
"price_mem": 0.0577,
"price_step": 0.0000721,
"protocol_major": 6,
"protocol_minor": 0,
"treasury_growth_rate": 0.2,
}
`;

Expand Down
2 changes: 1 addition & 1 deletion packages/cip2/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export interface InputSelector {
}

export type ProtocolParametersForInputSelection = Pick<
Cardano.ProtocolParametersBabbage,
Cardano.ProtocolParameters,
'coinsPerUtxoByte' | 'maxTxSize' | 'maxValueSize' | 'minFeeCoefficient' | 'minFeeConstant'
>;

Expand Down
101 changes: 76 additions & 25 deletions packages/core/src/Cardano/types/ProtocolParameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@ export interface ProtocolVersion {
minor: number;
patch?: number;
}
export type CostModels = CostModel[];

export type CostModel = number[];
export type ModelKey = string;

export type CostModel = {
[k: ModelKey]: number;
};

export type CostModels = CostModel[];

export interface Prices {
memory: number;
Expand All @@ -24,27 +29,73 @@ export interface ValidityInterval {
invalidHereafter?: Slot;
}

export interface ProtocolParametersBabbage {
minFeeCoefficient?: number;
minFeeConstant?: number;
maxBlockBodySize?: number;
maxBlockHeaderSize?: number;
maxTxSize?: number;
stakeKeyDeposit?: number;
poolDeposit?: number;
poolRetirementEpochBound?: number;
desiredNumberOfPools?: number;
poolInfluence?: number;
monetaryExpansion?: number;
treasuryExpansion?: number;
minPoolCost?: number;
coinsPerUtxoByte?: number;
maxValueSize?: number;
collateralPercentage?: number;
maxCollateralInputs?: number;
protocolVersion?: ProtocolVersion;
costModels?: CostModels;
prices?: Prices;
maxExecutionUnitsPerTransaction?: ExUnits;
maxExecutionUnitsPerBlock?: ExUnits;
export interface TxFeePolicy {
coefficient: string;
constant: number;
}

export interface SoftforkRule {
initThreshold: string;
minThreshold: string;
decrementThreshold: string;
}

type ProtocolParametersByron = {
heavyDlgThreshold: string;
maxBlockSize: number;
maxHeaderSize: number;
maxProposalSize: number;
maxTxSize: number;
mpcThreshold: string;
scriptVersion: number;
slotDuration: number;
unlockStakeEpoch: number;
updateProposalThreshold: string;
updateProposalTimeToLive: number;
updateVoteThreshold: string;
txFeePolicy: TxFeePolicy;
softforkRule: SoftforkRule;
};

type NewProtocolParamsInShelley = {
minFeeCoefficient: number;
minFeeConstant: number;
maxBlockBodySize: number;
maxBlockHeaderSize: number;
stakeKeyDeposit: number;
poolDeposit: number | null;
poolRetirementEpochBound: number;
desiredNumberOfPools: number;
poolInfluence: string;
monetaryExpansion: string;
treasuryExpansion: string;
decentralizationParameter: string;
minUtxoValue: number;
minPoolCost: number;
extraEntropy: 'neutral' | string;
protocolVersion: ProtocolVersion;
};

type ShelleyProtocolParams = Pick<ProtocolParametersByron, 'maxTxSize'> & NewProtocolParamsInShelley;

type NewProtocolParamsInAlonzo = {
coinsPerUtxoWord: number;
maxValueSize: number;
collateralPercentage: number;
maxCollateralInputs: number;
costModels: CostModels;
prices: Prices;
maxExecutionUnitsPerTransaction: ExUnits;
maxExecutionUnitsPerBlock: ExUnits;
};

type AlonzoProtocolParams = Omit<ShelleyProtocolParams, 'minUtxoValue'> & NewProtocolParamsInAlonzo;

type NewProtocolParamsInBabbage = {
coinsPerUtxoByte: number;
};

type BabbageProtocolParameters = Omit<AlonzoProtocolParams, 'coinsPerUtxoWord' | 'extraEntropy'> &
NewProtocolParamsInBabbage;

export type ProtocolParameters = BabbageProtocolParameters;
10 changes: 5 additions & 5 deletions packages/core/src/Cardano/types/Script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,22 +188,22 @@ export type NativeScript =
*/
export enum PlutusLanguageVersion {
/**
* PlutusV1 was the initial version of Plutus, introduced in the Alonzo hard fork.
* V1 was the initial version of Plutus, introduced in the Alonzo hard fork.
*/
PlutusV1 = 1,
V1 = 0,

/**
* PlutusV2 was introduced in the Vasil hard fork.
* V2 was introduced in the Vasil hard fork.
*
* The main changes in PlutusV2 were to the interface to scripts. The ScriptContext was extended
* The main changes in V2 of Plutus were to the interface to scripts. The ScriptContext was extended
* to include the following information:
*
* - The full “redeemers” structure, which contains all the redeemers used in the transaction
* - Reference inputs in the transaction (proposed in CIP-31)
* - Inline datums in the transaction (proposed in CIP-32)
* - Reference scripts in the transaction (proposed in CIP-33)
*/
PlutusV2 = 2
V2 = 1
}

/**
Expand Down
16 changes: 1 addition & 15 deletions packages/core/src/Provider/NetworkInfoProvider/types.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,6 @@
import { Cardano, EraSummary, Provider } from '../..';

export type ProtocolParametersRequiredByWallet = Required<
Pick<
Cardano.ProtocolParametersBabbage,
| 'coinsPerUtxoByte'
| 'maxTxSize'
| 'maxValueSize'
| 'stakeKeyDeposit'
| 'maxCollateralInputs'
| 'minFeeCoefficient'
| 'minFeeConstant'
| 'minPoolCost'
| 'poolDeposit'
| 'protocolVersion'
>
>;
export type ProtocolParametersRequiredByWallet = Omit<Cardano.ProtocolParameters, 'costModels'>;

export type SupplySummary = {
circulating: Cardano.Lovelace;
Expand Down

0 comments on commit 3b69ea4

Please sign in to comment.