Skip to content

Commit

Permalink
Merge pull request #259 from tahowallet/a-tender-booyan
Browse files Browse the repository at this point in the history
A tender booyan: Tenderly test build
  • Loading branch information
jagodarybacka authored Oct 6, 2023
2 parents 40b7fe5 + 7ebbfb4 commit 85b3dc5
Show file tree
Hide file tree
Showing 20 changed files with 2,278 additions and 334 deletions.
4 changes: 4 additions & 0 deletions .env.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,8 @@ SUPPORT_ARBITRUM_NOVA=false
SUPPORT_SWAP_QUOTE_REFRESH=false
SUPPORT_ACHIEVEMENTS_BANNER=false
SUPPORT_NFT_SEND=false
SUPPORT_THE_ISLAND_TESTNET=false
USE_MAINNET_FORK=false
ARBITRUM_FORK_RPC=https://rpc.tenderly.co/fork/2fc2cf12-5c58-439f-9b5e-967bfd02191a
TESTNET_TAHO_DEPLOYER_ADDRESS=0x0ACB7821EC6f2Ca5D8a2Dd5518db2C852A1E2A10
TESTNET_TAHO_ADDRESS=0xE808174921a73df31756ca0996C1a9E5D9667876
1 change: 1 addition & 0 deletions background/features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const RuntimeFlag = {
SUPPORT_SWAP_QUOTE_REFRESH: process.env.SUPPORT_SWAP_QUOTE_REFRESH === "true",
SUPPORT_CUSTOM_NETWORKS: process.env.SUPPORT_CUSTOM_NETWORKS === "true",
SUPPORT_CUSTOM_RPCS: process.env.SUPPORT_CUSTOM_RPCS === "true",
SUPPORT_THE_ISLAND_TESTNET: process.env.SUPPORT_THE_ISLAND_TESTNET === "true",
} as const

