Skip to content

Commit

Permalink
Validate parts of the deployment story
Browse files Browse the repository at this point in the history
  • Loading branch information
af-afk committed Sep 11, 2024
1 parent 6b740f3 commit 190a532
Show file tree
Hide file tree
Showing 20 changed files with 358 additions and 45 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ array-concat = "0.5.3"
sha3-const = "0.1.1"

[dev-dependencies]
const-hex = { version = "1.12.0", features = ["alloc"] }
proptest = "1.5.0"
const-hex = { version = "1.12.0", features = ["alloc"] }

[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
alloy-primitives = { version = "0.7.6", features = ["getrandom"] }
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ CARGO_BUILD_STYLUS := \
--artifact-dir . \
--features

.PHONY: build clean
.PHONY: build clean docs

OUT_SHARE := out/Share.sol/Share.json

Expand Down
2 changes: 1 addition & 1 deletion deploy-erc20-impl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
forge create Share \
--json \
--rpc-url="$SPN_SUPERPOSITION_URL" \
--private-key="$SPN_SUPERPOSITION_KEY" \
--private-key="$SPN_DEPLOYER_KEY" \
$@ \
| jq -r .deployedTo
9 changes: 9 additions & 0 deletions deploy-stylus.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh -eu

wasm_file="$1"

cargo stylus deploy \
--endpoint $SPN_SUPERPOSITION_URL \
--wasm-file "$wasm_file" \
--private-key $SPN_SUPERPOSITION_KEY \
| sed -nr 's/.*deployed code at address: +.*(0x.{40}).*$/\1/p'
10 changes: 7 additions & 3 deletions deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@ err() {
exit 1
}

[ -z "$SPN_TRADING_IMPL" ] && err "SPN_TRADING_IMPL not set"
[ -z "$SPN_FACTORY_IMPL" ] && err "SPN_FACTORY_IMPL not set"

# To get these implementation addresses known beforehand (and they
# should be compiled into the contract), you should estimate nonces.

# Deploy the ERC20 implementation...

export SPN_ERC20_IMPL="${SPN_ERC20_IMPL:-$(./deploy-erc20-impl.sh)}"

echo "export SPN_ERC20_IMPL=$SPN_ERC20_IMPL" >&2

# Deploy the Trading implemenation...

# Deploy the factory
forge script --broadcast --json scripts/DeployFactoryTransparentProxy.s.sol
2 changes: 1 addition & 1 deletion docs/src/src/IEvents.sol/interface.IEvents.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# IEvents
[Git Source](https://github.com/fluidity-money/9lives.so/blob/a70b8a6a3d94c40f265a10336f5593b66550e4ec/src/IEvents.sol)
[Git Source](https://github.com/fluidity-money/9lives.so/blob/a3e3525c308d1ecd85b41202701e1c53b0057200/src/IEvents.sol)


## Events
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# INineLivesTrading
[Git Source](https://github.com/fluidity-money/9lives.so/blob/a70b8a6a3d94c40f265a10336f5593b66550e4ec/src/INineLivesTrading.sol)
[Git Source](https://github.com/fluidity-money/9lives.so/blob/a3e3525c308d1ecd85b41202701e1c53b0057200/src/INineLivesTrading.sol)


## Functions
Expand Down Expand Up @@ -43,3 +43,58 @@ function mintPermit(bytes8 outcome, uint256 value, uint256 deadline, address rec
|`s`|`bytes32`|to use for permit.|


### decide

decide an outcome. Only callable by the oracle!


```solidity
function decide(bytes8 outcome) external;
```
**Parameters**

|Name|Type|Description|
|----|----|-----------|
|`outcome`|`bytes8`|to set as the winner.|


### payoff

collect the payoff if holding winning shares!


```solidity
function payoff(bytes8 outcomeId, address recipient) external returns (uint256);
```
**Parameters**

|Name|Type|Description|
|----|----|-----------|
|`outcomeId`|`bytes8`|to collect the payoff for.|
|`recipient`|`address`|to send the winnings to.|


### details

details that're available for this outcome.


```solidity
function details(bytes8 outcomeId) external view returns (uint256 shares, uint256 invested, bool isWinner);
```
**Parameters**

|Name|Type|Description|
|----|----|-----------|
|`outcomeId`|`bytes8`|to get the details for|


### invested

invested amount of fusdc in the betting pool


```solidity
function invested() external view returns (uint256);
```

2 changes: 1 addition & 1 deletion docs/src/src/Share.sol/contract.Share.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Share
[Git Source](https://github.com/fluidity-money/9lives.so/blob/a70b8a6a3d94c40f265a10336f5593b66550e4ec/src/Share.sol)
[Git Source](https://github.com/fluidity-money/9lives.so/blob/a3e3525c308d1ecd85b41202701e1c53b0057200/src/Share.sol)

**Inherits:**
Initializable, ERC20Upgradeable, OwnableUpgradeable, ERC20PermitUpgradeable
Expand Down
12 changes: 12 additions & 0 deletions scripts/DeployFactoryTransparentProxy.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;

import {Script, console} from "forge-std/Script.sol";

//import "@openzeppelin/contracts/token/ERC20/ERC20Upgradeable.sol";

contract DeployFactoryTransparentProxy is Script {
function run() public {
console.log("hello");
}
}
12 changes: 12 additions & 0 deletions scripts/get-deployment-addresses.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh -eu

get_nonce() {
curl \
-H 'Content-Type: application/json' \
-sd "{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"eth_getTransactionCount\",\"params\":[\"$SPN_DEPLOYER_ADDR\", \"latest\"]}" "$SPN_SUPERPOSITION_URL" \
| jq -r .result
}

cur_nonce="$(printf "%d\n" $(get_nonce))"

echo $((cur_nonce+1))
2 changes: 2 additions & 0 deletions src/IEvents.sol
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;

interface IEvents {
event NewTrading(
Expand Down
28 changes: 28 additions & 0 deletions src/INineLivesTrading.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,32 @@ interface INineLivesTrading {
bytes32 r,
bytes32 s
) external returns (uint256);

/**
* @notice decide an outcome. Only callable by the oracle!
* @param outcome to set as the winner.
*/
function decide(bytes8 outcome) external;

/**
* @notice collect the payoff if holding winning shares!
* @param outcomeId to collect the payoff for.
* @param recipient to send the winnings to.
*/
function payoff(bytes8 outcomeId, address recipient) external returns (uint256);

/**
* @notice details that're available for this outcome.
* @param outcomeId to get the details for
*/
function details(bytes8 outcomeId) external view returns (
uint256 shares,
uint256 invested,
bool isWinner
);

/**
* @notice invested amount of fusdc in the betting pool
*/
function invested() external view returns (uint256);
}
16 changes: 12 additions & 4 deletions src/Share.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,30 @@ import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20PermitUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts/utils/Strings.sol";

contract Share is
Initializable,
ERC20Upgradeable,
OwnableUpgradeable,
ERC20PermitUpgradeable
{
/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
_disableInitializers();
}

function ctor(bytes8 identifier, address admin) initializer public {
__ERC20_init("Shares", "");
string memory name = string.concat(
"9lives Share #",
Strings.toString(uint256(uint64(identifier)))
);
string memory symbol = string.concat(
"9#",
Strings.toString(uint256(uint64(identifier)))
);
__ERC20_init(name, symbol);
__Ownable_init(admin);
__ERC20Permit_init("Shares");
__ERC20Permit_init(name);
}

function mint(address to, uint256 amount) public onlyOwner {
Expand All @@ -31,4 +39,4 @@ contract Share is
function burn(address owner, uint256 value) public onlyOwner {
_burn(owner, value);
}
}
}
30 changes: 22 additions & 8 deletions src/erc20_cd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,15 @@ fn test_transfer() {

use const_hex;

let b = const_hex::encode(&pack_transfer(
address!("6221a9c005f6e47eb398fd867784cacfdcfff4e7"),
U256::from(123),
));

assert_eq!(
&pack_transfer(
address!("6221a9c005f6e47eb398fd867784cacfdcfff4e7"),
U256::from(123)
),
//cast calldata 'transfer(address,uint256)' `{bayge} 123
"a9059cbb0000000000000000000000006221a9c005f6e47eb398fd867784cacfdcfff4e7000000000000000000000000000000000000000000000000000000000000007b"
b,
//cast calldata 'transfer(address,uint256)' `{bayge} 123
"a9059cbb0000000000000000000000006221a9c005f6e47eb398fd867784cacfdcfff4e7000000000000000000000000000000000000000000000000000000000000007b"
);
}

Expand Down Expand Up @@ -109,10 +111,22 @@ fn test_pack_permit() {
let b = const_hex::encode(&pack_permit(
address!("6221a9c005f6e47eb398fd867784cacfdcfff4e7"),
address!("feb6034fc7df27df18a3a6bad5fb94c0d3dcb6d5"),
U256::from(100),
U256::from(123),
U256::from(456),
9,
FixedBytes::from_slice(&[
0x1c, 0x8a, 0xff, 0x95, 0x06, 0x85, 0xc2, 0xed, 0x4b, 0xc3, 0x17, 0x4f, 0x34, 0x72,
0x28, 0x7b, 0x56, 0xd9, 0x51, 0x7b, 0x9c, 0x94, 0x81, 0x27, 0x31, 0x9a, 0x09, 0xa7,
0xa3, 0x6d, 0xea, 0xc8,
]),
FixedBytes::from_slice(&[
0x84, 0x52, 0xc9, 0xb9, 0x14, 0x02, 0x22, 0xb0, 0x85, 0x93, 0xa2, 0x6d, 0xaa, 0x78,
0x27, 0x07, 0x29, 0x7b, 0xe9, 0xf7, 0xb3, 0xe8, 0x28, 0x1d, 0x7b, 0x49, 0x74, 0x76,
0x9f, 0x19, 0xaf, 0xd0,
]),
));
assert_eq!(
b,
"0xd505accf0000000000000000000000006221a9c005f6e47eb398fd867784cacfdcfff4e7000000000000000000000000feb6034fc7df27df18a3a6bad5fb94c0d3dcb6d5000000000000000000000000000000000000000000000000000000000000007b00000000000000000000000000000000000000000000000000000000000001c800000000000000000000000000000000000000000000000000000000000000091c8aff950685c2ed4bc3174f3472287b56d9517b9c948127319a09a7a36deac88452c9b9140222b08593a26daa782707297be9f7b3e8281d7b4974769f19afd0"
"d505accf0000000000000000000000006221a9c005f6e47eb398fd867784cacfdcfff4e7000000000000000000000000feb6034fc7df27df18a3a6bad5fb94c0d3dcb6d5000000000000000000000000000000000000000000000000000000000000007b00000000000000000000000000000000000000000000000000000000000001c800000000000000000000000000000000000000000000000000000000000000091c8aff950685c2ed4bc3174f3472287b56d9517b9c948127319a09a7a36deac88452c9b9140222b08593a26daa782707297be9f7b3e8281d7b4974769f19afd0"
);
}
9 changes: 6 additions & 3 deletions src/factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@

use stylus_sdk::{
alloy_primitives::{aliases::*, *},
msg,
contract, msg,
prelude::*,
storage::*,
contract
};

use crate::{error::*, immutables::*, longtail_call, proxy, share_call, trading_call};
Expand Down Expand Up @@ -101,7 +100,11 @@ impl Factory {
);
// Start to derive the outcomes that were given to find the share addresses.
for outcome_id in outcomes {
longtail_call::pause_pool(proxy::get_share_addr(contract::address(), outcome_id))?;
longtail_call::pause_pool(proxy::get_share_addr(
contract::address(),
msg::sender(),
outcome_id,
))?;
}
Ok(())
}
Expand Down
13 changes: 9 additions & 4 deletions src/immutables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,16 @@ pub const LONGTAIL_TICK_SPACING: u8 = 10;

pub const LONGTAIL_MAX_LIQ_PER_TICK: u128 = u128::MAX;

#[test]
#[ignore]
fn print_deployment_bytecode() {
use const_hex::encode;
dbg!(encode(PROXY_BYTECODE), encode(erc20_proxy_code()), encode(trading_proxy_code()));
}

#[test]
#[ignore]
fn print_proxy_hashes() {
dbg!(
const_hex::encode(erc20_proxy_hash()),
const_hex::encode(trading_proxy_hash())
);
use const_hex::encode;
dbg!(encode(erc20_proxy_hash()), encode(trading_proxy_hash()));
}
Loading

0 comments on commit 190a532

Please sign in to comment.