Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
0xjojoex committed Feb 7, 2024
1 parent 36cd61a commit d71912f
Show file tree
Hide file tree
Showing 6 changed files with 187 additions and 151 deletions.
155 changes: 83 additions & 72 deletions subgraphs/exchange-stableswap/arb/abis/PriceLens0.json
Original file line number Diff line number Diff line change
@@ -1,121 +1,132 @@
[
{
"type": "constructor",
"inputs": [
{ "name": "nativePriceAggregator", "type": "address", "internalType": "address" },
{ "name": "wnative", "type": "address", "internalType": "address" }
{ "internalType": "address", "name": "nativePriceAggregator", "type": "address" },
{ "internalType": "address", "name": "wnative", "type": "address" }
],
"stateMutability": "nonpayable"
"stateMutability": "nonpayable",
"type": "constructor"
},
{ "inputs": [], "name": "IncorrectBaseAddress", "type": "error" },
{ "inputs": [], "name": "IncorrectChainlinkPrice", "type": "error" },
{ "inputs": [], "name": "IncorrectSourceAddress", "type": "error" },
{ "inputs": [], "name": "UnknowPrice", "type": "error" },
{
"anonymous": false,
"inputs": [
{ "indexed": true, "internalType": "address", "name": "user", "type": "address" },
{ "indexed": true, "internalType": "address", "name": "newOwner", "type": "address" }
],
"name": "OwnershipTransferred",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{ "indexed": true, "internalType": "address", "name": "token", "type": "address" },
{ "indexed": true, "internalType": "enum PriceLens0.SourceType", "name": "sourceType", "type": "uint8" },
{ "indexed": false, "internalType": "address", "name": "sourceAddress", "type": "address" },
{ "indexed": true, "internalType": "address", "name": "baseAddress", "type": "address" }
],
"name": "UpdateSource",
"type": "event"
},
{
"type": "function",
"name": "DECIMALS",
"inputs": [],
"outputs": [{ "name": "", "type": "uint256", "internalType": "uint256" }],
"stateMutability": "view"
"name": "DECIMALS",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"stateMutability": "view",
"type": "function"
},
{
"type": "function",
"name": "_nativePriceAggregator",
"inputs": [],
"outputs": [{ "name": "", "type": "address", "internalType": "address" }],
"stateMutability": "view"
"name": "_nativePriceAggregator",
"outputs": [{ "internalType": "address", "name": "", "type": "address" }],
"stateMutability": "view",
"type": "function"
},
{
"type": "function",
"name": "_wnative",
"inputs": [],
"outputs": [{ "name": "", "type": "address", "internalType": "address" }],
"stateMutability": "view"
"name": "_wnative",
"outputs": [{ "internalType": "address", "name": "", "type": "address" }],
"stateMutability": "view",
"type": "function"
},
{
"type": "function",
"inputs": [{ "internalType": "address", "name": "token", "type": "address" }],
"name": "getNativePrice",
"inputs": [{ "name": "token", "type": "address", "internalType": "address" }],
"outputs": [{ "name": "nativePrice", "type": "uint256", "internalType": "uint256" }],
"stateMutability": "view"
"outputs": [{ "internalType": "uint256", "name": "nativePrice", "type": "uint256" }],
"stateMutability": "view",
"type": "function"
},
{
"type": "function",
"inputs": [{ "internalType": "address", "name": "token", "type": "address" }],
"name": "getUsd",
"inputs": [{ "name": "token", "type": "address", "internalType": "address" }],
"outputs": [{ "name": "price", "type": "uint256", "internalType": "uint256" }],
"stateMutability": "view"
"outputs": [{ "internalType": "uint256", "name": "price", "type": "uint256" }],
"stateMutability": "view",
"type": "function"
},
{
"type": "function",
"name": "owner",
"inputs": [],
"outputs": [{ "name": "", "type": "address", "internalType": "address" }],
"stateMutability": "view"
"name": "owner",
"outputs": [{ "internalType": "address", "name": "", "type": "address" }],
"stateMutability": "view",
"type": "function"
},
{
"type": "function",
"inputs": [{ "internalType": "address", "name": "nativePriceAggregator", "type": "address" }],
"name": "setNativePriceAggregator",
"inputs": [{ "name": "nativePriceAggregator", "type": "address", "internalType": "address" }],
"outputs": [],
"stateMutability": "nonpayable"
"stateMutability": "nonpayable",
"type": "function"
},
{
"type": "function",
"name": "setSource",
"inputs": [
{ "name": "token", "type": "address", "internalType": "address" },
{ "name": "sourceType", "type": "uint8", "internalType": "enum PriceLens0.SourceType" },
{ "name": "sourceAddress", "type": "address", "internalType": "address" },
{ "name": "baseAddress", "type": "address", "internalType": "address" }
{ "internalType": "address", "name": "token", "type": "address" },
{ "internalType": "enum PriceLens0.SourceType", "name": "sourceType", "type": "uint8" },
{ "internalType": "address", "name": "sourceAddress", "type": "address" },
{ "internalType": "address", "name": "baseAddress", "type": "address" }
],
"name": "setSource",
"outputs": [],
"stateMutability": "nonpayable"
"stateMutability": "nonpayable",
"type": "function"
},
{
"type": "function",
"name": "setSourceList",
"inputs": [
{
"name": "sourceList",
"type": "tuple[]",
"internalType": "struct PriceLens0.SourceList[]",
"components": [
{ "name": "token", "type": "address", "internalType": "address" },
{ "name": "sourceType", "type": "uint8", "internalType": "enum PriceLens0.SourceType" },
{ "name": "sourceAddress", "type": "address", "internalType": "address" },
{ "name": "baseAddress", "type": "address", "internalType": "address" }
]
{ "internalType": "address", "name": "token", "type": "address" },
{ "internalType": "enum PriceLens0.SourceType", "name": "sourceType", "type": "uint8" },
{ "internalType": "address", "name": "sourceAddress", "type": "address" },
{ "internalType": "address", "name": "baseAddress", "type": "address" }
],
"internalType": "struct PriceLens0.SourceList[]",
"name": "sourceList",
"type": "tuple[]"
}
],
"name": "setSourceList",
"outputs": [],
"stateMutability": "nonpayable"
"stateMutability": "nonpayable",
"type": "function"
},
{
"type": "function",
"inputs": [{ "internalType": "address", "name": "", "type": "address" }],
"name": "sources",
"inputs": [{ "name": "", "type": "address", "internalType": "address" }],
"outputs": [
{ "name": "sourceType", "type": "uint8", "internalType": "enum PriceLens0.SourceType" },
{ "name": "sourceAddress", "type": "address", "internalType": "address" },
{ "name": "baseAddress", "type": "address", "internalType": "address" }
{ "internalType": "enum PriceLens0.SourceType", "name": "sourceType", "type": "uint8" },
{ "internalType": "address", "name": "sourceAddress", "type": "address" },
{ "internalType": "address", "name": "baseAddress", "type": "address" }
],
"stateMutability": "view"
"stateMutability": "view",
"type": "function"
},
{
"type": "function",
"inputs": [{ "internalType": "address", "name": "newOwner", "type": "address" }],
"name": "transferOwnership",
"inputs": [{ "name": "newOwner", "type": "address", "internalType": "address" }],
"outputs": [],
"stateMutability": "nonpayable"
},
{
"type": "event",
"name": "OwnershipTransferred",
"inputs": [
{ "name": "user", "type": "address", "indexed": true, "internalType": "address" },
{ "name": "newOwner", "type": "address", "indexed": true, "internalType": "address" }
],
"anonymous": false
},
{ "type": "error", "name": "IncorrectBaseAddress", "inputs": [] },
{ "type": "error", "name": "IncorrectChainlinkPrice", "inputs": [] },
{ "type": "error", "name": "IncorrectSourceAddress", "inputs": [] },
{ "type": "error", "name": "UnknowPrice", "inputs": [] }
"stateMutability": "nonpayable",
"type": "function"
}
]
4 changes: 3 additions & 1 deletion subgraphs/exchange-stableswap/arb/mappings/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ export let PENDLE_ADDRESS = "0x0c880f6761F1af8d9Aa9C466984b80DAb9a8c9e8";
//When new factory was deployed, and SC address into list
export let FACTORIES: string[] = [STABLESWAP_FACTORY_ADDRESS];

