@ledgerhq/coin-aptos 2.2.0-nightly.3 → 2.2.1-nightly.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +32 -20
- package/lib/__tests__/api/craftTransaction.unit.test.js +31 -16
- package/lib/__tests__/api/craftTransaction.unit.test.js.map +1 -1
- package/lib/__tests__/api/index.integ.test.js +7 -14
- package/lib/__tests__/api/index.integ.test.js.map +1 -1
- package/lib/__tests__/api/index.test.js.map +1 -1
- package/lib/__tests__/network/client.test.js +3 -6
- package/lib/__tests__/network/client.test.js.map +1 -1
- package/lib/api/index.d.ts +3 -3
- package/lib/api/index.d.ts.map +1 -1
- package/lib/api/index.js.map +1 -1
- package/lib/logic/craftTransaction.d.ts +2 -2
- package/lib/logic/craftTransaction.d.ts.map +1 -1
- package/lib/logic/craftTransaction.js +3 -3
- package/lib/logic/craftTransaction.js.map +1 -1
- package/lib/network/client.d.ts +2 -2
- package/lib/network/client.d.ts.map +1 -1
- package/lib/network/client.js +2 -3
- package/lib/network/client.js.map +1 -1
- package/lib/types/assets.d.ts +4 -0
- package/lib/types/assets.d.ts.map +1 -1
- package/lib-es/__tests__/api/craftTransaction.unit.test.js +31 -16
- package/lib-es/__tests__/api/craftTransaction.unit.test.js.map +1 -1
- package/lib-es/__tests__/api/index.integ.test.js +7 -14
- package/lib-es/__tests__/api/index.integ.test.js.map +1 -1
- package/lib-es/__tests__/api/index.test.js.map +1 -1
- package/lib-es/__tests__/network/client.test.js +3 -6
- package/lib-es/__tests__/network/client.test.js.map +1 -1
- package/lib-es/api/index.d.ts +3 -3
- package/lib-es/api/index.d.ts.map +1 -1
- package/lib-es/api/index.js.map +1 -1
- package/lib-es/logic/craftTransaction.d.ts +2 -2
- package/lib-es/logic/craftTransaction.d.ts.map +1 -1
- package/lib-es/logic/craftTransaction.js +3 -3
- package/lib-es/logic/craftTransaction.js.map +1 -1
- package/lib-es/network/client.d.ts +2 -2
- package/lib-es/network/client.d.ts.map +1 -1
- package/lib-es/network/client.js +2 -3
- package/lib-es/network/client.js.map +1 -1
- package/lib-es/types/assets.d.ts +4 -0
- package/lib-es/types/assets.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/__tests__/api/craftTransaction.unit.test.ts +37 -22
- package/src/__tests__/api/index.integ.test.ts +11 -17
- package/src/__tests__/api/index.test.ts +6 -4
- package/src/__tests__/network/client.test.ts +10 -13
- package/src/api/index.ts +6 -4
- package/src/logic/craftTransaction.ts +8 -6
- package/src/network/client.ts +10 -5
- package/src/types/assets.ts +5 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Aptos } from "@aptos-labs/ts-sdk";
|
|
2
|
-
import type {
|
|
3
|
-
import type { AptosAsset } from "../../types/assets";
|
|
2
|
+
import type { Api } from "@ledgerhq/coin-framework/api/types";
|
|
3
|
+
import type { AptosAsset, AptosExtra, AptosFeeParameters, AptosSender } from "../../types/assets";
|
|
4
4
|
import type { AptosConfig } from "../../config";
|
|
5
5
|
import { createApi } from "../../api";
|
|
6
6
|
import coinConfig from "../../config";
|
|
@@ -33,7 +33,8 @@ describe("createApi", () => {
|
|
|
33
33
|
});
|
|
34
34
|
|
|
35
35
|
it("should return an API object with alpaca api methods", () => {
|
|
36
|
-
const api:
|
|
36
|
+
const api: Api<AptosAsset, AptosExtra, AptosSender, AptosFeeParameters> =
|
|
37
|
+
createApi(mockAptosConfig);
|
|
37
38
|
|
|
38
39
|
// Check that methods are set with what we expect
|
|
39
40
|
expect(api.broadcast).toBeDefined();
|
|
@@ -69,7 +70,8 @@ describe("lastBlock", () => {
|
|
|
69
70
|
}),
|
|
70
71
|
}));
|
|
71
72
|
|
|
72
|
-
const api:
|
|
73
|
+
const api: Api<AptosAsset, AptosExtra, AptosSender, AptosFeeParameters> =
|
|
74
|
+
createApi(mockAptosConfig);
|
|
73
75
|
|
|
74
76
|
expect(await api.lastBlock()).toStrictEqual({
|
|
75
77
|
height: 123,
|
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
import network from "@ledgerhq/live-network";
|
|
15
15
|
import BigNumber from "bignumber.js";
|
|
16
16
|
import { AptosAPI } from "../../network";
|
|
17
|
-
import { AptosAsset } from "../../types/assets";
|
|
17
|
+
import { AptosAsset, AptosExtra, AptosSender } from "../../types/assets";
|
|
18
18
|
import { Pagination, TransactionIntent } from "@ledgerhq/coin-framework/api/types";
|
|
19
19
|
import { APTOS_ASSET_ID } from "../../constants";
|
|
20
20
|
import { AptosBalance, AptosTransaction } from "../../types";
|
|
@@ -559,20 +559,19 @@ describe("Aptos API", () => {
|
|
|
559
559
|
}));
|
|
560
560
|
|
|
561
561
|
const amount = BigInt(100);
|
|
562
|
-
const sender = {
|
|
562
|
+
const sender: AptosSender = {
|
|
563
563
|
xpub: "xpub",
|
|
564
564
|
freshAddress: "address1",
|
|
565
565
|
};
|
|
566
566
|
const recipient = "address2";
|
|
567
567
|
|
|
568
568
|
const api = new AptosAPI("aptos");
|
|
569
|
-
const transactionIntent: TransactionIntent<AptosAsset> = {
|
|
569
|
+
const transactionIntent: TransactionIntent<AptosAsset, AptosExtra, AptosSender> = {
|
|
570
570
|
asset: {
|
|
571
571
|
type: "native",
|
|
572
572
|
},
|
|
573
573
|
type: "send",
|
|
574
|
-
sender
|
|
575
|
-
senderPublicKey: sender.xpub,
|
|
574
|
+
sender,
|
|
576
575
|
amount,
|
|
577
576
|
recipient,
|
|
578
577
|
};
|
|
@@ -624,22 +623,21 @@ describe("Aptos API", () => {
|
|
|
624
623
|
}));
|
|
625
624
|
|
|
626
625
|
const amount = BigInt(100);
|
|
627
|
-
const sender = {
|
|
626
|
+
const sender: AptosSender = {
|
|
628
627
|
xpub: "xpub",
|
|
629
628
|
freshAddress: "address1",
|
|
630
629
|
};
|
|
631
630
|
const recipient = "address2";
|
|
632
631
|
|
|
633
632
|
const api = new AptosAPI("aptos");
|
|
634
|
-
const transactionIntent: TransactionIntent<AptosAsset> = {
|
|
633
|
+
const transactionIntent: TransactionIntent<AptosAsset, AptosExtra, AptosSender> = {
|
|
635
634
|
asset: {
|
|
636
635
|
type: "token",
|
|
637
636
|
standard: "coin",
|
|
638
637
|
contractAddress: "0x111",
|
|
639
638
|
},
|
|
640
639
|
type: "send",
|
|
641
|
-
sender
|
|
642
|
-
senderPublicKey: sender.xpub,
|
|
640
|
+
sender,
|
|
643
641
|
amount,
|
|
644
642
|
recipient,
|
|
645
643
|
};
|
|
@@ -690,22 +688,21 @@ describe("Aptos API", () => {
|
|
|
690
688
|
}));
|
|
691
689
|
|
|
692
690
|
const amount = BigInt(100);
|
|
693
|
-
const sender = {
|
|
691
|
+
const sender: AptosSender = {
|
|
694
692
|
xpub: "xpub",
|
|
695
693
|
freshAddress: "address1",
|
|
696
694
|
};
|
|
697
695
|
const recipient = "address2";
|
|
698
696
|
|
|
699
697
|
const api = new AptosAPI("aptos");
|
|
700
|
-
const transactionIntent: TransactionIntent<AptosAsset> = {
|
|
698
|
+
const transactionIntent: TransactionIntent<AptosAsset, AptosExtra, AptosSender> = {
|
|
701
699
|
asset: {
|
|
702
700
|
type: "token",
|
|
703
701
|
standard: "fungible_asset",
|
|
704
702
|
contractAddress: "0x111",
|
|
705
703
|
},
|
|
706
704
|
type: "send",
|
|
707
|
-
sender
|
|
708
|
-
senderPublicKey: sender.xpub,
|
|
705
|
+
sender,
|
|
709
706
|
amount,
|
|
710
707
|
recipient,
|
|
711
708
|
};
|
package/src/api/index.ts
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Api } from "@ledgerhq/coin-framework/api/index";
|
|
2
2
|
import type { AptosConfig as AptosConfigApi } from "../config";
|
|
3
3
|
import type { Balance, Pagination, TransactionIntent } from "@ledgerhq/coin-framework/api/types";
|
|
4
4
|
import coinConfig from "../config";
|
|
5
|
-
import type { AptosAsset } from "../types/assets";
|
|
5
|
+
import type { AptosAsset, AptosExtra, AptosFeeParameters, AptosSender } from "../types/assets";
|
|
6
6
|
import { AptosAPI } from "../network";
|
|
7
7
|
import { combine } from "../logic/combine";
|
|
8
8
|
import { craftTransaction } from "../logic/craftTransaction";
|
|
9
9
|
import { getBalances } from "../logic/getBalances";
|
|
10
10
|
|
|
11
|
-
export function createApi(
|
|
11
|
+
export function createApi(
|
|
12
|
+
config: AptosConfigApi,
|
|
13
|
+
): Api<AptosAsset, AptosExtra, AptosSender, AptosFeeParameters> {
|
|
12
14
|
coinConfig.setCoinConfig(() => ({ ...config, status: { type: "active" } }));
|
|
13
15
|
|
|
14
16
|
const client = new AptosAPI(config.aptosSettings);
|
|
@@ -18,7 +20,7 @@ export function createApi(config: AptosConfigApi): AlpacaApi<AptosAsset> {
|
|
|
18
20
|
combine: (tx, signature, pubkey): string => combine(tx, signature, pubkey),
|
|
19
21
|
craftTransaction: (transactionIntent, _customFees): Promise<string> =>
|
|
20
22
|
craftTransaction(client, transactionIntent),
|
|
21
|
-
estimateFees: (transactionIntent: TransactionIntent<AptosAsset>) =>
|
|
23
|
+
estimateFees: (transactionIntent: TransactionIntent<AptosAsset, AptosExtra, AptosSender>) =>
|
|
22
24
|
client.estimateFees(transactionIntent),
|
|
23
25
|
getBalance: (address): Promise<Balance<AptosAsset>[]> => getBalances(client, address),
|
|
24
26
|
lastBlock: () => client.getLastBlock(),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { TransactionIntent } from "@ledgerhq/coin-framework/lib/api/types";
|
|
2
|
-
import type { AptosAsset } from "../types/assets";
|
|
2
|
+
import type { AptosAsset, AptosExtra, AptosSender } from "../types/assets";
|
|
3
3
|
import type { Account, TokenAccount } from "@ledgerhq/types-live";
|
|
4
4
|
import type { AptosAPI } from "../network";
|
|
5
5
|
import buildTransaction, { isTokenType } from "./buildTransaction";
|
|
@@ -10,7 +10,7 @@ import type { AptosBalance } from "../types";
|
|
|
10
10
|
|
|
11
11
|
export async function craftTransaction(
|
|
12
12
|
aptosClient: AptosAPI,
|
|
13
|
-
transactionIntent: TransactionIntent<AptosAsset>,
|
|
13
|
+
transactionIntent: TransactionIntent<AptosAsset, AptosExtra, AptosSender>,
|
|
14
14
|
): Promise<string> {
|
|
15
15
|
const newTx = createTransaction();
|
|
16
16
|
newTx.amount = BigNumber(transactionIntent.amount.toString());
|
|
@@ -19,8 +19,8 @@ export async function craftTransaction(
|
|
|
19
19
|
newTx.useAllAmount = transactionIntent.amount === BigInt(0);
|
|
20
20
|
|
|
21
21
|
const account = {
|
|
22
|
-
freshAddress: transactionIntent.sender,
|
|
23
|
-
xpub: transactionIntent.
|
|
22
|
+
freshAddress: transactionIntent.sender.freshAddress,
|
|
23
|
+
xpub: transactionIntent.sender.xpub,
|
|
24
24
|
subAccounts: new Array<TokenAccount>(),
|
|
25
25
|
} as Account;
|
|
26
26
|
|
|
@@ -29,7 +29,7 @@ export async function craftTransaction(
|
|
|
29
29
|
let balance: AptosBalance | undefined;
|
|
30
30
|
|
|
31
31
|
if (newTx.useAllAmount === true) {
|
|
32
|
-
const balances = await aptosClient.getBalances(transactionIntent.sender);
|
|
32
|
+
const balances = await aptosClient.getBalances(transactionIntent.sender.freshAddress);
|
|
33
33
|
balance = balances?.find(
|
|
34
34
|
b => b.contractAddress.toLowerCase() === contractAddress?.toLowerCase(),
|
|
35
35
|
);
|
|
@@ -54,7 +54,9 @@ export async function craftTransaction(
|
|
|
54
54
|
return aptosTx.bcsToHex().toString();
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
function getContractAddress(
|
|
57
|
+
function getContractAddress(
|
|
58
|
+
txIntent: TransactionIntent<AptosAsset, AptosExtra, AptosSender>,
|
|
59
|
+
): string {
|
|
58
60
|
if (txIntent.asset.type === "token" && isTokenType(txIntent.asset.standard)) {
|
|
59
61
|
return txIntent.asset.contractAddress;
|
|
60
62
|
}
|
package/src/network/client.ts
CHANGED
|
@@ -43,7 +43,7 @@ import {
|
|
|
43
43
|
Pagination,
|
|
44
44
|
TransactionIntent,
|
|
45
45
|
} from "@ledgerhq/coin-framework/api/types";
|
|
46
|
-
import { AptosAsset } from "../types/assets";
|
|
46
|
+
import { AptosAsset, AptosExtra, AptosFeeParameters, AptosSender } from "../types/assets";
|
|
47
47
|
import { log } from "@ledgerhq/logs";
|
|
48
48
|
import { transactionsToOperations } from "../logic/transactionsToOperations";
|
|
49
49
|
import { isTestnet } from "../logic/isTestnet";
|
|
@@ -175,8 +175,10 @@ export class AptosAPI {
|
|
|
175
175
|
};
|
|
176
176
|
}
|
|
177
177
|
|
|
178
|
-
async estimateFees(
|
|
179
|
-
|
|
178
|
+
async estimateFees(
|
|
179
|
+
transactionIntent: TransactionIntent<AptosAsset, AptosExtra, AptosSender>,
|
|
180
|
+
): Promise<FeeEstimation<AptosFeeParameters>> {
|
|
181
|
+
const publicKeyEd = new Ed25519PublicKey(transactionIntent.sender.xpub);
|
|
180
182
|
|
|
181
183
|
const txPayload: InputEntryFunctionData = {
|
|
182
184
|
function: "0x1::aptos_account::transfer_coins",
|
|
@@ -206,7 +208,11 @@ export class AptosAPI {
|
|
|
206
208
|
gasUnitPrice: DEFAULT_GAS_PRICE.toString(),
|
|
207
209
|
};
|
|
208
210
|
|
|
209
|
-
const tx = await this.generateTransaction(
|
|
211
|
+
const tx = await this.generateTransaction(
|
|
212
|
+
transactionIntent.sender.freshAddress,
|
|
213
|
+
txPayload,
|
|
214
|
+
txOptions,
|
|
215
|
+
);
|
|
210
216
|
|
|
211
217
|
const simulation = await this.simulateTransaction(publicKeyEd, tx);
|
|
212
218
|
const completedTx = simulation[0];
|
|
@@ -219,7 +225,6 @@ export class AptosAPI {
|
|
|
219
225
|
return {
|
|
220
226
|
value: BigInt(expectedGas.toString()),
|
|
221
227
|
parameters: {
|
|
222
|
-
storageLimit: BigInt(0),
|
|
223
228
|
gasLimit: BigInt(gasLimit.toString()),
|
|
224
229
|
gasPrice: BigInt(gasPrice.toString()),
|
|
225
230
|
},
|
package/src/types/assets.ts
CHANGED
|
@@ -9,6 +9,11 @@ export type AptosTokenInformation = {
|
|
|
9
9
|
|
|
10
10
|
export type AptosExtra = Record<string, unknown>;
|
|
11
11
|
|
|
12
|
+
export type AptosSender = {
|
|
13
|
+
xpub: string;
|
|
14
|
+
freshAddress: string;
|
|
15
|
+
};
|
|
16
|
+
|
|
12
17
|
export type AptosFeeParameters = {
|
|
13
18
|
gasLimit: bigint;
|
|
14
19
|
gasPrice: bigint;
|