Skip to content

Commit

Permalink
Merge pull request #196 from paltalabs/feat/deploy-script-new-strategies
Browse files Browse the repository at this point in the history
Deploy Scripts for Blend and APR Strategy
  • Loading branch information
joaquinsoza authored Nov 20, 2024
2 parents fd618a1 + d1a4513 commit 5036ea1
Show file tree
Hide file tree
Showing 7 changed files with 187 additions and 7 deletions.
2 changes: 2 additions & 0 deletions apps/contracts/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ DEFINDEX_EMERGENCY_MANAGER_SECRET_KEY=
DEFINDEX_FEE_RECEIVER_SECRET_KEY=
DEFINDEX_MANAGER_SECRET_KEY=

SOROSWAP_MINT_SECRET_KEY=

# RPC Setup
MAINNET_RPC_URL=

Expand Down
4 changes: 3 additions & 1 deletion apps/contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
"scripts": {
"build": "docker-compose run --rm --no-deps defindex-soroban make build",
"deploy-factory": "tsc && node dist/deploy_factory.js",
"deploy-hodl": "tsc && node dist/deploy_hodl.js",
"deploy-hodl": "tsc && node dist/strategies/deploy_hodl.js",
"deploy-fixed": "tsc && node dist/strategies/deploy_fixed.js",
"deploy-blend": "tsc && node dist/strategies/deploy_blend.js",
"publish-addresses": "tsc && node dist/publish_addresses.js",
"test": "tsc && node dist/test.js",
"test-vault": "tsc && node dist/tests/testOnlyVault.js",
Expand Down
76 changes: 76 additions & 0 deletions apps/contracts/src/strategies/deploy_blend.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { Address, Asset, Networks, xdr } from "@stellar/stellar-sdk";
import { AddressBook } from "../utils/address_book.js";
import {
airdropAccount,
deployContract,
installContract,
invokeContract,
} from "../utils/contract.js";
import { config } from "../utils/env_config.js";

export async function deployBlendStrategy(addressBook: AddressBook) {
if (network != "mainnet") await airdropAccount(loadedConfig.admin);
let account = await loadedConfig.horizonRpc.loadAccount(
loadedConfig.admin.publicKey()
);
console.log("publicKey", loadedConfig.admin.publicKey());
let balance = account.balances.filter((item) => item.asset_type == "native");
console.log("Current Admin account balance:", balance[0].balance);

console.log("-------------------------------------------------------");
console.log("Deploying Blend Strategy");
console.log("-------------------------------------------------------");
await installContract("blend_strategy", addressBook, loadedConfig.admin);
await deployContract(
"blend_strategy",
"blend_strategy",
addressBook,
loadedConfig.admin
);

const xlm = Asset.native();
let xlmContractId: string;
switch (network) {
case "testnet":
xlmContractId = xlm.contractId(Networks.TESTNET);
break;
case "mainnet":
xlmContractId = xlm.contractId(Networks.PUBLIC);
break;
default:
console.log("Invalid network:", network, "It should be either testnet or mainnet");
return;
break;
}
const xlmAddress = new Address(xlmContractId);
const xlmScVal = xlmAddress.toScVal();

const initArgs = xdr.ScVal.scvVec([
new Address("CCEVW3EEW4GRUZTZRTAMJAXD6XIF5IG7YQJMEEMKMVVGFPESTRXY2ZAV").toScVal(), //Blend pool on testnet!
]);

const args: xdr.ScVal[] = [
xlmScVal,
initArgs
];

console.log("Initializing Blend Strategy");
await invokeContract(
"blend_strategy",
addressBook,
"initialize",
args,
loadedConfig.admin
);
}

const network = process.argv[2];
const loadedConfig = config(network);
const addressBook = AddressBook.loadFromFile(network);

try {
await deployBlendStrategy(addressBook);
} catch (e) {
console.error(e);
}
addressBook.writeToFile();
92 changes: 92 additions & 0 deletions apps/contracts/src/strategies/deploy_fixed.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import { Address, nativeToScVal, xdr } from "@stellar/stellar-sdk";
import { AddressBook } from "../utils/address_book.js";
import {
airdropAccount,
deployContract,
installContract,
invokeContract,
invokeCustomContract,
} from "../utils/contract.js";
import { config } from "../utils/env_config.js";

export async function deployFixedAPRStrategy(addressBook: AddressBook) {
if (network != "mainnet") await airdropAccount(loadedConfig.admin);
let account = await loadedConfig.horizonRpc.loadAccount(
loadedConfig.admin.publicKey()
);
console.log("publicKey", loadedConfig.admin.publicKey());
let balance = account.balances.filter((item) => item.asset_type == "native");
console.log("Current Admin account balance:", balance[0].balance);

console.log("-------------------------------------------------------");
console.log("Deploying Fixed APR Strategy");
console.log("-------------------------------------------------------");
await installContract("fixed_apr_strategy", addressBook, loadedConfig.admin);
await deployContract(
"fixed_apr_strategy",
"fixed_apr_strategy",
addressBook,
loadedConfig.admin
);

// const xlm = Asset.native();
// let xlmContractId: string;
// switch (network) {
// case "testnet":
// xlmContractId = xlm.contractId(Networks.TESTNET);
// break;
// case "mainnet":
// xlmContractId = xlm.contractId(Networks.PUBLIC);
// break;
// default:
// console.log("Invalid network:", network, "It should be either testnet or mainnet");
// return;
// break;
// }
// const xlmAddress = new Address(xlmContractId);
// const xlmScVal = xlmAddress.toScVal();

const soroswapUsdc = "CAAFIHB4I7WQMJMKC22CZVQNNX7EONWSOMT6SUXK6I3G3F6J4XFRWNDI"
const soroswapScVal = new Address(soroswapUsdc).toScVal();

const initialAmount = 100_000_000_0_000_000;

// Mint to the admin the initailAmount
await invokeCustomContract(
soroswapUsdc,
"mint",
[new Address(loadedConfig.admin.publicKey()).toScVal(), nativeToScVal(initialAmount, { type: "i128" })],
loadedConfig.getUser("SOROSWAP_MINT_SECRET_KEY")
)

const initArgs = xdr.ScVal.scvVec([
nativeToScVal(1000, { type: "u32" }), // 10% APR
new Address(loadedConfig.admin.publicKey()).toScVal(),
nativeToScVal(initialAmount, { type: "i128" })
]);

const args: xdr.ScVal[] = [
soroswapScVal,
initArgs
];

console.log("Initializing Fixed APR Strategy");
await invokeContract(
"fixed_apr_strategy",
addressBook,
"initialize",
args,
loadedConfig.admin
);
}

const network = process.argv[2];
const loadedConfig = config(network);
const addressBook = AddressBook.loadFromFile(network);

try {
await deployFixedAPRStrategy(addressBook);
} catch (e) {
console.error(e);
}
addressBook.writeToFile();
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Address, Asset, Networks, xdr } from "@stellar/stellar-sdk";
import { AddressBook } from "./utils/address_book.js";
import { AddressBook } from "../utils/address_book.js";
import {
airdropAccount,
deployContract,
installContract,
invokeContract,
} from "./utils/contract.js";
import { config } from "./utils/env_config.js";
} from "../utils/contract.js";
import { config } from "../utils/env_config.js";

