Skip to content

Commit

Permalink
feat/aurora (#250)
Browse files Browse the repository at this point in the history
* deploy on aurora

* clean up bond natspec

* create, test, and deploy BridgeWrapper on aurora

* more aurora stuff

* deploy on polygon and mumbai
  • Loading branch information
leonardishere authored Feb 10, 2022
1 parent 8e9415a commit a137589
Show file tree
Hide file tree
Showing 23 changed files with 5,966 additions and 93 deletions.
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ KOVAN_URL=https://eth-kovan.alchemyapi.io/v2/<api_key>
GOERLI_URL=https://eth-goerli.alchemyapi.io/v2/<api_key>
AURORA_URL=https://mainnet.aurora.dev
AURORA_TESTNET_URL=https://testnet.aurora.dev
POLYGON_URL=https://polygon-mainnet.g.alchemy.com/v2/<api_key>
MUMBAI_URL=https://polygon-mumbai.g.alchemy.com/v2/<api_key>
MAINNET_ACCOUNTS=[ "<account1_private_key>", "<account2_private_key>", "etc" ]
RINKEBY_ACCOUNTS=[ "<account1_private_key>", "<account2_private_key>", "etc" ]
KOVAN_ACCOUNTS=[ "<account1_private_key>", "<account2_private_key>", "etc" ]
GOERLI_ACCOUNTS=[ "<account1_private_key>", "<account2_private_key>", "etc" ]
AURORA_ACCOUNTS=[ "<account1_private_key>", "<account2_private_key>", "etc" ]
AURORA_TESTNET_ACCOUNTS=[ "<account1_private_key>", "<account2_private_key>", "etc" ]
POLYGON_ACCOUNTS=[ "<account1_private_key>", "<account2_private_key>", "etc" ]
MUMBAI_ACCOUNTS=[ "<account1_private_key>", "<account2_private_key>", "etc" ]
LOCALHOST_ACCOUNTS=[ "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" ]
USE_PROCESSED_FILES=<true or false, default false>
FORK_NETWORK=<one of mainnet, rinkeby, kovan, goerli, aurora, or aurora_testnet>
Expand Down
746 changes: 746 additions & 0 deletions contracts/WMATIC.sol

Large diffs are not rendered by default.

588 changes: 588 additions & 0 deletions contracts/bonds/BondTellerMatic.sol

Large diffs are not rendered by default.

735 changes: 735 additions & 0 deletions contracts/interfaces/IWMATIC.sol

Large diffs are not rendered by default.

213 changes: 213 additions & 0 deletions contracts/interfaces/bonds/IBondTellerMatic.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.6;


/**
* @title IBondTellerMatic
* @author solace.fi
* @notice A bond teller that accepts **MATIC** and **WMATIC** as payment.
*
* Bond tellers allow users to buy bonds. Payments are made in **MATIC** or **WMATIC** which is sent to the underwriting pool and used to back risk. Users will receive [**SOLACE**](./../../SOLACE) but it must be bonded or staked. If bonded, the [**SOLACE**](./../../SOLACE) will be vested linearly and redeemed over time. If staked, the [**SOLACE**](./../../SOLACE) only be withdrawable after the lock expires but will give the user extra [**SOLACE**](./../../SOLACE) rewards and voting rights.
*
* Bonds can be purchased via [`depositMatic()`](#depositeth), [`depositWmatic()`](#depositwmatic), or [`depositWmaticSigned()`](#depositwmaticsigned). Bonds are represented as ERC721s, can be viewed with [`bonds()`](#bonds), and redeemed with [`claimRewards()`](#claimrewards). If staked, an [`xsLocker`](./../../staking/xsLocker) lock is created instead of a bond.
*/
interface IBondTellerMatic {

/***************************************
EVENTS
***************************************/

/// @notice Emitted when a bond is created.
event CreateBond(uint256 indexed lockID, uint256 principalAmount, uint256 payoutAmount, uint40 vestingStart, uint40 vestingTime);
/// @notice Emitted when a bond is redeemed.
event RedeemBond(uint256 indexed bondID, address recipient, uint256 payoutAmount);
/// @notice Emitted when deposits are paused.
event Paused();
/// @notice Emitted when deposits are unpaused.
event Unpaused();
/// @notice Emitted when terms are set.
event TermsSet();
/// @notice Emitted when fees are set.
event FeesSet();
/// @notice Emitted when fees are set.
event AddressesSet();

/***************************************
INITIALIZER
***************************************/

/**
* @notice Initializes the teller.
* @param name_ The name of the bond token.
* @param governance_ The address of the [governor](/docs/protocol/governance).
* @param solace_ The [**SOLACE**](./../../SOLACE) token.
* @param xsLocker_ The [**xsLocker**](./../../staking/xsLocker) contract.
* @param pool_ The underwriting pool.
* @param dao_ The DAO.
* @param principal_ The ERC20 token that users deposit.
* @param isPermittable_ True if `principal` supports `EIP2612`.
* @param bondDepo_ The bond depository.
*/
function initialize(
string memory name_,
address governance_,
address solace_,
address xsLocker_,
address pool_,
address dao_,
address principal_,
bool isPermittable_,
address bondDepo_
) external;

/***************************************
VIEW FUNCTIONS
***************************************/

// BOND PRICE

/**
* @notice Calculate the current price of a bond.
* Assumes 1 [**SOLACE**](./../../SOLACE) payout.
* @return price_ The price of the bond measured in `principal`.
*/
function bondPrice() external view returns (uint256 price_);

/**
* @notice Calculate the amount of [**SOLACE**](./../../SOLACE) out for an amount of `principal`.
* @param amountIn Amount of principal to deposit.
* @param stake True to stake, false to not stake.
* @return amountOut Amount of [**SOLACE**](./../../SOLACE) out.
*/
function calculateAmountOut(uint256 amountIn, bool stake) external view returns (uint256 amountOut);

/**
* @notice Calculate the amount of `principal` in for an amount of [**SOLACE**](./../../SOLACE) out.
* @param amountOut Amount of [**SOLACE**](./../../SOLACE) out.
* @param stake True to stake, false to not stake.
* @return amountIn Amount of principal to deposit.
*/
function calculateAmountIn(uint256 amountOut, bool stake) external view returns (uint256 amountIn);

/***************************************
BONDER FUNCTIONS
***************************************/

/**
* @notice Create a bond by depositing **MATIC**.
* Principal will be transferred from `msg.sender` using `allowance`.
* @param minAmountOut The minimum [**SOLACE**](./../../SOLACE) out.
* @param depositor The bond recipient, default msg.sender.
* @param stake True to stake, false to not stake.
* @return payout The amount of [**SOLACE**](./../../SOLACE) in the bond.
* @return tokenID The ID of the newly created bond or lock.
*/
function depositMatic(
uint256 minAmountOut,
address depositor,
bool stake
) external payable returns (uint256 payout, uint256 tokenID);

/**
* @notice Create a bond by depositing `amount` **WMATIC**.
* **WMATIC** will be transferred from `msg.sender` using `allowance`.
* @param amount Amount of **WMATIC** to deposit.
* @param minAmountOut The minimum [**SOLACE**](./../../SOLACE) out.
* @param depositor The bond recipient, default msg.sender.
* @param stake True to stake, false to not stake.
* @return payout The amount of [**SOLACE**](./../../SOLACE) in the bond.
* @return tokenID The ID of the newly created bond or lock.
*/
function depositWmatic(
uint256 amount,
uint256 minAmountOut,
address depositor,
bool stake
) external returns (uint256 payout, uint256 tokenID);

/**
* @notice Create a bond by depositing `amount` **WMATIC**.
* **WMATIC** will be transferred from `depositor` using `permit`.
* Note that not all **WMATIC**s have a permit function, in which case this function will revert.
* @param amount Amount of **WMATIC** to deposit.
* @param minAmountOut The minimum [**SOLACE**](./../../SOLACE) out.
* @param depositor The bond recipient, default msg.sender.
* @param stake True to stake, false to not stake.
* @param deadline Time the transaction must go through before.
* @param v secp256k1 signature
* @param r secp256k1 signature
* @param s secp256k1 signature
* @return payout The amount of [**SOLACE**](./../../SOLACE) in the bond.
* @return tokenID The ID of the newly created bond or lock.
*/
function depositWmaticSigned(
uint256 amount,
uint256 minAmountOut,
address depositor,
bool stake,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external returns (uint256 payout, uint256 tokenID);

/**
* @notice Claim payout for a bond that the user holds.
* User calling `claimPayout()` must be either the owner or approved for the entered bondID.
* @param bondID The ID of the bond to redeem.
*/
function claimPayout(uint256 bondID) external;

/***************************************
GOVERNANCE FUNCTIONS
***************************************/

/**
* @notice Pauses deposits.
* Can only be called by the current [**governor**](/docs/protocol/governance).
*/
function pause() external;

/**
* @notice Unpauses deposits.
* Can only be called by the current [**governor**](/docs/protocol/governance).
*/
function unpause() external;

/**
* @notice Sets the addresses to call out.
* Can only be called by the current [**governor**](/docs/protocol/governance).
* @param solace_ The [**SOLACE**](./../../SOLACE) token.
* @param xsLocker_ The [**xsLocker**](./../../staking/xsLocker) contract.
* @param pool_ The underwriting pool.
* @param dao_ The DAO.
* @param principal_ The ERC20 token that users deposit.
* @param isPermittable_ True if `principal` supports `EIP2612`.
* @param bondDepo_ The bond depository.
*/
function setAddresses(
address solace_,
address xsLocker_,
address pool_,
address dao_,
address principal_,
bool isPermittable_,
address bondDepo_
) external;

/***************************************
FALLBACK FUNCTIONS
***************************************/

/**
* @notice Fallback function to allow contract to receive *MATIC*.
* Deposits **MATIC** and creates bond.
*/
receive () external payable;

/**
* @notice Fallback function to allow contract to receive **MATIC**.
* Deposits **MATIC** and creates bond.
*/
fallback () external payable;
}
14 changes: 14 additions & 0 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ const kovan_fork = { url: process.env.KOVAN_URL || '', blockNumber: 28627875 };
const goerli_fork = { url: process.env.GOERLI_URL || '', blockNumber: 6267645 };
const aurora_fork = { url: process.env.AURORA_URL || '' };
const aurora_testnet_fork = { url: process.env.AURORA_TESTNET_URL || '' };
const polygon_fork = { url: process.env.POLYGON_URL || '', blockNumber: 24525000 };
const mumbai_fork = { url: process.env.MUMBAI_URL || '', blockNumber: 24529352 };
const no_fork = undefined;
const forking = (
process.env.FORK_NETWORK === "mainnet" ? mainnet_fork
Expand All @@ -27,6 +29,8 @@ const forking = (
: process.env.FORK_NETWORK === "goerli" ? goerli_fork
: process.env.FORK_NETWORK === "aurora" ? aurora_fork
: process.env.FORK_NETWORK === "aurora_testnet" ? aurora_testnet_fork
: process.env.FORK_NETWORK === "polygon" ? polygon_fork
: process.env.FORK_NETWORK === "mumbai" ? mumbai_fork
: no_fork
);

Expand Down Expand Up @@ -71,6 +75,16 @@ const config: HardhatUserConfig = {
chainId: 1313161555,
accounts: JSON.parse(process.env.AURORA_TESTNET_ACCOUNTS || '[]')
},
polygon: {
url: process.env.POLYGON_URL || '',
chainId: 137,
accounts: JSON.parse(process.env.POLYGON_ACCOUNTS || '[]')
},
mumbai: {
url: process.env.MUMBAI_URL || '',
chainId: 80001,
accounts: JSON.parse(process.env.MUMBAI_ACCOUNTS || '[]')
},
},
solidity: {
compilers: [
Expand Down
18 changes: 14 additions & 4 deletions scripts/bondHash.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import hardhat from "hardhat";
const { ethers } = hardhat;
import { BigNumber as BN } from "ethers";

const DAI_BOND_TELLER_ADDRESS = "0x501ACe677634Fd09A876E88126076933b686967a";

Expand All @@ -16,12 +17,17 @@ let found: any[] = [
// SCP
{"salt":"0x000000000000000000000000000000000000000000000000000000000244cea9","address":"0x501ACe00FD8e5dB7C3be5e6D254ba4995e1B45b7"},
// FRAX
{"salt":"0x0000000000000000000000000000000000000000000000000000000002e3569f","address":"0x501aCef4F8397413C33B13cB39670aD2f17BfE62"}
{"salt":"0x0000000000000000000000000000000000000000000000000000000002e3569f","address":"0x501aCef4F8397413C33B13cB39670aD2f17BfE62"},
// WETH (used on chains where eth is not native token)
{"salt":"0x0000000000000000000000000000000000000000000000000000000003ba0308","address":"0x501Ace367f1865DEa154236D5A8016B80a49e8a9"},
// NEAR
{"salt":"0x0000000000000000000000000000000000000000000000000000000004843332","address":"0x501aCe71a83CBE03B1467a6ffEaeB58645d844b4"},
// AURORA
{"salt":"0x0000000000000000000000000000000000000000000000000000000005201ba9","address":"0x501Ace35f0B7Fad91C199824B8Fe555ee9037AA3"}
]

let numToFind = 5;
let lastSalt = 48453279;
let nextSalt = 0;
let numToFind = 8;
let nextSalt = 62522121;
let maxSalt = 72057594037927936;

async function main () {
Expand All @@ -34,6 +40,10 @@ async function main () {
let initCode = `0x3d602d80600a3d3981f3363d3d373d3d3d363d73${DAI_BOND_TELLER_ADDRESS.substring(2)}5af43d82803e903d91602b57fd5bf3`;
// hash the initCode
var initCodeHash = keccak256(initCode);
// no redundant salts
for(var i = 0; i < found.length; ++i) {
nextSalt = Math.max(nextSalt, BN.from(found[i].salt).toNumber()+1);
}
// loop over possible salts
for (var i = nextSalt; i < maxSalt; i++) {
var saltToBytes = '0x'+i.toString(16).padStart(64, '0');
Expand Down
13 changes: 11 additions & 2 deletions scripts/bondHashAuroraTestnet.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import hardhat from "hardhat";
const { ethers } = hardhat;
import { BigNumber as BN } from "ethers";

const DAI_BOND_TELLER_ADDRESS = "0x501acED0B949D96B3289A1b37791cA8bD93B0D65";

Expand All @@ -14,10 +15,14 @@ let found: any[] = [
// USDT
{"salt":"0x0000000000000000000000000000000000000000000000000000000003b1f978","address":"0x501aCEa6ff6dcE05D108D616cE886AF74f00EAAa"},
// FRAX
{"salt":"0x0000000000000000000000000000000000000000000000000000000003de1cf9","address":"0x501acE87fF4E7A1498320ABB674a4960A87792E4"}
{"salt":"0x0000000000000000000000000000000000000000000000000000000003de1cf9","address":"0x501acE87fF4E7A1498320ABB674a4960A87792E4"},
// NEAR
{"salt":"0x0000000000000000000000000000000000000000000000000000000004373f7d","address":"0x501AcE9D730dcf60d6bbD1FDDca9c1b69CAF0A61"},
// AURORA
{"salt":"0x0000000000000000000000000000000000000000000000000000000004d104f9","address":"0x501ACef4fDF8C0597aA40b5Cb82035FFe5Ad3552"},
]

let numToFind = 4;
let numToFind = 6;
let nextSalt = 64888058;
let maxSalt = 72057594037927936;

Expand All @@ -31,6 +36,10 @@ async function main () {
let initCode = `0x3d602d80600a3d3981f3363d3d373d3d3d363d73${DAI_BOND_TELLER_ADDRESS.substring(2)}5af43d82803e903d91602b57fd5bf3`;
// hash the initCode
var initCodeHash = keccak256(initCode);
// no redundant salts
for(var i = 0; i < found.length; ++i) {
nextSalt = Math.max(nextSalt, BN.from(found[i].salt).toNumber()+1);
}
// loop over possible salts
for (var i = nextSalt; i < maxSalt; i++) {
var saltToBytes = '0x'+i.toString(16).padStart(64, '0');
Expand Down
Loading

0 comments on commit a137589

Please sign in to comment.