Skip to content

Commit

Permalink
feat: add support coin aptos (#428)
Browse files Browse the repository at this point in the history
add swap support for aptos
  • Loading branch information
jccguimaraes authored Jan 31, 2025
1 parent 89c205a commit 9724dce
Show file tree
Hide file tree
Showing 10 changed files with 157 additions and 54 deletions.
5 changes: 5 additions & 0 deletions .changeset/hot-pianos-juggle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ledgerhq/wallet-api-core": minor
---

add support for coin aptos
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ Each wallet and application then needs to implement this interface. In this repo
| decred (bitcoin) |||
| digibyte (bitcoin) |||
| algorand |||
| aptos |||
| qtum (bitcoin) |||
| bitcoin_gold (bitcoin) |||
| komodo (bitcoin) |||
Expand Down
30 changes: 30 additions & 0 deletions packages/core/src/families/aptos/serializer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import BigNumber from "bignumber.js";
import type { AptosTransaction, RawAptosTransaction } from "./types";

export const serializeAptosTransaction = ({
family,
mode,
fees,
amount,
recipient,
}: AptosTransaction): RawAptosTransaction => ({
family,
amount: amount.toString(),
recipient,
fees: fees ? fees.toString() : undefined,
mode,
});

export const deserializeAptosTransaction = ({
family,
mode,
fees,
amount,
recipient,
}: RawAptosTransaction): AptosTransaction => ({
family,
amount: new BigNumber(amount),
recipient,
fees: fees ? new BigNumber(fees) : undefined,
mode,
});
17 changes: 17 additions & 0 deletions packages/core/src/families/aptos/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import type BigNumber from "bignumber.js";
import type { z } from "zod";
import type { TransactionCommon } from "../index";
import type {
schemaAptosOperationMode,
schemaRawAptosTransaction,
} from "./validation";

export type AptosOperationMode = z.infer<typeof schemaAptosOperationMode>;

export type AptosTransaction = TransactionCommon & {
readonly family: RawAptosTransaction["family"];
mode: AptosOperationMode;
fees?: BigNumber;
};

export type RawAptosTransaction = z.infer<typeof schemaRawAptosTransaction>;
10 changes: 10 additions & 0 deletions packages/core/src/families/aptos/validation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { z } from "zod";
import { schemaFamilies, schemaTransactionCommon } from "../common";

export const schemaAptosOperationMode = z.enum(["send"]);

export const schemaRawAptosTransaction = schemaTransactionCommon.extend({
family: z.literal(schemaFamilies.enum.aptos),
mode: schemaAptosOperationMode,
fees: z.string().optional(),
});
1 change: 1 addition & 0 deletions packages/core/src/families/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const schemaTransactionCommon = z.object({

export const FAMILIES = [
"algorand",
"aptos",
"bitcoin",
"cardano",
"casper",
Expand Down
8 changes: 8 additions & 0 deletions packages/core/src/families/serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import {
deserializeAlgorandTransaction,
serializeAlgorandTransaction,
} from "./algorand/serializer";
import {
deserializeAptosTransaction,
serializeAptosTransaction,
} from "./aptos/serializer";
import {
deserializeBitcoinTransaction,
serializeBitcoinTransaction,
Expand Down Expand Up @@ -101,6 +105,8 @@ export function serializeTransaction(transaction: Transaction): RawTransaction {
return serializeBitcoinTransaction(transaction);
case "algorand":
return serializeAlgorandTransaction(transaction);
case "aptos":
return serializeAptosTransaction(transaction);
case "crypto_org":
return serializeCryptoOrgTransaction(transaction);
case "ripple":
Expand Down Expand Up @@ -166,6 +172,8 @@ export function deserializeTransaction(
return deserializeBitcoinTransaction(rawTransaction);
case "algorand":
return deserializeAlgorandTransaction(rawTransaction);
case "aptos":
return deserializeAptosTransaction(rawTransaction);
case "crypto_org":
return deserializeCryptoOrgTransaction(rawTransaction);
case "ripple":
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/families/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type BigNumber from "bignumber.js";
import type { z } from "zod";
import type { AlgorandTransaction } from "./algorand/types";
import type { AptosTransaction } from "./aptos/types";
import type { BitcoinTransaction } from "./bitcoin/types";
import type { CardanoTransaction } from "./cardano/types";
import type { CeloTransaction } from "./celo/types";
Expand Down Expand Up @@ -70,6 +71,7 @@ export type Transaction =
| EthereumTransaction
| BitcoinTransaction
| AlgorandTransaction
| AptosTransaction
| CryptoOrgTransaction
| HederaTransaction
| FilecoinTransaction
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/families/validation.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { z } from "zod";
import { schemaRawAlgorandTransaction } from "./algorand/validation";
import { schemaRawAptosTransaction } from "./aptos/validation";
import { schemaRawBitcoinTransaction } from "./bitcoin/validation";
import { schemaRawCeloTransaction } from "./celo/validation";
import { schemaRawCosmosTransaction } from "./cosmos/validation";
Expand All @@ -25,6 +26,7 @@ import { schemaRawCasperTransaction } from "./casper/validation";

export const schemaRawTransaction = z.discriminatedUnion("family", [
schemaRawAlgorandTransaction,
schemaRawAptosTransaction,
schemaRawBitcoinTransaction,
schemaRawCeloTransaction,
schemaRawCosmosTransaction,
Expand Down
135 changes: 81 additions & 54 deletions spec/core/types.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,58 +12,62 @@ Some types are defined as _raw_, usually in the form `Raw[TYPE-NAME]`. These typ

## Table of Contents

- [Transactions](#transactions)
- [Transaction](#transaction)
- [RawTransaction](#rawtransaction)
- [TransactionCommon](#transactioncommon)
- [RawTransactionCommon](#rawtransactioncommon)
- [AlgorandTransaction](#algorandtransaction)
- [RawAlgorandTransaction](#rawalgorandtransaction)
- [BitcoinTransaction](#bitcointransaction)
- [RawBitcoinTransaction](#rawbitcointransaction)
- [CosmosTransaction](#cosmostransaction)
- [RawCosmosTransaction](#rawcosmostransaction)
- [CryptoOrgTransaction](#cryptoorgtransaction)
- [RawCryptoOrgTransaction](#rawcryptoorgtransaction)
- [EthereumTransaction](#ethereumtransaction)
- [RawEthereumTransaction](#rawethereumtransaction)
- [PolkadotTransaction](#polkadottransaction)
- [RawPolkadotTransaction](#rawpolkadottransaction)
- [RippleTransaction](#rippletransaction)
- [RawRippleTransaction](#rawrippletransaction)
- [StellarTransaction](#stellartransaction)
- [RawStellarTransaction](#rawstellartransaction)
- [TezosTransaction](#tezostransaction)
- [RawTezosTransaction](#rawtezostransaction)
- [TronTransaction](#trontransaction)
- [RawTronTransaction](#rawtrontransaction)
- [Enums](#enums)
- [CurrencyType](#currencytype)
- [ExchangeType](#exchangetype)
- [FAMILIES](#families)
- [FeesLevel](#feeslevel)
- [TokenStandard](#tokenstandard)
- [Account](#account)
- [RawAccount](#rawaccount)
- [TronOperationMode](#tronoperationmode)
- [TronResource](#tronresource)
- [AlgorandOperationMode](#algorandoperationmode)
- [CosmosOperationMode](#cosmosoperationmode)
- [PolkadotOperationMode](#polkadotoperationmode)
- [TezosOperationMode](#tezosoperationmode)
- [StellarMemoType](#stellarmemotype)
- [ApplicationDetails](#applicationdetails)
- [BaseCurrency](#basecurrency)
- [CryptoCurrency](#cryptocurrency)
- [Currency](#currency)
- [DeviceInfo](#deviceinfo)
- [ERC20TokenCurrency](#erc20tokencurrency)
- [EcdsaSignature](#ecdsasignature)
- [ExchangeDeviceTxId](#exchangedevicetxid)
- [ExchangePayload](#exchangepayload)
- [RawSignedTransaction](#rawsignedtransaction)
- [TokenCurrency](#tokencurrency)
- [Unit](#unit)
- [Types](#types)
- [Table of Contents](#table-of-contents)
- [Transactions](#transactions)
- [Transaction](#transaction)
- [RawTransaction](#rawtransaction)
- [TransactionCommon](#transactioncommon)
- [RawTransactionCommon](#rawtransactioncommon)
- [AlgorandTransaction](#algorandtransaction)
- [RawAlgorandTransaction](#rawalgorandtransaction)
- [AptosTransaction](#aptostransaction)
- [RawAptosTransaction](#rawaptostransaction)
- [BitcoinTransaction](#bitcointransaction)
- [RawBitcoinTransaction](#rawbitcointransaction)
- [CosmosTransaction](#cosmostransaction)
- [RawCosmosTransaction](#rawcosmostransaction)
- [CryptoOrgTransaction](#cryptoorgtransaction)
- [RawCryptoOrgTransaction](#rawcryptoorgtransaction)
- [EthereumTransaction](#ethereumtransaction)
- [RawEthereumTransaction](#rawethereumtransaction)
- [PolkadotTransaction](#polkadottransaction)
- [RawPolkadotTransaction](#rawpolkadottransaction)
- [RippleTransaction](#rippletransaction)
- [RawRippleTransaction](#rawrippletransaction)
- [StellarTransaction](#stellartransaction)
- [RawStellarTransaction](#rawstellartransaction)
- [TezosTransaction](#tezostransaction)
- [RawTezosTransaction](#rawtezostransaction)
- [TronTransaction](#trontransaction)
- [RawTronTransaction](#rawtrontransaction)
- [Enums](#enums)
- [CurrencyType](#currencytype)
- [ExchangeType](#exchangetype)
- [FAMILIES](#families)
- [FeesLevel](#feeslevel)
- [TokenStandard](#tokenstandard)
- [Account](#account)
- [RawAccount](#rawaccount)
- [TronOperationMode](#tronoperationmode)
- [TronResource](#tronresource)
- [AlgorandOperationMode](#algorandoperationmode)
- [CosmosOperationMode](#cosmosoperationmode)
- [PolkadotOperationMode](#polkadotoperationmode)
- [TezosOperationMode](#tezosoperationmode)
- [StellarMemoType](#stellarmemotype)
- [ApplicationDetails](#applicationdetails)
- [BaseCurrency](#basecurrency)
- [CryptoCurrency](#cryptocurrency)
- [Currency](#currency)
- [DeviceInfo](#deviceinfo)
- [ERC20TokenCurrency](#erc20tokencurrency)
- [EcdsaSignature](#ecdsasignature)
- [ExchangeDeviceTxId](#exchangedevicetxid)
- [ExchangePayload](#exchangepayload)
- [RawSignedTransaction](#rawsignedtransaction)
- [TokenCurrency](#tokencurrency)
- [Unit](#unit)

---

Expand All @@ -73,13 +77,14 @@ Some types are defined as _raw_, usually in the form `Raw[TYPE-NAME]`. These typ

Description of an unsigned transaction. This type is used to build transactions and then sign them with a Ledger device and finally broadcast them to the network upon user validation.

[`EthereumTransaction`](/spec/core/types.md#ethereumtransaction) \| [`BitcoinTransaction`](/spec/core/types.md#bitcointransaction) \| [`AlgorandTransaction`](/spec/core/types.md#algorandtransaction) \| [`CryptoOrgTransaction`](/spec/core/types.md#cryptoorgtransaction) \| [`RippleTransaction`](/spec/core/types.md#rippletransaction) \| [`CosmosTransaction`](/spec/core/types.md#cosmostransaction) \| [`TezosTransaction`](/spec/core/types.md#tezostransaction) \| [`PolkadotTransaction`](/spec/core/types.md#polkadottransaction) \| [`StellarTransaction`](/spec/core/types.md#stellartransaction) \| [`TronTransaction`](/spec/core/types.md#trontransaction)
[`EthereumTransaction`](/spec/core/types.md#ethereumtransaction) \| [`BitcoinTransaction`](/spec/core/types.md#bitcointransaction) \| [`AlgorandTransaction`](/spec/core/types.md#algorandtransaction) \|
[`AptosTransaction`](/spec/core/types.md#aptostransaction) \| [`CryptoOrgTransaction`](/spec/core/types.md#cryptoorgtransaction) \| [`RippleTransaction`](/spec/core/types.md#rippletransaction) \| [`CosmosTransaction`](/spec/core/types.md#cosmostransaction) \| [`TezosTransaction`](/spec/core/types.md#tezostransaction) \| [`PolkadotTransaction`](/spec/core/types.md#polkadottransaction) \| [`StellarTransaction`](/spec/core/types.md#stellartransaction) \| [`TronTransaction`](/spec/core/types.md#trontransaction)

### RawTransaction

The raw representation of the generic [Transaction](/spec/core/types.md#transaction) type.

[`RawEthereumTransaction`](/spec/core/types.md#rawethereumtransaction) \| [`RawBitcoinTransaction`](/spec/core/types.md#rawbitcointransaction) \| [`RawAlgorandTransaction`](/spec/core/types.md#rawalgorandtransaction) \| [`RawCryptoOrgTransaction`](/spec/core/types.md#rawcryptoorgtransaction) \| [`RawRippleTransaction`](/spec/core/types.md#rawrippletransaction) \| [`RawCosmosTransaction`](/spec/core/types.md#rawcosmostransaction) \| [`RawTezosTransaction`](/spec/core/types.md#rawtezostransaction) \| [`RawPolkadotTransaction`](/spec/core/types.md#rawpolkadottransaction) \| [`RawStellarTransaction`](/spec/core/types.md#rawstellartransaction) \| [`RawTronTransaction`](/spec/core/types.md#rawtrontransaction)
[`RawEthereumTransaction`](/spec/core/types.md#rawethereumtransaction) \| [`RawBitcoinTransaction`](/spec/core/types.md#rawbitcointransaction) \| [`RawAlgorandTransaction`](/spec/core/types.md#rawalgorandtransaction) \| [`RawAptosTransaction`](/spec/core/types.md#rawaptostransaction) \| [`RawCryptoOrgTransaction`](/spec/core/types.md#rawcryptoorgtransaction) \| [`RawRippleTransaction`](/spec/core/types.md#rawrippletransaction) \| [`RawCosmosTransaction`](/spec/core/types.md#rawcosmostransaction) \| [`RawTezosTransaction`](/spec/core/types.md#rawtezostransaction) \| [`RawPolkadotTransaction`](/spec/core/types.md#rawpolkadottransaction) \| [`RawStellarTransaction`](/spec/core/types.md#rawstellartransaction) \| [`RawTronTransaction`](/spec/core/types.md#rawtrontransaction)

### TransactionCommon

Expand Down Expand Up @@ -123,6 +128,28 @@ The raw representation of the common transaction fields found in [TransactionCom
| `mode` | [`AlgorandOperationMode`](/spec/core/types.md#algorandoperationmode) | |
| `recipient` | `string` | The address of the transaction's recipient |

### AptosTransaction

| Name | Type | Description |
| ----------- | -------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `amount` | `BigNumber` | The amount of token to send in the transaction, denoted in the smallest cryptocurrency's magnitude For example in BTC, a tx with an 'amount' field of 1 will correspond to a tx corresponding to 0.00000001 BTC |
| `assetId?` | `string` | |
| `family` | [`APTOS`](/spec/core/types.md#families) | |
| `fees?` | `BigNumber` | |
| `mode` | [`AptosOperationMode`](/spec/core/types.md#aptosoperationmode) | |
| `recipient` | `string` | The address of the transaction's recipient |

### RawAptosTransaction

| Name | Type | Description |
| ----------- | -------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `amount` | `string` | The amount of token to send in the transaction, denoted in the smallest cryptocurrency's magnitude For example in BTC, a tx with an 'amount' field of 1 will correspond to a tx corresponding to 0.00000001 BTC |
| `assetId?` | `string` | |
| `family` | [`APTOS`](/spec/core/types.md#families) | |
| `fees?` | `string \| undefined` | |
| `mode` | [`AptosOperationMode`](/spec/core/types.md#aptosoperationmode) | |
| `recipient` | `string` | The address of the transaction's recipient |

### BitcoinTransaction

| Name | Type | Description |
Expand Down

0 comments on commit 9724dce

Please sign in to comment.