Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into HEAD
Browse files Browse the repository at this point in the history
  • Loading branch information
evanmarshall committed Aug 15, 2024
2 parents 04abe18 + 612bac7 commit e7230d2
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 24 deletions.
13 changes: 7 additions & 6 deletions .aws/pondo-bot-stack.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
AWSTemplateFormatVersion: '2010-09-09'
Description: CloudFormation template to deploy a Dockerized Node.js bot on an EC2 instance.
Parameters:
KeyPairName:
Description: Name of an existing EC2 KeyPair to enable SSH access to the instance
Type: AWS::EC2::KeyPair::KeyName
ConstraintDescription: must be the name of an existing EC2 KeyPair.
PondoBotAMIId:
Description: Amazon Machine Image ID
Type: String
Expand All @@ -18,11 +14,16 @@ Parameters:
Type: String

Resources:
PondoInstanceProfile:
Type: AWS::IAM::InstanceProfile
Properties:
Roles:
- PondoEC2Role
PondoBotInstance:
Type: 'AWS::EC2::Instance'
Properties:
InstanceType: 'c6a.4xlarge'
KeyName: !Ref KeyPairName
InstanceType: 'c6a.2xlarge'
IamInstanceProfile: !Ref PondoInstanceProfile
ImageId: !Ref PondoBotAMIId
SecurityGroupIds:
- !Ref InstanceSecurityGroup
Expand Down
11 changes: 0 additions & 11 deletions .github/workflows/provision-bot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ on:
github_actions_role:
required: true
type: string
default_validator_address:
required: true
type: string
pondo_foundation_address:
required: true
type: string
network:
required: true
type: string
Expand Down Expand Up @@ -47,8 +41,6 @@ on:
type: string

secrets:
KEY_PAIR_NAME:
required: true
PRIVATE_KEY:
required: true
ADDRESS:
Expand Down Expand Up @@ -92,8 +84,6 @@ jobs:
run: |
echo "PRIVATE_KEY=${{ secrets.PRIVATE_KEY }}" > .env
echo "ADDRESS=${{ secrets.ADDRESS }}" >> .env
echo "DEFAULT_VALIDATOR_ADDRESS=${{ inputs.default_validator_address }}" >> .env
echo "PONDO_FOUNDATION_ADDRESS=${{ inputs.pondo_foundation_address }}" >> .env
echo "NETWORK=${{ inputs.network }}" >> .env
echo "RPC_URL=${{ inputs.rpc_url }}" >> .env
echo "CLIENT_URL=${{ inputs.client_url }}" >> .env
Expand Down Expand Up @@ -135,6 +125,5 @@ jobs:
capabilities: 'CAPABILITY_NAMED_IAM'
no-fail-on-empty-changeset: "1"
parameter-overrides: >-
KeyPairName=${{ secrets.KEY_PAIR_NAME }}
BranchName=${{ env.BRANCH_NAME }}
LatestTag=${{ steps.rename-pondo-bot-image.outputs.pondo-bot-image-tag }}
11 changes: 4 additions & 7 deletions .github/workflows/testnet-beta-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ on:
push:
branches:
- 'testnet-beta'
- 'pondo-bot-deploy'

jobs:
pondo-bot-ap-southeast-1:
Expand All @@ -13,15 +12,13 @@ jobs:
environment: TestnetBeta
region: 'ap-southeast-1'
github_actions_role: 'pondo-bot-role'
default_validator_address: 'aleo15cxs366usuh0hzawudsnn7dza9jmsm6kqmpljtzq9e4529vmlcgq4dem0x'
pondo_foundation_address: 'aleo12shtwnmf49t5atmad2jnk3e58ahtp749d9trctt9z3wryxyzt5pspp0nd0'
network: 'TestnetV0'
rpc_url: 'https://testnetbeta.aleorpc.com'
client_url: 'https://testnetbeta.aleorpc.com'
epoch_blocks: '1000'
oracle_update_blocks: '800'
epoch_blocks: '4000'
oracle_update_blocks: '2500'
rebalance_blocks: '500'
version: 'v1'
paleo_token_id: '1751493913335802797273486270793650302076377624243810059080883537084141842602field'
pondo_token_id: '1751493913335802797273486270793650302076377624243810059080883537084141842603field'
paleo_token_id: '1751493913335802797273486270793650302076377624243810059080883537084141842600field'
pondo_token_id: '1751493913335802797273486270793650302076377624243810059080883537084141842601field'
secrets: inherit
3 changes: 3 additions & 0 deletions pondo-bot/src/aleo/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import path from 'path';

