Skip to content

Commit

Permalink
Merge pull request #14 from GuilaneDen/feat/implement-sendToken-method
Browse files Browse the repository at this point in the history
Feat/implement send token method
  • Loading branch information
GuilaneDen authored Feb 2, 2023
2 parents 245efab + 58dc8ff commit 471e345
Show file tree
Hide file tree
Showing 122 changed files with 4,096 additions and 99 deletions.
60 changes: 39 additions & 21 deletions .github/workflows/ci-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
runs-on: ubuntu-latest

container:
image: ghcr.io/blooo-io/ledger-app-builder/ledger-app-scanner:master
image: ghcr.io/ledgerhq/ledger-app-builder/ledger-app-scanner:latest

steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -94,9 +94,15 @@ jobs:
image: ghcr.io/ledgerhq/ledger-app-builder/ledger-app-builder:latest
steps:
- name: Clone
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
submodules: recursive
- name: Clone SDK
uses: actions/checkout@v3
with:
repository: LedgerHQ/ethereum-plugin-sdk
path: ethereum-plugin-sdk
ref: develop
- name: Build plugin for Nano S
run: |
git config --global --add safe.directory /__w/LedgerHQ-app-plugin-squid/LedgerHQ-app-plugin-squid
Expand All @@ -107,7 +113,7 @@ jobs:
mkdir -p ./tests/elfs/
mv bin/app.elf ./tests/elfs/squid_nanos.elf
- name: Upload plugin binary
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: binaries
path: tests/elfs/squid_nanos.elf
Expand All @@ -119,9 +125,15 @@ jobs:
image: ghcr.io/ledgerhq/ledger-app-builder/ledger-app-builder:latest
steps:
- name: Clone
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
submodules: recursive
- name: Clone SDK
uses: actions/checkout@v3
with:
repository: LedgerHQ/ethereum-plugin-sdk
path: ethereum-plugin-sdk
ref: develop
- name: Build plugin for Nano X
run: |
git config --global --add safe.directory /__w/LedgerHQ-app-plugin-squid/LedgerHQ-app-plugin-squid
Expand All @@ -132,7 +144,7 @@ jobs:
mkdir -p ./tests/elfs/
mv bin/app.elf ./tests/elfs/squid_nanox.elf
- name: Upload plugin binary
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: binaries
path: tests/elfs/squid_nanox.elf
Expand All @@ -144,9 +156,15 @@ jobs:
image: ghcr.io/ledgerhq/ledger-app-builder/ledger-app-builder:latest
steps:
- name: Clone
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
submodules: recursive
- name: Clone SDK
uses: actions/checkout@v3
with:
repository: LedgerHQ/ethereum-plugin-sdk
path: ethereum-plugin-sdk
ref: develop
- name: Build plugin for Nano S+
run: |
git config --global --add safe.directory /__w/LedgerHQ-app-plugin-squid/LedgerHQ-app-plugin-squid
Expand All @@ -157,7 +175,7 @@ jobs:
mkdir -p ./tests/elfs/
mv bin/app.elf ./tests/elfs/squid_nanosp.elf
- name: Upload plugin binary
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: binaries
path: tests/elfs/squid_nanosp.elf
Expand All @@ -169,10 +187,10 @@ jobs:
image: ghcr.io/ledgerhq/ledger-app-builder/ledger-app-builder:latest
steps:
- name: Checkout app-ethereum
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
repository: LedgerHQ/app-ethereum
ref: ${{ ((github.base_ref || github.ref_name) == 'main' && 'master') || (github.base_ref || github.ref_name) }}
ref: develop
submodules: recursive
- name: Build ethereum
run: |
Expand All @@ -184,7 +202,7 @@ jobs:
mkdir -p ./tests/elfs/
mv bin/app.elf ./tests/elfs/ethereum_nanos.elf
- name: Upload plugin binary
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: binaries
path: tests/elfs/ethereum_nanos.elf
Expand All @@ -196,10 +214,10 @@ jobs:
image: ghcr.io/ledgerhq/ledger-app-builder/ledger-app-builder:latest
steps:
- name: Checkout app-ethereum
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
repository: LedgerHQ/app-ethereum
ref: ${{ ((github.base_ref || github.ref_name) == 'main' && 'master') || (github.base_ref || github.ref_name) }}
ref: develop
submodules: recursive
- name: Build ethereum
run: |
Expand All @@ -211,7 +229,7 @@ jobs:
mkdir -p ./tests/elfs/
mv bin/app.elf ./tests/elfs/ethereum_nanox.elf
- name: Upload plugin binary
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: binaries
path: tests/elfs/ethereum_nanox.elf
Expand All @@ -223,10 +241,10 @@ jobs:
image: ghcr.io/ledgerhq/ledger-app-builder/ledger-app-builder:latest
steps:
- name: Checkout app-ethereum
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
repository: LedgerHQ/app-ethereum
ref: ${{ ((github.base_ref || github.ref_name) == 'main' && 'master') || (github.base_ref || github.ref_name) }}
ref: develop
submodules: recursive
- name: Build ethereum
run: |
Expand All @@ -238,7 +256,7 @@ jobs:
mkdir -p ./tests/elfs/
mv bin/app.elf ./tests/elfs/ethereum_nanosp.elf
- name: Upload plugin binary
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: binaries
path: tests/elfs/ethereum_nanosp.elf
Expand All @@ -259,19 +277,19 @@ jobs:
echo $HOME
echo $DISPLAY
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Download built binaries
uses: actions/download-artifact@v2
uses: actions/download-artifact@v3
with:
name: binaries
path: tests/elfs/
- name: Check downloaded binaries
run: ls -lh ./tests/elfs
- run: sudo apt-get update -y && sudo apt-get install -y libusb-1.0.0 libudev-dev
- name: Install node
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: "18.12.1"
node-version: "14.18.1"
- name: Install yarn
run: |
npm install -g yarn
Expand All @@ -280,4 +298,4 @@ jobs:
cd tests && yarn install
- name: Run zemu tests
run: |
cd tests && yarn test
cd tests && yarn test
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ The smart contracts covered by this plugin are:
| Network | Smart Contract |
| --- | --- |
| Ethereum | `0xce16F69375520ab01377ce7B88f5BA8C48F8D666`|
| Ethereum | `0x4f4495243837681061c4743b74b3eedf548d56a5`|
| Polygon | `0xce16F69375520ab01377ce7B88f5BA8C48F8D666`|
| Polygon | `0x6f015f16de9fc8791b234ef68d486d2bf203fba8`|
| BSC | `0xce16F69375520ab01377ce7B88f5BA8C48F8D666`|
| BSC | `0x304acf330bbe08d1e512eefaa92f6a57871fd895`|


