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

Release: SuperFluid Anchor Contract #1895

Merged
merged 6 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
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
10 changes: 10 additions & 0 deletions migration/data/seedTokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1695,6 +1695,16 @@ const seedTokens: ITokenData[] = [
coingeckoId: 'degen-base',
isGivbackEligible: false,
},
// cbBTC - https://basescan.org/token/0xcbB7C0000aB88B473b1f5aFd9ef808440eed33Bf
{
name: 'Coinbase Wrapped BTC',
symbol: 'cbBTC',
address: '0xcbB7C0000aB88B473b1f5aFd9ef808440eed33Bf',
decimals: 8,
networkId: NETWORK_IDS.BASE_MAINNET,
coingeckoId: 'coinbase-wrapped-btc',
isGivbackEligible: false,
},
// Osaka Protocol - https://basescan.org/token/0xbFd5206962267c7b4b4A8B3D76AC2E1b2A5c4d5e
{
name: 'Osaka Protocol',
Expand Down
68 changes: 68 additions & 0 deletions src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,76 @@ export const superTokensToToken = {
DAIx: 'DAI',
OPx: 'OP',
GIVx: 'GIV',
DEGENx: 'DEGEN',
cbBTCx: 'cbBTC',
};

export const superTokensBase = [
{
underlyingToken: {
decimals: 6,
id: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',
name: 'USD Coin',
symbol: 'USDC',
coingeckoId: 'usd-coin',
},
decimals: 18,
id: '0xD04383398dD2426297da660F9CCA3d439AF9ce1b',
name: 'Super USD Coin',
symbol: 'USDCx',
isSuperToken: true,
coingeckoId: 'usd-coin',
},
{
underlyingToken: {
name: 'Ethereum',
symbol: 'ETH',
decimals: 18,
id: '0x0000000000000000000000000000000000000000',
},
decimals: 18,
id: '0x46fd5cfB4c12D87acD3a13e92BAa53240C661D93',
name: 'Super ETH',
symbol: 'ETHx',
},
{
underlyingToken: {
decimals: 8,
id: '0xcbB7C0000aB88B473b1f5aFd9ef808440eed33Bf',
name: 'Coinbase Wrapped BTC',
symbol: 'cbBTC',
},
decimals: 18,
id: '0xDFd428908909CB5E24F5e79E6aD6BDE10bdf2327',
name: 'Super Coinbase Wrapped BTC',
symbol: 'cbBTCx',
},
{
underlyingToken: {
decimals: 18,
id: '0x50c5725949A6F0c72E6C4a641F24049A917DB0Cb',
name: 'DAI Stablecoin',
symbol: 'DAI',
},
decimals: 18,
id: '0x708169c8C87563Ce904E0a7F3BFC1F3b0b767f41',
name: 'Super DAI Stablecoin',
symbol: 'DAIx',
},
{
underlyingToken: {
decimals: 18,
id: '0x4ed4E862860beD51a9570b96d89aF5E1B0Efefed',
name: 'Degen',
symbol: 'DEGEN',
},
decimals: 18,
id: '0x1efF3Dd78F4A14aBfa9Fa66579bD3Ce9E1B30529',
name: 'Super Degen',
symbol: 'DEGENx',
},
];

export const superTokens = [
{
underlyingToken: {
Expand Down
12 changes: 9 additions & 3 deletions src/repositories/projectRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export type FilterProjectQueryInputParams = {
qfRoundId?: number;
activeQfRoundId?: number;
qfRoundSlug?: string;
includeUnlisted?: boolean;
};
export const filterProjectsQuery = (params: FilterProjectQueryInputParams) => {
const {
Expand All @@ -97,6 +98,7 @@ export const filterProjectsQuery = (params: FilterProjectQueryInputParams) => {
qfRoundId,
qfRoundSlug,
activeQfRoundId,
includeUnlisted,
} = params;

let query = Project.createQueryBuilder('project')
Expand All @@ -122,11 +124,16 @@ export const filterProjectsQuery = (params: FilterProjectQueryInputParams) => {
'projectPower.totalPower',
'projectPower.powerRank',
'projectPower.round',
])
.where(
]);

if (includeUnlisted) {
query = query.where(`project.statusId = ${ProjStatus.active}`);
} else {
query = query.where(
`project.statusId = ${ProjStatus.active} AND project.reviewStatus = :reviewStatus`,
{ reviewStatus: ReviewStatus.Listed },
);
}

const isFilterByQF =
!!filters?.find(f => f === FilterField.ActiveQfRound) && activeQfRoundId;
Expand Down Expand Up @@ -255,7 +262,6 @@ export const filterProjectsQuery = (params: FilterProjectQueryInputParams) => {
break;
case SortingField.BestMatch:
break;

default:
query
.addOrderBy('projectInstantPower.totalPower', OrderDirection.DESC)
Expand Down
32 changes: 27 additions & 5 deletions src/resolvers/anchorContractAddressResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import { ApolloContext } from '../types/ApolloContext';
import { findUserById } from '../repositories/userRepository';
import { getProvider } from '../provider';
import { logger } from '../utils/logger';
import { ChainType } from '../types/network';
import { addBulkNewProjectAddress } from '../repositories/projectAddressRepository';
import { validateProjectRelatedAddresses } from '../utils/validators/projectValidator';

@Resolver(_of => AnchorContractAddress)
export class AnchorContractAddressResolver {
Expand All @@ -24,6 +27,7 @@ export class AnchorContractAddressResolver {
@Arg('networkId', () => Int) networkId: number,
@Arg('address', () => String) address: string,
@Arg('txHash', () => String) txHash: string,
@Arg('recipientAddress', { nullable: true }) recipientAddress?: string,
): Promise<AnchorContractAddress> {
const userId = ctx?.req?.user?.userId;
const creatorUser = await findUserById(userId);
Expand Down Expand Up @@ -53,11 +57,29 @@ export class AnchorContractAddressResolver {
projectAddress.isRecipient === true,
)
) {
throw new Error(
i18n.__(
translationErrorMessagesKeys.PROJECT_DOESNT_HAVE_RECIPIENT_ADDRESS_ON_THIS_NETWORK,
),
);
if (recipientAddress) {
const recipientAddressInput = {
project,
user: creatorUser,
address: recipientAddress!,
chainType: ChainType.EVM,
networkId: networkId,
isRecipient: true,
};

await validateProjectRelatedAddresses(
[recipientAddressInput],
projectId,
);

await addBulkNewProjectAddress([recipientAddressInput]);
} else {
throw new Error(
i18n.__(
translationErrorMessagesKeys.PROJECT_DOESNT_HAVE_RECIPIENT_ADDRESS_ON_THIS_NETWORK,
),
);
}
}

const web3Provider = getProvider(networkId);
Expand Down
5 changes: 5 additions & 0 deletions src/resolvers/projectResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,9 @@ class GetProjectsArgs {

@Field(_type => String, { nullable: true })
qfRoundSlug?: string;

@Field({ nullable: true })
includeUnlisted?: boolean;
}

@ObjectType()
Expand Down Expand Up @@ -740,6 +743,7 @@ export class ProjectResolver {
campaignSlug,
qfRoundId,
qfRoundSlug,
includeUnlisted,
}: GetProjectsArgs,
@Ctx() { req: { user }, projectsFiltersThreadPool }: ApolloContext,
): Promise<AllProjects> {
Expand All @@ -766,6 +770,7 @@ export class ProjectResolver {
qfRoundId,
qfRoundSlug,
activeQfRoundId,
includeUnlisted,
};
let campaign;
if (campaignSlug) {
Expand Down
84 changes: 84 additions & 0 deletions src/resolvers/recurringDonationResolver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ import { QfRound } from '../entities/qfRound';
import { generateRandomString } from '../utils/utils';
import { ORGANIZATION_LABELS } from '../entities/organization';

describe(
'recurringDonationEligibleProjects test cases',
recurringDonationEligibleProjectsTestCases,
);

describe(
'createRecurringDonation test cases',
createRecurringDonationTestCases,
Expand Down Expand Up @@ -63,6 +68,85 @@ describe(
recurringDonationsByProjectDateTestCases,
);

function recurringDonationEligibleProjectsTestCases() {
it('should return eligible projects with their anchor contracts', async () => {
const projectOwner = await saveUserDirectlyToDb(
generateRandomEtheriumAddress(),
);

const project = await saveProjectDirectlyToDb(
{
...createProjectData(),
isGivbackEligible: true,
},
projectOwner,
);

const anchorContractAddress = await addNewAnchorAddress({
project,
owner: projectOwner,
creator: projectOwner,
address: generateRandomEtheriumAddress(),
networkId: NETWORK_IDS.OPTIMISTIC,
txHash: generateRandomEvmTxHash(),
});

const anchorContractAddressBASE = await addNewAnchorAddress({
project,
owner: projectOwner,
creator: projectOwner,
address: generateRandomEtheriumAddress(),
networkId: NETWORK_IDS.BASE_MAINNET,
txHash: generateRandomEvmTxHash(),
});

const result = await axios.post(graphqlUrl, {
query: `
query {
recurringDonationEligibleProjects {
id
slug
title
anchorContracts {
address
networkId
isActive
}
}
}
`,
});

assert.isNotNull(result.data.data.recurringDonationEligibleProjects);
const foundProject =
result.data.data.recurringDonationEligibleProjects.find(
p => p.id === project.id,
);

assert.isNotNull(
foundProject,
'Project should be found in eligible projects',
);
assert.equal(foundProject.slug, project.slug);
assert.equal(foundProject.title, project.title);
assert.equal(foundProject.anchorContracts.length, 2);

// Assert Optimistic anchor contract
const optimisticContract = foundProject.anchorContracts.find(
contract => contract.networkId === NETWORK_IDS.OPTIMISTIC,
);
assert.isNotNull(optimisticContract);
assert.equal(optimisticContract.address, anchorContractAddress.address);

// Assert BASE anchor contract
const baseContract = foundProject.anchorContracts.find(
contract => contract.networkId === NETWORK_IDS.BASE_MAINNET,
);
assert.isNotNull(baseContract);
assert.equal(baseContract.address, anchorContractAddressBASE.address);
});
}

function createRecurringDonationTestCases() {
it('should create recurringDonation successfully', async () => {
const projectOwner = await saveUserDirectlyToDb(
Expand Down
Loading
Loading