Skip to content

Commit 8007fa1

Browse files
committed
feat: add new etna experimental spend
1 parent 36dd950 commit 8007fa1

File tree

11 files changed

+652
-57
lines changed

11 files changed

+652
-57
lines changed

src/serializable/avax/utxo.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ import { TypeSymbols } from '../constants';
1212
* @see https://docs.avax.network/specs/avm-transaction-serialization#unsigned-Exporttx
1313
*/
1414
@serializable()
15-
export class Utxo {
15+
export class Utxo<Output extends Serializable = Serializable> {
1616
_type = TypeSymbols.UTXO;
1717

1818
constructor(
1919
public readonly utxoId: UTXOID,
2020
public readonly assetId: Id,
21-
public readonly output: Serializable,
21+
public readonly output: Output,
2222
) {}
2323

2424
static fromBytes(bytes: Uint8Array, codec: Codec): [Utxo, Uint8Array] {

src/serializable/pvm/stakeableLockOut.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ import { TypeSymbols } from '../constants';
1111
* @see https://docs.avax.network/specs/platform-transaction-serialization#stakeablelockin
1212
*/
1313
@serializable()
14-
export class StakeableLockOut implements Amounter {
14+
export class StakeableLockOut<TransferOut extends Amounter = Amounter>
15+
implements Amounter
16+
{
1517
_type = TypeSymbols.StakeableLockOut;
1618

1719
constructor(
1820
public readonly lockTime: BigIntPr,
19-
public readonly transferOut: Amounter,
21+
public readonly transferOut: TransferOut,
2022
) {}
2123

2224
amount() {

src/utils/consolidate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* @returns an array combined elements
1010
*/
1111
export const consolidate = <T>(
12-
arr: T[],
12+
arr: readonly T[],
1313
canCombine: (a: T, b: T) => boolean,
1414
combine: (a: T, b: T) => T,
1515
): T[] => {

src/vms/pvm/builder.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ describe('pvmBuilder', () => {
220220
});
221221

222222
it('AddValidatorTx - stakeable locked', () => {
223-
const utxos = testUtxos();
223+
const utxos: Utxo[] = testUtxos();
224224
const lockTime = BigInt(Math.floor(new Date().getTime() / 1000)) + 10000n;
225225
const lockedUtxo = new Utxo(
226226
new UTXOID(testUTXOID1, new Int(0)),
@@ -265,7 +265,7 @@ describe('pvmBuilder', () => {
265265
});
266266

267267
it('AddDelegatorTx', () => {
268-
const utxos = testUtxos();
268+
const utxos: Utxo[] = testUtxos();
269269
const lockTime = BigInt(Math.floor(new Date().getTime() / 1000)) + 10000n;
270270
const lockedUtxo = new Utxo(
271271
new UTXOID(testUTXOID1, new Int(0)),

src/vms/pvm/etna-builder/builder.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ import {
6565
getOwnerComplexity,
6666
getSignerComplexity,
6767
} from '../txs/fee';
68-
import { spend } from './spend';
68+
import { spend } from './experimental-spend';
6969

7070
const getAddressMaps = ({
7171
inputs,
@@ -317,16 +317,13 @@ export const newImportTx: TxBuilderFn<NewImportTxProps> = (
317317
outputComplexity,
318318
);
319319

320-
const toBurn = new Map<string, bigint>();
321-
322320
const [error, spendResults] = spend(
323321
{
324322
complexity,
325323
excessAVAX: importedAvax,
326324
fromAddresses,
327325
ownerOverride: OutputOwners.fromNative(toAddresses, locktime, threshold),
328326
spendOptions: defaultedOptions,
329-
toBurn,
330327
utxos,
331328
},
332329
context,
@@ -892,7 +889,6 @@ export const newAddPermissionlessValidatorTx: TxBuilderFn<
892889
context,
893890
) => {
894891
const isPrimaryNetwork = subnetId === PrimaryNetworkID.toString();
895-
const toBurn = new Map<string, bigint>();
896892

897893
const assetId = stakingAssetId ?? context.avaxAssetID;
898894

@@ -935,7 +931,6 @@ export const newAddPermissionlessValidatorTx: TxBuilderFn<
935931
excessAVAX: 0n,
936932
fromAddresses: addressesFromBytes(fromAddressesBytes),
937933
spendOptions: defaultedOptions,
938-
toBurn,
939934
toStake,
940935
utxos,
941936
},
@@ -1058,7 +1053,6 @@ export const newAddPermissionlessDelegatorTx: TxBuilderFn<
10581053
if (isPrimaryNetwork && assetId !== context.avaxAssetID)
10591054
throw new Error('Staking asset ID must be AVAX for the primary network.');
10601055

1061-
const toBurn = new Map<string, bigint>();
10621056
const toStake = new Map<string, bigint>([[assetId, weight]]);
10631057

10641058
const defaultedOptions = defaultSpendOptions(fromAddressesBytes, options);
@@ -1085,7 +1079,6 @@ export const newAddPermissionlessDelegatorTx: TxBuilderFn<
10851079
excessAVAX: 0n,
10861080
fromAddresses: addressesFromBytes(fromAddressesBytes),
10871081
spendOptions: defaultedOptions,
1088-
toBurn,
10891082
toStake,
10901083
utxos,
10911084
},

0 commit comments

Comments
 (0)