Skip to content

Commit

Permalink
feat(frontend): kong_backend integration
Browse files Browse the repository at this point in the history
  • Loading branch information
DenysKarmazynDFINITY committed Dec 20, 2024
1 parent 4224882 commit a0005bd
Show file tree
Hide file tree
Showing 18 changed files with 2,630 additions and 3 deletions.
20 changes: 20 additions & 0 deletions dfx.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,26 @@
}
}
},
"kong_backend": {
"type": "custom",
"build": "scripts/build.kong_backend.sh",
"candid": "target/kong_backend.did",
"wasm": "target/kong_backend.wasm.gz",
"shrink": false,
"specified_id": "l4lgk-raaaa-aaaar-qahpq-cai",
"remote": {
"id": {
"ic": "2ipq2-uqaaa-aaaar-qailq-cai",
"beta": "2ipq2-uqaaa-aaaar-qailq-cai",
"test_be_1": "l4lgk-raaaa-aaaar-qahpq-cai",
"test_fe_1": "l4lgk-raaaa-aaaar-qahpq-cai",
"test_fe_2": "l4lgk-raaaa-aaaar-qahpq-cai",
"test_fe_3": "l4lgk-raaaa-aaaar-qahpq-cai",
"test_fe_4": "l4lgk-raaaa-aaaar-qahpq-cai",
"staging": "l4lgk-raaaa-aaaar-qahpq-cai"
}
}
},
"backend": {
"candid": "src/backend/backend.did",
"package": "backend",
Expand Down
58 changes: 58 additions & 0 deletions scripts/build.kong_backend.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/usr/bin/env bash
set -euo pipefail

print_help() {
cat <<-EOF
Creates the Kong Backend installation files:
- The Wasm and Candid files are downloaded.
The files are installed at at the locations defined for 'kong_backend' in 'dfx.json'.
EOF
}

[[ "${1:-}" != "--help" ]] || {
print_help
exit 0
}

KONG_REPO_URL="https://raw.githubusercontent.com/KongSwap/kong/refs/heads/main/canisters"
CANDID_URL="${KONG_REPO_URL}/kong_backend.did"
WASM_URL="${KONG_REPO_URL}/kong_backend.wasm.gz"

CANDID_FILE="$(jq -r .canisters.kong_backend.candid dfx.json)"
WASM_FILE="$(jq -r .canisters.kong_backend.wasm dfx.json)"

download() {
: 'Downloads a URL to a given file.'
: '* With argument x, the filename is $X_FILE and the URL is $X_URL'
: '* If the file already exists, the user is prompted whether to overwrite, keeping the existing file by default.'
local asset asset_url asset_file response
asset="$1"
asset_url="${asset^^}_URL"
asset_file="${asset^^}_FILE"
: 'If the asset file already exists, ask the user whether to overwrite it.'
if test -e "${!asset_file}" && read -r -p "Overwrite existing ${!asset_file}? [y/N] " response && [[ "${response,,}" != y* ]]; then
echo "Using existing kong $asset file."
else
echo Downloading ${!asset_url} "-->" ${!asset_file}
mkdir -p "$(dirname "${!asset_file}")"
curl -sSL "${!asset_url}" >"${!asset_file}"
fi
}

####
# Downloads the candid file, if it does not exist already.
download candid

####
# Downloads the Wasm file, if it does not exist already.
download wasm

####
# Success
cat <<EOF
SUCCESS: The kong_backend installation files have been created:
kong_backend candid: $CANDID_FILE
kong_backend Wasm: $WASM_FILE
EOF
5 changes: 5 additions & 0 deletions scripts/deploy.kong_backend.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

DFX_NETWORK=local

KONG_BUILDENV="$DFX_NETWORK" dfx deploy kong_backend --network "$DFX_NETWORK" --specified-id l4lgk-raaaa-aaaar-qahpq-cai
2 changes: 2 additions & 0 deletions scripts/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ mkdir -p ./target/ic
./scripts/deploy.cketh.sh
./scripts/deploy.ckerc20.sh

./scripts/deploy.kong_backend.sh

dfx deploy internet_identity --specified-id rdmx6-jaaaa-aaaaa-aaadq-cai
dfx deploy pouh_issuer --specified-id qbw6f-caaaa-aaaah-qdcwa-cai
dfx deploy cycles_ledger
Expand Down
2 changes: 1 addition & 1 deletion scripts/did.delete.types.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const deleteFolder = async (canister) => {
};

const promises = Object.keys(canisters)
.filter((canister) => !['backend', 'frontend', 'signer', 'rewards'].includes(canister))
.filter((canister) => !['backend', 'frontend', 'signer', 'rewards', 'kong_backend'].includes(canister))
.map(deleteFolder);

await Promise.allSettled(promises);
Expand Down
2 changes: 1 addition & 1 deletion scripts/did.update.types.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ const copyCertifiedFactory = async ({ dest = `./src/declarations` }) => {

const certifiedFactoryPath = join(dest, dir, `${dir}.factory.certified.did.js`);

await writeFile(certifiedFactoryPath, content.toString().replace(/\['query']/g, ''));
await writeFile(certifiedFactoryPath, content.toString().replace(/\['query'],?/g, ''));

resolve();
};
Expand Down
2 changes: 2 additions & 0 deletions scripts/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ function install_did_files() {
./scripts/did.sh
# .. downloads candid for the signer
DFX_NETWORK=ic ./scripts/build.signer.sh
# .. downloads candid for the kong_backend
DFX_NETWORK=local ./scripts/build.kong_backend.sh
# Download .did files listed in dfx.json
install_did_files
# Generate Rust bindings
Expand Down
45 changes: 45 additions & 0 deletions src/declarations/kong_backend/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import type { ActorConfig, ActorSubclass, Agent, HttpAgentOptions } from '@dfinity/agent';
import type { IDL } from '@dfinity/candid';
import type { Principal } from '@dfinity/principal';

import { _SERVICE } from './kong_backend.did';

export declare const idlFactory: IDL.InterfaceFactory;
export declare const canisterId: string;

export declare interface CreateActorOptions {
/**
* @see {@link Agent}
*/
agent?: Agent;
/**
* @see {@link HttpAgentOptions}
*/
agentOptions?: HttpAgentOptions;
/**
* @see {@link ActorConfig}
*/
actorOptions?: ActorConfig;
}

/**
* Intializes an {@link ActorSubclass}, configured with the provided SERVICE interface of a canister.
* @constructs {@link ActorSubClass}
* @param {string | Principal} canisterId - ID of the canister the {@link Actor} will talk to
* @param {CreateActorOptions} options - see {@link CreateActorOptions}
* @param {CreateActorOptions["agent"]} options.agent - a pre-configured agent you'd like to use. Supercedes agentOptions
* @param {CreateActorOptions["agentOptions"]} options.agentOptions - options to set up a new agent
* @see {@link HttpAgentOptions}
* @param {CreateActorOptions["actorOptions"]} options.actorOptions - options for the Actor
* @see {@link ActorConfig}
*/
export declare const createActor: (
canisterId: string | Principal,
options?: CreateActorOptions
) => ActorSubclass<_SERVICE>;

/**
* Intialized Actor using default settings, ready to talk to a canister using its candid interface
* @constructs {@link ActorSubClass}
*/
export declare const kong_backend: ActorSubclass<_SERVICE>;
Loading

0 comments on commit a0005bd

Please sign in to comment.