@ledgerhq/coin-aptos 2.0.0-nightly.4 → 2.0.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/.unimportedrc.json +18 -6
- package/CHANGELOG.md +156 -29
- package/jest.config.js +2 -1
- package/jest.integ.config.js +8 -0
- package/lib/__tests__/api/index.integ.test.d.ts +2 -0
- package/lib/__tests__/api/index.integ.test.d.ts.map +1 -0
- package/lib/__tests__/api/index.integ.test.js +52 -0
- package/lib/__tests__/api/index.integ.test.js.map +1 -0
- package/lib/__tests__/api/index.test.js +48 -460
- package/lib/__tests__/api/index.test.js.map +1 -1
- package/lib/__tests__/bridge/broadcast.test.js +5 -5
- package/lib/__tests__/bridge/broadcast.test.js.map +1 -1
- package/lib/__tests__/bridge/buildTransaction.test.js +6 -6
- package/lib/__tests__/bridge/buildTransaction.test.js.map +1 -1
- package/lib/__tests__/bridge/createTransaction.test.js +1 -1
- package/lib/__tests__/bridge/createTransaction.test.js.map +1 -1
- package/lib/__tests__/bridge/getFeesForTransaction.test.js +9 -9
- package/lib/__tests__/bridge/getFeesForTransaction.test.js.map +1 -1
- package/lib/__tests__/bridge/prepareTransaction.test.js +3 -3
- package/lib/__tests__/bridge/prepareTransaction.test.js.map +1 -1
- package/lib/__tests__/bridge/signOperation.test.js +3 -2
- package/lib/__tests__/bridge/signOperation.test.js.map +1 -1
- package/lib/__tests__/bridge/synchronisation.test.js +6 -6
- package/lib/__tests__/bridge/synchronisation.test.js.map +1 -1
- package/lib/__tests__/network/client.test.d.ts +2 -0
- package/lib/__tests__/network/client.test.d.ts.map +1 -0
- package/lib/__tests__/network/client.test.js +520 -0
- package/lib/__tests__/network/client.test.js.map +1 -0
- package/lib/api/index.d.ts +4 -33
- package/lib/api/index.d.ts.map +1 -1
- package/lib/api/index.js +24 -196
- package/lib/api/index.js.map +1 -1
- package/lib/bridge/broadcast.d.ts +3 -2
- package/lib/bridge/broadcast.d.ts.map +1 -1
- package/lib/bridge/broadcast.js +4 -3
- package/lib/bridge/broadcast.js.map +1 -1
- package/lib/bridge/buildTransaction.d.ts +1 -1
- package/lib/bridge/buildTransaction.d.ts.map +1 -1
- package/lib/bridge/buildTransaction.js.map +1 -1
- package/lib/bridge/createTransaction.js +3 -3
- package/lib/bridge/createTransaction.js.map +1 -1
- package/lib/bridge/estimateMaxSpendable.d.ts.map +1 -1
- package/lib/bridge/estimateMaxSpendable.js +5 -4
- package/lib/bridge/estimateMaxSpendable.js.map +1 -1
- package/lib/bridge/getFeesForTransaction.d.ts +1 -1
- package/lib/bridge/getFeesForTransaction.d.ts.map +1 -1
- package/lib/bridge/getFeesForTransaction.js +7 -6
- package/lib/bridge/getFeesForTransaction.js.map +1 -1
- package/lib/bridge/index.d.ts +1 -1
- package/lib/bridge/index.d.ts.map +1 -1
- package/lib/bridge/logic.d.ts +0 -3
- package/lib/bridge/logic.d.ts.map +1 -1
- package/lib/bridge/logic.js +1 -4
- package/lib/bridge/logic.js.map +1 -1
- package/lib/bridge/prepareTransaction.d.ts.map +1 -1
- package/lib/bridge/prepareTransaction.js +4 -3
- package/lib/bridge/prepareTransaction.js.map +1 -1
- package/lib/bridge/signOperation.js +3 -3
- package/lib/bridge/signOperation.js.map +1 -1
- package/lib/bridge/synchronisation.js +3 -3
- package/lib/bridge/synchronisation.js.map +1 -1
- package/lib/config.d.ts +13 -0
- package/lib/config.d.ts.map +1 -0
- package/lib/config.js +9 -0
- package/lib/config.js.map +1 -0
- package/lib/constants.d.ts +4 -0
- package/lib/constants.d.ts.map +1 -1
- package/lib/constants.js +8 -1
- package/lib/constants.js.map +1 -1
- package/lib/network/client.d.ts +36 -0
- package/lib/network/client.d.ts.map +1 -0
- package/lib/network/client.js +247 -0
- package/lib/network/client.js.map +1 -0
- package/lib/network/graphql/queries.d.ts.map +1 -0
- package/lib/network/graphql/queries.js.map +1 -0
- package/lib/network/graphql/types.d.ts.map +1 -0
- package/lib/{api → network}/graphql/types.js.map +1 -1
- package/lib/network/index.d.ts +2 -1
- package/lib/network/index.d.ts.map +1 -1
- package/lib/network/index.js +15 -0
- package/lib/network/index.js.map +1 -1
- package/lib/test/bridgeDatasetTest.d.ts.map +1 -1
- package/lib/test/bridgeDatasetTest.js +1 -0
- package/lib/test/bridgeDatasetTest.js.map +1 -1
- package/lib/types/assets.d.ts +12 -0
- package/lib/types/assets.d.ts.map +1 -0
- package/lib/types/assets.js +3 -0
- package/lib/types/assets.js.map +1 -0
- package/lib-es/__tests__/api/index.integ.test.d.ts +2 -0
- package/lib-es/__tests__/api/index.integ.test.d.ts.map +1 -0
- package/lib-es/__tests__/api/index.integ.test.js +50 -0
- package/lib-es/__tests__/api/index.integ.test.js.map +1 -0
- package/lib-es/__tests__/api/index.test.js +52 -464
- package/lib-es/__tests__/api/index.test.js.map +1 -1
- package/lib-es/__tests__/bridge/broadcast.test.js +2 -2
- package/lib-es/__tests__/bridge/broadcast.test.js.map +1 -1
- package/lib-es/__tests__/bridge/buildTransaction.test.js +2 -2
- package/lib-es/__tests__/bridge/buildTransaction.test.js.map +1 -1
- package/lib-es/__tests__/bridge/createTransaction.test.js +1 -1
- package/lib-es/__tests__/bridge/createTransaction.test.js.map +1 -1
- package/lib-es/__tests__/bridge/getFeesForTransaction.test.js +2 -2
- package/lib-es/__tests__/bridge/getFeesForTransaction.test.js.map +1 -1
- package/lib-es/__tests__/bridge/prepareTransaction.test.js +2 -2
- package/lib-es/__tests__/bridge/prepareTransaction.test.js.map +1 -1
- package/lib-es/__tests__/bridge/signOperation.test.js +3 -2
- package/lib-es/__tests__/bridge/signOperation.test.js.map +1 -1
- package/lib-es/__tests__/bridge/synchronisation.test.js +3 -3
- package/lib-es/__tests__/bridge/synchronisation.test.js.map +1 -1
- package/lib-es/__tests__/network/client.test.d.ts +2 -0
- package/lib-es/__tests__/network/client.test.d.ts.map +1 -0
- package/lib-es/__tests__/network/client.test.js +515 -0
- package/lib-es/__tests__/network/client.test.js.map +1 -0
- package/lib-es/api/index.d.ts +4 -33
- package/lib-es/api/index.d.ts.map +1 -1
- package/lib-es/api/index.js +22 -194
- package/lib-es/api/index.js.map +1 -1
- package/lib-es/bridge/broadcast.d.ts +3 -2
- package/lib-es/bridge/broadcast.d.ts.map +1 -1
- package/lib-es/bridge/broadcast.js +4 -3
- package/lib-es/bridge/broadcast.js.map +1 -1
- package/lib-es/bridge/buildTransaction.d.ts +1 -1
- package/lib-es/bridge/buildTransaction.d.ts.map +1 -1
- package/lib-es/bridge/buildTransaction.js.map +1 -1
- package/lib-es/bridge/createTransaction.js +1 -1
- package/lib-es/bridge/createTransaction.js.map +1 -1
- package/lib-es/bridge/estimateMaxSpendable.d.ts.map +1 -1
- package/lib-es/bridge/estimateMaxSpendable.js +3 -2
- package/lib-es/bridge/estimateMaxSpendable.js.map +1 -1
- package/lib-es/bridge/getFeesForTransaction.d.ts +1 -1
- package/lib-es/bridge/getFeesForTransaction.d.ts.map +1 -1
- package/lib-es/bridge/getFeesForTransaction.js +2 -1
- package/lib-es/bridge/getFeesForTransaction.js.map +1 -1
- package/lib-es/bridge/index.d.ts +1 -1
- package/lib-es/bridge/index.d.ts.map +1 -1
- package/lib-es/bridge/logic.d.ts +0 -3
- package/lib-es/bridge/logic.d.ts.map +1 -1
- package/lib-es/bridge/logic.js +0 -3
- 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 +3 -2
- package/lib-es/bridge/prepareTransaction.js.map +1 -1
- package/lib-es/bridge/signOperation.js +1 -1
- package/lib-es/bridge/signOperation.js.map +1 -1
- package/lib-es/bridge/synchronisation.js +1 -1
- package/lib-es/bridge/synchronisation.js.map +1 -1
- package/lib-es/config.d.ts +13 -0
- package/lib-es/config.d.ts.map +1 -0
- package/lib-es/config.js +4 -0
- package/lib-es/config.js.map +1 -0
- package/lib-es/constants.d.ts +4 -0
- package/lib-es/constants.d.ts.map +1 -1
- package/lib-es/constants.js +4 -0
- package/lib-es/constants.js.map +1 -1
- package/lib-es/network/client.d.ts +36 -0
- package/lib-es/network/client.d.ts.map +1 -0
- package/lib-es/network/client.js +240 -0
- package/lib-es/network/client.js.map +1 -0
- package/lib-es/network/graphql/queries.d.ts.map +1 -0
- package/lib-es/network/graphql/queries.js.map +1 -0
- package/lib-es/network/graphql/types.d.ts.map +1 -0
- package/lib-es/{api → network}/graphql/types.js.map +1 -1
- package/lib-es/network/index.d.ts +2 -1
- package/lib-es/network/index.d.ts.map +1 -1
- package/lib-es/network/index.js +1 -0
- package/lib-es/network/index.js.map +1 -1
- package/lib-es/test/bridgeDatasetTest.d.ts.map +1 -1
- package/lib-es/test/bridgeDatasetTest.js +1 -0
- package/lib-es/test/bridgeDatasetTest.js.map +1 -1
- package/lib-es/types/assets.d.ts +12 -0
- package/lib-es/types/assets.d.ts.map +1 -0
- package/lib-es/types/assets.js +2 -0
- package/lib-es/types/assets.js.map +1 -0
- package/package.json +12 -10
- package/src/__tests__/api/index.integ.test.ts +58 -0
- package/src/__tests__/api/index.test.ts +60 -547
- package/src/__tests__/bridge/broadcast.test.ts +2 -2
- package/src/__tests__/bridge/buildTransaction.test.ts +2 -2
- package/src/__tests__/bridge/createTransaction.test.ts +1 -1
- package/src/__tests__/bridge/getFeesForTransaction.test.ts +2 -2
- package/src/__tests__/bridge/prepareTransaction.test.ts +2 -2
- package/src/__tests__/bridge/signOperation.test.ts +6 -3
- package/src/__tests__/bridge/synchronisation.test.ts +4 -4
- package/src/__tests__/network/client.test.ts +618 -0
- package/src/api/index.ts +31 -250
- package/src/bridge/broadcast.ts +7 -7
- package/src/bridge/buildTransaction.ts +1 -1
- package/src/bridge/createTransaction.ts +1 -1
- package/src/bridge/estimateMaxSpendable.ts +3 -2
- package/src/bridge/getFeesForTransaction.ts +3 -2
- package/src/bridge/index.ts +1 -1
- package/src/bridge/logic.ts +0 -4
- package/src/bridge/prepareTransaction.ts +4 -2
- package/src/bridge/signOperation.ts +1 -1
- package/src/bridge/synchronisation.ts +1 -1
- package/src/config.ts +19 -0
- package/src/constants.ts +5 -0
- package/src/network/client.ts +315 -0
- package/src/network/index.ts +2 -1
- package/src/test/bridgeDatasetTest.ts +1 -0
- package/src/types/assets.ts +15 -0
- package/lib/api/graphql/queries.d.ts.map +0 -1
- package/lib/api/graphql/queries.js.map +0 -1
- package/lib/api/graphql/types.d.ts.map +0 -1
- package/lib-es/api/graphql/queries.d.ts.map +0 -1
- package/lib-es/api/graphql/queries.js.map +0 -1
- package/lib-es/api/graphql/types.d.ts.map +0 -1
- /package/lib/{api → network}/graphql/queries.d.ts +0 -0
- /package/lib/{api → network}/graphql/queries.js +0 -0
- /package/lib/{api → network}/graphql/types.d.ts +0 -0
- /package/lib/{api → network}/graphql/types.js +0 -0
- /package/lib-es/{api → network}/graphql/queries.d.ts +0 -0
- /package/lib-es/{api → network}/graphql/queries.js +0 -0
- /package/lib-es/{api → network}/graphql/types.d.ts +0 -0
- /package/lib-es/{api → network}/graphql/types.js +0 -0
- /package/src/{api → network}/graphql/queries.ts +0 -0
- /package/src/{api → network}/graphql/types.ts +0 -0
package/src/api/index.ts
CHANGED
|
@@ -1,252 +1,33 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
Block,
|
|
20
|
-
} from "@aptos-labs/ts-sdk";
|
|
21
|
-
import { getEnv } from "@ledgerhq/live-env";
|
|
22
|
-
import network from "@ledgerhq/live-network";
|
|
23
|
-
import BigNumber from "bignumber.js";
|
|
24
|
-
import isUndefined from "lodash/isUndefined";
|
|
25
|
-
import { APTOS_ASSET_ID } from "../constants";
|
|
26
|
-
import { isTestnet } from "../bridge/logic";
|
|
27
|
-
import type { AptosTransaction, TransactionOptions } from "../types";
|
|
28
|
-
import { GetAccountTransactionsData, GetAccountTransactionsDataGt } from "./graphql/queries";
|
|
29
|
-
import {
|
|
30
|
-
GetAccountTransactionsDataQuery,
|
|
31
|
-
GetAccountTransactionsDataGtQueryVariables,
|
|
32
|
-
} from "./graphql/types";
|
|
33
|
-
import { TokenCurrency } from "@ledgerhq/types-cryptoassets";
|
|
34
|
-
|
|
35
|
-
const getApiEndpoint = (currencyId: string) =>
|
|
36
|
-
isTestnet(currencyId) ? getEnv("APTOS_TESTNET_API_ENDPOINT") : getEnv("APTOS_API_ENDPOINT");
|
|
37
|
-
const getIndexerEndpoint = (currencyId: string) =>
|
|
38
|
-
isTestnet(currencyId)
|
|
39
|
-
? getEnv("APTOS_TESTNET_INDEXER_ENDPOINT")
|
|
40
|
-
: getEnv("APTOS_INDEXER_ENDPOINT");
|
|
41
|
-
|
|
42
|
-
export class AptosAPI {
|
|
43
|
-
private apiUrl: string;
|
|
44
|
-
private indexerUrl: string;
|
|
45
|
-
private aptosConfig: AptosConfig;
|
|
46
|
-
private aptosClient: Aptos;
|
|
47
|
-
private apolloClient: ApolloClient<object>;
|
|
48
|
-
|
|
49
|
-
constructor(currencyId: string) {
|
|
50
|
-
this.apiUrl = getApiEndpoint(currencyId);
|
|
51
|
-
this.indexerUrl = getIndexerEndpoint(currencyId);
|
|
52
|
-
this.aptosConfig = new AptosConfig({
|
|
53
|
-
fullnode: this.apiUrl,
|
|
54
|
-
indexer: this.indexerUrl,
|
|
55
|
-
});
|
|
56
|
-
this.aptosClient = new Aptos(this.aptosConfig);
|
|
57
|
-
this.apolloClient = new ApolloClient({
|
|
58
|
-
uri: this.indexerUrl,
|
|
59
|
-
cache: new InMemoryCache(),
|
|
60
|
-
headers: {
|
|
61
|
-
"x-client": "ledger-live",
|
|
62
|
-
},
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
async getAccount(address: string): Promise<AccountData> {
|
|
67
|
-
return this.aptosClient.getAccountInfo({ accountAddress: address });
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
async getAccountInfo(address: string, startAt?: string) {
|
|
71
|
-
const [balance, transactions, blockHeight] = await Promise.all([
|
|
72
|
-
this.getCoinBalance(address, APTOS_ASSET_ID),
|
|
73
|
-
this.fetchTransactions(address, startAt),
|
|
74
|
-
this.getHeight(),
|
|
75
|
-
]);
|
|
76
|
-
|
|
77
|
-
return {
|
|
78
|
-
balance,
|
|
79
|
-
transactions,
|
|
80
|
-
blockHeight,
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
async estimateGasPrice(): Promise<GasEstimation> {
|
|
85
|
-
return this.aptosClient.getGasPriceEstimation();
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
async generateTransaction(
|
|
89
|
-
address: string,
|
|
90
|
-
payload: InputEntryFunctionData,
|
|
91
|
-
options: TransactionOptions,
|
|
92
|
-
): Promise<RawTransaction> {
|
|
93
|
-
const opts: Partial<InputGenerateTransactionOptions> = {};
|
|
94
|
-
if (!isUndefined(options.maxGasAmount)) {
|
|
95
|
-
opts.maxGasAmount = Number(options.maxGasAmount);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
if (!isUndefined(options.gasUnitPrice)) {
|
|
99
|
-
opts.gasUnitPrice = Number(options.gasUnitPrice);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
try {
|
|
103
|
-
const { ledger_timestamp } = await this.aptosClient.getLedgerInfo();
|
|
104
|
-
opts.expireTimestamp = Number(Math.ceil(+ledger_timestamp / 1_000_000 + 2 * 60)); // in milliseconds
|
|
105
|
-
} catch {
|
|
106
|
-
// skip
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
return this.aptosClient.transaction.build
|
|
110
|
-
.simple({
|
|
111
|
-
sender: address,
|
|
112
|
-
data: payload,
|
|
113
|
-
options: opts,
|
|
114
|
-
})
|
|
115
|
-
.then(t => t.rawTransaction)
|
|
116
|
-
.catch(error => {
|
|
117
|
-
throw error;
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
async simulateTransaction(
|
|
122
|
-
address: Ed25519PublicKey,
|
|
123
|
-
tx: RawTransaction,
|
|
124
|
-
options = {
|
|
125
|
-
estimateGasUnitPrice: true,
|
|
126
|
-
estimateMaxGasAmount: true,
|
|
127
|
-
estimatePrioritizedGasUnitPrice: false,
|
|
1
|
+
import type { Api } from "@ledgerhq/coin-framework/api/index";
|
|
2
|
+
import type { AptosConfig as AptosConfigApi } from "../config";
|
|
3
|
+
import type { Balance, Operation, TransactionIntent } from "@ledgerhq/coin-framework/api/types";
|
|
4
|
+
import coinConfig from "../config";
|
|
5
|
+
import type { AptosAsset, AptosExtra, AptosFeeParameters, AptosSender } from "../types/assets";
|
|
6
|
+
import { AptosAPI } from "../network";
|
|
7
|
+
|
|
8
|
+
export function createApi(
|
|
9
|
+
config: AptosConfigApi,
|
|
10
|
+
): Api<AptosAsset, AptosExtra, AptosSender, AptosFeeParameters> {
|
|
11
|
+
coinConfig.setCoinConfig(() => ({ ...config, status: { type: "active" } }));
|
|
12
|
+
|
|
13
|
+
const client = new AptosAPI(config.aptosSettings);
|
|
14
|
+
|
|
15
|
+
return {
|
|
16
|
+
broadcast: (tx: string) => client.broadcast(tx),
|
|
17
|
+
combine: (_tx, _signature, _pubkey): string => {
|
|
18
|
+
throw new Error("Not Implemented");
|
|
128
19
|
},
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
body: txBytes,
|
|
143
|
-
path: "transactions",
|
|
144
|
-
type: AptosApiType.FULLNODE,
|
|
145
|
-
originMethod: "",
|
|
146
|
-
});
|
|
147
|
-
return pendingTx.data.hash;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
async getBalance(address: string, token: TokenCurrency): Promise<BigNumber> {
|
|
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> {
|
|
161
|
-
try {
|
|
162
|
-
const [balanceStr] = await this.aptosClient.view<[string]>({
|
|
163
|
-
payload: {
|
|
164
|
-
function: "0x1::coin::balance",
|
|
165
|
-
typeArguments: [contract_address],
|
|
166
|
-
functionArguments: [address],
|
|
167
|
-
},
|
|
168
|
-
});
|
|
169
|
-
const balance = parseInt(balanceStr, 10);
|
|
170
|
-
return new BigNumber(balance);
|
|
171
|
-
} catch (_) {
|
|
172
|
-
return new BigNumber(0);
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
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
|
-
private async fetchTransactions(address: string, gt?: string) {
|
|
193
|
-
if (!address) {
|
|
194
|
-
return [];
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
let query = GetAccountTransactionsData;
|
|
198
|
-
if (gt) {
|
|
199
|
-
query = GetAccountTransactionsDataGt;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
const queryResponse = await this.apolloClient.query<
|
|
203
|
-
GetAccountTransactionsDataQuery,
|
|
204
|
-
GetAccountTransactionsDataGtQueryVariables
|
|
205
|
-
>({
|
|
206
|
-
query,
|
|
207
|
-
variables: {
|
|
208
|
-
address,
|
|
209
|
-
limit: 1000,
|
|
210
|
-
gt,
|
|
211
|
-
},
|
|
212
|
-
fetchPolicy: "network-only",
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
return Promise.all(
|
|
216
|
-
queryResponse.data.account_transactions.map(({ transaction_version }) => {
|
|
217
|
-
return this.richItemByVersion(transaction_version);
|
|
218
|
-
}),
|
|
219
|
-
);
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
private async richItemByVersion(version: number): Promise<AptosTransaction | null> {
|
|
223
|
-
try {
|
|
224
|
-
const tx: TransactionResponse = await this.aptosClient.getTransactionByVersion({
|
|
225
|
-
ledgerVersion: version,
|
|
226
|
-
});
|
|
227
|
-
const block = await this.getBlock(version);
|
|
228
|
-
return {
|
|
229
|
-
...tx,
|
|
230
|
-
block,
|
|
231
|
-
} as AptosTransaction;
|
|
232
|
-
} catch (error) {
|
|
233
|
-
return null;
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
private async getHeight(): Promise<number> {
|
|
238
|
-
const { data } = await network<Block>({
|
|
239
|
-
method: "GET",
|
|
240
|
-
url: this.apiUrl,
|
|
241
|
-
});
|
|
242
|
-
return parseInt(data.block_height);
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
private async getBlock(version: number) {
|
|
246
|
-
const block = await this.aptosClient.getBlockByVersion({ ledgerVersion: version });
|
|
247
|
-
return {
|
|
248
|
-
height: parseInt(block.block_height),
|
|
249
|
-
hash: block.block_hash,
|
|
250
|
-
};
|
|
251
|
-
}
|
|
20
|
+
craftTransaction: (_transactionIntent, _customFees): Promise<string> => {
|
|
21
|
+
throw new Error("Not Implemented");
|
|
22
|
+
},
|
|
23
|
+
estimateFees: (transactionIntent: TransactionIntent<AptosAsset, AptosExtra, AptosSender>) =>
|
|
24
|
+
client.estimateFees(transactionIntent),
|
|
25
|
+
getBalance: (_address): Promise<Balance<AptosAsset>[]> => {
|
|
26
|
+
throw new Error("Not Implemented");
|
|
27
|
+
},
|
|
28
|
+
lastBlock: () => client.getLastBlock(),
|
|
29
|
+
listOperations: (_address, _pagination): Promise<[Operation<AptosAsset>[], string]> => {
|
|
30
|
+
throw new Error("Not Implemented");
|
|
31
|
+
},
|
|
32
|
+
};
|
|
252
33
|
}
|
package/src/bridge/broadcast.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import type { Account, Operation, SignedOperation } from "@ledgerhq/types-live";
|
|
2
2
|
import { patchOperationWithHash } from "@ledgerhq/coin-framework/operation";
|
|
3
|
-
import { AptosAPI } from "../
|
|
3
|
+
import { AptosAPI } from "../network";
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
signedOperation,
|
|
7
|
-
account,
|
|
8
|
-
}: {
|
|
5
|
+
type broadcastFunc = {
|
|
9
6
|
signedOperation: SignedOperation;
|
|
10
7
|
account: Account;
|
|
11
|
-
}
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const broadcast = async ({ signedOperation, account }: broadcastFunc): Promise<Operation> => {
|
|
12
11
|
const { signature, operation } = signedOperation;
|
|
13
|
-
const
|
|
12
|
+
const client = new AptosAPI(account.currency.id);
|
|
13
|
+
const hash = await client.broadcast(signature);
|
|
14
14
|
return patchOperationWithHash(operation, hash);
|
|
15
15
|
};
|
|
16
16
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { InputEntryFunctionData, RawTransaction } from "@aptos-labs/ts-sdk";
|
|
2
2
|
import type { Account, TokenAccount } from "@ledgerhq/types-live";
|
|
3
3
|
import { findSubAccountById, isTokenAccount } from "@ledgerhq/coin-framework/account/index";
|
|
4
|
-
import { AptosAPI } from "../api";
|
|
5
4
|
import { APTOS_ASSET_ID, SUPPORTED_TOKEN_TYPES } from "../constants";
|
|
5
|
+
import { AptosAPI } from "../network";
|
|
6
6
|
import { normalizeTransactionOptions } from "./logic";
|
|
7
7
|
import type { Transaction } from "../types";
|
|
8
8
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import BigNumber from "bignumber.js";
|
|
2
2
|
import type { Transaction } from "../types";
|
|
3
|
-
import { DEFAULT_GAS, DEFAULT_GAS_PRICE } from "
|
|
3
|
+
import { DEFAULT_GAS, DEFAULT_GAS_PRICE } from "../constants";
|
|
4
4
|
|
|
5
5
|
const createTransaction = (): Transaction => ({
|
|
6
6
|
family: "aptos",
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { Account, AccountLike } from "@ledgerhq/types-live";
|
|
2
2
|
import { BigNumber } from "bignumber.js";
|
|
3
3
|
import { getMainAccount } from "@ledgerhq/coin-framework/account/index";
|
|
4
|
-
import { AptosAPI } from "../
|
|
4
|
+
import { AptosAPI } from "../network";
|
|
5
5
|
import { getEstimatedGas } from "./getFeesForTransaction";
|
|
6
|
-
import {
|
|
6
|
+
import { getMaxSendBalance } from "./logic";
|
|
7
|
+
import { DEFAULT_GAS, DEFAULT_GAS_PRICE } from "../constants";
|
|
7
8
|
import type { Transaction } from "../types";
|
|
8
9
|
|
|
9
10
|
const estimateMaxSpendable = async ({
|
|
@@ -3,9 +3,10 @@ import { log } from "@ledgerhq/logs";
|
|
|
3
3
|
import type { Account } from "@ledgerhq/types-live";
|
|
4
4
|
import BigNumber from "bignumber.js";
|
|
5
5
|
import { makeLRUCache, seconds } from "@ledgerhq/live-network/cache";
|
|
6
|
-
import { AptosAPI } from "../
|
|
6
|
+
import { AptosAPI } from "../network";
|
|
7
7
|
import buildTransaction from "./buildTransaction";
|
|
8
|
-
import {
|
|
8
|
+
import { getTokenAccount } from "./logic";
|
|
9
|
+
import { DEFAULT_GAS, DEFAULT_GAS_PRICE, ESTIMATE_GAS_MUL } from "../constants";
|
|
9
10
|
import type { Transaction, TransactionErrors } from "../types";
|
|
10
11
|
|
|
11
12
|
type IGetEstimatedGasReturnType = {
|
package/src/bridge/index.ts
CHANGED
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
updateTransaction,
|
|
7
7
|
} from "@ledgerhq/coin-framework/bridge/jsHelpers";
|
|
8
8
|
import getAddressWrapper from "@ledgerhq/coin-framework/bridge/getAddressWrapper";
|
|
9
|
-
import { SignerContext } from "@ledgerhq/coin-framework/signer";
|
|
9
|
+
import type { SignerContext } from "@ledgerhq/coin-framework/signer";
|
|
10
10
|
import type { Account, AccountBridge, CurrencyBridge } from "@ledgerhq/types-live";
|
|
11
11
|
import resolver from "../signer";
|
|
12
12
|
import type { Transaction, TransactionStatus, AptosSigner } from "../types";
|
package/src/bridge/logic.ts
CHANGED
|
@@ -36,10 +36,6 @@ import type {
|
|
|
36
36
|
} from "../types";
|
|
37
37
|
import { findTokenByAddressInCurrency } from "@ledgerhq/cryptoassets";
|
|
38
38
|
|
|
39
|
-
export const DEFAULT_GAS = new BigNumber(200);
|
|
40
|
-
export const DEFAULT_GAS_PRICE = new BigNumber(100);
|
|
41
|
-
export const ESTIMATE_GAS_MUL = new BigNumber(1.0); // define buffer for gas estimation change here, if needed
|
|
42
|
-
|
|
43
39
|
const CLEAN_HEX_REGEXP = /^0x0*|^0+/;
|
|
44
40
|
|
|
45
41
|
export function isTestnet(currencyId: string): boolean {
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type { Account } from "@ledgerhq/types-live";
|
|
2
2
|
import BigNumber from "bignumber.js";
|
|
3
|
-
|
|
3
|
+
|
|
4
|
+
import { AptosAPI } from "../network";
|
|
4
5
|
import { getEstimatedGas } from "./getFeesForTransaction";
|
|
5
6
|
import type { Transaction } from "../types";
|
|
6
|
-
import {
|
|
7
|
+
import { getMaxSendBalance } from "./logic";
|
|
8
|
+
import { DEFAULT_GAS, DEFAULT_GAS_PRICE } from "./../constants";
|
|
7
9
|
|
|
8
10
|
const prepareTransaction = async (
|
|
9
11
|
account: Account,
|
|
@@ -4,7 +4,7 @@ import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
|
|
|
4
4
|
import buildTransaction from "./buildTransaction";
|
|
5
5
|
import BigNumber from "bignumber.js";
|
|
6
6
|
import type { Account, AccountBridge, Operation, OperationType } from "@ledgerhq/types-live";
|
|
7
|
-
import { AptosAPI } from "../
|
|
7
|
+
import { AptosAPI } from "../network";
|
|
8
8
|
|
|
9
9
|
import { SignerContext } from "@ledgerhq/coin-framework/signer";
|
|
10
10
|
import { AptosSigner } from "../types";
|
|
@@ -2,7 +2,7 @@ import { inferSubOperations } from "@ledgerhq/coin-framework/serialization/index
|
|
|
2
2
|
import { decodeAccountId, encodeAccountId } from "@ledgerhq/coin-framework/account";
|
|
3
3
|
import type { GetAccountShape } from "@ledgerhq/coin-framework/bridge/jsHelpers";
|
|
4
4
|
import { mergeOps } from "@ledgerhq/coin-framework/bridge/jsHelpers";
|
|
5
|
-
import { AptosAPI } from "../
|
|
5
|
+
import { AptosAPI } from "../network";
|
|
6
6
|
import { txsToOps } from "./logic";
|
|
7
7
|
import type { AptosAccount } from "../types";
|
|
8
8
|
import { Account, Operation, TokenAccount } from "@ledgerhq/types-live";
|
package/src/config.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type AptosSettings } from "@aptos-labs/ts-sdk";
|
|
2
|
+
import buildCoinConfig, {
|
|
3
|
+
type CoinConfig,
|
|
4
|
+
type CurrencyConfig,
|
|
5
|
+
} from "@ledgerhq/coin-framework/config";
|
|
6
|
+
import type { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
|
|
7
|
+
|
|
8
|
+
export type AptosConfig = {
|
|
9
|
+
aptosSettings: AptosSettings;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export type AptosCoinConfig = CurrencyConfig & AptosConfig;
|
|
13
|
+
|
|
14
|
+
const coinConfig: {
|
|
15
|
+
setCoinConfig: (config: CoinConfig<AptosCoinConfig>) => void;
|
|
16
|
+
getCoinConfig: (currency?: CryptoCurrency) => AptosCoinConfig;
|
|
17
|
+
} = buildCoinConfig<AptosCoinConfig>();
|
|
18
|
+
|
|
19
|
+
export default coinConfig;
|
package/src/constants.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import { MoveStructId } from "@aptos-labs/ts-sdk";
|
|
2
|
+
import BigNumber from "bignumber.js";
|
|
3
|
+
|
|
4
|
+
export const DEFAULT_GAS = new BigNumber(200);
|
|
5
|
+
export const DEFAULT_GAS_PRICE = new BigNumber(100);
|
|
6
|
+
export const ESTIMATE_GAS_MUL = new BigNumber(1.0); // define buffer for gas estimation change here, if needed
|
|
2
7
|
|
|
3
8
|
export const LOAD_LIMIT = 10;
|
|
4
9
|
|