Skip to content

Commit

Permalink
contract: migrate from base goerli to base sepolia
Browse files Browse the repository at this point in the history
  • Loading branch information
dcposch committed Feb 10, 2024
1 parent d476fa0 commit 890e511
Show file tree
Hide file tree
Showing 48 changed files with 589 additions and 824 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ jobs:
version: nightly

- run: |
forge test -vvv --fork-url "https://base-goerli.publicnode.com"
forge coverage --report lcov --fork-url "https://base-goerli.publicnode.com"
forge test -vvv --fork-url "https://base-sepolia.publicnode.com"
forge coverage --report lcov --fork-url "https://base-sepolia.publicnode.com"
git diff --exit-code
working-directory: ./packages/contract
Expand Down
14 changes: 8 additions & 6 deletions apps/daimo-mobile/src/action/useSendAsync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import {
PendingOpEventID,
UserOpHex,
assert,
assertNotNull,
dollarsToAmount,
} from "@daimo/common";
import {
daimoChainFromId,
daimoEphemeralNotesAddress,
daimoEphemeralNotesV2Address,
notesV1AddressMap,
notesV2AddressMap,
} from "@daimo/contract";
import { DaimoOpSender, OpSenderCallback } from "@daimo/userop";
import * as Haptics from "expo-haptics";
Expand Down Expand Up @@ -180,12 +181,13 @@ function loadOpSender({
`[SEND] loading DaimoOpSender ${address} ${enclaveKeyName} ${keySlot}`
);

const chainConfig = env(daimoChain).chainConfig;
return await DaimoOpSender.init({
chainId,
tokenAddress: env(daimoChain).chainConfig.tokenAddress,
tokenDecimals: env(daimoChain).chainConfig.tokenDecimals,
notesAddress: daimoEphemeralNotesAddress,
notesAddressV2: daimoEphemeralNotesV2Address,
tokenAddress: chainConfig.tokenAddress,
tokenDecimals: chainConfig.tokenDecimals,
notesAddressV1: assertNotNull(notesV1AddressMap.get(chainId)),
notesAddressV2: assertNotNull(notesV2AddressMap.get(chainId)),
accountAddress: address,
accountSigner: signer,
opSender: sender,
Expand Down
2 changes: 1 addition & 1 deletion apps/daimo-mobile/src/common/useSendDebugLog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function useSendDebugLog(
}, []);

// Get phone and app info.
const daimoChain = daimoChainFromId(account?.homeChainId || 84531);
const daimoChain = daimoChainFromId(account?.homeChainId || 84532);
const envObj = env(daimoChain);
const envKV: Record<string, string> = {
Platform: `${Platform.OS} ${Platform.Version} ${envObj.deviceType}`,
Expand Down
1 change: 1 addition & 0 deletions apps/daimo-mobile/src/logic/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ function getDeviceType(): "computer" | "phone" {
return "phone";
}
}

export function env(daimoChain: DaimoChain) {
const chainConfig = getChainConfig(daimoChain);
return {
Expand Down
16 changes: 8 additions & 8 deletions apps/daimo-mobile/src/logic/trpc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { updateNetworkStateOnline } from "../sync/networkState";

const apiUrlT =
process.env.DAIMO_APP_API_URL_TESTNET || process.env.DAIMO_APP_API_URL;
const apiUrlTestnetWithChain = `${apiUrlT}/chain/84531`;
const apiUrlTestnetWithChain = `${apiUrlT}/chain/84532`;
const apiUrlM =
process.env.DAIMO_APP_API_URL_MAINNET || process.env.DAIMO_APP_API_URL;
const apiUrlMainnetWithChain = `${apiUrlM}/chain/8453`;
Expand Down Expand Up @@ -51,7 +51,7 @@ function chooseChain<T>({
testnet: T;
}): T {
assert(
["base", "baseGoerli"].includes(daimoChain),
["base", "baseSepolia"].includes(daimoChain),
`Unsupported chain: ${daimoChain}`
);
if (daimoChain === "base") return mainnet;
Expand Down Expand Up @@ -119,15 +119,15 @@ function getOpts(daimoChain: DaimoChain) {
};
}

const rpcHookMainnetClient = rpcHookMainnet.trpc.createClient(getOpts("base"));
const rpcHookTestnetClient = rpcHookTestnet.trpc.createClient(
getOpts("baseGoerli")
);
const optsMainnet = getOpts("base");
const optsTestnet = getOpts("baseSepolia");
const rpcHookMainnetClient = rpcHookMainnet.trpc.createClient(optsMainnet);
const rpcHookTestnetClient = rpcHookTestnet.trpc.createClient(optsTestnet);

type RpcClient = typeof rpcHookMainnetClient | typeof rpcHookTestnetClient;

const rpcFuncMainnet = createTRPCProxyClient<AppRouter>(getOpts("base"));
const rpcFuncTestnet = createTRPCProxyClient<AppRouter>(getOpts("baseGoerli"));
const rpcFuncMainnet = createTRPCProxyClient<AppRouter>(optsMainnet);
const rpcFuncTestnet = createTRPCProxyClient<AppRouter>(optsTestnet);

export function getRpcFunc(daimoChain: DaimoChain) {
return chooseChain({
Expand Down
2 changes: 1 addition & 1 deletion apps/daimo-mobile/src/view/screen/DeviceScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export function DeviceScreen({ route, navigation }: Props) {
const canRemove =
account.accountKeys.length > 1 ||
account.lastBalance < dollarsToAmount(1) ||
account.homeChainId === 84531; // Testnet
account.homeChainId === 84532; // Testnet

const statusMessage = (function (): ReactNode {
switch (status) {
Expand Down
24 changes: 10 additions & 14 deletions apps/daimo-mobile/src/view/screen/link/NoteScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,12 @@ import {
DaimoNoteState,
DaimoNoteStatus,
EAccount,
PendingOpEventID,
OpStatus,
PendingOpEventID,
dollarsToAmount,
getAccountName,
} from "@daimo/common";
import {
daimoChainFromId,
daimoEphemeralNotesAddress,
daimoEphemeralNotesV2Address,
} from "@daimo/contract";
import { daimoChainFromId } from "@daimo/contract";
import {
DaimoNonce,
DaimoNonceMetadata,
Expand Down Expand Up @@ -66,11 +62,9 @@ function NoteScreenInner({ route, account }: Props & { account: Account }) {
const { link } = route.params;
console.log(`[NOTE] rendering NoteScreen, link ${JSON.stringify(link)}`);

const noteFetch = useFetchLinkStatus(
link,
daimoChainFromId(account.homeChainId)
)!;

// Connect to the relevant DaimoEphemeralNotes[V2] contract info
const chain = daimoChainFromId(account.homeChainId);
const noteFetch = useFetchLinkStatus(link, chain)!;
const noteStatus = noteFetch.data as DaimoNoteStatus | undefined;

const title = (function (): string {
Expand All @@ -91,7 +85,9 @@ function NoteScreenInner({ route, account }: Props & { account: Account }) {
{noteFetch.isFetching && <Spinner />}
{noteFetch.error && <TextError>{noteFetch.error.message}</TextError>}
{noteStatus && (
<NoteDisplay {...{ account, noteStatus: { ...noteStatus, link } }} />
<NoteDisplayInner
{...{ account, noteStatus: { ...noteStatus, link } }}
/>
)}
</ScrollView>
</View>
Expand Down Expand Up @@ -144,7 +140,7 @@ function NoteDisplayInner({
const nonce = useMemo(() => new DaimoNonce(nonceMetadata), [ephemeralOwner]);

const isV2RecipientClaim =
noteStatus.contractAddress === daimoEphemeralNotesV2Address &&
noteStatus.link.type === "notev2" &&
noteStatus.sender.addr !== account.address;
const rpcFunc = env(daimoChainFromId(account.homeChainId)).rpcFunc;
const customHandler = isV2RecipientClaim
Expand All @@ -165,7 +161,7 @@ function NoteDisplayInner({
nonce,
chainGasConstants: account.chainGasConstants,
};
if (noteStatus.contractAddress === daimoEphemeralNotesAddress) {
if (noteStatus.contractAddress === opSender.opConfig.notesAddressV1) {
console.log(`[ACTION] claiming note ${ephemeralOwner}`);
return opSender.claimEphemeralNoteV1(
ephemeralOwner,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ function getNext(
case "create-invite":
return (input) => {
const { isTestnet } = assertNotNull(input);
setDaimoChain(assertNotNull(isTestnet) ? "baseGoerli" : "base");
setDaimoChain(assertNotNull(isTestnet) ? "baseSepolia" : "base");

if (Platform.OS !== "android") goToPage("create");
else goToPage("create-try-enclave");
Expand Down
13 changes: 8 additions & 5 deletions apps/daimo-mobile/src/view/screen/send/NoteActionButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import {
DaimoNoteState,
EAccount,
OpStatus,
assertNotNull,
dollarsToAmount,
formatDaimoLink,
generateNoteSeedAddress,
getNoteId,
} from "@daimo/common";
import { daimoEphemeralNotesV2Address } from "@daimo/contract";
import { notesV2AddressMap } from "@daimo/contract";
import {
DaimoNonce,
DaimoNonceMetadata,
Expand Down Expand Up @@ -65,8 +66,10 @@ function NoteActionButtonInner({
() => new DaimoNonce(new DaimoNonceMetadata(DaimoNonceType.CreateNote))
);

const notesV2Addr = assertNotNull(notesV2AddressMap.get(account.homeChainId));

const notesV2isApproved = account.recentTransfers.some(
(op) => op.type === "createLink" && op.to === daimoEphemeralNotesV2Address
(op) => op.type === "createLink" && op.to === notesV2Addr
);

const { status, message, cost, exec } = useSendAsync({
Expand All @@ -86,7 +89,7 @@ function NoteActionButtonInner({
type: "createLink",
status: OpStatus.pending,
from: account.address,
to: daimoEphemeralNotesV2Address,
to: notesV2Addr,
amount: Number(dollarsToAmount(dollars)),
timestamp: Date.now() / 1e3,
nonceMetadata: nonce.metadata.toHex(),
Expand All @@ -101,14 +104,14 @@ function NoteActionButtonInner({
status: DaimoNoteState.Pending,
sender: { addr: account.address, name: account.name },
dollars: `${dollars}`,
contractAddress: daimoEphemeralNotesV2Address,
contractAddress: notesV2Addr,
ephemeralOwner: noteAddress,
id: noteId,
},
},
accountTransform: transferAccountTransform([
{
addr: daimoEphemeralNotesV2Address,
addr: notesV2Addr,
label: AddrLabel.PaymentLink,
} as EAccount,
]),
Expand Down
2 changes: 1 addition & 1 deletion apps/daimo-mobile/test/account.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const account: Account = {
name: "test",
address: "0x0000000000000000000000000000000000000123",

homeChainId: 84531, // Base Goerli
homeChainId: 84531, // Base Goerli (old testnet)
homeCoinAddress: "0x1B85deDe8178E18CdE599B4C9d913534553C3dBf",

lastBalance: BigInt(123),
Expand Down
21 changes: 13 additions & 8 deletions apps/daimo-web/src/components/AppOrWalletCTA.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import {
DaimoNoteStatus,
DaimoRequestStatus,
assert,
assertNotNull,
getNoteClaimSignature,
getNoteClaimSignatureFromSeed,
} from "@daimo/common";
import {
daimoEphemeralNotesConfig,
daimoEphemeralNotesV2Address,
daimoEphemeralNotesV2Config,
daimoEphemeralNotesABI,
daimoEphemeralNotesV2ABI,
notesV1AddressMap,
notesV2AddressMap,
} from "@daimo/contract";
import { ConnectButton } from "@rainbow-me/rainbowkit";
import { useEffect, useMemo, useState } from "react";
Expand Down Expand Up @@ -216,6 +218,8 @@ async function linkStatusToAction(
selfAddress: Address,
urlHash: string
): Promise<Action> {
const chainId = chainConfig.chainL2.id;

switch (linkStatus.link.type) {
case "request": {
const { recipient } = linkStatus as DaimoRequestStatus;
Expand All @@ -234,8 +238,7 @@ async function linkStatusToAction(
}
case "note":
case "notev2": {
const { sender, contractAddress, ephemeralOwner } =
linkStatus as DaimoNoteStatus;
const { sender, ephemeralOwner } = linkStatus as DaimoNoteStatus;

const signature = await getNoteSignature(
linkStatus.link.type,
Expand All @@ -244,22 +247,24 @@ async function linkStatusToAction(
urlHash
);

if (contractAddress === daimoEphemeralNotesV2Address) {
if (linkStatus.link.type === "notev2") {
assert(
selfAddress !== sender.addr,
"sender shouldn't be claiming their own note on web"
);
return {
wagmiPrep: {
...daimoEphemeralNotesV2Config,
abi: daimoEphemeralNotesV2ABI,
address: assertNotNull(notesV2AddressMap.get(chainId)),
functionName: "claimNoteRecipient" as const,
args: [ephemeralOwner, selfAddress, signature] as const,
},
};
} else {
return {
wagmiPrep: {
...daimoEphemeralNotesConfig,
abi: daimoEphemeralNotesABI,
address: assertNotNull(notesV1AddressMap.get(chainId)),
functionName: "claimNote" as const,
args: [ephemeralOwner, signature] as const,
},
Expand Down
2 changes: 1 addition & 1 deletion apps/daimo-web/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import { DaimoChain, getChainConfig } from "@daimo/contract";

// || prevents build failures during CI
export const chainConfig = getChainConfig(
(process.env.NEXT_PUBLIC_DAIMO_CHAIN || "baseGoerli") as DaimoChain
(process.env.NEXT_PUBLIC_DAIMO_CHAIN || "baseSepolia") as DaimoChain
);
Loading

0 comments on commit 890e511

Please sign in to comment.