Skip to content

Commit

Permalink
Move nabla code before swap again
Browse files Browse the repository at this point in the history
  • Loading branch information
ebma committed Aug 7, 2024
1 parent dceadaa commit 4bb0db5
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/services/nabla.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,15 @@ export async function nablaSwap(state: OfframpingState, { renderEvent }: Executi

const { api, ss58Format } = (await getApiManagerInstance()).apiData!;

// get ephemeral keypair and account
const keyring = new Keyring({ type: 'sr25519', ss58Format });
const ephemeralKeypair = keyring.addFromUri(pendulumEphemeralSeed);
// balance before the swap. Important for recovery process.
// if transaction was able to get in, but we failed on the listening
const outputCurrencyId = getPendulumCurrencyId(outputTokenType);
const responseBalanceBefore = (await api.query.tokens.accounts(ephemeralKeypair.address, outputCurrencyId)) as any;
const rawBalanceBefore = Big(responseBalanceBefore?.free?.toString() ?? '0');

try {
renderEvent(
`Swapping ${inputAmountNabla.units} ${inputToken.axelarEquivalent.pendulumAssetSymbol} to ${outputAmount.units} ${outputToken.stellarAsset.code.string} `,
Expand All @@ -302,17 +311,6 @@ export async function nablaSwap(state: OfframpingState, { renderEvent }: Executi
renderEvent(`Could not swap the required amount of token: ${errorMessage}`, EventStatus.Error);
return Promise.reject('Could not swap token');
}

// get ephemeral keypair and account
const keyring = new Keyring({ type: 'sr25519', ss58Format });
const ephemeralKeypair = keyring.addFromUri(pendulumEphemeralSeed);

// balance before the swap. Important for recovery process.
// if transaction was able to get in, but we failed on the listening
const outputCurrencyId = getPendulumCurrencyId(outputTokenType);
const responseBalanceBefore = (await api.query.tokens.accounts(ephemeralKeypair.address, outputCurrencyId)) as any;
const rawBalanceBefore = Big(responseBalanceBefore?.free?.toString() ?? '0');

//verify token balance before releasing this process.
const responseBalanceAfter = (await api.query.tokens.accounts(ephemeralKeypair.address, outputCurrencyId)) as any;
const rawBalanceAfter = Big(responseBalanceAfter?.free?.toString() ?? '0');
Expand Down

0 comments on commit 4bb0db5

Please sign in to comment.