-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #196 from paltalabs/feat/deploy-script-new-strategies
Deploy Scripts for Blend and APR Strategy
- Loading branch information
Showing
7 changed files
with
187 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
6 changes: 3 additions & 3 deletions
6
apps/contracts/src/deploy_hodl.ts → apps/contracts/src/strategies/deploy_hodl.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |