Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2025 Bond Labs

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ cd apps/dapp
pnpm test:open
```

### Enabling new Chains

- Check examples under `packages/contract-library/src/deployments` for the configuration structure
- Update `../deployments/(mainnets/testnets)/index.ts` to include the newly added deployment configuration
- If oracle markets or fixed expiry is available, add it to `dapp/.../create-market/config.ts`

## Useful Links

[Turbopack](https://turbo.build/repo/docs)
Expand Down
16 changes: 5 additions & 11 deletions apps/dapp/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Bond Protocol dApp

## Dev setup (for now)
## Dev setup

```bash
pnpm install
Expand All @@ -15,9 +15,6 @@ pnpm build
pnpm preview
```

> [!WARNING]
> App still need the [caching API](https://github.com/Bond-Protocol/api) to be running in order to work, this should be deprecated in a near future

## Testing

E2E tests are setup using cypress and require a running foundry/anvil node.
Expand All @@ -38,11 +35,8 @@ pnpm test:run # Headless mode
pnpm test:open # Open browser mode -- useful for development
```

### New Chain Deployment Setup
### Enabling new Chains

- Add addresses to `packages/contract-library/.../address-provider.tsx`
- Add chain to `CHAIN_ID` enum in `packages/types/.../chains.ts`
- Add chain to `dapp/.../blockchain-provider.tsx`
- Add subgraph to `dapp/.../services/subgraph-endpoints.ts`
- Add chain handlers for defillama/coingecko to `dapp/.../defillama`
- If oracle markets are not available, add it to `dapp/.../create-market/config.ts`
- Check examples under `packages/contract-library/src/deployments` for the configuration structure
- Update `../deployments/(mainnets/testnets)/index.ts` to include the newly added deployment configuration
- If oracle markets or fixed expiry is available, add it to `dapp/.../create-market/config.ts`
3 changes: 2 additions & 1 deletion apps/dapp/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ dotenv.config();

