Skip to content

Commit ebbb290

Browse files
authored
feat: removed old pvm builder and apis
BREAKING CHANGE: The old PVM transaction builder has been removed. The new Etna builder is now the default builder in order to support dynamic fees. Static fees on P-chain are not longer applicable. Likewise, API's referring to retrieving static fees have been removed where no longer applicable, and new X-Chain specific API's have been added to cover retrieving static tx fees specific to X-Chain transactions. The `e` alias on `pvm` (ie `pvm.e.{builderMethod}`) has been marked deprecated since the builder methods are now directly available on the `pvm` export.
1 parent 06c8738 commit ebbb290

35 files changed

+431
-2903
lines changed

examples/p-chain/base.ts

+27-15
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,41 @@
1-
import { addTxSignatures } from '../../src/signer';
2-
import { TransferableOutput } from '../../src/serializable/avax';
3-
import { bech32ToBytes, hexToBuffer } from '../../src/utils';
4-
import { getContextFromURI } from '../../src/vms/context';
5-
import { newBaseTx } from '../../src/vms/pvm';
6-
import { pvmapi } from '../chain_apis';
1+
import { TransferableOutput, addTxSignatures, pvm, utils } from '../../src';
72
import { getEnvVars } from '../utils/getEnvVars';
3+
import { setupEtnaExample } from './utils/etna-helper';
4+
5+
/**
6+
* The amount of AVAX to send to self.
7+
*/
8+
const SEND_AVAX_AMOUNT: number = 0.001;
89

910
const main = async () => {
1011
const { AVAX_PUBLIC_URL, P_CHAIN_ADDRESS, PRIVATE_KEY } = getEnvVars();
1112

12-
const { utxos } = await pvmapi.getUTXOs({ addresses: [P_CHAIN_ADDRESS] });
13-
const context = await getContextFromURI(AVAX_PUBLIC_URL);
13+
const { context, feeState, pvmApi } = await setupEtnaExample(AVAX_PUBLIC_URL);
14+
15+
const { utxos } = await pvmApi.getUTXOs({ addresses: [P_CHAIN_ADDRESS] });
1416

15-
const tx = newBaseTx(context, [bech32ToBytes(P_CHAIN_ADDRESS)], utxos, [
16-
TransferableOutput.fromNative(context.avaxAssetID, BigInt(0.1 * 1e9), [
17-
bech32ToBytes(P_CHAIN_ADDRESS),
18-
]),
19-
]);
17+
const tx = pvm.newBaseTx(
18+
{
19+
feeState,
20+
fromAddressesBytes: [utils.bech32ToBytes(P_CHAIN_ADDRESS)],
21+
outputs: [
22+
TransferableOutput.fromNative(
23+
context.avaxAssetID,
24+
BigInt(SEND_AVAX_AMOUNT * 1e9),
25+
[utils.bech32ToBytes(P_CHAIN_ADDRESS)],
26+
),
27+
],
28+
utxos,
29+
},
30+
context,
31+
);
2032

2133
await addTxSignatures({
2234
unsignedTx: tx,
23-
privateKeys: [hexToBuffer(PRIVATE_KEY)],
35+
privateKeys: [utils.hexToBuffer(PRIVATE_KEY)],
2436
});
2537

26-
return pvmapi.issueSignedTx(tx.getSignedTx());
38+
return pvmApi.issueSignedTx(tx.getSignedTx());
2739
};
2840

2941
main().then(console.log);

examples/p-chain/etna/convertSubnetToL1.ts renamed to examples/p-chain/convertSubnetToL1.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import {
55
pvm,
66
pvmSerial,
77
utils,
8-
} from '../../../src';
8+
} from '../../src';
99
import { setupEtnaExample } from './utils/etna-helper';
10-
import { getEnvVars } from '../../utils/getEnvVars';
10+
import { getEnvVars } from '../utils/getEnvVars';
1111

1212
const AMOUNT_TO_VALIDATE_AVAX: number = 1;
1313
const BALANCE_AVAX: number = 1;
@@ -56,7 +56,7 @@ const convertSubnetToL1TxExample = async () => {
5656
pChainOwner,
5757
);
5858

