Skip to content

Commit f938065

Browse files
authored
Merge pull request #82 from balancer/fix-lbps
fix lbp v3 immutable data
2 parents e755933 + 6e1f691 commit f938065

File tree

2 files changed

+46
-38
lines changed

2 files changed

+46
-38
lines changed

subgraphs/v3-pools/src/mappings/lbp.ts

Lines changed: 44 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,58 +3,66 @@ import { Address, Bytes } from "@graphprotocol/graph-ts";
33
import { handlePoolCreated, PoolType } from "./common";
44
import { PoolCreated } from "../types/LBPoolV2Factory/BasePoolFactory";
55
import { LBPool } from "../types/LBPoolV2Factory/LBPool";
6-
import { LBPool as LBPoolV3 } from "../types/LBPoolV3Factory/LBPool";
6+
import { LBPoolV3 } from "../types/LBPoolV3Factory/LBPoolV3";
77
import { LBPParams, FixedLBPParams } from "../types/schema";
88
import { FixedPriceLBPool } from "../types/FixedPriceLBPoolFactory/FixedPriceLBPool";
99

1010
function handleLBPoolParams(poolAddress: Address): Bytes {
1111
let lbp = LBPool.bind(poolAddress);
1212
let lbpParams = new LBPParams(poolAddress);
1313

14-
let immutableData = lbp.getLBPoolImmutableData();
15-
let projectTokenIndex = immutableData.projectTokenIndex.toI32();
16-
let reserveTokenIndex = immutableData.reserveTokenIndex.toI32();
17-
18-
lbpParams.owner = lbp.owner();
19-
lbpParams.projectToken = immutableData.tokens[projectTokenIndex];
20-
lbpParams.reserveToken = immutableData.tokens[reserveTokenIndex];
21-
lbpParams.startTime = immutableData.startTime;
22-
lbpParams.endTime = immutableData.endTime;
23-
lbpParams.projectTokenStartWeight =
24-
immutableData.startWeights[projectTokenIndex];
25-
lbpParams.projectTokenEndWeight = immutableData.endWeights[projectTokenIndex];
26-
lbpParams.reserveTokenStartWeight =
27-
immutableData.startWeights[reserveTokenIndex];
28-
lbpParams.reserveTokenEndWeight = immutableData.endWeights[reserveTokenIndex];
29-
lbpParams.isProjectTokenSwapInBlocked =
30-
immutableData.isProjectTokenSwapInBlocked;
14+
let immutableData = lbp.try_getLBPoolImmutableData();
15+
if (!immutableData.reverted) {
16+
let projectTokenIndex = immutableData.value.projectTokenIndex.toI32();
17+
let reserveTokenIndex = immutableData.value.reserveTokenIndex.toI32();
18+
19+
lbpParams.owner = lbp.owner();
20+
lbpParams.projectToken = immutableData.value.tokens[projectTokenIndex];
21+
lbpParams.reserveToken = immutableData.value.tokens[reserveTokenIndex];
22+
lbpParams.startTime = immutableData.value.startTime;
23+
lbpParams.endTime = immutableData.value.endTime;
24+
lbpParams.projectTokenStartWeight =
25+
immutableData.value.startWeights[projectTokenIndex];
26+
lbpParams.projectTokenEndWeight =
27+
immutableData.value.endWeights[projectTokenIndex];
28+
lbpParams.reserveTokenStartWeight =
29+
immutableData.value.startWeights[reserveTokenIndex];
30+
lbpParams.reserveTokenEndWeight =
31+
immutableData.value.endWeights[reserveTokenIndex];
32+
lbpParams.isProjectTokenSwapInBlocked =
33+
immutableData.value.isProjectTokenSwapInBlocked;
34+
}
3135

3236
lbpParams.save();
3337

3438
return lbpParams.id;
3539
}
3640

3741
function handleLBPoolV3Params(poolAddress: Address): Bytes {
38-
let lbp = LBPoolV3.bind(poolAddress);
42+
let lbpV3 = LBPoolV3.bind(poolAddress);
3943
let lbpParams = new LBPParams(poolAddress);
4044

41-
let immutableData = lbp.getLBPoolImmutableData();
42-
let projectTokenIndex = immutableData.projectTokenIndex.toI32();
43-
let reserveTokenIndex = immutableData.reserveTokenIndex.toI32();
44-
45-
lbpParams.owner = lbp.owner();
46-
lbpParams.projectToken = immutableData.tokens[projectTokenIndex];
47-
lbpParams.reserveToken = immutableData.tokens[reserveTokenIndex];
48-
lbpParams.startTime = immutableData.startTime;
49-
lbpParams.endTime = immutableData.endTime;
50-
lbpParams.projectTokenStartWeight =
51-
immutableData.startWeights[projectTokenIndex];
52-
lbpParams.projectTokenEndWeight = immutableData.endWeights[projectTokenIndex];
53-
lbpParams.reserveTokenStartWeight =
54-
immutableData.startWeights[reserveTokenIndex];
55-
lbpParams.reserveTokenEndWeight = immutableData.endWeights[reserveTokenIndex];
56-
lbpParams.isProjectTokenSwapInBlocked =
57-
immutableData.isProjectTokenSwapInBlocked;
45+
let immutableData = lbpV3.try_getLBPoolImmutableData();
46+
if (!immutableData.reverted) {
47+
let projectTokenIndex = immutableData.value.projectTokenIndex.toI32();
48+
let reserveTokenIndex = immutableData.value.reserveTokenIndex.toI32();
49+
50+
lbpParams.owner = lbpV3.owner();
51+
lbpParams.projectToken = immutableData.value.tokens[projectTokenIndex];
52+
lbpParams.reserveToken = immutableData.value.tokens[reserveTokenIndex];
53+
lbpParams.startTime = immutableData.value.startTime;
54+
lbpParams.endTime = immutableData.value.endTime;
55+
lbpParams.projectTokenStartWeight =
56+
immutableData.value.startWeights[projectTokenIndex];
57+
lbpParams.projectTokenEndWeight =
58+
immutableData.value.endWeights[projectTokenIndex];
59+
lbpParams.reserveTokenStartWeight =
60+
immutableData.value.startWeights[reserveTokenIndex];
61+
lbpParams.reserveTokenEndWeight =
62+
immutableData.value.endWeights[reserveTokenIndex];
63+
lbpParams.isProjectTokenSwapInBlocked =
64+
immutableData.value.isProjectTokenSwapInBlocked;
65+
}
5866

5967
lbpParams.save();
6068

subgraphs/v3-pools/template.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,8 @@ dataSources:
274274
- Factory
275275
- Pool
276276
abis:
277-
- name: LBPool
278-
file: ./abis/LBPool.json
277+
- name: LBPoolV3
278+
file: ./abis/LBPoolV3.json
279279
- name: BasePoolFactory
280280
file: ./abis/BasePoolFactory.json
281281
eventHandlers:

0 commit comments

Comments
 (0)