# Bonding Curve

## **Introduction**

This guide focusses on the most common patterns of interactions with the Bonding Curve Modules. Please refer to the [Technical Reference](https://docs.inverter.network/contracts/technical-reference/modules/funding-manager/bonding-curve/fm_bc_bancor_redeeming_virtualsupply_v1.sol) section to see all public getters and setters.

## **Setup Requirements**

The guide includes code snippets for Inverter Network's TypeScript SDK. Please refer to the relevant code snippets based on the SDK you are using.

1. **Set up Inverter Network SDK**: Refer to the Quick Start guides for detailed instructions. See the [React SDK Guide](https://docs.inverter.network/sdk/react-sdk) or [TypeScript SDK Guide](https://docs.inverter.network/sdk/typescript-sdk) for more information.
2. **Deploy a Workflow**: Refer to the Deploy a Workflow guide for detailed instructions. See the [React SDK Guide ](https://docs.inverter.network/sdk/react-sdk/deploy-a-workflow)or [TypeScript SDK Guide](https://docs.inverter.network/sdk/typescript-sdk/deploy-a-workflow) for more information.
3. **Retrieve a deployed Workflow**: Refer to the Operate a Workflow guide for detailed instructions. See the [React SDK Guide](https://docs.inverter.network/sdk/react-sdk/operate-a-workflow) or [TypeScript SDK Guide](https://docs.inverter.network/sdk/typescript-sdk/operate-a-workflow) for more information.

* **Optionally if your setup needs a specific contract**: Refer to the Deploy a Contract Guide for detailed instructions. See the [React SDK](https://docs.inverter.network/sdk/react-sdk/deploy-a-contract) Guide or [TypeScript SDK](https://docs.inverter.network/sdk/typescript-sdk/deploy-a-contract) Guide for more information.

Bancor formula and supported chains can be found here: <https://github.com/InverterNetwork/deployments/tree/main/deployments>&#x20;

### Deployment Setup

* Deploy the `Issuance Token`
* Deploy the `Workflow`
* Retrieve the `Workflow`

### Post Deployment: Set the Curve as a minter

In order to perform this action you should be the deployer of the token

```typescript
await workflow.issuanceToken.module.write.setMinter([
    workflow.fundingManager.address, true
], { confirmations: 1 })
```

### Admin Actions

These actions can be preformed by the workflow admin role

```typescript
// Close/Open Buy/Sell
await workflow.fundingManager.write.closeBuy.run()
await workflow.fundingManager.write.openBuy.run()
await workflow.fundingManager.write.closeSell.run()
await workflow.fundingManager.write.openSell.run()

// Grant/Revoke Workflow Admin Role
const adminRole = await workflow.authorizer.read.DEFAULT_ADMIN_ROLE.run()
await workflow.authorizer.write.grantRole.run([adminRole, deployer])
await workflow.authorizer.write.revokeRole.run([adminRole, deployer])

// Fee Withdrawal
await workflow.fundingManager.write.withdrawProjectCollateralFee.run([
  '<address>' as `0x${string}`,
  '1000', // amount
])

// Update Parameters
await workflow.fundingManager.write.setBuyFee.run(
  '1000' // Fee in ( BPS ) Basis Points
)
await workflow.fundingManager.write.setSellFee.run(
  '1000' // Fee in ( BPS ) Basis Points
)
await workflow.fundingManager.write.setReserveRatioForBuying.run(
  333_333 // Reserve Ratio in ( PPM ) Parts Per Million
)
await workflow.fundingManager.write.setReserveRatioForSelling.run(
  333_333 // Reserve Ratio in ( PPM ) Parts Per Million
)
 await workflow.fundingManager.write.setVirtualCollateralSupply.run(
  '1000' // New Virtual Collateral Supply
)
await workflow.fundingManager.write.setVirtualIssuanceSupply.run(
  '1000' // New Virtual Issuance Supply
)
```

### Curve Actions

These actions can be performed by the users of the product | app. The bonding curve funding managers have a calculate function which uses the formula contract to define the minimum amount out from either buy or sell method.

```typescript
// Buy/Sell

// Amount to buy
const purchaseAmount = '1000'
// Min amount received from the buy
const purchaseReturn =
  await workflow.fundingManager.read.calculatePurchaseReturn.run(
    purchaseAmount
  )

// Buy using the connected account
await workflow.fundingManager.write.buy.run([
  purchaseAmount,
  purchaseReturn,
])
// Buy for another account
await workflow.fundingManager.write.buyFor.run([
  '<address>' as `0x${string}`,
  purchaseAmount,
  purchaseReturn,
])

// Amount to sell
const saleAmount = '1000'
// Min amount out of the sell
const saleReturn =
  await workflow.fundingManager.read.calculateSaleReturn.run(saleAmount)

// Sell using the connected account
await workflow.fundingManager.write.sell.run([saleAmount, saleReturn])
// Sell to another account
await workflow.fundingManager.write.sellTo.run([
  '<address>' as `0x${string}`,
  saleAmount,
  saleReturn,
])
```
