Setting up the SDK

To install the Yelay SDK, use the following npm command:

npm install "@spool.fi/spool-v2-sdk"

To use the Yelay SDK, you need to create an instance of the SpoolSdk class. To accomplish this, call the following function with these parameters:

import { SpoolSdk } from '@spool.fi/spool-v2-sdk';


const yelaySDK = new SpoolSdk(
  config: SDKConfig,
  signerOrProvider: Signer | Provider
)

The first parameter is the SDKConfig, which includes the subgraph URL, price feed URL, rewards URL, and ContractAddresses (see examples below).

Example 1: SDKConfig on Ethereum mainnet

Initiate SDKConfig with the addresses of the smart contracts that orchestrate main on-chain functions:

  • SmartVaultFactory is used for deploying new smart vaults (Yelay partners can also apply to be eligible to deploy vaults with performance fee up to 90%; in that case a different address for SmartVaultFactory should be used*)

  • StrategyRegistry is used for managing and keeping the list of strategies

  • DepositManager is used to process deposits

  • DepositSwap is used for wrapping and swapping assets while depositing

  • RewardManager is used to process rewards

  • SpoolLens is a helper contract that provides easier access to certain vault and user data points. It also allows us to simulate the events of certain processes like DoHardWork and flushes.

The following are also required for SDKConfig setup:

  • Link to Subgraph

  • Link to Price feeds service

  • Link to the Rewards Manager service

  • Link to the Fast Withdrawal service

import { SDKConfig } from '@spool.fi/spool-v2-sdk';
const contractAddresses: Record<number, ContractAddresses> = {
    1: {
        ISmartVaultManager: '0x23daf34e2b9af02a74dc19cb52af727b19403874',
        IDepositSwap: '0xd8534197bd587f8226d12e0c864ef2cae6f82f5c',
        ISmartVaultFactory: '0x8049fc710D4a1deea6a6bcef772c166ced7a82f5', // *use 0x362599cdc123e3ffeb7c0812d769128d180667e8 for high performance fees
        IDepositManager: '0x823ba38992825ff37e72b6c3d669a09173b8f7bf',
        IRewardManager: '0xd8d2c1c3c7982272e3e12dec5af681433fdcf003',
        IStrategyRegistry: '0x554c6bcb54656390aca0a0af38ca954dbe653f15',
        ISpoolLens: '0x8aa6174333f75421903b2b5c70ddf8da5d84f74f',
        ISpoolAccessControl: '0x7b533e72e0cdc63aacd8cdb926ac402b846fbd13', // optional
    },
};

const config: SDKConfig = new SDKConfig(
    // it says 'arbitrum' in the URL but the data is just published on arbitrum, it's indexing mainnet
    'https://gateway-arbitrum.network.thegraph.com/api/$API_KEY/subgraphs/id/41A5vZJ2fypeqtD8o5rD1HB7GjVkvP55NR3EeZDXkk2s', // -> replace $API_KEY
    'https://pricefeed.v2.spool.fi/',
    'https://rewards.v2.spool.fi/',
    'https://fastwithdraw.v2.spool.fi/',
    contractAddresses, );

Decentralized subgraph option

