diff --git a/src/strategies/math/README.md b/src/strategies/math/README.md index 36f506c43..3dea3038e 100644 --- a/src/strategies/math/README.md +++ b/src/strategies/math/README.md @@ -18,6 +18,7 @@ Currently supported operations are: | `a-if-gt-b` | 3 | (x, a, b) = x > b ? a : x | | `a-if-gte-b` | 3 | (x, a, b) = x >= b ? a : x | | `minus` | 2 | x - a | +| `plus` | 2 | x + a | | `divide` | 2 | x / a | ## Examples diff --git a/src/strategies/math/examples.json b/src/strategies/math/examples.json index 95de058f7..97186d554 100644 --- a/src/strategies/math/examples.json +++ b/src/strategies/math/examples.json @@ -1,6 +1,6 @@ [ { - "name": "Example simple contract call plus / minus", + "name": "Example simple contract call minus", "strategy": { "name": "math", "params": { @@ -34,6 +34,41 @@ ], "snapshot": 16847746 }, + { + "name": "Example simple contract call plus", + "strategy": { + "name": "math", + "params": { + "symbol": "MATH", + "operands": [ + { + "type": "strategy", + "strategy": { + "network": "1", + "name": "erc20-balance-of", + "params": { + "address": "0xdAC17F958D2ee523a2206206994597C13D831ec7", + "symbol": "USDT", + "decimals": 6 + } + } + }, + { + "type": "constant", + "value": 6 + } + ], + "operation": "plus" + } + }, + "network": "1", + "addresses": [ + "0x5C52cC7c96bDE8594e5B77D5b76d042CB5FaE5f2", + "0x4D19C0a5357bC48be0017095d3C871D9aFC3F21d", + "0xf59869753f41Db720127Ceb8DbB8afAF89030De4" + ], + "snapshot": 16847746 + }, { "name": "Example nested query", "strategy": { diff --git a/src/strategies/math/index.ts b/src/strategies/math/index.ts index 6d6444832..693979a9e 100644 --- a/src/strategies/math/index.ts +++ b/src/strategies/math/index.ts @@ -155,6 +155,16 @@ function resolveOperation( ); return Object.fromEntries(arr); } + case Operation.PLUS: { + return Object.fromEntries( + Object.entries(resolvedOperands[0]).map( + ([address, score]: [string, number]) => [ + address, + score + resolvedOperands[1][address] + ] + ) + ); + } case Operation.Divide: { const arr = Object.entries(resolvedOperands[0]).map( ([address, score]: [string, number]) => [ diff --git a/src/strategies/math/options.ts b/src/strategies/math/options.ts index 712e1e9f2..2e7e85222 100644 --- a/src/strategies/math/options.ts +++ b/src/strategies/math/options.ts @@ -31,6 +31,7 @@ export enum Operation { AIfGteB = 'a-if-gte-b', Multiply = 'multiply', MINUS = 'minus', + PLUS = 'plus', Divide = 'divide' } @@ -66,6 +67,7 @@ const operandCountByOperation: Record = { [Operation.AIfGtB]: 3, [Operation.AIfGteB]: 3, [Operation.MINUS]: 2, + [Operation.PLUS]: 2, [Operation.Divide]: 2 }; @@ -87,6 +89,7 @@ export function validateOptions(rawOptions: OptionalOptions): Options { rawOptions.operation !== Operation.AIfGteB && rawOptions.operation !== Operation.Multiply && rawOptions.operation !== Operation.MINUS && + rawOptions.operation !== Operation.PLUS && rawOptions.operation !== Operation.Divide ) { throw new Error('Invalid `operation`');