Skip to content

Commit

Permalink
support for assethub transactions storing
Browse files Browse the repository at this point in the history
  • Loading branch information
gianfra-t committed Dec 23, 2024
1 parent c84499b commit 8942a5d
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ require('dotenv').config();
const { spreadsheet } = require('../../config/vars');
const { initGoogleSpreadsheet, getOrCreateSheet, appendData } = require('../services/spreadsheet.service');

exports.storeDataInGoogleSpreadsheet = async (req, res, spreadsheetId, sheetHeaderValues) => {
exports.storeDataInGoogleSpreadsheet = async (req, res, spreadsheetId) => {
try {
// We expect the data to be an object that matches our schema
const data = req.body;
// Identify header values based on substrate vs evm offramp.
const sheetHeaderValues = req.body.offramperAddress.includes('0x')
? DUMP_SHEET_HEADER_VALUES_EVM
: DUMP_SHEET_HEADER_VALUES_ASSETHUB;

// Try dumping transactions to spreadsheet
const sheet = await initGoogleSpreadsheet(spreadsheetId, spreadsheet.googleCredentials).then((doc) =>
Expand Down
27 changes: 21 additions & 6 deletions signer-service/src/api/controllers/storage.controller.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const { spreadsheet } = require('../../config/vars');
const { storeDataInGoogleSpreadsheet } = require('./googleSpreadSheet.controller');

// These are the headers for the Google Spreadsheet
const DUMP_SHEET_HEADER_VALUES = [
// These are the headers for the Google Spreadsheet for polygon offramp
const DUMP_SHEET_HEADER_VALUES_EVM = [
'timestamp',
'polygonAddress',
'offramperAddress',
'stellarEphemeralPublicKey',
'pendulumEphemeralPublicKey',
'nablaApprovalTx',
Expand All @@ -20,7 +20,22 @@ const DUMP_SHEET_HEADER_VALUES = [
'squidRouterReceiverHash',
];

exports.DUMP_SHEET_HEADER_VALUES = DUMP_SHEET_HEADER_VALUES;
const DUMP_SHEET_HEADER_VALUES_ASSETHUB = [
'timestamp',
'offramperAddress',
'stellarEphemeralPublicKey',
'pendulumEphemeralPublicKey',
'nablaApprovalTx',
'nablaSwapTx',
'spacewalkRedeemTx',
'stellarOfframpTx',
'stellarCleanupTx',
'inputAmount',
'inputTokenType',
'outputAmount',
'outputTokenType',
];
exports.DUMP_SHEET_HEADER_VALUES_ASSETHUB = DUMP_SHEET_HEADER_VALUES_ASSETHUB;
exports.DUMP_SHEET_HEADER_VALUES_EVM = DUMP_SHEET_HEADER_VALUES_EVM;

exports.storeData = async (req, res) =>
storeDataInGoogleSpreadsheet(req, res, spreadsheet.storageSheetId, DUMP_SHEET_HEADER_VALUES);
exports.storeData = async (req, res) => storeDataInGoogleSpreadsheet(req, res, spreadsheet.storageSheetId);
3 changes: 3 additions & 0 deletions src/hooks/offramp/useSEP24/useAnchorWindowHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { showToast, ToastMessage } from '../../../helpers/notifications';

import { UseSEP24StateReturn } from './useSEP24State';
import { useTrackSEP24Events } from './useTrackSEP24Events';
import { useVortexAccount } from '../../useVortexAccount';

const handleAmountMismatch = (setOfframpingStarted: (started: boolean) => void): void => {
setOfframpingStarted(false);
Expand All @@ -25,6 +26,7 @@ const handleError = (error: unknown, setOfframpingStarted: (started: boolean) =>
export const useAnchorWindowHandler = (sep24State: UseSEP24StateReturn, cleanupFn: () => void) => {
const { trackKYCStarted, trackKYCCompleted } = useTrackSEP24Events();
const { firstSep24Response, anchorSessionParams, executionInput } = sep24State;
const { address } = useVortexAccount();

return useCallback(
async (
Expand Down Expand Up @@ -58,6 +60,7 @@ export const useAnchorWindowHandler = (sep24State: UseSEP24StateReturn, cleanupF
sepResult: secondSep24Response,
network: selectedNetwork,
pendulumNode,
offramperAddress: address!,
});

trackKYCCompleted(initialState, selectedNetwork);
Expand Down
4 changes: 4 additions & 0 deletions src/services/offrampingFlow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export interface InitiateStateArguments {
sepResult: SepResult;
network: Networks;
pendulumNode: { ss58Format: number; api: ApiPromise; decimals: number };
offramperAddress: string;
}

export interface OfframpingState {
Expand Down Expand Up @@ -118,6 +119,7 @@ export interface OfframpingState {
nablaSwapTransaction: string;
};
network: Networks;
offramperAddress: string;
}

export type StateTransitionFunction = (
Expand Down Expand Up @@ -172,6 +174,7 @@ export async function constructInitialState({
sepResult,
network,
pendulumNode,
offramperAddress,
}: InitiateStateArguments) {
const { seed: pendulumEphemeralSeed, address: pendulumEphemeralAddress } = await createPendulumEphemeralSeed(
pendulumNode,
Expand Down Expand Up @@ -216,6 +219,7 @@ export async function constructInitialState({
sepResult,
network,
pendulumEphemeralAddress,
offramperAddress,
};

storageService.set(OFFRAMPING_STATE_LOCAL_STORAGE_KEY, initialState);
Expand Down
6 changes: 1 addition & 5 deletions src/services/phases/signedTransactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,11 @@ export async function prepareTransactions(state: OfframpingState, context: Execu
const pendulumEphemeralKeypair = keyring.addFromUri(pendulumEphemeralSeed);
const pendulumEphemeralPublicKey = pendulumEphemeralKeypair.address;

// Get the Polygon account connected by the user
const polygonAccount = getAccount(context.wagmiConfig);
const polygonAddress = polygonAccount.address;

// Try to store the data in the backend
try {
const data = {
timestamp: new Date().toISOString(),
polygonAddress: polygonAddress || '',
offramperAddress: state.offramperAddress,
stellarEphemeralPublicKey,
pendulumEphemeralPublicKey,
nablaApprovalTx: transactions.nablaApproveTransaction,
Expand Down
2 changes: 1 addition & 1 deletion src/services/storage/remote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { SIGNING_SERVICE_URL } from '../../constants/constants';
// These are the headers for the Google Spreadsheet
interface DumpData {
timestamp: string;
polygonAddress: string;
offramperAddress: string;
stellarEphemeralPublicKey: string;
pendulumEphemeralPublicKey: string;
nablaApprovalTx: string;
Expand Down

0 comments on commit 8942a5d

Please sign in to comment.