-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ECO-2489] Add emojicoin arena Move prototype (#408)
Co-authored-by: Matt <90358481+xbtmatt@users.noreply.github.com>
- emojicoin-dot-fun-deployer-v0.0.7
- emojicoin-dot-fun-deployer-v0.0.6
- emojicoin-dot-fun-deployer-v0.0.5
- emojicoin-dot-fun-deployer-v0.0.4
- broker-v6.0.0
- broker-v6.0.0-alpha.3
- broker-v6.0.0-alpha.1
- broker-v6.0.0-alpha
- broker-v5.0.1
- broker-v5.0.0
- broker-v4.0.2
- broker-v4.0.1
- broker-v4.0.0
- broker-v3.0.1
- broker-v3.0.0
- broker-v2.2.0
- broker-v2.1.1
- broker-v2.0.1
- arena-move-v1.0.0-audited
Showing
5 changed files
with
1,106 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[addresses] | ||
arena = "_" | ||
integrator = "_" | ||
|
||
[dependencies.EmojicoinDotFun] | ||
local = "../emojicoin_dot_fun" | ||
|
||
[dev-addresses] | ||
arena = "0xaaa" | ||
coin_factory = "0xbbb" | ||
emojicoin_dot_fun = "0xc0de" | ||
integrator = "0xddd" | ||
|
||
[package] | ||
authors = ["Econia Labs (developers@econialabs.com)"] | ||
name = "EmojicoinArena" | ||
upgrade_policy = "compatible" | ||
version = "1.0.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Emojicoin Arena | ||
|
||
## A note on pseudo-randomness | ||
|
||
Since randomness is not supported in `init_module` per [`aptos-core` #15436], | ||
pseudo-random substitute implementations are used for the first crank. For a | ||
detailed rationale that explains how this is effectively random in practice, see | ||
[this `emojicoin-dot-fun` pull request comment]. | ||
|
||
[this `emojicoin-dot-fun` pull request comment]: https://github.com/econia-labs/emojicoin-dot-fun/pull/408#discussion_r1887856202 | ||
[`aptos-core` #15436]: https://github.com/aptos-labs/aptos-core/issues/15436 |
1,038 changes: 1,038 additions & 0 deletions
1,038
src/move/emojicoin_arena/sources/emojicoin_arena.move
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
module arena::pseudo_randomness { | ||
|
||
use aptos_framework::transaction_context; | ||
use std::bcs; | ||
use std::vector; | ||
|
||
friend arena::emojicoin_arena; | ||
|
||
/// Pseudo-random substitute for `aptos_framework::randomness::u64_range`, since | ||
/// the randomness API is not available during `init_module`. | ||
public(friend) inline fun u64_range(min_incl: u64, max_excl: u64): u64 { | ||
let range = ((max_excl - min_incl) as u256); | ||
let sample = ((u256_integer() % range) as u64); | ||
|
||
min_incl + sample | ||
} | ||
|
||
/// Pseudo-random substitute for `aptos_framework::randomness::next_32_bytes`, since | ||
/// the randomness API is not available during `init_module`. | ||
inline fun next_32_bytes(): vector<u8> { | ||
bcs::to_bytes(&transaction_context::generate_auid_address()) | ||
} | ||
|
||
/// Pseudo-random substitute for `aptos_framework::randomness::u256_integer`, since | ||
/// the randomness API is not available during `init_module`. | ||
inline fun u256_integer(): u256 { | ||
let raw = next_32_bytes(); | ||
let i = 0; | ||
let ret: u256 = 0; | ||
while (i < 32) { | ||
ret = ret * 256 + (vector::pop_back(&mut raw) as u256); | ||
i = i + 1; | ||
}; | ||
ret | ||
} | ||
} |