Catalog npm
Back to packageRELEASE DETAILS

0.1.15

npm

@0confirmation/sdk

0confirmation sdk

0confirmationsdk
Published26 Jun 2020
Direct dependencies52
Transitive dependenciesNot calculated

README

Current package documentation

@0confirmation/sdk

The flagship 0confirmation product. Imports all relevant modules to capture any sort of logic you would need for building 0confirmation enabled apps.

Usage

Instantiate a Zero instance:


const ethers = require('ethers');
const Zero = require('@0confirmation/sdk');
const makePrivateKeyWeb3Provider = require('@0confirmation/providers/private-key-or-seed') // truffle HDWalletProvider doesn't correctly handle personal_sign, but this provider will!
const web3ProviderFromEthersProvider = require('@0confirmation/providers/from-ethers'); // converts an ethers.js provider to a web3 provider

const provider = makePrivateKeyWeb3Provider('a000000000000000000000000000000000000000000000000000000000000000', web3ProviderFromEthersProvider(new ethers.providers.InfuraProvider('mainnet'));

const zero = new Zero(provider, 'mainnet');

await zero.initializeDriver(); // instantiates a WebRTC connection to the network via lendnet.0confirmation.com

Check liquidity pool renBTC holdings


// instantiate Zero instance

const { makeManagerClass } = require('@0confirmation/eth-manager');
const ERC20 = makeManagerClass(require('@0confirmation/sol/build/DAI')) // will make an ethers.js wrapper compatible with DAI, which is a mock token that exports the ERC20 ABI
const environments = require('@0confirmation/sdk/environments');
const mainnet = environments.getAddresses('mainnet');
const renbtc = new ERC20(mainnet.renbtc, zero.getProvider().asEthers());

const zeroBTC = await zero.getLiquidityTokenFor(mainnet.renbtc);
const liquidityPoolRenBTCHoldings = await renbtc.balanceOf(zeroBTC.address);
console.log(String(liquidityPoolRenBTCHoldings));

ERC20 approve liquidity pool, then add liquidity


await zero.approveLiquidityToken(mainnet.renbtc)
await (
  await zero.addLiquidity(ethers.utils.parseUnits('10', 8))
).wait(); // lets add 10 renbtc to the pool

For a keeper, ERC20 approve transfers by the ShifterPool to be able to execute borrows


await (
  await zero.approvePool(mainnet.renbtc)
).wait();

Create a liquidity request, sign it, broadcast over libp2p, then wait for your borrow proxy


const randomBytes = require('random-bytes').sync;

const liquidityRequest = zero.createLiquidityRequest({
  amount: ethers.utils.parseUnits('0.05', 8),
  gasRequested: ethers.utils.parseEther('0.05'), // request some gas to use your btc with, optional
  nonce: '0x' + randomBytes(32).toString('hex'),
  token: mainnet.renbtc
});

const liquidityRequestParcel = await liquidityRequest.sign();
console.log(liquidityRequestParcel.depositAddress) // outputs the BTC deposit address to initiate the shift
await liquidityRequestParcel.broadcast();
const depositedLiquidityRequestParcel = await liquidityRequestParcel.waitForDeposit();
while (true) {
  const borrowProxy = await depositedLiquidityRequestParcel.getBorrowProxy();
  if (borrowProxy) {
    // can call await borrowProxy.proxy(someContractAddress, calldata, value) to pilot the borrow proxy through supported modules
  } else {
    await new Promise((resolve) => setTimeout(resolve, 5000));
  }
}

Transaction scripts

To run transaction scripts with a borrow, you can either pass an array as follows:


const liquidityRequest = zero.createLiquidityRequest({
  amount: someAmount,
  nonce: someNonce,
  gasRequested: '0',
  token: mainnet.renbtc,
  actions: [{
    to: uniswapRouter,
    calldata: new ethers.utils.Interface(UniswapV2Router01.abi).functions.tokenToTokenSwapInput.encode(...someParameters)
  }]
});

Or for examples of how to use a thunk to preprocess a transaction payload, check the 0confirmation-swap-react for usage of Zero.staticPreprocessor to dynamically assemble bytecode for contract creation code which will be executed in a sandbox to compute a list of transactions to execute.

Refer to 0confirmation-sol/contracts/preprocessors/V2SwapAndDrop.sol for an example of a thunk

TODO

Running a keeper, for now refer to 0confirmation-keeper for example code

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Declared dependencies 52

Native requirements
52 direct targetsNot calculated transitive count
Package / targetRequirementRelationship
@0confirmation/eth-manager
Environment
{
  "local_name": "@0confirmation/eth-manager",
  "alias": false,
  "peer_metadata": null
}
^0.1.4runtime
@0confirmation/p2p
Environment
{
  "local_name": "@0confirmation/p2p",
  "alias": false,
  "peer_metadata": null
}
^0.1.4runtime
@0confirmation/providers
Environment
{
  "local_name": "@0confirmation/providers",
  "alias": false,
  "peer_metadata": null
}
^0.1.6runtime
@0confirmation/renvm
Environment
{
  "local_name": "@0confirmation/renvm",
  "alias": false,
  "peer_metadata": null
}
^0.1.4runtime
@0confirmation/sol
Environment
{
  "local_name": "@0confirmation/sol",
  "alias": false,
  "peer_metadata": null
}
^0.1.10runtime
@babel/core
Environment
{
  "local_name": "@babel/core",
  "alias": false,
  "peer_metadata": null
}
^7.9.0runtime
@babel/plugin-transform-modules-commonjs
Environment
{
  "local_name": "@babel/plugin-transform-modules-commonjs",
  "alias": false,
  "peer_metadata": null
}
^7.9.0runtime
@babel/preset-env
Environment
{
  "local_name": "@babel/preset-env",
  "alias": false,
  "peer_metadata": null
}
^7.9.0runtime
@nodeutils/defaults-deep
Environment
{
  "local_name": "@nodeutils/defaults-deep",
  "alias": false,
  "peer_metadata": null
}
^1.1.0runtime
@renproject/ren
Environment
{
  "local_name": "@renproject/ren",
  "alias": false,
  "peer_metadata": null
}
^1.0.2runtime
@truffle/hdwallet-provider
Environment
{
  "local_name": "@truffle/hdwallet-provider",
  "alias": false,
  "peer_metadata": null
}
^1.0.32runtime
@truffle/workflow-compile
Environment
{
  "local_name": "@truffle/workflow-compile",
  "alias": false,
  "peer_metadata": null
}
^2.1.24runtime
@uniswap/sdk
Environment
{
  "local_name": "@uniswap/sdk",
  "alias": false,
  "peer_metadata": null
}
^2.0.5runtime
babel-loader
Environment
{
  "local_name": "babel-loader",
  "alias": false,
  "peer_metadata": null
}
^8.1.0runtime
bitcoin-core
Environment
{
  "local_name": "bitcoin-core",
  "alias": false,
  "peer_metadata": null
}
^3.0.0runtime
bitcore-lib
Environment
{
  "local_name": "bitcore-lib",
  "alias": false,
  "peer_metadata": null
}
^8.16.0runtime
bluebird
Environment
{
  "local_name": "bluebird",
  "alias": false,
  "peer_metadata": null
}
^3.5.4runtime
bn.js
Environment
{
  "local_name": "bn.js",
  "alias": false,
  "peer_metadata": null
}
^5.1.1runtime
bufferutil
Environment
{
  "local_name": "bufferutil",
  "alias": false,
  "peer_metadata": null
}
^4.0.1runtime
chai
Environment
{
  "local_name": "chai",
  "alias": false,
  "peer_metadata": null
}
^4.2.0runtime
cross-env
Environment
{
  "local_name": "cross-env",
  "alias": false,
  "peer_metadata": null
}
^7.0.0runtime
emasm
Environment
{
  "local_name": "emasm",
  "alias": false,
  "peer_metadata": null
}
git+https://bitbucket.org/raypulver/emasm.gitruntime
ethereumjs-vm
Environment
{
  "local_name": "ethereumjs-vm",
  "alias": false,
  "peer_metadata": null
}
^4.1.3runtime
ethers
Environment
{
  "local_name": "ethers",
  "alias": false,
  "peer_metadata": null
}
^4.0.47runtime
fs-extra
Environment
{
  "local_name": "fs-extra",
  "alias": false,
  "peer_metadata": null
}
^8.1.0runtime
ganache-cli
Environment
{
  "local_name": "ganache-cli",
  "alias": false,
  "peer_metadata": null
}
^6.9.1runtime
libp2p
Environment
{
  "local_name": "libp2p",
  "alias": false,
  "peer_metadata": null
}
^0.27.0-rc.0runtime
libp2p-bootstrap
Environment
{
  "local_name": "libp2p-bootstrap",
  "alias": false,
  "peer_metadata": null
}
^0.10.4runtime
libp2p-kad-dht
Environment
{
  "local_name": "libp2p-kad-dht",
  "alias": false,
  "peer_metadata": null
}
^0.18.5runtime
libp2p-mdns
Environment
{
  "local_name": "libp2p-mdns",
  "alias": false,
  "peer_metadata": null
}
^0.13.3runtime
libp2p-secio
Environment
{
  "local_name": "libp2p-secio",
  "alias": false,
  "peer_metadata": null
}
^0.12.3runtime
libp2p-spdy
Environment
{
  "local_name": "libp2p-spdy",
  "alias": false,
  "peer_metadata": null
}
^0.13.3runtime
libp2p-tcp
Environment
{
  "local_name": "libp2p-tcp",
  "alias": false,
  "peer_metadata": null
}
^0.14.4runtime
libp2p-websocket-star
Environment
{
  "local_name": "libp2p-websocket-star",
  "alias": false,
  "peer_metadata": null
}
^0.10.2runtime
libp2p-websockets
Environment
{
  "local_name": "libp2p-websockets",
  "alias": false,
  "peer_metadata": null
}
^0.13.5runtime
mocha
Environment
{
  "local_name": "mocha",
  "alias": false,
  "peer_metadata": null
}
^7.1.0runtime
net
Environment
{
  "local_name": "net",
  "alias": false,
  "peer_metadata": null
}
^1.0.2runtime
npm-run-all
Environment
{
  "local_name": "npm-run-all",
  "alias": false,
  "peer_metadata": null
}
^4.1.5runtime
peer-info
Environment
{
  "local_name": "peer-info",
  "alias": false,
  "peer_metadata": null
}
^0.17.0runtime
promise-retry
Environment
{
  "local_name": "promise-retry",
  "alias": false,
  "peer_metadata": null
}
^1.1.1runtime
pull-stream
Environment
{
  "local_name": "pull-stream",
  "alias": false,
  "peer_metadata": null
}
^3.6.9runtime
random-bytes
Environment
{
  "local_name": "random-bytes",
  "alias": false,
  "peer_metadata": null
}
^1.0.0runtime
safe-buffer
Environment
{
  "local_name": "safe-buffer",
  "alias": false,
  "peer_metadata": null
}
^5.2.0runtime
scrypt-js
Environment
{
  "local_name": "scrypt-js",
  "alias": false,
  "peer_metadata": null
}
^3.0.0runtime
send-crypto
Environment
{
  "local_name": "send-crypto",
  "alias": false,
  "peer_metadata": null
}
^0.2.3runtime
tls
Environment
{
  "local_name": "tls",
  "alias": false,
  "peer_metadata": null
}
^0.0.1runtime
utf-8-validate
Environment
{
  "local_name": "utf-8-validate",
  "alias": false,
  "peer_metadata": null
}
^5.0.2runtime
uuid
Environment
{
  "local_name": "uuid",
  "alias": false,
  "peer_metadata": null
}
^3.3.3runtime
web3-utils
Environment
{
  "local_name": "web3-utils",
  "alias": false,
  "peer_metadata": null
}
^1.2.6runtime
webpack
Environment
{
  "local_name": "webpack",
  "alias": false,
  "peer_metadata": null
}
^4.42.1runtime
webpack-cli
Environment
{
  "local_name": "webpack-cli",
  "alias": false,
  "peer_metadata": null
}
^3.3.11runtime
webpack-node-externals
Environment
{
  "local_name": "webpack-node-externals",
  "alias": false,
  "peer_metadata": null
}
^1.7.2runtime

Distribution files

1 collected
Distribution 1

Source distribution

Source file
Checksums from source
{
  "integrity": "sha512-a79n37fmTI6QZXp8FHnAJzWIwPysq8qjHLLCR5iYh4vrXKq46za2Tp2J+/NUaueZJGdjnfkmL1VL4ZVrKsGh2g==",
  "shasum": "a210fb7ce277ad21e0f06019f77504aef01d8ede",
  "tarball": "https://registry.npmjs.org/@0confirmation/sdk/-/sdk-0.1.15.tgz",
  "fileCount": 54,
  "unpackedSize": 32032611,
  "npm-signature": "-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJe9l3YCRA9TVsSAnZWagAARyAP/i6vtlwsN3LRhMLqN+/4\nR5l84oH3P1h/1esWu+PPkoyVtNapIwHLQgP8mHPZRmTZPgq4fgpg9MgqJduH\nmzi668ZNyoK1JckSH1tkljQnvT1PXwnKLKGND5RqZFU/ROlPvI5xmUscifFX\n7agvmHkG2qkveTQDvIrw2VjDL/tMpu5BfQLx4US/7noPd/XpHECeNfzQbVjz\nQh/W3L5uqNgP9p0U9ViHqtQjMaIwzlp//QK/udpZaO1ZzeoyFEQ5DZhjJdpH\na+zIloz5i/vFfNYepBsNHs2SSRpoGePj0PutVR/1wd6j/dl8LIN5qxJ/bjO4\nxRTjagdh3VB59TzxTiN0ab5SPuo3fizJi91NLhnQqwMCKLrpEC4CW2D1hlAd\nZVPgV8DFw03Sml42vghmZj5IBZJjGg9kbYlwfCgm98Xgv5WXHYa1tYn5Tps5\n2NyRiNBpcwQu7TgAwIKkailMAv8FlCZkvBH2uVVuEqcLvhz8q9Ayr9WHDyaq\np+dIgceCRHvm9lk+s40RxxGuzh0cAwmO5fALGMvrTmNmwui6aqF2/TqCh5gb\nhI2ejku1eOJdoEJ462nNPZd2oo1uUB6DEIsyEgtTphuv9vTG4PeX4B9QOypS\nSMrmpDQkXrbrhZ0Xu/GratfNn5Q/IJuZzFT6ALN1EQYvf0xCWSQjpvE88+Yv\n+t6O\r\n=hUcw\r\n-----END PGP SIGNATURE-----\r\n",
  "signatures": [
    {
      "keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA",
      "sig": "MEQCIHSDo1CKqQFUf9X+GGs4qHwjNvc7lyOt/4Yjt53kHDU2AiA6s6YR1UVMfkuOt/94vwm60N4rmo6vLvAkeD60aJkq4Q=="
    }
  ]
}

Repository

PENDING
0confirmation/0confirmation

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 22:06 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package_version:fddc3284dbfddabebd02ca5cfa4ac5e85c3e69b6d80f371b81e688977e412dd0

Other collected versions

1.0.118 Feb1.0.018 Feb0.2.32 Jul0.2.22 Jul0.2.12 Jul0.1.1426 JunView all collected versions →