Skip to content

Commit ff6f5b6

Browse files
committed
Cleanup: Remove all references to ColonyStake model
1 parent d9e4323 commit ff6f5b6

File tree

8 files changed

+6
-441
lines changed

8 files changed

+6
-441
lines changed

src/graphql/generated.ts

Lines changed: 2 additions & 279 deletions
Large diffs are not rendered by default.

src/graphql/mutations/user.graphql

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/graphql/queries/user.graphql

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/handlers/motions/helpers.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,3 @@ export const getMessageKey = (
139139
): string => {
140140
return `${transactionHash}${logIndex}`;
141141
};
142-
143-
export const getColonyStakeId = (
144-
userAddress: string,
145-
colonyAddress: string,
146-
): string => {
147-
return `${userAddress}_${colonyAddress}`;
148-
};

src/handlers/motions/motionRewardClaimed/helpers.ts

Lines changed: 1 addition & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,16 @@
1-
import { BigNumber } from 'ethers';
2-
import { mutate, query } from '~amplifyClient';
1+
import { mutate } from '~amplifyClient';
32
import {
4-
GetColonyStakeDocument,
5-
GetColonyStakeQuery,
6-
GetColonyStakeQueryVariables,
73
StakerReward,
84
UpdateColonyDocument,
95
UpdateColonyMutation,
106
UpdateColonyMutationVariables,
11-
UpdateColonyStakeDocument,
12-
UpdateColonyStakeMutation,
13-
UpdateColonyStakeMutationVariables,
147
UpdateUserStakeDocument,
158
UpdateUserStakeMutation,
169
UpdateUserStakeMutationVariables,
17-
UserMotionStakes,
1810
} from '~graphql';
1911
import { getColonyFromDB, output } from '~utils';
2012
import { getUserStakeDatabaseId } from '~utils/stakes';
2113

