-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #196 from VenusProtocol/add-token-out-balance-to-c…
…onverter-config Add token out balance to converter config
- Loading branch information
Showing
24 changed files
with
526 additions
and
88 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
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 |
---|---|---|
@@ -1,12 +1,35 @@ | ||
import { Address } from '@graphprotocol/graph-ts'; | ||
|
||
import { | ||
btcbPrimeConverterAddress as btcbPrimeConverterAddressString, | ||
converterNetworkAddress as converterNetworkAddressString, | ||
ethPrimeConverterAddress as ethPrimeConverterAddressString, | ||
riskFundAddress as riskFundAddressString, | ||
riskFundConverterAddress as riskFundConverterAddressString, | ||
usdcPrimeConverterAddress as usdcPrimeConverterAddressString, | ||
usdtPrimeConverterAddress as usdtPrimeConverterAddressString, | ||
wbtcPrimeConverterAddress as wbtcPrimeConverterAddressString, | ||
wethPrimeConverterAddress as wethPrimeConverterAddressString, | ||
xvsVaultConverterAddress as xvsVaultConverterAddressString, | ||
} from './config'; | ||
|
||
export const converterNetworkAddress = Address.fromString(converterNetworkAddressString); | ||
export const riskFundConverterAddress = Address.fromString(riskFundConverterAddressString); | ||
export const riskFundAddress = Address.fromString(riskFundAddressString); | ||
export const nullAddress = Address.fromString('0x0000000000000000000000000000000000000000'); | ||
|
||
const addressFromCleanString = (str: string): Address => { | ||
if (str.length > 0) { | ||
return Address.fromString(str); | ||
} | ||
return nullAddress; | ||
}; | ||
|
||
export const converterNetworkAddress = addressFromCleanString(converterNetworkAddressString); | ||
export const riskFundConverterAddress = addressFromCleanString(riskFundConverterAddressString); | ||
export const btcbPrimeConverterAddress = addressFromCleanString(btcbPrimeConverterAddressString); | ||
export const ethPrimeConverterAddress = addressFromCleanString(ethPrimeConverterAddressString); | ||
export const usdcPrimeConverterAddress = addressFromCleanString(usdcPrimeConverterAddressString); | ||
export const usdtPrimeConverterAddress = addressFromCleanString(usdtPrimeConverterAddressString); | ||
export const xvsVaultConverterAddress = addressFromCleanString(xvsVaultConverterAddressString); | ||
export const wbtcPrimeConverterAddress = addressFromCleanString(wbtcPrimeConverterAddressString); | ||
export const wethPrimeConverterAddress = addressFromCleanString(wethPrimeConverterAddressString); | ||
|
||
export const riskFundAddress = addressFromCleanString(riskFundAddressString); |
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 |
---|---|---|
@@ -1,6 +1,13 @@ | ||
// Use yarn prepare commands to generate config typescript file per env | ||
|
||
export const converterNetworkAddress = '{{ converterNetworkAddress }}'; | ||
export const riskFundConverterAddress = '{{ riskFundConverterAddress }}'; | ||
export const riskFundAddress = '{{ riskFundAddress }}'; | ||
export const btcbPrimeConverterAddress = '{{btcbPrimeConverterAddress}}'; | ||
export const ethPrimeConverterAddress = '{{ethPrimeConverterAddress}}'; | ||
export const riskFundConverterAddress = '{{riskFundConverterAddress}}'; | ||
export const usdcPrimeConverterAddress = '{{usdcPrimeConverterAddress}}'; | ||
export const usdtPrimeConverterAddress = '{{usdtPrimeConverterAddress}}'; | ||
export const xvsVaultConverterAddress = '{{xvsVaultConverterAddress}}'; | ||
export const wbtcPrimeConverterAddress = '{{wbtcPrimeConverterAddress}}'; | ||
export const wethPrimeConverterAddress = '{{wethPrimeConverterAddress}}'; | ||
|
10 changes: 8 additions & 2 deletions
10
subgraphs/protocol-reserve/src/mappings/converterNetwork.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
17 changes: 17 additions & 0 deletions
17
subgraphs/protocol-reserve/src/mappings/protocolShareReserve.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,17 @@ | ||
import { AssetReleased } from '../../generated/ProtocolShareReserve/ProtocolShareReserve'; | ||
import { TokenConverterConfig } from '../../generated/schema'; | ||
import { getTokenConverter } from '../operations/get'; | ||
|
||
export function handleAssetReleased(event: AssetReleased): void { | ||
const tokenConverter = getTokenConverter(event.params.destination); | ||
if (tokenConverter) { | ||
const configs = tokenConverter.configs.load(); | ||
configs.reduce((e: AssetReleased, curr: TokenConverterConfig) => { | ||
if (e.params.asset.equals(curr.tokenOut)) { | ||
curr.tokenOutBalance = curr.tokenOutBalance.plus(e.params.amount); | ||
curr.save(); | ||
} | ||
return e; | ||
}, event); | ||
} | ||
} |
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 { TokenConverterConfig } from '../../generated/schema'; | ||
import { Transfer } from '../../generated/templates/Token/ERC20'; | ||
import { getTokenConverter } from '../operations/get'; | ||
|
||
export function handleTransferIn(event: Transfer): void { | ||
const tokenConverter = getTokenConverter(event.params.to)!; | ||
const configs = tokenConverter.configs.load(); | ||
configs.reduce((e: Transfer, curr: TokenConverterConfig) => { | ||
if (e.address.equals(curr.tokenOut)) { | ||
curr.tokenOutBalance = curr.tokenOutBalance.plus(e.params.value); | ||
curr.save(); | ||
} | ||
return e; | ||
}, event); | ||
} | ||
|
||
export function handleTransferOut(event: Transfer): void { | ||
const tokenConverter = getTokenConverter(event.params.from)!; | ||
const configs = tokenConverter.configs.load(); | ||
configs.reduce((e: Transfer, curr: TokenConverterConfig) => { | ||
if (e.address.equals(curr.tokenOut)) { | ||
curr.tokenOutBalance = curr.tokenOutBalance.minus(e.params.value); | ||
curr.save(); | ||
} | ||
return e; | ||
}, event); | ||
} |
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.