Skip to content

Commit

Permalink
Added missing docs
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrwitek committed Jul 12, 2024
1 parent 350bfd1 commit bde790b
Show file tree
Hide file tree
Showing 14 changed files with 41 additions and 40 deletions.
11 changes: 5 additions & 6 deletions sdk/allowance-common/src/interfaces/IAllowanceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,22 @@ import type { IAddress, IChainInfo, ITokenAmount, TransactionInfo } from '@summe

/**
* @name IAllowanceManager
* @description Interface for the Earn Protocol Manager which handles generating transactions for a Fleet
* @description Interface for the Allowance Manager which handles generating transactions for setting an allowance
*/
export interface IAllowanceManager {
/**
* @name getAllowance
* @description Deposit tokens into the Fleet
* @description Get the transactions needed to set an allowance for a token
*
* @param chainInfo Chain in which the token is
* @param tokenAddress Address of the token for the allowance
* @param user Address of the user that is trying to set the allowance
* @param amount Amount of tokens to set the allowance
* @param spender Address of the spender to approve
* @param amount Amount of tokens to allow the spender to spend
*
* @returns TransactionInfo[] An array of transactions that must be executed for the operation to succeed
*/
getAllowance(params: {
chainInfo: IChainInfo
fleetAddress: IAddress
spender: IAddress
amount: ITokenAmount
}): Promise<TransactionInfo[]>
}
10 changes: 5 additions & 5 deletions sdk/allowance-service/src/implementation/AllowanceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { encodeFunctionData, erc20Abi } from 'viem'

