Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
8d434e2
update: front end mainnet
BowTiedRadone Dec 22, 2023
3aab491
added: stacking mainnet contract
BowTiedDeployer Dec 22, 2023
537999e
update: stacking contract address
BowTiedRadone Dec 22, 2023
12f4893
Merge branch 'prod-stacking-mainnet' of https://github.com/degen-lab/…
BowTiedRadone Dec 22, 2023
ad85589
stacking: updated front-end & mainnet contract
BowTiedSirJonathan Jan 28, 2024
947ec0a
integration testing increase 1 time scenarios working
BowTiedBlox Mar 12, 2024
c91012e
prettier format code
BowTiedBlox Mar 15, 2024
10431ef
feat: convert address to hashbytes and version
BowTiedBlox Mar 15, 2024
c506240
Disallow multiple delegate same cycle
bowtiedbot Mar 15, 2024
543141a
feat: started updating delegate related fe
BowTiedBlox Mar 15, 2024
867d10c
can delegated pop up added
BowTiedBlox Mar 16, 2024
c4b0fa5
updated testnet SC
BowTiedBlox Mar 17, 2024
3e38d15
updated SC mainnet
BowTiedBlox Mar 17, 2024
57a5c41
updated sc stacking mainnet
BowTiedBlox Mar 18, 2024
866ffbe
uncomment readOnly canDelegate
BowTiedBlox Mar 18, 2024
e1260d9
update stacking to old mainnet SC
BowTiedBlox Mar 18, 2024
9266331
Stacking: SC update and FE
BowTiedBlox Mar 21, 2024
1df8704
updated 'how to use' info
BowTiedBlox Mar 21, 2024
a117d76
update stacking: post-condition withdraw
BowTiedBlox Mar 25, 2024
ab746be
transition unit tests to clarinet-sdk
BowTiedBlox May 9, 2024
881ea73
Start transitioning stacking-pool-test to pox-4
bowtiedbot May 9, 2024
cd00142
Update unit tests to expect new SC return
bowtiedbot May 9, 2024
d4ff237
Make aggregation function public, add signature example and aggregati…
bowtiedbot May 9, 2024
079d50a
update devnet clarinet for pox-4
BowTiedBlox May 9, 2024
e748dde
overall structure
BowTiedBlox May 11, 2024
d2d4e3c
add pox addr as config, fixed typo sc readonly
BowTiedBlox May 11, 2024
aba4fa4
finalized backend automation beta, next step: testing
BowTiedBlox May 12, 2024
f540875
update to loggs and localData.json
BowTiedBlox May 12, 2024
14cc444
reward distribution testing
BowTiedBlox May 13, 2024
c409ec2
migrate to integration testing the check block won flow
BowTiedBlox May 14, 2024
b8e4523
nakamoto integration fe and be
BowTiedBlox May 18, 2024
575120c
add signer private key
BowTiedBlox May 18, 2024
84c481b
backend not working broadcast
BowTiedBlox May 23, 2024
9260ba8
working contract call
BowTiedBlox May 27, 2024
14345ef
add: can delegate again
BowTiedBlox May 27, 2024
203fc8e
add sc calls handling and logging
BowTiedBlox May 27, 2024
15be6e8
update data backend
BowTiedBlox May 31, 2024
971094b
working backend automation (only left to be checked distribute rewards)
BowTiedBlox May 31, 2024
03b76c1
working prepare and reward phases (without distribution)
BowTiedBlox Jun 1, 2024
95a782b
fix: sc check blocks not claims
BowTiedBlox Jun 3, 2024
2153d5d
backend: full operational
BowTiedBlox Jun 3, 2024
69e72a8
stacking-pool pox-4 mainnet
BowTiedBlox Jun 3, 2024
8e6754b
backend: limit fee spent per transactions
BowTiedBlox Jun 3, 2024
67b24bc
update backend & deploy frontend
BowTiedBlox Jun 10, 2024
34d1d03
add debug
BowTiedBlox Jun 10, 2024
340076f
update api frontend
BowTiedBlox Jun 10, 2024
0fe57b3
update prod api frontend
BowTiedBlox Jun 10, 2024
36e0357
update returns
BowTiedBlox Jun 10, 2024
ff3fa99
update progress automation stacking pool
BowTiedBlox Jun 18, 2024
dbb0cec
add api key to bypass api rate limit
BowTiedBlox Jun 18, 2024
3db09a6
update bitcoin rewards amount displayed
BowTiedBlox Jun 25, 2024
69b6b33
add nonce, move events separately
BowTiedBlox Jul 1, 2024
7ab4c2f
remove console log
BowTiedBlox Jul 1, 2024
3b5dd21
updated cycle values and fix errors folder
BowTiedBlox Aug 18, 2024
6df9a95
updated formula
BowTiedBlox Sep 27, 2024
54ae7c4
update logs latest cycles
BowTiedBlox Dec 1, 2024
fcd0a50
move rewarding backend to subfolder
BowTiedBlox Dec 1, 2024
272dbe0
migrate backend for stacking operations
BowTiedBlox Dec 1, 2024
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.DS_Store
/get-btc-address
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"prettier.configPath": "back-end/.prettierrc"
}
18 changes: 18 additions & 0 deletions back-end/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
### run path