export let priceLensContract = PriceLens0.bind(Address.fromString("0x6234d989583520565d00131948c1fb7c4ebb691d"));
export let PRICE_LENS_ADDRESS = "0xe604940c06df1b6a9851f8e8d8d22468cb932e38";

export let priceLensContract = PriceLens0.bind(Address.fromString(PRICE_LENS_ADDRESS));

export let USDT_ADDR = Address.fromString(USDT_ADDRESS);
export let USDC_ADDR = Address.fromString(USDC_ADDRESS);
Expand Down
14 changes: 8 additions & 6 deletions subgraphs/exchange-stableswap/arb/mappings/utils/pricing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
WETH_ADDR,
PENDLE_ADDR,
USDC_ADDR,
PENDLE_ADDRESS,
priceLensContract,
convertTokenToDecimal,
BIG_INT_6,
Expand Down Expand Up @@ -63,8 +62,8 @@ let WHITELIST: string[] = [
// WETH_ADDRESS,
// USDT_ADDRESS,
// USDC_ADDRESS,
PENDLE_ADDRESS,
"0xB688BA096b7Bb75d7841e47163Cd12D18B36A5bF", // mPENDLE
// PENDLE_ADDRESS,
// "0xB688BA096b7Bb75d7841e47163Cd12D18B36A5bF", // mPENDLE
];