import { AuthorizeTransaction } from '../workers/authorizeTransaction';
import { delegateTransaction, pollDelegatedTransaction } from './client';
import { calculatedFees } from '../protocol/calculatedFees';

type AuthorizePool = Pool<
FunctionThread<[network: string, privateKey: string, program: string, functionName: string, inputs: string[], feeCredits: number, feeRecord?: string, imports?: {
Expand Down Expand Up @@ -52,6 +53,8 @@ export const submitTransaction = async (
feeRecord?: string,
imports?: { [key: string]: string }
): Promise<any> => {
// Get the fee for the program and function or use the input as a default
feeCredits = Number(calculatedFees[program]?.[functionName]) / 999_995 || feeCredits;
// Authorize the transaction
const authorization = await authorizeTransaction(network, privateKey, program, functionName, inputs, feeCredits, feeRecord, imports);
const aleoProgram = Aleo.Program.fromString(network, program);
Expand Down
53 changes: 53 additions & 0 deletions pondo-bot/src/protocol/calculatedFees.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* This file was automatically generated using the `yarn estimateFees` command.
*/

type FeeActions = Record<string, string>;

type CalculatedFees = {
[program: string]: FeeActions;
};

export const calculatedFees: CalculatedFees = {
"multi_token_support_programv1.aleo": { initialize: "48650" },
"mtsp_creditsv1.aleo": {},
"pondo_oraclev1.aleo": {
initialize: "238840",
add_delegator: "169508",
update_data: "1222149",
},
"pondo_staked_aleo_tokenv1.aleo": {},
"pondo_tokenv1.aleo": {},
"pondo_delegator1v1.aleo": {
bond: "388200",
unbond: "780078",
terminal_state: "69096",
},
"pondo_delegator2v1.aleo": {
bond: "388200",
unbond: "780078",
terminal_state: "69096",
},
"pondo_delegator3v1.aleo": {
bond: "388200",
unbond: "780078",
terminal_state: "69096",
},
"pondo_delegator4v1.aleo": {
bond: "388200",
unbond: "780078",
terminal_state: "69096",
},
"pondo_delegator5v1.aleo": {},
"pondo_core_protocolv1.aleo": {
initialize: "1032812",
prep_rebalance: "529697",
deposit_public_as_signer: "669023",
distribute_deposits: "594708",
withdraw_public: "738315",
rebalance_retrieve_credits: "1466846",
rebalance_redistribute: "1103486",
set_oracle_tvl: "204334",
},
"reference_delegatorgizgkl.aleo": { initialize: "543166" },
};
14 changes: 14 additions & 0 deletions pondo-bot/src/protocol/tokenActions.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import * as Aleo from '@demox-labs/aleo-sdk';

import { getMappingValue } from '../aleo/client';
import { submitTransaction } from '../aleo/execute';
import { resolveImports } from '../aleo/deploy';
Expand Down Expand Up @@ -120,3 +122,15 @@ export const burnPondo = async (
resolvedImports
);
};

export const getPAleoBalance = async (
address: string
): Promise<bigint> => {
const balanceKey = getTokenOwnerHash(address, PALEO_TOKEN_ID);
const balanceStruct = await getMappingValue(balanceKey, MTSP_PROGRAM, 'authorized_balances');
if (!balanceStruct) {
return BigInt(0);
}
const balance = BigInt(JSON.parse(formatAleoString(balanceStruct))['balance'].slice(0, -4));
return balance;
}
6 changes: 6 additions & 0 deletions pondo-bot/src/tests/scripts/runTokenActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
transferPondo,
burnPondo,
mintPondo,
getPAleoBalance
} from '../../protocol/tokenActions';

const [action, signer, address, amount] = process.argv.slice(2);
Expand All @@ -12,6 +13,7 @@ enum TOKEN_ACTION_TYPES {
transfer_pondo = 'transfer_pondo',
burn_pondo = 'burn_pondo',
mint_pondo = 'mint_pondo',
paleo_balance = 'paleo_balance'
}

async function main(
Expand All @@ -33,6 +35,10 @@ async function main(
case TOKEN_ACTION_TYPES.burn_pondo:
await burnPondo(signer, address, BigInt(amount));
break;
case TOKEN_ACTION_TYPES.paleo_balance:
const balance = await getPAleoBalance(signer); // In this case we expect signer to be an address
console.log('Balance for account', signer, 'is', balance, 'pAleo');
break;
}
}

Expand Down

0 comments on commit e7230d2

Please sign in to comment.