-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
77 additions
and
9 deletions.
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 |
---|---|---|
@@ -1,7 +1,18 @@ | ||
|
||
.PHONY: clean | ||
|
||
WASM_SRC := target/wasm32-unknown-unknown/release/shahmeersgame.wasm | ||
|
||
shahmeersgame.wasm: $(shell find src -type f) | ||
@forge build | ||
@rm -f ${WASM_SRC} shahmeersgame.wasm | ||
@cargo build \ | ||
--release \ | ||
--target wasm32-unknown-unknown | ||
@mv target/wasm32-unknown-unknown/release/shahmeersgame.wasm . | ||
@mv ${WASM_SRC} . | ||
|
||
clean: | ||
@rm -rf \ | ||
mutants.out.old \ | ||
mutants.out \ | ||
target |
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,8 @@ | ||
#!/bin/sh -e | ||
|
||
export \ | ||
SPN_DILUTION_CONCEPT_AMT=100000000 \ | ||
SPN_DILUTION_SUBMITTER_AMT=10000000 \ | ||
SPN_SHAHMEERSGAME_TOKEN_ADDR=0xFDab24861F407765E6E64c282420585ef7cf68fe | ||
|
||
./deploy.sh |
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 |
---|---|---|
@@ -1,4 +1,27 @@ | ||
#!/bin/sh | ||
#!/bin/sh -e | ||
|
||
impl="$(./deploy-stylus.sh shahmeersgame.wasm)" | ||
err() { | ||
>&2 echo $@ | ||
exit 1 | ||
} | ||
|
||
[ -z "$SPN_ADMIN_ADDR" ] && err "SPN_ADMIN_ADDR unset" | ||
[ -z "$SPN_DILUTION_CONCEPT_AMT" ] && err "SPN_DILUTION_CONCEPT_AMT unset" | ||
[ -z "$SPN_DILUTION_SUBMITTER_AMT" ] && err "SPN_DILUTION_SUBMITTER_AMT unset" | ||
[ -z "$SPN_SHAHMEERSGAME_TOKEN_ADDR" ] && err "SPN_SHAHMEERSGAME_TOKEN_ADDR unset" | ||
|
||
if [ -z "$SPN_SHAHMEERSGAME_IMPL" ]; then | ||
export SPN_SHAHMEERSGAME_IMPL="$(./deploy-stylus.sh shahmeersgame.wasm)" | ||
fi | ||
|
||
[ -z "$SPN_SHAHMEERSGAME_IMPL" ] && exit 1 | ||
|
||
echo "SPN_SHAHMEERSGAME_IMPL=$SPN_SHAHMEERSGAME_IMPL" | ||
|
||
forge create \ | ||
--broadcast \ | ||
--rpc-url "$SPN_SUPERPOSITION_URL" \ | ||
--private-key "$SPN_SUPERPOSITION_KEY" \ | ||
foundry-libs/openzeppelin-contracts/contracts/proxy/transparent/TransparentUpgradeableProxy.sol:TransparentUpgradeableProxy \ | ||
--constructor-args "$impl" "$SPN_ADMIN_ADDR" "$SPN_SHAHMEERSGAME_IMPL" "$(cast calldata 'ctor(address,address,uint256,uint256)' "$SPN_SHAHMEERSGAME_TOKEN_ADDR" "$SPN_ADMIN_ADDR" "$SPN_DILUTION_CONCEPT_AMT" "$SPN_DILUTION_SUBMITTER_AMT")" \ | ||
| jq -r .deployedTo |
Submodule openzeppelin-contracts
deleted from
acd4ff
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,3 @@ | ||
[toolchain] | ||
channel = "1.81" | ||
components = [ "rust-src" ] |
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 |
---|---|---|
@@ -1,9 +1,34 @@ | ||
|
||
use stylus_sdk::alloy_primitives::U256; | ||
|
||
pub const SCALING_AMT: U256 = U256::from_limbs([1000, 0, 0, 0]); | ||
|
||
/// Compute the quadratic voting power of a STG amount. | ||
/// Compute the quadratic voting power of a STG amount using the Babylonian method. | ||
pub fn stg_to_quad(x: U256) -> U256 { | ||
x.root(2) | ||
// Since the Alloy implementation uses some floating point conversions | ||
// the Stylus runtime doesn't have. Rounds down. | ||
if x.is_zero() { | ||
return U256::ZERO; | ||
} | ||
let mut z = (x >> 1) + U256::from(1); | ||
let mut y = x; | ||
while z < y { | ||
y = z; | ||
z = (x / z + z) >> 1; | ||
} | ||
if y * y > x { | ||
y -= U256::from(1); | ||
} | ||
y | ||
} | ||
|
||
#[cfg(not(target_arch = "wasm32"))] | ||
mod test { | ||
use proptest::prelude::*; | ||
|
||
proptest! { | ||
#[test] | ||
fn test_stg_to_quad(x in crate::storage::strat_tiny_u256()) { | ||
assert_eq!(x.root(2), super::stg_to_quad(x)); | ||
} | ||
} | ||
} |