/**
* @name AllowanceManager
* @description This class is the implementation of the IEarnProtocolManager interface. Takes care of choosing the best provider for a price consultation
* @description This class is the implementation of the IAllowanceManager interface. Takes care of generating transactions for setting an allowance
*/
export class AllowanceManager implements IAllowanceManager {
private _configProvider: IConfigurationProvider
Expand All @@ -19,13 +19,13 @@ export class AllowanceManager implements IAllowanceManager {
/** FUNCTIONS */
async getAllowance(params: {
chainInfo: IChainInfo
fleetAddress: IAddress
spender: IAddress
amount: ITokenAmount
}): Promise<TransactionInfo[]> {
const calldata = encodeFunctionData({
abi: erc20Abi,
functionName: 'approve',
args: [params.fleetAddress.value, BigInt(params.amount.toBaseUnit())],
args: [params.spender.value, BigInt(params.amount.toBaseUnit())],
})

return [
Expand All @@ -38,8 +38,8 @@ export class AllowanceManager implements IAllowanceManager {
description:
'Approve spending of ' +
params.amount.toString() +
' to Fleet at address: ' +
params.fleetAddress.value,
' to the spender at address: ' +
params.spender.value,
},
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { AllowanceManager } from './AllowanceManager'

/**
* @name AllowanceManagerFactory
* @description This class is responsible for creating instances of the OracleManager
* @description This class is responsible for creating instances of the AllowanceManager
*/
export class AllowanceManagerFactory {
public static newAllowanceManager(params: {
Expand Down
2 changes: 1 addition & 1 deletion sdk/allowance-service/tests/AllowanceManager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('Earn Protocol Service', () => {
it('should return approval transaction correctly', async () => {
const transactionInfo = await allowanceManager.getAllowance({
chainInfo,
fleetAddress,
spender: fleetAddress,
amount: tokenAmount,
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
IRpcConfig,
getRpcGatewayEndpoint,
} from '@summerfi/serverless-shared/getRpcGatewayEndpoint'
import type { BlockchainClient } from '../types/BlockchainClient'
import type { IBlockchainClient } from '../interfaces/IBlockchainClient'
import { IBlockchainClientProvider } from '../interfaces'

/**
Expand All @@ -21,16 +21,20 @@ const rpcConfig: IRpcConfig = {
source: 'borrow-prod',
}

export class BlockchainnClientProvider implements IBlockchainClientProvider {
private readonly _blockchainClients: Record<number, BlockchainClient> = {}
/**
* Blockchain client provider implements the IBlockchainClientProvider interface
* @implements IBlockchainClientProvider
*/
export class BlockchainClientProvider implements IBlockchainClientProvider {
private readonly _blockchainClients: Record<number, IBlockchainClient> = {}
private readonly _configProvider: IConfigurationProvider

constructor(params: { configProvider: IConfigurationProvider }) {
this._configProvider = params.configProvider
this._loadClients([mainnet, optimism, arbitrum, base])
}

public getBlockchainClient(params: { chainInfo: IChainInfo }): BlockchainClient {
public getBlockchainClient(params: { chainInfo: IChainInfo }): IBlockchainClient {
const provider = this._blockchainClients[params.chainInfo.chainId]
if (!provider) {
throw new Error('Provider not found')
Expand Down
2 changes: 1 addition & 1 deletion sdk/blockchain-client-provider/src/implementation/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { BlockchainnClientProvider } from './BlockchainClientProvider'
export { BlockchainClientProvider } from './BlockchainClientProvider'
1 change: 0 additions & 1 deletion sdk/blockchain-client-provider/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export * from './implementation'
export * from './interfaces'
export * from './types'
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { PublicClient } from 'viem'

/**
* @name IBlockchainClient
* @description The client for a particular chain
*/
export type IBlockchainClient = PublicClient
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import { type BlockchainClient } from '../types/BlockchainClient'
import { type IBlockchainClient } from './IBlockchainClient'
import type { IChainInfo } from '@summerfi/sdk-common'

/**
* @name IBlockchainClientProvider
* @description Interface for the configuration provider, which is used to retrieve configuration items which are
* typically stored in environment variables, although it could also fetch them from other sources
* @description Interface for the BlockchainClient provider, which is used to retrieve a BlockchainClient for a particular chain
*/
export interface IBlockchainClientProvider {
/**
* @name getBlockchainClient
* @description Retrieves a configuration item from the configuration provider
* @param name The name of the configuration item to retrieve
* @returns The value of the configuration item
* @description Retrieves a BlockchainClient for a particular chain
* @param chainInfo The chain information for the chain
* @returns IBlockchainClient The client for a particular chain
*/
getBlockchainClient(params: { chainInfo: IChainInfo }): BlockchainClient
getBlockchainClient(params: { chainInfo: IChainInfo }): IBlockchainClient
}
3 changes: 2 additions & 1 deletion sdk/blockchain-client-provider/src/interfaces/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { type IBlockchainClientProvider } from './IBlockchainClientProvider'
export * from './IBlockchainClientProvider'
export * from './IBlockchainClient'
7 changes: 0 additions & 7 deletions sdk/blockchain-client-provider/src/types/BlockchainClient.ts

This file was deleted.

1 change: 0 additions & 1 deletion sdk/blockchain-client-provider/src/types/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { ChainFamilyMap } from '@summerfi/sdk-common'
import { ConfigurationProvider } from '@summerfi/configuration-provider'
import { BlockchainnClientProvider } from '../src/implementation/BlockchainClientProvider'
import { BlockchainClientProvider } from '../src/implementation/BlockchainClientProvider'

describe('Blockchain Provider', () => {
it('should return a provider for supported chains', async () => {
const configProvider = {
getConfigurationItem: jest.fn().mockReturnValue('https://rpc-gateway-url.com'),
} as unknown as ConfigurationProvider

const blockchainClientProvider = new BlockchainnClientProvider({ configProvider })
const blockchainClientProvider = new BlockchainClientProvider({ configProvider })

const chainInfo = ChainFamilyMap.Base.Mainnet
const baseClient = blockchainClientProvider.getBlockchainClient({ chainInfo: chainInfo })
Expand Down
6 changes: 3 additions & 3 deletions sdk/sdk-server/src/context/SDKContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { IAddressBookManager } from '@summerfi/address-book-common'
import { AddressBookManagerFactory } from '@summerfi/address-book-service'
import { EarnProtocolManagerFactory } from '@summerfi/earn-protocol-service'
import type { IEarnProtocolManager } from '@summerfi/earn-protocol-common'
import { BlockchainnClientProvider } from '@summerfi/blockchain-client-provider'
import { BlockchainClientProvider } from '@summerfi/blockchain-client-provider'
import { AllowanceManagerFactory } from '@summerfi/allowance-service'
import type { IAllowanceManager } from '@summerfi/allowance-common'

Expand All @@ -26,7 +26,7 @@ export type SDKContextOptions = CreateAWSLambdaContextOptions<APIGatewayProxyEve
export type SDKAppContext = {
addressBookManager: IAddressBookManager
configProvider: IConfigurationProvider
blockchainClientProvider: BlockchainnClientProvider
blockchainClientProvider: BlockchainClientProvider
tokensManager: ITokensManager
swapManager: ISwapManager
oracleManager: IOracleManager
Expand All @@ -40,7 +40,7 @@ export type SDKAppContext = {
// context for each request
export const createSDKContext = (opts: SDKContextOptions): SDKAppContext => {
const configProvider = new ConfigurationProvider()
const blockchainClientProvider = new BlockchainnClientProvider({ configProvider })
const blockchainClientProvider = new BlockchainClientProvider({ configProvider })
const addressBookManager = AddressBookManagerFactory.newAddressBookManager({ configProvider })
const tokensManager = TokensManagerFactory.newTokensManager({ configProvider })
const orderPlannerService = new OrderPlannerService()
Expand Down

0 comments on commit bde790b

Please sign in to comment.