Skip to content

Commit

Permalink
deploy scripts and tested contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
joaquinsoza committed Nov 18, 2024
1 parent 0745ab3 commit 0088a64
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 34 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
8 changes: 5 additions & 3 deletions apps/contracts/src/strategies/deploy_blend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,16 @@ export async function deployBlendStrategy(addressBook: AddressBook) {
const xlmAddress = new Address(xlmContractId);
const xlmScVal = xlmAddress.toScVal();

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

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

console.log("Initializing DeFindex HODL Strategy");
console.log("Initializing Blend Strategy");
await invokeContract(
"blend_strategy",
addressBook,
Expand Down
77 changes: 50 additions & 27 deletions apps/contracts/src/strategies/deploy_fixed.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { Address, Asset, Networks, xdr } from "@stellar/stellar-sdk";
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 deployContracts(addressBook: AddressBook) {
export async function deployFixedAPRStrategy(addressBook: AddressBook) {
if (network != "mainnet") await airdropAccount(loadedConfig.admin);
let account = await loadedConfig.horizonRpc.loadAccount(
loadedConfig.admin.publicKey()
Expand All @@ -18,41 +19,63 @@ export async function deployContracts(addressBook: AddressBook) {
console.log("Current Admin account balance:", balance[0].balance);

console.log("-------------------------------------------------------");
console.log("Deploying Hodl Strategy");
console.log("Deploying Fixed APR Strategy");
console.log("-------------------------------------------------------");
await installContract("hodl_strategy", addressBook, loadedConfig.admin);
await installContract("fixed_apr_strategy", addressBook, loadedConfig.admin);
await deployContract(
"hodl_strategy",
"hodl_strategy",
"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 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 emptyVecScVal = xdr.ScVal.scvVec([]);
const soroswapUsdc = "CAAFIHB4I7WQMJMKC22CZVQNNX7EONWSOMT6SUXK6I3G3F6J4XFRWNDI"
const soroswapScVal = new Address(soroswapUsdc).toScVal();

console.log("Initializing DeFindex HODL Strategy");
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(
"hodl_strategy",
"fixed_apr_strategy",
addressBook,
"initialize",
[xlmScVal, emptyVecScVal],
args,
loadedConfig.admin
);
}
Expand All @@ -62,7 +85,7 @@ const loadedConfig = config(network);
const addressBook = AddressBook.loadFromFile(network);

try {
await deployContracts(addressBook);
await deployFixedAPRStrategy(addressBook);
} catch (e) {
console.error(e);
}
Expand Down
12 changes: 8 additions & 4 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": "CBHW3ETUDAZ4FKKEEASONLALSZAYR6IMBA2THXKRPGRAVRG7UQLZFEKP"
"hodl_strategy": "CCWUMJGE6LKWRDJ2IYEJBLCWJSMSUC3QCYZNI2MHTOEYPZRWZN56MIVA",
"defindex_factory": "CARG5QZELODA44D3NB4LIEIJSEMWLJSKA6CNOT4FFGPRYUKC7JLDDZ6L",
"blend_strategy": "CCNFSOPH4XFQ5TNWGTJB4ZVKUUARSNQ67SETXVIQLUIW3B3F7KHA3NKJ",
"fixed_apr_strategy": "CBSAMG2GTK2HMZIUYMAVBJ5EETHZP4U773GCWVWZBMHNK2PEK37TCJWY"
},
"hashes": {
"hodl_strategy": "fcdb4a3c11525a1f32611951741bca5bc4196f58fd1633af37d5b35d30fdf5b0",
"defindex_vault": "861b1b2734e65edb70cc632889d00ce0f07946110e3f957a76714ce9674c73ce",
"defindex_factory": "d6522e73d98e7826782e0b8df6c15410d1b1be95cca985b3e6f1c88a27a11a92"
"defindex_vault": "468b456399610600ae2718188e16052aabb7488493f7260d16b21c8f7dbf1001",
"defindex_factory": "d6522e73d98e7826782e0b8df6c15410d1b1be95cca985b3e6f1c88a27a11a92",
"blend_strategy": "9df8d8a7c261a892fe33c0ac74a6a3e26e014e3681f8b8dc20a4e5aa4dde5157",
"fixed_apr_strategy": "c93aafba3185ddac4a59257aff683b9f09750c8d486ae607d5fd95f8298d05cf"
}
}

0 comments on commit 0088a64

Please sign in to comment.