0. add deployer as signer

1. client
a. allow and join
b. delegate
2. server
a. run server npm and see it performs alright the data
b. mine block and see rewards getting distributed

### Flows checked nakamoto testnet

- [x] update balance
- [x] commit agg
- [x] increase agg
- [x] delegate stack stx many
- [ ] distribute rewards
1 change: 1 addition & 0 deletions back-end/errors/2024-08-24T20:44:09.664Z.log
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Error calling read-only function. Response 503: Service Unavailable. Attempted to fetch https://api.mainnet.hiro.so/v2/contracts/call-read/SP1SCEXE6PMGPAC6B4N5P2MDKX8V4GF9QDE1FNNGJ/degenlab-stacking-pool-pox4/get-pox-addr-indices and failed with the message: "upstream connect error or disconnect/reset before headers. reset reason: connection timeout"
1 change: 1 addition & 0 deletions back-end/errors/2024-09-02T06:40:00.996Z.log
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Error calling read-only function. Response 503: Service Unavailable. Attempted to fetch https://api.mainnet.hiro.so/v2/contracts/call-read/SP000000000000000000002Q6VF78/pox-4/get-partial-stacked-by-cycle and failed with the message: "upstream connect error or disconnect/reset before headers. reset reason: connection termination"
1 change: 1 addition & 0 deletions back-end/errors/2024-09-19T17:54:10.093Z.log
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fetch failed
1 change: 1 addition & 0 deletions back-end/errors/2024-10-07T04:42:00.648Z.log
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Unexpected token u in JSON at position 0
1 change: 1 addition & 0 deletions back-end/errors/2024-10-08T10:08:10.028Z.log
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fetch failed
1 change: 1 addition & 0 deletions back-end/errors/2024-11-03T10:00:02.018Z.log
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Error calling read-only function. Response 503: Service Unavailable. Attempted to fetch https://api.mainnet.hiro.so/v2/contracts/call-read/SP000000000000000000002Q6VF78/pox-4/get-pox-info and failed with the message: "upstream connect error or disconnect/reset before headers. reset reason: connection termination"
1 change: 1 addition & 0 deletions back-end/errors/2024-11-11T15:00:00.676Z.log
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Error calling read-only function. Response 503: Service Unavailable. Attempted to fetch https://api.mainnet.hiro.so/v2/contracts/call-read/SP000000000000000000002Q6VF78/pox-4/get-pox-info and failed with the message: "upstream connect error or disconnect/reset before headers. reset reason: connection termination"
1 change: 1 addition & 0 deletions back-end/errors/2024-11-13T05:22:01.313Z.log
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Error calling read-only function. Response 503: Service Unavailable. Attempted to fetch https://api.mainnet.hiro.so/v2/contracts/call-read/SP000000000000000000002Q6VF78/pox-4/get-pox-info and failed with the message: "upstream connect error or disconnect/reset before headers. reset reason: connection termination"
1 change: 1 addition & 0 deletions back-end/errors/2024-11-13T12:32:01.159Z.log
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Error calling read-only function. Response 503: Service Unavailable. Attempted to fetch https://api.mainnet.hiro.so/v2/contracts/call-read/SP000000000000000000002Q6VF78/pox-4/get-partial-stacked-by-cycle and failed with the message: "upstream connect error or disconnect/reset before headers. reset reason: connection termination"
1 change: 1 addition & 0 deletions back-end/errors/2024-11-25T11:00:01.656Z.log
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Error calling read-only function. Response 503: Service Unavailable. Attempted to fetch https://api.mainnet.hiro.so/v2/contracts/call-read/SP000000000000000000002Q6VF78/pox-4/get-pox-info and failed with the message: "upstream connect error or disconnect/reset before headers. reset reason: connection termination"
208 changes: 208 additions & 0 deletions back-end/events.log

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions back-end/localData.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"current_burn_block_height": 872797,
"current_cycle": 98,
"updated_balances_this_cycle": false,
"update_balances_txid": "",
"update_balances_burn_block_height": 871750,
"commit_agg_this_cycle": true,
"commit_agg_burn_block_height": 871851,
"commit_agg_txid": "8839e3d72a3ea7f24679fed97822f318ff762d44b089a166d8ffd68110f3f93d",
"increase_agg_burn_block_height": 861353,
"partial_stacked": 0,
"distribute_rewards_first_burn_block_height_to_check": 872579,
"delegated_stack_stx_many_this_cycle": false,
"delegated_stack_stx_many_txid": "",
"nonce_to_use": 296
}
91,445 changes: 91,445 additions & 0 deletions back-end/log-automation.log

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions back-end/rewarding/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# mainnet/testnet/devnet
NETWORK=devnet
# local/prod
DEVELOPMENT=local
API_KEY_LOCAL_MAINNET=https://api.mainnet.hiro.so
API_KEY_LOCAL_TESTNET=https://api.testnet.hiro.so
API_KEY_PROD_MAINNET=https://api.mainnet.hiro.so
API_KEY_PROD_TESTNET=https://api.testnet.hiro.so
API_KEY_DEVNET=http://localhost:3999

