Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swap NEAR #145

Open
wants to merge 22 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
13 changes: 13 additions & 0 deletions .github/workflows/reusable_swap_functional_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,15 @@ on:
default: 'LedgerHQ/app-tron'
type: string

branch_for_near:
required: false
default: 'y333_241015/add_swap_support'
type: string
repo_for_near:
required: false
default: 'LedgerHQ/app-near'
type: string

branch_for_ton:
required: false
default: 'develop'
Expand Down Expand Up @@ -177,6 +186,9 @@ jobs:
- name: cardano
repo: ${{ inputs.repo_for_cardano }}
branch: ${{ inputs.branch_for_cardano }}
- name: near
repo: ${{ inputs.repo_for_near }}
branch: ${{ inputs.branch_for_near }}

uses: LedgerHQ/ledger-app-workflows/.github/workflows/reusable_build.yml@v1
with:
Expand All @@ -187,6 +199,7 @@ jobs:
flags: "COIN=${{ matrix.coin.name }} CHAIN=${{ matrix.coin.name }} CAL_TEST_KEY=1 DOMAIN_NAME_TEST_KEY=1 SET_PLUGIN_TEST_KEY=1 NFT_TEST_KEY=1"
upload_app_binaries_artifact: libraries_binaries-${{ matrix.coin.name }}-${{ strategy.job-index }}
upload_as_lib_artifact: ${{ matrix.coin.name }}
builder: ledger-app-builder

merge_libraries_build:
name: Merge built libraries
Expand Down
2 changes: 2 additions & 0 deletions test/python/apps/cal.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from .tron import TRX_PACKED_DERIVATION_PATH, TRX_CONF
from .tron import TRX_USDT_CONF, TRX_USDC_CONF, TRX_TUSD_CONF, TRX_USDD_CONF
from .cardano import ADA_BYRON_PACKED_DERIVATION_PATH, ADA_SHELLEY_PACKED_DERIVATION_PATH, ADA_CONF
from .near import NEAR_PACKED_DERIVATION_PATH, NEAR_CONF

@dataclass
class CurrencyConfiguration:
Expand Down Expand Up @@ -57,6 +58,7 @@ def get_conf_for_ticker(self, overload_signer: Optional[SigningAuthority]=None)
USDD_CURRENCY_CONFIGURATION = CurrencyConfiguration(ticker="USDD", conf=TRX_USDD_CONF, packed_derivation_path=TRX_PACKED_DERIVATION_PATH)
ADA_BYRON_CURRENCY_CONFIGURATION = CurrencyConfiguration(ticker="ADA", conf=ADA_CONF, packed_derivation_path=ADA_BYRON_PACKED_DERIVATION_PATH)
ADA_SHELLEY_CURRENCY_CONFIGURATION = CurrencyConfiguration(ticker="ADA", conf=ADA_CONF, packed_derivation_path=ADA_SHELLEY_PACKED_DERIVATION_PATH)
NEAR_CURRENCY_CONFIGURATION = CurrencyConfiguration(ticker="NEAR", conf=NEAR_CONF, packed_derivation_path=NEAR_PACKED_DERIVATION_PATH)


# Helper that can be called from outside if we want to generate errors easily
Expand Down
114 changes: 114 additions & 0 deletions test/python/apps/near.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
from enum import IntEnum

from ragger.bip import pack_derivation_path
from ragger.utils import create_currency_config, RAPDU

NEAR_CONF = create_currency_config("NEAR", "NEAR")
NEAR_PACKED_DERIVATION_PATH = pack_derivation_path("m/44'/397'/0'/0'/1'")

class Ins():
SIGN = 0x02


class P1():
START = 0x00
MORE = 0x80


class P2():
UNUSED = 0x57


class NearErrors(IntEnum):
SW_DENY = 0x6985
SW_SWAP_CHECKING_FAIL = 0xB008


class NearClient:
CLA = 0x80

def __init__(self, backend):
self._backend = backend

def send_simple_sign_tx(self, path: str, destination: str, send_amount: int) -> RAPDU:
packed_path = pack_derivation_path(path)

if destination == "speculos.testnet" and send_amount == 1234560000000000000000000000:
"""
1234.56 NEAR
Transaction {
signer_id: "blablatest.testnet",
public_key: ed25519:EFr6nRvgKKeteKoEH7hudt8UHYiu94Liq2yMM7x2AU9U,
nonce: 103595482000005,
receiver_id: "speculos.testnet",
block_hash: Cb3vKNiF3MUuVoqfjuEFCgSNPT79pbuVfXXd2RxDXc5E,
actions: [
Transfer(
TransferAction {
deposit: 1234560000000000000000000000,
},
),
],
}
"""
tx = bytes.fromhex("12000000626c61626c61746573742e746573746e657400c4f5941e81e071c2fd1dae2e71fd3d859d462484391d9a90bf219211dcbb320f85aae733385e00001000000073706563756c6f732e746573746e6574ac299ac1376e375cd39338d8b29225613ef947424b74a3207c1226863a72583101000000030000001049f203b43f34fd0300000000")

elif destination == "speculos.testnet" and send_amount == 500000000000000000000000:
"""
0.5 NEAR
Transaction {
signer_id: "blablatest.testnet",
public_key: ed25519:EFr6nRvgKKeteKoEH7hudt8UHYiu94Liq2yMM7x2AU9U,
nonce: 103595482000005,
receiver_id: "speculos.testnet",
block_hash: Cb3vKNiF3MUuVoqfjuEFCgSNPT79pbuVfXXd2RxDXc5E,
actions: [
Transfer(
TransferAction {
deposit: 500000000000000000000000,
},
),
],
}
"""
tx = bytes.fromhex("12000000626c61626c61746573742e746573746e657400c4f5941e81e071c2fd1dae2e71fd3d859d462484391d9a90bf219211dcbb320f85aae733385e00001000000073706563756c6f732e746573746e6574ac299ac1376e375cd39338d8b29225613ef947424b74a3207c1226863a7258310100000003000080d07666e70de169000000000000")
elif destination == "ledger.testnet" and send_amount == 1234560000000000000000000000:
"""
1234.56 NEAR
Transaction {
signer_id: "blablatest.testnet",
public_key: ed25519:EFr6nRvgKKeteKoEH7hudt8UHYiu94Liq2yMM7x2AU9U,
nonce: 103595482000005,
receiver_id: "ledger.testnet",
block_hash: Cb3vKNiF3MUuVoqfjuEFCgSNPT79pbuVfXXd2RxDXc5E,
actions: [
Transfer(
TransferAction {
deposit: 1234560000000000000000000000,
},
),
],
}
"""
tx = bytes.fromhex("12000000626c61626c61746573742e746573746e657400c4f5941e81e071c2fd1dae2e71fd3d859d462484391d9a90bf219211dcbb320f85aae733385e00000e0000006c65646765722e746573746e6574ac299ac1376e375cd39338d8b29225613ef947424b74a3207c1226863a72583101000000030000001049f203b43f34fd0300000000")
else:
"""
0.5 NEAR
Transaction {
signer_id: "blablatest.testnet",
public_key: ed25519:EFr6nRvgKKeteKoEH7hudt8UHYiu94Liq2yMM7x2AU9U,
nonce: 103595482000005,
receiver_id: "ledger.testnet",
block_hash: Cb3vKNiF3MUuVoqfjuEFCgSNPT79pbuVfXXd2RxDXc5E,
actions: [
Transfer(
TransferAction {
deposit: 500000000000000000000000,
},
),
],
}
"""
tx = bytes.fromhex("12000000626c61626c61746573742e746573746e657400c4f5941e81e071c2fd1dae2e71fd3d859d462484391d9a90bf219211dcbb320f85aae733385e00000e0000006c65646765722e746573746e6574ac299ac1376e375cd39338d8b29225613ef947424b74a3207c1226863a7258310100000003000080d07666e70de169000000000000")

return self._backend.exchange(self.CLA, Ins.SIGN, P1.MORE, P2.UNUSED, packed_path[1:] + tx)
1 change: 1 addition & 0 deletions test/python/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"tron": "Tron",
"ton": "TON",
"cardano": "Cardano ADA",
"near": "NEAR",
}

configuration.OPTIONAL.SIDELOADED_APPS_DIR = "test/python/lib_binaries/"
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading