1.7.0 • Published 9 months ago

ptokens-swap v1.7.0

Weekly downloads
-
License
-
Repository
-
Last release
9 months ago

This package permits to build a pTokensSwap from a pTokensSwapBuilder instance. The created pTokensSwap object can be called with a specific method execute() to initiate the swap: the method return a PromiEvent, a particular Promise that can also emit events that can be listened.

In particular, given two pTokens Assets already build, the swap takes place as follows:

const PNETWORK_NODE = 'https://pnetwork-node-2a.eu.ngrok.io/v3'
const DESTINATION_ADDRESS: 'destination-address'

// create a pTokensNodeProvider and pTokensNode to interact with pNetwork
const provider = new pTokensNodeProvider(PNETWORK_NODE)
const node = new pTokensNode(provider)

// create swap builder
const swapBuilder = new pTokensSwapBuilder(node)

// create assets
let sourceAsset: pTokensAsset
let destinationAsset: pTokensAsset

// ...

// build the swap
swapBuilder.setSourceAsset(sourceAsset)
swapBuilder.addDestinationAsset(destinationAsset, DESTINATION_ADDRESS)
swapBuilder.setAmount(0.000001 * 10 ** 18)
const swap = swapBuilder.build()

try {
    // execute the swap and listen to events
    await swap
        .execute()
        .on('inputTxBroadcasted', (_) => console.info('inputTxBroadcasted', _))
        .on('inputTxConfirmed', (_) => console.info('inputTxConfirmed', _))
        .on('inputTxDetected', (_) => console.info('inputTxDetected', _))
        .on('outputTxDetected', (_) => console.info('outputTxDetected', _))
        .on('outputTxBroadcasted', (_) => console.info('outputTxBroadcasted', _))
        .on('outputTxConfirmed', (_) => console.info('outputTxConfirmed', _))
} catch (err) {
    console.info('err', err)
}

See the full documentation here.

1.2.0

12 months ago

1.7.0

9 months ago

1.6.0

10 months ago

1.5.0

10 months ago

1.4.0

11 months ago

1.3.0

11 months ago

1.1.0

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago