Skip to content

Commit

Permalink
1658 bnc - part 1 (#1777)
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...
  • Loading branch information
lucanicoladebiasi authored Jan 30, 2025
1 parent 631274e commit 3eecea9
Show file tree
Hide file tree
Showing 13 changed files with 96 additions and 104 deletions.
12 changes: 5 additions & 7 deletions docs/contracts.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,22 +202,21 @@ You can specify revisions (`best` or `finalized`) for read functions, similar to

## Delegating a Contract Call

VeChain supports delegated contract calls where fees are paid by the delegator.
VeChain supports delegated contract calls where fees are paid by the gas-payer.

```typescript { name=contract-delegation-erc20, category=example }
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: delegatorAccount.privateKey
delegatorPrivateKey: gasPayerAccount.privateKey
}
}),
true
);
const signer = (await provider.getSigner(
deployerAccount.address
)) as VeChainSigner;
const signer = await provider.getSigner(deployerAccount.address);

// Defining a function for deploying the ERC20 contract
const setupERC20Contract = async (): Promise<Contract<typeof ERC20_ABI>> => {
Expand All @@ -244,8 +243,7 @@ const transferResult = await contract.transact.transfer(
);

// Wait for the transfer transaction to complete and obtain its receipt
const transactionReceiptTransfer =
(await transferResult.wait()) as TransactionReceipt;
const transactionReceiptTransfer = await transferResult.wait();

// Asserting that the transaction has not been reverted
expect(transactionReceiptTransfer.reverted).toEqual(false);
Expand Down
16 changes: 7 additions & 9 deletions docs/examples/contracts/contract-delegation-ERC20.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ERC20_ABI, Hex, HexUInt } from '@vechain/sdk-core';
import { ERC20_ABI, HexUInt } from '@vechain/sdk-core';
import {
type Contract,
ProviderInternalBaseWallet,
Expand All @@ -23,8 +23,8 @@ const deployerAccount: ProviderInternalWalletAccount = {
address: '0xf02f557c753edf5fcdcbfe4c1c3a448b3cc84d54'
};

// Defining the delegator account, which has VTHO for transaction costs
const delegatorAccount = {
// Defining the gas-payer account, which has VTHO for transaction costs
const gasPayerAccount = {
privateKey:
'521b7793c6eb27d137b617627c6b85d57c0aa303380e9ca4e30a30302fbc6676',
address: '0x062F167A905C1484DE7e75B88EDC7439f82117DE'
Expand All @@ -36,15 +36,14 @@ 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: delegatorAccount.privateKey
delegatorPrivateKey: gasPayerAccount.privateKey
}
}),
true
);
const signer = (await provider.getSigner(
deployerAccount.address
)) as VeChainSigner;
const signer = await provider.getSigner(deployerAccount.address);

// Defining a function for deploying the ERC20 contract
const setupERC20Contract = async (): Promise<Contract<typeof ERC20_ABI>> => {
Expand All @@ -71,8 +70,7 @@ const transferResult = await contract.transact.transfer(
);

// Wait for the transfer transaction to complete and obtain its receipt
const transactionReceiptTransfer =
(await transferResult.wait()) as TransactionReceipt;
const transactionReceiptTransfer = await transferResult.wait();

// Asserting that the transaction has not been reverted
expect(transactionReceiptTransfer.reverted).toEqual(false);
Expand Down
8 changes: 4 additions & 4 deletions docs/examples/transactions/fee-delegation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,17 @@ const body: TransactionBody = {
// 4 - Create private keys of sender and delegate

const nodeDelegate = HDKey.fromMnemonic(Mnemonic.of());
const delegatorPrivateKey = nodeDelegate.privateKey;
const gasPayerPrivateKey = nodeDelegate.privateKey;

// 5 - Get address of delegate

const delegatorAddress = Address.ofPublicKey(nodeDelegate.publicKey).toString();
const gasPayerAddress = Address.ofPublicKey(nodeDelegate.publicKey).toString();

// 6 - Sign transaction as sender and delegate

const signedTransaction = Transaction.of(body).signAsSenderAndGasPayer(
HexUInt.of(senderAccount.privateKey).bytes,
HexUInt.of(delegatorPrivateKey).bytes
HexUInt.of(gasPayerPrivateKey).bytes
);

// 7 - Encode transaction
Expand All @@ -85,4 +85,4 @@ const decodedTx = Transaction.decode(encodedRaw, true);
// END_SNIPPET: FeeDelegationSnippet

expect(decodedTx.isDelegated).toBeTruthy();
expect(decodedTx.gasPayer.toString()).toBe(delegatorAddress);
expect(decodedTx.gasPayer.toString()).toBe(gasPayerAddress);
9 changes: 5 additions & 4 deletions docs/examples/transactions/full-flow-delegator-private-key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ const senderAccount: { privateKey: string; address: string } = {
address: '0x7a28e7361fd10f4f058f9fefc77544349ecff5d6'
};

// Delegator account with private key
const delegatorAccount: { privateKey: string; address: string } = {
// Gas-payer account with private key
const gasPayerAccount: { privateKey: string; address: string } = {
privateKey:
'521b7793c6eb27d137b617627c6b85d57c0aa303380e9ca4e30a30302fbc6676',
address: '0x062F167A905C1484DE7e75B88EDC7439f82117DE'
Expand All @@ -50,8 +50,9 @@ const providerWithDelegationEnabled = new VeChainProvider(
}
],
{
// The term `delegator` will be deprecated soon and renamed `gasPayer`.
delegator: {
delegatorPrivateKey: delegatorAccount.privateKey
delegatorPrivateKey: gasPayerAccount.privateKey
}
}
),
Expand Down Expand Up @@ -119,7 +120,7 @@ const txReceipt = await thorSoloClient.transactions.waitForTransaction(
// Check the signed transaction
expect(delegatedSigned.isSigned).toEqual(true);
expect(delegatedSigned.isDelegated).toEqual(true);
expect(delegatedSigned.gasPayer.toString()).toEqual(delegatorAccount.address);
expect(delegatedSigned.gasPayer.toString()).toEqual(gasPayerAccount.address);

// Check the transaction receipt
expect(txReceipt).toBeDefined();
Expand Down
9 changes: 5 additions & 4 deletions docs/examples/transactions/full-flow-delegator-url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ const senderAccount: {
address: '0x571E3E1fBE342891778151f037967E107fb89bd0'
};

// Delegator account with private key
const delegatorAccount = {
// Gas-payer account with private key
const gasPayerAccount = {
URL: 'https://sponsor-testnet.vechain.energy/by/269'
};

Expand All @@ -54,8 +54,9 @@ const providerWithDelegationEnabled = new VeChainProvider(
}
],
{
// The term `delegator` will be deprecated soon and renamed `gasPayer`.
delegator: {
delegatorUrl: delegatorAccount.URL
delegatorUrl: gasPayerAccount.URL
}
}
),
Expand Down Expand Up @@ -123,7 +124,7 @@ const txReceipt = await thorClient.transactions.waitForTransaction(
// Check the signed transaction
expect(delegatedSigned.isSigned).toEqual(true);
expect(delegatedSigned.isDelegated).toEqual(true);
// expect(signedTx.delegator).toEqual(delegatorAccount.address); ---
// expect(signedTx.delegator).toEqual(gasPayerAccount.address); ---

// Check the transaction receipt
expect(txReceipt).toBeDefined();
Expand Down
2 changes: 1 addition & 1 deletion docs/templates/contracts.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,6 @@ You can specify revisions (`best` or `finalized`) for read functions, similar to

## Delegating a Contract Call

VeChain supports delegated contract calls where fees are paid by the delegator.
VeChain supports delegated contract calls where fees are paid by the gas-payer.

[ERC20FunctionCallDelegatedSnippet](examples/contracts/contract-delegation-ERC20.ts)
20 changes: 11 additions & 9 deletions docs/transactions.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,17 +163,17 @@ const body: TransactionBody = {
// 4 - Create private keys of sender and delegate

const nodeDelegate = HDKey.fromMnemonic(Mnemonic.of());
const delegatorPrivateKey = nodeDelegate.privateKey;
const gasPayerPrivateKey = nodeDelegate.privateKey;

// 5 - Get address of delegate

const delegatorAddress = Address.ofPublicKey(nodeDelegate.publicKey).toString();
const gasPayerAddress = Address.ofPublicKey(nodeDelegate.publicKey).toString();

// 6 - Sign transaction as sender and delegate

const signedTransaction = Transaction.of(body).signAsSenderAndGasPayer(
HexUInt.of(senderAccount.privateKey).bytes,
HexUInt.of(delegatorPrivateKey).bytes
HexUInt.of(gasPayerPrivateKey).bytes
);

// 7 - Encode transaction
Expand Down Expand Up @@ -463,8 +463,8 @@ const senderAccount: { privateKey: string; address: string } = {
address: '0x7a28e7361fd10f4f058f9fefc77544349ecff5d6'
};

// Delegator account with private key
const delegatorAccount: { privateKey: string; address: string } = {
// Gas-payer account with private key
const gasPayerAccount: { privateKey: string; address: string } = {
privateKey:
'521b7793c6eb27d137b617627c6b85d57c0aa303380e9ca4e30a30302fbc6676',
address: '0x062F167A905C1484DE7e75B88EDC7439f82117DE'
Expand All @@ -484,8 +484,9 @@ const providerWithDelegationEnabled = new VeChainProvider(
}
],
{
// The term `delegator` will be deprecated soon and renamed `gasPayer`.
delegator: {
delegatorPrivateKey: delegatorAccount.privateKey
delegatorPrivateKey: gasPayerAccount.privateKey
}
}
),
Expand Down Expand Up @@ -570,8 +571,8 @@ const senderAccount: {
address: '0x571E3E1fBE342891778151f037967E107fb89bd0'
};

// Delegator account with private key
const delegatorAccount = {
// Gas-payer account with private key
const gasPayerAccount = {
URL: 'https://sponsor-testnet.vechain.energy/by/269'
};

Expand All @@ -589,8 +590,9 @@ const providerWithDelegationEnabled = new VeChainProvider(
}
],
{
// The term `delegator` will be deprecated soon and renamed `gasPayer`.
delegator: {
delegatorUrl: delegatorAccount.URL
delegatorUrl: gasPayerAccount.URL
}
}
),
Expand Down
Loading

1 comment on commit 3eecea9

@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% (4378/4423) 97.01% (1398/1441) 98.9% (906/916)
Title Tests Skipped Failures Errors Time
core 838 0 πŸ’€ 0 ❌ 0 πŸ”₯ 2m 28s ⏱️
network 731 0 πŸ’€ 0 ❌ 0 πŸ”₯ 5m 15s ⏱️
errors 40 0 πŸ’€ 0 ❌ 0 πŸ”₯ 18.531s ⏱️
logging 3 0 πŸ’€ 0 ❌ 0 πŸ”₯ 19.539s ⏱️
hardhat-plugin 19 0 πŸ’€ 0 ❌ 0 πŸ”₯ 1m 8s ⏱️
aws-kms-adapter 23 0 πŸ’€ 0 ❌ 0 πŸ”₯ 1m 21s ⏱️
ethers-adapter 5 0 πŸ’€ 0 ❌ 0 πŸ”₯ 1m 17s ⏱️
rpc-proxy 37 0 πŸ’€ 0 ❌ 0 πŸ”₯ 1m 7s ⏱️

Please sign in to comment.