Skip to content

Commit

Permalink
Update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
hippocampus-web3 committed Sep 24, 2023
1 parent 0a1af5d commit 34f8f0e
Show file tree
Hide file tree
Showing 23 changed files with 66 additions and 63 deletions.
6 changes: 4 additions & 2 deletions examples/check-tx/check-tx.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { Network } from '@xchainjs/xchain-client'
import { Midgard, ThorchainCache, Thornode, TransactionStage } from '@xchainjs/xchain-thorchain-query'
import { Midgard, MidgardCache, MidgardQuery } from '@xchainjs/xchain-midgard-query'
import { ThorchainCache, Thornode, TransactionStage } from '@xchainjs/xchain-thorchain-query'

//function printTx(inboundTxHash: string, source: string) {}

export const checkTx = async (network: Network, inboundHash: string) => {
const thorchainCache = new ThorchainCache(new Midgard(network), new Thornode(network))
const midgardCache = new MidgardCache(new Midgard(network))
const thorchainCache = new ThorchainCache(new Thornode(network), new MidgardQuery(midgardCache))
const transactionStage = new TransactionStage(thorchainCache)
const checkTransaction = await transactionStage.checkTxProgress(inboundHash)
console.log(`\ Checking on ${network} :)\n`)
Expand Down
1 change: 1 addition & 0 deletions examples/check-tx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"license": "MIT",
"dependencies": {
"@xchainjs/xchain-thorchain-query": "file:../../packages/xchain-thorchain-query",
"@xchainjs/xchain-midgard-query": "file:../../packages/xchain-midgard-query",
"@xchainjs/xchain-client": "file:../../packages/xchain-client",
"@xchainjs/xchain-midgard": "file:../../packages/xchain-midgard",
"@xchainjs/xchain-thornode": "file:../../packages/xchain-thornode",
Expand Down
6 changes: 4 additions & 2 deletions examples/do-swap/doSend.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Network } from '@xchainjs/xchain-client'
import { Midgard, MidgardCache, MidgardQuery } from '@xchainjs/xchain-midgard-query'
import { THORChain } from '@xchainjs/xchain-thorchain'
import { Wallet } from '@xchainjs/xchain-thorchain-amm'
import { Midgard, ThorchainCache, ThorchainQuery, Thornode } from '@xchainjs/xchain-thorchain-query'
import { ThorchainCache, ThorchainQuery, Thornode } from '@xchainjs/xchain-thorchain-query'
import { assetAmount, assetFromString, assetToBase } from '@xchainjs/xchain-util'

/**
Expand All @@ -28,7 +29,8 @@ const doSend = async (wallet: Wallet) => {
const main = async () => {
const seed = process.argv[2]
const network = process.argv[3] as Network
const thorchainCache = new ThorchainCache(new Midgard(network), new Thornode(network))
const midgardCache = new MidgardCache(new Midgard(network))
const thorchainCache = new ThorchainCache(new Thornode(network), new MidgardQuery(midgardCache))
const thorchainQuery = new ThorchainQuery(thorchainCache)
const wallet = new Wallet(seed, thorchainQuery)
console.log(`\ Send on ${network} :)\n`)
Expand Down
13 changes: 4 additions & 9 deletions examples/do-swap/doStreamingSwap.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
import { Network } from '@xchainjs/xchain-client'
import { Midgard, MidgardCache, MidgardQuery } from '@xchainjs/xchain-midgard-query'
import { THORChain } from '@xchainjs/xchain-thorchain'
import { AmmEstimateSwapParams, ThorchainAMM, Wallet } from '@xchainjs/xchain-thorchain-amm'
import {
CryptoAmount,
Midgard,
ThorchainCache,
ThorchainQuery,
Thornode,
TxDetails,
} from '@xchainjs/xchain-thorchain-query'
import { CryptoAmount, ThorchainCache, ThorchainQuery, Thornode, TxDetails } from '@xchainjs/xchain-thorchain-query'
import { assetAmount, assetFromString, assetToBase, assetToString, delay } from '@xchainjs/xchain-util'

import { checkTx } from '../check-tx/check-tx'
Expand Down Expand Up @@ -112,7 +106,8 @@ const doStreamingSwap = async (tcAmm: ThorchainAMM, wallet: Wallet, network: Net
const main = async () => {
const seed = process.argv[2]
const network = process.argv[3] as Network
const thorchainCache = new ThorchainCache(new Midgard(network), new Thornode(network))
const midgardCache = new MidgardCache(new Midgard(network))
const thorchainCache = new ThorchainCache(new Thornode(network), new MidgardQuery(midgardCache))
const thorchainQuery = new ThorchainQuery(thorchainCache)
const thorchainAmm = new ThorchainAMM(thorchainQuery)
const wallet = new Wallet(seed, thorchainQuery)
Expand Down
13 changes: 4 additions & 9 deletions examples/do-swap/doSwap.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
import { Network } from '@xchainjs/xchain-client'
import { Midgard, MidgardCache, MidgardQuery } from '@xchainjs/xchain-midgard-query'
import { THORChain } from '@xchainjs/xchain-thorchain'
import { AmmEstimateSwapParams, ThorchainAMM, Wallet } from '@xchainjs/xchain-thorchain-amm'
import {
CryptoAmount,
Midgard,
ThorchainCache,
ThorchainQuery,
Thornode,
TxDetails,
} from '@xchainjs/xchain-thorchain-query'
import { CryptoAmount, ThorchainCache, ThorchainQuery, Thornode, TxDetails } from '@xchainjs/xchain-thorchain-query'
import { assetAmount, assetFromString, assetToBase, assetToString, delay } from '@xchainjs/xchain-util'

import { checkTx } from '../check-tx/check-tx'
Expand Down Expand Up @@ -111,7 +105,8 @@ const doSingleSwap = async (tcAmm: ThorchainAMM, wallet: Wallet, network: Networ
const main = async () => {
const seed = process.argv[2]
const network = process.argv[3] as Network
const thorchainCache = new ThorchainCache(new Midgard(network), new Thornode(network))
const midgardCache = new MidgardCache(new Midgard(network))
const thorchainCache = new ThorchainCache(new Thornode(network), new MidgardQuery(midgardCache))
const thorchainQuery = new ThorchainQuery(thorchainCache)
const thorchainAmm = new ThorchainAMM(thorchainQuery)
const wallet = new Wallet(seed, thorchainQuery)
Expand Down
1 change: 1 addition & 0 deletions examples/do-swap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"@xchainjs/xchain-util": "file:../../packages/xchain-util",
"@xchainjs/xchain-avax": "file:../../packages/xchain-avax",
"@xchainjs/xchain-thorchain-query": "file:../../packages/xchain-thorchain-query",
"@xchainjs/xchain-midgard-query": "file:../../packages/xchain-midgard-query",
"axios-retry": "^3.3.1",
"bchaddrjs": "^0.5.2",
"bech32-buffer": "^0.2.0",
Expand Down
5 changes: 3 additions & 2 deletions examples/estimate-swap/estimateSwap.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Network } from '@xchainjs/xchain-client'
import { Midgard, MidgardCache, MidgardQuery } from '@xchainjs/xchain-midgard-query'
import {
CryptoAmount,
Midgard,
QuoteSwapParams,
SwapEstimate,
ThorchainCache,
Expand Down Expand Up @@ -53,7 +53,8 @@ const estimateSwap = async () => {
const toAsset = assetFromString(`${process.argv[6]}`)
const toDestinationAddress = `${process.argv[7]}`
const fromAddress = `${process.argv[8]}`
const thorchainCache = new ThorchainCache(new Midgard(network), new Thornode(network))
const midgardCache = new MidgardCache(new Midgard(network))
const thorchainCache = new ThorchainCache(new Thornode(network), new MidgardQuery(midgardCache))
const thorchainQuery = new ThorchainQuery(thorchainCache)
let swapParams: QuoteSwapParams

Expand Down
2 changes: 1 addition & 1 deletion examples/estimate-swap/listPools.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Network } from '@xchainjs/xchain-client'
import { Midgard } from '@xchainjs/xchain-thorchain-query'
import { Midgard } from '@xchainjs/xchain-midgard-query'

const main = async () => {
const network = process.argv[2] as Network
Expand Down
1 change: 1 addition & 0 deletions examples/estimate-swap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"license": "MIT",
"dependencies": {
"@xchainjs/xchain-thorchain-query": "file:../../packages/xchain-thorchain-query",
"@xchainjs/xchain-midgard-query": "file:../../packages/xchain-midgard-query",
"@xchainjs/xchain-client": "file:../../packages/xchain-client",
"@xchainjs/xchain-midgard": "file:../../packages/xchain-midgard",
"@xchainjs/xchain-thornode": "file:../../packages/xchain-thornode",
Expand Down
5 changes: 3 additions & 2 deletions examples/liquidity/add-liquidity.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Network } from '@xchainjs/xchain-client'
import { Midgard, MidgardCache, MidgardQuery } from '@xchainjs/xchain-midgard-query'
import { isAssetRuneNative } from '@xchainjs/xchain-thorchain'
import { ThorchainAMM, Wallet } from '@xchainjs/xchain-thorchain-amm'
import {
AddliquidityPosition,
CryptoAmount,
Midgard,
ThorchainCache,
ThorchainQuery,
Thornode,
Expand Down Expand Up @@ -41,7 +41,8 @@ const addLp = async (tcAmm: ThorchainAMM, wallet: Wallet) => {
const main = async () => {
const seed = process.argv[2]
const network = process.argv[3] as Network
const thorchainCache = new ThorchainCache(new Midgard(network), new Thornode(network))
const midgardCache = new MidgardCache(new Midgard(network))
const thorchainCache = new ThorchainCache(new Thornode(network), new MidgardQuery(midgardCache))
const thorchainQuery = new ThorchainQuery(thorchainCache)
const thorchainAmm = new ThorchainAMM(thorchainQuery)
const wallet = new Wallet(seed, thorchainQuery)
Expand Down
6 changes: 4 additions & 2 deletions examples/liquidity/add-savers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Network } from '@xchainjs/xchain-client'
import { Midgard, MidgardCache, MidgardQuery } from '@xchainjs/xchain-midgard-query'
import { ThorchainAMM, Wallet } from '@xchainjs/xchain-thorchain-amm'
import { CryptoAmount, Midgard, ThorchainCache, ThorchainQuery, Thornode } from '@xchainjs/xchain-thorchain-query'
import { CryptoAmount, ThorchainCache, ThorchainQuery, Thornode } from '@xchainjs/xchain-thorchain-query'
import { assetAmount, assetFromStringEx, assetToBase } from '@xchainjs/xchain-util'

/**
Expand All @@ -24,7 +25,8 @@ const addSavers = async (tcAmm: ThorchainAMM, wallet: Wallet) => {
const main = async () => {
const seed = process.argv[2]
const network = process.argv[3] as Network
const thorchainCache = new ThorchainCache(new Midgard(network), new Thornode(network))
const midgardCache = new MidgardCache(new Midgard(network))
const thorchainCache = new ThorchainCache(new Thornode(network), new MidgardQuery(midgardCache))
const thorchainQuery = new ThorchainQuery(thorchainCache)
const thorchainAmm = new ThorchainAMM(thorchainQuery)
const wallet = new Wallet(seed, thorchainQuery)
Expand Down
6 changes: 4 additions & 2 deletions examples/liquidity/check-liquidity.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Network } from '@xchainjs/xchain-client'
import { LiquidityPosition, Midgard, ThorchainCache, ThorchainQuery, Thornode } from '@xchainjs/xchain-thorchain-query'
import { Midgard, MidgardCache, MidgardQuery } from '@xchainjs/xchain-midgard-query'
import { LiquidityPosition, ThorchainCache, ThorchainQuery, Thornode } from '@xchainjs/xchain-thorchain-query'
import { assetFromString } from '@xchainjs/xchain-util'

function print(estimate: LiquidityPosition, address: string) {
Expand All @@ -24,7 +25,8 @@ function print(estimate: LiquidityPosition, address: string) {
const checkLiquidityPosition = async () => {
try {
const network = process.argv[2] as Network
const thorchainCacheMainnet = new ThorchainCache(new Midgard(network), new Thornode(network))
const midgardCache = new MidgardCache(new Midgard(network))
const thorchainCacheMainnet = new ThorchainCache(new Thornode(network), new MidgardQuery(midgardCache))
const thorchainQueryMainnet = new ThorchainQuery(thorchainCacheMainnet)

const asset = assetFromString(process.argv[3])
Expand Down
13 changes: 4 additions & 9 deletions examples/liquidity/check-saver-position.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import { Network } from '@xchainjs/xchain-client'
import {
Midgard,
SaversPosition,
ThorchainCache,
ThorchainQuery,
Thornode,
getSaver,
} from '@xchainjs/xchain-thorchain-query'
import { Midgard, MidgardCache, MidgardQuery } from '@xchainjs/xchain-midgard-query'
import { SaversPosition, ThorchainCache, ThorchainQuery, Thornode, getSaver } from '@xchainjs/xchain-thorchain-query'
import { assetFromString } from '@xchainjs/xchain-util'

function printSaversPosition(saver: SaversPosition) {
Expand All @@ -26,7 +20,8 @@ function printSaversPosition(saver: SaversPosition) {
const getSaverPosition = async () => {
try {
const network = process.argv[2] as Network
const thorchainCacheMainnet = new ThorchainCache(new Midgard(network), new Thornode(network))
const midgardCache = new MidgardCache(new Midgard(network))
const thorchainCacheMainnet = new ThorchainCache(new Thornode(network), new MidgardQuery(midgardCache))
const thorchainQueryMainnet = new ThorchainQuery(thorchainCacheMainnet)
const getSaver: getSaver = {
asset: assetFromString(process.argv[4]),
Expand Down
5 changes: 3 additions & 2 deletions examples/liquidity/estimate-add-liquidity.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Network } from '@xchainjs/xchain-client'
import { Midgard, MidgardCache, MidgardQuery } from '@xchainjs/xchain-midgard-query'
import { isAssetRuneNative } from '@xchainjs/xchain-thorchain'
import {
AddliquidityPosition,
CryptoAmount,
EstimateAddLP,
Midgard,
ThorchainCache,
ThorchainQuery,
Thornode,
Expand Down Expand Up @@ -36,7 +36,8 @@ function print(estimate: EstimateAddLP, rune: CryptoAmount, asset: CryptoAmount)
const estimateAddLp = async () => {
try {
const network = process.argv[2] as Network
const thorchainCacheMainnet = new ThorchainCache(new Midgard(network), new Thornode(network))
const midgardCache = new MidgardCache(new Midgard(network))
const thorchainCacheMainnet = new ThorchainCache(new Thornode(network), new MidgardQuery(midgardCache))
const thorchainQueryMainnet = new ThorchainQuery(thorchainCacheMainnet)

// TODO check if synth?
Expand Down
5 changes: 3 additions & 2 deletions examples/liquidity/estimate-add-saver.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Network } from '@xchainjs/xchain-client'
import { Midgard, MidgardCache, MidgardQuery } from '@xchainjs/xchain-midgard-query'
import {
CryptoAmount,
EstimateAddSaver,
Midgard,
ThorchainCache,
ThorchainQuery,
Thornode,
Expand Down Expand Up @@ -37,7 +37,8 @@ function printSaver(saver: EstimateAddSaver) {
const estimateAddSaver = async () => {
try {
const network = process.argv[2] as Network
const thorchainCacheMainnet = new ThorchainCache(new Midgard(network), new Thornode(network))
const midgardCache = new MidgardCache(new Midgard(network))
const thorchainCacheMainnet = new ThorchainCache(new Thornode(network), new MidgardQuery(midgardCache))
const thorchainQueryMainnet = new ThorchainQuery(thorchainCacheMainnet)

const asset = new CryptoAmount(
Expand Down
5 changes: 3 additions & 2 deletions examples/liquidity/estimate-remove-liquidity.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Network } from '@xchainjs/xchain-client'
import { Midgard, MidgardCache, MidgardQuery } from '@xchainjs/xchain-midgard-query'
import {
EstimateWithdrawLP,
Midgard,
ThorchainCache,
ThorchainQuery,
Thornode,
Expand Down Expand Up @@ -35,7 +35,8 @@ function print(estimate: EstimateWithdrawLP, withdrawLpParams: WithdrawLiquidity
const estimateWithdrawLp = async () => {
try {
const network = process.argv[2] as Network
const thorchainCacheMainnet = new ThorchainCache(new Midgard(network), new Thornode(network))
const midgardCache = new MidgardCache(new Midgard(network))
const thorchainCacheMainnet = new ThorchainCache(new Thornode(network), new MidgardQuery(midgardCache))
const thorchainQueryMainnet = new ThorchainQuery(thorchainCacheMainnet)

const asset = assetFromString(process.argv[3])
Expand Down
6 changes: 3 additions & 3 deletions examples/liquidity/estimate-withdraw-saver.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Network } from '@xchainjs/xchain-client'
import { Midgard, MidgardCache, MidgardQuery } from '@xchainjs/xchain-midgard-query'
import {
EstimateWithdrawSaver,
Midgard,
SaversWithdraw,
ThorchainCache,
ThorchainQuery,
Expand All @@ -20,7 +20,6 @@ function printWithdrawSaver(saver: EstimateWithdrawSaver) {
expiry: saver.expiry,
toAddress: saver.toAddress,
memo: saver.memo,
estimateWaitTime: saver.estimatedWaitTime,
slipBasisPoints: saver.slipBasisPoints,
}
console.log(expanded)
Expand All @@ -33,7 +32,8 @@ function printWithdrawSaver(saver: EstimateWithdrawSaver) {
const estimateWithdrawSaver = async () => {
try {
const network = process.argv[2] as Network
const thorchainCacheMainnet = new ThorchainCache(new Midgard(network), new Thornode(network))
const midgardCache = new MidgardCache(new Midgard(network))
const thorchainCacheMainnet = new ThorchainCache(new Thornode(network), new MidgardQuery(midgardCache))
const thorchainQueryMainnet = new ThorchainQuery(thorchainCacheMainnet)
const asset = assetFromStringEx(process.argv[4])
const withdrawPos: SaversWithdraw = {
Expand Down
1 change: 1 addition & 0 deletions examples/liquidity/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"dependencies": {
"@xchainjs/xchain-thorchain-amm": "file:../../packages/xchain-thorchain-amm",
"@xchainjs/xchain-thorchain-query": "file:../../packages/xchain-thorchain-query",
"@xchainjs/xchain-midgard-query": "file:../../packages/xchain-midgard-query",
"@xchainjs/xchain-client": "file:../../packages/xchain-client",
"@xchainjs/xchain-midgard": "file:../../packages/xchain-midgard",
"@xchainjs/xchain-thornode": "file:../../packages/xchain-thornode",
Expand Down
12 changes: 4 additions & 8 deletions examples/liquidity/withdraw-liquidity.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import { Network } from '@xchainjs/xchain-client'
import { Midgard, MidgardCache, MidgardQuery } from '@xchainjs/xchain-midgard-query'
import { ThorchainAMM, Wallet } from '@xchainjs/xchain-thorchain-amm'
import {
Midgard,
ThorchainCache,
ThorchainQuery,
Thornode,
WithdrawLiquidityPosition,
} from '@xchainjs/xchain-thorchain-query'
import { ThorchainCache, ThorchainQuery, Thornode, WithdrawLiquidityPosition } from '@xchainjs/xchain-thorchain-query'
import { assetFromString } from '@xchainjs/xchain-util'

/**
Expand Down Expand Up @@ -37,7 +32,8 @@ const withdrawLp = async (tcAmm: ThorchainAMM, wallet: Wallet) => {
const main = async () => {
const seed = process.argv[2]
const network = process.argv[3] as Network
const thorchainCache = new ThorchainCache(new Midgard(network), new Thornode(network))
const midgardCache = new MidgardCache(new Midgard(network))
const thorchainCache = new ThorchainCache(new Thornode(network), new MidgardQuery(midgardCache))
const thorchainQuery = new ThorchainQuery(thorchainCache)
const thorchainAmm = new ThorchainAMM(thorchainQuery)
const wallet = new Wallet(seed, thorchainQuery)
Expand Down
6 changes: 4 additions & 2 deletions examples/liquidity/withdrawSavers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Network } from '@xchainjs/xchain-client'
import { Midgard, MidgardCache, MidgardQuery } from '@xchainjs/xchain-midgard-query'
import { ThorchainAMM, Wallet } from '@xchainjs/xchain-thorchain-amm'
import { Midgard, SaversWithdraw, ThorchainCache, ThorchainQuery, Thornode } from '@xchainjs/xchain-thorchain-query'
import { SaversWithdraw, ThorchainCache, ThorchainQuery, Thornode } from '@xchainjs/xchain-thorchain-query'
import { assetFromString } from '@xchainjs/xchain-util'

/**
Expand Down Expand Up @@ -29,7 +30,8 @@ const withdrawSavers = async (tcAmm: ThorchainAMM, wallet: Wallet) => {
const main = async () => {
const seed = process.argv[2]
const network = process.argv[3] as Network
const thorchainCache = new ThorchainCache(new Midgard(network), new Thornode(network))
const midgardCache = new MidgardCache(new Midgard(network))
const thorchainCache = new ThorchainCache(new Thornode(network), new MidgardQuery(midgardCache))
const thorchainQuery = new ThorchainQuery(thorchainCache)
const thorchainAmm = new ThorchainAMM(thorchainQuery)
const wallet = new Wallet(seed, thorchainQuery)
Expand Down
5 changes: 3 additions & 2 deletions examples/loans/loanQuoteClosed.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Network } from '@xchainjs/xchain-client'
import { Midgard, MidgardCache, MidgardQuery } from '@xchainjs/xchain-midgard-query'
import { ThorchainAMM } from '@xchainjs/xchain-thorchain-amm'
import {
CryptoAmount,
LoanCloseParams,
Midgard,
ThorchainCache,
ThorchainQuery,
Thornode,
Expand Down Expand Up @@ -37,7 +37,8 @@ const getLoanQuoteClosed = async (tcAmm: ThorchainAMM) => {
// Call the function from main()
const main = async () => {
const network = process.argv[2] as Network
const thorchainCache = new ThorchainCache(new Midgard(network), new Thornode(network))
const midgardCache = new MidgardCache(new Midgard(network))
const thorchainCache = new ThorchainCache(new Thornode(network), new MidgardQuery(midgardCache))
const thorchainQuery = new ThorchainQuery(thorchainCache)
const thorchainAmm = new ThorchainAMM(thorchainQuery)
await getLoanQuoteClosed(thorchainAmm)
Expand Down
Loading

0 comments on commit 34f8f0e

Please sign in to comment.