-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Release v2 for columbus-5 and bombay-9 (#114)
* update for bombay-9 testnet Co-authored-by: Yun Yeo <[email protected]> Co-authored-by: brycepratt <[email protected]> Co-authored-by: Jon Lund Steffensen <[email protected]>
- Loading branch information
1 parent
ab9d7cd
commit 34fb928
Showing
107 changed files
with
13,057 additions
and
43,452 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,44 @@ | ||
import { LCDClient, MnemonicKey, MsgExecuteContract, Wallet } from '../src'; | ||
|
||
const client = new LCDClient({ | ||
chainID: 'bombay-9', | ||
URL: 'https://bombay-lcd.terra.dev', | ||
}); | ||
|
||
// LocalTerra test1 terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v | ||
const mk = new MnemonicKey({ | ||
mnemonic: | ||
'notice oak worry limit wrap speak medal online prefer cluster roof addict wrist behave treat actual wasp year salad speed social layer crew genius', | ||
}); | ||
|
||
const wallet = client.wallet(mk); | ||
|
||
async function main() { | ||
const execute = new MsgExecuteContract( | ||
wallet.key.accAddress, // sender | ||
'terra156v8s539wtz0sjpn8y8a8lfg8fhmwa7fy22aff', // contract account address | ||
// handle msg | ||
{ | ||
swap: { | ||
offer_asset: { | ||
amount: '1000000', | ||
info: { | ||
native_token: { | ||
denom: 'uluna', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ uluna: 1000000 } // coins | ||
); | ||
|
||
const executeTx = await wallet.createAndSignTx({ | ||
msgs: [execute], | ||
}); | ||
|
||
const executeTxResult = await client.tx.broadcastSync(executeTx); | ||
console.log(executeTxResult); | ||
} | ||
|
||
main().catch(console.error); |
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,145 @@ | ||
import { | ||
LCDClient, | ||
MnemonicKey, | ||
Wallet, | ||
MsgGrantAuthorization, | ||
SendAuthorization, | ||
MsgSend, | ||
Coins, | ||
MsgExecAuthorized, | ||
MsgRevokeAuthorization, | ||
} from '../src'; | ||
|
||
function grant( | ||
granter: Wallet, | ||
grantee: Wallet, | ||
spendLimit: Coins.Input, | ||
expiration: Date | ||
) { | ||
const msgs = [ | ||
new MsgGrantAuthorization( | ||
granter.key.accAddress, | ||
grantee.key.accAddress, | ||
new SendAuthorization(spendLimit), | ||
expiration | ||
), | ||
]; | ||
|
||
return granter.createAndSignTx({ msgs }); | ||
} | ||
|
||
function sendAuthorized( | ||
granter: Wallet, | ||
grantee: Wallet, | ||
to: string, | ||
amount: Coins.Input | ||
) { | ||
const msgs = [ | ||
new MsgExecAuthorized(grantee.key.accAddress, [ | ||
new MsgSend( | ||
granter.key.accAddress, // From test1 | ||
to, | ||
amount | ||
), | ||
]), | ||
]; | ||
|
||
return grantee.createAndSignTx({ msgs }); | ||
} | ||
|
||
function revoke(granter: Wallet, grantee: Wallet, msg_type_url: string) { | ||
const msgs = [ | ||
new MsgRevokeAuthorization( | ||
granter.key.accAddress, | ||
grantee.key.accAddress, | ||
msg_type_url | ||
), | ||
]; | ||
|
||
return granter.createAndSignTx({ msgs }); | ||
} | ||
|
||
async function main() { | ||
const client = new LCDClient({ | ||
URL: 'http://localhost:1317', | ||
chainID: 'localterra', | ||
gasPrices: '169.77ukrw', | ||
}); | ||
|
||
// Granter (terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v) | ||
const granter = client.wallet( | ||
new MnemonicKey({ | ||
mnemonic: | ||
'notice oak worry limit wrap speak medal online prefer cluster roof addict wrist behave treat actual wasp year salad speed social layer crew genius', | ||
}) | ||
); | ||
|
||
// Grantee (terra17lmam6zguazs5q5u6z5mmx76uj63gldnse2pdp) | ||
const grantee = client.wallet( | ||
new MnemonicKey({ | ||
mnemonic: | ||
'quality vacuum heart guard buzz spike sight swarm shove special gym robust assume sudden deposit grid alcohol choice devote leader tilt noodle tide penalty', | ||
}) | ||
); | ||
|
||
// MsgGrantAuthorization | ||
await grant( | ||
granter, | ||
grantee, | ||
// Set enough spend limit since it will be decreased upon every MsgSend transactions | ||
'1000000000000000ukrw', | ||
// expire after 100 year | ||
new Date('2050-01-01') | ||
) | ||
.then(tx => client.tx.broadcast(tx)) | ||
.then(console.info) | ||
.catch(err => { | ||
if (err.response) { | ||
console.error(err.response.data); | ||
} else { | ||
console.error(err.message); | ||
} | ||
}); | ||
|
||
// MsgExecAuthorized of MsgSend | ||
await sendAuthorized( | ||
granter, | ||
grantee, | ||
// Test3 | ||
'terra1757tkx08n0cqrw7p86ny9lnxsqeth0wgp0em95', | ||
'2000000000000ukrw' | ||
) | ||
.then(tx => client.tx.broadcast(tx)) | ||
.then(console.info) | ||
.catch(err => { | ||
if (err.response) { | ||
// unauthorized: authorization not found: failed to execute message; message index: 0: failed to simulate tx | ||
// happenes when there's not enough amount of granted amount of token | ||
|
||
// insufficient funds: insufficient account funds; ... | ||
// happenes when granter does not have enough amount of token | ||
console.error(err.response.data); | ||
} else { | ||
console.error(err.message); | ||
} | ||
}); | ||
|
||
// MsgRevokeAuthorization | ||
await revoke(granter, grantee, '/cosmos.bank.v1beta1.MsgSend') | ||
.then(tx => client.tx.broadcast(tx)) | ||
.then(console.info) | ||
.catch(err => { | ||
if (err.response) { | ||
// unauthorized: authorization not found: failed to execute message; message index: 0: failed to simulate tx | ||
// happenes when there's not enough amount of granted amount of token | ||
|
||
// insufficient funds: insufficient account funds; ... | ||
// happenes when granter does not have enough amount of token | ||
console.error(err.response.data); | ||
} else { | ||
console.error(err.message); | ||
} | ||
}); | ||
} | ||
|
||
main().catch(console.error); |
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,35 @@ | ||
import { LCDClient, MsgSend, MnemonicKey } from '../src'; | ||
|
||
// create a key out of a mnemonic | ||
const mk = new MnemonicKey({ | ||
mnemonic: | ||
'notice oak worry limit wrap speak medal online prefer cluster roof addict wrist behave treat actual wasp year salad speed social layer crew genius', | ||
}); | ||
|
||
// To use LocalTerra | ||
const terra = new LCDClient({ | ||
URL: 'http://localhost:1317', | ||
chainID: 'localterra', | ||
gasPrices: '169.77ukrw', | ||
}); | ||
|
||
// a wallet can be created out of any key | ||
// wallets abstract transaction building | ||
const wallet = terra.wallet(mk); | ||
|
||
// create a simple message that moves coin balances | ||
const send = new MsgSend( | ||
'terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v', | ||
'terra17lmam6zguazs5q5u6z5mmx76uj63gldnse2pdp', | ||
{ uluna: 1000000, ukrw: 1230201, uusd: 1312029 } | ||
); | ||
|
||
wallet | ||
.createAndSignTx({ | ||
msgs: [send], | ||
memo: 'test from terra.js!', | ||
}) | ||
.then(tx => terra.tx.broadcast(tx)) | ||
.then(result => { | ||
console.log(`TX hash: ${result.txhash}`); | ||
}); |
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,39 @@ | ||
import { | ||
Dec, | ||
LCDClient, | ||
MnemonicKey, | ||
MsgSubmitProposal, | ||
TextProposal, | ||
CommunityPoolSpendProposal, | ||
ParameterChangeProposal, | ||
} from '../src'; | ||
|
||
const client = new LCDClient({ | ||
chainID: 'bombay-9', | ||
URL: 'https://bombay-lcd.terra.dev', | ||
}); | ||
|
||
// LocalTerra test1 terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v | ||
const mk = new MnemonicKey({ | ||
mnemonic: | ||
'notice oak worry limit wrap speak medal online prefer cluster roof addict wrist behave treat actual wasp year salad speed social layer crew genius', | ||
}); | ||
|
||
const wallet = client.wallet(mk); | ||
|
||
async function main() { | ||
const execute = new MsgSubmitProposal( | ||
new TaxRateUpdateProposal('tax rate test', 'tax rate test', new Dec(0.2)), | ||
{ uluna: 10000000 }, | ||
wallet.key.accAddress | ||
); | ||
|
||
const executeTx = await wallet.createAndSignTx({ | ||
msgs: [execute], | ||
}); | ||
|
||
const executeTxResult = await client.tx.broadcastSync(executeTx); | ||
console.log(executeTxResult); | ||
} | ||
|
||
main().catch(console.error); |
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,8 +1,8 @@ | ||
import { LCDClient } from '../src'; | ||
|
||
const terra = new LCDClient({ | ||
chainID: 'columbus-4', | ||
URL: 'https://lcd.terra.dev', | ||
chainID: 'bombay-9', | ||
URL: 'https://bombay-lcd.terra.dev', | ||
}); | ||
|
||
terra.utils.validatorsWithVotingPower().then(x => console.log(x)); |
Oops, something went wrong.