Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Dashboard] Weekly/monthly funds trend #3080

Open
wants to merge 8 commits into
base: feat/enhanced-dashboard
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 54 additions & 2 deletions amplify/backend/api/colonycdapp/schema/balance.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,21 @@ input DomainBalanceArguments {
"""
The currency in which we want to exchange the in/out token balance
"""
selectedCurrency: SupportedCurrencies
selectedCurrency: ExtendedSupportedCurrencies
"""
The timeframe type (day/week/month) for which we want to get the in/out token balance
The timeframe type (day/week/month/total) for which we want to get the in/out token balance
Defaults to TimeframeType.MONTHLY
"""
timeframeType: TimeframeType
"""
The timeframe period for which we want to get the in/out token balance
"""
timeframePeriod: Int!
"""
The timeframe period end date until which we want to compute the in/out token balance
Default to Date.now()
"""
timeframePeriodEndDate: AWSDateTime
}

"""
Expand Down Expand Up @@ -60,13 +65,21 @@ type DomainBalanceReturn {
timeframe: [TimeframeDomainBalanceInOut]
}

"""
Return type for cache all domain balance
"""
type CacheAllDomainBalanceReturn {
statusCode: Int!
}

"""
Variants of different timeframe periods we can request balance for
"""
enum TimeframeType {
DAILY
WEEKLY
MONTHLY
TOTAL
}

"""
Expand All @@ -93,4 +106,43 @@ type TokenExchangeRate @model {
Exchange currency
"""
marketPrice: [MarketPrice]!
}

"""
Represents a table for caching the total balance
"""
type CacheTotalBalance @model {
"""
Unique identifier
"""
id: ID!
"""
Address of the colony on the blockchain
"""
colonyAddress: String! @index(name: "byColonyAddress", queryField: "cacheTotalBalanceByColonyAddress", sortKeyFields: ["date"] )
"""
Domain id within a colony
"""
domainId: String
"""
The timeframe type (day/week/month) for which we want to cache the in/out token balance
Defaults to TimeframeType.DAILY
"""
timeframeType: TimeframeType
"""
The timeframe period for which we want to cache the in/out token balance
"""
timeframePeriod: Int!
"""
Request timestamp
"""
date: AWSDateTime!
"""
The total in balance in USDC
"""
totalIn: String
"""
The total out balance in USDC
"""
totalOut: String
}
15 changes: 15 additions & 0 deletions amplify/backend/api/colonycdapp/schema/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -1022,6 +1022,11 @@ type Query {
input: DomainBalanceArguments!
): DomainBalanceReturn @function(name: "fetchDomainBalance-${env}")

"""
Trigger the balance caching
"""
cacheAllDomainBalance: CacheAllDomainBalanceReturn @function(name: "cacheDomainBalance-${env}")

}

"""
Expand Down Expand Up @@ -1084,6 +1089,16 @@ enum SupportedCurrencies {
}

enum ExtendedSupportedCurrencies {
USD # US Dollar
JPY # Japanese Yen
GBP # British Pound Sterling
EUR # Euro
CAD # Canadian Dollar
KRW # South Korean Won
INR # Indian Rupee
BRL # Brazilian Real
ETH # Ethereum
CLNY # Colony Network Token
USDC
}

Expand Down
14 changes: 14 additions & 0 deletions amplify/backend/backend-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,20 @@
"providerPlugin": "awscloudformation",
"service": "Lambda"
},
"cacheDomainBalance": {
"build": true,
"dependsOn": [
{
"attributes": [
"Arn"
],
"category": "function",
"resourceName": "colonycdappSSMAccess"
}
],
"providerPlugin": "awscloudformation",
"service": "Lambda"
},
"colonycdappSSMAccess": {
"build": true,
"providerPlugin": "awscloudformation",
Expand Down
6 changes: 6 additions & 0 deletions amplify/backend/function/cacheDomainBalance/amplify.state
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"pluginId": "amplify-nodejs-function-runtime-provider",
"functionRuntime": "nodejs20.x",
"useLegacyBuild": true,
"defaultEditorFile": "src/index.js"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,247 @@
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "Lambda Function resource stack creation using Amplify CLI",
"Parameters": {
"CloudWatchRule": {
"Type": "String",
"Default": "NONE",
"Description": " Schedule Expression"
},
"deploymentBucketName": {
"Type": "String"
},
"env": {
"Type": "String"
},
"s3Key": {
"Type": "String"
}
},
"Conditions": {
"ShouldNotCreateEnvResources": {
"Fn::Equals": [
{
"Ref": "env"
},
"NONE"
]
}
},
"Resources": {
"LambdaFunction": {
"Type": "AWS::Lambda::Function",
"Metadata": {
"aws:asset:path": "./src",
"aws:asset:property": "Code"
},
"Properties": {
"Code": {
"S3Bucket": {
"Ref": "deploymentBucketName"
},
"S3Key": {
"Ref": "s3Key"
}
},
"Handler": "index.handler",
"FunctionName": {
"Fn::If": [
"ShouldNotCreateEnvResources",
"cacheDomainBalance",
{
"Fn::Join": [
"",
[
"cacheDomainBalance",
"-",
{
"Ref": "env"
}
]
]
}
]
},
"Environment": {
"Variables": {
"ENV": {
"Ref": "env"
},
"REGION": {
"Ref": "AWS::Region"
}
}
},
"Role": {
"Fn::GetAtt": [
"LambdaExecutionRole",
"Arn"
]
},
"Runtime": "nodejs14.x",
"Layers": [],
"Timeout": 25
}
},
"LambdaExecutionRole": {
"Type": "AWS::IAM::Role",
"Properties": {
"RoleName": {
"Fn::If": [
"ShouldNotCreateEnvResources",
"colonycdappLambdaRoledd910e60",
{
"Fn::Join": [
"",
[
"colonycdappLambdaRoledd910e60",
"-",
{
"Ref": "env"
}
]
]
}
]
},
"AssumeRolePolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": [
"lambda.amazonaws.com"
]
},
"Action": [
"sts:AssumeRole"
]
}
]
}
}
},
"lambdaexecutionpolicy": {
"DependsOn": [
"LambdaExecutionRole"
],
"Type": "AWS::IAM::Policy",
"Properties": {
"PolicyName": "lambda-execution-policy",
"Roles": [
{
"Ref": "LambdaExecutionRole"
}
],
"PolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": {
"Fn::Sub": [
"arn:aws:logs:${region}:${account}:log-group:/aws/lambda/${lambda}:log-stream:*",
{
"region": {
"Ref": "AWS::Region"
},
"account": {
"Ref": "AWS::AccountId"
},
"lambda": {
"Ref": "LambdaFunction"
}
}
]
}
},
{
"Effect": "Allow",
"Action": [
"ssm:GetParameter",
"kms:Decrypt"
],
"Resource": {
"Fn::Sub": [
"arn:aws:ssm:${region}:${account}:parameter/*",
{
"region": {
"Ref": "AWS::Region"
},
"account": {
"Ref": "AWS::AccountId"
}
}
]
}
}
]
}
}
},
"DailyScheduleRule": {
"Type": "AWS::Events::Rule",
"Properties": {
"ScheduleExpression": "cron(0 1 * * ? *)",
"Targets": [
{
"Arn": {
"Fn::GetAtt": [
"LambdaFunction",
"Arn"
]
},
"Id": "ScheduledLambda-cacheDomainBalance"
}
]
}
},
"LambdaInvokePermission": {
"Type": "AWS::Lambda::Permission",
"Properties": {
"FunctionName": {
"Ref": "LambdaFunction"
},
"Action": "lambda:InvokeFunction",
"Principal": "events.amazonaws.com",
"SourceArn": {
"Fn::GetAtt": [
"DailyScheduleRule",
"Arn"
]
}
}
}
},
"Outputs": {
"Name": {
"Value": {
"Ref": "LambdaFunction"
}
},
"Arn": {
"Value": {
"Fn::GetAtt": [
"LambdaFunction",
"Arn"
]
}
},
"Region": {
"Value": {
"Ref": "AWS::Region"
}
},
"LambdaExecutionRole": {
"Value": {
"Ref": "LambdaExecutionRole"
}
}
}
}
Loading
Loading