Skip to content

Commit

Permalink
add fundraising conf
Browse files Browse the repository at this point in the history
  • Loading branch information
olgaklimenko committed Sep 5, 2023
1 parent 9280d62 commit 771f0cc
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 3 deletions.
1 change: 1 addition & 0 deletions conf/fundraising.template.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"address":"addr_test1xzyyxy9s609346ckm5eyv2qn3s56zc8spajw654yxsrwwkuggvgtp57trt43dhfjgc5p8rpf59s0qrmya4f2gdqxuads6zfmy0", "verTokenCurrency": "2ad1727329f49229089c470bcabc158a2344e149499614dba10cbfac", "verTokenName": "VerificationToken", "threadTokenName":"FundraisingThreadToken"}
56 changes: 56 additions & 0 deletions src/Config/Fundraising.purs
Original file line number Diff line number Diff line change
@@ -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
}
8 changes: 6 additions & 2 deletions src/Protocol/StartProtocol.purs
Original file line number Diff line number Diff line change
Expand Up @@ -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(..))
Expand All @@ -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(..))
Expand All @@ -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)

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ui/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const root = ReactDOM.createRoot(document.getElementById('root')!);
const App = () => {

const protocolData = {
protocolCurrency: "3b9cd2a49b3d715052857b736d2d570bfaa86b1ac33c51a615d9d418",
protocolCurrency: "8224a01dacaa1b2010b25a255e80e2953f773c3ac842e61175c7b02e",
protocolTokenName: "DonatPoolProtocol"
}

Expand Down

0 comments on commit 771f0cc

Please sign in to comment.