Skip to main content

kalypso-sdk

kalypso-sdk is a npm package that provides the tools required by various participants to interact with different components of the Kalypso ecosystem.

note

Installing the kalypso-sdk makes programmatic interactions with Kalypso convenient. While installation is a one-time activity, steps below also explain the different ways to configure it.

Install and setup the necessary npm packages

  • Create a directory kalypso-tutorial and initialize a project

    mkdir kalypso-tutorial
    cd kalypso-tutorial
    npm init
  • Install kalypso-sdk

    npm install kalypso-sdk --save
  • Install ts-node

    npm install ts-node --save
  • Edit scripts in package.json and add a start script as follows:

    /kalypso-tutorial/package.json
    {
    "name": "kalypso-tutorial",
    "version": "1.0.0",
    "description": "",
    "main": "index.js",
    "scripts": {
    "start": "ts-node index.ts"
    },
    "author": "",
    "license": "ISC",
    "dependencies": {
    "kalypso-sdk": "^1.0.29",
    "ts-node": "^10.9.2"
    }
    }

Configuration files: contracts and endpoints

  • Create a contracts directory with a json file arb-sepolia.json that contains important contract addresses and endpoints to be used in the SDK (as shown in the next step)

    mkdir contracts
    touch contracts/arb-sepolia.json
  • Edit the contents of ./contracts/arb-sepolia.json in an editor as follows. You can also find the contents of this json file on GitHub. Most values prescribed here are common across users through out the Kalypso protocol and updating them unilaterally will break compatibility with the marketplace.

    /kalypso-tutorials/contracts/arb-sepolia.json
    {
    "//comment1":
    "The generatorEnclave field is only required if you wish to join as a Generator in a
    type-1 or type-2 market i.e. markets which support confidential inputs",

    "generatorEnclave": {
    "url": "http://not deployed yet:5000",
    "utilityUrl": "http://not deployed yet:1500"
    },

    "//comment2":
    "The ivsEnclave field is only required if you are a Market Creator who wishes to
    create a type-3 or type-4 market i.e. markets which support only public inputs",

    "ivsEnclave": {
    "url": "http://not deployed yet:5000",
    "utilityUrl": "http://not deployed yet:1500"
    },

    "//comment3":
    "It is recommended to copy-paste the following values as-is
    and update them any time there are any protocol-wide changes",

    "payment_token": "0x01d84D33CC8636F83d2bb771e184cE57d8356863",
    "staking_token": "0xdb69299dDE4A00c99b885D9f8748B2AeD1Fe4Ed4",
    "entity_registry": "0xFFf22f221B9dB47a43cA5c8f48f7915c7957539c",
    "generator_registry": "0xCf30295AfC4F12FfAC6EE96Da3607e7749881BA7",
    "proof_market_place": "0xBD3700b9e4292C4842e6CB87205192Fa96e8Ed05",
    "tee_verifier_deployer": "0x5acCC2F599045D13EA03e4c2b7b0Ed9F8C7Fb99C",
    "matchingEngineEnclave": {
    "url": "http://not deployed yet:5000",
    "utilityUrl": "http://not deployed yet:1500"
    },
    "attestation_verifier": "0x63EEf1576b477Aa60Bfd7300B2C85b887639Ac1b",
    "attestationVerifierEndPoint": "http://13.201.207.60:1400"
    }

    Fields

    • generatorEnclave (only required if you are a Generator in a type-1 or type-2 market):

      • Description: The URLs for accessing the Proof Generator enclave and its utilities.
      • url: endpoint of the prover-executable
      • utilityUrl: URL to fetch attestations for the Generator enclave
    • ivsEnclave (only required if you are Market Creator who is creating a type-3 or type-4 market):

      • Description: The URLs for accessing the IVS enclave and its utilities.
      • url: endpoint of the input-verification-executable
      • utilityUrl: URL to fetch attestations for the Input Verification enclave
    • payment_token:

      • Description: The token used for payments within the system. This address corresponds to USDC on Arbitrum Nova.
    • staking_token

      • Description: The token that is staked by Generators. This address corresponds to POND on Arbitrum Nova.
    • entity_registry

      • Description: The contract that maintains the enclave keys (post attestation) of different entities or components in the system (the Matching Engine, IVS enclaves and Generators).
    • generator_registry:

      • Description: The contract that maintains information about registered Generators and their state (current stake, computational resources, reward address, registered markets etc).
    • proof_market_place:

      • Description: The marketplace contract where proof requests are made.
    • tee_verifier_deployer

      • Description: The contract responsible for deploying TEE verifier contracts.
    • matchingEngineEnclave: (Optional, and only required if you are performing actions related to the operation of the Matching Engine Enclave)

      • Description: The URLs for accessing the matching engine enclave and its utilities.
      • url: URL to access matching engine state
      • utilityUrl: URL to access matching engine attestations
    • attestation_verifier:

      • Description: The contract that verifies root attestations of Oyster enclaves.
    • attestationVerifierEndPoint:

      • Description: The endpoint for fetching the verified attestation that can be verified on attestation_verifier contract

Configuration files: keys

  • Create a keys directory with a json file arb-sepolia.json

    mkdir keys
    touch keys/arb-sepolia.json
  • Edit the contents of ./keys/arb-sepolia.json on an editor with the following information:

    /kalypso-tutorials/keys/arb-sepolia.json
    {
    "rpc": "https://arb-sepolia.g.alchemy.com/v2/your_api_key",
    "private_key": "your private key"
    }
    • rpc: An RPC endpoint of the corresponding chain
    • private_key: Your private key used for contract deployments and to pay for gas

Testing the SDK

  • Create a file named index.ts

    touch index.ts
  • Copy-paste the following code snippet. You need to create an instance of KalypsoSdk to interact with the different components of Kalypso.

    /kalypso-tutorial/index.ts
    import { ethers } from "ethers";
    import { KalspsoConfig } from "kalypso-sdk/dist/types";
    import { KalypsoSdk } from "kalypso-sdk";
    import * as fs from "fs";

    const kalypsoConfig: KalspsoConfig = JSON.parse(fs.readFileSync("./contracts/arb-sepolia.json", "utf-8"));
    const keys = JSON.parse(fs.readFileSync("./keys/arb-sepolia.json", "utf-8"));

    const provider = new ethers.JsonRpcProvider(keys.rpc);
    const wallet = new ethers.Wallet(`${keys.private_key}`, provider);

    async function main() {
    console.log("using address", await wallet.getAddress());

    const kalypso = new KalypsoSdk(wallet, kalypsoConfig);

    // your interaction with Kalypso starts here

    return "Done";
    }

    main().then(console.log).catch(console.log);

Verify the setup

Run the following command on terminal

npm run start

If the script successfully executes without any errors, kalypso-sdk should be ready to use.

tip

A variety of operations can be performed on Kalypso by simply modifying the contents of index.ts.