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

Improvements after fitting to v3 #14

Merged
merged 13 commits into from
Oct 5, 2023
96 changes: 94 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.0.1",
"version": "1.2.2",
"sideEffects": false,
"main": "dist/index.js",
"module": "dist/index.js",
Expand All @@ -17,11 +17,10 @@
"graphql": "graphql-codegen && ts-node -O '{\"module\": \"commonjs\"}' ./scripts/generateGraphqlExports",
"rollup": "rollup --config rollup.config.ts --configPlugin @rollup/plugin-typescript --bundleConfigAsCjs"
},
"files": [
"dist/"
],
"exports": {
"default": "./dist/index.js"
".": "./dist/index.js",
"./abis/*": "./dist/abis/*",
"./abis": "./dist/abis/index.js"
},
"keywords": [
"ethereum",
Expand All @@ -31,7 +30,7 @@
"access": "public"
},
"peerDependencies": {
"ethers": "^6.6.7"
"ethers": "^6.7.1"
},
"devDependencies": {
"@graphql-codegen/cli": "5.0.0",
Expand Down Expand Up @@ -60,6 +59,7 @@
"jest-fetch-mock": "3.0.3",
"regenerator-runtime": "0.14.0",
"rollup": "3.29.1",
"rollup-plugin-copy": "3.5.0",
"rollup-plugin-delete": "2.0.0",
"rollup-plugin-dts": "6.0.2",
"rollup-plugin-peer-deps-external": "2.2.4",
Expand Down
6 changes: 6 additions & 0 deletions rollup.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import copy from 'rollup-plugin-copy'
import json from '@rollup/plugin-json'
import del from 'rollup-plugin-delete'
import { dts } from 'rollup-plugin-dts'
Expand Down Expand Up @@ -42,6 +43,11 @@ const config: RollupOptions[] = [
comments: false,
},
}),
copy({
targets: [
{ src: 'src/contracts/abis', dest: 'dist' },
],
}),
],
},
{
Expand Down
8 changes: 4 additions & 4 deletions src/StakeWiseSDK.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ type VaultMulticallInput = Pick<Parameters<typeof vaultMulticall>[0], 'request'

class StakeWiseSDK {
readonly utils: StakeWise.Utils
readonly config: StakeWise.Config
readonly options: StakeWise.Options
readonly provider: StakeWise.Provider
readonly vault: StakeWise.VaultMethods
readonly contracts: StakeWise.Contracts
readonly osToken: StakeWise.OsTokenMethods
Expand All @@ -18,7 +20,9 @@ class StakeWiseSDK {
const config = configs[options.network]
const provider = options.provider || new JsonRpcProvider(apiUrls.getWeb3Url(options))

this.config = config
this.options = options
this.provider = provider
this.rateContracts = this.#initRateContracts()
this.contracts = createContracts({ provider, config })

Expand Down Expand Up @@ -52,10 +56,6 @@ class StakeWiseSDK {
get network() {
return this.options.network
}

get provider() {
return this.options.provider
}
}


Expand Down
1 change: 1 addition & 0 deletions src/contracts/abis/VestingEscrowAbi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"claim","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"claimedAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"endTime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"startTime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"vestedAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}]
1 change: 1 addition & 0 deletions src/contracts/abis/VestingEscrowFactoryAbi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"admin","type":"address"},{"indexed":true,"internalType":"address","name":"token","type":"address"},{"indexed":true,"internalType":"address","name":"recipient","type":"address"},{"indexed":false,"internalType":"address","name":"beneficiary","type":"address"},{"indexed":false,"internalType":"address","name":"escrow","type":"address"},{"indexed":false,"internalType":"uint256","name":"totalAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"startTime","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"endTime","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"cliffLength","type":"uint256"}],"name":"VestingEscrowCreated","type":"event"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"total","type":"uint256"}],"stateMutability":"view","type":"function"}]
4 changes: 4 additions & 0 deletions src/contracts/abis/index.ts → src/contracts/abis/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import RewardSplitterFactoryAbi from './RewardSplitterFactoryAbi.json'
import VestingEscrowFactoryAbi from './VestingEscrowFactoryAbi.json'
import Erc20PrivateVaultAbi from './Erc20PrivateVaultAbi.json'
import MintTokenConfigAbi from './MintTokenConfigAbi.json'
import VaultsRegistryAbi from './VaultsRegistryAbi.json'
import RewardSplitterAbi from './RewardSplitterAbi.json'
import V2RewardTokenAbi from './V2RewardTokenAbi.json'
import VestingEscrowAbi from './VestingEscrowAbi.json'
import PrivateVaultAbi from './PrivateVaultAbi.json'
import VaultFactoryAbi from './VaultFactoryAbi.json'
import PriceOracleAbi from './PriceOracleAbi.json'
Expand All @@ -20,11 +22,13 @@ import Erc20Abi from './Erc20Abi.json'

export {
RewardSplitterFactoryAbi,
VestingEscrowFactoryAbi,
Erc20PrivateVaultAbi,
MintTokenConfigAbi,
VaultsRegistryAbi,
RewardSplitterAbi,
V2RewardTokenAbi,
VestingEscrowAbi,
PrivateVaultAbi,
VaultFactoryAbi,
PriceOracleAbi,
Expand Down
1 change: 1 addition & 0 deletions src/contracts/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export { default as createRatesContracts } from './createRatesContracts'
export { default as createContracts } from './createContracts'
export { default as vaultMulticall } from './vaultMulticall'
export { default as createContract } from './createContract'
export { default as multicall } from './multicall'
20 changes: 11 additions & 9 deletions src/contracts/vaultMulticall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ type VaultMulticallRequestInput = {
}>
callStatic?: boolean
estimateGas?: boolean
updateState?: boolean
}

type VaultMulticallInput = {
Expand All @@ -26,21 +25,24 @@ type VaultMulticallInput = {

const vaultMulticall = async <T extends unknown>(values: VaultMulticallInput): Promise<T> => {
const { options, vaultAddress, userAddress, request, vaultContract, keeperContract } = values
const { params, callStatic, estimateGas, updateState } = request
const { params, callStatic, estimateGas } = request

const calls: string[] = []

const config = configs[options.network]
const library = new JsonRpcProvider(config.network.url)

const signer = new VoidSigner(userAddress, library)
const signedContract = vaultContract.connect(signer)
const library = options.provider || new JsonRpcProvider(config.network.url)

const signer = options.provider
? await library.getSigner(userAddress)
: new VoidSigner(userAddress, library)

const harvestParams = await getHarvestParams({ options, vaultAddress })
const signedContract = vaultContract.connect(signer)

const canHarvest = updateState
? Object.values(harvestParams).every(Boolean)
: await keeperContract.canHarvest(vaultAddress)
const [ harvestParams, canHarvest ] = await Promise.all([
getHarvestParams({ options, vaultAddress }),
keeperContract.canHarvest(vaultAddress),
])

if (canHarvest) {
const fragment = signedContract.interface.encodeFunctionData('updateState', [ harvestParams ])
Expand Down
4 changes: 2 additions & 2 deletions src/graphql/subgraph/exitQueue/exitQueueQuery.graphql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
query exitQueue($owner: Bytes, $vault: String!) {
query exitQueue($receiver: Bytes, $vault: String!) {
exitRequests(where: {
owner: $owner,
receiver: $receiver,
vault: $vault,
}) {
positionTicket
Expand Down
1 change: 1 addition & 0 deletions src/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export * as constants from './constants'
export { default as apiUrls } from './apiUrls'
export { default as configs } from './configs'
export { default as BigDecimal } from './BigDecimal'
export { default as validateArgs } from './validateArgs'
42 changes: 42 additions & 0 deletions src/helpers/validateArgs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { isAddress } from 'ethers'


const bigint = (values: Record<string, bigint>) => {
Object.keys(values).forEach((key) => {
if (typeof values[key] !== 'bigint') {
throw new Error(`The "${key}" argument must be of type bigint`)
}
})
}

const address = (values: Record<string, string>) => {
Object.keys(values).forEach((key) => {
if (!isAddress(values[key])) {
throw new Error(`The "${key}" argument must be a valid address`)
}
})
}

const string = (values: Record<string, string>) => {
Object.keys(values).forEach((key) => {
if (typeof values[key] !== 'string') {
throw new Error(`The "${key}" argument must be a string`)
}
})
}

const number = (values: Record<string, number>) => {
Object.keys(values).forEach((key) => {
if (typeof values[key] !== 'number') {
throw new Error(`The "${key}" argument must be a number`)
}
})
}


export default {
bigint,
string,
number,
address,
}
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ import './types/global'


export * from 'helpers/enums'
export { createContract } from 'contracts'
export { BigDecimal, configs } from 'helpers'
export { default as StakeWiseSDK } from './StakeWiseSDK'
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { validateArgs } from 'helpers'


type GetBurnAmountInput = {
ltvPercent: bigint
mintedAssets: bigint
Expand All @@ -9,6 +12,8 @@ type GetBurnAmountInput = {
const getBurnAmount = async (values: GetBurnAmountInput) => {
const { contracts, ltvPercent, mintedAssets, stakedAssets, newStakedAssets } = values

validateArgs.bigint({ ltvPercent, mintedAssets, stakedAssets, newStakedAssets })

const hasMinted = mintedAssets && mintedAssets > 0

if (!hasMinted) {
Expand Down
4 changes: 3 additions & 1 deletion src/methods/osToken/helpers/getHealthFactor.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { OsTokenPositionHealth, BigDecimal } from 'helpers'
import { OsTokenPositionHealth, BigDecimal, validateArgs } from 'helpers'


type GetHealthFactorInput = {
Expand All @@ -10,6 +10,8 @@ type GetHealthFactorInput = {
const getHealthFactor = (values: GetHealthFactorInput) => {
const { mintedAssets, stakedAssets, thresholdPercent } = values

validateArgs.bigint({ mintedAssets, stakedAssets, thresholdPercent })

if (mintedAssets === 0n || stakedAssets === 0n) {
return {
value: 0,
Expand Down
Loading
Loading