Skip to content

Commit

Permalink
Merge branch 'v2-release-nov-15' of https://github.com/warbler-labs/mono
Browse files Browse the repository at this point in the history
 into feature/liquidity-mining
  • Loading branch information
landakram committed Nov 18, 2021
2 parents 3e3d212 + 34c8afc commit 1094ead
Show file tree
Hide file tree
Showing 47 changed files with 949 additions and 323 deletions.
8 changes: 7 additions & 1 deletion .solhint.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
"drawdown": []
},
"**/TranchedPool.sol:TranchedPool": {
"setAllowedUIDTypes": ["onlyLocker"],
"deposit": ["whenNotPaused"],
"depositWithPermit": [],
"lockJuniorCapital": ["whenNotPaused", "onlyLocker"],
Expand Down Expand Up @@ -144,7 +145,12 @@
"grant": ["nonReentrant", "whenNotPaused", "onlyDistributor"],
"getReward": []
},
"**/PoolRewards.sol:PoolRewards": {
"**/Go.sol:Go": {
"go": [],
"goOnlyIdTypes": [],
"goSeniorPool": []
},
"**/BackerRewards.sol:BackerRewards": {
"allocateRewards": ["onlyPool"],
"setPoolTokenAccRewardsPerPrincipalDollarAtMint": [],
"withdraw": [],
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"test": "npx lerna run test --stream",
"test:client": "npm run test -- --scope @goldfinch-eng/client",
"test:protocol": "npm run test -- --scope @goldfinch-eng/protocol",
"test:autotasks": "npm run test -- --scope @goldfinch-eng/autotasks",
"lint": "npx lerna run lint --no-bail",
"lint:fix": "npx lerna run lint:fix --no-bail",
"prepare": "husky install",
Expand Down
5 changes: 4 additions & 1 deletion packages/autotasks/test/unique-identity-signer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {TestUniqueIdentityInstance} from "packages/protocol/typechain/truffle"
import {UniqueIdentity} from "packages/protocol/typechain/ethers"
import {FetchKYCFunction, KYC} from "../unique-identity-signer"

const TEST_TIMEOUT = 30000

function fetchStubbedKycStatus(kyc: KYC): FetchKYCFunction {
return async (_) => {
return Promise.resolve(kyc)
Expand Down Expand Up @@ -180,6 +182,7 @@ describe("unique-identity-signer", () => {
"x-goldfinch-signature": "test_signature",
"x-goldfinch-signature-block-num": "fake_block_number",
}
await uniqueIdentity.setSupportedUIDTypes([0], [true])

let result = await uniqueIdentitySigner.main({
auth,
Expand All @@ -206,7 +209,7 @@ describe("unique-identity-signer", () => {

await uniqueIdentity.burn(anotherUser, 0, result.expiresAt, result.signature, {from: anotherUser})
expect(await uniqueIdentity.balanceOf(anotherUser, 0)).to.bignumber.eq(new BN(0))
})
}).timeout(TEST_TIMEOUT)
})
})
})
2 changes: 1 addition & 1 deletion packages/autotasks/unique-identity-signer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export async function main({
const expiresAt = currentBlock.timestamp + SIGNATURE_EXPIRY_IN_SECONDS
const userAddress = auth["x-goldfinch-address"]
const nonce = await uniqueIdentity.nonces(userAddress)
const idVersion = await uniqueIdentity.ID_VERSION_0()
const idVersion = await uniqueIdentity.ID_TYPE_0()
const signTypes = ["address", "uint256", "uint256", "address", "uint256", "uint256"]
const signParams = [userAddress, idVersion, expiresAt, uniqueIdentity.address, nonce, network.chainId]
const encoded = pack(signTypes, signParams)
Expand Down
Binary file modified packages/client/public/icons/cauris.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion packages/client/src/components/verifyIdentity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ function CreateUID({disabled, dispatch}: {disabled: boolean; dispatch: React.Dis
user,
})
const uniqueIdentity = goldfinchProtocol.getContract<UniqueIdentityContract>("UniqueIdentity")
const version = await uniqueIdentity.methods.ID_VERSION_0().call(undefined, currentBlock.number)
const version = await uniqueIdentity.methods.ID_TYPE_0().call(undefined, currentBlock.number)
await sendFromUser(
uniqueIdentity.methods.mint(version, trustedSignature.expiresAt, trustedSignature.signature),
{
Expand Down
141 changes: 81 additions & 60 deletions packages/protocol/blockchain_scripts/baseDeploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ import {isMerkleDistributorInfo} from "./merkle/merkleDistributor/types"
import {
CommunityRewardsInstance,
GoInstance,
PoolRewardsInstance,
BackerRewardsInstance,
StakingRewardsInstance,
UniqueIdentityInstance,
MerkleDistributorInstance,
TestERC20Instance,
Expand All @@ -56,11 +57,11 @@ import {
} from "../typechain/truffle"
import {assertIsString, assertNonNullable} from "@goldfinch-eng/utils"
import {StakingRewards} from "../typechain/ethers/StakingRewards"
import {PoolRewards} from "../typechain/ethers/PoolRewards"
import {BackerRewards} from "../typechain/ethers/BackerRewards"
import {UNIQUE_IDENTITY_METADATA_URI} from "./uniqueIdentity/constants"
import {toEthers} from "../test/testHelpers"
import {getDeployEffects, DeployEffects} from "./migrations/deployEffects"
import {TestPoolRewards} from "../typechain/ethers/TestPoolRewards"
import {TestBackerRewards} from "../typechain/ethers/TestBackerRewards"
import {isMerkleDirectDistributorInfo} from "./merkle/merkleDirectDistributor/types"

const logger: Logger = console.log
Expand Down Expand Up @@ -105,7 +106,6 @@ const baseDeploy: DeployFunction = async function (hre: HardhatRuntimeEnvironmen

const gfi = await deployGFI(deployer, {config})
await deployLPStakingRewards(deployer, {config})
await deployPoolRewards(deployer, {config})
const communityRewards = await deployCommunityRewards(deployer, {config})
await deployMerkleDistributor(deployer, {communityRewards})
await deployMerkleDirectDistributor(deployer, {gfi})
Expand All @@ -114,7 +114,8 @@ const baseDeploy: DeployFunction = async function (hre: HardhatRuntimeEnvironmen
assertNonNullable(trustedSigner)
const uniqueIdentity = await deployUniqueIdentity({deployer, trustedSigner, deployEffects})

const go = await deployGo(deployer, {configAddress: config.address, uniqueIdentity, deployEffects})
await deployGo(deployer, {configAddress: config.address, uniqueIdentity, deployEffects})
await deployBackerRewards(deployer, {configAddress: config.address, deployEffects})

logger("Granting ownership of Pool to CreditDesk")
await grantOwnershipOfPoolToCreditDesk(pool, creditDesk.address)
Expand All @@ -123,28 +124,6 @@ const baseDeploy: DeployFunction = async function (hre: HardhatRuntimeEnvironmen

// Internal functions.

async function deployConfig(deployer: ContractDeployer): Promise<GoldfinchConfig> {
let contractName = "GoldfinchConfig"

if (isTestEnv()) {
contractName = "TestGoldfinchConfig"
}

assertIsString(gf_deployer)
const config = await deployer.deploy<GoldfinchConfig>(contractName, {from: gf_deployer})
const checkAddress = await config.getAddress(CONFIG_KEYS.TreasuryReserve)
if (checkAddress === ZERO_ADDRESS) {
logger("Config newly deployed, initializing...")
const protocol_owner = await getProtocolOwner()
assertIsString(protocol_owner)
await (await config.initialize(protocol_owner)).wait()
}

await setInitialConfigVals(config, logger)

return config
}

async function getOrDeployUSDC(deployer: ContractDeployer) {
assertIsChainId(chainId)
let usdcAddress = getUSDCAddress(chainId)
Expand Down Expand Up @@ -296,10 +275,11 @@ const baseDeploy: DeployFunction = async function (hre: HardhatRuntimeEnvironmen
deployer: ContractDeployer,
{config}: {config: GoldfinchConfig}
): Promise<StakingRewards> {
const contractName = "StakingRewards"
logger("About to deploy LPStakingRewards...")
assertIsString(gf_deployer)
const protocol_owner = await getProtocolOwner()
const stakingRewards = await deployer.deploy<StakingRewards>("StakingRewards", {
const stakingRewards = await deployer.deploy<StakingRewards>(contractName, {
from: gf_deployer,
gasLimit: 4000000,
proxy: {
Expand All @@ -311,42 +291,14 @@ const baseDeploy: DeployFunction = async function (hre: HardhatRuntimeEnvironmen
},
},
})
return stakingRewards
}

async function deployPoolRewards(
deployer: ContractDeployer,
{config}: {config: GoldfinchConfig}
): Promise<PoolRewards | TestPoolRewards> {
let contractName = "PoolRewards"
console.log("isTestEnv", isTestEnv())
if (isTestEnv()) {
contractName = "TestPoolRewards"
}
logger("About to deploy PoolRewards...")
assertIsString(gf_deployer)
const protocol_owner = await getProtocolOwner()
const poolRewards = await deployer.deploy<PoolRewards>(contractName, {
from: gf_deployer,
gasLimit: 4000000,
proxy: {
execute: {
init: {
methodName: "__initialize__",
args: [protocol_owner, config.address],
},
},
},
})
const contract = await getTruffleContract<StakingRewardsInstance>("StakingRewards", {at: stakingRewards.address})

const contract = await getContract<PoolRewards, PoolRewardsInstance>(contractName, TRUFFLE_CONTRACT_PROVIDER, {
at: poolRewards.address,
})
logger("Updating config...")
await updateConfig(config, "address", CONFIG_KEYS.PoolRewards, contract.address, {logger})
logger("Updated PoolRewards config address to:", contract.address)
await updateConfig(config, "address", CONFIG_KEYS.StakingRewards, contract.address, {logger})
logger("Updated StakingRewards config address to:", contract.address)

return poolRewards
return stakingRewards
}

async function deployCommunityRewards(
Expand Down Expand Up @@ -480,6 +432,29 @@ const baseDeploy: DeployFunction = async function (hre: HardhatRuntimeEnvironmen
}
}

export async function deployConfig(deployer: ContractDeployer): Promise<GoldfinchConfig> {
const {gf_deployer} = await deployer.getNamedAccounts()
let contractName = "GoldfinchConfig"

if (isTestEnv()) {
contractName = "TestGoldfinchConfig"
}

assertIsString(gf_deployer)
const config = await deployer.deploy<GoldfinchConfig>(contractName, {from: gf_deployer})
const checkAddress = await config.getAddress(CONFIG_KEYS.TreasuryReserve)
if (checkAddress === ZERO_ADDRESS) {
logger("Config newly deployed, initializing...")
const protocol_owner = await getProtocolOwner()
assertIsString(protocol_owner)
await (await config.initialize(protocol_owner)).wait()
}

await setInitialConfigVals(config, logger)

return config
}

export async function deployUniqueIdentity({
deployer,
trustedSigner,
Expand Down Expand Up @@ -523,6 +498,51 @@ export async function deployUniqueIdentity({
}
}

async function deployBackerRewards(
deployer: ContractDeployer,
{
configAddress,
deployEffects,
}: {
configAddress: string
deployEffects: DeployEffects
}
): Promise<BackerRewardsInstance> {
const {gf_deployer} = await deployer.getNamedAccounts()
let contractName = "BackerRewards"
if (isTestEnv()) {
contractName = "TestBackerRewards"
}
logger("About to deploy BackerRewards...")
assertIsString(gf_deployer)
const protocol_owner = await getProtocolOwner()
const backerRewards = await deployer.deploy<BackerRewards>(contractName, {
from: gf_deployer,
gasLimit: 4000000,
proxy: {
owner: protocol_owner,
execute: {
init: {
methodName: "__initialize__",
args: [protocol_owner, configAddress],
},
},
},
})

const contract = await getTruffleContract<BackerRewardsInstance>("BackerRewards", {at: backerRewards.address})

const goldfinchConfig = await getEthersContract<GoldfinchConfig>("GoldfinchConfig", {at: configAddress})

logger("Updating config...")
await deployEffects.add({
deferred: [await goldfinchConfig.populateTransaction.setAddress(CONFIG_KEYS.BackerRewards, contract.address)],
})
logger("Updated BackerRewards config address to:", contract.address)

return contract
}

export async function deployGo(
deployer: ContractDeployer,
{
Expand Down Expand Up @@ -822,6 +842,7 @@ async function deployBorrower(deployer: ContractDeployer, {config}: DeployOpts):
export {
baseDeploy,
deployPoolTokens,
deployBackerRewards,
deployTransferRestrictedVault,
deployTranchedPool,
deploySeniorPool,
Expand Down
3 changes: 2 additions & 1 deletion packages/protocol/blockchain_scripts/configKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ const CONFIG_KEYS_BY_TYPE = {
BorrowerImplementation: 17,
GFI: 18,
Go: 19,
PoolRewards: 20,
BackerRewards: 20,
StakingRewards: 21,
},
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {DeployOptions, DeployResult} from "hardhat-deploy/types"
import {Contract, BaseContract} from "ethers"

import {Logger} from "../types"
import {getProtocolOwner} from "./"

export class ContractDeployer {
public readonly logger: Logger
Expand All @@ -24,6 +25,10 @@ export class ContractDeployer {
}

async deploy<T extends BaseContract | Contract = Contract>(contractName: string, options: DeployOptions): Promise<T> {
if (typeof options === "object" && typeof options?.proxy === "object" && options?.proxy && !options?.proxy?.owner) {
const protocol_owner = await getProtocolOwner()
options = {proxy: {owner: protocol_owner, ...options.proxy}, ...options}
}
const result = await this.hre.deployments.deploy(contractName, options)
this.logger(`${contractName} was deployed to: ${result.address}`)
return (await ethers.getContractAt(result.abi, result.address)) as T
Expand Down
6 changes: 3 additions & 3 deletions packages/protocol/blockchain_scripts/deployHelpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {AdminClient} from "defender-admin-client"
import PROTOCOL_CONFIG from "../../protocol_config.json"
import {CONFIG_KEYS} from "../configKeys"
import {GoldfinchConfig} from "../../typechain/ethers"
import {DeploymentsExtension, DeployResult, DeployOptions} from "hardhat-deploy/types"
import {DeploymentsExtension} from "hardhat-deploy/types"
import {Contract, BaseContract, Signer} from "ethers"
import {
AssertionError,
Expand All @@ -36,8 +36,6 @@ import {
genExhaustiveTuple,
} from "@goldfinch-eng/utils"
import {getExistingContracts, MAINNET_MULTISIG} from "../mainnetForkingHelpers"
import {HardhatRuntimeEnvironment} from "hardhat/types"
import {Logger} from "../types"

import {ContractDeployer} from "./contractDeployer"
import {ContractUpgrader} from "./contractUpgrader"
Expand Down Expand Up @@ -345,8 +343,10 @@ function getDefenderClient() {
}

const ETHERS_CONTRACT_PROVIDER = "ethers"
// eslint-disable-next-line @typescript-eslint/no-redeclare
type ETHERS_CONTRACT_PROVIDER = typeof ETHERS_CONTRACT_PROVIDER
const TRUFFLE_CONTRACT_PROVIDER = "truffle"
// eslint-disable-next-line @typescript-eslint/no-redeclare
type TRUFFLE_CONTRACT_PROVIDER = typeof TRUFFLE_CONTRACT_PROVIDER
type ContractProvider = ETHERS_CONTRACT_PROVIDER | TRUFFLE_CONTRACT_PROVIDER

Expand Down
8 changes: 7 additions & 1 deletion packages/protocol/blockchain_scripts/fixAlmaCreditLine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,13 @@ async function main() {
assertIsChainId(chainId)
const deployer = new ContractDeployer(console.log, hre)
const existingContracts = await getExistingContracts(contractsToUpgrade, owner, chainId)
const upgradedContracts = await upgradeContracts(contractsToUpgrade, existingContracts, owner, gf_deployer, deployer)
const upgradedContracts = await upgradeContracts({
contractsToUpgrade,
contracts: existingContracts,
signer: owner,
deployFrom: gf_deployer,
deployer,
})

const goldfinchFactoryAddress = asNonNullable(upgradedContracts.GoldfinchFactory).ProxyContract.address
const goldfinchFactory = await getContract<GoldfinchFactory, GoldfinchFactoryInstance>(
Expand Down
Loading

0 comments on commit 1094ead

Please sign in to comment.