Skip to content

Restrict renewing to specific address #2

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

Open
wants to merge 1 commit into
base: main
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
105 changes: 51 additions & 54 deletions backend/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
LIMIT,
STACKS_NETWORK_NAME,
POOL_OPERATOR,
POOL_BTC_ADDRESS,
POX_CONTRACT_ADDRESS,
MAX_CYCLES_FOR_OPERATIONS,
STACKS_NETWORK_INSTANCE,
Expand Down Expand Up @@ -799,16 +800,18 @@ export const checkAvailableTransactions = (
: MAX_CYCLES,
MAX_CYCLES
);
const operation = {
functionName: 'delegate-stack-stx',
stacker: key,
amountUstx: value.amountUstx,
currentBlock,
poxAddress: value.poxAddress,
maxCycles,
};
if (maxCycles > 0) {
availableTransactions.push(operation);
if (value.poxAddress == null || value.poxAddress == POOL_BTC_ADDRESS) {
const operation = {
functionName: 'delegate-stack-stx',
stacker: key,
amountUstx: value.amountUstx,
currentBlock,
poxAddress: value.poxAddress,
maxCycles,
};
if (maxCycles > 0) {
availableTransactions.push(operation);
}
}
}
});
Expand Down Expand Up @@ -839,7 +842,7 @@ export const checkAvailableTransactions = (
const operation = {
functionName: 'delegate-stack-extend',
stacker: key,
poxAddress: delegationList[delegationList.length - 1].poxAddress,
poxAddress: POOL_BTC_ADDRESS,
maxExtendCycles,
};
availableTransactions.push(operation);
Expand All @@ -850,71 +853,65 @@ export const checkAvailableTransactions = (
const operation = {
functionName: 'delegate-stack-increase',
stacker: key,
poxAddress: delegationList[delegationList.length - 1].poxAddress,
poxAddress: POOL_BTC_ADDRESS,
increaseAmount,
};
availableTransactions.push(operation);
}
}
});

const poxAddressSet = new Set(
[...acceptedDelegations.values()].flat().map((d) => d.poxAddress)
);

poxAddressSet.forEach(async (address) => {
const acceptedDelegationsForAddress = [...acceptedDelegations.entries()]
.flatMap(([_, delegations]) => delegations)
.filter((d) => d.poxAddress === address);
const acceptedDelegationsForAddress = [...acceptedDelegations.entries()]
.flatMap(([_, delegations]) => delegations)
.filter((d) => d.poxAddress === POOL_BTC_ADDRESS);

const maxEndCycleList = Math.max(
...acceptedDelegationsForAddress.map((d) => d.endCycle)
);
const maxEndCycle = Math.min(
currentCycle + MAX_CYCLES + 1,
maxEndCycleList
);
const maxEndCycleList = Math.max(
...acceptedDelegationsForAddress.map((d) => d.endCycle)
);
const maxEndCycle = Math.min(
currentCycle + MAX_CYCLES + 1,
maxEndCycleList
);

const startCycleList = Math.min(
...acceptedDelegationsForAddress.map((d) => d.startCycle)
const startCycleList = Math.min(
...acceptedDelegationsForAddress.map((d) => d.startCycle)
);
const startCycle = Math.max(currentCycle + 1, startCycleList);

if (!committedDelegations.has(POOL_BTC_ADDRESS)) {
for (
let rewardCycle = startCycle;
rewardCycle < maxEndCycle;
rewardCycle++
) {
const operation = {
functionName: 'stack-aggregation-commit-indexed',
poxAddress: POOL_BTC_ADDRESS,
rewardCycle,
};
availableTransactions.push(operation);
}
} else {
const committedDelegationsForAddress = committedDelegations.get(POOL_BTC_ADDRESS);
const currentCommittedEndCycle = Math.max(
...committedDelegationsForAddress.map((d: any) => d.endCycle)
);
const startCycle = Math.max(currentCycle + 1, startCycleList);

if (!committedDelegations.has(address)) {
if (currentCommittedEndCycle < maxEndCycle) {
for (
let rewardCycle = startCycle;
let rewardCycle = currentCommittedEndCycle;
rewardCycle < maxEndCycle;
rewardCycle++
) {
const operation = {
functionName: 'stack-aggregation-commit-indexed',
poxAddress: address,
poxAddress: POOL_BTC_ADDRESS,
rewardCycle,
};
availableTransactions.push(operation);
}
} else {
const committedDelegationsForAddress = committedDelegations.get(address);
const currentCommittedEndCycle = Math.max(
...committedDelegationsForAddress.map((d: any) => d.endCycle)
);

if (currentCommittedEndCycle < maxEndCycle) {
for (
let rewardCycle = currentCommittedEndCycle;
rewardCycle < maxEndCycle;
rewardCycle++
) {
const operation = {
functionName: 'stack-aggregation-commit-indexed',
poxAddress: address,
rewardCycle,
};
availableTransactions.push(operation);
}
}
}
});
}

const temporaryMap = new Map();

Expand Down