On these smart contracts, the functions covered by this plugin are:
Expand All @@ -42,7 +45,7 @@ On these smart contracts, the functions covered by this plugin are:
|callBridgeCall | 0x8ca3bf68| <table> <tbody> <tr> <td><code>address token</code></td></tr> <tr><td><code>uint256 amount</code></td></tr> <tr><td><code>string destinationChain</code></td></tr> <tr><td><code>string bridgedTokenSymbol</code></td></tr> </tbody> </table> |
|bridgeCall | 0x3c659741| <table> <tbody> <tr><td><code>string destinationChain</code></td></tr> <tr><td><code>string bridgedTokenSymbol</code></td></tr> <tr><td><code>uint256 amount</code></td></tr> </tbody> </table>|
|callBridge | 0xf35af1f8| <table> <tbody> <tr> <td><code>address token</code></td></tr> <tr><td><code>uint256 amount</code></td></tr> <tr><td><code>string destinationChain</code></td></tr> <tr><td><code>string bridgedTokenSymbol</code></td></tr> </tbody> </table> |

|sendToken | 0x26ef699d| <table> <tbody> <tr> <td><code>string destinationChain</code></td></tr> <tr><td><code>string destinationAddress</code></td></tr> <tr><td><code>string symbol</code></td></tr> <tr><td><code>uint256 amount</code></td></tr> </tbody> </table> |

## Build

Expand Down
2 changes: 1 addition & 1 deletion ethereum-plugin-sdk
8 changes: 7 additions & 1 deletion src/contract.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ static const uint8_t SQUID_BRIDGE_CALL_SELECTOR[SELECTOR_SIZE] = {0x3c, 0x65, 0x
// callBridge : 0xf35af1f8
static const uint8_t SQUID_CALL_BRIDGE_SELECTOR[SELECTOR_SIZE] = {0xf3, 0x5a, 0xf1, 0xf8};

// sendToken : 0x26ef699d
static const uint8_t SQUID_SEND_TOKEN_SELECTOR[SELECTOR_SIZE] = {0x26, 0xef, 0x69, 0x9d};

// Array of all the different Squid selectors.
const uint8_t *const SQUID_SELECTORS[NUM_SQUID_SELECTORS] = {SQUID_CALL_BRIDGE_CALL_SELECTOR,
SQUID_BRIDGE_CALL_SELECTOR,
SQUID_CALL_BRIDGE_SELECTOR};
SQUID_CALL_BRIDGE_SELECTOR,
SQUID_SEND_TOKEN_SELECTOR};

