@xchainjs/xchain-thorchain-amm 0.1.0-alpha2 → 0.1.0-beta3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +46 -82
- package/lib/index.d.ts +3 -0
- package/lib/index.esm.js +208 -1143
- package/lib/index.js +205 -1149
- package/lib/thorchain-amm.d.ts +35 -0
- package/lib/types.d.ts +44 -0
- package/lib/utils/eth-helper.d.ts +25 -0
- package/lib/utils/evm-helper.d.ts +25 -0
- package/lib/wallet.d.ts +44 -0
- package/package.json +31 -25
- package/lib/xchain-thorchain-amm/src/chain-defaults.d.ts +0 -4
- package/lib/xchain-thorchain-amm/src/crypto-amount.d.ts +0 -37
- package/lib/xchain-thorchain-amm/src/index.d.ts +0 -6
- package/lib/xchain-thorchain-amm/src/liquidity-pool-cache.d.ts +0 -73
- package/lib/xchain-thorchain-amm/src/liquidity-pool.d.ts +0 -17
- package/lib/xchain-thorchain-amm/src/thorchain-amm.d.ts +0 -115
- package/lib/xchain-thorchain-amm/src/types.d.ts +0 -90
- package/lib/xchain-thorchain-amm/src/utils/index.d.ts +0 -3
- package/lib/xchain-thorchain-amm/src/utils/liquidity.d.ts +0 -33
- package/lib/xchain-thorchain-amm/src/utils/midgard.d.ts +0 -50
- package/lib/xchain-thorchain-amm/src/utils/swap.d.ts +0 -68
- package/lib/xchain-thorchain-amm/src/utils/thornode.d.ts +0 -66
- package/lib/xchain-thorchain-amm/src/wallet.d.ts +0 -63
package/README.md
CHANGED
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
|
|
5
5
|
Thorchain AMM module
|
|
6
6
|
|
|
7
|
-
|
|
8
7
|
## Installation
|
|
9
8
|
|
|
10
9
|
```
|
|
@@ -13,94 +12,59 @@ yarn add @xchainjs/xchain-thorchain-amm
|
|
|
13
12
|
|
|
14
13
|
Following peer dependencies have to be installed into your project. These are not included in `@xchainjs/xchain-thorchain-amm`.
|
|
15
14
|
|
|
15
|
+
```bash
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@binance-chain/javascript-sdk": "^4.2.0",
|
|
18
|
+
"@cosmos-client/core": "^0.45.1",
|
|
19
|
+
"@psf/bitcoincashjs-lib": "^4.0.2",
|
|
20
|
+
"@terra-money/terra.js": "^3.1.4",
|
|
21
|
+
"@xchainjs/xchain-binance": "^5.5.0",
|
|
22
|
+
"@xchainjs/xchain-bitcoin": "^0.19.0",
|
|
23
|
+
"@xchainjs/xchain-bitcoincash": "^0.14.0",
|
|
24
|
+
"@xchainjs/xchain-client": "^0.12.0",
|
|
25
|
+
"@xchainjs/xchain-cosmos": "^0.19.0",
|
|
26
|
+
"@xchainjs/xchain-crypto": "^0.2.6",
|
|
27
|
+
"@xchainjs/xchain-doge": "^0.3.0",
|
|
28
|
+
"@xchainjs/xchain-ethereum": "^0.26.0",
|
|
29
|
+
"@xchainjs/xchain-litecoin": "^0.9.0",
|
|
30
|
+
"@xchainjs/xchain-midgard": "^0.1.0-alpha2",
|
|
31
|
+
"@xchainjs/xchain-terra": "^0.2.0",
|
|
32
|
+
"@xchainjs/xchain-thorchain": "^0.25.3",
|
|
33
|
+
"@xchainjs/xchain-thornode": "^0.1.0-alpha3",
|
|
34
|
+
"@xchainjs/xchain-util": "^0.8.0",
|
|
35
|
+
"axios": "^0.27.2",
|
|
36
|
+
"axios-retry": "^3.3.1",
|
|
37
|
+
"bchaddrjs": "^0.5.2",
|
|
38
|
+
"bech32-buffer": "^0.2.0",
|
|
39
|
+
"bitcoinjs-lib": "^6.0.1",
|
|
40
|
+
"dotenv": "^16.0.0",
|
|
41
|
+
"ethers": "^5.6.2"
|
|
42
|
+
}
|
|
43
|
+
|
|
16
44
|
```
|
|
17
|
-
|
|
18
|
-
```
|
|
45
|
+
## Examples
|
|
19
46
|
|
|
20
|
-
## Usage
|
|
21
47
|
|
|
22
|
-
### Estimating a swap from BTC -> BUSD
|
|
23
48
|
|
|
24
|
-
|
|
25
|
-
import { Network } from '@xchainjs/xchain-client'
|
|
26
|
-
import { AssetBTC, assetAmount, assetFromString, assetToBase } from '@xchainjs/xchain-util'
|
|
27
|
-
import BigNumber from 'bignumber.js'
|
|
49
|
+
## Documentation
|
|
28
50
|
|
|
29
|
-
|
|
51
|
+
[xchain thorchain-amm](http://docs.xchainjs.org/xchain-thorchain-amm/)
|
|
52
|
+
[How thorchain-amm works](http://docs.xchainjs.org/xchain-thorchain-amm/how-it-works.html)\
|
|
53
|
+
[How to use thorchain-amm](http://docs.xchainjs.org/xchain-thorchain-amm/how-to-use.html)
|
|
30
54
|
|
|
31
|
-
|
|
32
|
-
if (!BUSD) throw Error('bad asset')
|
|
55
|
+
##
|
|
33
56
|
|
|
34
|
-
|
|
35
|
-
const expanded = {
|
|
36
|
-
input: input.formatedAssetString(),
|
|
37
|
-
totalFees: {
|
|
38
|
-
inboundFee: estimate.totalFees.inboundFee.formatedAssetString(),
|
|
39
|
-
swapFee: estimate.totalFees.swapFee.formatedAssetString(),
|
|
40
|
-
outboundFee: estimate.totalFees.outboundFee.formatedAssetString(),
|
|
41
|
-
affiliateFee: estimate.totalFees.affiliateFee.formatedAssetString(),
|
|
42
|
-
},
|
|
43
|
-
slipPercentage: estimate.slipPercentage.toFixed(),
|
|
44
|
-
netOutput: estimate.netOutput.formatedAssetString(),
|
|
45
|
-
waitTimeSeconds: estimate.waitTimeSeconds.toFixed(),
|
|
46
|
-
canSwap: estimate.canSwap,
|
|
47
|
-
errors: estimate.errors,
|
|
48
|
-
}
|
|
49
|
-
console.log(expanded)
|
|
50
|
-
}
|
|
51
|
-
try {
|
|
52
|
-
const midgard = new Midgard(Network.Mainnet) //defaults to mainnet
|
|
53
|
-
const thorchainAmm = new ThorchainAMM(midgard)
|
|
54
|
-
const swapParams: EstimateSwapParams = {
|
|
55
|
-
input: new CryptoAmount(assetToBase(assetAmount('1')), AssetBTC),
|
|
56
|
-
destinationAsset: BUSD,
|
|
57
|
-
// affiliateFeePercent: 0.003, //optional
|
|
58
|
-
slipLimit: new BigNumber('0.03'), //optional
|
|
59
|
-
}
|
|
60
|
-
const estimate = await thorchainAmm.estimateSwap(swapParams)
|
|
61
|
-
print(estimate, swapParams.input)
|
|
57
|
+
tsconfig compiler options
|
|
62
58
|
|
|
63
|
-
|
|
64
|
-
const estimateInBusd = await thorchainAmm.getFeesIn(estimate.totalFees, BUSD)
|
|
65
|
-
estimate.totalFees = estimateInBusd
|
|
66
|
-
print(estimate, swapParams.input)
|
|
67
|
-
} catch (e) {
|
|
68
|
-
console.error(e)
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
## output
|
|
74
|
-
|
|
75
|
-
```
|
|
76
|
-
===Estimate with fees in Rune===
|
|
77
|
-
{
|
|
78
|
-
input: '₿ 1',
|
|
79
|
-
totalFees: {
|
|
80
|
-
inboundFee: 'ᚱ 0.02165694',
|
|
81
|
-
swapFee: 'ᚱ 69.57707207',
|
|
82
|
-
outboundFee: 'ᚱ 0.03235451',
|
|
83
|
-
affiliateFee: 'ᚱ 0'
|
|
84
|
-
},
|
|
85
|
-
slipPercentage: '0.00299630164689824336',
|
|
86
|
-
netOutput: '$ 23,151.33630401',
|
|
87
|
-
waitTimeSeconds: '1116',
|
|
88
|
-
canSwap: true,
|
|
89
|
-
errors: undefined
|
|
90
|
-
}
|
|
91
|
-
===Estimate with fees in BUSD===
|
|
59
|
+
```ts
|
|
92
60
|
{
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
netOutput: '$ 23,151.33630401',
|
|
102
|
-
waitTimeSeconds: '1116',
|
|
103
|
-
canSwap: true,
|
|
104
|
-
errors: undefined
|
|
61
|
+
"compilerOptions": {
|
|
62
|
+
"module":"commonjs",
|
|
63
|
+
"target": "es5",
|
|
64
|
+
"noEmitOnError": true,
|
|
65
|
+
"resolveJsonModule": true,
|
|
66
|
+
"esModuleInterop": true,
|
|
67
|
+
"lib": ["es6", "dom", "es2016", "es2017"]
|
|
68
|
+
}
|
|
105
69
|
}
|
|
106
|
-
```
|
|
70
|
+
```
|
package/lib/index.d.ts
ADDED