From 771f0cce5115eb036b4b4bb8eb6a928f9afa16e2 Mon Sep 17 00:00:00 2001 From: Olga Klimenko Date: Tue, 5 Sep 2023 17:35:27 +0700 Subject: [PATCH] add fundraising conf --- conf/fundraising.template.conf | 1 + src/Config/Fundraising.purs | 56 +++++++++++++++++++++++++++++++++ src/Protocol/StartProtocol.purs | 8 +++-- ui/index.tsx | 2 +- 4 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 conf/fundraising.template.conf create mode 100644 src/Config/Fundraising.purs diff --git a/conf/fundraising.template.conf b/conf/fundraising.template.conf new file mode 100644 index 0000000..cd2e1ea --- /dev/null +++ b/conf/fundraising.template.conf @@ -0,0 +1 @@ +{"address":"addr_test1xzyyxy9s609346ckm5eyv2qn3s56zc8spajw654yxsrwwkuggvgtp57trt43dhfjgc5p8rpf59s0qrmya4f2gdqxuads6zfmy0", "verTokenCurrency": "2ad1727329f49229089c470bcabc158a2344e149499614dba10cbfac", "verTokenName": "VerificationToken", "threadTokenName":"FundraisingThreadToken"} \ No newline at end of file diff --git a/src/Config/Fundraising.purs b/src/Config/Fundraising.purs new file mode 100644 index 0000000..6b8f748 --- /dev/null +++ b/src/Config/Fundraising.purs @@ -0,0 +1,56 @@ +module Config.Fundraising where + +import Contract.Prelude + +import Contract.Address (Bech32String, addressToBech32, getNetworkId, validatorHashBaseAddress) +import Contract.Monad (Contract, liftContractM) +import Data.Argonaut.Core (stringify) +import Data.Argonaut.Encode (encodeJson) +import Effect (Effect) +import Ext.Contract.Value (currencySymbolToString, tokenNameToString, mkCurrencySymbol) +import Fundraising.FundraisingScript (getFundraisingTokenName, getFundraisingValidatorHash) +import Fundraising.Models (Fundraising(..)) +import MintingPolicy.VerTokenMinting as VerToken +import Node.Encoding (Encoding(..)) +import Node.FS.Sync (writeTextFile) +import Protocol.Models (Protocol) + +type FundraisingConfig = + { address :: Bech32String + , verTokenCurrency :: Bech32String + , verTokenName :: String + , threadTokenName :: String + } + +writeFundraisingConfig :: FundraisingConfig -> Effect Unit +writeFundraisingConfig fundraisingConfig = do + let jfundraisingConfig = stringify $ encodeJson fundraisingConfig + liftEffect $ writeTextFile UTF8 "conf/fundraising.local.conf" jfundraisingConfig + +makeFundraisingConfig ∷ Protocol → Contract FundraisingConfig +makeFundraisingConfig protocol = do + _ /\ verTokenCs <- mkCurrencySymbol (VerToken.mintingPolicy protocol) + let verTokenBech32 = currencySymbolToString verTokenCs + verTn <- VerToken.verTokenName + verTnString <- liftContractM "Impossible to decode fundraising ver token name" $ tokenNameToString verTn + + let + fundraising = Fundraising + { protocol: protocol + , verTokenCurrency: verTokenCs + , verTokenName: verTn + } + networkId <- getNetworkId + frValidatorHash <- getFundraisingValidatorHash fundraising + frAddress <- liftContractM "Impossible to get Fundraising script address" $ validatorHashBaseAddress networkId frValidatorHash + bech32Address <- addressToBech32 frAddress + + nftTn <- getFundraisingTokenName + nftTnString <- liftContractM "Impossible to decode fundraising thread token name" $ tokenNameToString nftTn + + pure $ + { address: bech32Address + , verTokenCurrency: verTokenBech32 + , verTokenName: verTnString + , threadTokenName: nftTnString + } diff --git a/src/Protocol/StartProtocol.purs b/src/Protocol/StartProtocol.purs index 9c855e6..0c797e5 100644 --- a/src/Protocol/StartProtocol.purs +++ b/src/Protocol/StartProtocol.purs @@ -8,8 +8,8 @@ module Protocol.StartProtocol ) where import Contract.Prelude -import Governance.UserData (StartGovernanceData(..)) -import Shared.OwnCredentials (OwnCredentials(..), getOwnCreds) + +import Config.Fundraising (makeFundraisingConfig, writeFundraisingConfig) import Config.Protocol (mapFromProtocolData, writeProtocolConfig) import Contract.Address (addressToBech32, getNetworkId, validatorHashBaseAddress) import Contract.Credential (Credential(..)) @@ -25,6 +25,7 @@ import Ext.Contract.Value (mkCurrencySymbol) import Governance.Config (getGovTokenFromConfig) import Governance.Datum (GovernanceDatum(..)) import Governance.GovernanceScript (getGovernanceValidatorHash, governanceTokenName, governanceValidatorScript) +import Governance.UserData (StartGovernanceData(..)) import MintingPolicy.NftMinting as NFT import MintingPolicy.NftRedeemer (PNftRedeemer(..)) import Protocol.Datum (PProtocolDatum(..)) @@ -33,6 +34,7 @@ import Protocol.ProtocolScript (getProtocolValidatorHash, protocolTokenName, pro import Protocol.UserData (ProtocolConfigParams(..), ProtocolData, dataToProtocol, protocolToData) import Shared.Config (mapFromProtocolConfigParams, writeDonatPoolConfig) import Shared.KeyWalletConfig (testnetKeyWalletConfig) +import Shared.OwnCredentials (OwnCredentials(..), getOwnCreds) import Shared.ScriptRef (mkFundraisingRefScript, mkGovernanceRefScript, mkProposalRefScript, mkProtocolRefScript, mkVerTokenPolicyRef) import Shared.Tx (completeTx) @@ -65,6 +67,8 @@ startSystem params = do mkGovernanceRefScript protocol mkProposalRefScript protocol mkVerTokenPolicyRef protocolData + frConfig <- makeFundraisingConfig protocol + liftEffect $ writeFundraisingConfig frConfig pure protocolData startProtocol :: ProtocolConfigParams -> Contract ProtocolData diff --git a/ui/index.tsx b/ui/index.tsx index 4709fda..5f5198b 100644 --- a/ui/index.tsx +++ b/ui/index.tsx @@ -9,7 +9,7 @@ const root = ReactDOM.createRoot(document.getElementById('root')!); const App = () => { const protocolData = { - protocolCurrency: "3b9cd2a49b3d715052857b736d2d570bfaa86b1ac33c51a615d9d418", + protocolCurrency: "8224a01dacaa1b2010b25a255e80e2953f773c3ac842e61175c7b02e", protocolTokenName: "DonatPoolProtocol" }