Skip to content

Commit

Permalink
Add Chang fork and fix ogmios chain context
Browse files Browse the repository at this point in the history
  • Loading branch information
Salvionied committed Aug 24, 2024
1 parent 20c9e7f commit 906cba3
Show file tree
Hide file tree
Showing 8 changed files with 214 additions and 80 deletions.
2 changes: 1 addition & 1 deletion ApolloBuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ func (b *Apollo) estimateFee() int64 {
return 0
}
fakeTxBytes, _ := fftx.Bytes()
estimatedFee := Utils.Fee(b.Context, len(fakeTxBytes), pExU.Steps, pExU.Mem)
estimatedFee := Utils.Fee(b.Context, len(fakeTxBytes), pExU.Steps, pExU.Mem, fftx.TransactionBody.ReferenceInputs)
estimatedFee += b.FeePadding
return estimatedFee

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/Salvionied/cbor/v2 v2.6.0
github.com/SundaeSwap-finance/kugo v0.1.5
github.com/SundaeSwap-finance/ogmigo v0.8.0
github.com/SundaeSwap-finance/ogmigo/v6 v6.0.0-20231101192200-2e052daaeb54
github.com/SundaeSwap-finance/ogmigo/v6 v6.0.0-20240117201106-ce491d0b031e
github.com/tyler-smith/go-bip39 v1.1.0
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1
golang.org/x/text v0.9.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ github.com/SundaeSwap-finance/kugo v0.1.5 h1:udigs4BdhFKNQqV2NW5oAma4Qhhenmh+3/j
github.com/SundaeSwap-finance/kugo v0.1.5/go.mod h1:P3Hn7eqby5AdRmZkclFLLc3EQIIexEaVvfDZD6lcKQ8=
github.com/SundaeSwap-finance/ogmigo v0.8.0 h1:cnta2oCuSwbFe/Wnc93lI+llz77GUrWCUpm+Vfj4HQc=
github.com/SundaeSwap-finance/ogmigo v0.8.0/go.mod h1:Zuywifig7DQb5sEBrXsE44tv7fIm3fa9izKihtaez1I=
github.com/SundaeSwap-finance/ogmigo/v6 v6.0.0-20231101192200-2e052daaeb54 h1:td92+pUFNDK4RwJASl0pLjs2hzqWYPPEMTqAHpBMGRQ=
github.com/SundaeSwap-finance/ogmigo/v6 v6.0.0-20231101192200-2e052daaeb54/go.mod h1:CsDGcgbkKoz6S4h0RJ30go7oXG+KhGE2KLhBpRFnEqA=
github.com/SundaeSwap-finance/ogmigo/v6 v6.0.0-20240117201106-ce491d0b031e h1:wYmyTXTnrYNMZqe3qFs9dJiUYy+yhZrNJFbN49tSjbY=
github.com/SundaeSwap-finance/ogmigo/v6 v6.0.0-20240117201106-ce491d0b031e/go.mod h1:CsDGcgbkKoz6S4h0RJ30go7oXG+KhGE2KLhBpRFnEqA=
github.com/aws/aws-sdk-go v1.44.197 h1:pkg/NZsov9v/CawQWy+qWVzJMIZRQypCtYjUBXFomF8=
github.com/aws/aws-sdk-go v1.44.197/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs=
Expand Down
131 changes: 103 additions & 28 deletions txBuilding/Backend/Base/Base.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,34 +36,38 @@ type GenesisParameters struct {
}

type ProtocolParameters struct {
MinFeeConstant int `json:"min_fee_b"`
MinFeeCoefficient int `json:"min_fee_a"`
MaxBlockSize int `json:"max_block_size"`
MaxTxSize int `json:"max_tx_size"`
MaxBlockHeaderSize int `json:"max_block_header_size"`
KeyDeposits string `json:"key_deposit"`
PoolDeposits string `json:"pool_deposit"`
PooolInfluence float32 `json:"a0"`
MonetaryExpansion float32 `json:"rho"`
TreasuryExpansion float32 `json:"tau"`
DecentralizationParam float32 `json:"decentralisation_param"`
ExtraEntropy string `json:"extra_entropy"`
ProtocolMajorVersion int `json:"protocol_major_ver"`
ProtocolMinorVersion int `json:"protocol_minor_ver"`
MinUtxo string `json:"min_utxo"`
MinPoolCost string `json:"min_pool_cost"`
PriceMem float32 `json:"price_mem"`
PriceStep float32 `json:"price_step"`
MaxTxExMem string `json:"max_tx_ex_mem"`
MaxTxExSteps string `json:"max_tx_ex_steps"`
MaxBlockExMem string `json:"max_block_ex_mem"`
MaxBlockExSteps string `json:"max_block_ex_steps"`
MaxValSize string `json:"max_val_size"`
CollateralPercent int `json:"collateral_percent"`
MaxCollateralInuts int `json:"max_collateral_inputs"`
CoinsPerUtxoWord string `json:"coins_per_utxo_word"`
CoinsPerUtxoByte string `json:"coins_per_utxo_byte"`
//CostModels map[string]map[string]any
MinFeeConstant int `json:"min_fee_b"`
MinFeeCoefficient int `json:"min_fee_a"`
MaxBlockSize int `json:"max_block_size"`
MaxTxSize int `json:"max_tx_size"`
MaxBlockHeaderSize int `json:"max_block_header_size"`
KeyDeposits string `json:"key_deposit"`
PoolDeposits string `json:"pool_deposit"`
PooolInfluence float32 `json:"a0"`
MonetaryExpansion float32 `json:"rho"`
TreasuryExpansion float32 `json:"tau"`
DecentralizationParam float32 `json:"decentralisation_param"`
ExtraEntropy string `json:"extra_entropy"`
ProtocolMajorVersion int `json:"protocol_major_ver"`
ProtocolMinorVersion int `json:"protocol_minor_ver"`
MinUtxo string `json:"min_utxo"`
MinPoolCost string `json:"min_pool_cost"`
PriceMem float32 `json:"price_mem"`
PriceStep float32 `json:"price_step"`
MaxTxExMem string `json:"max_tx_ex_mem"`
MaxTxExSteps string `json:"max_tx_ex_steps"`
MaxBlockExMem string `json:"max_block_ex_mem"`
MaxBlockExSteps string `json:"max_block_ex_steps"`
MaxValSize string `json:"max_val_size"`
CollateralPercent int `json:"collateral_percent"`
MaxCollateralInuts int `json:"max_collateral_inputs"`
CoinsPerUtxoWord string `json:"coins_per_utxo_word"`
CoinsPerUtxoByte string `json:"coins_per_utxo_byte"`
CostModels map[string][]uint64 `json:"cost_models"`
MaximumReferenceScriptsSize int `json:"maximum_reference_scripts_size"`
MinFeeReferenceScriptsRange int `json:"min_fee_reference_scripts_range"`
MinFeeReferenceScriptsBase int `json:"min_fee_reference_scripts_base"`
MinFeeReferenceScriptsMultiplier int `json:"min_fee_reference_scripts_multiplier"`
}

func (p ProtocolParameters) GetCoinsPerUtxoByte() int {
Expand Down Expand Up @@ -294,3 +298,74 @@ func Fee(context ChainContext, length int, exec_steps int, max_mem_unit int) int
int(max_mem_unit*int(protocol_param.PriceMem))

}

