@ledgerhq/coin-aptos 2.0.0-nightly.4 → 2.0.0-nightly.5
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 +9 -0
- package/lib/__tests__/api/index.test.js +5 -61
- package/lib/__tests__/api/index.test.js.map +1 -1
- package/lib/__tests__/bridge/buildTransaction.test.js +2 -57
- package/lib/__tests__/bridge/buildTransaction.test.js.map +1 -1
- package/lib/__tests__/bridge/getFeesForTransaction.test.js +8 -109
- package/lib/__tests__/bridge/getFeesForTransaction.test.js.map +1 -1
- package/lib/__tests__/bridge/getTransactionStatus.test.js +37 -175
- package/lib/__tests__/bridge/getTransactionStatus.test.js.map +1 -1
- package/lib/__tests__/bridge/logic.test.js +115 -889
- package/lib/__tests__/bridge/logic.test.js.map +1 -1
- package/lib/__tests__/bridge/signOperation.test.js +2 -128
- package/lib/__tests__/bridge/signOperation.test.js.map +1 -1
- package/lib/__tests__/bridge/synchronisation.test.js +67 -1214
- package/lib/__tests__/bridge/synchronisation.test.js.map +1 -1
- package/lib/api/graphql/queries.js +6 -6
- package/lib/api/graphql/types.d.ts +9 -9
- package/lib/api/graphql/types.d.ts.map +1 -1
- package/lib/api/index.d.ts +2 -5
- package/lib/api/index.d.ts.map +1 -1
- package/lib/api/index.js +4 -30
- package/lib/api/index.js.map +1 -1
- package/lib/bridge/bridge.fixture.d.ts +0 -2
- package/lib/bridge/bridge.fixture.d.ts.map +1 -1
- package/lib/bridge/bridge.fixture.js +13 -85
- package/lib/bridge/bridge.fixture.js.map +1 -1
- package/lib/bridge/buildTransaction.d.ts.map +1 -1
- package/lib/bridge/buildTransaction.js +3 -29
- package/lib/bridge/buildTransaction.js.map +1 -1
- package/lib/bridge/estimateMaxSpendable.js +1 -1
- package/lib/bridge/estimateMaxSpendable.js.map +1 -1
- package/lib/bridge/getFeesForTransaction.d.ts.map +1 -1
- package/lib/bridge/getFeesForTransaction.js +7 -12
- package/lib/bridge/getFeesForTransaction.js.map +1 -1
- package/lib/bridge/getTransactionStatus.d.ts.map +1 -1
- package/lib/bridge/getTransactionStatus.js +14 -28
- package/lib/bridge/getTransactionStatus.js.map +1 -1
- package/lib/bridge/logic.d.ts +8 -13
- package/lib/bridge/logic.d.ts.map +1 -1
- package/lib/bridge/logic.js +54 -152
- package/lib/bridge/logic.js.map +1 -1
- package/lib/bridge/prepareTransaction.d.ts.map +1 -1
- package/lib/bridge/prepareTransaction.js +2 -2
- package/lib/bridge/prepareTransaction.js.map +1 -1
- package/lib/bridge/signOperation.d.ts.map +1 -1
- package/lib/bridge/signOperation.js +3 -17
- package/lib/bridge/signOperation.js.map +1 -1
- package/lib/bridge/synchronisation.d.ts +0 -15
- package/lib/bridge/synchronisation.d.ts.map +1 -1
- package/lib/bridge/synchronisation.js +4 -127
- package/lib/bridge/synchronisation.js.map +1 -1
- package/lib/constants.d.ts +1 -5
- package/lib/constants.d.ts.map +1 -1
- package/lib/constants.js +2 -6
- package/lib/constants.js.map +1 -1
- package/lib/test/bot-specs.d.ts.map +1 -1
- package/lib/test/bot-specs.js +1 -40
- package/lib/test/bot-specs.js.map +1 -1
- package/lib/test/bridgeDatasetTest.d.ts.map +1 -1
- package/lib/test/bridgeDatasetTest.js +62 -43
- package/lib/test/bridgeDatasetTest.js.map +1 -1
- package/lib/test/speculos-deviceActions.d.ts +0 -1
- package/lib/test/speculos-deviceActions.d.ts.map +1 -1
- package/lib/test/speculos-deviceActions.js +5 -37
- package/lib/test/speculos-deviceActions.js.map +1 -1
- package/lib/types/index.d.ts +7 -18
- package/lib/types/index.d.ts.map +1 -1
- package/lib-es/__tests__/api/index.test.js +5 -61
- package/lib-es/__tests__/api/index.test.js.map +1 -1
- package/lib-es/__tests__/bridge/buildTransaction.test.js +3 -58
- package/lib-es/__tests__/bridge/buildTransaction.test.js.map +1 -1
- package/lib-es/__tests__/bridge/getFeesForTransaction.test.js +9 -110
- package/lib-es/__tests__/bridge/getFeesForTransaction.test.js.map +1 -1
- package/lib-es/__tests__/bridge/getTransactionStatus.test.js +39 -177
- package/lib-es/__tests__/bridge/getTransactionStatus.test.js.map +1 -1
- package/lib-es/__tests__/bridge/logic.test.js +117 -891
- package/lib-es/__tests__/bridge/logic.test.js.map +1 -1
- package/lib-es/__tests__/bridge/signOperation.test.js +2 -128
- package/lib-es/__tests__/bridge/signOperation.test.js.map +1 -1
- package/lib-es/__tests__/bridge/synchronisation.test.js +69 -1213
- package/lib-es/__tests__/bridge/synchronisation.test.js.map +1 -1
- package/lib-es/api/graphql/queries.js +6 -6
- package/lib-es/api/graphql/types.d.ts +9 -9
- package/lib-es/api/graphql/types.d.ts.map +1 -1
- package/lib-es/api/index.d.ts +2 -5
- package/lib-es/api/index.d.ts.map +1 -1
- package/lib-es/api/index.js +4 -30
- package/lib-es/api/index.js.map +1 -1
- package/lib-es/bridge/bridge.fixture.d.ts +0 -2
- package/lib-es/bridge/bridge.fixture.d.ts.map +1 -1
- package/lib-es/bridge/bridge.fixture.js +12 -82
- package/lib-es/bridge/bridge.fixture.js.map +1 -1
- package/lib-es/bridge/buildTransaction.d.ts.map +1 -1
- package/lib-es/bridge/buildTransaction.js +4 -30
- package/lib-es/bridge/buildTransaction.js.map +1 -1
- package/lib-es/bridge/estimateMaxSpendable.js +1 -1
- package/lib-es/bridge/estimateMaxSpendable.js.map +1 -1
- package/lib-es/bridge/getFeesForTransaction.d.ts.map +1 -1
- package/lib-es/bridge/getFeesForTransaction.js +8 -13
- package/lib-es/bridge/getFeesForTransaction.js.map +1 -1
- package/lib-es/bridge/getTransactionStatus.d.ts.map +1 -1
- package/lib-es/bridge/getTransactionStatus.js +14 -28
- package/lib-es/bridge/getTransactionStatus.js.map +1 -1
- package/lib-es/bridge/logic.d.ts +8 -13
- package/lib-es/bridge/logic.d.ts.map +1 -1
- package/lib-es/bridge/logic.js +52 -146
- package/lib-es/bridge/logic.js.map +1 -1
- package/lib-es/bridge/prepareTransaction.d.ts.map +1 -1
- package/lib-es/bridge/prepareTransaction.js +2 -2
- package/lib-es/bridge/prepareTransaction.js.map +1 -1
- package/lib-es/bridge/signOperation.d.ts.map +1 -1
- package/lib-es/bridge/signOperation.js +3 -17
- package/lib-es/bridge/signOperation.js.map +1 -1
- package/lib-es/bridge/synchronisation.d.ts +0 -15
- package/lib-es/bridge/synchronisation.d.ts.map +1 -1
- package/lib-es/bridge/synchronisation.js +3 -123
- package/lib-es/bridge/synchronisation.js.map +1 -1
- package/lib-es/constants.d.ts +1 -5
- package/lib-es/constants.d.ts.map +1 -1
- package/lib-es/constants.js +1 -5
- package/lib-es/constants.js.map +1 -1
- package/lib-es/test/bot-specs.d.ts.map +1 -1
- package/lib-es/test/bot-specs.js +2 -41
- package/lib-es/test/bot-specs.js.map +1 -1
- package/lib-es/test/bridgeDatasetTest.d.ts.map +1 -1
- package/lib-es/test/bridgeDatasetTest.js +59 -43
- package/lib-es/test/bridgeDatasetTest.js.map +1 -1
- package/lib-es/test/speculos-deviceActions.d.ts +0 -1
- package/lib-es/test/speculos-deviceActions.d.ts.map +1 -1
- package/lib-es/test/speculos-deviceActions.js +4 -36
- package/lib-es/test/speculos-deviceActions.js.map +1 -1
- package/lib-es/types/index.d.ts +7 -18
- package/lib-es/types/index.d.ts.map +1 -1
- package/package.json +5 -6
- package/src/__tests__/api/index.test.ts +5 -75
- package/src/__tests__/bridge/buildTransaction.test.ts +3 -85
- package/src/__tests__/bridge/getFeesForTransaction.test.ts +9 -144
- package/src/__tests__/bridge/getTransactionStatus.test.ts +38 -217
- package/src/__tests__/bridge/logic.test.ts +118 -922
- package/src/__tests__/bridge/signOperation.test.ts +2 -141
- package/src/__tests__/bridge/synchronisation.test.ts +71 -1265
- package/src/api/graphql/queries.ts +6 -6
- package/src/api/graphql/types.ts +9 -9
- package/src/api/index.ts +5 -32
- package/src/bridge/bridge.fixture.ts +12 -91
- package/src/bridge/buildTransaction.ts +6 -39
- package/src/bridge/estimateMaxSpendable.ts +1 -1
- package/src/bridge/getFeesForTransaction.ts +9 -14
- package/src/bridge/getTransactionStatus.ts +13 -35
- package/src/bridge/logic.ts +63 -202
- package/src/bridge/prepareTransaction.ts +3 -4
- package/src/bridge/signOperation.ts +3 -19
- package/src/bridge/synchronisation.ts +3 -170
- package/src/constants.ts +1 -12
- package/src/test/bot-specs.ts +3 -63
- package/src/test/bridgeDatasetTest.ts +59 -45
- package/src/test/speculos-deviceActions.ts +4 -40
- package/src/types/index.ts +1 -15
|
@@ -18,8 +18,8 @@ export const GetDelegatedStakingActivities = gql`
|
|
|
18
18
|
`;
|
|
19
19
|
export const GetAccountTransactionsData = gql`
|
|
20
20
|
query GetAccountTransactionsData($address: String, $limit: Int) {
|
|
21
|
-
|
|
22
|
-
where: {
|
|
21
|
+
address_version_from_move_resources(
|
|
22
|
+
where: { address: { _eq: $address } }
|
|
23
23
|
order_by: { transaction_version: desc }
|
|
24
24
|
limit: $limit
|
|
25
25
|
) {
|
|
@@ -30,8 +30,8 @@ export const GetAccountTransactionsData = gql`
|
|
|
30
30
|
`;
|
|
31
31
|
export const GetAccountTransactionsDataGt = gql`
|
|
32
32
|
query GetAccountTransactionsDataGt($address: String, $limit: Int, $gt: bigint) {
|
|
33
|
-
|
|
34
|
-
where: {
|
|
33
|
+
address_version_from_move_resources(
|
|
34
|
+
where: { address: { _eq: $address }, transaction_version: { _gt: $gt } }
|
|
35
35
|
order_by: { transaction_version: desc }
|
|
36
36
|
limit: $limit
|
|
37
37
|
) {
|
|
@@ -42,8 +42,8 @@ export const GetAccountTransactionsDataGt = gql`
|
|
|
42
42
|
`;
|
|
43
43
|
export const GetAccountTransactionsDataLt = gql`
|
|
44
44
|
query GetAccountTransactionsDataLt($address: String, $limit: Int, $lt: bigint) {
|
|
45
|
-
|
|
46
|
-
where: {
|
|
45
|
+
address_version_from_move_resources(
|
|
46
|
+
where: { address: { _eq: $address }, transaction_version: { _lt: $lt } }
|
|
47
47
|
order_by: { transaction_version: desc }
|
|
48
48
|
limit: $limit
|
|
49
49
|
) {
|
package/src/api/graphql/types.ts
CHANGED
|
@@ -22,9 +22,9 @@ export type GetAccountTransactionsDataQueryVariables = Exact<{
|
|
|
22
22
|
|
|
23
23
|
export type GetAccountTransactionsDataQuery = {
|
|
24
24
|
__typename?: "query_root";
|
|
25
|
-
|
|
26
|
-
__typename
|
|
27
|
-
transaction_version
|
|
25
|
+
address_version_from_move_resources: Array<{
|
|
26
|
+
__typename: "address_version_from_move_resources";
|
|
27
|
+
transaction_version?: any | null;
|
|
28
28
|
}>;
|
|
29
29
|
};
|
|
30
30
|
|
|
@@ -36,9 +36,9 @@ export type GetAccountTransactionsDataGtQueryVariables = Exact<{
|
|
|
36
36
|
|
|
37
37
|
export type GetAccountTransactionsDataGtQuery = {
|
|
38
38
|
__typename?: "query_root";
|
|
39
|
-
|
|
40
|
-
__typename
|
|
41
|
-
transaction_version
|
|
39
|
+
address_version_from_move_resources: Array<{
|
|
40
|
+
__typename: "address_version_from_move_resources";
|
|
41
|
+
transaction_version?: any | null;
|
|
42
42
|
}>;
|
|
43
43
|
};
|
|
44
44
|
|
|
@@ -50,9 +50,9 @@ export type GetAccountTransactionsDataLtQueryVariables = Exact<{
|
|
|
50
50
|
|
|
51
51
|
export type GetAccountTransactionsDataLtQuery = {
|
|
52
52
|
__typename?: "query_root";
|
|
53
|
-
|
|
54
|
-
__typename
|
|
55
|
-
transaction_version
|
|
53
|
+
address_version_from_move_resources: Array<{
|
|
54
|
+
__typename: "address_version_from_move_resources";
|
|
55
|
+
transaction_version?: any | null;
|
|
56
56
|
}>;
|
|
57
57
|
};
|
|
58
58
|
|
package/src/api/index.ts
CHANGED
|
@@ -30,7 +30,6 @@ import {
|
|
|
30
30
|
GetAccountTransactionsDataQuery,
|
|
31
31
|
GetAccountTransactionsDataGtQueryVariables,
|
|
32
32
|
} from "./graphql/types";
|
|
33
|
-
import { TokenCurrency } from "@ledgerhq/types-cryptoassets";
|
|
34
33
|
|
|
35
34
|
const getApiEndpoint = (currencyId: string) =>
|
|
36
35
|
isTestnet(currencyId) ? getEnv("APTOS_TESTNET_API_ENDPOINT") : getEnv("APTOS_API_ENDPOINT");
|
|
@@ -67,9 +66,9 @@ export class AptosAPI {
|
|
|
67
66
|
return this.aptosClient.getAccountInfo({ accountAddress: address });
|
|
68
67
|
}
|
|
69
68
|
|
|
70
|
-
async getAccountInfo(address: string, startAt
|
|
69
|
+
async getAccountInfo(address: string, startAt: string) {
|
|
71
70
|
const [balance, transactions, blockHeight] = await Promise.all([
|
|
72
|
-
this.
|
|
71
|
+
this.getBalance(address),
|
|
73
72
|
this.fetchTransactions(address, startAt),
|
|
74
73
|
this.getHeight(),
|
|
75
74
|
]);
|
|
@@ -147,22 +146,12 @@ export class AptosAPI {
|
|
|
147
146
|
return pendingTx.data.hash;
|
|
148
147
|
}
|
|
149
148
|
|
|
150
|
-
async getBalance(address: string
|
|
151
|
-
let balance = new BigNumber(0);
|
|
152
|
-
if (token.tokenType === "coin") {
|
|
153
|
-
balance = await this.getCoinBalance(address, token.contractAddress);
|
|
154
|
-
} else {
|
|
155
|
-
balance = await this.getFABalance(address, token.contractAddress);
|
|
156
|
-
}
|
|
157
|
-
return balance;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
async getCoinBalance(address: string, contract_address: string): Promise<BigNumber> {
|
|
149
|
+
private async getBalance(address: string): Promise<BigNumber> {
|
|
161
150
|
try {
|
|
162
151
|
const [balanceStr] = await this.aptosClient.view<[string]>({
|
|
163
152
|
payload: {
|
|
164
153
|
function: "0x1::coin::balance",
|
|
165
|
-
typeArguments: [
|
|
154
|
+
typeArguments: [APTOS_ASSET_ID],
|
|
166
155
|
functionArguments: [address],
|
|
167
156
|
},
|
|
168
157
|
});
|
|
@@ -173,22 +162,6 @@ export class AptosAPI {
|
|
|
173
162
|
}
|
|
174
163
|
}
|
|
175
164
|
|
|
176
|
-
async getFABalance(address: string, contract_address: string): Promise<BigNumber> {
|
|
177
|
-
try {
|
|
178
|
-
const [balanceStr] = await this.aptosClient.view<[string]>({
|
|
179
|
-
payload: {
|
|
180
|
-
function: "0x1::primary_fungible_store::balance",
|
|
181
|
-
typeArguments: ["0x1::object::ObjectCore"],
|
|
182
|
-
functionArguments: [address, contract_address],
|
|
183
|
-
},
|
|
184
|
-
});
|
|
185
|
-
const balance = parseInt(balanceStr, 10);
|
|
186
|
-
return new BigNumber(balance);
|
|
187
|
-
} catch (_) {
|
|
188
|
-
return new BigNumber(0);
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
|
|
192
165
|
private async fetchTransactions(address: string, gt?: string) {
|
|
193
166
|
if (!address) {
|
|
194
167
|
return [];
|
|
@@ -213,7 +186,7 @@ export class AptosAPI {
|
|
|
213
186
|
});
|
|
214
187
|
|
|
215
188
|
return Promise.all(
|
|
216
|
-
queryResponse.data.
|
|
189
|
+
queryResponse.data.address_version_from_move_resources.map(({ transaction_version }) => {
|
|
217
190
|
return this.richItemByVersion(transaction_version);
|
|
218
191
|
}),
|
|
219
192
|
);
|
|
@@ -3,7 +3,6 @@ import { faker } from "@faker-js/faker";
|
|
|
3
3
|
import type { AptosAccount, Transaction } from "../types/index";
|
|
4
4
|
import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets/currencies";
|
|
5
5
|
import { emptyHistoryCache } from "@ledgerhq/coin-framework/account/index";
|
|
6
|
-
import { TokenCurrency } from "@ledgerhq/types-cryptoassets";
|
|
7
6
|
|
|
8
7
|
const currency = getCryptoCurrencyById("aptos");
|
|
9
8
|
|
|
@@ -19,113 +18,35 @@ export function createFixtureAccount(account?: Partial<AptosAccount>): AptosAcco
|
|
|
19
18
|
seedIdentifier: faker.string.uuid(),
|
|
20
19
|
derivationMode: "",
|
|
21
20
|
index: faker.number.int(),
|
|
22
|
-
freshAddress: freshAddress.address,
|
|
23
|
-
freshAddressPath: freshAddress.derivationPath,
|
|
21
|
+
freshAddress: account?.freshAddress || freshAddress.address,
|
|
22
|
+
freshAddressPath: account?.freshAddressPath || freshAddress.derivationPath,
|
|
24
23
|
used: true,
|
|
25
|
-
balance: new BigNumber(0),
|
|
26
|
-
spendableBalance: new BigNumber(0),
|
|
24
|
+
balance: account?.balance || new BigNumber(0),
|
|
25
|
+
spendableBalance: account?.spendableBalance || new BigNumber(0),
|
|
27
26
|
creationDate: faker.date.past(),
|
|
28
27
|
blockHeight: faker.number.int({ min: 100_000, max: 200_000 }),
|
|
29
28
|
currency,
|
|
30
|
-
operationsCount: 0,
|
|
31
|
-
operations: [],
|
|
32
|
-
pendingOperations: [],
|
|
29
|
+
operationsCount: account?.operationsCount || 0,
|
|
30
|
+
operations: account?.operations || [],
|
|
31
|
+
pendingOperations: account?.pendingOperations || [],
|
|
33
32
|
lastSyncDate: new Date(),
|
|
34
33
|
balanceHistoryCache: emptyHistoryCache,
|
|
35
34
|
swapHistory: [],
|
|
36
|
-
...account,
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export function createFixtureAccountWithSubAccount(
|
|
41
|
-
tokenType: string,
|
|
42
|
-
account?: Partial<AptosAccount>,
|
|
43
|
-
): AptosAccount {
|
|
44
|
-
const freshAddress = {
|
|
45
|
-
address: "address",
|
|
46
|
-
derivationPath: "derivation_path",
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
const id = faker.string.uuid();
|
|
50
|
-
|
|
51
|
-
return {
|
|
52
|
-
type: "Account",
|
|
53
|
-
id,
|
|
54
|
-
seedIdentifier: faker.string.uuid(),
|
|
55
|
-
derivationMode: "",
|
|
56
|
-
index: faker.number.int(),
|
|
57
|
-
freshAddress: freshAddress.address,
|
|
58
|
-
freshAddressPath: freshAddress.derivationPath,
|
|
59
|
-
used: true,
|
|
60
|
-
balance: new BigNumber(0),
|
|
61
|
-
spendableBalance: new BigNumber(0),
|
|
62
|
-
creationDate: faker.date.past(),
|
|
63
|
-
blockHeight: faker.number.int({ min: 100_000, max: 200_000 }),
|
|
64
|
-
currency,
|
|
65
|
-
operationsCount: 0,
|
|
66
|
-
operations: [],
|
|
67
|
-
pendingOperations: [],
|
|
68
|
-
lastSyncDate: new Date(),
|
|
69
|
-
balanceHistoryCache: emptyHistoryCache,
|
|
70
|
-
swapHistory: [],
|
|
71
|
-
subAccounts: [
|
|
72
|
-
{
|
|
73
|
-
id: "1",
|
|
74
|
-
parentId: id,
|
|
75
|
-
type: "TokenAccount",
|
|
76
|
-
token: {
|
|
77
|
-
type: "TokenCurrency",
|
|
78
|
-
id: "aptToken",
|
|
79
|
-
contractAddress: "contract_address",
|
|
80
|
-
parentCurrency: currency,
|
|
81
|
-
tokenType,
|
|
82
|
-
} as TokenCurrency,
|
|
83
|
-
balance: BigNumber(1000),
|
|
84
|
-
spendableBalance: BigNumber(1000),
|
|
85
|
-
creationDate: new Date(),
|
|
86
|
-
operationsCount: 0,
|
|
87
|
-
operations: [],
|
|
88
|
-
pendingOperations: [],
|
|
89
|
-
balanceHistoryCache: emptyHistoryCache,
|
|
90
|
-
swapHistory: [],
|
|
91
|
-
},
|
|
92
|
-
],
|
|
93
|
-
...account,
|
|
94
35
|
};
|
|
95
36
|
}
|
|
96
37
|
|
|
97
38
|
export function createFixtureTransaction(tx?: Partial<Transaction>): Transaction {
|
|
98
39
|
const transaction: Transaction = {
|
|
99
|
-
amount: new BigNumber(0),
|
|
100
|
-
recipient:
|
|
101
|
-
useAllAmount: false,
|
|
102
|
-
family: "aptos",
|
|
103
|
-
mode: "send",
|
|
104
|
-
fees: null,
|
|
105
|
-
options: {
|
|
106
|
-
maxGasAmount: BigNumber(0).toString(),
|
|
107
|
-
gasUnitPrice: BigNumber(0).toString(),
|
|
108
|
-
},
|
|
109
|
-
...tx,
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
return transaction;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
export function createFixtureTransactionWithSubAccount(tx?: Partial<Transaction>): Transaction {
|
|
116
|
-
const transaction: Transaction = {
|
|
117
|
-
amount: new BigNumber(0),
|
|
118
|
-
recipient: "recipient",
|
|
119
|
-
useAllAmount: false,
|
|
40
|
+
amount: tx?.amount || new BigNumber(0),
|
|
41
|
+
recipient: tx?.recipient || "",
|
|
42
|
+
useAllAmount: tx?.useAllAmount || false,
|
|
120
43
|
family: "aptos",
|
|
121
|
-
mode: "send",
|
|
122
|
-
fees: null,
|
|
44
|
+
mode: tx?.mode || "send",
|
|
45
|
+
fees: tx?.fees || null,
|
|
123
46
|
options: {
|
|
124
47
|
maxGasAmount: BigNumber(0).toString(),
|
|
125
48
|
gasUnitPrice: BigNumber(0).toString(),
|
|
126
49
|
},
|
|
127
|
-
subAccountId: "1",
|
|
128
|
-
...tx,
|
|
129
50
|
};
|
|
130
51
|
|
|
131
52
|
return transaction;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { InputEntryFunctionData, RawTransaction } from "@aptos-labs/ts-sdk";
|
|
2
|
-
import type { Account
|
|
3
|
-
import
|
|
2
|
+
import type { Account } from "@ledgerhq/types-live";
|
|
3
|
+
import BigNumber from "bignumber.js";
|
|
4
4
|
import { AptosAPI } from "../api";
|
|
5
|
-
import { APTOS_ASSET_ID
|
|
5
|
+
import { APTOS_ASSET_ID } from "../constants";
|
|
6
6
|
import { normalizeTransactionOptions } from "./logic";
|
|
7
7
|
import type { Transaction } from "../types";
|
|
8
8
|
|
|
@@ -11,51 +11,18 @@ const buildTransaction = async (
|
|
|
11
11
|
transaction: Transaction,
|
|
12
12
|
aptosClient: AptosAPI,
|
|
13
13
|
): Promise<RawTransaction> => {
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
const txPayload = getPayload(subAccount, transaction);
|
|
14
|
+
const txPayload = getPayload(transaction.recipient, transaction.amount);
|
|
17
15
|
const txOptions = normalizeTransactionOptions(transaction.options);
|
|
18
16
|
const tx = await aptosClient.generateTransaction(account.freshAddress, txPayload, txOptions);
|
|
19
17
|
|
|
20
18
|
return tx;
|
|
21
19
|
};
|
|
22
20
|
|
|
23
|
-
const getPayload = (
|
|
24
|
-
tokenAccount: TokenAccount | undefined,
|
|
25
|
-
transaction: Transaction,
|
|
26
|
-
): InputEntryFunctionData => {
|
|
27
|
-
if (tokenAccount && isTokenAccount(tokenAccount)) {
|
|
28
|
-
const { tokenType } = tokenAccount.token;
|
|
29
|
-
|
|
30
|
-
if (!SUPPORTED_TOKEN_TYPES.includes(tokenType)) {
|
|
31
|
-
throw new Error(`Token type ${tokenType} not supported`);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
if (tokenType === "fungible_asset") {
|
|
35
|
-
return {
|
|
36
|
-
function: `0x1::primary_fungible_store::transfer`,
|
|
37
|
-
typeArguments: ["0x1::fungible_asset::Metadata"],
|
|
38
|
-
functionArguments: [
|
|
39
|
-
tokenAccount.token.contractAddress,
|
|
40
|
-
transaction.recipient,
|
|
41
|
-
transaction.amount.toString(),
|
|
42
|
-
],
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if (tokenType === "coin") {
|
|
47
|
-
return {
|
|
48
|
-
function: `0x1::aptos_account::transfer_coins`,
|
|
49
|
-
typeArguments: [tokenAccount.token.contractAddress],
|
|
50
|
-
functionArguments: [transaction.recipient, transaction.amount.toString()],
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
21
|
+
const getPayload = (sendTo: string, amount: BigNumber): InputEntryFunctionData => {
|
|
55
22
|
return {
|
|
56
23
|
function: "0x1::aptos_account::transfer_coins",
|
|
57
24
|
typeArguments: [APTOS_ASSET_ID],
|
|
58
|
-
functionArguments: [
|
|
25
|
+
functionArguments: [sendTo, amount.toString()],
|
|
59
26
|
};
|
|
60
27
|
};
|
|
61
28
|
|
|
@@ -29,7 +29,7 @@ const estimateMaxSpendable = async ({
|
|
|
29
29
|
gasUnitPrice = BigNumber(estimate.gasUnitPrice);
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
return getMaxSendBalance(maxGasAmount, gasUnitPrice
|
|
32
|
+
return getMaxSendBalance(mainAccount.spendableBalance, maxGasAmount, gasUnitPrice);
|
|
33
33
|
};
|
|
34
34
|
|
|
35
35
|
export default estimateMaxSpendable;
|
|
@@ -5,7 +5,7 @@ import BigNumber from "bignumber.js";
|
|
|
5
5
|
import { makeLRUCache, seconds } from "@ledgerhq/live-network/cache";
|
|
6
6
|
import { AptosAPI } from "../api";
|
|
7
7
|
import buildTransaction from "./buildTransaction";
|
|
8
|
-
import { DEFAULT_GAS, DEFAULT_GAS_PRICE, ESTIMATE_GAS_MUL
|
|
8
|
+
import { DEFAULT_GAS, DEFAULT_GAS_PRICE, ESTIMATE_GAS_MUL } from "./logic";
|
|
9
9
|
import type { Transaction, TransactionErrors } from "../types";
|
|
10
10
|
|
|
11
11
|
type IGetEstimatedGasReturnType = {
|
|
@@ -49,18 +49,16 @@ export const getFee = async (
|
|
|
49
49
|
|
|
50
50
|
const expectedGas = gasPrice.multipliedBy(gasLimit);
|
|
51
51
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
) {
|
|
59
|
-
// INSUFFICIENT_BALANCE will be processed by getTransactionStatus
|
|
52
|
+
const isUnderMaxSpendable = transaction.amount
|
|
53
|
+
.plus(expectedGas)
|
|
54
|
+
.isLessThan(account.spendableBalance);
|
|
55
|
+
|
|
56
|
+
if (isUnderMaxSpendable && !completedTx.success) {
|
|
57
|
+
// we want to skip INSUFFICIENT_BALANCE error because it will be processed by getTransactionStatus
|
|
58
|
+
if (!completedTx.vm_status.includes("INSUFFICIENT_BALANCE")) {
|
|
60
59
|
throw Error(`Simulation failed with following error: ${completedTx.vm_status}`);
|
|
61
60
|
}
|
|
62
61
|
}
|
|
63
|
-
|
|
64
62
|
res.fees = expectedGas;
|
|
65
63
|
res.estimate.maxGasAmount = gasLimit.toString();
|
|
66
64
|
res.estimate.gasUnitPrice = completedTx.gas_unit_price;
|
|
@@ -74,10 +72,7 @@ export const getFee = async (
|
|
|
74
72
|
|
|
75
73
|
const CACHE = makeLRUCache(
|
|
76
74
|
getFee,
|
|
77
|
-
(account: Account, transaction: Transaction) => {
|
|
78
|
-
const tokenAccount = getTokenAccount(account, transaction);
|
|
79
|
-
return `${tokenAccount ? tokenAccount.id : account.id}-${transaction.amount.toString()}}`;
|
|
80
|
-
},
|
|
75
|
+
(account: Account, transaction: Transaction) => `${account.id}-${transaction.amount.toString()}}`,
|
|
81
76
|
seconds(30),
|
|
82
77
|
);
|
|
83
78
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { BigNumber } from "bignumber.js";
|
|
1
2
|
import {
|
|
2
3
|
NotEnoughBalance,
|
|
3
4
|
RecipientRequired,
|
|
@@ -5,65 +6,42 @@ import {
|
|
|
5
6
|
FeeNotLoaded,
|
|
6
7
|
InvalidAddressBecauseDestinationIsAlsoSource,
|
|
7
8
|
AmountRequired,
|
|
8
|
-
NotEnoughBalanceFees,
|
|
9
9
|
} from "@ledgerhq/errors";
|
|
10
10
|
import type { Account } from "@ledgerhq/types-live";
|
|
11
|
-
import { BigNumber } from "bignumber.js";
|
|
12
11
|
import type { Transaction, TransactionStatus } from "../types";
|
|
13
12
|
|
|
14
13
|
import { AccountAddress } from "@aptos-labs/ts-sdk";
|
|
15
|
-
import { getTokenAccount } from "./logic";
|
|
16
14
|
|
|
17
15
|
const getTransactionStatus = async (a: Account, t: Transaction): Promise<TransactionStatus> => {
|
|
18
16
|
const errors: Record<string, Error> = {};
|
|
19
17
|
const warnings = {};
|
|
20
18
|
|
|
21
|
-
if (!t.recipient) {
|
|
22
|
-
errors.recipient = new RecipientRequired();
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
if (!AccountAddress.isValid({ input: t.recipient }).valid && !errors.recipient) {
|
|
26
|
-
errors.recipient = new InvalidAddress("", { currencyName: a.currency.name });
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (t.recipient === a.freshAddress && !errors.recipient) {
|
|
30
|
-
errors.recipient = new InvalidAddressBecauseDestinationIsAlsoSource();
|
|
31
|
-
}
|
|
32
|
-
|
|
33
19
|
if (!t.fees) {
|
|
34
20
|
errors.fees = new FeeNotLoaded();
|
|
35
21
|
}
|
|
36
22
|
|
|
37
23
|
const estimatedFees = t.fees || BigNumber(0);
|
|
38
24
|
|
|
39
|
-
if (t.amount.
|
|
25
|
+
if (t.amount.eq(0)) {
|
|
40
26
|
errors.amount = new AmountRequired();
|
|
41
27
|
}
|
|
42
28
|
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
const amount = t.useAllAmount
|
|
46
|
-
? tokenAccount
|
|
47
|
-
? tokenAccount.spendableBalance
|
|
48
|
-
: a.spendableBalance.minus(estimatedFees).isLessThan(0)
|
|
49
|
-
? BigNumber(0)
|
|
50
|
-
: a.spendableBalance.minus(estimatedFees)
|
|
51
|
-
: t.amount;
|
|
29
|
+
const amount = t.amount;
|
|
52
30
|
|
|
53
|
-
const totalSpent =
|
|
31
|
+
const totalSpent = BigNumber(t.amount).plus(estimatedFees);
|
|
54
32
|
|
|
55
|
-
if (
|
|
56
|
-
errors.amount = new NotEnoughBalanceFees();
|
|
57
|
-
}
|
|
58
|
-
if (
|
|
59
|
-
tokenAccount
|
|
60
|
-
? tokenAccount.spendableBalance.isLessThan(totalSpent) ||
|
|
61
|
-
a.spendableBalance.isLessThan(estimatedFees)
|
|
62
|
-
: a.spendableBalance.isLessThan(totalSpent) && !errors.amount
|
|
63
|
-
) {
|
|
33
|
+
if (totalSpent.gt(a.balance) && !errors.amount) {
|
|
64
34
|
errors.amount = new NotEnoughBalance();
|
|
65
35
|
}
|
|
66
36
|
|
|
37
|
+
if (!t.recipient) {
|
|
38
|
+
errors.recipient = new RecipientRequired();
|
|
39
|
+
} else if (AccountAddress.isValid({ input: t.recipient }).valid === false && !errors.recipient) {
|
|
40
|
+
errors.recipient = new InvalidAddress("", { currencyName: a.currency.name });
|
|
41
|
+
} else if (t.recipient === a.freshAddress && !errors.recipient) {
|
|
42
|
+
errors.recipient = new InvalidAddressBecauseDestinationIsAlsoSource();
|
|
43
|
+
}
|
|
44
|
+
|
|
67
45
|
return Promise.resolve({
|
|
68
46
|
errors,
|
|
69
47
|
warnings,
|