Smart Contract

WonderlandRewardAlgorithm

A.35f9e7ac86111b22.WonderlandRewardAlgorithm

Deployed

1d ago
Feb 26, 2026, 09:43:59 PM UTC

Dependents

0 imports
1import RewardAlgorithm from 0x35f9e7ac86111b22
2
3access(all)
4contract WonderlandRewardAlgorithm: RewardAlgorithm{ 
5	
6	// -----------------------------------------------------------------------
7	// Events
8	// -----------------------------------------------------------------------
9	access(all)
10	event ContractInitialized()
11	
12	// -----------------------------------------------------------------------
13	// Paths
14	// -----------------------------------------------------------------------
15	access(all)
16	let AlgorithmStoragePath: StoragePath
17	
18	access(all)
19	let AlgorithmPublicPath: PublicPath
20	
21	access(all)
22	resource Algorithm: RewardAlgorithm.Algorithm{ 
23		access(all)
24		fun randomAlgorithm(): Int{ 
25			// Generate a random number between 0 and 100_000_000
26			let randomNum = Int(revertibleRandom<UInt64>() % 100_000_000)
27			let threshold1 = 69_000_000 // for 69%
28			
29			let threshold2 = 87_000_000 // for 18%, cumulative 87%
30			
31			let threshold3 = 95_000_000 // for 8%, cumulative 95%
32			
33			let threshold4 = 99_000_000 // for 4%, cumulative 99%
34			
35			
36			// Return reward based on generated random number
37			if randomNum < threshold1{ 
38				return 1
39			} else if randomNum < threshold2{ 
40				return 2
41			} else if randomNum < threshold3{ 
42				return 3
43			} else if randomNum < threshold4{ 
44				return 4
45			} else{ 
46				return 5
47			} // for remaining 1%
48		
49		}
50	}
51	
52	access(all)
53	fun createAlgorithm(): @Algorithm{ 
54		return <-create WonderlandRewardAlgorithm.Algorithm()
55	}
56	
57	access(all)
58	fun borrowAlgorithm(): &Algorithm{ 
59		return self.account.capabilities.get<&WonderlandRewardAlgorithm.Algorithm>(self.AlgorithmPublicPath).borrow()!
60	}
61	
62	init(){ 
63		self.AlgorithmStoragePath = /storage/WonderlandRewardAlgorithm_2
64		self.AlgorithmPublicPath = /public/WonderlandRewardAlgorithm_2
65		self.account.storage.save(<-self.createAlgorithm(), to: self.AlgorithmStoragePath)
66		var capability_1 = self.account.capabilities.storage.issue<&WonderlandRewardAlgorithm.Algorithm>(self.AlgorithmStoragePath)
67		self.account.capabilities.publish(capability_1, at: self.AlgorithmPublicPath)
68		emit ContractInitialized()
69	}
70}
71