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

0.0.2 • Public • Published

Chain abstraction SDK

Installation

npm install @arcana/ca-sdk

Quick start

import { CA } from "@arcana/ca-sdk";

const provider = window.ethereum

const providerWithCA = new CA(provider)
await providerWithCA.init();
await providerWithCA.request({
    method: "eth_sendTransaction",
    params: [{
        to: "0xEa46Fb4b4Dc7755BA29D09Ef2a57C67bab383A2f",
        from: "0x7f521A827Ce5e93f0C6D773525c0282a21466f8d",
        value: "0x001"
    }],
})

Usage

Import and initialize

import { CA } from "@arcana/ca-sdk";
const ca = new CA(window.ethereum);
await ca.init();

ca can be used as a drop in replacement for EIP1193 provider(like window.ethereum)

API

UI Hooks for allowance and intent

ca.setOnAllowanceHook(async ({ allow, deny, sources }) => {
  // This is a hook for the dev to show user the allowances that need to be setup for the current tx to happen

  // sources: an array of objects with minAllowance, chainID, token symbol etc
  // allow(allowances): continue the flow - allowances is an array with allowance for each source (len(sources) == len(allowances))
  // deny(): stop the flow
})

ca.setOnIntentHook(({ intent, allow, deny, refresh }) => {
  // This is a hook for the dev to show user the intent, the sources and associated fees

  // intent: Intent data containing sources and fees for display purpose
  // allow(): accept the current intent and continue the flow
  // deny(): deny the intent and stop the flow
  // refresh(): should be on a timer of 5s to refresh the intent (if not refreshed old intents might fail due to fee changes)
})

Get unified balance

const balances = await ca.getUnifiedBalances()
const usdtBalance = await ca.getUnifiedBalance("usdt")

Bridge

await ca.bridge().token("usdt").amount(10).chain(137).exec();

chain() is optional, it will use the current chain as input if not specified.

Transfer

await ca.transfer().to("0x...").amount(5).chain(10).token("eth").exec()

chain() is optional, it will use the current chain as input if not specified.

Get allowance

// Get USDC allowance for polygon chain
await ca.allowance().tokens(["USDC"]).chain(137).get()

// Get USDC & USDT allowance for all supported chains
await ca.allowance().tokens(["USDC", "USDT"]).get()

// Get all supported token allowances for all supported chains
await ca.allowance().get()

Set allowance

await ca.allowance().tokens(["USDC"]).chain(42161).amount(BigInt(100000000000)).set()

Revoke allowance

await ca.allowance().tokens(["USDC"]).chain(42161).revoke()

CA Events listener

Add listener
ca.addCAEventListener((data) => {
    switch(data.type) {
        case "EXPECTED_STEPS":{
            // store data.data(an array of steps which will be followed)
            state.value.steps = data.data.map(s => ({ ...s, done: false }))
            state.value.inProgress = true
            break;
        }
        case "STEP_DONE": {
            const v = state.value.steps.find(s => {
                return s.typeID === data.data.typeID
            })
            if (v) {
                v.done = true
            }
            break;
        }
    }
});
Remove listener
ca.removeCAEventListener((data) => {...})

Readme

Keywords

none

Package Sidebar

Install

npm i @arcana/ca-sdk

Weekly Downloads

179

Version

0.0.2

License

MIT

Unpacked Size

559 kB

Total Files

42

Last publish

Collaborators

  • adminarcana
  • makyl
  • shrinath-newfang
  • mmjee-nf
  • subhamchar
  • fagunb
  • shalooshalini
  • arcanarnsdk