-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Supported Zap Vaults [WEB-1424] (#276)
* feat: Add `zapInWith` and `zapOutWith` to `VaultMetadata` * feat: Function to fetch vault token market data * feat: Merge new zapper props with current metadata * fix: Remove focused test * refactor: Use `getAddress` * refactor: Return only the supported zapper addresses * refactor: Move `mergeZapperPropsWithAddressables` to its own file * refactor: Create the `Addressable` type * refactor: Fix jsdoc * refactor: Rename spec to addressable
- Loading branch information
1 parent
85c76ef
commit 1ebfbf5
Showing
12 changed files
with
291 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./mergeZapperPropsWithAddressables"; |
58 changes: 58 additions & 0 deletions
58
src/interfaces/helpers/mergeZapperPropsWithAddressables.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { createMockTokenMarketData, createMockVaultMetadata } from "../../test-utils/factories"; | ||
import { mergeZapperPropsWithAddressables } from "./mergeZapperPropsWithAddressables"; | ||
|
||
describe("mergeZapperPropsWithAddressables", () => { | ||
it("should set the zapper properties on an addressable", async () => { | ||
const vaultMetadataMock = { | ||
zappable: createMockVaultMetadata({ | ||
displayName: "Zappable", | ||
address: "0x16de59092dae5ccf4a1e6439d611fd0653f0bd01", // not checksummed | ||
}), | ||
notZappable: createMockVaultMetadata({ | ||
displayName: "Not Zappable", | ||
address: "0x6B175474E89094C44Da98b954EedeAC495271d0F", | ||
}), | ||
}; | ||
|
||
const vaultTokenMarketDataMock = { | ||
zappable: createMockTokenMarketData({ | ||
label: "Zappable", | ||
address: "0x16de59092dAE5CcF4A1E6439D611fd0653f0Bd01", // checksummed | ||
}), | ||
notInVaults: createMockTokenMarketData({ | ||
label: "Not in Vaults", | ||
address: "0xd6aD7a6750A7593E092a9B218d66C0A814a3436e", | ||
}), | ||
random: createMockTokenMarketData({ label: "Random", address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48" }), | ||
}; | ||
|
||
const actual = mergeZapperPropsWithAddressables( | ||
[vaultMetadataMock.zappable, vaultMetadataMock.notZappable], | ||
[ | ||
vaultTokenMarketDataMock.zappable.address, | ||
vaultTokenMarketDataMock.notInVaults.address, | ||
vaultTokenMarketDataMock.random.address, | ||
] | ||
); | ||
|
||
expect(actual.length).toEqual(2); | ||
expect(actual).toEqual( | ||
expect.arrayContaining([ | ||
{ | ||
...vaultMetadataMock.zappable, | ||
allowZapIn: true, | ||
allowZapOut: true, | ||
zapInWith: "zapperZapIn", | ||
zapOutWith: "zapperZapOut", | ||
}, | ||
{ | ||
...vaultMetadataMock.notZappable, | ||
allowZapIn: false, | ||
allowZapOut: false, | ||
zapInWith: undefined, | ||
zapOutWith: undefined, | ||
}, | ||
]) | ||
); | ||
}); | ||
}); |
33 changes: 33 additions & 0 deletions
33
src/interfaces/helpers/mergeZapperPropsWithAddressables.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { getAddress } from "@ethersproject/address"; | ||
|
||
import { Address, Addressable } from "../../types"; | ||
|
||
/** | ||
* Helper function to set the zapper properties on an Addressable | ||
* @param addressables an array of objects with an address prop | ||
* @param supportedVaultAddresses the supported vault addresses | ||
* @returns the updated metadata | ||
*/ | ||
export function mergeZapperPropsWithAddressables<T extends Addressable>( | ||
addressables: T[], | ||
supportedVaultAddresses: Address[] | ||
): T[] { | ||
const supportedVaultAddressesSet = new Set(supportedVaultAddresses); | ||
|
||
return addressables.map((addressable) => { | ||
try { | ||
const address = getAddress(addressable.address); | ||
const isZappable = supportedVaultAddressesSet.has(address); | ||
|
||
return { | ||
...addressable, | ||
allowZapIn: isZappable, | ||
allowZapOut: isZappable, | ||
zapInWith: isZappable ? "zapperZapIn" : undefined, | ||
zapOutWith: isZappable ? "zapperZapOut" : undefined, | ||
}; | ||
} catch (error) { | ||
return addressable; | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { VaultTokenMarketData } from "../../types"; | ||
|
||
const DEFAULT_TOKEN_MARKET_DATA: VaultTokenMarketData = { | ||
type: "vault", | ||
category: "deposit", | ||
network: "ethereum", | ||
address: "0x16de59092dae5ccf4a1e6439d611fd0653f0bd01", | ||
symbol: "yDAI", | ||
label: "yDAI", | ||
img: "https://storage.googleapis.com/zapper-fi-assets/apps/yearn.png", | ||
decimals: 18, | ||
price: 1.126570223844831, | ||
pricePerShare: 1.126570223844831, | ||
liquidity: 6899652.482441678, | ||
supply: 6124476.163495696, | ||
appId: "yearn", | ||
isBlocked: true, | ||
tokens: [ | ||
{ | ||
type: "base", | ||
network: "ethereum", | ||
address: "0x6b175474e89094c44da98b954eedeac495271d0f", | ||
decimals: 18, | ||
symbol: "DAI", | ||
price: 1, | ||
reserve: 6899652.482441678, | ||
tokenImageUrl: | ||
"https://storage.googleapis.com/zapper-fi-assets/tokens/ethereum/0x6b175474e89094c44da98b954eedeac495271d0f.png", | ||
}, | ||
], | ||
appName: "Yearn", | ||
appImageUrl: "https://storage.googleapis.com/zapper-fi-assets/apps/yearn.png", | ||
protcolDisplay: "Yearn", | ||
}; | ||
|
||
export const createMockTokenMarketData = (overwrites: Partial<VaultTokenMarketData> = {}): VaultTokenMarketData => ({ | ||
...DEFAULT_TOKEN_MARKET_DATA, | ||
...overwrites, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.