Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"@venusprotocol/governance-contracts": "2.10.0",
"@venusprotocol/isolated-pools": "4.2.0-dev.9",
"@venusprotocol/oracle": "2.9.0",
"@venusprotocol/protocol-reserve": "3.1.0",
"@venusprotocol/protocol-reserve": "3.4.0-dev.3",
"@venusprotocol/solidity-utilities": "^2.0.3",
"@venusprotocol/venus-protocol": "9.6.0",
"assemblyscript": "0.19.23",
Expand Down Expand Up @@ -90,7 +90,7 @@
"resolutions": {
"@venusprotocol/governance-contracts": "2.10.0",
"@venusprotocol/venus-protocol": "9.6.0",
"@venusprotocol/protocol-reserve": "3.1.0",
"@venusprotocol/protocol-reserve": "3.4.0-dev.3",
"prettier": "^3.0.3"
},
"husky": {
Expand Down
6 changes: 6 additions & 0 deletions subgraphs/protocol-reserve/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ const main = () => {
usdtPrimeConverterStartBlock: '0',
xvsVaultConverterAddress: '0xa779C1D17bC5230c07afdC51376CAC1cb3Dd5314',
xvsVaultConverterStartBlock: '0',
wBnbBurnConverterAddress: '0xa079C1D17bC5230c07afdC51376CAC1cb3Dd5314',
wBnbBurnConverterStartBlock: '0',
riskFundAddress: '0x8d81a3dcd17030cd5f23ac7370e4efb10d2b3ca4',
protocolShareReserveAddress: '0x70e0bA845a1A0F2DA3359C97E0285013525FFC49',
protocolShareReserveStartBlock: '0',
Expand All @@ -55,6 +57,8 @@ const main = () => {
usdtPrimeConverterStartBlock: '36750639',
xvsVaultConverterAddress: chapelDeployments.addresses.XVSVaultConverter,
xvsVaultConverterStartBlock: '36750678',
wBnbBurnConverterAddress: chapelDeployments.addresses.WBNBBurnConverter,
wBnbBurnConverterStartBlock: '54160930',
riskFundAddress: chapelDeployments.addresses.RiskFundV2,
StartBlock: '36750498',
protocolShareReserveAddress: chapelDeployments.addresses.ProtocolShareReserve,
Expand All @@ -77,6 +81,8 @@ const main = () => {
usdtPrimeConverterStartBlock: '35140081',
xvsVaultConverterAddress: bscMainnetDeployments.addresses.XVSVaultConverter,
xvsVaultConverterStartBlock: '35140090',
wBnbBurnConverterAddress: bscMainnetDeployments.addresses.WBNBBurnConverter,
wBnbBurnConverterStartBlock: '51144405',
riskFundAddress: bscMainnetDeployments.addresses.RiskFundV2,
protocolShareReserveAddress: bscMainnetDeployments.addresses.ProtocolShareReserve,
protocolShareReserveStartBlock: '32659440',
Expand Down
12 changes: 12 additions & 0 deletions subgraphs/protocol-reserve/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type TokenConverter @entity {
destinationAddress: Bytes!
baseAsset: Token!
configs: [TokenConverterConfig!]! @derivedFrom(field: "tokenConverter")
destinationAmounts: [DestinationAmount!]! @derivedFrom(field: "tokenConverter")
paused: Boolean!
priceOracleAddress: Bytes!
}
Expand All @@ -54,3 +55,14 @@ type TokenConverterConfig @entity {
access: ConversionAccessibility!
tokenOutBalance: BigInt!
}

"""
Destination Amounts
"""
type DestinationAmount @entity {
id: Bytes!
address: Bytes!
tokenConverter: TokenConverter!
token: Token!
amount: BigInt!
}
2 changes: 2 additions & 0 deletions subgraphs/protocol-reserve/src/constants/addresses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
wbtcPrimeConverterAddress as wbtcPrimeConverterAddressString,
wethPrimeConverterAddress as wethPrimeConverterAddressString,
xvsVaultConverterAddress as xvsVaultConverterAddressString,
wBnbBurnConverterAddress as wBnbBurnConverterAddressString,
} from './config';

export const nullAddress = Address.fromString('0x0000000000000000000000000000000000000000');
Expand All @@ -31,5 +32,6 @@ export const usdtPrimeConverterAddress = addressFromCleanString(usdtPrimeConvert
export const xvsVaultConverterAddress = addressFromCleanString(xvsVaultConverterAddressString);
export const wbtcPrimeConverterAddress = addressFromCleanString(wbtcPrimeConverterAddressString);
export const wethPrimeConverterAddress = addressFromCleanString(wethPrimeConverterAddressString);
export const wBnbBurnConverterAddress = addressFromCleanString(wBnbBurnConverterAddressString);

export const riskFundAddress = addressFromCleanString(riskFundAddressString);
1 change: 1 addition & 0 deletions subgraphs/protocol-reserve/src/constants/config-template
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const riskFundConverterAddress = '{{riskFundConverterAddress}}';
export const usdcPrimeConverterAddress = '{{usdcPrimeConverterAddress}}';
export const usdtPrimeConverterAddress = '{{usdtPrimeConverterAddress}}';
export const xvsVaultConverterAddress = '{{xvsVaultConverterAddress}}';
export const wBnbBurnConverterAddress = '{{wBnbBurnConverterAddress}}';
export const wbtcPrimeConverterAddress = '{{wbtcPrimeConverterAddress}}';
export const wethPrimeConverterAddress = '{{wethPrimeConverterAddress}}';

57 changes: 55 additions & 2 deletions subgraphs/protocol-reserve/src/mappings/tokenConverter.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { ethereum } from '@graphprotocol/graph-ts';
import { Address, ethereum } from '@graphprotocol/graph-ts';

import {
AssetTransferredToDestination,
BaseAssetUpdated,
ConvertedExactTokens,
ConversionConfigUpdated,
ConversionPaused,
ConversionResumed,
Expand All @@ -18,9 +20,10 @@ import {
wbtcPrimeConverterAddress,
wethPrimeConverterAddress,
xvsVaultConverterAddress,
wBnbBurnConverterAddress,
} from '../constants/addresses';
import { getTokenConverter } from '../operations/get';
import { getOrCreateTokenConverter } from '../operations/getOrCreate';
import { getOrCreateDestinationAmount, getOrCreateTokenConverter } from '../operations/getOrCreate';
import { updateOrCreateTokenConverterConfig } from '../operations/updateOrCreate';
import { getConverterNetworkId } from '../utilities/ids';

Expand Down Expand Up @@ -59,6 +62,11 @@ export function handleInitializationWethPrimeConverter(block: ethereum.Block): v
getOrCreateTokenConverter(wethPrimeConverterAddress);
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
export function handleInitializationWBnbBurnConverter(block: ethereum.Block): void {
getOrCreateTokenConverter(wBnbBurnConverterAddress);
}
Comment on lines +65 to +68
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: since block is unused, you shouldn't need to define it at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function signature needs to match the template exactly, so the parameter needs to be declared even if unused


export function handleConversionConfigUpdated(event: ConversionConfigUpdated): void {
getOrCreateTokenConverter(event.address);
updateOrCreateTokenConverterConfig(event.address, event.params);
Expand Down Expand Up @@ -99,3 +107,48 @@ export function handlePriceOracleUpdated(event: PriceOracleUpdated): void {
tokenConverter.priceOracleAddress = event.params.priceOracle;
tokenConverter.save();
}

export function handleConvertedExactTokens(event: ConvertedExactTokens): void {
const tokenConverter = getTokenConverter(event.address)!;

// handle private conversions (conversions between converters)
const senderConverter = getTokenConverter(event.params.sender);
if (!!senderConverter && senderConverter.address !== riskFundConverterAddress) {
const senderDestinationAmount = getOrCreateDestinationAmount(
Address.fromBytes(senderConverter.address),
Address.fromBytes(senderConverter.destinationAddress),
event.params.tokenAddressOut,
);
senderDestinationAmount.amount = senderDestinationAmount.amount.plus(event.params.amountOut);
senderDestinationAmount.save();
}

const destinationAmountEntity = getOrCreateDestinationAmount(
event.address,
Address.fromBytes(tokenConverter.destinationAddress),
event.params.tokenAddressIn,
);
destinationAmountEntity.amount = destinationAmountEntity.amount.plus(event.params.amountIn);
destinationAmountEntity.save();
}

export function handleConversionEvent(event: ConvertedExactTokens): void {
const tokenConverter = getTokenConverter(event.address)!;
const destinationAmountEntity = getOrCreateDestinationAmount(
event.address,
Address.fromBytes(tokenConverter.destinationAddress),
event.params.tokenAddressIn,
);
destinationAmountEntity.amount = destinationAmountEntity.amount.plus(event.params.amountIn);
destinationAmountEntity.save();
}

export function handleAssetTransferredToDestination(event: AssetTransferredToDestination): void {
const destinationAmountEntity = getOrCreateDestinationAmount(
event.address,
event.params.receiver,
event.params.asset,
);
destinationAmountEntity.amount = destinationAmountEntity.amount.plus(event.params.amount);
destinationAmountEntity.save();
}
38 changes: 34 additions & 4 deletions subgraphs/protocol-reserve/src/operations/getOrCreate.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { Address } from '@graphprotocol/graph-ts';
import { Address, BigInt } from '@graphprotocol/graph-ts';

import { ERC20 } from '../../generated/RiskFundConverter/ERC20';
import { Token, TokenConverter, TokenConverterConfig } from '../../generated/schema';
import { getAssetId } from '../utilities/ids';
import {
DestinationAmount,
Token,
TokenConverter,
TokenConverterConfig,
} from '../../generated/schema';
import { getAssetId, getDestinationAmountId, getTokenConverterId } from '../utilities/ids';
import { createTokenConverter, createTokenConverterConfig } from './create';
import { getTokenConverter, getTokenConverterConfig } from './get';

Expand Down Expand Up @@ -44,7 +49,7 @@ export function getOrCreateTokenConverterConfig(
}

/**
* Creates and Token object with symbol and address
* Creates a Token object with symbol and address
*
* @param asset Address of the token
* @returns Token
Expand All @@ -62,3 +67,28 @@ export function getOrCreateToken(asset: Address): Token {
}
return tokenEntity;
}

/**
* Creates a DestinationAmount object
*
* @param asset Address of the token
* @returns Token
*/
export function getOrCreateDestinationAmount(
tokenConverterAddress: Address,
destinationAddress: Address,
tokenAddress: Address,
): DestinationAmount {
const entityId = getDestinationAmountId(tokenConverterAddress, destinationAddress, tokenAddress);
let destinationAmountEntity = DestinationAmount.load(entityId);

if (!destinationAmountEntity) {
destinationAmountEntity = new DestinationAmount(entityId);
destinationAmountEntity.tokenConverter = getTokenConverterId(tokenConverterAddress);
destinationAmountEntity.token = getOrCreateToken(tokenAddress).id;
destinationAmountEntity.amount = BigInt.zero();
destinationAmountEntity.address = destinationAddress;
}

return destinationAmountEntity;
}
6 changes: 6 additions & 0 deletions subgraphs/protocol-reserve/src/utilities/ids.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@ export const getTokenConverterConfigId = (
): Bytes => tokenConverterAddress.concat(tokenAddressIn).concat(tokenAddressOut);

export const getAssetId = (asset: Address): Bytes => asset;

export const getDestinationAmountId = (
tokenConverterAddress: Address,
destinationAddress: Address,
tokenAddress: Address,
): Bytes => tokenConverterAddress.concat(destinationAddress).concat(tokenAddress);
Loading
Loading