Skip to content

Commit

Permalink
Merge pull request #59 from dfinity/enable-xdr-based-nf-participation…
Browse files Browse the repository at this point in the history
…-limits

Enable XDR-based participation limits for Neurons' Fund swap participations
  • Loading branch information
anchpop authored Apr 23, 2024
2 parents 45c8d66 + 0a1c689 commit a1e6627
Show file tree
Hide file tree
Showing 12 changed files with 241 additions and 644 deletions.
658 changes: 42 additions & 616 deletions Cargo.lock

Large diffs are not rendered by default.

144 changes: 136 additions & 8 deletions dfx.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,152 @@
{
"canisters": {
"internet_identity": {
"build": "",
"candid": "candid/internet_identity.did",
"type": "custom",
"wasm": ""
},
"nns-cycles-minting": {
"build": "",
"candid": "candid/nns-cycles-minting.did",
"remote": {
"id": {
"ic": "rkp4c-7iaaa-aaaaa-aaaca-cai",
"local": "rkp4c-7iaaa-aaaaa-aaaca-cai"
}
},
"type": "custom",
"wasm": ""
},
"nns-dapp": {
"build": "",
"candid": "candid/nns-dapp.did",
"type": "custom",
"candid": "",
"wasm": "nns-dapp.wasm"
"wasm": ""
},
"internet_identity": {
"nns-genesis-token": {
"build": "",
"candid": "candid/nns-genesis-token.did",
"remote": {
"id": {
"ic": "renrk-eyaaa-aaaaa-aaada-cai",
"local": "renrk-eyaaa-aaaaa-aaada-cai"
}
},
"type": "custom",
"candid": "",
"wasm": "internet_identity_dev.wasm"
"wasm": ""
},
"sns_aggregator": {
"nns-governance": {
"build": "",
"candid": "candid/nns-governance.did",
"remote": {
"id": {
"ic": "rrkah-fqaaa-aaaaa-aaaaq-cai",
"local": "rrkah-fqaaa-aaaaa-aaaaq-cai"
}
},
"type": "custom",
"wasm": ""
},
"nns-ledger": {
"build": "",
"candid": "candid/nns-ledger.did",
"remote": {
"id": {
"ic": "ryjl3-tyaaa-aaaaa-aaaba-cai",
"local": "ryjl3-tyaaa-aaaaa-aaaba-cai"
}
},
"type": "custom",
"wasm": ""
},
"nns-lifeline": {
"build": "",
"candid": "candid/nns-lifeline.did",
"remote": {
"id": {
"ic": "rno2w-sqaaa-aaaaa-aaacq-cai",
"local": "rno2w-sqaaa-aaaaa-aaacq-cai"
}
},
"type": "custom",
"wasm": ""
},
"nns-registry": {
"build": "",
"candid": "candid/nns-registry.did",
"remote": {
"id": {
"ic": "rwlgt-iiaaa-aaaaa-aaaaa-cai",
"local": "rwlgt-iiaaa-aaaaa-aaaaa-cai"
}
},
"type": "custom",
"wasm": ""
},
"nns-root": {
"build": "",
"candid": "candid/nns-root.did",
"remote": {
"id": {
"ic": "r7inp-6aaaa-aaaaa-aaabq-cai",
"local": "r7inp-6aaaa-aaaaa-aaabq-cai"
}
},
"type": "custom",
"wasm": ""
},
"nns-sns-wasm": {
"build": "",
"candid": "candid/nns-sns-wasm.did",
"remote": {
"id": {
"ic": "qaa6y-5yaaa-aaaaa-aaafa-cai",
"local": "qaa6y-5yaaa-aaaaa-aaafa-cai"
}
},
"type": "custom",
"wasm": ""
},
"sns_aggregator": {
"candid": "candid/sns_aggregator.did",
"type": "custom",
"wasm": "sns_aggregator.wasm"
},
"sns_governance": {
"build": "",
"candid": "candid/sns_governance.did",
"type": "custom",
"wasm": ""
},
"sns_index": {
"build": "",
"candid": "candid/sns_index.did",
"type": "custom",
"wasm": ""
},
"sns_ledger": {
"build": "",
"candid": "candid/sns_ledger.did",
"type": "custom",
"wasm": ""
},
"sns_root": {
"build": "",
"candid": "candid/sns_root.did",
"type": "custom",
"wasm": ""
},
"sns_swap": {
"build": "",
"candid": "candid/sns_swap.did",
"type": "custom",
"wasm": ""
},
"test": {
"candid": "candid/test.did",
"type": "rust",
"package": "test"
"package": "test",
"type": "rust"
}
}
}
2 changes: 1 addition & 1 deletion download_release_candidate_wasms.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ ICRC1_ARCHIVE_FILENAME="$PWD/ic-icrc1-archive.wasm.gz"
TMP=$(execute_nns_tools_func get_sns_canister_wasm_gz_for_type archive "$RC_ICRC1_ARCHIVE_GIT_HASH")
mv "$TMP" "$ICRC1_ARCHIVE_FILENAME"

ICRC1_INDEX_FILENAME="$PWD/ic-icrc1-index.wasm.gz"
ICRC1_INDEX_FILENAME="$PWD/ic-icrc1-index-ng.wasm.gz"
TMP=$(execute_nns_tools_func get_sns_canister_wasm_gz_for_type index "$RC_ICRC1_INDEX_GIT_HASH")
mv "$TMP" "$ICRC1_INDEX_FILENAME"
2 changes: 1 addition & 1 deletion install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fi
gzip -fd sns.gz
chmod +x sns

curl --fail -L "https://github.com/dfinity/sdk/releases/download/0.14.2/dfx-0.14.2-x86_64-${OS}.tar.gz" -o dfx.tar.gz
curl --fail -L "https://github.com/dfinity/sdk/releases/download/0.19.0/dfx-0.19.0-x86_64-${OS}.tar.gz" -o dfx.tar.gz
tar -xzf dfx.tar.gz
rm dfx.tar.gz
chmod +x dfx
Expand Down
15 changes: 11 additions & 4 deletions run_basic_scenario.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ set -euo pipefail

cd -- "$(dirname -- "${BASH_SOURCE[0]}")"

# Set the ICP/XDR conversion rate (needed for the NNS Governance and the Neurons' Fund).
./set-icp-xdr-rate.sh 10000

# Deploy test canister
./deploy_test_canister.sh

# assert the default greeting text
# assert that we can interact with the test canister by querying the default greeting text
[ "$(./bin/dfx canister call test greet "M")" == '("Hoi, M!")' ] && echo "OK" || exit 1

# Add NNS Root as a co-controller of the dapp canisters to be decentralized.
Expand All @@ -24,12 +27,13 @@ jq -r '.root_canister_id' -e sns_canister_ids.json
jq -r '.swap_canister_id' -e sns_canister_ids.json

# Assert the SNS swap lifecycle is in the OPEN state.
[ "$(./get_sns_swap_state.sh | sed "s/0 : float32/0 : nat64/" | ./bin/idl2json | jq -r '.swap[0].lifecycle')" == "2" ] && echo "OK" || exit 1
[ "$(./get_sns_swap_state.sh | ./bin/idl2json | jq -r '.swap[0].lifecycle')" == "2" ] && echo "OK" || exit 1

# Assert that the test canister is indeed registered.
[ "$(./get_sns_canisters.sh | ./bin/idl2json | jq -r '.dapps[0]')" == "$(./bin/dfx canister id test)" ] && echo "OK" || exit 1

# Upgrade test canister (I)
# TODO: Make sure the following commands work. Currently, we get "The replica returned a replica error: Replica Error: reject code CanisterError, reject message Canister be2us-64aaa-aaaaa-qaabq-cai violated contract: Error getting performance counter type 1, error code None"
./upgrade_test_canister.sh Hello
./wait_for_last_sns_proposal.sh
./wait_for_canister_running.sh "$(./bin/dfx canister id test)"
Expand All @@ -42,10 +46,13 @@ jq -r '.swap_canister_id' -e sns_canister_ids.json

# Wait for the SNS swap lifecycle is in the COMPLETED state.
# This happens when the heartbeat of the SNS Swap canister is executed.
while [ "$(./get_sns_swap_state.sh | sed "s/0 : float32/0 : nat64/" | ./bin/idl2json | jq -r '.swap[0].lifecycle')" != "3" ]; do sleep 1; done
while [ "$(./get_sns_swap_state.sh | ./bin/idl2json | jq -r '.swap[0].lifecycle')" != "3" ]; do sleep 1; done

# Upgrade test canister (II)
./upgrade_test_canister.sh Welcome
# We expect that the canister has not been changed yet as we have now decentralized
# so we don't hold the majority of the voting power.
[ "$(./bin/dfx canister call test greet "M")" == '("Hello, M!")' ] && echo "OK" || exit 1

# Collect votes by the SNS developer neuron submitting the upgrade proposal and total number of votes.
YES="$(./get_last_sns_proposal.sh | ./bin/idl2json | jq -r '.proposals[0].latest_tally[0].yes')"
Expand All @@ -56,7 +63,7 @@ TOTAL="$(./get_last_sns_proposal.sh | ./bin/idl2json | jq -r '.proposals[0].late

# Vote on upgrade canister SNS proposal
./vote_on_sns_proposal.sh \
51 `# Simulate this number of SNS users' votes` \
61 `# Simulate this number of SNS users' votes. TODO: determine the smallest possible value that will work here` \
2 `# Proposal ID` \
y `# Vote to adopt this proposal`
./wait_for_last_sns_proposal.sh
Expand Down
9 changes: 9 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[toolchain]
channel = "1.77.2"
targets = [
"wasm32-unknown-unknown",
"x86_64-unknown-linux-gnu",
"x86_64-apple-darwin",
"x86_64-pc-windows-gnu",
]
profile = "default"
18 changes: 18 additions & 0 deletions set-icp-xdr-rate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash

set -euo pipefail

cd -- "$(dirname -- "${BASH_SOURCE[0]}")"

. ./constants.sh normal

export XDR_PERMYRIAD_PER_ICP="${1:-106292}"

echo "Setting ICP/XDR conversion rate to ${XDR_PERMYRIAD_PER_ICP} ..."

ic-admin \
--nns-url "${NETWORK_URL}" \
propose-xdr-icp-conversion-rate \
--xdr-permyriad-per-icp "${XDR_PERMYRIAD_PER_ICP}" \
--test-neuron-proposer \
--summary "Set ICP/XDR conversion rate to ${XDR_PERMYRIAD_PER_ICP}"
2 changes: 1 addition & 1 deletion settings.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ export NNS_DAPP_RELEASE="nightly-2023-10-30"
# $ ./gitlab-ci/src/artifacts/newest_sha_with_disk_image.sh origin/master
# from the IC monorepo: https://github.com/dfinity/ic
# if you change IC_COMMIT, then you need to rerun `source install.sh`
export IC_COMMIT="d1315a1b9b002f177526faa5ee6d7e1e1aa3a22a"
export IC_COMMIT="fda260e972c03a580be1119d6c2868e30171be02"

export TESTNET="local"
6 changes: 5 additions & 1 deletion setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,18 @@ then
. ./download_release_candidate_wasms.sh "${CANDIDATE}"
else
echo "Downloading WASMs at specified IC_COMMIT."
for canister in sns-root-canister "sns-governance-canister${CANISTER_TEST}" sns-swap-canister ic-icrc1-ledger ic-icrc1-archive ic-icrc1-index
for canister in sns-root-canister "sns-governance-canister${CANISTER_TEST}" sns-swap-canister ic-icrc1-ledger ic-icrc1-archive ic-icrc1-index-ng
do
curl -L "https://download.dfinity.systems/ic/${IC_COMMIT}/canisters/${canister}.wasm.gz" -o "${canister}.wasm.gz"
done

mv "./ic-icrc1-index-ng.wasm.gz" "ic-icrc1-index.wasm.gz"

if [ ! -z "${CANISTER_TEST}" ]
then
mv "./sns-governance-canister${CANISTER_TEST}.wasm.gz" ./sns-governance-canister.wasm.gz
fi

SNS_ROOT_CANISTER_FILENAME="./sns-root-canister.wasm.gz"
SNS_GOVERNANCE_CANISTER_FILENAME="./sns-governance-canister.wasm.gz"
SNS_SWAP_CANISTER_FILENAME="./sns-swap-canister.wasm.gz"
Expand Down
10 changes: 7 additions & 3 deletions setup_locally.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,24 @@ cd -- "$(dirname -- "${BASH_SOURCE[0]}")"

. ./constants.sh normal

for canister in cycles-minting-canister genesis-token-canister governance-canister governance-canister_test ic-ckbtc-minter identity-canister ledger-canister_notify-method lifeline_canister nns-ui-canister registry-canister root-canister sns-wasm-canister sns-root-canister "sns-governance-canister${CANISTER_TEST}" sns-swap-canister ic-icrc1-ledger ic-icrc1-archive ic-icrc1-index
for canister in cycles-minting-canister genesis-token-canister governance-canister governance-canister_test ic-ckbtc-minter identity-canister ledger-canister_notify-method lifeline_canister nns-ui-canister registry-canister root-canister sns-wasm-canister sns-root-canister "sns-governance-canister${CANISTER_TEST}" sns-swap-canister ic-icrc1-ledger ic-icrc1-archive ic-icrc1-index-ng
do
curl -L "https://download.dfinity.systems/ic/${IC_COMMIT}/canisters/${canister}.wasm.gz" -o "${canister}.wasm.gz"
gzip -d "${canister}.wasm.gz"
done

mv "./ic-icrc1-index-ng.wasm" "ic-icrc1-index.wasm"

if [ ! -z "${CANISTER_TEST}" ]
then
mv "./sns-governance-canister${CANISTER_TEST}.wasm" ./sns-governance-canister.wasm
fi

# Soon (after DFX 0.15.x is supported by the needed extensions) we would need to call these
# two commands:
# ${DFX} extension install nns
# ${DFX} extension install sns
# TODO: look into installing these extensions locally so we can ensure we get a particular version
${DFX} extension install nns || true
${DFX} extension install sns || true

${DFX} nns import
${DFX} sns import
Expand Down
5 changes: 2 additions & 3 deletions test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ edition = "2021"
crate-type = ["cdylib"]

[dependencies]
candid = "0.8.2"
ic-cdk = "0.6.0"
ic-cdk-macros = "0.6.0"
candid = "0.10.7"
ic-cdk = "0.13.2"
serde = "1"
wee_alloc = "0.4.3"
lazy_static = "1.4.0"
14 changes: 8 additions & 6 deletions test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ fn init_impl(x: Option<InitArgs>) {
}
}

#[ic_cdk_macros::init]
#[ic_cdk::init]
fn init(x: Option<InitArgs>) {
init_impl(x);
}

#[ic_cdk_macros::post_upgrade]
#[ic_cdk::post_upgrade]
fn post_upgrade(x: Option<InitArgs>) {
init_impl(x);
}

#[ic_cdk_macros::update]
#[ic_cdk::update]
fn validate(x: String) -> Result<String, String> {
if x.is_empty() {
Err("empty".to_string())
Expand All @@ -49,7 +49,7 @@ fn validate(x: String) -> Result<String, String> {
}
}

#[ic_cdk_macros::update]
#[ic_cdk::update]
fn execute(x: String) {
let gov = GOVERNANCE.with(|g| *g.borrow());
match gov {
Expand All @@ -65,12 +65,14 @@ fn execute(x: String) {
}
}

#[ic_cdk_macros::update]
#[ic_cdk::update]
fn get() -> u64 {
CTR.with(|c| *c.borrow_mut())
}

#[ic_cdk_macros::update]
#[ic_cdk::update]
fn greet(name: String) -> String {
format!("{}, {}!", STR.with(|s| (*s.borrow_mut()).clone()), name)
}

ic_cdk::export_candid!();

0 comments on commit a1e6627

Please sign in to comment.