Skip to content

Commit

Permalink
chore(bouncer): Update sdk to 1.2.1 (#4582)
Browse files Browse the repository at this point in the history
* chore(bouncer): Update sdk to 1.2.1-alpha.1

* Update cli package
  • Loading branch information
niklasnatter authored Mar 1, 2024
1 parent 0dbf0c9 commit f88ad10
Show file tree
Hide file tree
Showing 36 changed files with 258 additions and 132 deletions.
2 changes: 1 addition & 1 deletion bouncer/commands/create_lp_pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// initial price in USDC
// For example: ./commands/create_lp_pool.ts btc 10000

import { Asset } from '@chainflip-io/cli';
import { Asset } from '@chainflip/cli';
import { createLpPool } from '../shared/create_lp_pool';
import { runWithTimeout } from '../shared/utils';

Expand Down
2 changes: 1 addition & 1 deletion bouncer/commands/get_balance.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env -S pnpm tsx
import { Asset } from '@chainflip-io/cli';
import { Asset } from '@chainflip/cli';
import { getBalance as getBalanceShared } from '../shared/get_balance';

async function getBalance(ccy: string, address: string) {
Expand Down
15 changes: 8 additions & 7 deletions bouncer/commands/go_bananas.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env -S pnpm tsx
import axios from 'axios';
import { Asset, assetDecimals } from '@chainflip-io/cli';
import { Asset } from '@chainflip/cli';
import bitcoin from 'bitcoinjs-lib';
import { Tapleaf } from 'bitcoinjs-lib/src/types';
import { blake2AsHex } from '@polkadot/util-crypto';
Expand All @@ -11,6 +11,7 @@ import {
hexStringToBytesArray,
sleep,
fineAmountToAmount,
assetDecimals,
} from '../shared/utils';
import { requestNewSwap } from '../shared/perform_swap';
import { testSwap } from '../shared/swapping';
Expand Down Expand Up @@ -124,7 +125,7 @@ async function playLp(asset: Asset, price: number, liquidity: number) {
}
const fees = fineAmountToAmount(
BigInt(update.collected_fees.toString()).toString(10),
assetDecimals[ccy],
assetDecimals(ccy),
);
console.log(`Collected ${fees} ${ccy} in fees`);
}
Expand All @@ -140,7 +141,7 @@ async function playLp(asset: Asset, price: number, liquidity: number) {
}
const amount = fineAmountToAmount(
BigInt(update.bought_amount.toString()).toString(10),
assetDecimals[buyCcy],
assetDecimals(buyCcy),
);
console.log(`Bought ${amount} ${buyCcy} for ${sellCcy}`);
}
Expand Down Expand Up @@ -227,22 +228,22 @@ async function bananas() {
await Promise.all([
playLp(
'ETH',
price.get('ETH')! * 10 ** (assetDecimals.USDC - assetDecimals.ETH),
price.get('ETH')! * 10 ** (assetDecimals('USDC') - assetDecimals('ETH')),
liquidityUsdc,
),
playLp(
'BTC',
price.get('BTC')! * 10 ** (assetDecimals.USDC - assetDecimals.BTC),
price.get('BTC')! * 10 ** (assetDecimals('USDC') - assetDecimals('BTC')),
liquidityUsdc,
),
playLp(
'DOT',
price.get('DOT')! * 10 ** (assetDecimals.USDC - assetDecimals.DOT),
price.get('DOT')! * 10 ** (assetDecimals('USDC') - assetDecimals('DOT')),
liquidityUsdc,
),
playLp(
'FLIP',
price.get('FLIP')! * 10 ** (assetDecimals.USDC - assetDecimals.FLIP),
price.get('FLIP')! * 10 ** (assetDecimals('USDC') - assetDecimals('FLIP')),
liquidityUsdc,
),
playSwapper(),
Expand Down
2 changes: 1 addition & 1 deletion bouncer/commands/new_swap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// Argument 3 is the destination address
// For example: ./commands/new_swap.ts dot btc n1ocq2FF95qopwbEsjUTy3ZrawwXDJ6UsX

import { Asset } from '@chainflip-io/cli';
import { Asset } from '@chainflip/cli';
import { runWithTimeout } from '../shared/utils';
import { newSwap } from '../shared/new_swap';

Expand Down
2 changes: 1 addition & 1 deletion bouncer/commands/perform_swap.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env -S pnpm tsx
import { Asset } from '@chainflip-io/cli';
import { Asset } from '@chainflip/cli';
import { performSwap } from '../shared/perform_swap';

async function main() {
Expand Down
2 changes: 1 addition & 1 deletion bouncer/commands/provide_liquidity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// It will fund liquidity of the given currency and amount
// For example: ./commands/provide_liquidity.ts btc 1.5

import { Asset } from '@chainflip-io/cli';
import { Asset } from '@chainflip/cli';
import { runWithTimeout } from '../shared/utils';
import { provideLiquidity } from '../shared/provide_liquidity';

Expand Down
2 changes: 1 addition & 1 deletion bouncer/commands/range_order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// It will create a zero to infinity range order for the currency and amount given
// For example: ./commands/range_order.ts btc 10

import { Asset } from '@chainflip-io/cli';
import { Asset } from '@chainflip/cli';
import { rangeOrder } from '../shared/range_order';
import { runWithTimeout } from '../shared/utils';

Expand Down
2 changes: 1 addition & 1 deletion bouncer/commands/send.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env -S pnpm tsx
import { Asset } from '@chainflip-io/cli';
import { Asset } from '@chainflip/cli';
import { send } from '../shared/send';

send(process.argv[2].toUpperCase() as Asset, process.argv[3]);
2 changes: 1 addition & 1 deletion bouncer/commands/setup_swaps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// For example: ./commands/setup_swaps.ts

import { cryptoWaitReady } from '@polkadot/util-crypto';
import { Asset } from '@chainflip-io/cli';
import { Asset } from '@chainflip/cli';
import { runWithTimeout } from '../shared/utils';
import { createLpPool } from '../shared/create_lp_pool';
import { provideLiquidity } from '../shared/provide_liquidity';
Expand Down
5 changes: 3 additions & 2 deletions bouncer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"prettier:write": "prettier --write ."
},
"dependencies": {
"@chainflip-io/cli": "^0.1.5-rc.1",
"@chainflip/cli": "^1.2.1-alpha.3",
"@iarna/toml": "^2.2.5",
"@polkadot/api": "10.7.2",
"@polkadot/keyring": "12.2.1",
Expand All @@ -26,7 +26,8 @@
"tiny-secp256k1": "^2.2.1",
"toml": "^3.0.0",
"web3": "^1.9.0",
"yargs": "^17.7.2"
"yargs": "^17.7.2",
"zod": "^3.22.4"
},
"devDependencies": {
"@types/minimist": "^1.2.2",
Expand Down
84 changes: 77 additions & 7 deletions bouncer/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion bouncer/shared/approve_erc20.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Web3 from 'web3';
import { Asset } from '@chainflip-io/cli';
import { Asset } from '@chainflip/cli';
import { amountToFineAmount, chainFromAsset, getEvmEndpoint } from '../shared/utils';
import { getEvmContractAddress } from './utils';
import { signAndSendTxEvm } from './send_evm';
Expand Down
12 changes: 4 additions & 8 deletions bouncer/shared/contract_swap.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
import {
Asset,
executeSwap,
ExecuteSwapParams,
approveVault,
assetDecimals,
} from '@chainflip-io/cli';
import { Asset, executeSwap, ExecuteSwapParams, approveVault } from '@chainflip/cli';
import { Wallet, getDefaultProvider } from 'ethers';
import {
getChainflipApi,
Expand All @@ -17,6 +11,7 @@ import {
chainFromAsset,
getEvmEndpoint,
getWhaleMnemonic,
assetDecimals,
} from './utils';
import { getNextEvmNonce } from './send_evm';
import { getBalance } from './get_balance';
Expand Down Expand Up @@ -53,7 +48,7 @@ export async function executeContractSwap(
destAsset,
// It is important that this is large enough to result in
// an amount larger than existential (e.g. on Polkadot):
amount: amountToFineAmount(defaultAssetAmounts(srcAsset), assetDecimals[srcAsset]),
amount: amountToFineAmount(defaultAssetAmounts(srcAsset), assetDecimals(srcAsset)),
destAddress,
srcAsset,
srcChain,
Expand Down Expand Up @@ -149,6 +144,7 @@ export async function approveTokenVault(srcAsset: 'FLIP' | 'USDC' | 'ARBUSDC', a
approveVault(
{
amount,
srcChain: chainFromAsset(srcAsset as Asset),
srcAsset,
},
{
Expand Down
6 changes: 3 additions & 3 deletions bouncer/shared/create_lp_pool.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { assetDecimals, Asset } from '@chainflip-io/cli';
import { observeEvent, getChainflipApi } from '../shared/utils';
import { Asset } from '@chainflip/cli';
import { observeEvent, getChainflipApi, assetDecimals } from '../shared/utils';
import { submitGovernanceExtrinsic } from './cf_governance';

export async function createLpPool(ccy: Asset, initialPrice: number) {
Expand All @@ -13,7 +13,7 @@ export async function createLpPool(ccy: Asset, initialPrice: number) {
).toJSON()! === null
) {
const price = BigInt(
Math.round((initialPrice / 10 ** (assetDecimals[ccy] - assetDecimals.USDC)) * 2 ** 128),
Math.round((initialPrice / 10 ** (assetDecimals(ccy) - assetDecimals('USDC'))) * 2 ** 128),
);
console.log(
'Setting up ' + ccy + ' pool with an initial price of ' + initialPrice + ' USDC per ' + ccy,
Expand Down
Loading

0 comments on commit f88ad10

Please sign in to comment.