|
1 | 1 | import {
|
2 | 2 | NewPool,
|
3 | 3 | TokenAdded,
|
| 4 | + TokenRemoved, |
4 | 5 | OPCFeeChanged,
|
5 |
| - FactoryRouter |
| 6 | + FactoryRouter, |
| 7 | + SSContractAdded, |
| 8 | + SSContractRemoved, |
| 9 | + FixedRateContractAdded, |
| 10 | + FixedRateContractRemoved, |
| 11 | + DispenserContractAdded, |
| 12 | + DispenserContractRemoved |
6 | 13 | } from '../@types/FactoryRouter/FactoryRouter'
|
7 | 14 | import { BigInt } from '@graphprotocol/graph-ts'
|
8 | 15 | import { Pool } from '../@types/schema'
|
9 |
| -import { BPool } from '../@types/templates' |
10 |
| -import { addPool, getOPC } from './utils/globalUtils' |
| 16 | +import { BPool, FixedRateExchange, Dispenser } from '../@types/templates' |
| 17 | +import { addPool, getOPC, getTemplates } from './utils/globalUtils' |
11 | 18 | import { weiToDecimal } from './utils/generic'
|
12 | 19 |
|
13 | 20 | export function handleNewPool(event: NewPool): void {
|
@@ -62,5 +69,119 @@ export function handleTokenAdded(event: TokenAdded): void {
|
62 | 69 | if (newProviderFee.reverted) return
|
63 | 70 | opc.consumeFee = weiToDecimal(newConsumeFee.value.toBigDecimal(), decimals)
|
64 | 71 | opc.providerFee = weiToDecimal(newProviderFee.value.toBigDecimal(), decimals)
|
| 72 | + |
| 73 | + // add token to approvedTokens |
| 74 | + let existingTokens: string[] |
| 75 | + if (!opc.approvedTokens) existingTokens = [] |
| 76 | + else existingTokens = opc.approvedTokens as string[] |
| 77 | + if (!existingTokens.includes(event.params.token.toHexString())) |
| 78 | + existingTokens.push(event.params.token.toHexString()) |
| 79 | + opc.approvedTokens = existingTokens |
| 80 | + |
65 | 81 | opc.save()
|
66 | 82 | }
|
| 83 | + |
| 84 | +export function handleTokenRemoved(event: TokenRemoved): void { |
| 85 | + const opc = getOPC() |
| 86 | + const newList: string[] = [] |
| 87 | + let existingTokens: string[] |
| 88 | + if (!opc.approvedTokens) existingTokens = [] |
| 89 | + else existingTokens = opc.approvedTokens as string[] |
| 90 | + if (!existingTokens || existingTokens.length < 1) return |
| 91 | + while (existingTokens.length > 0) { |
| 92 | + const role = existingTokens.shift().toString() |
| 93 | + if (!role) break |
| 94 | + if (role !== event.params.token.toHexString()) newList.push(role) |
| 95 | + } |
| 96 | + opc.approvedTokens = newList |
| 97 | + opc.save() |
| 98 | +} |
| 99 | + |
| 100 | +export function handleSSContractAdded(event: SSContractAdded): void { |
| 101 | + // add token to approvedTokens |
| 102 | + const templates = getTemplates() |
| 103 | + let existingContracts: string[] |
| 104 | + if (!templates.ssTemplates) existingContracts = [] |
| 105 | + else existingContracts = templates.ssTemplates as string[] |
| 106 | + if (!existingContracts.includes(event.params.contractAddress.toHexString())) |
| 107 | + existingContracts.push(event.params.contractAddress.toHexString()) |
| 108 | + templates.ssTemplates = existingContracts |
| 109 | + templates.save() |
| 110 | +} |
| 111 | +export function handleSSContractRemoved(event: SSContractRemoved): void { |
| 112 | + const templates = getTemplates() |
| 113 | + const newList: string[] = [] |
| 114 | + let existingContracts: string[] |
| 115 | + if (!templates.ssTemplates) existingContracts = [] |
| 116 | + else existingContracts = templates.ssTemplates as string[] |
| 117 | + if (!existingContracts || existingContracts.length < 1) return |
| 118 | + while (existingContracts.length > 0) { |
| 119 | + const role = existingContracts.shift().toString() |
| 120 | + if (!role) break |
| 121 | + if (role !== event.params.contractAddress.toHexString()) newList.push(role) |
| 122 | + } |
| 123 | + templates.ssTemplates = newList |
| 124 | + templates.save() |
| 125 | +} |
| 126 | +export function handleFixedRateContractAdded( |
| 127 | + event: FixedRateContractAdded |
| 128 | +): void { |
| 129 | + FixedRateExchange.create(event.params.contractAddress) |
| 130 | + // add token to approvedTokens |
| 131 | + const templates = getTemplates() |
| 132 | + let existingContracts: string[] |
| 133 | + if (!templates.fixedRateTemplates) existingContracts = [] |
| 134 | + else existingContracts = templates.fixedRateTemplates as string[] |
| 135 | + if (!existingContracts.includes(event.params.contractAddress.toHexString())) |
| 136 | + existingContracts.push(event.params.contractAddress.toHexString()) |
| 137 | + templates.fixedRateTemplates = existingContracts |
| 138 | + templates.save() |
| 139 | +} |
| 140 | +export function handleFixedRateContractRemoved( |
| 141 | + event: FixedRateContractRemoved |
| 142 | +): void { |
| 143 | + const templates = getTemplates() |
| 144 | + const newList: string[] = [] |
| 145 | + let existingContracts: string[] |
| 146 | + if (!templates.fixedRateTemplates) existingContracts = [] |
| 147 | + else existingContracts = templates.fixedRateTemplates as string[] |
| 148 | + if (!existingContracts || existingContracts.length < 1) return |
| 149 | + while (existingContracts.length > 0) { |
| 150 | + const role = existingContracts.shift().toString() |
| 151 | + if (!role) break |
| 152 | + if (role !== event.params.contractAddress.toHexString()) newList.push(role) |
| 153 | + } |
| 154 | + templates.fixedRateTemplates = newList |
| 155 | + templates.save() |
| 156 | +} |
| 157 | +export function handleDispenserContractAdded( |
| 158 | + event: DispenserContractAdded |
| 159 | +): void { |
| 160 | + Dispenser.create(event.params.contractAddress) |
| 161 | + |
| 162 | + const templates = getTemplates() |
| 163 | + let existingContracts: string[] |
| 164 | + if (!templates.dispenserTemplates) existingContracts = [] |
| 165 | + else existingContracts = templates.dispenserTemplates as string[] |
| 166 | + if (!existingContracts.includes(event.params.contractAddress.toHexString())) |
| 167 | + existingContracts.push(event.params.contractAddress.toHexString()) |
| 168 | + templates.dispenserTemplates = existingContracts |
| 169 | + templates.save() |
| 170 | +} |
| 171 | +export function handleDispenserContractRemoved( |
| 172 | + event: DispenserContractRemoved |
| 173 | +): void { |
| 174 | + const templates = getTemplates() |
| 175 | + const newList: string[] = [] |
| 176 | + let existingContracts: string[] |
| 177 | + if (!templates.dispenserTemplates) existingContracts = [] |
| 178 | + else existingContracts = templates.dispenserTemplates as string[] |
| 179 | + if (!existingContracts || existingContracts.length < 1) return |
| 180 | + while (existingContracts.length > 0) { |
| 181 | + const role = existingContracts.shift().toString() |
| 182 | + if (!role) break |
| 183 | + if (role !== event.params.contractAddress.toHexString()) newList.push(role) |
| 184 | + } |
| 185 | + templates.dispenserTemplates = newList |
| 186 | + templates.save() |
| 187 | +} |
0 commit comments