Skip to content

Commit

Permalink
1658 bnc part 2 (#1788)
Browse files Browse the repository at this point in the history
* fix: fix BNC...

* fix: fix BNC...

* fix: fix BNC...

* fix: fix BNC...

* fix: fix BNC...

* fix: fix BNC...

* fix: en_7 recommendations... (#1749)

* fix: fr9 recommendations

* fix: en_1 recommendations

* fix: en_1 recommendations

* fix: en_2 recommendations...

* fix: en_2 recommendations...

* fix: en_7 recommendations...

* fix: en_7 recommendations...

* fix: n_7 recommandations

* fix: n_7 recommandations

* Merge branch 'main' into 1656-fr9

* Merge branch '1661-en_2' into 1662-en_7

* fix: EN_7

* fix: EN_7

* fix: EN_7

---------

Co-authored-by: Fabio Rigamonti <[email protected]>

(cherry picked from commit f52a556)

* fix: BNC (network)

* fix: BNC 2 network

* fix: BNC 2 network

* fix: BNC 2 network

* fix: BNC 2 network

* fix: BNC 2 network

* fix: BNC 2 network

* fix: BNC 2 network

* fix: BNC 2 network

* fix: BNC 2 network

* fix: BNC 2 network

* fix: BNC 2 network

* fix: BNC 2 network

* fix: BNC 2 network

* fix: BNC 2 network

* fix: BNC 2 network

* fix: BNC 2 network

* fix: BNC 2 network

* fix: BNC 2 network

* fix: BNC 2 network

* fix: BNC 2 network

* fix: BNC 2 network

* fix: BNC 2 network

* fix: BNC 2 network

* fix: BNC 2 network

* fix: BNC 2 network

* Update packages/rpc-proxy/src/utils/config-validator/config-validator.ts

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Signed-off-by: Luca Nicola Debiasi <[email protected]>

* Update packages/rpc-proxy/src/utils/config-validator/config-validator.ts

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Signed-off-by: Luca Nicola Debiasi <[email protected]>

* fix: BNC 2 network

* fix: `BNC` part 2 - network refactor

* fix: `BNC` part 2 - network refactor

* fix: `BNC` part 2 - network refactor

* fix: `BNC` part 2 - network refactor

* fix: `BNC` part 2 - openssl fix

* fix: `BNC` part 2 - openssl fix

* fix: `BNC` part 2 - rpc-proxy README.md amended

---------

Signed-off-by: Luca Nicola Debiasi <[email protected]>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
  • Loading branch information
lucanicoladebiasi and coderabbitai[bot] authored Feb 11, 2025
1 parent f52a556 commit e2d2d5e
Show file tree
Hide file tree
Showing 76 changed files with 407 additions and 413 deletions.
14 changes: 8 additions & 6 deletions .github/workflows/rpc-proxy-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ jobs:
- name: Set up QEMU
if: ${{ github.event_name != 'pull_request' }}
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
if: ${{ github.event_name != 'pull_request' }}
uses: docker/setup-buildx-action@v3

- name: Login to Docker Hub
if: ${{ github.event_name != 'pull_request' }}
uses: docker/login-action@v3
Expand All @@ -36,7 +36,7 @@ jobs:
uses: docker/metadata-action@v5
with:
images: vechain/sdk-rpc-proxy

- name: Build and export to Docker
uses: docker/build-push-action@v6
with:
Expand All @@ -48,8 +48,10 @@ jobs:

- name: Create .trivyignore file
# "cross-spawn" is resolved as version 7.0.5 but Trivy keeps showing the error
run: echo "CVE-2024-21538" > .trivyignore

run: |
echo "CVE-2024-21538" > .trivyignore
echo "CVE-2024-13176" >> .trivyignore
- name: Run Trivy Scan
uses: aquasecurity/trivy-action@master
with:
Expand All @@ -64,7 +66,7 @@ jobs:
env:
# See https://github.com/aquasecurity/trivy/discussions/7538
TRIVY_DB_REPOSITORY: public.ecr.aws/aquasecurity/trivy-db:2

- name: Build and push
if: ${{ github.event_name != 'pull_request' }}
uses: docker/build-push-action@v6
Expand Down
2 changes: 1 addition & 1 deletion apps/sdk-cloudflare-integration/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default {
};

// Create private key
const privateKey = await Secp256k1.generatePrivateKey();
const privateKey = Secp256k1.generatePrivateKey();

// 4 - Sign transaction
const signedTransaction = Transaction.of(body).sign(privateKey);
Expand Down
6 changes: 3 additions & 3 deletions apps/sdk-hardhat-integration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ The `hardhat.config.js` is the main configuration file. By specifying the desire
Note that:

- The network name should contain `vechain`, otherwise, it may result in an error.
- In the network configuration, two additional fields can be added: `delegator` and `useDebug`. These fields allow for more customization and control over the network settings, catering to specific project requirements and preferences.
- In the network configuration, two additional fields can be added: `gasPayer` and `useDebug`. These fields allow for more customization and control over the network settings, catering to specific project requirements and preferences.
- **Debug Mode**: The `debug` field enables or disables debug mode.
- **Delegator**: The `delegator` field allows you to delegate the transaction to a delegator. It supports two optional parameters: - **Delegator**: The `delegator` field allows you to delegate the transaction to a delegator. It supports two optional parameters: `delegatorPrivateKey` and `delegatorUrl`.
- **Delegator**: The `gasPayer` field allows you to delegate the transaction to a gasPayer. It supports two optional parameters: - **Delegator**: The `gasPayer` field allows you to delegate the transaction to a gasPayer. It supports two optional parameters: `delegatorPrivateKey` and `delegatorUrl`.
- When configuring your Solidity compiler settings in hardhat.config.js, it's recommended to set the evmVersion to "Paris" for projects targeting the latest EVM functionalities. This setting ensures that the compiled bytecode is optimized for the most recent features and gas cost adjustments associated with the Paris EVM version. Using an EVM version other than "Paris" could potentially lead to issues with unsupported opcodes, especially if your contracts rely on newer EVM features introduced in or after the Paris update.

This flexibility in the configuration file allows developers to tailor their development experience and adapt it to the requirements of their projects, ensuring a smooth and efficient development process.
This flexibility in the configuration file allows developers to tailor their development experience and adapt it to the requirements of their projects, ensuring a smooth and efficient development process.
16 changes: 8 additions & 8 deletions apps/sdk-hardhat-integration/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { type HttpNetworkConfig } from 'hardhat/types';
*
* They have custom parameters:
* - debug: whether to enable debug mode
* - delegator: the delegator to use
* - gasPayer: the gasPayer to use
* - enableDelegation: whether to enable fee delegation
*/
const config: HardhatUserConfig = {
Expand Down Expand Up @@ -42,7 +42,7 @@ const config: HardhatUserConfig = {
'7f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa158'
],
debug: false,
delegator: undefined,
gasPayer: undefined,
gas: 'auto',
gasPrice: 'auto',
gasMultiplier: 1,
Expand All @@ -65,7 +65,7 @@ const config: HardhatUserConfig = {
passphrase: 'vechainthor'
},
debug: true,
delegator: undefined,
gasPayer: undefined,
gas: 'auto',
gasPrice: 'auto',
gasMultiplier: 1,
Expand All @@ -74,7 +74,7 @@ const config: HardhatUserConfig = {
} satisfies HttpNetworkConfig,

/**
* Testnet configuration - with delegator url
* Testnet configuration - with gasPayer url
*/
vechain_testnet_delegator_url: {
// Testnet
Expand All @@ -88,7 +88,7 @@ const config: HardhatUserConfig = {
passphrase: 'vechainthor'
},
debug: true,
delegator: {
gasPayer: {
delegatorUrl: 'https://sponsor-testnet.vechain.energy/by/269'
},
enableDelegation: true,
Expand All @@ -100,7 +100,7 @@ const config: HardhatUserConfig = {
} satisfies HttpNetworkConfig,

/**
* Testnet configuration - with delegator private key
* Testnet configuration - with gasPayer private key
*/
vechain_testnet_delegator_private_key: {
// Testnet
Expand All @@ -114,7 +114,7 @@ const config: HardhatUserConfig = {
passphrase: 'vechainthor'
},
debug: true,
delegator: {
gasPayer: {
delegatorPrivateKey:
'ea5383ac1f9e625220039a4afac6a7f868bf1ad4f48ce3a1dd78bd214ee4ace5'
},
Expand All @@ -137,7 +137,7 @@ const config: HardhatUserConfig = {
],
debug: false,
enableDelegation: false,
delegator: undefined,
gasPayer: undefined,
gas: 'auto',
gasPrice: 'auto',
gasMultiplier: 1,
Expand Down
14 changes: 7 additions & 7 deletions docker-compose.rpc-proxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ services:

# Default configuration for the RPC proxy service
rpc-proxy:
build:
build:
context: .
dockerfile: docker/rpc-proxy/Dockerfile
container_name: rpc-proxy
Expand All @@ -80,7 +80,7 @@ services:

# 1. Example of a custom configuration file for the RPC proxy service
rpc-proxy-custom-config-file:
build:
build:
context: .
dockerfile: docker/rpc-proxy/Dockerfile
environment:
Expand All @@ -95,7 +95,7 @@ services:

# 2. Example of a custom parameters for the RPC proxy service
rpc-proxy-custom-parameters:
build:
build:
context: .
dockerfile: docker/rpc-proxy/Dockerfile
environment:
Expand All @@ -110,7 +110,7 @@ services:

# 3. Example of a custom accounts for the RPC proxy service
rpc-proxy-custom-accounts:
build:
build:
context: .
dockerfile: docker/rpc-proxy/Dockerfile
environment:
Expand All @@ -125,7 +125,7 @@ services:

# 3. Example of a custom mnemonic for the RPC proxy service
rpc-proxy-custom-mnemonic:
build:
build:
context: .
dockerfile: docker/rpc-proxy/Dockerfile
environment:
Expand All @@ -142,7 +142,7 @@ services:

# 4. Example of a custom delegation by private key for the RPC proxy service
rpc-proxy-with-delegation-by-private-key:
build:
build:
context: .
dockerfile: docker/rpc-proxy/Dockerfile
environment:
Expand All @@ -161,7 +161,7 @@ services:

# 5. Example of a custom delegation by url for the RPC proxy service
rpc-proxy-with-delegation-by-url:
build:
build:
context: .
dockerfile: docker/rpc-proxy/Dockerfile
environment:
Expand Down
4 changes: 2 additions & 2 deletions docker/rpc-proxy/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ COPY --from=builder /app/yarn.lock /app/yarn.lock
WORKDIR /app
RUN yarn workspace @vechain/sdk-rpc-proxy install --production --frozen-lockfile --ignore-scripts --prefer-offline \
&& yarn cache clean \
&& adduser -D rpc-proxy-user
&& adduser -D rpc-proxy-user
# Create a new user to run the app so we do not use root
USER rpc-proxy-user

# Tell we are running with Docker
ENV RUNNING_WITH_DOCKER=true

# Set the default command to use node to run the app
CMD ["node", "packages/rpc-proxy/dist/index.js"]
CMD ["node", "packages/rpc-proxy/dist/index.js"]
5 changes: 2 additions & 3 deletions docs/contracts.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,8 @@ const thorSoloClient = ThorClient.at(THOR_SOLO_URL);
const provider = new VeChainProvider(
thorSoloClient,
new ProviderInternalBaseWallet([deployerAccount], {
// The term `delegator` will be deprecated soon and renamed `gasPayer`.
delegator: {
delegatorPrivateKey: gasPayerAccount.privateKey
gasPayer: {
gasPayerPrivateKey: gasPayerAccount.privateKey
}
}),
true
Expand Down
2 changes: 1 addition & 1 deletion docs/diagrams/architecture/transaction.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ classDiagram
+Address origin
+Uint8Array signature?
+Transaction decode(Uint8Array rawTransaction, boolean isSigned)$
+Blake2b256 getTransactionHash(Address delegator?)
+Blake2b256 getTransactionHash(Address gasPayer?)
+VTHO intrinsicGas(TransactionClause[] clauses)$
+boolean isValidBody(TransactionBody body)$
+Transaction of(TransactionBody: body, Uint8Array signature?)$
Expand Down
9 changes: 3 additions & 6 deletions docs/examples/contracts/contract-delegation-ERC20.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import {
type ProviderInternalWalletAccount,
THOR_SOLO_URL,
ThorClient,
type TransactionReceipt,
VeChainProvider,
type VeChainSigner
VeChainProvider
} from '@vechain/sdk-network';
import { expect } from 'expect';

Expand Down Expand Up @@ -36,9 +34,8 @@ const thorSoloClient = ThorClient.at(THOR_SOLO_URL);
const provider = new VeChainProvider(
thorSoloClient,
new ProviderInternalBaseWallet([deployerAccount], {
// The term `delegator` will be deprecated soon and renamed `gasPayer`.
delegator: {
delegatorPrivateKey: gasPayerAccount.privateKey
gasPayer: {
gasPayerPrivateKey: gasPayerAccount.privateKey
}
}),
true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
} from '@vechain/sdk-network';
import { expect } from 'expect';

// START_SNIPPET: FullFlowDelegatorPrivateKeySnippet
// START_SNIPPET: FullFlowGasPayerPrivateKeySnippet

// 1 - Create the thor client
const thorSoloClient = ThorClient.at(THOR_SOLO_URL, {
Expand Down Expand Up @@ -50,9 +50,8 @@ const providerWithDelegationEnabled = new VeChainProvider(
}
],
{
// The term `delegator` will be deprecated soon and renamed `gasPayer`.
delegator: {
delegatorPrivateKey: gasPayerAccount.privateKey
gasPayer: {
gasPayerPrivateKey: gasPayerAccount.privateKey
}
}
),
Expand Down Expand Up @@ -115,7 +114,7 @@ const txReceipt = await thorSoloClient.transactions.waitForTransaction(
sendTransactionResult.id
);

// END_SNIPPET: FullFlowDelegatorPrivateKeySnippet
// END_SNIPPET: FullFlowGasPayerPrivateKeySnippet

// Check the signed transaction
expect(delegatedSigned.isSigned).toEqual(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
} from '@vechain/sdk-network';
import { expect } from 'expect';

// START_SNIPPET: FullFlowDelegatorUrlSnippet
// START_SNIPPET: FullFlowGasPayerServiceUrlSnippet

// 1 - Create the thor client
const thorClient = ThorClient.at(TESTNET_URL, {
Expand Down Expand Up @@ -54,9 +54,8 @@ const providerWithDelegationEnabled = new VeChainProvider(
}
],
{
// The term `delegator` will be deprecated soon and renamed `gasPayer`.
delegator: {
delegatorUrl: gasPayerAccount.URL
gasPayer: {
gasPayerServiceUrl: gasPayerAccount.URL
}
}
),
Expand Down Expand Up @@ -119,12 +118,12 @@ const txReceipt = await thorClient.transactions.waitForTransaction(
sendTransactionResult.id
);

// END_SNIPPET: FullFlowDelegatorUrlSnippet
// END_SNIPPET: FullFlowGasPayerServiceUrlSnippet

// Check the signed transaction
expect(delegatedSigned.isSigned).toEqual(true);
expect(delegatedSigned.isDelegated).toEqual(true);
// expect(signedTx.delegator).toEqual(gasPayerAccount.address); ---
// expect(signedTx.gasPayer).toEqual(gasPayerAccount.address); ---

// Check the transaction receipt
expect(txReceipt).toBeDefined();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
} from '@vechain/sdk-network';
import { expect } from 'expect';

// START_SNIPPET: FullFlowNoDelegatorSnippet
// START_SNIPPET: FullFlowNoGasPayerSnippet

// 1 - Create the thor client
const thorSoloClient = ThorClient.at(THOR_SOLO_URL, {
Expand Down Expand Up @@ -95,7 +95,7 @@ const txReceipt = await thorSoloClient.transactions.waitForTransaction(
sendTransactionResult.id
);

// END_SNIPPET: FullFlowNoDelegatorSnippet
// END_SNIPPET: FullFlowNoGasPayerSnippet

// Check the transaction receipt
expect(txReceipt).toBeDefined();
Expand Down
10 changes: 5 additions & 5 deletions docs/templates/transactions.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ In the following complete examples, we will explore the entire lifecycle of a Ve

1. **No Delegation (Signing Only with an Origin Private Key)**: In this scenario, we'll demonstrate the basic process of creating a transaction, signing it with the origin private key, and sending it to the VeChainThor blockchain without involving fee delegation.

[FullFlowNoDelegatorSnippet](examples/transactions/full-flow-no-delegator.ts)
[FullFlowNoGasPayerSnippet](examples/transactions/full-flow-no-gas-payer.ts)

2. **Delegation with Private Key**: Here, we'll extend the previous example by incorporating fee delegation. The transaction sender will delegate the transaction fee payment to another entity (delegator), and we'll guide you through the steps of building, signing, and sending such a transaction.
2. **Delegation with Private Key**: Here, we'll extend the previous example by incorporating fee delegation. The transaction sender will delegate the transaction fee payment to another entity (gasPayer), and we'll guide you through the steps of building, signing, and sending such a transaction.

[FullFlowDelegatorPrivateKeySnippet](examples/transactions/full-flow-delegator-private-key.ts)
[FullFlowGasPayerPrivateKeySnippet](examples/transactions/full-flow-gas-payer-private-key.ts)

3. **Delegation with URL**: This example will showcase the use of a delegation URL for fee delegation. The sender will specify a delegation URL in the `signTransaction` options, allowing a designated sponsor to pay the transaction fee. We'll cover the full process, from building clauses to verifying the transaction on-chain.

[FullFlowDelegatorUrlSnippet](examples/transactions/full-flow-delegator-url.ts)
[FullFlowGasPayerServiceUrlSnippet](examples/transactions/full-flow-gas-payer-service-url.ts)

By examining these complete examples, developers can gain a comprehensive understanding of transaction handling in the VeChain SDK. Each example demonstrates the steps involved in initiating, signing, and sending transactions, as well as the nuances associated with fee delegation.

Expand All @@ -78,4 +78,4 @@ Even when using the `simulateTransaction` method you can find the revert reason.

[RevertReasonSimulationSnippet](examples/transactions/revert-reason-with-simulation.ts)

In this case there is only a `TransactionSimulationResult`, so no need to loop.
In this case there is only a `TransactionSimulationResult`, so no need to loop.
Loading

1 comment on commit e2d2d5e

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test Coverage

Summary

Lines Statements Branches Functions
Coverage: 99%
98.98% (4377/4422) 97.01% (1398/1441) 98.9% (906/916)
Title Tests Skipped Failures Errors Time
core 838 0 πŸ’€ 0 ❌ 0 πŸ”₯ 2m 33s ⏱️
network 731 0 πŸ’€ 0 ❌ 0 πŸ”₯ 5m 4s ⏱️
errors 40 0 πŸ’€ 0 ❌ 0 πŸ”₯ 17.883s ⏱️
logging 3 0 πŸ’€ 0 ❌ 0 πŸ”₯ 19.251s ⏱️
hardhat-plugin 19 0 πŸ’€ 0 ❌ 0 πŸ”₯ 1m 14s ⏱️
aws-kms-adapter 23 0 πŸ’€ 0 ❌ 0 πŸ”₯ 1m 33s ⏱️
ethers-adapter 5 0 πŸ’€ 0 ❌ 0 πŸ”₯ 1m 23s ⏱️
rpc-proxy 37 0 πŸ’€ 0 ❌ 0 πŸ”₯ 1m 29s ⏱️

Please sign in to comment.