Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: msgExternalTransfer examples #242

Merged
merged 1 commit into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 71 additions & 8 deletions .gitbook/core-modules/auction.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const auctionApi = new ChainGrpcAuctionApi(endpointsForNetwork.grpc);
const injectiveAddress = "inj1...";
/* format amount for bid, note that bid amount has to be higher than the current highest bid */
const amount = {
denom: INJ,
denom: INJ_DENOM,
amount: new BigNumberInBase(1).toWei(),
};

Expand All @@ -38,20 +38,83 @@ const latestRound = uiLatestAuctionModuleState.auctionRound;
const msg = MsgBid.fromJSON({
amount,
injectiveAddress,
round: latestRound,
round: latestRound
});

const privateKey = "0x...";

/* broadcast transaction */
const txHash = await new MsgBroadcasterWithPk({
privateKey,
chainId: ChainId.Mainnet,
endpoints: endpointsForNetwork,
network: Network.Mainnet,
privateKey,
}).broadcast({
msgs: msg,
injectiveAddress,
});
msgs: msg
})


console.log(txHash);
```

### Burn Auction Deposit via MsgExternalTransfer

If you would like to grow the burn auction's pool size, you can directly send funds to the Auction subaccount.

Notes:
- You will need to send funds to the pool's subaccount `0x1111111111111111111111111111111111111111111111111111111111111111`.
- Be aware that any funds you send will be reflected in the next auction, not the current one.
- You cannot transfer from your default subaccountId since that balance is now associated with your Injective address in the bank module. Therefore, in order for `MsgExternalTransfer` to work, you will need to transfer from a non-default subaccountId.

How to find the subaccountId that you will be transferring from:
- you can query your existing subaccountIds via the [account portfolio api](../querying/querying-api/querying-indexer-portfolio.md).

How to use funds that are currently associated with your Injective Address in bank module:
- If you have existing non-default subaccounts, you'll want to do a [MsgDeposit](./exchange.md#MsgDeposit) to one of your existing non-default subaccountIds and use that subaccountId as the `srcSubaccountId` below.
- If you don't have existing non-default subaccounts, you can do a [MsgDeposit](./exchange.md#MsgDeposit) to a new default subaccountId, which would be done via importing `getSubaccountId` from `sdk-ts` and setting the `subaccountId` field in [MsgDeposit](./exchange.md#MsgDeposit) to `getSubaccountId(injectiveAddress, 1)`.

For more info, check out the [burn auction pool docs](https://docs.injective.network/develop/tech-concepts/auction_pool/).

```ts
import {
DenomClient,
MsgExternalTransfer,
MsgBroadcasterWithPk,
} from '@injectivelabs/sdk-ts'
import { BigNumberInBase } from '@injectivelabs/utils'
import { Network } from '@injectivelabs/networks'

const denomClient = new DenomClient(Network.Mainnet);

const injectiveAddress = 'inj1...'
const srcSubaccountId = '0x...'
const POOL_SUBACCOUNT_ID = `0x1111111111111111111111111111111111111111111111111111111111111111`
const USDT_TOKEN_SYMBOL='USDT'
const tokenMeta = denomClient.getTokenMetaDataBySymbol(USDT_TOKEN_SYMBOL);
const tokenDenom = `peggy${tokenMeta.erc20.address}`;

/* format amount to add to the burn auction pool */
const amount = {
denom: tokenDenom,
amount: new BigNumberInBase(1).toWei(tokenMeta.decimals).toFixed()
}

/* create message in proto format */
const msg = MsgExternalTransfer.fromJSON({
amount,
srcSubaccountId,
injectiveAddress,
dstSubaccountId: POOL_SUBACCOUNT_ID
})

const privateKey = '0x...'

/* broadcast transaction */
const txHash = await new MsgBroadcasterWithPk({
network: Network.Mainnet,
privateKey
}).broadcast({
msgs: msg
})


console.log(txHash)
```
24 changes: 9 additions & 15 deletions .gitbook/core-modules/authz.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Per [cosmos sdk docs](https://docs.cosmos.network/main/modules/authz), "Authoriz

```ts
import { MsgGrant, MsgBroadcasterWithPk } from '@injectivelabs/sdk-ts'
import { Network, getNetworkEndpoints } from '@injectivelabs/networks'
import { Network } from '@injectivelabs/networks'

const privateKeyOfGranter = '0x...'
const grantee = 'inj...'
Expand All @@ -46,11 +46,9 @@ const msg = MsgGrant.fromJSON({

const txHash = await new MsgBroadcasterWithPk({
privateKey: privateKeyOfGranter,
network: Network.Testnet,
endpoints: getNetworkEndpoints(Network.Testnet)
network: Network.Testnet
}).broadcast({
msgs: msg,
injectiveAddress: granter,
msgs: msg
})

console.log(txHash)
Expand All @@ -63,7 +61,7 @@ When a grantee wants to execute a transaction on behalf of a granter, they must
```ts
import { MsgExec, MsgSend, MsgBroadcasterWithPk } from '@injectivelabs/sdk-ts'
import { BigNumberInBase } from '@injectivelabs/utils'
import { Network, getNetworkEndpoints } from '@injectivelabs/networks'
import { Network } from '@injectivelabs/networks'

const privateKeyOfGrantee = '0x...'
const grantee = 'inj...'
Expand All @@ -85,11 +83,9 @@ const msg = MsgExec.fromJSON({

const txHash = await new MsgBroadcasterWithPk({
privateKey: privateKeyOfGrantee,
network: Network.Testnet,
endpoints: getNetworkEndpoints(Network.Testnet)
network: Network.Testnet
}).broadcast({
msgs: msg,
injectiveAddress: grantee,
msgs: msg
})

console.log(txHash)
Expand All @@ -101,7 +97,7 @@ A grant can be removed with the MsgRevoke message.

```ts
import { MsgRevoke, MsgBroadcasterWithPk, getEthereumAddress } from '@injectivelabs/sdk-ts'
import { Network, getNetworkEndpoints } from '@injectivelabs/networks'
import { Network } from '@injectivelabs/networks'

const privateKeyOfGranter = '0x...'
const grantee = 'inj...'
Expand All @@ -116,11 +112,9 @@ const msg = MsgRevoke.fromJSON({

const txHash = await new MsgBroadcasterWithPk({
privateKey: privateKeyOfGranter,
network: Network.Testnet,
endpoints: getNetworkEndpoints(Network.Testnet)
network: Network.Testnet
}).broadcast({
msgs: msg,
injectiveAddress: granter,
msgs: msg
})

console.log(txHash)
Expand Down
11 changes: 4 additions & 7 deletions .gitbook/core-modules/bank.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ This Message is used to send coins from one address to another.
```ts
import { MsgSend, MsgBroadcasterWithPk } from '@injectivelabs/sdk-ts'
import { BigNumberInBase } from '@injectivelabs/utils'
import { ChainId } from '@injectivelabs/ts-types'
import { Network, getNetworkEndpoints } from '@injectivelabs/networks'
import { Network } from '@injectivelabs/networks'

const privateKey = '0x...'
const injectiveAddress = 'inj1...'
Expand All @@ -27,16 +26,14 @@ const amount = {
const msg = MsgSend.fromJSON({
amount,
srcInjectiveAddress: injectiveAddress,
dstInjectiveAddress: injectiveAddress,
dstInjectiveAddress: injectiveAddress
});

const txHash = await new MsgBroadcasterWithPk({
privateKey,
chainId: ChainId.Testnet,
endpoints: getNetworkEndpoints(Network.Testnet)
network: Network.Testnet
}).broadcast({
msgs: msg,
injectiveAddress,
msgs: msg
})

console.log(txHash)
Expand Down
22 changes: 6 additions & 16 deletions .gitbook/core-modules/distribution.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ import {
MsgBroadcasterWithPk,
MsgWithdrawDelegatorReward,
} from "@injectivelabs/sdk-ts";
import { ChainId } from "@injectivelabs/ts-types";
import { getNetworkEndpoints, Network } from "@injectivelabs/networks";

const endpointsForNetwork = getNetworkEndpoints(Network.Mainnet);
import { Network } from "@injectivelabs/networks";

const injectiveAddress = "inj1...";
const validatorAddress = "inj1...";
Expand All @@ -32,11 +29,9 @@ const privateKey = "0x...";
/* broadcast transaction */
const txHash = await new MsgBroadcasterWithPk({
privateKey,
chainId: ChainId.Mainnet,
endpoints: endpointsForNetwork,
network: Network.Mainnet
}).broadcast({
msgs: msg,
injectiveAddress,
msgs: msg
});

console.log(txHash);
Expand All @@ -51,10 +46,7 @@ import {
MsgBroadcasterWithPk,
MsgWithdrawValidatorCommission,
} from "@injectivelabs/sdk-ts";
import { ChainId } from "@injectivelabs/ts-types";
import { getNetworkEndpoints, Network } from "@injectivelabs/networks";

const endpointsForNetwork = getNetworkEndpoints(Network.Mainnet);
import { Network } from "@injectivelabs/networks";

const injectiveAddress = "inj1...";
const validatorAddress = "inj1...";
Expand All @@ -69,11 +61,9 @@ const privateKey = "0x...";
/* broadcast transaction */
const txHash = await new MsgBroadcasterWithPk({
privateKey,
chainId: ChainId.Mainnet,
endpoints: endpointsForNetwork,
network: Network.Testnet
}).broadcast({
msgs: msg,
injectiveAddress,
msgs: msg
});

console.log(txHash);
Expand Down
Loading