Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use proportional stx amount #26

Open
wants to merge 1 commit into
base: feat/ccip-016-calculation
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 51 additions & 3 deletions src/dao/ccip016-summary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,27 @@ import {
PostConditionFungible,
} from "@stacks/stacks-blockchain-api-types";
import { readFile } from "fs/promises";
import { MissedPayouts, PayoutData } from "./ccip016-calculation";
import { callReadOnlyFunction } from "micro-stacks/api";
import { OptionalCV, TupleCV, UIntCV, uintCV } from "micro-stacks/clarity";
import { StacksMainnet } from "micro-stacks/network";
import { hiroApiBase, MissedPayouts, PayoutData } from "./ccip016-calculation";

const network = new StacksMainnet({ url: hiroApiBase });

async function fetchStackingStats(cycle: number, cityId: number) {
const result = (await callReadOnlyFunction({
contractAddress: "SP8A9HZ3PKST0S42VM9523Z9NV42SZ026V4K39WH",
contractName: "ccd007-citycoin-stacking",
functionName: "get-stacking-stats",
functionArgs: [uintCV(cityId), uintCV(cycle)],
senderAddress: "SP8A9HZ3PKST0S42VM9523Z9NV42SZ026V4K39WH",
network: network,
})) as TupleCV<{
reward: OptionalCV<UIntCV>;
total: UIntCV;
}>;
return Number(result.data.total.value);
}

async function main() {
// read missed payouts from file
Expand All @@ -14,16 +34,39 @@ async function main() {
(content) => JSON.parse(content.toString())
)) as PayoutData;

let contractCodeMia = "";
let contractCodeNyc = "";
let totalMia = 0;
let totalNyc = 0;
for (let cycle of Object.keys(missedPayouts)) {
const cycleNumber = Number(cycle);

const miaTotalCC = await fetchStackingStats(cycleNumber, 1);
const nycTotalCC = await fetchStackingStats(cycleNumber, 2);

const toUser = (tx: ContractCallTransaction) => {
const user: { user?: string; cc?: number; stx?: number } = {};
const user: {
user?: string;
cc?: number;
stx?: number;
} = {};
const ccAmount = (tx.post_conditions[0] as PostConditionFungible).amount;
user.user = tx.sender_address;
user.cc = Number(ccAmount);
const payoutStxAmount = payoutData[cycleNumber].miaPayoutAmount!;
user.stx = payoutStxAmount;
const arg0 = tx.contract_call?.function_args?.[0]?.repr;
console.log(arg0);
const isMia = arg0 === '"mia"';
const totalCC = isMia ? miaTotalCC : nycTotalCC;
user.stx = Math.floor((payoutStxAmount * user.cc) / totalCC);
contractCodeMia += isMia
? `(pay-rewards '${user.user} ${user.stx})\n`
: "";
contractCodeNyc += isMia
? ""
: `(pay-rewards '${user.user} ${user.stx})\n`;
totalMia += isMia ? user.stx || 0 : 0;
totalNyc += isMia ? 0 : user.stx || 0;
return user;
};

Expand All @@ -33,6 +76,11 @@ async function main() {
console.log(cycle, "mia", affectedAddressesMia);
console.log(cycle, "nyc", affectedAddressesNyc);
}
console.log({ totalMia, totalNyc });
console.log("Contract code for MIA");
console.log(contractCodeMia);
console.log("Contract code for NYC");
console.log(contractCodeNyc);
}

main();