@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.
Files changed (217) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/.unimportedrc.json +18 -6
  3. package/CHANGELOG.md +156 -29
  4. package/jest.config.js +2 -1
  5. package/jest.integ.config.js +8 -0
  6. package/lib/__tests__/api/index.integ.test.d.ts +2 -0
  7. package/lib/__tests__/api/index.integ.test.d.ts.map +1 -0
  8. package/lib/__tests__/api/index.integ.test.js +52 -0
  9. package/lib/__tests__/api/index.integ.test.js.map +1 -0
  10. package/lib/__tests__/api/index.test.js +48 -460
  11. package/lib/__tests__/api/index.test.js.map +1 -1
  12. package/lib/__tests__/bridge/broadcast.test.js +5 -5
  13. package/lib/__tests__/bridge/broadcast.test.js.map +1 -1
  14. package/lib/__tests__/bridge/buildTransaction.test.js +6 -6
  15. package/lib/__tests__/bridge/buildTransaction.test.js.map +1 -1
  16. package/lib/__tests__/bridge/createTransaction.test.js +1 -1
  17. package/lib/__tests__/bridge/createTransaction.test.js.map +1 -1
  18. package/lib/__tests__/bridge/getFeesForTransaction.test.js +9 -9
  19. package/lib/__tests__/bridge/getFeesForTransaction.test.js.map +1 -1
  20. package/lib/__tests__/bridge/prepareTransaction.test.js +3 -3
  21. package/lib/__tests__/bridge/prepareTransaction.test.js.map +1 -1
  22. package/lib/__tests__/bridge/signOperation.test.js +3 -2
  23. package/lib/__tests__/bridge/signOperation.test.js.map +1 -1
  24. package/lib/__tests__/bridge/synchronisation.test.js +6 -6
  25. package/lib/__tests__/bridge/synchronisation.test.js.map +1 -1
  26. package/lib/__tests__/network/client.test.d.ts +2 -0
  27. package/lib/__tests__/network/client.test.d.ts.map +1 -0
  28. package/lib/__tests__/network/client.test.js +520 -0
  29. package/lib/__tests__/network/client.test.js.map +1 -0
  30. package/lib/api/index.d.ts +4 -33
  31. package/lib/api/index.d.ts.map +1 -1
  32. package/lib/api/index.js +24 -196
  33. package/lib/api/index.js.map +1 -1
  34. package/lib/bridge/broadcast.d.ts +3 -2
  35. package/lib/bridge/broadcast.d.ts.map +1 -1
  36. package/lib/bridge/broadcast.js +4 -3
  37. package/lib/bridge/broadcast.js.map +1 -1
  38. package/lib/bridge/buildTransaction.d.ts +1 -1
  39. package/lib/bridge/buildTransaction.d.ts.map +1 -1
  40. package/lib/bridge/buildTransaction.js.map +1 -1
  41. package/lib/bridge/createTransaction.js +3 -3
  42. package/lib/bridge/createTransaction.js.map +1 -1
  43. package/lib/bridge/estimateMaxSpendable.d.ts.map +1 -1
  44. package/lib/bridge/estimateMaxSpendable.js +5 -4
  45. package/lib/bridge/estimateMaxSpendable.js.map +1 -1
  46. package/lib/bridge/getFeesForTransaction.d.ts +1 -1
  47. package/lib/bridge/getFeesForTransaction.d.ts.map +1 -1
  48. package/lib/bridge/getFeesForTransaction.js +7 -6
  49. package/lib/bridge/getFeesForTransaction.js.map +1 -1
  50. package/lib/bridge/index.d.ts +1 -1
  51. package/lib/bridge/index.d.ts.map +1 -1
  52. package/lib/bridge/logic.d.ts +0 -3
  53. package/lib/bridge/logic.d.ts.map +1 -1
  54. package/lib/bridge/logic.js +1 -4
  55. package/lib/bridge/logic.js.map +1 -1
  56. package/lib/bridge/prepareTransaction.d.ts.map +1 -1
  57. package/lib/bridge/prepareTransaction.js +4 -3
  58. package/lib/bridge/prepareTransaction.js.map +1 -1
  59. package/lib/bridge/signOperation.js +3 -3
  60. package/lib/bridge/signOperation.js.map +1 -1
  61. package/lib/bridge/synchronisation.js +3 -3
  62. package/lib/bridge/synchronisation.js.map +1 -1
  63. package/lib/config.d.ts +13 -0
  64. package/lib/config.d.ts.map +1 -0
  65. package/lib/config.js +9 -0
  66. package/lib/config.js.map +1 -0
  67. package/lib/constants.d.ts +4 -0
  68. package/lib/constants.d.ts.map +1 -1
  69. package/lib/constants.js +8 -1
  70. package/lib/constants.js.map +1 -1
  71. package/lib/network/client.d.ts +36 -0
  72. package/lib/network/client.d.ts.map +1 -0
  73. package/lib/network/client.js +247 -0
  74. package/lib/network/client.js.map +1 -0
  75. package/lib/network/graphql/queries.d.ts.map +1 -0
  76. package/lib/network/graphql/queries.js.map +1 -0
  77. package/lib/network/graphql/types.d.ts.map +1 -0
  78. package/lib/{api → network}/graphql/types.js.map +1 -1
  79. package/lib/network/index.d.ts +2 -1
  80. package/lib/network/index.d.ts.map +1 -1
  81. package/lib/network/index.js +15 -0
  82. package/lib/network/index.js.map +1 -1
  83. package/lib/test/bridgeDatasetTest.d.ts.map +1 -1
  84. package/lib/test/bridgeDatasetTest.js +1 -0
  85. package/lib/test/bridgeDatasetTest.js.map +1 -1
  86. package/lib/types/assets.d.ts +12 -0
  87. package/lib/types/assets.d.ts.map +1 -0
  88. package/lib/types/assets.js +3 -0
  89. package/lib/types/assets.js.map +1 -0
  90. package/lib-es/__tests__/api/index.integ.test.d.ts +2 -0
  91. package/lib-es/__tests__/api/index.integ.test.d.ts.map +1 -0
  92. package/lib-es/__tests__/api/index.integ.test.js +50 -0
  93. package/lib-es/__tests__/api/index.integ.test.js.map +1 -0
  94. package/lib-es/__tests__/api/index.test.js +52 -464
  95. package/lib-es/__tests__/api/index.test.js.map +1 -1
  96. package/lib-es/__tests__/bridge/broadcast.test.js +2 -2
  97. package/lib-es/__tests__/bridge/broadcast.test.js.map +1 -1
  98. package/lib-es/__tests__/bridge/buildTransaction.test.js +2 -2
  99. package/lib-es/__tests__/bridge/buildTransaction.test.js.map +1 -1
  100. package/lib-es/__tests__/bridge/createTransaction.test.js +1 -1
  101. package/lib-es/__tests__/bridge/createTransaction.test.js.map +1 -1
  102. package/lib-es/__tests__/bridge/getFeesForTransaction.test.js +2 -2
  103. package/lib-es/__tests__/bridge/getFeesForTransaction.test.js.map +1 -1
  104. package/lib-es/__tests__/bridge/prepareTransaction.test.js +2 -2
  105. package/lib-es/__tests__/bridge/prepareTransaction.test.js.map +1 -1
  106. package/lib-es/__tests__/bridge/signOperation.test.js +3 -2
  107. package/lib-es/__tests__/bridge/signOperation.test.js.map +1 -1
  108. package/lib-es/__tests__/bridge/synchronisation.test.js +3 -3
  109. package/lib-es/__tests__/bridge/synchronisation.test.js.map +1 -1
  110. package/lib-es/__tests__/network/client.test.d.ts +2 -0
  111. package/lib-es/__tests__/network/client.test.d.ts.map +1 -0
  112. package/lib-es/__tests__/network/client.test.js +515 -0
  113. package/lib-es/__tests__/network/client.test.js.map +1 -0
  114. package/lib-es/api/index.d.ts +4 -33
  115. package/lib-es/api/index.d.ts.map +1 -1
  116. package/lib-es/api/index.js +22 -194
  117. package/lib-es/api/index.js.map +1 -1
  118. package/lib-es/bridge/broadcast.d.ts +3 -2
  119. package/lib-es/bridge/broadcast.d.ts.map +1 -1
  120. package/lib-es/bridge/broadcast.js +4 -3
  121. package/lib-es/bridge/broadcast.js.map +1 -1
  122. package/lib-es/bridge/buildTransaction.d.ts +1 -1
  123. package/lib-es/bridge/buildTransaction.d.ts.map +1 -1
  124. package/lib-es/bridge/buildTransaction.js.map +1 -1
  125. package/lib-es/bridge/createTransaction.js +1 -1
  126. package/lib-es/bridge/createTransaction.js.map +1 -1
  127. package/lib-es/bridge/estimateMaxSpendable.d.ts.map +1 -1
  128. package/lib-es/bridge/estimateMaxSpendable.js +3 -2
  129. package/lib-es/bridge/estimateMaxSpendable.js.map +1 -1
  130. package/lib-es/bridge/getFeesForTransaction.d.ts +1 -1
  131. package/lib-es/bridge/getFeesForTransaction.d.ts.map +1 -1
  132. package/lib-es/bridge/getFeesForTransaction.js +2 -1
  133. package/lib-es/bridge/getFeesForTransaction.js.map +1 -1
  134. package/lib-es/bridge/index.d.ts +1 -1
  135. package/lib-es/bridge/index.d.ts.map +1 -1
  136. package/lib-es/bridge/logic.d.ts +0 -3
  137. package/lib-es/bridge/logic.d.ts.map +1 -1
  138. package/lib-es/bridge/logic.js +0 -3
  139. package/lib-es/bridge/logic.js.map +1 -1
  140. package/lib-es/bridge/prepareTransaction.d.ts.map +1 -1
  141. package/lib-es/bridge/prepareTransaction.js +3 -2
  142. package/lib-es/bridge/prepareTransaction.js.map +1 -1
  143. package/lib-es/bridge/signOperation.js +1 -1
  144. package/lib-es/bridge/signOperation.js.map +1 -1
  145. package/lib-es/bridge/synchronisation.js +1 -1
  146. package/lib-es/bridge/synchronisation.js.map +1 -1
  147. package/lib-es/config.d.ts +13 -0
  148. package/lib-es/config.d.ts.map +1 -0
  149. package/lib-es/config.js +4 -0
  150. package/lib-es/config.js.map +1 -0
  151. package/lib-es/constants.d.ts +4 -0
  152. package/lib-es/constants.d.ts.map +1 -1
  153. package/lib-es/constants.js +4 -0
  154. package/lib-es/constants.js.map +1 -1
  155. package/lib-es/network/client.d.ts +36 -0
  156. package/lib-es/network/client.d.ts.map +1 -0
  157. package/lib-es/network/client.js +240 -0
  158. package/lib-es/network/client.js.map +1 -0
  159. package/lib-es/network/graphql/queries.d.ts.map +1 -0
  160. package/lib-es/network/graphql/queries.js.map +1 -0
  161. package/lib-es/network/graphql/types.d.ts.map +1 -0
  162. package/lib-es/{api → network}/graphql/types.js.map +1 -1
  163. package/lib-es/network/index.d.ts +2 -1
  164. package/lib-es/network/index.d.ts.map +1 -1
  165. package/lib-es/network/index.js +1 -0
  166. package/lib-es/network/index.js.map +1 -1
  167. package/lib-es/test/bridgeDatasetTest.d.ts.map +1 -1
  168. package/lib-es/test/bridgeDatasetTest.js +1 -0
  169. package/lib-es/test/bridgeDatasetTest.js.map +1 -1
  170. package/lib-es/types/assets.d.ts +12 -0
  171. package/lib-es/types/assets.d.ts.map +1 -0
  172. package/lib-es/types/assets.js +2 -0
  173. package/lib-es/types/assets.js.map +1 -0
  174. package/package.json +12 -10
  175. package/src/__tests__/api/index.integ.test.ts +58 -0
  176. package/src/__tests__/api/index.test.ts +60 -547
  177. package/src/__tests__/bridge/broadcast.test.ts +2 -2
  178. package/src/__tests__/bridge/buildTransaction.test.ts +2 -2
  179. package/src/__tests__/bridge/createTransaction.test.ts +1 -1
  180. package/src/__tests__/bridge/getFeesForTransaction.test.ts +2 -2
  181. package/src/__tests__/bridge/prepareTransaction.test.ts +2 -2
  182. package/src/__tests__/bridge/signOperation.test.ts +6 -3
  183. package/src/__tests__/bridge/synchronisation.test.ts +4 -4
  184. package/src/__tests__/network/client.test.ts +618 -0
  185. package/src/api/index.ts +31 -250
  186. package/src/bridge/broadcast.ts +7 -7
  187. package/src/bridge/buildTransaction.ts +1 -1
  188. package/src/bridge/createTransaction.ts +1 -1
  189. package/src/bridge/estimateMaxSpendable.ts +3 -2
  190. package/src/bridge/getFeesForTransaction.ts +3 -2
  191. package/src/bridge/index.ts +1 -1
  192. package/src/bridge/logic.ts +0 -4
  193. package/src/bridge/prepareTransaction.ts +4 -2
  194. package/src/bridge/signOperation.ts +1 -1
  195. package/src/bridge/synchronisation.ts +1 -1
  196. package/src/config.ts +19 -0
  197. package/src/constants.ts +5 -0
  198. package/src/network/client.ts +315 -0
  199. package/src/network/index.ts +2 -1
  200. package/src/test/bridgeDatasetTest.ts +1 -0
  201. package/src/types/assets.ts +15 -0
  202. package/lib/api/graphql/queries.d.ts.map +0 -1
  203. package/lib/api/graphql/queries.js.map +0 -1
  204. package/lib/api/graphql/types.d.ts.map +0 -1
  205. package/lib-es/api/graphql/queries.d.ts.map +0 -1
  206. package/lib-es/api/graphql/queries.js.map +0 -1
  207. package/lib-es/api/graphql/types.d.ts.map +0 -1
  208. /package/lib/{api → network}/graphql/queries.d.ts +0 -0
  209. /package/lib/{api → network}/graphql/queries.js +0 -0
  210. /package/lib/{api → network}/graphql/types.d.ts +0 -0
  211. /package/lib/{api → network}/graphql/types.js +0 -0
  212. /package/lib-es/{api → network}/graphql/queries.d.ts +0 -0
  213. /package/lib-es/{api → network}/graphql/queries.js +0 -0
  214. /package/lib-es/{api → network}/graphql/types.d.ts +0 -0
  215. /package/lib-es/{api → network}/graphql/types.js +0 -0
  216. /package/src/{api → network}/graphql/queries.ts +0 -0
  217. /package/src/{api → network}/graphql/types.ts +0 -0