type BlockfrostProtocolParams struct {
MinFeeConstant int `json:"min_fee_b"`
MinFeeCoefficient int `json:"min_fee_a"`
MaxBlockSize int `json:"max_block_size"`
MaxTxSize int `json:"max_tx_size"`
MaxBlockHeaderSize int `json:"max_block_header_size"`
KeyDeposits string `json:"key_deposit"`
PoolDeposits string `json:"pool_deposit"`
PooolInfluence float32 `json:"a0"`
MonetaryExpansion float32 `json:"rho"`
TreasuryExpansion float32 `json:"tau"`
DecentralizationParam float32 `json:"decentralisation_param"`
ExtraEntropy string `json:"extra_entropy"`
ProtocolMajorVersion int `json:"protocol_major_ver"`
ProtocolMinorVersion int `json:"protocol_minor_ver"`
MinUtxo string `json:"min_utxo"`
MinPoolCost string `json:"min_pool_cost"`
PriceMem float32 `json:"price_mem"`
PriceStep float32 `json:"price_step"`
MaxTxExMem string `json:"max_tx_ex_mem"`
MaxTxExSteps string `json:"max_tx_ex_steps"`
MaxBlockExMem string `json:"max_block_ex_mem"`
MaxBlockExSteps string `json:"max_block_ex_steps"`
MaxValSize string `json:"max_val_size"`
CollateralPercent int `json:"collateral_percent"`
MaxCollateralInuts int `json:"max_collateral_inputs"`
CoinsPerUtxoWord string `json:"coins_per_utxo_word"`
CoinsPerUtxoByte string `json:"coins_per_utxo_byte"`
//CostModels //map[string][]uint64 `json:"cost_models"`
MaximumReferenceScriptsSize int `json:"maximum_reference_scripts_size"`
MinFeeReferenceScriptsRange int `json:"min_fee_reference_scripts_range"`
MinFeeReferenceScriptsBase int `json:"min_fee_reference_scripts_base"`
MinFeeReferenceScriptsMultiplier int `json:"min_fee_reference_scripts_multiplier"`
}

func (p BlockfrostProtocolParams) ToBaseParams() ProtocolParameters {
return ProtocolParameters{
MinFeeConstant: p.MinFeeConstant,
MinFeeCoefficient: p.MinFeeCoefficient,
MaxBlockSize: p.MaxBlockSize,
MaxTxSize: p.MaxTxSize,
MaxBlockHeaderSize: p.MaxBlockHeaderSize,
KeyDeposits: p.KeyDeposits,
PoolDeposits: p.PoolDeposits,
PooolInfluence: p.PooolInfluence,
MonetaryExpansion: p.MonetaryExpansion,
TreasuryExpansion: p.TreasuryExpansion,
DecentralizationParam: p.DecentralizationParam,
ExtraEntropy: p.ExtraEntropy,
ProtocolMajorVersion: p.ProtocolMajorVersion,
ProtocolMinorVersion: p.ProtocolMinorVersion,
MinUtxo: p.MinUtxo,
MinPoolCost: p.MinPoolCost,
PriceMem: p.PriceMem,
PriceStep: p.PriceStep,
MaxTxExMem: p.MaxTxExMem,
MaxTxExSteps: p.MaxTxExSteps,
MaxBlockExMem: p.MaxBlockExMem,
MaxBlockExSteps: p.MaxBlockExSteps,
MaxValSize: p.MaxValSize,
CollateralPercent: p.CollateralPercent,
MaxCollateralInuts: p.MaxCollateralInuts,
CoinsPerUtxoWord: p.CoinsPerUtxoWord,
CoinsPerUtxoByte: p.CoinsPerUtxoByte,
MaximumReferenceScriptsSize: p.MaximumReferenceScriptsSize,
MinFeeReferenceScriptsRange: p.MinFeeReferenceScriptsRange,
MinFeeReferenceScriptsBase: p.MinFeeReferenceScriptsBase,
MinFeeReferenceScriptsMultiplier: p.MinFeeReferenceScriptsMultiplier,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -198,15 +198,15 @@ func (bfc *BlockFrostChainContext) LatestEpochParams() Base.ProtocolParameters {
log.Fatal(err, "REQUEST PROTOCOL")
}
body, err := ioutil.ReadAll(res.Body)
var response = Base.ProtocolParameters{}
var response = Base.BlockfrostProtocolParams{}
err = json.Unmarshal(body, &response)
if err != nil {
log.Fatal(err, "UNMARSHAL PROTOCOL")
}
Cache.Set("latest_epoch_params", response)
now := time.Now()
Cache.Set("latest_epoch_params_time", now)
return response
return response.ToBaseParams()
} else {
return pm
}
Expand Down
Loading

0 comments on commit 906cba3

Please sign in to comment.