Skip to content

Commit 4f6c089

Browse files
committed
fix: transaction history with token fees
1 parent b588dfe commit 4f6c089

File tree

3 files changed

+16
-39
lines changed

3 files changed

+16
-39
lines changed

libs/coin-modules/coin-aptos/src/__tests__/bridge/logic.test.ts

+8-12
Original file line numberDiff line numberDiff line change
@@ -792,52 +792,48 @@ describe("Aptos sync logic ", () => {
792792
it("should calculate the correct amount when the address is the sender", () => {
793793
const address = "0x11";
794794
const sender = "0x11";
795-
const fee = new BigNumber(10); // account pays fees
796795
const amount_in = new BigNumber(50);
797796
const amount_out = new BigNumber(100);
798797

799-
const result = calculateAmount(sender, address, [APTOS_ASSET_ID], fee, amount_in, amount_out);
798+
const result = calculateAmount(sender, address, amount_in, amount_out);
800799

801800
// LL negates the amount for SEND transactions during output
802-
expect(result).toEqual(new BigNumber(60)); // -(50 - 100 - 10)
801+
expect(result).toEqual(new BigNumber(50)); // -(50 - 100 - 10)
803802
});
804803

805804
it("should calculate the correct amount when the address is not the sender", () => {
806805
const address = "0x11";
807806
const sender = "0x12";
808-
const fee = new BigNumber(10); // sender pays fees
809807
const amount_in = new BigNumber(100);
810808
const amount_out = new BigNumber(50);
811809

812-
const result = calculateAmount(sender, address, [APTOS_ASSET_ID], fee, amount_in, amount_out);
810+
const result = calculateAmount(sender, address, amount_in, amount_out);
813811

814812
expect(result).toEqual(new BigNumber(50)); // 100 - 50
815813
});
816814

817815
it("should handle transactions with zero amounts", () => {
818816
const address = "0x11";
819817
const sender = "0x11";
820-
const fee = new BigNumber(10);
821818
const amount_in = new BigNumber(0);
822819
const amount_out = new BigNumber(0);
823820

824-
const result = calculateAmount(sender, address, [APTOS_ASSET_ID], fee, amount_in, amount_out);
821+
const result = calculateAmount(sender, address, amount_in, amount_out);
825822

826823
// LL negates the amount for SEND transactions during output
827-
expect(result).toEqual(new BigNumber(10)); // -(0 - 0 - 10)
824+
expect(result).toEqual(new BigNumber(0)); // -(0 - 0 - 10)
828825
});
829826

830827
it("should get negative numbers (for send tx with deposit to account)", () => {
831828
const address = "0x11";
832829
const sender = "0x11";
833-
const fee = new BigNumber(10);
834830
const amount_in = new BigNumber(100);
835831
const amount_out = new BigNumber(0);
836832

837-
const result = calculateAmount(sender, address, [APTOS_ASSET_ID], fee, amount_in, amount_out);
833+
const result = calculateAmount(sender, address, amount_in, amount_out);
838834

839835
// LL negates the amount for SEND transactions during output
840-
expect(result).toEqual(new BigNumber(90).negated()); // 100 - 10
836+
expect(result).toEqual(new BigNumber(100).negated()); // 100 - 10
841837
});
842838
});
843839

