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

@moveflow/aptos-sdk

v0.0.12

Published

MoveFlow Aptos SDK

Downloads

22

Readme

moveflow-sdk-aptos

Introduction

Move-Flow is an crypto asset streaming protocol built in Move language on Aptos blockchains.

Move-Flow is able to transfer assets on chain according to predefined rules. With one transaction, funds will flow from your wallet to the recipient real-time(by second), to conduct timely financial transactions without intermediaries..

This is the Typescript SDK for the protocol.

You can find docs here

Install sdk

pnpm install @moveflow/aptos-sdk

Usage Example

Init SDK

Init Stream Object with Ed25516 Private key, this kind of stream object can execute transaction directly.

import { Stream, aptos } from "@moveflow/aptos-sdk";
const pair = new aptos.Ed25519PrivateKey(test_private_key);
const account = aptos.Account.fromPrivateKey({
  privateKey: pair,
});
const stream = new Stream(account, Network.TESTNET);

Init Stream Object with simple address, this kind of stream object can only return the prepared transaction.

const stream = new Stream(sender_address, Network.TESTNET);

Create a new payment(stream) stream

const now = Math.floor(Date.now() / 1000);
const interval = 60;

let options = new CreateStreamParams({
  execute: true,
  coin_type: "0x1::aptos_coin::AptosCoin",
  _remark: "nothing",
  name: "one test stream",
  is_fa: false,
  stream_type: StreamType.TypeStream,
  recipient: AccountAddress.from(default_to_address),
  deposit_amount: 10_000_000,
  cliff_amount: 1_000_000,
  cliff_time: now + 450,
  start_time: now + 300,
  stop_time: now + 300 + interval * 60 * 12,
  interval,
  auto_withdraw: false,
  auto_withdraw_interval: 600,
  pauseable: OperateUser.Both,
  closeable: OperateUser.Both,
  recipient_modifiable: OperateUser.Sender,
});
const sig = (await stream.createStream(options)) as TransactionResponse;
console.log(sig.hash);

await client.waitForTransaction({
  transactionHash: sig.hash,
  options: {
    checkSuccess: true,
  },
});

const execute_tx = (await client.getTransactionByHash({
  transactionHash: sig.hash,
})) as UserTransactionResponse;

assert(execute_tx.success, "transaction should be done");

If you create based common coin , you should pass with params:

is_fa:false and coin_type:"0x1::aptos_coin::AptosCoin"

And if you want to build with fa-coin should pass : is_fa:true and asset_type:"0x355efcd852a0757eb4289f25b4627f368e72bae178d719ad6f7b435c7f201e59".

Param stream_type can be used split payment stream or stream stream.

Batch Create streams(payment)

const now = Math.floor(Date.now() / 1000);
const interval = 60;

let test_batch_count = 10;

let names = [];
let recipients = [];
let deposit_amounts = [];
let cliff_amounts = [];

for (let i = 0; i < test_batch_count; i++) {
  names.push(`stream_${i}`);
  recipients.push(AccountAddress.from(`0x` + i.toString().padStart(64, "0")));
  deposit_amounts.push(10000);
  cliff_amounts.push(0);
}

const tx = (await stream.batchCreateSteam(
  new BatchCreateParams({
    execute: true,
    is_fa: true,
    asset_type:
      "0x355efcd852a0757eb4289f25b4627f368e72bae178d719ad6f7b435c7f201e59",
    _remark: "nothing",
    names,
    stream_type: StreamType.TypeStream,
    recipients,
    deposit_amounts,
    cliff_amounts,
    cliff_time: now + 450,
    start_time: now + 300,
    stop_time: now + 300 + interval * 60 * 12,
    interval,
    auto_withdraw: false,
    auto_withdraw_interval: 600,
    pauseable: OperateUser.Both,
    closeable: OperateUser.Both,
    recipient_modifiable: OperateUser.Sender,
  })
)) as PendingTransactionResponse;

