Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: Token fixes and improvements #1618

Merged
merged 23 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
3962cac
feat!(token configuration): Remove fetchDecimalsFromAddress
espendk Nov 24, 2023
535e0fa
feat!(unit calculations): Only accept decimals, not token name/symbol
espendk Nov 24, 2023
ec90e52
feat!: Remove token configuration getters&setters from Mangrove class
espendk Nov 24, 2023
02adda8
feat!: Remove Mangrove.getTokenAndAddress
espendk Nov 24, 2023
06aa630
feat!: Remove configuration getters&setters from MgvToken class
espendk Nov 24, 2023
1dfba25
feat!/fix: Replace token names with id and symbol
espendk Nov 24, 2023
2dd7a87
feat: Read token decimals and symbol from context-addresses
espendk Nov 24, 2023
5eba8c3
feat: Add functions to manage and create default token from symbol
espendk Nov 24, 2023
c464333
feat!: Replace getNameFromAddress with getTokenIdFromAddress
espendk Nov 24, 2023
71ff31d
feat!: openMarkets uses MgvToken instead of a bespoke struct
espendk Nov 24, 2023
67ce83d
feat!: Rename MgvToken to Token
espendk Nov 24, 2023
16a7de6
feat: Also accept `Token` as base and quote when connecting to a market
espendk Nov 24, 2023
be937e5
feat: Use data from configuration when creating token from address
espendk Nov 24, 2023
a921150
feat: Use token configuration in Mangrove.openMarkets
espendk Nov 24, 2023
99f3a08
feat: Add getTokenAddress(symbolOrId)
espendk Nov 24, 2023
a87f89d
refactor: Simplify token construction
espendk Nov 24, 2023
393e906
feat: Add displayedAsPriceDecimals to Token
espendk Nov 24, 2023
ec4f4bb
docs: Fix comments
espendk Nov 24, 2023
2a3cd4f
docs: Expand TODO comment
espendk Nov 27, 2023
74f6a04
refactor: Remove unnecessary awaits
espendk Nov 27, 2023
de49baf
feat: Throw error if default token ID is undefined
espendk Nov 27, 2023
e34e47f
feat: Throw error in `Token.getDecimals` if decimals are not on record
espendk Nov 27, 2023
cf28775
Merge branch 'develop' into feat/token-fixes
espendk Nov 27, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Next version

- feat!: `MgvToken` has been renamed to `Token`.
- feat!: Removed `configuration.tokens.fetchDecimalsFromAddress`. Instead, use `Token.createTokenFromAddress` and read the decimals from that token.
- feat!: `Mangrove.toUnits|fromUnits` no longer accepts a token name/symbol as this was ambiguous. Instead, use `Token.createToken` and call `toUnits|fromUnits` on that.
- feat!: Static token configuration getters and setters have been removed from `Mangrove` and `Token`. Instead, use the methods on `configuration.token`.
- feat!: `Mangrove.getTokenAndAddress` has been removed. Instead, use `Mangrove.tokenFromAddress` and read the address from there.
- feat!: Remove `Mangrove.tokenFromConfig`. Use `Mangrove.token` instead.
- feat!/fix: Token `name` was misused: Sometimes it was assumed to be a symbol and sometimes an ID. It has therefore been replaced by `id` and `symbol` in all relevant places. Configuration files have been converted to use the token instance ID's from the context-addresses package to avoid ambiguity among (1) different tokens with the same symbol and (2) multiple token instances such as `USDC` (Circle issued) and `USDC.e` (bridged from Ethereum).
- Default token IDs can be registered for a symbol and network. And if there is only one ID for a given symbol on a network, it will be considered the default. `Mangrove.token()` will create an instance of the default token ID if found.
- feat!: `Mangrove.getNameFromAddress` has been removed: It was ambiguous (multiple names could be registered) and only used for resolving tokens which can now be done with the new `configuration.tokens.getTokenIdFromAddress()` function.
- feat!: The `Mangrove.openMarkets` function now uses `Token` instead of a bespoke token data struct.
- feat: `Mangrove.market` and `Market.connect` now accept either symbol, token ID, or `Token` for base and quote.
- feat: Added `displayName` and `displayedAsPriceDecimals` to `Token`.
- feat!: `Token.getDecimals` now throws an error instead of returning undefined if the decimals are not on record.

# 2.0.0-8

# 2.0.0-7
Expand Down
22 changes: 11 additions & 11 deletions examples/aaveV3Module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ class AaveV3Module {
}

async #debtToken(
tokenName: string,
tokenId: string,
signer?: SignerOrProvider,
): Promise<typechain.ICreditDelegationToken> {
const asset_address = this.mgv.getAddress(tokenName);
const asset_address = this.mgv.getTokenAddress(tokenId);
const debt_address = await this.contract.debtToken(asset_address);
return typechain.ICreditDelegationToken__factory.connect(
debt_address,
Expand All @@ -39,11 +39,11 @@ class AaveV3Module {
}

async approveDelegation(
tokenName: string,
tokenId: string,
borrower: string,
overrides: ethers.Overrides = {},
): Promise<ethers.ContractTransaction> {
const dTtkn = await this.#debtToken(tokenName);
const dTtkn = await this.#debtToken(tokenId);
return dTtkn.approveDelegation(
borrower,
ethers.constants.MaxUint256,
Expand All @@ -52,11 +52,11 @@ class AaveV3Module {
}

async status(
tokenName: string,
tokenId: string,
account: string,
): Promise<{ available: Big; borrowable: Big; borrowing: Big }> {
const asset = await this.mgv.token(tokenName);
const dToken = await this.#debtToken(tokenName);
const asset = await this.mgv.token(tokenId);
const dToken = await this.#debtToken(tokenId);
const { maxRedeemableUnderlying, maxBorrowAfterRedeemInUnderlying } =
await this.contract.maxGettableUnderlying(asset.address, true, account);
return {
Expand All @@ -66,11 +66,11 @@ class AaveV3Module {
};
}

async logStatus(tokenNames: string[], account?: string): Promise<void> {
async logStatus(tokenIds: string[], account?: string): Promise<void> {
account = account ? account : await this.mgv.signer.getAddress();
for (const tokenName of tokenNames) {
const stat = await this.status(tokenName, account);
console.log(`----------${tokenName}----------`);
for (const tokenId of tokenIds) {
const stat = await this.status(tokenId, account);
console.log(`----------${tokenId}----------`);
console.log("debit:", `\u001b[32m${stat.available}\u001b[0m`);
console.log("credit:", `\u001b[33m${stat.borrowable}\u001b[0m`);
console.log("debt:", `\u001b[31m${stat.borrowing}\u001b[0m`);
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@
"just-clone": "^6.2.0",
"logform": "^2.5.1",
"loglevel": "^1.8.1",
"moize": "^6.1.6",
"node-cleanup": "^2.1.2",
"object-inspect": "^1.12.3",
"semver": "^7.5.4",
Expand Down
Loading