@@ -919,7 +915,7 @@ describe("Aptos sync logic ", () => {
919915
id: expect.any(String),
920916
hash: "0x123",
921917
type: DIRECTION.OUT,
922-
value: new BigNumber(20100),
918+
value: new BigNumber(100),
923919
fee: new BigNumber(20000),
924920
blockHash: "0xabc",
925921
blockHeight: 1,

libs/coin-modules/coin-aptos/src/__tests__/bridge/synchronisation.test.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ describe("getAccountShape", () => {
8989
expect(account.xpub).toEqual("address");
9090
expect(mockedEncodeAccountId).toHaveBeenCalledTimes(1);
9191
expect(mockedAptosAPI).toHaveBeenCalledTimes(1);
92-
expect(mockGetAccountSpy).toHaveBeenCalledWith("address", undefined);
92+
expect(mockGetAccountSpy).toHaveBeenCalledWith("address");
9393
});
9494

9595
it("account without xpub", async () => {
@@ -140,7 +140,7 @@ describe("getAccountShape", () => {
140140
expect(account.xpub).toEqual("1");
141141
expect(mockedEncodeAccountId).toHaveBeenCalledTimes(1);
142142
expect(mockedAptosAPI).toHaveBeenCalledTimes(1);
143-
expect(mockGetAccountSpy).toHaveBeenCalledWith("address", undefined);
143+
expect(mockGetAccountSpy).toHaveBeenCalledWith("address");
144144
});
145145

146146
it("without initialAccount", async () => {
@@ -171,7 +171,7 @@ describe("getAccountShape", () => {
171171
expect(account.xpub).toEqual("");
172172
expect(mockedEncodeAccountId).toHaveBeenCalledTimes(1);
173173
expect(mockedAptosAPI).toHaveBeenCalledTimes(1);
174-
expect(mockGetAccountSpy).toHaveBeenCalledWith("address", undefined);
174+
expect(mockGetAccountSpy).toHaveBeenCalledWith("address");
175175
});
176176

177177
it("initialAccount with operations", async () => {
@@ -236,7 +236,7 @@ describe("getAccountShape", () => {
236236
expect(account.xpub).toEqual("1");
237237
expect(mockedEncodeAccountId).toHaveBeenCalledTimes(1);
238238
expect(mockedAptosAPI).toHaveBeenCalledTimes(1);
239-
expect(mockGetAccountSpy).toHaveBeenCalledWith("address", undefined);
239+
expect(mockGetAccountSpy).toHaveBeenCalledWith("address");
240240
});
241241

242242
it("initialAccount with operations with extra", async () => {
@@ -302,7 +302,7 @@ describe("getAccountShape", () => {
302302
expect(account.xpub).toEqual("1");
303303
expect(mockedEncodeAccountId).toHaveBeenCalledTimes(1);
304304
expect(mockedAptosAPI).toHaveBeenCalledTimes(1);
305-
expect(mockGetAccountSpy).toHaveBeenCalledWith("address", 1);
305+
expect(mockGetAccountSpy).toHaveBeenCalledWith("address");
306306
});
307307

308308
it("get publicKey from rest", async () => {
@@ -369,6 +369,6 @@ describe("getAccountShape", () => {
369369
expect(account.xpub).toEqual("restPublicKey");
370370
expect(mockedEncodeAccountId).toHaveBeenCalledTimes(1);
371371
expect(mockedAptosAPI).toHaveBeenCalledTimes(1);
372-
expect(mockGetAccountSpy).toHaveBeenCalledWith("address", 1);
372+
expect(mockGetAccountSpy).toHaveBeenCalledWith("address");
373373
});
374374
});

libs/coin-modules/coin-aptos/src/bridge/logic.ts

+2-21
Original file line numberDiff line numberDiff line change
@@ -134,17 +134,11 @@ export const txsToOps = (
134134
}
135135

136136
const { coin_id, amount_in, amount_out } = getCoinAndAmounts(tx, address);
137-
op.value = calculateAmount(
138-
tx.sender,
139-
address,
140-
(tx.payload as EntryFunctionPayloadResponse).type_arguments,
141-
op.fee,
142-
amount_in,
143-
amount_out,
144-
);
137+
op.value = calculateAmount(tx.sender, address, amount_in, amount_out);
145138
op.type = compareAddress(tx.sender, address) ? DIRECTION.OUT : DIRECTION.IN;
146139
op.senders.push(tx.sender);
147140
op.hasFailed = !tx.success;
141+
op.id = encodeOperationId(op.accountId, tx.hash, op.type);
148142

149143
processRecipients(payload, address, op, function_address);
150144

@@ -157,14 +151,11 @@ export const txsToOps = (
157151
if (coin_id === null) {
158152
return;
159153
} else if (coin_id === APTOS_ASSET_ID) {
160-
// if (!tx.success) ops.push({ ...op, type: "FEES" });
161-
// else
162154
ops.push(op);
163155
} else {
164156
const token = findTokenByAddressInCurrency(coin_id.toLowerCase(), "aptos");
165157
if (token !== undefined) {
166158
op.accountId = encodeTokenAccountId(id, token);
167-
op.id = encodeOperationId(op.accountId, tx.hash, op.type);
168159
opsTokens.push(op);
169160

170161
if (op.type === DIRECTION.OUT) {
@@ -349,10 +340,6 @@ export function getCoinAndAmounts(
349340
let amount_in = BigNumber(0);
350341
let amount_out = BigNumber(0);
351342

352-
if (tx.hash === "0x75d05b1a9bf29c414101923dfeaba19f53a146ff9e56b08412106a73a21842b1") {
353-
console.log("ya");
354-
}
355-
356343
// collect all events related to the address and calculate the overall amounts
357344
tx.events.forEach(event => {
358345
switch (event.type) {
@@ -404,16 +391,10 @@ export function getCoinAndAmounts(
404391
export function calculateAmount(
405392
sender: string,
406393
address: string,
407-
type_arguments: string[],
408-
fee: BigNumber,
409394
amount_in: BigNumber,
410395
amount_out: BigNumber,
411396
): BigNumber {
412397
const is_sender: boolean = compareAddress(sender, address);
413-
// Include fees if our address is the sender
414-
if (is_sender && type_arguments.includes(APTOS_ASSET_ID)) {
415-
amount_out = amount_out.plus(fee);
416-
}
417398
// LL negates the amount for SEND transactions
418399
// to show positive amount on the send transaction (ex: in "cancel" tx, when amount will be returned to our account)
419400
// we need to make it negative

0 commit comments

Comments
 (0)