Skip to content

Commit

Permalink
chore: update to sdk@13
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdan-manole authored and kenodressel committed Feb 14, 2024
1 parent ed0fbc8 commit 1760101
Show file tree
Hide file tree
Showing 8 changed files with 1,068 additions and 2,842 deletions.
3,833 changes: 1,030 additions & 2,803 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"prisma:studio": "npx prisma studio"
},
"dependencies": {
"@aeternity/aepp-sdk": "github:aeternity/aepp-sdk-js",
"@aeternity/aepp-sdk": "^13.2.1",
"@nestjs/common": "^8.0.0",
"@nestjs/core": "^8.0.0",
"@nestjs/platform-express": "^8.0.0",
Expand Down
7 changes: 3 additions & 4 deletions src/imports.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//declare module '@aeternity/aepp-sdk';
declare module 'dex-contracts-v2/build/IAedexV2Router.aes.js';
declare module 'dex-contracts-v2/build/IAedexV2Factory.aes.js';
declare module 'dex-contracts-v2/build/IAedexV2Pair.aes';
declare module 'dex-contracts-v2/build/AedexV2Router.aci.json';
declare module 'dex-contracts-v2/build/AedexV2Factory.aci.json';
declare module 'dex-contracts-v2/build/AedexV2Pair.aci.json';
declare module '@aeternity/aepp-calldata';
45 changes: 21 additions & 24 deletions src/lib/contracts.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import NETWORKS from './networks';
import { AeSdk, Node } from '@aeternity/aepp-sdk';
import { CallData, ContractAddress, WalletAddress, nonNullable } from './utils';
import * as routerInterface from 'dex-contracts-v2/build/IAedexV2Router.aes.js';
import * as factoryInterface from 'dex-contracts-v2/build/IAedexV2Factory.aes.js';
import * as pairInterface from 'dex-contracts-v2/build/IAedexV2Pair.aes';
import * as routerInterface from 'dex-contracts-v2/build/AedexV2Router.aci.json';
import * as factoryInterface from 'dex-contracts-v2/build/AedexV2Factory.aci.json';
import * as pairInterface from 'dex-contracts-v2/build/AedexV2Pair.aci.json';

let client: AeSdk;
let node: Node;
Expand All @@ -17,7 +17,6 @@ const getClient = async (): Promise<[AeSdk, Node]> => {

client = new AeSdk({
nodes: [{ name: NETWORK_NAME, instance: node }],
compilerUrl: NETWORKS[NETWORK_NAME].compilerUrl,
});
}
return [client, node];
Expand Down Expand Up @@ -63,36 +62,28 @@ export type Aex9Methods = {
};

const wrapRouter = (router: any): RouterMethods => {
const methods = router.methods;

return {
factory: methods.factory,
factory: router.factory,
};
};
const wrapFactory = (factory: any): FactoryMethods => {
const methods = factory.methods;

return {
allPairs: methods.get_all_pairs,
allPairs: factory.get_all_pairs,
};
};

const wrapPair = (pair: any): PairMethods => {
const methods = pair.methods;

return {
token0: methods.token0,
token1: methods.token1,
totalSupply: methods.total_supply,
reserves: methods.get_reserves,
token0: pair.token0,
token1: pair.token1,
totalSupply: pair.total_supply,
reserves: pair.get_reserves,
};
};

const wrapAex9 = (token: any): Aex9Methods => {
const methods = token.methods;

return {
metaInfo: methods.meta_info,
metaInfo: token.meta_info,
};
};

Expand Down Expand Up @@ -134,21 +125,27 @@ const createGetPair =
return pair;
};

const instanceFactory = async (client: any) => {
return (source: string, contractAddress: string): Promise<any> =>
client.getContractInstance({ source, contractAddress });
const instanceFactory = async (client: AeSdk) => {
return (aci: any, contractAddress: ContractAddress) =>
client.initializeContract({ aci, address: contractAddress });
};

export const getContext = async (): Promise<Context> => {
const routerAddress = process.env.ROUTER_ADDRESS;
if (!routerAddress) {
throw new Error('Router address is not set');
}
const [client, node] = await getClient();
const getInstance = await instanceFactory(client);
const router = await getInstance(
routerInterface,
nonNullable(process.env.ROUTER_ADDRESS),
nonNullable<ContractAddress>(routerAddress as ContractAddress),
);
const factory = await getInstance(
factoryInterface,
nonNullable(process.env.FACTORY_ADDRESS),
nonNullable<ContractAddress>(
process.env.FACTORY_ADDRESS as ContractAddress,
),
);
const pairs: { [key: string]: PairMethods | undefined } = {};
const tokens: { [key: string]: Aex9Methods | undefined } = {};
Expand Down
16 changes: 9 additions & 7 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Encoded } from '@aeternity/aepp-sdk';

export const nonNullable = <T>(t: T | null | undefined, label?: string): T => {
if (t == null) {
throw new Error(
Expand All @@ -18,13 +20,13 @@ export const removeId = <ID, T extends { id: ID }>(t: T) => {
export const pluralize = (count: number, noun: string, suffix = 's') =>
`${count} ${noun}${count !== 1 ? suffix : ''}`;

export type ContractAddress = `ct_${string}`;
export type WalletAddress = `ak_${string}`;
export type CallData = `cb_${string}`; //TODO: are all starting with cb?
export type Signature = `sg_${string}`;
export type Hash = `th_${string}`;
export type BlockHash = `mh_${string}`;
export type Payload = `ba_${string}`;
export type ContractAddress = Encoded.ContractAddress;
export type WalletAddress = Encoded.AccountAddress;
export type CallData = Encoded.ContractBytearray;
export type Signature = Encoded.Signature;
export type Hash = Encoded.TxHash;
export type BlockHash = Encoded.MicroBlockHash;
export type Payload = Encoded.Bytearray;

const parseEnv = (x) => x && JSON.parse(x);
export const presentInvalidTokens = parseEnv(process.env.SHOW_INVALID_TOKENS);
2 changes: 1 addition & 1 deletion src/worker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ export default (ctx: Context) => {
autoStart?: boolean,
crashWhenClosed?: boolean,
) => {
logger.log('Starting worker...');
logger.log(`Starting ${process.env.NETWORK_NAME} worker...`);
await unsyncAllPairs();
await mdw.createNewConnection({
onConnected: async () => {
Expand Down
2 changes: 1 addition & 1 deletion test/data/subscription-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,6 @@ export const swapTxInfo = {
},
],
returnValue: 'cb_I2+IDeC2s6dj/8BviDdWMlDilUHN2k8STg==',
returnType: 'ok',
returnType: 'ok' as const,
},
};
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"noImplicitAny": false,
"strictBindCallApply": false,
"forceConsistentCasingInFileNames": false,
"noFallthroughCasesInSwitch": false
"noFallthroughCasesInSwitch": false,
"types": ["node"]
}
}

0 comments on commit 1760101

Please sign in to comment.