Skip to content

Commit

Permalink
Merge branch 'plutus-v3'
Browse files Browse the repository at this point in the history
  • Loading branch information
KtorZ committed Aug 13, 2024
2 parents d8f3e57 + 5be503c commit a010169
Show file tree
Hide file tree
Showing 17 changed files with 679 additions and 88 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ jobs:
uses: actions/configure-pages@v2

- name: 🧰 Install Aiken
uses: aiken-lang/setup-aiken@v1
uses: aiken-lang/setup-aiken@v0.1.0
with:
version: v1.0.28-alpha
version: v1.0.18-alpha

- name: 📝 Run fmt
run: aiken fmt --check
Expand All @@ -52,7 +52,7 @@ jobs:
path: "docs/"

deploy:
# if: ${{ startsWith(github.ref, 'refs/tags') }}
if: ${{ startsWith(github.ref, 'refs/tags') }}
needs: build
runs-on: ubuntu-latest
environment:
Expand Down
4 changes: 4 additions & 0 deletions lib/aiken/collection.ak
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/// An positive integer, that materializes the position of an element in a
/// collection.
pub type Index =
Int
File renamed without changes.
4 changes: 2 additions & 2 deletions lib/aiken/list.ak → lib/aiken/collection/list.ak
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use aiken/builtin
use aiken/bytearray
use aiken/int
use aiken/primitive/bytearray
use aiken/primitive/int

/// Determine if all elements of the list satisfy the given predicate.
///
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion lib/aiken/math/rational.ak
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//// Comparing rational values should, therefore, only happen after reduction (see [reduce](#reduce)) or via the [compare](#compare) method.

use aiken/builtin
use aiken/list
use aiken/collection/list
use aiken/math
use aiken/option

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion lib/aiken/int.ak → lib/aiken/primitive/int.ak
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use aiken/bytearray
use aiken/math
use aiken/option
use aiken/primitive/bytearray

/// Compare two integers.
///
Expand Down
File renamed without changes.
3 changes: 0 additions & 3 deletions lib/aiken/time.ak
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
/// A number of milliseconds since 00:00:00 UTC on 1 January 1970.
pub type PosixTime =
Int
15 changes: 0 additions & 15 deletions lib/aiken/transaction/certificate.ak

This file was deleted.

10 changes: 7 additions & 3 deletions lib/aiken/transaction/value.ak → lib/cardano/assets.ak
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
use aiken/dict.{Dict, from_ascending_pairs_with}
use aiken/collection/dict.{Dict, from_ascending_pairs_with}
use aiken/collection/list
use aiken/hash.{Blake2b_224, Hash}
use aiken/list
use aiken/option
use aiken/transaction/credential.{Script}
use cardano/credential.{Script}

/// Lovelace is now a type wrapper for Int.
pub type Lovelace =
Int

/// A type-alias for a `PolicyId`. A `PolicyId` is always 28-byte long
pub type PolicyId =
Expand Down
71 changes: 71 additions & 0 deletions lib/cardano/certificate.ak
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
use cardano/assets.{Lovelace}
use cardano/credential.{Credential, StakePoolId, VerificationKeyHash}

