Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement simple bond contract + add details to bond section of technical spec #4

Closed
RusseII opened this issue Jan 24, 2022 · 18 comments · Fixed by #12
Closed

Implement simple bond contract + add details to bond section of technical spec #4

RusseII opened this issue Jan 24, 2022 · 18 comments · Fixed by #12

Comments

@RusseII
Copy link
Contributor

RusseII commented Jan 24, 2022

Current info about bondtoken here - #1

It may help if we start with the simplest design - no factories - no convertibility - no upgradability -imagine we want to create just a simple bond token.

  1. The state of the bond needs to be managed.
  • What is the interest?
  • When is the payment due?
  • How much is owed?
  • What is the current state of the bond? (good standing, defaulted)
  1. The borrowing party needs a way to pay back the bond
  2. The lending parties need a way to redeem their bonds for interest + principle at maturity (edited)
@RusseII RusseII changed the title Write bond contract + fill bond section of technical spec Implement simple bond contract + fill bond section of technical spec Jan 24, 2022
@RusseII RusseII changed the title Implement simple bond contract + fill bond section of technical spec Implement simple bond contract + add details to bond section of technical spec Jan 24, 2022
@luckyrobot
Copy link

can we fork someone else's bond contract / dao to jumpstart our own? here's some examples i found 🤔

  1. https://github.com/BarnBridge/BarnBridge-SmartYieldBonds

  2. https://github.com/XBEfinance/SmartBond

  3. https://compound.finance/docs

BarnBridge even has a whole frontend we can use, that includes governance among a ton of other super cool features

https://github.com/BarnBridge/barnbridge-frontend

i gave it a local run and it looks cool too

image

@RusseII
Copy link
Contributor Author

RusseII commented Jan 25, 2022

can we fork someone else's bond contract / dao to jumpstart our own? here's some examples i found 🤔

I'm not sure how we would - our bond is a zero coupon bond without interest rates. SmartBond seems to be a bond that pays interest. Barnbridge seems significantly more complex than we need.
Looking at the compound cTokens implementation is good - our minting/burning process will probably be similar to theirs.

Barnbride junior/senior bond might be a good example though - https://github.com/BarnBridge/BarnBridge-SmartYieldBonds/blob/master/contracts/JuniorBond.sol
Actually their bonds are ERC-721s not ERC20s so not a good example

We'd want to inherit from open zepplin ERC20 token

More info about our bond token:
https://github.com/porter-finance/litepaper#bond-implementation

@RusseII
Copy link
Contributor Author

RusseII commented Jan 25, 2022

can we fork someone else's bond contract / dao to jumpstart our own? here's some examples i found 🤔

We will be forking gnosis auction for DAOs to perform the debt auction and sell their debt.

After an auction is cleared - we will need to deploy a new bond contract and send the bond tokens to the investors who had winning bids

@luckyrobot
Copy link

this one looks cool https://github.com/SamuelSchlesinger/erc20-bond

@luckyrobot
Copy link

our bond is a zero coupon bond without interest rates

this is a little confusing, our bond spec sheet shows several mentions of an interest rate

APR cap. Maximum interest rate issuer is willing to pay
The debt offering is structured as a batch auction where bidders submit public bids with their desired allocation and interest rate

so can people specify the interest rate they want on a bond or no? since it's imputed interest, shouldn't they only be allowed to bid on a bond's price? the par value will always be the same, and the interest rate will automatically calculate between bond price <> face value <> maturity date

Price = M ÷ (1 + r)n

Price is the offered value of the bond at auction (supplied by auction, that they bid on, with highest bid being the winner)
M is maturity value or face value (supplied by auction)
r is automatically calculated by us as the interest rate (supplied by auction)
n is numbers of years until maturity (supplied by bond issuer? or is this also what they're bidding on during auction?)

does this sound right?

@RusseII
Copy link
Contributor Author

RusseII commented Jan 27, 2022

this is a little confusing, our bond spec sheet shows several mentions of an interest rate

The original plan was to have actual interest payment but was changed - so language might be a bit confusing there. The plan for v1 is only zero coupon bonds.

shouldn't they only be allowed to bid on a bond's price?

exactly.

so can people specify the interest rate they want on a bond or no?

No - it's based on the bond price and calculated automatically. It may be displayed to the user though to help them decide which price to bid - that'd be calculated on the frontend though.

Price is the offered value of the bond at auction (supplied by auction, that they bid on, with highest bid being the winner)

Price will be the settlement price from the batch auction - (info would be supplied by auction)

M is maturity value or face value (supplied by auction)

Face value per bond will always be $1

r is automatically calculated by us as the interest rate (supplied by auction)

Exactly. Calculated by Price = M ÷ (1 + r)n and solving for r with all the other data supplied.

n is numbers of years until maturity (supplied by bond issuer? or is this also what they're bidding on during auction?)

This would be supplied by the bond issuer

@luckyrobot
Copy link

luckyrobot commented Jan 27, 2022

so are we having 1 contract (ie, a published & deployed address) per $1 bond?

if someone auctions for $2000, they are purchasing 2000 bonds, thus 2000 addresses to deploy on mainnet?

or will 1 contract hold multiple "bonds", ie the ending bond value of $2000?


the $1 par value is confusing me on how to architect this.

here's what I had but now the yield doesn't make sense if it's always $1 ?

// Bond.sol

  constructor(
    // Name of this contract
    string _name,
    // The borrowed token address this bond is holding
    address _borrowedToken,
    // Desired borrow amount
    uint256 _borrowAmount,
    // Where to withdraw funds from to pay out the bond
    address _treasury,
    // Who to deposit funds to pay out the bond
    address _winner,
    // Amount of time until bond matures
    uint256 _termLength,
    // Amount and type of collateral securing debt
    address _collateralToken,
    uint256 _collateralAmount,
    /*
     * -- Convertibility --
     * Whether or not the bond will be redeemable for the collateral provided.
     *
     * Convertibility gives bond holders the option to redeem their bond for a prorated
     * share of the collateral provided at any time. This provides bond holders a call
     * option on the asset in the collateral contract with the breakeven price being determined
     * by the amount of the collateral and the price of the bond with respect to the collateral asset.
     */
    bool _convertable,
    // Total value at maturity
    uint256 _yield

@RusseII
Copy link
Contributor Author

RusseII commented Jan 27, 2022

so are we having 1 contract (ie, a published & deployed address) per $1 bond?

One bond contract would have X number of bonds that have a maturity of $1. (Each token is a bond)

or will 1 contract hold multiple "bonds", ie the ending bond value of $2000?

This is correct.

You can imagine that an auction ends with a clearing price of 80 cents per bond, with 2000 bonds sold. 2000 bonds would need to be minted and distributed to the winning bidders.

It may be worth learning on how gnosis auction works if you are not already familiar. The winning bidders will be receiving these bond tokens as the auctioningToken

Code meta feedback:

I think we should follow NatSpec for comments. Aave Example

Code feedback:

address _winner there will be multiple winners for each auction - also not sure if we need to store that here as it will be stored in the auction contract along with the amount. There will need to be a way to mint and transfer the tokens to the auction winners though.

uint256 _termLength is there a reason we want to store this over maturityTime and issuanceTime

address _treasury would we want to specify a specific address that can repay the loan? Or allow anyone to pay it? I know aave has a onBehalfOf parameter for paying off other address debts.

uint256 _yield You are right this probably doesn't make sense - but having a state variable like initiaInterestRate that's set after the auction has cleared using Price = M ÷ (1 + r)n might make sense. It also might not make sense if we are assuming bonds can be sold on a secondary market since the price people are willing to pay would constantly increase the closer the current date is to the maturity date.

@RusseII
Copy link
Contributor Author

RusseII commented Jan 27, 2022

@luckyrobot can you look into about how much gas it takes to deploy the bond contract you are working on? We will likely be deploying a new bond contract for each auction - so it'd be good to know how much gas is needed for that so we can estimate price.

I'm a bit confused about how much it'd cost as this stack overflow post says 3m gas but https://soliditydeveloper.com/clonefactory shows 212k gas

@luckyrobot
Copy link

@luckyrobot can you look into about how much gas it takes to deploy the bond contract you are working on? We will likely be deploying a new bond contract for each auction - so it'd be good to know how much gas is needed for that so we can estimate price.

I'm a bit confused about how much it'd cost as this stack overflow post says 3m gas but https://soliditydeveloper.com/clonefactory shows 212k gas

can do. i can either have tests for it first to calculate gas, or i'd have to build the whole contract and deploy in testnet to see gas (correct me if im wrong)

@RusseII
Copy link
Contributor Author

RusseII commented Jan 28, 2022

can do. i can either have tests for it first to calculate gas, or i'd have to build the whole contract and deploy in testnet to see gas (correct me if im wrong)

I'm not sure - I think hardhat has something build it that makes estimating gas easier tho.

Maybe https://hardhat.org/hardhat-network/reference/#eth-estimategas?

i'd have to build the whole contract and deploy in testnet

That's just running npx hardhat run scripts/deploy.ts right?

@luckyrobot
Copy link

can do. i can either have tests for it first to calculate gas, or i'd have to build the whole contract and deploy in testnet to see gas (correct me if im wrong)

I'm not sure - I think hardhat has something build it that makes estimating gas easier tho.

Maybe https://hardhat.org/hardhat-network/reference/#eth-estimategas?

i'd have to build the whole contract and deploy in testnet

That's just running npx hardhat run scripts/deploy.ts right?

right, but since the contract isn't finished, the gas wouldn't be accurate yet

@RusseII
Copy link
Contributor Author

RusseII commented Jan 28, 2022

right, but since the contract isn't finished, the gas wouldn't be accurate yet

That's true but I'm moreso looking for a very rough estimate vs exact amount

This was linked to pull requests Feb 3, 2022
Closed
@RusseII
Copy link
Contributor Author

RusseII commented Feb 3, 2022

https://ropsten.etherscan.io/tx/0x387efb77e56e0b3f6066c8a853464c9a4b1b24ffbf0d49a0063793168f058638

2,271,956 gas to deploy current bond contract ...

https://ropsten.etherscan.io/tx/0xc164917ff5f918aec456e8d9912bd40ea9fc2715a69177093b421a93c6d2c498
1,154,924 gas to deploy very basic bond token...

@ 100 gwei
100k gas = .01 eth
1m gas = .1 eth
10m gas = 1 eth

So ~ .2eth ($500) to deploy a bond contract - yikes!

@RusseII
Copy link
Contributor Author

RusseII commented Feb 3, 2022

So ~ .2eth ($500) to deploy a bond contract - yikes!

I wonder if we could use https://github.com/optionality/clone-factory

@luckyrobot
Copy link

clone factory looks dope, do you know how much gas it would save?

@RusseII
Copy link
Contributor Author

RusseII commented Feb 3, 2022

clone factory looks dope, do you know how much gas it would save?

Not sure - I made #15 to explore that question + alternatives. Once you finish up the 2 bond PRs can you look into it?

luckyrobot added a commit that referenced this issue Feb 7, 2022
* update bond methods

* remove commetned out code

* Apply suggestions from code review

Co-authored-by: Kyle <[email protected]>

* address comments

* burnfrom instead

* set maturity date from constructor

* pr fixes

* remove user

* apply bond standing

* apply bond standing

* shorter require msg

* fix tests

* (pr fix) variable renames

Co-authored-by: bookland <bookland.porter.finance>
Co-authored-by: luckyrobot <[email protected]>
Co-authored-by: Kyle <[email protected]>
luckyrobot added a commit that referenced this issue Feb 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants