@ledgerhq/coin-aptos 2.4.0-nightly.1 → 2.5.0-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 +42 -11
- package/lib/__tests__/api/craftTransaction.unit.test.js +16 -31
- package/lib/__tests__/api/craftTransaction.unit.test.js.map +1 -1
- package/lib/__tests__/api/index.integ.test.js +14 -7
- 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 +6 -3
- 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 +3 -2
- package/lib/network/client.js.map +1 -1
- package/lib/types/assets.d.ts +0 -4
- package/lib/types/assets.d.ts.map +1 -1
- package/lib-es/__tests__/api/craftTransaction.unit.test.js +16 -31
- package/lib-es/__tests__/api/craftTransaction.unit.test.js.map +1 -1
- package/lib-es/__tests__/api/index.integ.test.js +14 -7
- 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 +6 -3
- 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 +3 -2
- package/lib-es/network/client.js.map +1 -1
- package/lib-es/types/assets.d.ts +0 -4
- package/lib-es/types/assets.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/__tests__/api/craftTransaction.unit.test.ts +22 -37
- package/src/__tests__/api/index.integ.test.ts +17 -11
- package/src/__tests__/api/index.test.ts +4 -6
- package/src/__tests__/network/client.test.ts +13 -10
- package/src/api/index.ts +4 -6
- package/src/logic/craftTransaction.ts +6 -8
- package/src/network/client.ts +5 -10
- package/src/types/assets.ts +0 -5
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Aptos } from "@aptos-labs/ts-sdk";
|
|
2
|
-
import type {
|
|
3
|
-
import type { AptosAsset
|
|
2
|
+
import type { AlpacaApi } from "@ledgerhq/coin-framework/api/types";
|
|
3
|
+
import type { AptosAsset } from "../../types/assets";
|
|
4
4
|
import type { AptosConfig } from "../../config";
|
|
5
5
|
import { createApi } from "../../api";
|
|
6
6
|
import coinConfig from "../../config";
|
|
@@ -33,8 +33,7 @@ describe("createApi", () => {
|
|
|
33
33
|
});
|
|
34
34
|
|
|
35
35
|
it("should return an API object with alpaca api methods", () => {
|
|
36
|
-
const api:
|
|
37
|
-
createApi(mockAptosConfig);
|
|
36
|
+
const api: AlpacaApi<AptosAsset> = createApi(mockAptosConfig);
|
|
38
37
|
|
|
39
38
|
// Check that methods are set with what we expect
|
|
40
39
|
expect(api.broadcast).toBeDefined();
|
|
@@ -70,8 +69,7 @@ describe("lastBlock", () => {
|
|
|
70
69
|
}),
|
|
71
70
|
}));
|
|
72
71
|
|
|
73
|
-
const api:
|
|
74
|
-
createApi(mockAptosConfig);
|
|
72
|
+
const api: AlpacaApi<AptosAsset> = createApi(mockAptosConfig);
|
|
75
73
|
|
|
76
74
|
expect(await api.lastBlock()).toStrictEqual({
|
|
77
75
|
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
|
|
17
|
+
import { AptosAsset } 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";
|
|
@@ -615,19 +615,20 @@ describe("Aptos API", () => {
|
|
|
615
615
|
}));
|
|
616
616
|
|
|
617
617
|
const amount = BigInt(100);
|
|
618
|
-
const sender
|
|
618
|
+
const sender = {
|
|
619
619
|
xpub: "xpub",
|
|
620
620
|
freshAddress: "address1",
|
|
621
621
|
};
|
|
622
622
|
const recipient = "address2";
|
|
623
623
|
|
|
624
624
|
const api = new AptosAPI("aptos");
|
|
625
|
-
const transactionIntent: TransactionIntent<AptosAsset
|
|
625
|
+
const transactionIntent: TransactionIntent<AptosAsset> = {
|
|
626
626
|
asset: {
|
|
627
627
|
type: "native",
|
|
628
628
|
},
|
|
629
629
|
type: "send",
|
|
630
|
-
sender,
|
|
630
|
+
sender: sender.freshAddress,
|
|
631
|
+
senderPublicKey: sender.xpub,
|
|
631
632
|
amount,
|
|
632
633
|
recipient,
|
|
633
634
|
};
|
|
@@ -679,21 +680,22 @@ describe("Aptos API", () => {
|
|
|
679
680
|
}));
|
|
680
681
|
|
|
681
682
|
const amount = BigInt(100);
|
|
682
|
-
const sender
|
|
683
|
+
const sender = {
|
|
683
684
|
xpub: "xpub",
|
|
684
685
|
freshAddress: "address1",
|
|
685
686
|
};
|
|
686
687
|
const recipient = "address2";
|
|
687
688
|
|
|
688
689
|
const api = new AptosAPI("aptos");
|
|
689
|
-
const transactionIntent: TransactionIntent<AptosAsset
|
|
690
|
+
const transactionIntent: TransactionIntent<AptosAsset> = {
|
|
690
691
|
asset: {
|
|
691
692
|
type: "token",
|
|
692
693
|
standard: "coin",
|
|
693
694
|
contractAddress: "0x111",
|
|
694
695
|
},
|
|
695
696
|
type: "send",
|
|
696
|
-
sender,
|
|
697
|
+
sender: sender.freshAddress,
|
|
698
|
+
senderPublicKey: sender.xpub,
|
|
697
699
|
amount,
|
|
698
700
|
recipient,
|
|
699
701
|
};
|
|
@@ -744,21 +746,22 @@ describe("Aptos API", () => {
|
|
|
744
746
|
}));
|
|
745
747
|
|
|
746
748
|
const amount = BigInt(100);
|
|
747
|
-
const sender
|
|
749
|
+
const sender = {
|
|
748
750
|
xpub: "xpub",
|
|
749
751
|
freshAddress: "address1",
|
|
750
752
|
};
|
|
751
753
|
const recipient = "address2";
|
|
752
754
|
|
|
753
755
|
const api = new AptosAPI("aptos");
|
|
754
|
-
const transactionIntent: TransactionIntent<AptosAsset
|
|
756
|
+
const transactionIntent: TransactionIntent<AptosAsset> = {
|
|
755
757
|
asset: {
|
|
756
758
|
type: "token",
|
|
757
759
|
standard: "fungible_asset",
|
|
758
760
|
contractAddress: "0x111",
|
|
759
761
|
},
|
|
760
762
|
type: "send",
|
|
761
|
-
sender,
|
|
763
|
+
sender: sender.freshAddress,
|
|
764
|
+
senderPublicKey: sender.xpub,
|
|
762
765
|
amount,
|
|
763
766
|
recipient,
|
|
764
767
|
};
|
package/src/api/index.ts
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AlpacaApi } 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
|
|
5
|
+
import type { AptosAsset } 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(
|
|
12
|
-
config: AptosConfigApi,
|
|
13
|
-
): Api<AptosAsset, AptosExtra, AptosSender, AptosFeeParameters> {
|
|
11
|
+
export function createApi(config: AptosConfigApi): AlpacaApi<AptosAsset> {
|
|
14
12
|
coinConfig.setCoinConfig(() => ({ ...config, status: { type: "active" } }));
|
|
15
13
|
|
|
16
14
|
const client = new AptosAPI(config.aptosSettings);
|
|
@@ -20,7 +18,7 @@ export function createApi(
|
|
|
20
18
|
combine: (tx, signature, pubkey): string => combine(tx, signature, pubkey),
|
|
21
19
|
craftTransaction: (transactionIntent, _customFees): Promise<string> =>
|
|
22
20
|
craftTransaction(client, transactionIntent),
|
|
23
|
-
estimateFees: (transactionIntent: TransactionIntent<AptosAsset
|
|
21
|
+
estimateFees: (transactionIntent: TransactionIntent<AptosAsset>) =>
|
|
24
22
|
client.estimateFees(transactionIntent),
|
|
25
23
|
getBalance: (address): Promise<Balance<AptosAsset>[]> => getBalances(client, address),
|
|
26
24
|
lastBlock: () => client.getLastBlock(),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { TransactionIntent } from "@ledgerhq/coin-framework/lib/api/types";
|
|
2
|
-
import type { AptosAsset
|
|
2
|
+
import type { AptosAsset } 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>,
|
|
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,
|
|
23
|
+
xpub: transactionIntent.senderPublicKey,
|
|
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);
|
|
33
33
|
balance = balances?.find(
|
|
34
34
|
b => b.contractAddress.toLowerCase() === contractAddress?.toLowerCase(),
|
|
35
35
|
);
|
|
@@ -54,9 +54,7 @@ export async function craftTransaction(
|
|
|
54
54
|
return aptosTx.bcsToHex().toString();
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
function getContractAddress(
|
|
58
|
-
txIntent: TransactionIntent<AptosAsset, AptosExtra, AptosSender>,
|
|
59
|
-
): string {
|
|
57
|
+
function getContractAddress(txIntent: TransactionIntent<AptosAsset>): string {
|
|
60
58
|
if (txIntent.asset.type === "token" && isTokenType(txIntent.asset.standard)) {
|
|
61
59
|
return txIntent.asset.contractAddress;
|
|
62
60
|
}
|
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
|
|
46
|
+
import { AptosAsset } 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,10 +175,8 @@ export class AptosAPI {
|
|
|
175
175
|
};
|
|
176
176
|
}
|
|
177
177
|
|
|
178
|
-
async estimateFees(
|
|
179
|
-
transactionIntent
|
|
180
|
-
): Promise<FeeEstimation<AptosFeeParameters>> {
|
|
181
|
-
const publicKeyEd = new Ed25519PublicKey(transactionIntent.sender.xpub);
|
|
178
|
+
async estimateFees(transactionIntent: TransactionIntent<AptosAsset>): Promise<FeeEstimation> {
|
|
179
|
+
const publicKeyEd = new Ed25519PublicKey(transactionIntent?.senderPublicKey ?? "");
|
|
182
180
|
|
|
183
181
|
const txPayload: InputEntryFunctionData = {
|
|
184
182
|
function: "0x1::aptos_account::transfer_coins",
|
|
@@ -208,11 +206,7 @@ export class AptosAPI {
|
|
|
208
206
|
gasUnitPrice: DEFAULT_GAS_PRICE.toString(),
|
|
209
207
|
};
|
|
210
208
|
|
|
211
|
-
const tx = await this.generateTransaction(
|
|
212
|
-
transactionIntent.sender.freshAddress,
|
|
213
|
-
txPayload,
|
|
214
|
-
txOptions,
|
|
215
|
-
);
|
|
209
|
+
const tx = await this.generateTransaction(transactionIntent.sender, txPayload, txOptions);
|
|
216
210
|
|
|
217
211
|
const simulation = await this.simulateTransaction(publicKeyEd, tx);
|
|
218
212
|
const completedTx = simulation[0];
|
|
@@ -225,6 +219,7 @@ export class AptosAPI {
|
|
|
225
219
|
return {
|
|
226
220
|
value: BigInt(expectedGas.toString()),
|
|
227
221
|
parameters: {
|
|
222
|
+
storageLimit: BigInt(0),
|
|
228
223
|
gasLimit: BigInt(gasLimit.toString()),
|
|
229
224
|
gasPrice: BigInt(gasPrice.toString()),
|
|
230
225
|
},
|
package/src/types/assets.ts
CHANGED
|
@@ -9,11 +9,6 @@ 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
|
-
|
|
17
12
|
export type AptosFeeParameters = {
|
|
18
13
|
gasLimit: bigint;
|
|
19
14
|
gasPrice: bigint;
|