# my private key
PRIVATE_KEY=something
STX_SIGNER_PRIVATE_KEY=something
3 changes: 3 additions & 0 deletions back-end/rewarding/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
.env
.DS_Store
5 changes: 5 additions & 0 deletions back-end/rewarding/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"tabWidth": 2,
"useTabs": false,
"singleQuote": true
}
16 changes: 16 additions & 0 deletions back-end/rewarding/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"skipFiles": ["<node_internals>/**"],
"program": "${workspaceFolder}/index.ts",
"outFiles": ["${workspaceFolder}/**/*.js"]
}
]
}
4 changes: 4 additions & 0 deletions back-end/rewarding/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"prettier.configPath": ".prettierrc",
"editor.formatOnSave": true
}
54 changes: 54 additions & 0 deletions back-end/rewarding/apiPox.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { apiMapping, stxAddress } from './network';

export const getApiPoxData = async () => {
return await fetch(apiMapping.stackingInfo).then((x) => x.json());
};

export const getNonceData = async () => {
return await fetch(apiMapping.nonce(stxAddress)).then((x) =>
x.json().then((x) => Number(x.possible_next_nonce)),
);
};

export const getCurrentBurnchainBlockHeight = (poxData: any): number => {
return poxData.current_burnchain_block_height;
};

export const isInPreparePhase = (poxData: any): boolean => {
return poxData.next_cycle.blocks_until_prepare_phase <= 0;
};

export const getCurrentCycle = (poxData: any): number => {
return poxData.current_cycle.id;
};

/// to be used for triggering maybe-agg-commit on given moments
export const getBlocksUntilPreparePhase = (poxData: any): number => {
return poxData.next_cycle.blocks_until_prepare_phase;
};

export const getRewardPhaseBlockLength = (poxData: any): number => {
return poxData.reward_phase_block_length;
};

export const getCheckCanDelegateAgainNow = (poxData: any): boolean => {
// bigger than first half of the cycle, not in prepare phase
const cycleLength: number =
poxData.prepare_phase_block_length + poxData.reward_phase_block_length;
const rewardPhaseFirstBlock: number =
poxData.next_cycle.reward_phase_start_block_height - cycleLength;
const isInPreparePhase: boolean =
poxData.next_cycle.blocks_until_prepare_phase < 0;
return (
poxData.current_burnchain_block_height >
rewardPhaseFirstBlock + cycleLength / 2 && !isInPreparePhase
);
};

/// TEST
// const jsonDataTest = await getApiPoxData();
// console.log(
// 'current burnchain block height',
// getCurrentBurnchainBlockHeight(jsonDataTest),
// );
// console.log('is in prepare phase', isInPreparePhase(jsonDataTest));
55 changes: 55 additions & 0 deletions back-end/rewarding/consts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
export const maxAmount = 9000000000000000;

export const blockSpanAggIncrease = {
mainnet: 300,
testnet: 100,
nakamotoTestnet: 100,
devnet: 3,
};

export const blockSpanRewardDistribute = {
mainnet: 300,
testnet: 200,
nakamotoTestnet: 200,
devnet: 3,
};

export const offsetRewardDistribute = {
mainnet: 10,
testnet: 10,
nakamotoTestnet: 10,
devnet: 4,
};

export const offsetIncreaseUpdateBalances = {
mainnet: 10,
testnet: 10,
nakamotoTestnet: 10,
devnet: 1,
};

export const triggerNumberOfLastXBlocksBeforeRewardPhase = {
mainnet: 10,
testnet: 10,
nakamotoTestnet: 10,
devnet: 5,
};

export const feeContractCall = {
updateBalances: 1,
updateBalancesIncreasedFee: 2,
};

export const thresholdAmounPartialStackedByCycle = {
mainnet: 10,
testnet: 10,
nakamotoTestnet: 10,
devnet: 1,
};

