import { CrossmintWallets, createCrossmint } from "@crossmint/wallets-sdk"
import { EVMWallet } from "@crossmint/client-sdk-react-ui"
import {
createWalletClient,
custom,
http,
MethodNotFoundRpcError,
type EIP1193RequestFn,
} from "viem"
import { tempoModerato } from "viem/chains"
import { Mppx, tempo } from "mppx/client"
const crossmint = createCrossmint({
apiKey: process.env.CROSSMINT_SERVER_API_KEY!,
})
const crossmintWallets = CrossmintWallets.from(crossmint)
const wallet = await crossmintWallets.getWallet(
process.env.CROSSMINT_WALLET_ADDRESS!,
{ chain: "base" },
)
await wallet.useSigner({
type: "server",
secret: process.env.CROSSMINT_SIGNER_SECRET!,
})
const evmWallet = EVMWallet.from(wallet)
const httpTransport = http()
const request: EIP1193RequestFn = async ({ method, params }) => {
if (method === "wallet_sendCalls") {
throw new MethodNotFoundRpcError(new Error("not implemented"))
}
if (method === "eth_sendTransaction") {
const [tx] = params as Array<{
to: `0x${string}`
data?: `0x${string}`
value?: `0x${string}`
}>
const sent = await evmWallet.sendTransaction({
to: tx.to,
data: tx.data ?? "0x",
value: tx.value ? BigInt(tx.value) : undefined,
})
return sent.hash as `0x${string}`
}
return httpTransport.request({ method, params } as any)
}
const walletClient = createWalletClient({
account: evmWallet.address as `0x${string}`,
chain: tempoModerato,
transport: custom({ request }),
})
const mppx = Mppx.create({
polyfill: false,
methods: [tempo({ mode: "push", getClient: () => walletClient as any })],
})
const res = await mppx.fetch(
"https://www.remlo.xyz/api/mpp/treasury/yield-rates",
)