-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
164 additions
and
46 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
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,96 @@ | ||
import { BigInt, log } from "@graphprotocol/graph-ts"; | ||
import { | ||
BEAN_ERC20, | ||
BEAN_ERC20_V1, | ||
WETH, | ||
CRV3_TOKEN, | ||
LUSD, | ||
BEAN_WETH_V1, | ||
BEAN_3CRV_V1, | ||
BEAN_LUSD_V1, | ||
BEAN_3CRV, | ||
BEAN_WETH_CP2_WELL | ||
} from "../../../subgraph-core/utils/Constants"; | ||
|
||
// Use this mapping to determine which tokens are in each pool. Pools may each follow a distinct interface, | ||
// so a view function shouldn't be used, and a new subgraph build is already required to track a newly whitelisted asset. | ||
export function getTokensForPool(pool: string): string[] { | ||
for (let i = 0; i < poolTokens.length; ++i) { | ||
if (poolTokens[i].pool == pool) { | ||
return poolTokens[i].tokens; | ||
} | ||
} | ||
throw new Error("Pool has not been configured"); | ||
} | ||
|
||
// Name/Decimals are not guaranteed as part of the ERC20 interface, so predefined values are necessary | ||
export function getTokenInfo(token: string): TokenInfo { | ||
for (let i = 0; i < tokens.length; ++i) { | ||
if (tokens[i].address == token) { | ||
return tokens[i].info; | ||
} | ||
} | ||
throw new Error("Token has not been configured"); | ||
} | ||
|
||
class PoolTokens { | ||
pool: string; | ||
tokens: string[]; | ||
} | ||
// WHITELIST: Add new pools here | ||
const poolTokens: PoolTokens[] = [ | ||
{ | ||
pool: BEAN_WETH_V1.toHexString(), | ||
tokens: [BEAN_ERC20_V1.toHexString(), WETH.toHexString()] | ||
}, | ||
{ | ||
pool: BEAN_3CRV_V1.toHexString(), | ||
tokens: [BEAN_ERC20_V1.toHexString(), CRV3_TOKEN.toHexString()] | ||
}, | ||
{ | ||
pool: BEAN_LUSD_V1.toHexString(), | ||
tokens: [BEAN_ERC20_V1.toHexString(), LUSD.toHexString()] | ||
}, | ||
{ | ||
pool: BEAN_3CRV.toHexString(), | ||
tokens: [BEAN_ERC20.toHexString(), CRV3_TOKEN.toHexString()] | ||
}, | ||
{ | ||
pool: BEAN_WETH_CP2_WELL.toHexString(), | ||
tokens: [BEAN_ERC20.toHexString(), WETH.toHexString()] | ||
} | ||
]; | ||
|
||
class Token { | ||
address: string; | ||
info: TokenInfo; | ||
} | ||
|
||
class TokenInfo { | ||
name: string; | ||
decimals: BigInt; | ||
} | ||
|
||
// WHITELIST: Add new tokens here | ||
const tokens: Token[] = [ | ||
{ | ||
address: BEAN_ERC20_V1.toHexString(), | ||
info: { name: "BEAN", decimals: BigInt.fromU32(6) } | ||
}, | ||
{ | ||
address: BEAN_ERC20.toHexString(), | ||
info: { name: "BEAN", decimals: BigInt.fromU32(6) } | ||
}, | ||
{ | ||
address: WETH.toHexString(), | ||
info: { name: "WETH", decimals: BigInt.fromU32(18) } | ||
}, | ||
{ | ||
address: CRV3_TOKEN.toHexString(), | ||
info: { name: "3CRV", decimals: BigInt.fromU32(18) } | ||
}, | ||
{ | ||
address: LUSD.toHexString(), | ||
info: { name: "LUSD", decimals: BigInt.fromU32(18) } | ||
} | ||
]; |
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,27 @@ | ||
import { afterEach, clearStore, describe, assert, test } from "matchstick-as/assembly/index"; | ||
import { loadOrCreateToken } from "../src/utils/Token"; | ||
import { BEAN_3CRV, BEAN_ERC20, BEAN_ERC20_V1, BEAN_WETH_V1, CRV3_TOKEN, WETH } from "../../subgraph-core/utils/Constants"; | ||
import { BigInt } from "@graphprotocol/graph-ts"; | ||
import { loadOrCreatePool } from "../src/utils/Pool"; | ||
|
||
describe("Token", () => { | ||
afterEach(() => { | ||
clearStore(); | ||
}); | ||
|
||
test("Pool and its tokens are assigned appropriate metadata", () => { | ||
const pool = loadOrCreatePool(BEAN_WETH_V1.toHexString(), BigInt.fromU32(14500000)); | ||
assert.stringEquals(BEAN_ERC20_V1.toHexString(), pool.tokens[0]); | ||
assert.stringEquals(WETH.toHexString(), pool.tokens[1]); | ||
|
||
assert.fieldEquals("Token", BEAN_ERC20_V1.toHexString(), "decimals", "6"); | ||
assert.fieldEquals("Token", WETH.toHexString(), "decimals", "18"); | ||
|
||
const pool2 = loadOrCreatePool(BEAN_3CRV.toHexString(), BigInt.fromU32(17500000)); | ||
assert.stringEquals(BEAN_ERC20.toHexString(), pool2.tokens[0]); | ||
assert.stringEquals(CRV3_TOKEN.toHexString(), pool2.tokens[1]); | ||
|
||
assert.fieldEquals("Token", BEAN_ERC20.toHexString(), "decimals", "6"); | ||
assert.fieldEquals("Token", CRV3_TOKEN.toHexString(), "decimals", "18"); | ||
}); | ||
}); |
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