export const limitPerReadOnly = {
mainnet: 12,
testnet: 12,
nakamotoTestnet: 12,
devnet: 6,
};
131 changes: 131 additions & 0 deletions back-end/rewarding/contracts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import { Cl, getAddressFromPrivateKey } from '@stacks/transactions';
import { NetworkType, privateKey } from './network';
import { poxAddressToTuple } from '@stacks/stacking';

type NetworkTypeMiningAndStacking = Record<
NetworkType,
{
contractAddress: string;
contractName: string;
owner: string;
}
>;
type ContractTypes = 'stacking' | 'pox';
type ContractMapping = Record<ContractTypes, NetworkTypeMiningAndStacking>;

export const contractMapping: ContractMapping = {
// TODO: complete the rest
stacking: {
mainnet: {
contractAddress: 'SP1SCEXE6PMGPAC6B4N5P2MDKX8V4GF9QDE1FNNGJ',
contractName: 'degenlab-stacking-pool-pox4',
owner: 'SP1SCEXE6PMGPAC6B4N5P2MDKX8V4GF9QDE1FNNGJ',
},
testnet: {
contractAddress: '',
contractName: '',
owner: '',
},
devnet: {
contractAddress: 'ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM',
contractName: 'stacking-pool-test',
owner: 'ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM',
},
nakamotoTestnet: {
contractAddress: 'ST2D033K08AW2TPRTCFP3QD5VHZB7494TY0QXERJ1',
contractName: 'stacking-pool-v1',
owner: 'ST2D033K08AW2TPRTCFP3QD5VHZB7494TY0QXERJ1',
},
},
pox: {
mainnet: {
contractAddress: 'SP000000000000000000002Q6VF78',
contractName: 'pox-4',
owner: 'SP000000000000000000002Q6VF78',
},
testnet: {
contractAddress: 'ST000000000000000000002AMW42H',
contractName: 'pox-4',
owner: 'ST000000000000000000002AMW42H',
},
devnet: {
contractAddress: 'ST000000000000000000002AMW42H',
contractName: 'pox-4',
owner: 'ST000000000000000000002AMW42H',
},
nakamotoTestnet: {
contractAddress: 'ST000000000000000000002AMW42H',
contractName: 'pox-4',
owner: 'ST000000000000000000002AMW42H',
},
},
};

interface IFunctionMapping {
stacking: {
readOnlyFunctions: {
updatedBalancesGivenCycle: string;
checkWonBlockRewardsBatch: string;
checkClaimedBlocksRewardsBatch: string;
// calculateExtraReservedFunds: string;
// canWithdrawExtraReservedNow: string;
isPreparePhaseNow: string;
getPoxAddrIndices: string;
getStackersList: string;
};
publicFunctions: {
updateSCBalances: string;
maybeStackAggregationCommit: string;
batchRewardDistribution: string;
delegateStackStxMany: string;
// TODO: increase amount stacked when given threshold is met
// unlockExtraReservedFunds: string; // if worthy, unlock extra amount
};
};
pox: {
readOnlyFunctions: {
getPartialStackedByCycle: string;
getStackingMinimum: string;
getPoxInfo: string;
};
publicFunctions: {
allowContractCaller: string;
revokeDelegate: string;
disallowContractCaller: string;
};
};
}

export const functionMapping: IFunctionMapping = {
stacking: {
readOnlyFunctions: {
updatedBalancesGivenCycle: 'updated-balances-given-cycle',
checkClaimedBlocksRewardsBatch: 'check-claimed-blocks-rewards-batch',
checkWonBlockRewardsBatch: 'check-won-block-rewards-batch', // maximum 12 blocks
isPreparePhaseNow: 'is-prepare-phase-now',
// calculateExtraReservedFunds: 'calculate-extra-reserved-funds',
// canWithdrawExtraReservedNow: 'can-withdraw-extra-reserved-now',
getPoxAddrIndices: 'get-pox-addr-indices',
getStackersList: 'get-pool-members',
},
publicFunctions: {
updateSCBalances: 'update-sc-balances',
maybeStackAggregationCommit: 'maybe-stack-aggregation-commit',
// unlockExtraReservedFunds: 'unlock-extra-reserved-funds',
batchRewardDistribution: 'batch-reward-distribution',
delegateStackStxMany: 'delegate-stack-stx-many',
},
},
pox: {
readOnlyFunctions: {
getPartialStackedByCycle: 'get-partial-stacked-by-cycle',
getStackingMinimum: 'get-stacking-minimum',
getPoxInfo: 'get-pox-info',
},
publicFunctions: {
allowContractCaller: 'allow-contract-caller',
revokeDelegate: 'revoke-delegate-stx',
disallowContractCaller: 'disallow-contract-caller',
},
},
};
Loading