package/src/api/index.ts CHANGED
@@ -1,252 +1,33 @@
1
- import { ApolloClient, InMemoryCache } from "@apollo/client";
2
-
3
- import {
4
- AccountData,
5
- Aptos,
6
- AptosApiType,
7
- AptosConfig,
8
- Ed25519PublicKey,
9
- GasEstimation,
10
- InputEntryFunctionData,
11
- InputGenerateTransactionOptions,
12
- MimeType,
13
- post,
14
- RawTransaction,
15
- SimpleTransaction,
16
- TransactionResponse,
17
- UserTransactionResponse,
18
- PostRequestOptions,
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
- ): Promise<UserTransactionResponse[]> {
130
- return this.aptosClient.transaction.simulate.simple({
131
- signerPublicKey: address,
132
- transaction: { rawTransaction: tx } as SimpleTransaction,
133
- options,
134
- });
135
- }
136
-
137
- async broadcast(signature: string): Promise<string> {
138
- const txBytes = Uint8Array.from(Buffer.from(signature, "hex"));
139
- const pendingTx = await post<PostRequestOptions, TransactionResponse>({
140
- contentType: MimeType.BCS_SIGNED_TRANSACTION,
141
- aptosConfig: this.aptosClient.config,
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
  }
@@ -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 "../api";
3
+ import { AptosAPI } from "../network";
4
4
 
5
- const broadcast = async ({
6
- signedOperation,
7
- account,
8
- }: {
5
+ type broadcastFunc = {
9
6
  signedOperation: SignedOperation;
10
7
  account: Account;
11
- }): Promise<Operation> => {
8
+ };
9
+
10
+ const broadcast = async ({ signedOperation, account }: broadcastFunc): Promise<Operation> => {
12
11
  const { signature, operation } = signedOperation;
13
- const hash = await new AptosAPI(account.currency.id).broadcast(signature);
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 "./logic";
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 "../api";
4
+ import { AptosAPI } from "../network";
5
5
  import { getEstimatedGas } from "./getFeesForTransaction";
6
- import { DEFAULT_GAS, DEFAULT_GAS_PRICE, getMaxSendBalance } from "./logic";
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 "../api";
6
+ import { AptosAPI } from "../network";
7
7
  import buildTransaction from "./buildTransaction";
8
- import { DEFAULT_GAS, DEFAULT_GAS_PRICE, ESTIMATE_GAS_MUL, getTokenAccount } from "./logic";
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 = {
@@ -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";
@@ -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
- import { AptosAPI } from "../api";
3
+
4
+ import { AptosAPI } from "../network";
4
5
  import { getEstimatedGas } from "./getFeesForTransaction";
5
6
  import type { Transaction } from "../types";
6
- import { DEFAULT_GAS, DEFAULT_GAS_PRICE, getMaxSendBalance } from "./logic";
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 "../api";
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 "../api";
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