Skip to content

Commit

Permalink
Merge pull request #280 from pendulum-chain/hotfix-signer-service-bug
Browse files Browse the repository at this point in the history
Fix for incorrect assetCode property
  • Loading branch information
gianfra-t authored Nov 14, 2024
2 parents 56110f4 + c80ff0e commit 4e1f8ee
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 37 deletions.
4 changes: 2 additions & 2 deletions signer-service/src/api/controllers/subsidize.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const Big = require('big.js');

const { PENDULUM_WSS, PENDULUM_FUNDING_SEED } = require('../../constants/constants');

const { TOKEN_CONFIG } = require('../../constants/tokenConfig');
const { TOKEN_CONFIG, getPaddedAssetCode } = require('../../constants/tokenConfig');

const TOKEN_TO_SWAP = 'usdc.axl';

Expand Down Expand Up @@ -49,7 +49,7 @@ exports.subsidizePostSwap = async (req, res) => {
const assetIssuerHex = `0x${Keypair.fromPublicKey(assetIssuer).rawPublicKey().toString('hex')}`;
const pendulumCurrencyId = {
Stellar: {
AlphaNum4: { code: assetCode.padEnd(4, '\0'), issuer: assetIssuerHex },
AlphaNum4: { code: getPaddedAssetCode(assetCode), issuer: assetIssuerHex },
},
};

Expand Down
6 changes: 3 additions & 3 deletions signer-service/src/api/services/stellar.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ async function buildCreationStellarTx(fundingSecret, ephemeralAccountId, maxTime
.addOperation(
Operation.changeTrust({
source: ephemeralAccountId,
asset: new Asset(tokenConfig.assetCodeStellar, tokenConfig.assetIssuer),
asset: new Asset(tokenConfig.assetCode, tokenConfig.assetIssuer),
}),
)
.setTimebounds(0, maxTime)
Expand Down Expand Up @@ -97,7 +97,7 @@ async function buildPaymentAndMergeTx(
.addOperation(
Operation.payment({
amount,
asset: new Asset(tokenConfig.assetCodeStellar, tokenConfig.assetIssuer),
asset: new Asset(tokenConfig.assetCode, tokenConfig.assetIssuer),
destination: offrampingAccount,
}),
)
Expand All @@ -111,7 +111,7 @@ async function buildPaymentAndMergeTx(
})
.addOperation(
Operation.changeTrust({
asset: new Asset(tokenConfig.assetCodeStellar, tokenConfig.assetIssuer),
asset: new Asset(tokenConfig.assetCode, tokenConfig.assetIssuer),
limit: '0',
}),
)
Expand Down
20 changes: 11 additions & 9 deletions signer-service/src/constants/tokenConfig.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
const TOKEN_CONFIG = {
eurc: {
tomlFileUrl: 'https://circle.anchor.mykobo.co/.well-known/stellar.toml',
assetCodeRaw: 'EURC',
assetCodeStellar: 'EURC',
assetCode: 'EURC',
assetIssuer: 'GDHU6WRG4IEQXM5NZ4BMPKOXHW76MZM4Y2IEMFDVXBSDP6SJY4ITNPP2',
vaultAccountId: '6bsD97dS8ZyomMmp1DLCnCtx25oABtf19dypQKdZe6FBQXSm',
minWithdrawalAmount: '10000000000000',
Expand All @@ -25,8 +24,7 @@ const TOKEN_CONFIG = {
},
ars: {
tomlFileUrl: 'https://api.anclap.com/.well-known/stellar.toml',
assetCodeRaw: 'ARS\0',
assetCodeStellar: 'ARS',
assetCode: 'ARS',
assetIssuer: 'GCYE7C77EB5AWAA25R5XMWNI2EDOKTTFTTPZKM2SR5DI4B4WFD52DARS',
vaultAccountId: '6bE2vjpLRkRNoVDqDtzokxE34QdSJC2fz7c87R9yCVFFDNWs',
minWithdrawalAmount: '11000000000000', // 11 ARS. Anchor minimum limit.
Expand All @@ -44,13 +42,17 @@ const TOKEN_CONFIG = {
},
};

function getTokenConfigByAssetCode(cofig, assetCode) {
for (const key in cofig) {
if (cofig[key].assetCode === assetCode) {
return cofig[key];
function getTokenConfigByAssetCode(config, assetCode) {
for (const key in config) {
if (config[key].assetCode === assetCode) {
return config[key];
}
}
return undefined;
}

module.exports = { TOKEN_CONFIG, getTokenConfigByAssetCode };
function getPaddedAssetCode(assetCode) {
return assetCode.padEnd(4, '\0');
}

module.exports = { TOKEN_CONFIG, getTokenConfigByAssetCode, getPaddedAssetCode };
9 changes: 3 additions & 6 deletions src/constants/tokenConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ export interface OutputTokenDetails {
stellarAsset: {
code: {
hex: string;
stringRaw: string; // stringRaw. With /0 if the Asset has less than 4 letters.
stringStellar: string;
string: string; // Stellar representation (3 or 4 letter code)
};
issuer: {
hex: string;
Expand Down Expand Up @@ -84,8 +83,7 @@ export const OUTPUT_TOKEN_CONFIG: Record<OutputTokenType, OutputTokenDetails> =
stellarAsset: {
code: {
hex: '0x45555243',
stringStellar: 'EURC',
stringRaw: 'EURC',
string: 'EURC',
},
issuer: {
hex: '0xcf4f5a26e2090bb3adcf02c7a9d73dbfe6659cc690461475b86437fa49c71136',
Expand All @@ -109,8 +107,7 @@ export const OUTPUT_TOKEN_CONFIG: Record<OutputTokenType, OutputTokenDetails> =
stellarAsset: {
code: {
hex: '0x41525300',
stringStellar: 'ARS',
stringRaw: 'ARS\0',
string: 'ARS',
},
issuer: {
hex: '0xb04f8bff207a0b001aec7b7659a8d106e54e659cdf9533528f468e079628fba1',
Expand Down
2 changes: 1 addition & 1 deletion src/contexts/events.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ export function createTransactionEvent(type: TransactionEvent['event'], state: O
return {
event: type,
from_asset: INPUT_TOKEN_CONFIG[state.inputTokenType].assetSymbol,
to_asset: OUTPUT_TOKEN_CONFIG[state.outputTokenType].stellarAsset.code.stringRaw,
to_asset: OUTPUT_TOKEN_CONFIG[state.outputTokenType].stellarAsset.code.string,
from_amount: state.inputAmount.units,
to_amount: state.outputAmount.units,
};
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useMainProcess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export const useMainProcess = () => {
trackEvent({
event: 'transaction_confirmation',
from_asset: INPUT_TOKEN_CONFIG[inputTokenType].assetSymbol,
to_asset: OUTPUT_TOKEN_CONFIG[outputTokenType].stellarAsset.code.stringRaw,
to_asset: OUTPUT_TOKEN_CONFIG[outputTokenType].stellarAsset.code.string,
from_amount: amountInUnits,
to_amount: offrampAmount.toFixed(2, 0),
});
Expand Down Expand Up @@ -197,7 +197,7 @@ export const useMainProcess = () => {
trackEvent({
event: 'kyc_started',
from_asset: INPUT_TOKEN_CONFIG[executionInputState.inputTokenType].assetSymbol,
to_asset: OUTPUT_TOKEN_CONFIG[executionInputState.outputTokenType].stellarAsset.code.stringRaw,
to_asset: OUTPUT_TOKEN_CONFIG[executionInputState.outputTokenType].stellarAsset.code.string,
from_amount: executionInputState.amountInUnits,
to_amount: executionInputState.offrampAmount.toFixed(2, 0),
});
Expand Down
4 changes: 2 additions & 2 deletions src/pages/progress/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ function createOfframpingPhaseMessage(offrampingState: OfframpingState): string
case 'nablaApprove':
case 'nablaSwap':
case 'subsidizePostSwap':
return `Swapping to ${outputToken.stellarAsset.code.stringRaw} on Vortex DEX`;
return `Swapping to ${outputToken.stellarAsset.code.string} on Vortex DEX`;
case 'executeSpacewalkRedeem':
return `Bridging ${outputToken.stellarAsset.code.stringRaw} to Stellar via Spacewalk`;
return `Bridging ${outputToken.stellarAsset.code.string} to Stellar via Spacewalk`;
case 'pendulumCleanup':
case 'stellarOfframp':
case 'stellarCleanup':
Expand Down
4 changes: 2 additions & 2 deletions src/services/anchor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,14 +216,14 @@ export async function sep24First(
throw new Error('Master must be defined at this point.');
}
sep24Params = new URLSearchParams({
asset_code: sessionParams.tokenConfig.stellarAsset.code.stringStellar,
asset_code: sessionParams.tokenConfig.stellarAsset.code.string,
amount: sessionParams.offrampAmount,
account: sep10Account, // THIS is a particularity of Anclap. Should be able to work without it, or with a different one
// to that of the sep-10
});
} else {
sep24Params = new URLSearchParams({
asset_code: sessionParams.tokenConfig.stellarAsset.code.stringStellar,
asset_code: sessionParams.tokenConfig.stellarAsset.code.string,
amount: sessionParams.offrampAmount,
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/services/nabla.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ export async function prepareNablaSwapTransaction(
// Try swap
try {
renderEvent(
`Swapping ${inputAmount.units} ${inputToken.axelarEquivalent.pendulumAssetSymbol} to ${outputAmount.units} ${outputToken.stellarAsset.code.stringRaw} `,
`Swapping ${inputAmount.units} ${inputToken.axelarEquivalent.pendulumAssetSymbol} to ${outputAmount.units} ${outputToken.stellarAsset.code.string} `,
EventStatus.Waiting,
);

Expand Down Expand Up @@ -336,7 +336,7 @@ export async function nablaSwap(state: OfframpingState, { renderEvent }: Executi

try {
renderEvent(
`Swapping ${inputAmount.units} ${inputToken.axelarEquivalent.pendulumAssetSymbol} to ${outputAmount.units} ${outputToken.stellarAsset.code.stringRaw} `,
`Swapping ${inputAmount.units} ${inputToken.axelarEquivalent.pendulumAssetSymbol} to ${outputAmount.units} ${outputToken.stellarAsset.code.string} `,
EventStatus.Waiting,
);

Expand Down
2 changes: 1 addition & 1 deletion src/services/polkadot/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ function checkBalancePeriodically(
try {
const someBalanceUnits = await getStellarBalanceUnits(
stellarTargetAccountId,
outputToken.stellarAsset.code.stringRaw,
outputToken.stellarAsset.code.string,
);
console.log(`Balance check: ${someBalanceUnits.toString()} / ${amountDesiredUnitsBig.toString()}`);

Expand Down
11 changes: 4 additions & 7 deletions src/services/stellar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ async function setupStellarAccount(
body: JSON.stringify({
accountId: ephemeralAccountId,
maxTime,
assetCode: outputToken.stellarAsset.code.stringRaw,
assetCode: outputToken.stellarAsset.code.string,
}),
});

Expand Down Expand Up @@ -142,10 +142,7 @@ async function setupStellarAccount(
.addOperation(
Operation.changeTrust({
source: ephemeralAccountId,
asset: new Asset(
outputToken.stellarAsset.code.stringStellar,
outputToken.stellarAsset.issuer.stellarEncoding,
),
asset: new Asset(outputToken.stellarAsset.code.string, outputToken.stellarAsset.issuer.stellarEncoding),
}),
)
.setTimebounds(0, maxTime)
Expand Down Expand Up @@ -195,7 +192,7 @@ async function createOfframpAndMergeTransaction(
throw new Error(`Unexpected offramp memo type: ${memoType}`);
}

const stellarAsset = new Asset(code.stringStellar, issuer.stellarEncoding);
const stellarAsset = new Asset(code.string, issuer.stellarEncoding);

// this operation would run completely in the browser
// that is where the signature of the ephemeral account is added
Expand Down Expand Up @@ -250,7 +247,7 @@ async function createOfframpAndMergeTransaction(
paymentData: sepResult,
sequence,
maxTime,
assetCode: code.stringRaw,
assetCode: code.string,
}),
});

Expand Down

0 comments on commit 4e1f8ee

Please sign in to comment.