const config: CodegenConfig = {
overwrite: true,
schema: process.env.VITE_SUBGRAPH_CODEGEN_SCHEMA_ENDPOINT,
schema:
"https://api.studio.thegraph.com/query/47265/bond-protocol-base/version/latest",
documents: "src/graphql/queries.gql",
config: {
legacyMode: false,
Expand Down
2 changes: 1 addition & 1 deletion apps/dapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"@tanstack/react-query": "^5.8.9",
"@wagmi/chains": "^1.8.0",
"@wagmi/core": "^1.4.12",
"axios": "^1.6.0",
"axios": "^1.7.4",
"buffer": "^6.0.3",
"cypress": "^14.1.0",
"date-fns": "2.30",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ import {
useWaitForTransaction,
} from "wagmi";
import * as contractLib from "@bond-protocol/contract-library";
import { BondType, CHAIN_ID, CreateMarketParams } from "@bond-protocol/types";
import { BondType, CreateMarketParams } from "@bond-protocol/types";
import {
checkOraclePairValidity,
getBlockExplorer,
getOracleDecimals,
getOraclePrice,
getTeller,
getAuctioneerForCreate,
} from "@bond-protocol/contract-library";
import {
CreateMarketAction,
Expand All @@ -28,6 +27,7 @@ import { useTokens } from "hooks";
import { parseUnits, formatUnits } from "viem";
import { useAllowance } from "hooks/contracts/useAllowance";
import { useCreateMarket as useCreateMarketContract } from "hooks/contracts/useCreateMarket";
import { mainnet } from "@wagmi/chains";

export const CreateMarketController = () => {
const [creationHash, setCreationHash] = useState<Address>();
Expand Down Expand Up @@ -364,7 +364,7 @@ export function getBondType(state: CreateMarketState) {
SDA v1.1 has not been deployed to Ethereum Mainnet
It has been deployed to Goerli, but using the old SDA contracts for consistency
*/
if (chainId === CHAIN_ID.ETHEREUM_MAINNET) {
if (chainId === mainnet.id.toString()) {
return state.vestingType === "term"
? BondType.FIXED_TERM_SDA
: BondType.FIXED_EXPIRY_SDA;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
import { Address } from "viem";
import { Token } from "@bond-protocol/types";
import { getBlockExplorer } from "@bond-protocol/contract-library";
import { unavailableFixedExpiry } from "./config";
import { availableFixedExpiry } from "./config";

export type CreateMarketScreenProps = {
projectionData: Array<PriceData>;
Expand Down Expand Up @@ -221,9 +221,9 @@ export const CreateMarketScreen = (props: CreateMarketScreenProps) => {
ModalContent={(props) => (
<SelectVestingDialog
{...props}
disableFixedExpiry={unavailableFixedExpiry.includes(
state.chainId
)}
disableFixedExpiry={
!availableFixedExpiry.includes(state.chainId)
}
/>
)}
onSubmit={({ value }) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { PriceModelDetails } from "./PriceModelDetails";
import { PriceModel, PriceType } from "./create-market-reducer";
import { PriceControl, PriceControlProps } from "./PriceControl";
import { useNetwork } from "wagmi";
import { unavailableOracleChains } from "./config";
import { availableOracleChains } from "./config";
import { featureToggles } from "src/feature-toggles";

export type PriceModelPickerProps = {
Expand Down Expand Up @@ -128,7 +128,7 @@ export const PriceModelPicker = (props: PriceModelPickerProps) => {
<div className="flex items-center justify-between">
<p className="text-sm text-light-grey-400">Price Model</p>
{featureToggles.ORACLE_BONDS ? (
props.chain && !unavailableOracleChains.includes(props.chain) ? (
props.chain && availableOracleChains.includes(props.chain) ? (
<Switch
label="Oracle"
onChange={(e) => {
Expand Down
8 changes: 4 additions & 4 deletions apps/dapp/src/components/modules/create-market/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** Chains where the Oracle Auctioneers are not avaiable*/
export const unavailableOracleChains = [1, 8453, 84532, 56, 34443];
/** Chains where the Oracle Auctioneers are avaiable*/
export const availableOracleChains = [42161, 10, 137];

/** Chains where the Fixed Expiry Auctioneers are not avaiable*/
export const unavailableFixedExpiry = [34443, 80084];
/** Chains where the Fixed Expiry Auctioneers are avaiable*/
export const availableFixedExpiry = [1, 10, 42161, 56];
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { calculateTrimDigits, trimAsNumber, formatDate } from "formatters";
import { createContext, Dispatch, useContext, useReducer } from "react";
import { differenceInCalendarDays } from "date-fns";
import { formatUnits, parseUnits } from "viem";
import { parseUnits } from "viem";
import { switchNetwork } from "@wagmi/core";
import { unavailableOracleChains } from "./config";
import { availableOracleChains } from "./config";

const DEFAULT_DEPOSIT_INTERVAL = 86400;
const DEFAULT_DEBT_BUFFER = 75;
Expand Down Expand Up @@ -198,11 +198,7 @@ function calculateAllowance(
let payoutTokenPrice = payoutToken.price;

if (state.priceModel === "static") {
if (
state.priceModels?.static?.fixedPrice &&
!payoutToken.price &&
capacityType === "quote"
) {
if (state.priceModels?.static?.fixedPrice && !payoutToken.price) {
payoutTokenPrice = state.priceModels?.static?.fixedPrice;
} else if (!payoutToken.price) {
return {
Expand Down Expand Up @@ -272,7 +268,7 @@ export const reducer = (

switchNetwork({ chainId });

const oracleUnavailable = unavailableOracleChains.includes(chainId);
const oracleUnavailable = !availableOracleChains.includes(chainId);

return {
...state,
Expand Down
3 changes: 3 additions & 0 deletions apps/dapp/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,6 @@ export const testnetSubgraphs =
"https://subgraph.satsuma-prod.com/35414fbc50a7/spaces-team/bond-protocol-base-sepolia/api",
}
: {};

// Key is domain restricted to *.bondprotocol.finance
export const GRAPH_API_KEY = "70873ff55ac0869c81ba8a128ef5e786";
2 changes: 1 addition & 1 deletion apps/dapp/src/config/auto-signer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { WalletClient } from "wagmi";
import { baseSepolia, foundry } from "viem/chains";
import { custom, createWalletClient, Account, Address } from "viem";
import { custom, createWalletClient, Address } from "viem";
import { Connector } from "wagmi";
import { injectAutoSignerProvider } from "@axis-finance/auto-signer-provider";
import { privateKeyToAccount } from "viem/accounts";
Expand Down
21 changes: 8 additions & 13 deletions apps/dapp/src/config/chains.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
import { arbitrum, mainnet, optimism, polygon, base } from "@wagmi/chains";
import { environment } from "src/environment";
import { getIconsForChains } from "src/utils/get-icons-for-chains";
import { Chain, baseSepolia, bsc } from "viem/chains";
import { sonic } from "@bond-protocol/contract-library";
import { Chain } from "viem/chains";
import { mainnetDeployments } from "@bond-protocol/contract-library/src/deployments/mainnets";
import { testnetDeployments } from "@bond-protocol/contract-library/src/deployments/testnets";

type _Chain = Chain & { logoUrl?: string };
export const TESTNETS = [baseSepolia].map(getIconsForChains);

export const MAINNETS = [
mainnet,
arbitrum,
optimism,
polygon,
base,
bsc,
sonic,
];
export const TESTNETS = testnetDeployments
.map((d) => d.chain)
.map(getIconsForChains);

export const MAINNETS = mainnetDeployments.map((d) => d.chain);

export const SUPPORTED_CHAINS = [...TESTNETS, ...MAINNETS];
export const ACTIVE_CHAINS: _Chain[] = environment.isTestnet
Expand Down
54 changes: 6 additions & 48 deletions apps/dapp/src/config/public-clients.ts
Original file line number Diff line number Diff line change
@@ -1,56 +1,14 @@
import {
arbitrum,
arbitrumGoerli,
mainnet,
optimism,
polygon,
base,
} from "@wagmi/chains";
import { environment } from "src/environment";
import { ANVIL_RPC_URL } from "./auto-signer";
import { PublicClient, createPublicClient, http } from "viem";
import { baseSepolia, bsc } from "viem/chains";
import { sonic } from "@bond-protocol/contract-library";
import { baseSepolia } from "viem/chains";
import { deployments } from "@bond-protocol/contract-library";
const key = import.meta.env.VITE_ALCHEMY_RPC_KEY;

const rpcConfigs = [
{
chain: mainnet,
endpoint: ` https://eth-mainnet.g.alchemy.com/v2/${key}`,
},
{
chain: arbitrumGoerli,
endpoint: `https://arb-goerli.g.alchemy.com/v2/${key}`,
},
{
chain: arbitrum,
endpoint: `https://arb-mainnet.g.alchemy.com/v2/${key}`,
},
{
chain: optimism,
endpoint: `https://opt-mainnet.g.alchemy.com/v2/${key}`,
},
{
chain: polygon,
endpoint: `https://polygon-mainnet.g.alchemy.com/v2/${key}`,
},
{
chain: base,
endpoint: `https://base-mainnet.g.alchemy.com/v2/${key}`,
},
{
chain: baseSepolia,
endpoint: `https://base-sepolia.g.alchemy.com/v2/${key}`,
},
{
chain: sonic,
endpoint: `https://sonic-mainnet.g.alchemy.com/v2/${key}`,
},
{
chain: bsc,
endpoint: `https://bnb-mainnet.g.alchemy.com/v2/${key}`,
},
];
const rpcConfigs = deployments.map((d) => ({
chain: d.chain,
endpoint: d.getRpcURL(key),
}));

const testRpcConfigs = [
{
Expand Down
Loading
Loading