type BuildTimeFlagType = keyof typeof BuildTimeFlag
Expand Down
32 changes: 18 additions & 14 deletions background/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
ProviderBridgeService,
TelemetryService,
ServiceCreatorFunction,
DoggoService,
IslandService,
LedgerService,
SigningService,
NFTsService,
Expand All @@ -41,7 +41,7 @@ import {
import { HexString, NormalizedEVMAddress } from "./types"
import { SignedTransaction } from "./networks"
import { AccountBalance, AddressOnNetwork, NameOnNetwork } from "./accounts"
import { Eligible } from "./services/doggo/types"
import { Eligible, ReferrerStats } from "./services/island/types"

import rootReducer from "./redux-slices"
import {
Expand All @@ -58,6 +58,7 @@ import {
removeAssetData,
} from "./redux-slices/assets"
import {
addIslandAsset,
setEligibility,
setEligibilityLoading,
setReferrer,
Expand Down Expand Up @@ -135,7 +136,6 @@ import {
SignatureResponse,
TXSignatureResponse,
} from "./services/signing"
import { ReferrerStats } from "./services/doggo/db"
import {
migrateReduxState,
REDUX_STATE_VERSION,
Expand Down Expand Up @@ -327,7 +327,7 @@ export default class Main extends BaseService<never> {
internalEthereumProviderService,
preferenceService,
)
const doggoService = DoggoService.create(chainService, indexingService)
const islandService = IslandService.create(chainService, indexingService)

const telemetryService = TelemetryService.create()

Expand Down Expand Up @@ -399,7 +399,7 @@ export default class Main extends BaseService<never> {
await nameService,
await internalEthereumProviderService,
await providerBridgeService,
await doggoService,
await islandService,
await telemetryService,
await ledgerService,
await signingService,
Expand Down Expand Up @@ -458,7 +458,7 @@ export default class Main extends BaseService<never> {
* A promise to the claim service, which saves the eligibility data
* for efficient storage and retrieval.
*/
private doggoService: DoggoService,
private islandService: IslandService,
/**
* A promise to the telemetry service, which keeps track of extension
* storage usage and (eventually) other statistics.
Expand Down Expand Up @@ -602,7 +602,7 @@ export default class Main extends BaseService<never> {
this.nameService.startService(),
this.internalEthereumProviderService.startService(),
this.providerBridgeService.startService(),
this.doggoService.startService(),
this.islandService.startService(),
this.telemetryService.startService(),
this.ledgerService.startService(),
this.signingService.startService(),
Expand All @@ -625,7 +625,7 @@ export default class Main extends BaseService<never> {
this.nameService.stopService(),
this.internalEthereumProviderService.stopService(),
this.providerBridgeService.stopService(),
this.doggoService.stopService(),
this.islandService.stopService(),
this.telemetryService.stopService(),
this.ledgerService.stopService(),
this.signingService.stopService(),
Expand All @@ -647,7 +647,7 @@ export default class Main extends BaseService<never> {
this.connectProviderBridgeService()
this.connectPreferenceService()
this.connectEnrichmentService()
this.connectDoggoService()
this.connectIslandService()
this.connectTelemetryService()
this.connectLedgerService()
this.connectSigningService()
Expand Down Expand Up @@ -1584,14 +1584,14 @@ export default class Main extends BaseService<never> {

this.store.dispatch(clearSwapQuote())
this.store.dispatch(setEligibilityLoading())
this.doggoService.getEligibility(addressNetwork.address)
this.islandService.getEligibility(addressNetwork.address)

this.store.dispatch(setVaultsAsStale())

await this.chainService.markAccountActivity(addressNetwork)

const referrerStats =
await this.doggoService.getReferrerStats(addressNetwork)
await this.islandService.getReferrerStats(addressNetwork)
this.store.dispatch(setReferrerStats(referrerStats))

this.providerBridgeService.notifyContentScriptsAboutAddressChange(
Expand Down Expand Up @@ -1629,15 +1629,15 @@ export default class Main extends BaseService<never> {
})
}

async connectDoggoService(): Promise<void> {
this.doggoService.emitter.on(
async connectIslandService(): Promise<void> {
this.islandService.emitter.on(
"newEligibility",
async (eligibility: Eligible) => {
await this.store.dispatch(setEligibility(eligibility))
},
)

this.doggoService.emitter.on(
this.islandService.emitter.on(
"newReferral",
async (
referral: {
Expand All @@ -1660,6 +1660,10 @@ export default class Main extends BaseService<never> {
}
},
)

this.islandService.emitter.on("monitoringTestnetAsset", (asset) => {
this.store.dispatch(addIslandAsset(asset))
})
}

connectTelemetryService(): void {
Expand Down
33 changes: 29 additions & 4 deletions background/redux-slices/claim.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createSlice, createSelector } from "@reduxjs/toolkit"
import { BigNumber, Signature, utils } from "ethers"
import { TransactionResponse } from "@ethersproject/abstract-provider"
import { Eligible } from "../services/doggo/types"
import { Eligible } from "../services/island/types"

import { createBackgroundAsyncThunk } from "./utils"
import { normalizeEVMAddress, truncateAddress } from "../lib/utils"
Expand All @@ -19,8 +19,14 @@ import DISTRIBUTOR_ABI from "./contract-abis/merkle-distributor"
import { DOGGO, HOUR } from "../constants"
import { FeatureFlags, isEnabled } from "../features"
import { ERC2612_INTERFACE } from "../lib/erc20"
import { ReferrerStats } from "../services/doggo/db"
import {
ReferrerStats,
TESTNET_TAHO,
VOTE_WITH_FRIENDS_ADDRESS,
} from "../services/island"
import { fromFixedPointNumber } from "../lib/fixed-point"
import { SmartContractFungibleAsset } from "../assets"
import { isSameAsset } from "./utils/asset-utils"

export interface DAO {
address: string
Expand All @@ -44,6 +50,7 @@ export interface Referrer {

interface ClaimingState {
status: string
islandAssets: SmartContractFungibleAsset[] | undefined
claimed: {
[address: HexString]: boolean
}
Expand All @@ -64,8 +71,6 @@ interface ClaimingState {
}

const DOGGO_TOKEN_ADDRESS = DOGGO.contractAddress
export const VOTE_WITH_FRIENDS_ADDRESS =
"0x0036B3a9D385Ce2CC072cf4A26dE29aE3283DEd0"

const getDistributorContract = async () => {
const distributorContractAddress = VOTE_WITH_FRIENDS_ADDRESS // VoteWithFriends contract address
Expand All @@ -78,6 +83,7 @@ const getDistributorContract = async () => {

const initialState: ClaimingState = {
status: "idle",
islandAssets: [],
claimed: {},
selectedForBonus: null,
selectedDelegate: null,
Expand Down Expand Up @@ -150,6 +156,16 @@ const claimingSlice = createSlice({
nonce,
expiry,
}),
addIslandAsset: (
immerState,
{ payload: asset }: { payload: SmartContractFungibleAsset },
) => {
if (immerState.islandAssets === undefined) {
immerState.islandAssets = [asset]
} else {
immerState.islandAssets.push(asset)
}
},
resetClaimFlow: (immerState) => {
immerState.signature = undefined
immerState.selectedForBonus = null
Expand Down Expand Up @@ -179,6 +195,7 @@ const claimingSlice = createSlice({
})

export const {
addIslandAsset,
chooseSelectedForBonus,
chooseDelegate,
setEligibility,
Expand Down Expand Up @@ -426,3 +443,11 @@ export const selectEligibilityLoading = createSelector(
(state: { claim: ClaimingState }): ClaimingState => state.claim,
(claimState: ClaimingState) => claimState.eligibilityLoading,
)

export const selectIsTestTahoDeployed = createSelector(
(state: { claim: ClaimingState }): ClaimingState => state.claim,
(claimState: ClaimingState) =>
claimState.islandAssets?.some((asset) =>
isSameAsset(asset, TESTNET_TAHO),
) ?? false,
)
12 changes: 8 additions & 4 deletions background/redux-slices/selectors/accountsSelectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
formatCurrencyAmount,
heuristicDesiredDecimalsForUnitPrice,
isNetworkBaseAsset,
isSameAsset,
isTrustedAsset,
} from "../utils/asset-utils"
import {
Expand Down Expand Up @@ -45,6 +46,7 @@ import { AccountSigner, SignerType } from "../../services/signing"
import { SignerImportSource } from "../../services/internal-signer"
import { assertUnreachable } from "../../lib/utils/type-guards"
import { PricesState, selectAssetPricePoint } from "../prices"
import { TESTNET_TAHO } from "../../services/island"

// TODO What actual precision do we want here? Probably more than 2
// TODO decimals? Maybe it's configurable?
Expand All @@ -64,11 +66,13 @@ export const userValueDustThreshold = 2
const shouldForciblyDisplayAsset = (
assetAmount: CompleteAssetAmount<AnyAsset>,
) => {
const isDoggo =
!isEnabled(FeatureFlags.HIDE_TOKEN_FEATURES) &&
assetAmount.asset.symbol === DOGGO.symbol
const isIslandRelated =
(!isEnabled(FeatureFlags.HIDE_TOKEN_FEATURES) &&
assetAmount.asset.symbol === DOGGO.symbol) ||
(isEnabled(FeatureFlags.SUPPORT_THE_ISLAND_TESTNET) &&
isSameAsset(assetAmount.asset, TESTNET_TAHO))

return isDoggo || isNetworkBaseAsset(assetAmount.asset)
return isIslandRelated || isNetworkBaseAsset(assetAmount.asset)
}

export function determineAssetDisplayAndVerify(
Expand Down
13 changes: 13 additions & 0 deletions background/services/chain/serial-fallback-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1090,6 +1090,19 @@ export function makeSerialFallbackProvider(
])
}

if (
chainID === ARBITRUM_ONE.chainID &&
process.env.ARBITRUM_FORK_RPC !== undefined &&
process.env.ARBITRUM_FORK_RPC.trim() !== ""
) {
return new SerialFallbackProvider(ARBITRUM_ONE.chainID, [
{
type: "generic" as const,
creator: () => new JsonRpcBatchProvider(process.env.ARBITRUM_FORK_RPC),
},
])
}

const alchemyProviderCreators: ProviderCreator[] =
ALCHEMY_SUPPORTED_CHAIN_IDS.has(chainID)
? [
Expand Down
Loading

0 comments on commit 85b3dc5

Please sign in to comment.