📢 Gate Square #Creator Campaign Phase 1# is now live – support the launch of the PUMP token sale!
The viral Solana-based project Pump.Fun ($PUMP) is now live on Gate for public sale!
Join the Gate Square Creator Campaign, unleash your content power, and earn rewards!
📅 Campaign Period: July 11, 18:00 – July 15, 22:00 (UTC+8)
🎁 Total Prize Pool: $500 token rewards
✅ Event 1: Create & Post – Win Content Rewards
📅 Timeframe: July 12, 22:00 – July 15, 22:00 (UTC+8)
📌 How to Join:
Post original content about the PUMP project on Gate Square:
Minimum 100 words
Include hashtags: #Creator Campaign
In-depth analysis of the Sputnik DAO platform factory contract: design implementation and security mechanisms
Rust Smart Contracts Development Diary (10-2): Sputnik DAO Factory Contract Analysis
This article will provide an in-depth interpretation of the design and implementation of the Sputnik DAO platform factory model (sputnikdao-factory).
1. Sputnik-DAO Factory Contract
Sputnik-DAO adopts a creation-based factory design pattern to achieve the unified creation and management of the decentralized autonomous organization (DAO) on the platform.
The source code repository for the corresponding contract is located at:
2. Introduction to DAPP Module Functions
The DAPP page of the Sputnik DAO platform displays the created DAO instance object (Sputnikdaov2 contract ). As of March 2022, the most active DAO on the platform is news.sputnik-dao.near, with 3051 proposals either voting or completed.
All DAO instance contracts created on the Sputnik DAO platform are uniformly deployed under its sub-accounts by the sputnik-dao.near account ( and the sputnikdao-factory contract ), for example:
Organizations can publicly call the create() method of the sputnikdao-factory smart contract in the NEAR mainnet to create new DAO instances.
3. Interpretation of sputnikdao-factory Contract Code
3.1 Create DAO
The contract status of sputnikdao-factory mainly consists of two parts:
rust pub struct SputnikDAOFactory { factory_manager: FactoryManager, daos: UnorderedSet, }
create() method definition:
rust #[payable] pub fn create(&mut self, name: AccountId, args: Base64VecU8) { let account_id: AccountId = format!('{}.{}', name, env::current_account_id()) .parse() .unwrap(); let callback_args = serde_json::to_vec(\u0026json!({ 'account_id': account_id, 'attached_deposit': U128(env::attached_deposit()), 'predecessor_account_id': env::predecessor_account_id() })) .expect('Failed to serialize'); self.factory_manager.create_contract( self.get_default_code_hash(), account_id, 'new', &args.0, 'on_create', &callback_args, ); }
The specific implementation of factory_manager.create_contract:
rust pub fn create_contract( &self, code_hash: Base58CryptoHash, account_id: AccountId, new_method: &str, args: [u8], callback_method: &str, callback_args: &[u8], ) { // Load contract code // Create Promise // Create Account // Transfer // Deploy contract
// Call the initialization function // Set Callback }
on_create callback function:
rust #[private] pub fn on_create( &mut self, account_id: AccountId, attached_deposit: U128, predecessor_account_id: AccountId, bool { if near_sdk::is_promise_success)( { self.daos.insert)\u0026account_id(; true } else { Promise::new)predecessor_account_id(.transfer)attached_deposit.0(; false } }
![])https://img-cdn.gateio.im/webp-social/moments-8b462e3ac0fd55e990921d21d66e3d42.webp(
) 3.2 Update DAO
update###( method:
rust pub fn update)&self, account_id: AccountId, code_hash: Base58CryptoHash( { let caller_id = env::predecessor_account_id)(; assert!) caller_id == self.get_owner(( || caller_id == account_id, 'Must be updated by the factory owner or the DAO itself' ); assert!) self.daos.contains(&account_id(, 'Must be contract created by factory' ); self.factory_manager .update_contract)account_id, code_hash, 'update'(; }
![])https://img-cdn.gateio.im/webp-social/moments-a8d69d504693c5c14767aed9244a090a.webp(
4. Sputnik-DAO Factory Contract Security Analysis
Mainly ensure security from the following aspects:
![])https://img-cdn.gateio.im/webp-social/moments-729b65b1335931b4645ff5a9981d125b.webp(
![])https://img-cdn.gateio.im/webp-social/moments-074c1aa0b7f9adfa5780a29c73654fc0.webp(
![])https://img-cdn.gateio.im/webp-social/moments-aebf6315f45abba98b7345259ffe8b5d.webp(
![])https://img-cdn.gateio.im/webp-social/moments-a3a84d139b8950498848a5cafbdfea83.webp(
![])https://img-cdn.gateio.im/webp-social/moments-46f1a89001b11b13b1a8d1b484d4877d.webp(