export async function deployContracts(addressBook: AddressBook) {
if (network != "mainnet") await airdropAccount(loadedConfig.admin);
Expand Down
4 changes: 4 additions & 0 deletions apps/contracts/src/utils/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ const CONTRACT_REL_PATH: object = {
"../../target/wasm32-unknown-unknown/release/soroswap_adapter.optimized.wasm",
hodl_strategy:
"../../target/wasm32-unknown-unknown/release/hodl_strategy.optimized.wasm",
blend_strategy:
"../../target/wasm32-unknown-unknown/release/blend_strategy.optimized.wasm",
fixed_apr_strategy:
"../../target/wasm32-unknown-unknown/release/fixed_apr_strategy.optimized.wasm",
};

const network = process.argv[2];
Expand Down
10 changes: 7 additions & 3 deletions public/testnet.contracts.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
{
"ids": {
"hodl_strategy": "CAEYFO6TY5MMPHSX6CMUKSDHPFVLJKV4TFPHE4ZXAEER2NEIB5GSVBVG",
"defindex_factory": "CARG5QZELODA44D3NB4LIEIJSEMWLJSKA6CNOT4FFGPRYUKC7JLDDZ6L"
"hodl_strategy": "CCWUMJGE6LKWRDJ2IYEJBLCWJSMSUC3QCYZNI2MHTOEYPZRWZN56MIVA",
"defindex_factory": "CARG5QZELODA44D3NB4LIEIJSEMWLJSKA6CNOT4FFGPRYUKC7JLDDZ6L",
"blend_strategy": "CCNFSOPH4XFQ5TNWGTJB4ZVKUUARSNQ67SETXVIQLUIW3B3F7KHA3NKJ",
"fixed_apr_strategy": "CBSAMG2GTK2HMZIUYMAVBJ5EETHZP4U773GCWVWZBMHNK2PEK37TCJWY"
},
"hashes": {
"hodl_strategy": "fcdb4a3c11525a1f32611951741bca5bc4196f58fd1633af37d5b35d30fdf5b0",
"defindex_vault": "468b456399610600ae2718188e16052aabb7488493f7260d16b21c8f7dbf1001",
"defindex_factory": "d6522e73d98e7826782e0b8df6c15410d1b1be95cca985b3e6f1c88a27a11a92"
"defindex_factory": "d6522e73d98e7826782e0b8df6c15410d1b1be95cca985b3e6f1c88a27a11a92",
"blend_strategy": "9df8d8a7c261a892fe33c0ac74a6a3e26e014e3681f8b8dc20a4e5aa4dde5157",
"fixed_apr_strategy": "c93aafba3185ddac4a59257aff683b9f09750c8d486ae607d5fd95f8298d05cf"
}
}

0 comments on commit 5036ea1

Please sign in to comment.