@goblinsax/goblink-sdk
TypeScript icon, indicating that this package has built-in type declarations

0.0.7 • Public • Published

Goblink-SDK

Overview

The Goblink-SDK acts as a bridge between the GoblinSax Analytical Backend and supported Execution Layers. This SDK provides specific functions for creating, modifying, or deleting NFT Loan Offers on the supported Execution Layers. By standardizing the data input for these functions, it simplifies interaction with the supported partner protocols.

Installation

The Goblink-SDK is available as an npm package. You can install it by running the following command:

npm install @goblinsax/goblink-sdk

Currently, we do not allow external contributions to our codebase, though that might change in the future.

Usage

The /examples folder contains code snippets demonstrating how to use the Goblink-SDK. After initializing an instance of the Goblink-SDK, you can make function calls such as goblinkSDK.createOffer() and pass the necessary parameters.

Initializing the SDK

Create a new instance of the SDK by providing it with a wallet object and a config type.

const { GoblinkSDK, goerliConfig, LendingProtocol } = require("@goblinsax/goblink-sdk")

const provider = ethers.getDefaultProvider(process.env.GOERLI_NODE_URL);
const wallet = new ethers.Wallet(process.env.WALLET_PRIVATE_KEY, provider);

const sdk = new GoblinkSDK(
        wallet,
        goerliConfig
    );

Function Calls

// Offer data
    const tokenId = '1570335';
    const collectionAddress = '0xf5de760f2e916647fd766b4ad9e85ff943ce3a2b';
    const borrowerAddress = '0x5b92b159C1F0afbb968B1ed8DE830e2b556A0ed7';
    const loanDuration = 86400; // 1 day
    const loanRepayment = "0.001";
    const loanPrincipal = "0.0001";
    const loanCurrency = config.token.weth;
    const expires = 21600 // 6h
    const expiry = Math.floor(Date.now() / 1000) + expires; // now + 6h

    const apiKey = process.env.NFTFI_API_KEY;

    const offerResult = await sdk.createOffer(
        LendingProtocol.NFTFI,
        false, // true for offer signed by SmartWallet, false for manual offer
        apiKey,
        wallet,
        tokenId,
        collectionAddress,
        borrowerAddress,
        wallet.address,
        loanDuration,
        loanRepayment,
        loanPrincipal,
        loanCurrency,
        expiry
    )

    console.log("Offer: ", offerResult)

Public Functions

createOffer

  • creates a normal (aka manual) offer
  • offer signature generated by enduser wallet object
public async createOffer(
    protocol: LendingProtocol,
    autoWallet: boolean,
    apiKey: string,
    lender: Wallet,
    tokenId: string,
    collectionAddress: string,
    borrowerAddress: string,
    lenderAddress: string,
    loanDuration: string,
    loanRepayment: string,
    loanPrincipal: string,
    loanCurrency: string,
    expiry: number,
) {};

After creating an offer successfully, this will be the response object:

{
	status: 201,
	statusText: 'Created', 
	data: {
    nft: {
      address: '0xabc...',
      tokenId: 
    },
    lender: {
      address: '0xabc...'
    },
    borrower: {
      address: '0xabc...'
    },
    referrer: {
      address: '0x0000000000000000000000000000000000000000'
    },
    terms: {
      loan: {
         duration: 
         repayment: 
         principal: 
         currency: 
         expiry: 
         interest: {
            prorated: false,
            bps: 0
         }
      }
    },
    nftfi: {
      contract: {
         name: 'v2-1.loan.fixed'
      },
      fee: {
         bps: '500'
      }
    },
    signature: '0xfdde...61b',
    id: 'f77d47ba-aaaa-bbbb-cccc-ddddddc0dfcd'
  }
}

The data part depends on the Lending Protocol that was used.

createAutoOffer

  • creates an 'autoWallet' nftfi offer
  • offer signature generated by our SmartWallet, not by an EOA
public async createOffer(
    protocol: LendingProtocol,
    autoWallet: true,
    apiKey: string,
    lender: Wallet,
    tokenId: string,
    collectionAddress: string,
    borrowerAddress: string,
    lenderAddress: string,
    loanDuration: string,
    loanRepayment: string,
    loanPrincipal: string,
    loanCurrency: string,
    expiry: number,
) {};

After creating an offer successfully, this will be the response object:

{
	status: 201,
	statusText: 'Created', 
	data: {
    nft: {
      address: '0xabc...',
      tokenId: 
    },
    lender: {
      address: '0xabc...'
    },
    borrower: {
      address: '0xabc...'
    },
    referrer: {
      address: '0x0000000000000000000000000000000000000000'
    },
    terms: {
      loan: {
         duration: 
         repayment: 
         principal: 
         currency: 
         expiry: 
         interest: {
            prorated: false,
            bps: 0
         }
      }
    },
    nftfi: {
      contract: {
         name: 'v2-1.loan.fixed'
      },
      fee: {
         bps: '500'
      }
    },
    signature: '0xfdde...61b',
    id: 'f77d47ba-aaaa-bbbb-cccc-ddddddc0dfcd'
  }
}

deleteOffer

  • deletes offer off-chain
  • needs unique offerId passed as parameter
public async deleteOffer(
    protocol: LendingProtocol,
    lender: Wallet,
    offerId: string,
    apiKey: string,
) {};

After successfully deleting an offer, this will be the response object:

{
   status: 200,
   statusText: 'OK',
	data: 'OK'
}

claimDefaultedLoan

  • claims nft of a defaulted loan to the lender wallet
public async claimDefaultedLoan(
    protocol: LendingProtocol,
    lender: Wallet,
    apiKey: string,
    loanId: string,
) {};

Arcade

The process for Arcade is exactly identical. Hence this part of the documentation will only reflect the differences in the data part of the response object.

createOffer

{
	status: 200,
	statusText: 'OK', 
	data: {
		id: 527,
		contractTokenId: '0xXYZ...-123',
    collateralAddress: '0xXYZ...',
    collateralId: '123',
    role: 'lender',
    state: 'created',
    creatorId: '0xabc...',
    durationSecs: 86400,
    numInstallments: 0,
    interestRate: '1000000000000000',
    principal: '10000000000000000',
    payableCurrency: '0xb4fbf271143f4fbf7b91a5ded31805e42b2208d6',
    deadline: '1687866570',
    createdAt: '2023-06-27T10:49:31.947Z',
    updatedAt: '2023-06-27T10:49:31.947Z',
    kind: 'asset',
    itemsHash: null,
    collectionId: '0xXYZ...',
    itemPredicates: null,
    loanCoreId: null,
    loanId: null,
    loanStartedOn: null,
    fundingAddress: null,
    expiresAt: '2023-06-27T11:49:30.000Z'
	}
}

After creating an autoOffer successfully, this will be the response object:

{
	status: 200,
	statusText: 'OK', 
	data: {
		id: 527,
		contractTokenId: '0xXYZ...-123',
    collateralAddress: '0xXYZ...',
    collateralId: '123',
    role: 'lender',
    state: 'created',
    creatorId: '0xabc...',
    durationSecs: 86400,
    numInstallments: 0,
    interestRate: '1000000000000000',
    principal: '10000000000000000',
    payableCurrency: '0xb4fbf271143f4fbf7b91a5ded31805e42b2208d6',
    deadline: '1687866570',
    createdAt: '2023-06-27T10:49:31.947Z',
    updatedAt: '2023-06-27T10:49:31.947Z',
    kind: 'asset',
    itemsHash: null,
    collectionId: '0xXYZ...',
    itemPredicates: null,
    loanCoreId: null,
    loanId: null,
    loanStartedOn: null,
    fundingAddress: null,
    expiresAt: '2023-06-27T11:49:30.000Z'
	}
}

After successfully deleting an offer, this will be the response object:

{
	status: 200,
  statusText: 'OK',
	data: 'OK'
}

claimDefaultedArcadeLoan

Currently still under development.

X2Y2

After creating an offer successfully, this will be the response object:

{
  status: 200,
  statusText: 'OK',
  data: {
    data: {
      offerId: '1673686631393157120',
      optType: 'insert',
      offerHase: '0xb932561d198d89fa01ccea24752d9da5c30480b2cef2af6ec64271ced02fa4bc' // means offerHash, but typo comes from X2Y2 response
    },
    code: 200,
    msg: 'ok',
    t: 1687872963172
  }
}

sendX2Y2AutoOffer

Currently still under development.

deleteX2Y2Offer

Currently still under development.

claimDefaultedX2Y2Loan

Currently still under development.

Current Limitations

The Goblink-SDK is an evolving project, and new features will be gradually introduced. Stay updated by checking the release notes for information on the latest enhancements.

Readme

Keywords

none

Package Sidebar

Install

npm i @goblinsax/goblink-sdk

Weekly Downloads

0

Version

0.0.7

License

ISC

Unpacked Size

511 kB

Total Files

84

Last publish

Collaborators

  • goblinsax