22-
import { getColonyStakeId } from '../helpers';
23-
2414
export const getUpdatedStakerRewards = (
2515
stakerRewards: StakerReward[],
2616
stakerAddress: string,
@@ -106,42 +96,8 @@ export const updateColonyUnclaimedStakes = async (
10696
*/
10797
export const reclaimUserStake = async (
10898
userAddress: string,
109-
colonyAddress: string,
110-
reclaimAmount: BigNumber,
11199
motionTransactionHash: string,
112100
): Promise<void> => {
113-
const colonyStakeId = getColonyStakeId(userAddress, colonyAddress);
114-
const { data } =
115-
(await query<GetColonyStakeQuery, GetColonyStakeQueryVariables>(
116-
GetColonyStakeDocument,
117-
{
118-
colonyStakeId,
119-
},
120-
)) ?? {};
121-
122-
if (!data?.getColonyStake) {
123-
output(
124-
`Could not find user stake for user ${userAddress} in colony ${colonyAddress}. This is a bug and should be investigated.`,
125-
);
126-
return;
127-
}
128-
129-
const totalAmount = data.getColonyStake.totalAmount;
130-
let updatedAmount = BigNumber.from(totalAmount).sub(reclaimAmount);
131-
132-
// Should never be negative, but just in case.
133-
if (updatedAmount.isNegative()) {
134-
updatedAmount = BigNumber.from(0);
135-
}
136-
137-
await mutate<UpdateColonyStakeMutation, UpdateColonyStakeMutationVariables>(
138-
UpdateColonyStakeDocument,
139-
{
140-
colonyStakeId,
141-
totalAmount: updatedAmount.toString(),
142-
},
143-
);
144-
145101
// Update user stake status
146102
await mutate<UpdateUserStakeMutation, UpdateUserStakeMutationVariables>(
147103
UpdateUserStakeDocument,
@@ -153,21 +109,3 @@ export const reclaimUserStake = async (
153109
},
154110
);
155111
};
156-
157-
export const getUserMotionStake = (
158-
usersStakes: UserMotionStakes[],
159-
userAddress: string,
160-
): BigNumber => {
161-
const userStakes = usersStakes.find(({ address }) => address === userAddress);
162-
163-
if (!userStakes) {
164-
output(
165-
`Could not find the stakes for user ${userAddress}. This is a bug and should be investigated.`,
166-
);
167-
return BigNumber.from(0);
168-
}
169-
170-
return BigNumber.from(userStakes.stakes.raw.yay).add(
171-
userStakes.stakes.raw.nay,
172-
);
173-
};

src/handlers/motions/motionRewardClaimed/motionRewardClaimed.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
updateColonyUnclaimedStakes,
1111
reclaimUserStake,
1212
getUpdatedStakerRewards,
13-
getUserMotionStake,
1413
} from './helpers';
1514
import { ColonyMotion } from '~graphql';
1615
import { ExtensionEventListener } from '~eventListeners';
@@ -41,9 +40,8 @@ export const handleMotionRewardClaimed: EventHandler = async (
4140
const claimedMotion = await getMotionFromDB(motionDatabaseId);
4241

4342
if (claimedMotion) {
44-
const { stakerRewards, usersStakes } = claimedMotion;
43+
const { stakerRewards } = claimedMotion;
4544

46-
const userStake = getUserMotionStake(usersStakes, staker);
4745
const updatedStakerRewards = getUpdatedStakerRewards(stakerRewards, staker);
4846

4947
const newMotionMessages = [
@@ -66,11 +64,6 @@ export const handleMotionRewardClaimed: EventHandler = async (
6664
motionDatabaseId,
6765
updatedStakerRewards,
6866
);
69-
await reclaimUserStake(
70-
staker,
71-
colonyAddress,
72-
userStake,
73-
updatedMotionData.transactionHash,
74-
);
67+
await reclaimUserStake(staker, updatedMotionData.transactionHash);
7568
}
7669
};

src/handlers/motions/motionStaked/helpers.ts

Lines changed: 1 addition & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,22 @@ import { BigNumber, constants } from 'ethers';
22
import { MotionVote, MotionEvents } from '~types';
33
import {
44
ColonyMotion,
5-
CreateColonyStakeDocument,
6-
CreateColonyStakeMutation,
7-
CreateColonyStakeMutationVariables,
85
CreateMotionMessageInput,
96
CreateUserStakeDocument,
107
CreateUserStakeMutation,
118
CreateUserStakeMutationVariables,
12-
GetColonyStakeDocument,
13-
GetColonyStakeQuery,
14-
GetColonyStakeQueryVariables,
159
GetUserStakeDocument,
1610
GetUserStakeQuery,
1711
GetUserStakeQueryVariables,
1812
MotionStakes,
19-
UpdateColonyStakeDocument,
20-
UpdateColonyStakeMutation,
21-
UpdateColonyStakeMutationVariables,
2213
UpdateUserStakeDocument,
2314
UpdateUserStakeMutation,
2415
UpdateUserStakeMutationVariables,
2516
UserMotionStakes,
2617
} from '~graphql';
2718
import { mutate, query } from '~amplifyClient';
2819
import { getUserStakeDatabaseId } from '~utils/stakes';
29-
import { getMotionSide, getColonyStakeId } from '../helpers';
20+
import { getMotionSide } from '../helpers';
3021

3122
export const getRequiredStake = (
3223
skillRep: BigNumber,
@@ -297,48 +288,6 @@ export const getUpdatedMessages = ({
297288
return updatedMessages;
298289
};
299290

300-
/**
301-
* If it's the first time a user has staked in a colony, we create a Colony Stake record for the user,
302-
* else we update the amount they've currently got staked in the colony.
303-
*/
304-
export const updateUserColonyStake = async (
305-
userAddress: string,
306-
colonyAddress: string,
307-
stakeAmount: BigNumber,
308-
): Promise<void> => {
309-
const colonyStakeId = getColonyStakeId(userAddress, colonyAddress);
310-
const { data } =
311-
(await query<GetColonyStakeQuery, GetColonyStakeQueryVariables>(
312-
GetColonyStakeDocument,
313-
{
314-
colonyStakeId,
315-
},
316-
)) ?? {};
317-
318-
if (data?.getColonyStake) {
319-
const { totalAmount } = data?.getColonyStake;
320-
const updatedTotal = BigNumber.from(totalAmount).add(stakeAmount);
321-
322-
await mutate<UpdateColonyStakeMutation, UpdateColonyStakeMutationVariables>(
323-
UpdateColonyStakeDocument,
324-
{
325-
totalAmount: updatedTotal.toString(),
326-
colonyStakeId,
327-
},
328-
);
329-
} else {
330-
await mutate<CreateColonyStakeMutation, CreateColonyStakeMutationVariables>(
331-
CreateColonyStakeDocument,
332-
{
333-
totalAmount: stakeAmount.toString(),
334-
colonyStakeId,
335-
colonyAddress,
336-
userAddress,
337-
},
338-
);
339-
}
340-
};
341-
342291
/**
343292
* Function to update the user stake following staking on a motion
344293
*/

src/handlers/motions/motionStaked/motionStaked.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
getUpdatedMessages,
1313
updateMotionInDB,
1414
getMessageKey,
15-
updateUserColonyStake,
1615
updateUserStake,
1716
} from '../helpers';
1817

@@ -29,8 +28,6 @@ export const handleMotionStaked: EventHandler = async (
2928
} = event;
3029
const { colonyAddress } = listener as ExtensionEventListener;
3130

32-
await updateUserColonyStake(staker, colonyAddress, amount);
33-
3431
const votingClient = await getVotingClient(colonyAddress);
3532

3633
if (!votingClient) {

0 commit comments

Comments
 (0)