Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
8afa54b
Fix eslint config for api
ebma Apr 14, 2025
3d89857
Refactor ramp-recovery.worker.ts and make it execute on start
ebma Apr 14, 2025
2ec9f72
Refactor cleanup.worker.ts
ebma Apr 14, 2025
6f2fbd4
Adjust to new constructor in api/src/index.ts
ebma Apr 14, 2025
455bad0
Add logs
ebma Apr 14, 2025
9fcf47b
Add more logs
ebma Apr 14, 2025
b7485a5
Improve handling of Stellar errors
ebma Apr 14, 2025
2981ef7
Replace usages of console log with `logger`
ebma Apr 14, 2025
4880585
Show quote timer in ramp summary
ebma Apr 14, 2025
2f44ac9
Make text of CopyButton copyable by default
ebma Apr 14, 2025
ba1accc
Disable submit button if ramp is expired
ebma Apr 14, 2025
d61b12e
Remove custom message for nablaApprove phase
ebma Apr 14, 2025
cfb6534
Merge branch 'staging' into improve-api-recovery-worker
ebma Apr 14, 2025
5b42086
re introduce rounding for offramp case
gianfra-t Apr 14, 2025
25605b0
Translate validation errors
ebma Apr 14, 2025
68cbe0a
Fix wrong condition in initial-phase-handler.ts
ebma Apr 14, 2025
bc332f8
Fix missing import in offrampTransactions.ts
ebma Apr 14, 2025
b7fb27b
Fix wrong import in cleanup.worker.test.ts
ebma Apr 14, 2025
80f31eb
Add logs for debugging
ebma Apr 15, 2025
e09ea9e
add BRLA disclaimer for Onramp
Sharqiewicz Apr 15, 2025
b02f42f
Reset ramp State when closing summary
ebma Apr 15, 2025
66fdafc
Add more logs
ebma Apr 15, 2025
d0fdd23
Move throwing of API errors out of try-catch
ebma Apr 15, 2025
27fc64e
Set quote and output amount to undefined if quote fetching failed
ebma Apr 15, 2025
bb95c3b
Show error when trying to onramp from AssetHub
ebma Apr 15, 2025
4391a01
Await crypto initialization in shared
ebma Apr 15, 2025
87583a5
Make sure the quote is refetched when closing the summary dialog
ebma Apr 15, 2025
79b0206
Set expected time for brlaTeleport phase to 90 seconds
ebma Apr 15, 2025
6f8c9b9
Refactor expiry in summary dialog
ebma Apr 15, 2025
f8d7a08
improve RampSummary button logic
Sharqiewicz Apr 15, 2025
e8c1ccb
Merge branch 'improve-api-recovery-worker' of github.com:pendulum-cha…
Sharqiewicz Apr 15, 2025
8e19e1d
remove unused ref in BrlaExtendedForm
Sharqiewicz Apr 15, 2025
235da8e
refactor OfframpSummaryDialog into RampSummaryDialog
Sharqiewicz Apr 15, 2025
dfa8cf8
add rampSummary store to handle expiry logic
Sharqiewicz Apr 15, 2025
63939d3
show BRL KYC form
Sharqiewicz Apr 15, 2025
d5c004c
fix translations BRLOnrampDetails
Sharqiewicz Apr 15, 2025
6c6afe3
fix translations FeeDetails
Sharqiewicz Apr 15, 2025
90d6863
fix translations TransactionTokensDisplay
Sharqiewicz Apr 15, 2025
975c863
fix translations RampSummaryButton
Sharqiewicz Apr 15, 2025
908f8bb
fix en translations for RampSummaryDialog
Sharqiewicz Apr 15, 2025
3786caf
add pt translations for RampSummaryDialog
Sharqiewicz Apr 15, 2025
c9647cc
hide Quote expires when is not defined
Sharqiewicz Apr 15, 2025
c0b32c8
fix Expired Quote button text
Sharqiewicz Apr 15, 2025
25120e2
handle canRegisterRamp and rename offrampStore to rampStore
Sharqiewicz Apr 15, 2025
22c57bd
Merge branch 'staging' into improve-api-recovery-worker
ebma Apr 15, 2025
73ed4d5
add handler for assethub onramp
gianfra-t Apr 15, 2025
55401b0
fix broken merge
gianfra-t Apr 15, 2025
3c6cba0
Show text for isQuoteExpired also for offramps
ebma Apr 15, 2025
5e7bc5b
Fix condition for showing quote expiry
ebma Apr 15, 2025
8d02b36
Remove unused attribute from quote store
ebma Apr 15, 2025
9675116
Adjust quote expiry button text
ebma Apr 15, 2025
7f469fa
enable assethub onramp
gianfra-t Apr 15, 2025
583a409
Fix wrong lock expiry check
ebma Apr 15, 2025
8453bee
Fix wrong log message
ebma Apr 15, 2025
3fbbb3d
Adjust styling of success page
ebma Apr 15, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ dist-ssr
.env.sentry-build-plugin

