Skip to main content
Last updated

Create custom policies

In additions to the concrete and example policies, you can use the interfaces defined in the kip.token-policy-v2 standard to create custom policies.

Custom policies allow you to implement rules and checks that are tailored to your specific requirements. To implement a custom policy, you first need to import the functions and interfaces defined in token-policy-v2.

Basic steps

To create a custom policy:

  1. Create a .pact file to contain the policy. For example, create a file called my-custom.pact.

  2. Import the token-policy-v2 interfaces by adding lines similar to the following to the file:

    (namespace 'my-namespace)(import 'marmalade-v2.token-policy-v2)
    (namespace 'my-namespace)(import 'marmalade-v2.token-policy-v2)
  3. Use the following functions to define when policies are enforced:

    • enforce-mint: Governs token minting.
    • enforce-burn: Regulates token burning.
    • enforce-init: Handles token initialization.
    • enforce-offer: Manages token offering for sale.
    • enforce-buy: Controls purchasing of tokens offered for sale.
    • enforce-withdraw: Defines the withdraw policy.
    • enforce-transfer: Administers token transfers between accounts.
  4. Create a .repl file to test different conditions for the policy.

Policy enforcement functions

You can define custom logic for each policy enforcement function to address unique requirements for your tokens. By implementing custom checks within the functions, you can control what happens during each phase of token activity.

enforce-mint

Use enforce-mint to enforce the minting policy for the specified token to the specified account with the specified mint amount.

Parameters

pact
    ( token:object{token-info}      account:string      guard:guard      amount:decimal    )
pact
    ( token:object{token-info}      account:string      guard:guard      amount:decimal    )

Return value

Boolean

enforce-burn

Use enforce-burn to enforce the burn policy for the specified token from the specified account with the specified burn amount.

Parameters

pact
    ( token:object{token-info}      account:string      amount:decimal    )
pact
    ( token:object{token-info}      account:string      amount:decimal    )

Return value

Boolean

enforce-init

Use enforce-init to enforce the logic for the specified token when token created is initiated.

Parameters

pact
(token:object{token-info}))
pact
(token:object{token-info}))

Return value

Boolean

enforce-offer

Use enforce-offer to enforce the offer policy for the specified token offered by the specified seller in the specified amount with the specified sale-id.

Parameters

pact
( token:object{token-info}      seller:string      amount:decimal      timeout:integer      sale-id:string ))
pact
( token:object{token-info}      seller:string      amount:decimal      timeout:integer      sale-id:string ))

Return value

Boolean

enforce-buy

Use enforce-buy to enforce the buy policy for the specified token offered by the specified seller in the specified amount with the specified sale-id.

Parameters

pact
    ( token:object{token-info}      seller:string      buyer:string      buyer-guard:guard      amount:decimal      sale-id:string )  )
pact
    ( token:object{token-info}      seller:string      buyer:string      buyer-guard:guard      amount:decimal      sale-id:string )  )

Return value

Boolean

enforce-withdraw

Use enforce-withdraw to enforce the withdrawal policy for the specified token offered by the specified seller in the specified amount with the specified sale-id.

( token:object{token-info}
  seller:string
  amount:decimal
  timeout:integer
  sale-id:string )

)

Return value

Boolean

enforce-transfer

Use enforce-transfer to enforce the transfer policy for the specified token in the specified amount from the specified sender to the specified receiver. This function also governs rotation of the sender with same receiver and an amount of 0.0.

Parameters

pact
    ( token:object{token-info}      sender:string      guard:guard      receiver:string      amount:decimal )    @doc "   )
pact
    ( token:object{token-info}      sender:string      guard:guard      receiver:string      amount:decimal )    @doc "   )

Return value

Boolean