refactor: XAssetID → UTXOAssetID (#119)

The field is the primary network's UTXO fee asset (P+X), not
X-chain-specific. P-chain CreateChainTx / AddChainValidatorTx and
X-chain transfers all burn it for fees. Same number on P and X by
construction; the name should reflect the function, not the chain.

Renames applied across:
- wallet/chain/{p,x}/builder.Context.UTXOAssetID
- wallet/chain/x/builder.Backend.UTXOAssetID() trait method
- node/config: resolveUTXOAssetID + nodeConfig.UTXOAssetID
- vms/platformvm + vms/xvm + chains/manager consumers
- examples (deploy-chains, get-p-chain-balance, ...)

Includes local replaces for luxfi/{runtime,consensus} pending their
release tags landing. Drop after upstream tags ship.

Companion PRs: luxfi/runtime#2, luxfi/consensus#11. Downstream
consumers (sdk, cli, genesis, liquidity) follow.
This commit is contained in:
Hanzo Dev
2026-05-30 14:28:08 -07:00
committed by GitHub
parent 8b2a559aef
commit be744a9dbf
69 changed files with 409 additions and 409 deletions
+24 -24
View File
@@ -292,7 +292,7 @@ func (b *txBuilder) NewBaseTx(
options ...common.Option,
) (*txs.BaseTx, error) {
toBurn := map[ids.ID]uint64{
b.context.XAssetID: b.context.StaticFeeConfig.TxFee,
b.context.UTXOAssetID: b.context.StaticFeeConfig.TxFee,
}
for _, out := range outputs {
assetID := out.AssetID()
@@ -327,12 +327,12 @@ func (b *txBuilder) NewAddValidatorTx(
shares uint32,
options ...common.Option,
) (*txs.AddValidatorTx, error) {
xAssetID := b.context.XAssetID
utxoAssetID := b.context.UTXOAssetID
toBurn := map[ids.ID]uint64{
xAssetID: b.context.StaticFeeConfig.AddNetworkValidatorFee,
utxoAssetID: b.context.StaticFeeConfig.AddNetworkValidatorFee,
}
toStake := map[ids.ID]uint64{
xAssetID: vdr.Wght,
utxoAssetID: vdr.Wght,
}
ops := common.NewOptions(options)
inputs, baseOutputs, stakeOutputs, err := b.spend(toBurn, toStake, ops)
@@ -361,7 +361,7 @@ func (b *txBuilder) NewAddChainValidatorTx(
options ...common.Option,
) (*txs.AddChainValidatorTx, error) {
toBurn := map[ids.ID]uint64{
b.context.XAssetID: b.context.StaticFeeConfig.AddChainValidatorFee,
b.context.UTXOAssetID: b.context.StaticFeeConfig.AddChainValidatorFee,
}
toStake := map[ids.ID]uint64{}
ops := common.NewOptions(options)
@@ -394,7 +394,7 @@ func (b *txBuilder) NewRemoveChainValidatorTx(
options ...common.Option,
) (*txs.RemoveChainValidatorTx, error) {
toBurn := map[ids.ID]uint64{
b.context.XAssetID: b.context.StaticFeeConfig.TxFee,
b.context.UTXOAssetID: b.context.StaticFeeConfig.TxFee,
}
toStake := map[ids.ID]uint64{}
ops := common.NewOptions(options)
@@ -427,12 +427,12 @@ func (b *txBuilder) NewAddDelegatorTx(
rewardsOwner *secp256k1fx.OutputOwners,
options ...common.Option,
) (*txs.AddDelegatorTx, error) {
xAssetID := b.context.XAssetID
utxoAssetID := b.context.UTXOAssetID
toBurn := map[ids.ID]uint64{
xAssetID: b.context.StaticFeeConfig.AddNetworkDelegatorFee,
utxoAssetID: b.context.StaticFeeConfig.AddNetworkDelegatorFee,
}
toStake := map[ids.ID]uint64{
b.context.XAssetID: vdr.Wght,
b.context.UTXOAssetID: vdr.Wght,
}
ops := common.NewOptions(options)
inputs, baseOutputs, stakeOutputs, err := b.spend(toBurn, toStake, ops)
@@ -464,7 +464,7 @@ func (b *txBuilder) NewCreateChainTx(
options ...common.Option,
) (*txs.CreateChainTx, error) {
toBurn := map[ids.ID]uint64{
b.context.XAssetID: b.context.StaticFeeConfig.CreateChainTxFee,
b.context.UTXOAssetID: b.context.StaticFeeConfig.CreateChainTxFee,
}
toStake := map[ids.ID]uint64{}
ops := common.NewOptions(options)
@@ -501,7 +501,7 @@ func (b *txBuilder) NewCreateNetworkTx(
options ...common.Option,
) (*txs.CreateNetworkTx, error) {
toBurn := map[ids.ID]uint64{
b.context.XAssetID: b.context.StaticFeeConfig.CreateNetworkTxFee,
b.context.UTXOAssetID: b.context.StaticFeeConfig.CreateNetworkTxFee,
}
toStake := map[ids.ID]uint64{}
ops := common.NewOptions(options)
@@ -537,7 +537,7 @@ func (b *txBuilder) NewImportTx(
var (
addrs = ops.Addresses(b.addrs)
minIssuanceTime = ops.MinIssuanceTime()
xAssetID = b.context.XAssetID
utxoAssetID = b.context.UTXOAssetID
txFee = b.context.StaticFeeConfig.TxFee
importedInputs = make([]*lux.TransferableInput, 0, len(utxos))
@@ -586,14 +586,14 @@ func (b *txBuilder) NewImportTx(
var (
inputs []*lux.TransferableInput
outputs = make([]*lux.TransferableOutput, 0, len(importedAmounts))
importedLUX = importedAmounts[xAssetID]
importedLUX = importedAmounts[utxoAssetID]
)
if importedLUX > txFee {
importedAmounts[xAssetID] -= txFee
importedAmounts[utxoAssetID] -= txFee
} else {
if importedLUX < txFee { // imported amount goes toward paying tx fee
toBurn := map[ids.ID]uint64{
xAssetID: txFee - importedLUX,
utxoAssetID: txFee - importedLUX,
}
toStake := map[ids.ID]uint64{}
var err error
@@ -602,7 +602,7 @@ func (b *txBuilder) NewImportTx(
return nil, fmt.Errorf("couldn't generate tx inputs/outputs: %w", err)
}
}
delete(importedAmounts, xAssetID)
delete(importedAmounts, utxoAssetID)
}
for assetID, amount := range importedAmounts {
@@ -635,7 +635,7 @@ func (b *txBuilder) NewExportTx(
options ...common.Option,
) (*txs.ExportTx, error) {
toBurn := map[ids.ID]uint64{
b.context.XAssetID: b.context.StaticFeeConfig.TxFee,
b.context.UTXOAssetID: b.context.StaticFeeConfig.TxFee,
}
for _, out := range outputs {
assetID := out.AssetID()
@@ -685,7 +685,7 @@ func (b *txBuilder) NewTransformChainTx(
options ...common.Option,
) (*txs.TransformChainTx, error) {
toBurn := map[ids.ID]uint64{
b.context.XAssetID: b.context.StaticFeeConfig.TransformChainTxFee,
b.context.UTXOAssetID: b.context.StaticFeeConfig.TransformChainTxFee,
assetID: maxSupply - initialSupply,
}
toStake := map[ids.ID]uint64{}
@@ -735,12 +735,12 @@ func (b *txBuilder) NewAddPermissionlessValidatorTx(
shares uint32,
options ...common.Option,
) (*txs.AddPermissionlessValidatorTx, error) {
xAssetID := b.context.XAssetID
utxoAssetID := b.context.UTXOAssetID
toBurn := map[ids.ID]uint64{}
if vdr.Chain == constants.PrimaryNetworkID {
toBurn[xAssetID] = b.context.StaticFeeConfig.AddNetworkValidatorFee
toBurn[utxoAssetID] = b.context.StaticFeeConfig.AddNetworkValidatorFee
} else {
toBurn[xAssetID] = b.context.StaticFeeConfig.AddChainValidatorFee
toBurn[utxoAssetID] = b.context.StaticFeeConfig.AddChainValidatorFee
}
toStake := map[ids.ID]uint64{
assetID: vdr.Wght,
@@ -777,12 +777,12 @@ func (b *txBuilder) NewAddPermissionlessDelegatorTx(
rewardsOwner *secp256k1fx.OutputOwners,
options ...common.Option,
) (*txs.AddPermissionlessDelegatorTx, error) {
xAssetID := b.context.XAssetID
utxoAssetID := b.context.UTXOAssetID
toBurn := map[ids.ID]uint64{}
if vdr.Chain == constants.PrimaryNetworkID {
toBurn[xAssetID] = b.context.StaticFeeConfig.AddNetworkDelegatorFee
toBurn[utxoAssetID] = b.context.StaticFeeConfig.AddNetworkDelegatorFee
} else {
toBurn[xAssetID] = b.context.StaticFeeConfig.AddChainDelegatorFee
toBurn[utxoAssetID] = b.context.StaticFeeConfig.AddChainDelegatorFee
}
toStake := map[ids.ID]uint64{
assetID: vdr.Wght,
+17 -17
View File
@@ -445,10 +445,10 @@ func (b *builder) NewAddValidatorTx(
shares uint32,
options ...common.Option,
) (*txs.AddValidatorTx, error) {
xAssetID := b.context.XAssetID
utxoAssetID := b.context.UTXOAssetID
toBurn := map[ids.ID]uint64{}
toStake := map[ids.ID]uint64{
xAssetID: vdr.Wght,
utxoAssetID: vdr.Wght,
}
ops := common.NewOptions(options)
inputs, baseOutputs, stakeOutputs, err := b.spend(
@@ -600,10 +600,10 @@ func (b *builder) NewAddDelegatorTx(
rewardsOwner *secp256k1fx.OutputOwners,
options ...common.Option,
) (*txs.AddDelegatorTx, error) {
xAssetID := b.context.XAssetID
utxoAssetID := b.context.UTXOAssetID
toBurn := map[ids.ID]uint64{}
toStake := map[ids.ID]uint64{
xAssetID: vdr.Wght,
utxoAssetID: vdr.Wght,
}
ops := common.NewOptions(options)
inputs, baseOutputs, stakeOutputs, err := b.spend(
@@ -846,7 +846,7 @@ func (b *builder) NewConvertNetworkToL1Tx(
var (
toBurn = map[ids.ID]uint64{
b.context.XAssetID: luxToBurn,
b.context.UTXOAssetID: luxToBurn,
}
toStake = map[ids.ID]uint64{}
ops = common.NewOptions(options)
@@ -919,7 +919,7 @@ func (b *builder) NewRegisterL1ValidatorTx(
) (*txs.RegisterL1ValidatorTx, error) {
var (
toBurn = map[ids.ID]uint64{
b.context.XAssetID: balance,
b.context.UTXOAssetID: balance,
}
toStake = map[ids.ID]uint64{}
@@ -1025,7 +1025,7 @@ func (b *builder) NewIncreaseL1ValidatorBalanceTx(
) (*txs.IncreaseL1ValidatorBalanceTx, error) {
var (
toBurn = map[ids.ID]uint64{
b.context.XAssetID: balance,
b.context.UTXOAssetID: balance,
}
toStake = map[ids.ID]uint64{}
ops = common.NewOptions(options)
@@ -1138,7 +1138,7 @@ func (b *builder) NewImportTx(
var (
addrs = ops.Addresses(b.addrs)
minIssuanceTime = ops.MinIssuanceTime()
xAssetID = b.context.XAssetID
utxoAssetID = b.context.UTXOAssetID
importedInputs = make([]*lux.TransferableInput, 0, len(utxos))
importedAmounts = make(map[ids.ID]uint64)
@@ -1185,7 +1185,7 @@ func (b *builder) NewImportTx(
outputs := make([]*lux.TransferableOutput, 0, len(importedAmounts))
for assetID, amount := range importedAmounts {
if assetID == xAssetID {
if assetID == utxoAssetID {
continue
}
@@ -1223,7 +1223,7 @@ func (b *builder) NewImportTx(
toBurn = map[ids.ID]uint64{}
toStake = map[ids.ID]uint64{}
)
excessLUX := importedAmounts[xAssetID]
excessLUX := importedAmounts[utxoAssetID]
inputs, changeOutputs, _, err := b.spend(
toBurn,
@@ -1718,7 +1718,7 @@ func (b *builder) spend(
}
// LUX is handled last to account for fees.
utxosByLUXAssetID := splitByAssetID(utxosByLocktime.unlocked, b.context.XAssetID)
utxosByLUXAssetID := splitByAssetID(utxosByLocktime.unlocked, b.context.UTXOAssetID)
for _, utxo := range utxosByLUXAssetID.other {
assetID := utxo.AssetID()
if !s.shouldConsumeAsset(assetID) {
@@ -1772,7 +1772,7 @@ func (b *builder) spend(
// Check if we already have enough excessLUX to pay fees before adding more inputs.
// This early exit is crucial for ImportTx where imported inputs may already provide
// sufficient LUX to cover fees, and we don't want to add unnecessary platform chain inputs.
if !s.shouldConsumeAsset(b.context.XAssetID) {
if !s.shouldConsumeAsset(b.context.UTXOAssetID) {
requiredFee, err := s.calculateFee()
if err != nil {
return nil, nil, nil, err
@@ -1807,7 +1807,7 @@ func (b *builder) spend(
return nil, nil, nil, err
}
excess := s.consumeAsset(b.context.XAssetID, out.Amt)
excess := s.consumeAsset(b.context.UTXOAssetID, out.Amt)
excessLUX, err = math.Add(excessLUX, excess)
if err != nil {
return nil, nil, nil, err
@@ -1822,7 +1822,7 @@ func (b *builder) spend(
// If we don't need to burn or stake additional LUX and we have
// consumed enough LUX to pay the required fee, we should stop
// consuming UTXOs.
if !s.shouldConsumeAsset(b.context.XAssetID) && excessLUX >= requiredFee {
if !s.shouldConsumeAsset(b.context.UTXOAssetID) && excessLUX >= requiredFee {
// If we need to consume additional LUX, we should be returning the
// change to the change address.
ownerOverride = changeOwner
@@ -1847,7 +1847,7 @@ func (b *builder) spend(
"%w: provided UTXOs needed %d more nLUX (%q)",
ErrInsufficientFunds,
requiredFee-excessLUX,
b.context.XAssetID,
b.context.UTXOAssetID,
)
}
@@ -1858,7 +1858,7 @@ func (b *builder) spend(
}
excessLUXOutput := &lux.TransferableOutput{
Asset: lux.Asset{
ID: b.context.XAssetID,
ID: b.context.UTXOAssetID,
},
Out: secpExcessLUXOutput,
}
@@ -1927,7 +1927,7 @@ func (b *builder) authorize(ownerID ids.ID, options *common.Options) (*secp256k1
}
func (b *builder) initCtx(tx txs.UnsignedTx) error {
rt, err := NewConsensusRuntime(b.context.NetworkID, b.context.XAssetID)
rt, err := NewConsensusRuntime(b.context.NetworkID, b.context.UTXOAssetID)
if err != nil {
return err
}
+5 -5
View File
@@ -16,22 +16,22 @@ const Alias = "P"
type Context struct {
NetworkID uint32
ChainID ids.ID // Optional: if set, overrides default PlatformChainID
XAssetID ids.ID
UTXOAssetID ids.ID
ComplexityWeights gas.Dimensions
GasPrice gas.Price
StaticFeeConfig fee.StaticConfig
}
func NewConsensusRuntime(networkID uint32, xAssetID ids.ID) (*runtime.Runtime, error) {
return NewConsensusRuntimeWithChainID(networkID, constants.PlatformChainID, xAssetID)
func NewConsensusRuntime(networkID uint32, utxoAssetID ids.ID) (*runtime.Runtime, error) {
return NewConsensusRuntimeWithChainID(networkID, constants.PlatformChainID, utxoAssetID)
}
func NewConsensusRuntimeWithChainID(networkID uint32, chainID ids.ID, xAssetID ids.ID) (*runtime.Runtime, error) {
func NewConsensusRuntimeWithChainID(networkID uint32, chainID ids.ID, utxoAssetID ids.ID) (*runtime.Runtime, error) {
lookup := ids.NewAliaser()
rt := &runtime.Runtime{
NetworkID: networkID,
ChainID: chainID,
XAssetID: xAssetID,
UTXOAssetID: utxoAssetID,
}
return rt, lookup.Alias(chainID, Alias)
}
+17 -17
View File
@@ -75,14 +75,14 @@ var (
Addrs: []ids.ShortID{validationAuthAddr},
}
// We hard-code [xAssetID] and [chainAssetID] to make ordering of UTXOs
// We hard-code [utxoAssetID] and [chainAssetID] to make ordering of UTXOs
// generated by [makeTestUTXOs] reproducible.
xAssetID = ids.Empty.Prefix(1789)
utxoAssetID = ids.Empty.Prefix(1789)
chainAssetID = ids.Empty.Prefix(2025)
utxos = makeTestUTXOs(utxoKey)
luxOutput = &lux.TransferableOutput{
Asset: lux.Asset{ID: xAssetID},
Asset: lux.Asset{ID: utxoAssetID},
Out: &secp256k1fx.TransferOutput{
Amt: 7 * constants.Lux,
OutputOwners: utxoOwner,
@@ -107,7 +107,7 @@ var (
testContext = &builder.Context{
NetworkID: constants.UnitTestID,
XAssetID: xAssetID,
UTXOAssetID: utxoAssetID,
ComplexityWeights: gas.Dimensions{
gas.Bandwidth: 1,
@@ -420,7 +420,7 @@ func TestAddPermissionlessValidatorTx(t *testing.T) {
TxID: ids.Empty.Prefix(utxosOffset),
OutputIndex: uint32(utxosOffset),
},
Asset: lux.Asset{ID: xAssetID},
Asset: lux.Asset{ID: utxoAssetID},
Out: &secp256k1fx.TransferOutput{
Amt: amount,
OutputOwners: utxoOwner,
@@ -459,7 +459,7 @@ func TestAddPermissionlessValidatorTx(t *testing.T) {
utx, err := builder.NewAddPermissionlessValidatorTx(
primaryNetworkPermissionlessStaker,
pop,
xAssetID,
utxoAssetID,
validationRewardsOwner,
delegationRewardsOwner,
delegationShares,
@@ -476,7 +476,7 @@ func TestAddPermissionlessValidatorTx(t *testing.T) {
// check stake amount
require.Equal(
map[ids.ID]uint64{
xAssetID: primaryNetworkPermissionlessStaker.Wght,
utxoAssetID: primaryNetworkPermissionlessStaker.Wght,
},
addOutputAmounts(utx.StakeOuts),
)
@@ -511,7 +511,7 @@ func TestAddPermissionlessDelegatorTx(t *testing.T) {
utx, err := builder.NewAddPermissionlessDelegatorTx(
primaryNetworkPermissionlessStaker,
xAssetID,
utxoAssetID,
rewardsOwner,
common.WithMemo(e.memo),
)
@@ -521,7 +521,7 @@ func TestAddPermissionlessDelegatorTx(t *testing.T) {
// check stake amount
require.Equal(
map[ids.ID]uint64{
xAssetID: primaryNetworkPermissionlessStaker.Wght,
utxoAssetID: primaryNetworkPermissionlessStaker.Wght,
},
addOutputAmounts(utx.StakeOuts),
)
@@ -618,7 +618,7 @@ func TestConvertNetworkToL1Tx(t *testing.T) {
nil,
nil,
map[ids.ID]uint64{
e.context.XAssetID: 3 * constants.Lux, // Balance of the validators
e.context.UTXOAssetID: 3 * constants.Lux, // Balance of the validators
},
)
})
@@ -721,7 +721,7 @@ func TestRegisterL1ValidatorTx(t *testing.T) {
nil,
nil,
map[ids.ID]uint64{
e.context.XAssetID: balance, // Balance of the validator
e.context.UTXOAssetID: balance, // Balance of the validator
},
)
})
@@ -838,7 +838,7 @@ func TestIncreaseL1ValidatorBalanceTx(t *testing.T) {
nil,
nil,
map[ids.ID]uint64{
e.context.XAssetID: balance, // Balance increase
e.context.UTXOAssetID: balance, // Balance increase
},
)
})
@@ -890,7 +890,7 @@ func makeTestUTXOs(utxosKey *secp256k1.PrivateKey) []*lux.UTXO {
TxID: ids.Empty.Prefix(utxosOffset),
OutputIndex: uint32(utxosOffset),
},
Asset: lux.Asset{ID: xAssetID},
Asset: lux.Asset{ID: utxoAssetID},
Out: &secp256k1fx.TransferOutput{
Amt: 2 * constants.MilliLux,
OutputOwners: secp256k1fx.OutputOwners{
@@ -905,7 +905,7 @@ func makeTestUTXOs(utxosKey *secp256k1.PrivateKey) []*lux.UTXO {
TxID: ids.Empty.Prefix(utxosOffset + 1),
OutputIndex: uint32(utxosOffset + 1),
},
Asset: lux.Asset{ID: xAssetID},
Asset: lux.Asset{ID: utxoAssetID},
Out: &stakeable.LockOut{
Locktime: uint64(time.Now().Add(time.Hour).Unix()),
TransferableOut: &secp256k1fx.TransferOutput{
@@ -937,7 +937,7 @@ func makeTestUTXOs(utxosKey *secp256k1.PrivateKey) []*lux.UTXO {
TxID: ids.Empty.Prefix(utxosOffset + 3),
OutputIndex: uint32(utxosOffset + 3),
},
Asset: lux.Asset{ID: xAssetID},
Asset: lux.Asset{ID: utxoAssetID},
Out: &stakeable.LockOut{
Locktime: uint64(time.Now().Add(time.Hour).Unix()),
TransferableOut: &secp256k1fx.TransferOutput{
@@ -954,7 +954,7 @@ func makeTestUTXOs(utxosKey *secp256k1.PrivateKey) []*lux.UTXO {
TxID: ids.Empty.Prefix(utxosOffset + 4),
OutputIndex: uint32(utxosOffset + 4),
},
Asset: lux.Asset{ID: xAssetID},
Asset: lux.Asset{ID: utxoAssetID},
Out: &secp256k1fx.TransferOutput{
Amt: 9 * constants.Lux,
OutputOwners: secp256k1fx.OutputOwners{
@@ -985,7 +985,7 @@ func requireFeeIsCorrect(
require.NoError(err)
expectedAmountBurned := addAmounts(
map[ids.ID]uint64{
xAssetID: expectedFee,
utxoAssetID: expectedFee,
},
additionalFee,
)
+2 -2
View File
@@ -36,7 +36,7 @@ func NewContextFromClients(
return nil, err
}
xAssetID, err := chainClient.GetStakingAssetID(ctx, constants.PrimaryNetworkID)
utxoAssetID, err := chainClient.GetStakingAssetID(ctx, constants.PrimaryNetworkID)
if err != nil {
return nil, err
}
@@ -53,7 +53,7 @@ func NewContextFromClients(
return &builder.Context{
NetworkID: networkID,
XAssetID: xAssetID,
UTXOAssetID: utxoAssetID,
ComplexityWeights: dynamicFeeConfig.Weights,
GasPrice: gasPriceMultiplier * gasPrice,
// Static fee config - use defaults matching platformvm/config
+11 -11
View File
@@ -153,7 +153,7 @@ type Builder interface {
type Context struct {
NetworkID uint32
BlockchainID ids.ID
XAssetID ids.ID
UTXOAssetID ids.ID
BaseTxFee uint64
CreateAssetTxFee uint64
}
@@ -163,7 +163,7 @@ type Context struct {
type BuilderBackend interface {
Context() *builder.Context
BlockchainID() ids.ID
XAssetID() ids.ID
UTXOAssetID() ids.ID
BaseTxFee() uint64
CreateAssetTxFee() uint64
@@ -208,7 +208,7 @@ func (b *txBuilder) NewBaseTx(
options ...common.Option,
) (*txs.BaseTx, error) {
toBurn := map[ids.ID]uint64{
b.backend.XAssetID(): b.backend.BaseTxFee(),
b.backend.UTXOAssetID(): b.backend.BaseTxFee(),
}
for _, out := range outputs {
assetID := out.AssetID()
@@ -244,7 +244,7 @@ func (b *txBuilder) NewCreateAssetTx(
options ...common.Option,
) (*txs.CreateAssetTx, error) {
toBurn := map[ids.ID]uint64{
b.backend.XAssetID(): b.backend.CreateAssetTxFee(),
b.backend.UTXOAssetID(): b.backend.CreateAssetTxFee(),
}
ops := common.NewOptions(options)
inputs, outputs, err := b.spend(toBurn, ops)
@@ -285,7 +285,7 @@ func (b *txBuilder) NewOperationTx(
options ...common.Option,
) (*txs.OperationTx, error) {
toBurn := map[ids.ID]uint64{
b.backend.XAssetID(): b.backend.BaseTxFee(),
b.backend.UTXOAssetID(): b.backend.BaseTxFee(),
}
ops := common.NewOptions(options)
inputs, outputs, err := b.spend(toBurn, ops)
@@ -371,7 +371,7 @@ func (b *txBuilder) NewImportTx(
var (
addrs = ops.Addresses(b.addrs)
minIssuanceTime = ops.MinIssuanceTime()
xAssetID = b.backend.XAssetID()
utxoAssetID = b.backend.UTXOAssetID()
txFee = b.backend.BaseTxFee()
importedInputs = make([]*lux.TransferableInput, 0, len(utxos))
@@ -421,14 +421,14 @@ func (b *txBuilder) NewImportTx(
var (
inputs []*lux.TransferableInput
outputs = make([]*lux.TransferableOutput, 0, len(importedAmounts))
importedLUX = importedAmounts[xAssetID]
importedLUX = importedAmounts[utxoAssetID]
)
if importedLUX > txFee {
importedAmounts[xAssetID] -= txFee
importedAmounts[utxoAssetID] -= txFee
} else {
if importedLUX < txFee { // imported amount goes toward paying tx fee
toBurn := map[ids.ID]uint64{
xAssetID: txFee - importedLUX,
utxoAssetID: txFee - importedLUX,
}
var err error
inputs, outputs, err = b.spend(toBurn, ops)
@@ -436,7 +436,7 @@ func (b *txBuilder) NewImportTx(
return nil, fmt.Errorf("couldn't generate tx inputs/outputs: %w", err)
}
}
delete(importedAmounts, xAssetID)
delete(importedAmounts, utxoAssetID)
}
for assetID, amount := range importedAmounts {
@@ -469,7 +469,7 @@ func (b *txBuilder) NewExportTx(
options ...common.Option,
) (*txs.ExportTx, error) {
toBurn := map[ids.ID]uint64{
b.backend.XAssetID(): b.backend.BaseTxFee(),
b.backend.UTXOAssetID(): b.backend.BaseTxFee(),
}
for _, out := range outputs {
assetID := out.AssetID()
+9 -9
View File
@@ -209,7 +209,7 @@ func (b *builder) NewBaseTx(
options ...common.Option,
) (*txs.BaseTx, error) {
toBurn := map[ids.ID]uint64{
b.context.XAssetID: b.context.BaseTxFee,
b.context.UTXOAssetID: b.context.BaseTxFee,
}
for _, out := range outputs {
assetID := out.AssetID()
@@ -246,7 +246,7 @@ func (b *builder) NewCreateAssetTx(
options ...common.Option,
) (*txs.CreateAssetTx, error) {
toBurn := map[ids.ID]uint64{
b.context.XAssetID: b.context.CreateAssetTxFee,
b.context.UTXOAssetID: b.context.CreateAssetTxFee,
}
ops := common.NewOptions(options)
inputs, outputs, err := b.spend(toBurn, ops)
@@ -288,7 +288,7 @@ func (b *builder) NewOperationTx(
options ...common.Option,
) (*txs.OperationTx, error) {
toBurn := map[ids.ID]uint64{
b.context.XAssetID: b.context.BaseTxFee,
b.context.UTXOAssetID: b.context.BaseTxFee,
}
ops := common.NewOptions(options)
inputs, outputs, err := b.spend(toBurn, ops)
@@ -375,7 +375,7 @@ func (b *builder) NewImportTx(
var (
addrs = ops.Addresses(b.addrs)
minIssuanceTime = ops.MinIssuanceTime()
xAssetID = b.context.XAssetID
utxoAssetID = b.context.UTXOAssetID
txFee = b.context.BaseTxFee
importedInputs = make([]*lux.TransferableInput, 0, len(utxos))
@@ -426,14 +426,14 @@ func (b *builder) NewImportTx(
var (
inputs []*lux.TransferableInput
outputs = make([]*lux.TransferableOutput, 0, len(importedAmounts))
importedLUX = importedAmounts[xAssetID]
importedLUX = importedAmounts[utxoAssetID]
)
if importedLUX > txFee {
importedAmounts[xAssetID] -= txFee
importedAmounts[utxoAssetID] -= txFee
} else {
if importedLUX < txFee { // imported amount goes toward paying tx fee
toBurn := map[ids.ID]uint64{
xAssetID: txFee - importedLUX,
utxoAssetID: txFee - importedLUX,
}
var err error
inputs, outputs, err = b.spend(toBurn, ops)
@@ -441,7 +441,7 @@ func (b *builder) NewImportTx(
return nil, fmt.Errorf("couldn't generate tx inputs/outputs: %w", err)
}
}
delete(importedAmounts, xAssetID)
delete(importedAmounts, utxoAssetID)
}
for assetID, amount := range importedAmounts {
@@ -476,7 +476,7 @@ func (b *builder) NewExportTx(
options ...common.Option,
) (*txs.ExportTx, error) {
toBurn := map[ids.ID]uint64{
b.context.XAssetID: b.context.BaseTxFee,
b.context.UTXOAssetID: b.context.BaseTxFee,
}
for _, out := range outputs {
assetID := out.AssetID()
+3 -3
View File
@@ -13,7 +13,7 @@ const Alias = "X"
type Context struct {
NetworkID uint32
BlockchainID ids.ID
XAssetID ids.ID
UTXOAssetID ids.ID
BaseTxFee uint64
CreateAssetTxFee uint64
}
@@ -21,14 +21,14 @@ type Context struct {
func NewConsensusRuntime(
networkID uint32,
blockchainID ids.ID,
xAssetID ids.ID,
utxoAssetID ids.ID,
) (*runtime.Runtime, error) {
lookup := ids.NewAliaser()
rt := &runtime.Runtime{
NetworkID: networkID,
ChainID: blockchainID,
XChainID: blockchainID,
XAssetID: xAssetID,
UTXOAssetID: utxoAssetID,
}
return rt, lookup.Alias(blockchainID, Alias)
}
+7 -7
View File
@@ -26,9 +26,9 @@ import (
var (
testKeys = secp256k1.TestKeys()
// We hard-code [xAssetID] and [chainAssetID] to make
// We hard-code [utxoAssetID] and [chainAssetID] to make
// ordering of UTXOs generated by [testUTXOsList] is reproducible
xAssetID = ids.Empty.Prefix(1789)
utxoAssetID = ids.Empty.Prefix(1789)
xChainID = ids.Empty.Prefix(2021)
nftAssetID = ids.Empty.Prefix(2022)
propertyAssetID = ids.Empty.Prefix(2023)
@@ -36,7 +36,7 @@ var (
testContext = &builder.Context{
NetworkID: constants.UnitTestID,
BlockchainID: xChainID,
XAssetID: xAssetID,
UTXOAssetID: utxoAssetID,
BaseTxFee: constants.MicroLux,
CreateAssetTxFee: 99 * constants.MilliLux,
}
@@ -66,7 +66,7 @@ func TestBaseTx(t *testing.T) {
// data to build the transaction
outputsToMove = []*lux.TransferableOutput{{
Asset: lux.Asset{ID: xAssetID},
Asset: lux.Asset{ID: utxoAssetID},
Out: &secp256k1fx.TransferOutput{
Amt: 7 * constants.Lux,
OutputOwners: secp256k1fx.OutputOwners{
@@ -428,7 +428,7 @@ func TestExportTx(t *testing.T) {
// data to build the transaction
netID = ids.GenerateTestID()
exportedOutputs = []*lux.TransferableOutput{{
Asset: lux.Asset{ID: xAssetID},
Asset: lux.Asset{ID: utxoAssetID},
Out: &secp256k1fx.TransferOutput{
Amt: 7 * constants.Lux,
OutputOwners: secp256k1fx.OutputOwners{
@@ -468,7 +468,7 @@ func makeTestUTXOs(utxosKey *secp256k1.PrivateKey) []*lux.UTXO {
TxID: ids.Empty.Prefix(utxosOffset),
OutputIndex: uint32(utxosOffset),
},
Asset: lux.Asset{ID: xAssetID},
Asset: lux.Asset{ID: utxoAssetID},
Out: &secp256k1fx.TransferOutput{
Amt: 2 * constants.MilliLux,
OutputOwners: secp256k1fx.OutputOwners{
@@ -538,7 +538,7 @@ func makeTestUTXOs(utxosKey *secp256k1.PrivateKey) []*lux.UTXO {
TxID: ids.Empty.Prefix(utxosOffset + 6),
OutputIndex: uint32(utxosOffset + 6),
},
Asset: lux.Asset{ID: xAssetID},
Asset: lux.Asset{ID: utxoAssetID},
Out: &secp256k1fx.TransferOutput{
Amt: 9 * constants.Lux,
OutputOwners: secp256k1fx.OutputOwners{
+4 -4
View File
@@ -11,15 +11,15 @@ import (
"github.com/luxfi/sdk/info"
)
func NewContextFromURI(ctx context.Context, uri string, xAssetID ids.ID, baseTxFee uint64, createAssetTxFee uint64) (*builder.Context, error) {
func NewContextFromURI(ctx context.Context, uri string, utxoAssetID ids.ID, baseTxFee uint64, createAssetTxFee uint64) (*builder.Context, error) {
infoClient := info.NewClient(uri)
return NewContextFromClients(ctx, infoClient, xAssetID, baseTxFee, createAssetTxFee)
return NewContextFromClients(ctx, infoClient, utxoAssetID, baseTxFee, createAssetTxFee)
}
func NewContextFromClients(
ctx context.Context,
infoClient *info.Client,
xAssetID ids.ID,
utxoAssetID ids.ID,
baseTxFee uint64,
createAssetTxFee uint64,
) (*builder.Context, error) {
@@ -36,7 +36,7 @@ func NewContextFromClients(
return &builder.Context{
NetworkID: networkID,
BlockchainID: chainID,
XAssetID: xAssetID,
UTXOAssetID: utxoAssetID,
BaseTxFee: baseTxFee,
CreateAssetTxFee: createAssetTxFee,
}, nil
+2 -2
View File
@@ -124,11 +124,11 @@ func FetchState(
// X-chain fees are derived from the P-chain context. The fee values
// here match the primary network defaults and are overridden at the
// chain level when dynamic fees are enabled.
xAssetID := pCTX.XAssetID
utxoAssetID := pCTX.UTXOAssetID
baseTxFee := uint64(1000000) // 0.001 LUX
createAssetTxFee := uint64(10000000) // 0.01 LUX
xCTX, err := x.NewContextFromClients(ctx, infoClient, xAssetID, baseTxFee, createAssetTxFee)
xCTX, err := x.NewContextFromClients(ctx, infoClient, utxoAssetID, baseTxFee, createAssetTxFee)
if err != nil {
return nil, err
}
@@ -66,7 +66,7 @@ func main() {
pWallet := wallet.P()
pBuilder := pWallet.Builder()
pContext := pBuilder.Context()
xAssetID := pContext.XAssetID
utxoAssetID := pContext.UTXOAssetID
addValidatorStartTime := time.Now()
addValidatorTx, err := pWallet.IssueAddPermissionlessValidatorTx(
@@ -77,7 +77,7 @@ func main() {
Wght: weight,
}},
pop,
xAssetID,
utxoAssetID,
&secp256k1fx.OutputOwners{
Threshold: 1,
Addrs: []ids.ShortID{validatorRewardAddr},
@@ -167,7 +167,7 @@ func main() {
log.Fatalf("wallet sync: %v", err)
}
luxAssetID := w.X().Builder().Context().XAssetID
luxAssetID := w.X().Builder().Context().UTXOAssetID
pBal, err := w.P().Builder().GetBalance()
if err != nil {
log.Fatalf("P balance: %v", err)
@@ -52,13 +52,13 @@ func main() {
pWallet := wallet.P()
pBuilder := pWallet.Builder()
pContext := pBuilder.Context()
xAssetID := pContext.XAssetID
utxoAssetID := pContext.UTXOAssetID
issueTxStartTime := time.Now()
tx, err := pWallet.IssueBaseTx([]*lux.TransferableOutput{
{
Asset: lux.Asset{
ID: xAssetID,
ID: utxoAssetID,
},
Out: &stakeable.LockOut{
Locktime: locktime,
@@ -40,7 +40,7 @@ func debugBalance() {
log.Fatal("FetchState error: ", err)
}
fmt.Printf("NetworkID: %d\n", state.PCTX.NetworkID)
fmt.Printf("XAssetID: %s\n", state.PCTX.XAssetID)
fmt.Printf("UTXOAssetID: %s\n", state.PCTX.UTXOAssetID)
wallet, err := primary.MakeWallet(ctx, &primary.WalletConfig{
URI: uri,
@@ -51,7 +51,7 @@ func debugBalance() {
log.Fatal("MakeWallet error: ", err)
}
luxAssetID := wallet.X().Builder().Context().XAssetID
luxAssetID := wallet.X().Builder().Context().UTXOAssetID
pBal, _ := wallet.P().Builder().GetBalance()
fmt.Printf("P balance: %v\n", pBal)
fmt.Printf("P LUX: %d\n", pBal[luxAssetID])
@@ -131,7 +131,7 @@ func main() {
log.Fatalf("wallet sync failed: %v", err)
}
luxAssetID := fundWallet.X().Builder().Context().XAssetID
luxAssetID := fundWallet.X().Builder().Context().UTXOAssetID
pBalanceMap, err := fundWallet.P().Builder().GetBalance()
if err != nil {
log.Fatalf("P-chain balance check failed: %v", err)
@@ -46,7 +46,7 @@ func main() {
log.Fatalf("failed to get the balance: %s\n", err)
}
luxID := state.PCTX.XAssetID
luxID := state.PCTX.UTXOAssetID
luxBalance := currentBalances[luxID]
log.Printf("current LUX balance of %s is %d nLUX\n", addrStr, luxBalance)
}
@@ -47,7 +47,7 @@ func main() {
log.Fatalf("failed to get the balance: %s\n", err)
}
luxID := state.XCTX.XAssetID
luxID := state.XCTX.UTXOAssetID
luxBalance := currentBalances[luxID]
log.Printf("current LUX balance of %s is %d nLUX\n", addrStr, luxBalance)
}
@@ -53,14 +53,14 @@ func main() {
pWallet := wallet.P()
pBuilder := pWallet.Builder()
pCtx := pBuilder.Context()
xAssetID := pCtx.XAssetID
utxoAssetID := pCtx.UTXOAssetID
// Check balance
balances, err := pBuilder.GetBalance()
if err != nil {
log.Fatalf("failed to get balance: %v", err)
}
luxBalance := balances[xAssetID]
luxBalance := balances[utxoAssetID]
log.Printf("P-chain LUX balance: %d µLUX = %d LUX", luxBalance, luxBalance/constants.Lux)
// Send 1 LUX to self — this forces block production on P-chain
@@ -73,7 +73,7 @@ func main() {
tx, err := pWallet.IssueBaseTx(
[]*lux.TransferableOutput{
{
Asset: lux.Asset{ID: xAssetID},
Asset: lux.Asset{ID: utxoAssetID},
Out: &secp256k1fx.TransferOutput{
Amt: amount,
OutputOwners: secp256k1fx.OutputOwners{