# testing artifacts
*/failedRampStateRecovery.json
*/lastRampState.json
*/lastRampStateOnramp.json
**/failedRampStateRecovery.json
**/lastRampState.json
**/lastRampStateOnramp.json

38 changes: 0 additions & 38 deletions api/.eslintrc

This file was deleted.

39 changes: 39 additions & 0 deletions api/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
module.exports = {
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
rules: {
'no-console': 0,
'no-underscore-dangle': 0,
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: 'next' }],
'no-use-before-define': 'off',
'@typescript-eslint/no-use-before-define': ['error', { variables: false }],
'no-multi-str': 0,
'import/extensions': [
'error',
'ignorePackages',
{
ts: 'never',
},
],
},
env: {
es2020: true,
node: true,
mocha: true,
},
parserOptions: {
ecmaVersion: 8, // Note: ecmaVersion 8 is ES2017. Consider updating if using newer features.
sourceType: 'module',
project: './tsconfig.json', // Path relative to tsconfigRootDir
tsconfigRootDir: __dirname, // Correctly resolves the directory of this config file
},
extends: ['airbnb-base', 'prettier', 'plugin:@typescript-eslint/recommended'],
settings: {
'import/resolver': {
node: {
extensions: ['.ts'],
},
},
},
};
Binary file modified api/bun.lockb
Binary file not shown.
3 changes: 2 additions & 1 deletion api/src/api/controllers/brla.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { BrlaApiService } from '../services/brla/brlaApiService';
import { eventPoller } from '../..';
import { BrlaTeleportService } from '../services/brla/brlaTeleportService';
import { generateReferenceLabel } from '../services/brla/helpers';
import logger from '../../config/logger';

