Skip to content

Commit

Permalink
fix: separate lp account for lp api (#5354)
Browse files Browse the repository at this point in the history
* fix: separate LP API test from other bouncer tests

* chore: ensure migration tests run
  • Loading branch information
kylezs authored and dandanlen committed Oct 31, 2024
1 parent 24d0a3a commit 857d7cd
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 20 deletions.
2 changes: 1 addition & 1 deletion bouncer/commands/run_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import { testBrokerFeeCollection } from '../tests/broker_fee_collection';
import { testBtcUtxoConsolidation } from '../tests/btc_utxo_consolidation';
import { testDCASwaps } from '../tests/DCA_test';
import { testEvmDeposits } from '../tests/evm_deposits';
import { testFillOrKill } from '../tests/fill_or_kill';
import { testFundRedeem } from '../tests/fund_redeem';
Expand All @@ -40,6 +39,7 @@ import { ConsoleColors, ConsoleLogColors } from '../shared/utils';
import { testDeltaBasedIngress } from '../tests/delta_based_ingress';
import { testCancelOrdersBatch } from '../tests/create_and_delete_multiple_orders';
import { depositChannelCreation } from '../tests/request_swap_deposit_address_with_affiliates';
import { testDCASwaps } from '../tests/DCA_test';

async function main() {
const testName = process.argv[2];
Expand Down
38 changes: 24 additions & 14 deletions bouncer/shared/setup_swaps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,33 @@ export async function setupSwaps(): Promise<void> {
createLpPool('SolUsdc', price.get('SolUsdc')!),
]);

console.log('LP Pools created');
const lp1Deposits = Promise.all([
depositLiquidity('Usdc', deposits.get('Usdc')!, false, '//LP_1'),
depositLiquidity('Eth', deposits.get('Eth')!, false, '//LP_1'),
depositLiquidity('Dot', deposits.get('Dot')!, false, '//LP_1'),
depositLiquidity('Btc', deposits.get('Btc')!, false, '//LP_1'),
depositLiquidity('Flip', deposits.get('Flip')!, false, '//LP_1'),
depositLiquidity('Usdt', deposits.get('Usdt')!, false, '//LP_1'),
depositLiquidity('ArbEth', deposits.get('ArbEth')!, false, '//LP_1'),
depositLiquidity('ArbUsdc', deposits.get('ArbUsdc')!, false, '//LP_1'),
depositLiquidity('Sol', deposits.get('Sol')!, false, '//LP_1'),
depositLiquidity('SolUsdc', deposits.get('SolUsdc')!, false, '//LP_1'),
]);

await Promise.all([
// provide liquidity to LP_1
depositLiquidity('Usdc', deposits.get('Usdc')!),
depositLiquidity('Eth', deposits.get('Eth')!),
depositLiquidity('Dot', deposits.get('Dot')!),
depositLiquidity('Btc', deposits.get('Btc')!),
depositLiquidity('Flip', deposits.get('Flip')!),
depositLiquidity('Usdt', deposits.get('Usdt')!),
depositLiquidity('ArbEth', deposits.get('ArbEth')!),
depositLiquidity('ArbUsdc', deposits.get('ArbUsdc')!),
depositLiquidity('Sol', deposits.get('Sol')!),
depositLiquidity('SolUsdc', deposits.get('SolUsdc')!),
const lpApiDeposits = Promise.all([
depositLiquidity('Usdc', 1000, false, '//LP_API'),
depositLiquidity('Eth', 100, false, '//LP_API'),
depositLiquidity('Dot', 2000, false, '//LP_API'),
depositLiquidity('Btc', 10, false, '//LP_API'),
depositLiquidity('Flip', 10000, false, '//LP_API'),
depositLiquidity('Usdt', 1000, false, '//LP_API'),
depositLiquidity('ArbEth', 10, false, '//LP_API'),
depositLiquidity('ArbUsdc', 1000, false, '//LP_API'),
depositLiquidity('Sol', 500, false, '//LP_API'),
depositLiquidity('SolUsdc', 1000, false, '//LP_API'),
]);

console.log('Liquidity provided');
await Promise.all([lp1Deposits, lpApiDeposits]);

await Promise.all([
rangeOrder('Eth', deposits.get('Eth')! * 0.9999),
Expand Down
14 changes: 14 additions & 0 deletions bouncer/shared/upgrade_network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { compileBinaries } from './utils/compile_binaries';
import { submitRuntimeUpgradeWithRestrictions } from './submit_runtime_upgrade';
import { execWithLog } from './utils/exec_with_log';
import { submitGovernanceExtrinsic } from './cf_governance';
import { setupLpAccount } from './setup_lp_account';

async function readPackageTomlVersion(projectRoot: string): Promise<string> {
const data = await fs.readFile(path.join(projectRoot, '/state-chain/runtime/Cargo.toml'), 'utf8');
Expand Down Expand Up @@ -338,6 +339,19 @@ export async function upgradeNetworkPrebuilt(
);
}

// Temp: until localnet/bouncer initialises to a version where the LP_API is funded already.
if (cleanOldVersion.startsWith('1.6')) {
console.log('Setting up LP account and adding liquidity for the LP-API.');
// Liquidity is provided as part of the LP-API test setup.
await setupLpAccount('//LP_API');
// Write LP_API key to keys/ so that the LP-API can use it - when upgrading the old version, which the upgrade-test is
// started from doesn't yet have this key.
await fs.writeFile(
`${localnetInitPath}/keys/LP_API`,
'8e1866e65039304e4142f09452a8305acd28d0ae0b833cd268b21a57d68782c1',
);
}

if (cleanOldVersion === nodeVersion) {
throw Error(
'The versions are the same. No need to upgrade. Please provide a different version.',
Expand Down
2 changes: 1 addition & 1 deletion bouncer/tests/all_concurrent_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import { testBrokerFeeCollection } from './broker_fee_collection';
import { testBoostingSwap } from './boost';
import { observeBadEvent } from '../shared/utils/substrate';
import { testFillOrKill } from './fill_or_kill';
import { testDCASwaps } from './DCA_test';
import { testCancelOrdersBatch } from './create_and_delete_multiple_orders';
import { testAllSwaps } from './all_swaps';
import { depositChannelCreation } from './request_swap_deposit_address_with_affiliates';
import { testDCASwaps } from './DCA_test';

async function runAllConcurrentTests() {
// Specify the number of nodes via providing an argument to this script.
Expand Down
4 changes: 2 additions & 2 deletions bouncer/tests/lp_api_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ async function provideLiquidityAndTestAssetBalances() {
amountToFineAmount(amountToProvide.toString(), assetDecimals('Eth')),
);
// We have to wait finalization here because the LP API server is using a finalized block stream (This may change in PRO-777 PR#3986)
await depositLiquidity(testAsset, amountToProvide, true);
await depositLiquidity(testAsset, amountToProvide, true, '//LP_API');

// Wait for the LP API to get the balance update, just incase it was slower than us to see the event.
let retryCount = 0;
Expand Down Expand Up @@ -154,7 +154,7 @@ async function testTransferAsset() {

const keyring = new Keyring({ type: 'sr25519' });

const sourceLpAccount = keyring.createFromUri('//LP_1');
const sourceLpAccount = keyring.createFromUri('//LP_API');
const destinationLpAccount = keyring.createFromUri('//LP_2');

const oldBalanceSource = await getLpBalance(sourceLpAccount.address);
Expand Down
1 change: 0 additions & 1 deletion localnet/init/keys/LP_1

This file was deleted.

1 change: 1 addition & 0 deletions localnet/init/keys/LP_API
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
8e1866e65039304e4142f09452a8305acd28d0ae0b833cd268b21a57d68782c1
2 changes: 1 addition & 1 deletion localnet/init/scripts/start-lp-api.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ binary_location=$1
RUST_LOG=debug,jsonrpsee_types::params=trace $binary_location/chainflip-lp-api \
--port=10589 \
--state_chain.ws_endpoint=ws://localhost:9944 \
--state_chain.signing_key_file $KEYS_DIR/LP_1 > /tmp/chainflip/chainflip-lp-api.$DATETIME.log 2>&1 &
--state_chain.signing_key_file $KEYS_DIR/LP_API > /tmp/chainflip/chainflip-lp-api.$DATETIME.log 2>&1 &
6 changes: 6 additions & 0 deletions state-chain/node/src/chain_spec/testnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ pub const SNOW_WHITE_SR25519: [u8; 32] =

pub fn extra_accounts() -> Vec<(AccountId, AccountRole, FlipBalance, Option<Vec<u8>>)> {
vec![
(
get_account_id_from_seed::<sr25519::Public>("LP_API"),
AccountRole::LiquidityProvider,
100 * FLIPPERINOS_PER_FLIP,
Some(b"Chainflip Testnet LP API".to_vec()),
),
(
get_account_id_from_seed::<sr25519::Public>("LP_1"),
AccountRole::LiquidityProvider,
Expand Down

0 comments on commit 857d7cd

Please sign in to comment.