In order to access public Yelay subgraph used by the SDK, follow these instructions:

  • First you must create an API key:

    • go to https://thegraph.com/studio/apikeys

    • connect an Ethereum address

    • sign the message to log in (Doesn't cost any Ether)

    • create API key

    • API key name: spool-v2

    • copy key as API_KEY

    • you can now query the Yelay subgraph for:

      • mainnet: https://gateway-arbitrum.network.thegraph.com/api/$API_KEY/subgraphs/id/41A5vZJ2fypeqtD8o5rD1HB7GjVkvP55NR3EeZDXkk2s (it says arbitrum in the URL but the data is just published on arbitrum, it's indexing mainnet)

      • sepolia: 'https://gateway-testnet-arbitrum.network.thegraph.com/api/$API_KEY/subgraphs/id/J5s1Q5ECEuvcyr8hfCVJxdebmwiQTGWbNGXu8GLfnSBj'

  • This will give you 100k queries for free every month.

  • Beyond that, payment is necessary. you can upgrade your plan here: https://thegraph.com/studio/billing/upgrade/ costs are about 4$ per 100k queries.

  • Alternatively, you may use a third party subgraph hosting service, such as Alchemy: https://www.alchemy.com/pricing.

  • Note that deployment of the subgraph to a third party hosting service must be completed for the Yelay subgraph to work there. The code is hosted here: https://github.com/spoolfi/spool-v2-core-subgraph/. There are detailed instructions in the README.

Example 2: test Yelay integration on Sepolia testnet

Yelay UI on Sepolia: https://sepolia.dev.spool.fi/sep/smart-vaults

SDKConfig:

import { SDKConfig } from '@spool.fi/spool-v2-sdk'; 

const contractAddresses = {
    11155111: {
        ISmartVaultManager: '0x2638d6c0b4EF6Dee04050fA0B07CA62500435747',
        IDepositSwap: '0x5FB08e00DE169f041711206A0995410884080177',
        ISmartVaultFactory: '0x8e1f2177adca17b96822d132279b17083dcd67d9', // use 0x86bb0376929218ba1cb825ce2ebe801bfccd8149 for high performance fees
        IDepositManager: '0xfA37dd47F3596681C39D3a1b55474595BB591dc9',
        IRewardManager: '0xcE7F66BD505a80129Ef25b06207Ac49620A55522',
        IStrategyRegistry: '0xf978853Db777d00b1130Ea21d8d98E8710b0Bc56',
        ISpoolLens: '0x33Df6cf08Fbb10047e318989fE687294CD45A7B4',
        IMetaVaultFactory: '0xe07a896CFD8FEdFb6d7515480853c5D5ED30EBFE',
        ISpoolAccessControl: '0x8325F9a463A8Aa72e1a91f57623e41Ee94d43525', //optional
    },
}

const config: SDKConfig = new SDKConfig(
    SubgraphLink, // to get the link please contact the Spool team in Discord by tagging @web3lling
    'https://pricefeed.dev.spool.fi/',
    'https://rewards.dev.spool.fi/sepolia/',
    'https://fastwithdraw.dev.spool.fi/sepolia/',
    contractAddresses,);

Important! On Sepolia, each integrator could initiate running DoHardWork by themselves. Please, reach out to your respective Yelay's technical account manager or the Yelay team on Discord in order to whitelist your account if you want to run DHW on Sepolia.

Please follow these instructions: https://github.com/SpoolFi/spool-v2-testnet-utils/

Sepolia setup has been equipped with 4 ‘mock’ strategies for each asset group:

"strategies": {
    "mock": {
        "beacon": "0xb3752bbb715acae2a3e9c28200b5a0b319f583ef",
        "mock-dai": "0xcc239fff84045cc1c81203695ee5d2e05530f026",
        "mock-usdc": "0x07ffa21cbf983e2f2246750108d9248133c85a98",
        "mock-usdt": "0x68b19781cbe5724b1666d944c729aa15d6925e0b",
        "mock-weth": "0x7fd3f41f2de554d8528db74294a4382f4718f3ad"
    }
}

Example 3: SDKConfig on Arbitrum

import { SDKConfig } from '@spool.fi/spool-v2-sdk'; 
const contractAddresses: Record<number, ContractAddresses> = {
    42161: {
        ISmartVaultManager:'0x72d545d9eb856bd0076b20626ac0bc76d787e098',
        IDepositSwap: '0xab90bd85a5e3dc33ebacfced59ea9f31c3eb21a3',
        ISmartVaultFactory: '0x25be35117497169f771e657e6d7bee14898e54ce', // use 0xaB79c24b134A8be2f5DC801b338Bcb63F375f563 for high performance fees
        IDepositManager: '0x4A98260e9552b09703bf4493B43c72A6b75Be47E',
        IRewardManager: '0x378e4288826d094372d5f61f6f5451026fb481fe',
        IStrategyRegistry: '0x874de028d3cad13d6c33513d92ce1e75d849199d',
        ISpoolLens: '0x902cbdd00a233d2057a8327cad5475d643dba1dd',
        IMetaVaultFactory: '0x0',
        ISpoolAccessControl: '0x68306356f6dde2b8a731cD02F7466e75977EfCF9', // optional
    },
}; 

const config: SDKConfig = new SDKConfig(
    decentralisedSubgraphLink, // to get the link please contact the Spool team in Discord by tagging @web3lling
    'https://pricefeed.v2.spool.fi/',
    'https://rewards.v2.spool.fi/arbitrum/',
    'https://fastwithdraw.v2.spool.fi/arbitrum',
    contractAddresses, );

Ethers Provider and Signer

If you intend to use only the view-only functions, only the Provider object can be used.

If you are planning to call state-changing transactions, you will require a Signer to sign transactions.

Creating an instance of Provider

const rpc = new StaticJsonRpcProvider('your_rpc_url_here');

Creating an instance of Signer

const pk = 'your_private_key_here'
const rpc = new StaticJsonRpcProvider('your_rpc_url_here');
const signer = new Wallet(pk, rpc);

Please replace the placeholder values with the actual values required for your use case.

Last updated