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

For new stake #155

Open
wants to merge 45 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
bda707a
[for-new-stake] add contract for genesis
Cast0001 Jul 16, 2024
1e072b7
[for-new-stake] improve vaultMulticall
Cast0001 Jul 17, 2024
ad73ec0
[for-new-stake] improve getOsTokenPosition
Cast0001 Jul 17, 2024
3c0dcd0
[for-new-stake] add panding to getExitQueuePositions
Cast0001 Jul 17, 2024
d1e4d93
[for-new-stake] add stake calculator
Cast0001 Jul 22, 2024
bf6078e
[for-new-stake] improve stake calculator
Cast0001 Jul 25, 2024
0f247d3
[for-new-stake] improve abis
Cast0001 Jul 26, 2024
7c840c3
[for-new-stake] new stakecalculator
Cast0001 Jul 29, 2024
c5b5d0b
Merge branch 'main' into for-new-stake
Cast0001 Aug 2, 2024
c1426ce
[for-new-stake] change address
Cast0001 Aug 6, 2024
1eaee07
Merge branch 'main' into for-new-stake
Cast0001 Aug 7, 2024
f897102
[for-new-stake] improve versions
Cast0001 Aug 15, 2024
d9383ba
Merge branch 'main' into for-new-stake
Cast0001 Aug 15, 2024
0c492d8
Merge branch 'main' into for-new-stake
Cast0001 Aug 20, 2024
9cd9776
[for-new-stake] open AbortPromise
Cast0001 Aug 20, 2024
2a9b7a1
Merge branch 'main' into for-new-stake
Cast0001 Aug 23, 2024
3320f40
Merge branch 'main' into for-new-stake
Cast0001 Sep 9, 2024
193187b
[for-new-stake] replace address
Cast0001 Sep 12, 2024
d7e09fe
[for-new-stake] change exit queue
Cast0001 Sep 12, 2024
c6d440d
Merge branch 'main' into for-new-stake
Cast0001 Sep 12, 2024
862891a
[for-new-stake] change logic
Cast0001 Sep 17, 2024
11fcf5e
New createVault method (#169)
Cast0001 Sep 20, 2024
b059774
New subgraph (#171)
mike-diamond Sep 24, 2024
17d349d
Subgraph tvl apy (#172)
Cast0001 Sep 24, 2024
70088c7
[exit queue] Update request (#173)
mike-diamond Sep 25, 2024
54614dc
[parse exit request] Update exit queue fetch (#174)
mike-diamond Sep 25, 2024
e5dfa50
Vault user (#175)
mike-diamond Sep 26, 2024
df65d64
[get config] update get config (#177)
mike-diamond Sep 27, 2024
cbd4bf9
Add new methods getUserStats & getVaultStats (#176)
dfkadyr Sep 27, 2024
e6031cd
new addresses
Cast0001 Sep 27, 2024
22fb447
[new-stake-calculator] set new addresses (#178)
Cast0001 Sep 30, 2024
319b964
[add-genesis-to-vault] (#180)
Cast0001 Oct 2, 2024
04f2c8e
Merge branch 'main' into for-new-stake
Cast0001 Oct 2, 2024
5d48fc9
Add new methods getFiatRates & getUserExchangeRewards (#179)
dfkadyr Oct 3, 2024
9255d2d
[polishing] remove old & change harvest (#181)
Cast0001 Oct 4, 2024
5585157
Replace depositDataRoot & depositDataManager (#182)
dfkadyr Oct 7, 2024
df6d5a1
new-improves
dfkadyr Oct 9, 2024
8f82fb5
Merge branch 'main' into for-new-stake
Cast0001 Oct 9, 2024
b558aff
hide score percentiles
Cast0001 Oct 14, 2024
6a62ffa
fix types
Cast0001 Oct 14, 2024
c6c8f7b
Remove ScorePercentiles logic (#185)
dfkadyr Oct 16, 2024
0d812e6
remove duplicates (#186)
dfkadyr Oct 18, 2024
95e9d4c
Improve ltv percent logic (#193)
dfkadyr Oct 23, 2024
73bdd0a
add v2 to getVaultVersion, update holesky factories, add queuedShares…
dfkadyr Oct 23, 2024
61ddf1d
update holesky & mainnet factories (#194)
dfkadyr Oct 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ node_modules
schema.graphql
src/types/graphql
src/contracts/types
src/contracts/vault/types
2 changes: 1 addition & 1 deletion .graphqlconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"extensions": {
"endpoints": {
"Subgraph GraphQL": {
"url": "https://holesky-graph.stakewise.io/subgraphs/name/stakewise/stakewise/graphql",
"url": "https://graphs.stakewise.io/holesky/subgraphs/name/stakewise/prod",
"headers": {
"user-agent": "JS GraphQL"
},
Expand Down
476 changes: 280 additions & 196 deletions README.md

Large diffs are not rendered by default.

128 changes: 119 additions & 9 deletions changelog/next-release.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
- Breaking change: Removed `sdk.osToken.getConfig`. Use `sdk.vault.getVault` instead to get osToken config data `{ osTokenConfig: { ltvPercent, thresholdPercent } }`.
- Added canHarvest: boolean to `sdk.vault.getHarvestParams` response.

# Updates
### 1. `sdk.vault.getVault`

Expand All @@ -12,25 +9,138 @@ type AddedOutput = {
ltvPercent: string
thresholdPercent: string
}
isGenesis: boolean
queuedShares: string
}
```

| Name | Description |
|-----------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Name | Description |
|------|-------------|
| `osTokenConfig` | contains the `ltvPercent`, which is the percentage used to calculate how much a user can mint in OsToken shares, and `thresholdPercent`, which is the liquidation threshold percentage used to calculate the health factor for the OsToken position |
| `isGenesis` | This vault is owned by stakewise |
| `queuedShares` | The total number of queued shares |

---
### 2. `sdk.vault.getHarvestParams`

#### New output field:
#### New output format:

```ts
type AddedOutput = {
canHarvest: boolean
type Output = {
canHarvest: boolean // NEW
params: {
reward: string
proof: Array<string>
rewardsRoot: string
unlockedMevReward: string
}
}
```

---

### 3. Removed method
### `sdk.vault.getVault`
### `sdk.osToken.getAvgRewardsPerSecond`

---

### 4. Removed output field
### `sdk.osToken.getPosition`

```ts
type RemovedOutput = {
minted: {
fee: bigint
}
}
```

### 5. Added method getStakewiseStats
### `sdk.utils.getStakewiseStats`
#### Getting common stakewise data for the network

---

### 6. Added optional input field
### `sdk.vault.getExitQueuePositions`
#### Added Argument:

| Name | Type | Required |
|--------------|-----------|----------|
| isClaimed | `boolean` | **No** |

---

### 7. Removed output field
### `sdk.vault.getStakeBalance`

```ts
type RemovedOutput = {
shares: bigint
}
```
---

### 8. Deprecated method `sdk.osToken.getConfig`
### Use `sdk.vault.getVault` instead to get the result in `osTokenConfig` field.

---

### 9. Add methods
### `sdk.vault.getVaultStats` & `sdk.vault.getUserStats`
#### With the help of this data it is possible to build a chart.

---

### 10. Removed method `sdk.vault.getSnapshots`
### Use `sdk.vault.getVaultStats` instead

---

### 11. Update method `sdk.vault.getUserRewards`
#### Update output format:

```ts
type Output = Array<{
date: number
dailyRewards: number
dailyRewardsEur: number
dailyRewardsGbp: number
dailyRewardsUsd: number
}>
```

#### New arguments:

| Name | Type | Type | Description |
|------|----------|-------------|---|
| dateFrom | `number` | **Yes** | Time to start in milliseconds |
| dateTo | `number` | **Yes** | Time to end in milliseconds |
| userAddress | `string` | **Yes** | The user address |
| vaultAddress | `string` | **Yes** | The address of the vault |

---

### 12. Added method getFiatRates
### `sdk.utils.getFiatRates`
#### Getting fiat values for the network

---

### 13. Removed input field
### `sdk.vault.operate`
#### Removed depositDataRoot use `vault.setDepositDataRoot` instead
#### Removed depositDataManager use `vault.setDepositDataManager` instead

```ts
type RemovedInput = {
depositDataManager: string
depositDataRoot: string
}
```

---

### 14. Removed method `sdk.vault.getScorePercentiles`

---
4 changes: 3 additions & 1 deletion codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ if (process.env.NETWORK === 'gnosis') {
const config = configs[network]
const subgraphIndex = Number(process.env.SUBGRAPH_INDEX || 0)

const subgraphUrl = Array.isArray(config.api.subgraph)
let subgraphUrl = Array.isArray(config.api.subgraph)
? config.api.subgraph[subgraphIndex]
: config.api.subgraph

subgraphUrl = subgraphUrl.replace('prod', 'stage')

const urls: Record<string, string> = {
backend: config.api.backend,
subgraph: subgraphUrl,
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
"test": "jest --clearCache && jest --onlyChanged",
"prepare": "npm run typechain && npm run graphql && npm run beforePublish",
"build": "npm run test && npm run prepare && rm -rf ./dist && npm run rollup",
"typechain": "typechain --target ethers-v6 --out-dir src/contracts/types 'src/contracts/abis/*.json'",
"typechain:vault": "typechain --target ethers-v6 --out-dir src/contracts/vault/types 'src/contracts/vault/abis/*.json'",
"typechain:base": "typechain --target ethers-v6 --out-dir src/contracts/types 'src/contracts/abis/*.json'",
"typechain": "npm run typechain:base && npm run typechain:vault",
"graphql": "graphql-codegen && ts-node -O '{\"module\": \"commonjs\"}' ./scripts/generateGraphqlExports",
"rollup": "rollup --config rollup.config.js --bundleConfigAsCjs",
"beforePublish": "node ./scripts/beforePublish",
Expand Down
63 changes: 52 additions & 11 deletions src/StakeWiseSDK.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
import methods from './methods'
import { configs, getGas, createProvider, getVaultFactory, VaultType } from './utils'

import { createContracts, vaultMulticall, rewardSplitterMulticall } from './contracts'

import {
getGas,
configs,
VaultType,
createProvider,
getVaultFactory,
getVaultVersion,
} from './utils'


type GetVaultFactoryInput = { vaultType?: VaultType, isErc20?: boolean }
type VaultMulticallInput = Pick<Parameters<typeof vaultMulticall>[0], 'request' | 'userAddress' | 'vaultAddress'>
Expand Down Expand Up @@ -35,6 +44,16 @@ class StakeWiseSDK {
this.provider = provider
this.contracts = contracts

if (options.endpoints?.subgraph) {
// @ts-ignore: It's better to just overwrite
this.config.api.subgraph = options.endpoints.subgraph
}

if (options.endpoints?.api) {
// @ts-ignore: It's better to just overwrite
this.config.api.backend = options.endpoints.api
}

const argsForMethods = { options, contracts, provider }

this.utils = methods.createUtils(argsForMethods)
Expand All @@ -43,26 +62,41 @@ class StakeWiseSDK {
this.rewardSplitter = methods.createRewardSplitterMethods(argsForMethods)
}

getVaultFactory({ vaultType, isErc20 }: GetVaultFactoryInput) {
return getVaultFactory({
vaultType,
isErc20,
contracts: this.contracts,
async vaultMulticall<T extends unknown>(values: VaultMulticallInput) {
const { userAddress, vaultAddress, request } = values

const { isBlocklist, isPrivate, isRestake, isGenesis } = await this.vault.getVault({ vaultAddress })

const vaultContract = this.contracts.helpers.createVault({
options: {
chainId: this.config.network.chainId,
isBlocklist,
isPrivate,
isGenesis,
isRestake,
},
vaultAddress,
})
}

vaultMulticall<T extends unknown>({ userAddress, vaultAddress, request }: VaultMulticallInput) {
return vaultMulticall<T>({
vaultContract: this.contracts.helpers.createVault(vaultAddress),
options: this.options,
vaultContract,
vaultAddress,
userAddress,
request,
})
}

rewardSplitterMulticall<T extends unknown>(props: RewardSplitterMulticallInput) {
const { userAddress, vaultAddress, rewardSplitterAddress, request } = props
getVaultFactory({ vaultType, isErc20 }: GetVaultFactoryInput) {
return getVaultFactory({
vaultType,
isErc20,
contracts: this.contracts,
})
}

rewardSplitterMulticall<T extends unknown>(values: RewardSplitterMulticallInput) {
const { userAddress, vaultAddress, rewardSplitterAddress, request } = values

return rewardSplitterMulticall<T>({
rewardSplitterContract: this.contracts.helpers.createRewardSplitter(rewardSplitterAddress),
Expand All @@ -80,6 +114,13 @@ class StakeWiseSDK {
})
}

getVaultVersion(vaultAddress: string) {
return getVaultVersion({
contracts: this.contracts,
vaultAddress,
})
}

get network() {
return this.options.network
}
Expand Down
41 changes: 40 additions & 1 deletion src/contracts/abis/KeeperAbi.json
Original file line number Diff line number Diff line change
@@ -1 +1,40 @@
[ { "inputs": [ { "internalType": "address", "name": "vault", "type": "address" } ], "name": "isCollateralized", "outputs": [ { "internalType": "bool", "name": "", "type": "bool" } ], "stateMutability": "view", "type": "function" }, { "inputs": [ { "internalType": "address", "name": "vault", "type": "address" } ], "name": "canHarvest", "outputs": [ { "internalType": "bool", "name": "", "type": "bool" } ], "stateMutability": "view", "type": "function" } ]
[
{
"inputs": [
{
"internalType": "address",
"name": "vault",
"type": "address"
}
],
"name": "isCollateralized",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "vault",
"type": "address"
}
],
"name": "canHarvest",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "view",
"type": "function"
}
]
47 changes: 46 additions & 1 deletion src/contracts/abis/MintTokenAbi.json
Original file line number Diff line number Diff line change
@@ -1 +1,46 @@
[ { "inputs": [ { "internalType": "address", "name": "account", "type": "address" } ], "name": "balanceOf", "outputs": [ { "internalType": "uint256", "name": "", "type": "uint256" } ], "stateMutability": "view", "type": "function" }, { "anonymous": false, "inputs": [ { "indexed": true, "internalType": "address", "name": "from", "type": "address" }, { "indexed": true, "internalType": "address", "name": "to", "type": "address" }, { "indexed": false, "internalType": "uint256", "name": "value", "type": "uint256" } ], "name": "Transfer", "type": "event" } ]
[
{
"inputs": [
{
"internalType": "address",
"name": "account",
"type": "address"
}
],
"name": "balanceOf",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "from",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "to",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "value",
"type": "uint256"
}
],
"name": "Transfer",
"type": "event"
}
]
Loading
Loading