const uint8_t NULL_ETH_ADDRESS[ADDRESS_LENGTH] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Expand All @@ -31,6 +35,7 @@ const struct chainIdToChainName_t SQUID_SUPPORTED_CHAINS[NUM_SUPPORTED_CHAINS] =
{"Avalanche", "Avalanche C-Chain"},
{"Moonbeam", "Moonbeam Mainnet"},
{"Polygon", "Polygon"},
{"polygon", "Polygon"},
{"binance", "Binance"},
{"cosmoshub", "Cosmos Hub"},
{"crescent", "Crescent"},
Expand All @@ -43,6 +48,7 @@ const struct chainIdToChainName_t SQUID_SUPPORTED_CHAINS[NUM_SUPPORTED_CHAINS] =
{"Agoric", "Agoric"},
{"ASSETMANTLE", "AssetMantle"},
{"Axelarnet", "Axelar"},
{"axelar", "Axelar"},
{"COMDEX", "Comdex"},
{"EVMOS", "Evmos"},
{"fetch", "Fetch"},
Expand Down
78 changes: 39 additions & 39 deletions src/handle_finalize.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,46 +38,46 @@ static void finalize_lookup(ethPluginFinalize_t *msg, squid_parameters_t *contex
void handle_finalize(void *parameters) {
ethPluginFinalize_t *msg = (ethPluginFinalize_t *) parameters;
squid_parameters_t *context = (squid_parameters_t *) msg->pluginContext;
if (context->valid) {
switch (context->selectorIndex) {
case CALL_BRIDGE_CALL:
msg->numScreens = 2;
finalize_lookup(msg, context);
break;
case CALL_BRIDGE:
msg->numScreens = 3;
finalize_lookup(msg, context);
break;
case BRIDGE_CALL:
msg->numScreens = 2;
msg->tokenLookup1 = NULL;
// check supported tokens custom mapping
// and set decimals for the specified token
bool success = set_ticker_for_mapped_token(context);
if (!success) {
// The token was not found in custom mapping
context->decimals_sent = DEFAULT_DECIMAL;
strlcpy(context->ticker_sent, DEFAULT_TICKER, sizeof(context->ticker_sent));
// // We will need an additional screen to display a warning message.
msg->numScreens++;
PRINTF("Token not found in mapping\n");
}
break;
default:
PRINTF("Selector Index %d not supported\n", context->selectorIndex);
msg->result = ETH_PLUGIN_RESULT_ERROR;
break;
}

if (!is_chain_supported(context)) {
// Add a warning screen if the dest chain is not supported
msg->numScreens++;
}
switch (context->selectorIndex) {
case CALL_BRIDGE_CALL:
msg->numScreens = 2;
finalize_lookup(msg, context);
break;
case CALL_BRIDGE:
msg->numScreens = 3;
finalize_lookup(msg, context);
break;
case BRIDGE_CALL:
case SEND_TOKEN:
msg->numScreens = 2;
if (context->selectorIndex == SEND_TOKEN) {
msg->numScreens = 3;
}
msg->tokenLookup1 = NULL;
// check supported tokens custom mapping
// and set decimals for the specified token
bool success = set_ticker_for_mapped_token(context);
if (!success) {
// The token was not found in custom mapping
context->decimals_sent = DEFAULT_DECIMAL;
strlcpy(context->ticker_sent, DEFAULT_TICKER, sizeof(context->ticker_sent));
// // We will need an additional screen to display a warning message.
msg->numScreens++;
PRINTF("Token not found in mapping\n");
}
break;
default:
PRINTF("Selector Index %d not supported\n", context->selectorIndex);
msg->result = ETH_PLUGIN_RESULT_ERROR;
break;
}

msg->uiType = ETH_UI_TYPE_GENERIC;
msg->result = ETH_PLUGIN_RESULT_OK;
} else {
PRINTF("Context not valid\n");
msg->result = ETH_PLUGIN_RESULT_FALLBACK;
if (!is_chain_supported(context)) {
// Add a warning screen if the dest chain is not supported
msg->numScreens++;
}

msg->uiType = ETH_UI_TYPE_GENERIC;
msg->result = ETH_PLUGIN_RESULT_OK;
}
2 changes: 1 addition & 1 deletion src/handle_init_contract.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ void handle_init_contract(void *parameters) {

squid_parameters_t *context = (squid_parameters_t *) msg->pluginContext;
memset(context, 0, sizeof(*context));
context->valid = 1;

// Determine a function to call
size_t i;
Expand All @@ -40,6 +39,7 @@ void handle_init_contract(void *parameters) {
context->next_param = TOKEN_SENT;
break;
case BRIDGE_CALL:
case SEND_TOKEN:
context->next_param = SAVE_CHAIN_OFFSET;
break;
default:
Expand Down
Loading

0 comments on commit 471e345

Please sign in to comment.