Skip to content

Commit

Permalink
Merge branch 'master' into btc-taproot-example
Browse files Browse the repository at this point in the history
  • Loading branch information
0xp3gasus committed Oct 3, 2024
2 parents 2e27e3f + 62eae5e commit bc10cec
Show file tree
Hide file tree
Showing 146 changed files with 3,247 additions and 636 deletions.
5 changes: 5 additions & 0 deletions .changeset/fast-months-sip.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@xchainjs/xchain-aggregator': patch
---

Add `streamingQuantity` and `streamingInterval` to allow streaming swaps
5 changes: 5 additions & 0 deletions .changeset/mean-cows-deny.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@xchainjs/xchain-aggregator': patch
---

Add arbitrum to chainflip protocol
5 changes: 5 additions & 0 deletions .changeset/polite-flowers-grow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@xchainjs/xchain-arbitrum': patch
---

Lower fee bound updated to 10000000.
5 changes: 5 additions & 0 deletions .changeset/rotten-toes-doubt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@xchainjs/xchain-cosmos': patch
---

Mintscan as explorer.
9 changes: 9 additions & 0 deletions examples/aggregator/.codesandbox/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
// These tasks will run in order when initializing your CodeSandbox project.
"setupTasks": [
{
"name": "Install Dependencies",
"command": "yarn install"
}
]
}
4 changes: 4 additions & 0 deletions examples/aggregator/.devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "Devcontainer",
"image": "ghcr.io/codesandbox/devcontainers/typescript-node:latest"
}
1 change: 1 addition & 0 deletions examples/aggregator/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# xchainjs-aggregator
32 changes: 32 additions & 0 deletions examples/aggregator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Aggregator

Aggregator examples to show different use cases

## Examples

### Swaps

#### Estimate swap

Check out how you should estimate a swap in this [example](https://github.com/xchainjs/xchainjs-lib/blob/master/examples/aggregator/swap-do.ts) or run it as

```sh
yarn estimateSwap fromAsset toAsset amount decimals
```

#### Do swap

Check out how you should do a swap between BTC and ETH in this [example](https://github.com/xchainjs/xchainjs-lib/blob/master/examples/aggregator/swap-estimate.ts) or run it as


```sh
yarn doSwap phrase amount
```

#### Get swap history

Check out how you should get the swap history of several addresses in this [example](https://github.com/xchainjs/xchainjs-lib/blob/master/examples/aggregator/swap-history.ts) or run it as

```sh
yarn swapHistory chain1:address1 chain2:address2
```
26 changes: 26 additions & 0 deletions examples/aggregator/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "xchainjs-aggregator",
"private": true,
"version": "0.0.1",
"scripts": {
"swapHistory": "npx ts-node swap-history.ts",
"estimateSwap": "npx ts-node swap-estimate.ts",
"doSwap": "npx ts-node swap-do.ts",
"build": "tsc --noEmit"
},
"description": "Examples using the Aggregator",
"main": "index.js",
"license": "MIT",
"dependencies": {
"@xchainjs/xchain-aggregator": "workspace:*",
"@xchainjs/xchain-bitcoin": "workspace:*",
"@xchainjs/xchain-ethereum": "workspace:*",
"@xchainjs/xchain-util": "workspace:*",
"@xchainjs/xchain-wallet": "workspace:*"
},
"devDependencies": {
"@types/node": "20.11.28",
"ts-node": "10.9.2",
"typescript": "^5.0.4"
}
}
33 changes: 33 additions & 0 deletions examples/aggregator/swap-do.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Aggregator } from '@xchainjs/xchain-aggregator'
import { AssetBTC, BTCChain, Client as BTCClient, defaultBTCParams } from '@xchainjs/xchain-bitcoin'
import { AssetETH, Client as ETHClient, ETHChain, defaultEthParams } from '@xchainjs/xchain-ethereum'
import { CryptoAmount, assetAmount, assetToBase } from '@xchainjs/xchain-util'
import { Wallet } from '@xchainjs/xchain-wallet'

const main = async () => {
const phrase = process.argv[2] || ''
const amount = assetToBase(assetAmount(process.argv[4], Number(process.argv[5] || 8)))

const wallet = new Wallet({
BTCChain: new BTCClient({ ...defaultBTCParams, phrase }),
ETHChain: new ETHClient({ ...defaultEthParams, phrase }),
})

const aggregator = new Aggregator({
wallet,
})

const txSubmited = await aggregator.doSwap({
fromAsset: AssetBTC,
destinationAsset: AssetETH,
fromAddress: await wallet.getAddress(BTCChain),
destinationAddress: await wallet.getAddress(ETHChain),
amount: new CryptoAmount(amount, AssetBTC),
})

console.log(txSubmited)
}

main()
.then(() => process.exit(0))
.catch((err) => console.error(err))
28 changes: 28 additions & 0 deletions examples/aggregator/swap-estimate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Aggregator } from '@xchainjs/xchain-aggregator'
import { CryptoAmount, assetAmount, assetFromStringEx, assetToBase } from '@xchainjs/xchain-util'

const main = async () => {
const fromAsset = assetFromStringEx(process.argv[2] || '')
const toAsset = assetFromStringEx(process.argv[3] || '')
const amount = assetToBase(assetAmount(process.argv[4], Number(process.argv[5] || 8)))

const aggregator = new Aggregator()

const quote = await aggregator.estimateSwap({
fromAsset,
destinationAsset: toAsset,
amount: new CryptoAmount(amount, fromAsset),
})

console.log({
canSwap: quote.canSwap,
protocol: quote.protocol,
expectedAmount: quote.expectedAmount.assetAmount.amount().toString(),
memo: quote.memo,
toAddress: quote.toAddress,
})
}

main()
.then(() => process.exit(0))
.catch((err) => console.error(err))
39 changes: 39 additions & 0 deletions examples/aggregator/swap-history.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { Aggregator } from '@xchainjs/xchain-aggregator'
import { assetToString } from '@xchainjs/xchain-util'

const main = async () => {
const chainAddress1 = process.argv[2] || ''
const chainAddress2 = process.argv[3] || ''

const aggregator = new Aggregator()

const swaps = await aggregator.getSwapHistory({
chainAddresses: [
{
chain: chainAddress1.split(':')[0],
address: chainAddress1.split(':')[1],
},
{
chain: chainAddress2.split(':')[0],
address: chainAddress2.split(':')[1],
},
],
})

console.table(
swaps.swaps.map((swap) => {
return {
protocol: swap.protocol,
fromAsset: assetToString(swap.inboundTx.amount.asset),
toAsset: swap.status === 'success' ? assetToString(swap.outboundTx.amount.asset) : undefined,
hash: swap.inboundTx.hash,
fromAmount: swap.inboundTx.amount.assetAmount.amount().toString(),
toAmount: swap.status === 'success' ? swap.outboundTx.amount.assetAmount.amount().toString() : undefined,
}
}),
)
}

main()
.then(() => process.exit(0))
.catch((err) => console.error(err))
15 changes: 15 additions & 0 deletions examples/aggregator/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"noEmitOnError": true,
"resolveJsonModule": true,
"esModuleInterop": true,
"lib": [
"es6",
"dom",
"es2016",
"es2017"
]
}
}
2 changes: 1 addition & 1 deletion examples/bitcoin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@
"ts-node": "10.9.2",
"typescript": "^5.0.4"
}
}
}
25 changes: 25 additions & 0 deletions examples/check-tx/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
# xchainjs-check-tx

## 1.0.17

### Patch Changes

- Updated dependencies [cf78958]
- Updated dependencies [33bfa40]
- @xchainjs/xchain-thorchain-query@1.0.6
- @xchainjs/xchain-midgard-query@1.0.6
- @xchainjs/xchain-thornode@0.3.20
- @xchainjs/xchain-midgard@0.5.10
- @xchainjs/xchain-client@1.0.6
- @xchainjs/xchain-crypto@0.3.5
- @xchainjs/xchain-util@1.0.5

## 1.0.16

### Patch Changes

- Updated dependencies [73b68ed]
- Updated dependencies [73b68ed]
- @xchainjs/xchain-thorchain-query@1.0.5
- @xchainjs/xchain-util@1.0.4
- @xchainjs/xchain-client@1.0.5
- @xchainjs/xchain-midgard-query@1.0.5

## 1.0.15

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion examples/check-tx/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "xchainjs-check-tx",
"private": true,
"version": "1.0.15",
"version": "1.0.17",
"scripts": {
"checktx": "npx ts-node check-tx.ts",
"build": "tsc --noEmit"
Expand Down
61 changes: 61 additions & 0 deletions examples/do-swap/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,66 @@
# xchainjs-do-swap

## 1.0.32

### Patch Changes

- Updated dependencies [cf78958]
- Updated dependencies [33bfa40]
- @xchainjs/xchain-thorchain-query@1.0.6
- @xchainjs/xchain-utxo-providers@1.0.6
- @xchainjs/xchain-evm-providers@1.0.8
- @xchainjs/xchain-midgard-query@1.0.6
- @xchainjs/xchain-thorchain-amm@2.0.12
- @xchainjs/xchain-bitcoincash@1.0.6
- @xchainjs/xchain-cosmos-sdk@1.0.7
- @xchainjs/xchain-thorchain@2.0.8
- @xchainjs/xchain-ethereum@1.0.10
- @xchainjs/xchain-litecoin@1.0.6
- @xchainjs/xchain-thornode@0.3.20
- @xchainjs/xchain-binance@6.0.6
- @xchainjs/xchain-bitcoin@1.1.2
- @xchainjs/xchain-midgard@0.5.10
- @xchainjs/xchain-client@1.0.6
- @xchainjs/xchain-cosmos@2.0.7
- @xchainjs/xchain-crypto@0.3.5
- @xchainjs/xchain-wallet@1.0.12
- @xchainjs/xchain-avax@1.0.10
- @xchainjs/xchain-dash@1.0.6
- @xchainjs/xchain-doge@1.0.6
- @xchainjs/xchain-util@1.0.5
- @xchainjs/xchain-utxo@1.0.6
- @xchainjs/xchain-bsc@1.0.10
- @xchainjs/xchain-evm@1.0.10

## 1.0.31

### Patch Changes

- Updated dependencies [73b68ed]
- Updated dependencies [73b68ed]
- @xchainjs/xchain-thorchain-query@1.0.5
- @xchainjs/xchain-util@1.0.4
- @xchainjs/xchain-thorchain-amm@2.0.11
- @xchainjs/xchain-avax@1.0.9
- @xchainjs/xchain-binance@6.0.5
- @xchainjs/xchain-bitcoin@1.1.1
- @xchainjs/xchain-bitcoincash@1.0.5
- @xchainjs/xchain-bsc@1.0.9
- @xchainjs/xchain-client@1.0.5
- @xchainjs/xchain-cosmos@2.0.6
- @xchainjs/xchain-cosmos-sdk@1.0.6
- @xchainjs/xchain-dash@1.0.5
- @xchainjs/xchain-doge@1.0.5
- @xchainjs/xchain-ethereum@1.0.9
- @xchainjs/xchain-evm@1.0.9
- @xchainjs/xchain-evm-providers@1.0.7
- @xchainjs/xchain-litecoin@1.0.5
- @xchainjs/xchain-midgard-query@1.0.5
- @xchainjs/xchain-thorchain@2.0.7
- @xchainjs/xchain-utxo@1.0.5
- @xchainjs/xchain-utxo-providers@1.0.5
- @xchainjs/xchain-wallet@1.0.11

## 1.0.30

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion examples/do-swap/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "xchainjs-do-swap",
"private": true,
"version": "1.0.30",
"version": "1.0.32",
"scripts": {
"doSwap": "npx ts-node doSwap.ts",
"doStreamingSwap": "npx ts-node doStreamingSwap.ts",
Expand Down
25 changes: 25 additions & 0 deletions examples/estimate-swap/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
# xchainjs-estimate-swap

## 1.0.17

### Patch Changes

- Updated dependencies [cf78958]
- Updated dependencies [33bfa40]
- @xchainjs/xchain-thorchain-query@1.0.6
- @xchainjs/xchain-midgard-query@1.0.6
- @xchainjs/xchain-thornode@0.3.20
- @xchainjs/xchain-midgard@0.5.10
- @xchainjs/xchain-client@1.0.6
- @xchainjs/xchain-crypto@0.3.5
- @xchainjs/xchain-util@1.0.5

## 1.0.16

### Patch Changes

- Updated dependencies [73b68ed]
- Updated dependencies [73b68ed]
- @xchainjs/xchain-thorchain-query@1.0.5
- @xchainjs/xchain-util@1.0.4
- @xchainjs/xchain-client@1.0.5
- @xchainjs/xchain-midgard-query@1.0.5

## 1.0.15

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion examples/estimate-swap/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "xchainjs-estimate-swap",
"private": true,
"version": "1.0.15",
"version": "1.0.17",
"scripts": {
"listPools": "npx ts-node listPools.ts",
"estimateSwap": "npx ts-node estimateSwap.ts",
Expand Down
Loading

0 comments on commit bc10cec

Please sign in to comment.