Skip to content

Commit

Permalink
feat: Add Armada data types and Armada Manager (#470)
Browse files Browse the repository at this point in the history
- Added `armada-protocol-common` and `armada-protocol-service` packages
with all Armada common data types and the Armada manager
- Added `ArmadaManagerClient` and SDK server handlers to provide
client/server communication
- Update the Armada webapp to use the new data types and functions
- Moved submodule name from `earn-protocol` to `armada-protocol`
- Promoted `armada-protocol/abis` to full package `armada-protocol-abis`
so we can use it in `contracts-provider-service`
- Updated all ABIs and generated TS files for them
- Consolidated packages exports (some were wrong due to weird merge from
`dev`
- Updated Turbo SDK service template to not do the main exports
  • Loading branch information
robercano authored Aug 20, 2024
1 parent cad604f commit 05003c9
Show file tree
Hide file tree
Showing 658 changed files with 2,115 additions and 552 deletions.
4 changes: 2 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "earn-protocol/contracts"]
path = earn-protocol/contracts
[submodule "armada-protocol/contracts"]
path = armada-protocol/contracts
url = git@github.com:OasisDEX/summer-earn-protocol.git
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ artifacts
packages/**/src/generated
packages/**/types/generated
apps/**/types/generated/*
earn-protocol/contracts/**/*
armada-protocol/contracts/**/*
apps/armada-protocol-dashboard/sst-env.d.ts
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pnpm dev

To initialize submodules use:

`git submodule update earn-protocol/contracts`
`git submodule update armada-protocol/contracts`

If you want to restore submodules after folder is removed or something broke, delete the submodule
folder and run following script: `./bin/restore-git-submodule`.
Expand Down
2 changes: 0 additions & 2 deletions apps/earn-protocol/components/organisms/Form/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ const Form = () => {
walletAddress,
fleetAddress: usdcFleetAddress,
amountString: amountValue.toString(),
token,
})
}

Expand All @@ -127,7 +126,6 @@ const Form = () => {
walletAddress,
fleetAddress: usdcFleetAddress,
amountString: amountValue.toString(),
token,
})
}

Expand Down
22 changes: 7 additions & 15 deletions apps/earn-protocol/hooks/use-deposit.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,24 @@
import { type Token, TokenAmount } from '@summerfi/sdk-common'

import { useSDK } from '@/hooks/use-sdk'

export const useDeposit = () => {
const { getFleetClient, getUserClient } = useSDK()
const { getNewDepositTX } = useSDK()

return async ({
return ({
chainId,
walletAddress,
fleetAddress,
amountString,
token,
}: {
chainId: number
walletAddress: string
fleetAddress: string
amountString: string
token: Token
}) => {
const fleet = await getFleetClient({ chainId, fleetAddress })
const user = await getUserClient({ chainId, walletAddress })

return fleet.deposit({
user,
amount: TokenAmount.createFrom({
amount: amountString,
token,
}),
return getNewDepositTX({
chainId,
fleetAddress,
walletAddress,
amount: amountString,
})
}
}
106 changes: 97 additions & 9 deletions apps/earn-protocol/hooks/use-sdk.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useMemo } from 'react'
import { ArmadaPoolId, ArmadaPositionId, ArmadaProtocol } from '@summerfi/armada-protocol-service'
import { makeSDK } from '@summerfi/sdk-client'
import { Address } from '@summerfi/sdk-common'
import { Address, TokenAmount, User, Wallet } from '@summerfi/sdk-common'

import { sdkApiUrl } from '@/constants/sdk'

Expand Down Expand Up @@ -31,25 +32,111 @@ export const useSDK = () => {
[sdk],
)

const getFleetClient = useMemo(
const getNewDepositTX = useMemo(
() =>
async ({ chainId, fleetAddress }: { chainId: number; fleetAddress: string }) => {
async ({
chainId,
fleetAddress,
walletAddress,
amount,
}: {
chainId: number
fleetAddress: string
walletAddress: string
amount: string
}) => {
const chain = await sdk.chains.getChainById({
chainId,
})

if (!chain) {
throw new Error('Chain not found')
}
const fleet = chain.armada.getFleet({
address: Address.createFromEthereum({ value: fleetAddress }),
const { chainInfo } = chain

const poolId = ArmadaPoolId.createFrom({
chainInfo,
fleetAddress: Address.createFromEthereum({ value: fleetAddress }),
protocol: ArmadaProtocol.createFrom({ chainInfo }),
})

const poolInfo = await sdk.armada.getPoolInfo({
poolId,
})

const user = User.createFrom({
chainInfo,
wallet: Wallet.createFrom({
address: Address.createFromEthereum({ value: walletAddress }),
}),
})

const tokenAmount = TokenAmount.createFrom({
amount,
token: poolInfo.totalDeposits.token,
})

return sdk.armada.getNewDepositTX({
poolId,
user,
amount: tokenAmount,
})
},
[sdk],
)

const getWithdrawTX = useMemo(
() =>
async ({
chainId,
fleetAddress,
walletAddress,
amount,
}: {
chainId: number
fleetAddress: string
walletAddress: string
amount: string
}) => {
const chain = await sdk.chains.getChainById({
chainId,
})

if (!fleet) {
throw new Error(`SDK: Fleet not found: ${fleetAddress}`)
if (!chain) {
throw new Error('Chain not found')
}
const { chainInfo } = chain

const poolId = ArmadaPoolId.createFrom({
chainInfo,
fleetAddress: Address.createFromEthereum({ value: fleetAddress }),
protocol: ArmadaProtocol.createFrom({ chainInfo }),
})

return fleet
const poolInfo = await sdk.armada.getPoolInfo({
poolId,
})

const user = User.createFrom({
chainInfo,
wallet: Wallet.createFrom({
address: Address.createFromEthereum({ value: walletAddress }),
}),
})

const tokenAmount = TokenAmount.createFrom({
amount,
token: poolInfo.totalDeposits.token,
})

return sdk.armada.getWithdrawTX({
poolId,
positionId: ArmadaPositionId.createFrom({
id: walletAddress,
user,
}),
amount: tokenAmount,
})
},
[sdk],
)
Expand Down Expand Up @@ -79,7 +166,8 @@ export const useSDK = () => {
)

return {
getFleetClient,
getNewDepositTX,
getWithdrawTX,
getTokenBySymbol,
getUserClient,
}
Expand Down
22 changes: 7 additions & 15 deletions apps/earn-protocol/hooks/use-withdraw.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,24 @@
import { type Token, TokenAmount } from '@summerfi/sdk-common'

import { useSDK } from '@/hooks/use-sdk'

export const useWithdraw = () => {
const { getFleetClient, getUserClient } = useSDK()
const { getWithdrawTX } = useSDK()

return async ({
return ({
chainId,
walletAddress,
fleetAddress,
amountString,
token,
}: {
chainId: number
walletAddress: string
fleetAddress: string
amountString: string
token: Token
}) => {
const fleet = await getFleetClient({ chainId, fleetAddress })
const user = await getUserClient({ chainId, walletAddress })

return fleet.withdraw({
user,
amount: TokenAmount.createFrom({
amount: amountString,
token,
}),
return getWithdrawTX({
chainId,
fleetAddress,
walletAddress,
amount: amountString,
})
}
}
1 change: 1 addition & 0 deletions apps/earn-protocol/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"@summerfi/rays-db": "workspace:*",
"@summerfi/sdk-client": "workspace:^",
"@summerfi/sdk-common": "workspace:^",
"@summerfi/armada-protocol-service": "workspace:*",
"@summerfi/serverless-shared": "workspace:*",
"@summerfi/summer-protocol-db": "workspace:*",
"@tabler/icons-react": "^3.11.0",
Expand Down
7 changes: 7 additions & 0 deletions armada-protocol/abis/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/** @type {import("eslint").Linter.Config} */
module.exports = {
root: true,
ignorePatterns: ['jest.config.js'],
extends: ['@summerfi/eslint-config/library.cjs'],
parser: '@typescript-eslint/parser',
}
File renamed without changes.
30 changes: 30 additions & 0 deletions armada-protocol/abis/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "@summerfi/armada-protocol-abis",
"version": "0.0.1",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"exports": {
".": {
"import": "./src/index.js",
"types": "./src/index.d.ts"
},
"./*": {
"import": "./dist/*/index.js",
"types": "./dist/*/index.d.ts"
}
},
"scripts": {
"tsc": "tsc",
"watch": "tsc -w",
"e2e": "jest e2e/",
"testw": "jest --watch",
"build": "tsc -b tsconfig.build.json",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"genindex": "rm -f src/index.ts && for dir in ./src/*; do cti create ./$dir -b -w > /dev/null; done && cti ./src -b -w -e '.t.sol' -e 'build-info' -e 'MockERC721.sol'"
},
"devDependencies": {
"@summerfi/eslint-config": "workspace:*",
"@summerfi/typescript-config": "workspace:*"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const AaveV3ArkTestForkAbi = [{"type":"function","name":"IS_TEST","inputs":[],"outputs":[{"name":"","type":"bool","internalType":"bool"}],"stateMutability":"view"},{"type":"function","name":"aaveAddressProvider","inputs":[],"outputs":[{"name":"","type":"address","internalType":"address"}],"stateMutability":"view"},{"type":"function","name":"aaveV3DataProvider","inputs":[],"outputs":[{"name":"","type":"address","internalType":"address"}],"stateMutability":"view"},{"type":"function","name":"aaveV3Pool","inputs":[],"outputs":[{"name":"","type":"address","internalType":"contract IPoolV3"}],"stateMutability":"view"},{"type":"function","name":"aaveV3PoolAddress","inputs":[],"outputs":[{"name":"","type":"address","internalType":"address"}],"stateMutability":"view"},{"type":"function","name":"ark","inputs":[],"outputs":[{"name":"","type":"address","internalType":"contract AaveV3Ark"}],"stateMutability":"view"},{"type":"function","name":"commander","inputs":[],"outputs":[{"name":"","type":"address","internalType":"address"}],"stateMutability":"view"},{"type":"function","name":"dai","inputs":[],"outputs":[{"name":"","type":"address","internalType":"contract IERC20"}],"stateMutability":"view"},{"type":"function","name":"excludeArtifacts","inputs":[],"outputs":[{"name":"excludedArtifacts_","type":"string[]","internalType":"string[]"}],"stateMutability":"view"},{"type":"function","name":"excludeContracts","inputs":[],"outputs":[{"name":"excludedContracts_","type":"address[]","internalType":"address[]"}],"stateMutability":"view"},{"type":"function","name":"excludeSelectors","inputs":[],"outputs":[{"name":"excludedSelectors_","type":"tuple[]","internalType":"struct StdInvariant.FuzzSelector[]","components":[{"name":"addr","type":"address","internalType":"address"},{"name":"selectors","type":"bytes4[]","internalType":"bytes4[]"}]}],"stateMutability":"view"},{"type":"function","name":"excludeSenders","inputs":[],"outputs":[{"name":"excludedSenders_","type":"address[]","internalType":"address[]"}],"stateMutability":"view"},{"type":"function","name":"failed","inputs":[],"outputs":[{"name":"","type":"bool","internalType":"bool"}],"stateMutability":"view"},{"type":"function","name":"governor","inputs":[],"outputs":[{"name":"","type":"address","internalType":"address"}],"stateMutability":"view"},{"type":"function","name":"nextArk","inputs":[],"outputs":[{"name":"","type":"address","internalType":"contract AaveV3Ark"}],"stateMutability":"view"},{"type":"function","name":"raft","inputs":[],"outputs":[{"name":"","type":"address","internalType":"address"}],"stateMutability":"view"},{"type":"function","name":"rewardsController","inputs":[],"outputs":[{"name":"","type":"address","internalType":"address"}],"stateMutability":"view"},{"type":"function","name":"setUp","inputs":[],"outputs":[],"stateMutability":"nonpayable"},{"type":"function","name":"targetArtifactSelectors","inputs":[],"outputs":[{"name":"targetedArtifactSelectors_","type":"tuple[]","internalType":"struct StdInvariant.FuzzArtifactSelector[]","components":[{"name":"artifact","type":"string","internalType":"string"},{"name":"selectors","type":"bytes4[]","internalType":"bytes4[]"}]}],"stateMutability":"view"},{"type":"function","name":"targetArtifacts","inputs":[],"outputs":[{"name":"targetedArtifacts_","type":"string[]","internalType":"string[]"}],"stateMutability":"view"},{"type":"function","name":"targetContracts","inputs":[],"outputs":[{"name":"targetedContracts_","type":"address[]","internalType":"address[]"}],"stateMutability":"view"},{"type":"function","name":"targetInterfaces","inputs":[],"outputs":[{"name":"targetedInterfaces_","type":"tuple[]","internalType":"struct StdInvariant.FuzzInterface[]","components":[{"name":"addr","type":"address","internalType":"address"},{"name":"artifacts","type":"string[]","internalType":"string[]"}]}],"stateMutability":"view"},{"type":"function","name":"targetSelectors","inputs":[],"outputs":[{"name":"targetedSelectors_","type":"tuple[]","internalType":"struct StdInvariant.FuzzSelector[]","components":[{"name":"addr","type":"address","internalType":"address"},{"name":"selectors","type":"bytes4[]","internalType":"bytes4[]"}]}],"stateMutability":"view"},{"type":"function","name":"targetSenders","inputs":[],"outputs":[{"name":"targetedSenders_","type":"address[]","internalType":"address[]"}],"stateMutability":"view"},{"type":"function","name":"test_Board_AaveV3_fork","inputs":[],"outputs":[],"stateMutability":"nonpayable"},{"type":"function","name":"tipJar","inputs":[],"outputs":[{"name":"","type":"address","internalType":"address"}],"stateMutability":"view"},{"type":"event","name":"ArkPoked","inputs":[{"name":"currentPrice","type":"uint256","indexed":false,"internalType":"uint256"},{"name":"timestamp","type":"uint256","indexed":false,"internalType":"uint256"}],"anonymous":false},{"type":"event","name":"ArkPokedNoChange","inputs":[],"anonymous":false},{"type":"event","name":"ArkPokedTooSoon","inputs":[],"anonymous":false},{"type":"event","name":"Boarded","inputs":[{"name":"commander","type":"address","indexed":true,"internalType":"address"},{"name":"token","type":"address","indexed":false,"internalType":"address"},{"name":"amount","type":"uint256","indexed":false,"internalType":"uint256"}],"anonymous":false},{"type":"event","name":"DepositCapUpdated","inputs":[{"name":"newCap","type":"uint256","indexed":false,"internalType":"uint256"}],"anonymous":false},{"type":"event","name":"Disembarked","inputs":[{"name":"commander","type":"address","indexed":true,"internalType":"address"},{"name":"token","type":"address","indexed":false,"internalType":"address"},{"name":"amount","type":"uint256","indexed":false,"internalType":"uint256"}],"anonymous":false},{"type":"event","name":"Harvested","inputs":[{"name":"amount","type":"uint256","indexed":false,"internalType":"uint256"}],"anonymous":false},{"type":"event","name":"MaxAllocationUpdated","inputs":[{"name":"newMaxAllocation","type":"uint256","indexed":false,"internalType":"uint256"}],"anonymous":false},{"type":"event","name":"Moved","inputs":[{"name":"from","type":"address","indexed":true,"internalType":"address"},{"name":"to","type":"address","indexed":true,"internalType":"address"},{"name":"token","type":"address","indexed":false,"internalType":"address"},{"name":"amount","type":"uint256","indexed":false,"internalType":"uint256"}],"anonymous":false},{"type":"event","name":"RaftUpdated","inputs":[{"name":"newRaft","type":"address","indexed":false,"internalType":"address"}],"anonymous":false},{"type":"event","name":"SlotFound","inputs":[{"name":"who","type":"address","indexed":false,"internalType":"address"},{"name":"fsig","type":"bytes4","indexed":false,"internalType":"bytes4"},{"name":"keysHash","type":"bytes32","indexed":false,"internalType":"bytes32"},{"name":"slot","type":"uint256","indexed":false,"internalType":"uint256"}],"anonymous":false},{"type":"event","name":"Transfer","inputs":[{"name":"from","type":"address","indexed":true,"internalType":"address"},{"name":"to","type":"address","indexed":true,"internalType":"address"},{"name":"value","type":"uint256","indexed":false,"internalType":"uint256"}],"anonymous":false},{"type":"event","name":"WARNING_UninitedSlot","inputs":[{"name":"who","type":"address","indexed":false,"internalType":"address"},{"name":"slot","type":"uint256","indexed":false,"internalType":"uint256"}],"anonymous":false},{"type":"event","name":"log","inputs":[{"name":"","type":"string","indexed":false,"internalType":"string"}],"anonymous":false},{"type":"event","name":"log_address","inputs":[{"name":"","type":"address","indexed":false,"internalType":"address"}],"anonymous":false},{"type":"event","name":"log_array","inputs":[{"name":"val","type":"uint256[]","indexed":false,"internalType":"uint256[]"}],"anonymous":false},{"type":"event","name":"log_array","inputs":[{"name":"val","type":"int256[]","indexed":false,"internalType":"int256[]"}],"anonymous":false},{"type":"event","name":"log_array","inputs":[{"name":"val","type":"address[]","indexed":false,"internalType":"address[]"}],"anonymous":false},{"type":"event","name":"log_bytes","inputs":[{"name":"","type":"bytes","indexed":false,"internalType":"bytes"}],"anonymous":false},{"type":"event","name":"log_bytes32","inputs":[{"name":"","type":"bytes32","indexed":false,"internalType":"bytes32"}],"anonymous":false},{"type":"event","name":"log_int","inputs":[{"name":"","type":"int256","indexed":false,"internalType":"int256"}],"anonymous":false},{"type":"event","name":"log_named_address","inputs":[{"name":"key","type":"string","indexed":false,"internalType":"string"},{"name":"val","type":"address","indexed":false,"internalType":"address"}],"anonymous":false},{"type":"event","name":"log_named_array","inputs":[{"name":"key","type":"string","indexed":false,"internalType":"string"},{"name":"val","type":"uint256[]","indexed":false,"internalType":"uint256[]"}],"anonymous":false},{"type":"event","name":"log_named_array","inputs":[{"name":"key","type":"string","indexed":false,"internalType":"string"},{"name":"val","type":"int256[]","indexed":false,"internalType":"int256[]"}],"anonymous":false},{"type":"event","name":"log_named_array","inputs":[{"name":"key","type":"string","indexed":false,"internalType":"string"},{"name":"val","type":"address[]","indexed":false,"internalType":"address[]"}],"anonymous":false},{"type":"event","name":"log_named_bytes","inputs":[{"name":"key","type":"string","indexed":false,"internalType":"string"},{"name":"val","type":"bytes","indexed":false,"internalType":"bytes"}],"anonymous":false},{"type":"event","name":"log_named_bytes32","inputs":[{"name":"key","type":"string","indexed":false,"internalType":"string"},{"name":"val","type":"bytes32","indexed":false,"internalType":"bytes32"}],"anonymous":false},{"type":"event","name":"log_named_decimal_int","inputs":[{"name":"key","type":"string","indexed":false,"internalType":"string"},{"name":"val","type":"int256","indexed":false,"internalType":"int256"},{"name":"decimals","type":"uint256","indexed":false,"internalType":"uint256"}],"anonymous":false},{"type":"event","name":"log_named_decimal_uint","inputs":[{"name":"key","type":"string","indexed":false,"internalType":"string"},{"name":"val","type":"uint256","indexed":false,"internalType":"uint256"},{"name":"decimals","type":"uint256","indexed":false,"internalType":"uint256"}],"anonymous":false},{"type":"event","name":"log_named_int","inputs":[{"name":"key","type":"string","indexed":false,"internalType":"string"},{"name":"val","type":"int256","indexed":false,"internalType":"int256"}],"anonymous":false},{"type":"event","name":"log_named_string","inputs":[{"name":"key","type":"string","indexed":false,"internalType":"string"},{"name":"val","type":"string","indexed":false,"internalType":"string"}],"anonymous":false},{"type":"event","name":"log_named_uint","inputs":[{"name":"key","type":"string","indexed":false,"internalType":"string"},{"name":"val","type":"uint256","indexed":false,"internalType":"uint256"}],"anonymous":false},{"type":"event","name":"log_string","inputs":[{"name":"","type":"string","indexed":false,"internalType":"string"}],"anonymous":false},{"type":"event","name":"log_uint","inputs":[{"name":"","type":"uint256","indexed":false,"internalType":"uint256"}],"anonymous":false},{"type":"event","name":"logs","inputs":[{"name":"","type":"bytes","indexed":false,"internalType":"bytes"}],"anonymous":false}] as const

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions armada-protocol/abis/src/AaveV3Ark.fork.t.sol/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './AaveV3ArkTestFork.abi';
Loading

0 comments on commit 05003c9

Please sign in to comment.