59-
const tx = pvm.e.newConvertSubnetToL1Tx(
59+
const tx = pvm.newConvertSubnetToL1Tx(
6060
{
6161
feeState,
6262
fromAddressesBytes: [testPAddr],

examples/p-chain/etna/createChain.ts renamed to examples/p-chain/createChain.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { pvm, utils } from '../../../src';
1+
import { pvm, utils } from '../../src';
22
import { setupEtnaExample } from './utils/etna-helper';
3-
import { testGenesisData } from '../../../src/fixtures/transactions';
4-
import { getEnvVars } from '../../utils/getEnvVars';
3+
import { testGenesisData } from '../../src/fixtures/transactions';
4+
import { getEnvVars } from '../utils/getEnvVars';
55
import { addSigToAllCreds } from './utils/addSignatureToAllCred';
66

77
/**
@@ -24,7 +24,7 @@ const createChainTxExample = async () => {
2424
const vmId = 'rWhpuQPF1kb72esV2momhMuTYGkEb1oL29pt2EBXWmSy4kxnT'; // platform vmId
2525
const subnetId = ''; // subnetId from createSubnetTx
2626

27-
const tx = pvm.e.newCreateChainTx(
27+
const tx = pvm.newCreateChainTx(
2828
{
2929
feeState,
3030
fromAddressesBytes: [testPAddr],

examples/p-chain/etna/createSubnet.ts renamed to examples/p-chain/createSubnet.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { addTxSignatures, pvm, utils } from '../../../src';
2-
import { getEnvVars } from '../../utils/getEnvVars';
1+
import { addTxSignatures, pvm, utils } from '../../src';
2+
import { getEnvVars } from '../utils/getEnvVars';
33
import { setupEtnaExample } from './utils/etna-helper';
44

55
const createSubnetTxExample = async () => {
@@ -11,7 +11,7 @@ const createSubnetTxExample = async () => {
1111

1212
const testPAddr = utils.bech32ToBytes(P_CHAIN_ADDRESS);
1313

14-
const tx = pvm.e.newCreateSubnetTx(
14+
const tx = pvm.newCreateSubnetTx(
1515
{
1616
feeState,
1717
fromAddressesBytes: [testPAddr],

examples/p-chain/delegate.ts

+31-24
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,49 @@
1-
import { PrimaryNetworkID } from '../../src/constants/networkIDs';
2-
import { addTxSignatures } from '../../src/signer';
3-
import { bech32ToBytes, hexToBuffer } from '../../src/utils';
4-
import { getContextFromURI } from '../../src/vms/context';
5-
import { PVMApi, newAddPermissionlessDelegatorTx } from '../../src/vms/pvm';
6-
import { pvmapi } from '../chain_apis';
1+
import { addTxSignatures, networkIDs, pvm, utils } from '../../src';
72
import { getEnvVars } from '../utils/getEnvVars';
3+
import { setupEtnaExample } from './utils/etna-helper';
4+
5+
const AMOUNT_TO_DELEGATE_AVAX: number = 1;
6+
const DAYS_TO_DELEGATE: number = 14;
87

98
const main = async () => {
109
const { AVAX_PUBLIC_URL, P_CHAIN_ADDRESS, PRIVATE_KEY } = getEnvVars();
1110

12-
const { utxos } = await pvmapi.getUTXOs({ addresses: [P_CHAIN_ADDRESS] });
13-
const context = await getContextFromURI(AVAX_PUBLIC_URL);
14-
const startTime = await new PVMApi().getTimestamp();
11+
const { context, feeState, pvmApi } = await setupEtnaExample(AVAX_PUBLIC_URL);
12+
13+
const { utxos } = await pvmApi.getUTXOs({ addresses: [P_CHAIN_ADDRESS] });
14+
15+
const startTime = await pvmApi.getTimestamp();
1516
const startDate = new Date(startTime.timestamp);
16-
const start = BigInt(startDate.getTime() / 1000);
17+
const start: bigint = BigInt(startDate.getTime() / 1_000);
18+
1719
const endTime = new Date(startTime.timestamp);
18-
endTime.setDate(endTime.getDate() + 21);
19-
const end = BigInt(endTime.getTime() / 1000);
20-
const nodeID = 'NodeID-HKLp5269LH8DcrLvHPc2PHjGczBQD3td4';
20+
endTime.setDate(endTime.getDate() + DAYS_TO_DELEGATE);
21+
const end: bigint = BigInt(endTime.getTime() / 1_000);
22+
23+
// TODO: Get this from an argument.
24+
const nodeId = 'NodeID-MqgFXT8JhorbEW2LpTDGePBBhv55SSp3M';
2125

22-
const tx = newAddPermissionlessDelegatorTx(
26+
const tx = pvm.newAddPermissionlessDelegatorTx(
27+
{
28+
end,
29+
feeState,
30+
fromAddressesBytes: [utils.bech32ToBytes(P_CHAIN_ADDRESS)],
31+
nodeId,
32+
rewardAddresses: [utils.bech32ToBytes(P_CHAIN_ADDRESS)],
33+
start,
34+
subnetId: networkIDs.PrimaryNetworkID.toString(),
35+
utxos,
36+
weight: BigInt(AMOUNT_TO_DELEGATE_AVAX * 1e9),
37+
},
2338
context,
24-
utxos,
25-
[bech32ToBytes(P_CHAIN_ADDRESS)],
26-
nodeID,
27-
PrimaryNetworkID.toString(),
28-
start,
29-
end,
30-
BigInt(1e9),
31-
[bech32ToBytes(P_CHAIN_ADDRESS)],
3239
);
3340

3441
await addTxSignatures({
3542
unsignedTx: tx,
36-
privateKeys: [hexToBuffer(PRIVATE_KEY)],
43+
privateKeys: [utils.hexToBuffer(PRIVATE_KEY)],
3744
});
3845

39-
return pvmapi.issueSignedTx(tx.getSignedTx());
46+
return pvmApi.issueSignedTx(tx.getSignedTx());
4047
};
4148

4249
main().then(console.log);

examples/p-chain/etna/base.ts

-41
This file was deleted.

examples/p-chain/etna/delegate.ts

-49
This file was deleted.

examples/p-chain/etna/export.ts

-42
This file was deleted.

examples/p-chain/etna/import.ts

-35
This file was deleted.

0 commit comments

Comments
 (0)