-
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.
feat: add support for deposit and requestWithdrawal events on xvsvault
- Loading branch information
Showing
18 changed files
with
254 additions
and
111 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
// Use yarn prepare commands to generate config typescript file per env | ||
|
||
export const governorBravoDelegateAddress = '{{ governorBravoDelegateAddress }}'; | ||
|
||
export const xvsVaultPid = '{{ xvsVaultPid }}'; | ||
|
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,50 @@ | ||
import { Address, BigInt, ethereum } from '@graphprotocol/graph-ts'; | ||
import { newMockEvent } from 'matchstick-as'; | ||
|
||
import { Deposit, ReqestedWithdrawal } from '../../generated/XVSVault/XVSVault'; | ||
import { mockXvsAddress } from '../common/constants'; | ||
|
||
export function createXvsDepositEvent(user: Address, amount: BigInt): Deposit { | ||
const event = changetype<Deposit>(newMockEvent()); | ||
event.parameters = []; | ||
|
||
const userParam = new ethereum.EventParam('user', ethereum.Value.fromAddress(user)); | ||
event.parameters.push(userParam); | ||
|
||
const rewardTokenParam = new ethereum.EventParam( | ||
'rewardToken', | ||
ethereum.Value.fromAddress(mockXvsAddress), | ||
); | ||
event.parameters.push(rewardTokenParam); | ||
|
||
const pidParam = new ethereum.EventParam('pid', ethereum.Value.fromUnsignedBigInt(new BigInt(0))); | ||
event.parameters.push(pidParam); | ||
|
||
const amountParam = new ethereum.EventParam('amount', ethereum.Value.fromUnsignedBigInt(amount)); | ||
event.parameters.push(amountParam); | ||
return event; | ||
} | ||
|
||
export function createXvsWithdrawlRequestedEvent( | ||
user: Address, | ||
amount: BigInt, | ||
): ReqestedWithdrawal { | ||
const event = changetype<ReqestedWithdrawal>(newMockEvent()); | ||
event.parameters = []; | ||
|
||
const userParam = new ethereum.EventParam('user', ethereum.Value.fromAddress(user)); | ||
event.parameters.push(userParam); | ||
|
||
const rewardTokenParam = new ethereum.EventParam( | ||
'rewardToken', | ||
ethereum.Value.fromAddress(mockXvsAddress), | ||
); | ||
event.parameters.push(rewardTokenParam); | ||
|
||
const pidParam = new ethereum.EventParam('pid', ethereum.Value.fromUnsignedBigInt(new BigInt(0))); | ||
event.parameters.push(pidParam); | ||
|
||
const amountParam = new ethereum.EventParam('amount', ethereum.Value.fromUnsignedBigInt(amount)); | ||
event.parameters.push(amountParam); | ||
return event; | ||
} |
117 changes: 117 additions & 0 deletions
117
subgraphs/venus-governance/tests/XVSVault/index.test.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,117 @@ | ||
import { Address, BigInt } from '@graphprotocol/graph-ts'; | ||
import { assert, beforeAll, beforeEach, describe, test } from 'matchstick-as/assembly/index'; | ||
|
||
import { ProposalCreated } from '../../generated/GovernorBravoDelegate/GovernorBravoDelegate'; | ||
import { DelegateChangedV2 } from '../../generated/XVSVault/XVSVault'; | ||
import { handleProposalCreated } from '../../src/mappings/bravo'; | ||
import { | ||
handleDelegateChanged, | ||
handleDeposit, | ||
handleRequestedWithdrawal, | ||
} from '../../src/mappings/xvsVault'; | ||
import { getOrCreateDelegate } from '../../src/operations/getOrCreate'; | ||
import { user1, user2, user3 } from '../common/constants'; | ||
import { createDelegateChangedEvent, createProposalCreatedEvent } from '../common/events'; | ||
import { createGovernorBravoMocks } from '../common/mocks'; | ||
import { createXvsDepositEvent, createXvsWithdrawlRequestedEvent } from './events'; | ||
|
||
const startBlock = 4563820; | ||
const endBlock = 4593820; | ||
const description = 'Very creative Proposal'; | ||
|
||
beforeAll(() => { | ||
createGovernorBravoMocks(); | ||
}); | ||
|
||
beforeEach(() => { | ||
/** setup test */ | ||
getOrCreateDelegate(user1.toHexString()); | ||
const proposalCreatedEvent = createProposalCreatedEvent<ProposalCreated>( | ||
1, | ||
user1, | ||
[], | ||
[], | ||
[], | ||
[], | ||
BigInt.fromI64(startBlock), | ||
BigInt.fromI64(endBlock), | ||
description, | ||
); | ||
handleProposalCreated(proposalCreatedEvent); | ||
}); | ||
|
||
describe('XVS Vault', () => { | ||
test('should create new delegate on first deposit', () => { | ||
const user = Address.fromString('0x0000000000000000000000000000000000000404'); | ||
const amount = '1000000000000000000'; | ||
/** run handler */ | ||
const depositEvent = createXvsDepositEvent(user, BigInt.fromString(amount)); | ||
// Expect delete not to exist | ||
assert.entityCount('Delegate', 1); | ||
|
||
handleDeposit(depositEvent); | ||
|
||
// Expect value to be updated | ||
assert.entityCount('Delegate', 2); | ||
assert.fieldEquals('Delegate', user.toHex(), 'stakedXvsMantissa', amount); | ||
}); | ||
|
||
test("should update delegate's total after withdrawl requested", () => { | ||
const user = Address.fromString('0x0000000000000000000000000000000000000404'); | ||
const amount = '200000000000000000'; | ||
/** run handler */ | ||
const withdrawRequestedEvent = createXvsWithdrawlRequestedEvent( | ||
user, | ||
BigInt.fromString(amount), | ||
); | ||
// Expect delete not to exist | ||
assert.entityCount('Delegate', 2); | ||
|
||
handleRequestedWithdrawal(withdrawRequestedEvent); | ||
|
||
// Expect value to be updated | ||
assert.entityCount('Delegate', 2); | ||
assert.fieldEquals('Delegate', user.toHex(), 'stakedXvsMantissa', '800000000000000000'); | ||
}); | ||
|
||
test('removes delegate after withdrawing everything', () => { | ||
const user = Address.fromString('0x0000000000000000000000000000000000000404'); | ||
const amount = '800000000000000000'; | ||
/** run handler */ | ||
const withdrawRequestedEvent = createXvsWithdrawlRequestedEvent( | ||
user, | ||
BigInt.fromString(amount), | ||
); | ||
// Expect delete not to exist | ||
assert.entityCount('Delegate', 2); | ||
|
||
handleRequestedWithdrawal(withdrawRequestedEvent); | ||
|
||
// Expect delegate to have been removed | ||
assert.entityCount('Delegate', 1); | ||
}); | ||
|
||
test('delegate changed', () => { | ||
const delegator = user1; | ||
const fromDelegate = user2; | ||
const toDelegate = user3; | ||
/** run handler */ | ||
const delegateChangedEvent = createDelegateChangedEvent<DelegateChangedV2>( | ||
delegator, | ||
fromDelegate, | ||
toDelegate, | ||
); | ||
handleDelegateChanged(delegateChangedEvent); | ||
// OldDelegate | ||
const assertOldDelegateDocument = (key: string, value: string): void => { | ||
assert.fieldEquals('Delegate', user2.toHex(), key, value); | ||
}; | ||
assertOldDelegateDocument('delegateCount', '-1'); | ||
|
||
// New Delegate | ||
const assertNewDelegateDocument = (key: string, value: string): void => { | ||
assert.fieldEquals('Delegate', user3.toHex(), key, value); | ||
}; | ||
assertNewDelegateDocument('delegateCount', '1'); | ||
}); | ||
}); |
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
78 changes: 0 additions & 78 deletions
78
subgraphs/venus-governance/tests/unit/Bravo/xvsVault.test.ts
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.