npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@apyrase/client

v0.0.3

Published

Apy-on-Aptos client

Downloads

11

Readme

Apy on Aptos nodejs and web client

The Apy on Aptos client provides a convenient way to interact with the Apy protocol on Aptos blockchain using JavaScript. It offers a set of utility functions, classes, and types to simplify the integration process and enhance developer productivity.

This library provides a clean wrapper around all the methods exposed by a Apy-on-Aptos contract, as well as the APY indexer REST API. The library is written in TypeScript and defines all the types exposed by underlying services.

Main features

  • Thin wrapper around the standard Aptos client.
  • Fully written in TypeScript, with strict types for security and safety.
  • Integration with popular Aptos wallets, such as Pontem.
  • Complete functionality for making calls to the contract and effective retriving market state from the Apy indexer.

Installation

For use in Node.js or a web application

$ pnpm install 

Once the package is installed, you can import the library using import or require approach:

import { ApyClient, AccountProvider } from "@apy/client"
import { Apy } from "@apy/client/markets"

Example

To run the example it needs the Apy-on-Aptos to be published and lend-borrow markets to be configured.
For details refer to Apy-on-Aptos testnet deployment instruction

import { ApyClient, AccountProvider } from "@apy/client"
import { AptosClient, AptosAccount, HexString } from "aptos"
import { Apy } from "@apy/client/markets"

// coin types
const USDC = process.env.USDC!
const BTC = process.env.BTC!
const ETH = process.env.ETH!

const APY = new HexString(process.env.APY!)
const NODE_URL = process.env.APTOS_NODE_URL!

// create apy client powered by simple account provider. In real world applications use Pontem wallet.  
export function getApyClient(signer: AptosAccount, client: AptosClient, apy: HexString): ApyClient {
  return new ApyClient(new AccountProvider(client, signer), apy);
}

export function isSet<T>(val?: T): T {
  if (val === undefined) {
    throw new Error("value is unknown")
  }
  return val
}

// It supposed, we have configured BTC, USDC and ETH markets.
const markets = new Apy(APY)
await markets.updateMarkets(new AptosClient(NODE_URL))

const borrower = new AptosAccount();
const lender = new AptosAccount();
// ... endow borrower with USDC and lender with BTC

const client = new AptosClient(NODE_URL);

let borrowerClient = getApyClient(borrower, client, APY)
let lenderClient = getApyClient(lender, client, APY)

// fetch markets into application cache
const apy = new Apy(APY)
await apy.updateMarkets(client)

const usdcMarket = isSet(apy.getMarketByCoinPeriod(USDC, "Hour"))
const ethMarket = isSet(apy.getMarketByCoinPeriod(ETH, "Hour"))
const btcMarket = isSet(apy.getMarketByCoinPeriod(BTC, "Hour"))

// deposit USDC as a collateral

await borrowerClient.deposit(usdcMarket, '100_000')

// deposit BTC and place a lend order
await lenderClient.deposit(btcMarket, '1.0')
await lenderClient.lend(btcMarket, '1.0', 1) // 1%

// cancel previous order and place new one at 2% 
await lenderClient.lend_cancel(btcMarket)
await lenderClient.lend(btcMarket, '1.0', 2.0) // 2%

// create borrow request on the 0.01 BTC
await borrowerClient.borrow(btcMarket, '0.01', 0) // 0.01 BTC at market rate(2%) 

// withdraw borrowed BTC
await borrowerClient.withdraw(btcMarket, '0.01')

Getting APY market states