/// An on-chain certificate attesting of some operation. Publishing
/// certificates / triggers different kind of rules; most of the time,
/// they require signatures from / specific keys.
pub type Certificate {
// Register a stake credential with an optional deposit amount.
// The deposit is always present when using the new registration certificate
// format available since the Conway era.
RegisterCredential { credential: Credential, deposit: Option<Lovelace> }
// Un-Register a stake credential with an optional refund amount
// The deposit is always present when using the new de-registration certificate
// format available since the Conway era.
UnregisterCredential { credential: Credential, refund: Option<Lovelace> }
// Delegate stake to a [Delegate](#Delegate).
DelegateCredential { credential: Credential, delegate: Delegate }
// Register and delegate staking credential to a Delegatee in one certificate.
RegisterAndDelegateCredential {
credential: Credential,
delegate: Delegate,
deposit: Lovelace,
}
// Register a delegate representative (a.k.a DRep). The deposit is explicit and
// is refunded when the delegate steps down (unregister).
RegisterDelegateRepresentative {
delegate_representative: Credential,
deposit: Lovelace,
}
// Update a delegate representative (a.k.a DRep). The certificate also contains
// metadata which aren't visible on-chain.
UpdateDelegateRepresentative { delegate_representative: Credential }
// UnRegister a delegate representative, and refund back its past deposit.
UnregisterDelegateRepresentative {
delegate_representative: Credential,
refund: Lovelace,
}
// Register a new stake pool
RegisterStakePool {
// The hash digest of the stake pool's cold (public) key
stake_pool: StakePoolId,
// The hash digest of the stake pool's VRF (public) key
vrf: VerificationKeyHash,
}
// Retire a stake pool. 'at_epoch' indicates in which the retirement will take place
RetireStakePool { stake_pool: StakePoolId, at_epoch: Int }
// Authorize a Hot credential for a specific Committee member's cold credential
AuthorizeConstitutionalCommitteeProxy {
constitutional_committee_member: Credential,
proxy: Credential,
}
// Step down from the constitutional committee as a member.
RetireFromConstitutionalCommittee {
constitutional_committee_member: Credential,
}
}

pub type Delegate {
DelegateBlockProduction { stake_pool: StakePoolId }
DelegateVote { delegate_representative: DelegateRepresentative }
DelegateBoth {
stake_pool: StakePoolId,
delegate_representative: DelegateRepresentative,
}
}

pub type DelegateRepresentative {
Registered(Credential)
AlwaysAbstain
AlwaysNoConfidence
}
32 changes: 17 additions & 15 deletions lib/aiken/transaction/credential.ak → lib/cardano/credential.ak
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use aiken/builtin
use aiken/hash.{Blake2b_224, Hash}
use aiken/hash.{Blake2b_224, Blake2b_256, Hash}

/// A general structure for representing an on-chain `Credential`.
///
/// Credentials are always one of two kinds: a direct public/private key
/// pair, or a script (native or Plutus).
pub type Credential {
VerificationKeyCredential(Hash<Blake2b_224, VerificationKey>)
ScriptCredential(Hash<Blake2b_224, Script>)
VerificationKey(VerificationKeyHash)
Script(ScriptHash)
}

