Skip to content

Commit

Permalink
remove getIsListed workaround assuming resolver exists
Browse files Browse the repository at this point in the history
  • Loading branch information
0xdavinchee committed Nov 24, 2023
1 parent a98c3c6 commit 11db192
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 79 deletions.
1 change: 1 addition & 0 deletions packages/subgraph/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"pretest": "yarn testenv:start",
"test": "npx hardhat test",
"matchstick": "run-s matchstick:*",
"matchstick:build-network-config": "npx ts-node scripts/buildNetworkConfig.ts polygon-mainnet",
"matchstick:prepare-manifest": "mustache config/polygon-mainnet.json subgraph.template.yaml > subgraph.yaml",
"matchstick:prepare-addresses": "mustache config/polygon-mainnet.json src/addresses.template.ts > src/addresses.ts",
"matchstick:prepare-generated": "yarn getAbi && yarn codegen && yarn generate-sf-meta-local",
Expand Down
4 changes: 0 additions & 4 deletions packages/subgraph/src/addresses.template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,3 @@ export function getResolverAddress(): Address {
export function getNativeAssetSuperTokenAddress(): Address {
return Address.fromString("{{nativeAssetSuperTokenAddress}}");
}

export function getIsLocalIntegrationTesting(): boolean {
return "{{testNetwork}}".length > 0;
}
1 change: 1 addition & 0 deletions packages/subgraph/src/mappingHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ export function getOrInitSuperToken(
);

token = handleTokenRPCCalls(token, resolverAddress);
token.isListed = false;
const underlyingAddress = token.underlyingAddress;
token.underlyingToken = underlyingAddress.toHexString();

Expand Down
20 changes: 0 additions & 20 deletions packages/subgraph/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
Token,
TokenStatistic,
} from "../generated/schema";
import { getIsLocalIntegrationTesting } from "./addresses";

/**************************************************************************
* Constants
Expand Down Expand Up @@ -106,9 +105,6 @@ export function handleTokenRPCCalls(
if (token.name.length == 0 || token.symbol.length == 0) {
token = getTokenInfoAndReturn(token);
}

// we do getIsListedToken after getTokenInfoAndReturn because it requires the token symbol
token = getIsListedToken(token, resolverAddress);
return token;
}

Expand All @@ -129,22 +125,6 @@ export function getTokenInfoAndReturn(token: Token): Token {
return token;
}

export function getIsListedToken(
token: Token,
resolverAddress: Address
): Token {
const resolverContract = Resolver.bind(resolverAddress);
const isLocalIntegrationTesting = getIsLocalIntegrationTesting();
const version = isLocalIntegrationTesting ? "test" : "v1";
const result = resolverContract.try_get(
"supertokens." + version + "." + token.symbol
);
const superTokenAddress = result.reverted ? ZERO_ADDRESS : result.value;
token.isListed = token.id == superTokenAddress.toHex();

return token;
}

/**
* Gets and sets the total supply for TokenStatistic of a SuperToken upon initial creation
* @param tokenStatistic
Expand Down
6 changes: 2 additions & 4 deletions packages/subgraph/tests/cfav1/cfav1.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export function createFlowOperatorUpdatedEvent(
* @param flowRate
* @param previousSenderFlowRate
* @param previousReceiverFlowRate
* @param isListed
* @param stringUserData
* @returns FlowUpdated event
*/
export function modifyFlowAndAssertFlowUpdatedEventProperties(
Expand All @@ -104,7 +104,6 @@ export function createFlowOperatorUpdatedEvent(
flowRate: BigInt,
previousSenderFlowRate: BigInt,
previousReceiverFlowRate: BigInt,
isListed: boolean,
stringUserData: string
): FlowUpdated {
const oldFlowRate = previousSenderFlowRate.abs();
Expand Down Expand Up @@ -133,8 +132,7 @@ export function createFlowOperatorUpdatedEvent(
tokenSymbol,
underlyingToken,
deposit,
expectedOwedDeposit,
isListed
expectedOwedDeposit
);

handleFlowUpdated(flowUpdatedEvent);
Expand Down
27 changes: 14 additions & 13 deletions packages/subgraph/tests/cfav1/event/cfav1.event.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,25 @@ import {
describe,
test,
} from "matchstick-as/assembly/index";
import { handleFlowOperatorUpdated } from "../../../src/mappings/cfav1";
import {
handleFlowOperatorUpdated,
} from "../../../src/mappings/cfav1";
import { BIG_INT_ZERO, getFlowOperatorID, ZERO_ADDRESS } from "../../../src/utils";
import {assertEventBaseProperties } from "../../assertionHelpers";
import { alice, bob, maticXAddress, maticXName, maticXSymbol } from "../../constants";
BIG_INT_ZERO,
getFlowOperatorID,
ZERO_ADDRESS,
} from "../../../src/utils";
import { assertEventBaseProperties } from "../../assertionHelpers";
import {
alice,
bob,
maticXAddress,
maticXName,
maticXSymbol,
} from "../../constants";
import {
createFlowOperatorUpdatedEvent,
modifyFlowAndAssertFlowUpdatedEventProperties,
} from "../cfav1.helper";
import {mockedApprove} from "../../mockedFunctions";
import { mockedApprove } from "../../mockedFunctions";

const initialFlowRate = BigInt.fromI32(100);

Expand All @@ -39,7 +47,6 @@ describe("ConstantFlowAgreementV1 Event Entity Unit Tests", () => {
initialFlowRate, // flowRate
BIG_INT_ZERO, // previousSenderFlowRate
BIG_INT_ZERO, // previousReceiverFlowRate
true, // isListed,
"" // userData
);
});
Expand All @@ -58,7 +65,6 @@ describe("ConstantFlowAgreementV1 Event Entity Unit Tests", () => {
initialFlowRate, // flowRate
BIG_INT_ZERO, // previousSenderFlowRate
BIG_INT_ZERO, // previousReceiverFlowRate
true, // isListed,
"" // userData
);

Expand All @@ -76,7 +82,6 @@ describe("ConstantFlowAgreementV1 Event Entity Unit Tests", () => {
increasedFlowRate, // flowRate
initialFlowRate, // previousSenderFlowRate
initialFlowRate, // previousReceiverFlowRate
true, // isListed,
"" // userData
);

Expand All @@ -93,7 +98,6 @@ describe("ConstantFlowAgreementV1 Event Entity Unit Tests", () => {
initialFlowRate, // flowRate
increasedFlowRate, // previousSenderFlowRate
increasedFlowRate, // previousReceiverFlowRate
true, // isListed,
"" // userData
);
});
Expand All @@ -112,7 +116,6 @@ describe("ConstantFlowAgreementV1 Event Entity Unit Tests", () => {
initialFlowRate, // flowRate
BIG_INT_ZERO, // previousSenderFlowRate
BIG_INT_ZERO, // previousReceiverFlowRate
true, // isListed,
"" // userData
);

Expand All @@ -130,7 +133,6 @@ describe("ConstantFlowAgreementV1 Event Entity Unit Tests", () => {
increasedFlowRate, // flowRate
initialFlowRate, // previousSenderFlowRate
initialFlowRate, // previousReceiverFlowRate
true, // isListed,
"" // userData
);

Expand All @@ -148,7 +150,6 @@ describe("ConstantFlowAgreementV1 Event Entity Unit Tests", () => {
BIG_INT_ZERO, // flowRate
increasedFlowRate, // previousSenderFlowRate
increasedFlowRate, // previousReceiverFlowRate
true, // isListed,
"" // userData
);
});
Expand Down
1 change: 0 additions & 1 deletion packages/subgraph/tests/cfav1/hol/cfav1.hol.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ describe("ConstantFlowAgreementV1 Higher Order Level Entity Unit Tests", () => {
initialFlowRate, // flowRate
BIG_INT_ZERO, // previousSenderFlowRate
BIG_INT_ZERO, // previousReceiverFlowRate
true, // isListed,
"henlo" // userData
);

Expand Down
3 changes: 1 addition & 2 deletions packages/subgraph/tests/idav1/event/idav1.event.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ describe("InstantDistributionV1 Event Entity Unit Tests", () => {
DEFAULT_DECIMALS,
ZERO_ADDRESS,
maticXName,
maticXSymbol,
true
maticXSymbol
);

// getOrInitIndex(event) => getOrInitAccount(publisher) => host.try_getAppManifest(sender)
Expand Down
2 changes: 0 additions & 2 deletions packages/subgraph/tests/mockedEntities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import { getStreamID } from "../src/utils";

/**
* Creates a SuperToken entity
* Note: this is needed otherwise we get a null error when we try
* run getIsListedToken and it tries to access token.symbol
* @param tokenAddress the address of the token
* @param block transaction block object
* @param decimals number of decimals
Expand Down
21 changes: 4 additions & 17 deletions packages/subgraph/tests/mockedFunctions.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { Address, BigInt, ethereum } from "@graphprotocol/graph-ts";
import { createMockedFunction } from "matchstick-as/assembly/index";
import { FlowUpdated } from "../generated/ConstantFlowAgreementV1/IConstantFlowAgreementV1";
import { BIG_INT_ZERO, ZERO_ADDRESS } from "../src/utils";
import { BIG_INT_ZERO } from "../src/utils";
import {
FAKE_INITIAL_BALANCE,
FAKE_SUPER_TOKEN_TOTAL_SUPPLY,
hostAddress,
resolverAddress,
} from "./constants";
import {
getETHAddress,
Expand All @@ -28,15 +27,13 @@ import {
* @param underlyingAddress
* @param tokenName
* @param tokenSymbol
* @param isListed
*/
export function mockedHandleSuperTokenInitRPCCalls(
superToken: string,
decimals: i32,
underlyingAddress: Address,
tokenName: string,
tokenSymbol: string,
isListed: boolean
tokenSymbol: string
): void {
// [START] getTokenInfoAndReturn =>
// token.try_getUnderlyingToken()
Expand All @@ -49,13 +46,6 @@ export function mockedHandleSuperTokenInitRPCCalls(
mockedTokenDecimals(superToken, decimals);
// [END] getTokenInfoAndReturn

// getIsListedToken(token, resolver) => resolver.try_get(key)
mockedResolverGet(
resolverAddress,
"supertokens.v1." + tokenSymbol,
isListed ? superToken : ZERO_ADDRESS.toHexString()
);

// updateTotalSupplyForNativeSuperToken(token, tokenStatistic, tokenAddress)
mockedTokenTotalSupply(superToken, FAKE_SUPER_TOKEN_TOTAL_SUPPLY);
}
Expand All @@ -70,7 +60,6 @@ export function mockedHandleSuperTokenInitRPCCalls(
* @param underlyingAddress
* @param expectedDeposit
* @param expectedOwedDeposit
* @param isListed
*/
export function mockedHandleFlowUpdatedRPCCalls(
flowUpdatedEvent: FlowUpdated,
Expand All @@ -80,8 +69,7 @@ export function mockedHandleFlowUpdatedRPCCalls(
tokenSymbol: string,
underlyingAddress: Address,
expectedDeposit: BigInt,
expectedOwedDeposit: BigInt,
isListed: boolean
expectedOwedDeposit: BigInt
): void {
const sender = flowUpdatedEvent.params.sender.toHex();
const receiver = flowUpdatedEvent.params.receiver.toHex();
Expand Down Expand Up @@ -113,8 +101,7 @@ export function mockedHandleFlowUpdatedRPCCalls(
decimals,
underlyingAddress,
tokenName,
tokenSymbol,
isListed
tokenSymbol
);
// [END] getOrInitStream(event) => getOrInitSuperToken(token, block) => handleTokenRPCCalls(token, resolverAddress)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ describe("SuperToken Mapper Unit Tests", () => {
DEFAULT_DECIMALS,
ZERO_ADDRESS,
maticXName,
maticXSymbol,
false
maticXSymbol
);

mockedRealtimeBalanceOf(
Expand Down Expand Up @@ -214,8 +213,7 @@ describe("SuperToken Mapper Unit Tests", () => {
DEFAULT_DECIMALS,
ZERO_ADDRESS,
maticXName,
maticXSymbol,
false
maticXSymbol
);

mockedRealtimeBalanceOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ describe("SuperTokenFactory Mapper Unit Tests", () => {
DEFAULT_DECIMALS,
ZERO_ADDRESS,
maticXName,
maticXSymbol,
false
maticXSymbol
);

handleSuperTokenCreated(SuperTokenCreatedEvent);
Expand All @@ -83,8 +82,7 @@ describe("SuperTokenFactory Mapper Unit Tests", () => {
DEFAULT_DECIMALS,
ZERO_ADDRESS,
maticXName,
maticXSymbol,
false
maticXSymbol
);

handleCustomSuperTokenCreated(CustomSuperTokenCreatedEvent);
Expand Down Expand Up @@ -138,8 +136,7 @@ describe("SuperTokenFactory Mapper Unit Tests", () => {
DEFAULT_DECIMALS,
ZERO_ADDRESS,
maticXName,
maticXSymbol,
false // isListed
maticXSymbol
);

handleSuperTokenCreated(SuperTokenCreatedEvent);
Expand Down Expand Up @@ -168,17 +165,15 @@ describe("SuperTokenFactory Mapper Unit Tests", () => {
DEFAULT_DECIMALS,
Address.fromString(daiAddress),
daiXName,
daiXSymbol,
false
daiXSymbol
);
// for getOrInitToken ((PoS) Dai Stablecoin (DAI))
mockedHandleSuperTokenInitRPCCalls(
daiAddress,
DEFAULT_DECIMALS,
ZERO_ADDRESS,
daiName,
daiSymbol,
false
daiSymbol
);

handleSuperTokenCreated(SuperTokenCreatedEvent);
Expand Down Expand Up @@ -226,8 +221,7 @@ describe("SuperTokenFactory Mapper Unit Tests", () => {
DEFAULT_DECIMALS,
ZERO_ADDRESS,
maticXName,
maticXSymbol,
false // isListed
maticXSymbol
);

handleSuperTokenCreated(SuperTokenCreatedEvent);
Expand Down

0 comments on commit 11db192

Please sign in to comment.