@ledgerhq/coin-aptos 2.1.0-nightly.2 → 2.1.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 +54 -12
- package/jest.config.js +5 -2
- 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 +7 -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 { TokenCurrency } from "@ledgerhq/types-cryptoassets";
|
|
20
20
|
import { APTOS_ASSET_ID } from "../../constants";
|
|
@@ -612,20 +612,19 @@ describe("Aptos API", () => {
|
|
|
612
612
|
}));
|
|
613
613
|
|
|
614
614
|
const amount = BigInt(100);
|
|
615
|
-
const sender = {
|
|
615
|
+
const sender: AptosSender = {
|
|
616
616
|
xpub: "xpub",
|
|
617
617
|
freshAddress: "address1",
|
|
618
618
|
};
|
|
619
619
|
const recipient = "address2";
|
|
620
620
|
|
|
621
621
|
const api = new AptosAPI("aptos");
|
|
622
|
-
const transactionIntent: TransactionIntent<AptosAsset> = {
|
|
622
|
+
const transactionIntent: TransactionIntent<AptosAsset, AptosExtra, AptosSender> = {
|
|
623
623
|
asset: {
|
|
624
624
|
type: "native",
|
|
625
625
|
},
|
|
626
626
|
type: "send",
|
|
627
|
-
sender
|
|
628
|
-
senderPublicKey: sender.xpub,
|
|
627
|
+
sender,
|
|
629
628
|
amount,
|
|
630
629
|
recipient,
|
|
631
630
|
};
|
|
@@ -677,22 +676,21 @@ describe("Aptos API", () => {
|
|
|
677
676
|
}));
|
|
678
677
|
|
|
679
678
|
const amount = BigInt(100);
|
|
680
|
-
const sender = {
|
|
679
|
+
const sender: AptosSender = {
|
|
681
680
|
xpub: "xpub",
|
|
682
681
|
freshAddress: "address1",
|
|
683
682
|
};
|
|
684
683
|
const recipient = "address2";
|
|
685
684
|
|
|
686
685
|
const api = new AptosAPI("aptos");
|
|
687
|
-
const transactionIntent: TransactionIntent<AptosAsset> = {
|
|
686
|
+
const transactionIntent: TransactionIntent<AptosAsset, AptosExtra, AptosSender> = {
|
|
688
687
|
asset: {
|
|
689
688
|
type: "token",
|
|
690
689
|
standard: "coin",
|
|
691
690
|
contractAddress: "0x111",
|
|
692
691
|
},
|
|
693
692
|
type: "send",
|
|
694
|
-
sender
|
|
695
|
-
senderPublicKey: sender.xpub,
|
|
693
|
+
sender,
|
|
696
694
|
amount,
|
|
697
695
|
recipient,
|
|
698
696
|
};
|
|
@@ -743,22 +741,21 @@ describe("Aptos API", () => {
|
|
|
743
741
|
}));
|
|
744
742
|
|
|
745
743
|
const amount = BigInt(100);
|
|
746
|
-
const sender = {
|
|
744
|
+
const sender: AptosSender = {
|
|
747
745
|
xpub: "xpub",
|
|
748
746
|
freshAddress: "address1",
|
|
749
747
|
};
|
|
750
748
|
const recipient = "address2";
|
|
751
749
|
|
|
752
750
|
const api = new AptosAPI("aptos");
|
|
753
|
-
const transactionIntent: TransactionIntent<AptosAsset> = {
|
|
751
|
+
const transactionIntent: TransactionIntent<AptosAsset, AptosExtra, AptosSender> = {
|
|
754
752
|
asset: {
|
|
755
753
|
type: "token",
|
|
756
754
|
standard: "fungible_asset",
|
|
757
755
|
contractAddress: "0x111",
|
|
758
756
|
},
|
|
759
757
|
type: "send",
|
|
760
|
-
sender
|
|
761
|
-
senderPublicKey: sender.xpub,
|
|
758
|
+
sender,
|
|
762
759
|
amount,
|
|
763
760
|
recipient,
|
|
764
761
|
};
|
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 { getBalance } from "../logic/getBalance";
|
|
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>[]> => getBalance(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
|
@@ -44,7 +44,7 @@ import {
|
|
|
44
44
|
Pagination,
|
|
45
45
|
TransactionIntent,
|
|
46
46
|
} from "@ledgerhq/coin-framework/api/types";
|
|
47
|
-
import { AptosAsset } from "../types/assets";
|
|
47
|
+
import { AptosAsset, AptosExtra, AptosFeeParameters, AptosSender } from "../types/assets";
|
|
48
48
|
import { log } from "@ledgerhq/logs";
|
|
49
49
|
import { transactionsToOperations } from "../logic/transactionsToOperations";
|
|
50
50
|
import { isTestnet } from "../logic/isTestnet";
|
|
@@ -223,8 +223,10 @@ export class AptosAPI {
|
|
|
223
223
|
}
|
|
224
224
|
}
|
|
225
225
|
|
|
226
|
-
async estimateFees(
|
|
227
|
-
|
|
226
|
+
async estimateFees(
|
|
227
|
+
transactionIntent: TransactionIntent<AptosAsset, AptosExtra, AptosSender>,
|
|
228
|
+
): Promise<FeeEstimation<AptosFeeParameters>> {
|
|
229
|
+
const publicKeyEd = new Ed25519PublicKey(transactionIntent.sender.xpub);
|
|
228
230
|
|
|
229
231
|
const txPayload: InputEntryFunctionData = {
|
|
230
232
|
function: "0x1::aptos_account::transfer_coins",
|
|
@@ -254,7 +256,11 @@ export class AptosAPI {
|
|
|
254
256
|
gasUnitPrice: DEFAULT_GAS_PRICE.toString(),
|
|
255
257
|
};
|
|
256
258
|
|
|
257
|
-
const tx = await this.generateTransaction(
|
|
259
|
+
const tx = await this.generateTransaction(
|
|
260
|
+
transactionIntent.sender.freshAddress,
|
|
261
|
+
txPayload,
|
|
262
|
+
txOptions,
|
|
263
|
+
);
|
|
258
264
|
|
|
259
265
|
const simulation = await this.simulateTransaction(publicKeyEd, tx);
|
|
260
266
|
const completedTx = simulation[0];
|
|
@@ -267,7 +273,6 @@ export class AptosAPI {
|
|
|
267
273
|
return {
|
|
268
274
|
value: BigInt(expectedGas.toString()),
|
|
269
275
|
parameters: {
|
|
270
|
-
storageLimit: BigInt(0),
|
|
271
276
|
gasLimit: BigInt(gasLimit.toString()),
|
|
272
277
|
gasPrice: BigInt(gasPrice.toString()),
|
|
273
278
|
},
|
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;
|