// minimum liquidity for price to get tracked
Expand Down Expand Up @@ -107,9 +106,6 @@ export function findBnbPerToken(token: Token): BigDecimal {
if (Address.fromString(token.id).equals(USDC_ADDR)) {
return getPairTokenPrice(USDC_WETH_V3_PAIR, false);
}
if (Address.fromString(token.id).equals(PENDLE_ADDR)) {
return getPairTokenPrice(PENDLE_WETH_V3_PAIR, true);
}
// loop through whitelist and check if paired with any
for (let i = 0; i < WHITELIST.length; ++i) {
if (Address.fromString(token.id).equals(Address.fromString(WHITELIST[i]))) {
Expand All @@ -132,10 +128,16 @@ export function findBnbPerToken(token: Token): BigDecimal {
}
}
let tokenBNBPrice = priceLensContract.try_getNativePrice(Address.fromString(token.id));

if (!tokenBNBPrice.reverted) {
return convertTokenToDecimal(tokenBNBPrice.value, BIG_INT_6);
}

// backward compatibility before price lens
if (Address.fromString(token.id).equals(PENDLE_ADDR)) {
return getPairTokenPrice(PENDLE_WETH_V3_PAIR, true);
}

return BIG_DECIMAL_ZERO; // nothing was found return 0
}

Expand Down
4 changes: 4 additions & 0 deletions subgraphs/exchange-stableswap/arb/subgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ templates:
file: ./abis/PairV3.json
- name: ERC20
file: ./abis/ERC20.json
- name: PriceLens0
file: ./abis/PriceLens0.json
eventHandlers:
- event: AddLiquidity(indexed address,uint256[2],uint256[2],uint256,uint256)
handler: handleAddLiquidity
Expand Down Expand Up @@ -106,6 +108,8 @@ templates:
file: ./abis/PairV3.json
- name: ERC20
file: ./abis/ERC20.json
- name: PriceLens0
file: ./abis/PriceLens0.json
eventHandlers:
- event: AddLiquidity(indexed address,uint256[3],uint256[3],uint256,uint256)
handler: handleTriAddLiquidity
Expand Down
Loading

0 comments on commit d71912f

Please sign in to comment.