@ledgerhq/coin-aptos 2.2.0-next.1 → 2.2.0-nightly.2
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 +19 -15
- 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/getBalance.unit.test.js +68 -28
- package/lib/__tests__/api/getBalance.unit.test.js.map +1 -1
- package/lib/__tests__/api/index.integ.test.js +30 -11
- package/lib/__tests__/api/index.integ.test.js.map +1 -1
- package/lib/__tests__/api/index.test.js.map +1 -1
- package/lib/__tests__/bridge/synchronisation.test.js +15 -6
- package/lib/__tests__/bridge/synchronisation.test.js.map +1 -1
- package/lib/__tests__/logic/getBalances.test.d.ts +2 -0
- package/lib/__tests__/logic/getBalances.test.d.ts.map +1 -0
- package/lib/__tests__/logic/getBalances.test.js +63 -0
- package/lib/__tests__/logic/getBalances.test.js.map +1 -0
- package/lib/__tests__/network/client.test.js +69 -66
- 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 +2 -2
- package/lib/api/index.js.map +1 -1
- package/lib/bridge/synchronisation.d.ts.map +1 -1
- package/lib/bridge/synchronisation.js +7 -2
- package/lib/bridge/synchronisation.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/logic/getBalances.d.ts +5 -0
- package/lib/logic/getBalances.d.ts.map +1 -0
- package/lib/logic/getBalances.js +21 -0
- package/lib/logic/getBalances.js.map +1 -0
- package/lib/network/client.d.ts +3 -7
- package/lib/network/client.d.ts.map +1 -1
- package/lib/network/client.js +28 -62
- 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/getBalance.unit.test.js +69 -26
- package/lib-es/__tests__/api/getBalance.unit.test.js.map +1 -1
- package/lib-es/__tests__/api/index.integ.test.js +30 -11
- 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__/bridge/synchronisation.test.js +15 -6
- package/lib-es/__tests__/bridge/synchronisation.test.js.map +1 -1
- package/lib-es/__tests__/logic/getBalances.test.d.ts +2 -0
- package/lib-es/__tests__/logic/getBalances.test.d.ts.map +1 -0
- package/lib-es/__tests__/logic/getBalances.test.js +61 -0
- package/lib-es/__tests__/logic/getBalances.test.js.map +1 -0
- package/lib-es/__tests__/network/client.test.js +69 -66
- 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 +2 -2
- package/lib-es/api/index.js.map +1 -1
- package/lib-es/bridge/synchronisation.d.ts.map +1 -1
- package/lib-es/bridge/synchronisation.js +4 -2
- package/lib-es/bridge/synchronisation.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/logic/getBalances.d.ts +5 -0
- package/lib-es/logic/getBalances.d.ts.map +1 -0
- package/lib-es/logic/getBalances.js +17 -0
- package/lib-es/logic/getBalances.js.map +1 -0
- package/lib-es/network/client.d.ts +3 -7
- package/lib-es/network/client.d.ts.map +1 -1
- package/lib-es/network/client.js +28 -62
- 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 +8 -8
- package/src/__tests__/api/craftTransaction.unit.test.ts +23 -38
- package/src/__tests__/api/getBalance.unit.test.ts +82 -28
- package/src/__tests__/api/index.integ.test.ts +36 -15
- package/src/__tests__/api/index.test.ts +4 -6
- package/src/__tests__/bridge/synchronisation.test.ts +21 -6
- package/src/__tests__/logic/getBalances.test.ts +80 -0
- package/src/__tests__/network/client.test.ts +83 -89
- package/src/api/index.ts +6 -8
- package/src/bridge/synchronisation.ts +4 -2
- package/src/logic/craftTransaction.ts +6 -8
- package/src/logic/getBalances.ts +27 -0
- package/src/network/client.ts +31 -74
- package/src/types/assets.ts +0 -5
- package/lib/logic/getBalance.d.ts +0 -5
- package/lib/logic/getBalance.d.ts.map +0 -1
- package/lib/logic/getBalance.js +0 -12
- package/lib/logic/getBalance.js.map +0 -1
- package/lib-es/logic/getBalance.d.ts +0 -5
- package/lib-es/logic/getBalance.d.ts.map +0 -1
- package/lib-es/logic/getBalance.js +0 -8
- package/lib-es/logic/getBalance.js.map +0 -1
- package/src/logic/getBalance.ts +0 -15
package/lib-es/network/client.js
CHANGED
|
@@ -42,12 +42,12 @@ export class AptosAPI {
|
|
|
42
42
|
}
|
|
43
43
|
async getAccountInfo(address, startAt) {
|
|
44
44
|
const [balance, transactions, blockHeight] = await Promise.all([
|
|
45
|
-
this.
|
|
45
|
+
this.getBalances(address, APTOS_ASSET_ID),
|
|
46
46
|
this.fetchTransactions(address, startAt),
|
|
47
47
|
this.getHeight(),
|
|
48
48
|
]);
|
|
49
49
|
return {
|
|
50
|
-
balance,
|
|
50
|
+
balance: balance[0].amount ?? BigInt(0),
|
|
51
51
|
transactions,
|
|
52
52
|
blockHeight,
|
|
53
53
|
};
|
|
@@ -103,12 +103,6 @@ export class AptosAPI {
|
|
|
103
103
|
});
|
|
104
104
|
return pendingTx.data.hash;
|
|
105
105
|
}
|
|
106
|
-
async getBalance(address, token) {
|
|
107
|
-
if (token.tokenType === "coin") {
|
|
108
|
-
return await this.getCoinBalance(address, token.contractAddress);
|
|
109
|
-
}
|
|
110
|
-
return await this.getFABalance(address, token.contractAddress);
|
|
111
|
-
}
|
|
112
106
|
async getLastBlock() {
|
|
113
107
|
const { block_height } = await this.aptosClient.getLedgerInfo();
|
|
114
108
|
const block = await this.aptosClient.getBlockByHeight({ blockHeight: Number(block_height) });
|
|
@@ -118,46 +112,8 @@ export class AptosAPI {
|
|
|
118
112
|
time: new Date(Number(block.block_timestamp) / 1_000),
|
|
119
113
|
};
|
|
120
114
|
}
|
|
121
|
-
async getCoinBalance(address, contract_address) {
|
|
122
|
-
try {
|
|
123
|
-
const [balanceStr] = await this.aptosClient.view({
|
|
124
|
-
payload: {
|
|
125
|
-
function: "0x1::coin::balance",
|
|
126
|
-
typeArguments: [contract_address],
|
|
127
|
-
functionArguments: [address],
|
|
128
|
-
},
|
|
129
|
-
});
|
|
130
|
-
const balance = parseInt(balanceStr, 10);
|
|
131
|
-
return new BigNumber(balance);
|
|
132
|
-
}
|
|
133
|
-
catch (error) {
|
|
134
|
-
log("error", "getCoinBalance", {
|
|
135
|
-
error,
|
|
136
|
-
});
|
|
137
|
-
return new BigNumber(0);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
async getFABalance(address, contract_address) {
|
|
141
|
-
try {
|
|
142
|
-
const [balanceStr] = await this.aptosClient.view({
|
|
143
|
-
payload: {
|
|
144
|
-
function: "0x1::primary_fungible_store::balance",
|
|
145
|
-
typeArguments: ["0x1::object::ObjectCore"],
|
|
146
|
-
functionArguments: [address, contract_address],
|
|
147
|
-
},
|
|
148
|
-
});
|
|
149
|
-
const balance = parseInt(balanceStr, 10);
|
|
150
|
-
return new BigNumber(balance);
|
|
151
|
-
}
|
|
152
|
-
catch (error) {
|
|
153
|
-
log("error", "getFABalance", {
|
|
154
|
-
error,
|
|
155
|
-
});
|
|
156
|
-
return new BigNumber(0);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
115
|
async estimateFees(transactionIntent) {
|
|
160
|
-
const publicKeyEd = new Ed25519PublicKey(transactionIntent
|
|
116
|
+
const publicKeyEd = new Ed25519PublicKey(transactionIntent?.senderPublicKey ?? "");
|
|
161
117
|
const txPayload = {
|
|
162
118
|
function: "0x1::aptos_account::transfer_coins",
|
|
163
119
|
typeArguments: [APTOS_ASSET_ID],
|
|
@@ -183,7 +139,7 @@ export class AptosAPI {
|
|
|
183
139
|
maxGasAmount: DEFAULT_GAS.toString(),
|
|
184
140
|
gasUnitPrice: DEFAULT_GAS_PRICE.toString(),
|
|
185
141
|
};
|
|
186
|
-
const tx = await this.generateTransaction(transactionIntent.sender
|
|
142
|
+
const tx = await this.generateTransaction(transactionIntent.sender, txPayload, txOptions);
|
|
187
143
|
const simulation = await this.simulateTransaction(publicKeyEd, tx);
|
|
188
144
|
const completedTx = simulation[0];
|
|
189
145
|
const gasLimit = new BigNumber(completedTx.gas_used).multipliedBy(ESTIMATE_GAS_MUL);
|
|
@@ -192,6 +148,7 @@ export class AptosAPI {
|
|
|
192
148
|
return {
|
|
193
149
|
value: BigInt(expectedGas.toString()),
|
|
194
150
|
parameters: {
|
|
151
|
+
storageLimit: BigInt(0),
|
|
195
152
|
gasLimit: BigInt(gasLimit.toString()),
|
|
196
153
|
gasPrice: BigInt(gasPrice.toString()),
|
|
197
154
|
},
|
|
@@ -256,21 +213,30 @@ export class AptosAPI {
|
|
|
256
213
|
hash: block.block_hash,
|
|
257
214
|
};
|
|
258
215
|
}
|
|
259
|
-
async getBalances(address) {
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
216
|
+
async getBalances(address, contractAddress) {
|
|
217
|
+
try {
|
|
218
|
+
const whereCondition = {
|
|
219
|
+
owner_address: { _eq: address },
|
|
220
|
+
};
|
|
221
|
+
if (contractAddress !== undefined && contractAddress !== "") {
|
|
222
|
+
whereCondition.asset_type = { _eq: contractAddress };
|
|
223
|
+
}
|
|
224
|
+
const response = await this.aptosClient.getCurrentFungibleAssetBalances({
|
|
225
|
+
options: {
|
|
226
|
+
where: whereCondition,
|
|
267
227
|
},
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
}
|
|
228
|
+
});
|
|
229
|
+
return response.map(x => ({
|
|
230
|
+
contractAddress: x.asset_type ?? "",
|
|
231
|
+
amount: BigNumber(x.amount),
|
|
232
|
+
}));
|
|
233
|
+
}
|
|
234
|
+
catch (error) {
|
|
235
|
+
log("error", "getCoinBalance", {
|
|
236
|
+
error,
|
|
237
|
+
});
|
|
238
|
+
return [{ amount: BigNumber(0), contractAddress: "" }];
|
|
239
|
+
}
|
|
274
240
|
}
|
|
275
241
|
}
|
|
276
242
|
//# sourceMappingURL=client.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/network/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE7D,OAAO,EAEL,KAAK,EACL,WAAW,EACX,gBAAgB,EAIhB,QAAQ,EAOR,GAAG,EACH,iBAAiB,GAElB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,OAAO,MAAM,wBAAwB,CAAC;AAC7C,OAAO,SAAS,MAAM,cAAc,CAAC;AACrC,OAAO,WAAW,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EACL,cAAc,EACd,WAAW,EACX,iBAAiB,EACjB,gBAAgB,EAChB,UAAU,GACX,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,0BAA0B,EAAE,4BAA4B,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/network/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE7D,OAAO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AAG,EAAE,OAAO,EAAE;aAChC,CAAC;YAEF,IAAI,eAAe,KAAK,SAAS,IAAI,eAAe,KAAK,EAAE,EAAE,CAAC;gBAC5D,cAAc,CAAC,UAAU,GAAG,EAAE,GAAG,EAAE,eAAe,EAAE,CAAC;YACvD,CAAC;YAED,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,+BAA+B,CAAC;gBACtE,OAAO,EAAE;oBACP,KAAK,EAAE,cAAc;iBACtB;aACF,CAAC,CAAC;YAEH,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;gBACxB,eAAe,EAAE,CAAC,CAAC,UAAU,IAAI,EAAE;gBACnC,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC;aAC5B,CAAC,CAAC,CAAC;QACN,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,GAAG,CAAC,OAAO,EAAE,gBAAgB,EAAE;gBAC7B,KAAK;aACN,CAAC,CAAC;YACH,OAAO,CAAC,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC,EAAE,eAAe,EAAE,EAAE,EAAE,CAAC,CAAC;QACzD,CAAC;IACH,CAAC;CACF"}
|
package/lib-es/types/assets.d.ts
CHANGED
|
@@ -5,10 +5,6 @@ export type AptosTokenInformation = {
|
|
|
5
5
|
contractAddress: string;
|
|
6
6
|
};
|
|
7
7
|
export type AptosExtra = Record<string, unknown>;
|
|
8
|
-
export type AptosSender = {
|
|
9
|
-
xpub: string;
|
|
10
|
-
freshAddress: string;
|
|
11
|
-
};
|
|
12
8
|
export type AptosFeeParameters = {
|
|
13
9
|
gasLimit: bigint;
|
|
14
10
|
gasPrice: bigint;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assets.d.ts","sourceRoot":"","sources":["../../src/types/assets.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oCAAoC,CAAC;AAEhE,MAAM,MAAM,UAAU,GAAG,KAAK,CAAC,qBAAqB,CAAC,CAAC;AAEtD,MAAM,MAAM,qBAAqB,GAAG;IAClC,QAAQ,EAAE,MAAM,CAAC;IACjB,eAAe,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEjD,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"assets.d.ts","sourceRoot":"","sources":["../../src/types/assets.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oCAAoC,CAAC;AAEhE,MAAM,MAAM,UAAU,GAAG,KAAK,CAAC,qBAAqB,CAAC,CAAC;AAEtD,MAAM,MAAM,qBAAqB,GAAG;IAClC,QAAQ,EAAE,MAAM,CAAC;IACjB,eAAe,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEjD,MAAM,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ledgerhq/coin-aptos",
|
|
3
|
-
"version": "2.2.0-
|
|
3
|
+
"version": "2.2.0-nightly.2",
|
|
4
4
|
"description": "Ledger Aptos Coin integration",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ledger",
|
|
@@ -90,14 +90,14 @@
|
|
|
90
90
|
"invariant": "^2.2.4",
|
|
91
91
|
"lodash": "^4.17.21",
|
|
92
92
|
"rxjs": "^7.8.1",
|
|
93
|
-
"@ledgerhq/coin-framework": "^5.3.0-
|
|
94
|
-
"@ledgerhq/cryptoassets": "^13.18.1-
|
|
95
|
-
"@ledgerhq/devices": "8.4.
|
|
96
|
-
"@ledgerhq/errors": "^6.
|
|
97
|
-
"@ledgerhq/live-env": "^2.
|
|
98
|
-
"@ledgerhq/live-network": "^2.0.10-
|
|
93
|
+
"@ledgerhq/coin-framework": "^5.3.0-nightly.2",
|
|
94
|
+
"@ledgerhq/cryptoassets": "^13.18.1-nightly.0",
|
|
95
|
+
"@ledgerhq/devices": "8.4.7-nightly.0",
|
|
96
|
+
"@ledgerhq/errors": "^6.22.0-nightly.0",
|
|
97
|
+
"@ledgerhq/live-env": "^2.9.1-nightly.0",
|
|
98
|
+
"@ledgerhq/live-network": "^2.0.10-nightly.0",
|
|
99
99
|
"@ledgerhq/logs": "^6.13.0",
|
|
100
|
-
"@ledgerhq/types-live": "^6.73.0-
|
|
100
|
+
"@ledgerhq/types-live": "^6.73.0-nightly.1"
|
|
101
101
|
},
|
|
102
102
|
"devDependencies": {
|
|
103
103
|
"@faker-js/faker": "^9.4.0",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Hex, RawTransaction, Deserializer } from "@aptos-labs/ts-sdk";
|
|
2
|
-
import type { TransactionIntent } from "@ledgerhq/coin-framework/
|
|
2
|
+
import type { TransactionIntent } from "@ledgerhq/coin-framework/api/types";
|
|
3
3
|
import { createApi } from "../../api";
|
|
4
|
-
import type { AptosAsset
|
|
4
|
+
import type { AptosAsset } from "../../types/assets";
|
|
5
5
|
import { AptosAPI } from "../../network";
|
|
6
6
|
import { APTOS_ASSET_ID } from "../../constants";
|
|
7
7
|
|
|
@@ -41,20 +41,17 @@ describe("craftTransaction", () => {
|
|
|
41
41
|
getBalances: mockGetBalances,
|
|
42
42
|
}));
|
|
43
43
|
|
|
44
|
-
const SENDER: AptosSender = {
|
|
45
|
-
xpub: "public-key",
|
|
46
|
-
freshAddress: SENDER_ADDR,
|
|
47
|
-
};
|
|
48
44
|
const api = createApi({
|
|
49
45
|
aptosSettings: {},
|
|
50
46
|
});
|
|
51
47
|
|
|
52
|
-
const txArg: TransactionIntent<AptosAsset
|
|
48
|
+
const txArg: TransactionIntent<AptosAsset> = {
|
|
53
49
|
type: "send",
|
|
54
|
-
sender:
|
|
50
|
+
sender: SENDER_ADDR,
|
|
51
|
+
senderPublicKey: "public-key",
|
|
55
52
|
recipient: RECIPIENT_ADDR,
|
|
56
53
|
amount: 10n,
|
|
57
|
-
asset: { type: "
|
|
54
|
+
asset: { type: "token", standard: "coin", contractAddress: "0x42::token::Token" },
|
|
58
55
|
};
|
|
59
56
|
|
|
60
57
|
const tx = await api.craftTransaction(txArg);
|
|
@@ -65,10 +62,10 @@ describe("craftTransaction", () => {
|
|
|
65
62
|
expect(mockGenerateTransaction).toHaveBeenCalledTimes(1);
|
|
66
63
|
|
|
67
64
|
expect(mockGenerateTransaction).toHaveBeenCalledWith(
|
|
68
|
-
|
|
65
|
+
SENDER_ADDR,
|
|
69
66
|
expect.objectContaining({
|
|
70
67
|
function: "0x1::aptos_account::transfer_coins",
|
|
71
|
-
typeArguments: [
|
|
68
|
+
typeArguments: ["0x42::token::Token"],
|
|
72
69
|
functionArguments: [RECIPIENT_ADDR, txArg.amount.toString()],
|
|
73
70
|
}),
|
|
74
71
|
expect.anything(),
|
|
@@ -85,17 +82,14 @@ describe("craftTransaction", () => {
|
|
|
85
82
|
getBalances: mockGetBalances,
|
|
86
83
|
}));
|
|
87
84
|
|
|
88
|
-
const SENDER: AptosSender = {
|
|
89
|
-
xpub: "public-key",
|
|
90
|
-
freshAddress: SENDER_ADDR,
|
|
91
|
-
};
|
|
92
85
|
const api = createApi({
|
|
93
86
|
aptosSettings: {},
|
|
94
87
|
});
|
|
95
88
|
|
|
96
|
-
const txArg: TransactionIntent<AptosAsset
|
|
89
|
+
const txArg: TransactionIntent<AptosAsset> = {
|
|
97
90
|
type: "send",
|
|
98
|
-
sender:
|
|
91
|
+
sender: SENDER_ADDR,
|
|
92
|
+
senderPublicKey: "public-key",
|
|
99
93
|
recipient: RECIPIENT_ADDR,
|
|
100
94
|
amount: 0n,
|
|
101
95
|
asset: { type: "native" },
|
|
@@ -109,7 +103,7 @@ describe("craftTransaction", () => {
|
|
|
109
103
|
expect(mockGenerateTransaction).toHaveBeenCalledTimes(1);
|
|
110
104
|
|
|
111
105
|
expect(mockGenerateTransaction).toHaveBeenCalledWith(
|
|
112
|
-
|
|
106
|
+
SENDER_ADDR,
|
|
113
107
|
expect.objectContaining({
|
|
114
108
|
function: "0x1::aptos_account::transfer_coins",
|
|
115
109
|
typeArguments: [APTOS_ASSET_ID],
|
|
@@ -129,17 +123,14 @@ describe("craftTransaction", () => {
|
|
|
129
123
|
getBalances: mockGetBalances,
|
|
130
124
|
}));
|
|
131
125
|
|
|
132
|
-
const SENDER: AptosSender = {
|
|
133
|
-
xpub: "public-key",
|
|
134
|
-
freshAddress: SENDER_ADDR,
|
|
135
|
-
};
|
|
136
126
|
const api = createApi({
|
|
137
127
|
aptosSettings: {},
|
|
138
128
|
});
|
|
139
129
|
|
|
140
|
-
const txArg: TransactionIntent<AptosAsset
|
|
130
|
+
const txArg: TransactionIntent<AptosAsset> = {
|
|
141
131
|
type: "send",
|
|
142
|
-
sender:
|
|
132
|
+
sender: SENDER_ADDR,
|
|
133
|
+
senderPublicKey: "public-key",
|
|
143
134
|
recipient: RECIPIENT_ADDR,
|
|
144
135
|
amount: 10n,
|
|
145
136
|
asset: { type: "token", standard: "coin", contractAddress: "0x42::token::Token" },
|
|
@@ -153,7 +144,7 @@ describe("craftTransaction", () => {
|
|
|
153
144
|
expect(mockGenerateTransaction).toHaveBeenCalledTimes(1);
|
|
154
145
|
|
|
155
146
|
expect(mockGenerateTransaction).toHaveBeenCalledWith(
|
|
156
|
-
|
|
147
|
+
SENDER_ADDR,
|
|
157
148
|
expect.objectContaining({
|
|
158
149
|
function: "0x1::aptos_account::transfer_coins",
|
|
159
150
|
typeArguments: ["0x42::token::Token"],
|
|
@@ -173,17 +164,14 @@ describe("craftTransaction", () => {
|
|
|
173
164
|
getBalances: mockGetBalances,
|
|
174
165
|
}));
|
|
175
166
|
|
|
176
|
-
const SENDER: AptosSender = {
|
|
177
|
-
xpub: "public-key",
|
|
178
|
-
freshAddress: SENDER_ADDR,
|
|
179
|
-
};
|
|
180
167
|
const api = createApi({
|
|
181
168
|
aptosSettings: {},
|
|
182
169
|
});
|
|
183
170
|
|
|
184
|
-
const txArg: TransactionIntent<AptosAsset
|
|
171
|
+
const txArg: TransactionIntent<AptosAsset> = {
|
|
185
172
|
type: "send",
|
|
186
|
-
sender:
|
|
173
|
+
sender: SENDER_ADDR,
|
|
174
|
+
senderPublicKey: "public-key",
|
|
187
175
|
recipient: RECIPIENT_ADDR,
|
|
188
176
|
amount: 0n,
|
|
189
177
|
asset: { type: "token", standard: "fungible_asset", contractAddress: "0x42" },
|
|
@@ -197,7 +185,7 @@ describe("craftTransaction", () => {
|
|
|
197
185
|
expect(mockGenerateTransaction).toHaveBeenCalledTimes(1);
|
|
198
186
|
|
|
199
187
|
expect(mockGenerateTransaction).toHaveBeenCalledWith(
|
|
200
|
-
|
|
188
|
+
SENDER_ADDR,
|
|
201
189
|
expect.objectContaining({
|
|
202
190
|
function: "0x1::primary_fungible_store::transfer",
|
|
203
191
|
typeArguments: ["0x1::fungible_asset::Metadata"],
|
|
@@ -217,17 +205,14 @@ describe("craftTransaction", () => {
|
|
|
217
205
|
getBalances: mockGetBalances,
|
|
218
206
|
}));
|
|
219
207
|
|
|
220
|
-
const SENDER: AptosSender = {
|
|
221
|
-
xpub: "public-key",
|
|
222
|
-
freshAddress: SENDER_ADDR,
|
|
223
|
-
};
|
|
224
208
|
const api = createApi({
|
|
225
209
|
aptosSettings: {},
|
|
226
210
|
});
|
|
227
211
|
|
|
228
|
-
const txArg: TransactionIntent<AptosAsset
|
|
212
|
+
const txArg: TransactionIntent<AptosAsset> = {
|
|
229
213
|
type: "send",
|
|
230
|
-
sender:
|
|
214
|
+
sender: SENDER_ADDR,
|
|
215
|
+
senderPublicKey: "public-key",
|
|
231
216
|
recipient: RECIPIENT_ADDR,
|
|
232
217
|
amount: 10n,
|
|
233
218
|
asset: { type: "token", standard: "asset", contractAddress: "0x42::token::Token" },
|
|
@@ -1,44 +1,98 @@
|
|
|
1
1
|
import { AptosAPI } from "../../network";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
jest.mock("../../network", () => {
|
|
7
|
-
return {
|
|
8
|
-
AptosAPI: jest.fn().mockImplementation(() => ({
|
|
9
|
-
getBalances: jest.fn(),
|
|
10
|
-
})),
|
|
11
|
-
};
|
|
12
|
-
});
|
|
2
|
+
import { APTOS_ASSET_ID, TOKEN_TYPE } from "../../constants";
|
|
3
|
+
import type { AptosConfig } from "../../config";
|
|
4
|
+
import { createApi } from "../../api";
|
|
13
5
|
|
|
14
|
-
|
|
15
|
-
|
|
6
|
+
jest.mock("@aptos-labs/ts-sdk");
|
|
7
|
+
let mockedAptosApi: jest.Mocked<any>;
|
|
8
|
+
jest.mock("../../network");
|
|
9
|
+
jest.mock("../../config", () => ({
|
|
10
|
+
setCoinConfig: jest.fn(),
|
|
11
|
+
}));
|
|
16
12
|
|
|
13
|
+
const mockAptosConfig: AptosConfig = {} as AptosConfig;
|
|
14
|
+
|
|
15
|
+
describe("getBalance", () => {
|
|
17
16
|
beforeEach(() => {
|
|
18
|
-
jest.
|
|
17
|
+
mockedAptosApi = jest.mocked(AptosAPI);
|
|
18
|
+
});
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
afterEach(() => {
|
|
21
|
+
jest.resetAllMocks();
|
|
22
|
+
});
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
it("should return balance with value 10", async () => {
|
|
25
|
+
mockedAptosApi.mockImplementation(() => ({
|
|
26
|
+
getBalances: jest.fn().mockResolvedValue([{ contractAddress: APTOS_ASSET_ID, amount: 10n }]),
|
|
26
27
|
}));
|
|
28
|
+
|
|
29
|
+
const api = createApi(mockAptosConfig);
|
|
30
|
+
const accountAddress = "0x4be47904b31063d60ac0dfde06e5dc203e647edbe853bae0e666ae5a763c3906";
|
|
31
|
+
|
|
32
|
+
expect(await api.getBalance(accountAddress)).toStrictEqual([
|
|
33
|
+
{ value: 10n, asset: { type: "native" } },
|
|
34
|
+
]);
|
|
27
35
|
});
|
|
28
36
|
|
|
29
|
-
|
|
30
|
-
|
|
37
|
+
it("should return empty array when no contract_address and no data", async () => {
|
|
38
|
+
mockedAptosApi.mockImplementation(() => ({
|
|
39
|
+
getBalances: jest.fn().mockResolvedValue([]),
|
|
40
|
+
}));
|
|
41
|
+
|
|
42
|
+
const accountAddress = "0xno_contract_and_no_data";
|
|
43
|
+
|
|
44
|
+
const api = createApi(mockAptosConfig);
|
|
45
|
+
expect(await api.getBalance(accountAddress)).toStrictEqual([]);
|
|
31
46
|
});
|
|
32
47
|
|
|
33
|
-
it("should
|
|
34
|
-
|
|
48
|
+
it("should return balance with 'native' contract_address (APTOS_ASSET_ID)", async () => {
|
|
49
|
+
mockedAptosApi.mockImplementation(() => ({
|
|
50
|
+
getBalances: jest.fn().mockResolvedValue([{ contractAddress: APTOS_ASSET_ID, amount: 15n }]),
|
|
51
|
+
}));
|
|
52
|
+
|
|
53
|
+
const api = createApi(mockAptosConfig);
|
|
54
|
+
const accountAddress = "0x4be47904b31063d60ac0dfde06e5dc203e647edbe853bae0e666ae5a763c3906";
|
|
55
|
+
|
|
56
|
+
expect(await api.getBalance(accountAddress)).toStrictEqual([
|
|
57
|
+
{ value: 15n, asset: { type: "native" } },
|
|
58
|
+
]);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it("should return token balance when contract_address is a coin token", async () => {
|
|
62
|
+
const TOKEN_ASSET_ID = "0x1::my_token::Token";
|
|
63
|
+
mockedAptosApi.mockImplementation(() => ({
|
|
64
|
+
getBalances: jest.fn().mockResolvedValue([{ contractAddress: TOKEN_ASSET_ID, amount: 25n }]),
|
|
65
|
+
}));
|
|
66
|
+
|
|
67
|
+
const api = createApi(mockAptosConfig);
|
|
68
|
+
const accountAddress = "0x4be47904b31063d60ac0dfde06e5dc203e647edbe853bae0e666ae5a763c3906";
|
|
69
|
+
|
|
70
|
+
expect(await api.getBalance(accountAddress)).toStrictEqual([
|
|
71
|
+
{
|
|
72
|
+
value: 25n,
|
|
73
|
+
asset: { type: "token", contractAddress: TOKEN_ASSET_ID, standard: TOKEN_TYPE.COIN },
|
|
74
|
+
},
|
|
75
|
+
]);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it("should return token balance when contract_address is a fungible_asset token", async () => {
|
|
79
|
+
const TOKEN_ASSET_ID = "0x1";
|
|
80
|
+
mockedAptosApi.mockImplementation(() => ({
|
|
81
|
+
getBalances: jest.fn().mockResolvedValue([{ contractAddress: TOKEN_ASSET_ID, amount: 25n }]),
|
|
82
|
+
}));
|
|
35
83
|
|
|
84
|
+
const api = createApi(mockAptosConfig);
|
|
36
85
|
const accountAddress = "0x4be47904b31063d60ac0dfde06e5dc203e647edbe853bae0e666ae5a763c3906";
|
|
37
|
-
const client = new AptosAPI("aptos");
|
|
38
|
-
const balance = await getBalance(client, accountAddress);
|
|
39
86
|
|
|
40
|
-
expect(
|
|
41
|
-
|
|
42
|
-
|
|
87
|
+
expect(await api.getBalance(accountAddress)).toStrictEqual([
|
|
88
|
+
{
|
|
89
|
+
value: 25n,
|
|
90
|
+
asset: {
|
|
91
|
+
type: "token",
|
|
92
|
+
contractAddress: TOKEN_ASSET_ID,
|
|
93
|
+
standard: TOKEN_TYPE.FUNGIBLE_ASSET,
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
]);
|
|
43
97
|
});
|
|
44
98
|
});
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Deserializer, Hex, Network, RawTransaction } from "@aptos-labs/ts-sdk";
|
|
2
2
|
import { createApi } from "../../api";
|
|
3
3
|
import { getEnv } from "@ledgerhq/live-env";
|
|
4
|
-
import type { AptosSender } from "../../types/assets";
|
|
5
4
|
import { DEFAULT_GAS, DEFAULT_GAS_PRICE } from "../../constants";
|
|
6
5
|
|
|
7
6
|
describe("createApi", () => {
|
|
@@ -12,18 +11,20 @@ describe("createApi", () => {
|
|
|
12
11
|
indexer: getEnv("APTOS_INDEXER_ENDPOINT"),
|
|
13
12
|
},
|
|
14
13
|
});
|
|
14
|
+
const assetTypeNative = "native";
|
|
15
|
+
const assetTypeToken = "token";
|
|
15
16
|
|
|
16
|
-
const sender
|
|
17
|
+
const sender = {
|
|
17
18
|
xpub: "0x934887885b27a0407bf8a5e0bbc6b6371254bea94de5510e948bcc92dc0a519b",
|
|
18
19
|
freshAddress: "0x0ef3b40f6ecd5583218d1985e0d54b54e8785ad2ec2d27ed1720ec16bb11686f",
|
|
19
20
|
};
|
|
20
21
|
|
|
21
|
-
const recipient
|
|
22
|
+
const recipient = {
|
|
22
23
|
xpub: "0x7fd6bfaac17c2c763f624b1f95cd4911e3646a5b777b03cc24f93ed0ac3f3e2b",
|
|
23
24
|
freshAddress: "0x4859a161dfe13081cf5a5eac409cd38f707c06176a21ddc875260c2ce63f3a28",
|
|
24
25
|
};
|
|
25
26
|
|
|
26
|
-
const tokenAccount
|
|
27
|
+
const tokenAccount = {
|
|
27
28
|
xpub: "0xeacada8192f15185637e475d7783e14486e232d8b9978ffa127383847ffc5318",
|
|
28
29
|
freshAddress: "0xb8922507317d85197d70c2bc1afc949c759fd0a62c8841a4300d1e2b63649bf6",
|
|
29
30
|
};
|
|
@@ -56,7 +57,8 @@ describe("createApi", () => {
|
|
|
56
57
|
type: "native",
|
|
57
58
|
},
|
|
58
59
|
type: "send",
|
|
59
|
-
sender,
|
|
60
|
+
sender: sender.freshAddress,
|
|
61
|
+
senderPublicKey: sender.xpub,
|
|
60
62
|
amount,
|
|
61
63
|
recipient: recipient.freshAddress,
|
|
62
64
|
});
|
|
@@ -75,7 +77,8 @@ describe("createApi", () => {
|
|
|
75
77
|
"0x50788befc1107c0cc4473848a92e5c783c635866ce3c98de71d2eeb7d2a34f85::usdc_coin::USDCoin",
|
|
76
78
|
},
|
|
77
79
|
type: "send",
|
|
78
|
-
sender,
|
|
80
|
+
sender: sender.freshAddress,
|
|
81
|
+
senderPublicKey: sender.xpub,
|
|
79
82
|
amount,
|
|
80
83
|
recipient: recipient.freshAddress,
|
|
81
84
|
});
|
|
@@ -93,7 +96,8 @@ describe("createApi", () => {
|
|
|
93
96
|
contractAddress: "0x357b0b74bc833e95a115ad22604854d6b0fca151cecd94111770e5d6ffc9dc2b",
|
|
94
97
|
},
|
|
95
98
|
type: "send",
|
|
96
|
-
sender,
|
|
99
|
+
sender: sender.freshAddress,
|
|
100
|
+
senderPublicKey: sender.xpub,
|
|
97
101
|
amount,
|
|
98
102
|
recipient: recipient.freshAddress,
|
|
99
103
|
});
|
|
@@ -107,7 +111,8 @@ describe("createApi", () => {
|
|
|
107
111
|
const hex = await api.craftTransaction(
|
|
108
112
|
{
|
|
109
113
|
amount: 1n,
|
|
110
|
-
sender: sender,
|
|
114
|
+
sender: sender.freshAddress,
|
|
115
|
+
senderPublicKey: sender.xpub,
|
|
111
116
|
recipient: recipient.freshAddress,
|
|
112
117
|
type: "send",
|
|
113
118
|
asset: { type: "native" },
|
|
@@ -128,7 +133,8 @@ describe("createApi", () => {
|
|
|
128
133
|
const hex = await api.craftTransaction(
|
|
129
134
|
{
|
|
130
135
|
amount: 1n,
|
|
131
|
-
sender: sender,
|
|
136
|
+
sender: sender.freshAddress,
|
|
137
|
+
senderPublicKey: sender.xpub,
|
|
132
138
|
recipient: recipient.freshAddress,
|
|
133
139
|
type: "send",
|
|
134
140
|
asset: {
|
|
@@ -154,7 +160,8 @@ describe("createApi", () => {
|
|
|
154
160
|
const hex = await api.craftTransaction(
|
|
155
161
|
{
|
|
156
162
|
amount: 0n,
|
|
157
|
-
sender: sender,
|
|
163
|
+
sender: sender.freshAddress,
|
|
164
|
+
senderPublicKey: sender.xpub,
|
|
158
165
|
recipient: recipient.freshAddress,
|
|
159
166
|
type: "send",
|
|
160
167
|
asset: {
|
|
@@ -182,7 +189,8 @@ describe("createApi", () => {
|
|
|
182
189
|
const hex = await api.craftTransaction(
|
|
183
190
|
{
|
|
184
191
|
amount: 0n,
|
|
185
|
-
sender: s,
|
|
192
|
+
sender: s.freshAddress,
|
|
193
|
+
senderPublicKey: s.xpub,
|
|
186
194
|
recipient: r.freshAddress,
|
|
187
195
|
type: "send",
|
|
188
196
|
asset: {
|
|
@@ -204,12 +212,25 @@ describe("createApi", () => {
|
|
|
204
212
|
});
|
|
205
213
|
});
|
|
206
214
|
|
|
207
|
-
describe("
|
|
208
|
-
it("
|
|
215
|
+
describe("getBalances", () => {
|
|
216
|
+
it("returned balances should have one native asset", async () => {
|
|
209
217
|
const balances = await api.getBalance(sender.freshAddress);
|
|
218
|
+
const nativeBalance = balances.filter(b => b.asset.type === assetTypeNative);
|
|
219
|
+
expect(nativeBalance.length).toBe(1);
|
|
220
|
+
expect(nativeBalance[0].value).toBeGreaterThan(0);
|
|
221
|
+
});
|
|
210
222
|
|
|
211
|
-
|
|
212
|
-
|
|
223
|
+
it("returned balances should have a token asset", async () => {
|
|
224
|
+
const balances = await api.getBalance(tokenAccount.freshAddress);
|
|
225
|
+
const tokenBalances = balances.filter(
|
|
226
|
+
b =>
|
|
227
|
+
b.asset.type === assetTypeToken &&
|
|
228
|
+
b.asset.contractAddress ===
|
|
229
|
+
"0x2ebb2ccac5e027a87fa0e2e5f656a3a4238d6a48d93ec9b610d570fc0aa0df12",
|
|
230
|
+
);
|
|
231
|
+
expect(tokenBalances.length).toBeGreaterThan(0);
|
|
232
|
+
expect(balances.length).toBeGreaterThan(1);
|
|
233
|
+
expect(balances[0].value).toBeGreaterThan(0);
|
|
213
234
|
});
|
|
214
235
|
});
|
|
215
236
|
|