// Package dao_sponsor shows how an authorized DAO executor can sponsor a budget. package dao_sponsor import ( "chain/banker" "chain/runtime/unsafe" "gno.land/r/g1aj9pzthj36aav0kff2zcmx9llapa7ng7xzcfct/shared_budget/maintenance/v4" "gno.land/r/g1aj9pzthj36aav0kff2zcmx9llapa7ng7xzcfct/shared_budget/treasury/v4" ) const lane = "maintenance" var ( realmPath = unsafe.CurrentRealm().PkgPath() // The deployer acts as the governance executor in this example. executor = unsafe.PreviousRealm().Address() ) // CreateAndOpen assembles the budget and funds it from this realm's native balance. // Send coins to the realm's address before calling it. func CreateAndOpen(cur realm, title, policyPath string, coordinator address, reviewersCSV string, quorum int, amount int64) int64 { requireExecutor(cur) id := treasury.CreateProgram(cross(cur), title, "", 0, 100, 1000, 80, 0) treasury.AddPolicy(cross(cur), id, lane, policyPath, amount, amount, false) maintenance.Configure(cross(cur), id, lane, coordinator, reviewersCSV, quorum) funds := banker.NewBanker(banker.BankerTypeRealmSend, cur) treasury.OpenFromBanker(cross(cur), id, funds, amount) return id } // Contribute funds any active native program from this realm's balance. // The executor can deposit coins into this realm in the same call. func Contribute(cur realm, programID, amount int64) { requireExecutor(cur) if cur.Previous().IsUserCall() { // An attachment credits this realm before the banker sends the requested amount. unsafe.OriginSend() } funds := banker.NewBanker(banker.BankerTypeRealmSend, cur) treasury.FundFromBanker(cross(cur), programID, funds, amount) } func RotateCoordinator(cur realm, programID int64, newCoordinator address) { requireExecutor(cur) maintenance.RotateCoordinator(cross(cur), programID, lane, newCoordinator) } func CloseIssuance(cur realm, programID int64) { requireExecutor(cur) treasury.CloseIssuance(cross(cur), programID) } // Withdraw collects an approved claim payable to this realm. // For a sponsor refund, pass lane "refund" and item ID 0 after finalization. func Withdraw(cur realm, programID int64, lane string, itemID int64) { requireExecutor(cur) treasury.Withdraw(cross(cur), programID, lane, itemID) } func requireExecutor(cur realm) { if !cur.IsCurrent() || cur.PkgPath() != realmPath { panic("invalid DAO sponsor context") } if cur.Previous().Address() != executor { panic("only the DAO executor can authorize this action") } }