-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7ce52ce
commit 7698bd5
Showing
13 changed files
with
194 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,17 @@ | ||
export const rpId = | ||
process.env.EXPO_PUBLIC_URL ?? | ||
/* eslint-disable @typescript-eslint/no-unnecessary-type-assertion -- prevents typescript-eslint issues */ | ||
|
||
export const rpId = (process.env.EXPO_PUBLIC_URL ?? | ||
(process.env.VERCEL_ENV === "production" | ||
? process.env.VERCEL_PROJECT_PRODUCTION_URL | ||
: process.env.VERCEL_BRANCH_URL) ?? | ||
"localhost"; | ||
"localhost") as string; | ||
|
||
export { optimismSepolia as chain } from "@alchemy/aa-core"; | ||
|
||
if (!process.env.EXPO_PUBLIC_ALCHEMY_API_KEY) throw new Error("missing alchemy api key"); | ||
if (!process.env.EXPO_PUBLIC_ALCHEMY_GAS_POLICY_ID) throw new Error("missing alchemy gas policy"); | ||
|
||
export const alchemyAPIKey = process.env.EXPO_PUBLIC_ALCHEMY_API_KEY as string; | ||
export const alchemyGasPolicyId = process.env.EXPO_PUBLIC_ALCHEMY_GAS_POLICY_ID as string; | ||
|
||
/* eslint-enable @typescript-eslint/no-unnecessary-type-assertion */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
pragma solidity ^0.8.17; | ||
|
||
import { Script, stdJson } from "forge-std/Script.sol"; | ||
import { StdAssertions } from "forge-std/StdAssertions.sol"; | ||
import { Vm } from "forge-std/Vm.sol"; // solhint-disable-line no-unused-import | ||
|
||
abstract contract BaseScript is Script, StdAssertions { | ||
using stdJson for string; | ||
|
||
function protocol(string memory name) internal returns (address addr) { | ||
addr = vm.readFile(string.concat("../../node_modules/@exactly/protocol/deployments/", chain(), "/", name, ".json")) | ||
.readAddress(".address"); | ||
vm.label(addr, name); | ||
|
||
address impl = | ||
address(uint160(uint256(vm.load(addr, bytes32(uint256(keccak256("eip1967.proxy.implementation")) - 1))))); | ||
if (impl != address(0)) { | ||
vm.label(impl, string.concat(name, "_Impl")); | ||
} else if (bytes10(addr.code) == 0x363d3d373d3d3d363d73) { | ||
vm.label(address(uint160(uint240(bytes30(addr.code)))), string.concat(name, "_Impl")); | ||
} | ||
} | ||
|
||
function chain() internal returns (string memory) { | ||
if (block.chainid == 11_155_420) return "op-sepolia"; | ||
return getChain(block.chainid).chainAlias; | ||
} | ||
} | ||
|
||
interface IProxy { | ||
function implementation() external returns (address); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// SPDX-License-Identifier: AGPL-3.0 | ||
pragma solidity ^0.8.0; | ||
|
||
import { LibString } from "solady/utils/LibString.sol"; | ||
|
||
import { ACCOUNT_IMPL, ENTRYPOINT } from "webauthn-owner-plugin/../script/Deploy.s.sol"; | ||
import { WebauthnOwnerPlugin } from "webauthn-owner-plugin/WebauthnOwnerPlugin.sol"; | ||
|
||
import { ExaAccountFactory } from "../src/ExaAccountFactory.sol"; | ||
import { ExaPlugin, IAuditor } from "../src/ExaPlugin.sol"; | ||
|
||
import { BaseScript, stdJson, Vm } from "./Base.s.sol"; | ||
|
||
contract DeployScript is BaseScript { | ||
using LibString for uint256; | ||
using stdJson for string; | ||
|
||
ExaAccountFactory public factory; | ||
ExaPlugin public exaPlugin; | ||
WebauthnOwnerPlugin public ownerPlugin; | ||
IAuditor public auditor; | ||
|
||
function setUp() external { | ||
Vm.DirEntry[] memory broadcasts = vm.readDir( | ||
string.concat("../../node_modules/webauthn-owner-plugin/broadcast/Deploy.s.sol/", block.chainid.toString()) | ||
); | ||
ownerPlugin = WebauthnOwnerPlugin( | ||
payable(vm.readFile(broadcasts[broadcasts.length - 1].path).readAddress(".transactions[0].contractAddress")) | ||
); | ||
auditor = IAuditor(protocol("Auditor")); | ||
} | ||
|
||
function run() external { | ||
assert(msg.sender != DEFAULT_SENDER); | ||
|
||
vm.startBroadcast(msg.sender); | ||
|
||
exaPlugin = new ExaPlugin(auditor, msg.sender); | ||
factory = new ExaAccountFactory(msg.sender, ownerPlugin, exaPlugin, ACCOUNT_IMPL, ENTRYPOINT); | ||
|
||
factory.addStake{ value: 0.1 ether }(1 days, 0.1 ether); | ||
|
||
exaPlugin.grantRole(exaPlugin.KEEPER_ROLE(), msg.sender); | ||
|
||
vm.stopBroadcast(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import type { VercelRequest, VercelResponse } from "@vercel/node"; | ||
import * as v from "valibot"; | ||
|
||
// import client from "../utils/chainClient.js"; | ||
|
||
export default function handler({ method, body, headers }: VercelRequest, response: VercelResponse) { | ||
if (method !== "POST") return response.status(405).end("method not allowed"); | ||
|
||
const payload = v.safeParse(Payload, body || placeholderPayload); | ||
console.dir(payload, { depth: null }); // eslint-disable-line no-console, unicorn/no-null | ||
if (!payload.success) return response.status(400).json(payload); // HACK for debugging | ||
|
||
// const { amount } = payload.output.data; | ||
|
||
// console.log(await client.simulateContract({})); | ||
|
||
return response.json({ response_code: "69" }); | ||
} | ||
|
||
const Payload = v.variant("event_type", [ | ||
v.object({ | ||
event_type: v.literal("AUTHORIZATION"), | ||
status: v.literal("PENDING"), | ||
product: v.literal("CARDS"), | ||
operation_id: v.string(), | ||
data: v.object({ | ||
card_id: v.string(), | ||
amount: v.number(), | ||
currency_number: v.literal(840), | ||
currency_code: v.literal("USD"), | ||
exchange_rate: v.null(), | ||
channel: v.picklist(["ECOMMERCE", "POS", "ATM", "Visa Direct"]), | ||
created_at: v.pipe(v.string(), v.isoTimestamp()), | ||
fees: v.object({ atm_fees: v.number(), fx_fees: v.number() }), | ||
merchant_data: v.object({ | ||
id: v.string(), | ||
name: v.string(), | ||
city: v.string(), | ||
post_code: v.nullable(v.string()), | ||
state: v.nullable(v.string()), | ||
country: v.string(), | ||
mcc_category: v.string(), | ||
mcc_code: v.string(), | ||
}), | ||
}), | ||
}), | ||
]); | ||
type Payload = v.InferOutput<typeof Payload>; // eslint-disable-line @typescript-eslint/no-redeclare | ||
|
||
/* eslint-disable unicorn/no-null */ | ||
const placeholderPayload = { | ||
event_type: "AUTHORIZATION", | ||
status: "PENDING", | ||
product: "CARDS", | ||
operation_id: "1b013f33-15e6-4073-9699-7b63c1146b1d", | ||
data: { | ||
card_id: "111fdf0f-9521-403e-a53d-874319243df1", | ||
amount: 0.1, | ||
currency_number: 840, | ||
currency_code: "USD", | ||
exchange_rate: null, | ||
channel: "ECOMMERCE", | ||
created_at: "2024-07-05T19:03:13.485Z", | ||
fees: { atm_fees: 0, fx_fees: 0 }, | ||
merchant_data: { | ||
id: "311178830000", | ||
name: "Reap", | ||
city: "www.reap.global", | ||
post_code: null, | ||
state: null, | ||
country: "HK", | ||
mcc_category: "Electronics Stores", | ||
mcc_code: "5732", | ||
}, | ||
}, | ||
}; | ||
/* eslint-enable unicorn/no-null */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { alchemyAPIKey, chain } from "@exactly/common/constants.js"; | ||
import { Hash } from "@exactly/common/types.js"; | ||
import { parse } from "valibot"; | ||
import { createClient, http, publicActions, walletActions } from "viem"; | ||
import { privateKeyToAccount } from "viem/accounts"; | ||
|
||
if (!chain.rpcUrls.alchemy?.http[0]) throw new Error("missing alchemy rpc url"); | ||
|
||
export default createClient({ | ||
chain, | ||
account: privateKeyToAccount(parse(Hash, process.env.PRIVATE_KEY, { message: "invalid private key" })), | ||
transport: http(`${chain.rpcUrls.alchemy.http[0]}/${alchemyAPIKey}`), | ||
}) | ||
.extend(publicActions) | ||
.extend(walletActions); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,4 @@ | ||
import { rpId } from "@exactly/common/constants"; | ||
|
||
if (!process.env.EXPO_PUBLIC_ALCHEMY_API_KEY) throw new Error("missing alchemy api key"); | ||
if (!process.env.EXPO_PUBLIC_ALCHEMY_GAS_POLICY_ID) throw new Error("missing alchemy gas policy"); | ||
|
||
export const apiURL = rpId === "localhost" ? "http://localhost:3000/api" : `https://${rpId}/api`; | ||
export const alchemyAPIKey = process.env.EXPO_PUBLIC_ALCHEMY_API_KEY; | ||
export const alchemyGasPolicyId = process.env.EXPO_PUBLIC_ALCHEMY_GAS_POLICY_ID; | ||
export const oneSignalAppId = process.env.EXPO_PUBLIC_ONE_SIGNAL_APP_ID; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters