-
Notifications
You must be signed in to change notification settings - Fork 8
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 #21 from terra-money/feature/mito
Feature/mito
- Loading branch information
Showing
8 changed files
with
326 additions
and
17 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
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,163 @@ | ||
import { MnemonicKey, Wallet } from '@terra-money/feather.js'; | ||
import { WarpSdk } from '../sdk'; | ||
import { uint, cond, fn, msg, variable, job, ts, query, string } from '../composers'; | ||
import { ChainName, NetworkName } from 'modules'; | ||
import dotenv from 'dotenv'; | ||
import fs from 'fs'; | ||
|
||
dotenv.config(); | ||
|
||
const configPath = process.argv[2]; | ||
const config = JSON.parse(fs.readFileSync(configPath, 'utf8')); | ||
|
||
const lcd = WarpSdk.lcdClient({ networks: [config.NETWORK as NetworkName], chains: [config.CHAIN as ChainName] }); | ||
const lcdClientConfig = Object.values(lcd.config)[0]; | ||
const wallet = new Wallet(lcd, new MnemonicKey({ mnemonic: config.MNEMONIC_KEY, coinType: Number(config.COIN_TYPE) })); | ||
const sdk = new WarpSdk(wallet, lcdClientConfig); | ||
const sender = wallet.key.accAddress(lcdClientConfig.prefix); | ||
|
||
const vault_contract_addr = 'inj1xvlnfmq5672rmvn6576rvj389ezu9nxc9dpk8l'; | ||
const vault_strategy_denom = 'inj'; | ||
|
||
const subaccount_id = variable | ||
.query() | ||
.kind('string') | ||
.name('subaccount_id') | ||
.onInit({ | ||
query: query.smart(vault_contract_addr, { base: { config: {} } }), | ||
selector: '$.config.base.subaccount_id', | ||
}) | ||
.reinitialize(true) | ||
.compose(); | ||
|
||
const next_subaccount_available_balance = variable | ||
.query() | ||
.kind('uint') | ||
.value('0') | ||
.name('next_subaccount_available_balance') | ||
.onInit({ | ||
query: { | ||
custom: { | ||
subaccount_deposit: { | ||
subaccount_id: variable.ref(subaccount_id), | ||
denom: vault_strategy_denom, | ||
}, | ||
}, | ||
} as any, | ||
selector: '$.deposits.available_balance', | ||
}) | ||
.reinitialize(true) | ||
.compose(); | ||
|
||
const prev_subaccount_available_balance = variable | ||
.static() | ||
.kind('uint') | ||
.name('prev_subaccount_available_balance') | ||
.reinitialize(false) | ||
.onInit({ | ||
uint: { | ||
simple: '0', | ||
}, | ||
}) | ||
.onSuccess({ | ||
uint: { | ||
ref: variable.ref(next_subaccount_available_balance), | ||
}, | ||
}) | ||
.compose(); | ||
|
||
const next_config = variable | ||
.query() | ||
.kind('string') | ||
.name('next_config') | ||
.onInit({ | ||
query: query.smart(vault_contract_addr, { base: { config: {} } }), | ||
selector: '$.config', | ||
}) | ||
.reinitialize(true) | ||
.compose(); | ||
|
||
const prev_config = variable | ||
.static() | ||
.kind('string') | ||
.onInit({ | ||
string: { | ||
simple: '', | ||
}, | ||
}) | ||
.name('prev_config') | ||
.reinitialize(false) | ||
.onSuccess({ | ||
string: { | ||
ref: variable.ref(next_config), | ||
}, | ||
}) | ||
.compose(); | ||
|
||
const condition = cond.or( | ||
cond.uint(uint.ref(prev_subaccount_available_balance), 'lt', uint.ref(next_subaccount_available_balance)), | ||
cond.string(string.ref(prev_config), 'neq', string.ref(next_config)) | ||
); | ||
|
||
const executions = [ | ||
{ | ||
condition, | ||
msgs: [ | ||
msg.execute(vault_contract_addr, { | ||
market_make: {}, | ||
}), | ||
], | ||
}, | ||
]; | ||
|
||
const recurring = true; | ||
const durationDays = '7'; | ||
// ordered in reference order (left to right, dfs) | ||
const vars = [ | ||
subaccount_id, | ||
next_subaccount_available_balance, | ||
prev_subaccount_available_balance, | ||
next_config, | ||
prev_config, | ||
]; | ||
|
||
const estimateJobRewardMsg = job | ||
.estimate() | ||
.recurring(recurring) | ||
.durationDays(durationDays) | ||
.vars(vars) | ||
.executions(executions) | ||
.compose(); | ||
|
||
const main = async () => { | ||
try { | ||
const reward = await sdk.estimateJobReward(sender, estimateJobRewardMsg); | ||
|
||
const operationalAmount = await sdk.estimateJobFee(sender, estimateJobRewardMsg, reward.amount.toString()); | ||
|
||
const createJobMsg = job | ||
.create() | ||
.name('mito-market-make') | ||
.description('Triggers market making on mito vaults.') | ||
.labels([]) | ||
.recurring(recurring) | ||
.reward(reward.amount.toString()) | ||
.operationalAmount(operationalAmount.amount.toString()) | ||
.vars(vars) | ||
.durationDays(durationDays) | ||
.executions(executions) | ||
.compose(); | ||
|
||
const tx = await sdk.tx.createJob(sender, createJobMsg, [operationalAmount]); | ||
|
||
console.log(JSON.stringify(tx.msgs, null, 2)); | ||
|
||
// sdk.createJob(sender, createJobMsg, [operationalAmount]).then((response) => { | ||
// console.log(response); | ||
// }); | ||
} catch (err) { | ||
console.log(err); | ||
} | ||
}; | ||
|
||
main(); |
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 { LCDClient, LCDClientConfig, MnemonicKey, Wallet } from '@terra-money/feather.js'; | ||
import { WarpSdk } from '../sdk'; | ||
import { uint, cond, fn, msg, variable, job, ts } from '../composers'; | ||
|
||
const piscoLcdClientConfig: LCDClientConfig = { | ||
lcd: 'https://pisco-lcd.terra.dev', | ||
chainID: 'pisco-1', | ||
gasAdjustment: 1.75, | ||
gasPrices: { uluna: 0.015 }, | ||
prefix: 'terra', | ||
}; | ||
|
||
const lcd = new LCDClient({ | ||
'pisco-1': piscoLcdClientConfig, | ||
}); | ||
|
||
const wallet = new Wallet(lcd, new MnemonicKey({ mnemonic: '...' })); | ||
|
||
const sdk = new WarpSdk(wallet, piscoLcdClientConfig); | ||
const sender = wallet.key.accAddress(piscoLcdClientConfig.prefix); | ||
|
||
const nextExecution = variable | ||
.static() | ||
.kind('uint') | ||
.name('next_execution') | ||
.onInit({ | ||
uint: { | ||
simple: ts.date(new Date('2023-04-10T12:30:00.000Z')), | ||
}, | ||
}) | ||
.onSuccess(fn.uint(uint.expr(uint.simple(ts.days(1)), 'add', uint.env('time')))) | ||
.onError(fn.uint(uint.expr(uint.simple(ts.hours(1)), 'add', uint.env('time')))) | ||
.compose(); | ||
|
||
const condition = cond.uint(uint.env('time'), 'gt', uint.ref(nextExecution)); | ||
|
||
const executions = [ | ||
{ | ||
condition, | ||
msgs: [ | ||
msg.execute('terra1kjv3e7v7m03kk8lrjqr2j604vusxrpxadg6xjz89jucladh5m5gqqag8q7', { | ||
execute_simulate_query: { | ||
query: { | ||
wasm: { | ||
contract_info: { contract_addr: 'terra1mmsl3mxq9n8a6dgye05pn0qlup7r24e2vyjkqgpe32pv3ehjgnes0jz5nc' }, | ||
}, | ||
}, | ||
}, | ||
}), | ||
], | ||
}, | ||
]; | ||
|
||
const recurring = true; | ||
const durationDays = '30'; | ||
const vars = [nextExecution]; | ||
|
||
const estimateJobRewardMsg = job | ||
.estimate() | ||
.recurring(recurring) | ||
.durationDays(durationDays) | ||
.vars(vars) | ||
.executions(executions) | ||
.compose(); | ||
|
||
const main = async () => { | ||
try { | ||
const reward = await sdk.estimateJobReward(sender, estimateJobRewardMsg); | ||
|
||
const operationalAmount = await sdk.estimateJobFee(sender, estimateJobRewardMsg, reward.amount.toString()); | ||
|
||
const createJobMsg = job | ||
.create() | ||
.name('warp-simulate') | ||
.description('This job executes a query simulation for testing purposes.') | ||
.labels([]) | ||
.recurring(recurring) | ||
.reward(reward.amount.toString()) | ||
.operationalAmount(operationalAmount.amount.toString()) | ||
.vars(vars) | ||
.durationDays(durationDays) | ||
.executions(executions) | ||
.compose(); | ||
|
||
console.log(JSON.stringify(createJobMsg, null, 2)); | ||
} catch (err) { | ||
console.log(err); | ||
throw err; | ||
} | ||
}; | ||
|
||
main(); |
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
Oops, something went wrong.