Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into root-format
Browse files Browse the repository at this point in the history
  • Loading branch information
nkuba committed Nov 28, 2023
2 parents 18b873e + ff60a53 commit d6ed6d7
Show file tree
Hide file tree
Showing 40 changed files with 451 additions and 60 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/core.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,42 @@ jobs:
core/typechain/
if-no-files-found: error

core-slither:
needs: [core-build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up pnpm
uses: pnpm/action-setup@v2

- name: Set up Node
uses: actions/setup-node@v4
with:
node-version-file: "core/.nvmrc"
cache: "pnpm"

- name: Install Dependencies
run: pnpm install --prefer-offline --frozen-lockfile

- uses: actions/setup-python@v4
with:
python-version: 3.11

- name: Install Slither
env:
SLITHER_VERSION: 0.9.6
run: pip3 install slither-analyzer==$SLITHER_VERSION

- name: Download Build Artifacts
uses: actions/download-artifact@v3
with:
name: core-build
path: core/

- name: Run Slither
run: slither --hardhat-ignore-compile .

core-test:
needs: [core-build]
runs-on: ubuntu-latest
Expand Down
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
# Node
node_modules/
pnpm-debug.log*

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
public-hoist-pattern[]=@chakra-ui/*
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lts/iron
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,24 @@ pre-commit run --all-files
# Execute hooks for specific files (e.g. Acre.sol):
pre-commit run --files ./core/contracts/Acre.sol
```

### Slither

[Slither](https://github.com/crytic/slither) is a static analysis framework used
for Solidity contracts verification.

#### Install

To install Slither execute:

```sh
pip3 install slither-analyzer
```

#### Usage

To run Slither execute:

```sh
slither .
```
4 changes: 1 addition & 3 deletions core/.gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# Hardhat
build/
cache/
export.json
export/
node_modules/
typechain/
yarn-debug.log*
yarn-error.log*
1 change: 1 addition & 0 deletions core/slither.config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"detectors_to_exclude": "assembly,naming-convention,timestamp,pragma,solc-version",
"hardhat_artifacts_directory": "build",
"filter_paths": "node_modules/.*"
}
1 change: 1 addition & 0 deletions dapp/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VITE_USE_TESTNET=true
26 changes: 2 additions & 24 deletions dapp/.gitignore
Original file line number Diff line number Diff line change
@@ -1,24 +1,2 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
# Output
dist/
32 changes: 24 additions & 8 deletions dapp/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
# Acre dApp

## Installation

1. Install dependencies and start the app.
```bash
yarn install
yarn start
```
2. Open [http://localhost:5173](http://localhost:5173) to view it in the browser.
The application is compatible with Ledger Live and allows people to earn yield on their Bitcoin via yield farming on Ethereum.

This project was bootstrapped with [Create Vite](https://github.com/vitejs/vite/tree/main/packages/create-vite).

## Quickstart

Install dependencies and start the app.

```bash
pnpm install
pnpm run start
```

Once the build is running, you can import the manifest on desktop:

1. [Install Ledger Live Desktop](https://www.ledger.com/ledger-live)
2. Enable the Developer mode

Go to the **Settings -> About** section, and click 10 times on the Ledger Live version. A new Developer section appears in the settings menu. Turn on **Enable platform dev** tools to use the developer tools window to inspect your app.
3. Add your manifest

Click on Browse next to **Add a local app** and select the manifest file. The app is now visible in the menu.

If you have any problems, take a look [here](https://developers.ledger.com/docs/non-dapp/tutorial/3-import/#desktop).
4 changes: 2 additions & 2 deletions dapp/manifest-ledger-live-app.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"manifestVersion": "1",
"branch": "stable",
"categories": ["buy"],
"currencies": ["bitcoin", "bitcoin_testnet"],
"currencies": ["bitcoin", "bitcoin_testnet", "ethereum", "ethereum_goerli"],
"content": {
"shortDescription": {
"en": "Bitcoin Liquid Staking"
Expand All @@ -18,6 +18,6 @@
"en": "Bitcoin Liquid Staking"
}
},
"permissions": [],
"permissions": ["account.request"],
"domains": ["http://*"]
}
2 changes: 0 additions & 2 deletions dapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
},
"dependencies": {
"@chakra-ui/react": "^2.8.2",
"@chakra-ui/styled-system": "^2.9.2",
"@chakra-ui/theme-tools": "^2.1.2",
"@emotion/react": "^11.11.1",
"@emotion/styled": "^11.11.0",
"@ledgerhq/wallet-api-client": "^1.2.1",
Expand Down
24 changes: 16 additions & 8 deletions dapp/src/DApp.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
import React from "react"
import { ChakraProvider, Button, Box } from "@chakra-ui/react"
import { useDetectThemeMode } from "./hooks"
import { LedgerWalletAPIProvider } from "./providers"
import { ChakraProvider, Box, Text } from "@chakra-ui/react"
import { useDetectThemeMode, useWalletContext } from "./hooks"
import theme from "./theme"
import { LedgerWalletAPIProvider, WalletContextProvider } from "./contexts"
import Navbar from "./components/Navbar"

function DApp() {
useDetectThemeMode()

const { btcAccount, ethAccount } = useWalletContext()

return (
<Box p={4}>
<Box>
<Navbar />
<h1>Ledger live - Acre dApp</h1>
<Button>Test button</Button>
{btcAccount && <Text>Account: {btcAccount.address}</Text>}
{ethAccount && <Text>Account: {ethAccount.address}</Text>}
</Box>
)
}

function DAppProviders() {
return (
<LedgerWalletAPIProvider>
<ChakraProvider theme={theme}>
<DApp />
</ChakraProvider>
<WalletContextProvider>
<ChakraProvider theme={theme}>
<DApp />
</ChakraProvider>
</WalletContextProvider>
</LedgerWalletAPIProvider>
)
}
Expand Down
16 changes: 16 additions & 0 deletions dapp/src/assets/bitcoin.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions dapp/src/assets/ethereum.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions dapp/src/assets/info.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
77 changes: 77 additions & 0 deletions dapp/src/components/Navbar/ConnectWallet.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import React from "react"
import { Box, Button, Image, Text } from "@chakra-ui/react"
import { Account } from "@ledgerhq/wallet-api-client"
import BitcoinIcon from "../../assets/bitcoin.svg"
import EthereumIcon from "../../assets/ethereum.svg"
import InfoIcon from "../../assets/info.svg"
import { BITCOIN } from "../../constants"
import {
useRequestBitcoinAccount,
useRequestEthereumAccount,
useWalletContext,
} from "../../hooks"
import { formatSatoshiAmount, truncateAddress } from "../../utils"

export type ConnectButtonsProps = {
leftIcon: string
rightIcon: string
account: Account | undefined
requestAccount: () => Promise<void>
}

function ConnectButton({
leftIcon,
rightIcon,
account,
requestAccount,
}: ConnectButtonsProps) {
const styles = !account ? { color: "error", borderColor: "error" } : undefined
return (
<Button
variant="outline"
sx={styles}
leftIcon={<Image src={leftIcon} />}
// TODO: Add a tooltip here
rightIcon={!account ? <Image src={rightIcon} /> : undefined}
onClick={requestAccount}
>
{account ? truncateAddress(account.address) : "Not connected"}
</Button>
)
}

export default function ConnectWallet() {
const { requestAccount: requestBitcoinAccount } = useRequestBitcoinAccount()
const { requestAccount: requestEthereumAccount } = useRequestEthereumAccount()
const { btcAccount, ethAccount } = useWalletContext()

return (
<Box display="flex" alignItems="center" gap="4">
<Box display="flex" gap="2">
<Text>Balance</Text>
<Text as="b">
{!btcAccount || btcAccount?.balance.isZero()
? "0.00"
: formatSatoshiAmount(btcAccount.balance.toString())}
</Text>
<Text>{BITCOIN.symbol}</Text>
</Box>
<ConnectButton
leftIcon={BitcoinIcon}
rightIcon={InfoIcon}
account={btcAccount}
requestAccount={async () => {
await requestBitcoinAccount()
}}
/>
<ConnectButton
leftIcon={EthereumIcon}
rightIcon={InfoIcon}
account={ethAccount}
requestAccount={async () => {
await requestEthereumAccount()
}}
/>
</Box>
)
}
11 changes: 11 additions & 0 deletions dapp/src/components/Navbar/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from "react"
import { Box } from "@chakra-ui/react"
import ConnectWallet from "./ConnectWallet"

export default function Navbar() {
return (
<Box p={4} display="flex" justifyContent="end">
<ConnectWallet />
</Box>
)
}
19 changes: 19 additions & 0 deletions dapp/src/constants/currency.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Currency } from "../types"

export const BITCOIN: Currency = {
name: "Bitcoin",
symbol: "BTC",
decimals: 8,
}

export const ETHEREUM: Currency = {
name: "Ethereum",
symbol: "ETH",
decimals: 18,
}

export const CURRENCY_ID_BITCOIN =
import.meta.env.VITE_USE_TESTNET === "true" ? "bitcoin_testnet" : "bitcoin"

export const CURRENCY_ID_ETHEREUM =
import.meta.env.VITE_USE_TESTNET === "true" ? "ethereum_goerli" : "ethereum"
1 change: 1 addition & 0 deletions dapp/src/constants/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./currency"
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type LedgerWalletAPIProviderProps = {
children: React.ReactElement
}

export default function LedgerWalletAPIProvider({
export function LedgerWalletAPIProvider({
children,
}: LedgerWalletAPIProviderProps): JSX.Element {
const transport = getWalletAPITransport()
Expand Down
Loading

0 comments on commit d6ed6d7

Please sign in to comment.