From 13623ae83f35e9b862f67f59f7b16c4184dcad09 Mon Sep 17 00:00:00 2001 From: Chef Huan Date: Mon, 22 Apr 2024 12:47:03 +0700 Subject: [PATCH] chore: Add NG SS pool mapping --- .../bsc/abis/AbstractStableSwap.json | 14 + .../bsc/abis/StableSwapNG.json | 1464 +++++++++++++++++ .../bsc/mappings/factory.ts | 20 +- .../bsc/mappings/stableSwapPairNG.ts | 91 + .../exchange-stableswap/bsc/subgraph.yaml | 49 +- 5 files changed, 1626 insertions(+), 12 deletions(-) create mode 100644 subgraphs/exchange-stableswap/bsc/abis/AbstractStableSwap.json create mode 100644 subgraphs/exchange-stableswap/bsc/abis/StableSwapNG.json create mode 100644 subgraphs/exchange-stableswap/bsc/mappings/stableSwapPairNG.ts diff --git a/subgraphs/exchange-stableswap/bsc/abis/AbstractStableSwap.json b/subgraphs/exchange-stableswap/bsc/abis/AbstractStableSwap.json new file mode 100644 index 00000000..dc4bc823 --- /dev/null +++ b/subgraphs/exchange-stableswap/bsc/abis/AbstractStableSwap.json @@ -0,0 +1,14 @@ +[ + { + "stateMutability": "view", + "type": "function", + "name": "token", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "address" + } + ] + } +] \ No newline at end of file diff --git a/subgraphs/exchange-stableswap/bsc/abis/StableSwapNG.json b/subgraphs/exchange-stableswap/bsc/abis/StableSwapNG.json new file mode 100644 index 00000000..10624118 --- /dev/null +++ b/subgraphs/exchange-stableswap/bsc/abis/StableSwapNG.json @@ -0,0 +1,1464 @@ +[ + { + "name": "Transfer", + "inputs": [ + { + "name": "sender", + "type": "address", + "indexed": true + }, + { + "name": "receiver", + "type": "address", + "indexed": true + }, + { + "name": "value", + "type": "uint256", + "indexed": false + } + ], + "anonymous": false, + "type": "event" + }, + { + "name": "Approval", + "inputs": [ + { + "name": "owner", + "type": "address", + "indexed": true + }, + { + "name": "spender", + "type": "address", + "indexed": true + }, + { + "name": "value", + "type": "uint256", + "indexed": false + } + ], + "anonymous": false, + "type": "event" + }, + { + "name": "TokenExchange", + "inputs": [ + { + "name": "buyer", + "type": "address", + "indexed": true + }, + { + "name": "sold_id", + "type": "int128", + "indexed": false + }, + { + "name": "tokens_sold", + "type": "uint256", + "indexed": false + }, + { + "name": "bought_id", + "type": "int128", + "indexed": false + }, + { + "name": "tokens_bought", + "type": "uint256", + "indexed": false + } + ], + "anonymous": false, + "type": "event" + }, + { + "name": "TokenExchangeUnderlying", + "inputs": [ + { + "name": "buyer", + "type": "address", + "indexed": true + }, + { + "name": "sold_id", + "type": "int128", + "indexed": false + }, + { + "name": "tokens_sold", + "type": "uint256", + "indexed": false + }, + { + "name": "bought_id", + "type": "int128", + "indexed": false + }, + { + "name": "tokens_bought", + "type": "uint256", + "indexed": false + } + ], + "anonymous": false, + "type": "event" + }, + { + "name": "AddLiquidity", + "inputs": [ + { + "name": "provider", + "type": "address", + "indexed": true + }, + { + "name": "token_amounts", + "type": "uint256[]", + "indexed": false + }, + { + "name": "fees", + "type": "uint256[]", + "indexed": false + }, + { + "name": "invariant", + "type": "uint256", + "indexed": false + }, + { + "name": "token_supply", + "type": "uint256", + "indexed": false + } + ], + "anonymous": false, + "type": "event" + }, + { + "name": "RemoveLiquidity", + "inputs": [ + { + "name": "provider", + "type": "address", + "indexed": true + }, + { + "name": "token_amounts", + "type": "uint256[]", + "indexed": false + }, + { + "name": "fees", + "type": "uint256[]", + "indexed": false + }, + { + "name": "token_supply", + "type": "uint256", + "indexed": false + } + ], + "anonymous": false, + "type": "event" + }, + { + "name": "RemoveLiquidityOne", + "inputs": [ + { + "name": "provider", + "type": "address", + "indexed": true + }, + { + "name": "token_id", + "type": "int128", + "indexed": false + }, + { + "name": "token_amount", + "type": "uint256", + "indexed": false + }, + { + "name": "coin_amount", + "type": "uint256", + "indexed": false + }, + { + "name": "token_supply", + "type": "uint256", + "indexed": false + } + ], + "anonymous": false, + "type": "event" + }, + { + "name": "RemoveLiquidityImbalance", + "inputs": [ + { + "name": "provider", + "type": "address", + "indexed": true + }, + { + "name": "token_amounts", + "type": "uint256[]", + "indexed": false + }, + { + "name": "fees", + "type": "uint256[]", + "indexed": false + }, + { + "name": "invariant", + "type": "uint256", + "indexed": false + }, + { + "name": "token_supply", + "type": "uint256", + "indexed": false + } + ], + "anonymous": false, + "type": "event" + }, + { + "name": "RampA", + "inputs": [ + { + "name": "old_A", + "type": "uint256", + "indexed": false + }, + { + "name": "new_A", + "type": "uint256", + "indexed": false + }, + { + "name": "initial_time", + "type": "uint256", + "indexed": false + }, + { + "name": "future_time", + "type": "uint256", + "indexed": false + } + ], + "anonymous": false, + "type": "event" + }, + { + "name": "StopRampA", + "inputs": [ + { + "name": "A", + "type": "uint256", + "indexed": false + }, + { + "name": "t", + "type": "uint256", + "indexed": false + } + ], + "anonymous": false, + "type": "event" + }, + { + "name": "ApplyNewFee", + "inputs": [ + { + "name": "fee", + "type": "uint256", + "indexed": false + }, + { + "name": "offpeg_fee_multiplier", + "type": "uint256", + "indexed": false + } + ], + "anonymous": false, + "type": "event" + }, + { + "name": "SetNewMATime", + "inputs": [ + { + "name": "ma_exp_time", + "type": "uint256", + "indexed": false + }, + { + "name": "D_ma_time", + "type": "uint256", + "indexed": false + } + ], + "anonymous": false, + "type": "event" + }, + { + "stateMutability": "nonpayable", + "type": "constructor", + "inputs": [ + { + "name": "_name", + "type": "string" + }, + { + "name": "_symbol", + "type": "string" + }, + { + "name": "_A", + "type": "uint256" + }, + { + "name": "_fee", + "type": "uint256" + }, + { + "name": "_offpeg_fee_multiplier", + "type": "uint256" + }, + { + "name": "_ma_exp_time", + "type": "uint256" + }, + { + "name": "_coins", + "type": "address[]" + }, + { + "name": "_rate_multipliers", + "type": "uint256[]" + }, + { + "name": "_asset_types", + "type": "uint8[]" + }, + { + "name": "_method_ids", + "type": "bytes4[]" + }, + { + "name": "_oracles", + "type": "address[]" + } + ], + "outputs": [] + }, + { + "stateMutability": "nonpayable", + "type": "function", + "name": "exchange", + "inputs": [ + { + "name": "i", + "type": "int128" + }, + { + "name": "j", + "type": "int128" + }, + { + "name": "_dx", + "type": "uint256" + }, + { + "name": "_min_dy", + "type": "uint256" + } + ], + "outputs": [ + { + "name": "", + "type": "uint256" + } + ] + }, + { + "stateMutability": "nonpayable", + "type": "function", + "name": "exchange", + "inputs": [ + { + "name": "i", + "type": "int128" + }, + { + "name": "j", + "type": "int128" + }, + { + "name": "_dx", + "type": "uint256" + }, + { + "name": "_min_dy", + "type": "uint256" + }, + { + "name": "_receiver", + "type": "address" + } + ], + "outputs": [ + { + "name": "", + "type": "uint256" + } + ] + }, + { + "stateMutability": "nonpayable", + "type": "function", + "name": "exchange_received", + "inputs": [ + { + "name": "i", + "type": "int128" + }, + { + "name": "j", + "type": "int128" + }, + { + "name": "_dx", + "type": "uint256" + }, + { + "name": "_min_dy", + "type": "uint256" + } + ], + "outputs": [ + { + "name": "", + "type": "uint256" + } + ] + }, + { + "stateMutability": "nonpayable", + "type": "function", + "name": "exchange_received", + "inputs": [ + { + "name": "i", + "type": "int128" + }, + { + "name": "j", + "type": "int128" + }, + { + "name": "_dx", + "type": "uint256" + }, + { + "name": "_min_dy", + "type": "uint256" + }, + { + "name": "_receiver", + "type": "address" + } + ], + "outputs": [ + { + "name": "", + "type": "uint256" + } + ] + }, + { + "stateMutability": "nonpayable", + "type": "function", + "name": "add_liquidity", + "inputs": [ + { + "name": "_amounts", + "type": "uint256[]" + }, + { + "name": "_min_mint_amount", + "type": "uint256" + } + ], + "outputs": [ + { + "name": "", + "type": "uint256" + } + ] + }, + { + "stateMutability": "nonpayable", + "type": "function", + "name": "add_liquidity", + "inputs": [ + { + "name": "_amounts", + "type": "uint256[]" + }, + { + "name": "_min_mint_amount", + "type": "uint256" + }, + { + "name": "_receiver", + "type": "address" + } + ], + "outputs": [ + { + "name": "", + "type": "uint256" + } + ] + }, + { + "stateMutability": "nonpayable", + "type": "function", + "name": "remove_liquidity_one_coin", + "inputs": [ + { + "name": "_burn_amount", + "type": "uint256" + }, + { + "name": "i", + "type": "int128" + }, + { + "name": "_min_received", + "type": "uint256" + } + ], + "outputs": [ + { + "name": "", + "type": "uint256" + } + ] + }, + { + "stateMutability": "nonpayable", + "type": "function", + "name": "remove_liquidity_one_coin", + "inputs": [ + { + "name": "_burn_amount", + "type": "uint256" + }, + { + "name": "i", + "type": "int128" + }, + { + "name": "_min_received", + "type": "uint256" + }, + { + "name": "_receiver", + "type": "address" + } + ], + "outputs": [ + { + "name": "", + "type": "uint256" + } + ] + }, + { + "stateMutability": "nonpayable", + "type": "function", + "name": "remove_liquidity_imbalance", + "inputs": [ + { + "name": "_amounts", + "type": "uint256[]" + }, + { + "name": "_max_burn_amount", + "type": "uint256" + } + ], + "outputs": [ + { + "name": "", + "type": "uint256" + } + ] + }, + { + "stateMutability": "nonpayable", + "type": "function", + "name": "remove_liquidity_imbalance", + "inputs": [ + { + "name": "_amounts", + "type": "uint256[]" + }, + { + "name": "_max_burn_amount", + "type": "uint256" + }, + { + "name": "_receiver", + "type": "address" + } + ], + "outputs": [ + { + "name": "", + "type": "uint256" + } + ] + }, + { + "stateMutability": "nonpayable", + "type": "function", + "name": "remove_liquidity", + "inputs": [ + { + "name": "_burn_amount", + "type": "uint256" + }, + { + "name": "_min_amounts", + "type": "uint256[]" + } + ], + "outputs": [ + { + "name": "", + "type": "uint256[]" + } + ] + }, + { + "stateMutability": "nonpayable", + "type": "function", + "name": "remove_liquidity", + "inputs": [ + { + "name": "_burn_amount", + "type": "uint256" + }, + { + "name": "_min_amounts", + "type": "uint256[]" + }, + { + "name": "_receiver", + "type": "address" + } + ], + "outputs": [ + { + "name": "", + "type": "uint256[]" + } + ] + }, + { + "stateMutability": "nonpayable", + "type": "function", + "name": "remove_liquidity", + "inputs": [ + { + "name": "_burn_amount", + "type": "uint256" + }, + { + "name": "_min_amounts", + "type": "uint256[]" + }, + { + "name": "_receiver", + "type": "address" + }, + { + "name": "_claim_admin_fees", + "type": "bool" + } + ], + "outputs": [ + { + "name": "", + "type": "uint256[]" + } + ] + }, + { + "stateMutability": "nonpayable", + "type": "function", + "name": "withdraw_admin_fees", + "inputs": [], + "outputs": [] + }, + { + "stateMutability": "view", + "type": "function", + "name": "last_price", + "inputs": [ + { + "name": "i", + "type": "uint256" + } + ], + "outputs": [ + { + "name": "", + "type": "uint256" + } + ] + }, + { + "stateMutability": "view", + "type": "function", + "name": "ema_price", + "inputs": [ + { + "name": "i", + "type": "uint256" + } + ], + "outputs": [ + { + "name": "", + "type": "uint256" + } + ] + }, + { + "stateMutability": "view", + "type": "function", + "name": "get_p", + "inputs": [ + { + "name": "i", + "type": "uint256" + } + ], + "outputs": [ + { + "name": "", + "type": "uint256" + } + ] + }, + { + "stateMutability": "view", + "type": "function", + "name": "price_oracle", + "inputs": [ + { + "name": "i", + "type": "uint256" + } + ], + "outputs": [ + { + "name": "", + "type": "uint256" + } + ] + }, + { + "stateMutability": "view", + "type": "function", + "name": "D_oracle", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "uint256" + } + ] + }, + { + "stateMutability": "nonpayable", + "type": "function", + "name": "transfer", + "inputs": [ + { + "name": "_to", + "type": "address" + }, + { + "name": "_value", + "type": "uint256" + } + ], + "outputs": [ + { + "name": "", + "type": "bool" + } + ] + }, + { + "stateMutability": "nonpayable", + "type": "function", + "name": "transferFrom", + "inputs": [ + { + "name": "_from", + "type": "address" + }, + { + "name": "_to", + "type": "address" + }, + { + "name": "_value", + "type": "uint256" + } + ], + "outputs": [ + { + "name": "", + "type": "bool" + } + ] + }, + { + "stateMutability": "nonpayable", + "type": "function", + "name": "approve", + "inputs": [ + { + "name": "_spender", + "type": "address" + }, + { + "name": "_value", + "type": "uint256" + } + ], + "outputs": [ + { + "name": "", + "type": "bool" + } + ] + }, + { + "stateMutability": "nonpayable", + "type": "function", + "name": "permit", + "inputs": [ + { + "name": "_owner", + "type": "address" + }, + { + "name": "_spender", + "type": "address" + }, + { + "name": "_value", + "type": "uint256" + }, + { + "name": "_deadline", + "type": "uint256" + }, + { + "name": "_v", + "type": "uint8" + }, + { + "name": "_r", + "type": "bytes32" + }, + { + "name": "_s", + "type": "bytes32" + } + ], + "outputs": [ + { + "name": "", + "type": "bool" + } + ] + }, + { + "stateMutability": "view", + "type": "function", + "name": "DOMAIN_SEPARATOR", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "bytes32" + } + ] + }, + { + "stateMutability": "view", + "type": "function", + "name": "get_dx", + "inputs": [ + { + "name": "i", + "type": "int128" + }, + { + "name": "j", + "type": "int128" + }, + { + "name": "dy", + "type": "uint256" + } + ], + "outputs": [ + { + "name": "", + "type": "uint256" + } + ] + }, + { + "stateMutability": "view", + "type": "function", + "name": "get_dy", + "inputs": [ + { + "name": "i", + "type": "int128" + }, + { + "name": "j", + "type": "int128" + }, + { + "name": "dx", + "type": "uint256" + } + ], + "outputs": [ + { + "name": "", + "type": "uint256" + } + ] + }, + { + "stateMutability": "view", + "type": "function", + "name": "calc_withdraw_one_coin", + "inputs": [ + { + "name": "_burn_amount", + "type": "uint256" + }, + { + "name": "i", + "type": "int128" + } + ], + "outputs": [ + { + "name": "", + "type": "uint256" + } + ] + }, + { + "stateMutability": "view", + "type": "function", + "name": "totalSupply", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "uint256" + } + ] + }, + { + "stateMutability": "view", + "type": "function", + "name": "get_virtual_price", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "uint256" + } + ] + }, + { + "stateMutability": "view", + "type": "function", + "name": "calc_token_amount", + "inputs": [ + { + "name": "_amounts", + "type": "uint256[]" + }, + { + "name": "_is_deposit", + "type": "bool" + } + ], + "outputs": [ + { + "name": "", + "type": "uint256" + } + ] + }, + { + "stateMutability": "view", + "type": "function", + "name": "A", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "uint256" + } + ] + }, + { + "stateMutability": "view", + "type": "function", + "name": "A_precise", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "uint256" + } + ] + }, + { + "stateMutability": "view", + "type": "function", + "name": "balances", + "inputs": [ + { + "name": "i", + "type": "uint256" + } + ], + "outputs": [ + { + "name": "", + "type": "uint256" + } + ] + }, + { + "stateMutability": "view", + "type": "function", + "name": "get_balances", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "uint256[]" + } + ] + }, + { + "stateMutability": "view", + "type": "function", + "name": "stored_rates", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "uint256[]" + } + ] + }, + { + "stateMutability": "view", + "type": "function", + "name": "dynamic_fee", + "inputs": [ + { + "name": "i", + "type": "int128" + }, + { + "name": "j", + "type": "int128" + } + ], + "outputs": [ + { + "name": "", + "type": "uint256" + } + ] + }, + { + "stateMutability": "nonpayable", + "type": "function", + "name": "ramp_A", + "inputs": [ + { + "name": "_future_A", + "type": "uint256" + }, + { + "name": "_future_time", + "type": "uint256" + } + ], + "outputs": [] + }, + { + "stateMutability": "nonpayable", + "type": "function", + "name": "stop_ramp_A", + "inputs": [], + "outputs": [] + }, + { + "stateMutability": "nonpayable", + "type": "function", + "name": "set_new_fee", + "inputs": [ + { + "name": "_new_fee", + "type": "uint256" + }, + { + "name": "_new_offpeg_fee_multiplier", + "type": "uint256" + } + ], + "outputs": [] + }, + { + "stateMutability": "nonpayable", + "type": "function", + "name": "set_ma_exp_time", + "inputs": [ + { + "name": "_ma_exp_time", + "type": "uint256" + }, + { + "name": "_D_ma_time", + "type": "uint256" + } + ], + "outputs": [] + }, + { + "stateMutability": "view", + "type": "function", + "name": "N_COINS", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "uint256" + } + ] + }, + { + "stateMutability": "view", + "type": "function", + "name": "token", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "address" + } + ] + }, + { + "stateMutability": "view", + "type": "function", + "name": "coins", + "inputs": [ + { + "name": "arg0", + "type": "uint256" + } + ], + "outputs": [ + { + "name": "", + "type": "address" + } + ] + }, + { + "stateMutability": "view", + "type": "function", + "name": "fee", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "uint256" + } + ] + }, + { + "stateMutability": "view", + "type": "function", + "name": "offpeg_fee_multiplier", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "uint256" + } + ] + }, + { + "stateMutability": "view", + "type": "function", + "name": "admin_fee", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "uint256" + } + ] + }, + { + "stateMutability": "view", + "type": "function", + "name": "initial_A", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "uint256" + } + ] + }, + { + "stateMutability": "view", + "type": "function", + "name": "future_A", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "uint256" + } + ] + }, + { + "stateMutability": "view", + "type": "function", + "name": "initial_A_time", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "uint256" + } + ] + }, + { + "stateMutability": "view", + "type": "function", + "name": "future_A_time", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "uint256" + } + ] + }, + { + "stateMutability": "view", + "type": "function", + "name": "admin_balances", + "inputs": [ + { + "name": "arg0", + "type": "uint256" + } + ], + "outputs": [ + { + "name": "", + "type": "uint256" + } + ] + }, + { + "stateMutability": "view", + "type": "function", + "name": "ma_exp_time", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "uint256" + } + ] + }, + { + "stateMutability": "view", + "type": "function", + "name": "D_ma_time", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "uint256" + } + ] + }, + { + "stateMutability": "view", + "type": "function", + "name": "ma_last_time", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "uint256" + } + ] + }, + { + "stateMutability": "view", + "type": "function", + "name": "name", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "string" + } + ] + }, + { + "stateMutability": "view", + "type": "function", + "name": "symbol", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "string" + } + ] + }, + { + "stateMutability": "view", + "type": "function", + "name": "decimals", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "uint8" + } + ] + }, + { + "stateMutability": "view", + "type": "function", + "name": "version", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "string" + } + ] + }, + { + "stateMutability": "view", + "type": "function", + "name": "balanceOf", + "inputs": [ + { + "name": "arg0", + "type": "address" + } + ], + "outputs": [ + { + "name": "", + "type": "uint256" + } + ] + }, + { + "stateMutability": "view", + "type": "function", + "name": "allowance", + "inputs": [ + { + "name": "arg0", + "type": "address" + }, + { + "name": "arg1", + "type": "address" + } + ], + "outputs": [ + { + "name": "", + "type": "uint256" + } + ] + }, + { + "stateMutability": "view", + "type": "function", + "name": "nonces", + "inputs": [ + { + "name": "arg0", + "type": "address" + } + ], + "outputs": [ + { + "name": "", + "type": "uint256" + } + ] + }, + { + "stateMutability": "view", + "type": "function", + "name": "salt", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "bytes32" + } + ] + } +] \ No newline at end of file diff --git a/subgraphs/exchange-stableswap/bsc/mappings/factory.ts b/subgraphs/exchange-stableswap/bsc/mappings/factory.ts index db0aa980..9e34b9ff 100644 --- a/subgraphs/exchange-stableswap/bsc/mappings/factory.ts +++ b/subgraphs/exchange-stableswap/bsc/mappings/factory.ts @@ -1,13 +1,11 @@ /* eslint-disable prefer-const */ import { DataSourceContext, log } from "@graphprotocol/graph-ts"; -import { StableSwapPair as StableSwapPairContract } from "../generated/templates/StableSwapPair/StableSwapPair"; -import { StableSwap3PairV2 as StableSwap3PairV2Contract } from "../generated/templates/StableSwap3PairV2/StableSwap3PairV2"; -// import { StableSwapPairV2 as StableSwapPairV2Contract } from "../generated/templates/StableSwapPairV2/StableSwapPairV2"; import { BIG_DECIMAL_ZERO, BIG_INT_ONE, BIG_INT_ZERO, ADDRESS_ZERO } from "./utils"; import { getOrCreateFactory, getOrCreateToken } from "./utils/data"; import { NewStableSwapPair } from "../generated/StableSwapFactory/StableSwapFactory"; -import { ERC20, StableSwapPair } from "../generated/templates"; +import { ERC20, StableSwapPair, StableSwapNG } from "../generated/templates"; import { Pair } from "../generated/schema"; +import { AbstractStableSwap } from "../generated/StableSwapFactory/AbstractStableSwap"; export function handlePairCreated(event: NewStableSwapPair): void { log.info("handlePairCreated. address: {}", [event.address.toHex()]); @@ -56,13 +54,15 @@ export function handlePairCreated(event: NewStableSwapPair): void { factory.totalPairs = factory.totalPairs.plus(BIG_INT_ONE); factory.save(); - StableSwapPair.create(event.params.swapContract); + let ssToken = AbstractStableSwap.bind(event.params.swapContract).token(); + let isNGPool = ssToken.equals(event.params.swapContract); + if (isNGPool) { + StableSwapNG.create(event.params.swapContract); + } else { + StableSwapPair.create(event.params.swapContract); + } let context = new DataSourceContext(); context.setString("pairAddress", event.params.swapContract.toHex()); - if (event.params.tokenC.toHex() != ADDRESS_ZERO) { - ERC20.createWithContext(StableSwap3PairV2Contract.bind(event.params.swapContract).token(), context); - } else { - ERC20.createWithContext(StableSwapPairContract.bind(event.params.swapContract).token(), context); - } + ERC20.createWithContext(ssToken, context); } diff --git a/subgraphs/exchange-stableswap/bsc/mappings/stableSwapPairNG.ts b/subgraphs/exchange-stableswap/bsc/mappings/stableSwapPairNG.ts new file mode 100644 index 00000000..c1fb005b --- /dev/null +++ b/subgraphs/exchange-stableswap/bsc/mappings/stableSwapPairNG.ts @@ -0,0 +1,91 @@ +/* eslint-disable prefer-const */ +import { log } from "@graphprotocol/graph-ts"; +import { BIG_INT_ONE, BIG_INT_ZERO } from "./utils"; +import { + AddLiquidity, + RemoveLiquidity, + RemoveLiquidityOne, + TokenExchange, +} from "../generated/templates/StableSwapNG/StableSwapNG"; +import { Pair } from "../generated/schema"; +import { BigInt } from "@graphprotocol/graph-ts"; +import { sync } from "./services/sync"; +import { swap, SwapParams } from "./services/swap"; +import { burn } from "./services/burn"; +import { mint } from "./services/mint"; + +export function handleTokenExchange(event: TokenExchange): void { + log.debug("swap for v2 pool: {} at {}", [event.address.toHexString(), event.transaction.hash.toHexString()]); + sync(event.address); + + let soldId = event.params.sold_id.toI32(); + let boughtId = event.params.bought_id.toI32(); + + let amount0In: BigInt; + let amount1In: BigInt; + let amount0Out: BigInt; + let amount1Out: BigInt; + if (soldId == 0) { + amount0In = event.params.tokens_sold; + amount1In = BIG_INT_ZERO; + } else { + amount0In = BIG_INT_ZERO; + amount1In = event.params.tokens_sold; + } + + if (boughtId == 0) { + amount0Out = event.params.tokens_bought; + amount1Out = BIG_INT_ZERO; + } else { + amount0Out = BIG_INT_ZERO; + amount1Out = event.params.tokens_bought; + } + + let params = { + to: event.params.buyer, + sender: event.transaction.from, + amount0In, + amount1In, + amount0Out, + amount1Out, + } as SwapParams; + swap(event, params); +} + +export function handleRemoveLiquidity(event: RemoveLiquidity): void { + let pair = Pair.load(event.address.toHexString()); + if (!pair) { + return; + } + log.info("Removed liquidity for pair: {} at {}", [event.address.toHexString(), event.transaction.hash.toHexString()]); + sync(event.address); + let tokenAmounts: Array = event.params.token_amounts; + burn(event, tokenAmounts[0], tokenAmounts[1], null); +} + +export function handleRemoveLiquidityOne(event: RemoveLiquidityOne): void { + let pair = Pair.load(event.address.toHexString()); + if (!pair) { + return; + } + + log.info("Removed liquidity for pool: {} at {}", [event.address.toHexString(), event.transaction.hash.toHexString()]); + sync(event.address); + + if (event.params.token_id.equals(BIG_INT_ZERO)) { + burn(event, event.params.coin_amount, BIG_INT_ZERO, null); + } else if (event.params.token_id.equals(BIG_INT_ONE)) { + burn(event, BIG_INT_ZERO, event.params.coin_amount, null); + } +} + +export function handleAddLiquidity(event: AddLiquidity): void { + let pair = Pair.load(event.address.toHexString()); + if (!pair) { + return; + } + log.info("Added liquidity for pool: {} at {}", [event.address.toHexString(), event.transaction.hash.toHexString()]); + sync(event.address); + let tokenAmounts: Array = event.params.token_amounts; + mint(event, tokenAmounts[0], tokenAmounts[1], event.params.provider); +} diff --git a/subgraphs/exchange-stableswap/bsc/subgraph.yaml b/subgraphs/exchange-stableswap/bsc/subgraph.yaml index eda12bdb..83f4c8ef 100644 --- a/subgraphs/exchange-stableswap/bsc/subgraph.yaml +++ b/subgraphs/exchange-stableswap/bsc/subgraph.yaml @@ -7,8 +7,8 @@ schema: # base: Qme4U6by9yqGwTPKRaPvbgo7Ar9CwYFaTjmy9z6uVSjxvL # block: 33890015 # for previous exiting factory graft: - base: QmXYctSeyF2dMi6Cmkb4t83BMn1RJcENkVSkAgsTTXFAC4 - block: 35922202 # for previous exiting factory + base: QmdDJpuigWY5htazwqWAZyG1k3pY79GHRoZESKN2DrqAu3 + block: 37995176 # for previous exiting factory dataSources: - kind: ethereum/contract name: StableSwapFactory @@ -27,6 +27,8 @@ dataSources: abis: - name: StableSwapFactory file: ./abis/StableSwapFactory.json + - name: AbstractStableSwap + file: ./abis/AbstractStableSwap.json - name: StableSwapPair file: ./abis/StableSwapPair.json - name: Factory @@ -158,6 +160,49 @@ templates: handler: handleTriRemoveLiquidityOne - event: TokenExchange(indexed address,uint256,uint256,uint256,uint256) handler: handleTriTokenExchange + - kind: ethereum/contract + name: StableSwapNG + network: bsc + source: + abi: StableSwapNG + mapping: + kind: ethereum/events + apiVersion: 0.0.4 + language: wasm/assemblyscript + file: ./mappings/stableSwapPairNG.ts + entities: + - Pair + - Mint + - Burn + - Transaction + abis: + - name: StableSwapFactory + file: ./abis/StableSwapFactory.json + - name: StableSwapNG + file: ./abis/StableSwapNG.json + + - name: Factory + file: ./abis/Factory.json + - name: Pair + file: ./abis/Pair.json + - name: PairV3 + file: ./abis/PairV3.json + + - name: PriceLens0 + file: ./abis/PriceLens0.json + eventHandlers: + - event: AddLiquidity(indexed address,uint256[],uint256[],uint256,uint256) + handler: handleAddLiquidity + - event: RemoveLiquidity(indexed address,uint256[],uint256[],uint256) + handler: handleRemoveLiquidity + - event: RemoveLiquidityOne(indexed address,int128,uint256,uint256,uint256) + handler: handleRemoveLiquidityOne + - event: RemoveLiquidityImbalance(indexed address,uint256[],uint256[],uint256,uint256) + handler: handleRemoveLiquidityImbalance + - event: TokenExchange(indexed address,int128,uint256,int128,uint256) + handler: handleTokenExchange + - event: TokenExchangeUnderlying(indexed address,int128,uint256,int128,uint256) + handler: handleTokenExchangeUnderlying - kind: ethereum/contract name: ERC20 network: bsc