// BRLA API requires the date in the format YYYY-MMM-DD
function convertDateToBRLAFormat(dateNumber: number) {
Expand Down Expand Up @@ -351,7 +352,7 @@ export const triggerPayIn = async (
res.status(400).json({ error: 'taxId invalid' });
return;
}
console.log('Requesting teleport:', subaccount.id, amount, receiverAddress);
logger.info('Requesting teleport:', subaccount.id, amount, receiverAddress);
const teleportService = BrlaTeleportService.getInstance();
await teleportService.requestTeleport(subaccount.id, Number(amount), receiverAddress);

Expand Down
5 changes: 3 additions & 2 deletions api/src/api/controllers/pendulum.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { fundEphemeralAccount, getFundingData } from '../services/pendulum/pendu
import { ChainDecimals, multiplyByPowerOfTen, nativeToDecimal } from '../services/pendulum/helpers';
import { SlackNotifier } from '../services/slack.service';
import { ApiManager } from '../services/pendulum/apiManager';
import logger from '../../config/logger';

// DEPRECATED
export const fundEphemeralAccountController = async (
Expand Down Expand Up @@ -60,7 +61,7 @@ export const sendStatusWithPk = async (): Promise<StatusResponse> => {
// Wait for all required token balances check.
await Promise.all(
Object.entries(TOKEN_CONFIG).map(async ([token, tokenConfig]: [string, StellarTokenConfig | XCMTokenConfig]) => {
console.log(`Checking token ${token} balance...`);
logger.info(`Checking token ${token} balance...`);
if (!tokenConfig.pendulumCurrencyId) {
throw new Error(`Token ${token} does not have a currency id.`);
}
Expand All @@ -80,7 +81,7 @@ export const sendStatusWithPk = async (): Promise<StatusResponse> => {

if (remainingMaxSubsidiesAvailable.lt(SUBSIDY_MINIMUM_RATIO_FUND_UNITS)) {
isTokensSufficient = false;
console.log(`Token ${token} balance is insufficient.`);
logger.info(`Token ${token} balance is insufficient.`);

const tokenDecimals = 'decimals' in tokenConfig ? tokenConfig.decimals : ChainDecimals;
slackNotifier.sendMessage({
Expand Down
5 changes: 3 additions & 2 deletions api/src/api/controllers/subsidize.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { StellarTokenConfig, TOKEN_CONFIG, XCMTokenConfig } from 'shared';
import { SubsidizeEndpoints } from 'shared/src/endpoints/subsidize.endpoints';
import { PENDULUM_FUNDING_SEED } from '../../constants/constants';
import { ApiManager } from '../services/pendulum/apiManager';
import logger from '../../config/logger';

export const getFundingAccount = () => {
if (!PENDULUM_FUNDING_SEED) {
Expand Down Expand Up @@ -39,7 +40,7 @@ export const subsidizePreSwap = async (
): Promise<void> => {
try {
const { address, amountRaw, tokenToSubsidize } = req.body;
console.log('Subsidize pre swap', address, amountRaw, tokenToSubsidize);
logger.info('Subsidize pre swap', address, amountRaw, tokenToSubsidize);

const config = getPendulumCurrencyConfig(tokenToSubsidize);

Expand Down Expand Up @@ -72,7 +73,7 @@ export const subsidizePostSwap = async (
): Promise<void> => {
try {
const { address, amountRaw, token } = req.body;
console.log('Subsidize post swap', address, amountRaw, token);
logger.info('Subsidize post swap', address, amountRaw, token);

const config = getPendulumCurrencyConfig(token);

Expand Down
4 changes: 2 additions & 2 deletions api/src/api/helpers/quote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ export function calculateTotalReceive(toAmount: Big, outputCurrency: RampCurrenc
const fixedFees = new Big(
outputTokenDetails.offrampFeesFixedComponent ? outputTokenDetails.offrampFeesFixedComponent : 0,
);
const fees = toAmount.mul(feeBasisPoints).div(10000).add(fixedFees).round(6, 0);
const fees = toAmount.mul(feeBasisPoints).div(10000).add(fixedFees).round(2, 1);
const totalReceiveRaw = toAmount.minus(fees);

if (totalReceiveRaw.gt(0)) {
return totalReceiveRaw.toFixed(6, 0);
return totalReceiveRaw.toFixed(2, 0);
}
return '0';
}
Expand Down
9 changes: 5 additions & 4 deletions api/src/api/services/brla/brlaTeleportService.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { BrlaApiService } from './brlaApiService';
import { FastQuoteQueryParams, BrlaSupportedChain, OnchainLog, SmartContractOperationType } from './types';
import { verifyReferenceLabel } from './helpers';
import logger from '../../../config/logger';

// This service is used to request and keep tracks of teleports (transfers) from BRLA's
// controlled accounts.
Expand Down Expand Up @@ -60,7 +61,7 @@ export class BrlaTeleportService {
status: 'claimed',
receiverAddress,
};
console.log('Requesting teleport:', teleport);
logger.info('Requesting teleport:', teleport);
this.teleports.set(subaccountId, teleport);
this.maybeStartPeriodicChecks();
}
Expand All @@ -77,7 +78,7 @@ export class BrlaTeleportService {
throw new Error('Teleport not in arrived state.');
}

console.log('Starting teleport:', teleport);
logger.info('Starting teleport:', teleport);
const fastQuoteParams: FastQuoteQueryParams = {
subaccountId: teleport.subaccountId,
operation: 'swap',
Expand All @@ -101,7 +102,7 @@ export class BrlaTeleportService {

this.maybeStartPeriodicChecks();
} catch (e) {
console.log('Error starting teleport:', e);
logger.error('Error starting teleport:', e);
this.teleports.set(subaccountId, { ...teleport, status: 'failed' });
}
}
Expand Down Expand Up @@ -141,7 +142,7 @@ export class BrlaTeleportService {

if (lastContractOp.operationName === SmartContractOperationType.MINT && lastContractOp.executed === true) {
this.completedTeleports.set(subaccountId, { ...teleport, status: 'completed' });
console.log('Teleport completed:', teleport);
logger.info('Teleport completed:', teleport);
this.teleports.delete(subaccountId);
}
}
Expand Down
3 changes: 2 additions & 1 deletion api/src/api/services/brla/webhooks.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { WEBHOOKS_CACHE_URL } from '../../../constants/constants';
import { BrlaApiService } from './brlaApiService';
import logger from '../../../config/logger';

type SubscriptionType = 'BURN' | 'BALANCE-UPDATE' | 'MONEY-TRANSFER' | 'MINT' | 'KYC';

Expand Down Expand Up @@ -97,7 +98,7 @@ export class EventPoller {
// async acknowledge events
if (eventsToAcknowledge.length > 0) {
this.brlaApiService.acknowledgeEvents(eventsToAcknowledge.flatMap((event) => event.id)).catch((error) => {
console.log('Poll: Error while acknowledging events: ', error);
logger.error('Poll: Error while acknowledging events: ', error);
});
}
}
Expand Down
3 changes: 2 additions & 1 deletion api/src/api/services/moonbeam/balance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { MOONBEAM_EPHEMERAL_STARTING_BALANCE_UNITS, MOONBEAM_FUNDING_PRIVATE_KEY
import { multiplyByPowerOfTen } from '../pendulum/helpers';
import { privateKeyToAccount } from 'viem/accounts';
import { createMoonbeamClientsAndConfig } from './createServices';
import logger from '../../../config/logger';

export function checkMoonbeamBalancePeriodically(
tokenAddress: string,
Expand All @@ -34,7 +35,7 @@ export function checkMoonbeamBalancePeriodically(
args: [brlaEvmAddress],
})) as string;

console.log(`Moonbeam balance check: ${result.toString()} / ${amountDesiredRaw.toString()}`);
logger.info(`Moonbeam balance check: ${result.toString()} / ${amountDesiredRaw.toString()}`);
const someBalanceBig = new Big(result.toString());
const amountDesiredUnitsBig = new Big(amountDesiredRaw);

Expand Down
13 changes: 7 additions & 6 deletions api/src/api/services/pendulum/apiManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ApiPromise, WsProvider } from '@polkadot/api';
import { SubmittableExtrinsic } from '@polkadot/api/types';
import { ISubmittableResult } from '@polkadot/types/types';
import { KeyringPair } from '@polkadot/keyring/types';
import logger from '../../../config/logger';

export type SubstrateApiNetwork = 'assethub' | 'pendulum' | 'moonbeam';

Expand Down Expand Up @@ -94,10 +95,10 @@ export class ApiManager {

public async populateApi(networkName: SubstrateApiNetwork): Promise<API> {
const network = this.getNetworkConfig(networkName);
console.log(`Connecting to node ${network.wsUrl}...`);
logger.info(`Connecting to node ${network.wsUrl}...`);
const newApi = await this.connectApi(networkName);
this.apiInstances.set(networkName, newApi);
console.log(`Connected to node ${network.wsUrl}`);
logger.info(`Connected to node ${network.wsUrl}`);

if (!newApi.api.isConnected) await newApi.api.connect();
await newApi.api.isReady;
Expand All @@ -123,7 +124,7 @@ export class ApiManager {
const previousSpecVersion = this.previousSpecVersions.get(networkName) ?? 0;

if (currentSpecVersion !== previousSpecVersion) {
console.log(`Spec version changed for ${networkName}, refreshing the api...`);
logger.info(`Spec version changed for ${networkName}, refreshing the api...`);
return await this.populateApi(networkName);
}

Expand Down Expand Up @@ -158,7 +159,7 @@ export class ApiManager {
return nonceRpc;
}

console.log(
logger.info(
`Nonce mismatch detected on ${networkName}. RPC: ${nonceRpc}, ApiManager: ${lastUsedNonce}, sending transaction with nonce ${
lastUsedNonce + 1
}`,
Expand All @@ -184,12 +185,12 @@ export class ApiManager {

try {
const nonce = await this.getNonce(senderKeypair, networkName);
console.log(`Sending transaction on ${networkName} with nonce ${nonce}`);
logger.info(`Sending transaction on ${networkName} with nonce ${nonce}`);
return call.signAndSend(senderKeypair, { nonce });
} catch (initialError: any) {
// Only retry if the error is regarding bad signature error
if (initialError.name === 'RpcError' && initialError.message.includes('Transaction has a bad signature')) {
console.log(
logger.info(
`Bad signature error encountered while sending transaction on ${networkName}, attempting to refresh the api...`,
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { StateMetadata } from '../meta-state-types';
import { BasePhaseHandler } from '../base-phase-handler';
import { BrlaApiService } from '../../brla/brlaApiService';
import { checkMoonbeamBalancePeriodically } from '../../moonbeam/balance';
import logger from '../../../../config/logger';

export class BrlaPayoutOnMoonbeamPhaseHandler extends BasePhaseHandler {
public getPhaseName(): RampPhase {
Expand Down Expand Up @@ -49,7 +50,7 @@ export class BrlaPayoutOnMoonbeamPhaseHandler extends BasePhaseHandler {
if (balanceCheckError.message === 'Balance did not meet the limit within the specified time') {
throw new Error(`BrlaPayoutOnMoonbeamPhaseHandler: balanceCheckError ${balanceCheckError.message}`);
} else {
console.log('Error checking Moonbeam balance:', balanceCheckError);
logger.error('Error checking Moonbeam balance:', balanceCheckError);
throw new Error(`Error checking Moonbeam balance`);
}
}
Expand Down
5 changes: 3 additions & 2 deletions api/src/api/services/phases/handlers/brla-teleport-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { BasePhaseHandler } from '../base-phase-handler';
import { BrlaApiService } from '../../brla/brlaApiService';
import { checkMoonbeamBalancePeriodically } from '../../moonbeam/balance';
import { BrlaTeleportService } from '../../brla/brlaTeleportService';
import logger from '../../../../config/logger';

export class BrlaTeleportPhaseHandler extends BasePhaseHandler {
public getPhaseName(): RampPhase {
Expand All @@ -30,7 +31,7 @@ export class BrlaTeleportPhaseHandler extends BasePhaseHandler {
if (!subaccount) {
throw new Error('Subaccount not found');
}
console.log('Requesting teleport:', subaccount.id, inputAmountBrla, moonbeamEphemeralAddress);
logger.info('Requesting teleport:', subaccount.id, inputAmountBrla, moonbeamEphemeralAddress);
const teleportService = BrlaTeleportService.getInstance();
await teleportService.requestTeleport(
subaccount.id,
Expand Down Expand Up @@ -62,7 +63,7 @@ export class BrlaTeleportPhaseHandler extends BasePhaseHandler {
if (balanceCheckError.message === 'Balance did not meet the limit within the specified time') {
throw new Error(`BrlaTeleportPhaseHandler: balanceCheckError ${balanceCheckError.message}`);
} else {
console.log('Error checking Moonbeam balance:', balanceCheckError);
logger.error('Error checking Moonbeam balance:', balanceCheckError);
throw new Error(`BrlaTeleportPhaseHandler: Error checking Moonbeam balance`);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { multiplyByPowerOfTen } from '../../pendulum/helpers';
import { GLMR_FUNDING_AMOUNT_RAW, PENDULUM_EPHEMERAL_STARTING_BALANCE_UNITS } from '../../../../constants/constants';
import { TOKEN_CONFIG } from 'shared';
import { fundMoonbeamEphemeralAccount } from '../../moonbeam/balance';
import logger from '../../../../config/logger';

export class FundEphemeralPhaseHandler extends BasePhaseHandler {
public getPhaseName(): RampPhase {
Expand Down Expand Up @@ -39,7 +40,7 @@ export class FundEphemeralPhaseHandler extends BasePhaseHandler {
}

if (!isPendulumFunded) {
console.log('Funding pen ephemeral...');
logger.info('Funding pen ephemeral...');
if (state.type === 'on' && state.to !== 'assethub') {
await fundEphemeralAccount('pendulum', pendulumEphemeralAddress, true);
} else if (state.state.outputCurrency === FiatToken.BRL) {
Expand All @@ -48,11 +49,11 @@ export class FundEphemeralPhaseHandler extends BasePhaseHandler {
await fundEphemeralAccount('pendulum', pendulumEphemeralAddress, false);
}
} else {
console.log('Pendulum ephemeral address already funded.');
logger.info('Pendulum ephemeral address already funded.');
}

if (state.type === 'on' && !isMoonbeamFunded) {
console.log('Funding moonbeam ephemeral...');
logger.info('Funding moonbeam ephemeral...');
await fundMoonbeamEphemeralAccount(moonbeamEphemeralAddress);
}
} catch (e) {
Expand Down
Loading
Loading