/// A Cardano `Address` typically holding one or two credential references.
Expand All @@ -23,18 +23,12 @@ pub type Address {

/// Smart-constructor for an [Address](#Address) from a [verification key](#VerificationKey) hash. The resulting address has no delegation rights whatsoever.
pub fn from_verification_key(vk: Hash<Blake2b_224, VerificationKey>) -> Address {
Address {
payment_credential: VerificationKeyCredential(vk),
stake_credential: None,
}
Address { payment_credential: VerificationKey(vk), stake_credential: None }
}

/// Smart-constructor for an [Address](#Address) from a [script](#Script) hash. The address has no delegation rights whatsoever.
pub fn from_script(script: Hash<Blake2b_224, Script>) -> Address {
Address {
payment_credential: ScriptCredential(script),
stake_credential: None,
}
Address { payment_credential: Script(script), stake_credential: None }
}

/// Set (or reset) the delegation part of an [Address](#Address) using a [verification key](#VerificationKey) hash. This is useful when combined with [`from_verification_key`](#from_verification_key) and/or [`from_script`](#from_script).
Expand All @@ -44,7 +38,7 @@ pub fn with_delegation_key(
) -> Address {
Address {
payment_credential: self.payment_credential,
stake_credential: Some(Inline(VerificationKeyCredential(vk))),
stake_credential: Some(Inline(VerificationKey(vk))),
}
}

Expand All @@ -55,7 +49,7 @@ pub fn with_delegation_script(
) -> Address {
Address {
payment_credential: self.payment_credential,
stake_credential: Some(Inline(ScriptCredential(script))),
stake_credential: Some(Inline(Script(script))),
}
}

Expand Down Expand Up @@ -107,6 +101,14 @@ pub type StakeCredential =
pub type PaymentCredential =
Credential

/// A unique stake pool identifier, as a hash of its owner verification key.
pub type PoolId =
pub type StakePoolId =
Hash<Blake2b_224, VerificationKey>

pub type VerificationKeyHash =
Hash<Blake2b_224, VerificationKey>

pub type ScriptHash =
Hash<Blake2b_224, Script>

pub type DatumHash =
Hash<Blake2b_256, Data>
109 changes: 109 additions & 0 deletions lib/cardano/governance.ak
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
use aiken/collection.{Index}
use aiken/hash.{Blake2b_256, Hash}
use aiken/math/rational.{Rational}
use cardano/assets.{Lovelace}
use cardano/credential.{Credential, ScriptHash, VerificationKeyHash}
use cardano/governance/protocol_parameters.{ProtocolParametersUpdate}

pub type ProposalProcedure {
deposit: Lovelace,
return_address: Credential,
governance_action: GovernanceAction,
}

pub type GovernanceAction {
ProtocolParameters {
/// The last governance action of type 'ProtocolParameters'. They must all
/// form a chain.
ancestor: Option<GovernanceActionId>,
/// The new proposed protocol parameters. Only values set to `Some` are relevant.
new_parameters: ProtocolParametersUpdate,
/// The optional guardrails script defined in the constitution. The script
/// is executed by the ledger in addition to the hard-coded ledger rules.
///
/// It must pass for the new protocol parameters to be deemed valid.
guardrails: Option<ScriptHash>,
}
HardFork {
/// The last governance action of type `HardFork`. They must all
/// form a chain.
ancestor: Option<GovernanceActionId>,
/// The new proposed version. Few rules apply to proposing new versions:
///
/// - The `major` component, if incremented, must be exactly one more than the current.
/// - The `minor` component, if incremented, must be exactly one more than the current.
/// - If the `major` component is incremented, `minor` must be set to `0`.
/// - Neither `minor` nor `major` can be decremented.
new_version: ProtocolVersion,
}
TreasuryWithdrawal {
/// A collection of beneficiaries, which can be plain verification key
/// hashes or script hashes (e.g. DAO).
beneficiaries: Pairs<Credential, Lovelace>,
/// The optional guardrails script defined in the constitution. The script
/// is executed by the ledger in addition to the hard-coded ledger rules.
///
/// It must pass for the withdrawals to be authorized.
guardrails: Option<ScriptHash>,
}
NoConfidence {
/// The last governance action of type `NoConfidence` or
/// `ConstitutionalCommittee`. They must all / form a chain.
ancestor: Option<GovernanceActionId>,
}
ConstitutionalCommittee {
/// The last governance action of type `NoConfidence` or
/// `ConstitutionalCommittee`. They must all / form a chain.
ancestor: Option<GovernanceActionId>,
/// Constitutional members to be removed.
evicted_members: List<Credential>,
/// Constitutional members to be added.
added_members: Pairs<Credential, Mandate>,
/// The new quorum value, as a ratio of a numerator and a denominator. The
/// quorum specifies the threshold of 'Yes' votes necessary for the
/// constitutional committee to accept a proposal procedure.
quorum: Rational,
}
NewConstitution {
/// The last governance action of type `Constitution` or
/// `ConstitutionalCommittee`. They must all / form a chain.
ancestor: Option<GovernanceActionId>,
/// The new proposed constitution.
constitution: Constitution,
}
NicePoll
}

pub type Vote {
No
Yes
Abstain
}

pub type TransactionId =
Hash<Blake2b_256, ByteArray>

pub type GovernanceActionId {
transaction: TransactionId,
proposal_procedure: Index,
}

pub type ProtocolVersion {
major: Int,
minor: Int,
}

pub type Constitution {
guardrails: Option<ScriptHash>,
}

/// An epoch number after which constitutional committee member
/// mandate expires.
pub type Mandate =
Int

pub type Voter {
ConstitutionalCommitteeMember(Credential)
DelegateRepresentative(Credential)
StakePool(VerificationKeyHash)
}
Loading

0 comments on commit a010169

Please sign in to comment.