Skip to content

Commit

Permalink
fix: add permission to stack for stx rewards treasury
Browse files Browse the repository at this point in the history
  • Loading branch information
friedger committed Jul 21, 2024
1 parent f0987f5 commit 5e04323
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 40 deletions.
9 changes: 5 additions & 4 deletions contracts/proposals/ccip019-pox-4-stacking.clar
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,10 @@
;; transfer funds to new treasury extensions
(try! (contract-call? .ccd002-treasury-mia-mining-v2 withdraw-stx miaBalance .ccd002-treasury-mia-mining-v3))

;; delegate stack the STX in the mining treasuries (up to 50M STX each)
;; delegate stack the STX in the mining and rewards treasuries (up to 50M STX each)
;; MAINNET: SP21YTSM60CAY6D011EZVEVNKXVW8FVZE198XEFFP.pox4-fast-pool-v3
(try! (contract-call? .ccd002-treasury-mia-mining-v3 delegate-stx u50000000000000 'SP21YTSM60CAY6D011EZVEVNKXVW8FVZE198XEFFP.pox4-fast-pool-v3))
(try! (contract-call? .ccd002-treasury-mia-stx-stacking-v3 delegate-stx u50000000000000 'SP21YTSM60CAY6D011EZVEVNKXVW8FVZE198XEFFP.pox4-fast-pool-v3))

;; add treasuries to ccd005-city-data
(try! (contract-call? .ccd005-city-data add-treasury miaId .ccd002-treasury-mia-mining-v3 "mining-v3"))
Expand Down Expand Up @@ -129,7 +130,7 @@
(miaVoteAmount (scale-down (default-to u0 (get-mia-vote voterId true))))
)
;; check that the user has a positive vote
(asserts! (or (> miaVoteAmount u0)) ERR_NOTHING_STACKED)
(asserts! (> miaVoteAmount u0) ERR_NOTHING_STACKED)
;; insert new user vote record
(asserts! (map-insert UserVotes voterId {
vote: vote,
Expand Down Expand Up @@ -225,12 +226,12 @@
;; MAINNET: mia cycle 82 / first block BTC 838,250 STX 145,643
;; cycle 2 / u4500 used in tests
(cycle82Hash (unwrap! (get-block-hash u145643) none))
(cycle82Data (at-block cycle82Hash (contract-call? .ccd007-citycoin-stacking get-stacker MIA_ID u2 userId)))
(cycle82Data (at-block cycle82Hash (contract-call? .ccd007-citycoin-stacking get-stacker MIA_ID u82 userId)))
(cycle82Amount (get stacked cycle82Data))
;; MAINNET: mia cycle 83 / first block BTC 840,350 STX 147,282
;; cycle 3 / u6600 used in tests
(cycle83Hash (unwrap! (get-block-hash u147282) none))
(cycle83Data (at-block cycle83Hash (contract-call? .ccd007-citycoin-stacking get-stacker MIA_ID u3 userId)))
(cycle83Data (at-block cycle83Hash (contract-call? .ccd007-citycoin-stacking get-stacker MIA_ID u83 userId)))
(cycle83Amount (get stacked cycle83Data))
;; mia vote calculation
(scaledVote (/ (+ (scale-up cycle82Amount) (scale-up cycle83Amount)) u2))
Expand Down
76 changes: 40 additions & 36 deletions simulations/stxer-ccip019.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { StacksMainnet } from "@stacks/network";
import { AnchorMode, PostConditionMode, StacksTransaction, boolCV, bufferCV, contractPrincipalCV, listCV, makeUnsignedContractCall, makeUnsignedContractDeploy, principalCV, serializeCV, stringAsciiCV, tupleCV, uintCV } from "@stacks/transactions";
import { AnchorMode, PostConditionMode, SignedTokenTransferOptions, StacksTransaction, boolCV, bufferCV, contractPrincipalCV, listCV, makeSTXTokenTransfer, makeUnsignedContractCall, makeUnsignedContractDeploy, makeUnsignedSTXTokenTransfer, principalCV, serializeCV, stringAsciiCV, tupleCV, uintCV } from "@stacks/transactions";
import { c32addressDecode } from "c32check";
import fs from "fs";

Expand Down Expand Up @@ -48,9 +48,23 @@ async function vote(address: string, nonce: number) {
return voteTx1;
}

async function directExecute(address: string, nonce: number) {
const [, addressHash] = c32addressDecode(address);
const voteTx1 = await makeUnsignedContractCall({
contractAddress: "SP8A9HZ3PKST0S42VM9523Z9NV42SZ026V4K39WH",
contractName: "ccd001-direct-execute",
functionName: "direct-execute",
functionArgs: [principalCV("SP8A9HZ3PKST0S42VM9523Z9NV42SZ026V4K39WH.ccip019-pox-4-stacking")],
nonce: nonce++,
...common_params,
});
voteTx1.auth.spendingCondition.signer = addressHash;
return voteTx1;
}

async function main() {
const block_height = 156894;
const block_hash = "390579d10ed73f98ef829e0068d014d32a6a128e3ba0b80c42321010c61fff1a";
const block_height = 157894;
const block_hash = "5e584e604a8caffc476be973562f4ad05231cecb70f3ede3af110986dffee4cf";

// DO NOT sign any transactions you're about to send, this is not required for simulation
let address = "SP8A9HZ3PKST0S42VM9523Z9NV42SZ026V4K39WH";
Expand Down Expand Up @@ -84,53 +98,43 @@ async function main() {

const voteTxs: StacksTransaction[] = [];

voteTxs.push(await vote("SP18Z92ZT0GAB2JHD21CZ3KS1WPGNDJCYZS7CV3MD", 524));
voteTxs.push(await vote("SP34N5WWPHWTVJVYPE368HYDEXMZWKPVF639B3P5T", 978));
voteTxs.push(await vote("SP1T91N2Y2TE5M937FE3R6DE0HGWD85SGCV50T95A", 243));
voteTxs.push(await vote("SP18Z92ZT0GAB2JHD21CZ3KS1WPGNDJCYZS7CV3MD", 529));
voteTxs.push(await vote("SP34N5WWPHWTVJVYPE368HYDEXMZWKPVF639B3P5T", 982));
voteTxs.push(await vote("SP1T91N2Y2TE5M937FE3R6DE0HGWD85SGCV50T95A", 245));

address = "SP7DGES13508FHRWS1FB0J3SZA326FP6QRMB6JDE";
[, addressHash] = c32addressDecode(address);
nonce = 120;
const tx1 = await makeUnsignedContractCall({
contractAddress: "SP8A9HZ3PKST0S42VM9523Z9NV42SZ026V4K39WH",
contractName: "ccd001-direct-execute",
functionName: "direct-execute",
functionArgs: [principalCV("SP8A9HZ3PKST0S42VM9523Z9NV42SZ026V4K39WH.ccip019-pox-4-stacking")],
nonce: nonce++,
...common_params,
});
tx1.auth.spendingCondition.signer = addressHash;
const executeTxs: StacksTransaction[] = [];
executeTxs.push(await directExecute("SP7DGES13508FHRWS1FB0J3SZA326FP6QRMB6JDE", 122));
executeTxs.push(await directExecute("SP3YYGCGX1B62CYAH4QX7PQE63YXG7RDTXD8BQHJQ", 17));
executeTxs.push(await directExecute("SPN4Y5QPGQA8882ZXW90ADC2DHYXMSTN8VAR8C3X", 803));

address = "SP3YYGCGX1B62CYAH4QX7PQE63YXG7RDTXD8BQHJQ";
[, addressHash] = c32addressDecode(address);
nonce = 17;
const tx2 = await makeUnsignedContractCall({
contractAddress: "SP8A9HZ3PKST0S42VM9523Z9NV42SZ026V4K39WH",
contractName: "ccd001-direct-execute",
functionName: "direct-execute",
functionArgs: [principalCV("SP8A9HZ3PKST0S42VM9523Z9NV42SZ026V4K39WH.ccip019-pox-4-stacking")],
address = "SPN4Y5QPGQA8882ZXW90ADC2DHYXMSTN8VAR8C3X";
nonce = 804;
const transferStxTx = await makeUnsignedSTXTokenTransfer({
amount: 10000000,
recipient: "SP8A9HZ3PKST0S42VM9523Z9NV42SZ026V4K39WH.ccd002-treasury-mia-stx-stacking-v3",
nonce: nonce++,
...common_params,
});
tx2.auth.spendingCondition.signer = addressHash;
[, addressHash] = c32addressDecode(address);
transferStxTx.auth.spendingCondition.signer = addressHash;

address = "SPN4Y5QPGQA8882ZXW90ADC2DHYXMSTN8VAR8C3X";
[, addressHash] = c32addressDecode(address);
nonce = 802;
const tx3 = await makeUnsignedContractCall({
contractAddress: "SP8A9HZ3PKST0S42VM9523Z9NV42SZ026V4K39WH",
contractName: "ccd001-direct-execute",
functionName: "direct-execute",
functionArgs: [principalCV("SP8A9HZ3PKST0S42VM9523Z9NV42SZ026V4K39WH.ccip019-pox-4-stacking")],
nonce = 805;
const lockStxTx = await makeUnsignedContractCall({
contractAddress: "SP21YTSM60CAY6D011EZVEVNKXVW8FVZE198XEFFP",
contractName: "pox4-fast-pool-v3",
functionName: "delegate-stack-stx-many",
functionArgs: [listCV([principalCV("SP8A9HZ3PKST0S42VM9523Z9NV42SZ026V4K39WH.ccd002-treasury-mia-mining-v3"), principalCV("SP8A9HZ3PKST0S42VM9523Z9NV42SZ026V4K39WH.ccd002-treasury-mia-stx-stacking-v3")])],
nonce: nonce++,
...common_params,
});
tx3.auth.spendingCondition.signer = addressHash;
[, addressHash] = c32addressDecode(address);
lockStxTx.auth.spendingCondition.signer = addressHash;

const req = tupleCV({
block_height: uintCV(block_height),
block_hash: bufferCV(Buffer.from(block_hash, "hex")),
steps: listCV([deployTx1, deployTx2, deployTx3, ...voteTxs, tx1, tx2, tx3].map((t) => runTx(t))),
steps: listCV([deployTx1, deployTx2, deployTx3, ...voteTxs, ...executeTxs, transferStxTx, lockStxTx].map((t) => runTx(t))),
});
const body = serializeCV(req);
const rs: any = await fetch(SIMULATION_API_ENDPOINT, {
Expand Down

0 comments on commit 5e04323

Please sign in to comment.