Deals

The Deals SDK offers developers a way to digitise commercial agreement term sheets and payment terms through smart contracts.

Create Deal

A deal is the representation of a term sheet with certain deliverables and associated payment schedules. Payments can have programmed rules attached for their release. Payments are initially locked into the vault upon the commencement of the agreement, prior to meeting the specific rules / tests allowing their release. Users can specify the value of the initial payments locked into the escrow function of the vault. This could be partial or complete collateralisation of the payments potentially due under the term sheet agreement.

The deal is created by the party expecting to be to be paid. Creation of the deal implied an acceptance to the terms by the payee, because otherwise, why would one create a deal with those terms?

Instructions

First, ensure you've imported the required libraries:

import { NotVault, Tokens, Deals, Files } from '@notcentralised/notvault-sdk';
  1. Instantiate the NotVault, Tokens, Files, and Deals classes:

const vault = new NotVault();
const tokens = new Tokens(vault);
const files = new Files(vault);
const deals = new Deals(vault, tokens, files);

This initialization is crucial for managing deals, tokens, and files within the NotVault.

  1. Create a deal

These initialisations provide the necessary setup to manage deals, tokens, and files within the NotVault.

const deal = await deals.createDeal(
    '... Token Address ...', 
    '... Oracle Address ...',
    { 
        name: '... Deal Name ...', 
        counterpart: '... Email or Address ...',
        description: '... Deal Description ...', 
        notional: 10000,
        initial: 1000,
        unlock_sender: Math.floor(new Date('2023-08-10').getTime() / 1000), // unix format
        unlock_receiver: Math.floor(new Date('2024-08-10').getTime() / 1000), // unix format
        oracle_owner: '... Owner Address ...',
        oracle_key: 1,
        oracle_value: 1
    },
    {
        data: [{
            created: 1685512747,
            data: 'B64',
            name: 'filename'
        }]
    });

The create method of the Deals class is used to create a deal. It returns a deal_cid (content identifier) for the newly created deal. Provide the required parameters:

  • Token Address: The address of the token to be used in the deal.

  • Oracle Address: The address of the oracle.

  • An object containing deal details:

    • Deal Name: The name of the deal.

    • Email or Address: The address of the recipient of the deal.

    • Deal Description: A description of the deal.

    • notional: The total amount of tokens involved in the deal.

    • initial: The initial amount to start the deal.

    • unlock_sender: The date when the sender can withdraw from the deal, represented in UNIX format.

    • unlock_receiver: The date when the receiver can withdraw from the deal, represented in UNIX format.

    • Owner Address: The address of the deal's owner.

    • oracle_key: The key provided by the oracle.

    • oracle_value: The value provided by the oracle.

  • An object representing deal's associated data:

    • created: The creation timestamp.

    • data: The base64 encoded data of the file.

    • name: The name of the file.

  1. Accept Deal

Once a deal has been created, the payor accepts the terms and payment schedule and creates a payment linked to the agreed upon initial collateral amount stated in the deal term sheet.

const hash_id = await deals.accept(
    '... Token Address ...',
    '... Email or Address ...',
    BigInt(1000) /* token amount */ * BigInt(10 ** 18) /* token decimal places */,
    1, // deal ID
    '... Oracle Address ...',
    '... Owner Address ...',
    1, // Oracle Value
    1, // Oracle Key
    Math.floor(new Date('2023-08-10').getTime() / 1000), // date when payer can withdraw in unix format
    Math.floor(new Date('2024-08-10').getTime() / 1000), // date when payee can withdraw in unix format
);

The accept method of the Deals class is used to accept a deal, and it returns a hash ID for the accepted deal. You need to provide the required parameters:

  • Token Address: The address of the token being used in the deal.

  • Email or Address: The address of the recipient of the deal.

  • token amount: The amount of the token in the deal. The provided value is multiplied by 10^18 to account for the token's decimal places.

  • deal ID: A unique identifier for the deal.

  • Oracle Address: The address of the oracle.

  • Owner Address: The address of the owner.

  • Oracle Value: The value provided by the oracle.

  • Oracle Key: The key provided by the oracle.

  • date when payer can withdraw: The date when the payer can withdraw from the deal, represented in UNIX format.

  • date when payee can withdraw: The date when the payee can withdraw from the deal, also represented in UNIX format.

Last updated