Skip to content

Commit

Permalink
Merge pull request #39 from stabilitydao/dev
Browse files Browse the repository at this point in the history
0.17.0: fixes, getChainStrategies, draw chain covers
  • Loading branch information
a17 authored Oct 12, 2024
2 parents dd6c300 + e210b8f commit 9370d0c
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 15 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Comprehensive information about platform strategies for managing DeFi assets. In
* `getStrategyShortId(id: string): StrategyShortId|undefined`
* `getStrategiesTotals(): {[state in StrategyState]: number}`
* `getStrategyProtocols(shortId: StrategyShortId): DeFiProtocol[]`
* `getChainStrategies(chainName: ChainName): Strategy[]`

### #️⃣ Deployments

Expand Down
Binary file modified chains.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@stabilitydao/stability",
"version": "0.16.1",
"version": "0.17.0",
"description": "Stability Integration Library",
"main": "out/index.js",
"types": "out/index.d.ts",
Expand Down
5 changes: 4 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ import {
getStrategyShortId,
strategyStateDescription,
getStrategiesTotals,
baseStrategyContracts, getStrategyProtocols,
baseStrategyContracts,
getStrategyProtocols,
getChainStrategies,
} from "./strategies";
import {
integrations,
Expand Down Expand Up @@ -66,6 +68,7 @@ export {
getStrategyProtocols,
getIntegrationStatus,
getChainProtocols,
getChainStrategies,
getSupportedChainNames,
assets,
Asset,
Expand Down
3 changes: 2 additions & 1 deletion src/integrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ export const integrations: { [org: string]: DeFiOrganization } = {
protocols: {
merkl: {
name: 'Merkl',
img: 'Merkl.svg',
category: DefiCategory.REWARDING,
// chains with active rewards
chains: [
Expand Down Expand Up @@ -400,7 +401,7 @@ export const integrations: { [org: string]: DeFiOrganization } = {
strategies: [StrategyShortId.TPF,],
},
stack: {
name: 'Stack More',
name: 'Stack',
img: 'Stack.svg',
category: DefiCategory.CDP,
chains: [ChainName.REAL,],
Expand Down
6 changes: 3 additions & 3 deletions src/stability.tokenlist.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"name": "Stability Token List",
"logoURI": "https://stability.farm/logo.svg",
"keywords": [],
"timestamp": "2024-10-11T00:00:00+00:00",
"timestamp": "2024-10-13T00:00:00+00:00",
"version": {
"major": 1,
"minor": 4,
"patch": 0
"patch": 1
},
"tags": {
"stablecoin": {
Expand Down Expand Up @@ -253,7 +253,7 @@
"symbol": "UKRE",
"name": "UK Real Estate",
"decimals": 18,
"logoURI": "https://raw.githubusercontent.com/stabilitydao/.github/main/tokens/UKRE.png"
"logoURI": "https://raw.githubusercontent.com/stabilitydao/.github/main/tokens/UKRE.svg"
},
{
"chainId": 111188,
Expand Down
21 changes: 21 additions & 0 deletions src/strategies.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {DeFiProtocol, integrations} from "./integrations";
import {ChainName} from "./chains";

export type Strategy = {
id: string
Expand Down Expand Up @@ -373,3 +374,23 @@ export const getStrategyProtocols = (shortId: StrategyShortId): DeFiProtocol[] =
}
return r
}

export const getChainStrategies = (chainName: ChainName): Strategy[] => {
const r:Strategy[] = []

for (const strategyShortId of Object.keys(strategies)) {
let chainOk = true
const protocols = getStrategyProtocols(strategyShortId as StrategyShortId)
for (const protocol of protocols) {
if (!protocol.chains.includes(chainName)) {
chainOk = false
break
}
}
if (chainOk) {
r.push(strategies[strategyShortId as StrategyShortId])
}
}

return r
}
6 changes: 5 additions & 1 deletion tests/strategies.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
baseStrategyContracts,
baseStrategyContracts, ChainName, getChainStrategies,
getMerklStrategies,
getStrategiesTotals,
getStrategyProtocols,
Expand Down Expand Up @@ -28,4 +28,8 @@ describe('testing strategies', () => {
test('get strategy protocols', () => {
expect(baseStrategyContracts[BaseStrategy.FARMING]).toEqual('FarmingStrategyBase')
})
test('get chain strategies', () => {
const realStrategies = getChainStrategies(ChainName.REAL)
expect(realStrategies.length).toBeGreaterThan(3)
})
});
59 changes: 51 additions & 8 deletions tools/draw-chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ import {version} from '../package.json';
async function main() {
console.log('== Draw chains ==')

// check tmp dirs
const tmpDir = './temp';
const coversDir = './temp/covers';
if (!fs.existsSync(tmpDir)){
fs.mkdirSync(tmpDir);
}
if (!fs.existsSync(coversDir)){
fs.mkdirSync(coversDir);
}

// save to
const filename = './chains.png';

Expand All @@ -19,12 +29,6 @@ async function main() {
const chainBlockPadding = 20
const xPadding = 76

// check tmp dir
const tmpDir = './temp';
if (!fs.existsSync(tmpDir)){
fs.mkdirSync(tmpDir);
}

// download chain images
console.log(`Download ${Object.keys(chains).length} chain images..`)
for (const chainId in chains) {
Expand All @@ -42,8 +46,8 @@ async function main() {
console.log()

// Instantiate the canvas object
const canvas = createCanvas(width, height);
const ctx = canvas.getContext("2d");
let canvas = createCanvas(width, height);
let ctx = canvas.getContext("2d");

// bg
const bgColor = '#15003b'
Expand Down Expand Up @@ -125,6 +129,45 @@ async function main() {
const buffer = canvas.toBuffer("image/png");
fs.writeFileSync(filename, buffer);
console.log(`Image of chains collection generated and saved to ${filename}`)

// draw covers
for (const chainId in chains) {
const chain = chains[chainId]
// Dimensions for the image
const coverWidth = 1000;
const coverHeight = 1000;

// Instantiate the canvas object
canvas = createCanvas(coverWidth, coverHeight);
ctx = canvas.getContext("2d");

// bg
// const bgColor = '#15003b'
ctx.fillStyle = bgColor;
ctx.fillRect(0, 0, coverWidth, coverHeight);

// chain name
ctx.font = 'bold 90px "Sans"'
ctx.fillStyle = "#ffffff";
ctx.fillText(chain.name, 100, 830)
ctx.font = '40px "Sans"'
ctx.fillText(`Chain ID: ${chainId}`, 100, 900)

// image
const image = await loadImage(`${tmpDir}/${chain.img}`)
ctx.drawImage(
image,
250,
170,
500,
500
)

// Write the image to file
const buffer = canvas.toBuffer("image/png");
fs.writeFileSync(`${coversDir}/${chainId}.png`, buffer);
}
console.log(`Covers of chains generated and saved to ${coversDir}`)
}

async function downloadFile(url:string, filepath:string) {
Expand Down

0 comments on commit 9370d0c

Please sign in to comment.