Skip to content

Commit

Permalink
Fixing lint errors and improving code syntax.
Browse files Browse the repository at this point in the history
  • Loading branch information
danilo-silva-funttastic committed Oct 18, 2023
1 parent 6e32c9b commit 836738d
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 49 deletions.
96 changes: 56 additions & 40 deletions src/connectors/kujira/kujira.convertors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -671,45 +671,55 @@ export const convertKujiraTransactionToTransaction = (
export const convertKujiraSettlementToSettlement = (
input: KujiraWithdraw,
quotations: IMap<TokenId, Price>,
marketPair: {base: any, quote: any}
market: Market
): Withdraws => {
const events = convertKujiraRawLogEventsToMapOfEvents([
{ msg_index: 'events', events: input['events'] },
]);

const nativeToken = getNotNullOrThrowError<any>(
((events.getIn(['events', 'tx', 'fee']) as string).match(/^(\d+)(.*)/))
(events.getIn(['events', 'tx', 'fee']) as string).match(/^(\d+)(.*)/)
);

const transferEventFeeAmountArray: any = events.getIn(['events', 'transfer', 'amount']);
const transferEventFeeAmountArray: any = events.getIn([
'events',
'transfer',
'amount',
]);

let tokenFees = {
"base": {
tokenId: marketPair.base.id,
feeAmount: BigNumber(0)
const tokenFees = {
base: {
tokenId: market.base.id,

Check failure on line 692 in src/connectors/kujira/kujira.convertors.ts

View workflow job for this annotation

GitHub Actions / Gateway build + unit tests

Property 'base' does not exist on type 'Market'.
feeAmount: BigNumber(0),
},
"quote": {
tokenId: marketPair.quote.id,
feeAmount: BigNumber(0)
quote: {
tokenId: market.quote.id,

Check failure on line 696 in src/connectors/kujira/kujira.convertors.ts

View workflow job for this annotation

GitHub Actions / Gateway build + unit tests

Property 'quote' does not exist on type 'Market'.
feeAmount: BigNumber(0),
},
"native": {
native: {
tokenId: nativeToken[2],
feeAmount: BigNumber(0)
feeAmount: BigNumber(0),
},
};

for (const transferEventFee of transferEventFeeAmountArray) {
const tokenIdFromFeeMatch = transferEventFee.match(/^(\d+)(.*)/);

if (tokenIdFromFeeMatch[2] == marketPair.base.id) {
tokenFees["base"].feeAmount = tokenFees["base"].feeAmount.plus(BigNumber(parseInt(tokenIdFromFeeMatch[1])));
} else if (tokenIdFromFeeMatch[2] == marketPair.quote.id) {
tokenFees["quote"].feeAmount = tokenFees["quote"].feeAmount.plus(BigNumber(parseInt(tokenIdFromFeeMatch[1])));
if (tokenIdFromFeeMatch[2] == market.base.id) {

Check failure on line 708 in src/connectors/kujira/kujira.convertors.ts

View workflow job for this annotation

GitHub Actions / Gateway build + unit tests

Property 'base' does not exist on type 'Market'.
tokenFees.base.feeAmount = tokenFees.base.feeAmount.plus(
BigNumber(parseInt(tokenIdFromFeeMatch[1]))
);
} else if (tokenIdFromFeeMatch[2] == market.quote.id) {

Check failure on line 712 in src/connectors/kujira/kujira.convertors.ts

View workflow job for this annotation

GitHub Actions / Gateway build + unit tests

Property 'quote' does not exist on type 'Market'.
tokenFees.quote.feeAmount = tokenFees.quote.feeAmount.plus(
BigNumber(parseInt(tokenIdFromFeeMatch[1]))
);
}
}

if (marketPair.base.id != nativeToken[2] && marketPair.quote.id != nativeToken[2]) {
tokenFees["native"].feeAmount = tokenFees.native.feeAmount.plus(BigNumber(parseInt(nativeToken[1])));
if (market.base.id != nativeToken[2] && market.quote.id != nativeToken[2]) {

Check failure on line 719 in src/connectors/kujira/kujira.convertors.ts

View workflow job for this annotation

GitHub Actions / Gateway build + unit tests

Property 'base' does not exist on type 'Market'.

Check failure on line 719 in src/connectors/kujira/kujira.convertors.ts

View workflow job for this annotation

GitHub Actions / Gateway build + unit tests

Property 'quote' does not exist on type 'Market'.
tokenFees.native.feeAmount = tokenFees.native.feeAmount.plus(
BigNumber(parseInt(nativeToken[1]))
);
}

const tokenWithdraw = IMap<TokenId, Withdraw>().asMutable();
Expand All @@ -722,22 +732,17 @@ export const convertKujiraSettlementToSettlement = (
},
} as Withdraws;

for (const item in tokenFees) {
let tokenFee = undefined;
if (tokenFees.hasOwnProperty(item)) {
tokenFee = tokenFees[item as keyof typeof tokenFees];
}

const denom = Denom.from(tokenFee?.tokenId);
for (const tokenFee of Object.values(tokenFees)) {
const denom = Denom.from(tokenFee.tokenId);
const token = convertKujiraTokenToToken(denom);

const amount = getNotNullOrThrowError<BigNumber>(
tokenFee?.feeAmount.multipliedBy(Math.pow(10, -denom.decimals))
tokenFee.feeAmount.multipliedBy(Math.pow(10, -denom.decimals))
);

if (amount > BigNumber(0)) {
if (amount.gt(BigNumber(0))) {
const quotation = getNotNullOrThrowError<BigNumber>(
quotations.get(token.id)
quotations.get(token.id)
);

const amountInUSD = amount.multipliedBy(quotation);
Expand All @@ -753,7 +758,7 @@ export const convertKujiraSettlementToSettlement = (
} as Withdraw);
} else {
const tokenData = getNotNullOrThrowError<any>(
tokenWithdraw.get(token.id)
tokenWithdraw.get(token.id)
);

tokenWithdraw.set(token.id, {
Expand Down Expand Up @@ -823,48 +828,59 @@ export const convertKujiraRawLogEventsToMapOfEvents = (
for (const eventLog of eventsLog) {
const bundleIndex = eventLog['msg_index'];
const events = eventLog['events'];
let transferTokenAmountArray = [];
const transferTokenAmountArray = [];

let feePayer: any = undefined;

const txEventArray = events.filter((item: any) => item.type == "tx");
const txEventArray = events.filter((item: any) => item.type == 'tx');

for (const txEvent of txEventArray) {
const txFeePayer = txEvent.attributes.find((attribute: any) => attribute.key == "fee_payer");
const txFeePayer = txEvent.attributes.find(
(attribute: any) => attribute.key == 'fee_payer'
);
if (txFeePayer != undefined && feePayer == undefined) {
feePayer = txFeePayer.value;
}
}

const transferEventArray = events.filter((item: any) => item.type == "transfer");
const transferEventArray = events.filter(
(item: any) => item.type == 'transfer'
);

for (const transferEvent of transferEventArray) {
let recipient = transferEvent.attributes.find((attribute: any) => attribute.key == "recipient");
let recipient = transferEvent.attributes.find(
(attribute: any) => attribute.key == 'recipient'
);

if (recipient != undefined) {
recipient = recipient.value;
}

if ((feePayer != recipient)) {
const transferAmounts = transferEvent.attributes.find((attribute: any) => attribute.key == "amount").value.split(",");
if (feePayer != recipient) {
const transferAmounts = transferEvent.attributes
.find((attribute: any) => attribute.key == 'amount')
.value.split(',');

for (const transferAmount of transferAmounts) {
if (transferAmount != undefined) {
transferTokenAmountArray.push(transferAmount)
transferTokenAmountArray.push(transferAmount);
}
}
}
}

for (const event of events) {
if (event.type != "transfer") {
if (event.type != 'transfer') {
for (const attribute of event.attributes) {
output.setIn([bundleIndex, event.type, attribute.key], attribute.value);
output.setIn(
[bundleIndex, event.type, attribute.key],
attribute.value
);
}
}
}

output.setIn([bundleIndex, "transfer", "amount"], transferTokenAmountArray);
output.setIn([bundleIndex, 'transfer', 'amount'], transferTokenAmountArray);
}

return output;
Expand Down
10 changes: 1 addition & 9 deletions src/connectors/kujira/kujira.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1850,17 +1850,9 @@ export class Kujira {

const quotations = await this.getAllTokensQuotationsInUSD({});

const marketPair = await this.getMarket({id: options.marketId});
output.set(
ownerAddress,
convertKujiraSettlementToSettlement(
result,
quotations,
{
base: marketPair.baseToken,
quote: marketPair.quoteToken
}
)
convertKujiraSettlementToSettlement(result, quotations, market)
);
}

Expand Down

0 comments on commit 836738d

Please sign in to comment.