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

58 setup queries for nabla backend for campaign and mainnet reward program #62

Merged
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
6aa5b86
Apply codegen, typegen and migrations
TorstenStueber Jan 26, 2024
2519556
Change schema.graphql and nabla-abi to new Nabla version
TorstenStueber Jan 26, 2024
2106321
Adopt types from official Nabla indexer
TorstenStueber Jan 27, 2024
42cfd0d
Migrate squid logic to new Nabla
TorstenStueber Jan 31, 2024
46cd3e2
Implement properly working Nabla indexer
TorstenStueber Feb 19, 2024
a4ae1cb
Clean up debugging instructions
TorstenStueber Feb 19, 2024
6f127b5
Clean up output
TorstenStueber Feb 19, 2024
4709f4c
Resolve merge conflicts
TorstenStueber Feb 19, 2024
09de98c
Bump squid version
TorstenStueber Feb 19, 2024
9187105
Merge latest changes from main
TorstenStueber Feb 20, 2024
5b4b527
Additionally track lp token decimals
TorstenStueber Feb 21, 2024
3aa56fb
Incorporate new Nabla metadata
TorstenStueber Apr 25, 2024
704c224
Merge latest changes from main
TorstenStueber Apr 25, 2024
a6cecc8
Update generated files
TorstenStueber Apr 25, 2024
3327b3d
Handle new Nabla events
TorstenStueber Apr 25, 2024
ae15c89
Bump squid version
TorstenStueber Apr 25, 2024
fe71b51
Add new types to schema
bogdanS98 May 2, 2024
61fd22a
Regenerate models
bogdanS98 May 2, 2024
5602754
Create migration
bogdanS98 May 2, 2024
3e2debd
Update mappings
bogdanS98 May 2, 2024
d4152c6
Update mappings
bogdanS98 May 2, 2024
4ad7c45
Use Nabla ABIs compiled with solang 0.3.3
ebma May 6, 2024
f436f03
Amend README
ebma May 6, 2024
5a7da94
Merge branch '44-migrate-to-new-nabla-contracts' of https://github.co…
bogdanS98 May 6, 2024
20fe8aa
Clean up APR related code
TorstenStueber May 9, 2024
cb9ab7e
Revert "Use Nabla ABIs compiled with solang 0.3.3"
ebma May 16, 2024
c21623f
Merge branch '44-migrate-to-new-nabla-contracts' into 58-setup-querie…
ebma May 23, 2024
84d220c
Simplify logic for local network configuration
TorstenStueber May 23, 2024
672978d
git pushMerge branch '44-migrate-to-new-nabla-contracts' of github.co…
TorstenStueber May 23, 2024
9dab1b0
Removed unused variable
TorstenStueber May 23, 2024
8a543ff
Add console.logs to some early returns
TorstenStueber May 27, 2024
75b2cc2
Address comments
bogdanS98 May 28, 2024
03f2dd6
Regenerate models
bogdanS98 May 28, 2024
84460a6
Merge branch '44-migrate-to-new-nabla-contracts' of https://github.co…
bogdanS98 May 28, 2024
ee25e61
Regenerate models
bogdanS98 May 28, 2024
b684fd5
Address change requests
bogdanS98 May 30, 2024
37d714a
Regenerate models
bogdanS98 May 30, 2024
2bd07e7
Merge branch 'main' of https://github.com/pendulum-chain/pendulum-squ…
bogdanS98 May 30, 2024
5aaf990
Fix failed merge
bogdanS98 May 30, 2024
5957b14
Regenerate models
bogdanS98 May 30, 2024
99e48ef
Remove unnecessary comments
bogdanS98 May 30, 2024
4280449
Bump squid versions
bogdanS98 May 31, 2024
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = class Data1714034652645 {
name = 'Data1714034652645'
module.exports = class Data1717086042133 {
name = 'Data1717086042133'

async up(db) {
await db.query(
Expand Down Expand Up @@ -326,6 +326,42 @@ module.exports = class Data1714034652645 {
await db.query(
`CREATE TABLE "router" ("id" character varying NOT NULL, "paused" boolean NOT NULL, CONSTRAINT "PK_510c864aa88ac8eb3a306789801" PRIMARY KEY ("id"))`
)
await db.query(
`CREATE TABLE "nabla_swap" ("id" character varying NOT NULL, "timestamp" TIMESTAMP WITH TIME ZONE NOT NULL, "sender" text NOT NULL, "amount_in" numeric NOT NULL, "amount_out" numeric NOT NULL, "to" text NOT NULL, "token_in_id" character varying, "token_out_id" character varying, "swap_fee_id" character varying, CONSTRAINT "PK_6274610b518e1a9e61b1c6f03bb" PRIMARY KEY ("id"))`
)
await db.query(
`CREATE INDEX "IDX_78ad17aaf8e256aada35d50c95" ON "nabla_swap" ("token_in_id") `
)
await db.query(
`CREATE INDEX "IDX_3ddf0d667a8f06da7f6ab50004" ON "nabla_swap" ("token_out_id") `
)
await db.query(
`CREATE INDEX "IDX_dd24afed240ad46290bfcf0603" ON "nabla_swap" ("swap_fee_id") `
)
await db.query(
`CREATE TABLE "nabla_backstop_liquidity_deposit" ("id" character varying NOT NULL, "timestamp" TIMESTAMP WITH TIME ZONE NOT NULL, "sender" text NOT NULL, "pool_shares_minted" numeric NOT NULL, "amount_pool_tokens_deposited" numeric NOT NULL, "backstop_pool_id" character varying, CONSTRAINT "PK_6a7b952f6ac801d591360e47743" PRIMARY KEY ("id"))`
)
await db.query(
`CREATE INDEX "IDX_a3ce6e5ba78f5987919e7ee346" ON "nabla_backstop_liquidity_deposit" ("backstop_pool_id") `
)
await db.query(
`CREATE TABLE "nabla_swap_liquidity_deposit" ("id" character varying NOT NULL, "timestamp" TIMESTAMP WITH TIME ZONE NOT NULL, "sender" text NOT NULL, "pool_shares_minted" numeric NOT NULL, "amount_pool_tokens_deposited" numeric NOT NULL, "swap_pool_id" character varying, CONSTRAINT "PK_4788b03472eec9547df44a82c48" PRIMARY KEY ("id"))`
)
await db.query(
`CREATE INDEX "IDX_e0480f777845618674d1bbc3b1" ON "nabla_swap_liquidity_deposit" ("swap_pool_id") `
)
await db.query(
`CREATE TABLE "nabla_backstop_liquidity_withdrawal" ("id" character varying NOT NULL, "timestamp" TIMESTAMP WITH TIME ZONE NOT NULL, "sender" text NOT NULL, "pool_shares_burned" numeric NOT NULL, "amount_pool_tokens_withdrawn" numeric NOT NULL, "backstop_pool_id" character varying, CONSTRAINT "PK_9fca1665db21118d0b318e1f828" PRIMARY KEY ("id"))`
)
await db.query(
`CREATE INDEX "IDX_33f15234263ac9c6d07fe5441f" ON "nabla_backstop_liquidity_withdrawal" ("backstop_pool_id") `
)
await db.query(
`CREATE TABLE "nabla_swap_liquidity_withdrawal" ("id" character varying NOT NULL, "timestamp" TIMESTAMP WITH TIME ZONE NOT NULL, "sender" text NOT NULL, "pool_shares_burned" numeric NOT NULL, "amount_pool_tokens_withdrawn" numeric NOT NULL, "swap_pool_id" character varying, CONSTRAINT "PK_38c9ff7047fcf36ccbd4b7cb521" PRIMARY KEY ("id"))`
)
await db.query(
`CREATE INDEX "IDX_ec313e0ceb8429cb76aa63ed74" ON "nabla_swap_liquidity_withdrawal" ("swap_pool_id") `
)
await db.query(
`CREATE TABLE "event" ("id" character varying NOT NULL, "index" integer NOT NULL, "phase" text NOT NULL, "pallet" text NOT NULL, "name" text NOT NULL, "args" jsonb, "args_str" text array, "block_id" character varying, "extrinsic_id" character varying, "call_id" character varying, CONSTRAINT "PK_30c2f3bbaf6d34a55f8ae6e4614" PRIMARY KEY ("id"))`
)
Expand Down Expand Up @@ -554,6 +590,27 @@ module.exports = class Data1714034652645 {
await db.query(
`ALTER TABLE "swap_pool" ADD CONSTRAINT "FK_b66a5cc8d2ce7bba1b48fd8c1ab" FOREIGN KEY ("token_id") REFERENCES "nabla_token"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`
)
await db.query(
`ALTER TABLE "nabla_swap" ADD CONSTRAINT "FK_78ad17aaf8e256aada35d50c95a" FOREIGN KEY ("token_in_id") REFERENCES "nabla_token"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`
)
await db.query(
`ALTER TABLE "nabla_swap" ADD CONSTRAINT "FK_3ddf0d667a8f06da7f6ab50004f" FOREIGN KEY ("token_out_id") REFERENCES "nabla_token"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`
)
await db.query(
`ALTER TABLE "nabla_swap" ADD CONSTRAINT "FK_dd24afed240ad46290bfcf0603b" FOREIGN KEY ("swap_fee_id") REFERENCES "nabla_swap_fee"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`
)
await db.query(
`ALTER TABLE "nabla_backstop_liquidity_deposit" ADD CONSTRAINT "FK_a3ce6e5ba78f5987919e7ee3467" FOREIGN KEY ("backstop_pool_id") REFERENCES "backstop_pool"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`
)
await db.query(
`ALTER TABLE "nabla_swap_liquidity_deposit" ADD CONSTRAINT "FK_e0480f777845618674d1bbc3b18" FOREIGN KEY ("swap_pool_id") REFERENCES "swap_pool"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`
)
await db.query(
`ALTER TABLE "nabla_backstop_liquidity_withdrawal" ADD CONSTRAINT "FK_33f15234263ac9c6d07fe5441f0" FOREIGN KEY ("backstop_pool_id") REFERENCES "backstop_pool"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`
)
await db.query(
`ALTER TABLE "nabla_swap_liquidity_withdrawal" ADD CONSTRAINT "FK_ec313e0ceb8429cb76aa63ed746" FOREIGN KEY ("swap_pool_id") REFERENCES "swap_pool"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`
)
await db.query(
`ALTER TABLE "event" ADD CONSTRAINT "FK_2b0d35d675c4f99751855c45021" FOREIGN KEY ("block_id") REFERENCES "block"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`
)
Expand Down Expand Up @@ -689,6 +746,18 @@ module.exports = class Data1714034652645 {
await db.query(`DROP INDEX "public"."IDX_5c3209a88e41d53bdc450605b3"`)
await db.query(`DROP INDEX "public"."IDX_b66a5cc8d2ce7bba1b48fd8c1a"`)
await db.query(`DROP TABLE "router"`)
await db.query(`DROP TABLE "nabla_swap"`)
await db.query(`DROP INDEX "public"."IDX_78ad17aaf8e256aada35d50c95"`)
await db.query(`DROP INDEX "public"."IDX_3ddf0d667a8f06da7f6ab50004"`)
await db.query(`DROP INDEX "public"."IDX_dd24afed240ad46290bfcf0603"`)
await db.query(`DROP TABLE "nabla_backstop_liquidity_deposit"`)
await db.query(`DROP INDEX "public"."IDX_a3ce6e5ba78f5987919e7ee346"`)
await db.query(`DROP TABLE "nabla_swap_liquidity_deposit"`)
await db.query(`DROP INDEX "public"."IDX_e0480f777845618674d1bbc3b1"`)
await db.query(`DROP TABLE "nabla_backstop_liquidity_withdrawal"`)
await db.query(`DROP INDEX "public"."IDX_33f15234263ac9c6d07fe5441f"`)
await db.query(`DROP TABLE "nabla_swap_liquidity_withdrawal"`)
await db.query(`DROP INDEX "public"."IDX_ec313e0ceb8429cb76aa63ed74"`)
await db.query(`DROP TABLE "event"`)
await db.query(`DROP INDEX "public"."IDX_2b0d35d675c4f99751855c4502"`)
await db.query(`DROP INDEX "public"."IDX_129efedcb305c80256db2d57a5"`)
Expand Down Expand Up @@ -857,6 +926,27 @@ module.exports = class Data1714034652645 {
await db.query(
`ALTER TABLE "swap_pool" DROP CONSTRAINT "FK_b66a5cc8d2ce7bba1b48fd8c1ab"`
)
await db.query(
`ALTER TABLE "nabla_swap" DROP CONSTRAINT "FK_78ad17aaf8e256aada35d50c95a"`
)
await db.query(
`ALTER TABLE "nabla_swap" DROP CONSTRAINT "FK_3ddf0d667a8f06da7f6ab50004f"`
)
await db.query(
`ALTER TABLE "nabla_swap" DROP CONSTRAINT "FK_dd24afed240ad46290bfcf0603b"`
)
await db.query(
`ALTER TABLE "nabla_backstop_liquidity_deposit" DROP CONSTRAINT "FK_a3ce6e5ba78f5987919e7ee3467"`
)
await db.query(
`ALTER TABLE "nabla_swap_liquidity_deposit" DROP CONSTRAINT "FK_e0480f777845618674d1bbc3b18"`
)
await db.query(
`ALTER TABLE "nabla_backstop_liquidity_withdrawal" DROP CONSTRAINT "FK_33f15234263ac9c6d07fe5441f0"`
)
await db.query(
`ALTER TABLE "nabla_swap_liquidity_withdrawal" DROP CONSTRAINT "FK_ec313e0ceb8429cb76aa63ed746"`
)
await db.query(
`ALTER TABLE "event" DROP CONSTRAINT "FK_2b0d35d675c4f99751855c45021"`
)
Expand Down
60 changes: 59 additions & 1 deletion schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ type BackstopPool @entity {
}

type NablaSwapFee @entity {
id: ID! # id is address of the swap pool contract + timestamp
id: ID! # # calculated from blockNumber - extrinsicIndex
lpFees: BigInt! # LP fee in `asset`
backstopFees: BigInt! # backstop fee in `asset`
protocolFees: BigInt! # protocol fee in `asset`
Expand All @@ -800,6 +800,64 @@ type NablaSwapFee @entity {
backstopPool: BackstopPool # link to the BackstopPool entity
}

type NablaSwap @entity {
id: ID! # calculated from blockNumber - extrinsicIndex
timestamp: DateTime! # need this to pull recent txns for specific token or pair
# from router Swap event
sender: String!
amountIn: BigInt!
amountOut: BigInt!
tokenIn: NablaToken!
tokenOut: NablaToken!
to: String!
# this will bring backstop pool and swap pool info
swapFee: NablaSwapFee
}

type NablaBackstopLiquidityDeposit @entity {
id: ID! # calculated from blockNumber - extrinsicIndex
timestamp: DateTime!
# from backstop Mint event
sender: String!
poolSharesMinted: BigInt!
amountPoolTokensDeposited: BigInt!
# this will bring backstop pool info
bogdanS98 marked this conversation as resolved.
Show resolved Hide resolved
backstopPool: BackstopPool!
}

type NablaSwapLiquidityDeposit @entity {
id: ID! # calculated from blockNumber - extrinsicIndex
timestamp: DateTime!
# from swap Mint event
sender: String!
poolSharesMinted: BigInt!
amountPoolTokensDeposited: BigInt!
# this will bring swap pool info
swapPool: SwapPool!
}

type NablaBackstopLiquidityWithdrawal @entity {
id: ID! # calculated from blockNumber - extrinsicIndex
timestamp: DateTime!
# from backstop Burn event
sender: String!
poolSharesBurned: BigInt!
amountPoolTokensWithdrawn: BigInt!
# this will bring backstop pool info
backstopPool: BackstopPool!
}

type NablaSwapLiquidityWithdrawal @entity {
id: ID! # calculated from blockNumber - extrinsicIndex
timestamp: DateTime!
# from swap Burn event
sender: String!
poolSharesBurned: BigInt!
amountPoolTokensWithdrawn: BigInt!
# this will bring swap pool info
swapPool: SwapPool!
}

type Block @entity {
"BlockHeight-blockHash - e.g. 0001812319-0001c"
id: ID!
Expand Down
9 changes: 8 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ export const config: ProcessorConfig =
console.log('Using ProcessorConfig: ', config)

// Fetch max height from the archive and export it as a promise

export const maxHeightPromise = isLocalExecution
? Promise.resolve(0)
: axios
Expand All @@ -91,3 +90,11 @@ export const maxHeightPromise = isLocalExecution
)
return Number.MAX_SAFE_INTEGER
})

// Derive ids from block number and extrinsic index of the event
export function generateId(
blockNumber: number,
extrinsicIndex?: number
): string {
return `${blockNumber}-${extrinsicIndex ?? ''}`
}
34 changes: 31 additions & 3 deletions src/mappings/nabla/backstopPoolEventHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@ import {
Event_WithdrawSwapLiquidity,
Contract as BackstopPoolContract,
Event_InsuranceFeeSet,
Event_Burn,
Event_Mint,
} from '../../abi/backstop'
import { Contract as Erc20Contract } from '../../abi/erc20'
import { hexToSs58, ss58ToHex } from './addresses'
import { getSwapPool } from './creation'
import {
createNablaBackstopLiquidityDeposit,
createNablaBackstopLiquidityWithdrawal,
getSwapPool,
} from './creation'
import { updateSwapPoolCoverageAndSupply } from './swapPoolEventHandler'

export async function handleBackstopPoolEvent(
Expand All @@ -25,7 +31,7 @@ export async function handleBackstopPoolEvent(
break

case 'Burn':
await handleBurn(ctx, backstopPool)
await handleBurn(ctx, event, backstopPool)
break

case 'CoverSwapWithdrawal':
Expand All @@ -37,7 +43,7 @@ export async function handleBackstopPoolEvent(
break

case 'Mint':
await handleMint(ctx, backstopPool)
await handleMint(ctx, event, backstopPool)
break

case 'OwnershipTransferred':
Expand Down Expand Up @@ -69,8 +75,19 @@ export async function handleBackstopPoolEvent(

export async function handleBurn(
ctx: EventHandlerContext,
event: Event_Burn,
backstopPool: BackstopPool
) {
await createNablaBackstopLiquidityWithdrawal(
ctx,
ctx.event.block.height,
ctx.event.extrinsicIndex,
ctx.event.block.timestamp,
hexToSs58(event.sender),
event.poolSharesBurned,
event.amountPrincipleWithdrawn,
backstopPool
)
await updateBackstopCoverageAndSupply(ctx, backstopPool)
await ctx.store.save(backstopPool)
}
Expand Down Expand Up @@ -112,9 +129,20 @@ export async function handleInsuranceFeeSet(

export async function handleMint(
ctx: EventHandlerContext,
event: Event_Mint,
backstopPool: BackstopPool
) {
await updateBackstopCoverageAndSupply(ctx, backstopPool)
await createNablaBackstopLiquidityDeposit(
ctx,
ctx.event.block.height,
ctx.event.extrinsicIndex,
ctx.event.block.timestamp,
hexToSs58(event.sender),
event.poolSharesMinted,
event.amountPrincipleDeposited,
backstopPool
)
await ctx.store.save(backstopPool)
}

Expand Down
Loading