await client.waitForTransaction({
  transactionHash: tx.hash,
  options: {
    checkSuccess: true,
  },
});

console.log("batch hash : ", tx.hash);

You can build as many as 200 streams in one transaction. One import tips you should know: You must set enough gas with one transaction.

Pause one stream

const sig = (await stream.pauseStream(
  new StreamOperateParams({
    stream_id:
      "0x297557e69964fd720177a5fad6f70ed1c9c6abe5a43710a68a68bedf2432a879",
    execute: true,
    is_fa: true,
  })
)) as PendingTransactionResponse;
console.log("pause transaction: ", sig.hash);
await client.waitForTransaction({
  transactionHash: sig.hash,
  options: {
    checkSuccess: true,
  },
});

Resume one stream

const sig = (await stream.resumeStream(
  new StreamOperateParams({
    stream_id:
      "0x297557e69964fd720177a5fad6f70ed1c9c6abe5a43710a68a68bedf2432a879",
    execute: true,
    is_fa: true,
  })
)) as PendingTransactionResponse;
console.log("pause transaction: ", sig.hash);
await client.waitForTransaction({
  transactionHash: sig.hash,
  options: {
    checkSuccess: true,
  },
});

Close one stream

const sig = (await stream.closeStream(
  new StreamOperateParams({
    stream_id:
      "0x297557e69964fd720177a5fad6f70ed1c9c6abe5a43710a68a68bedf2432a879",
    execute: true,
    is_fa: true,
  })
)) as PendingTransactionResponse;
console.log("pause transaction: ", sig.hash);
await client.waitForTransaction({
  transactionHash: sig.hash,
  options: {
    checkSuccess: true,
  },
});

Extend one stream

const stream_info = (await stream.fetchStream(stream_id)) as any;
console.log("current stop_time : ", stream_info.stop_time);
console.log("current interval : ", stream_info.interval);
const new_extend_time =
  Number(stream_info.stop_time) + Number(stream_info.interval) * 120;
console.log("new stop_time : ", new_extend_time);

const sig = (await stream.extendStream(
  new StreamOperateParams({
    stream_id:
      "0x8c3d8cb2e1fdc2e5db4988522b76ae5a99a910d432935d10b0fceda19e42adef",
    execute: true,
    extend_time: new_extend_time,
    coin_type: "0x1::aptos_coin::AptosCoin",
  })
)) as PendingTransactionResponse;
console.log("extend transaction: ", sig.hash);

fetch one stream info

const stream_id =
  "0x8c3d8cb2e1fdc2e5db4988522b76ae5a99a910d432935d10b0fceda19e42adef";

const stream_info = await stream.fetchStream(stream_id);
console.log(stream_info);

withdraw stream

const sig = (await stream.withdrawStream(
  new StreamOperateParams({
    stream_id:
      "0x8c3d8cb2e1fdc2e5db4988522b76ae5a99a910d432935d10b0fceda19e42adef",
    execute: true,
    coin_type: "0x1::aptos_coin::AptosCoin",
  })
)) as PendingTransactionResponse;
console.log("withdraw transaction: ", sig.hash);

await client.waitForTransaction({
  transactionHash: sig.hash,
  options: {
    checkSuccess: true,
  },
});

Batch withdraw streams

const tx = (await stream.batchWithdrawStream(
  new BatchWithdrawParams({
    is_fa: false,
    stream_ids: [
      "0xf1f5f103580f56393b5a259279c0648ef4756a5eff901ba7b66b2b94a9676f94",
    ],
    coin_type: "0x1::aptos_coin::AptosCoin",
    execute: true,
  })
)) as PendingTransactionResponse;

await client.waitForTransaction({
  transactionHash: tx.hash,
  options: {
    checkSuccess: true,
  },
});

console.log("batch withdraw tx : ", tx.hash);

Get registered coin configs

const configs = await stream.getRegisteredCoinConfigs();
console.log("configs", configs);